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
|
|---|---|---|---|---|---|---|---|---|
hakatashi/youtube-dl
|
youtube_dl/extractor/blinkx.py
|
12
|
3217
|
from __future__ import unicode_literals
import json
from .common import InfoExtractor
from ..utils import (
remove_start,
int_or_none,
)
class BlinkxIE(InfoExtractor):
_VALID_URL = r'(?:https?://(?:www\.)blinkx\.com/#?ce/|blinkx:)(?P<id>[^?]+)'
IE_NAME = 'blinkx'
_TEST = {
'url': 'http://www.blinkx.com/ce/Da0Gw3xc5ucpNduzLuDDlv4WC9PuI4fDi1-t6Y3LyfdY2SZS5Urbvn-UPJvrvbo8LTKTc67Wu2rPKSQDJyZeeORCR8bYkhs8lI7eqddznH2ofh5WEEdjYXnoRtj7ByQwt7atMErmXIeYKPsSDuMAAqJDlQZ-3Ff4HJVeH_s3Gh8oQ',
'md5': '337cf7a344663ec79bf93a526a2e06c7',
'info_dict': {
'id': 'Da0Gw3xc',
'ext': 'mp4',
'title': 'No Daily Show for John Oliver; HBO Show Renewed - IGN News',
'uploader': 'IGN News',
'upload_date': '20150217',
'timestamp': 1424215740,
'description': 'HBO has renewed Last Week Tonight With John Oliver for two more seasons.',
'duration': 47.743333,
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
display_id = video_id[:8]
api_url = ('https://apib4.blinkx.com/api.php?action=play_video&'
+ 'video=%s' % video_id)
data_json = self._download_webpage(api_url, display_id)
data = json.loads(data_json)['api']['results'][0]
duration = None
thumbnails = []
formats = []
for m in data['media']:
if m['type'] == 'jpg':
thumbnails.append({
'url': m['link'],
'width': int(m['w']),
'height': int(m['h']),
})
elif m['type'] == 'original':
duration = float(m['d'])
elif m['type'] == 'youtube':
yt_id = m['link']
self.to_screen('Youtube video detected: %s' % yt_id)
return self.url_result(yt_id, 'Youtube', video_id=yt_id)
elif m['type'] in ('flv', 'mp4'):
vcodec = remove_start(m['vcodec'], 'ff')
acodec = remove_start(m['acodec'], 'ff')
vbr = int_or_none(m.get('vbr') or m.get('vbitrate'), 1000)
abr = int_or_none(m.get('abr') or m.get('abitrate'), 1000)
tbr = vbr + abr if vbr and abr else None
format_id = '%s-%sk-%s' % (vcodec, tbr, m['w'])
formats.append({
'format_id': format_id,
'url': m['link'],
'vcodec': vcodec,
'acodec': acodec,
'abr': abr,
'vbr': vbr,
'tbr': tbr,
'width': int_or_none(m.get('w')),
'height': int_or_none(m.get('h')),
})
self._sort_formats(formats)
return {
'id': display_id,
'fullid': video_id,
'title': data['title'],
'formats': formats,
'uploader': data['channel_name'],
'timestamp': data['pubdate_epoch'],
'description': data.get('description'),
'thumbnails': thumbnails,
'duration': duration,
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
2813,
63,
928,
12,
272,
1109,
63,
269,
63,
3592,
12,
199,
9,
421,
199,
533,
699,
1073,
88,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
20459,
2859,
24524,
1544,
4537,
9,
24042,
88,
4537,
957,
12645,
31,
301,
15,
92,
24042,
88,
26,
18168,
48,
28,
344,
13489,
31,
29716,
272,
15292,
63,
2339,
275,
283,
24042,
88,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
24042,
88,
14,
957,
15,
301,
15,
25014,
16,
39,
87,
19,
1812,
21,
947,
80,
46,
2033,
90,
18176,
5745,
6371,
20,
55,
35,
25,
26607,
41,
20,
70,
1341,
17,
13,
84,
22,
57,
19,
27480,
2592,
57,
18,
18101,
51,
21,
53,
4848,
6002,
13,
2160,
42,
86,
6310,
656,
24,
17090,
12362,
67,
1822,
25728,
18,
82,
8884,
18445,
36,
16608,
58,
1024,
726,
2944,
24,
66,
57,
75,
4213,
24,
76,
41,
23,
4077,
617,
31591,
40,
18,
1618,
72,
21,
5408,
8751,
74,
16936,
889,
50,
84,
74,
23,
2175,
49,
9115,
23,
292,
45,
539,
77,
56,
14485,
57,
24974,
83,
3693,
85,
2054,
33,
81,
42,
22904,
49,
58,
13,
19,
38,
70,
20,
22313,
15169,
40,
63,
83,
19,
39,
72,
24,
79,
49,
297,
267,
283,
1064,
21,
356,
283,
11062,
2177,
23,
65,
10875,
18263,
825,
1965,
4361,
3129,
65,
29227,
65,
18,
69,
1690,
67,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
25014,
16,
39,
87,
19,
1812,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1944,
577,
17550,
12968,
367,
17815,
593,
317,
422,
27,
869,
3973,
12968,
10055,
546,
379,
446,
27499,
30951,
297,
288,
283,
13671,
356,
283,
3203,
30951,
297,
288,
283,
5064,
63,
602,
356,
283,
7806,
996,
1196,
297,
288,
283,
3954,
356,
4329,
1194,
7842,
17702,
12,
288,
283,
1802,
356,
283,
40,
3973,
965,
295,
1222,
379,
15237,
31072,
377,
265,
1070,
8777,
17815,
593,
317,
422,
367,
2877,
1655,
14718,
83,
3130,
288,
283,
5553,
356,
10954,
14,
1342,
6772,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
2929,
63,
344,
275,
3991,
63,
344,
1491,
24,
61,
398,
2986,
63,
633,
275,
661,
2859,
921,
1246,
66,
20,
14,
24042,
88,
14,
957,
15,
1246,
14,
8624,
31,
1287,
29,
2802,
63,
3722,
6,
7,
673,
435,
283,
3722,
2458,
83,
7,
450,
3991,
63,
344,
9,
267,
666,
63,
1001,
275,
291,
423,
4249,
63,
12022,
8,
1246,
63,
633,
12,
2929,
63,
344,
9,
267,
666,
275,
2022,
14,
3640,
8,
576,
63,
1001,
11820,
1246,
2545,
2604,
3488,
16,
61,
267,
7373,
275,
488,
267,
10062,
83,
275,
942,
267,
6752,
275,
942,
267,
367,
333,
315,
666,
459,
4603,
2565,
288,
340,
333,
459,
466,
418,
508,
283,
8476,
356,
355,
10062,
83,
14,
740,
2561,
490,
283,
633,
356,
333,
459,
1073,
995,
490,
283,
2063,
356,
1109,
8,
77,
459,
87,
3815,
490,
283,
3333,
356,
1109,
8,
77,
459,
72,
3815,
355,
3828,
288,
916,
333,
459,
466,
418,
508,
283,
5043,
356,
355,
7373,
275,
2069,
8,
77,
459,
68,
1105,
288,
916,
333,
459,
466,
418,
508,
283,
9788,
356,
355,
612,
84,
63,
344,
275,
333,
459,
1073,
418,
355,
291,
14,
475,
63,
5410,
360,
57,
7715,
3991,
10501,
26,
450,
83,
7,
450,
612,
84,
63,
344,
9,
355,
372,
291,
14,
633,
63,
1099,
8,
24264,
63,
344,
12,
283,
57,
7715,
297,
3991,
63,
344,
29,
24264,
63,
344,
9,
288,
916,
333,
459,
466,
418,
315,
661,
22753,
297,
283,
311,
20,
735,
355,
373,
9276,
275,
2813,
63,
928,
8,
77,
459,
86,
9276,
995,
283,
556,
358,
355,
282,
9276,
275,
2813,
63,
928,
8,
77,
459,
65,
9276,
995,
283,
556,
358,
355,
373,
3289,
275,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
86,
3289,
358,
503,
333,
14,
362,
360,
86,
24484,
659,
5198,
9,
355,
2236,
82,
275,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
371,
82,
358,
503,
333,
14,
362,
360,
30299,
1866,
659,
5198,
9,
355,
307,
3289,
275,
373,
3289,
435,
2236,
82,
340,
373,
3289,
436,
2236,
82,
587,
488,
355,
1475,
63,
344,
275,
1543,
83,
3295,
1339,
3295,
83,
7,
450,
334,
86,
9276,
12,
307,
3289,
12,
333,
459,
87,
1105,
355,
6752,
14,
740,
2561,
490,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
490,
283,
633,
356,
333,
459,
1073,
995,
490,
283,
86,
9276,
356,
373,
9276,
12,
490,
283,
65,
9276,
356,
282,
9276,
12,
490,
283,
371,
82,
356,
2236,
82,
12,
490,
283,
86,
3289,
356,
373,
3289,
12,
490,
283,
84,
3289,
356,
307,
3289,
12,
490,
283,
2063,
356,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
87,
3855,
490,
283,
3333,
356,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
72,
3855,
355,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
2929,
63,
344,
12,
288,
283,
1893,
7401,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
666,
459,
1213,
995,
288,
283,
6321,
356,
6752,
12,
288,
283,
13671,
356,
666,
459,
2775,
63,
354,
995,
288,
283,
3954,
356,
666,
459,
30218,
63,
7367,
995,
288,
283,
1802,
356,
666,
14,
362,
360,
1802,
659,
288,
283,
8311,
83,
356,
10062,
83,
12,
288,
283,
5553,
356,
7373,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
2813,
63,
928,
12,
272,
1109,
63,
269,
63,
3592,
12,
199,
9,
421,
199,
533,
699,
1073,
88,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
20459,
2859,
24524,
1544,
4537,
9,
24042,
88,
4537,
957,
12645,
31,
301,
15,
92,
24042,
88,
26,
18168,
48,
28,
344,
13489,
31,
29716,
272,
15292,
63,
2339,
275,
283,
24042,
88,
7,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
24042,
88,
14,
957,
15,
301,
15,
25014,
16,
39,
87,
19,
1812,
21,
947,
80,
46,
2033,
90,
18176,
5745,
6371,
20,
55,
35,
25,
26607,
41,
20,
70,
1341,
17,
13,
84,
22,
57,
19,
27480,
2592,
57,
18,
18101,
51,
21,
53,
4848,
6002,
13,
2160,
42,
86,
6310,
656,
24,
17090,
12362,
67,
1822,
25728,
18,
82,
8884,
18445,
36,
16608,
58,
1024,
726,
2944,
24,
66,
57,
75,
4213,
24,
76,
41,
23,
4077,
617,
31591,
40,
18,
1618,
72,
21,
5408,
8751,
74,
16936,
889,
50,
84,
74,
23,
2175,
49,
9115,
23,
292,
45,
539,
77,
56,
14485,
57,
24974,
83,
3693,
85,
2054,
33,
81,
42,
22904,
49,
58,
13,
19,
38,
70,
20,
22313,
15169,
40,
63,
83,
19,
39,
72,
24,
79,
49,
297,
267,
283,
1064,
21,
356,
283,
11062,
2177,
23,
65,
10875,
18263,
825,
1965,
4361,
3129,
65,
29227,
65,
18,
69,
1690,
67,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
25014,
16,
39,
87,
19,
1812,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1944,
577,
17550,
12968,
367,
17815,
593,
317,
422,
27,
869,
3973,
12968,
10055,
546,
379,
446,
27499,
30951,
297,
288,
283,
13671,
356,
283,
3203,
30951,
297,
288,
283,
5064,
63,
602,
356,
283,
7806,
996,
1196,
297,
288,
283,
3954,
356,
4329,
1194,
7842,
17702,
12,
288,
283,
1802,
356,
283,
40,
3973,
965,
295,
1222,
379,
15237,
31072,
377,
265,
1070,
8777,
17815,
593,
317,
422,
367,
2877,
1655,
14718,
83,
3130,
288,
283,
5553,
356,
10954,
14,
1342,
6772,
12,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
2929,
63,
344,
275,
3991,
63,
344,
1491,
24,
61,
398,
2986,
63,
633,
275,
661,
2859,
921,
1246,
66,
20,
14,
24042,
88,
14,
957,
15,
1246,
14,
8624,
31,
1287,
29,
2802,
63,
3722,
6,
7,
673,
435,
283,
3722,
2458,
83,
7,
450,
3991,
63,
344,
9,
267,
666,
63,
1001,
275,
291,
423,
4249,
63,
12022,
8,
1246,
63,
633,
12,
2929,
63,
344,
9,
267,
666,
275,
2022,
14,
3640,
8,
576,
63,
1001,
11820,
1246,
2545,
2604,
3488,
16,
61,
267,
7373,
275,
488,
267,
10062,
83,
275,
942,
267,
6752,
275,
942,
267,
367,
333,
315,
666,
459,
4603,
2565,
288,
340,
333,
459,
466,
418,
508,
283,
8476,
356,
355,
10062,
83,
14,
740,
2561,
490,
283,
633,
356,
333,
459,
1073,
995,
490,
283,
2063,
356,
1109,
8,
77,
459,
87,
3815,
490,
283,
3333,
356,
1109,
8,
77,
459,
72,
3815,
355,
3828,
288,
916,
333,
459,
466,
418,
508,
283,
5043,
356,
355,
7373,
275,
2069,
8,
77,
459,
68,
1105,
288,
916,
333,
459,
466,
418,
508,
283,
9788,
356,
355,
612,
84,
63,
344,
275,
333,
459,
1073,
418,
355,
291,
14,
475,
63,
5410,
360,
57,
7715,
3991,
10501,
26,
450,
83,
7,
450,
612,
84,
63,
344,
9,
355,
372,
291,
14,
633,
63,
1099,
8,
24264,
63,
344,
12,
283,
57,
7715,
297,
3991,
63,
344,
29,
24264,
63,
344,
9,
288,
916,
333,
459,
466,
418,
315,
661,
22753,
297,
283,
311,
20,
735,
355,
373,
9276,
275,
2813,
63,
928,
8,
77,
459,
86,
9276,
995,
283,
556,
358,
355,
282,
9276,
275,
2813,
63,
928,
8,
77,
459,
65,
9276,
995,
283,
556,
358,
355,
373,
3289,
275,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
86,
3289,
358,
503,
333,
14,
362,
360,
86,
24484,
659,
5198,
9,
355,
2236,
82,
275,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
371,
82,
358,
503,
333,
14,
362,
360,
30299,
1866,
659,
5198,
9,
355,
307,
3289,
275,
373,
3289,
435,
2236,
82,
340,
373,
3289,
436,
2236,
82,
587,
488,
355,
1475,
63,
344,
275,
1543,
83,
3295,
1339,
3295,
83,
7,
450,
334,
86,
9276,
12,
307,
3289,
12,
333,
459,
87,
1105,
355,
6752,
14,
740,
2561,
490,
283,
908,
63,
344,
356,
1475,
63,
344,
12,
490,
283,
633,
356,
333,
459,
1073,
995,
490,
283,
86,
9276,
356,
373,
9276,
12,
490,
283,
65,
9276,
356,
282,
9276,
12,
490,
283,
371,
82,
356,
2236,
82,
12,
490,
283,
86,
3289,
356,
373,
3289,
12,
490,
283,
84,
3289,
356,
307,
3289,
12,
490,
283,
2063,
356,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
87,
3855,
490,
283,
3333,
356,
1109,
63,
269,
63,
3592,
8,
77,
14,
362,
360,
72,
3855,
355,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
2929,
63,
344,
12,
288,
283,
1893,
7401,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
666,
459,
1213,
995,
288,
283,
6321,
356,
6752,
12,
288,
283,
13671,
356,
666,
459,
2775,
63,
354,
995,
288,
283,
3954,
356,
666,
459,
30218,
63,
7367,
995,
288,
283,
1802,
356,
666,
14,
362,
360,
1802,
659,
288,
283,
8311,
83,
356,
10062,
83,
12,
288,
283,
5553,
356,
7373,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cryptobanana/ansible
|
lib/ansible/modules/cloud/amazon/cloudtrail.py
|
3
|
23696
|
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: cloudtrail
short_description: manage CloudTrail create, delete, update
description:
- Creates, deletes, or updates CloudTrail configuration. Ensures logging is also enabled.
version_added: "2.0"
author:
- "Ansible Core Team"
- "Ted Timmons"
- "Daniel Shepherd (@shepdelacreme)"
requirements:
- boto3
- botocore
options:
state:
description:
- Add or remove CloudTrail configuration.
- The following states have been preserved for backwards compatibility. C(state=enabled) and C(state=disabled).
- enabled=present and disabled=absent.
required: true
choices: ['present', 'absent', 'enabled', 'disabled']
name:
description:
- Name for the CloudTrail.
- Names are unique per-region unless the CloudTrail is a multi-region trail, in which case it is unique per-account.
required: true
enable_logging:
description:
- Start or stop the CloudTrail logging. If stopped the trail will be paused and will not record events or deliver log files.
default: true
version_added: "2.4"
s3_bucket_name:
description:
- An existing S3 bucket where CloudTrail will deliver log files.
- This bucket should exist and have the proper policy.
- See U(http://docs.aws.amazon.com/awscloudtrail/latest/userguide/aggregating_logs_regions_bucket_policy.html)
- Required when C(state=present)
version_added: "2.4"
s3_key_prefix:
description:
- S3 Key prefix for delivered log files. A trailing slash is not necessary and will be removed.
is_multi_region_trail:
description:
- Specify whether the trail belongs only to one region or exists in all regions.
default: false
version_added: "2.4"
enable_log_file_validation:
description:
- Specifies whether log file integrity validation is enabled.
- CloudTrail will create a hash for every log file delivered and produce a signed digest file that can be used to ensure log files have not been tampered.
default: false
version_added: "2.4"
aliases: [ "log_file_validation_enabled" ]
include_global_events:
description:
- Record API calls from global services such as IAM and STS.
default: true
aliases: [ "include_global_service_events" ]
sns_topic_name:
description:
- SNS Topic name to send notifications to when a log file is delivered
version_added: "2.4"
cloudwatch_logs_role_arn:
description:
- Specifies a full ARN for an IAM role that assigns the proper permissions for CloudTrail to create and write to the log group.
- See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html)
- Required when C(cloudwatch_logs_log_group_arn)
version_added: "2.4"
cloudwatch_logs_log_group_arn:
description:
- A full ARN specifying a valid CloudWatch log group to which CloudTrail logs will be delivered. The log group should already exist.
- See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html)
- Required when C(cloudwatch_logs_role_arn)
version_added: "2.4"
kms_key_id:
description:
- Specifies the KMS key ID to use to encrypt the logs delivered by CloudTrail. This also has the effect of enabling log file encryption.
- The value can be an alias name prefixed by "alias/", a fully specified ARN to an alias, a fully specified ARN to a key, or a globally unique identifier.
- See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/encrypting-cloudtrail-log-files-with-aws-kms.html)
version_added: "2.4"
tags:
description:
- A hash/dictionary of tags to be applied to the CloudTrail resource.
- Remove completely or specify an empty dictionary to remove all tags.
default: {}
version_added: "2.4"
extends_documentation_fragment:
- aws
- ec2
'''
EXAMPLES = '''
- name: create single region cloudtrail
cloudtrail:
state: present
name: default
s3_bucket_name: mylogbucket
s3_key_prefix: cloudtrail
region: us-east-1
- name: create multi-region trail with validation and tags
cloudtrail:
state: present
name: default
s3_bucket_name: mylogbucket
region: us-east-1
is_multi_region_trail: true
enable_log_file_validation: true
cloudwatch_logs_role_arn: "arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role"
cloudwatch_logs_log_group_arn: "arn:aws:logs:us-east-1:123456789012:log-group:CloudTrail/DefaultLogGroup:*"
kms_key_id: "alias/MyAliasName"
tags:
environment: dev
Name: default
- name: show another valid kms_key_id
cloudtrail:
state: present
name: default
s3_bucket_name: mylogbucket
kms_key_id: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"
# simply "12345678-1234-1234-1234-123456789012" would be valid too.
- name: pause logging the trail we just created
cloudtrail:
state: present
name: default
enable_logging: false
s3_bucket_name: mylogbucket
region: us-east-1
is_multi_region_trail: true
enable_log_file_validation: true
tags:
environment: dev
Name: default
- name: delete a trail
cloudtrail:
state: absent
name: default
'''
RETURN = '''
exists:
description: whether the resource exists
returned: always
type: bool
sample: true
trail:
description: CloudTrail resource details
returned: always
type: complex
sample: hash/dictionary of values
contains:
trail_arn:
description: Full ARN of the CloudTrail resource
returned: success
type: string
sample: arn:aws:cloudtrail:us-east-1:123456789012:trail/default
name:
description: Name of the CloudTrail resource
returned: success
type: string
sample: default
is_logging:
description: Whether logging is turned on or paused for the Trail
returned: success
type: bool
sample: True
s3_bucket_name:
description: S3 bucket name where log files are delivered
returned: success
type: string
sample: myBucket
s3_key_prefix:
description: Key prefix in bucket where log files are delivered (if any)
returned: success when present
type: string
sample: myKeyPrefix
log_file_validation_enabled:
description: Whether log file validation is enabled on the trail
returned: success
type: bool
sample: true
include_global_service_events:
description: Whether global services (IAM, STS) are logged with this trail
returned: success
type: bool
sample: true
is_multi_region_trail:
description: Whether the trail applies to all regions or just one
returned: success
type: bool
sample: true
has_custom_event_selectors:
description: Whether any custom event selectors are used for this trail.
returned: success
type: bool
sample: False
home_region:
description: The home region where the trail was originally created and must be edited.
returned: success
type: string
sample: us-east-1
sns_topic_name:
description: The SNS topic name where log delivery notifications are sent.
returned: success when present
type: string
sample: myTopic
sns_topic_arn:
description: Full ARN of the SNS topic where log delivery notifications are sent.
returned: success when present
type: string
sample: arn:aws:sns:us-east-1:123456789012:topic/myTopic
cloud_watch_logs_log_group_arn:
description: Full ARN of the CloudWatch Logs log group where events are delivered.
returned: success when present
type: string
sample: arn:aws:logs:us-east-1:123456789012:log-group:CloudTrail/DefaultLogGroup:*
cloud_watch_logs_role_arn:
description: Full ARN of the IAM role that CloudTrail assumes to deliver events.
returned: success when present
type: string
sample: arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role
kms_key_id:
description: Full ARN of the KMS Key used to encrypt log files.
returned: success when present
type: string
sample: arn:aws:kms::123456789012:key/12345678-1234-1234-1234-123456789012
tags:
description: hash/dictionary of tags applied to this resource
returned: success
type: dict
sample: {'environment': 'dev', 'Name': 'default'}
'''
import traceback
try:
from botocore.exceptions import ClientError
except ImportError:
# Handled in main() by imported HAS_BOTO3
pass
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ec2 import (boto3_conn, ec2_argument_spec, get_aws_connection_info,
HAS_BOTO3, ansible_dict_to_boto3_tag_list,
boto3_tag_list_to_ansible_dict, camel_dict_to_snake_dict)
def create_trail(module, client, ct_params):
"""
Creates a CloudTrail
module : AnsibleModule object
client : boto3 client connection object
ct_params : The parameters for the Trail to create
"""
resp = {}
try:
resp = client.create_trail(**ct_params)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
return resp
def tag_trail(module, client, tags, trail_arn, curr_tags=None, dry_run=False):
"""
Creates, updates, removes tags on a CloudTrail resource
module : AnsibleModule object
client : boto3 client connection object
tags : Dict of tags converted from ansible_dict to boto3 list of dicts
trail_arn : The ARN of the CloudTrail to operate on
curr_tags : Dict of the current tags on resource, if any
dry_run : true/false to determine if changes will be made if needed
"""
adds = []
removes = []
updates = []
changed = False
if curr_tags is None:
# No current tags so just convert all to a tag list
adds = ansible_dict_to_boto3_tag_list(tags)
else:
curr_keys = set(curr_tags.keys())
new_keys = set(tags.keys())
add_keys = new_keys - curr_keys
remove_keys = curr_keys - new_keys
update_keys = dict()
for k in curr_keys.intersection(new_keys):
if curr_tags[k] != tags[k]:
update_keys.update({k: tags[k]})
adds = get_tag_list(add_keys, tags)
removes = get_tag_list(remove_keys, curr_tags)
updates = get_tag_list(update_keys, tags)
if removes or updates:
changed = True
if not dry_run:
try:
client.remove_tags(ResourceId=trail_arn, TagsList=removes + updates)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
if updates or adds:
changed = True
if not dry_run:
try:
client.add_tags(ResourceId=trail_arn, TagsList=updates + adds)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
return changed
def get_tag_list(keys, tags):
"""
Returns a list of dicts with tags to act on
keys : set of keys to get the values for
tags : the dict of tags to turn into a list
"""
tag_list = []
for k in keys:
tag_list.append({'Key': k, 'Value': tags[k]})
return tag_list
def set_logging(module, client, name, action):
"""
Starts or stops logging based on given state
module : AnsibleModule object
client : boto3 client connection object
name : The name or ARN of the CloudTrail to operate on
action : start or stop
"""
if action == 'start':
try:
client.start_logging(Name=name)
return client.get_trail_status(Name=name)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
elif action == 'stop':
try:
client.stop_logging(Name=name)
return client.get_trail_status(Name=name)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
else:
module.fail_json(msg="Unsupported logging action")
def get_trail_facts(module, client, name):
"""
Describes existing trail in an account
module : AnsibleModule object
client : boto3 client connection object
name : Name of the trail
"""
# get Trail info
try:
trail_resp = client.describe_trails(trailNameList=[name])
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
# Now check to see if our trail exists and get status and tags
if len(trail_resp['trailList']):
trail = trail_resp['trailList'][0]
try:
status_resp = client.get_trail_status(Name=trail['Name'])
tags_list = client.list_tags(ResourceIdList=[trail['TrailARN']])
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
trail['IsLogging'] = status_resp['IsLogging']
trail['tags'] = boto3_tag_list_to_ansible_dict(tags_list['ResourceTagList'][0]['TagsList'])
# Check for non-existent values and populate with None
optional_vals = set(['S3KeyPrefix', 'SnsTopicName', 'SnsTopicARN', 'CloudWatchLogsLogGroupArn', 'CloudWatchLogsRoleArn', 'KmsKeyId'])
for v in optional_vals - set(trail.keys()):
trail[v] = None
return trail
else:
# trail doesn't exist return None
return None
def delete_trail(module, client, trail_arn):
"""
Delete a CloudTrail
module : AnsibleModule object
client : boto3 client connection object
trail_arn : Full CloudTrail ARN
"""
try:
client.delete_trail(Name=trail_arn)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
def update_trail(module, client, ct_params):
"""
Delete a CloudTrail
module : AnsibleModule object
client : boto3 client connection object
ct_params : The parameters for the Trail to update
"""
try:
client.update_trail(**ct_params)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(dict(
state=dict(default='present', choices=['present', 'absent', 'enabled', 'disabled']),
name=dict(default='default'),
enable_logging=dict(default=True, type='bool'),
s3_bucket_name=dict(),
s3_key_prefix=dict(),
sns_topic_name=dict(),
is_multi_region_trail=dict(default=False, type='bool'),
enable_log_file_validation=dict(default=False, type='bool', aliases=['log_file_validation_enabled']),
include_global_events=dict(default=True, type='bool', aliases=['include_global_service_events']),
cloudwatch_logs_role_arn=dict(),
cloudwatch_logs_log_group_arn=dict(),
kms_key_id=dict(),
tags=dict(default={}, type='dict'),
))
required_if = [('state', 'present', ['s3_bucket_name']), ('state', 'enabled', ['s3_bucket_name'])]
required_together = [('cloudwatch_logs_role_arn', 'cloudwatch_logs_log_group_arn')]
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, required_together=required_together, required_if=required_if)
if not HAS_BOTO3:
module.fail_json(msg='boto3 is required for this module')
# collect parameters
if module.params['state'] in ('present', 'enabled'):
state = 'present'
elif module.params['state'] in ('absent', 'disabled'):
state = 'absent'
tags = module.params['tags']
enable_logging = module.params['enable_logging']
ct_params = dict(
Name=module.params['name'],
S3BucketName=module.params['s3_bucket_name'],
IncludeGlobalServiceEvents=module.params['include_global_events'],
IsMultiRegionTrail=module.params['is_multi_region_trail'],
EnableLogFileValidation=module.params['enable_log_file_validation'],
S3KeyPrefix='',
SnsTopicName='',
CloudWatchLogsRoleArn='',
CloudWatchLogsLogGroupArn='',
KmsKeyId=''
)
if module.params['s3_key_prefix']:
ct_params['S3KeyPrefix'] = module.params['s3_key_prefix'].rstrip('/')
if module.params['sns_topic_name']:
ct_params['SnsTopicName'] = module.params['sns_topic_name']
if module.params['cloudwatch_logs_role_arn']:
ct_params['CloudWatchLogsRoleArn'] = module.params['cloudwatch_logs_role_arn']
if module.params['cloudwatch_logs_log_group_arn']:
ct_params['CloudWatchLogsLogGroupArn'] = module.params['cloudwatch_logs_log_group_arn']
if module.params['kms_key_id']:
ct_params['KmsKeyId'] = module.params['kms_key_id']
try:
region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True)
client = boto3_conn(module, conn_type='client', resource='cloudtrail', region=region, endpoint=ec2_url, **aws_connect_params)
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
results = dict(
changed=False,
exists=False
)
# Get existing trail facts
trail = get_trail_facts(module, client, ct_params['Name'])
# If the trail exists set the result exists variable
if trail is not None:
results['exists'] = True
if state == 'absent' and results['exists']:
# If Trail exists go ahead and delete
results['changed'] = True
results['exists'] = False
results['trail'] = dict()
if not module.check_mode:
delete_trail(module, client, trail['TrailARN'])
elif state == 'present' and results['exists']:
# If Trail exists see if we need to update it
do_update = False
for key in ct_params:
tkey = str(key)
# boto3 has inconsistent parameter naming so we handle it here
if key == 'EnableLogFileValidation':
tkey = 'LogFileValidationEnabled'
# We need to make an empty string equal None
if ct_params.get(key) == '':
val = None
else:
val = ct_params.get(key)
if val != trail.get(tkey):
do_update = True
results['changed'] = True
# If we are in check mode copy the changed values to the trail facts in result output to show what would change.
if module.check_mode:
trail.update({tkey: ct_params.get(key)})
if not module.check_mode and do_update:
update_trail(module, client, ct_params)
trail = get_trail_facts(module, client, ct_params['Name'])
# Check if we need to start/stop logging
if enable_logging and not trail['IsLogging']:
results['changed'] = True
trail['IsLogging'] = True
if not module.check_mode:
set_logging(module, client, name=ct_params['Name'], action='start')
if not enable_logging and trail['IsLogging']:
results['changed'] = True
trail['IsLogging'] = False
if not module.check_mode:
set_logging(module, client, name=ct_params['Name'], action='stop')
# Check if we need to update tags on resource
tag_dry_run = False
if module.check_mode:
tag_dry_run = True
tags_changed = tag_trail(module, client, tags=tags, trail_arn=trail['TrailARN'], curr_tags=trail['tags'], dry_run=tag_dry_run)
if tags_changed:
results['changed'] = True
trail['tags'] = tags
# Populate trail facts in output
results['trail'] = camel_dict_to_snake_dict(trail)
elif state == 'present' and not results['exists']:
# Trail doesn't exist just go create it
results['changed'] = True
if not module.check_mode:
# If we aren't in check_mode then actually create it
created_trail = create_trail(module, client, ct_params)
# Apply tags
tag_trail(module, client, tags=tags, trail_arn=created_trail['TrailARN'])
# Get the trail status
try:
status_resp = client.get_trail_status(Name=created_trail['Name'])
except ClientError as err:
module.fail_json(msg=err.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(err.response))
# Set the logging state for the trail to desired value
if enable_logging and not status_resp['IsLogging']:
set_logging(module, client, name=ct_params['Name'], action='start')
if not enable_logging and status_resp['IsLogging']:
set_logging(module, client, name=ct_params['Name'], action='stop')
# Get facts for newly created Trail
trail = get_trail_facts(module, client, ct_params['Name'])
# If we are in check mode create a fake return structure for the newly minted trail
if module.check_mode:
acct_id = '123456789012'
try:
sts_client = boto3_conn(module, conn_type='client', resource='sts', region=region, endpoint=ec2_url, **aws_connect_params)
acct_id = sts_client.get_caller_identity()['Account']
except ClientError:
pass
trail = dict()
trail.update(ct_params)
trail['LogFileValidationEnabled'] = ct_params['EnableLogFileValidation']
trail.pop('EnableLogFileValidation')
fake_arn = 'arn:aws:cloudtrail:' + region + ':' + acct_id + ':trail/' + ct_params['Name']
trail['HasCustomEventSelectors'] = False
trail['HomeRegion'] = region
trail['TrailARN'] = fake_arn
trail['IsLogging'] = enable_logging
trail['tags'] = tags
# Populate trail facts in output
results['trail'] = camel_dict_to_snake_dict(trail)
module.exit_json(**results)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
8002,
15732,
199,
3612,
63,
1802,
26,
9635,
8142,
2437,
382,
1218,
12,
3145,
12,
1678,
199,
1802,
26,
523,
446,
10560,
12,
21812,
12,
503,
7029,
8142,
2437,
382,
2897,
14,
29652,
2050,
365,
2597,
5223,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
52,
379,
377,
20066,
4654,
2,
272,
446,
298,
29336,
14769,
428,
426,
7722,
68,
8593,
19195,
80,
271,
416,
1353,
278,
2924,
199,
7538,
26,
523,
446,
6055,
19,
523,
446,
21199,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
2654,
503,
2813,
8142,
2437,
382,
2897,
14,
489,
446,
710,
2569,
6363,
1172,
2757,
17731,
367,
8552,
7163,
14,
445,
8,
929,
29,
3827,
9,
436,
445,
8,
929,
29,
7011,
680,
489,
446,
5223,
29,
1881,
436,
6980,
29,
5575,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
3827,
297,
283,
7011,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
367,
314,
8142,
2437,
382,
14,
489,
446,
23923,
787,
3747,
1126,
13,
4551,
7444,
314,
8142,
2437,
382,
365,
282,
3510,
13,
4551,
27225,
12,
315,
1314,
1930,
652,
365,
3747,
1126,
13,
2048,
14,
272,
1415,
26,
2549,
523,
4756,
63,
4806,
26,
272,
1369,
26,
489,
446,
7707,
503,
3631,
314,
8142,
2437,
382,
2050,
14,
982,
15248,
314,
27225,
911,
506,
691,
2972,
436,
911,
440,
2777,
4474,
503,
28503,
943,
1584,
14,
272,
849,
26,
2549,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
308,
19,
63,
4623,
63,
354,
26,
272,
1369,
26,
489,
446,
1626,
3411,
428,
19,
5315,
2382,
8142,
2437,
382,
911,
28503,
943,
1584,
14,
489,
446,
961,
5315,
1077,
2187,
436,
1172,
314,
5576,
4592,
14,
489,
446,
1666,
738,
8,
1014,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
10978,
1958,
63,
7270,
63,
11963,
63,
4623,
63,
3185,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
929,
29,
1881,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
308,
19,
63,
498,
63,
1861,
26,
272,
1369,
26,
489,
446,
428,
19,
2606,
2403,
367,
28218,
943,
1584,
14,
437,
8520,
14457,
365,
440,
5784,
436,
911,
506,
4829,
14,
523,
365,
63,
3029,
63,
4551,
63,
15732,
26,
272,
1369,
26,
489,
446,
13327,
3775,
314,
27225,
15006,
1454,
370,
1373,
4897,
503,
3495,
315,
1006,
16150,
14,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
4756,
63,
793,
63,
493,
63,
6136,
26,
272,
1369,
26,
489,
446,
11015,
3775,
943,
570,
4661,
12997,
6411,
365,
5223,
14,
489,
446,
8142,
2437,
382,
911,
1218,
282,
2631,
367,
4036,
943,
570,
28218,
436,
7389,
282,
10514,
10017,
570,
626,
883,
506,
1202,
370,
4868,
943,
1584,
1172,
440,
2757,
3052,
311,
16179,
14,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
272,
5481,
26,
359,
298,
793,
63,
493,
63,
6136,
63,
3827,
2,
1622,
523,
2387,
63,
2966,
63,
4368,
26,
272,
1369,
26,
489,
446,
12651,
3261,
4882,
687,
2288,
8500,
4066,
465,
28155,
436,
4384,
51,
14,
272,
849,
26,
2549,
272,
5481,
26,
359,
298,
2613,
63,
2966,
63,
1364,
63,
4368,
2,
1622,
523,
308,
561,
63,
5746,
63,
354,
26,
272,
1369,
26,
489,
446,
428,
2709,
32166,
536,
370,
3222,
13116,
370,
1380,
282,
943,
570,
365,
28218,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
8002,
6821,
63,
7270,
63,
3756,
63,
1060,
26,
272,
1369,
26,
489,
446,
11015,
282,
2615,
4160,
46,
367,
376,
28155,
4719,
626,
465,
20440,
314,
5576,
3443,
367,
8142,
2437,
382,
370,
1218,
436,
2218,
370,
314,
943,
1572,
14,
489,
446,
1666,
738,
8,
2859,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
2254,
13,
4091,
15732,
13,
4368,
13,
475,
13,
4091,
6821,
13,
7270,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
4091,
6821,
63,
7270,
63,
793,
63,
923,
63,
1060,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
8002,
6821,
63,
7270,
63,
793,
63,
923,
63,
1060,
26,
272,
1369,
26,
489,
446,
437,
2615,
4160,
46,
9176,
282,
1686,
8142,
13978,
943,
1572,
370,
1314,
8142,
2437,
382,
9610,
911,
506,
28218,
14,
710,
943,
1572,
1077,
2575,
2187,
14,
489,
446,
1666,
738,
8,
2859,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
2254,
13,
4091,
15732,
13,
4368,
13,
475,
13,
4091,
6821,
13,
7270,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
4091,
6821,
63,
7270,
63,
3756,
63,
1060,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
1022,
706,
63,
498,
63,
344,
26,
272,
1369,
26,
489,
446,
11015,
314,
1804,
3053,
790,
2870,
370,
675,
370,
14645,
314,
9610,
28218,
701,
8142,
2437,
382,
14,
961,
2597,
965,
314,
7763,
402,
29310,
943,
570,
14396,
14,
489,
446,
710,
574,
883,
506,
376,
5162,
536,
18239,
701,
298,
3620,
10665,
282,
9999,
2013,
4160,
46,
370,
376,
5162,
12,
282,
9999,
2013,
4160,
46,
370,
282,
790,
12,
503,
282,
26662,
3747,
5148,
14,
489,
446,
1666
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
8002,
15732,
199,
3612,
63,
1802,
26,
9635,
8142,
2437,
382,
1218,
12,
3145,
12,
1678,
199,
1802,
26,
523,
446,
10560,
12,
21812,
12,
503,
7029,
8142,
2437,
382,
2897,
14,
29652,
2050,
365,
2597,
5223,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
272,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
52,
379,
377,
20066,
4654,
2,
272,
446,
298,
29336,
14769,
428,
426,
7722,
68,
8593,
19195,
80,
271,
416,
1353,
278,
2924,
199,
7538,
26,
523,
446,
6055,
19,
523,
446,
21199,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
2654,
503,
2813,
8142,
2437,
382,
2897,
14,
489,
446,
710,
2569,
6363,
1172,
2757,
17731,
367,
8552,
7163,
14,
445,
8,
929,
29,
3827,
9,
436,
445,
8,
929,
29,
7011,
680,
489,
446,
5223,
29,
1881,
436,
6980,
29,
5575,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
1881,
297,
283,
5575,
297,
283,
3827,
297,
283,
7011,
418,
523,
536,
26,
272,
1369,
26,
489,
446,
2812,
367,
314,
8142,
2437,
382,
14,
489,
446,
23923,
787,
3747,
1126,
13,
4551,
7444,
314,
8142,
2437,
382,
365,
282,
3510,
13,
4551,
27225,
12,
315,
1314,
1930,
652,
365,
3747,
1126,
13,
2048,
14,
272,
1415,
26,
2549,
523,
4756,
63,
4806,
26,
272,
1369,
26,
489,
446,
7707,
503,
3631,
314,
8142,
2437,
382,
2050,
14,
982,
15248,
314,
27225,
911,
506,
691,
2972,
436,
911,
440,
2777,
4474,
503,
28503,
943,
1584,
14,
272,
849,
26,
2549,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
308,
19,
63,
4623,
63,
354,
26,
272,
1369,
26,
489,
446,
1626,
3411,
428,
19,
5315,
2382,
8142,
2437,
382,
911,
28503,
943,
1584,
14,
489,
446,
961,
5315,
1077,
2187,
436,
1172,
314,
5576,
4592,
14,
489,
446,
1666,
738,
8,
1014,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
10978,
1958,
63,
7270,
63,
11963,
63,
4623,
63,
3185,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
929,
29,
1881,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
308,
19,
63,
498,
63,
1861,
26,
272,
1369,
26,
489,
446,
428,
19,
2606,
2403,
367,
28218,
943,
1584,
14,
437,
8520,
14457,
365,
440,
5784,
436,
911,
506,
4829,
14,
523,
365,
63,
3029,
63,
4551,
63,
15732,
26,
272,
1369,
26,
489,
446,
13327,
3775,
314,
27225,
15006,
1454,
370,
1373,
4897,
503,
3495,
315,
1006,
16150,
14,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
4756,
63,
793,
63,
493,
63,
6136,
26,
272,
1369,
26,
489,
446,
11015,
3775,
943,
570,
4661,
12997,
6411,
365,
5223,
14,
489,
446,
8142,
2437,
382,
911,
1218,
282,
2631,
367,
4036,
943,
570,
28218,
436,
7389,
282,
10514,
10017,
570,
626,
883,
506,
1202,
370,
4868,
943,
1584,
1172,
440,
2757,
3052,
311,
16179,
14,
272,
849,
26,
3055,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
272,
5481,
26,
359,
298,
793,
63,
493,
63,
6136,
63,
3827,
2,
1622,
523,
2387,
63,
2966,
63,
4368,
26,
272,
1369,
26,
489,
446,
12651,
3261,
4882,
687,
2288,
8500,
4066,
465,
28155,
436,
4384,
51,
14,
272,
849,
26,
2549,
272,
5481,
26,
359,
298,
2613,
63,
2966,
63,
1364,
63,
4368,
2,
1622,
523,
308,
561,
63,
5746,
63,
354,
26,
272,
1369,
26,
489,
446,
428,
2709,
32166,
536,
370,
3222,
13116,
370,
1380,
282,
943,
570,
365,
28218,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
8002,
6821,
63,
7270,
63,
3756,
63,
1060,
26,
272,
1369,
26,
489,
446,
11015,
282,
2615,
4160,
46,
367,
376,
28155,
4719,
626,
465,
20440,
314,
5576,
3443,
367,
8142,
2437,
382,
370,
1218,
436,
2218,
370,
314,
943,
1572,
14,
489,
446,
1666,
738,
8,
2859,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
2254,
13,
4091,
15732,
13,
4368,
13,
475,
13,
4091,
6821,
13,
7270,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
4091,
6821,
63,
7270,
63,
793,
63,
923,
63,
1060,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
8002,
6821,
63,
7270,
63,
793,
63,
923,
63,
1060,
26,
272,
1369,
26,
489,
446,
437,
2615,
4160,
46,
9176,
282,
1686,
8142,
13978,
943,
1572,
370,
1314,
8142,
2437,
382,
9610,
911,
506,
28218,
14,
710,
943,
1572,
1077,
2575,
2187,
14,
489,
446,
1666,
738,
8,
2859,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
10084,
551,
320,
1181,
15732,
15,
7410,
15,
751,
17348,
15,
2254,
13,
4091,
15732,
13,
4368,
13,
475,
13,
4091,
6821,
13,
7270,
14,
1360,
9,
489,
446,
11105,
1380,
445,
8,
4091,
6821,
63,
7270,
63,
3756,
63,
1060,
9,
272,
1015,
63,
3270,
26,
298,
18,
14,
20,
2,
523,
1022,
706,
63,
498,
63,
344,
26,
272,
1369,
26,
489,
446,
11015,
314,
1804,
3053,
790,
2870,
370,
675,
370,
14645,
314,
9610,
28218,
701,
8142,
2437,
382,
14,
961,
2597,
965,
314,
7763,
402,
29310,
943,
570,
14396,
14,
489,
446,
710,
574,
883,
506,
376,
5162,
536,
18239,
701,
298,
3620,
10665,
282,
9999,
2013,
4160,
46,
370,
376,
5162,
12,
282,
9999,
2013,
4160,
46,
370,
282,
790,
12,
503,
282,
26662,
3747,
5148,
14,
489,
446,
1666,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dabiboo/youtube-dl
|
youtube_dl/extractor/xhamster.py
|
24
|
6400
|
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
unified_strdate,
str_to_int,
int_or_none,
parse_duration,
)
class XHamsterIE(InfoExtractor):
_VALID_URL = r'(?P<proto>https?)://(?:.+?\.)?xhamster\.com/movies/(?P<id>[0-9]+)/(?P<seo>.+?)\.html(?:\?.*)?'
_TESTS = [
{
'url': 'http://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.html',
'info_dict': {
'id': '1509445',
'ext': 'mp4',
'title': 'FemaleAgent Shy beauty takes the bait',
'upload_date': '20121014',
'uploader': 'Ruseful2011',
'duration': 893,
'age_limit': 18,
}
},
{
'url': 'http://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hd',
'info_dict': {
'id': '2221348',
'ext': 'mp4',
'title': 'Britney Spears Sexy Booty',
'upload_date': '20130914',
'uploader': 'jojo747400',
'duration': 200,
'age_limit': 18,
}
},
{
'url': 'https://xhamster.com/movies/2272726/amber_slayed_by_the_knight.html',
'only_matching': True,
},
]
def _real_extract(self, url):
def extract_video_url(webpage, name):
return self._search_regex(
[r'''file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)''',
r'''<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumb''',
r'''<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>'''],
webpage, name, group='mp4')
def is_hd(webpage):
return '<div class=\'icon iconHD\'' in webpage
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
seo = mobj.group('seo')
proto = mobj.group('proto')
mrss_url = '%s://xhamster.com/movies/%s/%s.html' % (proto, video_id, seo)
webpage = self._download_webpage(mrss_url, video_id)
title = self._html_search_regex(
[r'<title>(?P<title>.+?)(?:, (?:[^,]+? )?Porn: xHamster| - xHamster\.com)</title>',
r'<h1>([^<]+)</h1>'], webpage, 'title')
# Only a few videos have an description
mobj = re.search(r'<span>Description: </span>([^<]+)', webpage)
description = mobj.group(1) if mobj else None
upload_date = self._html_search_regex(r'hint=\'(\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}\'',
webpage, 'upload date', fatal=False)
if upload_date:
upload_date = unified_strdate(upload_date)
uploader = self._html_search_regex(
r"<a href='[^']+xhamster\.com/user/[^>]+>(?P<uploader>[^<]+)",
webpage, 'uploader', default='anonymous')
thumbnail = self._search_regex(
[r'''thumb\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)''',
r'''<video[^>]+poster=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>'''],
webpage, 'thumbnail', fatal=False, group='thumbnail')
duration = parse_duration(self._html_search_regex(r'<span>Runtime:</span> (\d+:\d+)</div>',
webpage, 'duration', fatal=False))
view_count = self._html_search_regex(r'<span>Views:</span> ([^<]+)</div>', webpage, 'view count', fatal=False)
if view_count:
view_count = str_to_int(view_count)
mobj = re.search(r"hint='(?P<likecount>\d+) Likes / (?P<dislikecount>\d+) Dislikes'", webpage)
(like_count, dislike_count) = (mobj.group('likecount'), mobj.group('dislikecount')) if mobj else (None, None)
mobj = re.search(r'</label>Comments \((?P<commentcount>\d+)\)</div>', webpage)
comment_count = mobj.group('commentcount') if mobj else 0
age_limit = self._rta_search(webpage)
hd = is_hd(webpage)
format_id = 'hd' if hd else 'sd'
video_url = extract_video_url(webpage, format_id)
formats = [{
'url': video_url,
'format_id': 'hd' if hd else 'sd',
'preference': 1,
}]
if not hd:
mrss_url = self._search_regex(r'<link rel="canonical" href="([^"]+)', webpage, 'mrss_url')
webpage = self._download_webpage(mrss_url + '?hd', video_id, note='Downloading HD webpage')
if is_hd(webpage):
video_url = extract_video_url(webpage, 'hd')
formats.append({
'url': video_url,
'format_id': 'hd',
'preference': 2,
})
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'description': description,
'upload_date': upload_date,
'uploader': uploader,
'thumbnail': thumbnail,
'duration': duration,
'view_count': view_count,
'like_count': int_or_none(like_count),
'dislike_count': int_or_none(dislike_count),
'comment_count': int_or_none(comment_count),
'age_limit': age_limit,
'formats': formats,
}
class XHamsterEmbedIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?xhamster\.com/xembed\.php\?video=(?P<id>\d+)'
_TEST = {
'url': 'http://xhamster.com/xembed.php?video=3328539',
'info_dict': {
'id': '3328539',
'ext': 'mp4',
'title': 'Pen Masturbation',
'upload_date': '20140728',
'uploader_id': 'anonymous',
'duration': 5,
'age_limit': 18,
}
}
@staticmethod
def _extract_urls(webpage):
return [url for _, url in re.findall(
r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1',
webpage)]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
video_url = self._search_regex(
r'href="(https?://xhamster\.com/movies/%s/[^"]+\.html[^"]*)"' % video_id,
webpage, 'xhamster url')
return self.url_result(video_url, 'XHamster')
|
unlicense
|
[
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,
25344,
63,
495,
602,
12,
272,
620,
63,
475,
63,
442,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
199,
9,
421,
199,
533,
1323,
40,
455,
11652,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
10120,
48,
28,
2625,
30,
2859,
31,
304,
501,
5169,
11198,
20316,
88,
10670,
11652,
4537,
957,
15,
20888,
9448,
48,
28,
344,
9514,
16,
13,
25,
24598,
2229,
48,
28,
261,
79,
29587,
31477,
1360,
15840,
31,
2795,
5547,
7,
272,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
1046,
1643,
20761,
15,
771,
17667,
4054,
63,
609,
89,
63,
1235,
6898,
89,
63,
31613,
63,
1589,
63,
2470,
390,
14,
1360,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
1046,
1643,
20761,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
3456,
17667,
7788,
428,
3577,
506,
6898,
89,
6181,
314,
330,
2781,
297,
355,
283,
5064,
63,
602,
356,
283,
1797,
2025,
10752,
297,
355,
283,
13671,
356,
283,
50,
1180,
1893,
8128,
297,
355,
283,
5553,
356,
221,
14590,
12,
355,
283,
474,
63,
3097,
356,
6155,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
9485,
969,
2006,
15,
9660,
84,
23263,
63,
12325,
4291,
63,
261,
1702,
63,
4930,
89,
14,
1360,
31,
7952,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
9485,
969,
2006,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
34,
11133,
23263,
428,
321,
4291,
221,
428,
476,
89,
27324,
89,
297,
355,
283,
5064,
63,
602,
356,
283,
1797,
10556,
1079,
297,
355,
283,
13671,
356,
283,
743,
743,
1342,
1342,
383,
297,
355,
283,
5553,
356,
1926,
12,
355,
283,
474,
63,
3097,
356,
6155,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
2859,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
11385,
1465,
1479,
15,
455,
605,
63,
83,
817,
379,
63,
991,
63,
1589,
63,
75,
14873,
14,
1360,
297,
288,
283,
2118,
63,
9467,
356,
715,
12,
267,
1660,
272,
1622,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
347,
5536,
63,
3722,
63,
633,
8,
12022,
12,
536,
304,
288,
372,
291,
423,
1733,
63,
3821,
8,
355,
359,
82,
2344,
493,
60,
83,
10,
3427,
83,
30957,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
9,
18108,
326,
519,
2344,
28,
65,
60,
83,
11,
6399,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
2862,
83,
11,
533,
6270,
418,
311,
20,
2719,
4295,
18108,
326,
519,
2344,
28,
3722,
25524,
493,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
2788,
62,
30,
3672,
30,
891,
995,
355,
9248,
12,
536,
12,
1572,
534,
311,
20,
358,
398,
347,
365,
63,
7952,
8,
12022,
304,
288,
372,
2650,
3015,
1021,
25641,
4677,
7016,
14903,
60,
891,
315,
9248,
398,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
398,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
542,
79,
275,
14208,
14,
923,
360,
261,
79,
358,
267,
4104,
275,
14208,
14,
923,
360,
2625,
358,
267,
333,
13614,
63,
633,
275,
1543,
83,
921,
88,
10670,
11652,
14,
957,
15,
20888,
3149,
83,
3149,
83,
14,
1360,
7,
450,
334,
2625,
12,
3991,
63,
344,
12,
542,
79,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13118,
385,
63,
633,
12,
3991,
63,
344,
9,
398,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
359,
82,
7601,
1213,
30,
2229,
48,
28,
1213,
29587,
9,
5169,
12,
16697,
4735,
12,
2807,
31,
24836,
48,
6161,
26,
671,
40,
455,
11652,
92,
446,
671,
40,
455,
11652,
4537,
957,
15939,
1213,
4206,
1467,
519,
7601,
72,
17,
30,
31204,
11896,
1108,
72,
17,
16619,
9248,
12,
283,
1213,
358,
398,
327,
5972,
282,
9284,
22010,
1172,
376,
1369,
267,
14208,
275,
295,
14,
1733,
8,
82,
7601,
3751,
30,
5831,
26,
3068,
3751,
30,
31204,
28798,
9248,
9,
267,
1369,
275,
14208,
14,
923,
8,
17,
9,
340,
14208,
587,
488,
398,
5802,
63,
602,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7,
6479,
25641,
2961,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
1552,
971,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
359,
33,
13,
58,
8194,
19,
12,
20,
93,
3985,
297,
6343,
9248,
12,
283,
5064,
1434,
297,
14294,
29,
797,
9,
267,
340,
5802,
63,
602,
26,
288,
5802,
63,
602,
275,
25344,
63,
495,
602,
8,
5064,
63,
602,
9,
398,
25257,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
17030,
65,
4369,
534,
4735,
21899,
88,
10670,
11652,
4537,
957,
15,
751,
15,
25524,
30,
2229,
48,
28,
13671,
13489,
28,
2807,
4186,
288,
9248,
12,
283,
13671,
297,
849,
534,
12628,
358,
398,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
359,
82,
2344,
16534,
60,
83,
10,
3427,
83,
30957,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
8311,
29587,
18168,
48,
29,
81,
9,
18108,
1467,
519,
2344,
28,
3722,
25524,
20801,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
8311,
29587,
18168,
48,
29,
81,
2788,
62,
30,
3672,
30,
891,
995,
288,
9248,
12,
283,
8311,
297,
14294,
29,
797,
12,
1572,
534,
8311,
358,
398,
7373,
275,
2198,
63,
5553,
8,
277,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7601,
3751,
30,
14357,
9919,
3751,
30,
14749,
68,
11,
3427,
68,
8771,
1108,
3015
] |
[
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,
25344,
63,
495,
602,
12,
272,
620,
63,
475,
63,
442,
12,
272,
1109,
63,
269,
63,
3592,
12,
272,
2198,
63,
5553,
12,
199,
9,
421,
199,
533,
1323,
40,
455,
11652,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
10120,
48,
28,
2625,
30,
2859,
31,
304,
501,
5169,
11198,
20316,
88,
10670,
11652,
4537,
957,
15,
20888,
9448,
48,
28,
344,
9514,
16,
13,
25,
24598,
2229,
48,
28,
261,
79,
29587,
31477,
1360,
15840,
31,
2795,
5547,
7,
272,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
1046,
1643,
20761,
15,
771,
17667,
4054,
63,
609,
89,
63,
1235,
6898,
89,
63,
31613,
63,
1589,
63,
2470,
390,
14,
1360,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
1046,
1643,
20761,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
3456,
17667,
7788,
428,
3577,
506,
6898,
89,
6181,
314,
330,
2781,
297,
355,
283,
5064,
63,
602,
356,
283,
1797,
2025,
10752,
297,
355,
283,
13671,
356,
283,
50,
1180,
1893,
8128,
297,
355,
283,
5553,
356,
221,
14590,
12,
355,
283,
474,
63,
3097,
356,
6155,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
9485,
969,
2006,
15,
9660,
84,
23263,
63,
12325,
4291,
63,
261,
1702,
63,
4930,
89,
14,
1360,
31,
7952,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
9485,
969,
2006,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
34,
11133,
23263,
428,
321,
4291,
221,
428,
476,
89,
27324,
89,
297,
355,
283,
5064,
63,
602,
356,
283,
1797,
10556,
1079,
297,
355,
283,
13671,
356,
283,
743,
743,
1342,
1342,
383,
297,
355,
283,
5553,
356,
1926,
12,
355,
283,
474,
63,
3097,
356,
6155,
12,
288,
789,
267,
1660,
267,
469,
288,
283,
633,
356,
283,
2859,
921,
88,
10670,
11652,
14,
957,
15,
20888,
15,
11385,
1465,
1479,
15,
455,
605,
63,
83,
817,
379,
63,
991,
63,
1589,
63,
75,
14873,
14,
1360,
297,
288,
283,
2118,
63,
9467,
356,
715,
12,
267,
1660,
272,
1622,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
347,
5536,
63,
3722,
63,
633,
8,
12022,
12,
536,
304,
288,
372,
291,
423,
1733,
63,
3821,
8,
355,
359,
82,
2344,
493,
60,
83,
10,
3427,
83,
30957,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
9,
18108,
326,
519,
2344,
28,
65,
60,
83,
11,
6399,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
2862,
83,
11,
533,
6270,
418,
311,
20,
2719,
4295,
18108,
326,
519,
2344,
28,
3722,
25524,
493,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
311,
20,
29587,
18168,
48,
29,
81,
2788,
62,
30,
3672,
30,
891,
995,
355,
9248,
12,
536,
12,
1572,
534,
311,
20,
358,
398,
347,
365,
63,
7952,
8,
12022,
304,
288,
372,
2650,
3015,
1021,
25641,
4677,
7016,
14903,
60,
891,
315,
9248,
398,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
398,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
542,
79,
275,
14208,
14,
923,
360,
261,
79,
358,
267,
4104,
275,
14208,
14,
923,
360,
2625,
358,
267,
333,
13614,
63,
633,
275,
1543,
83,
921,
88,
10670,
11652,
14,
957,
15,
20888,
3149,
83,
3149,
83,
14,
1360,
7,
450,
334,
2625,
12,
3991,
63,
344,
12,
542,
79,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
13118,
385,
63,
633,
12,
3991,
63,
344,
9,
398,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
359,
82,
7601,
1213,
30,
2229,
48,
28,
1213,
29587,
9,
5169,
12,
16697,
4735,
12,
2807,
31,
24836,
48,
6161,
26,
671,
40,
455,
11652,
92,
446,
671,
40,
455,
11652,
4537,
957,
15939,
1213,
4206,
1467,
519,
7601,
72,
17,
30,
31204,
11896,
1108,
72,
17,
16619,
9248,
12,
283,
1213,
358,
398,
327,
5972,
282,
9284,
22010,
1172,
376,
1369,
267,
14208,
275,
295,
14,
1733,
8,
82,
7601,
3751,
30,
5831,
26,
3068,
3751,
30,
31204,
28798,
9248,
9,
267,
1369,
275,
14208,
14,
923,
8,
17,
9,
340,
14208,
587,
488,
398,
5802,
63,
602,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
82,
7,
6479,
25641,
2961,
68,
91,
20,
93,
2696,
68,
91,
18,
93,
2696,
68,
91,
18,
1552,
971,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
3427,
68,
91,
18,
93,
359,
33,
13,
58,
8194,
19,
12,
20,
93,
3985,
297,
6343,
9248,
12,
283,
5064,
1434,
297,
14294,
29,
797,
9,
267,
340,
5802,
63,
602,
26,
288,
5802,
63,
602,
275,
25344,
63,
495,
602,
8,
5064,
63,
602,
9,
398,
25257,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
17030,
65,
4369,
534,
4735,
21899,
88,
10670,
11652,
4537,
957,
15,
751,
15,
25524,
30,
2229,
48,
28,
13671,
13489,
28,
2807,
4186,
288,
9248,
12,
283,
13671,
297,
849,
534,
12628,
358,
398,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
359,
82,
2344,
16534,
60,
83,
10,
3427,
83,
30957,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
8311,
29587,
18168,
48,
29,
81,
9,
18108,
1467,
519,
2344,
28,
3722,
25524,
20801,
29,
2229,
48,
28,
81,
30,
905,
1105,
2229,
48,
28,
8311,
29587,
18168,
48,
29,
81,
2788,
62,
30,
3672,
30,
891,
995,
288,
9248,
12,
283,
8311,
297,
14294,
29,
797,
12,
1572,
534,
8311,
358,
398,
7373,
275,
2198,
63,
5553,
8,
277,
423,
1360,
63,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dnozay/lettuce
|
tests/integration/lib/Django-1.3/django/contrib/sites/tests.py
|
153
|
2147
|
from django.conf import settings
from django.contrib.sites.models import Site, RequestSite, get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest
from django.test import TestCase
class SitesFrameworkTests(TestCase):
def setUp(self):
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
self.old_Site_meta_installed = Site._meta.installed
Site._meta.installed = True
def tearDown(self):
Site._meta.installed = self.old_Site_meta_installed
def test_site_manager(self):
# Make sure that get_current() does not return a deleted Site object.
s = Site.objects.get_current()
self.assertTrue(isinstance(s, Site))
s.delete()
self.assertRaises(ObjectDoesNotExist, Site.objects.get_current)
def test_site_cache(self):
# After updating a Site object (e.g. via the admin), we shouldn't return a
# bogus value from the SITE_CACHE.
site = Site.objects.get_current()
self.assertEqual(u"example.com", site.name)
s2 = Site.objects.get(id=settings.SITE_ID)
s2.name = "Example site"
s2.save()
site = Site.objects.get_current()
self.assertEqual(u"Example site", site.name)
def test_get_current_site(self):
# Test that the correct Site object is returned
request = HttpRequest()
request.META = {
"SERVER_NAME": "example.com",
"SERVER_PORT": "80",
}
site = get_current_site(request)
self.assertTrue(isinstance(site, Site))
self.assertEqual(site.id, settings.SITE_ID)
# Test that an exception is raised if the sites framework is installed
# but there is no matching Site
site.delete()
self.assertRaises(ObjectDoesNotExist, get_current_site, request)
# A RequestSite is returned if the sites framework is not installed
Site._meta.installed = False
site = get_current_site(request)
self.assertTrue(isinstance(site, RequestSite))
self.assertEqual(site.name, u"example.com")
|
gpl-3.0
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
12,
4784,
8972,
12,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
1014,
492,
20730,
199,
504,
1639,
14,
396,
492,
7640,
421,
199,
533,
428,
4033,
16442,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
11666,
8,
344,
29,
1751,
14,
7917,
63,
998,
12,
2881,
628,
2694,
14,
957,
401,
536,
628,
2694,
14,
957,
3471,
2117,
342,
267,
291,
14,
1753,
63,
8972,
63,
2024,
63,
7657,
275,
11666,
423,
2024,
14,
7657,
267,
11666,
423,
2024,
14,
7657,
275,
715,
339,
347,
6766,
8,
277,
304,
267,
11666,
423,
2024,
14,
7657,
275,
291,
14,
1753,
63,
8972,
63,
2024,
63,
7657,
339,
347,
511,
63,
2124,
63,
2609,
8,
277,
304,
267,
327,
4155,
3238,
626,
664,
63,
1818,
342,
1630,
440,
372,
282,
5463,
11666,
909,
14,
267,
308,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
1815,
8,
6074,
8,
83,
12,
11666,
430,
267,
308,
14,
1807,
342,
267,
291,
14,
1855,
8,
1692,
7400,
12,
11666,
14,
1462,
14,
362,
63,
1818,
9,
339,
347,
511,
63,
2124,
63,
1637,
8,
277,
304,
267,
327,
12836,
12928,
282,
11666,
909,
334,
69,
14,
71,
14,
4799,
314,
4628,
395,
781,
9296,
1133,
372,
282,
267,
327,
23703,
574,
687,
314,
428,
4427,
63,
8677,
14,
267,
4770,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
629,
8,
85,
2,
2694,
14,
957,
401,
4770,
14,
354,
9,
267,
308,
18,
275,
11666,
14,
1462,
14,
362,
8,
344,
29,
1751,
14,
7917,
63,
998,
9,
267,
308,
18,
14,
354,
275,
298,
9846,
4770,
2,
267,
308,
18,
14,
2117,
342,
267,
4770,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
629,
8,
85,
2,
9846,
4770,
401,
4770,
14,
354,
9,
339,
347,
511,
63,
362,
63,
1818,
63,
2124,
8,
277,
304,
267,
327,
1379,
626,
314,
3211,
11666,
909,
365,
2138,
267,
1056,
275,
20730,
342,
267,
1056,
14,
10614,
275,
469,
288,
298,
6613,
63,
2339,
582,
298,
2694,
14,
957,
401,
288,
298,
6613,
63,
3657,
582,
298,
1257,
401,
267,
789,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
291,
14,
1815,
8,
6074,
8,
2124,
12,
11666,
430,
267,
291,
14,
629,
8,
2124,
14,
344,
12,
2202,
14,
7917,
63,
998,
9,
398,
327,
1379,
626,
376,
1919,
365,
4915,
340,
314,
15424,
10059,
365,
4903,
267,
327,
1325,
2337,
365,
949,
4877,
11666,
267,
4770,
14,
1807,
342,
267,
291,
14,
1855,
8,
1692,
7400,
12,
664,
63,
1818,
63,
2124,
12,
1056,
9,
398,
327,
437,
4784,
8972,
365,
2138,
340,
314,
15424,
10059,
365,
440,
4903,
267,
11666,
423,
2024,
14,
7657,
275,
756,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
291,
14,
1815,
8,
6074,
8,
2124,
12,
4784,
8972,
430,
267,
291,
14,
629,
8,
2124,
14,
354,
12,
399,
2,
2694,
14,
957,
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
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
12,
4784,
8972,
12,
664,
63,
1818,
63,
2124,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
199,
504,
1639,
14,
1014,
492,
20730,
199,
504,
1639,
14,
396,
492,
7640,
421,
199,
533,
428,
4033,
16442,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
11666,
8,
344,
29,
1751,
14,
7917,
63,
998,
12,
2881,
628,
2694,
14,
957,
401,
536,
628,
2694,
14,
957,
3471,
2117,
342,
267,
291,
14,
1753,
63,
8972,
63,
2024,
63,
7657,
275,
11666,
423,
2024,
14,
7657,
267,
11666,
423,
2024,
14,
7657,
275,
715,
339,
347,
6766,
8,
277,
304,
267,
11666,
423,
2024,
14,
7657,
275,
291,
14,
1753,
63,
8972,
63,
2024,
63,
7657,
339,
347,
511,
63,
2124,
63,
2609,
8,
277,
304,
267,
327,
4155,
3238,
626,
664,
63,
1818,
342,
1630,
440,
372,
282,
5463,
11666,
909,
14,
267,
308,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
1815,
8,
6074,
8,
83,
12,
11666,
430,
267,
308,
14,
1807,
342,
267,
291,
14,
1855,
8,
1692,
7400,
12,
11666,
14,
1462,
14,
362,
63,
1818,
9,
339,
347,
511,
63,
2124,
63,
1637,
8,
277,
304,
267,
327,
12836,
12928,
282,
11666,
909,
334,
69,
14,
71,
14,
4799,
314,
4628,
395,
781,
9296,
1133,
372,
282,
267,
327,
23703,
574,
687,
314,
428,
4427,
63,
8677,
14,
267,
4770,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
629,
8,
85,
2,
2694,
14,
957,
401,
4770,
14,
354,
9,
267,
308,
18,
275,
11666,
14,
1462,
14,
362,
8,
344,
29,
1751,
14,
7917,
63,
998,
9,
267,
308,
18,
14,
354,
275,
298,
9846,
4770,
2,
267,
308,
18,
14,
2117,
342,
267,
4770,
275,
11666,
14,
1462,
14,
362,
63,
1818,
342,
267,
291,
14,
629,
8,
85,
2,
9846,
4770,
401,
4770,
14,
354,
9,
339,
347,
511,
63,
362,
63,
1818,
63,
2124,
8,
277,
304,
267,
327,
1379,
626,
314,
3211,
11666,
909,
365,
2138,
267,
1056,
275,
20730,
342,
267,
1056,
14,
10614,
275,
469,
288,
298,
6613,
63,
2339,
582,
298,
2694,
14,
957,
401,
288,
298,
6613,
63,
3657,
582,
298,
1257,
401,
267,
789,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
291,
14,
1815,
8,
6074,
8,
2124,
12,
11666,
430,
267,
291,
14,
629,
8,
2124,
14,
344,
12,
2202,
14,
7917,
63,
998,
9,
398,
327,
1379,
626,
376,
1919,
365,
4915,
340,
314,
15424,
10059,
365,
4903,
267,
327,
1325,
2337,
365,
949,
4877,
11666,
267,
4770,
14,
1807,
342,
267,
291,
14,
1855,
8,
1692,
7400,
12,
664,
63,
1818,
63,
2124,
12,
1056,
9,
398,
327,
437,
4784,
8972,
365,
2138,
340,
314,
15424,
10059,
365,
440,
4903,
267,
11666,
423,
2024,
14,
7657,
275,
756,
267,
4770,
275,
664,
63,
1818,
63,
2124,
8,
1069,
9,
267,
291,
14,
1815,
8,
6074,
8,
2124,
12,
4784,
8972,
430,
267,
291,
14,
629,
8,
2124,
14,
354,
12,
399,
2,
2694,
14,
957,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
andresguisado/andresguisado.github.io
|
node_modules/pygmentize-bundled/vendor/pygments/pygments/styles/colorful.py
|
364
|
2778
|
# -*- coding: utf-8 -*-
"""
pygments.styles.colorful
~~~~~~~~~~~~~~~~~~~~~~~~
A colorful style, inspired by CodeRay.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace
class ColorfulStyle(Style):
"""
A colorful style, inspired by CodeRay.
"""
default_style = ""
styles = {
Whitespace: "#bbbbbb",
Comment: "#888",
Comment.Preproc: "#579",
Comment.Special: "bold #cc0000",
Keyword: "bold #080",
Keyword.Pseudo: "#038",
Keyword.Type: "#339",
Operator: "#333",
Operator.Word: "bold #000",
Name.Builtin: "#007020",
Name.Function: "bold #06B",
Name.Class: "bold #B06",
Name.Namespace: "bold #0e84b5",
Name.Exception: "bold #F00",
Name.Variable: "#963",
Name.Variable.Instance: "#33B",
Name.Variable.Class: "#369",
Name.Variable.Global: "bold #d70",
Name.Constant: "bold #036",
Name.Label: "bold #970",
Name.Entity: "bold #800",
Name.Attribute: "#00C",
Name.Tag: "#070",
Name.Decorator: "bold #555",
String: "bg:#fff0f0",
String.Char: "#04D bg:",
String.Doc: "#D42 bg:",
String.Interpol: "bg:#eee",
String.Escape: "bold #666",
String.Regex: "bg:#fff0ff #000",
String.Symbol: "#A60 bg:",
String.Other: "#D20",
Number: "bold #60E",
Number.Integer: "bold #00D",
Number.Float: "bold #60E",
Number.Hex: "bold #058",
Number.Oct: "bold #40E",
Generic.Heading: "bold #000080",
Generic.Subheading: "bold #800080",
Generic.Deleted: "#A00000",
Generic.Inserted: "#00A000",
Generic.Error: "#FF0000",
Generic.Emph: "italic",
Generic.Strong: "bold",
Generic.Prompt: "bold #c65d09",
Generic.Output: "#888",
Generic.Traceback: "#04D",
Error: "#F00 bg:#FAA"
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
2326,
1893,
272,
18294,
4919,
339,
437,
3164,
1893,
3449,
12,
315,
8721,
581,
701,
5495,
25474,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
11581,
1893,
6609,
8,
6609,
304,
272,
408,
272,
437,
3164,
1893,
3449,
12,
315,
8721,
581,
701,
5495,
25474,
14,
272,
408,
339,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
398,
6819,
26,
7861,
5426,
13997,
401,
267,
6819,
14,
19285,
26,
3698,
5426,
14003,
401,
267,
6819,
14,
12246,
26,
3698,
298,
9771,
327,
2055,
993,
401,
398,
6431,
26,
7861,
298,
9771,
327,
27014,
401,
267,
6431,
14,
23414,
26,
3322,
5426,
14273,
401,
267,
6431,
14,
804,
26,
4519,
5426,
11870,
401,
398,
11013,
26,
8295,
5426,
11769,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
1493,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
8255,
10173,
401,
267,
2812,
14,
3481,
26,
3777,
298,
9771,
327,
1690,
34,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
34,
1690,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
16,
69,
1349,
66,
21,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
38,
383,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
24548,
401,
267,
2812,
14,
2773,
14,
3244,
26,
259,
5426,
1153,
34,
401,
267,
2812,
14,
2773,
14,
2543,
26,
755,
5426,
11939,
401,
267,
2812,
14,
2773,
14,
7025,
26,
420,
298,
9771,
327,
68,
2760,
401,
267,
2812,
14,
9737,
26,
3777,
298,
9771,
327,
25368,
401,
267,
2812,
14,
4314,
26,
4483,
298,
9771,
327,
20598,
401,
267,
2812,
14,
7302,
26,
5185,
298,
9771,
327,
6718,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
383,
35,
401,
267,
2812,
14,
1931,
26,
8295,
5426,
19235,
401,
267,
2812,
14,
14946,
26,
3322,
298,
9771,
327,
15722,
401,
398,
2624,
26,
8540,
298,
6856,
15596,
18190,
16,
70,
16,
401,
267,
2624,
14,
1610,
26,
5185,
5426,
966,
36,
12994,
6783,
267,
2624,
14,
3768,
26,
4483,
5426,
36,
2260,
12994,
6783,
267,
2624,
14,
22713,
26,
3698,
298,
6856,
15596,
18777,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
11829,
401,
267,
2624,
14,
5103,
26,
4519,
298,
6856,
15596,
18190,
16,
556,
327,
1493,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
33,
2259,
12994,
6783,
267,
2624,
14,
8632,
26,
4519,
5426,
36,
1165,
401,
398,
4860,
26,
8540,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
2674,
26,
3322,
298,
9771,
327,
383,
36,
401,
267,
4860,
14,
5136,
26,
4519,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
10373,
26,
4483,
298,
9771,
327,
18009,
401,
267,
4860,
14,
17584,
26,
4483,
298,
9771,
327,
2167,
37,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
67,
2182,
68,
1643,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
5426,
38,
383,
12994,
15596,
2078,
33,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
2326,
1893,
272,
18294,
4919,
339,
437,
3164,
1893,
3449,
12,
315,
8721,
581,
701,
5495,
25474,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
11581,
1893,
6609,
8,
6609,
304,
272,
408,
272,
437,
3164,
1893,
3449,
12,
315,
8721,
581,
701,
5495,
25474,
14,
272,
408,
339,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
398,
6819,
26,
7861,
5426,
13997,
401,
267,
6819,
14,
19285,
26,
3698,
5426,
14003,
401,
267,
6819,
14,
12246,
26,
3698,
298,
9771,
327,
2055,
993,
401,
398,
6431,
26,
7861,
298,
9771,
327,
27014,
401,
267,
6431,
14,
23414,
26,
3322,
5426,
14273,
401,
267,
6431,
14,
804,
26,
4519,
5426,
11870,
401,
398,
11013,
26,
8295,
5426,
11769,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
1493,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
8255,
10173,
401,
267,
2812,
14,
3481,
26,
3777,
298,
9771,
327,
1690,
34,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
34,
1690,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
16,
69,
1349,
66,
21,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
38,
383,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
24548,
401,
267,
2812,
14,
2773,
14,
3244,
26,
259,
5426,
1153,
34,
401,
267,
2812,
14,
2773,
14,
2543,
26,
755,
5426,
11939,
401,
267,
2812,
14,
2773,
14,
7025,
26,
420,
298,
9771,
327,
68,
2760,
401,
267,
2812,
14,
9737,
26,
3777,
298,
9771,
327,
25368,
401,
267,
2812,
14,
4314,
26,
4483,
298,
9771,
327,
20598,
401,
267,
2812,
14,
7302,
26,
5185,
298,
9771,
327,
6718,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
383,
35,
401,
267,
2812,
14,
1931,
26,
8295,
5426,
19235,
401,
267,
2812,
14,
14946,
26,
3322,
298,
9771,
327,
15722,
401,
398,
2624,
26,
8540,
298,
6856,
15596,
18190,
16,
70,
16,
401,
267,
2624,
14,
1610,
26,
5185,
5426,
966,
36,
12994,
6783,
267,
2624,
14,
3768,
26,
4483,
5426,
36,
2260,
12994,
6783,
267,
2624,
14,
22713,
26,
3698,
298,
6856,
15596,
18777,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
11829,
401,
267,
2624,
14,
5103,
26,
4519,
298,
6856,
15596,
18190,
16,
556,
327,
1493,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
33,
2259,
12994,
6783,
267,
2624,
14,
8632,
26,
4519,
5426,
36,
1165,
401,
398,
4860,
26,
8540,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
2674,
26,
3322,
298,
9771,
327,
383,
36,
401,
267,
4860,
14,
5136,
26,
4519,
298,
9771,
327,
2259,
37,
401,
267,
4860,
14,
10373,
26,
4483,
298,
9771,
327,
18009,
401,
267,
4860,
14,
17584,
26,
4483,
298,
9771,
327,
2167,
37,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
67,
2182,
68,
1643,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
5426,
38,
383,
12994,
15596,
2078,
33,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cedriclaunay/gaffer
|
python/GafferSceneTest/ShaderTest.py
|
1
|
3822
|
##########################################################################
#
# Copyright (c) 2013, Image Engine Design 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 John Haddon nor the names of
# any other contributors to this software 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 unittest
import IECore
import Gaffer
import GafferTest
import GafferScene
import GafferSceneTest
class ShaderTest( unittest.TestCase ) :
def testDirtyPropagation( self ) :
s = GafferSceneTest.TestShader( "s" )
cs = GafferTest.CapturingSlot( s.plugDirtiedSignal() )
s["parameters"]["i"].setValue( 10 )
d = set( [ a[0].fullName() for a in cs ] )
self.assertTrue( "s.out" in d )
self.assertTrue( "s.out.r" in d )
self.assertTrue( "s.out.g" in d )
self.assertTrue( "s.out.b" in d )
def testDisabling( self ) :
s = GafferSceneTest.TestShader()
self.assertTrue( s["enabled"].isSame( s.enabledPlug() ) )
self.assertEqual( s.correspondingInput( s["out"] ), None )
h = s.stateHash()
self.assertEqual( len( s.state() ), 1 )
s["enabled"].setValue( False )
self.assertEqual( len( s.state() ), 0 )
self.assertNotEqual( s.stateHash(), h )
def testNodeNameBlindData( self ) :
s = GafferSceneTest.TestShader( "node1" )
h1 = s.stateHash()
s1 = s.state()
cs = GafferTest.CapturingSlot( s.plugDirtiedSignal() )
s.setName( "node2" )
self.assertTrue( s["out"] in [ x[0] for x in cs ] )
self.assertNotEqual( s.stateHash(), h1 )
s2 = s.state()
self.assertNotEqual( s2, s1 )
self.assertEqual( s1[0].blindData()["gaffer:nodeName"], IECore.StringData( "node1" ) )
self.assertEqual( s2[0].blindData()["gaffer:nodeName"], IECore.StringData( "node2" ) )
def testShaderTypesInState( self ) :
surface = GafferSceneTest.TestShader( "surface" )
surface["name"].setValue( "testSurface" )
surface["type"].setValue( "test:surface" )
surface["parameters"]["t"] = Gaffer.Color3fPlug()
texture = GafferSceneTest.TestShader( "texture" )
texture["name"].setValue( "testTexture" )
texture["type"].setValue( "test:shader" )
surface["parameters"]["t"].setInput( texture["out"] )
state = surface.state()
self.assertEqual( state[0].type, "test:shader" )
self.assertEqual( state[1].type, "test:surface" )
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
26863,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
6171,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
420,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
14,
199,
3,
199,
3,
420,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
3,
263,
314,
4084,
14,
199,
3,
199,
3,
420,
627,
11443,
314,
536,
402,
17815,
869,
9291,
6590,
314,
1561,
402,
199,
3,
263,
1263,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
263,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
263,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
2882,
199,
199,
646,
14707,
199,
199,
646,
16600,
199,
646,
16600,
774,
199,
646,
16600,
14216,
199,
646,
16600,
14216,
774,
199,
199,
533,
5244,
669,
774,
8,
2882,
14,
1746,
776,
520,
421,
198,
318,
511,
29413,
11376,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
83,
2,
776,
2742,
198,
1259,
275,
16600,
774,
14,
13519,
4039,
15183,
8,
308,
14,
13963,
3567,
29307,
11274,
342,
776,
2742,
198,
83,
905,
3214,
6611,
73,
4140,
14733,
8,
1616,
776,
2742,
198,
68,
275,
663,
8,
359,
282,
59,
16,
1055,
2861,
985,
342,
367,
282,
315,
7117,
1622,
776,
2742,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
82,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
71,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
66,
2,
315,
366,
776,
421,
198,
318,
511,
2825,
14744,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
342,
2742,
198,
277,
14,
1815,
8,
308,
905,
3827,
4140,
374,
8479,
8,
308,
14,
3827,
19173,
342,
776,
776,
507,
198,
277,
14,
629,
8,
308,
14,
989,
31137,
3205,
8,
308,
905,
548,
937,
2318,
488,
776,
2742,
198,
72,
275,
308,
14,
929,
3476,
342,
507,
198,
277,
14,
629,
8,
822,
8,
308,
14,
929,
342,
2318,
413,
776,
2742,
198,
83,
905,
3827,
4140,
14733,
8,
756,
776,
2742,
198,
277,
14,
629,
8,
822,
8,
308,
14,
929,
342,
2318,
378,
776,
507,
198,
277,
14,
7418,
8,
308,
14,
929,
3476,
1062,
394,
776,
421,
198,
318,
511,
1716,
985,
34,
24491,
1451,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
932,
17,
2,
776,
2742,
198,
72,
17,
275,
308,
14,
929,
3476,
342,
507,
198,
83,
17,
275,
308,
14,
929,
342,
2742,
198,
1259,
275,
16600,
774,
14,
13519,
4039,
15183,
8,
308,
14,
13963,
3567,
29307,
11274,
342,
776,
2742,
198,
83,
14,
18347,
8,
298,
932,
18,
2,
776,
2742,
198,
277,
14,
1815,
8,
308,
905,
548,
937,
315,
359,
671,
59,
16,
61,
367,
671,
315,
7117,
1622,
776,
2742,
198,
277,
14,
7418,
8,
308,
14,
929,
3476,
1062,
394,
17,
776,
2742,
198,
83,
18,
275,
308,
14,
929,
342,
507,
198,
277,
14,
7418,
8,
308,
18,
12,
308,
17,
776,
2742,
198,
277,
14,
629,
8,
308,
17,
59,
16,
1055,
66,
24491,
1451,
22957,
5294,
1260,
26,
13777,
2255,
14707,
14,
1558,
1451,
8,
298,
932,
17,
2,
776,
776,
507,
198,
277,
14,
629,
8,
308,
18,
59,
16,
1055,
66,
24491,
1451,
22957,
5294,
1260,
26,
13777,
2255,
14707,
14,
1558,
1451,
8,
298,
932,
18,
2,
776,
776,
421,
198,
318,
511,
21511,
4100,
607,
2223,
8,
291,
776,
520,
2742,
198,
10992,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
10992,
2,
776,
507,
198,
10992,
905,
354,
4140,
14733,
8,
298,
396,
16923,
2,
776,
507,
198,
10992,
905,
466,
4140,
14733,
8,
298,
396,
26,
10992,
2,
776,
507,
198,
10992,
905,
3214,
6611,
84,
937,
275,
16600,
14,
4117,
19,
70,
19173,
342,
2742,
198,
12611,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
12611,
2,
776,
507,
198,
12611,
905,
354,
4140,
14733,
8,
298,
396,
17165,
2,
776,
507,
198,
12611,
905,
466,
4140,
14733,
8,
298,
396,
26,
18116,
2,
776,
2742,
198,
10992,
905,
3214,
6611,
84,
4140,
409,
3205,
8,
14855,
905,
548,
937,
776,
2742,
198,
929,
275,
13195,
14,
929,
342,
507,
198,
277,
14,
629,
8,
1174,
59,
16,
1055,
466,
12,
298,
396,
26,
18116,
2,
776,
507,
198,
277,
14,
629,
8,
1174,
59,
17,
1055
] |
[
199,
3,
199,
3,
221,
1898,
334,
67,
9,
6171,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
420,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
14,
199,
3,
199,
3,
420,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
263,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
263,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
3,
263,
314,
4084,
14,
199,
3,
199,
3,
420,
627,
11443,
314,
536,
402,
17815,
869,
9291,
6590,
314,
1561,
402,
199,
3,
263,
1263,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
263,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
263,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
2882,
199,
199,
646,
14707,
199,
199,
646,
16600,
199,
646,
16600,
774,
199,
646,
16600,
14216,
199,
646,
16600,
14216,
774,
199,
199,
533,
5244,
669,
774,
8,
2882,
14,
1746,
776,
520,
421,
198,
318,
511,
29413,
11376,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
83,
2,
776,
2742,
198,
1259,
275,
16600,
774,
14,
13519,
4039,
15183,
8,
308,
14,
13963,
3567,
29307,
11274,
342,
776,
2742,
198,
83,
905,
3214,
6611,
73,
4140,
14733,
8,
1616,
776,
2742,
198,
68,
275,
663,
8,
359,
282,
59,
16,
1055,
2861,
985,
342,
367,
282,
315,
7117,
1622,
776,
2742,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
82,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
71,
2,
315,
366,
776,
507,
198,
277,
14,
1815,
8,
298,
83,
14,
548,
14,
66,
2,
315,
366,
776,
421,
198,
318,
511,
2825,
14744,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
342,
2742,
198,
277,
14,
1815,
8,
308,
905,
3827,
4140,
374,
8479,
8,
308,
14,
3827,
19173,
342,
776,
776,
507,
198,
277,
14,
629,
8,
308,
14,
989,
31137,
3205,
8,
308,
905,
548,
937,
2318,
488,
776,
2742,
198,
72,
275,
308,
14,
929,
3476,
342,
507,
198,
277,
14,
629,
8,
822,
8,
308,
14,
929,
342,
2318,
413,
776,
2742,
198,
83,
905,
3827,
4140,
14733,
8,
756,
776,
2742,
198,
277,
14,
629,
8,
822,
8,
308,
14,
929,
342,
2318,
378,
776,
507,
198,
277,
14,
7418,
8,
308,
14,
929,
3476,
1062,
394,
776,
421,
198,
318,
511,
1716,
985,
34,
24491,
1451,
8,
291,
776,
520,
2742,
198,
83,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
932,
17,
2,
776,
2742,
198,
72,
17,
275,
308,
14,
929,
3476,
342,
507,
198,
83,
17,
275,
308,
14,
929,
342,
2742,
198,
1259,
275,
16600,
774,
14,
13519,
4039,
15183,
8,
308,
14,
13963,
3567,
29307,
11274,
342,
776,
2742,
198,
83,
14,
18347,
8,
298,
932,
18,
2,
776,
2742,
198,
277,
14,
1815,
8,
308,
905,
548,
937,
315,
359,
671,
59,
16,
61,
367,
671,
315,
7117,
1622,
776,
2742,
198,
277,
14,
7418,
8,
308,
14,
929,
3476,
1062,
394,
17,
776,
2742,
198,
83,
18,
275,
308,
14,
929,
342,
507,
198,
277,
14,
7418,
8,
308,
18,
12,
308,
17,
776,
2742,
198,
277,
14,
629,
8,
308,
17,
59,
16,
1055,
66,
24491,
1451,
22957,
5294,
1260,
26,
13777,
2255,
14707,
14,
1558,
1451,
8,
298,
932,
17,
2,
776,
776,
507,
198,
277,
14,
629,
8,
308,
18,
59,
16,
1055,
66,
24491,
1451,
22957,
5294,
1260,
26,
13777,
2255,
14707,
14,
1558,
1451,
8,
298,
932,
18,
2,
776,
776,
421,
198,
318,
511,
21511,
4100,
607,
2223,
8,
291,
776,
520,
2742,
198,
10992,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
10992,
2,
776,
507,
198,
10992,
905,
354,
4140,
14733,
8,
298,
396,
16923,
2,
776,
507,
198,
10992,
905,
466,
4140,
14733,
8,
298,
396,
26,
10992,
2,
776,
507,
198,
10992,
905,
3214,
6611,
84,
937,
275,
16600,
14,
4117,
19,
70,
19173,
342,
2742,
198,
12611,
275,
16600,
14216,
774,
14,
774,
21511,
8,
298,
12611,
2,
776,
507,
198,
12611,
905,
354,
4140,
14733,
8,
298,
396,
17165,
2,
776,
507,
198,
12611,
905,
466,
4140,
14733,
8,
298,
396,
26,
18116,
2,
776,
2742,
198,
10992,
905,
3214,
6611,
84,
4140,
409,
3205,
8,
14855,
905,
548,
937,
776,
2742,
198,
929,
275,
13195,
14,
929,
342,
507,
198,
277,
14,
629,
8,
1174,
59,
16,
1055,
466,
12,
298,
396,
26,
18116,
2,
776,
507,
198,
277,
14,
629,
8,
1174,
59,
17,
1055,
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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
# -*- coding: utf-8 -*-
# Copyright (c) 2012-2014 CoNWeT Lab., Universidad Politécnica de Madrid
# This file is part of Wirecloud.
# Wirecloud 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.
# Wirecloud 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 Wirecloud. If not, see <http://www.gnu.org/licenses/>.
import os
import re
from shutil import rmtree
from six.moves.urllib.request import pathname2url
import zipfile
from wirecloud.commons.utils.template import TemplateParser
class InvalidContents(Exception):
pass
class WgtFile(object):
_template_filename = 'config.xml'
def __init__(self, _file):
self._zip = zipfile.ZipFile(_file)
def get_underlying_file(self):
return self._zip.fp
def read(self, path):
return self._zip.read(path)
def get_template(self):
try:
return self.read(self._template_filename)
except KeyError:
raise InvalidContents('Missing config.xml at the root of the zipfile (wgt)')
def extract_file(self, file_name, output_path, recreate_=False):
contents = self.read(file_name)
dir_path = os.path.dirname(output_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
f = open(output_path, 'wb')
f.write(contents)
f.close()
def extract_localized_files(self, file_name, output_dir):
(file_root, ext) = os.path.splitext(file_name)
search_re = re.compile(re.escape(file_root) + '(?:.\w\w(?:-\w\w)?)?' + re.escape(ext))
for name in self._zip.namelist():
if search_re.match(name):
self.extract_file(name, os.path.join(output_dir, os.path.basename(name)))
def extract_dir(self, dir_name, output_path):
if not dir_name.endswith('/'):
dir_name += '/'
files = tuple(name for name in self._zip.namelist() if name.startswith(dir_name))
if len(files) == 0:
raise KeyError("There is no directory named '%s' in the archive" % dir_name)
if not os.path.exists(output_path):
os.makedirs(output_path)
for name in files:
local_name = name[len(dir_name):]
listnames = local_name.split("/")[:-1]
folder = output_path
if name.endswith("/"):
for namedir in listnames:
folder += os.sep + namedir.replace("/", os.sep)
if (not os.path.exists(folder)
or (os.path.exists(folder) and not os.path.isdir(folder))):
os.mkdir(folder)
else:
for namedir in listnames:
folder += os.sep + namedir.replace("/", os.sep)
if not os.path.exists(folder) or not os.path.isdir(folder):
os.mkdir(folder)
outfile = open(os.path.join(output_path, local_name.replace("/", os.sep)), 'wb')
outfile.write(self._zip.read(name))
outfile.close()
def extract(self, path):
if not os.path.exists(path) or not os.path.isdir(path):
os.mkdir(path, 0o777)
for name in self._zip.namelist():
listnames = name.split("/")[:-1]
folder = path
if name.endswith("/"):
for namedir in listnames:
folder += os.sep + namedir.replace("/", os.sep)
if (not os.path.exists(folder)
or (os.path.exists(folder) and not os.path.isdir(folder))):
os.mkdir(folder)
else:
for namedir in listnames:
folder += os.sep + namedir.replace("/", os.sep)
if not os.path.exists(folder) or not os.path.isdir(folder):
os.mkdir(folder)
outfile = open(os.path.join(path, name.replace("/", os.sep)), 'wb')
outfile.write(self._zip.read(name))
outfile.close()
def close(self):
self._zip.close()
class WgtDeployer(object):
def __init__(self, root_dir):
self._root_dir = root_dir
@property
def root_dir(self):
return self._root_dir
def get_base_dir(self, vendor, name, version):
return os.path.join(
self._root_dir,
vendor,
name,
version,
)
def deploy(self, wgt_file):
template_content = wgt_file.get_template()
template_parser = TemplateParser(template_content)
widget_rel_dir = os.path.join(
template_parser.get_resource_vendor(),
template_parser.get_resource_name(),
template_parser.get_resource_version(),
)
widget_dir = os.path.join(self._root_dir, widget_rel_dir)
template_parser.set_base(pathname2url(widget_rel_dir) + '/')
self._create_folders(widget_dir)
wgt_file.extract(widget_dir)
return template_parser
def undeploy(self, vendor, name, version):
base_dir = self.get_base_dir(vendor, name, version)
if os.path.isdir(base_dir):
rmtree(base_dir)
def _create_folders(self, widget_dir):
self._create_folder(self._root_dir)
self._create_folder(widget_dir)
def _create_folder(self, folder):
if not os.path.isdir(folder):
os.makedirs(folder)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6029,
13,
7280,
1849,
46,
6004,
52,
16871,
2020,
1910,
4380,
4148,
350,
4376,
1051,
5741,
6413,
24027,
477,
603,
350,
1677,
199,
199,
3,
961,
570,
365,
1777,
402,
644,
3621,
4091,
14,
199,
199,
3,
644,
3621,
4091,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
644,
3621,
4091,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
644,
3621,
4091,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
199,
646,
295,
199,
504,
5145,
492,
20978,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
11776,
18,
633,
199,
646,
10392,
199,
199,
504,
11799,
4091,
14,
2330,
83,
14,
1208,
14,
1160,
492,
5458,
2842,
421,
199,
533,
6378,
11383,
8,
1726,
304,
272,
986,
421,
199,
533,
644,
3308,
1173,
8,
785,
304,
339,
485,
1160,
63,
1501,
275,
283,
888,
14,
1652,
7,
339,
347,
636,
826,
721,
277,
12,
485,
493,
304,
267,
291,
423,
3065,
275,
10392,
14,
15016,
1547,
493,
9,
339,
347,
664,
63,
7138,
6670,
63,
493,
8,
277,
304,
267,
372,
291,
423,
3065,
14,
3997,
339,
347,
1586,
8,
277,
12,
931,
304,
267,
372,
291,
423,
3065,
14,
739,
8,
515,
9,
339,
347,
664,
63,
1160,
8,
277,
304,
267,
862,
26,
288,
372,
291,
14,
739,
8,
277,
423,
1160,
63,
1501,
9,
267,
871,
4067,
26,
288,
746,
6378,
11383,
360,
7718,
1101,
14,
1652,
737,
314,
1738,
402,
314,
10392,
334,
87,
3308,
5942,
339,
347,
5536,
63,
493,
8,
277,
12,
570,
63,
354,
12,
1072,
63,
515,
12,
23959,
10683,
797,
304,
267,
4072,
275,
291,
14,
739,
8,
493,
63,
354,
9,
398,
2935,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
1199,
63,
515,
9,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
694,
63,
515,
304,
288,
747,
14,
8347,
8,
694,
63,
515,
9,
398,
289,
275,
1551,
8,
1199,
63,
515,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
4407,
9,
267,
289,
14,
1600,
342,
339,
347,
5536,
63,
22729,
63,
1725,
8,
277,
12,
570,
63,
354,
12,
1072,
63,
694,
304,
398,
334,
493,
63,
1231,
12,
1599,
9,
275,
747,
14,
515,
14,
7973,
8,
493,
63,
354,
9,
267,
2754,
63,
264,
275,
295,
14,
2014,
8,
264,
14,
3765,
8,
493,
63,
1231,
9,
435,
283,
5169,
3134,
87,
60,
87,
5169,
2696,
87,
60,
87,
5547,
5547,
7,
435,
295,
14,
3765,
8,
832,
430,
267,
367,
536,
315,
291,
423,
3065,
14,
23841,
837,
288,
340,
2754,
63,
264,
14,
1431,
8,
354,
304,
355,
291,
14,
5005,
63,
493,
8,
354,
12,
747,
14,
515,
14,
904,
8,
1199,
63,
694,
12,
747,
14,
515,
14,
4846,
8,
354,
1724,
339,
347,
5536,
63,
694,
8,
277,
12,
2935,
63,
354,
12,
1072,
63,
515,
304,
398,
340,
440,
2935,
63,
354,
14,
4130,
18265,
288,
2935,
63,
354,
847,
7324,
398,
1584,
275,
2008,
8,
354,
367,
536,
315,
291,
423,
3065,
14,
23841,
342,
340,
536,
14,
2460,
8,
694,
63,
354,
430,
398,
340,
822,
8,
1725,
9,
508,
378,
26,
288,
746,
4067,
480,
10924,
365,
949,
2082,
4310,
1543,
83,
7,
315,
314,
6359,
2,
450,
2935,
63,
354,
9,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
1199,
63,
515,
304,
288,
747,
14,
8347,
8,
1199,
63,
515,
9,
398,
367,
536,
315,
1584,
26,
953,
2257,
63,
354,
275,
536,
59,
552,
8,
694,
63,
354,
15405,
288,
769,
1247,
275,
2257,
63,
354,
14,
1294,
19031,
4439,
17,
61,
288,
4922,
275,
1072,
63,
515,
288,
340,
536,
14,
4130,
4769,
2349,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
334,
1397,
747,
14,
515,
14,
2444,
8,
3741,
9,
717,
503,
334,
736,
14,
515,
14,
2444,
8,
3741,
9,
436,
440,
747,
14,
515,
14,
6027,
8,
3741,
15206,
717,
747,
14,
8215,
8,
3741,
9,
288,
587,
26,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
440,
747,
14,
515,
14,
2444,
8,
3741,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
3741,
304,
717,
747,
14,
8215,
8,
3741,
9,
355,
4386,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1199,
63,
515,
12,
2257,
63,
354,
14,
1814,
27374,
747,
14,
4127,
1826,
283,
6603,
358,
355,
4386,
14,
952,
8,
277,
423,
3065,
14,
739,
8,
354,
430,
355,
4386,
14,
1600,
342,
339,
347,
5536,
8,
277,
12,
931,
304,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
747,
14,
8215,
8,
515,
12,
378,
79,
11956,
9,
398,
367,
536,
315,
291,
423,
3065,
14,
23841,
837,
288,
769,
1247,
275,
536,
14,
1294,
19031,
4439,
17,
61,
288,
4922,
275,
931,
288,
340,
536,
14,
4130,
4769,
2349,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
334,
1397,
747,
14,
515,
14,
2444,
8,
3741,
9,
717,
503,
334,
736,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6029,
13,
7280,
1849,
46,
6004,
52,
16871,
2020,
1910,
4380,
4148,
350,
4376,
1051,
5741,
6413,
24027,
477,
603,
350,
1677,
199,
199,
3,
961,
570,
365,
1777,
402,
644,
3621,
4091,
14,
199,
199,
3,
644,
3621,
4091,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
3,
644,
3621,
4091,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
644,
3621,
4091,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
199,
646,
295,
199,
504,
5145,
492,
20978,
199,
504,
3816,
14,
4912,
14,
4078,
14,
1069,
492,
11776,
18,
633,
199,
646,
10392,
199,
199,
504,
11799,
4091,
14,
2330,
83,
14,
1208,
14,
1160,
492,
5458,
2842,
421,
199,
533,
6378,
11383,
8,
1726,
304,
272,
986,
421,
199,
533,
644,
3308,
1173,
8,
785,
304,
339,
485,
1160,
63,
1501,
275,
283,
888,
14,
1652,
7,
339,
347,
636,
826,
721,
277,
12,
485,
493,
304,
267,
291,
423,
3065,
275,
10392,
14,
15016,
1547,
493,
9,
339,
347,
664,
63,
7138,
6670,
63,
493,
8,
277,
304,
267,
372,
291,
423,
3065,
14,
3997,
339,
347,
1586,
8,
277,
12,
931,
304,
267,
372,
291,
423,
3065,
14,
739,
8,
515,
9,
339,
347,
664,
63,
1160,
8,
277,
304,
267,
862,
26,
288,
372,
291,
14,
739,
8,
277,
423,
1160,
63,
1501,
9,
267,
871,
4067,
26,
288,
746,
6378,
11383,
360,
7718,
1101,
14,
1652,
737,
314,
1738,
402,
314,
10392,
334,
87,
3308,
5942,
339,
347,
5536,
63,
493,
8,
277,
12,
570,
63,
354,
12,
1072,
63,
515,
12,
23959,
10683,
797,
304,
267,
4072,
275,
291,
14,
739,
8,
493,
63,
354,
9,
398,
2935,
63,
515,
275,
747,
14,
515,
14,
3475,
8,
1199,
63,
515,
9,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
694,
63,
515,
304,
288,
747,
14,
8347,
8,
694,
63,
515,
9,
398,
289,
275,
1551,
8,
1199,
63,
515,
12,
283,
6603,
358,
267,
289,
14,
952,
8,
4407,
9,
267,
289,
14,
1600,
342,
339,
347,
5536,
63,
22729,
63,
1725,
8,
277,
12,
570,
63,
354,
12,
1072,
63,
694,
304,
398,
334,
493,
63,
1231,
12,
1599,
9,
275,
747,
14,
515,
14,
7973,
8,
493,
63,
354,
9,
267,
2754,
63,
264,
275,
295,
14,
2014,
8,
264,
14,
3765,
8,
493,
63,
1231,
9,
435,
283,
5169,
3134,
87,
60,
87,
5169,
2696,
87,
60,
87,
5547,
5547,
7,
435,
295,
14,
3765,
8,
832,
430,
267,
367,
536,
315,
291,
423,
3065,
14,
23841,
837,
288,
340,
2754,
63,
264,
14,
1431,
8,
354,
304,
355,
291,
14,
5005,
63,
493,
8,
354,
12,
747,
14,
515,
14,
904,
8,
1199,
63,
694,
12,
747,
14,
515,
14,
4846,
8,
354,
1724,
339,
347,
5536,
63,
694,
8,
277,
12,
2935,
63,
354,
12,
1072,
63,
515,
304,
398,
340,
440,
2935,
63,
354,
14,
4130,
18265,
288,
2935,
63,
354,
847,
7324,
398,
1584,
275,
2008,
8,
354,
367,
536,
315,
291,
423,
3065,
14,
23841,
342,
340,
536,
14,
2460,
8,
694,
63,
354,
430,
398,
340,
822,
8,
1725,
9,
508,
378,
26,
288,
746,
4067,
480,
10924,
365,
949,
2082,
4310,
1543,
83,
7,
315,
314,
6359,
2,
450,
2935,
63,
354,
9,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
1199,
63,
515,
304,
288,
747,
14,
8347,
8,
1199,
63,
515,
9,
398,
367,
536,
315,
1584,
26,
953,
2257,
63,
354,
275,
536,
59,
552,
8,
694,
63,
354,
15405,
288,
769,
1247,
275,
2257,
63,
354,
14,
1294,
19031,
4439,
17,
61,
288,
4922,
275,
1072,
63,
515,
288,
340,
536,
14,
4130,
4769,
2349,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
334,
1397,
747,
14,
515,
14,
2444,
8,
3741,
9,
717,
503,
334,
736,
14,
515,
14,
2444,
8,
3741,
9,
436,
440,
747,
14,
515,
14,
6027,
8,
3741,
15206,
717,
747,
14,
8215,
8,
3741,
9,
288,
587,
26,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
440,
747,
14,
515,
14,
2444,
8,
3741,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
3741,
304,
717,
747,
14,
8215,
8,
3741,
9,
355,
4386,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1199,
63,
515,
12,
2257,
63,
354,
14,
1814,
27374,
747,
14,
4127,
1826,
283,
6603,
358,
355,
4386,
14,
952,
8,
277,
423,
3065,
14,
739,
8,
354,
430,
355,
4386,
14,
1600,
342,
339,
347,
5536,
8,
277,
12,
931,
304,
398,
340,
440,
747,
14,
515,
14,
2444,
8,
515,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
747,
14,
8215,
8,
515,
12,
378,
79,
11956,
9,
398,
367,
536,
315,
291,
423,
3065,
14,
23841,
837,
288,
769,
1247,
275,
536,
14,
1294,
19031,
4439,
17,
61,
288,
4922,
275,
931,
288,
340,
536,
14,
4130,
4769,
2349,
355,
367,
536,
694,
315,
769,
1247,
26,
490,
4922,
847,
747,
14,
4127,
435,
536,
694,
14,
1814,
27374,
747,
14,
4127,
9,
490,
340,
334,
1397,
747,
14,
515,
14,
2444,
8,
3741,
9,
717,
503,
334,
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,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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
] |
chromium/chromium
|
tools/binary_size/libsupersize/ninja_parser.py
|
8
|
5118
|
#!/usr/bin/env python3
# Copyright 2017 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.
"""Extract source file information from .ninja files."""
import argparse
import logging
import os
import re
import sys
# E.g.:
# build obj/.../foo.o: cxx gen/.../foo.cc || obj/.../foo.inputdeps.stamp
# build obj/.../libfoo.a: alink obj/.../a.o obj/.../b.o |
# build ./libchrome.so ./lib.unstripped/libchrome.so: solink a.o b.o ...
# build libmonochrome.so: __chrome_android_libmonochrome___rule | ...
_REGEX = re.compile(r'build ([^:]+): \w+ (.*?)(?: *\||\n|$)')
class _SourceMapper(object):
def __init__(self, dep_map, parsed_file_count):
self._dep_map = dep_map
self.parsed_file_count = parsed_file_count
self._unmatched_paths = set()
def _FindSourceForPathInternal(self, path):
if not path.endswith(')'):
return self._dep_map.get(path)
# foo/bar.a(baz.o)
start_idx = path.index('(')
lib_name = path[:start_idx]
obj_name = path[start_idx + 1:-1]
by_basename = self._dep_map.get(lib_name)
if not by_basename:
return None
obj_path = by_basename.get(obj_name)
if not obj_path:
# Found the library, but it doesn't list the .o file.
logging.warning('no obj basename for %s', path)
return None
return self._dep_map.get(obj_path)
def FindSourceForPath(self, path):
"""Returns the source path for the given object path (or None if not found).
Paths for objects within archives should be in the format: foo/bar.a(baz.o)
"""
ret = self._FindSourceForPathInternal(path)
if not ret and path not in self._unmatched_paths:
if self.unmatched_paths_count < 10:
logging.warning('Could not find source path for %s', path)
self._unmatched_paths.add(path)
return ret
@property
def unmatched_paths_count(self):
return len(self._unmatched_paths)
def IterAllPaths(self):
return self._dep_map.keys()
def _ParseNinjaPathList(path_list):
ret = path_list.replace('\\ ', '\b')
return [s.replace('\b', ' ') for s in ret.split()]
def _ParseOneFile(lines, dep_map, elf_path):
sub_ninjas = []
elf_inputs = None
for line in lines:
if line.startswith('subninja '):
sub_ninjas.append(line[9:-1])
continue
m = _REGEX.match(line)
if m:
outputs, srcs = m.groups()
if len(outputs) > 2 and outputs[-2] == '.' and outputs[-1] in 'ao':
output = outputs.replace('\\ ', ' ')
assert output not in dep_map, 'Duplicate output: ' + output
if output[-1] == 'o':
dep_map[output] = srcs.replace('\\ ', ' ')
else:
obj_paths = _ParseNinjaPathList(srcs)
dep_map[output] = {os.path.basename(p): p for p in obj_paths}
elif elf_path and elf_path in outputs:
properly_parsed = [
os.path.normpath(p) for p in _ParseNinjaPathList(outputs)]
if elf_path in properly_parsed:
elf_inputs = _ParseNinjaPathList(srcs)
return sub_ninjas, elf_inputs
def ParseOneFileForTest(lines, dep_map, elf_path):
return _ParseOneFile(lines, dep_map, elf_path)
def Parse(output_directory, elf_path):
"""Parses build.ninja and subninjas.
Args:
output_directory: Where to find the root build.ninja.
elf_path: Path to elf file to find inputs for.
Returns: A tuple of (source_mapper, elf_inputs).
"""
if elf_path:
elf_path = os.path.relpath(elf_path, output_directory)
to_parse = ['build.ninja']
seen_paths = set(to_parse)
dep_map = {}
elf_inputs = None
while to_parse:
path = os.path.join(output_directory, to_parse.pop())
with open(path) as obj:
sub_ninjas, found_elf_inputs = _ParseOneFile(obj, dep_map, elf_path)
if found_elf_inputs:
assert not elf_inputs, 'Found multiple inputs for elf_path ' + elf_path
elf_inputs = found_elf_inputs
for subpath in sub_ninjas:
assert subpath not in seen_paths, 'Double include of ' + subpath
seen_paths.add(subpath)
to_parse.extend(sub_ninjas)
return _SourceMapper(dep_map, len(seen_paths)), elf_inputs
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--output-directory', required=True)
parser.add_argument('--elf-path')
parser.add_argument('--show-inputs', action='store_true')
parser.add_argument('--show-mappings', action='store_true')
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG,
format='%(levelname).1s %(relativeCreated)6d %(message)s')
source_mapper, elf_inputs = Parse(args.output_directory, args.elf_path)
if not elf_inputs:
elf_inputs = []
print('Found {} elf_inputs, and {} source mappings'.format(
len(elf_inputs), len(source_mapper._dep_map)))
if args.show_inputs:
print('elf_inputs:')
print('\n'.join(elf_inputs))
if args.show_mappings:
print('object_path -> source_path:')
for path in source_mapper.IterAllPaths():
print('{} -> {}'.format(path, source_mapper.FindSourceForPath(path)))
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
9708,
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,
624,
12147,
1350,
570,
2556,
687,
1275,
8675,
1584,
1041,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
3,
662,
14,
71,
16781,
199,
3,
1900,
1559,
15,
1396,
15,
1421,
14,
79,
26,
17327,
3805,
15,
1396,
15,
1421,
14,
2055,
12208,
1559,
15,
1396,
15,
1421,
14,
1210,
5846,
14,
2359,
199,
3,
1900,
1559,
15,
1396,
15,
773,
1421,
14,
65,
26,
741,
2292,
1559,
15,
1396,
15,
65,
14,
79,
1559,
15,
1396,
15,
66,
14,
79,
1204,
199,
3,
1900,
16605,
773,
9887,
14,
1152,
16605,
773,
14,
324,
25382,
15,
773,
9887,
14,
1152,
26,
8597,
2292,
282,
14,
79,
330,
14,
79,
2263,
199,
3,
1900,
1973,
19758,
9887,
14,
1152,
26,
636,
9887,
63,
6238,
63,
773,
19758,
9887,
8989,
2200,
1204,
2263,
199,
63,
10710,
275,
295,
14,
2014,
8,
82,
7,
1506,
334,
4735,
26,
2807,
304,
971,
87,
11,
334,
6697,
9,
5169,
30940,
92,
6113,
78,
92,
4,
5942,
421,
199,
533,
485,
2980,
11880,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2657,
63,
1130,
12,
4565,
63,
493,
63,
835,
304,
272,
291,
423,
2601,
63,
1130,
275,
2657,
63,
1130,
272,
291,
14,
6751,
63,
493,
63,
835,
275,
4565,
63,
493,
63,
835,
272,
291,
423,
324,
10151,
63,
3771,
275,
663,
342,
819,
347,
485,
6591,
2980,
1858,
2042,
8405,
8,
277,
12,
931,
304,
272,
340,
440,
931,
14,
4130,
15938,
735,
489,
372,
291,
423,
2601,
63,
1130,
14,
362,
8,
515,
9,
339,
327,
3925,
15,
1700,
14,
65,
8,
6185,
14,
79,
9,
272,
1343,
63,
2996,
275,
931,
14,
1080,
14097,
358,
272,
1973,
63,
354,
275,
931,
1491,
928,
63,
2996,
61,
272,
1559,
63,
354,
275,
931,
59,
928,
63,
2996,
435,
413,
6809,
17,
61,
272,
701,
63,
4846,
275,
291,
423,
2601,
63,
1130,
14,
362,
8,
773,
63,
354,
9,
272,
340,
440,
701,
63,
4846,
26,
489,
372,
488,
272,
1559,
63,
515,
275,
701,
63,
4846,
14,
362,
8,
1113,
63,
354,
9,
272,
340,
440,
1559,
63,
515,
26,
489,
327,
2643,
314,
3555,
12,
1325,
652,
3181,
1133,
769,
314,
1275,
79,
570,
14,
489,
2050,
14,
3764,
360,
889,
1559,
9593,
367,
450,
83,
297,
931,
9,
489,
372,
488,
272,
372,
291,
423,
2601,
63,
1130,
14,
362,
8,
1113,
63,
515,
9,
819,
347,
6668,
2980,
1858,
2042,
8,
277,
12,
931,
304,
272,
408,
3407,
314,
1350,
931,
367,
314,
1627,
909,
931,
334,
269,
488,
340,
440,
1911,
680,
339,
6912,
83,
367,
2251,
4453,
25993,
1077,
506,
315,
314,
1475,
26,
3925,
15,
1700,
14,
65,
8,
6185,
14,
79,
9,
272,
408,
272,
2203,
275,
291,
423,
6591,
2980,
1858,
2042,
8405,
8,
515,
9,
272,
340,
440,
2203,
436,
931,
440,
315,
291,
423,
324,
10151,
63,
3771,
26,
489,
340,
291,
14,
324,
10151,
63,
3771,
63,
835,
665,
1616,
26,
267,
2050,
14,
3764,
360,
6531,
440,
2342,
1350,
931,
367,
450,
83,
297,
931,
9,
489,
291,
423,
324,
10151,
63,
3771,
14,
525,
8,
515,
9,
272,
372,
2203,
819,
768,
1829,
523,
347,
625,
10151,
63,
3771,
63,
835,
8,
277,
304,
272,
372,
822,
8,
277,
423,
324,
10151,
63,
3771,
9,
819,
347,
11953,
2422,
11804,
8,
277,
304,
272,
372,
291,
423,
2601,
63,
1130,
14,
1612,
342,
421,
199,
318,
485,
4003,
24237,
2042,
1296,
8,
515,
63,
513,
304,
523,
2203,
275,
931,
63,
513,
14,
1814,
11671,
1656,
1557,
66,
358,
523,
372,
359,
83,
14,
1814,
2258,
66,
297,
283,
5320,
367,
308,
315,
2203,
14,
1294,
5106,
421,
199,
318,
485,
4003,
4395,
1173,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
304,
523,
1007,
63,
28693,
74,
305,
275,
942,
523,
325,
276,
63,
3711,
275,
488,
523,
367,
1004,
315,
2385,
26,
272,
340,
1004,
14,
2460,
360,
954,
8675,
18927,
489,
1007,
63,
28693,
74,
305,
14,
740,
8,
604,
59,
25,
6809,
17,
566,
489,
1980,
272,
333,
275,
485,
10710,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
489,
4704,
12,
2928,
83,
275,
333,
14,
2634,
342,
489,
340,
822,
8,
4467,
9,
690,
499,
436,
4704,
1988,
18,
61,
508,
7815,
436,
4704,
1988,
17,
61,
315,
283,
8035,
356,
267,
1072,
275,
4704,
14,
1814,
11671,
1656,
283,
5320,
267,
702,
1072,
440,
315,
2657,
63,
1130,
12,
283,
14773,
1072,
26,
283,
435,
1072,
267,
340,
1072,
1988,
17,
61,
508,
283,
79,
356,
881,
2657,
63,
1130,
59,
1199,
61,
275,
2928,
83,
14,
1814,
11671,
1656,
283,
5320,
267,
587,
26,
881,
1559,
63,
3771,
275,
485,
4003,
24237,
2042,
1296,
8,
2164,
83,
9,
881,
2657,
63,
1130,
59,
1199,
61,
275,
469,
736,
14,
515,
14,
4846,
8,
80,
304,
299,
367,
299,
315,
1559,
63,
3771,
93,
489,
916,
325,
276,
63,
515,
436,
325,
276,
63,
515,
315,
4704,
26,
267,
7684,
63,
6751,
275,
359,
288,
747,
14,
515,
14,
9267,
8,
80,
9,
367,
299,
315,
485,
4003,
24237,
2042,
1296,
8,
4467,
1874,
267,
340,
325,
276,
63,
515,
315,
7684,
63,
6751,
26,
881,
325,
276,
63,
3711,
275,
485,
4003,
24237,
2042,
1296,
8,
2164,
83,
9,
523,
372,
1007,
63,
28693,
74,
305,
12,
325,
276,
63,
3711,
421,
199,
318,
6077,
4395,
1173,
1858,
774,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
304,
523,
372,
485,
4003,
4395,
1173,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
9,
421,
199,
318,
6077,
8,
1199,
63,
3619,
12,
325,
276,
63,
515,
304,
523,
408,
23400,
1900,
14,
8675,
436,
1007,
28693,
74,
305,
14,
819,
3033,
26,
272,
1072,
63
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
9708,
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,
624,
12147,
1350,
570,
2556,
687,
1275,
8675,
1584,
1041,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
984,
421,
199,
3,
662,
14,
71,
16781,
199,
3,
1900,
1559,
15,
1396,
15,
1421,
14,
79,
26,
17327,
3805,
15,
1396,
15,
1421,
14,
2055,
12208,
1559,
15,
1396,
15,
1421,
14,
1210,
5846,
14,
2359,
199,
3,
1900,
1559,
15,
1396,
15,
773,
1421,
14,
65,
26,
741,
2292,
1559,
15,
1396,
15,
65,
14,
79,
1559,
15,
1396,
15,
66,
14,
79,
1204,
199,
3,
1900,
16605,
773,
9887,
14,
1152,
16605,
773,
14,
324,
25382,
15,
773,
9887,
14,
1152,
26,
8597,
2292,
282,
14,
79,
330,
14,
79,
2263,
199,
3,
1900,
1973,
19758,
9887,
14,
1152,
26,
636,
9887,
63,
6238,
63,
773,
19758,
9887,
8989,
2200,
1204,
2263,
199,
63,
10710,
275,
295,
14,
2014,
8,
82,
7,
1506,
334,
4735,
26,
2807,
304,
971,
87,
11,
334,
6697,
9,
5169,
30940,
92,
6113,
78,
92,
4,
5942,
421,
199,
533,
485,
2980,
11880,
8,
785,
304,
523,
347,
636,
826,
721,
277,
12,
2657,
63,
1130,
12,
4565,
63,
493,
63,
835,
304,
272,
291,
423,
2601,
63,
1130,
275,
2657,
63,
1130,
272,
291,
14,
6751,
63,
493,
63,
835,
275,
4565,
63,
493,
63,
835,
272,
291,
423,
324,
10151,
63,
3771,
275,
663,
342,
819,
347,
485,
6591,
2980,
1858,
2042,
8405,
8,
277,
12,
931,
304,
272,
340,
440,
931,
14,
4130,
15938,
735,
489,
372,
291,
423,
2601,
63,
1130,
14,
362,
8,
515,
9,
339,
327,
3925,
15,
1700,
14,
65,
8,
6185,
14,
79,
9,
272,
1343,
63,
2996,
275,
931,
14,
1080,
14097,
358,
272,
1973,
63,
354,
275,
931,
1491,
928,
63,
2996,
61,
272,
1559,
63,
354,
275,
931,
59,
928,
63,
2996,
435,
413,
6809,
17,
61,
272,
701,
63,
4846,
275,
291,
423,
2601,
63,
1130,
14,
362,
8,
773,
63,
354,
9,
272,
340,
440,
701,
63,
4846,
26,
489,
372,
488,
272,
1559,
63,
515,
275,
701,
63,
4846,
14,
362,
8,
1113,
63,
354,
9,
272,
340,
440,
1559,
63,
515,
26,
489,
327,
2643,
314,
3555,
12,
1325,
652,
3181,
1133,
769,
314,
1275,
79,
570,
14,
489,
2050,
14,
3764,
360,
889,
1559,
9593,
367,
450,
83,
297,
931,
9,
489,
372,
488,
272,
372,
291,
423,
2601,
63,
1130,
14,
362,
8,
1113,
63,
515,
9,
819,
347,
6668,
2980,
1858,
2042,
8,
277,
12,
931,
304,
272,
408,
3407,
314,
1350,
931,
367,
314,
1627,
909,
931,
334,
269,
488,
340,
440,
1911,
680,
339,
6912,
83,
367,
2251,
4453,
25993,
1077,
506,
315,
314,
1475,
26,
3925,
15,
1700,
14,
65,
8,
6185,
14,
79,
9,
272,
408,
272,
2203,
275,
291,
423,
6591,
2980,
1858,
2042,
8405,
8,
515,
9,
272,
340,
440,
2203,
436,
931,
440,
315,
291,
423,
324,
10151,
63,
3771,
26,
489,
340,
291,
14,
324,
10151,
63,
3771,
63,
835,
665,
1616,
26,
267,
2050,
14,
3764,
360,
6531,
440,
2342,
1350,
931,
367,
450,
83,
297,
931,
9,
489,
291,
423,
324,
10151,
63,
3771,
14,
525,
8,
515,
9,
272,
372,
2203,
819,
768,
1829,
523,
347,
625,
10151,
63,
3771,
63,
835,
8,
277,
304,
272,
372,
822,
8,
277,
423,
324,
10151,
63,
3771,
9,
819,
347,
11953,
2422,
11804,
8,
277,
304,
272,
372,
291,
423,
2601,
63,
1130,
14,
1612,
342,
421,
199,
318,
485,
4003,
24237,
2042,
1296,
8,
515,
63,
513,
304,
523,
2203,
275,
931,
63,
513,
14,
1814,
11671,
1656,
1557,
66,
358,
523,
372,
359,
83,
14,
1814,
2258,
66,
297,
283,
5320,
367,
308,
315,
2203,
14,
1294,
5106,
421,
199,
318,
485,
4003,
4395,
1173,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
304,
523,
1007,
63,
28693,
74,
305,
275,
942,
523,
325,
276,
63,
3711,
275,
488,
523,
367,
1004,
315,
2385,
26,
272,
340,
1004,
14,
2460,
360,
954,
8675,
18927,
489,
1007,
63,
28693,
74,
305,
14,
740,
8,
604,
59,
25,
6809,
17,
566,
489,
1980,
272,
333,
275,
485,
10710,
14,
1431,
8,
604,
9,
272,
340,
333,
26,
489,
4704,
12,
2928,
83,
275,
333,
14,
2634,
342,
489,
340,
822,
8,
4467,
9,
690,
499,
436,
4704,
1988,
18,
61,
508,
7815,
436,
4704,
1988,
17,
61,
315,
283,
8035,
356,
267,
1072,
275,
4704,
14,
1814,
11671,
1656,
283,
5320,
267,
702,
1072,
440,
315,
2657,
63,
1130,
12,
283,
14773,
1072,
26,
283,
435,
1072,
267,
340,
1072,
1988,
17,
61,
508,
283,
79,
356,
881,
2657,
63,
1130,
59,
1199,
61,
275,
2928,
83,
14,
1814,
11671,
1656,
283,
5320,
267,
587,
26,
881,
1559,
63,
3771,
275,
485,
4003,
24237,
2042,
1296,
8,
2164,
83,
9,
881,
2657,
63,
1130,
59,
1199,
61,
275,
469,
736,
14,
515,
14,
4846,
8,
80,
304,
299,
367,
299,
315,
1559,
63,
3771,
93,
489,
916,
325,
276,
63,
515,
436,
325,
276,
63,
515,
315,
4704,
26,
267,
7684,
63,
6751,
275,
359,
288,
747,
14,
515,
14,
9267,
8,
80,
9,
367,
299,
315,
485,
4003,
24237,
2042,
1296,
8,
4467,
1874,
267,
340,
325,
276,
63,
515,
315,
7684,
63,
6751,
26,
881,
325,
276,
63,
3711,
275,
485,
4003,
24237,
2042,
1296,
8,
2164,
83,
9,
523,
372,
1007,
63,
28693,
74,
305,
12,
325,
276,
63,
3711,
421,
199,
318,
6077,
4395,
1173,
1858,
774,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
304,
523,
372,
485,
4003,
4395,
1173,
8,
1278,
12,
2657,
63,
1130,
12,
325,
276,
63,
515,
9,
421,
199,
318,
6077,
8,
1199,
63,
3619,
12,
325,
276,
63,
515,
304,
523,
408,
23400,
1900,
14,
8675,
436,
1007,
28693,
74,
305,
14,
819,
3033,
26,
272,
1072,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chovanecm/sacredboard
|
sacredboard/tests/test_bootstrap.py
|
1
|
2528
|
# coding=utf-8
import pytest
import sacredboard.bootstrap as bootstrap
@pytest.fixture
def app():
return bootstrap.Flask(__name__)
@pytest.fixture()
def app_config():
return {
"http.serve_on_endpoint": "/",
"http.port": 5000,
"debug": False
}
@pytest.mark.parametrize("config_string",
("", "database_name", "789:db_name",
"anotherhost:789:db_name", "bla:bla:bla"))
def test_add_mongo_config(config_string, app):
if config_string == "bla:bla:bla":
with pytest.raises(ValueError):
bootstrap.add_mongo_config_simple(app, config_string, "collection_name")
else:
bootstrap.add_mongo_config_simple(app, config_string, "collection_name")
mongo_client = app.config["data"]
if config_string == "":
assert mongo_client._uri == "mongodb://localhost:27017"
assert (mongo_client._db_name == "sacred")
elif config_string == "database_name":
assert mongo_client._uri == "mongodb://localhost:27017"
assert (mongo_client._db_name == "database_name")
elif config_string == "789:db_name":
assert mongo_client._uri == "mongodb://localhost:789"
assert (mongo_client._db_name == "db_name")
elif config_string == "anotherhost:789:db_name":
assert mongo_client._uri == "mongodb://anotherhost:789"
assert (mongo_client._db_name == "db_name")
@pytest.mark.parametrize("connection_string", ("mongodb://user:password@192.168.0.1:1234?connectTimeoutMS=300000",
"mongodb://192.168.0.1:1234?connectTimeoutMS=300000"))
def test_add_mongo_config_with_uri(connection_string, app):
bootstrap.add_mongo_config_with_uri(app, connection_string, "db_name", "collection_name")
mongo_client = app.config["data"]
if connection_string == "mongodb://user:password@192.168.0.1:1234?connectTimeoutMS=300000":
assert mongo_client._uri == "mongodb://user:password@192.168.0.1:1234?connectTimeoutMS=300000"
elif connection_string == "mongodb://192.168.0.1:1234?connectTimeoutMS=300000":
assert mongo_client._uri == "mongodb://192.168.0.1:1234?connectTimeoutMS=300000"
assert (mongo_client._db_name == "db_name")
def test_module_initialisation_method_call_only(app_config):
"""Only test calling module initialisation to see that no module causes the application to crash"""
bootstrap._initialize_modules(app_config)
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
646,
4613,
199,
199,
646,
308,
645,
581,
3576,
14,
11146,
465,
15865,
421,
199,
32,
4462,
14,
5997,
199,
318,
1145,
837,
272,
372,
15865,
14,
14182,
3460,
354,
3368,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
1145,
63,
888,
837,
272,
372,
469,
267,
298,
1014,
14,
4909,
63,
265,
63,
6520,
582,
3286,
401,
267,
298,
1014,
14,
719,
582,
22369,
12,
267,
298,
1757,
582,
756,
272,
789,
199,
199,
32,
4462,
14,
1657,
14,
10396,
480,
888,
63,
875,
401,
586,
24727,
298,
4659,
63,
354,
401,
298,
24407,
26,
697,
63,
354,
401,
2079,
298,
13565,
1102,
26,
24407,
26,
697,
63,
354,
401,
298,
21244,
26,
21244,
26,
21244,
2237,
199,
318,
511,
63,
525,
63,
9217,
63,
888,
8,
888,
63,
875,
12,
1145,
304,
272,
340,
1101,
63,
875,
508,
298,
21244,
26,
21244,
26,
21244,
582,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
15865,
14,
525,
63,
9217,
63,
888,
63,
4129,
8,
571,
12,
1101,
63,
875,
12,
298,
3627,
63,
354,
531,
272,
587,
26,
267,
15865,
14,
525,
63,
9217,
63,
888,
63,
4129,
8,
571,
12,
1101,
63,
875,
12,
298,
3627,
63,
354,
531,
267,
18006,
63,
1258,
275,
1145,
14,
888,
905,
576,
937,
267,
340,
1101,
63,
875,
508,
10812,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
1465,
9570,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
83,
645,
581,
531,
267,
916,
1101,
63,
875,
508,
298,
4659,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
1465,
9570,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
4659,
63,
354,
531,
267,
916,
1101,
63,
875,
508,
298,
24407,
26,
697,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
24407,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
267,
916,
1101,
63,
875,
508,
298,
13565,
1102,
26,
24407,
26,
697,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
13565,
1102,
26,
24407,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2105,
63,
875,
401,
1689,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
401,
6901,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2237,
199,
318,
511,
63,
525,
63,
9217,
63,
888,
63,
1045,
63,
2302,
8,
2105,
63,
875,
12,
1145,
304,
272,
15865,
14,
525,
63,
9217,
63,
888,
63,
1045,
63,
2302,
8,
571,
12,
1950,
63,
875,
12,
298,
697,
63,
354,
401,
298,
3627,
63,
354,
531,
272,
18006,
63,
1258,
275,
1145,
14,
888,
905,
576,
937,
339,
340,
1950,
63,
875,
508,
298,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
582,
267,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2,
272,
916,
1950,
63,
875,
508,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
582,
267,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2,
339,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
421,
199,
318,
511,
63,
578,
63,
2747,
19914,
63,
765,
63,
1250,
63,
2118,
8,
571,
63,
888,
304,
272,
408,
5903,
511,
6358,
859,
2536,
19914,
370,
1937,
626,
949,
859,
14486,
314,
4223,
370,
12420,
624,
272,
15865,
423,
8489,
63,
3112,
8,
571,
63,
888,
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
] |
[
2803,
29,
1624,
13,
24,
199,
646,
4613,
199,
199,
646,
308,
645,
581,
3576,
14,
11146,
465,
15865,
421,
199,
32,
4462,
14,
5997,
199,
318,
1145,
837,
272,
372,
15865,
14,
14182,
3460,
354,
3368,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
1145,
63,
888,
837,
272,
372,
469,
267,
298,
1014,
14,
4909,
63,
265,
63,
6520,
582,
3286,
401,
267,
298,
1014,
14,
719,
582,
22369,
12,
267,
298,
1757,
582,
756,
272,
789,
199,
199,
32,
4462,
14,
1657,
14,
10396,
480,
888,
63,
875,
401,
586,
24727,
298,
4659,
63,
354,
401,
298,
24407,
26,
697,
63,
354,
401,
2079,
298,
13565,
1102,
26,
24407,
26,
697,
63,
354,
401,
298,
21244,
26,
21244,
26,
21244,
2237,
199,
318,
511,
63,
525,
63,
9217,
63,
888,
8,
888,
63,
875,
12,
1145,
304,
272,
340,
1101,
63,
875,
508,
298,
21244,
26,
21244,
26,
21244,
582,
267,
543,
4613,
14,
3536,
8,
3393,
304,
288,
15865,
14,
525,
63,
9217,
63,
888,
63,
4129,
8,
571,
12,
1101,
63,
875,
12,
298,
3627,
63,
354,
531,
272,
587,
26,
267,
15865,
14,
525,
63,
9217,
63,
888,
63,
4129,
8,
571,
12,
1101,
63,
875,
12,
298,
3627,
63,
354,
531,
267,
18006,
63,
1258,
275,
1145,
14,
888,
905,
576,
937,
267,
340,
1101,
63,
875,
508,
10812,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
1465,
9570,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
83,
645,
581,
531,
267,
916,
1101,
63,
875,
508,
298,
4659,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
1465,
9570,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
4659,
63,
354,
531,
267,
916,
1101,
63,
875,
508,
298,
24407,
26,
697,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5967,
26,
24407,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
267,
916,
1101,
63,
875,
508,
298,
13565,
1102,
26,
24407,
26,
697,
63,
354,
582,
288,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
13565,
1102,
26,
24407,
2,
288,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2105,
63,
875,
401,
1689,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
401,
6901,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2237,
199,
318,
511,
63,
525,
63,
9217,
63,
888,
63,
1045,
63,
2302,
8,
2105,
63,
875,
12,
1145,
304,
272,
15865,
14,
525,
63,
9217,
63,
888,
63,
1045,
63,
2302,
8,
571,
12,
1950,
63,
875,
12,
298,
697,
63,
354,
401,
298,
3627,
63,
354,
531,
272,
18006,
63,
1258,
275,
1145,
14,
888,
905,
576,
937,
339,
340,
1950,
63,
875,
508,
298,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
582,
267,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
751,
26,
2060,
32,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2,
272,
916,
1950,
63,
875,
508,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
582,
267,
702,
18006,
63,
1258,
423,
2302,
508,
298,
22130,
13152,
921,
5756,
14,
6568,
14,
16,
14,
17,
26,
4321,
31,
2242,
6372,
3053,
29,
19,
5345,
2,
339,
702,
334,
9217,
63,
1258,
423,
697,
63,
354,
508,
298,
697,
63,
354,
531,
421,
199,
318,
511,
63,
578,
63,
2747,
19914,
63,
765,
63,
1250,
63,
2118,
8,
571,
63,
888,
304,
272,
408,
5903,
511,
6358,
859,
2536,
19914,
370,
1937,
626,
949,
859,
14486,
314,
4223,
370,
12420,
624,
272,
15865,
423,
8489,
63,
3112,
8,
571,
63,
888,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zuntrax/schedule-ng
|
hacks.py
|
2
|
1054
|
from logging import Logger, getLogger
from typing import Callable
def noexcept(log: Logger = getLogger(__name__)):
"""
Grab all uncaught exceptions and log them with the logger
of the module implementing the decorated function.
:param log: logger of module using this.
:return: False
"""
def noexcept_decorator(f: Callable):
def noexcept_inner(*args, **kwargs):
# noinspection PyBroadException
try:
return f(*args, **kwargs)
except:
log.exception("An unexpected error occurred.")
return False
return noexcept_inner
if not isinstance(log, Logger) and callable(log):
# probably was called without arguments
actual_log = getLogger(__name__)
actual_log.warning("\033[1;33mSome monkey used the noexcept decorator without arguments, "
"which should not have happened. Go bug the devs about it.\033[1;0m")
return noexcept_decorator(log)
return noexcept_decorator
|
gpl-3.0
|
[
504,
2050,
492,
15996,
12,
28138,
199,
504,
14090,
492,
16975,
421,
199,
318,
949,
2590,
8,
793,
26,
15996,
275,
28138,
3460,
354,
363,
2298,
272,
408,
272,
29225,
1006,
625,
24872,
4967,
436,
943,
3062,
543,
314,
2512,
272,
402,
314,
859,
18234,
314,
16225,
805,
14,
272,
520,
635,
943,
26,
2512,
402,
859,
1808,
642,
14,
272,
520,
1107,
26,
756,
272,
408,
272,
347,
949,
2590,
63,
11547,
8,
70,
26,
16975,
304,
267,
347,
949,
2590,
63,
5216,
2031,
589,
12,
1011,
958,
304,
288,
327,
30870,
1611,
34,
5063,
1726,
288,
862,
26,
355,
372,
289,
2031,
589,
12,
1011,
958,
9,
288,
871,
26,
355,
943,
14,
1971,
480,
2493,
10537,
1125,
8920,
2685,
355,
372,
756,
267,
372,
949,
2590,
63,
5216,
339,
340,
440,
1228,
8,
793,
12,
15996,
9,
436,
4550,
8,
793,
304,
267,
327,
8646,
1990,
2797,
1928,
2368,
267,
3503,
63,
793,
275,
28138,
3460,
354,
3368,
267,
3503,
63,
793,
14,
3764,
4582,
8762,
59,
17,
27,
1153,
77,
7700,
14198,
1202,
314,
949,
2590,
7531,
1928,
2368,
12,
298,
2574,
298,
6777,
1077,
440,
1172,
21056,
14,
3971,
6519,
314,
477,
3122,
3595,
652,
3134,
8762,
59,
17,
27,
16,
77,
531,
267,
372,
949,
2590,
63,
11547,
8,
793,
9,
272,
372,
949,
2590,
63,
11547,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
492,
15996,
12,
28138,
199,
504,
14090,
492,
16975,
421,
199,
318,
949,
2590,
8,
793,
26,
15996,
275,
28138,
3460,
354,
363,
2298,
272,
408,
272,
29225,
1006,
625,
24872,
4967,
436,
943,
3062,
543,
314,
2512,
272,
402,
314,
859,
18234,
314,
16225,
805,
14,
272,
520,
635,
943,
26,
2512,
402,
859,
1808,
642,
14,
272,
520,
1107,
26,
756,
272,
408,
272,
347,
949,
2590,
63,
11547,
8,
70,
26,
16975,
304,
267,
347,
949,
2590,
63,
5216,
2031,
589,
12,
1011,
958,
304,
288,
327,
30870,
1611,
34,
5063,
1726,
288,
862,
26,
355,
372,
289,
2031,
589,
12,
1011,
958,
9,
288,
871,
26,
355,
943,
14,
1971,
480,
2493,
10537,
1125,
8920,
2685,
355,
372,
756,
267,
372,
949,
2590,
63,
5216,
339,
340,
440,
1228,
8,
793,
12,
15996,
9,
436,
4550,
8,
793,
304,
267,
327,
8646,
1990,
2797,
1928,
2368,
267,
3503,
63,
793,
275,
28138,
3460,
354,
3368,
267,
3503,
63,
793,
14,
3764,
4582,
8762,
59,
17,
27,
1153,
77,
7700,
14198,
1202,
314,
949,
2590,
7531,
1928,
2368,
12,
298,
2574,
298,
6777,
1077,
440,
1172,
21056,
14,
3971,
6519,
314,
477,
3122,
3595,
652,
3134,
8762,
59,
17,
27,
16,
77,
531,
267,
372,
949,
2590,
63,
11547,
8,
793,
9,
272,
372,
949,
2590,
63,
11547,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xi/ldif3
|
setup.py
|
1
|
1063
|
#!/usr/bin/env python
import os
import re
from setuptools import setup
DIRNAME = os.path.abspath(os.path.dirname(__file__))
rel = lambda *parts: os.path.abspath(os.path.join(DIRNAME, *parts))
README = open(rel('README.rst')).read()
MAIN = open(rel('ldif3.py')).read()
VERSION = re.search("__version__ = '([^']+)'", MAIN).group(1)
NAME = re.search('^"""(.*) - (.*)"""', MAIN).group(1)
DESCRIPTION = re.search('^"""(.*) - (.*)"""', MAIN).group(2)
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=README,
url='https://github.com/xi/ldif3',
author='Tobias Bengfort',
author_email='tobias.bengfort@posteo.de',
py_modules=['ldif3'],
license='BSD',
classifiers=[
'Development Status :: 4 - Beta',
'Operating System :: OS Independent',
'Programming Language :: Python',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Topic :: System :: Systems Administration :: '
'Authentication/Directory :: LDAP',
])
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
199,
646,
295,
199,
504,
9116,
492,
3272,
199,
199,
3022,
2339,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3369,
275,
2400,
627,
4181,
26,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3022,
2339,
12,
627,
4181,
430,
199,
199,
18195,
275,
1551,
8,
3369,
360,
18195,
14,
8332,
11103,
739,
342,
199,
5848,
275,
1551,
8,
3369,
360,
76,
7330,
19,
14,
647,
11103,
739,
342,
199,
4612,
275,
295,
14,
1733,
16232,
1023,
363,
275,
283,
7059,
21899,
3171,
401,
4828,
568,
680,
923,
8,
17,
9,
199,
2339,
275,
295,
14,
1733,
9097,
624,
8,
12432,
446,
334,
2795,
9471,
297,
4828,
568,
680,
923,
8,
17,
9,
199,
17705,
275,
295,
14,
1733,
9097,
624,
8,
12432,
446,
334,
2795,
9471,
297,
4828,
568,
680,
923,
8,
18,
9,
421,
199,
2758,
8,
272,
536,
29,
2339,
12,
272,
1015,
29,
4612,
12,
272,
1369,
29,
17705,
12,
272,
1846,
63,
1802,
29,
18195,
12,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
6865,
15,
76,
7330,
19,
297,
272,
4132,
534,
1378,
8160,
26844,
7102,
361,
297,
272,
4132,
63,
2123,
534,
475,
8160,
14,
18486,
7102,
361,
32,
27706,
79,
14,
271,
297,
272,
1134,
63,
3112,
2968,
76,
7330,
19,
995,
272,
4190,
534,
15400,
297,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
841,
446,
29521,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
12157,
3800,
6187,
3800,
15285,
9516,
4633,
3800,
283,
288,
283,
10348,
15,
6231,
3800,
20717,
297,
272,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
747,
199,
646,
295,
199,
504,
9116,
492,
3272,
199,
199,
3022,
2339,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3369,
275,
2400,
627,
4181,
26,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3022,
2339,
12,
627,
4181,
430,
199,
199,
18195,
275,
1551,
8,
3369,
360,
18195,
14,
8332,
11103,
739,
342,
199,
5848,
275,
1551,
8,
3369,
360,
76,
7330,
19,
14,
647,
11103,
739,
342,
199,
4612,
275,
295,
14,
1733,
16232,
1023,
363,
275,
283,
7059,
21899,
3171,
401,
4828,
568,
680,
923,
8,
17,
9,
199,
2339,
275,
295,
14,
1733,
9097,
624,
8,
12432,
446,
334,
2795,
9471,
297,
4828,
568,
680,
923,
8,
17,
9,
199,
17705,
275,
295,
14,
1733,
9097,
624,
8,
12432,
446,
334,
2795,
9471,
297,
4828,
568,
680,
923,
8,
18,
9,
421,
199,
2758,
8,
272,
536,
29,
2339,
12,
272,
1015,
29,
4612,
12,
272,
1369,
29,
17705,
12,
272,
1846,
63,
1802,
29,
18195,
12,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
6865,
15,
76,
7330,
19,
297,
272,
4132,
534,
1378,
8160,
26844,
7102,
361,
297,
272,
4132,
63,
2123,
534,
475,
8160,
14,
18486,
7102,
361,
32,
27706,
79,
14,
271,
297,
272,
1134,
63,
3112,
2968,
76,
7330,
19,
995,
272,
4190,
534,
15400,
297,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
841,
446,
29521,
297,
267,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
12157,
3800,
6187,
3800,
15285,
9516,
4633,
3800,
283,
288,
283,
10348,
15,
6231,
3800,
20717,
297,
272,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
heke123/chromium-crosswalk
|
tools/perf/page_sets/text_selection_sites.py
|
25
|
6888
|
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry import story
from telemetry.page import page as page_module
from telemetry.page import shared_page_state
class SimplePage(page_module.Page):
def __init__(self, url, page_set):
super(SimplePage, self).__init__(
url=url,
page_set=page_set,
shared_page_state_class=shared_page_state.SharedPageState,
credentials_path='data/credentials.json')
self.archive_data_file = 'data/text_selection_sites.json'
def RunNavigateSteps(self, action_runner):
super(SimplePage, self).RunNavigateSteps(action_runner)
action_runner.WaitForJavaScriptCondition(
'document.readyState == "complete"')
class SimpleTextSelectionPage(SimplePage):
def __init__(self, url, page_set):
super(SimpleTextSelectionPage, self).__init__(url=url, page_set=page_set)
def RunPageInteractions(self, action_runner):
# Create a fixed position div in the top left corner of the page, and
# another one in the bottom right corner of the page.
# Select the text within the first div.
action_runner.ExecuteJavaScript('''
(function() {
var text_div = document.createElement('div');
var text_div_2 = document.createElement('div');
text_div.style.fontSize = text_div_2.style.fontSize = "10vh";
text_div.style.lineHeight = text_div_2.style.lineHeight = "normal";
text_div.style.color = text_div_2.style.color = "red";
text_div.style.zIndex = text_div_2.style.zIndex = "1000";
text_div.style.position = text_div_2.style.position = "fixed";
text_div.style.left = "10%";
text_div.style.top = "10%";
text_div_2.style.right="0";
text_div_2.style.bottom="2%";
text_div.id="text-for-perf-test";
text_div_2.id="text-for-perf-test-2";
text_div.innerText="Hello";
text_div_2.innerText="World";
document.body.insertBefore(text_div, document.body.firstChild);
document.body.appendChild(text_div_2);
var selection = window.getSelection();
var textNode = text_div.childNodes[0];
selection.setBaseAndExtent(textNode, 0, textNode, 5);
window.requestAnimationFrame(function() {
text_div.style.color="green";
});
})();''')
# Wait two frames so that the selection information is sent to chromium
# and it is able to process input events interacting with selection.
action_runner.WaitForJavaScriptCondition(
'document.getElementById("text-for-perf-test").style.color == "green"')
action_runner.ExecuteJavaScript('''
window.requestAnimationFrame(function() {
document.getElementById("text-for-perf-test").style.color="red";
});
''')
action_runner.WaitForJavaScriptCondition(
'document.getElementById("text-for-perf-test").style.color == "red"')
# Confirm that the selection is set correctly.
text = action_runner.EvaluateJavaScript('window.getSelection().toString()')
assert text == "Hello"
# Tap on the selected text to make the handles show up.
with action_runner.CreateGestureInteraction('TapAction'):
action_runner.TapElement('#text-for-perf-test')
text_div_bottom = float(action_runner.EvaluateJavaScript('''
document.getElementById("text-for-perf-test").getClientRects()[0].bottom
'''))
text_div_2_bottom = float(action_runner.EvaluateJavaScript('''
document.getElementById(
"text-for-perf-test-2").getClientRects()[0].bottom
'''))
body_rect_str = action_runner.EvaluateJavaScript('''
var r = window.__GestureCommon_GetBoundingVisibleRect(document.body);
r.left + " " + r.top + " " + r.height + " " + r.width;
''')
body_rect_left, body_rect_top, body_rect_height, body_rect_width = map(
float, body_rect_str.split())
# Start the drag gesture 5 pixels below the bottom left corner of the
# first div in order to drag the left selection handle.
p1_left_ratio = .1
p1_top_ratio = float((text_div_bottom + 5 - body_rect_top) /
body_rect_height)
# End the drag gesture below the bottom right corner of the second div,
# so that the selection end is in the second div and we can easily
# determine the position of the corresponding handle.
p2_top_ratio = float((text_div_2_bottom - body_rect_top) /
body_rect_height)
with action_runner.CreateGestureInteraction('DragAction-1'):
action_runner.DragPage(left_start_ratio=p1_left_ratio,
top_start_ratio=p1_top_ratio, left_end_ratio=.99,
top_end_ratio=p2_top_ratio, speed_in_pixels_per_second=300,
use_touch=1)
# Confirm that the selection has changed.
text = action_runner.EvaluateJavaScript('window.getSelection().toString()')
assert text != "Hello"
# Determine the coordinates of the end of the selection
sel_end_str = action_runner.EvaluateJavaScript('''
var rects = window.getSelection().getRangeAt(0).getClientRects();
var last_rect = rects[rects.length - 1];
last_rect.right + " " + last_rect.bottom;
''')
sel_end_x, sel_end_y = map(float, sel_end_str.split())
# Start the second drag gesture 5 pixels below the end of the selection
# in order to drag the selection handle.
p2_left_ratio = float((sel_end_x - body_rect_left) / body_rect_width)
p2_top_ratio = float((sel_end_y + 5 - body_rect_top) / body_rect_height)
with action_runner.CreateGestureInteraction('DragAction-2'):
action_runner.DragPage(left_start_ratio=p2_left_ratio,
top_start_ratio=p2_top_ratio, left_end_ratio=p1_left_ratio,
top_end_ratio=p1_top_ratio, speed_in_pixels_per_second=300,
use_touch=1)
# Confirm that the selection is back to the text in the first div.
text = action_runner.EvaluateJavaScript('window.getSelection().toString()')
assert text == "Hello"
class TextSelectionSitesPageSet(story.StorySet):
def __init__(self):
super(TextSelectionSitesPageSet, self).__init__(
archive_data_file='data/top_10_mobile.json',
cloud_storage_bucket=story.PARTNER_BUCKET)
# A subset of top_10_mobile page set
page_urls = [
'https://www.google.com/#hl=en&q=science',
'https://m.facebook.com/rihanna',
'http://search.yahoo.com/search;_ylt=?p=google',
'http://www.baidu.com/s?word=google',
'https://mobile.twitter.com/justinbieber?skip_interstitial=true',
'http://yandex.ru/touchsearch?text=science'
]
for url in page_urls:
self.AddStory(SimpleTextSelectionPage(url, self))
|
bsd-3-clause
|
[
3,
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
504,
17298,
492,
19222,
199,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
63,
578,
199,
504,
17298,
14,
1606,
492,
5709,
63,
1606,
63,
929,
421,
199,
533,
5870,
3276,
8,
1606,
63,
578,
14,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
3184,
3276,
12,
291,
2843,
826,
721,
267,
1166,
29,
633,
12,
267,
2034,
63,
409,
29,
1606,
63,
409,
12,
267,
5709,
63,
1606,
63,
929,
63,
533,
29,
5555,
63,
1606,
63,
929,
14,
12197,
3276,
2223,
12,
267,
6235,
63,
515,
534,
576,
15,
6942,
14,
1001,
358,
272,
291,
14,
6404,
63,
576,
63,
493,
275,
283,
576,
15,
505,
63,
5592,
63,
8619,
14,
1001,
7,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1613,
8,
3184,
3276,
12,
291,
680,
2540,
31914,
20960,
8,
1287,
63,
5933,
9,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
2179,
2223,
508,
298,
4883,
9008,
421,
199,
533,
5870,
1872,
7713,
3276,
8,
3184,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
3184,
1872,
7713,
3276,
12,
291,
2843,
826,
721,
633,
29,
633,
12,
2034,
63,
409,
29,
1606,
63,
409,
9,
819,
347,
3378,
3276,
607,
22990,
8,
277,
12,
1595,
63,
5933,
304,
272,
327,
2790,
282,
6317,
3421,
9073,
315,
314,
2746,
3602,
17703,
402,
314,
2034,
12,
436,
272,
327,
4573,
1373,
315,
314,
9048,
2451,
17703,
402,
314,
2034,
14,
272,
327,
9496,
314,
1318,
4453,
314,
1642,
9073,
14,
272,
1595,
63,
5933,
14,
12049,
21986,
10505,
267,
334,
1593,
342,
469,
881,
2729,
1318,
63,
3015,
275,
2213,
14,
20296,
360,
3015,
11339,
881,
2729,
1318,
63,
3015,
63,
18,
275,
2213,
14,
20296,
360,
3015,
11339,
8592,
1318,
63,
3015,
14,
2487,
14,
31995,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
31995,
275,
298,
709,
20369,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
604,
8436,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
604,
8436,
275,
298,
3302,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
2326,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
2326,
275,
298,
581,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
90,
2681,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
90,
2681,
275,
298,
5279,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
3124,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
3124,
275,
298,
5964,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
3039,
275,
298,
709,
5,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
2119,
275,
298,
709,
5,
11436,
881,
1318,
63,
3015,
63,
18,
14,
2487,
14,
1019,
628,
16,
11436,
881,
1318,
63,
3015,
63,
18,
14,
2487,
14,
8305,
628,
18,
5,
11436,
8592,
1318,
63,
3015,
14,
344,
628,
505,
13,
509,
13,
9452,
13,
396,
11436,
881,
1318,
63,
3015,
63,
18,
14,
344,
628,
505,
13,
509,
13,
9452,
13,
396,
13,
18,
11436,
881,
1318,
63,
3015,
14,
5216,
1872,
628,
6257,
11436,
881,
1318,
63,
3015,
63,
18,
14,
5216,
1872,
628,
15943,
11436,
8592,
2213,
14,
2030,
14,
3176,
13569,
8,
505,
63,
3015,
12,
2213,
14,
2030,
14,
22262,
2736,
881,
2213,
14,
2030,
14,
14988,
8,
505,
63,
3015,
63,
18,
2736,
8592,
2729,
7267,
275,
4353,
14,
362,
7713,
7303,
881,
2729,
1318,
1716,
275,
1318,
63,
3015,
14,
10626,
59,
16,
11566,
881,
7267,
14,
409,
1563,
3325,
19808,
8,
505,
1716,
12,
378,
12,
1318,
1716,
12,
959,
2736,
8592,
4353,
14,
1069,
15957,
3160,
8,
1593,
342,
469,
288,
1318,
63,
3015,
14,
2487,
14,
2326,
628,
7731,
11436,
881,
789,
2736,
267,
3828,
7303,
12310,
339,
327,
13144,
2877,
11223,
880,
626,
314,
7267,
2556,
365,
4847,
370,
682,
7419,
272,
327,
436,
652,
365,
7688,
370,
2112,
1324,
4474,
17232,
316,
543,
7267,
14,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
508,
298,
7731,
9008,
272,
1595,
63,
5933,
14,
12049,
21986,
10505,
881,
4353,
14,
1069,
15957,
3160,
8,
1593,
342,
469,
288,
2213,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
628,
581,
11436,
881,
789,
2736,
267,
21464,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
508,
298,
581,
9008,
339,
327,
32112,
626,
314,
7267,
365,
663,
6657,
14,
272,
1318,
275,
1595,
63,
5933,
14,
25002,
21986,
360,
3806,
14,
362,
7713,
1252,
16695,
19004,
272,
702,
1318,
508,
298,
6257,
2,
339,
327,
377,
439,
641,
314,
4895,
1318,
370,
1852,
314,
10022,
2498,
1536,
14,
272,
543,
1595,
63,
5933,
14,
2499,
39,
597,
608,
31900,
360,
27746,
3310,
735,
489,
1595,
63,
5933,
14,
27746,
2162,
7863,
505,
13,
509,
13,
9452,
13,
396,
358,
339,
1318,
63,
3015,
63,
8305,
275,
2069,
8,
1287,
63,
5933,
14,
25002,
21986,
10505,
267,
2213,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
362,
3041,
8252,
83,
3430,
16,
1055,
8305,
267,
2125,
1333,
272,
1318,
63,
3015,
63,
18,
63,
8305,
275,
2069,
8,
1287,
63,
5933,
14,
25002,
21986,
10505,
267,
2213,
14,
26215,
8,
288,
298,
505,
13,
509,
13,
9452,
13,
396,
13,
18,
3471,
362,
3041,
8252,
83,
3430,
16,
1055,
8305,
267,
2125,
1333,
272,
2396,
63,
1201,
63,
495,
275,
1595,
63,
5933,
14,
25002,
21986,
10505,
267,
2729,
519,
275,
4353,
855,
39,
597,
608,
7844,
63,
1002,
8934,
316,
14917,
8252,
8,
3554,
14,
2030,
2736,
267,
519,
14,
3039,
435,
298,
298,
435,
519,
14,
2119,
435,
298,
298,
435,
519,
14,
3333
] |
[
1898,
6927,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
504,
17298,
492,
19222,
199,
504,
17298,
14,
1606,
492,
2034,
465,
2034,
63,
578,
199,
504,
17298,
14,
1606,
492,
5709,
63,
1606,
63,
929,
421,
199,
533,
5870,
3276,
8,
1606,
63,
578,
14,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
3184,
3276,
12,
291,
2843,
826,
721,
267,
1166,
29,
633,
12,
267,
2034,
63,
409,
29,
1606,
63,
409,
12,
267,
5709,
63,
1606,
63,
929,
63,
533,
29,
5555,
63,
1606,
63,
929,
14,
12197,
3276,
2223,
12,
267,
6235,
63,
515,
534,
576,
15,
6942,
14,
1001,
358,
272,
291,
14,
6404,
63,
576,
63,
493,
275,
283,
576,
15,
505,
63,
5592,
63,
8619,
14,
1001,
7,
819,
347,
3378,
31914,
20960,
8,
277,
12,
1595,
63,
5933,
304,
272,
1613,
8,
3184,
3276,
12,
291,
680,
2540,
31914,
20960,
8,
1287,
63,
5933,
9,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
2179,
2223,
508,
298,
4883,
9008,
421,
199,
533,
5870,
1872,
7713,
3276,
8,
3184,
3276,
304,
819,
347,
636,
826,
721,
277,
12,
1166,
12,
2034,
63,
409,
304,
272,
1613,
8,
3184,
1872,
7713,
3276,
12,
291,
2843,
826,
721,
633,
29,
633,
12,
2034,
63,
409,
29,
1606,
63,
409,
9,
819,
347,
3378,
3276,
607,
22990,
8,
277,
12,
1595,
63,
5933,
304,
272,
327,
2790,
282,
6317,
3421,
9073,
315,
314,
2746,
3602,
17703,
402,
314,
2034,
12,
436,
272,
327,
4573,
1373,
315,
314,
9048,
2451,
17703,
402,
314,
2034,
14,
272,
327,
9496,
314,
1318,
4453,
314,
1642,
9073,
14,
272,
1595,
63,
5933,
14,
12049,
21986,
10505,
267,
334,
1593,
342,
469,
881,
2729,
1318,
63,
3015,
275,
2213,
14,
20296,
360,
3015,
11339,
881,
2729,
1318,
63,
3015,
63,
18,
275,
2213,
14,
20296,
360,
3015,
11339,
8592,
1318,
63,
3015,
14,
2487,
14,
31995,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
31995,
275,
298,
709,
20369,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
604,
8436,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
604,
8436,
275,
298,
3302,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
2326,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
2326,
275,
298,
581,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
90,
2681,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
90,
2681,
275,
298,
5279,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
3124,
275,
1318,
63,
3015,
63,
18,
14,
2487,
14,
3124,
275,
298,
5964,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
3039,
275,
298,
709,
5,
11436,
881,
1318,
63,
3015,
14,
2487,
14,
2119,
275,
298,
709,
5,
11436,
881,
1318,
63,
3015,
63,
18,
14,
2487,
14,
1019,
628,
16,
11436,
881,
1318,
63,
3015,
63,
18,
14,
2487,
14,
8305,
628,
18,
5,
11436,
8592,
1318,
63,
3015,
14,
344,
628,
505,
13,
509,
13,
9452,
13,
396,
11436,
881,
1318,
63,
3015,
63,
18,
14,
344,
628,
505,
13,
509,
13,
9452,
13,
396,
13,
18,
11436,
881,
1318,
63,
3015,
14,
5216,
1872,
628,
6257,
11436,
881,
1318,
63,
3015,
63,
18,
14,
5216,
1872,
628,
15943,
11436,
8592,
2213,
14,
2030,
14,
3176,
13569,
8,
505,
63,
3015,
12,
2213,
14,
2030,
14,
22262,
2736,
881,
2213,
14,
2030,
14,
14988,
8,
505,
63,
3015,
63,
18,
2736,
8592,
2729,
7267,
275,
4353,
14,
362,
7713,
7303,
881,
2729,
1318,
1716,
275,
1318,
63,
3015,
14,
10626,
59,
16,
11566,
881,
7267,
14,
409,
1563,
3325,
19808,
8,
505,
1716,
12,
378,
12,
1318,
1716,
12,
959,
2736,
8592,
4353,
14,
1069,
15957,
3160,
8,
1593,
342,
469,
288,
1318,
63,
3015,
14,
2487,
14,
2326,
628,
7731,
11436,
881,
789,
2736,
267,
3828,
7303,
12310,
339,
327,
13144,
2877,
11223,
880,
626,
314,
7267,
2556,
365,
4847,
370,
682,
7419,
272,
327,
436,
652,
365,
7688,
370,
2112,
1324,
4474,
17232,
316,
543,
7267,
14,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
508,
298,
7731,
9008,
272,
1595,
63,
5933,
14,
12049,
21986,
10505,
881,
4353,
14,
1069,
15957,
3160,
8,
1593,
342,
469,
288,
2213,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
628,
581,
11436,
881,
789,
2736,
267,
21464,
272,
1595,
63,
5933,
14,
21433,
21986,
9558,
8,
267,
283,
3554,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
2487,
14,
2326,
508,
298,
581,
9008,
339,
327,
32112,
626,
314,
7267,
365,
663,
6657,
14,
272,
1318,
275,
1595,
63,
5933,
14,
25002,
21986,
360,
3806,
14,
362,
7713,
1252,
16695,
19004,
272,
702,
1318,
508,
298,
6257,
2,
339,
327,
377,
439,
641,
314,
4895,
1318,
370,
1852,
314,
10022,
2498,
1536,
14,
272,
543,
1595,
63,
5933,
14,
2499,
39,
597,
608,
31900,
360,
27746,
3310,
735,
489,
1595,
63,
5933,
14,
27746,
2162,
7863,
505,
13,
509,
13,
9452,
13,
396,
358,
339,
1318,
63,
3015,
63,
8305,
275,
2069,
8,
1287,
63,
5933,
14,
25002,
21986,
10505,
267,
2213,
14,
26215,
480,
505,
13,
509,
13,
9452,
13,
396,
3471,
362,
3041,
8252,
83,
3430,
16,
1055,
8305,
267,
2125,
1333,
272,
1318,
63,
3015,
63,
18,
63,
8305,
275,
2069,
8,
1287,
63,
5933,
14,
25002,
21986,
10505,
267,
2213,
14,
26215,
8,
288,
298,
505,
13,
509,
13,
9452,
13,
396,
13,
18,
3471,
362,
3041,
8252,
83,
3430,
16,
1055,
8305,
267,
2125,
1333,
272,
2396,
63,
1201,
63,
495,
275,
1595,
63,
5933,
14,
25002,
21986,
10505,
267,
2729,
519,
275,
4353,
855,
39,
597,
608,
7844,
63,
1002,
8934,
316,
14917,
8252,
8,
3554,
14,
2030,
2736,
267,
519,
14,
3039,
435,
298,
298,
435,
519,
14,
2119,
435,
298,
298,
435,
519,
14,
3333,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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|
# Verify that gdb can pretty-print the various PyObject* types
#
# The code for testing gdb was adapted from similar work in Unladen Swallow's
# Lib/test/test_jit_gdb.py
import os
import re
import pprint
import subprocess
import sys
import sysconfig
import unittest
import locale
# Is this Python configured to support threads?
try:
import _thread
except ImportError:
_thread = None
from test import support
from test.support import run_unittest, findfile, python_is_optimized
try:
gdb_version, _ = subprocess.Popen(["gdb", "-nx", "--version"],
stdout=subprocess.PIPE).communicate()
except OSError:
# This is what "no gdb" looks like. There may, however, be other
# errors that manifest this way too.
raise unittest.SkipTest("Couldn't find gdb on the path")
gdb_version_number = re.search(b"^GNU gdb [^\d]*(\d+)\.(\d)", gdb_version)
gdb_major_version = int(gdb_version_number.group(1))
gdb_minor_version = int(gdb_version_number.group(2))
if gdb_major_version < 7:
raise unittest.SkipTest("gdb versions before 7.0 didn't support python embedding"
" Saw:\n" + gdb_version.decode('ascii', 'replace'))
if not sysconfig.is_python_build():
raise unittest.SkipTest("test_gdb only works on source builds at the moment.")
# Location of custom hooks file in a repository checkout.
checkout_hook_path = os.path.join(os.path.dirname(sys.executable),
'python-gdb.py')
PYTHONHASHSEED = '123'
def run_gdb(*args, **env_vars):
"""Runs gdb in --batch mode with the additional arguments given by *args.
Returns its (stdout, stderr) decoded from utf-8 using the replace handler.
"""
if env_vars:
env = os.environ.copy()
env.update(env_vars)
else:
env = None
# -nx: Do not execute commands from any .gdbinit initialization files
# (issue #22188)
base_cmd = ('gdb', '--batch', '-nx')
if (gdb_major_version, gdb_minor_version) >= (7, 4):
base_cmd += ('-iex', 'add-auto-load-safe-path ' + checkout_hook_path)
out, err = subprocess.Popen(base_cmd + args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env,
).communicate()
return out.decode('utf-8', 'replace'), err.decode('utf-8', 'replace')
# Verify that "gdb" was built with the embedded python support enabled:
gdbpy_version, _ = run_gdb("--eval-command=python import sys; print(sys.version_info)")
if not gdbpy_version:
raise unittest.SkipTest("gdb not built with embedded python support")
# Verify that "gdb" can load our custom hooks, as OS security settings may
# disallow this without a customised .gdbinit.
cmd = ['--args', sys.executable]
_, gdbpy_errors = run_gdb('--args', sys.executable)
if "auto-loading has been declined" in gdbpy_errors:
msg = "gdb security settings prevent use of custom hooks: "
raise unittest.SkipTest(msg + gdbpy_errors.rstrip())
def gdb_has_frame_select():
# Does this build of gdb have gdb.Frame.select ?
stdout, _ = run_gdb("--eval-command=python print(dir(gdb.Frame))")
m = re.match(r'.*\[(.*)\].*', stdout)
if not m:
raise unittest.SkipTest("Unable to parse output from gdb.Frame.select test")
gdb_frame_dir = m.group(1).split(', ')
return "'select'" in gdb_frame_dir
HAS_PYUP_PYDOWN = gdb_has_frame_select()
BREAKPOINT_FN='builtin_id'
class DebuggerTests(unittest.TestCase):
"""Test that the debugger can debug Python."""
def get_stack_trace(self, source=None, script=None,
breakpoint=BREAKPOINT_FN,
cmds_after_breakpoint=None,
import_site=False):
'''
Run 'python -c SOURCE' under gdb with a breakpoint.
Support injecting commands after the breakpoint is reached
Returns the stdout from gdb
cmds_after_breakpoint: if provided, a list of strings: gdb commands
'''
# We use "set breakpoint pending yes" to avoid blocking with a:
# Function "foo" not defined.
# Make breakpoint pending on future shared library load? (y or [n])
# error, which typically happens python is dynamically linked (the
# breakpoints of interest are to be found in the shared library)
# When this happens, we still get:
# Function "textiowrapper_write" not defined.
# emitted to stderr each time, alas.
# Initially I had "--eval-command=continue" here, but removed it to
# avoid repeated print breakpoints when traversing hierarchical data
# structures
# Generate a list of commands in gdb's language:
commands = ['set breakpoint pending yes',
'break %s' % breakpoint,
# The tests assume that the first frame of printed
# backtrace will not contain program counter,
# that is however not guaranteed by gdb
# therefore we need to use 'set print address off' to
# make sure the counter is not there. For example:
# #0 in PyObject_Print ...
# is assumed, but sometimes this can be e.g.
# #0 0x00003fffb7dd1798 in PyObject_Print ...
'set print address off',
'run']
# GDB as of 7.4 onwards can distinguish between the
# value of a variable at entry vs current value:
# http://sourceware.org/gdb/onlinedocs/gdb/Variables.html
# which leads to the selftests failing with errors like this:
# AssertionError: 'v@entry=()' != '()'
# Disable this:
if (gdb_major_version, gdb_minor_version) >= (7, 4):
commands += ['set print entry-values no']
if cmds_after_breakpoint:
commands += cmds_after_breakpoint
else:
commands += ['backtrace']
# print commands
# Use "commands" to generate the arguments with which to invoke "gdb":
args = ["gdb", "--batch", "-nx"]
args += ['--eval-command=%s' % cmd for cmd in commands]
args += ["--args",
sys.executable]
if not import_site:
# -S suppresses the default 'import site'
args += ["-S"]
if source:
args += ["-c", source]
elif script:
args += [script]
# print args
# print (' '.join(args))
# Use "args" to invoke gdb, capturing stdout, stderr:
out, err = run_gdb(*args, PYTHONHASHSEED=PYTHONHASHSEED)
errlines = err.splitlines()
unexpected_errlines = []
# Ignore some benign messages on stderr.
ignore_patterns = (
'Function "%s" not defined.' % breakpoint,
"warning: no loadable sections found in added symbol-file"
" system-supplied DSO",
"warning: Unable to find libthread_db matching"
" inferior's thread library, thread debugging will"
" not be available.",
"warning: Cannot initialize thread debugging"
" library: Debugger service failed",
'warning: Could not load shared library symbols for '
'linux-vdso.so',
'warning: Could not load shared library symbols for '
'linux-gate.so',
'Do you need "set solib-search-path" or '
'"set sysroot"?',
'warning: Source file is more recent than executable.',
# Issue #19753: missing symbols on System Z
'Missing separate debuginfo for ',
'Try: zypper install -C ',
)
for line in errlines:
if not line.startswith(ignore_patterns):
unexpected_errlines.append(line)
# Ensure no unexpected error messages:
self.assertEqual(unexpected_errlines, [])
return out
def get_gdb_repr(self, source,
cmds_after_breakpoint=None,
import_site=False):
# Given an input python source representation of data,
# run "python -c'id(DATA)'" under gdb with a breakpoint on
# builtin_id and scrape out gdb's representation of the "op"
# parameter, and verify that the gdb displays the same string
#
# Verify that the gdb displays the expected string
#
# For a nested structure, the first time we hit the breakpoint will
# give us the top-level structure
# NOTE: avoid decoding too much of the traceback as some
# undecodable characters may lurk there in optimized mode
# (issue #19743).
cmds_after_breakpoint = cmds_after_breakpoint or ["backtrace 1"]
gdb_output = self.get_stack_trace(source, breakpoint=BREAKPOINT_FN,
cmds_after_breakpoint=cmds_after_breakpoint,
import_site=import_site)
# gdb can insert additional '\n' and space characters in various places
# in its output, depending on the width of the terminal it's connected
# to (using its "wrap_here" function)
m = re.match('.*#0\s+builtin_id\s+\(self\=.*,\s+v=\s*(.*?)\)\s+at\s+\S*Python/bltinmodule.c.*',
gdb_output, re.DOTALL)
if not m:
self.fail('Unexpected gdb output: %r\n%s' % (gdb_output, gdb_output))
return m.group(1), gdb_output
def assertEndsWith(self, actual, exp_end):
'''Ensure that the given "actual" string ends with "exp_end"'''
self.assertTrue(actual.endswith(exp_end),
msg='%r did not end with %r' % (actual, exp_end))
def assertMultilineMatches(self, actual, pattern):
m = re.match(pattern, actual, re.DOTALL)
if not m:
self.fail(msg='%r did not match %r' % (actual, pattern))
def get_sample_script(self):
return findfile('gdb_sample.py')
class PrettyPrintTests(DebuggerTests):
def test_getting_backtrace(self):
gdb_output = self.get_stack_trace('id(42)')
self.assertTrue(BREAKPOINT_FN in gdb_output)
def assertGdbRepr(self, val, exp_repr=None):
# Ensure that gdb's rendering of the value in a debugged process
# matches repr(value) in this process:
gdb_repr, gdb_output = self.get_gdb_repr('id(' + ascii(val) + ')')
if not exp_repr:
exp_repr = repr(val)
self.assertEqual(gdb_repr, exp_repr,
('%r did not equal expected %r; full output was:\n%s'
% (gdb_repr, exp_repr, gdb_output)))
def test_int(self):
'Verify the pretty-printing of various int values'
self.assertGdbRepr(42)
self.assertGdbRepr(0)
self.assertGdbRepr(-7)
self.assertGdbRepr(1000000000000)
self.assertGdbRepr(-1000000000000000)
def test_singletons(self):
'Verify the pretty-printing of True, False and None'
self.assertGdbRepr(True)
self.assertGdbRepr(False)
self.assertGdbRepr(None)
def test_dicts(self):
'Verify the pretty-printing of dictionaries'
self.assertGdbRepr({})
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'douglas': 42, 'foo': 'bar'}")
def test_lists(self):
'Verify the pretty-printing of lists'
self.assertGdbRepr([])
self.assertGdbRepr(list(range(5)))
def test_bytes(self):
'Verify the pretty-printing of bytes'
self.assertGdbRepr(b'')
self.assertGdbRepr(b'And now for something hopefully the same')
self.assertGdbRepr(b'string with embedded NUL here \0 and then some more text')
self.assertGdbRepr(b'this is a tab:\t'
b' this is a slash-N:\n'
b' this is a slash-R:\r'
)
self.assertGdbRepr(b'this is byte 255:\xff and byte 128:\x80')
self.assertGdbRepr(bytes([b for b in range(255)]))
def test_strings(self):
'Verify the pretty-printing of unicode strings'
encoding = locale.getpreferredencoding()
def check_repr(text):
try:
text.encode(encoding)
printable = True
except UnicodeEncodeError:
self.assertGdbRepr(text, ascii(text))
else:
self.assertGdbRepr(text)
self.assertGdbRepr('')
self.assertGdbRepr('And now for something hopefully the same')
self.assertGdbRepr('string with embedded NUL here \0 and then some more text')
# Test printing a single character:
# U+2620 SKULL AND CROSSBONES
check_repr('\u2620')
# Test printing a Japanese unicode string
# (I believe this reads "mojibake", using 3 characters from the CJK
# Unified Ideographs area, followed by U+3051 HIRAGANA LETTER KE)
check_repr('\u6587\u5b57\u5316\u3051')
# Test a character outside the BMP:
# U+1D121 MUSICAL SYMBOL C CLEF
# This is:
# UTF-8: 0xF0 0x9D 0x84 0xA1
# UTF-16: 0xD834 0xDD21
check_repr(chr(0x1D121))
def test_tuples(self):
'Verify the pretty-printing of tuples'
self.assertGdbRepr(tuple(), '()')
self.assertGdbRepr((1,), '(1,)')
self.assertGdbRepr(('foo', 'bar', 'baz'))
def test_sets(self):
'Verify the pretty-printing of sets'
if (gdb_major_version, gdb_minor_version) < (7, 3):
self.skipTest("pretty-printing of sets needs gdb 7.3 or later")
self.assertGdbRepr(set(), 'set()')
self.assertGdbRepr(set(['a', 'b']), "{'a', 'b'}")
self.assertGdbRepr(set([4, 5, 6]), "{4, 5, 6}")
# Ensure that we handle sets containing the "dummy" key value,
# which happens on deletion:
gdb_repr, gdb_output = self.get_gdb_repr('''s = set(['a','b'])
s.remove('a')
id(s)''')
self.assertEqual(gdb_repr, "{'b'}")
def test_frozensets(self):
'Verify the pretty-printing of frozensets'
if (gdb_major_version, gdb_minor_version) < (7, 3):
self.skipTest("pretty-printing of frozensets needs gdb 7.3 or later")
self.assertGdbRepr(frozenset(), 'frozenset()')
self.assertGdbRepr(frozenset(['a', 'b']), "frozenset({'a', 'b'})")
self.assertGdbRepr(frozenset([4, 5, 6]), "frozenset({4, 5, 6})")
def test_exceptions(self):
# Test a RuntimeError
gdb_repr, gdb_output = self.get_gdb_repr('''
try:
raise RuntimeError("I am an error")
except RuntimeError as e:
id(e)
''')
self.assertEqual(gdb_repr,
"RuntimeError('I am an error',)")
# Test division by zero:
gdb_repr, gdb_output = self.get_gdb_repr('''
try:
a = 1 / 0
except ZeroDivisionError as e:
id(e)
''')
self.assertEqual(gdb_repr,
"ZeroDivisionError('division by zero',)")
def test_modern_class(self):
'Verify the pretty-printing of new-style class instances'
gdb_repr, gdb_output = self.get_gdb_repr('''
class Foo:
pass
foo = Foo()
foo.an_int = 42
id(foo)''')
m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr)
self.assertTrue(m,
msg='Unexpected new-style class rendering %r' % gdb_repr)
def test_subclassing_list(self):
'Verify the pretty-printing of an instance of a list subclass'
gdb_repr, gdb_output = self.get_gdb_repr('''
class Foo(list):
pass
foo = Foo()
foo += [1, 2, 3]
foo.an_int = 42
id(foo)''')
m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr)
self.assertTrue(m,
msg='Unexpected new-style class rendering %r' % gdb_repr)
def test_subclassing_tuple(self):
'Verify the pretty-printing of an instance of a tuple subclass'
# This should exercise the negative tp_dictoffset code in the
# new-style class support
gdb_repr, gdb_output = self.get_gdb_repr('''
class Foo(tuple):
pass
foo = Foo((1, 2, 3))
foo.an_int = 42
id(foo)''')
m = re.match(r'<Foo\(an_int=42\) at remote 0x-?[0-9a-f]+>', gdb_repr)
self.assertTrue(m,
msg='Unexpected new-style class rendering %r' % gdb_repr)
def assertSane(self, source, corruption, exprepr=None):
'''Run Python under gdb, corrupting variables in the inferior process
immediately before taking a backtrace.
Verify that the variable's representation is the expected failsafe
representation'''
if corruption:
cmds_after_breakpoint=[corruption, 'backtrace']
else:
cmds_after_breakpoint=['backtrace']
gdb_repr, gdb_output = \
self.get_gdb_repr(source,
cmds_after_breakpoint=cmds_after_breakpoint)
if exprepr:
if gdb_repr == exprepr:
# gdb managed to print the value in spite of the corruption;
# this is good (see http://bugs.python.org/issue8330)
return
# Match anything for the type name; 0xDEADBEEF could point to
# something arbitrary (see http://bugs.python.org/issue8330)
pattern = '<.* at remote 0x-?[0-9a-f]+>'
m = re.match(pattern, gdb_repr)
if not m:
self.fail('Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
def test_NULL_ptr(self):
'Ensure that a NULL PyObject* is handled gracefully'
gdb_repr, gdb_output = (
self.get_gdb_repr('id(42)',
cmds_after_breakpoint=['set variable v=0',
'backtrace'])
)
self.assertEqual(gdb_repr, '0x0')
def test_NULL_ob_type(self):
'Ensure that a PyObject* with NULL ob_type is handled gracefully'
self.assertSane('id(42)',
'set v->ob_type=0')
def test_corrupt_ob_type(self):
'Ensure that a PyObject* with a corrupt ob_type is handled gracefully'
self.assertSane('id(42)',
'set v->ob_type=0xDEADBEEF',
exprepr='42')
def test_corrupt_tp_flags(self):
'Ensure that a PyObject* with a type with corrupt tp_flags is handled'
self.assertSane('id(42)',
'set v->ob_type->tp_flags=0x0',
exprepr='42')
def test_corrupt_tp_name(self):
'Ensure that a PyObject* with a type with corrupt tp_name is handled'
self.assertSane('id(42)',
'set v->ob_type->tp_name=0xDEADBEEF',
exprepr='42')
def test_builtins_help(self):
'Ensure that the new-style class _Helper in site.py can be handled'
# (this was the issue causing tracebacks in
# http://bugs.python.org/issue8032#msg100537 )
gdb_repr, gdb_output = self.get_gdb_repr('id(__builtins__.help)', import_site=True)
m = re.match(r'<_Helper at remote 0x-?[0-9a-f]+>', gdb_repr)
self.assertTrue(m,
msg='Unexpected rendering %r' % gdb_repr)
def test_selfreferential_list(self):
'''Ensure that a reference loop involving a list doesn't lead proxyval
into an infinite loop:'''
gdb_repr, gdb_output = \
self.get_gdb_repr("a = [3, 4, 5] ; a.append(a) ; id(a)")
self.assertEqual(gdb_repr, '[3, 4, 5, [...]]')
gdb_repr, gdb_output = \
self.get_gdb_repr("a = [3, 4, 5] ; b = [a] ; a.append(b) ; id(a)")
self.assertEqual(gdb_repr, '[3, 4, 5, [[...]]]')
def test_selfreferential_dict(self):
'''Ensure that a reference loop involving a dict doesn't lead proxyval
into an infinite loop:'''
gdb_repr, gdb_output = \
self.get_gdb_repr("a = {} ; b = {'bar':a} ; a['foo'] = b ; id(a)")
self.assertEqual(gdb_repr, "{'foo': {'bar': {...}}}")
def test_selfreferential_old_style_instance(self):
gdb_repr, gdb_output = \
self.get_gdb_repr('''
class Foo:
pass
foo = Foo()
foo.an_attr = foo
id(foo)''')
self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
def test_selfreferential_new_style_instance(self):
gdb_repr, gdb_output = \
self.get_gdb_repr('''
class Foo(object):
pass
foo = Foo()
foo.an_attr = foo
id(foo)''')
self.assertTrue(re.match('<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
gdb_repr, gdb_output = \
self.get_gdb_repr('''
class Foo(object):
pass
a = Foo()
b = Foo()
a.an_attr = b
b.an_attr = a
id(a)''')
self.assertTrue(re.match('<Foo\(an_attr=<Foo\(an_attr=<\.\.\.>\) at remote 0x-?[0-9a-f]+>\) at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
def test_truncation(self):
'Verify that very long output is truncated'
gdb_repr, gdb_output = self.get_gdb_repr('id(list(range(1000)))')
self.assertEqual(gdb_repr,
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "
"14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, "
"27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, "
"40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, "
"53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, "
"66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, "
"79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, "
"92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, "
"104, 105, 106, 107, 108, 109, 110, 111, 112, 113, "
"114, 115, 116, 117, 118, 119, 120, 121, 122, 123, "
"124, 125, 126, 127, 128, 129, 130, 131, 132, 133, "
"134, 135, 136, 137, 138, 139, 140, 141, 142, 143, "
"144, 145, 146, 147, 148, 149, 150, 151, 152, 153, "
"154, 155, 156, 157, 158, 159, 160, 161, 162, 163, "
"164, 165, 166, 167, 168, 169, 170, 171, 172, 173, "
"174, 175, 176, 177, 178, 179, 180, 181, 182, 183, "
"184, 185, 186, 187, 188, 189, 190, 191, 192, 193, "
"194, 195, 196, 197, 198, 199, 200, 201, 202, 203, "
"204, 205, 206, 207, 208, 209, 210, 211, 212, 213, "
"214, 215, 216, 217, 218, 219, 220, 221, 222, 223, "
"224, 225, 226...(truncated)")
self.assertEqual(len(gdb_repr),
1024 + len('...(truncated)'))
def test_builtin_method(self):
gdb_repr, gdb_output = self.get_gdb_repr('import sys; id(sys.stdout.readlines)')
self.assertTrue(re.match('<built-in method readlines of _io.TextIOWrapper object at remote 0x-?[0-9a-f]+>',
gdb_repr),
'Unexpected gdb representation: %r\n%s' % \
(gdb_repr, gdb_output))
def test_frames(self):
gdb_output = self.get_stack_trace('''
def foo(a, b, c):
pass
foo(3, 4, 5)
id(foo.__code__)''',
breakpoint='builtin_id',
cmds_after_breakpoint=['print (PyFrameObject*)(((PyCodeObject*)v)->co_zombieframe)']
)
self.assertTrue(re.match('.*\s+\$1 =\s+Frame 0x-?[0-9a-f]+, for file <string>, line 3, in foo \(\)\s+.*',
gdb_output,
re.DOTALL),
'Unexpected gdb representation: %r\n%s' % (gdb_output, gdb_output))
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
class PyListTests(DebuggerTests):
def assertListing(self, expected, actual):
self.assertEndsWith(actual, expected)
def test_basic_command(self):
'Verify that the "py-list" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list'])
self.assertListing(' 5 \n'
' 6 def bar(a, b, c):\n'
' 7 baz(a, b, c)\n'
' 8 \n'
' 9 def baz(*args):\n'
' >10 id(42)\n'
' 11 \n'
' 12 foo(1, 2, 3)\n',
bt)
def test_one_abs_arg(self):
'Verify the "py-list" command with one absolute argument'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list 9'])
self.assertListing(' 9 def baz(*args):\n'
' >10 id(42)\n'
' 11 \n'
' 12 foo(1, 2, 3)\n',
bt)
def test_two_abs_args(self):
'Verify the "py-list" command with two absolute arguments'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-list 1,3'])
self.assertListing(' 1 # Sample script for use by test_gdb.py\n'
' 2 \n'
' 3 def foo(a, b, c):\n',
bt)
class StackNavigationTests(DebuggerTests):
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_pyup_command(self):
'Verify that the "py-up" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up'])
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\)
$''')
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
def test_down_at_bottom(self):
'Verify handling of "py-down" at the bottom of the stack'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-down'])
self.assertEndsWith(bt,
'Unable to find a newer python frame\n')
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
def test_up_at_top(self):
'Verify handling of "py-up" at the top of the stack'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up'] * 4)
self.assertEndsWith(bt,
'Unable to find an older python frame\n')
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_up_then_down(self):
'Verify "py-up" followed by "py-down"'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-down'])
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 10, in baz \(args=\(1, 2, 3\)\)
id\(42\)
$''')
class PyBtTests(DebuggerTests):
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_bt(self):
'Verify that the "py-bt" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-bt'])
self.assertMultilineMatches(bt,
r'''^.*
Traceback \(most recent call first\):
File ".*gdb_sample.py", line 10, in baz
id\(42\)
File ".*gdb_sample.py", line 7, in bar
baz\(a, b, c\)
File ".*gdb_sample.py", line 4, in foo
bar\(a, b, c\)
File ".*gdb_sample.py", line 12, in <module>
foo\(1, 2, 3\)
''')
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_bt_full(self):
'Verify that the "py-bt-full" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-bt-full'])
self.assertMultilineMatches(bt,
r'''^.*
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 7, in bar \(a=1, b=2, c=3\)
baz\(a, b, c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 4, in foo \(a=1, b=2, c=3\)
bar\(a, b, c\)
#[0-9]+ Frame 0x-?[0-9a-f]+, for file .*gdb_sample.py, line 12, in <module> \(\)
foo\(1, 2, 3\)
''')
@unittest.skipUnless(_thread,
"Python was compiled without thread support")
def test_threads(self):
'Verify that "py-bt" indicates threads that are waiting for the GIL'
cmd = '''
from threading import Thread
class TestThread(Thread):
# These threads would run forever, but we'll interrupt things with the
# debugger
def run(self):
i = 0
while 1:
i += 1
t = {}
for i in range(4):
t[i] = TestThread()
t[i].start()
# Trigger a breakpoint on the main thread
id(42)
'''
# Verify with "py-bt":
gdb_output = self.get_stack_trace(cmd,
cmds_after_breakpoint=['thread apply all py-bt'])
self.assertIn('Waiting for the GIL', gdb_output)
# Verify with "py-bt-full":
gdb_output = self.get_stack_trace(cmd,
cmds_after_breakpoint=['thread apply all py-bt-full'])
self.assertIn('Waiting for the GIL', gdb_output)
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
# Some older versions of gdb will fail with
# "Cannot find new threads: generic error"
# unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround
@unittest.skipUnless(_thread,
"Python was compiled without thread support")
def test_gc(self):
'Verify that "py-bt" indicates if a thread is garbage-collecting'
cmd = ('from gc import collect\n'
'id(42)\n'
'def foo():\n'
' collect()\n'
'def bar():\n'
' foo()\n'
'bar()\n')
# Verify with "py-bt":
gdb_output = self.get_stack_trace(cmd,
cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt'],
)
self.assertIn('Garbage-collecting', gdb_output)
# Verify with "py-bt-full":
gdb_output = self.get_stack_trace(cmd,
cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt-full'],
)
self.assertIn('Garbage-collecting', gdb_output)
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
# Some older versions of gdb will fail with
# "Cannot find new threads: generic error"
# unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround
@unittest.skipUnless(_thread,
"Python was compiled without thread support")
def test_pycfunction(self):
'Verify that "py-bt" displays invocations of PyCFunction instances'
cmd = ('from time import sleep\n'
'def foo():\n'
' sleep(1)\n'
'def bar():\n'
' foo()\n'
'bar()\n')
# Verify with "py-bt":
gdb_output = self.get_stack_trace(cmd,
breakpoint='time_sleep',
cmds_after_breakpoint=['bt', 'py-bt'],
)
self.assertIn('<built-in method sleep', gdb_output)
# Verify with "py-bt-full":
gdb_output = self.get_stack_trace(cmd,
breakpoint='time_sleep',
cmds_after_breakpoint=['py-bt-full'],
)
self.assertIn('#0 <built-in method sleep', gdb_output)
class PyPrintTests(DebuggerTests):
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_basic_command(self):
'Verify that the "py-print" command works'
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print args'])
self.assertMultilineMatches(bt,
r".*\nlocal 'args' = \(1, 2, 3\)\n.*")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
def test_print_after_up(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-print c', 'py-print b', 'py-print a'])
self.assertMultilineMatches(bt,
r".*\nlocal 'c' = 3\nlocal 'b' = 2\nlocal 'a' = 1\n.*")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_printing_global(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print __name__'])
self.assertMultilineMatches(bt,
r".*\nglobal '__name__' = '__main__'\n.*")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_printing_builtin(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-print len'])
self.assertMultilineMatches(bt,
r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*")
class PyLocalsTests(DebuggerTests):
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_basic_command(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-locals'])
self.assertMultilineMatches(bt,
r".*\nargs = \(1, 2, 3\)\n.*")
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
@unittest.skipIf(python_is_optimized(),
"Python was compiled with optimizations")
def test_locals_after_up(self):
bt = self.get_stack_trace(script=self.get_sample_script(),
cmds_after_breakpoint=['py-up', 'py-locals'])
self.assertMultilineMatches(bt,
r".*\na = 1\nb = 2\nc = 3\n.*")
def test_main():
if support.verbose:
print("GDB version:")
for line in os.fsdecode(gdb_version).splitlines():
print(" " * 4 + line)
run_unittest(PrettyPrintTests,
PyListTests,
StackNavigationTests,
PyBtTests,
PyPrintTests,
PyLocalsTests
)
if __name__ == "__main__":
test_main()
|
gpl-2.0
|
[
3,
7635,
626,
12124,
883,
7268,
13,
1361,
314,
7750,
24106,
10,
2943,
199,
3,
199,
3,
710,
1233,
367,
5343,
12124,
1990,
26266,
687,
8545,
1736,
315,
1910,
416,
848,
16666,
3306,
1159,
199,
3,
8003,
15,
396,
15,
396,
63,
17676,
63,
17119,
14,
647,
199,
199,
646,
747,
199,
646,
295,
199,
646,
10933,
199,
646,
3873,
199,
646,
984,
199,
646,
22381,
199,
646,
2882,
199,
646,
5867,
199,
199,
3,
6596,
642,
2018,
7526,
370,
2291,
7183,
31,
199,
893,
26,
272,
492,
485,
2671,
199,
2590,
3545,
26,
272,
485,
2671,
275,
488,
199,
199,
504,
511,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
12,
2342,
493,
12,
2366,
63,
374,
63,
25499,
199,
199,
893,
26,
272,
12124,
63,
1023,
12,
485,
275,
3873,
14,
7942,
5234,
17119,
401,
3905,
7343,
401,
4320,
1023,
2255,
4228,
3839,
29,
5781,
14,
6089,
680,
10664,
342,
199,
2590,
6440,
26,
272,
327,
961,
365,
4052,
298,
889,
12124,
2,
10734,
2839,
14,
221,
6006,
1443,
12,
13432,
12,
506,
1163,
272,
327,
2552,
626,
7712,
642,
4340,
4634,
14,
272,
746,
2882,
14,
25755,
480,
20485,
1133,
2342,
12124,
641,
314,
931,
531,
199,
17119,
63,
1023,
63,
1955,
275,
295,
14,
1733,
8,
66,
16136,
17732,
12124,
359,
12773,
68,
3672,
2961,
68,
13439,
14,
2961,
68,
4186,
12124,
63,
1023,
9,
199,
17119,
63,
8452,
63,
1023,
275,
1109,
8,
17119,
63,
1023,
63,
1955,
14,
923,
8,
17,
430,
199,
17119,
63,
11067,
63,
1023,
275,
1109,
8,
17119,
63,
1023,
63,
1955,
14,
923,
8,
18,
430,
199,
692,
12124,
63,
8452,
63,
1023,
665,
1520,
26,
272,
746,
2882,
14,
25755,
480,
17119,
5459,
2544,
1520,
14,
16,
9980,
1133,
2291,
2366,
12452,
2,
1169,
298,
428,
10084,
3427,
78,
2,
435,
12124,
63,
1023,
14,
2708,
360,
4371,
297,
283,
1814,
1333,
199,
199,
692,
440,
22381,
14,
374,
63,
1548,
63,
1506,
837,
272,
746,
2882,
14,
25755,
480,
396,
63,
17119,
1454,
5419,
641,
1350,
14723,
737,
314,
12427,
2685,
199,
199,
3,
12625,
402,
3537,
12604,
570,
315,
282,
7611,
15243,
14,
199,
12891,
63,
3664,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
5904,
395,
3303,
283,
1548,
13,
17119,
14,
647,
358,
199,
199,
11720,
14395,
25508,
275,
283,
4288,
7,
199,
199,
318,
1255,
63,
17119,
2031,
589,
12,
1011,
1813,
63,
2936,
304,
272,
408,
16291,
12124,
315,
1553,
2912,
818,
543,
314,
4722,
2368,
1627,
701,
627,
589,
14,
339,
1803,
2399,
334,
2703,
12,
4635,
9,
11203,
687,
2774,
13,
24,
1808,
314,
3350,
3016,
14,
272,
408,
272,
340,
2589,
63,
2936,
26,
267,
2589,
275,
747,
14,
2314,
14,
1574,
342,
267,
2589,
14,
873,
8,
1813,
63,
2936,
9,
272,
587,
26,
267,
2589,
275,
488,
272,
327,
446,
7343,
26,
4226,
440,
5341,
3718,
687,
1263,
1275,
17119,
826,
11097,
1584,
272,
327,
420,
334,
5237,
327,
1081,
11501,
9,
272,
1300,
63,
1760,
275,
661,
17119,
297,
2850,
2912,
297,
2475,
7343,
358,
272,
340,
334,
17119,
63,
8452,
63,
1023,
12,
12124,
63,
11067,
63,
1023,
9,
2356,
334,
23,
12,
841,
304,
267,
1300,
63,
1760,
847,
12291,
73,
476,
297,
283,
525,
13,
2495,
13,
912,
13,
3489,
13,
515,
283,
435,
15243,
63,
3664,
63,
515,
9,
272,
734,
12,
2329,
275,
3873,
14,
7942,
8,
1095,
63,
1760,
435,
1249,
12,
267,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
2589,
29,
1813,
12,
267,
7092,
10664,
342,
272,
372,
734,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
659,
2329,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
358,
199,
199,
3,
7635,
626,
298,
17119,
2,
1990,
6137,
543,
314,
12169,
2366,
2291,
5223,
26,
199,
17119,
647,
63,
1023,
12,
485,
275,
1255,
63,
17119,
6739,
2579,
13,
1531,
29,
1548,
492,
984,
27,
870,
8,
1274,
14,
1023,
63,
815,
6320,
199,
692,
440,
12124,
647,
63,
1023,
26,
272,
746,
2882,
14,
25755,
480,
17119,
440,
6137,
543,
12169,
2366,
2291,
531,
199,
199,
3,
7635,
626,
298,
17119,
2,
883,
2248,
4154,
3537,
12604,
12,
465,
4403,
6391,
2202,
1443,
199,
3,
2153,
3306,
642,
1928,
282,
3537,
9096,
1275,
17119,
826,
14,
199,
1760,
275,
14574,
589,
297,
984,
14,
5904,
61,
199,
3131,
12124,
647,
63,
2550,
275,
1255,
63,
17119,
4517,
589,
297,
984,
14,
5904,
9,
199,
692,
298,
2495,
13,
8786,
965,
2757,
15021,
1942,
2,
315,
12124,
647,
63,
2550,
26,
272,
1499,
275,
298,
17119,
6391,
2202,
7981,
675,
402,
3537,
12604,
26,
298,
272,
746,
2882,
14,
25755,
8,
1328,
435,
12124,
647,
63,
2550,
14,
6735,
1012,
199,
199,
318,
12124,
63,
1989,
63,
1943,
63,
2416,
837,
272,
327,
12078,
642,
1900,
402,
12124,
1172,
12124,
14,
3160,
14,
2416,
5805,
272,
3839,
12,
485,
275,
1255,
63,
17119,
6739,
2579,
13,
1531,
29,
1548,
870,
8,
694,
8,
17119,
14,
3160,
430,
531,
272,
333,
275,
295,
14,
1431,
8,
82,
1370,
7590,
7528,
2795,
2862,
1055,
7693,
3839,
9,
272,
340,
440,
333,
26,
267,
746,
2882,
14,
25755,
480,
6005,
370,
2198,
1072,
687,
12124,
14,
3160,
14,
2416,
511,
531,
272,
12124,
63,
1943,
63,
694,
275,
333,
14,
923,
8,
17,
680,
1294,
5102,
5320,
272,
372,
3546,
2416,
4065,
315,
12124,
63,
1943,
63,
694,
199,
199,
13533,
63,
4521,
2160,
63,
4521,
8819,
275,
12124,
63,
1989,
63,
1943,
63,
2416,
342,
199,
199,
14731,
7217,
63,
4963,
534,
5351,
63,
344,
7,
199,
199,
533,
14245,
836,
2925,
8,
2796,
14,
1746,
304,
339,
408,
774,
626,
314,
14958,
883,
3105,
2018,
1041,
339,
347,
664,
63,
2340,
63,
3446,
8,
277,
12,
1350,
29,
403,
12,
2884,
29,
403,
12,
717,
17944,
29,
14731,
7217,
63,
4963,
12,
717,
11465,
63,
4399,
63,
20081,
29,
403,
12,
717,
492,
63,
2124,
29,
797,
304,
267,
1449,
267,
3378,
283,
1548,
446,
67,
25470,
7,
1334,
12124,
543,
282,
17944,
14
] |
[
7635,
626,
12124,
883,
7268,
13,
1361,
314,
7750,
24106,
10,
2943,
199,
3,
199,
3,
710,
1233,
367,
5343,
12124,
1990,
26266,
687,
8545,
1736,
315,
1910,
416,
848,
16666,
3306,
1159,
199,
3,
8003,
15,
396,
15,
396,
63,
17676,
63,
17119,
14,
647,
199,
199,
646,
747,
199,
646,
295,
199,
646,
10933,
199,
646,
3873,
199,
646,
984,
199,
646,
22381,
199,
646,
2882,
199,
646,
5867,
199,
199,
3,
6596,
642,
2018,
7526,
370,
2291,
7183,
31,
199,
893,
26,
272,
492,
485,
2671,
199,
2590,
3545,
26,
272,
485,
2671,
275,
488,
199,
199,
504,
511,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
12,
2342,
493,
12,
2366,
63,
374,
63,
25499,
199,
199,
893,
26,
272,
12124,
63,
1023,
12,
485,
275,
3873,
14,
7942,
5234,
17119,
401,
3905,
7343,
401,
4320,
1023,
2255,
4228,
3839,
29,
5781,
14,
6089,
680,
10664,
342,
199,
2590,
6440,
26,
272,
327,
961,
365,
4052,
298,
889,
12124,
2,
10734,
2839,
14,
221,
6006,
1443,
12,
13432,
12,
506,
1163,
272,
327,
2552,
626,
7712,
642,
4340,
4634,
14,
272,
746,
2882,
14,
25755,
480,
20485,
1133,
2342,
12124,
641,
314,
931,
531,
199,
17119,
63,
1023,
63,
1955,
275,
295,
14,
1733,
8,
66,
16136,
17732,
12124,
359,
12773,
68,
3672,
2961,
68,
13439,
14,
2961,
68,
4186,
12124,
63,
1023,
9,
199,
17119,
63,
8452,
63,
1023,
275,
1109,
8,
17119,
63,
1023,
63,
1955,
14,
923,
8,
17,
430,
199,
17119,
63,
11067,
63,
1023,
275,
1109,
8,
17119,
63,
1023,
63,
1955,
14,
923,
8,
18,
430,
199,
692,
12124,
63,
8452,
63,
1023,
665,
1520,
26,
272,
746,
2882,
14,
25755,
480,
17119,
5459,
2544,
1520,
14,
16,
9980,
1133,
2291,
2366,
12452,
2,
1169,
298,
428,
10084,
3427,
78,
2,
435,
12124,
63,
1023,
14,
2708,
360,
4371,
297,
283,
1814,
1333,
199,
199,
692,
440,
22381,
14,
374,
63,
1548,
63,
1506,
837,
272,
746,
2882,
14,
25755,
480,
396,
63,
17119,
1454,
5419,
641,
1350,
14723,
737,
314,
12427,
2685,
199,
199,
3,
12625,
402,
3537,
12604,
570,
315,
282,
7611,
15243,
14,
199,
12891,
63,
3664,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
5904,
395,
3303,
283,
1548,
13,
17119,
14,
647,
358,
199,
199,
11720,
14395,
25508,
275,
283,
4288,
7,
199,
199,
318,
1255,
63,
17119,
2031,
589,
12,
1011,
1813,
63,
2936,
304,
272,
408,
16291,
12124,
315,
1553,
2912,
818,
543,
314,
4722,
2368,
1627,
701,
627,
589,
14,
339,
1803,
2399,
334,
2703,
12,
4635,
9,
11203,
687,
2774,
13,
24,
1808,
314,
3350,
3016,
14,
272,
408,
272,
340,
2589,
63,
2936,
26,
267,
2589,
275,
747,
14,
2314,
14,
1574,
342,
267,
2589,
14,
873,
8,
1813,
63,
2936,
9,
272,
587,
26,
267,
2589,
275,
488,
272,
327,
446,
7343,
26,
4226,
440,
5341,
3718,
687,
1263,
1275,
17119,
826,
11097,
1584,
272,
327,
420,
334,
5237,
327,
1081,
11501,
9,
272,
1300,
63,
1760,
275,
661,
17119,
297,
2850,
2912,
297,
2475,
7343,
358,
272,
340,
334,
17119,
63,
8452,
63,
1023,
12,
12124,
63,
11067,
63,
1023,
9,
2356,
334,
23,
12,
841,
304,
267,
1300,
63,
1760,
847,
12291,
73,
476,
297,
283,
525,
13,
2495,
13,
912,
13,
3489,
13,
515,
283,
435,
15243,
63,
3664,
63,
515,
9,
272,
734,
12,
2329,
275,
3873,
14,
7942,
8,
1095,
63,
1760,
435,
1249,
12,
267,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
6089,
12,
2589,
29,
1813,
12,
267,
7092,
10664,
342,
272,
372,
734,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
659,
2329,
14,
2708,
360,
1624,
13,
24,
297,
283,
1814,
358,
199,
199,
3,
7635,
626,
298,
17119,
2,
1990,
6137,
543,
314,
12169,
2366,
2291,
5223,
26,
199,
17119,
647,
63,
1023,
12,
485,
275,
1255,
63,
17119,
6739,
2579,
13,
1531,
29,
1548,
492,
984,
27,
870,
8,
1274,
14,
1023,
63,
815,
6320,
199,
692,
440,
12124,
647,
63,
1023,
26,
272,
746,
2882,
14,
25755,
480,
17119,
440,
6137,
543,
12169,
2366,
2291,
531,
199,
199,
3,
7635,
626,
298,
17119,
2,
883,
2248,
4154,
3537,
12604,
12,
465,
4403,
6391,
2202,
1443,
199,
3,
2153,
3306,
642,
1928,
282,
3537,
9096,
1275,
17119,
826,
14,
199,
1760,
275,
14574,
589,
297,
984,
14,
5904,
61,
199,
3131,
12124,
647,
63,
2550,
275,
1255,
63,
17119,
4517,
589,
297,
984,
14,
5904,
9,
199,
692,
298,
2495,
13,
8786,
965,
2757,
15021,
1942,
2,
315,
12124,
647,
63,
2550,
26,
272,
1499,
275,
298,
17119,
6391,
2202,
7981,
675,
402,
3537,
12604,
26,
298,
272,
746,
2882,
14,
25755,
8,
1328,
435,
12124,
647,
63,
2550,
14,
6735,
1012,
199,
199,
318,
12124,
63,
1989,
63,
1943,
63,
2416,
837,
272,
327,
12078,
642,
1900,
402,
12124,
1172,
12124,
14,
3160,
14,
2416,
5805,
272,
3839,
12,
485,
275,
1255,
63,
17119,
6739,
2579,
13,
1531,
29,
1548,
870,
8,
694,
8,
17119,
14,
3160,
430,
531,
272,
333,
275,
295,
14,
1431,
8,
82,
1370,
7590,
7528,
2795,
2862,
1055,
7693,
3839,
9,
272,
340,
440,
333,
26,
267,
746,
2882,
14,
25755,
480,
6005,
370,
2198,
1072,
687,
12124,
14,
3160,
14,
2416,
511,
531,
272,
12124,
63,
1943,
63,
694,
275,
333,
14,
923,
8,
17,
680,
1294,
5102,
5320,
272,
372,
3546,
2416,
4065,
315,
12124,
63,
1943,
63,
694,
199,
199,
13533,
63,
4521,
2160,
63,
4521,
8819,
275,
12124,
63,
1989,
63,
1943,
63,
2416,
342,
199,
199,
14731,
7217,
63,
4963,
534,
5351,
63,
344,
7,
199,
199,
533,
14245,
836,
2925,
8,
2796,
14,
1746,
304,
339,
408,
774,
626,
314,
14958,
883,
3105,
2018,
1041,
339,
347,
664,
63,
2340,
63,
3446,
8,
277,
12,
1350,
29,
403,
12,
2884,
29,
403,
12,
717,
17944,
29,
14731,
7217,
63,
4963,
12,
717,
11465,
63,
4399,
63,
20081,
29,
403,
12,
717,
492,
63,
2124,
29,
797,
304,
267,
1449,
267,
3378,
283,
1548,
446,
67,
25470,
7,
1334,
12124,
543,
282,
17944,
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,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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
] |
HKUST-SING/tensorflow
|
tensorflow/python/debug/cli/readline_ui_test.py
|
81
|
5646
|
# 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.
# ==============================================================================
"""Tests of the readline-based CLI."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import tempfile
from tensorflow.python.debug.cli import debugger_cli_common
from tensorflow.python.debug.cli import readline_ui
from tensorflow.python.debug.cli import ui_factory
from tensorflow.python.framework import test_util
from tensorflow.python.platform import gfile
from tensorflow.python.platform import googletest
class MockReadlineUI(readline_ui.ReadlineUI):
"""Test subclass of ReadlineUI that bypasses terminal manipulations."""
def __init__(self, on_ui_exit=None, command_sequence=None):
readline_ui.ReadlineUI.__init__(self, on_ui_exit=on_ui_exit)
self._command_sequence = command_sequence
self._command_counter = 0
self.observers = {"screen_outputs": []}
def _get_user_command(self):
command = self._command_sequence[self._command_counter]
self._command_counter += 1
return command
def _display_output(self, screen_output):
self.observers["screen_outputs"].append(screen_output)
class CursesTest(test_util.TensorFlowTestCase):
def _babble(self, args, screen_info=None):
ap = argparse.ArgumentParser(
description="Do babble.", usage=argparse.SUPPRESS)
ap.add_argument(
"-n",
"--num_times",
dest="num_times",
type=int,
default=60,
help="How many times to babble")
parsed = ap.parse_args(args)
lines = ["bar"] * parsed.num_times
return debugger_cli_common.RichTextLines(lines)
def testUIFactoryCreatesReadlineUI(self):
ui = ui_factory.get_ui("readline")
self.assertIsInstance(ui, readline_ui.ReadlineUI)
def testUIFactoryRaisesExceptionOnInvalidUIType(self):
with self.assertRaisesRegexp(ValueError, "Invalid ui_type: 'foobar'"):
ui_factory.get_ui("foobar")
def testUIFactoryRaisesExceptionOnInvalidUITypeGivenAvailable(self):
with self.assertRaisesRegexp(ValueError, "Invalid ui_type: 'readline'"):
ui_factory.get_ui("readline", available_ui_types=["curses"])
def testRunUIExitImmediately(self):
"""Make sure that the UI can exit properly after launch."""
ui = MockReadlineUI(command_sequence=["exit"])
ui.run_ui()
# No screen output should have happened.
self.assertEqual(0, len(ui.observers["screen_outputs"]))
def testRunUIEmptyCommand(self):
"""Issue an empty command then exit."""
ui = MockReadlineUI(command_sequence=["", "exit"])
ui.run_ui()
self.assertEqual(1, len(ui.observers["screen_outputs"]))
def testRunUIWithInitCmd(self):
"""Run UI with an initial command specified."""
ui = MockReadlineUI(command_sequence=["exit"])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui(init_command="babble")
screen_outputs = ui.observers["screen_outputs"]
self.assertEqual(1, len(screen_outputs))
self.assertEqual(["bar"] * 60, screen_outputs[0].lines)
def testRunUIWithValidUsersCommands(self):
"""Run UI with an initial command specified."""
ui = MockReadlineUI(command_sequence=["babble -n 3", "babble -n 6", "exit"])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
screen_outputs = ui.observers["screen_outputs"]
self.assertEqual(2, len(screen_outputs))
self.assertEqual(["bar"] * 3, screen_outputs[0].lines)
self.assertEqual(["bar"] * 6, screen_outputs[1].lines)
def testRunUIWithInvalidUsersCommands(self):
"""Run UI with an initial command specified."""
ui = MockReadlineUI(command_sequence=["babble -n 3", "wobble", "exit"])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
screen_outputs = ui.observers["screen_outputs"]
self.assertEqual(2, len(screen_outputs))
self.assertEqual(["bar"] * 3, screen_outputs[0].lines)
self.assertEqual(["ERROR: Invalid command prefix \"wobble\""],
screen_outputs[1].lines)
def testRunUIWithOnUIExitCallback(self):
observer = {"callback_invoked": False}
def callback_for_test():
observer["callback_invoked"] = True
ui = MockReadlineUI(on_ui_exit=callback_for_test, command_sequence=["exit"])
self.assertFalse(observer["callback_invoked"])
ui.run_ui()
self.assertEqual(0, len(ui.observers["screen_outputs"]))
self.assertTrue(observer["callback_invoked"])
def testIncompleteRedirectWorks(self):
output_path = tempfile.mktemp()
ui = MockReadlineUI(
command_sequence=["babble -n 2 > %s" % output_path, "exit"])
ui.register_command_handler("babble", self._babble, "")
ui.run_ui()
screen_outputs = ui.observers["screen_outputs"]
self.assertEqual(1, len(screen_outputs))
self.assertEqual(["bar"] * 2, screen_outputs[0].lines)
with gfile.Open(output_path, "r") as f:
self.assertEqual("bar\nbar\n", f.read())
if __name__ == "__main__":
googletest.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
402,
314,
14441,
13,
6788,
14214,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
5549,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14441,
63,
1907,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
8574,
63,
3702,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
4420,
3284,
604,
6379,
8,
6407,
63,
1907,
14,
3284,
604,
6379,
304,
523,
408,
774,
5516,
402,
5574,
604,
6379,
626,
701,
16027,
11167,
13335,
21429,
1041,
819,
347,
636,
826,
721,
277,
12,
641,
63,
1907,
63,
2224,
29,
403,
12,
1414,
63,
4041,
29,
403,
304,
272,
14441,
63,
1907,
14,
3284,
604,
6379,
855,
826,
721,
277,
12,
641,
63,
1907,
63,
2224,
29,
265,
63,
1907,
63,
2224,
9,
339,
291,
423,
1531,
63,
4041,
275,
1414,
63,
4041,
272,
291,
423,
1531,
63,
5337,
275,
378,
339,
291,
14,
2873,
5871,
275,
2420,
5410,
63,
4467,
582,
23455,
819,
347,
485,
362,
63,
751,
63,
1531,
8,
277,
304,
272,
1414,
275,
291,
423,
1531,
63,
4041,
59,
277,
423,
1531,
63,
5337,
61,
272,
291,
423,
1531,
63,
5337,
847,
413,
272,
372,
1414,
819,
347,
485,
2918,
63,
1199,
8,
277,
12,
6426,
63,
1199,
304,
272,
291,
14,
2873,
5871,
905,
5410,
63,
4467,
4140,
740,
8,
5410,
63,
1199,
9,
421,
199,
533,
7319,
874,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
485,
26118,
830,
8,
277,
12,
1249,
12,
6426,
63,
815,
29,
403,
304,
272,
2771,
275,
7534,
14,
10730,
8,
267,
1369,
628,
2585,
330,
371,
830,
4765,
4503,
29,
18978,
14,
24023,
9,
272,
2771,
14,
525,
63,
2094,
8,
267,
3905,
78,
401,
267,
4320,
1507,
63,
4508,
401,
267,
2053,
628,
1507,
63,
4508,
401,
267,
730,
29,
442,
12,
267,
849,
29,
2259,
12,
267,
1720,
628,
18335,
5002,
5431,
370,
330,
371,
830,
531,
339,
4565,
275,
2771,
14,
1122,
63,
589,
8,
589,
9,
339,
2385,
275,
2097,
1700,
937,
627,
4565,
14,
1507,
63,
4508,
272,
372,
14958,
63,
2764,
63,
2330,
14,
19537,
9863,
8,
1278,
9,
819,
347,
511,
6379,
2927,
10607,
3284,
604,
6379,
8,
277,
304,
272,
8574,
275,
8574,
63,
3702,
14,
362,
63,
1907,
480,
6407,
531,
272,
291,
14,
6926,
8,
1907,
12,
14441,
63,
1907,
14,
3284,
604,
6379,
9,
819,
347,
511,
6379,
2927,
1811,
1726,
3314,
3364,
28666,
514,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
298,
3364,
8574,
63,
466,
26,
283,
9664,
7,
2349,
489,
8574,
63,
3702,
14,
362,
63,
1907,
480,
9664,
531,
819,
347,
511,
6379,
2927,
1811,
1726,
3314,
3364,
28666,
514,
13735,
11464,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
298,
3364,
8574,
63,
466,
26,
283,
6407,
7,
2349,
489,
8574,
63,
3702,
14,
362,
63,
1907,
480,
6407,
401,
2808,
63,
1907,
63,
1313,
6270,
12026,
3135,
819,
347,
511,
2540,
6379,
6699,
24481,
590,
8,
277,
304,
272,
408,
5483,
3238,
626,
314,
14041,
883,
4458,
7684,
2410,
10623,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
2224,
3135,
272,
8574,
14,
1065,
63,
1907,
342,
339,
327,
3091,
6426,
1072,
1077,
1172,
21056,
14,
272,
291,
14,
629,
8,
16,
12,
822,
8,
1907,
14,
2873,
5871,
905,
5410,
63,
4467,
13045,
819,
347,
511,
2540,
53,
4332,
1171,
3110,
8,
277,
304,
272,
408,
17106,
376,
2701,
1414,
2066,
4458,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
1524,
5151,
298,
2224,
3135,
272,
8574,
14,
1065,
63,
1907,
342,
272,
291,
14,
629,
8,
17,
12,
822,
8,
1907,
14,
2873,
5871,
905,
5410,
63,
4467,
13045,
819,
347,
511,
2540,
6379,
3007,
9346,
7874,
8,
277,
304,
272,
408,
2540,
14041,
543,
376,
2536,
1414,
2013,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
2224,
3135,
339,
8574,
14,
2683,
63,
1531,
63,
2232,
480,
26118,
830,
401,
291,
423,
26118,
830,
12,
6899,
272,
8574,
14,
1065,
63,
1907,
8,
826,
63,
1531,
628,
26118,
830,
531,
339,
6426,
63,
4467,
275,
8574,
14,
2873,
5871,
905,
5410,
63,
4467,
937,
272,
291,
14,
629,
8,
17,
12,
822,
8,
5410,
63,
4467,
430,
272,
291,
14,
629,
5234,
1700,
937,
627,
5212,
12,
6426,
63,
4467,
59,
16,
1055,
1278,
9,
819,
347,
511,
2540,
6379,
3007,
3490,
12117,
14680,
8,
277,
304,
272,
408,
2540,
14041,
543,
376,
2536,
1414,
2013,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
26118,
830,
446,
78,
650,
401,
298,
26118,
830,
446,
78,
1227,
401,
298,
2224,
3135,
272,
8574,
14,
2683,
63,
1531,
63,
2232,
480,
26118,
830,
401,
291,
423,
26118,
830,
12,
6899,
272,
8574,
14,
1065,
63,
1907,
342,
339,
6426,
63,
4467,
275
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
402,
314,
14441,
13,
6788,
14214,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
5549,
199,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14958,
63,
2764,
63,
2330,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
14441,
63,
1907,
199,
504,
3228,
14,
1548,
14,
1757,
14,
2764,
492,
8574,
63,
3702,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
3246,
492,
26532,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
4420,
3284,
604,
6379,
8,
6407,
63,
1907,
14,
3284,
604,
6379,
304,
523,
408,
774,
5516,
402,
5574,
604,
6379,
626,
701,
16027,
11167,
13335,
21429,
1041,
819,
347,
636,
826,
721,
277,
12,
641,
63,
1907,
63,
2224,
29,
403,
12,
1414,
63,
4041,
29,
403,
304,
272,
14441,
63,
1907,
14,
3284,
604,
6379,
855,
826,
721,
277,
12,
641,
63,
1907,
63,
2224,
29,
265,
63,
1907,
63,
2224,
9,
339,
291,
423,
1531,
63,
4041,
275,
1414,
63,
4041,
272,
291,
423,
1531,
63,
5337,
275,
378,
339,
291,
14,
2873,
5871,
275,
2420,
5410,
63,
4467,
582,
23455,
819,
347,
485,
362,
63,
751,
63,
1531,
8,
277,
304,
272,
1414,
275,
291,
423,
1531,
63,
4041,
59,
277,
423,
1531,
63,
5337,
61,
272,
291,
423,
1531,
63,
5337,
847,
413,
272,
372,
1414,
819,
347,
485,
2918,
63,
1199,
8,
277,
12,
6426,
63,
1199,
304,
272,
291,
14,
2873,
5871,
905,
5410,
63,
4467,
4140,
740,
8,
5410,
63,
1199,
9,
421,
199,
533,
7319,
874,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
485,
26118,
830,
8,
277,
12,
1249,
12,
6426,
63,
815,
29,
403,
304,
272,
2771,
275,
7534,
14,
10730,
8,
267,
1369,
628,
2585,
330,
371,
830,
4765,
4503,
29,
18978,
14,
24023,
9,
272,
2771,
14,
525,
63,
2094,
8,
267,
3905,
78,
401,
267,
4320,
1507,
63,
4508,
401,
267,
2053,
628,
1507,
63,
4508,
401,
267,
730,
29,
442,
12,
267,
849,
29,
2259,
12,
267,
1720,
628,
18335,
5002,
5431,
370,
330,
371,
830,
531,
339,
4565,
275,
2771,
14,
1122,
63,
589,
8,
589,
9,
339,
2385,
275,
2097,
1700,
937,
627,
4565,
14,
1507,
63,
4508,
272,
372,
14958,
63,
2764,
63,
2330,
14,
19537,
9863,
8,
1278,
9,
819,
347,
511,
6379,
2927,
10607,
3284,
604,
6379,
8,
277,
304,
272,
8574,
275,
8574,
63,
3702,
14,
362,
63,
1907,
480,
6407,
531,
272,
291,
14,
6926,
8,
1907,
12,
14441,
63,
1907,
14,
3284,
604,
6379,
9,
819,
347,
511,
6379,
2927,
1811,
1726,
3314,
3364,
28666,
514,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
298,
3364,
8574,
63,
466,
26,
283,
9664,
7,
2349,
489,
8574,
63,
3702,
14,
362,
63,
1907,
480,
9664,
531,
819,
347,
511,
6379,
2927,
1811,
1726,
3314,
3364,
28666,
514,
13735,
11464,
8,
277,
304,
272,
543,
291,
14,
10835,
8,
3393,
12,
298,
3364,
8574,
63,
466,
26,
283,
6407,
7,
2349,
489,
8574,
63,
3702,
14,
362,
63,
1907,
480,
6407,
401,
2808,
63,
1907,
63,
1313,
6270,
12026,
3135,
819,
347,
511,
2540,
6379,
6699,
24481,
590,
8,
277,
304,
272,
408,
5483,
3238,
626,
314,
14041,
883,
4458,
7684,
2410,
10623,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
2224,
3135,
272,
8574,
14,
1065,
63,
1907,
342,
339,
327,
3091,
6426,
1072,
1077,
1172,
21056,
14,
272,
291,
14,
629,
8,
16,
12,
822,
8,
1907,
14,
2873,
5871,
905,
5410,
63,
4467,
13045,
819,
347,
511,
2540,
53,
4332,
1171,
3110,
8,
277,
304,
272,
408,
17106,
376,
2701,
1414,
2066,
4458,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
1524,
5151,
298,
2224,
3135,
272,
8574,
14,
1065,
63,
1907,
342,
272,
291,
14,
629,
8,
17,
12,
822,
8,
1907,
14,
2873,
5871,
905,
5410,
63,
4467,
13045,
819,
347,
511,
2540,
6379,
3007,
9346,
7874,
8,
277,
304,
272,
408,
2540,
14041,
543,
376,
2536,
1414,
2013,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
2224,
3135,
339,
8574,
14,
2683,
63,
1531,
63,
2232,
480,
26118,
830,
401,
291,
423,
26118,
830,
12,
6899,
272,
8574,
14,
1065,
63,
1907,
8,
826,
63,
1531,
628,
26118,
830,
531,
339,
6426,
63,
4467,
275,
8574,
14,
2873,
5871,
905,
5410,
63,
4467,
937,
272,
291,
14,
629,
8,
17,
12,
822,
8,
5410,
63,
4467,
430,
272,
291,
14,
629,
5234,
1700,
937,
627,
5212,
12,
6426,
63,
4467,
59,
16,
1055,
1278,
9,
819,
347,
511,
2540,
6379,
3007,
3490,
12117,
14680,
8,
277,
304,
272,
408,
2540,
14041,
543,
376,
2536,
1414,
2013,
1041,
339,
8574,
275,
4420,
3284,
604,
6379,
8,
1531,
63,
4041,
6270,
26118,
830,
446,
78,
650,
401,
298,
26118,
830,
446,
78,
1227,
401,
298,
2224,
3135,
272,
8574,
14,
2683,
63,
1531,
63,
2232,
480,
26118,
830,
401,
291,
423,
26118,
830,
12,
6899,
272,
8574,
14,
1065,
63,
1907,
342,
339,
6426,
63,
4467,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
EricMuller/mynotes-backend
|
requirements/twisted/Twisted-17.1.0/src/twisted/logger/test/test_logger.py
|
13
|
6922
|
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Test cases for L{twisted.logger._logger}.
"""
from twisted.trial import unittest
from .._levels import InvalidLogLevelError
from .._levels import LogLevel
from .._format import formatEvent
from .._logger import Logger
from .._global import globalLogPublisher
class TestLogger(Logger):
"""
L{Logger} with an overridden C{emit} method that keeps track of received
events.
"""
def emit(self, level, format=None, **kwargs):
def observer(event):
self.event = event
globalLogPublisher.addObserver(observer)
try:
Logger.emit(self, level, format, **kwargs)
finally:
globalLogPublisher.removeObserver(observer)
self.emitted = {
"level": level,
"format": format,
"kwargs": kwargs,
}
class LogComposedObject(object):
"""
A regular object, with a logger attached.
"""
log = TestLogger()
def __init__(self, state=None):
self.state = state
def __str__(self):
return "<LogComposedObject {state}>".format(state=self.state)
class LoggerTests(unittest.TestCase):
"""
Tests for L{Logger}.
"""
def test_repr(self):
"""
repr() on Logger
"""
namespace = "bleargh"
log = Logger(namespace)
self.assertEqual(repr(log), "<Logger {0}>".format(repr(namespace)))
def test_namespaceDefault(self):
"""
Default namespace is module name.
"""
log = Logger()
self.assertEqual(log.namespace, __name__)
def test_namespaceAttribute(self):
"""
Default namespace for classes using L{Logger} as a descriptor is the
class name they were retrieved from.
"""
obj = LogComposedObject()
expectedNamespace = "{0}.{1}".format(
obj.__module__,
obj.__class__.__name__,
)
self.assertEqual(obj.log.namespace, expectedNamespace)
self.assertEqual(LogComposedObject.log.namespace, expectedNamespace)
self.assertIs(LogComposedObject.log.source, LogComposedObject)
self.assertIs(obj.log.source, obj)
self.assertIsNone(Logger().source)
def test_descriptorObserver(self):
"""
When used as a descriptor, the observer is propagated.
"""
observed = []
class MyObject(object):
log = Logger(observer=observed.append)
MyObject.log.info("hello")
self.assertEqual(len(observed), 1)
self.assertEqual(observed[0]['log_format'], "hello")
def test_sourceAvailableForFormatting(self):
"""
On instances that have a L{Logger} class attribute, the C{log_source}
key is available to format strings.
"""
obj = LogComposedObject("hello")
log = obj.log
log.error("Hello, {log_source}.")
self.assertIn("log_source", log.event)
self.assertEqual(log.event["log_source"], obj)
stuff = formatEvent(log.event)
self.assertIn("Hello, <LogComposedObject hello>.", stuff)
def test_basicLogger(self):
"""
Test that log levels and messages are emitted correctly for
Logger.
"""
log = TestLogger()
for level in LogLevel.iterconstants():
format = "This is a {level_name} message"
message = format.format(level_name=level.name)
logMethod = getattr(log, level.name)
logMethod(format, junk=message, level_name=level.name)
# Ensure that test_emit got called with expected arguments
self.assertEqual(log.emitted["level"], level)
self.assertEqual(log.emitted["format"], format)
self.assertEqual(log.emitted["kwargs"]["junk"], message)
self.assertTrue(hasattr(log, "event"), "No event observed.")
self.assertEqual(log.event["log_format"], format)
self.assertEqual(log.event["log_level"], level)
self.assertEqual(log.event["log_namespace"], __name__)
self.assertIsNone(log.event["log_source"])
self.assertEqual(log.event["junk"], message)
self.assertEqual(formatEvent(log.event), message)
def test_sourceOnClass(self):
"""
C{log_source} event key refers to the class.
"""
def observer(event):
self.assertEqual(event["log_source"], Thingo)
class Thingo(object):
log = TestLogger(observer=observer)
Thingo.log.info()
def test_sourceOnInstance(self):
"""
C{log_source} event key refers to the instance.
"""
def observer(event):
self.assertEqual(event["log_source"], thingo)
class Thingo(object):
log = TestLogger(observer=observer)
thingo = Thingo()
thingo.log.info()
def test_sourceUnbound(self):
"""
C{log_source} event key is L{None}.
"""
def observer(event):
self.assertIsNone(event["log_source"])
log = TestLogger(observer=observer)
log.info()
def test_defaultFailure(self):
"""
Test that log.failure() emits the right data.
"""
log = TestLogger()
try:
raise RuntimeError("baloney!")
except RuntimeError:
log.failure("Whoops")
errors = self.flushLoggedErrors(RuntimeError)
self.assertEqual(len(errors), 1)
self.assertEqual(log.emitted["level"], LogLevel.critical)
self.assertEqual(log.emitted["format"], "Whoops")
def test_conflictingKwargs(self):
"""
Make sure that kwargs conflicting with args don't pass through.
"""
log = TestLogger()
log.warn(
u"*",
log_format="#",
log_level=LogLevel.error,
log_namespace="*namespace*",
log_source="*source*",
)
self.assertEqual(log.event["log_format"], u"*")
self.assertEqual(log.event["log_level"], LogLevel.warn)
self.assertEqual(log.event["log_namespace"], log.namespace)
self.assertIsNone(log.event["log_source"])
def test_logInvalidLogLevel(self):
"""
Test passing in a bogus log level to C{emit()}.
"""
log = TestLogger()
log.emit("*bogus*")
errors = self.flushLoggedErrors(InvalidLogLevelError)
self.assertEqual(len(errors), 1)
def test_trace(self):
"""
Tracing keeps track of forwarding to the publisher.
"""
def publisher(event):
observer(event)
def observer(event):
self.assertEqual(event["log_trace"], [(log, publisher)])
log = TestLogger(observer=publisher)
log.info("Hello.", log_trace=[])
|
mit
|
[
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
774,
5560,
367,
491,
91,
12145,
14,
2921,
423,
2921,
5565,
199,
624,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
1275,
423,
11402,
492,
6378,
2445,
4670,
547,
199,
504,
1275,
423,
11402,
492,
5297,
4670,
199,
504,
1275,
423,
908,
492,
1475,
2390,
199,
504,
1275,
423,
2921,
492,
15996,
199,
504,
1275,
423,
2966,
492,
2288,
2445,
27341,
4388,
199,
533,
1379,
4455,
8,
4455,
304,
272,
408,
272,
491,
91,
4455,
93,
543,
376,
10087,
445,
91,
8159,
93,
1083,
626,
18578,
4426,
402,
3086,
272,
4474,
14,
272,
408,
339,
347,
8689,
8,
277,
12,
2166,
12,
1475,
29,
403,
12,
1011,
958,
304,
267,
347,
27336,
8,
1430,
304,
288,
291,
14,
1430,
275,
1566,
398,
2288,
2445,
27341,
14,
525,
22715,
8,
23968,
9,
267,
862,
26,
288,
15996,
14,
8159,
8,
277,
12,
2166,
12,
1475,
12,
1011,
958,
9,
267,
3753,
26,
288,
2288,
2445,
27341,
14,
2168,
22715,
8,
23968,
9,
398,
291,
14,
69,
4485,
275,
469,
288,
298,
1896,
582,
2166,
12,
288,
298,
908,
582,
1475,
12,
288,
298,
958,
582,
2074,
12,
267,
789,
4388,
199,
533,
5297,
16273,
939,
1692,
8,
785,
304,
272,
408,
272,
437,
5578,
909,
12,
543,
282,
2512,
10102,
14,
272,
408,
272,
943,
275,
1379,
4455,
342,
339,
347,
636,
826,
721,
277,
12,
1174,
29,
403,
304,
267,
291,
14,
929,
275,
1174,
2378,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
2445,
16273,
939,
1692,
469,
929,
93,
23167,
908,
8,
929,
29,
277,
14,
929,
9,
4388,
199,
533,
15996,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
4455,
5565,
272,
408,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
408,
267,
4700,
342,
641,
15996,
267,
408,
267,
3231,
275,
298,
830,
1273,
72,
2,
267,
943,
275,
15996,
8,
3251,
9,
267,
291,
14,
629,
8,
2722,
8,
793,
395,
3886,
4455,
469,
16,
93,
23167,
908,
8,
2722,
8,
3251,
1724,
2378,
347,
511,
63,
3251,
2698,
8,
277,
304,
267,
408,
267,
3758,
3231,
365,
859,
536,
14,
267,
408,
267,
943,
275,
15996,
342,
267,
291,
14,
629,
8,
793,
14,
3251,
12,
636,
354,
3368,
2378,
347,
511,
63,
3251,
1646,
8,
277,
304,
267,
408,
267,
3758,
3231,
367,
3992,
1808,
491,
91,
4455,
93,
465,
282,
5872,
365,
314,
267,
1021,
536,
2985,
4898,
12396,
687,
14,
267,
408,
267,
1559,
275,
5297,
16273,
939,
1692,
342,
267,
1420,
8814,
275,
5310,
16,
26944,
17,
5469,
908,
8,
288,
1559,
855,
578,
3108,
288,
1559,
855,
533,
4914,
354,
3108,
267,
776,
267,
291,
14,
629,
8,
1113,
14,
793,
14,
3251,
12,
1420,
8814,
9,
267,
291,
14,
629,
8,
2445,
16273,
939,
1692,
14,
793,
14,
3251,
12,
1420,
8814,
9,
267,
291,
14,
3436,
8,
2445,
16273,
939,
1692,
14,
793,
14,
1365,
12,
5297,
16273,
939,
1692,
9,
267,
291,
14,
3436,
8,
1113,
14,
793,
14,
1365,
12,
1559,
9,
267,
291,
14,
7702,
8,
4455,
1252,
1365,
9,
2378,
347,
511,
63,
4120,
22715,
8,
277,
304,
267,
408,
267,
3979,
1202,
465,
282,
5872,
12,
314,
27336,
365,
25350,
14,
267,
408,
267,
20802,
275,
942,
398,
1021,
4932,
1692,
8,
785,
304,
288,
943,
275,
15996,
8,
23968,
29,
22300,
14,
740,
9,
398,
4932,
1692,
14,
793,
14,
815,
480,
5006,
531,
267,
291,
14,
629,
8,
552,
8,
22300,
395,
413,
9,
267,
291,
14,
629,
8,
22300,
59,
16,
2733,
793,
63,
908,
995,
298,
5006,
531,
2378,
347,
511,
63,
1365,
11464,
1858,
20552,
8,
277,
304,
267,
408,
267,
4068,
4454,
626,
1172,
282,
491,
91,
4455,
93,
1021,
2225,
12,
314,
445,
91,
793,
63,
1365,
93,
267,
790,
365,
2808,
370,
1475,
3326,
14,
267,
408,
267,
1559,
275,
5297,
16273,
939,
1692,
480,
5006,
531,
267,
943,
275,
1559,
14,
793,
267,
943,
14,
705,
480,
6257,
12,
469,
793,
63,
1365,
93,
2685,
398,
291,
14,
4080,
480,
793,
63,
1365,
401,
943,
14,
1430,
9,
267,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
1365,
2255,
1559,
9,
398,
8292,
275,
1475,
2390,
8,
793,
14,
1430,
9,
267,
291,
14,
4080,
480,
6257,
12,
665,
2445,
16273,
939,
1692,
16509,
30,
4765,
8292,
9,
2378,
347,
511,
63,
4316,
4455,
8,
277,
304,
267,
408,
267,
1379,
626,
943,
11106,
436,
3788,
787,
19515,
6657,
367,
267,
15996,
14,
267,
408,
267,
943,
275,
1379,
4455,
342,
398,
367,
2166,
315,
5297,
4670,
14,
1661,
5559,
837,
288,
1475,
275,
298,
2765,
365,
282,
469,
1896,
63,
354,
93,
1245,
2,
288,
1245,
275,
1475,
14,
908,
8,
1896,
63,
354,
29,
1896,
14,
354,
9,
953,
943,
3767,
275,
2519,
8,
793,
12,
2166,
14,
354,
9,
288,
943,
3767,
8,
908,
12,
24605,
29,
1188,
12,
2166,
63,
354,
29,
1896,
14,
354,
9,
953,
327,
7523,
626,
511,
63,
8159,
4788,
2797,
543,
1420,
2368,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
1896,
2255,
2166,
9,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
908,
2255,
1475,
9,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
958,
6611,
17941,
2255,
1245,
9,
953,
291,
14,
1815,
8,
11161,
8,
793,
12,
298,
1430,
1288,
298,
1944,
1566,
20802,
2685,
953,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
908,
2255,
1475,
9,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
1896,
2255,
2166,
9,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
3251,
2255,
636,
354,
3368,
288,
291,
14,
7702,
8,
793,
14,
1430,
905,
793,
63,
1365,
3135,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
17941,
2255,
1245,
9,
953,
291,
14,
629,
8,
908,
2390,
8,
793,
14,
1430,
395,
1245,
9,
2378,
347,
511,
63,
1365,
3314,
2543,
8,
277,
304,
267,
408,
267,
445,
91,
793
] |
[
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
774,
5560,
367,
491,
91,
12145,
14,
2921,
423,
2921,
5565,
199,
624,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
1275,
423,
11402,
492,
6378,
2445,
4670,
547,
199,
504,
1275,
423,
11402,
492,
5297,
4670,
199,
504,
1275,
423,
908,
492,
1475,
2390,
199,
504,
1275,
423,
2921,
492,
15996,
199,
504,
1275,
423,
2966,
492,
2288,
2445,
27341,
4388,
199,
533,
1379,
4455,
8,
4455,
304,
272,
408,
272,
491,
91,
4455,
93,
543,
376,
10087,
445,
91,
8159,
93,
1083,
626,
18578,
4426,
402,
3086,
272,
4474,
14,
272,
408,
339,
347,
8689,
8,
277,
12,
2166,
12,
1475,
29,
403,
12,
1011,
958,
304,
267,
347,
27336,
8,
1430,
304,
288,
291,
14,
1430,
275,
1566,
398,
2288,
2445,
27341,
14,
525,
22715,
8,
23968,
9,
267,
862,
26,
288,
15996,
14,
8159,
8,
277,
12,
2166,
12,
1475,
12,
1011,
958,
9,
267,
3753,
26,
288,
2288,
2445,
27341,
14,
2168,
22715,
8,
23968,
9,
398,
291,
14,
69,
4485,
275,
469,
288,
298,
1896,
582,
2166,
12,
288,
298,
908,
582,
1475,
12,
288,
298,
958,
582,
2074,
12,
267,
789,
4388,
199,
533,
5297,
16273,
939,
1692,
8,
785,
304,
272,
408,
272,
437,
5578,
909,
12,
543,
282,
2512,
10102,
14,
272,
408,
272,
943,
275,
1379,
4455,
342,
339,
347,
636,
826,
721,
277,
12,
1174,
29,
403,
304,
267,
291,
14,
929,
275,
1174,
2378,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
2445,
16273,
939,
1692,
469,
929,
93,
23167,
908,
8,
929,
29,
277,
14,
929,
9,
4388,
199,
533,
15996,
2925,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
4455,
5565,
272,
408,
339,
347,
511,
63,
2722,
8,
277,
304,
267,
408,
267,
4700,
342,
641,
15996,
267,
408,
267,
3231,
275,
298,
830,
1273,
72,
2,
267,
943,
275,
15996,
8,
3251,
9,
267,
291,
14,
629,
8,
2722,
8,
793,
395,
3886,
4455,
469,
16,
93,
23167,
908,
8,
2722,
8,
3251,
1724,
2378,
347,
511,
63,
3251,
2698,
8,
277,
304,
267,
408,
267,
3758,
3231,
365,
859,
536,
14,
267,
408,
267,
943,
275,
15996,
342,
267,
291,
14,
629,
8,
793,
14,
3251,
12,
636,
354,
3368,
2378,
347,
511,
63,
3251,
1646,
8,
277,
304,
267,
408,
267,
3758,
3231,
367,
3992,
1808,
491,
91,
4455,
93,
465,
282,
5872,
365,
314,
267,
1021,
536,
2985,
4898,
12396,
687,
14,
267,
408,
267,
1559,
275,
5297,
16273,
939,
1692,
342,
267,
1420,
8814,
275,
5310,
16,
26944,
17,
5469,
908,
8,
288,
1559,
855,
578,
3108,
288,
1559,
855,
533,
4914,
354,
3108,
267,
776,
267,
291,
14,
629,
8,
1113,
14,
793,
14,
3251,
12,
1420,
8814,
9,
267,
291,
14,
629,
8,
2445,
16273,
939,
1692,
14,
793,
14,
3251,
12,
1420,
8814,
9,
267,
291,
14,
3436,
8,
2445,
16273,
939,
1692,
14,
793,
14,
1365,
12,
5297,
16273,
939,
1692,
9,
267,
291,
14,
3436,
8,
1113,
14,
793,
14,
1365,
12,
1559,
9,
267,
291,
14,
7702,
8,
4455,
1252,
1365,
9,
2378,
347,
511,
63,
4120,
22715,
8,
277,
304,
267,
408,
267,
3979,
1202,
465,
282,
5872,
12,
314,
27336,
365,
25350,
14,
267,
408,
267,
20802,
275,
942,
398,
1021,
4932,
1692,
8,
785,
304,
288,
943,
275,
15996,
8,
23968,
29,
22300,
14,
740,
9,
398,
4932,
1692,
14,
793,
14,
815,
480,
5006,
531,
267,
291,
14,
629,
8,
552,
8,
22300,
395,
413,
9,
267,
291,
14,
629,
8,
22300,
59,
16,
2733,
793,
63,
908,
995,
298,
5006,
531,
2378,
347,
511,
63,
1365,
11464,
1858,
20552,
8,
277,
304,
267,
408,
267,
4068,
4454,
626,
1172,
282,
491,
91,
4455,
93,
1021,
2225,
12,
314,
445,
91,
793,
63,
1365,
93,
267,
790,
365,
2808,
370,
1475,
3326,
14,
267,
408,
267,
1559,
275,
5297,
16273,
939,
1692,
480,
5006,
531,
267,
943,
275,
1559,
14,
793,
267,
943,
14,
705,
480,
6257,
12,
469,
793,
63,
1365,
93,
2685,
398,
291,
14,
4080,
480,
793,
63,
1365,
401,
943,
14,
1430,
9,
267,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
1365,
2255,
1559,
9,
398,
8292,
275,
1475,
2390,
8,
793,
14,
1430,
9,
267,
291,
14,
4080,
480,
6257,
12,
665,
2445,
16273,
939,
1692,
16509,
30,
4765,
8292,
9,
2378,
347,
511,
63,
4316,
4455,
8,
277,
304,
267,
408,
267,
1379,
626,
943,
11106,
436,
3788,
787,
19515,
6657,
367,
267,
15996,
14,
267,
408,
267,
943,
275,
1379,
4455,
342,
398,
367,
2166,
315,
5297,
4670,
14,
1661,
5559,
837,
288,
1475,
275,
298,
2765,
365,
282,
469,
1896,
63,
354,
93,
1245,
2,
288,
1245,
275,
1475,
14,
908,
8,
1896,
63,
354,
29,
1896,
14,
354,
9,
953,
943,
3767,
275,
2519,
8,
793,
12,
2166,
14,
354,
9,
288,
943,
3767,
8,
908,
12,
24605,
29,
1188,
12,
2166,
63,
354,
29,
1896,
14,
354,
9,
953,
327,
7523,
626,
511,
63,
8159,
4788,
2797,
543,
1420,
2368,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
1896,
2255,
2166,
9,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
908,
2255,
1475,
9,
288,
291,
14,
629,
8,
793,
14,
69,
4485,
905,
958,
6611,
17941,
2255,
1245,
9,
953,
291,
14,
1815,
8,
11161,
8,
793,
12,
298,
1430,
1288,
298,
1944,
1566,
20802,
2685,
953,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
908,
2255,
1475,
9,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
1896,
2255,
2166,
9,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
793,
63,
3251,
2255,
636,
354,
3368,
288,
291,
14,
7702,
8,
793,
14,
1430,
905,
793,
63,
1365,
3135,
288,
291,
14,
629,
8,
793,
14,
1430,
905,
17941,
2255,
1245,
9,
953,
291,
14,
629,
8,
908,
2390,
8,
793,
14,
1430,
395,
1245,
9,
2378,
347,
511,
63,
1365,
3314,
2543,
8,
277,
304,
267,
408,
267,
445,
91,
793,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Udzu/pudzu
|
dataviz/flagsaverage.py
|
1
|
2847
|
from pudzu.charts import *
from pudzu.sandbox.bamboo import *
flags = pd.read_csv("datasets/countries.csv")[lambda df: df.code != "EUU"].split_columns(('nationality', 'tld', 'country'), "|").explode('country').set_index('country').drop_duplicates(subset='flag', keep='first')
bg = "#EEEEEE"
def image_flag(c):
return Image.from_url_with_cache(flags['flag'][c]).convert("RGB")
def average_color(img):
float_array = np.array(img) / 256
float_average = [ math.sqrt((float_array[:,:,i] ** 2).mean()) for i in range(float_array.shape[-1])]
return RGBA(int(256 * f) for f in float_average)
def average_image(imgs, size, weights=None):
if weights is None: weights = [1 for _ in imgs]
average = (sum((np.array(img.resize(size)) / 256)**2 * w for img,w in zip(imgs, weights)) / sum(weights)) ** 0.5
return Image.fromarray(np.uint8(average * 256))
def average_flag(df, size, weights=None):
if callable(weights): weights = weights(df)
flags = [Image.from_url_with_cache(i).convert("RGB") for i in df.flag]
return average_image(flags, (size[0]-2,size[1]-2), weights).pad(1, "black")
continents = list(flags.groupby("continent").count().index)
continentlabels = [ Image.from_text(continent.upper(), arial(60, bold=True), "black", bg) for continent in continents ]
imgs = []
for weights, TITLE, SUBTITLE in [(None, "AVERAGE WORLD/CONTINENT FLAGS", "averages of aspect-normalised state & dependency flags"),
(lambda df: df.population, "WEIGHTED AVERAGE FLAGS", "same, but weighted by population")]:
world = average_flag(flags, (1200,800), weights=weights)
continentflags = [ average_flag(flags[flags.continent == continent], (630,420), weights=weights) for continent in continents ]
continentimgs = [ Image.from_column([label, flag], padding=10) for flag, label in zip(continentflags, continentlabels) ]
continentarray = Image.from_array(list(generate_batches(continentimgs, 3)), bg=bg, padding=5, yalign=1)
subtitle = Image.from_text(SUBTITLE, arial(60, bold=True), "black", bg, padding=(0,0,0,20))
title = Image.from_column([Image.from_text(TITLE, arial(96, bold=True), "black", bg), subtitle], bg=bg, padding=10)
img = Image.from_column([title, world, continentarray], bg=bg, padding=20)
imgs.append(img)
FOOTER = "*each flag is assigned to just one continent; average is the quadratic mean of RGB values (as per the Computer Color is Broken Youtube video)"
footer = Image.from_text(FOOTER, arial(48), "black", bg, padding=10)
img = Image.from_column([Image.from_row(imgs, yalign=0), footer], bg=bg, padding=20)
img.place(Image.from_text("/u/Udzu", font("arial", 32), fg="black", bg=bg, padding=10).pad((2,2,0,0), "black"), align=1, padding=20, copy=False)
img.save("output/flagsaverage.png")
|
mit
|
[
504,
299,
1181,
90,
85,
14,
31522,
492,
627,
202,
199,
504,
299,
1181,
90,
85,
14,
16647,
14,
21112,
15056,
492,
627,
2999,
199,
2469,
275,
6454,
14,
739,
63,
4737,
480,
12281,
15,
23598,
14,
4737,
9981,
2734,
4051,
26,
4051,
14,
600,
1137,
298,
37,
4622,
4140,
1294,
63,
3406,
4725,
26021,
1209,
297,
283,
84,
1447,
297,
283,
6063,
659,
15733,
3471,
16971,
271,
360,
6063,
1959,
409,
63,
1080,
360,
6063,
1959,
4824,
63,
18563,
8,
9401,
534,
4173,
297,
4215,
534,
2246,
358,
202,
199,
6856,
275,
5426,
8699,
8699,
8699,
2,
2999,
199,
318,
1834,
63,
4173,
8,
67,
304,
1128,
372,
6047,
14,
504,
63,
633,
63,
1045,
63,
1637,
8,
2469,
459,
4173,
3488,
67,
6575,
3916,
480,
12067,
531,
8428,
202,
199,
318,
8095,
63,
2326,
8,
4060,
304,
1128,
2069,
63,
1144,
275,
980,
14,
1144,
8,
4060,
9,
1182,
7633,
1128,
2069,
63,
8536,
275,
359,
3473,
14,
5079,
1332,
1609,
63,
1144,
27101,
73,
61,
1011,
499,
680,
3670,
1012,
367,
284,
315,
1425,
8,
1609,
63,
1144,
14,
1392,
1988,
17,
12457,
1128,
372,
820,
39,
4134,
8,
442,
8,
3912,
627,
289,
9,
367,
289,
315,
2069,
63,
8536,
9,
2999,
199,
318,
8095,
63,
1569,
8,
1017,
458,
12,
1568,
12,
4931,
29,
403,
304,
1128,
340,
4931,
365,
488,
26,
4931,
275,
359,
17,
367,
485,
315,
3416,
458,
61,
1128,
8095,
275,
334,
1838,
1332,
1590,
14,
1144,
8,
4060,
14,
8709,
8,
890,
430,
1182,
7633,
6422,
18,
627,
336,
367,
6050,
12,
87,
315,
3482,
8,
1017,
458,
12,
4931,
430,
1182,
3089,
8,
4916,
430,
1011,
378,
14,
21,
1128,
372,
6047,
14,
504,
1144,
8,
1590,
14,
1635,
24,
8,
8536,
627,
7633,
430,
2999,
199,
318,
8095,
63,
4173,
8,
1587,
12,
1568,
12,
4931,
29,
403,
304,
1128,
340,
4550,
8,
4916,
304,
4931,
275,
4931,
8,
1587,
9,
1128,
3285,
275,
359,
3491,
14,
504,
63,
633,
63,
1045,
63,
1637,
8,
73,
680,
3916,
480,
12067,
531,
367,
284,
315,
4051,
14,
4173,
61,
1128,
372,
8095,
63,
1569,
8,
2469,
12,
334,
890,
59,
16,
11285,
18,
12,
890,
59,
17,
11285,
18,
395,
4931,
680,
6226,
8,
17,
12,
298,
8399,
531,
2999,
199,
12875,
24871,
275,
769,
8,
2469,
14,
16968,
480,
12875,
484,
3471,
835,
1252,
1080,
9,
202,
199,
12875,
484,
3512,
275,
359,
6047,
14,
504,
63,
505,
8,
12875,
484,
14,
4142,
1062,
282,
1383,
8,
2259,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
9,
221,
367,
9832,
484,
315,
9832,
24871,
1622,
2999,
199,
1017,
458,
275,
942,
2999,
199,
509,
4931,
12,
377,
16507,
12,
7605,
19091,
315,
3842,
403,
12,
298,
33,
2111,
2962,
29557,
6533,
15,
26663,
1309,
12846,
401,
298,
8536,
83,
402,
17435,
13,
3302,
9096,
1174,
1253,
5936,
3285,
1288,
202,
639,
334,
2734,
4051,
26,
4051,
14,
16003,
12,
298,
25100,
1149,
437,
2111,
2962,
12846,
401,
298,
7191,
12,
1325,
14609,
701,
16423,
531,
2189,
1128,
6701,
275,
8095,
63,
4173,
8,
2469,
12,
334,
23781,
12,
6718,
395,
4931,
29,
4916,
9,
1128,
9832,
484,
2469,
275,
359,
8095,
63,
4173,
8,
2469,
59,
2469,
14,
12875,
484,
508,
9832,
484,
467,
334,
22,
1216,
12,
25102,
395,
4931,
29,
4916,
9,
367,
9832,
484,
315,
9832,
24871,
1622,
1128,
9832,
287,
2906,
458,
275,
359,
6047,
14,
504,
63,
2301,
779,
1302,
12,
3305,
467,
6273,
29,
709,
9,
367,
3305,
12,
1768,
315,
3482,
8,
12875,
484,
2469,
12,
9832,
484,
3512,
9,
1622,
1128,
9832,
484,
1144,
275,
6047,
14,
504,
63,
1144,
8,
513,
8,
4208,
63,
14896,
8,
12875,
287,
2906,
458,
12,
650,
1826,
12994,
29,
6856,
12,
6273,
29,
21,
12,
612,
5743,
29,
17,
9,
1128,
18197,
275,
6047,
14,
504,
63,
505,
8,
6348,
19091,
12,
282,
1383,
8,
2259,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
12,
6273,
2687,
16,
12,
16,
12,
16,
12,
1165,
430,
1128,
2538,
275,
6047,
14,
504,
63,
2301,
779,
3491,
14,
504,
63,
505,
8,
19091,
12,
282,
1383,
8,
2534,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
395,
18197,
467,
12994,
29,
6856,
12,
6273,
29,
709,
9,
1128,
6050,
275,
6047,
14,
504,
63,
2301,
779,
1213,
12,
6701,
12,
9832,
484,
1144,
467,
12994,
29,
6856,
12,
6273,
29,
1165,
9,
1128,
3416,
458,
14,
740,
8,
4060,
9,
2999,
199,
13046,
1157,
275,
8969,
10885,
3305,
365,
7943,
370,
2951,
1373,
9832,
484,
27,
8095,
365,
314,
16744,
19826,
4615,
402,
19013,
1338,
334,
305,
1126,
314,
3599,
2699,
11581,
365,
23804,
1488,
7715,
3991,
2924,
202,
199,
12781,
275,
6047,
14,
504,
63,
505,
8,
13046,
1157,
12,
282,
1383,
8,
2006,
395,
298,
8399,
401,
12994,
12,
6273,
29,
709,
9,
202,
199,
4060,
275,
6047,
14,
504,
63,
2301,
779,
3491,
14,
504,
63,
1143,
8,
1017,
458,
12,
612,
5743,
29,
16,
395,
14178,
467,
12994,
29,
6856,
12,
6273,
29,
1165,
9,
202,
199,
4060,
14,
2778,
8,
3491,
14,
504,
63,
505,
4769,
85,
15,
53,
17019,
85,
401,
5023,
480,
759,
279,
401,
4337,
395,
16587,
628,
8399,
401,
12994,
29,
6856,
12,
6273,
29,
709,
680,
6226,
1332,
18,
12,
18,
12,
16,
12,
16,
395,
298,
8399,
1288,
6998,
29,
17,
12,
6273,
29,
1165,
12,
1331,
29,
797,
9,
202,
199,
4060,
14,
2117,
480,
1199,
15,
2469,
8536,
14,
4524,
531,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
299,
1181,
90,
85,
14,
31522,
492,
627,
202,
199,
504,
299,
1181,
90,
85,
14,
16647,
14,
21112,
15056,
492,
627,
2999,
199,
2469,
275,
6454,
14,
739,
63,
4737,
480,
12281,
15,
23598,
14,
4737,
9981,
2734,
4051,
26,
4051,
14,
600,
1137,
298,
37,
4622,
4140,
1294,
63,
3406,
4725,
26021,
1209,
297,
283,
84,
1447,
297,
283,
6063,
659,
15733,
3471,
16971,
271,
360,
6063,
1959,
409,
63,
1080,
360,
6063,
1959,
4824,
63,
18563,
8,
9401,
534,
4173,
297,
4215,
534,
2246,
358,
202,
199,
6856,
275,
5426,
8699,
8699,
8699,
2,
2999,
199,
318,
1834,
63,
4173,
8,
67,
304,
1128,
372,
6047,
14,
504,
63,
633,
63,
1045,
63,
1637,
8,
2469,
459,
4173,
3488,
67,
6575,
3916,
480,
12067,
531,
8428,
202,
199,
318,
8095,
63,
2326,
8,
4060,
304,
1128,
2069,
63,
1144,
275,
980,
14,
1144,
8,
4060,
9,
1182,
7633,
1128,
2069,
63,
8536,
275,
359,
3473,
14,
5079,
1332,
1609,
63,
1144,
27101,
73,
61,
1011,
499,
680,
3670,
1012,
367,
284,
315,
1425,
8,
1609,
63,
1144,
14,
1392,
1988,
17,
12457,
1128,
372,
820,
39,
4134,
8,
442,
8,
3912,
627,
289,
9,
367,
289,
315,
2069,
63,
8536,
9,
2999,
199,
318,
8095,
63,
1569,
8,
1017,
458,
12,
1568,
12,
4931,
29,
403,
304,
1128,
340,
4931,
365,
488,
26,
4931,
275,
359,
17,
367,
485,
315,
3416,
458,
61,
1128,
8095,
275,
334,
1838,
1332,
1590,
14,
1144,
8,
4060,
14,
8709,
8,
890,
430,
1182,
7633,
6422,
18,
627,
336,
367,
6050,
12,
87,
315,
3482,
8,
1017,
458,
12,
4931,
430,
1182,
3089,
8,
4916,
430,
1011,
378,
14,
21,
1128,
372,
6047,
14,
504,
1144,
8,
1590,
14,
1635,
24,
8,
8536,
627,
7633,
430,
2999,
199,
318,
8095,
63,
4173,
8,
1587,
12,
1568,
12,
4931,
29,
403,
304,
1128,
340,
4550,
8,
4916,
304,
4931,
275,
4931,
8,
1587,
9,
1128,
3285,
275,
359,
3491,
14,
504,
63,
633,
63,
1045,
63,
1637,
8,
73,
680,
3916,
480,
12067,
531,
367,
284,
315,
4051,
14,
4173,
61,
1128,
372,
8095,
63,
1569,
8,
2469,
12,
334,
890,
59,
16,
11285,
18,
12,
890,
59,
17,
11285,
18,
395,
4931,
680,
6226,
8,
17,
12,
298,
8399,
531,
2999,
199,
12875,
24871,
275,
769,
8,
2469,
14,
16968,
480,
12875,
484,
3471,
835,
1252,
1080,
9,
202,
199,
12875,
484,
3512,
275,
359,
6047,
14,
504,
63,
505,
8,
12875,
484,
14,
4142,
1062,
282,
1383,
8,
2259,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
9,
221,
367,
9832,
484,
315,
9832,
24871,
1622,
2999,
199,
1017,
458,
275,
942,
2999,
199,
509,
4931,
12,
377,
16507,
12,
7605,
19091,
315,
3842,
403,
12,
298,
33,
2111,
2962,
29557,
6533,
15,
26663,
1309,
12846,
401,
298,
8536,
83,
402,
17435,
13,
3302,
9096,
1174,
1253,
5936,
3285,
1288,
202,
639,
334,
2734,
4051,
26,
4051,
14,
16003,
12,
298,
25100,
1149,
437,
2111,
2962,
12846,
401,
298,
7191,
12,
1325,
14609,
701,
16423,
531,
2189,
1128,
6701,
275,
8095,
63,
4173,
8,
2469,
12,
334,
23781,
12,
6718,
395,
4931,
29,
4916,
9,
1128,
9832,
484,
2469,
275,
359,
8095,
63,
4173,
8,
2469,
59,
2469,
14,
12875,
484,
508,
9832,
484,
467,
334,
22,
1216,
12,
25102,
395,
4931,
29,
4916,
9,
367,
9832,
484,
315,
9832,
24871,
1622,
1128,
9832,
287,
2906,
458,
275,
359,
6047,
14,
504,
63,
2301,
779,
1302,
12,
3305,
467,
6273,
29,
709,
9,
367,
3305,
12,
1768,
315,
3482,
8,
12875,
484,
2469,
12,
9832,
484,
3512,
9,
1622,
1128,
9832,
484,
1144,
275,
6047,
14,
504,
63,
1144,
8,
513,
8,
4208,
63,
14896,
8,
12875,
287,
2906,
458,
12,
650,
1826,
12994,
29,
6856,
12,
6273,
29,
21,
12,
612,
5743,
29,
17,
9,
1128,
18197,
275,
6047,
14,
504,
63,
505,
8,
6348,
19091,
12,
282,
1383,
8,
2259,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
12,
6273,
2687,
16,
12,
16,
12,
16,
12,
1165,
430,
1128,
2538,
275,
6047,
14,
504,
63,
2301,
779,
3491,
14,
504,
63,
505,
8,
19091,
12,
282,
1383,
8,
2534,
12,
17268,
29,
549,
395,
298,
8399,
401,
12994,
395,
18197,
467,
12994,
29,
6856,
12,
6273,
29,
709,
9,
1128,
6050,
275,
6047,
14,
504,
63,
2301,
779,
1213,
12,
6701,
12,
9832,
484,
1144,
467,
12994,
29,
6856,
12,
6273,
29,
1165,
9,
1128,
3416,
458,
14,
740,
8,
4060,
9,
2999,
199,
13046,
1157,
275,
8969,
10885,
3305,
365,
7943,
370,
2951,
1373,
9832,
484,
27,
8095,
365,
314,
16744,
19826,
4615,
402,
19013,
1338,
334,
305,
1126,
314,
3599,
2699,
11581,
365,
23804,
1488,
7715,
3991,
2924,
202,
199,
12781,
275,
6047,
14,
504,
63,
505,
8,
13046,
1157,
12,
282,
1383,
8,
2006,
395,
298,
8399,
401,
12994,
12,
6273,
29,
709,
9,
202,
199,
4060,
275,
6047,
14,
504,
63,
2301,
779,
3491,
14,
504,
63,
1143,
8,
1017,
458,
12,
612,
5743,
29,
16,
395,
14178,
467,
12994,
29,
6856,
12,
6273,
29,
1165,
9,
202,
199,
4060,
14,
2778,
8,
3491,
14,
504,
63,
505,
4769,
85,
15,
53,
17019,
85,
401,
5023,
480,
759,
279,
401,
4337,
395,
16587,
628,
8399,
401,
12994,
29,
6856,
12,
6273,
29,
709,
680,
6226,
1332,
18,
12,
18,
12,
16,
12,
16,
395,
298,
8399,
1288,
6998,
29,
17,
12,
6273,
29,
1165,
12,
1331,
29,
797,
9,
202,
199,
4060,
14,
2117,
480,
1199,
15,
2469,
8536,
14,
4524,
531,
10060,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
JianfengXu/crosswalk-test-suite
|
wrt/wrt-googleplay-android-tests/inst.apk.py
|
1996
|
3186
|
#!/usr/bin/env python
import os
import shutil
import glob
import time
import sys
import subprocess
from optparse import OptionParser, make_option
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PARAMETERS = None
ADB_CMD = "adb"
def doCMD(cmd):
# Do not need handle timeout in this short script, let tool do it
print "-->> \"%s\"" % cmd
output = []
cmd_return_code = 1
cmd_proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
while True:
output_line = cmd_proc.stdout.readline().strip("\r\n")
cmd_return_code = cmd_proc.poll()
if output_line == '' and cmd_return_code is not None:
break
sys.stdout.write("%s\n" % output_line)
sys.stdout.flush()
output.append(output_line)
return (cmd_return_code, output)
def uninstPKGs():
action_status = True
for root, dirs, files in os.walk(SCRIPT_DIR):
for file in files:
if file.endswith(".apk"):
cmd = "%s -s %s uninstall org.xwalk.%s" % (
ADB_CMD, PARAMETERS.device, os.path.basename(os.path.splitext(file)[0]))
(return_code, output) = doCMD(cmd)
for line in output:
if "Failure" in line:
action_status = False
break
return action_status
def instPKGs():
action_status = True
for root, dirs, files in os.walk(SCRIPT_DIR):
for file in files:
if file.endswith(".apk"):
cmd = "%s -s %s install %s" % (ADB_CMD,
PARAMETERS.device, os.path.join(root, file))
(return_code, output) = doCMD(cmd)
for line in output:
if "Failure" in line:
action_status = False
break
return action_status
def main():
try:
usage = "usage: inst.py -i"
opts_parser = OptionParser(usage=usage)
opts_parser.add_option(
"-s", dest="device", action="store", help="Specify device")
opts_parser.add_option(
"-i", dest="binstpkg", action="store_true", help="Install package")
opts_parser.add_option(
"-u", dest="buninstpkg", action="store_true", help="Uninstall package")
global PARAMETERS
(PARAMETERS, args) = opts_parser.parse_args()
except Exception as e:
print "Got wrong option: %s, exit ..." % e
sys.exit(1)
if not PARAMETERS.device:
(return_code, output) = doCMD("adb devices")
for line in output:
if str.find(line, "\tdevice") != -1:
PARAMETERS.device = line.split("\t")[0]
break
if not PARAMETERS.device:
print "No device found"
sys.exit(1)
if PARAMETERS.binstpkg and PARAMETERS.buninstpkg:
print "-i and -u are conflict"
sys.exit(1)
if PARAMETERS.buninstpkg:
if not uninstPKGs():
sys.exit(1)
else:
if not instPKGs():
sys.exit(1)
if __name__ == "__main__":
main()
sys.exit(0)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5739,
199,
646,
900,
199,
646,
984,
199,
646,
3873,
199,
504,
8691,
492,
13491,
12,
1852,
63,
1422,
421,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
24014,
275,
488,
199,
1554,
34,
63,
9744,
275,
298,
13741,
2,
421,
199,
318,
886,
9744,
8,
1760,
304,
272,
327,
4226,
440,
1929,
2429,
2653,
315,
642,
3974,
2884,
12,
4691,
4744,
886,
652,
272,
870,
4320,
1140,
18321,
83,
18781,
450,
2088,
272,
1072,
275,
942,
272,
2088,
63,
1107,
63,
600,
275,
413,
272,
2088,
63,
4687,
275,
3873,
14,
7942,
8,
267,
2088,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
12,
5218,
29,
549,
9,
339,
1830,
715,
26,
267,
1072,
63,
604,
275,
2088,
63,
4687,
14,
2703,
14,
6407,
1252,
1913,
4582,
82,
60,
78,
531,
267,
2088,
63,
1107,
63,
600,
275,
2088,
63,
4687,
14,
6843,
342,
267,
340,
1072,
63,
604,
508,
2125,
436,
2088,
63,
1107,
63,
600,
365,
440,
488,
26,
288,
2059,
267,
984,
14,
2703,
14,
952,
3647,
83,
60,
78,
2,
450,
1072,
63,
604,
9,
267,
984,
14,
2703,
14,
4939,
342,
267,
1072,
14,
740,
8,
1199,
63,
604,
9,
339,
372,
334,
1760,
63,
1107,
63,
600,
12,
1072,
9,
421,
199,
318,
625,
3615,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
23582,
2349,
355,
2088,
275,
2071,
83,
446,
83,
450,
83,
22199,
5981,
14,
88,
7757,
4111,
83,
2,
450,
334,
490,
437,
2846,
63,
9744,
12,
23710,
14,
1782,
12,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
7973,
8,
493,
2788,
16,
2459,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
272,
372,
1595,
63,
1205,
421,
199,
318,
2727,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
23582,
2349,
355,
2088,
275,
2071,
83,
446,
83,
450,
83,
3907,
450,
83,
2,
450,
334,
1554,
34,
63,
9744,
12,
6901,
23710,
14,
1782,
12,
747,
14,
515,
14,
904,
8,
1231,
12,
570,
430,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
272,
372,
1595,
63,
1205,
421,
199,
318,
2446,
837,
272,
862,
26,
267,
4503,
275,
298,
3807,
26,
2727,
14,
647,
446,
73,
2,
267,
3999,
63,
2087,
275,
13491,
8,
3807,
29,
3807,
9,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
83,
401,
2053,
628,
1782,
401,
1595,
628,
1617,
401,
1720,
628,
17768,
2243,
531,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
73,
401,
2053,
628,
1393,
270,
4600,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
8154,
2559,
531,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
85,
401,
2053,
628,
66,
324,
3615,
4600,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
1358,
3174,
2559,
531,
267,
2288,
23710,
267,
334,
24014,
12,
1249,
9,
275,
3999,
63,
2087,
14,
1122,
63,
589,
342,
272,
871,
2186,
465,
325,
26,
267,
870,
298,
13662,
6835,
945,
26,
450,
83,
12,
4458,
21742,
450,
325,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
440,
23710,
14,
1782,
26,
267,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
480,
13741,
7256,
531,
267,
367,
1004,
315,
1072,
26,
288,
340,
620,
14,
1623,
8,
604,
12,
1867,
84,
1782,
531,
1137,
446,
17,
26,
355,
23710,
14,
1782,
275,
1004,
14,
1294,
4582,
84,
9981,
16,
61,
355,
2059,
339,
340,
440,
23710,
14,
1782,
26,
267,
870,
298,
1944,
2243,
1911,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
23710,
14,
1393,
270,
4600,
436,
23710,
14,
66,
324,
3615,
4600,
26,
267,
870,
3905,
73,
436,
446,
85,
787,
12395,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
23710,
14,
66,
324,
3615,
4600,
26,
267,
340,
440,
625,
3615,
18150,
83,
837,
288,
984,
14,
2224,
8,
17,
9,
272,
587,
26,
267,
340,
440,
2727,
18150,
83,
837,
288,
984,
14,
2224,
8,
17,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
272,
984,
14,
2224,
8,
16,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5739,
199,
646,
900,
199,
646,
984,
199,
646,
3873,
199,
504,
8691,
492,
13491,
12,
1852,
63,
1422,
421,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
24014,
275,
488,
199,
1554,
34,
63,
9744,
275,
298,
13741,
2,
421,
199,
318,
886,
9744,
8,
1760,
304,
272,
327,
4226,
440,
1929,
2429,
2653,
315,
642,
3974,
2884,
12,
4691,
4744,
886,
652,
272,
870,
4320,
1140,
18321,
83,
18781,
450,
2088,
272,
1072,
275,
942,
272,
2088,
63,
1107,
63,
600,
275,
413,
272,
2088,
63,
4687,
275,
3873,
14,
7942,
8,
267,
2088,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
12,
5218,
29,
549,
9,
339,
1830,
715,
26,
267,
1072,
63,
604,
275,
2088,
63,
4687,
14,
2703,
14,
6407,
1252,
1913,
4582,
82,
60,
78,
531,
267,
2088,
63,
1107,
63,
600,
275,
2088,
63,
4687,
14,
6843,
342,
267,
340,
1072,
63,
604,
508,
2125,
436,
2088,
63,
1107,
63,
600,
365,
440,
488,
26,
288,
2059,
267,
984,
14,
2703,
14,
952,
3647,
83,
60,
78,
2,
450,
1072,
63,
604,
9,
267,
984,
14,
2703,
14,
4939,
342,
267,
1072,
14,
740,
8,
1199,
63,
604,
9,
339,
372,
334,
1760,
63,
1107,
63,
600,
12,
1072,
9,
421,
199,
318,
625,
3615,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
23582,
2349,
355,
2088,
275,
2071,
83,
446,
83,
450,
83,
22199,
5981,
14,
88,
7757,
4111,
83,
2,
450,
334,
490,
437,
2846,
63,
9744,
12,
23710,
14,
1782,
12,
747,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
7973,
8,
493,
2788,
16,
2459,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
272,
372,
1595,
63,
1205,
421,
199,
318,
2727,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
23582,
2349,
355,
2088,
275,
2071,
83,
446,
83,
450,
83,
3907,
450,
83,
2,
450,
334,
1554,
34,
63,
9744,
12,
6901,
23710,
14,
1782,
12,
747,
14,
515,
14,
904,
8,
1231,
12,
570,
430,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
272,
372,
1595,
63,
1205,
421,
199,
318,
2446,
837,
272,
862,
26,
267,
4503,
275,
298,
3807,
26,
2727,
14,
647,
446,
73,
2,
267,
3999,
63,
2087,
275,
13491,
8,
3807,
29,
3807,
9,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
83,
401,
2053,
628,
1782,
401,
1595,
628,
1617,
401,
1720,
628,
17768,
2243,
531,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
73,
401,
2053,
628,
1393,
270,
4600,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
8154,
2559,
531,
267,
3999,
63,
2087,
14,
525,
63,
1422,
8,
288,
3905,
85,
401,
2053,
628,
66,
324,
3615,
4600,
401,
1595,
628,
1617,
63,
2052,
401,
1720,
628,
1358,
3174,
2559,
531,
267,
2288,
23710,
267,
334,
24014,
12,
1249,
9,
275,
3999,
63,
2087,
14,
1122,
63,
589,
342,
272,
871,
2186,
465,
325,
26,
267,
870,
298,
13662,
6835,
945,
26,
450,
83,
12,
4458,
21742,
450,
325,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
440,
23710,
14,
1782,
26,
267,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
480,
13741,
7256,
531,
267,
367,
1004,
315,
1072,
26,
288,
340,
620,
14,
1623,
8,
604,
12,
1867,
84,
1782,
531,
1137,
446,
17,
26,
355,
23710,
14,
1782,
275,
1004,
14,
1294,
4582,
84,
9981,
16,
61,
355,
2059,
339,
340,
440,
23710,
14,
1782,
26,
267,
870,
298,
1944,
2243,
1911,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
23710,
14,
1393,
270,
4600,
436,
23710,
14,
66,
324,
3615,
4600,
26,
267,
870,
3905,
73,
436,
446,
85,
787,
12395,
2,
267,
984,
14,
2224,
8,
17,
9,
339,
340,
23710,
14,
66,
324,
3615,
4600,
26,
267,
340,
440,
625,
3615,
18150,
83,
837,
288,
984,
14,
2224,
8,
17,
9,
272,
587,
26,
267,
340,
440,
2727,
18150,
83,
837,
288,
984,
14,
2224,
8,
17,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
272,
984,
14,
2224,
8,
16,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rblalock/titanium_mobile
|
node_modules/ioslib/node_modules/node-ios-device/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py
|
1812
|
9537
|
# Copyright (c) 2013 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.
"""Utility functions shared amongst the Windows generators."""
import copy
import os
# A dictionary mapping supported target types to extensions.
TARGET_TYPE_EXT = {
'executable': 'exe',
'loadable_module': 'dll',
'shared_library': 'dll',
'static_library': 'lib',
}
def _GetLargePdbShimCcPath():
"""Returns the path of the large_pdb_shim.cc file."""
this_dir = os.path.abspath(os.path.dirname(__file__))
src_dir = os.path.abspath(os.path.join(this_dir, '..', '..'))
win_data_dir = os.path.join(src_dir, 'data', 'win')
large_pdb_shim_cc = os.path.join(win_data_dir, 'large-pdb-shim.cc')
return large_pdb_shim_cc
def _DeepCopySomeKeys(in_dict, keys):
"""Performs a partial deep-copy on |in_dict|, only copying the keys in |keys|.
Arguments:
in_dict: The dictionary to copy.
keys: The keys to be copied. If a key is in this list and doesn't exist in
|in_dict| this is not an error.
Returns:
The partially deep-copied dictionary.
"""
d = {}
for key in keys:
if key not in in_dict:
continue
d[key] = copy.deepcopy(in_dict[key])
return d
def _SuffixName(name, suffix):
"""Add a suffix to the end of a target.
Arguments:
name: name of the target (foo#target)
suffix: the suffix to be added
Returns:
Target name with suffix added (foo_suffix#target)
"""
parts = name.rsplit('#', 1)
parts[0] = '%s_%s' % (parts[0], suffix)
return '#'.join(parts)
def _ShardName(name, number):
"""Add a shard number to the end of a target.
Arguments:
name: name of the target (foo#target)
number: shard number
Returns:
Target name with shard added (foo_1#target)
"""
return _SuffixName(name, str(number))
def ShardTargets(target_list, target_dicts):
"""Shard some targets apart to work around the linkers limits.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
Returns:
Tuple of the new sharded versions of the inputs.
"""
# Gather the targets to shard, and how many pieces.
targets_to_shard = {}
for t in target_dicts:
shards = int(target_dicts[t].get('msvs_shard', 0))
if shards:
targets_to_shard[t] = shards
# Shard target_list.
new_target_list = []
for t in target_list:
if t in targets_to_shard:
for i in range(targets_to_shard[t]):
new_target_list.append(_ShardName(t, i))
else:
new_target_list.append(t)
# Shard target_dict.
new_target_dicts = {}
for t in target_dicts:
if t in targets_to_shard:
for i in range(targets_to_shard[t]):
name = _ShardName(t, i)
new_target_dicts[name] = copy.copy(target_dicts[t])
new_target_dicts[name]['target_name'] = _ShardName(
new_target_dicts[name]['target_name'], i)
sources = new_target_dicts[name].get('sources', [])
new_sources = []
for pos in range(i, len(sources), targets_to_shard[t]):
new_sources.append(sources[pos])
new_target_dicts[name]['sources'] = new_sources
else:
new_target_dicts[t] = target_dicts[t]
# Shard dependencies.
for t in new_target_dicts:
for deptype in ('dependencies', 'dependencies_original'):
dependencies = copy.copy(new_target_dicts[t].get(deptype, []))
new_dependencies = []
for d in dependencies:
if d in targets_to_shard:
for i in range(targets_to_shard[d]):
new_dependencies.append(_ShardName(d, i))
else:
new_dependencies.append(d)
new_target_dicts[t][deptype] = new_dependencies
return (new_target_list, new_target_dicts)
def _GetPdbPath(target_dict, config_name, vars):
"""Returns the path to the PDB file that will be generated by a given
configuration.
The lookup proceeds as follows:
- Look for an explicit path in the VCLinkerTool configuration block.
- Look for an 'msvs_large_pdb_path' variable.
- Use '<(PRODUCT_DIR)/<(product_name).(exe|dll).pdb' if 'product_name' is
specified.
- Use '<(PRODUCT_DIR)/<(target_name).(exe|dll).pdb'.
Arguments:
target_dict: The target dictionary to be searched.
config_name: The name of the configuration of interest.
vars: A dictionary of common GYP variables with generator-specific values.
Returns:
The path of the corresponding PDB file.
"""
config = target_dict['configurations'][config_name]
msvs = config.setdefault('msvs_settings', {})
linker = msvs.get('VCLinkerTool', {})
pdb_path = linker.get('ProgramDatabaseFile')
if pdb_path:
return pdb_path
variables = target_dict.get('variables', {})
pdb_path = variables.get('msvs_large_pdb_path', None)
if pdb_path:
return pdb_path
pdb_base = target_dict.get('product_name', target_dict['target_name'])
pdb_base = '%s.%s.pdb' % (pdb_base, TARGET_TYPE_EXT[target_dict['type']])
pdb_path = vars['PRODUCT_DIR'] + '/' + pdb_base
return pdb_path
def InsertLargePdbShims(target_list, target_dicts, vars):
"""Insert a shim target that forces the linker to use 4KB pagesize PDBs.
This is a workaround for targets with PDBs greater than 1GB in size, the
limit for the 1KB pagesize PDBs created by the linker by default.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
vars: A dictionary of common GYP variables with generator-specific values.
Returns:
Tuple of the shimmed version of the inputs.
"""
# Determine which targets need shimming.
targets_to_shim = []
for t in target_dicts:
target_dict = target_dicts[t]
# We only want to shim targets that have msvs_large_pdb enabled.
if not int(target_dict.get('msvs_large_pdb', 0)):
continue
# This is intended for executable, shared_library and loadable_module
# targets where every configuration is set up to produce a PDB output.
# If any of these conditions is not true then the shim logic will fail
# below.
targets_to_shim.append(t)
large_pdb_shim_cc = _GetLargePdbShimCcPath()
for t in targets_to_shim:
target_dict = target_dicts[t]
target_name = target_dict.get('target_name')
base_dict = _DeepCopySomeKeys(target_dict,
['configurations', 'default_configuration', 'toolset'])
# This is the dict for copying the source file (part of the GYP tree)
# to the intermediate directory of the project. This is necessary because
# we can't always build a relative path to the shim source file (on Windows
# GYP and the project may be on different drives), and Ninja hates absolute
# paths (it ends up generating the .obj and .obj.d alongside the source
# file, polluting GYPs tree).
copy_suffix = 'large_pdb_copy'
copy_target_name = target_name + '_' + copy_suffix
full_copy_target_name = _SuffixName(t, copy_suffix)
shim_cc_basename = os.path.basename(large_pdb_shim_cc)
shim_cc_dir = vars['SHARED_INTERMEDIATE_DIR'] + '/' + copy_target_name
shim_cc_path = shim_cc_dir + '/' + shim_cc_basename
copy_dict = copy.deepcopy(base_dict)
copy_dict['target_name'] = copy_target_name
copy_dict['type'] = 'none'
copy_dict['sources'] = [ large_pdb_shim_cc ]
copy_dict['copies'] = [{
'destination': shim_cc_dir,
'files': [ large_pdb_shim_cc ]
}]
# This is the dict for the PDB generating shim target. It depends on the
# copy target.
shim_suffix = 'large_pdb_shim'
shim_target_name = target_name + '_' + shim_suffix
full_shim_target_name = _SuffixName(t, shim_suffix)
shim_dict = copy.deepcopy(base_dict)
shim_dict['target_name'] = shim_target_name
shim_dict['type'] = 'static_library'
shim_dict['sources'] = [ shim_cc_path ]
shim_dict['dependencies'] = [ full_copy_target_name ]
# Set up the shim to output its PDB to the same location as the final linker
# target.
for config_name, config in shim_dict.get('configurations').iteritems():
pdb_path = _GetPdbPath(target_dict, config_name, vars)
# A few keys that we don't want to propagate.
for key in ['msvs_precompiled_header', 'msvs_precompiled_source', 'test']:
config.pop(key, None)
msvs = config.setdefault('msvs_settings', {})
# Update the compiler directives in the shim target.
compiler = msvs.setdefault('VCCLCompilerTool', {})
compiler['DebugInformationFormat'] = '3'
compiler['ProgramDataBaseFileName'] = pdb_path
# Set the explicit PDB path in the appropriate configuration of the
# original target.
config = target_dict['configurations'][config_name]
msvs = config.setdefault('msvs_settings', {})
linker = msvs.setdefault('VCLinkerTool', {})
linker['GenerateDebugInformation'] = 'true'
linker['ProgramDatabaseFile'] = pdb_path
# Add the new targets. They must go to the beginning of the list so that
# the dependency generation works as expected in ninja.
target_list.insert(0, full_copy_target_name)
target_list.insert(0, full_shim_target_name)
target_dicts[full_copy_target_name] = copy_dict
target_dicts[full_shim_target_name] = shim_dict
# Update the original target to depend on the shim target.
target_dict.setdefault('dependencies', []).append(full_shim_target_name)
return (target_list, target_dicts)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6171,
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,
17505,
3423,
5709,
16885,
270,
314,
5417,
16952,
1041,
199,
199,
646,
1331,
199,
646,
747,
421,
199,
3,
437,
2600,
4412,
3748,
1347,
2943,
370,
5478,
14,
199,
9268,
63,
2711,
63,
2472,
275,
469,
523,
283,
5904,
356,
283,
5803,
297,
523,
283,
20722,
63,
578,
356,
283,
9259,
297,
523,
283,
5555,
63,
4342,
356,
283,
9259,
297,
523,
283,
1986,
63,
4342,
356,
283,
773,
297,
199,
93,
421,
199,
318,
485,
1002,
17149,
21427,
2662,
1017,
21426,
2042,
837,
523,
408,
3407,
314,
931,
402,
314,
7031,
63,
10511,
63,
28238,
14,
2055,
570,
1041,
523,
642,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
523,
2928,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
19155,
11541,
1333,
523,
4747,
63,
576,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
283,
576,
297,
283,
2676,
358,
523,
7031,
63,
10511,
63,
28238,
63,
2055,
275,
747,
14,
515,
14,
904,
8,
2676,
63,
576,
63,
694,
12,
283,
9629,
13,
10511,
13,
28238,
14,
2055,
358,
523,
372,
7031,
63,
10511,
63,
28238,
63,
2055,
421,
199,
318,
485,
27753,
5116,
7700,
6340,
8,
262,
63,
807,
12,
2883,
304,
523,
408,
2623,
3351,
282,
7417,
13217,
13,
1574,
641,
1204,
262,
63,
807,
18712,
1454,
16743,
314,
2883,
315,
1204,
1612,
18257,
819,
7628,
26,
272,
315,
63,
807,
26,
710,
2600,
370,
1331,
14,
272,
2883,
26,
710,
2883,
370,
506,
8876,
14,
982,
282,
790,
365,
315,
642,
769,
436,
3181,
1133,
2187,
315,
267,
1204,
262,
63,
807,
92,
642,
365,
440,
376,
1125,
14,
523,
1803,
26,
272,
710,
25172,
13217,
13,
23581,
2600,
14,
523,
408,
523,
366,
275,
1052,
523,
367,
790,
315,
2883,
26,
272,
340,
790,
440,
315,
315,
63,
807,
26,
489,
1980,
272,
366,
59,
498,
61,
275,
1331,
14,
8293,
8,
262,
63,
807,
59,
498,
566,
523,
372,
366,
421,
199,
318,
485,
20126,
985,
8,
354,
12,
4739,
304,
523,
408,
1123,
282,
4739,
370,
314,
1284,
402,
282,
1347,
14,
819,
7628,
26,
272,
536,
26,
536,
402,
314,
1347,
334,
1421,
3,
1375,
9,
272,
4739,
26,
314,
4739,
370,
506,
3483,
523,
1803,
26,
272,
10256,
536,
543,
4739,
3483,
334,
1421,
63,
4511,
3,
1375,
9,
523,
408,
523,
4184,
275,
536,
14,
13490,
7863,
297,
413,
9,
523,
4184,
59,
16,
61,
275,
1543,
83,
4970,
83,
7,
450,
334,
4181,
59,
16,
467,
4739,
9,
523,
372,
3943,
1370,
904,
8,
4181,
9,
421,
199,
318,
485,
20019,
985,
8,
354,
12,
1329,
304,
523,
408,
1123,
282,
11814,
1329,
370,
314,
1284,
402,
282,
1347,
14,
819,
7628,
26,
272,
536,
26,
536,
402,
314,
1347,
334,
1421,
3,
1375,
9,
272,
1329,
26,
11814,
1329,
523,
1803,
26,
272,
10256,
536,
543,
11814,
3483,
334,
1421,
63,
17,
3,
1375,
9,
523,
408,
523,
372,
485,
20126,
985,
8,
354,
12,
620,
8,
1955,
430,
421,
199,
318,
5244,
1005,
14126,
8,
1375,
63,
513,
12,
1347,
63,
7892,
304,
523,
408,
20019,
2005,
4545,
29430,
370,
1736,
6818,
314,
2142,
1192,
10976,
14,
819,
7628,
26,
272,
1347,
63,
513,
26,
3820,
402,
1347,
6342,
26,
283,
1095,
15,
1095,
14,
6179,
26,
1095,
1370,
272,
1347,
63,
7892,
26,
7448,
402,
1347,
4382,
19272,
641,
1347,
4092,
14,
523,
1803,
26,
272,
11634,
402,
314,
892,
1033,
12910,
5459,
402,
314,
4153,
14,
523,
408,
523,
327,
19634,
314,
4545,
370,
11814,
12,
436,
4212,
5002,
10338,
14,
523,
4545,
63,
475,
63,
10810,
275,
1052,
523,
367,
307,
315,
1347,
63,
7892,
26,
272,
24130,
275,
1109,
8,
1375,
63,
7892,
59,
84,
1055,
362,
360,
8338,
63,
10810,
297,
378,
430,
272,
340,
24130,
26,
489,
4545,
63,
475,
63,
10810,
59,
84,
61,
275,
24130,
523,
327,
5244,
1005,
1347,
63,
513,
14,
523,
892,
63,
1375,
63,
513,
275,
942,
523,
367,
307,
315,
1347,
63,
513,
26,
272,
340,
307,
315,
4545,
63,
475,
63,
10810,
26,
489,
367,
284,
315,
1425,
8,
4684,
63,
475,
63,
10810,
59,
84,
4682,
267,
892,
63,
1375,
63,
513,
14,
740,
1547,
20019,
985,
8,
84,
12,
284,
430,
272,
587,
26,
489,
892,
63,
1375,
63,
513,
14,
740,
8,
84,
9,
523,
327,
5244,
1005,
1347,
63,
807,
14,
523,
892,
63,
1375,
63,
7892,
275,
1052,
523,
367,
307,
315,
1347,
63,
7892,
26,
272,
340,
307,
315,
4545,
63,
475,
63,
10810,
26,
489,
367,
284,
315,
1425,
8,
4684,
63,
475,
63,
10810,
59,
84,
4682,
267,
536,
275,
485,
20019,
985,
8,
84,
12,
284,
9,
267,
892,
63,
1375,
63,
7892,
59,
354,
61,
275,
1331,
14,
1574,
8,
1375,
63,
7892,
59,
84,
566,
267,
892,
63,
1375,
63,
7892,
59,
354,
2733,
1375,
63,
354,
418,
275,
485,
20019,
985,
8,
1467,
892,
63,
1375,
63,
7892,
59,
354,
2733,
1375,
63,
354,
995,
284,
9,
267,
5274,
275,
892,
63,
1375,
63,
7892,
59,
354,
1055,
362,
360,
4553,
297,
3073,
267,
892,
63,
4553,
275,
942,
267,
367,
2086,
315,
1425,
8,
73,
12,
822,
8,
4553,
395,
4545,
63,
475,
63,
10810,
59,
84,
4682,
881,
892,
63,
4553,
14,
740,
8,
4553,
59,
1712,
566,
267,
892,
63,
1375,
63,
7892,
59,
354,
2733,
4553,
418,
275,
892,
63,
4553,
272,
587,
26,
489,
892,
63,
1375,
63,
7892,
59,
84,
61,
275,
1347,
63,
7892,
59,
84,
61,
523,
327,
5244,
1005,
5124,
14,
523,
367,
307,
315,
892,
63,
1375,
63,
7892,
26,
272,
367,
2657,
466,
315,
661,
5714,
297,
283,
5714,
63,
5043,
735,
489,
5124,
275,
1331,
14,
1574,
8,
1222,
63,
1375,
63,
7892,
59,
84
] |
[
1898,
334,
67,
9,
6171,
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,
17505,
3423,
5709,
16885,
270,
314,
5417,
16952,
1041,
199,
199,
646,
1331,
199,
646,
747,
421,
199,
3,
437,
2600,
4412,
3748,
1347,
2943,
370,
5478,
14,
199,
9268,
63,
2711,
63,
2472,
275,
469,
523,
283,
5904,
356,
283,
5803,
297,
523,
283,
20722,
63,
578,
356,
283,
9259,
297,
523,
283,
5555,
63,
4342,
356,
283,
9259,
297,
523,
283,
1986,
63,
4342,
356,
283,
773,
297,
199,
93,
421,
199,
318,
485,
1002,
17149,
21427,
2662,
1017,
21426,
2042,
837,
523,
408,
3407,
314,
931,
402,
314,
7031,
63,
10511,
63,
28238,
14,
2055,
570,
1041,
523,
642,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
523,
2928,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
3749,
63,
694,
12,
19155,
11541,
1333,
523,
4747,
63,
576,
63,
694,
275,
747,
14,
515,
14,
904,
8,
2164,
63,
694,
12,
283,
576,
297,
283,
2676,
358,
523,
7031,
63,
10511,
63,
28238,
63,
2055,
275,
747,
14,
515,
14,
904,
8,
2676,
63,
576,
63,
694,
12,
283,
9629,
13,
10511,
13,
28238,
14,
2055,
358,
523,
372,
7031,
63,
10511,
63,
28238,
63,
2055,
421,
199,
318,
485,
27753,
5116,
7700,
6340,
8,
262,
63,
807,
12,
2883,
304,
523,
408,
2623,
3351,
282,
7417,
13217,
13,
1574,
641,
1204,
262,
63,
807,
18712,
1454,
16743,
314,
2883,
315,
1204,
1612,
18257,
819,
7628,
26,
272,
315,
63,
807,
26,
710,
2600,
370,
1331,
14,
272,
2883,
26,
710,
2883,
370,
506,
8876,
14,
982,
282,
790,
365,
315,
642,
769,
436,
3181,
1133,
2187,
315,
267,
1204,
262,
63,
807,
92,
642,
365,
440,
376,
1125,
14,
523,
1803,
26,
272,
710,
25172,
13217,
13,
23581,
2600,
14,
523,
408,
523,
366,
275,
1052,
523,
367,
790,
315,
2883,
26,
272,
340,
790,
440,
315,
315,
63,
807,
26,
489,
1980,
272,
366,
59,
498,
61,
275,
1331,
14,
8293,
8,
262,
63,
807,
59,
498,
566,
523,
372,
366,
421,
199,
318,
485,
20126,
985,
8,
354,
12,
4739,
304,
523,
408,
1123,
282,
4739,
370,
314,
1284,
402,
282,
1347,
14,
819,
7628,
26,
272,
536,
26,
536,
402,
314,
1347,
334,
1421,
3,
1375,
9,
272,
4739,
26,
314,
4739,
370,
506,
3483,
523,
1803,
26,
272,
10256,
536,
543,
4739,
3483,
334,
1421,
63,
4511,
3,
1375,
9,
523,
408,
523,
4184,
275,
536,
14,
13490,
7863,
297,
413,
9,
523,
4184,
59,
16,
61,
275,
1543,
83,
4970,
83,
7,
450,
334,
4181,
59,
16,
467,
4739,
9,
523,
372,
3943,
1370,
904,
8,
4181,
9,
421,
199,
318,
485,
20019,
985,
8,
354,
12,
1329,
304,
523,
408,
1123,
282,
11814,
1329,
370,
314,
1284,
402,
282,
1347,
14,
819,
7628,
26,
272,
536,
26,
536,
402,
314,
1347,
334,
1421,
3,
1375,
9,
272,
1329,
26,
11814,
1329,
523,
1803,
26,
272,
10256,
536,
543,
11814,
3483,
334,
1421,
63,
17,
3,
1375,
9,
523,
408,
523,
372,
485,
20126,
985,
8,
354,
12,
620,
8,
1955,
430,
421,
199,
318,
5244,
1005,
14126,
8,
1375,
63,
513,
12,
1347,
63,
7892,
304,
523,
408,
20019,
2005,
4545,
29430,
370,
1736,
6818,
314,
2142,
1192,
10976,
14,
819,
7628,
26,
272,
1347,
63,
513,
26,
3820,
402,
1347,
6342,
26,
283,
1095,
15,
1095,
14,
6179,
26,
1095,
1370,
272,
1347,
63,
7892,
26,
7448,
402,
1347,
4382,
19272,
641,
1347,
4092,
14,
523,
1803,
26,
272,
11634,
402,
314,
892,
1033,
12910,
5459,
402,
314,
4153,
14,
523,
408,
523,
327,
19634,
314,
4545,
370,
11814,
12,
436,
4212,
5002,
10338,
14,
523,
4545,
63,
475,
63,
10810,
275,
1052,
523,
367,
307,
315,
1347,
63,
7892,
26,
272,
24130,
275,
1109,
8,
1375,
63,
7892,
59,
84,
1055,
362,
360,
8338,
63,
10810,
297,
378,
430,
272,
340,
24130,
26,
489,
4545,
63,
475,
63,
10810,
59,
84,
61,
275,
24130,
523,
327,
5244,
1005,
1347,
63,
513,
14,
523,
892,
63,
1375,
63,
513,
275,
942,
523,
367,
307,
315,
1347,
63,
513,
26,
272,
340,
307,
315,
4545,
63,
475,
63,
10810,
26,
489,
367,
284,
315,
1425,
8,
4684,
63,
475,
63,
10810,
59,
84,
4682,
267,
892,
63,
1375,
63,
513,
14,
740,
1547,
20019,
985,
8,
84,
12,
284,
430,
272,
587,
26,
489,
892,
63,
1375,
63,
513,
14,
740,
8,
84,
9,
523,
327,
5244,
1005,
1347,
63,
807,
14,
523,
892,
63,
1375,
63,
7892,
275,
1052,
523,
367,
307,
315,
1347,
63,
7892,
26,
272,
340,
307,
315,
4545,
63,
475,
63,
10810,
26,
489,
367,
284,
315,
1425,
8,
4684,
63,
475,
63,
10810,
59,
84,
4682,
267,
536,
275,
485,
20019,
985,
8,
84,
12,
284,
9,
267,
892,
63,
1375,
63,
7892,
59,
354,
61,
275,
1331,
14,
1574,
8,
1375,
63,
7892,
59,
84,
566,
267,
892,
63,
1375,
63,
7892,
59,
354,
2733,
1375,
63,
354,
418,
275,
485,
20019,
985,
8,
1467,
892,
63,
1375,
63,
7892,
59,
354,
2733,
1375,
63,
354,
995,
284,
9,
267,
5274,
275,
892,
63,
1375,
63,
7892,
59,
354,
1055,
362,
360,
4553,
297,
3073,
267,
892,
63,
4553,
275,
942,
267,
367,
2086,
315,
1425,
8,
73,
12,
822,
8,
4553,
395,
4545,
63,
475,
63,
10810,
59,
84,
4682,
881,
892,
63,
4553,
14,
740,
8,
4553,
59,
1712,
566,
267,
892,
63,
1375,
63,
7892,
59,
354,
2733,
4553,
418,
275,
892,
63,
4553,
272,
587,
26,
489,
892,
63,
1375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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
] |
coberger/DIRAC
|
AccountingSystem/Client/Types/SRMSpaceTokenDeployment.py
|
9
|
1378
|
# $HeadURL$
__RCSID__ = "$Id$"
from DIRAC.AccountingSystem.Client.Types.BaseAccountingType import BaseAccountingType
class SRMSpaceTokenDeployment( BaseAccountingType ):
def __init__( self ):
BaseAccountingType.__init__( self )
self.definitionKeyFields = [ ( 'Site' , "VARCHAR(64)" ),
( 'Hostname', "VARCHAR(80)" ),
( 'SpaceTokenDesc', 'VARCHAR(64)' )
]
self.definitionAccountingFields = [ ( 'AvailableSpace', 'BIGINT UNSIGNED' ),
( 'UsedSpace', 'BIGINT UNSIGNED' ),
( 'TotalOnline', 'BIGINT UNSIGNED' ),
( 'UsedOnline', 'BIGINT UNSIGNED' ),
( 'FreeOnline', 'BIGINT UNSIGNED' ),
( 'TotalNearline', 'BIGINT UNSIGNED' ),
( 'UsedNearline', 'BIGINT UNSIGNED' ),
( 'FreeNearline', 'BIGINT UNSIGNED' ),
( 'ReservedNearline', 'BIGINT UNSIGNED' )
]
self.bucketsLength = [ ( 15552000, 86400 ), #<6m = 1d
( 31104000, 604800 ), #>6m = 1w
]
self.checkType()
|
gpl-3.0
|
[
3,
2672,
11664,
2632,
4,
199,
363,
50,
3298,
998,
363,
275,
7880,
1304,
17351,
199,
199,
504,
26565,
14,
6009,
316,
3989,
14,
3041,
14,
4100,
14,
1563,
6009,
316,
804,
492,
3523,
6009,
316,
804,
199,
199,
533,
12765,
3053,
1142,
3264,
25434,
8,
3523,
6009,
316,
804,
3461,
819,
347,
636,
826,
721,
291,
3461,
272,
3523,
6009,
316,
804,
855,
826,
721,
291,
776,
272,
291,
14,
7463,
1197,
7304,
275,
359,
334,
283,
8972,
7,
2360,
298,
24800,
8,
772,
2924,
2318,
639,
334,
283,
25680,
297,
298,
24800,
8,
1257,
2924,
2318,
639,
334,
283,
7643,
3264,
9921,
297,
283,
24800,
8,
772,
3171,
776,
3044,
1622,
272,
291,
14,
7463,
6009,
316,
7304,
275,
359,
334,
283,
11464,
7643,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
7643,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
7316,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10146,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
7316,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10146,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10285,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
776,
4228,
1622,
272,
291,
14,
15065,
4625,
275,
359,
334,
29710,
2528,
1493,
12,
31200,
2318,
327,
28,
22,
77,
275,
413,
68,
2574,
334,
650,
6019,
23641,
12,
1227,
966,
6718,
2318,
327,
30,
22,
77,
275,
413,
87,
586,
1622,
272,
291,
14,
1074,
804,
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
] |
[
2672,
11664,
2632,
4,
199,
363,
50,
3298,
998,
363,
275,
7880,
1304,
17351,
199,
199,
504,
26565,
14,
6009,
316,
3989,
14,
3041,
14,
4100,
14,
1563,
6009,
316,
804,
492,
3523,
6009,
316,
804,
199,
199,
533,
12765,
3053,
1142,
3264,
25434,
8,
3523,
6009,
316,
804,
3461,
819,
347,
636,
826,
721,
291,
3461,
272,
3523,
6009,
316,
804,
855,
826,
721,
291,
776,
272,
291,
14,
7463,
1197,
7304,
275,
359,
334,
283,
8972,
7,
2360,
298,
24800,
8,
772,
2924,
2318,
639,
334,
283,
25680,
297,
298,
24800,
8,
1257,
2924,
2318,
639,
334,
283,
7643,
3264,
9921,
297,
283,
24800,
8,
772,
3171,
776,
3044,
1622,
272,
291,
14,
7463,
6009,
316,
7304,
275,
359,
334,
283,
11464,
7643,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
7643,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
7316,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10146,
28587,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
7316,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
9167,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10146,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
2318,
3147,
334,
283,
10285,
46,
2210,
604,
297,
283,
18643,
2919,
32708,
3203,
1149,
7,
776,
4228,
1622,
272,
291,
14,
15065,
4625,
275,
359,
334,
29710,
2528,
1493,
12,
31200,
2318,
327,
28,
22,
77,
275,
413,
68,
2574,
334,
650,
6019,
23641,
12,
1227,
966,
6718,
2318,
327,
30,
22,
77,
275,
413,
87,
586,
1622,
272,
291,
14,
1074,
804,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
yasoob/youtube-dl-GUI
|
youtube_dl/extractor/slutload.py
|
23
|
2350
|
from __future__ import unicode_literals
from .common import InfoExtractor
class SlutloadIE(InfoExtractor):
_VALID_URL = r'https?://(?:\w+\.)?slutload\.com/(?:video/[^/]+|embed_player|watch)/(?P<id>[^/]+)'
_TESTS = [{
'url': 'http://www.slutload.com/video/virginie-baisee-en-cam/TD73btpBqSxc/',
'md5': '868309628ba00fd488cf516a113fd717',
'info_dict': {
'id': 'TD73btpBqSxc',
'ext': 'mp4',
'title': 'virginie baisee en cam',
'age_limit': 18,
'thumbnail': r're:https?://.*?\.jpg'
},
}, {
# mobile site
'url': 'http://mobile.slutload.com/video/masturbation-solo/fviFLmc6kzJ/',
'only_matching': True,
}, {
'url': 'http://www.slutload.com/embed_player/TD73btpBqSxc/',
'only_matching': True,
}, {
'url': 'http://www.slutload.com/watch/TD73btpBqSxc/Virginie-Baisee-En-Cam.html',
'only_matching': True,
}]
def _real_extract(self, url):
video_id = self._match_id(url)
embed_page = self._download_webpage(
'http://www.slutload.com/embed_player/%s' % video_id, video_id,
'Downloading embed page', fatal=False)
if embed_page:
def extract(what):
return self._html_search_regex(
r'data-video-%s=(["\'])(?P<url>(?:(?!\1).)+)\1' % what,
embed_page, 'video %s' % what, default=None, group='url')
video_url = extract('url')
if video_url:
title = self._html_search_regex(
r'<title>([^<]+)', embed_page, 'title', default=video_id)
return {
'id': video_id,
'url': video_url,
'title': title,
'thumbnail': extract('preview'),
'age_limit': 18
}
webpage = self._download_webpage(
'http://www.slutload.com/video/_/%s/' % video_id, video_id)
title = self._html_search_regex(
r'<h1><strong>([^<]+)</strong>', webpage, 'title').strip()
info = self._parse_html5_media_entries(url, webpage, video_id)[0]
info.update({
'id': video_id,
'title': title,
'age_limit': 18,
})
return info
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
428,
30562,
912,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
15840,
87,
11,
20316,
2482,
337,
912,
4537,
957,
32576,
3722,
15,
26285,
92,
6427,
63,
6147,
92,
6821,
2447,
2229,
48,
28,
344,
26906,
3171,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
3722,
15,
1042,
903,
1873,
13,
2470,
572,
69,
13,
287,
13,
15176,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
3678,
267,
283,
1064,
21,
356,
283,
15430,
1216,
2534,
1651,
2470,
383,
2592,
11926,
2177,
23691,
65,
9225,
2592,
31462,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
13449,
2898,
66,
683,
34,
81,
51,
1812,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1042,
903,
1873,
19325,
572,
69,
655,
27570,
297,
288,
283,
474,
63,
3097,
356,
6155,
12,
288,
283,
8311,
356,
519,
3984,
26,
2859,
14144,
6697,
4537,
8476,
7,
267,
1660,
272,
1660,
469,
267,
327,
21305,
4770,
267,
283,
633,
356,
283,
1014,
921,
11375,
14,
2482,
337,
912,
14,
957,
15,
3722,
15,
391,
270,
30395,
425,
13,
1152,
320,
15,
70,
433,
3143,
5466,
22,
75,
90,
42,
3678,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6427,
63,
6147,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
3678,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6821,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
15,
54,
723,
903,
1873,
13,
13864,
572,
69,
13,
1327,
13,
30524,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
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,
398,
6441,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6427,
63,
6147,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
12,
288,
283,
18085,
6441,
2034,
297,
14294,
29,
797,
9,
398,
340,
6441,
63,
1606,
26,
288,
347,
5536,
8,
10058,
304,
355,
372,
291,
423,
1360,
63,
1733,
63,
3821,
8,
490,
519,
5121,
419,
13,
3722,
3295,
83,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
7,
450,
4052,
12,
490,
6441,
63,
1606,
12,
283,
3722,
450,
83,
7,
450,
4052,
12,
849,
29,
403,
12,
1572,
534,
633,
358,
953,
3991,
63,
633,
275,
5536,
360,
633,
358,
288,
340,
3991,
63,
633,
26,
355,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
490,
519,
7601,
1213,
30,
31204,
28798,
6441,
63,
1606,
12,
283,
1213,
297,
849,
29,
3722,
63,
344,
9,
355,
372,
469,
490,
283,
344,
356,
3991,
63,
344,
12,
490,
283,
633,
356,
3991,
63,
633,
12,
490,
283,
1213,
356,
2538,
12,
490,
283,
8311,
356,
5536,
360,
7780,
659,
490,
283,
474,
63,
3097,
356,
6155,
355,
789,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
3722,
15607,
3149,
83,
4805,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
72,
17,
2535,
9370,
30,
31204,
11896,
1108,
9370,
4206,
9248,
12,
283,
1213,
1959,
1913,
342,
267,
2256,
275,
291,
423,
1122,
63,
1360,
21,
63,
4603,
63,
3189,
8,
633,
12,
9248,
12,
3991,
63,
344,
2788,
16,
61,
267,
2256,
14,
873,
2561,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
474,
63,
3097,
356,
6155,
12,
267,
3828,
267,
372,
2256,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1275,
2330,
492,
21298,
421,
199,
533,
428,
30562,
912,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
15840,
87,
11,
20316,
2482,
337,
912,
4537,
957,
32576,
3722,
15,
26285,
92,
6427,
63,
6147,
92,
6821,
2447,
2229,
48,
28,
344,
26906,
3171,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
3722,
15,
1042,
903,
1873,
13,
2470,
572,
69,
13,
287,
13,
15176,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
3678,
267,
283,
1064,
21,
356,
283,
15430,
1216,
2534,
1651,
2470,
383,
2592,
11926,
2177,
23691,
65,
9225,
2592,
31462,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
13449,
2898,
66,
683,
34,
81,
51,
1812,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1042,
903,
1873,
19325,
572,
69,
655,
27570,
297,
288,
283,
474,
63,
3097,
356,
6155,
12,
288,
283,
8311,
356,
519,
3984,
26,
2859,
14144,
6697,
4537,
8476,
7,
267,
1660,
272,
1660,
469,
267,
327,
21305,
4770,
267,
283,
633,
356,
283,
1014,
921,
11375,
14,
2482,
337,
912,
14,
957,
15,
3722,
15,
391,
270,
30395,
425,
13,
1152,
320,
15,
70,
433,
3143,
5466,
22,
75,
90,
42,
3678,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6427,
63,
6147,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
3678,
267,
283,
2118,
63,
9467,
356,
715,
12,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6821,
15,
13449,
2898,
66,
683,
34,
81,
51,
1812,
15,
54,
723,
903,
1873,
13,
13864,
572,
69,
13,
1327,
13,
30524,
14,
1360,
297,
267,
283,
2118,
63,
9467,
356,
715,
12,
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,
398,
6441,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
6427,
63,
6147,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
12,
288,
283,
18085,
6441,
2034,
297,
14294,
29,
797,
9,
398,
340,
6441,
63,
1606,
26,
288,
347,
5536,
8,
10058,
304,
355,
372,
291,
423,
1360,
63,
1733,
63,
3821,
8,
490,
519,
5121,
419,
13,
3722,
3295,
83,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
7,
450,
4052,
12,
490,
6441,
63,
1606,
12,
283,
3722,
450,
83,
7,
450,
4052,
12,
849,
29,
403,
12,
1572,
534,
633,
358,
953,
3991,
63,
633,
275,
5536,
360,
633,
358,
288,
340,
3991,
63,
633,
26,
355,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
490,
519,
7601,
1213,
30,
31204,
28798,
6441,
63,
1606,
12,
283,
1213,
297,
849,
29,
3722,
63,
344,
9,
355,
372,
469,
490,
283,
344,
356,
3991,
63,
344,
12,
490,
283,
633,
356,
3991,
63,
633,
12,
490,
283,
1213,
356,
2538,
12,
490,
283,
8311,
356,
5536,
360,
7780,
659,
490,
283,
474,
63,
3097,
356,
6155,
355,
789,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
1544,
14,
2482,
337,
912,
14,
957,
15,
3722,
15607,
3149,
83,
4805,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
72,
17,
2535,
9370,
30,
31204,
11896,
1108,
9370,
4206,
9248,
12,
283,
1213,
1959,
1913,
342,
267,
2256,
275,
291,
423,
1122,
63,
1360,
21,
63,
4603,
63,
3189,
8,
633,
12,
9248,
12,
3991,
63,
344,
2788,
16,
61,
267,
2256,
14,
873,
2561,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
474,
63,
3097,
356,
6155,
12,
267,
3828,
267,
372,
2256,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
Alex-Ian-Hamilton/sunpy
|
examples/gallery/map_from_numpy_array.py
|
1
|
1364
|
# -*- coding: utf-8 -*-
"""
=========================================
Generating a Map From Data
=========================================
A simple demonstration of creating a map from a numpy array of data.
"""
##############################################################################
# Start by importing the necessary modules.
from __future__ import print_function, division
import numpy as np
import sunpy.map
import sunpy.data.sample
##############################################################################
# SunPy Maps store 2D data in a numpy array and additional data in a metadata
# dictionary giving information relating to the data and instrument.
data = np.random.rand(20,15)
header = {}
manual_map = sunpy.map.Map((data, header))
##############################################################################
# In general the attributes are populated using details in the metadata and in
# this case there is no centre pixel or pixel size information given so SunPy
# is defaulting to assuming each pixel is 1 arcsec.
print(manual_map.xrange)
print(manual_map.yrange)
# This is in Helioprojective tangent projection in both longitude and latitude:
print(manual_map.coordinate_system)
##############################################################################
# You can quickly plot a map using the peek method:
manual_map.peek()
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
2486,
15495,
199,
29244,
282,
9672,
11606,
3918,
199,
2486,
15495,
199,
199,
33,
3486,
23789,
270,
1754,
402,
6425,
282,
2341,
687,
282,
2680,
1625,
402,
666,
14,
199,
624,
199,
199,
4605,
199,
3,
7707,
701,
16306,
314,
5784,
4621,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
26668,
647,
14,
1130,
199,
646,
26668,
647,
14,
576,
14,
3271,
199,
199,
4605,
199,
3,
25625,
2713,
23673,
3877,
499,
36,
666,
315,
282,
2680,
1625,
436,
4722,
666,
315,
282,
3341,
199,
3,
2600,
15131,
2556,
4668,
1958,
370,
314,
666,
436,
14498,
14,
199,
576,
275,
980,
14,
2355,
14,
3759,
8,
1165,
12,
1046,
9,
199,
1291,
275,
1052,
199,
9285,
63,
1130,
275,
26668,
647,
14,
1130,
14,
2956,
1332,
576,
12,
1406,
430,
199,
199,
4605,
199,
3,
1010,
8605,
314,
3004,
787,
16460,
1808,
2436,
315,
314,
3341,
436,
315,
199,
3,
642,
1930,
2337,
365,
949,
13345,
264,
7148,
503,
7148,
1568,
2556,
1627,
880,
25625,
2713,
199,
3,
365,
849,
316,
370,
18002,
1924,
7148,
365,
413,
14972,
3321,
14,
199,
1361,
8,
9285,
63,
1130,
14,
21120,
9,
199,
1361,
8,
9285,
63,
1130,
14,
89,
1842,
9,
199,
3,
961,
365,
315,
5311,
317,
11340,
74,
6850,
307,
29360,
14777,
315,
3865,
18154,
436,
18896,
26,
199,
1361,
8,
9285,
63,
1130,
14,
20493,
63,
2253,
9,
199,
199,
4605,
199,
3,
2047,
883,
23661,
5137,
282,
2341,
1808,
314,
15094,
1083,
26,
199,
9285,
63,
1130,
14,
13164,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2486,
15495,
199,
29244,
282,
9672,
11606,
3918,
199,
2486,
15495,
199,
199,
33,
3486,
23789,
270,
1754,
402,
6425,
282,
2341,
687,
282,
2680,
1625,
402,
666,
14,
199,
624,
199,
199,
4605,
199,
3,
7707,
701,
16306,
314,
5784,
4621,
14,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
646,
2680,
465,
980,
199,
199,
646,
26668,
647,
14,
1130,
199,
646,
26668,
647,
14,
576,
14,
3271,
199,
199,
4605,
199,
3,
25625,
2713,
23673,
3877,
499,
36,
666,
315,
282,
2680,
1625,
436,
4722,
666,
315,
282,
3341,
199,
3,
2600,
15131,
2556,
4668,
1958,
370,
314,
666,
436,
14498,
14,
199,
576,
275,
980,
14,
2355,
14,
3759,
8,
1165,
12,
1046,
9,
199,
1291,
275,
1052,
199,
9285,
63,
1130,
275,
26668,
647,
14,
1130,
14,
2956,
1332,
576,
12,
1406,
430,
199,
199,
4605,
199,
3,
1010,
8605,
314,
3004,
787,
16460,
1808,
2436,
315,
314,
3341,
436,
315,
199,
3,
642,
1930,
2337,
365,
949,
13345,
264,
7148,
503,
7148,
1568,
2556,
1627,
880,
25625,
2713,
199,
3,
365,
849,
316,
370,
18002,
1924,
7148,
365,
413,
14972,
3321,
14,
199,
1361,
8,
9285,
63,
1130,
14,
21120,
9,
199,
1361,
8,
9285,
63,
1130,
14,
89,
1842,
9,
199,
3,
961,
365,
315,
5311,
317,
11340,
74,
6850,
307,
29360,
14777,
315,
3865,
18154,
436,
18896,
26,
199,
1361,
8,
9285,
63,
1130,
14,
20493,
63,
2253,
9,
199,
199,
4605,
199,
3,
2047,
883,
23661,
5137,
282,
2341,
1808,
314,
15094,
1083,
26,
199,
9285,
63,
1130,
14,
13164,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
faneshion/MatchZoo
|
matchzoo/contrib/layers/spatial_gru.py
|
1
|
10175
|
"""An implementation of Spatial GRU Layer."""
import typing
import tensorflow as tf
from keras import backend as K
from keras.engine import Layer
from keras.layers import Permute
from keras.layers import Reshape
from keras import activations
from keras import initializers
class SpatialGRU(Layer):
"""
Spatial GRU layer.
:param units: Number of SpatialGRU units.
:param activation: Activation function to use. Default:
hyperbolic tangent (`tanh`). If you pass `None`, no
activation is applied (ie. "linear" activation: `a(x) = x`).
:param recurrent_activation: Activation function to use for
the recurrent step. Default: sigmoid (`sigmoid`).
If you pass `None`, no activation is applied (ie. "linear"
activation: `a(x) = x`).
:param kernel_initializer: Initializer for the `kernel` weights
matrix, used for the linear transformation of the inputs.
:param recurrent_initializer: Initializer for the `recurrent_kernel`
weights matrix, used for the linear transformation of the
recurrent state.
:param direction: Scanning direction. `lt` (i.e., left top)
indicates the scanning from left top to right bottom, and
`rb` (i.e., right bottom) indicates the scanning from
right bottom to left top.
:param kwargs: Standard layer keyword arguments.
Examples:
>>> import matchzoo as mz
>>> layer = mz.contrib.layers.SpatialGRU(units=10,
... direction='lt')
>>> num_batch, channel, left_len, right_len = 5, 5, 3, 2
>>> layer.build([num_batch, channel, left_len, right_len])
"""
def __init__(
self,
units: int = 10,
activation: str = 'tanh',
recurrent_activation: str = 'sigmoid',
kernel_initializer: str = 'glorot_uniform',
recurrent_initializer: str = 'orthogonal',
direction: str = 'lt',
**kwargs
):
""":class:`SpatialGRU` constructor."""
super().__init__(**kwargs)
self._units = units
self._activation = activations.get(activation)
self._recurrent_activation = activations.get(recurrent_activation)
self._kernel_initializer = initializers.get(kernel_initializer)
self._recurrent_initializer = initializers.get(recurrent_initializer)
self._direction = direction
def build(self, input_shape: typing.Any):
"""
Build the layer.
:param input_shape: the shapes of the input tensors.
"""
# Scalar dimensions referenced here:
# B = batch size (number of sequences)
# L = `input_left` sequence length
# R = `input_right` sequence length
# C = number of channels
# U = number of units
# input_shape = [B, C, L, R]
self._batch_size = input_shape[0]
self._channel = input_shape[1]
self._input_dim = self._channel + 3 * self._units
self._text1_maxlen = input_shape[2]
self._text2_maxlen = input_shape[3]
self._recurrent_step = self._text1_maxlen * self._text2_maxlen
# W = [3*U+C, 7*U]
self._W = self.add_weight(
name='W',
shape=(self._input_dim, self._units * 7),
initializer=self._kernel_initializer,
trainable=True
)
# U = [3*U, U]
self._U = self.add_weight(
name='U',
shape=(self._units * 3, self._units),
initializer=self._recurrent_initializer,
trainable=True
)
# bias = [8*U,]
self._bias = self.add_weight(
name='bias',
shape=(self._units * 8,),
initializer='zeros',
trainable=True
)
# w_rl, w_rt, w_rd = [B, 3*U]
self._wr = self._W[:, :self._units * 3]
# b_rl, b_rt, b_rd = [B, 3*U]
self._br = self._bias[:self._units * 3]
# w_zi, w_zl, w_zt, w_zd = [B, 4*U]
self._wz = self._W[:, self._units * 3: self._units * 7]
# b_zi, b_zl, b_zt, b_zd = [B, 4*U]
self._bz = self._bias[self._units * 3: self._units * 7]
# w_ij = [C, U]
self._w_ij = self.add_weight(
name='W_ij',
shape=(self._channel, self._units),
initializer=self._recurrent_initializer,
trainable=True
)
# b_ij = [7*U]
self._b_ij = self._bias[self._units * 7:]
super(SpatialGRU, self).build(input_shape)
def softmax_by_row(self, z: typing.Any) -> tuple:
"""Conduct softmax on each dimension across the four gates."""
# z_transform: [B, U, 4]
z_transform = Permute((2, 1))(Reshape((4, self._units))(z))
size = [-1, 1, -1]
# Perform softmax on each slice
for i in range(0, self._units):
begin = [0, i, 0]
# z_slice: [B, 1, 4]
z_slice = tf.slice(z_transform, begin, size)
if i == 0:
z_s = tf.nn.softmax(z_slice)
else:
z_s = tf.concat([z_s, tf.nn.softmax(z_slice)], 1)
# zi, zl, zt, zd: [B, U]
zi, zl, zt, zd = tf.unstack(z_s, axis=2)
return zi, zl, zt, zd
def calculate_recurrent_unit(
self,
inputs: typing.Any,
states: typing.Any,
step: int,
h: typing.Any,
) -> tuple:
"""
Calculate recurrent unit.
:param inputs: A TensorArray which contains interaction
between left text and right text.
:param states: A TensorArray which stores the hidden state
of every step.
:param step: Recurrent step.
:param h: Hidden state from last operation.
"""
# Get index i, j
i = tf.math.floordiv(step, tf.constant(self._text2_maxlen))
j = tf.math.mod(step, tf.constant(self._text2_maxlen))
# Get hidden state h_diag, h_top, h_left
# h_diag, h_top, h_left = [B, U]
h_diag = states.read(i * (self._text2_maxlen + 1) + j)
h_top = states.read(i * (self._text2_maxlen + 1) + j + 1)
h_left = states.read((i + 1) * (self._text2_maxlen + 1) + j)
# Get interaction between word i, j: s_ij
# s_ij = [B, C]
s_ij = inputs.read(step)
# Concatenate h_top, h_left, h_diag, s_ij
# q = [B, 3*U+C]
q = tf.concat([tf.concat([h_top, h_left], 1),
tf.concat([h_diag, s_ij], 1)], 1)
# Calculate reset gate
# r = [B, 3*U]
r = self._recurrent_activation(
self._time_distributed_dense(self._wr, q, self._br))
# Calculate updating gate
# z: [B, 4*U]
z = self._time_distributed_dense(self._wz, q, self._bz)
# Perform softmax
# zi, zl, zt, zd: [B, U]
zi, zl, zt, zd = self.softmax_by_row(z)
# Get h_ij_
# h_ij_ = [B, U]
h_ij_l = self._time_distributed_dense(self._w_ij, s_ij, self._b_ij)
h_ij_r = K.dot(r * (tf.concat([h_left, h_top, h_diag], 1)), self._U)
h_ij_ = self._activation(h_ij_l + h_ij_r)
# Calculate h_ij
# h_ij = [B, U]
h_ij = zl * h_left + zt * h_top + zd * h_diag + zi * h_ij_
# Write h_ij to states
states = states.write(((i + 1) * (self._text2_maxlen + 1) + j + 1),
h_ij)
h_ij.set_shape(h_top.get_shape())
return inputs, states, step + 1, h_ij
def call(self, inputs: list, **kwargs) -> typing.Any:
"""
The computation logic of SpatialGRU.
:param inputs: input tensors.
"""
batch_size = tf.shape(inputs)[0]
# h0 = [B, U]
self._bounder_state_h0 = tf.zeros([batch_size, self._units])
# input_x = [L, R, B, C]
input_x = tf.transpose(inputs, [2, 3, 0, 1])
if self._direction == 'rb':
# input_x: [R, L, B, C]
input_x = tf.reverse(input_x, [0, 1])
elif self._direction != 'lt':
raise ValueError(f"Invalid direction. "
f"`{self._direction}` received. "
f"Must be in `lt`, `rb`.")
# input_x = [L*R*B, C]
input_x = tf.reshape(input_x, [-1, self._channel])
# input_x = L*R * [B, C]
input_x = tf.split(
axis=0,
num_or_size_splits=self._text1_maxlen * self._text2_maxlen,
value=input_x
)
# inputs = L*R * [B, C]
inputs = tf.TensorArray(
dtype=tf.float32,
size=self._text1_maxlen * self._text2_maxlen,
name='inputs'
)
inputs = inputs.unstack(input_x)
# states = (L+1)*(R+1) * [B, U]
states = tf.TensorArray(
dtype=tf.float32,
size=(self._text1_maxlen + 1) * (self._text2_maxlen + 1),
name='states',
clear_after_read=False
)
# Initialize states
for i in range(self._text2_maxlen + 1):
states = states.write(i, self._bounder_state_h0)
for i in range(1, self._text1_maxlen + 1):
states = states.write(i * (self._text2_maxlen + 1),
self._bounder_state_h0)
# Calculate h_ij
# h_ij = [B, U]
_, _, _, h_ij = tf.while_loop(
cond=lambda _0, _1, i, _3: tf.less(i, self._recurrent_step),
body=self.calculate_recurrent_unit,
loop_vars=(
inputs,
states,
tf.constant(0, dtype=tf.int32),
self._bounder_state_h0
),
parallel_iterations=1,
swap_memory=True
)
return h_ij
def compute_output_shape(self, input_shape: typing.Any) -> tuple:
"""
Calculate the layer output shape.
:param input_shape: the shapes of the input tensors.
"""
output_shape = [input_shape[0], self._units]
return tuple(output_shape)
@classmethod
def _time_distributed_dense(cls, w, x, b):
x = K.dot(x, w)
x = K.bias_add(x, b)
return x
|
apache-2.0
|
[
624,
2493,
4514,
402,
13423,
598,
9500,
11915,
1041,
199,
646,
14090,
199,
646,
3228,
465,
2833,
199,
504,
11708,
492,
4865,
465,
1804,
199,
504,
11708,
14,
3908,
492,
11915,
199,
504,
11708,
14,
4359,
492,
3492,
12423,
199,
504,
11708,
14,
4359,
492,
3591,
15221,
199,
504,
11708,
492,
32038,
199,
504,
11708,
492,
2536,
6315,
421,
199,
533,
13423,
3975,
53,
8,
5003,
304,
272,
408,
272,
13423,
598,
9500,
4045,
14,
339,
520,
635,
6204,
26,
4860,
402,
13423,
3975,
53,
6204,
14,
272,
520,
635,
10361,
26,
29441,
805,
370,
675,
14,
3758,
26,
267,
10342,
9670,
307,
29360,
13493,
21468,
14963,
982,
1265,
986,
658,
403,
3559,
949,
267,
10361,
365,
6781,
334,
1873,
14,
298,
6676,
2,
10361,
26,
658,
65,
8,
88,
9,
275,
671,
14963,
272,
520,
635,
295,
1818,
63,
12312,
26,
29441,
805,
370,
675,
367,
267,
314,
295,
1818,
3650,
14,
3758,
26,
28886,
13493,
20035,
14963,
267,
982,
1265,
986,
658,
403,
3559,
949,
10361,
365,
6781,
334,
1873,
14,
298,
6676,
2,
267,
10361,
26,
658,
65,
8,
88,
9,
275,
671,
14963,
272,
520,
635,
5114,
63,
6498,
26,
6026,
1793,
367,
314,
658,
4989,
64,
4931,
267,
3634,
12,
1202,
367,
314,
7798,
13315,
402,
314,
4153,
14,
272,
520,
635,
295,
1818,
63,
6498,
26,
6026,
1793,
367,
314,
658,
31897,
63,
4989,
64,
267,
4931,
3634,
12,
1202,
367,
314,
7798,
13315,
402,
314,
267,
295,
1818,
1174,
14,
272,
520,
635,
7581,
26,
13916,
11495,
7581,
14,
658,
4116,
64,
334,
73,
14,
69,
2020,
3602,
2746,
9,
267,
9126,
314,
24928,
687,
3602,
2746,
370,
2451,
9048,
12,
436,
267,
658,
4848,
64,
334,
73,
14,
69,
2020,
2451,
9048,
9,
9126,
314,
24928,
687,
267,
2451,
9048,
370,
3602,
2746,
14,
272,
520,
635,
2074,
26,
9739,
4045,
4252,
2368,
14,
339,
6058,
26,
267,
1306,
492,
1336,
90,
1534,
465,
333,
90,
267,
1306,
4045,
275,
333,
90,
14,
2828,
14,
4359,
14,
18075,
3975,
53,
8,
5260,
29,
709,
12,
267,
2263,
32543,
7581,
534,
4116,
358,
267,
1306,
1967,
63,
2912,
12,
3623,
12,
3602,
63,
552,
12,
2451,
63,
552,
275,
959,
12,
959,
12,
650,
12,
499,
267,
1306,
4045,
14,
1506,
779,
1507,
63,
2912,
12,
3623,
12,
3602,
63,
552,
12,
2451,
63,
552,
566,
339,
408,
339,
347,
636,
826,
721,
267,
291,
12,
267,
6204,
26,
1109,
275,
1616,
12,
267,
10361,
26,
620,
275,
283,
21468,
297,
267,
295,
1818,
63,
12312,
26,
620,
275,
283,
20035,
297,
267,
5114,
63,
6498,
26,
620,
275,
283,
3528,
269,
357,
63,
8830,
297,
267,
295,
1818,
63,
6498,
26,
620,
275,
283,
11297,
19133,
297,
267,
7581,
26,
620,
275,
283,
4116,
297,
267,
1011,
958,
272,
3461,
267,
408,
26,
533,
1705,
18075,
3975,
53,
64,
3787,
1041,
267,
1613,
11027,
826,
14155,
958,
9,
267,
291,
423,
5260,
275,
6204,
267,
291,
423,
12312,
275,
32038,
14,
362,
8,
12312,
9,
267,
291,
423,
31897,
63,
12312,
275,
32038,
14,
362,
8,
31897,
63,
12312,
9,
398,
291,
423,
4989,
63,
6498,
275,
2536,
6315,
14,
362,
8,
4989,
63,
6498,
9,
267,
291,
423,
31897,
63,
6498,
275,
2536,
6315,
14,
362,
8,
31897,
63,
6498,
9,
267,
291,
423,
6874,
275,
7581,
339,
347,
1900,
8,
277,
12,
1324,
63,
1392,
26,
14090,
14,
9874,
304,
267,
408,
267,
6516,
314,
4045,
14,
398,
520,
635,
1324,
63,
1392,
26,
314,
11751,
402,
314,
1324,
10519,
14,
267,
408,
267,
327,
24289,
7365,
11812,
2348,
26,
267,
327,
257,
699,
275,
3522,
1568,
334,
1955,
402,
8013,
9,
267,
327,
257,
491,
275,
658,
1210,
63,
3039,
64,
3414,
2582,
267,
327,
257,
820,
275,
658,
1210,
63,
1019,
64,
3414,
2582,
267,
327,
257,
445,
275,
1329,
402,
9245,
267,
327,
257,
738,
275,
1329,
402,
6204,
398,
327,
1324,
63,
1392,
275,
359,
34,
12,
445,
12,
491,
12,
820,
61,
267,
291,
423,
2912,
63,
890,
275,
1324,
63,
1392,
59,
16,
61,
267,
291,
423,
2775,
275,
1324,
63,
1392,
59,
17,
61,
267,
291,
423,
1210,
63,
3572,
275,
291,
423,
2775,
435,
650,
627,
291,
423,
5260,
398,
291,
423,
505,
17,
63,
29078,
275,
1324,
63,
1392,
59,
18,
61,
267,
291,
423,
505,
18,
63,
29078,
275,
1324,
63,
1392,
59,
19,
61,
267,
291,
423,
31897,
63,
2926,
275,
291,
423,
505,
17,
63,
29078,
627,
291,
423,
505,
18,
63,
29078,
267,
327,
644,
275,
359,
19,
10,
53,
11,
35,
12,
1520,
10,
53,
61,
267,
291,
423,
55,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
55,
297,
288,
2215,
2687,
277,
423,
1210,
63,
3572,
12,
291,
423,
5260,
627,
1520,
395,
288,
11130,
29,
277,
423,
4989,
63,
6498,
12,
288,
17029,
29,
549,
267,
776,
267,
327,
738,
275,
359,
19,
10,
53,
12,
738,
61,
267,
291,
423,
53,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
53,
297,
288,
2215,
2687,
277,
423,
5260,
627,
650,
12,
291,
423,
5260,
395,
288,
11130,
29,
277,
423,
31897,
63,
6498,
12,
288,
17029,
29,
549,
267,
776,
267,
327,
10671,
275,
359,
24,
10,
53,
12,
61,
267,
291,
423,
8160,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
8160,
297,
288,
2215,
2687,
277,
423,
5260,
627,
1695,
4706,
288,
11130,
534,
4250,
297,
288,
17029,
29,
549,
267,
776,
398,
327,
336,
63,
4308,
12,
336,
63,
2591,
12,
336,
63,
6883,
275,
359,
34,
12,
650,
10,
53,
61,
267,
291,
423,
17097,
275,
291,
423,
55,
3981,
520,
277,
423,
5260,
627,
650,
61,
267,
327,
330,
63,
4308,
12,
330,
63,
2591,
12,
330,
63,
6883,
275,
359,
34,
12,
650,
10,
53,
61,
267,
291,
423,
3289,
275,
291,
423,
8160,
1491,
277,
423,
5260,
627,
650,
61,
267,
327,
336,
63,
16079,
12,
336,
63,
90,
76,
12,
336,
63,
90,
84,
12,
336,
63,
23670,
275,
359,
34,
12,
841,
10,
53,
61,
267,
291,
423,
87,
90,
275,
291
] |
[
2493,
4514,
402,
13423,
598,
9500,
11915,
1041,
199,
646,
14090,
199,
646,
3228,
465,
2833,
199,
504,
11708,
492,
4865,
465,
1804,
199,
504,
11708,
14,
3908,
492,
11915,
199,
504,
11708,
14,
4359,
492,
3492,
12423,
199,
504,
11708,
14,
4359,
492,
3591,
15221,
199,
504,
11708,
492,
32038,
199,
504,
11708,
492,
2536,
6315,
421,
199,
533,
13423,
3975,
53,
8,
5003,
304,
272,
408,
272,
13423,
598,
9500,
4045,
14,
339,
520,
635,
6204,
26,
4860,
402,
13423,
3975,
53,
6204,
14,
272,
520,
635,
10361,
26,
29441,
805,
370,
675,
14,
3758,
26,
267,
10342,
9670,
307,
29360,
13493,
21468,
14963,
982,
1265,
986,
658,
403,
3559,
949,
267,
10361,
365,
6781,
334,
1873,
14,
298,
6676,
2,
10361,
26,
658,
65,
8,
88,
9,
275,
671,
14963,
272,
520,
635,
295,
1818,
63,
12312,
26,
29441,
805,
370,
675,
367,
267,
314,
295,
1818,
3650,
14,
3758,
26,
28886,
13493,
20035,
14963,
267,
982,
1265,
986,
658,
403,
3559,
949,
10361,
365,
6781,
334,
1873,
14,
298,
6676,
2,
267,
10361,
26,
658,
65,
8,
88,
9,
275,
671,
14963,
272,
520,
635,
5114,
63,
6498,
26,
6026,
1793,
367,
314,
658,
4989,
64,
4931,
267,
3634,
12,
1202,
367,
314,
7798,
13315,
402,
314,
4153,
14,
272,
520,
635,
295,
1818,
63,
6498,
26,
6026,
1793,
367,
314,
658,
31897,
63,
4989,
64,
267,
4931,
3634,
12,
1202,
367,
314,
7798,
13315,
402,
314,
267,
295,
1818,
1174,
14,
272,
520,
635,
7581,
26,
13916,
11495,
7581,
14,
658,
4116,
64,
334,
73,
14,
69,
2020,
3602,
2746,
9,
267,
9126,
314,
24928,
687,
3602,
2746,
370,
2451,
9048,
12,
436,
267,
658,
4848,
64,
334,
73,
14,
69,
2020,
2451,
9048,
9,
9126,
314,
24928,
687,
267,
2451,
9048,
370,
3602,
2746,
14,
272,
520,
635,
2074,
26,
9739,
4045,
4252,
2368,
14,
339,
6058,
26,
267,
1306,
492,
1336,
90,
1534,
465,
333,
90,
267,
1306,
4045,
275,
333,
90,
14,
2828,
14,
4359,
14,
18075,
3975,
53,
8,
5260,
29,
709,
12,
267,
2263,
32543,
7581,
534,
4116,
358,
267,
1306,
1967,
63,
2912,
12,
3623,
12,
3602,
63,
552,
12,
2451,
63,
552,
275,
959,
12,
959,
12,
650,
12,
499,
267,
1306,
4045,
14,
1506,
779,
1507,
63,
2912,
12,
3623,
12,
3602,
63,
552,
12,
2451,
63,
552,
566,
339,
408,
339,
347,
636,
826,
721,
267,
291,
12,
267,
6204,
26,
1109,
275,
1616,
12,
267,
10361,
26,
620,
275,
283,
21468,
297,
267,
295,
1818,
63,
12312,
26,
620,
275,
283,
20035,
297,
267,
5114,
63,
6498,
26,
620,
275,
283,
3528,
269,
357,
63,
8830,
297,
267,
295,
1818,
63,
6498,
26,
620,
275,
283,
11297,
19133,
297,
267,
7581,
26,
620,
275,
283,
4116,
297,
267,
1011,
958,
272,
3461,
267,
408,
26,
533,
1705,
18075,
3975,
53,
64,
3787,
1041,
267,
1613,
11027,
826,
14155,
958,
9,
267,
291,
423,
5260,
275,
6204,
267,
291,
423,
12312,
275,
32038,
14,
362,
8,
12312,
9,
267,
291,
423,
31897,
63,
12312,
275,
32038,
14,
362,
8,
31897,
63,
12312,
9,
398,
291,
423,
4989,
63,
6498,
275,
2536,
6315,
14,
362,
8,
4989,
63,
6498,
9,
267,
291,
423,
31897,
63,
6498,
275,
2536,
6315,
14,
362,
8,
31897,
63,
6498,
9,
267,
291,
423,
6874,
275,
7581,
339,
347,
1900,
8,
277,
12,
1324,
63,
1392,
26,
14090,
14,
9874,
304,
267,
408,
267,
6516,
314,
4045,
14,
398,
520,
635,
1324,
63,
1392,
26,
314,
11751,
402,
314,
1324,
10519,
14,
267,
408,
267,
327,
24289,
7365,
11812,
2348,
26,
267,
327,
257,
699,
275,
3522,
1568,
334,
1955,
402,
8013,
9,
267,
327,
257,
491,
275,
658,
1210,
63,
3039,
64,
3414,
2582,
267,
327,
257,
820,
275,
658,
1210,
63,
1019,
64,
3414,
2582,
267,
327,
257,
445,
275,
1329,
402,
9245,
267,
327,
257,
738,
275,
1329,
402,
6204,
398,
327,
1324,
63,
1392,
275,
359,
34,
12,
445,
12,
491,
12,
820,
61,
267,
291,
423,
2912,
63,
890,
275,
1324,
63,
1392,
59,
16,
61,
267,
291,
423,
2775,
275,
1324,
63,
1392,
59,
17,
61,
267,
291,
423,
1210,
63,
3572,
275,
291,
423,
2775,
435,
650,
627,
291,
423,
5260,
398,
291,
423,
505,
17,
63,
29078,
275,
1324,
63,
1392,
59,
18,
61,
267,
291,
423,
505,
18,
63,
29078,
275,
1324,
63,
1392,
59,
19,
61,
267,
291,
423,
31897,
63,
2926,
275,
291,
423,
505,
17,
63,
29078,
627,
291,
423,
505,
18,
63,
29078,
267,
327,
644,
275,
359,
19,
10,
53,
11,
35,
12,
1520,
10,
53,
61,
267,
291,
423,
55,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
55,
297,
288,
2215,
2687,
277,
423,
1210,
63,
3572,
12,
291,
423,
5260,
627,
1520,
395,
288,
11130,
29,
277,
423,
4989,
63,
6498,
12,
288,
17029,
29,
549,
267,
776,
267,
327,
738,
275,
359,
19,
10,
53,
12,
738,
61,
267,
291,
423,
53,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
53,
297,
288,
2215,
2687,
277,
423,
5260,
627,
650,
12,
291,
423,
5260,
395,
288,
11130,
29,
277,
423,
31897,
63,
6498,
12,
288,
17029,
29,
549,
267,
776,
267,
327,
10671,
275,
359,
24,
10,
53,
12,
61,
267,
291,
423,
8160,
275,
291,
14,
525,
63,
3463,
8,
288,
536,
534,
8160,
297,
288,
2215,
2687,
277,
423,
5260,
627,
1695,
4706,
288,
11130,
534,
4250,
297,
288,
17029,
29,
549,
267,
776,
398,
327,
336,
63,
4308,
12,
336,
63,
2591,
12,
336,
63,
6883,
275,
359,
34,
12,
650,
10,
53,
61,
267,
291,
423,
17097,
275,
291,
423,
55,
3981,
520,
277,
423,
5260,
627,
650,
61,
267,
327,
330,
63,
4308,
12,
330,
63,
2591,
12,
330,
63,
6883,
275,
359,
34,
12,
650,
10,
53,
61,
267,
291,
423,
3289,
275,
291,
423,
8160,
1491,
277,
423,
5260,
627,
650,
61,
267,
327,
336,
63,
16079,
12,
336,
63,
90,
76,
12,
336,
63,
90,
84,
12,
336,
63,
23670,
275,
359,
34,
12,
841,
10,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
UnderGreen/ansible-modules-extras
|
notification/osx_say.py
|
161
|
2108
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2013, Michael DeHaan <michael@ansible.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/>.
DOCUMENTATION = '''
---
module: osx_say
version_added: "1.2"
short_description: Makes an OSX computer to speak.
description:
- makes an OS computer speak! Amuse your friends, annoy your coworkers!
notes:
- If you like this module, you may also be interested in the osx_say callback in the plugins/ directory of the source checkout.
options:
msg:
description:
What to say
required: true
voice:
description:
What voice to use
required: false
requirements: [ say ]
author:
- "Ansible Core Team"
- "Michael DeHaan (@mpdehaan)"
'''
EXAMPLES = '''
- local_action: osx_say msg="{{inventory_hostname}} is all done" voice=Zarvox
'''
DEFAULT_VOICE='Trinoids'
def say(module, msg, voice):
module.run_command(["/usr/bin/say", msg, "--voice=%s" % (voice)], check_rc=True)
def main():
module = AnsibleModule(
argument_spec=dict(
msg=dict(required=True),
voice=dict(required=False, default=DEFAULT_VOICE),
),
supports_check_mode=False
)
if not os.path.exists("/usr/bin/say"):
module.fail_json(msg="/usr/bin/say is not installed")
msg = module.params['msg']
voice = module.params['voice']
say(module, msg, voice)
module.exit_json(msg=msg, changed=False)
# import module snippets
from ansible.module_utils.basic import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
16922,
22453,
665,
22333,
32,
4853,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
88,
63,
19787,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
23365,
376,
32144,
24189,
370,
308,
8556,
14,
199,
1802,
26,
2043,
446,
7704,
376,
4403,
24189,
308,
8556,
1,
221,
437,
77,
1180,
2195,
26157,
12,
22984,
89,
2195,
512,
11009,
1,
199,
5983,
26,
2043,
446,
982,
1265,
2839,
642,
859,
12,
1265,
1443,
2597,
506,
22201,
315,
314,
747,
88,
63,
19787,
3233,
315,
314,
8963,
15,
2082,
402,
314,
1350,
15243,
14,
221,
199,
1419,
26,
523,
1499,
26,
272,
1369,
26,
489,
14791,
370,
14722,
272,
1415,
26,
2549,
523,
26563,
26,
272,
1369,
26,
489,
14791,
26563,
370,
675,
272,
1415,
26,
3055,
199,
7538,
26,
359,
14722,
1622,
199,
2502,
26,
5591,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
8593,
311,
24247,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
2257,
63,
1287,
26,
747,
88,
63,
19787,
1499,
628,
3638,
7212,
63,
4269,
4863,
365,
1006,
4224,
2,
26563,
29,
58,
285,
2392,
88,
199,
2344,
199,
199,
3472,
63,
10662,
4047,
534,
14064,
262,
1170,
83,
7,
199,
199,
318,
14722,
8,
578,
12,
1499,
12,
26563,
304,
272,
859,
14,
1065,
63,
1531,
5234,
15,
2647,
15,
1393,
15,
19787,
401,
1499,
12,
4320,
3789,
2458,
83,
2,
450,
334,
3789,
4360,
1104,
63,
1195,
29,
549,
9,
199,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
1499,
29,
807,
8,
2427,
29,
549,
395,
288,
26563,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
3472,
63,
10662,
4047,
395,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
797,
272,
776,
339,
340,
440,
747,
14,
515,
14,
2444,
4769,
2647,
15,
1393,
15,
19787,
2349,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9555,
2647,
15,
1393,
15,
19787,
365,
440,
4903,
531,
339,
1499,
257,
275,
859,
14,
1162,
459,
1328,
418,
272,
26563,
275,
859,
14,
1162,
459,
3789,
418,
339,
14722,
8,
578,
12,
1499,
12,
26563,
9,
339,
859,
14,
2224,
63,
1001,
8,
1328,
29,
1328,
12,
2896,
29,
797,
9,
9948,
199,
3,
492,
859,
19484,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
334,
67,
9,
6171,
12,
16922,
22453,
665,
22333,
32,
4853,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
88,
63,
19787,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
3612,
63,
1802,
26,
23365,
376,
32144,
24189,
370,
308,
8556,
14,
199,
1802,
26,
2043,
446,
7704,
376,
4403,
24189,
308,
8556,
1,
221,
437,
77,
1180,
2195,
26157,
12,
22984,
89,
2195,
512,
11009,
1,
199,
5983,
26,
2043,
446,
982,
1265,
2839,
642,
859,
12,
1265,
1443,
2597,
506,
22201,
315,
314,
747,
88,
63,
19787,
3233,
315,
314,
8963,
15,
2082,
402,
314,
1350,
15243,
14,
221,
199,
1419,
26,
523,
1499,
26,
272,
1369,
26,
489,
14791,
370,
14722,
272,
1415,
26,
2549,
523,
26563,
26,
272,
1369,
26,
489,
14791,
26563,
370,
675,
272,
1415,
26,
3055,
199,
7538,
26,
359,
14722,
1622,
199,
2502,
26,
5591,
446,
298,
10047,
11672,
11682,
2,
272,
446,
298,
45,
11781,
22453,
8593,
311,
24247,
2924,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
2257,
63,
1287,
26,
747,
88,
63,
19787,
1499,
628,
3638,
7212,
63,
4269,
4863,
365,
1006,
4224,
2,
26563,
29,
58,
285,
2392,
88,
199,
2344,
199,
199,
3472,
63,
10662,
4047,
534,
14064,
262,
1170,
83,
7,
199,
199,
318,
14722,
8,
578,
12,
1499,
12,
26563,
304,
272,
859,
14,
1065,
63,
1531,
5234,
15,
2647,
15,
1393,
15,
19787,
401,
1499,
12,
4320,
3789,
2458,
83,
2,
450,
334,
3789,
4360,
1104,
63,
1195,
29,
549,
9,
199,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
1499,
29,
807,
8,
2427,
29,
549,
395,
288,
26563,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
3472,
63,
10662,
4047,
395,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
797,
272,
776,
339,
340,
440,
747,
14,
515,
14,
2444,
4769,
2647,
15,
1393,
15,
19787,
2349,
267,
859,
14,
1633,
63,
1001,
8,
1328,
9555,
2647,
15,
1393,
15,
19787,
365,
440,
4903,
531,
339,
1499,
257,
275,
859,
14,
1162,
459,
1328,
418,
272,
26563,
275,
859,
14,
1162,
459,
3789,
418,
339,
14722,
8,
578,
12,
1499,
12,
26563,
9,
339,
859,
14,
2224,
63,
1001,
8,
1328,
29,
1328,
12,
2896,
29,
797,
9,
9948,
199,
3,
492,
859,
19484,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mglukhikh/intellij-community
|
python/lib/Lib/encodings/cp737.py
|
593
|
34937
|
""" Python Character Mapping Codec cp737 generated from 'VENDORS/MICSFT/PC/CP737.TXT' with gencodec.py.
"""#"
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_table)
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_table)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='cp737',
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: 0x0391, # GREEK CAPITAL LETTER ALPHA
0x0081: 0x0392, # GREEK CAPITAL LETTER BETA
0x0082: 0x0393, # GREEK CAPITAL LETTER GAMMA
0x0083: 0x0394, # GREEK CAPITAL LETTER DELTA
0x0084: 0x0395, # GREEK CAPITAL LETTER EPSILON
0x0085: 0x0396, # GREEK CAPITAL LETTER ZETA
0x0086: 0x0397, # GREEK CAPITAL LETTER ETA
0x0087: 0x0398, # GREEK CAPITAL LETTER THETA
0x0088: 0x0399, # GREEK CAPITAL LETTER IOTA
0x0089: 0x039a, # GREEK CAPITAL LETTER KAPPA
0x008a: 0x039b, # GREEK CAPITAL LETTER LAMDA
0x008b: 0x039c, # GREEK CAPITAL LETTER MU
0x008c: 0x039d, # GREEK CAPITAL LETTER NU
0x008d: 0x039e, # GREEK CAPITAL LETTER XI
0x008e: 0x039f, # GREEK CAPITAL LETTER OMICRON
0x008f: 0x03a0, # GREEK CAPITAL LETTER PI
0x0090: 0x03a1, # GREEK CAPITAL LETTER RHO
0x0091: 0x03a3, # GREEK CAPITAL LETTER SIGMA
0x0092: 0x03a4, # GREEK CAPITAL LETTER TAU
0x0093: 0x03a5, # GREEK CAPITAL LETTER UPSILON
0x0094: 0x03a6, # GREEK CAPITAL LETTER PHI
0x0095: 0x03a7, # GREEK CAPITAL LETTER CHI
0x0096: 0x03a8, # GREEK CAPITAL LETTER PSI
0x0097: 0x03a9, # GREEK CAPITAL LETTER OMEGA
0x0098: 0x03b1, # GREEK SMALL LETTER ALPHA
0x0099: 0x03b2, # GREEK SMALL LETTER BETA
0x009a: 0x03b3, # GREEK SMALL LETTER GAMMA
0x009b: 0x03b4, # GREEK SMALL LETTER DELTA
0x009c: 0x03b5, # GREEK SMALL LETTER EPSILON
0x009d: 0x03b6, # GREEK SMALL LETTER ZETA
0x009e: 0x03b7, # GREEK SMALL LETTER ETA
0x009f: 0x03b8, # GREEK SMALL LETTER THETA
0x00a0: 0x03b9, # GREEK SMALL LETTER IOTA
0x00a1: 0x03ba, # GREEK SMALL LETTER KAPPA
0x00a2: 0x03bb, # GREEK SMALL LETTER LAMDA
0x00a3: 0x03bc, # GREEK SMALL LETTER MU
0x00a4: 0x03bd, # GREEK SMALL LETTER NU
0x00a5: 0x03be, # GREEK SMALL LETTER XI
0x00a6: 0x03bf, # GREEK SMALL LETTER OMICRON
0x00a7: 0x03c0, # GREEK SMALL LETTER PI
0x00a8: 0x03c1, # GREEK SMALL LETTER RHO
0x00a9: 0x03c3, # GREEK SMALL LETTER SIGMA
0x00aa: 0x03c2, # GREEK SMALL LETTER FINAL SIGMA
0x00ab: 0x03c4, # GREEK SMALL LETTER TAU
0x00ac: 0x03c5, # GREEK SMALL LETTER UPSILON
0x00ad: 0x03c6, # GREEK SMALL LETTER PHI
0x00ae: 0x03c7, # GREEK SMALL LETTER CHI
0x00af: 0x03c8, # GREEK SMALL LETTER PSI
0x00b0: 0x2591, # LIGHT SHADE
0x00b1: 0x2592, # MEDIUM SHADE
0x00b2: 0x2593, # DARK SHADE
0x00b3: 0x2502, # BOX DRAWINGS LIGHT VERTICAL
0x00b4: 0x2524, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x00b5: 0x2561, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
0x00b6: 0x2562, # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
0x00b7: 0x2556, # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
0x00b8: 0x2555, # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
0x00b9: 0x2563, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x00ba: 0x2551, # BOX DRAWINGS DOUBLE VERTICAL
0x00bb: 0x2557, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x00bc: 0x255d, # BOX DRAWINGS DOUBLE UP AND LEFT
0x00bd: 0x255c, # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
0x00be: 0x255b, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
0x00bf: 0x2510, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x00c0: 0x2514, # BOX DRAWINGS LIGHT UP AND RIGHT
0x00c1: 0x2534, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x00c2: 0x252c, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x00c3: 0x251c, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x00c4: 0x2500, # BOX DRAWINGS LIGHT HORIZONTAL
0x00c5: 0x253c, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x00c6: 0x255e, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
0x00c7: 0x255f, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
0x00c8: 0x255a, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x00c9: 0x2554, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x00ca: 0x2569, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x00cb: 0x2566, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x00cc: 0x2560, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x00cd: 0x2550, # BOX DRAWINGS DOUBLE HORIZONTAL
0x00ce: 0x256c, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x00cf: 0x2567, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
0x00d0: 0x2568, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
0x00d1: 0x2564, # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
0x00d2: 0x2565, # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
0x00d3: 0x2559, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
0x00d4: 0x2558, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
0x00d5: 0x2552, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
0x00d6: 0x2553, # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
0x00d7: 0x256b, # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
0x00d8: 0x256a, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
0x00d9: 0x2518, # BOX DRAWINGS LIGHT UP AND LEFT
0x00da: 0x250c, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x00db: 0x2588, # FULL BLOCK
0x00dc: 0x2584, # LOWER HALF BLOCK
0x00dd: 0x258c, # LEFT HALF BLOCK
0x00de: 0x2590, # RIGHT HALF BLOCK
0x00df: 0x2580, # UPPER HALF BLOCK
0x00e0: 0x03c9, # GREEK SMALL LETTER OMEGA
0x00e1: 0x03ac, # GREEK SMALL LETTER ALPHA WITH TONOS
0x00e2: 0x03ad, # GREEK SMALL LETTER EPSILON WITH TONOS
0x00e3: 0x03ae, # GREEK SMALL LETTER ETA WITH TONOS
0x00e4: 0x03ca, # GREEK SMALL LETTER IOTA WITH DIALYTIKA
0x00e5: 0x03af, # GREEK SMALL LETTER IOTA WITH TONOS
0x00e6: 0x03cc, # GREEK SMALL LETTER OMICRON WITH TONOS
0x00e7: 0x03cd, # GREEK SMALL LETTER UPSILON WITH TONOS
0x00e8: 0x03cb, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA
0x00e9: 0x03ce, # GREEK SMALL LETTER OMEGA WITH TONOS
0x00ea: 0x0386, # GREEK CAPITAL LETTER ALPHA WITH TONOS
0x00eb: 0x0388, # GREEK CAPITAL LETTER EPSILON WITH TONOS
0x00ec: 0x0389, # GREEK CAPITAL LETTER ETA WITH TONOS
0x00ed: 0x038a, # GREEK CAPITAL LETTER IOTA WITH TONOS
0x00ee: 0x038c, # GREEK CAPITAL LETTER OMICRON WITH TONOS
0x00ef: 0x038e, # GREEK CAPITAL LETTER UPSILON WITH TONOS
0x00f0: 0x038f, # GREEK CAPITAL LETTER OMEGA WITH TONOS
0x00f1: 0x00b1, # PLUS-MINUS SIGN
0x00f2: 0x2265, # GREATER-THAN OR EQUAL TO
0x00f3: 0x2264, # LESS-THAN OR EQUAL TO
0x00f4: 0x03aa, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
0x00f5: 0x03ab, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
0x00f6: 0x00f7, # DIVISION SIGN
0x00f7: 0x2248, # ALMOST EQUAL TO
0x00f8: 0x00b0, # DEGREE SIGN
0x00f9: 0x2219, # BULLET OPERATOR
0x00fa: 0x00b7, # MIDDLE DOT
0x00fb: 0x221a, # SQUARE ROOT
0x00fc: 0x207f, # SUPERSCRIPT LATIN SMALL LETTER N
0x00fd: 0x00b2, # SUPERSCRIPT TWO
0x00fe: 0x25a0, # BLACK SQUARE
0x00ff: 0x00a0, # NO-BREAK SPACE
})
### Decoding Table
decoding_table = (
u'\x00' # 0x0000 -> NULL
u'\x01' # 0x0001 -> START OF HEADING
u'\x02' # 0x0002 -> START OF TEXT
u'\x03' # 0x0003 -> END OF TEXT
u'\x04' # 0x0004 -> END OF TRANSMISSION
u'\x05' # 0x0005 -> ENQUIRY
u'\x06' # 0x0006 -> ACKNOWLEDGE
u'\x07' # 0x0007 -> BELL
u'\x08' # 0x0008 -> BACKSPACE
u'\t' # 0x0009 -> HORIZONTAL TABULATION
u'\n' # 0x000a -> LINE FEED
u'\x0b' # 0x000b -> VERTICAL TABULATION
u'\x0c' # 0x000c -> FORM FEED
u'\r' # 0x000d -> CARRIAGE RETURN
u'\x0e' # 0x000e -> SHIFT OUT
u'\x0f' # 0x000f -> SHIFT IN
u'\x10' # 0x0010 -> DATA LINK ESCAPE
u'\x11' # 0x0011 -> DEVICE CONTROL ONE
u'\x12' # 0x0012 -> DEVICE CONTROL TWO
u'\x13' # 0x0013 -> DEVICE CONTROL THREE
u'\x14' # 0x0014 -> DEVICE CONTROL FOUR
u'\x15' # 0x0015 -> NEGATIVE ACKNOWLEDGE
u'\x16' # 0x0016 -> SYNCHRONOUS IDLE
u'\x17' # 0x0017 -> END OF TRANSMISSION BLOCK
u'\x18' # 0x0018 -> CANCEL
u'\x19' # 0x0019 -> END OF MEDIUM
u'\x1a' # 0x001a -> SUBSTITUTE
u'\x1b' # 0x001b -> ESCAPE
u'\x1c' # 0x001c -> FILE SEPARATOR
u'\x1d' # 0x001d -> GROUP SEPARATOR
u'\x1e' # 0x001e -> RECORD SEPARATOR
u'\x1f' # 0x001f -> UNIT SEPARATOR
u' ' # 0x0020 -> SPACE
u'!' # 0x0021 -> EXCLAMATION MARK
u'"' # 0x0022 -> QUOTATION MARK
u'#' # 0x0023 -> NUMBER SIGN
u'$' # 0x0024 -> DOLLAR SIGN
u'%' # 0x0025 -> PERCENT SIGN
u'&' # 0x0026 -> AMPERSAND
u"'" # 0x0027 -> APOSTROPHE
u'(' # 0x0028 -> LEFT PARENTHESIS
u')' # 0x0029 -> RIGHT PARENTHESIS
u'*' # 0x002a -> ASTERISK
u'+' # 0x002b -> PLUS SIGN
u',' # 0x002c -> COMMA
u'-' # 0x002d -> HYPHEN-MINUS
u'.' # 0x002e -> FULL STOP
u'/' # 0x002f -> SOLIDUS
u'0' # 0x0030 -> DIGIT ZERO
u'1' # 0x0031 -> DIGIT ONE
u'2' # 0x0032 -> DIGIT TWO
u'3' # 0x0033 -> DIGIT THREE
u'4' # 0x0034 -> DIGIT FOUR
u'5' # 0x0035 -> DIGIT FIVE
u'6' # 0x0036 -> DIGIT SIX
u'7' # 0x0037 -> DIGIT SEVEN
u'8' # 0x0038 -> DIGIT EIGHT
u'9' # 0x0039 -> DIGIT NINE
u':' # 0x003a -> COLON
u';' # 0x003b -> SEMICOLON
u'<' # 0x003c -> LESS-THAN SIGN
u'=' # 0x003d -> EQUALS SIGN
u'>' # 0x003e -> GREATER-THAN SIGN
u'?' # 0x003f -> QUESTION MARK
u'@' # 0x0040 -> COMMERCIAL AT
u'A' # 0x0041 -> LATIN CAPITAL LETTER A
u'B' # 0x0042 -> LATIN CAPITAL LETTER B
u'C' # 0x0043 -> LATIN CAPITAL LETTER C
u'D' # 0x0044 -> LATIN CAPITAL LETTER D
u'E' # 0x0045 -> LATIN CAPITAL LETTER E
u'F' # 0x0046 -> LATIN CAPITAL LETTER F
u'G' # 0x0047 -> LATIN CAPITAL LETTER G
u'H' # 0x0048 -> LATIN CAPITAL LETTER H
u'I' # 0x0049 -> LATIN CAPITAL LETTER I
u'J' # 0x004a -> LATIN CAPITAL LETTER J
u'K' # 0x004b -> LATIN CAPITAL LETTER K
u'L' # 0x004c -> LATIN CAPITAL LETTER L
u'M' # 0x004d -> LATIN CAPITAL LETTER M
u'N' # 0x004e -> LATIN CAPITAL LETTER N
u'O' # 0x004f -> LATIN CAPITAL LETTER O
u'P' # 0x0050 -> LATIN CAPITAL LETTER P
u'Q' # 0x0051 -> LATIN CAPITAL LETTER Q
u'R' # 0x0052 -> LATIN CAPITAL LETTER R
u'S' # 0x0053 -> LATIN CAPITAL LETTER S
u'T' # 0x0054 -> LATIN CAPITAL LETTER T
u'U' # 0x0055 -> LATIN CAPITAL LETTER U
u'V' # 0x0056 -> LATIN CAPITAL LETTER V
u'W' # 0x0057 -> LATIN CAPITAL LETTER W
u'X' # 0x0058 -> LATIN CAPITAL LETTER X
u'Y' # 0x0059 -> LATIN CAPITAL LETTER Y
u'Z' # 0x005a -> LATIN CAPITAL LETTER Z
u'[' # 0x005b -> LEFT SQUARE BRACKET
u'\\' # 0x005c -> REVERSE SOLIDUS
u']' # 0x005d -> RIGHT SQUARE BRACKET
u'^' # 0x005e -> CIRCUMFLEX ACCENT
u'_' # 0x005f -> LOW LINE
u'`' # 0x0060 -> GRAVE ACCENT
u'a' # 0x0061 -> LATIN SMALL LETTER A
u'b' # 0x0062 -> LATIN SMALL LETTER B
u'c' # 0x0063 -> LATIN SMALL LETTER C
u'd' # 0x0064 -> LATIN SMALL LETTER D
u'e' # 0x0065 -> LATIN SMALL LETTER E
u'f' # 0x0066 -> LATIN SMALL LETTER F
u'g' # 0x0067 -> LATIN SMALL LETTER G
u'h' # 0x0068 -> LATIN SMALL LETTER H
u'i' # 0x0069 -> LATIN SMALL LETTER I
u'j' # 0x006a -> LATIN SMALL LETTER J
u'k' # 0x006b -> LATIN SMALL LETTER K
u'l' # 0x006c -> LATIN SMALL LETTER L
u'm' # 0x006d -> LATIN SMALL LETTER M
u'n' # 0x006e -> LATIN SMALL LETTER N
u'o' # 0x006f -> LATIN SMALL LETTER O
u'p' # 0x0070 -> LATIN SMALL LETTER P
u'q' # 0x0071 -> LATIN SMALL LETTER Q
u'r' # 0x0072 -> LATIN SMALL LETTER R
u's' # 0x0073 -> LATIN SMALL LETTER S
u't' # 0x0074 -> LATIN SMALL LETTER T
u'u' # 0x0075 -> LATIN SMALL LETTER U
u'v' # 0x0076 -> LATIN SMALL LETTER V
u'w' # 0x0077 -> LATIN SMALL LETTER W
u'x' # 0x0078 -> LATIN SMALL LETTER X
u'y' # 0x0079 -> LATIN SMALL LETTER Y
u'z' # 0x007a -> LATIN SMALL LETTER Z
u'{' # 0x007b -> LEFT CURLY BRACKET
u'|' # 0x007c -> VERTICAL LINE
u'}' # 0x007d -> RIGHT CURLY BRACKET
u'~' # 0x007e -> TILDE
u'\x7f' # 0x007f -> DELETE
u'\u0391' # 0x0080 -> GREEK CAPITAL LETTER ALPHA
u'\u0392' # 0x0081 -> GREEK CAPITAL LETTER BETA
u'\u0393' # 0x0082 -> GREEK CAPITAL LETTER GAMMA
u'\u0394' # 0x0083 -> GREEK CAPITAL LETTER DELTA
u'\u0395' # 0x0084 -> GREEK CAPITAL LETTER EPSILON
u'\u0396' # 0x0085 -> GREEK CAPITAL LETTER ZETA
u'\u0397' # 0x0086 -> GREEK CAPITAL LETTER ETA
u'\u0398' # 0x0087 -> GREEK CAPITAL LETTER THETA
u'\u0399' # 0x0088 -> GREEK CAPITAL LETTER IOTA
u'\u039a' # 0x0089 -> GREEK CAPITAL LETTER KAPPA
u'\u039b' # 0x008a -> GREEK CAPITAL LETTER LAMDA
u'\u039c' # 0x008b -> GREEK CAPITAL LETTER MU
u'\u039d' # 0x008c -> GREEK CAPITAL LETTER NU
u'\u039e' # 0x008d -> GREEK CAPITAL LETTER XI
u'\u039f' # 0x008e -> GREEK CAPITAL LETTER OMICRON
u'\u03a0' # 0x008f -> GREEK CAPITAL LETTER PI
u'\u03a1' # 0x0090 -> GREEK CAPITAL LETTER RHO
u'\u03a3' # 0x0091 -> GREEK CAPITAL LETTER SIGMA
u'\u03a4' # 0x0092 -> GREEK CAPITAL LETTER TAU
u'\u03a5' # 0x0093 -> GREEK CAPITAL LETTER UPSILON
u'\u03a6' # 0x0094 -> GREEK CAPITAL LETTER PHI
u'\u03a7' # 0x0095 -> GREEK CAPITAL LETTER CHI
u'\u03a8' # 0x0096 -> GREEK CAPITAL LETTER PSI
u'\u03a9' # 0x0097 -> GREEK CAPITAL LETTER OMEGA
u'\u03b1' # 0x0098 -> GREEK SMALL LETTER ALPHA
u'\u03b2' # 0x0099 -> GREEK SMALL LETTER BETA
u'\u03b3' # 0x009a -> GREEK SMALL LETTER GAMMA
u'\u03b4' # 0x009b -> GREEK SMALL LETTER DELTA
u'\u03b5' # 0x009c -> GREEK SMALL LETTER EPSILON
u'\u03b6' # 0x009d -> GREEK SMALL LETTER ZETA
u'\u03b7' # 0x009e -> GREEK SMALL LETTER ETA
u'\u03b8' # 0x009f -> GREEK SMALL LETTER THETA
u'\u03b9' # 0x00a0 -> GREEK SMALL LETTER IOTA
u'\u03ba' # 0x00a1 -> GREEK SMALL LETTER KAPPA
u'\u03bb' # 0x00a2 -> GREEK SMALL LETTER LAMDA
u'\u03bc' # 0x00a3 -> GREEK SMALL LETTER MU
u'\u03bd' # 0x00a4 -> GREEK SMALL LETTER NU
u'\u03be' # 0x00a5 -> GREEK SMALL LETTER XI
u'\u03bf' # 0x00a6 -> GREEK SMALL LETTER OMICRON
u'\u03c0' # 0x00a7 -> GREEK SMALL LETTER PI
u'\u03c1' # 0x00a8 -> GREEK SMALL LETTER RHO
u'\u03c3' # 0x00a9 -> GREEK SMALL LETTER SIGMA
u'\u03c2' # 0x00aa -> GREEK SMALL LETTER FINAL SIGMA
u'\u03c4' # 0x00ab -> GREEK SMALL LETTER TAU
u'\u03c5' # 0x00ac -> GREEK SMALL LETTER UPSILON
u'\u03c6' # 0x00ad -> GREEK SMALL LETTER PHI
u'\u03c7' # 0x00ae -> GREEK SMALL LETTER CHI
u'\u03c8' # 0x00af -> GREEK SMALL LETTER PSI
u'\u2591' # 0x00b0 -> LIGHT SHADE
u'\u2592' # 0x00b1 -> MEDIUM SHADE
u'\u2593' # 0x00b2 -> DARK SHADE
u'\u2502' # 0x00b3 -> BOX DRAWINGS LIGHT VERTICAL
u'\u2524' # 0x00b4 -> BOX DRAWINGS LIGHT VERTICAL AND LEFT
u'\u2561' # 0x00b5 -> BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
u'\u2562' # 0x00b6 -> BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
u'\u2556' # 0x00b7 -> BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
u'\u2555' # 0x00b8 -> BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
u'\u2563' # 0x00b9 -> BOX DRAWINGS DOUBLE VERTICAL AND LEFT
u'\u2551' # 0x00ba -> BOX DRAWINGS DOUBLE VERTICAL
u'\u2557' # 0x00bb -> BOX DRAWINGS DOUBLE DOWN AND LEFT
u'\u255d' # 0x00bc -> BOX DRAWINGS DOUBLE UP AND LEFT
u'\u255c' # 0x00bd -> BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
u'\u255b' # 0x00be -> BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
u'\u2510' # 0x00bf -> BOX DRAWINGS LIGHT DOWN AND LEFT
u'\u2514' # 0x00c0 -> BOX DRAWINGS LIGHT UP AND RIGHT
u'\u2534' # 0x00c1 -> BOX DRAWINGS LIGHT UP AND HORIZONTAL
u'\u252c' # 0x00c2 -> BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
u'\u251c' # 0x00c3 -> BOX DRAWINGS LIGHT VERTICAL AND RIGHT
u'\u2500' # 0x00c4 -> BOX DRAWINGS LIGHT HORIZONTAL
u'\u253c' # 0x00c5 -> BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
u'\u255e' # 0x00c6 -> BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
u'\u255f' # 0x00c7 -> BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
u'\u255a' # 0x00c8 -> BOX DRAWINGS DOUBLE UP AND RIGHT
u'\u2554' # 0x00c9 -> BOX DRAWINGS DOUBLE DOWN AND RIGHT
u'\u2569' # 0x00ca -> BOX DRAWINGS DOUBLE UP AND HORIZONTAL
u'\u2566' # 0x00cb -> BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
u'\u2560' # 0x00cc -> BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
u'\u2550' # 0x00cd -> BOX DRAWINGS DOUBLE HORIZONTAL
u'\u256c' # 0x00ce -> BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
u'\u2567' # 0x00cf -> BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
u'\u2568' # 0x00d0 -> BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
u'\u2564' # 0x00d1 -> BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
u'\u2565' # 0x00d2 -> BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
u'\u2559' # 0x00d3 -> BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
u'\u2558' # 0x00d4 -> BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
u'\u2552' # 0x00d5 -> BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
u'\u2553' # 0x00d6 -> BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
u'\u256b' # 0x00d7 -> BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
u'\u256a' # 0x00d8 -> BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
u'\u2518' # 0x00d9 -> BOX DRAWINGS LIGHT UP AND LEFT
u'\u250c' # 0x00da -> BOX DRAWINGS LIGHT DOWN AND RIGHT
u'\u2588' # 0x00db -> FULL BLOCK
u'\u2584' # 0x00dc -> LOWER HALF BLOCK
u'\u258c' # 0x00dd -> LEFT HALF BLOCK
u'\u2590' # 0x00de -> RIGHT HALF BLOCK
u'\u2580' # 0x00df -> UPPER HALF BLOCK
u'\u03c9' # 0x00e0 -> GREEK SMALL LETTER OMEGA
u'\u03ac' # 0x00e1 -> GREEK SMALL LETTER ALPHA WITH TONOS
u'\u03ad' # 0x00e2 -> GREEK SMALL LETTER EPSILON WITH TONOS
u'\u03ae' # 0x00e3 -> GREEK SMALL LETTER ETA WITH TONOS
u'\u03ca' # 0x00e4 -> GREEK SMALL LETTER IOTA WITH DIALYTIKA
u'\u03af' # 0x00e5 -> GREEK SMALL LETTER IOTA WITH TONOS
u'\u03cc' # 0x00e6 -> GREEK SMALL LETTER OMICRON WITH TONOS
u'\u03cd' # 0x00e7 -> GREEK SMALL LETTER UPSILON WITH TONOS
u'\u03cb' # 0x00e8 -> GREEK SMALL LETTER UPSILON WITH DIALYTIKA
u'\u03ce' # 0x00e9 -> GREEK SMALL LETTER OMEGA WITH TONOS
u'\u0386' # 0x00ea -> GREEK CAPITAL LETTER ALPHA WITH TONOS
u'\u0388' # 0x00eb -> GREEK CAPITAL LETTER EPSILON WITH TONOS
u'\u0389' # 0x00ec -> GREEK CAPITAL LETTER ETA WITH TONOS
u'\u038a' # 0x00ed -> GREEK CAPITAL LETTER IOTA WITH TONOS
u'\u038c' # 0x00ee -> GREEK CAPITAL LETTER OMICRON WITH TONOS
u'\u038e' # 0x00ef -> GREEK CAPITAL LETTER UPSILON WITH TONOS
u'\u038f' # 0x00f0 -> GREEK CAPITAL LETTER OMEGA WITH TONOS
u'\xb1' # 0x00f1 -> PLUS-MINUS SIGN
u'\u2265' # 0x00f2 -> GREATER-THAN OR EQUAL TO
u'\u2264' # 0x00f3 -> LESS-THAN OR EQUAL TO
u'\u03aa' # 0x00f4 -> GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
u'\u03ab' # 0x00f5 -> GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
u'\xf7' # 0x00f6 -> DIVISION SIGN
u'\u2248' # 0x00f7 -> ALMOST EQUAL TO
u'\xb0' # 0x00f8 -> DEGREE SIGN
u'\u2219' # 0x00f9 -> BULLET OPERATOR
u'\xb7' # 0x00fa -> MIDDLE DOT
u'\u221a' # 0x00fb -> SQUARE ROOT
u'\u207f' # 0x00fc -> SUPERSCRIPT LATIN SMALL LETTER N
u'\xb2' # 0x00fd -> SUPERSCRIPT TWO
u'\u25a0' # 0x00fe -> BLACK SQUARE
u'\xa0' # 0x00ff -> NO-BREAK SPACE
)
### Encoding Map
encoding_map = {
0x0000: 0x0000, # NULL
0x0001: 0x0001, # START OF HEADING
0x0002: 0x0002, # START OF TEXT
0x0003: 0x0003, # END OF TEXT
0x0004: 0x0004, # END OF TRANSMISSION
0x0005: 0x0005, # ENQUIRY
0x0006: 0x0006, # ACKNOWLEDGE
0x0007: 0x0007, # BELL
0x0008: 0x0008, # BACKSPACE
0x0009: 0x0009, # HORIZONTAL TABULATION
0x000a: 0x000a, # LINE FEED
0x000b: 0x000b, # VERTICAL TABULATION
0x000c: 0x000c, # FORM FEED
0x000d: 0x000d, # CARRIAGE RETURN
0x000e: 0x000e, # SHIFT OUT
0x000f: 0x000f, # SHIFT IN
0x0010: 0x0010, # DATA LINK ESCAPE
0x0011: 0x0011, # DEVICE CONTROL ONE
0x0012: 0x0012, # DEVICE CONTROL TWO
0x0013: 0x0013, # DEVICE CONTROL THREE
0x0014: 0x0014, # DEVICE CONTROL FOUR
0x0015: 0x0015, # NEGATIVE ACKNOWLEDGE
0x0016: 0x0016, # SYNCHRONOUS IDLE
0x0017: 0x0017, # END OF TRANSMISSION BLOCK
0x0018: 0x0018, # CANCEL
0x0019: 0x0019, # END OF MEDIUM
0x001a: 0x001a, # SUBSTITUTE
0x001b: 0x001b, # ESCAPE
0x001c: 0x001c, # FILE SEPARATOR
0x001d: 0x001d, # GROUP SEPARATOR
0x001e: 0x001e, # RECORD SEPARATOR
0x001f: 0x001f, # UNIT SEPARATOR
0x0020: 0x0020, # SPACE
0x0021: 0x0021, # EXCLAMATION MARK
0x0022: 0x0022, # QUOTATION MARK
0x0023: 0x0023, # NUMBER SIGN
0x0024: 0x0024, # DOLLAR SIGN
0x0025: 0x0025, # PERCENT SIGN
0x0026: 0x0026, # AMPERSAND
0x0027: 0x0027, # APOSTROPHE
0x0028: 0x0028, # LEFT PARENTHESIS
0x0029: 0x0029, # RIGHT PARENTHESIS
0x002a: 0x002a, # ASTERISK
0x002b: 0x002b, # PLUS SIGN
0x002c: 0x002c, # COMMA
0x002d: 0x002d, # HYPHEN-MINUS
0x002e: 0x002e, # FULL STOP
0x002f: 0x002f, # SOLIDUS
0x0030: 0x0030, # DIGIT ZERO
0x0031: 0x0031, # DIGIT ONE
0x0032: 0x0032, # DIGIT TWO
0x0033: 0x0033, # DIGIT THREE
0x0034: 0x0034, # DIGIT FOUR
0x0035: 0x0035, # DIGIT FIVE
0x0036: 0x0036, # DIGIT SIX
0x0037: 0x0037, # DIGIT SEVEN
0x0038: 0x0038, # DIGIT EIGHT
0x0039: 0x0039, # DIGIT NINE
0x003a: 0x003a, # COLON
0x003b: 0x003b, # SEMICOLON
0x003c: 0x003c, # LESS-THAN SIGN
0x003d: 0x003d, # EQUALS SIGN
0x003e: 0x003e, # GREATER-THAN SIGN
0x003f: 0x003f, # QUESTION MARK
0x0040: 0x0040, # COMMERCIAL AT
0x0041: 0x0041, # LATIN CAPITAL LETTER A
0x0042: 0x0042, # LATIN CAPITAL LETTER B
0x0043: 0x0043, # LATIN CAPITAL LETTER C
0x0044: 0x0044, # LATIN CAPITAL LETTER D
0x0045: 0x0045, # LATIN CAPITAL LETTER E
0x0046: 0x0046, # LATIN CAPITAL LETTER F
0x0047: 0x0047, # LATIN CAPITAL LETTER G
0x0048: 0x0048, # LATIN CAPITAL LETTER H
0x0049: 0x0049, # LATIN CAPITAL LETTER I
0x004a: 0x004a, # LATIN CAPITAL LETTER J
0x004b: 0x004b, # LATIN CAPITAL LETTER K
0x004c: 0x004c, # LATIN CAPITAL LETTER L
0x004d: 0x004d, # LATIN CAPITAL LETTER M
0x004e: 0x004e, # LATIN CAPITAL LETTER N
0x004f: 0x004f, # LATIN CAPITAL LETTER O
0x0050: 0x0050, # LATIN CAPITAL LETTER P
0x0051: 0x0051, # LATIN CAPITAL LETTER Q
0x0052: 0x0052, # LATIN CAPITAL LETTER R
0x0053: 0x0053, # LATIN CAPITAL LETTER S
0x0054: 0x0054, # LATIN CAPITAL LETTER T
0x0055: 0x0055, # LATIN CAPITAL LETTER U
0x0056: 0x0056, # LATIN CAPITAL LETTER V
0x0057: 0x0057, # LATIN CAPITAL LETTER W
0x0058: 0x0058, # LATIN CAPITAL LETTER X
0x0059: 0x0059, # LATIN CAPITAL LETTER Y
0x005a: 0x005a, # LATIN CAPITAL LETTER Z
0x005b: 0x005b, # LEFT SQUARE BRACKET
0x005c: 0x005c, # REVERSE SOLIDUS
0x005d: 0x005d, # RIGHT SQUARE BRACKET
0x005e: 0x005e, # CIRCUMFLEX ACCENT
0x005f: 0x005f, # LOW LINE
0x0060: 0x0060, # GRAVE ACCENT
0x0061: 0x0061, # LATIN SMALL LETTER A
0x0062: 0x0062, # LATIN SMALL LETTER B
0x0063: 0x0063, # LATIN SMALL LETTER C
0x0064: 0x0064, # LATIN SMALL LETTER D
0x0065: 0x0065, # LATIN SMALL LETTER E
0x0066: 0x0066, # LATIN SMALL LETTER F
0x0067: 0x0067, # LATIN SMALL LETTER G
0x0068: 0x0068, # LATIN SMALL LETTER H
0x0069: 0x0069, # LATIN SMALL LETTER I
0x006a: 0x006a, # LATIN SMALL LETTER J
0x006b: 0x006b, # LATIN SMALL LETTER K
0x006c: 0x006c, # LATIN SMALL LETTER L
0x006d: 0x006d, # LATIN SMALL LETTER M
0x006e: 0x006e, # LATIN SMALL LETTER N
0x006f: 0x006f, # LATIN SMALL LETTER O
0x0070: 0x0070, # LATIN SMALL LETTER P
0x0071: 0x0071, # LATIN SMALL LETTER Q
0x0072: 0x0072, # LATIN SMALL LETTER R
0x0073: 0x0073, # LATIN SMALL LETTER S
0x0074: 0x0074, # LATIN SMALL LETTER T
0x0075: 0x0075, # LATIN SMALL LETTER U
0x0076: 0x0076, # LATIN SMALL LETTER V
0x0077: 0x0077, # LATIN SMALL LETTER W
0x0078: 0x0078, # LATIN SMALL LETTER X
0x0079: 0x0079, # LATIN SMALL LETTER Y
0x007a: 0x007a, # LATIN SMALL LETTER Z
0x007b: 0x007b, # LEFT CURLY BRACKET
0x007c: 0x007c, # VERTICAL LINE
0x007d: 0x007d, # RIGHT CURLY BRACKET
0x007e: 0x007e, # TILDE
0x007f: 0x007f, # DELETE
0x00a0: 0x00ff, # NO-BREAK SPACE
0x00b0: 0x00f8, # DEGREE SIGN
0x00b1: 0x00f1, # PLUS-MINUS SIGN
0x00b2: 0x00fd, # SUPERSCRIPT TWO
0x00b7: 0x00fa, # MIDDLE DOT
0x00f7: 0x00f6, # DIVISION SIGN
0x0386: 0x00ea, # GREEK CAPITAL LETTER ALPHA WITH TONOS
0x0388: 0x00eb, # GREEK CAPITAL LETTER EPSILON WITH TONOS
0x0389: 0x00ec, # GREEK CAPITAL LETTER ETA WITH TONOS
0x038a: 0x00ed, # GREEK CAPITAL LETTER IOTA WITH TONOS
0x038c: 0x00ee, # GREEK CAPITAL LETTER OMICRON WITH TONOS
0x038e: 0x00ef, # GREEK CAPITAL LETTER UPSILON WITH TONOS
0x038f: 0x00f0, # GREEK CAPITAL LETTER OMEGA WITH TONOS
0x0391: 0x0080, # GREEK CAPITAL LETTER ALPHA
0x0392: 0x0081, # GREEK CAPITAL LETTER BETA
0x0393: 0x0082, # GREEK CAPITAL LETTER GAMMA
0x0394: 0x0083, # GREEK CAPITAL LETTER DELTA
0x0395: 0x0084, # GREEK CAPITAL LETTER EPSILON
0x0396: 0x0085, # GREEK CAPITAL LETTER ZETA
0x0397: 0x0086, # GREEK CAPITAL LETTER ETA
0x0398: 0x0087, # GREEK CAPITAL LETTER THETA
0x0399: 0x0088, # GREEK CAPITAL LETTER IOTA
0x039a: 0x0089, # GREEK CAPITAL LETTER KAPPA
0x039b: 0x008a, # GREEK CAPITAL LETTER LAMDA
0x039c: 0x008b, # GREEK CAPITAL LETTER MU
0x039d: 0x008c, # GREEK CAPITAL LETTER NU
0x039e: 0x008d, # GREEK CAPITAL LETTER XI
0x039f: 0x008e, # GREEK CAPITAL LETTER OMICRON
0x03a0: 0x008f, # GREEK CAPITAL LETTER PI
0x03a1: 0x0090, # GREEK CAPITAL LETTER RHO
0x03a3: 0x0091, # GREEK CAPITAL LETTER SIGMA
0x03a4: 0x0092, # GREEK CAPITAL LETTER TAU
0x03a5: 0x0093, # GREEK CAPITAL LETTER UPSILON
0x03a6: 0x0094, # GREEK CAPITAL LETTER PHI
0x03a7: 0x0095, # GREEK CAPITAL LETTER CHI
0x03a8: 0x0096, # GREEK CAPITAL LETTER PSI
0x03a9: 0x0097, # GREEK CAPITAL LETTER OMEGA
0x03aa: 0x00f4, # GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
0x03ab: 0x00f5, # GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
0x03ac: 0x00e1, # GREEK SMALL LETTER ALPHA WITH TONOS
0x03ad: 0x00e2, # GREEK SMALL LETTER EPSILON WITH TONOS
0x03ae: 0x00e3, # GREEK SMALL LETTER ETA WITH TONOS
0x03af: 0x00e5, # GREEK SMALL LETTER IOTA WITH TONOS
0x03b1: 0x0098, # GREEK SMALL LETTER ALPHA
0x03b2: 0x0099, # GREEK SMALL LETTER BETA
0x03b3: 0x009a, # GREEK SMALL LETTER GAMMA
0x03b4: 0x009b, # GREEK SMALL LETTER DELTA
0x03b5: 0x009c, # GREEK SMALL LETTER EPSILON
0x03b6: 0x009d, # GREEK SMALL LETTER ZETA
0x03b7: 0x009e, # GREEK SMALL LETTER ETA
0x03b8: 0x009f, # GREEK SMALL LETTER THETA
0x03b9: 0x00a0, # GREEK SMALL LETTER IOTA
0x03ba: 0x00a1, # GREEK SMALL LETTER KAPPA
0x03bb: 0x00a2, # GREEK SMALL LETTER LAMDA
0x03bc: 0x00a3, # GREEK SMALL LETTER MU
0x03bd: 0x00a4, # GREEK SMALL LETTER NU
0x03be: 0x00a5, # GREEK SMALL LETTER XI
0x03bf: 0x00a6, # GREEK SMALL LETTER OMICRON
0x03c0: 0x00a7, # GREEK SMALL LETTER PI
0x03c1: 0x00a8, # GREEK SMALL LETTER RHO
0x03c2: 0x00aa, # GREEK SMALL LETTER FINAL SIGMA
0x03c3: 0x00a9, # GREEK SMALL LETTER SIGMA
0x03c4: 0x00ab, # GREEK SMALL LETTER TAU
0x03c5: 0x00ac, # GREEK SMALL LETTER UPSILON
0x03c6: 0x00ad, # GREEK SMALL LETTER PHI
0x03c7: 0x00ae, # GREEK SMALL LETTER CHI
0x03c8: 0x00af, # GREEK SMALL LETTER PSI
0x03c9: 0x00e0, # GREEK SMALL LETTER OMEGA
0x03ca: 0x00e4, # GREEK SMALL LETTER IOTA WITH DIALYTIKA
0x03cb: 0x00e8, # GREEK SMALL LETTER UPSILON WITH DIALYTIKA
0x03cc: 0x00e6, # GREEK SMALL LETTER OMICRON WITH TONOS
0x03cd: 0x00e7, # GREEK SMALL LETTER UPSILON WITH TONOS
0x03ce: 0x00e9, # GREEK SMALL LETTER OMEGA WITH TONOS
0x207f: 0x00fc, # SUPERSCRIPT LATIN SMALL LETTER N
0x2219: 0x00f9, # BULLET OPERATOR
0x221a: 0x00fb, # SQUARE ROOT
0x2248: 0x00f7, # ALMOST EQUAL TO
0x2264: 0x00f3, # LESS-THAN OR EQUAL TO
0x2265: 0x00f2, # GREATER-THAN OR EQUAL TO
0x2500: 0x00c4, # BOX DRAWINGS LIGHT HORIZONTAL
0x2502: 0x00b3, # BOX DRAWINGS LIGHT VERTICAL
0x250c: 0x00da, # BOX DRAWINGS LIGHT DOWN AND RIGHT
0x2510: 0x00bf, # BOX DRAWINGS LIGHT DOWN AND LEFT
0x2514: 0x00c0, # BOX DRAWINGS LIGHT UP AND RIGHT
0x2518: 0x00d9, # BOX DRAWINGS LIGHT UP AND LEFT
0x251c: 0x00c3, # BOX DRAWINGS LIGHT VERTICAL AND RIGHT
0x2524: 0x00b4, # BOX DRAWINGS LIGHT VERTICAL AND LEFT
0x252c: 0x00c2, # BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
0x2534: 0x00c1, # BOX DRAWINGS LIGHT UP AND HORIZONTAL
0x253c: 0x00c5, # BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
0x2550: 0x00cd, # BOX DRAWINGS DOUBLE HORIZONTAL
0x2551: 0x00ba, # BOX DRAWINGS DOUBLE VERTICAL
0x2552: 0x00d5, # BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
0x2553: 0x00d6, # BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
0x2554: 0x00c9, # BOX DRAWINGS DOUBLE DOWN AND RIGHT
0x2555: 0x00b8, # BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
0x2556: 0x00b7, # BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
0x2557: 0x00bb, # BOX DRAWINGS DOUBLE DOWN AND LEFT
0x2558: 0x00d4, # BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
0x2559: 0x00d3, # BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
0x255a: 0x00c8, # BOX DRAWINGS DOUBLE UP AND RIGHT
0x255b: 0x00be, # BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
0x255c: 0x00bd, # BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
0x255d: 0x00bc, # BOX DRAWINGS DOUBLE UP AND LEFT
0x255e: 0x00c6, # BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
0x255f: 0x00c7, # BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
0x2560: 0x00cc, # BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
0x2561: 0x00b5, # BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
0x2562: 0x00b6, # BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
0x2563: 0x00b9, # BOX DRAWINGS DOUBLE VERTICAL AND LEFT
0x2564: 0x00d1, # BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
0x2565: 0x00d2, # BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
0x2566: 0x00cb, # BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
0x2567: 0x00cf, # BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
0x2568: 0x00d0, # BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
0x2569: 0x00ca, # BOX DRAWINGS DOUBLE UP AND HORIZONTAL
0x256a: 0x00d8, # BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
0x256b: 0x00d7, # BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
0x256c: 0x00ce, # BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
0x2580: 0x00df, # UPPER HALF BLOCK
0x2584: 0x00dc, # LOWER HALF BLOCK
0x2588: 0x00db, # FULL BLOCK
0x258c: 0x00dd, # LEFT HALF BLOCK
0x2590: 0x00de, # RIGHT HALF BLOCK
0x2591: 0x00b0, # LIGHT SHADE
0x2592: 0x00b1, # MEDIUM SHADE
0x2593: 0x00b2, # DARK SHADE
0x25a0: 0x00fe, # BLACK SQUARE
}
|
apache-2.0
|
[
624,
2018,
17660,
12340,
13732,
7667,
29045,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
29045,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
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,
1224,
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,
1224,
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,
1850,
29045,
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,
272,
378,
88,
23686,
26,
378,
88,
10005,
17,
12,
258,
327,
221,
7571,
2678,
1578,
31278,
272,
378,
88,
383,
2835,
26,
378,
88,
10005,
18,
12,
258,
327,
221,
7571,
2678,
1578,
699,
15808,
272,
378,
88,
383,
2564,
26,
378,
88,
10005,
19,
12,
258,
327,
221,
7571,
2678,
1578,
598,
1156,
2054,
272,
378,
88,
383,
2658,
26,
378,
88,
10005,
20,
12,
258,
327,
221,
7571,
2678,
1578,
12355,
6166,
272,
378,
88,
30935,
26,
378,
88,
10005,
21,
12,
258,
327,
221,
7571,
2678,
1578,
662,
20725,
272,
378,
88,
383,
2426,
26,
378,
88,
10005,
22,
12,
258,
327,
221,
7571,
2678,
1578,
3107,
15808,
272,
378,
88,
31743,
26,
378,
88,
10005,
23,
12,
258,
327,
221,
7571,
2678,
1578,
662,
6166,
272,
378,
88,
383,
1555,
26,
378,
88,
10005,
24,
12,
258,
327,
221,
7571,
2678,
1578,
4221,
15808,
272,
378,
88,
31419,
26,
378,
88,
1644,
1020,
12,
258,
327,
221,
7571,
2678,
1578,
473,
32760,
272,
378,
88,
383,
1407,
26,
378,
88,
10005,
65,
12,
258,
327,
221,
7571,
2678,
1578,
1804,
7121,
33,
272,
378,
88,
8662,
65,
26,
378,
88,
10005,
66,
12,
258,
327,
221,
7571,
2678,
1578,
29935,
8980,
272,
378,
88,
8662,
66,
26,
378,
88,
10005,
67,
12,
258,
327,
221,
7571,
2678,
1578,
603,
53,
272,
378,
88,
8662,
67,
26,
378,
88,
10005,
68,
12,
258,
327,
221,
7571,
2678,
1578,
653,
53,
272,
378,
88,
8662,
68,
26,
378,
88,
10005,
69,
12,
258,
327,
221,
7571,
2678,
1578,
1323,
41,
272,
378,
88,
8662,
69,
26,
378,
88,
10005,
70,
12,
258,
327,
221,
7571,
2678,
1578,
593,
17233,
12758,
272,
378,
88,
8662,
70,
26,
378,
88,
1644,
65,
16,
12,
258,
327,
221,
7571,
2678,
1578,
16678,
272,
378,
88,
28875,
26,
378,
88,
1644,
65,
17,
12,
258,
327,
221,
7571,
2678,
1578,
820,
2979,
272,
378,
88,
383,
3328,
26,
378,
88,
1644,
65,
19,
12,
258,
327,
221,
7571,
2678,
1578,
15522,
2054,
272,
378,
88,
383,
2942,
26,
378,
88,
1644,
65,
20,
12,
258,
327,
221,
7571,
2678,
1578,
377,
9331,
272,
378,
88,
383,
3129,
26,
378,
88,
1644,
65,
21,
12,
258,
327,
221,
7571,
2678,
1578,
738,
20725,
272,
378,
88,
383,
2635,
26,
378,
88,
1644,
65,
22,
12,
258,
327,
221,
7571,
2678,
1578,
510,
11183,
272,
378,
88,
383,
2720,
26,
378,
88,
1644,
65,
23,
12,
258,
327,
221,
7571,
2678,
1578,
6624,
41,
272,
378,
88,
383,
2534,
26,
378,
88,
1644,
65,
24,
12,
258,
327,
221,
7571,
2678,
1578,
510,
2684,
272,
378,
88,
383,
2576,
26,
378,
88,
1644,
65,
25,
12,
258,
327,
221,
7571,
2678,
1578,
593,
31724,
272,
378,
88,
383,
2905,
26,
378,
88,
1644,
66,
17,
12,
258,
327,
221,
7571,
2516,
1578,
31278,
272,
378,
88,
29660,
26,
378,
88,
1644,
66,
18,
12,
258,
327,
221,
7571,
2516,
1578,
699,
15808,
272,
378,
88,
8581,
65,
26,
378,
88,
1644,
66,
19,
12,
258,
327,
221,
7571,
2516,
1578,
598,
1156,
2054,
272,
378,
88,
8581,
66,
26,
378,
88,
1644,
66,
20,
12,
258,
327,
221,
7571,
2516,
1578,
12355,
6166,
272,
378,
88,
8581,
67,
26,
378,
88,
1644,
66,
21,
12,
258,
327,
221,
7571,
2516,
1578,
662,
20725,
272,
378,
88,
8581,
68,
26,
378,
88,
1644,
66,
22,
12,
258,
327,
221,
7571,
2516,
1578,
3107,
15808,
272,
378,
88,
8581,
69,
26,
378,
88,
1644,
66,
23,
12,
258,
327,
221,
7571,
2516,
1578,
662,
6166,
272,
378,
88,
8581,
70,
26,
378,
88,
1644,
66,
24,
12,
258,
327,
221,
7571,
2516,
1578,
4221,
15808,
272,
378,
88,
383,
65,
16,
26,
378,
88,
1644,
66,
25,
12,
258,
327,
221,
7571,
2516,
1578,
473,
32760,
272,
378,
88,
383,
65,
17,
26,
378,
88,
1644,
2470,
12,
258,
327,
221,
7571,
2516,
1578,
1804,
7121,
33,
272,
378,
88,
383,
65,
18,
26,
378,
88,
1644,
2501,
12,
258,
327,
221,
7571,
2516,
1578,
29935,
8980,
272,
378,
88,
383,
65,
19,
26,
378,
88,
1644,
3776,
12,
258,
327,
221,
7571,
2516,
1578,
603,
53,
272,
378,
88,
383,
65,
20,
26,
378,
88,
1644,
3691,
12,
258,
327,
221,
7571
] |
[
2018,
17660,
12340,
13732,
7667,
29045,
4046,
687,
283,
27839,
4149,
15,
17233,
51,
2161,
15,
4222,
15,
2890,
29045,
14,
17715,
7,
543,
486,
2143,
67,
14,
647,
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,
1224,
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,
1224,
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,
1850,
29045,
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,
272,
378,
88,
23686,
26,
378,
88,
10005,
17,
12,
258,
327,
221,
7571,
2678,
1578,
31278,
272,
378,
88,
383,
2835,
26,
378,
88,
10005,
18,
12,
258,
327,
221,
7571,
2678,
1578,
699,
15808,
272,
378,
88,
383,
2564,
26,
378,
88,
10005,
19,
12,
258,
327,
221,
7571,
2678,
1578,
598,
1156,
2054,
272,
378,
88,
383,
2658,
26,
378,
88,
10005,
20,
12,
258,
327,
221,
7571,
2678,
1578,
12355,
6166,
272,
378,
88,
30935,
26,
378,
88,
10005,
21,
12,
258,
327,
221,
7571,
2678,
1578,
662,
20725,
272,
378,
88,
383,
2426,
26,
378,
88,
10005,
22,
12,
258,
327,
221,
7571,
2678,
1578,
3107,
15808,
272,
378,
88,
31743,
26,
378,
88,
10005,
23,
12,
258,
327,
221,
7571,
2678,
1578,
662,
6166,
272,
378,
88,
383,
1555,
26,
378,
88,
10005,
24,
12,
258,
327,
221,
7571,
2678,
1578,
4221,
15808,
272,
378,
88,
31419,
26,
378,
88,
1644,
1020,
12,
258,
327,
221,
7571,
2678,
1578,
473,
32760,
272,
378,
88,
383,
1407,
26,
378,
88,
10005,
65,
12,
258,
327,
221,
7571,
2678,
1578,
1804,
7121,
33,
272,
378,
88,
8662,
65,
26,
378,
88,
10005,
66,
12,
258,
327,
221,
7571,
2678,
1578,
29935,
8980,
272,
378,
88,
8662,
66,
26,
378,
88,
10005,
67,
12,
258,
327,
221,
7571,
2678,
1578,
603,
53,
272,
378,
88,
8662,
67,
26,
378,
88,
10005,
68,
12,
258,
327,
221,
7571,
2678,
1578,
653,
53,
272,
378,
88,
8662,
68,
26,
378,
88,
10005,
69,
12,
258,
327,
221,
7571,
2678,
1578,
1323,
41,
272,
378,
88,
8662,
69,
26,
378,
88,
10005,
70,
12,
258,
327,
221,
7571,
2678,
1578,
593,
17233,
12758,
272,
378,
88,
8662,
70,
26,
378,
88,
1644,
65,
16,
12,
258,
327,
221,
7571,
2678,
1578,
16678,
272,
378,
88,
28875,
26,
378,
88,
1644,
65,
17,
12,
258,
327,
221,
7571,
2678,
1578,
820,
2979,
272,
378,
88,
383,
3328,
26,
378,
88,
1644,
65,
19,
12,
258,
327,
221,
7571,
2678,
1578,
15522,
2054,
272,
378,
88,
383,
2942,
26,
378,
88,
1644,
65,
20,
12,
258,
327,
221,
7571,
2678,
1578,
377,
9331,
272,
378,
88,
383,
3129,
26,
378,
88,
1644,
65,
21,
12,
258,
327,
221,
7571,
2678,
1578,
738,
20725,
272,
378,
88,
383,
2635,
26,
378,
88,
1644,
65,
22,
12,
258,
327,
221,
7571,
2678,
1578,
510,
11183,
272,
378,
88,
383,
2720,
26,
378,
88,
1644,
65,
23,
12,
258,
327,
221,
7571,
2678,
1578,
6624,
41,
272,
378,
88,
383,
2534,
26,
378,
88,
1644,
65,
24,
12,
258,
327,
221,
7571,
2678,
1578,
510,
2684,
272,
378,
88,
383,
2576,
26,
378,
88,
1644,
65,
25,
12,
258,
327,
221,
7571,
2678,
1578,
593,
31724,
272,
378,
88,
383,
2905,
26,
378,
88,
1644,
66,
17,
12,
258,
327,
221,
7571,
2516,
1578,
31278,
272,
378,
88,
29660,
26,
378,
88,
1644,
66,
18,
12,
258,
327,
221,
7571,
2516,
1578,
699,
15808,
272,
378,
88,
8581,
65,
26,
378,
88,
1644,
66,
19,
12,
258,
327,
221,
7571,
2516,
1578,
598,
1156,
2054,
272,
378,
88,
8581,
66,
26,
378,
88,
1644,
66,
20,
12,
258,
327,
221,
7571,
2516,
1578,
12355,
6166,
272,
378,
88,
8581,
67,
26,
378,
88,
1644,
66,
21,
12,
258,
327,
221,
7571,
2516,
1578,
662,
20725,
272,
378,
88,
8581,
68,
26,
378,
88,
1644,
66,
22,
12,
258,
327,
221,
7571,
2516,
1578,
3107,
15808,
272,
378,
88,
8581,
69,
26,
378,
88,
1644,
66,
23,
12,
258,
327,
221,
7571,
2516,
1578,
662,
6166,
272,
378,
88,
8581,
70,
26,
378,
88,
1644,
66,
24,
12,
258,
327,
221,
7571,
2516,
1578,
4221,
15808,
272,
378,
88,
383,
65,
16,
26,
378,
88,
1644,
66,
25,
12,
258,
327,
221,
7571,
2516,
1578,
473,
32760,
272,
378,
88,
383,
65,
17,
26,
378,
88,
1644,
2470,
12,
258,
327,
221,
7571,
2516,
1578,
1804,
7121,
33,
272,
378,
88,
383,
65,
18,
26,
378,
88,
1644,
2501,
12,
258,
327,
221,
7571,
2516,
1578,
29935,
8980,
272,
378,
88,
383,
65,
19,
26,
378,
88,
1644,
3776,
12,
258,
327,
221,
7571,
2516,
1578,
603,
53,
272,
378,
88,
383,
65,
20,
26,
378,
88,
1644,
3691,
12,
258,
327,
221,
7571,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
qvazzler/Flexget
|
flexget/plugins/modify/plugin_rutracker.py
|
1
|
5223
|
# coding=utf-8
from __future__ import unicode_literals, division, absolute_import
from builtins import * # pylint: disable=unused-import, redefined-builtin
import json
import logging
from time import sleep
from datetime import datetime, timedelta
from sqlalchemy import Column, Unicode, Integer, DateTime
from sqlalchemy.types import TypeDecorator, VARCHAR
import re
from flexget import plugin
from flexget.event import event
from flexget.db_schema import versioned_base
from flexget.plugin import PluginError
from flexget.manager import Session
from requests import Session as RSession
from requests.auth import AuthBase
from requests.utils import dict_from_cookiejar
__author__ = 'asm0dey'
log = logging.getLogger('rutracker_auth')
Base = versioned_base('rutracker_auth', 0)
class JSONEncodedDict(TypeDecorator):
"""Represents an immutable structure as a json-encoded string.
Usage:
JSONEncodedDict(255)
"""
impl = VARCHAR
def process_bind_param(self, value, dialect):
if value is not None:
value = json.dumps(value)
return value
def process_result_value(self, value, dialect):
if value is not None:
value = json.loads(value)
return value
class RutrackerAccount(Base):
__tablename__ = 'rutracker_accoounts'
id = Column(Integer, primary_key=True, autoincrement=True, nullable=False)
login = Column(Unicode, index=True)
cookies = Column(JSONEncodedDict)
expiry_time = Column(DateTime)
class RutrackerAuth(AuthBase):
"""Supports downloading of torrents from 'rutracker' tracker
if you pass cookies (CookieJar) to constructor then authentication will be bypassed and cookies will be just set
"""
def try_authenticate(self, payload):
for _ in range(5):
s = RSession()
s.post("http://login.rutracker.org/forum/login.php", data=payload)
if s.cookies and len(s.cookies) > 0:
return s.cookies
else:
sleep(3)
raise PluginError('unable to obtain cookies from rutracker')
def __init__(self, login, password, cookies=None, db_session=None):
if cookies is None:
log.debug('rutracker cookie not found. Requesting new one')
payload_ = {'login_username': login,
'login_password': password, 'login': 'Вход'}
self.cookies_ = self.try_authenticate(payload_)
if db_session:
db_session.add(
RutrackerAccount(
login=login, cookies=dict_from_cookiejar(
self.cookies_),
expiry_time=datetime.now() + timedelta(days=1)))
db_session.commit()
else:
raise ValueError(
'db_session can not be None if cookies is None')
else:
log.debug('Using previously saved cookie')
self.cookies_ = cookies
def __call__(self, r):
url = r.url
id = re.findall(r'\d+', url)[0]
data = 't=' + id
headers = {
'referer': "http://rutracker.org/forum/viewtopic.php?t=" + id,
"Content-Type": "application/x-www-form-urlencoded", "t": id, 'Origin': 'http://rutracker.org',
'Accept-Encoding': 'gzip,deflate,sdch'}
r.prepare_body(data=data, files=None)
r.prepare_method('POST')
r.prepare_url(
url='http://dl.rutracker.org/forum/dl.php?t=' + id, params=None)
r.prepare_headers(headers)
r.prepare_cookies(self.cookies_)
return r
class RutrackerModify(object):
"""Usage:
rutracker_auth:
username: 'username_here'
password: 'password_here'
"""
schema = {'type': 'object',
'properties': {
'username': {'type': 'string'},
'password': {'type': 'string'}
},
"additionalProperties": False}
auth_cache = {}
@plugin.priority(127)
def on_task_urlrewrite(self, task, config):
username = config['username']
db_session = Session()
cookies = self.try_find_cookie(db_session, username)
if username not in self.auth_cache:
auth_handler = RutrackerAuth(
username, config['password'], cookies, db_session)
self.auth_cache[username] = auth_handler
else:
auth_handler = self.auth_cache[username]
for entry in task.accepted:
if entry['url'].startswith('http://rutracker.org/forum/viewtopic.php'):
entry['download_auth'] = auth_handler
def try_find_cookie(self, db_session, username):
account = db_session.query(RutrackerAccount).filter(
RutrackerAccount.login == username).first()
if account:
if account.expiry_time < datetime.now():
db_session.delete(account)
db_session.commit()
return None
return account.cookies
else:
return None
@event('plugin.register')
def register_plugin():
plugin.register(RutrackerModify, 'rutracker_auth', api_ver=2)
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
3679,
63,
646,
199,
504,
12963,
492,
627,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
295,
4037,
13,
5351,
199,
199,
646,
2022,
199,
646,
2050,
199,
504,
900,
492,
9435,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
8335,
492,
4996,
12,
6140,
12,
7225,
12,
13686,
199,
504,
8335,
14,
1313,
492,
2434,
14946,
12,
28490,
199,
199,
646,
295,
199,
504,
20758,
362,
492,
3589,
199,
504,
20758,
362,
14,
1430,
492,
1566,
199,
504,
20758,
362,
14,
697,
63,
3629,
492,
31792,
63,
1095,
199,
504,
20758,
362,
14,
2718,
492,
11349,
547,
199,
504,
20758,
362,
14,
2609,
492,
8596,
199,
504,
4145,
492,
8596,
465,
820,
4434,
199,
504,
4145,
14,
1178,
492,
3590,
1563,
199,
504,
4145,
14,
1208,
492,
1211,
63,
504,
63,
30552,
421,
199,
363,
2502,
363,
275,
283,
11374,
16,
271,
89,
7,
199,
199,
793,
275,
2050,
14,
5572,
360,
82,
337,
8085,
281,
63,
1178,
358,
199,
1563,
275,
31792,
63,
1095,
360,
82,
337,
8085,
281,
63,
1178,
297,
378,
9,
421,
199,
533,
4840,
32149,
2141,
8,
804,
14946,
304,
339,
408,
18089,
376,
17092,
5523,
465,
282,
2022,
13,
8167,
1059,
14,
339,
11028,
26,
398,
4840,
32149,
2141,
8,
2299,
9,
339,
408,
339,
11512,
275,
28490,
339,
347,
2112,
63,
3409,
63,
635,
8,
277,
12,
574,
12,
10982,
304,
267,
340,
574,
365,
440,
488,
26,
288,
574,
275,
2022,
14,
4180,
8,
585,
9,
398,
372,
574,
339,
347,
2112,
63,
1099,
63,
585,
8,
277,
12,
574,
12,
10982,
304,
267,
340,
574,
365,
440,
488,
26,
288,
574,
275,
2022,
14,
3640,
8,
585,
9,
267,
372,
574,
421,
199,
533,
820,
337,
8085,
281,
6009,
8,
1563,
304,
272,
636,
10983,
363,
275,
283,
82,
337,
8085,
281,
63,
645,
22684,
638,
83,
7,
272,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
12,
32497,
29,
549,
12,
7854,
29,
797,
9,
272,
4676,
275,
4996,
8,
7087,
12,
1478,
29,
549,
9,
272,
10049,
275,
4996,
8,
6243,
32149,
2141,
9,
272,
23402,
63,
521,
275,
4996,
8,
3926,
9,
421,
199,
533,
820,
337,
8085,
281,
2817,
8,
2817,
1563,
304,
339,
408,
31373,
25937,
402,
17671,
83,
687,
283,
82,
337,
8085,
281,
7,
15271,
2126,
340,
1265,
986,
10049,
334,
21315,
9,
370,
3787,
2066,
6299,
911,
506,
701,
12070,
436,
10049,
911,
506,
2951,
663,
272,
408,
339,
347,
862,
63,
13975,
8,
277,
12,
4886,
304,
267,
367,
485,
315,
1425,
8,
21,
304,
288,
308,
275,
820,
4434,
342,
288,
308,
14,
1932,
480,
1014,
921,
2886,
14,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
2886,
14,
8624,
401,
666,
29,
4749,
9,
288,
340,
308,
14,
7792,
436,
822,
8,
83,
14,
7792,
9,
690,
378,
26,
355,
372,
308,
14,
7792,
288,
587,
26,
355,
9435,
8,
19,
9,
267,
746,
11349,
547,
360,
17200,
370,
3332,
10049,
687,
519,
337,
8085,
281,
358,
339,
347,
636,
826,
721,
277,
12,
4676,
12,
2505,
12,
10049,
29,
403,
12,
1592,
63,
1730,
29,
403,
304,
267,
340,
10049,
365,
488,
26,
288,
943,
14,
1757,
360,
82,
337,
8085,
281,
5494,
440,
1911,
14,
4784,
316,
892,
1373,
358,
288,
4886,
63,
275,
791,
2886,
63,
2473,
356,
4676,
12,
717,
283,
2886,
63,
2060,
356,
2505,
12,
283,
2886,
356,
283,
141,
241,
25969,
28711,
936,
288,
291,
14,
7792,
63,
275,
291,
14,
893,
63,
13975,
8,
4749,
4602,
288,
340,
1592,
63,
1730,
26,
355,
1592,
63,
1730,
14,
525,
8,
490,
820,
337,
8085,
281,
6009,
8,
717,
4676,
29,
2886,
12,
10049,
29,
807,
63,
504,
63,
30552,
8,
1169,
291,
14,
7792,
29425,
717,
23402,
63,
521,
29,
2083,
14,
2131,
342,
435,
6871,
8,
4899,
29,
17,
1724,
355,
1592,
63,
1730,
14,
3543,
342,
288,
587,
26,
355,
746,
1722,
8,
490,
283,
697,
63,
1730,
883,
440,
506,
488,
340,
10049,
365,
488,
358,
267,
587,
26,
288,
943,
14,
1757,
360,
10369,
10889,
6290,
5494,
358,
288,
291,
14,
7792,
63,
275,
10049,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
1166,
275,
519,
14,
633,
267,
1305,
275,
295,
14,
6452,
8,
82,
1154,
68,
7386,
1166,
2788,
16,
61,
267,
666,
275,
283,
84,
534,
435,
1305,
267,
2323,
275,
469,
288,
283,
20996,
356,
298,
1014,
921,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
1345,
5746,
14,
8624,
31,
84,
628,
435,
1305,
12,
288,
298,
2714,
13,
804,
582,
298,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
401,
298,
84,
582,
1305,
12,
283,
12834,
356,
283,
1014,
921,
82,
337,
8085,
281,
14,
1308,
297,
288,
283,
8422,
13,
7630,
356,
283,
12256,
12,
20902,
12,
3893,
335,
936,
267,
519,
14,
6726,
63,
2030,
8,
576,
29,
576,
12,
1584,
29,
403,
9,
267,
519,
14,
6726,
63,
765,
360,
4030,
358,
267,
519,
14,
6726,
63,
633,
8,
288,
1166,
534,
1014,
921,
5030,
14,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
5030,
14,
8624,
31,
84,
534,
435,
1305,
12,
1862,
29,
403,
9,
267,
519,
14,
6726,
63,
2139,
8,
2139,
9,
267,
519,
14,
6726,
63,
7792,
8,
277,
14,
7792,
4602,
267,
372,
519,
421,
199,
533,
820,
337,
8085,
281,
18357,
8,
785,
304,
339,
408,
7692,
26,
339,
519,
337,
8085,
281,
63,
1178,
26,
489,
3434,
26,
283,
2473,
63,
1681,
7,
489,
2505,
26,
283,
2060,
63,
1681,
7,
272,
408,
272,
4177,
275,
791,
466,
356,
283,
785,
297,
1598,
283,
3282,
356,
469,
2116,
283,
2473,
356,
791,
466,
356,
283,
875,
2267,
2116,
283,
2060,
356,
791,
466,
356,
283,
875,
936,
1598,
1660,
1598,
298,
8460,
8516,
582,
756,
93,
339,
1790,
63,
1637,
275,
1052,
339,
768,
2718,
14,
6693,
8,
4195,
9,
272,
347,
641,
63,
1765,
63,
633,
14366,
8,
277,
12,
2120,
12
] |
[
2803,
29,
1624,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
3679,
63,
646,
199,
504,
12963,
492,
627,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
12,
295,
4037,
13,
5351,
199,
199,
646,
2022,
199,
646,
2050,
199,
504,
900,
492,
9435,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
8335,
492,
4996,
12,
6140,
12,
7225,
12,
13686,
199,
504,
8335,
14,
1313,
492,
2434,
14946,
12,
28490,
199,
199,
646,
295,
199,
504,
20758,
362,
492,
3589,
199,
504,
20758,
362,
14,
1430,
492,
1566,
199,
504,
20758,
362,
14,
697,
63,
3629,
492,
31792,
63,
1095,
199,
504,
20758,
362,
14,
2718,
492,
11349,
547,
199,
504,
20758,
362,
14,
2609,
492,
8596,
199,
504,
4145,
492,
8596,
465,
820,
4434,
199,
504,
4145,
14,
1178,
492,
3590,
1563,
199,
504,
4145,
14,
1208,
492,
1211,
63,
504,
63,
30552,
421,
199,
363,
2502,
363,
275,
283,
11374,
16,
271,
89,
7,
199,
199,
793,
275,
2050,
14,
5572,
360,
82,
337,
8085,
281,
63,
1178,
358,
199,
1563,
275,
31792,
63,
1095,
360,
82,
337,
8085,
281,
63,
1178,
297,
378,
9,
421,
199,
533,
4840,
32149,
2141,
8,
804,
14946,
304,
339,
408,
18089,
376,
17092,
5523,
465,
282,
2022,
13,
8167,
1059,
14,
339,
11028,
26,
398,
4840,
32149,
2141,
8,
2299,
9,
339,
408,
339,
11512,
275,
28490,
339,
347,
2112,
63,
3409,
63,
635,
8,
277,
12,
574,
12,
10982,
304,
267,
340,
574,
365,
440,
488,
26,
288,
574,
275,
2022,
14,
4180,
8,
585,
9,
398,
372,
574,
339,
347,
2112,
63,
1099,
63,
585,
8,
277,
12,
574,
12,
10982,
304,
267,
340,
574,
365,
440,
488,
26,
288,
574,
275,
2022,
14,
3640,
8,
585,
9,
267,
372,
574,
421,
199,
533,
820,
337,
8085,
281,
6009,
8,
1563,
304,
272,
636,
10983,
363,
275,
283,
82,
337,
8085,
281,
63,
645,
22684,
638,
83,
7,
272,
1305,
275,
4996,
8,
2674,
12,
5062,
63,
498,
29,
549,
12,
32497,
29,
549,
12,
7854,
29,
797,
9,
272,
4676,
275,
4996,
8,
7087,
12,
1478,
29,
549,
9,
272,
10049,
275,
4996,
8,
6243,
32149,
2141,
9,
272,
23402,
63,
521,
275,
4996,
8,
3926,
9,
421,
199,
533,
820,
337,
8085,
281,
2817,
8,
2817,
1563,
304,
339,
408,
31373,
25937,
402,
17671,
83,
687,
283,
82,
337,
8085,
281,
7,
15271,
2126,
340,
1265,
986,
10049,
334,
21315,
9,
370,
3787,
2066,
6299,
911,
506,
701,
12070,
436,
10049,
911,
506,
2951,
663,
272,
408,
339,
347,
862,
63,
13975,
8,
277,
12,
4886,
304,
267,
367,
485,
315,
1425,
8,
21,
304,
288,
308,
275,
820,
4434,
342,
288,
308,
14,
1932,
480,
1014,
921,
2886,
14,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
2886,
14,
8624,
401,
666,
29,
4749,
9,
288,
340,
308,
14,
7792,
436,
822,
8,
83,
14,
7792,
9,
690,
378,
26,
355,
372,
308,
14,
7792,
288,
587,
26,
355,
9435,
8,
19,
9,
267,
746,
11349,
547,
360,
17200,
370,
3332,
10049,
687,
519,
337,
8085,
281,
358,
339,
347,
636,
826,
721,
277,
12,
4676,
12,
2505,
12,
10049,
29,
403,
12,
1592,
63,
1730,
29,
403,
304,
267,
340,
10049,
365,
488,
26,
288,
943,
14,
1757,
360,
82,
337,
8085,
281,
5494,
440,
1911,
14,
4784,
316,
892,
1373,
358,
288,
4886,
63,
275,
791,
2886,
63,
2473,
356,
4676,
12,
717,
283,
2886,
63,
2060,
356,
2505,
12,
283,
2886,
356,
283,
141,
241,
25969,
28711,
936,
288,
291,
14,
7792,
63,
275,
291,
14,
893,
63,
13975,
8,
4749,
4602,
288,
340,
1592,
63,
1730,
26,
355,
1592,
63,
1730,
14,
525,
8,
490,
820,
337,
8085,
281,
6009,
8,
717,
4676,
29,
2886,
12,
10049,
29,
807,
63,
504,
63,
30552,
8,
1169,
291,
14,
7792,
29425,
717,
23402,
63,
521,
29,
2083,
14,
2131,
342,
435,
6871,
8,
4899,
29,
17,
1724,
355,
1592,
63,
1730,
14,
3543,
342,
288,
587,
26,
355,
746,
1722,
8,
490,
283,
697,
63,
1730,
883,
440,
506,
488,
340,
10049,
365,
488,
358,
267,
587,
26,
288,
943,
14,
1757,
360,
10369,
10889,
6290,
5494,
358,
288,
291,
14,
7792,
63,
275,
10049,
339,
347,
636,
1250,
721,
277,
12,
519,
304,
267,
1166,
275,
519,
14,
633,
267,
1305,
275,
295,
14,
6452,
8,
82,
1154,
68,
7386,
1166,
2788,
16,
61,
267,
666,
275,
283,
84,
534,
435,
1305,
267,
2323,
275,
469,
288,
283,
20996,
356,
298,
1014,
921,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
1345,
5746,
14,
8624,
31,
84,
628,
435,
1305,
12,
288,
298,
2714,
13,
804,
582,
298,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
401,
298,
84,
582,
1305,
12,
283,
12834,
356,
283,
1014,
921,
82,
337,
8085,
281,
14,
1308,
297,
288,
283,
8422,
13,
7630,
356,
283,
12256,
12,
20902,
12,
3893,
335,
936,
267,
519,
14,
6726,
63,
2030,
8,
576,
29,
576,
12,
1584,
29,
403,
9,
267,
519,
14,
6726,
63,
765,
360,
4030,
358,
267,
519,
14,
6726,
63,
633,
8,
288,
1166,
534,
1014,
921,
5030,
14,
82,
337,
8085,
281,
14,
1308,
15,
10044,
15,
5030,
14,
8624,
31,
84,
534,
435,
1305,
12,
1862,
29,
403,
9,
267,
519,
14,
6726,
63,
2139,
8,
2139,
9,
267,
519,
14,
6726,
63,
7792,
8,
277,
14,
7792,
4602,
267,
372,
519,
421,
199,
533,
820,
337,
8085,
281,
18357,
8,
785,
304,
339,
408,
7692,
26,
339,
519,
337,
8085,
281,
63,
1178,
26,
489,
3434,
26,
283,
2473,
63,
1681,
7,
489,
2505,
26,
283,
2060,
63,
1681,
7,
272,
408,
272,
4177,
275,
791,
466,
356,
283,
785,
297,
1598,
283,
3282,
356,
469,
2116,
283,
2473,
356,
791,
466,
356,
283,
875,
2267,
2116,
283,
2060,
356,
791,
466,
356,
283,
875,
936,
1598,
1660,
1598,
298,
8460,
8516,
582,
756,
93,
339,
1790,
63,
1637,
275,
1052,
339,
768,
2718,
14,
6693,
8,
4195,
9,
272,
347,
641,
63,
1765,
63,
633,
14366,
8,
277,
12,
2120,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
hbldh/bankkonto
|
bankkonto/account.py
|
1
|
7719
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
:mod:`account`
=======================
List of bank account number formats from `Bankgirot
<https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf>`_.
.. moduleauthor:: hbldh <henrik.blidh@swedwise.com>
Created on 2017-02-15, 11:41
"""
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
import re
from bankkonto.exceptions import BankkontoValidationError
TYPE_1_ACCOUNT_NUMBERS = """
Amfa Bank AB 9660-9669 00000xxxxxxC 2
Avanza Bank AB 9550-9569 00000xxxxxxC 2
BlueStep Finans AB 9680-9689 00000xxxxxxC 1
BNP Paribas Fortis Bank 9470-9479 00000xxxxxxC 2
Citibank 9040-9049 00000xxxxxxC 2
Danske Bank 1200-1399 00000xxxxxxC 1
Danske Bank 2400-2499 00000xxxxxxC 1
DNB Bank 9190-9199 00000xxxxxxC 2
DNB Bank 9260-9269 00000xxxxxxC 2
Ekobanken 9700-9709 00000xxxxxxC 2
Erik Penser AB 9590 – 9599 00000xxxxxxC 2
Forex Bank 9400-9449 00000xxxxxxC 1
ICA Banken AB 9270-9279 00000xxxxxxC 1
IKANO Bank 9170-9179 00000xxxxxxC 1
JAK Medlemsbank 9670-9679 00000xxxxxxC 2
Landshypotek AB 9390-9399 00000xxxxxxC 2
Lån & Spar Bank Sverige 9630-9639 00000xxxxxxC 1
Länsförsäkringar Bank 3400-3409 00000xxxxxxC 1
Länsförsäkringar Bank 9020-9029 00000xxxxxxC 2
Länsförsäkringar Bank 9060-9069 00000xxxxxxC 1
Marginalen Bank 9230-9239 00000xxxxxxC 1
Nordax Bank AB 9640-9649 00000xxxxxxC 2
Nordea 1100-1199 00000xxxxxxC 1
Nordea 1400-2099 00000xxxxxxC 1
Nordea 3000-3299 00000xxxxxxC 1
Nordea 3301-3399 00000xxxxxxC 1
Nordea 3410-3781 00000xxxxxxC 1
Nordea 3783-3999 00000xxxxxxC 1
Nordea 4000-4999 00000xxxxxxC 2
Nordnet Bank 9100-9109 00000xxxxxxC 2
Resurs Bank 9280-9289 00000xxxxxxC 1
Riksgälden 9880-9889 00000xxxxxxC 2
Royal bank of Scotland 9090-9099 00000xxxxxxC 2
Santander Consumer Bank AS 9460-9469 00000xxxxxxC 1
SBAB 9250-9259 00000xxxxxxC 1
SEB 5000-5999 00000xxxxxxC 1
SEB 9120-9124 00000xxxxxxC 1
SEB 9130-9149 00000xxxxxxC 1
Skandiabanken 9150-9169 00000xxxxxxC 2
Swedbank 7000-7999 00000xxxxxxC 1
Ålandsbanken Sverige AB 2300-2399 00000xxxxxxC 2
"""
TYPE_2_ACCOUNT_NUMBERS = """
Danske Bank 9180-9189 00xxxxxxxxxC 1
Handelsbanken 6000-6999 000xxxxxxxxC 2
Nordea/Plusgirot 9500-9549 00xxxxxxxxxC 3
Nordea/Plusgirot 9960-9969 00xxxxxxxxxC 3
Nordea - personkonto 3300 00xxxxxxxxxC 1
Nordea - personkonto 3782 00xxxxxxxxxC 1
Riksgälden 9890 -9899 00xxxxxxxxxC 1
Sparbanken Syd 9570- 9579 00xxxxxxxxxC 1
Swedbank 8000-8999 00xxxxxxxxxC 3
Swedbank 9300-9329 00xxxxxxxxxC 1
Swedbank (f.d. Sparbanken Öresund) 9330-9349 00xxxxxxxxxC 1
"""
_type_1 = [(_parse_result[0], int(_parse_result[1]),
int(_parse_result[2]) if _parse_result[2] else int(_parse_result[1]),
_parse_result[3], int(_parse_result[4])) for
_parse_result in re.findall('(.+)\\s([\\d]+)-*(\\d*)\\s(0+x+C)\\s(\\d+)', TYPE_1_ACCOUNT_NUMBERS.strip())]
_type_1.sort(key=lambda x: x[1])
_type_2 = [(_parse_result[0], int(_parse_result[1]),
int(_parse_result[2]) if _parse_result[2] else int(_parse_result[1]),
_parse_result[3], int(_parse_result[4])) for
_parse_result in re.findall('(.+)\\s([\\d]+)-*(\\d*)\\s(0+x+C)\\s(\\d+)', TYPE_2_ACCOUNT_NUMBERS.strip())]
_type_2.sort(key=lambda x: x[1])
def validate(clearing_number, bank_account_number):
clearing_number = re.sub('\\D', '', str(clearing_number))
bank_account_number = re.sub('\\D', '', str(bank_account_number))
if clearing_number[0] == '8':
# Swedbank account. Clearing number has five digits.
# Disregard the last one for validation purposes.
if len(clearing_number) != 5:
raise BankkontoValidationError("Clearing number for Swedbank accounts must be 5 digits.")
clearing_number = clearing_number[:-1]
else:
if len(clearing_number) != 4:
raise BankkontoValidationError("Clearing number must be 4 digits.")
bank_name, type_, nbr_format, footnote = get_account_number_format_based_on_clearing_number(clearing_number)
if len(nbr_format.strip('0')) != len(bank_account_number):
raise BankkontoValidationError("Bank account number for {0} must be {1} digits.".format(
bank_name, len(nbr_format.strip('0'))))
if type_ == 1:
if footnote == 1:
if not _module_11(clearing_number[1:], bank_account_number):
raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(
bank_account_number, bank_name, bank_account_number[-1]))
elif footnote == 2:
if not _module_11(clearing_number, bank_account_number):
raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(
bank_account_number, bank_name, bank_account_number[-1]))
else:
raise BankkontoValidationError("Unknown Type 1 footnote value: {0}.".format(footnote))
elif type_ == 2:
if footnote == 1:
if not _module_10(bank_account_number):
raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(
bank_account_number, bank_name, bank_account_number[-1]))
elif footnote == 2:
if not _module_11('', bank_account_number):
raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(
bank_account_number, bank_name, bank_account_number[-1]))
elif footnote == 3:
if not _module_10(bank_account_number):
# FIXME: The account number consists of 10 digits. Checksum calculation uses the last ten digits using
# the modulus 10 check, according format for account number (clearing number not
# included). However in rare occasions some of Swedbank’s accounts cannot be validated by
# a checksum calculation.
raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(
bank_account_number, bank_name, bank_account_number[-1]))
else:
raise BankkontoValidationError("Unknown Type 2 footnote value: {0}.".format(footnote))
else:
raise BankkontoValidationError("Unknown account type: {0}.".format(type_))
return True
def get_account_number_format_based_on_clearing_number(clearing_number):
clearing_number = int(clearing_number)
if clearing_number < 1000 or clearing_number > 9999:
raise BankkontoValidationError("Clearing number must be in range 1000 - 9999.")
res = list(filter(lambda x: x[1] <= clearing_number <= x[2], _type_1))
if res:
return res[0][0], 1, res[0][3], res[0][4]
res = list(filter(lambda x: x[1] <= clearing_number <= x[2], _type_2))
if res:
return res[0][0], 2, res[0][3], res[0][4]
raise BankkontoValidationError("Clearing number {0} does not correspond to any Swedish bank.".format(clearing_number))
def _module_11(clearing_number, bank_account_number):
weights = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
value = sum([weights[i] * int(c) for i, c in enumerate(
(str(clearing_number) + str(bank_account_number))[::-1])])
return (value % 11) == 0
def _module_10(bank_account_number):
values = [(2 if i % 2 else 1) * int(c) for i, c in enumerate(
(str(bank_account_number))[::-1])]
value = sum([(v - 9) if (v > 9) else v for v in values])
return (value % 10) == 0
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
26,
1494,
1705,
2048,
64,
199,
1280,
18673,
199,
199,
1296,
402,
16297,
2933,
1329,
6752,
687,
658,
14814,
6153,
4571,
199,
28,
2859,
921,
1544,
14,
9860,
6153,
4571,
14,
261,
15,
2966,
12186,
15,
68,
745,
760,
15,
290,
86,
460,
285,
1237,
1458,
1435,
15,
13206,
30136,
813,
265,
1860,
453,
2626,
384,
80,
991,
71,
784,
350,
63,
290,
86,
460,
285,
9285,
63,
2772,
14,
5607,
8637,
3754,
199,
199,
703,
28966,
447,
394,
14341,
72,
665,
16800,
25844,
14,
66,
7401,
72,
32,
3519,
379,
2605,
14,
957,
30,
199,
10502,
641,
9708,
13,
996,
13,
1046,
12,
4119,
26,
2953,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
16297,
75,
26296,
14,
3924,
492,
28721,
75,
26296,
8172,
421,
199,
2711,
63,
17,
63,
18928,
63,
8861,
3960,
275,
408,
199,
24566,
667,
28721,
14840,
1749,
15268,
13,
25,
15014,
378,
993,
5336,
2154,
35,
499,
199,
6651,
19024,
28721,
14840,
1749,
16859,
13,
25,
15143,
378,
993,
5336,
2154,
35,
499,
199,
15617,
7801,
11711,
796,
14840,
15580,
1257,
13,
2534,
1407,
378,
993,
5336,
2154,
35,
413,
199,
34,
14970,
510,
759,
31917,
13694,
83,
28721,
1749,
23110,
13,
2635,
1965,
378,
993,
5336,
2154,
35,
499,
199,
35,
5277,
9860,
1749,
11189,
13,
25,
12809,
378,
993,
5336,
2154,
35,
499,
199,
36,
796,
415,
28721,
413,
1840,
13,
969,
1020,
378,
993,
5336,
2154,
35,
413,
199,
36,
796,
415,
28721,
499,
5303,
13,
1194,
1020,
378,
993,
5336,
2154,
35,
413,
199,
10872,
34,
28721,
1749,
12205,
13,
3328,
1020,
378,
993,
5336,
2154,
35,
499,
199,
10872,
34,
28721,
1749,
13085,
13,
25,
12442,
378,
993,
5336,
2154,
35,
499,
199,
37,
75,
2873,
290,
917,
1749,
15946,
13,
2576,
1643,
378,
993,
5336,
2154,
35,
499,
199,
37,
25844,
510,
287,
332,
14840,
1749,
15458,
27430,
242,
16102,
1020,
378,
993,
5336,
2154,
35,
499,
199,
13099,
88,
28721,
1749,
5303,
13,
25,
19738,
378,
993,
5336,
2154,
35,
413,
199,
948,
33,
699,
290,
917,
14840,
1749,
13299,
13,
25,
12987,
378,
993,
5336,
2154,
35,
413,
199,
41,
43,
879,
47,
28721,
1749,
11010,
13,
25,
10699,
378,
993,
5336,
2154,
35,
413,
199,
42,
7872,
603,
379,
274,
706,
9860,
1749,
21451,
13,
25,
18450,
378,
993,
5336,
2154,
35,
499,
199,
44,
460,
609,
89,
555,
266,
75,
14840,
1749,
12302,
13,
3129,
1020,
378,
993,
5336,
2154,
35,
499,
199,
44,
30234,
78,
1253,
428,
462,
28721,
428,
422,
73,
303,
15580,
1216,
13,
2534,
1355,
378,
993,
5336,
2154,
35,
413,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
650,
5303,
13,
1082,
1643,
378,
993,
5336,
2154,
35,
413,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
1749,
10173,
13,
25,
13996,
378,
993,
5336,
2154,
35,
499,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
1749,
18857,
13,
25,
18264,
378,
993,
5336,
2154,
35,
413,
199,
15182,
20634,
28721,
1749,
9687,
13,
2942,
1355,
378,
993,
5336,
2154,
35,
413,
199,
23008,
983,
88,
28721,
14840,
1749,
12021,
13,
25,
11228,
378,
993,
5336,
2154,
35,
499,
199,
23008,
25395,
413,
1960,
13,
845,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
4329,
383,
13,
1165,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
29664,
13,
708,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
650,
8507,
13,
1153,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
8177,
709,
13,
1401,
2835,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
650,
22585,
13,
19,
5637,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
31092,
13,
20,
5637,
378,
993,
5336,
2154,
35,
499,
199,
46,
2181,
846,
28721,
1749,
1960,
13,
25,
6996,
378,
993,
5336,
2154,
35,
499,
199,
1322,
21050,
28721,
1749,
18520,
13,
2942,
1407,
378,
993,
5336,
2154,
35,
413,
199,
50,
3258,
1226,
13733,
76,
848,
16096,
1257,
13,
25,
13976,
378,
993,
5336,
2154,
35,
499,
199,
3863,
31876,
16297,
402,
428,
331,
5019,
460,
1749,
18526,
13,
2710,
1020,
378,
993,
5336,
2154,
35,
499,
199,
51,
867,
11438,
1448,
5391,
28721,
4319,
18729,
2259,
13,
2635,
1876,
378,
993,
5336,
2154,
35,
413,
199,
12463,
1217,
1749,
7991,
13,
25,
11990,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
22369,
13,
21,
5637,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
1749,
6708,
13,
25,
7214,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
1749,
9056,
13,
25,
10721,
378,
993,
5336,
2154,
35,
413,
199,
14194,
290,
328,
371,
290,
917,
1749,
8251,
13,
25,
10143,
378,
993,
5336,
2154,
35,
499,
199,
10941,
379,
9860,
1520,
1493,
13,
23,
5637,
378,
993,
5336,
2154,
35,
413,
199,
128,
228,
31813,
13206,
917,
428,
422,
73,
303,
14840,
499,
5863,
13,
1789,
1020,
378,
993,
5336,
2154,
35,
499,
199,
624,
199,
199,
2711,
63,
18,
63,
18928,
63,
8861,
3960,
275,
408,
199,
36,
796,
415,
28721,
1749,
7663,
13,
25,
11370,
8733,
9505,
8163,
413,
199,
40,
290,
271,
478,
13206,
917,
1227,
1493,
13,
22,
5637,
21551,
9505,
35,
499,
199,
23008,
25395,
15,
25800,
6153,
4571,
1749,
5783,
13,
25,
15419,
8733,
9505,
8163,
650,
199,
23008,
25395,
15,
25800,
6153,
4571,
8806,
2259,
13,
1020,
1876,
8733,
9505,
8163,
650,
199,
23008,
25395,
446,
4954,
75,
26296,
650,
5863,
8733,
9505,
8163,
413,
199,
23008,
25395,
446,
4954,
75,
26296,
650,
23199,
8733,
9505,
8163,
413,
199,
50,
3258,
1226,
13733,
76,
848,
1749,
13173,
446,
2905,
1020,
8733,
9505,
8163,
413,
199,
51,
462,
13206,
917,
5515,
68,
1749,
15986,
13,
1749,
14003,
8733,
9505,
8163,
413,
199,
10941,
379,
9860,
29855,
13,
24,
5637
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
26,
1494,
1705,
2048,
64,
199,
1280,
18673,
199,
199,
1296,
402,
16297,
2933,
1329,
6752,
687,
658,
14814,
6153,
4571,
199,
28,
2859,
921,
1544,
14,
9860,
6153,
4571,
14,
261,
15,
2966,
12186,
15,
68,
745,
760,
15,
290,
86,
460,
285,
1237,
1458,
1435,
15,
13206,
30136,
813,
265,
1860,
453,
2626,
384,
80,
991,
71,
784,
350,
63,
290,
86,
460,
285,
9285,
63,
2772,
14,
5607,
8637,
3754,
199,
199,
703,
28966,
447,
394,
14341,
72,
665,
16800,
25844,
14,
66,
7401,
72,
32,
3519,
379,
2605,
14,
957,
30,
199,
10502,
641,
9708,
13,
996,
13,
1046,
12,
4119,
26,
2953,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
16297,
75,
26296,
14,
3924,
492,
28721,
75,
26296,
8172,
421,
199,
2711,
63,
17,
63,
18928,
63,
8861,
3960,
275,
408,
199,
24566,
667,
28721,
14840,
1749,
15268,
13,
25,
15014,
378,
993,
5336,
2154,
35,
499,
199,
6651,
19024,
28721,
14840,
1749,
16859,
13,
25,
15143,
378,
993,
5336,
2154,
35,
499,
199,
15617,
7801,
11711,
796,
14840,
15580,
1257,
13,
2534,
1407,
378,
993,
5336,
2154,
35,
413,
199,
34,
14970,
510,
759,
31917,
13694,
83,
28721,
1749,
23110,
13,
2635,
1965,
378,
993,
5336,
2154,
35,
499,
199,
35,
5277,
9860,
1749,
11189,
13,
25,
12809,
378,
993,
5336,
2154,
35,
499,
199,
36,
796,
415,
28721,
413,
1840,
13,
969,
1020,
378,
993,
5336,
2154,
35,
413,
199,
36,
796,
415,
28721,
499,
5303,
13,
1194,
1020,
378,
993,
5336,
2154,
35,
413,
199,
10872,
34,
28721,
1749,
12205,
13,
3328,
1020,
378,
993,
5336,
2154,
35,
499,
199,
10872,
34,
28721,
1749,
13085,
13,
25,
12442,
378,
993,
5336,
2154,
35,
499,
199,
37,
75,
2873,
290,
917,
1749,
15946,
13,
2576,
1643,
378,
993,
5336,
2154,
35,
499,
199,
37,
25844,
510,
287,
332,
14840,
1749,
15458,
27430,
242,
16102,
1020,
378,
993,
5336,
2154,
35,
499,
199,
13099,
88,
28721,
1749,
5303,
13,
25,
19738,
378,
993,
5336,
2154,
35,
413,
199,
948,
33,
699,
290,
917,
14840,
1749,
13299,
13,
25,
12987,
378,
993,
5336,
2154,
35,
413,
199,
41,
43,
879,
47,
28721,
1749,
11010,
13,
25,
10699,
378,
993,
5336,
2154,
35,
413,
199,
42,
7872,
603,
379,
274,
706,
9860,
1749,
21451,
13,
25,
18450,
378,
993,
5336,
2154,
35,
499,
199,
44,
460,
609,
89,
555,
266,
75,
14840,
1749,
12302,
13,
3129,
1020,
378,
993,
5336,
2154,
35,
499,
199,
44,
30234,
78,
1253,
428,
462,
28721,
428,
422,
73,
303,
15580,
1216,
13,
2534,
1355,
378,
993,
5336,
2154,
35,
413,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
650,
5303,
13,
1082,
1643,
378,
993,
5336,
2154,
35,
413,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
1749,
10173,
13,
25,
13996,
378,
993,
5336,
2154,
35,
499,
199,
44,
13733,
561,
70,
14614,
2393,
13733,
75,
5985,
285,
28721,
1749,
18857,
13,
25,
18264,
378,
993,
5336,
2154,
35,
413,
199,
15182,
20634,
28721,
1749,
9687,
13,
2942,
1355,
378,
993,
5336,
2154,
35,
413,
199,
23008,
983,
88,
28721,
14840,
1749,
12021,
13,
25,
11228,
378,
993,
5336,
2154,
35,
499,
199,
23008,
25395,
413,
1960,
13,
845,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
4329,
383,
13,
1165,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
29664,
13,
708,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
650,
8507,
13,
1153,
1020,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
8177,
709,
13,
1401,
2835,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
650,
22585,
13,
19,
5637,
378,
993,
5336,
2154,
35,
413,
199,
23008,
25395,
31092,
13,
20,
5637,
378,
993,
5336,
2154,
35,
499,
199,
46,
2181,
846,
28721,
1749,
1960,
13,
25,
6996,
378,
993,
5336,
2154,
35,
499,
199,
1322,
21050,
28721,
1749,
18520,
13,
2942,
1407,
378,
993,
5336,
2154,
35,
413,
199,
50,
3258,
1226,
13733,
76,
848,
16096,
1257,
13,
25,
13976,
378,
993,
5336,
2154,
35,
499,
199,
3863,
31876,
16297,
402,
428,
331,
5019,
460,
1749,
18526,
13,
2710,
1020,
378,
993,
5336,
2154,
35,
499,
199,
51,
867,
11438,
1448,
5391,
28721,
4319,
18729,
2259,
13,
2635,
1876,
378,
993,
5336,
2154,
35,
413,
199,
12463,
1217,
1749,
7991,
13,
25,
11990,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
22369,
13,
21,
5637,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
1749,
6708,
13,
25,
7214,
378,
993,
5336,
2154,
35,
413,
199,
899,
34,
1749,
9056,
13,
25,
10721,
378,
993,
5336,
2154,
35,
413,
199,
14194,
290,
328,
371,
290,
917,
1749,
8251,
13,
25,
10143,
378,
993,
5336,
2154,
35,
499,
199,
10941,
379,
9860,
1520,
1493,
13,
23,
5637,
378,
993,
5336,
2154,
35,
413,
199,
128,
228,
31813,
13206,
917,
428,
422,
73,
303,
14840,
499,
5863,
13,
1789,
1020,
378,
993,
5336,
2154,
35,
499,
199,
624,
199,
199,
2711,
63,
18,
63,
18928,
63,
8861,
3960,
275,
408,
199,
36,
796,
415,
28721,
1749,
7663,
13,
25,
11370,
8733,
9505,
8163,
413,
199,
40,
290,
271,
478,
13206,
917,
1227,
1493,
13,
22,
5637,
21551,
9505,
35,
499,
199,
23008,
25395,
15,
25800,
6153,
4571,
1749,
5783,
13,
25,
15419,
8733,
9505,
8163,
650,
199,
23008,
25395,
15,
25800,
6153,
4571,
8806,
2259,
13,
1020,
1876,
8733,
9505,
8163,
650,
199,
23008,
25395,
446,
4954,
75,
26296,
650,
5863,
8733,
9505,
8163,
413,
199,
23008,
25395,
446,
4954,
75,
26296,
650,
23199,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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
] |
tximikel/kuma
|
kuma/core/tests/test_taggit_extras.py
|
29
|
2546
|
from django.test import TestCase
from .taggit_extras.models import Food
class NamespacedTaggableManagerTest(TestCase):
food_model = Food
def assert_tags_equal(self, qs, tags, sort=True, attr="name"):
got = map(lambda tag: getattr(tag, attr), qs)
if sort:
got.sort()
tags.sort()
self.assertEqual(got, tags)
def test_all_ns(self):
"""Tags can be collated or fetched by namespace"""
apple = self.food_model.objects.create(name="apple")
expected_tags = {
u'': [u'foo', u'bar', u'baz'],
u'int:': [u'int:1', u'int:2'],
u'string:': [u'string:asdf'],
u'color:': [u'color:red'],
u'system:contest:': [u'system:contest:finalist']
}
for tags in expected_tags.values():
apple.tags.add(*tags)
ns_tags = apple.tags.all_ns()
expected_ns = expected_tags.keys()
expected_ns.sort()
result_ns = ns_tags.keys()
result_ns.sort()
self.assertEqual(expected_ns, result_ns)
for ns in expected_ns:
self.assert_tags_equal(ns_tags[ns], expected_tags[ns])
self.assert_tags_equal(apple.tags.all_ns(ns), expected_tags[ns])
def test_clear_ns(self):
"""Tags can be selectively cleared by namespace"""
apple = self.food_model.objects.create(name="apple")
tags_cleared = ['a:1', 'a:2', 'a:3']
tags_not_cleared = ['1', '2', 'b:1', 'b:2', 'c:1']
apple.tags.add(*tags_cleared)
apple.tags.add(*tags_not_cleared)
apple.tags.clear_ns('a:')
self.assert_tags_equal(apple.tags.all(), tags_not_cleared)
def test_set_ns(self):
"""Tags can be selectively set by namespace"""
apple = self.food_model.objects.create(name="apple")
tags_before_set = ['a:1', 'a:2', 'a:3']
tags_after_set = ['a:4', 'a:5', 'a:6']
tags_not_set = ['1', '2', 'b:1', 'b:2', 'c:1']
apple.tags.add(*tags_before_set)
apple.tags.add(*tags_not_set)
apple.tags.set_ns('a:', *tags_after_set)
self.assert_tags_equal(apple.tags.all(), tags_after_set + tags_not_set)
def test_add_ns(self):
"""Tags that do not start with the namespace will be added with the
namespace tacked on."""
apple = self.food_model.objects.create(name="apple")
tags = ['foo', 'bar', 'baz']
apple.tags.add_ns('a:', *tags)
self.assert_tags_equal(apple.tags.all(), ['a:%s' % t for t in tags])
|
mpl-2.0
|
[
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
1450,
3187,
63,
9975,
14,
992,
492,
481,
23521,
421,
199,
533,
19317,
68,
1931,
16725,
2988,
774,
8,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
339,
347,
702,
63,
2969,
63,
1452,
8,
277,
12,
6377,
12,
3762,
12,
4069,
29,
549,
12,
1921,
628,
354,
2349,
267,
4788,
275,
2341,
8,
2734,
1947,
26,
2519,
8,
1450,
12,
1921,
395,
6377,
9,
267,
340,
4069,
26,
288,
4788,
14,
3191,
342,
288,
3762,
14,
3191,
342,
267,
291,
14,
629,
8,
7808,
12,
3762,
9,
339,
347,
511,
63,
452,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
1048,
1776,
503,
19251,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
1420,
63,
2969,
275,
469,
288,
399,
7,
356,
359,
85,
7,
1421,
297,
399,
7,
1700,
297,
399,
7,
6185,
995,
288,
399,
7,
442,
25156,
359,
85,
7,
442,
26,
17,
297,
399,
7,
442,
26,
18,
995,
288,
399,
1159,
1232,
25156,
359,
85,
1159,
1232,
26,
18196,
995,
288,
399,
7,
2326,
25156,
359,
85,
7,
2326,
26,
581,
995,
288,
399,
1159,
3045,
26,
388,
396,
25156,
359,
85,
1159,
3045,
26,
388,
396,
26,
5094,
631,
418,
267,
789,
398,
367,
3762,
315,
1420,
63,
2969,
14,
1459,
837,
288,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
9,
398,
700,
63,
2969,
275,
1145,
274,
14,
2969,
14,
452,
63,
561,
342,
398,
1420,
63,
561,
275,
1420,
63,
2969,
14,
1612,
342,
267,
1420,
63,
561,
14,
3191,
342,
267,
754,
63,
561,
275,
700,
63,
2969,
14,
1612,
342,
267,
754,
63,
561,
14,
3191,
342,
267,
291,
14,
629,
8,
2062,
63,
561,
12,
754,
63,
561,
9,
398,
367,
700,
315,
1420,
63,
561,
26,
288,
291,
14,
479,
63,
2969,
63,
1452,
8,
561,
63,
2969,
59,
561,
467,
1420,
63,
2969,
59,
561,
566,
288,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
63,
561,
8,
561,
395,
1420,
63,
2969,
59,
561,
566,
339,
347,
511,
63,
3584,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
542,
10251,
9462,
20518,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
3762,
63,
2265,
2899,
275,
788,
65,
26,
17,
297,
283,
65,
26,
18,
297,
283,
65,
26,
19,
418,
267,
3762,
63,
1397,
63,
2265,
2899,
275,
788,
17,
297,
283,
18,
297,
283,
66,
26,
17,
297,
283,
66,
26,
18,
297,
283,
67,
26,
17,
418,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
2265,
2899,
9,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
1397,
63,
2265,
2899,
9,
267,
1145,
274,
14,
2969,
14,
3584,
63,
561,
360,
65,
10993,
267,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
3762,
63,
1397,
63,
2265,
2899,
9,
339,
347,
511,
63,
409,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
542,
10251,
9462,
663,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
3762,
63,
5182,
63,
409,
275,
788,
65,
26,
17,
297,
283,
65,
26,
18,
297,
283,
65,
26,
19,
418,
267,
3762,
63,
4399,
63,
409,
275,
788,
65,
26,
20,
297,
283,
65,
26,
21,
297,
283,
65,
26,
22,
418,
267,
3762,
63,
1397,
63,
409,
275,
788,
17,
297,
283,
18,
297,
283,
66,
26,
17,
297,
283,
66,
26,
18,
297,
283,
67,
26,
17,
418,
398,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
5182,
63,
409,
9,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
1397,
63,
409,
9,
398,
1145,
274,
14,
2969,
14,
409,
63,
561,
360,
65,
6536,
627,
2969,
63,
4399,
63,
409,
9,
398,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
3762,
63,
4399,
63,
409,
435,
3762,
63,
1397,
63,
409,
9,
339,
347,
511,
63,
525,
63,
561,
8,
277,
304,
267,
408,
9440,
626,
886,
440,
1343,
543,
314,
3231,
911,
506,
3483,
543,
314,
267,
3231,
307,
564,
379,
641,
1041,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
3762,
275,
788,
1421,
297,
283,
1700,
297,
283,
6185,
418,
267,
1145,
274,
14,
2969,
14,
525,
63,
561,
360,
65,
6536,
627,
2969,
9,
398,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
788,
65,
2689,
83,
7,
450,
307,
367,
307,
315,
3762,
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
] |
[
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
1450,
3187,
63,
9975,
14,
992,
492,
481,
23521,
421,
199,
533,
19317,
68,
1931,
16725,
2988,
774,
8,
1746,
304,
272,
7090,
364,
63,
1238,
275,
481,
23521,
339,
347,
702,
63,
2969,
63,
1452,
8,
277,
12,
6377,
12,
3762,
12,
4069,
29,
549,
12,
1921,
628,
354,
2349,
267,
4788,
275,
2341,
8,
2734,
1947,
26,
2519,
8,
1450,
12,
1921,
395,
6377,
9,
267,
340,
4069,
26,
288,
4788,
14,
3191,
342,
288,
3762,
14,
3191,
342,
267,
291,
14,
629,
8,
7808,
12,
3762,
9,
339,
347,
511,
63,
452,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
1048,
1776,
503,
19251,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
1420,
63,
2969,
275,
469,
288,
399,
7,
356,
359,
85,
7,
1421,
297,
399,
7,
1700,
297,
399,
7,
6185,
995,
288,
399,
7,
442,
25156,
359,
85,
7,
442,
26,
17,
297,
399,
7,
442,
26,
18,
995,
288,
399,
1159,
1232,
25156,
359,
85,
1159,
1232,
26,
18196,
995,
288,
399,
7,
2326,
25156,
359,
85,
7,
2326,
26,
581,
995,
288,
399,
1159,
3045,
26,
388,
396,
25156,
359,
85,
1159,
3045,
26,
388,
396,
26,
5094,
631,
418,
267,
789,
398,
367,
3762,
315,
1420,
63,
2969,
14,
1459,
837,
288,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
9,
398,
700,
63,
2969,
275,
1145,
274,
14,
2969,
14,
452,
63,
561,
342,
398,
1420,
63,
561,
275,
1420,
63,
2969,
14,
1612,
342,
267,
1420,
63,
561,
14,
3191,
342,
267,
754,
63,
561,
275,
700,
63,
2969,
14,
1612,
342,
267,
754,
63,
561,
14,
3191,
342,
267,
291,
14,
629,
8,
2062,
63,
561,
12,
754,
63,
561,
9,
398,
367,
700,
315,
1420,
63,
561,
26,
288,
291,
14,
479,
63,
2969,
63,
1452,
8,
561,
63,
2969,
59,
561,
467,
1420,
63,
2969,
59,
561,
566,
288,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
63,
561,
8,
561,
395,
1420,
63,
2969,
59,
561,
566,
339,
347,
511,
63,
3584,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
542,
10251,
9462,
20518,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
267,
3762,
63,
2265,
2899,
275,
788,
65,
26,
17,
297,
283,
65,
26,
18,
297,
283,
65,
26,
19,
418,
267,
3762,
63,
1397,
63,
2265,
2899,
275,
788,
17,
297,
283,
18,
297,
283,
66,
26,
17,
297,
283,
66,
26,
18,
297,
283,
67,
26,
17,
418,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
2265,
2899,
9,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
1397,
63,
2265,
2899,
9,
267,
1145,
274,
14,
2969,
14,
3584,
63,
561,
360,
65,
10993,
267,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
3762,
63,
1397,
63,
2265,
2899,
9,
339,
347,
511,
63,
409,
63,
561,
8,
277,
304,
267,
408,
9440,
883,
506,
542,
10251,
9462,
663,
701,
3231,
624,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
3762,
63,
5182,
63,
409,
275,
788,
65,
26,
17,
297,
283,
65,
26,
18,
297,
283,
65,
26,
19,
418,
267,
3762,
63,
4399,
63,
409,
275,
788,
65,
26,
20,
297,
283,
65,
26,
21,
297,
283,
65,
26,
22,
418,
267,
3762,
63,
1397,
63,
409,
275,
788,
17,
297,
283,
18,
297,
283,
66,
26,
17,
297,
283,
66,
26,
18,
297,
283,
67,
26,
17,
418,
398,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
5182,
63,
409,
9,
267,
1145,
274,
14,
2969,
14,
525,
2031,
2969,
63,
1397,
63,
409,
9,
398,
1145,
274,
14,
2969,
14,
409,
63,
561,
360,
65,
6536,
627,
2969,
63,
4399,
63,
409,
9,
398,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
3762,
63,
4399,
63,
409,
435,
3762,
63,
1397,
63,
409,
9,
339,
347,
511,
63,
525,
63,
561,
8,
277,
304,
267,
408,
9440,
626,
886,
440,
1343,
543,
314,
3231,
911,
506,
3483,
543,
314,
267,
3231,
307,
564,
379,
641,
1041,
267,
1145,
274,
275,
291,
14,
22120,
63,
1238,
14,
1462,
14,
981,
8,
354,
628,
12820,
531,
398,
3762,
275,
788,
1421,
297,
283,
1700,
297,
283,
6185,
418,
267,
1145,
274,
14,
2969,
14,
525,
63,
561,
360,
65,
6536,
627,
2969,
9,
398,
291,
14,
479,
63,
2969,
63,
1452,
8,
12820,
14,
2969,
14,
452,
1062,
788,
65,
2689,
83,
7,
450,
307,
367,
307,
315,
3762,
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,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kiddinn/plaso
|
tests/parsers/sqlite.py
|
3
|
5508
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the SQLite database parser."""
import unittest
from plaso.parsers import sqlite
# Register all plugins.
from plaso.parsers import sqlite_plugins # pylint: disable=unused-import
from tests.parsers import test_lib
class SQLiteDatabaseTest(test_lib.ParserTestCase):
"""Tests for the SQLite database."""
# TODO: add tests for tables property
# TODO: add tests for _CopyFileObjectToTemporaryFile
# TODO: add tests for Open and Close
def testOpenClose(self):
"""Tests the Open and Close functions."""
database_file_path = self._GetTestFilePath(['contacts2.db'])
self._SkipIfPathNotExists(database_file_path)
database = sqlite.SQLiteDatabase('contacts2.db')
with open(database_file_path, 'rb') as database_file_object:
database.Open(database_file_object)
database.Close()
def testOpenCloseOnDatabaseWithDotInTableName(self):
"""Tests Open and Close on a database with a dot in a table name."""
database_file_path = self._GetTestFilePath(['data.db'])
self._SkipIfPathNotExists(database_file_path)
database = sqlite.SQLiteDatabase('data.db')
with open(database_file_path, 'rb') as database_file_object:
database.Open(database_file_object)
database.Close()
def testQueryOnDatabaseWithWAL(self):
"""Tests the Query function on a database with a WAL file."""
database_file_path = self._GetTestFilePath(['wal_database.db'])
self._SkipIfPathNotExists(database_file_path)
database_wal_file_path = self._GetTestFilePath(['wal_database.db-wal'])
self._SkipIfPathNotExists(database_wal_file_path)
database = sqlite.SQLiteDatabase('wal_database.db')
with open(database_file_path, 'rb') as database_file_object:
with open(database_wal_file_path, 'rb') as wal_file_object:
database.Open(database_file_object, wal_file_object=wal_file_object)
row_results = []
for row in database.Query('SELECT * FROM MyTable'):
row_results.append((row['Field1'], row['Field2'], row['Field3']))
expected_results = [
('Committed Text 1', 1, None),
('Committed Text 2', 2, None),
('Modified Committed Text 3', 4, None),
('Committed Text 4', 5, None),
('Committed Text 5', 7, None),
('Committed Text 6', 8, None),
('Committed Text 7', 9, None),
('Unhashable Row 1', 10, b'Binary Text!\x01\x02\x03'),
('Unhashable Row 2', 11, b'More Binary Text!\x01\x02\x03'),
('New Text 1', 12, None),
('New Text 2', 13, None)]
self.assertEqual(expected_results, row_results)
def testQueryOnDatabaseWithoutWAL(self):
"""Tests the Query function on a database without a WAL file."""
database_file_path = self._GetTestFilePath(['wal_database.db'])
self._SkipIfPathNotExists(database_file_path)
database = sqlite.SQLiteDatabase('wal_database.db')
with open(database_file_path, 'rb') as database_file_object:
database.Open(database_file_object)
row_results = []
for row in database.Query('SELECT * FROM MyTable'):
row_results.append((row['Field1'], row['Field2'], row['Field3']))
expected_results = [
('Committed Text 1', 1, None),
('Committed Text 2', 2, None),
('Deleted Text 1', 3, None),
('Committed Text 3', 4, None),
('Committed Text 4', 5, None),
('Deleted Text 2', 6, None),
('Committed Text 5', 7, None),
('Committed Text 6', 8, None),
('Committed Text 7', 9, None),
('Unhashable Row 1', 10, b'Binary Text!\x01\x02\x03')]
self.assertEqual(expected_results, row_results)
class SQLiteParserTest(test_lib.ParserTestCase):
"""Tests for the SQLite database parser."""
# pylint: disable=protected-access
# TODO: add tests for _OpenDatabaseWithWAL
def testEnablePlugins(self):
"""Tests the EnablePlugins function."""
parser = sqlite.SQLiteParser()
number_of_plugins = len(parser._plugin_classes)
parser.EnablePlugins([])
self.assertEqual(len(parser._plugins), 0)
parser.EnablePlugins(parser.ALL_PLUGINS)
self.assertEqual(len(parser._plugins), number_of_plugins)
parser.EnablePlugins(['chrome_27_history'])
self.assertEqual(len(parser._plugins), 1)
def testGetFormatSpecification(self):
"""Tests the GetFormatSpecification function."""
format_specification = sqlite.SQLiteParser.GetFormatSpecification()
self.assertIsNotNone(format_specification)
def testParseFileEntry(self):
"""Tests the ParseFileEntry function."""
parser = sqlite.SQLiteParser()
storage_writer = self._ParseFile(['contacts2.db'], parser)
self.assertEqual(storage_writer.number_of_events, 5)
self.assertEqual(storage_writer.number_of_extraction_warnings, 0)
self.assertEqual(storage_writer.number_of_recovery_warnings, 0)
for event in storage_writer.GetEvents():
event_data = self._GetEventDataOfEvent(storage_writer, event)
self.assertEqual(1, event_data.parser.count('/'))
def testParseFileEntryOnDatabaseWithDotInTableName(self):
"""Tests ParseFileEntry on a database with a dot in a table name."""
parser = sqlite.SQLiteParser()
storage_writer = self._ParseFile(['data.db'], parser)
self.assertEqual(storage_writer.number_of_events, 0)
self.assertEqual(storage_writer.number_of_extraction_warnings, 0)
self.assertEqual(storage_writer.number_of_recovery_warnings, 0)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
19245,
3050,
1798,
1041,
199,
199,
646,
2882,
199,
199,
504,
1620,
305,
79,
14,
11531,
492,
11723,
199,
3,
11828,
1006,
8963,
14,
199,
504,
1620,
305,
79,
14,
11531,
492,
11723,
63,
5265,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
199,
504,
2295,
14,
11531,
492,
511,
63,
773,
421,
199,
533,
19245,
7243,
774,
8,
396,
63,
773,
14,
2842,
1746,
304,
523,
408,
2925,
367,
314,
19245,
3050,
1041,
819,
327,
3254,
26,
1050,
2295,
367,
6716,
3324,
523,
327,
3254,
26,
1050,
2295,
367,
485,
5116,
1173,
1692,
1378,
13271,
523,
327,
3254,
26,
1050,
2295,
367,
3232,
436,
15524,
819,
347,
511,
4299,
4724,
8,
277,
304,
272,
408,
2925,
314,
3232,
436,
15524,
3423,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
18147,
18,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
18147,
18,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
489,
3050,
14,
4724,
342,
819,
347,
511,
4299,
4724,
3314,
7243,
3007,
14004,
607,
3186,
985,
8,
277,
304,
272,
408,
2925,
3232,
436,
15524,
641,
282,
3050,
543,
282,
6308,
315,
282,
1817,
536,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
576,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
576,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
489,
3050,
14,
4724,
342,
819,
347,
511,
3227,
3314,
7243,
3007,
55,
748,
8,
277,
304,
272,
408,
2925,
314,
8133,
805,
641,
282,
3050,
543,
282,
644,
748,
570,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
63,
20877,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
13,
20877,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
20877,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
20877,
63,
4659,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
543,
1551,
8,
4659,
63,
20877,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
336,
279,
63,
493,
63,
785,
26,
267,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
12,
336,
279,
63,
493,
63,
785,
29,
20877,
63,
493,
63,
785,
9,
339,
1962,
63,
2604,
275,
942,
272,
367,
1962,
315,
3050,
14,
3227,
360,
4859,
627,
4442,
4932,
3186,
735,
489,
1962,
63,
2604,
14,
740,
1332,
1143,
459,
792,
17,
995,
1962,
459,
792,
18,
995,
1962,
459,
792,
19,
5156,
339,
1420,
63,
2604,
275,
359,
267,
661,
11421,
471,
4516,
413,
297,
413,
12,
488,
395,
267,
661,
11421,
471,
4516,
499,
297,
499,
12,
488,
395,
267,
661,
11911,
21447,
471,
4516,
650,
297,
841,
12,
488,
395,
267,
661,
11421,
471,
4516,
841,
297,
959,
12,
488,
395,
267,
661,
11421,
471,
4516,
959,
297,
1520,
12,
488,
395,
267,
661,
11421,
471,
4516,
1227,
297,
1695,
12,
488,
395,
267,
661,
11421,
471,
4516,
1520,
297,
1749,
12,
488,
395,
267,
661,
1358,
24596,
15231,
413,
297,
1616,
12,
330,
7,
6636,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
659,
267,
661,
1358,
24596,
15231,
499,
297,
4119,
12,
330,
7,
11053,
14161,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
659,
267,
661,
4665,
4516,
413,
297,
3144,
12,
488,
395,
267,
661,
4665,
4516,
499,
297,
4944,
12,
488,
1874,
339,
291,
14,
629,
8,
2062,
63,
2604,
12,
1962,
63,
2604,
9,
819,
347,
511,
3227,
3314,
7243,
12450,
55,
748,
8,
277,
304,
272,
408,
2925,
314,
8133,
805,
641,
282,
3050,
1928,
282,
644,
748,
570,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
20877,
63,
4659,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
339,
1962,
63,
2604,
275,
942,
272,
367,
1962,
315,
3050,
14,
3227,
360,
4859,
627,
4442,
4932,
3186,
735,
489,
1962,
63,
2604,
14,
740,
1332,
1143,
459,
792,
17,
995,
1962,
459,
792,
18,
995,
1962,
459,
792,
19,
5156,
339,
1420,
63,
2604,
275,
359,
267,
661,
11421,
471,
4516,
413,
297,
413,
12,
488,
395,
267,
661,
11421,
471,
4516,
499,
297,
499,
12,
488,
395,
267,
661,
17735,
4516,
413,
297,
650,
12,
488,
395,
267,
661,
11421,
471,
4516,
650,
297,
841,
12,
488,
395,
267,
661,
11421,
471,
4516,
841,
297,
959,
12,
488,
395,
267,
661,
17735,
4516,
499,
297,
1227,
12,
488,
395,
267,
661,
11421,
471,
4516,
959,
297,
1520,
12,
488,
395,
267,
661,
11421,
471,
4516,
1227,
297,
1695,
12,
488,
395,
267,
661,
11421,
471,
4516,
1520,
297,
1749,
12,
488,
395,
267,
661,
1358,
24596,
15231,
413,
297,
1616,
12,
330,
7,
6636,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
5440,
339,
291,
14,
629,
8,
2062,
63,
2604,
12,
1962,
63,
2604,
9,
421,
199,
533,
19245,
2842,
774,
8,
396,
63,
773,
14,
2842,
1746,
304
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
2925,
367,
314,
19245,
3050,
1798,
1041,
199,
199,
646,
2882,
199,
199,
504,
1620,
305,
79,
14,
11531,
492,
11723,
199,
3,
11828,
1006,
8963,
14,
199,
504,
1620,
305,
79,
14,
11531,
492,
11723,
63,
5265,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
199,
504,
2295,
14,
11531,
492,
511,
63,
773,
421,
199,
533,
19245,
7243,
774,
8,
396,
63,
773,
14,
2842,
1746,
304,
523,
408,
2925,
367,
314,
19245,
3050,
1041,
819,
327,
3254,
26,
1050,
2295,
367,
6716,
3324,
523,
327,
3254,
26,
1050,
2295,
367,
485,
5116,
1173,
1692,
1378,
13271,
523,
327,
3254,
26,
1050,
2295,
367,
3232,
436,
15524,
819,
347,
511,
4299,
4724,
8,
277,
304,
272,
408,
2925,
314,
3232,
436,
15524,
3423,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
18147,
18,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
18147,
18,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
489,
3050,
14,
4724,
342,
819,
347,
511,
4299,
4724,
3314,
7243,
3007,
14004,
607,
3186,
985,
8,
277,
304,
272,
408,
2925,
3232,
436,
15524,
641,
282,
3050,
543,
282,
6308,
315,
282,
1817,
536,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
576,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
576,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
489,
3050,
14,
4724,
342,
819,
347,
511,
3227,
3314,
7243,
3007,
55,
748,
8,
277,
304,
272,
408,
2925,
314,
8133,
805,
641,
282,
3050,
543,
282,
644,
748,
570,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
63,
20877,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
13,
20877,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
20877,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
20877,
63,
4659,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
543,
1551,
8,
4659,
63,
20877,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
336,
279,
63,
493,
63,
785,
26,
267,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
12,
336,
279,
63,
493,
63,
785,
29,
20877,
63,
493,
63,
785,
9,
339,
1962,
63,
2604,
275,
942,
272,
367,
1962,
315,
3050,
14,
3227,
360,
4859,
627,
4442,
4932,
3186,
735,
489,
1962,
63,
2604,
14,
740,
1332,
1143,
459,
792,
17,
995,
1962,
459,
792,
18,
995,
1962,
459,
792,
19,
5156,
339,
1420,
63,
2604,
275,
359,
267,
661,
11421,
471,
4516,
413,
297,
413,
12,
488,
395,
267,
661,
11421,
471,
4516,
499,
297,
499,
12,
488,
395,
267,
661,
11911,
21447,
471,
4516,
650,
297,
841,
12,
488,
395,
267,
661,
11421,
471,
4516,
841,
297,
959,
12,
488,
395,
267,
661,
11421,
471,
4516,
959,
297,
1520,
12,
488,
395,
267,
661,
11421,
471,
4516,
1227,
297,
1695,
12,
488,
395,
267,
661,
11421,
471,
4516,
1520,
297,
1749,
12,
488,
395,
267,
661,
1358,
24596,
15231,
413,
297,
1616,
12,
330,
7,
6636,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
659,
267,
661,
1358,
24596,
15231,
499,
297,
4119,
12,
330,
7,
11053,
14161,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
659,
267,
661,
4665,
4516,
413,
297,
3144,
12,
488,
395,
267,
661,
4665,
4516,
499,
297,
4944,
12,
488,
1874,
339,
291,
14,
629,
8,
2062,
63,
2604,
12,
1962,
63,
2604,
9,
819,
347,
511,
3227,
3314,
7243,
12450,
55,
748,
8,
277,
304,
272,
408,
2925,
314,
8133,
805,
641,
282,
3050,
1928,
282,
644,
748,
570,
1041,
272,
3050,
63,
493,
63,
515,
275,
291,
423,
28967,
14225,
2941,
20877,
63,
4659,
14,
697,
1105,
272,
291,
423,
7738,
3917,
2042,
25095,
8,
4659,
63,
493,
63,
515,
9,
339,
3050,
275,
11723,
14,
4657,
1175,
7243,
360,
20877,
63,
4659,
14,
697,
358,
272,
543,
1551,
8,
4659,
63,
493,
63,
515,
12,
283,
4848,
358,
465,
3050,
63,
493,
63,
785,
26,
489,
3050,
14,
4299,
8,
4659,
63,
493,
63,
785,
9,
339,
1962,
63,
2604,
275,
942,
272,
367,
1962,
315,
3050,
14,
3227,
360,
4859,
627,
4442,
4932,
3186,
735,
489,
1962,
63,
2604,
14,
740,
1332,
1143,
459,
792,
17,
995,
1962,
459,
792,
18,
995,
1962,
459,
792,
19,
5156,
339,
1420,
63,
2604,
275,
359,
267,
661,
11421,
471,
4516,
413,
297,
413,
12,
488,
395,
267,
661,
11421,
471,
4516,
499,
297,
499,
12,
488,
395,
267,
661,
17735,
4516,
413,
297,
650,
12,
488,
395,
267,
661,
11421,
471,
4516,
650,
297,
841,
12,
488,
395,
267,
661,
11421,
471,
4516,
841,
297,
959,
12,
488,
395,
267,
661,
17735,
4516,
499,
297,
1227,
12,
488,
395,
267,
661,
11421,
471,
4516,
959,
297,
1520,
12,
488,
395,
267,
661,
11421,
471,
4516,
1227,
297,
1695,
12,
488,
395,
267,
661,
11421,
471,
4516,
1520,
297,
1749,
12,
488,
395,
267,
661,
1358,
24596,
15231,
413,
297,
1616,
12,
330,
7,
6636,
4516,
12525,
88,
614,
60,
88,
996,
60,
88,
1644,
5440,
339,
291,
14,
629,
8,
2062,
63,
2604,
12,
1962,
63,
2604,
9,
421,
199,
533,
19245,
2842,
774,
8,
396,
63,
773,
14,
2842,
1746,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
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/test_removebancommand.py
|
1
|
4391
|
import unittest
from unittest.mock import patch, Mock
import discord
import datetime
from commands import RemoveBanCommand
from serverobjects.server import DiscordServer
class TestRemoveBanCommand(unittest.TestCase):
def setUp(self):
self.command = RemoveBanCommand()
def test_is_command_authorized__no_permissions_disallowed(self):
result = self.command.is_command_authorized()
self.assertFalse(result)
def test_is_command_authorized__non_admin_disallowed(self):
permissions = discord.Permissions()
result = self.command.is_command_authorized(permissions)
self.assertFalse(result)
def test_is_command_authorized__admin_allowed(self):
permissions = discord.Permissions.all()
result = self.command.is_command_authorized(permissions)
self.assertTrue(result)
@patch('serverobjects.server.DiscordServer.unban_word')
def test_execute__remove_ban_valid(self, word_patch):
time = datetime.datetime.now()
server_json = {
'server_id' : 1,
'awake' : True,
'timeout_duration_seconds': 1800,
'prefix': '!vt',
'banned_words': [{
'rowid': 1,
'server_id': 1,
'banned_word': 'vore',
'infracted_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'calledout_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'record': {
'record_seconds': 2400,
'infraction_count': 0
}
},
{
'rowid': 2,
'server_id': 1,
'banned_word': 'test',
'infracted_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'calledout_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'record': {
'record_seconds': 2400,
'infraction_count': 0
}
}]
}
message = Mock(**{
'server': Mock(**{
'id': 1
}),
'content': "!vtunban 1",
'author': Mock(**{
'id': 2,
'mention': "@test",
'bot': False
}),
})
server = DiscordServer(server_json, time, None)
self.command.execute(server, time, message.content, message.author)
word_patch.assert_called_with(0)
self.assertTrue(word_patch.called)
@patch('serverobjects.server.DiscordServer.unban_word', side_effect=lambda x: False)
def test_execute__remove_ban_bad_index(self, word_patch):
time = datetime.datetime.now()
server_json = {
'server_id' : 1,
'awake' : True,
'timeout_duration_seconds': 1800,
'prefix': '!vt',
'banned_words': [{
'rowid': 1,
'server_id': 1,
'banned_word': 'vore',
'infracted_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'calledout_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'record': {
'record_seconds': 2400,
'infraction_count': 0
}
}]
}
message = Mock(**{
'server': Mock(**{
'id': 1
}),
'content': "!vtban test",
'author': Mock(**{
'id': 2,
'mention': "@test",
'bot': False
}),
})
server = DiscordServer(server_json, time, None)
result = self.command.execute(server, time, message.content, message.author)
self.assertEqual(result, "Sorry, I couldn't understand the provided index.")
@patch('serverobjects.server.DiscordServer.unban_word', side_effect=lambda x: False)
def test_execute__remove_ban_failed(self, word_patch):
time = datetime.datetime.now()
server_json = {
'server_id' : 1,
'awake' : True,
'timeout_duration_seconds': 1800,
'prefix': '!vt',
'banned_words': [{
'rowid': 1,
'server_id': 1,
'banned_word': 'vore',
'infracted_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'calledout_at': (time - datetime.timedelta(minutes=20)).strftime("%Y-%m-%d %H:%M:%S"),
'record': {
'record_seconds': 2400,
'infraction_count': 0
}
}]
}
message = Mock(**{
'server': Mock(**{
'id': 1
}),
'content': "!vtunban 1",
'author': Mock(**{
'id': 2,
'mention': "@test",
'bot': False
}),
})
server = DiscordServer(server_json, time, None)
result = self.command.execute(server, time, message.content, message.author)
self.assertEqual(result, "Sorry, I couldn't unban that word. You may have tried to unban your only banned word.")
|
mit
|
[
646,
2882,
199,
504,
2882,
14,
1805,
492,
3371,
12,
4420,
199,
646,
4339,
2181,
199,
646,
2197,
199,
199,
504,
3718,
492,
5852,
28018,
3110,
199,
504,
1654,
1462,
14,
1000,
492,
5289,
1577,
3120,
199,
199,
533,
1379,
5587,
28018,
3110,
8,
2796,
14,
1746,
304,
199,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
1531,
275,
5852,
28018,
3110,
342,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
889,
63,
6060,
63,
2297,
6541,
8,
277,
304,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
342,
507,
198,
277,
14,
3334,
8,
1099,
9,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
2865,
63,
2113,
63,
2297,
6541,
8,
277,
304,
507,
198,
6060,
275,
4339,
2181,
14,
17004,
342,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
8,
6060,
9,
507,
198,
277,
14,
3334,
8,
1099,
9,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
2113,
63,
6541,
8,
277,
304,
507,
198,
6060,
275,
4339,
2181,
14,
17004,
14,
452,
342,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
8,
6060,
9,
507,
198,
277,
14,
1815,
8,
1099,
9,
421,
198,
32,
2068,
360,
1000,
1462,
14,
1000,
14,
2825,
1577,
3120,
14,
324,
13206,
63,
1027,
358,
199,
198,
318,
511,
63,
2526,
363,
2168,
63,
13206,
63,
1078,
8,
277,
12,
4349,
63,
2068,
304,
507,
198,
521,
275,
2197,
14,
2083,
14,
2131,
342,
507,
198,
1000,
63,
1001,
275,
469,
686,
198,
1159,
23685,
63,
344,
7,
520,
413,
12,
686,
198,
7,
65,
15181,
7,
520,
715,
12,
686,
198,
1133,
1036,
548,
63,
5553,
63,
4515,
356,
6155,
383,
12,
686,
198,
7,
1861,
356,
14597,
5941,
297,
686,
198,
7,
66,
9386,
63,
3148,
356,
8910,
1585,
198,
7,
29450,
356,
413,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
86,
720,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
1386,
686,
198,
91,
1585,
198,
7,
29450,
356,
499,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
396,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
11049,
507,
198,
93,
507,
198,
1188,
275,
4420,
25679,
489,
283,
1000,
356,
4420,
25679,
267,
283,
344,
356,
413,
489,
9998,
489,
283,
1317,
356,
19724,
5941,
324,
13206,
413,
401,
489,
283,
2502,
356,
4420,
25679,
267,
283,
344,
356,
499,
12,
267,
283,
32016,
356,
9244,
396,
401,
267,
283,
3018,
356,
756,
489,
9998,
272,
3828,
507,
198,
1000,
275,
5289,
1577,
3120,
8,
1000,
63,
1001,
12,
900,
12,
488,
9,
507,
198,
277,
14,
1531,
14,
2526,
8,
1000,
12,
900,
12,
1245,
14,
1317,
12,
1245,
14,
2502,
9,
507,
198,
1027,
63,
2068,
14,
479,
63,
3527,
63,
1045,
8,
16,
9,
507,
198,
277,
14,
1815,
8,
1027,
63,
2068,
14,
3527,
9,
421,
198,
32,
2068,
360,
1000,
1462,
14,
1000,
14,
2825,
1577,
3120,
14,
324,
13206,
63,
1027,
297,
5366,
63,
5881,
29,
2734,
671,
26,
756,
9,
199,
198,
318,
511,
63,
2526,
363,
2168,
63,
13206,
63,
4087,
63,
1080,
8,
277,
12,
4349,
63,
2068,
304,
507,
198,
521,
275,
2197,
14,
2083,
14,
2131,
342,
507,
198,
1000,
63,
1001,
275,
469,
686,
198,
1159,
23685,
63,
344,
7,
520,
413,
12,
686,
198,
7,
65,
15181,
7,
520,
715,
12,
686,
198,
1133,
1036,
548,
63,
5553,
63,
4515,
356,
6155,
383,
12,
686,
198,
7,
1861,
356,
14597,
5941,
297,
686,
198,
7,
66,
9386,
63,
3148,
356,
8910,
1585,
198,
7,
29450,
356,
413,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
86,
720,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
11049,
507,
198,
93,
507,
198,
1188,
275,
4420,
25679,
489,
283,
1000,
356,
4420,
25679,
267,
283,
344,
356,
413,
489,
9998,
489,
283,
1317,
356,
19724,
86,
5842,
290,
511,
401,
489,
283,
2502,
356,
4420,
25679,
267,
283,
344,
356,
499,
12,
267,
283,
32016,
356,
9244,
396,
401,
267,
283,
3018,
356,
756,
489,
9998,
272,
3828,
507,
198,
1000,
275,
5289,
1577,
3120,
8,
1000,
63,
1001,
12,
900,
12,
488,
9,
507,
198,
1099,
275,
291,
14,
1531,
14,
2526,
8,
1000,
12,
900,
12,
1245,
14,
1317,
12,
1245,
14,
2502,
9,
507,
198,
277,
14,
629,
8,
1099,
12
] |
[
2882,
199,
504,
2882,
14,
1805,
492,
3371,
12,
4420,
199,
646,
4339,
2181,
199,
646,
2197,
199,
199,
504,
3718,
492,
5852,
28018,
3110,
199,
504,
1654,
1462,
14,
1000,
492,
5289,
1577,
3120,
199,
199,
533,
1379,
5587,
28018,
3110,
8,
2796,
14,
1746,
304,
199,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
1531,
275,
5852,
28018,
3110,
342,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
889,
63,
6060,
63,
2297,
6541,
8,
277,
304,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
342,
507,
198,
277,
14,
3334,
8,
1099,
9,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
2865,
63,
2113,
63,
2297,
6541,
8,
277,
304,
507,
198,
6060,
275,
4339,
2181,
14,
17004,
342,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
8,
6060,
9,
507,
198,
277,
14,
3334,
8,
1099,
9,
421,
198,
318,
511,
63,
374,
63,
1531,
63,
11497,
363,
2113,
63,
6541,
8,
277,
304,
507,
198,
6060,
275,
4339,
2181,
14,
17004,
14,
452,
342,
507,
198,
1099,
275,
291,
14,
1531,
14,
374,
63,
1531,
63,
11497,
8,
6060,
9,
507,
198,
277,
14,
1815,
8,
1099,
9,
421,
198,
32,
2068,
360,
1000,
1462,
14,
1000,
14,
2825,
1577,
3120,
14,
324,
13206,
63,
1027,
358,
199,
198,
318,
511,
63,
2526,
363,
2168,
63,
13206,
63,
1078,
8,
277,
12,
4349,
63,
2068,
304,
507,
198,
521,
275,
2197,
14,
2083,
14,
2131,
342,
507,
198,
1000,
63,
1001,
275,
469,
686,
198,
1159,
23685,
63,
344,
7,
520,
413,
12,
686,
198,
7,
65,
15181,
7,
520,
715,
12,
686,
198,
1133,
1036,
548,
63,
5553,
63,
4515,
356,
6155,
383,
12,
686,
198,
7,
1861,
356,
14597,
5941,
297,
686,
198,
7,
66,
9386,
63,
3148,
356,
8910,
1585,
198,
7,
29450,
356,
413,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
86,
720,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
1386,
686,
198,
91,
1585,
198,
7,
29450,
356,
499,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
396,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
11049,
507,
198,
93,
507,
198,
1188,
275,
4420,
25679,
489,
283,
1000,
356,
4420,
25679,
267,
283,
344,
356,
413,
489,
9998,
489,
283,
1317,
356,
19724,
5941,
324,
13206,
413,
401,
489,
283,
2502,
356,
4420,
25679,
267,
283,
344,
356,
499,
12,
267,
283,
32016,
356,
9244,
396,
401,
267,
283,
3018,
356,
756,
489,
9998,
272,
3828,
507,
198,
1000,
275,
5289,
1577,
3120,
8,
1000,
63,
1001,
12,
900,
12,
488,
9,
507,
198,
277,
14,
1531,
14,
2526,
8,
1000,
12,
900,
12,
1245,
14,
1317,
12,
1245,
14,
2502,
9,
507,
198,
1027,
63,
2068,
14,
479,
63,
3527,
63,
1045,
8,
16,
9,
507,
198,
277,
14,
1815,
8,
1027,
63,
2068,
14,
3527,
9,
421,
198,
32,
2068,
360,
1000,
1462,
14,
1000,
14,
2825,
1577,
3120,
14,
324,
13206,
63,
1027,
297,
5366,
63,
5881,
29,
2734,
671,
26,
756,
9,
199,
198,
318,
511,
63,
2526,
363,
2168,
63,
13206,
63,
4087,
63,
1080,
8,
277,
12,
4349,
63,
2068,
304,
507,
198,
521,
275,
2197,
14,
2083,
14,
2131,
342,
507,
198,
1000,
63,
1001,
275,
469,
686,
198,
1159,
23685,
63,
344,
7,
520,
413,
12,
686,
198,
7,
65,
15181,
7,
520,
715,
12,
686,
198,
1133,
1036,
548,
63,
5553,
63,
4515,
356,
6155,
383,
12,
686,
198,
7,
1861,
356,
14597,
5941,
297,
686,
198,
7,
66,
9386,
63,
3148,
356,
8910,
1585,
198,
7,
29450,
356,
413,
12,
1585,
198,
1159,
23685,
63,
344,
356,
413,
12,
1585,
198,
7,
66,
9386,
63,
1027,
356,
283,
86,
720,
297,
1585,
198,
7,
19505,
1522,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
1585,
198,
7,
3527,
548,
63,
292,
356,
334,
521,
446,
2197,
14,
7473,
8,
10430,
29,
1165,
4992,
6205,
3647,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
1288,
267,
283,
3059,
356,
469,
288,
283,
3059,
63,
4515,
356,
499,
5303,
12,
288,
283,
4904,
6156,
63,
835,
356,
378,
267,
789,
686,
198,
11049,
507,
198,
93,
507,
198,
1188,
275,
4420,
25679,
489,
283,
1000,
356,
4420,
25679,
267,
283,
344,
356,
413,
489,
9998,
489,
283,
1317,
356,
19724,
86,
5842,
290,
511,
401,
489,
283,
2502,
356,
4420,
25679,
267,
283,
344,
356,
499,
12,
267,
283,
32016,
356,
9244,
396,
401,
267,
283,
3018,
356,
756,
489,
9998,
272,
3828,
507,
198,
1000,
275,
5289,
1577,
3120,
8,
1000,
63,
1001,
12,
900,
12,
488,
9,
507,
198,
1099,
275,
291,
14,
1531,
14,
2526,
8,
1000,
12,
900,
12,
1245,
14,
1317,
12,
1245,
14,
2502,
9,
507,
198,
277,
14,
629,
8,
1099,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
uclouvain/osis
|
osis_role/contrib/permissions.py
|
1
|
4063
|
##############################################################################
#
# OSIS stands for Open Student Information System. It's an application
# designed to manage the core business of higher education institutions,
# such as universities, faculties, institutes and professional schools.
# The core business involves the administration of students, teachers,
# courses, programs and so on.
#
# Copyright (C) 2015-2019 Université catholique de Louvain (http://www.uclouvain.be)
#
# 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.
#
# A copy of this license - GNU General Public License - is available
# at the root of the source code of this program. If not,
# see http://www.gnu.org/licenses/.
#
##############################################################################
import rules
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import Permission, Group
from osis_role import role, errors
class ObjectPermissionBackend(ModelBackend):
def has_perm(self, user_obj, perm, *args, **kwargs):
if not user_obj.is_active or user_obj.is_anonymous:
return False
errors.clear_permission_error(user_obj, perm)
results = set()
for role_mdl in _get_relevant_roles(user_obj, perm):
rule_set = role_mdl.rule_set()
role_qs = role_mdl.objects.filter(person=getattr(user_obj, 'person', None))
_add_role_queryset_to_perms_context(rule_set, perm, role_qs)
results.add(rule_set.test_rule(perm, user_obj, *args, **kwargs))
return any(results) or super().has_perm(user_obj, perm, obj=kwargs.get('obj'))
def has_module_perms(self, user_obj, app_label, *args, **kwargs):
if not user_obj.is_active or user_obj.is_anonymous:
return False
roles_assigned = _get_roles_assigned_to_user(user_obj)
all_perms = []
for r in roles_assigned:
all_perms += [key for key in r.rule_set().keys() if app_label in key]
return any(app_label in perm for perm in all_perms) or super().has_module_perms(user_obj, app_label)
def _get_group_permissions(self, user_obj, obj=None):
"""
Override method in order to fallback to default RBAC Django when role is not registered
"""
sub_qs = Group.objects.filter(
user=user_obj
).exclude(name__in=role.role_manager.group_names_managed()).values_list('permissions', flat=True)
return Permission.objects.filter(pk__in=sub_qs)
def _get_relevant_roles(user_obj, perm):
roles_assigned = _get_roles_assigned_to_user(user_obj)
return {r for r in roles_assigned if r.rule_set().rule_exists(perm)}
def _get_roles_assigned_to_user(user_obj):
if not hasattr(user_obj, '_group_cache'):
user_obj._group_cache = set(user_obj.groups.values_list('name', flat=True))
return {r for r in role.role_manager.roles if r.group_name in user_obj._group_cache}
def _add_role_queryset_to_perms_context(rule_set, perm, qs):
"""
:param rule_set: Set of rules for a specific role
:param perm: Django permission name
:param qs: Queryset which represent the role found on database
:return: rule_set with cached predicate
"""
if perm in rule_set:
@rules.predicate(name='cache_role_qs')
def cache_role_qs_fn(*args, **kwargs):
cache_role_qs_fn.context['perm_name'] = perm
cache_role_qs_fn.context['role_qs'] = qs
return True
rule_set[perm] = cache_role_qs_fn & rule_set[perm]
return rule_set
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
259,
4403,
1311,
410,
5915,
367,
3232,
17246,
17064,
6187,
14,
2779,
1159,
376,
4223,
199,
3,
259,
19829,
370,
9635,
314,
6170,
26440,
402,
10948,
3988,
30500,
2727,
390,
8653,
12,
199,
3,
259,
4066,
465,
625,
4380,
338,
1417,
12,
21625,
1141,
397,
12,
2727,
390,
3862,
436,
22398,
28661,
308,
2239,
1446,
14,
199,
3,
259,
710,
6170,
26440,
25613,
2310,
314,
4628,
4633,
402,
18557,
12,
1565,
1225,
1192,
12,
199,
3,
259,
13588,
12,
18572,
436,
880,
641,
14,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
6900,
13,
14982,
1910,
4380,
2221,
5741,
286,
1619,
23711,
544,
477,
491,
810,
86,
1581,
334,
1014,
921,
1544,
14,
947,
320,
9154,
1581,
14,
1235,
9,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
437,
1331,
402,
642,
4190,
446,
1664,
1696,
1684,
844,
446,
365,
2808,
199,
3,
259,
737,
314,
1738,
402,
314,
1350,
1233,
402,
642,
2240,
14,
221,
982,
440,
12,
199,
3,
259,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
646,
4713,
199,
504,
1639,
14,
2828,
14,
1178,
14,
7765,
492,
5822,
8447,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
8779,
12,
5611,
199,
199,
504,
312,
2316,
63,
3756,
492,
4719,
12,
2552,
421,
199,
533,
6935,
7980,
8447,
8,
1685,
8447,
304,
272,
347,
965,
63,
8220,
8,
277,
12,
922,
63,
1113,
12,
10869,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
1113,
14,
374,
63,
2682,
503,
922,
63,
1113,
14,
374,
63,
12628,
26,
288,
372,
756,
398,
2552,
14,
3584,
63,
5693,
63,
705,
8,
751,
63,
1113,
12,
10869,
9,
267,
2058,
275,
663,
342,
267,
367,
4719,
63,
1064,
76,
315,
485,
362,
63,
21906,
63,
8050,
8,
751,
63,
1113,
12,
10869,
304,
288,
2332,
63,
409,
275,
4719,
63,
1064,
76,
14,
2200,
63,
409,
342,
288,
4719,
63,
6177,
275,
4719,
63,
1064,
76,
14,
1462,
14,
1541,
8,
5484,
29,
5675,
8,
751,
63,
1113,
12,
283,
5484,
297,
488,
430,
288,
485,
525,
63,
3756,
63,
7924,
63,
475,
63,
12068,
63,
1100,
8,
2200,
63,
409,
12,
10869,
12,
4719,
63,
6177,
9,
288,
2058,
14,
525,
8,
2200,
63,
409,
14,
396,
63,
2200,
8,
8220,
12,
922,
63,
1113,
12,
627,
589,
12,
1011,
958,
430,
267,
372,
1263,
8,
2604,
9,
503,
1613,
1252,
1989,
63,
8220,
8,
751,
63,
1113,
12,
10869,
12,
1559,
29,
958,
14,
362,
360,
1113,
1333,
339,
347,
965,
63,
578,
63,
12068,
8,
277,
12,
922,
63,
1113,
12,
1145,
63,
1302,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
1113,
14,
374,
63,
2682,
503,
922,
63,
1113,
14,
374,
63,
12628,
26,
288,
372,
756,
267,
11689,
63,
12941,
275,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
9,
267,
1006,
63,
12068,
275,
942,
267,
367,
519,
315,
11689,
63,
12941,
26,
288,
1006,
63,
12068,
847,
359,
498,
367,
790,
315,
519,
14,
2200,
63,
409,
1252,
1612,
342,
340,
1145,
63,
1302,
315,
790,
61,
267,
372,
1263,
8,
571,
63,
1302,
315,
10869,
367,
10869,
315,
1006,
63,
12068,
9,
503,
1613,
1252,
1989,
63,
578,
63,
12068,
8,
751,
63,
1113,
12,
1145,
63,
1302,
9,
339,
347,
485,
362,
63,
923,
63,
6060,
8,
277,
12,
922,
63,
1113,
12,
1559,
29,
403,
304,
267,
408,
267,
11041,
1083,
315,
1865,
370,
9567,
370,
849,
820,
34,
1348,
5634,
1380,
4719,
365,
440,
7264,
267,
408,
267,
1007,
63,
6177,
275,
5611,
14,
1462,
14,
1541,
8,
288,
922,
29,
751,
63,
1113,
267,
7092,
5473,
8,
354,
363,
262,
29,
3756,
14,
3756,
63,
2609,
14,
923,
63,
1247,
63,
11122,
8801,
1459,
63,
513,
360,
6060,
297,
6829,
29,
549,
9,
267,
372,
8779,
14,
1462,
14,
1541,
8,
2051,
363,
262,
29,
954,
63,
6177,
9,
421,
199,
318,
485,
362,
63,
21906,
63,
8050,
8,
751,
63,
1113,
12,
10869,
304,
272,
11689,
63,
12941,
275,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
9,
272,
372,
469,
82,
367,
519,
315,
11689,
63,
12941,
340,
519,
14,
2200,
63,
409,
1252,
2200,
63,
2444,
8,
8220,
6769,
421,
199,
318,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
304,
272,
340,
440,
2688,
8,
751,
63,
1113,
12,
2513,
923,
63,
1637,
735,
267,
922,
63,
1113,
423,
923,
63,
1637,
275,
663,
8,
751,
63,
1113,
14,
2634,
14,
1459,
63,
513,
360,
354,
297,
6829,
29,
549,
430,
272,
372,
469,
82,
367,
519,
315,
4719,
14,
3756,
63,
2609,
14,
8050,
340,
519,
14,
923,
63,
354,
315,
922,
63,
1113,
423,
923,
63,
1637,
93,
421,
199,
318,
485,
525,
63,
3756,
63,
7924,
63,
475,
63,
12068,
63,
1100,
8,
2200,
63,
409,
12,
10869,
12,
6377,
304,
272,
408,
272,
520,
635,
2332,
63,
409,
26,
2494,
402,
4713,
367,
282,
2488,
4719,
272,
520,
635,
10869,
26,
5634,
4983,
536,
272,
520,
635,
6377,
26,
8133,
409,
1314,
2954,
314,
4719,
1911,
641,
3050,
272,
520,
1107,
26,
2332,
63,
409,
543,
6328,
11944,
272,
408,
272,
340,
10869,
315,
2332,
63,
409,
26,
267,
768,
4423,
14,
14463
] |
[
199,
3,
199,
3,
259,
4403,
1311,
410,
5915,
367,
3232,
17246,
17064,
6187,
14,
2779,
1159,
376,
4223,
199,
3,
259,
19829,
370,
9635,
314,
6170,
26440,
402,
10948,
3988,
30500,
2727,
390,
8653,
12,
199,
3,
259,
4066,
465,
625,
4380,
338,
1417,
12,
21625,
1141,
397,
12,
2727,
390,
3862,
436,
22398,
28661,
308,
2239,
1446,
14,
199,
3,
259,
710,
6170,
26440,
25613,
2310,
314,
4628,
4633,
402,
18557,
12,
1565,
1225,
1192,
12,
199,
3,
259,
13588,
12,
18572,
436,
880,
641,
14,
199,
3,
199,
3,
259,
1898,
334,
35,
9,
6900,
13,
14982,
1910,
4380,
2221,
5741,
286,
1619,
23711,
544,
477,
491,
810,
86,
1581,
334,
1014,
921,
1544,
14,
947,
320,
9154,
1581,
14,
1235,
9,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
437,
1331,
402,
642,
4190,
446,
1664,
1696,
1684,
844,
446,
365,
2808,
199,
3,
259,
737,
314,
1738,
402,
314,
1350,
1233,
402,
642,
2240,
14,
221,
982,
440,
12,
199,
3,
259,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
3,
199,
4605,
199,
646,
4713,
199,
504,
1639,
14,
2828,
14,
1178,
14,
7765,
492,
5822,
8447,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
8779,
12,
5611,
199,
199,
504,
312,
2316,
63,
3756,
492,
4719,
12,
2552,
421,
199,
533,
6935,
7980,
8447,
8,
1685,
8447,
304,
272,
347,
965,
63,
8220,
8,
277,
12,
922,
63,
1113,
12,
10869,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
1113,
14,
374,
63,
2682,
503,
922,
63,
1113,
14,
374,
63,
12628,
26,
288,
372,
756,
398,
2552,
14,
3584,
63,
5693,
63,
705,
8,
751,
63,
1113,
12,
10869,
9,
267,
2058,
275,
663,
342,
267,
367,
4719,
63,
1064,
76,
315,
485,
362,
63,
21906,
63,
8050,
8,
751,
63,
1113,
12,
10869,
304,
288,
2332,
63,
409,
275,
4719,
63,
1064,
76,
14,
2200,
63,
409,
342,
288,
4719,
63,
6177,
275,
4719,
63,
1064,
76,
14,
1462,
14,
1541,
8,
5484,
29,
5675,
8,
751,
63,
1113,
12,
283,
5484,
297,
488,
430,
288,
485,
525,
63,
3756,
63,
7924,
63,
475,
63,
12068,
63,
1100,
8,
2200,
63,
409,
12,
10869,
12,
4719,
63,
6177,
9,
288,
2058,
14,
525,
8,
2200,
63,
409,
14,
396,
63,
2200,
8,
8220,
12,
922,
63,
1113,
12,
627,
589,
12,
1011,
958,
430,
267,
372,
1263,
8,
2604,
9,
503,
1613,
1252,
1989,
63,
8220,
8,
751,
63,
1113,
12,
10869,
12,
1559,
29,
958,
14,
362,
360,
1113,
1333,
339,
347,
965,
63,
578,
63,
12068,
8,
277,
12,
922,
63,
1113,
12,
1145,
63,
1302,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
922,
63,
1113,
14,
374,
63,
2682,
503,
922,
63,
1113,
14,
374,
63,
12628,
26,
288,
372,
756,
267,
11689,
63,
12941,
275,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
9,
267,
1006,
63,
12068,
275,
942,
267,
367,
519,
315,
11689,
63,
12941,
26,
288,
1006,
63,
12068,
847,
359,
498,
367,
790,
315,
519,
14,
2200,
63,
409,
1252,
1612,
342,
340,
1145,
63,
1302,
315,
790,
61,
267,
372,
1263,
8,
571,
63,
1302,
315,
10869,
367,
10869,
315,
1006,
63,
12068,
9,
503,
1613,
1252,
1989,
63,
578,
63,
12068,
8,
751,
63,
1113,
12,
1145,
63,
1302,
9,
339,
347,
485,
362,
63,
923,
63,
6060,
8,
277,
12,
922,
63,
1113,
12,
1559,
29,
403,
304,
267,
408,
267,
11041,
1083,
315,
1865,
370,
9567,
370,
849,
820,
34,
1348,
5634,
1380,
4719,
365,
440,
7264,
267,
408,
267,
1007,
63,
6177,
275,
5611,
14,
1462,
14,
1541,
8,
288,
922,
29,
751,
63,
1113,
267,
7092,
5473,
8,
354,
363,
262,
29,
3756,
14,
3756,
63,
2609,
14,
923,
63,
1247,
63,
11122,
8801,
1459,
63,
513,
360,
6060,
297,
6829,
29,
549,
9,
267,
372,
8779,
14,
1462,
14,
1541,
8,
2051,
363,
262,
29,
954,
63,
6177,
9,
421,
199,
318,
485,
362,
63,
21906,
63,
8050,
8,
751,
63,
1113,
12,
10869,
304,
272,
11689,
63,
12941,
275,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
9,
272,
372,
469,
82,
367,
519,
315,
11689,
63,
12941,
340,
519,
14,
2200,
63,
409,
1252,
2200,
63,
2444,
8,
8220,
6769,
421,
199,
318,
485,
362,
63,
8050,
63,
12941,
63,
475,
63,
751,
8,
751,
63,
1113,
304,
272,
340,
440,
2688,
8,
751,
63,
1113,
12,
2513,
923,
63,
1637,
735,
267,
922,
63,
1113,
423,
923,
63,
1637,
275,
663,
8,
751,
63,
1113,
14,
2634,
14,
1459,
63,
513,
360,
354,
297,
6829,
29,
549,
430,
272,
372,
469,
82,
367,
519,
315,
4719,
14,
3756,
63,
2609,
14,
8050,
340,
519,
14,
923,
63,
354,
315,
922,
63,
1113,
423,
923,
63,
1637,
93,
421,
199,
318,
485,
525,
63,
3756,
63,
7924,
63,
475,
63,
12068,
63,
1100,
8,
2200,
63,
409,
12,
10869,
12,
6377,
304,
272,
408,
272,
520,
635,
2332,
63,
409,
26,
2494,
402,
4713,
367,
282,
2488,
4719,
272,
520,
635,
10869,
26,
5634,
4983,
536,
272,
520,
635,
6377,
26,
8133,
409,
1314,
2954,
314,
4719,
1911,
641,
3050,
272,
520,
1107,
26,
2332,
63,
409,
543,
6328,
11944,
272,
408,
272,
340,
10869,
315,
2332,
63,
409,
26,
267,
768,
4423,
14,
14463,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrquim/mrquimrepo
|
script.module.youtube.dl/lib/youtube_dl/extractor/promptfile.py
|
52
|
2425
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
determine_ext,
ExtractorError,
urlencode_postdata,
)
class PromptFileIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?promptfile\.com/l/(?P<id>[0-9A-Z\-]+)'
_TEST = {
'url': 'http://www.promptfile.com/l/86D1CE8462-576CAAE416',
'md5': '5a7e285a26e0d66d9a263fae91bc92ce',
'info_dict': {
'id': '86D1CE8462-576CAAE416',
'ext': 'mp4',
'title': 'oceans.mp4',
'thumbnail': r're:^https?://.*\.jpg$',
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
if re.search(r'<div.+id="not_found_msg".+>(?!We are).+</div>[^-]', webpage) is not None:
raise ExtractorError('Video %s does not exist' % video_id,
expected=True)
chash = self._search_regex(
r'val\("([^"]*)"\s*\+\s*\$\("#chash"\)', webpage, 'chash')
fields = self._hidden_inputs(webpage)
keys = list(fields.keys())
chash_key = keys[0] if len(keys) == 1 else next(
key for key in keys if key.startswith('cha'))
fields[chash_key] = chash + fields[chash_key]
webpage = self._download_webpage(
url, video_id, 'Downloading video page',
data=urlencode_postdata(fields),
headers={'Content-type': 'application/x-www-form-urlencoded'})
video_url = self._search_regex(
(r'<a[^>]+href=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*Download File',
r'<a[^>]+href=(["\'])(?P<url>https?://(?:www\.)?promptfile\.com/file/(?:(?!\1).)+)\1'),
webpage, 'video url', group='url')
title = self._html_search_regex(
r'<span.+title="([^"]+)">', webpage, 'title')
thumbnail = self._html_search_regex(
r'<div id="player_overlay">.*button>.*?<img src="([^"]+)"',
webpage, 'thumbnail', fatal=False, flags=re.DOTALL)
formats = [{
'format_id': 'sd',
'url': video_url,
'ext': determine_ext(title),
}]
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'thumbnail': thumbnail,
'formats': formats,
}
|
gpl-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
19783,
12,
272,
16511,
63,
1932,
576,
12,
199,
9,
421,
199,
533,
2165,
4787,
1173,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
7650,
493,
4537,
957,
15,
76,
9448,
48,
28,
344,
9514,
16,
13,
25,
33,
13,
58,
16185,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
7650,
493,
14,
957,
15,
76,
15,
1184,
36,
17,
2089,
1349,
2789,
13,
12255,
35,
2276,
37,
25209,
297,
267,
283,
1064,
21,
356,
283,
21,
65,
23,
69,
14523,
65,
1479,
69,
16,
68,
1272,
68,
25,
65,
14622,
667,
69,
3328,
3776,
2942,
301,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1184,
36,
17,
2089,
1349,
2789,
13,
12255,
35,
2276,
37,
25209,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
79,
301,
796,
14,
311,
20,
297,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
340,
295,
14,
1733,
8,
82,
7601,
3015,
6977,
344,
628,
1397,
63,
4214,
63,
1328,
1674,
11,
30,
26313,
6004,
787,
680,
11,
1108,
3015,
13489,
13,
4300,
9248,
9,
365,
440,
488,
26,
288,
746,
19783,
360,
9166,
450,
83,
1630,
440,
2187,
7,
450,
3991,
63,
344,
12,
639,
1420,
29,
549,
9,
398,
682,
1119,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
637,
60,
480,
15710,
25952,
60,
83,
7590,
7896,
83,
7590,
16827,
10064,
335,
1119,
3212,
3196,
9248,
12,
283,
335,
1119,
358,
267,
1504,
275,
291,
423,
5642,
63,
3711,
8,
12022,
9,
267,
2883,
275,
769,
8,
955,
14,
1612,
1012,
267,
682,
1119,
63,
498,
275,
2883,
59,
16,
61,
340,
822,
8,
1612,
9,
508,
413,
587,
2163,
8,
288,
790,
367,
790,
315,
2883,
340,
790,
14,
2460,
360,
9518,
1333,
267,
1504,
59,
335,
1119,
63,
498,
61,
275,
682,
1119,
435,
1504,
59,
335,
1119,
63,
498,
61,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
1166,
12,
3991,
63,
344,
12,
283,
18085,
3991,
2034,
297,
288,
666,
29,
10738,
63,
1932,
576,
8,
955,
395,
288,
2323,
3713,
2714,
13,
466,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
3071,
398,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
334,
82,
7601,
65,
25524,
6399,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
28959,
3072,
83,
10,
11950,
3814,
297,
1467,
519,
7601,
65,
25524,
6399,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
2859,
24524,
1544,
20316,
7650,
493,
4537,
957,
15,
493,
32576,
2229,
12525,
17,
680,
6393,
2862,
17,
659,
288,
9248,
12,
283,
3722,
1166,
297,
1572,
534,
633,
358,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3751,
6977,
1213,
24296,
8771,
1743,
297,
9248,
12,
283,
1213,
358,
267,
10062,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
6147,
63,
18534,
1743,
2795,
3887,
27124,
28,
4060,
2928,
32391,
297,
288,
9248,
12,
283,
8311,
297,
14294,
29,
797,
12,
3285,
29,
264,
14,
16504,
9,
398,
6752,
275,
8910,
288,
283,
908,
63,
344,
356,
283,
3893,
297,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
832,
356,
6705,
63,
832,
8,
1213,
395,
267,
14877,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
6705,
63,
832,
12,
272,
19783,
12,
272,
16511,
63,
1932,
576,
12,
199,
9,
421,
199,
533,
2165,
4787,
1173,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
7650,
493,
4537,
957,
15,
76,
9448,
48,
28,
344,
9514,
16,
13,
25,
33,
13,
58,
16185,
29716,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
7650,
493,
14,
957,
15,
76,
15,
1184,
36,
17,
2089,
1349,
2789,
13,
12255,
35,
2276,
37,
25209,
297,
267,
283,
1064,
21,
356,
283,
21,
65,
23,
69,
14523,
65,
1479,
69,
16,
68,
1272,
68,
25,
65,
14622,
667,
69,
3328,
3776,
2942,
301,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1184,
36,
17,
2089,
1349,
2789,
13,
12255,
35,
2276,
37,
25209,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
79,
301,
796,
14,
311,
20,
297,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
340,
295,
14,
1733,
8,
82,
7601,
3015,
6977,
344,
628,
1397,
63,
4214,
63,
1328,
1674,
11,
30,
26313,
6004,
787,
680,
11,
1108,
3015,
13489,
13,
4300,
9248,
9,
365,
440,
488,
26,
288,
746,
19783,
360,
9166,
450,
83,
1630,
440,
2187,
7,
450,
3991,
63,
344,
12,
639,
1420,
29,
549,
9,
398,
682,
1119,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
637,
60,
480,
15710,
25952,
60,
83,
7590,
7896,
83,
7590,
16827,
10064,
335,
1119,
3212,
3196,
9248,
12,
283,
335,
1119,
358,
267,
1504,
275,
291,
423,
5642,
63,
3711,
8,
12022,
9,
267,
2883,
275,
769,
8,
955,
14,
1612,
1012,
267,
682,
1119,
63,
498,
275,
2883,
59,
16,
61,
340,
822,
8,
1612,
9,
508,
413,
587,
2163,
8,
288,
790,
367,
790,
315,
2883,
340,
790,
14,
2460,
360,
9518,
1333,
267,
1504,
59,
335,
1119,
63,
498,
61,
275,
682,
1119,
435,
1504,
59,
335,
1119,
63,
498,
61,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
1166,
12,
3991,
63,
344,
12,
283,
18085,
3991,
2034,
297,
288,
666,
29,
10738,
63,
1932,
576,
8,
955,
395,
288,
2323,
3713,
2714,
13,
466,
356,
283,
3578,
15,
88,
13,
1544,
13,
964,
13,
21886,
3071,
398,
3991,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
334,
82,
7601,
65,
25524,
6399,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
5169,
2229,
12525,
17,
680,
6393,
2862,
17,
28959,
3072,
83,
10,
11950,
3814,
297,
1467,
519,
7601,
65,
25524,
6399,
30982,
3212,
1105,
2229,
48,
28,
633,
30,
2859,
24524,
1544,
20316,
7650,
493,
4537,
957,
15,
493,
32576,
2229,
12525,
17,
680,
6393,
2862,
17,
659,
288,
9248,
12,
283,
3722,
1166,
297,
1572,
534,
633,
358,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3751,
6977,
1213,
24296,
8771,
1743,
297,
9248,
12,
283,
1213,
358,
267,
10062,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
6147,
63,
18534,
1743,
2795,
3887,
27124,
28,
4060,
2928,
32391,
297,
288,
9248,
12,
283,
8311,
297,
14294,
29,
797,
12,
3285,
29,
264,
14,
16504,
9,
398,
6752,
275,
8910,
288,
283,
908,
63,
344,
356,
283,
3893,
297,
288,
283,
633,
356,
3991,
63,
633,
12,
288,
283,
832,
356,
6705,
63,
832,
8,
1213,
395,
267,
14877,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
matthijsvk/multimodalSR
|
code/Experiments/neon-master/examples/nmt/train.py
|
1
|
6439
|
#!/usr/bin/env python
# ----------------------------------------------------------------------------
# Copyright 2016 Nervana Systems 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.
# ----------------------------------------------------------------------------
"""
Machine translation example using recurrent encoder-decoder.
Uses the subset of sentences that are shorter than the sequence length.
"""
from neon.backends import gen_backend
from neon.data.text import TextNMT
from neon.initializers import Uniform
from neon.layers import GeneralizedCost, Affine, GRU, Seq2Seq, LookupTable
from neon.models import Model
from neon.optimizers import RMSProp
from neon.transforms import Tanh, Logistic, Softmax, CrossEntropyMulti
from neon.callbacks.callbacks import Callbacks
from neon.util.argparser import NeonArgparser, extract_valid_args
from neon.transforms.cost import BLEUScore
import os
import itertools as itt
def bleu_format(examples, tgt_dict, num_batches, batch_size, eos=0):
"""
BLEU score
"""
sents = [examples[ex, b, :] for b, ex in itt.product(range(num_batches), range(batch_size))]
return [" ".join([tgt_dict[k].decode("utf-8") for k in sent if k != eos]) for sent in sents]
def print_sample(ex_source, ex_reference, ex_prediction, src_dict, tgt_dict):
"""
Print some example predictions.
"""
sample_output = u"""
Source Sentence: {source}
Reference Translation: {reference}
Predicted Translation: {prediction}
""".format(source=" ".join([src_dict[k].decode("utf-8") for k in ex_source]),
reference=" ".join([tgt_dict[k].decode("utf-8") for k in ex_reference]),
prediction=" ".join([tgt_dict[k].decode("utf-8") for k in ex_prediction]))
print(sample_output.encode("utf-8"))
# parse the command line arguments
default_overrides = dict(batch_size=128)
parser = NeonArgparser(__doc__, default_overrides=default_overrides)
parser.add_argument('--num_layers', default=2, type=int,
help='number of recurrent layers in encoder and decoder')
parser.add_argument('--num_hidden', default=512, type=int,
help='number of hidden units in each recurrent layer')
parser.add_argument('--embedding_dim', default=512, type=int,
help='word embedding dimension')
parser.add_argument('--num_beams', default=10, type=int,
help='number of beam search beams (0 for no beam search)')
parser.add_argument('--subset_pct', type=float, default=100,
help='subset of training dataset to use (percentage)')
args = parser.parse_args(gen_be=False)
# parameters
hidden_size = args.num_hidden
embedding_dim = args.embedding_dim
num_beams = args.num_beams
num_layers = args.num_layers
gradient_clip_value = 5
time_steps = 20
dataset = 'un2000'
# setup backend
be = gen_backend(**extract_valid_args(args, gen_backend))
# load data
train_path = os.path.join(args.data_dir, 'nmt', dataset)
train_set = TextNMT(time_steps, train_path, get_prev_target=True, onehot_input=False,
split='train', dataset=dataset, subset_pct=args.subset_pct)
valid_set = TextNMT(time_steps, train_path, get_prev_target=False, onehot_input=False,
split='valid', dataset=dataset)
# weight initialization
init = Uniform(low=-0.08, high=0.08)
# Standard or Conditional encoder / decoder:
encoder = [LookupTable(vocab_size=len(train_set.s_vocab), embedding_dim=embedding_dim,
init=init, name="LUT_en")]
decoder = [LookupTable(vocab_size=len(train_set.t_vocab), embedding_dim=embedding_dim,
init=init, name="LUT_de")]
decoder_connections = [] # link up recurrent layers
for ii in range(num_layers):
encoder.append(GRU(hidden_size, init, activation=Tanh(), gate_activation=Logistic(),
reset_cells=True, name="GRU1Enc"))
decoder.append(GRU(hidden_size, init, activation=Tanh(), gate_activation=Logistic(),
reset_cells=True, name="GRU1Dec"))
decoder_connections.append(ii)
decoder.append(Affine(train_set.nout, init, bias=init, activation=Softmax(), name="Affout"))
layers = Seq2Seq([encoder, decoder],
decoder_connections=decoder_connections,
name="Seq2Seq")
cost = GeneralizedCost(costfunc=CrossEntropyMulti(usebits=True))
model = Model(layers=layers)
optimizer = RMSProp(gradient_clip_value=gradient_clip_value, stochastic_round=args.rounding)
# configure callbacks
callbacks = Callbacks(model, eval_set=valid_set, **args.callback_args)
# train model
model.fit(train_set,
optimizer=optimizer,
num_epochs=args.epochs,
cost=cost, callbacks=callbacks)
# obtain predictions
shape = (valid_set.nbatches, args.batch_size, time_steps)
if num_beams == 0:
ypred = model.get_outputs(valid_set)
# flip the reversed predictions back to normal sentence order
prediction = ypred.argmax(2).reshape(shape).transpose(1, 0, 2)[:, :, ::-1]
else:
ypred = model.get_outputs_beam(valid_set, num_beams=num_beams)
prediction = ypred.reshape(shape).transpose(1, 0, 2)[:, :, ::-1]
# print some examples
src_dict, tgt_dict = valid_set.s_index_to_token, valid_set.t_index_to_token
for i in range(3):
print_sample(ex_source=valid_set.X[i, 0, :],
ex_reference=valid_set.y[i, 0, :],
ex_prediction=prediction[i, 0, :],
src_dict=src_dict, tgt_dict=tgt_dict)
# compute BLEU scores
inputs = valid_set.X[:, :valid_set.nbatches, :]
source_sentences = bleu_format(inputs, tgt_dict, valid_set.nbatches, args.batch_size)
generated = bleu_format(prediction, tgt_dict, valid_set.nbatches, args.batch_size)
references = bleu_format(valid_set.y, tgt_dict, valid_set.nbatches, args.batch_size)
references = [[r] for r in references]
bleu_score = BLEUScore()
bleu4 = bleu_score(generated, references, N=4, brevity_penalty=False, lower_case=True)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
27103,
199,
3,
1898,
7800,
653,
281,
86,
6738,
15285,
3277,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
27103,
199,
624,
199,
8412,
7761,
2893,
1808,
295,
1818,
10295,
13,
8813,
14,
199,
199,
21896,
314,
10026,
402,
24256,
626,
787,
18299,
2419,
314,
3414,
2582,
14,
199,
624,
199,
504,
1279,
265,
14,
7765,
492,
3805,
63,
4620,
199,
504,
1279,
265,
14,
576,
14,
505,
492,
4516,
46,
5747,
199,
504,
1279,
265,
14,
2747,
6315,
492,
1910,
8241,
199,
504,
1279,
265,
14,
4359,
492,
1696,
1759,
15568,
12,
31030,
1132,
12,
598,
9500,
12,
28534,
18,
11205,
12,
12785,
3186,
199,
504,
1279,
265,
14,
992,
492,
5822,
199,
504,
1279,
265,
14,
6433,
6315,
492,
820,
3053,
9955,
199,
504,
1279,
265,
14,
15133,
492,
377,
290,
72,
12,
5297,
6937,
12,
27238,
988,
12,
28965,
31224,
3947,
199,
504,
1279,
265,
14,
11948,
14,
11948,
492,
17555,
83,
199,
504,
1279,
265,
14,
1974,
14,
1273,
2087,
492,
5612,
265,
6373,
2087,
12,
5536,
63,
1078,
63,
589,
199,
504,
1279,
265,
14,
15133,
14,
6336,
492,
699,
906,
1668,
1018,
199,
646,
747,
199,
646,
7975,
465,
652,
84,
421,
199,
318,
29603,
85,
63,
908,
8,
8589,
12,
11967,
63,
807,
12,
1967,
63,
14896,
12,
3522,
63,
890,
12,
325,
736,
29,
16,
304,
272,
408,
272,
699,
23391,
5396,
272,
408,
272,
4847,
83,
275,
359,
8589,
59,
476,
12,
330,
12,
12228,
367,
330,
12,
444,
315,
652,
84,
14,
2558,
8,
1842,
8,
1507,
63,
14896,
395,
1425,
8,
2912,
63,
890,
10524,
272,
372,
2097,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
4847,
340,
1022,
1137,
325,
736,
566,
367,
4847,
315,
4847,
83,
61,
421,
199,
318,
870,
63,
3271,
8,
476,
63,
1365,
12,
444,
63,
4443,
12,
444,
63,
14845,
12,
2928,
63,
807,
12,
11967,
63,
807,
304,
272,
408,
272,
9101,
2005,
2893,
7914,
14,
272,
408,
272,
2690,
63,
1199,
275,
399,
624,
272,
5800,
428,
287,
6692,
26,
469,
1365,
93,
272,
10944,
25224,
26,
469,
4443,
93,
272,
5543,
328,
1522,
25224,
26,
469,
14845,
93,
272,
30512,
908,
8,
1365,
628,
3680,
904,
779,
2164,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
1365,
2522,
2049,
3659,
628,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
4443,
2522,
2049,
12044,
628,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
14845,
2459,
272,
870,
8,
3271,
63,
1199,
14,
2143,
480,
1624,
13,
24,
2237,
421,
199,
3,
2198,
314,
1414,
1004,
2368,
199,
885,
63,
12867,
275,
1211,
8,
2912,
63,
890,
29,
3933,
9,
199,
2087,
275,
5612,
265,
6373,
2087,
3460,
1301,
3108,
849,
63,
12867,
29,
885,
63,
12867,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
4359,
297,
849,
29,
18,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
295,
1818,
9393,
315,
10295,
436,
10334,
358,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
5642,
297,
849,
29,
7736,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
8752,
6204,
315,
1924,
295,
1818,
4045,
358,
199,
2087,
14,
525,
63,
2094,
4517,
14275,
63,
3572,
297,
849,
29,
7736,
12,
730,
29,
442,
12,
490,
1720,
534,
1027,
12452,
6240,
358,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
14529,
83,
297,
849,
29,
709,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
17453,
2754,
17453,
83,
334,
16,
367,
949,
17453,
2754,
5942,
199,
2087,
14,
525,
63,
2094,
4517,
9401,
63,
20778,
297,
730,
29,
1609,
12,
849,
29,
1960,
12,
490,
1720,
534,
9401,
402,
6093,
4789,
370,
675,
334,
14200,
5942,
199,
589,
275,
1798,
14,
1122,
63,
589,
8,
2268,
63,
1235,
29,
797,
9,
199,
199,
3,
2633,
199,
5642,
63,
890,
275,
1249,
14,
1507,
63,
5642,
199,
14275,
63,
3572,
275,
1249,
14,
14275,
63,
3572,
199,
1507,
63,
14529,
83,
275,
1249,
14,
1507,
63,
14529,
83,
199,
1507,
63,
4359,
275,
1249,
14,
1507,
63,
4359,
199,
7490,
63,
7548,
63,
585,
275,
959,
199,
521,
63,
5895,
275,
3388,
199,
5214,
275,
283,
324,
8269,
7,
199,
199,
3,
3272,
4865,
199,
1235,
275,
3805,
63,
4620,
3682,
5005,
63,
1078,
63,
589,
8,
589,
12,
3805,
63,
4620,
430,
199,
199,
3,
2248,
666,
199,
2834,
63,
515,
275,
747,
14,
515,
14,
904,
8,
589,
14,
576,
63,
694,
12,
283,
78,
2037,
297,
4789,
9,
199,
2834,
63,
409,
275,
4516,
46,
5747,
8,
521,
63,
5895,
12,
3560,
63,
515,
12,
664,
63,
5701,
63,
1375,
29,
549,
12,
1373,
8885,
63,
1210,
29,
797,
12,
490,
3715,
534,
2834,
297,
4789,
29,
5214,
12,
10026,
63,
20778,
29,
589,
14,
9401,
63,
20778,
9,
199,
1078,
63,
409,
275,
4516,
46,
5747,
8,
521,
63,
5895,
12,
3560,
63,
515,
12,
664,
63,
5701,
63,
1375,
29,
797,
12,
1373,
8885,
63,
1210,
29,
797,
12,
490,
3715,
534,
1078,
297,
4789,
29,
5214,
9,
199,
199,
3,
5401,
11097,
199,
826,
275,
1910
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
27103,
199,
3,
1898,
7800,
653,
281,
86,
6738,
15285,
3277,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
27103,
199,
624,
199,
8412,
7761,
2893,
1808,
295,
1818,
10295,
13,
8813,
14,
199,
199,
21896,
314,
10026,
402,
24256,
626,
787,
18299,
2419,
314,
3414,
2582,
14,
199,
624,
199,
504,
1279,
265,
14,
7765,
492,
3805,
63,
4620,
199,
504,
1279,
265,
14,
576,
14,
505,
492,
4516,
46,
5747,
199,
504,
1279,
265,
14,
2747,
6315,
492,
1910,
8241,
199,
504,
1279,
265,
14,
4359,
492,
1696,
1759,
15568,
12,
31030,
1132,
12,
598,
9500,
12,
28534,
18,
11205,
12,
12785,
3186,
199,
504,
1279,
265,
14,
992,
492,
5822,
199,
504,
1279,
265,
14,
6433,
6315,
492,
820,
3053,
9955,
199,
504,
1279,
265,
14,
15133,
492,
377,
290,
72,
12,
5297,
6937,
12,
27238,
988,
12,
28965,
31224,
3947,
199,
504,
1279,
265,
14,
11948,
14,
11948,
492,
17555,
83,
199,
504,
1279,
265,
14,
1974,
14,
1273,
2087,
492,
5612,
265,
6373,
2087,
12,
5536,
63,
1078,
63,
589,
199,
504,
1279,
265,
14,
15133,
14,
6336,
492,
699,
906,
1668,
1018,
199,
646,
747,
199,
646,
7975,
465,
652,
84,
421,
199,
318,
29603,
85,
63,
908,
8,
8589,
12,
11967,
63,
807,
12,
1967,
63,
14896,
12,
3522,
63,
890,
12,
325,
736,
29,
16,
304,
272,
408,
272,
699,
23391,
5396,
272,
408,
272,
4847,
83,
275,
359,
8589,
59,
476,
12,
330,
12,
12228,
367,
330,
12,
444,
315,
652,
84,
14,
2558,
8,
1842,
8,
1507,
63,
14896,
395,
1425,
8,
2912,
63,
890,
10524,
272,
372,
2097,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
4847,
340,
1022,
1137,
325,
736,
566,
367,
4847,
315,
4847,
83,
61,
421,
199,
318,
870,
63,
3271,
8,
476,
63,
1365,
12,
444,
63,
4443,
12,
444,
63,
14845,
12,
2928,
63,
807,
12,
11967,
63,
807,
304,
272,
408,
272,
9101,
2005,
2893,
7914,
14,
272,
408,
272,
2690,
63,
1199,
275,
399,
624,
272,
5800,
428,
287,
6692,
26,
469,
1365,
93,
272,
10944,
25224,
26,
469,
4443,
93,
272,
5543,
328,
1522,
25224,
26,
469,
14845,
93,
272,
30512,
908,
8,
1365,
628,
3680,
904,
779,
2164,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
1365,
2522,
2049,
3659,
628,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
4443,
2522,
2049,
12044,
628,
3680,
904,
779,
15328,
63,
807,
59,
75,
1055,
2708,
480,
1624,
13,
24,
531,
367,
1022,
315,
444,
63,
14845,
2459,
272,
870,
8,
3271,
63,
1199,
14,
2143,
480,
1624,
13,
24,
2237,
421,
199,
3,
2198,
314,
1414,
1004,
2368,
199,
885,
63,
12867,
275,
1211,
8,
2912,
63,
890,
29,
3933,
9,
199,
2087,
275,
5612,
265,
6373,
2087,
3460,
1301,
3108,
849,
63,
12867,
29,
885,
63,
12867,
9,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
4359,
297,
849,
29,
18,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
295,
1818,
9393,
315,
10295,
436,
10334,
358,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
5642,
297,
849,
29,
7736,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
8752,
6204,
315,
1924,
295,
1818,
4045,
358,
199,
2087,
14,
525,
63,
2094,
4517,
14275,
63,
3572,
297,
849,
29,
7736,
12,
730,
29,
442,
12,
490,
1720,
534,
1027,
12452,
6240,
358,
199,
2087,
14,
525,
63,
2094,
4517,
1507,
63,
14529,
83,
297,
849,
29,
709,
12,
730,
29,
442,
12,
490,
1720,
534,
1955,
402,
17453,
2754,
17453,
83,
334,
16,
367,
949,
17453,
2754,
5942,
199,
2087,
14,
525,
63,
2094,
4517,
9401,
63,
20778,
297,
730,
29,
1609,
12,
849,
29,
1960,
12,
490,
1720,
534,
9401,
402,
6093,
4789,
370,
675,
334,
14200,
5942,
199,
589,
275,
1798,
14,
1122,
63,
589,
8,
2268,
63,
1235,
29,
797,
9,
199,
199,
3,
2633,
199,
5642,
63,
890,
275,
1249,
14,
1507,
63,
5642,
199,
14275,
63,
3572,
275,
1249,
14,
14275,
63,
3572,
199,
1507,
63,
14529,
83,
275,
1249,
14,
1507,
63,
14529,
83,
199,
1507,
63,
4359,
275,
1249,
14,
1507,
63,
4359,
199,
7490,
63,
7548,
63,
585,
275,
959,
199,
521,
63,
5895,
275,
3388,
199,
5214,
275,
283,
324,
8269,
7,
199,
199,
3,
3272,
4865,
199,
1235,
275,
3805,
63,
4620,
3682,
5005,
63,
1078,
63,
589,
8,
589,
12,
3805,
63,
4620,
430,
199,
199,
3,
2248,
666,
199,
2834,
63,
515,
275,
747,
14,
515,
14,
904,
8,
589,
14,
576,
63,
694,
12,
283,
78,
2037,
297,
4789,
9,
199,
2834,
63,
409,
275,
4516,
46,
5747,
8,
521,
63,
5895,
12,
3560,
63,
515,
12,
664,
63,
5701,
63,
1375,
29,
549,
12,
1373,
8885,
63,
1210,
29,
797,
12,
490,
3715,
534,
2834,
297,
4789,
29,
5214,
12,
10026,
63,
20778,
29,
589,
14,
9401,
63,
20778,
9,
199,
1078,
63,
409,
275,
4516,
46,
5747,
8,
521,
63,
5895,
12,
3560,
63,
515,
12,
664,
63,
5701,
63,
1375,
29,
797,
12,
1373,
8885,
63,
1210,
29,
797,
12,
490,
3715,
534,
1078,
297,
4789,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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
anryko/ansible
|
lib/ansible/plugins/doc_fragments/netconf.py
|
44
|
2657
|
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
class ModuleDocFragment(object):
# Standard files documentation fragment
DOCUMENTATION = r'''
options:
host:
description:
- Specifies the DNS host name or address for connecting to the remote
device over the specified transport. The value of host is used as
the destination address for the transport.
type: str
required: true
port:
description:
- Specifies the port to use when building the connection to the remote
device. The port value will default to port 830.
type: int
default: 830
username:
description:
- Configures the username to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead.
type: str
password:
description:
- Specifies the password to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead.
type: str
timeout:
description:
- Specifies the timeout in seconds for communicating with the network device
for either connecting or sending commands. If the timeout is
exceeded before the operation is completed, the module will error.
type: int
default: 10
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This value is the path to the key
used to authenticate the SSH session. If the value is not specified in
the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE)
will be used instead.
type: path
hostkey_verify:
description:
- If set to C(yes), the ssh host key of the device must match a ssh key present on
the host if set to C(no), the ssh host key of the device is not checked.
type: bool
default: yes
look_for_keys:
description:
- Enables looking in the usual locations for the ssh keys (e.g. :file:`~/.ssh/id_*`)
type: bool
default: yes
notes:
- For information on using netconf see the :ref:`Platform Options guide using Netconf<netconf_enabled_platform_options>`
- For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>`
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
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,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
1584,
3794,
7956,
272,
29970,
2594,
275,
519,
2344,
199,
1419,
26,
523,
1591,
26,
272,
1369,
26,
489,
446,
11015,
314,
10237,
1591,
536,
503,
2287,
367,
18170,
370,
314,
3982,
267,
2243,
1806,
314,
2013,
7773,
14,
221,
710,
574,
402,
1591,
365,
1202,
465,
267,
314,
5724,
2287,
367,
314,
7773,
14,
272,
730,
26,
620,
272,
1415,
26,
2549,
523,
1844,
26,
272,
1369,
26,
489,
446,
11015,
314,
1844,
370,
675,
1380,
10015,
314,
1950,
370,
314,
3982,
267,
2243,
14,
221,
710,
1844,
574,
911,
849,
370,
1844,
1695,
1216,
14,
272,
730,
26,
1109,
272,
849,
26,
1695,
1216,
523,
3434,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
3434,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
221,
961,
574,
365,
1202,
370,
12895,
267,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
267,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
11958,
9,
911,
506,
1202,
3140,
14,
272,
730,
26,
620,
523,
2505,
26,
272,
1369,
26,
489,
446,
11015,
314,
2505,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
257,
961,
574,
365,
1202,
370,
12895,
267,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
267,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
9032,
9,
911,
506,
1202,
3140,
14,
272,
730,
26,
620,
523,
2653,
26,
272,
1369,
26,
489,
446,
11015,
314,
2653,
315,
4696,
367,
13882,
1958,
543,
314,
2784,
2243,
267,
367,
1902,
18170,
503,
10209,
3718,
14,
221,
982,
314,
2653,
365,
267,
22007,
2544,
314,
3439,
365,
9709,
12,
314,
859,
911,
1125,
14,
272,
730,
26,
1109,
272,
849,
26,
1616,
523,
8635,
63,
21856,
26,
272,
1369,
26,
489,
446,
11015,
314,
12027,
790,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
257,
961,
574,
365,
314,
931,
370,
314,
790,
267,
1202,
370,
12895,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
267,
314,
2120,
12,
314,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
9,
267,
911,
506,
1202,
3140,
14,
272,
730,
26,
931,
523,
1591,
498,
63,
4712,
26,
272,
1369,
26,
489,
446,
982,
663,
370,
445,
8,
5066,
395,
314,
8635,
1591,
790,
402,
314,
2243,
1471,
1336,
282,
8635,
790,
3451,
641,
267,
314,
1591,
340,
663,
370,
445,
8,
889,
395,
314,
8635,
1591,
790,
402,
314,
2243,
365,
440,
7923,
14,
272,
730,
26,
2155,
272,
849,
26,
9456,
523,
3648,
63,
509,
63,
1612,
26,
272,
1369,
26,
489,
446,
3447,
5921,
10023,
315,
314,
20195,
9918,
367,
314,
8635,
2883,
334,
69,
14,
71,
14,
520,
493,
6054,
8083,
5510,
15,
344,
15192,
10522,
272,
730,
26,
2155,
272,
849,
26,
9456,
199,
5983,
26,
523,
446,
2104,
2556,
641,
1808,
1851,
2190,
1937,
314,
520,
1121,
1705,
10397,
8394,
22885,
1808,
5365,
2190,
28,
18242,
63,
3827,
63,
3246,
63,
1419,
8637,
523,
446,
2104,
1655,
2556,
641,
1808,
2622,
370,
9635,
2784,
7256,
1937,
314,
520,
1121,
1705,
10047,
7220,
15423,
665,
1200,
63,
17348,
8637,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
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,
421,
199,
533,
5673,
3768,
11080,
8,
785,
304,
339,
327,
9739,
1584,
3794,
7956,
272,
29970,
2594,
275,
519,
2344,
199,
1419,
26,
523,
1591,
26,
272,
1369,
26,
489,
446,
11015,
314,
10237,
1591,
536,
503,
2287,
367,
18170,
370,
314,
3982,
267,
2243,
1806,
314,
2013,
7773,
14,
221,
710,
574,
402,
1591,
365,
1202,
465,
267,
314,
5724,
2287,
367,
314,
7773,
14,
272,
730,
26,
620,
272,
1415,
26,
2549,
523,
1844,
26,
272,
1369,
26,
489,
446,
11015,
314,
1844,
370,
675,
1380,
10015,
314,
1950,
370,
314,
3982,
267,
2243,
14,
221,
710,
1844,
574,
911,
849,
370,
1844,
1695,
1216,
14,
272,
730,
26,
1109,
272,
849,
26,
1695,
1216,
523,
3434,
26,
272,
1369,
26,
489,
446,
4094,
1482,
314,
3434,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
221,
961,
574,
365,
1202,
370,
12895,
267,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
267,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
11958,
9,
911,
506,
1202,
3140,
14,
272,
730,
26,
620,
523,
2505,
26,
272,
1369,
26,
489,
446,
11015,
314,
2505,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
257,
961,
574,
365,
1202,
370,
12895,
267,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
314,
2120,
12,
314,
267,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
9032,
9,
911,
506,
1202,
3140,
14,
272,
730,
26,
620,
523,
2653,
26,
272,
1369,
26,
489,
446,
11015,
314,
2653,
315,
4696,
367,
13882,
1958,
543,
314,
2784,
2243,
267,
367,
1902,
18170,
503,
10209,
3718,
14,
221,
982,
314,
2653,
365,
267,
22007,
2544,
314,
3439,
365,
9709,
12,
314,
859,
911,
1125,
14,
272,
730,
26,
1109,
272,
849,
26,
1616,
523,
8635,
63,
21856,
26,
272,
1369,
26,
489,
446,
11015,
314,
12027,
790,
370,
675,
370,
12895,
314,
1950,
370,
267,
314,
3982,
2243,
14,
257,
961,
574,
365,
314,
931,
370,
314,
790,
267,
1202,
370,
12895,
314,
12027,
2351,
14,
982,
314,
574,
365,
440,
2013,
315,
267,
314,
2120,
12,
314,
574,
402,
3734,
1750,
445,
8,
8490,
63,
7278,
63,
13716,
63,
3078,
3817,
9,
267,
911,
506,
1202,
3140,
14,
272,
730,
26,
931,
523,
1591,
498,
63,
4712,
26,
272,
1369,
26,
489,
446,
982,
663,
370,
445,
8,
5066,
395,
314,
8635,
1591,
790,
402,
314,
2243,
1471,
1336,
282,
8635,
790,
3451,
641,
267,
314,
1591,
340,
663,
370,
445,
8,
889,
395,
314,
8635,
1591,
790,
402,
314,
2243,
365,
440,
7923,
14,
272,
730,
26,
2155,
272,
849,
26,
9456,
523,
3648,
63,
509,
63,
1612,
26,
272,
1369,
26,
489,
446,
3447,
5921,
10023,
315,
314,
20195,
9918,
367,
314,
8635,
2883,
334,
69,
14,
71,
14,
520,
493,
6054,
8083,
5510,
15,
344,
15192,
10522,
272,
730,
26,
2155,
272,
849,
26,
9456,
199,
5983,
26,
523,
446,
2104,
2556,
641,
1808,
1851,
2190,
1937,
314,
520,
1121,
1705,
10397,
8394,
22885,
1808,
5365,
2190,
28,
18242,
63,
3827,
63,
3246,
63,
1419,
8637,
523,
446,
2104,
1655,
2556,
641,
1808,
2622,
370,
9635,
2784,
7256,
1937,
314,
520,
1121,
1705,
10047,
7220,
15423,
665,
1200,
63,
17348,
8637,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
niftynei/zulip
|
contrib_bots/lib/help.py
|
25
|
1148
|
# See readme.md for instructions on running this code.
class HelpHandler(object):
def usage(self):
return '''
This plugin will give info about Zulip to
any user that types a message saying "help".
This is example code; ideally, you would flesh
this out for more useful help pertaining to
your Zulip instance.
'''
def triage_message(self, message, client):
# return True if we think the message may be of interest
original_content = message['content']
if message['type'] != 'stream':
return True
if original_content.lower().strip() != 'help':
return False
return True
def handle_message(self, message, client, state_handler):
help_content = '''
Info on Zulip can be found here:
https://github.com/zulip/zulip
'''.strip()
client.send_message(dict(
type='stream',
to=message['display_recipient'],
subject=message['subject'],
content=help_content,
))
handler_class = HelpHandler
|
apache-2.0
|
[
3,
1666,
1586,
278,
14,
1064,
367,
15794,
641,
3879,
642,
1233,
14,
199,
199,
533,
15456,
2461,
8,
785,
304,
272,
347,
4503,
8,
277,
304,
267,
372,
1449,
288,
961,
3589,
911,
8120,
2256,
3595,
3107,
11294,
370,
288,
1263,
922,
626,
2943,
282,
1245,
14722,
316,
298,
3437,
1674,
953,
961,
365,
2893,
1233,
27,
9979,
1183,
12,
1265,
3955,
289,
274,
609,
288,
642,
734,
367,
1655,
2997,
1720,
1126,
24522,
370,
288,
2195,
3107,
11294,
1256,
14,
288,
1449,
339,
347,
3229,
474,
63,
1188,
8,
277,
12,
1245,
12,
1890,
304,
267,
327,
372,
715,
340,
781,
13516,
314,
1245,
1443,
506,
402,
13518,
267,
3379,
63,
1317,
275,
1245,
459,
1317,
418,
398,
340,
1245,
459,
466,
418,
1137,
283,
1745,
356,
288,
372,
715,
398,
340,
3379,
63,
1317,
14,
2325,
1252,
1913,
342,
1137,
283,
3437,
356,
288,
372,
756,
398,
372,
715,
339,
347,
2429,
63,
1188,
8,
277,
12,
1245,
12,
1890,
12,
1174,
63,
2232,
304,
267,
1720,
63,
1317,
275,
1449,
288,
10332,
641,
3107,
11294,
883,
506,
1911,
2348,
26,
288,
4178,
921,
5031,
14,
957,
15,
14548,
15,
14548,
288,
1449,
14,
1913,
342,
398,
1890,
14,
2254,
63,
1188,
8,
807,
8,
288,
730,
534,
1745,
297,
288,
370,
29,
1188,
459,
2918,
63,
10043,
995,
288,
5420,
29,
1188,
459,
5875,
995,
288,
1564,
29,
3437,
63,
1317,
12,
267,
5082,
199,
199,
2232,
63,
533,
275,
15456,
2461,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1666,
1586,
278,
14,
1064,
367,
15794,
641,
3879,
642,
1233,
14,
199,
199,
533,
15456,
2461,
8,
785,
304,
272,
347,
4503,
8,
277,
304,
267,
372,
1449,
288,
961,
3589,
911,
8120,
2256,
3595,
3107,
11294,
370,
288,
1263,
922,
626,
2943,
282,
1245,
14722,
316,
298,
3437,
1674,
953,
961,
365,
2893,
1233,
27,
9979,
1183,
12,
1265,
3955,
289,
274,
609,
288,
642,
734,
367,
1655,
2997,
1720,
1126,
24522,
370,
288,
2195,
3107,
11294,
1256,
14,
288,
1449,
339,
347,
3229,
474,
63,
1188,
8,
277,
12,
1245,
12,
1890,
304,
267,
327,
372,
715,
340,
781,
13516,
314,
1245,
1443,
506,
402,
13518,
267,
3379,
63,
1317,
275,
1245,
459,
1317,
418,
398,
340,
1245,
459,
466,
418,
1137,
283,
1745,
356,
288,
372,
715,
398,
340,
3379,
63,
1317,
14,
2325,
1252,
1913,
342,
1137,
283,
3437,
356,
288,
372,
756,
398,
372,
715,
339,
347,
2429,
63,
1188,
8,
277,
12,
1245,
12,
1890,
12,
1174,
63,
2232,
304,
267,
1720,
63,
1317,
275,
1449,
288,
10332,
641,
3107,
11294,
883,
506,
1911,
2348,
26,
288,
4178,
921,
5031,
14,
957,
15,
14548,
15,
14548,
288,
1449,
14,
1913,
342,
398,
1890,
14,
2254,
63,
1188,
8,
807,
8,
288,
730,
534,
1745,
297,
288,
370,
29,
1188,
459,
2918,
63,
10043,
995,
288,
5420,
29,
1188,
459,
5875,
995,
288,
1564,
29,
3437,
63,
1317,
12,
267,
5082,
199,
199,
2232,
63,
533,
275,
15456,
2461,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
LinuxChristian/home-assistant
|
tests/conftest.py
|
14
|
3245
|
"""Setup some common test helper things."""
import asyncio
import functools
import logging
import os
from unittest.mock import patch, MagicMock
import pytest
import requests_mock as _requests_mock
from homeassistant import util, setup
from homeassistant.util import location
from homeassistant.components import mqtt
from tests.common import async_test_home_assistant, mock_coro, INSTANCES
from tests.test_util.aiohttp import mock_aiohttp_client
from tests.mock.zwave import MockNetwork, MockOption
if os.environ.get('UVLOOP') == '1':
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
def test_real(func):
"""Force a function to require a keyword _test_real to be passed in."""
@functools.wraps(func)
def guard_func(*args, **kwargs):
real = kwargs.pop('_test_real', None)
if not real:
raise Exception('Forgot to mock or pass "_test_real=True" to %s',
func.__name__)
return func(*args, **kwargs)
return guard_func
# Guard a few functions that would make network connections
location.detect_location_info = test_real(location.detect_location_info)
location.elevation = test_real(location.elevation)
util.get_local_ip = lambda: '127.0.0.1'
@pytest.fixture(autouse=True)
def verify_cleanup():
"""Verify that the test has cleaned up resources correctly."""
yield
if len(INSTANCES) >= 2:
count = len(INSTANCES)
for inst in INSTANCES:
inst.stop()
pytest.exit("Detected non stopped instances "
"({}), aborting test run".format(count))
@pytest.fixture
def hass(loop):
"""Fixture to provide a test instance of HASS."""
hass = loop.run_until_complete(async_test_home_assistant(loop))
yield hass
loop.run_until_complete(hass.async_stop())
@pytest.fixture
def requests_mock():
"""Fixture to provide a requests mocker."""
with _requests_mock.mock() as m:
yield m
@pytest.fixture
def aioclient_mock():
"""Fixture to mock aioclient calls."""
with mock_aiohttp_client() as mock_session:
yield mock_session
@pytest.fixture
def mqtt_mock(loop, hass):
"""Fixture to mock MQTT."""
with patch('homeassistant.components.mqtt.MQTT') as mock_mqtt:
mock_mqtt().async_connect.return_value = mock_coro(True)
assert loop.run_until_complete(setup.async_setup_component(
hass, mqtt.DOMAIN, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'mock-broker',
}
}))
client = mock_mqtt()
client.reset_mock()
return client
@pytest.fixture
def mock_openzwave():
"""Mock out Open Z-Wave."""
base_mock = MagicMock()
libopenzwave = base_mock.libopenzwave
libopenzwave.__file__ = 'test'
base_mock.network.ZWaveNetwork = MockNetwork
base_mock.option.ZWaveOption = MockOption
with patch.dict('sys.modules', {
'libopenzwave': libopenzwave,
'openzwave.option': base_mock.option,
'openzwave.network': base_mock.network,
'openzwave.group': base_mock.group,
}):
yield base_mock
|
apache-2.0
|
[
624,
8555,
2005,
2863,
511,
5922,
7645,
1041,
199,
646,
16195,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
504,
2882,
14,
1805,
492,
3371,
12,
10079,
199,
199,
646,
4613,
199,
646,
4145,
63,
1805,
465,
485,
6615,
63,
1805,
199,
199,
504,
8846,
492,
4884,
12,
3272,
199,
504,
8846,
14,
1974,
492,
2909,
199,
504,
8846,
14,
4608,
492,
22925,
199,
199,
504,
2295,
14,
2330,
492,
5316,
63,
396,
63,
4219,
63,
7310,
12,
1683,
63,
989,
79,
12,
20514,
879,
16734,
199,
504,
2295,
14,
396,
63,
1974,
14,
65,
24134,
492,
1683,
63,
65,
24134,
63,
1258,
199,
504,
2295,
14,
1805,
14,
90,
10024,
492,
4420,
4491,
12,
4420,
2602,
199,
199,
692,
747,
14,
2314,
14,
362,
360,
15110,
26573,
358,
508,
283,
17,
356,
272,
492,
20879,
3813,
272,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
9154,
3813,
14,
2390,
7382,
4845,
1012,
199,
199,
4806,
14,
19602,
342,
199,
4806,
14,
5572,
360,
14536,
14,
3908,
1959,
13548,
8,
4806,
14,
4531,
9,
421,
199,
318,
511,
63,
3093,
8,
1532,
304,
272,
408,
13606,
282,
805,
370,
4409,
282,
4252,
485,
396,
63,
3093,
370,
506,
3032,
315,
1041,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
24453,
63,
1532,
2031,
589,
12,
1011,
958,
304,
267,
3363,
275,
2074,
14,
1935,
6412,
396,
63,
3093,
297,
488,
9,
398,
340,
440,
3363,
26,
288,
746,
2186,
360,
38,
1308,
357,
370,
1683,
503,
986,
2668,
396,
63,
3093,
29,
549,
2,
370,
450,
83,
297,
1169,
2562,
855,
354,
3368,
398,
372,
2562,
2031,
589,
12,
1011,
958,
9,
339,
372,
24453,
63,
1532,
421,
199,
3,
12436,
1005,
282,
9284,
3423,
626,
3955,
1852,
2784,
6947,
199,
1985,
14,
13552,
63,
1985,
63,
815,
275,
511,
63,
3093,
8,
1985,
14,
13552,
63,
1985,
63,
815,
9,
199,
1985,
14,
32568,
275,
511,
63,
3093,
8,
1985,
14,
32568,
9,
199,
1974,
14,
362,
63,
1832,
63,
711,
275,
2400,
26,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
4911,
63,
7661,
837,
272,
408,
7496,
626,
314,
511,
965,
12364,
1536,
5944,
6657,
1041,
272,
1995,
339,
340,
822,
8,
7834,
879,
16734,
9,
2356,
499,
26,
267,
2338,
275,
822,
8,
7834,
879,
16734,
9,
267,
367,
2727,
315,
20514,
879,
16734,
26,
288,
2727,
14,
2379,
342,
267,
4613,
14,
2224,
480,
872,
4530,
2222,
15248,
4454,
298,
490,
7340,
2440,
395,
12004,
316,
511,
1255,
1674,
908,
8,
835,
430,
421,
199,
32,
4462,
14,
5997,
199,
318,
6298,
8,
3813,
304,
272,
408,
12812,
370,
5647,
282,
511,
1256,
402,
869,
3755,
1041,
272,
6298,
275,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
4146,
63,
396,
63,
4219,
63,
7310,
8,
3813,
430,
339,
1995,
6298,
339,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
5387,
14,
4146,
63,
2379,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
4145,
63,
1805,
837,
272,
408,
12812,
370,
5647,
282,
4145,
15981,
1041,
272,
543,
485,
6615,
63,
1805,
14,
1805,
342,
465,
333,
26,
267,
1995,
333,
421,
199,
32,
4462,
14,
5997,
199,
318,
15933,
679,
864,
63,
1805,
837,
272,
408,
12812,
370,
1683,
15933,
679,
864,
4882,
1041,
272,
543,
1683,
63,
65,
24134,
63,
1258,
342,
465,
1683,
63,
1730,
26,
267,
1995,
1683,
63,
1730,
421,
199,
32,
4462,
14,
5997,
199,
318,
22925,
63,
1805,
8,
3813,
12,
6298,
304,
272,
408,
12812,
370,
1683,
603,
49,
1481,
1041,
272,
543,
3371,
360,
22799,
14,
4608,
14,
19214,
14,
14449,
1481,
358,
465,
1683,
63,
19214,
26,
267,
1683,
63,
19214,
1252,
4146,
63,
2242,
14,
1107,
63,
585,
275,
1683,
63,
989,
79,
8,
549,
9,
267,
702,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
2758,
14,
4146,
63,
2758,
63,
3173,
8,
288,
6298,
12,
22925,
14,
7378,
12,
469,
355,
22925,
14,
7378,
26,
469,
490,
22925,
14,
3103,
63,
21111,
19972,
26,
283,
1805,
13,
16620,
297,
355,
789,
288,
23451,
267,
1890,
275,
1683,
63,
19214,
342,
267,
1890,
14,
3958,
63,
1805,
342,
267,
372,
1890,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
1490,
90,
10024,
837,
272,
408,
3346,
734,
3232,
3107,
13,
21393,
1041,
272,
1300,
63,
1805,
275,
10079,
342,
272,
1973,
1490,
90,
10024,
275,
1300,
63,
1805,
14,
773,
1490,
90,
10024,
272,
1973,
1490,
90,
10024,
855,
493,
363,
275,
283,
396,
7,
272,
1300,
63,
1805,
14,
1200,
14,
14324,
811,
4491,
275,
4420,
4491,
272,
1300,
63,
1805,
14,
1422,
14,
14324,
811,
2602,
275,
4420,
2602,
339,
543,
3371,
14,
807,
360,
1274,
14,
3112,
297,
469,
267,
283,
773,
1490,
90,
10024,
356,
1973,
1490,
90,
10024,
12,
267,
283,
1490,
90,
10024,
14,
1422,
356,
1300,
63,
1805,
14,
1422,
12,
267,
283,
1490,
90,
10024,
14,
1200,
356,
1300,
63,
1805,
14,
1200,
12,
267,
283,
1490,
90,
10024,
14,
923,
356,
1300,
63,
1805,
14,
923,
12,
272,
789,
304,
267,
1995,
1300,
63,
1805,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8555,
2005,
2863,
511,
5922,
7645,
1041,
199,
646,
16195,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
504,
2882,
14,
1805,
492,
3371,
12,
10079,
199,
199,
646,
4613,
199,
646,
4145,
63,
1805,
465,
485,
6615,
63,
1805,
199,
199,
504,
8846,
492,
4884,
12,
3272,
199,
504,
8846,
14,
1974,
492,
2909,
199,
504,
8846,
14,
4608,
492,
22925,
199,
199,
504,
2295,
14,
2330,
492,
5316,
63,
396,
63,
4219,
63,
7310,
12,
1683,
63,
989,
79,
12,
20514,
879,
16734,
199,
504,
2295,
14,
396,
63,
1974,
14,
65,
24134,
492,
1683,
63,
65,
24134,
63,
1258,
199,
504,
2295,
14,
1805,
14,
90,
10024,
492,
4420,
4491,
12,
4420,
2602,
199,
199,
692,
747,
14,
2314,
14,
362,
360,
15110,
26573,
358,
508,
283,
17,
356,
272,
492,
20879,
3813,
272,
16195,
14,
409,
63,
1430,
63,
3813,
63,
3185,
8,
9154,
3813,
14,
2390,
7382,
4845,
1012,
199,
199,
4806,
14,
19602,
342,
199,
4806,
14,
5572,
360,
14536,
14,
3908,
1959,
13548,
8,
4806,
14,
4531,
9,
421,
199,
318,
511,
63,
3093,
8,
1532,
304,
272,
408,
13606,
282,
805,
370,
4409,
282,
4252,
485,
396,
63,
3093,
370,
506,
3032,
315,
1041,
272,
768,
17869,
14,
13582,
8,
1532,
9,
272,
347,
24453,
63,
1532,
2031,
589,
12,
1011,
958,
304,
267,
3363,
275,
2074,
14,
1935,
6412,
396,
63,
3093,
297,
488,
9,
398,
340,
440,
3363,
26,
288,
746,
2186,
360,
38,
1308,
357,
370,
1683,
503,
986,
2668,
396,
63,
3093,
29,
549,
2,
370,
450,
83,
297,
1169,
2562,
855,
354,
3368,
398,
372,
2562,
2031,
589,
12,
1011,
958,
9,
339,
372,
24453,
63,
1532,
421,
199,
3,
12436,
1005,
282,
9284,
3423,
626,
3955,
1852,
2784,
6947,
199,
1985,
14,
13552,
63,
1985,
63,
815,
275,
511,
63,
3093,
8,
1985,
14,
13552,
63,
1985,
63,
815,
9,
199,
1985,
14,
32568,
275,
511,
63,
3093,
8,
1985,
14,
32568,
9,
199,
1974,
14,
362,
63,
1832,
63,
711,
275,
2400,
26,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
4911,
63,
7661,
837,
272,
408,
7496,
626,
314,
511,
965,
12364,
1536,
5944,
6657,
1041,
272,
1995,
339,
340,
822,
8,
7834,
879,
16734,
9,
2356,
499,
26,
267,
2338,
275,
822,
8,
7834,
879,
16734,
9,
267,
367,
2727,
315,
20514,
879,
16734,
26,
288,
2727,
14,
2379,
342,
267,
4613,
14,
2224,
480,
872,
4530,
2222,
15248,
4454,
298,
490,
7340,
2440,
395,
12004,
316,
511,
1255,
1674,
908,
8,
835,
430,
421,
199,
32,
4462,
14,
5997,
199,
318,
6298,
8,
3813,
304,
272,
408,
12812,
370,
5647,
282,
511,
1256,
402,
869,
3755,
1041,
272,
6298,
275,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
4146,
63,
396,
63,
4219,
63,
7310,
8,
3813,
430,
339,
1995,
6298,
339,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
5387,
14,
4146,
63,
2379,
1012,
421,
199,
32,
4462,
14,
5997,
199,
318,
4145,
63,
1805,
837,
272,
408,
12812,
370,
5647,
282,
4145,
15981,
1041,
272,
543,
485,
6615,
63,
1805,
14,
1805,
342,
465,
333,
26,
267,
1995,
333,
421,
199,
32,
4462,
14,
5997,
199,
318,
15933,
679,
864,
63,
1805,
837,
272,
408,
12812,
370,
1683,
15933,
679,
864,
4882,
1041,
272,
543,
1683,
63,
65,
24134,
63,
1258,
342,
465,
1683,
63,
1730,
26,
267,
1995,
1683,
63,
1730,
421,
199,
32,
4462,
14,
5997,
199,
318,
22925,
63,
1805,
8,
3813,
12,
6298,
304,
272,
408,
12812,
370,
1683,
603,
49,
1481,
1041,
272,
543,
3371,
360,
22799,
14,
4608,
14,
19214,
14,
14449,
1481,
358,
465,
1683,
63,
19214,
26,
267,
1683,
63,
19214,
1252,
4146,
63,
2242,
14,
1107,
63,
585,
275,
1683,
63,
989,
79,
8,
549,
9,
267,
702,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
2758,
14,
4146,
63,
2758,
63,
3173,
8,
288,
6298,
12,
22925,
14,
7378,
12,
469,
355,
22925,
14,
7378,
26,
469,
490,
22925,
14,
3103,
63,
21111,
19972,
26,
283,
1805,
13,
16620,
297,
355,
789,
288,
23451,
267,
1890,
275,
1683,
63,
19214,
342,
267,
1890,
14,
3958,
63,
1805,
342,
267,
372,
1890,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
1490,
90,
10024,
837,
272,
408,
3346,
734,
3232,
3107,
13,
21393,
1041,
272,
1300,
63,
1805,
275,
10079,
342,
272,
1973,
1490,
90,
10024,
275,
1300,
63,
1805,
14,
773,
1490,
90,
10024,
272,
1973,
1490,
90,
10024,
855,
493,
363,
275,
283,
396,
7,
272,
1300,
63,
1805,
14,
1200,
14,
14324,
811,
4491,
275,
4420,
4491,
272,
1300,
63,
1805,
14,
1422,
14,
14324,
811,
2602,
275,
4420,
2602,
339,
543,
3371,
14,
807,
360,
1274,
14,
3112,
297,
469,
267,
283,
773,
1490,
90,
10024,
356,
1973,
1490,
90,
10024,
12,
267,
283,
1490,
90,
10024,
14,
1422,
356,
1300,
63,
1805,
14,
1422,
12,
267,
283,
1490,
90,
10024,
14,
1200,
356,
1300,
63,
1805,
14,
1200,
12,
267,
283,
1490,
90,
10024,
14,
923,
356,
1300,
63,
1805,
14,
923,
12,
272,
789,
304,
267,
1995,
1300,
63,
1805,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
chuan9/chromium-crosswalk
|
third_party/typ/typ/runner.py
|
25
|
31522
|
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import fnmatch
import importlib
import inspect
import json
import os
import pdb
import sys
import unittest
from collections import OrderedDict
# This ensures that absolute imports of typ modules will work when
# running typ/runner.py as a script even if typ is not installed.
# We need this entry in addition to the one in __main__.py to ensure
# that typ/runner.py works when invoked via subprocess on windows in
# _spawn_main().
path_to_file = os.path.realpath(__file__)
if path_to_file.endswith('.pyc'): # pragma: no cover
path_to_file = path_to_file[:-1]
dir_above_typ = os.path.dirname(os.path.dirname(path_to_file))
if dir_above_typ not in sys.path: # pragma: no cover
sys.path.append(dir_above_typ)
from typ import json_results
from typ.arg_parser import ArgumentParser
from typ.host import Host
from typ.pool import make_pool
from typ.stats import Stats
from typ.printer import Printer
from typ.test_case import TestCase as TypTestCase
from typ.version import VERSION
Result = json_results.Result
ResultSet = json_results.ResultSet
ResultType = json_results.ResultType
def main(argv=None, host=None, win_multiprocessing=None, **defaults):
host = host or Host()
runner = Runner(host=host)
if win_multiprocessing is not None:
runner.win_multiprocessing = win_multiprocessing
return runner.main(argv, **defaults)
class TestInput(object):
def __init__(self, name, msg='', timeout=None, expected=None):
self.name = name
self.msg = msg
self.timeout = timeout
self.expected = expected
class TestSet(object):
def __init__(self, parallel_tests=None, isolated_tests=None,
tests_to_skip=None):
def promote(tests):
tests = tests or []
return [test if isinstance(test, TestInput) else TestInput(test)
for test in tests]
self.parallel_tests = promote(parallel_tests)
self.isolated_tests = promote(isolated_tests)
self.tests_to_skip = promote(tests_to_skip)
class WinMultiprocessing(object):
ignore = 'ignore'
importable = 'importable'
spawn = 'spawn'
values = [ignore, importable, spawn]
class _AddTestsError(Exception):
pass
class Runner(object):
def __init__(self, host=None):
self.args = None
self.classifier = None
self.cov = None
self.context = None
self.coverage_source = None
self.host = host or Host()
self.loader = unittest.loader.TestLoader()
self.printer = None
self.setup_fn = None
self.stats = None
self.teardown_fn = None
self.top_level_dir = None
self.win_multiprocessing = WinMultiprocessing.spawn
self.final_responses = []
# initialize self.args to the defaults.
parser = ArgumentParser(self.host)
self.parse_args(parser, [])
def main(self, argv=None, **defaults):
parser = ArgumentParser(self.host)
self.parse_args(parser, argv, **defaults)
if parser.exit_status is not None:
return parser.exit_status
try:
ret, _, _ = self.run()
return ret
except KeyboardInterrupt:
self.print_("interrupted, exiting", stream=self.host.stderr)
return 130
def parse_args(self, parser, argv, **defaults):
for attrname in defaults:
if not hasattr(self.args, attrname):
parser.error("Unknown default argument name '%s'" % attrname,
bailout=False)
return
parser.set_defaults(**defaults)
self.args = parser.parse_args(args=argv)
if parser.exit_status is not None:
return
def print_(self, msg='', end='\n', stream=None):
self.host.print_(msg, end, stream=stream)
def run(self, test_set=None):
ret = 0
h = self.host
if self.args.version:
self.print_(VERSION)
return ret, None, None
should_spawn = self._check_win_multiprocessing()
if should_spawn:
return self._spawn(test_set)
ret = self._set_up_runner()
if ret: # pragma: no cover
return ret, None, None
find_start = h.time()
if self.cov: # pragma: no cover
self.cov.erase()
self.cov.start()
full_results = None
result_set = ResultSet()
if not test_set:
ret, test_set = self.find_tests(self.args)
find_end = h.time()
if not ret:
ret, full_results = self._run_tests(result_set, test_set)
if self.cov: # pragma: no cover
self.cov.stop()
self.cov.save()
test_end = h.time()
trace = self._trace_from_results(result_set)
if full_results:
self._summarize(full_results)
self._write(self.args.write_full_results_to, full_results)
upload_ret = self._upload(full_results)
if not ret:
ret = upload_ret
reporting_end = h.time()
self._add_trace_event(trace, 'run', find_start, reporting_end)
self._add_trace_event(trace, 'discovery', find_start, find_end)
self._add_trace_event(trace, 'testing', find_end, test_end)
self._add_trace_event(trace, 'reporting', test_end, reporting_end)
self._write(self.args.write_trace_to, trace)
self.report_coverage()
else:
upload_ret = 0
return ret, full_results, trace
def _check_win_multiprocessing(self):
wmp = self.win_multiprocessing
ignore, importable, spawn = WinMultiprocessing.values
if wmp not in WinMultiprocessing.values:
raise ValueError('illegal value %s for win_multiprocessing' %
wmp)
h = self.host
if wmp == ignore and h.platform == 'win32': # pragma: win32
raise ValueError('Cannot use WinMultiprocessing.ignore for '
'win_multiprocessing when actually running '
'on Windows.')
if wmp == ignore or self.args.jobs == 1:
return False
if wmp == importable:
if self._main_is_importable():
return False
raise ValueError('The __main__ module (%s) ' # pragma: no cover
'may not be importable' %
sys.modules['__main__'].__file__)
assert wmp == spawn
return True
def _main_is_importable(self): # pragma: untested
path = sys.modules['__main__'].__file__
if not path:
return False
if path.endswith('.pyc'):
path = path[:-1]
if not path.endswith('.py'):
return False
if path.endswith('__main__.py'):
# main modules are not directly importable.
return False
path = self.host.realpath(path)
for d in sys.path:
if path.startswith(self.host.realpath(d)):
return True
return False # pragma: no cover
def _spawn(self, test_set):
# TODO: Handle picklable hooks, rather than requiring them to be None.
assert self.classifier is None
assert self.context is None
assert self.setup_fn is None
assert self.teardown_fn is None
assert test_set is None
h = self.host
if self.args.write_trace_to: # pragma: untested
should_delete_trace = False
else:
should_delete_trace = True
fp = h.mktempfile(delete=False)
fp.close()
self.args.write_trace_to = fp.name
if self.args.write_full_results_to: # pragma: untested
should_delete_results = False
else:
should_delete_results = True
fp = h.mktempfile(delete=False)
fp.close()
self.args.write_full_results_to = fp.name
argv = ArgumentParser(h).argv_from_args(self.args)
ret = h.call_inline([h.python_interpreter, path_to_file] + argv)
trace = self._read_and_delete(self.args.write_trace_to,
should_delete_trace)
full_results = self._read_and_delete(self.args.write_full_results_to,
should_delete_results)
return ret, full_results, trace
def _set_up_runner(self):
h = self.host
args = self.args
self.stats = Stats(args.status_format, h.time, args.jobs)
self.printer = Printer(
self.print_, args.overwrite, args.terminal_width)
self.top_level_dir = args.top_level_dir
if not self.top_level_dir:
if args.tests and h.isdir(args.tests[0]):
# TODO: figure out what to do if multiple files are
# specified and they don't all have the same correct
# top level dir.
if h.exists(h.dirname(args.tests[0]), '__init__.py'):
top_dir = h.dirname(args.tests[0])
else:
top_dir = args.tests[0]
else:
top_dir = h.getcwd()
while h.exists(top_dir, '__init__.py'):
top_dir = h.dirname(top_dir)
self.top_level_dir = h.realpath(top_dir)
h.add_to_path(self.top_level_dir)
for path in args.path:
h.add_to_path(path)
if args.coverage: # pragma: no cover
try:
import coverage
except ImportError:
h.print_("Error: coverage is not installed")
return 1
source = self.args.coverage_source
if not source:
source = [self.top_level_dir] + self.args.path
self.coverage_source = source
self.cov = coverage.coverage(source=self.coverage_source,
data_suffix=True)
self.cov.erase()
return 0
def find_tests(self, args):
test_set = TestSet()
orig_skip = unittest.skip
orig_skip_if = unittest.skipIf
if args.all:
unittest.skip = lambda reason: lambda x: x
unittest.skipIf = lambda condition, reason: lambda x: x
try:
names = self._name_list_from_args(args)
classifier = self.classifier or _default_classifier(args)
for name in names:
try:
self._add_tests_to_set(test_set, args.suffixes,
self.top_level_dir, classifier,
name)
except (AttributeError, ImportError, SyntaxError) as e:
self.print_('Failed to load "%s": %s' % (name, e))
return 1, None
except _AddTestsError as e:
self.print_(str(e))
return 1, None
# TODO: Add support for discovering setupProcess/teardownProcess?
test_set.parallel_tests = _sort_inputs(test_set.parallel_tests)
test_set.isolated_tests = _sort_inputs(test_set.isolated_tests)
test_set.tests_to_skip = _sort_inputs(test_set.tests_to_skip)
return 0, test_set
finally:
unittest.skip = orig_skip
unittest.skipIf = orig_skip_if
def _name_list_from_args(self, args):
if args.tests:
names = args.tests
elif args.file_list:
if args.file_list == '-':
s = self.host.stdin.read()
else:
s = self.host.read_text_file(args.file_list)
names = [line.strip() for line in s.splitlines()]
else:
names = [self.top_level_dir]
return names
def _add_tests_to_set(self, test_set, suffixes, top_level_dir, classifier,
name):
h = self.host
loader = self.loader
add_tests = _test_adder(test_set, classifier)
if h.isfile(name):
rpath = h.relpath(name, top_level_dir)
if rpath.endswith('.py'):
rpath = rpath[:-3]
module = rpath.replace(h.sep, '.')
add_tests(loader.loadTestsFromName(module))
elif h.isdir(name):
for suffix in suffixes:
add_tests(loader.discover(name, suffix, top_level_dir))
else:
possible_dir = name.replace('.', h.sep)
if h.isdir(top_level_dir, possible_dir):
for suffix in suffixes:
path = h.join(top_level_dir, possible_dir)
suite = loader.discover(path, suffix, top_level_dir)
add_tests(suite)
else:
add_tests(loader.loadTestsFromName(name))
def _run_tests(self, result_set, test_set):
h = self.host
if not test_set.parallel_tests and not test_set.isolated_tests:
self.print_('No tests to run.')
return 1, None
all_tests = [ti.name for ti in
_sort_inputs(test_set.parallel_tests +
test_set.isolated_tests +
test_set.tests_to_skip)]
if self.args.list_only:
self.print_('\n'.join(all_tests))
return 0, None
self._run_one_set(self.stats, result_set, test_set)
failed_tests = sorted(json_results.failed_test_names(result_set))
retry_limit = self.args.retry_limit
while retry_limit and failed_tests:
if retry_limit == self.args.retry_limit:
self.flush()
self.args.overwrite = False
self.printer.should_overwrite = False
self.args.verbose = min(self.args.verbose, 1)
self.print_('')
self.print_('Retrying failed tests (attempt #%d of %d)...' %
(self.args.retry_limit - retry_limit + 1,
self.args.retry_limit))
self.print_('')
stats = Stats(self.args.status_format, h.time, 1)
stats.total = len(failed_tests)
tests_to_retry = TestSet(isolated_tests=list(failed_tests))
retry_set = ResultSet()
self._run_one_set(stats, retry_set, tests_to_retry)
result_set.results.extend(retry_set.results)
failed_tests = json_results.failed_test_names(retry_set)
retry_limit -= 1
if retry_limit != self.args.retry_limit:
self.print_('')
full_results = json_results.make_full_results(self.args.metadata,
int(h.time()),
all_tests, result_set)
return (json_results.exit_code_from_full_results(full_results),
full_results)
def _run_one_set(self, stats, result_set, test_set):
stats.total = (len(test_set.parallel_tests) +
len(test_set.isolated_tests) +
len(test_set.tests_to_skip))
self._skip_tests(stats, result_set, test_set.tests_to_skip)
self._run_list(stats, result_set,
test_set.parallel_tests, self.args.jobs)
self._run_list(stats, result_set,
test_set.isolated_tests, 1)
def _skip_tests(self, stats, result_set, tests_to_skip):
for test_input in tests_to_skip:
last = self.host.time()
stats.started += 1
self._print_test_started(stats, test_input)
now = self.host.time()
result = Result(test_input.name, actual=ResultType.Skip,
started=last, took=(now - last), worker=0,
expected=[ResultType.Skip],
out=test_input.msg)
result_set.add(result)
stats.finished += 1
self._print_test_finished(stats, result)
def _run_list(self, stats, result_set, test_inputs, jobs):
h = self.host
running_jobs = set()
jobs = min(len(test_inputs), jobs)
if not jobs:
return
child = _Child(self)
pool = make_pool(h, jobs, _run_one_test, child,
_setup_process, _teardown_process)
try:
while test_inputs or running_jobs:
while test_inputs and (len(running_jobs) < self.args.jobs):
test_input = test_inputs.pop(0)
stats.started += 1
pool.send(test_input)
running_jobs.add(test_input.name)
self._print_test_started(stats, test_input)
result = pool.get()
running_jobs.remove(result.name)
result_set.add(result)
stats.finished += 1
self._print_test_finished(stats, result)
pool.close()
finally:
self.final_responses.extend(pool.join())
def _print_test_started(self, stats, test_input):
if not self.args.quiet and self.args.overwrite:
self.update(stats.format() + test_input.name,
elide=(not self.args.verbose))
def _print_test_finished(self, stats, result):
stats.add_time()
assert result.actual in [ResultType.Failure, ResultType.Skip,
ResultType.Pass]
if result.actual == ResultType.Failure:
result_str = ' failed'
elif result.actual == ResultType.Skip:
result_str = ' was skipped'
elif result.actual == ResultType.Pass:
result_str = ' passed'
if result.unexpected:
result_str += ' unexpectedly'
if self.args.timing:
timing_str = ' %.4fs' % result.took
else:
timing_str = ''
suffix = '%s%s' % (result_str, timing_str)
out = result.out
err = result.err
if result.code:
if out or err:
suffix += ':\n'
self.update(stats.format() + result.name + suffix, elide=False)
for l in out.splitlines():
self.print_(' %s' % l)
for l in err.splitlines():
self.print_(' %s' % l)
elif not self.args.quiet:
if self.args.verbose > 1 and (out or err):
suffix += ':\n'
self.update(stats.format() + result.name + suffix,
elide=(not self.args.verbose))
if self.args.verbose > 1:
for l in out.splitlines():
self.print_(' %s' % l)
for l in err.splitlines():
self.print_(' %s' % l)
if self.args.verbose:
self.flush()
def update(self, msg, elide):
self.printer.update(msg, elide)
def flush(self):
self.printer.flush()
def _summarize(self, full_results):
num_tests = self.stats.finished
num_failures = json_results.num_failures(full_results)
if self.args.quiet and num_failures == 0:
return
if self.args.timing:
timing_clause = ' in %.1fs' % (self.host.time() -
self.stats.started_time)
else:
timing_clause = ''
self.update('%d test%s run%s, %d failure%s.' %
(num_tests,
'' if num_tests == 1 else 's',
timing_clause,
num_failures,
'' if num_failures == 1 else 's'), elide=False)
self.print_()
def _read_and_delete(self, path, delete):
h = self.host
obj = None
if h.exists(path):
contents = h.read_text_file(path)
if contents:
obj = json.loads(contents)
if delete:
h.remove(path)
return obj
def _write(self, path, obj):
if path:
self.host.write_text_file(path, json.dumps(obj, indent=2) + '\n')
def _upload(self, full_results):
h = self.host
if not self.args.test_results_server:
return 0
url, content_type, data = json_results.make_upload_request(
self.args.test_results_server, self.args.builder_name,
self.args.master_name, self.args.test_type,
full_results)
try:
h.fetch(url, data, {'Content-Type': content_type})
return 0
except Exception as e:
h.print_('Uploading the JSON results raised "%s"' % str(e))
return 1
def report_coverage(self):
if self.args.coverage: # pragma: no cover
self.host.print_()
import coverage
cov = coverage.coverage(data_suffix=True)
cov.combine()
cov.report(show_missing=self.args.coverage_show_missing,
omit=self.args.coverage_omit)
def _add_trace_event(self, trace, name, start, end):
event = {
'name': name,
'ts': int((start - self.stats.started_time) * 1000000),
'dur': int((end - start) * 1000000),
'ph': 'X',
'pid': self.host.getpid(),
'tid': 0,
}
trace['traceEvents'].append(event)
def _trace_from_results(self, result_set):
trace = OrderedDict()
trace['traceEvents'] = []
trace['otherData'] = {}
for m in self.args.metadata:
k, v = m.split('=')
trace['otherData'][k] = v
for result in result_set.results:
started = int((result.started - self.stats.started_time) * 1000000)
took = int(result.took * 1000000)
event = OrderedDict()
event['name'] = result.name
event['dur'] = took
event['ts'] = started
event['ph'] = 'X' # "Complete" events
event['pid'] = result.pid
event['tid'] = result.worker
args = OrderedDict()
args['expected'] = sorted(str(r) for r in result.expected)
args['actual'] = str(result.actual)
args['out'] = result.out
args['err'] = result.err
args['code'] = result.code
args['unexpected'] = result.unexpected
args['flaky'] = result.flaky
event['args'] = args
trace['traceEvents'].append(event)
return trace
def _matches(name, globs):
return any(fnmatch.fnmatch(name, glob) for glob in globs)
def _default_classifier(args):
def default_classifier(test_set, test):
name = test.id()
if not args.all and _matches(name, args.skip):
test_set.tests_to_skip.append(TestInput(name,
'skipped by request'))
elif _matches(name, args.isolate):
test_set.isolated_tests.append(TestInput(name))
else:
test_set.parallel_tests.append(TestInput(name))
return default_classifier
def _test_adder(test_set, classifier):
def add_tests(obj):
if isinstance(obj, unittest.suite.TestSuite):
for el in obj:
add_tests(el)
elif (obj.id().startswith('unittest.loader.LoadTestsFailure') or
obj.id().startswith('unittest.loader.ModuleImportFailure')):
# Access to protected member pylint: disable=W0212
module_name = obj._testMethodName
try:
method = getattr(obj, obj._testMethodName)
method()
except Exception as e:
if 'LoadTests' in obj.id():
raise _AddTestsError('%s.load_tests() failed: %s'
% (module_name, str(e)))
else:
raise _AddTestsError(str(e))
else:
assert isinstance(obj, unittest.TestCase)
classifier(test_set, obj)
return add_tests
class _Child(object):
def __init__(self, parent):
self.host = None
self.worker_num = None
self.all = parent.args.all
self.debugger = parent.args.debugger
self.coverage = parent.args.coverage and parent.args.jobs > 1
self.coverage_source = parent.coverage_source
self.dry_run = parent.args.dry_run
self.loader = parent.loader
self.passthrough = parent.args.passthrough
self.context = parent.context
self.setup_fn = parent.setup_fn
self.teardown_fn = parent.teardown_fn
self.context_after_setup = None
self.top_level_dir = parent.top_level_dir
self.loaded_suites = {}
self.cov = None
def _setup_process(host, worker_num, child):
child.host = host
child.worker_num = worker_num
if child.coverage: # pragma: no cover
import coverage
child.cov = coverage.coverage(source=child.coverage_source,
data_suffix=True)
child.cov._warn_no_data = False
child.cov.start()
if child.setup_fn:
child.context_after_setup = child.setup_fn(child, child.context)
else:
child.context_after_setup = child.context
return child
def _teardown_process(child):
res = None
e = None
if child.teardown_fn:
try:
res = child.teardown_fn(child, child.context_after_setup)
except Exception as e:
pass
if child.cov: # pragma: no cover
child.cov.stop()
child.cov.save()
return (child.worker_num, res, e)
def _run_one_test(child, test_input):
h = child.host
pid = h.getpid()
test_name = test_input.name
start = h.time()
# It is important to capture the output before loading the test
# to ensure that
# 1) the loader doesn't logs something we don't captured
# 2) neither the loader nor the test case grab a reference to the
# uncaptured stdout or stderr that later is used when the test is run.
# This comes up when using the FakeTestLoader and testing typ itself,
# but could come up when testing non-typ code as well.
h.capture_output(divert=not child.passthrough)
try:
orig_skip = unittest.skip
orig_skip_if = unittest.skipIf
if child.all:
unittest.skip = lambda reason: lambda x: x
unittest.skipIf = lambda condition, reason: lambda x: x
try:
suite = child.loader.loadTestsFromName(test_name)
except Exception:
suite = _load_via_load_tests(child, test_name)
finally:
unittest.skip = orig_skip
unittest.skipIf = orig_skip_if
tests = list(suite)
if len(tests) != 1:
err = 'failed to load %s' % test_name
h.restore_output()
return Result(test_name, ResultType.Failure, start, 0,
child.worker_num, unexpected=True, code=1,
err=err, pid=pid)
test_case = tests[0]
if isinstance(test_case, TypTestCase):
test_case.child = child
test_case.context = child.context_after_setup
test_result = unittest.TestResult()
out = ''
err = ''
try:
if child.dry_run:
pass
elif child.debugger: # pragma: no cover
_run_under_debugger(h, test_case, suite, test_result)
else:
suite.run(test_result)
finally:
out, err = h.restore_output()
took = h.time() - start
return _result_from_test_result(test_result, test_name, start, took, out,
err, child.worker_num, pid)
def _run_under_debugger(host, test_case, suite,
test_result): # pragma: no cover
# Access to protected member pylint: disable=W0212
test_func = getattr(test_case, test_case._testMethodName)
fname = inspect.getsourcefile(test_func)
lineno = inspect.getsourcelines(test_func)[1] + 1
dbg = pdb.Pdb(stdout=host.stdout.stream)
dbg.set_break(fname, lineno)
dbg.runcall(suite.run, test_result)
def _result_from_test_result(test_result, test_name, start, took, out, err,
worker_num, pid):
flaky = False
if test_result.failures:
expected = [ResultType.Pass]
actual = ResultType.Failure
code = 1
unexpected = True
err = err + test_result.failures[0][1]
elif test_result.errors:
expected = [ResultType.Pass]
actual = ResultType.Failure
code = 1
unexpected = True
err = err + test_result.errors[0][1]
elif test_result.skipped:
expected = [ResultType.Skip]
actual = ResultType.Skip
err = err + test_result.skipped[0][1]
code = 0
unexpected = False
elif test_result.expectedFailures:
expected = [ResultType.Failure]
actual = ResultType.Failure
code = 1
err = err + test_result.expectedFailures[0][1]
unexpected = False
elif test_result.unexpectedSuccesses:
expected = [ResultType.Failure]
actual = ResultType.Pass
code = 0
unexpected = True
else:
expected = [ResultType.Pass]
actual = ResultType.Pass
code = 0
unexpected = False
return Result(test_name, actual, start, took, worker_num,
expected, unexpected, flaky, code, out, err, pid)
def _load_via_load_tests(child, test_name):
# If we couldn't import a test directly, the test may be only loadable
# via unittest's load_tests protocol. See if we can find a load_tests
# entry point that will work for this test.
loader = child.loader
comps = test_name.split('.')
new_suite = unittest.TestSuite()
while comps:
name = '.'.join(comps)
module = None
suite = None
if name not in child.loaded_suites:
try:
module = importlib.import_module(name)
except ImportError:
pass
if module:
suite = loader.loadTestsFromModule(module)
child.loaded_suites[name] = suite
suite = child.loaded_suites[name]
if suite:
for test_case in suite:
assert isinstance(test_case, unittest.TestCase)
if test_case.id() == test_name:
new_suite.addTest(test_case)
break
comps.pop()
return new_suite
def _sort_inputs(inps):
return sorted(inps, key=lambda inp: inp.name)
if __name__ == '__main__': # pragma: no cover
sys.modules['__main__'].__file__ = path_to_file
sys.exit(main(win_multiprocessing=WinMultiprocessing.importable))
|
bsd-3-clause
|
[
3,
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
15951,
199,
646,
14802,
199,
646,
6485,
199,
646,
2022,
199,
646,
747,
199,
646,
10543,
199,
646,
984,
199,
646,
2882,
199,
199,
504,
5055,
492,
8773,
199,
199,
3,
961,
15620,
626,
3679,
8925,
402,
6211,
4621,
911,
1736,
1380,
199,
3,
3879,
6211,
15,
5933,
14,
647,
465,
282,
2884,
2755,
340,
6211,
365,
440,
4903,
14,
199,
3,
2136,
1929,
642,
2397,
315,
10234,
370,
314,
1373,
315,
636,
973,
4343,
647,
370,
4868,
199,
3,
626,
6211,
15,
5933,
14,
647,
5419,
1380,
10302,
4799,
3873,
641,
10061,
315,
199,
3,
485,
10212,
63,
973,
1252,
199,
515,
63,
475,
63,
493,
275,
747,
14,
515,
14,
11091,
3460,
493,
3368,
199,
692,
931,
63,
475,
63,
493,
14,
4130,
5175,
11357,
735,
221,
327,
11942,
26,
949,
8486,
272,
931,
63,
475,
63,
493,
275,
931,
63,
475,
63,
493,
4439,
17,
61,
199,
694,
63,
16181,
63,
9749,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
515,
63,
475,
63,
493,
430,
199,
692,
2935,
63,
16181,
63,
9749,
440,
315,
984,
14,
515,
26,
221,
327,
11942,
26,
949,
8486,
272,
984,
14,
515,
14,
740,
8,
694,
63,
16181,
63,
9749,
9,
421,
199,
504,
6211,
492,
2022,
63,
2604,
199,
504,
6211,
14,
1273,
63,
2087,
492,
27615,
199,
504,
6211,
14,
1102,
492,
10891,
199,
504,
6211,
14,
2293,
492,
1852,
63,
2293,
199,
504,
6211,
14,
3200,
492,
29062,
199,
504,
6211,
14,
11835,
492,
25716,
1058,
199,
504,
6211,
14,
396,
63,
2546,
492,
7640,
465,
18320,
1746,
199,
504,
6211,
14,
1023,
492,
15945,
421,
199,
2889,
275,
2022,
63,
2604,
14,
2889,
199,
21722,
275,
2022,
63,
2604,
14,
21722,
199,
2889,
804,
275,
2022,
63,
2604,
14,
2889,
804,
421,
199,
318,
2446,
8,
3020,
29,
403,
12,
1591,
29,
403,
12,
4747,
63,
25725,
29,
403,
12,
1011,
4322,
304,
272,
1591,
275,
1591,
503,
10891,
342,
272,
7876,
275,
3378,
1372,
8,
1102,
29,
1102,
9,
272,
340,
4747,
63,
25725,
365,
440,
488,
26,
267,
7876,
14,
2676,
63,
25725,
275,
4747,
63,
25725,
272,
372,
7876,
14,
973,
8,
3020,
12,
1011,
4322,
9,
421,
199,
533,
1379,
3205,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1499,
4581,
2653,
29,
403,
12,
1420,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
2062,
275,
1420,
421,
199,
533,
1379,
1084,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
9861,
63,
2219,
29,
403,
12,
23348,
63,
2219,
29,
403,
12,
326,
2295,
63,
475,
63,
2759,
29,
403,
304,
398,
347,
10016,
8,
2219,
304,
288,
2295,
275,
2295,
503,
942,
288,
372,
359,
396,
340,
1228,
8,
396,
12,
1379,
3205,
9,
587,
1379,
3205,
8,
396,
9,
490,
367,
511,
315,
2295,
61,
398,
291,
14,
11887,
63,
2219,
275,
10016,
8,
11887,
63,
2219,
9,
267,
291,
14,
21748,
63,
2219,
275,
10016,
8,
21748,
63,
2219,
9,
267,
291,
14,
2219,
63,
475,
63,
2759,
275,
10016,
8,
2219,
63,
475,
63,
2759,
9,
421,
199,
533,
13036,
3947,
6338,
8,
785,
304,
272,
3686,
275,
283,
4247,
7,
272,
492,
461,
275,
283,
646,
461,
7,
272,
15187,
275,
283,
10212,
7,
339,
1338,
275,
359,
4247,
12,
492,
461,
12,
15187,
61,
421,
199,
533,
485,
1123,
2925,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
3378,
1372,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1591,
29,
403,
304,
267,
291,
14,
589,
275,
488,
267,
291,
14,
14720,
275,
488,
267,
291,
14,
8695,
275,
488,
267,
291,
14,
1100,
275,
488,
267,
291,
14,
10828,
63,
1365,
275,
488,
267,
291,
14,
1102,
275,
1591,
503,
10891,
342,
267,
291,
14,
3422,
275,
2882,
14,
3422,
14,
15824,
342,
267,
291,
14,
11835,
275,
488,
267,
291,
14,
2758,
63,
2324,
275,
488,
267,
291,
14,
3200,
275,
488,
267,
291,
14,
15236,
63,
2324,
275,
488,
267,
291,
14,
2119,
63,
1896,
63,
694,
275,
488,
267,
291,
14,
2676,
63,
25725,
275,
13036,
3947,
6338,
14,
10212,
267,
291,
14,
5094,
63,
10360,
275,
942,
398,
327,
8265,
291,
14,
589,
370,
314,
4243,
14,
267,
1798,
275,
27615,
8,
277,
14,
1102,
9,
267,
291,
14,
1122,
63,
589,
8,
2087,
12,
3073,
339,
347,
2446,
8,
277,
12,
9238,
29,
403,
12,
1011,
4322,
304,
267,
1798,
275,
27615,
8,
277,
14,
1102,
9,
267,
291,
14,
1122,
63,
589,
8,
2087,
12,
9238,
12,
1011,
4322,
9,
267,
340,
1798,
14,
2224,
63,
1205,
365,
440,
488,
26,
288,
372,
1798,
14,
2224,
63,
1205,
398,
862,
26,
288,
2203,
12,
5501,
485,
275,
291,
14,
1065,
342,
288,
372,
2203,
267,
871,
13483,
26,
288,
291,
14,
1361,
14332,
1058,
15692,
12,
24234,
401,
2547,
29,
277,
14,
1102,
14,
3083,
9,
288,
372,
21334,
339,
347,
2198,
63,
589,
8,
277,
12,
1798,
12,
9238,
12,
1011,
4322,
304,
267,
367,
26367,
315,
4243,
26,
288,
340,
440,
2688,
8,
277,
14,
589,
12,
26367,
304,
355,
1798,
14,
705,
480,
5912,
849,
1423
] |
[
1898,
6927,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
15951,
199,
646,
14802,
199,
646,
6485,
199,
646,
2022,
199,
646,
747,
199,
646,
10543,
199,
646,
984,
199,
646,
2882,
199,
199,
504,
5055,
492,
8773,
199,
199,
3,
961,
15620,
626,
3679,
8925,
402,
6211,
4621,
911,
1736,
1380,
199,
3,
3879,
6211,
15,
5933,
14,
647,
465,
282,
2884,
2755,
340,
6211,
365,
440,
4903,
14,
199,
3,
2136,
1929,
642,
2397,
315,
10234,
370,
314,
1373,
315,
636,
973,
4343,
647,
370,
4868,
199,
3,
626,
6211,
15,
5933,
14,
647,
5419,
1380,
10302,
4799,
3873,
641,
10061,
315,
199,
3,
485,
10212,
63,
973,
1252,
199,
515,
63,
475,
63,
493,
275,
747,
14,
515,
14,
11091,
3460,
493,
3368,
199,
692,
931,
63,
475,
63,
493,
14,
4130,
5175,
11357,
735,
221,
327,
11942,
26,
949,
8486,
272,
931,
63,
475,
63,
493,
275,
931,
63,
475,
63,
493,
4439,
17,
61,
199,
694,
63,
16181,
63,
9749,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
515,
63,
475,
63,
493,
430,
199,
692,
2935,
63,
16181,
63,
9749,
440,
315,
984,
14,
515,
26,
221,
327,
11942,
26,
949,
8486,
272,
984,
14,
515,
14,
740,
8,
694,
63,
16181,
63,
9749,
9,
421,
199,
504,
6211,
492,
2022,
63,
2604,
199,
504,
6211,
14,
1273,
63,
2087,
492,
27615,
199,
504,
6211,
14,
1102,
492,
10891,
199,
504,
6211,
14,
2293,
492,
1852,
63,
2293,
199,
504,
6211,
14,
3200,
492,
29062,
199,
504,
6211,
14,
11835,
492,
25716,
1058,
199,
504,
6211,
14,
396,
63,
2546,
492,
7640,
465,
18320,
1746,
199,
504,
6211,
14,
1023,
492,
15945,
421,
199,
2889,
275,
2022,
63,
2604,
14,
2889,
199,
21722,
275,
2022,
63,
2604,
14,
21722,
199,
2889,
804,
275,
2022,
63,
2604,
14,
2889,
804,
421,
199,
318,
2446,
8,
3020,
29,
403,
12,
1591,
29,
403,
12,
4747,
63,
25725,
29,
403,
12,
1011,
4322,
304,
272,
1591,
275,
1591,
503,
10891,
342,
272,
7876,
275,
3378,
1372,
8,
1102,
29,
1102,
9,
272,
340,
4747,
63,
25725,
365,
440,
488,
26,
267,
7876,
14,
2676,
63,
25725,
275,
4747,
63,
25725,
272,
372,
7876,
14,
973,
8,
3020,
12,
1011,
4322,
9,
421,
199,
533,
1379,
3205,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1499,
4581,
2653,
29,
403,
12,
1420,
29,
403,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1328,
275,
1499,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
2062,
275,
1420,
421,
199,
533,
1379,
1084,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
9861,
63,
2219,
29,
403,
12,
23348,
63,
2219,
29,
403,
12,
326,
2295,
63,
475,
63,
2759,
29,
403,
304,
398,
347,
10016,
8,
2219,
304,
288,
2295,
275,
2295,
503,
942,
288,
372,
359,
396,
340,
1228,
8,
396,
12,
1379,
3205,
9,
587,
1379,
3205,
8,
396,
9,
490,
367,
511,
315,
2295,
61,
398,
291,
14,
11887,
63,
2219,
275,
10016,
8,
11887,
63,
2219,
9,
267,
291,
14,
21748,
63,
2219,
275,
10016,
8,
21748,
63,
2219,
9,
267,
291,
14,
2219,
63,
475,
63,
2759,
275,
10016,
8,
2219,
63,
475,
63,
2759,
9,
421,
199,
533,
13036,
3947,
6338,
8,
785,
304,
272,
3686,
275,
283,
4247,
7,
272,
492,
461,
275,
283,
646,
461,
7,
272,
15187,
275,
283,
10212,
7,
339,
1338,
275,
359,
4247,
12,
492,
461,
12,
15187,
61,
421,
199,
533,
485,
1123,
2925,
547,
8,
1726,
304,
272,
986,
421,
199,
533,
3378,
1372,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1591,
29,
403,
304,
267,
291,
14,
589,
275,
488,
267,
291,
14,
14720,
275,
488,
267,
291,
14,
8695,
275,
488,
267,
291,
14,
1100,
275,
488,
267,
291,
14,
10828,
63,
1365,
275,
488,
267,
291,
14,
1102,
275,
1591,
503,
10891,
342,
267,
291,
14,
3422,
275,
2882,
14,
3422,
14,
15824,
342,
267,
291,
14,
11835,
275,
488,
267,
291,
14,
2758,
63,
2324,
275,
488,
267,
291,
14,
3200,
275,
488,
267,
291,
14,
15236,
63,
2324,
275,
488,
267,
291,
14,
2119,
63,
1896,
63,
694,
275,
488,
267,
291,
14,
2676,
63,
25725,
275,
13036,
3947,
6338,
14,
10212,
267,
291,
14,
5094,
63,
10360,
275,
942,
398,
327,
8265,
291,
14,
589,
370,
314,
4243,
14,
267,
1798,
275,
27615,
8,
277,
14,
1102,
9,
267,
291,
14,
1122,
63,
589,
8,
2087,
12,
3073,
339,
347,
2446,
8,
277,
12,
9238,
29,
403,
12,
1011,
4322,
304,
267,
1798,
275,
27615,
8,
277,
14,
1102,
9,
267,
291,
14,
1122,
63,
589,
8,
2087,
12,
9238,
12,
1011,
4322,
9,
267,
340,
1798,
14,
2224,
63,
1205,
365,
440,
488,
26,
288,
372,
1798,
14,
2224,
63,
1205,
398,
862,
26,
288,
2203,
12,
5501,
485,
275,
291,
14,
1065,
342,
288,
372,
2203,
267,
871,
13483,
26,
288,
291,
14,
1361,
14332,
1058,
15692,
12,
24234,
401,
2547,
29,
277,
14,
1102,
14,
3083,
9,
288,
372,
21334,
339,
347,
2198,
63,
589,
8,
277,
12,
1798,
12,
9238,
12,
1011,
4322,
304,
267,
367,
26367,
315,
4243,
26,
288,
340,
440,
2688,
8,
277,
14,
589,
12,
26367,
304,
355,
1798,
14,
705,
480,
5912,
849,
1423,
0
] |
[
1,
1,
1,
1,
1,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|
photomanager/utils/imageutils.py
|
1
|
5894
|
import exifread
import os
import uuid
from PIL import Image
from photomanager.lib.pmconst import SUPPORT_EXTS, SKIP_LIST, PATH_SEP
from photomanager.lib.helper import get_file_md5, get_timestamp_from_str
from photomanager.utils.logger import logger
class ImageInfo:
def __init__(self, filename):
self.filename = filename
self.tags = TagInfo(filename)
self.fileinfo = FileInfo(filename)
class TagInfo:
def _init_props_by_exif_tags(self):
self.image_width = self._get_tag_item(self.tags.get("EXIF ExifImageWidth", None))
self.image_height = self._get_tag_item(self.tags.get("EXIF ExifImageLength", None))
self.image_datetime = self._get_tag_item(self.tags.get("Image DateTime", None))
self.origin_datetime = self._get_tag_item(self.tags.get("EXIF DateTimeOriginal", None))
self.digital_datetime = self._get_tag_item(self.tags.get("EXIF DateTimeDigitized", None))
self.camera_brand = self._get_tag_item(self.tags.get("Image Make", None))
self.camera_type = self._get_tag_item(self.tags.get("Image Model", None))
self.focal_length = self._get_tag_item(self.tags.get("EXIF FocalLength", None))
self.flash = self._get_tag_item(self.tags.get("EXIF Flash", None))
self.fnumber = self._get_tag_item(self.tags.get("EXIF FNumber", None))
self.aperture = self._get_tag_item(self.tags.get("EXIF ApertureValue", None))
self.exposure_time = self._get_tag_item(self.tags.get("EXIF ExposureTime", None))
self.exposure_bias = self._get_tag_item(self.tags.get("EXIF ExposureBiasValue", None))
self.exposure_mode = self._get_tag_item(self.tags.get("EXIF ExposureMode", None))
self.ISO_speed_rating = self._get_tag_item(self.tags.get("EXIF ISOSpeedRatings", None))
self.white_balance = self._get_tag_item(self.tags.get("EXIF WhiteBalance", None))
latitude_ref = self._get_tag_item(self.tags.get("GPS GPSLatitudeRef", None))
latitude = self._get_tag_item(self.tags.get("GPS GPSLatitude", None))
self.latitude = None if latitude is None else f"{latitude_ref}|{latitude}"
longitude_ref = self._get_tag_item(self.tags.get("GPS GPSLongitudeRef", None))
longitude = self._get_tag_item(self.tags.get("GPS GPSLongitude", None))
self.longitude = None if longitude is None else f"{longitude_ref}|{longitude}"
self.orientation = self._get_tag_item(self.tags.get("Thumbnail Orientation"))
def _get_tag_item(self, tag):
if tag:
values = tag.values
if isinstance(values, list):
if isinstance(values[0], exifread.utils.Ratio):
return tag.printable
else:
return values[0]
elif isinstance(values, str):
return values.strip()
elif isinstance(values, bytes):
return str(values).strip()
else:
return values
def _init_props_by_pil(self, f):
try:
img = Image.open(f)
self.image_width = img.width
self.image_height = img.height
except OSError as e:
self.image_width = 0
self.image_height = 0
logger.info("error when open image {filename} , message is {message}".format(filename=f.name, message=str(e)))
def __init__(self, filename):
self.tags = None
self.has_exif = False
with open(filename, "rb") as f:
try:
tags = exifread.process_file(f, details=True)
self.has_exif = bool(tags)
self.tags = tags
except KeyError:
logger.info("can not read exif from {filename} ".format(filename=filename))
except TypeError:
logger.info("can not read exif from {filename} ".format(filename=filename))
except IndexError:
logger.info("can not read exif from {filename} ".format(filename=filename))
except Exception:
logger.info("can not read exif from {filename} ".format(filename=filename))
if self.tags:
self._init_props_by_exif_tags()
else:
self._init_props_by_pil(f)
def info(self):
return dict((name, getattr(self, name)) for name in dir(self) if not name.startswith('__'))
class FileInfo:
def __init__(self, filename):
self.size = os.path.getsize(filename)
self.modify_time = os.path.getmtime(filename)
self.create_time = os.path.getctime(filename)
self.md5 = get_file_md5(filename)
self.uuid = str(uuid.uuid1())
def get_folder_image_files(folder: str, last_index_time_str: str = None) -> list:
files = []
for fpath, dirs, fs in os.walk(folder):
files = files + [
"{path}{sep}{filename}".format(path=fpath, sep=PATH_SEP, filename=f)[len(folder + PATH_SEP):] for f
in fs if _ext_is_supported(f) and not _filename_is_blocked(f)]
last_time_stamp = get_timestamp_from_str(last_index_time_str)
if last_time_stamp > 0:
return _filter_file_by_mtime(folder, files, last_time_stamp)
else:
return files
def _ext_is_supported(filename: str) -> bool:
return os.path.splitext(filename)[1].lower().strip(".") in SUPPORT_EXTS
def _filename_is_blocked(filename: str) -> bool:
for skip in SKIP_LIST:
if skip in filename:
return True
return False
def _filter_file_by_mtime(folder: str, files: list, last_time_stamp: float) -> list:
filter_files = []
for file_name in files:
try:
file_mtime = os.path.getmtime(folder + PATH_SEP + file_name)
except OSError:
file_mtime = 0
if file_mtime > last_time_stamp:
filter_files.append(file_name)
return filter_files
|
mit
|
[
646,
444,
692,
739,
199,
646,
747,
199,
646,
5377,
199,
199,
504,
14937,
492,
6047,
199,
199,
504,
3945,
357,
21604,
1456,
14,
773,
14,
7073,
1297,
492,
13756,
63,
2472,
51,
12,
27885,
63,
4924,
12,
15097,
63,
20848,
199,
504,
3945,
357,
21604,
1456,
14,
773,
14,
3676,
492,
664,
63,
493,
63,
1064,
21,
12,
664,
63,
3954,
63,
504,
63,
495,
199,
504,
3945,
357,
21604,
1456,
14,
1208,
14,
2921,
492,
2512,
421,
199,
533,
6047,
2354,
26,
272,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
2969,
275,
8053,
2354,
8,
1501,
9,
267,
291,
14,
493,
815,
275,
3814,
2354,
8,
1501,
9,
421,
199,
533,
8053,
2354,
26,
272,
347,
485,
826,
63,
6750,
63,
991,
63,
476,
692,
63,
2969,
8,
277,
304,
267,
291,
14,
1569,
63,
2063,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
692,
3491,
6216,
401,
488,
430,
267,
291,
14,
1569,
63,
3333,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
692,
3491,
4625,
401,
488,
430,
267,
291,
14,
1569,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
13686,
401,
488,
430,
267,
291,
14,
6493,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
13686,
17286,
401,
488,
430,
267,
291,
14,
25888,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
13686,
17107,
5277,
7068,
401,
488,
430,
267,
291,
14,
11928,
63,
19026,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
4155,
401,
488,
430,
267,
291,
14,
11928,
63,
466,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
5822,
401,
488,
430,
267,
291,
14,
545,
915,
63,
1267,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
481,
24560,
4625,
401,
488,
430,
267,
291,
14,
11331,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
11040,
1119,
401,
488,
430,
267,
291,
14,
70,
1955,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
481,
3259,
401,
488,
430,
267,
291,
14,
9804,
7603,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
437,
529,
7603,
1110,
401,
488,
430,
267,
291,
14,
28480,
63,
521,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
1366,
401,
488,
430,
267,
291,
14,
28480,
63,
8160,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
34,
2241,
1110,
401,
488,
430,
267,
291,
14,
28480,
63,
632,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
1385,
401,
488,
430,
267,
291,
14,
7336,
63,
7625,
63,
10417,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
2281,
3100,
4536,
50,
292,
780,
401,
488,
430,
267,
291,
14,
7510,
63,
7358,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
2816,
1175,
27106,
401,
488,
430,
398,
18896,
63,
1121,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
31429,
3786,
2891,
401,
488,
430,
267,
18896,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
31429,
3786,
401,
488,
430,
267,
291,
14,
13331,
275,
488,
340,
18896,
365,
488,
587,
289,
14381,
13331,
63,
1121,
22441,
91,
13331,
7063,
398,
18154,
63,
1121,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
951,
7779,
2891,
401,
488,
430,
267,
18154,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
951,
7779,
401,
488,
430,
267,
291,
14,
13803,
275,
488,
340,
18154,
365,
488,
587,
289,
14381,
13803,
63,
1121,
22441,
91,
13803,
7063,
398,
291,
14,
17001,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
2719,
5820,
593,
322,
484,
425,
2237,
339,
347,
485,
362,
63,
1450,
63,
1053,
8,
277,
12,
1947,
304,
267,
340,
1947,
26,
288,
1338,
275,
1947,
14,
1459,
288,
340,
1228,
8,
1459,
12,
769,
304,
355,
340,
1228,
8,
1459,
59,
16,
467,
444,
692,
739,
14,
1208,
14,
13971,
304,
490,
372,
1947,
14,
20557,
355,
587,
26,
490,
372,
1338,
59,
16,
61,
288,
916,
1228,
8,
1459,
12,
620,
304,
355,
372,
1338,
14,
1913,
342,
288,
916,
1228,
8,
1459,
12,
2783,
304,
355,
372,
620,
8,
1459,
680,
1913,
342,
288,
587,
26,
355,
372,
1338,
339,
347,
485,
826,
63,
6750,
63,
991,
63,
80,
382,
8,
277,
12,
289,
304,
267,
862,
26,
288,
6050,
275,
6047,
14,
1490,
8,
70,
9,
288,
291,
14,
1569,
63,
2063,
275,
6050,
14,
2063,
288,
291,
14,
1569,
63,
3333,
275,
6050,
14,
3333,
267,
871,
6440,
465,
325,
26,
288,
291,
14,
1569,
63,
2063,
275,
378,
288,
291,
14,
1569,
63,
3333,
275,
378,
288,
2512,
14,
815,
480,
705,
1380,
1551,
1834,
469,
1501,
93,
2360,
1245,
365,
469,
1188,
5469,
908,
8,
1501,
29,
70,
14,
354,
12,
1245,
29,
495,
8,
69,
1724,
339,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
2969,
275,
488,
267,
291,
14,
1989,
63,
476,
692,
275,
756,
398,
543,
1551,
8,
1501,
12,
298,
4848,
531,
465,
289,
26,
288,
862,
26,
355,
3762,
275,
444,
692,
739,
14,
1412,
63,
493,
8,
70
] |
[
444,
692,
739,
199,
646,
747,
199,
646,
5377,
199,
199,
504,
14937,
492,
6047,
199,
199,
504,
3945,
357,
21604,
1456,
14,
773,
14,
7073,
1297,
492,
13756,
63,
2472,
51,
12,
27885,
63,
4924,
12,
15097,
63,
20848,
199,
504,
3945,
357,
21604,
1456,
14,
773,
14,
3676,
492,
664,
63,
493,
63,
1064,
21,
12,
664,
63,
3954,
63,
504,
63,
495,
199,
504,
3945,
357,
21604,
1456,
14,
1208,
14,
2921,
492,
2512,
421,
199,
533,
6047,
2354,
26,
272,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
1501,
275,
1788,
267,
291,
14,
2969,
275,
8053,
2354,
8,
1501,
9,
267,
291,
14,
493,
815,
275,
3814,
2354,
8,
1501,
9,
421,
199,
533,
8053,
2354,
26,
272,
347,
485,
826,
63,
6750,
63,
991,
63,
476,
692,
63,
2969,
8,
277,
304,
267,
291,
14,
1569,
63,
2063,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
692,
3491,
6216,
401,
488,
430,
267,
291,
14,
1569,
63,
3333,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
692,
3491,
4625,
401,
488,
430,
267,
291,
14,
1569,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
13686,
401,
488,
430,
267,
291,
14,
6493,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
13686,
17286,
401,
488,
430,
267,
291,
14,
25888,
63,
2083,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
13686,
17107,
5277,
7068,
401,
488,
430,
267,
291,
14,
11928,
63,
19026,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
4155,
401,
488,
430,
267,
291,
14,
11928,
63,
466,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
3491,
5822,
401,
488,
430,
267,
291,
14,
545,
915,
63,
1267,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
481,
24560,
4625,
401,
488,
430,
267,
291,
14,
11331,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
11040,
1119,
401,
488,
430,
267,
291,
14,
70,
1955,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
481,
3259,
401,
488,
430,
267,
291,
14,
9804,
7603,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
437,
529,
7603,
1110,
401,
488,
430,
267,
291,
14,
28480,
63,
521,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
1366,
401,
488,
430,
267,
291,
14,
28480,
63,
8160,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
34,
2241,
1110,
401,
488,
430,
267,
291,
14,
28480,
63,
632,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
1316,
17678,
1385,
401,
488,
430,
267,
291,
14,
7336,
63,
7625,
63,
10417,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
2281,
3100,
4536,
50,
292,
780,
401,
488,
430,
267,
291,
14,
7510,
63,
7358,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
1438,
4656,
2816,
1175,
27106,
401,
488,
430,
398,
18896,
63,
1121,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
31429,
3786,
2891,
401,
488,
430,
267,
18896,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
31429,
3786,
401,
488,
430,
267,
291,
14,
13331,
275,
488,
340,
18896,
365,
488,
587,
289,
14381,
13331,
63,
1121,
22441,
91,
13331,
7063,
398,
18154,
63,
1121,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
951,
7779,
2891,
401,
488,
430,
267,
18154,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
26359,
17346,
4929,
951,
7779,
401,
488,
430,
267,
291,
14,
13803,
275,
488,
340,
18154,
365,
488,
587,
289,
14381,
13803,
63,
1121,
22441,
91,
13803,
7063,
398,
291,
14,
17001,
275,
291,
423,
362,
63,
1450,
63,
1053,
8,
277,
14,
2969,
14,
362,
480,
2719,
5820,
593,
322,
484,
425,
2237,
339,
347,
485,
362,
63,
1450,
63,
1053,
8,
277,
12,
1947,
304,
267,
340,
1947,
26,
288,
1338,
275,
1947,
14,
1459,
288,
340,
1228,
8,
1459,
12,
769,
304,
355,
340,
1228,
8,
1459,
59,
16,
467,
444,
692,
739,
14,
1208,
14,
13971,
304,
490,
372,
1947,
14,
20557,
355,
587,
26,
490,
372,
1338,
59,
16,
61,
288,
916,
1228,
8,
1459,
12,
620,
304,
355,
372,
1338,
14,
1913,
342,
288,
916,
1228,
8,
1459,
12,
2783,
304,
355,
372,
620,
8,
1459,
680,
1913,
342,
288,
587,
26,
355,
372,
1338,
339,
347,
485,
826,
63,
6750,
63,
991,
63,
80,
382,
8,
277,
12,
289,
304,
267,
862,
26,
288,
6050,
275,
6047,
14,
1490,
8,
70,
9,
288,
291,
14,
1569,
63,
2063,
275,
6050,
14,
2063,
288,
291,
14,
1569,
63,
3333,
275,
6050,
14,
3333,
267,
871,
6440,
465,
325,
26,
288,
291,
14,
1569,
63,
2063,
275,
378,
288,
291,
14,
1569,
63,
3333,
275,
378,
288,
2512,
14,
815,
480,
705,
1380,
1551,
1834,
469,
1501,
93,
2360,
1245,
365,
469,
1188,
5469,
908,
8,
1501,
29,
70,
14,
354,
12,
1245,
29,
495,
8,
69,
1724,
339,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
2969,
275,
488,
267,
291,
14,
1989,
63,
476,
692,
275,
756,
398,
543,
1551,
8,
1501,
12,
298,
4848,
531,
465,
289,
26,
288,
862,
26,
355,
3762,
275,
444,
692,
739,
14,
1412,
63,
493,
8,
70,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
Affix/fas
|
fas/tgcaptcha2/plugins/image/vanasco_dowty/__init__.py
|
1
|
1183
|
import captcha
from turbogears import config
import random
import os.path
from pkg_resources import resource_filename
plugin_name = 'fas.tgcaptcha2.plugin.vanasco_dowty.'
width = int(config.get(plugin_name + 'width', 300))
height = int(config.get(plugin_name + 'height', 100))
bg_color = config.get(plugin_name + 'bg_color', '#DDDDDD')
fg_color = config.get(plugin_name + 'fg_color',
["#330000","#660000","#003300","#006600","#000033","#000066"])
font_size_min = int(config.get(plugin_name + 'font_size_min', 30))
font_size_max = int(config.get(plugin_name + 'font_size_max', 45))
font_paths = config.get(plugin_name + 'font_paths',
[os.path.normpath('/usr/share/fonts/tulrich-tuffy/Tuffy.ttf')])
captcha.font__paths = font_paths
captcha.captcha__text__render_mode = config.get(plugin_name +
'text_render_mode', 'by_letter')
captcha.captcha__font_range = (font_size_min, font_size_max)
def generate_jpeg(text, file_):
font_size = random.randint(font_size_min, font_size_max)
fg = random.choice(fg_color)
ci = captcha._Captcha__Img(text, width, height, font_size, fg, bg_color)
image = ci.render()
image.save(file_, format='JPEG')
|
gpl-2.0
|
[
646,
12162,
9518,
199,
504,
307,
300,
656,
303,
4291,
492,
1101,
199,
646,
2196,
199,
646,
747,
14,
515,
199,
504,
5496,
63,
4435,
492,
2073,
63,
1501,
199,
199,
2718,
63,
354,
275,
283,
70,
305,
14,
17699,
20559,
18,
14,
2718,
14,
20662,
305,
331,
63,
68,
583,
369,
3530,
199,
199,
2063,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
2063,
297,
9601,
430,
199,
3333,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
3333,
297,
2948,
430,
199,
6856,
63,
2326,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
6856,
63,
2326,
297,
3943,
5745,
5745,
5745,
358,
199,
9681,
63,
2326,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
9681,
63,
2326,
297,
288,
2097,
3,
1153,
993,
2266,
3,
1272,
993,
2266,
3,
31152,
383,
2266,
3,
29327,
383,
2266,
3,
993,
1153,
2266,
3,
993,
1272,
3135,
199,
4246,
63,
890,
63,
827,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
890,
63,
827,
297,
4233,
430,
199,
4246,
63,
890,
63,
988,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
890,
63,
988,
297,
10416,
430,
199,
4246,
63,
3771,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
3771,
297,
267,
359,
736,
14,
515,
14,
9267,
2336,
2647,
15,
6251,
15,
19864,
15,
84,
348,
10399,
13,
84,
3043,
89,
15,
52,
3043,
89,
14,
32264,
2023,
199,
199,
20559,
14,
4246,
363,
3771,
275,
5023,
63,
3771,
199,
20559,
14,
20559,
363,
505,
363,
3352,
63,
632,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
267,
283,
505,
63,
3352,
63,
632,
297,
283,
991,
63,
9269,
358,
199,
20559,
14,
20559,
363,
4246,
63,
1842,
275,
334,
4246,
63,
890,
63,
827,
12,
5023,
63,
890,
63,
988,
9,
421,
199,
318,
3550,
63,
14230,
8,
505,
12,
570,
7822,
272,
5023,
63,
890,
275,
2196,
14,
8393,
8,
4246,
63,
890,
63,
827,
12,
5023,
63,
890,
63,
988,
9,
272,
16587,
275,
2196,
14,
5095,
8,
9681,
63,
2326,
9,
272,
16279,
275,
12162,
9518,
423,
13519,
9518,
363,
27261,
8,
505,
12,
3462,
12,
4569,
12,
5023,
63,
890,
12,
16587,
12,
12994,
63,
2326,
9,
272,
1834,
275,
16279,
14,
3352,
342,
272,
1834,
14,
2117,
8,
493,
3131,
1475,
534,
28412,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12162,
9518,
199,
504,
307,
300,
656,
303,
4291,
492,
1101,
199,
646,
2196,
199,
646,
747,
14,
515,
199,
504,
5496,
63,
4435,
492,
2073,
63,
1501,
199,
199,
2718,
63,
354,
275,
283,
70,
305,
14,
17699,
20559,
18,
14,
2718,
14,
20662,
305,
331,
63,
68,
583,
369,
3530,
199,
199,
2063,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
2063,
297,
9601,
430,
199,
3333,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
3333,
297,
2948,
430,
199,
6856,
63,
2326,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
6856,
63,
2326,
297,
3943,
5745,
5745,
5745,
358,
199,
9681,
63,
2326,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
9681,
63,
2326,
297,
288,
2097,
3,
1153,
993,
2266,
3,
1272,
993,
2266,
3,
31152,
383,
2266,
3,
29327,
383,
2266,
3,
993,
1153,
2266,
3,
993,
1272,
3135,
199,
4246,
63,
890,
63,
827,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
890,
63,
827,
297,
4233,
430,
199,
4246,
63,
890,
63,
988,
275,
1109,
8,
888,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
890,
63,
988,
297,
10416,
430,
199,
4246,
63,
3771,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
283,
4246,
63,
3771,
297,
267,
359,
736,
14,
515,
14,
9267,
2336,
2647,
15,
6251,
15,
19864,
15,
84,
348,
10399,
13,
84,
3043,
89,
15,
52,
3043,
89,
14,
32264,
2023,
199,
199,
20559,
14,
4246,
363,
3771,
275,
5023,
63,
3771,
199,
20559,
14,
20559,
363,
505,
363,
3352,
63,
632,
275,
1101,
14,
362,
8,
2718,
63,
354,
435,
267,
283,
505,
63,
3352,
63,
632,
297,
283,
991,
63,
9269,
358,
199,
20559,
14,
20559,
363,
4246,
63,
1842,
275,
334,
4246,
63,
890,
63,
827,
12,
5023,
63,
890,
63,
988,
9,
421,
199,
318,
3550,
63,
14230,
8,
505,
12,
570,
7822,
272,
5023,
63,
890,
275,
2196,
14,
8393,
8,
4246,
63,
890,
63,
827,
12,
5023,
63,
890,
63,
988,
9,
272,
16587,
275,
2196,
14,
5095,
8,
9681,
63,
2326,
9,
272,
16279,
275,
12162,
9518,
423,
13519,
9518,
363,
27261,
8,
505,
12,
3462,
12,
4569,
12,
5023,
63,
890,
12,
16587,
12,
12994,
63,
2326,
9,
272,
1834,
275,
16279,
14,
3352,
342,
272,
1834,
14,
2117,
8,
493,
3131,
1475,
534,
28412,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ahsanali/expense-tracker
|
tracker/forms/expenses.py
|
1
|
1193
|
from flask.ext.wtf import Form
from wtforms_alchemy import model_form_factory
from wtforms import StringField, DateField, IntegerField
from wtforms.validators import DataRequired
from tracker.extensions import db
from tracker.models import Expense
BaseModelForm = model_form_factory(Form)
class ModelForm(BaseModelForm):
@classmethod
def get_session(self):
return db.session
class ExpenseCreateForm(ModelForm):
class Meta:
model = Expense
class ExpenseSearchForm(Form):
min_date = StringField('min_date')
max_date = StringField('max_date')
min_amount = IntegerField('min_amount')
max_amount = IntegerField('max_amount')
def get_filters(self):
expenses = Expense.query
if self.min_amount.data:
expenses = expenses.filter(Expense.amount > self.min_amount.data)
if self.max_amount.data:
expenses = expenses.filter(Expense.amount < self.max_amount.data)
if self.min_date.data:
expenses = expenses.filter(Expense.expense_time > self.min_date.data)
if self.max_date.data:
expenses = expenses.filter(Expense.expense_time < self.max_date.data)
expenses = expenses.order_by(Expense.created_time)
return expenses
|
apache-2.0
|
[
504,
7209,
14,
832,
14,
87,
3249,
492,
8204,
523,
199,
504,
24756,
3351,
63,
6732,
492,
1402,
63,
964,
63,
3702,
199,
504,
24756,
3351,
492,
21409,
12,
30997,
12,
26141,
199,
504,
24756,
3351,
14,
11346,
492,
3918,
8030,
523,
199,
504,
15271,
14,
5359,
492,
1592,
199,
504,
15271,
14,
992,
492,
7910,
677,
523,
199,
1563,
15937,
275,
1402,
63,
964,
63,
3702,
8,
2821,
9,
523,
199,
533,
28455,
8,
1563,
15937,
304,
272,
768,
3744,
272,
347,
664,
63,
1730,
8,
277,
304,
267,
372,
1592,
14,
1730,
523,
199,
533,
7910,
677,
2499,
2821,
8,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
7910,
677,
1362,
199,
533,
7910,
677,
5278,
2821,
8,
2821,
304,
199,
198,
827,
63,
602,
275,
21409,
360,
827,
63,
602,
358,
199,
198,
988,
63,
602,
275,
21409,
360,
988,
63,
602,
358,
199,
198,
827,
63,
4606,
275,
26141,
360,
827,
63,
4606,
358,
199,
198,
988,
63,
4606,
275,
26141,
360,
988,
63,
4606,
358,
421,
198,
318,
664,
63,
4273,
8,
277,
304,
2742,
198,
16886,
83,
275,
7910,
677,
14,
1131,
9068,
198,
692,
291,
14,
827,
63,
4606,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
4606,
690,
221,
291,
14,
827,
63,
4606,
14,
576,
9,
507,
198,
692,
291,
14,
988,
63,
4606,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
4606,
665,
221,
291,
14,
988,
63,
4606,
14,
576,
9,
507,
198,
692,
291,
14,
827,
63,
602,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
16886,
63,
521,
690,
221,
291,
14,
827,
63,
602,
14,
576,
9,
507,
198,
692,
291,
14,
988,
63,
602,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
16886,
63,
521,
665,
221,
291,
14,
988,
63,
602,
14,
576,
9,
9068,
198,
16886,
83,
275,
26963,
83,
14,
1648,
63,
991,
8,
4527,
677,
14,
3966,
63,
521,
9,
9068,
198,
1107,
26963,
83,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
14,
832,
14,
87,
3249,
492,
8204,
523,
199,
504,
24756,
3351,
63,
6732,
492,
1402,
63,
964,
63,
3702,
199,
504,
24756,
3351,
492,
21409,
12,
30997,
12,
26141,
199,
504,
24756,
3351,
14,
11346,
492,
3918,
8030,
523,
199,
504,
15271,
14,
5359,
492,
1592,
199,
504,
15271,
14,
992,
492,
7910,
677,
523,
199,
1563,
15937,
275,
1402,
63,
964,
63,
3702,
8,
2821,
9,
523,
199,
533,
28455,
8,
1563,
15937,
304,
272,
768,
3744,
272,
347,
664,
63,
1730,
8,
277,
304,
267,
372,
1592,
14,
1730,
523,
199,
533,
7910,
677,
2499,
2821,
8,
15937,
304,
339,
1021,
6288,
26,
267,
1402,
275,
7910,
677,
1362,
199,
533,
7910,
677,
5278,
2821,
8,
2821,
304,
199,
198,
827,
63,
602,
275,
21409,
360,
827,
63,
602,
358,
199,
198,
988,
63,
602,
275,
21409,
360,
988,
63,
602,
358,
199,
198,
827,
63,
4606,
275,
26141,
360,
827,
63,
4606,
358,
199,
198,
988,
63,
4606,
275,
26141,
360,
988,
63,
4606,
358,
421,
198,
318,
664,
63,
4273,
8,
277,
304,
2742,
198,
16886,
83,
275,
7910,
677,
14,
1131,
9068,
198,
692,
291,
14,
827,
63,
4606,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
4606,
690,
221,
291,
14,
827,
63,
4606,
14,
576,
9,
507,
198,
692,
291,
14,
988,
63,
4606,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
4606,
665,
221,
291,
14,
988,
63,
4606,
14,
576,
9,
507,
198,
692,
291,
14,
827,
63,
602,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
16886,
63,
521,
690,
221,
291,
14,
827,
63,
602,
14,
576,
9,
507,
198,
692,
291,
14,
988,
63,
602,
14,
576,
26,
686,
198,
16886,
83,
275,
26963,
83,
14,
1541,
8,
4527,
677,
14,
16886,
63,
521,
665,
221,
291,
14,
988,
63,
602,
14,
576,
9,
9068,
198,
16886,
83,
275,
26963,
83,
14,
1648,
63,
991,
8,
4527,
677,
14,
3966,
63,
521,
9,
9068,
198,
1107,
26963,
83,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
curiosityio/taiga-docker
|
taiga-back/taiga-back/tests/integration/test_importer_api.py
|
1
|
55263
|
# Copyright (C) 2014-2016 Andrey Antukh <niwi@niwi.nz>
# Copyright (C) 2014-2016 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014-2016 David Barragán <bameda@dbarragan.com>
# Copyright (C) 2014-2016 Alejandro Alonso <alejandro.alonso@kaleidos.net>
# 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 pytest
import base64
from django.apps import apps
from django.core.urlresolvers import reverse
from django.core.files.base import ContentFile
from taiga.base.utils import json
from taiga.export_import import services
from taiga.export_import.exceptions import TaigaImportError
from taiga.projects.models import Project, Membership
from taiga.projects.issues.models import Issue
from taiga.projects.userstories.models import UserStory
from taiga.projects.tasks.models import Task
from taiga.projects.wiki.models import WikiPage
from .. import factories as f
from ..utils import DUMMY_BMP_DATA
pytestmark = pytest.mark.django_db
#######################################################
## test api/v1/importer
#######################################################
def test_invalid_project_import(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_project_import_without_extra_data(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{"name": "Role"}],
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
must_empty_children = [
"issues", "user_stories", "us_statuses", "wiki_pages", "priorities",
"severities", "milestones", "points", "issue_types", "task_statuses",
"issue_statuses", "wiki_links",
]
assert all(map(lambda x: len(response.data[x]) == 0, must_empty_children))
assert response.data["owner"] == user.email
assert response.data["watchers"] == [user.email, user_watching.email]
def test_valid_project_without_enough_public_projects_slots(client):
user = f.UserFactory.create(max_public_projects=0)
url = reverse("importer-list")
data = {
"slug": "public-project-without-slots",
"name": "Imported project",
"description": "Imported project",
"roles": [{"name": "Role"}],
"is_private": False
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert "can't have more public projects" in response.data["_error_message"]
assert Project.objects.filter(slug="public-project-without-slots").count() == 0
assert response["Taiga-Info-Project-Memberships"] == "1"
assert response["Taiga-Info-Project-Is-Private"] == "False"
def test_valid_project_without_enough_private_projects_slots(client):
user = f.UserFactory.create(max_private_projects=0)
url = reverse("importer-list")
data = {
"slug": "private-project-without-slots",
"name": "Imported project",
"description": "Imported project",
"roles": [{"name": "Role"}],
"is_private": True
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert "can't have more private projects" in response.data["_error_message"]
assert response["Taiga-Info-Project-Memberships"] == "1"
assert response["Taiga-Info-Project-Is-Private"] == "True"
assert Project.objects.filter(slug="private-project-without-slots").count() == 0
def test_valid_project_with_enough_public_projects_slots(client):
user = f.UserFactory.create(max_public_projects=1)
url = reverse("importer-list")
data = {
"slug": "public-project-with-slots",
"name": "Imported project",
"description": "Imported project",
"roles": [{"name": "Role"}],
"is_private": False
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert Project.objects.filter(slug="public-project-with-slots").count() == 1
def test_valid_project_with_enough_private_projects_slots(client):
user = f.UserFactory.create(max_private_projects=1)
url = reverse("importer-list")
data = {
"slug": "private-project-with-slots",
"name": "Imported project",
"description": "Imported project",
"roles": [{"name": "Role"}],
"is_private": True
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert Project.objects.filter(slug="private-project-with-slots").count() == 1
def test_valid_project_import_with_not_existing_memberships(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"memberships": [{
"email": "bad@email.com",
"role": "Role",
}],
"roles": [{"name": "Role"}]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
# The new membership and the owner membership
assert len(response.data["memberships"]) == 2
def test_valid_project_import_with_membership_uuid_rewrite(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"memberships": [{
"email": "with-uuid@email.com",
"role": "Role",
"token": "123",
}],
"roles": [{"name": "Role"}]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert Membership.objects.filter(email="with-uuid@email.com", token="123").count() == 0
def test_valid_project_import_with_extra_data(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{
"permissions": [],
"name": "Test"
}],
"us_statuses": [{
"name": "Test"
}],
"severities": [{
"name": "Test"
}],
"priorities": [{
"name": "Test"
}],
"points": [{
"name": "Test"
}],
"issue_types": [{
"name": "Test"
}],
"task_statuses": [{
"name": "Test"
}],
"issue_statuses": [{
"name": "Test"
}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
must_empty_children = [
"issues", "user_stories", "wiki_pages", "milestones",
"wiki_links",
]
must_one_instance_children = [
"roles", "us_statuses", "severities", "priorities", "points",
"issue_types", "task_statuses", "issue_statuses", "memberships",
]
assert all(map(lambda x: len(response.data[x]) == 0, must_empty_children))
# Allwais is created at least the owner membership
assert all(map(lambda x: len(response.data[x]) == 1, must_one_instance_children))
assert response.data["owner"] == user.email
def test_invalid_project_import_without_roles(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 2
assert Project.objects.filter(slug="imported-project").count() == 0
def test_invalid_project_import_with_extra_data(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{
"permissions": [],
"name": "Test"
}],
"us_statuses": [{}],
"severities": [{}],
"priorities": [{}],
"points": [{}],
"issue_types": [{}],
"task_statuses": [{}],
"issue_statuses": [{}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 7
assert Project.objects.filter(slug="imported-project").count() == 0
def test_valid_project_import_with_custom_attributes(client):
user = f.UserFactory.create()
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{
"permissions": [],
"name": "Test"
}],
"userstorycustomattributes": [{
"name": "custom attribute example 1",
"description": "short description 1",
"order": 1
}],
"taskcustomattributes": [{
"name": "custom attribute example 1",
"description": "short description 1",
"order": 1
}],
"issuecustomattributes": [{
"name": "custom attribute example 1",
"description": "short description 1",
"order": 1
}]
}
must_empty_children = ["issues", "user_stories", "wiki_pages", "milestones", "wiki_links"]
must_one_instance_children = ["userstorycustomattributes", "taskcustomattributes", "issuecustomattributes"]
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert all(map(lambda x: len(response.data[x]) == 0, must_empty_children))
# Allwais is created at least the owner membership
assert all(map(lambda x: len(response.data[x]) == 1, must_one_instance_children))
assert response.data["owner"] == user.email
def test_invalid_project_import_with_custom_attributes(client):
user = f.UserFactory.create()
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{
"permissions": [],
"name": "Test"
}],
"userstorycustomattributes": [{ }],
"taskcustomattributes": [{ }],
"issuecustomattributes": [{ }]
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 3
assert Project.objects.filter(slug="imported-project").count() == 0
#######################################################
## tes api/v1/importer/milestone
#######################################################
def test_invalid_milestone_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-milestone", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_milestone_import(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-milestone", args=[project.pk])
data = {
"name": "Imported milestone",
"estimated_start": "2014-10-10",
"estimated_finish": "2014-10-20",
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["watchers"] == [user_watching.email]
def test_milestone_import_duplicated_milestone(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-milestone", args=[project.pk])
data = {
"name": "Imported milestone",
"estimated_start": "2014-10-10",
"estimated_finish": "2014-10-20",
}
# We create twice the same milestone
response = client.json.post(url, json.dumps(data))
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert response.data["milestones"][0]["name"][0] == "Name duplicated for the project"
#######################################################
## tes api/v1/importer/us
#######################################################
def test_invalid_us_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_us_import_without_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Test"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
def test_valid_us_import_with_extra_data(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Imported us",
"description": "Imported us",
"attachments": [{
"owner": user.email,
"attached_file": {
"name": "imported attachment",
"data": base64.b64encode(b"TEST").decode("utf-8")
}
}],
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert len(response.data["attachments"]) == 1
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
assert response.data["watchers"] == [user_watching.email]
def test_invalid_us_import_with_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Imported us",
"description": "Imported us",
"attachments": [{}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
assert UserStory.objects.filter(subject="Imported us").count() == 0
def test_invalid_us_import_with_bad_choices(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Imported us",
"description": "Imported us",
"status": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
#######################################################
## tes api/v1/importer/task
#######################################################
def test_invalid_task_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_task_import_without_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Test"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
def test_valid_task_import_with_custom_attributes_values(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
membership = f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
project.save()
custom_attr = f.TaskCustomAttributeFactory(project=project)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Test Custom Attrs Values Tasks",
"custom_attributes_values": {
custom_attr.name: "test_value"
}
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
custom_attributes_values = apps.get_model("custom_attributes.TaskCustomAttributesValues").objects.get(
task__subject=response.data["subject"])
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
def test_valid_task_import_with_extra_data(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Imported task",
"description": "Imported task",
"attachments": [{
"owner": user.email,
"attached_file": {
"name": "imported attachment",
"data": base64.b64encode(b"TEST").decode("utf-8")
}
}],
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert len(response.data["attachments"]) == 1
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
assert response.data["watchers"] == [user_watching.email]
def test_invalid_task_import_with_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Imported task",
"description": "Imported task",
"attachments": [{}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
assert Task.objects.filter(subject="Imported task").count() == 0
def test_invalid_task_import_with_bad_choices(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Imported task",
"description": "Imported task",
"status": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
def test_valid_task_with_user_story(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_task_status = f.TaskStatusFactory.create(project=project)
us = f.UserStoryFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-task", args=[project.pk])
data = {
"subject": "Imported task",
"description": "Imported task",
"user_story": us.ref
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert us.tasks.all().count() == 1
#######################################################
## tes api/v1/importer/issue
#######################################################
def test_invalid_issue_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-issue", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_user_story_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Imported issue",
"finish_date": "2014-10-24T00:00:00+0000"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["subject"] == "Imported issue"
assert response.data["finish_date"] == "2014-10-24T00:00:00+0000"
def test_valid_user_story_import_with_custom_attributes_values(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
membership = f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
project.save()
custom_attr = f.UserStoryCustomAttributeFactory(project=project)
url = reverse("importer-us", args=[project.pk])
data = {
"subject": "Test Custom Attrs Values User Story",
"custom_attributes_values": {
custom_attr.name: "test_value"
}
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
custom_attributes_values = apps.get_model("custom_attributes.UserStoryCustomAttributesValues").objects.get(
user_story__subject=response.data["subject"])
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
def test_valid_issue_import_without_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_issue_type = f.IssueTypeFactory.create(project=project)
project.default_issue_status = f.IssueStatusFactory.create(project=project)
project.default_severity = f.SeverityFactory.create(project=project)
project.default_priority = f.PriorityFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Test"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
def test_valid_issue_import_with_custom_attributes_values(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
membership = f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_issue_type = f.IssueTypeFactory.create(project=project)
project.default_issue_status = f.IssueStatusFactory.create(project=project)
project.default_severity = f.SeverityFactory.create(project=project)
project.default_priority = f.PriorityFactory.create(project=project)
project.save()
custom_attr = f.IssueCustomAttributeFactory(project=project)
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Test Custom Attrs Values Issues",
"custom_attributes_values": {
custom_attr.name: "test_value"
}
}
client.login(user)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
custom_attributes_values = apps.get_model("custom_attributes.IssueCustomAttributesValues").objects.get(
issue__subject=response.data["subject"])
assert custom_attributes_values.attributes_values == {str(custom_attr.id): "test_value"}
def test_valid_issue_import_with_extra_data(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_issue_type = f.IssueTypeFactory.create(project=project)
project.default_issue_status = f.IssueStatusFactory.create(project=project)
project.default_severity = f.SeverityFactory.create(project=project)
project.default_priority = f.PriorityFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"finished_date": "2014-10-24T00:00:00+0000",
"attachments": [{
"owner": user.email,
"attached_file": {
"name": "imported attachment",
"data": base64.b64encode(b"TEST").decode("utf-8")
}
}],
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert len(response.data["attachments"]) == 1
assert response.data["owner"] == user.email
assert response.data["ref"] is not None
assert response.data["finished_date"] == "2014-10-24T00:00:00+0000"
assert response.data["watchers"] == [user_watching.email]
def test_invalid_issue_import_with_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_issue_type = f.IssueTypeFactory.create(project=project)
project.default_issue_status = f.IssueStatusFactory.create(project=project)
project.default_severity = f.SeverityFactory.create(project=project)
project.default_priority = f.PriorityFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"attachments": [{}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
assert Issue.objects.filter(subject="Imported issue").count() == 0
def test_invalid_issue_import_with_bad_choices(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
project.default_issue_type = f.IssueTypeFactory.create(project=project)
project.default_issue_status = f.IssueStatusFactory.create(project=project)
project.default_severity = f.SeverityFactory.create(project=project)
project.default_priority = f.PriorityFactory.create(project=project)
project.save()
client.login(user)
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"status": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"priority": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"severity": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
url = reverse("importer-issue", args=[project.pk])
data = {
"subject": "Imported issue",
"description": "Imported issue",
"type": "Not valid"
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
#######################################################
## tes api/v1/importer/wiki-page
#######################################################
def test_invalid_wiki_page_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-page", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_wiki_page_import_without_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-page", args=[project.pk])
data = {
"slug": "imported-wiki-page",
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["owner"] == user.email
def test_valid_wiki_page_import_with_extra_data(client):
user = f.UserFactory.create()
user_watching = f.UserFactory.create(email="testing@taiga.io")
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-page", args=[project.pk])
data = {
"slug": "imported-wiki-page",
"content": "Imported wiki_page",
"attachments": [{
"owner": user.email,
"attached_file": {
"name": "imported attachment",
"data": base64.b64encode(b"TEST").decode("utf-8")
}
}],
"watchers": ["testing@taiga.io"]
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert len(response.data["attachments"]) == 1
assert response.data["owner"] == user.email
assert response.data["watchers"] == [user_watching.email]
def test_invalid_wiki_page_import_with_extra_data(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-page", args=[project.pk])
data = {
"slug": "imported-wiki-page",
"content": "Imported wiki_page",
"attachments": [{}],
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
assert len(response.data) == 1
assert WikiPage.objects.filter(slug="imported-wiki-page").count() == 0
#######################################################
## tes api/v1/importer/wiki-link
#######################################################
def test_invalid_wiki_link_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-link", args=[project.pk])
data = {}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 400
def test_valid_wiki_link_import(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory(project=project, user=user, is_admin=True)
client.login(user)
url = reverse("importer-wiki-link", args=[project.pk])
data = {
"title": "Imported wiki_link",
"href": "imported-wiki-link",
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
response.data
##################################################################
## tes taiga.export_import.services.store_project_from_dict
##################################################################
def test_services_store_project_from_dict_with_no_projects_slots_available(client):
user = f.UserFactory.create(max_private_projects=0)
data = {
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True
}
with pytest.raises(TaigaImportError) as excinfo:
project = services.store_project_from_dict(data, owner=user)
assert "can't have more private projects" in str(excinfo.value)
def test_services_store_project_from_dict_with_no_members_private_project_slots_available(client):
user = f.UserFactory.create(max_memberships_private_projects=2)
data = {
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True,
"roles": [{"name": "Role"}],
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
}
]
}
with pytest.raises(TaigaImportError) as excinfo:
project = services.store_project_from_dict(data, owner=user)
assert "reaches your current limit of memberships for private" in str(excinfo.value)
def test_services_store_project_from_dict_with_no_members_public_project_slots_available(client):
user = f.UserFactory.create(max_memberships_public_projects=2)
data = {
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False,
"roles": [{"name": "Role"}],
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
}
]
}
with pytest.raises(TaigaImportError) as excinfo:
project = services.store_project_from_dict(data, owner=user)
assert "reaches your current limit of memberships for public" in str(excinfo.value)
##################################################################
## tes api/v1/importer/load-dummp
##################################################################
def test_invalid_dump_import(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(b"test")
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
assert response.data["_error_message"] == "Invalid dump format"
def test_valid_dump_import_without_enough_public_projects_slots(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_public_projects=0)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "public-project-without-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
assert "can't have more public projects" in response.data["_error_message"]
assert response["Taiga-Info-Project-Memberships"] == "1"
assert response["Taiga-Info-Project-Is-Private"] == "False"
assert Project.objects.filter(slug="public-project-without-slots").count() == 0
def test_valid_dump_import_without_enough_private_projects_slots(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_private_projects=0)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "private-project-without-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
assert "can't have more private projects" in response.data["_error_message"]
assert response["Taiga-Info-Project-Memberships"] == "1"
assert response["Taiga-Info-Project-Is-Private"] == "True"
assert Project.objects.filter(slug="private-project-without-slots").count() == 0
def test_valid_dump_import_without_enough_membership_private_project_slots_one_project(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_private_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "project-without-memberships-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True,
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
{
"email": "test6@test.com",
"role": "Role",
},
],
"roles": [{"name": "Role"}]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
assert "reaches your current limit of memberships for private" in response.data["_error_message"]
assert Project.objects.filter(slug="project-without-memberships-slots").count() == 0
def test_valid_dump_import_without_enough_membership_public_project_slots_one_project(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_public_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "project-without-memberships-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False,
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
{
"email": "test6@test.com",
"role": "Role",
},
],
"roles": [{"name": "Role"}]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
assert "reaches your current limit of memberships for public" in response.data["_error_message"]
assert Project.objects.filter(slug="project-without-memberships-slots").count() == 0
def test_valid_dump_import_with_enough_membership_private_project_slots_multiple_projects(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_private_projects=10)
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "project-without-memberships-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True,
"roles": [{"name": "Role"}],
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
{
"email": "test6@test.com",
"role": "Role",
}
]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert "id" in response.data
assert response.data["name"] == "Valid project"
def test_valid_dump_import_with_enough_membership_public_project_slots_multiple_projects(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_public_projects=10)
project = f.ProjectFactory.create(owner=user)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
f.MembershipFactory.create(project=project)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "project-without-memberships-slots",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False,
"roles": [{"name": "Role"}],
"memberships": [
{
"email": "test1@test.com",
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
{
"email": "test6@test.com",
"role": "Role",
}
]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert "id" in response.data
assert response.data["name"] == "Valid project"
def test_valid_dump_import_with_the_limit_of_membership_whit_you_for_private_project(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_private_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "private-project-with-memberships-limit-with-you",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True,
"memberships": [
{
"email": user.email,
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
],
"roles": [{"name": "Role"}]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert Project.objects.filter(slug="private-project-with-memberships-limit-with-you").count() == 1
def test_valid_dump_import_with_the_limit_of_membership_whit_you_for_public_project(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_public_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "public-project-with-memberships-limit-with-you",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False,
"memberships": [
{
"email": user.email,
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
],
"roles": [{"name": "Role"}]
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert Project.objects.filter(slug="public-project-with-memberships-limit-with-you").count() == 1
def test_valid_dump_import_with_celery_disabled(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert "id" in response.data
assert response.data["name"] == "Valid project"
def test_invalid_dump_import_with_celery_disabled(client, settings):
settings.CELERY_ENABLED = False
user = f.UserFactory.create(max_memberships_public_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "invalid-project",
"name": "Invalid project",
"description": "Valid project desc",
"is_private": False,
"memberships": [
{
"email": user.email,
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
],
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 400
def test_valid_dump_import_with_celery_enabled(client, settings):
settings.CELERY_ENABLED = True
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 202
assert "import_id" in response.data
assert Project.objects.filter(slug="valid-project").count() == 1
def test_invalid_dump_import_with_celery_enabled(client, settings):
settings.CELERY_ENABLED = True
user = f.UserFactory.create(max_memberships_public_projects=5)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "invalid-project",
"name": "Invalid project",
"description": "Valid project desc",
"is_private": False,
"memberships": [
{
"email": user.email,
"role": "Role",
},
{
"email": "test2@test.com",
"role": "Role",
},
{
"email": "test3@test.com",
"role": "Role",
},
{
"email": "test4@test.com",
"role": "Role",
},
{
"email": "test5@test.com",
"role": "Role",
},
],
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 202
assert "import_id" in response.data
assert Project.objects.filter(slug="invalid-project").count() == 0
def test_dump_import_throttling(client, settings):
settings.REST_FRAMEWORK["DEFAULT_THROTTLE_RATES"]["import-dump-mode"] = "1/minute"
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": project.slug,
"name": "Test import",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
response = client.post(url, {'dump': data})
assert response.status_code == 429
def test_valid_dump_import_without_slug(client):
project = f.ProjectFactory.create(slug="existing-slug")
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"name": "Project name",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
def test_valid_dump_import_with_logo(client, settings):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": "valid-project",
"name": "Valid project",
"description": "Valid project desc",
"is_private": False,
"logo": {
"name": "logo.bmp",
"data": base64.b64encode(DUMMY_BMP_DATA).decode("utf-8")
}
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert "id" in response.data
assert response.data["name"] == "Valid project"
assert "logo_small_url" in response.data
assert response.data["logo_small_url"] != None
assert "logo_big_url" in response.data
assert response.data["logo_big_url"] != None
def test_valid_project_import_and_disabled_is_featured(client):
user = f.UserFactory.create()
client.login(user)
url = reverse("importer-list")
data = {
"name": "Imported project",
"description": "Imported project",
"roles": [{
"permissions": [],
"name": "Test"
}],
"is_featured": True
}
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
assert response.data["owner"] == user.email
assert response.data["is_featured"] == False
def test_dump_import_duplicated_project(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create(owner=user)
client.login(user)
url = reverse("importer-load-dump")
data = ContentFile(bytes(json.dumps({
"slug": project.slug,
"name": "Test import",
"description": "Valid project desc",
"is_private": True
}), "utf-8"))
data.name = "test"
response = client.post(url, {'dump': data})
assert response.status_code == 201
assert response.data["name"] == "Test import"
assert response.data["slug"] == "{}-test-import".format(user.username)
|
mit
|
[
3,
1898,
334,
35,
9,
6927,
13,
9261,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
15291,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
6832,
74,
460,
293,
4580,
265,
1152,
665,
1895,
74,
460,
293,
14,
279,
265,
1152,
32,
75,
1895,
344,
736,
14,
846,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4613,
199,
646,
1300,
772,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
1725,
14,
1095,
492,
6646,
1173,
199,
199,
504,
3052,
29055,
14,
1095,
14,
1208,
492,
2022,
199,
504,
3052,
29055,
14,
3790,
63,
646,
492,
8500,
199,
504,
3052,
29055,
14,
3790,
63,
646,
14,
3924,
492,
221,
32316,
29055,
17825,
199,
504,
3052,
29055,
14,
6776,
14,
992,
492,
7290,
12,
24326,
199,
504,
3052,
29055,
14,
6776,
14,
10115,
14,
992,
492,
13383,
199,
504,
3052,
29055,
14,
6776,
14,
751,
270,
6112,
14,
992,
492,
2876,
25120,
199,
504,
3052,
29055,
14,
6776,
14,
5054,
14,
992,
492,
8495,
199,
504,
3052,
29055,
14,
6776,
14,
6797,
14,
992,
492,
644,
11545,
3276,
199,
199,
504,
2508,
492,
22115,
465,
289,
199,
504,
2508,
1208,
492,
577,
22472,
63,
34,
1658,
63,
3998,
199,
199,
4462,
1657,
275,
4613,
14,
1657,
14,
1176,
63,
697,
4388,
199,
22529,
14776,
199,
309,
511,
2986,
15,
86,
17,
15,
12138,
199,
22529,
14776,
199,
199,
318,
511,
63,
3197,
63,
1715,
63,
646,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
342,
272,
1890,
14,
2886,
8,
751,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
1052,
339,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
272,
702,
1177,
14,
1205,
63,
600,
508,
8290,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
646,
63,
7395,
63,
2911,
63,
576,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
342,
272,
922,
63,
6821,
316,
275,
289,
14,
24594,
14,
981,
8,
2123,
628,
4776,
32,
502,
29055,
14,
2308,
531,
272,
1890,
14,
2886,
8,
751,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
469,
267,
298,
354,
582,
298,
8499,
1376,
2199,
401,
267,
298,
1802,
582,
298,
8499,
1376,
2199,
401,
267,
298,
8050,
582,
16870,
354,
582,
298,
7422,
3570,
467,
267,
298,
6821,
1192,
582,
2097,
4776,
32,
502,
29055,
14,
2308,
937,
272,
789,
339,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
272,
702,
1177,
14,
1205,
63,
600,
508,
1784,
272,
1471,
63,
1667,
63,
3223,
275,
359,
267,
298,
10115,
401,
298,
751,
63,
270,
6112,
401,
298,
527,
63,
17084,
401,
298,
6797,
63,
5856,
401,
298,
13775,
12107,
401,
267,
298,
261,
422,
12107,
401,
298,
77,
24156,
401,
298,
3438,
401,
298,
5237,
63,
1313,
401,
298,
1765,
63,
17084,
401,
267,
298,
5237,
63,
17084,
401,
298,
6797,
63,
4614,
401,
272,
1622,
272,
702,
1006,
8,
1130,
8,
2734,
671,
26,
822,
8,
1310,
14,
576,
59,
88,
566,
508,
378,
12,
1471,
63,
1667,
63,
3223,
430,
272,
702,
1177,
14,
576,
905,
4597,
937,
508,
922,
14,
2123,
272,
702,
1177,
14,
576,
905,
6821,
1192,
937,
508,
359,
751,
14,
2123,
12,
922,
63,
6821,
316,
14,
2123,
61,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
7395,
63,
30881,
63,
3455,
63,
6776,
63,
7257,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
8,
988,
63,
3455,
63,
6776,
29,
16,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
469,
267,
298,
5464,
582,
298,
3455,
13,
1715,
13,
7395,
13,
7257,
401,
267,
298,
354,
582,
298,
8499,
1376,
2199,
401,
267,
298,
1802,
582,
298,
8499,
1376,
2199,
401,
267,
298,
8050,
582,
16870,
354,
582,
298,
7422,
3570,
467,
267,
298,
374,
63,
4239,
582,
756,
272,
789,
339,
1890,
14,
2886,
8,
751,
9,
272,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
339,
702,
1177,
14,
1205,
63,
600,
508,
8290,
272,
702,
298,
2425,
1133,
1172,
1655,
4575,
11336,
2,
315,
1177,
14,
576,
18524,
705,
63,
1188,
937,
272,
702,
7290,
14,
1462,
14,
1541,
8,
5464,
628,
3455,
13,
1715,
13,
7395,
13,
7257,
3471,
835,
342,
508,
378,
272,
702,
1177,
905,
22620,
29055,
13,
2354,
13,
4761,
13,
19480,
83,
937,
508,
298,
17,
2,
272,
702,
1177,
905,
22620,
29055,
13,
2354,
13,
4761,
13,
1831,
13,
12185,
937,
508,
298,
797,
2,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
7395,
63,
30881,
63,
4239,
63,
6776,
63,
7257,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
8
] |
[
1898,
334,
35,
9,
6927,
13,
9261,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
15291,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
9261,
6832,
74,
460,
293,
4580,
265,
1152,
665,
1895,
74,
460,
293,
14,
279,
265,
1152,
32,
75,
1895,
344,
736,
14,
846,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
4613,
199,
646,
1300,
772,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1018,
14,
1725,
14,
1095,
492,
6646,
1173,
199,
199,
504,
3052,
29055,
14,
1095,
14,
1208,
492,
2022,
199,
504,
3052,
29055,
14,
3790,
63,
646,
492,
8500,
199,
504,
3052,
29055,
14,
3790,
63,
646,
14,
3924,
492,
221,
32316,
29055,
17825,
199,
504,
3052,
29055,
14,
6776,
14,
992,
492,
7290,
12,
24326,
199,
504,
3052,
29055,
14,
6776,
14,
10115,
14,
992,
492,
13383,
199,
504,
3052,
29055,
14,
6776,
14,
751,
270,
6112,
14,
992,
492,
2876,
25120,
199,
504,
3052,
29055,
14,
6776,
14,
5054,
14,
992,
492,
8495,
199,
504,
3052,
29055,
14,
6776,
14,
6797,
14,
992,
492,
644,
11545,
3276,
199,
199,
504,
2508,
492,
22115,
465,
289,
199,
504,
2508,
1208,
492,
577,
22472,
63,
34,
1658,
63,
3998,
199,
199,
4462,
1657,
275,
4613,
14,
1657,
14,
1176,
63,
697,
4388,
199,
22529,
14776,
199,
309,
511,
2986,
15,
86,
17,
15,
12138,
199,
22529,
14776,
199,
199,
318,
511,
63,
3197,
63,
1715,
63,
646,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
342,
272,
1890,
14,
2886,
8,
751,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
1052,
339,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
272,
702,
1177,
14,
1205,
63,
600,
508,
8290,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
646,
63,
7395,
63,
2911,
63,
576,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
342,
272,
922,
63,
6821,
316,
275,
289,
14,
24594,
14,
981,
8,
2123,
628,
4776,
32,
502,
29055,
14,
2308,
531,
272,
1890,
14,
2886,
8,
751,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
469,
267,
298,
354,
582,
298,
8499,
1376,
2199,
401,
267,
298,
1802,
582,
298,
8499,
1376,
2199,
401,
267,
298,
8050,
582,
16870,
354,
582,
298,
7422,
3570,
467,
267,
298,
6821,
1192,
582,
2097,
4776,
32,
502,
29055,
14,
2308,
937,
272,
789,
339,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
272,
702,
1177,
14,
1205,
63,
600,
508,
1784,
272,
1471,
63,
1667,
63,
3223,
275,
359,
267,
298,
10115,
401,
298,
751,
63,
270,
6112,
401,
298,
527,
63,
17084,
401,
298,
6797,
63,
5856,
401,
298,
13775,
12107,
401,
267,
298,
261,
422,
12107,
401,
298,
77,
24156,
401,
298,
3438,
401,
298,
5237,
63,
1313,
401,
298,
1765,
63,
17084,
401,
267,
298,
5237,
63,
17084,
401,
298,
6797,
63,
4614,
401,
272,
1622,
272,
702,
1006,
8,
1130,
8,
2734,
671,
26,
822,
8,
1310,
14,
576,
59,
88,
566,
508,
378,
12,
1471,
63,
1667,
63,
3223,
430,
272,
702,
1177,
14,
576,
905,
4597,
937,
508,
922,
14,
2123,
272,
702,
1177,
14,
576,
905,
6821,
1192,
937,
508,
359,
751,
14,
2123,
12,
922,
63,
6821,
316,
14,
2123,
61,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
7395,
63,
30881,
63,
3455,
63,
6776,
63,
7257,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
8,
988,
63,
3455,
63,
6776,
29,
16,
9,
339,
1166,
275,
3837,
480,
12138,
13,
513,
531,
272,
666,
275,
469,
267,
298,
5464,
582,
298,
3455,
13,
1715,
13,
7395,
13,
7257,
401,
267,
298,
354,
582,
298,
8499,
1376,
2199,
401,
267,
298,
1802,
582,
298,
8499,
1376,
2199,
401,
267,
298,
8050,
582,
16870,
354,
582,
298,
7422,
3570,
467,
267,
298,
374,
63,
4239,
582,
756,
272,
789,
339,
1890,
14,
2886,
8,
751,
9,
272,
1177,
275,
1890,
14,
1001,
14,
1932,
8,
633,
12,
2022,
14,
4180,
8,
576,
430,
339,
702,
1177,
14,
1205,
63,
600,
508,
8290,
272,
702,
298,
2425,
1133,
1172,
1655,
4575,
11336,
2,
315,
1177,
14,
576,
18524,
705,
63,
1188,
937,
272,
702,
7290,
14,
1462,
14,
1541,
8,
5464,
628,
3455,
13,
1715,
13,
7395,
13,
7257,
3471,
835,
342,
508,
378,
272,
702,
1177,
905,
22620,
29055,
13,
2354,
13,
4761,
13,
19480,
83,
937,
508,
298,
17,
2,
272,
702,
1177,
905,
22620,
29055,
13,
2354,
13,
4761,
13,
1831,
13,
12185,
937,
508,
298,
797,
2,
421,
199,
318,
511,
63,
1078,
63,
1715,
63,
7395,
63,
30881,
63,
4239,
63,
6776,
63,
7257,
8,
1258,
304,
272,
922,
275,
289,
14,
24594,
14,
981,
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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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
] |
sam-m888/gramps
|
gramps/gen/filters/rules/family/_memberbase.py
|
10
|
2013
|
#
# 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.
#
"""
Set of wrappers for family filter rules based on personal rules.
Any rule that matches family based on personal rule applied
to father, mother, or any child, just needs to do two things:
> Set the class attribute 'base_class' to the personal rule
> Set apply method to be an appropriate wrapper below
Example:
in the class body, outside any method:
> base_class = SearchName
> apply = child_base
"""
def father_base(self, db, family):
father_handle = family.get_father_handle()
if father_handle:
father = db.get_person_from_handle(father_handle)
if father:
return self.base_class.apply(self, db, father)
else:
return False
def mother_base(self, db, family):
mother_handle = family.get_mother_handle()
if mother_handle:
mother = db.get_person_from_handle(mother_handle)
if mother:
return self.base_class.apply(self, db, mother)
else:
return False
def child_base(self, db, family):
for child_ref in family.get_child_ref_list():
child = db.get_person_from_handle(child_ref.ref)
if self.base_class.apply(self, db, child):
return True
return False
|
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,
624,
199,
1084,
402,
17995,
367,
9614,
2457,
4713,
4079,
641,
25994,
4713,
14,
199,
199,
9874,
2332,
626,
4450,
9614,
4079,
641,
25994,
2332,
6781,
199,
475,
1433,
728,
12,
1303,
728,
12,
503,
1263,
1982,
12,
2951,
4839,
370,
886,
2877,
7645,
26,
199,
30,
2494,
314,
1021,
2225,
283,
1095,
63,
533,
7,
370,
314,
25994,
2332,
199,
30,
2494,
4838,
1083,
370,
506,
376,
5827,
4975,
5084,
199,
9846,
26,
199,
262,
314,
1021,
2396,
12,
9682,
1263,
1083,
26,
199,
30,
259,
1300,
63,
533,
275,
8730,
985,
199,
30,
259,
4838,
275,
1982,
63,
1095,
199,
624,
199,
199,
318,
1433,
728,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
1433,
728,
63,
2479,
275,
9614,
14,
362,
63,
667,
728,
63,
2479,
342,
272,
340,
1433,
728,
63,
2479,
26,
267,
1433,
728,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
667,
728,
63,
2479,
9,
267,
340,
1433,
728,
26,
288,
372,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1433,
728,
9,
267,
587,
26,
288,
372,
756,
199,
199,
318,
1303,
728,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
1303,
728,
63,
2479,
275,
9614,
14,
362,
63,
573,
728,
63,
2479,
342,
272,
340,
1303,
728,
63,
2479,
26,
267,
1303,
728,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
573,
728,
63,
2479,
9,
267,
340,
1303,
728,
26,
288,
372,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1303,
728,
9,
267,
587,
26,
288,
372,
756,
199,
199,
318,
1982,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
367,
1982,
63,
1121,
315,
9614,
14,
362,
63,
1739,
63,
1121,
63,
513,
837,
267,
1982,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
1739,
63,
1121,
14,
1121,
9,
267,
340,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1982,
304,
288,
372,
715,
272,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
624,
199,
1084,
402,
17995,
367,
9614,
2457,
4713,
4079,
641,
25994,
4713,
14,
199,
199,
9874,
2332,
626,
4450,
9614,
4079,
641,
25994,
2332,
6781,
199,
475,
1433,
728,
12,
1303,
728,
12,
503,
1263,
1982,
12,
2951,
4839,
370,
886,
2877,
7645,
26,
199,
30,
2494,
314,
1021,
2225,
283,
1095,
63,
533,
7,
370,
314,
25994,
2332,
199,
30,
2494,
4838,
1083,
370,
506,
376,
5827,
4975,
5084,
199,
9846,
26,
199,
262,
314,
1021,
2396,
12,
9682,
1263,
1083,
26,
199,
30,
259,
1300,
63,
533,
275,
8730,
985,
199,
30,
259,
4838,
275,
1982,
63,
1095,
199,
624,
199,
199,
318,
1433,
728,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
1433,
728,
63,
2479,
275,
9614,
14,
362,
63,
667,
728,
63,
2479,
342,
272,
340,
1433,
728,
63,
2479,
26,
267,
1433,
728,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
667,
728,
63,
2479,
9,
267,
340,
1433,
728,
26,
288,
372,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1433,
728,
9,
267,
587,
26,
288,
372,
756,
199,
199,
318,
1303,
728,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
1303,
728,
63,
2479,
275,
9614,
14,
362,
63,
573,
728,
63,
2479,
342,
272,
340,
1303,
728,
63,
2479,
26,
267,
1303,
728,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
573,
728,
63,
2479,
9,
267,
340,
1303,
728,
26,
288,
372,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1303,
728,
9,
267,
587,
26,
288,
372,
756,
199,
199,
318,
1982,
63,
1095,
8,
277,
12,
1592,
12,
9614,
304,
272,
367,
1982,
63,
1121,
315,
9614,
14,
362,
63,
1739,
63,
1121,
63,
513,
837,
267,
1982,
275,
1592,
14,
362,
63,
5484,
63,
504,
63,
2479,
8,
1739,
63,
1121,
14,
1121,
9,
267,
340,
291,
14,
1095,
63,
533,
14,
4998,
8,
277,
12,
1592,
12,
1982,
304,
288,
372,
715,
272,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
unixunion/python-libsolace
|
libsolace/settingsloader.py
|
1
|
2455
|
import yaml
import os
import logging
import sys
__author__ = 'johlyh'
primary_config = 'libsolace.yaml',
try:
primary_config = os.environ['LIBSOLACE_CONFIG']
except Exception, e:
pass
__yamlfiles__ = [
"%s" % primary_config,
'/etc/libsolace/libsolace.yaml',
'/opt/libsolace/libsolace.yaml'
]
__doc__ = """
The settingsloader searches for a libsolace.yaml file in:
- libsolace.yaml
- /etc/libsolace/libsolace.yaml
- /opt/libsolace/libsolace.yaml
The environment variable: :envvar:`LIBSOLACE_CONFIG` can also be used to specify another file. e.g
LIBSOLACE_CONFIG="/tmp/my.yaml" ./bin/solace-provision.py ....
Examples:
>>> import libsolace.settingsloader as settings
>>> settings.CMDB_URL
'http://mydomain.com/path'
"""
logging.basicConfig(format='[%(module)s] %(filename)s:%(lineno)s %(asctime)s %(levelname)s %(message)s',
stream=sys.stdout)
logging.getLogger().setLevel(logging.INFO)
logging = logging.getLogger(__name__)
yaml_loaded = False
# defaults which are set / could not be present
defaults = {
"UPDATE_MOCK_TESTS": False,
"CMDB_URL": "http://someurl/site.xml",
"CMDB_FILE": "provision-example.yaml",
"CMDB_USER": "",
"CMDB_PASS": "",
"SOLACE_QUEUE_PLUGIN": "SolaceQueue"
}
for yaml_file in __yamlfiles__:
if not os.path.exists(yaml_file):
continue
logging.info("Using yaml file %s" % yaml_file)
stream = open(yaml_file, 'r')
yaml_settings = yaml.load(stream)
# set the defaults
for default in defaults:
logging.info("Setting default %s:%s" % (default, defaults[default]))
globals()[default] = defaults[default]
# TODO FIXME
# get each plugins "default" variables and add to globals
# get the real values if any
for variable in yaml_settings.keys():
logging.info("Setting config %s:%s" % (variable, yaml_settings[variable]))
globals()[variable] = yaml_settings[variable]
yaml_loaded = True
logging.debug("Yaml loaded successful")
logging.info("Loading plugins...")
for p in globals()['PLUGINS']:
try:
__import__(p, globals())
except Exception, e:
logging.error("Failed to import plugin %s" % p)
raise
break
if yaml_loaded is False:
msg = "Failed to find libpipeline.yaml in any of these locations: %s" % ",".join(__yamlfiles__)
logging.error(msg)
raise Exception(msg)
|
mit
|
[
646,
8864,
199,
646,
747,
199,
646,
2050,
199,
646,
984,
199,
199,
363,
2502,
363,
275,
283,
31073,
590,
72,
7,
199,
199,
3327,
63,
888,
275,
283,
773,
7873,
7984,
14,
5963,
297,
199,
199,
893,
26,
272,
5062,
63,
888,
275,
747,
14,
2314,
459,
5617,
15096,
4121,
63,
5569,
418,
199,
2590,
2186,
12,
325,
26,
272,
986,
199,
199,
363,
89,
455,
12059,
83,
363,
275,
359,
272,
2071,
83,
2,
450,
5062,
63,
888,
12,
272,
1994,
6839,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
297,
272,
1994,
2992,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
7,
199,
61,
199,
363,
1301,
363,
275,
408,
199,
1918,
2202,
3422,
21858,
367,
282,
1973,
7873,
7984,
14,
5963,
570,
315,
26,
339,
446,
1973,
7873,
7984,
14,
5963,
272,
446,
1182,
6839,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
272,
446,
1182,
2992,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
199,
199,
1918,
3734,
1750,
26,
520,
1813,
1391,
1705,
5617,
15096,
4121,
63,
5569,
64,
883,
2597,
506,
1202,
370,
4165,
4573,
570,
14,
325,
14,
71,
339,
25764,
15096,
4121,
63,
5569,
9555,
2791,
15,
1662,
14,
5963,
2,
16605,
1393,
15,
7873,
7984,
13,
13717,
14,
647,
29222,
199,
199,
22787,
26,
339,
1306,
492,
1973,
7873,
7984,
14,
1751,
3422,
465,
2202,
272,
1306,
2202,
14,
9249,
2846,
63,
2632,
272,
283,
1014,
921,
30945,
14,
957,
15,
515,
7,
199,
199,
624,
199,
199,
4806,
14,
19602,
8,
908,
30845,
2840,
578,
9,
83,
61,
2818,
1501,
9,
83,
19648,
3469,
9,
83,
2818,
18331,
9,
83,
2818,
20056,
9,
83,
2818,
1188,
9,
83,
297,
490,
2547,
29,
1274,
14,
2703,
9,
199,
4806,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
199,
199,
4806,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
5963,
63,
4591,
275,
756,
199,
199,
3,
4243,
1314,
787,
663,
1182,
4293,
440,
506,
3451,
199,
4322,
275,
469,
272,
298,
10383,
63,
17749,
63,
7569,
582,
756,
12,
272,
298,
9249,
2846,
63,
2632,
582,
298,
1014,
921,
3972,
633,
15,
2124,
14,
1652,
401,
272,
298,
9249,
2846,
63,
3817,
582,
298,
13717,
13,
2694,
14,
5963,
401,
272,
298,
9249,
2846,
63,
3791,
582,
4873,
272,
298,
9249,
2846,
63,
6909,
582,
4873,
272,
298,
15096,
4121,
63,
15125,
63,
19108,
582,
298,
27262,
7984,
3737,
2,
199,
93,
199,
199,
509,
8864,
63,
493,
315,
636,
89,
455,
12059,
83,
10651,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5963,
63,
493,
304,
267,
1980,
339,
2050,
14,
815,
480,
10369,
8864,
570,
450,
83,
2,
450,
8864,
63,
493,
9,
272,
2547,
275,
1551,
8,
5963,
63,
493,
12,
283,
82,
358,
272,
8864,
63,
1751,
275,
8864,
14,
912,
8,
1745,
9,
339,
327,
663,
314,
4243,
272,
367,
849,
315,
4243,
26,
267,
2050,
14,
815,
480,
7776,
849,
450,
83,
2689,
83,
2,
450,
334,
885,
12,
4243,
59,
885,
2459,
267,
7992,
3430,
885,
61,
275,
4243,
59,
885,
61,
339,
327,
3254,
7600,
272,
327,
664,
1924,
8963,
298,
885,
2,
2860,
436,
1050,
370,
7992,
339,
327,
664,
314,
3363,
1338,
340,
1263,
272,
367,
1750,
315,
8864,
63,
1751,
14,
1612,
837,
267,
2050,
14,
815,
480,
7776,
1101,
450,
83,
2689,
83,
2,
450,
334,
1975,
12,
8864,
63,
1751,
59,
1975,
2459,
267,
7992,
3430,
1975,
61,
275,
8864,
63,
1751,
59,
1975,
61,
339,
8864,
63,
4591,
275,
715,
272,
2050,
14,
1757,
480,
57,
3935,
6511,
9512,
531,
339,
2050,
14,
815,
480,
19236,
8963,
12594,
272,
367,
299,
315,
7992,
12047,
16483,
10789,
2565,
267,
862,
26,
288,
636,
646,
721,
80,
12,
7992,
1012,
267,
871,
2186,
12,
325,
26,
288,
2050,
14,
705,
480,
4276,
370,
492,
3589,
450,
83,
2,
450,
299,
9,
288,
746,
272,
2059,
199,
199,
692,
8864,
63,
4591,
365,
756,
26,
272,
1499,
275,
298,
4276,
370,
2342,
1973,
7379,
14,
5963,
315,
1263,
402,
3520,
9918,
26,
450,
83,
2,
450,
19089,
904,
3460,
89,
455,
12059,
83,
3368,
272,
2050,
14,
705,
8,
1328,
9,
272,
746,
2186,
8,
1328,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8864,
199,
646,
747,
199,
646,
2050,
199,
646,
984,
199,
199,
363,
2502,
363,
275,
283,
31073,
590,
72,
7,
199,
199,
3327,
63,
888,
275,
283,
773,
7873,
7984,
14,
5963,
297,
199,
199,
893,
26,
272,
5062,
63,
888,
275,
747,
14,
2314,
459,
5617,
15096,
4121,
63,
5569,
418,
199,
2590,
2186,
12,
325,
26,
272,
986,
199,
199,
363,
89,
455,
12059,
83,
363,
275,
359,
272,
2071,
83,
2,
450,
5062,
63,
888,
12,
272,
1994,
6839,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
297,
272,
1994,
2992,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
7,
199,
61,
199,
363,
1301,
363,
275,
408,
199,
1918,
2202,
3422,
21858,
367,
282,
1973,
7873,
7984,
14,
5963,
570,
315,
26,
339,
446,
1973,
7873,
7984,
14,
5963,
272,
446,
1182,
6839,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
272,
446,
1182,
2992,
15,
773,
7873,
7984,
15,
773,
7873,
7984,
14,
5963,
199,
199,
1918,
3734,
1750,
26,
520,
1813,
1391,
1705,
5617,
15096,
4121,
63,
5569,
64,
883,
2597,
506,
1202,
370,
4165,
4573,
570,
14,
325,
14,
71,
339,
25764,
15096,
4121,
63,
5569,
9555,
2791,
15,
1662,
14,
5963,
2,
16605,
1393,
15,
7873,
7984,
13,
13717,
14,
647,
29222,
199,
199,
22787,
26,
339,
1306,
492,
1973,
7873,
7984,
14,
1751,
3422,
465,
2202,
272,
1306,
2202,
14,
9249,
2846,
63,
2632,
272,
283,
1014,
921,
30945,
14,
957,
15,
515,
7,
199,
199,
624,
199,
199,
4806,
14,
19602,
8,
908,
30845,
2840,
578,
9,
83,
61,
2818,
1501,
9,
83,
19648,
3469,
9,
83,
2818,
18331,
9,
83,
2818,
20056,
9,
83,
2818,
1188,
9,
83,
297,
490,
2547,
29,
1274,
14,
2703,
9,
199,
4806,
14,
5572,
1252,
13548,
8,
4806,
14,
4531,
9,
199,
199,
4806,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
5963,
63,
4591,
275,
756,
199,
199,
3,
4243,
1314,
787,
663,
1182,
4293,
440,
506,
3451,
199,
4322,
275,
469,
272,
298,
10383,
63,
17749,
63,
7569,
582,
756,
12,
272,
298,
9249,
2846,
63,
2632,
582,
298,
1014,
921,
3972,
633,
15,
2124,
14,
1652,
401,
272,
298,
9249,
2846,
63,
3817,
582,
298,
13717,
13,
2694,
14,
5963,
401,
272,
298,
9249,
2846,
63,
3791,
582,
4873,
272,
298,
9249,
2846,
63,
6909,
582,
4873,
272,
298,
15096,
4121,
63,
15125,
63,
19108,
582,
298,
27262,
7984,
3737,
2,
199,
93,
199,
199,
509,
8864,
63,
493,
315,
636,
89,
455,
12059,
83,
10651,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
5963,
63,
493,
304,
267,
1980,
339,
2050,
14,
815,
480,
10369,
8864,
570,
450,
83,
2,
450,
8864,
63,
493,
9,
272,
2547,
275,
1551,
8,
5963,
63,
493,
12,
283,
82,
358,
272,
8864,
63,
1751,
275,
8864,
14,
912,
8,
1745,
9,
339,
327,
663,
314,
4243,
272,
367,
849,
315,
4243,
26,
267,
2050,
14,
815,
480,
7776,
849,
450,
83,
2689,
83,
2,
450,
334,
885,
12,
4243,
59,
885,
2459,
267,
7992,
3430,
885,
61,
275,
4243,
59,
885,
61,
339,
327,
3254,
7600,
272,
327,
664,
1924,
8963,
298,
885,
2,
2860,
436,
1050,
370,
7992,
339,
327,
664,
314,
3363,
1338,
340,
1263,
272,
367,
1750,
315,
8864,
63,
1751,
14,
1612,
837,
267,
2050,
14,
815,
480,
7776,
1101,
450,
83,
2689,
83,
2,
450,
334,
1975,
12,
8864,
63,
1751,
59,
1975,
2459,
267,
7992,
3430,
1975,
61,
275,
8864,
63,
1751,
59,
1975,
61,
339,
8864,
63,
4591,
275,
715,
272,
2050,
14,
1757,
480,
57,
3935,
6511,
9512,
531,
339,
2050,
14,
815,
480,
19236,
8963,
12594,
272,
367,
299,
315,
7992,
12047,
16483,
10789,
2565,
267,
862,
26,
288,
636,
646,
721,
80,
12,
7992,
1012,
267,
871,
2186,
12,
325,
26,
288,
2050,
14,
705,
480,
4276,
370,
492,
3589,
450,
83,
2,
450,
299,
9,
288,
746,
272,
2059,
199,
199,
692,
8864,
63,
4591,
365,
756,
26,
272,
1499,
275,
298,
4276,
370,
2342,
1973,
7379,
14,
5963,
315,
1263,
402,
3520,
9918,
26,
450,
83,
2,
450,
19089,
904,
3460,
89,
455,
12059,
83,
3368,
272,
2050,
14,
705,
8,
1328,
9,
272,
746,
2186,
8,
1328,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
davidyezsetz/kuma
|
vendor/packages/sqlalchemy/lib/sqlalchemy/dialects/firebird/base.py
|
17
|
26177
|
# firebird.py
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Michael Bayer mike_mp@zzzcomputing.com
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""
Support for the Firebird database.
Connectivity is usually supplied via the kinterbasdb_ DBAPI module.
Dialects
~~~~~~~~
Firebird offers two distinct dialects_ (not to be confused with a
SQLAlchemy ``Dialect``):
dialect 1
This is the old syntax and behaviour, inherited from Interbase pre-6.0.
dialect 3
This is the newer and supported syntax, introduced in Interbase 6.0.
The SQLAlchemy Firebird dialect detects these versions and
adjusts its representation of SQL accordingly. However,
support for dialect 1 is not well tested and probably has
incompatibilities.
Locking Behavior
~~~~~~~~~~~~~~~~
Firebird locks tables aggressively. For this reason, a DROP TABLE may
hang until other transactions are released. SQLAlchemy does its best
to release transactions as quickly as possible. The most common cause
of hanging transactions is a non-fully consumed result set, i.e.::
result = engine.execute("select * from table")
row = result.fetchone()
return
Where above, the ``ResultProxy`` has not been fully consumed. The
connection will be returned to the pool and the transactional state
rolled back once the Python garbage collector reclaims the objects
which hold onto the connection, which often occurs asynchronously.
The above use case can be alleviated by calling ``first()`` on the
``ResultProxy`` which will fetch the first row and immediately close
all remaining cursor/connection resources.
RETURNING support
~~~~~~~~~~~~~~~~~
Firebird 2.0 supports returning a result set from inserts, and 2.1
extends that to deletes and updates. This is generically exposed by
the SQLAlchemy ``returning()`` method, such as::
# INSERT..RETURNING
result = table.insert().returning(table.c.col1, table.c.col2).\\
values(name='foo')
print result.fetchall()
# UPDATE..RETURNING
raises = empl.update().returning(empl.c.id, empl.c.salary).\\
where(empl.c.sales>100).\\
values(dict(salary=empl.c.salary * 1.1))
print raises.fetchall()
.. _dialects: http://mc-computing.com/Databases/Firebird/SQL_Dialect.html
"""
import datetime, re
from sqlalchemy import schema as sa_schema
from sqlalchemy import exc, types as sqltypes, sql, util
from sqlalchemy.sql import expression
from sqlalchemy.engine import base, default, reflection
from sqlalchemy.sql import compiler
from sqlalchemy.types import (BIGINT, BLOB, BOOLEAN, DATE,
FLOAT, INTEGER, NUMERIC, SMALLINT,
TEXT, TIME, TIMESTAMP)
RESERVED_WORDS = set([
"active", "add", "admin", "after", "all", "alter", "and", "any", "as",
"asc", "ascending", "at", "auto", "avg", "before", "begin", "between",
"bigint", "bit_length", "blob", "both", "by", "case", "cast", "char",
"character", "character_length", "char_length", "check", "close",
"collate", "column", "commit", "committed", "computed", "conditional",
"connect", "constraint", "containing", "count", "create", "cross",
"cstring", "current", "current_connection", "current_date",
"current_role", "current_time", "current_timestamp",
"current_transaction", "current_user", "cursor", "database", "date",
"day", "dec", "decimal", "declare", "default", "delete", "desc",
"descending", "disconnect", "distinct", "do", "domain", "double",
"drop", "else", "end", "entry_point", "escape", "exception",
"execute", "exists", "exit", "external", "extract", "fetch", "file",
"filter", "float", "for", "foreign", "from", "full", "function",
"gdscode", "generator", "gen_id", "global", "grant", "group",
"having", "hour", "if", "in", "inactive", "index", "inner",
"input_type", "insensitive", "insert", "int", "integer", "into", "is",
"isolation", "join", "key", "leading", "left", "length", "level",
"like", "long", "lower", "manual", "max", "maximum_segment", "merge",
"min", "minute", "module_name", "month", "names", "national",
"natural", "nchar", "no", "not", "null", "numeric", "octet_length",
"of", "on", "only", "open", "option", "or", "order", "outer",
"output_type", "overflow", "page", "pages", "page_size", "parameter",
"password", "plan", "position", "post_event", "precision", "primary",
"privileges", "procedure", "protected", "rdb$db_key", "read", "real",
"record_version", "recreate", "recursive", "references", "release",
"reserv", "reserving", "retain", "returning_values", "returns",
"revoke", "right", "rollback", "rows", "row_count", "savepoint",
"schema", "second", "segment", "select", "sensitive", "set", "shadow",
"shared", "singular", "size", "smallint", "snapshot", "some", "sort",
"sqlcode", "stability", "start", "starting", "starts", "statistics",
"sub_type", "sum", "suspend", "table", "then", "time", "timestamp",
"to", "trailing", "transaction", "trigger", "trim", "uncommitted",
"union", "unique", "update", "upper", "user", "using", "value",
"values", "varchar", "variable", "varying", "view", "wait", "when",
"where", "while", "with", "work", "write", "year",
])
class _StringType(sqltypes.String):
"""Base for Firebird string types."""
def __init__(self, charset = None, **kw):
self.charset = charset
super(_StringType, self).__init__(**kw)
class VARCHAR(_StringType, sqltypes.VARCHAR):
"""Firebird VARCHAR type"""
__visit_name__ = 'VARCHAR'
def __init__(self, length = None, **kwargs):
super(VARCHAR, self).__init__(length=length, **kwargs)
class CHAR(_StringType, sqltypes.CHAR):
"""Firebird CHAR type"""
__visit_name__ = 'CHAR'
def __init__(self, length = None, **kwargs):
super(CHAR, self).__init__(length=length, **kwargs)
colspecs = {
}
ischema_names = {
'SHORT': SMALLINT,
'LONG': BIGINT,
'QUAD': FLOAT,
'FLOAT': FLOAT,
'DATE': DATE,
'TIME': TIME,
'TEXT': TEXT,
'INT64': NUMERIC,
'DOUBLE': FLOAT,
'TIMESTAMP': TIMESTAMP,
'VARYING': VARCHAR,
'CSTRING': CHAR,
'BLOB': BLOB,
}
# TODO: date conversion types (should be implemented as _FBDateTime,
# _FBDate, etc. as bind/result functionality is required)
class FBTypeCompiler(compiler.GenericTypeCompiler):
def visit_boolean(self, type_):
return self.visit_SMALLINT(type_)
def visit_datetime(self, type_):
return self.visit_TIMESTAMP(type_)
def visit_TEXT(self, type_):
return "BLOB SUB_TYPE 1"
def visit_BLOB(self, type_):
return "BLOB SUB_TYPE 0"
def _extend_string(self, type_, basic):
charset = getattr(type_, 'charset', None)
if charset is None:
return basic
else:
return '%s CHARACTER SET %s' % (basic, charset)
def visit_CHAR(self, type_):
basic = super(FBTypeCompiler, self).visit_CHAR(type_)
return self._extend_string(type_, basic)
def visit_VARCHAR(self, type_):
basic = super(FBTypeCompiler, self).visit_VARCHAR(type_)
return self._extend_string(type_, basic)
class FBCompiler(sql.compiler.SQLCompiler):
"""Firebird specific idiosincrasies"""
def visit_mod(self, binary, **kw):
# Firebird lacks a builtin modulo operator, but there is
# an equivalent function in the ib_udf library.
return "mod(%s, %s)" % (
self.process(binary.left),
self.process(binary.right))
def visit_alias(self, alias, asfrom=False, **kwargs):
if self.dialect._version_two:
return super(FBCompiler, self).\
visit_alias(alias, asfrom=asfrom, **kwargs)
else:
# Override to not use the AS keyword which FB 1.5 does not like
if asfrom:
alias_name = isinstance(alias.name,
expression._generated_label) and \
self._truncated_identifier("alias",
alias.name) or alias.name
return self.process(
alias.original, asfrom=asfrom, **kwargs) + \
" " + \
self.preparer.format_alias(alias, alias_name)
else:
return self.process(alias.original, **kwargs)
def visit_substring_func(self, func, **kw):
s = self.process(func.clauses.clauses[0])
start = self.process(func.clauses.clauses[1])
if len(func.clauses.clauses) > 2:
length = self.process(func.clauses.clauses[2])
return "SUBSTRING(%s FROM %s FOR %s)" % (s, start, length)
else:
return "SUBSTRING(%s FROM %s)" % (s, start)
def visit_length_func(self, function, **kw):
if self.dialect._version_two:
return "char_length" + self.function_argspec(function)
else:
return "strlen" + self.function_argspec(function)
visit_char_length_func = visit_length_func
def function_argspec(self, func, **kw):
if func.clauses is not None and len(func.clauses):
return self.process(func.clause_expr)
else:
return ""
def default_from(self):
return " FROM rdb$database"
def visit_sequence(self, seq):
return "gen_id(%s, 1)" % self.preparer.format_sequence(seq)
def get_select_precolumns(self, select):
"""Called when building a ``SELECT`` statement, position is just
before column list Firebird puts the limit and offset right
after the ``SELECT``...
"""
result = ""
if select._limit:
result += "FIRST %d " % select._limit
if select._offset:
result +="SKIP %d " % select._offset
if select._distinct:
result += "DISTINCT "
return result
def limit_clause(self, select):
"""Already taken care of in the `get_select_precolumns` method."""
return ""
def returning_clause(self, stmt, returning_cols):
columns = [
self.process(
self.label_select_column(None, c, asfrom=False),
within_columns_clause=True,
result_map=self.result_map
)
for c in expression._select_iterables(returning_cols)
]
return 'RETURNING ' + ', '.join(columns)
class FBDDLCompiler(sql.compiler.DDLCompiler):
"""Firebird syntactic idiosincrasies"""
def visit_create_sequence(self, create):
"""Generate a ``CREATE GENERATOR`` statement for the sequence."""
# no syntax for these
# http://www.firebirdsql.org/manual/generatorguide-sqlsyntax.html
if create.element.start is not None:
raise NotImplemented(
"Firebird SEQUENCE doesn't support START WITH")
if create.element.increment is not None:
raise NotImplemented(
"Firebird SEQUENCE doesn't support INCREMENT BY")
if self.dialect._version_two:
return "CREATE SEQUENCE %s" % \
self.preparer.format_sequence(create.element)
else:
return "CREATE GENERATOR %s" % \
self.preparer.format_sequence(create.element)
def visit_drop_sequence(self, drop):
"""Generate a ``DROP GENERATOR`` statement for the sequence."""
if self.dialect._version_two:
return "DROP SEQUENCE %s" % \
self.preparer.format_sequence(drop.element)
else:
return "DROP GENERATOR %s" % \
self.preparer.format_sequence(drop.element)
class FBIdentifierPreparer(sql.compiler.IdentifierPreparer):
"""Install Firebird specific reserved words."""
reserved_words = RESERVED_WORDS
def __init__(self, dialect):
super(FBIdentifierPreparer, self).__init__(dialect, omit_schema=True)
class FBExecutionContext(default.DefaultExecutionContext):
def fire_sequence(self, seq):
"""Get the next value from the sequence using ``gen_id()``."""
return self._execute_scalar(
"SELECT gen_id(%s, 1) FROM rdb$database" %
self.dialect.identifier_preparer.format_sequence(seq)
)
class FBDialect(default.DefaultDialect):
"""Firebird dialect"""
name = 'firebird'
max_identifier_length = 31
supports_sequences = True
sequences_optional = False
supports_default_values = True
postfetch_lastrowid = False
supports_native_boolean = False
requires_name_normalize = True
supports_empty_insert = False
statement_compiler = FBCompiler
ddl_compiler = FBDDLCompiler
preparer = FBIdentifierPreparer
type_compiler = FBTypeCompiler
execution_ctx_cls = FBExecutionContext
colspecs = colspecs
ischema_names = ischema_names
# defaults to dialect ver. 3,
# will be autodetected off upon
# first connect
_version_two = True
def initialize(self, connection):
super(FBDialect, self).initialize(connection)
self._version_two = self.server_version_info > (2, )
if not self._version_two:
# TODO: whatever other pre < 2.0 stuff goes here
self.ischema_names = ischema_names.copy()
self.ischema_names['TIMESTAMP'] = sqltypes.DATE
self.colspecs = {
sqltypes.DateTime: sqltypes.DATE
}
else:
self.implicit_returning = True
def normalize_name(self, name):
# Remove trailing spaces: FB uses a CHAR() type,
# that is padded with spaces
name = name and name.rstrip()
if name is None:
return None
elif name.upper() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.lower()
else:
return name
def denormalize_name(self, name):
if name is None:
return None
elif name.lower() == name and \
not self.identifier_preparer._requires_quotes(name.lower()):
return name.upper()
else:
return name
def has_table(self, connection, table_name, schema=None):
"""Return ``True`` if the given table exists, ignoring
the `schema`."""
tblqry = """
SELECT 1 AS has_table FROM rdb$database
WHERE EXISTS (SELECT rdb$relation_name
FROM rdb$relations
WHERE rdb$relation_name=?)
"""
c = connection.execute(tblqry, [self.denormalize_name(table_name)])
return c.first() is not None
def has_sequence(self, connection, sequence_name, schema=None):
"""Return ``True`` if the given sequence (generator) exists."""
genqry = """
SELECT 1 AS has_sequence FROM rdb$database
WHERE EXISTS (SELECT rdb$generator_name
FROM rdb$generators
WHERE rdb$generator_name=?)
"""
c = connection.execute(genqry, [self.denormalize_name(sequence_name)])
return c.first() is not None
@reflection.cache
def get_table_names(self, connection, schema=None, **kw):
s = """
SELECT DISTINCT rdb$relation_name
FROM rdb$relation_fields
WHERE rdb$system_flag=0 AND rdb$view_context IS NULL
"""
return [self.normalize_name(row[0]) for row in connection.execute(s)]
@reflection.cache
def get_view_names(self, connection, schema=None, **kw):
s = """
SELECT distinct rdb$view_name
FROM rdb$view_relations
"""
return [self.normalize_name(row[0]) for row in connection.execute(s)]
@reflection.cache
def get_view_definition(self, connection, view_name, schema=None, **kw):
qry = """
SELECT rdb$view_source AS view_source
FROM rdb$relations
WHERE rdb$relation_name=?
"""
rp = connection.execute(qry, [self.denormalize_name(view_name)])
row = rp.first()
if row:
return row['view_source']
else:
return None
@reflection.cache
def get_primary_keys(self, connection, table_name, schema=None, **kw):
# Query to extract the PK/FK constrained fields of the given table
keyqry = """
SELECT se.rdb$field_name AS fname
FROM rdb$relation_constraints rc
JOIN rdb$index_segments se ON rc.rdb$index_name=se.rdb$index_name
WHERE rc.rdb$constraint_type=? AND rc.rdb$relation_name=?
"""
tablename = self.denormalize_name(table_name)
# get primary key fields
c = connection.execute(keyqry, ["PRIMARY KEY", tablename])
pkfields = [self.normalize_name(r['fname']) for r in c.fetchall()]
return pkfields
@reflection.cache
def get_column_sequence(self, connection,
table_name, column_name,
schema=None, **kw):
tablename = self.denormalize_name(table_name)
colname = self.denormalize_name(column_name)
# Heuristic-query to determine the generator associated to a PK field
genqry = """
SELECT trigdep.rdb$depended_on_name AS fgenerator
FROM rdb$dependencies tabdep
JOIN rdb$dependencies trigdep
ON tabdep.rdb$dependent_name=trigdep.rdb$dependent_name
AND trigdep.rdb$depended_on_type=14
AND trigdep.rdb$dependent_type=2
JOIN rdb$triggers trig ON
trig.rdb$trigger_name=tabdep.rdb$dependent_name
WHERE tabdep.rdb$depended_on_name=?
AND tabdep.rdb$depended_on_type=0
AND trig.rdb$trigger_type=1
AND tabdep.rdb$field_name=?
AND (SELECT count(*)
FROM rdb$dependencies trigdep2
WHERE trigdep2.rdb$dependent_name = trigdep.rdb$dependent_name) = 2
"""
genr = connection.execute(genqry, [tablename, colname]).first()
if genr is not None:
return dict(name=self.normalize_name(genr['fgenerator']))
@reflection.cache
def get_columns(self, connection, table_name, schema=None, **kw):
# Query to extract the details of all the fields of the given table
tblqry = """
SELECT DISTINCT r.rdb$field_name AS fname,
r.rdb$null_flag AS null_flag,
t.rdb$type_name AS ftype,
f.rdb$field_sub_type AS stype,
f.rdb$field_length/
COALESCE(cs.rdb$bytes_per_character,1) AS flen,
f.rdb$field_precision AS fprec,
f.rdb$field_scale AS fscale,
COALESCE(r.rdb$default_source,
f.rdb$default_source) AS fdefault
FROM rdb$relation_fields r
JOIN rdb$fields f ON r.rdb$field_source=f.rdb$field_name
JOIN rdb$types t
ON t.rdb$type=f.rdb$field_type AND
t.rdb$field_name='RDB$FIELD_TYPE'
LEFT JOIN rdb$character_sets cs ON
f.rdb$character_set_id=cs.rdb$character_set_id
WHERE f.rdb$system_flag=0 AND r.rdb$relation_name=?
ORDER BY r.rdb$field_position
"""
# get the PK, used to determine the eventual associated sequence
pkey_cols = self.get_primary_keys(connection, table_name)
tablename = self.denormalize_name(table_name)
# get all of the fields for this table
c = connection.execute(tblqry, [tablename])
cols = []
while True:
row = c.fetchone()
if row is None:
break
name = self.normalize_name(row['fname'])
orig_colname = row['fname']
# get the data type
colspec = row['ftype'].rstrip()
coltype = self.ischema_names.get(colspec)
if coltype is None:
util.warn("Did not recognize type '%s' of column '%s'" %
(colspec, name))
coltype = sqltypes.NULLTYPE
elif colspec == 'INT64':
coltype = coltype(
precision=row['fprec'],
scale=row['fscale'] * -1)
elif colspec in ('VARYING', 'CSTRING'):
coltype = coltype(row['flen'])
elif colspec == 'TEXT':
coltype = TEXT(row['flen'])
elif colspec == 'BLOB':
if row['stype'] == 1:
coltype = TEXT()
else:
coltype = BLOB()
else:
coltype = coltype(row)
# does it have a default value?
defvalue = None
if row['fdefault'] is not None:
# the value comes down as "DEFAULT 'value'": there may be
# more than one whitespace around the "DEFAULT" keyword
# and it may also be lower case
# (see also http://tracker.firebirdsql.org/browse/CORE-356)
defexpr = row['fdefault'].lstrip()
assert defexpr[:8].rstrip().upper() == \
'DEFAULT', "Unrecognized default value: %s" % \
defexpr
defvalue = defexpr[8:].strip()
if defvalue == 'NULL':
# Redundant
defvalue = None
col_d = {
'name' : name,
'type' : coltype,
'nullable' : not bool(row['null_flag']),
'default' : defvalue
}
if orig_colname.lower() == orig_colname:
col_d['quote'] = True
# if the PK is a single field, try to see if its linked to
# a sequence thru a trigger
if len(pkey_cols)==1 and name==pkey_cols[0]:
seq_d = self.get_column_sequence(connection, tablename, name)
if seq_d is not None:
col_d['sequence'] = seq_d
cols.append(col_d)
return cols
@reflection.cache
def get_foreign_keys(self, connection, table_name, schema=None, **kw):
# Query to extract the details of each UK/FK of the given table
fkqry = """
SELECT rc.rdb$constraint_name AS cname,
cse.rdb$field_name AS fname,
ix2.rdb$relation_name AS targetrname,
se.rdb$field_name AS targetfname
FROM rdb$relation_constraints rc
JOIN rdb$indices ix1 ON ix1.rdb$index_name=rc.rdb$index_name
JOIN rdb$indices ix2 ON ix2.rdb$index_name=ix1.rdb$foreign_key
JOIN rdb$index_segments cse ON
cse.rdb$index_name=ix1.rdb$index_name
JOIN rdb$index_segments se
ON se.rdb$index_name=ix2.rdb$index_name
AND se.rdb$field_position=cse.rdb$field_position
WHERE rc.rdb$constraint_type=? AND rc.rdb$relation_name=?
ORDER BY se.rdb$index_name, se.rdb$field_position
"""
tablename = self.denormalize_name(table_name)
c = connection.execute(fkqry, ["FOREIGN KEY", tablename])
fks = util.defaultdict(lambda:{
'name' : None,
'constrained_columns' : [],
'referred_schema' : None,
'referred_table' : None,
'referred_columns' : []
})
for row in c:
cname = self.normalize_name(row['cname'])
fk = fks[cname]
if not fk['name']:
fk['name'] = cname
fk['referred_table'] = self.normalize_name(row['targetrname'])
fk['constrained_columns'].append(
self.normalize_name(row['fname']))
fk['referred_columns'].append(
self.normalize_name(row['targetfname']))
return fks.values()
@reflection.cache
def get_indexes(self, connection, table_name, schema=None, **kw):
qry = """
SELECT ix.rdb$index_name AS index_name,
ix.rdb$unique_flag AS unique_flag,
ic.rdb$field_name AS field_name
FROM rdb$indices ix
JOIN rdb$index_segments ic
ON ix.rdb$index_name=ic.rdb$index_name
LEFT OUTER JOIN rdb$relation_constraints
ON rdb$relation_constraints.rdb$index_name =
ic.rdb$index_name
WHERE ix.rdb$relation_name=? AND ix.rdb$foreign_key IS NULL
AND rdb$relation_constraints.rdb$constraint_type IS NULL
ORDER BY index_name, field_name
"""
c = connection.execute(qry, [self.denormalize_name(table_name)])
indexes = util.defaultdict(dict)
for row in c:
indexrec = indexes[row['index_name']]
if 'name' not in indexrec:
indexrec['name'] = self.normalize_name(row['index_name'])
indexrec['column_names'] = []
indexrec['unique'] = bool(row['unique_flag'])
indexrec['column_names'].append(
self.normalize_name(row['field_name']))
return indexes.values()
def do_execute(self, cursor, statement, parameters, context=None):
# kinterbase does not accept a None, but wants an empty list
# when there are no arguments.
cursor.execute(statement, parameters or [])
def do_rollback(self, connection):
# Use the retaining feature, that keeps the transaction going
connection.rollback(True)
def do_commit(self, connection):
# Use the retaining feature, that keeps the transaction going
connection.commit(True)
|
mpl-2.0
|
[
3,
8344,
22488,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
16922,
29434,
281,
333,
7455,
63,
311,
32,
29414,
863,
4655,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
199,
11532,
367,
314,
15967,
22488,
3050,
14,
199,
199,
714,
13498,
365,
9987,
6841,
4799,
314,
1022,
1058,
31917,
697,
63,
27980,
859,
14,
199,
199,
22080,
83,
199,
4919,
199,
199,
13081,
22488,
32563,
2877,
15392,
10982,
83,
63,
334,
1397,
370,
506,
3743,
2972,
543,
282,
199,
4657,
12800,
1124,
22080,
1040,
304,
199,
199,
11072,
413,
523,
961,
365,
314,
2269,
6302,
436,
13942,
12,
12623,
687,
6551,
1095,
876,
13,
22,
14,
16,
14,
199,
199,
11072,
650,
523,
961,
365,
314,
15666,
436,
3748,
6302,
12,
21399,
315,
6551,
1095,
1227,
14,
16,
14,
199,
199,
1918,
14303,
15967,
22488,
10982,
477,
28853,
3520,
5459,
436,
199,
10917,
83,
2399,
6025,
402,
5385,
24137,
14,
221,
9738,
12,
199,
4058,
367,
10982,
413,
365,
440,
5521,
12470,
436,
8646,
965,
199,
262,
863,
2159,
66,
5462,
14,
199,
199,
6432,
316,
6423,
13115,
199,
9753,
199,
199,
13081,
22488,
23340,
6716,
1839,
7266,
9840,
14,
221,
2104,
642,
4499,
12,
282,
26704,
9934,
1443,
199,
27304,
5133,
1163,
15809,
787,
14286,
14,
221,
14303,
1630,
2399,
5526,
199,
475,
4683,
15809,
465,
23661,
465,
3962,
14,
221,
710,
4750,
2863,
7675,
199,
1618,
394,
8544,
15809,
365,
282,
2222,
13,
5836,
16949,
754,
663,
12,
284,
14,
69,
28383,
339,
754,
275,
6869,
14,
2526,
480,
2416,
627,
687,
1817,
531,
272,
1962,
275,
754,
14,
11591,
342,
272,
372,
199,
199,
26493,
3432,
12,
314,
1124,
2889,
4936,
1040,
965,
440,
2757,
9999,
16949,
14,
221,
710,
199,
2105,
911,
506,
2138,
370,
314,
4203,
436,
314,
6008,
279,
1174,
199,
10504,
1771,
5403,
314,
2018,
17516,
14910,
295,
3995,
11171,
314,
2251,
199,
6777,
10266,
14602,
314,
1950,
12,
1314,
14115,
11058,
29914,
14,
199,
1918,
3432,
675,
1930,
883,
506,
27458,
433,
972,
701,
6358,
1124,
2246,
8497,
641,
314,
199,
1040,
2889,
4936,
1040,
1314,
911,
5267,
314,
1642,
1962,
436,
9939,
4002,
199,
452,
7971,
3920,
15,
2105,
5944,
14,
199,
199,
7341,
1230,
6024,
2291,
199,
9753,
94,
199,
199,
13081,
22488,
499,
14,
16,
5171,
8152,
282,
754,
663,
687,
28203,
12,
436,
499,
14,
17,
199,
11036,
626,
370,
21812,
436,
7029,
14,
961,
365,
1519,
7288,
19282,
701,
199,
1589,
14303,
1124,
24112,
8497,
1083,
12,
4066,
465,
447,
339,
327,
22542,
703,
7341,
1230,
6024,
272,
754,
275,
1817,
14,
3176,
1252,
24112,
8,
1224,
14,
67,
14,
761,
17,
12,
1817,
14,
67,
14,
761,
18,
680,
1103,
673,
1338,
8,
354,
534,
1421,
358,
272,
870,
754,
14,
10174,
342,
339,
327,
17148,
703,
7341,
1230,
6024,
272,
6534,
275,
325,
2421,
14,
873,
1252,
24112,
8,
2109,
76,
14,
67,
14,
344,
12,
325,
2421,
14,
67,
14,
22025,
680,
1103,
2116,
2382,
8,
2109,
76,
14,
67,
14,
16175,
30,
1960,
680,
1103,
2116,
1338,
8,
807,
8,
22025,
29,
2109,
76,
14,
67,
14,
22025,
627,
413,
14,
17,
430,
272,
870,
6534,
14,
10174,
342,
421,
199,
703,
485,
11072,
83,
26,
1455,
921,
5466,
13,
863,
4655,
14,
957,
15,
7243,
83,
15,
13081,
22488,
15,
4657,
63,
22080,
14,
1360,
199,
199,
624,
199,
199,
646,
2197,
12,
295,
199,
199,
504,
8335,
492,
4177,
465,
2937,
63,
3629,
199,
504,
8335,
492,
3178,
12,
2943,
465,
23111,
12,
3875,
12,
4884,
199,
504,
8335,
14,
3009,
492,
3965,
199,
504,
8335,
14,
3908,
492,
1300,
12,
849,
12,
25572,
199,
504,
8335,
14,
3009,
492,
6365,
421,
199,
504,
8335,
14,
1313,
492,
334,
18643,
2919,
12,
699,
9376,
12,
4367,
20540,
12,
30131,
12,
2892,
31241,
12,
17086,
12,
31806,
12,
2516,
2919,
12,
2892,
11951,
12,
17032,
12,
32745,
9,
421,
199,
26933,
63,
19984,
275,
663,
779,
272,
298,
2682,
401,
298,
525,
401,
298,
2113,
401,
298,
4399,
401,
298,
452,
401,
298,
11858,
401,
298,
460,
401,
298,
1629,
401,
298,
305,
401,
272,
298,
10125,
401,
298,
10125,
3219,
401,
298,
292,
401,
298,
2495,
401,
298,
8595,
401,
298,
5182,
401,
298,
5037,
401,
298,
13007,
401,
272,
298,
24884,
401,
298,
2075,
63,
1267,
401,
298,
6582,
401,
298,
10727,
401,
298,
991,
401,
298,
2546,
401,
298,
2931,
401,
298,
1560,
401,
272,
298,
10856,
401,
298,
10856,
63,
1267,
401,
298,
1560,
63,
1267,
401,
298,
1074,
401,
298,
1600,
401,
272,
298,
761,
750,
401,
298,
2301,
401,
298,
3543,
401,
298,
20300,
401,
298,
14378,
401,
298,
14353,
401,
272,
298,
2242,
401,
298,
5631,
401,
298,
16133,
401,
298,
835,
401,
298,
981,
401,
298,
7925,
401,
272,
298,
67,
875,
401,
298,
1818,
401,
298,
1818,
63,
2105,
401,
298,
1818,
63,
602,
401,
272,
298,
1818,
63,
3756,
401,
298,
1818,
63,
521,
401,
298,
1818,
63,
3954,
401,
272,
298,
1818,
63,
5945,
401,
298,
1818,
63,
751,
401,
298,
3937,
401,
298,
4659,
401,
298,
602,
401,
272,
298,
2977,
401,
298,
7778,
401,
298,
6355,
401,
298,
16536,
401,
298,
885,
401,
298,
1807,
401,
298,
3257,
401,
272,
298,
3257,
3219,
401,
298,
10673,
401,
298,
12926,
401,
298,
1117,
401,
298,
2261,
401,
298,
3157,
401,
272,
298,
4824,
401,
298,
2836,
401,
298,
500,
401,
298,
2373,
63,
1403,
401,
298,
3765,
401,
298,
1971,
401,
272,
298,
2526,
401,
298,
2444,
401,
298,
2224,
401,
298,
5159,
401,
298,
5005,
401,
298,
3535,
401,
298,
493,
401,
272,
298,
1541,
401,
298,
1609,
401,
298,
509,
401,
298,
6846,
401,
298,
504,
401,
298,
2861,
401,
298,
1593,
401,
272,
298,
27987,
600,
401,
298,
4679,
401,
298,
2268,
63,
344,
401,
298,
2966,
401,
298,
17362,
401,
298,
923,
401,
272,
298,
31569
] |
[
8344,
22488,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
16922,
29434,
281,
333,
7455,
63,
311,
32,
29414,
863,
4655,
14,
957,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
199,
11532,
367,
314,
15967,
22488,
3050,
14,
199,
199,
714,
13498,
365,
9987,
6841,
4799,
314,
1022,
1058,
31917,
697,
63,
27980,
859,
14,
199,
199,
22080,
83,
199,
4919,
199,
199,
13081,
22488,
32563,
2877,
15392,
10982,
83,
63,
334,
1397,
370,
506,
3743,
2972,
543,
282,
199,
4657,
12800,
1124,
22080,
1040,
304,
199,
199,
11072,
413,
523,
961,
365,
314,
2269,
6302,
436,
13942,
12,
12623,
687,
6551,
1095,
876,
13,
22,
14,
16,
14,
199,
199,
11072,
650,
523,
961,
365,
314,
15666,
436,
3748,
6302,
12,
21399,
315,
6551,
1095,
1227,
14,
16,
14,
199,
199,
1918,
14303,
15967,
22488,
10982,
477,
28853,
3520,
5459,
436,
199,
10917,
83,
2399,
6025,
402,
5385,
24137,
14,
221,
9738,
12,
199,
4058,
367,
10982,
413,
365,
440,
5521,
12470,
436,
8646,
965,
199,
262,
863,
2159,
66,
5462,
14,
199,
199,
6432,
316,
6423,
13115,
199,
9753,
199,
199,
13081,
22488,
23340,
6716,
1839,
7266,
9840,
14,
221,
2104,
642,
4499,
12,
282,
26704,
9934,
1443,
199,
27304,
5133,
1163,
15809,
787,
14286,
14,
221,
14303,
1630,
2399,
5526,
199,
475,
4683,
15809,
465,
23661,
465,
3962,
14,
221,
710,
4750,
2863,
7675,
199,
1618,
394,
8544,
15809,
365,
282,
2222,
13,
5836,
16949,
754,
663,
12,
284,
14,
69,
28383,
339,
754,
275,
6869,
14,
2526,
480,
2416,
627,
687,
1817,
531,
272,
1962,
275,
754,
14,
11591,
342,
272,
372,
199,
199,
26493,
3432,
12,
314,
1124,
2889,
4936,
1040,
965,
440,
2757,
9999,
16949,
14,
221,
710,
199,
2105,
911,
506,
2138,
370,
314,
4203,
436,
314,
6008,
279,
1174,
199,
10504,
1771,
5403,
314,
2018,
17516,
14910,
295,
3995,
11171,
314,
2251,
199,
6777,
10266,
14602,
314,
1950,
12,
1314,
14115,
11058,
29914,
14,
199,
1918,
3432,
675,
1930,
883,
506,
27458,
433,
972,
701,
6358,
1124,
2246,
8497,
641,
314,
199,
1040,
2889,
4936,
1040,
1314,
911,
5267,
314,
1642,
1962,
436,
9939,
4002,
199,
452,
7971,
3920,
15,
2105,
5944,
14,
199,
199,
7341,
1230,
6024,
2291,
199,
9753,
94,
199,
199,
13081,
22488,
499,
14,
16,
5171,
8152,
282,
754,
663,
687,
28203,
12,
436,
499,
14,
17,
199,
11036,
626,
370,
21812,
436,
7029,
14,
961,
365,
1519,
7288,
19282,
701,
199,
1589,
14303,
1124,
24112,
8497,
1083,
12,
4066,
465,
447,
339,
327,
22542,
703,
7341,
1230,
6024,
272,
754,
275,
1817,
14,
3176,
1252,
24112,
8,
1224,
14,
67,
14,
761,
17,
12,
1817,
14,
67,
14,
761,
18,
680,
1103,
673,
1338,
8,
354,
534,
1421,
358,
272,
870,
754,
14,
10174,
342,
339,
327,
17148,
703,
7341,
1230,
6024,
272,
6534,
275,
325,
2421,
14,
873,
1252,
24112,
8,
2109,
76,
14,
67,
14,
344,
12,
325,
2421,
14,
67,
14,
22025,
680,
1103,
2116,
2382,
8,
2109,
76,
14,
67,
14,
16175,
30,
1960,
680,
1103,
2116,
1338,
8,
807,
8,
22025,
29,
2109,
76,
14,
67,
14,
22025,
627,
413,
14,
17,
430,
272,
870,
6534,
14,
10174,
342,
421,
199,
703,
485,
11072,
83,
26,
1455,
921,
5466,
13,
863,
4655,
14,
957,
15,
7243,
83,
15,
13081,
22488,
15,
4657,
63,
22080,
14,
1360,
199,
199,
624,
199,
199,
646,
2197,
12,
295,
199,
199,
504,
8335,
492,
4177,
465,
2937,
63,
3629,
199,
504,
8335,
492,
3178,
12,
2943,
465,
23111,
12,
3875,
12,
4884,
199,
504,
8335,
14,
3009,
492,
3965,
199,
504,
8335,
14,
3908,
492,
1300,
12,
849,
12,
25572,
199,
504,
8335,
14,
3009,
492,
6365,
421,
199,
504,
8335,
14,
1313,
492,
334,
18643,
2919,
12,
699,
9376,
12,
4367,
20540,
12,
30131,
12,
2892,
31241,
12,
17086,
12,
31806,
12,
2516,
2919,
12,
2892,
11951,
12,
17032,
12,
32745,
9,
421,
199,
26933,
63,
19984,
275,
663,
779,
272,
298,
2682,
401,
298,
525,
401,
298,
2113,
401,
298,
4399,
401,
298,
452,
401,
298,
11858,
401,
298,
460,
401,
298,
1629,
401,
298,
305,
401,
272,
298,
10125,
401,
298,
10125,
3219,
401,
298,
292,
401,
298,
2495,
401,
298,
8595,
401,
298,
5182,
401,
298,
5037,
401,
298,
13007,
401,
272,
298,
24884,
401,
298,
2075,
63,
1267,
401,
298,
6582,
401,
298,
10727,
401,
298,
991,
401,
298,
2546,
401,
298,
2931,
401,
298,
1560,
401,
272,
298,
10856,
401,
298,
10856,
63,
1267,
401,
298,
1560,
63,
1267,
401,
298,
1074,
401,
298,
1600,
401,
272,
298,
761,
750,
401,
298,
2301,
401,
298,
3543,
401,
298,
20300,
401,
298,
14378,
401,
298,
14353,
401,
272,
298,
2242,
401,
298,
5631,
401,
298,
16133,
401,
298,
835,
401,
298,
981,
401,
298,
7925,
401,
272,
298,
67,
875,
401,
298,
1818,
401,
298,
1818,
63,
2105,
401,
298,
1818,
63,
602,
401,
272,
298,
1818,
63,
3756,
401,
298,
1818,
63,
521,
401,
298,
1818,
63,
3954,
401,
272,
298,
1818,
63,
5945,
401,
298,
1818,
63,
751,
401,
298,
3937,
401,
298,
4659,
401,
298,
602,
401,
272,
298,
2977,
401,
298,
7778,
401,
298,
6355,
401,
298,
16536,
401,
298,
885,
401,
298,
1807,
401,
298,
3257,
401,
272,
298,
3257,
3219,
401,
298,
10673,
401,
298,
12926,
401,
298,
1117,
401,
298,
2261,
401,
298,
3157,
401,
272,
298,
4824,
401,
298,
2836,
401,
298,
500,
401,
298,
2373,
63,
1403,
401,
298,
3765,
401,
298,
1971,
401,
272,
298,
2526,
401,
298,
2444,
401,
298,
2224,
401,
298,
5159,
401,
298,
5005,
401,
298,
3535,
401,
298,
493,
401,
272,
298,
1541,
401,
298,
1609,
401,
298,
509,
401,
298,
6846,
401,
298,
504,
401,
298,
2861,
401,
298,
1593,
401,
272,
298,
27987,
600,
401,
298,
4679,
401,
298,
2268,
63,
344,
401,
298,
2966,
401,
298,
17362,
401,
298,
923,
401,
272,
298,
31569,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
DarioGT/OMS-PluginXML
|
org.modelsphere.sms/lib/jython-2.2.1/Lib/test/string_tests.py
|
1
|
11250
|
"""Common tests shared by test_string and test_userstring"""
import string
from test_support import verify, verbose, TestFailed, have_unicode
transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
from UserList import UserList
class Sequence:
def __init__(self): self.seq = 'wxyz'
def __len__(self): return len(self.seq)
def __getitem__(self, i): return self.seq[i]
class BadSeq1(Sequence):
def __init__(self): self.seq = [7, 'hello', 123L]
class BadSeq2(Sequence):
def __init__(self): self.seq = ['a', 'b', 'c']
def __len__(self): return 8
def run_module_tests(test):
"""Run all tests that exercise a function in the string module"""
test('atoi', " 1 ", 1)
test('atoi', " 1x", ValueError)
test('atoi', " x1 ", ValueError)
test('atol', " 1 ", 1L)
test('atol', " 1x ", ValueError)
test('atol', " x1 ", ValueError)
test('atof', " 1 ", 1.0)
test('atof', " 1x ", ValueError)
test('atof', " x1 ", ValueError)
test('maketrans', 'abc', transtable, 'xyz')
test('maketrans', 'abc', ValueError, 'xyzq')
# join now works with any sequence type
test('join', ['a', 'b', 'c', 'd'], 'a b c d')
test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
test('join', Sequence(), 'w x y z')
test('join', 7, TypeError)
test('join', BadSeq1(), TypeError)
test('join', BadSeq2(), 'a b c')
# try a few long ones
print ":".join(['x' * 100] * 100)
print ":".join(('x' * 100,) * 100)
def run_method_tests(test):
"""Run all tests that exercise a method of a string object"""
test('capitalize', ' hello ', ' hello ')
test('capitalize', 'hello ', 'Hello ')
test('capitalize', 'aaaa', 'Aaaa')
test('capitalize', 'AaAa', 'Aaaa')
test('count', 'aaa', 3, 'a')
test('count', 'aaa', 0, 'b')
test('find', 'abcdefghiabc', 0, 'abc')
test('find', 'abcdefghiabc', 9, 'abc', 1)
test('find', 'abcdefghiabc', -1, 'def', 4)
test('rfind', 'abcdefghiabc', 9, 'abc')
test('lower', 'HeLLo', 'hello')
test('lower', 'hello', 'hello')
test('upper', 'HeLLo', 'HELLO')
test('upper', 'HELLO', 'HELLO')
test('title', ' hello ', ' Hello ')
test('title', 'hello ', 'Hello ')
test('title', "fOrMaT thIs aS titLe String", 'Format This As Title String')
test('title', "fOrMaT,thIs-aS*titLe;String", 'Format,This-As*Title;String')
test('title', "getInt", 'Getint')
test('expandtabs', 'abc\rab\tdef\ng\thi', 'abc\rab def\ng hi')
test('expandtabs', 'abc\rab\tdef\ng\thi', 'abc\rab def\ng hi', 8)
test('expandtabs', 'abc\rab\tdef\ng\thi', 'abc\rab def\ng hi', 4)
test('expandtabs', 'abc\r\nab\tdef\ng\thi', 'abc\r\nab def\ng hi', 4)
test('islower', 'a', 1)
test('islower', 'A', 0)
test('islower', '\n', 0)
test('islower', 'abc', 1)
test('islower', 'aBc', 0)
test('islower', 'abc\n', 1)
test('isupper', 'a', 0)
test('isupper', 'A', 1)
test('isupper', '\n', 0)
test('isupper', 'ABC', 1)
test('isupper', 'AbC', 0)
test('isupper', 'ABC\n', 1)
test('istitle', 'a', 0)
test('istitle', 'A', 1)
test('istitle', '\n', 0)
test('istitle', 'A Titlecased Line', 1)
test('istitle', 'A\nTitlecased Line', 1)
test('istitle', 'A Titlecased, Line', 1)
test('istitle', 'Not a capitalized String', 0)
test('istitle', 'Not\ta Titlecase String', 0)
test('istitle', 'Not--a Titlecase String', 0)
test('isalpha', 'a', 1)
test('isalpha', 'A', 1)
test('isalpha', '\n', 0)
test('isalpha', 'abc', 1)
test('isalpha', 'aBc123', 0)
test('isalpha', 'abc\n', 0)
test('isalnum', 'a', 1)
test('isalnum', 'A', 1)
test('isalnum', '\n', 0)
test('isalnum', '123abc456', 1)
test('isalnum', 'a1b3c', 1)
test('isalnum', 'aBc000 ', 0)
test('isalnum', 'abc\n', 0)
# join now works with any sequence type
test('join', ' ', 'a b c d', ['a', 'b', 'c', 'd'])
test('join', '', 'abcd', ('a', 'b', 'c', 'd'))
test('join', ' ', 'w x y z', Sequence())
test('join', 'a', 'abc', ('abc',))
test('join', 'a', 'z', UserList(['z']))
if have_unicode:
test('join', unicode('.'), unicode('a.b.c'), ['a', 'b', 'c'])
test('join', '.', unicode('a.b.c'), [unicode('a'), 'b', 'c'])
test('join', '.', unicode('a.b.c'), ['a', unicode('b'), 'c'])
test('join', '.', unicode('a.b.c'), ['a', 'b', unicode('c')])
test('join', '.', TypeError, ['a', unicode('b'), 3])
for i in [5, 25, 125]:
test('join', '-', ((('a' * i) + '-') * i)[:-1],
['a' * i] * i)
test('join', ' ', TypeError, BadSeq1())
test('join', ' ', 'a b c', BadSeq2())
test('splitlines', "abc\ndef\n\rghi", ['abc', 'def', '', 'ghi'])
test('splitlines', "abc\ndef\n\r\nghi", ['abc', 'def', '', 'ghi'])
test('splitlines', "abc\ndef\r\nghi", ['abc', 'def', 'ghi'])
test('splitlines', "abc\ndef\r\nghi\n", ['abc', 'def', 'ghi'])
test('splitlines', "abc\ndef\r\nghi\n\r", ['abc', 'def', 'ghi', ''])
test('splitlines', "\nabc\ndef\r\nghi\n\r", ['', 'abc', 'def', 'ghi', ''])
test('splitlines', "\nabc\ndef\r\nghi\n\r", ['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], 1)
test('split', 'this is the split function',
['this', 'is', 'the', 'split', 'function'])
test('split', 'a|b|c|d', ['a', 'b', 'c', 'd'], '|')
test('split', 'a|b|c|d', ['a', 'b', 'c|d'], '|', 2)
test('split', 'a b c d', ['a', 'b c d'], None, 1)
test('split', 'a b c d', ['a', 'b', 'c d'], None, 2)
test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 3)
test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 4)
test('split', 'a b c d', ['a b c d'], None, 0)
test('split', 'a b c d', ['a', 'b', 'c d'], None, 2)
test('split', 'a b c d ', ['a', 'b', 'c', 'd'])
test('strip', ' hello ', 'hello')
test('lstrip', ' hello ', 'hello ')
test('rstrip', ' hello ', ' hello')
test('strip', 'hello', 'hello')
# strip/lstrip/rstrip with None arg
test('strip', ' hello ', 'hello', None)
test('lstrip', ' hello ', 'hello ', None)
test('rstrip', ' hello ', ' hello', None)
test('strip', 'hello', 'hello', None)
# strip/lstrip/rstrip with str arg
test('strip', 'xyzzyhelloxyzzy', 'hello', 'xyz')
test('lstrip', 'xyzzyhelloxyzzy', 'helloxyzzy', 'xyz')
test('rstrip', 'xyzzyhelloxyzzy', 'xyzzyhello', 'xyz')
test('strip', 'hello', 'hello', 'xyz')
# strip/lstrip/rstrip with unicode arg
test('strip', 'xyzzyhelloxyzzy', u'hello', u'xyz')
test('lstrip', 'xyzzyhelloxyzzy', u'helloxyzzy', u'xyz')
test('rstrip', 'xyzzyhelloxyzzy', u'xyzzyhello', u'xyz')
test('strip', 'hello', u'hello', u'xyz')
test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')
table = string.maketrans('a', 'A')
test('translate', 'abc', 'Abc', table)
test('translate', 'xyz', 'xyz', table)
test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
test('replace', 'one!two!three!', 'onetwothree', '!', '')
test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
test('replace', 'one!two!three!', 'one!two!three!', '!', '@', 0)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@')
test('replace', 'one!two!three!', 'one!two!three!', 'x', '@')
test('replace', 'one!two!three!', 'one!two!three!', 'x', '@', 2)
# Next three for SF bug 422088: [OSF1 alpha] string.replace(); died with
# MemoryError due to empty result (platform malloc issue when requesting
# 0 bytes).
test('replace', '123', '', '123', '')
test('replace', '123123', '', '123', '')
test('replace', '123x123', 'x', '123', '')
test('startswith', 'hello', 1, 'he')
test('startswith', 'hello', 1, 'hello')
test('startswith', 'hello', 0, 'hello world')
test('startswith', 'hello', 1, '')
test('startswith', 'hello', 0, 'ello')
test('startswith', 'hello', 1, 'ello', 1)
test('startswith', 'hello', 1, 'o', 4)
test('startswith', 'hello', 0, 'o', 5)
test('startswith', 'hello', 1, '', 5)
test('startswith', 'hello', 0, 'lo', 6)
test('startswith', 'helloworld', 1, 'lowo', 3)
test('startswith', 'helloworld', 1, 'lowo', 3, 7)
test('startswith', 'helloworld', 0, 'lowo', 3, 6)
test('endswith', 'hello', 1, 'lo')
test('endswith', 'hello', 0, 'he')
test('endswith', 'hello', 1, '')
test('endswith', 'hello', 0, 'hello world')
test('endswith', 'helloworld', 0, 'worl')
test('endswith', 'helloworld', 1, 'worl', 3, 9)
test('endswith', 'helloworld', 1, 'world', 3, 12)
test('endswith', 'helloworld', 1, 'lowo', 1, 7)
test('endswith', 'helloworld', 1, 'lowo', 2, 7)
test('endswith', 'helloworld', 1, 'lowo', 3, 7)
test('endswith', 'helloworld', 0, 'lowo', 4, 7)
test('endswith', 'helloworld', 0, 'lowo', 3, 8)
test('endswith', 'ab', 0, 'ab', 0, 1)
test('endswith', 'ab', 0, 'ab', 0, 0)
test('zfill', '123', '123', 2)
test('zfill', '123', '123', 3)
test('zfill', '123', '0123', 4)
test('zfill', '+123', '+123', 3)
test('zfill', '+123', '+123', 4)
test('zfill', '+123', '+0123', 5)
test('zfill', '-123', '-123', 3)
test('zfill', '-123', '-123', 4)
test('zfill', '-123', '-0123', 5)
test('zfill', '', '000', 3)
test('zfill', '34', '34', 1)
test('zfill', '34', '0034', 4)
# Encoding/decoding
codecs = [('rot13', 'uryyb jbeyq'),
('base64', 'aGVsbG8gd29ybGQ=\n'),
('hex', '68656c6c6f20776f726c64'),
('uu', 'begin 666 <data>\n+:&5L;&\\@=V]R;&0 \n \nend\n')]
for encoding, data in codecs:
test('encode', 'hello world', data, encoding)
test('decode', data, 'hello world', encoding)
# zlib is optional, so we make the test optional too...
try:
import zlib
except ImportError:
pass
else:
data = 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]'
verify('hello world'.encode('zlib') == data)
verify(data.decode('zlib') == 'hello world')
|
gpl-3.0
|
[
624,
7844,
2295,
5709,
701,
511,
63,
875,
436,
511,
63,
751,
875,
624,
2999,
199,
646,
1059,
202,
199,
504,
511,
63,
4058,
492,
4911,
12,
3376,
12,
1379,
4276,
12,
1172,
63,
2975,
2999,
199,
3936,
11989,
275,
1557,
1493,
60,
4587,
60,
7432,
60,
8262,
60,
7979,
60,
7972,
60,
8010,
60,
8255,
60,
9523,
60,
13059,
60,
11533,
60,
13264,
60,
10752,
60,
11164,
60,
10882,
60,
9570,
60,
10173,
60,
15385,
60,
16348,
60,
16771,
60,
5284,
60,
18823,
60,
14842,
60,
14218,
60,
22739,
60,
19225,
60,
21683,
60,
8762,
60,
21756,
60,
21088,
60,
25368,
60,
18325,
8546,
2,
3,
22074,
6,
3985,
25608,
11,
3057,
13186,
11371,
26,
27,
12932,
30,
31,
32,
28114,
59,
1103,
61,
62,
28116,
8568,
318,
3561,
7879,
20701,
21832,
91,
92,
93,
94,
60,
8881,
60,
1840,
60,
1797,
60,
4999,
60,
11341,
60,
6686,
60,
10629,
60,
11089,
60,
10744,
60,
12725,
60,
12832,
60,
11722,
60,
14271,
60,
6886,
60,
7842,
60,
9669,
60,
9335,
60,
11174,
60,
11564,
60,
9485,
60,
11583,
60,
8731,
60,
10932,
60,
11085,
60,
11385,
60,
9687,
60,
11921,
60,
8001,
60,
10034,
60,
5533,
60,
8276,
60,
10008,
60,
10638,
60,
9873,
60,
13571,
60,
13212,
60,
13440,
60,
11603,
60,
11677,
60,
11440,
60,
11717,
60,
7991,
60,
12140,
60,
6390,
60,
3781,
60,
8306,
60,
2299,
60,
3912,
60,
11551,
60,
13085,
60,
15128,
60,
14820,
60,
14622,
60,
9408,
60,
13730,
60,
9969,
60,
13406,
60,
13299,
60,
16344,
60,
12900,
60,
15000,
60,
9014,
60,
13643,
60,
13319,
60,
9963,
60,
5863,
60,
8507,
60,
8551,
60,
11810,
60,
8533,
60,
11565,
60,
11363,
60,
11516,
60,
18035,
60,
17539,
60,
16683,
60,
19455,
60,
8988,
60,
9927,
60,
21376,
60,
21974,
60,
12122,
60,
12638,
60,
15858,
60,
13905,
60,
12744,
60,
13288,
60,
8342,
60,
11754,
60,
14137,
60,
15638,
60,
9526,
60,
11769,
60,
8425,
60,
13793,
60,
12135,
60,
11062,
60,
13424,
60,
15590,
60,
14519,
60,
14761,
60,
10875,
60,
9908,
60,
12583,
60,
12532,
60,
13595,
60,
16860,
60,
15139,
60,
15355,
60,
12967,
60,
10156,
60,
13251,
60,
13155,
60,
11197,
60,
15702,
60,
16369,
60,
15031,
60,
22775,
60,
12664,
60,
11065,
60,
12684,
60,
13812,
60,
16124,
60,
15541,
60,
14539,
60,
9880,
60,
9946,
60,
11452,
60,
7332,
7,
2999,
199,
504,
28639,
492,
28639,
2999,
199,
533,
10975,
26,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
283,
19400,
7,
1128,
347,
636,
552,
721,
277,
304,
372,
822,
8,
277,
14,
3610,
9,
1128,
347,
636,
6095,
721,
277,
12,
284,
304,
372,
291,
14,
3610,
59,
73,
61,
2999,
199,
533,
8857,
11205,
17,
8,
5826,
304,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
359,
23,
12,
283,
5006,
297,
11869,
44,
61,
2999,
199,
533,
8857,
11205,
18,
8,
5826,
304,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
788,
65,
297,
283,
66,
297,
283,
67,
418,
1128,
347,
636,
552,
721,
277,
304,
372,
1695,
2999,
199,
318,
1255,
63,
578,
63,
2219,
8,
396,
304,
1128,
408,
2540,
1006,
2295,
626,
26511,
282,
805,
315,
314,
1059,
859,
624,
2958,
511,
360,
11318,
73,
297,
298,
413,
3872,
413,
9,
1128,
511,
360,
11318,
73,
297,
298,
413,
88,
401,
1722,
9,
1128,
511,
360,
11318,
73,
297,
298,
671,
17,
3872,
1722,
9,
1128,
511,
360,
24504,
297,
298,
221,
413,
221,
3872,
413,
44,
9,
1128,
511,
360,
24504,
297,
298,
221,
413,
88,
3872,
1722,
9,
1128,
511,
360,
24504,
297,
298,
221,
671,
17,
3872,
1722,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
413,
221,
3872,
413,
14,
16,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
413,
88,
3872,
1722,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
671,
17,
3872,
1722,
9,
2958,
511,
360,
22191,
31552,
297,
283,
3175,
297,
7115,
11989,
12,
283,
8568,
358,
1128,
511,
360,
22191,
31552,
297,
283,
3175,
297,
1722,
12,
283,
8568,
81,
358,
2958,
327,
4263,
3063,
5419,
543,
1263,
3414,
730,
1128,
511,
360,
904,
297,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
995,
283,
65,
330,
286,
366,
358,
1128,
511,
360,
904,
297,
661,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
659,
283,
13591,
297,
4074,
1128,
511,
360,
904,
297,
10975,
1062,
283,
87,
671,
612,
1315,
358,
1128,
511,
360,
904,
297,
1520,
12,
3146,
9,
2958,
511,
360,
904,
297,
8857,
11205,
17,
1062,
3146,
9,
1128,
511,
360,
904,
297,
8857,
11205,
18,
1062,
283,
65,
330,
286,
358,
2958,
327,
862,
282,
9284,
1846,
7869,
1128,
870,
7244,
1674,
904,
2941,
88,
7,
627,
2948,
61,
627,
2948,
9,
1128,
870,
7244,
1674,
904,
4725,
88,
7,
627,
2948,
4258,
627,
2948,
9,
8065,
199,
318,
1255,
63,
765,
63,
2219,
8,
396,
304,
1128,
408,
2540,
1006,
2295,
626,
26511,
282,
1083,
402,
282,
1059,
909,
624,
2958,
511,
360,
18351,
297,
283,
16509,
1656,
283,
16509,
5320,
1128,
511,
360,
18351,
297,
283,
5006,
1656,
283,
6257,
5320,
1128,
511,
360,
18351,
297,
283,
6000,
297,
283,
33,
11629,
358,
1128,
511,
360,
18351,
297,
283,
33,
65,
33,
65,
297,
283,
33,
11629,
358,
2958,
511,
360,
835,
297,
283,
11629,
297,
650,
12,
283,
65,
358,
1128,
511,
360,
835,
297,
283,
11629,
297,
378,
12,
283,
66,
358,
2958,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
378,
12,
283,
3175,
358,
1128,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
1749,
12,
283,
3175,
297,
413,
9,
1128,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
446,
17,
12,
283,
318,
297,
841,
9,
1128,
511,
360,
14542,
297,
283,
16238,
73,
3175,
297,
1749,
12,
283,
3175,
358,
1128,
511,
360,
2325,
297,
283,
1966,
44,
2041,
297,
283,
5006,
358,
1128,
511,
360,
2325,
297,
283,
5006,
297,
283,
5006,
358,
1128,
511,
360,
4142,
297,
283,
1966,
44,
2041,
297,
283,
24771,
1484,
358
] |
[
7844,
2295,
5709,
701,
511,
63,
875,
436,
511,
63,
751,
875,
624,
2999,
199,
646,
1059,
202,
199,
504,
511,
63,
4058,
492,
4911,
12,
3376,
12,
1379,
4276,
12,
1172,
63,
2975,
2999,
199,
3936,
11989,
275,
1557,
1493,
60,
4587,
60,
7432,
60,
8262,
60,
7979,
60,
7972,
60,
8010,
60,
8255,
60,
9523,
60,
13059,
60,
11533,
60,
13264,
60,
10752,
60,
11164,
60,
10882,
60,
9570,
60,
10173,
60,
15385,
60,
16348,
60,
16771,
60,
5284,
60,
18823,
60,
14842,
60,
14218,
60,
22739,
60,
19225,
60,
21683,
60,
8762,
60,
21756,
60,
21088,
60,
25368,
60,
18325,
8546,
2,
3,
22074,
6,
3985,
25608,
11,
3057,
13186,
11371,
26,
27,
12932,
30,
31,
32,
28114,
59,
1103,
61,
62,
28116,
8568,
318,
3561,
7879,
20701,
21832,
91,
92,
93,
94,
60,
8881,
60,
1840,
60,
1797,
60,
4999,
60,
11341,
60,
6686,
60,
10629,
60,
11089,
60,
10744,
60,
12725,
60,
12832,
60,
11722,
60,
14271,
60,
6886,
60,
7842,
60,
9669,
60,
9335,
60,
11174,
60,
11564,
60,
9485,
60,
11583,
60,
8731,
60,
10932,
60,
11085,
60,
11385,
60,
9687,
60,
11921,
60,
8001,
60,
10034,
60,
5533,
60,
8276,
60,
10008,
60,
10638,
60,
9873,
60,
13571,
60,
13212,
60,
13440,
60,
11603,
60,
11677,
60,
11440,
60,
11717,
60,
7991,
60,
12140,
60,
6390,
60,
3781,
60,
8306,
60,
2299,
60,
3912,
60,
11551,
60,
13085,
60,
15128,
60,
14820,
60,
14622,
60,
9408,
60,
13730,
60,
9969,
60,
13406,
60,
13299,
60,
16344,
60,
12900,
60,
15000,
60,
9014,
60,
13643,
60,
13319,
60,
9963,
60,
5863,
60,
8507,
60,
8551,
60,
11810,
60,
8533,
60,
11565,
60,
11363,
60,
11516,
60,
18035,
60,
17539,
60,
16683,
60,
19455,
60,
8988,
60,
9927,
60,
21376,
60,
21974,
60,
12122,
60,
12638,
60,
15858,
60,
13905,
60,
12744,
60,
13288,
60,
8342,
60,
11754,
60,
14137,
60,
15638,
60,
9526,
60,
11769,
60,
8425,
60,
13793,
60,
12135,
60,
11062,
60,
13424,
60,
15590,
60,
14519,
60,
14761,
60,
10875,
60,
9908,
60,
12583,
60,
12532,
60,
13595,
60,
16860,
60,
15139,
60,
15355,
60,
12967,
60,
10156,
60,
13251,
60,
13155,
60,
11197,
60,
15702,
60,
16369,
60,
15031,
60,
22775,
60,
12664,
60,
11065,
60,
12684,
60,
13812,
60,
16124,
60,
15541,
60,
14539,
60,
9880,
60,
9946,
60,
11452,
60,
7332,
7,
2999,
199,
504,
28639,
492,
28639,
2999,
199,
533,
10975,
26,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
283,
19400,
7,
1128,
347,
636,
552,
721,
277,
304,
372,
822,
8,
277,
14,
3610,
9,
1128,
347,
636,
6095,
721,
277,
12,
284,
304,
372,
291,
14,
3610,
59,
73,
61,
2999,
199,
533,
8857,
11205,
17,
8,
5826,
304,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
359,
23,
12,
283,
5006,
297,
11869,
44,
61,
2999,
199,
533,
8857,
11205,
18,
8,
5826,
304,
1128,
347,
636,
826,
721,
277,
304,
291,
14,
3610,
275,
788,
65,
297,
283,
66,
297,
283,
67,
418,
1128,
347,
636,
552,
721,
277,
304,
372,
1695,
2999,
199,
318,
1255,
63,
578,
63,
2219,
8,
396,
304,
1128,
408,
2540,
1006,
2295,
626,
26511,
282,
805,
315,
314,
1059,
859,
624,
2958,
511,
360,
11318,
73,
297,
298,
413,
3872,
413,
9,
1128,
511,
360,
11318,
73,
297,
298,
413,
88,
401,
1722,
9,
1128,
511,
360,
11318,
73,
297,
298,
671,
17,
3872,
1722,
9,
1128,
511,
360,
24504,
297,
298,
221,
413,
221,
3872,
413,
44,
9,
1128,
511,
360,
24504,
297,
298,
221,
413,
88,
3872,
1722,
9,
1128,
511,
360,
24504,
297,
298,
221,
671,
17,
3872,
1722,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
413,
221,
3872,
413,
14,
16,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
413,
88,
3872,
1722,
9,
1128,
511,
360,
292,
1618,
297,
298,
221,
671,
17,
3872,
1722,
9,
2958,
511,
360,
22191,
31552,
297,
283,
3175,
297,
7115,
11989,
12,
283,
8568,
358,
1128,
511,
360,
22191,
31552,
297,
283,
3175,
297,
1722,
12,
283,
8568,
81,
358,
2958,
327,
4263,
3063,
5419,
543,
1263,
3414,
730,
1128,
511,
360,
904,
297,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
995,
283,
65,
330,
286,
366,
358,
1128,
511,
360,
904,
297,
661,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
659,
283,
13591,
297,
4074,
1128,
511,
360,
904,
297,
10975,
1062,
283,
87,
671,
612,
1315,
358,
1128,
511,
360,
904,
297,
1520,
12,
3146,
9,
2958,
511,
360,
904,
297,
8857,
11205,
17,
1062,
3146,
9,
1128,
511,
360,
904,
297,
8857,
11205,
18,
1062,
283,
65,
330,
286,
358,
2958,
327,
862,
282,
9284,
1846,
7869,
1128,
870,
7244,
1674,
904,
2941,
88,
7,
627,
2948,
61,
627,
2948,
9,
1128,
870,
7244,
1674,
904,
4725,
88,
7,
627,
2948,
4258,
627,
2948,
9,
8065,
199,
318,
1255,
63,
765,
63,
2219,
8,
396,
304,
1128,
408,
2540,
1006,
2295,
626,
26511,
282,
1083,
402,
282,
1059,
909,
624,
2958,
511,
360,
18351,
297,
283,
16509,
1656,
283,
16509,
5320,
1128,
511,
360,
18351,
297,
283,
5006,
1656,
283,
6257,
5320,
1128,
511,
360,
18351,
297,
283,
6000,
297,
283,
33,
11629,
358,
1128,
511,
360,
18351,
297,
283,
33,
65,
33,
65,
297,
283,
33,
11629,
358,
2958,
511,
360,
835,
297,
283,
11629,
297,
650,
12,
283,
65,
358,
1128,
511,
360,
835,
297,
283,
11629,
297,
378,
12,
283,
66,
358,
2958,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
378,
12,
283,
3175,
358,
1128,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
1749,
12,
283,
3175,
297,
413,
9,
1128,
511,
360,
1623,
297,
283,
16238,
73,
3175,
297,
446,
17,
12,
283,
318,
297,
841,
9,
1128,
511,
360,
14542,
297,
283,
16238,
73,
3175,
297,
1749,
12,
283,
3175,
358,
1128,
511,
360,
2325,
297,
283,
1966,
44,
2041,
297,
283,
5006,
358,
1128,
511,
360,
2325,
297,
283,
5006,
297,
283,
5006,
358,
1128,
511,
360,
4142,
297,
283,
1966,
44,
2041,
297,
283,
24771,
1484,
358,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adityacs/ansible
|
lib/ansible/modules/clustering/consul.py
|
25
|
20671
|
#!/usr/bin/python
#
# (c) 2015, Steve Gargan <steve.gargan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = """
module: consul
short_description: "Add, modify & delete services within a consul cluster."
description:
- Registers services and checks for an agent with a consul cluster.
A service is some process running on the agent node that should be advertised by
consul's discovery mechanism. It may optionally supply a check definition,
a periodic service test to notify the consul cluster of service's health.
- "Checks may also be registered per node e.g. disk usage, or cpu usage and
notify the health of the entire node to the cluster.
Service level checks do not require a check name or id as these are derived
by Consul from the Service name and id respectively by appending 'service:'
Node level checks require a check_name and optionally a check_id."
- Currently, there is no complete way to retrieve the script, interval or ttl
metadata for a registered check. Without this metadata it is not possible to
tell if the data supplied with ansible represents a change to a check. As a
result this does not attempt to determine changes and will always report a
changed occurred. An api method is planned to supply this metadata so at that
stage change management will be added.
- "See http://consul.io for more details."
requirements:
- "python >= 2.6"
- python-consul
- requests
version_added: "2.0"
author: "Steve Gargan (@sgargan)"
options:
state:
description:
- register or deregister the consul service, defaults to present
required: true
choices: ['present', 'absent']
service_name:
description:
- Unique name for the service on a node, must be unique per node,
required if registering a service. May be omitted if registering
a node level check
required: false
service_id:
description:
- the ID for the service, must be unique per node, defaults to the
service name if the service name is supplied
required: false
default: service_name if supplied
host:
description:
- host of the consul agent defaults to localhost
required: false
default: localhost
port:
description:
- the port on which the consul agent is running
required: false
default: 8500
scheme:
description:
- the protocol scheme on which the consul agent is running
required: false
default: http
version_added: "2.1"
validate_certs:
description:
- whether to verify the tls certificate of the consul agent
required: false
default: True
version_added: "2.1"
notes:
description:
- Notes to attach to check when registering it.
required: false
default: None
service_port:
description:
- the port on which the service is listening required for
registration of a service, i.e. if service_name or service_id is set
required: false
service_address:
description:
- the address to advertise that the service will be listening on.
This value will be passed as the I(Address) parameter to Consul's
U(/v1/agent/service/register) API method, so refer to the Consul API
documentation for further details.
required: false
default: None
version_added: "2.1"
tags:
description:
- a list of tags that will be attached to the service registration.
required: false
default: None
script:
description:
- the script/command that will be run periodically to check the health
of the service. Scripts require an interval and vise versa
required: false
default: None
interval:
description:
- the interval at which the service check will be run. This is a number
with a s or m suffix to signify the units of seconds or minutes e.g
15s or 1m. If no suffix is supplied, m will be used by default e.g.
1 will be 1m. Required if the script param is specified.
required: false
default: None
check_id:
description:
- an ID for the service check, defaults to the check name, ignored if
part of a service definition.
required: false
default: None
check_name:
description:
- a name for the service check, defaults to the check id. required if
standalone, ignored if part of service definition.
required: false
default: None
ttl:
description:
- checks can be registered with a ttl instead of a script and interval
this means that the service will check in with the agent before the
ttl expires. If it doesn't the check will be considered failed.
Required if registering a check and the script an interval are missing
Similar to the interval this is a number with a s or m suffix to
signify the units of seconds or minutes e.g 15s or 1m. If no suffix
is supplied, m will be used by default e.g. 1 will be 1m
required: false
default: None
http:
description:
- checks can be registered with an http endpoint. This means that consul
will check that the http endpoint returns a successful http status.
Interval must also be provided with this option.
required: false
default: None
version_added: "2.0"
timeout:
description:
- A custom HTTP check timeout. The consul default is 10 seconds.
Similar to the interval this is a number with a s or m suffix to
signify the units of seconds or minutes, e.g. 15s or 1m.
required: false
default: None
version_added: "2.0"
token:
description:
- the token key indentifying an ACL rule set. May be required to register services.
required: false
default: None
"""
EXAMPLES = '''
- name: register nginx service with the local consul agent
consul:
service_name: nginx
service_port: 80
- name: register nginx service with curl check
consul:
service_name: nginx
service_port: 80
script: curl http://localhost
interval: 60s
- name: register nginx with an http check
consul:
service_name: nginx
service_port: 80
interval: 60s
http: http://localhost:80/status
- name: register external service nginx available at 10.1.5.23
consul:
service_name: nginx
service_port: 80
service_address: 10.1.5.23
- name: register nginx with some service tags
consul:
service_name: nginx
service_port: 80
tags:
- prod
- webservers
- name: remove nginx service
consul:
service_name: nginx
state: absent
- name: create a node level check to test disk usage
consul:
check_name: Disk usage
check_id: disk_usage
script: /opt/disk_usage.py
interval: 5m
- name: register an http check against a service that's already registered
consul:
check_name: nginx-check2
check_id: nginx-check2
service_id: nginx
interval: 60s
http: http://localhost:80/morestatus
'''
try:
import consul
from requests.exceptions import ConnectionError
python_consul_installed = True
except ImportError:
python_consul_installed = False
def register_with_consul(module):
state = module.params.get('state')
if state == 'present':
add(module)
else:
remove(module)
def add(module):
''' adds a service or a check depending on supplied configuration'''
check = parse_check(module)
service = parse_service(module)
if not service and not check:
module.fail_json(msg='a name and port are required to register a service')
if service:
if check:
service.add_check(check)
add_service(module, service)
elif check:
add_check(module, check)
def remove(module):
''' removes a service or a check '''
service_id = module.params.get('service_id') or module.params.get('service_name')
check_id = module.params.get('check_id') or module.params.get('check_name')
if not (service_id or check_id):
module.fail_json(msg='services and checks are removed by id or name. please supply a service id/name or a check id/name')
if service_id:
remove_service(module, service_id)
else:
remove_check(module, check_id)
def add_check(module, check):
''' registers a check with the given agent. currently there is no way
retrieve the full metadata of an existing check through the consul api.
Without this we can't compare to the supplied check and so we must assume
a change. '''
if not check.name and not service_id:
module.fail_json(msg='a check name is required for a node level check, one not attached to a service')
consul_api = get_consul_api(module)
check.register(consul_api)
module.exit_json(changed=True,
check_id=check.check_id,
check_name=check.name,
script=check.script,
interval=check.interval,
ttl=check.ttl,
http=check.http,
timeout=check.timeout,
service_id=check.service_id)
def remove_check(module, check_id):
''' removes a check using its id '''
consul_api = get_consul_api(module)
if check_id in consul_api.agent.checks():
consul_api.agent.check.deregister(check_id)
module.exit_json(changed=True, id=check_id)
module.exit_json(changed=False, id=check_id)
def add_service(module, service):
''' registers a service with the the current agent '''
result = service
changed = False
consul_api = get_consul_api(module)
existing = get_service_by_id_or_name(consul_api, service.id)
# there is no way to retrieve the details of checks so if a check is present
# in the service it must be re-registered
if service.has_checks() or not existing or not existing == service:
service.register(consul_api)
# check that it registered correctly
registered = get_service_by_id_or_name(consul_api, service.id)
if registered:
result = registered
changed = True
module.exit_json(changed=changed,
service_id=result.id,
service_name=result.name,
service_port=result.port,
checks=[check.to_dict() for check in service.checks],
tags=result.tags)
def remove_service(module, service_id):
''' deregister a service from the given agent using its service id '''
consul_api = get_consul_api(module)
service = get_service_by_id_or_name(consul_api, service_id)
if service:
consul_api.agent.service.deregister(service_id)
module.exit_json(changed=True, id=service_id)
module.exit_json(changed=False, id=service_id)
def get_consul_api(module, token=None):
return consul.Consul(host=module.params.get('host'),
port=module.params.get('port'),
scheme=module.params.get('scheme'),
verify=module.params.get('validate_certs'),
token=module.params.get('token'))
def get_service_by_id_or_name(consul_api, service_id_or_name):
''' iterate the registered services and find one with the given id '''
for name, service in consul_api.agent.services().items():
if service['ID'] == service_id_or_name or service['Service'] == service_id_or_name:
return ConsulService(loaded=service)
def parse_check(module):
if len(filter(None, [module.params.get('script'), module.params.get('ttl'), module.params.get('http')])) > 1:
module.fail_json(
msg='check are either script, http or ttl driven, supplying more than one does not make sense')
if module.params.get('check_id') or module.params.get('script') or module.params.get('ttl') or module.params.get('http'):
return ConsulCheck(
module.params.get('check_id'),
module.params.get('check_name'),
module.params.get('check_node'),
module.params.get('check_host'),
module.params.get('script'),
module.params.get('interval'),
module.params.get('ttl'),
module.params.get('notes'),
module.params.get('http'),
module.params.get('timeout'),
module.params.get('service_id'),
)
def parse_service(module):
if module.params.get('service_name') and module.params.get('service_port'):
return ConsulService(
module.params.get('service_id'),
module.params.get('service_name'),
module.params.get('service_address'),
module.params.get('service_port'),
module.params.get('tags'),
)
elif module.params.get('service_name') and not module.params.get('service_port'):
module.fail_json( msg="service_name supplied but no service_port, a port is required to configure a service. Did you configure the 'port' argument meaning 'service_port'?")
class ConsulService():
def __init__(self, service_id=None, name=None, address=None, port=-1,
tags=None, loaded=None):
self.id = self.name = name
if service_id:
self.id = service_id
self.address = address
self.port = port
self.tags = tags
self.checks = []
if loaded:
self.id = loaded['ID']
self.name = loaded['Service']
self.port = loaded['Port']
self.tags = loaded['Tags']
def register(self, consul_api):
if len(self.checks) > 0:
check = self.checks[0]
consul_api.agent.service.register(
self.name,
service_id=self.id,
address=self.address,
port=self.port,
tags=self.tags,
check=check.check)
else:
consul_api.agent.service.register(
self.name,
service_id=self.id,
address=self.address,
port=self.port,
tags=self.tags)
def add_check(self, check):
self.checks.append(check)
def checks(self):
return self.checks
def has_checks(self):
return len(self.checks) > 0
def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.id == other.id
and self.name == other.name
and self.port == other.port
and self.tags == other.tags)
def __ne__(self, other):
return not self.__eq__(other)
def to_dict(self):
data = {'id': self.id, "name": self.name}
if self.port:
data['port'] = self.port
if self.tags and len(self.tags) > 0:
data['tags'] = self.tags
if len(self.checks) > 0:
data['check'] = self.checks[0].to_dict()
return data
class ConsulCheck():
def __init__(self, check_id, name, node=None, host='localhost',
script=None, interval=None, ttl=None, notes=None, http=None, timeout=None, service_id=None):
self.check_id = self.name = name
if check_id:
self.check_id = check_id
self.service_id = service_id
self.notes = notes
self.node = node
self.host = host
self.interval = self.validate_duration('interval', interval)
self.ttl = self.validate_duration('ttl', ttl)
self.script = script
self.http = http
self.timeout = self.validate_duration('timeout', timeout)
self.check = None
if script:
self.check = consul.Check.script(script, self.interval)
if ttl:
self.check = consul.Check.ttl(self.ttl)
if http:
if interval is None:
raise Exception('http check must specify interval')
self.check = consul.Check.http(http, self.interval, self.timeout)
def validate_duration(self, name, duration):
if duration:
duration_units = ['ns', 'us', 'ms', 's', 'm', 'h']
if not any((duration.endswith(suffix) for suffix in duration_units)):
duration = "{}s".format(duration)
return duration
def register(self, consul_api):
consul_api.agent.check.register(self.name, check_id=self.check_id, service_id=self.service_id,
notes=self.notes,
check=self.check)
def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.check_id == other.check_id
and self.service_id == other.service_id
and self.name == other.name
and self.script == script
and self.interval == interval)
def __ne__(self, other):
return not self.__eq__(other)
def to_dict(self):
data = {}
self._add(data, 'id', attr='check_id')
self._add(data, 'name', attr='check_name')
self._add(data, 'script')
self._add(data, 'node')
self._add(data, 'notes')
self._add(data, 'host')
self._add(data, 'interval')
self._add(data, 'ttl')
self._add(data, 'http')
self._add(data, 'timeout')
self._add(data, 'service_id')
return data
def _add(self, data, key, attr=None):
try:
if attr is None:
attr = key
data[key] = getattr(self, attr)
except:
pass
def test_dependencies(module):
if not python_consul_installed:
module.fail_json(msg="python-consul required for this module. see http://python-consul.readthedocs.org/en/latest/#installation")
def main():
module = AnsibleModule(
argument_spec=dict(
host=dict(default='localhost'),
port=dict(default=8500, type='int'),
scheme=dict(required=False, default='http'),
validate_certs=dict(required=False, default=True, type='bool'),
check_id=dict(required=False),
check_name=dict(required=False),
check_node=dict(required=False),
check_host=dict(required=False),
notes=dict(required=False),
script=dict(required=False),
service_id=dict(required=False),
service_name=dict(required=False),
service_address=dict(required=False, type='str', default=None),
service_port=dict(required=False, type='int'),
state=dict(default='present', choices=['present', 'absent']),
interval=dict(required=False, type='str'),
ttl=dict(required=False, type='str'),
http=dict(required=False, type='str'),
timeout=dict(required=False, type='str'),
tags=dict(required=False, type='list'),
token=dict(required=False, no_log=True)
),
supports_check_mode=False,
)
test_dependencies(module)
try:
register_with_consul(module)
except ConnectionError as e:
module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
module.params.get('host'), module.params.get('port'), str(e)))
except Exception as e:
module.fail_json(msg=str(e))
# import module snippets
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
334,
67,
9,
6900,
12,
17854,
432,
598,
1273,
290,
665,
1597,
432,
14,
71,
1273,
290,
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,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
408,
199,
578,
26,
13447,
348,
199,
3612,
63,
1802,
26,
298,
1123,
12,
2811,
1253,
3145,
8500,
4453,
282,
13447,
348,
4350,
2122,
199,
1802,
26,
199,
446,
5044,
14186,
8500,
436,
5920,
367,
376,
6631,
543,
282,
13447,
348,
4350,
14,
2043,
437,
2435,
365,
2005,
2112,
3879,
641,
314,
6631,
1031,
626,
1077,
506,
19613,
939,
701,
2043,
13447,
348,
1159,
13172,
14729,
14,
2779,
1443,
14190,
17169,
282,
1104,
5492,
12,
2043,
282,
18745,
2435,
511,
370,
11705,
314,
13447,
348,
4350,
402,
2435,
1159,
13822,
14,
199,
446,
298,
11834,
1443,
2597,
506,
7264,
1126,
1031,
325,
14,
71,
14,
4543,
4503,
12,
503,
5033,
4503,
436,
2043,
11705,
314,
13822,
402,
314,
8039,
1031,
370,
314,
4350,
14,
2043,
7591,
2166,
5920,
886,
440,
4409,
282,
1104,
536,
503,
1305,
465,
3520,
787,
7131,
2043,
701,
1448,
83,
348,
687,
314,
7591,
536,
436,
1305,
17342,
701,
24373,
283,
1364,
4881,
2043,
5013,
2166,
5920,
4409,
282,
1104,
63,
354,
436,
14190,
282,
1104,
63,
344,
2122,
199,
446,
13550,
12,
2337,
365,
949,
4890,
4340,
370,
8044,
314,
2884,
12,
6252,
503,
14856,
2043,
3341,
367,
282,
7264,
1104,
14,
23952,
642,
3341,
652,
365,
221,
440,
3962,
370,
2043,
11480,
340,
314,
666,
6841,
543,
3242,
8469,
282,
1570,
370,
282,
1104,
14,
3709,
282,
2043,
754,
642,
1630,
440,
7427,
370,
6705,
4493,
436,
911,
3544,
3622,
282,
2043,
2896,
8920,
14,
1626,
2986,
1083,
365,
1620,
9386,
370,
17169,
642,
3341,
880,
737,
626,
2043,
9546,
1570,
10041,
911,
506,
3483,
14,
199,
446,
298,
9295,
1455,
921,
8704,
348,
14,
2308,
367,
1655,
2436,
2122,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
2366,
13,
8704,
348,
523,
446,
4145,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
26696,
432,
598,
1273,
290,
8593,
1226,
1273,
290,
2924,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
881,
446,
2274,
503,
477,
2683,
314,
13447,
348,
2435,
12,
4243,
370,
3451,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
2435,
63,
354,
26,
267,
1369,
26,
881,
446,
18276,
536,
367,
314,
2435,
641,
282,
1031,
12,
1471,
506,
3747,
1126,
1031,
12,
288,
1415,
340,
2274,
316,
282,
2435,
14,
10162,
506,
11684,
340,
2274,
316,
288,
282,
1031,
2166,
1104,
267,
1415,
26,
3055,
272,
2435,
63,
344,
26,
267,
1369,
26,
881,
446,
314,
2870,
367,
314,
2435,
12,
1471,
506,
3747,
1126,
1031,
12,
4243,
370,
314,
288,
2435,
536,
340,
314,
2435,
536,
365,
6841,
267,
1415,
26,
3055,
267,
849,
26,
2435,
63,
354,
340,
6841,
272,
1591,
26,
267,
1369,
26,
881,
446,
1591,
402,
314,
13447,
348,
6631,
4243,
370,
11667,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
1844,
26,
267,
1369,
26,
881,
446,
314,
1844,
641,
1314,
314,
13447,
348,
6631,
365,
3879,
267,
1415,
26,
3055,
267,
849,
26,
1695,
5783,
272,
5687,
26,
267,
1369,
26,
881,
446,
314,
4113,
5687,
641,
1314,
314,
13447,
348,
6631,
365,
3879,
267,
1415,
26,
3055,
267,
849,
26,
1455,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
4107,
63,
8356,
26,
267,
1369,
26,
881,
446,
3775,
370,
4911,
314,
15142,
5897,
402,
314,
13447,
348,
6631,
267,
1415,
26,
3055,
267,
849,
26,
715,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
12681,
26,
267,
1369,
26,
881,
446,
8144,
370,
6554,
370,
1104,
1380,
2274,
316,
652,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
2435,
63,
719,
26,
267,
1369,
26,
881,
446,
314,
1844,
641,
1314,
314,
2435,
365,
22721,
1415,
367,
288,
10991,
402,
282,
2435,
12,
284,
14,
69,
14,
340,
2435,
63,
354,
503,
2435,
63,
344,
365,
663,
267,
1415,
26,
3055,
272,
2435,
63,
1562,
26,
267,
1369,
26,
881,
446,
314,
2287,
370,
19613,
261,
626,
314,
2435,
911,
506,
22721,
641,
14,
288,
961,
574,
911,
506,
3032,
465,
314,
473,
8,
1476,
9,
2725,
370,
1448,
83,
348,
1159,
288,
738,
29478,
86,
17,
15,
4054,
15,
1364,
15,
2683,
9,
3261,
1083,
12,
880,
10618,
370,
314,
1448,
83,
348,
3261,
288,
3794,
367,
9848,
2436,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
3762,
26,
267,
1369,
26,
881,
446,
282,
769,
402,
3762,
626,
911,
506,
10102,
370,
314,
2435,
10991,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
2884,
26,
267,
1369,
26,
881,
446,
314,
2884,
15,
1531,
626,
911,
506,
1255,
18745,
1183,
370,
1104,
314,
13822,
288,
402,
314,
2435,
14,
14914,
83,
4409,
376,
6252,
436,
373
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
334,
67,
9,
6900,
12,
17854,
432,
598,
1273,
290,
665,
1597,
432,
14,
71,
1273,
290,
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,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
408,
199,
578,
26,
13447,
348,
199,
3612,
63,
1802,
26,
298,
1123,
12,
2811,
1253,
3145,
8500,
4453,
282,
13447,
348,
4350,
2122,
199,
1802,
26,
199,
446,
5044,
14186,
8500,
436,
5920,
367,
376,
6631,
543,
282,
13447,
348,
4350,
14,
2043,
437,
2435,
365,
2005,
2112,
3879,
641,
314,
6631,
1031,
626,
1077,
506,
19613,
939,
701,
2043,
13447,
348,
1159,
13172,
14729,
14,
2779,
1443,
14190,
17169,
282,
1104,
5492,
12,
2043,
282,
18745,
2435,
511,
370,
11705,
314,
13447,
348,
4350,
402,
2435,
1159,
13822,
14,
199,
446,
298,
11834,
1443,
2597,
506,
7264,
1126,
1031,
325,
14,
71,
14,
4543,
4503,
12,
503,
5033,
4503,
436,
2043,
11705,
314,
13822,
402,
314,
8039,
1031,
370,
314,
4350,
14,
2043,
7591,
2166,
5920,
886,
440,
4409,
282,
1104,
536,
503,
1305,
465,
3520,
787,
7131,
2043,
701,
1448,
83,
348,
687,
314,
7591,
536,
436,
1305,
17342,
701,
24373,
283,
1364,
4881,
2043,
5013,
2166,
5920,
4409,
282,
1104,
63,
354,
436,
14190,
282,
1104,
63,
344,
2122,
199,
446,
13550,
12,
2337,
365,
949,
4890,
4340,
370,
8044,
314,
2884,
12,
6252,
503,
14856,
2043,
3341,
367,
282,
7264,
1104,
14,
23952,
642,
3341,
652,
365,
221,
440,
3962,
370,
2043,
11480,
340,
314,
666,
6841,
543,
3242,
8469,
282,
1570,
370,
282,
1104,
14,
3709,
282,
2043,
754,
642,
1630,
440,
7427,
370,
6705,
4493,
436,
911,
3544,
3622,
282,
2043,
2896,
8920,
14,
1626,
2986,
1083,
365,
1620,
9386,
370,
17169,
642,
3341,
880,
737,
626,
2043,
9546,
1570,
10041,
911,
506,
3483,
14,
199,
446,
298,
9295,
1455,
921,
8704,
348,
14,
2308,
367,
1655,
2436,
2122,
199,
7538,
26,
523,
446,
298,
1548,
2356,
499,
14,
22,
2,
523,
446,
2366,
13,
8704,
348,
523,
446,
4145,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
26696,
432,
598,
1273,
290,
8593,
1226,
1273,
290,
2924,
199,
1419,
26,
272,
1174,
26,
267,
1369,
26,
881,
446,
2274,
503,
477,
2683,
314,
13447,
348,
2435,
12,
4243,
370,
3451,
267,
1415,
26,
2549,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
272,
2435,
63,
354,
26,
267,
1369,
26,
881,
446,
18276,
536,
367,
314,
2435,
641,
282,
1031,
12,
1471,
506,
3747,
1126,
1031,
12,
288,
1415,
340,
2274,
316,
282,
2435,
14,
10162,
506,
11684,
340,
2274,
316,
288,
282,
1031,
2166,
1104,
267,
1415,
26,
3055,
272,
2435,
63,
344,
26,
267,
1369,
26,
881,
446,
314,
2870,
367,
314,
2435,
12,
1471,
506,
3747,
1126,
1031,
12,
4243,
370,
314,
288,
2435,
536,
340,
314,
2435,
536,
365,
6841,
267,
1415,
26,
3055,
267,
849,
26,
2435,
63,
354,
340,
6841,
272,
1591,
26,
267,
1369,
26,
881,
446,
1591,
402,
314,
13447,
348,
6631,
4243,
370,
11667,
267,
1415,
26,
3055,
267,
849,
26,
11667,
272,
1844,
26,
267,
1369,
26,
881,
446,
314,
1844,
641,
1314,
314,
13447,
348,
6631,
365,
3879,
267,
1415,
26,
3055,
267,
849,
26,
1695,
5783,
272,
5687,
26,
267,
1369,
26,
881,
446,
314,
4113,
5687,
641,
1314,
314,
13447,
348,
6631,
365,
3879,
267,
1415,
26,
3055,
267,
849,
26,
1455,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
4107,
63,
8356,
26,
267,
1369,
26,
881,
446,
3775,
370,
4911,
314,
15142,
5897,
402,
314,
13447,
348,
6631,
267,
1415,
26,
3055,
267,
849,
26,
715,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
12681,
26,
267,
1369,
26,
881,
446,
8144,
370,
6554,
370,
1104,
1380,
2274,
316,
652,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
2435,
63,
719,
26,
267,
1369,
26,
881,
446,
314,
1844,
641,
1314,
314,
2435,
365,
22721,
1415,
367,
288,
10991,
402,
282,
2435,
12,
284,
14,
69,
14,
340,
2435,
63,
354,
503,
2435,
63,
344,
365,
663,
267,
1415,
26,
3055,
272,
2435,
63,
1562,
26,
267,
1369,
26,
881,
446,
314,
2287,
370,
19613,
261,
626,
314,
2435,
911,
506,
22721,
641,
14,
288,
961,
574,
911,
506,
3032,
465,
314,
473,
8,
1476,
9,
2725,
370,
1448,
83,
348,
1159,
288,
738,
29478,
86,
17,
15,
4054,
15,
1364,
15,
2683,
9,
3261,
1083,
12,
880,
10618,
370,
314,
1448,
83,
348,
3261,
288,
3794,
367,
9848,
2436,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
267,
1015,
63,
3270,
26,
298,
18,
14,
17,
2,
272,
3762,
26,
267,
1369,
26,
881,
446,
282,
769,
402,
3762,
626,
911,
506,
10102,
370,
314,
2435,
10991,
14,
267,
1415,
26,
3055,
267,
849,
26,
488,
272,
2884,
26,
267,
1369,
26,
881,
446,
314,
2884,
15,
1531,
626,
911,
506,
1255,
18745,
1183,
370,
1104,
314,
13822,
288,
402,
314,
2435,
14,
14914,
83,
4409,
376,
6252,
436,
373,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
anand-c-goog/tensorflow
|
tensorflow/contrib/distributions/python/ops/dirichlet_multinomial.py
|
7
|
11100
|
# 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.
# ==============================================================================
"""The Dirichlet Multinomial distribution class."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.contrib.distributions.python.ops import distribution
from tensorflow.contrib.distributions.python.ops import distribution_util
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import check_ops
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import special_math_ops
_dirichlet_multinomial_prob_note = """
For each batch of counts `[n_1,...,n_k]`, `P[counts]` is the probability
that after sampling `n` draws from this Dirichlet Multinomial
distribution, the number of draws falling in class `j` is `n_j`. Note that
different sequences of draws can result in the same counts, thus the
probability includes a combinatorial coefficient.
Note that input, "counts", must be a non-negative tensor with dtype `dtype`
and whose shape can be broadcast with `self.alpha`. For fixed leading
dimensions, the last dimension represents counts for the corresponding
Dirichlet Multinomial distribution in `self.alpha`. `counts` is only legal if
it sums up to `n` and its components are equal to integer values.
"""
class DirichletMultinomial(distribution.Distribution):
"""DirichletMultinomial mixture distribution.
This distribution is parameterized by a vector `alpha` of concentration
parameters for `k` classes and `n`, the counts per each class..
#### Mathematical details
The Dirichlet Multinomial is a distribution over k-class count data, meaning
for each k-tuple of non-negative integer `counts = [c_1,...,c_k]`, we have a
probability of these draws being made from the distribution. The distribution
has hyperparameters `alpha = (alpha_1,...,alpha_k)`, and probability mass
function (pmf):
```pmf(counts) = N! / (n_1!...n_k!) * Beta(alpha + c) / Beta(alpha)```
where above `N = sum_j n_j`, `N!` is `N` factorial, and
`Beta(x) = prod_j Gamma(x_j) / Gamma(sum_j x_j)` is the multivariate beta
function.
This is a mixture distribution in that `M` samples can be produced by:
1. Choose class probabilities `p = (p_1,...,p_k) ~ Dir(alpha)`
2. Draw integers `m = (n_1,...,n_k) ~ Multinomial(N, p)`
This class provides methods to create indexed batches of Dirichlet
Multinomial distributions. If the provided `alpha` is rank 2 or higher, for
every fixed set of leading dimensions, the last dimension represents one
single Dirichlet Multinomial distribution. When calling distribution
functions (e.g. `dist.pmf(counts)`), `alpha` and `counts` are broadcast to the
same shape (if possible). In all cases, the last dimension of alpha/counts
represents single Dirichlet Multinomial distributions.
#### Examples
```python
alpha = [1, 2, 3]
n = 2
dist = DirichletMultinomial(n, alpha)
```
Creates a 3-class distribution, with the 3rd class is most likely to be drawn.
The distribution functions can be evaluated on counts.
```python
# counts same shape as alpha.
counts = [0, 0, 2]
dist.pmf(counts) # Shape []
# alpha will be broadcast to [[1, 2, 3], [1, 2, 3]] to match counts.
counts = [[1, 1, 0], [1, 0, 1]]
dist.pmf(counts) # Shape [2]
# alpha will be broadcast to shape [5, 7, 3] to match counts.
counts = [[...]] # Shape [5, 7, 3]
dist.pmf(counts) # Shape [5, 7]
```
Creates a 2-batch of 3-class distributions.
```python
alpha = [[1, 2, 3], [4, 5, 6]] # Shape [2, 3]
n = [3, 3]
dist = DirichletMultinomial(n, alpha)
# counts will be broadcast to [[2, 1, 0], [2, 1, 0]] to match alpha.
counts = [2, 1, 0]
dist.pmf(counts) # Shape [2]
```
"""
# TODO(b/27419586) Change docstring for dtype of alpha once int allowed.
def __init__(self,
n,
alpha,
validate_args=False,
allow_nan_stats=True,
name="DirichletMultinomial"):
"""Initialize a batch of DirichletMultinomial distributions.
Args:
n: Non-negative floating point tensor, whose dtype is the same as
`alpha`. The shape is broadcastable to `[N1,..., Nm]` with `m >= 0`.
Defines this as a batch of `N1 x ... x Nm` different Dirichlet
multinomial distributions. Its components should be equal to integer
values.
alpha: Positive floating point tensor, whose dtype is the same as
`n` with shape broadcastable to `[N1,..., Nm, k]` `m >= 0`. Defines
this as a batch of `N1 x ... x Nm` different `k` class Dirichlet
multinomial distributions.
validate_args: `Boolean`, default `False`. Whether to assert valid
values for parameters `alpha` and `n`, and `x` in `prob` and
`log_prob`. If `False`, correct behavior is not guaranteed.
allow_nan_stats: `Boolean`, default `True`. If `False`, raise an
exception if a statistic (e.g. mean/mode/etc...) is undefined for any
batch member. If `True`, batch members with valid parameters leading to
undefined statistics will return NaN for this statistic.
name: The name to prefix Ops created by this distribution class.
Examples:
```python
# Define 1-batch of 2-class Dirichlet multinomial distribution,
# also known as a beta-binomial.
dist = DirichletMultinomial(2.0, [1.1, 2.0])
# Define a 2-batch of 3-class distributions.
dist = DirichletMultinomial([3., 4], [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
```
"""
parameters = locals()
parameters.pop("self")
with ops.name_scope(name, values=[n, alpha]) as ns:
# Broadcasting works because:
# * The broadcasting convention is to prepend dimensions of size [1], and
# we use the last dimension for the distribution, wherease
# the batch dimensions are the leading dimensions, which forces the
# distribution dimension to be defined explicitly (i.e. it cannot be
# created automatically by prepending). This forces enough
# explicitivity.
# * All calls involving `counts` eventually require a broadcast between
# `counts` and alpha.
self._alpha = self._assert_valid_alpha(alpha, validate_args)
self._n = self._assert_valid_n(n, validate_args)
self._alpha_sum = math_ops.reduce_sum(
self._alpha, reduction_indices=[-1], keep_dims=False)
super(DirichletMultinomial, self).__init__(
dtype=self._alpha.dtype,
is_continuous=False,
is_reparameterized=False,
validate_args=validate_args,
allow_nan_stats=allow_nan_stats,
parameters=parameters,
graph_parents=[self._alpha, self._n, self._alpha_sum],
name=ns)
@property
def n(self):
"""Parameter defining this distribution."""
return self._n
@property
def alpha(self):
"""Parameter defining this distribution."""
return self._alpha
@property
def alpha_sum(self):
"""Summation of alpha parameter."""
return self._alpha_sum
def _batch_shape(self):
return array_ops.shape(self.alpha_sum)
def _get_batch_shape(self):
return self.alpha_sum.get_shape()
def _event_shape(self):
return array_ops.reverse(array_ops.shape(self.alpha), [True])[0]
def _get_event_shape(self):
# Event shape depends only on alpha, not "n".
return self.alpha.get_shape().with_rank_at_least(1)[-1:]
@distribution_util.AppendDocstring(_dirichlet_multinomial_prob_note)
def _log_prob(self, counts):
counts = self._assert_valid_counts(counts)
ordered_prob = (special_math_ops.lbeta(self.alpha + counts) -
special_math_ops.lbeta(self.alpha))
log_prob = ordered_prob + distribution_util.log_combinations(
self.n, counts)
return log_prob
@distribution_util.AppendDocstring(_dirichlet_multinomial_prob_note)
def _prob(self, counts):
return math_ops.exp(self._log_prob(counts))
def _mean(self):
normalized_alpha = self.alpha / array_ops.expand_dims(self.alpha_sum, -1)
return array_ops.expand_dims(self.n, -1) * normalized_alpha
@distribution_util.AppendDocstring(
"""The variance for each batch member is defined as the following:
```
Var(X_j) = n * alpha_j / alpha_0 * (1 - alpha_j / alpha_0) *
(n + alpha_0) / (1 + alpha_0)
```
where `alpha_0 = sum_j alpha_j`.
The covariance between elements in a batch is defined as:
```
Cov(X_i, X_j) = -n * alpha_i * alpha_j / alpha_0 ** 2 *
(n + alpha_0) / (1 + alpha_0)
```
""")
def _variance(self):
alpha_sum = array_ops.expand_dims(self.alpha_sum, -1)
normalized_alpha = self.alpha / alpha_sum
variance = -math_ops.batch_matmul(
array_ops.expand_dims(normalized_alpha, -1),
array_ops.expand_dims(normalized_alpha, -2))
variance = array_ops.matrix_set_diag(variance, normalized_alpha *
(1. - normalized_alpha))
shared_factor = (self.n * (alpha_sum + self.n) /
(alpha_sum + 1) * array_ops.ones_like(self.alpha))
variance *= array_ops.expand_dims(shared_factor, -1)
return variance
def _assert_valid_counts(self, counts):
"""Check counts for proper shape, values, then return tensor version."""
counts = ops.convert_to_tensor(counts, name="counts")
if not self.validate_args:
return counts
candidate_n = math_ops.reduce_sum(counts, reduction_indices=[-1])
return control_flow_ops.with_dependencies([
check_ops.assert_non_negative(counts),
check_ops.assert_equal(
self._n, candidate_n,
message="counts do not sum to n"),
distribution_util.assert_integer_form(counts)], counts)
def _assert_valid_alpha(self, alpha, validate_args):
alpha = ops.convert_to_tensor(alpha, name="alpha")
if not validate_args:
return alpha
return control_flow_ops.with_dependencies(
[check_ops.assert_rank_at_least(alpha, 1),
check_ops.assert_positive(alpha)], alpha)
def _assert_valid_n(self, n, validate_args):
n = ops.convert_to_tensor(n, name="n")
if not validate_args:
return n
return control_flow_ops.with_dependencies(
[check_ops.assert_non_negative(n),
distribution_util.assert_integer_form(n)], n)
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
3757,
19683,
603,
427,
16956,
4084,
1021,
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,
5613,
14,
1548,
14,
1483,
492,
4084,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
4084,
63,
1974,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4539,
63,
3442,
63,
1483,
421,
199,
63,
328,
19683,
63,
28265,
63,
6101,
63,
4610,
275,
408,
199,
1858,
1924,
3522,
402,
8242,
14505,
78,
63,
17,
32699,
78,
63,
75,
61,
3559,
658,
48,
59,
6851,
16090,
365,
314,
12224,
199,
9099,
2410,
15877,
658,
78,
64,
5954,
83,
687,
642,
3757,
19683,
603,
427,
16956,
199,
4972,
12,
314,
1329,
402,
5954,
83,
32039,
315,
1021,
658,
74,
64,
365,
658,
78,
63,
74,
2313,
221,
3390,
626,
199,
14020,
8013,
402,
5954,
83,
883,
754,
315,
314,
2011,
8242,
12,
12850,
314,
199,
17210,
6952,
282,
5300,
8566,
2380,
9421,
14,
199,
199,
7443,
626,
1324,
12,
298,
6851,
401,
1471,
506,
282,
2222,
13,
7371,
2345,
543,
2152,
658,
2271,
64,
199,
460,
7447,
2215,
883,
506,
11180,
543,
658,
277,
14,
4468,
2313,
221,
2104,
6317,
9186,
199,
13320,
12,
314,
2061,
6240,
8469,
8242,
367,
314,
5226,
199,
1341,
19683,
603,
427,
16956,
4084,
315,
658,
277,
14,
4468,
2313,
658,
6851,
64,
365,
1454,
18393,
340,
199,
390,
27690,
1536,
370,
658,
78,
64,
436,
2399,
7323,
787,
4472,
370,
3000,
1338,
14,
199,
624,
421,
199,
533,
3757,
19683,
30233,
16956,
8,
4972,
14,
8580,
304,
523,
408,
1341,
19683,
30233,
16956,
31885,
4084,
14,
819,
961,
4084,
365,
29526,
701,
282,
5477,
658,
4468,
64,
402,
406,
19722,
523,
2633,
367,
658,
75,
64,
3992,
436,
658,
78,
3559,
314,
8242,
1126,
1924,
1021,
703,
819,
14055,
16593,
28491,
2436,
819,
710,
3757,
19683,
603,
427,
16956,
365,
282,
4084,
1806,
1022,
13,
533,
2338,
666,
12,
11150,
523,
367,
1924,
1022,
13,
2960,
402,
2222,
13,
7371,
3000,
658,
6851,
275,
359,
67,
63,
17,
32699,
67,
63,
75,
61,
3559,
781,
1172,
282,
523,
12224,
402,
3520,
5954,
83,
3769,
6326,
687,
314,
4084,
14,
221,
710,
4084,
523,
965,
10342,
3214,
658,
4468,
275,
334,
4468,
63,
17,
32699,
4468,
63,
75,
32124,
436,
12224,
12250,
523,
805,
334,
31842,
304,
819,
10841,
31842,
8,
6851,
9,
275,
653,
1,
1182,
334,
78,
63,
17,
1,
1396,
78,
63,
75,
21866,
627,
29521,
8,
4468,
435,
286,
9,
1182,
29521,
8,
4468,
9719,
64,
819,
2382,
3432,
658,
46,
275,
3089,
63,
74,
302,
63,
74,
3559,
658,
46,
1,
64,
365,
658,
46,
64,
32618,
12,
436,
523,
658,
21732,
8,
88,
9,
275,
12441,
63,
74,
598,
4746,
8,
88,
63,
74,
9,
1182,
598,
4746,
8,
1838,
63,
74,
671,
63,
74,
12544,
365,
314,
32409,
8201,
523,
805,
14,
819,
961,
365,
282,
31885,
4084,
315,
626,
658,
45,
64,
5845,
883,
506,
13584,
701,
26,
272,
413,
14,
29826,
1021,
19555,
658,
80,
275,
334,
80,
63,
17,
32699,
80,
63,
75,
9,
6146,
25866,
8,
4468,
12544,
272,
499,
14,
17813,
9446,
658,
77,
275,
334,
78,
63,
17,
32699,
78,
63,
75,
9,
6146,
603,
427,
16956,
8,
46,
12,
299,
12544,
819,
961,
1021,
6571,
3102,
370,
1218,
15235,
19593,
402,
3757,
19683,
523,
603,
427,
16956,
10208,
14,
221,
982,
314,
2741,
658,
4468,
64,
365,
6915,
499,
503,
10948,
12,
367,
523,
4036,
6317,
663,
402,
9186,
7365,
12,
314,
2061,
6240,
8469,
1373,
523,
2849,
3757,
19683,
603,
427,
16956,
4084,
14,
221,
3979,
6358,
4084,
523,
3423,
334,
69,
14,
71,
14,
658,
2686,
14,
31842,
8,
6851,
12544,
395,
658,
4468,
64,
436,
658,
6851,
64,
787,
11180,
370,
314,
523,
2011,
2215,
334,
692,
3962,
680,
221,
1010,
1006,
5560,
12,
314,
2061,
6240,
402,
5131,
15,
6851,
523,
8469,
2849,
3757,
19683,
603,
427,
16956,
10208,
14,
819,
14055,
6058,
819,
10841,
1548,
523,
5131,
275,
359,
17,
12,
499,
12,
650,
61,
523,
302,
275,
499,
523,
2917,
275,
3757,
19683,
30233,
16956,
8,
78,
12,
5131,
9,
523,
10841,
819,
10560,
282,
650,
13,
533,
4084,
12,
543,
314,
650,
6883,
1021,
365,
4750,
12060,
370,
506,
19341,
14,
523,
710,
4084,
3423,
883,
506,
13006,
641,
8242,
14,
819,
10841,
1548,
523,
327,
8242,
2011,
2215,
465,
5131,
14,
523,
8242,
275,
359,
16,
12,
378,
12,
499,
61,
523,
2917,
14,
31842,
8,
6851,
9,
221,
327,
16528,
942,
819,
327,
5131,
911,
506,
11180,
370,
3474,
17,
12,
499,
12,
650,
467,
359,
17,
12,
499,
12,
650,
2677,
370,
1336,
8242,
14,
523,
8242,
275,
3474,
17,
12,
413,
12,
378,
467,
359,
17,
12,
378,
12,
413,
2677,
523,
2917,
14,
31842,
8,
6851,
9
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
3757,
19683,
603,
427,
16956,
4084,
1021,
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,
5613,
14,
1548,
14,
1483,
492,
4084,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
492,
4084,
63,
1974,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1104,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3304,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4539,
63,
3442,
63,
1483,
421,
199,
63,
328,
19683,
63,
28265,
63,
6101,
63,
4610,
275,
408,
199,
1858,
1924,
3522,
402,
8242,
14505,
78,
63,
17,
32699,
78,
63,
75,
61,
3559,
658,
48,
59,
6851,
16090,
365,
314,
12224,
199,
9099,
2410,
15877,
658,
78,
64,
5954,
83,
687,
642,
3757,
19683,
603,
427,
16956,
199,
4972,
12,
314,
1329,
402,
5954,
83,
32039,
315,
1021,
658,
74,
64,
365,
658,
78,
63,
74,
2313,
221,
3390,
626,
199,
14020,
8013,
402,
5954,
83,
883,
754,
315,
314,
2011,
8242,
12,
12850,
314,
199,
17210,
6952,
282,
5300,
8566,
2380,
9421,
14,
199,
199,
7443,
626,
1324,
12,
298,
6851,
401,
1471,
506,
282,
2222,
13,
7371,
2345,
543,
2152,
658,
2271,
64,
199,
460,
7447,
2215,
883,
506,
11180,
543,
658,
277,
14,
4468,
2313,
221,
2104,
6317,
9186,
199,
13320,
12,
314,
2061,
6240,
8469,
8242,
367,
314,
5226,
199,
1341,
19683,
603,
427,
16956,
4084,
315,
658,
277,
14,
4468,
2313,
658,
6851,
64,
365,
1454,
18393,
340,
199,
390,
27690,
1536,
370,
658,
78,
64,
436,
2399,
7323,
787,
4472,
370,
3000,
1338,
14,
199,
624,
421,
199,
533,
3757,
19683,
30233,
16956,
8,
4972,
14,
8580,
304,
523,
408,
1341,
19683,
30233,
16956,
31885,
4084,
14,
819,
961,
4084,
365,
29526,
701,
282,
5477,
658,
4468,
64,
402,
406,
19722,
523,
2633,
367,
658,
75,
64,
3992,
436,
658,
78,
3559,
314,
8242,
1126,
1924,
1021,
703,
819,
14055,
16593,
28491,
2436,
819,
710,
3757,
19683,
603,
427,
16956,
365,
282,
4084,
1806,
1022,
13,
533,
2338,
666,
12,
11150,
523,
367,
1924,
1022,
13,
2960,
402,
2222,
13,
7371,
3000,
658,
6851,
275,
359,
67,
63,
17,
32699,
67,
63,
75,
61,
3559,
781,
1172,
282,
523,
12224,
402,
3520,
5954,
83,
3769,
6326,
687,
314,
4084,
14,
221,
710,
4084,
523,
965,
10342,
3214,
658,
4468,
275,
334,
4468,
63,
17,
32699,
4468,
63,
75,
32124,
436,
12224,
12250,
523,
805,
334,
31842,
304,
819,
10841,
31842,
8,
6851,
9,
275,
653,
1,
1182,
334,
78,
63,
17,
1,
1396,
78,
63,
75,
21866,
627,
29521,
8,
4468,
435,
286,
9,
1182,
29521,
8,
4468,
9719,
64,
819,
2382,
3432,
658,
46,
275,
3089,
63,
74,
302,
63,
74,
3559,
658,
46,
1,
64,
365,
658,
46,
64,
32618,
12,
436,
523,
658,
21732,
8,
88,
9,
275,
12441,
63,
74,
598,
4746,
8,
88,
63,
74,
9,
1182,
598,
4746,
8,
1838,
63,
74,
671,
63,
74,
12544,
365,
314,
32409,
8201,
523,
805,
14,
819,
961,
365,
282,
31885,
4084,
315,
626,
658,
45,
64,
5845,
883,
506,
13584,
701,
26,
272,
413,
14,
29826,
1021,
19555,
658,
80,
275,
334,
80,
63,
17,
32699,
80,
63,
75,
9,
6146,
25866,
8,
4468,
12544,
272,
499,
14,
17813,
9446,
658,
77,
275,
334,
78,
63,
17,
32699,
78,
63,
75,
9,
6146,
603,
427,
16956,
8,
46,
12,
299,
12544,
819,
961,
1021,
6571,
3102,
370,
1218,
15235,
19593,
402,
3757,
19683,
523,
603,
427,
16956,
10208,
14,
221,
982,
314,
2741,
658,
4468,
64,
365,
6915,
499,
503,
10948,
12,
367,
523,
4036,
6317,
663,
402,
9186,
7365,
12,
314,
2061,
6240,
8469,
1373,
523,
2849,
3757,
19683,
603,
427,
16956,
4084,
14,
221,
3979,
6358,
4084,
523,
3423,
334,
69,
14,
71,
14,
658,
2686,
14,
31842,
8,
6851,
12544,
395,
658,
4468,
64,
436,
658,
6851,
64,
787,
11180,
370,
314,
523,
2011,
2215,
334,
692,
3962,
680,
221,
1010,
1006,
5560,
12,
314,
2061,
6240,
402,
5131,
15,
6851,
523,
8469,
2849,
3757,
19683,
603,
427,
16956,
10208,
14,
819,
14055,
6058,
819,
10841,
1548,
523,
5131,
275,
359,
17,
12,
499,
12,
650,
61,
523,
302,
275,
499,
523,
2917,
275,
3757,
19683,
30233,
16956,
8,
78,
12,
5131,
9,
523,
10841,
819,
10560,
282,
650,
13,
533,
4084,
12,
543,
314,
650,
6883,
1021,
365,
4750,
12060,
370,
506,
19341,
14,
523,
710,
4084,
3423,
883,
506,
13006,
641,
8242,
14,
819,
10841,
1548,
523,
327,
8242,
2011,
2215,
465,
5131,
14,
523,
8242,
275,
359,
16,
12,
378,
12,
499,
61,
523,
2917,
14,
31842,
8,
6851,
9,
221,
327,
16528,
942,
819,
327,
5131,
911,
506,
11180,
370,
3474,
17,
12,
499,
12,
650,
467,
359,
17,
12,
499,
12,
650,
2677,
370,
1336,
8242,
14,
523,
8242,
275,
3474,
17,
12,
413,
12,
378,
467,
359,
17,
12,
378,
12,
413,
2677,
523,
2917,
14,
31842,
8,
6851,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
jacegem/lotto-store
|
lib/future/moves/urllib/request.py
|
70
|
3525
|
from __future__ import absolute_import
from future.standard_library import suspend_hooks
from future.utils import PY3
if PY3:
from urllib.request import *
# This aren't in __all__:
from urllib.request import (getproxies,
pathname2url,
proxy_bypass,
quote,
request_host,
splitattr,
splithost,
splitpasswd,
splitport,
splitquery,
splittag,
splittype,
splituser,
splitvalue,
thishost,
to_bytes,
unquote,
unwrap,
url2pathname,
urlcleanup,
urljoin,
urlopen,
urlparse,
urlretrieve,
urlsplit,
urlunparse)
else:
__future_module__ = True
with suspend_hooks():
from urllib import *
from urllib2 import *
from urlparse import *
# Rename:
from urllib import toBytes # missing from __all__ on Py2.6
to_bytes = toBytes
# from urllib import (pathname2url,
# url2pathname,
# getproxies,
# urlretrieve,
# urlcleanup,
# URLopener,
# FancyURLopener,
# proxy_bypass)
# from urllib2 import (
# AbstractBasicAuthHandler,
# AbstractDigestAuthHandler,
# BaseHandler,
# CacheFTPHandler,
# FileHandler,
# FTPHandler,
# HTTPBasicAuthHandler,
# HTTPCookieProcessor,
# HTTPDefaultErrorHandler,
# HTTPDigestAuthHandler,
# HTTPErrorProcessor,
# HTTPHandler,
# HTTPPasswordMgr,
# HTTPPasswordMgrWithDefaultRealm,
# HTTPRedirectHandler,
# HTTPSHandler,
# URLError,
# build_opener,
# install_opener,
# OpenerDirector,
# ProxyBasicAuthHandler,
# ProxyDigestAuthHandler,
# ProxyHandler,
# Request,
# UnknownHandler,
# urlopen,
# )
# from urlparse import (
# urldefrag
# urljoin,
# urlparse,
# urlunparse,
# urlsplit,
# urlunsplit,
# parse_qs,
# parse_q"
# )
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
6466,
14,
6807,
63,
4342,
492,
20288,
63,
7922,
199,
504,
6466,
14,
1208,
492,
7843,
19,
199,
199,
692,
7843,
19,
26,
272,
687,
4011,
14,
1069,
492,
627,
272,
327,
961,
10621,
1133,
315,
636,
452,
10651,
272,
687,
4011,
14,
1069,
492,
334,
362,
17128,
12,
1816,
11776,
18,
633,
12,
1816,
4566,
63,
20605,
12,
1816,
6313,
12,
1816,
1056,
63,
1102,
12,
1816,
3715,
962,
12,
1816,
2249,
317,
15157,
12,
1816,
2249,
317,
32376,
2989,
12,
1816,
2249,
317,
19394,
12,
1816,
3715,
1131,
12,
1816,
3715,
1450,
12,
1816,
3715,
466,
12,
1816,
3715,
751,
12,
1816,
3715,
585,
12,
1816,
642,
1102,
12,
1816,
370,
63,
2394,
12,
1816,
14342,
12,
1816,
625,
3823,
12,
1816,
1166,
18,
12445,
12,
1816,
1166,
7661,
12,
1816,
20818,
12,
1816,
18279,
12,
1816,
7097,
12,
1816,
1166,
14270,
12,
1816,
29596,
12,
1816,
30111,
9,
199,
2836,
26,
272,
636,
2443,
63,
578,
363,
275,
715,
272,
543,
20288,
63,
7922,
837,
267,
687,
4011,
492,
627,
267,
687,
4011,
18,
492,
627,
267,
687,
7097,
492,
627,
398,
327,
22756,
26,
267,
687,
4011,
492,
370,
5571,
259,
327,
4124,
687,
636,
452,
363,
641,
1611,
18,
14,
22,
267,
370,
63,
2394,
275,
370,
5571,
398,
327,
687,
4011,
492,
334,
12445,
18,
633,
12,
267,
327,
9326,
1166,
18,
12445,
12,
267,
327,
9326,
664,
17128,
12,
267,
327,
9326,
1166,
14270,
12,
267,
327,
9326,
1166,
7661,
12,
267,
327,
9326,
2851,
11637,
12,
267,
327,
9326,
481,
9844,
2632,
11637,
12,
267,
327,
9326,
4566,
63,
20605,
9,
13857,
327,
687,
4011,
18,
492,
334,
267,
327,
8295,
11836,
6845,
21547,
12,
267,
327,
8295,
11836,
18541,
21547,
12,
267,
327,
8295,
3523,
2461,
12,
267,
327,
8295,
11977,
15123,
2461,
12,
267,
327,
8295,
3814,
2461,
12,
267,
327,
8295,
23125,
2461,
12,
267,
327,
8295,
3101,
6845,
21547,
12,
267,
327,
8295,
3101,
7810,
10438,
12,
267,
327,
8295,
3101,
2698,
25933,
12,
267,
327,
8295,
3101,
18541,
21547,
12,
267,
327,
8295,
15050,
10438,
12,
267,
327,
8295,
3101,
2461,
12,
267,
327,
8295,
3101,
6139,
20752,
12,
267,
327,
8295,
3101,
6139,
20752,
3007,
2698,
27422,
12,
267,
327,
8295,
3101,
7071,
2461,
12,
267,
327,
8295,
14147,
2461,
12,
267,
327,
8295,
30794,
12,
267,
327,
8295,
1900,
63,
11637,
12,
267,
327,
8295,
3907,
63,
11637,
12,
267,
327,
8295,
9319,
727,
28704,
12,
267,
327,
8295,
12373,
6845,
21547,
12,
267,
327,
8295,
12373,
18541,
21547,
12,
267,
327,
8295,
12373,
2461,
12,
267,
327,
8295,
4784,
12,
267,
327,
8295,
14831,
2461,
12,
267,
327,
8295,
18279,
12,
267,
327,
463,
776,
13857,
327,
687,
7097,
492,
334,
267,
327,
8295,
1166,
318,
2527,
267,
327,
8295,
20818,
12,
267,
327,
8295,
7097,
12,
267,
327,
8295,
30111,
12,
267,
327,
8295,
29596,
12,
267,
327,
8295,
1166,
30038,
12,
267,
327,
8295,
2198,
63,
6177,
12,
267,
327,
8295,
2198,
63,
81,
2,
267,
327,
463,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
6466,
14,
6807,
63,
4342,
492,
20288,
63,
7922,
199,
504,
6466,
14,
1208,
492,
7843,
19,
199,
199,
692,
7843,
19,
26,
272,
687,
4011,
14,
1069,
492,
627,
272,
327,
961,
10621,
1133,
315,
636,
452,
10651,
272,
687,
4011,
14,
1069,
492,
334,
362,
17128,
12,
1816,
11776,
18,
633,
12,
1816,
4566,
63,
20605,
12,
1816,
6313,
12,
1816,
1056,
63,
1102,
12,
1816,
3715,
962,
12,
1816,
2249,
317,
15157,
12,
1816,
2249,
317,
32376,
2989,
12,
1816,
2249,
317,
19394,
12,
1816,
3715,
1131,
12,
1816,
3715,
1450,
12,
1816,
3715,
466,
12,
1816,
3715,
751,
12,
1816,
3715,
585,
12,
1816,
642,
1102,
12,
1816,
370,
63,
2394,
12,
1816,
14342,
12,
1816,
625,
3823,
12,
1816,
1166,
18,
12445,
12,
1816,
1166,
7661,
12,
1816,
20818,
12,
1816,
18279,
12,
1816,
7097,
12,
1816,
1166,
14270,
12,
1816,
29596,
12,
1816,
30111,
9,
199,
2836,
26,
272,
636,
2443,
63,
578,
363,
275,
715,
272,
543,
20288,
63,
7922,
837,
267,
687,
4011,
492,
627,
267,
687,
4011,
18,
492,
627,
267,
687,
7097,
492,
627,
398,
327,
22756,
26,
267,
687,
4011,
492,
370,
5571,
259,
327,
4124,
687,
636,
452,
363,
641,
1611,
18,
14,
22,
267,
370,
63,
2394,
275,
370,
5571,
398,
327,
687,
4011,
492,
334,
12445,
18,
633,
12,
267,
327,
9326,
1166,
18,
12445,
12,
267,
327,
9326,
664,
17128,
12,
267,
327,
9326,
1166,
14270,
12,
267,
327,
9326,
1166,
7661,
12,
267,
327,
9326,
2851,
11637,
12,
267,
327,
9326,
481,
9844,
2632,
11637,
12,
267,
327,
9326,
4566,
63,
20605,
9,
13857,
327,
687,
4011,
18,
492,
334,
267,
327,
8295,
11836,
6845,
21547,
12,
267,
327,
8295,
11836,
18541,
21547,
12,
267,
327,
8295,
3523,
2461,
12,
267,
327,
8295,
11977,
15123,
2461,
12,
267,
327,
8295,
3814,
2461,
12,
267,
327,
8295,
23125,
2461,
12,
267,
327,
8295,
3101,
6845,
21547,
12,
267,
327,
8295,
3101,
7810,
10438,
12,
267,
327,
8295,
3101,
2698,
25933,
12,
267,
327,
8295,
3101,
18541,
21547,
12,
267,
327,
8295,
15050,
10438,
12,
267,
327,
8295,
3101,
2461,
12,
267,
327,
8295,
3101,
6139,
20752,
12,
267,
327,
8295,
3101,
6139,
20752,
3007,
2698,
27422,
12,
267,
327,
8295,
3101,
7071,
2461,
12,
267,
327,
8295,
14147,
2461,
12,
267,
327,
8295,
30794,
12,
267,
327,
8295,
1900,
63,
11637,
12,
267,
327,
8295,
3907,
63,
11637,
12,
267,
327,
8295,
9319,
727,
28704,
12,
267,
327,
8295,
12373,
6845,
21547,
12,
267,
327,
8295,
12373,
18541,
21547,
12,
267,
327,
8295,
12373,
2461,
12,
267,
327,
8295,
4784,
12,
267,
327,
8295,
14831,
2461,
12,
267,
327,
8295,
18279,
12,
267,
327,
463,
776,
13857,
327,
687,
7097,
492,
334,
267,
327,
8295,
1166,
318,
2527,
267,
327,
8295,
20818,
12,
267,
327,
8295,
7097,
12,
267,
327,
8295,
30111,
12,
267,
327,
8295,
29596,
12,
267,
327,
8295,
1166,
30038,
12,
267,
327,
8295,
2198,
63,
6177,
12,
267,
327,
8295,
2198,
63,
81,
2,
267,
327,
463,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrquim/repository.mrquim
|
repo/plugin.video.LiveTV/resources/lib/acestream.py
|
21
|
4639
|
# -*- coding: utf-8 -*-
""" Plexus (c) 2015 enen92
This file contains the function that brigdes the addon to the acecore.py file
Functions:
load_local_torrent() -> Load a local .torrent file
acestreams(name,iconimage,chid) -> Function that interprets the received url (acestream://,*.acelive,ts://) and sends it to acestreams_builtin
acestreams_builtin(name,iconimage,chid -> Bridge to acecore.py file
"""
import xbmc,xbmcgui,xbmcplugin,urllib,xbmcvfs,os,subprocess
from plexusutils.pluginxbmc import *
from history import *
aceport=62062
def load_local_torrent():
torrent_file = xbmcgui.Dialog().browse(1, translate(30037),'video', '.torrent')
if torrent_file:
if xbmc.getCondVisibility('system.platform.windows'):
acestreams("Local .torrent ("+str("file:\\" + torrent_file) +")","",'file:\\' + torrent_file)
else:
acestreams("Local .torrent ("+str("file://" + torrent_file) +")","",'file://' + urllib.quote(torrent_file))
else: pass
def acestreams(name,iconimage,chid):
if not iconimage: iconimage=os.path.join(addonpath,'resources','art','acestream-menu-item.png')
else: iconimage = urllib.unquote(iconimage)
if settings.getSetting('addon_history') == "true":
try: add_to_history(name, str(chid),1, iconimage)
except: pass
if settings.getSetting('engine_app') != '2' and settings.getSetting('engine_app') != '3':
if settings.getSetting('aceplay_type') == "2":
pDialog = xbmcgui.DialogProgress()
ret = pDialog.create(translate(30000), translate(30038),translate(30039),translate(30040))
pDialog.update(0)
xbmc.sleep(3000)
pDialog.update(100)
pDialog.close()
ip_adress = settings.getSetting('ip_addr')
proxy_port = settings.getSetting('aceporta')
chid=chid.replace('acestream://','').replace('ts://','')
strm = "http://" + ip_adress + ":" + proxy_port + "/pid/" + chid + "/stream.mp4"
listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
listitem.setLabel(name + " (" + chid + ")")
listitem.setInfo('video', {'Title': name + " (" + chid + ")"})
xbmc.Player().play(strm,listitem)
else: acestreams_builtin(name,iconimage,chid)
else:
if '.acelive' in chid: pass
elif '.torrent' in chid: pass
else:
if 'acestream://' in chid: pass
else: chid = 'acestream://' + chid
if settings.getSetting('engine_app') == '2':
xbmc.executebuiltin('XBMC.StartAndroidActivity("org.acestream","android.intent.action.VIEW","","'+chid+'")')
elif settings.getSetting('engine_app') == '3':
xbmc.executebuiltin('XBMC.StartAndroidActivity("ru.vidsoftware.acestreamcontroller.free","android.intent.action.VIEW","","'+chid+'")')
def acestreams_builtin(name,iconimage,chid):
if xbmc.getCondVisibility('system.platform.windows'):
try:
import _winreg
t = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 'Software\AceStream')
needed_value = _winreg.QueryValueEx(t , 'EnginePath')[0]
print needed_value.replace('\\','\\\\')
subprocess.Popen("wmic process where ExecutablePath='"+needed_value.replace('\\','\\\\')+"' delete",shell=True)
xbmc.sleep(200)
subprocess.Popen('taskkill /F /IM ace_player.exe /T',shell=True)
xbmc.sleep(200)
except: pass
elif xbmc.getCondVisibility('System.Platform.OSX'):
if settings.getSetting('shutdown-engine') == "true":
os.system("kill $(ps aux | grep '[s]tart.py')")
try:from acecore import TSengine as tsengine
except:
mensagemok(translate(30000),translate(30041))
return
xbmc.executebuiltin('Action(Stop)')
lock_file = xbmc.translatePath('special://temp/'+ 'ts.lock')
if xbmcvfs.exists(lock_file):
xbmcvfs.delete(lock_file)
if chid != '':
chid=chid.replace('acestream://','').replace('ts://','')
print("Starting Player Ace hash: " + chid)
TSPlayer = tsengine()
out = None
if chid.find('http://') == -1 and chid.find('.torrent') == -1:
out = TSPlayer.load_torrent(chid,'PID',port=aceport)
elif chid.find('http://') == -1 and chid.find('.torrent') != -1:
out = TSPlayer.load_torrent(chid,'TORRENT',port=aceport)
else:
out = TSPlayer.load_torrent(chid,'TORRENT',port=aceport)
if out == 'Ok':
TSPlayer.play_url_ind(0,name + ' (' + chid + ')',iconimage,iconimage)
TSPlayer.end()
return
else:
mensagemok(translate(30000),translate(30042))
TSPlayer.end()
return
else:
mensagemprogresso.close()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
510,
3113,
527,
221,
334,
67,
9,
221,
6900,
655,
287,
2942,
339,
961,
570,
3509,
314,
805,
626,
20611,
71,
3424,
314,
13553,
370,
314,
282,
301,
1018,
14,
647,
570,
2286,
17471,
26,
2286,
2248,
63,
1832,
63,
14101,
342,
1035,
7190,
282,
2257,
1275,
14101,
570,
272,
282,
301,
11231,
8,
354,
12,
4677,
1569,
12,
335,
344,
9,
1035,
6801,
626,
6421,
1086,
314,
3086,
1166,
334,
7984,
1745,
921,
12,
4856,
7984,
6442,
12,
1086,
921,
9,
436,
16178,
652,
370,
282,
301,
11231,
63,
5351,
272,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
1035,
699,
5562,
370,
282,
301,
1018,
14,
647,
570,
272,
198,
199,
199,
624,
1362,
199,
646,
11709,
12,
21382,
5885,
12,
21382,
2718,
12,
4078,
12,
1774,
77,
5107,
2319,
12,
736,
12,
5781,
199,
504,
299,
3113,
527,
1208,
14,
2718,
21382,
492,
627,
199,
504,
7994,
492,
627,
199,
199,
7984,
719,
29,
22085,
2789,
199,
199,
318,
2248,
63,
1832,
63,
14101,
837,
199,
198,
14101,
63,
493,
275,
26418,
14,
5619,
1252,
4570,
8,
17,
12,
9028,
8,
5863,
1401,
26582,
3722,
297,
1987,
14101,
358,
199,
198,
692,
17671,
63,
493,
26,
507,
198,
692,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
686,
198,
7984,
11231,
480,
5339,
1275,
14101,
1689,
11,
495,
480,
493,
26,
15022,
435,
17671,
63,
493,
9,
435,
531,
401,
341,
2584,
493,
18589,
7,
435,
17671,
63,
493,
9,
507,
198,
2836,
26,
686,
198,
7984,
11231,
480,
5339,
1275,
14101,
1689,
11,
495,
480,
493,
30443,
435,
17671,
63,
493,
9,
435,
531,
401,
341,
2584,
493,
22399,
435,
4011,
14,
3513,
8,
14101,
63,
493,
430,
199,
198,
2836,
26,
986,
199,
199,
318,
282,
301,
11231,
8,
354,
12,
4677,
1569,
12,
335,
344,
304,
199,
198,
692,
440,
7016,
1569,
26,
7016,
1569,
29,
736,
14,
515,
14,
904,
8,
9291,
515,
2584,
4435,
1673,
580,
1673,
7984,
1745,
13,
4470,
13,
1053,
14,
4524,
358,
199,
198,
2836,
26,
7016,
1569,
275,
4011,
14,
12240,
8,
4677,
1569,
9,
199,
198,
692,
2202,
14,
30008,
360,
9291,
63,
5570,
358,
508,
298,
2052,
582,
507,
198,
893,
26,
1050,
63,
475,
63,
5570,
8,
354,
12,
620,
8,
335,
344,
395,
17,
12,
7016,
1569,
9,
507,
198,
2590,
26,
986,
199,
198,
692,
2202,
14,
30008,
360,
3908,
63,
571,
358,
1137,
283,
18,
7,
436,
2202,
14,
30008,
360,
3908,
63,
571,
358,
1137,
283,
19,
356,
507,
198,
692,
2202,
14,
30008,
360,
7984,
2802,
63,
466,
358,
508,
298,
18,
582,
686,
198,
80,
5619,
275,
26418,
14,
5619,
11504,
342,
686,
198,
3292,
275,
299,
5619,
14,
981,
8,
5275,
8,
19,
993,
395,
9028,
8,
5863,
1703,
395,
5275,
8,
5863,
1355,
395,
5275,
8,
5863,
2167,
430,
686,
198,
80,
5619,
14,
873,
8,
16,
9,
686,
198,
21382,
14,
4532,
8,
19962,
9,
686,
198,
80,
5619,
14,
873,
8,
1960,
9,
686,
198,
80,
5619,
14,
1600,
342,
686,
198,
711,
63,
350,
753,
275,
2202,
14,
30008,
360,
711,
63,
2697,
358,
686,
198,
3280,
63,
719,
275,
2202,
14,
30008,
360,
7984,
719,
65,
358,
686,
198,
335,
344,
29,
335,
344,
14,
1814,
360,
7984,
1745,
921,
26516,
1814,
360,
1086,
921,
20944,
686,
198,
495,
77,
275,
298,
1014,
30443,
435,
3384,
63,
350,
753,
435,
14725,
435,
4566,
63,
719,
435,
3286,
3150,
6687,
435,
682,
344,
435,
3286,
1745,
14,
311,
20,
2,
686,
198,
513,
1053,
275,
26418,
14,
24229,
8,
354,
12,
7016,
3491,
628,
2698,
9166,
14,
4524,
401,
10062,
3491,
29,
4677,
1569,
9,
686,
198,
513,
1053,
14,
409,
4314,
8,
354,
435,
298,
1689,
435,
682,
344,
435,
6099,
531,
686,
198,
513,
1053,
14,
409,
2354,
360,
3722,
297,
791,
6888,
356,
536,
435,
298,
1689,
435,
682,
344,
435,
19607,
1552,
686,
198,
21382,
14,
10921,
1252,
2802,
8,
495,
77,
12,
513,
1053,
9,
507,
198,
2836,
26,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
9,
199,
198,
2836,
26,
507,
198,
692,
1987,
7984,
6442,
7,
315,
682,
344,
26,
986,
507,
198,
4164,
1987,
14101,
7,
315,
682,
344,
26,
986,
507,
198,
2836,
26,
686,
198,
692,
283,
7984,
1745,
22399,
315,
682,
344,
26,
986,
686,
198,
2836,
26,
682,
344,
275,
283,
7984,
1745,
22399,
435,
682,
344,
507,
198,
692,
2202,
14,
30008,
360,
3908,
63,
571,
358,
508,
283,
18,
356,
686,
198,
21382,
14,
2526,
5351,
360,
20806,
7608,
14,
3162,
20762,
14350,
480,
1308,
14,
7984,
1745,
2266,
6238,
14,
17456,
14,
1287,
14,
12058,
401,
5151,
4507,
11,
335,
344,
4786,
531,
358,
507,
198,
4164,
2202,
14,
30008,
360,
3908,
63,
571,
358,
508,
283,
19,
356,
686,
198,
21382,
14,
2526,
5351,
360,
20806,
7608,
14,
3162,
20762,
14350,
480,
6558,
14,
5017,
15619,
14,
7984,
1745,
5538,
14,
4624,
2266,
6238,
14,
17456,
14,
1287,
14,
12058,
401,
5151,
4507,
11,
335,
344,
4786,
531,
358,
199,
199,
318,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
304,
272,
340,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
267,
862,
26,
288,
492,
485,
15658,
288,
307,
275,
485,
15658,
14,
28144,
1547,
15658,
14,
23802,
63,
14211,
63,
3791,
12,
283,
10337,
60,
33,
301,
3296,
358,
288,
4346,
63,
585,
275,
221,
485,
15658,
14,
3227,
1110,
920,
8,
84,
2360,
283,
8524,
2042,
5832,
16,
61,
288,
870,
4346,
63,
585,
14,
1814,
11671,
1673,
8712,
358,
288,
3873,
14,
7942,
480,
87,
15003,
2112,
2382,
9434,
2964,
2042,
534,
7709,
11368,
63,
585,
14,
1814,
11671,
1673,
8712,
358,
11,
4507,
3145,
401,
5641,
29,
549,
9,
288,
11709,
14,
4532,
8,
1840,
9,
288,
3873,
14,
7942,
360,
1765,
8997,
1182,
38,
1182,
1469,
282,
301,
63,
6147,
14,
5803,
1182,
52,
297,
5641,
29,
549,
9,
288
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
510,
3113,
527,
221,
334,
67,
9,
221,
6900,
655,
287,
2942,
339,
961,
570,
3509,
314,
805,
626,
20611,
71,
3424,
314,
13553,
370,
314,
282,
301,
1018,
14,
647,
570,
2286,
17471,
26,
2286,
2248,
63,
1832,
63,
14101,
342,
1035,
7190,
282,
2257,
1275,
14101,
570,
272,
282,
301,
11231,
8,
354,
12,
4677,
1569,
12,
335,
344,
9,
1035,
6801,
626,
6421,
1086,
314,
3086,
1166,
334,
7984,
1745,
921,
12,
4856,
7984,
6442,
12,
1086,
921,
9,
436,
16178,
652,
370,
282,
301,
11231,
63,
5351,
272,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
1035,
699,
5562,
370,
282,
301,
1018,
14,
647,
570,
272,
198,
199,
199,
624,
1362,
199,
646,
11709,
12,
21382,
5885,
12,
21382,
2718,
12,
4078,
12,
1774,
77,
5107,
2319,
12,
736,
12,
5781,
199,
504,
299,
3113,
527,
1208,
14,
2718,
21382,
492,
627,
199,
504,
7994,
492,
627,
199,
199,
7984,
719,
29,
22085,
2789,
199,
199,
318,
2248,
63,
1832,
63,
14101,
837,
199,
198,
14101,
63,
493,
275,
26418,
14,
5619,
1252,
4570,
8,
17,
12,
9028,
8,
5863,
1401,
26582,
3722,
297,
1987,
14101,
358,
199,
198,
692,
17671,
63,
493,
26,
507,
198,
692,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
686,
198,
7984,
11231,
480,
5339,
1275,
14101,
1689,
11,
495,
480,
493,
26,
15022,
435,
17671,
63,
493,
9,
435,
531,
401,
341,
2584,
493,
18589,
7,
435,
17671,
63,
493,
9,
507,
198,
2836,
26,
686,
198,
7984,
11231,
480,
5339,
1275,
14101,
1689,
11,
495,
480,
493,
30443,
435,
17671,
63,
493,
9,
435,
531,
401,
341,
2584,
493,
22399,
435,
4011,
14,
3513,
8,
14101,
63,
493,
430,
199,
198,
2836,
26,
986,
199,
199,
318,
282,
301,
11231,
8,
354,
12,
4677,
1569,
12,
335,
344,
304,
199,
198,
692,
440,
7016,
1569,
26,
7016,
1569,
29,
736,
14,
515,
14,
904,
8,
9291,
515,
2584,
4435,
1673,
580,
1673,
7984,
1745,
13,
4470,
13,
1053,
14,
4524,
358,
199,
198,
2836,
26,
7016,
1569,
275,
4011,
14,
12240,
8,
4677,
1569,
9,
199,
198,
692,
2202,
14,
30008,
360,
9291,
63,
5570,
358,
508,
298,
2052,
582,
507,
198,
893,
26,
1050,
63,
475,
63,
5570,
8,
354,
12,
620,
8,
335,
344,
395,
17,
12,
7016,
1569,
9,
507,
198,
2590,
26,
986,
199,
198,
692,
2202,
14,
30008,
360,
3908,
63,
571,
358,
1137,
283,
18,
7,
436,
2202,
14,
30008,
360,
3908,
63,
571,
358,
1137,
283,
19,
356,
507,
198,
692,
2202,
14,
30008,
360,
7984,
2802,
63,
466,
358,
508,
298,
18,
582,
686,
198,
80,
5619,
275,
26418,
14,
5619,
11504,
342,
686,
198,
3292,
275,
299,
5619,
14,
981,
8,
5275,
8,
19,
993,
395,
9028,
8,
5863,
1703,
395,
5275,
8,
5863,
1355,
395,
5275,
8,
5863,
2167,
430,
686,
198,
80,
5619,
14,
873,
8,
16,
9,
686,
198,
21382,
14,
4532,
8,
19962,
9,
686,
198,
80,
5619,
14,
873,
8,
1960,
9,
686,
198,
80,
5619,
14,
1600,
342,
686,
198,
711,
63,
350,
753,
275,
2202,
14,
30008,
360,
711,
63,
2697,
358,
686,
198,
3280,
63,
719,
275,
2202,
14,
30008,
360,
7984,
719,
65,
358,
686,
198,
335,
344,
29,
335,
344,
14,
1814,
360,
7984,
1745,
921,
26516,
1814,
360,
1086,
921,
20944,
686,
198,
495,
77,
275,
298,
1014,
30443,
435,
3384,
63,
350,
753,
435,
14725,
435,
4566,
63,
719,
435,
3286,
3150,
6687,
435,
682,
344,
435,
3286,
1745,
14,
311,
20,
2,
686,
198,
513,
1053,
275,
26418,
14,
24229,
8,
354,
12,
7016,
3491,
628,
2698,
9166,
14,
4524,
401,
10062,
3491,
29,
4677,
1569,
9,
686,
198,
513,
1053,
14,
409,
4314,
8,
354,
435,
298,
1689,
435,
682,
344,
435,
6099,
531,
686,
198,
513,
1053,
14,
409,
2354,
360,
3722,
297,
791,
6888,
356,
536,
435,
298,
1689,
435,
682,
344,
435,
19607,
1552,
686,
198,
21382,
14,
10921,
1252,
2802,
8,
495,
77,
12,
513,
1053,
9,
507,
198,
2836,
26,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
9,
199,
198,
2836,
26,
507,
198,
692,
1987,
7984,
6442,
7,
315,
682,
344,
26,
986,
507,
198,
4164,
1987,
14101,
7,
315,
682,
344,
26,
986,
507,
198,
2836,
26,
686,
198,
692,
283,
7984,
1745,
22399,
315,
682,
344,
26,
986,
686,
198,
2836,
26,
682,
344,
275,
283,
7984,
1745,
22399,
435,
682,
344,
507,
198,
692,
2202,
14,
30008,
360,
3908,
63,
571,
358,
508,
283,
18,
356,
686,
198,
21382,
14,
2526,
5351,
360,
20806,
7608,
14,
3162,
20762,
14350,
480,
1308,
14,
7984,
1745,
2266,
6238,
14,
17456,
14,
1287,
14,
12058,
401,
5151,
4507,
11,
335,
344,
4786,
531,
358,
507,
198,
4164,
2202,
14,
30008,
360,
3908,
63,
571,
358,
508,
283,
19,
356,
686,
198,
21382,
14,
2526,
5351,
360,
20806,
7608,
14,
3162,
20762,
14350,
480,
6558,
14,
5017,
15619,
14,
7984,
1745,
5538,
14,
4624,
2266,
6238,
14,
17456,
14,
1287,
14,
12058,
401,
5151,
4507,
11,
335,
344,
4786,
531,
358,
199,
199,
318,
282,
301,
11231,
63,
5351,
8,
354,
12,
4677,
1569,
12,
335,
344,
304,
272,
340,
11709,
14,
362,
23735,
24735,
360,
2253,
14,
3246,
14,
8258,
735,
267,
862,
26,
288,
492,
485,
15658,
288,
307,
275,
485,
15658,
14,
28144,
1547,
15658,
14,
23802,
63,
14211,
63,
3791,
12,
283,
10337,
60,
33,
301,
3296,
358,
288,
4346,
63,
585,
275,
221,
485,
15658,
14,
3227,
1110,
920,
8,
84,
2360,
283,
8524,
2042,
5832,
16,
61,
288,
870,
4346,
63,
585,
14,
1814,
11671,
1673,
8712,
358,
288,
3873,
14,
7942,
480,
87,
15003,
2112,
2382,
9434,
2964,
2042,
534,
7709,
11368,
63,
585,
14,
1814,
11671,
1673,
8712,
358,
11,
4507,
3145,
401,
5641,
29,
549,
9,
288,
11709,
14,
4532,
8,
1840,
9,
288,
3873,
14,
7942,
360,
1765,
8997,
1182,
38,
1182,
1469,
282,
301,
63,
6147,
14,
5803,
1182,
52,
297,
5641,
29,
549,
9,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fedora-conary/conary
|
conary/cmds/clone.py
|
2
|
8091
|
#
# Copyright (c) SAS Institute Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import itertools
from conary import callbacks
from conary import errors
from conary import versions
from conary.conaryclient import ConaryClient, cmdline
from conary.conaryclient import callbacks as client_callbacks
def displayCloneJob(cs):
indent = ' '
def _sortTroveNameKey(x):
name = x.getName()
return (not name.endswith(':source'), x.getNewFlavor(), name)
csTroves = sorted(cs.iterNewTroveList(), key=_sortTroveNameKey)
for csTrove in csTroves:
newInfo = str(csTrove.getNewVersion())
flavor = csTrove.getNewFlavor()
if not flavor.isEmpty():
newInfo += '[%s]' % flavor
print "%sClone %-20s (%s)" % (indent, csTrove.getName(), newInfo)
def CloneTrove(cfg, targetBranch, troveSpecList, updateBuildInfo = True,
info = False, cloneSources = False, message = None,
test = False, fullRecurse = False, ignoreConflicts = False,
exactFlavors = False):
client = ConaryClient(cfg)
repos = client.getRepos()
targetBranch = versions.VersionFromString(targetBranch)
if not isinstance(targetBranch, versions.Branch):
raise errors.ParseError('Cannot specify full version "%s" to clone to - must specify target branch' % targetBranch)
troveSpecs = [ cmdline.parseTroveSpec(x) for x in troveSpecList]
componentSpecs = [ x[0] for x in troveSpecs
if ':' in x[0] and x[0].split(':')[1] != 'source']
if componentSpecs:
raise errors.ParseError('Cannot clone components: %s' % ', '.join(componentSpecs))
trovesToClone = repos.findTroves(cfg.installLabelPath,
troveSpecs, cfg.flavor,
exactFlavors = exactFlavors)
trovesToClone = list(set(itertools.chain(*trovesToClone.itervalues())))
if not client.cfg.quiet:
callback = client_callbacks.CloneCallback(client.cfg, message)
else:
callback = callbacks.CloneCallback()
okay, cs = client.createCloneChangeSet(targetBranch, trovesToClone,
updateBuildInfo=updateBuildInfo,
infoOnly=info, callback=callback,
fullRecurse=fullRecurse,
cloneSources=cloneSources)
if not okay:
return
return _finishClone(client, cfg, cs, callback, info=info,
test=test, ignoreConflicts=ignoreConflicts)
def _convertLabelOrBranch(lblStr, template):
try:
if not lblStr:
return None
if lblStr[0] == '/':
v = versions.VersionFromString(lblStr)
if isinstance(v, versions.Branch):
return v
# Some day we could lift this restriction if its useful.
raise errors.ParseError('Cannot specify version to promote'
' - must specify branch or label')
if not template:
return versions.Label(lblStr)
hostName = template.getHost()
nameSpace = template.getNamespace()
tag = template.branch
if lblStr[0] == ':':
lblStr = '%s@%s%s' % (hostName, nameSpace, lblStr)
elif lblStr[0] == '@':
lblStr = '%s%s' % (hostName, lblStr)
elif lblStr[-1] == '@':
lblStr = '%s%s:%s' % (lblStr, nameSpace, tag)
return versions.Label(lblStr)
except Exception, msg:
raise errors.ParseError('Error parsing %r: %s' % (lblStr, msg))
def promoteTroves(cfg, troveSpecs, targetList, skipBuildInfo=False,
info=False, message=None, test=False,
ignoreConflicts=False, cloneOnlyByDefaultTroves=False,
cloneSources = False, allFlavors = False, client=None,
targetFile = None, exactFlavors = None,
excludeGroups = False):
targetMap = {}
searchPath = []
for fromLoc, toLoc in targetList:
context = cfg.buildLabel
fromLoc = _convertLabelOrBranch(fromLoc, context)
if fromLoc is not None:
if isinstance(fromLoc, versions.Branch):
context = fromLoc.label()
else:
context = fromLoc
searchPath.append(context)
toLoc = _convertLabelOrBranch(toLoc, context)
targetMap[fromLoc] = toLoc
troveSpecs = [ cmdline.parseTroveSpec(x, False) for x in troveSpecs ]
if exactFlavors:
allFlavors = False
elif allFlavors:
cfg.flavor = []
troveSpecFlavors = {}
for troveSpec in troveSpecs:
troveSpecFlavors.setdefault(
(troveSpec[0], troveSpec[1], None),
[]).append(troveSpec[2])
troveSpecs = list(troveSpecFlavors)
client = ConaryClient(cfg)
if not searchPath:
searchPath = cfg.buildLabel
searchSource = client.getSearchSource(installLabelPath=searchPath)
results = searchSource.findTroves(troveSpecs,
bestFlavor=not allFlavors,
exactFlavors=exactFlavors)
if allFlavors:
trovesToClone = []
for troveSpec, troveTups in results.items():
specFlavors = troveSpecFlavors[troveSpec]
for specFlavor in specFlavors:
if specFlavor is None:
matchingTups = troveTups
else:
matchingTups = [ x for x in troveTups
if x[2].stronglySatisfies(specFlavor)]
# we only clone the latest version for all troves.
# bestFlavor=False resturns the leaves for all flavors, so
# we may need to cut some out.
latest = max([x[1] for x in matchingTups])
matchingTups = [ x for x in matchingTups if x[1] == latest ]
trovesToClone.extend(matchingTups)
else:
trovesToClone = itertools.chain(*results.itervalues())
trovesToClone = list(set(trovesToClone))
if not client.cfg.quiet:
callback = client_callbacks.CloneCallback(client.cfg, message)
else:
callback = callbacks.CloneCallback()
okay, cs = client.createSiblingCloneChangeSet(
targetMap, trovesToClone,
updateBuildInfo=not skipBuildInfo,
infoOnly=info, callback=callback,
cloneOnlyByDefaultTroves=cloneOnlyByDefaultTroves,
cloneSources=cloneSources,
excludeGroups=excludeGroups)
if not okay:
return False
return _finishClone(client, cfg, cs, callback, info=info,
test=test, ignoreConflicts=ignoreConflicts,
targetFile=targetFile)
def _finishClone(client, cfg, cs, callback, info=False, test=False,
ignoreConflicts=False, targetFile=None):
repos = client.repos
if cfg.interactive or info:
print 'The following clones will be created:'
displayCloneJob(cs)
if info:
return
if cfg.interactive:
print
okay = cmdline.askYn('continue with clone? [y/N]', default=False)
if not okay:
return
if targetFile:
cs.writeToFile(targetFile)
elif not test:
repos.commitChangeSet(cs, callback=callback)
return cs
|
apache-2.0
|
[
3,
199,
3,
1898,
334,
67,
9,
26124,
1010,
25585,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
421,
199,
646,
7975,
199,
199,
504,
406,
695,
492,
13484,
199,
504,
406,
695,
492,
2552,
199,
504,
406,
695,
492,
5459,
199,
504,
406,
695,
14,
388,
695,
1258,
492,
1448,
695,
3041,
12,
21206,
199,
504,
406,
695,
14,
388,
695,
1258,
492,
13484,
465,
1890,
63,
11948,
421,
199,
318,
2929,
21222,
6694,
8,
1259,
304,
272,
4363,
275,
283,
257,
283,
272,
347,
485,
3191,
52,
11750,
985,
1197,
8,
88,
304,
267,
536,
275,
671,
14,
16405,
342,
267,
372,
334,
1397,
536,
14,
4130,
6176,
1365,
659,
671,
14,
362,
4665,
16739,
1062,
536,
9,
272,
7117,
52,
293,
2310,
275,
3355,
8,
1259,
14,
1661,
4665,
52,
11750,
1296,
1062,
790,
3699,
3191,
52,
11750,
985,
1197,
9,
339,
367,
7117,
52,
11750,
315,
7117,
52,
293,
2310,
26,
267,
892,
2354,
275,
620,
8,
1259,
52,
11750,
14,
362,
4665,
3353,
1012,
267,
8541,
275,
7117,
52,
11750,
14,
362,
4665,
16739,
342,
267,
340,
440,
8541,
14,
374,
4699,
837,
288,
892,
2354,
847,
30423,
83,
6616,
450,
8541,
398,
870,
2071,
83,
21222,
221,
19752,
1165,
83,
4366,
83,
2924,
450,
334,
3724,
12,
7117,
52,
11750,
14,
16405,
1062,
892,
2354,
9,
199,
199,
318,
8465,
368,
52,
11750,
8,
4128,
12,
1347,
12526,
12,
307,
11750,
5307,
1296,
12,
1678,
3425,
2354,
275,
715,
12,
2049,
2256,
275,
756,
12,
7289,
13959,
275,
756,
12,
1245,
275,
488,
12,
2049,
511,
275,
756,
12,
2615,
14244,
261,
275,
756,
12,
3686,
8930,
13192,
275,
756,
12,
2049,
5835,
38,
13579,
275,
756,
304,
272,
1890,
275,
1448,
695,
3041,
8,
4128,
9,
272,
20416,
275,
1890,
14,
362,
497,
1712,
342,
339,
1347,
12526,
275,
5459,
14,
3353,
7671,
8,
1375,
12526,
9,
272,
340,
440,
1228,
8,
1375,
12526,
12,
5459,
14,
12526,
304,
267,
746,
2552,
14,
9123,
360,
6612,
4165,
2615,
1015,
2071,
83,
2,
370,
7289,
370,
446,
1471,
4165,
1347,
5246,
7,
450,
1347,
12526,
9,
339,
307,
11750,
28834,
275,
359,
21206,
14,
1122,
52,
11750,
5307,
8,
88,
9,
367,
671,
315,
307,
11750,
5307,
1296,
61,
339,
3931,
28834,
275,
359,
671,
59,
16,
61,
367,
671,
315,
307,
11750,
28834,
2432,
340,
10871,
315,
671,
59,
16,
61,
436,
671,
59,
16,
1055,
1294,
24050,
17,
61,
1137,
283,
1365,
418,
272,
340,
3931,
28834,
26,
267,
746,
2552,
14,
9123,
360,
6612,
7289,
7323,
26,
450,
83,
7,
450,
1656,
1987,
904,
8,
3173,
28834,
430,
2378,
22621,
2310,
1378,
21222,
275,
20416,
14,
1623,
52,
293,
2310,
8,
4128,
14,
3174,
4314,
2042,
12,
2511,
307,
11750,
28834,
12,
4810,
14,
6081,
12,
2511,
5835,
38,
13579,
275,
5835,
38,
13579,
9,
272,
22621,
2310,
1378,
21222,
275,
769,
8,
409,
8,
17691,
14,
4429,
2031,
1374,
2310,
1378,
21222,
14,
13012,
16890,
339,
340,
440,
1890,
14,
4128,
14,
10243,
26,
267,
3233,
275,
1890,
63,
11948,
14,
21222,
2806,
8,
1258,
14,
4128,
12,
1245,
9,
272,
587,
26,
267,
3233,
275,
13484,
14,
21222,
2806,
342,
339,
5849,
12,
7117,
275,
1890,
14,
981,
21222,
4001,
1084,
8,
1375,
12526,
12,
22621,
2310,
1378,
21222,
12,
5644,
1678,
3425,
2354,
29,
873,
3425,
2354,
12,
5644,
2256,
5903,
29,
815,
12,
3233,
29,
3058,
12,
5644,
2615,
14244,
261,
29,
2861,
14244,
261,
12,
5644,
7289,
13959,
29,
6311,
13959,
9,
272,
340,
440,
5849,
26,
267,
372,
272,
372,
485,
8192,
21222,
8,
1258,
12,
4810,
12,
7117,
12,
3233,
12,
2256,
29,
815,
12,
717,
511,
29,
396,
12,
3686,
8930,
13192,
29,
4247,
8930,
13192,
9,
199,
199,
318,
485,
3916,
4314,
2844,
12526,
8,
18842,
2848,
12,
1978,
304,
272,
862,
26,
267,
340,
440,
32375,
2848,
26,
288,
372,
488,
267,
340,
32375,
2848,
59,
16,
61,
508,
20549,
288,
373,
275,
5459,
14,
3353,
7671,
8,
18842,
2848,
9,
288,
340,
1228,
8,
86,
12,
5459,
14,
12526,
304,
355,
372,
373,
288,
327,
6601,
5382,
781,
4293,
221,
30133,
642,
10588,
340,
2399,
2997,
14,
288,
746,
2552,
14,
9123,
360,
6612,
4165,
1015,
370,
10016,
7,
2511,
283,
446,
1471,
4165,
5246,
503,
1768,
358,
267,
340,
440,
1978,
26,
288,
372,
5459,
14,
4314,
8,
18842,
2848,
9,
7318,
1591,
985,
275,
1978,
14,
362,
4965,
342,
267,
536,
7643,
275,
1978,
14,
362,
8814,
342,
267,
1947,
275,
1978,
14,
4694,
398,
340,
32375,
2848,
59,
16,
61,
508,
7596,
356,
288,
32375,
2848,
275,
1543,
83,
19437,
83,
5,
83,
7,
450,
334,
1102,
985,
12,
536,
7643,
12,
32375,
2848,
9,
267,
916,
32375,
2848,
59,
16,
61,
508,
10267,
356,
288,
32375,
2848,
275,
1543,
83,
5,
83,
7,
450,
334,
1102,
985,
12,
32375,
2848,
9,
267,
916,
32375,
2848,
1988,
17,
61,
508,
10267,
356,
288,
32375,
2848,
275,
1543,
83,
5,
83,
2689,
83,
7,
450,
334,
18842,
2848,
12,
536,
7643,
12,
1947,
9,
267,
372,
5459,
14,
4314,
8,
18842,
2848,
9,
272,
871,
2186,
12,
1499,
26,
267,
746,
2552,
14,
9123,
360,
547,
6057,
450,
82,
26,
450,
83,
7,
450,
334,
18842,
2848,
12,
1499,
430,
199,
199,
318,
10016,
52,
293,
2310,
8,
4128,
12,
307,
11750,
28834,
12,
1347
] |
[
199,
3,
1898,
334,
67,
9,
26124,
1010,
25585,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
421,
199,
646,
7975,
199,
199,
504,
406,
695,
492,
13484,
199,
504,
406,
695,
492,
2552,
199,
504,
406,
695,
492,
5459,
199,
504,
406,
695,
14,
388,
695,
1258,
492,
1448,
695,
3041,
12,
21206,
199,
504,
406,
695,
14,
388,
695,
1258,
492,
13484,
465,
1890,
63,
11948,
421,
199,
318,
2929,
21222,
6694,
8,
1259,
304,
272,
4363,
275,
283,
257,
283,
272,
347,
485,
3191,
52,
11750,
985,
1197,
8,
88,
304,
267,
536,
275,
671,
14,
16405,
342,
267,
372,
334,
1397,
536,
14,
4130,
6176,
1365,
659,
671,
14,
362,
4665,
16739,
1062,
536,
9,
272,
7117,
52,
293,
2310,
275,
3355,
8,
1259,
14,
1661,
4665,
52,
11750,
1296,
1062,
790,
3699,
3191,
52,
11750,
985,
1197,
9,
339,
367,
7117,
52,
11750,
315,
7117,
52,
293,
2310,
26,
267,
892,
2354,
275,
620,
8,
1259,
52,
11750,
14,
362,
4665,
3353,
1012,
267,
8541,
275,
7117,
52,
11750,
14,
362,
4665,
16739,
342,
267,
340,
440,
8541,
14,
374,
4699,
837,
288,
892,
2354,
847,
30423,
83,
6616,
450,
8541,
398,
870,
2071,
83,
21222,
221,
19752,
1165,
83,
4366,
83,
2924,
450,
334,
3724,
12,
7117,
52,
11750,
14,
16405,
1062,
892,
2354,
9,
199,
199,
318,
8465,
368,
52,
11750,
8,
4128,
12,
1347,
12526,
12,
307,
11750,
5307,
1296,
12,
1678,
3425,
2354,
275,
715,
12,
2049,
2256,
275,
756,
12,
7289,
13959,
275,
756,
12,
1245,
275,
488,
12,
2049,
511,
275,
756,
12,
2615,
14244,
261,
275,
756,
12,
3686,
8930,
13192,
275,
756,
12,
2049,
5835,
38,
13579,
275,
756,
304,
272,
1890,
275,
1448,
695,
3041,
8,
4128,
9,
272,
20416,
275,
1890,
14,
362,
497,
1712,
342,
339,
1347,
12526,
275,
5459,
14,
3353,
7671,
8,
1375,
12526,
9,
272,
340,
440,
1228,
8,
1375,
12526,
12,
5459,
14,
12526,
304,
267,
746,
2552,
14,
9123,
360,
6612,
4165,
2615,
1015,
2071,
83,
2,
370,
7289,
370,
446,
1471,
4165,
1347,
5246,
7,
450,
1347,
12526,
9,
339,
307,
11750,
28834,
275,
359,
21206,
14,
1122,
52,
11750,
5307,
8,
88,
9,
367,
671,
315,
307,
11750,
5307,
1296,
61,
339,
3931,
28834,
275,
359,
671,
59,
16,
61,
367,
671,
315,
307,
11750,
28834,
2432,
340,
10871,
315,
671,
59,
16,
61,
436,
671,
59,
16,
1055,
1294,
24050,
17,
61,
1137,
283,
1365,
418,
272,
340,
3931,
28834,
26,
267,
746,
2552,
14,
9123,
360,
6612,
7289,
7323,
26,
450,
83,
7,
450,
1656,
1987,
904,
8,
3173,
28834,
430,
2378,
22621,
2310,
1378,
21222,
275,
20416,
14,
1623,
52,
293,
2310,
8,
4128,
14,
3174,
4314,
2042,
12,
2511,
307,
11750,
28834,
12,
4810,
14,
6081,
12,
2511,
5835,
38,
13579,
275,
5835,
38,
13579,
9,
272,
22621,
2310,
1378,
21222,
275,
769,
8,
409,
8,
17691,
14,
4429,
2031,
1374,
2310,
1378,
21222,
14,
13012,
16890,
339,
340,
440,
1890,
14,
4128,
14,
10243,
26,
267,
3233,
275,
1890,
63,
11948,
14,
21222,
2806,
8,
1258,
14,
4128,
12,
1245,
9,
272,
587,
26,
267,
3233,
275,
13484,
14,
21222,
2806,
342,
339,
5849,
12,
7117,
275,
1890,
14,
981,
21222,
4001,
1084,
8,
1375,
12526,
12,
22621,
2310,
1378,
21222,
12,
5644,
1678,
3425,
2354,
29,
873,
3425,
2354,
12,
5644,
2256,
5903,
29,
815,
12,
3233,
29,
3058,
12,
5644,
2615,
14244,
261,
29,
2861,
14244,
261,
12,
5644,
7289,
13959,
29,
6311,
13959,
9,
272,
340,
440,
5849,
26,
267,
372,
272,
372,
485,
8192,
21222,
8,
1258,
12,
4810,
12,
7117,
12,
3233,
12,
2256,
29,
815,
12,
717,
511,
29,
396,
12,
3686,
8930,
13192,
29,
4247,
8930,
13192,
9,
199,
199,
318,
485,
3916,
4314,
2844,
12526,
8,
18842,
2848,
12,
1978,
304,
272,
862,
26,
267,
340,
440,
32375,
2848,
26,
288,
372,
488,
267,
340,
32375,
2848,
59,
16,
61,
508,
20549,
288,
373,
275,
5459,
14,
3353,
7671,
8,
18842,
2848,
9,
288,
340,
1228,
8,
86,
12,
5459,
14,
12526,
304,
355,
372,
373,
288,
327,
6601,
5382,
781,
4293,
221,
30133,
642,
10588,
340,
2399,
2997,
14,
288,
746,
2552,
14,
9123,
360,
6612,
4165,
1015,
370,
10016,
7,
2511,
283,
446,
1471,
4165,
5246,
503,
1768,
358,
267,
340,
440,
1978,
26,
288,
372,
5459,
14,
4314,
8,
18842,
2848,
9,
7318,
1591,
985,
275,
1978,
14,
362,
4965,
342,
267,
536,
7643,
275,
1978,
14,
362,
8814,
342,
267,
1947,
275,
1978,
14,
4694,
398,
340,
32375,
2848,
59,
16,
61,
508,
7596,
356,
288,
32375,
2848,
275,
1543,
83,
19437,
83,
5,
83,
7,
450,
334,
1102,
985,
12,
536,
7643,
12,
32375,
2848,
9,
267,
916,
32375,
2848,
59,
16,
61,
508,
10267,
356,
288,
32375,
2848,
275,
1543,
83,
5,
83,
7,
450,
334,
1102,
985,
12,
32375,
2848,
9,
267,
916,
32375,
2848,
1988,
17,
61,
508,
10267,
356,
288,
32375,
2848,
275,
1543,
83,
5,
83,
2689,
83,
7,
450,
334,
18842,
2848,
12,
536,
7643,
12,
1947,
9,
267,
372,
5459,
14,
4314,
8,
18842,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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
] |
SDM-OS/playlist
|
cherrymusicserver/database/__init__.py
|
1
|
5561
|
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# CherryMusic - a standalone music server
# Copyright (c) 2012 Tom Wallroth & Tilman Boerner
#
# Project page:
# http://fomori.org/cherrymusic/
# Sources on github:
# http://github.com/devsnd/cherrymusic/
#
# CherryMusic is based on
# jPlayer (GPL/MIT license) http://www.jplayer.org/
# CherryPy (BSD license) http://www.cherrypy.org/
#
# licensed under GNU GPL version 3 (or later)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
"""CherryMusic database definition, versioning and control.
To support schema changes that are not backward-compatible, databases can be
versioned.
"""
import itertools
from cherrymusicserver import log
from cherrymusicserver.database import defs
from cherrymusicserver.database import sql
def require(dbname, version):
""" Raise an AssertionError if the database does not exist or has the wrong
version.
"""
if not dbname:
raise ValueError('dbname must not be empty or None')
isversion = MultiUpdater.checkversion(dbname)
assert isversion == version, (
'{0!r}: bad version: {1!r} (want: {2!r})'.format(
dbname, isversion, version))
def ensure_current_version(dbname=None, autoconsent=False, consentcallback=None):
'''Make sure all defined databases exist and are up to date.
Will connect to all these databases and try to update their layout, if
necessary, possibly asking the user for consent.
dbname : str
When given, only make sure of the database with that name.
autoconsent : bool
When ``True``, don't ask for consent, ever.
consentcallback: callable
Called when an update requires user consent; if the return value
does not evaluate to ``True``, abort don't run any updates and
return ``False``. If no callback is given or autoconsent == True,
the value of autoconsent will be used to decide if the update
should run.
Returns : bool
``True`` if requirements are met.
'''
if autoconsent or consentcallback is None:
consentcallback = lambda _: autoconsent
with MultiUpdater(dbname) as update:
if update.needed:
if update.requires_consent and not consentcallback(update.prompts):
return False
log.w("Database schema update; don't turn off the program!")
update.run()
log.i('Database schema update complete.')
return True
def resetdb(dbname):
'''Delete all content and defined data structures from a database.
Raises:
ValueError : If dbname is ``None`` or empty, or not a defined database
name.
'''
if not dbname:
raise ValueError('dbname must not be empty or None')
with MultiUpdater(dbname) as updater:
updater.reset()
class MultiUpdater(object):
'''Manage the state of multiple databases at once.
defs : dict
Definitions of all databases to manage.
connector : :class:`.connect.AbstractConnector`
For connecting to the databases.
'''
def __init__(self, dbname=None):
if dbname is None:
dbdefs = defs.getall()
self.updaters = tuple(sql.Updater(k, dbdefs[k]) for k in dbdefs)
else:
self.updaters = (sql.Updater(dbname, defs.get(dbname)),)
def __iter__(self):
return iter(self.updaters)
def __enter__(self):
for updater in self:
updater._lock()
return self
def __exit__(self, exctype, exception, traceback):
for updater in self:
updater._unlock()
@property
def needed(self):
"""``True`` if any database needs updating.
See :meth:`.sql.Updater.needed`.
"""
for updater in self:
if updater.needed:
return True
return False
@property
def requires_consent(self):
"""``True`` if any database update needs user consent.
See :meth:`.sql.Updater.requires_consent`.
"""
for updater in self:
if updater.requires_consent:
return True
return False
@property
def prompts(self):
"""An iterable of string prompts for updates that require consent."""
return itertools.chain(*(updater.prompts for updater in self))
def run(self):
"""Update all databases with out of date versions.
See :meth:`.sql.Updater.run`.
"""
for updater in self:
if updater.needed:
updater.run()
def reset(self):
"""Delete content and data structures of all included databases.
See :meth:`.sql.Updater.reset`.
"""
for updater in self:
updater.reset()
@classmethod
def checkversion(self, dbname):
"""Return the effective version of a database."""
with sql.Updater(dbname, defs.get(dbname)) as updater:
return updater._version
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
30992,
651,
29869,
446,
282,
18042,
30891,
1654,
199,
3,
1898,
334,
67,
9,
6029,
21644,
644,
452,
293,
273,
1253,
377,
382,
1237,
5088,
281,
1372,
199,
3,
199,
3,
7290,
2034,
26,
199,
3,
257,
1455,
921,
545,
12416,
73,
14,
1308,
15,
7641,
651,
20544,
15,
199,
3,
5800,
83,
641,
12869,
26,
199,
3,
257,
1455,
921,
5031,
14,
957,
15,
18804,
977,
15,
7641,
651,
20544,
15,
199,
3,
199,
3,
30992,
651,
29869,
365,
4079,
641,
199,
3,
257,
1335,
10921,
334,
12006,
15,
13965,
4190,
9,
1455,
921,
1544,
14,
74,
6147,
14,
1308,
15,
199,
3,
257,
30992,
27794,
334,
15400,
4190,
9,
1455,
921,
1544,
14,
23438,
14,
1308,
15,
199,
3,
199,
3,
18233,
1334,
1664,
14629,
1015,
650,
334,
269,
2945,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
199,
3,
199,
624,
1049,
281,
651,
29869,
3050,
5492,
12,
1015,
316,
436,
3304,
14,
199,
199,
1378,
2291,
4177,
4493,
626,
787,
440,
13388,
13,
6490,
12,
16219,
883,
506,
199,
24155,
14,
199,
624,
199,
199,
646,
7975,
199,
199,
504,
12907,
651,
20544,
1000,
492,
943,
199,
504,
12907,
651,
20544,
1000,
14,
4659,
492,
22603,
199,
504,
12907,
651,
20544,
1000,
14,
4659,
492,
3875,
421,
199,
318,
4409,
8,
13238,
12,
1015,
304,
272,
408,
14771,
376,
9070,
340,
314,
3050,
1630,
440,
2187,
503,
965,
314,
6835,
267,
1015,
14,
272,
408,
272,
340,
440,
21842,
26,
267,
746,
1722,
360,
13238,
1471,
440,
506,
2701,
503,
488,
358,
272,
365,
1023,
275,
6879,
4152,
82,
14,
1074,
1023,
8,
13238,
9,
272,
702,
365,
1023,
508,
1015,
12,
334,
267,
5041,
16,
1,
82,
9160,
4875,
1015,
26,
469,
17,
1,
82,
93,
334,
7051,
26,
469,
18,
1,
82,
25885,
908,
8,
288,
21842,
12,
365,
1023,
12,
1015,
430,
421,
199,
318,
4868,
63,
1818,
63,
1023,
8,
13238,
29,
403,
12,
2599,
388,
1150,
29,
797,
12,
406,
1150,
3058,
29,
403,
304,
272,
1449,
5483,
3238,
1006,
3247,
16219,
2187,
436,
787,
1536,
370,
1434,
14,
339,
12823,
4907,
370,
1006,
3520,
16219,
436,
862,
370,
1678,
3932,
7054,
12,
340,
272,
5784,
12,
12570,
7198,
316,
314,
922,
367,
406,
1150,
14,
339,
21842,
520,
620,
267,
3979,
1627,
12,
1454,
1852,
3238,
402,
314,
3050,
543,
626,
536,
14,
272,
2599,
388,
1150,
520,
2155,
267,
3979,
1124,
549,
4542,
2793,
1133,
7198,
367,
406,
1150,
12,
14433,
14,
272,
406,
1150,
3058,
26,
4550,
267,
12295,
1380,
376,
1678,
5074,
922,
406,
1150,
27,
340,
314,
372,
574,
267,
1630,
440,
9352,
370,
1124,
549,
4542,
12004,
2793,
1133,
1255,
1263,
7029,
436,
267,
372,
1124,
797,
4345,
982,
949,
3233,
365,
1627,
503,
2599,
388,
1150,
508,
715,
12,
267,
314,
574,
402,
2599,
388,
1150,
911,
506,
1202,
370,
19822,
340,
314,
1678,
267,
1077,
1255,
14,
272,
1803,
520,
2155,
267,
1124,
549,
1040,
340,
9760,
787,
7647,
14,
272,
1449,
272,
340,
2599,
388,
1150,
503,
406,
1150,
3058,
365,
488,
26,
267,
406,
1150,
3058,
275,
2400,
24700,
2599,
388,
1150,
272,
543,
6879,
4152,
82,
8,
13238,
9,
465,
1678,
26,
267,
340,
1678,
14,
11368,
26,
288,
340,
1678,
14,
6537,
63,
388,
1150,
436,
440,
406,
1150,
3058,
8,
873,
14,
496,
311,
1086,
304,
355,
372,
756,
288,
943,
14,
87,
480,
7243,
4177,
1678,
27,
2793,
1133,
7485,
2331,
314,
2240,
9124,
288,
1678,
14,
1065,
342,
288,
943,
14,
73,
360,
7243,
4177,
1678,
4890,
2659,
272,
372,
715,
421,
199,
318,
5305,
697,
8,
13238,
304,
272,
1449,
5392,
1006,
1564,
436,
3247,
666,
13955,
687,
282,
3050,
14,
339,
6218,
26,
267,
1722,
520,
982,
21842,
365,
1124,
403,
1040,
503,
2701,
12,
503,
440,
282,
3247,
3050,
267,
536,
14,
272,
1449,
272,
340,
440,
21842,
26,
267,
746,
1722,
360,
13238,
1471,
440,
506,
2701,
503,
488,
358,
272,
543,
6879,
4152,
82,
8,
13238,
9,
465,
1678,
82,
26,
267,
1678,
82,
14,
3958,
342,
421,
199,
533,
6879,
4152,
82,
8,
785,
304,
272,
1449,
20588,
314,
1174,
402,
3663,
16219,
737,
5403,
14,
339,
22603,
520,
1211,
267,
22659,
852,
402,
1006,
16219,
370,
9635,
14,
272,
13252,
520,
520,
533,
5026,
2242,
14,
8458,
20476,
64,
267,
2104,
18170,
370,
314,
16219,
14,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
21842,
29,
403,
304,
267,
340,
21842,
365,
488,
26,
288,
1592,
8710,
275,
22603,
14,
362,
452,
342,
288,
291,
14,
873,
2393,
275,
2008,
8,
3009,
14,
4152,
82,
8,
75,
12,
1592,
8710,
59,
75,
566,
367,
1022,
315,
1592,
8710,
9,
267,
587,
26,
288,
291,
14,
873,
2393,
275,
334,
3009,
14,
4152,
82,
8,
13238,
12,
22603,
14,
362,
8,
13238,
1826,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
873,
2393,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
367,
1678,
82,
315,
291,
26,
288,
1678,
82,
423,
831,
342,
267,
372,
291,
339,
347,
636,
2224,
721,
277,
12,
444,
3667,
12,
1919,
12,
5190,
304,
267,
367
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
30992,
651,
29869,
446,
282,
18042,
30891,
1654,
199,
3,
1898,
334,
67,
9,
6029,
21644,
644,
452,
293,
273,
1253,
377,
382,
1237,
5088,
281,
1372,
199,
3,
199,
3,
7290,
2034,
26,
199,
3,
257,
1455,
921,
545,
12416,
73,
14,
1308,
15,
7641,
651,
20544,
15,
199,
3,
5800,
83,
641,
12869,
26,
199,
3,
257,
1455,
921,
5031,
14,
957,
15,
18804,
977,
15,
7641,
651,
20544,
15,
199,
3,
199,
3,
30992,
651,
29869,
365,
4079,
641,
199,
3,
257,
1335,
10921,
334,
12006,
15,
13965,
4190,
9,
1455,
921,
1544,
14,
74,
6147,
14,
1308,
15,
199,
3,
257,
30992,
27794,
334,
15400,
4190,
9,
1455,
921,
1544,
14,
23438,
14,
1308,
15,
199,
3,
199,
3,
18233,
1334,
1664,
14629,
1015,
650,
334,
269,
2945,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
199,
3,
199,
624,
1049,
281,
651,
29869,
3050,
5492,
12,
1015,
316,
436,
3304,
14,
199,
199,
1378,
2291,
4177,
4493,
626,
787,
440,
13388,
13,
6490,
12,
16219,
883,
506,
199,
24155,
14,
199,
624,
199,
199,
646,
7975,
199,
199,
504,
12907,
651,
20544,
1000,
492,
943,
199,
504,
12907,
651,
20544,
1000,
14,
4659,
492,
22603,
199,
504,
12907,
651,
20544,
1000,
14,
4659,
492,
3875,
421,
199,
318,
4409,
8,
13238,
12,
1015,
304,
272,
408,
14771,
376,
9070,
340,
314,
3050,
1630,
440,
2187,
503,
965,
314,
6835,
267,
1015,
14,
272,
408,
272,
340,
440,
21842,
26,
267,
746,
1722,
360,
13238,
1471,
440,
506,
2701,
503,
488,
358,
272,
365,
1023,
275,
6879,
4152,
82,
14,
1074,
1023,
8,
13238,
9,
272,
702,
365,
1023,
508,
1015,
12,
334,
267,
5041,
16,
1,
82,
9160,
4875,
1015,
26,
469,
17,
1,
82,
93,
334,
7051,
26,
469,
18,
1,
82,
25885,
908,
8,
288,
21842,
12,
365,
1023,
12,
1015,
430,
421,
199,
318,
4868,
63,
1818,
63,
1023,
8,
13238,
29,
403,
12,
2599,
388,
1150,
29,
797,
12,
406,
1150,
3058,
29,
403,
304,
272,
1449,
5483,
3238,
1006,
3247,
16219,
2187,
436,
787,
1536,
370,
1434,
14,
339,
12823,
4907,
370,
1006,
3520,
16219,
436,
862,
370,
1678,
3932,
7054,
12,
340,
272,
5784,
12,
12570,
7198,
316,
314,
922,
367,
406,
1150,
14,
339,
21842,
520,
620,
267,
3979,
1627,
12,
1454,
1852,
3238,
402,
314,
3050,
543,
626,
536,
14,
272,
2599,
388,
1150,
520,
2155,
267,
3979,
1124,
549,
4542,
2793,
1133,
7198,
367,
406,
1150,
12,
14433,
14,
272,
406,
1150,
3058,
26,
4550,
267,
12295,
1380,
376,
1678,
5074,
922,
406,
1150,
27,
340,
314,
372,
574,
267,
1630,
440,
9352,
370,
1124,
549,
4542,
12004,
2793,
1133,
1255,
1263,
7029,
436,
267,
372,
1124,
797,
4345,
982,
949,
3233,
365,
1627,
503,
2599,
388,
1150,
508,
715,
12,
267,
314,
574,
402,
2599,
388,
1150,
911,
506,
1202,
370,
19822,
340,
314,
1678,
267,
1077,
1255,
14,
272,
1803,
520,
2155,
267,
1124,
549,
1040,
340,
9760,
787,
7647,
14,
272,
1449,
272,
340,
2599,
388,
1150,
503,
406,
1150,
3058,
365,
488,
26,
267,
406,
1150,
3058,
275,
2400,
24700,
2599,
388,
1150,
272,
543,
6879,
4152,
82,
8,
13238,
9,
465,
1678,
26,
267,
340,
1678,
14,
11368,
26,
288,
340,
1678,
14,
6537,
63,
388,
1150,
436,
440,
406,
1150,
3058,
8,
873,
14,
496,
311,
1086,
304,
355,
372,
756,
288,
943,
14,
87,
480,
7243,
4177,
1678,
27,
2793,
1133,
7485,
2331,
314,
2240,
9124,
288,
1678,
14,
1065,
342,
288,
943,
14,
73,
360,
7243,
4177,
1678,
4890,
2659,
272,
372,
715,
421,
199,
318,
5305,
697,
8,
13238,
304,
272,
1449,
5392,
1006,
1564,
436,
3247,
666,
13955,
687,
282,
3050,
14,
339,
6218,
26,
267,
1722,
520,
982,
21842,
365,
1124,
403,
1040,
503,
2701,
12,
503,
440,
282,
3247,
3050,
267,
536,
14,
272,
1449,
272,
340,
440,
21842,
26,
267,
746,
1722,
360,
13238,
1471,
440,
506,
2701,
503,
488,
358,
272,
543,
6879,
4152,
82,
8,
13238,
9,
465,
1678,
82,
26,
267,
1678,
82,
14,
3958,
342,
421,
199,
533,
6879,
4152,
82,
8,
785,
304,
272,
1449,
20588,
314,
1174,
402,
3663,
16219,
737,
5403,
14,
339,
22603,
520,
1211,
267,
22659,
852,
402,
1006,
16219,
370,
9635,
14,
272,
13252,
520,
520,
533,
5026,
2242,
14,
8458,
20476,
64,
267,
2104,
18170,
370,
314,
16219,
14,
272,
1449,
272,
347,
636,
826,
721,
277,
12,
21842,
29,
403,
304,
267,
340,
21842,
365,
488,
26,
288,
1592,
8710,
275,
22603,
14,
362,
452,
342,
288,
291,
14,
873,
2393,
275,
2008,
8,
3009,
14,
4152,
82,
8,
75,
12,
1592,
8710,
59,
75,
566,
367,
1022,
315,
1592,
8710,
9,
267,
587,
26,
288,
291,
14,
873,
2393,
275,
334,
3009,
14,
4152,
82,
8,
13238,
12,
22603,
14,
362,
8,
13238,
1826,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
873,
2393,
9,
339,
347,
636,
4200,
721,
277,
304,
267,
367,
1678,
82,
315,
291,
26,
288,
1678,
82,
423,
831,
342,
267,
372,
291,
339,
347,
636,
2224,
721,
277,
12,
444,
3667,
12,
1919,
12,
5190,
304,
267,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kdwink/intellij-community
|
python/helpers/py2only/docutils/parsers/rst/languages/de.py
|
57
|
3262
|
# $Id: de.py 5174 2007-05-31 00:01:52Z wiemann $
# Authors: Engelbert Gruber <grubert@users.sourceforge.net>;
# Lea Wiemann <LeWiemann@gmail.com>
# Copyright: This module has been placed in the public domain.
# New language mappings are welcome. Before doing a new translation, please
# read <http://docutils.sf.net/docs/howto/i18n.html>. Two files must be
# translated for each language: one in docutils/languages, the other in
# docutils/parsers/rst/languages.
"""
German-language mappings for language-dependent features of
reStructuredText.
"""
__docformat__ = 'reStructuredText'
directives = {
'achtung': 'attention',
'vorsicht': 'caution',
'gefahr': 'danger',
'fehler': 'error',
'hinweis': 'hint',
'wichtig': 'important',
'notiz': 'note',
'tipp': 'tip',
'warnung': 'warning',
'ermahnung': 'admonition',
'kasten': 'sidebar',
'seitenkasten': 'sidebar',
'thema': 'topic',
'zeilen-block': 'line-block',
'parsed-literal (translation required)': 'parsed-literal',
'rubrik': 'rubric',
'epigraph': 'epigraph',
'highlights (translation required)': 'highlights',
'pull-quote (translation required)': 'pull-quote', # kasten too ?
'zusammengesetzt': 'compound',
'verbund': 'compound',
u'container (translation required)': 'container',
#'fragen': 'questions',
'tabelle': 'table',
'csv-tabelle': 'csv-table',
'list-table (translation required)': 'list-table',
'meta': 'meta',
#'imagemap': 'imagemap',
'bild': 'image',
'abbildung': 'figure',
u'unver\xe4ndert': 'raw',
u'roh': 'raw',
u'einf\xfcgen': 'include',
'ersetzung': 'replace',
'ersetzen': 'replace',
'ersetze': 'replace',
'unicode': 'unicode',
'datum': 'date',
'klasse': 'class',
'rolle': 'role',
u'default-role (translation required)': 'default-role',
u'title (translation required)': 'title',
'inhalt': 'contents',
'kapitel-nummerierung': 'sectnum',
'abschnitts-nummerierung': 'sectnum',
u'linkziel-fu\xdfnoten': 'target-notes',
u'header (translation required)': 'header',
u'footer (translation required)': 'footer',
#u'fu\xdfnoten': 'footnotes',
#'zitate': 'citations',
}
"""German name to registered (in directives/__init__.py) directive name
mapping."""
roles = {
u'abk\xfcrzung': 'abbreviation',
'akronym': 'acronym',
'index': 'index',
'tiefgestellt': 'subscript',
'hochgestellt': 'superscript',
'titel-referenz': 'title-reference',
'pep-referenz': 'pep-reference',
'rfc-referenz': 'rfc-reference',
'betonung': 'emphasis',
'fett': 'strong',
u'w\xf6rtlich': 'literal',
'benannte-referenz': 'named-reference',
'unbenannte-referenz': 'anonymous-reference',
u'fu\xdfnoten-referenz': 'footnote-reference',
'zitat-referenz': 'citation-reference',
'ersetzungs-referenz': 'substitution-reference',
'ziel': 'target',
'uri-referenz': 'uri-reference',
u'unver\xe4ndert': 'raw',
u'roh': 'raw',}
"""Mapping of German role names to canonical role names for interpreted text.
"""
|
apache-2.0
|
[
3,
2672,
1304,
26,
477,
14,
647,
959,
9892,
10219,
13,
1717,
13,
2192,
8733,
26,
614,
26,
2528,
58,
336,
1873,
20059,
2672,
199,
3,
6642,
26,
3447,
24920,
12504,
598,
82,
10400,
665,
2587,
10400,
84,
32,
3707,
14,
22943,
14,
846,
30,
27,
199,
3,
3515,
491,
4489,
644,
1873,
20059,
665,
2553,
55,
1873,
20059,
32,
6799,
14,
957,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
3,
7053,
2637,
13546,
787,
336,
14628,
14,
221,
21467,
9689,
282,
892,
7761,
12,
8749,
199,
3,
1586,
665,
1014,
921,
27114,
14,
7646,
14,
846,
15,
4757,
15,
21232,
15,
73,
1085,
78,
14,
1360,
10827,
221,
16853,
1584,
1471,
506,
199,
3,
14598,
367,
1924,
2637,
26,
1373,
315,
18382,
15,
13209,
12,
314,
1163,
315,
199,
3,
18382,
15,
11531,
15,
8332,
15,
13209,
14,
199,
199,
624,
199,
27866,
1237,
13,
3671,
13546,
367,
2637,
13,
7106,
4534,
402,
199,
264,
27486,
1872,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
421,
199,
23216,
275,
469,
489,
283,
1225,
10032,
71,
356,
283,
22393,
297,
489,
283,
14419,
338,
335,
84,
356,
283,
696,
2206,
297,
489,
283,
303,
667,
6271,
356,
283,
68,
12974,
297,
489,
283,
771,
72,
1435,
356,
283,
705,
297,
489,
283,
72,
262,
1129,
374,
356,
283,
6479,
297,
489,
283,
87,
1158,
17277,
356,
283,
19559,
297,
489,
283,
889,
280,
90,
356,
283,
4610,
297,
489,
283,
280,
802,
356,
283,
8996,
297,
489,
283,
4050,
10335,
356,
283,
3764,
297,
489,
283,
281,
391,
6164,
10335,
356,
283,
350,
31722,
297,
489,
283,
75,
305,
724,
356,
283,
27372,
297,
489,
283,
261,
25840,
75,
305,
724,
356,
283,
27372,
297,
489,
283,
24508,
356,
283,
5746,
297,
489,
283,
806,
441,
78,
13,
1457,
356,
283,
604,
13,
1457,
297,
489,
283,
6751,
13,
8939,
334,
6893,
1415,
11862,
283,
6751,
13,
8939,
297,
489,
283,
82,
456,
25844,
356,
283,
21586,
297,
489,
283,
1545,
528,
3255,
356,
283,
1545,
528,
3255,
297,
489,
283,
14337,
83,
334,
6893,
1415,
11862,
283,
14337,
83,
297,
489,
283,
9302,
13,
3513,
334,
6893,
1415,
11862,
283,
9302,
13,
3513,
297,
327,
1022,
305,
724,
4634,
5805,
489,
283,
90,
527,
455,
1410,
303,
409,
90,
84,
356,
283,
15278,
297,
489,
283,
17050,
725,
356,
283,
15278,
297,
489,
399,
7,
3600,
334,
6893,
1415,
11862,
283,
3600,
297,
489,
17384,
21844,
2268,
356,
283,
16069,
297,
489,
283,
84,
902,
274,
356,
283,
1224,
297,
489,
283,
4737,
13,
84,
902,
274,
356,
283,
4737,
13,
1224,
297,
489,
283,
513,
13,
1224,
334,
6893,
1415,
11862,
283,
513,
13,
1224,
297,
489,
283,
2024,
356,
283,
2024,
297,
489,
17384,
1569,
1130,
356,
283,
1569,
1130,
297,
489,
283,
66,
668,
356,
283,
1569,
297,
489,
283,
12198,
668,
10335,
356,
283,
8941,
297,
489,
399,
7,
324,
422,
60,
1845,
20,
78,
424,
84,
356,
283,
1773,
297,
489,
399,
7,
293,
72,
356,
283,
1773,
297,
489,
399,
7,
69,
4904,
60,
10347,
2268,
356,
283,
2613,
297,
489,
283,
281,
409,
90,
10335,
356,
283,
1814,
297,
489,
283,
281,
409,
5193,
356,
283,
1814,
297,
489,
283,
281,
409,
806,
356,
283,
1814,
297,
489,
283,
2975,
356,
283,
2975,
297,
489,
283,
18945,
356,
283,
602,
297,
489,
283,
9503,
305,
261,
356,
283,
533,
297,
489,
283,
8459,
274,
356,
283,
3756,
297,
489,
399,
5121,
69,
1879,
13,
3756,
334,
6893,
1415,
11862,
283,
885,
13,
3756,
297,
489,
399,
1133,
5776,
334,
6893,
1415,
11862,
283,
1213,
297,
489,
283,
17695,
4478,
356,
283,
4407,
297,
489,
283,
75,
439,
1175,
76,
13,
1507,
278,
10742,
10335,
356,
283,
8519,
1507,
297,
489,
283,
2101,
11019,
390,
1086,
13,
1507,
278,
10742,
10335,
356,
283,
8519,
1507,
297,
489,
399,
7,
1073,
90,
14769,
13,
13499,
60,
10418,
889,
724,
356,
283,
1375,
13,
5983,
297,
489,
399,
7,
1291,
334,
6893,
1415,
11862,
283,
1291,
297,
489,
399,
7,
12781,
334,
6893,
1415,
11862,
283,
12781,
297,
489,
327,
85,
7,
13499,
60,
10418,
889,
724,
356,
283,
11407,
5983,
297,
489,
17384,
90,
390,
323,
356,
283,
14422,
1298,
297,
489,
789,
199,
624,
27866,
1237,
536,
370,
7264,
334,
262,
13502,
22128,
826,
4343,
647,
9,
13613,
536,
199,
4745,
1041,
199,
199,
8050,
275,
469,
489,
399,
7,
371,
75,
60,
1949,
1556,
90,
10335,
356,
283,
371,
30369,
297,
489,
283,
1151,
2641,
12828,
356,
283,
645,
2641,
12828,
297,
489,
283,
1080,
356,
283,
1080,
297,
489,
283,
280,
2829,
303,
1597,
914,
84,
356,
283,
30907,
297,
489,
283,
526,
335,
303,
1597,
914,
84,
356,
283,
4792,
1579,
297,
489,
283,
280,
14146,
13,
264,
1485,
90,
356,
283,
1213,
13,
4443,
297,
489,
283,
12636,
13,
264,
1485,
90,
356,
283,
12636,
13,
4443,
297,
489,
283,
8973,
13,
264,
1485,
90,
356,
283,
8973,
13,
4443,
297,
489,
283,
9549,
265,
10335,
356,
283,
28907,
297,
489,
283,
70,
386,
84,
356,
283,
9370,
297,
489,
399,
7,
87,
60,
1949,
22,
2591,
317,
335,
356,
283,
8939,
297,
489,
283,
18486,
1189,
266,
13,
264,
1485,
90,
356,
283,
4579,
13,
4443,
297,
489,
283,
324,
18486,
1189,
266,
13,
264,
1485,
90,
356,
283,
12628,
13,
4443,
297,
489,
399,
7,
13499,
60,
10418,
889,
724,
13,
264,
1485,
90,
356,
283,
19589,
13,
4443,
297,
489,
283,
90,
390,
292,
13,
264,
1485,
90,
356,
283,
6210,
13,
4443,
297,
489,
283,
281,
409,
90,
324,
458,
13,
264,
1485,
90,
356,
283,
30809,
13,
4443,
297,
489,
283,
90,
14769,
356,
283,
1375,
297,
489,
283,
2302,
13,
264,
1485,
90,
356,
283,
2302,
13,
4443,
297,
489,
399,
7,
324,
422,
60,
1845,
20,
78,
424,
84,
356,
283,
1773,
297,
489,
399,
7,
293,
72,
356,
283,
1773,
297,
93,
199,
624,
7674,
402,
22261,
1237,
4719,
1561,
370,
11358,
4719,
1561,
367,
11922,
1318,
14,
199
] |
[
2672,
1304,
26,
477,
14,
647,
959,
9892,
10219,
13,
1717,
13,
2192,
8733,
26,
614,
26,
2528,
58,
336,
1873,
20059,
2672,
199,
3,
6642,
26,
3447,
24920,
12504,
598,
82,
10400,
665,
2587,
10400,
84,
32,
3707,
14,
22943,
14,
846,
30,
27,
199,
3,
3515,
491,
4489,
644,
1873,
20059,
665,
2553,
55,
1873,
20059,
32,
6799,
14,
957,
30,
199,
3,
1898,
26,
961,
859,
965,
2757,
15090,
315,
314,
4575,
2881,
14,
199,
199,
3,
7053,
2637,
13546,
787,
336,
14628,
14,
221,
21467,
9689,
282,
892,
7761,
12,
8749,
199,
3,
1586,
665,
1014,
921,
27114,
14,
7646,
14,
846,
15,
4757,
15,
21232,
15,
73,
1085,
78,
14,
1360,
10827,
221,
16853,
1584,
1471,
506,
199,
3,
14598,
367,
1924,
2637,
26,
1373,
315,
18382,
15,
13209,
12,
314,
1163,
315,
199,
3,
18382,
15,
11531,
15,
8332,
15,
13209,
14,
199,
199,
624,
199,
27866,
1237,
13,
3671,
13546,
367,
2637,
13,
7106,
4534,
402,
199,
264,
27486,
1872,
14,
199,
624,
199,
199,
363,
21841,
363,
275,
283,
264,
27486,
1872,
7,
421,
199,
23216,
275,
469,
489,
283,
1225,
10032,
71,
356,
283,
22393,
297,
489,
283,
14419,
338,
335,
84,
356,
283,
696,
2206,
297,
489,
283,
303,
667,
6271,
356,
283,
68,
12974,
297,
489,
283,
771,
72,
1435,
356,
283,
705,
297,
489,
283,
72,
262,
1129,
374,
356,
283,
6479,
297,
489,
283,
87,
1158,
17277,
356,
283,
19559,
297,
489,
283,
889,
280,
90,
356,
283,
4610,
297,
489,
283,
280,
802,
356,
283,
8996,
297,
489,
283,
4050,
10335,
356,
283,
3764,
297,
489,
283,
281,
391,
6164,
10335,
356,
283,
350,
31722,
297,
489,
283,
75,
305,
724,
356,
283,
27372,
297,
489,
283,
261,
25840,
75,
305,
724,
356,
283,
27372,
297,
489,
283,
24508,
356,
283,
5746,
297,
489,
283,
806,
441,
78,
13,
1457,
356,
283,
604,
13,
1457,
297,
489,
283,
6751,
13,
8939,
334,
6893,
1415,
11862,
283,
6751,
13,
8939,
297,
489,
283,
82,
456,
25844,
356,
283,
21586,
297,
489,
283,
1545,
528,
3255,
356,
283,
1545,
528,
3255,
297,
489,
283,
14337,
83,
334,
6893,
1415,
11862,
283,
14337,
83,
297,
489,
283,
9302,
13,
3513,
334,
6893,
1415,
11862,
283,
9302,
13,
3513,
297,
327,
1022,
305,
724,
4634,
5805,
489,
283,
90,
527,
455,
1410,
303,
409,
90,
84,
356,
283,
15278,
297,
489,
283,
17050,
725,
356,
283,
15278,
297,
489,
399,
7,
3600,
334,
6893,
1415,
11862,
283,
3600,
297,
489,
17384,
21844,
2268,
356,
283,
16069,
297,
489,
283,
84,
902,
274,
356,
283,
1224,
297,
489,
283,
4737,
13,
84,
902,
274,
356,
283,
4737,
13,
1224,
297,
489,
283,
513,
13,
1224,
334,
6893,
1415,
11862,
283,
513,
13,
1224,
297,
489,
283,
2024,
356,
283,
2024,
297,
489,
17384,
1569,
1130,
356,
283,
1569,
1130,
297,
489,
283,
66,
668,
356,
283,
1569,
297,
489,
283,
12198,
668,
10335,
356,
283,
8941,
297,
489,
399,
7,
324,
422,
60,
1845,
20,
78,
424,
84,
356,
283,
1773,
297,
489,
399,
7,
293,
72,
356,
283,
1773,
297,
489,
399,
7,
69,
4904,
60,
10347,
2268,
356,
283,
2613,
297,
489,
283,
281,
409,
90,
10335,
356,
283,
1814,
297,
489,
283,
281,
409,
5193,
356,
283,
1814,
297,
489,
283,
281,
409,
806,
356,
283,
1814,
297,
489,
283,
2975,
356,
283,
2975,
297,
489,
283,
18945,
356,
283,
602,
297,
489,
283,
9503,
305,
261,
356,
283,
533,
297,
489,
283,
8459,
274,
356,
283,
3756,
297,
489,
399,
5121,
69,
1879,
13,
3756,
334,
6893,
1415,
11862,
283,
885,
13,
3756,
297,
489,
399,
1133,
5776,
334,
6893,
1415,
11862,
283,
1213,
297,
489,
283,
17695,
4478,
356,
283,
4407,
297,
489,
283,
75,
439,
1175,
76,
13,
1507,
278,
10742,
10335,
356,
283,
8519,
1507,
297,
489,
283,
2101,
11019,
390,
1086,
13,
1507,
278,
10742,
10335,
356,
283,
8519,
1507,
297,
489,
399,
7,
1073,
90,
14769,
13,
13499,
60,
10418,
889,
724,
356,
283,
1375,
13,
5983,
297,
489,
399,
7,
1291,
334,
6893,
1415,
11862,
283,
1291,
297,
489,
399,
7,
12781,
334,
6893,
1415,
11862,
283,
12781,
297,
489,
327,
85,
7,
13499,
60,
10418,
889,
724,
356,
283,
11407,
5983,
297,
489,
17384,
90,
390,
323,
356,
283,
14422,
1298,
297,
489,
789,
199,
624,
27866,
1237,
536,
370,
7264,
334,
262,
13502,
22128,
826,
4343,
647,
9,
13613,
536,
199,
4745,
1041,
199,
199,
8050,
275,
469,
489,
399,
7,
371,
75,
60,
1949,
1556,
90,
10335,
356,
283,
371,
30369,
297,
489,
283,
1151,
2641,
12828,
356,
283,
645,
2641,
12828,
297,
489,
283,
1080,
356,
283,
1080,
297,
489,
283,
280,
2829,
303,
1597,
914,
84,
356,
283,
30907,
297,
489,
283,
526,
335,
303,
1597,
914,
84,
356,
283,
4792,
1579,
297,
489,
283,
280,
14146,
13,
264,
1485,
90,
356,
283,
1213,
13,
4443,
297,
489,
283,
12636,
13,
264,
1485,
90,
356,
283,
12636,
13,
4443,
297,
489,
283,
8973,
13,
264,
1485,
90,
356,
283,
8973,
13,
4443,
297,
489,
283,
9549,
265,
10335,
356,
283,
28907,
297,
489,
283,
70,
386,
84,
356,
283,
9370,
297,
489,
399,
7,
87,
60,
1949,
22,
2591,
317,
335,
356,
283,
8939,
297,
489,
283,
18486,
1189,
266,
13,
264,
1485,
90,
356,
283,
4579,
13,
4443,
297,
489,
283,
324,
18486,
1189,
266,
13,
264,
1485,
90,
356,
283,
12628,
13,
4443,
297,
489,
399,
7,
13499,
60,
10418,
889,
724,
13,
264,
1485,
90,
356,
283,
19589,
13,
4443,
297,
489,
283,
90,
390,
292,
13,
264,
1485,
90,
356,
283,
6210,
13,
4443,
297,
489,
283,
281,
409,
90,
324,
458,
13,
264,
1485,
90,
356,
283,
30809,
13,
4443,
297,
489,
283,
90,
14769,
356,
283,
1375,
297,
489,
283,
2302,
13,
264,
1485,
90,
356,
283,
2302,
13,
4443,
297,
489,
399,
7,
324,
422,
60,
1845,
20,
78,
424,
84,
356,
283,
1773,
297,
489,
399,
7,
293,
72,
356,
283,
1773,
297,
93,
199,
624,
7674,
402,
22261,
1237,
4719,
1561,
370,
11358,
4719,
1561,
367,
11922,
1318,
14,
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,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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
] |
bigmlcom/bigmler
|
bigmler/options/export.py
|
1
|
2037
|
# -*- coding: utf-8 -*-
#
# Copyright 2017-2021 BigML
#
# 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.
"""Options for BigMLer code export functions
"""
def get_export_options(defaults=None):
"""code export related options
"""
if defaults is None:
defaults = {}
options = {
# ID of the model to generate a local model
'--model': {
'action': 'store',
'dest': 'model',
'default': defaults.get('model', None),
'help': ("ID of the model to generate a local model.")},
# ID of the ensemble to generate the local models in the ensemble
'--ensemble': {
'action': 'store',
'dest': 'ensemble',
'default': defaults.get('ensemble', None),
'help': ("ID of the ensemble to generate the local models in"
" the ensemble.")},
'--language': {
'action': 'store',
'dest': 'language',
'choices': ['python', 'javascript', 'tableau', 'mysql', 'r'],
'default': defaults.get('language', 'javascript'),
'help': ("Language to be used in code generation.")}}
# If a BigML logistic regression is provided, the script will
# use it to generate predictions
# '--logistic-regression': {
# 'action': 'store',
# 'dest': 'logistic_regression',
# 'default': defaults.get('logistic_regression', None),
# 'help': "BigML logistic regression Id."}
return options
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9708,
13,
22150,
13123,
1698,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
421,
199,
624,
4558,
367,
13123,
1698,
281,
1233,
4843,
3423,
199,
199,
624,
199,
199,
318,
664,
63,
3790,
63,
1419,
8,
4322,
29,
403,
304,
272,
408,
600,
4843,
4048,
1511,
339,
408,
339,
340,
4243,
365,
488,
26,
267,
4243,
275,
1052,
339,
1511,
275,
469,
267,
327,
2870,
402,
314,
1402,
370,
3550,
282,
2257,
1402,
267,
2850,
1238,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
1238,
297,
288,
283,
885,
356,
4243,
14,
362,
360,
1238,
297,
488,
395,
288,
283,
3437,
356,
1689,
998,
402,
314,
1402,
370,
3550,
282,
2257,
1402,
2685,
1386,
267,
327,
2870,
402,
314,
19965,
370,
3550,
314,
2257,
1709,
315,
314,
19965,
267,
2850,
15628,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
15628,
297,
288,
283,
885,
356,
4243,
14,
362,
360,
15628,
297,
488,
395,
288,
283,
3437,
356,
1689,
998,
402,
314,
19965,
370,
3550,
314,
2257,
1709,
315,
2,
2151,
298,
314,
19965,
2685,
1386,
267,
2850,
3671,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
3671,
297,
288,
283,
4577,
356,
788,
1548,
297,
283,
9554,
297,
283,
1224,
3844,
297,
283,
8644,
297,
283,
82,
995,
288,
283,
885,
356,
4243,
14,
362,
360,
3671,
297,
283,
9554,
659,
288,
283,
3437,
356,
1689,
8493,
370,
506,
1202,
315,
1233,
10152,
2685,
4863,
398,
327,
982,
282,
13123,
1698,
30360,
10864,
365,
2741,
12,
314,
2884,
911,
267,
327,
675,
652,
370,
3550,
7914,
199,
3,
263,
2850,
23452,
13,
12513,
356,
469,
199,
3,
3698,
283,
1287,
356,
283,
1617,
297,
199,
3,
3698,
283,
2614,
356,
283,
23452,
63,
12513,
297,
199,
3,
3698,
283,
885,
356,
4243,
14,
362,
360,
23452,
63,
12513,
297,
488,
395,
199,
3,
3698,
283,
3437,
356,
298,
7279,
1698,
30360,
10864,
15418,
2122,
93,
339,
372,
1511,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9708,
13,
22150,
13123,
1698,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
421,
199,
624,
4558,
367,
13123,
1698,
281,
1233,
4843,
3423,
199,
199,
624,
199,
199,
318,
664,
63,
3790,
63,
1419,
8,
4322,
29,
403,
304,
272,
408,
600,
4843,
4048,
1511,
339,
408,
339,
340,
4243,
365,
488,
26,
267,
4243,
275,
1052,
339,
1511,
275,
469,
267,
327,
2870,
402,
314,
1402,
370,
3550,
282,
2257,
1402,
267,
2850,
1238,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
1238,
297,
288,
283,
885,
356,
4243,
14,
362,
360,
1238,
297,
488,
395,
288,
283,
3437,
356,
1689,
998,
402,
314,
1402,
370,
3550,
282,
2257,
1402,
2685,
1386,
267,
327,
2870,
402,
314,
19965,
370,
3550,
314,
2257,
1709,
315,
314,
19965,
267,
2850,
15628,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
15628,
297,
288,
283,
885,
356,
4243,
14,
362,
360,
15628,
297,
488,
395,
288,
283,
3437,
356,
1689,
998,
402,
314,
19965,
370,
3550,
314,
2257,
1709,
315,
2,
2151,
298,
314,
19965,
2685,
1386,
267,
2850,
3671,
356,
469,
288,
283,
1287,
356,
283,
1617,
297,
288,
283,
2614,
356,
283,
3671,
297,
288,
283,
4577,
356,
788,
1548,
297,
283,
9554,
297,
283,
1224,
3844,
297,
283,
8644,
297,
283,
82,
995,
288,
283,
885,
356,
4243,
14,
362,
360,
3671,
297,
283,
9554,
659,
288,
283,
3437,
356,
1689,
8493,
370,
506,
1202,
315,
1233,
10152,
2685,
4863,
398,
327,
982,
282,
13123,
1698,
30360,
10864,
365,
2741,
12,
314,
2884,
911,
267,
327,
675,
652,
370,
3550,
7914,
199,
3,
263,
2850,
23452,
13,
12513,
356,
469,
199,
3,
3698,
283,
1287,
356,
283,
1617,
297,
199,
3,
3698,
283,
2614,
356,
283,
23452,
63,
12513,
297,
199,
3,
3698,
283,
885,
356,
4243,
14,
362,
360,
23452,
63,
12513,
297,
488,
395,
199,
3,
3698,
283,
3437,
356,
298,
7279,
1698,
30360,
10864,
15418,
2122,
93,
339,
372,
1511,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
redpath11/phy981_thr
|
projects/proj2/shell_model.py
|
1
|
3917
|
import numpy as np
from decimal import Decimal
import os
from scipy.misc import comb
from numpy import linalg as LA
import itertools
# bitCount() counts the number of bits set (not an optimal function)
def bitCount(int_type):
""" Count bits set in integer """
count = 0
while(int_type):
int_type &= int_type - 1
count += 1
return(count)
# allperms() generates a .jpg file displaying a composite image of all
# the WORST hairstyles from the '80s
#
# actually it generates all possible <Nbits> words as a list of strings
def allperms(Nbits):
result = ["".join(seq) for seq in itertools.product("01", repeat=Nbits)]
return result
def slaterdet(numLevels, numPairs):
# file = open("slater_dets.list", "w")
# file.write("This is my output! You have " + str(numParticles) + " particles! \n")
# This is where you can do your calculation. You can nest the file.write line inside a loop, if you need to
# nLvls=numStates/2
# nPairs=numParticles/2
numSDs=int(round(comb(numLevels, numPairs, exact=False)))
SD = np.zeros([numSDs,numLevels])
ap=allperms(numLevels)
apmax=len(ap)
# loop over generated list of <nLvls>-bit words and select ones with <nPairs> bits set
# i.e. eliminate states that don't have the specified number of pairs
idxSD=0
idxLVL=0
for i in range(apmax):
state=int(ap[i],2)
# if word has right number of pairs
# we add a new SD
if (bitCount(state) == numPairs):
idxLVL=0
for j in range(numLevels):
SD[idxSD][idxLVL]=ap[i][j]
idxLVL+=1
idxSD+=1
# file.close()
return SD
def hamiltonian(numLevels, numPairs, dim_H, G,dE):
# The following lines should give you a NumPy array, where each row corresponds to a Slater determinant
# SDarray = np.genfromtxt('slater_dets.list-sample1')
SDarray = slaterdet(numLevels, numPairs)
b = slaterdet(numLevels, numPairs)
print 'My array of Slater determinants is \n', SDarray
# This next line should let you check that the data was imported correctly
print 'It contains', np.size(SDarray,0), 'Slater determinants constructed from', np.size(SDarray,1), 'single particle states.'
H = np.zeros([dim_H, dim_H])
ne=0
for i in range(dim_H):
for q in range(numLevels):
if SDarray[i][q]==1:
for p in range(numLevels):
if SDarray[i][p]==0:
b[i][q]=0
b[i][p]=1
for j in range(dim_H):
if np.array_equal(SDarray[j],b[i]):
# print "SDarray,b: ", SDarray[j],b[i]
H[i][j]=H[i][j]-G
b[i][p]=0
b[i][q]=1
print(H*G)
for i in range(dim_H):
for j in range(numLevels):
if SDarray[i][j]==1:
ne=ne+(numLevels-j-1)
H[i][i]=H[i][i]+2*ne*dE-G*numPairs
ne=0
print H
return H
if __name__ == '__main__':
Nlevels = int(raw_input('Number of Levels = '))
# Nstates = 2*Nlevels
Npairs = int(raw_input('Number of Pairs = '))
size_H = comb(Nlevels, Npairs, exact=False)
# g=1
dE=1 #0
# h = hamiltonian(Nlevels, Npairs, size_H, g,dE)
# EigValues, EigVectors = LA.eigh(h)
# permute = EigValues.argsort()
# print '\n For g =', g, 'the eigenvalues of the Hamiltonian are \n', EigValues[permute]
# print 'and the corresponding eigenvectors are \n', EigVectors[:,permute], '\n'
for g in np.linspace(-1, 1, num=5):
# slaterdet(Nstates, Nparticles)
# h = hamiltonian(Nstates, Nparticles, size_H, g)
# EigValues, EigVectors = LA.eigh(h)
h = hamiltonian(Nlevels, Npairs, size_H, g,dE)
EigValues, EigVectors = LA.eigh(h)
permute = EigValues.argsort()
print '\n For g =', g, 'the eigenvalues of the Hamiltonian are \n', EigValues[permute]
print 'and the corresponding eigenvectors are \n', EigVectors[:,permute], '\n'
|
apache-2.0
|
[
646,
2680,
465,
980,
221,
199,
504,
6107,
492,
6345,
199,
646,
747,
199,
504,
7026,
14,
9923,
492,
5300,
199,
504,
2680,
492,
16727,
465,
31046,
199,
646,
7975,
199,
199,
3,
4546,
2353,
342,
8242,
314,
1329,
402,
5821,
663,
334,
1397,
376,
22081,
805,
9,
199,
199,
318,
4546,
2353,
8,
442,
63,
466,
304,
272,
408,
14826,
5821,
663,
315,
3000,
408,
272,
2338,
275,
378,
272,
1830,
8,
442,
63,
466,
304,
267,
1109,
63,
466,
18415,
1109,
63,
466,
446,
413,
267,
2338,
847,
413,
272,
372,
8,
835,
9,
199,
199,
3,
1006,
12068,
342,
12821,
282,
1275,
8476,
570,
20589,
282,
19306,
1834,
402,
1006,
199,
3,
314,
29557,
840,
18251,
1472,
1775,
83,
687,
314,
283,
1257,
83,
199,
3,
199,
3,
5965,
652,
12821,
1006,
3962,
665,
46,
5609,
30,
5932,
465,
282,
769,
402,
3326,
199,
199,
318,
1006,
12068,
8,
46,
5609,
304,
199,
198,
1099,
275,
359,
25148,
904,
8,
3610,
9,
367,
5412,
315,
7975,
14,
2558,
480,
614,
401,
11982,
29,
46,
5609,
1874,
199,
198,
1107,
754,
4388,
199,
318,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
304,
199,
3,
198,
493,
275,
1551,
480,
83,
18103,
63,
271,
1086,
14,
513,
401,
298,
87,
531,
199,
3,
198,
493,
14,
952,
480,
2765,
365,
3002,
1072,
1,
2047,
1172,
298,
435,
620,
8,
1507,
14986,
83,
9,
435,
298,
26115,
1,
971,
78,
531,
199,
198,
3,
961,
365,
2382,
1265,
883,
886,
2195,
15232,
14,
2047,
883,
10715,
314,
570,
14,
952,
1004,
6272,
282,
4438,
12,
340,
1265,
1929,
370,
199,
3,
198,
78,
44,
86,
478,
29,
1507,
18010,
15,
18,
199,
3,
198,
78,
12882,
83,
29,
1507,
14986,
83,
15,
18,
421,
198,
1507,
3693,
83,
29,
442,
8,
2363,
8,
6560,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
12,
5835,
29,
797,
1724,
199,
198,
3693,
275,
980,
14,
4250,
779,
1507,
3693,
83,
12,
1507,
4670,
83,
566,
421,
198,
439,
29,
452,
12068,
8,
1507,
4670,
83,
9,
199,
198,
439,
988,
29,
552,
8,
439,
9,
199,
198,
3,
4438,
1806,
4046,
769,
402,
665,
78,
44,
86,
478,
24860,
2075,
5932,
436,
3504,
7869,
543,
665,
78,
12882,
83,
30,
5821,
663,
199,
198,
3,
284,
14,
69,
14,
20714,
323,
6363,
626,
2793,
1133,
1172,
314,
2013,
1329,
402,
6342,
199,
198,
2996,
3693,
29,
16,
199,
198,
2996,
18750,
44,
29,
16,
199,
198,
509,
284,
315,
1425,
8,
439,
988,
304,
507,
198,
929,
29,
442,
8,
439,
59,
73,
467,
18,
9,
507,
198,
3,
340,
4349,
965,
2451,
1329,
402,
6342,
507,
198,
3,
781,
1050,
282,
892,
428,
36,
507,
198,
692,
334,
2075,
2353,
8,
929,
9,
508,
1967,
12882,
83,
304,
686,
198,
2996,
18750,
44,
29,
16,
686,
198,
509,
1335,
315,
1425,
8,
1507,
4670,
83,
304,
1585,
198,
3693,
59,
2996,
3693,
1527,
2996,
18750,
44,
10404,
439,
59,
73,
1527,
74,
61,
1585,
198,
2996,
18750,
44,
10365,
17,
686,
198,
2996,
3693,
10365,
17,
4388,
199,
3,
198,
493,
14,
1600,
342,
199,
198,
1107,
428,
36,
199,
199,
318,
24868,
382,
1860,
5653,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
12,
8134,
63,
40,
12,
598,
12,
68,
37,
304,
199,
198,
3,
710,
2569,
2385,
1077,
8120,
1265,
282,
20602,
1625,
12,
2382,
1924,
1962,
13718,
370,
282,
428,
18103,
4563,
867,
199,
3,
198,
3693,
1144,
275,
980,
14,
2268,
30439,
360,
83,
18103,
63,
271,
1086,
14,
513,
13,
3271,
17,
358,
421,
198,
3693,
1144,
275,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
9,
199,
198,
66,
275,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
9,
199,
198,
1361,
283,
5713,
1625,
402,
428,
18103,
4563,
2285,
365,
971,
78,
297,
428,
36,
1144,
421,
198,
3,
961,
2163,
1004,
1077,
4691,
1265,
1104,
626,
314,
666,
1990,
8439,
6657,
199,
198,
1361,
283,
7940,
3509,
297,
980,
14,
890,
8,
3693,
1144,
12,
16,
395,
283,
51,
18103,
4563,
2285,
14701,
687,
297,
980,
14,
890,
8,
3693,
1144,
12,
17,
395,
283,
4780,
13833,
6363,
3530,
421,
198,
40,
275,
980,
14,
4250,
779,
3572,
63,
40,
12,
8134,
63,
40,
566,
199,
198,
685,
29,
16,
199,
198,
509,
284,
315,
1425,
8,
3572,
63,
40,
304,
288,
367,
1894,
315,
1425,
8,
1507,
4670,
83,
304,
355,
340,
428,
36,
1144,
59,
73,
1527,
81,
19219,
17,
26,
490,
367,
299,
315,
1425,
8,
1507,
4670,
83,
304,
717,
340,
428,
36,
1144,
59,
73,
1527,
80,
19219,
16,
26,
1169,
330,
59,
73,
1527,
81,
10404,
16,
1169,
330,
59,
73,
1527,
80,
10404,
17,
1169,
367,
1335,
315,
1425,
8,
3572,
63,
40,
304,
1816,
340,
980,
14,
1144,
63,
1452,
8,
3693,
1144,
59,
74,
467,
66,
59,
73,
4682,
199,
3,
7542,
259,
870,
298,
3693,
1144,
12,
66,
26,
3872,
428,
36,
1144,
59,
74,
467,
66,
59,
73,
61,
2511,
869,
59,
73,
1527,
74,
10404,
40,
59,
73,
1527,
74,
11285,
39,
1169,
330,
59,
73,
1527,
80,
10404,
16,
1169,
330,
59,
73,
1527,
81,
10404,
17,
267,
870,
8,
40,
10,
39,
9,
398,
367,
284,
315,
1425,
8,
3572,
63,
40,
304,
288,
367,
1335,
315,
1425,
8,
1507,
4670,
83,
304,
355,
340,
428,
36,
1144,
59,
73,
1527,
74,
19219,
17,
26,
490,
1279,
29,
685,
15622,
1507,
4670,
83,
13,
74,
13,
17,
9,
288,
869,
59,
73,
1527,
73,
10404,
40,
59,
73,
1527,
73,
2807,
18,
10,
685,
10,
68,
37,
13,
39,
10,
1507,
12882,
83,
288,
1279,
29,
16,
267,
870,
869,
8299,
198,
1107,
869,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
46,
11402,
275,
1109,
8,
1773,
63,
1210,
360,
3259,
402,
20400,
83,
275,
20005,
199,
3,
198,
46,
4981,
275,
499,
10,
46,
11402,
199,
198,
46,
7322,
275,
1109,
8,
1773,
63,
1210,
360,
3259,
402,
510,
8387,
83,
275,
20005,
199,
198,
890
] |
[
2680,
465,
980,
221,
199,
504,
6107,
492,
6345,
199,
646,
747,
199,
504,
7026,
14,
9923,
492,
5300,
199,
504,
2680,
492,
16727,
465,
31046,
199,
646,
7975,
199,
199,
3,
4546,
2353,
342,
8242,
314,
1329,
402,
5821,
663,
334,
1397,
376,
22081,
805,
9,
199,
199,
318,
4546,
2353,
8,
442,
63,
466,
304,
272,
408,
14826,
5821,
663,
315,
3000,
408,
272,
2338,
275,
378,
272,
1830,
8,
442,
63,
466,
304,
267,
1109,
63,
466,
18415,
1109,
63,
466,
446,
413,
267,
2338,
847,
413,
272,
372,
8,
835,
9,
199,
199,
3,
1006,
12068,
342,
12821,
282,
1275,
8476,
570,
20589,
282,
19306,
1834,
402,
1006,
199,
3,
314,
29557,
840,
18251,
1472,
1775,
83,
687,
314,
283,
1257,
83,
199,
3,
199,
3,
5965,
652,
12821,
1006,
3962,
665,
46,
5609,
30,
5932,
465,
282,
769,
402,
3326,
199,
199,
318,
1006,
12068,
8,
46,
5609,
304,
199,
198,
1099,
275,
359,
25148,
904,
8,
3610,
9,
367,
5412,
315,
7975,
14,
2558,
480,
614,
401,
11982,
29,
46,
5609,
1874,
199,
198,
1107,
754,
4388,
199,
318,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
304,
199,
3,
198,
493,
275,
1551,
480,
83,
18103,
63,
271,
1086,
14,
513,
401,
298,
87,
531,
199,
3,
198,
493,
14,
952,
480,
2765,
365,
3002,
1072,
1,
2047,
1172,
298,
435,
620,
8,
1507,
14986,
83,
9,
435,
298,
26115,
1,
971,
78,
531,
199,
198,
3,
961,
365,
2382,
1265,
883,
886,
2195,
15232,
14,
2047,
883,
10715,
314,
570,
14,
952,
1004,
6272,
282,
4438,
12,
340,
1265,
1929,
370,
199,
3,
198,
78,
44,
86,
478,
29,
1507,
18010,
15,
18,
199,
3,
198,
78,
12882,
83,
29,
1507,
14986,
83,
15,
18,
421,
198,
1507,
3693,
83,
29,
442,
8,
2363,
8,
6560,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
12,
5835,
29,
797,
1724,
199,
198,
3693,
275,
980,
14,
4250,
779,
1507,
3693,
83,
12,
1507,
4670,
83,
566,
421,
198,
439,
29,
452,
12068,
8,
1507,
4670,
83,
9,
199,
198,
439,
988,
29,
552,
8,
439,
9,
199,
198,
3,
4438,
1806,
4046,
769,
402,
665,
78,
44,
86,
478,
24860,
2075,
5932,
436,
3504,
7869,
543,
665,
78,
12882,
83,
30,
5821,
663,
199,
198,
3,
284,
14,
69,
14,
20714,
323,
6363,
626,
2793,
1133,
1172,
314,
2013,
1329,
402,
6342,
199,
198,
2996,
3693,
29,
16,
199,
198,
2996,
18750,
44,
29,
16,
199,
198,
509,
284,
315,
1425,
8,
439,
988,
304,
507,
198,
929,
29,
442,
8,
439,
59,
73,
467,
18,
9,
507,
198,
3,
340,
4349,
965,
2451,
1329,
402,
6342,
507,
198,
3,
781,
1050,
282,
892,
428,
36,
507,
198,
692,
334,
2075,
2353,
8,
929,
9,
508,
1967,
12882,
83,
304,
686,
198,
2996,
18750,
44,
29,
16,
686,
198,
509,
1335,
315,
1425,
8,
1507,
4670,
83,
304,
1585,
198,
3693,
59,
2996,
3693,
1527,
2996,
18750,
44,
10404,
439,
59,
73,
1527,
74,
61,
1585,
198,
2996,
18750,
44,
10365,
17,
686,
198,
2996,
3693,
10365,
17,
4388,
199,
3,
198,
493,
14,
1600,
342,
199,
198,
1107,
428,
36,
199,
199,
318,
24868,
382,
1860,
5653,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
12,
8134,
63,
40,
12,
598,
12,
68,
37,
304,
199,
198,
3,
710,
2569,
2385,
1077,
8120,
1265,
282,
20602,
1625,
12,
2382,
1924,
1962,
13718,
370,
282,
428,
18103,
4563,
867,
199,
3,
198,
3693,
1144,
275,
980,
14,
2268,
30439,
360,
83,
18103,
63,
271,
1086,
14,
513,
13,
3271,
17,
358,
421,
198,
3693,
1144,
275,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
9,
199,
198,
66,
275,
308,
18103,
9886,
8,
1507,
4670,
83,
12,
1967,
12882,
83,
9,
199,
198,
1361,
283,
5713,
1625,
402,
428,
18103,
4563,
2285,
365,
971,
78,
297,
428,
36,
1144,
421,
198,
3,
961,
2163,
1004,
1077,
4691,
1265,
1104,
626,
314,
666,
1990,
8439,
6657,
199,
198,
1361,
283,
7940,
3509,
297,
980,
14,
890,
8,
3693,
1144,
12,
16,
395,
283,
51,
18103,
4563,
2285,
14701,
687,
297,
980,
14,
890,
8,
3693,
1144,
12,
17,
395,
283,
4780,
13833,
6363,
3530,
421,
198,
40,
275,
980,
14,
4250,
779,
3572,
63,
40,
12,
8134,
63,
40,
566,
199,
198,
685,
29,
16,
199,
198,
509,
284,
315,
1425,
8,
3572,
63,
40,
304,
288,
367,
1894,
315,
1425,
8,
1507,
4670,
83,
304,
355,
340,
428,
36,
1144,
59,
73,
1527,
81,
19219,
17,
26,
490,
367,
299,
315,
1425,
8,
1507,
4670,
83,
304,
717,
340,
428,
36,
1144,
59,
73,
1527,
80,
19219,
16,
26,
1169,
330,
59,
73,
1527,
81,
10404,
16,
1169,
330,
59,
73,
1527,
80,
10404,
17,
1169,
367,
1335,
315,
1425,
8,
3572,
63,
40,
304,
1816,
340,
980,
14,
1144,
63,
1452,
8,
3693,
1144,
59,
74,
467,
66,
59,
73,
4682,
199,
3,
7542,
259,
870,
298,
3693,
1144,
12,
66,
26,
3872,
428,
36,
1144,
59,
74,
467,
66,
59,
73,
61,
2511,
869,
59,
73,
1527,
74,
10404,
40,
59,
73,
1527,
74,
11285,
39,
1169,
330,
59,
73,
1527,
80,
10404,
16,
1169,
330,
59,
73,
1527,
81,
10404,
17,
267,
870,
8,
40,
10,
39,
9,
398,
367,
284,
315,
1425,
8,
3572,
63,
40,
304,
288,
367,
1335,
315,
1425,
8,
1507,
4670,
83,
304,
355,
340,
428,
36,
1144,
59,
73,
1527,
74,
19219,
17,
26,
490,
1279,
29,
685,
15622,
1507,
4670,
83,
13,
74,
13,
17,
9,
288,
869,
59,
73,
1527,
73,
10404,
40,
59,
73,
1527,
73,
2807,
18,
10,
685,
10,
68,
37,
13,
39,
10,
1507,
12882,
83,
288,
1279,
29,
16,
267,
870,
869,
8299,
198,
1107,
869,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
46,
11402,
275,
1109,
8,
1773,
63,
1210,
360,
3259,
402,
20400,
83,
275,
20005,
199,
3,
198,
46,
4981,
275,
499,
10,
46,
11402,
199,
198,
46,
7322,
275,
1109,
8,
1773,
63,
1210,
360,
3259,
402,
510,
8387,
83,
275,
20005,
199,
198,
890,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ashhher3/invenio
|
modules/bibformat/lib/elements/bfe_affiliation.py
|
19
|
2664
|
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2006, 2007, 2008, 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.
"""BibFormat element - Prints affiliation
"""
__revision__ = "$Id$"
import cgi
from invenio.config import \
CFG_SITE_URL, CFG_SITE_NAME
from invenio.bibauthority_config import \
CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME
from invenio.bibauthority_engine import \
get_low_level_recIDs_from_control_no
def format_element(bfo):
"""
HTML Affiliation display
"""
affiliations = bfo.fields('909C1', repeatable_subfields_p=True)
out = ""
for affiliation_dict in affiliations:
if 'u' in affiliation_dict:
recIDs = []
affiliation = affiliation_dict['u'][0]
control_nos = affiliation_dict.get('0')
for control_no in control_nos or []:
recIDs.extend(get_low_level_recIDs_from_control_no(control_no))
affiliation = cgi.escape(affiliation)
if len(recIDs) == 1:
affiliation = '<a href="' + CFG_SITE_URL + \
'/record/' + str(recIDs[0]) + \
'?ln=' + bfo.lang + \
'">' + affiliation + '</a>'
elif len(recIDs) > 1:
affiliation = '<a href="' + CFG_SITE_URL + \
'/search?' + \
'p=recid:' + " or recid:".join([str(_id) for _id in recIDs]) + \
'&c=' + CFG_SITE_NAME + \
'&c=' + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
'&ln=' + bfo.lang + \
'">' + affiliation + '</a>'
out += affiliation + " "
if out:
return "<br/>" + out
def escape_values(bfo):
"""
Called by BibFormat in order to check if output of this element
should be escaped.
"""
return 0
|
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,
8315,
12,
10219,
12,
9079,
12,
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,
624,
25217,
3484,
1819,
446,
9101,
83,
23528,
18835,
199,
624,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
16004,
199,
504,
13640,
14,
888,
492,
971,
272,
10974,
63,
7917,
63,
2632,
12,
10974,
63,
7917,
63,
2339,
199,
504,
13640,
14,
8804,
23635,
63,
888,
492,
971,
272,
10974,
63,
19832,
29039,
63,
29039,
63,
29374,
63,
2339,
1362,
199,
504,
13640,
14,
8804,
23635,
63,
3908,
492,
971,
272,
664,
63,
674,
63,
1896,
63,
2761,
12818,
63,
504,
63,
2785,
63,
889,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
304,
272,
408,
272,
4163,
437,
11286,
18835,
2929,
272,
408,
272,
29172,
1298,
275,
330,
545,
14,
955,
360,
26578,
35,
17,
297,
11982,
461,
63,
954,
955,
63,
80,
29,
549,
9,
272,
734,
275,
3087,
272,
367,
23528,
18835,
63,
807,
315,
29172,
1298,
26,
267,
340,
283,
85,
7,
315,
23528,
18835,
63,
807,
26,
288,
6488,
12818,
275,
942,
288,
23528,
18835,
275,
23528,
18835,
63,
807,
459,
85,
3488,
16,
61,
288,
3304,
63,
12712,
275,
23528,
18835,
63,
807,
14,
362,
360,
16,
358,
288,
367,
3304,
63,
889,
315,
3304,
63,
12712,
503,
18410,
355,
6488,
12818,
14,
2880,
8,
362,
63,
674,
63,
1896,
63,
2761,
12818,
63,
504,
63,
2785,
63,
889,
8,
2785,
63,
889,
430,
288,
23528,
18835,
275,
16004,
14,
3765,
8,
27054,
18835,
9,
288,
340,
822,
8,
2761,
12818,
9,
508,
413,
26,
355,
23528,
18835,
275,
2650,
65,
4369,
26957,
435,
10974,
63,
7917,
63,
2632,
435,
971,
2892,
1994,
3059,
4805,
435,
620,
8,
2761,
12818,
59,
16,
566,
435,
971,
2892,
8720,
6066,
534,
435,
330,
545,
14,
4159,
435,
971,
2892,
283,
15603,
435,
23528,
18835,
435,
11936,
65,
3524,
288,
916,
822,
8,
2761,
12818,
9,
690,
413,
26,
355,
23528,
18835,
275,
2650,
65,
4369,
26957,
435,
10974,
63,
7917,
63,
2632,
435,
971,
2892,
1994,
1733,
14069,
435,
971,
2892,
283,
80,
29,
17532,
4881,
435,
221,
298,
503,
25305,
26,
1674,
904,
779,
495,
1547,
344,
9,
367,
485,
344,
315,
6488,
12818,
566,
435,
971,
2892,
7673,
5282,
27,
67,
534,
435,
10974,
63,
7917,
63,
2339,
435,
971,
2892,
7673,
5282,
27,
67,
534,
435,
10974,
63,
19832,
29039,
63,
29039,
63,
29374,
63,
2339,
435,
971,
2892,
7673,
5282,
27,
6066,
534,
435,
330,
545,
14,
4159,
435,
971,
2892,
283,
15603,
435,
23528,
18835,
435,
11936,
65,
3524,
953,
734,
847,
23528,
18835,
435,
298,
755,
298,
339,
340,
734,
26,
267,
372,
3886,
3289,
25552,
435,
734,
421,
199,
318,
4772,
63,
1459,
8,
66,
545,
304,
272,
408,
272,
12295,
701,
21949,
3484,
315,
1865,
370,
1104,
340,
1072,
402,
642,
1819,
272,
1077,
506,
11077,
14,
272,
408,
272,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
8315,
12,
10219,
12,
9079,
12,
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,
624,
25217,
3484,
1819,
446,
9101,
83,
23528,
18835,
199,
624,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
16004,
199,
504,
13640,
14,
888,
492,
971,
272,
10974,
63,
7917,
63,
2632,
12,
10974,
63,
7917,
63,
2339,
199,
504,
13640,
14,
8804,
23635,
63,
888,
492,
971,
272,
10974,
63,
19832,
29039,
63,
29039,
63,
29374,
63,
2339,
1362,
199,
504,
13640,
14,
8804,
23635,
63,
3908,
492,
971,
272,
664,
63,
674,
63,
1896,
63,
2761,
12818,
63,
504,
63,
2785,
63,
889,
199,
199,
318,
1475,
63,
2108,
8,
66,
545,
304,
272,
408,
272,
4163,
437,
11286,
18835,
2929,
272,
408,
272,
29172,
1298,
275,
330,
545,
14,
955,
360,
26578,
35,
17,
297,
11982,
461,
63,
954,
955,
63,
80,
29,
549,
9,
272,
734,
275,
3087,
272,
367,
23528,
18835,
63,
807,
315,
29172,
1298,
26,
267,
340,
283,
85,
7,
315,
23528,
18835,
63,
807,
26,
288,
6488,
12818,
275,
942,
288,
23528,
18835,
275,
23528,
18835,
63,
807,
459,
85,
3488,
16,
61,
288,
3304,
63,
12712,
275,
23528,
18835,
63,
807,
14,
362,
360,
16,
358,
288,
367,
3304,
63,
889,
315,
3304,
63,
12712,
503,
18410,
355,
6488,
12818,
14,
2880,
8,
362,
63,
674,
63,
1896,
63,
2761,
12818,
63,
504,
63,
2785,
63,
889,
8,
2785,
63,
889,
430,
288,
23528,
18835,
275,
16004,
14,
3765,
8,
27054,
18835,
9,
288,
340,
822,
8,
2761,
12818,
9,
508,
413,
26,
355,
23528,
18835,
275,
2650,
65,
4369,
26957,
435,
10974,
63,
7917,
63,
2632,
435,
971,
2892,
1994,
3059,
4805,
435,
620,
8,
2761,
12818,
59,
16,
566,
435,
971,
2892,
8720,
6066,
534,
435,
330,
545,
14,
4159,
435,
971,
2892,
283,
15603,
435,
23528,
18835,
435,
11936,
65,
3524,
288,
916,
822,
8,
2761,
12818,
9,
690,
413,
26,
355,
23528,
18835,
275,
2650,
65,
4369,
26957,
435,
10974,
63,
7917,
63,
2632,
435,
971,
2892,
1994,
1733,
14069,
435,
971,
2892,
283,
80,
29,
17532,
4881,
435,
221,
298,
503,
25305,
26,
1674,
904,
779,
495,
1547,
344,
9,
367,
485,
344,
315,
6488,
12818,
566,
435,
971,
2892,
7673,
5282,
27,
67,
534,
435,
10974,
63,
7917,
63,
2339,
435,
971,
2892,
7673,
5282,
27,
67,
534,
435,
10974,
63,
19832,
29039,
63,
29039,
63,
29374,
63,
2339,
435,
971,
2892,
7673,
5282,
27,
6066,
534,
435,
330,
545,
14,
4159,
435,
971,
2892,
283,
15603,
435,
23528,
18835,
435,
11936,
65,
3524,
953,
734,
847,
23528,
18835,
435,
298,
755,
298,
339,
340,
734,
26,
267,
372,
3886,
3289,
25552,
435,
734,
421,
199,
318,
4772,
63,
1459,
8,
66,
545,
304,
272,
408,
272,
12295,
701,
21949,
3484,
315,
1865,
370,
1104,
340,
1072,
402,
642,
1819,
272,
1077,
506,
11077,
14,
272,
408,
272,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
40223119/2015w13-1
|
static/Brython3.1.3-20150514-095342/Lib/_sre.py
|
622
|
51369
|
# NOT_RPYTHON
"""
A pure Python reimplementation of the _sre module from CPython 2.4
Copyright 2005 Nik Haldimann, licensed under the MIT license
This code is based on material licensed under CNRI's Python 1.6 license and
copyrighted by: Copyright (c) 1997-2001 by Secret Labs AB
"""
MAXREPEAT = 2147483648
#import array
import operator, sys
from sre_constants import ATCODES, OPCODES, CHCODES
from sre_constants import SRE_INFO_PREFIX, SRE_INFO_LITERAL
from sre_constants import SRE_FLAG_UNICODE, SRE_FLAG_LOCALE
import sys
# Identifying as _sre from Python 2.3 or 2.4
#if sys.version_info[:2] >= (2, 4):
MAGIC = 20031017
#else:
# MAGIC = 20030419
# In _sre.c this is bytesize of the code word type of the C implementation.
# There it's 2 for normal Python builds and more for wide unicode builds (large
# enough to hold a 32-bit UCS-4 encoded character). Since here in pure Python
# we only see re bytecodes as Python longs, we shouldn't have to care about the
# codesize. But sre_compile will compile some stuff differently depending on the
# codesize (e.g., charsets).
# starting with python 3.3 CODESIZE is 4
#if sys.maxunicode == 65535:
# CODESIZE = 2
#else:
CODESIZE = 4
copyright = "_sre.py 2.4c Copyright 2005 by Nik Haldimann"
def getcodesize():
return CODESIZE
def compile(pattern, flags, code, groups=0, groupindex={}, indexgroup=[None]):
"""Compiles (or rather just converts) a pattern descriptor to a SRE_Pattern
object. Actual compilation to opcodes happens in sre_compile."""
return SRE_Pattern(pattern, flags, code, groups, groupindex, indexgroup)
def getlower(char_ord, flags):
if (char_ord < 128) or (flags & SRE_FLAG_UNICODE) \
or (flags & SRE_FLAG_LOCALE and char_ord < 256):
#return ord(unichr(char_ord).lower())
return ord(chr(char_ord).lower())
else:
return char_ord
class SRE_Pattern:
def __init__(self, pattern, flags, code, groups=0, groupindex={}, indexgroup=[None]):
self.pattern = pattern
self.flags = flags
self.groups = groups
self.groupindex = groupindex # Maps group names to group indices
self._indexgroup = indexgroup # Maps indices to group names
self._code = code
def match(self, string, pos=0, endpos=sys.maxsize):
"""If zero or more characters at the beginning of string match this
regular expression, return a corresponding MatchObject instance. Return
None if the string does not match the pattern."""
state = _State(string, pos, endpos, self.flags)
if state.match(self._code):
return SRE_Match(self, state)
return None
def search(self, string, pos=0, endpos=sys.maxsize):
"""Scan through string looking for a location where this regular
expression produces a match, and return a corresponding MatchObject
instance. Return None if no position in the string matches the
pattern."""
state = _State(string, pos, endpos, self.flags)
if state.search(self._code):
return SRE_Match(self, state)
else:
return None
def findall(self, string, pos=0, endpos=sys.maxsize):
"""Return a list of all non-overlapping matches of pattern in string."""
matchlist = []
state = _State(string, pos, endpos, self.flags)
while state.start <= state.end:
state.reset()
state.string_position = state.start
if not state.search(self._code):
break
match = SRE_Match(self, state)
if self.groups == 0 or self.groups == 1:
item = match.group(self.groups)
else:
item = match.groups("")
matchlist.append(item)
if state.string_position == state.start:
state.start += 1
else:
state.start = state.string_position
return matchlist
def _subx(self, template, string, count=0, subn=False):
filter = template
if not callable(template) and "\\" in template:
# handle non-literal strings ; hand it over to the template compiler
#import sre #sre was renamed to re
#fix me brython
#print("possible issue at _sre.py line 116")
import re as sre
filter = sre._subx(self, template)
state = _State(string, 0, sys.maxsize, self.flags)
sublist = []
n = last_pos = 0
while not count or n < count:
state.reset()
state.string_position = state.start
if not state.search(self._code):
break
if last_pos < state.start:
sublist.append(string[last_pos:state.start])
if not (last_pos == state.start and
last_pos == state.string_position and n > 0):
# the above ignores empty matches on latest position
if callable(filter):
sublist.append(filter(SRE_Match(self, state)))
else:
sublist.append(filter)
last_pos = state.string_position
n += 1
if state.string_position == state.start:
state.start += 1
else:
state.start = state.string_position
if last_pos < state.end:
sublist.append(string[last_pos:state.end])
item = "".join(sublist)
if subn:
return item, n
else:
return item
def sub(self, repl, string, count=0):
"""Return the string obtained by replacing the leftmost non-overlapping
occurrences of pattern in string by the replacement repl."""
return self._subx(repl, string, count, False)
def subn(self, repl, string, count=0):
"""Return the tuple (new_string, number_of_subs_made) found by replacing
the leftmost non-overlapping occurrences of pattern with the replacement
repl."""
return self._subx(repl, string, count, True)
def split(self, string, maxsplit=0):
"""Split string by the occurrences of pattern."""
splitlist = []
state = _State(string, 0, sys.maxsize, self.flags)
n = 0
last = state.start
while not maxsplit or n < maxsplit:
state.reset()
state.string_position = state.start
if not state.search(self._code):
break
if state.start == state.string_position: # zero-width match
if last == state.end: # or end of string
break
state.start += 1
continue
splitlist.append(string[last:state.start])
# add groups (if any)
if self.groups:
match = SRE_Match(self, state)
splitlist.extend(list(match.groups(None)))
n += 1
last = state.start = state.string_position
splitlist.append(string[last:state.end])
return splitlist
def finditer(self, string, pos=0, endpos=sys.maxsize):
"""Return a list of all non-overlapping matches of pattern in string."""
#scanner = self.scanner(string, pos, endpos)
_list=[]
_m=self.scanner(string, pos, endpos)
_re=SRE_Scanner(self, string, pos, endpos)
_m=_re.search()
while _m:
_list.append(_m)
_m=_re.search()
return _list
#return iter(scanner.search, None)
def scanner(self, string, start=0, end=sys.maxsize):
return SRE_Scanner(self, string, start, end)
def __copy__(self):
raise TypeError("cannot copy this pattern object")
def __deepcopy__(self):
raise TypeError("cannot copy this pattern object")
class SRE_Scanner:
"""Undocumented scanner interface of sre."""
def __init__(self, pattern, string, start, end):
self.pattern = pattern
self._state = _State(string, start, end, self.pattern.flags)
def _match_search(self, matcher):
state = self._state
state.reset()
state.string_position = state.start
match = None
if matcher(self.pattern._code):
match = SRE_Match(self.pattern, state)
if match is None or state.string_position == state.start:
state.start += 1
else:
state.start = state.string_position
return match
def match(self):
return self._match_search(self._state.match)
def search(self):
return self._match_search(self._state.search)
class SRE_Match:
def __init__(self, pattern, state):
self.re = pattern
self.string = state.string
self.pos = state.pos
self.endpos = state.end
self.lastindex = state.lastindex
if self.lastindex < 0:
self.lastindex = None
self.regs = self._create_regs(state)
#statement below is not valid under python3 ( 0 <= None)
#if pattern._indexgroup and 0 <= self.lastindex < len(pattern._indexgroup):
if self.lastindex is not None and pattern._indexgroup and 0 <= self.lastindex < len(pattern._indexgroup):
# The above upper-bound check should not be necessary, as the re
# compiler is supposed to always provide an _indexgroup list long
# enough. But the re.Scanner class seems to screw up something
# there, test_scanner in test_re won't work without upper-bound
# checking. XXX investigate this and report bug to CPython.
self.lastgroup = pattern._indexgroup[self.lastindex]
else:
self.lastgroup = None
def _create_regs(self, state):
"""Creates a tuple of index pairs representing matched groups."""
regs = [(state.start, state.string_position)]
for group in range(self.re.groups):
mark_index = 2 * group
if mark_index + 1 < len(state.marks) \
and state.marks[mark_index] is not None \
and state.marks[mark_index + 1] is not None:
regs.append((state.marks[mark_index], state.marks[mark_index + 1]))
else:
regs.append((-1, -1))
return tuple(regs)
def _get_index(self, group):
if isinstance(group, int):
if group >= 0 and group <= self.re.groups:
return group
else:
if group in self.re.groupindex:
return self.re.groupindex[group]
raise IndexError("no such group")
def _get_slice(self, group, default):
group_indices = self.regs[group]
if group_indices[0] >= 0:
return self.string[group_indices[0]:group_indices[1]]
else:
return default
def start(self, group=0):
"""Returns the indices of the start of the substring matched by group;
group defaults to zero (meaning the whole matched substring). Returns -1
if group exists but did not contribute to the match."""
return self.regs[self._get_index(group)][0]
def end(self, group=0):
"""Returns the indices of the end of the substring matched by group;
group defaults to zero (meaning the whole matched substring). Returns -1
if group exists but did not contribute to the match."""
return self.regs[self._get_index(group)][1]
def span(self, group=0):
"""Returns the 2-tuple (m.start(group), m.end(group))."""
return self.start(group), self.end(group)
def expand(self, template):
"""Return the string obtained by doing backslash substitution and
resolving group references on template."""
import sre
return sre._expand(self.re, self, template)
def groups(self, default=None):
"""Returns a tuple containing all the subgroups of the match. The
default argument is used for groups that did not participate in the
match (defaults to None)."""
groups = []
for indices in self.regs[1:]:
if indices[0] >= 0:
groups.append(self.string[indices[0]:indices[1]])
else:
groups.append(default)
return tuple(groups)
def groupdict(self, default=None):
"""Return a dictionary containing all the named subgroups of the match.
The default argument is used for groups that did not participate in the
match (defaults to None)."""
groupdict = {}
for key, value in self.re.groupindex.items():
groupdict[key] = self._get_slice(value, default)
return groupdict
def group(self, *args):
"""Returns one or more subgroups of the match. Each argument is either a
group index or a group name."""
if len(args) == 0:
args = (0,)
grouplist = []
for group in args:
grouplist.append(self._get_slice(self._get_index(group), None))
if len(grouplist) == 1:
return grouplist[0]
else:
return tuple(grouplist)
def __copy__():
raise TypeError("cannot copy this pattern object")
def __deepcopy__():
raise TypeError("cannot copy this pattern object")
class _State:
def __init__(self, string, start, end, flags):
self.string = string
if start < 0:
start = 0
if end > len(string):
end = len(string)
self.start = start
self.string_position = self.start
self.end = end
self.pos = start
self.flags = flags
self.reset()
def reset(self):
self.marks = []
self.lastindex = -1
self.marks_stack = []
self.context_stack = []
self.repeat = None
def match(self, pattern_codes):
# Optimization: Check string length. pattern_codes[3] contains the
# minimum length for a string to possibly match.
# brython.. the optimization doesn't work
#if pattern_codes[0] == OPCODES["info"] and pattern_codes[3]:
# if self.end - self.string_position < pattern_codes[3]:
# #_log("reject (got %d chars, need %d)"
# # % (self.end - self.string_position, pattern_codes[3]))
# return False
dispatcher = _OpcodeDispatcher()
self.context_stack.append(_MatchContext(self, pattern_codes))
has_matched = None
while len(self.context_stack) > 0:
context = self.context_stack[-1]
has_matched = dispatcher.match(context)
if has_matched is not None: # don't pop if context isn't done
self.context_stack.pop()
return has_matched
def search(self, pattern_codes):
flags = 0
if pattern_codes[0] == OPCODES["info"]:
# optimization info block
# <INFO> <1=skip> <2=flags> <3=min> <4=max> <5=prefix info>
if pattern_codes[2] & SRE_INFO_PREFIX and pattern_codes[5] > 1:
return self.fast_search(pattern_codes)
flags = pattern_codes[2]
pattern_codes = pattern_codes[pattern_codes[1] + 1:]
string_position = self.start
if pattern_codes[0] == OPCODES["literal"]:
# Special case: Pattern starts with a literal character. This is
# used for short prefixes
character = pattern_codes[1]
while True:
while string_position < self.end \
and ord(self.string[string_position]) != character:
string_position += 1
if string_position >= self.end:
return False
self.start = string_position
string_position += 1
self.string_position = string_position
if flags & SRE_INFO_LITERAL:
return True
if self.match(pattern_codes[2:]):
return True
return False
# General case
while string_position <= self.end:
self.reset()
self.start = self.string_position = string_position
if self.match(pattern_codes):
return True
string_position += 1
return False
def fast_search(self, pattern_codes):
"""Skips forward in a string as fast as possible using information from
an optimization info block."""
# pattern starts with a known prefix
# <5=length> <6=skip> <7=prefix data> <overlap data>
flags = pattern_codes[2]
prefix_len = pattern_codes[5]
prefix_skip = pattern_codes[6] # don't really know what this is good for
prefix = pattern_codes[7:7 + prefix_len]
overlap = pattern_codes[7 + prefix_len - 1:pattern_codes[1] + 1]
pattern_codes = pattern_codes[pattern_codes[1] + 1:]
i = 0
string_position = self.string_position
while string_position < self.end:
while True:
if ord(self.string[string_position]) != prefix[i]:
if i == 0:
break
else:
i = overlap[i]
else:
i += 1
if i == prefix_len:
# found a potential match
self.start = string_position + 1 - prefix_len
self.string_position = string_position + 1 \
- prefix_len + prefix_skip
if flags & SRE_INFO_LITERAL:
return True # matched all of pure literal pattern
if self.match(pattern_codes[2 * prefix_skip:]):
return True
i = overlap[i]
break
string_position += 1
return False
def set_mark(self, mark_nr, position):
if mark_nr & 1:
# This id marks the end of a group.
# fix python 3 division incompatability
#self.lastindex = mark_nr / 2 + 1
self.lastindex = mark_nr // 2 + 1
if mark_nr >= len(self.marks):
self.marks.extend([None] * (mark_nr - len(self.marks) + 1))
self.marks[mark_nr] = position
def get_marks(self, group_index):
marks_index = 2 * group_index
if len(self.marks) > marks_index + 1:
return self.marks[marks_index], self.marks[marks_index + 1]
else:
return None, None
def marks_push(self):
self.marks_stack.append((self.marks[:], self.lastindex))
def marks_pop(self):
self.marks, self.lastindex = self.marks_stack.pop()
def marks_pop_keep(self):
self.marks, self.lastindex = self.marks_stack[-1]
def marks_pop_discard(self):
self.marks_stack.pop()
def lower(self, char_ord):
return getlower(char_ord, self.flags)
class _MatchContext:
def __init__(self, state, pattern_codes):
self.state = state
self.pattern_codes = pattern_codes
self.string_position = state.string_position
self.code_position = 0
self.has_matched = None
def push_new_context(self, pattern_offset):
"""Creates a new child context of this context and pushes it on the
stack. pattern_offset is the offset off the current code position to
start interpreting from."""
child_context = _MatchContext(self.state,
self.pattern_codes[self.code_position + pattern_offset:])
#print("_sre.py:517:pushing new context") #, child_context.has_matched)
#print(self.state.string_position)
#print(self.pattern_codes[self.code_position + pattern_offset:])
#print(pattern_offset)
self.state.context_stack.append(child_context)
return child_context
def peek_char(self, peek=0):
return self.state.string[self.string_position + peek]
def skip_char(self, skip_count):
self.string_position += skip_count
def remaining_chars(self):
return self.state.end - self.string_position
def peek_code(self, peek=0):
return self.pattern_codes[self.code_position + peek]
def skip_code(self, skip_count):
self.code_position += skip_count
def remaining_codes(self):
return len(self.pattern_codes) - self.code_position
def at_beginning(self):
return self.string_position == 0
def at_end(self):
return self.string_position == self.state.end
def at_linebreak(self):
return not self.at_end() and _is_linebreak(self.peek_char())
def at_boundary(self, word_checker):
if self.at_beginning() and self.at_end():
return False
that = not self.at_beginning() and word_checker(self.peek_char(-1))
this = not self.at_end() and word_checker(self.peek_char())
return this != that
class _RepeatContext(_MatchContext):
def __init__(self, context):
_MatchContext.__init__(self, context.state,
context.pattern_codes[context.code_position:])
self.count = -1
#print('569:repeat', context.state.repeat)
self.previous = context.state.repeat
self.last_position = None
class _Dispatcher:
DISPATCH_TABLE = None
def dispatch(self, code, context):
method = self.DISPATCH_TABLE.get(code, self.__class__.unknown)
return method(self, context)
def unknown(self, code, ctx):
raise NotImplementedError()
def build_dispatch_table(cls, code_dict, method_prefix):
if cls.DISPATCH_TABLE is not None:
return
table = {}
for key, value in code_dict.items():
if hasattr(cls, "%s%s" % (method_prefix, key)):
table[value] = getattr(cls, "%s%s" % (method_prefix, key))
cls.DISPATCH_TABLE = table
build_dispatch_table = classmethod(build_dispatch_table)
class _OpcodeDispatcher(_Dispatcher):
def __init__(self):
self.executing_contexts = {}
self.at_dispatcher = _AtcodeDispatcher()
self.ch_dispatcher = _ChcodeDispatcher()
self.set_dispatcher = _CharsetDispatcher()
def match(self, context):
"""Returns True if the current context matches, False if it doesn't and
None if matching is not finished, ie must be resumed after child
contexts have been matched."""
while context.remaining_codes() > 0 and context.has_matched is None:
opcode = context.peek_code()
if not self.dispatch(opcode, context):
return None
if context.has_matched is None:
context.has_matched = False
return context.has_matched
def dispatch(self, opcode, context):
"""Dispatches a context on a given opcode. Returns True if the context
is done matching, False if it must be resumed when next encountered."""
#if self.executing_contexts.has_key(id(context)):
if id(context) in self.executing_contexts:
generator = self.executing_contexts[id(context)]
del self.executing_contexts[id(context)]
has_finished = next(generator)
else:
method = self.DISPATCH_TABLE.get(opcode, _OpcodeDispatcher.unknown)
has_finished = method(self, context)
if hasattr(has_finished, "__next__"): # avoid using the types module
generator = has_finished
has_finished = next(generator)
if not has_finished:
self.executing_contexts[id(context)] = generator
return has_finished
def op_success(self, ctx):
# end of pattern
#self._log(ctx, "SUCCESS")
ctx.state.string_position = ctx.string_position
ctx.has_matched = True
return True
def op_failure(self, ctx):
# immediate failure
#self._log(ctx, "FAILURE")
ctx.has_matched = False
return True
def general_op_literal(self, ctx, compare, decorate=lambda x: x):
#print(ctx.peek_char())
if ctx.at_end() or not compare(decorate(ord(ctx.peek_char())),
decorate(ctx.peek_code(1))):
ctx.has_matched = False
ctx.skip_code(2)
ctx.skip_char(1)
def op_literal(self, ctx):
# match literal string
# <LITERAL> <code>
#self._log(ctx, "LITERAL", ctx.peek_code(1))
self.general_op_literal(ctx, operator.eq)
return True
def op_not_literal(self, ctx):
# match anything that is not the given literal character
# <NOT_LITERAL> <code>
#self._log(ctx, "NOT_LITERAL", ctx.peek_code(1))
self.general_op_literal(ctx, operator.ne)
return True
def op_literal_ignore(self, ctx):
# match literal regardless of case
# <LITERAL_IGNORE> <code>
#self._log(ctx, "LITERAL_IGNORE", ctx.peek_code(1))
self.general_op_literal(ctx, operator.eq, ctx.state.lower)
return True
def op_not_literal_ignore(self, ctx):
# match literal regardless of case
# <LITERAL_IGNORE> <code>
#self._log(ctx, "LITERAL_IGNORE", ctx.peek_code(1))
self.general_op_literal(ctx, operator.ne, ctx.state.lower)
return True
def op_at(self, ctx):
# match at given position
# <AT> <code>
#self._log(ctx, "AT", ctx.peek_code(1))
if not self.at_dispatcher.dispatch(ctx.peek_code(1), ctx):
ctx.has_matched = False
#print('_sre.py:line693, update context.has_matched variable')
return True
ctx.skip_code(2)
return True
def op_category(self, ctx):
# match at given category
# <CATEGORY> <code>
#self._log(ctx, "CATEGORY", ctx.peek_code(1))
if ctx.at_end() or not self.ch_dispatcher.dispatch(ctx.peek_code(1), ctx):
ctx.has_matched = False
#print('_sre.py:line703, update context.has_matched variable')
return True
ctx.skip_code(2)
ctx.skip_char(1)
return True
def op_any(self, ctx):
# match anything (except a newline)
# <ANY>
#self._log(ctx, "ANY")
if ctx.at_end() or ctx.at_linebreak():
ctx.has_matched = False
#print('_sre.py:line714, update context.has_matched variable')
return True
ctx.skip_code(1)
ctx.skip_char(1)
return True
def op_any_all(self, ctx):
# match anything
# <ANY_ALL>
#self._log(ctx, "ANY_ALL")
if ctx.at_end():
ctx.has_matched = False
#print('_sre.py:line725, update context.has_matched variable')
return True
ctx.skip_code(1)
ctx.skip_char(1)
return True
def general_op_in(self, ctx, decorate=lambda x: x):
#self._log(ctx, "OP_IN")
#print('general_op_in')
if ctx.at_end():
ctx.has_matched = False
#print('_sre.py:line734, update context.has_matched variable')
return
skip = ctx.peek_code(1)
ctx.skip_code(2) # set op pointer to the set code
#print(ctx.peek_char(), ord(ctx.peek_char()),
# decorate(ord(ctx.peek_char())))
if not self.check_charset(ctx, decorate(ord(ctx.peek_char()))):
#print('_sre.py:line738, update context.has_matched variable')
ctx.has_matched = False
return
ctx.skip_code(skip - 1)
ctx.skip_char(1)
#print('end:general_op_in')
def op_in(self, ctx):
# match set member (or non_member)
# <IN> <skip> <set>
#self._log(ctx, "OP_IN")
self.general_op_in(ctx)
return True
def op_in_ignore(self, ctx):
# match set member (or non_member), disregarding case of current char
# <IN_IGNORE> <skip> <set>
#self._log(ctx, "OP_IN_IGNORE")
self.general_op_in(ctx, ctx.state.lower)
return True
def op_jump(self, ctx):
# jump forward
# <JUMP> <offset>
#self._log(ctx, "JUMP", ctx.peek_code(1))
ctx.skip_code(ctx.peek_code(1) + 1)
return True
# skip info
# <INFO> <skip>
op_info = op_jump
def op_mark(self, ctx):
# set mark
# <MARK> <gid>
#self._log(ctx, "OP_MARK", ctx.peek_code(1))
ctx.state.set_mark(ctx.peek_code(1), ctx.string_position)
ctx.skip_code(2)
return True
def op_branch(self, ctx):
# alternation
# <BRANCH> <0=skip> code <JUMP> ... <NULL>
#self._log(ctx, "BRANCH")
ctx.state.marks_push()
ctx.skip_code(1)
current_branch_length = ctx.peek_code(0)
while current_branch_length:
# The following tries to shortcut branches starting with a
# (unmatched) literal. _sre.c also shortcuts charsets here.
if not (ctx.peek_code(1) == OPCODES["literal"] and \
(ctx.at_end() or ctx.peek_code(2) != ord(ctx.peek_char()))):
ctx.state.string_position = ctx.string_position
child_context = ctx.push_new_context(1)
#print("_sre.py:803:op_branch")
yield False
if child_context.has_matched:
ctx.has_matched = True
yield True
ctx.state.marks_pop_keep()
ctx.skip_code(current_branch_length)
current_branch_length = ctx.peek_code(0)
ctx.state.marks_pop_discard()
ctx.has_matched = False
#print('_sre.py:line805, update context.has_matched variable')
yield True
def op_repeat_one(self, ctx):
# match repeated sequence (maximizing).
# this operator only works if the repeated item is exactly one character
# wide, and we're not already collecting backtracking points.
# <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail
mincount = ctx.peek_code(2)
maxcount = ctx.peek_code(3)
#print("repeat one", mincount, maxcount)
#self._log(ctx, "REPEAT_ONE", mincount, maxcount)
if ctx.remaining_chars() < mincount:
ctx.has_matched = False
yield True
ctx.state.string_position = ctx.string_position
count = self.count_repetitions(ctx, maxcount)
ctx.skip_char(count)
if count < mincount:
ctx.has_matched = False
yield True
if ctx.peek_code(ctx.peek_code(1) + 1) == OPCODES["success"]:
# tail is empty. we're finished
ctx.state.string_position = ctx.string_position
ctx.has_matched = True
yield True
ctx.state.marks_push()
if ctx.peek_code(ctx.peek_code(1) + 1) == OPCODES["literal"]:
# Special case: Tail starts with a literal. Skip positions where
# the rest of the pattern cannot possibly match.
char = ctx.peek_code(ctx.peek_code(1) + 2)
while True:
while count >= mincount and \
(ctx.at_end() or ord(ctx.peek_char()) != char):
ctx.skip_char(-1)
count -= 1
if count < mincount:
break
ctx.state.string_position = ctx.string_position
child_context = ctx.push_new_context(ctx.peek_code(1) + 1)
#print("_sre.py:856:push_new_context")
yield False
if child_context.has_matched:
ctx.has_matched = True
yield True
ctx.skip_char(-1)
count -= 1
ctx.state.marks_pop_keep()
else:
# General case: backtracking
while count >= mincount:
ctx.state.string_position = ctx.string_position
child_context = ctx.push_new_context(ctx.peek_code(1) + 1)
yield False
if child_context.has_matched:
ctx.has_matched = True
yield True
ctx.skip_char(-1)
count -= 1
ctx.state.marks_pop_keep()
ctx.state.marks_pop_discard()
ctx.has_matched = False
#ctx.has_matched = True # <== this should be True (so match object gets returned to program)
yield True
def op_min_repeat_one(self, ctx):
# match repeated sequence (minimizing)
# <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail
mincount = ctx.peek_code(2)
maxcount = ctx.peek_code(3)
#self._log(ctx, "MIN_REPEAT_ONE", mincount, maxcount)
if ctx.remaining_chars() < mincount:
ctx.has_matched = False
yield True
ctx.state.string_position = ctx.string_position
if mincount == 0:
count = 0
else:
count = self.count_repetitions(ctx, mincount)
if count < mincount:
ctx.has_matched = False
#print('_sre.py:line891, update context.has_matched variable')
yield True
ctx.skip_char(count)
if ctx.peek_code(ctx.peek_code(1) + 1) == OPCODES["success"]:
# tail is empty. we're finished
ctx.state.string_position = ctx.string_position
ctx.has_matched = True
yield True
ctx.state.marks_push()
while maxcount == MAXREPEAT or count <= maxcount:
ctx.state.string_position = ctx.string_position
child_context = ctx.push_new_context(ctx.peek_code(1) + 1)
#print('_sre.py:916:push new context')
yield False
if child_context.has_matched:
ctx.has_matched = True
yield True
ctx.state.string_position = ctx.string_position
if self.count_repetitions(ctx, 1) == 0:
break
ctx.skip_char(1)
count += 1
ctx.state.marks_pop_keep()
ctx.state.marks_pop_discard()
ctx.has_matched = False
yield True
def op_repeat(self, ctx):
# create repeat context. all the hard work is done by the UNTIL
# operator (MAX_UNTIL, MIN_UNTIL)
# <REPEAT> <skip> <1=min> <2=max> item <UNTIL> tail
#self._log(ctx, "REPEAT", ctx.peek_code(2), ctx.peek_code(3))
#if ctx.state.repeat is None:
# print("951:ctx.state.repeat is None")
# #ctx.state.repeat=_RepeatContext(ctx)
repeat = _RepeatContext(ctx)
ctx.state.repeat = repeat
ctx.state.string_position = ctx.string_position
child_context = ctx.push_new_context(ctx.peek_code(1) + 1)
#print("_sre.py:941:push new context", id(child_context))
#print(child_context.state.repeat)
#print(ctx.state.repeat)
# are these two yields causing the issue?
yield False
ctx.state.repeat = repeat.previous
ctx.has_matched = child_context.has_matched
yield True
def op_max_until(self, ctx):
# maximizing repeat
# <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail
repeat = ctx.state.repeat
#print("op_max_until") #, id(ctx.state.repeat))
if repeat is None:
#print(id(ctx), id(ctx.state))
raise RuntimeError("Internal re error: MAX_UNTIL without REPEAT.")
mincount = repeat.peek_code(2)
maxcount = repeat.peek_code(3)
ctx.state.string_position = ctx.string_position
count = repeat.count + 1
#self._log(ctx, "MAX_UNTIL", count)
if count < mincount:
# not enough matches
repeat.count = count
child_context = repeat.push_new_context(4)
yield False
ctx.has_matched = child_context.has_matched
if not ctx.has_matched:
repeat.count = count - 1
ctx.state.string_position = ctx.string_position
yield True
if (count < maxcount or maxcount == MAXREPEAT) \
and ctx.state.string_position != repeat.last_position:
# we may have enough matches, if we can match another item, do so
repeat.count = count
ctx.state.marks_push()
save_last_position = repeat.last_position # zero-width match protection
repeat.last_position = ctx.state.string_position
child_context = repeat.push_new_context(4)
yield False
repeat.last_position = save_last_position
if child_context.has_matched:
ctx.state.marks_pop_discard()
ctx.has_matched = True
yield True
ctx.state.marks_pop()
repeat.count = count - 1
ctx.state.string_position = ctx.string_position
# cannot match more repeated items here. make sure the tail matches
ctx.state.repeat = repeat.previous
child_context = ctx.push_new_context(1)
#print("_sre.py:987:op_max_until")
yield False
ctx.has_matched = child_context.has_matched
if not ctx.has_matched:
ctx.state.repeat = repeat
ctx.state.string_position = ctx.string_position
yield True
def op_min_until(self, ctx):
# minimizing repeat
# <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail
repeat = ctx.state.repeat
if repeat is None:
raise RuntimeError("Internal re error: MIN_UNTIL without REPEAT.")
mincount = repeat.peek_code(2)
maxcount = repeat.peek_code(3)
ctx.state.string_position = ctx.string_position
count = repeat.count + 1
#self._log(ctx, "MIN_UNTIL", count)
if count < mincount:
# not enough matches
repeat.count = count
child_context = repeat.push_new_context(4)
yield False
ctx.has_matched = child_context.has_matched
if not ctx.has_matched:
repeat.count = count - 1
ctx.state.string_position = ctx.string_position
yield True
# see if the tail matches
ctx.state.marks_push()
ctx.state.repeat = repeat.previous
child_context = ctx.push_new_context(1)
#print('_sre.py:1022:push new context')
yield False
if child_context.has_matched:
ctx.has_matched = True
yield True
ctx.state.repeat = repeat
ctx.state.string_position = ctx.string_position
ctx.state.marks_pop()
# match more until tail matches
if count >= maxcount and maxcount != MAXREPEAT:
ctx.has_matched = False
#print('_sre.py:line1022, update context.has_matched variable')
yield True
repeat.count = count
child_context = repeat.push_new_context(4)
yield False
ctx.has_matched = child_context.has_matched
if not ctx.has_matched:
repeat.count = count - 1
ctx.state.string_position = ctx.string_position
yield True
def general_op_groupref(self, ctx, decorate=lambda x: x):
group_start, group_end = ctx.state.get_marks(ctx.peek_code(1))
if group_start is None or group_end is None or group_end < group_start:
ctx.has_matched = False
return True
while group_start < group_end:
if ctx.at_end() or decorate(ord(ctx.peek_char())) \
!= decorate(ord(ctx.state.string[group_start])):
ctx.has_matched = False
#print('_sre.py:line1042, update context.has_matched variable')
return True
group_start += 1
ctx.skip_char(1)
ctx.skip_code(2)
return True
def op_groupref(self, ctx):
# match backreference
# <GROUPREF> <zero-based group index>
#self._log(ctx, "GROUPREF", ctx.peek_code(1))
return self.general_op_groupref(ctx)
def op_groupref_ignore(self, ctx):
# match backreference case-insensitive
# <GROUPREF_IGNORE> <zero-based group index>
#self._log(ctx, "GROUPREF_IGNORE", ctx.peek_code(1))
return self.general_op_groupref(ctx, ctx.state.lower)
def op_groupref_exists(self, ctx):
# <GROUPREF_EXISTS> <group> <skip> codeyes <JUMP> codeno ...
#self._log(ctx, "GROUPREF_EXISTS", ctx.peek_code(1))
group_start, group_end = ctx.state.get_marks(ctx.peek_code(1))
if group_start is None or group_end is None or group_end < group_start:
ctx.skip_code(ctx.peek_code(2) + 1)
else:
ctx.skip_code(3)
return True
def op_assert(self, ctx):
# assert subpattern
# <ASSERT> <skip> <back> <pattern>
#self._log(ctx, "ASSERT", ctx.peek_code(2))
ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
if ctx.state.string_position < 0:
ctx.has_matched = False
yield True
child_context = ctx.push_new_context(3)
yield False
if child_context.has_matched:
ctx.skip_code(ctx.peek_code(1) + 1)
else:
ctx.has_matched = False
yield True
def op_assert_not(self, ctx):
# assert not subpattern
# <ASSERT_NOT> <skip> <back> <pattern>
#self._log(ctx, "ASSERT_NOT", ctx.peek_code(2))
ctx.state.string_position = ctx.string_position - ctx.peek_code(2)
if ctx.state.string_position >= 0:
child_context = ctx.push_new_context(3)
yield False
if child_context.has_matched:
ctx.has_matched = False
yield True
ctx.skip_code(ctx.peek_code(1) + 1)
yield True
def unknown(self, ctx):
#self._log(ctx, "UNKNOWN", ctx.peek_code())
raise RuntimeError("Internal re error. Unknown opcode: %s" % ctx.peek_code())
def check_charset(self, ctx, char):
"""Checks whether a character matches set of arbitrary length. Assumes
the code pointer is at the first member of the set."""
self.set_dispatcher.reset(char)
save_position = ctx.code_position
result = None
while result is None:
result = self.set_dispatcher.dispatch(ctx.peek_code(), ctx)
ctx.code_position = save_position
#print("_sre.py:1123:check_charset", result)
return result
def count_repetitions(self, ctx, maxcount):
"""Returns the number of repetitions of a single item, starting from the
current string position. The code pointer is expected to point to a
REPEAT_ONE operation (with the repeated 4 ahead)."""
count = 0
real_maxcount = ctx.state.end - ctx.string_position
if maxcount < real_maxcount and maxcount != MAXREPEAT:
real_maxcount = maxcount
# XXX could special case every single character pattern here, as in C.
# This is a general solution, a bit hackisch, but works and should be
# efficient.
code_position = ctx.code_position
string_position = ctx.string_position
ctx.skip_code(4)
reset_position = ctx.code_position
while count < real_maxcount:
# this works because the single character pattern is followed by
# a success opcode
ctx.code_position = reset_position
self.dispatch(ctx.peek_code(), ctx)
#print("count_repetitions", ctx.has_matched, count)
if ctx.has_matched is False: # could be None as well
break
count += 1
ctx.has_matched = None
ctx.code_position = code_position
ctx.string_position = string_position
return count
def _log(self, context, opname, *args):
arg_string = ("%s " * len(args)) % args
_log("|%s|%s|%s %s" % (context.pattern_codes,
context.string_position, opname, arg_string))
_OpcodeDispatcher.build_dispatch_table(OPCODES, "op_")
class _CharsetDispatcher(_Dispatcher):
def __init__(self):
self.ch_dispatcher = _ChcodeDispatcher()
def reset(self, char):
self.char = char
self.ok = True
def set_failure(self, ctx):
return not self.ok
def set_literal(self, ctx):
# <LITERAL> <code>
if ctx.peek_code(1) == self.char:
return self.ok
else:
ctx.skip_code(2)
def set_category(self, ctx):
# <CATEGORY> <code>
if self.ch_dispatcher.dispatch(ctx.peek_code(1), ctx):
return self.ok
else:
ctx.skip_code(2)
def set_charset(self, ctx):
# <CHARSET> <bitmap> (16 bits per code word)
char_code = self.char
ctx.skip_code(1) # point to beginning of bitmap
if CODESIZE == 2:
if char_code < 256 and ctx.peek_code(char_code >> 4) \
& (1 << (char_code & 15)):
return self.ok
ctx.skip_code(16) # skip bitmap
else:
if char_code < 256 and ctx.peek_code(char_code >> 5) \
& (1 << (char_code & 31)):
return self.ok
ctx.skip_code(8) # skip bitmap
def set_range(self, ctx):
# <RANGE> <lower> <upper>
if ctx.peek_code(1) <= self.char <= ctx.peek_code(2):
return self.ok
ctx.skip_code(3)
def set_negate(self, ctx):
self.ok = not self.ok
ctx.skip_code(1)
#fixme brython. array module doesn't exist
def set_bigcharset(self, ctx):
raise NotImplementationError("_sre.py: set_bigcharset, array not implemented")
# <BIGCHARSET> <blockcount> <256 blockindices> <blocks>
char_code = self.char
count = ctx.peek_code(1)
ctx.skip_code(2)
if char_code < 65536:
block_index = char_code >> 8
# NB: there are CODESIZE block indices per bytecode
a = array.array("B")
a.fromstring(array.array(CODESIZE == 2 and "H" or "I",
[ctx.peek_code(block_index // CODESIZE)]).tostring())
block = a[block_index % CODESIZE]
ctx.skip_code(256 // CODESIZE) # skip block indices
block_value = ctx.peek_code(block * (32 // CODESIZE)
+ ((char_code & 255) >> (CODESIZE == 2 and 4 or 5)))
if block_value & (1 << (char_code & ((8 * CODESIZE) - 1))):
return self.ok
else:
ctx.skip_code(256 // CODESIZE) # skip block indices
ctx.skip_code(count * (32 // CODESIZE)) # skip blocks
def unknown(self, ctx):
return False
_CharsetDispatcher.build_dispatch_table(OPCODES, "set_")
class _AtcodeDispatcher(_Dispatcher):
def at_beginning(self, ctx):
return ctx.at_beginning()
at_beginning_string = at_beginning
def at_beginning_line(self, ctx):
return ctx.at_beginning() or _is_linebreak(ctx.peek_char(-1))
def at_end(self, ctx):
return (ctx.remaining_chars() == 1 and ctx.at_linebreak()) or ctx.at_end()
def at_end_line(self, ctx):
return ctx.at_linebreak() or ctx.at_end()
def at_end_string(self, ctx):
return ctx.at_end()
def at_boundary(self, ctx):
return ctx.at_boundary(_is_word)
def at_non_boundary(self, ctx):
return not ctx.at_boundary(_is_word)
def at_loc_boundary(self, ctx):
return ctx.at_boundary(_is_loc_word)
def at_loc_non_boundary(self, ctx):
return not ctx.at_boundary(_is_loc_word)
def at_uni_boundary(self, ctx):
return ctx.at_boundary(_is_uni_word)
def at_uni_non_boundary(self, ctx):
return not ctx.at_boundary(_is_uni_word)
def unknown(self, ctx):
return False
_AtcodeDispatcher.build_dispatch_table(ATCODES, "")
class _ChcodeDispatcher(_Dispatcher):
def category_digit(self, ctx):
return _is_digit(ctx.peek_char())
def category_not_digit(self, ctx):
return not _is_digit(ctx.peek_char())
def category_space(self, ctx):
return _is_space(ctx.peek_char())
def category_not_space(self, ctx):
return not _is_space(ctx.peek_char())
def category_word(self, ctx):
return _is_word(ctx.peek_char())
def category_not_word(self, ctx):
return not _is_word(ctx.peek_char())
def category_linebreak(self, ctx):
return _is_linebreak(ctx.peek_char())
def category_not_linebreak(self, ctx):
return not _is_linebreak(ctx.peek_char())
def category_loc_word(self, ctx):
return _is_loc_word(ctx.peek_char())
def category_loc_not_word(self, ctx):
return not _is_loc_word(ctx.peek_char())
def category_uni_digit(self, ctx):
return ctx.peek_char().isdigit()
def category_uni_not_digit(self, ctx):
return not ctx.peek_char().isdigit()
def category_uni_space(self, ctx):
return ctx.peek_char().isspace()
def category_uni_not_space(self, ctx):
return not ctx.peek_char().isspace()
def category_uni_word(self, ctx):
return _is_uni_word(ctx.peek_char())
def category_uni_not_word(self, ctx):
return not _is_uni_word(ctx.peek_char())
def category_uni_linebreak(self, ctx):
return ord(ctx.peek_char()) in _uni_linebreaks
def category_uni_not_linebreak(self, ctx):
return ord(ctx.peek_char()) not in _uni_linebreaks
def unknown(self, ctx):
return False
_ChcodeDispatcher.build_dispatch_table(CHCODES, "")
_ascii_char_info = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25, 0, 0, 0, 0, 0, 0, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0,
0, 0, 16, 0, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 0, 0, 0, 0, 0 ]
def _is_digit(char):
code = ord(char)
return code < 128 and _ascii_char_info[code] & 1
def _is_space(char):
code = ord(char)
return code < 128 and _ascii_char_info[code] & 2
def _is_word(char):
# NB: non-ASCII chars aren't words according to _sre.c
code = ord(char)
return code < 128 and _ascii_char_info[code] & 16
def _is_loc_word(char):
return (not (ord(char) & ~255) and char.isalnum()) or char == '_'
def _is_uni_word(char):
# not valid in python 3
#return unichr(ord(char)).isalnum() or char == '_'
return chr(ord(char)).isalnum() or char == '_'
def _is_linebreak(char):
return char == "\n"
# Static list of all unicode codepoints reported by Py_UNICODE_ISLINEBREAK.
_uni_linebreaks = [10, 13, 28, 29, 30, 133, 8232, 8233]
def _log(message):
if 0:
print(message)
|
gpl-3.0
|
[
3,
2845,
63,
50,
11720,
199,
624,
199,
33,
15111,
2018,
295,
12236,
402,
314,
485,
31026,
859,
687,
25654,
499,
14,
20,
199,
7384,
11811,
653,
3258,
869,
279,
3572,
1189,
12,
18233,
1334,
314,
10697,
4190,
199,
199,
2765,
1233,
365,
4079,
641,
6285,
18233,
1334,
445,
46,
6129,
1159,
2018,
413,
14,
22,
4190,
436,
199,
1574,
31816,
471,
701,
26,
1898,
334,
67,
9,
9013,
23,
13,
8339,
701,
23580,
491,
2101,
14840,
199,
624,
199,
199,
4283,
23851,
275,
21237,
16809,
10552,
199,
199,
3,
646,
1625,
199,
646,
4182,
12,
984,
199,
504,
25877,
63,
5559,
492,
15059,
15639,
12,
9827,
15639,
12,
6624,
15639,
199,
504,
25877,
63,
5559,
492,
26421,
63,
4531,
63,
6351,
12,
26421,
63,
4531,
63,
21692,
199,
504,
25877,
63,
5559,
492,
26421,
63,
3719,
63,
12819,
12,
26421,
63,
3719,
63,
20828,
421,
199,
646,
984,
199,
199,
3,
473,
848,
3338,
316,
465,
485,
31026,
687,
2018,
499,
14,
19,
503,
499,
14,
20,
199,
3,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
18,
12,
841,
304,
199,
19973,
275,
1926,
2192,
9570,
199,
3,
2836,
26,
199,
3,
259,
23336,
275,
1926,
8533,
1167,
199,
199,
3,
1010,
485,
31026,
14,
67,
642,
365,
3696,
890,
402,
314,
1233,
4349,
730,
402,
314,
445,
4514,
14,
199,
3,
6006,
652,
1159,
499,
367,
3293,
2018,
14723,
436,
1655,
367,
20239,
2649,
14723,
334,
9629,
221,
199,
3,
8321,
370,
10266,
282,
4337,
13,
2075,
21884,
13,
20,
5737,
4528,
680,
9336,
2348,
315,
15111,
2018,
199,
3,
781,
1454,
1937,
295,
3696,
6021,
465,
2018,
6132,
458,
12,
781,
9296,
1133,
1172,
370,
10296,
3595,
314,
199,
3,
1233,
890,
14,
11017,
25877,
63,
2014,
911,
6555,
2005,
8292,
23142,
10298,
641,
314,
199,
3,
1233,
890,
334,
69,
14,
71,
2020,
1495,
2193,
680,
199,
3,
6617,
543,
2366,
650,
14,
19,
221,
5099,
4448,
11025,
365,
841,
199,
3,
692,
984,
14,
988,
2975,
508,
18247,
26,
199,
3,
259,
5099,
4448,
11025,
275,
499,
199,
3,
2836,
26,
199,
15639,
11025,
275,
841,
199,
199,
7307,
275,
2668,
31026,
14,
647,
499,
14,
20,
67,
1898,
11811,
701,
653,
3258,
869,
279,
3572,
1189,
2,
421,
199,
318,
664,
600,
890,
837,
272,
372,
5099,
4448,
11025,
199,
199,
318,
6555,
8,
3401,
12,
3285,
12,
1233,
12,
4652,
29,
16,
12,
1572,
1080,
10324,
1478,
923,
1524,
403,
4682,
272,
408,
12626,
83,
334,
269,
7830,
2951,
15373,
9,
282,
3851,
5872,
370,
282,
26421,
63,
9959,
272,
909,
14,
18982,
1061,
18653,
370,
27388,
10986,
315,
25877,
63,
2014,
1041,
272,
372,
26421,
63,
9959,
8,
3401,
12,
3285,
12,
1233,
12,
4652,
12,
1572,
1080,
12,
1478,
923,
9,
1362,
199,
318,
664,
2325,
8,
1560,
63,
2181,
12,
3285,
304,
272,
340,
334,
1560,
63,
2181,
665,
7960,
9,
503,
334,
2469,
1253,
26421,
63,
3719,
63,
12819,
9,
971,
2892,
503,
334,
2469,
1253,
26421,
63,
3719,
63,
20828,
436,
1495,
63,
2181,
665,
7633,
304,
267,
327,
1107,
6206,
8,
324,
15257,
8,
1560,
63,
2181,
680,
2325,
1012,
267,
372,
6206,
8,
10194,
8,
1560,
63,
2181,
680,
2325,
1012,
272,
587,
26,
267,
372,
1495,
63,
2181,
421,
199,
533,
26421,
63,
9959,
26,
339,
347,
636,
826,
721,
277,
12,
3851,
12,
3285,
12,
1233,
12,
4652,
29,
16,
12,
1572,
1080,
10324,
1478,
923,
1524,
403,
4682,
267,
291,
14,
3401,
275,
3851,
267,
291,
14,
2469,
275,
3285,
267,
291,
14,
2634,
275,
4652,
267,
291,
14,
923,
1080,
275,
1572,
1080,
327,
23673,
1572,
1561,
370,
1572,
4918,
267,
291,
423,
1080,
923,
275,
1478,
923,
327,
23673,
4918,
370,
1572,
1561,
267,
291,
423,
600,
275,
1233,
2286,
347,
1336,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
3917,
4697,
503,
1655,
4110,
737,
314,
9608,
402,
1059,
1336,
642,
267,
5578,
3965,
12,
372,
282,
5226,
9814,
1692,
1256,
14,
1432,
267,
488,
340,
314,
1059,
1630,
440,
1336,
314,
3851,
1041,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
340,
1174,
14,
1431,
8,
277,
423,
600,
304,
288,
372,
26421,
63,
4486,
8,
277,
12,
1174,
9,
267,
372,
488,
339,
347,
2754,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
15936,
4012,
1059,
10023,
367,
282,
2909,
2382,
642,
5578,
267,
3965,
16904,
282,
1336,
12,
436,
372,
282,
5226,
9814,
1692,
267,
1256,
14,
1432,
488,
340,
949,
3421,
315,
314,
1059,
4450,
314,
267,
3851,
1041,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
340,
1174,
14,
1733,
8,
277,
423,
600,
304,
288,
372,
26421,
63,
4486,
8,
277,
12,
1174,
9,
267,
587,
26,
288,
372,
488,
339,
347,
2342,
452,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
1767,
282,
769,
402,
1006,
2222,
13,
31034,
4450,
402,
3851,
315,
1059,
1041,
267,
1336,
513,
275,
942,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
1830,
1174,
14,
928,
2695,
1174,
14,
500,
26,
288,
1174,
14,
3958,
342,
288,
1174,
14,
875,
63,
3124,
275,
1174,
14,
928,
288,
340,
440,
1174,
14,
1733,
8,
277,
423,
600,
304,
355,
2059,
288,
1336,
275,
26421,
63,
4486,
8,
277,
12,
1174,
9,
288,
340,
291,
14,
2634,
508,
378,
503,
291,
14,
2634,
508,
413,
26,
355,
1242,
275,
1336,
14,
923,
8,
277,
14,
2634,
9,
288,
587,
26,
355,
1242,
275,
1336,
14,
2634,
10804,
288,
1336,
513,
14,
740,
8,
1053,
9,
288,
340,
1174,
14,
875,
63,
3124,
508,
1174,
14,
928,
26,
355,
1174,
14,
928,
847,
413,
288,
587,
26,
355,
1174,
14,
928,
275,
1174,
14,
875,
63,
3124,
267,
372,
1336,
513,
260,
5493,
347,
485,
954,
88,
8,
277,
12,
1978,
12,
1059,
12,
2338,
29
] |
[
2845,
63,
50,
11720,
199,
624,
199,
33,
15111,
2018,
295,
12236,
402,
314,
485,
31026,
859,
687,
25654,
499,
14,
20,
199,
7384,
11811,
653,
3258,
869,
279,
3572,
1189,
12,
18233,
1334,
314,
10697,
4190,
199,
199,
2765,
1233,
365,
4079,
641,
6285,
18233,
1334,
445,
46,
6129,
1159,
2018,
413,
14,
22,
4190,
436,
199,
1574,
31816,
471,
701,
26,
1898,
334,
67,
9,
9013,
23,
13,
8339,
701,
23580,
491,
2101,
14840,
199,
624,
199,
199,
4283,
23851,
275,
21237,
16809,
10552,
199,
199,
3,
646,
1625,
199,
646,
4182,
12,
984,
199,
504,
25877,
63,
5559,
492,
15059,
15639,
12,
9827,
15639,
12,
6624,
15639,
199,
504,
25877,
63,
5559,
492,
26421,
63,
4531,
63,
6351,
12,
26421,
63,
4531,
63,
21692,
199,
504,
25877,
63,
5559,
492,
26421,
63,
3719,
63,
12819,
12,
26421,
63,
3719,
63,
20828,
421,
199,
646,
984,
199,
199,
3,
473,
848,
3338,
316,
465,
485,
31026,
687,
2018,
499,
14,
19,
503,
499,
14,
20,
199,
3,
692,
984,
14,
1023,
63,
815,
1491,
18,
61,
2356,
334,
18,
12,
841,
304,
199,
19973,
275,
1926,
2192,
9570,
199,
3,
2836,
26,
199,
3,
259,
23336,
275,
1926,
8533,
1167,
199,
199,
3,
1010,
485,
31026,
14,
67,
642,
365,
3696,
890,
402,
314,
1233,
4349,
730,
402,
314,
445,
4514,
14,
199,
3,
6006,
652,
1159,
499,
367,
3293,
2018,
14723,
436,
1655,
367,
20239,
2649,
14723,
334,
9629,
221,
199,
3,
8321,
370,
10266,
282,
4337,
13,
2075,
21884,
13,
20,
5737,
4528,
680,
9336,
2348,
315,
15111,
2018,
199,
3,
781,
1454,
1937,
295,
3696,
6021,
465,
2018,
6132,
458,
12,
781,
9296,
1133,
1172,
370,
10296,
3595,
314,
199,
3,
1233,
890,
14,
11017,
25877,
63,
2014,
911,
6555,
2005,
8292,
23142,
10298,
641,
314,
199,
3,
1233,
890,
334,
69,
14,
71,
2020,
1495,
2193,
680,
199,
3,
6617,
543,
2366,
650,
14,
19,
221,
5099,
4448,
11025,
365,
841,
199,
3,
692,
984,
14,
988,
2975,
508,
18247,
26,
199,
3,
259,
5099,
4448,
11025,
275,
499,
199,
3,
2836,
26,
199,
15639,
11025,
275,
841,
199,
199,
7307,
275,
2668,
31026,
14,
647,
499,
14,
20,
67,
1898,
11811,
701,
653,
3258,
869,
279,
3572,
1189,
2,
421,
199,
318,
664,
600,
890,
837,
272,
372,
5099,
4448,
11025,
199,
199,
318,
6555,
8,
3401,
12,
3285,
12,
1233,
12,
4652,
29,
16,
12,
1572,
1080,
10324,
1478,
923,
1524,
403,
4682,
272,
408,
12626,
83,
334,
269,
7830,
2951,
15373,
9,
282,
3851,
5872,
370,
282,
26421,
63,
9959,
272,
909,
14,
18982,
1061,
18653,
370,
27388,
10986,
315,
25877,
63,
2014,
1041,
272,
372,
26421,
63,
9959,
8,
3401,
12,
3285,
12,
1233,
12,
4652,
12,
1572,
1080,
12,
1478,
923,
9,
1362,
199,
318,
664,
2325,
8,
1560,
63,
2181,
12,
3285,
304,
272,
340,
334,
1560,
63,
2181,
665,
7960,
9,
503,
334,
2469,
1253,
26421,
63,
3719,
63,
12819,
9,
971,
2892,
503,
334,
2469,
1253,
26421,
63,
3719,
63,
20828,
436,
1495,
63,
2181,
665,
7633,
304,
267,
327,
1107,
6206,
8,
324,
15257,
8,
1560,
63,
2181,
680,
2325,
1012,
267,
372,
6206,
8,
10194,
8,
1560,
63,
2181,
680,
2325,
1012,
272,
587,
26,
267,
372,
1495,
63,
2181,
421,
199,
533,
26421,
63,
9959,
26,
339,
347,
636,
826,
721,
277,
12,
3851,
12,
3285,
12,
1233,
12,
4652,
29,
16,
12,
1572,
1080,
10324,
1478,
923,
1524,
403,
4682,
267,
291,
14,
3401,
275,
3851,
267,
291,
14,
2469,
275,
3285,
267,
291,
14,
2634,
275,
4652,
267,
291,
14,
923,
1080,
275,
1572,
1080,
327,
23673,
1572,
1561,
370,
1572,
4918,
267,
291,
423,
1080,
923,
275,
1478,
923,
327,
23673,
4918,
370,
1572,
1561,
267,
291,
423,
600,
275,
1233,
2286,
347,
1336,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
3917,
4697,
503,
1655,
4110,
737,
314,
9608,
402,
1059,
1336,
642,
267,
5578,
3965,
12,
372,
282,
5226,
9814,
1692,
1256,
14,
1432,
267,
488,
340,
314,
1059,
1630,
440,
1336,
314,
3851,
1041,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
340,
1174,
14,
1431,
8,
277,
423,
600,
304,
288,
372,
26421,
63,
4486,
8,
277,
12,
1174,
9,
267,
372,
488,
339,
347,
2754,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
15936,
4012,
1059,
10023,
367,
282,
2909,
2382,
642,
5578,
267,
3965,
16904,
282,
1336,
12,
436,
372,
282,
5226,
9814,
1692,
267,
1256,
14,
1432,
488,
340,
949,
3421,
315,
314,
1059,
4450,
314,
267,
3851,
1041,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
340,
1174,
14,
1733,
8,
277,
423,
600,
304,
288,
372,
26421,
63,
4486,
8,
277,
12,
1174,
9,
267,
587,
26,
288,
372,
488,
339,
347,
2342,
452,
8,
277,
12,
1059,
12,
2086,
29,
16,
12,
26690,
29,
1274,
14,
13634,
304,
267,
408,
1767,
282,
769,
402,
1006,
2222,
13,
31034,
4450,
402,
3851,
315,
1059,
1041,
267,
1336,
513,
275,
942,
267,
1174,
275,
485,
2223,
8,
875,
12,
2086,
12,
26690,
12,
291,
14,
2469,
9,
267,
1830,
1174,
14,
928,
2695,
1174,
14,
500,
26,
288,
1174,
14,
3958,
342,
288,
1174,
14,
875,
63,
3124,
275,
1174,
14,
928,
288,
340,
440,
1174,
14,
1733,
8,
277,
423,
600,
304,
355,
2059,
288,
1336,
275,
26421,
63,
4486,
8,
277,
12,
1174,
9,
288,
340,
291,
14,
2634,
508,
378,
503,
291,
14,
2634,
508,
413,
26,
355,
1242,
275,
1336,
14,
923,
8,
277,
14,
2634,
9,
288,
587,
26,
355,
1242,
275,
1336,
14,
2634,
10804,
288,
1336,
513,
14,
740,
8,
1053,
9,
288,
340,
1174,
14,
875,
63,
3124,
508,
1174,
14,
928,
26,
355,
1174,
14,
928,
847,
413,
288,
587,
26,
355,
1174,
14,
928,
275,
1174,
14,
875,
63,
3124,
267,
372,
1336,
513,
260,
5493,
347,
485,
954,
88,
8,
277,
12,
1978,
12,
1059,
12,
2338,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
PALab/PLACE
|
place/plugins/ds345_function_gen/ds345_driver.py
|
1
|
13211
|
"""Driver module for Stanford Research Systems DS345 Function Generator."""
import serial
class DS345Driver:
#pylint: disable=too-many-public-methods
"""Class for low-level access to the function generator settings."""
def __init__(self, serial_port):
self._serial_port = str(serial_port)
# FUNCTION OUTPUT CONTROL COMMANDS
def aecl(self):
"""Sets the output to the ECL levels of 1 V peak-to-peak with a -1.3 V offset."""
self._set('AECL')
def ampl(self, amplitude=None, units='Vpp'):
"""Sets or queries the output amplitude."""
unit_opts = {'Vpp': 'VP', 'Vrms': 'VR', 'dBm': 'DB'}
if amplitude is None:
if units is None:
res = self._query('AMPL?')
else:
res = self._query('AMPL? {}'.format(unit_opts[units]))
amp, unit_opt = res[:-2], res[-2:]
try:
unit = next(key for key, value in unit_opts.items()
if value == unit_opt)
except StopIteration:
raise RuntimeError(
'Could not determine unit for string {}'.format(res))
return float(amp), unit
self._set('AMPL {:.6f}{}'.format(amplitude, unit_opts[units]))
def attl(self):
"""Sets the TTL output levels to 5 V peak-to-peak with a 2.5 V offset."""
self._set('ATTL')
def freq(self, frequency=None):
"""Sets or queries the output frequency."""
if frequency is None:
return float(self._query('FREQ?'))
self._set('FREQ {:.6f}'.format(frequency))
def fsmp(self, frequency=None):
"""Sets or queries the arbitrary waveform sampling frequency."""
if frequency is None:
return float(self._query('FSMP?'))
self._set('FSMP {:.6f}'.format(frequency))
def func(self, function_type=None):
"""Sets or queries the output frequency type."""
types = ['SINE', 'SQUARE', 'TRIANGLE', 'RAMP', 'NOISE', 'ARBITRARY']
if function_type is None:
return types[int(self._query('FUNC?'))]
self._set('FUNC {:d}'.format(types.index(function_type.upper())))
def invt(self, output_inversion=None):
"""Sets or queries the output inversion value."""
opts = ['off', 'on']
if output_inversion is None:
return opts[int(self._query('INVT?'))]
self._set('INVT {:d}'.format(opts.index(output_inversion)))
def offs(self, dc_offset=None):
"""Sets or queries the output's DC offset."""
if dc_offset is None:
return float(self._query('OFFS?'))
self._set('OFFS {:.6f}'.format(dc_offset))
def pclr(self):
"""Sets the waveform phase value to 0."""
self._set('PCLR')
def phse(self, output_phase=None):
"""Sets or queries the waveform output phase."""
if output_phase is None:
self._query('*ESR? 4')
resp = self._query('PHSE?')
if self._query('*ESR? 4') != 0:
return 'Execution err'
return float(resp)
self._set('PHSE {:.6f}'.format(output_phase))
# MODULATION CONTROL COMMANDS
def trg(self):
"""Triggers a burst or single sweep."""
if self.tsrc() != 'SINGLE':
raise RuntimeError("Cannot trigger a burst or single sweep when " +
"trigger source is not 'single'.")
self._set('*TRG')
def bcnt(self, count=None):
"""Sets or queries the burst count."""
if count is None:
return int(self._query('BCNT?'))
if 1 <= count <= 30000:
self._set('BCNT {:d}'.format(count))
else:
raise ValueError(
'Burst count must be between 1 and 30000 (inclusive)')
def dpth(self, depth=None):
"""Sets or queries the AM modulation depth percentage.
If the depth is negative, the modulation is set to double sideband
suppressed carrier modulation (DSBSC).
"""
if depth is None:
return int(self._query('DPTH?'))
if -100 <= depth <= 100:
self._set('DPTH {:d}'.format(depth))
else:
raise ValueError(
'AM modulation depth percentage must be between -100 and 100.')
def fdev(self, span=None):
"""Sets or queries the FM span."""
if span is None:
return float(self._query('FDEV?'))
self._set('FDEV {:.6f}'.format(span))
def mdwf(self, waveform=None):
"""Sets or queries the modulation waveform."""
opts = ['SINGLE SWEEP', 'RAMP', 'TRIANGLE',
'SINE', 'SQUARE', 'ARB', 'NONE']
if waveform is None:
return opts[int(self._query('MDWF?'))]
self._set('MDWF {:d}'.format(opts.index(waveform.upper())))
def mena(self, modulation=None):
"""Set or queries whether modulation is enabled."""
if modulation is None:
return int(self._query('MENA?')) == 1
if modulation is False:
self._set('MENA 0')
else:
self._set('MENA 1')
def mksp(self):
"""Sets the sweep markers to the extremes of the sweep span."""
self._set('MKSP')
def mrkf(self, marker, frequency=None):
"""Sets or queries one of the sweep markers."""
markers = ['START', 'STOP', 'CENTER', 'SPAN']
if frequency is None:
return float(self._query('MRKF? {:d}'.format(markers.index(marker.upper()))))
self._set('MRKF {:d} {:.6f}'.format(
markers.index(marker.upper()), frequency))
def mtyp(self, modulation=None):
"""Sets or queries the modulation type."""
types = ['LIN SWEEP', 'LOG SWEEP',
'INTERNAL AM', 'FM', 'PHI_M', 'BURST']
if modulation is None:
return types[int(self._query('MTYP?'))]
self._set('MTYP {:d}'.format(types.index(modulation.upper())))
def pdev(self, span=None):
"""Sets or queries the span of the phase modulation."""
if span is None:
return float(self._query('PDEV?'))
self._set('PDEV {:.6f}'.format(span))
def rate(self, rate=None):
"""Sets or queries the modulation rate."""
if rate is None:
return float(self._query('RATE?'))
self._set('RATE {:.3f}'.format(rate))
def span(self, span=None):
"""Sets or queries the sweep span."""
if span is None:
return float(self._query('SPAN?'))
self._set('SPAN {:.6f}'.format(span))
def spcf(self, frequency=None):
"""Sets or queries the sweep center frequency."""
if frequency is None:
return float(self._query('SPCF?'))
self._set('SPCF {:.6f}'.format(frequency))
def spfr(self, frequency=None):
"""Sets or queries the sweep stop frequency."""
if frequency is None:
return float(self._query('SPFR?'))
self._set('SPFR {:.6f}'.format(frequency))
def spmk(self):
"""Sets the sweep span to the sweep marker frequency."""
self._set('SPMK')
def stfr(self, frequency=None):
"""Sets or queries the sweep start frequency."""
if frequency is None:
return float(self._query('STFR?'))
self._set('STFR {:.6f}'.format(frequency))
def trat(self, rate=None):
"""Sets or queries the trigger rate for internally triggered single sweeps."""
if rate is None:
return float(self._query('TRAT?'))
self._set('TRAT {:.6f}'.format(rate))
def tsrc(self, source=None):
"""Sets or queries the trigger source for bursts and sweeps."""
opts = ['SINGLE', 'INTERNAL RATE',
'+ SLOPE EXTERNAL', '- SLOPE EXTERNAL', 'LINE']
if source is None:
return opts[int(self._query('TSRC?'))]
self._set('TSRC {:d}'.format(opts.index(source.upper())))
# ARBITRARY WAVEFORM AND MODULATION COMMANDS
def amrt(self, rate=None):
"""Sets or queries the arbitrary modulation rate divider."""
if rate is None:
return int(self._query('AMRT?'))
self._set('AMRT {:d}'.format(rate))
def amod(self, length):
"""Allow downloading arbitrary waveform and modulation patterns.
*Not implemented*
"""
raise NotImplementedError
def ldwf(self, format_, data_length):
"""Allows downloading arbitrary waveforms in either point or vector format.
*Not implemented*
"""
raise NotImplementedError
# SETUP CONTROL COMMANDS
def idn(self):
"""Returns the device configuration."""
return self._query('*IDN?')
def rcl(self, number):
"""Recalls stored settings."""
if 0 <= number <= 9:
self._set('*RCL {:d}'.format(number))
else:
raise ValueError('Setting number must be between 0 and 9.')
def rst(self):
"""Resets the device to default configurations."""
self._set('*RST')
def sav(self, number):
"""Saves settings to internal storage."""
if 0 <= number <= 9:
self._set('*SAV {:d}'.format(number))
else:
raise ValueError('Setting number must be between 0 and 9.')
# STATUS REPORTING COMMANDS
def cls(self):
"""Clears all status registers."""
self._set('*CLS')
def ese(self, value=None):
"""Sets or queries the standard event status byte enable register."""
if value is None:
return int(self._query('*ESE?'))
self._set('*ESE {:d}'.format(value))
def esr(self, bit=None):
"""Reads and then clears that value of the standard event status register."""
if bit is None:
return int(self._query('*ESR?'))
return int(self._query('*ESR? {:d}'.format(bit)))
def psc(self, bit=None):
"""Sets or queries the power-on status clear bit."""
if bit is None:
return int(self._query('*PSC?'))
self._set('*PSC {:d}'.format(bit))
def sre(self, value=None):
"""Sets or queries the value of the serial poll enable register."""
if value is None:
return int(self._query('*SRE?'))
self._set('*SRE {:d}'.format(value))
def stb(self, bit=None):
"""Reads the value of the serial poll byte or a specific bit."""
if bit is None:
return int(self._query('*STB?'))
return int(self._query('*STB? {:d}'.format(bit)))
def dena(self, value=None):
"""Sets or queries the DDS status enable register."""
if value is None:
return int(self._query('DENA?'))
self._set('DENA {:d}'.format(value))
def stat(self, bit=None):
"""Reads the value of the DDS status byte or a specific bit."""
if bit is None:
return int(self._query('STAT?'))
return int(self._query('STAT? {:d}'.format(bit)))
# HARDWARE TEST AND CALIBRATION COMMANDS
def cal(self):
"""Initiates the device calibration routines.
*Not implemented*
"""
raise NotImplementedError
def tst(self):
"""Runs the internal self-tests.
*Not implemented*
"""
raise NotImplementedError
def atd(self, range_=None):
"""Sets or queries the output attenuators.
*Not implemented*
"""
raise NotImplementedError
def fcl(self):
"""Recalls the factory calibration bytes.
*Not implemented*
"""
raise NotImplementedError
def mdc(self, mimic_dac):
"""Sets the mimic DAC to the given value.
*Not Implemented*
"""
raise NotImplementedError
def wrd(self, word, value=None):
"""Set or queries the value of a calibration word.
*Not implemented*
"""
raise NotImplementedError
# HELPER METHODS
def _set(self, cmd):
"""Sets a value on the function generator.
:param cmd: the command to send over the serial port
:type cmd: str
"""
with serial.Serial(self._serial_port,
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
timeout=2) as connection:
connection.write(bytes(cmd + '\n', 'ascii'))
def _query(self, cmd):
"""Request a value from the function generator.
:param cmd: the command to send over the serial port
:type cmd: str
:returns: the response on the serial connection
:rtype: str
"""
with serial.Serial(self._serial_port,
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_TWO,
timeout=2) as connection:
connection.write(bytes(cmd + '\n', 'ascii'))
resp = connection.readline().decode('ascii').strip()
return resp
|
lgpl-3.0
|
[
624,
6158,
859,
367,
1933,
290,
18090,
26993,
15285,
577,
51,
9908,
6801,
15042,
1041,
199,
199,
646,
3012,
421,
199,
533,
577,
51,
9908,
6158,
26,
272,
327,
26324,
26,
3507,
29,
7354,
13,
3479,
13,
3455,
13,
2474,
272,
408,
2543,
367,
6465,
13,
1896,
2879,
370,
314,
805,
4306,
2202,
1041,
339,
347,
636,
826,
721,
277,
12,
3012,
63,
719,
304,
267,
291,
423,
2171,
63,
719,
275,
620,
8,
2171,
63,
719,
9,
199,
199,
3,
32744,
18746,
8098,
11293,
20033,
339,
347,
16951,
429,
8,
277,
304,
267,
408,
9899,
314,
1072,
370,
314,
662,
1981,
11106,
402,
413,
812,
21441,
13,
475,
13,
8556,
543,
282,
446,
17,
14,
19,
812,
3268,
1041,
267,
291,
423,
409,
360,
12500,
1981,
358,
339,
347,
282,
2421,
8,
277,
12,
30727,
29,
403,
12,
6204,
534,
54,
802,
735,
267,
408,
9899,
503,
9212,
314,
1072,
30727,
1041,
267,
4137,
63,
3291,
275,
791,
54,
802,
356,
283,
14159,
297,
283,
54,
24444,
356,
283,
20271,
297,
283,
26256,
77,
356,
283,
2846,
936,
267,
340,
30727,
365,
488,
26,
288,
340,
6204,
365,
488,
26,
355,
522,
275,
291,
423,
1131,
360,
7855,
18478,
288,
587,
26,
355,
522,
275,
291,
423,
1131,
360,
7855,
31,
9499,
908,
8,
3248,
63,
3291,
59,
5260,
2459,
288,
15204,
12,
4137,
63,
2992,
275,
522,
4439,
18,
467,
522,
1988,
18,
2938,
288,
862,
26,
355,
4137,
275,
2163,
8,
498,
367,
790,
12,
574,
315,
4137,
63,
3291,
14,
1744,
342,
1169,
340,
574,
508,
4137,
63,
2992,
9,
288,
871,
10852,
26,
355,
746,
6064,
8,
490,
283,
6531,
440,
6705,
4137,
367,
1059,
9499,
908,
8,
470,
430,
288,
372,
2069,
8,
5282,
395,
4137,
267,
291,
423,
409,
360,
7855,
469,
14010,
22,
70,
93,
11123,
908,
8,
31928,
12,
4137,
63,
3291,
59,
5260,
2459,
339,
347,
737,
5019,
8,
277,
304,
267,
408,
9899,
314,
30822,
1072,
11106,
370,
959,
812,
21441,
13,
475,
13,
8556,
543,
282,
499,
14,
21,
812,
3268,
1041,
267,
291,
423,
409,
360,
619,
7308,
358,
339,
347,
9220,
8,
277,
12,
9857,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
9857,
1041,
267,
340,
9857,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
38,
14583,
31,
1333,
267,
291,
423,
409,
360,
38,
14583,
469,
14010,
22,
70,
5285,
908,
8,
11132,
430,
339,
347,
7449,
311,
8,
277,
12,
9857,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
9697,
12204,
964,
15877,
9857,
1041,
267,
340,
9857,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
7079,
1658,
31,
1333,
267,
291,
423,
409,
360,
7079,
1658,
469,
14010,
22,
70,
5285,
908,
8,
11132,
430,
339,
347,
2562,
8,
277,
12,
805,
63,
466,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
9857,
730,
1041,
267,
2943,
275,
788,
51,
3565,
297,
283,
51,
14424,
297,
283,
1766,
41,
30421,
297,
283,
50,
7089,
297,
283,
2826,
4971,
297,
283,
8611,
649,
50,
4392,
418,
267,
340,
805,
63,
466,
365,
488,
26,
288,
372,
2943,
59,
442,
8,
277,
423,
1131,
360,
19587,
31,
27738,
267,
291,
423,
409,
360,
19587,
19850,
68,
5285,
908,
8,
1313,
14,
1080,
8,
1593,
63,
466,
14,
4142,
16890,
339,
347,
4572,
84,
8,
277,
12,
1072,
63,
262,
1023,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
315,
1023,
574,
1041,
267,
3999,
275,
788,
1997,
297,
283,
265,
418,
267,
340,
1072,
63,
262,
1023,
365,
488,
26,
288,
372,
3999,
59,
442,
8,
277,
423,
1131,
360,
568,
8156,
31,
27738,
267,
291,
423,
409,
360,
568,
8156,
19850,
68,
5285,
908,
8,
3291,
14,
1080,
8,
1199,
63,
262,
1023,
1724,
339,
347,
402,
2319,
8,
277,
12,
12326,
63,
2743,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
1159,
30592,
3268,
1041,
267,
340,
12326,
63,
2743,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
7517,
51,
31,
1333,
267,
291,
423,
409,
360,
7517,
51,
469,
14010,
22,
70,
5285,
908,
8,
3833,
63,
2743,
430,
339,
347,
299,
31553,
8,
277,
304,
267,
408,
9899,
314,
12204,
964,
7669,
574,
370,
378,
1041,
267,
291,
423,
409,
360,
48,
25346,
358,
339,
347,
3945,
261,
8,
277,
12,
1072,
63,
6971,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
12204,
964,
1072,
7669,
1041,
267,
340,
1072,
63,
6971,
365,
488,
26,
288,
291,
423,
1131,
18225,
654,
50,
31,
841,
358,
288,
3085,
275,
291,
423,
1131,
360,
9791,
899,
18478,
288,
340,
291,
423,
1131,
18225,
654,
50,
31,
841,
358,
1137,
378,
26,
355,
372,
283,
11310,
2329,
7,
288,
372,
2069,
8,
4518,
9,
267,
291,
423,
409,
360,
9791,
899,
469,
14010,
22,
70,
5285,
908,
8,
1199,
63,
6971,
430,
199,
199,
3,
30920,
19531,
8098,
11293,
20033,
339,
347,
5651,
71,
8,
277,
304,
267,
408,
16276,
83,
282,
330,
13305,
503,
2849,
5584,
7840,
1041,
267,
340,
291,
14,
1086,
1195,
342,
1137,
283,
16425,
356,
288,
746,
6064,
480,
6612,
6804,
282,
330,
13305,
503,
2849,
5584,
7840,
1380,
298,
435,
3044,
298,
7631,
1350,
365,
440,
283,
4780,
29435,
267,
291,
423,
409,
18225,
1766,
39,
358,
339,
347,
330,
6507,
8,
277,
12,
2338,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
330,
13305,
2338,
1041,
267,
340,
2338,
365,
488,
26,
288,
372,
1109,
8,
277,
423,
1131,
360,
6265,
12460,
31,
1333,
267,
340,
413,
2695,
2338,
2695,
650,
993,
26,
288,
291,
423,
409,
360,
6265,
12460,
19850,
68,
5285,
908,
8,
835,
430,
267,
587,
26,
288,
746,
1722,
8,
355,
283,
20468,
2338,
1471,
506,
3382,
413,
436,
650,
993,
334,
26062,
5942,
339,
347,
12392,
273,
8,
277,
12,
5818,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
24343,
3413,
5332,
5818,
16327,
14,
398,
982,
314,
5818,
365,
6946,
12,
314,
3413,
5332,
365,
663,
370,
4270,
5366,
7877,
267,
30581,
9590,
10742,
3413,
5332,
334,
3177,
34,
5153,
680,
267,
408
] |
[
6158,
859,
367,
1933,
290,
18090,
26993,
15285,
577,
51,
9908,
6801,
15042,
1041,
199,
199,
646,
3012,
421,
199,
533,
577,
51,
9908,
6158,
26,
272,
327,
26324,
26,
3507,
29,
7354,
13,
3479,
13,
3455,
13,
2474,
272,
408,
2543,
367,
6465,
13,
1896,
2879,
370,
314,
805,
4306,
2202,
1041,
339,
347,
636,
826,
721,
277,
12,
3012,
63,
719,
304,
267,
291,
423,
2171,
63,
719,
275,
620,
8,
2171,
63,
719,
9,
199,
199,
3,
32744,
18746,
8098,
11293,
20033,
339,
347,
16951,
429,
8,
277,
304,
267,
408,
9899,
314,
1072,
370,
314,
662,
1981,
11106,
402,
413,
812,
21441,
13,
475,
13,
8556,
543,
282,
446,
17,
14,
19,
812,
3268,
1041,
267,
291,
423,
409,
360,
12500,
1981,
358,
339,
347,
282,
2421,
8,
277,
12,
30727,
29,
403,
12,
6204,
534,
54,
802,
735,
267,
408,
9899,
503,
9212,
314,
1072,
30727,
1041,
267,
4137,
63,
3291,
275,
791,
54,
802,
356,
283,
14159,
297,
283,
54,
24444,
356,
283,
20271,
297,
283,
26256,
77,
356,
283,
2846,
936,
267,
340,
30727,
365,
488,
26,
288,
340,
6204,
365,
488,
26,
355,
522,
275,
291,
423,
1131,
360,
7855,
18478,
288,
587,
26,
355,
522,
275,
291,
423,
1131,
360,
7855,
31,
9499,
908,
8,
3248,
63,
3291,
59,
5260,
2459,
288,
15204,
12,
4137,
63,
2992,
275,
522,
4439,
18,
467,
522,
1988,
18,
2938,
288,
862,
26,
355,
4137,
275,
2163,
8,
498,
367,
790,
12,
574,
315,
4137,
63,
3291,
14,
1744,
342,
1169,
340,
574,
508,
4137,
63,
2992,
9,
288,
871,
10852,
26,
355,
746,
6064,
8,
490,
283,
6531,
440,
6705,
4137,
367,
1059,
9499,
908,
8,
470,
430,
288,
372,
2069,
8,
5282,
395,
4137,
267,
291,
423,
409,
360,
7855,
469,
14010,
22,
70,
93,
11123,
908,
8,
31928,
12,
4137,
63,
3291,
59,
5260,
2459,
339,
347,
737,
5019,
8,
277,
304,
267,
408,
9899,
314,
30822,
1072,
11106,
370,
959,
812,
21441,
13,
475,
13,
8556,
543,
282,
499,
14,
21,
812,
3268,
1041,
267,
291,
423,
409,
360,
619,
7308,
358,
339,
347,
9220,
8,
277,
12,
9857,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
9857,
1041,
267,
340,
9857,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
38,
14583,
31,
1333,
267,
291,
423,
409,
360,
38,
14583,
469,
14010,
22,
70,
5285,
908,
8,
11132,
430,
339,
347,
7449,
311,
8,
277,
12,
9857,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
9697,
12204,
964,
15877,
9857,
1041,
267,
340,
9857,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
7079,
1658,
31,
1333,
267,
291,
423,
409,
360,
7079,
1658,
469,
14010,
22,
70,
5285,
908,
8,
11132,
430,
339,
347,
2562,
8,
277,
12,
805,
63,
466,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
9857,
730,
1041,
267,
2943,
275,
788,
51,
3565,
297,
283,
51,
14424,
297,
283,
1766,
41,
30421,
297,
283,
50,
7089,
297,
283,
2826,
4971,
297,
283,
8611,
649,
50,
4392,
418,
267,
340,
805,
63,
466,
365,
488,
26,
288,
372,
2943,
59,
442,
8,
277,
423,
1131,
360,
19587,
31,
27738,
267,
291,
423,
409,
360,
19587,
19850,
68,
5285,
908,
8,
1313,
14,
1080,
8,
1593,
63,
466,
14,
4142,
16890,
339,
347,
4572,
84,
8,
277,
12,
1072,
63,
262,
1023,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
315,
1023,
574,
1041,
267,
3999,
275,
788,
1997,
297,
283,
265,
418,
267,
340,
1072,
63,
262,
1023,
365,
488,
26,
288,
372,
3999,
59,
442,
8,
277,
423,
1131,
360,
568,
8156,
31,
27738,
267,
291,
423,
409,
360,
568,
8156,
19850,
68,
5285,
908,
8,
3291,
14,
1080,
8,
1199,
63,
262,
1023,
1724,
339,
347,
402,
2319,
8,
277,
12,
12326,
63,
2743,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
1072,
1159,
30592,
3268,
1041,
267,
340,
12326,
63,
2743,
365,
488,
26,
288,
372,
2069,
8,
277,
423,
1131,
360,
7517,
51,
31,
1333,
267,
291,
423,
409,
360,
7517,
51,
469,
14010,
22,
70,
5285,
908,
8,
3833,
63,
2743,
430,
339,
347,
299,
31553,
8,
277,
304,
267,
408,
9899,
314,
12204,
964,
7669,
574,
370,
378,
1041,
267,
291,
423,
409,
360,
48,
25346,
358,
339,
347,
3945,
261,
8,
277,
12,
1072,
63,
6971,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
12204,
964,
1072,
7669,
1041,
267,
340,
1072,
63,
6971,
365,
488,
26,
288,
291,
423,
1131,
18225,
654,
50,
31,
841,
358,
288,
3085,
275,
291,
423,
1131,
360,
9791,
899,
18478,
288,
340,
291,
423,
1131,
18225,
654,
50,
31,
841,
358,
1137,
378,
26,
355,
372,
283,
11310,
2329,
7,
288,
372,
2069,
8,
4518,
9,
267,
291,
423,
409,
360,
9791,
899,
469,
14010,
22,
70,
5285,
908,
8,
1199,
63,
6971,
430,
199,
199,
3,
30920,
19531,
8098,
11293,
20033,
339,
347,
5651,
71,
8,
277,
304,
267,
408,
16276,
83,
282,
330,
13305,
503,
2849,
5584,
7840,
1041,
267,
340,
291,
14,
1086,
1195,
342,
1137,
283,
16425,
356,
288,
746,
6064,
480,
6612,
6804,
282,
330,
13305,
503,
2849,
5584,
7840,
1380,
298,
435,
3044,
298,
7631,
1350,
365,
440,
283,
4780,
29435,
267,
291,
423,
409,
18225,
1766,
39,
358,
339,
347,
330,
6507,
8,
277,
12,
2338,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
330,
13305,
2338,
1041,
267,
340,
2338,
365,
488,
26,
288,
372,
1109,
8,
277,
423,
1131,
360,
6265,
12460,
31,
1333,
267,
340,
413,
2695,
2338,
2695,
650,
993,
26,
288,
291,
423,
409,
360,
6265,
12460,
19850,
68,
5285,
908,
8,
835,
430,
267,
587,
26,
288,
746,
1722,
8,
355,
283,
20468,
2338,
1471,
506,
3382,
413,
436,
650,
993,
334,
26062,
5942,
339,
347,
12392,
273,
8,
277,
12,
5818,
29,
403,
304,
267,
408,
9899,
503,
9212,
314,
24343,
3413,
5332,
5818,
16327,
14,
398,
982,
314,
5818,
365,
6946,
12,
314,
3413,
5332,
365,
663,
370,
4270,
5366,
7877,
267,
30581,
9590,
10742,
3413,
5332,
334,
3177,
34,
5153,
680,
267,
408,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
CG-F16-24-Rutgers/steersuite-rutgers
|
steerstats/tools/deap/tests/test_pickle.py
|
9
|
4499
|
import sys
import unittest
import array
import pickle
import operator
from test import test_support
sys.path.append("..")
import numpy
import creator
import base
import gp
import tools
def func():
return "True"
class Pickling(unittest.TestCase):
def setUp(self):
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("IndList", list, fitness=creator.FitnessMax)
creator.create("IndArray", array.array, typecode='f', fitness=creator.FitnessMax)
creator.create("IndTree", gp.PrimitiveTree, fitness=creator.FitnessMax)
self.toolbox = base.Toolbox()
self.toolbox.register("func", func)
self.toolbox.register("lambda_func", lambda: "True")
def test_pickle_fitness(self):
fitness = creator.FitnessMax()
fitness.values = (1.0,)
fitness_s = pickle.dumps(fitness)
fitness_l = pickle.loads(fitness_s)
self.failUnlessEqual(fitness, fitness_l, "Unpickled fitness != pickled fitness")
def test_pickle_ind_list(self):
ind = creator.IndList([1.0, 2.0, 3.0])
ind.fitness.values = (4.0,)
ind_s = pickle.dumps(ind)
ind_l = pickle.loads(ind_s)
self.failUnlessEqual(ind, ind_l, "Unpickled individual list != pickled individual list")
self.failUnlessEqual(ind.fitness, ind_l.fitness, "Unpickled individual fitness != pickled individual fitness")
def test_pickle_ind_array(self):
ind = creator.IndArray([1.0, 2.0, 3.0])
ind.fitness.values = (4.0,)
ind_s = pickle.dumps(ind)
ind_l = pickle.loads(ind_s)
self.failUnlessEqual(ind, ind_l, "Unpickled individual array != pickled individual array")
self.failUnlessEqual(ind.fitness, ind_l.fitness, "Unpickled individual fitness != pickled individual fitness")
def test_pickle_tree(self):
ind = creator.IndTree([operator.add, 1, 2])
ind.fitness.values = (1.0,)
ind_s = pickle.dumps(ind)
ind_l = pickle.loads(ind_s)
msg = "Unpickled individual %s != pickled individual %s" % (str(ind), str(ind_l))
self.failUnlessEqual(ind, ind_l, msg)
msg = "Unpickled fitness %s != pickled fitness %s" % (str(ind.fitness), str(ind_l.fitness))
self.failUnlessEqual(ind.fitness, ind_l.fitness, msg)
def test_pickle_population(self):
ind1 = creator.IndList([1.0,2.0,3.0])
ind1.fitness.values = (1.0,)
ind2 = creator.IndList([4.0,5.0,6.0])
ind2.fitness.values = (2.0,)
ind3 = creator.IndList([7.0,8.0,9.0])
ind3.fitness.values = (3.0,)
pop = [ind1, ind2, ind3]
pop_s = pickle.dumps(pop)
pop_l = pickle.loads(pop_s)
self.failUnlessEqual(pop[0], pop_l[0], "Unpickled individual list != pickled individual list")
self.failUnlessEqual(pop[0].fitness, pop_l[0].fitness, "Unpickled individual fitness != pickled individual fitness")
self.failUnlessEqual(pop[1], pop_l[1], "Unpickled individual list != pickled individual list")
self.failUnlessEqual(pop[1].fitness, pop_l[1].fitness, "Unpickled individual fitness != pickled individual fitness")
self.failUnlessEqual(pop[2], pop_l[2], "Unpickled individual list != pickled individual list")
self.failUnlessEqual(pop[2].fitness, pop_l[2].fitness, "Unpickled individual fitness != pickled individual fitness")
def test_pickle_logbook(self):
stats = tools.Statistics()
logbook = tools.Logbook()
stats.register("mean", numpy.mean)
record = stats.compile([1,2,3,4,5,6,8,9,10])
logbook.record(**record)
stats_s = pickle.dumps(logbook)
logbook_r = pickle.loads(stats_s)
self.failUnlessEqual(logbook, logbook_r, "Unpickled logbook != pickled logbook")
if not sys.version_info < (2, 7):
def test_pickle_partial(self):
func_s = pickle.dumps(self.toolbox.func)
func_l = pickle.loads(func_s)
self.failUnlessEqual(self.toolbox.func(), func_l())
@unittest.expectedFailure
def test_pickle_lambda(self):
func_s = pickle.dumps(self.toolbox.lambda_func)
func_l = pickle.loads(func_s)
self.failUnlessEqual(self.toolbox.lambda_func(), func_l())
if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(Pickling)
unittest.TextTestRunner(verbosity=2).run(suite)
|
gpl-3.0
|
[
199,
646,
984,
199,
646,
2882,
199,
646,
1625,
199,
646,
5927,
199,
646,
4182,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
1274,
14,
515,
14,
740,
480,
703,
531,
199,
199,
646,
2680,
199,
199,
646,
14875,
199,
646,
1300,
199,
646,
15852,
199,
646,
7249,
199,
199,
318,
2562,
837,
272,
372,
298,
549,
2,
199,
199,
533,
16568,
2983,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
14875,
14,
981,
480,
13776,
4171,
4261,
401,
1300,
14,
13776,
4171,
12,
4931,
2687,
17,
14,
16,
4641,
267,
14875,
14,
981,
480,
25564,
1296,
401,
769,
12,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
14875,
14,
981,
480,
25564,
3836,
401,
1625,
14,
1144,
12,
221,
30573,
534,
70,
297,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
14875,
14,
981,
480,
25564,
3987,
401,
15852,
14,
22231,
3987,
12,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
291,
14,
3557,
1977,
275,
1300,
14,
5157,
1977,
342,
267,
291,
14,
3557,
1977,
14,
2683,
480,
1532,
401,
2562,
9,
267,
291,
14,
3557,
1977,
14,
2683,
480,
2734,
63,
1532,
401,
2400,
26,
298,
549,
531,
2286,
347,
511,
63,
8092,
63,
3269,
4171,
8,
277,
304,
267,
5542,
4171,
275,
14875,
14,
13776,
4171,
4261,
342,
267,
5542,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
5542,
4171,
63,
83,
275,
5927,
14,
4180,
8,
3269,
4171,
9,
267,
5542,
4171,
63,
76,
275,
5927,
14,
3640,
8,
3269,
4171,
63,
83,
9,
267,
291,
14,
14247,
8,
3269,
4171,
12,
5542,
4171,
63,
76,
12,
298,
1358,
20428,
5542,
4171,
1137,
18731,
5542,
4171,
531,
339,
347,
511,
63,
8092,
63,
688,
63,
513,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
1296,
779,
17,
14,
16,
12,
499,
14,
16,
12,
650,
14,
16,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
20,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
881,
272,
347,
511,
63,
8092,
63,
688,
63,
1144,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
3836,
779,
17,
14,
16,
12,
499,
14,
16,
12,
650,
14,
16,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
20,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
298,
1358,
20428,
8212,
1625,
1137,
18731,
8212,
1625,
531,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
2286,
347,
511,
63,
8092,
63,
2350,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
3987,
779,
3856,
14,
525,
12,
413,
12,
499,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
1499,
275,
221,
298,
1358,
20428,
8212,
450,
83,
1137,
18731,
8212,
450,
83,
2,
450,
334,
495,
8,
688,
395,
620,
8,
688,
63,
76,
430,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
1499,
9,
267,
1499,
275,
221,
298,
1358,
20428,
5542,
4171,
450,
83,
1137,
18731,
5542,
4171,
450,
83,
2,
450,
334,
495,
8,
688,
14,
3269,
4171,
395,
620,
8,
688,
63,
76,
14,
3269,
4171,
430,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
1499,
9,
2286,
347,
511,
63,
8092,
63,
16003,
8,
277,
304,
267,
7654,
17,
275,
14875,
14,
25564,
1296,
779,
17,
14,
16,
12,
18,
14,
16,
12,
19,
14,
16,
566,
267,
7654,
17,
14,
3269,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
7654,
18,
275,
14875,
14,
25564,
1296,
779,
20,
14,
16,
12,
21,
14,
16,
12,
22,
14,
16,
566,
267,
7654,
18,
14,
3269,
4171,
14,
1459,
275,
334,
18,
14,
16,
4258,
267,
7654,
19,
275,
14875,
14,
25564,
1296,
779,
23,
14,
16,
12,
24,
14,
16,
12,
25,
14,
16,
566,
267,
7654,
19,
14,
3269,
4171,
14,
1459,
275,
334,
19,
14,
16,
4258,
2728,
4560,
275,
359,
688,
17,
12,
7654,
18,
12,
7654,
19,
61,
2728,
4560,
63,
83,
275,
5927,
14,
4180,
8,
1935,
9,
267,
4560,
63,
76,
275,
5927,
14,
3640,
8,
1935,
63,
83,
9,
2728,
291,
14,
14247,
8,
1935,
59,
16,
467,
4560,
63,
76,
59,
16,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
16,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
16,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
267,
291,
14,
14247,
8,
1935,
59,
17,
467,
4560,
63,
76,
59,
17,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
17,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
17,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
267,
291,
14,
14247,
8,
1935,
59,
18,
467,
4560,
63,
76,
59,
18,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
18,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
18,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
2286,
347,
511,
63,
8092,
63,
793,
2706,
8,
277,
304,
267,
5020,
275,
7249
] |
[
646,
984,
199,
646,
2882,
199,
646,
1625,
199,
646,
5927,
199,
646,
4182,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
1274,
14,
515,
14,
740,
480,
703,
531,
199,
199,
646,
2680,
199,
199,
646,
14875,
199,
646,
1300,
199,
646,
15852,
199,
646,
7249,
199,
199,
318,
2562,
837,
272,
372,
298,
549,
2,
199,
199,
533,
16568,
2983,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
14875,
14,
981,
480,
13776,
4171,
4261,
401,
1300,
14,
13776,
4171,
12,
4931,
2687,
17,
14,
16,
4641,
267,
14875,
14,
981,
480,
25564,
1296,
401,
769,
12,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
14875,
14,
981,
480,
25564,
3836,
401,
1625,
14,
1144,
12,
221,
30573,
534,
70,
297,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
14875,
14,
981,
480,
25564,
3987,
401,
15852,
14,
22231,
3987,
12,
5542,
4171,
29,
9986,
14,
13776,
4171,
4261,
9,
267,
291,
14,
3557,
1977,
275,
1300,
14,
5157,
1977,
342,
267,
291,
14,
3557,
1977,
14,
2683,
480,
1532,
401,
2562,
9,
267,
291,
14,
3557,
1977,
14,
2683,
480,
2734,
63,
1532,
401,
2400,
26,
298,
549,
531,
2286,
347,
511,
63,
8092,
63,
3269,
4171,
8,
277,
304,
267,
5542,
4171,
275,
14875,
14,
13776,
4171,
4261,
342,
267,
5542,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
5542,
4171,
63,
83,
275,
5927,
14,
4180,
8,
3269,
4171,
9,
267,
5542,
4171,
63,
76,
275,
5927,
14,
3640,
8,
3269,
4171,
63,
83,
9,
267,
291,
14,
14247,
8,
3269,
4171,
12,
5542,
4171,
63,
76,
12,
298,
1358,
20428,
5542,
4171,
1137,
18731,
5542,
4171,
531,
339,
347,
511,
63,
8092,
63,
688,
63,
513,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
1296,
779,
17,
14,
16,
12,
499,
14,
16,
12,
650,
14,
16,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
20,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
881,
272,
347,
511,
63,
8092,
63,
688,
63,
1144,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
3836,
779,
17,
14,
16,
12,
499,
14,
16,
12,
650,
14,
16,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
20,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
298,
1358,
20428,
8212,
1625,
1137,
18731,
8212,
1625,
531,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
2286,
347,
511,
63,
8092,
63,
2350,
8,
277,
304,
267,
7654,
275,
14875,
14,
25564,
3987,
779,
3856,
14,
525,
12,
413,
12,
499,
566,
267,
7654,
14,
3269,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
7654,
63,
83,
275,
5927,
14,
4180,
8,
688,
9,
267,
7654,
63,
76,
275,
5927,
14,
3640,
8,
688,
63,
83,
9,
267,
1499,
275,
221,
298,
1358,
20428,
8212,
450,
83,
1137,
18731,
8212,
450,
83,
2,
450,
334,
495,
8,
688,
395,
620,
8,
688,
63,
76,
430,
267,
291,
14,
14247,
8,
688,
12,
7654,
63,
76,
12,
1499,
9,
267,
1499,
275,
221,
298,
1358,
20428,
5542,
4171,
450,
83,
1137,
18731,
5542,
4171,
450,
83,
2,
450,
334,
495,
8,
688,
14,
3269,
4171,
395,
620,
8,
688,
63,
76,
14,
3269,
4171,
430,
267,
291,
14,
14247,
8,
688,
14,
3269,
4171,
12,
7654,
63,
76,
14,
3269,
4171,
12,
1499,
9,
2286,
347,
511,
63,
8092,
63,
16003,
8,
277,
304,
267,
7654,
17,
275,
14875,
14,
25564,
1296,
779,
17,
14,
16,
12,
18,
14,
16,
12,
19,
14,
16,
566,
267,
7654,
17,
14,
3269,
4171,
14,
1459,
275,
334,
17,
14,
16,
4258,
267,
7654,
18,
275,
14875,
14,
25564,
1296,
779,
20,
14,
16,
12,
21,
14,
16,
12,
22,
14,
16,
566,
267,
7654,
18,
14,
3269,
4171,
14,
1459,
275,
334,
18,
14,
16,
4258,
267,
7654,
19,
275,
14875,
14,
25564,
1296,
779,
23,
14,
16,
12,
24,
14,
16,
12,
25,
14,
16,
566,
267,
7654,
19,
14,
3269,
4171,
14,
1459,
275,
334,
19,
14,
16,
4258,
2728,
4560,
275,
359,
688,
17,
12,
7654,
18,
12,
7654,
19,
61,
2728,
4560,
63,
83,
275,
5927,
14,
4180,
8,
1935,
9,
267,
4560,
63,
76,
275,
5927,
14,
3640,
8,
1935,
63,
83,
9,
2728,
291,
14,
14247,
8,
1935,
59,
16,
467,
4560,
63,
76,
59,
16,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
16,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
16,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
267,
291,
14,
14247,
8,
1935,
59,
17,
467,
4560,
63,
76,
59,
17,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
17,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
17,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
267,
291,
14,
14247,
8,
1935,
59,
18,
467,
4560,
63,
76,
59,
18,
467,
298,
1358,
20428,
8212,
769,
1137,
18731,
8212,
769,
531,
267,
291,
14,
14247,
8,
1935,
59,
18,
1055,
3269,
4171,
12,
4560,
63,
76,
59,
18,
1055,
3269,
4171,
12,
298,
1358,
20428,
8212,
5542,
4171,
1137,
18731,
8212,
5542,
4171,
531,
2286,
347,
511,
63,
8092,
63,
793,
2706,
8,
277,
304,
267,
5020,
275,
7249,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
elkingtonmcb/shogun
|
examples/undocumented/python_modular/kernel_comm_ulong_string_modular.py
|
26
|
1450
|
#!/usr/bin/env python
from tools.load import LoadMatrix
lm=LoadMatrix()
traindat =lm.load_dna('../data/fm_train_dna.dat')
testdat = lm.load_dna('../data/fm_test_dna.dat')
parameter_list = [[traindat,testdat,3,0,False ],[traindat,testdat,4,0,False]]
def kernel_comm_ulong_string_modular (fm_train_dna=traindat,fm_test_dna=testdat, order=3, gap=0, reverse = False):
from modshogun import CommUlongStringKernel
from modshogun import StringUlongFeatures, StringCharFeatures, DNA
from modshogun import SortUlongString
charfeat=StringCharFeatures(DNA)
charfeat.set_features(fm_train_dna)
feats_train=StringUlongFeatures(charfeat.get_alphabet())
feats_train.obtain_from_char(charfeat, order-1, order, gap, reverse)
preproc=SortUlongString()
preproc.init(feats_train)
feats_train.add_preprocessor(preproc)
feats_train.apply_preprocessor()
charfeat=StringCharFeatures(DNA)
charfeat.set_features(fm_test_dna)
feats_test=StringUlongFeatures(charfeat.get_alphabet())
feats_test.obtain_from_char(charfeat, order-1, order, gap, reverse)
feats_test.add_preprocessor(preproc)
feats_test.apply_preprocessor()
use_sign=False
kernel=CommUlongStringKernel(feats_train, feats_train, use_sign)
km_train=kernel.get_kernel_matrix()
kernel.init(feats_train, feats_test)
km_test=kernel.get_kernel_matrix()
return km_train,km_test,kernel
if __name__=='__main__':
print('CommUlongString')
kernel_comm_ulong_string_modular(*parameter_list[0])
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
7249,
14,
912,
492,
7190,
6443,
199,
14344,
29,
6200,
6443,
342,
199,
199,
1239,
688,
292,
275,
14344,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
2834,
63,
21075,
14,
4616,
358,
199,
396,
4616,
275,
221,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
396,
63,
21075,
14,
4616,
358,
199,
5329,
63,
513,
275,
3474,
1239,
688,
292,
12,
396,
4616,
12,
19,
12,
16,
12,
797,
2156,
59,
1239,
688,
292,
12,
396,
4616,
12,
20,
12,
16,
12,
797,
2677,
199,
199,
318,
5114,
63,
1404,
63,
15688,
63,
875,
63,
1494,
2238,
334,
10886,
63,
2834,
63,
21075,
29,
1239,
688,
292,
12,
10886,
63,
396,
63,
21075,
29,
396,
4616,
12,
1865,
29,
19,
12,
16301,
29,
16,
12,
3837,
275,
756,
304,
421,
198,
504,
3413,
13927,
17924,
492,
7046,
53,
2809,
1558,
14127,
199,
198,
504,
3413,
13927,
17924,
492,
2624,
53,
2809,
10807,
12,
2624,
1610,
10807,
12,
577,
7170,
199,
198,
504,
3413,
13927,
17924,
492,
16722,
53,
2809,
1558,
421,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
23372,
9,
199,
198,
1560,
11873,
14,
409,
63,
3179,
8,
10886,
63,
2834,
63,
21075,
9,
199,
198,
29255,
63,
2834,
29,
1558,
53,
2809,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
29255,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
657,
4687,
29,
14376,
53,
2809,
1558,
342,
199,
198,
657,
4687,
14,
826,
8,
29255,
63,
2834,
9,
199,
198,
29255,
63,
2834,
14,
525,
63,
657,
6459,
8,
657,
4687,
9,
199,
198,
29255,
63,
2834,
14,
4998,
63,
657,
6459,
342,
4388,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
23372,
9,
199,
198,
1560,
11873,
14,
409,
63,
3179,
8,
10886,
63,
396,
63,
21075,
9,
199,
198,
29255,
63,
396,
29,
1558,
53,
2809,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
29255,
63,
396,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
29255,
63,
396,
14,
525,
63,
657,
6459,
8,
657,
4687,
9,
199,
198,
29255,
63,
396,
14,
4998,
63,
657,
6459,
342,
421,
198,
1180,
63,
1037,
29,
797,
421,
198,
4989,
29,
5150,
53,
2809,
1558,
14127,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
2834,
12,
675,
63,
1037,
9,
421,
198,
14595,
63,
2834,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
396,
9,
199,
198,
14595,
63,
396,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
1107,
16155,
63,
2834,
12,
14595,
63,
396,
12,
4989,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
5150,
53,
2809,
1558,
358,
199,
198,
4989,
63,
1404,
63,
15688,
63,
875,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
7249,
14,
912,
492,
7190,
6443,
199,
14344,
29,
6200,
6443,
342,
199,
199,
1239,
688,
292,
275,
14344,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
2834,
63,
21075,
14,
4616,
358,
199,
396,
4616,
275,
221,
24546,
14,
912,
63,
21075,
24592,
576,
15,
10886,
63,
396,
63,
21075,
14,
4616,
358,
199,
5329,
63,
513,
275,
3474,
1239,
688,
292,
12,
396,
4616,
12,
19,
12,
16,
12,
797,
2156,
59,
1239,
688,
292,
12,
396,
4616,
12,
20,
12,
16,
12,
797,
2677,
199,
199,
318,
5114,
63,
1404,
63,
15688,
63,
875,
63,
1494,
2238,
334,
10886,
63,
2834,
63,
21075,
29,
1239,
688,
292,
12,
10886,
63,
396,
63,
21075,
29,
396,
4616,
12,
1865,
29,
19,
12,
16301,
29,
16,
12,
3837,
275,
756,
304,
421,
198,
504,
3413,
13927,
17924,
492,
7046,
53,
2809,
1558,
14127,
199,
198,
504,
3413,
13927,
17924,
492,
2624,
53,
2809,
10807,
12,
2624,
1610,
10807,
12,
577,
7170,
199,
198,
504,
3413,
13927,
17924,
492,
16722,
53,
2809,
1558,
421,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
23372,
9,
199,
198,
1560,
11873,
14,
409,
63,
3179,
8,
10886,
63,
2834,
63,
21075,
9,
199,
198,
29255,
63,
2834,
29,
1558,
53,
2809,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
29255,
63,
2834,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
657,
4687,
29,
14376,
53,
2809,
1558,
342,
199,
198,
657,
4687,
14,
826,
8,
29255,
63,
2834,
9,
199,
198,
29255,
63,
2834,
14,
525,
63,
657,
6459,
8,
657,
4687,
9,
199,
198,
29255,
63,
2834,
14,
4998,
63,
657,
6459,
342,
4388,
198,
1560,
11873,
29,
1558,
1610,
10807,
8,
23372,
9,
199,
198,
1560,
11873,
14,
409,
63,
3179,
8,
10886,
63,
396,
63,
21075,
9,
199,
198,
29255,
63,
396,
29,
1558,
53,
2809,
10807,
8,
1560,
11873,
14,
362,
63,
31884,
1012,
199,
198,
29255,
63,
396,
14,
2873,
877,
63,
504,
63,
1560,
8,
1560,
11873,
12,
1865,
13,
17,
12,
1865,
12,
16301,
12,
3837,
9,
199,
198,
29255,
63,
396,
14,
525,
63,
657,
6459,
8,
657,
4687,
9,
199,
198,
29255,
63,
396,
14,
4998,
63,
657,
6459,
342,
421,
198,
1180,
63,
1037,
29,
797,
421,
198,
4989,
29,
5150,
53,
2809,
1558,
14127,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
2834,
12,
675,
63,
1037,
9,
421,
198,
14595,
63,
2834,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
4989,
14,
826,
8,
29255,
63,
2834,
12,
1964,
1956,
63,
396,
9,
199,
198,
14595,
63,
396,
29,
4989,
14,
362,
63,
4989,
63,
3642,
342,
199,
198,
1107,
16155,
63,
2834,
12,
14595,
63,
396,
12,
4989,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
5150,
53,
2809,
1558,
358,
199,
198,
4989,
63,
1404,
63,
15688,
63,
875,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dpwrussell/openmicroscopy
|
components/tools/OmeroPy/test/integration/gatewaytest/test_connection.py
|
6
|
9679
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright 2009-2013 Glencoe Software, Inc. All rights reserved.
Use is subject to license terms supplied in LICENSE.txt
pytest fixtures used as defined in conftest.py:
- gatewaywrapper
- author_testimg
"""
import omero
import Ice
from omero.gateway.scripts import dbhelpers
import pytest
class TestConnectionMethods(object):
def testMultiProcessSession(self, gatewaywrapper):
# 120 amongst other things trying to getSession() twice for the same
# session dies. Also in separate processes.
# we mimic this by calling setGroupForSession, which calls
# sessionservice.getSession, 2 times on cloned connections
gatewaywrapper.loginAsAuthor()
assert gatewaywrapper.gateway.getSession() is not None
c2 = gatewaywrapper.gateway.clone()
assert c2.connect(sUuid=gatewaywrapper.gateway._sessionUuid)
assert c2.getSession() is not None
a = c2.getAdminService()
g = omero.gateway.ExperimenterGroupWrapper(
c2, a.containedGroups(c2.getUserId())[-1])
c2.setGroupForSession(g)
c3 = gatewaywrapper.gateway.clone()
assert c3.connect(sUuid=gatewaywrapper.gateway._sessionUuid)
assert c3.getSession() is not None
a = c3.getAdminService()
g = omero.gateway.ExperimenterGroupWrapper(
c3, a.containedGroups(c3.getUserId())[1])
c3.setGroupForSession(g)
# seppuku is deprecated: testClose below supersedes this test
def testSeppuku(self, gatewaywrapper, author_testimg):
# author_testimg in args to make sure the image has been imported
gatewaywrapper.loginAsAuthor()
assert gatewaywrapper.getTestImage() is not None
gatewaywrapper.gateway.seppuku()
pytest.raises(Ice.ConnectionLostException, gatewaywrapper.getTestImage)
gatewaywrapper._has_connected = False
gatewaywrapper.doDisconnect()
gatewaywrapper.loginAsAuthor()
assert gatewaywrapper.getTestImage() is not None
gatewaywrapper.gateway.seppuku(softclose=False)
pytest.raises(Ice.ConnectionLostException, gatewaywrapper.getTestImage)
gatewaywrapper._has_connected = False
gatewaywrapper.doDisconnect()
# Also make sure softclose does the right thing
gatewaywrapper.loginAsAuthor()
g2 = gatewaywrapper.gateway.clone()
def g2_getTestImage():
return dbhelpers.getImage(g2, 'testimg1')
assert g2.connect(gatewaywrapper.gateway._sessionUuid)
assert gatewaywrapper.getTestImage() is not None
assert g2_getTestImage() is not None
g2.seppuku(softclose=True)
pytest.raises(Ice.ConnectionLostException, g2_getTestImage)
assert gatewaywrapper.getTestImage() is not None
g2 = gatewaywrapper.gateway.clone()
assert g2.connect(gatewaywrapper.gateway._sessionUuid)
assert gatewaywrapper.getTestImage() is not None
assert g2_getTestImage() is not None
g2.seppuku(softclose=False)
pytest.raises(Ice.ConnectionLostException, g2_getTestImage)
pytest.raises(Ice.ObjectNotExistException, gatewaywrapper.getTestImage)
gatewaywrapper._has_connected = False
gatewaywrapper.doDisconnect()
def testClose(self, gatewaywrapper, author_testimg):
# author_testimg in args to make sure the image has been imported
gatewaywrapper.loginAsAuthor()
assert gatewaywrapper.getTestImage() is not None
gatewaywrapper.gateway.close()
pytest.raises(Ice.ConnectionLostException, gatewaywrapper.getTestImage)
gatewaywrapper._has_connected = False
gatewaywrapper.doDisconnect()
gatewaywrapper.loginAsAuthor()
g2 = gatewaywrapper.gateway.clone()
def g2_getTestImage():
return dbhelpers.getImage(g2, 'testimg1')
assert g2.connect(gatewaywrapper.gateway._sessionUuid)
assert gatewaywrapper.getTestImage() is not None
assert g2_getTestImage() is not None
g2.close()
pytest.raises(Ice.ConnectionLostException, g2_getTestImage)
pytest.raises(Ice.ObjectNotExistException, gatewaywrapper.getTestImage)
gatewaywrapper._has_connected = False
gatewaywrapper.doDisconnect()
def testTopLevelObjects(self, gatewaywrapper, author_testimg):
##
# Test listProjects as root (sees, does not own)
parents = author_testimg.getAncestry()
project_id = parents[-1].getId()
# Original (4.1) test fails since 'admin' is logged into group 0, but
# the project created above is in new group.
# gatewaywrapper.loginAsAdmin()
# test passes if we remain logged in as Author
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id in ids
# test passes if we NOW log in as Admin (different group)
gatewaywrapper.loginAsAdmin()
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id not in ids
##
# Test listProjects as author (sees, owns)
gatewaywrapper.loginAsAuthor()
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id in ids
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id in ids
##
# Test listProjects as guest (does not see, does not own)
gatewaywrapper.doLogin(gatewaywrapper.USER)
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id not in ids
ids = map(lambda x: x.getId(), gatewaywrapper.gateway.listProjects())
assert project_id not in ids
##
# Test getProject
gatewaywrapper.loginAsAuthor()
assert gatewaywrapper.gateway.getObject(
"Project", project_id).getId() == project_id
##
# Test getDataset
dataset_id = parents[0].getId()
assert gatewaywrapper.gateway.getObject(
"Dataset", dataset_id).getId() == dataset_id
##
# Test listExperimenters
# exps = map(lambda x: x.omeName,
# gatewaywrapper.gateway.listExperimenters()) # removed from blitz
# gateway
exps = map(lambda x: x.omeName,
gatewaywrapper.gateway.getObjects("Experimenter"))
for omeName in (gatewaywrapper.USER.name, gatewaywrapper.AUTHOR.name,
gatewaywrapper.ADMIN.name.decode('utf-8')):
assert omeName in exps
assert len(list(gatewaywrapper.gateway.getObjects(
"Experimenter", attributes={'omeName': omeName}))) > 0
comboName = gatewaywrapper.USER.name + \
gatewaywrapper.AUTHOR.name + gatewaywrapper.ADMIN.name
assert len(list(gatewaywrapper.gateway.getObjects(
"Experimenter", attributes={'omeName': comboName}))) == 0
##
# Test lookupExperimenter
assert gatewaywrapper.gateway.getObject(
"Experimenter",
attributes={'omeName': gatewaywrapper.USER.name}).omeName == \
gatewaywrapper.USER.name
assert gatewaywrapper.gateway.getObject(
"Experimenter", attributes={'omeName': comboName}) is None
##
# still logged in as Author, test listImages(ns)
def listImages(ns=None):
imageAnnLinks = gatewaywrapper.gateway.getAnnotationLinks("Image",
ns=ns)
return [omero.gateway.ImageWrapper(gatewaywrapper.gateway,
link.parent) for link in imageAnnLinks]
ns = 'weblitz.test_annotation'
obj = gatewaywrapper.getTestImage()
# Make sure it doesn't yet exist
obj.removeAnnotations(ns)
assert obj.getAnnotation(ns) is None
# Check without the ann
assert len(listImages(ns=ns)) == 0
annclass = omero.gateway.CommentAnnotationWrapper
# createAndLink
annclass.createAndLink(target=obj, ns=ns, val='foo')
imgs = listImages(ns=ns)
assert len(imgs) == 1
assert imgs[0] == obj
# and clean up
obj.removeAnnotations(ns)
assert obj.getAnnotation(ns) is None
def testCloseSession(self, gatewaywrapper):
# 74 the failed connection for a user not in the system group does not
# get closed
gatewaywrapper.gateway.setIdentity(
gatewaywrapper.USER.name, gatewaywrapper.USER.passwd)
setprop = gatewaywrapper.gateway.c.ic.getProperties().setProperty
map(lambda x: setprop(x[0], str(x[1])),
gatewaywrapper.gateway._ic_props.items())
gatewaywrapper.gateway.c.ic.getImplicitContext().put(
omero.constants.GROUP, gatewaywrapper.gateway.group)
# I'm not certain the following assertion is as intended.
# This should be reviewed, see ticket #6037
# assert gatewaywrapper.gateway._sessionUuid == None
pytest.raises(omero.ClientError, gatewaywrapper.gateway._createSession)
assert gatewaywrapper.gateway._sessionUuid is not None
# 74 bug found while fixing this, the uuid passed to closeSession was
# not wrapped in rtypes, so logout didn't
gatewaywrapper.gateway._closeSession() # was raising ValueError
gatewaywrapper.gateway = None
def testMiscellaneous(self, gatewaywrapper):
gatewaywrapper.loginAsUser()
assert gatewaywrapper.gateway.getUser().omeName == \
gatewaywrapper.USER.name
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
2043,
1898,
8937,
13,
6965,
598,
552,
331,
69,
2290,
12,
3277,
14,
2900,
4481,
4644,
14,
2043,
3645,
365,
5420,
370,
4190,
2895,
6841,
315,
5113,
14,
2424,
8410,
4613,
15188,
1202,
465,
3247,
315,
3743,
396,
14,
647,
26,
2043,
446,
10391,
5029,
2043,
446,
4132,
63,
396,
4060,
199,
199,
624,
199,
199,
646,
27122,
199,
646,
473,
301,
199,
504,
27122,
14,
7019,
14,
6429,
492,
1592,
7546,
199,
646,
4613,
421,
199,
533,
1379,
3225,
10385,
8,
785,
304,
339,
347,
511,
3947,
3498,
4434,
8,
277,
12,
10391,
5029,
304,
267,
327,
13960,
16885,
270,
1163,
7645,
9936,
370,
664,
4434,
342,
13373,
367,
314,
2011,
267,
327,
2351,
487,
397,
14,
6121,
315,
7396,
10358,
14,
267,
327,
781,
24102,
530,
642,
701,
6358,
663,
2448,
1858,
4434,
12,
1314,
4882,
267,
327,
2351,
1364,
14,
362,
4434,
12,
499,
5431,
641,
26210,
6947,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
7019,
14,
362,
4434,
342,
365,
440,
488,
267,
286,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
286,
18,
14,
2242,
8,
83,
19557,
29,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
286,
18,
14,
362,
4434,
342,
365,
440,
488,
267,
282,
275,
286,
18,
14,
362,
4880,
3167,
342,
267,
486,
275,
27122,
14,
7019,
14,
920,
21888,
2448,
4590,
8,
288,
286,
18,
12,
282,
14,
30288,
10177,
8,
67,
18,
14,
32627,
1304,
1012,
1988,
17,
566,
267,
286,
18,
14,
409,
2448,
1858,
4434,
8,
71,
9,
267,
286,
19,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
286,
19,
14,
2242,
8,
83,
19557,
29,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
286,
19,
14,
362,
4434,
342,
365,
440,
488,
267,
282,
275,
286,
19,
14,
362,
4880,
3167,
342,
267,
486,
275,
27122,
14,
7019,
14,
920,
21888,
2448,
4590,
8,
288,
286,
19,
12,
282,
14,
30288,
10177,
8,
67,
19,
14,
32627,
1304,
18756,
17,
566,
267,
286,
19,
14,
409,
2448,
1858,
4434,
8,
71,
9,
339,
327,
542,
802,
3210,
85,
365,
5906,
26,
511,
4724,
5084,
1613,
261,
3424,
642,
511,
272,
347,
511,
1513,
802,
3210,
85,
8,
277,
12,
10391,
5029,
12,
4132,
63,
396,
4060,
304,
267,
327,
4132,
63,
396,
4060,
315,
1249,
370,
1852,
3238,
314,
1834,
965,
2757,
8439,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
261,
802,
3210,
85,
342,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
797,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
327,
6121,
1852,
3238,
11620,
1600,
1630,
314,
2451,
8377,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
398,
347,
486,
18,
63,
362,
774,
3491,
837,
288,
372,
1592,
7546,
14,
362,
3491,
8,
71,
18,
12,
283,
396,
4060,
17,
358,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
702,
486,
18,
63,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
549,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
486,
18,
63,
362,
774,
3491,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
702,
486,
18,
63,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
797,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
486,
18,
63,
362,
774,
3491,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
1692,
1763,
6439,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
339,
347,
511,
4724,
8,
277,
12,
10391,
5029,
12,
4132,
63,
396,
4060,
304,
267,
327,
4132,
63,
396,
4060,
315,
1249,
370,
1852,
3238,
314,
1834,
965,
2757,
8439,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
1600,
342,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
398,
347,
486,
18,
63,
362,
774,
3491,
837,
288,
372,
1592,
7546,
14,
362,
3491,
8,
71,
18,
12,
283,
396,
4060,
17,
358,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
702,
486,
18,
63,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
14,
1600,
342,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
486,
18,
63,
362,
774,
3491,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
1692
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
2043,
1898,
8937,
13,
6965,
598,
552,
331,
69,
2290,
12,
3277,
14,
2900,
4481,
4644,
14,
2043,
3645,
365,
5420,
370,
4190,
2895,
6841,
315,
5113,
14,
2424,
8410,
4613,
15188,
1202,
465,
3247,
315,
3743,
396,
14,
647,
26,
2043,
446,
10391,
5029,
2043,
446,
4132,
63,
396,
4060,
199,
199,
624,
199,
199,
646,
27122,
199,
646,
473,
301,
199,
504,
27122,
14,
7019,
14,
6429,
492,
1592,
7546,
199,
646,
4613,
421,
199,
533,
1379,
3225,
10385,
8,
785,
304,
339,
347,
511,
3947,
3498,
4434,
8,
277,
12,
10391,
5029,
304,
267,
327,
13960,
16885,
270,
1163,
7645,
9936,
370,
664,
4434,
342,
13373,
367,
314,
2011,
267,
327,
2351,
487,
397,
14,
6121,
315,
7396,
10358,
14,
267,
327,
781,
24102,
530,
642,
701,
6358,
663,
2448,
1858,
4434,
12,
1314,
4882,
267,
327,
2351,
1364,
14,
362,
4434,
12,
499,
5431,
641,
26210,
6947,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
7019,
14,
362,
4434,
342,
365,
440,
488,
267,
286,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
286,
18,
14,
2242,
8,
83,
19557,
29,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
286,
18,
14,
362,
4434,
342,
365,
440,
488,
267,
282,
275,
286,
18,
14,
362,
4880,
3167,
342,
267,
486,
275,
27122,
14,
7019,
14,
920,
21888,
2448,
4590,
8,
288,
286,
18,
12,
282,
14,
30288,
10177,
8,
67,
18,
14,
32627,
1304,
1012,
1988,
17,
566,
267,
286,
18,
14,
409,
2448,
1858,
4434,
8,
71,
9,
267,
286,
19,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
286,
19,
14,
2242,
8,
83,
19557,
29,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
286,
19,
14,
362,
4434,
342,
365,
440,
488,
267,
282,
275,
286,
19,
14,
362,
4880,
3167,
342,
267,
486,
275,
27122,
14,
7019,
14,
920,
21888,
2448,
4590,
8,
288,
286,
19,
12,
282,
14,
30288,
10177,
8,
67,
19,
14,
32627,
1304,
18756,
17,
566,
267,
286,
19,
14,
409,
2448,
1858,
4434,
8,
71,
9,
339,
327,
542,
802,
3210,
85,
365,
5906,
26,
511,
4724,
5084,
1613,
261,
3424,
642,
511,
272,
347,
511,
1513,
802,
3210,
85,
8,
277,
12,
10391,
5029,
12,
4132,
63,
396,
4060,
304,
267,
327,
4132,
63,
396,
4060,
315,
1249,
370,
1852,
3238,
314,
1834,
965,
2757,
8439,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
261,
802,
3210,
85,
342,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
797,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
327,
6121,
1852,
3238,
11620,
1600,
1630,
314,
2451,
8377,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
398,
347,
486,
18,
63,
362,
774,
3491,
837,
288,
372,
1592,
7546,
14,
362,
3491,
8,
71,
18,
12,
283,
396,
4060,
17,
358,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
702,
486,
18,
63,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
549,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
486,
18,
63,
362,
774,
3491,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
702,
486,
18,
63,
362,
774,
3491,
342,
365,
440,
488,
267,
486,
18,
14,
261,
802,
3210,
85,
8,
4617,
1600,
29,
797,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
486,
18,
63,
362,
774,
3491,
9,
267,
4613,
14,
3536,
8,
41,
301,
14,
1692,
1763,
6439,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
339,
347,
511,
4724,
8,
277,
12,
10391,
5029,
12,
4132,
63,
396,
4060,
304,
267,
327,
4132,
63,
396,
4060,
315,
1249,
370,
1852,
3238,
314,
1834,
965,
2757,
8439,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
702,
10391,
5029,
14,
362,
774,
3491,
342,
365,
440,
488,
267,
10391,
5029,
14,
7019,
14,
1600,
342,
267,
4613,
14,
3536,
8,
41,
301,
14,
3225,
14074,
1726,
12,
10391,
5029,
14,
362,
774,
3491,
9,
267,
10391,
5029,
423,
1989,
63,
7113,
275,
756,
267,
10391,
5029,
14,
1117,
16761,
342,
267,
10391,
5029,
14,
2886,
2822,
5949,
342,
267,
486,
18,
275,
10391,
5029,
14,
7019,
14,
6311,
342,
398,
347,
486,
18,
63,
362,
774,
3491,
837,
288,
372,
1592,
7546,
14,
362,
3491,
8,
71,
18,
12,
283,
396,
4060,
17,
358,
267,
702,
486,
18,
14,
2242,
8,
7019,
5029,
14,
7019,
423,
28093,
9,
267,
702,
10391,
5029,
14,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
leereilly/django-1
|
django/utils/tree.py
|
103
|
5755
|
"""
A class for storing a tree graph. Primarily used for filter constructs in the
ORM.
"""
import copy
class Node(object):
"""
A single internal node in the tree graph. A Node should be viewed as a
connection (the root) with the children being either leaf nodes or other
Node instances.
"""
# Standard connector type. Clients usually won't use this at all and
# subclasses will usually override the value.
default = 'DEFAULT'
def __init__(self, children=None, connector=None, negated=False):
"""
Constructs a new Node. If no connector is given, the default will be
used.
Warning: You probably don't want to pass in the 'negated' parameter. It
is NOT the same as constructing a node and calling negate() on the
result.
"""
self.children = children and children[:] or []
self.connector = connector or self.default
self.subtree_parents = []
self.negated = negated
# We need this because of django.db.models.query_utils.Q. Q. __init__() is
# problematic, but it is a natural Node subclass in all other respects.
def _new_instance(cls, children=None, connector=None, negated=False):
"""
This is called to create a new instance of this class when we need new
Nodes (or subclasses) in the internal code in this class. Normally, it
just shadows __init__(). However, subclasses with an __init__ signature
that is not an extension of Node.__init__ might need to implement this
method to allow a Node to create a new instance of them (if they have
any extra setting up to do).
"""
obj = Node(children, connector, negated)
obj.__class__ = cls
return obj
_new_instance = classmethod(_new_instance)
def __str__(self):
if self.negated:
return '(NOT (%s: %s))' % (self.connector, ', '.join([str(c) for c
in self.children]))
return '(%s: %s)' % (self.connector, ', '.join([str(c) for c in
self.children]))
def __deepcopy__(self, memodict):
"""
Utility method used by copy.deepcopy().
"""
obj = Node(connector=self.connector, negated=self.negated)
obj.__class__ = self.__class__
obj.children = copy.deepcopy(self.children, memodict)
obj.subtree_parents = copy.deepcopy(self.subtree_parents, memodict)
return obj
def __len__(self):
"""
The size of a node if the number of children it has.
"""
return len(self.children)
def __nonzero__(self):
"""
For truth value testing.
"""
return bool(self.children)
def __contains__(self, other):
"""
Returns True is 'other' is a direct child of this instance.
"""
return other in self.children
def add(self, node, conn_type):
"""
Adds a new node to the tree. If the conn_type is the same as the root's
current connector type, the node is added to the first level.
Otherwise, the whole tree is pushed down one level and a new root
connector is created, connecting the existing tree and the new node.
"""
if node in self.children and conn_type == self.connector:
return
if len(self.children) < 2:
self.connector = conn_type
if self.connector == conn_type:
if isinstance(node, Node) and (node.connector == conn_type or
len(node) == 1):
self.children.extend(node.children)
else:
self.children.append(node)
else:
obj = self._new_instance(self.children, self.connector,
self.negated)
self.connector = conn_type
self.children = [obj, node]
def negate(self):
"""
Negate the sense of the root connector. This reorganises the children
so that the current node has a single child: a negated node containing
all the previous children. This slightly odd construction makes adding
new children behave more intuitively.
Interpreting the meaning of this negate is up to client code. This
method is useful for implementing "not" arrangements.
"""
self.children = [self._new_instance(self.children, self.connector,
not self.negated)]
self.connector = self.default
def start_subtree(self, conn_type):
"""
Sets up internal state so that new nodes are added to a subtree of the
current node. The conn_type specifies how the sub-tree is joined to the
existing children.
"""
if len(self.children) == 1:
self.connector = conn_type
elif self.connector != conn_type:
self.children = [self._new_instance(self.children, self.connector,
self.negated)]
self.connector = conn_type
self.negated = False
self.subtree_parents.append(self.__class__(self.children,
self.connector, self.negated))
self.connector = self.default
self.negated = False
self.children = []
def end_subtree(self):
"""
Closes off the most recently unmatched start_subtree() call.
This puts the current state into a node of the parent tree and returns
the current instances state to be the parent.
"""
obj = self.subtree_parents.pop()
node = self.__class__(self.children, self.connector)
self.connector = obj.connector
self.negated = obj.negated
self.children = obj.children
self.children.append(node)
|
bsd-3-clause
|
[
624,
199,
33,
1021,
367,
16915,
282,
3123,
3343,
14,
8538,
30468,
1202,
367,
2457,
21638,
315,
314,
199,
8832,
14,
199,
624,
199,
199,
646,
1331,
199,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
5007,
1031,
315,
314,
3123,
3343,
14,
437,
5013,
1077,
506,
2455,
379,
465,
282,
272,
1950,
334,
1589,
1738,
9,
543,
314,
4978,
3769,
1902,
11747,
3380,
503,
1163,
272,
5013,
4454,
14,
272,
408,
272,
327,
9739,
13252,
730,
14,
6810,
83,
9987,
7859,
1133,
675,
642,
737,
1006,
436,
272,
327,
9180,
911,
9987,
4278,
314,
574,
14,
272,
849,
275,
283,
3472,
7,
339,
347,
636,
826,
721,
277,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
9215,
83,
282,
892,
5013,
14,
982,
949,
13252,
365,
1627,
12,
314,
849,
911,
506,
267,
1202,
14,
398,
15902,
26,
2047,
8646,
2793,
1133,
2934,
370,
986,
315,
314,
283,
8705,
972,
7,
2725,
14,
2779,
267,
365,
2845,
314,
2011,
465,
22048,
282,
1031,
436,
6358,
30112,
342,
641,
314,
267,
754,
14,
267,
408,
267,
291,
14,
3223,
275,
4978,
436,
4978,
5873,
503,
942,
267,
291,
14,
11815,
275,
13252,
503,
291,
14,
885,
267,
291,
14,
26043,
63,
8859,
275,
942,
267,
291,
14,
8705,
972,
275,
14158,
972,
339,
327,
2136,
1929,
642,
2952,
402,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
14,
49,
14,
1413,
14,
636,
826,
4533,
365,
272,
327,
557,
31197,
12,
1325,
652,
365,
282,
19981,
5013,
5516,
315,
1006,
1163,
14021,
83,
14,
272,
347,
485,
1222,
63,
842,
8,
1886,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
961,
365,
2797,
370,
1218,
282,
892,
1256,
402,
642,
1021,
1380,
781,
1929,
892,
267,
23836,
334,
269,
9180,
9,
315,
314,
5007,
1233,
315,
642,
1021,
14,
24573,
12,
652,
267,
2951,
15084,
83,
636,
826,
31261,
9738,
12,
9180,
543,
376,
636,
826,
363,
4955,
267,
626,
365,
440,
376,
3329,
402,
5013,
855,
826,
363,
5594,
1929,
370,
5669,
642,
267,
1083,
370,
2040,
282,
5013,
370,
1218,
282,
892,
1256,
402,
3062,
334,
692,
2985,
1172,
267,
1263,
2402,
4260,
1536,
370,
886,
680,
267,
408,
267,
1559,
275,
5013,
8,
3223,
12,
13252,
12,
14158,
972,
9,
267,
1559,
855,
533,
363,
275,
843,
267,
372,
1559,
272,
485,
1222,
63,
842,
275,
18990,
1547,
1222,
63,
842,
9,
339,
347,
636,
495,
721,
277,
304,
267,
340,
291,
14,
8705,
972,
26,
288,
372,
8189,
4609,
4366,
83,
26,
450,
83,
23089,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
779,
495,
8,
67,
9,
367,
286,
490,
315,
291,
14,
3223,
2459,
267,
372,
25676,
83,
26,
450,
83,
3171,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
779,
495,
8,
67,
9,
367,
286,
315,
355,
291,
14,
3223,
2459,
339,
347,
636,
8293,
721,
277,
12,
11955,
807,
304,
267,
408,
267,
20511,
1083,
1202,
701,
1331,
14,
8293,
1252,
267,
408,
267,
1559,
275,
5013,
8,
11815,
29,
277,
14,
11815,
12,
14158,
972,
29,
277,
14,
8705,
972,
9,
267,
1559,
855,
533,
363,
275,
291,
855,
533,
363,
267,
1559,
14,
3223,
275,
1331,
14,
8293,
8,
277,
14,
3223,
12,
11955,
807,
9,
267,
1559,
14,
26043,
63,
8859,
275,
1331,
14,
8293,
8,
277,
14,
26043,
63,
8859,
12,
11955,
807,
9,
267,
372,
1559,
339,
347,
636,
552,
721,
277,
304,
267,
408,
267,
710,
1568,
402,
282,
1031,
340,
314,
1329,
402,
4978,
652,
965,
14,
267,
408,
267,
372,
822,
8,
277,
14,
3223,
9,
339,
347,
636,
10262,
721,
277,
304,
267,
408,
267,
2104,
16865,
574,
5343,
14,
267,
408,
267,
372,
2155,
8,
277,
14,
3223,
9,
339,
347,
636,
6134,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
365,
283,
1848,
7,
365,
282,
4125,
1982,
402,
642,
1256,
14,
267,
408,
267,
372,
1163,
315,
291,
14,
3223,
339,
347,
1050,
8,
277,
12,
1031,
12,
2557,
63,
466,
304,
267,
408,
267,
15747,
282,
892,
1031,
370,
314,
3123,
14,
982,
314,
2557,
63,
466,
365,
314,
2011,
465,
314,
1738,
1159,
267,
1453,
13252,
730,
12,
314,
1031,
365,
3483,
370,
314,
1642,
2166,
14,
267,
6630,
12,
314,
8852,
3123,
365,
22319,
3224,
1373,
2166,
436,
282,
892,
1738,
267,
13252,
365,
2737,
12,
18170,
314,
3411,
3123,
436,
314,
892,
1031,
14,
267,
408,
267,
340,
1031,
315,
291,
14,
3223,
436,
2557,
63,
466,
508,
291,
14,
11815,
26,
288,
372,
267,
340,
822,
8,
277,
14,
3223,
9,
665,
499,
26,
288,
291,
14,
11815,
275,
2557,
63,
466,
267,
340,
291,
14,
11815,
508,
2557,
63,
466,
26,
288,
340,
1228,
8,
932,
12,
5013,
9,
436,
334,
932,
14,
11815,
508,
2557,
63,
466,
503,
490,
822,
8,
932,
9,
508,
413,
304,
355,
291,
14,
3223,
14,
2880,
8,
932,
14,
3223,
9,
288,
587,
26,
355,
291,
14,
3223,
14,
740,
8,
932,
9,
267,
587,
26,
288,
1559,
275,
291,
423,
1222,
63,
842,
8,
277,
14,
3223,
12,
291,
14,
11815,
12,
490,
291,
14,
8705,
972,
9,
288,
291,
14,
11815,
275,
2557,
63,
466,
288,
291,
14,
3223,
275,
359,
1113,
12,
1031,
61,
339,
347,
30112,
8,
277,
304,
267,
408,
267,
5612,
3237,
314,
12249,
402,
314,
1738,
13252,
14,
961,
295,
19916,
1388,
314,
4978,
267,
880,
626,
314,
1453,
1031,
965,
282,
2849,
1982,
26,
282,
14158,
972,
1031,
3035,
267,
1006,
314,
4136,
4978,
14,
961,
18023,
16699,
14538,
7704,
7791,
267,
892,
4978,
24062,
1655,
1109,
1907,
9462,
14,
398,
6551,
657,
1337,
314,
11150,
402,
642,
30112,
365,
1536,
370,
1890,
1233,
14,
961,
267,
1083,
365,
2997,
367,
18234,
298,
1397,
2,
601,
1842,
1470,
14,
267,
408,
267,
291,
14,
3223,
275,
359,
277,
423,
1222,
63,
842,
8,
277,
14,
3223,
12,
291,
14,
11815,
12,
355,
440,
291,
14,
8705,
972,
1874,
267,
291,
14,
11815,
275,
291,
14,
885
] |
[
199,
33,
1021,
367,
16915,
282,
3123,
3343,
14,
8538,
30468,
1202,
367,
2457,
21638,
315,
314,
199,
8832,
14,
199,
624,
199,
199,
646,
1331,
199,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
5007,
1031,
315,
314,
3123,
3343,
14,
437,
5013,
1077,
506,
2455,
379,
465,
282,
272,
1950,
334,
1589,
1738,
9,
543,
314,
4978,
3769,
1902,
11747,
3380,
503,
1163,
272,
5013,
4454,
14,
272,
408,
272,
327,
9739,
13252,
730,
14,
6810,
83,
9987,
7859,
1133,
675,
642,
737,
1006,
436,
272,
327,
9180,
911,
9987,
4278,
314,
574,
14,
272,
849,
275,
283,
3472,
7,
339,
347,
636,
826,
721,
277,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
9215,
83,
282,
892,
5013,
14,
982,
949,
13252,
365,
1627,
12,
314,
849,
911,
506,
267,
1202,
14,
398,
15902,
26,
2047,
8646,
2793,
1133,
2934,
370,
986,
315,
314,
283,
8705,
972,
7,
2725,
14,
2779,
267,
365,
2845,
314,
2011,
465,
22048,
282,
1031,
436,
6358,
30112,
342,
641,
314,
267,
754,
14,
267,
408,
267,
291,
14,
3223,
275,
4978,
436,
4978,
5873,
503,
942,
267,
291,
14,
11815,
275,
13252,
503,
291,
14,
885,
267,
291,
14,
26043,
63,
8859,
275,
942,
267,
291,
14,
8705,
972,
275,
14158,
972,
339,
327,
2136,
1929,
642,
2952,
402,
1639,
14,
697,
14,
992,
14,
1131,
63,
1208,
14,
49,
14,
1413,
14,
636,
826,
4533,
365,
272,
327,
557,
31197,
12,
1325,
652,
365,
282,
19981,
5013,
5516,
315,
1006,
1163,
14021,
83,
14,
272,
347,
485,
1222,
63,
842,
8,
1886,
12,
4978,
29,
403,
12,
13252,
29,
403,
12,
14158,
972,
29,
797,
304,
267,
408,
267,
961,
365,
2797,
370,
1218,
282,
892,
1256,
402,
642,
1021,
1380,
781,
1929,
892,
267,
23836,
334,
269,
9180,
9,
315,
314,
5007,
1233,
315,
642,
1021,
14,
24573,
12,
652,
267,
2951,
15084,
83,
636,
826,
31261,
9738,
12,
9180,
543,
376,
636,
826,
363,
4955,
267,
626,
365,
440,
376,
3329,
402,
5013,
855,
826,
363,
5594,
1929,
370,
5669,
642,
267,
1083,
370,
2040,
282,
5013,
370,
1218,
282,
892,
1256,
402,
3062,
334,
692,
2985,
1172,
267,
1263,
2402,
4260,
1536,
370,
886,
680,
267,
408,
267,
1559,
275,
5013,
8,
3223,
12,
13252,
12,
14158,
972,
9,
267,
1559,
855,
533,
363,
275,
843,
267,
372,
1559,
272,
485,
1222,
63,
842,
275,
18990,
1547,
1222,
63,
842,
9,
339,
347,
636,
495,
721,
277,
304,
267,
340,
291,
14,
8705,
972,
26,
288,
372,
8189,
4609,
4366,
83,
26,
450,
83,
23089,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
779,
495,
8,
67,
9,
367,
286,
490,
315,
291,
14,
3223,
2459,
267,
372,
25676,
83,
26,
450,
83,
3171,
450,
334,
277,
14,
11815,
12,
1656,
1987,
904,
779,
495,
8,
67,
9,
367,
286,
315,
355,
291,
14,
3223,
2459,
339,
347,
636,
8293,
721,
277,
12,
11955,
807,
304,
267,
408,
267,
20511,
1083,
1202,
701,
1331,
14,
8293,
1252,
267,
408,
267,
1559,
275,
5013,
8,
11815,
29,
277,
14,
11815,
12,
14158,
972,
29,
277,
14,
8705,
972,
9,
267,
1559,
855,
533,
363,
275,
291,
855,
533,
363,
267,
1559,
14,
3223,
275,
1331,
14,
8293,
8,
277,
14,
3223,
12,
11955,
807,
9,
267,
1559,
14,
26043,
63,
8859,
275,
1331,
14,
8293,
8,
277,
14,
26043,
63,
8859,
12,
11955,
807,
9,
267,
372,
1559,
339,
347,
636,
552,
721,
277,
304,
267,
408,
267,
710,
1568,
402,
282,
1031,
340,
314,
1329,
402,
4978,
652,
965,
14,
267,
408,
267,
372,
822,
8,
277,
14,
3223,
9,
339,
347,
636,
10262,
721,
277,
304,
267,
408,
267,
2104,
16865,
574,
5343,
14,
267,
408,
267,
372,
2155,
8,
277,
14,
3223,
9,
339,
347,
636,
6134,
721,
277,
12,
1163,
304,
267,
408,
267,
1803,
715,
365,
283,
1848,
7,
365,
282,
4125,
1982,
402,
642,
1256,
14,
267,
408,
267,
372,
1163,
315,
291,
14,
3223,
339,
347,
1050,
8,
277,
12,
1031,
12,
2557,
63,
466,
304,
267,
408,
267,
15747,
282,
892,
1031,
370,
314,
3123,
14,
982,
314,
2557,
63,
466,
365,
314,
2011,
465,
314,
1738,
1159,
267,
1453,
13252,
730,
12,
314,
1031,
365,
3483,
370,
314,
1642,
2166,
14,
267,
6630,
12,
314,
8852,
3123,
365,
22319,
3224,
1373,
2166,
436,
282,
892,
1738,
267,
13252,
365,
2737,
12,
18170,
314,
3411,
3123,
436,
314,
892,
1031,
14,
267,
408,
267,
340,
1031,
315,
291,
14,
3223,
436,
2557,
63,
466,
508,
291,
14,
11815,
26,
288,
372,
267,
340,
822,
8,
277,
14,
3223,
9,
665,
499,
26,
288,
291,
14,
11815,
275,
2557,
63,
466,
267,
340,
291,
14,
11815,
508,
2557,
63,
466,
26,
288,
340,
1228,
8,
932,
12,
5013,
9,
436,
334,
932,
14,
11815,
508,
2557,
63,
466,
503,
490,
822,
8,
932,
9,
508,
413,
304,
355,
291,
14,
3223,
14,
2880,
8,
932,
14,
3223,
9,
288,
587,
26,
355,
291,
14,
3223,
14,
740,
8,
932,
9,
267,
587,
26,
288,
1559,
275,
291,
423,
1222,
63,
842,
8,
277,
14,
3223,
12,
291,
14,
11815,
12,
490,
291,
14,
8705,
972,
9,
288,
291,
14,
11815,
275,
2557,
63,
466,
288,
291,
14,
3223,
275,
359,
1113,
12,
1031,
61,
339,
347,
30112,
8,
277,
304,
267,
408,
267,
5612,
3237,
314,
12249,
402,
314,
1738,
13252,
14,
961,
295,
19916,
1388,
314,
4978,
267,
880,
626,
314,
1453,
1031,
965,
282,
2849,
1982,
26,
282,
14158,
972,
1031,
3035,
267,
1006,
314,
4136,
4978,
14,
961,
18023,
16699,
14538,
7704,
7791,
267,
892,
4978,
24062,
1655,
1109,
1907,
9462,
14,
398,
6551,
657,
1337,
314,
11150,
402,
642,
30112,
365,
1536,
370,
1890,
1233,
14,
961,
267,
1083,
365,
2997,
367,
18234,
298,
1397,
2,
601,
1842,
1470,
14,
267,
408,
267,
291,
14,
3223,
275,
359,
277,
423,
1222,
63,
842,
8,
277,
14,
3223,
12,
291,
14,
11815,
12,
355,
440,
291,
14,
8705,
972,
1874,
267,
291,
14,
11815,
275,
291,
14,
885,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
twobob/buildroot-kindle
|
output/build/host-python-2.7.2/Tools/scripts/pysource.py
|
94
|
3846
|
#!/usr/bin/env python
"""\
List python source files.
There are three functions to check whether a file is a Python source, listed
here with increasing complexity:
- has_python_ext() checks whether a file name ends in '.py[w]'.
- look_like_python() checks whether the file is not binary and either has
the '.py[w]' extension or the first line contains the word 'python'.
- can_be_compiled() checks whether the file can be compiled by compile().
The file also must be of appropriate size - not bigger than a megabyte.
walk_python_files() recursively lists all Python files under the given directories.
"""
__author__ = "Oleg Broytmann, Georg Brandl"
__all__ = ["has_python_ext", "looks_like_python", "can_be_compiled", "walk_python_files"]
import os, re
binary_re = re.compile('[\x00-\x08\x0E-\x1F\x7F]')
debug = False
def print_debug(msg):
if debug: print msg
def _open(fullpath):
try:
size = os.stat(fullpath).st_size
except OSError, err: # Permission denied - ignore the file
print_debug("%s: permission denied: %s" % (fullpath, err))
return None
if size > 1024*1024: # too big
print_debug("%s: the file is too big: %d bytes" % (fullpath, size))
return None
try:
return open(fullpath, 'rU')
except IOError, err: # Access denied, or a special file - ignore it
print_debug("%s: access denied: %s" % (fullpath, err))
return None
def has_python_ext(fullpath):
return fullpath.endswith(".py") or fullpath.endswith(".pyw")
def looks_like_python(fullpath):
infile = _open(fullpath)
if infile is None:
return False
line = infile.readline()
infile.close()
if binary_re.search(line):
# file appears to be binary
print_debug("%s: appears to be binary" % fullpath)
return False
if fullpath.endswith(".py") or fullpath.endswith(".pyw"):
return True
elif "python" in line:
# disguised Python script (e.g. CGI)
return True
return False
def can_be_compiled(fullpath):
infile = _open(fullpath)
if infile is None:
return False
code = infile.read()
infile.close()
try:
compile(code, fullpath, "exec")
except Exception, err:
print_debug("%s: cannot compile: %s" % (fullpath, err))
return False
return True
def walk_python_files(paths, is_python=looks_like_python, exclude_dirs=None):
"""\
Recursively yield all Python source files below the given paths.
paths: a list of files and/or directories to be checked.
is_python: a function that takes a file name and checks whether it is a
Python source file
exclude_dirs: a list of directory base names that should be excluded in
the search
"""
if exclude_dirs is None:
exclude_dirs=[]
for path in paths:
print_debug("testing: %s" % path)
if os.path.isfile(path):
if is_python(path):
yield path
elif os.path.isdir(path):
print_debug(" it is a directory")
for dirpath, dirnames, filenames in os.walk(path):
for exclude in exclude_dirs:
if exclude in dirnames:
dirnames.remove(exclude)
for filename in filenames:
fullpath = os.path.join(dirpath, filename)
print_debug("testing: %s" % fullpath)
if is_python(fullpath):
yield fullpath
else:
print_debug(" unknown type")
if __name__ == "__main__":
# Two simple examples/tests
for fullpath in walk_python_files(['.']):
print fullpath
print "----------"
for fullpath in walk_python_files(['.'], is_python=can_be_compiled):
print fullpath
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
19659,
199,
1296,
2366,
1350,
1584,
14,
199,
199,
10924,
787,
7795,
3423,
370,
1104,
3775,
282,
570,
365,
282,
2018,
1350,
12,
10532,
199,
1681,
543,
22255,
6114,
1209,
26,
199,
199,
13,
965,
63,
1548,
63,
832,
342,
5920,
3775,
282,
570,
536,
11187,
315,
1987,
647,
59,
87,
61,
1370,
199,
13,
3648,
63,
2930,
63,
1548,
342,
5920,
3775,
314,
570,
365,
440,
3366,
436,
1902,
965,
523,
314,
1987,
647,
59,
87,
6616,
3329,
503,
314,
1642,
1004,
3509,
314,
4349,
283,
1548,
1370,
199,
13,
883,
63,
1235,
63,
8427,
342,
5920,
3775,
314,
570,
883,
506,
10311,
701,
6555,
1252,
199,
199,
1918,
570,
2597,
1471,
506,
402,
5827,
1568,
446,
440,
29416,
2419,
282,
562,
71,
17585,
266,
14,
199,
199,
7757,
63,
1548,
63,
1725,
342,
15035,
5548,
1006,
2018,
1584,
1334,
314,
1627,
6602,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
47,
4170,
699,
4813,
7574,
1189,
12,
5346,
1308,
699,
3759,
76,
2,
199,
199,
363,
452,
363,
275,
2097,
1989,
63,
1548,
63,
832,
401,
298,
11660,
83,
63,
2930,
63,
1548,
401,
298,
2425,
63,
1235,
63,
8427,
401,
298,
7757,
63,
1548,
63,
1725,
937,
421,
199,
646,
747,
12,
295,
199,
199,
3008,
63,
264,
275,
295,
14,
2014,
360,
7023,
88,
383,
2696,
88,
2036,
60,
88,
16,
37,
2696,
88,
17,
38,
60,
88,
23,
38,
10374,
199,
199,
1757,
275,
756,
199,
199,
318,
870,
63,
1757,
8,
1328,
304,
272,
340,
3105,
26,
870,
1499,
421,
199,
318,
485,
1490,
8,
17943,
304,
272,
862,
26,
267,
1568,
275,
747,
14,
3736,
8,
17943,
680,
270,
63,
890,
272,
871,
6440,
12,
2329,
26,
327,
8779,
23355,
446,
3686,
314,
570,
267,
870,
63,
1757,
3647,
83,
26,
4983,
23355,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
488,
339,
340,
1568,
690,
6619,
10,
7727,
26,
327,
4634,
7282,
267,
870,
63,
1757,
3647,
83,
26,
314,
570,
365,
4634,
7282,
26,
450,
68,
2783,
2,
450,
334,
17943,
12,
1568,
430,
267,
372,
488,
339,
862,
26,
267,
372,
1551,
8,
17943,
12,
283,
28978,
358,
272,
871,
5925,
12,
2329,
26,
327,
11003,
23355,
12,
503,
282,
4539,
570,
446,
3686,
652,
267,
870,
63,
1757,
3647,
83,
26,
2879,
23355,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
488,
199,
199,
318,
965,
63,
1548,
63,
832,
8,
17943,
304,
272,
372,
26404,
14,
4130,
9520,
647,
531,
503,
26404,
14,
4130,
9520,
647,
87,
531,
199,
199,
318,
10734,
63,
2930,
63,
1548,
8,
17943,
304,
272,
14734,
275,
485,
1490,
8,
17943,
9,
272,
340,
14734,
365,
488,
26,
267,
372,
756,
339,
1004,
275,
14734,
14,
6407,
342,
272,
14734,
14,
1600,
342,
339,
340,
3366,
63,
264,
14,
1733,
8,
604,
304,
267,
327,
570,
11337,
370,
506,
3366,
267,
870,
63,
1757,
3647,
83,
26,
11337,
370,
506,
3366,
2,
450,
26404,
9,
267,
372,
756,
339,
340,
26404,
14,
4130,
9520,
647,
531,
503,
26404,
14,
4130,
9520,
647,
87,
2349,
267,
372,
715,
272,
916,
298,
1548,
2,
315,
1004,
26,
267,
327,
487,
1226,
85,
9096,
2018,
2884,
334,
69,
14,
71,
14,
28716,
9,
267,
372,
715,
339,
372,
756,
199,
199,
318,
883,
63,
1235,
63,
8427,
8,
17943,
304,
272,
14734,
275,
485,
1490,
8,
17943,
9,
272,
340,
14734,
365,
488,
26,
267,
372,
756,
339,
1233,
275,
14734,
14,
739,
342,
272,
14734,
14,
1600,
342,
339,
862,
26,
267,
6555,
8,
600,
12,
26404,
12,
298,
1628,
531,
272,
871,
2186,
12,
2329,
26,
267,
870,
63,
1757,
3647,
83,
26,
3913,
6555,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
756,
339,
372,
715,
421,
199,
318,
12778,
63,
1548,
63,
1725,
8,
3771,
12,
365,
63,
1548,
29,
11660,
83,
63,
2930,
63,
1548,
12,
5760,
63,
3220,
29,
403,
304,
272,
9638,
272,
18306,
9840,
1995,
1006,
2018,
1350,
1584,
5084,
314,
1627,
3792,
14,
339,
3792,
26,
282,
769,
402,
1584,
436,
15,
269,
6602,
370,
506,
7923,
14,
272,
365,
63,
1548,
26,
282,
805,
626,
6181,
282,
570,
536,
436,
5920,
3775,
652,
365,
282,
2049,
2018,
1350,
570,
272,
5760,
63,
3220,
26,
282,
769,
402,
2082,
1300,
1561,
626,
1077,
506,
8789,
315,
2116,
314,
2754,
272,
408,
272,
340,
5760,
63,
3220,
365,
488,
26,
267,
5760,
63,
3220,
9811,
339,
367,
931,
315,
3792,
26,
267,
870,
63,
1757,
480,
4776,
26,
450,
83,
2,
450,
931,
9,
267,
340,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
340,
365,
63,
1548,
8,
515,
304,
355,
1995,
931,
267,
916,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
870,
63,
1757,
480,
259,
652,
365,
282,
2082,
531,
288,
367,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
515,
304,
355,
367,
5760,
315,
5760,
63,
3220,
26,
490,
340,
5760,
315,
22310,
26,
717,
22310,
14,
2168,
8,
5473,
9,
355,
367,
1788,
315,
6203,
26,
490,
26404,
275,
747,
14,
515,
14,
904,
8,
17254,
12,
1788,
9,
490,
870,
63,
1757,
480,
4776,
26,
450,
83,
2,
450,
26404,
9,
490,
340,
365,
63,
1548,
8,
17943,
304,
717,
1995,
26404,
267,
587,
26,
288,
870,
63,
1757,
480,
259,
5809,
730,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
16853,
3486,
7251,
15,
2219,
272,
367,
26404,
315,
12778,
63,
1548,
63,
1725,
2941,
14,
9090,
267,
870,
26404,
272,
870,
298,
9460,
2,
272,
367,
26404,
315,
12778,
63,
1548,
63,
1725,
2941,
14,
995,
365,
63,
1548,
29,
2425,
63,
1235,
63,
8427,
304,
267,
870,
26404,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
19659,
199,
1296,
2366,
1350,
1584,
14,
199,
199,
10924,
787,
7795,
3423,
370,
1104,
3775,
282,
570,
365,
282,
2018,
1350,
12,
10532,
199,
1681,
543,
22255,
6114,
1209,
26,
199,
199,
13,
965,
63,
1548,
63,
832,
342,
5920,
3775,
282,
570,
536,
11187,
315,
1987,
647,
59,
87,
61,
1370,
199,
13,
3648,
63,
2930,
63,
1548,
342,
5920,
3775,
314,
570,
365,
440,
3366,
436,
1902,
965,
523,
314,
1987,
647,
59,
87,
6616,
3329,
503,
314,
1642,
1004,
3509,
314,
4349,
283,
1548,
1370,
199,
13,
883,
63,
1235,
63,
8427,
342,
5920,
3775,
314,
570,
883,
506,
10311,
701,
6555,
1252,
199,
199,
1918,
570,
2597,
1471,
506,
402,
5827,
1568,
446,
440,
29416,
2419,
282,
562,
71,
17585,
266,
14,
199,
199,
7757,
63,
1548,
63,
1725,
342,
15035,
5548,
1006,
2018,
1584,
1334,
314,
1627,
6602,
14,
199,
624,
199,
363,
2502,
363,
275,
298,
47,
4170,
699,
4813,
7574,
1189,
12,
5346,
1308,
699,
3759,
76,
2,
199,
199,
363,
452,
363,
275,
2097,
1989,
63,
1548,
63,
832,
401,
298,
11660,
83,
63,
2930,
63,
1548,
401,
298,
2425,
63,
1235,
63,
8427,
401,
298,
7757,
63,
1548,
63,
1725,
937,
421,
199,
646,
747,
12,
295,
199,
199,
3008,
63,
264,
275,
295,
14,
2014,
360,
7023,
88,
383,
2696,
88,
2036,
60,
88,
16,
37,
2696,
88,
17,
38,
60,
88,
23,
38,
10374,
199,
199,
1757,
275,
756,
199,
199,
318,
870,
63,
1757,
8,
1328,
304,
272,
340,
3105,
26,
870,
1499,
421,
199,
318,
485,
1490,
8,
17943,
304,
272,
862,
26,
267,
1568,
275,
747,
14,
3736,
8,
17943,
680,
270,
63,
890,
272,
871,
6440,
12,
2329,
26,
327,
8779,
23355,
446,
3686,
314,
570,
267,
870,
63,
1757,
3647,
83,
26,
4983,
23355,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
488,
339,
340,
1568,
690,
6619,
10,
7727,
26,
327,
4634,
7282,
267,
870,
63,
1757,
3647,
83,
26,
314,
570,
365,
4634,
7282,
26,
450,
68,
2783,
2,
450,
334,
17943,
12,
1568,
430,
267,
372,
488,
339,
862,
26,
267,
372,
1551,
8,
17943,
12,
283,
28978,
358,
272,
871,
5925,
12,
2329,
26,
327,
11003,
23355,
12,
503,
282,
4539,
570,
446,
3686,
652,
267,
870,
63,
1757,
3647,
83,
26,
2879,
23355,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
488,
199,
199,
318,
965,
63,
1548,
63,
832,
8,
17943,
304,
272,
372,
26404,
14,
4130,
9520,
647,
531,
503,
26404,
14,
4130,
9520,
647,
87,
531,
199,
199,
318,
10734,
63,
2930,
63,
1548,
8,
17943,
304,
272,
14734,
275,
485,
1490,
8,
17943,
9,
272,
340,
14734,
365,
488,
26,
267,
372,
756,
339,
1004,
275,
14734,
14,
6407,
342,
272,
14734,
14,
1600,
342,
339,
340,
3366,
63,
264,
14,
1733,
8,
604,
304,
267,
327,
570,
11337,
370,
506,
3366,
267,
870,
63,
1757,
3647,
83,
26,
11337,
370,
506,
3366,
2,
450,
26404,
9,
267,
372,
756,
339,
340,
26404,
14,
4130,
9520,
647,
531,
503,
26404,
14,
4130,
9520,
647,
87,
2349,
267,
372,
715,
272,
916,
298,
1548,
2,
315,
1004,
26,
267,
327,
487,
1226,
85,
9096,
2018,
2884,
334,
69,
14,
71,
14,
28716,
9,
267,
372,
715,
339,
372,
756,
199,
199,
318,
883,
63,
1235,
63,
8427,
8,
17943,
304,
272,
14734,
275,
485,
1490,
8,
17943,
9,
272,
340,
14734,
365,
488,
26,
267,
372,
756,
339,
1233,
275,
14734,
14,
739,
342,
272,
14734,
14,
1600,
342,
339,
862,
26,
267,
6555,
8,
600,
12,
26404,
12,
298,
1628,
531,
272,
871,
2186,
12,
2329,
26,
267,
870,
63,
1757,
3647,
83,
26,
3913,
6555,
26,
450,
83,
2,
450,
334,
17943,
12,
2329,
430,
267,
372,
756,
339,
372,
715,
421,
199,
318,
12778,
63,
1548,
63,
1725,
8,
3771,
12,
365,
63,
1548,
29,
11660,
83,
63,
2930,
63,
1548,
12,
5760,
63,
3220,
29,
403,
304,
272,
9638,
272,
18306,
9840,
1995,
1006,
2018,
1350,
1584,
5084,
314,
1627,
3792,
14,
339,
3792,
26,
282,
769,
402,
1584,
436,
15,
269,
6602,
370,
506,
7923,
14,
272,
365,
63,
1548,
26,
282,
805,
626,
6181,
282,
570,
536,
436,
5920,
3775,
652,
365,
282,
2049,
2018,
1350,
570,
272,
5760,
63,
3220,
26,
282,
769,
402,
2082,
1300,
1561,
626,
1077,
506,
8789,
315,
2116,
314,
2754,
272,
408,
272,
340,
5760,
63,
3220,
365,
488,
26,
267,
5760,
63,
3220,
9811,
339,
367,
931,
315,
3792,
26,
267,
870,
63,
1757,
480,
4776,
26,
450,
83,
2,
450,
931,
9,
267,
340,
747,
14,
515,
14,
6292,
8,
515,
304,
288,
340,
365,
63,
1548,
8,
515,
304,
355,
1995,
931,
267,
916,
747,
14,
515,
14,
6027,
8,
515,
304,
288,
870,
63,
1757,
480,
259,
652,
365,
282,
2082,
531,
288,
367,
20648,
12,
22310,
12,
6203,
315,
747,
14,
7757,
8,
515,
304,
355,
367,
5760,
315,
5760,
63,
3220,
26,
490,
340,
5760,
315,
22310,
26,
717,
22310,
14,
2168,
8,
5473,
9,
355,
367,
1788,
315,
6203,
26,
490,
26404,
275,
747,
14,
515,
14,
904,
8,
17254,
12,
1788,
9,
490,
870,
63,
1757,
480,
4776,
26,
450,
83,
2,
450,
26404,
9,
490,
340,
365,
63,
1548,
8,
17943,
304,
717,
1995,
26404,
267,
587,
26,
288,
870,
63,
1757,
480,
259,
5809,
730,
531,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
327,
16853,
3486,
7251,
15,
2219,
272,
367,
26404,
315,
12778,
63,
1548,
63,
1725,
2941,
14,
9090,
267,
870,
26404,
272,
870,
298,
9460,
2,
272,
367,
26404,
315,
12778,
63,
1548,
63,
1725,
2941,
14,
995,
365,
63,
1548,
29,
2425,
63,
1235,
63,
8427,
304,
267,
870,
26404,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eMerzh/Diamond-1
|
src/collectors/example/test/testexample.py
|
38
|
1240
|
#!/usr/bin/python
# coding=utf-8
################################################################################
from test import CollectorTestCase
from test import get_collector_config
from test import unittest
from mock import patch
from diamond.collector import Collector
from example import ExampleCollector
################################################################################
class TestExampleCollector(CollectorTestCase):
def setUp(self):
config = get_collector_config('ExampleCollector', {
'interval': 10
})
self.collector = ExampleCollector(config, None)
def test_import(self):
self.assertTrue(ExampleCollector)
@patch.object(Collector, 'publish')
def test(self, publish_mock):
self.collector.collect()
metrics = {
'my.example.metric': 42
}
self.setDocExample(collector=self.collector.__class__.__name__,
metrics=metrics,
defaultpath=self.collector.config['path'])
self.assertPublishedMany(publish_mock, metrics)
################################################################################
if __name__ == "__main__":
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
2803,
29,
1624,
13,
24,
199,
13289,
199,
199,
504,
511,
492,
3626,
3283,
1746,
199,
504,
511,
492,
664,
63,
10946,
63,
888,
199,
504,
511,
492,
2882,
199,
504,
1683,
492,
3371,
199,
199,
504,
487,
24940,
14,
10946,
492,
3626,
3283,
199,
504,
2893,
492,
5679,
12852,
199,
199,
13289,
421,
199,
533,
1379,
9846,
12852,
8,
12852,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1101,
275,
664,
63,
10946,
63,
888,
360,
9846,
12852,
297,
469,
288,
283,
4284,
356,
1616,
267,
3828,
398,
291,
14,
10946,
275,
5679,
12852,
8,
888,
12,
488,
9,
339,
347,
511,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
9846,
12852,
9,
339,
768,
2068,
14,
785,
8,
12852,
12,
283,
4763,
358,
272,
347,
511,
8,
277,
12,
2780,
63,
1805,
304,
267,
291,
14,
10946,
14,
7112,
342,
398,
7186,
275,
469,
288,
283,
1662,
14,
2694,
14,
5165,
356,
221,
5685,
267,
789,
398,
291,
14,
409,
3768,
9846,
8,
10946,
29,
277,
14,
10946,
855,
533,
4914,
354,
3108,
2574,
7186,
29,
6759,
12,
2574,
849,
515,
29,
277,
14,
10946,
14,
888,
459,
515,
1105,
267,
291,
14,
479,
27862,
4089,
8,
4763,
63,
1805,
12,
7186,
9,
199,
199,
13289,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2803,
29,
1624,
13,
24,
199,
13289,
199,
199,
504,
511,
492,
3626,
3283,
1746,
199,
504,
511,
492,
664,
63,
10946,
63,
888,
199,
504,
511,
492,
2882,
199,
504,
1683,
492,
3371,
199,
199,
504,
487,
24940,
14,
10946,
492,
3626,
3283,
199,
504,
2893,
492,
5679,
12852,
199,
199,
13289,
421,
199,
533,
1379,
9846,
12852,
8,
12852,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1101,
275,
664,
63,
10946,
63,
888,
360,
9846,
12852,
297,
469,
288,
283,
4284,
356,
1616,
267,
3828,
398,
291,
14,
10946,
275,
5679,
12852,
8,
888,
12,
488,
9,
339,
347,
511,
63,
646,
8,
277,
304,
267,
291,
14,
1815,
8,
9846,
12852,
9,
339,
768,
2068,
14,
785,
8,
12852,
12,
283,
4763,
358,
272,
347,
511,
8,
277,
12,
2780,
63,
1805,
304,
267,
291,
14,
10946,
14,
7112,
342,
398,
7186,
275,
469,
288,
283,
1662,
14,
2694,
14,
5165,
356,
221,
5685,
267,
789,
398,
291,
14,
409,
3768,
9846,
8,
10946,
29,
277,
14,
10946,
855,
533,
4914,
354,
3108,
2574,
7186,
29,
6759,
12,
2574,
849,
515,
29,
277,
14,
10946,
14,
888,
459,
515,
1105,
267,
291,
14,
479,
27862,
4089,
8,
4763,
63,
1805,
12,
7186,
9,
199,
199,
13289,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
schlueter/ansible
|
test/units/modules/network/netscaler/test_netscaler_nitro_request.py
|
57
|
12941
|
# Copyright (c) 2017 Citrix Systems
#
# 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.compat.tests.mock import patch, Mock, call
from .netscaler_module import TestModule
import copy
import tempfile
import json
import sys
import codecs
from ansible.modules.network.netscaler import netscaler_nitro_request
module_arguments = dict(
nsip=None,
nitro_user=None,
nitro_pass=None,
nitro_protocol=None,
validate_certs=None,
nitro_auth_token=None,
resource=None,
name=None,
attributes=None,
args=None,
filter=None,
operation=None,
expected_nitro_errorcode=None,
action=None,
instance_ip=None,
instance_name=None,
instance_id=None,
)
class TestNetscalerNitroRequestModule(TestModule):
@classmethod
def setUpClass(cls):
class MockException(Exception):
pass
cls.MockException = MockException
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
pass
def tearDown(self):
pass
def test_fail_on_conflicting_authentication_methods(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
nitro_auth_token='##DDASKLFDJ',
))
mock_module_instance = Mock(params=args)
expected_calls = [
call.fail_json(
changed=False,
failed=True,
msg='Cannot define both authentication token and username/password'
)
]
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
netscaler_nitro_request.NitroAPICaller()
mock_module_instance.assert_has_calls(expected_calls)
def test_nitro_user_pass_credentials(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
))
mock_module_instance = Mock(params=args)
expected_headers = {
'Content-Type': 'application/json',
'X-NITRO-USER': 'nsroot',
'X-NITRO-PASS': 'nsroot',
}
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
instance = netscaler_nitro_request.NitroAPICaller()
self.assertDictEqual(instance._headers, expected_headers)
def test_mas_login_headers(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
operation='mas_login',
))
mock_module_instance = Mock(params=args)
expected_headers = {
'Content-Type': 'application/json',
}
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
instance = netscaler_nitro_request.NitroAPICaller()
self.assertDictEqual(instance._headers, expected_headers)
def test_mas_proxy_call_headers_instance_ip(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_auth_token='##ABDB',
operation='add',
instance_ip='192.168.1.1',
))
mock_module_instance = Mock(params=args)
expected_headers = {
'Content-Type': 'application/json',
'_MPS_API_PROXY_MANAGED_INSTANCE_IP': args['instance_ip'],
'Cookie': 'NITRO_AUTH_TOKEN=%s' % args['nitro_auth_token'],
}
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
instance = netscaler_nitro_request.NitroAPICaller()
self.assertDictEqual(instance._headers, expected_headers)
def test_mas_proxy_call_headers_instance_id(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_auth_token='##ABDB',
operation='add',
instance_id='myid',
))
mock_module_instance = Mock(params=args)
expected_headers = {
'Content-Type': 'application/json',
'_MPS_API_PROXY_MANAGED_INSTANCE_ID': args['instance_id'],
'Cookie': 'NITRO_AUTH_TOKEN=%s' % args['nitro_auth_token'],
}
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
instance = netscaler_nitro_request.NitroAPICaller()
self.assertDictEqual(instance._headers, expected_headers)
def test_mas_proxy_call_headers_instance_name(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_auth_token='##ABDB',
operation='add',
instance_name='myname',
))
mock_module_instance = Mock(params=args)
expected_headers = {
'Content-Type': 'application/json',
'_MPS_API_PROXY_MANAGED_INSTANCE_NAME': args['instance_name'],
'Cookie': 'NITRO_AUTH_TOKEN=%s' % args['nitro_auth_token'],
}
module_mock = Mock(return_value=mock_module_instance)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', module_mock):
instance = netscaler_nitro_request.NitroAPICaller()
self.assertDictEqual(instance._headers, expected_headers)
def test_edit_response_data_no_body_success_status(self):
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule'):
instance = netscaler_nitro_request.NitroAPICaller()
r = None
info = {
'status': 200,
}
result = {}
success_status = 200
expected_result = {
'nitro_errorcode': 0,
'nitro_message': 'Success',
'nitro_severity': 'NONE',
'http_response_body': '',
'http_response_data': info,
}
instance.edit_response_data(r, info, result, success_status)
self.assertDictEqual(result, expected_result)
def test_edit_response_data_no_body_fail_status(self):
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule'):
instance = netscaler_nitro_request.NitroAPICaller()
r = None
info = {
'status': 201,
}
result = {}
success_status = 200
expected_result = {
'nitro_errorcode': -1,
'nitro_message': 'HTTP status %s' % info['status'],
'nitro_severity': 'ERROR',
'http_response_body': '',
'http_response_data': info,
}
instance.edit_response_data(r, info, result, success_status)
self.assertDictEqual(result, expected_result)
def test_edit_response_data_actual_body_data(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
nitro_auth_token='##DDASKLFDJ',
))
module_mock = Mock(params=args, from_json=json.loads)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
with tempfile.TemporaryFile() as r:
actual_body = {
'errorcode': 258,
'message': 'Some error',
'severity': 'ERROR',
}
r.write(codecs.encode(json.dumps(actual_body), 'utf-8'))
r.seek(0)
instance = netscaler_nitro_request.NitroAPICaller()
info = {
'status': 200,
}
result = {}
success_status = 200
expected_result = {
'http_response_body': json.dumps(actual_body),
'http_response_data': info,
}
nitro_data = {}
for key, value in actual_body.items():
nitro_data['nitro_%s' % key] = value
expected_result.update(nitro_data)
instance.edit_response_data(r, info, result, success_status)
self.assertDictEqual(result, expected_result)
def test_edit_response_data_actual_body_data_irrelevant(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
nitro_auth_token='##DDASKLFDJ',
))
module_mock = Mock(params=args, from_json=json.loads)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
with tempfile.TemporaryFile() as r:
actual_body = {}
r.write(codecs.encode(json.dumps(actual_body), 'utf-8'))
r.seek(0)
instance = netscaler_nitro_request.NitroAPICaller()
info = {
'status': 200,
}
result = {}
success_status = 200
expected_result = {
'http_response_body': json.dumps(actual_body),
'http_response_data': info,
'nitro_errorcode': 0,
'nitro_message': 'Success',
'nitro_severity': 'NONE',
}
instance.edit_response_data(r, info, result, success_status)
self.assertDictEqual(result, expected_result)
def test_edit_response_data_body_in_info(self):
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
))
module_mock = Mock(params=args, from_json=json.loads)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
body = {
'errorcode': 258,
'message': 'Numerical error 258',
'severity': 'ERROR'
}
instance = netscaler_nitro_request.NitroAPICaller()
r = None
info = {
'status': 200,
'body': codecs.encode(json.dumps(body), 'utf-8'),
}
result = {}
success_status = 200
expected_result = {
'http_response_body': json.dumps(body),
'http_response_data': info,
}
nitro_data = {}
for key, value in body.items():
nitro_data['nitro_%s' % key] = value
expected_result.update(nitro_data)
instance.edit_response_data(r, info, result, success_status)
self.assertDictEqual(result, expected_result)
def test_handle_get_return_object(self):
resource = 'lbvserver'
args = copy.deepcopy(module_arguments)
args.update(dict(
nitro_user='nsroot',
nitro_pass='nsroot',
resource=resource,
))
resource_data = {
'property1': 'value1',
'property2': 'value2',
}
module_mock = Mock(params=args, from_json=json.loads)
with patch('ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
instance = netscaler_nitro_request.NitroAPICaller()
data = {resource: resource_data}
result = {
'nitro_errorcode': 0,
'http_response_body': json.dumps(data),
}
expected_result = {
'nitro_object': resource_data
}
expected_result.update(result)
instance.handle_get_return_object(result)
self.assertDictEqual(result, expected_result)
|
gpl-3.0
|
[
199,
3,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
12,
4420,
12,
1240,
199,
504,
1275,
18860,
63,
578,
492,
1379,
2377,
199,
646,
1331,
199,
646,
5549,
199,
646,
2022,
199,
646,
984,
199,
646,
6010,
199,
199,
504,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
18893,
63,
1069,
199,
199,
578,
63,
4958,
275,
1211,
8,
272,
302,
17839,
29,
403,
12,
272,
20107,
63,
751,
29,
403,
12,
272,
20107,
63,
1529,
29,
403,
12,
272,
20107,
63,
3922,
29,
403,
12,
272,
4107,
63,
8356,
29,
403,
12,
272,
20107,
63,
1178,
63,
1418,
29,
403,
12,
272,
2073,
29,
403,
12,
272,
536,
29,
403,
12,
272,
3004,
29,
403,
12,
272,
1249,
29,
403,
12,
272,
2457,
29,
403,
12,
272,
3439,
29,
403,
12,
272,
1420,
63,
18893,
63,
28857,
29,
403,
12,
272,
1595,
29,
403,
12,
272,
1256,
63,
711,
29,
403,
12,
272,
1256,
63,
354,
29,
403,
12,
272,
1256,
63,
344,
29,
403,
12,
199,
9,
421,
199,
533,
1379,
2480,
11494,
46,
12691,
2017,
2377,
8,
774,
2377,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
398,
843,
14,
3346,
1726,
275,
4420,
1726,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
986,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
511,
63,
1633,
63,
265,
63,
15207,
316,
63,
11725,
63,
2474,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
288,
20107,
63,
1178,
63,
1418,
534,
309,
5745,
7946,
44,
7902,
42,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
5352,
275,
359,
288,
1240,
14,
1633,
63,
1001,
8,
355,
2896,
29,
797,
12,
355,
3405,
29,
549,
12,
355,
1499,
534,
6612,
5627,
3865,
6299,
1526,
436,
3434,
15,
2060,
7,
288,
776,
267,
1622,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
1683,
63,
578,
63,
842,
14,
479,
63,
1989,
63,
5352,
8,
2062,
63,
5352,
9,
339,
347,
511,
63,
18893,
63,
751,
63,
1529,
63,
6942,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
2139,
275,
469,
288,
283,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
288,
283,
56,
13,
46,
649,
1092,
13,
3791,
356,
283,
561,
1231,
297,
288,
283,
56,
13,
46,
649,
1092,
13,
6909,
356,
283,
561,
1231,
297,
267,
789,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
1256,
275,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
291,
14,
19512,
8,
842,
423,
2139,
12,
1420,
63,
2139,
9,
339,
347,
511,
63,
5892,
63,
2886,
63,
2139,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
288,
3439,
534,
5892,
63,
2886,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
2139,
275,
469,
288,
283,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
267,
789,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
1256,
275,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
291,
14,
19512,
8,
842,
423,
2139,
12,
1420,
63,
2139,
9,
339,
347,
511,
63,
5892,
63,
3280,
63,
1250,
63,
2139,
63,
842,
63,
711,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
1178,
63,
1418,
534,
309,
1217,
2846,
297,
288,
3439,
534,
525,
297,
288,
1256,
63,
711,
534,
5756,
14,
6568,
14,
17,
14,
17,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420
] |
[
3,
221,
1898,
334,
67,
9,
9708,
445,
390,
1904,
15285,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
504,
3242,
14,
5819,
14,
2219,
14,
1805,
492,
3371,
12,
4420,
12,
1240,
199,
504,
1275,
18860,
63,
578,
492,
1379,
2377,
199,
646,
1331,
199,
646,
5549,
199,
646,
2022,
199,
646,
984,
199,
646,
6010,
199,
199,
504,
3242,
14,
3112,
14,
1200,
14,
18860,
492,
26067,
63,
18893,
63,
1069,
199,
199,
578,
63,
4958,
275,
1211,
8,
272,
302,
17839,
29,
403,
12,
272,
20107,
63,
751,
29,
403,
12,
272,
20107,
63,
1529,
29,
403,
12,
272,
20107,
63,
3922,
29,
403,
12,
272,
4107,
63,
8356,
29,
403,
12,
272,
20107,
63,
1178,
63,
1418,
29,
403,
12,
272,
2073,
29,
403,
12,
272,
536,
29,
403,
12,
272,
3004,
29,
403,
12,
272,
1249,
29,
403,
12,
272,
2457,
29,
403,
12,
272,
3439,
29,
403,
12,
272,
1420,
63,
18893,
63,
28857,
29,
403,
12,
272,
1595,
29,
403,
12,
272,
1256,
63,
711,
29,
403,
12,
272,
1256,
63,
354,
29,
403,
12,
272,
1256,
63,
344,
29,
403,
12,
199,
9,
421,
199,
533,
1379,
2480,
11494,
46,
12691,
2017,
2377,
8,
774,
2377,
304,
339,
768,
3744,
272,
347,
18561,
8,
1886,
304,
267,
1021,
4420,
1726,
8,
1726,
304,
288,
986,
398,
843,
14,
3346,
1726,
275,
4420,
1726,
339,
768,
3744,
272,
347,
24468,
8,
1886,
304,
267,
986,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
511,
63,
1633,
63,
265,
63,
15207,
316,
63,
11725,
63,
2474,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
288,
20107,
63,
1178,
63,
1418,
534,
309,
5745,
7946,
44,
7902,
42,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
5352,
275,
359,
288,
1240,
14,
1633,
63,
1001,
8,
355,
2896,
29,
797,
12,
355,
3405,
29,
549,
12,
355,
1499,
534,
6612,
5627,
3865,
6299,
1526,
436,
3434,
15,
2060,
7,
288,
776,
267,
1622,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
1683,
63,
578,
63,
842,
14,
479,
63,
1989,
63,
5352,
8,
2062,
63,
5352,
9,
339,
347,
511,
63,
18893,
63,
751,
63,
1529,
63,
6942,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
2139,
275,
469,
288,
283,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
288,
283,
56,
13,
46,
649,
1092,
13,
3791,
356,
283,
561,
1231,
297,
288,
283,
56,
13,
46,
649,
1092,
13,
6909,
356,
283,
561,
1231,
297,
267,
789,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
1256,
275,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
291,
14,
19512,
8,
842,
423,
2139,
12,
1420,
63,
2139,
9,
339,
347,
511,
63,
5892,
63,
2886,
63,
2139,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
751,
534,
561,
1231,
297,
288,
20107,
63,
1529,
534,
561,
1231,
297,
288,
3439,
534,
5892,
63,
2886,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
63,
2139,
275,
469,
288,
283,
2714,
13,
804,
356,
283,
3578,
15,
1001,
297,
267,
789,
267,
859,
63,
1805,
275,
4420,
8,
1107,
63,
585,
29,
1805,
63,
578,
63,
842,
9,
267,
543,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
18860,
14,
18860,
63,
18893,
63,
1069,
14,
10047,
2377,
297,
859,
63,
1805,
304,
288,
1256,
275,
26067,
63,
18893,
63,
1069,
14,
46,
12691,
1282,
948,
9230,
342,
288,
291,
14,
19512,
8,
842,
423,
2139,
12,
1420,
63,
2139,
9,
339,
347,
511,
63,
5892,
63,
3280,
63,
1250,
63,
2139,
63,
842,
63,
711,
8,
277,
304,
267,
1249,
275,
1331,
14,
8293,
8,
578,
63,
4958,
9,
267,
1249,
14,
873,
8,
807,
8,
288,
20107,
63,
1178,
63,
1418,
534,
309,
1217,
2846,
297,
288,
3439,
534,
525,
297,
288,
1256,
63,
711,
534,
5756,
14,
6568,
14,
17,
14,
17,
297,
267,
5082,
267,
1683,
63,
578,
63,
842,
275,
4420,
8,
1162,
29,
589,
9,
267,
1420,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ywcui1990/nupic
|
tests/swarming/nupic/swarming/experiments/dummyV2/permutations.py
|
10
|
3634
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# 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 Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""
Template file used by ExpGenerator to generate the actual
permutations.py file by replacing $XXXXXXXX tokens with desired values.
This permutations.py file was generated by:
'/Users/ronmarianetti/nupic/eng/lib/python2.6/site-packages/nupic/frameworks/opf/expGenerator/experiment_generator.py'
"""
import os
from nupic.swarming.permutation_helpers import *
# The name of the field being predicted. Any allowed permutation MUST contain
# the prediction field.
# (generated from PREDICTION_FIELD)
predictedField = 'consumption'
permutations = {
'modelParams': {
'sensorParams': {
'encoders': {
'gym': PermuteEncoder(fieldName='gym', encoderClass='SDRCategoryEncoder', w=21, n=300),
'timestamp_dayOfWeek': PermuteEncoder(fieldName='timestamp', encoderClass='DateEncoder.dayOfWeek', radius=PermuteChoices([1, 3]), w=7),
'timestamp_timeOfDay': PermuteEncoder(fieldName='timestamp', encoderClass='DateEncoder.timeOfDay', radius=PermuteChoices([1, 8]), w=7),
'consumption': PermuteEncoder(fieldName='consumption', encoderClass='ScalarEncoder', maxval=PermuteInt(100, 300, 25), n=PermuteInt(39, 1500, 60), w=21, minval=0),
'address': PermuteEncoder(fieldName='address', encoderClass='SDRCategoryEncoder', w=21, n=300),
},
},
'tmParams': {
'minThreshold': PermuteInt(9, 12),
'activationThreshold': PermuteInt(12, 16),
},
}
}
# Fields selected for final hypersearch report;
# NOTE: These values are used as regular expressions by RunPermutations.py's
# report generator
# (fieldname values generated from PERM_PREDICTED_FIELD_NAME)
report = [
'.*consumption.*',
]
# Permutation optimization setting: either minimize or maximize metric
# used by RunPermutations.
# NOTE: The value is used as a regular expressions by RunPermutations.py's
# report generator
# (generated from minimize = 'prediction:rmse:field=consumption')
minimize = 'prediction:rmse:field=consumption'
def permutationFilter(perm):
""" This function can be used to selectively filter out specific permutation
combinations. It is called by RunPermutations for every possible permutation
of the variables in the permutations dict. It should return True for valid a
combination of permutation values and False for an invalid one.
Parameters:
---------------------------------------------------------
perm: dict of one possible combination of name:value
pairs chosen from permutations.
"""
# An example of how to use this
if perm['modelParams']['sensorParams']['encoders']['consumption']['maxval'] > 250:
return False;
return True
|
agpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
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,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
4231,
570,
1202,
701,
7910,
7599,
370,
3550,
314,
3503,
199,
28237,
14,
647,
570,
701,
15810,
2672,
13312,
4645,
543,
6387,
1338,
14,
199,
199,
2765,
26899,
14,
647,
570,
1990,
4046,
701,
26,
199,
9807,
12117,
15,
2641,
77,
15289,
386,
280,
15,
14596,
530,
15,
7420,
15,
773,
15,
1548,
18,
14,
22,
15,
2124,
13,
5154,
15,
14596,
530,
15,
32037,
15,
16893,
15,
1474,
7599,
15,
10873,
63,
4679,
14,
647,
7,
199,
624,
199,
199,
646,
747,
199,
199,
504,
26084,
14,
22096,
316,
14,
23832,
63,
7546,
492,
627,
199,
199,
3,
710,
536,
402,
314,
901,
3769,
14746,
14,
221,
6184,
4370,
22966,
18095,
1395,
199,
3,
314,
12044,
901,
14,
199,
3,
334,
10176,
687,
510,
7387,
6196,
1075,
63,
8609,
9,
199,
21118,
792,
275,
283,
8704,
15052,
7,
199,
199,
28237,
275,
469,
819,
283,
1238,
6007,
356,
469,
272,
283,
8956,
6007,
356,
469,
489,
283,
9347,
83,
356,
469,
267,
283,
4312,
77,
356,
3492,
12423,
6679,
8,
698,
985,
534,
4312,
77,
297,
10295,
2543,
534,
3693,
50,
7841,
6679,
297,
336,
29,
2025,
12,
302,
29,
5863,
395,
267,
283,
3954,
63,
2977,
3466,
20995,
356,
3492,
12423,
6679,
8,
698,
985,
534,
3954,
297,
10295,
2543,
534,
2506,
6679,
14,
2977,
3466,
20995,
297,
9362,
29,
2623,
12423,
30806,
779,
17,
12,
650,
2522,
336,
29,
23,
395,
267,
283,
3954,
63,
521,
3466,
12631,
356,
3492,
12423,
6679,
8,
698,
985,
534,
3954,
297,
10295,
2543,
534,
2506,
6679,
14,
521,
3466,
12631,
297,
9362,
29,
2623,
12423,
30806,
779,
17,
12,
1695,
2522,
336,
29,
23,
395,
267,
283,
8704,
15052,
356,
3492,
12423,
6679,
8,
698,
985,
534,
8704,
15052,
297,
10295,
2543,
534,
13090,
6679,
297,
23291,
29,
2623,
12423,
3241,
8,
1960,
12,
9601,
12,
5661,
395,
302,
29,
2623,
12423,
3241,
8,
1355,
12,
24970,
12,
5212,
395,
336,
29,
2025,
12,
30135,
29,
16,
395,
267,
283,
1562,
356,
3492,
12423,
6679,
8,
698,
985,
534,
1562,
297,
10295,
2543,
534,
3693,
50,
7841,
6679,
297,
336,
29,
2025,
12,
302,
29,
5863,
395,
489,
1660,
272,
1660,
2378,
283,
7574,
6007,
356,
469,
489,
283,
827,
12109,
356,
3492,
12423,
3241,
8,
25,
12,
3144,
395,
489,
283,
12312,
12109,
356,
3492,
12423,
3241,
8,
713,
12,
3193,
395,
272,
1660,
2378,
789,
199,
93,
421,
199,
3,
16424,
4895,
367,
4242,
10342,
1733,
3622,
27,
199,
3,
6944,
26,
5723,
1338,
787,
1202,
465,
5578,
8455,
701,
3378,
2623,
15974,
14,
647,
1159,
199,
3,
755,
3622,
4306,
199,
3,
334,
13646,
1338,
4046,
687,
13873,
45,
63,
4225,
12511,
1149,
63,
8609,
63,
2339,
9,
199,
3070,
275,
359,
881,
1987,
10,
8704,
15052,
16110,
268,
1622,
199,
199,
3,
30054,
13712,
4260,
26,
1902,
24720,
503,
1390,
11807,
6370,
199,
3,
1202,
701,
3378,
2623,
15974,
14,
199,
3,
6944,
26,
710,
574,
365,
1202,
465,
282,
5578,
8455,
701,
3378,
2623,
15974,
14,
647,
1159,
199,
3,
755,
3622,
4306,
199,
3,
334,
10176,
687,
24720,
275,
283,
14845,
26,
5682,
261,
26,
698,
29,
8704,
15052,
358,
199,
19333,
275,
283,
14845,
26,
5682,
261,
26,
698,
29,
8704,
15052,
7,
4388,
199,
318,
22966,
4131,
8,
8220,
304,
523,
408,
961,
805,
883,
506,
1202,
370,
542,
10251,
9462,
2457,
734,
2488,
22966,
523,
15821,
14,
2779,
365,
2797,
701,
3378,
2623,
15974,
367,
4036,
3962,
22966,
523,
402,
314,
2860,
315,
314,
26899,
1211,
14,
2779,
1077,
372,
715,
367,
1686,
282,
523,
14665,
402,
22966,
1338,
436,
756,
367,
376,
3866,
1373,
14,
819,
3897,
26,
523,
9527,
9960,
523,
10869,
26,
1211,
402,
1373,
3962,
14665,
402,
536,
26,
585,
267,
6342,
12414,
687,
26899,
14,
523,
408,
819,
327,
1626,
2893,
402,
4212,
370,
675,
642,
523,
340,
10869,
459,
1238,
6007,
2545,
8956,
6007,
2545,
9347,
83,
2545,
8704,
15052,
2545,
30909,
418,
690,
16074,
26,
272,
372,
756,
27,
819,
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
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
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,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
4231,
570,
1202,
701,
7910,
7599,
370,
3550,
314,
3503,
199,
28237,
14,
647,
570,
701,
15810,
2672,
13312,
4645,
543,
6387,
1338,
14,
199,
199,
2765,
26899,
14,
647,
570,
1990,
4046,
701,
26,
199,
9807,
12117,
15,
2641,
77,
15289,
386,
280,
15,
14596,
530,
15,
7420,
15,
773,
15,
1548,
18,
14,
22,
15,
2124,
13,
5154,
15,
14596,
530,
15,
32037,
15,
16893,
15,
1474,
7599,
15,
10873,
63,
4679,
14,
647,
7,
199,
624,
199,
199,
646,
747,
199,
199,
504,
26084,
14,
22096,
316,
14,
23832,
63,
7546,
492,
627,
199,
199,
3,
710,
536,
402,
314,
901,
3769,
14746,
14,
221,
6184,
4370,
22966,
18095,
1395,
199,
3,
314,
12044,
901,
14,
199,
3,
334,
10176,
687,
510,
7387,
6196,
1075,
63,
8609,
9,
199,
21118,
792,
275,
283,
8704,
15052,
7,
199,
199,
28237,
275,
469,
819,
283,
1238,
6007,
356,
469,
272,
283,
8956,
6007,
356,
469,
489,
283,
9347,
83,
356,
469,
267,
283,
4312,
77,
356,
3492,
12423,
6679,
8,
698,
985,
534,
4312,
77,
297,
10295,
2543,
534,
3693,
50,
7841,
6679,
297,
336,
29,
2025,
12,
302,
29,
5863,
395,
267,
283,
3954,
63,
2977,
3466,
20995,
356,
3492,
12423,
6679,
8,
698,
985,
534,
3954,
297,
10295,
2543,
534,
2506,
6679,
14,
2977,
3466,
20995,
297,
9362,
29,
2623,
12423,
30806,
779,
17,
12,
650,
2522,
336,
29,
23,
395,
267,
283,
3954,
63,
521,
3466,
12631,
356,
3492,
12423,
6679,
8,
698,
985,
534,
3954,
297,
10295,
2543,
534,
2506,
6679,
14,
521,
3466,
12631,
297,
9362,
29,
2623,
12423,
30806,
779,
17,
12,
1695,
2522,
336,
29,
23,
395,
267,
283,
8704,
15052,
356,
3492,
12423,
6679,
8,
698,
985,
534,
8704,
15052,
297,
10295,
2543,
534,
13090,
6679,
297,
23291,
29,
2623,
12423,
3241,
8,
1960,
12,
9601,
12,
5661,
395,
302,
29,
2623,
12423,
3241,
8,
1355,
12,
24970,
12,
5212,
395,
336,
29,
2025,
12,
30135,
29,
16,
395,
267,
283,
1562,
356,
3492,
12423,
6679,
8,
698,
985,
534,
1562,
297,
10295,
2543,
534,
3693,
50,
7841,
6679,
297,
336,
29,
2025,
12,
302,
29,
5863,
395,
489,
1660,
272,
1660,
2378,
283,
7574,
6007,
356,
469,
489,
283,
827,
12109,
356,
3492,
12423,
3241,
8,
25,
12,
3144,
395,
489,
283,
12312,
12109,
356,
3492,
12423,
3241,
8,
713,
12,
3193,
395,
272,
1660,
2378,
789,
199,
93,
421,
199,
3,
16424,
4895,
367,
4242,
10342,
1733,
3622,
27,
199,
3,
6944,
26,
5723,
1338,
787,
1202,
465,
5578,
8455,
701,
3378,
2623,
15974,
14,
647,
1159,
199,
3,
755,
3622,
4306,
199,
3,
334,
13646,
1338,
4046,
687,
13873,
45,
63,
4225,
12511,
1149,
63,
8609,
63,
2339,
9,
199,
3070,
275,
359,
881,
1987,
10,
8704,
15052,
16110,
268,
1622,
199,
199,
3,
30054,
13712,
4260,
26,
1902,
24720,
503,
1390,
11807,
6370,
199,
3,
1202,
701,
3378,
2623,
15974,
14,
199,
3,
6944,
26,
710,
574,
365,
1202,
465,
282,
5578,
8455,
701,
3378,
2623,
15974,
14,
647,
1159,
199,
3,
755,
3622,
4306,
199,
3,
334,
10176,
687,
24720,
275,
283,
14845,
26,
5682,
261,
26,
698,
29,
8704,
15052,
358,
199,
19333,
275,
283,
14845,
26,
5682,
261,
26,
698,
29,
8704,
15052,
7,
4388,
199,
318,
22966,
4131,
8,
8220,
304,
523,
408,
961,
805,
883,
506,
1202,
370,
542,
10251,
9462,
2457,
734,
2488,
22966,
523,
15821,
14,
2779,
365,
2797,
701,
3378,
2623,
15974,
367,
4036,
3962,
22966,
523,
402,
314,
2860,
315,
314,
26899,
1211,
14,
2779,
1077,
372,
715,
367,
1686,
282,
523,
14665,
402,
22966,
1338,
436,
756,
367,
376,
3866,
1373,
14,
819,
3897,
26,
523,
9527,
9960,
523,
10869,
26,
1211,
402,
1373,
3962,
14665,
402,
536,
26,
585,
267,
6342,
12414,
687,
26899,
14,
523,
408,
819,
327,
1626,
2893,
402,
4212,
370,
675,
642,
523,
340,
10869,
459,
1238,
6007,
2545,
8956,
6007,
2545,
9347,
83,
2545,
8704,
15052,
2545,
30909,
418,
690,
16074,
26,
272,
372,
756,
27,
819,
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,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
0,
0,
0,
0,
0
] |
Emergya/icm-openedx-educamadrid-platform-basic
|
common/test/acceptance/tests/studio/test_studio_acid_xblock.py
|
130
|
6909
|
"""
Acceptance tests for Studio related to the acid xblock.
"""
from bok_choy.web_app_test import WebAppTest
from ...pages.studio.auto_auth import AutoAuthPage
from ...pages.studio.overview import CourseOutlinePage
from ...pages.xblock.acid import AcidView
from ...fixtures.course import CourseFixture, XBlockFixtureDesc
class XBlockAcidBase(WebAppTest):
"""
Base class for tests that verify that XBlock integration is working correctly
"""
__test__ = False
def setUp(self):
"""
Create a unique identifier for the course used in this test.
"""
# Ensure that the superclass sets up
super(XBlockAcidBase, self).setUp()
# Define a unique course identifier
self.course_info = {
'org': 'test_org',
'number': 'course_' + self.unique_id[:5],
'run': 'test_' + self.unique_id,
'display_name': 'Test Course ' + self.unique_id
}
self.outline = CourseOutlinePage(
self.browser,
self.course_info['org'],
self.course_info['number'],
self.course_info['run']
)
self.course_id = '{org}.{number}.{run}'.format(**self.course_info)
self.setup_fixtures()
self.auth_page = AutoAuthPage(
self.browser,
staff=False,
username=self.user.get('username'),
email=self.user.get('email'),
password=self.user.get('password')
)
self.auth_page.visit()
def validate_acid_block_preview(self, acid_block):
"""
Validate the Acid Block's preview
"""
self.assertTrue(acid_block.init_fn_passed)
self.assertTrue(acid_block.resource_url_passed)
self.assertTrue(acid_block.scope_passed('user_state'))
self.assertTrue(acid_block.scope_passed('user_state_summary'))
self.assertTrue(acid_block.scope_passed('preferences'))
self.assertTrue(acid_block.scope_passed('user_info'))
def test_acid_block_preview(self):
"""
Verify that all expected acid block tests pass in studio preview
"""
self.outline.visit()
subsection = self.outline.section('Test Section').subsection('Test Subsection')
unit = subsection.expand_subsection().unit('Test Unit').go_to()
acid_block = AcidView(self.browser, unit.xblocks[0].preview_selector)
self.validate_acid_block_preview(acid_block)
def test_acid_block_editor(self):
"""
Verify that all expected acid block tests pass in studio editor
"""
self.outline.visit()
subsection = self.outline.section('Test Section').subsection('Test Subsection')
unit = subsection.expand_subsection().unit('Test Unit').go_to()
acid_block = AcidView(self.browser, unit.xblocks[0].edit().editor_selector)
self.assertTrue(acid_block.init_fn_passed)
self.assertTrue(acid_block.resource_url_passed)
class XBlockAcidNoChildTest(XBlockAcidBase):
"""
Tests of an AcidBlock with no children
"""
__test__ = True
def setup_fixtures(self):
course_fix = CourseFixture(
self.course_info['org'],
self.course_info['number'],
self.course_info['run'],
self.course_info['display_name']
)
course_fix.add_children(
XBlockFixtureDesc('chapter', 'Test Section').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection').add_children(
XBlockFixtureDesc('vertical', 'Test Unit').add_children(
XBlockFixtureDesc('acid', 'Acid Block')
)
)
)
).install()
self.user = course_fix.user
class XBlockAcidParentBase(XBlockAcidBase):
"""
Base class for tests that verify that parent XBlock integration is working correctly
"""
__test__ = False
def validate_acid_block_preview(self, acid_block):
super(XBlockAcidParentBase, self).validate_acid_block_preview(acid_block)
self.assertTrue(acid_block.child_tests_passed)
def test_acid_block_preview(self):
"""
Verify that all expected acid block tests pass in studio preview
"""
self.outline.visit()
subsection = self.outline.section('Test Section').subsection('Test Subsection')
unit = subsection.expand_subsection().unit('Test Unit').go_to()
container = unit.xblocks[0].go_to_container()
acid_block = AcidView(self.browser, container.xblocks[0].preview_selector)
self.validate_acid_block_preview(acid_block)
class XBlockAcidEmptyParentTest(XBlockAcidParentBase):
"""
Tests of an AcidBlock with children
"""
__test__ = True
def setup_fixtures(self):
course_fix = CourseFixture(
self.course_info['org'],
self.course_info['number'],
self.course_info['run'],
self.course_info['display_name']
)
course_fix.add_children(
XBlockFixtureDesc('chapter', 'Test Section').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection').add_children(
XBlockFixtureDesc('vertical', 'Test Unit').add_children(
XBlockFixtureDesc('acid_parent', 'Acid Parent Block').add_children(
)
)
)
)
).install()
self.user = course_fix.user
class XBlockAcidChildTest(XBlockAcidParentBase):
"""
Tests of an AcidBlock with children
"""
__test__ = True
def setup_fixtures(self):
course_fix = CourseFixture(
self.course_info['org'],
self.course_info['number'],
self.course_info['run'],
self.course_info['display_name']
)
course_fix.add_children(
XBlockFixtureDesc('chapter', 'Test Section').add_children(
XBlockFixtureDesc('sequential', 'Test Subsection').add_children(
XBlockFixtureDesc('vertical', 'Test Unit').add_children(
XBlockFixtureDesc('acid_parent', 'Acid Parent Block').add_children(
XBlockFixtureDesc('acid', 'First Acid Child', metadata={'name': 'first'}),
XBlockFixtureDesc('acid', 'Second Acid Child', metadata={'name': 'second'}),
XBlockFixtureDesc('html', 'Html Child', data="<html>Contents</html>"),
)
)
)
)
).install()
self.user = course_fix.user
def test_acid_block_preview(self):
super(XBlockAcidChildTest, self).test_acid_block_preview()
def test_acid_block_editor(self):
super(XBlockAcidChildTest, self).test_acid_block_editor()
|
agpl-3.0
|
[
624,
199,
8422,
554,
2295,
367,
13225,
4048,
370,
314,
1066,
344,
12971,
14,
199,
624,
199,
504,
330,
745,
63,
2239,
89,
14,
2520,
63,
571,
63,
396,
492,
6001,
2640,
774,
199,
199,
504,
2263,
5856,
14,
19806,
14,
2495,
63,
1178,
492,
9195,
2817,
3276,
199,
504,
2263,
5856,
14,
19806,
14,
21753,
492,
5531,
21432,
3276,
199,
504,
2263,
5856,
14,
11283,
14,
645,
344,
492,
4473,
344,
2768,
199,
504,
2263,
8769,
14,
1972,
492,
5531,
12812,
12,
28802,
421,
199,
533,
15398,
1945,
344,
1563,
8,
5926,
2640,
774,
304,
272,
408,
272,
3523,
1021,
367,
2295,
626,
4911,
626,
15398,
13150,
365,
6449,
6657,
272,
408,
272,
636,
396,
363,
275,
756,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
282,
3747,
5148,
367,
314,
2518,
1202,
315,
642,
511,
14,
267,
408,
267,
327,
7523,
626,
314,
17035,
5951,
1536,
267,
1613,
8,
24784,
1945,
344,
1563,
12,
291,
680,
5996,
342,
398,
327,
13930,
282,
3747,
2518,
5148,
267,
291,
14,
1972,
63,
815,
275,
469,
288,
283,
1308,
356,
283,
396,
63,
1308,
297,
288,
283,
1955,
356,
283,
1972,
8650,
435,
291,
14,
3235,
63,
344,
1491,
21,
467,
288,
283,
1065,
356,
283,
396,
8650,
435,
291,
14,
3235,
63,
344,
12,
288,
283,
2918,
63,
354,
356,
283,
774,
5531,
283,
435,
291,
14,
3235,
63,
344,
267,
789,
398,
291,
14,
11550,
275,
5531,
21432,
3276,
8,
288,
291,
14,
5750,
12,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
288,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
418,
267,
776,
398,
291,
14,
1972,
63,
344,
275,
5041,
1308,
26944,
1955,
26944,
1065,
5285,
908,
3682,
277,
14,
1972,
63,
815,
9,
398,
291,
14,
2758,
63,
8769,
342,
398,
291,
14,
1178,
63,
1606,
275,
9195,
2817,
3276,
8,
288,
291,
14,
5750,
12,
288,
12622,
29,
797,
12,
288,
3434,
29,
277,
14,
751,
14,
362,
360,
2473,
659,
288,
3031,
29,
277,
14,
751,
14,
362,
360,
2123,
659,
288,
2505,
29,
277,
14,
751,
14,
362,
360,
2060,
358,
267,
776,
267,
291,
14,
1178,
63,
1606,
14,
5427,
342,
339,
347,
4107,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
12,
1066,
344,
63,
1457,
304,
267,
408,
267,
12134,
314,
4473,
344,
8651,
1159,
19653,
267,
408,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
826,
63,
2324,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
1927,
63,
633,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
929,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
929,
63,
4705,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
18063,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
815,
1333,
339,
347,
511,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
304,
267,
408,
267,
7635,
626,
1006,
1420,
1066,
344,
1853,
2295,
986,
315,
410,
5208,
19653,
267,
408,
398,
291,
14,
11550,
14,
5427,
342,
267,
19876,
275,
291,
14,
11550,
14,
2792,
360,
774,
15247,
1959,
18920,
360,
774,
4804,
2792,
358,
267,
4137,
275,
19876,
14,
4441,
63,
18920,
1252,
3248,
360,
774,
12008,
1959,
1939,
63,
475,
342,
398,
1066,
344,
63,
1457,
275,
4473,
344,
2768,
8,
277,
14,
5750,
12,
4137,
14,
88,
4166,
59,
16,
1055,
7780,
63,
6662,
9,
267,
291,
14,
3502,
63,
645,
344,
63,
1457,
63,
7780,
8,
645,
344,
63,
1457,
9,
339,
347,
511,
63,
645,
344,
63,
1457,
63,
7515,
8,
277,
304,
267,
408,
267,
7635,
626,
1006,
1420,
1066,
344,
1853,
2295,
986,
315,
410,
5208,
8823,
267,
408,
398,
291,
14,
11550,
14,
5427,
342,
267,
19876,
275,
291,
14,
11550,
14,
2792,
360,
774,
15247,
1959,
18920,
360,
774,
4804,
2792,
358,
267,
4137,
275,
19876,
14,
4441,
63,
18920,
1252,
3248,
360,
774,
12008,
1959,
1939,
63,
475,
342,
398,
1066,
344,
63,
1457,
275,
4473,
344,
2768,
8,
277,
14,
5750,
12,
4137,
14,
88,
4166,
59,
16,
1055,
3773,
1252,
7515,
63,
6662,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
826,
63,
2324,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
1927,
63,
633,
63,
12070,
9,
421,
199,
533,
15398,
1945,
344,
1944,
3493,
774,
8,
24784,
1945,
344,
1563,
304,
272,
408,
272,
6496,
402,
376,
4473,
344,
3142,
543,
949,
4978,
272,
408,
272,
636,
396,
363,
275,
715,
339,
347,
3272,
63,
8769,
8,
277,
304,
398,
2518,
63,
970,
275,
5531,
12812,
8,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
288,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
995,
288,
291,
14,
1972,
63,
815,
459,
2918,
63,
354,
418,
267,
776,
398,
2518,
63,
970,
14,
525,
63,
3223,
8,
288,
28802,
360,
11316,
297,
283,
774,
15247,
1959,
525,
63,
3223,
8,
355,
28802,
360,
16211,
297,
283,
774,
4804,
2792,
1959,
525,
63,
3223,
8,
490,
28802,
360,
7870,
297,
283,
774,
12008,
1959,
525,
63,
3223,
8,
717,
28802,
360,
645,
344,
297,
283,
1945,
344,
8651,
358,
490,
776,
355,
776,
288,
776,
267,
7092,
3174,
342,
398,
291,
14,
751,
275,
2518,
63,
970,
14,
751,
421,
199,
533,
15398,
1945,
344,
6652,
1563,
8,
24784,
1945,
344,
1563,
304,
272,
408,
272,
3523,
1021,
367,
2295,
626,
4911,
626,
1676,
15398,
13150,
365,
6449,
6657,
272,
408,
272,
636,
396,
363,
275,
756,
339,
347,
4107,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
12,
1066,
344,
63,
1457,
304,
267,
1613,
8,
24784,
1945,
344,
6652,
1563,
12,
291,
680,
3502,
63,
645,
344,
63,
1457,
63,
7780,
8,
645,
344,
63,
1457,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
1739,
63,
2219,
63,
12070,
9,
339,
347
] |
[
199,
8422,
554,
2295,
367,
13225,
4048,
370,
314,
1066,
344,
12971,
14,
199,
624,
199,
504,
330,
745,
63,
2239,
89,
14,
2520,
63,
571,
63,
396,
492,
6001,
2640,
774,
199,
199,
504,
2263,
5856,
14,
19806,
14,
2495,
63,
1178,
492,
9195,
2817,
3276,
199,
504,
2263,
5856,
14,
19806,
14,
21753,
492,
5531,
21432,
3276,
199,
504,
2263,
5856,
14,
11283,
14,
645,
344,
492,
4473,
344,
2768,
199,
504,
2263,
8769,
14,
1972,
492,
5531,
12812,
12,
28802,
421,
199,
533,
15398,
1945,
344,
1563,
8,
5926,
2640,
774,
304,
272,
408,
272,
3523,
1021,
367,
2295,
626,
4911,
626,
15398,
13150,
365,
6449,
6657,
272,
408,
272,
636,
396,
363,
275,
756,
339,
347,
3613,
8,
277,
304,
267,
408,
267,
2790,
282,
3747,
5148,
367,
314,
2518,
1202,
315,
642,
511,
14,
267,
408,
267,
327,
7523,
626,
314,
17035,
5951,
1536,
267,
1613,
8,
24784,
1945,
344,
1563,
12,
291,
680,
5996,
342,
398,
327,
13930,
282,
3747,
2518,
5148,
267,
291,
14,
1972,
63,
815,
275,
469,
288,
283,
1308,
356,
283,
396,
63,
1308,
297,
288,
283,
1955,
356,
283,
1972,
8650,
435,
291,
14,
3235,
63,
344,
1491,
21,
467,
288,
283,
1065,
356,
283,
396,
8650,
435,
291,
14,
3235,
63,
344,
12,
288,
283,
2918,
63,
354,
356,
283,
774,
5531,
283,
435,
291,
14,
3235,
63,
344,
267,
789,
398,
291,
14,
11550,
275,
5531,
21432,
3276,
8,
288,
291,
14,
5750,
12,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
288,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
418,
267,
776,
398,
291,
14,
1972,
63,
344,
275,
5041,
1308,
26944,
1955,
26944,
1065,
5285,
908,
3682,
277,
14,
1972,
63,
815,
9,
398,
291,
14,
2758,
63,
8769,
342,
398,
291,
14,
1178,
63,
1606,
275,
9195,
2817,
3276,
8,
288,
291,
14,
5750,
12,
288,
12622,
29,
797,
12,
288,
3434,
29,
277,
14,
751,
14,
362,
360,
2473,
659,
288,
3031,
29,
277,
14,
751,
14,
362,
360,
2123,
659,
288,
2505,
29,
277,
14,
751,
14,
362,
360,
2060,
358,
267,
776,
267,
291,
14,
1178,
63,
1606,
14,
5427,
342,
339,
347,
4107,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
12,
1066,
344,
63,
1457,
304,
267,
408,
267,
12134,
314,
4473,
344,
8651,
1159,
19653,
267,
408,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
826,
63,
2324,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
1927,
63,
633,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
929,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
929,
63,
4705,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
18063,
1333,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
2645,
63,
12070,
360,
751,
63,
815,
1333,
339,
347,
511,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
304,
267,
408,
267,
7635,
626,
1006,
1420,
1066,
344,
1853,
2295,
986,
315,
410,
5208,
19653,
267,
408,
398,
291,
14,
11550,
14,
5427,
342,
267,
19876,
275,
291,
14,
11550,
14,
2792,
360,
774,
15247,
1959,
18920,
360,
774,
4804,
2792,
358,
267,
4137,
275,
19876,
14,
4441,
63,
18920,
1252,
3248,
360,
774,
12008,
1959,
1939,
63,
475,
342,
398,
1066,
344,
63,
1457,
275,
4473,
344,
2768,
8,
277,
14,
5750,
12,
4137,
14,
88,
4166,
59,
16,
1055,
7780,
63,
6662,
9,
267,
291,
14,
3502,
63,
645,
344,
63,
1457,
63,
7780,
8,
645,
344,
63,
1457,
9,
339,
347,
511,
63,
645,
344,
63,
1457,
63,
7515,
8,
277,
304,
267,
408,
267,
7635,
626,
1006,
1420,
1066,
344,
1853,
2295,
986,
315,
410,
5208,
8823,
267,
408,
398,
291,
14,
11550,
14,
5427,
342,
267,
19876,
275,
291,
14,
11550,
14,
2792,
360,
774,
15247,
1959,
18920,
360,
774,
4804,
2792,
358,
267,
4137,
275,
19876,
14,
4441,
63,
18920,
1252,
3248,
360,
774,
12008,
1959,
1939,
63,
475,
342,
398,
1066,
344,
63,
1457,
275,
4473,
344,
2768,
8,
277,
14,
5750,
12,
4137,
14,
88,
4166,
59,
16,
1055,
3773,
1252,
7515,
63,
6662,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
826,
63,
2324,
63,
12070,
9,
267,
291,
14,
1815,
8,
645,
344,
63,
1457,
14,
1927,
63,
633,
63,
12070,
9,
421,
199,
533,
15398,
1945,
344,
1944,
3493,
774,
8,
24784,
1945,
344,
1563,
304,
272,
408,
272,
6496,
402,
376,
4473,
344,
3142,
543,
949,
4978,
272,
408,
272,
636,
396,
363,
275,
715,
339,
347,
3272,
63,
8769,
8,
277,
304,
398,
2518,
63,
970,
275,
5531,
12812,
8,
288,
291,
14,
1972,
63,
815,
459,
1308,
995,
288,
291,
14,
1972,
63,
815,
459,
1955,
995,
288,
291,
14,
1972,
63,
815,
459,
1065,
995,
288,
291,
14,
1972,
63,
815,
459,
2918,
63,
354,
418,
267,
776,
398,
2518,
63,
970,
14,
525,
63,
3223,
8,
288,
28802,
360,
11316,
297,
283,
774,
15247,
1959,
525,
63,
3223,
8,
355,
28802,
360,
16211,
297,
283,
774,
4804,
2792,
1959,
525,
63,
3223,
8,
490,
28802,
360,
7870,
297,
283,
774,
12008,
1959,
525,
63,
3223,
8,
717,
28802,
360,
645,
344,
297,
283,
1945,
344,
8651,
358,
490,
776,
355,
776,
288,
776,
267,
7092,
3174,
342,
398,
291,
14,
751,
275,
2518,
63,
970,
14,
751,
421,
199,
533,
15398,
1945,
344,
6652,
1563,
8,
24784,
1945,
344,
1563,
304,
272,
408,
272,
3523,
1021,
367,
2295,
626,
4911,
626,
1676,
15398,
13150,
365,
6449,
6657,
272,
408,
272,
636,
396,
363,
275,
756,
339,
347,
4107,
63,
645,
344,
63,
1457,
63,
7780,
8,
277,
12,
1066,
344,
63,
1457,
304,
267,
1613,
8,
24784,
1945,
344,
6652,
1563,
12,
291,
680,
3502,
63,
645,
344,
63,
1457,
63,
7780,
8,
645,
344,
63,
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
] |
diegojromerolopez/djanban
|
src/djanban/apps/repositories/pylinter.py
|
1
|
2199
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import json
import os
import re
from pylint import epylint as lint
from djanban.apps.repositories.cloc import Cloc
# Pylinter for directories
class PythonDirectoryAnalyzer(object):
def __init__(self, dir_path):
self.dir_path = dir_path
def run(self):
Cloc.assert_existence()
results = []
for root, subdirs, files in os.walk(self.dir_path):
for filename in files:
if PythonDirectoryAnalyzer.is_python_file(filename):
file_path = u"{0}/{1}".format(root, filename)
if not PythonDirectoryAnalyzer.file_is_empty(file_path):
# Count of lines of code
cloc = Cloc(file_path)
cloc_result = cloc.run()
pylinter = Pylinter(file_path)
pylinter_result = pylinter.run()
pylinter_result.cloc_result = cloc_result
results.append(pylinter_result)
return results
@staticmethod
def is_python_file(filename):
return filename != "__init__.py" and re.match(r"^[^\.]+\.py$", filename)
@staticmethod
def file_is_empty(file_path):
file_size = os.path.getsize(file_path)
return file_size == 0
# Runs pylint on a file
class Pylinter(object):
def __init__(self, file_path):
self.file_path = file_path
self.stdout = None
self.stderr = None
def run(self):
command_options = u"{0} --output-format=json --reports=y".format(self.file_path)
(stdout, stderr) = lint.py_run(command_options, return_std=True)
return PylinterResult(self.file_path, stdout, stderr)
# Stores pylint result
class PylinterResult(object):
def __init__(self, file_path, stdout, stderr):
self.file_path = file_path
self.stdout = stdout.getvalue()
self.stderr = stderr.getvalue()
self._init_results()
# Initialize results
def _init_results(self):
self.messages = []
if self.stdout != "":
self.messages = json.loads(self.stdout)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
504,
4287,
492,
325,
26324,
465,
24620,
199,
504,
366,
24418,
13206,
14,
5181,
14,
23949,
14,
1251,
67,
492,
445,
2102,
421,
199,
3,
1611,
25240,
367,
6602,
199,
533,
2018,
6231,
17606,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2935,
63,
515,
304,
267,
291,
14,
694,
63,
515,
275,
2935,
63,
515,
339,
347,
1255,
8,
277,
304,
267,
445,
2102,
14,
479,
63,
476,
18586,
342,
267,
2058,
275,
942,
267,
367,
1738,
12,
31396,
12,
1584,
315,
747,
14,
7757,
8,
277,
14,
694,
63,
515,
304,
288,
367,
1788,
315,
1584,
26,
355,
340,
2018,
6231,
17606,
14,
374,
63,
1548,
63,
493,
8,
1501,
304,
490,
570,
63,
515,
275,
399,
14381,
16,
16152,
17,
5469,
908,
8,
1231,
12,
1788,
9,
490,
340,
440,
2018,
6231,
17606,
14,
493,
63,
374,
63,
1667,
8,
493,
63,
515,
304,
717,
327,
14826,
402,
2385,
402,
1233,
717,
286,
2102,
275,
445,
2102,
8,
493,
63,
515,
9,
717,
286,
2102,
63,
1099,
275,
286,
2102,
14,
1065,
342,
717,
1134,
25240,
275,
1611,
25240,
8,
493,
63,
515,
9,
717,
1134,
25240,
63,
1099,
275,
1134,
25240,
14,
1065,
342,
717,
1134,
25240,
63,
1099,
14,
1251,
67,
63,
1099,
275,
286,
2102,
63,
1099,
717,
2058,
14,
740,
8,
647,
25240,
63,
1099,
9,
267,
372,
2058,
339,
768,
4639,
272,
347,
365,
63,
1548,
63,
493,
8,
1501,
304,
267,
372,
1788,
1137,
4396,
826,
4343,
647,
2,
436,
295,
14,
1431,
8,
82,
16136,
4735,
4537,
2807,
4537,
647,
11918,
1788,
9,
339,
768,
4639,
272,
347,
570,
63,
374,
63,
1667,
8,
493,
63,
515,
304,
267,
570,
63,
890,
275,
747,
14,
515,
14,
20733,
8,
493,
63,
515,
9,
267,
372,
570,
63,
890,
508,
378,
421,
199,
3,
23773,
4287,
641,
282,
570,
199,
533,
1611,
25240,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
570,
63,
515,
304,
267,
291,
14,
493,
63,
515,
275,
570,
63,
515,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
339,
347,
1255,
8,
277,
304,
267,
1414,
63,
1419,
275,
399,
14381,
16,
93,
1553,
1199,
13,
908,
29,
1001,
1553,
15629,
29,
89,
1674,
908,
8,
277,
14,
493,
63,
515,
9,
267,
334,
2703,
12,
4635,
9,
275,
24620,
14,
647,
63,
1065,
8,
1531,
63,
1419,
12,
372,
63,
1516,
29,
549,
9,
267,
372,
1611,
25240,
2889,
8,
277,
14,
493,
63,
515,
12,
3839,
12,
4635,
9,
421,
199,
3,
31299,
4287,
754,
199,
533,
1611,
25240,
2889,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
570,
63,
515,
12,
3839,
12,
4635,
304,
267,
291,
14,
493,
63,
515,
275,
570,
63,
515,
267,
291,
14,
2703,
275,
3839,
14,
7150,
342,
267,
291,
14,
3083,
275,
4635,
14,
7150,
342,
398,
291,
423,
826,
63,
2604,
342,
339,
327,
11578,
2058,
272,
347,
485,
826,
63,
2604,
8,
277,
304,
267,
291,
14,
3431,
275,
942,
267,
340,
291,
14,
2703,
1137,
10812,
288,
291,
14,
3431,
275,
2022,
14,
3640,
8,
277,
14,
2703,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
295,
199,
504,
4287,
492,
325,
26324,
465,
24620,
199,
504,
366,
24418,
13206,
14,
5181,
14,
23949,
14,
1251,
67,
492,
445,
2102,
421,
199,
3,
1611,
25240,
367,
6602,
199,
533,
2018,
6231,
17606,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2935,
63,
515,
304,
267,
291,
14,
694,
63,
515,
275,
2935,
63,
515,
339,
347,
1255,
8,
277,
304,
267,
445,
2102,
14,
479,
63,
476,
18586,
342,
267,
2058,
275,
942,
267,
367,
1738,
12,
31396,
12,
1584,
315,
747,
14,
7757,
8,
277,
14,
694,
63,
515,
304,
288,
367,
1788,
315,
1584,
26,
355,
340,
2018,
6231,
17606,
14,
374,
63,
1548,
63,
493,
8,
1501,
304,
490,
570,
63,
515,
275,
399,
14381,
16,
16152,
17,
5469,
908,
8,
1231,
12,
1788,
9,
490,
340,
440,
2018,
6231,
17606,
14,
493,
63,
374,
63,
1667,
8,
493,
63,
515,
304,
717,
327,
14826,
402,
2385,
402,
1233,
717,
286,
2102,
275,
445,
2102,
8,
493,
63,
515,
9,
717,
286,
2102,
63,
1099,
275,
286,
2102,
14,
1065,
342,
717,
1134,
25240,
275,
1611,
25240,
8,
493,
63,
515,
9,
717,
1134,
25240,
63,
1099,
275,
1134,
25240,
14,
1065,
342,
717,
1134,
25240,
63,
1099,
14,
1251,
67,
63,
1099,
275,
286,
2102,
63,
1099,
717,
2058,
14,
740,
8,
647,
25240,
63,
1099,
9,
267,
372,
2058,
339,
768,
4639,
272,
347,
365,
63,
1548,
63,
493,
8,
1501,
304,
267,
372,
1788,
1137,
4396,
826,
4343,
647,
2,
436,
295,
14,
1431,
8,
82,
16136,
4735,
4537,
2807,
4537,
647,
11918,
1788,
9,
339,
768,
4639,
272,
347,
570,
63,
374,
63,
1667,
8,
493,
63,
515,
304,
267,
570,
63,
890,
275,
747,
14,
515,
14,
20733,
8,
493,
63,
515,
9,
267,
372,
570,
63,
890,
508,
378,
421,
199,
3,
23773,
4287,
641,
282,
570,
199,
533,
1611,
25240,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
570,
63,
515,
304,
267,
291,
14,
493,
63,
515,
275,
570,
63,
515,
267,
291,
14,
2703,
275,
488,
267,
291,
14,
3083,
275,
488,
339,
347,
1255,
8,
277,
304,
267,
1414,
63,
1419,
275,
399,
14381,
16,
93,
1553,
1199,
13,
908,
29,
1001,
1553,
15629,
29,
89,
1674,
908,
8,
277,
14,
493,
63,
515,
9,
267,
334,
2703,
12,
4635,
9,
275,
24620,
14,
647,
63,
1065,
8,
1531,
63,
1419,
12,
372,
63,
1516,
29,
549,
9,
267,
372,
1611,
25240,
2889,
8,
277,
14,
493,
63,
515,
12,
3839,
12,
4635,
9,
421,
199,
3,
31299,
4287,
754,
199,
533,
1611,
25240,
2889,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
570,
63,
515,
12,
3839,
12,
4635,
304,
267,
291,
14,
493,
63,
515,
275,
570,
63,
515,
267,
291,
14,
2703,
275,
3839,
14,
7150,
342,
267,
291,
14,
3083,
275,
4635,
14,
7150,
342,
398,
291,
423,
826,
63,
2604,
342,
339,
327,
11578,
2058,
272,
347,
485,
826,
63,
2604,
8,
277,
304,
267,
291,
14,
3431,
275,
942,
267,
340,
291,
14,
2703,
1137,
10812,
288,
291,
14,
3431,
275,
2022,
14,
3640,
8,
277,
14,
2703,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Bitcoin-com/BUcash
|
qa/rpc-tests/replace-by-fee.py
|
8
|
21940
|
#!/usr/bin/env python3
# Copyright (c) 2014-2015 The Bitcoin Core developers
# Copyright (c) 2015-2017 The Bitcoin Unlimited developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test replace by fee code
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.script import *
from test_framework.mininode import *
MAX_REPLACEMENT_LIMIT = 100
def txToHex(tx):
return bytes_to_hex_str(tx.serialize())
def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
"""Create a txout with a given amount and scriptPubKey
Mines coins as needed.
confirmed - txouts created will be confirmed in the blockchain;
unconfirmed otherwise.
"""
fee = 1*COIN
while node.getbalance() < satoshi_round((amount + fee)/COIN):
node.generate(100)
#print (node.getbalance(), amount, fee)
new_addr = node.getnewaddress()
#print new_addr
txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))
tx1 = node.getrawtransaction(txid, 1)
txid = int(txid, 16)
i = None
for i, txout in enumerate(tx1['vout']):
#print i, txout['scriptPubKey']['addresses']
if txout['scriptPubKey']['addresses'] == [new_addr]:
#print i
break
assert i is not None
tx2 = CTransaction()
tx2.vin = [CTxIn(COutPoint(txid, i))]
tx2.vout = [CTxOut(amount, scriptPubKey)]
tx2.rehash()
signed_tx = node.signrawtransaction(txToHex(tx2))
txid = node.sendrawtransaction(signed_tx['hex'], True)
# If requested, ensure txouts are confirmed.
if confirmed:
mempool_size = len(node.getrawmempool())
while mempool_size > 0:
node.generate(1)
new_size = len(node.getrawmempool())
# Error out if we have something stuck in the mempool, as this
# would likely be a bug.
assert(new_size < mempool_size)
mempool_size = new_size
return COutPoint(int(txid, 16), 0)
class ReplaceByFeeTest(BitcoinTestFramework):
def setup_network(self):
self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-maxorphantx=1000", "-debug",
"-relaypriority=0", "-whitelist=127.0.0.1",
"-limitancestorcount=50",
"-limitancestorsize=101",
"-limitdescendantcount=200",
"-limitdescendantsize=101"
]))
self.is_network_split = False
def run_test(self):
make_utxo(self.nodes[0], 1*COIN)
print("Running test simple doublespend...")
self.test_simple_doublespend()
print("Running test doublespend chain...")
self.test_doublespend_chain()
print("Running test doublespend tree...")
self.test_doublespend_tree()
print("Running test replacement feeperkb...")
self.test_replacement_feeperkb()
print("Running test spends of conflicting outputs...")
self.test_spends_of_conflicting_outputs()
print("Running test new unconfirmed inputs...")
self.test_new_unconfirmed_inputs()
print("Running test too many replacements...")
self.test_too_many_replacements()
print("Running test opt-in...")
self.test_opt_in()
print("Running test prioritised transactions...")
self.test_prioritised_transactions()
print("Passed\n")
def test_simple_doublespend(self):
"""Simple doublespend"""
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
# Should fail because we haven't changed the fee
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(1*COIN, CScript([b'b']))]
tx1b_hex = txToHex(tx1b)
try:
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26) # insufficient fee
else:
assert(False)
# Extra 0.1 BTC fee
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
tx1b_hex = txToHex(tx1b)
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
mempool = self.nodes[0].getrawmempool()
assert (tx1a_txid not in mempool)
assert (tx1b_txid in mempool)
assert_equal(tx1b_hex, self.nodes[0].getrawtransaction(tx1b_txid))
def test_doublespend_chain(self):
"""Doublespend of a long chain"""
initial_nValue = 50*COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
prevout = tx0_outpoint
remaining_value = initial_nValue
chain_txids = []
while remaining_value > 10*COIN:
remaining_value -= 1*COIN
tx = CTransaction()
tx.vin = [CTxIn(prevout, nSequence=0)]
tx.vout = [CTxOut(remaining_value, CScript([1]))]
tx_hex = txToHex(tx)
txid = self.nodes[0].sendrawtransaction(tx_hex, True)
chain_txids.append(txid)
prevout = COutPoint(int(txid, 16), 0)
# Whether the double-spend is allowed is evaluated by including all
# child fees - 40 BTC - so this attempt is rejected.
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - 30*COIN, CScript([1]))]
dbl_tx_hex = txToHex(dbl_tx)
try:
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26) # insufficient fee
else:
assert(False) # transaction mistakenly accepted!
# Accepted with sufficient fee
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(1*COIN, CScript([1]))]
dbl_tx_hex = txToHex(dbl_tx)
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
mempool = self.nodes[0].getrawmempool()
for doublespent_txid in chain_txids:
assert(doublespent_txid not in mempool)
def test_doublespend_tree(self):
"""Doublespend of a big tree of transactions"""
initial_nValue = 50*COIN
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _total_txs=None):
if _total_txs is None:
_total_txs = [0]
if _total_txs[0] >= max_txs:
return
txout_value = (initial_value - fee) // tree_width
if txout_value < fee:
return
vout = [CTxOut(txout_value, CScript([i+1]))
for i in range(tree_width)]
tx = CTransaction()
tx.vin = [CTxIn(prevout, nSequence=0)]
tx.vout = vout
tx_hex = txToHex(tx)
assert(len(tx.serialize()) < 100000)
txid = self.nodes[0].sendrawtransaction(tx_hex, True)
yield tx
_total_txs[0] += 1
txid = int(txid, 16)
for i, txout in enumerate(tx.vout):
for x in branch(COutPoint(txid, i), txout_value,
max_txs,
tree_width=tree_width, fee=fee,
_total_txs=_total_txs):
yield x
fee = int(0.0001*COIN)
n = MAX_REPLACEMENT_LIMIT
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
assert_equal(len(tree_txs), n)
# Attempt double-spend, will fail because too little fee paid
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - fee*n, CScript([1]))]
dbl_tx_hex = txToHex(dbl_tx)
try:
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26) # insufficient fee
else:
assert(False)
# 1 BTC fee is enough
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - fee*n - 1*COIN, CScript([1]))]
dbl_tx_hex = txToHex(dbl_tx)
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
mempool = self.nodes[0].getrawmempool()
for tx in tree_txs:
tx.rehash()
assert (tx.hash not in mempool)
# Try again, but with more total transactions than the "max txs
# double-spent at once" anti-DoS limit.
for n in (MAX_REPLACEMENT_LIMIT+1, MAX_REPLACEMENT_LIMIT*2):
fee = int(0.0001*COIN)
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
assert_equal(len(tree_txs), n)
dbl_tx = CTransaction()
dbl_tx.vin = [CTxIn(tx0_outpoint, nSequence=0)]
dbl_tx.vout = [CTxOut(initial_nValue - 2*fee*n, CScript([1]))]
dbl_tx_hex = txToHex(dbl_tx)
try:
self.nodes[0].sendrawtransaction(dbl_tx_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
assert_equal("too many potential replacements" in exp.error['message'], True)
else:
assert(False)
for tx in tree_txs:
tx.rehash()
self.nodes[0].getrawtransaction(tx.hash)
def test_replacement_feeperkb(self):
"""Replacement requires fee-per-KB to be higher"""
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
# Higher fee, but the fee per KB is much lower, so the replacement is
# rejected.
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))]
tx1b_hex = txToHex(tx1b)
try:
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26) # insufficient fee
else:
assert(False)
def test_spends_of_conflicting_outputs(self):
"""Replacements that spend conflicting tx outputs are rejected"""
utxo1 = make_utxo(self.nodes[0], int(1.2*COIN))
utxo2 = make_utxo(self.nodes[0], 3*COIN)
tx1a = CTransaction()
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
tx1a.vout = [CTxOut(int(1.1*COIN), CScript([b'a']))]
tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
tx1a_txid = int(tx1a_txid, 16)
# Direct spend an output of the transaction we're replacing.
tx2 = CTransaction()
tx2.vin = [CTxIn(utxo1, nSequence=0), CTxIn(utxo2, nSequence=0)]
tx2.vin.append(CTxIn(COutPoint(tx1a_txid, 0), nSequence=0))
tx2.vout = tx1a.vout
tx2_hex = txToHex(tx2)
try:
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
# Spend tx1a's output to test the indirect case.
tx1b = CTransaction()
tx1b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
tx1b.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1b_hex = txToHex(tx1b)
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
tx1b_txid = int(tx1b_txid, 16)
tx2 = CTransaction()
tx2.vin = [CTxIn(utxo1, nSequence=0), CTxIn(utxo2, nSequence=0),
CTxIn(COutPoint(tx1b_txid, 0))]
tx2.vout = tx1a.vout
tx2_hex = txToHex(tx2)
try:
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
def test_new_unconfirmed_inputs(self):
"""Replacements that add new unconfirmed inputs are rejected"""
confirmed_utxo = make_utxo(self.nodes[0], int(1.1*COIN))
unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1*COIN), False)
tx1 = CTransaction()
tx1.vin = [CTxIn(confirmed_utxo)]
tx1.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1_hex = txToHex(tx1)
tx1_txid = self.nodes[0].sendrawtransaction(tx1_hex, True)
tx2 = CTransaction()
tx2.vin = [CTxIn(confirmed_utxo), CTxIn(unconfirmed_utxo)]
tx2.vout = tx1.vout
tx2_hex = txToHex(tx2)
try:
tx2_txid = self.nodes[0].sendrawtransaction(tx2_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
def test_too_many_replacements(self):
"""Replacements that evict too many transactions are rejected"""
# Try directly replacing more than MAX_REPLACEMENT_LIMIT
# transactions
# Start by creating a single transaction with many outputs
initial_nValue = 10*COIN
utxo = make_utxo(self.nodes[0], initial_nValue)
fee = int(0.0001*COIN)
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
actual_fee = initial_nValue - split_value*(MAX_REPLACEMENT_LIMIT+1)
outputs = []
for i in range(MAX_REPLACEMENT_LIMIT+1):
outputs.append(CTxOut(split_value, CScript([1])))
splitting_tx = CTransaction()
splitting_tx.vin = [CTxIn(utxo, nSequence=0)]
splitting_tx.vout = outputs
splitting_tx_hex = txToHex(splitting_tx)
txid = self.nodes[0].sendrawtransaction(splitting_tx_hex, True)
txid = int(txid, 16)
# Now spend each of those outputs individually
for i in range(MAX_REPLACEMENT_LIMIT+1):
tx_i = CTransaction()
tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)]
tx_i.vout = [CTxOut(split_value-fee, CScript([b'a']))]
tx_i_hex = txToHex(tx_i)
self.nodes[0].sendrawtransaction(tx_i_hex, True)
# Now create doublespend of the whole lot; should fail.
# Need a big enough fee to cover all spending transactions and have
# a higher fee rate
double_spend_value = (split_value-100*fee)*(MAX_REPLACEMENT_LIMIT+1)
inputs = []
for i in range(MAX_REPLACEMENT_LIMIT+1):
inputs.append(CTxIn(COutPoint(txid, i), nSequence=0))
double_tx = CTransaction()
double_tx.vin = inputs
double_tx.vout = [CTxOut(double_spend_value, CScript([b'a']))]
double_tx_hex = txToHex(double_tx)
try:
self.nodes[0].sendrawtransaction(double_tx_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
assert_equal("too many potential replacements" in exp.error['message'], True)
else:
assert(False)
# If we remove an input, it should pass
double_tx = CTransaction()
double_tx.vin = inputs[0:-1]
double_tx.vout = [CTxOut(double_spend_value, CScript([b'a']))]
double_tx_hex = txToHex(double_tx)
self.nodes[0].sendrawtransaction(double_tx_hex, True)
def test_opt_in(self):
""" Replacing should only work if orig tx opted in """
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
# Create a non-opting in transaction
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0xffffffff)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
# Shouldn't be able to double-spend
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
tx1b_hex = txToHex(tx1b)
try:
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
print(tx1b_txid)
assert(False)
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
# Create a different non-opting in transaction
tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0xfffffffe)]
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx2a_hex = txToHex(tx2a)
tx2a_txid = self.nodes[0].sendrawtransaction(tx2a_hex, True)
# Still shouldn't be able to double-spend
tx2b = CTransaction()
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2b.vout = [CTxOut(int(0.9*COIN), CScript([b'b']))]
tx2b_hex = txToHex(tx2b)
try:
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
# Now create a new transaction that spends from tx1a and tx2a
# opt-in on one of the inputs
# Transaction should be replaceable on either input
tx1a_txid = int(tx1a_txid, 16)
tx2a_txid = int(tx2a_txid, 16)
tx3a = CTransaction()
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
tx3a.vout = [CTxOut(int(0.9*COIN), CScript([b'c'])), CTxOut(int(0.9*COIN), CScript([b'd']))]
tx3a_hex = txToHex(tx3a)
self.nodes[0].sendrawtransaction(tx3a_hex, True)
tx3b = CTransaction()
tx3b.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0)]
tx3b.vout = [CTxOut(int(0.5*COIN), CScript([b'e']))]
tx3b_hex = txToHex(tx3b)
tx3c = CTransaction()
tx3c.vin = [CTxIn(COutPoint(tx2a_txid, 0), nSequence=0)]
tx3c.vout = [CTxOut(int(0.5*COIN), CScript([b'f']))]
tx3c_hex = txToHex(tx3c)
self.nodes[0].sendrawtransaction(tx3b_hex, True)
# If tx3b was accepted, tx3c won't look like a replacement,
# but make sure it is accepted anyway
self.nodes[0].sendrawtransaction(tx3c_hex, True)
def test_prioritised_transactions(self):
# Ensure that fee deltas used via prioritisetransaction are
# correctly used by replacement logic
# 1. Check that feeperkb uses modified fees
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
tx1a = CTransaction()
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx1a_hex = txToHex(tx1a)
tx1a_txid = self.nodes[0].sendrawtransaction(tx1a_hex, True)
# Higher fee, but the actual fee per KB is much lower.
tx1b = CTransaction()
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*740000]))]
tx1b_hex = txToHex(tx1b)
# Verify tx1b cannot replace tx1a.
try:
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
# Use prioritisetransaction to set tx1a's fee to 0.
self.nodes[0].prioritisetransaction(tx1a_txid, 0, int(-0.1*COIN))
# Now tx1b should be able to replace tx1a
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, True)
assert(tx1b_txid in self.nodes[0].getrawmempool())
# 2. Check that absolute fee checks use modified fee.
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
tx2a = CTransaction()
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2a.vout = [CTxOut(1*COIN, CScript([b'a']))]
tx2a_hex = txToHex(tx2a)
tx2a_txid = self.nodes[0].sendrawtransaction(tx2a_hex, True)
# Lower fee, but we'll prioritise it
tx2b = CTransaction()
tx2b.vin = [CTxIn(tx1_outpoint, nSequence=0)]
tx2b.vout = [CTxOut(int(1.01*COIN), CScript([b'a']))]
tx2b.rehash()
tx2b_hex = txToHex(tx2b)
# Verify tx2b cannot replace tx2a.
try:
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, True)
except JSONRPCException as exp:
assert_equal(exp.error['code'], -26)
else:
assert(False)
# Now prioritise tx2b to have a higher modified fee
self.nodes[0].prioritisetransaction(tx2b.hash, 0, int(0.1*COIN))
# tx2b should now be accepted
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, True)
assert(tx2b_txid in self.nodes[0].getrawmempool())
if __name__ == '__main__':
ReplaceByFeeTest().main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
7806,
710,
21158,
11672,
19782,
199,
3,
1898,
334,
67,
9,
6900,
13,
10680,
710,
21158,
1910,
14136,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
199,
3,
199,
3,
1379,
3350,
701,
14751,
1233,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
199,
504,
511,
63,
4857,
14,
1579,
492,
627,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
627,
199,
199,
4283,
63,
30583,
63,
13387,
275,
2948,
199,
199,
318,
4773,
1378,
10373,
8,
2347,
304,
272,
372,
2783,
63,
475,
63,
4097,
63,
495,
8,
2347,
14,
3549,
1012,
199,
199,
318,
1852,
63,
30275,
8,
932,
12,
5982,
12,
22763,
29,
549,
12,
2884,
29632,
29,
3298,
1669,
779,
17,
18710,
272,
408,
2499,
282,
4773,
548,
543,
282,
1627,
5982,
436,
2884,
29632,
339,
603,
3746,
512,
3617,
465,
4346,
14,
339,
22763,
446,
4773,
16816,
2737,
911,
506,
22763,
315,
314,
1853,
4429,
27,
355,
625,
16391,
4257,
14,
272,
408,
272,
14751,
275,
413,
10,
1439,
568,
272,
1830,
1031,
14,
29213,
342,
665,
308,
11318,
19377,
63,
2363,
1332,
4606,
435,
14751,
2447,
1439,
568,
304,
267,
1031,
14,
4208,
8,
1960,
9,
267,
327,
1361,
334,
932,
14,
29213,
1062,
5982,
12,
14751,
9,
339,
892,
63,
2697,
275,
1031,
14,
21102,
342,
272,
327,
1361,
892,
63,
2697,
272,
22083,
275,
1031,
14,
23267,
1562,
8,
1222,
63,
2697,
12,
308,
11318,
19377,
63,
2363,
1332,
4606,
11,
11195,
2447,
1439,
568,
430,
272,
4773,
17,
275,
1031,
14,
362,
16900,
8,
14113,
12,
413,
9,
272,
22083,
275,
1109,
8,
14113,
12,
3193,
9,
272,
284,
275,
488,
339,
367,
284,
12,
4773,
548,
315,
3874,
8,
2347,
17,
459,
17853,
9090,
267,
327,
1361,
284,
12,
4773,
548,
459,
1579,
29632,
2545,
7423,
418,
267,
340,
4773,
548,
459,
1579,
29632,
2545,
7423,
418,
508,
359,
1222,
63,
2697,
2189,
288,
327,
1361,
284,
288,
2059,
272,
702,
284,
365,
440,
488,
339,
4773,
18,
275,
445,
10161,
342,
272,
4773,
18,
14,
11908,
275,
359,
27831,
607,
8,
1439,
337,
3428,
8,
14113,
12,
284,
10524,
272,
4773,
18,
14,
17853,
275,
359,
27831,
2204,
8,
4606,
12,
2884,
29632,
1874,
272,
4773,
18,
14,
264,
2227,
342,
339,
10514,
63,
2347,
275,
1031,
14,
1037,
16900,
8,
2347,
1378,
10373,
8,
2347,
18,
430,
339,
22083,
275,
1031,
14,
2254,
16900,
8,
1737,
63,
2347,
459,
4097,
995,
715,
9,
339,
327,
982,
5839,
12,
4868,
4773,
16816,
787,
22763,
14,
272,
340,
22763,
26,
267,
30330,
63,
890,
275,
822,
8,
932,
14,
362,
1773,
25341,
1012,
267,
1830,
30330,
63,
890,
690,
378,
26,
288,
1031,
14,
4208,
8,
17,
9,
288,
892,
63,
890,
275,
822,
8,
932,
14,
362,
1773,
25341,
1012,
288,
327,
4520,
734,
340,
781,
1172,
6020,
410,
10112,
315,
314,
30330,
12,
465,
642,
288,
327,
3955,
12060,
506,
282,
6519,
14,
288,
702,
8,
1222,
63,
890,
665,
30330,
63,
890,
9,
288,
30330,
63,
890,
275,
892,
63,
890,
339,
372,
445,
2204,
3428,
8,
442,
8,
14113,
12,
3193,
395,
378,
9,
199,
199,
533,
14402,
2175,
28042,
774,
8,
4734,
9061,
26203,
304,
339,
347,
3272,
63,
1200,
8,
277,
304,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
2415,
14,
740,
8,
928,
63,
932,
8,
16,
12,
291,
14,
1419,
14,
8616,
12,
16984,
988,
6847,
867,
88,
29,
5279,
401,
3905,
1757,
401,
16854,
3905,
21855,
6693,
29,
16,
401,
3905,
14189,
29,
4195,
14,
16,
14,
16,
14,
17,
401,
16854,
3905,
3097,
20745,
835,
29,
1400,
401,
16854,
3905,
3097,
20745,
890,
29,
4893,
401,
16854,
3905,
3097,
31759,
835,
29,
1840,
401,
16854,
3905,
3097,
31759,
890,
29,
4893,
2,
16854,
22979,
267,
291,
14,
374,
63,
1200,
63,
1294,
275,
756,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
1852,
63,
30275,
8,
277,
14,
2415,
59,
16,
467,
413,
10,
1439,
568,
9,
398,
870,
480,
9602,
511,
3486,
4270,
31340,
12594,
267,
291,
14,
396,
63,
4129,
63,
3157,
31340,
342,
398,
870,
480,
9602,
511,
4270,
31340,
6036,
12594,
267,
291,
14,
396,
63,
3157,
31340,
63,
4429,
342,
398,
870,
480,
9602,
511,
4270,
31340,
3123,
12594,
267,
291,
14,
396,
63,
3157,
31340,
63,
2350,
342,
398,
870,
480,
9602,
511,
8343,
14751,
529,
7862,
12594,
267,
291,
14,
396,
63,
15895,
63,
11195,
529,
7862,
342,
398,
870,
480,
9602,
511,
2249,
3198,
402,
28204,
4704,
12594,
267,
291,
14,
396,
63,
681,
3198,
63,
1618,
63,
15207,
316,
63,
4467,
342,
398,
870,
480,
9602,
511,
892,
625,
16391,
4153,
12594,
267,
291,
14,
396,
63,
1222,
63,
324,
16391,
63,
3711,
342,
398,
870,
480,
9602,
511,
4634,
5002,
22372,
12594,
267,
291,
14,
396,
63,
7354,
63,
3479,
63,
1814,
1470,
342,
398,
870,
480,
9602,
511,
2450,
13,
262,
12594,
267,
291,
14,
396,
63,
2992,
63,
262,
342,
398,
870,
480,
9602,
511,
6791,
5277,
939,
15809,
12594,
267,
291,
14,
396,
63,
13775,
5277,
939,
63,
13754,
342,
398,
870,
480,
48,
2744,
60,
78,
531,
339,
347,
511,
63,
4129,
63,
3157,
31340,
8,
277,
304,
267,
408,
3184,
4270,
31340,
624,
267,
4773,
16,
63,
548,
1403,
275,
1852,
63,
30275,
8,
277,
14,
2415,
59,
16,
467,
1109,
8,
17,
14,
17,
10,
1439,
568,
430,
398,
4773,
17,
65,
275,
445,
10161,
342,
267,
4773,
17,
65,
14,
11908,
275,
359,
27831,
607,
8,
2347,
16,
63,
548,
1403,
12,
302,
5826,
29,
16,
1874,
267,
4773,
17,
65,
14,
17853,
275,
359,
27831,
2204,
8,
17,
10,
1439,
568,
12,
24682,
779,
66,
7,
65,
5156,
61,
267,
4773,
17,
65,
63,
4097,
275,
4773,
1378,
10373,
8,
2347,
17,
65
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1898,
334,
67,
9,
6927,
13,
7806,
710,
21158,
11672,
19782,
199,
3,
1898,
334,
67,
9,
6900,
13,
10680,
710,
21158,
1910,
14136,
19782,
199,
3,
17484,
1334,
314,
10697,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
199,
3,
199,
3,
1379,
3350,
701,
14751,
1233,
199,
3,
199,
199,
504,
511,
63,
4857,
14,
396,
63,
4857,
492,
21158,
26203,
199,
504,
511,
63,
4857,
14,
1974,
492,
627,
199,
504,
511,
63,
4857,
14,
1579,
492,
627,
199,
504,
511,
63,
4857,
14,
827,
15993,
492,
627,
199,
199,
4283,
63,
30583,
63,
13387,
275,
2948,
199,
199,
318,
4773,
1378,
10373,
8,
2347,
304,
272,
372,
2783,
63,
475,
63,
4097,
63,
495,
8,
2347,
14,
3549,
1012,
199,
199,
318,
1852,
63,
30275,
8,
932,
12,
5982,
12,
22763,
29,
549,
12,
2884,
29632,
29,
3298,
1669,
779,
17,
18710,
272,
408,
2499,
282,
4773,
548,
543,
282,
1627,
5982,
436,
2884,
29632,
339,
603,
3746,
512,
3617,
465,
4346,
14,
339,
22763,
446,
4773,
16816,
2737,
911,
506,
22763,
315,
314,
1853,
4429,
27,
355,
625,
16391,
4257,
14,
272,
408,
272,
14751,
275,
413,
10,
1439,
568,
272,
1830,
1031,
14,
29213,
342,
665,
308,
11318,
19377,
63,
2363,
1332,
4606,
435,
14751,
2447,
1439,
568,
304,
267,
1031,
14,
4208,
8,
1960,
9,
267,
327,
1361,
334,
932,
14,
29213,
1062,
5982,
12,
14751,
9,
339,
892,
63,
2697,
275,
1031,
14,
21102,
342,
272,
327,
1361,
892,
63,
2697,
272,
22083,
275,
1031,
14,
23267,
1562,
8,
1222,
63,
2697,
12,
308,
11318,
19377,
63,
2363,
1332,
4606,
11,
11195,
2447,
1439,
568,
430,
272,
4773,
17,
275,
1031,
14,
362,
16900,
8,
14113,
12,
413,
9,
272,
22083,
275,
1109,
8,
14113,
12,
3193,
9,
272,
284,
275,
488,
339,
367,
284,
12,
4773,
548,
315,
3874,
8,
2347,
17,
459,
17853,
9090,
267,
327,
1361,
284,
12,
4773,
548,
459,
1579,
29632,
2545,
7423,
418,
267,
340,
4773,
548,
459,
1579,
29632,
2545,
7423,
418,
508,
359,
1222,
63,
2697,
2189,
288,
327,
1361,
284,
288,
2059,
272,
702,
284,
365,
440,
488,
339,
4773,
18,
275,
445,
10161,
342,
272,
4773,
18,
14,
11908,
275,
359,
27831,
607,
8,
1439,
337,
3428,
8,
14113,
12,
284,
10524,
272,
4773,
18,
14,
17853,
275,
359,
27831,
2204,
8,
4606,
12,
2884,
29632,
1874,
272,
4773,
18,
14,
264,
2227,
342,
339,
10514,
63,
2347,
275,
1031,
14,
1037,
16900,
8,
2347,
1378,
10373,
8,
2347,
18,
430,
339,
22083,
275,
1031,
14,
2254,
16900,
8,
1737,
63,
2347,
459,
4097,
995,
715,
9,
339,
327,
982,
5839,
12,
4868,
4773,
16816,
787,
22763,
14,
272,
340,
22763,
26,
267,
30330,
63,
890,
275,
822,
8,
932,
14,
362,
1773,
25341,
1012,
267,
1830,
30330,
63,
890,
690,
378,
26,
288,
1031,
14,
4208,
8,
17,
9,
288,
892,
63,
890,
275,
822,
8,
932,
14,
362,
1773,
25341,
1012,
288,
327,
4520,
734,
340,
781,
1172,
6020,
410,
10112,
315,
314,
30330,
12,
465,
642,
288,
327,
3955,
12060,
506,
282,
6519,
14,
288,
702,
8,
1222,
63,
890,
665,
30330,
63,
890,
9,
288,
30330,
63,
890,
275,
892,
63,
890,
339,
372,
445,
2204,
3428,
8,
442,
8,
14113,
12,
3193,
395,
378,
9,
199,
199,
533,
14402,
2175,
28042,
774,
8,
4734,
9061,
26203,
304,
339,
347,
3272,
63,
1200,
8,
277,
304,
267,
291,
14,
2415,
275,
942,
267,
291,
14,
2415,
14,
740,
8,
928,
63,
932,
8,
16,
12,
291,
14,
1419,
14,
8616,
12,
16984,
988,
6847,
867,
88,
29,
5279,
401,
3905,
1757,
401,
16854,
3905,
21855,
6693,
29,
16,
401,
3905,
14189,
29,
4195,
14,
16,
14,
16,
14,
17,
401,
16854,
3905,
3097,
20745,
835,
29,
1400,
401,
16854,
3905,
3097,
20745,
890,
29,
4893,
401,
16854,
3905,
3097,
31759,
835,
29,
1840,
401,
16854,
3905,
3097,
31759,
890,
29,
4893,
2,
16854,
22979,
267,
291,
14,
374,
63,
1200,
63,
1294,
275,
756,
339,
347,
1255,
63,
396,
8,
277,
304,
267,
1852,
63,
30275,
8,
277,
14,
2415,
59,
16,
467,
413,
10,
1439,
568,
9,
398,
870,
480,
9602,
511,
3486,
4270,
31340,
12594,
267,
291,
14,
396,
63,
4129,
63,
3157,
31340,
342,
398,
870,
480,
9602,
511,
4270,
31340,
6036,
12594,
267,
291,
14,
396,
63,
3157,
31340,
63,
4429,
342,
398,
870,
480,
9602,
511,
4270,
31340,
3123,
12594,
267,
291,
14,
396,
63,
3157,
31340,
63,
2350,
342,
398,
870,
480,
9602,
511,
8343,
14751,
529,
7862,
12594,
267,
291,
14,
396,
63,
15895,
63,
11195,
529,
7862,
342,
398,
870,
480,
9602,
511,
2249,
3198,
402,
28204,
4704,
12594,
267,
291,
14,
396,
63,
681,
3198,
63,
1618,
63,
15207,
316,
63,
4467,
342,
398,
870,
480,
9602,
511,
892,
625,
16391,
4153,
12594,
267,
291,
14,
396,
63,
1222,
63,
324,
16391,
63,
3711,
342,
398,
870,
480,
9602,
511,
4634,
5002,
22372,
12594,
267,
291,
14,
396,
63,
7354,
63,
3479,
63,
1814,
1470,
342,
398,
870,
480,
9602,
511,
2450,
13,
262,
12594,
267,
291,
14,
396,
63,
2992,
63,
262,
342,
398,
870,
480,
9602,
511,
6791,
5277,
939,
15809,
12594,
267,
291,
14,
396,
63,
13775,
5277,
939,
63,
13754,
342,
398,
870,
480,
48,
2744,
60,
78,
531,
339,
347,
511,
63,
4129,
63,
3157,
31340,
8,
277,
304,
267,
408,
3184,
4270,
31340,
624,
267,
4773,
16,
63,
548,
1403,
275,
1852,
63,
30275,
8,
277,
14,
2415,
59,
16,
467,
1109,
8,
17,
14,
17,
10,
1439,
568,
430,
398,
4773,
17,
65,
275,
445,
10161,
342,
267,
4773,
17,
65,
14,
11908,
275,
359,
27831,
607,
8,
2347,
16,
63,
548,
1403,
12,
302,
5826,
29,
16,
1874,
267,
4773,
17,
65,
14,
17853,
275,
359,
27831,
2204,
8,
17,
10,
1439,
568,
12,
24682,
779,
66,
7,
65,
5156,
61,
267,
4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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
wenhuizhang/neutron
|
neutron/plugins/nuage/plugin.py
|
48
|
1051
|
# Copyright 2014 Alcatel-Lucent USA Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nuage_neutron.plugins.nuage import plugin
class NuagePlugin(plugin.NuagePlugin):
vendor_extensions = plugin.NuagePlugin.vendor_extensions
supported_extension_aliases = ["router", "binding", "external-net",
"quotas", "provider", "extraroute",
"security-group"] + vendor_extensions
def __init__(self):
super(NuagePlugin, self).__init__()
|
apache-2.0
|
[
3,
1898,
6927,
4580,
1411,
76,
13,
44,
947,
484,
8217,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
302,
1718,
63,
10271,
14,
5265,
14,
78,
1718,
492,
3589,
421,
199,
533,
653,
1718,
5061,
8,
2718,
14,
46,
1718,
5061,
304,
339,
20868,
63,
5359,
275,
3589,
14,
46,
1718,
5061,
14,
9884,
63,
5359,
272,
3748,
63,
3435,
63,
8602,
275,
2097,
4995,
401,
298,
9140,
401,
298,
5159,
13,
846,
401,
3521,
298,
17056,
401,
298,
3780,
401,
298,
832,
26378,
810,
266,
401,
3521,
298,
4416,
13,
923,
937,
435,
20868,
63,
5359,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
46,
1718,
5061,
12,
291,
2843,
826,
4533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6927,
4580,
1411,
76,
13,
44,
947,
484,
8217,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
302,
1718,
63,
10271,
14,
5265,
14,
78,
1718,
492,
3589,
421,
199,
533,
653,
1718,
5061,
8,
2718,
14,
46,
1718,
5061,
304,
339,
20868,
63,
5359,
275,
3589,
14,
46,
1718,
5061,
14,
9884,
63,
5359,
272,
3748,
63,
3435,
63,
8602,
275,
2097,
4995,
401,
298,
9140,
401,
298,
5159,
13,
846,
401,
3521,
298,
17056,
401,
298,
3780,
401,
298,
832,
26378,
810,
266,
401,
3521,
298,
4416,
13,
923,
937,
435,
20868,
63,
5359,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
46,
1718,
5061,
12,
291,
2843,
826,
4533,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
eul721/The-Perfect-Pokemon-Team-Balancer
|
libs/env/Lib/site-packages/pip/_vendor/requests/packages/charade/sbcsgroupprober.py
|
2936
|
3291
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .charsetgroupprober import CharSetGroupProber
from .sbcharsetprober import SingleByteCharSetProber
from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel,
Latin5CyrillicModel, MacCyrillicModel,
Ibm866Model, Ibm855Model)
from .langgreekmodel import Latin7GreekModel, Win1253GreekModel
from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel
from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel
from .langthaimodel import TIS620ThaiModel
from .langhebrewmodel import Win1255HebrewModel
from .hebrewprober import HebrewProber
class SBCSGroupProber(CharSetGroupProber):
def __init__(self):
CharSetGroupProber.__init__(self)
self._mProbers = [
SingleByteCharSetProber(Win1251CyrillicModel),
SingleByteCharSetProber(Koi8rModel),
SingleByteCharSetProber(Latin5CyrillicModel),
SingleByteCharSetProber(MacCyrillicModel),
SingleByteCharSetProber(Ibm866Model),
SingleByteCharSetProber(Ibm855Model),
SingleByteCharSetProber(Latin7GreekModel),
SingleByteCharSetProber(Win1253GreekModel),
SingleByteCharSetProber(Latin5BulgarianModel),
SingleByteCharSetProber(Win1251BulgarianModel),
SingleByteCharSetProber(Latin2HungarianModel),
SingleByteCharSetProber(Win1250HungarianModel),
SingleByteCharSetProber(TIS620ThaiModel),
]
hebrewProber = HebrewProber()
logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel,
False, hebrewProber)
visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True,
hebrewProber)
hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber)
self._mProbers.extend([hebrewProber, logicalHebrewProber,
visualHebrewProber])
self.reset()
|
gpl-2.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
9264,
6043,
19903,
492,
13050,
21312,
199,
504,
1275,
4159,
17405,
1238,
492,
334,
8886,
21381,
9156,
11909,
1685,
12,
1804,
16142,
24,
82,
1685,
12,
1816,
23864,
21,
9156,
11909,
1685,
12,
10444,
9156,
11909,
1685,
12,
1816,
473,
12648,
13465,
1685,
12,
473,
12648,
12593,
1685,
9,
199,
504,
1275,
4159,
32007,
1238,
492,
23864,
23,
29480,
1685,
12,
13036,
28452,
29480,
1685,
199,
504,
1275,
4159,
25792,
71,
15289,
1238,
492,
23864,
21,
34,
27092,
15289,
1685,
12,
13036,
21381,
34,
27092,
15289,
1685,
199,
504,
1275,
4159,
72,
25364,
1238,
492,
23864,
18,
40,
25364,
1685,
12,
13036,
26572,
40,
25364,
1685,
199,
504,
1275,
4159,
24825,
1238,
492,
377,
1311,
22085,
52,
17945,
1685,
199,
504,
1275,
4159,
14557,
1238,
492,
13036,
20197,
1966,
15850,
1685,
199,
504,
1275,
14557,
19903,
492,
19771,
8029,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
13050,
21312,
8,
8886,
21381,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
43,
16142,
24,
82,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
3399,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
13465,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
12593,
1685,
395,
288,
13050,
21312,
8,
27317,
23,
29480,
1685,
395,
288,
13050,
21312,
8,
8886,
28452,
29480,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
8886,
21381,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
267,
1622,
267,
946,
15850,
8029,
275,
19771,
8029,
342,
267,
11461,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
10028,
756,
12,
946,
15850,
8029,
9,
267,
13104,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
9349,
946,
15850,
8029,
9,
267,
946,
15850,
8029,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
1966,
15850,
8029,
12,
13104,
1966,
15850,
8029,
9,
267,
291,
423,
77,
8029,
83,
14,
2880,
779,
14557,
8029,
12,
11461,
1966,
15850,
8029,
12,
3044,
13104,
1966,
15850,
8029,
566,
398,
291,
14,
3958,
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
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
9264,
6043,
19903,
492,
13050,
21312,
199,
504,
1275,
4159,
17405,
1238,
492,
334,
8886,
21381,
9156,
11909,
1685,
12,
1804,
16142,
24,
82,
1685,
12,
1816,
23864,
21,
9156,
11909,
1685,
12,
10444,
9156,
11909,
1685,
12,
1816,
473,
12648,
13465,
1685,
12,
473,
12648,
12593,
1685,
9,
199,
504,
1275,
4159,
32007,
1238,
492,
23864,
23,
29480,
1685,
12,
13036,
28452,
29480,
1685,
199,
504,
1275,
4159,
25792,
71,
15289,
1238,
492,
23864,
21,
34,
27092,
15289,
1685,
12,
13036,
21381,
34,
27092,
15289,
1685,
199,
504,
1275,
4159,
72,
25364,
1238,
492,
23864,
18,
40,
25364,
1685,
12,
13036,
26572,
40,
25364,
1685,
199,
504,
1275,
4159,
24825,
1238,
492,
377,
1311,
22085,
52,
17945,
1685,
199,
504,
1275,
4159,
14557,
1238,
492,
13036,
20197,
1966,
15850,
1685,
199,
504,
1275,
14557,
19903,
492,
19771,
8029,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
13050,
21312,
8,
8886,
21381,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
43,
16142,
24,
82,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
3399,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
13465,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
12593,
1685,
395,
288,
13050,
21312,
8,
27317,
23,
29480,
1685,
395,
288,
13050,
21312,
8,
8886,
28452,
29480,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
8886,
21381,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
267,
1622,
267,
946,
15850,
8029,
275,
19771,
8029,
342,
267,
11461,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
10028,
756,
12,
946,
15850,
8029,
9,
267,
13104,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
9349,
946,
15850,
8029,
9,
267,
946,
15850,
8029,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
1966,
15850,
8029,
12,
13104,
1966,
15850,
8029,
9,
267,
291,
423,
77,
8029,
83,
14,
2880,
779,
14557,
8029,
12,
11461,
1966,
15850,
8029,
12,
3044,
13104,
1966,
15850,
8029,
566,
398,
291,
14,
3958,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
liangazhou/django-rdp
|
packages/eclipse/plugins/org.python.pydev.jython_4.4.0.201510052309/Lib/encodings/gb2312.py
|
816
|
1027
|
#
# gb2312.py: Python Unicode Codec for GB2312
#
# Written by Hye-Shik Chang <perky@FreeBSD.org>
#
import _codecs_cn, codecs
import _multibytecodec as mbc
codec = _codecs_cn.getcodec('gb2312')
class Codec(codecs.Codec):
encode = codec.encode
decode = codec.decode
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
codecs.IncrementalEncoder):
codec = codec
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
codecs.IncrementalDecoder):
codec = codec
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
codec = codec
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
codec = codec
def getregentry():
return codecs.CodecInfo(
name='gb2312',
encode=Codec().encode,
decode=Codec().decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
apache-2.0
|
[
3,
199,
3,
25411,
16909,
14,
647,
26,
2018,
6140,
13732,
367,
18553,
16909,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
6413,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
6413,
14,
362,
9276,
360,
4908,
16909,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4908,
16909,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
25411,
16909,
14,
647,
26,
2018,
6140,
13732,
367,
18553,
16909,
199,
3,
199,
3,
27694,
701,
869,
8048,
13,
2662,
3258,
2799,
621,
665,
529,
10562,
32,
10146,
15400,
14,
1308,
30,
199,
3,
199,
199,
646,
485,
8933,
63,
6413,
12,
6010,
199,
646,
485,
3029,
4414,
9276,
465,
333,
3776,
199,
199,
9276,
275,
485,
8933,
63,
6413,
14,
362,
9276,
360,
4908,
16909,
358,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
272,
3752,
275,
9076,
14,
2143,
272,
4849,
275,
9076,
14,
2708,
199,
199,
533,
24350,
8,
887,
67,
14,
3947,
4414,
17016,
12,
586,
6010,
14,
17016,
304,
272,
9076,
275,
9076,
199,
199,
533,
24385,
8,
887,
67,
14,
3947,
4414,
16703,
12,
586,
6010,
14,
16703,
304,
272,
9076,
275,
9076,
199,
199,
533,
22970,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16132,
12,
6010,
14,
16132,
304,
272,
9076,
275,
9076,
199,
199,
533,
24163,
8,
8818,
12,
333,
3776,
14,
3947,
4414,
16551,
12,
6010,
14,
16551,
304,
272,
9076,
275,
9076,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
4908,
16909,
297,
267,
3752,
29,
8818,
1252,
2143,
12,
267,
4849,
29,
8818,
1252,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26101,
29,
16132,
12,
267,
26112,
29,
16551,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
jaharkes/home-assistant
|
homeassistant/components/sensor/command_line.py
|
5
|
3568
|
"""
Allows to configure custom shell commands to turn a value for a sensor.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.command_line/
"""
import logging
import subprocess
from datetime import timedelta
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_NAME, CONF_VALUE_TEMPLATE, CONF_UNIT_OF_MEASUREMENT, CONF_COMMAND,
STATE_UNKNOWN)
from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'Command Sensor'
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_COMMAND): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Command Sensor."""
name = config.get(CONF_NAME)
command = config.get(CONF_COMMAND)
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
value_template = config.get(CONF_VALUE_TEMPLATE)
if value_template is not None:
value_template.hass = hass
data = CommandSensorData(command)
add_devices([CommandSensor(hass, data, name, unit, value_template)])
class CommandSensor(Entity):
"""Representation of a sensor that is using shell commands."""
def __init__(self, hass, data, name, unit_of_measurement, value_template):
"""Initialize the sensor."""
self._hass = hass
self.data = data
self._name = name
self._state = STATE_UNKNOWN
self._unit_of_measurement = unit_of_measurement
self._value_template = value_template
self.update()
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
"""Return the state of the device."""
return self._state
def update(self):
"""Get the latest data and updates the state."""
self.data.update()
value = self.data.value
if value is None:
value = STATE_UNKNOWN
elif self._value_template is not None:
self._state = self._value_template.render_with_possible_json_value(
value, STATE_UNKNOWN)
else:
self._state = value
class CommandSensorData(object):
"""The class for handling the data retrieval."""
def __init__(self, command):
"""Initialize the data object."""
self.command = command
self.value = None
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Get the latest data with a shell command."""
_LOGGER.info('Running command: %s', self.command)
try:
return_value = subprocess.check_output(self.command, shell=True,
timeout=15)
self.value = return_value.strip().decode('utf-8')
except subprocess.CalledProcessError:
_LOGGER.error('Command failed: %s', self.command)
except subprocess.TimeoutExpired:
_LOGGER.error('Timeout for command: %s', self.command)
|
mit
|
[
624,
199,
19780,
370,
7908,
3537,
5218,
3718,
370,
7485,
282,
574,
367,
282,
8778,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
8956,
14,
1531,
63,
604,
15,
199,
624,
199,
646,
2050,
199,
646,
3873,
199,
504,
2197,
492,
6871,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
2339,
12,
6392,
63,
7041,
63,
7433,
12,
6392,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
6392,
63,
10761,
12,
272,
11377,
63,
11588,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
504,
8846,
14,
1974,
492,
3868,
12301,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3472,
63,
2339,
275,
283,
3110,
18474,
7,
199,
199,
4896,
63,
4961,
63,
34,
29056,
63,
23612,
654,
275,
6871,
8,
4515,
29,
2259,
9,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
10761,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
7041,
63,
7433,
304,
6277,
14,
1160,
12,
199,
1552,
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,
5817,
18474,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
9,
272,
1414,
275,
1101,
14,
362,
8,
3103,
63,
10761,
9,
272,
4137,
275,
1101,
14,
362,
8,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
9,
272,
574,
63,
1160,
275,
1101,
14,
362,
8,
3103,
63,
7041,
63,
7433,
9,
272,
340,
574,
63,
1160,
365,
440,
488,
26,
267,
574,
63,
1160,
14,
5387,
275,
6298,
272,
666,
275,
5817,
10160,
1451,
8,
1531,
9,
339,
1050,
63,
6410,
779,
3110,
10160,
8,
5387,
12,
666,
12,
536,
12,
4137,
12,
574,
63,
1160,
3948,
421,
199,
533,
5817,
10160,
8,
7302,
304,
272,
408,
20609,
402,
282,
8778,
626,
365,
1808,
5218,
3718,
1041,
339,
347,
636,
826,
721,
277,
12,
6298,
12,
666,
12,
536,
12,
4137,
63,
1618,
63,
17912,
12,
574,
63,
1160,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
5387,
275,
6298,
267,
291,
14,
576,
275,
666,
267,
291,
423,
354,
275,
536,
267,
291,
423,
929,
275,
11377,
63,
11588,
267,
291,
423,
3248,
63,
1618,
63,
17912,
275,
4137,
63,
1618,
63,
17912,
267,
291,
423,
585,
63,
1160,
275,
574,
63,
1160,
267,
291,
14,
873,
342,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
314,
574,
365,
19147,
315,
1041,
267,
372,
291,
423,
3248,
63,
1618,
63,
17912,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
372,
291,
423,
929,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
436,
7029,
314,
1174,
1041,
267,
291,
14,
576,
14,
873,
342,
267,
574,
275,
291,
14,
576,
14,
585,
398,
340,
574,
365,
488,
26,
288,
574,
275,
11377,
63,
11588,
267,
916,
291,
423,
585,
63,
1160,
365,
440,
488,
26,
288,
291,
423,
929,
275,
291,
423,
585,
63,
1160,
14,
3352,
63,
1045,
63,
13893,
63,
1001,
63,
585,
8,
355,
574,
12,
11377,
63,
11588,
9,
267,
587,
26,
288,
291,
423,
929,
275,
574,
421,
199,
533,
5817,
10160,
1451,
8,
785,
304,
272,
408,
1918,
1021,
367,
7252,
314,
666,
27157,
1041,
339,
347,
636,
826,
721,
277,
12,
1414,
304,
267,
408,
9345,
314,
666,
909,
1041,
267,
291,
14,
1531,
275,
1414,
267,
291,
14,
585,
275,
488,
339,
768,
26192,
8,
4896,
63,
4961,
63,
34,
29056,
63,
23612,
654,
9,
272,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
543,
282,
5218,
1414,
1041,
267,
485,
10186,
14,
815,
360,
9602,
1414,
26,
450,
83,
297,
291,
14,
1531,
9,
398,
862,
26,
288,
372,
63,
585,
275,
3873,
14,
1074,
63,
1199,
8,
277,
14,
1531,
12,
5218,
29,
549,
12,
8962,
2653,
29,
1046,
9,
288,
291,
14,
585,
275,
372,
63,
585,
14,
1913,
1252,
2708,
360,
1624,
13,
24,
358,
267,
871,
3873,
14,
24691,
26,
288,
485,
10186,
14,
705,
360,
3110,
3405,
26,
450,
83,
297,
291,
14,
1531,
9,
267,
871,
3873,
14,
6372,
20898,
26,
288,
485,
10186,
14,
705,
360,
6372,
367,
1414,
26,
450,
83,
297,
291,
14,
1531,
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
] |
[
199,
19780,
370,
7908,
3537,
5218,
3718,
370,
7485,
282,
574,
367,
282,
8778,
14,
199,
199,
1858,
1655,
2436,
3595,
642,
4298,
12,
8749,
10618,
370,
314,
3794,
737,
199,
2859,
921,
4219,
13,
7310,
14,
2308,
15,
4608,
15,
8956,
14,
1531,
63,
604,
15,
199,
624,
199,
646,
2050,
199,
646,
3873,
199,
504,
2197,
492,
6871,
199,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
8956,
492,
21966,
63,
10926,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
2339,
12,
6392,
63,
7041,
63,
7433,
12,
6392,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
12,
6392,
63,
10761,
12,
272,
11377,
63,
11588,
9,
199,
504,
8846,
14,
7546,
14,
4502,
492,
17680,
199,
504,
8846,
14,
1974,
492,
3868,
12301,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
3472,
63,
2339,
275,
283,
3110,
18474,
7,
199,
199,
4896,
63,
4961,
63,
34,
29056,
63,
23612,
654,
275,
6871,
8,
4515,
29,
2259,
9,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
2561,
272,
5236,
14,
8030,
8,
3103,
63,
10761,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
2339,
12,
849,
29,
3472,
63,
2339,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
304,
6277,
14,
875,
12,
272,
5236,
14,
7012,
8,
3103,
63,
7041,
63,
7433,
304,
6277,
14,
1160,
12,
199,
1552,
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,
5817,
18474,
1041,
272,
536,
275,
1101,
14,
362,
8,
3103,
63,
2339,
9,
272,
1414,
275,
1101,
14,
362,
8,
3103,
63,
10761,
9,
272,
4137,
275,
1101,
14,
362,
8,
3103,
63,
15505,
63,
3359,
63,
31097,
3942,
4479,
9,
272,
574,
63,
1160,
275,
1101,
14,
362,
8,
3103,
63,
7041,
63,
7433,
9,
272,
340,
574,
63,
1160,
365,
440,
488,
26,
267,
574,
63,
1160,
14,
5387,
275,
6298,
272,
666,
275,
5817,
10160,
1451,
8,
1531,
9,
339,
1050,
63,
6410,
779,
3110,
10160,
8,
5387,
12,
666,
12,
536,
12,
4137,
12,
574,
63,
1160,
3948,
421,
199,
533,
5817,
10160,
8,
7302,
304,
272,
408,
20609,
402,
282,
8778,
626,
365,
1808,
5218,
3718,
1041,
339,
347,
636,
826,
721,
277,
12,
6298,
12,
666,
12,
536,
12,
4137,
63,
1618,
63,
17912,
12,
574,
63,
1160,
304,
267,
408,
9345,
314,
8778,
1041,
267,
291,
423,
5387,
275,
6298,
267,
291,
14,
576,
275,
666,
267,
291,
423,
354,
275,
536,
267,
291,
423,
929,
275,
11377,
63,
11588,
267,
291,
423,
3248,
63,
1618,
63,
17912,
275,
4137,
63,
1618,
63,
17912,
267,
291,
423,
585,
63,
1160,
275,
574,
63,
1160,
267,
291,
14,
873,
342,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
408,
1767,
314,
536,
402,
314,
8778,
1041,
267,
372,
291,
423,
354,
339,
768,
1829,
272,
347,
4137,
63,
1618,
63,
17912,
8,
277,
304,
267,
408,
1767,
314,
4137,
314,
574,
365,
19147,
315,
1041,
267,
372,
291,
423,
3248,
63,
1618,
63,
17912,
339,
768,
1829,
272,
347,
1174,
8,
277,
304,
267,
408,
1767,
314,
1174,
402,
314,
2243,
1041,
267,
372,
291,
423,
929,
339,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
436,
7029,
314,
1174,
1041,
267,
291,
14,
576,
14,
873,
342,
267,
574,
275,
291,
14,
576,
14,
585,
398,
340,
574,
365,
488,
26,
288,
574,
275,
11377,
63,
11588,
267,
916,
291,
423,
585,
63,
1160,
365,
440,
488,
26,
288,
291,
423,
929,
275,
291,
423,
585,
63,
1160,
14,
3352,
63,
1045,
63,
13893,
63,
1001,
63,
585,
8,
355,
574,
12,
11377,
63,
11588,
9,
267,
587,
26,
288,
291,
423,
929,
275,
574,
421,
199,
533,
5817,
10160,
1451,
8,
785,
304,
272,
408,
1918,
1021,
367,
7252,
314,
666,
27157,
1041,
339,
347,
636,
826,
721,
277,
12,
1414,
304,
267,
408,
9345,
314,
666,
909,
1041,
267,
291,
14,
1531,
275,
1414,
267,
291,
14,
585,
275,
488,
339,
768,
26192,
8,
4896,
63,
4961,
63,
34,
29056,
63,
23612,
654,
9,
272,
347,
1678,
8,
277,
304,
267,
408,
1002,
314,
8839,
666,
543,
282,
5218,
1414,
1041,
267,
485,
10186,
14,
815,
360,
9602,
1414,
26,
450,
83,
297,
291,
14,
1531,
9,
398,
862,
26,
288,
372,
63,
585,
275,
3873,
14,
1074,
63,
1199,
8,
277,
14,
1531,
12,
5218,
29,
549,
12,
8962,
2653,
29,
1046,
9,
288,
291,
14,
585,
275,
372,
63,
585,
14,
1913,
1252,
2708,
360,
1624,
13,
24,
358,
267,
871,
3873,
14,
24691,
26,
288,
485,
10186,
14,
705,
360,
3110,
3405,
26,
450,
83,
297,
291,
14,
1531,
9,
267,
871,
3873,
14,
6372,
20898,
26,
288,
485,
10186,
14,
705,
360,
6372,
367,
1414,
26,
450,
83,
297,
291,
14,
1531,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eddieantonio/imgcat
|
libexec/gen_img.py
|
1
|
2780
|
#!/usr/bin/env python
# Copyright (c) 2014–2018, Eddie Antonio Santos <easantos@ualberta.ca>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""
Generates images for tests.
pip install --user PyYAML Pillow
- 1px_256_table.png
A PNG where every pixel EXACTLY cooresponds to a
256 color value.
- 1px_256_table.jpg
A JPEG where every pixel ATTEMPTS to cooresponds to
a 256 color value. But they won't.
"""
import os
import sys
import yaml
from PIL import Image
TEST_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'test')
WIDTH = 12
# 256 color cube, greyscale ramp, 16 colors
HEIGHT = 18 + 2 + 2
with open('xterm-256color.yaml') as f:
_COLORS = yaml.load(f)
def tupleize(name, x):
i = lambda x: int(x, 16)
rgb = (i(x[1:3]), i(x[3:5]), i(x[5:7]))
return name, rgb
COLORS = [
[tupleize(*arg) for arg in _COLORS[':xterm256']],
[tupleize(*arg) for arg in _COLORS[':xtermGreyscale']],
[tupleize(*arg) for arg in _COLORS[':xterm16']]
]
def main(*args):
im = Image.new('RGB', (WIDTH, HEIGHT), (0, 0, 0))
row = 0
col = 0
base_row = 0
# 18 rows of 6**3 color cube.
for _, val in COLORS[0]:
im.putpixel((col, row), val)
row += 1
# Next column...
if (row % 6) == 0:
col += 1
if (col % 12) == 0:
base_row += 6
col = 0
row = base_row
assert row == 18
# 2 rows of greyscale
for _, val in COLORS[1]:
im.putpixel((col, row), val)
col += 1
# Next row...
if (col % 12) == 0:
row += 1
col = 0
assert row == 20
# 2 rows of 16 color.
for _, val in COLORS[2]:
im.putpixel((col, row), val)
col += 1
# Next row...
if (col % 8) == 0:
row += 1
col = 0
# Save 'em
im.save(os.path.join(TEST_DIR, '1px_256_table.png'))
im.save(os.path.join(TEST_DIR, '1px_256_table.jpg'), quality=40)
if __name__ == '__main__':
sys.exit(main(*sys.argv))
|
isc
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6927,
8477,
242,
12682,
12,
17379,
15130,
437,
343,
265,
2308,
29359,
14543,
665,
69,
305,
290,
14543,
32,
1061,
605,
502,
14,
696,
30,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
15,
269,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
199,
20551,
5935,
367,
2295,
14,
339,
7305,
3907,
1553,
751,
1611,
23103,
18130,
674,
421,
446,
413,
5326,
63,
3912,
63,
1224,
14,
4524,
2126,
437,
26951,
2382,
4036,
7148,
3651,
3036,
6084,
512,
79,
3853,
795,
370,
282,
2126,
7633,
3164,
574,
14,
421,
446,
413,
5326,
63,
3912,
63,
1224,
14,
8476,
267,
437,
1603,
17557,
2382,
4036,
7148,
10395,
37,
1658,
9730,
370,
512,
79,
3853,
795,
370,
267,
282,
7633,
3164,
574,
14,
11017,
2985,
7859,
1133,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
8864,
199,
199,
504,
14937,
492,
6047,
199,
199,
2864,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
395,
283,
396,
358,
421,
199,
11139,
275,
3144,
199,
3,
7633,
3164,
15681,
12,
30357,
3467,
660,
311,
12,
3193,
9229,
199,
13509,
275,
6155,
435,
499,
435,
499,
199,
199,
1045,
1551,
360,
31896,
13,
3912,
2326,
14,
5963,
358,
465,
289,
26,
272,
485,
25671,
275,
8864,
14,
912,
8,
70,
9,
421,
199,
318,
2008,
794,
8,
354,
12,
671,
304,
272,
284,
275,
2400,
671,
26,
1109,
8,
88,
12,
3193,
9,
272,
15180,
275,
334,
73,
8,
88,
59,
17,
26,
19,
2522,
284,
8,
88,
59,
19,
26,
21,
2522,
284,
8,
88,
59,
21,
26,
23,
2459,
272,
372,
536,
12,
15180,
199,
199,
25671,
275,
359,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
3912,
2157,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
39,
17885,
3467,
2157,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
975,
6538,
199,
61,
421,
199,
318,
2446,
2031,
589,
304,
272,
3416,
275,
6047,
14,
1222,
360,
12067,
297,
334,
11139,
12,
8378,
2830,
395,
334,
16,
12,
378,
12,
378,
430,
339,
1962,
275,
378,
272,
1048,
275,
378,
272,
1300,
63,
1143,
275,
378,
339,
327,
6155,
4730,
402,
1227,
538,
19,
3164,
15681,
14,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
16,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1962,
847,
413,
267,
327,
16840,
2763,
1396,
267,
340,
334,
1143,
450,
1227,
9,
508,
378,
26,
288,
1048,
847,
413,
288,
340,
334,
761,
450,
3144,
9,
508,
378,
26,
355,
1300,
63,
1143,
847,
1227,
355,
1048,
275,
378,
288,
1962,
275,
1300,
63,
1143,
339,
702,
1962,
508,
6155,
339,
327,
499,
4730,
402,
30357,
3467,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
17,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1048,
847,
413,
267,
327,
16840,
1962,
1396,
267,
340,
334,
761,
450,
3144,
9,
508,
378,
26,
288,
1962,
847,
413,
288,
1048,
275,
378,
339,
702,
1962,
508,
3388,
339,
327,
499,
4730,
402,
3193,
3164,
14,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
18,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1048,
847,
413,
267,
327,
16840,
1962,
1396,
267,
340,
334,
761,
450,
1695,
9,
508,
378,
26,
288,
1962,
847,
413,
288,
1048,
275,
378,
339,
327,
11063,
283,
5633,
272,
3416,
14,
2117,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
17,
5326,
63,
3912,
63,
1224,
14,
4524,
1333,
272,
3416,
14,
2117,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
17,
5326,
63,
3912,
63,
1224,
14,
8476,
659,
11030,
29,
2167,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
984,
14,
2224,
8,
973,
2031,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
6927,
8477,
242,
12682,
12,
17379,
15130,
437,
343,
265,
2308,
29359,
14543,
665,
69,
305,
290,
14543,
32,
1061,
605,
502,
14,
696,
30,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
15,
269,
11207,
642,
2032,
367,
1263,
199,
3,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
2741,
626,
314,
3432,
199,
3,
4248,
4245,
436,
642,
4983,
4245,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
2334,
17632,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
2334,
17632,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
1634,
199,
3,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
624,
199,
20551,
5935,
367,
2295,
14,
339,
7305,
3907,
1553,
751,
1611,
23103,
18130,
674,
421,
446,
413,
5326,
63,
3912,
63,
1224,
14,
4524,
2126,
437,
26951,
2382,
4036,
7148,
3651,
3036,
6084,
512,
79,
3853,
795,
370,
282,
2126,
7633,
3164,
574,
14,
421,
446,
413,
5326,
63,
3912,
63,
1224,
14,
8476,
267,
437,
1603,
17557,
2382,
4036,
7148,
10395,
37,
1658,
9730,
370,
512,
79,
3853,
795,
370,
267,
282,
7633,
3164,
574,
14,
11017,
2985,
7859,
1133,
14,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
8864,
199,
199,
504,
14937,
492,
6047,
199,
199,
2864,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
395,
283,
396,
358,
421,
199,
11139,
275,
3144,
199,
3,
7633,
3164,
15681,
12,
30357,
3467,
660,
311,
12,
3193,
9229,
199,
13509,
275,
6155,
435,
499,
435,
499,
199,
199,
1045,
1551,
360,
31896,
13,
3912,
2326,
14,
5963,
358,
465,
289,
26,
272,
485,
25671,
275,
8864,
14,
912,
8,
70,
9,
421,
199,
318,
2008,
794,
8,
354,
12,
671,
304,
272,
284,
275,
2400,
671,
26,
1109,
8,
88,
12,
3193,
9,
272,
15180,
275,
334,
73,
8,
88,
59,
17,
26,
19,
2522,
284,
8,
88,
59,
19,
26,
21,
2522,
284,
8,
88,
59,
21,
26,
23,
2459,
272,
372,
536,
12,
15180,
199,
199,
25671,
275,
359,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
3912,
2157,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
39,
17885,
3467,
2157,
272,
359,
2960,
794,
2031,
1273,
9,
367,
1680,
315,
485,
25671,
59,
356,
31896,
975,
6538,
199,
61,
421,
199,
318,
2446,
2031,
589,
304,
272,
3416,
275,
6047,
14,
1222,
360,
12067,
297,
334,
11139,
12,
8378,
2830,
395,
334,
16,
12,
378,
12,
378,
430,
339,
1962,
275,
378,
272,
1048,
275,
378,
272,
1300,
63,
1143,
275,
378,
339,
327,
6155,
4730,
402,
1227,
538,
19,
3164,
15681,
14,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
16,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1962,
847,
413,
267,
327,
16840,
2763,
1396,
267,
340,
334,
1143,
450,
1227,
9,
508,
378,
26,
288,
1048,
847,
413,
288,
340,
334,
761,
450,
3144,
9,
508,
378,
26,
355,
1300,
63,
1143,
847,
1227,
355,
1048,
275,
378,
288,
1962,
275,
1300,
63,
1143,
339,
702,
1962,
508,
6155,
339,
327,
499,
4730,
402,
30357,
3467,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
17,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1048,
847,
413,
267,
327,
16840,
1962,
1396,
267,
340,
334,
761,
450,
3144,
9,
508,
378,
26,
288,
1962,
847,
413,
288,
1048,
275,
378,
339,
702,
1962,
508,
3388,
339,
327,
499,
4730,
402,
3193,
3164,
14,
272,
367,
5501,
1139,
315,
13513,
4149,
59,
18,
2189,
267,
3416,
14,
524,
8435,
1332,
761,
12,
1962,
395,
1139,
9,
398,
1048,
847,
413,
267,
327,
16840,
1962,
1396,
267,
340,
334,
761,
450,
1695,
9,
508,
378,
26,
288,
1962,
847,
413,
288,
1048,
275,
378,
339,
327,
11063,
283,
5633,
272,
3416,
14,
2117,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
17,
5326,
63,
3912,
63,
1224,
14,
4524,
1333,
272,
3416,
14,
2117,
8,
736,
14,
515,
14,
904,
8,
2864,
63,
3022,
12,
283,
17,
5326,
63,
3912,
63,
1224,
14,
8476,
659,
11030,
29,
2167,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
984,
14,
2224,
8,
973,
2031,
1274,
14,
3020,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
daizhengy/RDS
|
trove/db/__init__.py
|
5
|
3592
|
# Copyright 2010-2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import optparse
from trove.common import utils
from trove.common import cfg
CONF = cfg.CONF
db_api_opt = CONF.db_api_implementation
def get_db_api():
return utils.import_module(db_api_opt)
class Query(object):
"""Mimics sqlalchemy query object.
This class allows us to store query conditions and use them with
bulk updates and deletes just like sqlalchemy query object.
Using this class makes the models independent of sqlalchemy
"""
def __init__(self, model, query_func, **conditions):
self._query_func = query_func
self._model = model
self._conditions = conditions
self.db_api = get_db_api()
def all(self):
return self.db_api.list(self._query_func, self._model,
**self._conditions)
def count(self):
return self.db_api.count(self._query_func, self._model,
**self._conditions)
def first(self):
return self.db_api.first(self._query_func, self._model,
**self._conditions)
def join(self, *args):
return self.db_api.join(self._query_func, self._model, *args)
def __iter__(self):
return iter(self.all())
def update(self, **values):
self.db_api.update_all(self._query_func, self._model, self._conditions,
values)
def delete(self):
self.db_api.delete_all(self._query_func, self._model,
**self._conditions)
def limit(self, limit=200, marker=None, marker_column=None):
return self.db_api.find_all_by_limit(
self._query_func,
self._model,
self._conditions,
limit=limit,
marker=marker,
marker_column=marker_column)
def paginated_collection(self, limit=200, marker=None, marker_column=None):
collection = self.limit(int(limit) + 1, marker, marker_column)
if len(collection) > int(limit):
return (collection[0:-1], collection[-2]['id'])
return (collection, None)
class Queryable(object):
def __getattr__(self, item):
return lambda model, **conditions: Query(
model, query_func=getattr(get_db_api(), item), **conditions)
db_query = Queryable()
def add_options(parser):
"""Adds any configuration options that the db layer might have.
:param parser: An optparse.OptionParser object
:retval None
"""
help_text = ("The following configuration options are specific to the "
"Trove database.")
group = optparse.OptionGroup(
parser,
"Registry Database Options",
help_text)
group.add_option(
'--sql-connection',
metavar="CONNECTION",
default=None,
help="A valid SQLAlchemy connection string for the "
"registry database. Default: %(default)s.")
parser.add_option_group(group)
|
apache-2.0
|
[
3,
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
8691,
199,
199,
504,
307,
11750,
14,
2330,
492,
3778,
199,
504,
307,
11750,
14,
2330,
492,
4810,
199,
199,
3103,
275,
4810,
14,
3103,
199,
199,
697,
63,
1246,
63,
2992,
275,
6392,
14,
697,
63,
1246,
63,
12236,
421,
199,
318,
664,
63,
697,
63,
1246,
837,
272,
372,
3778,
14,
646,
63,
578,
8,
697,
63,
1246,
63,
2992,
9,
421,
199,
533,
8133,
8,
785,
304,
272,
408,
45,
1017,
2932,
8335,
1827,
909,
14,
339,
961,
1021,
6127,
2739,
370,
3877,
1827,
3704,
436,
675,
3062,
543,
272,
13137,
7029,
436,
21812,
2951,
2839,
8335,
1827,
909,
14,
272,
11719,
642,
1021,
7704,
314,
1709,
12717,
402,
8335,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1402,
12,
1827,
63,
1532,
12,
1011,
9855,
304,
267,
291,
423,
1131,
63,
1532,
275,
1827,
63,
1532,
267,
291,
423,
1238,
275,
1402,
267,
291,
423,
9855,
275,
3704,
267,
291,
14,
697,
63,
1246,
275,
664,
63,
697,
63,
1246,
342,
339,
347,
1006,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
513,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
1816,
1011,
277,
423,
9855,
9,
339,
347,
2338,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
835,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
639,
1011,
277,
423,
9855,
9,
339,
347,
1642,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
2246,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
639,
1011,
277,
423,
9855,
9,
339,
347,
4263,
8,
277,
12,
627,
589,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
904,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
627,
589,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
452,
1012,
339,
347,
1678,
8,
277,
12,
1011,
1459,
304,
267,
291,
14,
697,
63,
1246,
14,
873,
63,
452,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
291,
423,
9855,
12,
3044,
1338,
9,
339,
347,
3145,
8,
277,
304,
267,
291,
14,
697,
63,
1246,
14,
1807,
63,
452,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
3044,
1011,
277,
423,
9855,
9,
339,
347,
2304,
8,
277,
12,
2304,
29,
1840,
12,
3608,
29,
403,
12,
3608,
63,
2301,
29,
403,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
1623,
63,
452,
63,
991,
63,
3097,
8,
288,
291,
423,
1131,
63,
1532,
12,
288,
291,
423,
1238,
12,
288,
291,
423,
9855,
12,
288,
2304,
29,
3097,
12,
288,
3608,
29,
4211,
12,
288,
3608,
63,
2301,
29,
4211,
63,
2301,
9,
339,
347,
9881,
23831,
63,
3627,
8,
277,
12,
2304,
29,
1840,
12,
3608,
29,
403,
12,
3608,
63,
2301,
29,
403,
304,
267,
3245,
275,
291,
14,
3097,
8,
442,
8,
3097,
9,
435,
413,
12,
3608,
12,
3608,
63,
2301,
9,
267,
340,
822,
8,
3627,
9,
690,
1109,
8,
3097,
304,
288,
372,
334,
3627,
59,
16,
6809,
17,
467,
3245,
1988,
18,
2733,
344,
1105,
267,
372,
334,
3627,
12,
488,
9,
421,
199,
533,
8133,
461,
8,
785,
304,
339,
347,
636,
5675,
721,
277,
12,
1242,
304,
267,
372,
2400,
1402,
12,
1011,
9855,
26,
8133,
8,
288,
1402,
12,
1827,
63,
1532,
29,
5675,
8,
362,
63,
697,
63,
1246,
1062,
1242,
395,
1011,
9855,
9,
199,
199,
697,
63,
1131,
275,
8133,
461,
342,
421,
199,
318,
1050,
63,
1419,
8,
2087,
304,
272,
408,
14995,
1263,
2897,
1511,
626,
314,
1592,
4045,
5594,
1172,
14,
339,
520,
635,
1798,
26,
1626,
8691,
14,
14553,
909,
272,
520,
18476,
488,
339,
408,
272,
1720,
63,
505,
275,
1689,
1918,
2569,
2897,
1511,
787,
2488,
370,
314,
298,
326,
298,
52,
11750,
3050,
2685,
339,
1572,
275,
8691,
14,
2602,
2448,
8,
267,
1798,
12,
267,
298,
10899,
8692,
8394,
401,
267,
1720,
63,
505,
9,
272,
1572,
14,
525,
63,
1422,
8,
267,
2850,
3009,
13,
2105,
297,
267,
8214,
628,
18389,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
33,
1686,
14303,
1950,
1059,
367,
314,
298,
1467,
298,
5189,
3050,
14,
3758,
26,
2818,
885,
9,
83,
2685,
272,
1798,
14,
525,
63,
1422,
63,
923,
8,
923,
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
] |
[
1898,
7129,
13,
8128,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
8691,
199,
199,
504,
307,
11750,
14,
2330,
492,
3778,
199,
504,
307,
11750,
14,
2330,
492,
4810,
199,
199,
3103,
275,
4810,
14,
3103,
199,
199,
697,
63,
1246,
63,
2992,
275,
6392,
14,
697,
63,
1246,
63,
12236,
421,
199,
318,
664,
63,
697,
63,
1246,
837,
272,
372,
3778,
14,
646,
63,
578,
8,
697,
63,
1246,
63,
2992,
9,
421,
199,
533,
8133,
8,
785,
304,
272,
408,
45,
1017,
2932,
8335,
1827,
909,
14,
339,
961,
1021,
6127,
2739,
370,
3877,
1827,
3704,
436,
675,
3062,
543,
272,
13137,
7029,
436,
21812,
2951,
2839,
8335,
1827,
909,
14,
272,
11719,
642,
1021,
7704,
314,
1709,
12717,
402,
8335,
339,
408,
272,
347,
636,
826,
721,
277,
12,
1402,
12,
1827,
63,
1532,
12,
1011,
9855,
304,
267,
291,
423,
1131,
63,
1532,
275,
1827,
63,
1532,
267,
291,
423,
1238,
275,
1402,
267,
291,
423,
9855,
275,
3704,
267,
291,
14,
697,
63,
1246,
275,
664,
63,
697,
63,
1246,
342,
339,
347,
1006,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
513,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
1816,
1011,
277,
423,
9855,
9,
339,
347,
2338,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
835,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
639,
1011,
277,
423,
9855,
9,
339,
347,
1642,
8,
277,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
2246,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
639,
1011,
277,
423,
9855,
9,
339,
347,
4263,
8,
277,
12,
627,
589,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
904,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
627,
589,
9,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
14,
452,
1012,
339,
347,
1678,
8,
277,
12,
1011,
1459,
304,
267,
291,
14,
697,
63,
1246,
14,
873,
63,
452,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
291,
423,
9855,
12,
3044,
1338,
9,
339,
347,
3145,
8,
277,
304,
267,
291,
14,
697,
63,
1246,
14,
1807,
63,
452,
8,
277,
423,
1131,
63,
1532,
12,
291,
423,
1238,
12,
3044,
1011,
277,
423,
9855,
9,
339,
347,
2304,
8,
277,
12,
2304,
29,
1840,
12,
3608,
29,
403,
12,
3608,
63,
2301,
29,
403,
304,
267,
372,
291,
14,
697,
63,
1246,
14,
1623,
63,
452,
63,
991,
63,
3097,
8,
288,
291,
423,
1131,
63,
1532,
12,
288,
291,
423,
1238,
12,
288,
291,
423,
9855,
12,
288,
2304,
29,
3097,
12,
288,
3608,
29,
4211,
12,
288,
3608,
63,
2301,
29,
4211,
63,
2301,
9,
339,
347,
9881,
23831,
63,
3627,
8,
277,
12,
2304,
29,
1840,
12,
3608,
29,
403,
12,
3608,
63,
2301,
29,
403,
304,
267,
3245,
275,
291,
14,
3097,
8,
442,
8,
3097,
9,
435,
413,
12,
3608,
12,
3608,
63,
2301,
9,
267,
340,
822,
8,
3627,
9,
690,
1109,
8,
3097,
304,
288,
372,
334,
3627,
59,
16,
6809,
17,
467,
3245,
1988,
18,
2733,
344,
1105,
267,
372,
334,
3627,
12,
488,
9,
421,
199,
533,
8133,
461,
8,
785,
304,
339,
347,
636,
5675,
721,
277,
12,
1242,
304,
267,
372,
2400,
1402,
12,
1011,
9855,
26,
8133,
8,
288,
1402,
12,
1827,
63,
1532,
29,
5675,
8,
362,
63,
697,
63,
1246,
1062,
1242,
395,
1011,
9855,
9,
199,
199,
697,
63,
1131,
275,
8133,
461,
342,
421,
199,
318,
1050,
63,
1419,
8,
2087,
304,
272,
408,
14995,
1263,
2897,
1511,
626,
314,
1592,
4045,
5594,
1172,
14,
339,
520,
635,
1798,
26,
1626,
8691,
14,
14553,
909,
272,
520,
18476,
488,
339,
408,
272,
1720,
63,
505,
275,
1689,
1918,
2569,
2897,
1511,
787,
2488,
370,
314,
298,
326,
298,
52,
11750,
3050,
2685,
339,
1572,
275,
8691,
14,
2602,
2448,
8,
267,
1798,
12,
267,
298,
10899,
8692,
8394,
401,
267,
1720,
63,
505,
9,
272,
1572,
14,
525,
63,
1422,
8,
267,
2850,
3009,
13,
2105,
297,
267,
8214,
628,
18389,
401,
267,
849,
29,
403,
12,
267,
1720,
628,
33,
1686,
14303,
1950,
1059,
367,
314,
298,
1467,
298,
5189,
3050,
14,
3758,
26,
2818,
885,
9,
83,
2685,
272,
1798,
14,
525,
63,
1422,
63,
923,
8,
923,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rahuldhote/odoo
|
addons/website_customer/__openerp__.py
|
313
|
1571
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2013-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/>.
#
##############################################################################
{
'name': 'Customer References',
'category': 'Website',
'website': 'https://www.odoo.com/page/website-builder',
'summary': 'Publish Your Customer References',
'version': '1.0',
'description': """
OpenERP Customer References
===========================
""",
'author': 'OpenERP SA',
'depends': [
'crm_partner_assign',
'website_partner',
'website_google_map',
],
'demo': [
'website_customer_demo.xml',
],
'data': [
'views/website_customer.xml',
],
'qweb': [],
'installable': 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,
13,
31982,
7653,
428,
14,
33,
14,
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,
91,
272,
283,
354,
356,
283,
17025,
14504,
297,
272,
283,
3710,
356,
283,
26354,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
7360,
13,
5649,
297,
272,
283,
4705,
356,
283,
13956,
19519,
22397,
14504,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
1802,
356,
408,
199,
25347,
22397,
14504,
199,
1280,
21326,
199,
7208,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
359,
267,
283,
15213,
63,
3899,
63,
5038,
297,
267,
283,
7360,
63,
3899,
297,
267,
283,
7360,
63,
3098,
63,
1130,
297,
272,
2156,
272,
283,
8768,
356,
359,
267,
283,
7360,
63,
10178,
63,
8768,
14,
1652,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4196,
15,
7360,
63,
10178,
14,
1652,
297,
272,
2156,
272,
283,
22600,
356,
990,
272,
283,
21762,
356,
715,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
13,
31982,
7653,
428,
14,
33,
14,
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,
91,
272,
283,
354,
356,
283,
17025,
14504,
297,
272,
283,
3710,
356,
283,
26354,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
7360,
13,
5649,
297,
272,
283,
4705,
356,
283,
13956,
19519,
22397,
14504,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
1802,
356,
408,
199,
25347,
22397,
14504,
199,
1280,
21326,
199,
7208,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
359,
267,
283,
15213,
63,
3899,
63,
5038,
297,
267,
283,
7360,
63,
3899,
297,
267,
283,
7360,
63,
3098,
63,
1130,
297,
272,
2156,
272,
283,
8768,
356,
359,
267,
283,
7360,
63,
10178,
63,
8768,
14,
1652,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
4196,
15,
7360,
63,
10178,
14,
1652,
297,
272,
2156,
272,
283,
22600,
356,
990,
272,
283,
21762,
356,
715,
12,
199,
93,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nmercier/linux-cross-gcc
|
linux/lib/python2.7/dist-packages/PIL/IptcImagePlugin.py
|
19
|
6977
|
#
# The Python Imaging Library.
# $Id$
#
# IPTC/NAA file handling
#
# history:
# 1995-10-01 fl Created
# 1998-03-09 fl Cleaned up and added to PIL
# 2002-06-18 fl Added getiptcinfo helper
#
# Copyright (c) Secret Labs AB 1997-2002.
# Copyright (c) Fredrik Lundh 1995.
#
# See the README file for information on usage and redistribution.
#
from __future__ import print_function
from PIL import Image, ImageFile, _binary
import os
import tempfile
__version__ = "0.3"
i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
o8 = _binary.o8
COMPRESSION = {
1: "raw",
5: "jpeg"
}
PAD = o8(0) * 4
#
# Helpers
def i(c):
return i32((PAD + c)[-4:])
def dump(c):
for i in c:
print("%02x" % i8(i), end=' ')
print()
##
# Image plugin for IPTC/NAA datastreams. To read IPTC/NAA fields
# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.
class IptcImageFile(ImageFile.ImageFile):
format = "IPTC"
format_description = "IPTC/NAA"
def getint(self, key):
return i(self.info[key])
def field(self):
#
# get a IPTC field header
s = self.fp.read(5)
if not len(s):
return None, 0
tag = i8(s[1]), i8(s[2])
# syntax
if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:
raise SyntaxError("invalid IPTC/NAA file")
# field size
size = i8(s[3])
if size > 132:
raise IOError("illegal field length in IPTC/NAA file")
elif size == 128:
size = 0
elif size > 128:
size = i(self.fp.read(size-128))
else:
size = i16(s[3:])
return tag, size
def _open(self):
# load descriptive fields
while True:
offset = self.fp.tell()
tag, size = self.field()
if not tag or tag == (8, 10):
break
if size:
tagdata = self.fp.read(size)
else:
tagdata = None
if tag in list(self.info.keys()):
if isinstance(self.info[tag], list):
self.info[tag].append(tagdata)
else:
self.info[tag] = [self.info[tag], tagdata]
else:
self.info[tag] = tagdata
# print tag, self.info[tag]
# mode
layers = i8(self.info[(3, 60)][0])
component = i8(self.info[(3, 60)][1])
if (3, 65) in self.info:
id = i8(self.info[(3, 65)][0])-1
else:
id = 0
if layers == 1 and not component:
self.mode = "L"
elif layers == 3 and component:
self.mode = "RGB"[id]
elif layers == 4 and component:
self.mode = "CMYK"[id]
# size
self.size = self.getint((3, 20)), self.getint((3, 30))
# compression
try:
compression = COMPRESSION[self.getint((3, 120))]
except KeyError:
raise IOError("Unknown IPTC image compression")
# tile
if tag == (8, 10):
self.tile = [("iptc", (compression, offset),
(0, 0, self.size[0], self.size[1]))]
def load(self):
if len(self.tile) != 1 or self.tile[0][0] != "iptc":
return ImageFile.ImageFile.load(self)
type, tile, box = self.tile[0]
encoding, offset = tile
self.fp.seek(offset)
# Copy image data to temporary file
o_fd, outfile = tempfile.mkstemp(text=False)
o = os.fdopen(o_fd)
if encoding == "raw":
# To simplify access to the extracted file,
# prepend a PPM header
o.write("P5\n%d %d\n255\n" % self.size)
while True:
type, size = self.field()
if type != (8, 10):
break
while size > 0:
s = self.fp.read(min(size, 8192))
if not s:
break
o.write(s)
size -= len(s)
o.close()
try:
try:
# fast
self.im = Image.core.open_ppm(outfile)
except:
# slightly slower
im = Image.open(outfile)
im.load()
self.im = im.im
finally:
try:
os.unlink(outfile)
except OSError:
pass
Image.register_open(IptcImageFile.format, IptcImageFile)
Image.register_extension(IptcImageFile.format, ".iim")
##
# Get IPTC information from TIFF, JPEG, or IPTC file.
#
# @param im An image containing IPTC data.
# @return A dictionary containing IPTC information, or None if
# no IPTC information block was found.
def getiptcinfo(im):
from PIL import TiffImagePlugin, JpegImagePlugin
import io
data = None
if isinstance(im, IptcImageFile):
# return info dictionary right away
return im.info
elif isinstance(im, JpegImagePlugin.JpegImageFile):
# extract the IPTC/NAA resource
try:
app = im.app["APP13"]
if app[:14] == b"Photoshop 3.0\x00":
app = app[14:]
# parse the image resource block
offset = 0
while app[offset:offset+4] == b"8BIM":
offset += 4
# resource code
code = i16(app, offset)
offset += 2
# resource name (usually empty)
name_len = i8(app[offset])
# name = app[offset+1:offset+1+name_len]
offset = 1 + offset + name_len
if offset & 1:
offset += 1
# resource data block
size = i32(app, offset)
offset += 4
if code == 0x0404:
# 0x0404 contains IPTC/NAA data
data = app[offset:offset+size]
break
offset = offset + size
if offset & 1:
offset += 1
except (AttributeError, KeyError):
pass
elif isinstance(im, TiffImagePlugin.TiffImageFile):
# get raw data from the IPTC/NAA tag (PhotoShop tags the data
# as 4-byte integers, so we cannot use the get method...)
try:
data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
except (AttributeError, KeyError):
pass
if data is None:
return None # no properties
# create an IptcImagePlugin object without initializing it
class FakeImage(object):
pass
im = FakeImage()
im.__class__ = IptcImageFile
# parse the IPTC information chunk
im.info = {}
im.fp = io.BytesIO(data)
try:
im._open()
except (IndexError, KeyError):
pass # expected failure
return im.info
|
bsd-3-clause
|
[
3,
199,
3,
710,
2018,
473,
391,
1540,
11243,
14,
199,
3,
2672,
1304,
4,
199,
3,
199,
3,
3531,
5708,
15,
46,
2276,
570,
7252,
199,
3,
199,
3,
7994,
26,
199,
3,
9013,
21,
13,
709,
13,
614,
2717,
257,
18208,
199,
3,
19960,
13,
1644,
13,
1643,
2717,
257,
12762,
379,
1536,
436,
3483,
370,
14937,
199,
3,
14790,
13,
1690,
13,
1085,
2717,
257,
16230,
2312,
280,
541,
67,
815,
5922,
199,
3,
199,
3,
1898,
334,
67,
9,
23580,
491,
2101,
14840,
9013,
23,
13,
15135,
14,
199,
3,
1898,
334,
67,
9,
481,
581,
25844,
491,
725,
72,
9013,
21,
14,
199,
3,
199,
3,
1666,
314,
27781,
570,
367,
2556,
641,
4503,
436,
295,
4972,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
14937,
492,
6047,
12,
6047,
1173,
12,
485,
3008,
199,
646,
747,
199,
646,
5549,
199,
199,
363,
1023,
363,
275,
298,
16,
14,
19,
2,
199,
199,
73,
24,
275,
485,
3008,
14,
73,
24,
199,
73,
975,
275,
485,
3008,
14,
73,
975,
1235,
199,
73,
708,
275,
485,
3008,
14,
73,
708,
1235,
199,
79,
24,
275,
485,
3008,
14,
79,
24,
199,
199,
30193,
275,
469,
272,
413,
26,
298,
1773,
401,
272,
959,
26,
298,
14230,
2,
199,
93,
199,
199,
32420,
275,
312,
24,
8,
16,
9,
627,
841,
421,
199,
3,
199,
3,
11642,
83,
199,
199,
318,
284,
8,
67,
304,
272,
372,
284,
708,
1332,
32420,
435,
286,
15786,
20,
5728,
421,
199,
318,
5461,
8,
67,
304,
272,
367,
284,
315,
286,
26,
267,
870,
3647,
996,
88,
2,
450,
284,
24,
8,
73,
395,
1284,
534,
5320,
272,
870,
342,
421,
199,
309,
199,
3,
6047,
3589,
367,
3531,
5708,
15,
46,
2276,
666,
11231,
14,
221,
4005,
1586,
3531,
5708,
15,
46,
2276,
1504,
199,
3,
687,
377,
24150,
436,
1603,
17557,
1584,
12,
675,
314,
665,
66,
30,
303,
280,
541,
67,
815,
1108,
66,
30,
805,
14,
199,
199,
533,
473,
541,
67,
30636,
8,
30636,
14,
30636,
304,
339,
1475,
275,
298,
4385,
35,
2,
272,
1475,
63,
1802,
275,
298,
4385,
35,
15,
46,
2276,
2,
339,
347,
664,
442,
8,
277,
12,
790,
304,
267,
372,
284,
8,
277,
14,
815,
59,
498,
566,
339,
347,
901,
8,
277,
304,
267,
327,
267,
327,
664,
282,
3531,
5708,
901,
1406,
267,
308,
275,
291,
14,
3997,
14,
739,
8,
21,
9,
267,
340,
440,
822,
8,
83,
304,
288,
372,
488,
12,
378,
398,
1947,
275,
284,
24,
8,
83,
59,
17,
2522,
284,
24,
8,
83,
59,
18,
566,
398,
327,
6302,
267,
340,
284,
24,
8,
83,
59,
16,
566,
1137,
378,
88,
17,
35,
503,
1947,
59,
16,
61,
665,
413,
503,
1947,
59,
16,
61,
690,
1749,
26,
288,
746,
12053,
480,
3197,
3531,
5708,
15,
46,
2276,
570,
531,
398,
327,
901,
1568,
267,
1568,
275,
284,
24,
8,
83,
59,
19,
566,
267,
340,
1568,
690,
27207,
26,
288,
746,
5925,
480,
23375,
901,
2582,
315,
3531,
5708,
15,
46,
2276,
570,
531,
267,
916,
1568,
508,
7960,
26,
288,
1568,
275,
378,
267,
916,
1568,
690,
7960,
26,
288,
1568,
275,
284,
8,
277,
14,
3997,
14,
739,
8,
890,
13,
3933,
430,
267,
587,
26,
288,
1568,
275,
284,
975,
8,
83,
59,
19,
5728,
398,
372,
1947,
12,
1568,
339,
347,
485,
1490,
8,
277,
304,
398,
327,
2248,
30262,
1504,
267,
1830,
715,
26,
288,
3268,
275,
291,
14,
3997,
14,
9974,
342,
288,
1947,
12,
1568,
275,
291,
14,
698,
342,
288,
340,
440,
1947,
503,
1947,
508,
334,
24,
12,
1616,
304,
355,
2059,
288,
340,
1568,
26,
355,
1947,
576,
275,
291,
14,
3997,
14,
739,
8,
890,
9,
288,
587,
26,
355,
1947,
576,
275,
488,
288,
340,
1947,
315,
769,
8,
277,
14,
815,
14,
1612,
5109,
355,
340,
1228,
8,
277,
14,
815,
59,
1450,
467,
769,
304,
490,
291,
14,
815,
59,
1450,
1055,
740,
8,
1450,
576,
9,
355,
587,
26,
490,
291,
14,
815,
59,
1450,
61,
275,
359,
277,
14,
815,
59,
1450,
467,
1947,
576,
61,
288,
587,
26,
355,
291,
14,
815,
59,
1450,
61,
275,
1947,
576,
953,
327,
870,
1947,
12,
291,
14,
815,
59,
1450,
61,
398,
327,
818,
267,
9393,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
5212,
30372,
16,
566,
267,
3931,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
5212,
30372,
17,
566,
267,
340,
334,
19,
12,
11738,
9,
315,
291,
14,
815,
26,
288,
1305,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
11738,
30372,
16,
566,
13,
17,
267,
587,
26,
288,
1305,
275,
378,
267,
340,
9393,
508,
413,
436,
440,
3931,
26,
288,
291,
14,
632,
275,
298,
44,
2,
267,
916,
9393,
508,
650,
436,
3931,
26,
288,
291,
14,
632,
275,
298,
12067,
22774,
344,
61,
267,
916,
9393,
508,
841,
436,
3931,
26,
288,
291,
14,
632,
275,
298,
9249,
57,
43,
22774,
344,
61,
398,
327,
1568,
267,
291,
14,
890,
275,
291,
14,
26627,
1332,
19,
12,
3388,
1826,
291,
14,
26627,
1332,
19,
12,
4233,
430,
398,
327,
10291,
267,
862,
26,
288,
10291,
275,
16503,
50,
9577,
59,
277,
14,
26627,
1332,
19,
12,
13960,
10524,
267,
871,
4067,
26,
288,
746,
5925,
480,
5912,
3531,
5708,
1834,
10291,
531,
398,
327,
12835,
267,
340,
1947,
508,
334,
24,
12,
1616,
304,
288,
291,
14,
7172,
275,
10003,
10432,
67,
401,
334,
12849,
12,
3268,
395,
586,
334,
16,
12,
378,
12,
291,
14,
890,
59,
16,
467,
291,
14,
890,
59,
17,
2459,
61,
339,
347,
2248,
8,
277,
304,
398,
340,
822,
8,
277,
14,
7172,
9,
1137,
413,
503,
291,
14,
7172,
59,
16,
1527,
16,
61,
1137,
298,
10432,
67,
582,
288,
372,
6047,
1173,
14,
30636,
14,
912,
8,
277,
9,
398,
730,
12,
12835,
12,
5689,
275,
291,
14,
7172,
59,
16,
61,
398,
2644,
12,
3268,
275,
12835,
398,
291,
14,
3997,
14,
5507,
8
] |
[
199,
3,
710,
2018,
473,
391,
1540,
11243,
14,
199,
3,
2672,
1304,
4,
199,
3,
199,
3,
3531,
5708,
15,
46,
2276,
570,
7252,
199,
3,
199,
3,
7994,
26,
199,
3,
9013,
21,
13,
709,
13,
614,
2717,
257,
18208,
199,
3,
19960,
13,
1644,
13,
1643,
2717,
257,
12762,
379,
1536,
436,
3483,
370,
14937,
199,
3,
14790,
13,
1690,
13,
1085,
2717,
257,
16230,
2312,
280,
541,
67,
815,
5922,
199,
3,
199,
3,
1898,
334,
67,
9,
23580,
491,
2101,
14840,
9013,
23,
13,
15135,
14,
199,
3,
1898,
334,
67,
9,
481,
581,
25844,
491,
725,
72,
9013,
21,
14,
199,
3,
199,
3,
1666,
314,
27781,
570,
367,
2556,
641,
4503,
436,
295,
4972,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
14937,
492,
6047,
12,
6047,
1173,
12,
485,
3008,
199,
646,
747,
199,
646,
5549,
199,
199,
363,
1023,
363,
275,
298,
16,
14,
19,
2,
199,
199,
73,
24,
275,
485,
3008,
14,
73,
24,
199,
73,
975,
275,
485,
3008,
14,
73,
975,
1235,
199,
73,
708,
275,
485,
3008,
14,
73,
708,
1235,
199,
79,
24,
275,
485,
3008,
14,
79,
24,
199,
199,
30193,
275,
469,
272,
413,
26,
298,
1773,
401,
272,
959,
26,
298,
14230,
2,
199,
93,
199,
199,
32420,
275,
312,
24,
8,
16,
9,
627,
841,
421,
199,
3,
199,
3,
11642,
83,
199,
199,
318,
284,
8,
67,
304,
272,
372,
284,
708,
1332,
32420,
435,
286,
15786,
20,
5728,
421,
199,
318,
5461,
8,
67,
304,
272,
367,
284,
315,
286,
26,
267,
870,
3647,
996,
88,
2,
450,
284,
24,
8,
73,
395,
1284,
534,
5320,
272,
870,
342,
421,
199,
309,
199,
3,
6047,
3589,
367,
3531,
5708,
15,
46,
2276,
666,
11231,
14,
221,
4005,
1586,
3531,
5708,
15,
46,
2276,
1504,
199,
3,
687,
377,
24150,
436,
1603,
17557,
1584,
12,
675,
314,
665,
66,
30,
303,
280,
541,
67,
815,
1108,
66,
30,
805,
14,
199,
199,
533,
473,
541,
67,
30636,
8,
30636,
14,
30636,
304,
339,
1475,
275,
298,
4385,
35,
2,
272,
1475,
63,
1802,
275,
298,
4385,
35,
15,
46,
2276,
2,
339,
347,
664,
442,
8,
277,
12,
790,
304,
267,
372,
284,
8,
277,
14,
815,
59,
498,
566,
339,
347,
901,
8,
277,
304,
267,
327,
267,
327,
664,
282,
3531,
5708,
901,
1406,
267,
308,
275,
291,
14,
3997,
14,
739,
8,
21,
9,
267,
340,
440,
822,
8,
83,
304,
288,
372,
488,
12,
378,
398,
1947,
275,
284,
24,
8,
83,
59,
17,
2522,
284,
24,
8,
83,
59,
18,
566,
398,
327,
6302,
267,
340,
284,
24,
8,
83,
59,
16,
566,
1137,
378,
88,
17,
35,
503,
1947,
59,
16,
61,
665,
413,
503,
1947,
59,
16,
61,
690,
1749,
26,
288,
746,
12053,
480,
3197,
3531,
5708,
15,
46,
2276,
570,
531,
398,
327,
901,
1568,
267,
1568,
275,
284,
24,
8,
83,
59,
19,
566,
267,
340,
1568,
690,
27207,
26,
288,
746,
5925,
480,
23375,
901,
2582,
315,
3531,
5708,
15,
46,
2276,
570,
531,
267,
916,
1568,
508,
7960,
26,
288,
1568,
275,
378,
267,
916,
1568,
690,
7960,
26,
288,
1568,
275,
284,
8,
277,
14,
3997,
14,
739,
8,
890,
13,
3933,
430,
267,
587,
26,
288,
1568,
275,
284,
975,
8,
83,
59,
19,
5728,
398,
372,
1947,
12,
1568,
339,
347,
485,
1490,
8,
277,
304,
398,
327,
2248,
30262,
1504,
267,
1830,
715,
26,
288,
3268,
275,
291,
14,
3997,
14,
9974,
342,
288,
1947,
12,
1568,
275,
291,
14,
698,
342,
288,
340,
440,
1947,
503,
1947,
508,
334,
24,
12,
1616,
304,
355,
2059,
288,
340,
1568,
26,
355,
1947,
576,
275,
291,
14,
3997,
14,
739,
8,
890,
9,
288,
587,
26,
355,
1947,
576,
275,
488,
288,
340,
1947,
315,
769,
8,
277,
14,
815,
14,
1612,
5109,
355,
340,
1228,
8,
277,
14,
815,
59,
1450,
467,
769,
304,
490,
291,
14,
815,
59,
1450,
1055,
740,
8,
1450,
576,
9,
355,
587,
26,
490,
291,
14,
815,
59,
1450,
61,
275,
359,
277,
14,
815,
59,
1450,
467,
1947,
576,
61,
288,
587,
26,
355,
291,
14,
815,
59,
1450,
61,
275,
1947,
576,
953,
327,
870,
1947,
12,
291,
14,
815,
59,
1450,
61,
398,
327,
818,
267,
9393,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
5212,
30372,
16,
566,
267,
3931,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
5212,
30372,
17,
566,
267,
340,
334,
19,
12,
11738,
9,
315,
291,
14,
815,
26,
288,
1305,
275,
284,
24,
8,
277,
14,
815,
7528,
19,
12,
11738,
30372,
16,
566,
13,
17,
267,
587,
26,
288,
1305,
275,
378,
267,
340,
9393,
508,
413,
436,
440,
3931,
26,
288,
291,
14,
632,
275,
298,
44,
2,
267,
916,
9393,
508,
650,
436,
3931,
26,
288,
291,
14,
632,
275,
298,
12067,
22774,
344,
61,
267,
916,
9393,
508,
841,
436,
3931,
26,
288,
291,
14,
632,
275,
298,
9249,
57,
43,
22774,
344,
61,
398,
327,
1568,
267,
291,
14,
890,
275,
291,
14,
26627,
1332,
19,
12,
3388,
1826,
291,
14,
26627,
1332,
19,
12,
4233,
430,
398,
327,
10291,
267,
862,
26,
288,
10291,
275,
16503,
50,
9577,
59,
277,
14,
26627,
1332,
19,
12,
13960,
10524,
267,
871,
4067,
26,
288,
746,
5925,
480,
5912,
3531,
5708,
1834,
10291,
531,
398,
327,
12835,
267,
340,
1947,
508,
334,
24,
12,
1616,
304,
288,
291,
14,
7172,
275,
10003,
10432,
67,
401,
334,
12849,
12,
3268,
395,
586,
334,
16,
12,
378,
12,
291,
14,
890,
59,
16,
467,
291,
14,
890,
59,
17,
2459,
61,
339,
347,
2248,
8,
277,
304,
398,
340,
822,
8,
277,
14,
7172,
9,
1137,
413,
503,
291,
14,
7172,
59,
16,
1527,
16,
61,
1137,
298,
10432,
67,
582,
288,
372,
6047,
1173,
14,
30636,
14,
912,
8,
277,
9,
398,
730,
12,
12835,
12,
5689,
275,
291,
14,
7172,
59,
16,
61,
398,
2644,
12,
3268,
275,
12835,
398,
291,
14,
3997,
14,
5507,
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,
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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
] |
louietsai/python-for-android
|
python-modules/twisted/twisted/conch/test/test_openssh_compat.py
|
60
|
3381
|
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.conch.openssh_compat}.
"""
import os
from twisted.trial.unittest import TestCase
from twisted.python.filepath import FilePath
from twisted.python.compat import set
try:
import Crypto.Cipher.DES3
import pyasn1
except ImportError:
OpenSSHFactory = None
else:
from twisted.conch.openssh_compat.factory import OpenSSHFactory
from twisted.conch.test import keydata
from twisted.test.test_process import MockOS
class OpenSSHFactoryTests(TestCase):
"""
Tests for L{OpenSSHFactory}.
"""
if getattr(os, "geteuid", None) is None:
skip = "geteuid/seteuid not available"
elif OpenSSHFactory is None:
skip = "Cannot run without PyCrypto or PyASN1"
def setUp(self):
self.factory = OpenSSHFactory()
self.keysDir = FilePath(self.mktemp())
self.keysDir.makedirs()
self.factory.dataRoot = self.keysDir.path
self.keysDir.child("ssh_host_foo").setContent("foo")
self.keysDir.child("bar_key").setContent("foo")
self.keysDir.child("ssh_host_one_key").setContent(
keydata.privateRSA_openssh)
self.keysDir.child("ssh_host_two_key").setContent(
keydata.privateDSA_openssh)
self.keysDir.child("ssh_host_three_key").setContent(
"not a key content")
self.keysDir.child("ssh_host_one_key.pub").setContent(
keydata.publicRSA_openssh)
self.mockos = MockOS()
self.patch(os, "seteuid", self.mockos.seteuid)
self.patch(os, "setegid", self.mockos.setegid)
def test_getPublicKeys(self):
"""
L{OpenSSHFactory.getPublicKeys} should return the available public keys
in the data directory
"""
keys = self.factory.getPublicKeys()
self.assertEquals(len(keys), 1)
keyTypes = keys.keys()
self.assertEqual(keyTypes, ['ssh-rsa'])
def test_getPrivateKeys(self):
"""
L{OpenSSHFactory.getPrivateKeys} should return the available private
keys in the data directory.
"""
keys = self.factory.getPrivateKeys()
self.assertEquals(len(keys), 2)
keyTypes = keys.keys()
self.assertEqual(set(keyTypes), set(['ssh-rsa', 'ssh-dss']))
self.assertEquals(self.mockos.seteuidCalls, [])
self.assertEquals(self.mockos.setegidCalls, [])
def test_getPrivateKeysAsRoot(self):
"""
L{OpenSSHFactory.getPrivateKeys} should switch to root if the keys
aren't readable by the current user.
"""
keyFile = self.keysDir.child("ssh_host_two_key")
# Fake permission error by changing the mode
keyFile.chmod(0000)
self.addCleanup(keyFile.chmod, 0777)
# And restore the right mode when seteuid is called
savedSeteuid = os.seteuid
def seteuid(euid):
keyFile.chmod(0777)
return savedSeteuid(euid)
self.patch(os, "seteuid", seteuid)
keys = self.factory.getPrivateKeys()
self.assertEquals(len(keys), 2)
keyTypes = keys.keys()
self.assertEqual(set(keyTypes), set(['ssh-rsa', 'ssh-dss']))
self.assertEquals(self.mockos.seteuidCalls, [0, os.geteuid()])
self.assertEquals(self.mockos.setegidCalls, [0, os.getegid()])
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
12521,
13,
9300,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
388,
335,
14,
1490,
5510,
63,
5819,
5565,
199,
624,
199,
199,
646,
747,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1548,
14,
7218,
492,
27961,
199,
504,
7390,
14,
1548,
14,
5819,
492,
663,
199,
199,
893,
26,
272,
492,
18855,
14,
21967,
14,
4448,
19,
272,
492,
1134,
6228,
17,
199,
2590,
3545,
26,
272,
3232,
13716,
2927,
275,
488,
199,
2836,
26,
272,
687,
7390,
14,
388,
335,
14,
1490,
5510,
63,
5819,
14,
3702,
492,
3232,
13716,
2927,
199,
199,
504,
7390,
14,
388,
335,
14,
396,
492,
790,
576,
199,
504,
7390,
14,
396,
14,
396,
63,
1412,
492,
4420,
3100,
421,
199,
533,
3232,
13716,
2927,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
4299,
13716,
2927,
5565,
272,
408,
272,
340,
2519,
8,
736,
12,
298,
31508,
1535,
401,
488,
9,
365,
488,
26,
267,
3372,
275,
298,
31508,
1535,
15,
30563,
1535,
440,
2808,
2,
272,
916,
3232,
13716,
2927,
365,
488,
26,
267,
3372,
275,
298,
6612,
1255,
1928,
1611,
17134,
503,
1611,
21696,
17,
2,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3702,
275,
3232,
13716,
2927,
342,
267,
291,
14,
1612,
3567,
275,
27961,
8,
277,
14,
22136,
1012,
267,
291,
14,
1612,
3567,
14,
8347,
342,
267,
291,
14,
3702,
14,
576,
6405,
275,
291,
14,
1612,
3567,
14,
515,
398,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
1421,
3471,
28680,
480,
1421,
531,
267,
291,
14,
1612,
3567,
14,
1739,
480,
1700,
63,
498,
3471,
28680,
480,
1421,
531,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
368,
63,
498,
3471,
28680,
8,
288,
790,
576,
14,
4239,
12115,
63,
1490,
5510,
9,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
5601,
63,
498,
3471,
28680,
8,
288,
790,
576,
14,
4239,
23007,
63,
1490,
5510,
9,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
10480,
63,
498,
3471,
28680,
8,
288,
298,
1397,
282,
790,
1564,
531,
398,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
368,
63,
498,
14,
5645,
3471,
28680,
8,
288,
790,
576,
14,
3455,
12115,
63,
1490,
5510,
9,
398,
291,
14,
1805,
736,
275,
4420,
3100,
342,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
1535,
401,
291,
14,
1805,
736,
14,
30563,
1535,
9,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
8787,
401,
291,
14,
1805,
736,
14,
30563,
8787,
9,
2378,
347,
511,
63,
362,
9885,
6340,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
9885,
6340,
93,
1077,
372,
314,
2808,
4575,
2883,
267,
315,
314,
666,
2082,
267,
408,
267,
2883,
275,
291,
14,
3702,
14,
362,
9885,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
413,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
498,
4100,
12,
788,
5510,
13,
13487,
1105,
2378,
347,
511,
63,
362,
12185,
6340,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
12185,
6340,
93,
1077,
372,
314,
2808,
5726,
267,
2883,
315,
314,
666,
2082,
14,
267,
408,
267,
2883,
275,
291,
14,
3702,
14,
362,
12185,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
499,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
409,
8,
498,
4100,
395,
663,
2941,
5510,
13,
13487,
297,
283,
5510,
13,
68,
385,
5156,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
1535,
18287,
12,
3073,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
8787,
18287,
12,
3073,
2378,
347,
511,
63,
362,
12185,
6340,
2822,
6405,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
12185,
6340,
93,
1077,
6258,
370,
1738,
340,
314,
2883,
267,
10621,
1133,
12701,
701,
314,
1453,
922,
14,
267,
408,
267,
790,
1173,
275,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
5601,
63,
498,
531,
267,
327,
7777,
4983,
1125,
701,
13729,
314,
818,
267,
790,
1173,
14,
11693,
8,
993,
9,
267,
291,
14,
12808,
8,
498,
1173,
14,
11693,
12,
378,
11956,
9,
267,
327,
6061,
9066,
314,
2451,
818,
1380,
542,
266,
1535,
365,
2797,
267,
6290,
1513,
266,
1535,
275,
747,
14,
30563,
1535,
267,
347,
542,
266,
1535,
8,
69,
1535,
304,
288,
790,
1173,
14,
11693,
8,
16,
11956,
9,
288,
372,
6290,
1513,
266,
1535,
8,
69,
1535,
9,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
1535,
401,
542,
266,
1535,
9,
267,
2883,
275,
291,
14,
3702,
14,
362,
12185,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
499,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
409,
8,
498,
4100,
395,
663,
2941,
5510,
13,
13487,
297,
283,
5510,
13,
68,
385,
5156,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
1535,
18287,
12,
359,
16,
12,
747,
14,
31508,
1535,
9383,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
8787,
18287,
12,
359,
16,
12,
747,
14,
31508,
8787,
9383,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
12521,
13,
9300,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
388,
335,
14,
1490,
5510,
63,
5819,
5565,
199,
624,
199,
199,
646,
747,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1548,
14,
7218,
492,
27961,
199,
504,
7390,
14,
1548,
14,
5819,
492,
663,
199,
199,
893,
26,
272,
492,
18855,
14,
21967,
14,
4448,
19,
272,
492,
1134,
6228,
17,
199,
2590,
3545,
26,
272,
3232,
13716,
2927,
275,
488,
199,
2836,
26,
272,
687,
7390,
14,
388,
335,
14,
1490,
5510,
63,
5819,
14,
3702,
492,
3232,
13716,
2927,
199,
199,
504,
7390,
14,
388,
335,
14,
396,
492,
790,
576,
199,
504,
7390,
14,
396,
14,
396,
63,
1412,
492,
4420,
3100,
421,
199,
533,
3232,
13716,
2927,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
4299,
13716,
2927,
5565,
272,
408,
272,
340,
2519,
8,
736,
12,
298,
31508,
1535,
401,
488,
9,
365,
488,
26,
267,
3372,
275,
298,
31508,
1535,
15,
30563,
1535,
440,
2808,
2,
272,
916,
3232,
13716,
2927,
365,
488,
26,
267,
3372,
275,
298,
6612,
1255,
1928,
1611,
17134,
503,
1611,
21696,
17,
2,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
3702,
275,
3232,
13716,
2927,
342,
267,
291,
14,
1612,
3567,
275,
27961,
8,
277,
14,
22136,
1012,
267,
291,
14,
1612,
3567,
14,
8347,
342,
267,
291,
14,
3702,
14,
576,
6405,
275,
291,
14,
1612,
3567,
14,
515,
398,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
1421,
3471,
28680,
480,
1421,
531,
267,
291,
14,
1612,
3567,
14,
1739,
480,
1700,
63,
498,
3471,
28680,
480,
1421,
531,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
368,
63,
498,
3471,
28680,
8,
288,
790,
576,
14,
4239,
12115,
63,
1490,
5510,
9,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
5601,
63,
498,
3471,
28680,
8,
288,
790,
576,
14,
4239,
23007,
63,
1490,
5510,
9,
267,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
10480,
63,
498,
3471,
28680,
8,
288,
298,
1397,
282,
790,
1564,
531,
398,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
368,
63,
498,
14,
5645,
3471,
28680,
8,
288,
790,
576,
14,
3455,
12115,
63,
1490,
5510,
9,
398,
291,
14,
1805,
736,
275,
4420,
3100,
342,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
1535,
401,
291,
14,
1805,
736,
14,
30563,
1535,
9,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
8787,
401,
291,
14,
1805,
736,
14,
30563,
8787,
9,
2378,
347,
511,
63,
362,
9885,
6340,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
9885,
6340,
93,
1077,
372,
314,
2808,
4575,
2883,
267,
315,
314,
666,
2082,
267,
408,
267,
2883,
275,
291,
14,
3702,
14,
362,
9885,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
413,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
498,
4100,
12,
788,
5510,
13,
13487,
1105,
2378,
347,
511,
63,
362,
12185,
6340,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
12185,
6340,
93,
1077,
372,
314,
2808,
5726,
267,
2883,
315,
314,
666,
2082,
14,
267,
408,
267,
2883,
275,
291,
14,
3702,
14,
362,
12185,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
499,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
409,
8,
498,
4100,
395,
663,
2941,
5510,
13,
13487,
297,
283,
5510,
13,
68,
385,
5156,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
1535,
18287,
12,
3073,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
8787,
18287,
12,
3073,
2378,
347,
511,
63,
362,
12185,
6340,
2822,
6405,
8,
277,
304,
267,
408,
267,
491,
91,
4299,
13716,
2927,
14,
362,
12185,
6340,
93,
1077,
6258,
370,
1738,
340,
314,
2883,
267,
10621,
1133,
12701,
701,
314,
1453,
922,
14,
267,
408,
267,
790,
1173,
275,
291,
14,
1612,
3567,
14,
1739,
480,
5510,
63,
1102,
63,
5601,
63,
498,
531,
267,
327,
7777,
4983,
1125,
701,
13729,
314,
818,
267,
790,
1173,
14,
11693,
8,
993,
9,
267,
291,
14,
12808,
8,
498,
1173,
14,
11693,
12,
378,
11956,
9,
267,
327,
6061,
9066,
314,
2451,
818,
1380,
542,
266,
1535,
365,
2797,
267,
6290,
1513,
266,
1535,
275,
747,
14,
30563,
1535,
267,
347,
542,
266,
1535,
8,
69,
1535,
304,
288,
790,
1173,
14,
11693,
8,
16,
11956,
9,
288,
372,
6290,
1513,
266,
1535,
8,
69,
1535,
9,
267,
291,
14,
2068,
8,
736,
12,
298,
30563,
1535,
401,
542,
266,
1535,
9,
267,
2883,
275,
291,
14,
3702,
14,
362,
12185,
6340,
342,
267,
291,
14,
2947,
8,
552,
8,
1612,
395,
499,
9,
267,
790,
4100,
275,
2883,
14,
1612,
342,
267,
291,
14,
629,
8,
409,
8,
498,
4100,
395,
663,
2941,
5510,
13,
13487,
297,
283,
5510,
13,
68,
385,
5156,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
1535,
18287,
12,
359,
16,
12,
747,
14,
31508,
1535,
9383,
267,
291,
14,
2947,
8,
277,
14,
1805,
736,
14,
30563,
8787,
18287,
12,
359,
16,
12,
747,
14,
31508,
8787,
9383,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0
] |
mag6367/Cracking_the_Coding_Interview_Python_Solutions
|
chapter2/quest2_4.py
|
1
|
1881
|
# question 2.4 from cracking the code interview 4th ed.
# Look at LinkedList.py to understand the implementation of Linked List
'''
You have two numbers represented by a linked list, where each node contains a single digit.
The digits are stored in reverse order, such that the 1’s digit is at the head of the list.
Write a function that adds the two numbers and returns the sum as a linked list.
EXAMPLE
Input: (3 -> 1 -> 5), (5 -> 9 -> 2)
Output: 8 -> 0 -> 8
'''
# This is a really interesting problem that takes numerous steps to solve
# We will need to implement a Queue data structure because of the way the numbers are arranged in LL
# stacks module is in this directory
from stacks import Stack
from linkedList import LinkedList
def addLinkedLists (LinkedList1, LinkedList2):
# First we need to add the values to a queue in order to sum them
queue1 = Queue()
current1 = LinkedList1.head
while current1:
queue1.enqueue(current1.data)
current1 = current1.next
queue2 = Queue()
current2 = LinkedList2.head
while current2:
queue2.enqueue(current2.data)
current2 = current2.next
# Now we need to add the numbers in reverse times 10^n
sumValues = 0
exp = 0
while not queue1.isEmpty() or not queue2.isEmpty():
sumValues += (queue1.dequeue() + queue2.dequeue()) * (10 ** exp)
exp += 1
print(sumValues)
# The answer is actually sumValues reversed
finalAnswer = 0
if sumValues < 0: # because we are using string slice [::-1] operator to reverse, we need to check if negative
sumValues = abs(sumValues)
finalAnswer = int(str(sumValues)[::-1]) * -1
else:
finalAnswer = int(str(sumValues)[::-1])
# Finally, we need to create a new linked List with the digits in order and return it
finalList = LinkedList()
while finalAnswer / 10 > 0:
finalList.insertLast(finalAnswer % 10)
finalAnswer = finalAnswer // 10
return finalList
|
mit
|
[
3,
7894,
499,
14,
20,
687,
286,
8085,
316,
314,
1233,
1640,
1345,
841,
273,
3988,
14,
199,
3,
12077,
737,
10967,
379,
1296,
14,
647,
370,
20647,
314,
4514,
402,
10967,
379,
3820,
199,
2344,
199,
5556,
1172,
2877,
5579,
11159,
701,
282,
10632,
769,
12,
2382,
1924,
1031,
3509,
282,
2849,
10964,
14,
221,
199,
1918,
7576,
787,
5489,
315,
3837,
1865,
12,
4066,
626,
314,
413,
21045,
83,
10964,
365,
737,
314,
4854,
402,
314,
769,
14,
199,
3534,
282,
805,
626,
9584,
314,
2877,
5579,
436,
2529,
314,
3089,
465,
282,
10632,
769,
14,
199,
26900,
199,
3205,
26,
334,
19,
1035,
413,
1035,
959,
395,
334,
21,
1035,
1749,
1035,
499,
9,
199,
2959,
26,
1695,
1035,
378,
1035,
1695,
199,
2344,
199,
199,
3,
961,
365,
282,
7710,
19604,
5160,
626,
6181,
10330,
293,
527,
7124,
370,
14241,
199,
3,
2136,
911,
1929,
370,
5669,
282,
10703,
666,
5523,
2952,
402,
314,
4340,
314,
5579,
787,
601,
1842,
68,
315,
491,
44,
199,
3,
26733,
859,
365,
315,
642,
2082,
221,
199,
504,
26733,
492,
13894,
199,
504,
10632,
1296,
492,
10967,
379,
1296,
221,
421,
199,
318,
1050,
26748,
15116,
334,
26748,
1296,
17,
12,
10967,
379,
1296,
18,
304,
199,
198,
3,
7758,
781,
1929,
370,
1050,
314,
1338,
370,
282,
4126,
315,
1865,
370,
3089,
3062,
199,
198,
1825,
17,
275,
10703,
342,
199,
198,
1818,
17,
275,
10967,
379,
1296,
17,
14,
2993,
199,
198,
6710,
1453,
17,
26,
507,
198,
1825,
17,
14,
12456,
8,
1818,
17,
14,
576,
9,
507,
198,
1818,
17,
275,
1453,
17,
14,
2184,
421,
198,
1825,
18,
275,
10703,
342,
199,
198,
1818,
18,
275,
10967,
379,
1296,
18,
14,
2993,
199,
198,
6710,
1453,
18,
26,
507,
198,
1825,
18,
14,
12456,
8,
1818,
18,
14,
576,
9,
507,
198,
1818,
18,
275,
1453,
18,
14,
2184,
4388,
198,
3,
7356,
781,
1929,
370,
1050,
314,
5579,
315,
3837,
5431,
1616,
62,
78,
199,
198,
1838,
6550,
275,
378,
199,
198,
1474,
275,
378,
199,
198,
6710,
440,
4126,
17,
14,
374,
4699,
342,
503,
440,
4126,
18,
14,
374,
4699,
837,
507,
198,
1838,
6550,
847,
334,
1825,
17,
14,
18522,
342,
435,
4126,
18,
14,
18522,
1012,
627,
334,
709,
1011,
1437,
9,
507,
198,
1474,
847,
413,
507,
198,
1361,
8,
1838,
6550,
9,
4388,
198,
3,
710,
6385,
365,
5965,
3089,
6550,
10822,
9948,
198,
5094,
19104,
275,
378,
199,
198,
692,
3089,
6550,
665,
378,
26,
221,
327,
2952,
781,
787,
1808,
1059,
6014,
359,
21123,
17,
61,
4182,
370,
3837,
12,
781,
1929,
370,
1104,
340,
6946,
507,
198,
1838,
6550,
275,
2853,
8,
1838,
6550,
9,
507,
198,
5094,
19104,
275,
1109,
8,
495,
8,
1838,
6550,
2788,
21123,
17,
566,
627,
446,
17,
199,
198,
2836,
26,
507,
198,
5094,
19104,
275,
1109,
8,
495,
8,
1838,
6550,
2788,
21123,
17,
566,
421,
198,
3,
19177,
12,
781,
1929,
370,
1218,
282,
892,
10632,
3820,
543,
314,
7576,
315,
1865,
436,
372,
652,
199,
198,
5094,
1296,
275,
10967,
379,
1296,
342,
421,
198,
6710,
4242,
19104,
1182,
1616,
690,
378,
26,
507,
198,
5094,
1296,
14,
3176,
6090,
8,
5094,
19104,
450,
1616,
9,
507,
198,
5094,
19104,
275,
4242,
19104,
5001,
1616,
421,
198,
1107,
4242,
1296,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7894,
499,
14,
20,
687,
286,
8085,
316,
314,
1233,
1640,
1345,
841,
273,
3988,
14,
199,
3,
12077,
737,
10967,
379,
1296,
14,
647,
370,
20647,
314,
4514,
402,
10967,
379,
3820,
199,
2344,
199,
5556,
1172,
2877,
5579,
11159,
701,
282,
10632,
769,
12,
2382,
1924,
1031,
3509,
282,
2849,
10964,
14,
221,
199,
1918,
7576,
787,
5489,
315,
3837,
1865,
12,
4066,
626,
314,
413,
21045,
83,
10964,
365,
737,
314,
4854,
402,
314,
769,
14,
199,
3534,
282,
805,
626,
9584,
314,
2877,
5579,
436,
2529,
314,
3089,
465,
282,
10632,
769,
14,
199,
26900,
199,
3205,
26,
334,
19,
1035,
413,
1035,
959,
395,
334,
21,
1035,
1749,
1035,
499,
9,
199,
2959,
26,
1695,
1035,
378,
1035,
1695,
199,
2344,
199,
199,
3,
961,
365,
282,
7710,
19604,
5160,
626,
6181,
10330,
293,
527,
7124,
370,
14241,
199,
3,
2136,
911,
1929,
370,
5669,
282,
10703,
666,
5523,
2952,
402,
314,
4340,
314,
5579,
787,
601,
1842,
68,
315,
491,
44,
199,
3,
26733,
859,
365,
315,
642,
2082,
221,
199,
504,
26733,
492,
13894,
199,
504,
10632,
1296,
492,
10967,
379,
1296,
221,
421,
199,
318,
1050,
26748,
15116,
334,
26748,
1296,
17,
12,
10967,
379,
1296,
18,
304,
199,
198,
3,
7758,
781,
1929,
370,
1050,
314,
1338,
370,
282,
4126,
315,
1865,
370,
3089,
3062,
199,
198,
1825,
17,
275,
10703,
342,
199,
198,
1818,
17,
275,
10967,
379,
1296,
17,
14,
2993,
199,
198,
6710,
1453,
17,
26,
507,
198,
1825,
17,
14,
12456,
8,
1818,
17,
14,
576,
9,
507,
198,
1818,
17,
275,
1453,
17,
14,
2184,
421,
198,
1825,
18,
275,
10703,
342,
199,
198,
1818,
18,
275,
10967,
379,
1296,
18,
14,
2993,
199,
198,
6710,
1453,
18,
26,
507,
198,
1825,
18,
14,
12456,
8,
1818,
18,
14,
576,
9,
507,
198,
1818,
18,
275,
1453,
18,
14,
2184,
4388,
198,
3,
7356,
781,
1929,
370,
1050,
314,
5579,
315,
3837,
5431,
1616,
62,
78,
199,
198,
1838,
6550,
275,
378,
199,
198,
1474,
275,
378,
199,
198,
6710,
440,
4126,
17,
14,
374,
4699,
342,
503,
440,
4126,
18,
14,
374,
4699,
837,
507,
198,
1838,
6550,
847,
334,
1825,
17,
14,
18522,
342,
435,
4126,
18,
14,
18522,
1012,
627,
334,
709,
1011,
1437,
9,
507,
198,
1474,
847,
413,
507,
198,
1361,
8,
1838,
6550,
9,
4388,
198,
3,
710,
6385,
365,
5965,
3089,
6550,
10822,
9948,
198,
5094,
19104,
275,
378,
199,
198,
692,
3089,
6550,
665,
378,
26,
221,
327,
2952,
781,
787,
1808,
1059,
6014,
359,
21123,
17,
61,
4182,
370,
3837,
12,
781,
1929,
370,
1104,
340,
6946,
507,
198,
1838,
6550,
275,
2853,
8,
1838,
6550,
9,
507,
198,
5094,
19104,
275,
1109,
8,
495,
8,
1838,
6550,
2788,
21123,
17,
566,
627,
446,
17,
199,
198,
2836,
26,
507,
198,
5094,
19104,
275,
1109,
8,
495,
8,
1838,
6550,
2788,
21123,
17,
566,
421,
198,
3,
19177,
12,
781,
1929,
370,
1218,
282,
892,
10632,
3820,
543,
314,
7576,
315,
1865,
436,
372,
652,
199,
198,
5094,
1296,
275,
10967,
379,
1296,
342,
421,
198,
6710,
4242,
19104,
1182,
1616,
690,
378,
26,
507,
198,
5094,
1296,
14,
3176,
6090,
8,
5094,
19104,
450,
1616,
9,
507,
198,
5094,
19104,
275,
4242,
19104,
5001,
1616,
421,
198,
1107,
4242,
1296,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
UASLab/ImageAnalysis
|
video/archive/deprecated_cam_calib.py
|
1
|
3390
|
import numpy as np
# set camera calibration from some hard coded options
def set_camera_calibration(value):
if value == 0:
name = "Mobius 1920x1080 (Curt)"
K = np.array( [[1362.1, 0.0, 980.8],
[ 0.0, 1272.8, 601.3],
[ 0.0, 0.0, 1.0]] )
dist = [-0.36207197, 0.14627927, -0.00674558, 0.0008926, -0.02635695]
elif value == 1:
name = "Mobius 1920x1080 (UMN 002)"
K = np.array( [[983.02, 0., 939.97982344],
[ 0., 984.37 , 483.59345072],
[ 0., 0., 1. ]] )
dist = [-0.37987874, 0.2016648, -0.00027986, -0.00000415, -0.06917004]
elif value == 2:
name = "Mobius 1920x1080 (UMN 003)"
K = np.array( [[ 1401.21111735, 0. , 904.25404757],
[ 0. , 1400.2530882, 490.12157373],
[ 0. , 0. , 1. ]] )
dist = [-0.39012303, 0.19687255, -0.00069657, 0.00465592, -0.05845262]
elif value == 3:
name = "RunCamHD2 1920x1080 (Curt)"
K = np.array( [[ 971.96149426, 0. , 957.46750602],
[ 0. , 971.67133264, 516.50578382],
[ 0. , 0. , 1. ]] )
dist = [-0.26910665, 0.10580125, 0.00048417, 0.00000925, -0.02321387]
elif value == 4:
name = "RunCamHD2 1920x1440 (Curt)"
K = np.array( [[ 1296.11187055, 0. , 955.43024994],
[ 0. , 1296.01457451, 691.47053988],
[ 0. , 0. , 1. ]] )
dist = [-0.28250371, 0.14064665, 0.00061846, 0.00014488, -0.05106045]
elif value == 5:
name = "RunCamHD2 1920x1440 (UMN)"
K = np.array( [[ 1300.21142205, 0. , 905.34625643],
[ 0. , 1299.95340627, 675.19425751],
[ 0. , 0. , 1. ]] )
dist = [-0.2804515, 0.13299211, 0.00211206, 0.00128484, -0.04957892]
elif value == 6:
name = "Sony A6000 SEL20F28 (still shot)"
# calibrated with 96 still shots
K = np.array( [[ 5405.06334404, 0. , 2794.37314413],
[ 0. , 5411.68843156, 2141.95772584],
[ 0. , 0. , 1. ]] )
dist = [-0.16982874, 0.00414135, 0.00025503, 0.00259518, 0.04215282]
elif value == 7:
name = "Sony A6000 SEL20F28 (movie mode)"
K = np.array( [[ 1684.73041209, 0. , 943.23763223],
[ 0. , 1683.14718211, 545.48606484],
[ 0. , 0. , 1. ]] )
dist = [-0.17650495, 0.19188425, 0.00157936, -0.00020868, -0.06309823]
elif value == 8:
name = "Mobius 1280x720 (Matt)"
K = np.array( [[ 1713.27, 0.0, 651.4],
[ 0.0, 1714.36, 338.2],
[ 0.0, 0.0, 1.0]] )
dist = [-0.43730502, 1.1380363, -0.00389018, -0.00234571, -4.34796866]
else:
print "unknown camera"
name = "None"
K = None
dist = None
return name, K, dist
|
mit
|
[
646,
2680,
465,
980,
199,
199,
3,
663,
15177,
25365,
687,
2005,
7508,
1233,
68,
1511,
199,
318,
663,
63,
11928,
63,
25851,
8,
585,
304,
272,
340,
574,
508,
378,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
969,
2789,
14,
17,
12,
259,
378,
14,
16,
12,
1749,
1257,
14,
24,
467,
2432,
359,
257,
378,
14,
16,
12,
12792,
18,
14,
24,
12,
1227,
614,
14,
19,
467,
2432,
359,
257,
378,
14,
16,
12,
259,
378,
14,
16,
12,
257,
413,
14,
16,
2677,
776,
267,
2917,
275,
5243,
16,
14,
1344,
10744,
11165,
12,
378,
14,
11432,
12987,
1465,
12,
446,
16,
14,
8010,
1342,
17686,
12,
378,
14,
1493,
1407,
1479,
12,
446,
16,
14,
14842,
1276,
20017,
61,
272,
916,
574,
508,
413,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
2639,
46,
378,
996,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
25,
2658,
14,
996,
12,
257,
378,
2020,
260,
1749,
1355,
14,
31955,
2564,
10875,
467,
1993,
359,
221,
378,
2020,
260,
1749,
1349,
14,
1401,
2360,
841,
2658,
14,
1427,
1082,
1400,
2819,
467,
1993,
359,
221,
378,
2020,
3698,
378,
2020,
3698,
413,
14,
263,
1622,
61,
776,
398,
2917,
275,
5243,
16,
14,
12015,
14681,
1342,
12,
221,
378,
14,
9261,
10552,
12,
221,
446,
16,
14,
9425,
1965,
1184,
12,
446,
16,
14,
993,
966,
1046,
12,
446,
16,
14,
18264,
1196,
7979,
61,
272,
916,
574,
508,
499,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
2639,
46,
378,
1644,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
4329,
614,
14,
18,
6984,
31327,
12,
258,
378,
14,
755,
2360,
259,
1749,
966,
14,
821,
5188,
32339,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
4329,
383,
14,
821,
1216,
19119,
12,
259,
841,
2710,
14,
713,
10823,
14539,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
755,
2360,
420,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1355,
614,
9687,
19,
12,
221,
378,
14,
10800,
1555,
2299,
12,
446,
16,
14,
1493,
15154,
1641,
12,
221,
378,
14,
383,
2466,
1229,
2942,
12,
446,
16,
14,
1717,
16963,
14820,
61,
272,
916,
574,
508,
650,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
23514,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
1749,
3172,
14,
2534,
1079,
2635,
1479,
12,
257,
378,
14,
263,
2360,
1749,
1641,
14,
16226,
13725,
996,
467,
2432,
359,
257,
378,
14,
263,
2360,
1749,
3172,
14,
1822,
969,
708,
772,
12,
959,
975,
14,
1400,
14992,
16244,
467,
2432,
359,
257,
378,
14,
263,
2360,
257,
378,
14,
263,
2360,
257,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
12442,
709,
16373,
12,
378,
14,
709,
2010,
614,
821,
12,
378,
14,
16643,
1349,
1196,
12,
378,
14,
993,
1643,
821,
12,
446,
16,
14,
996,
708,
969,
1555,
61,
272,
916,
574,
508,
841,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
1079,
2167,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
413,
11700,
14,
845,
1085,
2760,
1229,
12,
258,
378,
14,
263,
2360,
257,
1749,
1229,
14,
2824,
5284,
14966,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
413,
11700,
14,
614,
2322,
1342,
2869,
12,
257,
1227,
3328,
14,
2417,
1717,
1355,
1299,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1651,
7991,
16124,
12,
378,
14,
10037,
772,
16373,
12,
378,
14,
20965,
1085,
2466,
12,
378,
14,
4183,
1602,
1299,
12,
446,
16,
14,
1717,
7357,
12618,
61,
272,
916,
574,
508,
959,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
1079,
2167,
334,
2639,
46,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
4944,
383,
14,
18,
7636,
1081,
1717,
12,
258,
378,
14,
263,
2360,
257,
1749,
1717,
14,
12583,
821,
14637,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
3144,
1020,
14,
2720,
1082,
1690,
1465,
12,
257,
1227,
2194,
14,
10860,
821,
24595,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1651,
12618,
1046,
12,
257,
378,
14,
6557,
1020,
12832,
12,
221,
378,
14,
383,
2025,
713,
1690,
12,
221,
378,
14,
22728,
1349,
1349,
12,
446,
16,
14,
12809,
1641,
15765,
61,
272,
916,
574,
508,
1227,
26,
267,
536,
275,
298,
51,
5220,
437,
32623,
428,
2901,
1165,
38,
1651,
334,
32310,
1033,
357,
2924,
267,
327,
12855,
12601,
543,
15580,
5139,
1033,
16673,
267,
1804,
275,
980,
14,
1144,
8,
3474,
13470,
1717,
14,
1690,
8425,
5188,
12,
258,
378,
14,
263,
2360,
221,
499,
21618,
14,
1401,
8988,
23663,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
13470,
845,
14,
27697,
2824,
11309,
12,
221,
499,
12735,
14,
2720,
1138,
28681,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
975,
2905,
1651,
1342,
12,
221,
378,
14,
7979,
1079,
8312,
12,
221,
378,
14,
1493,
821,
15773,
12,
221,
378,
14,
29445,
2720,
1085,
12,
221,
378,
14,
966,
7842,
16450,
61,
272,
916,
574,
508,
1520,
26,
267,
536,
275,
298,
51,
5220,
437,
32623,
428,
2901,
1165,
38,
1651,
334,
10888,
818,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
26060,
14,
2898,
31720,
1643,
12,
258,
378,
14,
263,
2360,
257,
1749,
2824,
14,
10638,
27250,
1789,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
413,
25689,
14,
11160,
1085,
12832,
12,
257,
959,
2322,
14,
20,
14832,
772,
1349,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275
] |
[
2680,
465,
980,
199,
199,
3,
663,
15177,
25365,
687,
2005,
7508,
1233,
68,
1511,
199,
318,
663,
63,
11928,
63,
25851,
8,
585,
304,
272,
340,
574,
508,
378,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
969,
2789,
14,
17,
12,
259,
378,
14,
16,
12,
1749,
1257,
14,
24,
467,
2432,
359,
257,
378,
14,
16,
12,
12792,
18,
14,
24,
12,
1227,
614,
14,
19,
467,
2432,
359,
257,
378,
14,
16,
12,
259,
378,
14,
16,
12,
257,
413,
14,
16,
2677,
776,
267,
2917,
275,
5243,
16,
14,
1344,
10744,
11165,
12,
378,
14,
11432,
12987,
1465,
12,
446,
16,
14,
8010,
1342,
17686,
12,
378,
14,
1493,
1407,
1479,
12,
446,
16,
14,
14842,
1276,
20017,
61,
272,
916,
574,
508,
413,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
2639,
46,
378,
996,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
25,
2658,
14,
996,
12,
257,
378,
2020,
260,
1749,
1355,
14,
31955,
2564,
10875,
467,
1993,
359,
221,
378,
2020,
260,
1749,
1349,
14,
1401,
2360,
841,
2658,
14,
1427,
1082,
1400,
2819,
467,
1993,
359,
221,
378,
2020,
3698,
378,
2020,
3698,
413,
14,
263,
1622,
61,
776,
398,
2917,
275,
5243,
16,
14,
12015,
14681,
1342,
12,
221,
378,
14,
9261,
10552,
12,
221,
446,
16,
14,
9425,
1965,
1184,
12,
446,
16,
14,
993,
966,
1046,
12,
446,
16,
14,
18264,
1196,
7979,
61,
272,
916,
574,
508,
499,
26,
267,
536,
275,
298,
10970,
73,
527,
5851,
1165,
88,
23514,
334,
2639,
46,
378,
1644,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
4329,
614,
14,
18,
6984,
31327,
12,
258,
378,
14,
755,
2360,
259,
1749,
966,
14,
821,
5188,
32339,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
4329,
383,
14,
821,
1216,
19119,
12,
259,
841,
2710,
14,
713,
10823,
14539,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
755,
2360,
420,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1355,
614,
9687,
19,
12,
221,
378,
14,
10800,
1555,
2299,
12,
446,
16,
14,
1493,
15154,
1641,
12,
221,
378,
14,
383,
2466,
1229,
2942,
12,
446,
16,
14,
1717,
16963,
14820,
61,
272,
916,
574,
508,
650,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
23514,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
1749,
3172,
14,
2534,
1079,
2635,
1479,
12,
257,
378,
14,
263,
2360,
1749,
1641,
14,
16226,
13725,
996,
467,
2432,
359,
257,
378,
14,
263,
2360,
1749,
3172,
14,
1822,
969,
708,
772,
12,
959,
975,
14,
1400,
14992,
16244,
467,
2432,
359,
257,
378,
14,
263,
2360,
257,
378,
14,
263,
2360,
257,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
12442,
709,
16373,
12,
378,
14,
709,
2010,
614,
821,
12,
378,
14,
16643,
1349,
1196,
12,
378,
14,
993,
1643,
821,
12,
446,
16,
14,
996,
708,
969,
1555,
61,
272,
916,
574,
508,
841,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
1079,
2167,
334,
3864,
84,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
413,
11700,
14,
845,
1085,
2760,
1229,
12,
258,
378,
14,
263,
2360,
257,
1749,
1229,
14,
2824,
5284,
14966,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
413,
11700,
14,
614,
2322,
1342,
2869,
12,
257,
1227,
3328,
14,
2417,
1717,
1355,
1299,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1651,
7991,
16124,
12,
378,
14,
10037,
772,
16373,
12,
378,
14,
20965,
1085,
2466,
12,
378,
14,
4183,
1602,
1299,
12,
446,
16,
14,
1717,
7357,
12618,
61,
272,
916,
574,
508,
959,
26,
267,
536,
275,
298,
2540,
30524,
14903,
18,
5851,
1165,
88,
1079,
2167,
334,
2639,
46,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
4944,
383,
14,
18,
7636,
1081,
1717,
12,
258,
378,
14,
263,
2360,
257,
1749,
1717,
14,
12583,
821,
14637,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
3144,
1020,
14,
2720,
1082,
1690,
1465,
12,
257,
1227,
2194,
14,
10860,
821,
24595,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
1651,
12618,
1046,
12,
257,
378,
14,
6557,
1020,
12832,
12,
221,
378,
14,
383,
2025,
713,
1690,
12,
221,
378,
14,
22728,
1349,
1349,
12,
446,
16,
14,
12809,
1641,
15765,
61,
272,
916,
574,
508,
1227,
26,
267,
536,
275,
298,
51,
5220,
437,
32623,
428,
2901,
1165,
38,
1651,
334,
32310,
1033,
357,
2924,
267,
327,
12855,
12601,
543,
15580,
5139,
1033,
16673,
267,
1804,
275,
980,
14,
1144,
8,
3474,
13470,
1717,
14,
1690,
8425,
5188,
12,
258,
378,
14,
263,
2360,
221,
499,
21618,
14,
1401,
8988,
23663,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
13470,
845,
14,
27697,
2824,
11309,
12,
221,
499,
12735,
14,
2720,
1138,
28681,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
5243,
16,
14,
975,
2905,
1651,
1342,
12,
221,
378,
14,
7979,
1079,
8312,
12,
221,
378,
14,
1493,
821,
15773,
12,
221,
378,
14,
29445,
2720,
1085,
12,
221,
378,
14,
966,
7842,
16450,
61,
272,
916,
574,
508,
1520,
26,
267,
536,
275,
298,
51,
5220,
437,
32623,
428,
2901,
1165,
38,
1651,
334,
10888,
818,
2924,
267,
1804,
275,
980,
14,
1144,
8,
3474,
26060,
14,
2898,
31720,
1643,
12,
258,
378,
14,
263,
2360,
257,
1749,
2824,
14,
10638,
27250,
1789,
467,
2432,
359,
259,
378,
14,
263,
2360,
221,
413,
25689,
14,
11160,
1085,
12832,
12,
257,
959,
2322,
14,
20,
14832,
772,
1349,
467,
2432,
359,
259,
378,
14,
263,
2360,
258,
378,
14,
263,
2360,
258,
413,
14,
263,
1622,
61,
776,
267,
2917,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
safwanrahman/kitsune
|
authority/templatetags/permissions.py
|
5
|
15494
|
from django import template
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AnonymousUser
from authority import get_check
from authority import permissions
from authority.compat import get_user_model
from authority.models import Permission
from authority.forms import UserPermissionForm
User = get_user_model()
register = template.Library()
@register.simple_tag
def url_for_obj(view_name, obj):
return reverse(view_name, kwargs={
'app_label': obj._meta.app_label,
'module_name': obj._meta.module_name,
'pk': obj.pk}
)
@register.simple_tag
def add_url_for_obj(obj):
return url_for_obj('authority-add-permission', obj)
@register.simple_tag
def request_url_for_obj(obj):
return url_for_obj('authority-add-permission-request', obj)
class ResolverNode(template.Node):
"""
A small wrapper that adds a convenient resolve method.
"""
def resolve(self, var, context):
"""Resolves a variable out of context if it's not in quotes"""
if var is None:
return var
if var[0] in ('"', "'") and var[-1] == var[0]:
return var[1:-1]
else:
return template.Variable(var).resolve(context)
@classmethod
def next_bit_for(cls, bits, key, if_none=None):
try:
return bits[bits.index(key)+1]
except ValueError:
return if_none
class PermissionComparisonNode(ResolverNode):
"""
Implements a node to provide an "if user/group has permission on object"
"""
@classmethod
def handle_token(cls, parser, token):
bits = token.contents.split()
if 5 < len(bits) < 3:
raise template.TemplateSyntaxError(
"'%s' tag takes three, "
"four or five arguments" % bits[0]
)
end_tag = 'endifhasperm'
nodelist_true = parser.parse(('else', end_tag))
token = parser.next_token()
if token.contents == 'else': # there is an 'else' clause in the tag
nodelist_false = parser.parse((end_tag,))
parser.delete_first_token()
else:
nodelist_false = template.NodeList()
if len(bits) == 3: # this tag requires at most 2 objects . None is given
objs = (None, None)
elif len(bits) == 4: # one is given
objs = (bits[3], None)
else: # two are given
objs = (bits[3], bits[4])
return cls(bits[2], bits[1], nodelist_true, nodelist_false, *objs)
def __init__(self, user, perm, nodelist_true, nodelist_false, *objs):
self.user = user
self.objs = objs
self.perm = perm
self.nodelist_true = nodelist_true
self.nodelist_false = nodelist_false
def render(self, context):
try:
user = self.resolve(self.user, context)
perm = self.resolve(self.perm, context)
if self.objs:
objs = []
for obj in self.objs:
if obj is not None:
objs.append(self.resolve(obj, context))
else:
objs = None
check = get_check(user, perm)
if check is not None:
if check(*objs):
# return True if check was successful
return self.nodelist_true.render(context)
# If the app couldn't be found
except (ImproperlyConfigured, ImportError):
return ''
# If either variable fails to resolve, return nothing.
except template.VariableDoesNotExist:
return ''
# If the types don't permit comparison, return nothing.
except (TypeError, AttributeError):
return ''
return self.nodelist_false.render(context)
@register.tag
def ifhasperm(parser, token):
"""
This function provides functionality for the 'ifhasperm' template tag
Syntax::
{% ifhasperm PERMISSION_LABEL.CHECK_NAME USER *OBJS %}
lalala
{% else %}
meh
{% endifhasperm %}
{% ifhasperm "poll_permission.change_poll" request.user %}
lalala
{% else %}
meh
{% endifhasperm %}
"""
return PermissionComparisonNode.handle_token(parser, token)
class PermissionFormNode(ResolverNode):
@classmethod
def handle_token(cls, parser, token, approved):
bits = token.contents.split()
kwargs = {
'obj': cls.next_bit_for(bits, 'for'),
'perm': cls.next_bit_for(bits, 'using', None),
'template_name': cls.next_bit_for(bits, 'with', ''),
'approved': approved,
}
return cls(**kwargs)
def __init__(self, obj, perm=None, approved=False, template_name=None):
self.obj = obj
self.perm = perm
self.approved = approved
self.template_name = template_name
def render(self, context):
obj = self.resolve(self.obj, context)
perm = self.resolve(self.perm, context)
if self.template_name:
template_name = [self.resolve(o, context) for o in self.template_name.split(',')]
else:
template_name = 'authority/permission_form.html'
request = context['request']
extra_context = {}
if self.approved:
if (request.user.is_authenticated() and
request.user.has_perm('authority.add_permission')):
extra_context = {
'form_url': url_for_obj('authority-add-permission', obj),
'next': request.build_absolute_uri(),
'approved': self.approved,
'form': UserPermissionForm(perm, obj, approved=self.approved,
initial=dict(codename=perm)),
}
else:
if request.user.is_authenticated() and not request.user.is_superuser:
extra_context = {
'form_url': url_for_obj('authority-add-permission-request', obj),
'next': request.build_absolute_uri(),
'approved': self.approved,
'form': UserPermissionForm(
perm,
obj,
approved=self.approved,
initial=dict(codename=perm, user=request.user.username)),
}
return template.loader.render_to_string(
template_name, extra_context, context_instance=template.RequestContext(request))
@register.tag
def permission_form(parser, token):
"""
Renders an "add permissions" form for the given object. If no object
is given it will render a select box to choose from.
Syntax::
{% permission_form for OBJ using PERMISSION_LABEL.CHECK_NAME [with TEMPLATE] %}
{% permission_form for lesson using "lesson_permission.add_lesson" %}
"""
return PermissionFormNode.handle_token(parser, token, approved=True)
@register.tag
def permission_request_form(parser, token):
"""
Renders an "add permissions" form for the given object. If no object
is given it will render a select box to choose from.
Syntax::
{% permission_request_form for OBJ and PERMISSION_LABEL.CHECK_NAME [with TEMPLATE] %}
{% permission_request_form for lesson using "lesson_permission.add_lesson"
with "authority/permission_request_form.html" %}
"""
return PermissionFormNode.handle_token(parser, token, approved=False)
class PermissionsForObjectNode(ResolverNode):
@classmethod
def handle_token(cls, parser, token, approved, name):
bits = token.contents.split()
tag_name = bits[0]
kwargs = {
'obj': cls.next_bit_for(bits, tag_name),
'user': cls.next_bit_for(bits, 'for'),
'var_name': cls.next_bit_for(bits, 'as', name),
'approved': approved,
}
return cls(**kwargs)
def __init__(self, obj, user, var_name, approved, perm=None):
self.obj = obj
self.user = user
self.perm = perm
self.var_name = var_name
self.approved = approved
def render(self, context):
obj = self.resolve(self.obj, context)
var_name = self.resolve(self.var_name, context)
user = self.resolve(self.user, context)
perms = []
if not isinstance(user, AnonymousUser):
perms = Permission.objects.for_object(obj, self.approved)
if isinstance(user, User):
perms = perms.filter(user=user)
context[var_name] = perms
return ''
@register.tag
def get_permissions(parser, token):
"""
Retrieves all permissions associated with the given obj and user
and assigns the result to a context variable.
Syntax::
{% get_permissions obj %}
{% for perm in permissions %}
{{ perm }}
{% endfor %}
{% get_permissions obj as "my_permissions" %}
{% get_permissions obj for request.user as "my_permissions" %}
"""
return PermissionsForObjectNode.handle_token(parser, token, approved=True,
name='"permissions"')
@register.tag
def get_permission_requests(parser, token):
"""
Retrieves all permissions requests associated with the given obj and user
and assigns the result to a context variable.
Syntax::
{% get_permission_requests obj %}
{% for perm in permissions %}
{{ perm }}
{% endfor %}
{% get_permission_requests obj as "my_permissions" %}
{% get_permission_requests obj for request.user as "my_permissions" %}
"""
return PermissionsForObjectNode.handle_token(parser, token,
approved=False,
name='"permission_requests"')
class PermissionForObjectNode(ResolverNode):
@classmethod
def handle_token(cls, parser, token, approved, name):
bits = token.contents.split()
tag_name = bits[0]
kwargs = {
'perm': cls.next_bit_for(bits, tag_name),
'user': cls.next_bit_for(bits, 'for'),
'objs': cls.next_bit_for(bits, 'and'),
'var_name': cls.next_bit_for(bits, 'as', name),
'approved': approved,
}
return cls(**kwargs)
def __init__(self, perm, user, objs, approved, var_name):
self.perm = perm
self.user = user
self.objs = objs
self.var_name = var_name
self.approved = approved
def render(self, context):
objs = [self.resolve(obj, context) for obj in self.objs.split(',')]
var_name = self.resolve(self.var_name, context)
perm = self.resolve(self.perm, context)
user = self.resolve(self.user, context)
granted = False
if not isinstance(user, AnonymousUser):
if self.approved:
check = get_check(user, perm)
if check is not None:
granted = check(*objs)
else:
check = permissions.BasePermission(user=user)
for obj in objs:
granted = check.requested_perm(perm, obj)
if granted:
break
context[var_name] = granted
return ''
@register.tag
def get_permission(parser, token):
"""
Performs a permission check with the given signature, user and objects
and assigns the result to a context variable.
Syntax::
{% get_permission PERMISSION_LABEL.CHECK_NAME for USER and *OBJS [as VARNAME] %}
{% get_permission "poll_permission.change_poll"
for request.user and poll as "is_allowed" %}
{% get_permission "poll_permission.change_poll"
for request.user and poll,second_poll as "is_allowed" %}
{% if is_allowed %}
I've got ze power to change ze pollllllzzz. Muahahaa.
{% else %}
Meh. No power for meeeee.
{% endif %}
"""
return PermissionForObjectNode.handle_token(parser, token,
approved=True,
name='"permission"')
@register.tag
def get_permission_request(parser, token):
"""
Performs a permission request check with the given signature, user and objects
and assigns the result to a context variable.
Syntax::
{% get_permission_request PERMISSION_LABEL.CHECK_NAME for USER and *OBJS [as VARNAME] %}
{% get_permission_request "poll_permission.change_poll"
for request.user and poll as "asked_for_permissio" %}
{% get_permission_request "poll_permission.change_poll"
for request.user and poll,second_poll as "asked_for_permissio" %}
{% if asked_for_permissio %}
Dude, you already asked for permission!
{% else %}
Oh, please fill out this 20 page form and sign here.
{% endif %}
"""
return PermissionForObjectNode.handle_token(
parser, token, approved=False, name='"permission_request"')
def base_link(context, perm, view_name):
return {
'next': context['request'].build_absolute_uri(),
'url': reverse(view_name, kwargs={'permission_pk': perm.pk}),
}
@register.inclusion_tag('authority/permission_delete_link.html', takes_context=True)
def permission_delete_link(context, perm):
"""
Renders a html link to the delete view of the given permission. Returns
no content if the request-user has no permission to delete foreign
permissions.
"""
user = context['request'].user
if user.is_authenticated():
if (user.has_perm('authority.delete_foreign_permissions') or
user.pk == perm.creator.pk):
return base_link(context, perm, 'authority-delete-permission')
return {'url': None}
@register.inclusion_tag('authority/permission_request_delete_link.html', takes_context=True)
def permission_request_delete_link(context, perm):
"""
Renders a html link to the delete view of the given permission request.
Returns no content if the request-user has no permission to delete foreign
permissions.
"""
user = context['request'].user
if user.is_authenticated():
link_kwargs = base_link(context, perm,
'authority-delete-permission-request')
if user.has_perm('authority.delete_permission'):
link_kwargs['is_requestor'] = False
return link_kwargs
if not perm.approved and perm.user == user:
link_kwargs['is_requestor'] = True
return link_kwargs
return {'url': None}
@register.inclusion_tag('authority/permission_request_approve_link.html', takes_context=True)
def permission_request_approve_link(context, perm):
"""
Renders a html link to the approve view of the given permission request.
Returns no content if the request-user has no permission to delete foreign
permissions.
"""
user = context['request'].user
if user.is_authenticated():
if user.has_perm('authority.approve_permission_requests'):
return base_link(context, perm, 'authority-approve-permission-request')
return {'url': None}
|
bsd-3-clause
|
[
504,
1639,
492,
1978,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
199,
504,
18330,
492,
664,
63,
1074,
199,
504,
18330,
492,
3443,
199,
504,
18330,
14,
5819,
492,
664,
63,
751,
63,
1238,
199,
504,
18330,
14,
992,
492,
8779,
199,
504,
18330,
14,
3351,
492,
2876,
7980,
2821,
421,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1166,
63,
509,
63,
1113,
8,
1345,
63,
354,
12,
1559,
304,
272,
372,
3837,
8,
1345,
63,
354,
12,
2074,
3126,
267,
283,
571,
63,
1302,
356,
1559,
423,
2024,
14,
571,
63,
1302,
12,
267,
283,
578,
63,
354,
356,
1559,
423,
2024,
14,
578,
63,
354,
12,
267,
283,
2051,
356,
1559,
14,
2051,
93,
272,
776,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1050,
63,
633,
63,
509,
63,
1113,
8,
1113,
304,
272,
372,
1166,
63,
509,
63,
1113,
360,
23635,
13,
525,
13,
5693,
297,
1559,
9,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1056,
63,
633,
63,
509,
63,
1113,
8,
1113,
304,
272,
372,
1166,
63,
509,
63,
1113,
360,
23635,
13,
525,
13,
5693,
13,
1069,
297,
1559,
9,
421,
199,
533,
26046,
1716,
8,
1160,
14,
1716,
304,
272,
408,
272,
437,
7425,
4975,
626,
9584,
282,
22700,
7512,
1083,
14,
272,
408,
272,
347,
7512,
8,
277,
12,
2729,
12,
1067,
304,
267,
408,
1322,
393,
2310,
282,
1750,
734,
402,
1067,
340,
652,
1159,
440,
315,
9344,
624,
267,
340,
2729,
365,
488,
26,
288,
372,
2729,
267,
340,
2729,
59,
16,
61,
315,
661,
6949,
3546,
531,
436,
2729,
1988,
17,
61,
508,
2729,
59,
16,
2189,
288,
372,
2729,
59,
17,
6809,
17,
61,
267,
587,
26,
288,
372,
1978,
14,
2773,
8,
1391,
680,
6983,
8,
1100,
9,
339,
768,
3744,
272,
347,
2163,
63,
2075,
63,
509,
8,
1886,
12,
5821,
12,
790,
12,
340,
63,
3592,
29,
403,
304,
267,
862,
26,
288,
372,
5821,
59,
5609,
14,
1080,
8,
498,
6393,
17,
61,
267,
871,
1722,
26,
288,
372,
340,
63,
3592,
421,
199,
533,
8779,
25834,
1716,
8,
12407,
1716,
304,
272,
408,
272,
24664,
282,
1031,
370,
5647,
376,
298,
692,
922,
15,
923,
965,
4983,
641,
909,
2,
272,
408,
272,
768,
3744,
272,
347,
2429,
63,
1418,
8,
1886,
12,
1798,
12,
1526,
304,
267,
5821,
275,
1526,
14,
4407,
14,
1294,
342,
267,
340,
959,
665,
822,
8,
5609,
9,
665,
650,
26,
288,
746,
1978,
14,
20837,
8,
355,
17648,
83,
7,
1947,
6181,
7795,
12,
298,
355,
298,
13672,
503,
24187,
2368,
2,
450,
5821,
59,
16,
61,
288,
776,
267,
1284,
63,
1450,
275,
283,
13739,
1989,
8220,
7,
267,
13642,
63,
2052,
275,
1798,
14,
1122,
4725,
2836,
297,
1284,
63,
1450,
430,
267,
1526,
275,
1798,
14,
2184,
63,
1418,
342,
267,
340,
1526,
14,
4407,
508,
283,
2836,
356,
221,
327,
2337,
365,
376,
283,
2836,
7,
8502,
315,
314,
1947,
288,
13642,
63,
3910,
275,
1798,
14,
1122,
1332,
500,
63,
1450,
4641,
288,
1798,
14,
1807,
63,
2246,
63,
1418,
342,
267,
587,
26,
288,
13642,
63,
3910,
275,
1978,
14,
29166,
342,
267,
340,
822,
8,
5609,
9,
508,
650,
26,
221,
327,
642,
1947,
5074,
737,
4750,
499,
2251,
1275,
488,
365,
1627,
288,
13474,
275,
334,
403,
12,
488,
9,
267,
916,
822,
8,
5609,
9,
508,
841,
26,
221,
327,
1373,
365,
1627,
288,
13474,
275,
334,
5609,
59,
19,
467,
488,
9,
267,
587,
26,
221,
327,
2877,
787,
1627,
288,
13474,
275,
334,
5609,
59,
19,
467,
5821,
59,
20,
566,
267,
372,
843,
8,
5609,
59,
18,
467,
5821,
59,
17,
467,
13642,
63,
2052,
12,
13642,
63,
3910,
12,
627,
8718,
9,
339,
347,
636,
826,
721,
277,
12,
922,
12,
10869,
12,
13642,
63,
2052,
12,
13642,
63,
3910,
12,
627,
8718,
304,
267,
291,
14,
751,
275,
922,
267,
291,
14,
8718,
275,
13474,
267,
291,
14,
8220,
275,
10869,
267,
291,
14,
14371,
63,
2052,
275,
13642,
63,
2052,
267,
291,
14,
14371,
63,
3910,
275,
13642,
63,
3910,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
862,
26,
288,
922,
275,
291,
14,
6983,
8,
277,
14,
751,
12,
1067,
9,
288,
10869,
275,
291,
14,
6983,
8,
277,
14,
8220,
12,
1067,
9,
288,
340,
291,
14,
8718,
26,
355,
13474,
275,
942,
355,
367,
1559,
315,
291,
14,
8718,
26,
490,
340,
1559,
365,
440,
488,
26,
717,
13474,
14,
740,
8,
277,
14,
6983,
8,
1113,
12,
1067,
430,
288,
587,
26,
355,
13474,
275,
488,
288,
1104,
275,
664,
63,
1074,
8,
751,
12,
10869,
9,
288,
340,
1104,
365,
440,
488,
26,
355,
340,
1104,
2031,
8718,
304,
490,
327,
372,
715,
340,
1104,
1990,
9512,
490,
372,
291,
14,
14371,
63,
2052,
14,
3352,
8,
1100,
9,
267,
327,
982,
314,
1145,
21554,
1133,
506,
1911,
267,
871,
334,
8499,
10951,
12,
3545,
304,
288,
372,
2125,
267,
327,
982,
1902,
1750,
6918,
370,
7512,
12,
372,
6548,
14,
267,
871,
1978,
14,
2773,
7400,
26,
288,
372,
2125,
267,
327,
982,
314,
2943,
2793,
1133,
11291,
9132,
12,
372,
6548,
14,
267,
871,
334,
4333,
12,
4281,
304,
288,
372,
2125,
267,
372,
291,
14,
14371,
63,
3910,
14,
3352,
8,
1100,
9,
421,
199,
32,
2683,
14,
1450,
199,
318,
340,
1989,
8220,
8,
2087,
12,
1526,
304,
272,
408,
272,
961,
805,
6571,
9330,
367,
314,
283,
692,
1989,
8220,
7,
1978,
1947,
339,
18377,
447,
398,
7749,
340,
1989,
8220,
13873,
22320,
63,
13837,
14,
8936,
63,
2339,
13044,
627,
5488,
11378,
3674,
288,
634,
279,
14774,
267,
7749,
587,
3674,
288,
562,
72,
267,
7749,
14454,
1989,
8220,
3674,
398,
7749,
340,
1989,
8220,
298,
6843,
63,
5693,
14,
1461,
63,
6843,
2,
1056,
14,
751,
3674,
288,
634,
279,
14774,
267,
7749
] |
[
1639,
492,
1978,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
29952,
199,
199,
504,
18330,
492,
664,
63,
1074,
199,
504,
18330,
492,
3443,
199,
504,
18330,
14,
5819,
492,
664,
63,
751,
63,
1238,
199,
504,
18330,
14,
992,
492,
8779,
199,
504,
18330,
14,
3351,
492,
2876,
7980,
2821,
421,
199,
1899,
275,
664,
63,
751,
63,
1238,
342,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1166,
63,
509,
63,
1113,
8,
1345,
63,
354,
12,
1559,
304,
272,
372,
3837,
8,
1345,
63,
354,
12,
2074,
3126,
267,
283,
571,
63,
1302,
356,
1559,
423,
2024,
14,
571,
63,
1302,
12,
267,
283,
578,
63,
354,
356,
1559,
423,
2024,
14,
578,
63,
354,
12,
267,
283,
2051,
356,
1559,
14,
2051,
93,
272,
776,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1050,
63,
633,
63,
509,
63,
1113,
8,
1113,
304,
272,
372,
1166,
63,
509,
63,
1113,
360,
23635,
13,
525,
13,
5693,
297,
1559,
9,
421,
199,
32,
2683,
14,
4129,
63,
1450,
199,
318,
1056,
63,
633,
63,
509,
63,
1113,
8,
1113,
304,
272,
372,
1166,
63,
509,
63,
1113,
360,
23635,
13,
525,
13,
5693,
13,
1069,
297,
1559,
9,
421,
199,
533,
26046,
1716,
8,
1160,
14,
1716,
304,
272,
408,
272,
437,
7425,
4975,
626,
9584,
282,
22700,
7512,
1083,
14,
272,
408,
272,
347,
7512,
8,
277,
12,
2729,
12,
1067,
304,
267,
408,
1322,
393,
2310,
282,
1750,
734,
402,
1067,
340,
652,
1159,
440,
315,
9344,
624,
267,
340,
2729,
365,
488,
26,
288,
372,
2729,
267,
340,
2729,
59,
16,
61,
315,
661,
6949,
3546,
531,
436,
2729,
1988,
17,
61,
508,
2729,
59,
16,
2189,
288,
372,
2729,
59,
17,
6809,
17,
61,
267,
587,
26,
288,
372,
1978,
14,
2773,
8,
1391,
680,
6983,
8,
1100,
9,
339,
768,
3744,
272,
347,
2163,
63,
2075,
63,
509,
8,
1886,
12,
5821,
12,
790,
12,
340,
63,
3592,
29,
403,
304,
267,
862,
26,
288,
372,
5821,
59,
5609,
14,
1080,
8,
498,
6393,
17,
61,
267,
871,
1722,
26,
288,
372,
340,
63,
3592,
421,
199,
533,
8779,
25834,
1716,
8,
12407,
1716,
304,
272,
408,
272,
24664,
282,
1031,
370,
5647,
376,
298,
692,
922,
15,
923,
965,
4983,
641,
909,
2,
272,
408,
272,
768,
3744,
272,
347,
2429,
63,
1418,
8,
1886,
12,
1798,
12,
1526,
304,
267,
5821,
275,
1526,
14,
4407,
14,
1294,
342,
267,
340,
959,
665,
822,
8,
5609,
9,
665,
650,
26,
288,
746,
1978,
14,
20837,
8,
355,
17648,
83,
7,
1947,
6181,
7795,
12,
298,
355,
298,
13672,
503,
24187,
2368,
2,
450,
5821,
59,
16,
61,
288,
776,
267,
1284,
63,
1450,
275,
283,
13739,
1989,
8220,
7,
267,
13642,
63,
2052,
275,
1798,
14,
1122,
4725,
2836,
297,
1284,
63,
1450,
430,
267,
1526,
275,
1798,
14,
2184,
63,
1418,
342,
267,
340,
1526,
14,
4407,
508,
283,
2836,
356,
221,
327,
2337,
365,
376,
283,
2836,
7,
8502,
315,
314,
1947,
288,
13642,
63,
3910,
275,
1798,
14,
1122,
1332,
500,
63,
1450,
4641,
288,
1798,
14,
1807,
63,
2246,
63,
1418,
342,
267,
587,
26,
288,
13642,
63,
3910,
275,
1978,
14,
29166,
342,
267,
340,
822,
8,
5609,
9,
508,
650,
26,
221,
327,
642,
1947,
5074,
737,
4750,
499,
2251,
1275,
488,
365,
1627,
288,
13474,
275,
334,
403,
12,
488,
9,
267,
916,
822,
8,
5609,
9,
508,
841,
26,
221,
327,
1373,
365,
1627,
288,
13474,
275,
334,
5609,
59,
19,
467,
488,
9,
267,
587,
26,
221,
327,
2877,
787,
1627,
288,
13474,
275,
334,
5609,
59,
19,
467,
5821,
59,
20,
566,
267,
372,
843,
8,
5609,
59,
18,
467,
5821,
59,
17,
467,
13642,
63,
2052,
12,
13642,
63,
3910,
12,
627,
8718,
9,
339,
347,
636,
826,
721,
277,
12,
922,
12,
10869,
12,
13642,
63,
2052,
12,
13642,
63,
3910,
12,
627,
8718,
304,
267,
291,
14,
751,
275,
922,
267,
291,
14,
8718,
275,
13474,
267,
291,
14,
8220,
275,
10869,
267,
291,
14,
14371,
63,
2052,
275,
13642,
63,
2052,
267,
291,
14,
14371,
63,
3910,
275,
13642,
63,
3910,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
862,
26,
288,
922,
275,
291,
14,
6983,
8,
277,
14,
751,
12,
1067,
9,
288,
10869,
275,
291,
14,
6983,
8,
277,
14,
8220,
12,
1067,
9,
288,
340,
291,
14,
8718,
26,
355,
13474,
275,
942,
355,
367,
1559,
315,
291,
14,
8718,
26,
490,
340,
1559,
365,
440,
488,
26,
717,
13474,
14,
740,
8,
277,
14,
6983,
8,
1113,
12,
1067,
430,
288,
587,
26,
355,
13474,
275,
488,
288,
1104,
275,
664,
63,
1074,
8,
751,
12,
10869,
9,
288,
340,
1104,
365,
440,
488,
26,
355,
340,
1104,
2031,
8718,
304,
490,
327,
372,
715,
340,
1104,
1990,
9512,
490,
372,
291,
14,
14371,
63,
2052,
14,
3352,
8,
1100,
9,
267,
327,
982,
314,
1145,
21554,
1133,
506,
1911,
267,
871,
334,
8499,
10951,
12,
3545,
304,
288,
372,
2125,
267,
327,
982,
1902,
1750,
6918,
370,
7512,
12,
372,
6548,
14,
267,
871,
1978,
14,
2773,
7400,
26,
288,
372,
2125,
267,
327,
982,
314,
2943,
2793,
1133,
11291,
9132,
12,
372,
6548,
14,
267,
871,
334,
4333,
12,
4281,
304,
288,
372,
2125,
267,
372,
291,
14,
14371,
63,
3910,
14,
3352,
8,
1100,
9,
421,
199,
32,
2683,
14,
1450,
199,
318,
340,
1989,
8220,
8,
2087,
12,
1526,
304,
272,
408,
272,
961,
805,
6571,
9330,
367,
314,
283,
692,
1989,
8220,
7,
1978,
1947,
339,
18377,
447,
398,
7749,
340,
1989,
8220,
13873,
22320,
63,
13837,
14,
8936,
63,
2339,
13044,
627,
5488,
11378,
3674,
288,
634,
279,
14774,
267,
7749,
587,
3674,
288,
562,
72,
267,
7749,
14454,
1989,
8220,
3674,
398,
7749,
340,
1989,
8220,
298,
6843,
63,
5693,
14,
1461,
63,
6843,
2,
1056,
14,
751,
3674,
288,
634,
279,
14774,
267,
7749,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pku9104038/edx-platform
|
common/djangoapps/terrain/browser.py
|
7
|
7617
|
"""
Browser set up for acceptance tests.
"""
#pylint: disable=E1101
#pylint: disable=W0613
from lettuce import before, after, world
from splinter.browser import Browser
from logging import getLogger
from django.core.management import call_command
from django.conf import settings
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import requests
from base64 import encodestring
from json import dumps
from pymongo import MongoClient
import xmodule.modulestore.django
from xmodule.contentstore.django import _CONTENTSTORE
# There is an import issue when using django-staticfiles with lettuce
# Lettuce assumes that we are using django.contrib.staticfiles,
# but the rest of the app assumes we are using django-staticfiles
# (in particular, django-pipeline and our mako implementation)
# To resolve this, we check whether staticfiles is installed,
# then redirect imports for django.contrib.staticfiles
# to use staticfiles.
try:
import staticfiles
import staticfiles.handlers
except ImportError:
pass
else:
import sys
sys.modules['django.contrib.staticfiles'] = staticfiles
sys.modules['django.contrib.staticfiles.handlers'] = staticfiles.handlers
LOGGER = getLogger(__name__)
LOGGER.info("Loading the lettuce acceptance testing terrain file...")
MAX_VALID_BROWSER_ATTEMPTS = 20
GLOBAL_SCRIPT_TIMEOUT = 20
def get_saucelabs_username_and_key():
"""
Returns the Sauce Labs username and access ID as set by environment variables
"""
return {"username": settings.SAUCE.get('USERNAME'), "access-key": settings.SAUCE.get('ACCESS_ID')}
def set_saucelabs_job_status(jobid, passed=True):
"""
Sets the job status on sauce labs
"""
config = get_saucelabs_username_and_key()
url = 'http://saucelabs.com/rest/v1/{}/jobs/{}'.format(config['username'], world.jobid)
body_content = dumps({"passed": passed})
base64string = encodestring('{}:{}'.format(config['username'], config['access-key']))[:-1]
headers = {"Authorization": "Basic {}".format(base64string)}
result = requests.put(url, data=body_content, headers=headers)
return result.status_code == 200
def make_saucelabs_desired_capabilities():
"""
Returns a DesiredCapabilities object corresponding to the environment sauce parameters
"""
desired_capabilities = settings.SAUCE.get('BROWSER', DesiredCapabilities.CHROME)
desired_capabilities['platform'] = settings.SAUCE.get('PLATFORM')
desired_capabilities['version'] = settings.SAUCE.get('VERSION')
desired_capabilities['device-type'] = settings.SAUCE.get('DEVICE')
desired_capabilities['name'] = settings.SAUCE.get('SESSION')
desired_capabilities['build'] = settings.SAUCE.get('BUILD')
desired_capabilities['video-upload-on-pass'] = False
desired_capabilities['sauce-advisor'] = False
desired_capabilities['capture-html'] = True
desired_capabilities['record-screenshots'] = True
desired_capabilities['selenium-version'] = "2.34.0"
desired_capabilities['max-duration'] = 3600
desired_capabilities['public'] = 'public restricted'
return desired_capabilities
@before.harvest
def initial_setup(server):
"""
Launch the browser once before executing the tests.
"""
world.absorb(settings.LETTUCE_SELENIUM_CLIENT, 'LETTUCE_SELENIUM_CLIENT')
if world.LETTUCE_SELENIUM_CLIENT == 'local':
browser_driver = getattr(settings, 'LETTUCE_BROWSER', 'chrome')
# There is an issue with ChromeDriver2 r195627 on Ubuntu
# in which we sometimes get an invalid browser session.
# This is a work-around to ensure that we get a valid session.
success = False
num_attempts = 0
while (not success) and num_attempts < MAX_VALID_BROWSER_ATTEMPTS:
# Load the browser and try to visit the main page
# If the browser couldn't be reached or
# the browser session is invalid, this will
# raise a WebDriverException
try:
world.browser = Browser(browser_driver)
world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
world.visit('/')
except WebDriverException:
if hasattr(world, 'browser'):
world.browser.quit()
num_attempts += 1
else:
success = True
# If we were unable to get a valid session within the limit of attempts,
# then we cannot run the tests.
if not success:
raise IOError("Could not acquire valid {driver} browser session.".format(driver=browser_driver))
world.absorb(0, 'IMPLICIT_WAIT')
world.browser.driver.set_window_size(1280, 1024)
elif world.LETTUCE_SELENIUM_CLIENT == 'saucelabs':
config = get_saucelabs_username_and_key()
world.browser = Browser(
'remote',
url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config['username'], config['access-key']),
**make_saucelabs_desired_capabilities()
)
world.absorb(30, 'IMPLICIT_WAIT')
world.browser.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
elif world.LETTUCE_SELENIUM_CLIENT == 'grid':
world.browser = Browser(
'remote',
url=settings.SELENIUM_GRID.get('URL'),
browser=settings.SELENIUM_GRID.get('BROWSER'),
)
world.absorb(30, 'IMPLICIT_WAIT')
world.browser.driver.set_script_timeout(GLOBAL_SCRIPT_TIMEOUT)
else:
raise Exception("Unknown selenium client '{}'".format(world.LETTUCE_SELENIUM_CLIENT))
world.browser.driver.implicitly_wait(world.IMPLICIT_WAIT)
world.absorb(world.browser.driver.session_id, 'jobid')
@before.each_scenario
def reset_data(scenario):
"""
Clean out the django test database defined in the
envs/acceptance.py file: edx-platform/db/test_edx.db
"""
LOGGER.debug("Flushing the test database...")
call_command('flush', interactive=False, verbosity=0)
world.absorb({}, 'scenario_dict')
@after.each_scenario
def clear_data(scenario):
world.spew('scenario_dict')
@after.each_scenario
def reset_databases(scenario):
'''
After each scenario, all databases are cleared/dropped. Contentstore data are stored in unique databases
whereas modulestore data is in unique collection names. This data is created implicitly during the scenarios.
If no data is created during the test, these lines equivilently do nothing.
'''
mongo = MongoClient()
mongo.drop_database(settings.CONTENTSTORE['DOC_STORE_CONFIG']['db'])
_CONTENTSTORE.clear()
modulestore = xmodule.modulestore.django.editable_modulestore()
modulestore.collection.drop()
xmodule.modulestore.django.clear_existing_modulestores()
@after.each_scenario
def screenshot_on_error(scenario):
"""
Save a screenshot to help with debugging.
"""
if scenario.failed:
try:
output_dir = '{}/log'.format(settings.TEST_ROOT)
image_name = '{}/{}.png'.format(output_dir, scenario.name.replace(' ', '_'))
world.browser.driver.save_screenshot(image_name)
except WebDriverException:
LOGGER.error('Could not capture a screenshot')
@after.harvest
def teardown_browser(total):
"""
Quit the browser after executing the tests.
"""
if world.LETTUCE_SELENIUM_CLIENT == 'saucelabs':
set_saucelabs_job_status(world.jobid, total.scenarios_ran == total.scenarios_passed)
world.browser.quit()
|
agpl-3.0
|
[
624,
199,
11930,
663,
1536,
367,
4729,
554,
2295,
14,
199,
624,
199,
199,
3,
26324,
26,
3507,
29,
37,
24827,
199,
3,
26324,
26,
3507,
29,
55,
1690,
969,
199,
199,
504,
4691,
84,
3683,
492,
2544,
12,
2410,
12,
6701,
199,
504,
2249,
25240,
14,
5750,
492,
27620,
199,
504,
2050,
492,
28138,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
19481,
14,
2330,
14,
3924,
492,
27104,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
16035,
63,
10732,
492,
1487,
5381,
17006,
199,
646,
4145,
199,
504,
1300,
772,
492,
3752,
875,
199,
504,
2022,
492,
16864,
199,
199,
504,
21878,
492,
13503,
3041,
199,
646,
9872,
14,
10012,
14,
1176,
199,
504,
9872,
14,
28160,
14,
1176,
492,
485,
9663,
16169,
199,
199,
3,
6006,
365,
376,
492,
4976,
1380,
1808,
1639,
13,
18373,
543,
4691,
84,
3683,
199,
3,
12230,
84,
3683,
15194,
626,
781,
787,
1808,
1639,
14,
2828,
14,
18373,
12,
199,
3,
1325,
314,
4618,
402,
314,
1145,
15194,
781,
787,
1808,
1639,
13,
18373,
199,
3,
334,
262,
6770,
12,
1639,
13,
7379,
436,
4154,
26834,
4514,
9,
199,
3,
4005,
7512,
642,
12,
781,
1104,
3775,
2955,
1725,
365,
4903,
12,
199,
3,
2066,
4660,
8925,
367,
1639,
14,
2828,
14,
18373,
199,
3,
370,
675,
2955,
1725,
14,
199,
893,
26,
272,
492,
2955,
1725,
272,
492,
2955,
1725,
14,
5586,
199,
2590,
3545,
26,
272,
986,
199,
2836,
26,
272,
492,
984,
272,
984,
14,
3112,
459,
1176,
14,
2828,
14,
18373,
418,
275,
2955,
1725,
272,
984,
14,
3112,
459,
1176,
14,
2828,
14,
18373,
14,
5586,
418,
275,
2955,
1725,
14,
5586,
199,
199,
10186,
275,
28138,
3460,
354,
3368,
199,
10186,
14,
815,
480,
19236,
314,
4691,
84,
3683,
4729,
554,
5343,
2044,
6322,
570,
12594,
199,
199,
4283,
63,
5600,
63,
31956,
3279,
63,
619,
12510,
9730,
275,
3388,
199,
13808,
63,
10484,
63,
8899,
275,
3388,
421,
199,
318,
664,
63,
2231,
3683,
76,
2101,
63,
2473,
63,
460,
63,
498,
837,
272,
408,
272,
1803,
314,
428,
65,
3683,
491,
2101,
3434,
436,
2879,
2870,
465,
663,
701,
3734,
2860,
272,
408,
272,
372,
2420,
2473,
582,
2202,
14,
4251,
53,
2089,
14,
362,
360,
11958,
659,
298,
2732,
13,
498,
582,
2202,
14,
4251,
53,
2089,
14,
362,
360,
11074,
63,
998,
21004,
421,
199,
318,
663,
63,
2231,
3683,
76,
2101,
63,
2423,
63,
1205,
8,
2423,
344,
12,
3032,
29,
549,
304,
272,
408,
272,
10729,
314,
3906,
2004,
641,
2937,
3683,
634,
2101,
272,
408,
272,
1101,
275,
664,
63,
2231,
3683,
76,
2101,
63,
2473,
63,
460,
63,
498,
342,
272,
1166,
275,
283,
1014,
921,
2231,
3683,
76,
2101,
14,
957,
15,
3911,
15,
86,
17,
19655,
6920,
30837,
908,
8,
888,
459,
2473,
995,
6701,
14,
2423,
344,
9,
272,
2396,
63,
1317,
275,
16864,
6333,
12070,
582,
3032,
1552,
272,
1300,
772,
875,
275,
3752,
875,
17519,
26,
11123,
908,
8,
888,
459,
2473,
995,
1101,
459,
2732,
13,
498,
5156,
4439,
17,
61,
272,
2323,
275,
2420,
11626,
582,
298,
6845,
8352,
908,
8,
1095,
772,
875,
6769,
272,
754,
275,
4145,
14,
524,
8,
633,
12,
666,
29,
2030,
63,
1317,
12,
2323,
29,
2139,
9,
272,
372,
754,
14,
1205,
63,
600,
508,
1926,
421,
199,
318,
1852,
63,
2231,
3683,
76,
2101,
63,
16035,
63,
10732,
837,
272,
408,
272,
1803,
282,
1487,
5381,
17006,
909,
5226,
370,
314,
3734,
2937,
3683,
2633,
272,
408,
272,
6387,
63,
10732,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
31956,
3279,
297,
1487,
5381,
17006,
14,
1244,
31364,
9,
272,
6387,
63,
10732,
459,
3246,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
17805,
358,
272,
6387,
63,
10732,
459,
1023,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
4612,
358,
272,
6387,
63,
10732,
459,
1782,
13,
466,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
10555,
358,
272,
6387,
63,
10732,
459,
354,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
12763,
358,
272,
6387,
63,
10732,
459,
1506,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
8248,
358,
272,
6387,
63,
10732,
459,
3722,
13,
5064,
13,
265,
13,
1529,
418,
275,
756,
272,
6387,
63,
10732,
459,
2231,
3683,
13,
350,
8286,
418,
275,
756,
272,
6387,
63,
10732,
459,
12685,
13,
1360,
418,
275,
715,
272,
6387,
63,
10732,
459,
3059,
13,
23269,
83,
418,
275,
715,
272,
6387,
63,
10732,
459,
15041,
13,
1023,
418,
275,
298,
18,
14,
1082,
14,
16,
2,
272,
6387,
63,
10732,
459,
988,
13,
5553,
418,
275,
15751,
272,
6387,
63,
10732,
459,
3455,
418,
275,
283,
3455,
15297,
7,
272,
372,
6387,
63,
10732,
421,
199,
32,
5182,
14,
32222,
199,
318,
2536,
63,
2758,
8,
1000,
304,
272,
408,
272,
23615,
314,
7042,
5403,
2544,
14043,
314,
2295,
14,
272,
408,
272,
6701,
14,
371,
1509,
66,
8,
1751,
14,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
12,
283,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
358,
339,
340,
6701,
14,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
508,
283,
1832,
356,
267,
7042,
63,
3090,
275,
2519,
8,
1751,
12,
283,
44,
775,
21364,
2089,
63,
31956,
3279,
297,
283,
9887,
358,
398,
327,
6006,
365,
376,
4976,
543,
16776,
6158,
18,
519,
1167,
1367,
1465,
641,
31631,
267,
327,
315,
1314,
781,
15026,
664,
376,
3866,
7042,
2351,
14,
267,
327,
961,
365,
282,
1736,
13,
11659,
370,
4868,
626,
781,
664,
282,
1686,
2351,
14,
267,
3182,
275,
756,
267,
1967,
63,
13143,
275,
378,
267,
1830,
334,
1397,
3182,
9,
436,
1967,
63,
13143,
665,
9141,
63,
5600,
63,
31956,
3279,
63,
619,
12510,
9730,
26,
953,
327,
7190,
314,
7042,
436,
862,
370,
5684,
314,
2446,
2034,
288,
327,
982,
314,
7042,
21554,
1133,
506,
13075,
503,
288,
327,
314,
7042,
2351,
365,
3866,
12,
642,
911,
288,
327,
746,
282,
27104,
1726,
288
] |
[
199,
11930,
663,
1536,
367,
4729,
554,
2295,
14,
199,
624,
199,
199,
3,
26324,
26,
3507,
29,
37,
24827,
199,
3,
26324,
26,
3507,
29,
55,
1690,
969,
199,
199,
504,
4691,
84,
3683,
492,
2544,
12,
2410,
12,
6701,
199,
504,
2249,
25240,
14,
5750,
492,
27620,
199,
504,
2050,
492,
28138,
199,
504,
1639,
14,
1018,
14,
8110,
492,
1240,
63,
1531,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
19481,
14,
2330,
14,
3924,
492,
27104,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
16035,
63,
10732,
492,
1487,
5381,
17006,
199,
646,
4145,
199,
504,
1300,
772,
492,
3752,
875,
199,
504,
2022,
492,
16864,
199,
199,
504,
21878,
492,
13503,
3041,
199,
646,
9872,
14,
10012,
14,
1176,
199,
504,
9872,
14,
28160,
14,
1176,
492,
485,
9663,
16169,
199,
199,
3,
6006,
365,
376,
492,
4976,
1380,
1808,
1639,
13,
18373,
543,
4691,
84,
3683,
199,
3,
12230,
84,
3683,
15194,
626,
781,
787,
1808,
1639,
14,
2828,
14,
18373,
12,
199,
3,
1325,
314,
4618,
402,
314,
1145,
15194,
781,
787,
1808,
1639,
13,
18373,
199,
3,
334,
262,
6770,
12,
1639,
13,
7379,
436,
4154,
26834,
4514,
9,
199,
3,
4005,
7512,
642,
12,
781,
1104,
3775,
2955,
1725,
365,
4903,
12,
199,
3,
2066,
4660,
8925,
367,
1639,
14,
2828,
14,
18373,
199,
3,
370,
675,
2955,
1725,
14,
199,
893,
26,
272,
492,
2955,
1725,
272,
492,
2955,
1725,
14,
5586,
199,
2590,
3545,
26,
272,
986,
199,
2836,
26,
272,
492,
984,
272,
984,
14,
3112,
459,
1176,
14,
2828,
14,
18373,
418,
275,
2955,
1725,
272,
984,
14,
3112,
459,
1176,
14,
2828,
14,
18373,
14,
5586,
418,
275,
2955,
1725,
14,
5586,
199,
199,
10186,
275,
28138,
3460,
354,
3368,
199,
10186,
14,
815,
480,
19236,
314,
4691,
84,
3683,
4729,
554,
5343,
2044,
6322,
570,
12594,
199,
199,
4283,
63,
5600,
63,
31956,
3279,
63,
619,
12510,
9730,
275,
3388,
199,
13808,
63,
10484,
63,
8899,
275,
3388,
421,
199,
318,
664,
63,
2231,
3683,
76,
2101,
63,
2473,
63,
460,
63,
498,
837,
272,
408,
272,
1803,
314,
428,
65,
3683,
491,
2101,
3434,
436,
2879,
2870,
465,
663,
701,
3734,
2860,
272,
408,
272,
372,
2420,
2473,
582,
2202,
14,
4251,
53,
2089,
14,
362,
360,
11958,
659,
298,
2732,
13,
498,
582,
2202,
14,
4251,
53,
2089,
14,
362,
360,
11074,
63,
998,
21004,
421,
199,
318,
663,
63,
2231,
3683,
76,
2101,
63,
2423,
63,
1205,
8,
2423,
344,
12,
3032,
29,
549,
304,
272,
408,
272,
10729,
314,
3906,
2004,
641,
2937,
3683,
634,
2101,
272,
408,
272,
1101,
275,
664,
63,
2231,
3683,
76,
2101,
63,
2473,
63,
460,
63,
498,
342,
272,
1166,
275,
283,
1014,
921,
2231,
3683,
76,
2101,
14,
957,
15,
3911,
15,
86,
17,
19655,
6920,
30837,
908,
8,
888,
459,
2473,
995,
6701,
14,
2423,
344,
9,
272,
2396,
63,
1317,
275,
16864,
6333,
12070,
582,
3032,
1552,
272,
1300,
772,
875,
275,
3752,
875,
17519,
26,
11123,
908,
8,
888,
459,
2473,
995,
1101,
459,
2732,
13,
498,
5156,
4439,
17,
61,
272,
2323,
275,
2420,
11626,
582,
298,
6845,
8352,
908,
8,
1095,
772,
875,
6769,
272,
754,
275,
4145,
14,
524,
8,
633,
12,
666,
29,
2030,
63,
1317,
12,
2323,
29,
2139,
9,
272,
372,
754,
14,
1205,
63,
600,
508,
1926,
421,
199,
318,
1852,
63,
2231,
3683,
76,
2101,
63,
16035,
63,
10732,
837,
272,
408,
272,
1803,
282,
1487,
5381,
17006,
909,
5226,
370,
314,
3734,
2937,
3683,
2633,
272,
408,
272,
6387,
63,
10732,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
31956,
3279,
297,
1487,
5381,
17006,
14,
1244,
31364,
9,
272,
6387,
63,
10732,
459,
3246,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
17805,
358,
272,
6387,
63,
10732,
459,
1023,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
4612,
358,
272,
6387,
63,
10732,
459,
1782,
13,
466,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
10555,
358,
272,
6387,
63,
10732,
459,
354,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
12763,
358,
272,
6387,
63,
10732,
459,
1506,
418,
275,
2202,
14,
4251,
53,
2089,
14,
362,
360,
8248,
358,
272,
6387,
63,
10732,
459,
3722,
13,
5064,
13,
265,
13,
1529,
418,
275,
756,
272,
6387,
63,
10732,
459,
2231,
3683,
13,
350,
8286,
418,
275,
756,
272,
6387,
63,
10732,
459,
12685,
13,
1360,
418,
275,
715,
272,
6387,
63,
10732,
459,
3059,
13,
23269,
83,
418,
275,
715,
272,
6387,
63,
10732,
459,
15041,
13,
1023,
418,
275,
298,
18,
14,
1082,
14,
16,
2,
272,
6387,
63,
10732,
459,
988,
13,
5553,
418,
275,
15751,
272,
6387,
63,
10732,
459,
3455,
418,
275,
283,
3455,
15297,
7,
272,
372,
6387,
63,
10732,
421,
199,
32,
5182,
14,
32222,
199,
318,
2536,
63,
2758,
8,
1000,
304,
272,
408,
272,
23615,
314,
7042,
5403,
2544,
14043,
314,
2295,
14,
272,
408,
272,
6701,
14,
371,
1509,
66,
8,
1751,
14,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
12,
283,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
358,
339,
340,
6701,
14,
44,
775,
21364,
2089,
63,
899,
5304,
24967,
63,
9901,
508,
283,
1832,
356,
267,
7042,
63,
3090,
275,
2519,
8,
1751,
12,
283,
44,
775,
21364,
2089,
63,
31956,
3279,
297,
283,
9887,
358,
398,
327,
6006,
365,
376,
4976,
543,
16776,
6158,
18,
519,
1167,
1367,
1465,
641,
31631,
267,
327,
315,
1314,
781,
15026,
664,
376,
3866,
7042,
2351,
14,
267,
327,
961,
365,
282,
1736,
13,
11659,
370,
4868,
626,
781,
664,
282,
1686,
2351,
14,
267,
3182,
275,
756,
267,
1967,
63,
13143,
275,
378,
267,
1830,
334,
1397,
3182,
9,
436,
1967,
63,
13143,
665,
9141,
63,
5600,
63,
31956,
3279,
63,
619,
12510,
9730,
26,
953,
327,
7190,
314,
7042,
436,
862,
370,
5684,
314,
2446,
2034,
288,
327,
982,
314,
7042,
21554,
1133,
506,
13075,
503,
288,
327,
314,
7042,
2351,
365,
3866,
12,
642,
911,
288,
327,
746,
282,
27104,
1726,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lucadealfaro/crowdranker
|
models/keystore.py
|
1
|
2062
|
# -*- coding: utf-8 -*-
# Implementation of a key-value store API.
db.define_table('key_value_store',
Field('content', 'text'))
def keystore_write(v):
"""Writes a new string v to the key-value store, returning the string key."""
id = db.key_value_store.insert(content = v)
logger.info("inserting keystore key " + str(id) + " value " + str(v)[:20])
return str(id)
def keystore_read(k, default=None):
"""Returns the string read from the keystore for a key k."""
logger.info("Reading keystore key " + str(k))
try:
id = int(k)
except ValueError:
return default
except TypeError:
return default
v = db.key_value_store(id)
if v is None:
return default
return v.content
def keystore_multi_read(k_list, default=None):
"""Gets a list of keys to read and a default value, and returns a dictionary
mapping every key to the value read, using the default value if the value could
not be found."""
logger.info("Reading keystore keys: %r" % k_list)
r = {}
for k in k_list:
v = keystore_read(k, default=default)
r[k] = v
return r
def keystore_update(k, v):
"""Updates the keystore, replacing the previous value for key k
(if any) with value v. If the key k is invalid, creates a new key.
It returns the key that has been used."""
logger.info("Updating keystore for key " + str(k) + " and value: " + str(v)[:20])
try:
id = int(k)
except ValueError:
id = db.key_value_store.insert(content = v)
return str(id)
except TypeError:
id = db.key_value_store.insert(content = v)
return str(id)
db.key_value_store.update_or_insert(db.key_value_store.id == id, content = v)
return k
def keystore_delete(k):
"""Deletes the entry for key k, if present."""
logger.info("Requesting deletion of keystore key " + str(k))
try:
id = int(k)
except ValueError:
return
except TypeError:
return
db(db.key_value_store.id == id).delete()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
24425,
402,
282,
790,
13,
585,
3877,
3261,
14,
199,
199,
697,
14,
4640,
63,
1224,
360,
498,
63,
585,
63,
1617,
297,
272,
5024,
360,
1317,
297,
283,
505,
1333,
421,
199,
318,
28254,
63,
952,
8,
86,
304,
272,
408,
20908,
282,
892,
1059,
373,
370,
314,
790,
13,
585,
3877,
12,
8152,
314,
1059,
790,
1041,
272,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
272,
2512,
14,
815,
480,
3176,
316,
28254,
790,
298,
435,
620,
8,
344,
9,
435,
298,
574,
298,
435,
620,
8,
86,
18562,
1165,
566,
272,
372,
620,
8,
344,
9,
421,
199,
318,
28254,
63,
739,
8,
75,
12,
849,
29,
403,
304,
272,
408,
3407,
314,
1059,
1586,
687,
314,
28254,
367,
282,
790,
1022,
1041,
272,
2512,
14,
815,
480,
20568,
28254,
790,
298,
435,
620,
8,
75,
430,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
372,
849,
272,
871,
3146,
26,
267,
372,
849,
272,
373,
275,
1592,
14,
498,
63,
585,
63,
1617,
8,
344,
9,
272,
340,
373,
365,
488,
26,
267,
372,
849,
272,
372,
373,
14,
1317,
421,
199,
318,
28254,
63,
3029,
63,
739,
8,
75,
63,
513,
12,
849,
29,
403,
304,
272,
408,
14426,
282,
769,
402,
2883,
370,
1586,
436,
282,
849,
574,
12,
436,
2529,
282,
2600,
272,
4412,
4036,
790,
370,
314,
574,
1586,
12,
1808,
314,
849,
574,
340,
314,
574,
4293,
272,
440,
506,
1911,
1041,
272,
2512,
14,
815,
480,
20568,
28254,
2883,
26,
450,
82,
2,
450,
1022,
63,
513,
9,
272,
519,
275,
1052,
272,
367,
1022,
315,
1022,
63,
513,
26,
267,
373,
275,
28254,
63,
739,
8,
75,
12,
849,
29,
885,
9,
267,
519,
59,
75,
61,
275,
373,
272,
372,
519,
421,
199,
318,
28254,
63,
873,
8,
75,
12,
373,
304,
272,
408,
16083,
314,
28254,
12,
15810,
314,
4136,
574,
367,
790,
1022,
272,
334,
692,
1263,
9,
543,
574,
373,
14,
221,
982,
314,
790,
1022,
365,
3866,
12,
8491,
282,
892,
790,
14,
5591,
2779,
2529,
314,
790,
626,
965,
2757,
1202,
1041,
272,
2512,
14,
815,
480,
24993,
28254,
367,
790,
298,
435,
620,
8,
75,
9,
435,
298,
436,
574,
26,
298,
435,
620,
8,
86,
18562,
1165,
566,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
267,
372,
620,
8,
344,
9,
272,
871,
3146,
26,
267,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
267,
372,
620,
8,
344,
9,
272,
1592,
14,
498,
63,
585,
63,
1617,
14,
873,
63,
269,
63,
3176,
8,
697,
14,
498,
63,
585,
63,
1617,
14,
344,
508,
1305,
12,
1564,
275,
373,
9,
272,
372,
1022,
421,
199,
318,
28254,
63,
1807,
8,
75,
304,
272,
408,
26372,
314,
2397,
367,
790,
1022,
12,
340,
3451,
1041,
272,
2512,
14,
815,
480,
2017,
316,
14068,
402,
28254,
790,
298,
435,
620,
8,
75,
430,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
372,
272,
871,
3146,
26,
267,
372,
272,
1592,
8,
697,
14,
498,
63,
585,
63,
1617,
14,
344,
508,
1305,
680,
1807,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
24425,
402,
282,
790,
13,
585,
3877,
3261,
14,
199,
199,
697,
14,
4640,
63,
1224,
360,
498,
63,
585,
63,
1617,
297,
272,
5024,
360,
1317,
297,
283,
505,
1333,
421,
199,
318,
28254,
63,
952,
8,
86,
304,
272,
408,
20908,
282,
892,
1059,
373,
370,
314,
790,
13,
585,
3877,
12,
8152,
314,
1059,
790,
1041,
272,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
272,
2512,
14,
815,
480,
3176,
316,
28254,
790,
298,
435,
620,
8,
344,
9,
435,
298,
574,
298,
435,
620,
8,
86,
18562,
1165,
566,
272,
372,
620,
8,
344,
9,
421,
199,
318,
28254,
63,
739,
8,
75,
12,
849,
29,
403,
304,
272,
408,
3407,
314,
1059,
1586,
687,
314,
28254,
367,
282,
790,
1022,
1041,
272,
2512,
14,
815,
480,
20568,
28254,
790,
298,
435,
620,
8,
75,
430,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
372,
849,
272,
871,
3146,
26,
267,
372,
849,
272,
373,
275,
1592,
14,
498,
63,
585,
63,
1617,
8,
344,
9,
272,
340,
373,
365,
488,
26,
267,
372,
849,
272,
372,
373,
14,
1317,
421,
199,
318,
28254,
63,
3029,
63,
739,
8,
75,
63,
513,
12,
849,
29,
403,
304,
272,
408,
14426,
282,
769,
402,
2883,
370,
1586,
436,
282,
849,
574,
12,
436,
2529,
282,
2600,
272,
4412,
4036,
790,
370,
314,
574,
1586,
12,
1808,
314,
849,
574,
340,
314,
574,
4293,
272,
440,
506,
1911,
1041,
272,
2512,
14,
815,
480,
20568,
28254,
2883,
26,
450,
82,
2,
450,
1022,
63,
513,
9,
272,
519,
275,
1052,
272,
367,
1022,
315,
1022,
63,
513,
26,
267,
373,
275,
28254,
63,
739,
8,
75,
12,
849,
29,
885,
9,
267,
519,
59,
75,
61,
275,
373,
272,
372,
519,
421,
199,
318,
28254,
63,
873,
8,
75,
12,
373,
304,
272,
408,
16083,
314,
28254,
12,
15810,
314,
4136,
574,
367,
790,
1022,
272,
334,
692,
1263,
9,
543,
574,
373,
14,
221,
982,
314,
790,
1022,
365,
3866,
12,
8491,
282,
892,
790,
14,
5591,
2779,
2529,
314,
790,
626,
965,
2757,
1202,
1041,
272,
2512,
14,
815,
480,
24993,
28254,
367,
790,
298,
435,
620,
8,
75,
9,
435,
298,
436,
574,
26,
298,
435,
620,
8,
86,
18562,
1165,
566,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
267,
372,
620,
8,
344,
9,
272,
871,
3146,
26,
267,
1305,
275,
1592,
14,
498,
63,
585,
63,
1617,
14,
3176,
8,
1317,
275,
373,
9,
267,
372,
620,
8,
344,
9,
272,
1592,
14,
498,
63,
585,
63,
1617,
14,
873,
63,
269,
63,
3176,
8,
697,
14,
498,
63,
585,
63,
1617,
14,
344,
508,
1305,
12,
1564,
275,
373,
9,
272,
372,
1022,
421,
199,
318,
28254,
63,
1807,
8,
75,
304,
272,
408,
26372,
314,
2397,
367,
790,
1022,
12,
340,
3451,
1041,
272,
2512,
14,
815,
480,
2017,
316,
14068,
402,
28254,
790,
298,
435,
620,
8,
75,
430,
272,
862,
26,
267,
1305,
275,
1109,
8,
75,
9,
272,
871,
1722,
26,
267,
372,
272,
871,
3146,
26,
267,
372,
272,
1592,
8,
697,
14,
498,
63,
585,
63,
1617,
14,
344,
508,
1305,
680,
1807,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
suqinhuang/tp-qemu
|
qemu/tests/unittest_kvmctl.py
|
16
|
1028
|
import os
from autotest.client import utils
from autotest.client.shared import error
def run(test, params, env):
"""
This is kvm userspace unit test, use kvm test harness kvmctl load binary
test case file to test various functions of the kvm kernel module.
The output of all unit tests can be found in the test result dir.
:param test: QEMU test object.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
"""
case = params["case"]
srcdir = params.get("srcdir", test.srcdir)
unit_dir = os.path.join(srcdir, "kvm_userspace", "kvm", "user")
if not os.path.isdir(unit_dir):
os.makedirs(unit_dir)
os.chdir(unit_dir)
cmd = "./kvmctl test/x86/bootstrap test/x86/%s.flat" % case
try:
results = utils.system_output(cmd)
except error.CmdError:
raise error.TestFail("Unit test %s failed" % case)
result_file = os.path.join(test.resultsdir, case)
utils.open_write_close(result_file, results)
|
gpl-2.0
|
[
646,
747,
199,
504,
2599,
396,
14,
1258,
492,
3778,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
421,
199,
318,
1255,
8,
396,
12,
1862,
12,
2589,
304,
272,
408,
272,
961,
365,
1022,
2611,
922,
2638,
4137,
511,
12,
675,
1022,
2611,
511,
20458,
1022,
2611,
8077,
2248,
3366,
272,
511,
1930,
570,
370,
511,
7750,
3423,
402,
314,
1022,
2611,
5114,
859,
14,
272,
710,
1072,
402,
1006,
4137,
2295,
883,
506,
1911,
315,
314,
511,
754,
2935,
14,
339,
520,
635,
511,
26,
1413,
2769,
53,
511,
909,
14,
272,
520,
635,
1862,
26,
11932,
543,
314,
511,
2633,
14,
272,
520,
635,
2589,
26,
11932,
543,
511,
3734,
14,
272,
408,
272,
1930,
275,
1862,
905,
2546,
937,
272,
31967,
275,
1862,
14,
362,
480,
17878,
401,
511,
14,
17878,
9,
272,
4137,
63,
694,
275,
747,
14,
515,
14,
904,
8,
17878,
12,
298,
29272,
63,
751,
2638,
401,
298,
29272,
401,
298,
751,
531,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
3248,
63,
694,
304,
267,
747,
14,
8347,
8,
3248,
63,
694,
9,
272,
747,
14,
8563,
8,
3248,
63,
694,
9,
339,
2088,
275,
26069,
29272,
8077,
511,
15,
88,
1184,
15,
11146,
511,
15,
88,
1184,
3149,
83,
14,
7088,
2,
450,
1930,
272,
862,
26,
267,
2058,
275,
3778,
14,
2253,
63,
1199,
8,
1760,
9,
272,
871,
1125,
14,
7874,
547,
26,
267,
746,
1125,
14,
774,
4874,
480,
5072,
511,
450,
83,
3405,
2,
450,
1930,
9,
339,
754,
63,
493,
275,
747,
14,
515,
14,
904,
8,
396,
14,
2604,
694,
12,
1930,
9,
272,
3778,
14,
1490,
63,
952,
63,
1600,
8,
1099,
63,
493,
12,
2058,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
504,
2599,
396,
14,
1258,
492,
3778,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
421,
199,
318,
1255,
8,
396,
12,
1862,
12,
2589,
304,
272,
408,
272,
961,
365,
1022,
2611,
922,
2638,
4137,
511,
12,
675,
1022,
2611,
511,
20458,
1022,
2611,
8077,
2248,
3366,
272,
511,
1930,
570,
370,
511,
7750,
3423,
402,
314,
1022,
2611,
5114,
859,
14,
272,
710,
1072,
402,
1006,
4137,
2295,
883,
506,
1911,
315,
314,
511,
754,
2935,
14,
339,
520,
635,
511,
26,
1413,
2769,
53,
511,
909,
14,
272,
520,
635,
1862,
26,
11932,
543,
314,
511,
2633,
14,
272,
520,
635,
2589,
26,
11932,
543,
511,
3734,
14,
272,
408,
272,
1930,
275,
1862,
905,
2546,
937,
272,
31967,
275,
1862,
14,
362,
480,
17878,
401,
511,
14,
17878,
9,
272,
4137,
63,
694,
275,
747,
14,
515,
14,
904,
8,
17878,
12,
298,
29272,
63,
751,
2638,
401,
298,
29272,
401,
298,
751,
531,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
3248,
63,
694,
304,
267,
747,
14,
8347,
8,
3248,
63,
694,
9,
272,
747,
14,
8563,
8,
3248,
63,
694,
9,
339,
2088,
275,
26069,
29272,
8077,
511,
15,
88,
1184,
15,
11146,
511,
15,
88,
1184,
3149,
83,
14,
7088,
2,
450,
1930,
272,
862,
26,
267,
2058,
275,
3778,
14,
2253,
63,
1199,
8,
1760,
9,
272,
871,
1125,
14,
7874,
547,
26,
267,
746,
1125,
14,
774,
4874,
480,
5072,
511,
450,
83,
3405,
2,
450,
1930,
9,
339,
754,
63,
493,
275,
747,
14,
515,
14,
904,
8,
396,
14,
2604,
694,
12,
1930,
9,
272,
3778,
14,
1490,
63,
952,
63,
1600,
8,
1099,
63,
493,
12,
2058,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jaechankim/namebench
|
nb_third_party/dns/rdtypes/ANY/CNAME.py
|
248
|
1092
|
# Copyright (C) 2003-2007, 2009, 2010 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
# provided that the above copyright notice and this permission notice
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import dns.rdtypes.nsbase
class CNAME(dns.rdtypes.nsbase.NSBase):
"""CNAME record
Note: although CNAME is officially a singleton type, dnspython allows
non-singleton CNAME rdatasets because such sets have been commonly
used by BIND and other nameservers for load balancing."""
pass
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
6715,
14,
82,
5717,
14,
561,
1095,
199,
199,
533,
445,
2339,
8,
5797,
14,
82,
5717,
14,
561,
1095,
14,
2709,
1563,
304,
272,
408,
35,
2339,
2777,
339,
3390,
26,
22160,
445,
2339,
365,
402,
4294,
1183,
282,
19768,
730,
12,
6715,
1548,
6127,
272,
2222,
13,
24675,
445,
2339,
519,
12281,
2952,
4066,
5951,
1172,
2757,
28829,
272,
1202,
701,
699,
3192,
436,
1163,
536,
5871,
367,
2248,
29300,
1041,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
13004,
13,
9488,
12,
8937,
12,
7129,
653,
676,
262,
453,
12,
3277,
14,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
436,
2399,
199,
3,
3794,
367,
1263,
12016,
543,
503,
1928,
14751,
365,
11882,
10009,
12,
199,
3,
2741,
626,
314,
3432,
4248,
4245,
436,
642,
4983,
4245,
199,
3,
7468,
315,
1006,
6866,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
4825,
4896,
2639,
8990,
51,
11727,
2990,
199,
3,
1663,
14142,
7816,
2296,
5749,
4141,
6931,
11727,
5292,
2990,
1634,
199,
3,
3169,
2401,
3092,
14,
1621,
4825,
6461,
7000,
4825,
4896,
2639,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
8703,
12,
9168,
12,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
7061,
1621,
1261,
199,
3,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
9612,
12,
7043,
5738,
199,
3,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
13873,
30340,
1634,
5749,
4141,
14,
199,
199,
646,
6715,
14,
82,
5717,
14,
561,
1095,
199,
199,
533,
445,
2339,
8,
5797,
14,
82,
5717,
14,
561,
1095,
14,
2709,
1563,
304,
272,
408,
35,
2339,
2777,
339,
3390,
26,
22160,
445,
2339,
365,
402,
4294,
1183,
282,
19768,
730,
12,
6715,
1548,
6127,
272,
2222,
13,
24675,
445,
2339,
519,
12281,
2952,
4066,
5951,
1172,
2757,
28829,
272,
1202,
701,
699,
3192,
436,
1163,
536,
5871,
367,
2248,
29300,
1041,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
ferabra/edx-platform
|
cms/djangoapps/contentstore/tests/test_crud.py
|
60
|
6006
|
import unittest
from xmodule import templates
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DATA_SPLIT_MODULESTORE
from xmodule.course_module import CourseDescriptor
from xmodule.seq_module import SequenceDescriptor
from xmodule.capa_module import CapaDescriptor
from xmodule.html_module import HtmlDescriptor
from xmodule.modulestore.exceptions import DuplicateCourseError
class TemplateTests(ModuleStoreTestCase):
"""
Test finding and using the templates (boilerplates) for xblocks.
"""
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def test_get_templates(self):
found = templates.all_templates()
self.assertIsNotNone(found.get('course'))
self.assertIsNotNone(found.get('about'))
self.assertIsNotNone(found.get('html'))
self.assertIsNotNone(found.get('problem'))
self.assertEqual(len(found.get('course')), 0)
self.assertEqual(len(found.get('about')), 1)
self.assertGreaterEqual(len(found.get('html')), 2)
self.assertGreaterEqual(len(found.get('problem')), 10)
dropdown = None
for template in found['problem']:
self.assertIn('metadata', template)
self.assertIn('display_name', template['metadata'])
if template['metadata']['display_name'] == 'Dropdown':
dropdown = template
break
self.assertIsNotNone(dropdown)
self.assertIn('markdown', dropdown['metadata'])
self.assertIn('data', dropdown)
self.assertRegexpMatches(dropdown['metadata']['markdown'], r'^Dropdown.*')
self.assertRegexpMatches(dropdown['data'], r'<problem>\s*<p>Dropdown.*')
def test_get_some_templates(self):
self.assertEqual(len(SequenceDescriptor.templates()), 0)
self.assertGreater(len(HtmlDescriptor.templates()), 0)
self.assertIsNone(SequenceDescriptor.get_template('doesntexist.yaml'))
self.assertIsNone(HtmlDescriptor.get_template('doesntexist.yaml'))
self.assertIsNotNone(HtmlDescriptor.get_template('announcement.yaml'))
def test_factories(self):
test_course = CourseFactory.create(
org='testx',
course='course',
run='2014',
display_name='fun test course',
user_id='testbot'
)
self.assertIsInstance(test_course, CourseDescriptor)
self.assertEqual(test_course.display_name, 'fun test course')
course_from_store = self.store.get_course(test_course.id)
self.assertEqual(course_from_store.id.org, 'testx')
self.assertEqual(course_from_store.id.course, 'course')
self.assertEqual(course_from_store.id.run, '2014')
test_chapter = ItemFactory.create(
parent_location=test_course.location,
category='chapter',
display_name='chapter 1'
)
self.assertIsInstance(test_chapter, SequenceDescriptor)
# refetch parent which should now point to child
test_course = self.store.get_course(test_course.id.version_agnostic())
self.assertIn(test_chapter.location, test_course.children)
with self.assertRaises(DuplicateCourseError):
CourseFactory.create(
org='testx',
course='course',
run='2014',
display_name='fun test course',
user_id='testbot'
)
def test_temporary_xblocks(self):
"""
Test create_xblock to create non persisted xblocks
"""
test_course = CourseFactory.create(
course='course', run='2014', org='testx',
display_name='fun test course', user_id='testbot'
)
test_chapter = self.store.create_xblock(
test_course.system, test_course.id, 'chapter', fields={'display_name': 'chapter n'},
parent_xblock=test_course
)
self.assertIsInstance(test_chapter, SequenceDescriptor)
self.assertEqual(test_chapter.display_name, 'chapter n')
self.assertIn(test_chapter, test_course.get_children())
# test w/ a definition (e.g., a problem)
test_def_content = '<problem>boo</problem>'
test_problem = self.store.create_xblock(
test_course.system, test_course.id, 'problem', fields={'data': test_def_content},
parent_xblock=test_chapter
)
self.assertIsInstance(test_problem, CapaDescriptor)
self.assertEqual(test_problem.data, test_def_content)
self.assertIn(test_problem, test_chapter.get_children())
test_problem.display_name = 'test problem'
self.assertEqual(test_problem.display_name, 'test problem')
def test_delete_course(self):
test_course = CourseFactory.create(
org='edu.harvard',
course='history',
run='doomed',
display_name='doomed test course',
user_id='testbot')
ItemFactory.create(
parent_location=test_course.location,
category='chapter',
display_name='chapter 1'
)
id_locator = test_course.id.for_branch(ModuleStoreEnum.BranchName.draft)
# verify it can be retrieved by id
self.assertIsInstance(self.store.get_course(id_locator), CourseDescriptor)
# TODO reenable when split_draft supports getting specific versions
# guid_locator = test_course.location.course_agnostic()
# Verify it can be retrieved by guid
# self.assertIsInstance(self.store.get_item(guid_locator), CourseDescriptor)
self.store.delete_course(id_locator, 'testbot')
# Test can no longer retrieve by id.
self.assertIsNone(self.store.get_course(id_locator))
# But can retrieve by guid -- same TODO as above
# self.assertIsInstance(self.store.get_item(guid_locator), CourseDescriptor)
|
agpl-3.0
|
[
646,
2882,
199,
199,
504,
9872,
492,
7009,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
12,
19319,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
12,
7393,
63,
3998,
63,
30538,
63,
27011,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
3610,
63,
578,
492,
10975,
4311,
199,
504,
9872,
14,
18182,
63,
578,
492,
8790,
387,
4311,
199,
504,
9872,
14,
1360,
63,
578,
492,
20880,
4311,
199,
504,
9872,
14,
10012,
14,
3924,
492,
23942,
6979,
547,
421,
199,
533,
5458,
2925,
8,
27863,
304,
272,
408,
272,
1379,
17196,
436,
1808,
314,
7009,
334,
656,
27025,
83,
9,
367,
671,
4166,
14,
272,
408,
272,
30920,
1293,
23278,
275,
7393,
63,
3998,
63,
30538,
63,
27011,
339,
347,
511,
63,
362,
63,
5876,
8,
277,
304,
267,
1911,
275,
7009,
14,
452,
63,
5876,
342,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
1972,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
10254,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
1360,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
6462,
1333,
267,
291,
14,
629,
8,
552,
8,
4214,
14,
362,
360,
1972,
3855,
378,
9,
267,
291,
14,
629,
8,
552,
8,
4214,
14,
362,
360,
10254,
3855,
413,
9,
267,
291,
14,
26875,
8,
552,
8,
4214,
14,
362,
360,
1360,
3855,
499,
9,
267,
291,
14,
26875,
8,
552,
8,
4214,
14,
362,
360,
6462,
3855,
1616,
9,
267,
5978,
2110,
275,
488,
267,
367,
1978,
315,
1911,
459,
6462,
2565,
288,
291,
14,
4080,
360,
2343,
297,
1978,
9,
288,
291,
14,
4080,
360,
2918,
63,
354,
297,
1978,
459,
2343,
1105,
288,
340,
1978,
459,
2343,
2545,
2918,
63,
354,
418,
508,
283,
11070,
2110,
356,
355,
5978,
2110,
275,
1978,
355,
2059,
267,
291,
14,
10389,
8,
29595,
9,
267,
291,
14,
4080,
360,
15653,
297,
5978,
2110,
459,
2343,
1105,
267,
291,
14,
4080,
360,
576,
297,
5978,
2110,
9,
267,
291,
14,
26672,
8,
29595,
459,
2343,
2545,
15653,
995,
519,
4289,
11070,
2110,
24915,
267,
291,
14,
26672,
8,
29595,
459,
576,
995,
519,
7601,
6462,
3072,
83,
10,
28,
80,
30,
11070,
2110,
24915,
339,
347,
511,
63,
362,
63,
3972,
63,
5876,
8,
277,
304,
267,
291,
14,
629,
8,
552,
8,
5826,
4311,
14,
5876,
4000,
378,
9,
267,
291,
14,
15070,
8,
552,
8,
12957,
4311,
14,
5876,
4000,
378,
9,
267,
291,
14,
7702,
8,
5826,
4311,
14,
362,
63,
1160,
360,
30977,
3858,
631,
14,
5963,
1333,
267,
291,
14,
7702,
8,
12957,
4311,
14,
362,
63,
1160,
360,
30977,
3858,
631,
14,
5963,
1333,
267,
291,
14,
10389,
8,
12957,
4311,
14,
362,
63,
1160,
360,
17803,
434,
14,
5963,
1333,
339,
347,
511,
63,
15406,
8,
277,
304,
267,
511,
63,
1972,
275,
17862,
14,
981,
8,
288,
5981,
534,
396,
88,
297,
288,
2518,
534,
1972,
297,
288,
1255,
534,
7280,
297,
288,
2929,
63,
354,
534,
7036,
511,
2518,
297,
288,
922,
63,
344,
534,
396,
3018,
7,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
1972,
12,
5531,
4311,
9,
267,
291,
14,
629,
8,
396,
63,
1972,
14,
2918,
63,
354,
12,
283,
7036,
511,
2518,
358,
267,
2518,
63,
504,
63,
1617,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
396,
63,
1972,
14,
344,
9,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1308,
12,
283,
396,
88,
358,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1972,
12,
283,
1972,
358,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1065,
12,
283,
7280,
358,
398,
511,
63,
11316,
275,
19319,
14,
981,
8,
288,
1676,
63,
1985,
29,
396,
63,
1972,
14,
1985,
12,
288,
4637,
534,
11316,
297,
288,
2929,
63,
354,
534,
11316,
413,
7,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
11316,
12,
10975,
4311,
9,
267,
327,
2984,
2367,
1676,
1314,
1077,
3063,
2376,
370,
1982,
267,
511,
63,
1972,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
396,
63,
1972,
14,
344,
14,
1023,
63,
643,
19075,
1012,
267,
291,
14,
4080,
8,
396,
63,
11316,
14,
1985,
12,
511,
63,
1972,
14,
3223,
9,
398,
543,
291,
14,
1855,
8,
14773,
6979,
547,
304,
288,
17862,
14,
981,
8,
355,
5981,
534,
396,
88,
297,
355,
2518,
534,
1972,
297,
355,
1255,
534,
7280,
297,
355,
2929,
63,
354,
534,
7036,
511,
2518,
297,
355,
922,
63,
344,
534,
396,
3018,
7,
288,
776,
339,
347,
511,
63,
13555,
63,
88,
4166,
8,
277,
304,
267,
408,
267,
1379,
1218,
63,
11283,
370,
1218,
2222,
1126,
24925,
671,
4166,
267,
408,
267,
511,
63,
1972,
275,
17862,
14,
981,
8,
288,
2518,
534,
1972,
297,
1255,
534,
7280,
297,
5981,
534,
396,
88,
297,
288,
2929,
63,
354,
534,
7036,
511,
2518,
297,
922,
63,
344,
534,
396,
3018,
7,
267,
776,
398,
511,
63,
11316,
275,
291,
14,
1617,
14,
981,
63,
11283,
8,
288,
511,
63,
1972,
14,
2253,
12,
511,
63,
1972,
14,
344,
12,
283,
11316,
297,
1504,
3713,
2918,
63,
354,
356,
283,
11316,
302,
2267,
288,
1676,
63,
11283,
29,
396,
63,
1972,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
11316,
12,
10975,
4311,
9,
267,
291,
14,
629,
8,
396,
63,
11316,
14,
2918,
63,
354,
12,
283,
11316,
302,
358,
267,
291,
14,
4080,
8,
396,
63,
11316,
12,
511,
63,
1972,
14,
362,
63,
3223,
1012,
398,
327,
511,
336,
15,
282,
5492,
334,
69,
14,
71,
2020,
282,
5160,
9,
267,
511,
63,
318,
63,
1317,
275,
2650,
6462,
30,
15056,
1108,
6462,
3524,
267,
511,
63,
6462,
275,
291,
14,
1617,
14,
981,
63,
11283,
8,
288,
511,
63,
1972,
14,
2253,
12,
511,
63,
1972,
14,
344,
12,
283,
6462,
297,
1504,
3713,
576,
356,
511,
63,
318,
63,
1317,
1386,
288,
1676,
63,
11283,
29
] |
[
2882,
199,
199,
504,
9872,
492,
7009,
199,
504,
9872,
14,
10012,
492,
23431,
199,
504,
9872,
14,
10012,
14,
2219,
14,
15406,
492,
17862,
12,
19319,
199,
504,
9872,
14,
10012,
14,
2219,
14,
1176,
63,
1208,
492,
17996,
1746,
12,
7393,
63,
3998,
63,
30538,
63,
27011,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
3610,
63,
578,
492,
10975,
4311,
199,
504,
9872,
14,
18182,
63,
578,
492,
8790,
387,
4311,
199,
504,
9872,
14,
1360,
63,
578,
492,
20880,
4311,
199,
504,
9872,
14,
10012,
14,
3924,
492,
23942,
6979,
547,
421,
199,
533,
5458,
2925,
8,
27863,
304,
272,
408,
272,
1379,
17196,
436,
1808,
314,
7009,
334,
656,
27025,
83,
9,
367,
671,
4166,
14,
272,
408,
272,
30920,
1293,
23278,
275,
7393,
63,
3998,
63,
30538,
63,
27011,
339,
347,
511,
63,
362,
63,
5876,
8,
277,
304,
267,
1911,
275,
7009,
14,
452,
63,
5876,
342,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
1972,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
10254,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
1360,
1333,
267,
291,
14,
10389,
8,
4214,
14,
362,
360,
6462,
1333,
267,
291,
14,
629,
8,
552,
8,
4214,
14,
362,
360,
1972,
3855,
378,
9,
267,
291,
14,
629,
8,
552,
8,
4214,
14,
362,
360,
10254,
3855,
413,
9,
267,
291,
14,
26875,
8,
552,
8,
4214,
14,
362,
360,
1360,
3855,
499,
9,
267,
291,
14,
26875,
8,
552,
8,
4214,
14,
362,
360,
6462,
3855,
1616,
9,
267,
5978,
2110,
275,
488,
267,
367,
1978,
315,
1911,
459,
6462,
2565,
288,
291,
14,
4080,
360,
2343,
297,
1978,
9,
288,
291,
14,
4080,
360,
2918,
63,
354,
297,
1978,
459,
2343,
1105,
288,
340,
1978,
459,
2343,
2545,
2918,
63,
354,
418,
508,
283,
11070,
2110,
356,
355,
5978,
2110,
275,
1978,
355,
2059,
267,
291,
14,
10389,
8,
29595,
9,
267,
291,
14,
4080,
360,
15653,
297,
5978,
2110,
459,
2343,
1105,
267,
291,
14,
4080,
360,
576,
297,
5978,
2110,
9,
267,
291,
14,
26672,
8,
29595,
459,
2343,
2545,
15653,
995,
519,
4289,
11070,
2110,
24915,
267,
291,
14,
26672,
8,
29595,
459,
576,
995,
519,
7601,
6462,
3072,
83,
10,
28,
80,
30,
11070,
2110,
24915,
339,
347,
511,
63,
362,
63,
3972,
63,
5876,
8,
277,
304,
267,
291,
14,
629,
8,
552,
8,
5826,
4311,
14,
5876,
4000,
378,
9,
267,
291,
14,
15070,
8,
552,
8,
12957,
4311,
14,
5876,
4000,
378,
9,
267,
291,
14,
7702,
8,
5826,
4311,
14,
362,
63,
1160,
360,
30977,
3858,
631,
14,
5963,
1333,
267,
291,
14,
7702,
8,
12957,
4311,
14,
362,
63,
1160,
360,
30977,
3858,
631,
14,
5963,
1333,
267,
291,
14,
10389,
8,
12957,
4311,
14,
362,
63,
1160,
360,
17803,
434,
14,
5963,
1333,
339,
347,
511,
63,
15406,
8,
277,
304,
267,
511,
63,
1972,
275,
17862,
14,
981,
8,
288,
5981,
534,
396,
88,
297,
288,
2518,
534,
1972,
297,
288,
1255,
534,
7280,
297,
288,
2929,
63,
354,
534,
7036,
511,
2518,
297,
288,
922,
63,
344,
534,
396,
3018,
7,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
1972,
12,
5531,
4311,
9,
267,
291,
14,
629,
8,
396,
63,
1972,
14,
2918,
63,
354,
12,
283,
7036,
511,
2518,
358,
267,
2518,
63,
504,
63,
1617,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
396,
63,
1972,
14,
344,
9,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1308,
12,
283,
396,
88,
358,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1972,
12,
283,
1972,
358,
267,
291,
14,
629,
8,
1972,
63,
504,
63,
1617,
14,
344,
14,
1065,
12,
283,
7280,
358,
398,
511,
63,
11316,
275,
19319,
14,
981,
8,
288,
1676,
63,
1985,
29,
396,
63,
1972,
14,
1985,
12,
288,
4637,
534,
11316,
297,
288,
2929,
63,
354,
534,
11316,
413,
7,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
11316,
12,
10975,
4311,
9,
267,
327,
2984,
2367,
1676,
1314,
1077,
3063,
2376,
370,
1982,
267,
511,
63,
1972,
275,
291,
14,
1617,
14,
362,
63,
1972,
8,
396,
63,
1972,
14,
344,
14,
1023,
63,
643,
19075,
1012,
267,
291,
14,
4080,
8,
396,
63,
11316,
14,
1985,
12,
511,
63,
1972,
14,
3223,
9,
398,
543,
291,
14,
1855,
8,
14773,
6979,
547,
304,
288,
17862,
14,
981,
8,
355,
5981,
534,
396,
88,
297,
355,
2518,
534,
1972,
297,
355,
1255,
534,
7280,
297,
355,
2929,
63,
354,
534,
7036,
511,
2518,
297,
355,
922,
63,
344,
534,
396,
3018,
7,
288,
776,
339,
347,
511,
63,
13555,
63,
88,
4166,
8,
277,
304,
267,
408,
267,
1379,
1218,
63,
11283,
370,
1218,
2222,
1126,
24925,
671,
4166,
267,
408,
267,
511,
63,
1972,
275,
17862,
14,
981,
8,
288,
2518,
534,
1972,
297,
1255,
534,
7280,
297,
5981,
534,
396,
88,
297,
288,
2929,
63,
354,
534,
7036,
511,
2518,
297,
922,
63,
344,
534,
396,
3018,
7,
267,
776,
398,
511,
63,
11316,
275,
291,
14,
1617,
14,
981,
63,
11283,
8,
288,
511,
63,
1972,
14,
2253,
12,
511,
63,
1972,
14,
344,
12,
283,
11316,
297,
1504,
3713,
2918,
63,
354,
356,
283,
11316,
302,
2267,
288,
1676,
63,
11283,
29,
396,
63,
1972,
267,
776,
267,
291,
14,
6926,
8,
396,
63,
11316,
12,
10975,
4311,
9,
267,
291,
14,
629,
8,
396,
63,
11316,
14,
2918,
63,
354,
12,
283,
11316,
302,
358,
267,
291,
14,
4080,
8,
396,
63,
11316,
12,
511,
63,
1972,
14,
362,
63,
3223,
1012,
398,
327,
511,
336,
15,
282,
5492,
334,
69,
14,
71,
2020,
282,
5160,
9,
267,
511,
63,
318,
63,
1317,
275,
2650,
6462,
30,
15056,
1108,
6462,
3524,
267,
511,
63,
6462,
275,
291,
14,
1617,
14,
981,
63,
11283,
8,
288,
511,
63,
1972,
14,
2253,
12,
511,
63,
1972,
14,
344,
12,
283,
6462,
297,
1504,
3713,
576,
356,
511,
63,
318,
63,
1317,
1386,
288,
1676,
63,
11283,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
Open-Source-Coins/mry
|
contrib/pyminer/pyminer.py
|
385
|
6434
|
#!/usr/bin/python
#
# Copyright (c) 2011 The Bitcoin developers
# Distributed under the MIT/X11 software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
import time
import json
import pprint
import hashlib
import struct
import re
import base64
import httplib
import sys
from multiprocessing import Process
ERR_SLEEP = 15
MAX_NONCE = 1000000L
settings = {}
pp = pprint.PrettyPrinter(indent=4)
class BitcoinRPC:
OBJID = 1
def __init__(self, host, port, username, password):
authpair = "%s:%s" % (username, password)
self.authhdr = "Basic %s" % (base64.b64encode(authpair))
self.conn = httplib.HTTPConnection(host, port, False, 30)
def rpc(self, method, params=None):
self.OBJID += 1
obj = { 'version' : '1.1',
'method' : method,
'id' : self.OBJID }
if params is None:
obj['params'] = []
else:
obj['params'] = params
self.conn.request('POST', '/', json.dumps(obj),
{ 'Authorization' : self.authhdr,
'Content-type' : 'application/json' })
resp = self.conn.getresponse()
if resp is None:
print "JSON-RPC: no response"
return None
body = resp.read()
resp_obj = json.loads(body)
if resp_obj is None:
print "JSON-RPC: cannot JSON-decode body"
return None
if 'error' in resp_obj and resp_obj['error'] != None:
return resp_obj['error']
if 'result' not in resp_obj:
print "JSON-RPC: no result in object"
return None
return resp_obj['result']
def getblockcount(self):
return self.rpc('getblockcount')
def getwork(self, data=None):
return self.rpc('getwork', data)
def uint32(x):
return x & 0xffffffffL
def bytereverse(x):
return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
(((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
def bufreverse(in_buf):
out_words = []
for i in range(0, len(in_buf), 4):
word = struct.unpack('@I', in_buf[i:i+4])[0]
out_words.append(struct.pack('@I', bytereverse(word)))
return ''.join(out_words)
def wordreverse(in_buf):
out_words = []
for i in range(0, len(in_buf), 4):
out_words.append(in_buf[i:i+4])
out_words.reverse()
return ''.join(out_words)
class Miner:
def __init__(self, id):
self.id = id
self.max_nonce = MAX_NONCE
def work(self, datastr, targetstr):
# decode work data hex string to binary
static_data = datastr.decode('hex')
static_data = bufreverse(static_data)
# the first 76b of 80b do not change
blk_hdr = static_data[:76]
# decode 256-bit target value
targetbin = targetstr.decode('hex')
targetbin = targetbin[::-1] # byte-swap and dword-swap
targetbin_str = targetbin.encode('hex')
target = long(targetbin_str, 16)
# pre-hash first 76b of block header
static_hash = hashlib.sha256()
static_hash.update(blk_hdr)
for nonce in xrange(self.max_nonce):
# encode 32-bit nonce value
nonce_bin = struct.pack("<I", nonce)
# hash final 4b, the nonce value
hash1_o = static_hash.copy()
hash1_o.update(nonce_bin)
hash1 = hash1_o.digest()
# sha256 hash of sha256 hash
hash_o = hashlib.sha256()
hash_o.update(hash1)
hash = hash_o.digest()
# quick test for winning solution: high 32 bits zero?
if hash[-4:] != '\0\0\0\0':
continue
# convert binary hash to 256-bit Python long
hash = bufreverse(hash)
hash = wordreverse(hash)
hash_str = hash.encode('hex')
l = long(hash_str, 16)
# proof-of-work test: hash < target
if l < target:
print time.asctime(), "PROOF-OF-WORK found: %064x" % (l,)
return (nonce + 1, nonce_bin)
else:
print time.asctime(), "PROOF-OF-WORK false positive %064x" % (l,)
# return (nonce + 1, nonce_bin)
return (nonce + 1, None)
def submit_work(self, rpc, original_data, nonce_bin):
nonce_bin = bufreverse(nonce_bin)
nonce = nonce_bin.encode('hex')
solution = original_data[:152] + nonce + original_data[160:256]
param_arr = [ solution ]
result = rpc.getwork(param_arr)
print time.asctime(), "--> Upstream RPC result:", result
def iterate(self, rpc):
work = rpc.getwork()
if work is None:
time.sleep(ERR_SLEEP)
return
if 'data' not in work or 'target' not in work:
time.sleep(ERR_SLEEP)
return
time_start = time.time()
(hashes_done, nonce_bin) = self.work(work['data'],
work['target'])
time_end = time.time()
time_diff = time_end - time_start
self.max_nonce = long(
(hashes_done * settings['scantime']) / time_diff)
if self.max_nonce > 0xfffffffaL:
self.max_nonce = 0xfffffffaL
if settings['hashmeter']:
print "HashMeter(%d): %d hashes, %.2f Khash/sec" % (
self.id, hashes_done,
(hashes_done / 1000.0) / time_diff)
if nonce_bin is not None:
self.submit_work(rpc, work['data'], nonce_bin)
def loop(self):
rpc = BitcoinRPC(settings['host'], settings['port'],
settings['rpcuser'], settings['rpcpass'])
if rpc is None:
return
while True:
self.iterate(rpc)
def miner_thread(id):
miner = Miner(id)
miner.loop()
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage: pyminer.py CONFIG-FILE"
sys.exit(1)
f = open(sys.argv[1])
for line in f:
# skip comment lines
m = re.search('^\s*#', line)
if m:
continue
# parse key=value lines
m = re.search('^(\w+)\s*=\s*(\S.*)$', line)
if m is None:
continue
settings[m.group(1)] = m.group(2)
f.close()
if 'host' not in settings:
settings['host'] = '127.0.0.1'
if 'port' not in settings:
settings['port'] = 8332
if 'threads' not in settings:
settings['threads'] = 1
if 'hashmeter' not in settings:
settings['hashmeter'] = 0
if 'scantime' not in settings:
settings['scantime'] = 30L
if 'rpcuser' not in settings or 'rpcpass' not in settings:
print "Missing username and/or password in cfg file"
sys.exit(1)
settings['port'] = int(settings['port'])
settings['threads'] = int(settings['threads'])
settings['hashmeter'] = int(settings['hashmeter'])
settings['scantime'] = long(settings['scantime'])
thr_list = []
for thr_id in range(settings['threads']):
p = Process(target=miner_thread, args=(thr_id,))
p.start()
thr_list.append(p)
time.sleep(1) # stagger threads
print settings['threads'], "mining threads started"
print time.asctime(), "Miner Starts - %s:%s" % (settings['host'], settings['port'])
try:
for thr_proc in thr_list:
thr_proc.join()
except KeyboardInterrupt:
pass
print time.asctime(), "Miner Stops - %s:%s" % (settings['host'], settings['port'])
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
710,
21158,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2022,
199,
646,
10933,
199,
646,
8337,
199,
646,
2702,
199,
646,
295,
199,
646,
1300,
772,
199,
646,
8809,
199,
646,
984,
199,
504,
12866,
492,
7132,
199,
199,
2666,
63,
51,
906,
6102,
275,
4114,
199,
4283,
63,
13887,
2089,
275,
19492,
44,
199,
199,
1751,
275,
1052,
199,
802,
275,
10933,
14,
27153,
14131,
8,
3724,
29,
20,
9,
199,
199,
533,
21158,
8171,
26,
199,
198,
15862,
998,
275,
413,
421,
198,
318,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
3434,
12,
2505,
304,
507,
198,
1178,
3852,
275,
2071,
83,
2689,
83,
2,
450,
334,
2473,
12,
2505,
9,
507,
198,
277,
14,
1178,
11244,
275,
298,
6845,
450,
83,
2,
450,
334,
1095,
772,
14,
66,
772,
2143,
8,
1178,
3852,
430,
507,
198,
277,
14,
1631,
275,
8809,
14,
19114,
8,
1102,
12,
1844,
12,
756,
12,
4233,
9,
199,
198,
318,
8985,
8,
277,
12,
1083,
12,
1862,
29,
403,
304,
507,
198,
277,
14,
15862,
998,
847,
413,
507,
198,
1113,
275,
469,
283,
1023,
7,
520,
283,
17,
14,
17,
297,
686,
198,
6704,
69,
594,
7,
520,
1083,
12,
686,
198,
7,
344,
7,
520,
291,
14,
15862,
998,
789,
507,
198,
692,
1862,
365,
488,
26,
686,
198,
1113,
459,
1162,
418,
275,
942,
507,
198,
2836,
26,
686,
198,
1113,
459,
1162,
418,
275,
1862,
507,
198,
277,
14,
1631,
14,
1069,
360,
4030,
297,
17220,
2022,
14,
4180,
8,
1113,
395,
686,
198,
91,
283,
11626,
7,
520,
291,
14,
1178,
11244,
12,
1585,
221,
283,
2714,
13,
466,
7,
520,
283,
3578,
15,
1001,
7,
3828,
2742,
198,
4518,
275,
291,
14,
1631,
14,
25006,
342,
507,
198,
692,
3085,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
1177,
2,
686,
198,
1107,
488,
2742,
198,
2030,
275,
3085,
14,
739,
342,
507,
198,
4518,
63,
1113,
275,
2022,
14,
3640,
8,
2030,
9,
507,
198,
692,
3085,
63,
1113,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
3913,
4840,
13,
2708,
2396,
2,
686,
198,
1107,
488,
507,
198,
692,
283,
705,
7,
315,
3085,
63,
1113,
436,
3085,
63,
1113,
459,
705,
418,
1137,
488,
26,
686,
198,
1107,
3085,
63,
1113,
459,
705,
418,
507,
198,
692,
283,
1099,
7,
440,
315,
3085,
63,
1113,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
754,
315,
909,
2,
686,
198,
1107,
488,
2742,
198,
1107,
3085,
63,
1113,
459,
1099,
418,
199,
198,
318,
664,
1457,
835,
8,
277,
304,
507,
198,
1107,
291,
14,
4354,
360,
30710,
358,
199,
198,
318,
664,
800,
8,
277,
12,
666,
29,
403,
304,
507,
198,
1107,
291,
14,
4354,
360,
362,
800,
297,
666,
9,
199,
199,
318,
3152,
708,
8,
88,
304,
199,
198,
1107,
671,
1253,
378,
21870,
44,
199,
199,
318,
3696,
4471,
8,
88,
304,
199,
198,
1107,
3152,
708,
1332,
3666,
88,
9,
5213,
5504,
9,
1204,
20337,
88,
9,
5213,
1695,
9,
1253,
378,
88,
383,
556,
993,
9,
1204,
686,
198,
12925,
88,
9,
4331,
1695,
9,
1253,
378,
88,
993,
556,
383,
9,
1204,
3666,
88,
9,
4331,
5504,
9,
5082,
199,
199,
318,
4123,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
1027,
275,
2702,
14,
5301,
16591,
41,
297,
315,
63,
1436,
59,
73,
26,
73,
11,
20,
11057,
16,
61,
507,
198,
548,
63,
3148,
14,
740,
8,
1820,
14,
1389,
16591,
41,
297,
3696,
4471,
8,
1027,
1724,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
318,
4349,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
548,
63,
3148,
14,
740,
8,
262,
63,
1436,
59,
73,
26,
73,
11,
20,
566,
199,
198,
548,
63,
3148,
14,
4471,
342,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
533,
10195,
281,
26,
199,
198,
318,
636,
826,
721,
277,
12,
1305,
304,
507,
198,
277,
14,
344,
275,
1305,
507,
198,
277,
14,
988,
63,
10667,
275,
9141,
63,
13887,
2089,
421,
198,
318,
1736,
8,
277,
12,
666,
495,
12,
1347,
495,
304,
507,
198,
3,
4849,
1736,
666,
6318,
1059,
370,
3366,
507,
198,
1986,
63,
576,
275,
666,
495,
14,
2708,
360,
4097,
358,
507,
198,
1986,
63,
576,
275,
4123,
4471,
8,
1986,
63,
576,
9,
2742,
198,
3,
314,
1642,
14646,
66,
402,
5939,
66,
886,
440,
1570,
507,
198,
14023,
63,
11244,
275,
2955,
63,
576,
1491,
2114,
61,
2742,
198,
3,
4849,
7633,
13,
2075,
1347,
574,
507,
198,
1375,
1393,
275,
1347,
495,
14,
2708,
360,
4097,
358,
507,
198,
1375,
1393,
275,
1347,
1393,
14172,
17,
61,
198,
3,
3696,
13,
9286,
436,
366,
1027,
13,
9286,
507,
198,
1375,
1393,
63,
495,
275,
1347,
1393,
14,
2143,
360,
4097,
358,
507,
198,
1375,
275,
1846,
8,
1375,
1393,
63,
495,
12,
3193,
9,
2742,
198,
3,
876,
13,
2227,
1642,
14646,
66,
402,
1853,
1406,
507,
198,
1986,
63,
2227,
275,
8337,
14,
4835,
3912,
342,
507,
198,
1986,
63,
2227,
14,
873,
8,
14023,
63,
11244,
9,
2742,
198,
509,
13711,
315,
4945,
8,
277,
14,
988,
63,
10667,
304,
6319,
198,
3,
3752,
4337,
13,
2075,
13711,
574,
686,
198,
10667,
63,
1393,
275,
2702,
14,
1389,
6757,
41,
401,
13711,
9,
6319,
198,
3,
2631,
4242,
841,
66,
12,
314,
13711,
574,
686,
198,
2227,
17,
63,
79,
275,
2955,
63,
2227,
14,
1574,
342
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
710,
21158,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
9685,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2022,
199,
646,
10933,
199,
646,
8337,
199,
646,
2702,
199,
646,
295,
199,
646,
1300,
772,
199,
646,
8809,
199,
646,
984,
199,
504,
12866,
492,
7132,
199,
199,
2666,
63,
51,
906,
6102,
275,
4114,
199,
4283,
63,
13887,
2089,
275,
19492,
44,
199,
199,
1751,
275,
1052,
199,
802,
275,
10933,
14,
27153,
14131,
8,
3724,
29,
20,
9,
199,
199,
533,
21158,
8171,
26,
199,
198,
15862,
998,
275,
413,
421,
198,
318,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
3434,
12,
2505,
304,
507,
198,
1178,
3852,
275,
2071,
83,
2689,
83,
2,
450,
334,
2473,
12,
2505,
9,
507,
198,
277,
14,
1178,
11244,
275,
298,
6845,
450,
83,
2,
450,
334,
1095,
772,
14,
66,
772,
2143,
8,
1178,
3852,
430,
507,
198,
277,
14,
1631,
275,
8809,
14,
19114,
8,
1102,
12,
1844,
12,
756,
12,
4233,
9,
199,
198,
318,
8985,
8,
277,
12,
1083,
12,
1862,
29,
403,
304,
507,
198,
277,
14,
15862,
998,
847,
413,
507,
198,
1113,
275,
469,
283,
1023,
7,
520,
283,
17,
14,
17,
297,
686,
198,
6704,
69,
594,
7,
520,
1083,
12,
686,
198,
7,
344,
7,
520,
291,
14,
15862,
998,
789,
507,
198,
692,
1862,
365,
488,
26,
686,
198,
1113,
459,
1162,
418,
275,
942,
507,
198,
2836,
26,
686,
198,
1113,
459,
1162,
418,
275,
1862,
507,
198,
277,
14,
1631,
14,
1069,
360,
4030,
297,
17220,
2022,
14,
4180,
8,
1113,
395,
686,
198,
91,
283,
11626,
7,
520,
291,
14,
1178,
11244,
12,
1585,
221,
283,
2714,
13,
466,
7,
520,
283,
3578,
15,
1001,
7,
3828,
2742,
198,
4518,
275,
291,
14,
1631,
14,
25006,
342,
507,
198,
692,
3085,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
1177,
2,
686,
198,
1107,
488,
2742,
198,
2030,
275,
3085,
14,
739,
342,
507,
198,
4518,
63,
1113,
275,
2022,
14,
3640,
8,
2030,
9,
507,
198,
692,
3085,
63,
1113,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
3913,
4840,
13,
2708,
2396,
2,
686,
198,
1107,
488,
507,
198,
692,
283,
705,
7,
315,
3085,
63,
1113,
436,
3085,
63,
1113,
459,
705,
418,
1137,
488,
26,
686,
198,
1107,
3085,
63,
1113,
459,
705,
418,
507,
198,
692,
283,
1099,
7,
440,
315,
3085,
63,
1113,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
754,
315,
909,
2,
686,
198,
1107,
488,
2742,
198,
1107,
3085,
63,
1113,
459,
1099,
418,
199,
198,
318,
664,
1457,
835,
8,
277,
304,
507,
198,
1107,
291,
14,
4354,
360,
30710,
358,
199,
198,
318,
664,
800,
8,
277,
12,
666,
29,
403,
304,
507,
198,
1107,
291,
14,
4354,
360,
362,
800,
297,
666,
9,
199,
199,
318,
3152,
708,
8,
88,
304,
199,
198,
1107,
671,
1253,
378,
21870,
44,
199,
199,
318,
3696,
4471,
8,
88,
304,
199,
198,
1107,
3152,
708,
1332,
3666,
88,
9,
5213,
5504,
9,
1204,
20337,
88,
9,
5213,
1695,
9,
1253,
378,
88,
383,
556,
993,
9,
1204,
686,
198,
12925,
88,
9,
4331,
1695,
9,
1253,
378,
88,
993,
556,
383,
9,
1204,
3666,
88,
9,
4331,
5504,
9,
5082,
199,
199,
318,
4123,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
1027,
275,
2702,
14,
5301,
16591,
41,
297,
315,
63,
1436,
59,
73,
26,
73,
11,
20,
11057,
16,
61,
507,
198,
548,
63,
3148,
14,
740,
8,
1820,
14,
1389,
16591,
41,
297,
3696,
4471,
8,
1027,
1724,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
318,
4349,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
548,
63,
3148,
14,
740,
8,
262,
63,
1436,
59,
73,
26,
73,
11,
20,
566,
199,
198,
548,
63,
3148,
14,
4471,
342,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
533,
10195,
281,
26,
199,
198,
318,
636,
826,
721,
277,
12,
1305,
304,
507,
198,
277,
14,
344,
275,
1305,
507,
198,
277,
14,
988,
63,
10667,
275,
9141,
63,
13887,
2089,
421,
198,
318,
1736,
8,
277,
12,
666,
495,
12,
1347,
495,
304,
507,
198,
3,
4849,
1736,
666,
6318,
1059,
370,
3366,
507,
198,
1986,
63,
576,
275,
666,
495,
14,
2708,
360,
4097,
358,
507,
198,
1986,
63,
576,
275,
4123,
4471,
8,
1986,
63,
576,
9,
2742,
198,
3,
314,
1642,
14646,
66,
402,
5939,
66,
886,
440,
1570,
507,
198,
14023,
63,
11244,
275,
2955,
63,
576,
1491,
2114,
61,
2742,
198,
3,
4849,
7633,
13,
2075,
1347,
574,
507,
198,
1375,
1393,
275,
1347,
495,
14,
2708,
360,
4097,
358,
507,
198,
1375,
1393,
275,
1347,
1393,
14172,
17,
61,
198,
3,
3696,
13,
9286,
436,
366,
1027,
13,
9286,
507,
198,
1375,
1393,
63,
495,
275,
1347,
1393,
14,
2143,
360,
4097,
358,
507,
198,
1375,
275,
1846,
8,
1375,
1393,
63,
495,
12,
3193,
9,
2742,
198,
3,
876,
13,
2227,
1642,
14646,
66,
402,
1853,
1406,
507,
198,
1986,
63,
2227,
275,
8337,
14,
4835,
3912,
342,
507,
198,
1986,
63,
2227,
14,
873,
8,
14023,
63,
11244,
9,
2742,
198,
509,
13711,
315,
4945,
8,
277,
14,
988,
63,
10667,
304,
6319,
198,
3,
3752,
4337,
13,
2075,
13711,
574,
686,
198,
10667,
63,
1393,
275,
2702,
14,
1389,
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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
] |
sathnaga/virt-test
|
qemu/tests/pxe_query_cpus.py
|
2
|
4098
|
import time, logging
from autotest.client.shared import error, utils
from virttest import utils_test, env_process, utils_misc
class Modprobe(object):
prog = "/sbin/modprobe"
def __init__(self, name):
self.name = name
def get_parm(self, parm):
"""
Read parm value from sys file system
"""
path = "/sys/module/%s/parameters/%s" % (self.name, parm)
try:
parm_fd = open(path, "r")
val = parm_fd.readline()
val = str(val).strip("\n")
parm_fd.close()
return val
except IOError:
return None
def set_parm(self, parm, val):
"""
Reload module with param to changes module params
"""
val = str(val)
_val = self.get_parm(parm)
if val != _val:
self.unload()
self.load("%s=%s" % (parm, val))
val = self.get_parm(parm)
return (val == _val)
return True
def unload(self):
cmd = "%s -r %s" % (self.prog, self.name)
return utils.run(cmd)
def load(self, s_parm=""):
self.unload()
cmd = "%s %s %s" % (self.prog, self.name, s_parm)
return utils.run(cmd)
def restore(self):
"""
restore default module params
"""
self.unload()
time.sleep(0.5)
return self.load()
class PxeTest(Modprobe):
def __init__(self, test, params, env):
"""
According cpu flag init module name and mmu
"""
self.test = test
self.params = params
self.env = env
c_flags = utils_misc.get_cpu_flags()
if 'vmx' in c_flags:
name = 'kvm_intel'
if 'ept' in c_flags:
mmu = "ept"
elif 'svm' in c_flags:
name = "kvm_amd"
if 'npt' in c_flags:
mmu = "npt"
self.mmu = mmu
super(PxeTest, self).__init__(name)
def get_vm(self):
params = self.params
vm_name = params["main_vm"]
params["start_vm"] = "yes"
vm = self.env.get_vm(vm_name)
env_process.preprocess_vm(self.test, params, self.env, vm_name)
vm.verify_alive()
return vm
def stop_vms(self):
qemu_bin = self.params["qemu_binary"]
for vm in self.env.get_all_vms():
if vm.is_alive():
vm.destroy()
utils.run("fuser -k %s" % qemu_bin, ignore_status=True)
def enable_mmu(self):
if not self.mmu:
logging.warning("%s not support on host" % self.mmu)
return
self.stop_vms()
enabled = self.set_parm(self.mmu, '1')
if not enabled:
raise error.TestFail("Fail to enable %s" % self.mmu)
def cleanup(self):
self.stop_vms()
self.restore()
@error.context_aware
def run_pxe_query_cpus(test, params, env):
"""
Qemu guest pxe boot test:
1). check npt/ept function enable, then boot vm
2). execute query/info cpus in loop
3). verify vm not paused during pxe booting
params:
@param test: QEMU test object
@param params: Dictionary with the test parameters
@param env: Dictionary with test environment.
"""
pxe_test = PxeTest(test, params, env)
error.context("Enable %s on host" % pxe_test.mmu, logging.info)
pxe_test.enable_mmu()
error.context("Bootup vm from network", logging.info)
vm = pxe_test.get_vm()
params["start_vm"] = "yes"
params["restart_vm"] = "no"
bg = utils.InterruptedThread(utils_test.run_virt_sub_test,
args=(test, params, env,),
kwargs={"sub_type":"pxe"})
bg.start()
count = 0
try:
error.context("Query cpus in loop", logging.info)
while True:
vm.monitor.info("cpus")
count += 1
vm.verify_status("running")
if not bg.isAlive():
break
logging.info("Execute info/query cpus %d times", count)
finally:
pxe_test.cleanup()
|
gpl-2.0
|
[
646,
900,
12,
2050,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
12,
3778,
199,
504,
12043,
396,
492,
3778,
63,
396,
12,
2589,
63,
1412,
12,
3778,
63,
9923,
421,
199,
533,
22035,
15944,
8,
785,
304,
339,
13205,
275,
3286,
21457,
15,
1494,
15944,
2,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
664,
63,
22176,
8,
277,
12,
623,
77,
304,
267,
408,
267,
5574,
623,
77,
574,
687,
984,
570,
2656,
267,
408,
267,
931,
275,
3286,
1274,
15,
578,
3149,
83,
15,
3214,
3149,
83,
2,
450,
334,
277,
14,
354,
12,
623,
77,
9,
267,
862,
26,
288,
623,
77,
63,
2592,
275,
1551,
8,
515,
12,
298,
82,
531,
288,
1139,
275,
623,
77,
63,
2592,
14,
6407,
342,
288,
1139,
275,
620,
8,
637,
680,
1913,
4582,
78,
531,
288,
623,
77,
63,
2592,
14,
1600,
342,
288,
372,
1139,
267,
871,
5925,
26,
288,
372,
488,
339,
347,
663,
63,
22176,
8,
277,
12,
623,
77,
12,
1139,
304,
267,
408,
267,
799,
912,
859,
543,
1215,
370,
4493,
859,
1862,
267,
408,
267,
1139,
275,
620,
8,
637,
9,
267,
485,
637,
275,
291,
14,
362,
63,
22176,
8,
22176,
9,
267,
340,
1139,
1137,
485,
637,
26,
288,
291,
14,
25477,
342,
288,
291,
14,
912,
3647,
83,
2458,
83,
2,
450,
334,
22176,
12,
1139,
430,
288,
1139,
275,
291,
14,
362,
63,
22176,
8,
22176,
9,
288,
372,
334,
637,
508,
485,
637,
9,
267,
372,
715,
339,
347,
625,
912,
8,
277,
304,
267,
2088,
275,
2071,
83,
446,
82,
450,
83,
2,
450,
334,
277,
14,
6595,
12,
291,
14,
354,
9,
267,
372,
3778,
14,
1065,
8,
1760,
9,
339,
347,
2248,
8,
277,
12,
308,
63,
22176,
17364,
267,
291,
14,
25477,
342,
267,
2088,
275,
2071,
83,
450,
83,
450,
83,
2,
450,
334,
277,
14,
6595,
12,
291,
14,
354,
12,
308,
63,
22176,
9,
267,
372,
3778,
14,
1065,
8,
1760,
9,
339,
347,
9066,
8,
277,
304,
267,
408,
267,
9066,
849,
859,
1862,
267,
408,
267,
291,
14,
25477,
342,
267,
900,
14,
4532,
8,
16,
14,
21,
9,
267,
372,
291,
14,
912,
342,
199,
199,
533,
510,
1845,
774,
8,
9871,
15944,
304,
339,
347,
636,
826,
721,
277,
12,
511,
12,
1862,
12,
2589,
304,
267,
408,
267,
31970,
5033,
3305,
4205,
859,
536,
436,
333,
6553,
267,
408,
267,
291,
14,
396,
275,
511,
267,
291,
14,
1162,
275,
1862,
267,
291,
14,
1813,
275,
2589,
267,
286,
63,
2469,
275,
3778,
63,
9923,
14,
362,
63,
3541,
63,
2469,
342,
267,
340,
283,
2611,
88,
7,
315,
286,
63,
2469,
26,
288,
536,
275,
283,
29272,
63,
22264,
7,
288,
340,
283,
69,
541,
7,
315,
286,
63,
2469,
26,
355,
333,
6553,
275,
298,
69,
541,
2,
267,
916,
283,
16820,
7,
315,
286,
63,
2469,
26,
288,
536,
275,
298,
29272,
63,
21778,
2,
288,
340,
283,
78,
541,
7,
315,
286,
63,
2469,
26,
355,
333,
6553,
275,
298,
78,
541,
2,
267,
291,
14,
596,
85,
275,
333,
6553,
267,
1613,
8,
48,
1845,
774,
12,
291,
2843,
826,
721,
354,
9,
339,
347,
664,
63,
2611,
8,
277,
304,
267,
1862,
275,
291,
14,
1162,
267,
4169,
63,
354,
275,
1862,
905,
973,
63,
2611,
937,
267,
1862,
905,
928,
63,
2611,
937,
275,
298,
5066,
2,
267,
4169,
275,
291,
14,
1813,
14,
362,
63,
2611,
8,
2611,
63,
354,
9,
267,
2589,
63,
1412,
14,
17677,
63,
2611,
8,
277,
14,
396,
12,
1862,
12,
291,
14,
1813,
12,
4169,
63,
354,
9,
267,
4169,
14,
4712,
63,
9631,
342,
267,
372,
4169,
339,
347,
3631,
63,
16092,
8,
277,
304,
267,
1894,
14756,
63,
1393,
275,
291,
14,
1162,
905,
19839,
63,
3008,
937,
267,
367,
4169,
315,
291,
14,
1813,
14,
362,
63,
452,
63,
16092,
837,
288,
340,
4169,
14,
374,
63,
9631,
837,
355,
4169,
14,
7237,
342,
267,
3778,
14,
1065,
480,
70,
751,
446,
75,
450,
83,
2,
450,
1894,
14756,
63,
1393,
12,
3686,
63,
1205,
29,
549,
9,
339,
347,
4756,
63,
596,
85,
8,
277,
304,
267,
340,
440,
291,
14,
596,
85,
26,
288,
2050,
14,
3764,
3647,
83,
440,
2291,
641,
1591,
2,
450,
291,
14,
596,
85,
9,
288,
372,
267,
291,
14,
2379,
63,
16092,
342,
267,
5223,
275,
291,
14,
409,
63,
22176,
8,
277,
14,
596,
85,
12,
283,
17,
358,
267,
340,
440,
5223,
26,
288,
746,
1125,
14,
774,
4874,
480,
4874,
370,
4756,
450,
83,
2,
450,
291,
14,
596,
85,
9,
339,
347,
9058,
8,
277,
304,
267,
291,
14,
2379,
63,
16092,
342,
267,
291,
14,
8011,
342,
421,
199,
32,
705,
14,
1100,
63,
14600,
199,
318,
1255,
63,
80,
1845,
63,
1131,
63,
8896,
8,
396,
12,
1862,
12,
2589,
304,
272,
408,
272,
1413,
14756,
13980,
299,
1845,
8498,
511,
26,
272,
413,
680,
1104,
29340,
15,
69,
541,
805,
4756,
12,
2066,
8498,
4169,
272,
499,
680,
5341,
1827,
15,
815,
24174,
315,
4438,
272,
650,
680,
4911,
4169,
440,
691,
2972,
5309,
299,
1845,
8498,
316,
339,
1862,
26,
272,
768,
635,
511,
26,
1413,
2769,
53,
511,
909,
272,
768,
635,
1862,
26,
11932,
543,
314,
511,
2633,
272,
768,
635,
2589,
26,
11932,
543,
511,
3734,
14,
272,
408,
272,
299,
1845,
63,
396,
275,
510,
1845,
774,
8,
396,
12,
1862,
12,
2589,
9,
272,
1125,
14,
1100,
480,
6476,
450,
83,
641,
1591,
2,
450,
299,
1845,
63,
396,
14,
596,
85,
12,
2050,
14,
815,
9,
272,
299,
1845,
63,
396,
14,
4296,
63,
596,
85,
342,
339,
1125,
14,
1100,
480,
17989,
384,
4169,
687,
2784,
401,
2050,
14,
815,
9,
272,
4169,
275,
299,
1845,
63,
396,
14,
362,
63,
2611,
342,
272,
1862,
905,
928,
63,
2611,
937,
275,
298,
5066,
2,
272,
1862,
905,
10506,
63,
2611,
937,
275,
298,
889,
2,
272,
12994,
275,
3778,
14,
2620,
15692,
4436,
8,
1208,
63,
396,
14
] |
[
900,
12,
2050,
199,
504,
2599,
396,
14,
1258,
14,
5555,
492,
1125,
12,
3778,
199,
504,
12043,
396,
492,
3778,
63,
396,
12,
2589,
63,
1412,
12,
3778,
63,
9923,
421,
199,
533,
22035,
15944,
8,
785,
304,
339,
13205,
275,
3286,
21457,
15,
1494,
15944,
2,
339,
347,
636,
826,
721,
277,
12,
536,
304,
267,
291,
14,
354,
275,
536,
339,
347,
664,
63,
22176,
8,
277,
12,
623,
77,
304,
267,
408,
267,
5574,
623,
77,
574,
687,
984,
570,
2656,
267,
408,
267,
931,
275,
3286,
1274,
15,
578,
3149,
83,
15,
3214,
3149,
83,
2,
450,
334,
277,
14,
354,
12,
623,
77,
9,
267,
862,
26,
288,
623,
77,
63,
2592,
275,
1551,
8,
515,
12,
298,
82,
531,
288,
1139,
275,
623,
77,
63,
2592,
14,
6407,
342,
288,
1139,
275,
620,
8,
637,
680,
1913,
4582,
78,
531,
288,
623,
77,
63,
2592,
14,
1600,
342,
288,
372,
1139,
267,
871,
5925,
26,
288,
372,
488,
339,
347,
663,
63,
22176,
8,
277,
12,
623,
77,
12,
1139,
304,
267,
408,
267,
799,
912,
859,
543,
1215,
370,
4493,
859,
1862,
267,
408,
267,
1139,
275,
620,
8,
637,
9,
267,
485,
637,
275,
291,
14,
362,
63,
22176,
8,
22176,
9,
267,
340,
1139,
1137,
485,
637,
26,
288,
291,
14,
25477,
342,
288,
291,
14,
912,
3647,
83,
2458,
83,
2,
450,
334,
22176,
12,
1139,
430,
288,
1139,
275,
291,
14,
362,
63,
22176,
8,
22176,
9,
288,
372,
334,
637,
508,
485,
637,
9,
267,
372,
715,
339,
347,
625,
912,
8,
277,
304,
267,
2088,
275,
2071,
83,
446,
82,
450,
83,
2,
450,
334,
277,
14,
6595,
12,
291,
14,
354,
9,
267,
372,
3778,
14,
1065,
8,
1760,
9,
339,
347,
2248,
8,
277,
12,
308,
63,
22176,
17364,
267,
291,
14,
25477,
342,
267,
2088,
275,
2071,
83,
450,
83,
450,
83,
2,
450,
334,
277,
14,
6595,
12,
291,
14,
354,
12,
308,
63,
22176,
9,
267,
372,
3778,
14,
1065,
8,
1760,
9,
339,
347,
9066,
8,
277,
304,
267,
408,
267,
9066,
849,
859,
1862,
267,
408,
267,
291,
14,
25477,
342,
267,
900,
14,
4532,
8,
16,
14,
21,
9,
267,
372,
291,
14,
912,
342,
199,
199,
533,
510,
1845,
774,
8,
9871,
15944,
304,
339,
347,
636,
826,
721,
277,
12,
511,
12,
1862,
12,
2589,
304,
267,
408,
267,
31970,
5033,
3305,
4205,
859,
536,
436,
333,
6553,
267,
408,
267,
291,
14,
396,
275,
511,
267,
291,
14,
1162,
275,
1862,
267,
291,
14,
1813,
275,
2589,
267,
286,
63,
2469,
275,
3778,
63,
9923,
14,
362,
63,
3541,
63,
2469,
342,
267,
340,
283,
2611,
88,
7,
315,
286,
63,
2469,
26,
288,
536,
275,
283,
29272,
63,
22264,
7,
288,
340,
283,
69,
541,
7,
315,
286,
63,
2469,
26,
355,
333,
6553,
275,
298,
69,
541,
2,
267,
916,
283,
16820,
7,
315,
286,
63,
2469,
26,
288,
536,
275,
298,
29272,
63,
21778,
2,
288,
340,
283,
78,
541,
7,
315,
286,
63,
2469,
26,
355,
333,
6553,
275,
298,
78,
541,
2,
267,
291,
14,
596,
85,
275,
333,
6553,
267,
1613,
8,
48,
1845,
774,
12,
291,
2843,
826,
721,
354,
9,
339,
347,
664,
63,
2611,
8,
277,
304,
267,
1862,
275,
291,
14,
1162,
267,
4169,
63,
354,
275,
1862,
905,
973,
63,
2611,
937,
267,
1862,
905,
928,
63,
2611,
937,
275,
298,
5066,
2,
267,
4169,
275,
291,
14,
1813,
14,
362,
63,
2611,
8,
2611,
63,
354,
9,
267,
2589,
63,
1412,
14,
17677,
63,
2611,
8,
277,
14,
396,
12,
1862,
12,
291,
14,
1813,
12,
4169,
63,
354,
9,
267,
4169,
14,
4712,
63,
9631,
342,
267,
372,
4169,
339,
347,
3631,
63,
16092,
8,
277,
304,
267,
1894,
14756,
63,
1393,
275,
291,
14,
1162,
905,
19839,
63,
3008,
937,
267,
367,
4169,
315,
291,
14,
1813,
14,
362,
63,
452,
63,
16092,
837,
288,
340,
4169,
14,
374,
63,
9631,
837,
355,
4169,
14,
7237,
342,
267,
3778,
14,
1065,
480,
70,
751,
446,
75,
450,
83,
2,
450,
1894,
14756,
63,
1393,
12,
3686,
63,
1205,
29,
549,
9,
339,
347,
4756,
63,
596,
85,
8,
277,
304,
267,
340,
440,
291,
14,
596,
85,
26,
288,
2050,
14,
3764,
3647,
83,
440,
2291,
641,
1591,
2,
450,
291,
14,
596,
85,
9,
288,
372,
267,
291,
14,
2379,
63,
16092,
342,
267,
5223,
275,
291,
14,
409,
63,
22176,
8,
277,
14,
596,
85,
12,
283,
17,
358,
267,
340,
440,
5223,
26,
288,
746,
1125,
14,
774,
4874,
480,
4874,
370,
4756,
450,
83,
2,
450,
291,
14,
596,
85,
9,
339,
347,
9058,
8,
277,
304,
267,
291,
14,
2379,
63,
16092,
342,
267,
291,
14,
8011,
342,
421,
199,
32,
705,
14,
1100,
63,
14600,
199,
318,
1255,
63,
80,
1845,
63,
1131,
63,
8896,
8,
396,
12,
1862,
12,
2589,
304,
272,
408,
272,
1413,
14756,
13980,
299,
1845,
8498,
511,
26,
272,
413,
680,
1104,
29340,
15,
69,
541,
805,
4756,
12,
2066,
8498,
4169,
272,
499,
680,
5341,
1827,
15,
815,
24174,
315,
4438,
272,
650,
680,
4911,
4169,
440,
691,
2972,
5309,
299,
1845,
8498,
316,
339,
1862,
26,
272,
768,
635,
511,
26,
1413,
2769,
53,
511,
909,
272,
768,
635,
1862,
26,
11932,
543,
314,
511,
2633,
272,
768,
635,
2589,
26,
11932,
543,
511,
3734,
14,
272,
408,
272,
299,
1845,
63,
396,
275,
510,
1845,
774,
8,
396,
12,
1862,
12,
2589,
9,
272,
1125,
14,
1100,
480,
6476,
450,
83,
641,
1591,
2,
450,
299,
1845,
63,
396,
14,
596,
85,
12,
2050,
14,
815,
9,
272,
299,
1845,
63,
396,
14,
4296,
63,
596,
85,
342,
339,
1125,
14,
1100,
480,
17989,
384,
4169,
687,
2784,
401,
2050,
14,
815,
9,
272,
4169,
275,
299,
1845,
63,
396,
14,
362,
63,
2611,
342,
272,
1862,
905,
928,
63,
2611,
937,
275,
298,
5066,
2,
272,
1862,
905,
10506,
63,
2611,
937,
275,
298,
889,
2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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
mspringett/namebench
|
nb_third_party/jinja2/ext.py
|
199
|
21800
|
# -*- coding: utf-8 -*-
"""
jinja2.ext
~~~~~~~~~~
Jinja extensions allow to add custom tags similar to the way django custom
tags work. By default two example extensions exist: an i18n and a cache
extension.
:copyright: (c) 2010 by the Jinja Team.
:license: BSD.
"""
from collections import deque
from jinja2 import nodes
from jinja2.defaults import *
from jinja2.environment import get_spontaneous_environment
from jinja2.runtime import Undefined, concat
from jinja2.exceptions import TemplateAssertionError, TemplateSyntaxError
from jinja2.utils import contextfunction, import_string, Markup, next
# the only real useful gettext functions for a Jinja template. Note
# that ugettext must be assigned to gettext as Jinja doesn't support
# non unicode strings.
GETTEXT_FUNCTIONS = ('_', 'gettext', 'ngettext')
class ExtensionRegistry(type):
"""Gives the extension an unique identifier."""
def __new__(cls, name, bases, d):
rv = type.__new__(cls, name, bases, d)
rv.identifier = rv.__module__ + '.' + rv.__name__
return rv
class Extension(object):
"""Extensions can be used to add extra functionality to the Jinja template
system at the parser level. Custom extensions are bound to an environment
but may not store environment specific data on `self`. The reason for
this is that an extension can be bound to another environment (for
overlays) by creating a copy and reassigning the `environment` attribute.
As extensions are created by the environment they cannot accept any
arguments for configuration. One may want to work around that by using
a factory function, but that is not possible as extensions are identified
by their import name. The correct way to configure the extension is
storing the configuration values on the environment. Because this way the
environment ends up acting as central configuration storage the
attributes may clash which is why extensions have to ensure that the names
they choose for configuration are not too generic. ``prefix`` for example
is a terrible name, ``fragment_cache_prefix`` on the other hand is a good
name as includes the name of the extension (fragment cache).
"""
__metaclass__ = ExtensionRegistry
#: if this extension parses this is the list of tags it's listening to.
tags = set()
#: the priority of that extension. This is especially useful for
#: extensions that preprocess values. A lower value means higher
#: priority.
#:
#: .. versionadded:: 2.4
priority = 100
def __init__(self, environment):
self.environment = environment
def bind(self, environment):
"""Create a copy of this extension bound to another environment."""
rv = object.__new__(self.__class__)
rv.__dict__.update(self.__dict__)
rv.environment = environment
return rv
def preprocess(self, source, name, filename=None):
"""This method is called before the actual lexing and can be used to
preprocess the source. The `filename` is optional. The return value
must be the preprocessed source.
"""
return source
def filter_stream(self, stream):
"""It's passed a :class:`~jinja2.lexer.TokenStream` that can be used
to filter tokens returned. This method has to return an iterable of
:class:`~jinja2.lexer.Token`\s, but it doesn't have to return a
:class:`~jinja2.lexer.TokenStream`.
In the `ext` folder of the Jinja2 source distribution there is a file
called `inlinegettext.py` which implements a filter that utilizes this
method.
"""
return stream
def parse(self, parser):
"""If any of the :attr:`tags` matched this method is called with the
parser as first argument. The token the parser stream is pointing at
is the name token that matched. This method has to return one or a
list of multiple nodes.
"""
raise NotImplementedError()
def attr(self, name, lineno=None):
"""Return an attribute node for the current extension. This is useful
to pass constants on extensions to generated template code::
self.attr('_my_attribute', lineno=lineno)
"""
return nodes.ExtensionAttribute(self.identifier, name, lineno=lineno)
def call_method(self, name, args=None, kwargs=None, dyn_args=None,
dyn_kwargs=None, lineno=None):
"""Call a method of the extension. This is a shortcut for
:meth:`attr` + :class:`jinja2.nodes.Call`.
"""
if args is None:
args = []
if kwargs is None:
kwargs = []
return nodes.Call(self.attr(name, lineno=lineno), args, kwargs,
dyn_args, dyn_kwargs, lineno=lineno)
@contextfunction
def _gettext_alias(context, string):
return context.resolve('gettext')(string)
class InternationalizationExtension(Extension):
"""This extension adds gettext support to Jinja2."""
tags = set(['trans'])
# TODO: the i18n extension is currently reevaluating values in a few
# situations. Take this example:
# {% trans count=something() %}{{ count }} foo{% pluralize
# %}{{ count }} fooss{% endtrans %}
# something is called twice here. One time for the gettext value and
# the other time for the n-parameter of the ngettext function.
def __init__(self, environment):
Extension.__init__(self, environment)
environment.globals['_'] = _gettext_alias
environment.extend(
install_gettext_translations=self._install,
install_null_translations=self._install_null,
uninstall_gettext_translations=self._uninstall,
extract_translations=self._extract
)
def _install(self, translations):
gettext = getattr(translations, 'ugettext', None)
if gettext is None:
gettext = translations.gettext
ngettext = getattr(translations, 'ungettext', None)
if ngettext is None:
ngettext = translations.ngettext
self.environment.globals.update(gettext=gettext, ngettext=ngettext)
def _install_null(self):
self.environment.globals.update(
gettext=lambda x: x,
ngettext=lambda s, p, n: (n != 1 and (p,) or (s,))[0]
)
def _uninstall(self, translations):
for key in 'gettext', 'ngettext':
self.environment.globals.pop(key, None)
def _extract(self, source, gettext_functions=GETTEXT_FUNCTIONS):
if isinstance(source, basestring):
source = self.environment.parse(source)
return extract_from_ast(source, gettext_functions)
def parse(self, parser):
"""Parse a translatable tag."""
lineno = next(parser.stream).lineno
# find all the variables referenced. Additionally a variable can be
# defined in the body of the trans block too, but this is checked at
# a later state.
plural_expr = None
variables = {}
while parser.stream.current.type != 'block_end':
if variables:
parser.stream.expect('comma')
# skip colon for python compatibility
if parser.stream.skip_if('colon'):
break
name = parser.stream.expect('name')
if name.value in variables:
parser.fail('translatable variable %r defined twice.' %
name.value, name.lineno,
exc=TemplateAssertionError)
# expressions
if parser.stream.current.type == 'assign':
next(parser.stream)
variables[name.value] = var = parser.parse_expression()
else:
variables[name.value] = var = nodes.Name(name.value, 'load')
if plural_expr is None:
plural_expr = var
parser.stream.expect('block_end')
plural = plural_names = None
have_plural = False
referenced = set()
# now parse until endtrans or pluralize
singular_names, singular = self._parse_block(parser, True)
if singular_names:
referenced.update(singular_names)
if plural_expr is None:
plural_expr = nodes.Name(singular_names[0], 'load')
# if we have a pluralize block, we parse that too
if parser.stream.current.test('name:pluralize'):
have_plural = True
next(parser.stream)
if parser.stream.current.type != 'block_end':
name = parser.stream.expect('name')
if name.value not in variables:
parser.fail('unknown variable %r for pluralization' %
name.value, name.lineno,
exc=TemplateAssertionError)
plural_expr = variables[name.value]
parser.stream.expect('block_end')
plural_names, plural = self._parse_block(parser, False)
next(parser.stream)
referenced.update(plural_names)
else:
next(parser.stream)
# register free names as simple name expressions
for var in referenced:
if var not in variables:
variables[var] = nodes.Name(var, 'load')
# no variables referenced? no need to escape
if not referenced:
singular = singular.replace('%%', '%')
if plural:
plural = plural.replace('%%', '%')
if not have_plural:
plural_expr = None
elif plural_expr is None:
parser.fail('pluralize without variables', lineno)
if variables:
variables = nodes.Dict([nodes.Pair(nodes.Const(x, lineno=lineno), y)
for x, y in variables.items()])
else:
variables = None
node = self._make_node(singular, plural, variables, plural_expr)
node.set_lineno(lineno)
return node
def _parse_block(self, parser, allow_pluralize):
"""Parse until the next block tag with a given name."""
referenced = []
buf = []
while 1:
if parser.stream.current.type == 'data':
buf.append(parser.stream.current.value.replace('%', '%%'))
next(parser.stream)
elif parser.stream.current.type == 'variable_begin':
next(parser.stream)
name = parser.stream.expect('name').value
referenced.append(name)
buf.append('%%(%s)s' % name)
parser.stream.expect('variable_end')
elif parser.stream.current.type == 'block_begin':
next(parser.stream)
if parser.stream.current.test('name:endtrans'):
break
elif parser.stream.current.test('name:pluralize'):
if allow_pluralize:
break
parser.fail('a translatable section can have only one '
'pluralize section')
parser.fail('control structures in translatable sections are '
'not allowed')
elif parser.stream.eos:
parser.fail('unclosed translation block')
else:
assert False, 'internal parser error'
return referenced, concat(buf)
def _make_node(self, singular, plural, variables, plural_expr):
"""Generates a useful node from the data provided."""
# singular only:
if plural_expr is None:
gettext = nodes.Name('gettext', 'load')
node = nodes.Call(gettext, [nodes.Const(singular)],
[], None, None)
# singular and plural
else:
ngettext = nodes.Name('ngettext', 'load')
node = nodes.Call(ngettext, [
nodes.Const(singular),
nodes.Const(plural),
plural_expr
], [], None, None)
# mark the return value as safe if we are in an
# environment with autoescaping turned on
if self.environment.autoescape:
node = nodes.MarkSafe(node)
if variables:
node = nodes.Mod(node, variables)
return nodes.Output([node])
class ExprStmtExtension(Extension):
"""Adds a `do` tag to Jinja2 that works like the print statement just
that it doesn't print the return value.
"""
tags = set(['do'])
def parse(self, parser):
node = nodes.ExprStmt(lineno=next(parser.stream).lineno)
node.node = parser.parse_tuple()
return node
class LoopControlExtension(Extension):
"""Adds break and continue to the template engine."""
tags = set(['break', 'continue'])
def parse(self, parser):
token = next(parser.stream)
if token.value == 'break':
return nodes.Break(lineno=token.lineno)
return nodes.Continue(lineno=token.lineno)
class WithExtension(Extension):
"""Adds support for a django-like with block."""
tags = set(['with'])
def parse(self, parser):
node = nodes.Scope(lineno=next(parser.stream).lineno)
assignments = []
while parser.stream.current.type != 'block_end':
lineno = parser.stream.current.lineno
if assignments:
parser.stream.expect('comma')
target = parser.parse_assign_target()
parser.stream.expect('assign')
expr = parser.parse_expression()
assignments.append(nodes.Assign(target, expr, lineno=lineno))
node.body = assignments + \
list(parser.parse_statements(('name:endwith',),
drop_needle=True))
return node
class AutoEscapeExtension(Extension):
"""Changes auto escape rules for a scope."""
tags = set(['autoescape'])
def parse(self, parser):
node = nodes.ScopedEvalContextModifier(lineno=next(parser.stream).lineno)
node.options = [
nodes.Keyword('autoescape', parser.parse_expression())
]
node.body = parser.parse_statements(('name:endautoescape',),
drop_needle=True)
return nodes.Scope([node])
def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS,
babel_style=True):
"""Extract localizable strings from the given template node. Per
default this function returns matches in babel style that means non string
parameters as well as keyword arguments are returned as `None`. This
allows Babel to figure out what you really meant if you are using
gettext functions that allow keyword arguments for placeholder expansion.
If you don't want that behavior set the `babel_style` parameter to `False`
which causes only strings to be returned and parameters are always stored
in tuples. As a consequence invalid gettext calls (calls without a single
string parameter or string parameters after non-string parameters) are
skipped.
This example explains the behavior:
>>> from jinja2 import Environment
>>> env = Environment()
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
>>> list(extract_from_ast(node))
[(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))]
>>> list(extract_from_ast(node, babel_style=False))
[(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))]
For every string found this function yields a ``(lineno, function,
message)`` tuple, where:
* ``lineno`` is the number of the line on which the string was found,
* ``function`` is the name of the ``gettext`` function used (if the
string was extracted from embedded Python code), and
* ``message`` is the string itself (a ``unicode`` object, or a tuple
of ``unicode`` objects for functions with multiple string arguments).
This extraction function operates on the AST and is because of that unable
to extract any comments. For comment support you have to use the babel
extraction interface or extract comments yourself.
"""
for node in node.find_all(nodes.Call):
if not isinstance(node.node, nodes.Name) or \
node.node.name not in gettext_functions:
continue
strings = []
for arg in node.args:
if isinstance(arg, nodes.Const) and \
isinstance(arg.value, basestring):
strings.append(arg.value)
else:
strings.append(None)
for arg in node.kwargs:
strings.append(None)
if node.dyn_args is not None:
strings.append(None)
if node.dyn_kwargs is not None:
strings.append(None)
if not babel_style:
strings = tuple(x for x in strings if x is not None)
if not strings:
continue
else:
if len(strings) == 1:
strings = strings[0]
else:
strings = tuple(strings)
yield node.lineno, node.node.name, strings
class _CommentFinder(object):
"""Helper class to find comments in a token stream. Can only
find comments for gettext calls forwards. Once the comment
from line 4 is found, a comment for line 1 will not return a
usable value.
"""
def __init__(self, tokens, comment_tags):
self.tokens = tokens
self.comment_tags = comment_tags
self.offset = 0
self.last_lineno = 0
def find_backwards(self, offset):
try:
for _, token_type, token_value in \
reversed(self.tokens[self.offset:offset]):
if token_type in ('comment', 'linecomment'):
try:
prefix, comment = token_value.split(None, 1)
except ValueError:
continue
if prefix in self.comment_tags:
return [comment.rstrip()]
return []
finally:
self.offset = offset
def find_comments(self, lineno):
if not self.comment_tags or self.last_lineno > lineno:
return []
for idx, (token_lineno, _, _) in enumerate(self.tokens[self.offset:]):
if token_lineno > lineno:
return self.find_backwards(self.offset + idx)
return self.find_backwards(len(self.tokens))
def babel_extract(fileobj, keywords, comment_tags, options):
"""Babel extraction method for Jinja templates.
.. versionchanged:: 2.3
Basic support for translation comments was added. If `comment_tags`
is now set to a list of keywords for extraction, the extractor will
try to find the best preceeding comment that begins with one of the
keywords. For best results, make sure to not have more than one
gettext call in one line of code and the matching comment in the
same line or the line before.
:param fileobj: the file-like object the messages should be extracted from
:param keywords: a list of keywords (i.e. function names) that should be
recognized as translation functions
:param comment_tags: a list of translator tags to search for and include
in the results.
:param options: a dictionary of additional options (optional)
:return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
(comments will be empty currently)
"""
extensions = set()
for extension in options.get('extensions', '').split(','):
extension = extension.strip()
if not extension:
continue
extensions.add(import_string(extension))
if InternationalizationExtension not in extensions:
extensions.add(InternationalizationExtension)
environment = get_spontaneous_environment(
options.get('block_start_string', BLOCK_START_STRING),
options.get('block_end_string', BLOCK_END_STRING),
options.get('variable_start_string', VARIABLE_START_STRING),
options.get('variable_end_string', VARIABLE_END_STRING),
options.get('comment_start_string', COMMENT_START_STRING),
options.get('comment_end_string', COMMENT_END_STRING),
options.get('line_statement_prefix') or LINE_STATEMENT_PREFIX,
options.get('line_comment_prefix') or LINE_COMMENT_PREFIX,
str(options.get('trim_blocks', TRIM_BLOCKS)).lower() in \
('1', 'on', 'yes', 'true'),
NEWLINE_SEQUENCE, frozenset(extensions),
# fill with defaults so that environments are shared
# with other spontaneus environments. The rest of the
# arguments are optimizer, undefined, finalize, autoescape,
# loader, cache size, auto reloading setting and the
# bytecode cache
True, Undefined, None, False, None, 0, False, None
)
source = fileobj.read().decode(options.get('encoding', 'utf-8'))
try:
node = environment.parse(source)
tokens = list(environment.lex(environment.preprocess(source)))
except TemplateSyntaxError, e:
# skip templates with syntax errors
return
finder = _CommentFinder(tokens, comment_tags)
for lineno, func, message in extract_from_ast(node, keywords):
yield lineno, func, message, finder.find_comments(lineno)
#: nicer import names
i18n = InternationalizationExtension
do = ExprStmtExtension
loopcontrols = LoopControlExtension
with_ = WithExtension
autoescape = AutoEscapeExtension
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
832,
272,
221,
4919,
1714,
339,
17300,
5478,
2040,
370,
1050,
3537,
3762,
8545,
370,
314,
4340,
1639,
3537,
272,
3762,
1736,
14,
221,
4885,
849,
2877,
2893,
5478,
2187,
26,
376,
284,
1085,
78,
436,
282,
2581,
272,
3329,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
14,
199,
624,
199,
504,
5055,
492,
15782,
199,
504,
10321,
18,
492,
3380,
199,
504,
10321,
18,
14,
4322,
492,
627,
199,
504,
10321,
18,
14,
5418,
492,
664,
63,
83,
678,
84,
13815,
63,
5418,
199,
504,
10321,
18,
14,
7726,
492,
25868,
12,
17159,
199,
504,
10321,
18,
14,
3924,
492,
5458,
14844,
12,
17762,
199,
504,
10321,
18,
14,
1208,
492,
1067,
1593,
12,
492,
63,
875,
12,
17504,
12,
2163,
421,
199,
3,
314,
1454,
3363,
2997,
9796,
3423,
367,
282,
17300,
1978,
14,
221,
3390,
199,
3,
626,
10366,
1471,
506,
7943,
370,
9796,
465,
17300,
3181,
1133,
2291,
199,
3,
2222,
2649,
3326,
14,
199,
2970,
3876,
63,
29865,
275,
12331,
297,
283,
5152,
297,
283,
28234,
358,
421,
199,
533,
13282,
10899,
8,
466,
304,
272,
408,
39,
7602,
314,
3329,
376,
3747,
5148,
1041,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
4336,
275,
730,
855,
1222,
721,
1886,
12,
536,
12,
9768,
12,
366,
9,
267,
4336,
14,
5364,
275,
4336,
855,
578,
363,
435,
7815,
435,
4336,
855,
354,
363,
267,
372,
4336,
421,
199,
533,
13282,
8,
785,
304,
272,
408,
10597,
883,
506,
1202,
370,
1050,
2402,
9330,
370,
314,
17300,
1978,
272,
2656,
737,
314,
1798,
2166,
14,
221,
8388,
5478,
787,
3914,
370,
376,
3734,
272,
1325,
1443,
440,
3877,
3734,
2488,
666,
641,
658,
277,
2313,
221,
710,
4499,
367,
272,
642,
365,
626,
376,
3329,
883,
506,
3914,
370,
4573,
3734,
334,
509,
272,
1806,
9316,
9,
701,
6425,
282,
1331,
436,
295,
5038,
316,
314,
658,
5418,
64,
2225,
14,
339,
3709,
5478,
787,
2737,
701,
314,
3734,
2985,
3913,
4729,
1263,
272,
2368,
367,
2897,
14,
221,
7309,
1443,
2934,
370,
1736,
6818,
626,
701,
1808,
272,
282,
6434,
805,
12,
1325,
626,
365,
440,
3962,
465,
5478,
787,
15836,
272,
701,
3932,
492,
536,
14,
221,
710,
3211,
4340,
370,
7908,
314,
3329,
365,
272,
16915,
314,
2897,
1338,
641,
314,
3734,
14,
221,
13821,
642,
4340,
314,
272,
3734,
11187,
1536,
2454,
316,
465,
18796,
2897,
4887,
314,
272,
3004,
1443,
30109,
1314,
365,
10842,
5478,
1172,
370,
4868,
626,
314,
1561,
272,
2985,
11496,
367,
2897,
787,
440,
4634,
7809,
14,
221,
1124,
1861,
1040,
367,
2893,
272,
365,
282,
2044,
322,
830,
536,
12,
1124,
7677,
63,
1637,
63,
1861,
1040,
641,
314,
1163,
4926,
365,
282,
6954,
272,
536,
465,
6952,
314,
536,
402,
314,
3329,
334,
7677,
2581,
680,
272,
408,
272,
636,
6577,
363,
275,
13282,
10899,
339,
6079,
340,
642,
3329,
19953,
642,
365,
314,
769,
402,
3762,
652,
1159,
22721,
370,
14,
272,
3762,
275,
663,
342,
339,
6079,
314,
7464,
402,
626,
3329,
14,
221,
961,
365,
24002,
2997,
367,
272,
6079,
5478,
626,
23351,
1338,
14,
221,
437,
5117,
574,
4910,
10948,
272,
6079,
7464,
14,
272,
6079,
272,
6079,
2508,
7445,
447,
499,
14,
20,
272,
7464,
275,
2948,
339,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
291,
14,
5418,
275,
3734,
339,
347,
5398,
8,
277,
12,
3734,
304,
267,
408,
2499,
282,
1331,
402,
642,
3329,
3914,
370,
4573,
3734,
1041,
267,
4336,
275,
909,
855,
1222,
721,
277,
855,
533,
3368,
267,
4336,
855,
807,
4343,
873,
8,
277,
855,
807,
3368,
267,
4336,
14,
5418,
275,
3734,
267,
372,
4336,
339,
347,
23351,
8,
277,
12,
1350,
12,
536,
12,
1788,
29,
403,
304,
267,
408,
2765,
1083,
365,
2797,
2544,
314,
3503,
7103,
316,
436,
883,
506,
1202,
370,
267,
23351,
314,
1350,
14,
221,
710,
658,
1501,
64,
365,
2716,
14,
221,
710,
372,
574,
267,
1471,
506,
314,
876,
7292,
1350,
14,
267,
408,
267,
372,
1350,
339,
347,
2457,
63,
1745,
8,
277,
12,
2547,
304,
267,
408,
7940,
1159,
3032,
282,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
3296,
64,
626,
883,
506,
1202,
267,
370,
2457,
4645,
2138,
14,
221,
961,
1083,
965,
370,
372,
376,
6076,
402,
267,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
25502,
83,
12,
1325,
652,
3181,
1133,
1172,
370,
372,
282,
267,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
3296,
2313,
398,
1010,
314,
658,
832,
64,
4922,
402,
314,
17300,
18,
1350,
4084,
2337,
365,
282,
570,
267,
2797,
658,
6460,
5152,
14,
647,
64,
1314,
9031,
282,
2457,
626,
7678,
19030,
397,
642,
267,
1083,
14,
267,
408,
267,
372,
2547,
339,
347,
2198,
8,
277,
12,
1798,
304,
267,
408,
3917,
1263,
402,
314,
520,
962,
1705,
2969,
64,
7838,
642,
1083,
365,
2797,
543,
314,
267,
1798,
465,
1642,
1423,
14,
221,
710,
1526,
314,
1798,
2547,
365,
20686,
737,
267,
365,
314,
536,
1526,
626,
7838,
14,
221,
961,
1083,
965,
370,
372,
1373,
503,
282,
267,
769,
402,
3663,
3380,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
1921,
8,
277,
12,
536,
12,
5874,
29,
403,
304,
267,
408,
1767,
376,
2225,
1031,
367,
314,
1453,
3329,
14,
221,
961,
365,
2997,
267,
370,
986,
5262,
641,
5478,
370,
4046,
1978,
1233,
447,
953,
291,
14,
962,
6412,
1662,
63,
3215,
297,
5874,
29,
3469,
9,
267,
408,
267,
372,
3380,
14,
6382,
1646,
8,
277,
14,
5364,
12,
536,
12,
5874,
29,
3469,
9,
339,
347,
1240,
63,
765,
8,
277,
12,
536,
12,
1249,
29,
403,
12,
2074,
29,
403,
12,
25653,
63,
589,
29,
403,
12,
490,
25653,
63,
958,
29,
403,
12,
5874,
29,
403,
304,
267,
408,
2176,
282,
1083,
402,
314,
3329,
14,
221,
961,
365,
282,
17522,
367,
267,
520,
5247,
1705,
962,
64,
435,
520,
533,
1705,
12264,
18,
14,
2415,
14,
2176,
2313
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10321,
18,
14,
832,
272,
221,
4919,
1714,
339,
17300,
5478,
2040,
370,
1050,
3537,
3762,
8545,
370,
314,
4340,
1639,
3537,
272,
3762,
1736,
14,
221,
4885,
849,
2877,
2893,
5478,
2187,
26,
376,
284,
1085,
78,
436,
282,
2581,
272,
3329,
14,
339,
520,
7307,
26,
334,
67,
9,
7129,
701,
314,
17300,
11682,
14,
272,
520,
1682,
26,
6289,
14,
199,
624,
199,
504,
5055,
492,
15782,
199,
504,
10321,
18,
492,
3380,
199,
504,
10321,
18,
14,
4322,
492,
627,
199,
504,
10321,
18,
14,
5418,
492,
664,
63,
83,
678,
84,
13815,
63,
5418,
199,
504,
10321,
18,
14,
7726,
492,
25868,
12,
17159,
199,
504,
10321,
18,
14,
3924,
492,
5458,
14844,
12,
17762,
199,
504,
10321,
18,
14,
1208,
492,
1067,
1593,
12,
492,
63,
875,
12,
17504,
12,
2163,
421,
199,
3,
314,
1454,
3363,
2997,
9796,
3423,
367,
282,
17300,
1978,
14,
221,
3390,
199,
3,
626,
10366,
1471,
506,
7943,
370,
9796,
465,
17300,
3181,
1133,
2291,
199,
3,
2222,
2649,
3326,
14,
199,
2970,
3876,
63,
29865,
275,
12331,
297,
283,
5152,
297,
283,
28234,
358,
421,
199,
533,
13282,
10899,
8,
466,
304,
272,
408,
39,
7602,
314,
3329,
376,
3747,
5148,
1041,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
366,
304,
267,
4336,
275,
730,
855,
1222,
721,
1886,
12,
536,
12,
9768,
12,
366,
9,
267,
4336,
14,
5364,
275,
4336,
855,
578,
363,
435,
7815,
435,
4336,
855,
354,
363,
267,
372,
4336,
421,
199,
533,
13282,
8,
785,
304,
272,
408,
10597,
883,
506,
1202,
370,
1050,
2402,
9330,
370,
314,
17300,
1978,
272,
2656,
737,
314,
1798,
2166,
14,
221,
8388,
5478,
787,
3914,
370,
376,
3734,
272,
1325,
1443,
440,
3877,
3734,
2488,
666,
641,
658,
277,
2313,
221,
710,
4499,
367,
272,
642,
365,
626,
376,
3329,
883,
506,
3914,
370,
4573,
3734,
334,
509,
272,
1806,
9316,
9,
701,
6425,
282,
1331,
436,
295,
5038,
316,
314,
658,
5418,
64,
2225,
14,
339,
3709,
5478,
787,
2737,
701,
314,
3734,
2985,
3913,
4729,
1263,
272,
2368,
367,
2897,
14,
221,
7309,
1443,
2934,
370,
1736,
6818,
626,
701,
1808,
272,
282,
6434,
805,
12,
1325,
626,
365,
440,
3962,
465,
5478,
787,
15836,
272,
701,
3932,
492,
536,
14,
221,
710,
3211,
4340,
370,
7908,
314,
3329,
365,
272,
16915,
314,
2897,
1338,
641,
314,
3734,
14,
221,
13821,
642,
4340,
314,
272,
3734,
11187,
1536,
2454,
316,
465,
18796,
2897,
4887,
314,
272,
3004,
1443,
30109,
1314,
365,
10842,
5478,
1172,
370,
4868,
626,
314,
1561,
272,
2985,
11496,
367,
2897,
787,
440,
4634,
7809,
14,
221,
1124,
1861,
1040,
367,
2893,
272,
365,
282,
2044,
322,
830,
536,
12,
1124,
7677,
63,
1637,
63,
1861,
1040,
641,
314,
1163,
4926,
365,
282,
6954,
272,
536,
465,
6952,
314,
536,
402,
314,
3329,
334,
7677,
2581,
680,
272,
408,
272,
636,
6577,
363,
275,
13282,
10899,
339,
6079,
340,
642,
3329,
19953,
642,
365,
314,
769,
402,
3762,
652,
1159,
22721,
370,
14,
272,
3762,
275,
663,
342,
339,
6079,
314,
7464,
402,
626,
3329,
14,
221,
961,
365,
24002,
2997,
367,
272,
6079,
5478,
626,
23351,
1338,
14,
221,
437,
5117,
574,
4910,
10948,
272,
6079,
7464,
14,
272,
6079,
272,
6079,
2508,
7445,
447,
499,
14,
20,
272,
7464,
275,
2948,
339,
347,
636,
826,
721,
277,
12,
3734,
304,
267,
291,
14,
5418,
275,
3734,
339,
347,
5398,
8,
277,
12,
3734,
304,
267,
408,
2499,
282,
1331,
402,
642,
3329,
3914,
370,
4573,
3734,
1041,
267,
4336,
275,
909,
855,
1222,
721,
277,
855,
533,
3368,
267,
4336,
855,
807,
4343,
873,
8,
277,
855,
807,
3368,
267,
4336,
14,
5418,
275,
3734,
267,
372,
4336,
339,
347,
23351,
8,
277,
12,
1350,
12,
536,
12,
1788,
29,
403,
304,
267,
408,
2765,
1083,
365,
2797,
2544,
314,
3503,
7103,
316,
436,
883,
506,
1202,
370,
267,
23351,
314,
1350,
14,
221,
710,
658,
1501,
64,
365,
2716,
14,
221,
710,
372,
574,
267,
1471,
506,
314,
876,
7292,
1350,
14,
267,
408,
267,
372,
1350,
339,
347,
2457,
63,
1745,
8,
277,
12,
2547,
304,
267,
408,
7940,
1159,
3032,
282,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
3296,
64,
626,
883,
506,
1202,
267,
370,
2457,
4645,
2138,
14,
221,
961,
1083,
965,
370,
372,
376,
6076,
402,
267,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
25502,
83,
12,
1325,
652,
3181,
1133,
1172,
370,
372,
282,
267,
520,
533,
6054,
12264,
18,
14,
11729,
14,
3264,
3296,
2313,
398,
1010,
314,
658,
832,
64,
4922,
402,
314,
17300,
18,
1350,
4084,
2337,
365,
282,
570,
267,
2797,
658,
6460,
5152,
14,
647,
64,
1314,
9031,
282,
2457,
626,
7678,
19030,
397,
642,
267,
1083,
14,
267,
408,
267,
372,
2547,
339,
347,
2198,
8,
277,
12,
1798,
304,
267,
408,
3917,
1263,
402,
314,
520,
962,
1705,
2969,
64,
7838,
642,
1083,
365,
2797,
543,
314,
267,
1798,
465,
1642,
1423,
14,
221,
710,
1526,
314,
1798,
2547,
365,
20686,
737,
267,
365,
314,
536,
1526,
626,
7838,
14,
221,
961,
1083,
965,
370,
372,
1373,
503,
282,
267,
769,
402,
3663,
3380,
14,
267,
408,
267,
746,
4279,
342,
339,
347,
1921,
8,
277,
12,
536,
12,
5874,
29,
403,
304,
267,
408,
1767,
376,
2225,
1031,
367,
314,
1453,
3329,
14,
221,
961,
365,
2997,
267,
370,
986,
5262,
641,
5478,
370,
4046,
1978,
1233,
447,
953,
291,
14,
962,
6412,
1662,
63,
3215,
297,
5874,
29,
3469,
9,
267,
408,
267,
372,
3380,
14,
6382,
1646,
8,
277,
14,
5364,
12,
536,
12,
5874,
29,
3469,
9,
339,
347,
1240,
63,
765,
8,
277,
12,
536,
12,
1249,
29,
403,
12,
2074,
29,
403,
12,
25653,
63,
589,
29,
403,
12,
490,
25653,
63,
958,
29,
403,
12,
5874,
29,
403,
304,
267,
408,
2176,
282,
1083,
402,
314,
3329,
14,
221,
961,
365,
282,
17522,
367,
267,
520,
5247,
1705,
962,
64,
435,
520,
533,
1705,
12264,
18,
14,
2415,
14,
2176,
2313,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lg-devs/android_kernel_lge_msm8610
|
Documentation/networking/cxacru-cf.py
|
14668
|
1626
|
#!/usr/bin/env python
# Copyright 2009 Simon Arlott
#
# 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., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Usage: cxacru-cf.py < cxacru-cf.bin
# Output: values string suitable for the sysfs adsl_config attribute
#
# Warning: cxacru-cf.bin with MD5 hash cdbac2689969d5ed5d4850f117702110
# contains mis-aligned values which will stop the modem from being able
# to make a connection. If the first and last two bytes are removed then
# the values become valid, but the modulation will be forced to ANSI
# T1.413 only which may not be appropriate.
#
# The original binary format is a packed list of le32 values.
import sys
import struct
i = 0
while True:
buf = sys.stdin.read(4)
if len(buf) == 0:
break
elif len(buf) != 4:
sys.stdout.write("\n")
sys.stderr.write("Error: read {0} not 4 bytes\n".format(len(buf)))
sys.exit(1)
if i > 0:
sys.stdout.write(" ")
sys.stdout.write("{0:x}={1}".format(i, struct.unpack("<I", buf)[0]))
i += 1
sys.stdout.write("\n")
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
8937,
10751,
265,
1952,
1653,
84,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
199,
3,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
3,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
199,
3,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8155,
199,
3,
15630,
10902,
446,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
12,
8217,
14,
199,
3,
199,
3,
11028,
26,
286,
10104,
6558,
13,
2177,
14,
647,
665,
286,
10104,
6558,
13,
2177,
14,
1393,
199,
3,
7242,
26,
1338,
1059,
11233,
367,
314,
984,
2319,
282,
795,
76,
63,
888,
2225,
199,
3,
199,
3,
15902,
26,
286,
10104,
6558,
13,
2177,
14,
1393,
543,
15830,
21,
2631,
286,
697,
645,
13731,
1020,
1876,
68,
21,
379,
21,
68,
2006,
1400,
70,
845,
1138,
996,
6019,
199,
3,
3509,
3201,
13,
19175,
1338,
1314,
911,
3631,
314,
818,
77,
687,
3769,
7688,
199,
3,
370,
1852,
282,
1950,
14,
982,
314,
1642,
436,
2061,
2877,
2783,
787,
4829,
2066,
199,
3,
314,
1338,
8649,
1686,
12,
1325,
314,
3413,
5332,
911,
506,
19565,
370,
25600,
199,
3,
377,
17,
14,
23663,
1454,
1314,
1443,
440,
506,
5827,
14,
199,
3,
199,
3,
710,
3379,
3366,
1475,
365,
282,
13170,
769,
402,
1026,
708,
1338,
14,
199,
199,
646,
984,
199,
646,
2702,
199,
199,
73,
275,
378,
199,
6710,
715,
26,
199,
198,
1436,
275,
984,
14,
6626,
14,
739,
8,
20,
9,
421,
198,
692,
822,
8,
1436,
9,
508,
378,
26,
507,
198,
4785,
199,
198,
4164,
822,
8,
1436,
9,
1137,
841,
26,
507,
198,
1274,
14,
2703,
14,
952,
4582,
78,
531,
507,
198,
1274,
14,
3083,
14,
952,
480,
547,
26,
1586,
469,
16,
93,
440,
841,
2783,
60,
78,
1674,
908,
8,
552,
8,
1436,
1724,
507,
198,
1274,
14,
2224,
8,
17,
9,
421,
198,
692,
284,
690,
378,
26,
507,
198,
1274,
14,
2703,
14,
952,
480,
6099,
199,
198,
1274,
14,
2703,
14,
952,
13076,
16,
26,
88,
93,
3126,
17,
5469,
908,
8,
73,
12,
2702,
14,
5301,
6757,
41,
401,
4123,
2788,
16,
2459,
199,
198,
73,
847,
413,
199,
199,
1274,
14,
2703,
14,
952,
4582,
78,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
devlin85/p2pool
|
p2pool/bitcoin/worker_interface.py
|
230
|
5901
|
from __future__ import division
import StringIO
import json
import random
import sys
from twisted.internet import defer
import p2pool
from p2pool.bitcoin import data as bitcoin_data, getwork
from p2pool.util import expiring_dict, jsonrpc, pack, variable
class _Provider(object):
def __init__(self, parent, long_poll):
self.parent = parent
self.long_poll = long_poll
def rpc_getwork(self, request, data=None):
return self.parent._getwork(request, data, long_poll=self.long_poll)
class _GETableServer(jsonrpc.HTTPServer):
def __init__(self, provider, render_get_func):
jsonrpc.HTTPServer.__init__(self, provider)
self.render_GET = render_get_func
class WorkerBridge(object):
def __init__(self):
self.new_work_event = variable.Event()
def preprocess_request(self, request):
return request, # *args to self.compute
def get_work(self, request):
raise NotImplementedError()
class WorkerInterface(object):
def __init__(self, worker_bridge):
self.worker_bridge = worker_bridge
self.worker_views = {}
self.merkle_root_to_handler = expiring_dict.ExpiringDict(300)
def attach_to(self, res, get_handler=None):
res.putChild('', _GETableServer(_Provider(self, long_poll=False), get_handler))
def repost(request):
request.content = StringIO.StringIO(json.dumps(dict(id=0, method='getwork')))
return s.render_POST(request)
s = _GETableServer(_Provider(self, long_poll=True), repost)
res.putChild('long-polling', s)
@defer.inlineCallbacks
def _getwork(self, request, data, long_poll):
request.setHeader('X-Long-Polling', '/long-polling')
request.setHeader('X-Roll-NTime', 'expire=100')
request.setHeader('X-Is-P2Pool', 'true')
if request.getHeader('Host') is not None:
request.setHeader('X-Stratum', 'stratum+tcp://' + request.getHeader('Host'))
if data is not None:
header = getwork.decode_data(data)
if header['merkle_root'] not in self.merkle_root_to_handler:
print >>sys.stderr, '''Couldn't link returned work's merkle root with its handler. This should only happen if this process was recently restarted!'''
defer.returnValue(False)
defer.returnValue(self.merkle_root_to_handler[header['merkle_root']](header, request.getUser() if request.getUser() is not None else '', '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH))
if p2pool.DEBUG:
id = random.randrange(1000, 10000)
print 'POLL %i START is_long_poll=%r user_agent=%r user=%r' % (id, long_poll, request.getHeader('User-Agent'), request.getUser())
if long_poll:
request_id = request.getClientIP(), request.getHeader('Authorization')
if self.worker_views.get(request_id, self.worker_bridge.new_work_event.times) != self.worker_bridge.new_work_event.times:
if p2pool.DEBUG:
print 'POLL %i PUSH' % (id,)
else:
if p2pool.DEBUG:
print 'POLL %i WAITING' % (id,)
yield self.worker_bridge.new_work_event.get_deferred()
self.worker_views[request_id] = self.worker_bridge.new_work_event.times
x, handler = self.worker_bridge.get_work(*self.worker_bridge.preprocess_request(request.getUser() if request.getUser() is not None else ''))
res = getwork.BlockAttempt(
version=x['version'],
previous_block=x['previous_block'],
merkle_root=bitcoin_data.check_merkle_link(bitcoin_data.hash256(x['coinb1'] + '\0'*self.worker_bridge.COINBASE_NONCE_LENGTH + x['coinb2']), x['merkle_link']),
timestamp=x['timestamp'],
bits=x['bits'],
share_target=x['share_target'],
)
assert res.merkle_root not in self.merkle_root_to_handler
self.merkle_root_to_handler[res.merkle_root] = handler
if p2pool.DEBUG:
print 'POLL %i END identifier=%i' % (id, self.worker_bridge.new_work_event.times)
extra_params = {}
if request.getHeader('User-Agent') == 'Jephis PIC Miner':
# ASICMINER BE Blades apparently have a buffer overflow bug and
# can't handle much extra in the getwork response
extra_params = {}
else:
extra_params = dict(identifier=str(self.worker_bridge.new_work_event.times), submitold=True)
defer.returnValue(res.getwork(**extra_params))
class CachingWorkerBridge(object):
def __init__(self, inner):
self._inner = inner
self.net = self._inner.net
self.COINBASE_NONCE_LENGTH = (inner.COINBASE_NONCE_LENGTH+1)//2
self.new_work_event = inner.new_work_event
self.preprocess_request = inner.preprocess_request
self._my_bits = (self._inner.COINBASE_NONCE_LENGTH - self.COINBASE_NONCE_LENGTH)*8
self._cache = {}
self._times = None
def get_work(self, *args):
if self._times != self.new_work_event.times:
self._cache = {}
self._times = self.new_work_event.times
if args not in self._cache:
x, handler = self._inner.get_work(*args)
self._cache[args] = x, handler, 0
x, handler, nonce = self._cache.pop(args)
res = (
dict(x, coinb1=x['coinb1'] + pack.IntType(self._my_bits).pack(nonce)),
lambda header, user, coinbase_nonce: handler(header, user, pack.IntType(self._my_bits).pack(nonce) + coinbase_nonce),
)
if nonce + 1 != 2**self._my_bits:
self._cache[args] = x, handler, nonce + 1
return res
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
4629,
199,
199,
646,
5228,
199,
646,
2022,
199,
646,
2196,
199,
646,
984,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
646,
299,
18,
2293,
199,
504,
299,
18,
2293,
14,
22816,
492,
666,
465,
27214,
63,
576,
12,
664,
800,
199,
504,
299,
18,
2293,
14,
1974,
492,
1437,
16648,
63,
807,
12,
2022,
4354,
12,
1706,
12,
1750,
199,
199,
533,
485,
6663,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
1846,
63,
6843,
304,
267,
291,
14,
1708,
275,
1676,
267,
291,
14,
2809,
63,
6843,
275,
1846,
63,
6843,
2286,
347,
8985,
63,
362,
800,
8,
277,
12,
1056,
12,
666,
29,
403,
304,
267,
372,
291,
14,
1708,
423,
362,
800,
8,
1069,
12,
666,
12,
1846,
63,
6843,
29,
277,
14,
2809,
63,
6843,
9,
199,
199,
533,
485,
2970,
461,
3120,
8,
31395,
14,
14938,
304,
272,
347,
636,
826,
721,
277,
12,
5022,
12,
3795,
63,
362,
63,
1532,
304,
267,
2022,
4354,
14,
14938,
855,
826,
721,
277,
12,
5022,
9,
267,
291,
14,
3352,
63,
2970,
275,
3795,
63,
362,
63,
1532,
199,
199,
533,
23886,
14491,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1222,
63,
800,
63,
1430,
275,
1750,
14,
2390,
342,
2286,
347,
23351,
63,
1069,
8,
277,
12,
1056,
304,
267,
372,
1056,
12,
327,
627,
589,
370,
291,
14,
3357,
2286,
347,
664,
63,
800,
8,
277,
12,
1056,
304,
267,
746,
4279,
342,
199,
199,
533,
23886,
4267,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
7239,
63,
9528,
304,
267,
291,
14,
6599,
63,
9528,
275,
7239,
63,
9528,
2728,
291,
14,
6599,
63,
4196,
275,
1052,
2728,
291,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
275,
1437,
16648,
63,
807,
14,
4527,
16648,
2141,
8,
5863,
9,
2286,
347,
6554,
63,
475,
8,
277,
12,
522,
12,
664,
63,
2232,
29,
403,
304,
267,
522,
14,
524,
3493,
8594,
485,
2970,
461,
3120,
1547,
6663,
8,
277,
12,
1846,
63,
6843,
29,
797,
395,
664,
63,
2232,
430,
2728,
347,
295,
1932,
8,
1069,
304,
288,
1056,
14,
1317,
275,
5228,
14,
6424,
8,
1001,
14,
4180,
8,
807,
8,
344,
29,
16,
12,
1083,
534,
362,
800,
7058,
288,
372,
308,
14,
3352,
63,
4030,
8,
1069,
9,
267,
308,
275,
485,
2970,
461,
3120,
1547,
6663,
8,
277,
12,
1846,
63,
6843,
29,
549,
395,
295,
1932,
9,
267,
522,
14,
524,
3493,
360,
2809,
13,
17154,
297,
308,
9,
2286,
768,
11610,
14,
24813,
272,
347,
485,
362,
800,
8,
277,
12,
1056,
12,
666,
12,
1846,
63,
6843,
304,
267,
1056,
14,
409,
2567,
360,
56,
13,
9551,
13,
28588,
297,
1994,
2809,
13,
17154,
358,
267,
1056,
14,
409,
2567,
360,
56,
13,
24363,
13,
46,
1366,
297,
283,
14691,
29,
1960,
358,
267,
1056,
14,
409,
2567,
360,
56,
13,
1831,
13,
48,
18,
5453,
297,
283,
2052,
358,
267,
340,
1056,
14,
362,
2567,
360,
4965,
358,
365,
440,
488,
26,
288,
1056,
14,
409,
2567,
360,
56,
13,
2848,
5729,
297,
283,
495,
5729,
11,
8815,
22399,
435,
1056,
14,
362,
2567,
360,
4965,
1333,
2728,
340,
666,
365,
440,
488,
26,
288,
1406,
275,
664,
800,
14,
2708,
63,
576,
8,
576,
9,
288,
340,
1406,
459,
2626,
23572,
63,
1231,
418,
440,
315,
291,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
26,
355,
870,
4331,
1274,
14,
3083,
12,
1449,
20485,
1133,
2142,
2138,
1736,
1159,
4004,
23572,
1738,
543,
2399,
3016,
14,
961,
1077,
1454,
5992,
340,
642,
2112,
1990,
23568,
32277,
1,
2344,
355,
10133,
14,
1107,
1110,
8,
797,
9,
288,
10133,
14,
1107,
1110,
8,
277,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
59,
1291,
459,
2626,
23572,
63,
1231,
6538,
8,
1291,
12,
1056,
14,
32627,
342,
340,
1056,
14,
32627,
342,
365,
440,
488,
587,
3260,
1557,
16,
16804,
277,
14,
6599,
63,
9528,
14,
1439,
568,
5825,
63,
13887,
2089,
63,
9127,
430,
2728,
340,
299,
18,
2293,
14,
5287,
26,
288,
1305,
275,
2196,
14,
20539,
8,
5279,
12,
11630,
9,
288,
870,
283,
16428,
450,
73,
13910,
365,
63,
2809,
63,
6843,
2458,
82,
922,
63,
4054,
2458,
82,
922,
2458,
82,
7,
450,
334,
344,
12,
1846,
63,
6843,
12,
1056,
14,
362,
2567,
360,
1899,
13,
7788,
659,
1056,
14,
32627,
1012,
2728,
340,
1846,
63,
6843,
26,
288,
1056,
63,
344,
275,
1056,
14,
362,
3041,
1772,
1062,
1056,
14,
362,
2567,
360,
11626,
358,
288,
340,
291,
14,
6599,
63,
4196,
14,
362,
8,
1069,
63,
344,
12,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
9,
1137,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
26,
355,
340,
299,
18,
2293,
14,
5287,
26,
490,
870,
283,
16428,
450,
73,
510,
14527,
7,
450,
334,
344,
4258,
288,
587,
26,
355,
340,
299,
18,
2293,
14,
5287,
26,
490,
870,
283,
16428,
450,
73,
644,
33,
649,
1206,
7,
450,
334,
344,
4258,
355,
1995,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
362,
63,
12116,
342,
288,
291,
14,
6599,
63,
4196,
59,
1069,
63,
344,
61,
275,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
2728,
671,
12,
3016,
275,
291,
14,
6599,
63,
9528,
14,
362,
63,
800,
2031,
277,
14,
6599,
63,
9528,
14,
17677,
63,
1069,
8,
1069,
14,
32627,
342,
340,
1056,
14,
32627,
342,
365,
440,
488,
587,
12381,
267,
522,
275,
664,
800,
14,
3142,
23272,
8,
288,
1015,
29,
88,
459,
1023,
995,
288,
4136,
63,
1457,
29,
88,
459,
6352,
63,
1457,
995,
288,
4004,
23572,
63,
1231,
29,
22816,
63,
576,
14,
1074,
63,
2626,
23572,
63,
1073,
8,
22816,
63,
576,
14,
2227,
3912,
8,
88,
459,
9061,
66,
17,
418,
435,
1557,
16,
16804,
277,
14,
6599,
63,
9528,
14,
1439,
568,
5825,
63,
13887,
2089,
63,
9127,
435,
671,
459,
9061,
66,
18
] |
[
636,
2443,
363,
492,
4629,
199,
199,
646,
5228,
199,
646,
2022,
199,
646,
2196,
199,
646,
984,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
199,
646,
299,
18,
2293,
199,
504,
299,
18,
2293,
14,
22816,
492,
666,
465,
27214,
63,
576,
12,
664,
800,
199,
504,
299,
18,
2293,
14,
1974,
492,
1437,
16648,
63,
807,
12,
2022,
4354,
12,
1706,
12,
1750,
199,
199,
533,
485,
6663,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
1846,
63,
6843,
304,
267,
291,
14,
1708,
275,
1676,
267,
291,
14,
2809,
63,
6843,
275,
1846,
63,
6843,
2286,
347,
8985,
63,
362,
800,
8,
277,
12,
1056,
12,
666,
29,
403,
304,
267,
372,
291,
14,
1708,
423,
362,
800,
8,
1069,
12,
666,
12,
1846,
63,
6843,
29,
277,
14,
2809,
63,
6843,
9,
199,
199,
533,
485,
2970,
461,
3120,
8,
31395,
14,
14938,
304,
272,
347,
636,
826,
721,
277,
12,
5022,
12,
3795,
63,
362,
63,
1532,
304,
267,
2022,
4354,
14,
14938,
855,
826,
721,
277,
12,
5022,
9,
267,
291,
14,
3352,
63,
2970,
275,
3795,
63,
362,
63,
1532,
199,
199,
533,
23886,
14491,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1222,
63,
800,
63,
1430,
275,
1750,
14,
2390,
342,
2286,
347,
23351,
63,
1069,
8,
277,
12,
1056,
304,
267,
372,
1056,
12,
327,
627,
589,
370,
291,
14,
3357,
2286,
347,
664,
63,
800,
8,
277,
12,
1056,
304,
267,
746,
4279,
342,
199,
199,
533,
23886,
4267,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
7239,
63,
9528,
304,
267,
291,
14,
6599,
63,
9528,
275,
7239,
63,
9528,
2728,
291,
14,
6599,
63,
4196,
275,
1052,
2728,
291,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
275,
1437,
16648,
63,
807,
14,
4527,
16648,
2141,
8,
5863,
9,
2286,
347,
6554,
63,
475,
8,
277,
12,
522,
12,
664,
63,
2232,
29,
403,
304,
267,
522,
14,
524,
3493,
8594,
485,
2970,
461,
3120,
1547,
6663,
8,
277,
12,
1846,
63,
6843,
29,
797,
395,
664,
63,
2232,
430,
2728,
347,
295,
1932,
8,
1069,
304,
288,
1056,
14,
1317,
275,
5228,
14,
6424,
8,
1001,
14,
4180,
8,
807,
8,
344,
29,
16,
12,
1083,
534,
362,
800,
7058,
288,
372,
308,
14,
3352,
63,
4030,
8,
1069,
9,
267,
308,
275,
485,
2970,
461,
3120,
1547,
6663,
8,
277,
12,
1846,
63,
6843,
29,
549,
395,
295,
1932,
9,
267,
522,
14,
524,
3493,
360,
2809,
13,
17154,
297,
308,
9,
2286,
768,
11610,
14,
24813,
272,
347,
485,
362,
800,
8,
277,
12,
1056,
12,
666,
12,
1846,
63,
6843,
304,
267,
1056,
14,
409,
2567,
360,
56,
13,
9551,
13,
28588,
297,
1994,
2809,
13,
17154,
358,
267,
1056,
14,
409,
2567,
360,
56,
13,
24363,
13,
46,
1366,
297,
283,
14691,
29,
1960,
358,
267,
1056,
14,
409,
2567,
360,
56,
13,
1831,
13,
48,
18,
5453,
297,
283,
2052,
358,
267,
340,
1056,
14,
362,
2567,
360,
4965,
358,
365,
440,
488,
26,
288,
1056,
14,
409,
2567,
360,
56,
13,
2848,
5729,
297,
283,
495,
5729,
11,
8815,
22399,
435,
1056,
14,
362,
2567,
360,
4965,
1333,
2728,
340,
666,
365,
440,
488,
26,
288,
1406,
275,
664,
800,
14,
2708,
63,
576,
8,
576,
9,
288,
340,
1406,
459,
2626,
23572,
63,
1231,
418,
440,
315,
291,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
26,
355,
870,
4331,
1274,
14,
3083,
12,
1449,
20485,
1133,
2142,
2138,
1736,
1159,
4004,
23572,
1738,
543,
2399,
3016,
14,
961,
1077,
1454,
5992,
340,
642,
2112,
1990,
23568,
32277,
1,
2344,
355,
10133,
14,
1107,
1110,
8,
797,
9,
288,
10133,
14,
1107,
1110,
8,
277,
14,
2626,
23572,
63,
1231,
63,
475,
63,
2232,
59,
1291,
459,
2626,
23572,
63,
1231,
6538,
8,
1291,
12,
1056,
14,
32627,
342,
340,
1056,
14,
32627,
342,
365,
440,
488,
587,
3260,
1557,
16,
16804,
277,
14,
6599,
63,
9528,
14,
1439,
568,
5825,
63,
13887,
2089,
63,
9127,
430,
2728,
340,
299,
18,
2293,
14,
5287,
26,
288,
1305,
275,
2196,
14,
20539,
8,
5279,
12,
11630,
9,
288,
870,
283,
16428,
450,
73,
13910,
365,
63,
2809,
63,
6843,
2458,
82,
922,
63,
4054,
2458,
82,
922,
2458,
82,
7,
450,
334,
344,
12,
1846,
63,
6843,
12,
1056,
14,
362,
2567,
360,
1899,
13,
7788,
659,
1056,
14,
32627,
1012,
2728,
340,
1846,
63,
6843,
26,
288,
1056,
63,
344,
275,
1056,
14,
362,
3041,
1772,
1062,
1056,
14,
362,
2567,
360,
11626,
358,
288,
340,
291,
14,
6599,
63,
4196,
14,
362,
8,
1069,
63,
344,
12,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
9,
1137,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
26,
355,
340,
299,
18,
2293,
14,
5287,
26,
490,
870,
283,
16428,
450,
73,
510,
14527,
7,
450,
334,
344,
4258,
288,
587,
26,
355,
340,
299,
18,
2293,
14,
5287,
26,
490,
870,
283,
16428,
450,
73,
644,
33,
649,
1206,
7,
450,
334,
344,
4258,
355,
1995,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
362,
63,
12116,
342,
288,
291,
14,
6599,
63,
4196,
59,
1069,
63,
344,
61,
275,
291,
14,
6599,
63,
9528,
14,
1222,
63,
800,
63,
1430,
14,
4508,
2728,
671,
12,
3016,
275,
291,
14,
6599,
63,
9528,
14,
362,
63,
800,
2031,
277,
14,
6599,
63,
9528,
14,
17677,
63,
1069,
8,
1069,
14,
32627,
342,
340,
1056,
14,
32627,
342,
365,
440,
488,
587,
12381,
267,
522,
275,
664,
800,
14,
3142,
23272,
8,
288,
1015,
29,
88,
459,
1023,
995,
288,
4136,
63,
1457,
29,
88,
459,
6352,
63,
1457,
995,
288,
4004,
23572,
63,
1231,
29,
22816,
63,
576,
14,
1074,
63,
2626,
23572,
63,
1073,
8,
22816,
63,
576,
14,
2227,
3912,
8,
88,
459,
9061,
66,
17,
418,
435,
1557,
16,
16804,
277,
14,
6599,
63,
9528,
14,
1439,
568,
5825,
63,
13887,
2089,
63,
9127,
435,
671,
459,
9061,
66,
18,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ycaihua/kbengine
|
kbe/src/lib/python/Lib/selectors.py
|
75
|
16460
|
"""Selectors module.
This module allows high-level and efficient I/O multiplexing, built upon the
`select` module primitives.
"""
from abc import ABCMeta, abstractmethod
from collections import namedtuple, Mapping
import math
import select
import sys
# generic events, that must be mapped to implementation-specific ones
EVENT_READ = (1 << 0)
EVENT_WRITE = (1 << 1)
def _fileobj_to_fd(fileobj):
"""Return a file descriptor from a file object.
Parameters:
fileobj -- file object or file descriptor
Returns:
corresponding file descriptor
Raises:
ValueError if the object is invalid
"""
if isinstance(fileobj, int):
fd = fileobj
else:
try:
fd = int(fileobj.fileno())
except (AttributeError, TypeError, ValueError):
raise ValueError("Invalid file object: "
"{!r}".format(fileobj)) from None
if fd < 0:
raise ValueError("Invalid file descriptor: {}".format(fd))
return fd
SelectorKey = namedtuple('SelectorKey', ['fileobj', 'fd', 'events', 'data'])
"""Object used to associate a file object to its backing file descriptor,
selected event mask and attached data."""
class _SelectorMapping(Mapping):
"""Mapping of file objects to selector keys."""
def __init__(self, selector):
self._selector = selector
def __len__(self):
return len(self._selector._fd_to_key)
def __getitem__(self, fileobj):
try:
fd = self._selector._fileobj_lookup(fileobj)
return self._selector._fd_to_key[fd]
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
def __iter__(self):
return iter(self._selector._fd_to_key)
class BaseSelector(metaclass=ABCMeta):
"""Selector abstract base class.
A selector supports registering file objects to be monitored for specific
I/O events.
A file object is a file descriptor or any object with a `fileno()` method.
An arbitrary object can be attached to the file object, which can be used
for example to store context information, a callback, etc.
A selector can use various implementations (select(), poll(), epoll()...)
depending on the platform. The default `Selector` class uses the most
efficient implementation on the current platform.
"""
@abstractmethod
def register(self, fileobj, events, data=None):
"""Register a file object.
Parameters:
fileobj -- file object or file descriptor
events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
data -- attached data
Returns:
SelectorKey instance
Raises:
ValueError if events is invalid
KeyError if fileobj is already registered
OSError if fileobj is closed or otherwise is unacceptable to
the underlying system call (if a system call is made)
Note:
OSError may or may not be raised
"""
raise NotImplementedError
@abstractmethod
def unregister(self, fileobj):
"""Unregister a file object.
Parameters:
fileobj -- file object or file descriptor
Returns:
SelectorKey instance
Raises:
KeyError if fileobj is not registered
Note:
If fileobj is registered but has since been closed this does
*not* raise OSError (even if the wrapped syscall does)
"""
raise NotImplementedError
def modify(self, fileobj, events, data=None):
"""Change a registered file object monitored events or attached data.
Parameters:
fileobj -- file object or file descriptor
events -- events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE)
data -- attached data
Returns:
SelectorKey instance
Raises:
Anything that unregister() or register() raises
"""
self.unregister(fileobj)
return self.register(fileobj, events, data)
@abstractmethod
def select(self, timeout=None):
"""Perform the actual selection, until some monitored file objects are
ready or a timeout expires.
Parameters:
timeout -- if timeout > 0, this specifies the maximum wait time, in
seconds
if timeout <= 0, the select() call won't block, and will
report the currently ready file objects
if timeout is None, select() will block until a monitored
file object becomes ready
Returns:
list of (key, events) for ready file objects
`events` is a bitwise mask of EVENT_READ|EVENT_WRITE
"""
raise NotImplementedError
def close(self):
"""Close the selector.
This must be called to make sure that any underlying resource is freed.
"""
pass
def get_key(self, fileobj):
"""Return the key associated to a registered file object.
Returns:
SelectorKey for this file object
"""
mapping = self.get_map()
try:
return mapping[fileobj]
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
@abstractmethod
def get_map(self):
"""Return a mapping of file objects to selector keys."""
raise NotImplementedError
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
class _BaseSelectorImpl(BaseSelector):
"""Base selector implementation."""
def __init__(self):
# this maps file descriptors to keys
self._fd_to_key = {}
# read-only mapping returned by get_map()
self._map = _SelectorMapping(self)
def _fileobj_lookup(self, fileobj):
"""Return a file descriptor from a file object.
This wraps _fileobj_to_fd() to do an exhaustive search in case
the object is invalid but we still have it in our map. This
is used by unregister() so we can unregister an object that
was previously registered even if it is closed. It is also
used by _SelectorMapping.
"""
try:
return _fileobj_to_fd(fileobj)
except ValueError:
# Do an exhaustive search.
for key in self._fd_to_key.values():
if key.fileobj is fileobj:
return key.fd
# Raise ValueError after all.
raise
def register(self, fileobj, events, data=None):
if (not events) or (events & ~(EVENT_READ | EVENT_WRITE)):
raise ValueError("Invalid events: {!r}".format(events))
key = SelectorKey(fileobj, self._fileobj_lookup(fileobj), events, data)
if key.fd in self._fd_to_key:
raise KeyError("{!r} (FD {}) is already registered"
.format(fileobj, key.fd))
self._fd_to_key[key.fd] = key
return key
def unregister(self, fileobj):
try:
key = self._fd_to_key.pop(self._fileobj_lookup(fileobj))
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
return key
def modify(self, fileobj, events, data=None):
# TODO: Subclasses can probably optimize this even further.
try:
key = self._fd_to_key[self._fileobj_lookup(fileobj)]
except KeyError:
raise KeyError("{!r} is not registered".format(fileobj)) from None
if events != key.events:
self.unregister(fileobj)
key = self.register(fileobj, events, data)
elif data != key.data:
# Use a shortcut to update the data.
key = key._replace(data=data)
self._fd_to_key[key.fd] = key
return key
def close(self):
self._fd_to_key.clear()
def get_map(self):
return self._map
def _key_from_fd(self, fd):
"""Return the key associated to a given file descriptor.
Parameters:
fd -- file descriptor
Returns:
corresponding key, or None if not found
"""
try:
return self._fd_to_key[fd]
except KeyError:
return None
class SelectSelector(_BaseSelectorImpl):
"""Select-based selector."""
def __init__(self):
super().__init__()
self._readers = set()
self._writers = set()
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
if events & EVENT_READ:
self._readers.add(key.fd)
if events & EVENT_WRITE:
self._writers.add(key.fd)
return key
def unregister(self, fileobj):
key = super().unregister(fileobj)
self._readers.discard(key.fd)
self._writers.discard(key.fd)
return key
if sys.platform == 'win32':
def _select(self, r, w, _, timeout=None):
r, w, x = select.select(r, w, w, timeout)
return r, w + x, []
else:
_select = select.select
def select(self, timeout=None):
timeout = None if timeout is None else max(timeout, 0)
ready = []
try:
r, w, _ = self._select(self._readers, self._writers, [], timeout)
except InterruptedError:
return ready
r = set(r)
w = set(w)
for fd in r | w:
events = 0
if fd in r:
events |= EVENT_READ
if fd in w:
events |= EVENT_WRITE
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
if hasattr(select, 'poll'):
class PollSelector(_BaseSelectorImpl):
"""Poll-based selector."""
def __init__(self):
super().__init__()
self._poll = select.poll()
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
poll_events = 0
if events & EVENT_READ:
poll_events |= select.POLLIN
if events & EVENT_WRITE:
poll_events |= select.POLLOUT
self._poll.register(key.fd, poll_events)
return key
def unregister(self, fileobj):
key = super().unregister(fileobj)
self._poll.unregister(key.fd)
return key
def select(self, timeout=None):
if timeout is None:
timeout = None
elif timeout <= 0:
timeout = 0
else:
# poll() has a resolution of 1 millisecond, round away from
# zero to wait *at least* timeout seconds.
timeout = math.ceil(timeout * 1e3)
ready = []
try:
fd_event_list = self._poll.poll(timeout)
except InterruptedError:
return ready
for fd, event in fd_event_list:
events = 0
if event & ~select.POLLIN:
events |= EVENT_WRITE
if event & ~select.POLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
if hasattr(select, 'epoll'):
class EpollSelector(_BaseSelectorImpl):
"""Epoll-based selector."""
def __init__(self):
super().__init__()
self._epoll = select.epoll()
def fileno(self):
return self._epoll.fileno()
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
epoll_events = 0
if events & EVENT_READ:
epoll_events |= select.EPOLLIN
if events & EVENT_WRITE:
epoll_events |= select.EPOLLOUT
self._epoll.register(key.fd, epoll_events)
return key
def unregister(self, fileobj):
key = super().unregister(fileobj)
try:
self._epoll.unregister(key.fd)
except OSError:
# This can happen if the FD was closed since it
# was registered.
pass
return key
def select(self, timeout=None):
if timeout is None:
timeout = -1
elif timeout <= 0:
timeout = 0
else:
# epoll_wait() has a resolution of 1 millisecond, round away
# from zero to wait *at least* timeout seconds.
timeout = math.ceil(timeout * 1e3) * 1e-3
max_ev = len(self._fd_to_key)
ready = []
try:
fd_event_list = self._epoll.poll(timeout, max_ev)
except InterruptedError:
return ready
for fd, event in fd_event_list:
events = 0
if event & ~select.EPOLLIN:
events |= EVENT_WRITE
if event & ~select.EPOLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
def close(self):
self._epoll.close()
super().close()
if hasattr(select, 'kqueue'):
class KqueueSelector(_BaseSelectorImpl):
"""Kqueue-based selector."""
def __init__(self):
super().__init__()
self._kqueue = select.kqueue()
def fileno(self):
return self._kqueue.fileno()
def register(self, fileobj, events, data=None):
key = super().register(fileobj, events, data)
if events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_ADD)
self._kqueue.control([kev], 0, 0)
if events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_ADD)
self._kqueue.control([kev], 0, 0)
return key
def unregister(self, fileobj):
key = super().unregister(fileobj)
if key.events & EVENT_READ:
kev = select.kevent(key.fd, select.KQ_FILTER_READ,
select.KQ_EV_DELETE)
try:
self._kqueue.control([kev], 0, 0)
except OSError:
# This can happen if the FD was closed since it
# was registered.
pass
if key.events & EVENT_WRITE:
kev = select.kevent(key.fd, select.KQ_FILTER_WRITE,
select.KQ_EV_DELETE)
try:
self._kqueue.control([kev], 0, 0)
except OSError:
# See comment above.
pass
return key
def select(self, timeout=None):
timeout = None if timeout is None else max(timeout, 0)
max_ev = len(self._fd_to_key)
ready = []
try:
kev_list = self._kqueue.control(None, max_ev, timeout)
except InterruptedError:
return ready
for kev in kev_list:
fd = kev.ident
flag = kev.filter
events = 0
if flag == select.KQ_FILTER_READ:
events |= EVENT_READ
if flag == select.KQ_FILTER_WRITE:
events |= EVENT_WRITE
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
def close(self):
self._kqueue.close()
super().close()
# Choose the best implementation: roughly, epoll|kqueue > poll > select.
# select() also can't accept a FD > FD_SETSIZE (usually around 1024)
if 'KqueueSelector' in globals():
DefaultSelector = KqueueSelector
elif 'EpollSelector' in globals():
DefaultSelector = EpollSelector
elif 'PollSelector' in globals():
DefaultSelector = PollSelector
else:
DefaultSelector = SelectSelector
|
lgpl-3.0
|
[
624,
11212,
83,
859,
14,
199,
199,
2765,
859,
6127,
4721,
13,
1896,
436,
13402,
473,
15,
47,
3663,
88,
316,
12,
6137,
12188,
314,
199,
64,
2416,
64,
859,
1979,
22337,
14,
199,
624,
421,
199,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
5055,
492,
12863,
12,
12340,
199,
646,
3473,
199,
646,
3504,
199,
646,
984,
421,
199,
3,
7809,
4474,
12,
626,
1471,
506,
9994,
370,
4514,
13,
6100,
7869,
199,
8193,
63,
5670,
275,
334,
17,
5213,
378,
9,
199,
8193,
63,
10387,
275,
334,
17,
5213,
413,
9,
421,
199,
318,
485,
9234,
63,
475,
63,
2592,
8,
9234,
304,
272,
408,
1767,
282,
570,
5872,
687,
282,
570,
909,
14,
339,
3897,
26,
272,
11099,
1553,
570,
909,
503,
570,
5872,
339,
1803,
26,
272,
5226,
570,
5872,
339,
6218,
26,
272,
1722,
340,
314,
909,
365,
3866,
272,
408,
272,
340,
1228,
8,
9234,
12,
1109,
304,
267,
6111,
275,
11099,
272,
587,
26,
267,
862,
26,
288,
6111,
275,
1109,
8,
9234,
14,
9843,
1012,
267,
871,
334,
10227,
12,
3146,
12,
1722,
304,
288,
746,
1722,
480,
3364,
570,
909,
26,
298,
2490,
5310,
1,
82,
5469,
908,
8,
9234,
430,
687,
488,
272,
340,
6111,
665,
378,
26,
267,
746,
1722,
480,
3364,
570,
5872,
26,
8352,
908,
8,
2592,
430,
272,
372,
6111,
421,
199,
11212,
1197,
275,
12863,
360,
11212,
1197,
297,
788,
9234,
297,
283,
2592,
297,
283,
4368,
297,
283,
576,
1105,
199,
624,
1692,
1202,
370,
20133,
282,
570,
909,
370,
2399,
21094,
570,
5872,
12,
199,
5511,
1566,
3656,
436,
10102,
666,
1041,
421,
199,
533,
485,
11212,
7674,
8,
7674,
304,
272,
408,
7674,
402,
570,
2251,
370,
9759,
2883,
1041,
339,
347,
636,
826,
721,
277,
12,
9759,
304,
267,
291,
423,
6662,
275,
9759,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
6662,
423,
2592,
63,
475,
63,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
11099,
304,
267,
862,
26,
288,
6111,
275,
291,
423,
6662,
423,
9234,
63,
3892,
8,
9234,
9,
288,
372,
291,
423,
6662,
423,
2592,
63,
475,
63,
498,
59,
2592,
61,
267,
871,
4067,
26,
288,
746,
4067,
13076,
1,
82,
93,
365,
440,
7264,
1674,
908,
8,
9234,
430,
687,
488,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
6662,
423,
2592,
63,
475,
63,
498,
9,
421,
199,
533,
3523,
11212,
8,
6577,
29,
22254,
304,
272,
408,
11212,
9006,
1300,
1021,
14,
339,
437,
9759,
5171,
2274,
316,
570,
2251,
370,
506,
23821,
367,
2488,
272,
473,
15,
47,
4474,
14,
339,
437,
570,
909,
365,
282,
570,
5872,
503,
1263,
909,
543,
282,
658,
9843,
11995,
1083,
14,
272,
1626,
9697,
909,
883,
506,
10102,
370,
314,
570,
909,
12,
1314,
883,
506,
1202,
272,
367,
2893,
370,
3877,
1067,
2556,
12,
282,
3233,
12,
5423,
14,
339,
437,
9759,
883,
675,
7750,
12591,
334,
2416,
1062,
11271,
1062,
325,
6843,
342,
11965,
272,
10298,
641,
314,
4298,
14,
710,
849,
658,
11212,
64,
1021,
4440,
314,
4750,
272,
13402,
4514,
641,
314,
1453,
4298,
14,
272,
408,
339,
768,
10315,
272,
347,
2274,
8,
277,
12,
11099,
12,
4474,
12,
666,
29,
403,
304,
267,
408,
7099,
282,
570,
909,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
267,
4474,
221,
1553,
4474,
370,
8372,
334,
28831,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
9,
267,
666,
259,
1553,
10102,
666,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
1722,
340,
4474,
365,
3866,
267,
4067,
340,
11099,
365,
2575,
7264,
267,
6440,
340,
11099,
365,
6876,
503,
4257,
365,
625,
28751,
370,
355,
314,
8793,
2656,
1240,
334,
692,
282,
2656,
1240,
365,
6326,
9,
398,
3390,
26,
267,
6440,
1443,
503,
1443,
440,
506,
4915,
267,
408,
267,
746,
4279,
339,
768,
10315,
272,
347,
24369,
8,
277,
12,
11099,
304,
267,
408,
27419,
282,
570,
909,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
4067,
340,
11099,
365,
440,
7264,
398,
3390,
26,
267,
982,
11099,
365,
7264,
1325,
965,
3967,
2757,
6876,
642,
1630,
267,
627,
1397,
10,
746,
6440,
334,
12056,
340,
314,
8072,
18901,
1630,
9,
267,
408,
267,
746,
4279,
339,
347,
2811,
8,
277,
12,
11099,
12,
4474,
12,
666,
29,
403,
304,
267,
408,
4001,
282,
7264,
570,
909,
23821,
4474,
503,
10102,
666,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
267,
4474,
221,
1553,
4474,
370,
8372,
334,
28831,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
9,
267,
666,
259,
1553,
10102,
666,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
6184,
2127,
626,
24369,
342,
503,
2274,
342,
6534,
267,
408,
267,
291,
14,
18408,
8,
9234,
9,
267,
372,
291,
14,
2683,
8,
9234,
12,
4474,
12,
666,
9,
339,
768,
10315,
272,
347,
3504,
8,
277,
12,
2653,
29,
403,
304,
267,
408,
20906,
314,
3503,
7267,
12,
5133,
2005,
23821,
570,
2251,
787,
267,
10144,
503,
282,
2653,
12261,
14,
398,
3897,
26,
267,
2653,
1553,
340,
2653,
690,
378,
12,
642,
9314,
314,
5696,
3618,
900,
12,
315,
673,
4696,
673,
340,
2653,
2695,
378,
12,
314,
3504,
342,
1240,
7859,
1133,
1853,
12,
436,
911,
673,
3622,
314,
5544,
10144,
570,
2251,
673,
340,
2653,
365,
488,
12,
3504,
342,
911,
1853,
5133,
282,
23821,
673,
570,
909,
15410,
10144,
398,
1803,
26,
267,
769,
402,
334,
498,
12,
4474,
9,
367,
10144,
570,
2251,
267,
658,
4368,
64,
365,
282,
31927,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
267,
408,
267,
746,
4279,
339,
347,
4002,
8,
277,
304,
267,
408,
4724,
314,
9759,
14,
398,
961,
1471,
506,
2797,
370,
1852,
3238,
626,
1263,
8793,
2073,
365,
23694,
14,
267,
408,
267,
986,
339,
347,
664,
63,
498,
8,
277,
12,
11099,
304,
267,
408,
1767,
314,
790,
4568,
370,
282,
7264,
570
] |
[
11212,
83,
859,
14,
199,
199,
2765,
859,
6127,
4721,
13,
1896,
436,
13402,
473,
15,
47,
3663,
88,
316,
12,
6137,
12188,
314,
199,
64,
2416,
64,
859,
1979,
22337,
14,
199,
624,
421,
199,
504,
13022,
492,
29565,
12,
9006,
765,
199,
504,
5055,
492,
12863,
12,
12340,
199,
646,
3473,
199,
646,
3504,
199,
646,
984,
421,
199,
3,
7809,
4474,
12,
626,
1471,
506,
9994,
370,
4514,
13,
6100,
7869,
199,
8193,
63,
5670,
275,
334,
17,
5213,
378,
9,
199,
8193,
63,
10387,
275,
334,
17,
5213,
413,
9,
421,
199,
318,
485,
9234,
63,
475,
63,
2592,
8,
9234,
304,
272,
408,
1767,
282,
570,
5872,
687,
282,
570,
909,
14,
339,
3897,
26,
272,
11099,
1553,
570,
909,
503,
570,
5872,
339,
1803,
26,
272,
5226,
570,
5872,
339,
6218,
26,
272,
1722,
340,
314,
909,
365,
3866,
272,
408,
272,
340,
1228,
8,
9234,
12,
1109,
304,
267,
6111,
275,
11099,
272,
587,
26,
267,
862,
26,
288,
6111,
275,
1109,
8,
9234,
14,
9843,
1012,
267,
871,
334,
10227,
12,
3146,
12,
1722,
304,
288,
746,
1722,
480,
3364,
570,
909,
26,
298,
2490,
5310,
1,
82,
5469,
908,
8,
9234,
430,
687,
488,
272,
340,
6111,
665,
378,
26,
267,
746,
1722,
480,
3364,
570,
5872,
26,
8352,
908,
8,
2592,
430,
272,
372,
6111,
421,
199,
11212,
1197,
275,
12863,
360,
11212,
1197,
297,
788,
9234,
297,
283,
2592,
297,
283,
4368,
297,
283,
576,
1105,
199,
624,
1692,
1202,
370,
20133,
282,
570,
909,
370,
2399,
21094,
570,
5872,
12,
199,
5511,
1566,
3656,
436,
10102,
666,
1041,
421,
199,
533,
485,
11212,
7674,
8,
7674,
304,
272,
408,
7674,
402,
570,
2251,
370,
9759,
2883,
1041,
339,
347,
636,
826,
721,
277,
12,
9759,
304,
267,
291,
423,
6662,
275,
9759,
339,
347,
636,
552,
721,
277,
304,
267,
372,
822,
8,
277,
423,
6662,
423,
2592,
63,
475,
63,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
11099,
304,
267,
862,
26,
288,
6111,
275,
291,
423,
6662,
423,
9234,
63,
3892,
8,
9234,
9,
288,
372,
291,
423,
6662,
423,
2592,
63,
475,
63,
498,
59,
2592,
61,
267,
871,
4067,
26,
288,
746,
4067,
13076,
1,
82,
93,
365,
440,
7264,
1674,
908,
8,
9234,
430,
687,
488,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
2740,
8,
277,
423,
6662,
423,
2592,
63,
475,
63,
498,
9,
421,
199,
533,
3523,
11212,
8,
6577,
29,
22254,
304,
272,
408,
11212,
9006,
1300,
1021,
14,
339,
437,
9759,
5171,
2274,
316,
570,
2251,
370,
506,
23821,
367,
2488,
272,
473,
15,
47,
4474,
14,
339,
437,
570,
909,
365,
282,
570,
5872,
503,
1263,
909,
543,
282,
658,
9843,
11995,
1083,
14,
272,
1626,
9697,
909,
883,
506,
10102,
370,
314,
570,
909,
12,
1314,
883,
506,
1202,
272,
367,
2893,
370,
3877,
1067,
2556,
12,
282,
3233,
12,
5423,
14,
339,
437,
9759,
883,
675,
7750,
12591,
334,
2416,
1062,
11271,
1062,
325,
6843,
342,
11965,
272,
10298,
641,
314,
4298,
14,
710,
849,
658,
11212,
64,
1021,
4440,
314,
4750,
272,
13402,
4514,
641,
314,
1453,
4298,
14,
272,
408,
339,
768,
10315,
272,
347,
2274,
8,
277,
12,
11099,
12,
4474,
12,
666,
29,
403,
304,
267,
408,
7099,
282,
570,
909,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
267,
4474,
221,
1553,
4474,
370,
8372,
334,
28831,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
9,
267,
666,
259,
1553,
10102,
666,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
1722,
340,
4474,
365,
3866,
267,
4067,
340,
11099,
365,
2575,
7264,
267,
6440,
340,
11099,
365,
6876,
503,
4257,
365,
625,
28751,
370,
355,
314,
8793,
2656,
1240,
334,
692,
282,
2656,
1240,
365,
6326,
9,
398,
3390,
26,
267,
6440,
1443,
503,
1443,
440,
506,
4915,
267,
408,
267,
746,
4279,
339,
768,
10315,
272,
347,
24369,
8,
277,
12,
11099,
304,
267,
408,
27419,
282,
570,
909,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
4067,
340,
11099,
365,
440,
7264,
398,
3390,
26,
267,
982,
11099,
365,
7264,
1325,
965,
3967,
2757,
6876,
642,
1630,
267,
627,
1397,
10,
746,
6440,
334,
12056,
340,
314,
8072,
18901,
1630,
9,
267,
408,
267,
746,
4279,
339,
347,
2811,
8,
277,
12,
11099,
12,
4474,
12,
666,
29,
403,
304,
267,
408,
4001,
282,
7264,
570,
909,
23821,
4474,
503,
10102,
666,
14,
398,
3897,
26,
267,
11099,
1553,
570,
909,
503,
570,
5872,
267,
4474,
221,
1553,
4474,
370,
8372,
334,
28831,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
9,
267,
666,
259,
1553,
10102,
666,
398,
1803,
26,
267,
3240,
3283,
1197,
1256,
398,
6218,
26,
267,
6184,
2127,
626,
24369,
342,
503,
2274,
342,
6534,
267,
408,
267,
291,
14,
18408,
8,
9234,
9,
267,
372,
291,
14,
2683,
8,
9234,
12,
4474,
12,
666,
9,
339,
768,
10315,
272,
347,
3504,
8,
277,
12,
2653,
29,
403,
304,
267,
408,
20906,
314,
3503,
7267,
12,
5133,
2005,
23821,
570,
2251,
787,
267,
10144,
503,
282,
2653,
12261,
14,
398,
3897,
26,
267,
2653,
1553,
340,
2653,
690,
378,
12,
642,
9314,
314,
5696,
3618,
900,
12,
315,
673,
4696,
673,
340,
2653,
2695,
378,
12,
314,
3504,
342,
1240,
7859,
1133,
1853,
12,
436,
911,
673,
3622,
314,
5544,
10144,
570,
2251,
673,
340,
2653,
365,
488,
12,
3504,
342,
911,
1853,
5133,
282,
23821,
673,
570,
909,
15410,
10144,
398,
1803,
26,
267,
769,
402,
334,
498,
12,
4474,
9,
367,
10144,
570,
2251,
267,
658,
4368,
64,
365,
282,
31927,
3656,
402,
6461,
63,
5670,
92,
8193,
63,
10387,
267,
408,
267,
746,
4279,
339,
347,
4002,
8,
277,
304,
267,
408,
4724,
314,
9759,
14,
398,
961,
1471,
506,
2797,
370,
1852,
3238,
626,
1263,
8793,
2073,
365,
23694,
14,
267,
408,
267,
986,
339,
347,
664,
63,
498,
8,
277,
12,
11099,
304,
267,
408,
1767,
314,
790,
4568,
370,
282,
7264,
570,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tulsawebdevs/django-multi-gtfs
|
examples/explore/exploreapp/urls.py
|
1
|
5061
|
from django.conf.urls import url
from django.views.generic import DetailView, ListView
from multigtfs.models import (
Agency, Block, Fare, FareRule, Feed, FeedInfo, Route, Service, ServiceDate,
Shape, ShapePoint, Stop, StopTime, Trip, Zone)
from exploreapp.views import (
ByFeedListView, FareRuleByFareListView, FareRuleByRouteListView,
FrequencyByTripListView, ServiceDateByServiceListView,
ShapePointByShapeListView, StopTimeByStopListView, StopTimeByTripListView,
TripByBlockListView, TripByRouteListView, TripByServiceListView,
TripByShapeListView)
urlpatterns = [
url(r'feed/$', ListView.as_view(model=Feed), name='feed_list'),
url(r'feed/(?P<pk>\d+)/$', DetailView.as_view(model=Feed),
name='feed_detail'),
url(r'feed/(?P<feed_id>\d+)/agency/$',
ByFeedListView.as_view(model=Agency),
name='agency_list'),
url(r'feed/(?P<feed_id>\d+)/agency/(?P<pk>\d+)/$',
DetailView.as_view(model=Agency), name='agency_detail'),
url(r'feed/(?P<feed_id>\d+)/stop/$',
ByFeedListView.as_view(model=Stop),
name='stop_list'),
url(r'feed/(?P<feed_id>\d+)/stop/(?P<pk>\d+)/$',
DetailView.as_view(model=Stop), name='stop_detail'),
url(r'feed/(?P<feed_id>\d+)/stop/(?P<stop_id>\d+)/stoptime/$',
StopTimeByStopListView.as_view(), name='stoptime_by_stop_list'),
url(r'feed/(?P<feed_id>\d+)/stoptime/(?P<pk>\d+)/$',
DetailView.as_view(model=StopTime), name='stoptime_detail'),
url(r'feed/(?P<feed_id>\d+)/trip/(?P<pk>\d+)/$',
DetailView.as_view(model=Trip), name='trip_detail'),
url(r'feed/(?P<feed_id>\d+)/trip/(?P<trip_id>\d+)/frequency/$',
FrequencyByTripListView.as_view(), name='frequency_by_trip_list'),
url(r'feed/(?P<feed_id>\d+)/trip/(?P<trip_id>\d+)/stoptime/$',
StopTimeByTripListView.as_view(), name='stoptime_by_trip_list'),
url(r'feed/(?P<feed_id>\d+)/route/(?P<route_id>\d+)/farerule/$',
FareRuleByRouteListView.as_view(), name='farerule_by_route_list'),
url(r'feed/(?P<feed_id>\d+)/route/(?P<route_id>\d+)/trip/$',
TripByRouteListView.as_view(), name='trip_by_route_list'),
url(r'feed/(?P<feed_id>\d+)/route/$',
ByFeedListView.as_view(model=Route),
name='route_list'),
url(r'feed/(?P<feed_id>\d+)/route/(?P<pk>\d+)/$',
DetailView.as_view(model=Route), name='route_detail'),
url(r'feed/(?P<feed_id>\d+)/service/$',
ByFeedListView.as_view(model=Service),
name='service_list'),
url(r'feed/(?P<feed_id>\d+)/service/(?P<pk>\d+)/$',
DetailView.as_view(model=Service), name='service_detail'),
url(r'feed/(?P<feed_id>\d+)/service/(?P<service_id>\d+)/servicedate/$',
ServiceDateByServiceListView.as_view(),
name='servicedate_by_service_list'),
url(r'feed/(?P<feed_id>\d+)/service/(?P<service_id>\d+)/trip/$',
TripByServiceListView.as_view(), name='trip_by_service_list'),
url(r'feed/(?P<feed_id>\d+)/servicedate/(?P<pk>\d+)/$',
DetailView.as_view(model=ServiceDate), name='servicedate_detail'),
url(r'feed/(?P<feed_id>\d+)/shape/$',
ByFeedListView.as_view(model=Shape),
name='shape_list'),
url(r'feed/(?P<feed_id>\d+)/shape/(?P<pk>\d+)/$',
DetailView.as_view(model=Shape), name='shape_detail'),
url(r'feed/(?P<feed_id>\d+)/shape/(?P<shape_id>\d+)/shapepoint/$',
ShapePointByShapeListView.as_view(), name='shapepoint_by_shape_list'),
url(r'feed/(?P<feed_id>\d+)/shape/(?P<shape_id>\d+)/trip/$',
TripByShapeListView.as_view(), name='trip_by_shape_list'),
url(r'feed/(?P<feed_id>\d+)/shapepoint/(?P<pk>\d+)$',
DetailView.as_view(model=ShapePoint), name='shapepoint_detail'),
url(r'feed/(?P<feed_id>\d+)/fare/$',
ByFeedListView.as_view(model=Fare),
name='fare_list'),
url(r'feed/(?P<feed_id>\d+)/fare/(?P<pk>\d+)/$',
DetailView.as_view(model=Fare), name='fare_detail'),
url(r'feed/(?P<feed_id>\d+)/fare/(?P<fare_id>\d+)/farerule$',
FareRuleByFareListView.as_view(), name='farerule_by_fare_list'),
url(r'feed/(?P<feed_id>\d+)/farerule/(?P<pk>\d+)/$',
DetailView.as_view(model=FareRule), name='farerule_detail'),
url(r'feed/(?P<feed_id>\d+)/feedinfo/$',
ByFeedListView.as_view(model=FeedInfo),
name='feedinfo_list'),
url(r'feed/(?P<feed_id>\d+)/feedinfo/(?P<pk>\d+)/$',
DetailView.as_view(model=FeedInfo), name='feedinfo_detail'),
url(r'feed/(?P<feed_id>\d+)/zone/$',
ByFeedListView.as_view(model=Zone),
name='zone_list'),
url(r'feed/(?P<feed_id>\d+)/zone/(?P<pk>\d+)/$',
DetailView.as_view(model=Zone), name='zone_detail'),
url(r'feed/(?P<feed_id>\d+)/block/$',
ByFeedListView.as_view(model=Block),
name='block_list'),
url(r'feed/(?P<feed_id>\d+)/block/(?P<pk>\d+)/$',
DetailView.as_view(model=Block), name='block_detail'),
url(r'feed/(?P<feed_id>\d+)/block/(?P<block_id>\d+)/trip/$',
TripByBlockListView.as_view(), name='trip_by_block_list'),
]
|
apache-2.0
|
[
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
4196,
14,
6767,
492,
13302,
2768,
12,
3820,
2768,
199,
504,
3510,
3308,
2319,
14,
992,
492,
334,
272,
437,
27798,
12,
8651,
12,
481,
1530,
12,
481,
1530,
5065,
12,
16261,
12,
16261,
2354,
12,
24244,
12,
7591,
12,
7591,
2506,
12,
272,
16528,
12,
16528,
3428,
12,
8015,
12,
8015,
1366,
12,
12480,
80,
12,
22518,
9,
199,
199,
504,
15868,
264,
571,
14,
4196,
492,
334,
272,
4885,
7658,
23239,
12,
481,
1530,
5065,
2175,
38,
1530,
23239,
12,
481,
1530,
5065,
2175,
7161,
23239,
12,
272,
481,
6056,
2175,
32220,
23239,
12,
7591,
2506,
2175,
3167,
23239,
12,
272,
16528,
3428,
2175,
7238,
23239,
12,
8015,
1366,
2175,
6293,
23239,
12,
8015,
1366,
2175,
32220,
23239,
12,
272,
12480,
80,
2175,
3142,
23239,
12,
12480,
80,
2175,
7161,
23239,
12,
12480,
80,
2175,
3167,
23239,
12,
272,
12480,
80,
2175,
7238,
23239,
9,
421,
199,
20050,
275,
359,
272,
1166,
8,
82,
7,
3871,
10884,
3820,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7658,
395,
536,
534,
3871,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7658,
395,
267,
536,
534,
3871,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
643,
9501,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
33,
27798,
395,
267,
536,
534,
643,
9501,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
643,
9501,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
33,
27798,
395,
536,
534,
643,
9501,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
6293,
395,
267,
536,
534,
2379,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
6293,
395,
536,
534,
2379,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
9448,
48,
28,
2379,
63,
344,
3072,
68,
18830,
2379,
521,
10884,
267,
8015,
1366,
2175,
6293,
23239,
14,
305,
63,
1345,
1062,
536,
534,
2379,
521,
63,
991,
63,
2379,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
521,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
6293,
1366,
395,
536,
534,
2379,
521,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
32220,
395,
536,
534,
7254,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
7254,
63,
344,
3072,
68,
18830,
11132,
10884,
267,
481,
6056,
2175,
32220,
23239,
14,
305,
63,
1345,
1062,
536,
534,
11132,
63,
991,
63,
7254,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
7254,
63,
344,
3072,
68,
18830,
2379,
521,
10884,
267,
8015,
1366,
2175,
32220,
23239,
14,
305,
63,
1345,
1062,
536,
534,
2379,
521,
63,
991,
63,
7254,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
4449,
63,
344,
3072,
68,
18830,
667,
264,
2200,
10884,
267,
481,
1530,
5065,
2175,
7161,
23239,
14,
305,
63,
1345,
1062,
536,
534,
667,
264,
2200,
63,
991,
63,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
4449,
63,
344,
3072,
68,
18830,
7254,
10884,
267,
12480,
80,
2175,
7161,
23239,
14,
305,
63,
1345,
1062,
536,
534,
7254,
63,
991,
63,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
7161,
395,
267,
536,
534,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7161,
395,
536,
534,
4449,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
3167,
395,
267,
536,
534,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
3167,
395,
536,
534,
1364,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
1364,
63,
344,
3072,
68,
18830,
1364,
602,
10884,
267,
7591,
2506,
2175,
3167,
23239,
14,
305,
63,
1345,
1062,
267,
536,
534,
1364,
602,
63,
991,
63,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
1364,
63,
344,
3072,
68,
18830,
7254,
10884,
267,
12480,
80,
2175,
3167,
23239,
14,
305,
63,
1345,
1062,
536,
534,
7254,
63,
991,
63,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
602,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
3167,
2506,
395,
536,
534,
1364,
602,
63,
5506,
659,
272,
1166
] |
[
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
4196,
14,
6767,
492,
13302,
2768,
12,
3820,
2768,
199,
504,
3510,
3308,
2319,
14,
992,
492,
334,
272,
437,
27798,
12,
8651,
12,
481,
1530,
12,
481,
1530,
5065,
12,
16261,
12,
16261,
2354,
12,
24244,
12,
7591,
12,
7591,
2506,
12,
272,
16528,
12,
16528,
3428,
12,
8015,
12,
8015,
1366,
12,
12480,
80,
12,
22518,
9,
199,
199,
504,
15868,
264,
571,
14,
4196,
492,
334,
272,
4885,
7658,
23239,
12,
481,
1530,
5065,
2175,
38,
1530,
23239,
12,
481,
1530,
5065,
2175,
7161,
23239,
12,
272,
481,
6056,
2175,
32220,
23239,
12,
7591,
2506,
2175,
3167,
23239,
12,
272,
16528,
3428,
2175,
7238,
23239,
12,
8015,
1366,
2175,
6293,
23239,
12,
8015,
1366,
2175,
32220,
23239,
12,
272,
12480,
80,
2175,
3142,
23239,
12,
12480,
80,
2175,
7161,
23239,
12,
12480,
80,
2175,
3167,
23239,
12,
272,
12480,
80,
2175,
7238,
23239,
9,
421,
199,
20050,
275,
359,
272,
1166,
8,
82,
7,
3871,
10884,
3820,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7658,
395,
536,
534,
3871,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7658,
395,
267,
536,
534,
3871,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
643,
9501,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
33,
27798,
395,
267,
536,
534,
643,
9501,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
643,
9501,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
33,
27798,
395,
536,
534,
643,
9501,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
6293,
395,
267,
536,
534,
2379,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
6293,
395,
536,
534,
2379,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
9448,
48,
28,
2379,
63,
344,
3072,
68,
18830,
2379,
521,
10884,
267,
8015,
1366,
2175,
6293,
23239,
14,
305,
63,
1345,
1062,
536,
534,
2379,
521,
63,
991,
63,
2379,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
2379,
521,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
6293,
1366,
395,
536,
534,
2379,
521,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
32220,
395,
536,
534,
7254,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
7254,
63,
344,
3072,
68,
18830,
11132,
10884,
267,
481,
6056,
2175,
32220,
23239,
14,
305,
63,
1345,
1062,
536,
534,
11132,
63,
991,
63,
7254,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
7254,
9448,
48,
28,
7254,
63,
344,
3072,
68,
18830,
2379,
521,
10884,
267,
8015,
1366,
2175,
32220,
23239,
14,
305,
63,
1345,
1062,
536,
534,
2379,
521,
63,
991,
63,
7254,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
4449,
63,
344,
3072,
68,
18830,
667,
264,
2200,
10884,
267,
481,
1530,
5065,
2175,
7161,
23239,
14,
305,
63,
1345,
1062,
536,
534,
667,
264,
2200,
63,
991,
63,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
4449,
63,
344,
3072,
68,
18830,
7254,
10884,
267,
12480,
80,
2175,
7161,
23239,
14,
305,
63,
1345,
1062,
536,
534,
7254,
63,
991,
63,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
7161,
395,
267,
536,
534,
4449,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
4449,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
7161,
395,
536,
534,
4449,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
10884,
267,
4885,
7658,
23239,
14,
305,
63,
1345,
8,
1238,
29,
3167,
395,
267,
536,
534,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
3167,
395,
536,
534,
1364,
63,
5506,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
1364,
63,
344,
3072,
68,
18830,
1364,
602,
10884,
267,
7591,
2506,
2175,
3167,
23239,
14,
305,
63,
1345,
1062,
267,
536,
534,
1364,
602,
63,
991,
63,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
9448,
48,
28,
1364,
63,
344,
3072,
68,
18830,
7254,
10884,
267,
12480,
80,
2175,
3167,
23239,
14,
305,
63,
1345,
1062,
536,
534,
7254,
63,
991,
63,
1364,
63,
513,
659,
272,
1166,
8,
82,
7,
3871,
9448,
48,
28,
3871,
63,
344,
3072,
68,
18830,
1364,
602,
9448,
48,
28,
2051,
3072,
68,
18830,
4268,
267,
13302,
2768,
14,
305,
63,
1345,
8,
1238,
29,
3167,
2506,
395,
536,
534,
1364,
602,
63,
5506,
659,
272,
1166,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
spirrello/spirrello-pynet-work
|
applied_python/lib64/python2.7/site-packages/wrapt/wrappers.py
|
7
|
32340
|
import sys
import functools
import operator
import weakref
import inspect
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
else:
string_types = basestring,
def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
return meta("NewBase", bases, {})
class _ObjectProxyMethods(object):
# We use properties to override the values of __module__ and
# __doc__. If we add these in ObjectProxy, the derived class
# __dict__ will still be setup to have string variants of these
# attributes and the rules of descriptors means that they appear to
# take precedence over the properties in the base class. To avoid
# that, we copy the properties into the derived class type itself
# via a meta class. In that way the properties will always take
# precedence.
@property
def __module__(self):
return self.__wrapped__.__module__
@__module__.setter
def __module__(self, value):
self.__wrapped__.__module__ = value
@property
def __doc__(self):
return self.__wrapped__.__doc__
@__doc__.setter
def __doc__(self, value):
self.__wrapped__.__doc__ = value
# We similar use a property for __dict__. We need __dict__ to be
# explicit to ensure that vars() works as expected.
@property
def __dict__(self):
return self.__wrapped__.__dict__
# Need to also propagate the special __weakref__ attribute for case
# where decorating classes which will define this. If do not define
# it and use a function like inspect.getmembers() on a decorator
# class it will fail. This can't be in the derived classes.
@property
def __weakref__(self):
return self.__wrapped__.__weakref__
class _ObjectProxyMetaType(type):
def __new__(cls, name, bases, dictionary):
# Copy our special properties into the class so that they
# always take precedence over attributes of the same name added
# during construction of a derived class. This is to save
# duplicating the implementation for them in all derived classes.
dictionary.update(vars(_ObjectProxyMethods))
return type.__new__(cls, name, bases, dictionary)
class ObjectProxy(with_metaclass(_ObjectProxyMetaType)):
__slots__ = '__wrapped__'
def __init__(self, wrapped):
object.__setattr__(self, '__wrapped__', wrapped)
# Python 3.2+ has the __qualname__ attribute, but it does not
# allow it to be overridden using a property and it must instead
# be an actual string object instead.
try:
object.__setattr__(self, '__qualname__', wrapped.__qualname__)
except AttributeError:
pass
@property
def __name__(self):
return self.__wrapped__.__name__
@__name__.setter
def __name__(self, value):
self.__wrapped__.__name__ = value
@property
def __class__(self):
return self.__wrapped__.__class__
@__class__.setter
def __class__(self, value):
self.__wrapped__.__class__ = value
@property
def __annotations__(self):
return self.__wrapped__.__anotations__
@__annotations__.setter
def __annotations__(self, value):
self.__wrapped__.__annotations__ = value
def __dir__(self):
return dir(self.__wrapped__)
def __str__(self):
return str(self.__wrapped__)
if PY3:
def __bytes__(self):
return bytes(self.__wrapped__)
def __repr__(self):
return '<%s at 0x%x for %s at 0x%x>' % (
type(self).__name__, id(self),
type(self.__wrapped__).__name__,
id(self.__wrapped__))
def __reversed__(self):
return reversed(self.__wrapped__)
if PY3:
def __round__(self):
return round(self.__wrapped__)
def __lt__(self, other):
return self.__wrapped__ < other
def __le__(self, other):
return self.__wrapped__ <= other
def __eq__(self, other):
return self.__wrapped__ == other
def __ne__(self, other):
return self.__wrapped__ != other
def __gt__(self, other):
return self.__wrapped__ > other
def __ge__(self, other):
return self.__wrapped__ >= other
def __hash__(self):
return hash(self.__wrapped__)
def __nonzero__(self):
return bool(self.__wrapped__)
def __bool__(self):
return bool(self.__wrapped__)
def __setattr__(self, name, value):
if name.startswith('_self_'):
object.__setattr__(self, name, value)
elif name == '__wrapped__':
object.__setattr__(self, name, value)
try:
object.__delattr__(self, '__qualname__')
except AttributeError:
pass
try:
object.__setattr__(self, '__qualname__', value.__qualname__)
except AttributeError:
pass
elif name == '__qualname__':
setattr(self.__wrapped__, name, value)
object.__setattr__(self, name, value)
elif hasattr(type(self), name):
object.__setattr__(self, name, value)
else:
setattr(self.__wrapped__, name, value)
def __getattr__(self, name):
# If we are being to lookup '__wrapped__' then the
# '__init__()' method cannot have been called.
if name == '__wrapped__':
raise ValueError('wrapper has not been initialised')
return getattr(self.__wrapped__, name)
def __delattr__(self, name):
if name.startswith('_self_'):
object.__delattr__(self, name)
elif name == '__wrapped__':
raise TypeError('__wrapped__ must be an object')
elif name == '__qualname__':
object.__delattr__(self, name)
delattr(self.__wrapped__, name)
elif hasattr(type(self), name):
object.__delattr__(self, name)
else:
delattr(self.__wrapped__, name)
def __add__(self, other):
return self.__wrapped__ + other
def __sub__(self, other):
return self.__wrapped__ - other
def __mul__(self, other):
return self.__wrapped__ * other
def __div__(self, other):
return operator.div(self.__wrapped__, other)
def __truediv__(self, other):
return operator.truediv(self.__wrapped__, other)
def __floordiv__(self, other):
return self.__wrapped__ // other
def __mod__(self, other):
return self.__wrapped__ % other
def __divmod__(self, other):
return divmod(self.__wrapped__, other)
def __pow__(self, other, *args):
return pow(self.__wrapped__, other, *args)
def __lshift__(self, other):
return self.__wrapped__ << other
def __rshift__(self, other):
return self.__wrapped__ >> other
def __and__(self, other):
return self.__wrapped__ & other
def __xor__(self, other):
return self.__wrapped__ ^ other
def __or__(self, other):
return self.__wrapped__ | other
def __radd__(self, other):
return other + self.__wrapped__
def __rsub__(self, other):
return other - self.__wrapped__
def __rmul__(self, other):
return other * self.__wrapped__
def __rdiv__(self, other):
return operator.div(other, self.__wrapped__)
def __rtruediv__(self, other):
return operator.truediv(other, self.__wrapped__)
def __rfloordiv__(self, other):
return other // self.__wrapped__
def __rmod__(self, other):
return other % self.__wrapped__
def __rdivmod__(self, other):
return divmod(other, self.__wrapped__)
def __rpow__(self, other, *args):
return pow(other, self.__wrapped__, *args)
def __rlshift__(self, other):
return other << self.__wrapped__
def __rrshift__(self, other):
return other >> self.__wrapped__
def __rand__(self, other):
return other & self.__wrapped__
def __rxor__(self, other):
return other ^ self.__wrapped__
def __ror__(self, other):
return other | self.__wrapped__
def __iadd__(self, other):
self.__wrapped__ += other
return self
def __isub__(self, other):
self.__wrapped__ -= other
return self
def __imul__(self, other):
self.__wrapped__ *= other
return self
def __idiv__(self, other):
self.__wrapped__ = operator.idiv(self.__wrapped__, other)
return self
def __itruediv__(self, other):
self.__wrapped__ = operator.itruediv(self.__wrapped__, other)
return self
def __ifloordiv__(self, other):
self.__wrapped__ //= other
return self
def __imod__(self, other):
self.__wrapped__ %= other
return self
def __ipow__(self, other):
self.__wrapped__ **= other
return self
def __ilshift__(self, other):
self.__wrapped__ <<= other
return self
def __irshift__(self, other):
self.__wrapped__ >>= other
return self
def __iand__(self, other):
self.__wrapped__ &= other
return self
def __ixor__(self, other):
self.__wrapped__ ^= other
return self
def __ior__(self, other):
self.__wrapped__ |= other
return self
def __neg__(self):
return -self.__wrapped__
def __pos__(self):
return +self.__wrapped__
def __abs__(self):
return abs(self.__wrapped__)
def __invert__(self):
return ~self.__wrapped__
def __int__(self):
return int(self.__wrapped__)
def __long__(self):
return long(self.__wrapped__)
def __float__(self):
return float(self.__wrapped__)
def __oct__(self):
return oct(self.__wrapped__)
def __hex__(self):
return hex(self.__wrapped__)
def __index__(self):
return operator.index(self.__wrapped__)
def __len__(self):
return len(self.__wrapped__)
def __contains__(self, value):
return value in self.__wrapped__
def __getitem__(self, key):
return self.__wrapped__[key]
def __setitem__(self, key, value):
self.__wrapped__[key] = value
def __delitem__(self, key):
del self.__wrapped__[key]
def __getslice__(self, i, j):
return self.__wrapped__[i:j]
def __setslice__(self, i, j, value):
self.__wrapped__[i:j] = value
def __delslice__(self, i, j):
del self.__wrapped__[i:j]
def __enter__(self):
return self.__wrapped__.__enter__()
def __exit__(self, *args, **kwargs):
return self.__wrapped__.__exit__(*args, **kwargs)
def __iter__(self):
return iter(self.__wrapped__)
class CallableObjectProxy(ObjectProxy):
def __call__(self, *args, **kwargs):
return self.__wrapped__(*args, **kwargs)
class _FunctionWrapperBase(ObjectProxy):
__slots__ = ('_self_instance', '_self_wrapper', '_self_enabled',
'_self_binding', '_self_parent')
def __init__(self, wrapped, instance, wrapper, enabled=None,
binding='function', parent=None):
super(_FunctionWrapperBase, self).__init__(wrapped)
object.__setattr__(self, '_self_instance', instance)
object.__setattr__(self, '_self_wrapper', wrapper)
object.__setattr__(self, '_self_enabled', enabled)
object.__setattr__(self, '_self_binding', binding)
object.__setattr__(self, '_self_parent', parent)
def __get__(self, instance, owner):
# This method is actually doing double duty for both unbound and
# bound derived wrapper classes. It should possibly be broken up
# and the distinct functionality moved into the derived classes.
# Can't do that straight away due to some legacy code which is
# relying on it being here in this base class.
#
# The distinguishing attribute which determines whether we are
# being called in an unbound or bound wrapper is the parent
# attribute. If binding has never occured, then the parent will
# be None.
#
# First therefore, is if we are called in an unbound wrapper. In
# this case we perform the binding.
#
# We have one special case to worry about here. This is where we
# are decorating a nested class. In this case the wrapped class
# would not have a __get__() method to call. In that case we
# simply return self.
#
# Note that we otherwise still do binding even if instance is
# None and accessing an unbound instance method from a class.
# This is because we need to be able to later detect that
# specific case as we will need to extract the instance from the
# first argument of those passed in.
if self._self_parent is None:
if not inspect.isclass(self.__wrapped__):
descriptor = self.__wrapped__.__get__(instance, owner)
return self.__bound_function_wrapper__(descriptor, instance,
self._self_wrapper, self._self_enabled,
self._self_binding, self)
return self
# Now we have the case of binding occuring a second time on what
# was already a bound function. In this case we would usually
# return ourselves again. This mirrors what Python does.
#
# The special case this time is where we were originally bound
# with an instance of None and we were likely an instance
# method. In that case we rebind against the original wrapped
# function from the parent again.
if self._self_instance is None and self._self_binding == 'function':
descriptor = self._self_parent.__wrapped__.__get__(
instance, owner)
return self._self_parent.__bound_function_wrapper__(
descriptor, instance, self._self_wrapper,
self._self_enabled, self._self_binding,
self._self_parent)
return self
def __call__(self, *args, **kwargs):
# If enabled has been specified, then evaluate it at this point
# and if the wrapper is not to be executed, then simply return
# the bound function rather than a bound wrapper for the bound
# function. When evaluating enabled, if it is callable we call
# it, otherwise we evaluate it as a boolean.
if self._self_enabled is not None:
if callable(self._self_enabled):
if not self._self_enabled():
return self.__wrapped__(*args, **kwargs)
elif not self._self_enabled:
return self.__wrapped__(*args, **kwargs)
# This can occur where initial function wrapper was applied to
# a function that was already bound to an instance. In that case
# we want to extract the instance from the function and use it.
if self._self_binding == 'function':
if self._self_instance is None:
instance = getattr(self.__wrapped__, '__self__', None)
if instance is not None:
return self._self_wrapper(self.__wrapped__, instance,
args, kwargs)
# This is generally invoked when the wrapped function is being
# called as a normal function and is not bound to a class as an
# instance method. This is also invoked in the case where the
# wrapped function was a method, but this wrapper was in turn
# wrapped using the staticmethod decorator.
return self._self_wrapper(self.__wrapped__, self._self_instance,
args, kwargs)
class BoundFunctionWrapper(_FunctionWrapperBase):
def __call__(self, *args, **kwargs):
# If enabled has been specified, then evaluate it at this point
# and if the wrapper is not to be executed, then simply return
# the bound function rather than a bound wrapper for the bound
# function. When evaluating enabled, if it is callable we call
# it, otherwise we evaluate it as a boolean.
if self._self_enabled is not None:
if callable(self._self_enabled):
if not self._self_enabled():
return self.__wrapped__(*args, **kwargs)
elif not self._self_enabled:
return self.__wrapped__(*args, **kwargs)
# We need to do things different depending on whether we are
# likely wrapping an instance method vs a static method or class
# method.
if self._self_binding == 'function':
if self._self_instance is None:
# This situation can occur where someone is calling the
# instancemethod via the class type and passing the instance
# as the first argument. We need to shift the args before
# making the call to the wrapper and effectively bind the
# instance to the wrapped function using a partial so the
# wrapper doesn't see anything as being different.
if not args:
raise TypeError('missing 1 required positional argument')
instance, args = args[0], args[1:]
wrapped = functools.partial(self.__wrapped__, instance)
return self._self_wrapper(wrapped, instance, args, kwargs)
return self._self_wrapper(self.__wrapped__, self._self_instance,
args, kwargs)
else:
# As in this case we would be dealing with a classmethod or
# staticmethod, then _self_instance will only tell us whether
# when calling the classmethod or staticmethod they did it via an
# instance of the class it is bound to and not the case where
# done by the class type itself. We thus ignore _self_instance
# and use the __self__ attribute of the bound function instead.
# For a classmethod, this means instance will be the class type
# and for a staticmethod it will be None. This is probably the
# more useful thing we can pass through even though we loose
# knowledge of whether they were called on the instance vs the
# class type, as it reflects what they have available in the
# decoratored function.
instance = getattr(self.__wrapped__, '__self__', None)
return self._self_wrapper(self.__wrapped__, instance, args,
kwargs)
class FunctionWrapper(_FunctionWrapperBase):
__bound_function_wrapper__ = BoundFunctionWrapper
def __init__(self, wrapped, wrapper, enabled=None):
# What it is we are wrapping here could be anything. We need to
# try and detect specific cases though. In particular, we need
# to detect when we are given something that is a method of a
# class. Further, we need to know when it is likely an instance
# method, as opposed to a class or static method. This can
# become problematic though as there isn't strictly a fool proof
# method of knowing.
#
# The situations we could encounter when wrapping a method are:
#
# 1. The wrapper is being applied as part of a decorator which
# is a part of the class definition. In this case what we are
# given is the raw unbound function, classmethod or staticmethod
# wrapper objects.
#
# The problem here is that we will not know we are being applied
# in the context of the class being set up. This becomes
# important later for the case of an instance method, because in
# that case we just see it as a raw function and can't
# distinguish it from wrapping a normal function outside of
# a class context.
#
# 2. The wrapper is being applied when performing monkey
# patching of the class type afterwards and the method to be
# wrapped was retrieved direct from the __dict__ of the class
# type. This is effectively the same as (1) above.
#
# 3. The wrapper is being applied when performing monkey
# patching of the class type afterwards and the method to be
# wrapped was retrieved from the class type. In this case
# binding will have been performed where the instance against
# which the method is bound will be None at that point.
#
# This case is a problem because we can no longer tell if the
# method was a static method, plus if using Python3, we cannot
# tell if it was an instance method as the concept of an
# unnbound method no longer exists.
#
# 4. The wrapper is being applied when performing monkey
# patching of an instance of a class. In this case binding will
# have been perfomed where the instance was not None.
#
# This case is a problem because we can no longer tell if the
# method was a static method.
#
# Overall, the best we can do is look at the original type of the
# object which was wrapped prior to any binding being done and
# see if it is an instance of classmethod or staticmethod. In
# the case where other decorators are between us and them, if
# they do not propagate the __class__ attribute so that the
# isinstance() checks works, then likely this will do the wrong
# thing where classmethod and staticmethod are used.
#
# Since it is likely to be very rare that anyone even puts
# decorators around classmethod and staticmethod, likelihood of
# that being an issue is very small, so we accept it and suggest
# that those other decorators be fixed. It is also only an issue
# if a decorator wants to actually do things with the arguments.
#
# As to not being able to identify static methods properly, we
# just hope that that isn't something people are going to want
# to wrap, or if they do suggest they do it the correct way by
# ensuring that it is decorated in the class definition itself,
# or patch it in the __dict__ of the class type.
#
# So to get the best outcome we can, whenever we aren't sure what
# it is, we label it as a 'function'. If it was already bound and
# that is rebound later, we assume that it will be an instance
# method and try an cope with the possibility that the 'self'
# argument it being passed as an explicit argument and shuffle
# the arguments around to extract 'self' for use as the instance.
if isinstance(wrapped, classmethod):
binding = 'classmethod'
elif isinstance(wrapped, staticmethod):
binding = 'staticmethod'
elif hasattr(wrapped, '__self__'):
if inspect.isclass(wrapped.__self__):
binding = 'classmethod'
else:
binding = 'function'
else:
binding = 'function'
super(FunctionWrapper, self).__init__(wrapped, None, wrapper,
enabled, binding)
try:
from ._wrappers import (ObjectProxy, CallableObjectProxy, FunctionWrapper,
BoundFunctionWrapper, _FunctionWrapperBase)
except ImportError:
pass
# Helper functions for applying wrappers to existing functions.
def resolve_path(module, name):
if isinstance(module, string_types):
__import__(module)
module = sys.modules[module]
parent = module
path = name.split('.')
attribute = path[0]
original = getattr(parent, attribute)
for attribute in path[1:]:
parent = original
# We can't just always use getattr() because in doing
# that on a class it will cause binding to occur which
# will complicate things later and cause some things not
# to work. For the case of a class we therefore access
# the __dict__ directly. To cope though with the wrong
# class being given to us, or a method being moved into
# a base class, we need to walk the class heirarchy to
# work out exactly which __dict__ the method was defined
# in, as accessing it from __dict__ will fail if it was
# not actually on the class given. Fallback to using
# getattr() if we can't find it. If it truly doesn't
# exist, then that will fail.
if inspect.isclass(original):
for cls in inspect.getmro(original):
if attribute in vars(original):
original = vars(original)[attribute]
break
else:
original = getattr(original, attribute)
else:
original = getattr(original, attribute)
return (parent, attribute, original)
def apply_patch(parent, attribute, replacement):
setattr(parent, attribute, replacement)
def wrap_object(module, name, factory, args=(), kwargs={}):
(parent, attribute, original) = resolve_path(module, name)
wrapper = factory(original, *args, **kwargs)
apply_patch(parent, attribute, wrapper)
return wrapper
# Function for applying a proxy object to an attribute of a class
# instance. The wrapper works by defining an attribute of the same name
# on the class which is a descriptor and which intercepts access to the
# instance attribute. Note that this cannot be used on attributes which
# are themselves defined by a property object.
class AttributeWrapper(object):
def __init__(self, attribute, factory, args, kwargs):
self.attribute = attribute
self.factory = factory
self.args = args
self.kwargs = kwargs
def __get__(self, instance, owner):
value = instance.__dict__[self.attribute]
return self.factory(value, *self.args, **self.kwargs)
def __set__(self, instance, value):
instance.__dict__[self.attribute] = value
def __delete__(self, instance):
del instance.__dict__[self.attribute]
def wrap_object_attribute(module, name, factory, args=(), kwargs={}):
path, attribute = name.rsplit('.', 1)
parent = resolve_path(module, path)[2]
wrapper = AttributeWrapper(attribute, factory, args, kwargs)
apply_patch(parent, attribute, wrapper)
return wrapper
# Functions for creating a simple decorator using a FunctionWrapper,
# plus short cut functions for applying wrappers to functions. These are
# for use when doing monkey patching. For a more featured way of
# creating decorators see the decorator decorator instead.
def function_wrapper(wrapper):
def _wrapper(wrapped, instance, args, kwargs):
target_wrapped = args[0]
if instance is None:
target_wrapper = wrapper
elif inspect.isclass(instance):
target_wrapper = wrapper.__get__(None, instance)
else:
target_wrapper = wrapper.__get__(instance, type(instance))
return FunctionWrapper(target_wrapped, target_wrapper)
return FunctionWrapper(wrapper, _wrapper)
def wrap_function_wrapper(module, name, wrapper):
return wrap_object(module, name, FunctionWrapper, (wrapper,))
def patch_function_wrapper(module, name):
def _wrapper(wrapper):
return wrap_object(module, name, FunctionWrapper, (wrapper,))
return _wrapper
def transient_function_wrapper(module, name):
def _decorator(wrapper):
def _wrapper(wrapped, instance, args, kwargs):
target_wrapped = args[0]
if instance is None:
target_wrapper = wrapper
elif inspect.isclass(instance):
target_wrapper = wrapper.__get__(None, instance)
else:
target_wrapper = wrapper.__get__(instance, type(instance))
def _execute(wrapped, instance, args, kwargs):
(parent, attribute, original) = resolve_path(module, name)
replacement = FunctionWrapper(original, target_wrapper)
setattr(parent, attribute, replacement)
try:
return wrapped(*args, **kwargs)
finally:
setattr(parent, attribute, original)
return FunctionWrapper(target_wrapped, _execute)
return FunctionWrapper(wrapper, _wrapper)
return _decorator
# A weak function proxy. This will work on instance methods, class
# methods, static methods and regular functions. Special treatment is
# needed for the method types because the bound method is effectively a
# transient object and applying a weak reference to one will immediately
# result in it being destroyed and the weakref callback called. The weak
# reference is therefore applied to the instance the method is bound to
# and the original function. The function is then rebound at the point
# of a call via the weak function proxy.
def _weak_function_proxy_callback(ref, proxy, callback):
if proxy._self_expired:
return
proxy._self_expired = True
# This could raise an exception. We let it propagate back and let
# the weakref.proxy() deal with it, at which point it generally
# prints out a short error message direct to stderr and keeps going.
if callback is not None:
callback(proxy)
class WeakFunctionProxy(ObjectProxy):
__slots__ = ('_self_expired', '_self_instance')
def __init__(self, wrapped, callback=None):
# We need to determine if the wrapped function is actually a
# bound method. In the case of a bound method, we need to keep a
# reference to the original unbound function and the instance.
# This is necessary because if we hold a reference to the bound
# function, it will be the only reference and given it is a
# temporary object, it will almost immediately expire and
# the weakref callback triggered. So what is done is that we
# hold a reference to the instance and unbound function and
# when called bind the function to the instance once again and
# then call it. Note that we avoid using a nested function for
# the callback here so as not to cause any odd reference cycles.
_callback = callback and functools.partial(
_weak_function_proxy_callback, proxy=self,
callback=callback)
self._self_expired = False
if isinstance(wrapped, _FunctionWrapperBase):
self._self_instance = weakref.ref(wrapped._self_instance,
_callback)
if wrapped._self_parent is not None:
super(WeakFunctionProxy, self).__init__(
weakref.proxy(wrapped._self_parent, _callback))
else:
super(WeakFunctionProxy, self).__init__(
weakref.proxy(wrapped, _callback))
return
try:
self._self_instance = weakref.ref(wrapped.__self__, _callback)
super(WeakFunctionProxy, self).__init__(
weakref.proxy(wrapped.__func__, _callback))
except AttributeError:
self._self_instance = None
super(WeakFunctionProxy, self).__init__(
weakref.proxy(wrapped, _callback))
def __call__(self, *args, **kwargs):
# We perform a boolean check here on the instance and wrapped
# function as that will trigger the reference error prior to
# calling if the reference had expired.
instance = self._self_instance and self._self_instance()
function = self.__wrapped__ and self.__wrapped__
# If the wrapped function was originally a bound function, for
# which we retained a reference to the instance and the unbound
# function we need to rebind the function and then call it. If
# not just called the wrapped function.
if instance is None:
return self.__wrapped__(*args, **kwargs)
return function.__get__(instance, type(instance))(*args, **kwargs)
|
gpl-3.0
|
[
646,
984,
199,
646,
9143,
199,
646,
4182,
199,
646,
13852,
199,
646,
6485,
199,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
199,
199,
318,
543,
63,
6577,
8,
2024,
12,
627,
12087,
304,
272,
408,
2499,
282,
1300,
1021,
543,
282,
17074,
1041,
272,
372,
3404,
480,
4665,
1563,
401,
9768,
12,
5009,
199,
199,
533,
485,
1692,
4936,
10385,
8,
785,
304,
10813,
327,
2136,
675,
4382,
370,
4278,
314,
1338,
402,
636,
578,
363,
436,
1362,
327,
636,
1301,
4343,
982,
781,
1050,
3520,
315,
6935,
4936,
12,
314,
7131,
1021,
1362,
327,
636,
807,
363,
911,
5139,
506,
3272,
370,
1172,
1059,
21169,
402,
3520,
1362,
327,
3004,
436,
314,
4713,
402,
15428,
4910,
626,
2985,
7468,
370,
1362,
327,
5452,
13823,
1806,
314,
4382,
315,
314,
1300,
1021,
14,
4005,
5126,
1362,
327,
626,
12,
781,
1331,
314,
4382,
1901,
314,
7131,
1021,
730,
6337,
1362,
327,
4799,
282,
3404,
1021,
14,
1010,
626,
4340,
314,
4382,
911,
3544,
5452,
1362,
327,
13823,
14,
339,
768,
1829,
272,
347,
636,
578,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
578,
363,
339,
768,
363,
578,
4343,
8345,
272,
347,
636,
578,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
578,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
1301,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
1301,
363,
339,
768,
363,
1301,
4343,
8345,
272,
347,
636,
1301,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
1301,
363,
275,
574,
339,
327,
2136,
8545,
675,
282,
3324,
367,
636,
807,
4343,
2136,
1929,
636,
807,
363,
370,
506,
272,
327,
5027,
370,
4868,
626,
6802,
342,
5419,
465,
1420,
14,
339,
768,
1829,
272,
347,
636,
807,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
807,
363,
339,
327,
14012,
370,
2597,
19843,
314,
4539,
636,
21330,
363,
2225,
367,
1930,
272,
327,
2382,
5509,
1958,
3992,
1314,
911,
5627,
642,
14,
982,
886,
440,
5627,
272,
327,
652,
436,
675,
282,
805,
2839,
6485,
14,
28719,
342,
641,
282,
7531,
272,
327,
1021,
652,
911,
2449,
14,
961,
883,
1133,
506,
315,
314,
7131,
3992,
14,
339,
768,
1829,
272,
347,
636,
21330,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
21330,
363,
199,
199,
533,
485,
1692,
4936,
3396,
804,
8,
466,
304,
1362,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
268,
327,
11247,
4154,
4539,
4382,
1901,
314,
1021,
880,
626,
2985,
268,
327,
3544,
5452,
13823,
1806,
3004,
402,
314,
2011,
536,
3483,
268,
327,
5309,
14538,
402,
282,
7131,
1021,
14,
961,
365,
370,
3354,
268,
327,
366,
4230,
1958,
314,
4514,
367,
3062,
315,
1006,
7131,
3992,
14,
13359,
2600,
14,
873,
8,
2936,
1547,
1692,
4936,
10385,
430,
13359,
372,
730,
855,
1222,
721,
1886,
12,
536,
12,
9768,
12,
2600,
9,
199,
199,
533,
6935,
4936,
8,
1045,
63,
6577,
1547,
1692,
4936,
3396,
804,
2298,
339,
636,
7257,
363,
275,
2560,
9130,
12217,
339,
347,
636,
826,
721,
277,
12,
8072,
304,
267,
909,
855,
10202,
721,
277,
12,
2560,
9130,
7500,
8072,
9,
398,
327,
2018,
650,
14,
18,
11,
965,
314,
636,
537,
354,
363,
2225,
12,
1325,
652,
1630,
440,
267,
327,
2040,
652,
370,
506,
10087,
1808,
282,
3324,
436,
652,
1471,
3140,
267,
327,
506,
376,
3503,
1059,
909,
3140,
14,
398,
862,
26,
288,
909,
855,
10202,
721,
277,
12,
2560,
537,
354,
7500,
8072,
855,
537,
354,
3368,
267,
871,
4281,
26,
288,
986,
339,
768,
1829,
272,
347,
636,
354,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
354,
363,
339,
768,
363,
354,
4343,
8345,
272,
347,
636,
354,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
354,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
533,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
533,
363,
339,
768,
363,
533,
4343,
8345,
272,
347,
636,
533,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
533,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
11270,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
290,
357,
1298,
363,
339,
768,
363,
11270,
4343,
8345,
272,
347,
636,
11270,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
11270,
363,
275,
574,
339,
347,
636,
694,
721,
277,
304,
267,
372,
2935,
8,
277,
855,
9130,
3368,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
855,
9130,
3368,
339,
340,
7843,
19,
26,
267,
347,
636,
2394,
721,
277,
304,
288,
372,
2783,
8,
277,
855,
9130,
3368,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
737,
378,
88,
5,
88,
367,
450,
83,
737,
378,
88,
5,
88,
3524,
450,
334,
355,
730,
8,
277,
2843,
354,
3108,
1305,
8,
277,
395,
355,
730,
8,
277,
855,
9130,
363,
2843,
354,
3108,
355,
1305,
8,
277,
855,
9130,
8964,
339,
347,
636,
13501,
721,
277,
304,
267,
372,
10822,
8,
277,
855,
9130,
3368,
339,
340,
7843,
19,
26,
267,
347,
636,
2363,
721,
277,
304,
288,
372,
6168,
8,
277,
855,
9130,
3368,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
665,
1163,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
2695,
1163,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
508,
1163,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
1137,
1163,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
690,
1163,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
2356,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
855,
9130,
3368,
339,
347,
636,
10262,
721
] |
[
984,
199,
646,
9143,
199,
646,
4182,
199,
646,
13852,
199,
646,
6485,
199,
199,
4521,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
199,
4521,
19,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
650,
199,
199,
692,
7843,
19,
26,
272,
1059,
63,
1313,
275,
620,
12,
199,
2836,
26,
272,
1059,
63,
1313,
275,
7116,
12,
199,
199,
318,
543,
63,
6577,
8,
2024,
12,
627,
12087,
304,
272,
408,
2499,
282,
1300,
1021,
543,
282,
17074,
1041,
272,
372,
3404,
480,
4665,
1563,
401,
9768,
12,
5009,
199,
199,
533,
485,
1692,
4936,
10385,
8,
785,
304,
10813,
327,
2136,
675,
4382,
370,
4278,
314,
1338,
402,
636,
578,
363,
436,
1362,
327,
636,
1301,
4343,
982,
781,
1050,
3520,
315,
6935,
4936,
12,
314,
7131,
1021,
1362,
327,
636,
807,
363,
911,
5139,
506,
3272,
370,
1172,
1059,
21169,
402,
3520,
1362,
327,
3004,
436,
314,
4713,
402,
15428,
4910,
626,
2985,
7468,
370,
1362,
327,
5452,
13823,
1806,
314,
4382,
315,
314,
1300,
1021,
14,
4005,
5126,
1362,
327,
626,
12,
781,
1331,
314,
4382,
1901,
314,
7131,
1021,
730,
6337,
1362,
327,
4799,
282,
3404,
1021,
14,
1010,
626,
4340,
314,
4382,
911,
3544,
5452,
1362,
327,
13823,
14,
339,
768,
1829,
272,
347,
636,
578,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
578,
363,
339,
768,
363,
578,
4343,
8345,
272,
347,
636,
578,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
578,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
1301,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
1301,
363,
339,
768,
363,
1301,
4343,
8345,
272,
347,
636,
1301,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
1301,
363,
275,
574,
339,
327,
2136,
8545,
675,
282,
3324,
367,
636,
807,
4343,
2136,
1929,
636,
807,
363,
370,
506,
272,
327,
5027,
370,
4868,
626,
6802,
342,
5419,
465,
1420,
14,
339,
768,
1829,
272,
347,
636,
807,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
807,
363,
339,
327,
14012,
370,
2597,
19843,
314,
4539,
636,
21330,
363,
2225,
367,
1930,
272,
327,
2382,
5509,
1958,
3992,
1314,
911,
5627,
642,
14,
982,
886,
440,
5627,
272,
327,
652,
436,
675,
282,
805,
2839,
6485,
14,
28719,
342,
641,
282,
7531,
272,
327,
1021,
652,
911,
2449,
14,
961,
883,
1133,
506,
315,
314,
7131,
3992,
14,
339,
768,
1829,
272,
347,
636,
21330,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
21330,
363,
199,
199,
533,
485,
1692,
4936,
3396,
804,
8,
466,
304,
1362,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
2600,
304,
268,
327,
11247,
4154,
4539,
4382,
1901,
314,
1021,
880,
626,
2985,
268,
327,
3544,
5452,
13823,
1806,
3004,
402,
314,
2011,
536,
3483,
268,
327,
5309,
14538,
402,
282,
7131,
1021,
14,
961,
365,
370,
3354,
268,
327,
366,
4230,
1958,
314,
4514,
367,
3062,
315,
1006,
7131,
3992,
14,
13359,
2600,
14,
873,
8,
2936,
1547,
1692,
4936,
10385,
430,
13359,
372,
730,
855,
1222,
721,
1886,
12,
536,
12,
9768,
12,
2600,
9,
199,
199,
533,
6935,
4936,
8,
1045,
63,
6577,
1547,
1692,
4936,
3396,
804,
2298,
339,
636,
7257,
363,
275,
2560,
9130,
12217,
339,
347,
636,
826,
721,
277,
12,
8072,
304,
267,
909,
855,
10202,
721,
277,
12,
2560,
9130,
7500,
8072,
9,
398,
327,
2018,
650,
14,
18,
11,
965,
314,
636,
537,
354,
363,
2225,
12,
1325,
652,
1630,
440,
267,
327,
2040,
652,
370,
506,
10087,
1808,
282,
3324,
436,
652,
1471,
3140,
267,
327,
506,
376,
3503,
1059,
909,
3140,
14,
398,
862,
26,
288,
909,
855,
10202,
721,
277,
12,
2560,
537,
354,
7500,
8072,
855,
537,
354,
3368,
267,
871,
4281,
26,
288,
986,
339,
768,
1829,
272,
347,
636,
354,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
354,
363,
339,
768,
363,
354,
4343,
8345,
272,
347,
636,
354,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
354,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
533,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
533,
363,
339,
768,
363,
533,
4343,
8345,
272,
347,
636,
533,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
533,
363,
275,
574,
339,
768,
1829,
272,
347,
636,
11270,
721,
277,
304,
267,
372,
291,
855,
9130,
4914,
290,
357,
1298,
363,
339,
768,
363,
11270,
4343,
8345,
272,
347,
636,
11270,
721,
277,
12,
574,
304,
267,
291,
855,
9130,
4914,
11270,
363,
275,
574,
339,
347,
636,
694,
721,
277,
304,
267,
372,
2935,
8,
277,
855,
9130,
3368,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
855,
9130,
3368,
339,
340,
7843,
19,
26,
267,
347,
636,
2394,
721,
277,
304,
288,
372,
2783,
8,
277,
855,
9130,
3368,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
737,
378,
88,
5,
88,
367,
450,
83,
737,
378,
88,
5,
88,
3524,
450,
334,
355,
730,
8,
277,
2843,
354,
3108,
1305,
8,
277,
395,
355,
730,
8,
277,
855,
9130,
363,
2843,
354,
3108,
355,
1305,
8,
277,
855,
9130,
8964,
339,
347,
636,
13501,
721,
277,
304,
267,
372,
10822,
8,
277,
855,
9130,
3368,
339,
340,
7843,
19,
26,
267,
347,
636,
2363,
721,
277,
304,
288,
372,
6168,
8,
277,
855,
9130,
3368,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
665,
1163,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
2695,
1163,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
508,
1163,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
1137,
1163,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
690,
1163,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
291,
855,
9130,
363,
2356,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
855,
9130,
3368,
339,
347,
636,
10262,
721,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PaulWay/insights-core
|
insights/parsers/tests/test_tuned.py
|
1
|
2414
|
import unittest
from insights.parsers.tuned import Tuned
from insights.tests import context_wrap
TUNED_OUTPUT = '''
Available profiles:
- balanced
- desktop
- latency-performance
- network-latency
- network-throughput
- powersave
- throughput-performance
- virtual-guest
- virtual-host
Current active profile: virtual-guest
'''.strip()
TUNED_OUTPUT2 = '''
Available profiles:
- balanced
- desktop
- latency-performance
- network-latency
- network-throughput
- powersave
- throughput-performance
- virtual-guest
- virtual-host
It seems that tuned daemon is not running, preset profile is not activated.
Preset profile: virtual-guest
'''.strip()
class CheckTuned(unittest.TestCase):
def test_active_profile(self):
tuned_output = Tuned(context_wrap(TUNED_OUTPUT))
assert len(tuned_output.data.get('available')) == 9
assert tuned_output.data.get('active') == 'virtual-guest'
assert tuned_output.data.get('available') == ['balanced',
'desktop',
'latency-performance',
'network-latency',
'network-throughput',
'powersave',
'throughput-performance',
'virtual-guest',
'virtual-host']
def test_preset_profile(self):
tuned_output = Tuned(context_wrap(TUNED_OUTPUT2))
assert len(tuned_output.data.get('available')) == 9
assert tuned_output.data.get('preset') == 'virtual-guest'
assert tuned_output.data.get('available') == ['balanced',
'desktop',
'latency-performance',
'network-latency',
'network-throughput',
'powersave',
'throughput-performance',
'virtual-guest',
'virtual-host']
|
apache-2.0
|
[
646,
2882,
199,
504,
315,
22727,
83,
14,
11531,
14,
10032,
379,
492,
377,
324,
379,
199,
504,
315,
22727,
83,
14,
2219,
492,
1067,
63,
3823,
199,
199,
52,
1734,
1149,
63,
8414,
275,
1449,
199,
11464,
17390,
26,
199,
13,
14094,
68,
199,
13,
19763,
199,
13,
23967,
13,
20576,
199,
13,
2784,
13,
19645,
199,
13,
2784,
13,
8304,
524,
199,
13,
13131,
1192,
811,
199,
13,
4012,
524,
13,
20576,
199,
13,
5791,
13,
10409,
199,
13,
5791,
13,
1102,
199,
5639,
4702,
4690,
26,
5791,
13,
10409,
199,
891,
1370,
1913,
342,
199,
199,
52,
1734,
1149,
63,
8414,
18,
275,
1449,
199,
11464,
17390,
26,
199,
13,
14094,
68,
199,
13,
19763,
199,
13,
23967,
13,
20576,
199,
13,
2784,
13,
19645,
199,
13,
2784,
13,
8304,
524,
199,
13,
13131,
1192,
811,
199,
13,
4012,
524,
13,
20576,
199,
13,
5791,
13,
10409,
199,
13,
5791,
13,
1102,
199,
7940,
12237,
626,
15486,
379,
11128,
365,
440,
3879,
12,
876,
409,
4690,
365,
440,
22225,
14,
199,
2398,
409,
4690,
26,
5791,
13,
10409,
199,
891,
1370,
1913,
342,
421,
199,
533,
2670,
22664,
379,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2682,
63,
2913,
8,
277,
304,
267,
15486,
379,
63,
1199,
275,
377,
324,
379,
8,
1100,
63,
3823,
8,
52,
1734,
1149,
63,
8414,
430,
267,
702,
822,
8,
10032,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
1333,
508,
1749,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
2682,
358,
508,
283,
2065,
13,
10409,
7,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
358,
508,
788,
18923,
297,
10028,
283,
14487,
297,
10028,
283,
19645,
13,
20576,
297,
10028,
283,
1200,
13,
19645,
297,
10028,
283,
1200,
13,
8304,
524,
297,
10028,
283,
8278,
1192,
811,
297,
10028,
283,
8304,
524,
13,
20576,
297,
10028,
283,
2065,
13,
10409,
297,
10028,
283,
2065,
13,
1102,
418,
339,
347,
511,
63,
25701,
63,
2913,
8,
277,
304,
267,
15486,
379,
63,
1199,
275,
377,
324,
379,
8,
1100,
63,
3823,
8,
52,
1734,
1149,
63,
8414,
18,
430,
267,
702,
822,
8,
10032,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
1333,
508,
1749,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
25701,
358,
508,
283,
2065,
13,
10409,
7,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
358,
508,
788,
18923,
297,
10028,
283,
14487,
297,
10028,
283,
19645,
13,
20576,
297,
10028,
283,
1200,
13,
19645,
297,
10028,
283,
1200,
13,
8304,
524,
297,
10028,
283,
8278,
1192,
811,
297,
10028,
283,
8304,
524,
13,
20576,
297,
10028,
283,
2065,
13,
10409,
297,
10028,
283,
2065,
13,
1102,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
504,
315,
22727,
83,
14,
11531,
14,
10032,
379,
492,
377,
324,
379,
199,
504,
315,
22727,
83,
14,
2219,
492,
1067,
63,
3823,
199,
199,
52,
1734,
1149,
63,
8414,
275,
1449,
199,
11464,
17390,
26,
199,
13,
14094,
68,
199,
13,
19763,
199,
13,
23967,
13,
20576,
199,
13,
2784,
13,
19645,
199,
13,
2784,
13,
8304,
524,
199,
13,
13131,
1192,
811,
199,
13,
4012,
524,
13,
20576,
199,
13,
5791,
13,
10409,
199,
13,
5791,
13,
1102,
199,
5639,
4702,
4690,
26,
5791,
13,
10409,
199,
891,
1370,
1913,
342,
199,
199,
52,
1734,
1149,
63,
8414,
18,
275,
1449,
199,
11464,
17390,
26,
199,
13,
14094,
68,
199,
13,
19763,
199,
13,
23967,
13,
20576,
199,
13,
2784,
13,
19645,
199,
13,
2784,
13,
8304,
524,
199,
13,
13131,
1192,
811,
199,
13,
4012,
524,
13,
20576,
199,
13,
5791,
13,
10409,
199,
13,
5791,
13,
1102,
199,
7940,
12237,
626,
15486,
379,
11128,
365,
440,
3879,
12,
876,
409,
4690,
365,
440,
22225,
14,
199,
2398,
409,
4690,
26,
5791,
13,
10409,
199,
891,
1370,
1913,
342,
421,
199,
533,
2670,
22664,
379,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
2682,
63,
2913,
8,
277,
304,
267,
15486,
379,
63,
1199,
275,
377,
324,
379,
8,
1100,
63,
3823,
8,
52,
1734,
1149,
63,
8414,
430,
267,
702,
822,
8,
10032,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
1333,
508,
1749,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
2682,
358,
508,
283,
2065,
13,
10409,
7,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
358,
508,
788,
18923,
297,
10028,
283,
14487,
297,
10028,
283,
19645,
13,
20576,
297,
10028,
283,
1200,
13,
19645,
297,
10028,
283,
1200,
13,
8304,
524,
297,
10028,
283,
8278,
1192,
811,
297,
10028,
283,
8304,
524,
13,
20576,
297,
10028,
283,
2065,
13,
10409,
297,
10028,
283,
2065,
13,
1102,
418,
339,
347,
511,
63,
25701,
63,
2913,
8,
277,
304,
267,
15486,
379,
63,
1199,
275,
377,
324,
379,
8,
1100,
63,
3823,
8,
52,
1734,
1149,
63,
8414,
18,
430,
267,
702,
822,
8,
10032,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
1333,
508,
1749,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
25701,
358,
508,
283,
2065,
13,
10409,
7,
267,
702,
15486,
379,
63,
1199,
14,
576,
14,
362,
360,
4561,
358,
508,
788,
18923,
297,
10028,
283,
14487,
297,
10028,
283,
19645,
13,
20576,
297,
10028,
283,
1200,
13,
19645,
297,
10028,
283,
1200,
13,
8304,
524,
297,
10028,
283,
8278,
1192,
811,
297,
10028,
283,
8304,
524,
13,
20576,
297,
10028,
283,
2065,
13,
10409,
297,
10028,
283,
2065,
13,
1102,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ajestu/python.training
|
model/contact.py
|
1
|
1179
|
from sys import maxsize
class Contact:
def __init__(self, firstname= None, lastname= None, id= None,
homephone= None, mobilephone= None, workphone= None, secondphone= None , all_phones_from_homepage=None,
address=None, email=None, email2=None, email3=None, all_emails=None):
self.firstname = firstname
self.lastname = lastname
self.homephone = homephone
self.workphone = workphone
self.mobilephone = mobilephone
self.secondphone = secondphone
self.all_phones_from_homepage = all_phones_from_homepage
self.address=address
self.email=email
self.email2=email2
self.email3=email3
self.id = id
self.all_emails=all_emails
def __repr__ (self):
return "%s : %s : %s"%(self.id, self.firstname ,self.lastname)
def __eq__(self, other):
return (self.id is None or other.id is None or self.id == other.id) and self.firstname == other.firstname \
and self.lastname==other.lastname
def id_or_max(self):
if self.id:
return int(self.id)
else:
return maxsize
|
apache-2.0
|
[
504,
984,
492,
19791,
421,
199,
533,
18684,
26,
272,
347,
636,
826,
721,
277,
12,
1642,
354,
29,
488,
12,
2061,
354,
29,
488,
12,
1305,
29,
488,
12,
326,
5629,
9339,
29,
488,
12,
221,
21305,
9339,
29,
488,
12,
1736,
9339,
29,
488,
12,
3499,
9339,
29,
488,
2360,
1006,
63,
838,
4548,
63,
504,
63,
25539,
29,
403,
12,
326,
2287,
29,
403,
12,
3031,
29,
403,
12,
3031,
18,
29,
403,
12,
3031,
19,
29,
403,
12,
1006,
63,
14170,
29,
403,
304,
267,
291,
14,
25603,
275,
1642,
354,
267,
291,
14,
31164,
275,
2061,
354,
267,
291,
14,
4219,
9339,
275,
5629,
9339,
267,
291,
14,
800,
9339,
275,
1736,
9339,
267,
291,
14,
11375,
9339,
275,
21305,
9339,
267,
291,
14,
4375,
9339,
275,
3499,
9339,
267,
291,
14,
452,
63,
838,
4548,
63,
504,
63,
25539,
275,
1006,
63,
838,
4548,
63,
504,
63,
25539,
267,
291,
14,
1562,
29,
1562,
267,
291,
14,
2123,
29,
2123,
267,
291,
14,
2123,
18,
29,
2123,
18,
267,
291,
14,
2123,
19,
29,
2123,
19,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
452,
63,
14170,
29,
452,
63,
14170,
339,
347,
636,
2722,
363,
334,
277,
304,
267,
372,
2071,
83,
520,
450,
83,
520,
450,
83,
14007,
277,
14,
344,
12,
291,
14,
25603,
2360,
277,
14,
31164,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
344,
365,
488,
503,
1163,
14,
344,
365,
488,
221,
503,
291,
14,
344,
508,
1163,
14,
344,
9,
436,
291,
14,
25603,
508,
1163,
14,
25603,
971,
490,
436,
291,
14,
31164,
389,
1848,
14,
31164,
339,
347,
1305,
63,
269,
63,
988,
8,
277,
304,
267,
340,
291,
14,
344,
26,
288,
372,
1109,
8,
277,
14,
344,
9,
267,
587,
26,
288,
372,
19791,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
492,
19791,
421,
199,
533,
18684,
26,
272,
347,
636,
826,
721,
277,
12,
1642,
354,
29,
488,
12,
2061,
354,
29,
488,
12,
1305,
29,
488,
12,
326,
5629,
9339,
29,
488,
12,
221,
21305,
9339,
29,
488,
12,
1736,
9339,
29,
488,
12,
3499,
9339,
29,
488,
2360,
1006,
63,
838,
4548,
63,
504,
63,
25539,
29,
403,
12,
326,
2287,
29,
403,
12,
3031,
29,
403,
12,
3031,
18,
29,
403,
12,
3031,
19,
29,
403,
12,
1006,
63,
14170,
29,
403,
304,
267,
291,
14,
25603,
275,
1642,
354,
267,
291,
14,
31164,
275,
2061,
354,
267,
291,
14,
4219,
9339,
275,
5629,
9339,
267,
291,
14,
800,
9339,
275,
1736,
9339,
267,
291,
14,
11375,
9339,
275,
21305,
9339,
267,
291,
14,
4375,
9339,
275,
3499,
9339,
267,
291,
14,
452,
63,
838,
4548,
63,
504,
63,
25539,
275,
1006,
63,
838,
4548,
63,
504,
63,
25539,
267,
291,
14,
1562,
29,
1562,
267,
291,
14,
2123,
29,
2123,
267,
291,
14,
2123,
18,
29,
2123,
18,
267,
291,
14,
2123,
19,
29,
2123,
19,
267,
291,
14,
344,
275,
1305,
267,
291,
14,
452,
63,
14170,
29,
452,
63,
14170,
339,
347,
636,
2722,
363,
334,
277,
304,
267,
372,
2071,
83,
520,
450,
83,
520,
450,
83,
14007,
277,
14,
344,
12,
291,
14,
25603,
2360,
277,
14,
31164,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
334,
277,
14,
344,
365,
488,
503,
1163,
14,
344,
365,
488,
221,
503,
291,
14,
344,
508,
1163,
14,
344,
9,
436,
291,
14,
25603,
508,
1163,
14,
25603,
971,
490,
436,
291,
14,
31164,
389,
1848,
14,
31164,
339,
347,
1305,
63,
269,
63,
988,
8,
277,
304,
267,
340,
291,
14,
344,
26,
288,
372,
1109,
8,
277,
14,
344,
9,
267,
587,
26,
288,
372,
19791,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
402231466/2015cd_midterm
|
gear.py
|
11
|
19446
|
#@+leo-ver=5-thin
#@+node:office.20150407074720.1: * @file gear.py
#@@language python
#@@tabwidth -4
#@+<<declarations>>
#@+node:office.20150407074720.2: ** <<declarations>> (application)
#@@language python
import cherrypy
import os
import sys
# 這個程式要計算正齒輪的齒面寬, 資料庫連結希望使用 pybean 與 SQLite
# 導入 pybean 模組與所要使用的 Store 及 SQLiteWriter 方法
from pybean import Store, SQLiteWriter
import math
# 確定程式檔案所在目錄, 在 Windows 有最後的反斜線
_curdir = os.path.join(os.getcwd(), os.path.dirname(__file__))
# 將所在目錄設為系統搜尋目錄
sys.path.append(_curdir)
if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
# while program is executed in OpenShift
download_root_dir = os.environ['OPENSHIFT_DATA_DIR']
data_dir = os.environ['OPENSHIFT_DATA_DIR']
else:
# while program is executed in localhost
download_root_dir = _curdir + "/local_data/"
data_dir = _curdir + "/local_data/"
# 這是 Gear 設計資料表的定義
'''
lewis.db 中有兩個資料表, steel 與 lewis
CREATE TABLE steel (
serialno INTEGER,
unsno TEXT,
aisino TEXT,
treatment TEXT,
yield_str INTEGER,
tensile_str INTEGER,
stretch_ratio INTEGER,
sectional_shr INTEGER,
brinell INTEGER
);
CREATE TABLE lewis (
serialno INTEGER PRIMARY KEY
NOT NULL,
gearno INTEGER,
type1 NUMERIC,
type4 NUMERIC,
type3 NUMERIC,
type2 NUMERIC
);
'''
#@-<<declarations>>
#@+others
#@+node:office.20150407074720.3: ** class Gear
class Gear(object):
#@+others
#@+node:office.20150407074720.4: *3* __init__
def __init__(self):
# hope to create downloads and images directories
if not os.path.isdir(download_root_dir+"downloads"):
try:
os.makedirs(download_root_dir+"downloads")
except:
print("mkdir error")
if not os.path.isdir(download_root_dir+"images"):
try:
os.makedirs(download_root_dir+"images")
except:
print("mkdir error")
if not os.path.isdir(download_root_dir+"tmp"):
try:
os.makedirs(download_root_dir+"tmp")
except:
print("mkdir error")
#@+node:office.20150407074720.5: *3* default
@cherrypy.expose
def default(self, attr='default', *args, **kwargs):
raise cherrypy.HTTPRedirect("/")
#@+node:office.20150407074720.6: *3* index
# 各組利用 index 引導隨後的程式執行
@cherrypy.expose
def index(self, *args, **kwargs):
# 進行資料庫檔案連結, 並且取出所有資料
try:
# 利用 Store 建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
# 因為程式以 application 所在目錄執行, 因此利用相對目錄連結 lewis.db 資料庫檔案
SQLite連結 = Store(SQLiteWriter(_curdir+"/lewis.db", frozen=True))
#material = SQLite連結.find_one("steel","serialno = ?",[序號])
# str(SQLite連結.count("steel")) 將傳回 70, 表示資料庫中有 70 筆資料
material = SQLite連結.find("steel")
# 所傳回的 material 為 iterator
'''
outstring = ""
for material_item in material:
outstring += str(material_item.serialno) + ":" + material_item.unsno + "_" + material_item.treatment + "<br />"
return outstring
'''
except:
return "抱歉! 資料庫無法連線<br />"
outstring = '''
<form method=\"post\" action=\"gear_width">
請先下載齒輪的檔案,放在V槽跟目錄下,存成黨名gear.prt,在開creo打本網址即可使用<br />
模數:<input type=\"text\" name=\"m\"><br />
齒數:<input type=\"text\" name=\"n\"><br />
PS:壓力角內定20度,不可更改<br />
請填妥下列參數,以完成適當的齒面寬尺寸大小設計。<br />
馬達馬力:<input type=text name=horsepower id=horsepower value=100 size=10>horse power<br />
馬達轉速:<input type=text name=rpm id=rpm value=1120 size=10>rpm<br />
齒輪減速比: <input type=text name=ratio id=ratio value=4 size=10><br />
齒形:<select name=toothtype id=toothtype>
<option value=type1>壓力角20度,a=0.8,b=1.0
<option value=type2>壓力角20度,a=1.0,b=1.25
</select><br />
安全係數:<input type=text name=safetyfactor id=safetyfactor value=3 size=10><br />
齒輪材質:<select name=material_serialno id=material_serialno><br />
'''
for material_item in material:
outstring += "<option value=" + str(material_item.serialno) + ">UNS - " + \
material_item.unsno + " - " + material_item.treatment
outstring += "</select><br />"
outstring += "小齒輪齒數:<input type=text name=npinion id=npinion value=18 size=10><br />"
outstring += "<input type=submit id=submit value=進行運算>"
outstring += "</form>"
return outstring
#@+node:office.20150407074720.7: *3* interpolation
@cherrypy.expose
def interpolation(self, small_gear_no=18, gear_type=1):
SQLite連結 = Store(SQLiteWriter(_curdir+"/lewis.db", frozen=True))
# 使用內插法求值
# 找出比目標齒數大的其中的最小的,就是最鄰近的大值
lewis_factor = SQLite連結.find_one("lewis","gearno > ?",[small_gear_no])
if(gear_type == 1):
larger_formfactor = lewis_factor.type1
elif(gear_type == 2):
larger_formfactor = lewis_factor.type2
elif(gear_type == 3):
larger_formfactor = lewis_factor.type3
else:
larger_formfactor = lewis_factor.type4
larger_toothnumber = lewis_factor.gearno
# 找出比目標齒數小的其中的最大的,就是最鄰近的小值
lewis_factor = SQLite連結.find_one("lewis","gearno < ? order by gearno DESC",[small_gear_no])
if(gear_type == 1):
smaller_formfactor = lewis_factor.type1
elif(gear_type == 2):
smaller_formfactor = lewis_factor.type2
elif(gear_type == 3):
smaller_formfactor = lewis_factor.type3
else:
smaller_formfactor = lewis_factor.type4
smaller_toothnumber = lewis_factor.gearno
calculated_factor = larger_formfactor + (small_gear_no - larger_toothnumber) * (larger_formfactor - smaller_formfactor) / (larger_toothnumber - smaller_toothnumber)
# 只傳回小數點後五位數
return str(round(calculated_factor, 5))
#@+node:office.20150407074720.8: *3* gear_width
# 改寫為齒面寬的設計函式
@cherrypy.expose
def gear_width(self, horsepower=100, rpm=1000, ratio=4, toothtype=1, safetyfactor=2, material_serialno=1, npinion=18,facewidth=None,n=None,m=None):
SQLite連結 = Store(SQLiteWriter(_curdir+"/lewis.db", frozen=True))
outstring = ""
# 根據所選用的齒形決定壓力角
if(toothtype == 1 or toothtype == 2):
壓力角 = 20
else:
壓力角 = 25
# 根據壓力角決定最小齒數
if(壓力角== 20):
最小齒數 = 18
else:
最小齒數 = 12
# 直接設最小齒數
if int(npinion) <= 最小齒數:
npinion = 最小齒數
# 大於400的齒數則視為齒條(Rack)
if int(npinion) >= 400:
npinion = 400
# 根據所選用的材料查詢強度值
# 由 material之序號查 steel 表以得材料之降伏強度S單位為 kpsi 因此查得的值要成乘上1000
# 利用 Store 建立資料庫檔案對應物件, 並且設定 frozen=True 表示不要開放動態資料表的建立
#SQLite連結 = Store(SQLiteWriter("lewis.db", frozen=True))
# 指定 steel 資料表
steel = SQLite連結.new("steel")
# 資料查詢
#material = SQLite連結.find_one("steel","unsno=? and treatment=?",[unsno, treatment])
material = SQLite連結.find_one("steel","serialno=?",[material_serialno])
# 列出 steel 資料表中的資料筆數
#print(SQLite連結.count("steel"))
#print (material.yield_str)
strengthstress = material.yield_str*1000
# 由小齒輪的齒數與齒形類別,查詢lewis form factor
# 先查驗是否有直接對應值
on_table = SQLite連結.count("lewis","gearno=?",[npinion])
if on_table == 1:
# 直接進入設計運算
#print("直接運算")
#print(on_table)
lewis_factor = SQLite連結.find_one("lewis","gearno=?",[npinion])
#print(lewis_factor.type1)
# 根據齒形查出 formfactor 值
if(toothtype == 1):
formfactor = lewis_factor.type1
elif(toothtype == 2):
formfactor = lewis_factor.type2
elif(toothtype == 3):
formfactor = lewis_factor.type3
else:
formfactor = lewis_factor.type4
else:
# 沒有直接對應值, 必須進行查表內插運算後, 再執行設計運算
#print("必須內插")
#print(interpolation(npinion, gear_type))
formfactor = self.interpolation(npinion, toothtype)
# 開始進行設計運算
ngear = int(npinion) * int(ratio)
# 重要的最佳化設計---儘量用整數的diametralpitch
# 先嘗試用整數算若 diametralpitch 找到100 仍無所獲則改用 0.25 作為增量再不行則宣告 fail
counter = 0
i = 0.1
facewidth = 0
circularpitch = 0
while (facewidth <= 3 * circularpitch or facewidth >= 5 * circularpitch):
diametralpitch = i
#circularpitch = 3.14159/diametralpitch
circularpitch = math.pi/diametralpitch
pitchdiameter = int(npinion)/diametralpitch
#pitchlinevelocity = 3.14159*pitchdiameter*rpm/12
pitchlinevelocity = math.pi*pitchdiameter * float(rpm)/12
transmittedload = 33000*float(horsepower)/pitchlinevelocity
velocityfactor = 1200/(1200 + pitchlinevelocity)
# formfactor is Lewis form factor
# formfactor need to get from table 13-3 and determined ty teeth number and type of tooth
# formfactor = 0.293
# 90 is the value get from table corresponding to material type
facewidth = transmittedload*diametralpitch*float(safetyfactor)/velocityfactor/formfactor/strengthstress
if(counter>5000):
outstring += "超過5000次的設計運算,仍無法找到答案!<br />"
outstring += "可能所選用的傳遞功率過大,或無足夠強度的材料可以使用!<br />"
# 離開while迴圈
break
i += 0.1
counter += 1
facewidth = round(facewidth, 4)
if(counter<5000):
# 再載入 gear 程式測試
outstring = '''<script type="text/javascript" src="/static/weblink/pfcUtils.js"></script>
<script type="text/javascript" src="/static/weblink/wl_header.js">// <![CDATA[
document.writeln ("Error loading Pro/Web.Link header!");
// ]]></script>
<script type="text/javascript" language="JavaScript">// <![CDATA[
if (!pfcIsWindows()) netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// 若第三輸入為 false, 表示僅載入 session, 但是不顯示
// ret 為 model open return
var ret = document.pwl.pwlMdlOpen("gear.prt", "v:/", false);
if (!ret.Status) {
alert("pwlMdlOpen failed (" + ret.ErrorCode + ")");
}
//將 ProE 執行階段設為變數 session
var session = pfcGetProESession();
// 在視窗中打開零件檔案, 並且顯示出來
var window = session.OpenFile(pfcCreate("pfcModelDescriptor").CreateFromFileName("gear.prt"));
var solid = session.GetModel("gear.prt",pfcCreate("pfcModelType").MDL_PART);
var n,width,m,myf,myn,mym,i,j,volume,count,d1Value,d2Value,d3Value;
// 將模型檔中的 length 變數設為 javascript 中的 length 變數
n = solid.GetParam("n");
// 將模型檔中的 width 變數設為 javascript 中的 width 變數
width = solid.GetParam("face_width");
m = solid.GetParam("module");
//改變零件尺寸
//myf=20;
//myn=20;
volume=0;
count=0;
try
{
// 以下採用 URL 輸入對應變數
//createParametersFromArguments ();
// 以下則直接利用 javascript 程式改變零件參數
for(i=0;i<=1;i++)
{
//for(j=0;j<=1;j++)
//{
myf='''+str(n)+''';
myn='''+str(facewidth)+'''
mym='''+str(m)+'''
// 設定變數值, 利用 ModelItem 中的 CreateDoubleParamValue 轉換成 Pro/Web.Link 所需要的浮點數值
//d1Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myf);
d1Value = pfcCreate ("MpfcModelItem").CreateIntParamValue(myf);
d2Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myn);
d3Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(mym);
// 將處理好的變數值, 指定給對應的零件變數
n.Value = d1Value;
width.Value = d2Value;
m.Value = d3Value;
//零件尺寸重新設定後, 呼叫 Regenerate 更新模型
solid.Regenerate(void null);
//利用 GetMassProperty 取得模型的質量相關物件
properties = solid.GetMassProperty(void null);
//volume = volume + properties.Volume;
volume = properties.Volume;
count = count + 1;
alert("你已經完成"+count+"顆"+myf+"齒,模數"+mym+"的大好齒輪");
// 將零件存為新檔案
var newfile = document.pwl.pwlMdlSaveAs("gear.prt", "v:/", "mygear_"+count+".prt");
if (!newfile.Status) {
alert("pwlMdlSaveAs failed (" + newfile.ErrorCode + ")");
}
//} // 內圈 for 迴圈
} //外圈 for 迴圈
//alert("共執行:"+count+"次,零件總體積:"+volume);
//alert("零件體積:"+properties.Volume);
//alert("零件體積取整數:"+Math.round(properties.Volume));
}
catch(err)
{
alert ("Exception occurred: "+pfcGetExceptionType (err));
}
// ]]></script>
'''
outstring += "進行"+str(counter)+"次重複運算後,得到合用的facewidth值為:"+str(facewidth)
return outstring
#@+node:office.20150407074720.9: *3* cube_weblink
@cherrypy.expose
def cube_weblink(self):
outstring = '''<script type="text/javascript" src="/static/weblink/pfcUtils.js"></script>
<script type="text/javascript" src="/static/weblink/wl_header.js">
document.writeln ("Error loading Pro/Web.Link header!");
</script>
<script type="text/javascript" language="JavaScript">
// 若第三輸入為 false, 表示僅載入 session, 但是不顯示
// ret 為 model open return
var ret = document.pwl.pwlMdlOpen("cube.prt", "v:/tmp", false);
if (!ret.Status) {
alert("pwlMdlOpen failed (" + ret.ErrorCode + ")");
}
//將 ProE 執行階段設為變數 session
var session = pfcGetProESession();
// 在視窗中打開零件檔案, 並且顯示出來
var window = session.OpenFile(pfcCreate("pfcModelDescriptor").CreateFromFileName("cube.prt"));
var solid = session.GetModel("cube.prt",pfcCreate("pfcModelType").MDL_PART);
var length,width,myf,myn,i,j,volume,count,d1Value,d2Value;
// 將模型檔中的 length 變數設為 javascript 中的 length 變數
length = solid.GetParam("a1");
// 將模型檔中的 width 變數設為 javascript 中的 width 變數
width = solid.GetParam("a2");
//改變零件尺寸
//myf=20;
//myn=20;
volume=0;
count=0;
try
{
// 以下採用 URL 輸入對應變數
//createParametersFromArguments ();
// 以下則直接利用 javascript 程式改變零件參數
for(i=0;i<=1;i++)
{
//for(j=0;j<=2;j++)
//{
myf=20.0;
myn=10.0+i*0.5;
// 設定變數值, 利用 ModelItem 中的 CreateDoubleParamValue 轉換成 Pro/Web.Link 所需要的浮點數值
d1Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myf);
d2Value = pfcCreate ("MpfcModelItem").CreateDoubleParamValue(myn);
// 將處理好的變數值, 指定給對應的零件變數
length.Value = d1Value;
width.Value = d2Value;
//零件尺寸重新設定後, 呼叫 Regenerate 更新模型
solid.Regenerate(void null);
//利用 GetMassProperty 取得模型的質量相關物件
properties = solid.GetMassProperty(void null);
//volume = volume + properties.Volume;
volume = properties.Volume;
count = count + 1;
alert("執行第"+count+"次,零件總體積:"+volume);
// 將零件存為新檔案
var newfile = document.pwl.pwlMdlSaveAs("cube.prt", "v:/tmp", "cube"+count+".prt");
if (!newfile.Status) {
alert("pwlMdlSaveAs failed (" + newfile.ErrorCode + ")");
}
//} // 內圈 for 迴圈
} //外圈 for 迴圈
//alert("共執行:"+count+"次,零件總體積:"+volume);
//alert("零件體積:"+properties.Volume);
//alert("零件體積取整數:"+Math.round(properties.Volume));
}
catch(err)
{
alert ("Exception occurred: "+pfcGetExceptionType (err));
}
</script>
'''
return outstring
#@-others
#@-others
root = Gear()
# setup static, images and downloads directories
application_conf = {
'/static':{
'tools.staticdir.on': True,
'tools.staticdir.dir': _curdir+"/static"},
'/images':{
'tools.staticdir.on': True,
'tools.staticdir.dir': data_dir+"/images"},
'/downloads':{
'tools.staticdir.on': True,
'tools.staticdir.dir': data_dir+"/downloads"}
}
# if inOpenshift ('OPENSHIFT_REPO_DIR' exists in environment variables) or not inOpenshift
if __name__ == '__main__':
if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
# operate in OpenShift
application = cherrypy.Application(root, config = application_conf)
else:
# operate in localhost
cherrypy.quickstart(root, config = application_conf)
#@-leo
|
gpl-3.0
|
[
17577,
11,
274,
79,
13,
422,
29,
21,
13,
24474,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
17,
26,
627,
768,
493,
2312,
285,
14,
647,
199,
3,
7492,
3671,
2366,
199,
3,
7492,
2902,
2063,
446,
20,
199,
199,
17577,
11,
8999,
21200,
1140,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
18,
26,
1011,
5213,
21200,
1140,
334,
3578,
9,
199,
3,
7492,
3671,
2366,
199,
199,
646,
13397,
199,
646,
747,
199,
646,
984,
199,
3,
10469,
223,
248,
20757,
234,
30664,
21041,
22274,
20278,
231,
21895,
17627,
97,
23157,
25624,
104,
8106,
23157,
26398,
96,
15150,
106,
12,
9065,
112,
230,
10310,
248,
15013,
105,
14333,
97,
23767,
239,
15280,
235,
6587,
250,
30026,
1134,
28142,
9065,
231,
230,
19245,
199,
3,
7094,
109,
237,
18236,
1134,
28142,
8853,
102,
95,
23767,
227,
165,
231,
230,
16570,
22274,
30026,
8106,
13874,
221,
6075,
233,
19245,
6261,
8853,
245,
118,
27397,
199,
504,
1134,
28142,
492,
13874,
12,
19245,
6261,
199,
646,
3473,
199,
199,
3,
9112,
96,
119,
20766,
30664,
21041,
163,
104,
243,
31333,
231,
16570,
21448,
31869,
166,
235,
227,
12,
7094,
251,
102,
5417,
221,
20916,
23112,
19073,
235,
8106,
6075,
236,
10310,
251,
27035,
249,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3,
7094,
109,
230,
16570,
21448,
31869,
166,
235,
227,
20278,
256,
24889,
27842,
120,
23767,
110,
163,
239,
251,
15348,
234,
31869,
166,
235,
227,
199,
1274,
14,
515,
14,
740,
1547,
15594,
9,
199,
692,
283,
9935,
18013,
63,
20424,
63,
3022,
7,
315,
747,
14,
2314,
14,
1612,
837,
272,
327,
1830,
2240,
365,
7934,
315,
3232,
14379,
272,
5235,
63,
1231,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
272,
666,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
199,
2836,
26,
272,
327,
1830,
2240,
365,
7934,
315,
11667,
272,
5235,
63,
1231,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
272,
666,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
199,
199,
3,
10469,
223,
248,
9729,
598,
2210,
9065,
102,
256,
20278,
231,
29273,
230,
10310,
248,
23243,
8106,
20766,
164,
123,
103,
199,
2344,
199,
199,
274,
87,
374,
14,
697,
221,
17088,
20916,
8379,
103,
20757,
234,
29273,
230,
10310,
248,
23243,
12,
20345,
352,
9065,
231,
230,
1026,
87,
374,
421,
16999,
9934,
20345,
352,
334,
5591,
3012,
889,
420,
17086,
12,
272,
625,
83,
889,
260,
11951,
12,
272,
282,
374,
10175,
263,
11951,
12,
272,
14312,
434,
258,
11951,
12,
272,
1995,
63,
495,
258,
17086,
12,
272,
16685,
338,
274,
63,
495,
257,
17086,
12,
272,
31262,
63,
6884,
17086,
12,
272,
3420,
279,
63,
609,
82,
17086,
12,
272,
11665,
262,
1697,
755,
17086,
221,
199,
2736,
199,
199,
8366,
9934,
1026,
87,
374,
334,
5591,
3012,
889,
17086,
19770,
9301,
2151,
2845,
5962,
12,
272,
2312,
285,
889,
257,
17086,
12,
272,
730,
17,
259,
31806,
12,
272,
730,
20,
259,
31806,
12,
272,
730,
19,
259,
31806,
12,
272,
730,
18,
259,
31806,
221,
199,
2736,
199,
2344,
199,
199,
17577,
13,
8999,
21200,
1140,
199,
17577,
11,
21714,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
19,
26,
1011,
1021,
598,
2210,
199,
533,
598,
2210,
8,
785,
304,
272,
18215,
21714,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
20,
26,
627,
19,
10,
636,
826,
363,
272,
347,
636,
826,
721,
277,
304,
267,
327,
3661,
370,
1218,
28242,
436,
5935,
6602,
12805,
223,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
20373,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
20373,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
4782,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
4782,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
2791,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
2791,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
21,
26,
627,
19,
10,
849,
272,
768,
23438,
14,
20586,
272,
347,
849,
8,
277,
12,
1921,
534,
885,
297,
627,
589,
12,
1011,
958,
304,
267,
746,
13397,
14,
2856,
7071,
19031,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
22,
26,
627,
19,
10,
1478,
272,
327,
7094,
239,
227,
23767,
227,
9051,
103,
11428,
1478,
7094,
121,
244,
15348,
237,
166,
249,
102,
19073,
235,
8106,
30664,
21041,
25056,
116,
12609,
272,
768,
23438,
14,
20586,
272,
347,
1478,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
10469,
223,
111,
12609,
29273,
230,
10310,
248,
15013,
105,
163,
104,
243,
31333,
231,
14333,
97,
23767,
239,
12,
221,
221,
4344,
100,
4344,
243,
22924,
22914,
16570,
20916,
29273,
230,
10310,
248,
267,
862,
26,
288,
327,
7094,
231,
103,
11428,
13874,
221,
7094,
120,
119,
21341,
234,
29273,
230,
10310,
248,
15013,
105,
163,
104,
243,
31333,
231,
15348,
236,
163,
230,
232,
19431,
103,
15054,
12,
221,
4344,
100,
4344,
243,
20278,
256,
20766,
8101,
29,
549,
9065,
95,
102,
29875,
119,
19594,
22274,
31834,
234,
17130,
123,
162,
234,
244,
163,
228,
234,
29273,
230,
10310,
248,
23243,
8106,
29427,
119,
21341,
234,
288,
327,
7094,
250,
255,
24889,
30664,
21041,
23681,
4223,
8853,
232,
223,
21448,
31869,
166,
235,
227,
25056,
116,
12609,
12,
7094,
250,
255,
17627,
98,
9051,
103,
11428,
15545,
117,
15348,
236,
31869,
166,
235,
227,
14333,
97,
23767,
239,
1026,
87,
374,
14,
697,
9065,
112,
230,
10310,
248,
15013
] |
[
11,
274,
79,
13,
422,
29,
21,
13,
24474,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
17,
26,
627,
768,
493,
2312,
285,
14,
647,
199,
3,
7492,
3671,
2366,
199,
3,
7492,
2902,
2063,
446,
20,
199,
199,
17577,
11,
8999,
21200,
1140,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
18,
26,
1011,
5213,
21200,
1140,
334,
3578,
9,
199,
3,
7492,
3671,
2366,
199,
199,
646,
13397,
199,
646,
747,
199,
646,
984,
199,
3,
10469,
223,
248,
20757,
234,
30664,
21041,
22274,
20278,
231,
21895,
17627,
97,
23157,
25624,
104,
8106,
23157,
26398,
96,
15150,
106,
12,
9065,
112,
230,
10310,
248,
15013,
105,
14333,
97,
23767,
239,
15280,
235,
6587,
250,
30026,
1134,
28142,
9065,
231,
230,
19245,
199,
3,
7094,
109,
237,
18236,
1134,
28142,
8853,
102,
95,
23767,
227,
165,
231,
230,
16570,
22274,
30026,
8106,
13874,
221,
6075,
233,
19245,
6261,
8853,
245,
118,
27397,
199,
504,
1134,
28142,
492,
13874,
12,
19245,
6261,
199,
646,
3473,
199,
199,
3,
9112,
96,
119,
20766,
30664,
21041,
163,
104,
243,
31333,
231,
16570,
21448,
31869,
166,
235,
227,
12,
7094,
251,
102,
5417,
221,
20916,
23112,
19073,
235,
8106,
6075,
236,
10310,
251,
27035,
249,
199,
63,
15594,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
747,
14,
515,
14,
3475,
3460,
493,
8964,
199,
3,
7094,
109,
230,
16570,
21448,
31869,
166,
235,
227,
20278,
256,
24889,
27842,
120,
23767,
110,
163,
239,
251,
15348,
234,
31869,
166,
235,
227,
199,
1274,
14,
515,
14,
740,
1547,
15594,
9,
199,
692,
283,
9935,
18013,
63,
20424,
63,
3022,
7,
315,
747,
14,
2314,
14,
1612,
837,
272,
327,
1830,
2240,
365,
7934,
315,
3232,
14379,
272,
5235,
63,
1231,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
272,
666,
63,
694,
275,
747,
14,
2314,
459,
9935,
18013,
63,
3998,
63,
3022,
418,
199,
2836,
26,
272,
327,
1830,
2240,
365,
7934,
315,
11667,
272,
5235,
63,
1231,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
272,
666,
63,
694,
275,
485,
15594,
435,
3286,
1832,
63,
576,
6687,
199,
199,
3,
10469,
223,
248,
9729,
598,
2210,
9065,
102,
256,
20278,
231,
29273,
230,
10310,
248,
23243,
8106,
20766,
164,
123,
103,
199,
2344,
199,
199,
274,
87,
374,
14,
697,
221,
17088,
20916,
8379,
103,
20757,
234,
29273,
230,
10310,
248,
23243,
12,
20345,
352,
9065,
231,
230,
1026,
87,
374,
421,
16999,
9934,
20345,
352,
334,
5591,
3012,
889,
420,
17086,
12,
272,
625,
83,
889,
260,
11951,
12,
272,
282,
374,
10175,
263,
11951,
12,
272,
14312,
434,
258,
11951,
12,
272,
1995,
63,
495,
258,
17086,
12,
272,
16685,
338,
274,
63,
495,
257,
17086,
12,
272,
31262,
63,
6884,
17086,
12,
272,
3420,
279,
63,
609,
82,
17086,
12,
272,
11665,
262,
1697,
755,
17086,
221,
199,
2736,
199,
199,
8366,
9934,
1026,
87,
374,
334,
5591,
3012,
889,
17086,
19770,
9301,
2151,
2845,
5962,
12,
272,
2312,
285,
889,
257,
17086,
12,
272,
730,
17,
259,
31806,
12,
272,
730,
20,
259,
31806,
12,
272,
730,
19,
259,
31806,
12,
272,
730,
18,
259,
31806,
221,
199,
2736,
199,
2344,
199,
199,
17577,
13,
8999,
21200,
1140,
199,
17577,
11,
21714,
199,
17577,
11,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
19,
26,
1011,
1021,
598,
2210,
199,
533,
598,
2210,
8,
785,
304,
272,
18215,
21714,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
20,
26,
627,
19,
10,
636,
826,
363,
272,
347,
636,
826,
721,
277,
304,
267,
327,
3661,
370,
1218,
28242,
436,
5935,
6602,
12805,
223,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
20373,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
20373,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
4782,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
4782,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
267,
340,
440,
747,
14,
515,
14,
6027,
8,
4249,
63,
1231,
63,
694,
5207,
2791,
2349,
288,
862,
26,
355,
747,
14,
8347,
8,
4249,
63,
1231,
63,
694,
5207,
2791,
531,
288,
871,
26,
355,
870,
480,
8215,
1125,
531,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
21,
26,
627,
19,
10,
849,
272,
768,
23438,
14,
20586,
272,
347,
849,
8,
277,
12,
1921,
534,
885,
297,
627,
589,
12,
1011,
958,
304,
267,
746,
13397,
14,
2856,
7071,
19031,
272,
18215,
932,
26,
18812,
14,
7806,
966,
19235,
17592,
1165,
14,
22,
26,
627,
19,
10,
1478,
272,
327,
7094,
239,
227,
23767,
227,
9051,
103,
11428,
1478,
7094,
121,
244,
15348,
237,
166,
249,
102,
19073,
235,
8106,
30664,
21041,
25056,
116,
12609,
272,
768,
23438,
14,
20586,
272,
347,
1478,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
327,
10469,
223,
111,
12609,
29273,
230,
10310,
248,
15013,
105,
163,
104,
243,
31333,
231,
14333,
97,
23767,
239,
12,
221,
221,
4344,
100,
4344,
243,
22924,
22914,
16570,
20916,
29273,
230,
10310,
248,
267,
862,
26,
288,
327,
7094,
231,
103,
11428,
13874,
221,
7094,
120,
119,
21341,
234,
29273,
230,
10310,
248,
15013,
105,
163,
104,
243,
31333,
231,
15348,
236,
163,
230,
232,
19431,
103,
15054,
12,
221,
4344,
100,
4344,
243,
20278,
256,
20766,
8101,
29,
549,
9065,
95,
102,
29875,
119,
19594,
22274,
31834,
234,
17130,
123,
162,
234,
244,
163,
228,
234,
29273,
230,
10310,
248,
23243,
8106,
29427,
119,
21341,
234,
288,
327,
7094,
250,
255,
24889,
30664,
21041,
23681,
4223,
8853,
232,
223,
21448,
31869,
166,
235,
227,
25056,
116,
12609,
12,
7094,
250,
255,
17627,
98,
9051,
103,
11428,
15545,
117,
15348,
236,
31869,
166,
235,
227,
14333,
97,
23767,
239,
1026,
87,
374,
14,
697,
9065,
112,
230,
10310,
248,
15013,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
orione7/Italorione
|
servers/fileflyer.py
|
20
|
2254
|
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# pelisalacarta - XBMC Plugin
# Conector para fileflyer
# http://blog.tvalacarta.info/plugin-xbmc/pelisalacarta/
#------------------------------------------------------------
import urlparse,urllib2,urllib,re
import os
from core import scrapertools
from core import logger
from core import config
def test_video_exists( page_url ):
logger.info("[fileflyer.py] test_video_exists(page_url='%s')" % page_url)
# Vídeo borrado: http://www.fileflyer.com/view/fioZRBu
# Video erróneo:
data = scrapertools.cache_page( page_url )
if '<a href="/RemoveDetail.aspx">' in data:
return False,"El archivo ya no está disponible<br/>en fileflyer (ha sido borrado)"
else:
return True,""
def get_video_url( page_url , premium = False , user="" , password="", video_password="" ):
logger.info("[fileflyer.py] get_video_url(page_url='%s')" % page_url)
video_urls = []
data = scrapertools.cache_page(page_url)
location = scrapertools.get_match(data,'<td class="dwnlbtn"[^<]+<a id="[^"]+" title="[^"]+" class="[^"]+" href="([^"]+)"')
video_urls.append( [ scrapertools.get_filename_from_url(location)[-4:]+" [fileflyer]" , location ] )
for video_url in video_urls:
logger.info("[fileflyer.py] %s - %s" % (video_url[0],video_url[1]))
return video_urls
# Encuentra vídeos del servidor en el texto pasado
def find_videos(data):
encontrados = set()
devuelve = []
# http://www.fileflyer.com/view/fioZRBu
patronvideos = '(fileflyer.com/view/[a-zA-Z0-9]+)'
logger.info("[fileflyer.py] find_videos #"+patronvideos+"#")
matches = re.compile(patronvideos,re.DOTALL).findall(data)
for match in matches:
titulo = "[fileflyer]"
url = "http://www."+match
if url not in encontrados:
logger.info(" url="+url)
devuelve.append( [ titulo , url , 'fileflyer' ] )
encontrados.add(url)
else:
logger.info(" url duplicada="+url)
return devuelve
def test():
video_urls = get_video_url("http://www.fileflyer.com/view/Pi1BSCJ")
return len(video_urls)>0
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
570,
21600,
281,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
7097,
12,
4078,
18,
12,
4078,
12,
264,
199,
646,
747,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
199,
318,
511,
63,
3722,
63,
2444,
8,
2034,
63,
633,
3461,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
2286,
327,
812,
13676,
2172,
330,
269,
345,
1117,
26,
1455,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
329,
79,
58,
50,
1713,
272,
327,
15709,
2329,
11980,
685,
79,
26,
5591,
666,
275,
28348,
14,
1637,
63,
1606,
8,
2034,
63,
633,
776,
272,
340,
2650,
65,
4369,
9555,
5587,
8064,
14,
26146,
15603,
315,
666,
26,
267,
372,
756,
4589,
10420,
3819,
1003,
79,
612,
65,
949,
4347,
11302,
2153,
678,
7247,
28,
3289,
3133,
287,
570,
21600,
281,
334,
2411,
15764,
79,
330,
269,
345,
1117,
2924,
272,
587,
26,
267,
372,
715,
12,
341,
199,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
272,
3991,
63,
3603,
275,
942,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
272,
2909,
275,
28348,
14,
362,
63,
1431,
8,
576,
2584,
28,
2076,
1021,
628,
68,
3501,
6374,
5889,
2,
4735,
28,
2807,
28,
65,
1305,
628,
25153,
5207,
2538,
628,
25153,
5207,
1021,
628,
25153,
5207,
4369,
32391,
358,
6163,
272,
3991,
63,
3603,
14,
740,
8,
359,
28348,
14,
362,
63,
1501,
63,
504,
63,
633,
8,
1985,
15786,
20,
26,
2807,
2,
359,
493,
21600,
281,
8480,
2360,
2909,
1622,
776,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
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,
327,
1455,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
329,
79,
58,
50,
1713,
272,
32500,
11418,
221,
275,
8189,
493,
21600,
281,
14,
957,
15,
1345,
32418,
65,
13,
6353,
13,
58,
16,
13,
25,
29716,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
576,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
493,
21600,
281,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
2122,
11,
1431,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
493,
21600,
281,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
339,
372,
4866,
13086,
432,
199,
199,
318,
511,
837,
272,
3991,
63,
3603,
275,
664,
63,
3722,
63,
633,
480,
1014,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
10542,
17,
34,
5153,
42,
531,
339,
372,
822,
8,
3722,
63,
3603,
13032,
16,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
17807,
4559,
199,
3,
4837,
317,
6327,
645,
29549,
446,
1323,
28994,
11349,
199,
3,
445,
368,
630,
12665,
570,
21600,
281,
199,
3,
1455,
921,
11486,
14,
84,
637,
645,
29549,
14,
815,
15,
2718,
13,
21382,
15,
321,
317,
6327,
645,
29549,
15,
199,
17807,
4559,
199,
199,
646,
7097,
12,
4078,
18,
12,
4078,
12,
264,
199,
646,
747,
199,
199,
504,
6170,
492,
28348,
199,
504,
6170,
492,
2512,
199,
504,
6170,
492,
1101,
199,
199,
318,
511,
63,
3722,
63,
2444,
8,
2034,
63,
633,
3461,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
511,
63,
3722,
63,
2444,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
2286,
327,
812,
13676,
2172,
330,
269,
345,
1117,
26,
1455,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
329,
79,
58,
50,
1713,
272,
327,
15709,
2329,
11980,
685,
79,
26,
5591,
666,
275,
28348,
14,
1637,
63,
1606,
8,
2034,
63,
633,
776,
272,
340,
2650,
65,
4369,
9555,
5587,
8064,
14,
26146,
15603,
315,
666,
26,
267,
372,
756,
4589,
10420,
3819,
1003,
79,
612,
65,
949,
4347,
11302,
2153,
678,
7247,
28,
3289,
3133,
287,
570,
21600,
281,
334,
2411,
15764,
79,
330,
269,
345,
1117,
2924,
272,
587,
26,
267,
372,
715,
12,
341,
199,
199,
318,
664,
63,
3722,
63,
633,
8,
2034,
63,
633,
2360,
876,
23481,
275,
756,
2360,
922,
9287,
2360,
2505,
8772,
3991,
63,
2060,
9287,
3461,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
664,
63,
3722,
63,
633,
8,
1606,
63,
633,
9569,
83,
19124,
450,
2034,
63,
633,
9,
272,
3991,
63,
3603,
275,
942,
339,
666,
275,
28348,
14,
1637,
63,
1606,
8,
1606,
63,
633,
9,
272,
2909,
275,
28348,
14,
362,
63,
1431,
8,
576,
2584,
28,
2076,
1021,
628,
68,
3501,
6374,
5889,
2,
4735,
28,
2807,
28,
65,
1305,
628,
25153,
5207,
2538,
628,
25153,
5207,
1021,
628,
25153,
5207,
4369,
32391,
358,
6163,
272,
3991,
63,
3603,
14,
740,
8,
359,
28348,
14,
362,
63,
1501,
63,
504,
63,
633,
8,
1985,
15786,
20,
26,
2807,
2,
359,
493,
21600,
281,
8480,
2360,
2909,
1622,
776,
339,
367,
3991,
63,
633,
315,
3991,
63,
3603,
26,
267,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
450,
83,
446,
450,
83,
2,
450,
334,
3722,
63,
633,
59,
16,
467,
3722,
63,
633,
59,
17,
2459,
339,
372,
3991,
63,
3603,
199,
199,
3,
3447,
15140,
484,
345,
373,
13676,
18808,
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,
327,
1455,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
329,
79,
58,
50,
1713,
272,
32500,
11418,
221,
275,
8189,
493,
21600,
281,
14,
957,
15,
1345,
32418,
65,
13,
6353,
13,
58,
16,
13,
25,
29716,
272,
2512,
14,
815,
10994,
493,
21600,
281,
14,
647,
61,
2342,
63,
11418,
327,
7709,
10853,
2641,
11418,
5207,
3,
531,
272,
4450,
275,
295,
14,
2014,
8,
10853,
2641,
11418,
12,
264,
14,
16504,
680,
6452,
8,
576,
9,
339,
367,
1336,
315,
4450,
26,
267,
3367,
10963,
320,
275,
7369,
493,
21600,
281,
8480,
267,
1166,
275,
298,
1014,
921,
1544,
2122,
11,
1431,
267,
340,
1166,
440,
315,
655,
17926,
18339,
26,
288,
2512,
14,
815,
480,
221,
1166,
16368,
633,
9,
288,
4866,
13086,
432,
14,
740,
8,
359,
3367,
10963,
320,
2360,
1166,
2360,
283,
493,
21600,
281,
7,
1622,
776,
288,
655,
17926,
18339,
14,
525,
8,
633,
9,
267,
587,
26,
288,
2512,
14,
815,
480,
221,
1166,
366,
4230,
10641,
16368,
633,
9,
339,
372,
4866,
13086,
432,
199,
199,
318,
511,
837,
272,
3991,
63,
3603,
275,
664,
63,
3722,
63,
633,
480,
1014,
921,
1544,
14,
493,
21600,
281,
14,
957,
15,
1345,
15,
10542,
17,
34,
5153,
42,
531,
339,
372,
822,
8,
3722,
63,
3603,
13032,
16,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
kurikuri99/xen_study
|
tools/python/xen/xend/tests/test_XendConfig.py
|
49
|
2017
|
import unittest
import xen.xend.XendConfig as XendConfig
class test_XendConfig(unittest.TestCase):
def testParseFromSXP(self):
cfg = XendConfig.XendConfig(
sxp_obj = (
['vm',
['bootloader_args', '-q --default_args="root=/dev/sda1 ro" --extra_args="quiet" /images/VM1.sda'],
['bootloader', '/usr/bin/pygrub'],
['device', ['vif', ['mac', '00:16:3E:4C:D1:00'], ['script', 'vif-bridge'], ['bridge', 'xenbr0']]],
['device', ['vif', ['mac', '00:16:3E:48:56:26'], ['script', 'vif-bridge'], ['bridge', 'vbridge0']]],
['device', ['vbd', ['uname', 'phy:/images/VM1.sda'], ['dev', 'sda'], ['mode', 'w']]],
['device', ['vbd', ['uname', 'phy:/images/VM1.sdb'], ['dev', 'sdb'], ['mode', 'w']]],
['memory', '256'], ['name', 'VM1'], ['on_crash', 'restart'],
['uuid', '10927a76-fe27-49b2-8f57-2970b7bbed6c'], ['vcpus', '1']
]))
self.assertEqual(cfg['uuid'], '10927a76-fe27-49b2-8f57-2970b7bbed6c')
self.assertEqual(cfg['name_label'], 'VM1')
self.assertEqual(cfg['memory_static_max'], 256)
ordered_refs = cfg.ordered_device_refs()
self.assertEqual(cfg['devices'][ordered_refs[0]][0], 'vbd')
self.assertEqual(cfg['devices'][ordered_refs[1]][0], 'vbd')
self.assertEqual(cfg['devices'][ordered_refs[2]][0], 'vif')
self.assertEqual(cfg['devices'][ordered_refs[3]][0], 'vif')
self.assertEqual(cfg['devices'][ordered_refs[0]][1]['uname'],
'phy:/images/VM1.sda')
self.assertEqual(cfg['devices'][ordered_refs[1]][1]['uname'],
'phy:/images/VM1.sdb')
self.assertEqual(cfg['devices'][ordered_refs[2]][1]['mac'],
'00:16:3E:4C:D1:00')
self.assertEqual(cfg['devices'][ordered_refs[3]][1]['mac'],
'00:16:3E:48:56:26')
def test_suite():
return unittest.makeSuite(test_XendConfig)
|
gpl-2.0
|
[
646,
2882,
199,
199,
646,
20388,
14,
88,
500,
14,
56,
500,
2028,
465,
31314,
2028,
421,
199,
533,
511,
63,
56,
500,
2028,
8,
2796,
14,
1746,
304,
339,
347,
511,
4003,
2532,
51,
20168,
8,
277,
304,
267,
4810,
275,
31314,
2028,
14,
56,
500,
2028,
8,
288,
308,
9290,
63,
1113,
275,
334,
288,
788,
2611,
297,
1467,
788,
4930,
3422,
63,
589,
297,
2475,
81,
1553,
885,
63,
589,
628,
1231,
13043,
2374,
15,
19387,
17,
882,
2,
1553,
2911,
63,
589,
628,
10243,
2,
1182,
4782,
15,
6849,
17,
14,
19387,
995,
2432,
788,
4930,
3422,
297,
1994,
2647,
15,
1393,
15,
647,
2587,
456,
995,
1467,
788,
1782,
297,
788,
14430,
297,
788,
3088,
297,
283,
383,
26,
975,
26,
19,
37,
26,
20,
35,
26,
36,
17,
26,
383,
995,
788,
1579,
297,
283,
14430,
13,
9528,
995,
788,
9528,
297,
283,
13615,
3289,
16,
4397,
1467,
788,
1782,
297,
788,
14430,
297,
788,
3088,
297,
283,
383,
26,
975,
26,
19,
37,
26,
2006,
26,
1367,
26,
1479,
995,
788,
1579,
297,
283,
14430,
13,
9528,
995,
788,
9528,
297,
283,
86,
9528,
16,
4397,
1467,
788,
1782,
297,
788,
32505,
297,
788,
16040,
297,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
19387,
995,
788,
2374,
297,
283,
19387,
995,
788,
632,
297,
283,
87,
4397,
1467,
788,
1782,
297,
788,
32505,
297,
788,
16040,
297,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
21624,
995,
788,
2374,
297,
283,
21624,
995,
788,
632,
297,
283,
87,
4397,
1467,
788,
4844,
297,
283,
3912,
995,
788,
354,
297,
283,
6849,
17,
995,
788,
265,
63,
14807,
297,
283,
10506,
995,
1467,
788,
2580,
297,
283,
6996,
1465,
65,
2114,
13,
771,
1465,
13,
1887,
66,
18,
13,
24,
70,
1641,
13,
1398,
2760,
66,
23,
2501,
379,
22,
67,
995,
788,
19685,
297,
283,
17,
418,
1467,
22979,
398,
291,
14,
629,
8,
4128,
459,
2580,
995,
283,
6996,
1465,
65,
2114,
13,
771,
1465,
13,
1887,
66,
18,
13,
24,
70,
1641,
13,
1398,
2760,
66,
23,
2501,
379,
22,
67,
358,
267,
291,
14,
629,
8,
4128,
459,
354,
63,
1302,
995,
283,
6849,
17,
358,
267,
291,
14,
629,
8,
4128,
459,
4844,
63,
1986,
63,
988,
995,
7633,
9,
398,
7741,
63,
7655,
275,
4810,
14,
8235,
63,
1782,
63,
7655,
342,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
16,
22235,
16,
467,
283,
32505,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
17,
22235,
16,
467,
283,
32505,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
18,
22235,
16,
467,
283,
14430,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
19,
22235,
16,
467,
283,
14430,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
16,
22235,
17,
2733,
16040,
995,
586,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
19387,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
17,
22235,
17,
2733,
16040,
995,
586,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
21624,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
18,
22235,
17,
2733,
3088,
995,
586,
283,
383,
26,
975,
26,
19,
37,
26,
20,
35,
26,
36,
17,
26,
383,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
19,
22235,
17,
2733,
3088,
995,
586,
283,
383,
26,
975,
26,
19,
37,
26,
2006,
26,
1367,
26,
1479,
358,
421,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
396,
63,
56,
500,
2028,
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
] |
[
2882,
199,
199,
646,
20388,
14,
88,
500,
14,
56,
500,
2028,
465,
31314,
2028,
421,
199,
533,
511,
63,
56,
500,
2028,
8,
2796,
14,
1746,
304,
339,
347,
511,
4003,
2532,
51,
20168,
8,
277,
304,
267,
4810,
275,
31314,
2028,
14,
56,
500,
2028,
8,
288,
308,
9290,
63,
1113,
275,
334,
288,
788,
2611,
297,
1467,
788,
4930,
3422,
63,
589,
297,
2475,
81,
1553,
885,
63,
589,
628,
1231,
13043,
2374,
15,
19387,
17,
882,
2,
1553,
2911,
63,
589,
628,
10243,
2,
1182,
4782,
15,
6849,
17,
14,
19387,
995,
2432,
788,
4930,
3422,
297,
1994,
2647,
15,
1393,
15,
647,
2587,
456,
995,
1467,
788,
1782,
297,
788,
14430,
297,
788,
3088,
297,
283,
383,
26,
975,
26,
19,
37,
26,
20,
35,
26,
36,
17,
26,
383,
995,
788,
1579,
297,
283,
14430,
13,
9528,
995,
788,
9528,
297,
283,
13615,
3289,
16,
4397,
1467,
788,
1782,
297,
788,
14430,
297,
788,
3088,
297,
283,
383,
26,
975,
26,
19,
37,
26,
2006,
26,
1367,
26,
1479,
995,
788,
1579,
297,
283,
14430,
13,
9528,
995,
788,
9528,
297,
283,
86,
9528,
16,
4397,
1467,
788,
1782,
297,
788,
32505,
297,
788,
16040,
297,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
19387,
995,
788,
2374,
297,
283,
19387,
995,
788,
632,
297,
283,
87,
4397,
1467,
788,
1782,
297,
788,
32505,
297,
788,
16040,
297,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
21624,
995,
788,
2374,
297,
283,
21624,
995,
788,
632,
297,
283,
87,
4397,
1467,
788,
4844,
297,
283,
3912,
995,
788,
354,
297,
283,
6849,
17,
995,
788,
265,
63,
14807,
297,
283,
10506,
995,
1467,
788,
2580,
297,
283,
6996,
1465,
65,
2114,
13,
771,
1465,
13,
1887,
66,
18,
13,
24,
70,
1641,
13,
1398,
2760,
66,
23,
2501,
379,
22,
67,
995,
788,
19685,
297,
283,
17,
418,
1467,
22979,
398,
291,
14,
629,
8,
4128,
459,
2580,
995,
283,
6996,
1465,
65,
2114,
13,
771,
1465,
13,
1887,
66,
18,
13,
24,
70,
1641,
13,
1398,
2760,
66,
23,
2501,
379,
22,
67,
358,
267,
291,
14,
629,
8,
4128,
459,
354,
63,
1302,
995,
283,
6849,
17,
358,
267,
291,
14,
629,
8,
4128,
459,
4844,
63,
1986,
63,
988,
995,
7633,
9,
398,
7741,
63,
7655,
275,
4810,
14,
8235,
63,
1782,
63,
7655,
342,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
16,
22235,
16,
467,
283,
32505,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
17,
22235,
16,
467,
283,
32505,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
18,
22235,
16,
467,
283,
14430,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
19,
22235,
16,
467,
283,
14430,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
16,
22235,
17,
2733,
16040,
995,
586,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
19387,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
17,
22235,
17,
2733,
16040,
995,
586,
283,
6581,
11254,
4782,
15,
6849,
17,
14,
21624,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
18,
22235,
17,
2733,
3088,
995,
586,
283,
383,
26,
975,
26,
19,
37,
26,
20,
35,
26,
36,
17,
26,
383,
358,
267,
291,
14,
629,
8,
4128,
459,
6410,
3488,
8235,
63,
7655,
59,
19,
22235,
17,
2733,
3088,
995,
586,
283,
383,
26,
975,
26,
19,
37,
26,
2006,
26,
1367,
26,
1479,
358,
421,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
396,
63,
56,
500,
2028,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scotthartbti/android_external_chromium_org
|
base/PRESUBMIT.py
|
58
|
1853
|
# 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.
"""Chromium presubmit script for src/base.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details on the presubmit API built into gcl.
"""
def _CheckNoInterfacesInBase(input_api, output_api):
"""Checks to make sure no files in libbase.a have |@interface|."""
pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
files = []
for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
if (f.LocalPath().startswith('base/') and
not "/test/" in f.LocalPath() and
not f.LocalPath().endswith('_unittest.mm') and
not f.LocalPath().endswith('mac/sdk_forward_declarations.h')):
contents = input_api.ReadFile(f)
if pattern.search(contents):
files.append(f)
if len(files):
return [ output_api.PresubmitError(
'Objective-C interfaces or categories are forbidden in libbase. ' +
'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
'browse_thread/thread/efb28c10435987fd',
files) ]
return []
def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit."""
results = []
results.extend(_CheckNoInterfacesInBase(input_api, output_api))
return results
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
return results
def CheckChangeOnCommit(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
return results
def GetPreferredTrySlaves():
return [
'linux_rel:sync_integration_tests',
'mac_rel:sync_integration_tests',
'win_rel:sync_integration_tests',
]
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
29381,
23895,
2884,
367,
2928,
15,
1095,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
641,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
318,
485,
1799,
1944,
18680,
607,
1563,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
408,
11834,
370,
1852,
3238,
949,
1584,
315,
1973,
1095,
14,
65,
1172,
1204,
32,
3266,
92,
1041,
523,
3851,
275,
1324,
63,
1246,
14,
264,
14,
2014,
8,
82,
15542,
83,
10,
32,
3266,
297,
1324,
63,
1246,
14,
264,
14,
16661,
9,
523,
1584,
275,
942,
523,
367,
289,
315,
1324,
63,
1246,
14,
19256,
6201,
2980,
5535,
8,
1210,
63,
1246,
14,
4131,
2980,
1173,
304,
272,
340,
334,
70,
14,
26453,
1252,
2460,
360,
1095,
6217,
436,
267,
440,
3286,
396,
6687,
315,
289,
14,
26453,
342,
436,
267,
440,
289,
14,
26453,
1252,
4130,
6412,
2796,
14,
596,
358,
436,
267,
440,
289,
14,
26453,
1252,
4130,
360,
3088,
15,
9277,
63,
6688,
63,
21200,
14,
72,
8109,
489,
4072,
275,
1324,
63,
1246,
14,
32356,
8,
70,
9,
489,
340,
3851,
14,
1733,
8,
4407,
304,
267,
1584,
14,
740,
8,
70,
9,
819,
340,
822,
8,
1725,
304,
272,
372,
359,
1072,
63,
1246,
14,
30607,
547,
8,
267,
283,
29104,
13,
35,
8386,
503,
9695,
787,
24786,
315,
1973,
1095,
14,
283,
435,
267,
283,
9295,
1455,
921,
2634,
14,
3098,
14,
957,
15,
65,
15,
13211,
14,
1308,
15,
923,
15,
13211,
13,
2374,
4805,
435,
267,
283,
4570,
63,
2671,
15,
2671,
15,
2829,
66,
1651,
67,
6785,
11444,
1555,
2592,
297,
267,
1584,
9,
1622,
523,
372,
942,
421,
199,
318,
485,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
408,
11834,
2863,
370,
3865,
5802,
436,
5532,
1041,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
1799,
1944,
18680,
607,
1563,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
199,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
421,
199,
318,
2372,
29373,
12357,
51,
21868,
837,
523,
372,
359,
272,
283,
5135,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
272,
283,
3088,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
272,
283,
2676,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
523,
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
] |
[
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,
29381,
23895,
2884,
367,
2928,
15,
1095,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
641,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
318,
485,
1799,
1944,
18680,
607,
1563,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
408,
11834,
370,
1852,
3238,
949,
1584,
315,
1973,
1095,
14,
65,
1172,
1204,
32,
3266,
92,
1041,
523,
3851,
275,
1324,
63,
1246,
14,
264,
14,
2014,
8,
82,
15542,
83,
10,
32,
3266,
297,
1324,
63,
1246,
14,
264,
14,
16661,
9,
523,
1584,
275,
942,
523,
367,
289,
315,
1324,
63,
1246,
14,
19256,
6201,
2980,
5535,
8,
1210,
63,
1246,
14,
4131,
2980,
1173,
304,
272,
340,
334,
70,
14,
26453,
1252,
2460,
360,
1095,
6217,
436,
267,
440,
3286,
396,
6687,
315,
289,
14,
26453,
342,
436,
267,
440,
289,
14,
26453,
1252,
4130,
6412,
2796,
14,
596,
358,
436,
267,
440,
289,
14,
26453,
1252,
4130,
360,
3088,
15,
9277,
63,
6688,
63,
21200,
14,
72,
8109,
489,
4072,
275,
1324,
63,
1246,
14,
32356,
8,
70,
9,
489,
340,
3851,
14,
1733,
8,
4407,
304,
267,
1584,
14,
740,
8,
70,
9,
819,
340,
822,
8,
1725,
304,
272,
372,
359,
1072,
63,
1246,
14,
30607,
547,
8,
267,
283,
29104,
13,
35,
8386,
503,
9695,
787,
24786,
315,
1973,
1095,
14,
283,
435,
267,
283,
9295,
1455,
921,
2634,
14,
3098,
14,
957,
15,
65,
15,
13211,
14,
1308,
15,
923,
15,
13211,
13,
2374,
4805,
435,
267,
283,
4570,
63,
2671,
15,
2671,
15,
2829,
66,
1651,
67,
6785,
11444,
1555,
2592,
297,
267,
1584,
9,
1622,
523,
372,
942,
421,
199,
318,
485,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
408,
11834,
2863,
370,
3865,
5802,
436,
5532,
1041,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
1799,
1944,
18680,
607,
1563,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
199,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
421,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
2058,
275,
942,
523,
2058,
14,
2880,
1547,
7844,
11834,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
430,
523,
372,
2058,
421,
199,
318,
2372,
29373,
12357,
51,
21868,
837,
523,
372,
359,
272,
283,
5135,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
272,
283,
3088,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
272,
283,
2676,
63,
3369,
26,
5186,
63,
15092,
63,
2219,
297,
523,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ding: utf-8
"""
Kubernetes
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
The version of the OpenAPI document: release-1.18
Generated by: https://openapi-generator.tech
"""
import pprint
import re # noqa: F401
import six
from kubernetes.client.configuration import Configuration
class V1FCVolumeSource(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'fs_type': 'str',
'lun': 'int',
'read_only': 'bool',
'target_ww_ns': 'list[str]',
'wwids': 'list[str]'
}
attribute_map = {
'fs_type': 'fsType',
'lun': 'lun',
'read_only': 'readOnly',
'target_ww_ns': 'targetWWNs',
'wwids': 'wwids'
}
def __init__(self, fs_type=None, lun=None, read_only=None, target_ww_ns=None, wwids=None, local_vars_configuration=None): # noqa: E501
"""V1FCVolumeSource - a model defined in OpenAPI""" # noqa: E501
if local_vars_configuration is None:
local_vars_configuration = Configuration()
self.local_vars_configuration = local_vars_configuration
self._fs_type = None
self._lun = None
self._read_only = None
self._target_ww_ns = None
self._wwids = None
self.discriminator = None
if fs_type is not None:
self.fs_type = fs_type
if lun is not None:
self.lun = lun
if read_only is not None:
self.read_only = read_only
if target_ww_ns is not None:
self.target_ww_ns = target_ww_ns
if wwids is not None:
self.wwids = wwids
@property
def fs_type(self):
"""Gets the fs_type of this V1FCVolumeSource. # noqa: E501
Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\", \"ntfs\". Implicitly inferred to be \"ext4\" if unspecified. # noqa: E501
:return: The fs_type of this V1FCVolumeSource. # noqa: E501
:rtype: str
"""
return self._fs_type
@fs_type.setter
def fs_type(self, fs_type):
"""Sets the fs_type of this V1FCVolumeSource.
Filesystem type to mount. Must be a filesystem type supported by the host operating system. Ex. \"ext4\", \"xfs\", \"ntfs\". Implicitly inferred to be \"ext4\" if unspecified. # noqa: E501
:param fs_type: The fs_type of this V1FCVolumeSource. # noqa: E501
:type: str
"""
self._fs_type = fs_type
@property
def lun(self):
"""Gets the lun of this V1FCVolumeSource. # noqa: E501
Optional: FC target lun number # noqa: E501
:return: The lun of this V1FCVolumeSource. # noqa: E501
:rtype: int
"""
return self._lun
@lun.setter
def lun(self, lun):
"""Sets the lun of this V1FCVolumeSource.
Optional: FC target lun number # noqa: E501
:param lun: The lun of this V1FCVolumeSource. # noqa: E501
:type: int
"""
self._lun = lun
@property
def read_only(self):
"""Gets the read_only of this V1FCVolumeSource. # noqa: E501
Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts. # noqa: E501
:return: The read_only of this V1FCVolumeSource. # noqa: E501
:rtype: bool
"""
return self._read_only
@read_only.setter
def read_only(self, read_only):
"""Sets the read_only of this V1FCVolumeSource.
Optional: Defaults to false (read/write). ReadOnly here will force the ReadOnly setting in VolumeMounts. # noqa: E501
:param read_only: The read_only of this V1FCVolumeSource. # noqa: E501
:type: bool
"""
self._read_only = read_only
@property
def target_ww_ns(self):
"""Gets the target_ww_ns of this V1FCVolumeSource. # noqa: E501
Optional: FC target worldwide names (WWNs) # noqa: E501
:return: The target_ww_ns of this V1FCVolumeSource. # noqa: E501
:rtype: list[str]
"""
return self._target_ww_ns
@target_ww_ns.setter
def target_ww_ns(self, target_ww_ns):
"""Sets the target_ww_ns of this V1FCVolumeSource.
Optional: FC target worldwide names (WWNs) # noqa: E501
:param target_ww_ns: The target_ww_ns of this V1FCVolumeSource. # noqa: E501
:type: list[str]
"""
self._target_ww_ns = target_ww_ns
@property
def wwids(self):
"""Gets the wwids of this V1FCVolumeSource. # noqa: E501
Optional: FC volume world wide identifiers (wwids) Either wwids or combination of targetWWNs and lun must be set, but not both simultaneously. # noqa: E501
:return: The wwids of this V1FCVolumeSource. # noqa: E501
:rtype: list[str]
"""
return self._wwids
@wwids.setter
def wwids(self, wwids):
"""Sets the wwids of this V1FCVolumeSource.
Optional: FC volume world wide identifiers (wwids) Either wwids or combination of targetWWNs and lun must be set, but not both simultaneously. # noqa: E501
:param wwids: The wwids of this V1FCVolumeSource. # noqa: E501
:type: list[str]
"""
self._wwids = wwids
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, V1FCVolumeSource):
return False
return self.to_dict() == other.to_dict()
def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, V1FCVolumeSource):
return True
return self.to_dict() != other.to_dict()
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
28723,
339,
3091,
1369,
2741,
334,
10176,
701,
3232,
1246,
15042,
4178,
921,
5031,
14,
957,
15,
1490,
439,
390,
5998,
15,
1490,
1246,
13,
4679,
9,
221,
327,
8151,
26,
662,
8216,
339,
710,
1015,
402,
314,
3232,
3735,
2213,
26,
4683,
13,
17,
14,
1085,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
646,
10933,
199,
646,
295,
221,
327,
8151,
26,
481,
8854,
199,
199,
646,
3816,
199,
199,
504,
31160,
14,
1258,
14,
4758,
492,
11595,
421,
199,
533,
812,
17,
4161,
6464,
2980,
8,
785,
304,
272,
408,
19855,
26,
961,
1021,
365,
2599,
4046,
701,
3232,
3735,
15042,
14,
272,
15397,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
339,
4226,
440,
5283,
314,
1021,
10250,
14,
272,
408,
339,
408,
272,
9382,
26,
489,
1551,
1246,
63,
1313,
334,
807,
304,
710,
790,
365,
2225,
536,
1169,
436,
314,
574,
365,
2225,
730,
14,
489,
2225,
63,
1130,
334,
807,
304,
710,
790,
365,
2225,
536,
1169,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
272,
408,
272,
1551,
1246,
63,
1313,
275,
469,
267,
283,
2319,
63,
466,
356,
283,
495,
297,
267,
283,
13542,
356,
283,
442,
297,
267,
283,
739,
63,
2118,
356,
283,
2245,
297,
267,
283,
1375,
63,
978,
63,
561,
356,
283,
513,
59,
495,
4300,
267,
283,
978,
1580,
356,
283,
513,
59,
495,
6616,
272,
789,
339,
2225,
63,
1130,
275,
469,
267,
283,
2319,
63,
466,
356,
283,
2319,
804,
297,
267,
283,
13542,
356,
283,
13542,
297,
267,
283,
739,
63,
2118,
356,
283,
739,
5903,
297,
267,
283,
1375,
63,
978,
63,
561,
356,
283,
1375,
11178,
2438,
297,
267,
283,
978,
1580,
356,
283,
978,
1580,
7,
272,
789,
339,
347,
636,
826,
721,
277,
12,
7449,
63,
466,
29,
403,
12,
19465,
29,
403,
12,
1586,
63,
2118,
29,
403,
12,
1347,
63,
978,
63,
561,
29,
403,
12,
24618,
1580,
29,
403,
12,
2257,
63,
2936,
63,
4758,
29,
403,
304,
221,
327,
8151,
26,
662,
8216,
267,
408,
54,
17,
4161,
6464,
2980,
446,
282,
1402,
3247,
315,
3232,
3735,
624,
221,
327,
8151,
26,
662,
8216,
267,
340,
2257,
63,
2936,
63,
4758,
365,
488,
26,
288,
2257,
63,
2936,
63,
4758,
275,
11595,
342,
267,
291,
14,
1832,
63,
2936,
63,
4758,
275,
2257,
63,
2936,
63,
4758,
398,
291,
423,
2319,
63,
466,
275,
488,
267,
291,
423,
13542,
275,
488,
267,
291,
423,
739,
63,
2118,
275,
488,
267,
291,
423,
1375,
63,
978,
63,
561,
275,
488,
267,
291,
423,
978,
1580,
275,
488,
267,
291,
14,
328,
24565,
275,
488,
398,
340,
7449,
63,
466,
365,
440,
488,
26,
288,
291,
14,
2319,
63,
466,
275,
7449,
63,
466,
267,
340,
19465,
365,
440,
488,
26,
288,
291,
14,
13542,
275,
19465,
267,
340,
1586,
63,
2118,
365,
440,
488,
26,
288,
291,
14,
739,
63,
2118,
275,
1586,
63,
2118,
267,
340,
1347,
63,
978,
63,
561,
365,
440,
488,
26,
288,
291,
14,
1375,
63,
978,
63,
561,
275,
1347,
63,
978,
63,
561,
267,
340,
24618,
1580,
365,
440,
488,
26,
288,
291,
14,
978,
1580,
275,
24618,
1580,
339,
768,
1829,
272,
347,
7449,
63,
466,
8,
277,
304,
267,
408,
14426,
314,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
3814,
2253,
730,
370,
10760,
14,
9498,
506,
282,
10036,
730,
3748,
701,
314,
1591,
17406,
2656,
14,
1316,
14,
8441,
832,
20,
20756,
8441,
1949,
83,
20756,
8441,
343,
2319,
60,
1674,
8362,
3137,
590,
22515,
370,
506,
8441,
832,
20,
4451,
340,
21994,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
291,
423,
2319,
63,
466,
339,
768,
2319,
63,
466,
14,
8345,
272,
347,
7449,
63,
466,
8,
277,
12,
7449,
63,
466,
304,
267,
408,
9899,
314,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
398,
3814,
2253,
730,
370,
10760,
14,
9498,
506,
282,
10036,
730,
3748,
701,
314,
1591,
17406,
2656,
14,
1316,
14,
8441,
832,
20,
20756,
8441,
1949,
83,
20756,
8441,
343,
2319,
60,
1674,
8362,
3137,
590,
22515,
370,
506,
8441,
832,
20,
4451,
340,
21994,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
635,
7449,
63,
466,
26,
710,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
466,
26,
620,
267,
408,
398,
291,
423,
2319,
63,
466,
275,
7449,
63,
466,
339,
768,
1829,
272,
347,
19465,
8,
277,
304,
267,
408,
14426,
314,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
4879,
26,
20934,
1347,
19465,
1329,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
13542,
339,
768,
13542,
14,
8345,
272,
347,
19465,
8,
277,
12,
19465,
304,
267,
408,
9899,
314,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
398,
4879,
26,
20934,
1347,
19465,
1329,
221,
327,
8151,
26,
662,
8216,
398,
520,
635,
19465,
26,
710,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
13542,
275,
19465,
339,
768,
1829,
272,
347,
1586,
63,
2118,
8,
277,
304,
267,
408,
14426,
314,
1586,
63,
2118,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
4879,
26,
7827,
370,
3055,
334,
739,
15,
952,
680,
5574,
5903,
2348,
911,
3542,
314,
5574,
5903,
4260,
315,
15018,
24467,
83,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
1586,
63,
2118,
402,
642,
812,
17,
4161,
6464,
2980
] |
[
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
28723,
339,
3091,
1369,
2741,
334,
10176,
701,
3232,
1246,
15042,
4178,
921,
5031,
14,
957,
15,
1490,
439,
390,
5998,
15,
1490,
1246,
13,
4679,
9,
221,
327,
8151,
26,
662,
8216,
339,
710,
1015,
402,
314,
3232,
3735,
2213,
26,
4683,
13,
17,
14,
1085,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
646,
10933,
199,
646,
295,
221,
327,
8151,
26,
481,
8854,
199,
199,
646,
3816,
199,
199,
504,
31160,
14,
1258,
14,
4758,
492,
11595,
421,
199,
533,
812,
17,
4161,
6464,
2980,
8,
785,
304,
272,
408,
19855,
26,
961,
1021,
365,
2599,
4046,
701,
3232,
3735,
15042,
14,
272,
15397,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
339,
4226,
440,
5283,
314,
1021,
10250,
14,
272,
408,
339,
408,
272,
9382,
26,
489,
1551,
1246,
63,
1313,
334,
807,
304,
710,
790,
365,
2225,
536,
1169,
436,
314,
574,
365,
2225,
730,
14,
489,
2225,
63,
1130,
334,
807,
304,
710,
790,
365,
2225,
536,
1169,
436,
314,
574,
365,
2022,
790,
315,
5492,
14,
272,
408,
272,
1551,
1246,
63,
1313,
275,
469,
267,
283,
2319,
63,
466,
356,
283,
495,
297,
267,
283,
13542,
356,
283,
442,
297,
267,
283,
739,
63,
2118,
356,
283,
2245,
297,
267,
283,
1375,
63,
978,
63,
561,
356,
283,
513,
59,
495,
4300,
267,
283,
978,
1580,
356,
283,
513,
59,
495,
6616,
272,
789,
339,
2225,
63,
1130,
275,
469,
267,
283,
2319,
63,
466,
356,
283,
2319,
804,
297,
267,
283,
13542,
356,
283,
13542,
297,
267,
283,
739,
63,
2118,
356,
283,
739,
5903,
297,
267,
283,
1375,
63,
978,
63,
561,
356,
283,
1375,
11178,
2438,
297,
267,
283,
978,
1580,
356,
283,
978,
1580,
7,
272,
789,
339,
347,
636,
826,
721,
277,
12,
7449,
63,
466,
29,
403,
12,
19465,
29,
403,
12,
1586,
63,
2118,
29,
403,
12,
1347,
63,
978,
63,
561,
29,
403,
12,
24618,
1580,
29,
403,
12,
2257,
63,
2936,
63,
4758,
29,
403,
304,
221,
327,
8151,
26,
662,
8216,
267,
408,
54,
17,
4161,
6464,
2980,
446,
282,
1402,
3247,
315,
3232,
3735,
624,
221,
327,
8151,
26,
662,
8216,
267,
340,
2257,
63,
2936,
63,
4758,
365,
488,
26,
288,
2257,
63,
2936,
63,
4758,
275,
11595,
342,
267,
291,
14,
1832,
63,
2936,
63,
4758,
275,
2257,
63,
2936,
63,
4758,
398,
291,
423,
2319,
63,
466,
275,
488,
267,
291,
423,
13542,
275,
488,
267,
291,
423,
739,
63,
2118,
275,
488,
267,
291,
423,
1375,
63,
978,
63,
561,
275,
488,
267,
291,
423,
978,
1580,
275,
488,
267,
291,
14,
328,
24565,
275,
488,
398,
340,
7449,
63,
466,
365,
440,
488,
26,
288,
291,
14,
2319,
63,
466,
275,
7449,
63,
466,
267,
340,
19465,
365,
440,
488,
26,
288,
291,
14,
13542,
275,
19465,
267,
340,
1586,
63,
2118,
365,
440,
488,
26,
288,
291,
14,
739,
63,
2118,
275,
1586,
63,
2118,
267,
340,
1347,
63,
978,
63,
561,
365,
440,
488,
26,
288,
291,
14,
1375,
63,
978,
63,
561,
275,
1347,
63,
978,
63,
561,
267,
340,
24618,
1580,
365,
440,
488,
26,
288,
291,
14,
978,
1580,
275,
24618,
1580,
339,
768,
1829,
272,
347,
7449,
63,
466,
8,
277,
304,
267,
408,
14426,
314,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
3814,
2253,
730,
370,
10760,
14,
9498,
506,
282,
10036,
730,
3748,
701,
314,
1591,
17406,
2656,
14,
1316,
14,
8441,
832,
20,
20756,
8441,
1949,
83,
20756,
8441,
343,
2319,
60,
1674,
8362,
3137,
590,
22515,
370,
506,
8441,
832,
20,
4451,
340,
21994,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
4500,
26,
620,
267,
408,
267,
372,
291,
423,
2319,
63,
466,
339,
768,
2319,
63,
466,
14,
8345,
272,
347,
7449,
63,
466,
8,
277,
12,
7449,
63,
466,
304,
267,
408,
9899,
314,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
398,
3814,
2253,
730,
370,
10760,
14,
9498,
506,
282,
10036,
730,
3748,
701,
314,
1591,
17406,
2656,
14,
1316,
14,
8441,
832,
20,
20756,
8441,
1949,
83,
20756,
8441,
343,
2319,
60,
1674,
8362,
3137,
590,
22515,
370,
506,
8441,
832,
20,
4451,
340,
21994,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
635,
7449,
63,
466,
26,
710,
7449,
63,
466,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
466,
26,
620,
267,
408,
398,
291,
423,
2319,
63,
466,
275,
7449,
63,
466,
339,
768,
1829,
272,
347,
19465,
8,
277,
304,
267,
408,
14426,
314,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
4879,
26,
20934,
1347,
19465,
1329,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
4500,
26,
1109,
267,
408,
267,
372,
291,
423,
13542,
339,
768,
13542,
14,
8345,
272,
347,
19465,
8,
277,
12,
19465,
304,
267,
408,
9899,
314,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
398,
4879,
26,
20934,
1347,
19465,
1329,
221,
327,
8151,
26,
662,
8216,
398,
520,
635,
19465,
26,
710,
19465,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
267,
520,
466,
26,
1109,
267,
408,
398,
291,
423,
13542,
275,
19465,
339,
768,
1829,
272,
347,
1586,
63,
2118,
8,
277,
304,
267,
408,
14426,
314,
1586,
63,
2118,
402,
642,
812,
17,
4161,
6464,
2980,
14,
221,
327,
8151,
26,
662,
8216,
398,
4879,
26,
7827,
370,
3055,
334,
739,
15,
952,
680,
5574,
5903,
2348,
911,
3542,
314,
5574,
5903,
4260,
315,
15018,
24467,
83,
14,
221,
327,
8151,
26,
662,
8216,
398,
520,
1107,
26,
710,
1586,
63,
2118,
402,
642,
812,
17,
4161,
6464,
2980,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mayblue9/bokeh
|
bokeh/server/tests/wsmanager_test.py
|
29
|
2390
|
from __future__ import absolute_import
from bokeh import protocol
from bokeh import session
from . import test_utils
from ..app import bokeh_app
ws_address = "ws://localhost:5006/bokeh/sub"
class TestSubscribeWebSocket(test_utils.BokehServerTestCase):
def test_basic_subscribe(self):
self.sess1 = session.Session()
self.sess1.use_doc('first')
self.sess2 = session.Session()
self.sess2.use_doc('second')
#connect sock to defaultdoc
#connect sock2 to defaultdoc
#connect sock3 to defaultdoc2
firstid = self.sess1.docid
secondid = self.sess2.docid
firsttoken = self.sess1.apikey
secondtoken = self.sess2.apikey
import websocket
sock = websocket.WebSocket()
connect(sock, ws_address, 'bokehplot:%s' % firstid, firsttoken)
sock2 = websocket.WebSocket()
connect(sock2, ws_address, 'bokehplot:%s' % firstid, firsttoken)
sock3 = websocket.WebSocket()
connect(sock3, ws_address, 'bokehplot:%s' % secondid, secondtoken)
#make sure sock and sock2 receive message
bokeh_app.publisher.send('bokehplot:%s' % firstid, 'hello!')
msg = sock.recv()
assert msg == 'bokehplot:%s:hello!' % firstid
msg = sock2.recv()
assert msg == 'bokehplot:%s:hello!' % firstid
# send messages on 2 topics, make sure that sockets receive
# the right messages
bokeh_app.publisher.send('bokehplot:%s' % firstid, 'hello2!')
bokeh_app.publisher.send('bokehplot:%s' % secondid, 'hello3!')
msg = sock.recv()
assert msg == 'bokehplot:%s:hello2!' % firstid
msg = sock2.recv()
assert msg == 'bokehplot:%s:hello2!' % firstid
msg = sock3.recv()
assert msg == 'bokehplot:%s:hello3!' % secondid
def connect(sock, addr, topic, auth):
# TODO (bev) increasing timeout due to failing TravisCI tests
# investigate if this is the real solution or if there is a
# deeper problem
sock.timeout = 4.0
sock.connect(addr)
msgobj = dict(msgtype='subscribe',
topic=topic,
auth=auth
)
sock.send(protocol.serialize_json(msgobj))
msg = sock.recv()
msg = msg.split(":", 2)[-1]
msgobj = protocol.deserialize_json(msg)
assert msgobj['status'][:2] == ['subscribesuccess', topic]
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
25214,
492,
4113,
199,
504,
25214,
492,
2351,
199,
199,
504,
1275,
492,
511,
63,
1208,
199,
504,
2508,
571,
492,
25214,
63,
571,
199,
199,
3569,
63,
1562,
275,
298,
3569,
921,
5967,
26,
5783,
22,
15,
656,
16610,
15,
954,
2,
199,
199,
533,
1379,
2610,
5355,
18477,
8,
396,
63,
1208,
14,
2208,
16610,
3120,
1746,
304,
272,
347,
511,
63,
4316,
63,
10108,
8,
277,
304,
267,
291,
14,
5480,
17,
275,
2351,
14,
4434,
342,
267,
291,
14,
5480,
17,
14,
1180,
63,
1301,
360,
2246,
358,
267,
291,
14,
5480,
18,
275,
2351,
14,
4434,
342,
267,
291,
14,
5480,
18,
14,
1180,
63,
1301,
360,
4375,
358,
267,
327,
2242,
6771,
370,
849,
1301,
267,
327,
2242,
6771,
18,
370,
849,
1301,
267,
327,
2242,
6771,
19,
370,
849,
1301,
18,
267,
1642,
344,
275,
291,
14,
5480,
17,
14,
1301,
344,
267,
542,
388,
14887,
275,
291,
14,
5480,
18,
14,
1301,
344,
267,
1642,
1418,
275,
291,
14,
5480,
17,
14,
28181,
267,
3499,
1418,
275,
291,
14,
5480,
18,
14,
28181,
267,
492,
24897,
267,
6771,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
1642,
1418,
9,
267,
6771,
18,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
18,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
1642,
1418,
9,
398,
6771,
19,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
19,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
542,
388,
14887,
12,
3499,
1418,
9,
267,
327,
1875,
3238,
6771,
436,
6771,
18,
9128,
1245,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
283,
5006,
10916,
267,
1499,
275,
6771,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
18,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
11213,
450,
1642,
344,
398,
327,
3222,
3788,
641,
499,
17398,
12,
1852,
3238,
626,
18772,
9128,
267,
327,
314,
2451,
3788,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
283,
5006,
18,
10916,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
542,
388,
14887,
12,
283,
5006,
19,
10916,
267,
1499,
275,
6771,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
18,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
18,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
18,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
19,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
19,
11213,
450,
542,
388,
14887,
199,
199,
318,
4907,
8,
5096,
12,
5552,
12,
7482,
12,
1790,
304,
272,
327,
3254,
334,
1235,
86,
9,
22255,
2653,
7037,
370,
18648,
12643,
5068,
3553,
2295,
272,
327,
315,
27174,
323,
340,
642,
365,
314,
3363,
8744,
503,
340,
2337,
365,
282,
272,
327,
477,
15033,
5160,
272,
6771,
14,
2593,
275,
841,
14,
16,
272,
6771,
14,
2242,
8,
2697,
9,
272,
1499,
1113,
275,
1211,
8,
1328,
466,
534,
10108,
297,
2116,
7482,
29,
5746,
12,
2116,
1790,
29,
1178,
2116,
776,
272,
6771,
14,
2254,
8,
3922,
14,
3549,
63,
1001,
8,
28048,
430,
272,
1499,
275,
6771,
14,
7637,
342,
272,
1499,
275,
1499,
14,
1294,
480,
6783,
499,
15786,
17,
61,
272,
1499,
1113,
275,
4113,
14,
11143,
63,
1001,
8,
1328,
9,
272,
702,
1499,
1113,
459,
1205,
418,
1491,
18,
61,
508,
788,
954,
729,
11562,
1992,
297,
7482,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
25214,
492,
4113,
199,
504,
25214,
492,
2351,
199,
199,
504,
1275,
492,
511,
63,
1208,
199,
504,
2508,
571,
492,
25214,
63,
571,
199,
199,
3569,
63,
1562,
275,
298,
3569,
921,
5967,
26,
5783,
22,
15,
656,
16610,
15,
954,
2,
199,
199,
533,
1379,
2610,
5355,
18477,
8,
396,
63,
1208,
14,
2208,
16610,
3120,
1746,
304,
272,
347,
511,
63,
4316,
63,
10108,
8,
277,
304,
267,
291,
14,
5480,
17,
275,
2351,
14,
4434,
342,
267,
291,
14,
5480,
17,
14,
1180,
63,
1301,
360,
2246,
358,
267,
291,
14,
5480,
18,
275,
2351,
14,
4434,
342,
267,
291,
14,
5480,
18,
14,
1180,
63,
1301,
360,
4375,
358,
267,
327,
2242,
6771,
370,
849,
1301,
267,
327,
2242,
6771,
18,
370,
849,
1301,
267,
327,
2242,
6771,
19,
370,
849,
1301,
18,
267,
1642,
344,
275,
291,
14,
5480,
17,
14,
1301,
344,
267,
542,
388,
14887,
275,
291,
14,
5480,
18,
14,
1301,
344,
267,
1642,
1418,
275,
291,
14,
5480,
17,
14,
28181,
267,
3499,
1418,
275,
291,
14,
5480,
18,
14,
28181,
267,
492,
24897,
267,
6771,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
1642,
1418,
9,
267,
6771,
18,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
18,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
1642,
1418,
9,
398,
6771,
19,
275,
24897,
14,
18477,
342,
267,
4907,
8,
5096,
19,
12,
10900,
63,
1562,
12,
283,
656,
16610,
2798,
2689,
83,
7,
450,
542,
388,
14887,
12,
3499,
1418,
9,
267,
327,
1875,
3238,
6771,
436,
6771,
18,
9128,
1245,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
283,
5006,
10916,
267,
1499,
275,
6771,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
18,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
11213,
450,
1642,
344,
398,
327,
3222,
3788,
641,
499,
17398,
12,
1852,
3238,
626,
18772,
9128,
267,
327,
314,
2451,
3788,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
1642,
344,
12,
283,
5006,
18,
10916,
267,
25214,
63,
571,
14,
12789,
14,
2254,
360,
656,
16610,
2798,
2689,
83,
7,
450,
542,
388,
14887,
12,
283,
5006,
19,
10916,
267,
1499,
275,
6771,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
18,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
18,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
18,
11213,
450,
1642,
344,
267,
1499,
275,
6771,
19,
14,
7637,
342,
267,
702,
1499,
508,
283,
656,
16610,
2798,
2689,
83,
26,
5006,
19,
11213,
450,
542,
388,
14887,
199,
199,
318,
4907,
8,
5096,
12,
5552,
12,
7482,
12,
1790,
304,
272,
327,
3254,
334,
1235,
86,
9,
22255,
2653,
7037,
370,
18648,
12643,
5068,
3553,
2295,
272,
327,
315,
27174,
323,
340,
642,
365,
314,
3363,
8744,
503,
340,
2337,
365,
282,
272,
327,
477,
15033,
5160,
272,
6771,
14,
2593,
275,
841,
14,
16,
272,
6771,
14,
2242,
8,
2697,
9,
272,
1499,
1113,
275,
1211,
8,
1328,
466,
534,
10108,
297,
2116,
7482,
29,
5746,
12,
2116,
1790,
29,
1178,
2116,
776,
272,
6771,
14,
2254,
8,
3922,
14,
3549,
63,
1001,
8,
28048,
430,
272,
1499,
275,
6771,
14,
7637,
342,
272,
1499,
275,
1499,
14,
1294,
480,
6783,
499,
15786,
17,
61,
272,
1499,
1113,
275,
4113,
14,
11143,
63,
1001,
8,
1328,
9,
272,
702,
1499,
1113,
459,
1205,
418,
1491,
18,
61,
508,
788,
954,
729,
11562,
1992,
297,
7482,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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