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
sequencelengths 1.02k
1.02k
| labels
sequencelengths 1.02k
1.02k
| attention_mask
sequencelengths 1.02k
1.02k
|
---|---|---|---|---|---|---|---|---|
132nd-etcher/EMFT | emft/gui/tab_about.py | 1 | 1269 | # coding=utf-8
from emft.core import constant
from emft.core.logging import make_logger
from emft.gui.base import GridLayout, HSpacer, Label, VLayout, VSpacer
from emft.gui.main_ui_tab_widget import MainUiTabChild
LOGGER = make_logger(__name__)
class TabChildAbout(MainUiTabChild):
def tab_clicked(self):
pass
@property
def tab_title(self) -> str:
return 'About'
def __init__(self, parent=None):
super(TabChildAbout, self).__init__(parent)
repo_label = Label(
'''<a href='{link}'>{link}</a>'''.format(link=constant.LINK_REPO)
)
repo_label.setOpenExternalLinks(True)
changelog_label = Label(
'''<a href='{link}'>{link}</a>'''.format(link=constant.LINK_CHANGELOG)
)
changelog_label.setOpenExternalLinks(True)
self.setLayout(
VLayout(
[
GridLayout(
[
[Label('Github repository: '), repo_label, HSpacer()],
[Label('Changelog: '), changelog_label, HSpacer()],
],
[0, 0, 1]
),
VSpacer(),
]
)
)
| gpl-3.0 | [
3,
2803,
29,
1624,
13,
24,
199,
199,
504,
18564,
856,
14,
1018,
492,
4413,
199,
504,
18564,
856,
14,
1018,
14,
4806,
492,
1852,
63,
2921,
199,
504,
18564,
856,
14,
5885,
14,
1095,
492,
16386,
4798,
12,
869,
12739,
2247,
12,
10354,
12,
812,
4798,
12,
812,
12739,
2247,
199,
504,
18564,
856,
14,
5885,
14,
973,
63,
1907,
63,
2902,
63,
3440,
492,
11298,
18203,
7690,
3493,
199,
199,
10186,
275,
1852,
63,
2921,
3460,
354,
3368,
421,
199,
533,
23159,
3493,
18816,
8,
6756,
18203,
7690,
3493,
304,
272,
347,
5174,
63,
11276,
8,
277,
304,
267,
986,
339,
768,
1829,
272,
347,
5174,
63,
1213,
8,
277,
9,
1035,
620,
26,
267,
372,
283,
18816,
7,
339,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
8,
7690,
3493,
18816,
12,
291,
2843,
826,
721,
1708,
9,
398,
3831,
63,
1302,
275,
10354,
8,
288,
28827,
65,
4369,
32134,
1073,
6834,
22266,
1073,
17890,
65,
30,
891,
1370,
908,
8,
1073,
29,
4083,
14,
7916,
63,
20424,
9,
267,
776,
267,
3831,
63,
1302,
14,
409,
4299,
11389,
16974,
8,
549,
9,
398,
1570,
793,
63,
1302,
275,
10354,
8,
288,
28827,
65,
4369,
32134,
1073,
6834,
22266,
1073,
17890,
65,
30,
891,
1370,
908,
8,
1073,
29,
4083,
14,
7916,
63,
16062,
4947,
9,
267,
776,
267,
1570,
793,
63,
1302,
14,
409,
4299,
11389,
16974,
8,
549,
9,
398,
291,
14,
409,
4798,
8,
288,
812,
4798,
8,
355,
359,
490,
16386,
4798,
8,
717,
359,
1169,
359,
4314,
360,
14772,
7611,
26,
17748,
3831,
63,
1302,
12,
869,
12739,
2247,
15618,
1169,
359,
4314,
360,
4001,
793,
26,
17748,
1570,
793,
63,
1302,
12,
869,
12739,
2247,
15618,
717,
2156,
717,
359,
16,
12,
378,
12,
413,
61,
490,
2318,
490,
812,
12739,
2247,
1062,
355,
1622,
288,
776,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
504,
18564,
856,
14,
1018,
492,
4413,
199,
504,
18564,
856,
14,
1018,
14,
4806,
492,
1852,
63,
2921,
199,
504,
18564,
856,
14,
5885,
14,
1095,
492,
16386,
4798,
12,
869,
12739,
2247,
12,
10354,
12,
812,
4798,
12,
812,
12739,
2247,
199,
504,
18564,
856,
14,
5885,
14,
973,
63,
1907,
63,
2902,
63,
3440,
492,
11298,
18203,
7690,
3493,
199,
199,
10186,
275,
1852,
63,
2921,
3460,
354,
3368,
421,
199,
533,
23159,
3493,
18816,
8,
6756,
18203,
7690,
3493,
304,
272,
347,
5174,
63,
11276,
8,
277,
304,
267,
986,
339,
768,
1829,
272,
347,
5174,
63,
1213,
8,
277,
9,
1035,
620,
26,
267,
372,
283,
18816,
7,
339,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
8,
7690,
3493,
18816,
12,
291,
2843,
826,
721,
1708,
9,
398,
3831,
63,
1302,
275,
10354,
8,
288,
28827,
65,
4369,
32134,
1073,
6834,
22266,
1073,
17890,
65,
30,
891,
1370,
908,
8,
1073,
29,
4083,
14,
7916,
63,
20424,
9,
267,
776,
267,
3831,
63,
1302,
14,
409,
4299,
11389,
16974,
8,
549,
9,
398,
1570,
793,
63,
1302,
275,
10354,
8,
288,
28827,
65,
4369,
32134,
1073,
6834,
22266,
1073,
17890,
65,
30,
891,
1370,
908,
8,
1073,
29,
4083,
14,
7916,
63,
16062,
4947,
9,
267,
776,
267,
1570,
793,
63,
1302,
14,
409,
4299,
11389,
16974,
8,
549,
9,
398,
291,
14,
409,
4798,
8,
288,
812,
4798,
8,
355,
359,
490,
16386,
4798,
8,
717,
359,
1169,
359,
4314,
360,
14772,
7611,
26,
17748,
3831,
63,
1302,
12,
869,
12739,
2247,
15618,
1169,
359,
4314,
360,
4001,
793,
26,
17748,
1570,
793,
63,
1302,
12,
869,
12739,
2247,
15618,
717,
2156,
717,
359,
16,
12,
378,
12,
413,
61,
490,
2318,
490,
812,
12739,
2247,
1062,
355,
1622,
288,
776,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
jfinkels/networkx | networkx/readwrite/graph6.py | 3 | 7803 | # Original author: D. Eppstein, UC Irvine, August 12, 2003.
# The original code at http://www.ics.uci.edu/~eppstein/PADS/ is public domain.
# Copyright (C) 2004-2016 by
# Aric Hagberg <hagberg@lanl.gov>
# Dan Schult <dschult@colgate.edu>
# Pieter Swart <swart@lanl.gov>
# Tomas Gavenciak <gavento@ucw.cz>
# All rights reserved.
# BSD license.
#
# Authors: Tomas Gavenciak <gavento@ucw.cz>
# Aric Hagberg <aric.hagberg@lanl.gov>
"""Functions for reading and writing graphs in the *graph6* format.
The *graph6* file format is suitable for small graphs or large dense
graphs. For large sparse graphs, use the *sparse6* format.
For more information, see the `graph6`_ homepage.
.. _graph6: http://users.cecs.anu.edu.au/~bdm/data/formats.html
"""
import networkx as nx
from networkx.exception import NetworkXError
from networkx.utils import open_file, not_implemented_for
__all__ = ['read_graph6', 'parse_graph6', 'generate_graph6', 'write_graph6']
def parse_graph6(string):
"""Read a simple undirected graph in graph6 format from string.
Parameters
----------
string : string
Data in graph6 format
Returns
-------
G : Graph
Raises
------
NetworkXError
If the string is unable to be parsed in graph6 format
Examples
--------
>>> G = nx.parse_graph6('A_')
>>> sorted(G.edges())
[(0, 1)]
See Also
--------
generate_graph6, read_graph6, write_graph6
References
----------
.. [1] Graph6 specification
<http://users.cecs.anu.edu.au/~bdm/data/formats.html>
"""
def bits():
"""Return sequence of individual bits from 6-bit-per-value
list of data values."""
for d in data:
for i in [5,4,3,2,1,0]:
yield (d>>i)&1
if string.startswith('>>graph6<<'):
string = string[10:]
data = graph6_to_data(string)
n, data = data_to_n(data)
nd = (n*(n-1)//2 + 5) // 6
if len(data) != nd:
raise NetworkXError(\
'Expected %d bits but got %d in graph6' % (n*(n-1)//2, len(data)*6))
G=nx.Graph()
G.add_nodes_from(range(n))
for (i,j),b in zip([(i,j) for j in range(1,n) for i in range(j)], bits()):
if b:
G.add_edge(i,j)
return G
@open_file(0,mode='rt')
def read_graph6(path):
"""Read simple undirected graphs in graph6 format from path.
Parameters
----------
path : file or string
File or filename to write.
Returns
-------
G : Graph or list of Graphs
If the file contains multiple lines then a list of graphs is returned
Raises
------
NetworkXError
If the string is unable to be parsed in graph6 format
Examples
--------
>>> nx.write_graph6(nx.Graph([(0,1)]), 'test.g6')
>>> G = nx.read_graph6('test.g6')
>>> sorted(G.edges())
[(0, 1)]
See Also
--------
generate_graph6, parse_graph6, write_graph6
References
----------
.. [1] Graph6 specification
<http://users.cecs.anu.edu.au/~bdm/data/formats.html>
"""
glist = []
for line in path:
line = line.strip()
if not len(line):
continue
glist.append(parse_graph6(line))
if len(glist) == 1:
return glist[0]
else:
return glist
@not_implemented_for('directed','multigraph')
def generate_graph6(G, nodes = None, header=True):
"""Generate graph6 format string from a simple undirected graph.
Parameters
----------
G : Graph (undirected)
nodes: list or iterable
Nodes are labeled 0...n-1 in the order provided. If None the ordering
given by G.nodes() is used.
header: bool
If True add '>>graph6<<' string to head of data
Returns
-------
s : string
String in graph6 format
Raises
------
NetworkXError
If the graph is directed or has parallel edges
Examples
--------
>>> G = nx.Graph([(0, 1)])
>>> nx.generate_graph6(G)
'>>graph6<<A_'
See Also
--------
read_graph6, parse_graph6, write_graph6
Notes
-----
The format does not support edge or node labels, parallel edges or
self loops. If self loops are present they are silently ignored.
References
----------
.. [1] Graph6 specification
<http://users.cecs.anu.edu.au/~bdm/data/formats.html>
"""
if nodes is not None:
G = G.subgraph(nodes)
H = nx.convert_node_labels_to_integers(G)
ns = sorted(H.nodes())
def bits():
for (i,j) in [(i,j) for j in range(1,n) for i in range(j)]:
yield G.has_edge(ns[i],ns[j])
n = G.order()
data = n_to_data(n)
d = 0
flush = False
for i, b in zip(range(n * n), bits()):
d |= b << (5 - (i % 6))
flush = True
if i % 6 == 5:
data.append(d)
d = 0
flush = False
if flush:
data.append(d)
string_data = data_to_graph6(data)
if header:
string_data = '>>graph6<<' + string_data
return string_data
@open_file(1, mode='wt')
def write_graph6(G, path, nodes = None, header=True):
"""Write a simple undirected graph to path in graph6 format.
Parameters
----------
G : Graph (undirected)
path : file or string
File or filename to write.
nodes: list or iterable
Nodes are labeled 0...n-1 in the order provided. If None the ordering
given by G.nodes() is used.
header: bool
If True add '>>graph6<<' string to head of data
Raises
------
NetworkXError
If the graph is directed or has parallel edges
Examples
--------
>>> G = nx.Graph([(0, 1)])
>>> nx.write_graph6(G, 'test.g6')
See Also
--------
generate_graph6, parse_graph6, read_graph6
Notes
-----
The format does not support edge or node labels, parallel edges or
self loops. If self loops are present they are silently ignored.
References
----------
.. [1] Graph6 specification
<http://users.cecs.anu.edu.au/~bdm/data/formats.html>
"""
path.write(generate_graph6(G, nodes=nodes, header=header))
path.write('\n')
# helper functions
def graph6_to_data(string):
"""Convert graph6 character sequence to 6-bit integers."""
v = [ord(c)-63 for c in string]
if len(v) > 0 and (min(v) < 0 or max(v) > 63):
return None
return v
def data_to_graph6(data):
"""Convert 6-bit integer sequence to graph6 character sequence."""
if len(data) > 0 and (min(data) < 0 or max(data) > 63):
raise NetworkXError("graph6 data units must be within 0..63")
return ''.join([chr(d+63) for d in data])
def data_to_n(data):
"""Read initial one-, four- or eight-unit value from graph6
integer sequence.
Return (value, rest of seq.)"""
if data[0] <= 62:
return data[0], data[1:]
if data[1] <= 62:
return (data[1]<<12) + (data[2]<<6) + data[3], data[4:]
return ((data[2]<<30) + (data[3]<<24) + (data[4]<<18) +
(data[5]<<12) + (data[6]<<6) + data[7], data[8:])
def n_to_data(n):
"""Convert an integer to one-, four- or eight-unit graph6 sequence."""
if n < 0:
raise NetworkXError("Numbers in graph6 format must be non-negative.")
if n <= 62:
return [n]
if n <= 258047:
return [63, (n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f]
if n <= 68719476735:
return [63, 63,
(n>>30) & 0x3f, (n>>24) & 0x3f, (n>>18) & 0x3f,
(n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f]
raise NetworkXError("Numbers above 68719476735 are not supported by graph6")
def teardown_module(module):
import os
if os.path.isfile('test.g6'):
os.unlink('test.g6')
| bsd-3-clause | [
3,
12769,
4132,
26,
577,
14,
662,
802,
1597,
262,
12,
738,
35,
473,
6310,
1132,
12,
25298,
833,
3144,
12,
13004,
14,
199,
3,
710,
3379,
1233,
737,
1455,
921,
1544,
14,
2932,
14,
85,
559,
14,
8654,
22500,
69,
802,
1597,
262,
15,
32420,
51,
15,
365,
4575,
2881,
14,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
9261,
701,
199,
3,
259,
437,
1567,
869,
643,
14630,
665,
72,
643,
14630,
32,
1502,
76,
14,
16294,
30,
199,
3,
259,
24747,
22985,
427,
665,
795,
335,
427,
32,
761,
3237,
14,
8654,
30,
199,
3,
259,
510,
1873,
351,
16666,
580,
665,
3519,
580,
32,
1502,
76,
14,
16294,
30,
199,
3,
259,
21644,
305,
598,
15556,
559,
1151,
665,
71,
15556,
475,
32,
947,
87,
14,
16823,
30,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
259,
6289,
4190,
14,
199,
3,
199,
3,
6642,
26,
21644,
305,
598,
15556,
559,
1151,
665,
71,
15556,
475,
32,
947,
87,
14,
16823,
30,
199,
3,
3515,
437,
1567,
869,
643,
14630,
665,
285,
530,
14,
72,
643,
14630,
32,
1502,
76,
14,
16294,
30,
199,
624,
13967,
367,
7664,
436,
3575,
18312,
315,
314,
627,
2180,
22,
10,
1475,
14,
199,
199,
1918,
627,
2180,
22,
10,
570,
1475,
365,
11233,
367,
7425,
18312,
503,
7031,
9363,
199,
16670,
14,
2104,
7031,
5178,
18312,
12,
675,
314,
627,
4421,
22,
10,
1475,
14,
199,
199,
1858,
1655,
2556,
12,
1937,
314,
658,
2180,
22,
18417,
26586,
14,
199,
199,
703,
485,
2180,
22,
26,
1455,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
199,
199,
624,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
1971,
492,
7220,
29356,
199,
504,
24313,
14,
1208,
492,
1551,
63,
493,
12,
440,
63,
13825,
63,
509,
199,
199,
363,
452,
363,
275,
788,
739,
63,
2180,
22,
297,
283,
1122,
63,
2180,
22,
297,
283,
4208,
63,
2180,
22,
297,
283,
952,
63,
2180,
22,
418,
421,
199,
318,
2198,
63,
2180,
22,
8,
875,
304,
272,
408,
3284,
282,
3486,
625,
12080,
3343,
315,
3343,
22,
1475,
687,
1059,
14,
339,
3897,
272,
4143,
272,
1059,
520,
1059,
2126,
3918,
315,
3343,
22,
1475,
339,
1803,
272,
5514,
272,
598,
520,
11513,
339,
6218,
272,
21397,
272,
7220,
29356,
267,
982,
314,
1059,
365,
17329,
370,
506,
4565,
315,
3343,
22,
1475,
339,
6058,
272,
3001,
272,
1306,
598,
275,
8484,
14,
1122,
63,
2180,
22,
360,
33,
15452,
272,
1306,
3355,
8,
39,
14,
6929,
1012,
272,
3842,
16,
12,
413,
1874,
339,
1666,
6121,
272,
3001,
272,
3550,
63,
2180,
22,
12,
1586,
63,
2180,
22,
12,
2218,
63,
2180,
22,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
11513,
22,
8929,
1779,
665,
1014,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
30,
339,
408,
272,
347,
5821,
837,
267,
408,
1767,
3414,
402,
8212,
5821,
687,
1227,
13,
2075,
13,
529,
13,
585,
267,
769,
402,
666,
1338,
1041,
267,
367,
366,
315,
666,
26,
288,
367,
284,
315,
359,
21,
12,
20,
12,
19,
12,
18,
12,
17,
12,
16,
2189,
355,
1995,
334,
68,
1140,
73,
9,
6,
17,
339,
340,
1059,
14,
2460,
360,
1140,
2180,
22,
8999,
735,
267,
1059,
275,
1059,
59,
709,
2938,
272,
666,
275,
3343,
22,
63,
475,
63,
576,
8,
875,
9,
272,
302,
12,
666,
275,
666,
63,
475,
63,
78,
8,
576,
9,
272,
5222,
275,
334,
78,
5830,
78,
13,
17,
28428,
18,
435,
959,
9,
5001,
1227,
272,
340,
822,
8,
576,
9,
1137,
5222,
26,
267,
746,
7220,
29356,
2961,
288,
283,
6964,
450,
68,
5821,
1325,
4788,
450,
68,
315,
3343,
22,
7,
450,
334,
78,
5830,
78,
13,
17,
28428,
18,
12,
822,
8,
576,
3342,
22,
430,
339,
598,
29,
7343,
14,
4578,
342,
272,
598,
14,
525,
63,
2415,
63,
504,
8,
1842,
8,
78,
430,
272,
367,
334,
73,
12,
74,
395,
66,
315,
3482,
7694,
73,
12,
74,
9,
367,
1335,
315,
1425,
8,
17,
12,
78,
9,
367,
284,
315,
1425,
8,
74,
4360,
5821,
5109,
267,
340,
330,
26,
288,
598,
14,
525,
63,
5173,
8,
73,
12,
74,
9,
339,
372,
598,
199,
199,
32,
1490,
63,
493,
8,
16,
12,
632,
534,
2591,
358,
199,
318,
1586,
63,
2180,
22,
8,
515,
304,
272,
408,
3284,
3486,
625,
12080,
18312,
315,
3343,
22,
1475,
687,
931,
14,
339,
3897,
272,
4143,
272,
931,
520,
570,
503,
1059,
2126,
3814,
503,
1788,
370,
2218,
14,
339,
1803,
272,
5514,
272,
598,
520,
11513,
503,
769,
402,
11513,
83,
2126,
982,
314,
570,
3509,
3663,
2385,
2066,
282,
769,
402,
18312,
365,
2138,
339,
6218,
272,
21397,
272,
7220,
29356,
267,
982,
314,
1059,
365,
17329,
370,
506,
4565,
315,
3343,
22,
1475,
339,
6058,
272,
3001,
272,
1306,
8484,
14,
952,
63,
2180,
22,
8,
7343,
14,
4578,
7694,
16,
12,
17,
16636,
283,
396,
14,
71,
22,
358,
272,
1306,
598,
275,
8484,
14,
739,
63,
2180,
22,
360,
396,
14,
71,
22,
358,
272,
1306,
3355,
8,
39,
14,
6929,
1012,
272,
3842,
16,
12,
413,
1874,
339,
1666,
6121,
272,
3001,
272,
3550,
63,
2180,
22,
12,
2198,
63,
2180,
22,
12,
2218,
63,
2180,
22,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
11513,
22,
8929,
1779,
665,
1014,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
30,
339,
408,
272,
486,
513,
275,
942,
272,
367,
1004,
315,
931,
26,
267,
1004,
275,
1004,
14,
1913,
342,
267,
340,
440,
822,
8,
604,
304,
288,
1980,
267,
486,
513,
14,
740,
8,
1122,
63,
2180,
22,
8,
604,
430,
272,
340,
822,
8,
71,
513,
9,
508,
413,
26,
267,
372,
486,
513,
59,
16,
61,
272,
587,
26,
267,
372,
486,
513,
199,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
1673,
3029,
2180,
358,
199,
318,
3550
] | [
12769,
4132,
26,
577,
14,
662,
802,
1597,
262,
12,
738,
35,
473,
6310,
1132,
12,
25298,
833,
3144,
12,
13004,
14,
199,
3,
710,
3379,
1233,
737,
1455,
921,
1544,
14,
2932,
14,
85,
559,
14,
8654,
22500,
69,
802,
1597,
262,
15,
32420,
51,
15,
365,
4575,
2881,
14,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
9261,
701,
199,
3,
259,
437,
1567,
869,
643,
14630,
665,
72,
643,
14630,
32,
1502,
76,
14,
16294,
30,
199,
3,
259,
24747,
22985,
427,
665,
795,
335,
427,
32,
761,
3237,
14,
8654,
30,
199,
3,
259,
510,
1873,
351,
16666,
580,
665,
3519,
580,
32,
1502,
76,
14,
16294,
30,
199,
3,
259,
21644,
305,
598,
15556,
559,
1151,
665,
71,
15556,
475,
32,
947,
87,
14,
16823,
30,
199,
3,
259,
2900,
4481,
4644,
14,
199,
3,
259,
6289,
4190,
14,
199,
3,
199,
3,
6642,
26,
21644,
305,
598,
15556,
559,
1151,
665,
71,
15556,
475,
32,
947,
87,
14,
16823,
30,
199,
3,
3515,
437,
1567,
869,
643,
14630,
665,
285,
530,
14,
72,
643,
14630,
32,
1502,
76,
14,
16294,
30,
199,
624,
13967,
367,
7664,
436,
3575,
18312,
315,
314,
627,
2180,
22,
10,
1475,
14,
199,
199,
1918,
627,
2180,
22,
10,
570,
1475,
365,
11233,
367,
7425,
18312,
503,
7031,
9363,
199,
16670,
14,
2104,
7031,
5178,
18312,
12,
675,
314,
627,
4421,
22,
10,
1475,
14,
199,
199,
1858,
1655,
2556,
12,
1937,
314,
658,
2180,
22,
18417,
26586,
14,
199,
199,
703,
485,
2180,
22,
26,
1455,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
199,
199,
624,
199,
646,
24313,
465,
8484,
199,
504,
24313,
14,
1971,
492,
7220,
29356,
199,
504,
24313,
14,
1208,
492,
1551,
63,
493,
12,
440,
63,
13825,
63,
509,
199,
199,
363,
452,
363,
275,
788,
739,
63,
2180,
22,
297,
283,
1122,
63,
2180,
22,
297,
283,
4208,
63,
2180,
22,
297,
283,
952,
63,
2180,
22,
418,
421,
199,
318,
2198,
63,
2180,
22,
8,
875,
304,
272,
408,
3284,
282,
3486,
625,
12080,
3343,
315,
3343,
22,
1475,
687,
1059,
14,
339,
3897,
272,
4143,
272,
1059,
520,
1059,
2126,
3918,
315,
3343,
22,
1475,
339,
1803,
272,
5514,
272,
598,
520,
11513,
339,
6218,
272,
21397,
272,
7220,
29356,
267,
982,
314,
1059,
365,
17329,
370,
506,
4565,
315,
3343,
22,
1475,
339,
6058,
272,
3001,
272,
1306,
598,
275,
8484,
14,
1122,
63,
2180,
22,
360,
33,
15452,
272,
1306,
3355,
8,
39,
14,
6929,
1012,
272,
3842,
16,
12,
413,
1874,
339,
1666,
6121,
272,
3001,
272,
3550,
63,
2180,
22,
12,
1586,
63,
2180,
22,
12,
2218,
63,
2180,
22,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
11513,
22,
8929,
1779,
665,
1014,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
30,
339,
408,
272,
347,
5821,
837,
267,
408,
1767,
3414,
402,
8212,
5821,
687,
1227,
13,
2075,
13,
529,
13,
585,
267,
769,
402,
666,
1338,
1041,
267,
367,
366,
315,
666,
26,
288,
367,
284,
315,
359,
21,
12,
20,
12,
19,
12,
18,
12,
17,
12,
16,
2189,
355,
1995,
334,
68,
1140,
73,
9,
6,
17,
339,
340,
1059,
14,
2460,
360,
1140,
2180,
22,
8999,
735,
267,
1059,
275,
1059,
59,
709,
2938,
272,
666,
275,
3343,
22,
63,
475,
63,
576,
8,
875,
9,
272,
302,
12,
666,
275,
666,
63,
475,
63,
78,
8,
576,
9,
272,
5222,
275,
334,
78,
5830,
78,
13,
17,
28428,
18,
435,
959,
9,
5001,
1227,
272,
340,
822,
8,
576,
9,
1137,
5222,
26,
267,
746,
7220,
29356,
2961,
288,
283,
6964,
450,
68,
5821,
1325,
4788,
450,
68,
315,
3343,
22,
7,
450,
334,
78,
5830,
78,
13,
17,
28428,
18,
12,
822,
8,
576,
3342,
22,
430,
339,
598,
29,
7343,
14,
4578,
342,
272,
598,
14,
525,
63,
2415,
63,
504,
8,
1842,
8,
78,
430,
272,
367,
334,
73,
12,
74,
395,
66,
315,
3482,
7694,
73,
12,
74,
9,
367,
1335,
315,
1425,
8,
17,
12,
78,
9,
367,
284,
315,
1425,
8,
74,
4360,
5821,
5109,
267,
340,
330,
26,
288,
598,
14,
525,
63,
5173,
8,
73,
12,
74,
9,
339,
372,
598,
199,
199,
32,
1490,
63,
493,
8,
16,
12,
632,
534,
2591,
358,
199,
318,
1586,
63,
2180,
22,
8,
515,
304,
272,
408,
3284,
3486,
625,
12080,
18312,
315,
3343,
22,
1475,
687,
931,
14,
339,
3897,
272,
4143,
272,
931,
520,
570,
503,
1059,
2126,
3814,
503,
1788,
370,
2218,
14,
339,
1803,
272,
5514,
272,
598,
520,
11513,
503,
769,
402,
11513,
83,
2126,
982,
314,
570,
3509,
3663,
2385,
2066,
282,
769,
402,
18312,
365,
2138,
339,
6218,
272,
21397,
272,
7220,
29356,
267,
982,
314,
1059,
365,
17329,
370,
506,
4565,
315,
3343,
22,
1475,
339,
6058,
272,
3001,
272,
1306,
8484,
14,
952,
63,
2180,
22,
8,
7343,
14,
4578,
7694,
16,
12,
17,
16636,
283,
396,
14,
71,
22,
358,
272,
1306,
598,
275,
8484,
14,
739,
63,
2180,
22,
360,
396,
14,
71,
22,
358,
272,
1306,
3355,
8,
39,
14,
6929,
1012,
272,
3842,
16,
12,
413,
1874,
339,
1666,
6121,
272,
3001,
272,
3550,
63,
2180,
22,
12,
2198,
63,
2180,
22,
12,
2218,
63,
2180,
22,
339,
14504,
272,
4143,
272,
2508,
359,
17,
61,
11513,
22,
8929,
1779,
665,
1014,
921,
3707,
14,
301,
1259,
14,
290,
85,
14,
8654,
14,
3844,
22500,
21520,
15,
576,
15,
6321,
14,
1360,
30,
339,
408,
272,
486,
513,
275,
942,
272,
367,
1004,
315,
931,
26,
267,
1004,
275,
1004,
14,
1913,
342,
267,
340,
440,
822,
8,
604,
304,
288,
1980,
267,
486,
513,
14,
740,
8,
1122,
63,
2180,
22,
8,
604,
430,
272,
340,
822,
8,
71,
513,
9,
508,
413,
26,
267,
372,
486,
513,
59,
16,
61,
272,
587,
26,
267,
372,
486,
513,
199,
199,
32,
1397,
63,
13825,
63,
509,
360,
12080,
1673,
3029,
2180,
358,
199,
318,
3550,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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.
""" Lexer for PPAPI IDL """
#
# IDL Lexer
#
# The lexer is uses the PLY lex library to build a tokenizer which understands
# WebIDL tokens.
#
# WebIDL, and WebIDL regular expressions can be found at:
# http://dev.w3.org/2006/webapi/WebIDL/
# PLY can be found at:
# http://www.dabeaz.com/ply/
import os.path
import re
import sys
#
# Try to load the ply module, if not, then assume it is in the third_party
# directory, relative to ppapi
#
try:
from ply import lex
except:
module_path, module_name = os.path.split(__file__)
third_party = os.path.join(module_path, '..', '..', 'third_party')
sys.path.append(third_party)
from ply import lex
from idl_option import GetOption, Option, ParseOptions
Option('output', 'Generate output.')
#
# IDL Lexer
#
class IDLLexer(object):
# 'tokens' is a value required by lex which specifies the complete list
# of valid token types.
tokens = [
# Symbol and keywords types
'COMMENT',
'DESCRIBE',
'ENUM',
'LABEL',
'SYMBOL',
'INLINE',
'INTERFACE',
'STRUCT',
'TYPEDEF',
# Extra WebIDL keywords
'CALLBACK',
'DICTIONARY',
'OPTIONAL',
'STATIC',
# Invented for apps use
'NAMESPACE',
# Data types
'FLOAT',
'OCT',
'INT',
'HEX',
'STRING',
# Operators
'LSHIFT',
'RSHIFT'
]
# 'keywords' is a map of string to token type. All SYMBOL tokens are
# matched against keywords, to determine if the token is actually a keyword.
keywords = {
'describe' : 'DESCRIBE',
'enum' : 'ENUM',
'label' : 'LABEL',
'interface' : 'INTERFACE',
'readonly' : 'READONLY',
'struct' : 'STRUCT',
'typedef' : 'TYPEDEF',
'callback' : 'CALLBACK',
'dictionary' : 'DICTIONARY',
'optional' : 'OPTIONAL',
'static' : 'STATIC',
'namespace' : 'NAMESPACE',
}
# 'literals' is a value expected by lex which specifies a list of valid
# literal tokens, meaning the token type and token value are identical.
literals = '"*.(){}[],;:=+-/~|&^?'
# Token definitions
#
# Lex assumes any value or function in the form of 't_<TYPE>' represents a
# regular expression where a match will emit a token of type <TYPE>. In the
# case of a function, the function is called when a match is made. These
# definitions come from WebIDL.
# 't_ignore' is a special match of items to ignore
t_ignore = ' \t'
# Constant values
t_FLOAT = r'-?(\d+\.\d*|\d*\.\d+)([Ee][+-]?\d+)?|-?\d+[Ee][+-]?\d+'
t_INT = r'-?[0-9]+[uU]?'
t_OCT = r'-?0[0-7]+'
t_HEX = r'-?0[Xx][0-9A-Fa-f]+'
t_LSHIFT = r'<<'
t_RSHIFT = r'>>'
# A line ending '\n', we use this to increment the line number
def t_LINE_END(self, t):
r'\n+'
self.AddLines(len(t.value))
# We do not process escapes in the IDL strings. Strings are exclusively
# used for attributes, and not used as typical 'C' constants.
def t_STRING(self, t):
r'"[^"]*"'
t.value = t.value[1:-1]
self.AddLines(t.value.count('\n'))
return t
# A C or C++ style comment: /* xxx */ or //
def t_COMMENT(self, t):
r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)'
self.AddLines(t.value.count('\n'))
return t
# Return a "preprocessor" inline block
def t_INLINE(self, t):
r'\#inline (.|\n)*?\#endinl.*'
self.AddLines(t.value.count('\n'))
return t
# A symbol or keyword.
def t_KEYWORD_SYMBOL(self, t):
r'_?[A-Za-z][A-Za-z_0-9]*'
# All non-keywords are assumed to be symbols
t.type = self.keywords.get(t.value, 'SYMBOL')
# We strip leading underscores so that you can specify symbols with the same
# value as a keywords (E.g. a dictionary named 'interface').
if t.value[0] == '_':
t.value = t.value[1:]
return t
def t_ANY_error(self, t):
msg = "Unrecognized input"
line = self.lexobj.lineno
# If that line has not been accounted for, then we must have hit
# EoF, so compute the beginning of the line that caused the problem.
if line >= len(self.index):
# Find the offset in the line of the first word causing the issue
word = t.value.split()[0]
offs = self.lines[line - 1].find(word)
# Add the computed line's starting position
self.index.append(self.lexobj.lexpos - offs)
msg = "Unexpected EoF reached after"
pos = self.lexobj.lexpos - self.index[line]
file = self.lexobj.filename
out = self.ErrorMessage(file, line, pos, msg)
sys.stderr.write(out + '\n')
self.lex_errors += 1
def AddLines(self, count):
# Set the lexer position for the beginning of the next line. In the case
# of multiple lines, tokens can not exist on any of the lines except the
# last one, so the recorded value for previous lines are unused. We still
# fill the array however, to make sure the line count is correct.
self.lexobj.lineno += count
for i in range(count):
self.index.append(self.lexobj.lexpos)
def FileLineMsg(self, file, line, msg):
if file: return "%s(%d) : %s" % (file, line + 1, msg)
return "<BuiltIn> : %s" % msg
def SourceLine(self, file, line, pos):
caret = '\t^'.expandtabs(pos)
# We decrement the line number since the array is 0 based while the
# line numbers are 1 based.
return "%s\n%s" % (self.lines[line - 1], caret)
def ErrorMessage(self, file, line, pos, msg):
return "\n%s\n%s" % (
self.FileLineMsg(file, line, msg),
self.SourceLine(file, line, pos))
def SetData(self, filename, data):
# Start with line 1, not zero
self.lexobj.lineno = 1
self.lexobj.filename = filename
self.lines = data.split('\n')
self.index = [0]
self.lexobj.input(data)
self.lex_errors = 0
def __init__(self):
self.lexobj = lex.lex(object=self, lextab=None, optimize=0)
#
# FilesToTokens
#
# From a set of source file names, generate a list of tokens.
#
def FilesToTokens(filenames, verbose=False):
lexer = IDLLexer()
outlist = []
for filename in filenames:
data = open(filename).read()
lexer.SetData(filename, data)
if verbose: sys.stdout.write(' Loaded %s...\n' % filename)
while 1:
t = lexer.lexobj.token()
if t is None: break
outlist.append(t)
return outlist
def TokensFromText(text):
lexer = IDLLexer()
lexer.SetData('unknown', text)
outlist = []
while 1:
t = lexer.lexobj.token()
if t is None: break
outlist.append(t.value)
return outlist
#
# TextToTokens
#
# From a block of text, generate a list of tokens
#
def TextToTokens(source):
lexer = IDLLexer()
outlist = []
lexer.SetData('AUTO', source)
while 1:
t = lexer.lexobj.token()
if t is None: break
outlist.append(t.value)
return outlist
#
# TestSame
#
# From a set of token values, generate a new source text by joining with a
# single space. The new source is then tokenized and compared against the
# old set.
#
def TestSame(values1):
# Recreate the source from the tokens. We use newline instead of whitespace
# since the '//' and #inline regex are line sensitive.
text = '\n'.join(values1)
values2 = TextToTokens(text)
count1 = len(values1)
count2 = len(values2)
if count1 != count2:
print "Size mismatch original %d vs %d\n" % (count1, count2)
if count1 > count2: count1 = count2
for i in range(count1):
if values1[i] != values2[i]:
print "%d >>%s<< >>%s<<" % (i, values1[i], values2[i])
if GetOption('output'):
sys.stdout.write('Generating original.txt and tokenized.txt\n')
open('original.txt', 'w').write(src1)
open('tokenized.txt', 'w').write(src2)
if values1 == values2:
sys.stdout.write('Same: Pass\n')
return 0
print "****************\n%s\n%s***************\n" % (src1, src2)
sys.stdout.write('Same: Failed\n')
return -1
#
# TestExpect
#
# From a set of tokens pairs, verify the type field of the second matches
# the value of the first, so that:
# INT 123 FLOAT 1.1
# will generate a passing test, where the first token is the SYMBOL INT,
# and the second token is the INT 123, third token is the SYMBOL FLOAT and
# the fourth is the FLOAT 1.1, etc...
def TestExpect(tokens):
count = len(tokens)
index = 0
errors = 0
while index < count:
type = tokens[index].value
token = tokens[index + 1]
index += 2
if type != token.type:
sys.stderr.write('Mismatch: Expected %s, but got %s = %s.\n' %
(type, token.type, token.value))
errors += 1
if not errors:
sys.stdout.write('Expect: Pass\n')
return 0
sys.stdout.write('Expect: Failed\n')
return -1
def Main(args):
filenames = ParseOptions(args)
try:
tokens = FilesToTokens(filenames, GetOption('verbose'))
values = [tok.value for tok in tokens]
if GetOption('output'): sys.stdout.write(' <> '.join(values) + '\n')
if GetOption('test'):
if TestSame(values):
return -1
if TestExpect(tokens):
return -1
return 0
except lex.LexError as le:
sys.stderr.write('%s\n' % str(le))
return -1
if __name__ == '__main__':
sys.exit(Main(sys.argv[1:]))
| bsd-3-clause | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
21125,
367,
510,
48,
3735,
14575,
408,
199,
199,
3,
199,
3,
14575,
21125,
199,
3,
199,
3,
710,
10426,
365,
4440,
314,
510,
6084,
7103,
3555,
370,
1900,
282,
14803,
1314,
1334,
26580,
199,
3,
22817,
4645,
14,
199,
3,
199,
3,
22817,
12,
436,
22817,
5578,
8455,
883,
506,
1911,
737,
26,
199,
3,
257,
1455,
921,
2374,
14,
87,
19,
14,
1308,
15,
7968,
15,
2520,
1246,
15,
5926,
11505,
15,
199,
3,
510,
6084,
883,
506,
1911,
737,
26,
199,
3,
257,
1455,
921,
1544,
14,
68,
371,
4489,
90,
14,
957,
15,
19786,
15,
199,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
199,
3,
199,
3,
7649,
370,
2248,
314,
299,
590,
859,
12,
340,
440,
12,
2066,
5534,
652,
365,
315,
314,
10919,
63,
7522,
199,
3,
2082,
12,
3847,
370,
299,
387,
1038,
199,
3,
199,
893,
26,
523,
687,
299,
590,
492,
7103,
199,
2590,
26,
523,
859,
63,
515,
12,
859,
63,
354,
275,
747,
14,
515,
14,
1294,
3460,
493,
3368,
523,
10919,
63,
7522,
275,
747,
14,
515,
14,
904,
8,
578,
63,
515,
12,
19155,
19155,
283,
11470,
63,
7522,
358,
523,
984,
14,
515,
14,
740,
8,
11470,
63,
7522,
9,
523,
687,
299,
590,
492,
7103,
199,
199,
504,
20365,
63,
1422,
492,
2372,
2602,
12,
3207,
12,
6077,
4558,
421,
199,
2602,
360,
1199,
297,
283,
6864,
1072,
2659,
199,
199,
3,
199,
3,
14575,
21125,
199,
3,
199,
533,
2870,
4464,
5273,
8,
785,
304,
523,
327,
283,
4504,
7,
365,
282,
574,
1415,
701,
7103,
1314,
9314,
314,
4890,
769,
523,
327,
402,
1686,
1526,
2943,
14,
523,
4645,
275,
359,
272,
327,
10080,
436,
7681,
2943,
489,
283,
10973,
297,
489,
283,
4448,
27448,
37,
297,
489,
283,
17563,
297,
489,
283,
13837,
297,
489,
283,
10527,
297,
489,
283,
568,
6174,
297,
489,
283,
17598,
297,
489,
283,
8893,
297,
489,
283,
2711,
5638,
297,
339,
327,
11177,
22817,
7681,
489,
283,
28100,
297,
489,
283,
12511,
1075,
4392,
297,
489,
283,
21008,
297,
489,
283,
10449,
297,
339,
327,
1010,
1856,
471,
367,
8686,
675,
489,
283,
13001,
297,
339,
327,
3918,
2943,
489,
283,
11783,
297,
489,
283,
47,
1028,
297,
489,
283,
2919,
297,
489,
283,
21377,
297,
489,
283,
5353,
297,
339,
327,
6654,
2750,
489,
283,
44,
18013,
297,
489,
283,
50,
18013,
7,
523,
1622,
819,
327,
283,
7511,
7,
365,
282,
2341,
402,
1059,
370,
1526,
730,
14,
221,
2900,
10046,
9903,
4645,
787,
523,
327,
7838,
6169,
7681,
12,
370,
6705,
340,
314,
1526,
365,
5965,
282,
4252,
14,
523,
7681,
275,
469,
272,
283,
11935,
7,
520,
283,
4448,
27448,
37,
297,
272,
283,
4869,
7,
221,
520,
283,
17563,
297,
272,
283,
1302,
7,
520,
283,
13837,
297,
272,
283,
3266,
7,
520,
283,
17598,
297,
272,
283,
6753,
7,
520,
283,
5670,
10452,
297,
272,
283,
1820,
7,
520,
283,
8893,
297,
272,
283,
9594,
7,
520,
283,
2711,
5638,
297,
339,
283,
3058,
7,
520,
283,
28100,
297,
272,
283,
9086,
7,
520,
283,
12511,
1075,
4392,
297,
272,
283,
4144,
7,
520,
283,
21008,
297,
272,
283,
1986,
7,
520,
283,
10449,
297,
272,
283,
3251,
7,
520,
283,
13001,
297,
523,
789,
819,
327,
283,
5955,
7,
365,
282,
574,
1420,
701,
7103,
1314,
9314,
282,
769,
402,
1686,
523,
327,
8785,
4645,
12,
11150,
314,
1526,
730,
436,
1526,
574,
787,
13130,
14,
523,
18041,
275,
5522,
4856,
342,
2440,
59,
467,
27,
26,
29,
16341,
22500,
92,
6,
62,
14069,
819,
327,
8767,
10269,
523,
327,
523,
327,
491,
476,
15194,
1263,
574,
503,
805,
315,
314,
1824,
402,
283,
84,
27718,
2711,
3524,
8469,
282,
523,
327,
5578,
3965,
2382,
282,
1336,
911,
8689,
282,
1526,
402,
730,
665,
2711,
10827,
221,
1010,
314,
523,
327,
1930,
402,
282,
805,
12,
314,
805,
365,
2797,
1380,
282,
1336,
365,
6326,
14,
5723,
523,
327,
10269,
11492,
687,
22817,
14,
819,
327,
283,
84,
63,
4247,
7,
365,
282,
4539,
1336,
402,
2974,
370,
3686,
523,
307,
63,
4247,
275,
283,
971,
84,
7,
819,
327,
19991,
1338,
523,
307,
63,
11783,
275,
519,
12418,
31,
2961,
68,
23294,
68,
10,
6113,
68,
7590,
3134,
68,
8771,
779,
37,
69,
1527,
16341,
22426,
68,
19544,
28447,
8995,
68,
21324,
37,
69,
1527,
16341,
22426,
68,
4786,
523,
307,
63,
2919,
275,
519,
12418,
26736,
16,
13,
25,
2807,
59,
85,
53,
11843,
7,
523,
307,
63,
47,
1028,
275,
519,
12418,
31,
16,
59,
16,
13,
23,
28012,
523,
307,
63,
21377,
275,
519,
12418,
31,
16,
59,
56,
88,
1527,
16,
13,
25,
33,
13,
1906,
13,
70,
28012,
523,
307,
63,
44,
18013,
275,
519,
7601,
28,
7,
523,
307,
63,
50,
18013,
275,
519,
7,
1140,
7,
819,
327,
437,
1004,
13401,
1557,
78,
297,
781,
675,
642,
370,
11609,
314,
1004,
1329,
523,
347,
307,
63,
6174,
63,
3902,
8,
277,
12,
307,
304,
272,
519,
1154,
78,
4786,
272,
291,
14,
1123,
9863,
8,
552,
8,
84,
14,
585,
430,
819,
327,
2136,
886,
440,
2112,
24644,
315,
314,
14575,
3326,
14,
221,
24361,
787,
444,
1016,
9840,
523,
327,
1202,
367,
3004,
12,
436,
440,
1202,
465,
25780,
283,
35,
7,
5262,
14,
523,
347,
307,
63,
5353,
8,
277,
12,
307,
304,
272,
519,
4065,
25153,
10,
4507,
272,
307,
14,
585,
275,
307,
14,
585,
59,
17,
6809,
17,
61,
272,
291,
14,
1123,
9863,
8,
84,
14,
585,
14,
835,
2258,
78,
1333,
272,
372,
307,
819,
327,
437,
445,
503,
445,
4176,
3449,
3721,
26,
221,
13505,
26571,
11589,
503,
5001,
523,
347,
307,
63,
10973,
8,
277,
12,
307,
304,
272,
519,
6774,
6307,
5830,
14,
6113,
78,
3342,
8995,
15870,
8636
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
21125,
367,
510,
48,
3735,
14575,
408,
199,
199,
3,
199,
3,
14575,
21125,
199,
3,
199,
3,
710,
10426,
365,
4440,
314,
510,
6084,
7103,
3555,
370,
1900,
282,
14803,
1314,
1334,
26580,
199,
3,
22817,
4645,
14,
199,
3,
199,
3,
22817,
12,
436,
22817,
5578,
8455,
883,
506,
1911,
737,
26,
199,
3,
257,
1455,
921,
2374,
14,
87,
19,
14,
1308,
15,
7968,
15,
2520,
1246,
15,
5926,
11505,
15,
199,
3,
510,
6084,
883,
506,
1911,
737,
26,
199,
3,
257,
1455,
921,
1544,
14,
68,
371,
4489,
90,
14,
957,
15,
19786,
15,
199,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
199,
3,
199,
3,
7649,
370,
2248,
314,
299,
590,
859,
12,
340,
440,
12,
2066,
5534,
652,
365,
315,
314,
10919,
63,
7522,
199,
3,
2082,
12,
3847,
370,
299,
387,
1038,
199,
3,
199,
893,
26,
523,
687,
299,
590,
492,
7103,
199,
2590,
26,
523,
859,
63,
515,
12,
859,
63,
354,
275,
747,
14,
515,
14,
1294,
3460,
493,
3368,
523,
10919,
63,
7522,
275,
747,
14,
515,
14,
904,
8,
578,
63,
515,
12,
19155,
19155,
283,
11470,
63,
7522,
358,
523,
984,
14,
515,
14,
740,
8,
11470,
63,
7522,
9,
523,
687,
299,
590,
492,
7103,
199,
199,
504,
20365,
63,
1422,
492,
2372,
2602,
12,
3207,
12,
6077,
4558,
421,
199,
2602,
360,
1199,
297,
283,
6864,
1072,
2659,
199,
199,
3,
199,
3,
14575,
21125,
199,
3,
199,
533,
2870,
4464,
5273,
8,
785,
304,
523,
327,
283,
4504,
7,
365,
282,
574,
1415,
701,
7103,
1314,
9314,
314,
4890,
769,
523,
327,
402,
1686,
1526,
2943,
14,
523,
4645,
275,
359,
272,
327,
10080,
436,
7681,
2943,
489,
283,
10973,
297,
489,
283,
4448,
27448,
37,
297,
489,
283,
17563,
297,
489,
283,
13837,
297,
489,
283,
10527,
297,
489,
283,
568,
6174,
297,
489,
283,
17598,
297,
489,
283,
8893,
297,
489,
283,
2711,
5638,
297,
339,
327,
11177,
22817,
7681,
489,
283,
28100,
297,
489,
283,
12511,
1075,
4392,
297,
489,
283,
21008,
297,
489,
283,
10449,
297,
339,
327,
1010,
1856,
471,
367,
8686,
675,
489,
283,
13001,
297,
339,
327,
3918,
2943,
489,
283,
11783,
297,
489,
283,
47,
1028,
297,
489,
283,
2919,
297,
489,
283,
21377,
297,
489,
283,
5353,
297,
339,
327,
6654,
2750,
489,
283,
44,
18013,
297,
489,
283,
50,
18013,
7,
523,
1622,
819,
327,
283,
7511,
7,
365,
282,
2341,
402,
1059,
370,
1526,
730,
14,
221,
2900,
10046,
9903,
4645,
787,
523,
327,
7838,
6169,
7681,
12,
370,
6705,
340,
314,
1526,
365,
5965,
282,
4252,
14,
523,
7681,
275,
469,
272,
283,
11935,
7,
520,
283,
4448,
27448,
37,
297,
272,
283,
4869,
7,
221,
520,
283,
17563,
297,
272,
283,
1302,
7,
520,
283,
13837,
297,
272,
283,
3266,
7,
520,
283,
17598,
297,
272,
283,
6753,
7,
520,
283,
5670,
10452,
297,
272,
283,
1820,
7,
520,
283,
8893,
297,
272,
283,
9594,
7,
520,
283,
2711,
5638,
297,
339,
283,
3058,
7,
520,
283,
28100,
297,
272,
283,
9086,
7,
520,
283,
12511,
1075,
4392,
297,
272,
283,
4144,
7,
520,
283,
21008,
297,
272,
283,
1986,
7,
520,
283,
10449,
297,
272,
283,
3251,
7,
520,
283,
13001,
297,
523,
789,
819,
327,
283,
5955,
7,
365,
282,
574,
1420,
701,
7103,
1314,
9314,
282,
769,
402,
1686,
523,
327,
8785,
4645,
12,
11150,
314,
1526,
730,
436,
1526,
574,
787,
13130,
14,
523,
18041,
275,
5522,
4856,
342,
2440,
59,
467,
27,
26,
29,
16341,
22500,
92,
6,
62,
14069,
819,
327,
8767,
10269,
523,
327,
523,
327,
491,
476,
15194,
1263,
574,
503,
805,
315,
314,
1824,
402,
283,
84,
27718,
2711,
3524,
8469,
282,
523,
327,
5578,
3965,
2382,
282,
1336,
911,
8689,
282,
1526,
402,
730,
665,
2711,
10827,
221,
1010,
314,
523,
327,
1930,
402,
282,
805,
12,
314,
805,
365,
2797,
1380,
282,
1336,
365,
6326,
14,
5723,
523,
327,
10269,
11492,
687,
22817,
14,
819,
327,
283,
84,
63,
4247,
7,
365,
282,
4539,
1336,
402,
2974,
370,
3686,
523,
307,
63,
4247,
275,
283,
971,
84,
7,
819,
327,
19991,
1338,
523,
307,
63,
11783,
275,
519,
12418,
31,
2961,
68,
23294,
68,
10,
6113,
68,
7590,
3134,
68,
8771,
779,
37,
69,
1527,
16341,
22426,
68,
19544,
28447,
8995,
68,
21324,
37,
69,
1527,
16341,
22426,
68,
4786,
523,
307,
63,
2919,
275,
519,
12418,
26736,
16,
13,
25,
2807,
59,
85,
53,
11843,
7,
523,
307,
63,
47,
1028,
275,
519,
12418,
31,
16,
59,
16,
13,
23,
28012,
523,
307,
63,
21377,
275,
519,
12418,
31,
16,
59,
56,
88,
1527,
16,
13,
25,
33,
13,
1906,
13,
70,
28012,
523,
307,
63,
44,
18013,
275,
519,
7601,
28,
7,
523,
307,
63,
50,
18013,
275,
519,
7,
1140,
7,
819,
327,
437,
1004,
13401,
1557,
78,
297,
781,
675,
642,
370,
11609,
314,
1004,
1329,
523,
347,
307,
63,
6174,
63,
3902,
8,
277,
12,
307,
304,
272,
519,
1154,
78,
4786,
272,
291,
14,
1123,
9863,
8,
552,
8,
84,
14,
585,
430,
819,
327,
2136,
886,
440,
2112,
24644,
315,
314,
14575,
3326,
14,
221,
24361,
787,
444,
1016,
9840,
523,
327,
1202,
367,
3004,
12,
436,
440,
1202,
465,
25780,
283,
35,
7,
5262,
14,
523,
347,
307,
63,
5353,
8,
277,
12,
307,
304,
272,
519,
4065,
25153,
10,
4507,
272,
307,
14,
585,
275,
307,
14,
585,
59,
17,
6809,
17,
61,
272,
291,
14,
1123,
9863,
8,
84,
14,
585,
14,
835,
2258,
78,
1333,
272,
372,
307,
819,
327,
437,
445,
503,
445,
4176,
3449,
3721,
26,
221,
13505,
26571,
11589,
503,
5001,
523,
347,
307,
63,
10973,
8,
277,
12,
307,
304,
272,
519,
6774,
6307,
5830,
14,
6113,
78,
3342,
8995,
15870,
8636,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sanger-pathogens/gff3toembl | gff3toembl/EMBLConverter.py | 3 | 1946 | import gff3toembl
from gt import CustomVisitor
from gff3toembl.EMBLContig import EMBLContig
class EMBLConverter(CustomVisitor):
def __init__(self, locus_tag=None, translation_table=11):
CustomVisitor.__init__(self)
self.contigs = {}
self.locus_tag = locus_tag
self.translation_table = translation_table
def visit_feature_node(self, feature_node):
sequence_id = feature_node.get_seqid()
contig = self.contigs.get(sequence_id)
if contig: # contig already exists, just try and update it
contig.add_feature(sequence_id = sequence_id, feature_type = feature_node.get_type(), start = feature_node.get_start(),
end = feature_node.get_end(), strand = feature_node.get_strand(),
feature_attributes = feature_node.attribs,
locus_tag = self.locus_tag, translation_table = self.translation_table)
else:
contig = EMBLContig()
successfully_added_feature = contig.add_feature(sequence_id = sequence_id, feature_type = feature_node.get_type(), start = feature_node.get_start(),
end = feature_node.get_end(), strand = feature_node.get_strand(),
feature_attributes = feature_node.attribs,
locus_tag = self.locus_tag, translation_table = self.translation_table)
if successfully_added_feature:
self.contigs[sequence_id] = contig
else:
pass # discard the contig because we didn't add a feature so it is empty
def visit_region_node(self, region_node):
pass # for now
def visit_comment_node(self, comment_node):
pass # for now
def visit_sequence_node(self, sequence_node):
sequence_id = sequence_node.get_description()
contig = self.contigs.setdefault(sequence_id, EMBLContig())
contig.add_sequence(sequence_node.get_sequence())
| gpl-3.0 | [
646,
486,
556,
19,
475,
18847,
76,
199,
504,
16484,
492,
8388,
18324,
199,
504,
486,
556,
19,
475,
18847,
76,
14,
2769,
7847,
714,
17277,
492,
662,
4567,
44,
714,
17277,
199,
199,
533,
662,
4567,
44,
11907,
8,
7223,
18324,
304,
339,
347,
636,
826,
721,
277,
12,
4355,
527,
63,
1450,
29,
403,
12,
7761,
63,
1224,
29,
845,
304,
267,
8388,
18324,
855,
826,
721,
277,
9,
267,
291,
14,
388,
280,
458,
275,
1052,
267,
291,
14,
2102,
527,
63,
1450,
275,
4355,
527,
63,
1450,
267,
291,
14,
6893,
63,
1224,
275,
7761,
63,
1224,
339,
347,
5684,
63,
4445,
63,
932,
8,
277,
12,
3878,
63,
932,
304,
489,
3414,
63,
344,
275,
3878,
63,
932,
14,
362,
63,
26693,
342,
489,
406,
17277,
275,
291,
14,
388,
280,
458,
14,
362,
8,
4041,
63,
344,
9,
489,
340,
406,
17277,
26,
327,
406,
17277,
2575,
3495,
12,
2951,
862,
436,
1678,
652,
267,
406,
17277,
14,
525,
63,
4445,
8,
4041,
63,
344,
275,
3414,
63,
344,
12,
3878,
63,
466,
275,
3878,
63,
932,
14,
362,
63,
466,
1062,
1343,
275,
3878,
63,
932,
14,
362,
63,
928,
1062,
2574,
1284,
275,
3878,
63,
932,
14,
362,
63,
500,
1062,
620,
460,
275,
3878,
63,
932,
14,
362,
63,
30964,
1062,
2574,
3878,
63,
2987,
275,
3878,
63,
932,
14,
30674,
12,
2574,
4355,
527,
63,
1450,
275,
291,
14,
2102,
527,
63,
1450,
12,
7761,
63,
1224,
275,
291,
14,
6893,
63,
1224,
9,
489,
587,
26,
267,
406,
17277,
275,
662,
4567,
44,
714,
17277,
342,
267,
8792,
63,
3270,
63,
4445,
275,
406,
17277,
14,
525,
63,
4445,
8,
4041,
63,
344,
275,
3414,
63,
344,
12,
3878,
63,
466,
275,
3878,
63,
932,
14,
362,
63,
466,
1062,
1343,
275,
3878,
63,
932,
14,
362,
63,
928,
1062,
2574,
1284,
275,
3878,
63,
932,
14,
362,
63,
500,
1062,
620,
460,
275,
3878,
63,
932,
14,
362,
63,
30964,
1062,
2574,
3878,
63,
2987,
275,
3878,
63,
932,
14,
30674,
12,
2574,
4355,
527,
63,
1450,
275,
291,
14,
2102,
527,
63,
1450,
12,
7761,
63,
1224,
275,
291,
14,
6893,
63,
1224,
9,
267,
340,
8792,
63,
3270,
63,
4445,
26,
881,
291,
14,
388,
280,
458,
59,
4041,
63,
344,
61,
275,
406,
17277,
267,
587,
26,
881,
986,
327,
16895,
314,
406,
17277,
2952,
781,
9980,
1133,
1050,
282,
3878,
880,
652,
365,
2701,
339,
347,
5684,
63,
4551,
63,
932,
8,
277,
12,
4897,
63,
932,
304,
267,
986,
221,
327,
367,
3063,
339,
347,
5684,
63,
3349,
63,
932,
8,
277,
12,
3721,
63,
932,
304,
267,
986,
221,
327,
367,
3063,
339,
347,
5684,
63,
4041,
63,
932,
8,
277,
12,
3414,
63,
932,
304,
489,
3414,
63,
344,
275,
3414,
63,
932,
14,
362,
63,
1802,
342,
489,
406,
17277,
275,
291,
14,
388,
280,
458,
14,
5486,
8,
4041,
63,
344,
12,
662,
4567,
44,
714,
17277,
1012,
489,
406,
17277,
14,
525,
63,
4041,
8,
4041,
63,
932,
14,
362,
63,
4041,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
486,
556,
19,
475,
18847,
76,
199,
504,
16484,
492,
8388,
18324,
199,
504,
486,
556,
19,
475,
18847,
76,
14,
2769,
7847,
714,
17277,
492,
662,
4567,
44,
714,
17277,
199,
199,
533,
662,
4567,
44,
11907,
8,
7223,
18324,
304,
339,
347,
636,
826,
721,
277,
12,
4355,
527,
63,
1450,
29,
403,
12,
7761,
63,
1224,
29,
845,
304,
267,
8388,
18324,
855,
826,
721,
277,
9,
267,
291,
14,
388,
280,
458,
275,
1052,
267,
291,
14,
2102,
527,
63,
1450,
275,
4355,
527,
63,
1450,
267,
291,
14,
6893,
63,
1224,
275,
7761,
63,
1224,
339,
347,
5684,
63,
4445,
63,
932,
8,
277,
12,
3878,
63,
932,
304,
489,
3414,
63,
344,
275,
3878,
63,
932,
14,
362,
63,
26693,
342,
489,
406,
17277,
275,
291,
14,
388,
280,
458,
14,
362,
8,
4041,
63,
344,
9,
489,
340,
406,
17277,
26,
327,
406,
17277,
2575,
3495,
12,
2951,
862,
436,
1678,
652,
267,
406,
17277,
14,
525,
63,
4445,
8,
4041,
63,
344,
275,
3414,
63,
344,
12,
3878,
63,
466,
275,
3878,
63,
932,
14,
362,
63,
466,
1062,
1343,
275,
3878,
63,
932,
14,
362,
63,
928,
1062,
2574,
1284,
275,
3878,
63,
932,
14,
362,
63,
500,
1062,
620,
460,
275,
3878,
63,
932,
14,
362,
63,
30964,
1062,
2574,
3878,
63,
2987,
275,
3878,
63,
932,
14,
30674,
12,
2574,
4355,
527,
63,
1450,
275,
291,
14,
2102,
527,
63,
1450,
12,
7761,
63,
1224,
275,
291,
14,
6893,
63,
1224,
9,
489,
587,
26,
267,
406,
17277,
275,
662,
4567,
44,
714,
17277,
342,
267,
8792,
63,
3270,
63,
4445,
275,
406,
17277,
14,
525,
63,
4445,
8,
4041,
63,
344,
275,
3414,
63,
344,
12,
3878,
63,
466,
275,
3878,
63,
932,
14,
362,
63,
466,
1062,
1343,
275,
3878,
63,
932,
14,
362,
63,
928,
1062,
2574,
1284,
275,
3878,
63,
932,
14,
362,
63,
500,
1062,
620,
460,
275,
3878,
63,
932,
14,
362,
63,
30964,
1062,
2574,
3878,
63,
2987,
275,
3878,
63,
932,
14,
30674,
12,
2574,
4355,
527,
63,
1450,
275,
291,
14,
2102,
527,
63,
1450,
12,
7761,
63,
1224,
275,
291,
14,
6893,
63,
1224,
9,
267,
340,
8792,
63,
3270,
63,
4445,
26,
881,
291,
14,
388,
280,
458,
59,
4041,
63,
344,
61,
275,
406,
17277,
267,
587,
26,
881,
986,
327,
16895,
314,
406,
17277,
2952,
781,
9980,
1133,
1050,
282,
3878,
880,
652,
365,
2701,
339,
347,
5684,
63,
4551,
63,
932,
8,
277,
12,
4897,
63,
932,
304,
267,
986,
221,
327,
367,
3063,
339,
347,
5684,
63,
3349,
63,
932,
8,
277,
12,
3721,
63,
932,
304,
267,
986,
221,
327,
367,
3063,
339,
347,
5684,
63,
4041,
63,
932,
8,
277,
12,
3414,
63,
932,
304,
489,
3414,
63,
344,
275,
3414,
63,
932,
14,
362,
63,
1802,
342,
489,
406,
17277,
275,
291,
14,
388,
280,
458,
14,
5486,
8,
4041,
63,
344,
12,
662,
4567,
44,
714,
17277,
1012,
489,
406,
17277,
14,
525,
63,
4041,
8,
4041,
63,
932,
14,
362,
63,
4041,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
SanPen/GridCal | src/GridCal/Engine/Sparse/utils.py | 1 | 2463 | # This file is part of GridCal.
#
# GridCal 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.
#
# GridCal 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 GridCal. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
def slice_to_range(sl: slice, n):
"""
Turn a slice into a range
:param sl: slice object
:param n: total number of items
:return: range object, if the slice is not supported an exception is raised
"""
if sl.start is None and sl.step is None and sl.start is None: # (:)
return range(n)
elif sl.start is not None and sl.step is None and sl.start is None: # (a:)
return range(sl.start, n)
elif sl.start is not None and sl.step is not None and sl.start is None: # (?)
raise Exception('Invalid slice')
elif sl.start is not None and sl.step is None and sl.start is not None: # (a:b)
return range(sl.start, sl.stop)
elif sl.start is not None and sl.step is not None and sl.start is not None: # (a:s:b)
return range(sl.start, sl.stop, sl.step)
elif sl.start is None and sl.step is None and sl.start is not None: # (:b)
return range(sl.stop)
else:
raise Exception('Invalid slice')
def dense_to_str(mat: np.ndarray):
"""
Turn dense 2D numpy array into a string
:param mat: 2D numpy array
:return: string
"""
rows, cols = mat.shape
val = "Matrix (" + ("%d" % rows) + " x " + ("%d" % cols) + ")\n"
val += str(mat).replace('. ', ' ').replace('[', ' ').replace(']', '').replace('0 ', '_ ').replace('0.', '_ ')
# for i in range(0, rows):
# for j in range(0, cols):
# x = mat[i, j]
# if x is not None:
# if x == 0:
# val += '{:<4}'.format(0)
# else:
# val += '{:<4}'.format(x)
# else:
# val += ""
# val += '\n'
# for rows in M:
# print(*['{:<4}'.format(each) for each in rows])
return val
| gpl-3.0 | [
3,
961,
570,
365,
1777,
402,
16386,
6584,
14,
199,
3,
199,
3,
16386,
6584,
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,
16386,
6584,
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,
16386,
6584,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2680,
465,
980,
421,
199,
318,
6014,
63,
475,
63,
1842,
8,
2482,
26,
6014,
12,
302,
304,
272,
408,
272,
16147,
282,
6014,
1901,
282,
1425,
272,
520,
635,
5340,
26,
6014,
909,
272,
520,
635,
302,
26,
3141,
1329,
402,
2974,
272,
520,
1107,
26,
1425,
909,
12,
340,
314,
6014,
365,
440,
3748,
376,
1919,
365,
4915,
272,
408,
272,
340,
5340,
14,
928,
365,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
18479,
9,
267,
372,
1425,
8,
78,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
334,
65,
26,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
302,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
440,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
7558,
9,
267,
746,
2186,
360,
3364,
6014,
358,
272,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
334,
65,
26,
66,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
5340,
14,
2379,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
440,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
334,
65,
26,
83,
26,
66,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
5340,
14,
2379,
12,
5340,
14,
2926,
9,
339,
916,
5340,
14,
928,
365,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
18479,
66,
9,
267,
372,
1425,
8,
2482,
14,
2379,
9,
339,
587,
26,
267,
746,
2186,
360,
3364,
6014,
358,
421,
199,
318,
9363,
63,
475,
63,
495,
8,
569,
26,
980,
14,
8237,
304,
272,
408,
272,
16147,
9363,
499,
36,
2680,
1625,
1901,
282,
1059,
272,
520,
635,
2530,
26,
499,
36,
2680,
1625,
272,
520,
1107,
26,
1059,
272,
408,
272,
4730,
12,
8850,
275,
2530,
14,
1392,
272,
1139,
275,
298,
6443,
1689,
435,
19426,
68,
2,
450,
4730,
9,
435,
298,
671,
298,
435,
19426,
68,
2,
450,
8850,
9,
435,
298,
2862,
78,
2,
272,
1139,
847,
620,
8,
569,
680,
1814,
5175,
1656,
283,
27274,
1814,
11894,
297,
283,
27274,
1814,
360,
4300,
12548,
1814,
360,
16,
1656,
2513,
27274,
1814,
360,
16,
3130,
2513,
5320,
272,
327,
367,
284,
315,
1425,
8,
16,
12,
4730,
304,
272,
327,
258,
367,
1335,
315,
1425,
8,
16,
12,
8850,
304,
272,
327,
260,
671,
275,
2530,
59,
73,
12,
1335,
61,
272,
327,
260,
340,
671,
365,
440,
488,
26,
272,
327,
3777,
340,
671,
508,
378,
26,
272,
327,
463,
1139,
847,
5041,
16875,
20,
5285,
908,
8,
16,
9,
272,
327,
3777,
587,
26,
272,
327,
463,
1139,
847,
5041,
16875,
20,
5285,
908,
8,
88,
9,
272,
327,
260,
587,
26,
272,
327,
3777,
1139,
847,
3087,
272,
327,
258,
1139,
847,
1557,
78,
7,
339,
327,
367,
4730,
315,
603,
26,
272,
327,
258,
870,
2031,
459,
91,
16875,
20,
5285,
908,
8,
10885,
9,
367,
1924,
315,
4730,
566,
339,
372,
1139,
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
] | [
961,
570,
365,
1777,
402,
16386,
6584,
14,
199,
3,
199,
3,
16386,
6584,
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,
16386,
6584,
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,
16386,
6584,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
2680,
465,
980,
421,
199,
318,
6014,
63,
475,
63,
1842,
8,
2482,
26,
6014,
12,
302,
304,
272,
408,
272,
16147,
282,
6014,
1901,
282,
1425,
272,
520,
635,
5340,
26,
6014,
909,
272,
520,
635,
302,
26,
3141,
1329,
402,
2974,
272,
520,
1107,
26,
1425,
909,
12,
340,
314,
6014,
365,
440,
3748,
376,
1919,
365,
4915,
272,
408,
272,
340,
5340,
14,
928,
365,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
18479,
9,
267,
372,
1425,
8,
78,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
334,
65,
26,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
302,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
440,
488,
436,
5340,
14,
928,
365,
488,
26,
221,
327,
7558,
9,
267,
746,
2186,
360,
3364,
6014,
358,
272,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
334,
65,
26,
66,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
5340,
14,
2379,
9,
339,
916,
5340,
14,
928,
365,
440,
488,
436,
5340,
14,
2926,
365,
440,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
334,
65,
26,
83,
26,
66,
9,
267,
372,
1425,
8,
2482,
14,
928,
12,
5340,
14,
2379,
12,
5340,
14,
2926,
9,
339,
916,
5340,
14,
928,
365,
488,
436,
5340,
14,
2926,
365,
488,
436,
5340,
14,
928,
365,
440,
488,
26,
221,
327,
18479,
66,
9,
267,
372,
1425,
8,
2482,
14,
2379,
9,
339,
587,
26,
267,
746,
2186,
360,
3364,
6014,
358,
421,
199,
318,
9363,
63,
475,
63,
495,
8,
569,
26,
980,
14,
8237,
304,
272,
408,
272,
16147,
9363,
499,
36,
2680,
1625,
1901,
282,
1059,
272,
520,
635,
2530,
26,
499,
36,
2680,
1625,
272,
520,
1107,
26,
1059,
272,
408,
272,
4730,
12,
8850,
275,
2530,
14,
1392,
272,
1139,
275,
298,
6443,
1689,
435,
19426,
68,
2,
450,
4730,
9,
435,
298,
671,
298,
435,
19426,
68,
2,
450,
8850,
9,
435,
298,
2862,
78,
2,
272,
1139,
847,
620,
8,
569,
680,
1814,
5175,
1656,
283,
27274,
1814,
11894,
297,
283,
27274,
1814,
360,
4300,
12548,
1814,
360,
16,
1656,
2513,
27274,
1814,
360,
16,
3130,
2513,
5320,
272,
327,
367,
284,
315,
1425,
8,
16,
12,
4730,
304,
272,
327,
258,
367,
1335,
315,
1425,
8,
16,
12,
8850,
304,
272,
327,
260,
671,
275,
2530,
59,
73,
12,
1335,
61,
272,
327,
260,
340,
671,
365,
440,
488,
26,
272,
327,
3777,
340,
671,
508,
378,
26,
272,
327,
463,
1139,
847,
5041,
16875,
20,
5285,
908,
8,
16,
9,
272,
327,
3777,
587,
26,
272,
327,
463,
1139,
847,
5041,
16875,
20,
5285,
908,
8,
88,
9,
272,
327,
260,
587,
26,
272,
327,
3777,
1139,
847,
3087,
272,
327,
258,
1139,
847,
1557,
78,
7,
339,
327,
367,
4730,
315,
603,
26,
272,
327,
258,
870,
2031,
459,
91,
16875,
20,
5285,
908,
8,
10885,
9,
367,
1924,
315,
4730,
566,
339,
372,
1139,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
trashkalmar/omim | tools/python/mwm/dump_mwm.py | 10 | 1418 | #!/usr/bin/python
import sys, os.path, random
import json
from mwm import MWM
if len(sys.argv) < 2:
print('Dumps some MWM structures.')
print('Usage: {0} <country.mwm>'.format(sys.argv[0]))
sys.exit(1)
mwm = MWM(open(sys.argv[1], 'rb'))
mwm.read_types(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', 'data', 'types.txt'))
print('Tags:')
tvv = sorted([(k, v[0], v[1]) for k, v in mwm.tags.items()], key=lambda x: x[1])
for tv in tvv:
print(' {0:<8}: offs {1:9} len {2:8}'.format(tv[0], tv[1], tv[2]))
v = mwm.read_version()
print('Format: {0}, version: {1}'.format(v['fmt'], v['date'].strftime('%Y-%m-%d %H:%M')))
print('Header: {0}'.format(mwm.read_header()))
print('Region Info: {0}'.format(mwm.read_region_info()))
print('Metadata count: {0}'.format(len(mwm.read_metadata())))
cross = mwm.read_crossmwm()
if cross:
print('Outgoing points: {0}, incoming: {1}'.format(len(cross['out']), len(cross['in'])))
print('Outgoing regions: {0}'.format(set(cross['neighbours'])))
# Print some random features using reservoir sampling
count = 5
sample = []
for i, feature in enumerate(mwm.iter_features()):
if i < count:
sample.append(feature)
elif random.randint(0, i) < count:
sample[random.randint(0, count-1)] = feature
print('Feature count: {0}'.format(i))
print('Sample features:')
for feature in sample:
print(json.dumps(feature, ensure_ascii=False))
| apache-2.0 | [
3381,
2647,
15,
1393,
15,
1548,
199,
646,
984,
12,
747,
14,
515,
12,
2196,
199,
646,
2022,
199,
504,
333,
16240,
492,
603,
13073,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
870,
360,
11772,
83,
2005,
603,
13073,
13955,
2659,
272,
870,
360,
7692,
26,
469,
16,
93,
665,
6063,
14,
14716,
77,
22936,
908,
8,
1274,
14,
3020,
59,
16,
2459,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
14716,
77,
275,
603,
13073,
8,
1490,
8,
1274,
14,
3020,
59,
17,
467,
283,
4848,
1333,
199,
14716,
77,
14,
739,
63,
1313,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
19155,
19155,
19155,
283,
576,
297,
283,
1313,
14,
2424,
1333,
199,
1361,
360,
9440,
10993,
199,
6993,
86,
275,
3355,
7694,
75,
12,
373,
59,
16,
467,
373,
59,
17,
566,
367,
1022,
12,
373,
315,
333,
16240,
14,
2969,
14,
1744,
15618,
790,
29,
2734,
671,
26,
671,
59,
17,
566,
199,
509,
13466,
315,
307,
8958,
26,
272,
870,
360,
221,
469,
16,
16875,
24,
9160,
402,
2319,
469,
17,
26,
25,
93,
822,
469,
18,
26,
24,
5285,
908,
8,
6993,
59,
16,
467,
13466,
59,
17,
467,
13466,
59,
18,
2459,
199,
86,
275,
333,
16240,
14,
739,
63,
1023,
342,
199,
1361,
360,
3484,
26,
469,
16,
1386,
1015,
26,
469,
17,
5285,
908,
8,
86,
459,
5045,
995,
373,
459,
602,
2278,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
7058,
199,
1361,
360,
2567,
26,
469,
16,
5285,
908,
8,
14716,
77,
14,
739,
63,
1291,
4059,
199,
1361,
360,
10708,
10332,
26,
469,
16,
5285,
908,
8,
14716,
77,
14,
739,
63,
4551,
63,
815,
4059,
199,
1361,
360,
5142,
2338,
26,
469,
16,
5285,
908,
8,
552,
8,
14716,
77,
14,
739,
63,
2343,
16890,
199,
199,
7925,
275,
333,
16240,
14,
739,
63,
7925,
14716,
77,
342,
199,
692,
8059,
26,
272,
870,
360,
2204,
10947,
4501,
26,
469,
16,
1386,
12467,
26,
469,
17,
5285,
908,
8,
552,
8,
7925,
459,
548,
3815,
822,
8,
7925,
459,
262,
26991,
272,
870,
360,
2204,
10947,
16150,
26,
469,
16,
5285,
908,
8,
409,
8,
7925,
459,
685,
4594,
16363,
26991,
199,
199,
3,
9101,
2005,
2196,
4534,
1808,
295,
25943,
723,
15877,
199,
835,
275,
959,
199,
3271,
275,
942,
199,
509,
284,
12,
3878,
315,
3874,
8,
14716,
77,
14,
1661,
63,
3179,
5109,
272,
340,
284,
665,
2338,
26,
267,
2690,
14,
740,
8,
4445,
9,
272,
916,
2196,
14,
8393,
8,
16,
12,
284,
9,
665,
2338,
26,
267,
2690,
59,
2355,
14,
8393,
8,
16,
12,
2338,
13,
17,
1874,
275,
3878,
199,
199,
1361,
360,
5968,
2338,
26,
469,
16,
5285,
908,
8,
73,
430,
199,
1361,
360,
8176,
4534,
10993,
199,
509,
3878,
315,
2690,
26,
272,
870,
8,
1001,
14,
4180,
8,
4445,
12,
4868,
63,
4371,
29,
797,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2647,
15,
1393,
15,
1548,
199,
646,
984,
12,
747,
14,
515,
12,
2196,
199,
646,
2022,
199,
504,
333,
16240,
492,
603,
13073,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
870,
360,
11772,
83,
2005,
603,
13073,
13955,
2659,
272,
870,
360,
7692,
26,
469,
16,
93,
665,
6063,
14,
14716,
77,
22936,
908,
8,
1274,
14,
3020,
59,
16,
2459,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
14716,
77,
275,
603,
13073,
8,
1490,
8,
1274,
14,
3020,
59,
17,
467,
283,
4848,
1333,
199,
14716,
77,
14,
739,
63,
1313,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2522,
19155,
19155,
19155,
283,
576,
297,
283,
1313,
14,
2424,
1333,
199,
1361,
360,
9440,
10993,
199,
6993,
86,
275,
3355,
7694,
75,
12,
373,
59,
16,
467,
373,
59,
17,
566,
367,
1022,
12,
373,
315,
333,
16240,
14,
2969,
14,
1744,
15618,
790,
29,
2734,
671,
26,
671,
59,
17,
566,
199,
509,
13466,
315,
307,
8958,
26,
272,
870,
360,
221,
469,
16,
16875,
24,
9160,
402,
2319,
469,
17,
26,
25,
93,
822,
469,
18,
26,
24,
5285,
908,
8,
6993,
59,
16,
467,
13466,
59,
17,
467,
13466,
59,
18,
2459,
199,
86,
275,
333,
16240,
14,
739,
63,
1023,
342,
199,
1361,
360,
3484,
26,
469,
16,
1386,
1015,
26,
469,
17,
5285,
908,
8,
86,
459,
5045,
995,
373,
459,
602,
2278,
6205,
3508,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
7058,
199,
1361,
360,
2567,
26,
469,
16,
5285,
908,
8,
14716,
77,
14,
739,
63,
1291,
4059,
199,
1361,
360,
10708,
10332,
26,
469,
16,
5285,
908,
8,
14716,
77,
14,
739,
63,
4551,
63,
815,
4059,
199,
1361,
360,
5142,
2338,
26,
469,
16,
5285,
908,
8,
552,
8,
14716,
77,
14,
739,
63,
2343,
16890,
199,
199,
7925,
275,
333,
16240,
14,
739,
63,
7925,
14716,
77,
342,
199,
692,
8059,
26,
272,
870,
360,
2204,
10947,
4501,
26,
469,
16,
1386,
12467,
26,
469,
17,
5285,
908,
8,
552,
8,
7925,
459,
548,
3815,
822,
8,
7925,
459,
262,
26991,
272,
870,
360,
2204,
10947,
16150,
26,
469,
16,
5285,
908,
8,
409,
8,
7925,
459,
685,
4594,
16363,
26991,
199,
199,
3,
9101,
2005,
2196,
4534,
1808,
295,
25943,
723,
15877,
199,
835,
275,
959,
199,
3271,
275,
942,
199,
509,
284,
12,
3878,
315,
3874,
8,
14716,
77,
14,
1661,
63,
3179,
5109,
272,
340,
284,
665,
2338,
26,
267,
2690,
14,
740,
8,
4445,
9,
272,
916,
2196,
14,
8393,
8,
16,
12,
284,
9,
665,
2338,
26,
267,
2690,
59,
2355,
14,
8393,
8,
16,
12,
2338,
13,
17,
1874,
275,
3878,
199,
199,
1361,
360,
5968,
2338,
26,
469,
16,
5285,
908,
8,
73,
430,
199,
1361,
360,
8176,
4534,
10993,
199,
509,
3878,
315,
2690,
26,
272,
870,
8,
1001,
14,
4180,
8,
4445,
12,
4868,
63,
4371,
29,
797,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vergecurrency/electrum-xvg | gui/qt/version_getter.py | 2 | 4598 | #!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2012 thomasv@gitorious
#
# 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/>.
import threading, re, socket
import webbrowser
import requests
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import PyQt4.QtCore as QtCore
from electrum_xvg.i18n import _
from electrum_xvg import ELECTRUM_VERSION, print_error
class VersionGetter(threading.Thread):
def __init__(self, label):
threading.Thread.__init__(self)
self.label = label
self.daemon = True
def run(self):
try:
res = requests.request("GET", "http://electrum-verge.xyz/version")
except:
print_error("Could not retrieve version information")
return
if res.status_code == 200:
latest_version = res.text
latest_version = latest_version.replace("\n","")
if(re.match('^\d+(\.\d+)*$', latest_version)):
self.label.callback(latest_version)
class UpdateLabel(QLabel):
def __init__(self, config, sb):
QLabel.__init__(self)
self.new_version = False
self.sb = sb
self.config = config
self.current_version = ELECTRUM_VERSION
self.connect(self, QtCore.SIGNAL('new_electrum_version'), self.new_electrum_version)
# prevent HTTP leaks if a proxy is set
if self.config.get('proxy'):
return
VersionGetter(self).start()
def callback(self, version):
self.latest_version = version
if(self.compare_versions(self.latest_version, self.current_version) == 1):
latest_seen = self.config.get("last_seen_version",ELECTRUM_VERSION)
if(self.compare_versions(self.latest_version, latest_seen) == 1):
self.new_version = True
self.emit(QtCore.SIGNAL('new_electrum_version'))
def new_electrum_version(self):
if self.new_version:
self.setText(_("New version available") + ": " + self.latest_version)
self.sb.insertPermanentWidget(1, self)
def compare_versions(self, version1, version2):
def normalize(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
try:
return cmp(normalize(version1), normalize(version2))
except:
return 0
def ignore_this_version(self):
self.setText("")
self.config.set_key("last_seen_version", self.latest_version, True)
QMessageBox.information(self, _("Preference saved"), _("Notifications about this update will not be shown again."))
self.dialog.done(0)
def ignore_all_version(self):
self.setText("")
self.config.set_key("last_seen_version", "9.9.9", True)
QMessageBox.information(self, _("Preference saved"), _("No more notifications about version updates will be shown."))
self.dialog.done(0)
def open_website(self):
webbrowser.open("http://electrum-verge.xyz/download.html")
self.dialog.done(0)
def mouseReleaseEvent(self, event):
dialog = QDialog(self)
dialog.setWindowTitle(_('Electrum-XVG update'))
dialog.setModal(1)
main_layout = QGridLayout()
main_layout.addWidget(QLabel(_("A new version of Electrum-XVG is available:")+" " + self.latest_version), 0,0,1,3)
ignore_version = QPushButton(_("Ignore this version"))
ignore_version.clicked.connect(self.ignore_this_version)
ignore_all_versions = QPushButton(_("Ignore all versions"))
ignore_all_versions.clicked.connect(self.ignore_all_version)
open_website = QPushButton(_("Goto download page"))
open_website.clicked.connect(self.open_website)
main_layout.addWidget(ignore_version, 1, 0)
main_layout.addWidget(ignore_all_versions, 1, 1)
main_layout.addWidget(open_website, 1, 2)
dialog.setLayout(main_layout)
self.dialog = dialog
if not dialog.exec_(): return
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
662,
1264,
28430,
446,
10540,
3463,
21158,
1890,
199,
3,
1898,
334,
35,
9,
6029,
294,
676,
305,
86,
32,
3187,
16039,
1785,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5796,
12,
295,
12,
2838,
199,
646,
781,
29063,
199,
646,
4145,
199,
199,
504,
14084,
20,
14,
10604,
492,
627,
199,
504,
14084,
20,
14,
10901,
492,
627,
199,
646,
14084,
20,
14,
10901,
465,
10565,
199,
199,
504,
28933,
28430,
63,
88,
10929,
14,
73,
1085,
78,
492,
485,
199,
504,
28933,
28430,
63,
88,
10929,
492,
662,
3923,
50,
2639,
63,
4612,
12,
870,
63,
705,
199,
199,
533,
3394,
22038,
8,
12562,
14,
4436,
304,
339,
347,
636,
826,
721,
277,
12,
1768,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
10824,
275,
715,
339,
347,
1255,
8,
277,
304,
267,
862,
26,
288,
522,
275,
4145,
14,
1069,
480,
2970,
401,
298,
1014,
921,
26334,
28430,
13,
422,
303,
14,
8568,
15,
1023,
531,
267,
871,
26,
288,
870,
63,
705,
480,
6531,
440,
8044,
1015,
2556,
531,
288,
372,
398,
340,
522,
14,
1205,
63,
600,
508,
1926,
26,
288,
8839,
63,
1023,
275,
522,
14,
505,
288,
8839,
63,
1023,
275,
8839,
63,
1023,
14,
1814,
4582,
78,
401,
7230,
288,
340,
8,
264,
14,
1431,
9097,
60,
68,
20900,
3134,
68,
11,
3342,
4268,
8839,
63,
1023,
2298,
355,
291,
14,
1302,
14,
3058,
8,
7410,
63,
1023,
9,
199,
199,
533,
6162,
4314,
8,
19890,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
12,
20088,
304,
267,
1413,
4314,
855,
826,
721,
277,
9,
267,
291,
14,
1222,
63,
1023,
275,
756,
267,
291,
14,
9264,
275,
20088,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
1818,
63,
1023,
275,
662,
3923,
50,
2639,
63,
4612,
267,
291,
14,
2242,
8,
277,
12,
10565,
14,
16496,
360,
1222,
63,
26334,
28430,
63,
1023,
659,
291,
14,
1222,
63,
26334,
28430,
63,
1023,
9,
267,
327,
7981,
3101,
1026,
14631,
340,
282,
4566,
365,
663,
267,
340,
291,
14,
888,
14,
362,
360,
3280,
735,
288,
372,
267,
3394,
22038,
8,
277,
680,
928,
342,
339,
347,
3233,
8,
277,
12,
1015,
304,
267,
291,
14,
7410,
63,
1023,
275,
1015,
267,
340,
8,
277,
14,
5785,
63,
6234,
8,
277,
14,
7410,
63,
1023,
12,
291,
14,
1818,
63,
1023,
9,
508,
413,
304,
288,
8839,
63,
8606,
275,
291,
14,
888,
14,
362,
480,
2019,
63,
8606,
63,
1023,
401,
37,
3923,
50,
2639,
63,
4612,
9,
288,
340,
8,
277,
14,
5785,
63,
6234,
8,
277,
14,
7410,
63,
1023,
12,
8839,
63,
8606,
9,
508,
413,
304,
355,
291,
14,
1222,
63,
1023,
275,
715,
355,
291,
14,
8159,
8,
10901,
14,
16496,
360,
1222,
63,
26334,
28430,
63,
1023,
1333,
339,
347,
892,
63,
26334,
28430,
63,
1023,
8,
277,
304,
267,
340,
291,
14,
1222,
63,
1023,
26,
288,
291,
14,
8341,
6115,
4665,
1015,
2808,
531,
435,
7244,
298,
435,
291,
14,
7410,
63,
1023,
9,
288,
291,
14,
9264,
14,
3176,
31776,
3339,
8,
17,
12,
291,
9,
339,
347,
6540,
63,
6234,
8,
277,
12,
1015,
17,
12,
1015,
18,
304,
267,
347,
7666,
8,
86,
304,
288,
372,
359,
442,
8,
88,
9,
367,
671,
315,
295,
14,
954,
8,
82,
13445,
14,
16,
11,
3342,
4,
1673,
297,
373,
680,
1294,
15857,
61,
267,
862,
26,
288,
372,
10467,
8,
7721,
8,
1023,
17,
395,
7666,
8,
1023,
18,
430,
267,
871,
26,
288,
372,
378,
339,
347,
3686,
63,
3749,
63,
1023,
8,
277,
304,
267,
291,
14,
8341,
10804,
267,
291,
14,
888,
14,
409,
63,
498,
480,
2019,
63,
8606,
63,
1023,
401,
291,
14,
7410,
63,
1023,
12,
715,
9,
267,
25159,
14,
11697,
8,
277,
12,
3824,
25258,
6290,
1288,
3824,
30620,
3595,
642,
1678,
911,
440,
506,
9164,
4020,
13853,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
3686,
63,
452,
63,
1023,
8,
277,
304,
267,
291,
14,
8341,
10804,
267,
291,
14,
888,
14,
409,
63,
498,
480,
2019,
63,
8606,
63,
1023,
401,
298,
25,
14,
25,
14,
25,
401,
715,
9,
267,
25159,
14,
11697,
8,
277,
12,
3824,
25258,
6290,
1288,
3824,
1944,
1655,
13116,
3595,
1015,
7029,
911,
506,
9164,
13853,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
1551,
63,
7360,
8,
277,
304,
267,
781,
29063,
14,
1490,
480,
1014,
921,
26334,
28430,
13,
422,
303,
14,
8568,
15,
4249,
14,
1360,
531,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
12817,
9625,
2390,
8,
277,
12,
1566,
304,
267,
9592,
275,
1413,
5619,
8,
277,
9,
267,
9592,
14,
30601,
6723,
37,
1264,
28430,
13,
56,
29355,
1678,
1333,
267,
9592,
14,
409,
23689,
8,
17,
9,
398,
2446,
63,
4209,
275,
1413,
7900,
4798,
342,
267,
2446,
63,
4209,
14,
9475,
8,
19890,
6115,
33,
892,
1015,
402,
662,
1264,
28430,
13,
56,
29355,
365,
2808,
9107,
5207,
298,
435,
291,
14,
7410,
63,
1023,
395,
378,
12,
16,
12,
17,
12,
19,
9,
398,
3686,
63,
1023,
275,
1413,
20083
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
662,
1264,
28430,
446,
10540,
3463,
21158,
1890,
199,
3,
1898,
334,
35,
9,
6029,
294,
676,
305,
86,
32,
3187,
16039,
1785,
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,
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,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
5796,
12,
295,
12,
2838,
199,
646,
781,
29063,
199,
646,
4145,
199,
199,
504,
14084,
20,
14,
10604,
492,
627,
199,
504,
14084,
20,
14,
10901,
492,
627,
199,
646,
14084,
20,
14,
10901,
465,
10565,
199,
199,
504,
28933,
28430,
63,
88,
10929,
14,
73,
1085,
78,
492,
485,
199,
504,
28933,
28430,
63,
88,
10929,
492,
662,
3923,
50,
2639,
63,
4612,
12,
870,
63,
705,
199,
199,
533,
3394,
22038,
8,
12562,
14,
4436,
304,
339,
347,
636,
826,
721,
277,
12,
1768,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
10824,
275,
715,
339,
347,
1255,
8,
277,
304,
267,
862,
26,
288,
522,
275,
4145,
14,
1069,
480,
2970,
401,
298,
1014,
921,
26334,
28430,
13,
422,
303,
14,
8568,
15,
1023,
531,
267,
871,
26,
288,
870,
63,
705,
480,
6531,
440,
8044,
1015,
2556,
531,
288,
372,
398,
340,
522,
14,
1205,
63,
600,
508,
1926,
26,
288,
8839,
63,
1023,
275,
522,
14,
505,
288,
8839,
63,
1023,
275,
8839,
63,
1023,
14,
1814,
4582,
78,
401,
7230,
288,
340,
8,
264,
14,
1431,
9097,
60,
68,
20900,
3134,
68,
11,
3342,
4268,
8839,
63,
1023,
2298,
355,
291,
14,
1302,
14,
3058,
8,
7410,
63,
1023,
9,
199,
199,
533,
6162,
4314,
8,
19890,
304,
272,
347,
636,
826,
721,
277,
12,
1101,
12,
20088,
304,
267,
1413,
4314,
855,
826,
721,
277,
9,
267,
291,
14,
1222,
63,
1023,
275,
756,
267,
291,
14,
9264,
275,
20088,
267,
291,
14,
888,
275,
1101,
267,
291,
14,
1818,
63,
1023,
275,
662,
3923,
50,
2639,
63,
4612,
267,
291,
14,
2242,
8,
277,
12,
10565,
14,
16496,
360,
1222,
63,
26334,
28430,
63,
1023,
659,
291,
14,
1222,
63,
26334,
28430,
63,
1023,
9,
267,
327,
7981,
3101,
1026,
14631,
340,
282,
4566,
365,
663,
267,
340,
291,
14,
888,
14,
362,
360,
3280,
735,
288,
372,
267,
3394,
22038,
8,
277,
680,
928,
342,
339,
347,
3233,
8,
277,
12,
1015,
304,
267,
291,
14,
7410,
63,
1023,
275,
1015,
267,
340,
8,
277,
14,
5785,
63,
6234,
8,
277,
14,
7410,
63,
1023,
12,
291,
14,
1818,
63,
1023,
9,
508,
413,
304,
288,
8839,
63,
8606,
275,
291,
14,
888,
14,
362,
480,
2019,
63,
8606,
63,
1023,
401,
37,
3923,
50,
2639,
63,
4612,
9,
288,
340,
8,
277,
14,
5785,
63,
6234,
8,
277,
14,
7410,
63,
1023,
12,
8839,
63,
8606,
9,
508,
413,
304,
355,
291,
14,
1222,
63,
1023,
275,
715,
355,
291,
14,
8159,
8,
10901,
14,
16496,
360,
1222,
63,
26334,
28430,
63,
1023,
1333,
339,
347,
892,
63,
26334,
28430,
63,
1023,
8,
277,
304,
267,
340,
291,
14,
1222,
63,
1023,
26,
288,
291,
14,
8341,
6115,
4665,
1015,
2808,
531,
435,
7244,
298,
435,
291,
14,
7410,
63,
1023,
9,
288,
291,
14,
9264,
14,
3176,
31776,
3339,
8,
17,
12,
291,
9,
339,
347,
6540,
63,
6234,
8,
277,
12,
1015,
17,
12,
1015,
18,
304,
267,
347,
7666,
8,
86,
304,
288,
372,
359,
442,
8,
88,
9,
367,
671,
315,
295,
14,
954,
8,
82,
13445,
14,
16,
11,
3342,
4,
1673,
297,
373,
680,
1294,
15857,
61,
267,
862,
26,
288,
372,
10467,
8,
7721,
8,
1023,
17,
395,
7666,
8,
1023,
18,
430,
267,
871,
26,
288,
372,
378,
339,
347,
3686,
63,
3749,
63,
1023,
8,
277,
304,
267,
291,
14,
8341,
10804,
267,
291,
14,
888,
14,
409,
63,
498,
480,
2019,
63,
8606,
63,
1023,
401,
291,
14,
7410,
63,
1023,
12,
715,
9,
267,
25159,
14,
11697,
8,
277,
12,
3824,
25258,
6290,
1288,
3824,
30620,
3595,
642,
1678,
911,
440,
506,
9164,
4020,
13853,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
3686,
63,
452,
63,
1023,
8,
277,
304,
267,
291,
14,
8341,
10804,
267,
291,
14,
888,
14,
409,
63,
498,
480,
2019,
63,
8606,
63,
1023,
401,
298,
25,
14,
25,
14,
25,
401,
715,
9,
267,
25159,
14,
11697,
8,
277,
12,
3824,
25258,
6290,
1288,
3824,
1944,
1655,
13116,
3595,
1015,
7029,
911,
506,
9164,
13853,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
1551,
63,
7360,
8,
277,
304,
267,
781,
29063,
14,
1490,
480,
1014,
921,
26334,
28430,
13,
422,
303,
14,
8568,
15,
4249,
14,
1360,
531,
267,
291,
14,
7196,
14,
4456,
8,
16,
9,
339,
347,
12817,
9625,
2390,
8,
277,
12,
1566,
304,
267,
9592,
275,
1413,
5619,
8,
277,
9,
267,
9592,
14,
30601,
6723,
37,
1264,
28430,
13,
56,
29355,
1678,
1333,
267,
9592,
14,
409,
23689,
8,
17,
9,
398,
2446,
63,
4209,
275,
1413,
7900,
4798,
342,
267,
2446,
63,
4209,
14,
9475,
8,
19890,
6115,
33,
892,
1015,
402,
662,
1264,
28430,
13,
56,
29355,
365,
2808,
9107,
5207,
298,
435,
291,
14,
7410,
63,
1023,
395,
378,
12,
16,
12,
17,
12,
19,
9,
398,
3686,
63,
1023,
275,
1413,
20083,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lambeau/ansible-modules-core | cloud/openstack/_quantum_router.py | 37 | 7032 | #!/usr/bin/python
#coding: utf-8 -*-
# (c) 2013, Benno Joy <benno@ansible.com>
#
# This module 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 software 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 software. If not, see <http://www.gnu.org/licenses/>.
try:
try:
from neutronclient.neutron import client
except ImportError:
from quantumclient.quantum import client
from keystoneclient.v2_0 import client as ksclient
HAVE_DEPS = True
except ImportError:
HAVE_DEPS = False
DOCUMENTATION = '''
---
module: quantum_router
version_added: "1.2"
author: "Benno Joy (@bennojoy)"
deprecated: Deprecated in 2.0. Use os_router instead
short_description: Create or Remove router from openstack
description:
- Create or Delete routers from OpenStack
options:
login_username:
description:
- login username to authenticate to keystone
required: true
default: admin
login_password:
description:
- Password of login user
required: true
default: 'yes'
login_tenant_name:
description:
- The tenant name of the login user
required: true
default: 'yes'
auth_url:
description:
- The keystone url for authentication
required: false
default: 'http://127.0.0.1:35357/v2.0/'
region_name:
description:
- Name of the region
required: false
default: None
state:
description:
- Indicate desired state of the resource
choices: ['present', 'absent']
default: present
name:
description:
- Name to be give to the router
required: true
default: None
tenant_name:
description:
- Name of the tenant for which the router has to be created, if none router would be created for the login tenant.
required: false
default: None
admin_state_up:
description:
- desired admin state of the created router .
required: false
default: true
requirements:
- "python >= 2.6"
- "python-neutronclient or python-quantumclient"
- "python-keystoneclient"
'''
EXAMPLES = '''
# Creates a router for tenant admin
- quantum_router: state=present
login_username=admin
login_password=admin
login_tenant_name=admin
name=router1"
'''
_os_keystone = None
_os_tenant_id = None
def _get_ksclient(module, kwargs):
try:
kclient = ksclient.Client(username=kwargs.get('login_username'),
password=kwargs.get('login_password'),
tenant_name=kwargs.get('login_tenant_name'),
auth_url=kwargs.get('auth_url'))
except Exception, e:
module.fail_json(msg = "Error authenticating to the keystone: %s " % e.message)
global _os_keystone
_os_keystone = kclient
return kclient
def _get_endpoint(module, ksclient):
try:
endpoint = ksclient.service_catalog.url_for(service_type='network', endpoint_type='publicURL')
except Exception, e:
module.fail_json(msg = "Error getting network endpoint: %s" % e.message)
return endpoint
def _get_neutron_client(module, kwargs):
_ksclient = _get_ksclient(module, kwargs)
token = _ksclient.auth_token
endpoint = _get_endpoint(module, _ksclient)
kwargs = {
'token': token,
'endpoint_url': endpoint
}
try:
neutron = client.Client('2.0', **kwargs)
except Exception, e:
module.fail_json(msg = "Error in connecting to neutron: %s " % e.message)
return neutron
def _set_tenant_id(module):
global _os_tenant_id
if not module.params['tenant_name']:
_os_tenant_id = _os_keystone.tenant_id
else:
tenant_name = module.params['tenant_name']
for tenant in _os_keystone.tenants.list():
if tenant.name == tenant_name:
_os_tenant_id = tenant.id
break
if not _os_tenant_id:
module.fail_json(msg = "The tenant id cannot be found, please check the parameters")
def _get_router_id(module, neutron):
kwargs = {
'name': module.params['name'],
'tenant_id': _os_tenant_id,
}
try:
routers = neutron.list_routers(**kwargs)
except Exception, e:
module.fail_json(msg = "Error in getting the router list: %s " % e.message)
if not routers['routers']:
return None
return routers['routers'][0]['id']
def _create_router(module, neutron):
router = {
'name': module.params['name'],
'tenant_id': _os_tenant_id,
'admin_state_up': module.params['admin_state_up'],
}
try:
new_router = neutron.create_router(dict(router=router))
except Exception, e:
module.fail_json( msg = "Error in creating router: %s" % e.message)
return new_router['router']['id']
def _delete_router(module, neutron, router_id):
try:
neutron.delete_router(router_id)
except:
module.fail_json("Error in deleting the router")
return True
def main():
argument_spec = openstack_argument_spec()
argument_spec.update(dict(
name = dict(required=True),
tenant_name = dict(default=None),
state = dict(default='present', choices=['absent', 'present']),
admin_state_up = dict(type='bool', default=True),
))
module = AnsibleModule(argument_spec=argument_spec)
if not HAVE_DEPS:
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
neutron = _get_neutron_client(module, module.params)
_set_tenant_id(module)
if module.params['state'] == 'present':
router_id = _get_router_id(module, neutron)
if not router_id:
router_id = _create_router(module, neutron)
module.exit_json(changed=True, result="Created", id=router_id)
else:
module.exit_json(changed=False, result="success" , id=router_id)
else:
router_id = _get_router_id(module, neutron)
if not router_id:
module.exit_json(changed=False, result="success")
else:
_delete_router(module, neutron, router_id)
module.exit_json(changed=True, result="deleted")
# this is magic, see lib/ansible/module.params['common.py
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
if __name__ == '__main__':
main()
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1523,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
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,
2032,
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,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
862,
26,
267,
687,
8224,
1258,
14,
10271,
492,
1890,
272,
871,
3545,
26,
267,
687,
15381,
453,
1258,
14,
25999,
492,
1890,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
1022,
551,
864,
272,
25227,
63,
1093,
5067,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
1093,
5067,
275,
756,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
15381,
453,
63,
4995,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
2502,
26,
298,
31231,
889,
7135,
89,
8593,
18486,
889,
26729,
2924,
199,
6667,
26,
17993,
315,
499,
14,
16,
14,
3645,
747,
63,
4995,
3140,
199,
3612,
63,
1802,
26,
2790,
503,
5852,
6197,
687,
13869,
199,
1802,
26,
2043,
446,
2790,
503,
8496,
24464,
687,
14260,
199,
1419,
26,
2043,
4676,
63,
2473,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
2549,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
402,
314,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
1790,
63,
633,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
4897,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
4897,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
370,
506,
8120,
370,
314,
6197,
1362,
1415,
26,
2549,
1362,
849,
26,
488,
2043,
8261,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
8261,
367,
1314,
314,
6197,
965,
370,
506,
2737,
12,
340,
7179,
6197,
3955,
506,
2737,
367,
314,
4676,
8261,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
4628,
63,
929,
63,
384,
26,
1362,
1369,
26,
267,
446,
6387,
4628,
1174,
402,
314,
2737,
6197,
1275,
1362,
1415,
26,
3055,
1362,
849,
26,
2549,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
298,
1548,
13,
10271,
1258,
503,
2366,
13,
25999,
1258,
2,
272,
446,
298,
1548,
13,
19143,
1258,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
10560,
282,
6197,
367,
8261,
4628,
199,
13,
15381,
453,
63,
4995,
26,
1174,
29,
1881,
355,
4676,
63,
2473,
29,
2113,
355,
4676,
63,
2060,
29,
2113,
355,
4676,
63,
4647,
63,
354,
29,
2113,
355,
536,
29,
4995,
17,
2,
199,
2344,
199,
199,
63,
736,
63,
19143,
275,
488,
199,
63,
736,
63,
4647,
63,
344,
275,
488,
199,
199,
318,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
304,
272,
862,
26,
267,
1022,
1258,
275,
1022,
551,
864,
14,
3041,
8,
2473,
29,
958,
14,
362,
360,
2886,
63,
2473,
659,
639,
2505,
29,
958,
14,
362,
360,
2886,
63,
2060,
659,
639,
8261,
63,
354,
29,
958,
14,
362,
360,
2886,
63,
4647,
63,
354,
659,
639,
1790,
63,
633,
29,
958,
14,
362,
360,
1178,
63,
633,
1333,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
28532,
1958,
370,
314,
19395,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
2288,
485,
736,
63,
19143,
272,
485,
736,
63,
19143,
275,
1022,
1258,
272,
372,
1022,
1258,
421,
199,
318,
485,
362,
63,
6520,
8,
578,
12,
1022,
551,
864,
304,
272,
862,
26,
267,
6037,
275,
1022,
551,
864,
14,
1364,
63,
7959,
14,
633,
63,
509,
8,
1364,
63,
466,
534,
1200,
297,
6037,
63,
466,
534,
3455,
2632,
358,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
10232,
2784,
6037,
26,
450,
83,
2,
450,
325,
14,
1188,
9,
272,
372,
6037,
199,
199,
318,
485,
362,
63,
10271,
63,
1258,
8,
578,
12,
2074,
304,
272,
485,
75,
551,
864,
275,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
9,
272,
1526,
275,
485,
75,
551,
864,
14,
1178,
63,
1418,
272,
6037,
275,
485,
362,
63,
6520,
8,
578,
12,
485,
75,
551,
864,
9,
272,
2074,
275,
469,
288,
283,
1418,
356,
1526,
12,
288,
283,
6520,
63,
633,
356,
6037,
272,
789,
272,
862,
26,
267,
8224,
275,
1890,
14,
3041,
360,
18,
14,
16,
297,
1011,
958,
9,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
315,
18170,
370,
8224,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
372,
8224,
199,
199,
318,
485,
409,
63,
4647,
63,
344,
8
] | [
2647,
15,
1393,
15,
1548,
199,
3,
1523,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
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,
2032,
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,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
862,
26,
267,
687,
8224,
1258,
14,
10271,
492,
1890,
272,
871,
3545,
26,
267,
687,
15381,
453,
1258,
14,
25999,
492,
1890,
272,
687,
19395,
1258,
14,
86,
18,
63,
16,
492,
1890,
465,
1022,
551,
864,
272,
25227,
63,
1093,
5067,
275,
715,
199,
2590,
3545,
26,
272,
25227,
63,
1093,
5067,
275,
756,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
15381,
453,
63,
4995,
199,
1023,
63,
3270,
26,
298,
17,
14,
18,
2,
199,
2502,
26,
298,
31231,
889,
7135,
89,
8593,
18486,
889,
26729,
2924,
199,
6667,
26,
17993,
315,
499,
14,
16,
14,
3645,
747,
63,
4995,
3140,
199,
3612,
63,
1802,
26,
2790,
503,
5852,
6197,
687,
13869,
199,
1802,
26,
2043,
446,
2790,
503,
8496,
24464,
687,
14260,
199,
1419,
26,
2043,
4676,
63,
2473,
26,
1362,
1369,
26,
267,
446,
4676,
3434,
370,
12895,
370,
19395,
1362,
1415,
26,
2549,
1362,
849,
26,
4628,
2043,
4676,
63,
2060,
26,
1362,
1369,
26,
267,
446,
13635,
402,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
4676,
63,
4647,
63,
354,
26,
1362,
1369,
26,
267,
446,
710,
8261,
536,
402,
314,
4676,
922,
1362,
1415,
26,
2549,
1362,
849,
26,
283,
5066,
7,
2043,
1790,
63,
633,
26,
1362,
1369,
26,
267,
446,
710,
19395,
1166,
367,
6299,
1362,
1415,
26,
3055,
1362,
849,
26,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1276,
13155,
15,
86,
18,
14,
16,
4805,
2043,
4897,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
4897,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
1174,
26,
1362,
1369,
26,
267,
446,
1010,
10188,
6387,
1174,
402,
314,
2073,
1362,
3415,
26,
788,
1881,
297,
283,
5575,
418,
1362,
849,
26,
3451,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
370,
506,
8120,
370,
314,
6197,
1362,
1415,
26,
2549,
1362,
849,
26,
488,
2043,
8261,
63,
354,
26,
1362,
1369,
26,
267,
446,
2812,
402,
314,
8261,
367,
1314,
314,
6197,
965,
370,
506,
2737,
12,
340,
7179,
6197,
3955,
506,
2737,
367,
314,
4676,
8261,
14,
1362,
1415,
26,
3055,
1362,
849,
26,
488,
2043,
4628,
63,
929,
63,
384,
26,
1362,
1369,
26,
267,
446,
6387,
4628,
1174,
402,
314,
2737,
6197,
1275,
1362,
1415,
26,
3055,
1362,
849,
26,
2549,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
298,
1548,
13,
10271,
1258,
503,
2366,
13,
25999,
1258,
2,
272,
446,
298,
1548,
13,
19143,
1258,
2,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
10560,
282,
6197,
367,
8261,
4628,
199,
13,
15381,
453,
63,
4995,
26,
1174,
29,
1881,
355,
4676,
63,
2473,
29,
2113,
355,
4676,
63,
2060,
29,
2113,
355,
4676,
63,
4647,
63,
354,
29,
2113,
355,
536,
29,
4995,
17,
2,
199,
2344,
199,
199,
63,
736,
63,
19143,
275,
488,
199,
63,
736,
63,
4647,
63,
344,
275,
488,
199,
199,
318,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
304,
272,
862,
26,
267,
1022,
1258,
275,
1022,
551,
864,
14,
3041,
8,
2473,
29,
958,
14,
362,
360,
2886,
63,
2473,
659,
639,
2505,
29,
958,
14,
362,
360,
2886,
63,
2060,
659,
639,
8261,
63,
354,
29,
958,
14,
362,
360,
2886,
63,
4647,
63,
354,
659,
639,
1790,
63,
633,
29,
958,
14,
362,
360,
1178,
63,
633,
1333,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
28532,
1958,
370,
314,
19395,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
2288,
485,
736,
63,
19143,
272,
485,
736,
63,
19143,
275,
1022,
1258,
272,
372,
1022,
1258,
421,
199,
318,
485,
362,
63,
6520,
8,
578,
12,
1022,
551,
864,
304,
272,
862,
26,
267,
6037,
275,
1022,
551,
864,
14,
1364,
63,
7959,
14,
633,
63,
509,
8,
1364,
63,
466,
534,
1200,
297,
6037,
63,
466,
534,
3455,
2632,
358,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
10232,
2784,
6037,
26,
450,
83,
2,
450,
325,
14,
1188,
9,
272,
372,
6037,
199,
199,
318,
485,
362,
63,
10271,
63,
1258,
8,
578,
12,
2074,
304,
272,
485,
75,
551,
864,
275,
485,
362,
63,
75,
551,
864,
8,
578,
12,
2074,
9,
272,
1526,
275,
485,
75,
551,
864,
14,
1178,
63,
1418,
272,
6037,
275,
485,
362,
63,
6520,
8,
578,
12,
485,
75,
551,
864,
9,
272,
2074,
275,
469,
288,
283,
1418,
356,
1526,
12,
288,
283,
6520,
63,
633,
356,
6037,
272,
789,
272,
862,
26,
267,
8224,
275,
1890,
14,
3041,
360,
18,
14,
16,
297,
1011,
958,
9,
272,
871,
2186,
12,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
275,
298,
547,
315,
18170,
370,
8224,
26,
450,
83,
298,
450,
325,
14,
1188,
9,
272,
372,
8224,
199,
199,
318,
485,
409,
63,
4647,
63,
344,
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,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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
] |
regionbibliotekhalland/digitalasagor | edittabvideo.py | 1 | 4897 | # Copyright 2013 Regionbibliotek Halland
#
# This file is part of Digitala sagor.
#
# Digitala sagor 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.
#
# Digitala sagor 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 Digitala sagor. If not, see <http://www.gnu.org/licenses/>.
from Tkinter import *
import ttk
from tooltip import ToolTip
from language import lang
import language as lng
from playerdlg import showPlayerDialog
from datamodel import tpVideo
import tkFileDialog
import os
import os.path
import shutil
import spmanager as spm
from edittab import EditTab
_videoFileFormats = [('mp4', '*.mp4'), ('avi', '*.avi'), ('wmv', '*.wmv'), ('mpeg', '*.mpeg'), ('mov', '*.mov')]
class EditTabVideo(EditTab):
"""A Frame for editing video based stories"""
def __init__(self, parent, wdir, datamodel, psize):
"""Initiate
Arguments
parent -- parent tkinter item
wdir -- working directory
datamodel -- the database that is edited by the program
psize -- tuple defining preview size of videos
"""
EditTab.__init__(self, parent, wdir, datamodel, psize)
self._mediatype = tpVideo
#Create variables for common data
self._svVideo = StringVar()
#Make the first row expandable
self.rowconfigure(0, weight = 1)
#Add frame from super class
self._superFrame.grid(row = 0, column = 0, sticky = W + N)
#Create the right column
rightLf = ttk.LabelFrame(self, text = ' ' + lang[lng.txtVideo] + ' ')
rightLf.grid(row = 0, column = 1, pady = 10, sticky = W + N)
rightFrame = Frame(rightLf)
rightFrame.grid()
e = Entry(rightFrame, w = 32, textvariable = self._svVideo, state = "readonly")
e.grid(row = 0, column = 0, padx = 10, pady = 5, sticky = W);
tt = ToolTip(e, '', textvariable = self._svVideo, wraplength = parent.winfo_screenwidth() * 4 / 5)
b = Button(rightFrame, text = lang[lng.txtSelect] + '...', command = self._ehGetVideo)
b.grid(row = 0, column = 1, padx = 10, pady = 5)
b = Button(rightFrame, text = lang[lng.txtWatch], command = self._ehWatch)
b.grid(row = 0, column = 2, padx = 10, pady = 5)
def open(self, slideshow, prepared = False):
"""Open a slideshow for editing
Arguments
slideshow -- the slideshow
prepared -- if true, all media data is already copied to the working folder
(i.e. the slideshow has been created automatically)
"""
EditTab.open(self, slideshow, prepared = False)
if(not prepared):
if(slideshow.video != ''):
shutil.copyfile(slideshow.getPath(slideshow.video), os.path.join(self._wdir, slideshow.video))
self._svVideo.set(slideshow.video)
def clear(self):
"""Clear the edit tab"""
EditTab.clear(self)
self._svVideo.set('')
def _getCurrentSlideshow(self):
"""Create and return a slideshow representing the currently edited slideshow."""
slideshow = EditTab._getCurrentSlideshow(self)
slideshow.video = self._svVideo.get()
return slideshow
#Event handlers
def _ehGetVideo(self):
"""Event handler for assigning a video"""
initdir = spm.spmanager.getFirstPath([spm.VideoFolder,
spm.MostRecentFolder])
filenamepath = tkFileDialog.askopenfilename(initialdir = initdir, filetypes = _videoFileFormats)
if(len(filenamepath) > 0):
filename = os.path.basename(filenamepath)
try:
shutil.copyfile(filenamepath, os.path.join(self._wdir, filename))
except IOError:
showerror(lang[lng.txtCopyError], lang[lng.txtCouldNotCopy] + os.path.basename(filename))
return
self._svVideo.set(filename)
self.setDirty(True)
spm.spmanager.setPath(spm.VideoFolder, os.path.dirname(filenamepath))
def _ehWatch(self):
"""Event handler for preview of the video"""
media = self._getCurrentSlideshow()
showPlayerDialog(self._parent, self._psize, media)
| gpl-3.0 | [
3,
259,
1898,
6171,
22240,
8804,
317,
1583,
75,
869,
452,
460,
202,
199,
3,
202,
199,
3,
259,
961,
570,
365,
1777,
402,
29979,
65,
308,
643,
269,
14,
202,
199,
3,
202,
199,
3,
259,
29979,
65,
308,
643,
269,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
259,
29979,
65,
308,
643,
269,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
259,
3180,
543,
29979,
65,
308,
643,
269,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
202,
199,
504,
16826,
492,
627,
202,
199,
646,
28431,
2999,
199,
504,
28013,
492,
15650,
15915,
2999,
199,
504,
2637,
492,
6339,
202,
199,
646,
2637,
465,
634,
2753,
202,
199,
504,
7748,
24645,
492,
2498,
10921,
5619,
202,
199,
504,
666,
1238,
492,
9253,
9166,
202,
199,
646,
10157,
25213,
202,
199,
646,
747,
202,
199,
646,
747,
14,
515,
202,
199,
646,
5145,
202,
199,
646,
2249,
2609,
465,
2249,
77,
202,
199,
504,
5283,
2902,
492,
16407,
7690,
2999,
199,
63,
3722,
1173,
29717,
275,
4274,
311,
20,
297,
11937,
311,
20,
659,
661,
7194,
297,
11937,
7194,
659,
661,
87,
12393,
297,
11937,
87,
12393,
659,
661,
16801,
297,
11937,
16801,
659,
661,
14469,
297,
11937,
14469,
5440,
2999,
199,
533,
16407,
7690,
9166,
8,
4685,
7690,
304,
1128,
408,
33,
11726,
367,
20401,
3991,
4079,
410,
6112,
624,
1128,
347,
636,
826,
721,
277,
12,
1676,
12,
336,
694,
12,
666,
1238,
12,
299,
890,
304,
1039,
408,
607,
5277,
323,
13594,
7628,
1039,
1676,
1553,
1676,
22171,
1242,
1039,
336,
694,
1553,
6449,
2082,
1039,
666,
1238,
1553,
314,
3050,
626,
365,
21062,
701,
314,
2240,
1039,
299,
890,
1553,
2008,
12669,
19653,
1568,
402,
22010,
20085,
1039,
408,
1039,
16407,
7690,
855,
826,
721,
277,
12,
1676,
12,
336,
694,
12,
666,
1238,
12,
299,
890,
9,
4341,
291,
423,
3700,
8588,
275,
9253,
9166,
4341,
327,
2499,
2860,
367,
2863,
666,
1039,
291,
423,
2772,
9166,
275,
2624,
5894,
342,
4341,
327,
5483,
314,
1642,
1962,
6544,
461,
260,
1039,
291,
14,
1143,
6472,
8,
16,
12,
5401,
275,
413,
9,
4341,
327,
1123,
2787,
687,
1613,
1021,
1039,
291,
423,
4792,
3160,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
378,
12,
17870,
275,
644,
435,
653,
9,
4341,
327,
2499,
314,
2451,
2763,
1039,
2451,
44,
70,
275,
28431,
14,
4314,
3160,
8,
277,
12,
1318,
275,
283,
283,
435,
6339,
59,
23829,
14,
2424,
9166,
61,
435,
283,
5320,
1039,
2451,
44,
70,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
413,
12,
22626,
275,
1616,
12,
17870,
275,
644,
435,
653,
9,
1039,
2451,
3160,
275,
11726,
8,
1019,
44,
70,
9,
1039,
2451,
3160,
14,
3825,
342,
4341,
325,
275,
11855,
8,
1019,
3160,
12,
336,
275,
4337,
12,
1318,
1975,
275,
291,
423,
2772,
9166,
12,
1174,
275,
298,
6753,
531,
1039,
325,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
378,
12,
21729,
275,
1616,
12,
22626,
275,
959,
12,
17870,
275,
644,
2736,
4341,
13638,
275,
15650,
15915,
8,
69,
12,
3260,
1318,
1975,
275,
291,
423,
2772,
9166,
12,
4816,
1267,
275,
1676,
14,
23562,
63,
5410,
2063,
342,
627,
841,
1182,
959,
9,
4341,
330,
275,
16005,
8,
1019,
3160,
12,
1318,
275,
6339,
59,
23829,
14,
2424,
5446,
61,
435,
283,
20833,
1414,
275,
291,
423,
24528,
1002,
9166,
9,
1039,
330,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
413,
12,
21729,
275,
1616,
12,
22626,
275,
959,
9,
4341,
330,
275,
16005,
8,
1019,
3160,
12,
1318,
275,
6339,
59,
23829,
14,
2424,
13978,
467,
1414,
275,
291,
423,
24528,
13978,
9,
1039,
330,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
499,
12,
21729,
275,
1616,
12,
22626,
275,
959,
9,
2958,
347,
1551,
8,
277,
12,
27063,
2384,
12,
16318,
275,
756,
304,
1039,
408,
4299,
282,
27063,
2384,
367,
20401,
13594,
7628,
1039,
27063,
2384,
1553,
314,
27063,
2384,
1039,
16318,
1553,
340,
2549,
12,
1006,
5898,
666,
365,
2575,
8876,
370,
314,
6449,
4922,
4906,
334,
73,
14,
69,
14,
314,
27063,
2384,
965,
2757,
2737,
5847,
9,
13594,
408,
1039,
16407,
7690,
14,
1490,
8,
277,
12,
27063,
2384,
12,
16318,
275,
756,
9,
4341,
340,
8,
1397,
16318,
304,
1675,
340,
8,
19968,
2384,
14,
3722,
1137,
21019,
2628,
5145,
14,
21997,
8,
19968,
2384,
14,
362,
2042,
8,
19968,
2384,
14,
3722,
395,
747,
14,
515,
14,
904,
8,
277,
423,
87,
694,
12,
27063,
2384,
14,
3722,
430,
4341,
291,
423,
2772,
9166,
14,
409,
8,
19968,
2384,
14,
3722,
9,
2958,
347,
5436,
8,
277,
304,
1039,
408,
9721,
314,
5283,
5174,
624,
1039,
16407,
7690,
14,
3584,
8,
277,
9,
1039,
291,
423,
2772,
9166,
14,
409,
8355,
2958,
347,
485,
16662,
51,
8409,
2384,
8,
277,
304,
1039,
408,
2499,
436,
372,
282,
27063,
2384,
6144,
314,
5544,
21062,
27063,
2384,
1041,
1039,
27063,
2384,
275,
16407,
7690,
423,
16662,
51,
8409,
2384,
8,
277,
9,
1039,
27063,
2384,
14,
3722,
275,
291,
423,
2772,
9166,
14,
362,
342,
4341,
372,
27063,
2384,
260,
26016,
327,
2390,
8297,
1128,
347,
485,
24528,
1002,
9166,
8,
277,
304,
1039,
408,
2390,
3016,
367,
26694,
282,
3991,
624,
1039,
4205,
694,
275,
2249,
77,
14,
681,
2609,
14,
362,
7147,
2042,
779,
681,
77,
14
] | [
259,
1898,
6171,
22240,
8804,
317,
1583,
75,
869,
452,
460,
202,
199,
3,
202,
199,
3,
259,
961,
570,
365,
1777,
402,
29979,
65,
308,
643,
269,
14,
202,
199,
3,
202,
199,
3,
259,
29979,
65,
308,
643,
269,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
202,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
202,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
202,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
259,
29979,
65,
308,
643,
269,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
202,
199,
3,
259,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
202,
199,
3,
259,
3180,
543,
29979,
65,
308,
643,
269,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
202,
199,
504,
16826,
492,
627,
202,
199,
646,
28431,
2999,
199,
504,
28013,
492,
15650,
15915,
2999,
199,
504,
2637,
492,
6339,
202,
199,
646,
2637,
465,
634,
2753,
202,
199,
504,
7748,
24645,
492,
2498,
10921,
5619,
202,
199,
504,
666,
1238,
492,
9253,
9166,
202,
199,
646,
10157,
25213,
202,
199,
646,
747,
202,
199,
646,
747,
14,
515,
202,
199,
646,
5145,
202,
199,
646,
2249,
2609,
465,
2249,
77,
202,
199,
504,
5283,
2902,
492,
16407,
7690,
2999,
199,
63,
3722,
1173,
29717,
275,
4274,
311,
20,
297,
11937,
311,
20,
659,
661,
7194,
297,
11937,
7194,
659,
661,
87,
12393,
297,
11937,
87,
12393,
659,
661,
16801,
297,
11937,
16801,
659,
661,
14469,
297,
11937,
14469,
5440,
2999,
199,
533,
16407,
7690,
9166,
8,
4685,
7690,
304,
1128,
408,
33,
11726,
367,
20401,
3991,
4079,
410,
6112,
624,
1128,
347,
636,
826,
721,
277,
12,
1676,
12,
336,
694,
12,
666,
1238,
12,
299,
890,
304,
1039,
408,
607,
5277,
323,
13594,
7628,
1039,
1676,
1553,
1676,
22171,
1242,
1039,
336,
694,
1553,
6449,
2082,
1039,
666,
1238,
1553,
314,
3050,
626,
365,
21062,
701,
314,
2240,
1039,
299,
890,
1553,
2008,
12669,
19653,
1568,
402,
22010,
20085,
1039,
408,
1039,
16407,
7690,
855,
826,
721,
277,
12,
1676,
12,
336,
694,
12,
666,
1238,
12,
299,
890,
9,
4341,
291,
423,
3700,
8588,
275,
9253,
9166,
4341,
327,
2499,
2860,
367,
2863,
666,
1039,
291,
423,
2772,
9166,
275,
2624,
5894,
342,
4341,
327,
5483,
314,
1642,
1962,
6544,
461,
260,
1039,
291,
14,
1143,
6472,
8,
16,
12,
5401,
275,
413,
9,
4341,
327,
1123,
2787,
687,
1613,
1021,
1039,
291,
423,
4792,
3160,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
378,
12,
17870,
275,
644,
435,
653,
9,
4341,
327,
2499,
314,
2451,
2763,
1039,
2451,
44,
70,
275,
28431,
14,
4314,
3160,
8,
277,
12,
1318,
275,
283,
283,
435,
6339,
59,
23829,
14,
2424,
9166,
61,
435,
283,
5320,
1039,
2451,
44,
70,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
413,
12,
22626,
275,
1616,
12,
17870,
275,
644,
435,
653,
9,
1039,
2451,
3160,
275,
11726,
8,
1019,
44,
70,
9,
1039,
2451,
3160,
14,
3825,
342,
4341,
325,
275,
11855,
8,
1019,
3160,
12,
336,
275,
4337,
12,
1318,
1975,
275,
291,
423,
2772,
9166,
12,
1174,
275,
298,
6753,
531,
1039,
325,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
378,
12,
21729,
275,
1616,
12,
22626,
275,
959,
12,
17870,
275,
644,
2736,
4341,
13638,
275,
15650,
15915,
8,
69,
12,
3260,
1318,
1975,
275,
291,
423,
2772,
9166,
12,
4816,
1267,
275,
1676,
14,
23562,
63,
5410,
2063,
342,
627,
841,
1182,
959,
9,
4341,
330,
275,
16005,
8,
1019,
3160,
12,
1318,
275,
6339,
59,
23829,
14,
2424,
5446,
61,
435,
283,
20833,
1414,
275,
291,
423,
24528,
1002,
9166,
9,
1039,
330,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
413,
12,
21729,
275,
1616,
12,
22626,
275,
959,
9,
4341,
330,
275,
16005,
8,
1019,
3160,
12,
1318,
275,
6339,
59,
23829,
14,
2424,
13978,
467,
1414,
275,
291,
423,
24528,
13978,
9,
1039,
330,
14,
3825,
8,
1143,
275,
378,
12,
2763,
275,
499,
12,
21729,
275,
1616,
12,
22626,
275,
959,
9,
2958,
347,
1551,
8,
277,
12,
27063,
2384,
12,
16318,
275,
756,
304,
1039,
408,
4299,
282,
27063,
2384,
367,
20401,
13594,
7628,
1039,
27063,
2384,
1553,
314,
27063,
2384,
1039,
16318,
1553,
340,
2549,
12,
1006,
5898,
666,
365,
2575,
8876,
370,
314,
6449,
4922,
4906,
334,
73,
14,
69,
14,
314,
27063,
2384,
965,
2757,
2737,
5847,
9,
13594,
408,
1039,
16407,
7690,
14,
1490,
8,
277,
12,
27063,
2384,
12,
16318,
275,
756,
9,
4341,
340,
8,
1397,
16318,
304,
1675,
340,
8,
19968,
2384,
14,
3722,
1137,
21019,
2628,
5145,
14,
21997,
8,
19968,
2384,
14,
362,
2042,
8,
19968,
2384,
14,
3722,
395,
747,
14,
515,
14,
904,
8,
277,
423,
87,
694,
12,
27063,
2384,
14,
3722,
430,
4341,
291,
423,
2772,
9166,
14,
409,
8,
19968,
2384,
14,
3722,
9,
2958,
347,
5436,
8,
277,
304,
1039,
408,
9721,
314,
5283,
5174,
624,
1039,
16407,
7690,
14,
3584,
8,
277,
9,
1039,
291,
423,
2772,
9166,
14,
409,
8355,
2958,
347,
485,
16662,
51,
8409,
2384,
8,
277,
304,
1039,
408,
2499,
436,
372,
282,
27063,
2384,
6144,
314,
5544,
21062,
27063,
2384,
1041,
1039,
27063,
2384,
275,
16407,
7690,
423,
16662,
51,
8409,
2384,
8,
277,
9,
1039,
27063,
2384,
14,
3722,
275,
291,
423,
2772,
9166,
14,
362,
342,
4341,
372,
27063,
2384,
260,
26016,
327,
2390,
8297,
1128,
347,
485,
24528,
1002,
9166,
8,
277,
304,
1039,
408,
2390,
3016,
367,
26694,
282,
3991,
624,
1039,
4205,
694,
275,
2249,
77,
14,
681,
2609,
14,
362,
7147,
2042,
779,
681,
77,
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,
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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
] |
devalbo/mm_anywhere | google/protobuf/internal/encoder.py | 484 | 25695 | # Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# http://code.google.com/p/protobuf/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Code for encoding protocol message primitives.
Contains the logic for encoding every logical protocol field type
into one of the 5 physical wire types.
This code is designed to push the Python interpreter's performance to the
limits.
The basic idea is that at startup time, for every field (i.e. every
FieldDescriptor) we construct two functions: a "sizer" and an "encoder". The
sizer takes a value of this field's type and computes its byte size. The
encoder takes a writer function and a value. It encodes the value into byte
strings and invokes the writer function to write those strings. Typically the
writer function is the write() method of a cStringIO.
We try to do as much work as possible when constructing the writer and the
sizer rather than when calling them. In particular:
* We copy any needed global functions to local variables, so that we do not need
to do costly global table lookups at runtime.
* Similarly, we try to do any attribute lookups at startup time if possible.
* Every field's tag is encoded to bytes at startup, since it can't change at
runtime.
* Whatever component of the field size we can compute at startup, we do.
* We *avoid* sharing code if doing so would make the code slower and not sharing
does not burden us too much. For example, encoders for repeated fields do
not just call the encoders for singular fields in a loop because this would
add an extra function call overhead for every loop iteration; instead, we
manually inline the single-value encoder into the loop.
* If a Python function lacks a return statement, Python actually generates
instructions to pop the result of the last statement off the stack, push
None onto the stack, and then return that. If we really don't care what
value is returned, then we can save two instructions by returning the
result of the last statement. It looks funny but it helps.
* We assume that type and bounds checking has happened at a higher level.
"""
__author__ = 'kenton@google.com (Kenton Varda)'
import struct
from google.protobuf.internal import wire_format
# This will overflow and thus become IEEE-754 "infinity". We would use
# "float('inf')" but it doesn't work on Windows pre-Python-2.6.
_POS_INF = 1e10000
_NEG_INF = -_POS_INF
def _VarintSize(value):
"""Compute the size of a varint value."""
if value <= 0x7f: return 1
if value <= 0x3fff: return 2
if value <= 0x1fffff: return 3
if value <= 0xfffffff: return 4
if value <= 0x7ffffffff: return 5
if value <= 0x3ffffffffff: return 6
if value <= 0x1ffffffffffff: return 7
if value <= 0xffffffffffffff: return 8
if value <= 0x7fffffffffffffff: return 9
return 10
def _SignedVarintSize(value):
"""Compute the size of a signed varint value."""
if value < 0: return 10
if value <= 0x7f: return 1
if value <= 0x3fff: return 2
if value <= 0x1fffff: return 3
if value <= 0xfffffff: return 4
if value <= 0x7ffffffff: return 5
if value <= 0x3ffffffffff: return 6
if value <= 0x1ffffffffffff: return 7
if value <= 0xffffffffffffff: return 8
if value <= 0x7fffffffffffffff: return 9
return 10
def _TagSize(field_number):
"""Returns the number of bytes required to serialize a tag with this field
number."""
# Just pass in type 0, since the type won't affect the tag+type size.
return _VarintSize(wire_format.PackTag(field_number, 0))
# --------------------------------------------------------------------
# In this section we define some generic sizers. Each of these functions
# takes parameters specific to a particular field type, e.g. int32 or fixed64.
# It returns another function which in turn takes parameters specific to a
# particular field, e.g. the field number and whether it is repeated or packed.
# Look at the next section to see how these are used.
def _SimpleSizer(compute_value_size):
"""A sizer which uses the function compute_value_size to compute the size of
each value. Typically compute_value_size is _VarintSize."""
def SpecificSizer(field_number, is_repeated, is_packed):
tag_size = _TagSize(field_number)
if is_packed:
local_VarintSize = _VarintSize
def PackedFieldSize(value):
result = 0
for element in value:
result += compute_value_size(element)
return result + local_VarintSize(result) + tag_size
return PackedFieldSize
elif is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
result += compute_value_size(element)
return result
return RepeatedFieldSize
else:
def FieldSize(value):
return tag_size + compute_value_size(value)
return FieldSize
return SpecificSizer
def _ModifiedSizer(compute_value_size, modify_value):
"""Like SimpleSizer, but modify_value is invoked on each value before it is
passed to compute_value_size. modify_value is typically ZigZagEncode."""
def SpecificSizer(field_number, is_repeated, is_packed):
tag_size = _TagSize(field_number)
if is_packed:
local_VarintSize = _VarintSize
def PackedFieldSize(value):
result = 0
for element in value:
result += compute_value_size(modify_value(element))
return result + local_VarintSize(result) + tag_size
return PackedFieldSize
elif is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
result += compute_value_size(modify_value(element))
return result
return RepeatedFieldSize
else:
def FieldSize(value):
return tag_size + compute_value_size(modify_value(value))
return FieldSize
return SpecificSizer
def _FixedSizer(value_size):
"""Like _SimpleSizer except for a fixed-size field. The input is the size
of one value."""
def SpecificSizer(field_number, is_repeated, is_packed):
tag_size = _TagSize(field_number)
if is_packed:
local_VarintSize = _VarintSize
def PackedFieldSize(value):
result = len(value) * value_size
return result + local_VarintSize(result) + tag_size
return PackedFieldSize
elif is_repeated:
element_size = value_size + tag_size
def RepeatedFieldSize(value):
return len(value) * element_size
return RepeatedFieldSize
else:
field_size = value_size + tag_size
def FieldSize(value):
return field_size
return FieldSize
return SpecificSizer
# ====================================================================
# Here we declare a sizer constructor for each field type. Each "sizer
# constructor" is a function that takes (field_number, is_repeated, is_packed)
# as parameters and returns a sizer, which in turn takes a field value as
# a parameter and returns its encoded size.
Int32Sizer = Int64Sizer = EnumSizer = _SimpleSizer(_SignedVarintSize)
UInt32Sizer = UInt64Sizer = _SimpleSizer(_VarintSize)
SInt32Sizer = SInt64Sizer = _ModifiedSizer(
_SignedVarintSize, wire_format.ZigZagEncode)
Fixed32Sizer = SFixed32Sizer = FloatSizer = _FixedSizer(4)
Fixed64Sizer = SFixed64Sizer = DoubleSizer = _FixedSizer(8)
BoolSizer = _FixedSizer(1)
def StringSizer(field_number, is_repeated, is_packed):
"""Returns a sizer for a string field."""
tag_size = _TagSize(field_number)
local_VarintSize = _VarintSize
local_len = len
assert not is_packed
if is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
l = local_len(element.encode('utf-8'))
result += local_VarintSize(l) + l
return result
return RepeatedFieldSize
else:
def FieldSize(value):
l = local_len(value.encode('utf-8'))
return tag_size + local_VarintSize(l) + l
return FieldSize
def BytesSizer(field_number, is_repeated, is_packed):
"""Returns a sizer for a bytes field."""
tag_size = _TagSize(field_number)
local_VarintSize = _VarintSize
local_len = len
assert not is_packed
if is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
l = local_len(element)
result += local_VarintSize(l) + l
return result
return RepeatedFieldSize
else:
def FieldSize(value):
l = local_len(value)
return tag_size + local_VarintSize(l) + l
return FieldSize
def GroupSizer(field_number, is_repeated, is_packed):
"""Returns a sizer for a group field."""
tag_size = _TagSize(field_number) * 2
assert not is_packed
if is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
result += element.ByteSize()
return result
return RepeatedFieldSize
else:
def FieldSize(value):
return tag_size + value.ByteSize()
return FieldSize
def MessageSizer(field_number, is_repeated, is_packed):
"""Returns a sizer for a message field."""
tag_size = _TagSize(field_number)
local_VarintSize = _VarintSize
assert not is_packed
if is_repeated:
def RepeatedFieldSize(value):
result = tag_size * len(value)
for element in value:
l = element.ByteSize()
result += local_VarintSize(l) + l
return result
return RepeatedFieldSize
else:
def FieldSize(value):
l = value.ByteSize()
return tag_size + local_VarintSize(l) + l
return FieldSize
# --------------------------------------------------------------------
# MessageSet is special.
def MessageSetItemSizer(field_number):
"""Returns a sizer for extensions of MessageSet.
The message set message looks like this:
message MessageSet {
repeated group Item = 1 {
required int32 type_id = 2;
required string message = 3;
}
}
"""
static_size = (_TagSize(1) * 2 + _TagSize(2) + _VarintSize(field_number) +
_TagSize(3))
local_VarintSize = _VarintSize
def FieldSize(value):
l = value.ByteSize()
return static_size + local_VarintSize(l) + l
return FieldSize
# ====================================================================
# Encoders!
def _VarintEncoder():
"""Return an encoder for a basic varint value (does not include tag)."""
local_chr = chr
def EncodeVarint(write, value):
bits = value & 0x7f
value >>= 7
while value:
write(local_chr(0x80|bits))
bits = value & 0x7f
value >>= 7
return write(local_chr(bits))
return EncodeVarint
def _SignedVarintEncoder():
"""Return an encoder for a basic signed varint value (does not include
tag)."""
local_chr = chr
def EncodeSignedVarint(write, value):
if value < 0:
value += (1 << 64)
bits = value & 0x7f
value >>= 7
while value:
write(local_chr(0x80|bits))
bits = value & 0x7f
value >>= 7
return write(local_chr(bits))
return EncodeSignedVarint
_EncodeVarint = _VarintEncoder()
_EncodeSignedVarint = _SignedVarintEncoder()
def _VarintBytes(value):
"""Encode the given integer as a varint and return the bytes. This is only
called at startup time so it doesn't need to be fast."""
pieces = []
_EncodeVarint(pieces.append, value)
return "".join(pieces)
def TagBytes(field_number, wire_type):
"""Encode the given tag and return the bytes. Only called at startup."""
return _VarintBytes(wire_format.PackTag(field_number, wire_type))
# --------------------------------------------------------------------
# As with sizers (see above), we have a number of common encoder
# implementations.
def _SimpleEncoder(wire_type, encode_value, compute_value_size):
"""Return a constructor for an encoder for fields of a particular type.
Args:
wire_type: The field's wire type, for encoding tags.
encode_value: A function which encodes an individual value, e.g.
_EncodeVarint().
compute_value_size: A function which computes the size of an individual
value, e.g. _VarintSize().
"""
def SpecificEncoder(field_number, is_repeated, is_packed):
if is_packed:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
def EncodePackedField(write, value):
write(tag_bytes)
size = 0
for element in value:
size += compute_value_size(element)
local_EncodeVarint(write, size)
for element in value:
encode_value(write, element)
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeRepeatedField(write, value):
for element in value:
write(tag_bytes)
encode_value(write, element)
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeField(write, value):
write(tag_bytes)
return encode_value(write, value)
return EncodeField
return SpecificEncoder
def _ModifiedEncoder(wire_type, encode_value, compute_value_size, modify_value):
"""Like SimpleEncoder but additionally invokes modify_value on every value
before passing it to encode_value. Usually modify_value is ZigZagEncode."""
def SpecificEncoder(field_number, is_repeated, is_packed):
if is_packed:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
def EncodePackedField(write, value):
write(tag_bytes)
size = 0
for element in value:
size += compute_value_size(modify_value(element))
local_EncodeVarint(write, size)
for element in value:
encode_value(write, modify_value(element))
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeRepeatedField(write, value):
for element in value:
write(tag_bytes)
encode_value(write, modify_value(element))
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeField(write, value):
write(tag_bytes)
return encode_value(write, modify_value(value))
return EncodeField
return SpecificEncoder
def _StructPackEncoder(wire_type, format):
"""Return a constructor for an encoder for a fixed-width field.
Args:
wire_type: The field's wire type, for encoding tags.
format: The format string to pass to struct.pack().
"""
value_size = struct.calcsize(format)
def SpecificEncoder(field_number, is_repeated, is_packed):
local_struct_pack = struct.pack
if is_packed:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
def EncodePackedField(write, value):
write(tag_bytes)
local_EncodeVarint(write, len(value) * value_size)
for element in value:
write(local_struct_pack(format, element))
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeRepeatedField(write, value):
for element in value:
write(tag_bytes)
write(local_struct_pack(format, element))
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeField(write, value):
write(tag_bytes)
return write(local_struct_pack(format, value))
return EncodeField
return SpecificEncoder
def _FloatingPointEncoder(wire_type, format):
"""Return a constructor for an encoder for float fields.
This is like StructPackEncoder, but catches errors that may be due to
passing non-finite floating-point values to struct.pack, and makes a
second attempt to encode those values.
Args:
wire_type: The field's wire type, for encoding tags.
format: The format string to pass to struct.pack().
"""
value_size = struct.calcsize(format)
if value_size == 4:
def EncodeNonFiniteOrRaise(write, value):
# Remember that the serialized form uses little-endian byte order.
if value == _POS_INF:
write('\x00\x00\x80\x7F')
elif value == _NEG_INF:
write('\x00\x00\x80\xFF')
elif value != value: # NaN
write('\x00\x00\xC0\x7F')
else:
raise
elif value_size == 8:
def EncodeNonFiniteOrRaise(write, value):
if value == _POS_INF:
write('\x00\x00\x00\x00\x00\x00\xF0\x7F')
elif value == _NEG_INF:
write('\x00\x00\x00\x00\x00\x00\xF0\xFF')
elif value != value: # NaN
write('\x00\x00\x00\x00\x00\x00\xF8\x7F')
else:
raise
else:
raise ValueError('Can\'t encode floating-point values that are '
'%d bytes long (only 4 or 8)' % value_size)
def SpecificEncoder(field_number, is_repeated, is_packed):
local_struct_pack = struct.pack
if is_packed:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
def EncodePackedField(write, value):
write(tag_bytes)
local_EncodeVarint(write, len(value) * value_size)
for element in value:
# This try/except block is going to be faster than any code that
# we could write to check whether element is finite.
try:
write(local_struct_pack(format, element))
except SystemError:
EncodeNonFiniteOrRaise(write, element)
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeRepeatedField(write, value):
for element in value:
write(tag_bytes)
try:
write(local_struct_pack(format, element))
except SystemError:
EncodeNonFiniteOrRaise(write, element)
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_type)
def EncodeField(write, value):
write(tag_bytes)
try:
write(local_struct_pack(format, value))
except SystemError:
EncodeNonFiniteOrRaise(write, value)
return EncodeField
return SpecificEncoder
# ====================================================================
# Here we declare an encoder constructor for each field type. These work
# very similarly to sizer constructors, described earlier.
Int32Encoder = Int64Encoder = EnumEncoder = _SimpleEncoder(
wire_format.WIRETYPE_VARINT, _EncodeSignedVarint, _SignedVarintSize)
UInt32Encoder = UInt64Encoder = _SimpleEncoder(
wire_format.WIRETYPE_VARINT, _EncodeVarint, _VarintSize)
SInt32Encoder = SInt64Encoder = _ModifiedEncoder(
wire_format.WIRETYPE_VARINT, _EncodeVarint, _VarintSize,
wire_format.ZigZagEncode)
# Note that Python conveniently guarantees that when using the '<' prefix on
# formats, they will also have the same size across all platforms (as opposed
# to without the prefix, where their sizes depend on the C compiler's basic
# type sizes).
Fixed32Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED32, '<I')
Fixed64Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED64, '<Q')
SFixed32Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED32, '<i')
SFixed64Encoder = _StructPackEncoder(wire_format.WIRETYPE_FIXED64, '<q')
FloatEncoder = _FloatingPointEncoder(wire_format.WIRETYPE_FIXED32, '<f')
DoubleEncoder = _FloatingPointEncoder(wire_format.WIRETYPE_FIXED64, '<d')
def BoolEncoder(field_number, is_repeated, is_packed):
"""Returns an encoder for a boolean field."""
false_byte = chr(0)
true_byte = chr(1)
if is_packed:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
def EncodePackedField(write, value):
write(tag_bytes)
local_EncodeVarint(write, len(value))
for element in value:
if element:
write(true_byte)
else:
write(false_byte)
return EncodePackedField
elif is_repeated:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
def EncodeRepeatedField(write, value):
for element in value:
write(tag_bytes)
if element:
write(true_byte)
else:
write(false_byte)
return EncodeRepeatedField
else:
tag_bytes = TagBytes(field_number, wire_format.WIRETYPE_VARINT)
def EncodeField(write, value):
write(tag_bytes)
if value:
return write(true_byte)
return write(false_byte)
return EncodeField
def StringEncoder(field_number, is_repeated, is_packed):
"""Returns an encoder for a string field."""
tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
local_len = len
assert not is_packed
if is_repeated:
def EncodeRepeatedField(write, value):
for element in value:
encoded = element.encode('utf-8')
write(tag)
local_EncodeVarint(write, local_len(encoded))
write(encoded)
return EncodeRepeatedField
else:
def EncodeField(write, value):
encoded = value.encode('utf-8')
write(tag)
local_EncodeVarint(write, local_len(encoded))
return write(encoded)
return EncodeField
def BytesEncoder(field_number, is_repeated, is_packed):
"""Returns an encoder for a bytes field."""
tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
local_len = len
assert not is_packed
if is_repeated:
def EncodeRepeatedField(write, value):
for element in value:
write(tag)
local_EncodeVarint(write, local_len(element))
write(element)
return EncodeRepeatedField
else:
def EncodeField(write, value):
write(tag)
local_EncodeVarint(write, local_len(value))
return write(value)
return EncodeField
def GroupEncoder(field_number, is_repeated, is_packed):
"""Returns an encoder for a group field."""
start_tag = TagBytes(field_number, wire_format.WIRETYPE_START_GROUP)
end_tag = TagBytes(field_number, wire_format.WIRETYPE_END_GROUP)
assert not is_packed
if is_repeated:
def EncodeRepeatedField(write, value):
for element in value:
write(start_tag)
element._InternalSerialize(write)
write(end_tag)
return EncodeRepeatedField
else:
def EncodeField(write, value):
write(start_tag)
value._InternalSerialize(write)
return write(end_tag)
return EncodeField
def MessageEncoder(field_number, is_repeated, is_packed):
"""Returns an encoder for a message field."""
tag = TagBytes(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
local_EncodeVarint = _EncodeVarint
assert not is_packed
if is_repeated:
def EncodeRepeatedField(write, value):
for element in value:
write(tag)
local_EncodeVarint(write, element.ByteSize())
element._InternalSerialize(write)
return EncodeRepeatedField
else:
def EncodeField(write, value):
write(tag)
local_EncodeVarint(write, value.ByteSize())
return value._InternalSerialize(write)
return EncodeField
# --------------------------------------------------------------------
# As before, MessageSet is special.
def MessageSetItemEncoder(field_number):
"""Encoder for extensions of MessageSet.
The message set message looks like this:
message MessageSet {
repeated group Item = 1 {
required int32 type_id = 2;
required string message = 3;
}
}
"""
start_bytes = "".join([
TagBytes(1, wire_format.WIRETYPE_START_GROUP),
TagBytes(2, wire_format.WIRETYPE_VARINT),
_VarintBytes(field_number),
TagBytes(3, wire_format.WIRETYPE_LENGTH_DELIMITED)])
end_bytes = TagBytes(1, wire_format.WIRETYPE_END_GROUP)
local_EncodeVarint = _EncodeVarint
def EncodeField(write, value):
write(start_bytes)
local_EncodeVarint(write, value.ByteSize())
value._InternalSerialize(write)
return write(end_bytes)
return EncodeField
| agpl-3.0 | [
3,
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
3034,
367,
2644,
4113,
1245,
1979,
22337,
14,
199,
199,
6906,
314,
9661,
367,
2644,
4036,
11461,
4113,
901,
730,
199,
9924,
1373,
402,
314,
959,
14095,
11799,
2943,
14,
199,
199,
2765,
1233,
365,
19829,
370,
6675,
314,
2018,
12693,
1159,
10238,
370,
314,
199,
9368,
14,
199,
199,
1918,
5678,
16819,
365,
626,
737,
14210,
900,
12,
367,
4036,
901,
334,
73,
14,
69,
14,
4036,
199,
8510,
9,
781,
6982,
2877,
3423,
26,
221,
282,
298,
19158,
2,
436,
376,
298,
9347,
1674,
221,
710,
199,
19158,
6181,
282,
574,
402,
642,
901,
1159,
730,
436,
21445,
2399,
3696,
1568,
14,
221,
710,
199,
9347,
6181,
282,
7060,
805,
436,
282,
574,
14,
221,
2779,
3752,
83,
314,
574,
1901,
3696,
199,
5465,
436,
29761,
314,
7060,
805,
370,
2218,
5204,
3326,
14,
221,
26914,
314,
199,
5491,
805,
365,
314,
2218,
342,
1083,
402,
282,
15073,
14,
199,
199,
6004,
862,
370,
886,
465,
8298,
1736,
465,
3962,
1380,
22048,
314,
7060,
436,
314,
199,
19158,
7830,
2419,
1380,
6358,
3062,
14,
221,
1010,
6770,
26,
199,
10,
2136,
1331,
1263,
4346,
2288,
3423,
370,
2257,
2860,
12,
880,
626,
781,
886,
440,
1929,
523,
370,
886,
7918,
590,
2288,
1817,
16807,
737,
8836,
14,
199,
10,
20046,
590,
12,
781,
862,
370,
886,
1263,
2225,
16807,
737,
14210,
900,
340,
3962,
14,
199,
10,
18414,
901,
1159,
1947,
365,
5737,
370,
2783,
737,
14210,
12,
3967,
652,
883,
1133,
1570,
737,
523,
8836,
14,
199,
10,
2816,
12359,
3931,
402,
314,
901,
1568,
781,
883,
4526,
737,
14210,
12,
781,
886,
14,
199,
10,
2136,
627,
27403,
10,
26994,
1233,
340,
9689,
880,
3955,
1852,
314,
1233,
26200,
436,
440,
26994,
523,
1630,
440,
330,
300,
848,
2739,
4634,
8298,
14,
221,
2104,
2893,
12,
10295,
83,
367,
10877,
1504,
886,
523,
440,
2951,
1240,
314,
10295,
83,
367,
15823,
1504,
315,
282,
4438,
2952,
642,
3955,
523,
1050,
376,
2402,
805,
1240,
24075,
367,
4036,
4438,
8494,
27,
3140,
12,
781,
523,
10250,
8308,
314,
2849,
13,
585,
10295,
1901,
314,
4438,
14,
199,
10,
982,
282,
2018,
805,
1127,
5618,
282,
372,
5164,
12,
2018,
5965,
12821,
523,
15794,
370,
4560,
314,
754,
402,
314,
2061,
5164,
2331,
314,
3464,
12,
6675,
523,
488,
14602,
314,
3464,
12,
436,
2066,
372,
626,
14,
221,
982,
781,
7710,
2793,
1133,
10296,
4052,
523,
574,
365,
2138,
12,
2066,
781,
883,
3354,
2877,
15794,
701,
8152,
314,
523,
754,
402,
314,
2061,
5164,
14,
221,
2779,
10734,
9627,
9745,
1325,
652,
22577,
14,
199,
10,
2136,
5534,
626,
730,
436,
10461,
7907,
965,
21056,
737,
282,
10948,
2166,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
75,
484,
265,
32,
3098,
14,
957,
334,
43,
484,
265,
21084,
983,
3171,
199,
199,
646,
2702,
199,
504,
6233,
14,
7204,
14,
4672,
492,
11799,
63,
908,
421,
199,
3,
961,
911,
15784,
436,
12850,
8649,
473,
29146,
13,
13332,
298,
262,
9693,
1674,
221,
2136,
3955,
675,
199,
3,
298,
1609,
360,
4904,
19124,
1325,
652,
3181,
1133,
1736,
641,
5417,
876,
13,
4718,
13,
18,
14,
22,
14,
199,
63,
9263,
63,
11384,
275,
413,
69,
9943,
199,
63,
31254,
63,
11384,
275,
446,
63,
9263,
63,
11384,
421,
199,
318,
485,
20151,
2320,
8,
585,
304,
523,
408,
8564,
314,
1568,
402,
282,
2729,
442,
574,
1041,
523,
340,
574,
2695,
378,
88,
23,
70,
26,
372,
413,
523,
340,
574,
2695,
378,
88,
19,
18190,
26,
372,
499,
523,
340,
574,
2695,
378,
88,
17,
4717,
70,
26,
372,
650,
523,
340,
574,
2695,
378,
3581,
4717,
70,
26,
372,
841,
523,
340,
574,
2695,
378,
88,
23,
15798,
26,
372,
959,
523,
340,
574,
2695,
378,
88,
19,
4717,
12596,
26,
372,
1227,
523,
340,
574,
2695,
378,
88,
17,
15798,
4717,
26,
372,
1520,
523,
340,
574,
2695,
378,
3581,
15798,
4717,
26,
372,
1695,
523,
340,
574,
2695,
378,
88,
23,
15798,
12596,
70,
26,
372,
1749,
523,
372,
1616,
421,
199,
318,
485
] | [
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
3034,
367,
2644,
4113,
1245,
1979,
22337,
14,
199,
199,
6906,
314,
9661,
367,
2644,
4036,
11461,
4113,
901,
730,
199,
9924,
1373,
402,
314,
959,
14095,
11799,
2943,
14,
199,
199,
2765,
1233,
365,
19829,
370,
6675,
314,
2018,
12693,
1159,
10238,
370,
314,
199,
9368,
14,
199,
199,
1918,
5678,
16819,
365,
626,
737,
14210,
900,
12,
367,
4036,
901,
334,
73,
14,
69,
14,
4036,
199,
8510,
9,
781,
6982,
2877,
3423,
26,
221,
282,
298,
19158,
2,
436,
376,
298,
9347,
1674,
221,
710,
199,
19158,
6181,
282,
574,
402,
642,
901,
1159,
730,
436,
21445,
2399,
3696,
1568,
14,
221,
710,
199,
9347,
6181,
282,
7060,
805,
436,
282,
574,
14,
221,
2779,
3752,
83,
314,
574,
1901,
3696,
199,
5465,
436,
29761,
314,
7060,
805,
370,
2218,
5204,
3326,
14,
221,
26914,
314,
199,
5491,
805,
365,
314,
2218,
342,
1083,
402,
282,
15073,
14,
199,
199,
6004,
862,
370,
886,
465,
8298,
1736,
465,
3962,
1380,
22048,
314,
7060,
436,
314,
199,
19158,
7830,
2419,
1380,
6358,
3062,
14,
221,
1010,
6770,
26,
199,
10,
2136,
1331,
1263,
4346,
2288,
3423,
370,
2257,
2860,
12,
880,
626,
781,
886,
440,
1929,
523,
370,
886,
7918,
590,
2288,
1817,
16807,
737,
8836,
14,
199,
10,
20046,
590,
12,
781,
862,
370,
886,
1263,
2225,
16807,
737,
14210,
900,
340,
3962,
14,
199,
10,
18414,
901,
1159,
1947,
365,
5737,
370,
2783,
737,
14210,
12,
3967,
652,
883,
1133,
1570,
737,
523,
8836,
14,
199,
10,
2816,
12359,
3931,
402,
314,
901,
1568,
781,
883,
4526,
737,
14210,
12,
781,
886,
14,
199,
10,
2136,
627,
27403,
10,
26994,
1233,
340,
9689,
880,
3955,
1852,
314,
1233,
26200,
436,
440,
26994,
523,
1630,
440,
330,
300,
848,
2739,
4634,
8298,
14,
221,
2104,
2893,
12,
10295,
83,
367,
10877,
1504,
886,
523,
440,
2951,
1240,
314,
10295,
83,
367,
15823,
1504,
315,
282,
4438,
2952,
642,
3955,
523,
1050,
376,
2402,
805,
1240,
24075,
367,
4036,
4438,
8494,
27,
3140,
12,
781,
523,
10250,
8308,
314,
2849,
13,
585,
10295,
1901,
314,
4438,
14,
199,
10,
982,
282,
2018,
805,
1127,
5618,
282,
372,
5164,
12,
2018,
5965,
12821,
523,
15794,
370,
4560,
314,
754,
402,
314,
2061,
5164,
2331,
314,
3464,
12,
6675,
523,
488,
14602,
314,
3464,
12,
436,
2066,
372,
626,
14,
221,
982,
781,
7710,
2793,
1133,
10296,
4052,
523,
574,
365,
2138,
12,
2066,
781,
883,
3354,
2877,
15794,
701,
8152,
314,
523,
754,
402,
314,
2061,
5164,
14,
221,
2779,
10734,
9627,
9745,
1325,
652,
22577,
14,
199,
10,
2136,
5534,
626,
730,
436,
10461,
7907,
965,
21056,
737,
282,
10948,
2166,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
75,
484,
265,
32,
3098,
14,
957,
334,
43,
484,
265,
21084,
983,
3171,
199,
199,
646,
2702,
199,
504,
6233,
14,
7204,
14,
4672,
492,
11799,
63,
908,
421,
199,
3,
961,
911,
15784,
436,
12850,
8649,
473,
29146,
13,
13332,
298,
262,
9693,
1674,
221,
2136,
3955,
675,
199,
3,
298,
1609,
360,
4904,
19124,
1325,
652,
3181,
1133,
1736,
641,
5417,
876,
13,
4718,
13,
18,
14,
22,
14,
199,
63,
9263,
63,
11384,
275,
413,
69,
9943,
199,
63,
31254,
63,
11384,
275,
446,
63,
9263,
63,
11384,
421,
199,
318,
485,
20151,
2320,
8,
585,
304,
523,
408,
8564,
314,
1568,
402,
282,
2729,
442,
574,
1041,
523,
340,
574,
2695,
378,
88,
23,
70,
26,
372,
413,
523,
340,
574,
2695,
378,
88,
19,
18190,
26,
372,
499,
523,
340,
574,
2695,
378,
88,
17,
4717,
70,
26,
372,
650,
523,
340,
574,
2695,
378,
3581,
4717,
70,
26,
372,
841,
523,
340,
574,
2695,
378,
88,
23,
15798,
26,
372,
959,
523,
340,
574,
2695,
378,
88,
19,
4717,
12596,
26,
372,
1227,
523,
340,
574,
2695,
378,
88,
17,
15798,
4717,
26,
372,
1520,
523,
340,
574,
2695,
378,
3581,
15798,
4717,
26,
372,
1695,
523,
340,
574,
2695,
378,
88,
23,
15798,
12596,
70,
26,
372,
1749,
523,
372,
1616,
421,
199,
318,
485,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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active, Audiencia, Passive
from popolo.models import Identifier
import uuid
import unicodedata
from datetime import datetime
class ActivosCSVReader():
def parse_line(self, line):
active = Active()
active.name = unicode(line[3] + " " + line[4])
active.save()
seed = line[3] + line[4] + line[5] + line[7]
i = Identifier(identifier=line[0])
active.identifiers.add(i)
class AudienciasCSVReader():
def __init__(self, *args, **kwargs):
self.audiencia_records = {
}
def parse_audiencia_line(self, line):
audiencia = Audiencia()
audiencia.observations = line[9].decode('utf-8').strip()
audiencia.length = int(line[7])
date = datetime.strptime(line[6], '%Y-%m-%d %H:%M:%S')
audiencia.date = date
self.audiencia_records[line[0]] = audiencia
def parse_several_lines(self, lines):
lines.pop(0)
for line in lines:
self.parse_audiencia_line(line)
def parse_one_person(self, line, klass, pre_):
name = line[3].decode('utf-8').strip() + u" " + line[4].decode('utf-8').strip()
p = klass.objects.get(name=name)
i = Identifier(identifier=pre_ + line[0].decode('utf-8').strip())
p.identifiers.add(i)
def parse_one_passive_lines(self, line):
self.parse_one_person(line, Passive, 'passive_')
def parse_several_passives_lines(self, lines):
lines.pop(0)
for line in lines:
self.parse_one_passive_lines(line)
def parse_one_active_lines(self, line):
self.parse_one_person(line, Active, 'active_')
| agpl-3.0 | [
504,
560,
66,
991,
14,
992,
492,
23241,
12,
437,
14525,
287,
16521,
12,
510,
13202,
199,
504,
4560,
79,
320,
14,
992,
492,
23285,
199,
646,
5377,
199,
646,
23128,
199,
504,
2197,
492,
2197,
421,
199,
533,
21904,
86,
736,
19018,
5929,
837,
272,
347,
2198,
63,
604,
8,
277,
12,
1004,
304,
267,
4702,
275,
23241,
342,
267,
4702,
14,
354,
275,
2649,
8,
604,
59,
19,
61,
435,
298,
298,
435,
1004,
59,
20,
566,
267,
4702,
14,
2117,
342,
267,
6347,
275,
1004,
59,
19,
61,
435,
1004,
59,
20,
61,
435,
1004,
59,
21,
61,
435,
1004,
59,
23,
61,
267,
284,
275,
23285,
8,
5364,
29,
604,
59,
16,
566,
267,
4702,
14,
14227,
14,
525,
8,
73,
9,
421,
199,
533,
437,
14525,
287,
559,
305,
19018,
5929,
837,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
23577,
287,
16521,
63,
6502,
275,
469,
398,
789,
339,
347,
2198,
63,
23577,
287,
16521,
63,
604,
8,
277,
12,
1004,
304,
267,
10576,
328,
287,
16521,
275,
437,
14525,
287,
16521,
342,
267,
10576,
328,
287,
16521,
14,
2873,
12225,
275,
1004,
59,
25,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
267,
10576,
328,
287,
16521,
14,
1267,
275,
1109,
8,
604,
59,
23,
566,
267,
1434,
275,
2197,
14,
9866,
8,
604,
59,
22,
467,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
358,
267,
10576,
328,
287,
16521,
14,
602,
275,
1434,
267,
291,
14,
23577,
287,
16521,
63,
6502,
59,
604,
59,
16,
2677,
275,
10576,
328,
287,
16521,
339,
347,
2198,
63,
261,
422,
279,
63,
1278,
8,
277,
12,
2385,
304,
267,
2385,
14,
1935,
8,
16,
9,
267,
367,
1004,
315,
2385,
26,
288,
291,
14,
1122,
63,
23577,
287,
16521,
63,
604,
8,
604,
9,
339,
347,
2198,
63,
368,
63,
5484,
8,
277,
12,
1004,
12,
8531,
12,
876,
7822,
267,
536,
275,
1004,
59,
19,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
435,
399,
2,
298,
435,
1004,
59,
20,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
267,
299,
275,
8531,
14,
1462,
14,
362,
8,
354,
29,
354,
9,
267,
284,
275,
23285,
8,
5364,
29,
657,
63,
435,
1004,
59,
16,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
1012,
267,
299,
14,
14227,
14,
525,
8,
73,
9,
339,
347,
2198,
63,
368,
63,
25166,
63,
1278,
8,
277,
12,
1004,
304,
267,
291,
14,
1122,
63,
368,
63,
5484,
8,
604,
12,
510,
13202,
12,
283,
25166,
15452,
339,
347,
2198,
63,
261,
422,
279,
63,
80,
2608,
2310,
63,
1278,
8,
277,
12,
2385,
304,
267,
2385,
14,
1935,
8,
16,
9,
267,
367,
1004,
315,
2385,
26,
288,
291,
14,
1122,
63,
368,
63,
25166,
63,
1278,
8,
604,
9,
339,
347,
2198,
63,
368,
63,
2682,
63,
1278,
8,
277,
12,
1004,
304,
267,
291,
14,
1122,
63,
368,
63,
5484,
8,
604,
12,
23241,
12,
283,
2682,
15452,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
560,
66,
991,
14,
992,
492,
23241,
12,
437,
14525,
287,
16521,
12,
510,
13202,
199,
504,
4560,
79,
320,
14,
992,
492,
23285,
199,
646,
5377,
199,
646,
23128,
199,
504,
2197,
492,
2197,
421,
199,
533,
21904,
86,
736,
19018,
5929,
837,
272,
347,
2198,
63,
604,
8,
277,
12,
1004,
304,
267,
4702,
275,
23241,
342,
267,
4702,
14,
354,
275,
2649,
8,
604,
59,
19,
61,
435,
298,
298,
435,
1004,
59,
20,
566,
267,
4702,
14,
2117,
342,
267,
6347,
275,
1004,
59,
19,
61,
435,
1004,
59,
20,
61,
435,
1004,
59,
21,
61,
435,
1004,
59,
23,
61,
267,
284,
275,
23285,
8,
5364,
29,
604,
59,
16,
566,
267,
4702,
14,
14227,
14,
525,
8,
73,
9,
421,
199,
533,
437,
14525,
287,
559,
305,
19018,
5929,
837,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
14,
23577,
287,
16521,
63,
6502,
275,
469,
398,
789,
339,
347,
2198,
63,
23577,
287,
16521,
63,
604,
8,
277,
12,
1004,
304,
267,
10576,
328,
287,
16521,
275,
437,
14525,
287,
16521,
342,
267,
10576,
328,
287,
16521,
14,
2873,
12225,
275,
1004,
59,
25,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
267,
10576,
328,
287,
16521,
14,
1267,
275,
1109,
8,
604,
59,
23,
566,
267,
1434,
275,
2197,
14,
9866,
8,
604,
59,
22,
467,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
358,
267,
10576,
328,
287,
16521,
14,
602,
275,
1434,
267,
291,
14,
23577,
287,
16521,
63,
6502,
59,
604,
59,
16,
2677,
275,
10576,
328,
287,
16521,
339,
347,
2198,
63,
261,
422,
279,
63,
1278,
8,
277,
12,
2385,
304,
267,
2385,
14,
1935,
8,
16,
9,
267,
367,
1004,
315,
2385,
26,
288,
291,
14,
1122,
63,
23577,
287,
16521,
63,
604,
8,
604,
9,
339,
347,
2198,
63,
368,
63,
5484,
8,
277,
12,
1004,
12,
8531,
12,
876,
7822,
267,
536,
275,
1004,
59,
19,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
435,
399,
2,
298,
435,
1004,
59,
20,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
342,
267,
299,
275,
8531,
14,
1462,
14,
362,
8,
354,
29,
354,
9,
267,
284,
275,
23285,
8,
5364,
29,
657,
63,
435,
1004,
59,
16,
1055,
2708,
360,
1624,
13,
24,
1959,
1913,
1012,
267,
299,
14,
14227,
14,
525,
8,
73,
9,
339,
347,
2198,
63,
368,
63,
25166,
63,
1278,
8,
277,
12,
1004,
304,
267,
291,
14,
1122,
63,
368,
63,
5484,
8,
604,
12,
510,
13202,
12,
283,
25166,
15452,
339,
347,
2198,
63,
261,
422,
279,
63,
80,
2608,
2310,
63,
1278,
8,
277,
12,
2385,
304,
267,
2385,
14,
1935,
8,
16,
9,
267,
367,
1004,
315,
2385,
26,
288,
291,
14,
1122,
63,
368,
63,
25166,
63,
1278,
8,
604,
9,
339,
347,
2198,
63,
368,
63,
2682,
63,
1278,
8,
277,
12,
1004,
304,
267,
291,
14,
1122,
63,
368,
63,
5484,
8,
604,
12,
23241,
12,
283,
2682,
15452,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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