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
|
|---|---|---|---|---|---|---|---|---|
minhphung171093/OpenERP_V7
|
openerp/addons/auth_openid/__openerp__.py
|
58
|
1668
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'OpenID Authentification',
'version': '2.0',
'category': 'Tools',
'description': """
Allow users to login through OpenID.
====================================
""",
'author': 'OpenERP s.a.',
'maintainer': 'OpenERP s.a.',
'website': 'http://www.openerp.com',
'depends': ['base', 'web'],
'data': ['res_users.xml'],
'js': ['static/src/js/auth_openid.js'],
'css': ['static/src/css/openid.css'],
'qweb': ['static/src/xml/auth_openid.xml'],
'external_dependencies': {
'python' : ['openid'],
},
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
30244,
3590,
287,
3793,
297,
272,
283,
1023,
356,
283,
18,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
7852,
4390,
370,
4676,
4012,
25463,
14,
199,
2486,
532,
199,
7208,
272,
283,
2502,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
26665,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
2520,
995,
272,
283,
576,
356,
788,
470,
63,
3707,
14,
1652,
995,
272,
283,
3596,
356,
788,
1986,
15,
2164,
15,
3596,
15,
1178,
63,
15403,
14,
3596,
995,
272,
283,
3919,
356,
788,
1986,
15,
2164,
15,
3919,
15,
15403,
14,
3919,
995,
272,
283,
22600,
356,
788,
1986,
15,
2164,
15,
1652,
15,
1178,
63,
15403,
14,
1652,
995,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
7,
520,
788,
15403,
995,
272,
1660,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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
] |
[
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,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
421,
199,
91,
272,
283,
354,
356,
283,
30244,
3590,
287,
3793,
297,
272,
283,
1023,
356,
283,
18,
14,
16,
297,
272,
283,
3710,
356,
283,
11654,
297,
272,
283,
1802,
356,
408,
199,
7852,
4390,
370,
4676,
4012,
25463,
14,
199,
2486,
532,
199,
7208,
272,
283,
2502,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
26665,
356,
283,
25347,
308,
14,
65,
3130,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
8912,
356,
788,
1095,
297,
283,
2520,
995,
272,
283,
576,
356,
788,
470,
63,
3707,
14,
1652,
995,
272,
283,
3596,
356,
788,
1986,
15,
2164,
15,
3596,
15,
1178,
63,
15403,
14,
3596,
995,
272,
283,
3919,
356,
788,
1986,
15,
2164,
15,
3919,
15,
15403,
14,
3919,
995,
272,
283,
22600,
356,
788,
1986,
15,
2164,
15,
1652,
15,
1178,
63,
15403,
14,
1652,
995,
272,
283,
5159,
63,
5714,
356,
469,
267,
283,
1548,
7,
520,
788,
15403,
995,
272,
1660,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jerrybai2009/WhereHows-1
|
metadata-etl/src/main/resources/jython/requests/packages/urllib3/util/timeout.py
|
713
|
9596
|
from __future__ import absolute_import
# The default socket timeout, used by httplib to indicate that no timeout was
# specified by the user
from socket import _GLOBAL_DEFAULT_TIMEOUT
import time
from ..exceptions import TimeoutStateError
# A sentinel value to indicate that no timeout was specified by the user in
# urllib3
_Default = object()
def current_time():
"""
Retrieve the current time. This function is mocked out in unit testing.
"""
return time.time()
class Timeout(object):
""" Timeout configuration.
Timeouts can be defined as a default for a pool::
timeout = Timeout(connect=2.0, read=7.0)
http = PoolManager(timeout=timeout)
response = http.request('GET', 'http://example.com/')
Or per-request (which overrides the default for the pool)::
response = http.request('GET', 'http://example.com/', timeout=Timeout(10))
Timeouts can be disabled by setting all the parameters to ``None``::
no_timeout = Timeout(connect=None, read=None)
response = http.request('GET', 'http://example.com/, timeout=no_timeout)
:param total:
This combines the connect and read timeouts into one; the read timeout
will be set to the time leftover from the connect attempt. In the
event that both a connect timeout and a total are specified, or a read
timeout and a total are specified, the shorter timeout will be applied.
Defaults to None.
:type total: integer, float, or None
:param connect:
The maximum amount of time to wait for a connection attempt to a server
to succeed. Omitting the parameter will default the connect timeout to
the system default, probably `the global default timeout in socket.py
<http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
None will set an infinite timeout for connection attempts.
:type connect: integer, float, or None
:param read:
The maximum amount of time to wait between consecutive
read operations for a response from the server. Omitting
the parameter will default the read timeout to the system
default, probably `the global default timeout in socket.py
<http://hg.python.org/cpython/file/603b4d593758/Lib/socket.py#l535>`_.
None will set an infinite timeout.
:type read: integer, float, or None
.. note::
Many factors can affect the total amount of time for urllib3 to return
an HTTP response.
For example, Python's DNS resolver does not obey the timeout specified
on the socket. Other factors that can affect total request time include
high CPU load, high swap, the program running at a low priority level,
or other behaviors.
In addition, the read and total timeouts only measure the time between
read operations on the socket connecting the client and the server,
not the total amount of time for the request to return a complete
response. For most requests, the timeout is raised because the server
has not sent the first byte in the specified time. This is not always
the case; if a server streams one byte every fifteen seconds, a timeout
of 20 seconds will not trigger, even though the request will take
several minutes to complete.
If your goal is to cut off any request after a set amount of wall clock
time, consider having a second "watcher" thread to cut off a slow
request.
"""
#: A sentinel object representing the default timeout value
DEFAULT_TIMEOUT = _GLOBAL_DEFAULT_TIMEOUT
def __init__(self, total=None, connect=_Default, read=_Default):
self._connect = self._validate_timeout(connect, 'connect')
self._read = self._validate_timeout(read, 'read')
self.total = self._validate_timeout(total, 'total')
self._start_connect = None
def __str__(self):
return '%s(connect=%r, read=%r, total=%r)' % (
type(self).__name__, self._connect, self._read, self.total)
@classmethod
def _validate_timeout(cls, value, name):
""" Check that a timeout attribute is valid.
:param value: The timeout value to validate
:param name: The name of the timeout attribute to validate. This is
used to specify in error messages.
:return: The validated and casted version of the given value.
:raises ValueError: If the type is not an integer or a float, or if it
is a numeric value less than zero.
"""
if value is _Default:
return cls.DEFAULT_TIMEOUT
if value is None or value is cls.DEFAULT_TIMEOUT:
return value
try:
float(value)
except (TypeError, ValueError):
raise ValueError("Timeout value %s was %s, but it must be an "
"int or float." % (name, value))
try:
if value < 0:
raise ValueError("Attempted to set %s timeout to %s, but the "
"timeout cannot be set to a value less "
"than 0." % (name, value))
except TypeError: # Python 3
raise ValueError("Timeout value %s was %s, but it must be an "
"int or float." % (name, value))
return value
@classmethod
def from_float(cls, timeout):
""" Create a new Timeout from a legacy timeout value.
The timeout value used by httplib.py sets the same timeout on the
connect(), and recv() socket requests. This creates a :class:`Timeout`
object that sets the individual timeouts to the ``timeout`` value
passed to this function.
:param timeout: The legacy timeout value.
:type timeout: integer, float, sentinel default object, or None
:return: Timeout object
:rtype: :class:`Timeout`
"""
return Timeout(read=timeout, connect=timeout)
def clone(self):
""" Create a copy of the timeout object
Timeout properties are stored per-pool but each request needs a fresh
Timeout object to ensure each one has its own start/stop configured.
:return: a copy of the timeout object
:rtype: :class:`Timeout`
"""
# We can't use copy.deepcopy because that will also create a new object
# for _GLOBAL_DEFAULT_TIMEOUT, which socket.py uses as a sentinel to
# detect the user default.
return Timeout(connect=self._connect, read=self._read,
total=self.total)
def start_connect(self):
""" Start the timeout clock, used during a connect() attempt
:raises urllib3.exceptions.TimeoutStateError: if you attempt
to start a timer that has been started already.
"""
if self._start_connect is not None:
raise TimeoutStateError("Timeout timer has already been started.")
self._start_connect = current_time()
return self._start_connect
def get_connect_duration(self):
""" Gets the time elapsed since the call to :meth:`start_connect`.
:return: Elapsed time.
:rtype: float
:raises urllib3.exceptions.TimeoutStateError: if you attempt
to get duration for a timer that hasn't been started.
"""
if self._start_connect is None:
raise TimeoutStateError("Can't get connect duration for timer "
"that has not started.")
return current_time() - self._start_connect
@property
def connect_timeout(self):
""" Get the value to use when setting a connection timeout.
This will be a positive float or integer, the value None
(never timeout), or the default system timeout.
:return: Connect timeout.
:rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
"""
if self.total is None:
return self._connect
if self._connect is None or self._connect is self.DEFAULT_TIMEOUT:
return self.total
return min(self._connect, self.total)
@property
def read_timeout(self):
""" Get the value for the read timeout.
This assumes some time has elapsed in the connection timeout and
computes the read timeout appropriately.
If self.total is set, the read timeout is dependent on the amount of
time taken by the connect timeout. If the connection time has not been
established, a :exc:`~urllib3.exceptions.TimeoutStateError` will be
raised.
:return: Value to use for the read timeout.
:rtype: int, float, :attr:`Timeout.DEFAULT_TIMEOUT` or None
:raises urllib3.exceptions.TimeoutStateError: If :meth:`start_connect`
has not yet been called on this object.
"""
if (self.total is not None and
self.total is not self.DEFAULT_TIMEOUT and
self._read is not None and
self._read is not self.DEFAULT_TIMEOUT):
# In case the connect timeout has not yet been established.
if self._start_connect is None:
return self._read
return max(0, min(self.total - self.get_connect_duration(),
self._read))
elif self.total is not None and self.total is not self.DEFAULT_TIMEOUT:
return max(0, self.total - self.get_connect_duration())
else:
return self._read
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
3,
710,
849,
2838,
2653,
12,
1202,
701,
8809,
370,
6623,
626,
949,
2653,
1990,
199,
3,
2013,
701,
314,
922,
199,
504,
2838,
492,
485,
13808,
63,
3472,
63,
8899,
199,
646,
900,
199,
199,
504,
2508,
3924,
492,
12878,
2223,
547,
199,
199,
3,
437,
13792,
574,
370,
6623,
626,
949,
2653,
1990,
2013,
701,
314,
922,
315,
199,
3,
4011,
19,
199,
63,
2698,
275,
909,
342,
421,
199,
318,
1453,
63,
521,
837,
272,
408,
272,
13939,
314,
1453,
900,
14,
961,
805,
365,
16991,
734,
315,
4137,
5343,
14,
272,
408,
272,
372,
900,
14,
521,
342,
421,
199,
533,
12878,
8,
785,
304,
272,
408,
12878,
2897,
14,
339,
12878,
83,
883,
506,
3247,
465,
282,
849,
367,
282,
4203,
447,
398,
2653,
275,
12878,
8,
2242,
29,
18,
14,
16,
12,
1586,
29,
23,
14,
16,
9,
267,
1455,
275,
15553,
2988,
8,
2593,
29,
2593,
9,
267,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
6217,
339,
4236,
1126,
13,
1069,
334,
6777,
10580,
314,
849,
367,
314,
4203,
304,
26,
398,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
3678,
2653,
29,
6372,
8,
709,
430,
339,
12878,
83,
883,
506,
6980,
701,
4260,
1006,
314,
2633,
370,
1124,
403,
1040,
447,
398,
949,
63,
2593,
275,
12878,
8,
2242,
29,
403,
12,
1586,
29,
403,
9,
267,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
15,
12,
2653,
29,
889,
63,
2593,
9,
2378,
520,
635,
3141,
26,
267,
961,
5300,
3746,
314,
4907,
436,
1586,
25870,
1901,
1373,
27,
314,
1586,
2653,
267,
911,
506,
663,
370,
314,
900,
32196,
687,
314,
4907,
7427,
14,
1010,
314,
267,
1566,
626,
3865,
282,
4907,
2653,
436,
282,
3141,
787,
2013,
12,
503,
282,
1586,
267,
2653,
436,
282,
3141,
787,
2013,
12,
314,
18299,
2653,
911,
506,
6781,
14,
398,
7827,
370,
488,
14,
339,
520,
466,
3141,
26,
3000,
12,
2069,
12,
503,
488,
339,
520,
635,
4907,
26,
267,
710,
5696,
5982,
402,
900,
370,
3618,
367,
282,
1950,
7427,
370,
282,
1654,
267,
370,
17961,
14,
593,
1147,
1337,
314,
2725,
911,
849,
314,
4907,
2653,
370,
267,
314,
2656,
849,
12,
8646,
658,
1589,
2288,
849,
2653,
315,
2838,
14,
647,
267,
665,
1014,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
493,
15,
30877,
66,
20,
68,
1427,
1401,
2010,
15,
4728,
15,
3450,
14,
647,
3,
76,
7920,
8637,
3754,
267,
488,
911,
663,
376,
15258,
2653,
367,
1950,
12454,
14,
339,
520,
466,
4907,
26,
3000,
12,
2069,
12,
503,
488,
339,
520,
635,
1586,
26,
267,
710,
5696,
5982,
402,
900,
370,
3618,
3382,
23376,
267,
1586,
5331,
367,
282,
1177,
687,
314,
1654,
14,
593,
1147,
1337,
267,
314,
2725,
911,
849,
314,
1586,
2653,
370,
314,
2656,
267,
849,
12,
8646,
658,
1589,
2288,
849,
2653,
315,
2838,
14,
647,
267,
665,
1014,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
493,
15,
30877,
66,
20,
68,
1427,
1401,
2010,
15,
4728,
15,
3450,
14,
647,
3,
76,
7920,
8637,
3754,
267,
488,
911,
663,
376,
15258,
2653,
14,
339,
520,
466,
1586,
26,
3000,
12,
2069,
12,
503,
488,
339,
2508,
5317,
447,
398,
15517,
17704,
883,
12787,
314,
3141,
5982,
402,
900,
367,
4011,
19,
370,
372,
267,
376,
3101,
1177,
14,
398,
2104,
2893,
12,
2018,
1159,
10237,
15611,
1630,
440,
312,
32236,
314,
2653,
2013,
267,
641,
314,
2838,
14,
5439,
17704,
626,
883,
12787,
3141,
1056,
900,
2387,
267,
4721,
11952,
2248,
12,
4721,
11413,
12,
314,
2240,
3879,
737,
282,
6465,
7464,
2166,
12,
267,
503,
1163,
5112,
1384,
14,
398,
1010,
10234,
12,
314,
1586,
436,
3141,
25870,
1454,
9775,
314,
900,
3382,
267,
1586,
5331,
641,
314,
2838,
18170,
314,
1890,
436,
314,
1654,
12,
267,
440,
314,
3141,
5982,
402,
900,
367,
314,
1056,
370,
372,
282,
4890,
267,
1177,
14,
2104,
4750,
4145,
12,
314,
2653,
365,
4915,
2952,
314,
1654,
267,
965,
440,
4847,
314,
1642,
3696,
315,
314,
2013,
900,
14,
961,
365,
440,
3544,
267,
314,
1930,
27,
340,
282,
1654,
13788,
1373,
3696,
4036,
289,
692,
25076,
4696,
12,
282,
2653,
267,
402,
3388,
4696,
911,
440,
6804,
12,
2755,
10617,
314,
1056,
911,
5452,
267,
9978,
9395,
370,
4890,
14,
398,
982,
2195,
14850,
365,
370,
10415,
2331,
1263,
1056,
2410,
282,
663,
5982,
402,
19882,
12516,
267,
900,
12,
11201,
9445,
282,
3499,
298,
22226,
2,
2462,
370,
10415,
2331,
282,
11999,
267,
1056,
14,
272,
408,
339,
6079,
437,
13792,
909,
6144,
314,
849,
2653,
574,
272,
6186,
63,
8899,
275,
485,
13808,
63,
3472,
63,
8899,
339,
347,
636,
826,
721,
277,
12,
3141,
29,
403,
12,
4907,
3699,
2698,
12,
1586,
3699,
2698,
304,
267,
291,
423,
2242,
275,
291,
423,
3502,
63,
2593,
8,
2242,
12,
283,
2242,
358,
267,
291,
423,
739,
275,
291,
423,
3502,
63,
2593,
8,
739,
12,
283,
739,
358,
267,
291,
14,
2923,
275,
291,
423,
3502,
63,
2593,
8,
2923,
12,
283,
2923,
358,
267,
291,
423,
928,
63,
2242,
275,
488,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
8,
2242,
2458,
82,
12,
1586,
2458,
82,
12,
3141,
2458,
82,
3171,
450,
334,
288,
730,
8,
277,
2843,
354,
3108,
291,
423,
2242,
12,
291,
423,
739,
12,
291,
14,
2923,
9,
339,
768,
3744,
272,
347,
485,
3502,
63,
2593,
8,
1886,
12,
574,
12,
536,
304,
267,
408,
2670,
626,
282,
2653,
2225,
365,
1686,
14,
398,
520,
635,
574,
26,
710,
2653,
574,
370,
4107,
267,
520,
635,
536,
26,
710,
536,
402,
314,
2653,
2225,
370,
4107,
14,
961,
365,
288,
1202,
370,
4165,
315,
1125,
3788,
14,
267,
520,
1107,
26,
710,
16468,
436,
14984,
471,
1015,
402,
314,
1627,
574,
14,
267,
520,
3536,
1722,
26,
982,
314,
730,
365,
440,
376,
3000,
503,
282,
2069,
12,
503,
340,
652,
288,
365,
282,
8950,
574
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
3,
710,
849,
2838,
2653,
12,
1202,
701,
8809,
370,
6623,
626,
949,
2653,
1990,
199,
3,
2013,
701,
314,
922,
199,
504,
2838,
492,
485,
13808,
63,
3472,
63,
8899,
199,
646,
900,
199,
199,
504,
2508,
3924,
492,
12878,
2223,
547,
199,
199,
3,
437,
13792,
574,
370,
6623,
626,
949,
2653,
1990,
2013,
701,
314,
922,
315,
199,
3,
4011,
19,
199,
63,
2698,
275,
909,
342,
421,
199,
318,
1453,
63,
521,
837,
272,
408,
272,
13939,
314,
1453,
900,
14,
961,
805,
365,
16991,
734,
315,
4137,
5343,
14,
272,
408,
272,
372,
900,
14,
521,
342,
421,
199,
533,
12878,
8,
785,
304,
272,
408,
12878,
2897,
14,
339,
12878,
83,
883,
506,
3247,
465,
282,
849,
367,
282,
4203,
447,
398,
2653,
275,
12878,
8,
2242,
29,
18,
14,
16,
12,
1586,
29,
23,
14,
16,
9,
267,
1455,
275,
15553,
2988,
8,
2593,
29,
2593,
9,
267,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
6217,
339,
4236,
1126,
13,
1069,
334,
6777,
10580,
314,
849,
367,
314,
4203,
304,
26,
398,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
3678,
2653,
29,
6372,
8,
709,
430,
339,
12878,
83,
883,
506,
6980,
701,
4260,
1006,
314,
2633,
370,
1124,
403,
1040,
447,
398,
949,
63,
2593,
275,
12878,
8,
2242,
29,
403,
12,
1586,
29,
403,
9,
267,
1177,
275,
1455,
14,
1069,
360,
2970,
297,
283,
1014,
921,
2694,
14,
957,
15,
12,
2653,
29,
889,
63,
2593,
9,
2378,
520,
635,
3141,
26,
267,
961,
5300,
3746,
314,
4907,
436,
1586,
25870,
1901,
1373,
27,
314,
1586,
2653,
267,
911,
506,
663,
370,
314,
900,
32196,
687,
314,
4907,
7427,
14,
1010,
314,
267,
1566,
626,
3865,
282,
4907,
2653,
436,
282,
3141,
787,
2013,
12,
503,
282,
1586,
267,
2653,
436,
282,
3141,
787,
2013,
12,
314,
18299,
2653,
911,
506,
6781,
14,
398,
7827,
370,
488,
14,
339,
520,
466,
3141,
26,
3000,
12,
2069,
12,
503,
488,
339,
520,
635,
4907,
26,
267,
710,
5696,
5982,
402,
900,
370,
3618,
367,
282,
1950,
7427,
370,
282,
1654,
267,
370,
17961,
14,
593,
1147,
1337,
314,
2725,
911,
849,
314,
4907,
2653,
370,
267,
314,
2656,
849,
12,
8646,
658,
1589,
2288,
849,
2653,
315,
2838,
14,
647,
267,
665,
1014,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
493,
15,
30877,
66,
20,
68,
1427,
1401,
2010,
15,
4728,
15,
3450,
14,
647,
3,
76,
7920,
8637,
3754,
267,
488,
911,
663,
376,
15258,
2653,
367,
1950,
12454,
14,
339,
520,
466,
4907,
26,
3000,
12,
2069,
12,
503,
488,
339,
520,
635,
1586,
26,
267,
710,
5696,
5982,
402,
900,
370,
3618,
3382,
23376,
267,
1586,
5331,
367,
282,
1177,
687,
314,
1654,
14,
593,
1147,
1337,
267,
314,
2725,
911,
849,
314,
1586,
2653,
370,
314,
2656,
267,
849,
12,
8646,
658,
1589,
2288,
849,
2653,
315,
2838,
14,
647,
267,
665,
1014,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
493,
15,
30877,
66,
20,
68,
1427,
1401,
2010,
15,
4728,
15,
3450,
14,
647,
3,
76,
7920,
8637,
3754,
267,
488,
911,
663,
376,
15258,
2653,
14,
339,
520,
466,
1586,
26,
3000,
12,
2069,
12,
503,
488,
339,
2508,
5317,
447,
398,
15517,
17704,
883,
12787,
314,
3141,
5982,
402,
900,
367,
4011,
19,
370,
372,
267,
376,
3101,
1177,
14,
398,
2104,
2893,
12,
2018,
1159,
10237,
15611,
1630,
440,
312,
32236,
314,
2653,
2013,
267,
641,
314,
2838,
14,
5439,
17704,
626,
883,
12787,
3141,
1056,
900,
2387,
267,
4721,
11952,
2248,
12,
4721,
11413,
12,
314,
2240,
3879,
737,
282,
6465,
7464,
2166,
12,
267,
503,
1163,
5112,
1384,
14,
398,
1010,
10234,
12,
314,
1586,
436,
3141,
25870,
1454,
9775,
314,
900,
3382,
267,
1586,
5331,
641,
314,
2838,
18170,
314,
1890,
436,
314,
1654,
12,
267,
440,
314,
3141,
5982,
402,
900,
367,
314,
1056,
370,
372,
282,
4890,
267,
1177,
14,
2104,
4750,
4145,
12,
314,
2653,
365,
4915,
2952,
314,
1654,
267,
965,
440,
4847,
314,
1642,
3696,
315,
314,
2013,
900,
14,
961,
365,
440,
3544,
267,
314,
1930,
27,
340,
282,
1654,
13788,
1373,
3696,
4036,
289,
692,
25076,
4696,
12,
282,
2653,
267,
402,
3388,
4696,
911,
440,
6804,
12,
2755,
10617,
314,
1056,
911,
5452,
267,
9978,
9395,
370,
4890,
14,
398,
982,
2195,
14850,
365,
370,
10415,
2331,
1263,
1056,
2410,
282,
663,
5982,
402,
19882,
12516,
267,
900,
12,
11201,
9445,
282,
3499,
298,
22226,
2,
2462,
370,
10415,
2331,
282,
11999,
267,
1056,
14,
272,
408,
339,
6079,
437,
13792,
909,
6144,
314,
849,
2653,
574,
272,
6186,
63,
8899,
275,
485,
13808,
63,
3472,
63,
8899,
339,
347,
636,
826,
721,
277,
12,
3141,
29,
403,
12,
4907,
3699,
2698,
12,
1586,
3699,
2698,
304,
267,
291,
423,
2242,
275,
291,
423,
3502,
63,
2593,
8,
2242,
12,
283,
2242,
358,
267,
291,
423,
739,
275,
291,
423,
3502,
63,
2593,
8,
739,
12,
283,
739,
358,
267,
291,
14,
2923,
275,
291,
423,
3502,
63,
2593,
8,
2923,
12,
283,
2923,
358,
267,
291,
423,
928,
63,
2242,
275,
488,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
8,
2242,
2458,
82,
12,
1586,
2458,
82,
12,
3141,
2458,
82,
3171,
450,
334,
288,
730,
8,
277,
2843,
354,
3108,
291,
423,
2242,
12,
291,
423,
739,
12,
291,
14,
2923,
9,
339,
768,
3744,
272,
347,
485,
3502,
63,
2593,
8,
1886,
12,
574,
12,
536,
304,
267,
408,
2670,
626,
282,
2653,
2225,
365,
1686,
14,
398,
520,
635,
574,
26,
710,
2653,
574,
370,
4107,
267,
520,
635,
536,
26,
710,
536,
402,
314,
2653,
2225,
370,
4107,
14,
961,
365,
288,
1202,
370,
4165,
315,
1125,
3788,
14,
267,
520,
1107,
26,
710,
16468,
436,
14984,
471,
1015,
402,
314,
1627,
574,
14,
267,
520,
3536,
1722,
26,
982,
314,
730,
365,
440,
376,
3000,
503,
282,
2069,
12,
503,
340,
652,
288,
365,
282,
8950,
574,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,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.py
|
58
|
29186
|
"""Dirac notation for states."""
from __future__ import print_function, division
from sympy import (cacheit, conjugate, Expr, Function, integrate, oo, sqrt,
Tuple)
from sympy.core.compatibility import u, range
from sympy.printing.pretty.stringpict import stringPict
from sympy.physics.quantum.qexpr import QExpr, dispatch_method
__all__ = [
'KetBase',
'BraBase',
'StateBase',
'State',
'Ket',
'Bra',
'TimeDepState',
'TimeDepBra',
'TimeDepKet',
'Wavefunction'
]
#-----------------------------------------------------------------------------
# States, bras and kets.
#-----------------------------------------------------------------------------
# ASCII brackets
_lbracket = "<"
_rbracket = ">"
_straight_bracket = "|"
# Unicode brackets
# MATHEMATICAL ANGLE BRACKETS
_lbracket_ucode = u("\N{MATHEMATICAL LEFT ANGLE BRACKET}")
_rbracket_ucode = u("\N{MATHEMATICAL RIGHT ANGLE BRACKET}")
# LIGHT VERTICAL BAR
_straight_bracket_ucode = u("\N{LIGHT VERTICAL BAR}")
# Other options for unicode printing of <, > and | for Dirac notation.
# LEFT-POINTING ANGLE BRACKET
# _lbracket = u"\u2329"
# _rbracket = u"\u232A"
# LEFT ANGLE BRACKET
# _lbracket = u"\u3008"
# _rbracket = u"\u3009"
# VERTICAL LINE
# _straight_bracket = u"\u007C"
class StateBase(QExpr):
"""Abstract base class for general abstract states in quantum mechanics.
All other state classes defined will need to inherit from this class. It
carries the basic structure for all other states such as dual, _eval_adjoint
and label.
This is an abstract base class and you should not instantiate it directly,
instead use State.
"""
@classmethod
def _operators_to_state(self, ops, **options):
""" Returns the eigenstate instance for the passed operators.
This method should be overridden in subclasses. It will handle being
passed either an Operator instance or set of Operator instances. It
should return the corresponding state INSTANCE or simply raise a
NotImplementedError. See cartesian.py for an example.
"""
raise NotImplementedError("Cannot map operators to states in this class. Method not implemented!")
def _state_to_operators(self, op_classes, **options):
""" Returns the operators which this state instance is an eigenstate
of.
This method should be overridden in subclasses. It will be called on
state instances and be passed the operator classes that we wish to make
into instances. The state instance will then transform the classes
appropriately, or raise a NotImplementedError if it cannot return
operator instances. See cartesian.py for examples,
"""
raise NotImplementedError(
"Cannot map this state to operators. Method not implemented!")
@property
def operators(self):
"""Return the operator(s) that this state is an eigenstate of"""
from .operatorset import state_to_operators # import internally to avoid circular import errors
return state_to_operators(self)
def _enumerate_state(self, num_states, **options):
raise NotImplementedError("Cannot enumerate this state!")
def _represent_default_basis(self, **options):
return self._represent(basis=self.operators)
#-------------------------------------------------------------------------
# Dagger/dual
#-------------------------------------------------------------------------
@property
def dual(self):
"""Return the dual state of this one."""
return self.dual_class()._new_rawargs(self.hilbert_space, *self.args)
@classmethod
def dual_class(self):
"""Return the class used to construt the dual."""
raise NotImplementedError(
'dual_class must be implemented in a subclass'
)
def _eval_adjoint(self):
"""Compute the dagger of this state using the dual."""
return self.dual
#-------------------------------------------------------------------------
# Printing
#-------------------------------------------------------------------------
def _pretty_brackets(self, height, use_unicode=True):
# Return pretty printed brackets for the state
# Ideally, this could be done by pform.parens but it does not support the angled < and >
# Setup for unicode vs ascii
if use_unicode:
lbracket, rbracket = self.lbracket_ucode, self.rbracket_ucode
slash, bslash, vert = u('\N{BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT}'), \
u('\N{BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT}'), \
u('\N{BOX DRAWINGS LIGHT VERTICAL}')
else:
lbracket, rbracket = self.lbracket, self.rbracket
slash, bslash, vert = '/', '\\', '|'
# If height is 1, just return brackets
if height == 1:
return stringPict(lbracket), stringPict(rbracket)
# Make height even
height += (height % 2)
brackets = []
for bracket in lbracket, rbracket:
# Create left bracket
if bracket in set([_lbracket, _lbracket_ucode]):
bracket_args = [ ' ' * (height//2 - i - 1) +
slash for i in range(height // 2)]
bracket_args.extend(
[ ' ' * i + bslash for i in range(height // 2)])
# Create right bracket
elif bracket in set([_rbracket, _rbracket_ucode]):
bracket_args = [ ' ' * i + bslash for i in range(height // 2)]
bracket_args.extend([ ' ' * (
height//2 - i - 1) + slash for i in range(height // 2)])
# Create straight bracket
elif bracket in set([_straight_bracket, _straight_bracket_ucode]):
bracket_args = [vert for i in range(height)]
else:
raise ValueError(bracket)
brackets.append(
stringPict('\n'.join(bracket_args), baseline=height//2))
return brackets
def _sympystr(self, printer, *args):
contents = self._print_contents(printer, *args)
return '%s%s%s' % (self.lbracket, contents, self.rbracket)
def _pretty(self, printer, *args):
from sympy.printing.pretty.stringpict import prettyForm
# Get brackets
pform = self._print_contents_pretty(printer, *args)
lbracket, rbracket = self._pretty_brackets(
pform.height(), printer._use_unicode)
# Put together state
pform = prettyForm(*pform.left(lbracket))
pform = prettyForm(*pform.right(rbracket))
return pform
def _latex(self, printer, *args):
contents = self._print_contents_latex(printer, *args)
# The extra {} brackets are needed to get matplotlib's latex
# rendered to render this properly.
return '{%s%s%s}' % (self.lbracket_latex, contents, self.rbracket_latex)
class KetBase(StateBase):
"""Base class for Kets.
This class defines the dual property and the brackets for printing. This is
an abstract base class and you should not instantiate it directly, instead
use Ket.
"""
lbracket = _straight_bracket
rbracket = _rbracket
lbracket_ucode = _straight_bracket_ucode
rbracket_ucode = _rbracket_ucode
lbracket_latex = r'\left|'
rbracket_latex = r'\right\rangle '
@classmethod
def default_args(self):
return ("psi",)
@classmethod
def dual_class(self):
return BraBase
def __mul__(self, other):
"""KetBase*other"""
from sympy.physics.quantum.operator import OuterProduct
if isinstance(other, BraBase):
return OuterProduct(self, other)
else:
return Expr.__mul__(self, other)
def __rmul__(self, other):
"""other*KetBase"""
from sympy.physics.quantum.innerproduct import InnerProduct
if isinstance(other, BraBase):
return InnerProduct(other, self)
else:
return Expr.__rmul__(self, other)
#-------------------------------------------------------------------------
# _eval_* methods
#-------------------------------------------------------------------------
def _eval_innerproduct(self, bra, **hints):
"""Evaluate the inner product betweeen this ket and a bra.
This is called to compute <bra|ket>, where the ket is ``self``.
This method will dispatch to sub-methods having the format::
``def _eval_innerproduct_BraClass(self, **hints):``
Subclasses should define these methods (one for each BraClass) to
teach the ket how to take inner products with bras.
"""
return dispatch_method(self, '_eval_innerproduct', bra, **hints)
def _apply_operator(self, op, **options):
"""Apply an Operator to this Ket.
This method will dispatch to methods having the format::
``def _apply_operator_OperatorName(op, **options):``
Subclasses should define these methods (one for each OperatorName) to
teach the Ket how operators act on it.
Parameters
==========
op : Operator
The Operator that is acting on the Ket.
options : dict
A dict of key/value pairs that control how the operator is applied
to the Ket.
"""
return dispatch_method(self, '_apply_operator', op, **options)
class BraBase(StateBase):
"""Base class for Bras.
This class defines the dual property and the brackets for printing. This
is an abstract base class and you should not instantiate it directly,
instead use Bra.
"""
lbracket = _lbracket
rbracket = _straight_bracket
lbracket_ucode = _lbracket_ucode
rbracket_ucode = _straight_bracket_ucode
lbracket_latex = r'\left\langle '
rbracket_latex = r'\right|'
@classmethod
def _operators_to_state(self, ops, **options):
state = self.dual_class().operators_to_state(ops, **options)
return state.dual
def _state_to_operators(self, op_classes, **options):
return self.dual._state_to_operators(op_classes, **options)
def _enumerate_state(self, num_states, **options):
dual_states = self.dual._enumerate_state(num_states, **options)
return [x.dual for x in dual_states]
@classmethod
def default_args(self):
return self.dual_class().default_args()
@classmethod
def dual_class(self):
return KetBase
def __mul__(self, other):
"""BraBase*other"""
from sympy.physics.quantum.innerproduct import InnerProduct
if isinstance(other, KetBase):
return InnerProduct(self, other)
else:
return Expr.__mul__(self, other)
def __rmul__(self, other):
"""other*BraBase"""
from sympy.physics.quantum.operator import OuterProduct
if isinstance(other, KetBase):
return OuterProduct(other, self)
else:
return Expr.__rmul__(self, other)
def _represent(self, **options):
"""A default represent that uses the Ket's version."""
from sympy.physics.quantum.dagger import Dagger
return Dagger(self.dual._represent(**options))
class State(StateBase):
"""General abstract quantum state used as a base class for Ket and Bra."""
pass
class Ket(State, KetBase):
"""A general time-independent Ket in quantum mechanics.
Inherits from State and KetBase. This class should be used as the base
class for all physical, time-independent Kets in a system. This class
and its subclasses will be the main classes that users will use for
expressing Kets in Dirac notation [1]_.
Parameters
==========
args : tuple
The list of numbers or parameters that uniquely specify the
ket. This will usually be its symbol or its quantum numbers. For
time-dependent state, this will include the time.
Examples
========
Create a simple Ket and looking at its properties::
>>> from sympy.physics.quantum import Ket, Bra
>>> from sympy import symbols, I
>>> k = Ket('psi')
>>> k
|psi>
>>> k.hilbert_space
H
>>> k.is_commutative
False
>>> k.label
(psi,)
Ket's know about their associated bra::
>>> k.dual
<psi|
>>> k.dual_class()
<class 'sympy.physics.quantum.state.Bra'>
Take a linear combination of two kets::
>>> k0 = Ket(0)
>>> k1 = Ket(1)
>>> 2*I*k0 - 4*k1
2*I*|0> - 4*|1>
Compound labels are passed as tuples::
>>> n, m = symbols('n,m')
>>> k = Ket(n,m)
>>> k
|nm>
References
==========
.. [1] http://en.wikipedia.org/wiki/Bra-ket_notation
"""
@classmethod
def dual_class(self):
return Bra
class Bra(State, BraBase):
"""A general time-independent Bra in quantum mechanics.
Inherits from State and BraBase. A Bra is the dual of a Ket [1]_. This
class and its subclasses will be the main classes that users will use for
expressing Bras in Dirac notation.
Parameters
==========
args : tuple
The list of numbers or parameters that uniquely specify the
ket. This will usually be its symbol or its quantum numbers. For
time-dependent state, this will include the time.
Examples
========
Create a simple Bra and look at its properties::
>>> from sympy.physics.quantum import Ket, Bra
>>> from sympy import symbols, I
>>> b = Bra('psi')
>>> b
<psi|
>>> b.hilbert_space
H
>>> b.is_commutative
False
Bra's know about their dual Ket's::
>>> b.dual
|psi>
>>> b.dual_class()
<class 'sympy.physics.quantum.state.Ket'>
Like Kets, Bras can have compound labels and be manipulated in a similar
manner::
>>> n, m = symbols('n,m')
>>> b = Bra(n,m) - I*Bra(m,n)
>>> b
-I*<mn| + <nm|
Symbols in a Bra can be substituted using ``.subs``::
>>> b.subs(n,m)
<mm| - I*<mm|
References
==========
.. [1] http://en.wikipedia.org/wiki/Bra-ket_notation
"""
@classmethod
def dual_class(self):
return Ket
#-----------------------------------------------------------------------------
# Time dependent states, bras and kets.
#-----------------------------------------------------------------------------
class TimeDepState(StateBase):
"""Base class for a general time-dependent quantum state.
This class is used as a base class for any time-dependent state. The main
difference between this class and the time-independent state is that this
class takes a second argument that is the time in addition to the usual
label argument.
Parameters
==========
args : tuple
The list of numbers or parameters that uniquely specify the ket. This
will usually be its symbol or its quantum numbers. For time-dependent
state, this will include the time as the final argument.
"""
#-------------------------------------------------------------------------
# Initialization
#-------------------------------------------------------------------------
@classmethod
def default_args(self):
return ("psi", "t")
#-------------------------------------------------------------------------
# Properties
#-------------------------------------------------------------------------
@property
def label(self):
"""The label of the state."""
return self.args[:-1]
@property
def time(self):
"""The time of the state."""
return self.args[-1]
#-------------------------------------------------------------------------
# Printing
#-------------------------------------------------------------------------
def _print_time(self, printer, *args):
return printer._print(self.time, *args)
_print_time_repr = _print_time
_print_time_latex = _print_time
def _print_time_pretty(self, printer, *args):
pform = printer._print(self.time, *args)
return pform
def _print_contents(self, printer, *args):
label = self._print_label(printer, *args)
time = self._print_time(printer, *args)
return '%s;%s' % (label, time)
def _print_label_repr(self, printer, *args):
label = self._print_sequence(self.label, ',', printer, *args)
time = self._print_time_repr(printer, *args)
return '%s,%s' % (label, time)
def _print_contents_pretty(self, printer, *args):
label = self._print_label_pretty(printer, *args)
time = self._print_time_pretty(printer, *args)
return printer._print_seq((label, time), delimiter=';')
def _print_contents_latex(self, printer, *args):
label = self._print_sequence(
self.label, self._label_separator, printer, *args)
time = self._print_time_latex(printer, *args)
return '%s;%s' % (label, time)
class TimeDepKet(TimeDepState, KetBase):
"""General time-dependent Ket in quantum mechanics.
This inherits from ``TimeDepState`` and ``KetBase`` and is the main class
that should be used for Kets that vary with time. Its dual is a
``TimeDepBra``.
Parameters
==========
args : tuple
The list of numbers or parameters that uniquely specify the ket. This
will usually be its symbol or its quantum numbers. For time-dependent
state, this will include the time as the final argument.
Examples
========
Create a TimeDepKet and look at its attributes::
>>> from sympy.physics.quantum import TimeDepKet
>>> k = TimeDepKet('psi', 't')
>>> k
|psi;t>
>>> k.time
t
>>> k.label
(psi,)
>>> k.hilbert_space
H
TimeDepKets know about their dual bra::
>>> k.dual
<psi;t|
>>> k.dual_class()
<class 'sympy.physics.quantum.state.TimeDepBra'>
"""
@classmethod
def dual_class(self):
return TimeDepBra
class TimeDepBra(TimeDepState, BraBase):
"""General time-dependent Bra in quantum mechanics.
This inherits from TimeDepState and BraBase and is the main class that
should be used for Bras that vary with time. Its dual is a TimeDepBra.
Parameters
==========
args : tuple
The list of numbers or parameters that uniquely specify the ket. This
will usually be its symbol or its quantum numbers. For time-dependent
state, this will include the time as the final argument.
Examples
========
>>> from sympy.physics.quantum import TimeDepBra
>>> from sympy import symbols, I
>>> b = TimeDepBra('psi', 't')
>>> b
<psi;t|
>>> b.time
t
>>> b.label
(psi,)
>>> b.hilbert_space
H
>>> b.dual
|psi;t>
"""
@classmethod
def dual_class(self):
return TimeDepKet
class Wavefunction(Function):
"""Class for representations in continuous bases
This class takes an expression and coordinates in its constructor. It can
be used to easily calculate normalizations and probabilities.
Parameters
==========
expr : Expr
The expression representing the functional form of the w.f.
coords : Symbol or tuple
The coordinates to be integrated over, and their bounds
Examples
========
Particle in a box, specifying bounds in the more primitive way of using
Piecewise:
>>> from sympy import Symbol, Piecewise, pi, N
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x = Symbol('x', real=True)
>>> n = 1
>>> L = 1
>>> g = Piecewise((0, x < 0), (0, x > L), (sqrt(2//L)*sin(n*pi*x/L), True))
>>> f = Wavefunction(g, x)
>>> f.norm
1
>>> f.is_normalized
True
>>> p = f.prob()
>>> p(0)
0
>>> p(L)
0
>>> p(0.5)
2
>>> p(0.85*L)
2*sin(0.85*pi)**2
>>> N(p(0.85*L))
0.412214747707527
Additionally, you can specify the bounds of the function and the indices in
a more compact way:
>>> from sympy import symbols, pi, diff
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
1
>>> f(L+1)
0
>>> f(L-1)
sqrt(2)*sin(pi*n*(L - 1)/L)/sqrt(L)
>>> f(-1)
0
>>> f(0.85)
sqrt(2)*sin(0.85*pi*n/L)/sqrt(L)
>>> f(0.85, n=1, L=1)
sqrt(2)*sin(0.85*pi)
>>> f.is_commutative
False
All arguments are automatically sympified, so you can define the variables
as strings rather than symbols:
>>> expr = x**2
>>> f = Wavefunction(expr, 'x')
>>> type(f.variables[0])
<class 'sympy.core.symbol.Symbol'>
Derivatives of Wavefunctions will return Wavefunctions:
>>> diff(f, x)
Wavefunction(2*x, x)
"""
#Any passed tuples for coordinates and their bounds need to be
#converted to Tuples before Function's constructor is called, to
#avoid errors from calling is_Float in the constructor
def __new__(cls, *args, **options):
new_args = [None for i in args]
ct = 0
for arg in args:
if isinstance(arg, tuple):
new_args[ct] = Tuple(*arg)
else:
new_args[ct] = arg
ct += 1
return super(Function, cls).__new__(cls, *new_args, **options)
def __call__(self, *args, **options):
var = self.variables
if len(args) != len(var):
raise NotImplementedError(
"Incorrect number of arguments to function!")
ct = 0
#If the passed value is outside the specified bounds, return 0
for v in var:
lower, upper = self.limits[v]
#Do the comparison to limits only if the passed symbol is actually
#a symbol present in the limits;
#Had problems with a comparison of x > L
if isinstance(args[ct], Expr) and \
not (lower in args[ct].free_symbols
or upper in args[ct].free_symbols):
continue
if (args[ct] < lower) == True or (args[ct] > upper) == True:
return 0
ct += 1
expr = self.expr
#Allows user to make a call like f(2, 4, m=1, n=1)
for symbol in list(expr.free_symbols):
if str(symbol) in options.keys():
val = options[str(symbol)]
expr = expr.subs(symbol, val)
return expr.subs(zip(var, args))
def _eval_derivative(self, symbol):
expr = self.expr
deriv = expr._eval_derivative(symbol)
return Wavefunction(deriv, *self.args[1:])
def _eval_conjugate(self):
return Wavefunction(conjugate(self.expr), *self.args[1:])
def _eval_transpose(self):
return self
@property
def free_symbols(self):
return self.expr.free_symbols
@property
def is_commutative(self):
"""
Override Function's is_commutative so that order is preserved in
represented expressions
"""
return False
@classmethod
def eval(self, *args):
return None
@property
def variables(self):
"""
Return the coordinates which the wavefunction depends on
Examples
========
>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x,y = symbols('x,y')
>>> f = Wavefunction(x*y, x, y)
>>> f.variables
(x, y)
>>> g = Wavefunction(x*y, x)
>>> g.variables
(x,)
"""
var = [g[0] if isinstance(g, Tuple) else g for g in self._args[1:]]
return tuple(var)
@property
def limits(self):
"""
Return the limits of the coordinates which the w.f. depends on If no
limits are specified, defaults to ``(-oo, oo)``.
Examples
========
>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x, y = symbols('x, y')
>>> f = Wavefunction(x**2, (x, 0, 1))
>>> f.limits
{x: (0, 1)}
>>> f = Wavefunction(x**2, x)
>>> f.limits
{x: (-oo, oo)}
>>> f = Wavefunction(x**2 + y**2, x, (y, -1, 2))
>>> f.limits
{x: (-oo, oo), y: (-1, 2)}
"""
limits = [(g[1], g[2]) if isinstance(g, Tuple) else (-oo, oo)
for g in self._args[1:]]
return dict(zip(self.variables, tuple(limits)))
@property
def expr(self):
"""
Return the expression which is the functional form of the Wavefunction
Examples
========
>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x, y = symbols('x, y')
>>> f = Wavefunction(x**2, x)
>>> f.expr
x**2
"""
return self._args[0]
@property
def is_normalized(self):
"""
Returns true if the Wavefunction is properly normalized
Examples
========
>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.is_normalized
True
"""
return (self.norm == 1.0)
@property
@cacheit
def norm(self):
"""
Return the normalization of the specified functional form.
This function integrates over the coordinates of the Wavefunction, with
the bounds specified.
Examples
========
>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
1
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
sqrt(2)*sqrt(L)/2
"""
exp = self.expr*conjugate(self.expr)
var = self.variables
limits = self.limits
for v in var:
curr_limits = limits[v]
exp = integrate(exp, (v, curr_limits[0], curr_limits[1]))
return sqrt(exp)
def normalize(self):
"""
Return a normalized version of the Wavefunction
Examples
========
>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x = symbols('x', real=True)
>>> L = symbols('L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.normalize()
Wavefunction(sqrt(2)*sin(pi*n*x/L)/sqrt(L), (x, 0, L))
"""
const = self.norm
if const == oo:
raise NotImplementedError("The function is not normalizable!")
else:
return Wavefunction((const)**(-1)*self.expr, *self.args[1:])
def prob(self):
"""
Return the absolute magnitude of the w.f., `|\psi(x)|^2`
Examples
========
>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', real=True)
>>> n = symbols('n', integer=True)
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.prob()
Wavefunction(sin(pi*n*x/L)**2, x)
"""
return Wavefunction(self.expr*conjugate(self.expr), *self.variables)
|
bsd-3-clause
|
[
624,
1341,
6457,
15843,
367,
6363,
1041,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
492,
334,
1637,
390,
12,
27246,
12,
14754,
12,
6801,
12,
21494,
12,
16390,
12,
7452,
12,
673,
11634,
9,
199,
504,
5840,
14,
1018,
14,
15390,
492,
399,
12,
1425,
199,
504,
5840,
14,
26514,
14,
9118,
14,
875,
1038,
319,
492,
1059,
10542,
319,
199,
504,
5840,
14,
24724,
14,
25999,
14,
81,
3684,
492,
1413,
8561,
12,
7634,
63,
765,
199,
199,
363,
452,
363,
275,
359,
272,
283,
5018,
1563,
297,
272,
283,
17171,
1563,
297,
272,
283,
2223,
1563,
297,
272,
283,
2223,
297,
272,
283,
5018,
297,
272,
283,
17171,
297,
272,
283,
1366,
8598,
2223,
297,
272,
283,
1366,
8598,
17171,
297,
272,
283,
1366,
8598,
5018,
297,
272,
283,
21393,
1593,
7,
199,
61,
421,
199,
18045,
199,
3,
24230,
12,
330,
6360,
436,
1022,
8716,
14,
199,
18045,
199,
199,
3,
10485,
21873,
199,
63,
6374,
345,
2284,
275,
3886,
2,
199,
63,
4848,
345,
2284,
275,
28192,
199,
63,
14183,
1070,
63,
14594,
275,
15733,
2,
421,
199,
3,
6140,
21873,
199,
3,
603,
619,
1645,
16996,
5974,
18827,
13585,
51,
199,
63,
6374,
345,
2284,
63,
85,
600,
275,
399,
4582,
46,
91,
16996,
1645,
16996,
5974,
6578,
18827,
13585,
15412,
199,
63,
4848,
345,
2284,
63,
85,
600,
275,
399,
4582,
46,
91,
16996,
1645,
16996,
5974,
7052,
18827,
13585,
15412,
199,
3,
9024,
8267,
25357,
199,
63,
14183,
1070,
63,
14594,
63,
85,
600,
275,
399,
4582,
46,
91,
21613,
8267,
25357,
15412,
199,
199,
3,
5439,
1511,
367,
2649,
16116,
402,
665,
12,
690,
436,
1204,
367,
3757,
6457,
15843,
14,
199,
199,
3,
6578,
13,
18940,
18827,
13585,
199,
3,
485,
6374,
345,
2284,
275,
399,
3212,
85,
8001,
25,
2,
199,
3,
485,
4848,
345,
2284,
275,
399,
3212,
85,
8001,
33,
2,
199,
199,
3,
6578,
18827,
13585,
199,
3,
485,
6374,
345,
2284,
275,
399,
3212,
85,
5863,
24,
2,
199,
3,
485,
4848,
345,
2284,
275,
399,
3212,
85,
5863,
25,
2,
199,
199,
3,
8267,
13587,
199,
3,
485,
14183,
1070,
63,
14594,
275,
399,
3212,
85,
8255,
35,
2,
421,
199,
533,
8511,
1563,
8,
49,
8561,
304,
272,
408,
8458,
1300,
1021,
367,
8605,
9006,
6363,
315,
15381,
453,
562,
11984,
2932,
14,
339,
2900,
1163,
1174,
3992,
3247,
911,
1929,
370,
8287,
687,
642,
1021,
14,
2779,
272,
9590,
1996,
314,
5678,
5523,
367,
1006,
1163,
6363,
4066,
465,
21164,
12,
485,
2579,
63,
26055,
272,
436,
1768,
14,
339,
961,
365,
376,
9006,
1300,
1021,
436,
1265,
1077,
440,
17321,
652,
5370,
12,
272,
3140,
675,
8511,
14,
272,
408,
339,
768,
3744,
272,
347,
485,
12688,
63,
475,
63,
929,
8,
277,
12,
4156,
12,
1011,
1419,
304,
267,
408,
1803,
314,
11471,
929,
1256,
367,
314,
3032,
10211,
14,
398,
961,
1083,
1077,
506,
10087,
315,
9180,
14,
2779,
911,
2429,
3769,
267,
3032,
1902,
376,
11013,
1256,
503,
663,
402,
11013,
4454,
14,
2779,
267,
1077,
372,
314,
5226,
1174,
20514,
7140,
503,
9329,
746,
282,
267,
4279,
14,
1666,
9590,
19157,
14,
647,
367,
376,
2893,
14,
267,
408,
398,
746,
4279,
480,
6612,
2341,
10211,
370,
6363,
315,
642,
1021,
14,
9075,
440,
6366,
9124,
339,
347,
485,
929,
63,
475,
63,
12688,
8,
277,
12,
1687,
63,
2888,
12,
1011,
1419,
304,
267,
408,
1803,
314,
10211,
1314,
642,
1174,
1256,
365,
376,
11471,
929,
267,
402,
14,
398,
961,
1083,
1077,
506,
10087,
315,
9180,
14,
2779,
911,
506,
2797,
641,
267,
1174,
4454,
436,
506,
3032,
314,
4182,
3992,
626,
781,
13809,
370,
1852,
267,
1901,
4454,
14,
710,
1174,
1256,
911,
2066,
5793,
314,
3992,
267,
22497,
12,
503,
746,
282,
4279,
340,
652,
3913,
372,
267,
4182,
4454,
14,
1666,
9590,
19157,
14,
647,
367,
7251,
12,
267,
408,
398,
746,
4279,
8,
288,
298,
6612,
2341,
642,
1174,
370,
10211,
14,
9075,
440,
6366,
9124,
339,
768,
1829,
272,
347,
10211,
8,
277,
304,
267,
408,
1767,
314,
4182,
8,
83,
9,
626,
642,
1174,
365,
376,
11471,
929,
402,
624,
267,
687,
1275,
3856,
409,
492,
1174,
63,
475,
63,
12688,
221,
327,
492,
14448,
370,
5126,
15032,
492,
2552,
267,
372,
1174,
63,
475,
63,
12688,
8,
277,
9,
339,
347,
485,
26318,
63,
929,
8,
277,
12,
1967,
63,
4981,
12,
1011,
1419,
304,
267,
746,
4279,
480,
6612,
3874,
642,
1174,
9124,
339,
347,
485,
13063,
63,
885,
63,
19220,
8,
277,
12,
1011,
1419,
304,
267,
372,
291,
423,
13063,
8,
19220,
29,
277,
14,
12688,
9,
339,
14309,
9960,
272,
327,
577,
16267,
15,
17962,
272,
14309,
9960,
339,
768,
1829,
272,
347,
21164,
8,
277,
304,
267,
408,
1767,
314,
21164,
1174,
402,
642,
1373,
1041,
267,
372,
291,
14,
17962,
63,
533,
19050,
1222,
63,
1773,
589,
8,
277,
14,
72,
382,
12504,
63,
2638,
12,
627,
277,
14,
589,
9,
339,
768,
3744,
272,
347,
21164,
63,
533,
8,
277,
304,
267,
408,
1767,
314,
1021,
1202,
370,
406,
495,
337,
314,
21164,
1041,
267,
746,
4279,
8,
288,
283,
17962,
63,
533,
1471,
506,
6366,
315,
282,
5516,
7,
267,
776,
339,
347,
485,
2579,
63,
26055,
8,
277,
304,
267,
408,
8564,
314,
10158,
836,
402,
642,
1174,
1808,
314,
21164,
1041,
267,
372,
291,
14,
17962,
339,
14309,
9960,
272,
327,
9101,
316,
272,
14309,
9960,
339,
347,
485,
9118,
63,
14594,
83,
8,
277,
12,
4569,
12,
675,
63,
2975,
29,
549,
304,
267,
327,
1432,
7268,
12487,
21873,
367,
314,
1174,
267,
327,
473,
271,
1183,
12,
642,
4293,
506,
4224,
701,
299,
964,
14,
31910,
1325,
652,
1630,
440,
2291,
314,
14550,
1146,
665,
436,
690,
398,
327,
12439,
367,
2649,
8118,
13294,
267,
340,
675,
63,
2975,
26,
288,
634,
14594,
12,
519,
14594,
275,
291,
14,
6374,
345,
2284,
63,
85,
600,
12,
291,
14,
4848,
345,
2284,
63,
85,
600,
288,
14457,
12,
330,
7001,
12,
809,
84,
275,
399,
2258,
46,
91,
15694,
5276,
9024,
5266,
1254
] |
[
1341,
6457,
15843,
367,
6363,
1041,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
5840,
492,
334,
1637,
390,
12,
27246,
12,
14754,
12,
6801,
12,
21494,
12,
16390,
12,
7452,
12,
673,
11634,
9,
199,
504,
5840,
14,
1018,
14,
15390,
492,
399,
12,
1425,
199,
504,
5840,
14,
26514,
14,
9118,
14,
875,
1038,
319,
492,
1059,
10542,
319,
199,
504,
5840,
14,
24724,
14,
25999,
14,
81,
3684,
492,
1413,
8561,
12,
7634,
63,
765,
199,
199,
363,
452,
363,
275,
359,
272,
283,
5018,
1563,
297,
272,
283,
17171,
1563,
297,
272,
283,
2223,
1563,
297,
272,
283,
2223,
297,
272,
283,
5018,
297,
272,
283,
17171,
297,
272,
283,
1366,
8598,
2223,
297,
272,
283,
1366,
8598,
17171,
297,
272,
283,
1366,
8598,
5018,
297,
272,
283,
21393,
1593,
7,
199,
61,
421,
199,
18045,
199,
3,
24230,
12,
330,
6360,
436,
1022,
8716,
14,
199,
18045,
199,
199,
3,
10485,
21873,
199,
63,
6374,
345,
2284,
275,
3886,
2,
199,
63,
4848,
345,
2284,
275,
28192,
199,
63,
14183,
1070,
63,
14594,
275,
15733,
2,
421,
199,
3,
6140,
21873,
199,
3,
603,
619,
1645,
16996,
5974,
18827,
13585,
51,
199,
63,
6374,
345,
2284,
63,
85,
600,
275,
399,
4582,
46,
91,
16996,
1645,
16996,
5974,
6578,
18827,
13585,
15412,
199,
63,
4848,
345,
2284,
63,
85,
600,
275,
399,
4582,
46,
91,
16996,
1645,
16996,
5974,
7052,
18827,
13585,
15412,
199,
3,
9024,
8267,
25357,
199,
63,
14183,
1070,
63,
14594,
63,
85,
600,
275,
399,
4582,
46,
91,
21613,
8267,
25357,
15412,
199,
199,
3,
5439,
1511,
367,
2649,
16116,
402,
665,
12,
690,
436,
1204,
367,
3757,
6457,
15843,
14,
199,
199,
3,
6578,
13,
18940,
18827,
13585,
199,
3,
485,
6374,
345,
2284,
275,
399,
3212,
85,
8001,
25,
2,
199,
3,
485,
4848,
345,
2284,
275,
399,
3212,
85,
8001,
33,
2,
199,
199,
3,
6578,
18827,
13585,
199,
3,
485,
6374,
345,
2284,
275,
399,
3212,
85,
5863,
24,
2,
199,
3,
485,
4848,
345,
2284,
275,
399,
3212,
85,
5863,
25,
2,
199,
199,
3,
8267,
13587,
199,
3,
485,
14183,
1070,
63,
14594,
275,
399,
3212,
85,
8255,
35,
2,
421,
199,
533,
8511,
1563,
8,
49,
8561,
304,
272,
408,
8458,
1300,
1021,
367,
8605,
9006,
6363,
315,
15381,
453,
562,
11984,
2932,
14,
339,
2900,
1163,
1174,
3992,
3247,
911,
1929,
370,
8287,
687,
642,
1021,
14,
2779,
272,
9590,
1996,
314,
5678,
5523,
367,
1006,
1163,
6363,
4066,
465,
21164,
12,
485,
2579,
63,
26055,
272,
436,
1768,
14,
339,
961,
365,
376,
9006,
1300,
1021,
436,
1265,
1077,
440,
17321,
652,
5370,
12,
272,
3140,
675,
8511,
14,
272,
408,
339,
768,
3744,
272,
347,
485,
12688,
63,
475,
63,
929,
8,
277,
12,
4156,
12,
1011,
1419,
304,
267,
408,
1803,
314,
11471,
929,
1256,
367,
314,
3032,
10211,
14,
398,
961,
1083,
1077,
506,
10087,
315,
9180,
14,
2779,
911,
2429,
3769,
267,
3032,
1902,
376,
11013,
1256,
503,
663,
402,
11013,
4454,
14,
2779,
267,
1077,
372,
314,
5226,
1174,
20514,
7140,
503,
9329,
746,
282,
267,
4279,
14,
1666,
9590,
19157,
14,
647,
367,
376,
2893,
14,
267,
408,
398,
746,
4279,
480,
6612,
2341,
10211,
370,
6363,
315,
642,
1021,
14,
9075,
440,
6366,
9124,
339,
347,
485,
929,
63,
475,
63,
12688,
8,
277,
12,
1687,
63,
2888,
12,
1011,
1419,
304,
267,
408,
1803,
314,
10211,
1314,
642,
1174,
1256,
365,
376,
11471,
929,
267,
402,
14,
398,
961,
1083,
1077,
506,
10087,
315,
9180,
14,
2779,
911,
506,
2797,
641,
267,
1174,
4454,
436,
506,
3032,
314,
4182,
3992,
626,
781,
13809,
370,
1852,
267,
1901,
4454,
14,
710,
1174,
1256,
911,
2066,
5793,
314,
3992,
267,
22497,
12,
503,
746,
282,
4279,
340,
652,
3913,
372,
267,
4182,
4454,
14,
1666,
9590,
19157,
14,
647,
367,
7251,
12,
267,
408,
398,
746,
4279,
8,
288,
298,
6612,
2341,
642,
1174,
370,
10211,
14,
9075,
440,
6366,
9124,
339,
768,
1829,
272,
347,
10211,
8,
277,
304,
267,
408,
1767,
314,
4182,
8,
83,
9,
626,
642,
1174,
365,
376,
11471,
929,
402,
624,
267,
687,
1275,
3856,
409,
492,
1174,
63,
475,
63,
12688,
221,
327,
492,
14448,
370,
5126,
15032,
492,
2552,
267,
372,
1174,
63,
475,
63,
12688,
8,
277,
9,
339,
347,
485,
26318,
63,
929,
8,
277,
12,
1967,
63,
4981,
12,
1011,
1419,
304,
267,
746,
4279,
480,
6612,
3874,
642,
1174,
9124,
339,
347,
485,
13063,
63,
885,
63,
19220,
8,
277,
12,
1011,
1419,
304,
267,
372,
291,
423,
13063,
8,
19220,
29,
277,
14,
12688,
9,
339,
14309,
9960,
272,
327,
577,
16267,
15,
17962,
272,
14309,
9960,
339,
768,
1829,
272,
347,
21164,
8,
277,
304,
267,
408,
1767,
314,
21164,
1174,
402,
642,
1373,
1041,
267,
372,
291,
14,
17962,
63,
533,
19050,
1222,
63,
1773,
589,
8,
277,
14,
72,
382,
12504,
63,
2638,
12,
627,
277,
14,
589,
9,
339,
768,
3744,
272,
347,
21164,
63,
533,
8,
277,
304,
267,
408,
1767,
314,
1021,
1202,
370,
406,
495,
337,
314,
21164,
1041,
267,
746,
4279,
8,
288,
283,
17962,
63,
533,
1471,
506,
6366,
315,
282,
5516,
7,
267,
776,
339,
347,
485,
2579,
63,
26055,
8,
277,
304,
267,
408,
8564,
314,
10158,
836,
402,
642,
1174,
1808,
314,
21164,
1041,
267,
372,
291,
14,
17962,
339,
14309,
9960,
272,
327,
9101,
316,
272,
14309,
9960,
339,
347,
485,
9118,
63,
14594,
83,
8,
277,
12,
4569,
12,
675,
63,
2975,
29,
549,
304,
267,
327,
1432,
7268,
12487,
21873,
367,
314,
1174,
267,
327,
473,
271,
1183,
12,
642,
4293,
506,
4224,
701,
299,
964,
14,
31910,
1325,
652,
1630,
440,
2291,
314,
14550,
1146,
665,
436,
690,
398,
327,
12439,
367,
2649,
8118,
13294,
267,
340,
675,
63,
2975,
26,
288,
634,
14594,
12,
519,
14594,
275,
291,
14,
6374,
345,
2284,
63,
85,
600,
12,
291,
14,
4848,
345,
2284,
63,
85,
600,
288,
14457,
12,
330,
7001,
12,
809,
84,
275,
399,
2258,
46,
91,
15694,
5276,
9024,
5266,
1254,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gonboy/sl4a
|
python/src/Lib/csv.py
|
62
|
15730
|
"""
csv.py - read/write/investigate CSV files
"""
import re
from functools import reduce
from _csv import Error, __version__, writer, reader, register_dialect, \
unregister_dialect, get_dialect, list_dialects, \
field_size_limit, \
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
__doc__
from _csv import Dialect as _Dialect
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
"Error", "Dialect", "__doc__", "excel", "excel_tab",
"field_size_limit", "reader", "writer",
"register_dialect", "get_dialect", "list_dialects", "Sniffer",
"unregister_dialect", "__version__", "DictReader", "DictWriter" ]
class Dialect:
"""Describe an Excel dialect.
This must be subclassed (see csv.excel). Valid attributes are:
delimiter, quotechar, escapechar, doublequote, skipinitialspace,
lineterminator, quoting.
"""
_name = ""
_valid = False
# placeholders
delimiter = None
quotechar = None
escapechar = None
doublequote = None
skipinitialspace = None
lineterminator = None
quoting = None
def __init__(self):
if self.__class__ != Dialect:
self._valid = True
self._validate()
def _validate(self):
try:
_Dialect(self)
except TypeError, e:
# We do this for compatibility with py2.3
raise Error(str(e))
class excel(Dialect):
"""Describe the usual properties of Excel-generated CSV files."""
delimiter = ','
quotechar = '"'
doublequote = True
skipinitialspace = False
lineterminator = '\r\n'
quoting = QUOTE_MINIMAL
register_dialect("excel", excel)
class excel_tab(excel):
"""Describe the usual properties of Excel-generated TAB-delimited files."""
delimiter = '\t'
register_dialect("excel-tab", excel_tab)
class DictReader:
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
dialect="excel", *args, **kwds):
self._fieldnames = fieldnames # list of keys for the dict
self.restkey = restkey # key to catch long rows
self.restval = restval # default value for short rows
self.reader = reader(f, dialect, *args, **kwds)
self.dialect = dialect
self.line_num = 0
def __iter__(self):
return self
@property
def fieldnames(self):
if self._fieldnames is None:
try:
self._fieldnames = self.reader.next()
except StopIteration:
pass
self.line_num = self.reader.line_num
return self._fieldnames
@fieldnames.setter
def fieldnames(self, value):
self._fieldnames = value
def next(self):
if self.line_num == 0:
# Used only for its side effect.
self.fieldnames
row = self.reader.next()
self.line_num = self.reader.line_num
# unlike the basic reader, we prefer not to return blanks,
# because we will typically wind up with a dict full of None
# values
while row == []:
row = self.reader.next()
d = dict(zip(self.fieldnames, row))
lf = len(self.fieldnames)
lr = len(row)
if lf < lr:
d[self.restkey] = row[lf:]
elif lf > lr:
for key in self.fieldnames[lr:]:
d[key] = self.restval
return d
class DictWriter:
def __init__(self, f, fieldnames, restval="", extrasaction="raise",
dialect="excel", *args, **kwds):
self.fieldnames = fieldnames # list of keys for the dict
self.restval = restval # for writing short dicts
if extrasaction.lower() not in ("raise", "ignore"):
raise ValueError, \
("extrasaction (%s) must be 'raise' or 'ignore'" %
extrasaction)
self.extrasaction = extrasaction
self.writer = writer(f, dialect, *args, **kwds)
def _dict_to_list(self, rowdict):
if self.extrasaction == "raise":
wrong_fields = [k for k in rowdict if k not in self.fieldnames]
if wrong_fields:
raise ValueError("dict contains fields not in fieldnames: " +
", ".join(wrong_fields))
return [rowdict.get(key, self.restval) for key in self.fieldnames]
def writerow(self, rowdict):
return self.writer.writerow(self._dict_to_list(rowdict))
def writerows(self, rowdicts):
rows = []
for rowdict in rowdicts:
rows.append(self._dict_to_list(rowdict))
return self.writer.writerows(rows)
# Guard Sniffer's type checking against builds that exclude complex()
try:
complex
except NameError:
complex = float
class Sniffer:
'''
"Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
Returns a Dialect object.
'''
def __init__(self):
# in case there is more than one possible delimiter
self.preferred = [',', '\t', ';', ' ', ':']
def sniff(self, sample, delimiters=None):
"""
Returns a dialect (or None) corresponding to the sample
"""
quotechar, delimiter, skipinitialspace = \
self._guess_quote_and_delimiter(sample, delimiters)
if not delimiter:
delimiter, skipinitialspace = self._guess_delimiter(sample,
delimiters)
if not delimiter:
raise Error, "Could not determine delimiter"
class dialect(Dialect):
_name = "sniffed"
lineterminator = '\r\n'
quoting = QUOTE_MINIMAL
# escapechar = ''
doublequote = False
dialect.delimiter = delimiter
# _csv.reader won't accept a quotechar of ''
dialect.quotechar = quotechar or '"'
dialect.skipinitialspace = skipinitialspace
return dialect
def _guess_quote_and_delimiter(self, data, delimiters):
"""
Looks for text enclosed between two identical quotes
(the probable quotechar) which are preceded and followed
by the same character (the probable delimiter).
For example:
,'some text',
The quote with the most wins, same with the delimiter.
If there is no quotechar the delimiter can't be determined
this way.
"""
matches = []
for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
'(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
matches = regexp.findall(data)
if matches:
break
if not matches:
return ('', None, 0) # (quotechar, delimiter, skipinitialspace)
quotes = {}
delims = {}
spaces = 0
for m in matches:
n = regexp.groupindex['quote'] - 1
key = m[n]
if key:
quotes[key] = quotes.get(key, 0) + 1
try:
n = regexp.groupindex['delim'] - 1
key = m[n]
except KeyError:
continue
if key and (delimiters is None or key in delimiters):
delims[key] = delims.get(key, 0) + 1
try:
n = regexp.groupindex['space'] - 1
except KeyError:
continue
if m[n]:
spaces += 1
quotechar = reduce(lambda a, b, quotes = quotes:
(quotes[a] > quotes[b]) and a or b, quotes.keys())
if delims:
delim = reduce(lambda a, b, delims = delims:
(delims[a] > delims[b]) and a or b, delims.keys())
skipinitialspace = delims[delim] == spaces
if delim == '\n': # most likely a file with a single column
delim = ''
else:
# there is *no* delimiter, it's a single column of quoted data
delim = ''
skipinitialspace = 0
return (quotechar, delim, skipinitialspace)
def _guess_delimiter(self, data, delimiters):
"""
The delimiter /should/ occur the same number of times on
each row. However, due to malformed data, it may not. We don't want
an all or nothing approach, so we allow for small variations in this
number.
1) build a table of the frequency of each character on every line.
2) build a table of freqencies of this frequency (meta-frequency?),
e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows,
7 times in 2 rows'
3) use the mode of the meta-frequency to determine the /expected/
frequency for that character
4) find out how often the character actually meets that goal
5) the character that best meets its goal is the delimiter
For performance reasons, the data is evaluated in chunks, so it can
try and evaluate the smallest portion of the data possible, evaluating
additional chunks as necessary.
"""
data = filter(None, data.split('\n'))
ascii = [chr(c) for c in range(127)] # 7-bit ASCII
# build frequency tables
chunkLength = min(10, len(data))
iteration = 0
charFrequency = {}
modes = {}
delims = {}
start, end = 0, min(chunkLength, len(data))
while start < len(data):
iteration += 1
for line in data[start:end]:
for char in ascii:
metaFrequency = charFrequency.get(char, {})
# must count even if frequency is 0
freq = line.count(char)
# value is the mode
metaFrequency[freq] = metaFrequency.get(freq, 0) + 1
charFrequency[char] = metaFrequency
for char in charFrequency.keys():
items = charFrequency[char].items()
if len(items) == 1 and items[0][0] == 0:
continue
# get the mode of the frequencies
if len(items) > 1:
modes[char] = reduce(lambda a, b: a[1] > b[1] and a or b,
items)
# adjust the mode - subtract the sum of all
# other frequencies
items.remove(modes[char])
modes[char] = (modes[char][0], modes[char][1]
- reduce(lambda a, b: (0, a[1] + b[1]),
items)[1])
else:
modes[char] = items[0]
# build a list of possible delimiters
modeList = modes.items()
total = float(chunkLength * iteration)
# (rows of consistent data) / (number of rows) = 100%
consistency = 1.0
# minimum consistency threshold
threshold = 0.9
while len(delims) == 0 and consistency >= threshold:
for k, v in modeList:
if v[0] > 0 and v[1] > 0:
if ((v[1]/total) >= consistency and
(delimiters is None or k in delimiters)):
delims[k] = v
consistency -= 0.01
if len(delims) == 1:
delim = delims.keys()[0]
skipinitialspace = (data[0].count(delim) ==
data[0].count("%c " % delim))
return (delim, skipinitialspace)
# analyze another chunkLength lines
start = end
end += chunkLength
if not delims:
return ('', 0)
# if there's more than one, fall back to a 'preferred' list
if len(delims) > 1:
for d in self.preferred:
if d in delims.keys():
skipinitialspace = (data[0].count(d) ==
data[0].count("%c " % d))
return (d, skipinitialspace)
# nothing else indicates a preference, pick the character that
# dominates(?)
items = [(v,k) for (k,v) in delims.items()]
items.sort()
delim = items[-1][1]
skipinitialspace = (data[0].count(delim) ==
data[0].count("%c " % delim))
return (delim, skipinitialspace)
def has_header(self, sample):
# Creates a dictionary of types of data in each column. If any
# column is of a single type (say, integers), *except* for the first
# row, then the first row is presumed to be labels. If the type
# can't be determined, it is assumed to be a string in which case
# the length of the string is the determining factor: if all of the
# rows except for the first are the same length, it's a header.
# Finally, a 'vote' is taken at the end for each column, adding or
# subtracting from the likelihood of the first row being a header.
rdr = reader(StringIO(sample), self.sniff(sample))
header = rdr.next() # assume first row is header
columns = len(header)
columnTypes = {}
for i in range(columns): columnTypes[i] = None
checked = 0
for row in rdr:
# arbitrary number of rows to check, to keep it sane
if checked > 20:
break
checked += 1
if len(row) != columns:
continue # skip rows that have irregular number of columns
for col in columnTypes.keys():
for thisType in [int, long, float, complex]:
try:
thisType(row[col])
break
except (ValueError, OverflowError):
pass
else:
# fallback to length of string
thisType = len(row[col])
# treat longs as ints
if thisType == long:
thisType = int
if thisType != columnTypes[col]:
if columnTypes[col] is None: # add new column type
columnTypes[col] = thisType
else:
# type is inconsistent, remove column from
# consideration
del columnTypes[col]
# finally, compare results against first row and "vote"
# on whether it's a header
hasHeader = 0
for col, colType in columnTypes.items():
if type(colType) == type(0): # it's a length
if len(header[col]) != colType:
hasHeader += 1
else:
hasHeader -= 1
else: # attempt typecast
try:
colType(header[col])
except (ValueError, TypeError):
hasHeader += 1
else:
hasHeader -= 1
return hasHeader > 0
|
apache-2.0
|
[
199,
624,
199,
4737,
14,
647,
446,
1586,
15,
952,
15,
262,
27174,
323,
14689,
1584,
199,
624,
199,
199,
646,
295,
199,
504,
9143,
492,
7114,
199,
504,
485,
4737,
492,
4520,
12,
636,
1023,
3108,
7060,
12,
7002,
12,
2274,
63,
11072,
12,
971,
326,
24369,
63,
11072,
12,
664,
63,
11072,
12,
769,
63,
11072,
83,
12,
971,
326,
901,
63,
890,
63,
3097,
12,
971,
326,
7813,
9407,
63,
4896,
16980,
12,
7813,
9407,
63,
1761,
12,
7813,
9407,
63,
13887,
28425,
12,
7813,
9407,
63,
9185,
12,
971,
326,
636,
1301,
363,
199,
504,
485,
4737,
492,
3757,
9062,
465,
485,
22080,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
363,
452,
363,
275,
359,
298,
18495,
63,
4896,
16980,
401,
298,
18495,
63,
1761,
401,
298,
18495,
63,
13887,
28425,
401,
298,
18495,
63,
9185,
401,
288,
298,
547,
401,
298,
22080,
401,
4396,
1301,
13915,
298,
28330,
401,
298,
28330,
63,
2902,
401,
288,
298,
698,
63,
890,
63,
3097,
401,
298,
5503,
401,
298,
5491,
401,
288,
298,
2683,
63,
11072,
401,
298,
362,
63,
11072,
401,
298,
513,
63,
11072,
83,
401,
298,
51,
8445,
1260,
401,
288,
298,
18408,
63,
11072,
401,
4396,
1023,
13915,
298,
2141,
5929,
401,
298,
2141,
6261,
2,
1622,
199,
199,
533,
3757,
9062,
26,
272,
408,
19506,
376,
27832,
10982,
14,
339,
961,
1471,
506,
1007,
28271,
334,
3239,
7392,
14,
28330,
680,
221,
4821,
3004,
787,
26,
272,
11172,
12,
6313,
1560,
12,
4772,
1560,
12,
4270,
3513,
12,
3372,
2747,
2638,
12,
272,
1004,
26370,
12,
18593,
14,
339,
408,
272,
485,
354,
275,
3087,
272,
485,
1078,
275,
756,
272,
327,
24987,
272,
11172,
275,
488,
272,
6313,
1560,
275,
488,
272,
4772,
1560,
275,
488,
272,
4270,
3513,
275,
488,
272,
3372,
2747,
2638,
275,
488,
272,
1004,
26370,
275,
488,
272,
18593,
275,
488,
339,
347,
636,
826,
721,
277,
304,
267,
340,
291,
855,
533,
363,
1137,
3757,
9062,
26,
288,
291,
423,
1078,
275,
715,
267,
291,
423,
3502,
342,
339,
347,
485,
3502,
8,
277,
304,
267,
862,
26,
288,
485,
22080,
8,
277,
9,
267,
871,
3146,
12,
325,
26,
288,
327,
2136,
886,
642,
367,
7163,
543,
1134,
18,
14,
19,
288,
746,
4520,
8,
495,
8,
69,
430,
199,
199,
533,
444,
6067,
8,
22080,
304,
272,
408,
19506,
314,
20195,
4382,
402,
27832,
13,
10176,
14689,
1584,
1041,
272,
11172,
275,
13647,
272,
6313,
1560,
275,
14788,
272,
4270,
3513,
275,
715,
272,
3372,
2747,
2638,
275,
756,
272,
1004,
26370,
275,
1557,
82,
60,
78,
7,
272,
18593,
275,
7813,
9407,
63,
4896,
16980,
199,
2683,
63,
11072,
480,
28330,
401,
444,
6067,
9,
199,
199,
533,
444,
6067,
63,
2902,
8,
28330,
304,
272,
408,
19506,
314,
20195,
4382,
402,
27832,
13,
10176,
17916,
13,
25672,
1584,
1041,
272,
11172,
275,
1557,
84,
7,
199,
2683,
63,
11072,
480,
28330,
13,
2902,
401,
444,
6067,
63,
2902,
9,
421,
199,
533,
7448,
5929,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
901,
1247,
29,
403,
12,
4618,
498,
29,
403,
12,
4618,
637,
29,
403,
12,
326,
10982,
628,
28330,
401,
627,
589,
12,
1011,
10340,
304,
267,
291,
423,
698,
1247,
275,
901,
1247,
257,
327,
769,
402,
2883,
367,
314,
1211,
267,
291,
14,
3911,
498,
275,
4618,
498,
3515,
327,
790,
370,
8579,
1846,
4730,
267,
291,
14,
3911,
637,
275,
4618,
637,
3515,
327,
849,
574,
367,
3974,
4730,
267,
291,
14,
5503,
275,
7002,
8,
70,
12,
10982,
12,
627,
589,
12,
1011,
10340,
9,
267,
291,
14,
11072,
275,
10982,
267,
291,
14,
604,
63,
1507,
275,
378,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
768,
1829,
272,
347,
901,
1247,
8,
277,
304,
267,
340,
291,
423,
698,
1247,
365,
488,
26,
288,
862,
26,
355,
291,
423,
698,
1247,
275,
291,
14,
5503,
14,
2184,
342,
288,
871,
10852,
26,
355,
986,
267,
291,
14,
604,
63,
1507,
275,
291,
14,
5503,
14,
604,
63,
1507,
267,
372,
291,
423,
698,
1247,
339,
768,
698,
1247,
14,
8345,
272,
347,
901,
1247,
8,
277,
12,
574,
304,
267,
291,
423,
698,
1247,
275,
574,
339,
347,
2163,
8,
277,
304,
267,
340,
291,
14,
604,
63,
1507,
508,
378,
26,
288,
327,
8051,
1454,
367,
2399,
5366,
7763,
14,
288,
291,
14,
698,
1247,
267,
1962,
275,
291,
14,
5503,
14,
2184,
342,
267,
291,
14,
604,
63,
1507,
275,
291,
14,
5503,
14,
604,
63,
1507,
398,
327,
29750,
314,
5678,
7002,
12,
781,
16602,
440,
370,
372,
4596,
83,
12,
267,
327,
2952,
781,
911,
13609,
15417,
1536,
543,
282,
1211,
2615,
402,
488,
267,
327,
1338,
267,
1830,
1962,
508,
18410,
288,
1962,
275,
291,
14,
5503,
14,
2184,
342,
267,
366,
275,
1211,
8,
3065,
8,
277,
14,
698,
1247,
12,
1962,
430,
267,
14642,
275,
822,
8,
277,
14,
698,
1247,
9,
267,
13645,
275,
822,
8,
1143,
9,
267,
340,
14642,
665,
13645,
26,
288,
366,
59,
277,
14,
3911,
498,
61,
275,
1962,
59,
276,
2938,
267,
916,
14642,
690,
13645,
26,
288,
367,
790,
315,
291,
14,
698,
1247,
59,
7493,
10688,
355,
366,
59,
498,
61,
275,
291,
14,
3911,
637,
267,
372,
366,
421,
199,
533,
7448,
6261,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
901,
1247,
12,
4618,
637,
8772,
13751,
1287,
628,
3730,
401,
326,
10982,
628,
28330,
401,
627,
589,
12,
1011,
10340,
304,
267,
291,
14,
698,
1247,
275,
901,
1247,
259,
327,
769,
402,
2883,
367,
314,
1211,
267,
291,
14,
3911,
637,
275,
4618,
637,
3515,
327,
367,
3575,
3974,
10809,
267,
340,
13751,
1287,
14,
2325,
342,
440,
315,
1689,
3730,
401,
298,
4247,
2349,
288,
746,
1722,
12,
971,
2116,
1689,
9975,
1287,
4366,
83,
9,
1471,
506,
283,
3730,
7,
503,
283,
4247,
4065,
450,
673,
13751,
1287,
9,
267,
291,
14,
9975,
1287,
275,
13751,
1287,
267,
291,
14,
5491,
275,
7060,
8,
70,
12
] |
[
624,
199,
4737,
14,
647,
446,
1586,
15,
952,
15,
262,
27174,
323,
14689,
1584,
199,
624,
199,
199,
646,
295,
199,
504,
9143,
492,
7114,
199,
504,
485,
4737,
492,
4520,
12,
636,
1023,
3108,
7060,
12,
7002,
12,
2274,
63,
11072,
12,
971,
326,
24369,
63,
11072,
12,
664,
63,
11072,
12,
769,
63,
11072,
83,
12,
971,
326,
901,
63,
890,
63,
3097,
12,
971,
326,
7813,
9407,
63,
4896,
16980,
12,
7813,
9407,
63,
1761,
12,
7813,
9407,
63,
13887,
28425,
12,
7813,
9407,
63,
9185,
12,
971,
326,
636,
1301,
363,
199,
504,
485,
4737,
492,
3757,
9062,
465,
485,
22080,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
199,
2590,
3545,
26,
272,
687,
5228,
492,
5228,
199,
199,
363,
452,
363,
275,
359,
298,
18495,
63,
4896,
16980,
401,
298,
18495,
63,
1761,
401,
298,
18495,
63,
13887,
28425,
401,
298,
18495,
63,
9185,
401,
288,
298,
547,
401,
298,
22080,
401,
4396,
1301,
13915,
298,
28330,
401,
298,
28330,
63,
2902,
401,
288,
298,
698,
63,
890,
63,
3097,
401,
298,
5503,
401,
298,
5491,
401,
288,
298,
2683,
63,
11072,
401,
298,
362,
63,
11072,
401,
298,
513,
63,
11072,
83,
401,
298,
51,
8445,
1260,
401,
288,
298,
18408,
63,
11072,
401,
4396,
1023,
13915,
298,
2141,
5929,
401,
298,
2141,
6261,
2,
1622,
199,
199,
533,
3757,
9062,
26,
272,
408,
19506,
376,
27832,
10982,
14,
339,
961,
1471,
506,
1007,
28271,
334,
3239,
7392,
14,
28330,
680,
221,
4821,
3004,
787,
26,
272,
11172,
12,
6313,
1560,
12,
4772,
1560,
12,
4270,
3513,
12,
3372,
2747,
2638,
12,
272,
1004,
26370,
12,
18593,
14,
339,
408,
272,
485,
354,
275,
3087,
272,
485,
1078,
275,
756,
272,
327,
24987,
272,
11172,
275,
488,
272,
6313,
1560,
275,
488,
272,
4772,
1560,
275,
488,
272,
4270,
3513,
275,
488,
272,
3372,
2747,
2638,
275,
488,
272,
1004,
26370,
275,
488,
272,
18593,
275,
488,
339,
347,
636,
826,
721,
277,
304,
267,
340,
291,
855,
533,
363,
1137,
3757,
9062,
26,
288,
291,
423,
1078,
275,
715,
267,
291,
423,
3502,
342,
339,
347,
485,
3502,
8,
277,
304,
267,
862,
26,
288,
485,
22080,
8,
277,
9,
267,
871,
3146,
12,
325,
26,
288,
327,
2136,
886,
642,
367,
7163,
543,
1134,
18,
14,
19,
288,
746,
4520,
8,
495,
8,
69,
430,
199,
199,
533,
444,
6067,
8,
22080,
304,
272,
408,
19506,
314,
20195,
4382,
402,
27832,
13,
10176,
14689,
1584,
1041,
272,
11172,
275,
13647,
272,
6313,
1560,
275,
14788,
272,
4270,
3513,
275,
715,
272,
3372,
2747,
2638,
275,
756,
272,
1004,
26370,
275,
1557,
82,
60,
78,
7,
272,
18593,
275,
7813,
9407,
63,
4896,
16980,
199,
2683,
63,
11072,
480,
28330,
401,
444,
6067,
9,
199,
199,
533,
444,
6067,
63,
2902,
8,
28330,
304,
272,
408,
19506,
314,
20195,
4382,
402,
27832,
13,
10176,
17916,
13,
25672,
1584,
1041,
272,
11172,
275,
1557,
84,
7,
199,
2683,
63,
11072,
480,
28330,
13,
2902,
401,
444,
6067,
63,
2902,
9,
421,
199,
533,
7448,
5929,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
901,
1247,
29,
403,
12,
4618,
498,
29,
403,
12,
4618,
637,
29,
403,
12,
326,
10982,
628,
28330,
401,
627,
589,
12,
1011,
10340,
304,
267,
291,
423,
698,
1247,
275,
901,
1247,
257,
327,
769,
402,
2883,
367,
314,
1211,
267,
291,
14,
3911,
498,
275,
4618,
498,
3515,
327,
790,
370,
8579,
1846,
4730,
267,
291,
14,
3911,
637,
275,
4618,
637,
3515,
327,
849,
574,
367,
3974,
4730,
267,
291,
14,
5503,
275,
7002,
8,
70,
12,
10982,
12,
627,
589,
12,
1011,
10340,
9,
267,
291,
14,
11072,
275,
10982,
267,
291,
14,
604,
63,
1507,
275,
378,
339,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
339,
768,
1829,
272,
347,
901,
1247,
8,
277,
304,
267,
340,
291,
423,
698,
1247,
365,
488,
26,
288,
862,
26,
355,
291,
423,
698,
1247,
275,
291,
14,
5503,
14,
2184,
342,
288,
871,
10852,
26,
355,
986,
267,
291,
14,
604,
63,
1507,
275,
291,
14,
5503,
14,
604,
63,
1507,
267,
372,
291,
423,
698,
1247,
339,
768,
698,
1247,
14,
8345,
272,
347,
901,
1247,
8,
277,
12,
574,
304,
267,
291,
423,
698,
1247,
275,
574,
339,
347,
2163,
8,
277,
304,
267,
340,
291,
14,
604,
63,
1507,
508,
378,
26,
288,
327,
8051,
1454,
367,
2399,
5366,
7763,
14,
288,
291,
14,
698,
1247,
267,
1962,
275,
291,
14,
5503,
14,
2184,
342,
267,
291,
14,
604,
63,
1507,
275,
291,
14,
5503,
14,
604,
63,
1507,
398,
327,
29750,
314,
5678,
7002,
12,
781,
16602,
440,
370,
372,
4596,
83,
12,
267,
327,
2952,
781,
911,
13609,
15417,
1536,
543,
282,
1211,
2615,
402,
488,
267,
327,
1338,
267,
1830,
1962,
508,
18410,
288,
1962,
275,
291,
14,
5503,
14,
2184,
342,
267,
366,
275,
1211,
8,
3065,
8,
277,
14,
698,
1247,
12,
1962,
430,
267,
14642,
275,
822,
8,
277,
14,
698,
1247,
9,
267,
13645,
275,
822,
8,
1143,
9,
267,
340,
14642,
665,
13645,
26,
288,
366,
59,
277,
14,
3911,
498,
61,
275,
1962,
59,
276,
2938,
267,
916,
14642,
690,
13645,
26,
288,
367,
790,
315,
291,
14,
698,
1247,
59,
7493,
10688,
355,
366,
59,
498,
61,
275,
291,
14,
3911,
637,
267,
372,
366,
421,
199,
533,
7448,
6261,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
901,
1247,
12,
4618,
637,
8772,
13751,
1287,
628,
3730,
401,
326,
10982,
628,
28330,
401,
627,
589,
12,
1011,
10340,
304,
267,
291,
14,
698,
1247,
275,
901,
1247,
259,
327,
769,
402,
2883,
367,
314,
1211,
267,
291,
14,
3911,
637,
275,
4618,
637,
3515,
327,
367,
3575,
3974,
10809,
267,
340,
13751,
1287,
14,
2325,
342,
440,
315,
1689,
3730,
401,
298,
4247,
2349,
288,
746,
1722,
12,
971,
2116,
1689,
9975,
1287,
4366,
83,
9,
1471,
506,
283,
3730,
7,
503,
283,
4247,
4065,
450,
673,
13751,
1287,
9,
267,
291,
14,
9975,
1287,
275,
13751,
1287,
267,
291,
14,
5491,
275,
7060,
8,
70,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
elena/django
|
tests/template_tests/syntax_tests/test_if.py
|
129
|
27415
|
from django.template import TemplateSyntaxError
from django.template.defaulttags import IfNode
from django.test import SimpleTestCase
from ..utils import TestObj, setup
class IfTagTests(SimpleTestCase):
@setup({'if-tag01': '{% if foo %}yes{% else %}no{% endif %}'})
def test_if_tag01(self):
output = self.engine.render_to_string('if-tag01', {'foo': True})
self.assertEqual(output, 'yes')
@setup({'if-tag02': '{% if foo %}yes{% else %}no{% endif %}'})
def test_if_tag02(self):
output = self.engine.render_to_string('if-tag02', {'foo': False})
self.assertEqual(output, 'no')
@setup({'if-tag03': '{% if foo %}yes{% else %}no{% endif %}'})
def test_if_tag03(self):
output = self.engine.render_to_string('if-tag03')
self.assertEqual(output, 'no')
@setup({'if-tag04': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
def test_if_tag04(self):
output = self.engine.render_to_string('if-tag04', {'foo': True})
self.assertEqual(output, 'foo')
@setup({'if-tag05': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
def test_if_tag05(self):
output = self.engine.render_to_string('if-tag05', {'bar': True})
self.assertEqual(output, 'bar')
@setup({'if-tag06': '{% if foo %}foo{% elif bar %}bar{% endif %}'})
def test_if_tag06(self):
output = self.engine.render_to_string('if-tag06')
self.assertEqual(output, '')
@setup({'if-tag07': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
def test_if_tag07(self):
output = self.engine.render_to_string('if-tag07', {'foo': True})
self.assertEqual(output, 'foo')
@setup({'if-tag08': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
def test_if_tag08(self):
output = self.engine.render_to_string('if-tag08', {'bar': True})
self.assertEqual(output, 'bar')
@setup({'if-tag09': '{% if foo %}foo{% elif bar %}bar{% else %}nothing{% endif %}'})
def test_if_tag09(self):
output = self.engine.render_to_string('if-tag09')
self.assertEqual(output, 'nothing')
@setup({'if-tag10': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
def test_if_tag10(self):
output = self.engine.render_to_string('if-tag10', {'foo': True})
self.assertEqual(output, 'foo')
@setup({'if-tag11': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
def test_if_tag11(self):
output = self.engine.render_to_string('if-tag11', {'bar': True})
self.assertEqual(output, 'bar')
@setup({'if-tag12': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
def test_if_tag12(self):
output = self.engine.render_to_string('if-tag12', {'baz': True})
self.assertEqual(output, 'baz')
@setup({'if-tag13': '{% if foo %}foo{% elif bar %}bar{% elif baz %}baz{% else %}nothing{% endif %}'})
def test_if_tag13(self):
output = self.engine.render_to_string('if-tag13')
self.assertEqual(output, 'nothing')
# Filters
@setup({'if-tag-filter01': '{% if foo|length == 5 %}yes{% else %}no{% endif %}'})
def test_if_tag_filter01(self):
output = self.engine.render_to_string('if-tag-filter01', {'foo': 'abcde'})
self.assertEqual(output, 'yes')
@setup({'if-tag-filter02': '{% if foo|upper == \'ABC\' %}yes{% else %}no{% endif %}'})
def test_if_tag_filter02(self):
output = self.engine.render_to_string('if-tag-filter02')
self.assertEqual(output, 'no')
# Equality
@setup({'if-tag-eq01': '{% if foo == bar %}yes{% else %}no{% endif %}'})
def test_if_tag_eq01(self):
output = self.engine.render_to_string('if-tag-eq01')
self.assertEqual(output, 'yes')
@setup({'if-tag-eq02': '{% if foo == bar %}yes{% else %}no{% endif %}'})
def test_if_tag_eq02(self):
output = self.engine.render_to_string('if-tag-eq02', {'foo': 1})
self.assertEqual(output, 'no')
@setup({'if-tag-eq03': '{% if foo == bar %}yes{% else %}no{% endif %}'})
def test_if_tag_eq03(self):
output = self.engine.render_to_string('if-tag-eq03', {'foo': 1, 'bar': 1})
self.assertEqual(output, 'yes')
@setup({'if-tag-eq04': '{% if foo == bar %}yes{% else %}no{% endif %}'})
def test_if_tag_eq04(self):
output = self.engine.render_to_string('if-tag-eq04', {'foo': 1, 'bar': 2})
self.assertEqual(output, 'no')
@setup({'if-tag-eq05': '{% if foo == \'\' %}yes{% else %}no{% endif %}'})
def test_if_tag_eq05(self):
output = self.engine.render_to_string('if-tag-eq05')
self.assertEqual(output, 'no')
# Inequality
@setup({'if-tag-noteq01': '{% if foo != bar %}yes{% else %}no{% endif %}'})
def test_if_tag_noteq01(self):
output = self.engine.render_to_string('if-tag-noteq01')
self.assertEqual(output, 'no')
@setup({'if-tag-noteq02': '{% if foo != bar %}yes{% else %}no{% endif %}'})
def test_if_tag_noteq02(self):
output = self.engine.render_to_string('if-tag-noteq02', {'foo': 1})
self.assertEqual(output, 'yes')
@setup({'if-tag-noteq03': '{% if foo != bar %}yes{% else %}no{% endif %}'})
def test_if_tag_noteq03(self):
output = self.engine.render_to_string('if-tag-noteq03', {'foo': 1, 'bar': 1})
self.assertEqual(output, 'no')
@setup({'if-tag-noteq04': '{% if foo != bar %}yes{% else %}no{% endif %}'})
def test_if_tag_noteq04(self):
output = self.engine.render_to_string('if-tag-noteq04', {'foo': 1, 'bar': 2})
self.assertEqual(output, 'yes')
@setup({'if-tag-noteq05': '{% if foo != "" %}yes{% else %}no{% endif %}'})
def test_if_tag_noteq05(self):
output = self.engine.render_to_string('if-tag-noteq05')
self.assertEqual(output, 'yes')
# Comparison
@setup({'if-tag-gt-01': '{% if 2 > 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_gt_01(self):
output = self.engine.render_to_string('if-tag-gt-01')
self.assertEqual(output, 'yes')
@setup({'if-tag-gt-02': '{% if 1 > 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_gt_02(self):
output = self.engine.render_to_string('if-tag-gt-02')
self.assertEqual(output, 'no')
@setup({'if-tag-gte-01': '{% if 1 >= 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_gte_01(self):
output = self.engine.render_to_string('if-tag-gte-01')
self.assertEqual(output, 'yes')
@setup({'if-tag-gte-02': '{% if 1 >= 2 %}yes{% else %}no{% endif %}'})
def test_if_tag_gte_02(self):
output = self.engine.render_to_string('if-tag-gte-02')
self.assertEqual(output, 'no')
@setup({'if-tag-lt-01': '{% if 1 < 2 %}yes{% else %}no{% endif %}'})
def test_if_tag_lt_01(self):
output = self.engine.render_to_string('if-tag-lt-01')
self.assertEqual(output, 'yes')
@setup({'if-tag-lt-02': '{% if 1 < 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_lt_02(self):
output = self.engine.render_to_string('if-tag-lt-02')
self.assertEqual(output, 'no')
@setup({'if-tag-lte-01': '{% if 1 <= 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_lte_01(self):
output = self.engine.render_to_string('if-tag-lte-01')
self.assertEqual(output, 'yes')
@setup({'if-tag-lte-02': '{% if 2 <= 1 %}yes{% else %}no{% endif %}'})
def test_if_tag_lte_02(self):
output = self.engine.render_to_string('if-tag-lte-02')
self.assertEqual(output, 'no')
# Contains
@setup({'if-tag-in-01': '{% if 1 in x %}yes{% else %}no{% endif %}'})
def test_if_tag_in_01(self):
output = self.engine.render_to_string('if-tag-in-01', {'x': [1]})
self.assertEqual(output, 'yes')
@setup({'if-tag-in-02': '{% if 2 in x %}yes{% else %}no{% endif %}'})
def test_if_tag_in_02(self):
output = self.engine.render_to_string('if-tag-in-02', {'x': [1]})
self.assertEqual(output, 'no')
@setup({'if-tag-not-in-01': '{% if 1 not in x %}yes{% else %}no{% endif %}'})
def test_if_tag_not_in_01(self):
output = self.engine.render_to_string('if-tag-not-in-01', {'x': [1]})
self.assertEqual(output, 'no')
@setup({'if-tag-not-in-02': '{% if 2 not in x %}yes{% else %}no{% endif %}'})
def test_if_tag_not_in_02(self):
output = self.engine.render_to_string('if-tag-not-in-02', {'x': [1]})
self.assertEqual(output, 'yes')
# AND
@setup({'if-tag-and01': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and01(self):
output = self.engine.render_to_string('if-tag-and01', {'foo': True, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-and02': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and02(self):
output = self.engine.render_to_string('if-tag-and02', {'foo': True, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-and03': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and03(self):
output = self.engine.render_to_string('if-tag-and03', {'foo': False, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-and04': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and04(self):
output = self.engine.render_to_string('if-tag-and04', {'foo': False, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-and05': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and05(self):
output = self.engine.render_to_string('if-tag-and05', {'foo': False})
self.assertEqual(output, 'no')
@setup({'if-tag-and06': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and06(self):
output = self.engine.render_to_string('if-tag-and06', {'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-and07': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and07(self):
output = self.engine.render_to_string('if-tag-and07', {'foo': True})
self.assertEqual(output, 'no')
@setup({'if-tag-and08': '{% if foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_and08(self):
output = self.engine.render_to_string('if-tag-and08', {'bar': True})
self.assertEqual(output, 'no')
# OR
@setup({'if-tag-or01': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or01(self):
output = self.engine.render_to_string('if-tag-or01', {'foo': True, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-or02': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or02(self):
output = self.engine.render_to_string('if-tag-or02', {'foo': True, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-or03': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or03(self):
output = self.engine.render_to_string('if-tag-or03', {'foo': False, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-or04': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or04(self):
output = self.engine.render_to_string('if-tag-or04', {'foo': False, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-or05': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or05(self):
output = self.engine.render_to_string('if-tag-or05', {'foo': False})
self.assertEqual(output, 'no')
@setup({'if-tag-or06': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or06(self):
output = self.engine.render_to_string('if-tag-or06', {'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-or07': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or07(self):
output = self.engine.render_to_string('if-tag-or07', {'foo': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-or08': '{% if foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_or08(self):
output = self.engine.render_to_string('if-tag-or08', {'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-or09': '{% if foo or bar or baz %}yes{% else %}no{% endif %}'})
def test_if_tag_or09(self):
"""
multiple ORs
"""
output = self.engine.render_to_string('if-tag-or09', {'baz': True})
self.assertEqual(output, 'yes')
# NOT
@setup({'if-tag-not01': '{% if not foo %}no{% else %}yes{% endif %}'})
def test_if_tag_not01(self):
output = self.engine.render_to_string('if-tag-not01', {'foo': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not02': '{% if not not foo %}no{% else %}yes{% endif %}'})
def test_if_tag_not02(self):
output = self.engine.render_to_string('if-tag-not02', {'foo': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not06': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not06(self):
output = self.engine.render_to_string('if-tag-not06')
self.assertEqual(output, 'no')
@setup({'if-tag-not07': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not07(self):
output = self.engine.render_to_string('if-tag-not07', {'foo': True, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not08': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not08(self):
output = self.engine.render_to_string('if-tag-not08', {'foo': True, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not09': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not09(self):
output = self.engine.render_to_string('if-tag-not09', {'foo': False, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not10': '{% if foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not10(self):
output = self.engine.render_to_string('if-tag-not10', {'foo': False, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-not11': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not11(self):
output = self.engine.render_to_string('if-tag-not11')
self.assertEqual(output, 'no')
@setup({'if-tag-not12': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not12(self):
output = self.engine.render_to_string('if-tag-not12', {'foo': True, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not13': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not13(self):
output = self.engine.render_to_string('if-tag-not13', {'foo': True, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-not14': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not14(self):
output = self.engine.render_to_string('if-tag-not14', {'foo': False, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not15': '{% if not foo and bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not15(self):
output = self.engine.render_to_string('if-tag-not15', {'foo': False, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-not16': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not16(self):
output = self.engine.render_to_string('if-tag-not16')
self.assertEqual(output, 'yes')
@setup({'if-tag-not17': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not17(self):
output = self.engine.render_to_string('if-tag-not17', {'foo': True, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not18': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not18(self):
output = self.engine.render_to_string('if-tag-not18', {'foo': True, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not19': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not19(self):
output = self.engine.render_to_string('if-tag-not19', {'foo': False, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not20': '{% if foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not20(self):
output = self.engine.render_to_string('if-tag-not20', {'foo': False, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not21': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not21(self):
output = self.engine.render_to_string('if-tag-not21')
self.assertEqual(output, 'yes')
@setup({'if-tag-not22': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not22(self):
output = self.engine.render_to_string('if-tag-not22', {'foo': True, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not23': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not23(self):
output = self.engine.render_to_string('if-tag-not23', {'foo': True, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-not24': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not24(self):
output = self.engine.render_to_string('if-tag-not24', {'foo': False, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not25': '{% if not foo or bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not25(self):
output = self.engine.render_to_string('if-tag-not25', {'foo': False, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not26': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not26(self):
output = self.engine.render_to_string('if-tag-not26')
self.assertEqual(output, 'yes')
@setup({'if-tag-not27': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not27(self):
output = self.engine.render_to_string('if-tag-not27', {'foo': True, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not28': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not28(self):
output = self.engine.render_to_string('if-tag-not28', {'foo': True, 'bar': False})
self.assertEqual(output, 'no')
@setup({'if-tag-not29': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not29(self):
output = self.engine.render_to_string('if-tag-not29', {'foo': False, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not30': '{% if not foo and not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not30(self):
output = self.engine.render_to_string('if-tag-not30', {'foo': False, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not31': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not31(self):
output = self.engine.render_to_string('if-tag-not31')
self.assertEqual(output, 'yes')
@setup({'if-tag-not32': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not32(self):
output = self.engine.render_to_string('if-tag-not32', {'foo': True, 'bar': True})
self.assertEqual(output, 'no')
@setup({'if-tag-not33': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not33(self):
output = self.engine.render_to_string('if-tag-not33', {'foo': True, 'bar': False})
self.assertEqual(output, 'yes')
@setup({'if-tag-not34': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not34(self):
output = self.engine.render_to_string('if-tag-not34', {'foo': False, 'bar': True})
self.assertEqual(output, 'yes')
@setup({'if-tag-not35': '{% if not foo or not bar %}yes{% else %}no{% endif %}'})
def test_if_tag_not35(self):
output = self.engine.render_to_string('if-tag-not35', {'foo': False, 'bar': False})
self.assertEqual(output, 'yes')
# Various syntax errors
@setup({'if-tag-error01': '{% if %}yes{% endif %}'})
def test_if_tag_error01(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error01')
@setup({'if-tag-error02': '{% if foo and %}yes{% else %}no{% endif %}'})
def test_if_tag_error02(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('if-tag-error02', {'foo': True})
@setup({'if-tag-error03': '{% if foo or %}yes{% else %}no{% endif %}'})
def test_if_tag_error03(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('if-tag-error03', {'foo': True})
@setup({'if-tag-error04': '{% if not foo and %}yes{% else %}no{% endif %}'})
def test_if_tag_error04(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('if-tag-error04', {'foo': True})
@setup({'if-tag-error05': '{% if not foo or %}yes{% else %}no{% endif %}'})
def test_if_tag_error05(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('if-tag-error05', {'foo': True})
@setup({'if-tag-error06': '{% if abc def %}yes{% endif %}'})
def test_if_tag_error06(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error06')
@setup({'if-tag-error07': '{% if not %}yes{% endif %}'})
def test_if_tag_error07(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error07')
@setup({'if-tag-error08': '{% if and %}yes{% endif %}'})
def test_if_tag_error08(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error08')
@setup({'if-tag-error09': '{% if or %}yes{% endif %}'})
def test_if_tag_error09(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error09')
@setup({'if-tag-error10': '{% if == %}yes{% endif %}'})
def test_if_tag_error10(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error10')
@setup({'if-tag-error11': '{% if 1 == %}yes{% endif %}'})
def test_if_tag_error11(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error11')
@setup({'if-tag-error12': '{% if a not b %}yes{% endif %}'})
def test_if_tag_error12(self):
with self.assertRaises(TemplateSyntaxError):
self.engine.get_template('if-tag-error12')
@setup({'else-if-tag-error01': '{% if foo is bar %} yes {% else if foo is not bar %} no {% endif %}'})
def test_else_if_tag_error01(self):
error_message = 'Malformed template tag at line 1: "else if foo is not bar"'
with self.assertRaisesMessage(TemplateSyntaxError, error_message):
self.engine.get_template('else-if-tag-error01')
@setup({'if-tag-shortcircuit01': '{% if x.is_true or x.is_bad %}yes{% else %}no{% endif %}'})
def test_if_tag_shortcircuit01(self):
"""
If evaluations are shortcircuited where possible
"""
output = self.engine.render_to_string('if-tag-shortcircuit01', {'x': TestObj()})
self.assertEqual(output, 'yes')
@setup({'if-tag-shortcircuit02': '{% if x.is_false and x.is_bad %}yes{% else %}no{% endif %}'})
def test_if_tag_shortcircuit02(self):
"""
The is_bad() function should not be evaluated. If it is, an
exception is raised.
"""
output = self.engine.render_to_string('if-tag-shortcircuit02', {'x': TestObj()})
self.assertEqual(output, 'no')
@setup({'if-tag-badarg01': '{% if x|default_if_none:y %}yes{% endif %}'})
def test_if_tag_badarg01(self):
"""Nonexistent args"""
output = self.engine.render_to_string('if-tag-badarg01')
self.assertEqual(output, '')
@setup({'if-tag-badarg02': '{% if x|default_if_none:y %}yes{% endif %}'})
def test_if_tag_badarg02(self):
output = self.engine.render_to_string('if-tag-badarg02', {'y': 0})
self.assertEqual(output, '')
@setup({'if-tag-badarg03': '{% if x|default_if_none:y %}yes{% endif %}'})
def test_if_tag_badarg03(self):
output = self.engine.render_to_string('if-tag-badarg03', {'y': 1})
self.assertEqual(output, 'yes')
@setup({'if-tag-badarg04': '{% if x|default_if_none:y %}yes{% else %}no{% endif %}'})
def test_if_tag_badarg04(self):
output = self.engine.render_to_string('if-tag-badarg04')
self.assertEqual(output, 'no')
@setup({'if-tag-single-eq': '{% if foo = bar %}yes{% else %}no{% endif %}'})
def test_if_tag_single_eq(self):
# A single equals sign is a syntax error.
with self.assertRaises(TemplateSyntaxError):
self.engine.render_to_string('if-tag-single-eq', {'foo': 1})
@setup({'template': '{% if foo is True %}yes{% else %}no{% endif %}'})
def test_if_is_match(self):
output = self.engine.render_to_string('template', {'foo': True})
self.assertEqual(output, 'yes')
@setup({'template': '{% if foo is True %}yes{% else %}no{% endif %}'})
def test_if_is_no_match(self):
output = self.engine.render_to_string('template', {'foo': 1})
self.assertEqual(output, 'no')
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
def test_if_is_variable_missing(self):
output = self.engine.render_to_string('template', {'foo': 1})
self.assertEqual(output, 'no')
@setup({'template': '{% if foo is bar %}yes{% else %}no{% endif %}'})
def test_if_is_both_variables_missing(self):
output = self.engine.render_to_string('template', {})
self.assertEqual(output, 'yes')
@setup({'template': '{% if foo is not None %}yes{% else %}no{% endif %}'})
def test_if_is_not_match(self):
# For this to act as a regression test, it's important not to use
# foo=True because True is (not None)
output = self.engine.render_to_string('template', {'foo': False})
self.assertEqual(output, 'yes')
@setup({'template': '{% if foo is not None %}yes{% else %}no{% endif %}'})
def test_if_is_not_no_match(self):
output = self.engine.render_to_string('template', {'foo': None})
self.assertEqual(output, 'no')
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
def test_if_is_not_variable_missing(self):
output = self.engine.render_to_string('template', {'foo': False})
self.assertEqual(output, 'yes')
@setup({'template': '{% if foo is not bar %}yes{% else %}no{% endif %}'})
def test_if_is_not_both_variables_missing(self):
output = self.engine.render_to_string('template', {})
self.assertEqual(output, 'no')
class IfNodeTests(SimpleTestCase):
def test_repr(self):
node = IfNode(conditions_nodelists=[])
self.assertEqual(repr(node), '<IfNode>')
|
bsd-3-clause
|
[
504,
1639,
14,
1160,
492,
17762,
199,
504,
1639,
14,
1160,
14,
885,
2969,
492,
982,
1716,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
2508,
1208,
492,
1379,
5665,
12,
3272,
421,
199,
533,
982,
1931,
2925,
8,
17968,
304,
339,
768,
2758,
3252,
692,
13,
1450,
614,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
614,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
5066,
358,
339,
768,
2758,
3252,
692,
13,
1450,
996,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
996,
297,
791,
1421,
356,
756,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
889,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1644,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1644,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1644,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
889,
358,
339,
768,
2758,
3252,
692,
13,
1450,
966,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
966,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
966,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1717,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1717,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1717,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1690,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1690,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1690,
358,
267,
291,
14,
629,
8,
1199,
12,
4074,
339,
768,
2758,
3252,
692,
13,
1450,
1780,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1780,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1780,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
2036,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
2036,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
2036,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1643,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1643,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1643,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
16323,
358,
339,
768,
2758,
3252,
692,
13,
1450,
709,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
709,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
709,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
845,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
845,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
845,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
713,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
713,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
713,
297,
791,
6185,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
6185,
358,
339,
768,
2758,
3252,
692,
13,
1450,
969,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
969,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
969,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
16323,
358,
339,
327,
21240,
272,
768,
2758,
3252,
692,
13,
1450,
13,
1541,
614,
356,
12100,
340,
3925,
92,
1267,
508,
959,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
63,
1541,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
13,
1541,
614,
297,
791,
1421,
356,
283,
28109,
3071,
267,
291,
14,
629,
8,
1199,
12,
283,
5066,
358,
339,
768,
2758,
3252,
692,
13,
1450,
13,
1541,
996,
356,
12100,
340,
3925,
92,
4142,
508,
8891,
8390,
3985,
3674
] |
[
1639,
14,
1160,
492,
17762,
199,
504,
1639,
14,
1160,
14,
885,
2969,
492,
982,
1716,
199,
504,
1639,
14,
396,
492,
24424,
199,
199,
504,
2508,
1208,
492,
1379,
5665,
12,
3272,
421,
199,
533,
982,
1931,
2925,
8,
17968,
304,
339,
768,
2758,
3252,
692,
13,
1450,
614,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
614,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
5066,
358,
339,
768,
2758,
3252,
692,
13,
1450,
996,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
996,
297,
791,
1421,
356,
756,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
889,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1644,
356,
12100,
340,
3925,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1644,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1644,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
889,
358,
339,
768,
2758,
3252,
692,
13,
1450,
966,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
966,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
966,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1717,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1717,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1717,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1690,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1690,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1690,
358,
267,
291,
14,
629,
8,
1199,
12,
4074,
339,
768,
2758,
3252,
692,
13,
1450,
1780,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1780,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1780,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
2036,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
2036,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
2036,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
1643,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
1643,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
1643,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
16323,
358,
339,
768,
2758,
3252,
692,
13,
1450,
709,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
709,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
709,
297,
791,
1421,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1421,
358,
339,
768,
2758,
3252,
692,
13,
1450,
845,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
845,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
845,
297,
791,
1700,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
1700,
358,
339,
768,
2758,
3252,
692,
13,
1450,
713,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
713,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
713,
297,
791,
6185,
356,
715,
1552,
267,
291,
14,
629,
8,
1199,
12,
283,
6185,
358,
339,
768,
2758,
3252,
692,
13,
1450,
969,
356,
12100,
340,
3925,
3674,
1421,
3996,
916,
4681,
3674,
1700,
3996,
916,
15507,
3674,
6185,
3996,
587,
3674,
16323,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
969,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
969,
358,
267,
291,
14,
629,
8,
1199,
12,
283,
16323,
358,
339,
327,
21240,
272,
768,
2758,
3252,
692,
13,
1450,
13,
1541,
614,
356,
12100,
340,
3925,
92,
1267,
508,
959,
3674,
5066,
3996,
587,
3674,
889,
3996,
14454,
17776,
272,
347,
511,
63,
692,
63,
1450,
63,
1541,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
692,
13,
1450,
13,
1541,
614,
297,
791,
1421,
356,
283,
28109,
3071,
267,
291,
14,
629,
8,
1199,
12,
283,
5066,
358,
339,
768,
2758,
3252,
692,
13,
1450,
13,
1541,
996,
356,
12100,
340,
3925,
92,
4142,
508,
8891,
8390,
3985,
3674,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
saltastro/saltefficiency
|
dataquality/upload_throughput.py
|
1
|
4898
|
import os
import argparse
import glob
import traceback
import mysql
import dataquality as dq
def upload_throughput(sdb, infile, force=False):
"""Upload throughput measurements to the Science Database
Parameters
----------
sdb: ~mysql.sdb
Connection to the Science Database
infile: str
Path to file to upload to the database
force: bool
If True, it will update the database even if an entry
already exists
"""
# parse the name of the file
tab_name, obsdate = dq.parse_filename(infile)
# check if it is already in the table
sel_cmd = "{}_Id, Throughput_Id".format(tab_name)
tab_cmd = "{} join Throughput using (Throughput_Id) join NightInfo using (NightInfo_id) ".format(tab_name)
log_cmd = " Date = '{}-{}-{}'".format(obsdate[0:4], obsdate[4:6], obsdate[6:8])
record = sdb.select(sel_cmd, tab_cmd, log_cmd)
if len(record) > 0 and not force: return
if os.path.basename(infile).startswith('Rss'):
instr='Rss'
elif os.path.basename(infile).startswith('Salticam'):
instr='Salticam'
else:
raise ValueError("File name not recognized")
# parse the file and update or insert into the database
lines = open(infile).readlines()
if len(lines) < 3 :
raise ValueError("Insufficient number of lines in {}".format(infile))
stars = lines[0].strip()
comment = lines[1].strip().strip('\'')
nid = sdb.select('NightInfo_Id', 'NightInfo', log_cmd)[0][0]
#create throughput
try:
tid = sdb.select('Throughput_Id','Throughput', 'NightInfo_Id={}'.format(nid))[0][0]
except:
ins_cmd = "NightInfo_Id = {} , StarsUsed = '{}', Comments = '{}'".format(nid, stars, comment)
sdb.insert(ins_cmd, 'Throughput')
tid = sdb.select('Throughput_Id','Throughput', 'NightInfo_Id={}'.format(nid))[0][0]
if force:
upd_cmd = "StarsUsed = '{}', Comments = '{}'".format(stars, comment)
sdb.update(upd_cmd, 'Throughput', 'Throughput_Id={}'.format(tid))
# upload each of the filters
for l in lines[2:]:
if not l.strip(): return
l = l.split()
if instr == 'Rss':
l[0] = l[0].strip(',')
try:
fid = sdb.select('RssFilter_Id', 'RssFilter', 'Barcode="{}"'.format(l[0]))[0][0]
except IndexError:
raise ValueError('{} is not an RSS Filter'.format(l[0]))
ins_cmd = 'RssFilter_Id={}, RssThroughputMeasurement={}'.format(fid, l[1])
up_cmd = 'RssFilter_Id={} and Throughput_Id={}'.format(fid, tid)
elif instr == 'Salticam':
l[0] = l[0].strip(',')
try:
fid = sdb.select('SalticamFilter_Id', 'SalticamFilter', 'SalticamFilter_Name="{}"'.format(l[0]))[0][0]
except IndexError:
raise ValueError('{} is not an Salticam Filter'.format(l[0]))
ins_cmd = '{}Filter_Id={}, Throughput_Id={}, {}={}'.format(instr, fid, tid, tab_name, l[1])
if len(record)==0:
sdb.insert(ins_cmd, tab_name)
elif force:
up_cmd = '{}Filter_Id={} and Throughput_Id={}'.format(instr, fid, tid)
uid = sdb.select('{}_Id'.format(tab_name), tab_name, up_cmd)[0][0]
sdb.update(ins_cmd, tab_name, '{}_Id={}'.format(tab_name, uid))
if __name__=='__main__':
parser = argparse.ArgumentParser(description='Upload throughput measurents ot the SDB')
parser.add_argument('-dir', dest='throughput_dir', action='store',
default='/salt/logs/dataquality/throughput/',
help='Directory with throughput files')
parser.add_argument('-f', dest='force', action='store_const',
const=True, default=False,
help='Force the updates')
parser.add_argument('-e', dest='email', action='store_const',
const=True, default=False,
help='Email error results')
args = parser.parse_args()
user=os.environ['SDBUSER']
password=os.environ['SDBPASS']
sdb=mysql.mysql(sdbhost, sdbname, user, password, port=3306)
#get the file names
error_msg = ''
for infile in glob.glob(args.throughput_dir+'*.txt'):
try:
upload_throughput(sdb, infile, force=args.force)
except ValueError, e:
error_msg += infile + '\n' + traceback.format_exc() + str(e) + '\n\n'
except IOError, e:
error_msg += infile + '\n' + traceback.format_exc() + str(e) + '\n\n'
if error_msg: print(error_msg)
if email and error_msg:
mailuser = os.environ['MAILUSER']
mailpass = os.environ['MAILPASS']
dq.send_email(error_msg, 'UPLOAD_TRHOUGHPUT Error', username=mailuser,
password=mailpass, to=os.environ['TPUTLIST'], sender = os.environ['MAILSENDER'])
|
bsd-3-clause
|
[
646,
747,
199,
646,
7534,
199,
646,
5739,
199,
646,
5190,
199,
199,
646,
12896,
199,
646,
666,
9161,
465,
366,
81,
421,
199,
318,
5802,
63,
8304,
524,
8,
21624,
12,
14734,
12,
3542,
29,
797,
304,
272,
408,
10301,
4012,
524,
32619,
370,
314,
27491,
8692,
339,
3897,
272,
4143,
272,
308,
697,
26,
6146,
8644,
14,
21624,
4960,
8113,
370,
314,
27491,
8692,
339,
14734,
26,
620,
267,
6912,
370,
570,
370,
5802,
370,
314,
3050,
339,
3542,
26,
2155,
267,
982,
715,
12,
652,
911,
1678,
314,
3050,
2755,
340,
376,
2397,
4960,
2575,
3495,
272,
408,
339,
327,
2198,
314,
536,
402,
314,
570,
272,
5174,
63,
354,
12,
16087,
602,
275,
366,
81,
14,
1122,
63,
1501,
8,
13880,
9,
2378,
327,
1104,
340,
652,
365,
2575,
315,
314,
1817,
272,
13680,
63,
1760,
275,
11491,
63,
1304,
12,
3868,
3202,
524,
63,
1304,
1674,
908,
8,
2902,
63,
354,
9,
272,
5174,
63,
1760,
275,
11491,
4263,
3868,
3202,
524,
1808,
334,
26732,
524,
63,
1304,
9,
4263,
653,
1070,
2354,
1808,
334,
46,
1070,
2354,
63,
344,
9,
3680,
908,
8,
2902,
63,
354,
9,
272,
943,
63,
1760,
275,
298,
6148,
275,
9005,
13,
2440,
13,
2440,
7,
1674,
908,
8,
11226,
602,
59,
16,
26,
20,
467,
16087,
602,
59,
20,
26,
22,
467,
16087,
602,
59,
22,
26,
24,
566,
272,
2777,
275,
308,
697,
14,
2416,
8,
5891,
63,
1760,
12,
5174,
63,
1760,
12,
943,
63,
1760,
9,
339,
340,
822,
8,
3059,
9,
690,
378,
436,
440,
3542,
26,
372,
18407,
340,
747,
14,
515,
14,
4846,
8,
13880,
680,
2460,
360,
50,
385,
735,
2126,
18885,
534,
50,
385,
7,
272,
916,
747,
14,
515,
14,
4846,
8,
13880,
680,
2460,
360,
27177,
764,
455,
735,
2126,
18885,
534,
27177,
764,
455,
7,
272,
587,
26,
2126,
746,
1722,
480,
1173,
536,
440,
18054,
531,
272,
272,
327,
2198,
314,
570,
436,
1678,
503,
5518,
1901,
314,
3050,
272,
2385,
275,
1551,
8,
13880,
680,
9684,
342,
339,
340,
822,
8,
1278,
9,
665,
650,
520,
2126,
746,
1722,
480,
13962,
12983,
1329,
402,
2385,
315,
8352,
908,
8,
13880,
430,
339,
410,
4291,
275,
2385,
59,
16,
1055,
1913,
342,
272,
3721,
275,
2385,
59,
17,
1055,
1913,
1252,
1913,
2258,
17483,
272,
302,
344,
275,
308,
697,
14,
2416,
360,
46,
1070,
2354,
63,
1304,
297,
283,
46,
1070,
2354,
297,
943,
63,
1760,
2788,
16,
1527,
16,
61,
339,
327,
981,
4012,
524,
5591,
862,
26,
2126,
11559,
275,
308,
697,
14,
2416,
360,
26732,
524,
63,
1304,
1673,
26732,
524,
297,
283,
46,
1070,
2354,
63,
1304,
27244,
908,
8,
30411,
11515,
16,
1527,
16,
61,
272,
871,
26,
28872,
5261,
63,
1760,
275,
298,
46,
1070,
2354,
63,
1304,
275,
1052,
2360,
1933,
4291,
9167,
275,
9005,
297,
5429,
1470,
275,
19574,
1674,
908,
8,
30411,
12,
410,
4291,
12,
3721,
9,
2126,
308,
697,
14,
3176,
8,
3617,
63,
1760,
12,
283,
26732,
524,
358,
2126,
11559,
275,
308,
697,
14,
2416,
360,
26732,
524,
63,
1304,
1673,
26732,
524,
297,
283,
46,
1070,
2354,
63,
1304,
27244,
908,
8,
30411,
11515,
16,
1527,
16,
61,
339,
340,
3542,
26,
2126,
1536,
68,
63,
1760,
275,
298,
933,
4291,
9167,
275,
9005,
297,
5429,
1470,
275,
19574,
1674,
908,
8,
270,
4291,
12,
3721,
9,
2126,
308,
697,
14,
873,
8,
27517,
63,
1760,
12,
283,
26732,
524,
297,
283,
26732,
524,
63,
1304,
27244,
908,
8,
5700,
430,
339,
327,
5802,
1924,
402,
314,
4766,
272,
367,
634,
315,
2385,
59,
18,
10688,
267,
340,
440,
634,
14,
1913,
837,
372,
267,
634,
275,
634,
14,
1294,
342,
267,
340,
18885,
508,
283,
50,
385,
356,
7205,
634,
59,
16,
61,
275,
634,
59,
16,
1055,
1913,
11917,
288,
862,
26,
2049,
8289,
275,
308,
697,
14,
2416,
360,
50,
385,
4131,
63,
1304,
297,
283,
50,
385,
4131,
297,
283,
5281,
600,
32053,
2,
1370,
908,
8,
76,
59,
16,
2459,
59,
16,
1527,
16,
61,
288,
871,
7888,
26,
2049,
746,
1722,
17519,
365,
440,
376,
30331,
9388,
1370,
908,
8,
76,
59,
16,
2459,
288,
5261,
63,
1760,
275,
283,
50,
385,
4131,
63,
1304,
10324,
820,
385,
26732,
524,
18611,
434,
27244,
908,
8,
9430,
12,
634,
59,
17,
566,
288,
1536,
63,
1760,
275,
283,
50,
385,
4131,
63,
1304,
7622,
436,
3868,
3202,
524,
63,
1304,
27244,
908,
8,
9430,
12,
11559,
9,
267,
916,
18885,
508,
283,
27177,
764,
455,
356,
288,
634,
59,
16,
61,
275,
634,
59,
16,
1055,
1913,
11917,
288,
862,
26,
2049,
8289,
275,
308,
697,
14,
2416,
360,
27177,
764,
455,
4131,
63,
1304,
297,
283,
27177,
764,
455,
4131,
297,
283,
27177,
764,
455,
4131,
63,
985,
32053,
2,
1370,
908,
8,
76,
59,
16,
2459,
59,
16,
1527,
16,
61,
288,
871,
7888,
26,
2049,
746,
1722,
17519,
365,
440,
376,
428,
279,
764,
455,
9388,
1370,
908,
8,
76,
59,
16,
2459,
267,
5261,
63,
1760,
275,
9005,
4131,
63,
1304,
10324,
3868,
3202,
524,
63,
1304,
10324,
1052,
27244,
908,
8,
21309,
12,
8289,
12,
11559,
12,
5174,
63,
354,
12,
634,
59,
17,
566,
267,
340,
822,
8,
3059,
12694,
16,
26,
288,
308,
697,
14,
3176,
8,
3617,
63,
1760,
12,
5174,
63,
354,
9,
267,
916,
3542,
26,
288,
1536,
63,
1760,
275,
9005,
4131,
63,
1304,
7622,
436,
3868,
3202,
524,
63,
1304,
27244,
908,
8,
21309,
12,
8289,
12,
11559,
9,
288,
1747,
275,
308,
697,
14,
2416,
17519,
63,
1304,
1370,
908,
8,
2902,
63,
354,
395,
5174,
63,
354,
12,
1536,
63,
1760,
2788,
16,
1527,
16,
61,
288,
308,
697,
14,
873,
8,
3617,
63,
1760,
12,
5174,
63,
354,
12,
9005,
63,
1304,
27244,
908,
8,
2902,
63,
354,
12,
1747,
430,
10813,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
534,
10301,
4012,
524,
9775,
343,
83,
312,
84,
314,
428,
2846,
358,
272,
1798,
14,
525,
63,
2094,
3654,
694,
297,
2053,
534,
8304,
524
] |
[
747,
199,
646,
7534,
199,
646,
5739,
199,
646,
5190,
199,
199,
646,
12896,
199,
646,
666,
9161,
465,
366,
81,
421,
199,
318,
5802,
63,
8304,
524,
8,
21624,
12,
14734,
12,
3542,
29,
797,
304,
272,
408,
10301,
4012,
524,
32619,
370,
314,
27491,
8692,
339,
3897,
272,
4143,
272,
308,
697,
26,
6146,
8644,
14,
21624,
4960,
8113,
370,
314,
27491,
8692,
339,
14734,
26,
620,
267,
6912,
370,
570,
370,
5802,
370,
314,
3050,
339,
3542,
26,
2155,
267,
982,
715,
12,
652,
911,
1678,
314,
3050,
2755,
340,
376,
2397,
4960,
2575,
3495,
272,
408,
339,
327,
2198,
314,
536,
402,
314,
570,
272,
5174,
63,
354,
12,
16087,
602,
275,
366,
81,
14,
1122,
63,
1501,
8,
13880,
9,
2378,
327,
1104,
340,
652,
365,
2575,
315,
314,
1817,
272,
13680,
63,
1760,
275,
11491,
63,
1304,
12,
3868,
3202,
524,
63,
1304,
1674,
908,
8,
2902,
63,
354,
9,
272,
5174,
63,
1760,
275,
11491,
4263,
3868,
3202,
524,
1808,
334,
26732,
524,
63,
1304,
9,
4263,
653,
1070,
2354,
1808,
334,
46,
1070,
2354,
63,
344,
9,
3680,
908,
8,
2902,
63,
354,
9,
272,
943,
63,
1760,
275,
298,
6148,
275,
9005,
13,
2440,
13,
2440,
7,
1674,
908,
8,
11226,
602,
59,
16,
26,
20,
467,
16087,
602,
59,
20,
26,
22,
467,
16087,
602,
59,
22,
26,
24,
566,
272,
2777,
275,
308,
697,
14,
2416,
8,
5891,
63,
1760,
12,
5174,
63,
1760,
12,
943,
63,
1760,
9,
339,
340,
822,
8,
3059,
9,
690,
378,
436,
440,
3542,
26,
372,
18407,
340,
747,
14,
515,
14,
4846,
8,
13880,
680,
2460,
360,
50,
385,
735,
2126,
18885,
534,
50,
385,
7,
272,
916,
747,
14,
515,
14,
4846,
8,
13880,
680,
2460,
360,
27177,
764,
455,
735,
2126,
18885,
534,
27177,
764,
455,
7,
272,
587,
26,
2126,
746,
1722,
480,
1173,
536,
440,
18054,
531,
272,
272,
327,
2198,
314,
570,
436,
1678,
503,
5518,
1901,
314,
3050,
272,
2385,
275,
1551,
8,
13880,
680,
9684,
342,
339,
340,
822,
8,
1278,
9,
665,
650,
520,
2126,
746,
1722,
480,
13962,
12983,
1329,
402,
2385,
315,
8352,
908,
8,
13880,
430,
339,
410,
4291,
275,
2385,
59,
16,
1055,
1913,
342,
272,
3721,
275,
2385,
59,
17,
1055,
1913,
1252,
1913,
2258,
17483,
272,
302,
344,
275,
308,
697,
14,
2416,
360,
46,
1070,
2354,
63,
1304,
297,
283,
46,
1070,
2354,
297,
943,
63,
1760,
2788,
16,
1527,
16,
61,
339,
327,
981,
4012,
524,
5591,
862,
26,
2126,
11559,
275,
308,
697,
14,
2416,
360,
26732,
524,
63,
1304,
1673,
26732,
524,
297,
283,
46,
1070,
2354,
63,
1304,
27244,
908,
8,
30411,
11515,
16,
1527,
16,
61,
272,
871,
26,
28872,
5261,
63,
1760,
275,
298,
46,
1070,
2354,
63,
1304,
275,
1052,
2360,
1933,
4291,
9167,
275,
9005,
297,
5429,
1470,
275,
19574,
1674,
908,
8,
30411,
12,
410,
4291,
12,
3721,
9,
2126,
308,
697,
14,
3176,
8,
3617,
63,
1760,
12,
283,
26732,
524,
358,
2126,
11559,
275,
308,
697,
14,
2416,
360,
26732,
524,
63,
1304,
1673,
26732,
524,
297,
283,
46,
1070,
2354,
63,
1304,
27244,
908,
8,
30411,
11515,
16,
1527,
16,
61,
339,
340,
3542,
26,
2126,
1536,
68,
63,
1760,
275,
298,
933,
4291,
9167,
275,
9005,
297,
5429,
1470,
275,
19574,
1674,
908,
8,
270,
4291,
12,
3721,
9,
2126,
308,
697,
14,
873,
8,
27517,
63,
1760,
12,
283,
26732,
524,
297,
283,
26732,
524,
63,
1304,
27244,
908,
8,
5700,
430,
339,
327,
5802,
1924,
402,
314,
4766,
272,
367,
634,
315,
2385,
59,
18,
10688,
267,
340,
440,
634,
14,
1913,
837,
372,
267,
634,
275,
634,
14,
1294,
342,
267,
340,
18885,
508,
283,
50,
385,
356,
7205,
634,
59,
16,
61,
275,
634,
59,
16,
1055,
1913,
11917,
288,
862,
26,
2049,
8289,
275,
308,
697,
14,
2416,
360,
50,
385,
4131,
63,
1304,
297,
283,
50,
385,
4131,
297,
283,
5281,
600,
32053,
2,
1370,
908,
8,
76,
59,
16,
2459,
59,
16,
1527,
16,
61,
288,
871,
7888,
26,
2049,
746,
1722,
17519,
365,
440,
376,
30331,
9388,
1370,
908,
8,
76,
59,
16,
2459,
288,
5261,
63,
1760,
275,
283,
50,
385,
4131,
63,
1304,
10324,
820,
385,
26732,
524,
18611,
434,
27244,
908,
8,
9430,
12,
634,
59,
17,
566,
288,
1536,
63,
1760,
275,
283,
50,
385,
4131,
63,
1304,
7622,
436,
3868,
3202,
524,
63,
1304,
27244,
908,
8,
9430,
12,
11559,
9,
267,
916,
18885,
508,
283,
27177,
764,
455,
356,
288,
634,
59,
16,
61,
275,
634,
59,
16,
1055,
1913,
11917,
288,
862,
26,
2049,
8289,
275,
308,
697,
14,
2416,
360,
27177,
764,
455,
4131,
63,
1304,
297,
283,
27177,
764,
455,
4131,
297,
283,
27177,
764,
455,
4131,
63,
985,
32053,
2,
1370,
908,
8,
76,
59,
16,
2459,
59,
16,
1527,
16,
61,
288,
871,
7888,
26,
2049,
746,
1722,
17519,
365,
440,
376,
428,
279,
764,
455,
9388,
1370,
908,
8,
76,
59,
16,
2459,
267,
5261,
63,
1760,
275,
9005,
4131,
63,
1304,
10324,
3868,
3202,
524,
63,
1304,
10324,
1052,
27244,
908,
8,
21309,
12,
8289,
12,
11559,
12,
5174,
63,
354,
12,
634,
59,
17,
566,
267,
340,
822,
8,
3059,
12694,
16,
26,
288,
308,
697,
14,
3176,
8,
3617,
63,
1760,
12,
5174,
63,
354,
9,
267,
916,
3542,
26,
288,
1536,
63,
1760,
275,
9005,
4131,
63,
1304,
7622,
436,
3868,
3202,
524,
63,
1304,
27244,
908,
8,
21309,
12,
8289,
12,
11559,
9,
288,
1747,
275,
308,
697,
14,
2416,
17519,
63,
1304,
1370,
908,
8,
2902,
63,
354,
395,
5174,
63,
354,
12,
1536,
63,
1760,
2788,
16,
1527,
16,
61,
288,
308,
697,
14,
873,
8,
3617,
63,
1760,
12,
5174,
63,
354,
12,
9005,
63,
1304,
27244,
908,
8,
2902,
63,
354,
12,
1747,
430,
10813,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
534,
10301,
4012,
524,
9775,
343,
83,
312,
84,
314,
428,
2846,
358,
272,
1798,
14,
525,
63,
2094,
3654,
694,
297,
2053,
534,
8304,
524,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ChrisGoedhart/Uforia
|
source/django/views/decorators/cache.py
|
83
|
3975
|
from functools import wraps
from django.utils.decorators import decorator_from_middleware_with_args, available_attrs
from django.utils.cache import patch_cache_control, add_never_cache_headers
from django.middleware.cache import CacheMiddleware
def cache_page(*args, **kwargs):
"""
Decorator for views that tries getting the page from the cache and
populates the cache if the page isn't in the cache yet.
The cache is keyed by the URL and some data from the headers.
Additionally there is the key prefix that is used to distinguish different
cache areas in a multi-site setup. You could use the
sites.get_current().domain, for example, as that is unique across a Django
project.
Additionally, all headers from the response's Vary header will be taken
into account on caching -- just like the middleware does.
"""
# We need backwards compatibility with code which spells it this way:
# def my_view(): pass
# my_view = cache_page(my_view, 123)
# and this way:
# my_view = cache_page(123)(my_view)
# and this:
# my_view = cache_page(my_view, 123, key_prefix="foo")
# and this:
# my_view = cache_page(123, key_prefix="foo")(my_view)
# and possibly this way (?):
# my_view = cache_page(123, my_view)
# and also this way:
# my_view = cache_page(my_view)
# and also this way:
# my_view = cache_page()(my_view)
# We also add some asserts to give better error messages in case people are
# using other ways to call cache_page that no longer work.
cache_alias = kwargs.pop('cache', None)
key_prefix = kwargs.pop('key_prefix', None)
assert not kwargs, "The only keyword arguments are cache and key_prefix"
def warn():
import warnings
warnings.warn('The cache_page decorator must be called like: '
'cache_page(timeout, [cache=cache name], [key_prefix=key prefix]). '
'All other ways are deprecated.',
PendingDeprecationWarning,
stacklevel=3)
if len(args) > 1:
assert len(args) == 2, "cache_page accepts at most 2 arguments"
warn()
if callable(args[0]):
return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[1], cache_alias=cache_alias, key_prefix=key_prefix)(args[0])
elif callable(args[1]):
return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], cache_alias=cache_alias, key_prefix=key_prefix)(args[1])
else:
assert False, "cache_page must be passed a view function if called with two arguments"
elif len(args) == 1:
if callable(args[0]):
warn()
return decorator_from_middleware_with_args(CacheMiddleware)(cache_alias=cache_alias, key_prefix=key_prefix)(args[0])
else:
# The One True Way
return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], cache_alias=cache_alias, key_prefix=key_prefix)
else:
warn()
return decorator_from_middleware_with_args(CacheMiddleware)(cache_alias=cache_alias, key_prefix=key_prefix)
def cache_control(**kwargs):
def _cache_controller(viewfunc):
@wraps(viewfunc, assigned=available_attrs(viewfunc))
def _cache_controlled(request, *args, **kw):
response = viewfunc(request, *args, **kw)
patch_cache_control(response, **kwargs)
return response
return _cache_controlled
return _cache_controller
def never_cache(view_func):
"""
Decorator that adds headers to a response so that it will
never be cached.
"""
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view_func(request, *args, **kwargs):
response = view_func(request, *args, **kwargs)
add_never_cache_headers(response)
return response
return _wrapped_view_func
|
gpl-2.0
|
[
504,
9143,
492,
14018,
199,
504,
1639,
14,
1208,
14,
11582,
492,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
12,
2808,
63,
3288,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
1637,
63,
2785,
12,
1050,
63,
18178,
63,
1637,
63,
2139,
199,
504,
1639,
14,
5754,
14,
1637,
492,
11977,
6608,
421,
199,
318,
2581,
63,
1606,
2031,
589,
12,
1011,
958,
304,
272,
408,
272,
30684,
367,
6858,
626,
11275,
10232,
314,
2034,
687,
314,
2581,
436,
272,
4560,
15409,
314,
2581,
340,
314,
2034,
5712,
1133,
315,
314,
2581,
5966,
14,
339,
710,
2581,
365,
19272,
701,
314,
2851,
436,
2005,
666,
687,
314,
2323,
14,
272,
25448,
2337,
365,
314,
790,
2403,
626,
365,
1202,
370,
22237,
3365,
272,
2581,
787,
305,
315,
282,
3510,
13,
2124,
3272,
14,
2047,
4293,
675,
314,
272,
15424,
14,
362,
63,
1818,
1252,
2261,
12,
367,
2893,
12,
465,
626,
365,
3747,
9371,
282,
5634,
272,
2199,
14,
339,
25448,
12,
1006,
2323,
687,
314,
1177,
1159,
812,
695,
1406,
911,
506,
9394,
272,
1901,
2933,
641,
13627,
1553,
2951,
2839,
314,
10816,
1630,
14,
272,
408,
272,
327,
2136,
1929,
8552,
7163,
543,
1233,
1314,
14475,
76,
478,
652,
642,
4340,
26,
272,
327,
257,
347,
3002,
63,
1345,
837,
986,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
12,
11869,
9,
272,
327,
436,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
5130,
1662,
63,
1345,
9,
272,
327,
436,
642,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
12,
11869,
12,
790,
63,
1861,
628,
1421,
531,
272,
327,
436,
642,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
12,
790,
63,
1861,
628,
1421,
25232,
1662,
63,
1345,
9,
272,
327,
436,
12570,
642,
4340,
7558,
304,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
12,
3002,
63,
1345,
9,
272,
327,
436,
2597,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
9,
272,
327,
436,
2597,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
24851,
1662,
63,
1345,
9,
339,
327,
2136,
2597,
1050,
2005,
702,
83,
370,
8120,
8034,
1125,
3788,
315,
1930,
13135,
787,
272,
327,
1808,
1163,
15217,
370,
1240,
2581,
63,
1606,
626,
949,
8088,
1736,
14,
272,
2581,
63,
3620,
275,
2074,
14,
1935,
360,
1637,
297,
488,
9,
272,
790,
63,
1861,
275,
2074,
14,
1935,
360,
498,
63,
1861,
297,
488,
9,
272,
702,
440,
2074,
12,
298,
1918,
1454,
4252,
2368,
787,
2581,
436,
790,
63,
1861,
2,
272,
347,
7987,
837,
267,
492,
3598,
267,
3598,
14,
4050,
360,
1918,
2581,
63,
1606,
7531,
1471,
506,
2797,
2839,
26,
283,
1993,
283,
1637,
63,
1606,
8,
2593,
12,
359,
1637,
29,
1637,
536,
467,
359,
498,
63,
1861,
29,
498,
2403,
6575,
283,
1993,
283,
2422,
1163,
15217,
787,
5906,
3130,
1993,
29216,
15561,
12,
1993,
13232,
29,
19,
9,
339,
340,
822,
8,
589,
9,
690,
413,
26,
267,
702,
822,
8,
589,
9,
508,
499,
12,
298,
1637,
63,
1606,
11479,
737,
4750,
499,
2368,
2,
267,
7987,
342,
267,
340,
4550,
8,
589,
59,
16,
4682,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
17,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
16,
566,
267,
916,
4550,
8,
589,
59,
17,
4682,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
16,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
17,
566,
267,
587,
26,
288,
702,
756,
12,
298,
1637,
63,
1606,
1471,
506,
3032,
282,
2455,
805,
340,
2797,
543,
2877,
2368,
2,
272,
916,
822,
8,
589,
9,
508,
413,
26,
267,
340,
4550,
8,
589,
59,
16,
4682,
288,
7987,
342,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
16,
566,
267,
587,
26,
288,
327,
710,
7309,
715,
644,
1187,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
16,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
9,
272,
587,
26,
267,
7987,
342,
267,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
9,
421,
199,
318,
2581,
63,
2785,
3682,
958,
304,
272,
347,
485,
1637,
63,
5538,
8,
1345,
1532,
304,
267,
768,
13582,
8,
1345,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
1532,
430,
267,
347,
485,
1637,
63,
2785,
1146,
8,
1069,
12,
627,
589,
12,
1011,
829,
304,
288,
1177,
275,
2455,
1532,
8,
1069,
12,
627,
589,
12,
1011,
829,
9,
288,
3371,
63,
1637,
63,
2785,
8,
1310,
12,
1011,
958,
9,
288,
372,
1177,
267,
372,
485,
1637,
63,
2785,
1146,
272,
372,
485,
1637,
63,
5538,
421,
199,
318,
7078,
63,
1637,
8,
1345,
63,
1532,
304,
272,
408,
272,
30684,
626,
9584,
2323,
370,
282,
1177,
880,
626,
652,
911,
272,
7078,
506,
6328,
14,
272,
408,
272,
768,
13582,
8,
1345,
63,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
63,
1532,
430,
272,
347,
485,
9130,
63,
1345,
63,
1532,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
1177,
275,
2455,
63,
1532,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
1050,
63,
18178,
63,
1637,
63,
2139,
8,
1310,
9,
267,
372,
1177,
272,
372,
485,
9130,
63,
1345,
63,
1532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9143,
492,
14018,
199,
504,
1639,
14,
1208,
14,
11582,
492,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
12,
2808,
63,
3288,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
1637,
63,
2785,
12,
1050,
63,
18178,
63,
1637,
63,
2139,
199,
504,
1639,
14,
5754,
14,
1637,
492,
11977,
6608,
421,
199,
318,
2581,
63,
1606,
2031,
589,
12,
1011,
958,
304,
272,
408,
272,
30684,
367,
6858,
626,
11275,
10232,
314,
2034,
687,
314,
2581,
436,
272,
4560,
15409,
314,
2581,
340,
314,
2034,
5712,
1133,
315,
314,
2581,
5966,
14,
339,
710,
2581,
365,
19272,
701,
314,
2851,
436,
2005,
666,
687,
314,
2323,
14,
272,
25448,
2337,
365,
314,
790,
2403,
626,
365,
1202,
370,
22237,
3365,
272,
2581,
787,
305,
315,
282,
3510,
13,
2124,
3272,
14,
2047,
4293,
675,
314,
272,
15424,
14,
362,
63,
1818,
1252,
2261,
12,
367,
2893,
12,
465,
626,
365,
3747,
9371,
282,
5634,
272,
2199,
14,
339,
25448,
12,
1006,
2323,
687,
314,
1177,
1159,
812,
695,
1406,
911,
506,
9394,
272,
1901,
2933,
641,
13627,
1553,
2951,
2839,
314,
10816,
1630,
14,
272,
408,
272,
327,
2136,
1929,
8552,
7163,
543,
1233,
1314,
14475,
76,
478,
652,
642,
4340,
26,
272,
327,
257,
347,
3002,
63,
1345,
837,
986,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
12,
11869,
9,
272,
327,
436,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
5130,
1662,
63,
1345,
9,
272,
327,
436,
642,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
12,
11869,
12,
790,
63,
1861,
628,
1421,
531,
272,
327,
436,
642,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
12,
790,
63,
1861,
628,
1421,
25232,
1662,
63,
1345,
9,
272,
327,
436,
12570,
642,
4340,
7558,
304,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
4288,
12,
3002,
63,
1345,
9,
272,
327,
436,
2597,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
8,
1662,
63,
1345,
9,
272,
327,
436,
2597,
642,
4340,
26,
272,
327,
257,
3002,
63,
1345,
275,
2581,
63,
1606,
24851,
1662,
63,
1345,
9,
339,
327,
2136,
2597,
1050,
2005,
702,
83,
370,
8120,
8034,
1125,
3788,
315,
1930,
13135,
787,
272,
327,
1808,
1163,
15217,
370,
1240,
2581,
63,
1606,
626,
949,
8088,
1736,
14,
272,
2581,
63,
3620,
275,
2074,
14,
1935,
360,
1637,
297,
488,
9,
272,
790,
63,
1861,
275,
2074,
14,
1935,
360,
498,
63,
1861,
297,
488,
9,
272,
702,
440,
2074,
12,
298,
1918,
1454,
4252,
2368,
787,
2581,
436,
790,
63,
1861,
2,
272,
347,
7987,
837,
267,
492,
3598,
267,
3598,
14,
4050,
360,
1918,
2581,
63,
1606,
7531,
1471,
506,
2797,
2839,
26,
283,
1993,
283,
1637,
63,
1606,
8,
2593,
12,
359,
1637,
29,
1637,
536,
467,
359,
498,
63,
1861,
29,
498,
2403,
6575,
283,
1993,
283,
2422,
1163,
15217,
787,
5906,
3130,
1993,
29216,
15561,
12,
1993,
13232,
29,
19,
9,
339,
340,
822,
8,
589,
9,
690,
413,
26,
267,
702,
822,
8,
589,
9,
508,
499,
12,
298,
1637,
63,
1606,
11479,
737,
4750,
499,
2368,
2,
267,
7987,
342,
267,
340,
4550,
8,
589,
59,
16,
4682,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
17,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
16,
566,
267,
916,
4550,
8,
589,
59,
17,
4682,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
16,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
17,
566,
267,
587,
26,
288,
702,
756,
12,
298,
1637,
63,
1606,
1471,
506,
3032,
282,
2455,
805,
340,
2797,
543,
2877,
2368,
2,
272,
916,
822,
8,
589,
9,
508,
413,
26,
267,
340,
4550,
8,
589,
59,
16,
4682,
288,
7987,
342,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
5130,
589,
59,
16,
566,
267,
587,
26,
288,
327,
710,
7309,
715,
644,
1187,
288,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
2593,
29,
589,
59,
16,
467,
2581,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
9,
272,
587,
26,
267,
7987,
342,
267,
372,
7531,
63,
504,
63,
5754,
63,
1045,
63,
589,
8,
4437,
6608,
5130,
1637,
63,
3620,
29,
1637,
63,
3620,
12,
790,
63,
1861,
29,
498,
63,
1861,
9,
421,
199,
318,
2581,
63,
2785,
3682,
958,
304,
272,
347,
485,
1637,
63,
5538,
8,
1345,
1532,
304,
267,
768,
13582,
8,
1345,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
1532,
430,
267,
347,
485,
1637,
63,
2785,
1146,
8,
1069,
12,
627,
589,
12,
1011,
829,
304,
288,
1177,
275,
2455,
1532,
8,
1069,
12,
627,
589,
12,
1011,
829,
9,
288,
3371,
63,
1637,
63,
2785,
8,
1310,
12,
1011,
958,
9,
288,
372,
1177,
267,
372,
485,
1637,
63,
2785,
1146,
272,
372,
485,
1637,
63,
5538,
421,
199,
318,
7078,
63,
1637,
8,
1345,
63,
1532,
304,
272,
408,
272,
30684,
626,
9584,
2323,
370,
282,
1177,
880,
626,
652,
911,
272,
7078,
506,
6328,
14,
272,
408,
272,
768,
13582,
8,
1345,
63,
1532,
12,
7943,
29,
4561,
63,
3288,
8,
1345,
63,
1532,
430,
272,
347,
485,
9130,
63,
1345,
63,
1532,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
1177,
275,
2455,
63,
1532,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
1050,
63,
18178,
63,
1637,
63,
2139,
8,
1310,
9,
267,
372,
1177,
272,
372,
485,
9130,
63,
1345,
63,
1532,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shohei/Octoprint
|
tests/users/__init__.py
|
4
|
4243
|
# coding=utf-8
"""
Unit tests for octoprint.users
"""
from __future__ import absolute_import, division, print_function
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
import unittest
import ddt
import octoprint.users
from octoprint.util import dict_merge
default_settings = dict(key="value", sub=dict(subkey="subvalue"))
@ddt.ddt
class UserTestCase(unittest.TestCase):
def setUp(self):
self.user = octoprint.users.User("user", "passwordHash", True, ("user",), apikey="apikey_user", settings=default_settings)
self.admin = octoprint.users.User("admin", "passwordHash", True, ("user","admin"), apikey="apikey_admin", settings=default_settings)
self.inactive = octoprint.users.User("inactive", "passwordHash", False, ("user",), apikey="apikey_inactive", settings=default_settings)
@ddt.data(
("user", dict(name="user",
active=True,
admin=False,
user=True,
apikey="apikey_user",
settings=default_settings)),
("admin", dict(name="admin",
active=True,
admin=True,
user=True,
apikey="apikey_admin",
settings=default_settings)),
("inactive", dict(name="inactive",
active=False,
admin=False,
user=True,
apikey="apikey_inactive",
settings=default_settings))
)
@ddt.unpack
def test_as_dict(self, uservar, expected):
user = getattr(self, uservar)
self.assertDictEqual(expected, user.asDict())
@ddt.data(
("key", "value"),
(["sub", "subkey"], "subvalue"),
("doesntexist", None)
)
@ddt.unpack
def test_get_setting(self, key, expected):
value = self.user.get_setting(key)
self.assertEqual(expected, value)
@ddt.data(
("otherkey", "othervalue", dict(otherkey="othervalue"), True),
(["sub", "othersubkey"], "othersubvalue", dict(sub=dict(othersubkey="othersubvalue")), True),
("booleankey", True, dict(booleankey=True), True),
(["newsub", "newsubkey"], "newsubvalue", dict(newsub=dict(newsubkey="newsubvalue")), True),
(["sub", "subkey", "wontwork"], "wontwork", dict(), False)
)
@ddt.unpack
def test_set_setting_string(self, key, value, update, expected_returnvalue):
returnvalue = self.user.set_setting(key, value)
expected = dict_merge(default_settings, update)
self.assertDictEqual(expected, self.user.get_all_settings())
self.assertEqual(expected_returnvalue, returnvalue)
def test_check_password(self):
self.assertTrue(self.user.check_password("passwordHash"))
self.assertFalse(self.user.check_password("notThePasswordHash"))
@ddt.data(
("user", "User(id=user,name=user,active=True,user=True,admin=False)"),
("admin", "User(id=admin,name=admin,active=True,user=True,admin=True)"),
("inactive", "User(id=inactive,name=inactive,active=False,user=True,admin=False)")
)
@ddt.unpack
def test_repr(self, uservar, output):
self.assertEqual(output, repr(getattr(self, uservar)))
class SessionUserTestCase(unittest.TestCase):
def setUp(self):
self.user = octoprint.users.User("username", "passwordHash", True, ("user",), apikey="apikey", settings=dict(key="value"))
def test_two_sessions(self):
session1 = octoprint.users.SessionUser(self.user)
session2 = octoprint.users.SessionUser(self.user)
self.assertNotEqual(session1.get_session(), session2.get_session())
self.assertEqual(session1._user, session2._user)
self.assertEqual(session1._username, session2._username)
def test_settings_change_propagates(self):
user = octoprint.users.SessionUser(self.user)
self.user.set_setting("otherkey", "othervalue")
self.assertDictEqual(dict(key="value", otherkey="othervalue"), user.get_all_settings())
def test_repr(self):
user = octoprint.users.SessionUser(self.user)
expected = "SessionUser(id=username,name=username,active=True,user=True,admin=False,session={},created={})".format(user._session, user._created)
self.assertEqual(expected, repr(user))
|
agpl-3.0
|
[
3,
2803,
29,
1624,
13,
24,
199,
624,
199,
5072,
2295,
367,
17162,
411,
672,
14,
3707,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
2502,
363,
275,
298,
39,
13765,
869,
13733,
85,
128,
254,
303,
665,
736,
68,
32,
1421,
5891,
14,
846,
4335,
199,
363,
1682,
363,
275,
283,
17732,
4265,
1696,
1684,
844,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
7,
199,
363,
7307,
363,
275,
298,
7384,
334,
35,
9,
6900,
710,
18365,
79,
5375,
7290,
446,
17646,
68,
1334,
2895,
402,
314,
437,
28863,
19,
844,
2,
199,
199,
646,
2882,
199,
646,
366,
3583,
199,
199,
646,
17162,
411,
672,
14,
3707,
199,
504,
17162,
411,
672,
14,
1974,
492,
1211,
63,
5628,
199,
199,
885,
63,
1751,
275,
1211,
8,
498,
628,
585,
401,
1007,
29,
807,
8,
954,
498,
628,
954,
585,
2237,
199,
199,
32,
11138,
14,
11138,
199,
533,
2876,
1746,
8,
2796,
14,
1746,
304,
199,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
751,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
751,
401,
298,
2060,
3476,
401,
715,
12,
1689,
751,
18529,
2986,
498,
628,
28181,
63,
751,
401,
2202,
29,
885,
63,
1751,
9,
507,
198,
277,
14,
2113,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
2113,
401,
298,
2060,
3476,
401,
715,
12,
1689,
751,
2266,
2113,
1288,
2986,
498,
628,
28181,
63,
2113,
401,
2202,
29,
885,
63,
1751,
9,
507,
198,
277,
14,
16856,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
16856,
401,
298,
2060,
3476,
401,
756,
12,
1689,
751,
18529,
2986,
498,
628,
28181,
63,
16856,
401,
2202,
29,
885,
63,
1751,
9,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
751,
401,
258,
1211,
8,
354,
628,
751,
401,
686,
8295,
4702,
29,
549,
12,
686,
8295,
4628,
29,
797,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
751,
401,
686,
8295,
2202,
29,
885,
63,
1751,
1826,
507,
198,
480,
2113,
401,
259,
1211,
8,
354,
628,
2113,
401,
686,
8295,
4702,
29,
549,
12,
686,
8295,
4628,
29,
549,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
2113,
401,
686,
8295,
2202,
29,
885,
63,
1751,
1826,
507,
198,
480,
16856,
401,
1211,
8,
354,
628,
16856,
401,
686,
8295,
4702,
29,
797,
12,
686,
8295,
4628,
29,
797,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
16856,
401,
686,
8295,
2202,
29,
885,
63,
1751,
430,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
305,
63,
807,
8,
277,
12,
922,
1391,
12,
1420,
304,
507,
198,
751,
275,
2519,
8,
277,
12,
922,
1391,
9,
507,
198,
277,
14,
19512,
8,
2062,
12,
922,
14,
305,
2141,
1012,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
498,
401,
298,
585,
1288,
507,
198,
5234,
954,
401,
298,
954,
498,
2255,
298,
954,
585,
1288,
507,
198,
480,
30977,
3858,
631,
401,
488,
9,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
362,
63,
6031,
8,
277,
12,
790,
12,
1420,
304,
507,
198,
585,
275,
291,
14,
751,
14,
362,
63,
6031,
8,
498,
9,
507,
198,
277,
14,
629,
8,
2062,
12,
574,
9,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
1848,
498,
401,
298,
1848,
585,
401,
1211,
8,
1848,
498,
628,
1848,
585,
1288,
715,
395,
507,
198,
5234,
954,
401,
298,
1848,
954,
498,
2255,
298,
1848,
954,
585,
401,
1211,
8,
954,
29,
807,
8,
1848,
954,
498,
628,
1848,
954,
585,
8150,
715,
395,
507,
198,
480,
4871,
498,
401,
715,
12,
1211,
8,
4871,
498,
29,
549,
395,
715,
395,
507,
198,
5234,
1222,
954,
401,
298,
1222,
954,
498,
2255,
298,
1222,
954,
585,
401,
1211,
8,
1222,
954,
29,
807,
8,
1222,
954,
498,
628,
1222,
954,
585,
8150,
715,
395,
507,
198,
5234,
954,
401,
298,
954,
498,
401,
298,
87,
1888,
800,
2255,
298,
87,
1888,
800,
401,
1211,
1062,
756,
9,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
409,
63,
6031,
63,
875,
8,
277,
12,
790,
12,
574,
12,
1678,
12,
1420,
63,
1107,
585,
304,
507,
198,
1107,
585,
275,
291,
14,
751,
14,
409,
63,
6031,
8,
498,
12,
574,
9,
2742,
198,
2062,
275,
1211,
63,
5628,
8,
885,
63,
1751,
12,
1678,
9,
2742,
198,
277,
14,
19512,
8,
2062,
12,
291,
14,
751,
14,
362,
63,
452,
63,
1751,
1012,
507,
198,
277,
14,
629,
8,
2062,
63,
1107,
585,
12,
372,
585,
9,
421,
198,
318,
511,
63,
1074,
63,
2060,
8,
277,
304,
507,
198,
277,
14,
1815,
8,
277,
14,
751,
14,
1074,
63,
2060,
480,
2060,
3476,
2237,
507,
198,
277,
14,
3334,
8,
277,
14,
751,
14,
1074,
63,
2060,
480,
1397,
1918,
6139,
3476,
2237,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
751,
401,
298,
1899,
8,
344,
29,
751,
12,
354,
29,
751,
12,
2682,
29,
549,
12,
751,
29,
549,
12,
2113,
29,
797,
13185,
507,
198,
480,
2113,
401,
298,
1899,
8,
344,
29,
2113,
12,
354,
29,
2113,
12,
2682,
29,
549,
12,
751,
29,
549,
12,
2113,
29,
549,
13185,
507,
198,
480,
16856,
401,
298,
1899,
8,
344,
29,
16856,
12,
354,
29,
16856,
12,
2682,
29,
797,
12,
751,
29,
549,
12,
2113,
29,
797,
6320,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
2722,
8,
277,
12,
922,
1391,
12,
1072,
304,
507,
198,
277,
14,
629,
8,
1199,
12,
4700,
8,
5675,
8,
277,
12,
922,
1391,
1724,
199,
199,
533,
8596,
1899,
1746,
8,
2796,
14,
1746,
304,
421,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
751,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
2473,
401,
298,
2060,
3476,
401,
715
] |
[
2803,
29,
1624,
13,
24,
199,
624,
199,
5072,
2295,
367,
17162,
411,
672,
14,
3707,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
2502,
363,
275,
298,
39,
13765,
869,
13733,
85,
128,
254,
303,
665,
736,
68,
32,
1421,
5891,
14,
846,
4335,
199,
363,
1682,
363,
275,
283,
17732,
4265,
1696,
1684,
844,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
643,
1168,
14,
1360,
7,
199,
363,
7307,
363,
275,
298,
7384,
334,
35,
9,
6900,
710,
18365,
79,
5375,
7290,
446,
17646,
68,
1334,
2895,
402,
314,
437,
28863,
19,
844,
2,
199,
199,
646,
2882,
199,
646,
366,
3583,
199,
199,
646,
17162,
411,
672,
14,
3707,
199,
504,
17162,
411,
672,
14,
1974,
492,
1211,
63,
5628,
199,
199,
885,
63,
1751,
275,
1211,
8,
498,
628,
585,
401,
1007,
29,
807,
8,
954,
498,
628,
954,
585,
2237,
199,
199,
32,
11138,
14,
11138,
199,
533,
2876,
1746,
8,
2796,
14,
1746,
304,
199,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
751,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
751,
401,
298,
2060,
3476,
401,
715,
12,
1689,
751,
18529,
2986,
498,
628,
28181,
63,
751,
401,
2202,
29,
885,
63,
1751,
9,
507,
198,
277,
14,
2113,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
2113,
401,
298,
2060,
3476,
401,
715,
12,
1689,
751,
2266,
2113,
1288,
2986,
498,
628,
28181,
63,
2113,
401,
2202,
29,
885,
63,
1751,
9,
507,
198,
277,
14,
16856,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
16856,
401,
298,
2060,
3476,
401,
756,
12,
1689,
751,
18529,
2986,
498,
628,
28181,
63,
16856,
401,
2202,
29,
885,
63,
1751,
9,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
751,
401,
258,
1211,
8,
354,
628,
751,
401,
686,
8295,
4702,
29,
549,
12,
686,
8295,
4628,
29,
797,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
751,
401,
686,
8295,
2202,
29,
885,
63,
1751,
1826,
507,
198,
480,
2113,
401,
259,
1211,
8,
354,
628,
2113,
401,
686,
8295,
4702,
29,
549,
12,
686,
8295,
4628,
29,
549,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
2113,
401,
686,
8295,
2202,
29,
885,
63,
1751,
1826,
507,
198,
480,
16856,
401,
1211,
8,
354,
628,
16856,
401,
686,
8295,
4702,
29,
797,
12,
686,
8295,
4628,
29,
797,
12,
686,
8295,
922,
29,
549,
12,
686,
8295,
2986,
498,
628,
28181,
63,
16856,
401,
686,
8295,
2202,
29,
885,
63,
1751,
430,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
305,
63,
807,
8,
277,
12,
922,
1391,
12,
1420,
304,
507,
198,
751,
275,
2519,
8,
277,
12,
922,
1391,
9,
507,
198,
277,
14,
19512,
8,
2062,
12,
922,
14,
305,
2141,
1012,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
498,
401,
298,
585,
1288,
507,
198,
5234,
954,
401,
298,
954,
498,
2255,
298,
954,
585,
1288,
507,
198,
480,
30977,
3858,
631,
401,
488,
9,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
362,
63,
6031,
8,
277,
12,
790,
12,
1420,
304,
507,
198,
585,
275,
291,
14,
751,
14,
362,
63,
6031,
8,
498,
9,
507,
198,
277,
14,
629,
8,
2062,
12,
574,
9,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
1848,
498,
401,
298,
1848,
585,
401,
1211,
8,
1848,
498,
628,
1848,
585,
1288,
715,
395,
507,
198,
5234,
954,
401,
298,
1848,
954,
498,
2255,
298,
1848,
954,
585,
401,
1211,
8,
954,
29,
807,
8,
1848,
954,
498,
628,
1848,
954,
585,
8150,
715,
395,
507,
198,
480,
4871,
498,
401,
715,
12,
1211,
8,
4871,
498,
29,
549,
395,
715,
395,
507,
198,
5234,
1222,
954,
401,
298,
1222,
954,
498,
2255,
298,
1222,
954,
585,
401,
1211,
8,
1222,
954,
29,
807,
8,
1222,
954,
498,
628,
1222,
954,
585,
8150,
715,
395,
507,
198,
5234,
954,
401,
298,
954,
498,
401,
298,
87,
1888,
800,
2255,
298,
87,
1888,
800,
401,
1211,
1062,
756,
9,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
409,
63,
6031,
63,
875,
8,
277,
12,
790,
12,
574,
12,
1678,
12,
1420,
63,
1107,
585,
304,
507,
198,
1107,
585,
275,
291,
14,
751,
14,
409,
63,
6031,
8,
498,
12,
574,
9,
2742,
198,
2062,
275,
1211,
63,
5628,
8,
885,
63,
1751,
12,
1678,
9,
2742,
198,
277,
14,
19512,
8,
2062,
12,
291,
14,
751,
14,
362,
63,
452,
63,
1751,
1012,
507,
198,
277,
14,
629,
8,
2062,
63,
1107,
585,
12,
372,
585,
9,
421,
198,
318,
511,
63,
1074,
63,
2060,
8,
277,
304,
507,
198,
277,
14,
1815,
8,
277,
14,
751,
14,
1074,
63,
2060,
480,
2060,
3476,
2237,
507,
198,
277,
14,
3334,
8,
277,
14,
751,
14,
1074,
63,
2060,
480,
1397,
1918,
6139,
3476,
2237,
421,
198,
32,
11138,
14,
576,
8,
507,
198,
480,
751,
401,
298,
1899,
8,
344,
29,
751,
12,
354,
29,
751,
12,
2682,
29,
549,
12,
751,
29,
549,
12,
2113,
29,
797,
13185,
507,
198,
480,
2113,
401,
298,
1899,
8,
344,
29,
2113,
12,
354,
29,
2113,
12,
2682,
29,
549,
12,
751,
29,
549,
12,
2113,
29,
549,
13185,
507,
198,
480,
16856,
401,
298,
1899,
8,
344,
29,
16856,
12,
354,
29,
16856,
12,
2682,
29,
797,
12,
751,
29,
549,
12,
2113,
29,
797,
6320,
199,
198,
9,
199,
198,
32,
11138,
14,
5301,
199,
198,
318,
511,
63,
2722,
8,
277,
12,
922,
1391,
12,
1072,
304,
507,
198,
277,
14,
629,
8,
1199,
12,
4700,
8,
5675,
8,
277,
12,
922,
1391,
1724,
199,
199,
533,
8596,
1899,
1746,
8,
2796,
14,
1746,
304,
421,
198,
318,
3613,
8,
277,
304,
507,
198,
277,
14,
751,
275,
17162,
411,
672,
14,
3707,
14,
1899,
480,
2473,
401,
298,
2060,
3476,
401,
715,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
willingc/oh-mainline
|
vendor/packages/celery/celery/tests/test_backends/test_redis.py
|
18
|
3445
|
from __future__ import absolute_import
from __future__ import with_statement
import sys
import socket
from nose import SkipTest
from celery.exceptions import ImproperlyConfigured
from celery import states
from celery.utils import uuid
from celery.backends import redis
from celery.backends.redis import RedisBackend
from celery.tests.utils import mask_modules
from celery.tests.utils import unittest
_no_redis_msg = "* Redis %s. Will not execute related tests."
_no_redis_msg_emitted = False
try:
from redis.exceptions import ConnectionError
except ImportError:
class ConnectionError(socket.error): # noqa
pass
class SomeClass(object):
def __init__(self, data):
self.data = data
def get_redis_or_SkipTest():
def emit_no_redis_msg(reason):
global _no_redis_msg_emitted
if not _no_redis_msg_emitted:
sys.stderr.write("\n" + _no_redis_msg % reason + "\n")
_no_redis_msg_emitted = True
if redis.redis is None:
emit_no_redis_msg("not installed")
raise SkipTest("redis library not installed")
try:
tb = RedisBackend(redis_db="celery_unittest")
try:
# Evaluate lazy connection
tb.client.info()
except ConnectionError, exc:
emit_no_redis_msg("not running")
raise SkipTest("can't connect to redis: %s" % (exc, ))
return tb
except ImproperlyConfigured, exc:
if "need to install" in str(exc):
return emit_no_redis_msg("not installed")
return emit_no_redis_msg("not configured")
class TestRedisBackend(unittest.TestCase):
def test_mark_as_done(self):
tb = get_redis_or_SkipTest()
tid = uuid()
self.assertEqual(tb.get_status(tid), states.PENDING)
self.assertIsNone(tb.get_result(tid))
tb.mark_as_done(tid, 42)
self.assertEqual(tb.get_status(tid), states.SUCCESS)
self.assertEqual(tb.get_result(tid), 42)
def test_is_pickled(self):
tb = get_redis_or_SkipTest()
tid2 = uuid()
result = {"foo": "baz", "bar": SomeClass(12345)}
tb.mark_as_done(tid2, result)
# is serialized properly.
rindb = tb.get_result(tid2)
self.assertEqual(rindb.get("foo"), "baz")
self.assertEqual(rindb.get("bar").data, 12345)
def test_mark_as_failure(self):
tb = get_redis_or_SkipTest()
tid3 = uuid()
try:
raise KeyError("foo")
except KeyError, exception:
pass
tb.mark_as_failure(tid3, exception)
self.assertEqual(tb.get_status(tid3), states.FAILURE)
self.assertIsInstance(tb.get_result(tid3), KeyError)
class TestRedisBackendNoRedis(unittest.TestCase):
def test_redis_None_if_redis_not_installed(self):
prev = sys.modules.pop("celery.backends.redis")
try:
with mask_modules("redis"):
from celery.backends.redis import redis
self.assertIsNone(redis)
finally:
sys.modules["celery.backends.redis"] = prev
def test_constructor_raises_if_redis_not_installed(self):
from celery.backends import redis
prev = redis.RedisBackend.redis
redis.RedisBackend.redis = None
try:
with self.assertRaises(ImproperlyConfigured):
redis.RedisBackend()
finally:
redis.RedisBackend.redis = prev
|
agpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
984,
199,
646,
2838,
199,
199,
504,
11354,
492,
18795,
199,
199,
504,
22748,
14,
3924,
492,
11897,
199,
199,
504,
22748,
492,
6363,
199,
504,
22748,
14,
1208,
492,
5377,
199,
504,
22748,
14,
7765,
492,
16967,
199,
504,
22748,
14,
7765,
14,
15369,
492,
25496,
8447,
199,
504,
22748,
14,
2219,
14,
1208,
492,
3656,
63,
3112,
199,
504,
22748,
14,
2219,
14,
1208,
492,
2882,
199,
199,
63,
889,
63,
15369,
63,
1328,
275,
8969,
25496,
450,
83,
14,
12823,
440,
5341,
4048,
2295,
2122,
199,
63,
889,
63,
15369,
63,
1328,
63,
69,
4485,
275,
756,
199,
199,
893,
26,
272,
687,
16967,
14,
3924,
492,
25417,
199,
2590,
3545,
26,
272,
1021,
25417,
8,
3450,
14,
705,
304,
221,
327,
8151,
267,
986,
421,
199,
533,
6601,
2543,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
576,
275,
666,
421,
199,
318,
664,
63,
15369,
63,
269,
63,
25755,
837,
339,
347,
8689,
63,
889,
63,
15369,
63,
1328,
8,
5764,
304,
267,
2288,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
267,
340,
440,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
26,
288,
984,
14,
3083,
14,
952,
4582,
78,
2,
435,
485,
889,
63,
15369,
63,
1328,
450,
4499,
435,
1867,
78,
531,
288,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
275,
715,
339,
340,
16967,
14,
15369,
365,
488,
26,
267,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
4903,
531,
267,
746,
18795,
480,
15369,
3555,
440,
4903,
531,
272,
862,
26,
267,
7070,
275,
25496,
8447,
8,
15369,
63,
697,
628,
23593,
63,
2796,
531,
267,
862,
26,
288,
327,
27450,
9617,
1950,
288,
7070,
14,
1258,
14,
815,
342,
267,
871,
25417,
12,
3178,
26,
288,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
3879,
531,
288,
746,
18795,
480,
2425,
1133,
4907,
370,
16967,
26,
450,
83,
2,
450,
334,
2804,
12,
5082,
267,
372,
7070,
272,
871,
11897,
12,
3178,
26,
267,
340,
298,
9321,
370,
3907,
2,
315,
620,
8,
2804,
304,
288,
372,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
4903,
531,
267,
372,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
7526,
531,
421,
199,
533,
1379,
29605,
8447,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1657,
63,
305,
63,
4456,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
275,
5377,
342,
398,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
395,
6363,
14,
21243,
9,
267,
291,
14,
7702,
8,
5842,
14,
362,
63,
1099,
8,
5700,
430,
398,
7070,
14,
1657,
63,
305,
63,
4456,
8,
5700,
12,
5685,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
395,
6363,
14,
12779,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1099,
8,
5700,
395,
5685,
9,
339,
347,
511,
63,
374,
63,
20428,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
18,
275,
5377,
342,
267,
754,
275,
2420,
1421,
582,
298,
6185,
401,
298,
1700,
582,
6601,
2543,
8,
13261,
6769,
267,
7070,
14,
1657,
63,
305,
63,
4456,
8,
5700,
18,
12,
754,
9,
267,
327,
365,
6380,
7684,
14,
267,
519,
688,
66,
275,
7070,
14,
362,
63,
1099,
8,
5700,
18,
9,
267,
291,
14,
629,
8,
82,
688,
66,
14,
362,
480,
1421,
1288,
298,
6185,
531,
267,
291,
14,
629,
8,
82,
688,
66,
14,
362,
480,
1700,
3471,
576,
12,
25538,
9,
339,
347,
511,
63,
1657,
63,
305,
63,
5328,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
19,
275,
5377,
342,
267,
862,
26,
288,
746,
4067,
480,
1421,
531,
267,
871,
4067,
12,
1919,
26,
288,
986,
267,
7070,
14,
1657,
63,
305,
63,
5328,
8,
5700,
19,
12,
1919,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
19,
395,
6363,
14,
13989,
9,
267,
291,
14,
6926,
8,
5842,
14,
362,
63,
1099,
8,
5700,
19,
395,
4067,
9,
421,
199,
533,
1379,
29605,
8447,
1944,
29605,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
15369,
63,
403,
63,
692,
63,
15369,
63,
1397,
63,
7657,
8,
277,
304,
267,
5071,
275,
984,
14,
3112,
14,
1935,
480,
23593,
14,
7765,
14,
15369,
531,
267,
862,
26,
288,
543,
3656,
63,
3112,
480,
15369,
2349,
355,
687,
22748,
14,
7765,
14,
15369,
492,
16967,
355,
291,
14,
7702,
8,
15369,
9,
267,
3753,
26,
288,
984,
14,
3112,
905,
23593,
14,
7765,
14,
15369,
937,
275,
5071,
339,
347,
511,
63,
1880,
63,
3536,
63,
692,
63,
15369,
63,
1397,
63,
7657,
8,
277,
304,
267,
687,
22748,
14,
7765,
492,
16967,
267,
5071,
275,
16967,
14,
29605,
8447,
14,
15369,
267,
16967,
14,
29605,
8447,
14,
15369,
275,
488,
267,
862,
26,
288,
543,
291,
14,
1855,
8,
8499,
10951,
304,
355,
16967,
14,
29605,
8447,
342,
267,
3753,
26,
288,
16967,
14,
29605,
8447,
14,
15369,
275,
5071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
984,
199,
646,
2838,
199,
199,
504,
11354,
492,
18795,
199,
199,
504,
22748,
14,
3924,
492,
11897,
199,
199,
504,
22748,
492,
6363,
199,
504,
22748,
14,
1208,
492,
5377,
199,
504,
22748,
14,
7765,
492,
16967,
199,
504,
22748,
14,
7765,
14,
15369,
492,
25496,
8447,
199,
504,
22748,
14,
2219,
14,
1208,
492,
3656,
63,
3112,
199,
504,
22748,
14,
2219,
14,
1208,
492,
2882,
199,
199,
63,
889,
63,
15369,
63,
1328,
275,
8969,
25496,
450,
83,
14,
12823,
440,
5341,
4048,
2295,
2122,
199,
63,
889,
63,
15369,
63,
1328,
63,
69,
4485,
275,
756,
199,
199,
893,
26,
272,
687,
16967,
14,
3924,
492,
25417,
199,
2590,
3545,
26,
272,
1021,
25417,
8,
3450,
14,
705,
304,
221,
327,
8151,
267,
986,
421,
199,
533,
6601,
2543,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
666,
304,
267,
291,
14,
576,
275,
666,
421,
199,
318,
664,
63,
15369,
63,
269,
63,
25755,
837,
339,
347,
8689,
63,
889,
63,
15369,
63,
1328,
8,
5764,
304,
267,
2288,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
267,
340,
440,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
26,
288,
984,
14,
3083,
14,
952,
4582,
78,
2,
435,
485,
889,
63,
15369,
63,
1328,
450,
4499,
435,
1867,
78,
531,
288,
485,
889,
63,
15369,
63,
1328,
63,
69,
4485,
275,
715,
339,
340,
16967,
14,
15369,
365,
488,
26,
267,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
4903,
531,
267,
746,
18795,
480,
15369,
3555,
440,
4903,
531,
272,
862,
26,
267,
7070,
275,
25496,
8447,
8,
15369,
63,
697,
628,
23593,
63,
2796,
531,
267,
862,
26,
288,
327,
27450,
9617,
1950,
288,
7070,
14,
1258,
14,
815,
342,
267,
871,
25417,
12,
3178,
26,
288,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
3879,
531,
288,
746,
18795,
480,
2425,
1133,
4907,
370,
16967,
26,
450,
83,
2,
450,
334,
2804,
12,
5082,
267,
372,
7070,
272,
871,
11897,
12,
3178,
26,
267,
340,
298,
9321,
370,
3907,
2,
315,
620,
8,
2804,
304,
288,
372,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
4903,
531,
267,
372,
8689,
63,
889,
63,
15369,
63,
1328,
480,
1397,
7526,
531,
421,
199,
533,
1379,
29605,
8447,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
1657,
63,
305,
63,
4456,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
275,
5377,
342,
398,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
395,
6363,
14,
21243,
9,
267,
291,
14,
7702,
8,
5842,
14,
362,
63,
1099,
8,
5700,
430,
398,
7070,
14,
1657,
63,
305,
63,
4456,
8,
5700,
12,
5685,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
395,
6363,
14,
12779,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1099,
8,
5700,
395,
5685,
9,
339,
347,
511,
63,
374,
63,
20428,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
18,
275,
5377,
342,
267,
754,
275,
2420,
1421,
582,
298,
6185,
401,
298,
1700,
582,
6601,
2543,
8,
13261,
6769,
267,
7070,
14,
1657,
63,
305,
63,
4456,
8,
5700,
18,
12,
754,
9,
267,
327,
365,
6380,
7684,
14,
267,
519,
688,
66,
275,
7070,
14,
362,
63,
1099,
8,
5700,
18,
9,
267,
291,
14,
629,
8,
82,
688,
66,
14,
362,
480,
1421,
1288,
298,
6185,
531,
267,
291,
14,
629,
8,
82,
688,
66,
14,
362,
480,
1700,
3471,
576,
12,
25538,
9,
339,
347,
511,
63,
1657,
63,
305,
63,
5328,
8,
277,
304,
267,
7070,
275,
664,
63,
15369,
63,
269,
63,
25755,
342,
398,
11559,
19,
275,
5377,
342,
267,
862,
26,
288,
746,
4067,
480,
1421,
531,
267,
871,
4067,
12,
1919,
26,
288,
986,
267,
7070,
14,
1657,
63,
305,
63,
5328,
8,
5700,
19,
12,
1919,
9,
267,
291,
14,
629,
8,
5842,
14,
362,
63,
1205,
8,
5700,
19,
395,
6363,
14,
13989,
9,
267,
291,
14,
6926,
8,
5842,
14,
362,
63,
1099,
8,
5700,
19,
395,
4067,
9,
421,
199,
533,
1379,
29605,
8447,
1944,
29605,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
15369,
63,
403,
63,
692,
63,
15369,
63,
1397,
63,
7657,
8,
277,
304,
267,
5071,
275,
984,
14,
3112,
14,
1935,
480,
23593,
14,
7765,
14,
15369,
531,
267,
862,
26,
288,
543,
3656,
63,
3112,
480,
15369,
2349,
355,
687,
22748,
14,
7765,
14,
15369,
492,
16967,
355,
291,
14,
7702,
8,
15369,
9,
267,
3753,
26,
288,
984,
14,
3112,
905,
23593,
14,
7765,
14,
15369,
937,
275,
5071,
339,
347,
511,
63,
1880,
63,
3536,
63,
692,
63,
15369,
63,
1397,
63,
7657,
8,
277,
304,
267,
687,
22748,
14,
7765,
492,
16967,
267,
5071,
275,
16967,
14,
29605,
8447,
14,
15369,
267,
16967,
14,
29605,
8447,
14,
15369,
275,
488,
267,
862,
26,
288,
543,
291,
14,
1855,
8,
8499,
10951,
304,
355,
16967,
14,
29605,
8447,
342,
267,
3753,
26,
288,
16967,
14,
29605,
8447,
14,
15369,
275,
5071,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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ementations of changeset classes.
"""
import sqlalchemy as sa
from sqlalchemy.databases import oracle as sa_base
from migrate import exceptions
from migrate.changeset import ansisql
OracleSchemaGenerator = sa_base.OracleDDLCompiler
class OracleColumnGenerator(OracleSchemaGenerator, ansisql.ANSIColumnGenerator):
pass
class OracleColumnDropper(ansisql.ANSIColumnDropper):
pass
class OracleSchemaChanger(OracleSchemaGenerator, ansisql.ANSISchemaChanger):
def get_column_specification(self, column, **kwargs):
# Ignore the NOT NULL generated
override_nullable = kwargs.pop('override_nullable', None)
if override_nullable:
orig = column.nullable
column.nullable = True
ret = super(OracleSchemaChanger, self).get_column_specification(
column, **kwargs)
if override_nullable:
column.nullable = orig
return ret
def visit_column(self, delta):
keys = delta.keys()
if 'name' in keys:
self._run_subvisit(delta,
self._visit_column_name,
start_alter=False)
if len(set(('type', 'nullable', 'server_default')).intersection(keys)):
self._run_subvisit(delta,
self._visit_column_change,
start_alter=False)
def _visit_column_change(self, table, column, delta):
# Oracle cannot drop a default once created, but it can set it
# to null. We'll do that if default=None
# http://forums.oracle.com/forums/message.jspa?messageID=1273234#1273234
dropdefault_hack = (column.server_default is None \
and 'server_default' in delta.keys())
# Oracle apparently doesn't like it when we say "not null" if
# the column's already not null. Fudge it, so we don't need a
# new function
notnull_hack = ((not column.nullable) \
and ('nullable' not in delta.keys()))
# We need to specify NULL if we're removing a NOT NULL
# constraint
null_hack = (column.nullable and ('nullable' in delta.keys()))
if dropdefault_hack:
column.server_default = sa.PassiveDefault(sa.sql.null())
if notnull_hack:
column.nullable = True
colspec = self.get_column_specification(column,
override_nullable=null_hack)
if null_hack:
colspec += ' NULL'
if notnull_hack:
column.nullable = False
if dropdefault_hack:
column.server_default = None
self.start_alter_table(table)
self.append("MODIFY (")
self.append(colspec)
self.append(")")
class OracleConstraintCommon(object):
def get_constraint_name(self, cons):
# Oracle constraints can't guess their name like other DBs
if not cons.name:
raise exceptions.NotSupportedError(
"Oracle constraint names must be explicitly stated")
return cons.name
class OracleConstraintGenerator(OracleConstraintCommon,
ansisql.ANSIConstraintGenerator):
pass
class OracleConstraintDropper(OracleConstraintCommon,
ansisql.ANSIConstraintDropper):
pass
class OracleDialect(ansisql.ANSIDialect):
columngenerator = OracleColumnGenerator
columndropper = OracleColumnDropper
schemachanger = OracleSchemaChanger
constraintgenerator = OracleConstraintGenerator
constraintdropper = OracleConstraintDropper
|
bsd-3-clause
|
[
624,
2043,
15309,
3050,
2488,
12591,
402,
23316,
3992,
14,
199,
624,
199,
646,
8335,
465,
2937,
199,
504,
8335,
14,
17439,
492,
28123,
465,
2937,
63,
1095,
199,
199,
504,
12810,
492,
4967,
199,
504,
12810,
14,
26027,
492,
376,
2316,
1710,
421,
199,
21202,
6700,
7599,
275,
2937,
63,
1095,
14,
21202,
31868,
9131,
421,
199,
533,
15309,
4547,
7599,
8,
21202,
6700,
7599,
12,
376,
2316,
1710,
14,
5622,
948,
393,
1307,
7599,
304,
272,
986,
421,
199,
533,
15309,
4547,
11070,
529,
8,
290,
2316,
1710,
14,
5622,
948,
393,
1307,
11070,
529,
304,
272,
986,
421,
199,
533,
15309,
6700,
1049,
12974,
8,
21202,
6700,
7599,
12,
376,
2316,
1710,
14,
5622,
1311,
2095,
1049,
12974,
304,
339,
347,
664,
63,
2301,
63,
22271,
8,
277,
12,
2763,
12,
1011,
958,
304,
267,
327,
14092,
314,
2845,
5962,
4046,
267,
4278,
63,
16375,
275,
2074,
14,
1935,
360,
4415,
63,
16375,
297,
488,
9,
267,
340,
4278,
63,
16375,
26,
288,
2306,
275,
2763,
14,
16375,
288,
2763,
14,
16375,
275,
715,
267,
2203,
275,
1613,
8,
21202,
6700,
1049,
12974,
12,
291,
680,
362,
63,
2301,
63,
22271,
8,
288,
2763,
12,
1011,
958,
9,
267,
340,
4278,
63,
16375,
26,
288,
2763,
14,
16375,
275,
2306,
267,
372,
2203,
339,
347,
5684,
63,
2301,
8,
277,
12,
5762,
304,
267,
2883,
275,
5762,
14,
1612,
342,
398,
340,
283,
354,
7,
315,
2883,
26,
288,
291,
423,
1065,
63,
954,
5427,
8,
3136,
12,
3044,
291,
423,
5427,
63,
2301,
63,
354,
12,
3044,
1343,
63,
11858,
29,
797,
9,
398,
340,
822,
8,
409,
4725,
466,
297,
283,
16375,
297,
283,
1000,
63,
885,
11103,
12569,
8,
1612,
2298,
288,
291,
423,
1065,
63,
954,
5427,
8,
3136,
12,
3044,
291,
423,
5427,
63,
2301,
63,
1461,
12,
3044,
1343,
63,
11858,
29,
797,
9,
339,
347,
485,
5427,
63,
2301,
63,
1461,
8,
277,
12,
1817,
12,
2763,
12,
5762,
304,
267,
327,
15309,
3913,
5978,
282,
849,
5403,
2737,
12,
1325,
652,
883,
663,
652,
267,
327,
370,
2973,
14,
221,
2136,
7171,
886,
626,
340,
849,
29,
403,
267,
327,
1455,
921,
10044,
83,
14,
16404,
14,
957,
15,
10044,
83,
15,
1188,
14,
3596,
387,
31,
1188,
998,
29,
4195,
708,
1082,
3,
4195,
708,
1082,
267,
5978,
885,
63,
20875,
275,
334,
2301,
14,
1000,
63,
885,
365,
488,
971,
1816,
436,
283,
1000,
63,
885,
7,
315,
5762,
14,
1612,
1012,
267,
327,
15309,
27241,
590,
3181,
1133,
2839,
652,
1380,
781,
14722,
298,
1397,
2973,
2,
340,
267,
327,
314,
2763,
1159,
2575,
440,
2973,
14,
481,
16603,
652,
12,
880,
781,
2793,
1133,
1929,
282,
267,
327,
892,
805,
267,
440,
2307,
63,
20875,
275,
3666,
1397,
2763,
14,
16375,
9,
971,
1169,
436,
661,
16375,
7,
440,
315,
5762,
14,
1612,
4059,
267,
327,
2136,
1929,
370,
4165,
5962,
340,
781,
3984,
12881,
282,
2845,
5962,
267,
327,
5828,
267,
2973,
63,
20875,
275,
334,
2301,
14,
16375,
436,
661,
16375,
7,
315,
5762,
14,
1612,
4059,
398,
340,
5978,
885,
63,
20875,
26,
288,
2763,
14,
1000,
63,
885,
275,
2937,
14,
48,
13202,
2698,
8,
2231,
14,
3009,
14,
2307,
1012,
267,
340,
440,
2307,
63,
20875,
26,
288,
2763,
14,
16375,
275,
715,
267,
1048,
1650,
275,
291,
14,
362,
63,
2301,
63,
22271,
8,
2301,
12,
288,
4278,
63,
16375,
29,
2307,
63,
20875,
9,
267,
340,
2973,
63,
20875,
26,
288,
1048,
1650,
847,
283,
5962,
7,
267,
340,
440,
2307,
63,
20875,
26,
288,
2763,
14,
16375,
275,
756,
267,
340,
5978,
885,
63,
20875,
26,
288,
2763,
14,
1000,
63,
885,
275,
488,
398,
291,
14,
928,
63,
11858,
63,
1224,
8,
1224,
9,
267,
291,
14,
740,
480,
31225,
334,
531,
267,
291,
14,
740,
8,
4574,
733,
9,
267,
291,
14,
740,
480,
6320,
421,
199,
533,
15309,
8463,
7844,
8,
785,
304,
339,
347,
664,
63,
5631,
63,
354,
8,
277,
12,
13447,
304,
267,
327,
15309,
9565,
883,
1133,
9519,
3932,
536,
2839,
1163,
6249,
83,
267,
340,
440,
13447,
14,
354,
26,
288,
746,
4967,
14,
26077,
547,
8,
355,
298,
21202,
5828,
1561,
1471,
506,
7662,
410,
972,
531,
267,
372,
13447,
14,
354,
421,
199,
533,
15309,
8463,
7599,
8,
21202,
8463,
7844,
12,
1816,
376,
2316,
1710,
14,
879,
2684,
8463,
7599,
304,
272,
986,
421,
199,
533,
15309,
8463,
11070,
529,
8,
21202,
8463,
7844,
12,
2892,
376,
2316,
1710,
14,
879,
2684,
8463,
11070,
529,
304,
272,
986,
421,
199,
533,
15309,
22080,
8,
290,
2316,
1710,
14,
5622,
998,
4674,
1264,
304,
272,
2763,
4679,
275,
15309,
4547,
7599,
272,
1048,
453,
977,
2675,
529,
275,
15309,
4547,
11070,
529,
272,
4177,
335,
12974,
275,
15309,
6700,
1049,
12974,
272,
5828,
4679,
275,
15309,
8463,
7599,
272,
5828,
4824,
529,
275,
15309,
8463,
11070,
529,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2043,
15309,
3050,
2488,
12591,
402,
23316,
3992,
14,
199,
624,
199,
646,
8335,
465,
2937,
199,
504,
8335,
14,
17439,
492,
28123,
465,
2937,
63,
1095,
199,
199,
504,
12810,
492,
4967,
199,
504,
12810,
14,
26027,
492,
376,
2316,
1710,
421,
199,
21202,
6700,
7599,
275,
2937,
63,
1095,
14,
21202,
31868,
9131,
421,
199,
533,
15309,
4547,
7599,
8,
21202,
6700,
7599,
12,
376,
2316,
1710,
14,
5622,
948,
393,
1307,
7599,
304,
272,
986,
421,
199,
533,
15309,
4547,
11070,
529,
8,
290,
2316,
1710,
14,
5622,
948,
393,
1307,
11070,
529,
304,
272,
986,
421,
199,
533,
15309,
6700,
1049,
12974,
8,
21202,
6700,
7599,
12,
376,
2316,
1710,
14,
5622,
1311,
2095,
1049,
12974,
304,
339,
347,
664,
63,
2301,
63,
22271,
8,
277,
12,
2763,
12,
1011,
958,
304,
267,
327,
14092,
314,
2845,
5962,
4046,
267,
4278,
63,
16375,
275,
2074,
14,
1935,
360,
4415,
63,
16375,
297,
488,
9,
267,
340,
4278,
63,
16375,
26,
288,
2306,
275,
2763,
14,
16375,
288,
2763,
14,
16375,
275,
715,
267,
2203,
275,
1613,
8,
21202,
6700,
1049,
12974,
12,
291,
680,
362,
63,
2301,
63,
22271,
8,
288,
2763,
12,
1011,
958,
9,
267,
340,
4278,
63,
16375,
26,
288,
2763,
14,
16375,
275,
2306,
267,
372,
2203,
339,
347,
5684,
63,
2301,
8,
277,
12,
5762,
304,
267,
2883,
275,
5762,
14,
1612,
342,
398,
340,
283,
354,
7,
315,
2883,
26,
288,
291,
423,
1065,
63,
954,
5427,
8,
3136,
12,
3044,
291,
423,
5427,
63,
2301,
63,
354,
12,
3044,
1343,
63,
11858,
29,
797,
9,
398,
340,
822,
8,
409,
4725,
466,
297,
283,
16375,
297,
283,
1000,
63,
885,
11103,
12569,
8,
1612,
2298,
288,
291,
423,
1065,
63,
954,
5427,
8,
3136,
12,
3044,
291,
423,
5427,
63,
2301,
63,
1461,
12,
3044,
1343,
63,
11858,
29,
797,
9,
339,
347,
485,
5427,
63,
2301,
63,
1461,
8,
277,
12,
1817,
12,
2763,
12,
5762,
304,
267,
327,
15309,
3913,
5978,
282,
849,
5403,
2737,
12,
1325,
652,
883,
663,
652,
267,
327,
370,
2973,
14,
221,
2136,
7171,
886,
626,
340,
849,
29,
403,
267,
327,
1455,
921,
10044,
83,
14,
16404,
14,
957,
15,
10044,
83,
15,
1188,
14,
3596,
387,
31,
1188,
998,
29,
4195,
708,
1082,
3,
4195,
708,
1082,
267,
5978,
885,
63,
20875,
275,
334,
2301,
14,
1000,
63,
885,
365,
488,
971,
1816,
436,
283,
1000,
63,
885,
7,
315,
5762,
14,
1612,
1012,
267,
327,
15309,
27241,
590,
3181,
1133,
2839,
652,
1380,
781,
14722,
298,
1397,
2973,
2,
340,
267,
327,
314,
2763,
1159,
2575,
440,
2973,
14,
481,
16603,
652,
12,
880,
781,
2793,
1133,
1929,
282,
267,
327,
892,
805,
267,
440,
2307,
63,
20875,
275,
3666,
1397,
2763,
14,
16375,
9,
971,
1169,
436,
661,
16375,
7,
440,
315,
5762,
14,
1612,
4059,
267,
327,
2136,
1929,
370,
4165,
5962,
340,
781,
3984,
12881,
282,
2845,
5962,
267,
327,
5828,
267,
2973,
63,
20875,
275,
334,
2301,
14,
16375,
436,
661,
16375,
7,
315,
5762,
14,
1612,
4059,
398,
340,
5978,
885,
63,
20875,
26,
288,
2763,
14,
1000,
63,
885,
275,
2937,
14,
48,
13202,
2698,
8,
2231,
14,
3009,
14,
2307,
1012,
267,
340,
440,
2307,
63,
20875,
26,
288,
2763,
14,
16375,
275,
715,
267,
1048,
1650,
275,
291,
14,
362,
63,
2301,
63,
22271,
8,
2301,
12,
288,
4278,
63,
16375,
29,
2307,
63,
20875,
9,
267,
340,
2973,
63,
20875,
26,
288,
1048,
1650,
847,
283,
5962,
7,
267,
340,
440,
2307,
63,
20875,
26,
288,
2763,
14,
16375,
275,
756,
267,
340,
5978,
885,
63,
20875,
26,
288,
2763,
14,
1000,
63,
885,
275,
488,
398,
291,
14,
928,
63,
11858,
63,
1224,
8,
1224,
9,
267,
291,
14,
740,
480,
31225,
334,
531,
267,
291,
14,
740,
8,
4574,
733,
9,
267,
291,
14,
740,
480,
6320,
421,
199,
533,
15309,
8463,
7844,
8,
785,
304,
339,
347,
664,
63,
5631,
63,
354,
8,
277,
12,
13447,
304,
267,
327,
15309,
9565,
883,
1133,
9519,
3932,
536,
2839,
1163,
6249,
83,
267,
340,
440,
13447,
14,
354,
26,
288,
746,
4967,
14,
26077,
547,
8,
355,
298,
21202,
5828,
1561,
1471,
506,
7662,
410,
972,
531,
267,
372,
13447,
14,
354,
421,
199,
533,
15309,
8463,
7599,
8,
21202,
8463,
7844,
12,
1816,
376,
2316,
1710,
14,
879,
2684,
8463,
7599,
304,
272,
986,
421,
199,
533,
15309,
8463,
11070,
529,
8,
21202,
8463,
7844,
12,
2892,
376,
2316,
1710,
14,
879,
2684,
8463,
11070,
529,
304,
272,
986,
421,
199,
533,
15309,
22080,
8,
290,
2316,
1710,
14,
5622,
998,
4674,
1264,
304,
272,
2763,
4679,
275,
15309,
4547,
7599,
272,
1048,
453,
977,
2675,
529,
275,
15309,
4547,
11070,
529,
272,
4177,
335,
12974,
275,
15309,
6700,
1049,
12974,
272,
5828,
4679,
275,
15309,
8463,
7599,
272,
5828,
4824,
529,
275,
15309,
8463,
11070,
529,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
0xdyu/RouteFlow-Exodus
|
pox/pox/lib/packet/arp.py
|
27
|
6250
|
# Copyright 2011 James McCauley
# Copyright 2008 (C) Nicira, Inc.
#
# This file is part of POX.
#
# POX 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.
#
# POX 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 POX. If not, see <http://www.gnu.org/licenses/>.
# This file is derived from the packet library in NOX, which was
# developed by Nicira, Inc.
#=====================================================================
#
# 0 1 2 3
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Hardware type | Protocol type |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Source hardware address ::: |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Source protocol address ::: |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Destination hardware address ::: |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Destination protocol address ::: |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Data ::: |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
#=====================================================================
import struct
from packet_base import packet_base
from ipv4 import ipv4
from ethernet import ethernet
from ethernet import ETHER_ANY
from ethernet import ETHER_BROADCAST
from ipv4 import IP_ANY
from ipv4 import IP_BROADCAST
from pox.lib.addresses import IPAddr, EthAddr
from packet_utils import *
class arp (packet_base):
"ARP/RARP packet struct"
MIN_LEN = 28
HW_TYPE_ETHERNET = 1
PROTO_TYPE_IP = 0x0800
# OPCODES
REQUEST = 1 # ARP
REPLY = 2 # ARP
REV_REQUEST = 3 # RARP
REV_REPLY = 4 # RARP
def __init__(self, raw=None, prev=None, **kw):
packet_base.__init__(self)
self.prev = prev
self.hwtype = arp.HW_TYPE_ETHERNET
self.prototype = arp.PROTO_TYPE_IP
self.hwsrc = ETHER_ANY
self.hwdst = ETHER_ANY
self.hwlen = 6
self.opcode = 0
self.protolen = 4
self.protosrc = IP_ANY
self.protodst = IP_ANY
self.next = b''
if raw is not None:
self.parse(raw)
self._init(kw)
def parse (self, raw):
assert isinstance(raw, bytes)
self.raw = raw
dlen = len(raw)
if dlen < arp.MIN_LEN:
self.msg('(arp parse) warning IP packet data too short to parse header: data len %u' % dlen)
return
(self.hwtype, self.prototype, self.hwlen, self.protolen,self.opcode) =\
struct.unpack('!HHBBH', raw[:8])
if self.hwtype != arp.HW_TYPE_ETHERNET:
self.msg('(arp parse) hw type unknown %u' % self.hwtype)
if self.hwlen != 6:
self.msg('(arp parse) unknown hw len %u' % self.hwlen)
else:
self.hwsrc = EthAddr(raw[8:14])
self.hwdst = EthAddr(raw[18:24])
if self.prototype != arp.PROTO_TYPE_IP:
self.msg('(arp parse) proto type unknown %u' % self.prototype)
if self.protolen != 4:
self.msg('(arp parse) unknown proto len %u' % self.protolen)
else:
self.protosrc = IPAddr(struct.unpack('!I',raw[14:18])[0])
self.protodst = IPAddr(struct.unpack('!I',raw[24:28])[0])
self.next = raw[28:]
self.parsed = True
def hdr(self, payload):
buf = struct.pack('!HHBBH', self.hwtype, self.prototype,
self.hwlen, self.protolen,self.opcode)
if type(self.hwsrc) == bytes:
buf += self.hwsrc
else:
buf += self.hwsrc.toRaw()
if type(self.protosrc) is IPAddr:
buf += struct.pack('!I',self.protosrc.toUnsigned())
else:
buf += struct.pack('!I',self.protosrc)
if type(self.hwdst) == bytes:
buf += self.hwdst
else:
buf += self.hwdst.toRaw()
if type(self.protodst) is IPAddr:
buf += struct.pack('!I',self.protodst.toUnsigned())
else:
buf += struct.pack('!I',self.protodst)
return buf
def _to_str(self):
op = str(self.opcode)
eth_type = None
# Ethernet
if hasattr(self.prev, 'type'):
eth_type = self.prev.type
# Vlan
elif hasattr(self.prev, 'eth_type'):
eth_type = self.prev.eth_type
else:
self.err('(arp) unknown datalink type')
eth_type = ethernet.ARP_TYPE
if eth_type == ethernet.ARP_TYPE:
if self.opcode == arp.REQUEST:
op = "REQUEST"
elif self.opcode == arp.REPLY:
op = "REPLY"
elif eth_type == ethernet.RARP_TYPE:
if self.opcode == arp.REV_REQUEST:
op = "REV_REQUEST"
elif self.opcode == arp.REV_REPLY:
op = "REV_REPLY"
s = "[ARP {0} hw:{1} p:{2} {3}>{4} {5}>{6}]".format(op,
self.hwtype,
self.prototype,
EthAddr(self.hwsrc),
EthAddr(self.hwdst),
IPAddr(self.protosrc),
IPAddr(self.protodst))
return s
|
apache-2.0
|
[
3,
1898,
7760,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
1898,
9079,
334,
35,
9,
653,
530,
20936,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
3625,
56,
14,
199,
3,
199,
3,
3625,
56,
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,
3625,
56,
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,
3625,
56,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
961,
570,
365,
7131,
687,
314,
3644,
3555,
315,
4825,
56,
12,
1314,
1990,
199,
3,
477,
27813,
701,
653,
530,
20936,
12,
3277,
14,
199,
199,
14813,
19989,
199,
3,
199,
3,
259,
378,
7861,
413,
7861,
499,
7861,
650,
199,
3,
259,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
3515,
22825,
1068,
730,
263,
1204,
3777,
11557,
730,
258,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
8295,
5800,
14991,
2287,
3800,
26,
8295,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
8295,
5800,
4113,
2287,
3800,
26,
8295,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
5185,
28505,
14991,
2287,
3800,
26,
4483,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
5185,
28505,
4113,
2287,
3800,
26,
4483,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
13235,
3918,
3800,
26,
14960,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
199,
14813,
19989,
199,
646,
2702,
199,
199,
504,
3644,
63,
1095,
492,
3644,
63,
1095,
199,
504,
3278,
20,
492,
3278,
20,
199,
199,
504,
21944,
492,
21944,
199,
504,
21944,
492,
662,
2080,
540,
63,
8974,
199,
504,
21944,
492,
662,
2080,
540,
63,
21111,
32215,
199,
199,
504,
3278,
20,
492,
3531,
63,
8974,
199,
504,
3278,
20,
492,
3531,
63,
21111,
32215,
199,
199,
504,
1115,
88,
14,
773,
14,
7423,
492,
3531,
11404,
12,
662,
273,
11404,
199,
199,
504,
3644,
63,
1208,
755,
492,
627,
199,
199,
533,
26262,
334,
6253,
63,
1095,
304,
272,
298,
23610,
15,
50,
23610,
3644,
2702,
2,
339,
15861,
63,
5304,
275,
7294,
339,
869,
55,
63,
2711,
63,
6919,
7278,
275,
413,
272,
3611,
2566,
63,
2711,
63,
1772,
259,
275,
378,
88,
25822,
339,
327,
9827,
15639,
272,
31325,
258,
275,
413,
327,
4160,
48,
272,
5363,
31370,
755,
275,
499,
327,
4160,
48,
272,
5363,
54,
63,
6780,
275,
650,
327,
820,
23610,
272,
5363,
54,
63,
21130,
257,
275,
841,
327,
820,
23610,
339,
347,
636,
826,
721,
277,
12,
3066,
29,
403,
12,
5071,
29,
403,
12,
1011,
829,
304,
267,
3644,
63,
1095,
855,
826,
721,
277,
9,
398,
291,
14,
5701,
275,
5071,
398,
291,
14,
8090,
466,
258,
275,
26262,
14,
15487,
63,
2711,
63,
6919,
7278,
267,
291,
14,
16141,
221,
275,
26262,
14,
7459,
63,
2711,
63,
1772,
267,
291,
14,
8090,
2164,
420,
275,
662,
2080,
540,
63,
8974,
267,
291,
14,
72,
2989,
270,
420,
275,
662,
2080,
540,
63,
8974,
267,
291,
14,
8090,
552,
420,
275,
1227,
267,
291,
14,
14325,
258,
275,
378,
267,
291,
14,
2625,
552,
257,
275,
841,
267,
291,
14,
2625,
2164,
257,
275,
3531,
63,
8974,
4960,
291,
14,
2745,
364,
270,
257,
275,
3531,
63,
8974,
267,
291,
14,
2184,
755,
275,
330,
891,
398,
340,
3066,
365,
440,
488,
26,
288,
291,
14,
1122,
8,
1773,
9,
398,
291,
423,
826,
8,
829,
9,
339,
347,
2198,
334,
277,
12,
3066,
304,
267,
702,
1228,
8,
1773,
12,
2783,
9,
267,
291,
14,
1773,
275,
3066,
267,
366,
552,
275,
822,
8,
1773,
9,
267,
340,
366,
552,
665,
26262,
14,
4896,
63,
5304,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5721,
3531,
3644,
666,
4634,
3974,
370,
2198,
1406,
26,
666,
822,
450,
85,
7,
450,
366,
552,
9,
288,
372,
398,
334,
277,
14,
8090,
466,
12,
291,
14,
16141,
12,
291,
14,
8090,
552,
12,
291,
14,
2625,
552,
12,
277,
14,
14325,
9,
26447,
267,
2702,
14,
5301,
16157,
10213,
5342,
40,
297,
3066,
1491,
24,
566,
398,
340,
291,
14,
8090,
466,
1137,
26262,
14,
15487,
63,
2711,
63,
6919,
7278,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
12073,
730,
5809,
450,
85,
7,
450,
291,
14,
8090,
466,
9,
267,
340,
291,
14,
8090,
552,
1137,
1227,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5809,
12073,
822,
450,
85,
7,
450,
291,
14,
8090,
552,
9,
267,
587,
26,
288,
291,
14,
8090,
2164,
275,
662,
273,
11404,
8,
1773,
59,
24,
26,
1079,
566,
288,
291,
14,
72,
2989,
270,
275,
662,
273,
11404,
8,
1773,
59,
1085,
26,
1194,
566,
267,
340,
291,
14,
16141,
1137,
26262,
14,
7459,
63,
2711,
63,
1772,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
4104,
730,
5809,
450,
85,
7,
450,
291,
14,
16141,
9,
267,
340,
291,
14,
2625,
552,
1137,
841,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5809,
4104,
822,
450,
85,
7,
450,
291,
14,
2625,
552,
9,
267,
587,
26,
288,
291,
14,
2625,
2164,
275,
3531,
11404,
8,
1820,
14,
5301,
16157,
41,
297,
1773
] |
[
1898,
7760,
1603,
14015,
22895,
3630,
443,
89,
199,
3,
1898,
9079,
334,
35,
9,
653,
530,
20936,
12,
3277,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
3625,
56,
14,
199,
3,
199,
3,
3625,
56,
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,
3625,
56,
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,
3625,
56,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
961,
570,
365,
7131,
687,
314,
3644,
3555,
315,
4825,
56,
12,
1314,
1990,
199,
3,
477,
27813,
701,
653,
530,
20936,
12,
3277,
14,
199,
199,
14813,
19989,
199,
3,
199,
3,
259,
378,
7861,
413,
7861,
499,
7861,
650,
199,
3,
259,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
499,
650,
841,
959,
1227,
1520,
1695,
1749,
378,
413,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
3515,
22825,
1068,
730,
263,
1204,
3777,
11557,
730,
258,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
8295,
5800,
14991,
2287,
3800,
26,
8295,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
8295,
5800,
4113,
2287,
3800,
26,
8295,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
5185,
28505,
14991,
2287,
3800,
26,
4483,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
5185,
28505,
4113,
2287,
3800,
26,
4483,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
257,
1204,
13235,
3918,
3800,
26,
14960,
1204,
199,
3,
257,
435,
23495,
23495,
23495,
23495,
199,
3,
199,
14813,
19989,
199,
646,
2702,
199,
199,
504,
3644,
63,
1095,
492,
3644,
63,
1095,
199,
504,
3278,
20,
492,
3278,
20,
199,
199,
504,
21944,
492,
21944,
199,
504,
21944,
492,
662,
2080,
540,
63,
8974,
199,
504,
21944,
492,
662,
2080,
540,
63,
21111,
32215,
199,
199,
504,
3278,
20,
492,
3531,
63,
8974,
199,
504,
3278,
20,
492,
3531,
63,
21111,
32215,
199,
199,
504,
1115,
88,
14,
773,
14,
7423,
492,
3531,
11404,
12,
662,
273,
11404,
199,
199,
504,
3644,
63,
1208,
755,
492,
627,
199,
199,
533,
26262,
334,
6253,
63,
1095,
304,
272,
298,
23610,
15,
50,
23610,
3644,
2702,
2,
339,
15861,
63,
5304,
275,
7294,
339,
869,
55,
63,
2711,
63,
6919,
7278,
275,
413,
272,
3611,
2566,
63,
2711,
63,
1772,
259,
275,
378,
88,
25822,
339,
327,
9827,
15639,
272,
31325,
258,
275,
413,
327,
4160,
48,
272,
5363,
31370,
755,
275,
499,
327,
4160,
48,
272,
5363,
54,
63,
6780,
275,
650,
327,
820,
23610,
272,
5363,
54,
63,
21130,
257,
275,
841,
327,
820,
23610,
339,
347,
636,
826,
721,
277,
12,
3066,
29,
403,
12,
5071,
29,
403,
12,
1011,
829,
304,
267,
3644,
63,
1095,
855,
826,
721,
277,
9,
398,
291,
14,
5701,
275,
5071,
398,
291,
14,
8090,
466,
258,
275,
26262,
14,
15487,
63,
2711,
63,
6919,
7278,
267,
291,
14,
16141,
221,
275,
26262,
14,
7459,
63,
2711,
63,
1772,
267,
291,
14,
8090,
2164,
420,
275,
662,
2080,
540,
63,
8974,
267,
291,
14,
72,
2989,
270,
420,
275,
662,
2080,
540,
63,
8974,
267,
291,
14,
8090,
552,
420,
275,
1227,
267,
291,
14,
14325,
258,
275,
378,
267,
291,
14,
2625,
552,
257,
275,
841,
267,
291,
14,
2625,
2164,
257,
275,
3531,
63,
8974,
4960,
291,
14,
2745,
364,
270,
257,
275,
3531,
63,
8974,
267,
291,
14,
2184,
755,
275,
330,
891,
398,
340,
3066,
365,
440,
488,
26,
288,
291,
14,
1122,
8,
1773,
9,
398,
291,
423,
826,
8,
829,
9,
339,
347,
2198,
334,
277,
12,
3066,
304,
267,
702,
1228,
8,
1773,
12,
2783,
9,
267,
291,
14,
1773,
275,
3066,
267,
366,
552,
275,
822,
8,
1773,
9,
267,
340,
366,
552,
665,
26262,
14,
4896,
63,
5304,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5721,
3531,
3644,
666,
4634,
3974,
370,
2198,
1406,
26,
666,
822,
450,
85,
7,
450,
366,
552,
9,
288,
372,
398,
334,
277,
14,
8090,
466,
12,
291,
14,
16141,
12,
291,
14,
8090,
552,
12,
291,
14,
2625,
552,
12,
277,
14,
14325,
9,
26447,
267,
2702,
14,
5301,
16157,
10213,
5342,
40,
297,
3066,
1491,
24,
566,
398,
340,
291,
14,
8090,
466,
1137,
26262,
14,
15487,
63,
2711,
63,
6919,
7278,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
12073,
730,
5809,
450,
85,
7,
450,
291,
14,
8090,
466,
9,
267,
340,
291,
14,
8090,
552,
1137,
1227,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5809,
12073,
822,
450,
85,
7,
450,
291,
14,
8090,
552,
9,
267,
587,
26,
288,
291,
14,
8090,
2164,
275,
662,
273,
11404,
8,
1773,
59,
24,
26,
1079,
566,
288,
291,
14,
72,
2989,
270,
275,
662,
273,
11404,
8,
1773,
59,
1085,
26,
1194,
566,
267,
340,
291,
14,
16141,
1137,
26262,
14,
7459,
63,
2711,
63,
1772,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
4104,
730,
5809,
450,
85,
7,
450,
291,
14,
16141,
9,
267,
340,
291,
14,
2625,
552,
1137,
841,
26,
288,
291,
14,
1328,
14097,
12868,
2198,
9,
5809,
4104,
822,
450,
85,
7,
450,
291,
14,
2625,
552,
9,
267,
587,
26,
288,
291,
14,
2625,
2164,
275,
3531,
11404,
8,
1820,
14,
5301,
16157,
41,
297,
1773,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bheesham/hyde
|
tests/test_initialize.py
|
6
|
3678
|
# -*- coding: utf-8 -*-
"""
Use nose
`$ pip install nose`
`$ nosetests`
"""
from hyde.engine import Engine
from hyde.exceptions import HydeException
from hyde.layout import Layout
from fswrap import File, Folder
from nose.tools import raises, with_setup, nottest
TEST_SITE = File(__file__).parent.child_folder('_test')
TEST_SITE_AT_USER = Folder('~/_test')
@nottest
def create_test_site():
TEST_SITE.make()
@nottest
def delete_test_site():
TEST_SITE.delete()
@nottest
def create_test_site_at_user():
TEST_SITE_AT_USER.make()
@nottest
def delete_test_site_at_user():
TEST_SITE_AT_USER.delete()
@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_site_yaml_exists():
e = Engine(raise_exceptions=True)
File(TEST_SITE.child('site.yaml')).write("Hey")
e.run(e.parse(['-s', unicode(TEST_SITE), 'create']))
@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_content_folder_exists():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('content').make()
e.run(e.parse(['-s', unicode(TEST_SITE), 'create']))
@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_layout_folder_exists():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('layout').make()
e.run(e.parse(['-s', unicode(TEST_SITE), 'create']))
@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_empty_site_exists():
e = Engine(raise_exceptions=True)
e.run(e.parse(['-s', unicode(TEST_SITE), 'create']))
verify_site_contents(TEST_SITE, Layout.find_layout())
@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_forced():
e = Engine(raise_exceptions=True)
TEST_SITE.child_folder('layout').make()
e.run(e.parse(['-s', unicode(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())
TEST_SITE.delete()
TEST_SITE.child_folder('content').make()
e.run(e.parse(['-s', unicode(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())
TEST_SITE.delete()
TEST_SITE.make()
File(TEST_SITE.child('site.yaml')).write("Hey")
e.run(e.parse(['-s', unicode(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())
@with_setup(create_test_site, delete_test_site)
def test_ensure_no_exception_when_sitepath_does_not_exist():
e = Engine(raise_exceptions=True)
TEST_SITE.delete()
e.run(e.parse(['-s', unicode(TEST_SITE), 'create', '-f']))
verify_site_contents(TEST_SITE, Layout.find_layout())
@with_setup(create_test_site_at_user, delete_test_site_at_user)
def test_ensure_can_create_site_at_user():
e = Engine(raise_exceptions=True)
TEST_SITE_AT_USER.delete()
e.run(e.parse(['-s', unicode(TEST_SITE_AT_USER), 'create', '-f']))
verify_site_contents(TEST_SITE_AT_USER, Layout.find_layout())
@nottest
def verify_site_contents(site, layout):
assert site.exists
assert site.child_folder('layout').exists
assert File(site.child('info.yaml')).exists
expected = map(
lambda f: f.get_relative_path(layout), layout.walker.walk_all())
actual = map(lambda f: f.get_relative_path(site), site.walker.walk_all())
assert actual
assert expected
expected.sort()
actual.sort()
assert actual == expected
@raises(HydeException)
@with_setup(create_test_site, delete_test_site)
def test_ensure_exception_when_layout_is_invalid():
e = Engine(raise_exceptions=True)
e.run(e.parse(['-s', unicode(TEST_SITE), 'create', '-l', 'junk']))
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
6119,
11354,
199,
64,
4,
7305,
3907,
11354,
64,
199,
64,
4,
11354,
2219,
64,
199,
624,
421,
199,
504,
7188,
271,
14,
3908,
492,
12580,
199,
504,
7188,
271,
14,
3924,
492,
29591,
271,
1726,
199,
504,
7188,
271,
14,
4209,
492,
25604,
199,
199,
504,
289,
3519,
1330,
492,
3814,
12,
29121,
199,
504,
11354,
14,
2537,
492,
6534,
12,
543,
63,
2758,
12,
440,
396,
199,
199,
2864,
63,
7917,
275,
3814,
3460,
493,
28634,
1708,
14,
1739,
63,
3741,
6412,
396,
358,
199,
2864,
63,
7917,
63,
619,
63,
3791,
275,
29121,
21114,
15607,
396,
358,
421,
199,
32,
1397,
396,
199,
318,
1218,
63,
396,
63,
2124,
837,
272,
7393,
63,
7917,
14,
1875,
342,
421,
199,
32,
1397,
396,
199,
318,
3145,
63,
396,
63,
2124,
837,
272,
7393,
63,
7917,
14,
1807,
342,
421,
199,
32,
1397,
396,
199,
318,
1218,
63,
396,
63,
2124,
63,
292,
63,
751,
837,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1875,
342,
421,
199,
32,
1397,
396,
199,
318,
3145,
63,
396,
63,
2124,
63,
292,
63,
751,
837,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1807,
342,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
2124,
63,
5963,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
3814,
8,
2864,
63,
7917,
14,
1739,
360,
2124,
14,
5963,
11103,
952,
480,
1966,
89,
531,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
1317,
63,
3741,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
1317,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
4209,
63,
3741,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
4209,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
1667,
63,
2124,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
28074,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
4209,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
272,
7393,
63,
7917,
14,
1807,
342,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
1317,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
272,
7393,
63,
7917,
14,
1807,
342,
272,
7393,
63,
7917,
14,
1875,
342,
272,
3814,
8,
2864,
63,
7917,
14,
1739,
360,
2124,
14,
5963,
11103,
952,
480,
1966,
89,
531,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
2124,
515,
63,
9105,
63,
1397,
63,
4494,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1807,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
63,
292,
63,
751,
12,
3145,
63,
396,
63,
2124,
63,
292,
63,
751,
9,
199,
318,
511,
63,
7505,
63,
2425,
63,
981,
63,
2124,
63,
292,
63,
751,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1807,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
63,
619,
63,
3791,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
63,
619,
63,
3791,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1397,
396,
199,
318,
4911,
63,
2124,
63,
4407,
8,
2124,
12,
7054,
304,
272,
702,
4770,
14,
2444,
272,
702,
4770,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
6119,
11354,
199,
64,
4,
7305,
3907,
11354,
64,
199,
64,
4,
11354,
2219,
64,
199,
624,
421,
199,
504,
7188,
271,
14,
3908,
492,
12580,
199,
504,
7188,
271,
14,
3924,
492,
29591,
271,
1726,
199,
504,
7188,
271,
14,
4209,
492,
25604,
199,
199,
504,
289,
3519,
1330,
492,
3814,
12,
29121,
199,
504,
11354,
14,
2537,
492,
6534,
12,
543,
63,
2758,
12,
440,
396,
199,
199,
2864,
63,
7917,
275,
3814,
3460,
493,
28634,
1708,
14,
1739,
63,
3741,
6412,
396,
358,
199,
2864,
63,
7917,
63,
619,
63,
3791,
275,
29121,
21114,
15607,
396,
358,
421,
199,
32,
1397,
396,
199,
318,
1218,
63,
396,
63,
2124,
837,
272,
7393,
63,
7917,
14,
1875,
342,
421,
199,
32,
1397,
396,
199,
318,
3145,
63,
396,
63,
2124,
837,
272,
7393,
63,
7917,
14,
1807,
342,
421,
199,
32,
1397,
396,
199,
318,
1218,
63,
396,
63,
2124,
63,
292,
63,
751,
837,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1875,
342,
421,
199,
32,
1397,
396,
199,
318,
3145,
63,
396,
63,
2124,
63,
292,
63,
751,
837,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1807,
342,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
2124,
63,
5963,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
3814,
8,
2864,
63,
7917,
14,
1739,
360,
2124,
14,
5963,
11103,
952,
480,
1966,
89,
531,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
1317,
63,
3741,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
1317,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
3536,
8,
21568,
271,
1726,
9,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
1971,
63,
6526,
63,
4209,
63,
3741,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
4209,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
1667,
63,
2124,
63,
2444,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
28074,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
4209,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
272,
7393,
63,
7917,
14,
1807,
342,
272,
7393,
63,
7917,
14,
1739,
63,
3741,
360,
1317,
1959,
1875,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
272,
7393,
63,
7917,
14,
1807,
342,
272,
7393,
63,
7917,
14,
1875,
342,
272,
3814,
8,
2864,
63,
7917,
14,
1739,
360,
2124,
14,
5963,
11103,
952,
480,
1966,
89,
531,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
12,
3145,
63,
396,
63,
2124,
9,
199,
318,
511,
63,
7505,
63,
889,
63,
1971,
63,
6526,
63,
2124,
515,
63,
9105,
63,
1397,
63,
4494,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
14,
1807,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1045,
63,
2758,
8,
981,
63,
396,
63,
2124,
63,
292,
63,
751,
12,
3145,
63,
396,
63,
2124,
63,
292,
63,
751,
9,
199,
318,
511,
63,
7505,
63,
2425,
63,
981,
63,
2124,
63,
292,
63,
751,
837,
272,
325,
275,
12580,
8,
3730,
63,
3924,
29,
549,
9,
272,
7393,
63,
7917,
63,
619,
63,
3791,
14,
1807,
342,
272,
325,
14,
1065,
8,
69,
14,
1122,
24829,
83,
297,
2649,
8,
2864,
63,
7917,
63,
619,
63,
3791,
395,
283,
981,
297,
2475,
70,
5156,
272,
4911,
63,
2124,
63,
4407,
8,
2864,
63,
7917,
63,
619,
63,
3791,
12,
25604,
14,
1623,
63,
4209,
1012,
421,
199,
32,
1397,
396,
199,
318,
4911,
63,
2124,
63,
4407,
8,
2124,
12,
7054,
304,
272,
702,
4770,
14,
2444,
272,
702,
4770,
14,
0
] |
[
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|
gonzaparra/webankyrins
|
src/LFP/StructuralAnks/MainBundle/Resources/public/jmol/doc/source/xml2po-modes/gs.py
|
2
|
2904
|
# Copyright (c) 2004 Danilo Segan <danilo@kvota.net>.
#
# This file is part of xml2po.
#
# xml2po 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.
#
# xml2po 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 xml2po; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Special case Gnome Summary
#
class gsXmlMode:
"""Abstract class for special handling of document types."""
def getIgnoredTags(self):
"Returns array of tags to be ignored."
return [ 'link', 'bug-stats', 'cvs-stats', 'unixname' ]
def getFinalTags(self):
"Returns array of tags to be considered 'final'."
return ['title', 'para', 'name', 'desc' ]
def getSpacePreserveTags(self):
"Returns array of tags in which spaces are to be preserved."
return []
def preProcessXml(self, doc, msg):
"Preprocess a document and perhaps adds some messages."
pass
def _find_salute(self, node):
if node.name == 'salute':
return node
child = node.children
while child:
ret = self._find_salute(child)
if ret:
return ret
child = child.next
return None
def postProcessXmlTranslation(self, doc, language, translators):
"""Sets a language and translators in "doc" tree.
"translators" is a string consisted of translator credits.
"language" is a simple string.
"doc" is a libxml2.xmlDoc instance."""
# Find "salute" tag and add a comment about translator.
if translators == self.getStringForTranslators():
return
else:
salute = self._find_salute(doc.getRootElement())
if salute and salute.name=='salute':
# found
salute.newChild(None, "para", translators)
else:
return
def getStringForTranslators(self):
"""Returns None or a string to be added to PO files.
Common example is 'translator-credits'."""
return "translator-credits"
def getCommentForTranslators(self):
"""Returns a comment to be added next to string for crediting translators.
It should explain the format of the string provided by getStringForTranslators()."""
return """Translators: enter a short paragraph creditting yourself and others who helped you with the translation."""
|
mit
|
[
3,
1898,
334,
67,
9,
8353,
24747,
11737,
3240,
24975,
665,
24863,
11737,
32,
11475,
12041,
14,
846,
10827,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2748,
18,
555,
14,
199,
3,
199,
3,
2748,
18,
555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2748,
18,
555,
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,
2748,
18,
555,
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,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
199,
3,
12568,
1930,
598,
29897,
22486,
199,
3,
199,
199,
533,
8763,
8672,
1385,
26,
272,
408,
8458,
1021,
367,
4539,
7252,
402,
2213,
2943,
1041,
272,
347,
664,
19399,
2908,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
370,
506,
5525,
2122,
267,
372,
359,
283,
1073,
297,
283,
1266,
13,
3200,
297,
283,
28151,
13,
3200,
297,
283,
11864,
354,
7,
1622,
339,
347,
664,
12776,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
370,
506,
8652,
283,
5094,
16669,
267,
372,
788,
1213,
297,
283,
12227,
297,
283,
354,
297,
283,
3257,
7,
1622,
339,
347,
664,
7643,
2398,
4909,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
315,
1314,
7883,
787,
370,
506,
17731,
2122,
267,
372,
942,
339,
347,
876,
3498,
8672,
8,
277,
12,
1382,
12,
1499,
304,
267,
298,
26539,
282,
2213,
436,
25358,
9584,
2005,
3788,
2122,
267,
986,
339,
347,
485,
1623,
63,
6327,
938,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
354,
508,
283,
6327,
938,
356,
288,
372,
1031,
267,
1982,
275,
1031,
14,
3223,
267,
1830,
1982,
26,
288,
2203,
275,
291,
423,
1623,
63,
6327,
938,
8,
1739,
9,
288,
340,
2203,
26,
355,
372,
2203,
288,
1982,
275,
1982,
14,
2184,
267,
372,
488,
339,
347,
2963,
3498,
8672,
18483,
8,
277,
12,
1382,
12,
2637,
12,
1752,
20830,
304,
267,
408,
9899,
282,
2637,
436,
1752,
20830,
315,
298,
1301,
2,
3123,
14,
2728,
298,
1515,
20830,
2,
365,
282,
1059,
406,
24925,
402,
32034,
2837,
15256,
14,
267,
298,
3671,
2,
365,
282,
3486,
1059,
14,
267,
298,
1301,
2,
365,
282,
15404,
18,
14,
1652,
3768,
1256,
1041,
267,
327,
6668,
298,
6327,
938,
2,
1947,
436,
1050,
282,
3721,
3595,
32034,
14,
267,
340,
1752,
20830,
508,
291,
14,
362,
1558,
1858,
3188,
20830,
837,
288,
372,
267,
587,
26,
288,
18641,
938,
275,
291,
423,
1623,
63,
6327,
938,
8,
1301,
14,
362,
6405,
2162,
1012,
288,
340,
18641,
938,
436,
18641,
938,
14,
354,
6803,
6327,
938,
356,
355,
327,
1911,
355,
18641,
938,
14,
1222,
3493,
8,
403,
12,
298,
12227,
401,
1752,
20830,
9,
288,
587,
26,
355,
372,
339,
347,
664,
1558,
1858,
3188,
20830,
8,
277,
304,
267,
408,
3407,
488,
503,
282,
1059,
370,
506,
3483,
370,
3625,
1584,
14,
398,
13964,
2893,
365,
283,
29346,
13,
22461,
23690,
267,
372,
298,
29346,
13,
22461,
2,
339,
347,
664,
7488,
1858,
3188,
20830,
8,
277,
304,
267,
408,
3407,
282,
3721,
370,
506,
3483,
2163,
370,
1059,
367,
2837,
328,
1337,
1752,
20830,
14,
398,
2779,
1077,
27797,
314,
1475,
402,
314,
1059,
2741,
701,
664,
1558,
1858,
3188,
20830,
20693,
267,
372,
408,
3188,
20830,
26,
9509,
282,
3974,
13168,
16630,
1337,
28225,
436,
11789,
3963,
20181,
1915,
1265,
543,
314,
7761,
1041,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8353,
24747,
11737,
3240,
24975,
665,
24863,
11737,
32,
11475,
12041,
14,
846,
10827,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2748,
18,
555,
14,
199,
3,
199,
3,
2748,
18,
555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2748,
18,
555,
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,
2748,
18,
555,
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,
221,
15673,
13,
13421,
221,
8217,
199,
3,
199,
199,
3,
12568,
1930,
598,
29897,
22486,
199,
3,
199,
199,
533,
8763,
8672,
1385,
26,
272,
408,
8458,
1021,
367,
4539,
7252,
402,
2213,
2943,
1041,
272,
347,
664,
19399,
2908,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
370,
506,
5525,
2122,
267,
372,
359,
283,
1073,
297,
283,
1266,
13,
3200,
297,
283,
28151,
13,
3200,
297,
283,
11864,
354,
7,
1622,
339,
347,
664,
12776,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
370,
506,
8652,
283,
5094,
16669,
267,
372,
788,
1213,
297,
283,
12227,
297,
283,
354,
297,
283,
3257,
7,
1622,
339,
347,
664,
7643,
2398,
4909,
9440,
8,
277,
304,
267,
298,
3407,
1625,
402,
3762,
315,
1314,
7883,
787,
370,
506,
17731,
2122,
267,
372,
942,
339,
347,
876,
3498,
8672,
8,
277,
12,
1382,
12,
1499,
304,
267,
298,
26539,
282,
2213,
436,
25358,
9584,
2005,
3788,
2122,
267,
986,
339,
347,
485,
1623,
63,
6327,
938,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
354,
508,
283,
6327,
938,
356,
288,
372,
1031,
267,
1982,
275,
1031,
14,
3223,
267,
1830,
1982,
26,
288,
2203,
275,
291,
423,
1623,
63,
6327,
938,
8,
1739,
9,
288,
340,
2203,
26,
355,
372,
2203,
288,
1982,
275,
1982,
14,
2184,
267,
372,
488,
339,
347,
2963,
3498,
8672,
18483,
8,
277,
12,
1382,
12,
2637,
12,
1752,
20830,
304,
267,
408,
9899,
282,
2637,
436,
1752,
20830,
315,
298,
1301,
2,
3123,
14,
2728,
298,
1515,
20830,
2,
365,
282,
1059,
406,
24925,
402,
32034,
2837,
15256,
14,
267,
298,
3671,
2,
365,
282,
3486,
1059,
14,
267,
298,
1301,
2,
365,
282,
15404,
18,
14,
1652,
3768,
1256,
1041,
267,
327,
6668,
298,
6327,
938,
2,
1947,
436,
1050,
282,
3721,
3595,
32034,
14,
267,
340,
1752,
20830,
508,
291,
14,
362,
1558,
1858,
3188,
20830,
837,
288,
372,
267,
587,
26,
288,
18641,
938,
275,
291,
423,
1623,
63,
6327,
938,
8,
1301,
14,
362,
6405,
2162,
1012,
288,
340,
18641,
938,
436,
18641,
938,
14,
354,
6803,
6327,
938,
356,
355,
327,
1911,
355,
18641,
938,
14,
1222,
3493,
8,
403,
12,
298,
12227,
401,
1752,
20830,
9,
288,
587,
26,
355,
372,
339,
347,
664,
1558,
1858,
3188,
20830,
8,
277,
304,
267,
408,
3407,
488,
503,
282,
1059,
370,
506,
3483,
370,
3625,
1584,
14,
398,
13964,
2893,
365,
283,
29346,
13,
22461,
23690,
267,
372,
298,
29346,
13,
22461,
2,
339,
347,
664,
7488,
1858,
3188,
20830,
8,
277,
304,
267,
408,
3407,
282,
3721,
370,
506,
3483,
2163,
370,
1059,
367,
2837,
328,
1337,
1752,
20830,
14,
398,
2779,
1077,
27797,
314,
1475,
402,
314,
1059,
2741,
701,
664,
1558,
1858,
3188,
20830,
20693,
267,
372,
408,
3188,
20830,
26,
9509,
282,
3974,
13168,
16630,
1337,
28225,
436,
11789,
3963,
20181,
1915,
1265,
543,
314,
7761,
1041,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
paivaspol/appengine-try-out
|
settings.py
|
5
|
1608
|
# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *
import os
# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'
SECRET_KEY = '=r-$b*8hglm+858&9t043hlm6-&6-3d3vfc4((7yd0dbrakhvi'
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'djangotoolbox',
'autoload',
'dbindexer',
# djangoappengine should come last, so it can override a few manage.py commands
'djangoappengine',
)
MIDDLEWARE_CLASSES = (
# This loads the index definitions, so it has to come first
'autoload.middleware.AutoloadMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request',
'django.core.context_processors.media',
)
# This test runner captures stdout and associates tracebacks with their
# corresponding output. Helps a lot with print-debugging.
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'
STATIC_URL = '/static/'
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)
ROOT_URLCONF = 'urls'
|
bsd-3-clause
|
[
3,
11578,
4693,
12580,
436,
492,
314,
849,
2202,
334,
2846,
4865,
12,
5423,
25860,
199,
3,
982,
1265,
2934,
370,
675,
282,
3365,
4865,
1265,
1172,
370,
2813,
1006,
14706,
608,
78,
823,
199,
3,
402,
298,
1176,
15358,
2,
687,
642,
570,
14,
199,
504,
1639,
15358,
14,
1751,
63,
1095,
492,
627,
199,
199,
646,
747,
199,
199,
3,
21904,
2409,
1639,
13,
697,
15615,
367,
314,
849,
3050,
199,
27260,
459,
6106,
418,
275,
26931,
21983,
459,
885,
418,
199,
27260,
459,
885,
418,
275,
791,
15956,
356,
283,
697,
15615,
297,
283,
9268,
356,
283,
6106,
936,
199,
13883,
7405,
63,
7917,
3103,
275,
283,
10116,
7,
199,
199,
12961,
63,
3078,
275,
26143,
82,
13,
4,
66,
10,
24,
72,
3528,
77,
11,
29567,
6,
25,
84,
5882,
72,
14344,
22,
13,
6,
22,
13,
19,
68,
19,
86,
3003,
20,
1332,
23,
24503,
16,
697,
345,
21889,
433,
7,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
12816,
3459,
393,
1977,
297,
272,
283,
2495,
912,
297,
272,
283,
697,
15615,
297,
339,
327,
1639,
15358,
1077,
11492,
2061,
12,
880,
652,
883,
4278,
282,
9284,
9635,
14,
647,
3718,
272,
283,
1176,
15358,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
327,
961,
14404,
314,
1478,
10269,
12,
880,
652,
965,
370,
11492,
1642,
272,
283,
2495,
912,
14,
5754,
14,
3358,
912,
6608,
297,
339,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
199,
9,
199,
199,
7433,
63,
9059,
63,
10494,
4149,
275,
334,
272,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
272,
283,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
1069,
297,
272,
283,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
4603,
297,
199,
9,
199,
199,
3,
961,
511,
7876,
12162,
1482,
3839,
436,
4035,
2335,
5190,
83,
543,
3932,
199,
3,
5226,
1072,
14,
869,
352,
1190,
282,
13918,
543,
870,
13,
24913,
14,
199,
2864,
63,
9390,
15215,
275,
283,
12816,
3459,
393,
1977,
14,
396,
14,
13519,
4039,
10591,
7446,
7,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
7433,
63,
14455,
275,
334,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
5876,
659,
9,
199,
199,
5441,
63,
18125,
275,
283,
3603,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11578,
4693,
12580,
436,
492,
314,
849,
2202,
334,
2846,
4865,
12,
5423,
25860,
199,
3,
982,
1265,
2934,
370,
675,
282,
3365,
4865,
1265,
1172,
370,
2813,
1006,
14706,
608,
78,
823,
199,
3,
402,
298,
1176,
15358,
2,
687,
642,
570,
14,
199,
504,
1639,
15358,
14,
1751,
63,
1095,
492,
627,
199,
199,
646,
747,
199,
199,
3,
21904,
2409,
1639,
13,
697,
15615,
367,
314,
849,
3050,
199,
27260,
459,
6106,
418,
275,
26931,
21983,
459,
885,
418,
199,
27260,
459,
885,
418,
275,
791,
15956,
356,
283,
697,
15615,
297,
283,
9268,
356,
283,
6106,
936,
199,
13883,
7405,
63,
7917,
3103,
275,
283,
10116,
7,
199,
199,
12961,
63,
3078,
275,
26143,
82,
13,
4,
66,
10,
24,
72,
3528,
77,
11,
29567,
6,
25,
84,
5882,
72,
14344,
22,
13,
6,
22,
13,
19,
68,
19,
86,
3003,
20,
1332,
23,
24503,
16,
697,
345,
21889,
433,
7,
199,
199,
15942,
63,
14219,
275,
334,
272,
283,
1176,
14,
2828,
14,
2113,
297,
272,
283,
1176,
14,
2828,
14,
10778,
297,
272,
283,
1176,
14,
2828,
14,
1178,
297,
272,
283,
1176,
14,
2828,
14,
11676,
297,
272,
283,
12816,
3459,
393,
1977,
297,
272,
283,
2495,
912,
297,
272,
283,
697,
15615,
297,
339,
327,
1639,
15358,
1077,
11492,
2061,
12,
880,
652,
883,
4278,
282,
9284,
9635,
14,
647,
3718,
272,
283,
1176,
15358,
297,
199,
9,
199,
199,
19987,
63,
13748,
275,
334,
272,
327,
961,
14404,
314,
1478,
10269,
12,
880,
652,
965,
370,
11492,
1642,
272,
283,
2495,
912,
14,
5754,
14,
3358,
912,
6608,
297,
339,
283,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
297,
272,
283,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
297,
272,
283,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
297,
199,
9,
199,
199,
7433,
63,
9059,
63,
10494,
4149,
275,
334,
272,
283,
1176,
14,
2828,
14,
1178,
14,
1100,
63,
10547,
14,
1178,
297,
272,
283,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
1069,
297,
272,
283,
1176,
14,
1018,
14,
1100,
63,
10547,
14,
4603,
297,
199,
9,
199,
199,
3,
961,
511,
7876,
12162,
1482,
3839,
436,
4035,
2335,
5190,
83,
543,
3932,
199,
3,
5226,
1072,
14,
869,
352,
1190,
282,
13918,
543,
870,
13,
24913,
14,
199,
2864,
63,
9390,
15215,
275,
283,
12816,
3459,
393,
1977,
14,
396,
14,
13519,
4039,
10591,
7446,
7,
199,
199,
10449,
63,
2632,
275,
1994,
1986,
4805,
199,
199,
7433,
63,
14455,
275,
334,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
5876,
659,
9,
199,
199,
5441,
63,
18125,
275,
283,
3603,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ric2b/Vivaldi-browser
|
chromium/base/android/jni_generator/jni_refactorer.py
|
7
|
14708
|
#!/usr/bin/env python2.7
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tool for doing Java refactors over native methods.
Converts
(a) non-static natives to static natives using @JCaller
e.g.
class A {
native void nativeFoo(int a);
void bar() {
nativeFoo(5);
}
}
->
import .....JCaller
class A {
static native void nativeFoo(@JCaller caller, int a);
void bar() {
nativeFoo(A.this, 5);
}
}
(b) static natives to new mockable static natives.
e.g.
class A {
static native void nativeFoo(@JCaller caller, int a);
void bar() {
nativeFoo(5);
}
}
->
import .....JCaller
class A {
void bar() {
AJni.get().foo(A.this, 5);
}
@NativeMethods
interface Natives {
static native void foo(@JCaller caller, int a);
}
}
Created for large refactors to @NativeMethods.
Note: This tool does most of the heavy lifting in the conversion but
there are some things that are difficult to implement with regex and
infrequent enough that they can be done by hand.
These exceptions are:
1) public native methods calls used in other classes are not refactored.
2) native methods inherited from a super class are not refactored
3) Non-static methods are always assumed to be called by the class instance
instead of by another class using that object.
"""
from __future__ import print_function
import argparse
import sys
import string
import re
import os
import pickle
import jni_generator
_JNI_INTERFACE_TEMPLATES = string.Template("""
@NativeMethods
interface ${INTERFACE_NAME} {${METHODS}
}
""")
_JNI_METHOD_DECL = string.Template("""
${RETURN_TYPE} ${NAME}($PARAMS);""")
_COMMENT_REGEX_STRING = r'(?:(?:(?:\/\*[^\/]*\*\/)+|(?:\/\/[^\n]*?\n))+\s*)*'
_NATIVES_REGEX = re.compile(
r'(?P<comments>' + _COMMENT_REGEX_STRING + ')'
r'(?P<annotations>(@NativeClassQualifiedName'
r'\(\"(?P<native_class_name>.*?)\"\)\s+)?'
r'(@NativeCall(\(\"(?P<java_class_name>.*?)\"\))\s+)?)'
r'(?P<qualifiers>\w+\s\w+|\w+|\s+)\s+static\s*native '
r'(?P<return_type>\S*) '
r'(?P<name>native\w+)\((?P<params>.*?)\);\n', re.DOTALL)
_NON_STATIC_NATIVES_REGEX = re.compile(
r'(?P<comments>' + _COMMENT_REGEX_STRING + ')'
r'(?P<annotations>(@NativeClassQualifiedName'
r'\(\"(?P<native_class_name>.*?)\"\)\s+)?'
r'(@NativeCall(\(\"(?P<java_class_name>.*?)\"\))\s+)?)'
r'(?P<qualifiers>\w+\s\w+|\w+|\s+)\s*native '
r'(?P<return_type>\S*) '
r'(?P<name>native\w+)\((?P<params>.*?)\);\n', re.DOTALL)
_NATIVE_PTR_REGEX = re.compile(r'\s*long native.*')
JNI_IMPORT_STRING = 'import org.chromium.base.annotations.NativeMethods;'
IMPORT_REGEX = re.compile(r'^import .*?;', re.MULTILINE)
PICKLE_LOCATION = './jni_ref_pickle'
def build_method_declaration(return_type, name, params, annotations, comments):
out = _JNI_METHOD_DECL.substitute({
'RETURN_TYPE': return_type,
'NAME': name,
'PARAMS': params
})
if annotations:
out = '\n' + annotations + out
if comments:
out = '\n' + comments + out
if annotations or comments:
out += '\n'
return out
def add_chromium_import_to_java_file(contents, import_string):
# Just in cases there are no imports default to after the package statement.
import_insert = contents.find(';') + 1
# Insert in alphabetical order into org.chromium. This assumes
# that all files will contain some org.chromium import.
for match in IMPORT_REGEX.finditer(contents):
import_name = match.group()
if not 'import org.chromium' in import_name:
continue
if import_name > import_insert:
import_insert = match.start()
break
else:
import_insert = match.end() + 1
return "%s%s\n%s" % (contents[:import_insert], import_string,
contents[import_insert:])
def convert_nonstatic_to_static(java_file_name,
skip_caller=False,
dry=False,
verbose=True):
if java_file_name is None:
return
if not os.path.isfile(java_file_name):
if verbose:
print('%s does not exist', java_file_name)
return
with open(java_file_name, 'r') as f:
contents = f.read()
no_comment_content = jni_generator.RemoveComments(contents)
parsed_natives = jni_generator.ExtractNatives(no_comment_content, 'long')
non_static_natives = [n for n in parsed_natives if not n.static]
if not non_static_natives:
if verbose:
print('no natives found')
return
class_name = jni_generator.ExtractFullyQualifiedJavaClassName(
java_file_name, no_comment_content).split('/')[-1]
# For fixing call sites.
replace_patterns = []
should_append_comma = []
should_prepend_comma = []
new_contents = contents
# 1. Change non-static -> static.
insertion_offset = 0
matches = []
for match in _NON_STATIC_NATIVES_REGEX.finditer(contents):
if not 'static' in match.group('qualifiers'):
matches.append(match)
# Insert static as a keyword.
qual_end = match.end('qualifiers') + insertion_offset
insert_str = ' static '
new_contents = new_contents[:qual_end] + insert_str + new_contents[
qual_end:]
insertion_offset += len(insert_str)
if skip_caller:
continue
# Insert an object param.
insert_str = '%s caller' % class_name
# No params.
if not match.group('params'):
start = insertion_offset + match.start('params')
append_comma = False
prepend_comma = False
# One or more params.
else:
# Has mNativePtr.
if _NATIVE_PTR_REGEX.match(match.group('params')):
# Only 1 param, append to end of params.
if match.group('params').count(',') == 0:
start = insertion_offset + match.end('params')
append_comma = False
prepend_comma = True
# Multiple params, insert after first param.
else:
comma_pos = match.group('params').find(',')
start = insertion_offset + match.start('params') + comma_pos + 1
append_comma = True
prepend_comma = False
else:
# No mNativePtr, insert as first param.
start = insertion_offset + match.start('params')
append_comma = True
prepend_comma = False
if prepend_comma:
insert_str = ', ' + insert_str
if append_comma:
insert_str = insert_str + ', '
new_contents = new_contents[:start] + insert_str + new_contents[start:]
# Match lines that don't have a native keyword.
native_match = r'\((\s*?(([ms]Native\w+)|([ms]\w+Android(Ptr)?)),?)?)'
replace_patterns.append(r'(^\s*' + match.group('name') + native_match)
replace_patterns.append(r'(return ' + match.group('name') + native_match)
replace_patterns.append(r'([\:\)\(\+\*\?\&\|,\.\-\=\!\/][ \t]*' +
match.group('name') + native_match)
should_append_comma.extend([append_comma] * 3)
should_prepend_comma.extend([prepend_comma] * 3)
insertion_offset += len(insert_str)
assert len(matches) == len(non_static_natives), ('Regex missed a native '
'method that was found by '
'the jni_generator.')
# 2. Add a this param to all calls.
for i, r in enumerate(replace_patterns):
prepend_comma = ', ' if should_prepend_comma[i] else ''
append_comma = ', ' if should_append_comma[i] else ''
repl_str = '\g<1>' + prepend_comma + ' %s.this' + append_comma
new_contents = re.sub(
r, repl_str % class_name, new_contents, flags=re.MULTILINE)
if dry:
print(new_contents)
else:
with open(java_file_name, 'w') as f:
f.write(new_contents)
def filter_files_with_natives(files, verbose=True):
filtered = []
i = 1
for java_file_name in files:
if not os.path.isfile(java_file_name):
print('does not exist')
return
if verbose:
print('Processing %s/%s - %s ' % (i, len(files), java_file_name))
with open(java_file_name, 'r') as f:
contents = f.read()
no_comment_content = jni_generator.RemoveComments(contents)
natives = jni_generator.ExtractNatives(no_comment_content, 'long')
if len(natives) > 1:
filtered.append(java_file_name)
i += 1
return filtered
def convert_file_to_proxy_natives(java_file_name, dry=False, verbose=True):
if not os.path.isfile(java_file_name):
if verbose:
print('%s does not exist', java_file_name)
return
with open(java_file_name, 'r') as f:
contents = f.read()
no_comment_content = jni_generator.RemoveComments(contents)
natives = jni_generator.ExtractNatives(no_comment_content, 'long')
static_natives = [n for n in natives if n.static]
if not static_natives:
if verbose:
print('%s has no static natives.', java_file_name)
return
contents = add_chromium_import_to_java_file(contents, JNI_IMPORT_STRING)
# Extract comments and annotations above native methods.
native_map = {}
for itr in re.finditer(_NATIVES_REGEX, contents):
n_dict = {}
n_dict['annotations'] = itr.group('annotations').strip()
n_dict['comments'] = itr.group('comments').strip()
n_dict['params'] = itr.group('params').strip()
native_map[itr.group('name')] = n_dict
# Using static natives here ensures all the methods that are picked up by
# the JNI generator are also caught by our own regex.
methods = []
for n in static_natives:
new_name = n.name[0].lower() + n.name[1:]
n_dict = native_map['native' + n.name]
params = n_dict['params']
comments = n_dict['comments']
annotations = n_dict['annotations']
methods.append(
build_method_declaration(n.return_type, new_name, params, annotations,
comments))
fully_qualified_class = jni_generator.ExtractFullyQualifiedJavaClassName(
java_file_name, contents)
class_name = fully_qualified_class.split('/')[-1]
jni_class_name = class_name + 'Jni'
# Remove all old declarations.
for n in static_natives:
pattern = _NATIVES_REGEX
contents = re.sub(pattern, '', contents)
# Replace occurences with new signature.
for n in static_natives:
# Okay not to match first (.
# Since even if natives share a prefix, the replacement is the same.
# E.g. if nativeFoo() and nativeFooBar() are both statics
# and in nativeFooBar() we replace nativeFoo -> AJni.get().foo
# the result is the same as replacing nativeFooBar() -> AJni.get().fooBar
pattern = r'native%s' % n.name
lower_name = n.name[0].lower() + n.name[1:]
contents = re.sub(pattern, '%s.get().%s' % (jni_class_name, lower_name),
contents)
# Build and insert the @NativeMethods interface.
interface = _JNI_INTERFACE_TEMPLATES.substitute({
'INTERFACE_NAME': 'Natives',
'METHODS': ''.join(methods)
})
# Insert the interface at the bottom of the top level class.
# Most of the time this will be before the last }.
insertion_point = contents.rfind('}')
contents = contents[:insertion_point] + '\n' + interface + contents[
insertion_point:]
if not dry:
with open(java_file_name, 'w') as f:
f.write(contents)
else:
print(contents)
return contents
def main(argv):
arg_parser = argparse.ArgumentParser()
mutually_ex_group = arg_parser.add_mutually_exclusive_group()
mutually_ex_group.add_argument(
'-R',
'--recursive',
action='store_true',
help='Run recursively over all java files '
'descendants of the current directory.',
default=False)
mutually_ex_group.add_argument(
'--read_cache',
help='Reads paths to refactor from pickled file %s.' % PICKLE_LOCATION,
action='store_true',
default=False)
mutually_ex_group.add_argument(
'--source', help='Path to refactor single source file.', default=None)
arg_parser.add_argument(
'--cache',
action='store_true',
help='Finds all java files with native functions recursively from '
'the current directory, then pickles and saves them to %s and then'
'exits.' % PICKLE_LOCATION,
default=False)
arg_parser.add_argument(
'--dry_run',
default=False,
action='store_true',
help='Print refactor output to console instead '
'of replacing the contents of files.')
arg_parser.add_argument(
'--nonstatic',
default=False,
action='store_true',
help='If true converts native nonstatic methods to static methods'
' instead of converting static methods to new jni.')
arg_parser.add_argument(
'--verbose', default=False, action='store_true', help='')
arg_parser.add_argument(
'--ignored-paths',
action='append',
help='Paths to ignore during conversion.')
arg_parser.add_argument(
'--skip-caller-arg',
default=False,
action='store_true',
help='Do not add the "this" param when converting non-static methods.')
args = arg_parser.parse_args()
java_file_paths = []
if args.source:
java_file_paths = [args.source]
elif args.read_cache:
print('Reading paths from ' + PICKLE_LOCATION)
with open(PICKLE_LOCATION, 'r') as file:
java_file_paths = pickle.load(file)
print('Found %s java paths.' % len(java_file_paths))
elif args.recursive:
for root, _, files in os.walk(os.path.abspath('.')):
java_file_paths.extend(
['%s/%s' % (root, f) for f in files if f.endswith('.java')])
else:
# Get all java files in current dir.
java_file_paths = filter(lambda x: x.endswith('.java'),
map(os.path.abspath, os.listdir('.')))
if args.ignored_paths:
java_file_paths = [
path for path in java_file_paths
if all(p not in path for p in args.ignored_paths)
]
if args.cache:
with open(PICKLE_LOCATION, 'w') as file:
pickle.dump(filter_files_with_natives(java_file_paths), file)
print('Java files with proxy natives written to ' + PICKLE_LOCATION)
i = 1
for f in java_file_paths:
print(f)
if args.nonstatic:
convert_nonstatic_to_static(
f,
skip_caller=args.skip_caller_arg,
dry=args.dry_run,
verbose=args.verbose)
else:
convert_file_to_proxy_natives(f, dry=args.dry_run, verbose=args.verbose)
print('Done converting %s/%s' % (i, len(java_file_paths)))
i += 1
print('Done please run git cl format.')
if __name__ == '__main__':
sys.exit(main(sys.argv))
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
14,
23,
199,
3,
1898,
14894,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5157,
367,
9689,
9586,
295,
16125,
1806,
5438,
3102,
14,
199,
199,
17729,
199,
8,
65,
9,
2222,
13,
1986,
302,
10661,
370,
2955,
302,
10661,
1808,
768,
42,
6584,
1435,
199,
69,
14,
71,
14,
199,
533,
437,
469,
523,
5438,
2309,
5438,
5686,
8,
442,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
21,
2736,
523,
789,
199,
93,
199,
5118,
199,
646,
2508,
1396,
42,
6584,
1435,
199,
533,
437,
469,
523,
2955,
5438,
2309,
5438,
5686,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
33,
14,
3749,
12,
959,
2736,
523,
789,
199,
93,
199,
199,
8,
66,
9,
2955,
302,
10661,
370,
892,
1683,
461,
2955,
302,
10661,
14,
199,
69,
14,
71,
14,
199,
533,
437,
469,
523,
2955,
5438,
2309,
5438,
5686,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
21,
2736,
523,
789,
199,
93,
199,
5118,
199,
646,
2508,
1396,
42,
6584,
1435,
199,
533,
437,
469,
523,
2309,
4681,
342,
469,
272,
437,
42,
8445,
14,
362,
1252,
1421,
8,
33,
14,
3749,
12,
959,
2736,
523,
789,
819,
768,
19675,
10385,
523,
3217,
653,
10661,
469,
272,
2955,
5438,
2309,
3925,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
523,
789,
199,
93,
199,
199,
10502,
367,
7031,
295,
16125,
370,
768,
19675,
10385,
14,
199,
7443,
26,
961,
4744,
1630,
4750,
402,
314,
946,
22421,
221,
853,
1337,
315,
314,
8603,
1325,
199,
16990,
787,
2005,
7645,
626,
787,
29870,
370,
5669,
543,
5163,
436,
199,
4904,
264,
9333,
8321,
626,
2985,
883,
506,
4224,
701,
4926,
14,
199,
199,
20676,
4967,
787,
26,
199,
17,
9,
4575,
5438,
3102,
4882,
1202,
315,
1163,
3992,
787,
440,
295,
7783,
2908,
14,
199,
18,
9,
5438,
3102,
12623,
687,
282,
1613,
1021,
787,
440,
295,
7783,
2908,
199,
19,
9,
10172,
13,
1986,
3102,
787,
3544,
10826,
370,
506,
2797,
701,
314,
1021,
1256,
199,
23145,
402,
701,
4573,
1021,
1808,
626,
909,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
646,
1059,
199,
646,
295,
199,
646,
747,
199,
646,
5927,
199,
199,
646,
1335,
8445,
63,
4679,
199,
199,
63,
42,
16730,
63,
17598,
63,
25437,
275,
1059,
14,
4231,
4852,
272,
768,
19675,
10385,
272,
3217,
10839,
17598,
63,
2339,
93,
469,
10545,
18383,
93,
272,
789,
199,
6141,
199,
199,
63,
42,
16730,
63,
9977,
63,
27402,
275,
1059,
14,
4231,
4852,
267,
10839,
9677,
63,
2711,
93,
10839,
2339,
93,
22187,
17978,
2736,
6141,
199,
199,
63,
10973,
63,
10710,
63,
5353,
275,
519,
20459,
5169,
15840,
6307,
10,
16045,
15,
25739,
7590,
15,
6393,
92,
15840,
6307,
15,
16045,
78,
3672,
8995,
78,
430,
7896,
83,
10,
3342,
7,
199,
199,
63,
28927,
6882,
654,
63,
10710,
275,
295,
14,
2014,
8,
272,
519,
10120,
48,
28,
6223,
3524,
435,
485,
10973,
63,
10710,
63,
5353,
435,
16107,
272,
519,
10120,
48,
28,
11270,
13661,
32,
19675,
2543,
23279,
985,
7,
272,
519,
1154,
2961,
24726,
48,
28,
6106,
63,
533,
63,
354,
27124,
2862,
3212,
2862,
83,
19544,
7,
272,
519,
6774,
32,
19675,
2176,
2961,
2961,
24726,
48,
28,
6138,
63,
533,
63,
354,
27124,
2862,
3212,
25105,
83,
19544,
3171,
272,
519,
10120,
48,
28,
537,
26765,
3072,
87,
7896,
83,
60,
87,
11,
6113,
87,
11,
6113,
83,
13439,
83,
11,
1986,
60,
83,
10,
6106,
283,
272,
519,
10120,
48,
28,
1107,
63,
466,
3072,
51,
13278,
283,
272,
519,
10120,
48,
28,
354,
30,
6106,
60,
87,
13439,
17304,
48,
28,
1162,
27124,
2862,
6152,
78,
297,
295,
14,
16504,
9,
199,
199,
63,
13887,
63,
10449,
63,
28927,
6882,
654,
63,
10710,
275,
295,
14,
2014,
8,
272,
519,
10120,
48,
28,
6223,
3524,
435,
485,
10973,
63,
10710,
63,
5353,
435,
16107,
272,
519,
10120,
48,
28,
11270,
13661,
32,
19675,
2543,
23279,
985,
7,
272,
519,
1154,
2961,
24726,
48,
28,
6106,
63,
533,
63,
354,
27124,
2862,
3212,
2862,
83,
19544,
7,
272,
519,
6774,
32,
19675,
2176,
2961,
2961,
24726,
48,
28,
6138,
63,
533,
63,
354,
27124,
2862,
3212,
25105,
83,
19544,
3171,
272,
519,
10120,
48,
28,
537,
26765,
3072,
87,
7896,
83,
60,
87,
11,
6113,
87,
11,
6113,
83,
13439,
83,
10,
6106,
283,
272,
519,
10120,
48,
28,
1107,
63,
466,
3072,
51,
13278,
283,
272,
519,
10120,
48,
28,
354,
30,
6106,
60,
87,
13439,
17304,
48,
28,
1162,
27124,
2862,
6152,
78,
297,
295,
14,
16504,
9,
199,
63,
46,
14277,
63,
14528,
63,
10710,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
2809,
5438,
24915,
199,
199,
42,
16730,
63,
17576,
63,
5353,
275,
283,
646,
5981,
14,
13211,
14,
1095,
14,
11270,
14,
19675,
10385,
8942,
199,
17576,
63,
10710,
275,
295,
14,
2014,
8,
82,
4289,
646,
1275,
15279,
10805,
295,
14,
16661,
9,
199,
199,
48,
13884,
906,
63,
16575,
275,
21526,
74,
8445,
63,
1121,
63,
8092,
7,
421,
199,
318,
1900,
63,
765,
63,
15477,
8,
1107,
63,
466,
12,
536,
12,
1862,
12,
15538,
12,
6786,
304,
523,
734,
275,
485,
42,
16730,
63,
9977,
63,
27402,
14,
20374,
2561,
489,
283,
9677,
63,
2711,
356,
372,
63,
466,
12,
489,
283,
2339,
356,
536,
12,
489,
283,
17978,
356,
1862,
523,
3828,
523,
340,
15538,
26,
272,
734,
275,
1557,
78,
7,
435,
15538,
435,
734,
523,
340,
6786,
26,
272,
734,
275,
1557,
78,
7,
435,
6786,
435,
734,
523,
340,
15538,
503,
6786,
26,
272,
734,
847,
1557,
78,
7,
523,
372,
734,
421,
199,
318,
1050,
63,
13211,
63,
646,
63,
475,
63,
6138,
63,
493
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
14,
23,
199,
3,
1898,
14894,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5157,
367,
9689,
9586,
295,
16125,
1806,
5438,
3102,
14,
199,
199,
17729,
199,
8,
65,
9,
2222,
13,
1986,
302,
10661,
370,
2955,
302,
10661,
1808,
768,
42,
6584,
1435,
199,
69,
14,
71,
14,
199,
533,
437,
469,
523,
5438,
2309,
5438,
5686,
8,
442,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
21,
2736,
523,
789,
199,
93,
199,
5118,
199,
646,
2508,
1396,
42,
6584,
1435,
199,
533,
437,
469,
523,
2955,
5438,
2309,
5438,
5686,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
33,
14,
3749,
12,
959,
2736,
523,
789,
199,
93,
199,
199,
8,
66,
9,
2955,
302,
10661,
370,
892,
1683,
461,
2955,
302,
10661,
14,
199,
69,
14,
71,
14,
199,
533,
437,
469,
523,
2955,
5438,
2309,
5438,
5686,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
819,
2309,
4681,
342,
469,
272,
5438,
5686,
8,
21,
2736,
523,
789,
199,
93,
199,
5118,
199,
646,
2508,
1396,
42,
6584,
1435,
199,
533,
437,
469,
523,
2309,
4681,
342,
469,
272,
437,
42,
8445,
14,
362,
1252,
1421,
8,
33,
14,
3749,
12,
959,
2736,
523,
789,
819,
768,
19675,
10385,
523,
3217,
653,
10661,
469,
272,
2955,
5438,
2309,
3925,
8,
32,
42,
6584,
1435,
8025,
12,
1109,
282,
2736,
523,
789,
199,
93,
199,
199,
10502,
367,
7031,
295,
16125,
370,
768,
19675,
10385,
14,
199,
7443,
26,
961,
4744,
1630,
4750,
402,
314,
946,
22421,
221,
853,
1337,
315,
314,
8603,
1325,
199,
16990,
787,
2005,
7645,
626,
787,
29870,
370,
5669,
543,
5163,
436,
199,
4904,
264,
9333,
8321,
626,
2985,
883,
506,
4224,
701,
4926,
14,
199,
199,
20676,
4967,
787,
26,
199,
17,
9,
4575,
5438,
3102,
4882,
1202,
315,
1163,
3992,
787,
440,
295,
7783,
2908,
14,
199,
18,
9,
5438,
3102,
12623,
687,
282,
1613,
1021,
787,
440,
295,
7783,
2908,
199,
19,
9,
10172,
13,
1986,
3102,
787,
3544,
10826,
370,
506,
2797,
701,
314,
1021,
1256,
199,
23145,
402,
701,
4573,
1021,
1808,
626,
909,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
7534,
199,
646,
984,
199,
646,
1059,
199,
646,
295,
199,
646,
747,
199,
646,
5927,
199,
199,
646,
1335,
8445,
63,
4679,
199,
199,
63,
42,
16730,
63,
17598,
63,
25437,
275,
1059,
14,
4231,
4852,
272,
768,
19675,
10385,
272,
3217,
10839,
17598,
63,
2339,
93,
469,
10545,
18383,
93,
272,
789,
199,
6141,
199,
199,
63,
42,
16730,
63,
9977,
63,
27402,
275,
1059,
14,
4231,
4852,
267,
10839,
9677,
63,
2711,
93,
10839,
2339,
93,
22187,
17978,
2736,
6141,
199,
199,
63,
10973,
63,
10710,
63,
5353,
275,
519,
20459,
5169,
15840,
6307,
10,
16045,
15,
25739,
7590,
15,
6393,
92,
15840,
6307,
15,
16045,
78,
3672,
8995,
78,
430,
7896,
83,
10,
3342,
7,
199,
199,
63,
28927,
6882,
654,
63,
10710,
275,
295,
14,
2014,
8,
272,
519,
10120,
48,
28,
6223,
3524,
435,
485,
10973,
63,
10710,
63,
5353,
435,
16107,
272,
519,
10120,
48,
28,
11270,
13661,
32,
19675,
2543,
23279,
985,
7,
272,
519,
1154,
2961,
24726,
48,
28,
6106,
63,
533,
63,
354,
27124,
2862,
3212,
2862,
83,
19544,
7,
272,
519,
6774,
32,
19675,
2176,
2961,
2961,
24726,
48,
28,
6138,
63,
533,
63,
354,
27124,
2862,
3212,
25105,
83,
19544,
3171,
272,
519,
10120,
48,
28,
537,
26765,
3072,
87,
7896,
83,
60,
87,
11,
6113,
87,
11,
6113,
83,
13439,
83,
11,
1986,
60,
83,
10,
6106,
283,
272,
519,
10120,
48,
28,
1107,
63,
466,
3072,
51,
13278,
283,
272,
519,
10120,
48,
28,
354,
30,
6106,
60,
87,
13439,
17304,
48,
28,
1162,
27124,
2862,
6152,
78,
297,
295,
14,
16504,
9,
199,
199,
63,
13887,
63,
10449,
63,
28927,
6882,
654,
63,
10710,
275,
295,
14,
2014,
8,
272,
519,
10120,
48,
28,
6223,
3524,
435,
485,
10973,
63,
10710,
63,
5353,
435,
16107,
272,
519,
10120,
48,
28,
11270,
13661,
32,
19675,
2543,
23279,
985,
7,
272,
519,
1154,
2961,
24726,
48,
28,
6106,
63,
533,
63,
354,
27124,
2862,
3212,
2862,
83,
19544,
7,
272,
519,
6774,
32,
19675,
2176,
2961,
2961,
24726,
48,
28,
6138,
63,
533,
63,
354,
27124,
2862,
3212,
25105,
83,
19544,
3171,
272,
519,
10120,
48,
28,
537,
26765,
3072,
87,
7896,
83,
60,
87,
11,
6113,
87,
11,
6113,
83,
13439,
83,
10,
6106,
283,
272,
519,
10120,
48,
28,
1107,
63,
466,
3072,
51,
13278,
283,
272,
519,
10120,
48,
28,
354,
30,
6106,
60,
87,
13439,
17304,
48,
28,
1162,
27124,
2862,
6152,
78,
297,
295,
14,
16504,
9,
199,
63,
46,
14277,
63,
14528,
63,
10710,
275,
295,
14,
2014,
8,
82,
1154,
83,
10,
2809,
5438,
24915,
199,
199,
42,
16730,
63,
17576,
63,
5353,
275,
283,
646,
5981,
14,
13211,
14,
1095,
14,
11270,
14,
19675,
10385,
8942,
199,
17576,
63,
10710,
275,
295,
14,
2014,
8,
82,
4289,
646,
1275,
15279,
10805,
295,
14,
16661,
9,
199,
199,
48,
13884,
906,
63,
16575,
275,
21526,
74,
8445,
63,
1121,
63,
8092,
7,
421,
199,
318,
1900,
63,
765,
63,
15477,
8,
1107,
63,
466,
12,
536,
12,
1862,
12,
15538,
12,
6786,
304,
523,
734,
275,
485,
42,
16730,
63,
9977,
63,
27402,
14,
20374,
2561,
489,
283,
9677,
63,
2711,
356,
372,
63,
466,
12,
489,
283,
2339,
356,
536,
12,
489,
283,
17978,
356,
1862,
523,
3828,
523,
340,
15538,
26,
272,
734,
275,
1557,
78,
7,
435,
15538,
435,
734,
523,
340,
6786,
26,
272,
734,
275,
1557,
78,
7,
435,
6786,
435,
734,
523,
340,
15538,
503,
6786,
26,
272,
734,
847,
1557,
78,
7,
523,
372,
734,
421,
199,
318,
1050,
63,
13211,
63,
646,
63,
475,
63,
6138,
63,
493,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wangyum/tensorflow
|
tensorflow/python/kernel_tests/weights_broadcast_test.py
|
130
|
9711
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for broadcast rules."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.framework import dtypes as dtypes_lib
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import weights_broadcast_ops
from tensorflow.python.platform import test
def _test_values(shape):
return np.reshape(np.cumsum(np.ones(shape), dtype=np.int32), newshape=shape)
class AssertBroadcastableTest(test.TestCase):
def setUp(self):
ops.reset_default_graph()
def _test_valid(self, weights, values):
static_op = weights_broadcast_ops.assert_broadcastable(
weights=weights, values=values)
weights_placeholder = array_ops.placeholder(dtypes_lib.float32)
values_placeholder = array_ops.placeholder(dtypes_lib.float32)
dynamic_op = weights_broadcast_ops.assert_broadcastable(
weights=weights_placeholder, values=values_placeholder)
with self.test_session():
static_op.run()
dynamic_op.run(feed_dict={
weights_placeholder: weights,
values_placeholder: values,
})
def testScalar(self):
self._test_valid(weights=5, values=_test_values((3, 2, 4)))
def test1x1x1(self):
self._test_valid(
weights=np.asarray((5,)).reshape((1, 1, 1)),
values=_test_values((3, 2, 4)))
def test1x1xN(self):
self._test_valid(
weights=np.asarray((5, 7, 11, 3)).reshape((1, 1, 4)),
values=_test_values((3, 2, 4)))
def test1xNx1(self):
self._test_valid(
weights=np.asarray((5, 11)).reshape((1, 2, 1)),
values=_test_values((3, 2, 4)))
def test1xNxN(self):
self._test_valid(
weights=np.asarray((5, 7, 11, 3, 2, 13, 7, 5)).reshape((1, 2, 4)),
values=_test_values((3, 2, 4)))
def testNx1x1(self):
self._test_valid(
weights=np.asarray((5, 7, 11)).reshape((3, 1, 1)),
values=_test_values((3, 2, 4)))
def testNx1xN(self):
self._test_valid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3)).reshape((3, 1, 4)),
values=_test_values((3, 2, 4)))
def testNxNxN(self):
self._test_valid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((3, 2, 4)),
values=_test_values((3, 2, 4)))
def _test_invalid(self, weights, values):
error_msg = 'weights can not be broadcast to values'
with self.assertRaisesRegexp(ValueError, error_msg):
weights_broadcast_ops.assert_broadcastable(weights=weights, values=values)
weights_placeholder = array_ops.placeholder(dtypes_lib.float32)
values_placeholder = array_ops.placeholder(dtypes_lib.float32)
dynamic_op = weights_broadcast_ops.assert_broadcastable(
weights=weights_placeholder, values=values_placeholder)
with self.test_session():
with self.assertRaisesRegexp(errors_impl.OpError, error_msg):
dynamic_op.run(feed_dict={
weights_placeholder: weights,
values_placeholder: values,
})
def testInvalid1(self):
self._test_invalid(weights=np.asarray((5,)), values=_test_values((3, 2, 4)))
def testInvalid1x1(self):
self._test_invalid(
weights=np.asarray((5,)).reshape((1, 1)),
values=_test_values((3, 2, 4)))
def testInvalidPrefixMatch(self):
self._test_invalid(
weights=np.asarray((5, 7, 11, 3, 2, 12)).reshape((3, 2)),
values=_test_values((3, 2, 4)))
def testInvalidSuffixMatch(self):
self._test_invalid(
weights=np.asarray((5, 7, 11, 3, 2, 12, 7, 5)).reshape((2, 4)),
values=_test_values((3, 2, 4)))
def testInvalidOnesExtraDim(self):
self._test_invalid(
weights=np.asarray((5,)).reshape((1, 1, 1, 1)),
values=_test_values((3, 2, 4)))
def testInvalidPrefixMatchExtraDim(self):
self._test_invalid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((3, 2, 4, 1)),
values=_test_values((3, 2, 4)))
def testInvalidSuffixMatchExtraDim(self):
self._test_invalid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((1, 3, 2, 4)),
values=_test_values((3, 2, 4)))
class BroadcastWeightsTest(test.TestCase):
def setUp(self):
ops.reset_default_graph()
def _test_valid(self, weights, values, expected):
static_op = weights_broadcast_ops.broadcast_weights(
weights=weights, values=values)
weights_placeholder = array_ops.placeholder(dtypes_lib.float32)
values_placeholder = array_ops.placeholder(dtypes_lib.float32)
dynamic_op = weights_broadcast_ops.broadcast_weights(
weights=weights_placeholder, values=values_placeholder)
with self.test_session():
self.assertAllEqual(expected, static_op.eval())
self.assertAllEqual(expected, dynamic_op.eval(feed_dict={
weights_placeholder: weights,
values_placeholder: values,
}))
def testScalar(self):
self._test_valid(
weights=5,
values=_test_values((3, 2, 4)),
expected=5 * np.ones((3, 2, 4)))
def test1x1x1(self):
self._test_valid(
weights=np.asarray((5,)).reshape((1, 1, 1)),
values=_test_values((3, 2, 4)),
expected=5 * np.ones((3, 2, 4)))
def test1x1xN(self):
weights = np.asarray((5, 7, 11, 3)).reshape((1, 1, 4))
self._test_valid(
weights=weights,
values=_test_values((3, 2, 4)),
expected=np.tile(weights, reps=(3, 2, 1)))
def test1xNx1(self):
weights = np.asarray((5, 11)).reshape((1, 2, 1))
self._test_valid(
weights=weights,
values=_test_values((3, 2, 4)),
expected=np.tile(weights, reps=(3, 1, 4)))
def test1xNxN(self):
weights = np.asarray((5, 7, 11, 3, 2, 13, 7, 5)).reshape((1, 2, 4))
self._test_valid(
weights=weights,
values=_test_values((3, 2, 4)),
expected=np.tile(weights, reps=(3, 1, 1)))
def testNx1x1(self):
weights = np.asarray((5, 7, 11)).reshape((3, 1, 1))
self._test_valid(
weights=weights,
values=_test_values((3, 2, 4)),
expected=np.tile(weights, reps=(1, 2, 4)))
def testNx1xN(self):
weights = np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3)).reshape((3, 1, 4))
self._test_valid(
weights=weights,
values=_test_values((3, 2, 4)),
expected=np.tile(weights, reps=(1, 2, 1)))
def testNxNxN(self):
weights = np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((3, 2, 4))
self._test_valid(
weights=weights, values=_test_values((3, 2, 4)), expected=weights)
def _test_invalid(self, weights, values):
error_msg = 'weights can not be broadcast to values'
with self.assertRaisesRegexp(ValueError, error_msg):
weights_broadcast_ops.broadcast_weights(weights=weights, values=values)
weights_placeholder = array_ops.placeholder(dtypes_lib.float32)
values_placeholder = array_ops.placeholder(dtypes_lib.float32)
dynamic_op = weights_broadcast_ops.broadcast_weights(
weights=weights_placeholder, values=values_placeholder)
with self.test_session():
with self.assertRaisesRegexp(errors_impl.OpError, error_msg):
dynamic_op.eval(feed_dict={
weights_placeholder: weights,
values_placeholder: values,
})
def testInvalid1(self):
self._test_invalid(weights=np.asarray((5,)), values=_test_values((3, 2, 4)))
def testInvalid1x1(self):
self._test_invalid(
weights=np.asarray((5,)).reshape((1, 1)),
values=_test_values((3, 2, 4)))
def testInvalidPrefixMatch(self):
self._test_invalid(
weights=np.asarray((5, 7, 11, 3, 2, 12)).reshape((3, 2)),
values=_test_values((3, 2, 4)))
def testInvalidSuffixMatch(self):
self._test_invalid(
weights=np.asarray((5, 7, 11, 3, 2, 12, 7, 5)).reshape((2, 4)),
values=_test_values((3, 2, 4)))
def testInvalidOnesExtraDim(self):
self._test_invalid(
weights=np.asarray((5,)).reshape((1, 1, 1, 1)),
values=_test_values((3, 2, 4)))
def testInvalidPrefixMatchExtraDim(self):
self._test_invalid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((3, 2, 4, 1)),
values=_test_values((3, 2, 4)))
def testInvalidSuffixMatchExtraDim(self):
self._test_invalid(
weights=np.asarray((
5, 7, 11, 3, 2, 12, 7, 5, 2, 17, 11, 3,
2, 17, 11, 3, 5, 7, 11, 3, 2, 12, 7, 5)).reshape((1, 3, 2, 4)),
values=_test_values((3, 2, 4)))
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
11180,
4713,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
465,
6674,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4931,
63,
10786,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
485,
396,
63,
1459,
8,
1392,
304,
523,
372,
980,
14,
5217,
8,
1590,
14,
23916,
8,
1590,
14,
4548,
8,
1392,
395,
2152,
29,
1590,
14,
442,
708,
395,
892,
1392,
29,
1392,
9,
421,
199,
533,
10716,
12105,
461,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
819,
347,
485,
396,
63,
1078,
8,
277,
12,
4931,
12,
1338,
304,
272,
2955,
63,
411,
275,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
267,
4931,
29,
4916,
12,
1338,
29,
1459,
9,
272,
4931,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
1338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
8336,
63,
411,
275,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
267,
4931,
29,
4916,
63,
6199,
12,
1338,
29,
1459,
63,
6199,
9,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2955,
63,
411,
14,
1065,
342,
489,
8336,
63,
411,
14,
1065,
8,
3871,
63,
807,
3126,
881,
4931,
63,
6199,
26,
4931,
12,
881,
1338,
63,
6199,
26,
1338,
12,
489,
3828,
819,
347,
511,
13090,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
4916,
29,
21,
12,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
88,
17,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
4641,
14,
5217,
1332,
17,
12,
413,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
88,
17,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
12,
650,
4992,
5217,
1332,
17,
12,
413,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
31985,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
4119,
4992,
5217,
1332,
17,
12,
499,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
31985,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
4944,
12,
1520,
12,
959,
4992,
5217,
1332,
17,
12,
499,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
88,
17,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
4992,
5217,
1332,
19,
12,
413,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
88,
17,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
288,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
12,
499,
12,
5557,
12,
4119,
12,
650,
4992,
5217,
1332,
19,
12,
413,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
31985,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
288,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
12,
499,
12,
5557,
12,
4119,
12,
650,
12,
288,
499,
12,
5557,
12,
4119,
12,
650,
12,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
4992,
5217,
1332,
19,
12,
499,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
485,
396,
63,
3197,
8,
277,
12,
4931,
12,
1338,
304,
272,
1125,
63,
1328,
275,
283,
4916,
883,
440,
506,
11180,
370,
1338,
7,
272,
543,
291,
14,
10835,
8,
3393,
12,
1125,
63,
1328,
304,
489,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
4916,
29,
4916,
12,
1338,
29,
1459,
9,
272,
4931,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
1338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
8336,
63,
411,
275,
4931,
63,
10786,
63,
1483,
14
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
11180,
4713,
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,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
465,
6674,
63,
773,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2552,
63,
5472,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4931,
63,
10786,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
485,
396,
63,
1459,
8,
1392,
304,
523,
372,
980,
14,
5217,
8,
1590,
14,
23916,
8,
1590,
14,
4548,
8,
1392,
395,
2152,
29,
1590,
14,
442,
708,
395,
892,
1392,
29,
1392,
9,
421,
199,
533,
10716,
12105,
461,
774,
8,
396,
14,
1746,
304,
819,
347,
3613,
8,
277,
304,
272,
4156,
14,
3958,
63,
885,
63,
2180,
342,
819,
347,
485,
396,
63,
1078,
8,
277,
12,
4931,
12,
1338,
304,
272,
2955,
63,
411,
275,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
267,
4931,
29,
4916,
12,
1338,
29,
1459,
9,
272,
4931,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
1338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
8336,
63,
411,
275,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
267,
4931,
29,
4916,
63,
6199,
12,
1338,
29,
1459,
63,
6199,
9,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
2955,
63,
411,
14,
1065,
342,
489,
8336,
63,
411,
14,
1065,
8,
3871,
63,
807,
3126,
881,
4931,
63,
6199,
26,
4931,
12,
881,
1338,
63,
6199,
26,
1338,
12,
489,
3828,
819,
347,
511,
13090,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
4916,
29,
21,
12,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
88,
17,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
4641,
14,
5217,
1332,
17,
12,
413,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
88,
17,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
12,
650,
4992,
5217,
1332,
17,
12,
413,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
31985,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
4119,
4992,
5217,
1332,
17,
12,
499,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
17,
31985,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
4944,
12,
1520,
12,
959,
4992,
5217,
1332,
17,
12,
499,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
88,
17,
88,
17,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
21,
12,
1520,
12,
4119,
4992,
5217,
1332,
19,
12,
413,
12,
413,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
88,
17,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
288,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
12,
499,
12,
5557,
12,
4119,
12,
650,
4992,
5217,
1332,
19,
12,
413,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
511,
46,
31985,
31985,
8,
277,
304,
272,
291,
423,
396,
63,
1078,
8,
267,
4931,
29,
1590,
14,
8748,
1332,
288,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
12,
499,
12,
5557,
12,
4119,
12,
650,
12,
288,
499,
12,
5557,
12,
4119,
12,
650,
12,
959,
12,
1520,
12,
4119,
12,
650,
12,
499,
12,
3144,
12,
1520,
12,
959,
4992,
5217,
1332,
19,
12,
499,
12,
841,
1826,
267,
1338,
3699,
396,
63,
1459,
1332,
19,
12,
499,
12,
841,
1724,
819,
347,
485,
396,
63,
3197,
8,
277,
12,
4931,
12,
1338,
304,
272,
1125,
63,
1328,
275,
283,
4916,
883,
440,
506,
11180,
370,
1338,
7,
272,
543,
291,
14,
10835,
8,
3393,
12,
1125,
63,
1328,
304,
489,
4931,
63,
10786,
63,
1483,
14,
479,
63,
10786,
461,
8,
4916,
29,
4916,
12,
1338,
29,
1459,
9,
272,
4931,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
1338,
63,
6199,
275,
1625,
63,
1483,
14,
6199,
8,
5717,
63,
773,
14,
1609,
708,
9,
272,
8336,
63,
411,
275,
4931,
63,
10786,
63,
1483,
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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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
] |
dpursehouse/buck
|
third-party/py/twitter-commons/src/python/twitter/common/python/interpreter.py
|
18
|
13136
|
"""
twitter.common.python support for interpreter environments.
"""
from __future__ import absolute_import
try:
from numbers import Integral
except ImportError:
Integral = (int, long)
from collections import defaultdict
import os
import re
import subprocess
import sys
from .base import maybe_requirement, maybe_requirement_list
from .compatibility import string
from .tracer import Tracer
from pkg_resources import (
find_distributions,
Distribution,
Requirement,
)
TRACER = Tracer(predicate=Tracer.env_filter('PEX_VERBOSE'),
prefix='twitter.common.python.interpreter: ')
# Determine in the most platform-compatible way possible the identity of the interpreter
# and its known packages.
ID_PY = b"""
import sys
if hasattr(sys, 'pypy_version_info'):
subversion = 'PyPy'
elif sys.platform.startswith('java'):
subversion = 'Jython'
else:
subversion = 'CPython'
print("%s %s %s %s" % (
subversion,
sys.version_info[0],
sys.version_info[1],
sys.version_info[2]))
setuptools_path = None
try:
import pkg_resources
except ImportError:
sys.exit(0)
requirements = {}
for item in sys.path:
for dist in pkg_resources.find_distributions(item):
requirements[str(dist.as_requirement())] = dist.location
for requirement_str, location in requirements.items():
rs = requirement_str.split('==', 2)
if len(rs) == 2:
print('%s %s %s' % (rs[0], rs[1], location))
"""
class PythonCapability(list):
def __init__(self, requirements=None):
super(PythonCapability, self).__init__(maybe_requirement_list(requirements or []))
class PythonIdentity(object):
class Error(Exception): pass
class InvalidError(Error): pass
class UnknownRequirement(Error): pass
# TODO(user) Support interpreter-specific versions, e.g. PyPy-2.2.1
HASHBANGS = {
'CPython': 'python%(major)d.%(minor)d',
'Jython': 'jython',
'PyPy': 'pypy',
}
@classmethod
def get_subversion(cls):
if hasattr(sys, 'pypy_version_info'):
subversion = 'PyPy'
elif sys.platform.startswith('java'):
subversion = 'Jython'
else:
subversion = 'CPython'
return subversion
@classmethod
def get(cls):
return cls(cls.get_subversion(), sys.version_info[0], sys.version_info[1], sys.version_info[2])
@classmethod
def from_id_string(cls, id_string):
values = id_string.split()
if len(values) != 4:
raise cls.InvalidError("Invalid id string: %s" % id_string)
return cls(str(values[0]), int(values[1]), int(values[2]), int(values[3]))
@classmethod
def from_path(cls, dirname):
interp, version = dirname.split('-')
major, minor, patch = version.split('.')
return cls(str(interp), int(major), int(minor), int(patch))
def __init__(self, interpreter, major, minor, patch):
for var in (major, minor, patch):
assert isinstance(var, Integral)
self._interpreter = interpreter
self._version = (major, minor, patch)
@property
def interpreter(self):
return self._interpreter
@property
def version(self):
return self._version
@property
def requirement(self):
return self.distribution.as_requirement()
@property
def distribution(self):
return Distribution(project_name=self._interpreter, version='.'.join(map(str, self._version)))
@classmethod
def parse_requirement(cls, requirement, default_interpreter='CPython'):
if isinstance(requirement, Requirement):
return requirement
elif isinstance(requirement, string):
try:
requirement = Requirement.parse(requirement)
except ValueError:
try:
requirement = Requirement.parse('%s%s' % (default_interpreter, requirement))
except ValueError:
raise ValueError('Unknown requirement string: %s' % requirement)
return requirement
else:
raise ValueError('Unknown requirement type: %r' % (requirement,))
def matches(self, requirement):
"""Given a Requirement, check if this interpreter matches."""
try:
requirement = self.parse_requirement(requirement, self._interpreter)
except ValueError as e:
raise self.UnknownRequirement(str(e))
return self.distribution in requirement
def hashbang(self):
hashbang_string = self.HASHBANGS.get(self.interpreter, 'CPython') % {
'major': self._version[0],
'minor': self._version[1],
'patch': self._version[2],
}
return '#!/usr/bin/env %s' % hashbang_string
@property
def python(self):
# return the python version in the format of the 'python' key for distributions
# specifically, '2.6', '2.7', '3.2', etc.
return '%d.%d' % (self.version[0:2])
def __str__(self):
return '%s-%s.%s.%s' % (self._interpreter,
self._version[0], self._version[1], self._version[2])
def __repr__(self):
return 'PythonIdentity(%r, %s, %s, %s)' % (
self._interpreter, self._version[0], self._version[1], self._version[2])
def __eq__(self, other):
return all([isinstance(other, PythonIdentity),
self.interpreter == other.interpreter,
self.version == other.version])
def __hash__(self):
return hash((self._interpreter, self._version))
class PythonInterpreter(object):
REGEXEN = (
re.compile(r'jython$'),
re.compile(r'python$'),
re.compile(r'python[23].[0-9]$'),
re.compile(r'pypy$'),
re.compile(r'pypy-1.[0-9]$'),
)
CACHE = {} # memoize executable => PythonInterpreter
try:
# Versions of distribute prior to the setuptools merge would automatically replace
# 'setuptools' requirements with 'distribute'. It provided the 'replacement' kwarg
# to toggle this, but it was removed post-merge.
COMPATIBLE_SETUPTOOLS = Requirement.parse('setuptools>=1.0', replacement=False)
except TypeError:
COMPATIBLE_SETUPTOOLS = Requirement.parse('setuptools>=1.0')
class Error(Exception): pass
class IdentificationError(Error): pass
class InterpreterNotFound(Error): pass
@classmethod
def get(cls):
return cls.from_binary(sys.executable)
@classmethod
def all(cls, paths=None):
if paths is None:
paths = os.getenv('PATH', '').split(':')
return cls.filter(cls.find(paths))
@classmethod
def _parse_extras(cls, output_lines):
def iter_lines():
for line in output_lines:
try:
dist_name, dist_version, location = line.split()
except ValueError:
raise cls.IdentificationError('Could not identify requirement: %s' % line)
yield ((dist_name, dist_version), location)
return dict(iter_lines())
@classmethod
def _from_binary_internal(cls, path_extras):
def iter_extras():
for item in sys.path + list(path_extras):
for dist in find_distributions(item):
if dist.version:
yield ((dist.key, dist.version), dist.location)
return cls(sys.executable, PythonIdentity.get(), dict(iter_extras()))
@classmethod
def _from_binary_external(cls, binary, path_extras):
environ = cls.sanitized_environment()
environ['PYTHONPATH'] = ':'.join(path_extras)
po = subprocess.Popen(
[binary],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
env=environ)
so, _ = po.communicate(ID_PY)
output = so.decode('utf8').splitlines()
if len(output) == 0:
raise cls.IdentificationError('Could not establish identity of %s' % binary)
identity, extras = output[0], output[1:]
return cls(
binary,
PythonIdentity.from_id_string(identity),
extras=cls._parse_extras(extras))
@classmethod
def expand_path(cls, path):
if os.path.isfile(path):
return [path]
elif os.path.isdir(path):
return [os.path.join(path, fn) for fn in os.listdir(path)]
return []
@classmethod
def from_env(cls, hashbang):
"""Resolve a PythonInterpreter as /usr/bin/env would.
:param hashbang: A string, e.g. "python3.3" representing some binary on the $PATH.
"""
paths = os.getenv('PATH', '').split(':')
for path in paths:
for fn in cls.expand_path(path):
basefile = os.path.basename(fn)
if hashbang == basefile:
try:
return cls.from_binary(fn)
except Exception as e:
TRACER.log('Could not identify %s: %s' % (fn, e))
@classmethod
def from_binary(cls, binary, path_extras=None):
path_extras = path_extras or ()
if binary not in cls.CACHE:
if binary == sys.executable:
cls.CACHE[binary] = cls._from_binary_internal(path_extras)
else:
cls.CACHE[binary] = cls._from_binary_external(binary, path_extras)
return cls.CACHE[binary]
@classmethod
def find(cls, paths):
"""
Given a list of files or directories, try to detect python interpreters amongst them.
Returns a list of PythonInterpreter objects.
"""
pythons = []
for path in paths:
for fn in cls.expand_path(path):
basefile = os.path.basename(fn)
if any(matcher.match(basefile) is not None for matcher in cls.REGEXEN):
try:
pythons.append(cls.from_binary(fn))
except Exception as e:
TRACER.log('Could not identify %s: %s' % (fn, e))
continue
return pythons
@classmethod
def filter(cls, pythons):
"""
Given a map of python interpreters in the format provided by PythonInterpreter.find(),
filter out duplicate versions and versions we would prefer not to use.
Returns a map in the same format as find.
"""
good = []
MAJOR, MINOR, SUBMINOR = range(3)
def version_filter(version):
return (version[MAJOR] == 2 and version[MINOR] >= 6 or
version[MAJOR] == 3 and version[MINOR] >= 2)
all_versions = set(interpreter.identity.version for interpreter in pythons)
good_versions = filter(version_filter, all_versions)
for version in good_versions:
# For each candidate, use the latest version we find on the filesystem.
candidates = defaultdict(list)
for interp in pythons:
if interp.identity.version == version:
candidates[interp.identity.interpreter].append(interp)
for interp_class in candidates:
candidates[interp_class].sort(
key=lambda interp: os.path.getmtime(interp.binary), reverse=True)
good.append(candidates[interp_class].pop(0))
return good
@classmethod
def sanitized_environment(cls):
# N.B. This is merely a hack because sysconfig.py on the default OS X
# installation of 2.6/2.7 breaks.
env_copy = os.environ.copy()
env_copy.pop('MACOSX_DEPLOYMENT_TARGET', None)
return env_copy
@classmethod
def replace(cls, requirement):
self = cls.get()
if self.identity.matches(requirement):
return False
for pi in cls.all():
if pi.identity.matches(requirement):
break
else:
raise cls.InterpreterNotFound('Could not find interpreter matching filter!')
os.execve(pi.binary, [pi.binary] + sys.argv, cls.sanitized_environment())
def __init__(self, binary, identity, extras=None):
"""Construct a PythonInterpreter.
You should probably PythonInterpreter.from_binary instead.
:param binary: The full path of the python binary.
:param identity: The :class:`PythonIdentity` of the PythonInterpreter.
:param extras: A mapping from (dist.key, dist.version) to dist.location
of the extras associated with this interpreter.
"""
self._binary = os.path.realpath(binary)
self._binary_stat = os.stat(self._binary)
self._extras = extras or {}
self._identity = identity
def with_extra(self, key, version, location):
extras = self._extras.copy()
extras[(key, version)] = location
return self.__class__(self._binary, self._identity, extras)
@property
def extras(self):
return self._extras.copy()
@property
def binary(self):
return self._binary
@property
def identity(self):
return self._identity
@property
def python(self):
return self._identity.python
@property
def version(self):
return self._identity.version
@property
def version_string(self):
return str(self._identity)
def satisfies(self, capability):
if not isinstance(capability, PythonCapability):
raise TypeError('Capability must be a PythonCapability, got %s' % type(capability))
return not any(self.get_location(req) is None for req in capability)
def get_location(self, req):
req = maybe_requirement(req)
for dist, location in self.extras.items():
dist_name, dist_version = dist
if req.key == dist_name and dist_version in req:
return location
def __hash__(self):
return hash(self._binary_stat)
def __eq__(self, other):
if not isinstance(other, PythonInterpreter):
return False
return self._binary_stat == other._binary_stat
def __lt__(self, other):
if not isinstance(other, PythonInterpreter):
return False
return self.version < other.version
def __repr__(self):
return '%s(%r, %r, %r)' % (self.__class__.__name__, self._binary, self._identity, self._extras)
|
apache-2.0
|
[
624,
199,
13746,
14,
2330,
14,
1548,
2291,
367,
12693,
22196,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
523,
687,
5579,
492,
23095,
199,
2590,
3545,
26,
523,
23095,
275,
334,
442,
12,
1846,
9,
199,
199,
504,
5055,
492,
10018,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
504,
1275,
1095,
492,
11703,
63,
12434,
12,
11703,
63,
12434,
63,
513,
199,
504,
1275,
15390,
492,
1059,
199,
504,
1275,
16825,
492,
12643,
2247,
199,
199,
504,
5496,
63,
4435,
492,
334,
272,
2342,
63,
5613,
12,
272,
11839,
12,
272,
25013,
12,
199,
9,
199,
199,
1766,
1348,
540,
275,
12643,
2247,
8,
14463,
29,
2437,
2247,
14,
1813,
63,
1541,
360,
48,
1438,
63,
16075,
659,
272,
2403,
534,
13746,
14,
2330,
14,
1548,
14,
20244,
26,
5320,
421,
199,
3,
14703,
315,
314,
4750,
4298,
13,
6490,
4340,
3962,
314,
8503,
402,
314,
12693,
199,
3,
436,
2399,
6040,
6117,
14,
199,
998,
63,
4521,
275,
330,
624,
199,
646,
984,
199,
199,
692,
2688,
8,
1274,
12,
283,
20233,
63,
1023,
63,
815,
735,
523,
1007,
1023,
275,
283,
2713,
2713,
7,
199,
4164,
984,
14,
3246,
14,
2460,
360,
6138,
735,
523,
1007,
1023,
275,
283,
42,
11361,
7,
199,
2836,
26,
523,
1007,
1023,
275,
283,
35,
4718,
7,
199,
199,
1361,
3647,
83,
450,
83,
450,
83,
450,
83,
2,
450,
334,
523,
1007,
1023,
12,
523,
984,
14,
1023,
63,
815,
59,
16,
467,
523,
984,
14,
1023,
63,
815,
59,
17,
467,
523,
984,
14,
1023,
63,
815,
59,
18,
2459,
199,
199,
13623,
63,
515,
275,
488,
199,
893,
26,
523,
492,
5496,
63,
4435,
199,
2590,
3545,
26,
523,
984,
14,
2224,
8,
16,
9,
199,
199,
7538,
275,
1052,
199,
509,
1242,
315,
984,
14,
515,
26,
523,
367,
2917,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
1053,
304,
272,
9760,
59,
495,
8,
2686,
14,
305,
63,
12434,
24821,
275,
2917,
14,
1985,
199,
199,
509,
10685,
63,
495,
12,
2909,
315,
9760,
14,
1744,
837,
523,
10717,
275,
10685,
63,
495,
14,
1294,
360,
389,
297,
499,
9,
523,
340,
822,
8,
2393,
9,
508,
499,
26,
272,
870,
3508,
83,
450,
83,
450,
83,
7,
450,
334,
2393,
59,
16,
467,
10717,
59,
17,
467,
2909,
430,
199,
624,
421,
199,
533,
2018,
24512,
8,
513,
304,
523,
347,
636,
826,
721,
277,
12,
9760,
29,
403,
304,
272,
1613,
8,
4718,
24512,
12,
291,
2843,
826,
721,
11853,
63,
12434,
63,
513,
8,
7538,
503,
15927,
421,
199,
533,
2018,
10193,
8,
785,
304,
523,
1021,
4520,
8,
1726,
304,
986,
523,
1021,
6378,
547,
8,
547,
304,
986,
523,
1021,
14831,
17947,
8,
547,
304,
986,
819,
327,
3254,
8,
751,
9,
221,
12502,
12693,
13,
6100,
5459,
12,
325,
14,
71,
14,
1611,
2713,
13,
18,
14,
18,
14,
17,
523,
7509,
25262,
3986,
51,
275,
469,
272,
283,
35,
4718,
356,
283,
1548,
2840,
8452,
9,
68,
31706,
11067,
9,
68,
297,
272,
283,
42,
11361,
356,
283,
27179,
297,
272,
283,
2713,
2713,
356,
283,
20233,
297,
523,
789,
819,
768,
3744,
523,
347,
664,
63,
954,
1023,
8,
1886,
304,
272,
340,
2688,
8,
1274,
12,
283,
20233,
63,
1023,
63,
815,
735,
489,
1007,
1023,
275,
283,
2713,
2713,
7,
272,
916,
984,
14,
3246,
14,
2460,
360,
6138,
735,
489,
1007,
1023,
275,
283,
42,
11361,
7,
272,
587,
26,
489,
1007,
1023,
275,
283,
35,
4718,
7,
272,
372,
1007,
1023,
819,
768,
3744,
523,
347,
664,
8,
1886,
304,
272,
372,
843,
8,
1886,
14,
362,
63,
954,
1023,
1062,
984,
14,
1023,
63,
815,
59,
16,
467,
984,
14,
1023,
63,
815,
59,
17,
467,
984,
14,
1023,
63,
815,
59,
18,
566,
819,
768,
3744,
523,
347,
687,
63,
344,
63,
875,
8,
1886,
12,
1305,
63,
875,
304,
272,
1338,
275,
1305,
63,
875,
14,
1294,
342,
272,
340,
822,
8,
1459,
9,
1137,
841,
26,
489,
746,
843,
14,
3364,
547,
480,
3364,
1305,
1059,
26,
450,
83,
2,
450,
1305,
63,
875,
9,
272,
372,
843,
8,
495,
8,
1459,
59,
16,
2522,
1109,
8,
1459,
59,
17,
2522,
1109,
8,
1459,
59,
18,
2522,
1109,
8,
1459,
59,
19,
2459,
819,
768,
3744,
523,
347,
687,
63,
515,
8,
1886,
12,
9017,
304,
272,
23716,
12,
1015,
275,
9017,
14,
1294,
21950,
272,
12160,
12,
12612,
12,
3371,
275,
1015,
14,
1294,
7563,
272,
372,
843,
8,
495,
8,
14252,
395,
1109,
8,
8452,
395,
1109,
8,
11067,
395,
1109,
8,
2068,
430,
819,
347,
636,
826,
721,
277,
12,
12693,
12,
12160,
12,
12612,
12,
3371,
304,
272,
367,
2729,
315,
334,
8452,
12,
12612,
12,
3371,
304,
489,
702,
1228,
8,
1391,
12,
23095,
9,
272,
291,
423,
20244,
275,
12693,
272,
291,
423,
1023,
275,
334,
8452,
12,
12612,
12,
3371,
9,
819,
768,
1829,
523,
347,
12693,
8,
277,
304,
272,
372,
291,
423,
20244,
819,
768,
1829,
523,
347,
1015,
8,
277,
304,
272,
372,
291,
423,
1023,
819,
768,
1829,
523,
347,
10685,
8,
277,
304,
272,
372,
291,
14,
4972,
14,
305,
63,
12434,
342,
819,
768,
1829,
523,
347,
4084,
8,
277,
304,
272,
372,
11839,
8,
1715,
63,
354,
29,
277,
423,
20244,
12,
1015,
15637,
1370,
904,
8,
1130,
8,
495,
12,
291,
423,
1023,
1724,
819,
768,
3744,
523,
347,
2198,
63,
12434,
8,
1886,
12,
10685,
12,
849,
63,
20244,
534,
35,
4718,
735,
272,
340,
1228,
8,
12434,
12,
25013,
304,
489,
372,
10685,
272,
916,
1228,
8,
12434,
12,
1059,
304,
489,
862,
26,
267,
10685,
275,
25013,
14,
1122,
8,
12434,
9,
489,
871,
1722,
26,
267,
862,
26,
881,
10685,
275,
25013,
14,
1122,
3508,
83,
5,
83,
7,
450,
334,
885,
63,
20244,
12,
10685,
430,
267,
871,
1722,
26,
881,
746,
1722,
360,
5912,
10685,
1059,
26,
450,
83,
7,
450,
10685,
9,
489,
372,
10685,
272,
587,
26,
489,
746,
1722,
360,
5912,
10685,
730,
26
] |
[
199,
13746,
14,
2330,
14,
1548,
2291,
367,
12693,
22196,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
893,
26,
523,
687,
5579,
492,
23095,
199,
2590,
3545,
26,
523,
23095,
275,
334,
442,
12,
1846,
9,
199,
199,
504,
5055,
492,
10018,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
504,
1275,
1095,
492,
11703,
63,
12434,
12,
11703,
63,
12434,
63,
513,
199,
504,
1275,
15390,
492,
1059,
199,
504,
1275,
16825,
492,
12643,
2247,
199,
199,
504,
5496,
63,
4435,
492,
334,
272,
2342,
63,
5613,
12,
272,
11839,
12,
272,
25013,
12,
199,
9,
199,
199,
1766,
1348,
540,
275,
12643,
2247,
8,
14463,
29,
2437,
2247,
14,
1813,
63,
1541,
360,
48,
1438,
63,
16075,
659,
272,
2403,
534,
13746,
14,
2330,
14,
1548,
14,
20244,
26,
5320,
421,
199,
3,
14703,
315,
314,
4750,
4298,
13,
6490,
4340,
3962,
314,
8503,
402,
314,
12693,
199,
3,
436,
2399,
6040,
6117,
14,
199,
998,
63,
4521,
275,
330,
624,
199,
646,
984,
199,
199,
692,
2688,
8,
1274,
12,
283,
20233,
63,
1023,
63,
815,
735,
523,
1007,
1023,
275,
283,
2713,
2713,
7,
199,
4164,
984,
14,
3246,
14,
2460,
360,
6138,
735,
523,
1007,
1023,
275,
283,
42,
11361,
7,
199,
2836,
26,
523,
1007,
1023,
275,
283,
35,
4718,
7,
199,
199,
1361,
3647,
83,
450,
83,
450,
83,
450,
83,
2,
450,
334,
523,
1007,
1023,
12,
523,
984,
14,
1023,
63,
815,
59,
16,
467,
523,
984,
14,
1023,
63,
815,
59,
17,
467,
523,
984,
14,
1023,
63,
815,
59,
18,
2459,
199,
199,
13623,
63,
515,
275,
488,
199,
893,
26,
523,
492,
5496,
63,
4435,
199,
2590,
3545,
26,
523,
984,
14,
2224,
8,
16,
9,
199,
199,
7538,
275,
1052,
199,
509,
1242,
315,
984,
14,
515,
26,
523,
367,
2917,
315,
5496,
63,
4435,
14,
1623,
63,
5613,
8,
1053,
304,
272,
9760,
59,
495,
8,
2686,
14,
305,
63,
12434,
24821,
275,
2917,
14,
1985,
199,
199,
509,
10685,
63,
495,
12,
2909,
315,
9760,
14,
1744,
837,
523,
10717,
275,
10685,
63,
495,
14,
1294,
360,
389,
297,
499,
9,
523,
340,
822,
8,
2393,
9,
508,
499,
26,
272,
870,
3508,
83,
450,
83,
450,
83,
7,
450,
334,
2393,
59,
16,
467,
10717,
59,
17,
467,
2909,
430,
199,
624,
421,
199,
533,
2018,
24512,
8,
513,
304,
523,
347,
636,
826,
721,
277,
12,
9760,
29,
403,
304,
272,
1613,
8,
4718,
24512,
12,
291,
2843,
826,
721,
11853,
63,
12434,
63,
513,
8,
7538,
503,
15927,
421,
199,
533,
2018,
10193,
8,
785,
304,
523,
1021,
4520,
8,
1726,
304,
986,
523,
1021,
6378,
547,
8,
547,
304,
986,
523,
1021,
14831,
17947,
8,
547,
304,
986,
819,
327,
3254,
8,
751,
9,
221,
12502,
12693,
13,
6100,
5459,
12,
325,
14,
71,
14,
1611,
2713,
13,
18,
14,
18,
14,
17,
523,
7509,
25262,
3986,
51,
275,
469,
272,
283,
35,
4718,
356,
283,
1548,
2840,
8452,
9,
68,
31706,
11067,
9,
68,
297,
272,
283,
42,
11361,
356,
283,
27179,
297,
272,
283,
2713,
2713,
356,
283,
20233,
297,
523,
789,
819,
768,
3744,
523,
347,
664,
63,
954,
1023,
8,
1886,
304,
272,
340,
2688,
8,
1274,
12,
283,
20233,
63,
1023,
63,
815,
735,
489,
1007,
1023,
275,
283,
2713,
2713,
7,
272,
916,
984,
14,
3246,
14,
2460,
360,
6138,
735,
489,
1007,
1023,
275,
283,
42,
11361,
7,
272,
587,
26,
489,
1007,
1023,
275,
283,
35,
4718,
7,
272,
372,
1007,
1023,
819,
768,
3744,
523,
347,
664,
8,
1886,
304,
272,
372,
843,
8,
1886,
14,
362,
63,
954,
1023,
1062,
984,
14,
1023,
63,
815,
59,
16,
467,
984,
14,
1023,
63,
815,
59,
17,
467,
984,
14,
1023,
63,
815,
59,
18,
566,
819,
768,
3744,
523,
347,
687,
63,
344,
63,
875,
8,
1886,
12,
1305,
63,
875,
304,
272,
1338,
275,
1305,
63,
875,
14,
1294,
342,
272,
340,
822,
8,
1459,
9,
1137,
841,
26,
489,
746,
843,
14,
3364,
547,
480,
3364,
1305,
1059,
26,
450,
83,
2,
450,
1305,
63,
875,
9,
272,
372,
843,
8,
495,
8,
1459,
59,
16,
2522,
1109,
8,
1459,
59,
17,
2522,
1109,
8,
1459,
59,
18,
2522,
1109,
8,
1459,
59,
19,
2459,
819,
768,
3744,
523,
347,
687,
63,
515,
8,
1886,
12,
9017,
304,
272,
23716,
12,
1015,
275,
9017,
14,
1294,
21950,
272,
12160,
12,
12612,
12,
3371,
275,
1015,
14,
1294,
7563,
272,
372,
843,
8,
495,
8,
14252,
395,
1109,
8,
8452,
395,
1109,
8,
11067,
395,
1109,
8,
2068,
430,
819,
347,
636,
826,
721,
277,
12,
12693,
12,
12160,
12,
12612,
12,
3371,
304,
272,
367,
2729,
315,
334,
8452,
12,
12612,
12,
3371,
304,
489,
702,
1228,
8,
1391,
12,
23095,
9,
272,
291,
423,
20244,
275,
12693,
272,
291,
423,
1023,
275,
334,
8452,
12,
12612,
12,
3371,
9,
819,
768,
1829,
523,
347,
12693,
8,
277,
304,
272,
372,
291,
423,
20244,
819,
768,
1829,
523,
347,
1015,
8,
277,
304,
272,
372,
291,
423,
1023,
819,
768,
1829,
523,
347,
10685,
8,
277,
304,
272,
372,
291,
14,
4972,
14,
305,
63,
12434,
342,
819,
768,
1829,
523,
347,
4084,
8,
277,
304,
272,
372,
11839,
8,
1715,
63,
354,
29,
277,
423,
20244,
12,
1015,
15637,
1370,
904,
8,
1130,
8,
495,
12,
291,
423,
1023,
1724,
819,
768,
3744,
523,
347,
2198,
63,
12434,
8,
1886,
12,
10685,
12,
849,
63,
20244,
534,
35,
4718,
735,
272,
340,
1228,
8,
12434,
12,
25013,
304,
489,
372,
10685,
272,
916,
1228,
8,
12434,
12,
1059,
304,
489,
862,
26,
267,
10685,
275,
25013,
14,
1122,
8,
12434,
9,
489,
871,
1722,
26,
267,
862,
26,
881,
10685,
275,
25013,
14,
1122,
3508,
83,
5,
83,
7,
450,
334,
885,
63,
20244,
12,
10685,
430,
267,
871,
1722,
26,
881,
746,
1722,
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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
] |
MSusik/invenio
|
invenio/modules/sequencegenerator/models.py
|
4
|
1370
|
# -*- coding: utf-8 -*-
#
## This file is part of Invenio.
## Copyright (C) 2012, 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.
"""
SeqUtils database models.
"""
from invenio.ext.sqlalchemy import db
class SeqSTORE(db.Model):
"""Represents a SeqSTORE record."""
__tablename__ = 'seqSTORE'
id = db.Column(
db.Integer(15, unsigned=True),
primary_key=True, nullable=False,
autoincrement=True
)
seq_name = db.Column(db.String(15))
seq_value = db.Column(db.String(20))
__table_args__ = (db.Index('seq_name_value', seq_name, seq_value,
unique=True),
db.Model.__table_args__)
__all__ = ['SeqSTORE']
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6029,
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,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
11205,
7535,
3050,
1709,
14,
199,
624,
199,
199,
504,
13640,
14,
832,
14,
14536,
492,
1592,
421,
199,
533,
28534,
16169,
8,
697,
14,
1685,
304,
272,
408,
18089,
282,
28534,
16169,
2777,
1041,
272,
636,
10983,
363,
275,
283,
3610,
16169,
7,
339,
1305,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
8,
1046,
12,
7381,
29,
549,
395,
267,
5062,
63,
498,
29,
549,
12,
7854,
29,
797,
12,
267,
32497,
29,
549,
272,
776,
272,
5412,
63,
354,
275,
1592,
14,
4547,
8,
697,
14,
1558,
8,
1046,
430,
272,
5412,
63,
585,
275,
1592,
14,
4547,
8,
697,
14,
1558,
8,
1165,
430,
339,
636,
1224,
63,
589,
363,
275,
334,
697,
14,
2681,
360,
3610,
63,
354,
63,
585,
297,
5412,
63,
354,
12,
5412,
63,
585,
12,
3044,
3747,
29,
549,
395,
1993,
1592,
14,
1685,
855,
1224,
63,
589,
3368,
199,
199,
363,
452,
363,
275,
788,
11205,
16169,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6029,
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,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
199,
11205,
7535,
3050,
1709,
14,
199,
624,
199,
199,
504,
13640,
14,
832,
14,
14536,
492,
1592,
421,
199,
533,
28534,
16169,
8,
697,
14,
1685,
304,
272,
408,
18089,
282,
28534,
16169,
2777,
1041,
272,
636,
10983,
363,
275,
283,
3610,
16169,
7,
339,
1305,
275,
1592,
14,
4547,
8,
267,
1592,
14,
2674,
8,
1046,
12,
7381,
29,
549,
395,
267,
5062,
63,
498,
29,
549,
12,
7854,
29,
797,
12,
267,
32497,
29,
549,
272,
776,
272,
5412,
63,
354,
275,
1592,
14,
4547,
8,
697,
14,
1558,
8,
1046,
430,
272,
5412,
63,
585,
275,
1592,
14,
4547,
8,
697,
14,
1558,
8,
1165,
430,
339,
636,
1224,
63,
589,
363,
275,
334,
697,
14,
2681,
360,
3610,
63,
354,
63,
585,
297,
5412,
63,
354,
12,
5412,
63,
585,
12,
3044,
3747,
29,
549,
395,
1993,
1592,
14,
1685,
855,
1224,
63,
589,
3368,
199,
199,
363,
452,
363,
275,
788,
11205,
16169,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
cjdelisle/cjdns
|
node_build/dependencies/libuv/build/gyp/test/defines-escaping/gyptest-defines-escaping.py
|
350
|
4737
|
#!/usr/bin/env python
# Copyright (c) 2010 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Verifies build of an executable with C++ define specified by a gyp define using
various special characters such as quotes, commas, etc.
"""
import os
import TestGyp
test = TestGyp.TestGyp()
# Tests string literals, percents, and backslash escapes.
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s\n' """
r"""test_args='"Simple test of %s with a literal"'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.build('defines-escaping.gyp')
expect = """
Simple test of %s with a literal
"""
test.run_built_executable('defines_escaping', stdout=expect)
# Test multiple comma-and-space-separated string literals.
try:
os.environ['GYP_DEFINES'] = \
r"""test_format='\n%s and %s\n' test_args='"foo", "bar"'"""
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = """
foo and bar
"""
test.run_built_executable('defines_escaping', stdout=expect)
# Test string literals containing quotes.
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s %s %s %s %s\n' """
r"""test_args='"\"These,\"","""
r""" "\"words,\"","""
r""" "\"are,\"","""
r""" "\"in,\"","""
r""" "\"quotes.\""'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = """
"These," "words," "are," "in," "quotes."
"""
test.run_built_executable('defines_escaping', stdout=expect)
# Test string literals containing single quotes.
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s %s %s %s %s\n' """
r"""test_args="\"'These,'\","""
r""" \"'words,'\","""
r""" \"'are,'\","""
r""" \"'in,'\","""
r""" \"'quotes.'\"" """)
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = """
'These,' 'words,' 'are,' 'in,' 'quotes.'
"""
test.run_built_executable('defines_escaping', stdout=expect)
# Test string literals containing different numbers of backslashes before quotes
# (to exercise Windows' quoting behaviour).
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s\n%s\n%s\n' """
r"""test_args='"\\\"1 visible slash\\\"","""
r""" "\\\\\"2 visible slashes\\\\\"","""
r""" "\\\\\\\"3 visible slashes\\\\\\\""'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = r"""
\"1 visible slash\"
\\"2 visible slashes\\"
\\\"3 visible slashes\\\"
"""
test.run_built_executable('defines_escaping', stdout=expect)
# Test that various scary sequences are passed unfettered.
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s\n' """
r"""test_args='"$foo, " `foo`;"'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = """
$foo, " `foo`;
"""
test.run_built_executable('defines_escaping', stdout=expect)
# VisualStudio 2010 can't handle passing %PATH%
if not (test.format == 'msvs' and test.uses_msbuild):
try:
os.environ['GYP_DEFINES'] = (
"""test_format='%s' """
"""test_args='"%PATH%"'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = "%PATH%"
test.run_built_executable('defines_escaping', stdout=expect)
# Test commas and semi-colons preceded by backslashes (to exercise Windows'
# quoting behaviour).
try:
os.environ['GYP_DEFINES'] = (
r"""test_format='\n%s\n%s\n' """
r"""test_args='"\\, \\\\;","""
# Same thing again, but enclosed in visible quotes.
r""" "\"\\, \\\\;\""'""")
test.run_gyp('defines-escaping.gyp')
finally:
del os.environ['GYP_DEFINES']
test.sleep()
test.touch('defines-escaping.c')
test.build('defines-escaping.gyp')
expect = r"""
\, \\;
"\, \\;"
"""
test.run_built_executable('defines_escaping', stdout=expect)
# We deliberately do not test having an odd number of quotes in a string
# literal because that isn't feasible in MSVS.
test.pass_test()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
1900,
402,
376,
7286,
543,
445,
4176,
5627,
2013,
701,
282,
4902,
5627,
1808,
199,
3808,
1785,
4539,
4110,
4066,
465,
9344,
12,
24476,
12,
5423,
14,
199,
624,
199,
199,
646,
747,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
342,
199,
199,
3,
6496,
1059,
18041,
12,
8878,
83,
12,
436,
13831,
24644,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
2,
3184,
511,
402,
450,
83,
543,
282,
8785,
4507,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
3184,
511,
402,
450,
83,
543,
282,
8785,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
3663,
10029,
13,
460,
13,
2638,
13,
12794,
1059,
18041,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
971,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
436,
450,
83,
60,
78,
7,
511,
63,
589,
534,
2,
1421,
401,
298,
1700,
4507,
624,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
1421,
436,
4681,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
9344,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
3212,
2,
20676,
4202,
5151,
624,
355,
519,
624,
30768,
3148,
4202,
5151,
624,
355,
519,
624,
30768,
1530,
4202,
5151,
624,
355,
519,
624,
30768,
262,
4202,
5151,
624,
355,
519,
624,
30768,
14005,
3134,
341,
7,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
2,
20676,
4589,
298,
3148,
4589,
298,
1530,
4589,
298,
262,
4589,
298,
14005,
2122,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
2849,
9344,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
628,
4451,
7,
20676,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
3148,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
1530,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
262,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
14005,
14,
1154,
341,
7857,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
7,
20676,
2584,
283,
3148,
2584,
283,
1530,
2584,
283,
262,
2584,
283,
14005,
3530,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
3365,
5579,
402,
23396,
2544,
9344,
199,
3,
334,
475,
26511,
5417,
7,
18593,
13942,
680,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
5,
83,
60,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
22996,
4451,
17,
8917,
14457,
9780,
5151,
624,
355,
519,
624,
298,
8712,
4451,
18,
8917,
20275,
8712,
60,
5151,
624,
355,
519,
624,
298,
8712,
1103,
4451,
19,
8917,
20275,
8712,
9780,
341,
7,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
519,
624,
199,
4451,
17,
8917,
14457,
4451,
199,
15022,
18,
8917,
20275,
15022,
199,
1103,
4451,
19,
8917,
20275,
1103,
4451,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
626,
7750,
4061,
695,
8013,
787,
3032,
625,
70,
386,
3014,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
2,
4,
1421,
12,
1253,
5184,
27,
658,
1421,
64,
27,
4507,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1898,
334,
67,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
21168,
1900,
402,
376,
7286,
543,
445,
4176,
5627,
2013,
701,
282,
4902,
5627,
1808,
199,
3808,
1785,
4539,
4110,
4066,
465,
9344,
12,
24476,
12,
5423,
14,
199,
624,
199,
199,
646,
747,
199,
646,
25688,
199,
199,
396,
275,
25688,
14,
774,
13899,
342,
199,
199,
3,
6496,
1059,
18041,
12,
8878,
83,
12,
436,
13831,
24644,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
2,
3184,
511,
402,
450,
83,
543,
282,
8785,
4507,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
3184,
511,
402,
450,
83,
543,
282,
8785,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
3663,
10029,
13,
460,
13,
2638,
13,
12794,
1059,
18041,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
971,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
436,
450,
83,
60,
78,
7,
511,
63,
589,
534,
2,
1421,
401,
298,
1700,
4507,
624,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
1421,
436,
4681,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
9344,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
3212,
2,
20676,
4202,
5151,
624,
355,
519,
624,
30768,
3148,
4202,
5151,
624,
355,
519,
624,
30768,
1530,
4202,
5151,
624,
355,
519,
624,
30768,
262,
4202,
5151,
624,
355,
519,
624,
30768,
14005,
3134,
341,
7,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
2,
20676,
4589,
298,
3148,
4589,
298,
1530,
4589,
298,
262,
4589,
298,
14005,
2122,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
2849,
9344,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
450,
83,
450,
83,
450,
83,
450,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
628,
4451,
7,
20676,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
3148,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
1530,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
262,
12,
1154,
401,
624,
355,
519,
624,
971,
4507,
14005,
14,
1154,
341,
7857,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
408,
199,
7,
20676,
2584,
283,
3148,
2584,
283,
1530,
2584,
283,
262,
2584,
283,
14005,
3530,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
1059,
18041,
3035,
3365,
5579,
402,
23396,
2544,
9344,
199,
3,
334,
475,
26511,
5417,
7,
18593,
13942,
680,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
5,
83,
60,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
22996,
4451,
17,
8917,
14457,
9780,
5151,
624,
355,
519,
624,
298,
8712,
4451,
18,
8917,
20275,
8712,
60,
5151,
624,
355,
519,
624,
298,
8712,
1103,
4451,
19,
8917,
20275,
8712,
9780,
341,
7,
6141,
523,
511,
14,
1065,
63,
6179,
360,
14334,
13,
26306,
14,
6179,
358,
199,
15172,
26,
523,
2150,
747,
14,
2314,
459,
14884,
63,
27196,
418,
199,
199,
396,
14,
4532,
342,
199,
396,
14,
12376,
360,
14334,
13,
26306,
14,
67,
358,
199,
396,
14,
1506,
360,
14334,
13,
26306,
14,
6179,
358,
199,
199,
4921,
275,
519,
624,
199,
4451,
17,
8917,
14457,
4451,
199,
15022,
18,
8917,
20275,
15022,
199,
1103,
4451,
19,
8917,
20275,
1103,
4451,
199,
624,
199,
396,
14,
1065,
63,
11730,
63,
5904,
360,
14334,
63,
26306,
297,
3839,
29,
4921,
9,
421,
199,
3,
1379,
626,
7750,
4061,
695,
8013,
787,
3032,
625,
70,
386,
3014,
14,
199,
893,
26,
523,
747,
14,
2314,
459,
14884,
63,
27196,
418,
275,
334,
489,
519,
624,
396,
63,
908,
17115,
78,
5,
83,
60,
78,
7,
408,
489,
519,
624,
396,
63,
589,
534,
2,
4,
1421,
12,
1253,
5184,
27,
658,
1421,
64,
27,
4507,
6141,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
elliott10/decaf-multiOS
|
scripts/ordereddict.py
|
1047
|
4094
|
# Copyright (c) 2009 Raymond Hettinger
#
# 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.
from UserDict import DictMixin
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
try:
self.__end
except AttributeError:
self.clear()
self.update(*args, **kwds)
def clear(self):
self.__end = end = []
end += [None, end, end] # sentinel node for doubly linked list
self.__map = {} # key --> [key, prev, next]
dict.clear(self)
def __setitem__(self, key, value):
if key not in self:
end = self.__end
curr = end[1]
curr[2] = end[1] = self.__map[key] = [key, curr, end]
dict.__setitem__(self, key, value)
def __delitem__(self, key):
dict.__delitem__(self, key)
key, prev, next = self.__map.pop(key)
prev[2] = next
next[1] = prev
def __iter__(self):
end = self.__end
curr = end[2]
while curr is not end:
yield curr[0]
curr = curr[2]
def __reversed__(self):
end = self.__end
curr = end[1]
while curr is not end:
yield curr[0]
curr = curr[1]
def popitem(self, last=True):
if not self:
raise KeyError('dictionary is empty')
if last:
key = reversed(self).next()
else:
key = iter(self).next()
value = self.pop(key)
return key, value
def __reduce__(self):
items = [[k, self[k]] for k in self]
tmp = self.__map, self.__end
del self.__map, self.__end
inst_dict = vars(self).copy()
self.__map, self.__end = tmp
if inst_dict:
return (self.__class__, (items,), inst_dict)
return self.__class__, (items,)
def keys(self):
return list(self)
setdefault = DictMixin.setdefault
update = DictMixin.update
pop = DictMixin.pop
values = DictMixin.values
items = DictMixin.items
iterkeys = DictMixin.iterkeys
itervalues = DictMixin.itervalues
iteritems = DictMixin.iteritems
def __repr__(self):
if not self:
return '%s()' % (self.__class__.__name__,)
return '%s(%r)' % (self.__class__.__name__, self.items())
def copy(self):
return self.__class__(self)
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
for key in iterable:
d[key] = value
return d
def __eq__(self, other):
if isinstance(other, OrderedDict):
if len(self) != len(other):
return False
for p, q in zip(self.items(), other.items()):
if p != q:
return False
return True
return dict.__eq__(self, other)
def __ne__(self, other):
return not self == other
|
gpl-2.0
|
[
3,
1898,
334,
67,
9,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
199,
3,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
199,
3,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
199,
3,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
199,
3,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
199,
3,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
258,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
3,
258,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
258,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
258,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
199,
3,
258,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
258,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
199,
3,
258,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
258,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
258,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
258,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
504,
32241,
492,
7448,
4256,
199,
199,
533,
8773,
8,
807,
12,
7448,
4256,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
2062,
737,
4750,
413,
2368,
12,
4788,
450,
68,
7,
450,
822,
8,
589,
430,
267,
862,
26,
288,
291,
855,
500,
267,
871,
4281,
26,
288,
291,
14,
3584,
342,
267,
291,
14,
873,
2031,
589,
12,
1011,
10340,
9,
339,
347,
5436,
8,
277,
304,
267,
291,
855,
500,
275,
1284,
275,
942,
267,
1284,
847,
359,
403,
12,
1284,
12,
1284,
61,
260,
327,
13792,
1031,
367,
28584,
590,
10632,
769,
267,
291,
855,
1130,
275,
1052,
463,
327,
790,
10541,
359,
498,
12,
5071,
12,
2163,
61,
267,
1211,
14,
3584,
8,
277,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
440,
315,
291,
26,
288,
1284,
275,
291,
855,
500,
288,
8230,
275,
1284,
59,
17,
61,
288,
8230,
59,
18,
61,
275,
1284,
59,
17,
61,
275,
291,
855,
1130,
59,
498,
61,
275,
359,
498,
12,
8230,
12,
1284,
61,
267,
1211,
855,
8617,
721,
277,
12,
790,
12,
574,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
1211,
855,
13228,
721,
277,
12,
790,
9,
267,
790,
12,
5071,
12,
2163,
275,
291,
855,
1130,
14,
1935,
8,
498,
9,
267,
5071,
59,
18,
61,
275,
2163,
267,
2163,
59,
17,
61,
275,
5071,
339,
347,
636,
1661,
721,
277,
304,
267,
1284,
275,
291,
855,
500,
267,
8230,
275,
1284,
59,
18,
61,
267,
1830,
8230,
365,
440,
1284,
26,
288,
1995,
8230,
59,
16,
61,
288,
8230,
275,
8230,
59,
18,
61,
339,
347,
636,
13501,
721,
277,
304,
267,
1284,
275,
291,
855,
500,
267,
8230,
275,
1284,
59,
17,
61,
267,
1830,
8230,
365,
440,
1284,
26,
288,
1995,
8230,
59,
16,
61,
288,
8230,
275,
8230,
59,
17,
61,
339,
347,
4560,
1053,
8,
277,
12,
2061,
29,
549,
304,
267,
340,
440,
291,
26,
288,
746,
4067,
360,
9086,
365,
2701,
358,
267,
340,
2061,
26,
288,
790,
275,
10822,
8,
277,
680,
2184,
342,
267,
587,
26,
288,
790,
275,
2740,
8,
277,
680,
2184,
342,
267,
574,
275,
291,
14,
1935,
8,
498,
9,
267,
372,
790,
12,
574,
339,
347,
636,
5270,
721,
277,
304,
267,
2974,
275,
3474,
75,
12,
291,
59,
75,
2677,
367,
1022,
315,
291,
61,
267,
3529,
275,
291,
855,
1130,
12,
291,
855,
500,
267,
2150,
291,
855,
1130,
12,
291,
855,
500,
267,
2727,
63,
807,
275,
6802,
8,
277,
680,
1574,
342,
267,
291,
855,
1130,
12,
291,
855,
500,
275,
3529,
267,
340,
2727,
63,
807,
26,
288,
372,
334,
277,
855,
533,
3108,
334,
1744,
4706,
2727,
63,
807,
9,
267,
372,
291,
855,
533,
3108,
334,
1744,
4258,
339,
347,
2883,
8,
277,
304,
267,
372,
769,
8,
277,
9,
339,
29408,
275,
7448,
4256,
14,
5486,
272,
1678,
275,
7448,
4256,
14,
873,
272,
4560,
275,
7448,
4256,
14,
1935,
272,
1338,
275,
7448,
4256,
14,
1459,
272,
2974,
275,
7448,
4256,
14,
1744,
272,
25706,
275,
7448,
4256,
14,
16007,
272,
24451,
275,
7448,
4256,
14,
13012,
272,
10849,
275,
7448,
4256,
14,
4611,
339,
347,
636,
2722,
721,
277,
304,
267,
340,
440,
291,
26,
288,
372,
1543,
83,
11716,
450,
334,
277,
855,
533,
4914,
354,
3108,
9,
267,
372,
1543,
83,
4042,
82,
3171,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
1744,
1012,
339,
347,
1331,
8,
277,
304,
267,
372,
291,
855,
533,
721,
277,
9,
339,
768,
3744,
272,
347,
687,
1612,
8,
1886,
12,
6076,
12,
574,
29,
403,
304,
267,
366,
275,
843,
342,
267,
367,
790,
315,
6076,
26,
288,
366,
59,
498,
61,
275,
574,
267,
372,
366,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
8773,
304,
288,
340,
822,
8,
277,
9,
1137,
822,
8,
1848,
304,
355,
372,
756,
288,
367,
299,
12,
1894,
315,
221,
3482,
8,
277,
14,
1744,
1062,
1163,
14,
1744,
5109,
355,
340,
299,
1137,
1894,
26,
490,
372,
756,
288,
372,
715,
267,
372,
1211,
855,
4077,
721,
277,
12,
1163,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
291,
508,
1163,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8937,
30703,
2106,
68,
869,
386,
1337,
281,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
199,
3,
12408,
282,
1331,
402,
642,
2032,
436,
4568,
3794,
1584,
199,
3,
334,
1589,
298,
10337,
1288,
370,
7962,
315,
314,
2290,
1928,
10588,
12,
199,
3,
5893,
1928,
12305,
314,
4481,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
199,
3,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
199,
3,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
199,
3,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
258,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
199,
3,
258,
5120,
315,
1006,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
258,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
199,
3,
258,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
199,
3,
258,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
258,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
199,
3,
258,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
199,
3,
258,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
199,
3,
258,
4442,
12,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
199,
3,
258,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
504,
32241,
492,
7448,
4256,
199,
199,
533,
8773,
8,
807,
12,
7448,
4256,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
340,
822,
8,
589,
9,
690,
413,
26,
288,
746,
3146,
360,
2062,
737,
4750,
413,
2368,
12,
4788,
450,
68,
7,
450,
822,
8,
589,
430,
267,
862,
26,
288,
291,
855,
500,
267,
871,
4281,
26,
288,
291,
14,
3584,
342,
267,
291,
14,
873,
2031,
589,
12,
1011,
10340,
9,
339,
347,
5436,
8,
277,
304,
267,
291,
855,
500,
275,
1284,
275,
942,
267,
1284,
847,
359,
403,
12,
1284,
12,
1284,
61,
260,
327,
13792,
1031,
367,
28584,
590,
10632,
769,
267,
291,
855,
1130,
275,
1052,
463,
327,
790,
10541,
359,
498,
12,
5071,
12,
2163,
61,
267,
1211,
14,
3584,
8,
277,
9,
339,
347,
636,
8617,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
440,
315,
291,
26,
288,
1284,
275,
291,
855,
500,
288,
8230,
275,
1284,
59,
17,
61,
288,
8230,
59,
18,
61,
275,
1284,
59,
17,
61,
275,
291,
855,
1130,
59,
498,
61,
275,
359,
498,
12,
8230,
12,
1284,
61,
267,
1211,
855,
8617,
721,
277,
12,
790,
12,
574,
9,
339,
347,
636,
13228,
721,
277,
12,
790,
304,
267,
1211,
855,
13228,
721,
277,
12,
790,
9,
267,
790,
12,
5071,
12,
2163,
275,
291,
855,
1130,
14,
1935,
8,
498,
9,
267,
5071,
59,
18,
61,
275,
2163,
267,
2163,
59,
17,
61,
275,
5071,
339,
347,
636,
1661,
721,
277,
304,
267,
1284,
275,
291,
855,
500,
267,
8230,
275,
1284,
59,
18,
61,
267,
1830,
8230,
365,
440,
1284,
26,
288,
1995,
8230,
59,
16,
61,
288,
8230,
275,
8230,
59,
18,
61,
339,
347,
636,
13501,
721,
277,
304,
267,
1284,
275,
291,
855,
500,
267,
8230,
275,
1284,
59,
17,
61,
267,
1830,
8230,
365,
440,
1284,
26,
288,
1995,
8230,
59,
16,
61,
288,
8230,
275,
8230,
59,
17,
61,
339,
347,
4560,
1053,
8,
277,
12,
2061,
29,
549,
304,
267,
340,
440,
291,
26,
288,
746,
4067,
360,
9086,
365,
2701,
358,
267,
340,
2061,
26,
288,
790,
275,
10822,
8,
277,
680,
2184,
342,
267,
587,
26,
288,
790,
275,
2740,
8,
277,
680,
2184,
342,
267,
574,
275,
291,
14,
1935,
8,
498,
9,
267,
372,
790,
12,
574,
339,
347,
636,
5270,
721,
277,
304,
267,
2974,
275,
3474,
75,
12,
291,
59,
75,
2677,
367,
1022,
315,
291,
61,
267,
3529,
275,
291,
855,
1130,
12,
291,
855,
500,
267,
2150,
291,
855,
1130,
12,
291,
855,
500,
267,
2727,
63,
807,
275,
6802,
8,
277,
680,
1574,
342,
267,
291,
855,
1130,
12,
291,
855,
500,
275,
3529,
267,
340,
2727,
63,
807,
26,
288,
372,
334,
277,
855,
533,
3108,
334,
1744,
4706,
2727,
63,
807,
9,
267,
372,
291,
855,
533,
3108,
334,
1744,
4258,
339,
347,
2883,
8,
277,
304,
267,
372,
769,
8,
277,
9,
339,
29408,
275,
7448,
4256,
14,
5486,
272,
1678,
275,
7448,
4256,
14,
873,
272,
4560,
275,
7448,
4256,
14,
1935,
272,
1338,
275,
7448,
4256,
14,
1459,
272,
2974,
275,
7448,
4256,
14,
1744,
272,
25706,
275,
7448,
4256,
14,
16007,
272,
24451,
275,
7448,
4256,
14,
13012,
272,
10849,
275,
7448,
4256,
14,
4611,
339,
347,
636,
2722,
721,
277,
304,
267,
340,
440,
291,
26,
288,
372,
1543,
83,
11716,
450,
334,
277,
855,
533,
4914,
354,
3108,
9,
267,
372,
1543,
83,
4042,
82,
3171,
450,
334,
277,
855,
533,
4914,
354,
3108,
291,
14,
1744,
1012,
339,
347,
1331,
8,
277,
304,
267,
372,
291,
855,
533,
721,
277,
9,
339,
768,
3744,
272,
347,
687,
1612,
8,
1886,
12,
6076,
12,
574,
29,
403,
304,
267,
366,
275,
843,
342,
267,
367,
790,
315,
6076,
26,
288,
366,
59,
498,
61,
275,
574,
267,
372,
366,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
8773,
304,
288,
340,
822,
8,
277,
9,
1137,
822,
8,
1848,
304,
355,
372,
756,
288,
367,
299,
12,
1894,
315,
221,
3482,
8,
277,
14,
1744,
1062,
1163,
14,
1744,
5109,
355,
340,
299,
1137,
1894,
26,
490,
372,
756,
288,
372,
715,
267,
372,
1211,
855,
4077,
721,
277,
12,
1163,
9,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
291,
508,
1163,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
puzan/ansible
|
lib/ansible/playbook/taggable.py
|
32
|
3442
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import itertools
from ansible.compat.six import string_types
from ansible.errors import AnsibleError
from ansible.playbook.attribute import FieldAttribute
from ansible.template import Templar
class Taggable:
untagged = frozenset(['untagged'])
_tags = FieldAttribute(isa='list', default=[], listof=(string_types,int))
def __init__(self):
super(Taggable, self).__init__()
def _load_tags(self, attr, ds):
if isinstance(ds, list):
return ds
elif isinstance(ds, string_types):
value = ds.split(',')
if isinstance(value, list):
return [ x.strip() for x in value ]
else:
return [ ds ]
else:
raise AnsibleError('tags must be specified as a list', obj=ds)
def _get_attr_tags(self):
'''
Override for the 'tags' getattr fetcher, used from Base.
'''
tags = self._attributes['tags']
if tags is None:
tags = []
if hasattr(self, '_get_parent_attribute'):
tags = self._get_parent_attribute('tags', extend=True)
return tags
def evaluate_tags(self, only_tags, skip_tags, all_vars):
''' this checks if the current item should be executed depending on tag options '''
should_run = True
if self.tags:
templar = Templar(loader=self._loader, variables=all_vars)
tags = templar.template(self.tags)
if not isinstance(tags, list):
if tags.find(',') != -1:
tags = set(tags.split(','))
else:
tags = set([tags])
else:
tags = set([i for i,_ in itertools.groupby(tags)])
else:
# this makes isdisjoint work for untagged
tags = self.untagged
if only_tags:
should_run = False
if 'always' in tags or 'all' in only_tags:
should_run = True
elif not tags.isdisjoint(only_tags):
should_run = True
elif 'tagged' in only_tags and tags != self.untagged:
should_run = True
if should_run and skip_tags:
# Check for tags that we need to skip
if 'all' in skip_tags:
if 'always' not in tags or 'always' in skip_tags:
should_run = False
elif not tags.isdisjoint(skip_tags):
should_run = False
elif 'tagged' in skip_tags and tags != self.untagged:
should_run = False
return should_run
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
13,
7280,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
7975,
199,
199,
504,
3242,
14,
5819,
14,
4174,
492,
1059,
63,
1313,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
14205,
14,
3215,
492,
5024,
1646,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
199,
533,
8053,
16725,
26,
339,
625,
15679,
275,
9522,
2941,
31595,
1105,
272,
485,
2969,
275,
5024,
1646,
8,
13655,
534,
513,
297,
849,
6034,
769,
1618,
2687,
875,
63,
1313,
12,
442,
430,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
1931,
16725,
12,
291,
2843,
826,
4533,
339,
347,
485,
912,
63,
2969,
8,
277,
12,
1921,
12,
6364,
304,
267,
340,
1228,
8,
795,
12,
769,
304,
288,
372,
6364,
267,
916,
1228,
8,
795,
12,
1059,
63,
1313,
304,
288,
574,
275,
6364,
14,
1294,
11917,
288,
340,
1228,
8,
585,
12,
769,
304,
355,
372,
359,
671,
14,
1913,
342,
367,
671,
315,
574,
1622,
288,
587,
26,
355,
372,
359,
6364,
1622,
267,
587,
26,
288,
746,
13358,
360,
2969,
1471,
506,
2013,
465,
282,
769,
297,
1559,
29,
795,
9,
339,
347,
485,
362,
63,
962,
63,
2969,
8,
277,
304,
267,
1449,
267,
11041,
367,
314,
283,
2969,
7,
2519,
5267,
281,
12,
1202,
687,
3523,
14,
267,
1449,
267,
3762,
275,
291,
423,
2987,
459,
2969,
418,
267,
340,
3762,
365,
488,
26,
288,
3762,
275,
942,
267,
340,
2688,
8,
277,
12,
2513,
362,
63,
1708,
63,
3215,
735,
288,
3762,
275,
291,
423,
362,
63,
1708,
63,
3215,
360,
2969,
297,
12247,
29,
549,
9,
267,
372,
3762,
339,
347,
9352,
63,
2969,
8,
277,
12,
1454,
63,
2969,
12,
3372,
63,
2969,
12,
1006,
63,
2936,
304,
267,
1449,
642,
5920,
340,
314,
1453,
1242,
1077,
506,
7934,
10298,
641,
1947,
1511,
1449,
398,
1077,
63,
1065,
275,
715,
398,
340,
291,
14,
2969,
26,
288,
28038,
275,
12540,
9828,
8,
3422,
29,
277,
423,
3422,
12,
2860,
29,
452,
63,
2936,
9,
288,
3762,
275,
28038,
14,
1160,
8,
277,
14,
2969,
9,
953,
340,
440,
1228,
8,
2969,
12,
769,
304,
355,
340,
3762,
14,
1623,
11917,
1137,
446,
17,
26,
490,
3762,
275,
663,
8,
2969,
14,
1294,
5102,
1333,
355,
587,
26,
490,
3762,
275,
663,
779,
2969,
566,
288,
587,
26,
355,
3762,
275,
663,
779,
73,
367,
284,
16987,
315,
7975,
14,
16968,
8,
2969,
3948,
267,
587,
26,
288,
327,
642,
7704,
365,
31880,
1736,
367,
625,
15679,
288,
3762,
275,
291,
14,
31595,
398,
340,
1454,
63,
2969,
26,
953,
1077,
63,
1065,
275,
756,
953,
340,
283,
9223,
7,
315,
3762,
503,
283,
452,
7,
315,
1454,
63,
2969,
26,
355,
1077,
63,
1065,
275,
715,
288,
916,
440,
3762,
14,
374,
31880,
8,
2118,
63,
2969,
304,
355,
1077,
63,
1065,
275,
715,
288,
916,
283,
15679,
7,
315,
1454,
63,
2969,
436,
3762,
1137,
291,
14,
31595,
26,
355,
1077,
63,
1065,
275,
715,
398,
340,
1077,
63,
1065,
436,
3372,
63,
2969,
26,
953,
327,
2670,
367,
3762,
626,
781,
1929,
370,
3372,
288,
340,
283,
452,
7,
315,
3372,
63,
2969,
26,
355,
340,
283,
9223,
7,
440,
315,
3762,
503,
283,
9223,
7,
315,
3372,
63,
2969,
26,
490,
1077,
63,
1065,
275,
756,
288,
916,
440,
3762,
14,
374,
31880,
8,
2759,
63,
2969,
304,
355,
1077,
63,
1065,
275,
756,
288,
916,
283,
15679,
7,
315,
3372,
63,
2969,
436,
3762,
1137,
291,
14,
31595,
26,
355,
1077,
63,
1065,
275,
756,
398,
372,
1077,
63,
1065,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
7975,
199,
199,
504,
3242,
14,
5819,
14,
4174,
492,
1059,
63,
1313,
199,
504,
3242,
14,
2550,
492,
13358,
199,
504,
3242,
14,
14205,
14,
3215,
492,
5024,
1646,
199,
504,
3242,
14,
1160,
492,
12540,
9828,
199,
199,
533,
8053,
16725,
26,
339,
625,
15679,
275,
9522,
2941,
31595,
1105,
272,
485,
2969,
275,
5024,
1646,
8,
13655,
534,
513,
297,
849,
6034,
769,
1618,
2687,
875,
63,
1313,
12,
442,
430,
339,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
1931,
16725,
12,
291,
2843,
826,
4533,
339,
347,
485,
912,
63,
2969,
8,
277,
12,
1921,
12,
6364,
304,
267,
340,
1228,
8,
795,
12,
769,
304,
288,
372,
6364,
267,
916,
1228,
8,
795,
12,
1059,
63,
1313,
304,
288,
574,
275,
6364,
14,
1294,
11917,
288,
340,
1228,
8,
585,
12,
769,
304,
355,
372,
359,
671,
14,
1913,
342,
367,
671,
315,
574,
1622,
288,
587,
26,
355,
372,
359,
6364,
1622,
267,
587,
26,
288,
746,
13358,
360,
2969,
1471,
506,
2013,
465,
282,
769,
297,
1559,
29,
795,
9,
339,
347,
485,
362,
63,
962,
63,
2969,
8,
277,
304,
267,
1449,
267,
11041,
367,
314,
283,
2969,
7,
2519,
5267,
281,
12,
1202,
687,
3523,
14,
267,
1449,
267,
3762,
275,
291,
423,
2987,
459,
2969,
418,
267,
340,
3762,
365,
488,
26,
288,
3762,
275,
942,
267,
340,
2688,
8,
277,
12,
2513,
362,
63,
1708,
63,
3215,
735,
288,
3762,
275,
291,
423,
362,
63,
1708,
63,
3215,
360,
2969,
297,
12247,
29,
549,
9,
267,
372,
3762,
339,
347,
9352,
63,
2969,
8,
277,
12,
1454,
63,
2969,
12,
3372,
63,
2969,
12,
1006,
63,
2936,
304,
267,
1449,
642,
5920,
340,
314,
1453,
1242,
1077,
506,
7934,
10298,
641,
1947,
1511,
1449,
398,
1077,
63,
1065,
275,
715,
398,
340,
291,
14,
2969,
26,
288,
28038,
275,
12540,
9828,
8,
3422,
29,
277,
423,
3422,
12,
2860,
29,
452,
63,
2936,
9,
288,
3762,
275,
28038,
14,
1160,
8,
277,
14,
2969,
9,
953,
340,
440,
1228,
8,
2969,
12,
769,
304,
355,
340,
3762,
14,
1623,
11917,
1137,
446,
17,
26,
490,
3762,
275,
663,
8,
2969,
14,
1294,
5102,
1333,
355,
587,
26,
490,
3762,
275,
663,
779,
2969,
566,
288,
587,
26,
355,
3762,
275,
663,
779,
73,
367,
284,
16987,
315,
7975,
14,
16968,
8,
2969,
3948,
267,
587,
26,
288,
327,
642,
7704,
365,
31880,
1736,
367,
625,
15679,
288,
3762,
275,
291,
14,
31595,
398,
340,
1454,
63,
2969,
26,
953,
1077,
63,
1065,
275,
756,
953,
340,
283,
9223,
7,
315,
3762,
503,
283,
452,
7,
315,
1454,
63,
2969,
26,
355,
1077,
63,
1065,
275,
715,
288,
916,
440,
3762,
14,
374,
31880,
8,
2118,
63,
2969,
304,
355,
1077,
63,
1065,
275,
715,
288,
916,
283,
15679,
7,
315,
1454,
63,
2969,
436,
3762,
1137,
291,
14,
31595,
26,
355,
1077,
63,
1065,
275,
715,
398,
340,
1077,
63,
1065,
436,
3372,
63,
2969,
26,
953,
327,
2670,
367,
3762,
626,
781,
1929,
370,
3372,
288,
340,
283,
452,
7,
315,
3372,
63,
2969,
26,
355,
340,
283,
9223,
7,
440,
315,
3762,
503,
283,
9223,
7,
315,
3372,
63,
2969,
26,
490,
1077,
63,
1065,
275,
756,
288,
916,
440,
3762,
14,
374,
31880,
8,
2759,
63,
2969,
304,
355,
1077,
63,
1065,
275,
756,
288,
916,
283,
15679,
7,
315,
3372,
63,
2969,
436,
3762,
1137,
291,
14,
31595,
26,
355,
1077,
63,
1065,
275,
756,
398,
372,
1077,
63,
1065,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
tizianasellitto/servo
|
etc/ci/performance/runner.py
|
14
|
9487
|
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
import itertools
import json
import os
import subprocess
from functools import partial
from statistics import median, StatisticsError
def load_manifest(filename):
with open(filename, 'r') as f:
text = f.read()
return list(parse_manifest(text))
def parse_manifest(text):
return filter(lambda x: x != "" and not x.startswith("#"),
map(lambda x: x.strip(), text.splitlines()))
def execute_test(url, command, timeout):
try:
return subprocess.check_output(
command, stderr=subprocess.STDOUT, timeout=timeout
)
except subprocess.CalledProcessError as e:
print("Unexpected Fail:")
print(e)
print("You may want to re-run the test manually:\n{}"
.format(' '.join(command)))
except subprocess.TimeoutExpired:
print("Test FAILED due to timeout: {}".format(url))
return ""
def run_servo_test(url, timeout):
ua_script_path = "{}/user-agent-js".format(os.getcwd())
command = [
"../../../target/release/servo", url,
"--userscripts", ua_script_path,
"--headless",
"-x", "-o", "output.png"
]
log = ""
try:
log = subprocess.check_output(
command, stderr=subprocess.STDOUT, timeout=timeout
)
except subprocess.CalledProcessError as e:
print("Unexpected Fail:")
print(e)
print("You may want to re-run the test manually:\n{}".format(
' '.join(command)
))
except subprocess.TimeoutExpired:
print("Test FAILED due to timeout: {}".format(url))
return parse_log(log, url)
def parse_log(log, testcase):
blocks = []
block = []
copy = False
for line_bytes in log.splitlines():
line = line_bytes.decode()
if line.strip() == ("[PERF] perf block start"):
copy = True
elif line.strip() == ("[PERF] perf block end"):
copy = False
blocks.append(block)
block = []
elif copy and line.strip().startswith("[PERF]"):
block.append(line)
def parse_block(block):
timing = {}
for line in block:
try:
(_, key, value) = line.split(",")
except:
print("[DEBUG] failed to parse the following line:")
print(line)
print('[DEBUG] log:')
print('-----')
print(log)
print('-----')
return None
if key == "testcase" or key == "title":
timing[key] = value
else:
timing[key] = None if (value == "undefined") else int(value)
return timing
def valid_timing(timing, testcase=None):
if (timing is None or
testcase is None or
timing.get('title') == 'Error response' or
timing.get('testcase') != testcase):
return False
else:
return True
# We need to still include the failed tests, otherwise Treeherder will
# consider the result to be a new test series, and thus a new graph. So we
# use a placeholder with values = -1 to make Treeherder happy, and still be
# able to identify failed tests (successful tests have time >=0).
def create_placeholder(testcase):
return {
"testcase": testcase,
"title": "",
"navigationStart": 0,
"unloadEventStart": -1,
"domLoading": -1,
"fetchStart": -1,
"responseStart": -1,
"loadEventEnd": -1,
"connectStart": -1,
"domainLookupStart": -1,
"redirectStart": -1,
"domContentLoadedEventEnd": -1,
"requestStart": -1,
"secureConnectionStart": -1,
"connectEnd": -1,
"loadEventStart": -1,
"domInteractive": -1,
"domContentLoadedEventStart": -1,
"redirectEnd": -1,
"domainLookupEnd": -1,
"unloadEventEnd": -1,
"responseEnd": -1,
"domComplete": -1,
}
valid_timing_for_case = partial(valid_timing, testcase=testcase)
timings = list(filter(valid_timing_for_case, map(parse_block, blocks)))
if len(timings) == 0:
print("Didn't find any perf data in the log, test timeout?")
print('[DEBUG] log:')
print('-----')
print(log)
print('-----')
return [create_placeholder(testcase)]
else:
return timings
def filter_result_by_manifest(result_json, manifest):
filtered = []
for name in manifest:
match = [tc for tc in result_json if tc['testcase'] == name]
if len(match) == 0:
raise Exception(("Missing test result: {}. This will cause a "
"discontinuity in the treeherder graph, "
"so we won't submit this data.").format(name))
filtered += match
return filtered
def take_result_median(result_json, expected_runs):
median_results = []
for k, g in itertools.groupby(result_json, lambda x: x['testcase']):
group = list(g)
if len(group) != expected_runs:
print(("Warning: Not enough test data for {},"
" maybe some runs failed?").format(k))
median_result = {}
for k, _ in group[0].items():
if k == "testcase":
median_result[k] = group[0][k]
else:
try:
median_result[k] = median([x[k] for x in group
if x[k] is not None])
except StatisticsError:
median_result[k] = -1
median_results.append(median_result)
return median_results
def save_result_json(results, filename, manifest, expected_runs):
results = filter_result_by_manifest(results, manifest)
results = take_result_median(results, expected_runs)
if len(results) == 0:
with open(filename, 'w') as f:
json.dump("No test result found in the log. All tests timeout?",
f, indent=2)
else:
with open(filename, 'w') as f:
json.dump(results, f, indent=2)
print("Result saved to {}".format(filename))
def format_result_summary(results):
failures = list(filter(lambda x: x['domComplete'] == -1, results))
result_log = """
========================================
Total {total} tests; {suc} succeeded, {fail} failed.
Failure summary:
""".format(
total=len(results),
suc=len(list(filter(lambda x: x['domComplete'] != -1, results))),
fail=len(failures)
)
uniq_failures = list(set(map(lambda x: x['testcase'], failures)))
for failure in uniq_failures:
result_log += " - {}\n".format(failure)
result_log += "========================================\n"
return result_log
def main():
parser = argparse.ArgumentParser(
description="Run page load test on servo"
)
parser.add_argument("tp5_manifest",
help="the test manifest in tp5 format")
parser.add_argument("output_file",
help="filename for the output json")
parser.add_argument("--runs",
type=int,
default=20,
help="number of runs for each test case. Defult: 20")
parser.add_argument("--timeout",
type=int,
default=300, # 5 min
help=("kill the test if not finished in time (sec)."
" Default: 5 min"))
parser.add_argument("--engine",
type=str,
default='servo',
help=("The engine to run the tests on. Currently only"
" servo and gecko are supported."))
args = parser.parse_args()
if args.engine == 'servo':
run_test = run_servo_test
elif args.engine == 'gecko':
import gecko_driver # Load this only when we need gecko test
run_test = gecko_driver.run_gecko_test
try:
# Assume the server is up and running
testcases = load_manifest(args.tp5_manifest)
results = []
for testcase in testcases:
for run in range(args.runs):
print("Running test {}/{} on {}".format(run + 1,
args.runs,
testcase))
# results will be a mixure of timings dict and testcase strings
# testcase string indicates a failed test
results += run_test(testcase, args.timeout)
print("Finished")
# TODO: Record and analyze other performance.timing properties
print(format_result_summary(results))
save_result_json(results, args.output_file, testcases, args.runs)
except KeyboardInterrupt:
print("Test stopped by user, saving partial result")
save_result_json(results, args.output_file, testcases, args.runs)
if __name__ == "__main__":
main()
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
7534,
199,
646,
7975,
199,
646,
2022,
199,
646,
747,
199,
646,
3873,
199,
504,
9143,
492,
7417,
199,
504,
11076,
492,
17312,
12,
28365,
547,
421,
199,
318,
2248,
63,
6418,
8,
1501,
304,
272,
543,
1551,
8,
1501,
12,
283,
82,
358,
465,
289,
26,
267,
1318,
275,
289,
14,
739,
342,
272,
372,
769,
8,
1122,
63,
6418,
8,
505,
430,
421,
199,
318,
2198,
63,
6418,
8,
505,
304,
272,
372,
2457,
8,
2734,
671,
26,
671,
1137,
3087,
436,
440,
671,
14,
2460,
10064,
1288,
2116,
2341,
8,
2734,
671,
26,
671,
14,
1913,
1062,
1318,
14,
7644,
4059,
421,
199,
318,
5341,
63,
396,
8,
633,
12,
1414,
12,
2653,
304,
272,
862,
26,
267,
372,
3873,
14,
1074,
63,
1199,
8,
288,
1414,
12,
4635,
29,
5781,
14,
13850,
12,
2653,
29,
2593,
267,
776,
272,
871,
3873,
14,
24691,
465,
325,
26,
267,
870,
480,
8708,
12176,
9107,
267,
870,
8,
69,
9,
267,
870,
480,
5556,
1443,
2934,
370,
295,
13,
1065,
314,
511,
10250,
3427,
78,
2440,
2,
1598,
1275,
908,
360,
1987,
904,
8,
1531,
1724,
272,
871,
3873,
14,
6372,
20898,
26,
267,
870,
480,
774,
26892,
7037,
370,
2653,
26,
8352,
908,
8,
633,
430,
272,
372,
3087,
421,
199,
318,
1255,
63,
25943,
63,
396,
8,
633,
12,
2653,
304,
272,
18500,
63,
1579,
63,
515,
275,
11491,
15,
751,
13,
4054,
13,
3596,
1674,
908,
8,
736,
14,
9458,
1012,
272,
1414,
275,
359,
267,
298,
29866,
1375,
15,
3221,
15,
25943,
401,
1166,
12,
267,
4320,
751,
6429,
401,
18500,
63,
1579,
63,
515,
12,
267,
4320,
2993,
2003,
401,
267,
3905,
88,
401,
3905,
79,
401,
298,
1199,
14,
4524,
2,
272,
1622,
272,
943,
275,
3087,
272,
862,
26,
267,
943,
275,
3873,
14,
1074,
63,
1199,
8,
288,
1414,
12,
4635,
29,
5781,
14,
13850,
12,
2653,
29,
2593,
267,
776,
272,
871,
3873,
14,
24691,
465,
325,
26,
267,
870,
480,
8708,
12176,
9107,
267,
870,
8,
69,
9,
267,
870,
480,
5556,
1443,
2934,
370,
295,
13,
1065,
314,
511,
10250,
3427,
78,
13536,
908,
8,
288,
283,
1987,
904,
8,
1531,
9,
267,
5082,
272,
871,
3873,
14,
6372,
20898,
26,
267,
870,
480,
774,
26892,
7037,
370,
2653,
26,
8352,
908,
8,
633,
430,
272,
372,
2198,
63,
793,
8,
793,
12,
1166,
9,
421,
199,
318,
2198,
63,
793,
8,
793,
12,
16228,
304,
272,
5664,
275,
942,
272,
1853,
275,
942,
272,
1331,
275,
756,
272,
367,
1004,
63,
2394,
315,
943,
14,
7644,
837,
267,
1004,
275,
1004,
63,
2394,
14,
2708,
342,
398,
340,
1004,
14,
1913,
342,
508,
1689,
59,
17038,
61,
8582,
1853,
1343,
2349,
288,
1331,
275,
715,
267,
916,
1004,
14,
1913,
342,
508,
1689,
59,
17038,
61,
8582,
1853,
1284,
2349,
288,
1331,
275,
756,
288,
5664,
14,
740,
8,
1457,
9,
288,
1853,
275,
942,
267,
916,
1331,
436,
1004,
14,
1913,
1252,
2460,
10994,
17038,
61,
2349,
288,
1853,
14,
740,
8,
604,
9,
339,
347,
2198,
63,
1457,
8,
1457,
304,
267,
20542,
275,
1052,
267,
367,
1004,
315,
1853,
26,
288,
862,
26,
355,
27017,
790,
12,
574,
9,
275,
1004,
14,
1294,
20324,
288,
871,
26,
355,
870,
10994,
5287,
61,
3405,
370,
2198,
314,
2569,
1004,
9107,
355,
870,
8,
604,
9,
355,
870,
11894,
5287,
61,
943,
10993,
355,
870,
360,
9858,
358,
355,
870,
8,
793,
9,
355,
870,
360,
9858,
358,
355,
372,
488,
953,
340,
790,
508,
298,
10847,
2,
503,
790,
508,
298,
1213,
582,
355,
20542,
59,
498,
61,
275,
574,
288,
587,
26,
355,
20542,
59,
498,
61,
275,
488,
340,
334,
585,
508,
298,
10705,
531,
587,
1109,
8,
585,
9,
398,
372,
20542,
339,
347,
1686,
63,
14639,
8,
14639,
12,
16228,
29,
403,
304,
267,
340,
334,
14639,
365,
488,
503,
355,
16228,
365,
488,
503,
355,
20542,
14,
362,
360,
1213,
358,
508,
283,
547,
1177,
7,
503,
355,
20542,
14,
362,
360,
10847,
358,
1137,
16228,
304,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
327,
2136,
1929,
370,
5139,
2387,
314,
3405,
2295,
12,
4257,
12178,
2523,
424,
911,
272,
327,
11201,
314,
754,
370,
506,
282,
892,
511,
6779,
12,
436,
12850,
282,
892,
3343,
14,
2002,
781,
272,
327,
675,
282,
10069,
543,
1338,
275,
446,
17,
370,
1852,
12178,
2523,
424,
394,
18869,
12,
436,
5139,
506,
272,
327,
7688,
370,
10405,
3405,
2295,
334,
18157,
2295,
1172,
900,
2356,
16,
680,
272,
347,
1218,
63,
6199,
8,
10847,
304,
267,
372,
469,
288,
298,
10847,
582,
16228,
12,
288,
298,
1213,
582,
4873,
288,
298,
24148,
3162,
582,
378,
12,
288,
298,
25477,
2390,
3162,
582,
446,
17,
12,
288,
298,
4556,
19236,
582,
446,
17,
12,
288,
298,
3535,
3162,
582,
446,
17,
12,
288,
298,
1310,
3162,
582,
446,
17,
12,
288,
298,
912,
2390,
3005,
582,
446,
17,
12,
288,
298,
2242,
3162,
582,
446,
17,
12,
288,
298,
2261,
7521,
3162,
582,
446,
17,
12,
288,
298,
4876,
3162,
582,
446,
17,
12,
288,
298,
4556,
2714,
19757,
2390,
3005,
582,
446,
17,
12,
288,
298,
1069,
3162,
582,
446,
17,
12,
288,
298,
7817,
3225,
3162,
582,
446,
17,
12,
288,
298,
2242,
3005,
582,
446,
17,
12,
288,
298,
912,
2390,
3162,
582,
446,
17,
12,
288,
298,
4556,
23879,
582,
446,
17,
12,
288,
298,
4556,
2714,
19757,
2390,
3162,
582,
446,
17,
12,
288,
298,
4876,
3005,
582,
446,
17,
12,
288,
298,
2261,
7521,
3005,
582,
446,
17,
12,
288,
298,
25477,
2390,
3005,
582,
446,
17,
12,
288,
298,
1310,
3005,
582,
446,
17,
12,
288,
298,
4556
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
199,
3,
570,
12,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
7534,
199,
646,
7975,
199,
646,
2022,
199,
646,
747,
199,
646,
3873,
199,
504,
9143,
492,
7417,
199,
504,
11076,
492,
17312,
12,
28365,
547,
421,
199,
318,
2248,
63,
6418,
8,
1501,
304,
272,
543,
1551,
8,
1501,
12,
283,
82,
358,
465,
289,
26,
267,
1318,
275,
289,
14,
739,
342,
272,
372,
769,
8,
1122,
63,
6418,
8,
505,
430,
421,
199,
318,
2198,
63,
6418,
8,
505,
304,
272,
372,
2457,
8,
2734,
671,
26,
671,
1137,
3087,
436,
440,
671,
14,
2460,
10064,
1288,
2116,
2341,
8,
2734,
671,
26,
671,
14,
1913,
1062,
1318,
14,
7644,
4059,
421,
199,
318,
5341,
63,
396,
8,
633,
12,
1414,
12,
2653,
304,
272,
862,
26,
267,
372,
3873,
14,
1074,
63,
1199,
8,
288,
1414,
12,
4635,
29,
5781,
14,
13850,
12,
2653,
29,
2593,
267,
776,
272,
871,
3873,
14,
24691,
465,
325,
26,
267,
870,
480,
8708,
12176,
9107,
267,
870,
8,
69,
9,
267,
870,
480,
5556,
1443,
2934,
370,
295,
13,
1065,
314,
511,
10250,
3427,
78,
2440,
2,
1598,
1275,
908,
360,
1987,
904,
8,
1531,
1724,
272,
871,
3873,
14,
6372,
20898,
26,
267,
870,
480,
774,
26892,
7037,
370,
2653,
26,
8352,
908,
8,
633,
430,
272,
372,
3087,
421,
199,
318,
1255,
63,
25943,
63,
396,
8,
633,
12,
2653,
304,
272,
18500,
63,
1579,
63,
515,
275,
11491,
15,
751,
13,
4054,
13,
3596,
1674,
908,
8,
736,
14,
9458,
1012,
272,
1414,
275,
359,
267,
298,
29866,
1375,
15,
3221,
15,
25943,
401,
1166,
12,
267,
4320,
751,
6429,
401,
18500,
63,
1579,
63,
515,
12,
267,
4320,
2993,
2003,
401,
267,
3905,
88,
401,
3905,
79,
401,
298,
1199,
14,
4524,
2,
272,
1622,
272,
943,
275,
3087,
272,
862,
26,
267,
943,
275,
3873,
14,
1074,
63,
1199,
8,
288,
1414,
12,
4635,
29,
5781,
14,
13850,
12,
2653,
29,
2593,
267,
776,
272,
871,
3873,
14,
24691,
465,
325,
26,
267,
870,
480,
8708,
12176,
9107,
267,
870,
8,
69,
9,
267,
870,
480,
5556,
1443,
2934,
370,
295,
13,
1065,
314,
511,
10250,
3427,
78,
13536,
908,
8,
288,
283,
1987,
904,
8,
1531,
9,
267,
5082,
272,
871,
3873,
14,
6372,
20898,
26,
267,
870,
480,
774,
26892,
7037,
370,
2653,
26,
8352,
908,
8,
633,
430,
272,
372,
2198,
63,
793,
8,
793,
12,
1166,
9,
421,
199,
318,
2198,
63,
793,
8,
793,
12,
16228,
304,
272,
5664,
275,
942,
272,
1853,
275,
942,
272,
1331,
275,
756,
272,
367,
1004,
63,
2394,
315,
943,
14,
7644,
837,
267,
1004,
275,
1004,
63,
2394,
14,
2708,
342,
398,
340,
1004,
14,
1913,
342,
508,
1689,
59,
17038,
61,
8582,
1853,
1343,
2349,
288,
1331,
275,
715,
267,
916,
1004,
14,
1913,
342,
508,
1689,
59,
17038,
61,
8582,
1853,
1284,
2349,
288,
1331,
275,
756,
288,
5664,
14,
740,
8,
1457,
9,
288,
1853,
275,
942,
267,
916,
1331,
436,
1004,
14,
1913,
1252,
2460,
10994,
17038,
61,
2349,
288,
1853,
14,
740,
8,
604,
9,
339,
347,
2198,
63,
1457,
8,
1457,
304,
267,
20542,
275,
1052,
267,
367,
1004,
315,
1853,
26,
288,
862,
26,
355,
27017,
790,
12,
574,
9,
275,
1004,
14,
1294,
20324,
288,
871,
26,
355,
870,
10994,
5287,
61,
3405,
370,
2198,
314,
2569,
1004,
9107,
355,
870,
8,
604,
9,
355,
870,
11894,
5287,
61,
943,
10993,
355,
870,
360,
9858,
358,
355,
870,
8,
793,
9,
355,
870,
360,
9858,
358,
355,
372,
488,
953,
340,
790,
508,
298,
10847,
2,
503,
790,
508,
298,
1213,
582,
355,
20542,
59,
498,
61,
275,
574,
288,
587,
26,
355,
20542,
59,
498,
61,
275,
488,
340,
334,
585,
508,
298,
10705,
531,
587,
1109,
8,
585,
9,
398,
372,
20542,
339,
347,
1686,
63,
14639,
8,
14639,
12,
16228,
29,
403,
304,
267,
340,
334,
14639,
365,
488,
503,
355,
16228,
365,
488,
503,
355,
20542,
14,
362,
360,
1213,
358,
508,
283,
547,
1177,
7,
503,
355,
20542,
14,
362,
360,
10847,
358,
1137,
16228,
304,
288,
372,
756,
267,
587,
26,
288,
372,
715,
339,
327,
2136,
1929,
370,
5139,
2387,
314,
3405,
2295,
12,
4257,
12178,
2523,
424,
911,
272,
327,
11201,
314,
754,
370,
506,
282,
892,
511,
6779,
12,
436,
12850,
282,
892,
3343,
14,
2002,
781,
272,
327,
675,
282,
10069,
543,
1338,
275,
446,
17,
370,
1852,
12178,
2523,
424,
394,
18869,
12,
436,
5139,
506,
272,
327,
7688,
370,
10405,
3405,
2295,
334,
18157,
2295,
1172,
900,
2356,
16,
680,
272,
347,
1218,
63,
6199,
8,
10847,
304,
267,
372,
469,
288,
298,
10847,
582,
16228,
12,
288,
298,
1213,
582,
4873,
288,
298,
24148,
3162,
582,
378,
12,
288,
298,
25477,
2390,
3162,
582,
446,
17,
12,
288,
298,
4556,
19236,
582,
446,
17,
12,
288,
298,
3535,
3162,
582,
446,
17,
12,
288,
298,
1310,
3162,
582,
446,
17,
12,
288,
298,
912,
2390,
3005,
582,
446,
17,
12,
288,
298,
2242,
3162,
582,
446,
17,
12,
288,
298,
2261,
7521,
3162,
582,
446,
17,
12,
288,
298,
4876,
3162,
582,
446,
17,
12,
288,
298,
4556,
2714,
19757,
2390,
3005,
582,
446,
17,
12,
288,
298,
1069,
3162,
582,
446,
17,
12,
288,
298,
7817,
3225,
3162,
582,
446,
17,
12,
288,
298,
2242,
3005,
582,
446,
17,
12,
288,
298,
912,
2390,
3162,
582,
446,
17,
12,
288,
298,
4556,
23879,
582,
446,
17,
12,
288,
298,
4556,
2714,
19757,
2390,
3162,
582,
446,
17,
12,
288,
298,
4876,
3005,
582,
446,
17,
12,
288,
298,
2261,
7521,
3005,
582,
446,
17,
12,
288,
298,
25477,
2390,
3005,
582,
446,
17,
12,
288,
298,
1310,
3005,
582,
446,
17,
12,
288,
298,
4556,
0
] |
[
1,
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 numpy as np
from copy import deepcopy
from random import shuffle
from scipy.io import loadmat
class DataSet(object):
def __init__(self, cfg):
"""Construct a DataSet.
"""
self.cfg = cfg
self.all_walks, self.node_seq = self.get_walks(cfg.walks_dir)
#self.node_seq = self.all_walks[:, -1] # index by ending node
self.all_labels = self.get_labels(cfg.label_dir)
self.all_features= self.get_fetaures(cfg.features_dir)
#Increment the positions by 1 and mark the 0th one as False
self.train_nodes = np.concatenate(([False], np.load(cfg.label_fold_dir + 'train_ids.npy')))
self.val_nodes = np.concatenate(([False], np.load(cfg.label_fold_dir + 'val_ids.npy')))
self.test_nodes = np.concatenate(([False], np.load(cfg.label_fold_dir + 'test_ids.npy')))
# [!!!IMP!!]Assert no overlap between test/val/train nodes
self.label_cache, self.update_cache = {0:list(self.all_labels[0])}, {}
def get_walks(self, path):
walks = np.fliplr(np.loadtxt(path, dtype=np.int)) # reverse the sequence
seq = deepcopy(walks[:,-1])
#rotate around the sequences, such that ends are padded with zeros
for i in range(np.shape(walks)[0]):
non_zeros = np.sum(walks[i] > 0)
walks[i] = np.roll(walks[i], non_zeros)
return walks, seq
def get_fetaures(self, path):
# Serves 2 purpose:
# a) add feature for dummy node 0 a.k.a <EOS> and <unlabeled>
# b) increments index of all features by 1, thus aligning it with indices in walks
all_features = np.load(path)
all_features = all_features.astype(np.float32, copy=False) # Required conversion for Python3
all_features = np.concatenate(([np.zeros(all_features.shape[1])], all_features), 0)
return all_features
def get_labels(self, path):
# Labels start with node '0'; Walks_data with node '1'
# To get corresponding mapping, increment the label node number by 1
# add label for dummy node 0 a.k.a <EOS> and <unlabeled>
all_labels = np.load(path)
all_labels = np.concatenate(([np.zeros(all_labels.shape[1])], all_labels), 0)
return all_labels
def accumulate_label_cache(self, labels, nodes):
#Aggregates all the labels for the corresponding nodes
#and tracks the count of updates made
default = (self.all_labels[0], 0) #Initial estimate -> all_zeros
labels = labels[0]
if self.cfg.data_sets.binary_label_updates:
#Convert to binary and keep only the maximum value as 1
amax = np.argmax(labels, axis = 1)
labels = np.zeros(labels.shape)
for idx, pos in enumerate(amax):
labels[idx,pos] = 1
for idx, node in enumerate(nodes):
prv_label, prv_count = self.update_cache.get(node, default)
new_label = prv_label + labels[idx]
new_count = prv_count + 1
self.update_cache[node] = (new_label, new_count)
def update_label_cache(self):
#Average all the predictions made for the corresponding nodes and reset cache
for k, v in self.update_cache.items():
self.label_cache[k] = list(v[0]/v[1])
self.update_cache = {}
def get_nodes(self, dataset):
nodes = []
if dataset == 'train':
nodes = self.train_nodes
elif dataset == 'val':
nodes = self.val_nodes
elif dataset == 'test':
nodes = self.test_nodes
elif dataset == 'all':
# Get all the nodes except the 0th node
nodes = [True]*len(self.train_nodes)
nodes[0] = False
else:
raise ValueError
return nodes
def next_batch(self, dataset, batch_size, shuffle=True):
nodes = self.get_nodes(dataset)
label_len = np.shape(self.all_labels)[1]
max_len = self.all_walks.shape[1]
# Get position of all walks ending with desired set of nodes
pos = []
seq = []
for node in np.where(nodes)[0]:
temp = np.where(self.node_seq == node)[0]
pos.extend(temp)
seq.extend([node]*len(temp))
pos = np.array(pos)
seq = np.array(seq)
if shuffle:
indices = np.random.permutation(len(pos))
pos = pos[indices]
seq = seq[indices]
if batch_size == -1:
batch_size = len(pos)
tot = len(pos)//batch_size
for i in range(0, len(pos), batch_size):
x = self.all_walks[pos[i: i + batch_size]]
temp = np.array(x)>0 #get locations of all zero inputs
lengths = max_len - np.sum(temp, axis=1)
x = np.swapaxes(x, 0, 1) # convert from (batch x step) to (step x batch)
# get labels for valid data points, for others: select the 0th label
x2 = [[self.label_cache.get(item, self.label_cache[0]) for item in row] for row in x]
y = [list(self.all_labels[item]) for item in seq[i: i+batch_size]]
# get features for all data points
x = [[self.all_features[item] for item in row] for row in x]
#seq = self.node_seq[pos[i: i + batch_size]]
yield (x, x2, seq, y, tot, lengths)
def next_batch_same(self, dataset, node_count=1):
nodes = self.get_nodes(dataset)
pos = []
counts = []
seq = []
for node in np.where(nodes)[0]:
temp = np.where(self.node_seq == node)[0]
counts.append(len(temp))
seq.append(node)
pos.extend(temp)
pos = np.array(pos)
start = 0
max_len = self.all_walks.shape[1]
# Get a batch of all walks for 'node_count' number of node
for idx in range(0, len(counts), node_count):
#print(idx)
stop = start + np.sum(counts[idx:idx+node_count]) #start + total number of walks to be consiudered this time
x = self.all_walks[pos[start:stop]] #get the walks corresponding to respective positions
temp = np.array(x)>0 #get locations of all zero inputs
lengths = max_len - np.sum(temp, axis=1)
x = np.swapaxes(x, 0, 1) # convert from (batch x step) to (step x batch)
# get labels for valid data points, for others: select the 0th label
x2 = [[self.label_cache.get(item, self.label_cache[0]) for item in row] for row in x]
y = [list(self.all_labels[item]) for item in x[-1,:]] #Not useful, only presetn for sake of placeholder
# get features for all data points
x = [[self.all_features[item] for item in row] for row in x]
start = stop
yield (x, x2, seq[idx:idx+node_count], counts[idx:idx+node_count], y, lengths)
|
mit
|
[
504,
636,
2443,
363,
492,
16952,
12,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
504,
1331,
492,
14800,
199,
504,
2196,
492,
13031,
199,
504,
7026,
14,
2308,
492,
2248,
569,
199,
199,
533,
3918,
1084,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4810,
304,
267,
408,
11493,
282,
3918,
1084,
14,
267,
408,
267,
291,
14,
4128,
275,
4810,
267,
291,
14,
452,
63,
7757,
83,
12,
291,
14,
932,
63,
3610,
221,
275,
291,
14,
362,
63,
7757,
83,
8,
4128,
14,
7757,
83,
63,
694,
9,
267,
327,
277,
14,
932,
63,
3610,
259,
275,
291,
14,
452,
63,
7757,
83,
3981,
446,
17,
61,
221,
327,
1478,
701,
13401,
1031,
267,
291,
14,
452,
63,
3512,
221,
275,
291,
14,
362,
63,
3512,
8,
4128,
14,
1302,
63,
694,
9,
267,
291,
14,
452,
63,
3179,
29,
291,
14,
362,
63,
70,
1841,
1482,
8,
4128,
14,
3179,
63,
694,
9,
398,
327,
29485,
314,
12266,
701,
413,
436,
2216,
314,
378,
273,
1373,
465,
756,
267,
291,
14,
2834,
63,
2415,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
2834,
63,
1580,
14,
20245,
7058,
267,
291,
14,
637,
63,
2415,
257,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
637,
63,
1580,
14,
20245,
7058,
267,
291,
14,
396,
63,
2415,
221,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
396,
63,
1580,
14,
20245,
7058,
267,
327,
359,
21512,
8947,
3480,
61,
9699,
949,
15145,
3382,
511,
15,
637,
15,
2834,
3380,
398,
291,
14,
1302,
63,
1637,
12,
291,
14,
873,
63,
1637,
275,
469,
16,
26,
513,
8,
277,
14,
452,
63,
3512,
59,
16,
566,
1386,
1052,
339,
347,
664,
63,
7757,
83,
8,
277,
12,
931,
304,
267,
12778,
83,
275,
980,
14,
70,
317,
1168,
82,
8,
1590,
14,
27992,
8,
515,
12,
2152,
29,
1590,
14,
442,
430,
221,
327,
3837,
314,
3414,
267,
5412,
275,
14800,
8,
7757,
83,
1491,
3057,
17,
566,
267,
327,
12873,
6818,
314,
8013,
12,
4066,
626,
11187,
787,
21824,
543,
10136,
267,
367,
284,
315,
1425,
8,
1590,
14,
1392,
8,
7757,
83,
2788,
16,
4682,
288,
2222,
63,
4250,
275,
980,
14,
1838,
8,
7757,
83,
59,
73,
61,
690,
378,
9,
288,
12778,
83,
59,
73,
61,
275,
980,
14,
2827,
8,
7757,
83,
59,
73,
467,
2222,
63,
4250,
9,
398,
372,
12778,
83,
12,
5412,
339,
347,
664,
63,
70,
1841,
1482,
8,
277,
12,
931,
304,
267,
327,
3739,
2310,
499,
12016,
26,
267,
327,
282,
9,
1050,
3878,
367,
7283,
1031,
378,
282,
14,
75,
14,
65,
665,
37,
3100,
30,
436,
665,
324,
21242,
30,
267,
327,
330,
9,
10035,
1470,
1478,
402,
1006,
4534,
701,
413,
12,
12850,
6998,
316,
652,
543,
4918,
315,
12778,
83,
267,
1006,
63,
3179,
275,
980,
14,
912,
8,
515,
9,
267,
1006,
63,
3179,
275,
1006,
63,
3179,
14,
6041,
8,
1590,
14,
1609,
708,
12,
1331,
29,
797,
9,
221,
327,
11105,
8603,
367,
2018,
19,
267,
1006,
63,
3179,
275,
980,
14,
13433,
27123,
1590,
14,
4250,
8,
452,
63,
3179,
14,
1392,
59,
17,
27520,
1006,
63,
3179,
395,
378,
9,
267,
372,
1006,
63,
3179,
339,
347,
664,
63,
3512,
8,
277,
12,
931,
304,
267,
327,
10354,
83,
1343,
543,
1031,
283,
16,
13619,
644,
4878,
83,
63,
576,
543,
1031,
283,
17,
7,
267,
327,
4005,
664,
5226,
4412,
12,
11609,
314,
1768,
1031,
1329,
701,
413,
267,
327,
1050,
1768,
367,
7283,
1031,
378,
282,
14,
75,
14,
65,
665,
37,
3100,
30,
436,
665,
324,
21242,
30,
267,
1006,
63,
3512,
275,
980,
14,
912,
8,
515,
9,
267,
1006,
63,
3512,
275,
980,
14,
13433,
27123,
1590,
14,
4250,
8,
452,
63,
3512,
14,
1392,
59,
17,
27520,
1006,
63,
3512,
395,
378,
9,
398,
372,
1006,
63,
3512,
339,
347,
30535,
63,
1302,
63,
1637,
8,
277,
12,
3628,
12,
3380,
304,
267,
327,
8073,
2335,
1006,
314,
3628,
367,
314,
5226,
3380,
267,
327,
460,
18917,
314,
2338,
402,
7029,
6326,
267,
849,
275,
334,
277,
14,
452,
63,
3512,
59,
16,
467,
378,
9,
327,
5733,
14497,
1035,
1006,
63,
4250,
267,
3628,
275,
3628,
59,
16,
61,
2728,
340,
291,
14,
4128,
14,
576,
63,
2193,
14,
3008,
63,
1302,
63,
7618,
26,
288,
327,
7306,
370,
3366,
436,
4215,
1454,
314,
5696,
574,
465,
413,
288,
282,
988,
275,
980,
14,
16383,
8,
3512,
12,
3114,
275,
413,
9,
288,
3628,
275,
980,
14,
4250,
8,
3512,
14,
1392,
9,
288,
367,
4280,
12,
2086,
315,
3874,
8,
65,
988,
304,
355,
3628,
59,
2996,
12,
1712,
61,
275,
413,
2728,
367,
4280,
12,
1031,
315,
3874,
8,
2415,
304,
288,
5448,
86,
63,
1302,
12,
5448,
86,
63,
835,
275,
291,
14,
873,
63,
1637,
14,
362,
8,
932,
12,
849,
9,
288,
892,
63,
1302,
275,
5448,
86,
63,
1302,
435,
3628,
59,
2996,
61,
288,
892,
63,
835,
275,
5448,
86,
63,
835,
435,
413,
288,
291,
14,
873,
63,
1637,
59,
932,
61,
275,
334,
1222,
63,
1302,
12,
892,
63,
835,
9,
339,
347,
1678,
63,
1302,
63,
1637,
8,
277,
304,
267,
327,
17400,
1006,
314,
7914,
6326,
367,
314,
5226,
3380,
436,
5305,
2581,
267,
367,
1022,
12,
373,
315,
291,
14,
873,
63,
1637,
14,
1744,
837,
288,
291,
14,
1302,
63,
1637,
59,
75,
61,
275,
769,
8,
86,
59,
16,
12978,
86,
59,
17,
566,
27439,
291,
14,
873,
63,
1637,
275,
1052,
18407,
347,
664,
63,
2415,
8,
277,
12,
4789,
304,
267,
3380,
275,
942,
267,
340,
4789,
508,
283,
2834,
356,
288,
3380,
275,
291,
14,
2834,
63,
2415,
267,
916,
4789,
508,
283,
637,
356,
288,
3380,
275,
291,
14,
637,
63,
2415,
267,
916,
4789,
508,
283,
396,
356,
288,
3380,
275,
291,
14,
396,
63,
2415,
267,
916
] |
[
636,
2443,
363,
492,
16952,
12,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
504,
1331,
492,
14800,
199,
504,
2196,
492,
13031,
199,
504,
7026,
14,
2308,
492,
2248,
569,
199,
199,
533,
3918,
1084,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
4810,
304,
267,
408,
11493,
282,
3918,
1084,
14,
267,
408,
267,
291,
14,
4128,
275,
4810,
267,
291,
14,
452,
63,
7757,
83,
12,
291,
14,
932,
63,
3610,
221,
275,
291,
14,
362,
63,
7757,
83,
8,
4128,
14,
7757,
83,
63,
694,
9,
267,
327,
277,
14,
932,
63,
3610,
259,
275,
291,
14,
452,
63,
7757,
83,
3981,
446,
17,
61,
221,
327,
1478,
701,
13401,
1031,
267,
291,
14,
452,
63,
3512,
221,
275,
291,
14,
362,
63,
3512,
8,
4128,
14,
1302,
63,
694,
9,
267,
291,
14,
452,
63,
3179,
29,
291,
14,
362,
63,
70,
1841,
1482,
8,
4128,
14,
3179,
63,
694,
9,
398,
327,
29485,
314,
12266,
701,
413,
436,
2216,
314,
378,
273,
1373,
465,
756,
267,
291,
14,
2834,
63,
2415,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
2834,
63,
1580,
14,
20245,
7058,
267,
291,
14,
637,
63,
2415,
257,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
637,
63,
1580,
14,
20245,
7058,
267,
291,
14,
396,
63,
2415,
221,
275,
980,
14,
13433,
27123,
797,
467,
980,
14,
912,
8,
4128,
14,
1302,
63,
14011,
63,
694,
435,
283,
396,
63,
1580,
14,
20245,
7058,
267,
327,
359,
21512,
8947,
3480,
61,
9699,
949,
15145,
3382,
511,
15,
637,
15,
2834,
3380,
398,
291,
14,
1302,
63,
1637,
12,
291,
14,
873,
63,
1637,
275,
469,
16,
26,
513,
8,
277,
14,
452,
63,
3512,
59,
16,
566,
1386,
1052,
339,
347,
664,
63,
7757,
83,
8,
277,
12,
931,
304,
267,
12778,
83,
275,
980,
14,
70,
317,
1168,
82,
8,
1590,
14,
27992,
8,
515,
12,
2152,
29,
1590,
14,
442,
430,
221,
327,
3837,
314,
3414,
267,
5412,
275,
14800,
8,
7757,
83,
1491,
3057,
17,
566,
267,
327,
12873,
6818,
314,
8013,
12,
4066,
626,
11187,
787,
21824,
543,
10136,
267,
367,
284,
315,
1425,
8,
1590,
14,
1392,
8,
7757,
83,
2788,
16,
4682,
288,
2222,
63,
4250,
275,
980,
14,
1838,
8,
7757,
83,
59,
73,
61,
690,
378,
9,
288,
12778,
83,
59,
73,
61,
275,
980,
14,
2827,
8,
7757,
83,
59,
73,
467,
2222,
63,
4250,
9,
398,
372,
12778,
83,
12,
5412,
339,
347,
664,
63,
70,
1841,
1482,
8,
277,
12,
931,
304,
267,
327,
3739,
2310,
499,
12016,
26,
267,
327,
282,
9,
1050,
3878,
367,
7283,
1031,
378,
282,
14,
75,
14,
65,
665,
37,
3100,
30,
436,
665,
324,
21242,
30,
267,
327,
330,
9,
10035,
1470,
1478,
402,
1006,
4534,
701,
413,
12,
12850,
6998,
316,
652,
543,
4918,
315,
12778,
83,
267,
1006,
63,
3179,
275,
980,
14,
912,
8,
515,
9,
267,
1006,
63,
3179,
275,
1006,
63,
3179,
14,
6041,
8,
1590,
14,
1609,
708,
12,
1331,
29,
797,
9,
221,
327,
11105,
8603,
367,
2018,
19,
267,
1006,
63,
3179,
275,
980,
14,
13433,
27123,
1590,
14,
4250,
8,
452,
63,
3179,
14,
1392,
59,
17,
27520,
1006,
63,
3179,
395,
378,
9,
267,
372,
1006,
63,
3179,
339,
347,
664,
63,
3512,
8,
277,
12,
931,
304,
267,
327,
10354,
83,
1343,
543,
1031,
283,
16,
13619,
644,
4878,
83,
63,
576,
543,
1031,
283,
17,
7,
267,
327,
4005,
664,
5226,
4412,
12,
11609,
314,
1768,
1031,
1329,
701,
413,
267,
327,
1050,
1768,
367,
7283,
1031,
378,
282,
14,
75,
14,
65,
665,
37,
3100,
30,
436,
665,
324,
21242,
30,
267,
1006,
63,
3512,
275,
980,
14,
912,
8,
515,
9,
267,
1006,
63,
3512,
275,
980,
14,
13433,
27123,
1590,
14,
4250,
8,
452,
63,
3512,
14,
1392,
59,
17,
27520,
1006,
63,
3512,
395,
378,
9,
398,
372,
1006,
63,
3512,
339,
347,
30535,
63,
1302,
63,
1637,
8,
277,
12,
3628,
12,
3380,
304,
267,
327,
8073,
2335,
1006,
314,
3628,
367,
314,
5226,
3380,
267,
327,
460,
18917,
314,
2338,
402,
7029,
6326,
267,
849,
275,
334,
277,
14,
452,
63,
3512,
59,
16,
467,
378,
9,
327,
5733,
14497,
1035,
1006,
63,
4250,
267,
3628,
275,
3628,
59,
16,
61,
2728,
340,
291,
14,
4128,
14,
576,
63,
2193,
14,
3008,
63,
1302,
63,
7618,
26,
288,
327,
7306,
370,
3366,
436,
4215,
1454,
314,
5696,
574,
465,
413,
288,
282,
988,
275,
980,
14,
16383,
8,
3512,
12,
3114,
275,
413,
9,
288,
3628,
275,
980,
14,
4250,
8,
3512,
14,
1392,
9,
288,
367,
4280,
12,
2086,
315,
3874,
8,
65,
988,
304,
355,
3628,
59,
2996,
12,
1712,
61,
275,
413,
2728,
367,
4280,
12,
1031,
315,
3874,
8,
2415,
304,
288,
5448,
86,
63,
1302,
12,
5448,
86,
63,
835,
275,
291,
14,
873,
63,
1637,
14,
362,
8,
932,
12,
849,
9,
288,
892,
63,
1302,
275,
5448,
86,
63,
1302,
435,
3628,
59,
2996,
61,
288,
892,
63,
835,
275,
5448,
86,
63,
835,
435,
413,
288,
291,
14,
873,
63,
1637,
59,
932,
61,
275,
334,
1222,
63,
1302,
12,
892,
63,
835,
9,
339,
347,
1678,
63,
1302,
63,
1637,
8,
277,
304,
267,
327,
17400,
1006,
314,
7914,
6326,
367,
314,
5226,
3380,
436,
5305,
2581,
267,
367,
1022,
12,
373,
315,
291,
14,
873,
63,
1637,
14,
1744,
837,
288,
291,
14,
1302,
63,
1637,
59,
75,
61,
275,
769,
8,
86,
59,
16,
12978,
86,
59,
17,
566,
27439,
291,
14,
873,
63,
1637,
275,
1052,
18407,
347,
664,
63,
2415,
8,
277,
12,
4789,
304,
267,
3380,
275,
942,
267,
340,
4789,
508,
283,
2834,
356,
288,
3380,
275,
291,
14,
2834,
63,
2415,
267,
916,
4789,
508,
283,
637,
356,
288,
3380,
275,
291,
14,
637,
63,
2415,
267,
916,
4789,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DirtyUnicorns/android_external_chromium_org
|
third_party/protobuf/python/google/protobuf/descriptor_pool.py
|
228
|
18667
|
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# http://code.google.com/p/protobuf/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Provides DescriptorPool to use as a container for proto2 descriptors.
The DescriptorPool is used in conjection with a DescriptorDatabase to maintain
a collection of protocol buffer descriptors for use when dynamically creating
message types at runtime.
For most applications protocol buffers should be used via modules generated by
the protocol buffer compiler tool. This should only be used when the type of
protocol buffers used in an application or library cannot be predetermined.
Below is a straightforward example on how to use this class:
pool = DescriptorPool()
file_descriptor_protos = [ ... ]
for file_descriptor_proto in file_descriptor_protos:
pool.Add(file_descriptor_proto)
my_message_descriptor = pool.FindMessageTypeByName('some.package.MessageType')
The message descriptor can be used in conjunction with the message_factory
module in order to create a protocol buffer class that can be encoded and
decoded.
"""
__author__ = 'matthewtoia@google.com (Matt Toia)'
from google.protobuf import descriptor_pb2
from google.protobuf import descriptor
from google.protobuf import descriptor_database
class DescriptorPool(object):
"""A collection of protobufs dynamically constructed by descriptor protos."""
def __init__(self, descriptor_db=None):
"""Initializes a Pool of proto buffs.
The descriptor_db argument to the constructor is provided to allow
specialized file descriptor proto lookup code to be triggered on demand. An
example would be an implementation which will read and compile a file
specified in a call to FindFileByName() and not require the call to Add()
at all. Results from this database will be cached internally here as well.
Args:
descriptor_db: A secondary source of file descriptors.
"""
self._internal_db = descriptor_database.DescriptorDatabase()
self._descriptor_db = descriptor_db
self._descriptors = {}
self._enum_descriptors = {}
self._file_descriptors = {}
def Add(self, file_desc_proto):
"""Adds the FileDescriptorProto and its types to this pool.
Args:
file_desc_proto: The FileDescriptorProto to add.
"""
self._internal_db.Add(file_desc_proto)
def FindFileByName(self, file_name):
"""Gets a FileDescriptor by file name.
Args:
file_name: The path to the file to get a descriptor for.
Returns:
A FileDescriptor for the named file.
Raises:
KeyError: if the file can not be found in the pool.
"""
try:
file_proto = self._internal_db.FindFileByName(file_name)
except KeyError as error:
if self._descriptor_db:
file_proto = self._descriptor_db.FindFileByName(file_name)
else:
raise error
if not file_proto:
raise KeyError('Cannot find a file named %s' % file_name)
return self._ConvertFileProtoToFileDescriptor(file_proto)
def FindFileContainingSymbol(self, symbol):
"""Gets the FileDescriptor for the file containing the specified symbol.
Args:
symbol: The name of the symbol to search for.
Returns:
A FileDescriptor that contains the specified symbol.
Raises:
KeyError: if the file can not be found in the pool.
"""
try:
file_proto = self._internal_db.FindFileContainingSymbol(symbol)
except KeyError as error:
if self._descriptor_db:
file_proto = self._descriptor_db.FindFileContainingSymbol(symbol)
else:
raise error
if not file_proto:
raise KeyError('Cannot find a file containing %s' % symbol)
return self._ConvertFileProtoToFileDescriptor(file_proto)
def FindMessageTypeByName(self, full_name):
"""Loads the named descriptor from the pool.
Args:
full_name: The full name of the descriptor to load.
Returns:
The descriptor for the named type.
"""
full_name = full_name.lstrip('.') # fix inconsistent qualified name formats
if full_name not in self._descriptors:
self.FindFileContainingSymbol(full_name)
return self._descriptors[full_name]
def FindEnumTypeByName(self, full_name):
"""Loads the named enum descriptor from the pool.
Args:
full_name: The full name of the enum descriptor to load.
Returns:
The enum descriptor for the named type.
"""
full_name = full_name.lstrip('.') # fix inconsistent qualified name formats
if full_name not in self._enum_descriptors:
self.FindFileContainingSymbol(full_name)
return self._enum_descriptors[full_name]
def _ConvertFileProtoToFileDescriptor(self, file_proto):
"""Creates a FileDescriptor from a proto or returns a cached copy.
This method also has the side effect of loading all the symbols found in
the file into the appropriate dictionaries in the pool.
Args:
file_proto: The proto to convert.
Returns:
A FileDescriptor matching the passed in proto.
"""
if file_proto.name not in self._file_descriptors:
file_descriptor = descriptor.FileDescriptor(
name=file_proto.name,
package=file_proto.package,
options=file_proto.options,
serialized_pb=file_proto.SerializeToString())
scope = {}
dependencies = list(self._GetDeps(file_proto))
for dependency in dependencies:
dep_desc = self.FindFileByName(dependency.name)
dep_proto = descriptor_pb2.FileDescriptorProto.FromString(
dep_desc.serialized_pb)
package = '.' + dep_proto.package
package_prefix = package + '.'
def _strip_package(symbol):
if symbol.startswith(package_prefix):
return symbol[len(package_prefix):]
return symbol
symbols = list(self._ExtractSymbols(dep_proto.message_type, package))
scope.update(symbols)
scope.update((_strip_package(k), v) for k, v in symbols)
symbols = list(self._ExtractEnums(dep_proto.enum_type, package))
scope.update(symbols)
scope.update((_strip_package(k), v) for k, v in symbols)
for message_type in file_proto.message_type:
message_desc = self._ConvertMessageDescriptor(
message_type, file_proto.package, file_descriptor, scope)
file_descriptor.message_types_by_name[message_desc.name] = message_desc
for enum_type in file_proto.enum_type:
self._ConvertEnumDescriptor(enum_type, file_proto.package,
file_descriptor, None, scope)
for desc_proto in self._ExtractMessages(file_proto.message_type):
self._SetFieldTypes(desc_proto, scope)
for desc_proto in file_proto.message_type:
desc = scope[desc_proto.name]
file_descriptor.message_types_by_name[desc_proto.name] = desc
self.Add(file_proto)
self._file_descriptors[file_proto.name] = file_descriptor
return self._file_descriptors[file_proto.name]
def _ConvertMessageDescriptor(self, desc_proto, package=None, file_desc=None,
scope=None):
"""Adds the proto to the pool in the specified package.
Args:
desc_proto: The descriptor_pb2.DescriptorProto protobuf message.
package: The package the proto should be located in.
file_desc: The file containing this message.
scope: Dict mapping short and full symbols to message and enum types.
Returns:
The added descriptor.
"""
if package:
desc_name = '.'.join((package, desc_proto.name))
else:
desc_name = desc_proto.name
if file_desc is None:
file_name = None
else:
file_name = file_desc.name
if scope is None:
scope = {}
nested = [
self._ConvertMessageDescriptor(nested, desc_name, file_desc, scope)
for nested in desc_proto.nested_type]
enums = [
self._ConvertEnumDescriptor(enum, desc_name, file_desc, None, scope)
for enum in desc_proto.enum_type]
fields = [self._MakeFieldDescriptor(field, desc_name, index)
for index, field in enumerate(desc_proto.field)]
extensions = [self._MakeFieldDescriptor(extension, desc_name, True)
for index, extension in enumerate(desc_proto.extension)]
extension_ranges = [(r.start, r.end) for r in desc_proto.extension_range]
if extension_ranges:
is_extendable = True
else:
is_extendable = False
desc = descriptor.Descriptor(
name=desc_proto.name,
full_name=desc_name,
filename=file_name,
containing_type=None,
fields=fields,
nested_types=nested,
enum_types=enums,
extensions=extensions,
options=desc_proto.options,
is_extendable=is_extendable,
extension_ranges=extension_ranges,
file=file_desc,
serialized_start=None,
serialized_end=None)
for nested in desc.nested_types:
nested.containing_type = desc
for enum in desc.enum_types:
enum.containing_type = desc
scope[desc_proto.name] = desc
scope['.' + desc_name] = desc
self._descriptors[desc_name] = desc
return desc
def _ConvertEnumDescriptor(self, enum_proto, package=None, file_desc=None,
containing_type=None, scope=None):
"""Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf.
Args:
enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the enum descriptor.
containing_type: The type containing this enum.
scope: Scope containing available types.
Returns:
The added descriptor
"""
if package:
enum_name = '.'.join((package, enum_proto.name))
else:
enum_name = enum_proto.name
if file_desc is None:
file_name = None
else:
file_name = file_desc.name
values = [self._MakeEnumValueDescriptor(value, index)
for index, value in enumerate(enum_proto.value)]
desc = descriptor.EnumDescriptor(name=enum_proto.name,
full_name=enum_name,
filename=file_name,
file=file_desc,
values=values,
containing_type=containing_type,
options=enum_proto.options)
scope[enum_proto.name] = desc
scope['.%s' % enum_name] = desc
self._enum_descriptors[enum_name] = desc
return desc
def _MakeFieldDescriptor(self, field_proto, message_name, index,
is_extension=False):
"""Creates a field descriptor from a FieldDescriptorProto.
For message and enum type fields, this method will do a look up
in the pool for the appropriate descriptor for that type. If it
is unavailable, it will fall back to the _source function to
create it. If this type is still unavailable, construction will
fail.
Args:
field_proto: The proto describing the field.
message_name: The name of the containing message.
index: Index of the field
is_extension: Indication that this field is for an extension.
Returns:
An initialized FieldDescriptor object
"""
if message_name:
full_name = '.'.join((message_name, field_proto.name))
else:
full_name = field_proto.name
return descriptor.FieldDescriptor(
name=field_proto.name,
full_name=full_name,
index=index,
number=field_proto.number,
type=field_proto.type,
cpp_type=None,
message_type=None,
enum_type=None,
containing_type=None,
label=field_proto.label,
has_default_value=False,
default_value=None,
is_extension=is_extension,
extension_scope=None,
options=field_proto.options)
def _SetFieldTypes(self, desc_proto, scope):
"""Sets the field's type, cpp_type, message_type and enum_type.
Args:
desc_proto: The message descriptor to update.
scope: Enclosing scope of available types.
"""
desc = scope[desc_proto.name]
for field_proto, field_desc in zip(desc_proto.field, desc.fields):
if field_proto.type_name:
type_name = field_proto.type_name
if type_name not in scope:
type_name = '.' + type_name
desc = scope[type_name]
else:
desc = None
if not field_proto.HasField('type'):
if isinstance(desc, descriptor.Descriptor):
field_proto.type = descriptor.FieldDescriptor.TYPE_MESSAGE
else:
field_proto.type = descriptor.FieldDescriptor.TYPE_ENUM
field_desc.cpp_type = descriptor.FieldDescriptor.ProtoTypeToCppProtoType(
field_proto.type)
if (field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE
or field_proto.type == descriptor.FieldDescriptor.TYPE_GROUP):
field_desc.message_type = desc
if field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:
field_desc.enum_type = desc
if field_proto.label == descriptor.FieldDescriptor.LABEL_REPEATED:
field_desc.has_default = False
field_desc.default_value = []
elif field_proto.HasField('default_value'):
field_desc.has_default = True
if (field_proto.type == descriptor.FieldDescriptor.TYPE_DOUBLE or
field_proto.type == descriptor.FieldDescriptor.TYPE_FLOAT):
field_desc.default_value = float(field_proto.default_value)
elif field_proto.type == descriptor.FieldDescriptor.TYPE_STRING:
field_desc.default_value = field_proto.default_value
elif field_proto.type == descriptor.FieldDescriptor.TYPE_BOOL:
field_desc.default_value = field_proto.default_value.lower() == 'true'
elif field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:
field_desc.default_value = field_desc.enum_type.values_by_name[
field_proto.default_value].index
else:
field_desc.default_value = int(field_proto.default_value)
else:
field_desc.has_default = False
field_desc.default_value = None
field_desc.type = field_proto.type
for nested_type in desc_proto.nested_type:
self._SetFieldTypes(nested_type, scope)
def _MakeEnumValueDescriptor(self, value_proto, index):
"""Creates a enum value descriptor object from a enum value proto.
Args:
value_proto: The proto describing the enum value.
index: The index of the enum value.
Returns:
An initialized EnumValueDescriptor object.
"""
return descriptor.EnumValueDescriptor(
name=value_proto.name,
index=index,
number=value_proto.number,
options=value_proto.options,
type=None)
def _ExtractSymbols(self, desc_protos, package):
"""Pulls out all the symbols from descriptor protos.
Args:
desc_protos: The protos to extract symbols from.
package: The package containing the descriptor type.
Yields:
A two element tuple of the type name and descriptor object.
"""
for desc_proto in desc_protos:
if package:
message_name = '.'.join((package, desc_proto.name))
else:
message_name = desc_proto.name
message_desc = self.FindMessageTypeByName(message_name)
yield (message_name, message_desc)
for symbol in self._ExtractSymbols(desc_proto.nested_type, message_name):
yield symbol
for symbol in self._ExtractEnums(desc_proto.enum_type, message_name):
yield symbol
def _ExtractEnums(self, enum_protos, package):
"""Pulls out all the symbols from enum protos.
Args:
enum_protos: The protos to extract symbols from.
package: The package containing the enum type.
Yields:
A two element tuple of the type name and enum descriptor object.
"""
for enum_proto in enum_protos:
if package:
enum_name = '.'.join((package, enum_proto.name))
else:
enum_name = enum_proto.name
enum_desc = self.FindEnumTypeByName(enum_name)
yield (enum_name, enum_desc)
def _ExtractMessages(self, desc_protos):
"""Pulls out all the message protos from descriptos.
Args:
desc_protos: The protos to extract symbols from.
Yields:
Descriptor protos.
"""
for desc_proto in desc_protos:
yield desc_proto
for message in self._ExtractMessages(desc_proto.nested_type):
yield message
def _GetDeps(self, file_proto):
"""Recursively finds dependencies for file protos.
Args:
file_proto: The proto to get dependencies from.
Yields:
Each direct and indirect dependency.
"""
for dependency in file_proto.dependency:
dep_desc = self.FindFileByName(dependency)
dep_proto = descriptor_pb2.FileDescriptorProto.FromString(
dep_desc.serialized_pb)
yield dep_proto
for parent_dep in self._GetDeps(dep_proto):
yield parent_dep
|
bsd-3-clause
|
[
3,
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
17473,
28131,
5453,
370,
675,
465,
282,
3970,
367,
4104,
18,
15428,
14,
199,
199,
1918,
28131,
5453,
365,
1202,
315,
406,
8923,
543,
282,
28131,
7243,
370,
11075,
199,
65,
3245,
402,
4113,
3335,
15428,
367,
675,
1380,
18774,
6425,
199,
1188,
2943,
737,
8836,
14,
199,
199,
1858,
4750,
13103,
4113,
19383,
1077,
506,
1202,
4799,
4621,
4046,
701,
199,
1589,
4113,
3335,
6365,
4744,
14,
961,
1077,
1454,
506,
1202,
1380,
314,
730,
402,
199,
3922,
19383,
1202,
315,
376,
4223,
503,
3555,
3913,
506,
876,
27248,
14,
199,
199,
3655,
674,
365,
282,
23669,
6688,
2893,
641,
4212,
370,
675,
642,
1021,
26,
819,
4203,
275,
28131,
5453,
342,
523,
570,
63,
4120,
63,
27478,
275,
359,
2263,
1622,
523,
367,
570,
63,
4120,
63,
2625,
315,
570,
63,
4120,
63,
27478,
26,
272,
4203,
14,
1123,
8,
493,
63,
4120,
63,
2625,
9,
523,
3002,
63,
1188,
63,
4120,
275,
4203,
14,
6591,
12091,
11190,
360,
3972,
14,
2491,
14,
12091,
358,
199,
199,
1918,
1245,
5872,
883,
506,
1202,
315,
22888,
543,
314,
1245,
63,
3702,
199,
578,
315,
1865,
370,
1218,
282,
4113,
3335,
1021,
626,
883,
506,
5737,
436,
199,
16167,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
569,
29640,
475,
4674,
32,
3098,
14,
957,
334,
45,
6796,
4005,
4674,
3171,
199,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
504,
6233,
14,
7204,
492,
5872,
199,
504,
6233,
14,
7204,
492,
5872,
63,
4659,
421,
199,
533,
28131,
5453,
8,
785,
304,
523,
408,
33,
3245,
402,
25886,
83,
18774,
14701,
701,
5872,
4104,
83,
1041,
819,
347,
636,
826,
721,
277,
12,
5872,
63,
697,
29,
403,
304,
272,
408,
23489,
282,
15553,
402,
4104,
17893,
83,
14,
339,
710,
5872,
63,
697,
1423,
370,
314,
3787,
365,
2741,
370,
2040,
272,
27877,
570,
5872,
4104,
4237,
1233,
370,
506,
15572,
641,
29237,
14,
1626,
272,
2893,
3955,
506,
376,
4514,
1314,
911,
1586,
436,
6555,
282,
570,
272,
2013,
315,
282,
1240,
370,
6668,
1173,
11190,
342,
436,
440,
4409,
314,
1240,
370,
2654,
342,
272,
737,
1006,
14,
24288,
687,
642,
3050,
911,
506,
6328,
14448,
2348,
465,
5521,
14,
339,
3033,
26,
489,
5872,
63,
697,
26,
437,
13851,
1350,
402,
570,
15428,
14,
272,
408,
339,
291,
423,
4672,
63,
697,
275,
5872,
63,
4659,
14,
4311,
7243,
342,
272,
291,
423,
4120,
63,
697,
275,
5872,
63,
697,
272,
291,
423,
17752,
275,
1052,
272,
291,
423,
4869,
63,
17752,
275,
1052,
272,
291,
423,
493,
63,
17752,
275,
1052,
819,
347,
2654,
8,
277,
12,
570,
63,
3257,
63,
2625,
304,
272,
408,
14995,
314,
3814,
4311,
8548,
436,
2399,
2943,
370,
642,
4203,
14,
339,
3033,
26,
489,
570,
63,
3257,
63,
2625,
26,
710,
3814,
4311,
8548,
370,
1050,
14,
272,
408,
339,
291,
423,
4672,
63,
697,
14,
1123,
8,
493,
63,
3257,
63,
2625,
9,
819,
347,
6668,
1173,
11190,
8,
277,
12,
570,
63,
354,
304,
272,
408,
14426,
282,
3814,
4311,
701,
570,
536,
14,
339,
3033,
26,
489,
570,
63,
354,
26,
710,
931,
370,
314,
570,
370,
664,
282,
5872,
367,
14,
339,
1803,
26,
489,
437,
3814,
4311,
367,
314,
4310,
570,
14,
339,
6218,
26,
489,
4067,
26,
340,
314,
570,
883,
440,
506,
1911,
315,
314,
4203,
14,
272,
408,
339,
862,
26,
489,
570,
63,
2625,
275,
291,
423,
4672,
63,
697,
14,
6591,
1173,
11190,
8,
493,
63,
354,
9,
272,
871,
4067,
465,
1125,
26,
489,
340,
291,
423,
4120,
63,
697,
26,
267,
570,
63,
2625,
275,
291,
423,
4120,
63,
697,
14,
6591,
1173,
11190,
8,
493,
63,
354,
9,
489,
587,
26,
267,
746,
1125,
272,
340,
440,
570,
63,
2625,
26,
489,
746,
4067,
360,
6612,
2342,
282,
570,
4310,
450,
83,
7,
450,
570,
63,
354,
9,
272,
372,
291,
423,
7306,
1173,
8548,
1378,
23859,
8,
493,
63,
2625,
9,
819,
347,
6668,
1173,
714,
24522,
8169,
8,
277,
12,
5272,
304,
272
] |
[
11557,
699,
3043,
1192,
446,
4475,
1159,
666,
1640,
1461,
1475,
199,
3,
1898,
9079,
4475,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
7204,
15,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
17473,
28131,
5453,
370,
675,
465,
282,
3970,
367,
4104,
18,
15428,
14,
199,
199,
1918,
28131,
5453,
365,
1202,
315,
406,
8923,
543,
282,
28131,
7243,
370,
11075,
199,
65,
3245,
402,
4113,
3335,
15428,
367,
675,
1380,
18774,
6425,
199,
1188,
2943,
737,
8836,
14,
199,
199,
1858,
4750,
13103,
4113,
19383,
1077,
506,
1202,
4799,
4621,
4046,
701,
199,
1589,
4113,
3335,
6365,
4744,
14,
961,
1077,
1454,
506,
1202,
1380,
314,
730,
402,
199,
3922,
19383,
1202,
315,
376,
4223,
503,
3555,
3913,
506,
876,
27248,
14,
199,
199,
3655,
674,
365,
282,
23669,
6688,
2893,
641,
4212,
370,
675,
642,
1021,
26,
819,
4203,
275,
28131,
5453,
342,
523,
570,
63,
4120,
63,
27478,
275,
359,
2263,
1622,
523,
367,
570,
63,
4120,
63,
2625,
315,
570,
63,
4120,
63,
27478,
26,
272,
4203,
14,
1123,
8,
493,
63,
4120,
63,
2625,
9,
523,
3002,
63,
1188,
63,
4120,
275,
4203,
14,
6591,
12091,
11190,
360,
3972,
14,
2491,
14,
12091,
358,
199,
199,
1918,
1245,
5872,
883,
506,
1202,
315,
22888,
543,
314,
1245,
63,
3702,
199,
578,
315,
1865,
370,
1218,
282,
4113,
3335,
1021,
626,
883,
506,
5737,
436,
199,
16167,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
569,
29640,
475,
4674,
32,
3098,
14,
957,
334,
45,
6796,
4005,
4674,
3171,
199,
199,
504,
6233,
14,
7204,
492,
5872,
63,
3317,
18,
199,
504,
6233,
14,
7204,
492,
5872,
199,
504,
6233,
14,
7204,
492,
5872,
63,
4659,
421,
199,
533,
28131,
5453,
8,
785,
304,
523,
408,
33,
3245,
402,
25886,
83,
18774,
14701,
701,
5872,
4104,
83,
1041,
819,
347,
636,
826,
721,
277,
12,
5872,
63,
697,
29,
403,
304,
272,
408,
23489,
282,
15553,
402,
4104,
17893,
83,
14,
339,
710,
5872,
63,
697,
1423,
370,
314,
3787,
365,
2741,
370,
2040,
272,
27877,
570,
5872,
4104,
4237,
1233,
370,
506,
15572,
641,
29237,
14,
1626,
272,
2893,
3955,
506,
376,
4514,
1314,
911,
1586,
436,
6555,
282,
570,
272,
2013,
315,
282,
1240,
370,
6668,
1173,
11190,
342,
436,
440,
4409,
314,
1240,
370,
2654,
342,
272,
737,
1006,
14,
24288,
687,
642,
3050,
911,
506,
6328,
14448,
2348,
465,
5521,
14,
339,
3033,
26,
489,
5872,
63,
697,
26,
437,
13851,
1350,
402,
570,
15428,
14,
272,
408,
339,
291,
423,
4672,
63,
697,
275,
5872,
63,
4659,
14,
4311,
7243,
342,
272,
291,
423,
4120,
63,
697,
275,
5872,
63,
697,
272,
291,
423,
17752,
275,
1052,
272,
291,
423,
4869,
63,
17752,
275,
1052,
272,
291,
423,
493,
63,
17752,
275,
1052,
819,
347,
2654,
8,
277,
12,
570,
63,
3257,
63,
2625,
304,
272,
408,
14995,
314,
3814,
4311,
8548,
436,
2399,
2943,
370,
642,
4203,
14,
339,
3033,
26,
489,
570,
63,
3257,
63,
2625,
26,
710,
3814,
4311,
8548,
370,
1050,
14,
272,
408,
339,
291,
423,
4672,
63,
697,
14,
1123,
8,
493,
63,
3257,
63,
2625,
9,
819,
347,
6668,
1173,
11190,
8,
277,
12,
570,
63,
354,
304,
272,
408,
14426,
282,
3814,
4311,
701,
570,
536,
14,
339,
3033,
26,
489,
570,
63,
354,
26,
710,
931,
370,
314,
570,
370,
664,
282,
5872,
367,
14,
339,
1803,
26,
489,
437,
3814,
4311,
367,
314,
4310,
570,
14,
339,
6218,
26,
489,
4067,
26,
340,
314,
570,
883,
440,
506,
1911,
315,
314,
4203,
14,
272,
408,
339,
862,
26,
489,
570,
63,
2625,
275,
291,
423,
4672,
63,
697,
14,
6591,
1173,
11190,
8,
493,
63,
354,
9,
272,
871,
4067,
465,
1125,
26,
489,
340,
291,
423,
4120,
63,
697,
26,
267,
570,
63,
2625,
275,
291,
423,
4120,
63,
697,
14,
6591,
1173,
11190,
8,
493,
63,
354,
9,
489,
587,
26,
267,
746,
1125,
272,
340,
440,
570,
63,
2625,
26,
489,
746,
4067,
360,
6612,
2342,
282,
570,
4310,
450,
83,
7,
450,
570,
63,
354,
9,
272,
372,
291,
423,
7306,
1173,
8548,
1378,
23859,
8,
493,
63,
2625,
9,
819,
347,
6668,
1173,
714,
24522,
8169,
8,
277,
12,
5272,
304,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
michalliu/OpenWrt-Firefly-Libraries
|
staging_dir/host/lib/python3.4/distutils/tests/test_clean.py
|
94
|
1467
|
"""Tests for distutils.command.clean."""
import sys
import os
import unittest
import getpass
from distutils.command.clean import clean
from distutils.tests import support
from test.support import run_unittest
class cleanTestCase(support.TempdirManager,
support.LoggingSilencer,
unittest.TestCase):
def test_simple_run(self):
pkg_dir, dist = self.create_dist()
cmd = clean(dist)
# let's add some elements clean should remove
dirs = [(d, os.path.join(pkg_dir, d))
for d in ('build_temp', 'build_lib', 'bdist_base',
'build_scripts', 'build_base')]
for name, path in dirs:
os.mkdir(path)
setattr(cmd, name, path)
if name == 'build_base':
continue
for f in ('one', 'two', 'three'):
self.write_file(os.path.join(path, f))
# let's run the command
cmd.all = 1
cmd.ensure_finalized()
cmd.run()
# make sure the files where removed
for name, path in dirs:
self.assertFalse(os.path.exists(path),
'%s was not removed' % path)
# let's run the command again (should spit warnings but succeed)
cmd.all = 1
cmd.ensure_finalized()
cmd.run()
def test_suite():
return unittest.makeSuite(cleanTestCase)
if __name__ == "__main__":
run_unittest(test_suite())
|
gpl-2.0
|
[
624,
2925,
367,
7065,
14,
1531,
14,
3118,
1041,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
18354,
199,
199,
504,
7065,
14,
1531,
14,
3118,
492,
3633,
199,
504,
7065,
14,
2219,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
533,
3633,
1746,
8,
4058,
14,
6530,
694,
2988,
12,
490,
2291,
14,
14054,
51,
441,
78,
2247,
12,
490,
2882,
14,
1746,
304,
339,
347,
511,
63,
4129,
63,
1065,
8,
277,
304,
267,
5496,
63,
694,
12,
2917,
275,
291,
14,
981,
63,
2686,
342,
267,
2088,
275,
3633,
8,
2686,
9,
398,
327,
4691,
1159,
1050,
2005,
4008,
3633,
1077,
2813,
267,
7606,
275,
3842,
68,
12,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
366,
430,
355,
367,
366,
315,
661,
1506,
63,
808,
297,
283,
1506,
63,
773,
297,
283,
17403,
63,
1095,
297,
355,
283,
1506,
63,
6429,
297,
283,
1506,
63,
1095,
5440,
398,
367,
536,
12,
931,
315,
7606,
26,
288,
747,
14,
8215,
8,
515,
9,
288,
5371,
8,
1760,
12,
536,
12,
931,
9,
288,
340,
536,
508,
283,
1506,
63,
1095,
356,
355,
1980,
288,
367,
289,
315,
661,
368,
297,
283,
5601,
297,
283,
10480,
735,
355,
291,
14,
952,
63,
493,
8,
736,
14,
515,
14,
904,
8,
515,
12,
289,
430,
398,
327,
4691,
1159,
1255,
314,
1414,
267,
2088,
14,
452,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
1852,
3238,
314,
1584,
2382,
4829,
267,
367,
536,
12,
931,
315,
7606,
26,
288,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
8,
515,
395,
586,
1543,
83,
1990,
440,
4829,
7,
450,
931,
9,
398,
327,
4691,
1159,
1255,
314,
1414,
4020,
334,
5626,
2249,
390,
3598,
1325,
17961,
9,
267,
2088,
14,
452,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
199,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
3118,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
2796,
8,
396,
63,
5768,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2925,
367,
7065,
14,
1531,
14,
3118,
1041,
199,
646,
984,
199,
646,
747,
199,
646,
2882,
199,
646,
18354,
199,
199,
504,
7065,
14,
1531,
14,
3118,
492,
3633,
199,
504,
7065,
14,
2219,
492,
2291,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
533,
3633,
1746,
8,
4058,
14,
6530,
694,
2988,
12,
490,
2291,
14,
14054,
51,
441,
78,
2247,
12,
490,
2882,
14,
1746,
304,
339,
347,
511,
63,
4129,
63,
1065,
8,
277,
304,
267,
5496,
63,
694,
12,
2917,
275,
291,
14,
981,
63,
2686,
342,
267,
2088,
275,
3633,
8,
2686,
9,
398,
327,
4691,
1159,
1050,
2005,
4008,
3633,
1077,
2813,
267,
7606,
275,
3842,
68,
12,
747,
14,
515,
14,
904,
8,
4600,
63,
694,
12,
366,
430,
355,
367,
366,
315,
661,
1506,
63,
808,
297,
283,
1506,
63,
773,
297,
283,
17403,
63,
1095,
297,
355,
283,
1506,
63,
6429,
297,
283,
1506,
63,
1095,
5440,
398,
367,
536,
12,
931,
315,
7606,
26,
288,
747,
14,
8215,
8,
515,
9,
288,
5371,
8,
1760,
12,
536,
12,
931,
9,
288,
340,
536,
508,
283,
1506,
63,
1095,
356,
355,
1980,
288,
367,
289,
315,
661,
368,
297,
283,
5601,
297,
283,
10480,
735,
355,
291,
14,
952,
63,
493,
8,
736,
14,
515,
14,
904,
8,
515,
12,
289,
430,
398,
327,
4691,
1159,
1255,
314,
1414,
267,
2088,
14,
452,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
398,
327,
1852,
3238,
314,
1584,
2382,
4829,
267,
367,
536,
12,
931,
315,
7606,
26,
288,
291,
14,
3334,
8,
736,
14,
515,
14,
2444,
8,
515,
395,
586,
1543,
83,
1990,
440,
4829,
7,
450,
931,
9,
398,
327,
4691,
1159,
1255,
314,
1414,
4020,
334,
5626,
2249,
390,
3598,
1325,
17961,
9,
267,
2088,
14,
452,
275,
413,
267,
2088,
14,
7505,
63,
19231,
342,
267,
2088,
14,
1065,
342,
199,
199,
318,
511,
63,
5768,
837,
272,
372,
2882,
14,
18275,
8,
3118,
1746,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
1255,
63,
2796,
8,
396,
63,
5768,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Mixser/django
|
django/contrib/admindocs/utils.py
|
411
|
4187
|
"Misc. utility functions/classes for admin documentation generator."
import re
from email.errors import HeaderParseError
from email.parser import HeaderParser
from django.core.urlresolvers import reverse
from django.utils.encoding import force_bytes
from django.utils.safestring import mark_safe
try:
import docutils.core
import docutils.nodes
import docutils.parsers.rst.roles
except ImportError:
docutils_is_available = False
else:
docutils_is_available = True
def trim_docstring(docstring):
"""
Uniformly trim leading/trailing whitespace from docstrings.
Based on https://www.python.org/dev/peps/pep-0257/#handling-docstring-indentation
"""
if not docstring or not docstring.strip():
return ''
# Convert tabs to spaces and split into lines
lines = docstring.expandtabs().splitlines()
indent = min(len(line) - len(line.lstrip()) for line in lines if line.lstrip())
trimmed = [lines[0].lstrip()] + [line[indent:].rstrip() for line in lines[1:]]
return "\n".join(trimmed).strip()
def parse_docstring(docstring):
"""
Parse out the parts of a docstring. Return (title, body, metadata).
"""
docstring = trim_docstring(docstring)
parts = re.split(r'\n{2,}', docstring)
title = parts[0]
if len(parts) == 1:
body = ''
metadata = {}
else:
parser = HeaderParser()
try:
metadata = parser.parsestr(parts[-1])
except HeaderParseError:
metadata = {}
body = "\n\n".join(parts[1:])
else:
metadata = dict(metadata.items())
if metadata:
body = "\n\n".join(parts[1:-1])
else:
body = "\n\n".join(parts[1:])
return title, body, metadata
def parse_rst(text, default_reference_context, thing_being_parsed=None):
"""
Convert the string from reST to an XHTML fragment.
"""
overrides = {
'doctitle_xform': True,
'inital_header_level': 3,
"default_reference_context": default_reference_context,
"link_base": reverse('django-admindocs-docroot').rstrip('/'),
'raw_enabled': False,
'file_insertion_enabled': False,
}
if thing_being_parsed:
thing_being_parsed = force_bytes("<%s>" % thing_being_parsed)
# Wrap ``text`` in some reST that sets the default role to ``cmsreference``,
# then restores it.
source = """
.. default-role:: cmsreference
%s
.. default-role::
"""
parts = docutils.core.publish_parts(source % text,
source_path=thing_being_parsed, destination_path=None,
writer_name='html', settings_overrides=overrides)
return mark_safe(parts['fragment'])
#
# reST roles
#
ROLES = {
'model': '%s/models/%s/',
'view': '%s/views/%s/',
'template': '%s/templates/%s/',
'filter': '%s/filters/#%s',
'tag': '%s/tags/#%s',
}
def create_reference_role(rolename, urlbase):
def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
if options is None:
options = {}
if content is None:
content = []
node = docutils.nodes.reference(
rawtext,
text,
refuri=(urlbase % (
inliner.document.settings.link_base,
text.lower(),
)),
**options
)
return [node], []
docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
if options is None:
options = {}
if content is None:
content = []
context = inliner.document.settings.default_reference_context
node = docutils.nodes.reference(
rawtext,
text,
refuri=(ROLES[context] % (
inliner.document.settings.link_base,
text.lower(),
)),
**options
)
return [node], []
if docutils_is_available:
docutils.parsers.rst.roles.register_canonical_role('cmsreference', default_reference_role)
for name, urlbase in ROLES.items():
create_reference_role(name, urlbase)
|
bsd-3-clause
|
[
2,
29926,
14,
11420,
3423,
15,
2888,
367,
4628,
3794,
4306,
2122,
199,
199,
646,
295,
199,
504,
3031,
14,
2550,
492,
10240,
9123,
199,
504,
3031,
14,
2087,
492,
10240,
2842,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2394,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
893,
26,
272,
492,
18382,
14,
1018,
272,
492,
18382,
14,
2415,
272,
492,
18382,
14,
11531,
14,
8332,
14,
8050,
199,
2590,
3545,
26,
272,
18382,
63,
374,
63,
4561,
275,
756,
199,
2836,
26,
272,
18382,
63,
374,
63,
4561,
275,
715,
421,
199,
318,
11639,
63,
12485,
8,
12485,
304,
272,
408,
272,
1910,
8241,
590,
11639,
9186,
15,
15910,
8139,
687,
20964,
14,
339,
21311,
641,
4178,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
15,
12636,
13,
16,
11551,
12645,
22273,
13,
12485,
13,
25152,
272,
408,
272,
340,
440,
9214,
503,
440,
9214,
14,
1913,
837,
267,
372,
2125,
272,
327,
7905,
12187,
370,
7883,
436,
3715,
1901,
2385,
272,
2385,
275,
9214,
14,
30386,
1252,
7644,
342,
272,
4363,
275,
1748,
8,
552,
8,
604,
9,
446,
822,
8,
604,
14,
10124,
1012,
367,
1004,
315,
2385,
340,
1004,
14,
10124,
1012,
272,
24196,
275,
359,
1278,
59,
16,
1055,
10124,
5106,
435,
359,
604,
59,
3724,
11455,
6735,
342,
367,
1004,
315,
2385,
59,
17,
21316,
272,
372,
1867,
78,
1674,
904,
8,
12263,
3594,
680,
1913,
342,
421,
199,
318,
2198,
63,
12485,
8,
12485,
304,
272,
408,
272,
6077,
734,
314,
4184,
402,
282,
9214,
14,
221,
1432,
334,
1213,
12,
2396,
12,
3341,
680,
272,
408,
272,
9214,
275,
11639,
63,
12485,
8,
12485,
9,
272,
4184,
275,
295,
14,
1294,
8,
82,
1154,
78,
91,
18,
12,
7293,
9214,
9,
272,
2538,
275,
4184,
59,
16,
61,
272,
340,
822,
8,
4181,
9,
508,
413,
26,
267,
2396,
275,
2125,
267,
3341,
275,
1052,
272,
587,
26,
267,
1798,
275,
10240,
2842,
342,
267,
862,
26,
288,
3341,
275,
1798,
14,
1122,
495,
8,
4181,
1988,
17,
566,
267,
871,
10240,
9123,
26,
288,
3341,
275,
1052,
288,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
5728,
267,
587,
26,
288,
3341,
275,
1211,
8,
2343,
14,
1744,
1012,
288,
340,
3341,
26,
355,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
6809,
17,
566,
288,
587,
26,
355,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
5728,
272,
372,
2538,
12,
2396,
12,
3341,
421,
199,
318,
2198,
63,
8332,
8,
505,
12,
849,
63,
4443,
63,
1100,
12,
8377,
63,
1235,
316,
63,
6751,
29,
403,
304,
272,
408,
272,
7905,
314,
1059,
687,
20883,
370,
376,
26223,
7956,
14,
272,
408,
272,
10580,
275,
469,
267,
283,
1301,
1213,
63,
24226,
356,
715,
12,
267,
283,
826,
279,
63,
1291,
63,
1896,
356,
650,
12,
267,
298,
885,
63,
4443,
63,
1100,
582,
849,
63,
4443,
63,
1100,
12,
267,
298,
1073,
63,
1095,
582,
3837,
360,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
1959,
6735,
2336,
659,
267,
283,
1773,
63,
3827,
356,
756,
12,
267,
283,
493,
63,
14739,
63,
3827,
356,
756,
12,
272,
789,
272,
340,
8377,
63,
1235,
316,
63,
6751,
26,
267,
8377,
63,
1235,
316,
63,
6751,
275,
3542,
63,
2394,
6757,
5,
83,
4335,
450,
8377,
63,
1235,
316,
63,
6751,
9,
272,
327,
20322,
1124,
505,
1040,
315,
2005,
20883,
626,
5951,
314,
849,
4719,
370,
1124,
10781,
4443,
4542,
272,
327,
2066,
4618,
7944,
652,
14,
272,
1350,
275,
408,
199,
703,
849,
13,
3756,
447,
19240,
4443,
199,
199,
5,
83,
199,
199,
703,
849,
13,
3756,
447,
199,
624,
272,
4184,
275,
18382,
14,
1018,
14,
4763,
63,
4181,
8,
1365,
450,
1318,
12,
355,
1350,
63,
515,
29,
2127,
63,
1235,
316,
63,
6751,
12,
5724,
63,
515,
29,
403,
12,
355,
7060,
63,
354,
534,
1360,
297,
2202,
63,
12867,
29,
12867,
9,
272,
372,
2216,
63,
3489,
8,
4181,
459,
7677,
1105,
199,
199,
3,
199,
3,
20883,
11689,
199,
3,
199,
6245,
654,
275,
469,
272,
283,
1238,
356,
1543,
83,
15,
992,
3149,
83,
3678,
272,
283,
1345,
356,
1543,
83,
15,
4196,
3149,
83,
3678,
272,
283,
1160,
356,
1543,
83,
15,
5876,
3149,
83,
3678,
272,
283,
1541,
356,
1543,
83,
15,
4273,
12645,
5,
83,
297,
272,
283,
1450,
356,
1543,
83,
15,
2969,
12645,
5,
83,
297,
199,
93,
421,
199,
318,
1218,
63,
4443,
63,
3756,
8,
3756,
354,
12,
1166,
1095,
304,
272,
347,
485,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1511,
29,
403,
12,
1564,
29,
403,
304,
267,
340,
1511,
365,
488,
26,
288,
1511,
275,
1052,
267,
340,
1564,
365,
488,
26,
288,
1564,
275,
942,
267,
1031,
275,
18382,
14,
2415,
14,
4443,
8,
288,
3066,
505,
12,
288,
1318,
12,
288,
2984,
2302,
2687,
633,
1095,
450,
334,
355,
315,
31338,
14,
3554,
14,
1751,
14,
1073,
63,
1095,
12,
355,
1318,
14,
2325,
1062,
288,
22583,
288,
1011,
1419,
267,
776,
267,
372,
359,
932,
467,
942,
272,
18382,
14,
11531,
14,
8332,
14,
8050,
14,
2683,
63,
13109,
63,
3756,
8,
3756,
354,
12,
485,
3756,
9,
421,
199,
318,
849,
63,
4443,
63,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1511,
29,
403,
12,
1564,
29,
403,
304,
272,
340,
1511,
365,
488,
26,
267,
1511,
275,
1052,
272,
340,
1564,
365,
488,
26,
267,
1564,
275,
942,
272,
1067,
275,
315,
31338,
14,
3554,
14,
1751,
14,
885,
63,
4443,
63,
1100,
272,
1031,
275,
18382,
14,
2415,
14,
4443,
8,
267,
3066,
505,
12,
267,
1318,
12,
267,
2984,
2302,
2687,
6245,
654,
59,
1100,
61,
450,
334,
288,
315,
31338,
14,
3554,
14,
1751,
14,
1073,
63,
1095,
12,
288,
1318,
14,
2325,
1062,
267,
22583,
267,
1011,
1419,
272,
776,
272,
372,
359,
932,
467,
942,
199
] |
[
29926,
14,
11420,
3423,
15,
2888,
367,
4628,
3794,
4306,
2122,
199,
199,
646,
295,
199,
504,
3031,
14,
2550,
492,
10240,
9123,
199,
504,
3031,
14,
2087,
492,
10240,
2842,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2394,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
893,
26,
272,
492,
18382,
14,
1018,
272,
492,
18382,
14,
2415,
272,
492,
18382,
14,
11531,
14,
8332,
14,
8050,
199,
2590,
3545,
26,
272,
18382,
63,
374,
63,
4561,
275,
756,
199,
2836,
26,
272,
18382,
63,
374,
63,
4561,
275,
715,
421,
199,
318,
11639,
63,
12485,
8,
12485,
304,
272,
408,
272,
1910,
8241,
590,
11639,
9186,
15,
15910,
8139,
687,
20964,
14,
339,
21311,
641,
4178,
921,
1544,
14,
1548,
14,
1308,
15,
2374,
15,
321,
1190,
15,
12636,
13,
16,
11551,
12645,
22273,
13,
12485,
13,
25152,
272,
408,
272,
340,
440,
9214,
503,
440,
9214,
14,
1913,
837,
267,
372,
2125,
272,
327,
7905,
12187,
370,
7883,
436,
3715,
1901,
2385,
272,
2385,
275,
9214,
14,
30386,
1252,
7644,
342,
272,
4363,
275,
1748,
8,
552,
8,
604,
9,
446,
822,
8,
604,
14,
10124,
1012,
367,
1004,
315,
2385,
340,
1004,
14,
10124,
1012,
272,
24196,
275,
359,
1278,
59,
16,
1055,
10124,
5106,
435,
359,
604,
59,
3724,
11455,
6735,
342,
367,
1004,
315,
2385,
59,
17,
21316,
272,
372,
1867,
78,
1674,
904,
8,
12263,
3594,
680,
1913,
342,
421,
199,
318,
2198,
63,
12485,
8,
12485,
304,
272,
408,
272,
6077,
734,
314,
4184,
402,
282,
9214,
14,
221,
1432,
334,
1213,
12,
2396,
12,
3341,
680,
272,
408,
272,
9214,
275,
11639,
63,
12485,
8,
12485,
9,
272,
4184,
275,
295,
14,
1294,
8,
82,
1154,
78,
91,
18,
12,
7293,
9214,
9,
272,
2538,
275,
4184,
59,
16,
61,
272,
340,
822,
8,
4181,
9,
508,
413,
26,
267,
2396,
275,
2125,
267,
3341,
275,
1052,
272,
587,
26,
267,
1798,
275,
10240,
2842,
342,
267,
862,
26,
288,
3341,
275,
1798,
14,
1122,
495,
8,
4181,
1988,
17,
566,
267,
871,
10240,
9123,
26,
288,
3341,
275,
1052,
288,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
5728,
267,
587,
26,
288,
3341,
275,
1211,
8,
2343,
14,
1744,
1012,
288,
340,
3341,
26,
355,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
6809,
17,
566,
288,
587,
26,
355,
2396,
275,
1867,
78,
60,
78,
1674,
904,
8,
4181,
59,
17,
5728,
272,
372,
2538,
12,
2396,
12,
3341,
421,
199,
318,
2198,
63,
8332,
8,
505,
12,
849,
63,
4443,
63,
1100,
12,
8377,
63,
1235,
316,
63,
6751,
29,
403,
304,
272,
408,
272,
7905,
314,
1059,
687,
20883,
370,
376,
26223,
7956,
14,
272,
408,
272,
10580,
275,
469,
267,
283,
1301,
1213,
63,
24226,
356,
715,
12,
267,
283,
826,
279,
63,
1291,
63,
1896,
356,
650,
12,
267,
298,
885,
63,
4443,
63,
1100,
582,
849,
63,
4443,
63,
1100,
12,
267,
298,
1073,
63,
1095,
582,
3837,
360,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
1959,
6735,
2336,
659,
267,
283,
1773,
63,
3827,
356,
756,
12,
267,
283,
493,
63,
14739,
63,
3827,
356,
756,
12,
272,
789,
272,
340,
8377,
63,
1235,
316,
63,
6751,
26,
267,
8377,
63,
1235,
316,
63,
6751,
275,
3542,
63,
2394,
6757,
5,
83,
4335,
450,
8377,
63,
1235,
316,
63,
6751,
9,
272,
327,
20322,
1124,
505,
1040,
315,
2005,
20883,
626,
5951,
314,
849,
4719,
370,
1124,
10781,
4443,
4542,
272,
327,
2066,
4618,
7944,
652,
14,
272,
1350,
275,
408,
199,
703,
849,
13,
3756,
447,
19240,
4443,
199,
199,
5,
83,
199,
199,
703,
849,
13,
3756,
447,
199,
624,
272,
4184,
275,
18382,
14,
1018,
14,
4763,
63,
4181,
8,
1365,
450,
1318,
12,
355,
1350,
63,
515,
29,
2127,
63,
1235,
316,
63,
6751,
12,
5724,
63,
515,
29,
403,
12,
355,
7060,
63,
354,
534,
1360,
297,
2202,
63,
12867,
29,
12867,
9,
272,
372,
2216,
63,
3489,
8,
4181,
459,
7677,
1105,
199,
199,
3,
199,
3,
20883,
11689,
199,
3,
199,
6245,
654,
275,
469,
272,
283,
1238,
356,
1543,
83,
15,
992,
3149,
83,
3678,
272,
283,
1345,
356,
1543,
83,
15,
4196,
3149,
83,
3678,
272,
283,
1160,
356,
1543,
83,
15,
5876,
3149,
83,
3678,
272,
283,
1541,
356,
1543,
83,
15,
4273,
12645,
5,
83,
297,
272,
283,
1450,
356,
1543,
83,
15,
2969,
12645,
5,
83,
297,
199,
93,
421,
199,
318,
1218,
63,
4443,
63,
3756,
8,
3756,
354,
12,
1166,
1095,
304,
272,
347,
485,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1511,
29,
403,
12,
1564,
29,
403,
304,
267,
340,
1511,
365,
488,
26,
288,
1511,
275,
1052,
267,
340,
1564,
365,
488,
26,
288,
1564,
275,
942,
267,
1031,
275,
18382,
14,
2415,
14,
4443,
8,
288,
3066,
505,
12,
288,
1318,
12,
288,
2984,
2302,
2687,
633,
1095,
450,
334,
355,
315,
31338,
14,
3554,
14,
1751,
14,
1073,
63,
1095,
12,
355,
1318,
14,
2325,
1062,
288,
22583,
288,
1011,
1419,
267,
776,
267,
372,
359,
932,
467,
942,
272,
18382,
14,
11531,
14,
8332,
14,
8050,
14,
2683,
63,
13109,
63,
3756,
8,
3756,
354,
12,
485,
3756,
9,
421,
199,
318,
849,
63,
4443,
63,
3756,
8,
354,
12,
3066,
505,
12,
1318,
12,
5874,
12,
315,
31338,
12,
1511,
29,
403,
12,
1564,
29,
403,
304,
272,
340,
1511,
365,
488,
26,
267,
1511,
275,
1052,
272,
340,
1564,
365,
488,
26,
267,
1564,
275,
942,
272,
1067,
275,
315,
31338,
14,
3554,
14,
1751,
14,
885,
63,
4443,
63,
1100,
272,
1031,
275,
18382,
14,
2415,
14,
4443,
8,
267,
3066,
505,
12,
267,
1318,
12,
267,
2984,
2302,
2687,
6245,
654,
59,
1100,
61,
450,
334,
288,
315,
31338,
14,
3554,
14,
1751,
14,
1073,
63,
1095,
12,
288,
1318,
14,
2325,
1062,
267,
22583,
267,
1011,
1419,
272,
776,
272,
372,
359,
932,
467,
942,
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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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
] |
gisce/OCB
|
addons/account/report/account_general_ledger.py
|
53
|
15525
|
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2005-2006 CamptoCamp
# Copyright (c) 2006-2010 OpenERP S.A
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
##############################################################################
import time
from openerp.report import report_sxw
from common_report_header import common_report_header
class general_ledger(report_sxw.rml_parse, common_report_header):
_name = 'report.account.general.ledger'
def set_context(self, objects, data, ids, report_type=None):
new_ids = ids
obj_move = self.pool.get('account.move.line')
self.sortby = data['form'].get('sortby', 'sort_date')
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context',{}))
ctx2 = data['form'].get('used_context',{}).copy()
self.init_balance = data['form'].get('initial_balance', True)
if self.init_balance:
ctx2.update({'initial_bal': True})
self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx2)
self.display_account = data['form']['display_account']
self.target_move = data['form'].get('target_move', 'all')
ctx = self.context.copy()
ctx['fiscalyear'] = data['form']['fiscalyear_id']
if data['form']['filter'] == 'filter_period':
ctx['periods'] = data['form']['periods']
elif data['form']['filter'] == 'filter_date':
ctx['date_from'] = data['form']['date_from']
ctx['date_to'] = data['form']['date_to']
ctx['state'] = data['form']['target_move']
self.context.update(ctx)
if (data['model'] == 'ir.ui.menu'):
new_ids = [data['form']['chart_account_id']]
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
return super(general_ledger, self).set_context(objects, data, new_ids, report_type=report_type)
def __init__(self, cr, uid, name, context=None):
if context is None:
context = {}
super(general_ledger, self).__init__(cr, uid, name, context=context)
self.query = ""
self.tot_currency = 0.0
self.period_sql = ""
self.sold_accounts = {}
self.sortby = 'sort_date'
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_account': self._sum_debit_account,
'sum_credit_account': self._sum_credit_account,
'sum_balance_account': self._sum_balance_account,
'sum_currency_amount_account': self._sum_currency_amount_account,
'get_children_accounts': self.get_children_accounts,
'get_fiscalyear': self._get_fiscalyear,
'get_journal': self._get_journal,
'get_account': self._get_account,
'get_start_period': self.get_start_period,
'get_end_period': self.get_end_period,
'get_filter': self._get_filter,
'get_sortby': self._get_sortby,
'get_start_date':self._get_start_date,
'get_end_date':self._get_end_date,
'get_target_move': self._get_target_move,
})
self.context = context
def _sum_currency_amount_account(self, account):
self.cr.execute('SELECT sum(l.amount_currency) AS tot_currency \
FROM account_move_line l \
WHERE l.account_id = %s AND %s' %(account.id, self.query))
sum_currency = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(l.amount_currency) AS tot_currency \
FROM account_move_line l \
WHERE l.account_id = %s AND %s '%(account.id, self.init_query))
sum_currency += self.cr.fetchone()[0] or 0.0
return sum_currency
def get_children_accounts(self, account):
res = []
currency_obj = self.pool.get('res.currency')
ids_acc = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, account.id)
currency = account.currency_id and account.currency_id or account.company_id.currency_id
for child_account in self.pool.get('account.account').browse(self.cr, self.uid, ids_acc, context=self.context):
sql = """
SELECT count(id)
FROM account_move_line AS l
WHERE %s AND l.account_id = %%s
""" % (self.query)
self.cr.execute(sql, (child_account.id,))
num_entry = self.cr.fetchone()[0] or 0
sold_account = self._sum_balance_account(child_account)
self.sold_accounts[child_account.id] = sold_account
if self.display_account == 'movement':
if child_account.type != 'view' and num_entry <> 0:
res.append(child_account)
elif self.display_account == 'not_zero':
if child_account.type != 'view' and num_entry <> 0:
if not currency_obj.is_zero(self.cr, self.uid, currency, sold_account):
res.append(child_account)
else:
res.append(child_account)
if not res:
return [account]
return res
def lines(self, account):
""" Return all the account_move_line of account with their account code counterparts """
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted', '']
# First compute all counterpart strings for every move_id where this account appear.
# Currently, the counterpart info is used only in landscape mode
sql = """
SELECT m1.move_id,
array_to_string(ARRAY(SELECT DISTINCT a.code
FROM account_move_line m2
LEFT JOIN account_account a ON (m2.account_id=a.id)
WHERE m2.move_id = m1.move_id
AND m2.account_id<>%%s), ', ') AS counterpart
FROM (SELECT move_id
FROM account_move_line l
LEFT JOIN account_move am ON (am.id = l.move_id)
WHERE am.state IN %s and %s AND l.account_id = %%s GROUP BY move_id) m1
"""% (tuple(move_state), self.query)
self.cr.execute(sql, (account.id, account.id))
counterpart_res = self.cr.dictfetchall()
counterpart_accounts = {}
for i in counterpart_res:
counterpart_accounts[i['move_id']] = i['counterpart']
del counterpart_res
# Then select all account_move_line of this account
if self.sortby == 'sort_journal_partner':
sql_sort='j.code, p.name, l.move_id'
else:
sql_sort='l.date, l.move_id'
sql = """
SELECT l.id AS lid, l.date AS ldate, j.code AS lcode, l.currency_id,l.amount_currency,l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, l.period_id AS lperiod_id, l.partner_id AS lpartner_id,
m.name AS move_name, m.id AS mmove_id,per.code as period_code,
c.symbol AS currency_code,
i.id AS invoice_id, i.type AS invoice_type, i.number AS invoice_number,
p.name AS partner_name
FROM account_move_line l
JOIN account_move m on (l.move_id=m.id)
LEFT JOIN res_currency c on (l.currency_id=c.id)
LEFT JOIN res_partner p on (l.partner_id=p.id)
LEFT JOIN account_invoice i on (m.id =i.move_id)
LEFT JOIN account_period per on (per.id=l.period_id)
JOIN account_journal j on (l.journal_id=j.id)
WHERE %s AND m.state IN %s AND l.account_id = %%s ORDER by %s
""" %(self.query, tuple(move_state), sql_sort)
self.cr.execute(sql, (account.id,))
res_lines = self.cr.dictfetchall()
res_init = []
if res_lines and self.init_balance:
#FIXME: replace the label of lname with a string translatable
sql = """
SELECT 0 AS lid, '' AS ldate, '' AS lcode, COALESCE(SUM(l.amount_currency),0.0) AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, '' AS lperiod_id, '' AS lpartner_id,
'' AS move_name, '' AS mmove_id, '' AS period_code,
'' AS currency_code,
NULL AS currency_id,
'' AS invoice_id, '' AS invoice_type, '' AS invoice_number,
'' AS partner_name
FROM account_move_line l
LEFT JOIN account_move m on (l.move_id=m.id)
LEFT JOIN res_currency c on (l.currency_id=c.id)
LEFT JOIN res_partner p on (l.partner_id=p.id)
LEFT JOIN account_invoice i on (m.id =i.move_id)
JOIN account_journal j on (l.journal_id=j.id)
WHERE %s AND m.state IN %s AND l.account_id = %%s
""" %(self.init_query, tuple(move_state))
self.cr.execute(sql, (account.id,))
res_init = self.cr.dictfetchall()
res = res_init + res_lines
account_sum = 0.0
for l in res:
l['move'] = l['move_name'] != '/' and l['move_name'] or ('*'+str(l['mmove_id']))
l['partner'] = l['partner_name'] or ''
account_sum += l['debit'] - l['credit']
l['progress'] = account_sum
l['line_corresp'] = l['mmove_id'] == '' and ' ' or counterpart_accounts[l['mmove_id']].replace(', ',',')
# Modification of amount Currency
if l['credit'] > 0:
if l['amount_currency'] != None:
l['amount_currency'] = abs(l['amount_currency']) * -1
if l['amount_currency'] != None:
self.tot_currency = self.tot_currency + l['amount_currency']
return res
def _sum_debit_account(self, account):
if account.type == 'view':
return account.debit
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT sum(debit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_debit = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(debit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_debit += self.cr.fetchone()[0] or 0.0
return sum_debit
def _sum_credit_account(self, account):
if account.type == 'view':
return account.credit
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT sum(credit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_credit = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT sum(credit) \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_credit += self.cr.fetchone()[0] or 0.0
return sum_credit
def _sum_balance_account(self, account):
if account.type == 'view':
return account.balance
move_state = ['draft','posted']
if self.target_move == 'posted':
move_state = ['posted','']
self.cr.execute('SELECT (sum(debit) - sum(credit)) as tot_balance \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.query +' '
,(account.id, tuple(move_state)))
sum_balance = self.cr.fetchone()[0] or 0.0
if self.init_balance:
self.cr.execute('SELECT (sum(debit) - sum(credit)) as tot_balance \
FROM account_move_line l \
JOIN account_move am ON (am.id = l.move_id) \
WHERE (l.account_id = %s) \
AND (am.state IN %s) \
AND '+ self.init_query +' '
,(account.id, tuple(move_state)))
# Add initial balance to the result
sum_balance += self.cr.fetchone()[0] or 0.0
return sum_balance
def _get_account(self, data):
if data['model'] == 'account.account':
return self.pool.get('account.account').browse(self.cr, self.uid, data['form']['id']).company_id.name
return super(general_ledger ,self)._get_account(data)
def _get_sortby(self, data):
if self.sortby == 'sort_date':
return self._translate('Date')
elif self.sortby == 'sort_journal_partner':
return self._translate('Journal & Partner')
return self._translate('Date')
report_sxw.report_sxw('report.account.general.ledger', 'account.account', 'addons/account/report/account_general_ledger.rml', parser=general_ledger, header='internal')
report_sxw.report_sxw('report.account.general.ledger_landscape', 'account.account', 'addons/account/report/account_general_ledger_landscape.rml', parser=general_ledger, header='internal landscape')
# 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,
1898,
334,
67,
9,
11811,
13,
7968,
24569,
475,
3630,
311,
199,
3,
1898,
334,
67,
9,
8315,
13,
6542,
7653,
428,
14,
33,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
4783,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
12072,
397,
436,
2291,
787,
30390,
1503,
17311,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
2863,
63,
3070,
63,
1291,
492,
2863,
63,
3070,
63,
1291,
199,
199,
533,
8605,
63,
28771,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
12,
2863,
63,
3070,
63,
1291,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
14,
10706,
14,
28771,
7,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
892,
63,
1580,
275,
2762,
267,
1559,
63,
1185,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
291,
14,
3191,
991,
275,
666,
459,
964,
2278,
362,
360,
3191,
991,
297,
283,
3191,
63,
602,
358,
267,
291,
14,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
576,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
430,
267,
4027,
18,
275,
666,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
680,
1574,
342,
267,
291,
14,
826,
63,
7358,
275,
666,
459,
964,
2278,
362,
360,
2747,
63,
7358,
297,
715,
9,
267,
340,
291,
14,
826,
63,
7358,
26,
288,
4027,
18,
14,
873,
3252,
2747,
63,
4982,
356,
715,
1552,
267,
291,
14,
826,
63,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
3799,
18,
9,
267,
291,
14,
2918,
63,
2048,
275,
666,
459,
964,
2545,
2918,
63,
2048,
418,
267,
291,
14,
1375,
63,
1185,
275,
666,
459,
964,
2278,
362,
360,
1375,
63,
1185,
297,
283,
452,
358,
267,
4027,
275,
291,
14,
1100,
14,
1574,
342,
267,
4027,
459,
21260,
418,
275,
666,
459,
964,
2545,
21260,
63,
344,
418,
267,
340,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
5191,
356,
288,
4027,
459,
20441,
418,
275,
666,
459,
964,
2545,
20441,
418,
267,
916,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
602,
356,
288,
4027,
459,
602,
63,
504,
418,
275,
666,
459,
964,
2545,
602,
63,
504,
418,
288,
4027,
459,
602,
63,
475,
418,
275,
221,
666,
459,
964,
2545,
602,
63,
475,
418,
267,
4027,
459,
929,
418,
275,
666,
459,
964,
2545,
1375,
63,
1185,
418,
267,
291,
14,
1100,
14,
873,
8,
3799,
9,
267,
340,
334,
576,
459,
1238,
418,
508,
283,
723,
14,
1907,
14,
4470,
735,
288,
892,
63,
1580,
275,
359,
576,
459,
964,
2545,
9019,
63,
2048,
63,
344,
6538,
288,
2251,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
2048,
1959,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
892,
63,
1580,
9,
267,
372,
1613,
8,
10706,
63,
28771,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
892,
63,
1580,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
10706,
63,
28771,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
1131,
275,
3087,
267,
291,
14,
13280,
63,
4968,
275,
378,
14,
16,
267,
291,
14,
5191,
63,
3009,
275,
3087,
267,
291,
14,
83,
1753,
63,
8370,
275,
1052,
267,
291,
14,
3191,
991,
275,
283,
3191,
63,
602,
7,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
1278,
356,
291,
14,
1278,
12,
288,
283,
1838,
63,
12964,
63,
2048,
356,
291,
423,
1838,
63,
12964,
63,
2048,
12,
288,
283,
1838,
63,
9365,
63,
2048,
356,
291,
423,
1838,
63,
9365,
63,
2048,
12,
288,
283,
1838,
63,
7358,
63,
2048,
356,
291,
423,
1838,
63,
7358,
63,
2048,
12,
288,
283,
1838,
63,
4968,
63,
4606,
63,
2048,
356,
291,
423,
1838,
63,
4968,
63,
4606,
63,
2048,
12,
288,
283,
362,
63,
3223,
63,
8370,
356,
291,
14,
362,
63,
3223,
63,
8370,
12,
288,
283,
362,
63,
21260,
356,
291,
423,
362,
63,
21260,
12,
288,
283,
362,
63,
7067,
356,
291,
423,
362,
63,
7067,
12,
288,
283,
362,
63,
2048,
356,
291,
423,
362,
63,
2048,
12,
288,
283,
362,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
13,
7968,
24569,
475,
3630,
311,
199,
3,
1898,
334,
67,
9,
8315,
13,
6542,
7653,
428,
14,
33,
199,
3,
199,
3,
14750,
26,
961,
2240,
465,
4066,
365,
11619,
370,
506,
1202,
701,
22398,
28661,
199,
3,
2240,
16465,
3963,
5452,
314,
8852,
9163,
4783,
402,
465,
5480,
316,
1006,
12330,
199,
3,
406,
13436,
9183,
687,
2399,
1566,
1061,
315,
9587,
27164,
2578,
436,
18227,
199,
3,
9599,
4390,
3963,
787,
10023,
367,
282,
10144,
13,
475,
13,
1180,
8744,
543,
2414,
23012,
199,
3,
12072,
397,
436,
2291,
787,
30390,
1503,
17311,
370,
16077,
282,
2868,
2290,
199,
3,
7591,
15878,
199,
3,
199,
3,
961,
2240,
365,
2868,
2290,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
221,
8217,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
2863,
63,
3070,
63,
1291,
492,
2863,
63,
3070,
63,
1291,
199,
199,
533,
8605,
63,
28771,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
12,
2863,
63,
3070,
63,
1291,
304,
272,
485,
354,
275,
283,
3070,
14,
2048,
14,
10706,
14,
28771,
7,
339,
347,
663,
63,
1100,
8,
277,
12,
2251,
12,
666,
12,
2762,
12,
3622,
63,
466,
29,
403,
304,
267,
892,
63,
1580,
275,
2762,
267,
1559,
63,
1185,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
291,
14,
3191,
991,
275,
666,
459,
964,
2278,
362,
360,
3191,
991,
297,
283,
3191,
63,
602,
358,
267,
291,
14,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
576,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
430,
267,
4027,
18,
275,
666,
459,
964,
2278,
362,
360,
2972,
63,
1100,
297,
2440,
680,
1574,
342,
267,
291,
14,
826,
63,
7358,
275,
666,
459,
964,
2278,
362,
360,
2747,
63,
7358,
297,
715,
9,
267,
340,
291,
14,
826,
63,
7358,
26,
288,
4027,
18,
14,
873,
3252,
2747,
63,
4982,
356,
715,
1552,
267,
291,
14,
826,
63,
1131,
275,
1559,
63,
1185,
423,
1131,
63,
362,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
1559,
534,
76,
297,
1067,
29,
3799,
18,
9,
267,
291,
14,
2918,
63,
2048,
275,
666,
459,
964,
2545,
2918,
63,
2048,
418,
267,
291,
14,
1375,
63,
1185,
275,
666,
459,
964,
2278,
362,
360,
1375,
63,
1185,
297,
283,
452,
358,
267,
4027,
275,
291,
14,
1100,
14,
1574,
342,
267,
4027,
459,
21260,
418,
275,
666,
459,
964,
2545,
21260,
63,
344,
418,
267,
340,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
5191,
356,
288,
4027,
459,
20441,
418,
275,
666,
459,
964,
2545,
20441,
418,
267,
916,
666,
459,
964,
2545,
1541,
418,
508,
283,
1541,
63,
602,
356,
288,
4027,
459,
602,
63,
504,
418,
275,
666,
459,
964,
2545,
602,
63,
504,
418,
288,
4027,
459,
602,
63,
475,
418,
275,
221,
666,
459,
964,
2545,
602,
63,
475,
418,
267,
4027,
459,
929,
418,
275,
666,
459,
964,
2545,
1375,
63,
1185,
418,
267,
291,
14,
1100,
14,
873,
8,
3799,
9,
267,
340,
334,
576,
459,
1238,
418,
508,
283,
723,
14,
1907,
14,
4470,
735,
288,
892,
63,
1580,
275,
359,
576,
459,
964,
2545,
9019,
63,
2048,
63,
344,
6538,
288,
2251,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
2048,
1959,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
892,
63,
1580,
9,
267,
372,
1613,
8,
10706,
63,
28771,
12,
291,
680,
409,
63,
1100,
8,
1462,
12,
666,
12,
892,
63,
1580,
12,
3622,
63,
466,
29,
3070,
63,
466,
9,
339,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
29,
403,
304,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
1613,
8,
10706,
63,
28771,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
267,
291,
14,
1131,
275,
3087,
267,
291,
14,
13280,
63,
4968,
275,
378,
14,
16,
267,
291,
14,
5191,
63,
3009,
275,
3087,
267,
291,
14,
83,
1753,
63,
8370,
275,
1052,
267,
291,
14,
3191,
991,
275,
283,
3191,
63,
602,
7,
267,
291,
14,
17886,
14,
873,
8,
469,
288,
283,
521,
356,
900,
12,
288,
283,
1278,
356,
291,
14,
1278,
12,
288,
283,
1838,
63,
12964,
63,
2048,
356,
291,
423,
1838,
63,
12964,
63,
2048,
12,
288,
283,
1838,
63,
9365,
63,
2048,
356,
291,
423,
1838,
63,
9365,
63,
2048,
12,
288,
283,
1838,
63,
7358,
63,
2048,
356,
291,
423,
1838,
63,
7358,
63,
2048,
12,
288,
283,
1838,
63,
4968,
63,
4606,
63,
2048,
356,
291,
423,
1838,
63,
4968,
63,
4606,
63,
2048,
12,
288,
283,
362,
63,
3223,
63,
8370,
356,
291,
14,
362,
63,
3223,
63,
8370,
12,
288,
283,
362,
63,
21260,
356,
291,
423,
362,
63,
21260,
12,
288,
283,
362,
63,
7067,
356,
291,
423,
362,
63,
7067,
12,
288,
283,
362,
63,
2048,
356,
291,
423,
362,
63,
2048,
12,
288,
283,
362,
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,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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
] |
paran0ids0ul/infernal-twin
|
build/pip/pip/_vendor/html5lib/filters/whitespace.py
|
1730
|
1142
|
from __future__ import absolute_import, division, unicode_literals
import re
from . import _base
from ..constants import rcdataElements, spaceCharacters
spaceCharacters = "".join(spaceCharacters)
SPACES_REGEX = re.compile("[%s]+" % spaceCharacters)
class Filter(_base.Filter):
spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
def __iter__(self):
preserve = 0
for token in _base.Filter.__iter__(self):
type = token["type"]
if type == "StartTag" \
and (preserve or token["name"] in self.spacePreserveElements):
preserve += 1
elif type == "EndTag" and preserve:
preserve -= 1
elif not preserve and type == "SpaceCharacters" and token["data"]:
# Test on token["data"] above to not introduce spaces where there were not
token["data"] = " "
elif not preserve and type == "Characters":
token["data"] = collapse_spaces(token["data"])
yield token
def collapse_spaces(text):
return SPACES_REGEX.sub(' ', text)
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
1547,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
485,
1095,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
5559,
492,
4819,
576,
6255,
12,
25431,
199,
2638,
9272,
275,
10587,
904,
8,
2638,
9272,
9,
199,
199,
5763,
21287,
63,
10710,
275,
295,
14,
2014,
480,
9722,
83,
2807,
2,
450,
25431,
9,
421,
199,
533,
9388,
1547,
1095,
14,
4131,
304,
339,
4601,
2398,
4909,
6255,
275,
9522,
5234,
657,
401,
298,
20895,
937,
435,
769,
8,
1195,
576,
6255,
430,
339,
347,
636,
1661,
721,
277,
304,
267,
11211,
275,
378,
267,
367,
1526,
315,
485,
1095,
14,
4131,
855,
1661,
721,
277,
304,
288,
730,
275,
1526,
905,
466,
937,
288,
340,
730,
508,
298,
17697,
2,
971,
490,
436,
334,
17053,
503,
1526,
905,
354,
937,
315,
291,
14,
2638,
2398,
4909,
6255,
304,
355,
11211,
847,
413,
953,
916,
730,
508,
298,
16906,
2,
436,
11211,
26,
355,
11211,
4862,
413,
953,
916,
440,
11211,
436,
730,
508,
298,
28501,
2,
436,
1526,
905,
576,
6229,
355,
327,
1379,
641,
1526,
905,
576,
937,
3432,
370,
440,
13318,
3402,
7883,
2382,
2337,
4898,
440,
355,
1526,
905,
576,
937,
275,
298,
298,
953,
916,
440,
11211,
436,
730,
508,
298,
9272,
582,
355,
1526,
905,
576,
937,
275,
24311,
63,
10749,
8,
1418,
905,
576,
3135,
953,
1995,
1526,
421,
199,
318,
24311,
63,
10749,
8,
505,
304,
272,
372,
6988,
21287,
63,
10710,
14,
954,
360,
1656,
1318,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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invoice/test_purchase_invoice.py
|
2
|
32514
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import unittest
import frappe, erpnext
import frappe.model
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from frappe.utils import cint, flt, today, nowdate, add_days
import frappe.defaults
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory, \
test_records as pr_test_records
from erpnext.controllers.accounts_controller import get_payment_terms
from erpnext.exceptions import InvalidCurrency
from erpnext.stock.doctype.stock_entry.test_stock_entry import get_qty_after_transaction
from erpnext.accounts.doctype.account.test_account import get_inventory_account
test_dependencies = ["Item", "Cost Center", "Payment Term", "Payment Terms Template"]
test_ignore = ["Serial No"]
class TestPurchaseInvoice(unittest.TestCase):
@classmethod
def setUpClass(self):
unlink_payment_on_cancel_of_invoice()
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
@classmethod
def tearDownClass(self):
unlink_payment_on_cancel_of_invoice(0)
def test_gl_entries_without_perpetual_inventory(self):
frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC")
wrapper = frappe.copy_doc(test_records[0])
set_perpetual_inventory(0, wrapper.company)
self.assertTrue(not cint(erpnext.is_perpetual_inventory_enabled(wrapper.company)))
wrapper.insert()
wrapper.submit()
wrapper.load_from_db()
dl = wrapper
expected_gl_entries = {
"_Test Payable - _TC": [0, 1512.0],
"_Test Account Cost for Goods Sold - _TC": [1250, 0],
"_Test Account Shipping Charges - _TC": [100, 0],
"_Test Account Excise Duty - _TC": [140, 0],
"_Test Account Education Cess - _TC": [2.8, 0],
"_Test Account S&H Education Cess - _TC": [1.4, 0],
"_Test Account CST - _TC": [29.88, 0],
"_Test Account VAT - _TC": [156.25, 0],
"_Test Account Discount - _TC": [0, 168.03],
"Round Off - _TC": [0, 0.3]
}
gl_entries = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
where voucher_type = 'Purchase Invoice' and voucher_no = %s""", dl.name, as_dict=1)
for d in gl_entries:
self.assertEqual([d.debit, d.credit], expected_gl_entries.get(d.account))
def test_gl_entries_with_perpetual_inventory(self):
pi = frappe.copy_doc(test_records[1])
set_perpetual_inventory(1, pi.company)
self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pi.company)), 1)
pi.insert()
pi.submit()
self.check_gle_for_pi(pi.name)
set_perpetual_inventory(0, pi.company)
def test_terms_added_after_save(self):
pi = frappe.copy_doc(test_records[1])
pi.insert()
self.assertTrue(pi.payment_schedule)
self.assertEqual(pi.payment_schedule[0].due_date, pi.due_date)
def test_payment_entry_unlink_against_purchase_invoice(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
unlink_payment_on_cancel_of_invoice(0)
pi_doc = make_purchase_invoice()
pe = get_payment_entry("Purchase Invoice", pi_doc.name, bank_account="_Test Bank - _TC")
pe.reference_no = "1"
pe.reference_date = nowdate()
pe.paid_from_account_currency = pi_doc.currency
pe.paid_to_account_currency = pi_doc.currency
pe.source_exchange_rate = 1
pe.target_exchange_rate = 1
pe.paid_amount = pi_doc.grand_total
pe.save(ignore_permissions=True)
pe.submit()
pi_doc = frappe.get_doc('Purchase Invoice', pi_doc.name)
self.assertRaises(frappe.LinkExistsError, pi_doc.cancel)
unlink_payment_on_cancel_of_invoice()
def test_purchase_invoice_for_blocked_supplier(self):
supplier = frappe.get_doc('Supplier', '_Test Supplier')
supplier.on_hold = 1
supplier.save()
self.assertRaises(frappe.ValidationError, make_purchase_invoice)
supplier.on_hold = 0
supplier.save()
def test_purchase_invoice_for_blocked_supplier_invoice(self):
supplier = frappe.get_doc('Supplier', '_Test Supplier')
supplier.on_hold = 1
supplier.hold_type = 'Invoices'
supplier.save()
self.assertRaises(frappe.ValidationError, make_purchase_invoice)
supplier.on_hold = 0
supplier.save()
def test_purchase_invoice_for_blocked_supplier_payment(self):
supplier = frappe.get_doc('Supplier', '_Test Supplier')
supplier.on_hold = 1
supplier.hold_type = 'Payments'
supplier.save()
pi = make_purchase_invoice()
self.assertRaises(
frappe.ValidationError, get_payment_entry, dt='Purchase Invoice', dn=pi.name, bank_account="_Test Bank - _TC")
supplier.on_hold = 0
supplier.save()
def test_purchase_invoice_for_blocked_supplier_payment_today_date(self):
supplier = frappe.get_doc('Supplier', '_Test Supplier')
supplier.on_hold = 1
supplier.hold_type = 'Payments'
supplier.release_date = nowdate()
supplier.save()
pi = make_purchase_invoice()
self.assertRaises(
frappe.ValidationError, get_payment_entry, dt='Purchase Invoice', dn=pi.name,
bank_account="_Test Bank - _TC")
supplier.on_hold = 0
supplier.save()
def test_purchase_invoice_for_blocked_supplier_payment_past_date(self):
# this test is meant to fail only if something fails in the try block
with self.assertRaises(Exception):
try:
supplier = frappe.get_doc('Supplier', '_Test Supplier')
supplier.on_hold = 1
supplier.hold_type = 'Payments'
supplier.release_date = '2018-03-01'
supplier.save()
pi = make_purchase_invoice()
get_payment_entry('Purchase Invoice', dn=pi.name, bank_account="_Test Bank - _TC")
supplier.on_hold = 0
supplier.save()
except:
pass
else:
raise Exception
def test_purchase_invoice_blocked_invoice_must_be_in_future(self):
pi = make_purchase_invoice(do_not_save=True)
pi.release_date = nowdate()
self.assertRaises(frappe.ValidationError, pi.save)
pi.release_date = ''
pi.save()
def test_purchase_invoice_temporary_blocked(self):
pi = make_purchase_invoice(do_not_save=True)
pi.release_date = add_days(nowdate(), 10)
pi.save()
pi.submit()
pe = get_payment_entry('Purchase Invoice', dn=pi.name, bank_account="_Test Bank - _TC")
self.assertRaises(frappe.ValidationError, pe.save)
def test_purchase_invoice_explicit_block(self):
pi = make_purchase_invoice()
pi.block_invoice()
self.assertEqual(pi.on_hold, 1)
pi.unblock_invoice()
self.assertEqual(pi.on_hold, 0)
def test_gl_entries_with_perpetual_inventory_against_pr(self):
pr = frappe.copy_doc(pr_test_records[0])
set_perpetual_inventory(1, pr.company)
self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)
pr.submit()
pi = frappe.copy_doc(test_records[1])
for d in pi.get("items"):
d.purchase_receipt = pr.name
pi.insert()
pi.submit()
self.check_gle_for_pi(pi.name)
set_perpetual_inventory(0, pr.company)
def check_gle_for_pi(self, pi):
gl_entries = frappe.db.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi, as_dict=1)
self.assertTrue(gl_entries)
expected_values = dict((d[0], d) for d in [
["_Test Payable - _TC", 0, 720],
["Stock Received But Not Billed - _TC", 500.0, 0],
["_Test Account Shipping Charges - _TC", 100.0, 0],
["_Test Account VAT - _TC", 120.0, 0],
])
for i, gle in enumerate(gl_entries):
self.assertEqual(expected_values[gle.account][0], gle.account)
self.assertEqual(expected_values[gle.account][1], gle.debit)
self.assertEqual(expected_values[gle.account][2], gle.credit)
def test_purchase_invoice_change_naming_series(self):
pi = frappe.copy_doc(test_records[1])
pi.insert()
pi.naming_series = 'TEST-'
self.assertRaises(frappe.CannotChangeConstantError, pi.save)
pi = frappe.copy_doc(test_records[0])
pi.insert()
pi.naming_series = 'TEST-'
self.assertRaises(frappe.CannotChangeConstantError, pi.save)
def test_gl_entries_with_aia_for_non_stock_items(self):
pi = frappe.copy_doc(test_records[1])
set_perpetual_inventory(1, pi.company)
self.assertTrue(cint(erpnext.is_perpetual_inventory_enabled(pi.company)), 1)
pi.get("items")[0].item_code = "_Test Non Stock Item"
pi.get("items")[0].expense_account = "_Test Account Cost for Goods Sold - _TC"
pi.get("taxes").pop(0)
pi.get("taxes").pop(1)
pi.insert()
pi.submit()
gl_entries = frappe.db.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
expected_values = sorted([
["_Test Payable - _TC", 0, 620],
["_Test Account Cost for Goods Sold - _TC", 500.0, 0],
["_Test Account VAT - _TC", 120.0, 0],
])
for i, gle in enumerate(gl_entries):
self.assertEqual(expected_values[i][0], gle.account)
self.assertEqual(expected_values[i][1], gle.debit)
self.assertEqual(expected_values[i][2], gle.credit)
set_perpetual_inventory(0, pi.company)
def test_purchase_invoice_calculation(self):
pi = frappe.copy_doc(test_records[0])
pi.insert()
pi.load_from_db()
expected_values = [
["_Test Item Home Desktop 100", 90, 59],
["_Test Item Home Desktop 200", 135, 177]
]
for i, item in enumerate(pi.get("items")):
self.assertEqual(item.item_code, expected_values[i][0])
self.assertEqual(item.item_tax_amount, expected_values[i][1])
self.assertEqual(item.valuation_rate, expected_values[i][2])
self.assertEqual(pi.base_net_total, 1250)
# tax amounts
expected_values = [
["_Test Account Shipping Charges - _TC", 100, 1350],
["_Test Account Customs Duty - _TC", 125, 1350],
["_Test Account Excise Duty - _TC", 140, 1490],
["_Test Account Education Cess - _TC", 2.8, 1492.8],
["_Test Account S&H Education Cess - _TC", 1.4, 1494.2],
["_Test Account CST - _TC", 29.88, 1524.08],
["_Test Account VAT - _TC", 156.25, 1680.33],
["_Test Account Discount - _TC", 168.03, 1512.30],
]
for i, tax in enumerate(pi.get("taxes")):
self.assertEqual(tax.account_head, expected_values[i][0])
self.assertEqual(tax.tax_amount, expected_values[i][1])
self.assertEqual(tax.total, expected_values[i][2])
def test_purchase_invoice_with_subcontracted_item(self):
wrapper = frappe.copy_doc(test_records[0])
wrapper.get("items")[0].item_code = "_Test FG Item"
wrapper.insert()
wrapper.load_from_db()
expected_values = [
["_Test FG Item", 90, 59],
["_Test Item Home Desktop 200", 135, 177]
]
for i, item in enumerate(wrapper.get("items")):
self.assertEqual(item.item_code, expected_values[i][0])
self.assertEqual(item.item_tax_amount, expected_values[i][1])
self.assertEqual(item.valuation_rate, expected_values[i][2])
self.assertEqual(wrapper.base_net_total, 1250)
# tax amounts
expected_values = [
["_Test Account Shipping Charges - _TC", 100, 1350],
["_Test Account Customs Duty - _TC", 125, 1350],
["_Test Account Excise Duty - _TC", 140, 1490],
["_Test Account Education Cess - _TC", 2.8, 1492.8],
["_Test Account S&H Education Cess - _TC", 1.4, 1494.2],
["_Test Account CST - _TC", 29.88, 1524.08],
["_Test Account VAT - _TC", 156.25, 1680.33],
["_Test Account Discount - _TC", 168.03, 1512.30],
]
for i, tax in enumerate(wrapper.get("taxes")):
self.assertEqual(tax.account_head, expected_values[i][0])
self.assertEqual(tax.tax_amount, expected_values[i][1])
self.assertEqual(tax.total, expected_values[i][2])
def test_purchase_invoice_with_advance(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry \
import test_records as jv_test_records
jv = frappe.copy_doc(jv_test_records[1])
jv.insert()
jv.submit()
pi = frappe.copy_doc(test_records[0])
pi.disable_rounded_total = 1
pi.allocate_advances_automatically = 0
pi.append("advances", {
"reference_type": "Journal Entry",
"reference_name": jv.name,
"reference_row": jv.get("accounts")[0].name,
"advance_amount": 400,
"allocated_amount": 300,
"remarks": jv.remark
})
pi.insert()
self.assertEqual(pi.outstanding_amount, 1212.30)
pi.disable_rounded_total = 0
pi.get("payment_schedule")[0].payment_amount = 1512.0
pi.save()
self.assertEqual(pi.outstanding_amount, 1212.0)
pi.submit()
pi.load_from_db()
self.assertTrue(frappe.db.sql("""select name from `tabJournal Entry Account`
where reference_type='Purchase Invoice'
and reference_name=%s and debit_in_account_currency=300""", pi.name))
pi.cancel()
self.assertFalse(frappe.db.sql("""select name from `tabJournal Entry Account`
where reference_type='Purchase Invoice' and reference_name=%s""", pi.name))
def test_invoice_with_advance_and_multi_payment_terms(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry \
import test_records as jv_test_records
jv = frappe.copy_doc(jv_test_records[1])
jv.insert()
jv.submit()
pi = frappe.copy_doc(test_records[0])
pi.disable_rounded_total = 1
pi.allocate_advances_automatically = 0
pi.append("advances", {
"reference_type": "Journal Entry",
"reference_name": jv.name,
"reference_row": jv.get("accounts")[0].name,
"advance_amount": 400,
"allocated_amount": 300,
"remarks": jv.remark
})
pi.insert()
pi.update({
"payment_schedule": get_payment_terms("_Test Payment Term Template",
pi.posting_date, pi.grand_total)
})
pi.save()
pi.submit()
self.assertEqual(pi.payment_schedule[0].payment_amount, 606.15)
self.assertEqual(pi.payment_schedule[0].due_date, pi.posting_date)
self.assertEqual(pi.payment_schedule[1].payment_amount, 606.15)
self.assertEqual(pi.payment_schedule[1].due_date, add_days(pi.posting_date, 30))
pi.load_from_db()
self.assertTrue(
frappe.db.sql(
"select name from `tabJournal Entry Account` where reference_type='Purchase Invoice' and "
"reference_name=%s and debit_in_account_currency=300", pi.name)
)
self.assertEqual(pi.outstanding_amount, 1212.30)
pi.cancel()
self.assertFalse(
frappe.db.sql(
"select name from `tabJournal Entry Account` where reference_type='Purchase Invoice' and "
"reference_name=%s", pi.name)
)
def test_total_purchase_cost_for_project(self):
existing_purchase_cost = frappe.db.sql("""select sum(base_net_amount)
from `tabPurchase Invoice Item` where project = '_Test Project' and docstatus=1""")
existing_purchase_cost = existing_purchase_cost and existing_purchase_cost[0][0] or 0
pi = make_purchase_invoice(currency="USD", conversion_rate=60, project="_Test Project")
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
existing_purchase_cost + 15000)
pi1 = make_purchase_invoice(qty=10, project="_Test Project")
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
existing_purchase_cost + 15500)
pi1.cancel()
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"),
existing_purchase_cost + 15000)
pi.cancel()
self.assertEqual(frappe.db.get_value("Project", "_Test Project", "total_purchase_cost"), existing_purchase_cost)
def test_return_purchase_invoice(self):
set_perpetual_inventory()
pi = make_purchase_invoice()
return_pi = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2)
# check gl entries for return
gl_entries = frappe.db.sql("""select account, debit, credit
from `tabGL Entry` where voucher_type=%s and voucher_no=%s
order by account desc""", ("Purchase Invoice", return_pi.name), as_dict=1)
self.assertTrue(gl_entries)
expected_values = {
"Creditors - _TC": [100.0, 0.0],
"Stock Received But Not Billed - _TC": [0.0, 100.0],
}
for gle in gl_entries:
self.assertEqual(expected_values[gle.account][0], gle.debit)
self.assertEqual(expected_values[gle.account][1], gle.credit)
set_perpetual_inventory(0)
def test_multi_currency_gle(self):
set_perpetual_inventory(0)
pi = make_purchase_invoice(supplier="_Test Supplier USD", credit_to="_Test Payable USD - _TC",
currency="USD", conversion_rate=50)
gl_entries = frappe.db.sql("""select account, account_currency, debit, credit,
debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
expected_values = {
"_Test Payable USD - _TC": {
"account_currency": "USD",
"debit": 0,
"debit_in_account_currency": 0,
"credit": 12500,
"credit_in_account_currency": 250
},
"_Test Account Cost for Goods Sold - _TC": {
"account_currency": "INR",
"debit": 12500,
"debit_in_account_currency": 12500,
"credit": 0,
"credit_in_account_currency": 0
}
}
for field in ("account_currency", "debit", "debit_in_account_currency", "credit", "credit_in_account_currency"):
for i, gle in enumerate(gl_entries):
self.assertEqual(expected_values[gle.account][field], gle[field])
# Check for valid currency
pi1 = make_purchase_invoice(supplier="_Test Supplier USD", credit_to="_Test Payable USD - _TC",
do_not_save=True)
self.assertRaises(InvalidCurrency, pi1.save)
# cancel
pi.cancel()
gle = frappe.db.sql("""select name from `tabGL Entry`
where voucher_type='Sales Invoice' and voucher_no=%s""", pi.name)
self.assertFalse(gle)
def test_purchase_invoice_update_stock_gl_entry_with_perpetual_inventory(self):
set_perpetual_inventory()
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime())
gl_entries = frappe.db.sql("""select account, account_currency, debit, credit,
debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
stock_in_hand_account = get_inventory_account(pi.company, pi.get("items")[0].warehouse)
expected_gl_entries = dict((d[0], d) for d in [
[pi.credit_to, 0.0, 250.0],
[stock_in_hand_account, 250.0, 0.0]
])
for i, gle in enumerate(gl_entries):
self.assertEqual(expected_gl_entries[gle.account][0], gle.account)
self.assertEqual(expected_gl_entries[gle.account][1], gle.debit)
self.assertEqual(expected_gl_entries[gle.account][2], gle.credit)
def test_purchase_invoice_for_is_paid_and_update_stock_gl_entry_with_perpetual_inventory(self):
set_perpetual_inventory()
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime(), cash_bank_account="Cash - _TC", is_paid=1)
gl_entries = frappe.db.sql("""select account, account_currency, sum(debit) as debit,
sum(credit) as credit, debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
group by account, voucher_no order by account asc;""", pi.name, as_dict=1)
stock_in_hand_account = get_inventory_account(pi.company, pi.get("items")[0].warehouse)
self.assertTrue(gl_entries)
expected_gl_entries = dict((d[0], d) for d in [
[pi.credit_to, 250.0, 250.0],
[stock_in_hand_account, 250.0, 0.0],
["Cash - _TC", 0.0, 250.0]
])
for i, gle in enumerate(gl_entries):
self.assertEqual(expected_gl_entries[gle.account][0], gle.account)
self.assertEqual(expected_gl_entries[gle.account][1], gle.debit)
self.assertEqual(expected_gl_entries[gle.account][2], gle.credit)
def test_auto_batch(self):
item_code = frappe.db.get_value('Item',
{'has_batch_no': 1, 'create_new_batch':1}, 'name')
if not item_code:
doc = frappe.get_doc({
'doctype': 'Item',
'is_stock_item': 1,
'item_code': 'test batch item',
'item_group': 'Products',
'has_batch_no': 1,
'create_new_batch': 1
}).insert(ignore_permissions=True)
item_code = doc.name
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime(), item_code=item_code)
self.assertTrue(frappe.db.get_value('Batch',
{'item': item_code, 'reference_name': pi.name}))
def test_update_stock_and_purchase_return(self):
actual_qty_0 = get_qty_after_transaction()
pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
posting_time=frappe.utils.nowtime())
actual_qty_1 = get_qty_after_transaction()
self.assertEqual(actual_qty_0 + 5, actual_qty_1)
# return entry
pi1 = make_purchase_invoice(is_return=1, return_against=pi.name, qty=-2, rate=50, update_stock=1)
actual_qty_2 = get_qty_after_transaction()
self.assertEqual(actual_qty_1 - 2, actual_qty_2)
pi1.cancel()
self.assertEqual(actual_qty_1, get_qty_after_transaction())
pi.reload()
pi.cancel()
self.assertEqual(actual_qty_0, get_qty_after_transaction())
def test_subcontracting_via_purchase_invoice(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100)
make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC",
qty=100, basic_rate=100)
pi = make_purchase_invoice(item_code="_Test FG Item", qty=10, rate=500,
update_stock=1, is_subcontracted="Yes")
self.assertEqual(len(pi.get("supplied_items")), 2)
rm_supp_cost = sum([d.amount for d in pi.get("supplied_items")])
self.assertEqual(pi.get("items")[0].rm_supp_cost, flt(rm_supp_cost, 2))
def test_rejected_serial_no(self):
pi = make_purchase_invoice(item_code="_Test Serialized Item With Series", received_qty=2, qty=1,
rejected_qty=1, rate=500, update_stock=1,
rejected_warehouse = "_Test Rejected Warehouse - _TC")
self.assertEqual(frappe.db.get_value("Serial No", pi.get("items")[0].serial_no, "warehouse"),
pi.get("items")[0].warehouse)
self.assertEqual(frappe.db.get_value("Serial No", pi.get("items")[0].rejected_serial_no,
"warehouse"), pi.get("items")[0].rejected_warehouse)
def test_outstanding_amount_after_advance_jv_cancelation(self):
from erpnext.accounts.doctype.journal_entry.test_journal_entry \
import test_records as jv_test_records
jv = frappe.copy_doc(jv_test_records[1])
jv.accounts[0].is_advance = 'Yes'
jv.insert()
jv.submit()
pi = frappe.copy_doc(test_records[0])
pi.append("advances", {
"reference_type": "Journal Entry",
"reference_name": jv.name,
"reference_row": jv.get("accounts")[0].name,
"advance_amount": 400,
"allocated_amount": 300,
"remarks": jv.remark
})
pi.insert()
pi.submit()
pi.load_from_db()
#check outstanding after advance allocation
self.assertEqual(flt(pi.outstanding_amount), flt(pi.rounded_total - pi.total_advance))
#added to avoid Document has been modified exception
jv = frappe.get_doc("Journal Entry", jv.name)
jv.cancel()
pi.load_from_db()
#check outstanding after advance cancellation
self.assertEqual(flt(pi.outstanding_amount), flt(pi.rounded_total + pi.total_advance))
def test_outstanding_amount_after_advance_payment_entry_cancelation(self):
pe = frappe.get_doc({
"doctype": "Payment Entry",
"payment_type": "Pay",
"party_type": "Supplier",
"party": "_Test Supplier",
"company": "_Test Company",
"paid_from_account_currency": "INR",
"paid_to_account_currency": "INR",
"source_exchange_rate": 1,
"target_exchange_rate": 1,
"reference_no": "1",
"reference_date": nowdate(),
"received_amount": 300,
"paid_amount": 300,
"paid_from": "_Test Cash - _TC",
"paid_to": "_Test Payable - _TC"
})
pe.insert()
pe.submit()
pi = frappe.copy_doc(test_records[0])
pi.is_pos = 0
pi.append("advances", {
"doctype": "Purchase Invoice Advance",
"reference_type": "Payment Entry",
"reference_name": pe.name,
"advance_amount": 300,
"allocated_amount": 300,
"remarks": pe.remarks
})
pi.insert()
pi.submit()
pi.load_from_db()
#check outstanding after advance allocation
self.assertEqual(flt(pi.outstanding_amount), flt(pi.rounded_total - pi.total_advance))
#added to avoid Document has been modified exception
pe = frappe.get_doc("Payment Entry", pe.name)
pe.cancel()
pi.load_from_db()
#check outstanding after advance cancellation
self.assertEqual(flt(pi.outstanding_amount), flt(pi.rounded_total + pi.total_advance))
def test_purchase_invoice_with_shipping_rule(self):
from erpnext.accounts.doctype.shipping_rule.test_shipping_rule \
import create_shipping_rule
shipping_rule = create_shipping_rule(shipping_rule_type = "Buying", shipping_rule_name = "Shipping Rule - Purchase Invoice Test")
pi = frappe.copy_doc(test_records[0])
pi.shipping_rule = shipping_rule.name
pi.insert()
shipping_amount = 0.0
for condition in shipping_rule.get("conditions"):
if not condition.to_value or (flt(condition.from_value) <= pi.net_total <= flt(condition.to_value)):
shipping_amount = condition.shipping_amount
shipping_charge = {
"doctype": "Purchase Taxes and Charges",
"category": "Valuation and Total",
"charge_type": "Actual",
"account_head": shipping_rule.account,
"cost_center": shipping_rule.cost_center,
"tax_amount": shipping_amount,
"description": shipping_rule.name,
"add_deduct_tax": "Add"
}
pi.append("taxes", shipping_charge)
pi.save()
self.assertEqual(pi.net_total, 1250)
self.assertEqual(pi.total_taxes_and_charges, 462.3)
self.assertEqual(pi.grand_total, 1712.3)
def test_make_pi_without_terms(self):
pi = make_purchase_invoice(do_not_save=1)
self.assertFalse(pi.get('payment_schedule'))
pi.insert()
self.assertTrue(pi.get('payment_schedule'))
def test_duplicate_due_date_in_terms(self):
pi = make_purchase_invoice(do_not_save=1)
pi.append('payment_schedule', dict(due_date='2017-01-01', invoice_portion=50.00, payment_amount=50))
pi.append('payment_schedule', dict(due_date='2017-01-01', invoice_portion=50.00, payment_amount=50))
self.assertRaises(frappe.ValidationError, pi.insert)
def test_debit_note(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import get_outstanding_amount
pi = make_purchase_invoice(item_code = "_Test Item", qty = (5 * -1), rate=500, is_return = 1)
outstanding_amount = get_outstanding_amount(pi.doctype,
pi.name, "Creditors - _TC", pi.supplier, "Supplier")
self.assertEqual(pi.outstanding_amount, outstanding_amount)
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
pe.reference_no = "1"
pe.reference_date = nowdate()
pe.paid_from_account_currency = pi.currency
pe.paid_to_account_currency = pi.currency
pe.source_exchange_rate = 1
pe.target_exchange_rate = 1
pe.paid_amount = pi.grand_total * -1
pe.insert()
pe.submit()
pi_doc = frappe.get_doc('Purchase Invoice', pi.name)
self.assertEqual(pi_doc.outstanding_amount, 0)
def test_purchase_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self):
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
accounts_settings.allow_cost_center_in_entry_of_bs_account = 1
accounts_settings.save()
cost_center = "_Test Cost Center for BS Account - _TC"
create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company")
pi = make_purchase_invoice_against_cost_center(cost_center=cost_center, credit_to="Creditors - _TC")
self.assertEqual(pi.cost_center, cost_center)
expected_values = {
"Creditors - _TC": {
"cost_center": cost_center
},
"_Test Account Cost for Goods Sold - _TC": {
"cost_center": cost_center
}
}
gl_entries = frappe.db.sql("""select account, cost_center, account_currency, debit, credit,
debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
for gle in gl_entries:
self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
accounts_settings.save()
def test_purchase_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
accounts_settings.save()
cost_center = "_Test Cost Center - _TC"
pi = make_purchase_invoice(credit_to="Creditors - _TC")
expected_values = {
"Creditors - _TC": {
"cost_center": None
},
"_Test Account Cost for Goods Sold - _TC": {
"cost_center": cost_center
}
}
gl_entries = frappe.db.sql("""select account, cost_center, account_currency, debit, credit,
debit_in_account_currency, credit_in_account_currency
from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", pi.name, as_dict=1)
self.assertTrue(gl_entries)
for gle in gl_entries:
self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center)
def unlink_payment_on_cancel_of_invoice(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
accounts_settings.unlink_payment_on_cancellation_of_invoice = enable
accounts_settings.save()
def make_purchase_invoice(**args):
pi = frappe.new_doc("Purchase Invoice")
args = frappe._dict(args)
pi.posting_date = args.posting_date or today()
if args.posting_time:
pi.posting_time = args.posting_time
if args.update_stock:
pi.update_stock = 1
if args.is_paid:
pi.is_paid = 1
if args.cash_bank_account:
pi.cash_bank_account=args.cash_bank_account
pi.company = args.company or "_Test Company"
pi.supplier = args.supplier or "_Test Supplier"
pi.currency = args.currency or "INR"
pi.conversion_rate = args.conversion_rate or 1
pi.is_return = args.is_return
pi.return_against = args.return_against
pi.is_subcontracted = args.is_subcontracted or "No"
pi.supplier_warehouse = "_Test Warehouse 1 - _TC"
pi.append("items", {
"item_code": args.item or args.item_code or "_Test Item",
"warehouse": args.warehouse or "_Test Warehouse - _TC",
"qty": args.qty or 5,
"received_qty": args.received_qty or 0,
"rejected_qty": args.rejected_qty or 0,
"rate": args.rate or 50,
"conversion_factor": 1.0,
"serial_no": args.serial_no,
"stock_uom": "_Test UOM",
"cost_center": "_Test Cost Center - _TC",
"project": args.project,
"rejected_warehouse": args.rejected_warehouse or "",
"rejected_serial_no": args.rejected_serial_no or ""
})
if not args.do_not_save:
pi.insert()
if not args.do_not_submit:
pi.submit()
return pi
def make_purchase_invoice_against_cost_center(**args):
pi = frappe.new_doc("Purchase Invoice")
args = frappe._dict(args)
pi.posting_date = args.posting_date or today()
if args.posting_time:
pi.posting_time = args.posting_time
if args.update_stock:
pi.update_stock = 1
if args.is_paid:
pi.is_paid = 1
if args.cash_bank_account:
pi.cash_bank_account=args.cash_bank_account
pi.company = args.company or "_Test Company"
pi.cost_center = args.cost_center or "_Test Cost Center - _TC"
pi.supplier = args.supplier or "_Test Supplier"
pi.currency = args.currency or "INR"
pi.conversion_rate = args.conversion_rate or 1
pi.is_return = args.is_return
pi.is_return = args.is_return
pi.credit_to = args.return_against or "Creditors - _TC"
pi.is_subcontracted = args.is_subcontracted or "No"
pi.supplier_warehouse = "_Test Warehouse 1 - _TC"
pi.append("items", {
"item_code": args.item or args.item_code or "_Test Item",
"warehouse": args.warehouse or "_Test Warehouse - _TC",
"qty": args.qty or 5,
"received_qty": args.received_qty or 0,
"rejected_qty": args.rejected_qty or 0,
"rate": args.rate or 50,
"conversion_factor": 1.0,
"serial_no": args.serial_no,
"stock_uom": "_Test UOM",
"cost_center": args.cost_center or "_Test Cost Center - _TC",
"project": args.project,
"rejected_warehouse": args.rejected_warehouse or "",
"rejected_serial_no": args.rejected_serial_no or ""
})
if not args.do_not_save:
pi.insert()
if not args.do_not_submit:
pi.submit()
return pi
test_records = frappe.get_test_records('Purchase Invoice')
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
6950,
12,
29106,
199,
646,
6950,
14,
1238,
199,
504,
29106,
14,
8370,
14,
6356,
14,
7948,
63,
2373,
14,
7948,
63,
2373,
492,
664,
63,
7948,
63,
2373,
199,
504,
6950,
14,
1208,
492,
286,
442,
12,
17166,
12,
11168,
12,
3063,
602,
12,
1050,
63,
4899,
199,
646,
6950,
14,
4322,
199,
504,
29106,
14,
6088,
14,
6356,
14,
9533,
63,
18905,
14,
396,
63,
9533,
63,
18905,
492,
663,
63,
529,
321,
1688,
63,
7212,
12,
971,
199,
198,
396,
63,
6502,
465,
5448,
63,
396,
63,
6502,
199,
504,
29106,
14,
20531,
14,
8370,
63,
5538,
492,
664,
63,
7948,
63,
9187,
199,
504,
29106,
14,
3924,
492,
6378,
19567,
199,
504,
29106,
14,
6088,
14,
6356,
14,
6088,
63,
2373,
14,
396,
63,
6088,
63,
2373,
492,
664,
63,
5643,
63,
4399,
63,
5945,
199,
504,
29106,
14,
8370,
14,
6356,
14,
2048,
14,
396,
63,
2048,
492,
664,
63,
7212,
63,
2048,
199,
199,
396,
63,
5714,
275,
2097,
2081,
401,
298,
15568,
24699,
401,
298,
22374,
13861,
77,
401,
298,
22374,
13861,
706,
5458,
937,
199,
396,
63,
4247,
275,
2097,
3571,
3091,
937,
199,
199,
533,
1379,
20486,
21092,
8,
2796,
14,
1746,
304,
199,
198,
32,
3744,
199,
198,
318,
18561,
8,
277,
304,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
342,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
1713,
22440,
13303,
401,
488,
12,
298,
3306,
63,
6048,
63,
1744,
401,
413,
9,
421,
198,
32,
3744,
199,
198,
318,
24468,
8,
277,
304,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
8,
16,
9,
421,
198,
318,
511,
63,
3528,
63,
3189,
63,
7395,
63,
529,
321,
1688,
63,
7212,
8,
277,
304,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16063,
401,
2668,
774,
15878,
401,
298,
2363,
63,
1997,
63,
2048,
401,
298,
18579,
28856,
446,
485,
5708,
531,
507,
198,
5029,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
16,
566,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
12,
4975,
14,
4627,
9,
507,
198,
277,
14,
1815,
8,
1397,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
5029,
14,
4627,
1724,
507,
198,
5029,
14,
3176,
342,
507,
198,
5029,
14,
7275,
342,
507,
198,
5029,
14,
912,
63,
504,
63,
697,
342,
507,
198,
5030,
275,
4975,
2742,
198,
2062,
63,
3528,
63,
3189,
275,
469,
686,
198,
2,
63,
774,
15911,
461,
446,
485,
5708,
582,
359,
16,
12,
4114,
713,
14,
16,
467,
686,
198,
2,
63,
774,
9973,
24681,
367,
22311,
83,
428,
1753,
446,
485,
5708,
582,
359,
26572,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
5244,
711,
4073,
6659,
3389,
446,
485,
5708,
582,
359,
1960,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
1316,
11900,
577,
19974,
446,
485,
5708,
582,
359,
10037,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
662,
5905,
425,
445,
16709,
446,
485,
5708,
582,
359,
18,
14,
24,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
428,
6,
40,
662,
5905,
425,
445,
16709,
446,
485,
5708,
582,
359,
17,
14,
20,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
445,
840,
446,
485,
5708,
582,
359,
1398,
14,
1299,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
812,
619,
446,
485,
5708,
582,
359,
11309,
14,
821,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
5289,
835,
446,
485,
5708,
582,
359,
16,
12,
413,
2333,
14,
1644,
467,
686,
198,
2,
18579,
28856,
446,
485,
5708,
582,
359,
16,
12,
378,
14,
19,
61,
507,
198,
93,
507,
198,
3528,
63,
3189,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
2933,
12,
24732,
12,
16630,
687,
658,
2902,
2226,
11855,
64,
686,
198,
4509,
17866,
63,
466,
275,
283,
20486,
19868,
7,
436,
17866,
63,
889,
275,
450,
83,
7208,
15396,
14,
354,
12,
465,
63,
807,
29,
17,
9,
507,
198,
509,
366,
315,
6482,
63,
3189,
26,
686,
198,
277,
14,
629,
779,
68,
14,
12964,
12,
366,
14,
9365,
467,
1420,
63,
3528,
63,
3189,
14,
362,
8,
68,
14,
2048,
430,
421,
198,
318,
511,
63,
3528,
63,
3189,
63,
1045,
63,
529,
321,
1688,
63,
7212,
8,
277,
304,
507,
198,
1038,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
17,
566,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
17,
12,
6682,
14,
4627,
9,
507,
198,
277,
14,
1815,
8,
67,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
1038,
14,
4627,
1826,
413,
9,
507,
198,
1038,
14,
3176,
342,
507,
198,
1038,
14,
7275,
342,
2742,
198,
277,
14,
1074,
63,
3845,
63,
509,
63,
1038,
8,
1038,
14,
354,
9,
2742,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
12,
6682,
14,
4627,
9,
421,
198,
318,
511,
63,
9187,
63,
3270,
63,
4399,
63,
2117,
8,
277,
304,
507,
198,
1038,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
17,
566,
507,
198,
1038,
14,
3176,
342,
507,
198,
277,
14,
1815,
8,
1038,
14,
7948,
63,
7211,
9,
507,
198,
277,
14,
629,
8,
1038,
14,
7948,
63,
7211,
59,
16,
1055,
11933,
63,
602,
12,
6682,
14,
11933,
63,
602,
9,
421,
198,
318,
511,
63,
7948,
63,
2373,
63,
7162,
63,
17777,
63,
9533,
63,
5404,
8,
277,
304,
507,
198,
504,
29106,
14,
8370,
14,
6356,
14,
7948,
63,
2373,
14,
396,
63,
7948,
63,
2373,
492,
664,
63,
7948,
63,
2373,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
8,
16,
9,
2742,
198,
1038,
63,
1301,
275,
1852,
63,
9533
] |
[
1898,
334,
67,
9,
6900,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
23212,
199,
3,
844,
26,
1664,
1696,
1684,
844,
373,
19,
14,
1666,
4190,
14,
2424,
421,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
6950,
12,
29106,
199,
646,
6950,
14,
1238,
199,
504,
29106,
14,
8370,
14,
6356,
14,
7948,
63,
2373,
14,
7948,
63,
2373,
492,
664,
63,
7948,
63,
2373,
199,
504,
6950,
14,
1208,
492,
286,
442,
12,
17166,
12,
11168,
12,
3063,
602,
12,
1050,
63,
4899,
199,
646,
6950,
14,
4322,
199,
504,
29106,
14,
6088,
14,
6356,
14,
9533,
63,
18905,
14,
396,
63,
9533,
63,
18905,
492,
663,
63,
529,
321,
1688,
63,
7212,
12,
971,
199,
198,
396,
63,
6502,
465,
5448,
63,
396,
63,
6502,
199,
504,
29106,
14,
20531,
14,
8370,
63,
5538,
492,
664,
63,
7948,
63,
9187,
199,
504,
29106,
14,
3924,
492,
6378,
19567,
199,
504,
29106,
14,
6088,
14,
6356,
14,
6088,
63,
2373,
14,
396,
63,
6088,
63,
2373,
492,
664,
63,
5643,
63,
4399,
63,
5945,
199,
504,
29106,
14,
8370,
14,
6356,
14,
2048,
14,
396,
63,
2048,
492,
664,
63,
7212,
63,
2048,
199,
199,
396,
63,
5714,
275,
2097,
2081,
401,
298,
15568,
24699,
401,
298,
22374,
13861,
77,
401,
298,
22374,
13861,
706,
5458,
937,
199,
396,
63,
4247,
275,
2097,
3571,
3091,
937,
199,
199,
533,
1379,
20486,
21092,
8,
2796,
14,
1746,
304,
199,
198,
32,
3744,
199,
198,
318,
18561,
8,
277,
304,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
342,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
1713,
22440,
13303,
401,
488,
12,
298,
3306,
63,
6048,
63,
1744,
401,
413,
9,
421,
198,
32,
3744,
199,
198,
318,
24468,
8,
277,
304,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
8,
16,
9,
421,
198,
318,
511,
63,
3528,
63,
3189,
63,
7395,
63,
529,
321,
1688,
63,
7212,
8,
277,
304,
507,
198,
9098,
14,
697,
14,
409,
63,
585,
480,
16063,
401,
2668,
774,
15878,
401,
298,
2363,
63,
1997,
63,
2048,
401,
298,
18579,
28856,
446,
485,
5708,
531,
507,
198,
5029,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
16,
566,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
12,
4975,
14,
4627,
9,
507,
198,
277,
14,
1815,
8,
1397,
286,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
5029,
14,
4627,
1724,
507,
198,
5029,
14,
3176,
342,
507,
198,
5029,
14,
7275,
342,
507,
198,
5029,
14,
912,
63,
504,
63,
697,
342,
507,
198,
5030,
275,
4975,
2742,
198,
2062,
63,
3528,
63,
3189,
275,
469,
686,
198,
2,
63,
774,
15911,
461,
446,
485,
5708,
582,
359,
16,
12,
4114,
713,
14,
16,
467,
686,
198,
2,
63,
774,
9973,
24681,
367,
22311,
83,
428,
1753,
446,
485,
5708,
582,
359,
26572,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
5244,
711,
4073,
6659,
3389,
446,
485,
5708,
582,
359,
1960,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
1316,
11900,
577,
19974,
446,
485,
5708,
582,
359,
10037,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
662,
5905,
425,
445,
16709,
446,
485,
5708,
582,
359,
18,
14,
24,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
428,
6,
40,
662,
5905,
425,
445,
16709,
446,
485,
5708,
582,
359,
17,
14,
20,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
445,
840,
446,
485,
5708,
582,
359,
1398,
14,
1299,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
812,
619,
446,
485,
5708,
582,
359,
11309,
14,
821,
12,
378,
467,
686,
198,
2,
63,
774,
9973,
5289,
835,
446,
485,
5708,
582,
359,
16,
12,
413,
2333,
14,
1644,
467,
686,
198,
2,
18579,
28856,
446,
485,
5708,
582,
359,
16,
12,
378,
14,
19,
61,
507,
198,
93,
507,
198,
3528,
63,
3189,
275,
6950,
14,
697,
14,
3009,
4852,
2416,
2933,
12,
24732,
12,
16630,
687,
658,
2902,
2226,
11855,
64,
686,
198,
4509,
17866,
63,
466,
275,
283,
20486,
19868,
7,
436,
17866,
63,
889,
275,
450,
83,
7208,
15396,
14,
354,
12,
465,
63,
807,
29,
17,
9,
507,
198,
509,
366,
315,
6482,
63,
3189,
26,
686,
198,
277,
14,
629,
779,
68,
14,
12964,
12,
366,
14,
9365,
467,
1420,
63,
3528,
63,
3189,
14,
362,
8,
68,
14,
2048,
430,
421,
198,
318,
511,
63,
3528,
63,
3189,
63,
1045,
63,
529,
321,
1688,
63,
7212,
8,
277,
304,
507,
198,
1038,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
17,
566,
507,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
17,
12,
6682,
14,
4627,
9,
507,
198,
277,
14,
1815,
8,
67,
442,
8,
281,
23416,
14,
374,
63,
529,
321,
1688,
63,
7212,
63,
3827,
8,
1038,
14,
4627,
1826,
413,
9,
507,
198,
1038,
14,
3176,
342,
507,
198,
1038,
14,
7275,
342,
2742,
198,
277,
14,
1074,
63,
3845,
63,
509,
63,
1038,
8,
1038,
14,
354,
9,
2742,
198,
409,
63,
529,
321,
1688,
63,
7212,
8,
16,
12,
6682,
14,
4627,
9,
421,
198,
318,
511,
63,
9187,
63,
3270,
63,
4399,
63,
2117,
8,
277,
304,
507,
198,
1038,
275,
6950,
14,
1574,
63,
1301,
8,
396,
63,
6502,
59,
17,
566,
507,
198,
1038,
14,
3176,
342,
507,
198,
277,
14,
1815,
8,
1038,
14,
7948,
63,
7211,
9,
507,
198,
277,
14,
629,
8,
1038,
14,
7948,
63,
7211,
59,
16,
1055,
11933,
63,
602,
12,
6682,
14,
11933,
63,
602,
9,
421,
198,
318,
511,
63,
7948,
63,
2373,
63,
7162,
63,
17777,
63,
9533,
63,
5404,
8,
277,
304,
507,
198,
504,
29106,
14,
8370,
14,
6356,
14,
7948,
63,
2373,
14,
396,
63,
7948,
63,
2373,
492,
664,
63,
7948,
63,
2373,
507,
198,
7162,
63,
7948,
63,
265,
63,
6406,
63,
1618,
63,
5404,
8,
16,
9,
2742,
198,
1038,
63,
1301,
275,
1852,
63,
9533,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MQQiang/kbengine
|
kbe/src/lib/python/Lib/test/test_email/test_message.py
|
72
|
26378
|
import unittest
import textwrap
from email import policy, message_from_string
from email.message import EmailMessage, MIMEPart
from test.test_email import TestEmailBase, parameterize
# Helper.
def first(iterable):
return next(filter(lambda x: x is not None, iterable), None)
class Test(TestEmailBase):
policy = policy.default
def test_error_on_setitem_if_max_count_exceeded(self):
m = self._str_msg("")
m['To'] = 'abc@xyz'
with self.assertRaises(ValueError):
m['To'] = 'xyz@abc'
def test_rfc2043_auto_decoded_and_emailmessage_used(self):
m = message_from_string(textwrap.dedent("""\
Subject: Ayons asperges pour le =?utf-8?q?d=C3=A9jeuner?=
From: =?utf-8?q?Pep=C3=A9?= Le Pew <pepe@example.com>
To: "Penelope Pussycat" <"penelope@example.com">
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
sample text
"""), policy=policy.default)
self.assertEqual(m['subject'], "Ayons asperges pour le déjeuner")
self.assertEqual(m['from'], "Pepé Le Pew <pepe@example.com>")
self.assertIsInstance(m, EmailMessage)
@parameterize
class TestEmailMessageBase:
policy = policy.default
# The first argument is a triple (related, html, plain) of indices into the
# list returned by 'walk' called on a Message constructed from the third.
# The indices indicate which part should match the corresponding part-type
# when passed to get_body (ie: the "first" part of that type in the
# message). The second argument is a list of indices into the 'walk' list
# of the attachments that should be returned by a call to
# 'iter_attachments'. The third argument is a list of indices into 'walk'
# that should be returned by a call to 'iter_parts'. Note that the first
# item returned by 'walk' is the Message itself.
message_params = {
'empty_message': (
(None, None, 0),
(),
(),
""),
'non_mime_plain': (
(None, None, 0),
(),
(),
textwrap.dedent("""\
To: foo@example.com
simple text body
""")),
'mime_non_text': (
(None, None, None),
(),
(),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: image/jpg
bogus body.
""")),
'plain_html_alternative': (
(None, 2, 1),
(),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="==="
preamble
--===
Content-Type: text/plain
simple body
--===
Content-Type: text/html
<p>simple body</p>
--===--
""")),
'plain_html_mixed': (
(None, 2, 1),
(),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
preamble
--===
Content-Type: text/plain
simple body
--===
Content-Type: text/html
<p>simple body</p>
--===--
""")),
'plain_html_attachment_mixed': (
(None, None, 1),
(2,),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: text/plain
simple body
--===
Content-Type: text/html
Content-Disposition: attachment
<p>simple body</p>
--===--
""")),
'html_text_attachment_mixed': (
(None, 2, None),
(1,),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: text/plain
Content-Disposition: AtTaChment
simple body
--===
Content-Type: text/html
<p>simple body</p>
--===--
""")),
'html_text_attachment_inline_mixed': (
(None, 2, 1),
(),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: text/plain
Content-Disposition: InLine
simple body
--===
Content-Type: text/html
Content-Disposition: inline
<p>simple body</p>
--===--
""")),
# RFC 2387
'related': (
(0, 1, None),
(2,),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/related; boundary="==="; type=text/html
--===
Content-Type: text/html
<p>simple body</p>
--===
Content-Type: image/jpg
Content-ID: <image1>
bogus data
--===--
""")),
# This message structure will probably never be seen in the wild, but
# it proves we distinguish between text parts based on 'start'. The
# content would not, of course, actually work :)
'related_with_start': (
(0, 2, None),
(1,),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/related; boundary="==="; type=text/html;
start="<body>"
--===
Content-Type: text/html
Content-ID: <include>
useless text
--===
Content-Type: text/html
Content-ID: <body>
<p>simple body</p>
<!--#include file="<include>"-->
--===--
""")),
'mixed_alternative_plain_related': (
(3, 4, 2),
(6, 7),
(1, 6, 7),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: multipart/alternative; boundary="+++"
--+++
Content-Type: text/plain
simple body
--+++
Content-Type: multipart/related; boundary="___"
--___
Content-Type: text/html
<p>simple body</p>
--___
Content-Type: image/jpg
Content-ID: <image1@cid>
bogus jpg body
--___--
--+++--
--===
Content-Type: image/jpg
Content-Disposition: attachment
bogus jpg body
--===
Content-Type: image/jpg
Content-Disposition: AttacHmenT
another bogus jpg body
--===--
""")),
# This structure suggested by Stephen J. Turnbull...may not exist/be
# supported in the wild, but we want to support it.
'mixed_related_alternative_plain_html': (
(1, 4, 3),
(6, 7),
(1, 6, 7),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: multipart/related; boundary="+++"
--+++
Content-Type: multipart/alternative; boundary="___"
--___
Content-Type: text/plain
simple body
--___
Content-Type: text/html
<p>simple body</p>
--___--
--+++
Content-Type: image/jpg
Content-ID: <image1@cid>
bogus jpg body
--+++--
--===
Content-Type: image/jpg
Content-Disposition: attachment
bogus jpg body
--===
Content-Type: image/jpg
Content-Disposition: attachment
another bogus jpg body
--===--
""")),
# Same thing, but proving we only look at the root part, which is the
# first one if there isn't any start parameter. That is, this is a
# broken related.
'mixed_related_alternative_plain_html_wrong_order': (
(1, None, None),
(6, 7),
(1, 6, 7),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: multipart/related; boundary="+++"
--+++
Content-Type: image/jpg
Content-ID: <image1@cid>
bogus jpg body
--+++
Content-Type: multipart/alternative; boundary="___"
--___
Content-Type: text/plain
simple body
--___
Content-Type: text/html
<p>simple body</p>
--___--
--+++--
--===
Content-Type: image/jpg
Content-Disposition: attachment
bogus jpg body
--===
Content-Type: image/jpg
Content-Disposition: attachment
another bogus jpg body
--===--
""")),
'message_rfc822': (
(None, None, None),
(),
(),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: message/rfc822
To: bar@example.com
From: robot@examp.com
this is a message body.
""")),
'mixed_text_message_rfc822': (
(None, None, 1),
(2,),
(1, 2),
textwrap.dedent("""\
To: foo@example.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==="
--===
Content-Type: text/plain
Your message has bounced, ser.
--===
Content-Type: message/rfc822
To: bar@example.com
From: robot@examp.com
this is a message body.
--===--
""")),
}
def message_as_get_body(self, body_parts, attachments, parts, msg):
m = self._str_msg(msg)
allparts = list(m.walk())
expected = [None if n is None else allparts[n] for n in body_parts]
related = 0; html = 1; plain = 2
self.assertEqual(m.get_body(), first(expected))
self.assertEqual(m.get_body(preferencelist=(
'related', 'html', 'plain')),
first(expected))
self.assertEqual(m.get_body(preferencelist=('related', 'html')),
first(expected[related:html+1]))
self.assertEqual(m.get_body(preferencelist=('related', 'plain')),
first([expected[related], expected[plain]]))
self.assertEqual(m.get_body(preferencelist=('html', 'plain')),
first(expected[html:plain+1]))
self.assertEqual(m.get_body(preferencelist=['related']),
expected[related])
self.assertEqual(m.get_body(preferencelist=['html']), expected[html])
self.assertEqual(m.get_body(preferencelist=['plain']), expected[plain])
self.assertEqual(m.get_body(preferencelist=('plain', 'html')),
first(expected[plain:html-1:-1]))
self.assertEqual(m.get_body(preferencelist=('plain', 'related')),
first([expected[plain], expected[related]]))
self.assertEqual(m.get_body(preferencelist=('html', 'related')),
first(expected[html::-1]))
self.assertEqual(m.get_body(preferencelist=('plain', 'html', 'related')),
first(expected[::-1]))
self.assertEqual(m.get_body(preferencelist=('html', 'plain', 'related')),
first([expected[html],
expected[plain],
expected[related]]))
def message_as_iter_attachment(self, body_parts, attachments, parts, msg):
m = self._str_msg(msg)
allparts = list(m.walk())
attachments = [allparts[n] for n in attachments]
self.assertEqual(list(m.iter_attachments()), attachments)
def message_as_iter_parts(self, body_parts, attachments, parts, msg):
m = self._str_msg(msg)
allparts = list(m.walk())
parts = [allparts[n] for n in parts]
self.assertEqual(list(m.iter_parts()), parts)
class _TestContentManager:
def get_content(self, msg, *args, **kw):
return msg, args, kw
def set_content(self, msg, *args, **kw):
self.msg = msg
self.args = args
self.kw = kw
def test_get_content_with_cm(self):
m = self._str_msg('')
cm = self._TestContentManager()
self.assertEqual(m.get_content(content_manager=cm), (m, (), {}))
msg, args, kw = m.get_content('foo', content_manager=cm, bar=1, k=2)
self.assertEqual(msg, m)
self.assertEqual(args, ('foo',))
self.assertEqual(kw, dict(bar=1, k=2))
def test_get_content_default_cm_comes_from_policy(self):
p = policy.default.clone(content_manager=self._TestContentManager())
m = self._str_msg('', policy=p)
self.assertEqual(m.get_content(), (m, (), {}))
msg, args, kw = m.get_content('foo', bar=1, k=2)
self.assertEqual(msg, m)
self.assertEqual(args, ('foo',))
self.assertEqual(kw, dict(bar=1, k=2))
def test_set_content_with_cm(self):
m = self._str_msg('')
cm = self._TestContentManager()
m.set_content(content_manager=cm)
self.assertEqual(cm.msg, m)
self.assertEqual(cm.args, ())
self.assertEqual(cm.kw, {})
m.set_content('foo', content_manager=cm, bar=1, k=2)
self.assertEqual(cm.msg, m)
self.assertEqual(cm.args, ('foo',))
self.assertEqual(cm.kw, dict(bar=1, k=2))
def test_set_content_default_cm_comes_from_policy(self):
cm = self._TestContentManager()
p = policy.default.clone(content_manager=cm)
m = self._str_msg('', policy=p)
m.set_content()
self.assertEqual(cm.msg, m)
self.assertEqual(cm.args, ())
self.assertEqual(cm.kw, {})
m.set_content('foo', bar=1, k=2)
self.assertEqual(cm.msg, m)
self.assertEqual(cm.args, ('foo',))
self.assertEqual(cm.kw, dict(bar=1, k=2))
# outcome is whether xxx_method should raise ValueError error when called
# on multipart/subtype. Blank outcome means it depends on xxx (add
# succeeds, make raises). Note: 'none' means there are content-type
# headers but payload is None...this happening in practice would be very
# unusual, so treating it as if there were content seems reasonable.
# method subtype outcome
subtype_params = (
('related', 'no_content', 'succeeds'),
('related', 'none', 'succeeds'),
('related', 'plain', 'succeeds'),
('related', 'related', ''),
('related', 'alternative', 'raises'),
('related', 'mixed', 'raises'),
('alternative', 'no_content', 'succeeds'),
('alternative', 'none', 'succeeds'),
('alternative', 'plain', 'succeeds'),
('alternative', 'related', 'succeeds'),
('alternative', 'alternative', ''),
('alternative', 'mixed', 'raises'),
('mixed', 'no_content', 'succeeds'),
('mixed', 'none', 'succeeds'),
('mixed', 'plain', 'succeeds'),
('mixed', 'related', 'succeeds'),
('mixed', 'alternative', 'succeeds'),
('mixed', 'mixed', ''),
)
def _make_subtype_test_message(self, subtype):
m = self.message()
payload = None
msg_headers = [
('To', 'foo@bar.com'),
('From', 'bar@foo.com'),
]
if subtype != 'no_content':
('content-shadow', 'Logrus'),
msg_headers.append(('X-Random-Header', 'Corwin'))
if subtype == 'text':
payload = ''
msg_headers.append(('Content-Type', 'text/plain'))
m.set_payload('')
elif subtype != 'no_content':
payload = []
msg_headers.append(('Content-Type', 'multipart/' + subtype))
msg_headers.append(('X-Trump', 'Random'))
m.set_payload(payload)
for name, value in msg_headers:
m[name] = value
return m, msg_headers, payload
def _check_disallowed_subtype_raises(self, m, method_name, subtype, method):
with self.assertRaises(ValueError) as ar:
getattr(m, method)()
exc_text = str(ar.exception)
self.assertIn(subtype, exc_text)
self.assertIn(method_name, exc_text)
def _check_make_multipart(self, m, msg_headers, payload):
count = 0
for name, value in msg_headers:
if not name.lower().startswith('content-'):
self.assertEqual(m[name], value)
count += 1
self.assertEqual(len(m), count+1) # +1 for new Content-Type
part = next(m.iter_parts())
count = 0
for name, value in msg_headers:
if name.lower().startswith('content-'):
self.assertEqual(part[name], value)
count += 1
self.assertEqual(len(part), count)
self.assertEqual(part.get_payload(), payload)
def subtype_as_make(self, method, subtype, outcome):
m, msg_headers, payload = self._make_subtype_test_message(subtype)
make_method = 'make_' + method
if outcome in ('', 'raises'):
self._check_disallowed_subtype_raises(m, method, subtype, make_method)
return
getattr(m, make_method)()
self.assertEqual(m.get_content_maintype(), 'multipart')
self.assertEqual(m.get_content_subtype(), method)
if subtype == 'no_content':
self.assertEqual(len(m.get_payload()), 0)
self.assertEqual(m.items(),
msg_headers + [('Content-Type',
'multipart/'+method)])
else:
self.assertEqual(len(m.get_payload()), 1)
self._check_make_multipart(m, msg_headers, payload)
def subtype_as_make_with_boundary(self, method, subtype, outcome):
# Doing all variation is a bit of overkill...
m = self.message()
if outcome in ('', 'raises'):
m['Content-Type'] = 'multipart/' + subtype
with self.assertRaises(ValueError) as cm:
getattr(m, 'make_' + method)()
return
if subtype == 'plain':
m['Content-Type'] = 'text/plain'
elif subtype != 'no_content':
m['Content-Type'] = 'multipart/' + subtype
getattr(m, 'make_' + method)(boundary="abc")
self.assertTrue(m.is_multipart())
self.assertEqual(m.get_boundary(), 'abc')
def test_policy_on_part_made_by_make_comes_from_message(self):
for method in ('make_related', 'make_alternative', 'make_mixed'):
m = self.message(policy=self.policy.clone(content_manager='foo'))
m['Content-Type'] = 'text/plain'
getattr(m, method)()
self.assertEqual(m.get_payload(0).policy.content_manager, 'foo')
class _TestSetContentManager:
def set_content(self, msg, content, *args, **kw):
msg['Content-Type'] = 'text/plain'
msg.set_payload(content)
def subtype_as_add(self, method, subtype, outcome):
m, msg_headers, payload = self._make_subtype_test_message(subtype)
cm = self._TestSetContentManager()
add_method = 'add_attachment' if method=='mixed' else 'add_' + method
if outcome == 'raises':
self._check_disallowed_subtype_raises(m, method, subtype, add_method)
return
getattr(m, add_method)('test', content_manager=cm)
self.assertEqual(m.get_content_maintype(), 'multipart')
self.assertEqual(m.get_content_subtype(), method)
if method == subtype or subtype == 'no_content':
self.assertEqual(len(m.get_payload()), 1)
for name, value in msg_headers:
self.assertEqual(m[name], value)
part = m.get_payload()[0]
else:
self.assertEqual(len(m.get_payload()), 2)
self._check_make_multipart(m, msg_headers, payload)
part = m.get_payload()[1]
self.assertEqual(part.get_content_type(), 'text/plain')
self.assertEqual(part.get_payload(), 'test')
if method=='mixed':
self.assertEqual(part['Content-Disposition'], 'attachment')
elif method=='related':
self.assertEqual(part['Content-Disposition'], 'inline')
else:
# Otherwise we don't guess.
self.assertIsNone(part['Content-Disposition'])
class _TestSetRaisingContentManager:
def set_content(self, msg, content, *args, **kw):
raise Exception('test')
def test_default_content_manager_for_add_comes_from_policy(self):
cm = self._TestSetRaisingContentManager()
m = self.message(policy=self.policy.clone(content_manager=cm))
for method in ('add_related', 'add_alternative', 'add_attachment'):
with self.assertRaises(Exception) as ar:
getattr(m, method)('')
self.assertEqual(str(ar.exception), 'test')
def message_as_clear(self, body_parts, attachments, parts, msg):
m = self._str_msg(msg)
m.clear()
self.assertEqual(len(m), 0)
self.assertEqual(list(m.items()), [])
self.assertIsNone(m.get_payload())
self.assertEqual(list(m.iter_parts()), [])
def message_as_clear_content(self, body_parts, attachments, parts, msg):
m = self._str_msg(msg)
expected_headers = [h for h in m.keys()
if not h.lower().startswith('content-')]
m.clear_content()
self.assertEqual(list(m.keys()), expected_headers)
self.assertIsNone(m.get_payload())
self.assertEqual(list(m.iter_parts()), [])
def test_is_attachment(self):
m = self._make_message()
self.assertFalse(m.is_attachment())
with self.assertWarns(DeprecationWarning):
self.assertFalse(m.is_attachment)
m['Content-Disposition'] = 'inline'
self.assertFalse(m.is_attachment())
with self.assertWarns(DeprecationWarning):
self.assertFalse(m.is_attachment)
m.replace_header('Content-Disposition', 'attachment')
self.assertTrue(m.is_attachment())
with self.assertWarns(DeprecationWarning):
self.assertTrue(m.is_attachment)
m.replace_header('Content-Disposition', 'AtTachMent')
self.assertTrue(m.is_attachment())
with self.assertWarns(DeprecationWarning):
self.assertTrue(m.is_attachment)
m.set_param('filename', 'abc.png', 'Content-Disposition')
self.assertTrue(m.is_attachment())
with self.assertWarns(DeprecationWarning):
self.assertTrue(m.is_attachment)
class TestEmailMessage(TestEmailMessageBase, TestEmailBase):
message = EmailMessage
def test_set_content_adds_MIME_Version(self):
m = self._str_msg('')
cm = self._TestContentManager()
self.assertNotIn('MIME-Version', m)
m.set_content(content_manager=cm)
self.assertEqual(m['MIME-Version'], '1.0')
class _MIME_Version_adding_CM:
def set_content(self, msg, *args, **kw):
msg['MIME-Version'] = '1.0'
def test_set_content_does_not_duplicate_MIME_Version(self):
m = self._str_msg('')
cm = self._MIME_Version_adding_CM()
self.assertNotIn('MIME-Version', m)
m.set_content(content_manager=cm)
self.assertEqual(m['MIME-Version'], '1.0')
class TestMIMEPart(TestEmailMessageBase, TestEmailBase):
# Doing the full test run here may seem a bit redundant, since the two
# classes are almost identical. But what if they drift apart? So we do
# the full tests so that any future drift doesn't introduce bugs.
message = MIMEPart
def test_set_content_does_not_add_MIME_Version(self):
m = self._str_msg('')
cm = self._TestContentManager()
self.assertNotIn('MIME-Version', m)
m.set_content(content_manager=cm)
self.assertNotIn('MIME-Version', m)
if __name__ == '__main__':
unittest.main()
|
lgpl-3.0
|
[
646,
2882,
199,
646,
13390,
199,
504,
3031,
492,
4592,
12,
1245,
63,
504,
63,
875,
199,
504,
3031,
14,
1188,
492,
11426,
2209,
12,
14735,
8416,
199,
504,
511,
14,
396,
63,
2123,
492,
1379,
7035,
1563,
12,
18117,
6236,
806,
421,
199,
3,
11642,
14,
199,
318,
1642,
8,
8147,
304,
272,
372,
2163,
8,
1541,
8,
2734,
671,
26,
671,
365,
440,
488,
12,
6076,
395,
488,
9,
421,
199,
533,
1379,
8,
774,
7035,
1563,
304,
339,
4592,
275,
4592,
14,
885,
339,
347,
511,
63,
705,
63,
265,
63,
8617,
63,
692,
63,
988,
63,
835,
63,
476,
19750,
8,
277,
304,
267,
333,
275,
291,
423,
495,
63,
1328,
10804,
267,
333,
459,
1378,
418,
275,
283,
3175,
32,
8568,
7,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
333,
459,
1378,
418,
275,
283,
8568,
32,
3175,
7,
339,
347,
511,
63,
8973,
18,
5882,
63,
2495,
63,
16167,
63,
460,
63,
2123,
1188,
63,
2972,
8,
277,
304,
267,
333,
275,
1245,
63,
504,
63,
875,
8,
505,
3823,
14,
14674,
21723,
288,
26793,
26,
437,
89,
4654,
465,
529,
3389,
299,
567,
1026,
24785,
1624,
13,
24,
31,
81,
31,
68,
29,
35,
19,
29,
33,
25,
6532,
324,
281,
23295,
288,
11606,
26,
24785,
1624,
13,
24,
31,
81,
31,
48,
1545,
29,
35,
19,
29,
33,
25,
23295,
7005,
510,
546,
665,
321,
321,
32,
2694,
14,
957,
30,
288,
4005,
26,
298,
48,
6349,
14363,
510,
27678,
89,
3385,
2,
665,
2,
897,
69,
14363,
32,
2694,
14,
957,
1743,
288,
14735,
13,
3353,
26,
413,
14,
16,
288,
6646,
13,
804,
26,
1318,
15,
6104,
27,
5960,
628,
1624,
13,
24,
2,
953,
2690,
1318,
288,
408,
395,
4592,
29,
3185,
14,
885,
9,
267,
291,
14,
629,
8,
77,
459,
5875,
995,
298,
33,
89,
4654,
465,
529,
3389,
299,
567,
1026,
366,
5741,
6532,
324,
281,
531,
267,
291,
14,
629,
8,
77,
459,
504,
995,
298,
48,
1545,
5741,
7005,
510,
546,
665,
321,
321,
32,
2694,
14,
957,
9579,
267,
291,
14,
6926,
8,
77,
12,
11426,
2209,
9,
421,
199,
32,
8121,
6236,
806,
199,
533,
1379,
7035,
2209,
1563,
26,
339,
4592,
275,
4592,
14,
885,
339,
327,
710,
1642,
1423,
365,
282,
19671,
334,
2407,
12,
3517,
12,
8971,
9,
402,
4918,
1901,
314,
272,
327,
769,
2138,
701,
283,
7757,
7,
2797,
641,
282,
6430,
14701,
687,
314,
10919,
14,
272,
327,
710,
4918,
6623,
1314,
1777,
1077,
1336,
314,
5226,
1777,
13,
466,
272,
327,
1380,
3032,
370,
664,
63,
2030,
334,
1873,
26,
314,
298,
2246,
2,
1777,
402,
626,
730,
315,
314,
272,
327,
1245,
680,
221,
710,
3499,
1423,
365,
282,
769,
402,
4918,
1901,
314,
283,
7757,
7,
769,
272,
327,
402,
314,
18912,
626,
1077,
506,
2138,
701,
282,
1240,
370,
272,
327,
283,
1661,
63,
15855,
1370,
221,
710,
10919,
1423,
365,
282,
769,
402,
4918,
1901,
283,
7757,
7,
272,
327,
626,
1077,
506,
2138,
701,
282,
1240,
370,
283,
1661,
63,
4181,
1370,
221,
3390,
626,
314,
1642,
272,
327,
1242,
2138,
701,
283,
7757,
7,
365,
314,
6430,
6337,
14,
339,
1245,
63,
1162,
275,
469,
398,
283,
1667,
63,
1188,
356,
334,
288,
334,
403,
12,
488,
12,
378,
395,
288,
11969,
288,
11969,
288,
16241,
398,
283,
2865,
63,
7626,
63,
6104,
356,
334,
288,
334,
403,
12,
488,
12,
378,
395,
288,
11969,
288,
11969,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
2234,
3486,
1318,
2396,
355,
408,
1826,
398,
283,
7626,
63,
2865,
63,
505,
356,
334,
288,
334,
403,
12,
488,
12,
488,
395,
288,
11969,
288,
11969,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
1834,
15,
8476,
2234,
23703,
2396,
14,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
19389,
356,
334,
288,
334,
403,
12,
499,
12,
413,
395,
288,
11969,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
19389,
27,
8424,
628,
389,
628,
2234,
19789,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
355,
1553,
5918,
306,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
10455,
356,
334,
288,
334,
403,
12,
499,
12,
413,
395,
288,
11969,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
10455,
27,
8424,
628,
389,
628,
2234,
19789,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
2234,
1553,
5918,
306,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
8905,
63,
10455,
356,
334,
288,
334,
403,
12,
488,
12,
413,
395,
288,
334,
18,
4706,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
10455,
27,
8424,
628,
389,
628,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
355,
6646,
13,
15954,
26,
12193,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
2234,
1553,
5918,
306,
355,
408,
1826,
398,
283,
1360,
63,
505,
63,
8905,
63,
10455,
356,
334,
288,
334,
403,
12,
499,
12,
488,
395,
288,
334,
17,
4706,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13
] |
[
2882,
199,
646,
13390,
199,
504,
3031,
492,
4592,
12,
1245,
63,
504,
63,
875,
199,
504,
3031,
14,
1188,
492,
11426,
2209,
12,
14735,
8416,
199,
504,
511,
14,
396,
63,
2123,
492,
1379,
7035,
1563,
12,
18117,
6236,
806,
421,
199,
3,
11642,
14,
199,
318,
1642,
8,
8147,
304,
272,
372,
2163,
8,
1541,
8,
2734,
671,
26,
671,
365,
440,
488,
12,
6076,
395,
488,
9,
421,
199,
533,
1379,
8,
774,
7035,
1563,
304,
339,
4592,
275,
4592,
14,
885,
339,
347,
511,
63,
705,
63,
265,
63,
8617,
63,
692,
63,
988,
63,
835,
63,
476,
19750,
8,
277,
304,
267,
333,
275,
291,
423,
495,
63,
1328,
10804,
267,
333,
459,
1378,
418,
275,
283,
3175,
32,
8568,
7,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
333,
459,
1378,
418,
275,
283,
8568,
32,
3175,
7,
339,
347,
511,
63,
8973,
18,
5882,
63,
2495,
63,
16167,
63,
460,
63,
2123,
1188,
63,
2972,
8,
277,
304,
267,
333,
275,
1245,
63,
504,
63,
875,
8,
505,
3823,
14,
14674,
21723,
288,
26793,
26,
437,
89,
4654,
465,
529,
3389,
299,
567,
1026,
24785,
1624,
13,
24,
31,
81,
31,
68,
29,
35,
19,
29,
33,
25,
6532,
324,
281,
23295,
288,
11606,
26,
24785,
1624,
13,
24,
31,
81,
31,
48,
1545,
29,
35,
19,
29,
33,
25,
23295,
7005,
510,
546,
665,
321,
321,
32,
2694,
14,
957,
30,
288,
4005,
26,
298,
48,
6349,
14363,
510,
27678,
89,
3385,
2,
665,
2,
897,
69,
14363,
32,
2694,
14,
957,
1743,
288,
14735,
13,
3353,
26,
413,
14,
16,
288,
6646,
13,
804,
26,
1318,
15,
6104,
27,
5960,
628,
1624,
13,
24,
2,
953,
2690,
1318,
288,
408,
395,
4592,
29,
3185,
14,
885,
9,
267,
291,
14,
629,
8,
77,
459,
5875,
995,
298,
33,
89,
4654,
465,
529,
3389,
299,
567,
1026,
366,
5741,
6532,
324,
281,
531,
267,
291,
14,
629,
8,
77,
459,
504,
995,
298,
48,
1545,
5741,
7005,
510,
546,
665,
321,
321,
32,
2694,
14,
957,
9579,
267,
291,
14,
6926,
8,
77,
12,
11426,
2209,
9,
421,
199,
32,
8121,
6236,
806,
199,
533,
1379,
7035,
2209,
1563,
26,
339,
4592,
275,
4592,
14,
885,
339,
327,
710,
1642,
1423,
365,
282,
19671,
334,
2407,
12,
3517,
12,
8971,
9,
402,
4918,
1901,
314,
272,
327,
769,
2138,
701,
283,
7757,
7,
2797,
641,
282,
6430,
14701,
687,
314,
10919,
14,
272,
327,
710,
4918,
6623,
1314,
1777,
1077,
1336,
314,
5226,
1777,
13,
466,
272,
327,
1380,
3032,
370,
664,
63,
2030,
334,
1873,
26,
314,
298,
2246,
2,
1777,
402,
626,
730,
315,
314,
272,
327,
1245,
680,
221,
710,
3499,
1423,
365,
282,
769,
402,
4918,
1901,
314,
283,
7757,
7,
769,
272,
327,
402,
314,
18912,
626,
1077,
506,
2138,
701,
282,
1240,
370,
272,
327,
283,
1661,
63,
15855,
1370,
221,
710,
10919,
1423,
365,
282,
769,
402,
4918,
1901,
283,
7757,
7,
272,
327,
626,
1077,
506,
2138,
701,
282,
1240,
370,
283,
1661,
63,
4181,
1370,
221,
3390,
626,
314,
1642,
272,
327,
1242,
2138,
701,
283,
7757,
7,
365,
314,
6430,
6337,
14,
339,
1245,
63,
1162,
275,
469,
398,
283,
1667,
63,
1188,
356,
334,
288,
334,
403,
12,
488,
12,
378,
395,
288,
11969,
288,
11969,
288,
16241,
398,
283,
2865,
63,
7626,
63,
6104,
356,
334,
288,
334,
403,
12,
488,
12,
378,
395,
288,
11969,
288,
11969,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
2234,
3486,
1318,
2396,
355,
408,
1826,
398,
283,
7626,
63,
2865,
63,
505,
356,
334,
288,
334,
403,
12,
488,
12,
488,
395,
288,
11969,
288,
11969,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
1834,
15,
8476,
2234,
23703,
2396,
14,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
19389,
356,
334,
288,
334,
403,
12,
499,
12,
413,
395,
288,
11969,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
19389,
27,
8424,
628,
389,
628,
2234,
19789,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
355,
1553,
5918,
306,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
10455,
356,
334,
288,
334,
403,
12,
499,
12,
413,
395,
288,
11969,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
10455,
27,
8424,
628,
389,
628,
2234,
19789,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
2234,
1553,
5918,
306,
355,
408,
1826,
398,
283,
6104,
63,
1360,
63,
8905,
63,
10455,
356,
334,
288,
334,
403,
12,
488,
12,
413,
395,
288,
334,
18,
4706,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
804,
26,
15193,
15,
10455,
27,
8424,
628,
389,
628,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
6104,
2234,
3486,
2396,
2234,
1553,
5918,
355,
6646,
13,
804,
26,
1318,
15,
1360,
355,
6646,
13,
15954,
26,
12193,
2234,
665,
80,
30,
4129,
2396,
1108,
80,
30,
2234,
1553,
5918,
306,
355,
408,
1826,
398,
283,
1360,
63,
505,
63,
8905,
63,
10455,
356,
334,
288,
334,
403,
12,
499,
12,
488,
395,
288,
334,
17,
4706,
288,
334,
17,
12,
499,
395,
288,
13390,
14,
14674,
21723,
355,
4005,
26,
3925,
32,
2694,
14,
957,
355,
14735,
13,
3353,
26,
413,
14,
16,
355,
6646,
13,
0
] |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1
] |
DOV-Vlaanderen/pydov
|
setup.py
|
1
|
2043
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""The setup script."""
from setuptools import find_packages, setup
with open('README.md') as readme_file:
readme = readme_file.read()
with open('HISTORY.rst') as history_file:
history = history_file.read()
with open('requirements.txt') as f:
requirements = f.read().splitlines()
with open('requirements_dev.txt') as f:
# ignore the general requirements
requirements_dev = f.read().splitlines()[1:]
with open('requirements_doc.txt') as f:
requirements_doc = f.read().splitlines()
with open('requirements_vectorfile.txt') as f:
requirements_vectorfile = f.read().splitlines()
setup(
name='pydov',
version='2.1.0',
description=("A Python package to download data from Databank Ondergrond "
"Vlaanderen (DOV)."),
long_description=readme,
long_description_content_type='text/markdown',
author="DOV-Vlaanderen",
author_email='dov@vlaanderen.be',
url='https://github.com/DOV-Vlaanderen/pydov',
packages=find_packages(
include=['pydov']),
include_package_data=True,
install_requires=requirements,
license="MIT license",
zip_safe=False,
keywords='pydov',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Natural Language :: Dutch',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering',
],
test_suite='tests',
tests_require=requirements_dev,
extras_require={
'docs': requirements_doc,
'devs': requirements_dev,
'vectorfile': requirements_vectorfile
}
)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
1918,
3272,
2884,
1041,
199,
199,
504,
9116,
492,
2342,
63,
5154,
12,
3272,
199,
199,
1045,
1551,
360,
18195,
14,
1064,
358,
465,
1586,
278,
63,
493,
26,
272,
1586,
278,
275,
1586,
278,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
360,
30895,
14,
8332,
358,
465,
7994,
63,
493,
26,
272,
7994,
275,
7994,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
360,
7538,
14,
2424,
358,
465,
289,
26,
272,
9760,
275,
289,
14,
739,
1252,
7644,
342,
199,
1045,
1551,
360,
7538,
63,
2374,
14,
2424,
358,
465,
289,
26,
272,
327,
3686,
314,
8605,
9760,
272,
9760,
63,
2374,
275,
289,
14,
739,
1252,
7644,
3430,
17,
2938,
199,
1045,
1551,
360,
7538,
63,
1301,
14,
2424,
358,
465,
289,
26,
272,
9760,
63,
1301,
275,
289,
14,
739,
1252,
7644,
342,
199,
1045,
1551,
360,
7538,
63,
4106,
493,
14,
2424,
358,
465,
289,
26,
272,
9760,
63,
4106,
493,
275,
289,
14,
739,
1252,
7644,
342,
199,
199,
2758,
8,
272,
536,
534,
647,
1117,
86,
297,
272,
1015,
534,
18,
14,
17,
14,
16,
297,
272,
1369,
15387,
33,
2018,
2559,
370,
5235,
666,
687,
577,
1936,
3580,
4068,
424,
2587,
7835,
298,
326,
298,
54,
416,
290,
271,
828,
334,
1649,
54,
680,
1288,
272,
1846,
63,
1802,
29,
32709,
12,
272,
1846,
63,
1802,
63,
1317,
63,
466,
534,
505,
15,
15653,
297,
272,
4132,
628,
1649,
54,
13,
54,
416,
290,
271,
828,
401,
272,
4132,
63,
2123,
534,
1117,
86,
32,
86,
416,
290,
271,
828,
14,
1235,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
1649,
54,
13,
54,
416,
290,
271,
828,
15,
647,
1117,
86,
297,
272,
6117,
29,
1623,
63,
5154,
8,
267,
2387,
2968,
647,
1117,
86,
3815,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
29,
7538,
12,
272,
4190,
628,
13965,
4190,
401,
272,
3482,
63,
3489,
29,
797,
12,
272,
7681,
534,
647,
1117,
86,
297,
272,
19137,
1524,
288,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
288,
283,
23910,
23975,
3800,
23493,
297,
288,
283,
23910,
23975,
3800,
27491,
15,
497,
1733,
297,
288,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
288,
283,
23604,
4889,
8466,
3800,
20144,
297,
288,
283,
23604,
4889,
8466,
3800,
577,
337,
335,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
22,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
23,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
24,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
25,
297,
288,
283,
12157,
3800,
16578,
23509,
15,
8524,
15663,
297,
272,
2156,
272,
511,
63,
5768,
534,
2219,
297,
272,
2295,
63,
4365,
29,
7538,
63,
2374,
12,
272,
13751,
63,
4365,
3126,
267,
283,
4757,
356,
9760,
63,
1301,
12,
267,
283,
18804,
356,
9760,
63,
2374,
12,
267,
283,
4106,
493,
356,
9760,
63,
4106,
493,
272,
789,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
1918,
3272,
2884,
1041,
199,
199,
504,
9116,
492,
2342,
63,
5154,
12,
3272,
199,
199,
1045,
1551,
360,
18195,
14,
1064,
358,
465,
1586,
278,
63,
493,
26,
272,
1586,
278,
275,
1586,
278,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
360,
30895,
14,
8332,
358,
465,
7994,
63,
493,
26,
272,
7994,
275,
7994,
63,
493,
14,
739,
342,
199,
199,
1045,
1551,
360,
7538,
14,
2424,
358,
465,
289,
26,
272,
9760,
275,
289,
14,
739,
1252,
7644,
342,
199,
1045,
1551,
360,
7538,
63,
2374,
14,
2424,
358,
465,
289,
26,
272,
327,
3686,
314,
8605,
9760,
272,
9760,
63,
2374,
275,
289,
14,
739,
1252,
7644,
3430,
17,
2938,
199,
1045,
1551,
360,
7538,
63,
1301,
14,
2424,
358,
465,
289,
26,
272,
9760,
63,
1301,
275,
289,
14,
739,
1252,
7644,
342,
199,
1045,
1551,
360,
7538,
63,
4106,
493,
14,
2424,
358,
465,
289,
26,
272,
9760,
63,
4106,
493,
275,
289,
14,
739,
1252,
7644,
342,
199,
199,
2758,
8,
272,
536,
534,
647,
1117,
86,
297,
272,
1015,
534,
18,
14,
17,
14,
16,
297,
272,
1369,
15387,
33,
2018,
2559,
370,
5235,
666,
687,
577,
1936,
3580,
4068,
424,
2587,
7835,
298,
326,
298,
54,
416,
290,
271,
828,
334,
1649,
54,
680,
1288,
272,
1846,
63,
1802,
29,
32709,
12,
272,
1846,
63,
1802,
63,
1317,
63,
466,
534,
505,
15,
15653,
297,
272,
4132,
628,
1649,
54,
13,
54,
416,
290,
271,
828,
401,
272,
4132,
63,
2123,
534,
1117,
86,
32,
86,
416,
290,
271,
828,
14,
1235,
297,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
1649,
54,
13,
54,
416,
290,
271,
828,
15,
647,
1117,
86,
297,
272,
6117,
29,
1623,
63,
5154,
8,
267,
2387,
2968,
647,
1117,
86,
3815,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3907,
63,
6537,
29,
7538,
12,
272,
4190,
628,
13965,
4190,
401,
272,
3482,
63,
3489,
29,
797,
12,
272,
7681,
534,
647,
1117,
86,
297,
272,
19137,
1524,
288,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
288,
283,
23910,
23975,
3800,
23493,
297,
288,
283,
23910,
23975,
3800,
27491,
15,
497,
1733,
297,
288,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
288,
283,
23604,
4889,
8466,
3800,
20144,
297,
288,
283,
23604,
4889,
8466,
3800,
577,
337,
335,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
22,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
23,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
24,
297,
288,
283,
11411,
8466,
3800,
2018,
3800,
650,
14,
25,
297,
288,
283,
12157,
3800,
16578,
23509,
15,
8524,
15663,
297,
272,
2156,
272,
511,
63,
5768,
534,
2219,
297,
272,
2295,
63,
4365,
29,
7538,
63,
2374,
12,
272,
13751,
63,
4365,
3126,
267,
283,
4757,
356,
9760,
63,
1301,
12,
267,
283,
18804,
356,
9760,
63,
2374,
12,
267,
283,
4106,
493,
356,
9760,
63,
4106,
493,
272,
789,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
lxybox1/MissionPlanner
|
Lib/site-packages/numpy/distutils/misc_util.py
|
53
|
84156
|
import os
import re
import sys
import imp
import copy
import glob
import atexit
import tempfile
import subprocess
import shutil
from distutils.errors import DistutilsError
try:
set
except NameError:
from sets import Set as set
from numpy.distutils.compat import get_exception
__all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',
'dict_append', 'appendpath', 'generate_config_py',
'get_cmd', 'allpath', 'get_mathlibs',
'terminal_has_colors', 'red_text', 'green_text', 'yellow_text',
'blue_text', 'cyan_text', 'cyg2win32','mingw32','all_strings',
'has_f_sources', 'has_cxx_sources', 'filter_sources',
'get_dependencies', 'is_local_src_dir', 'get_ext_source_files',
'get_script_files', 'get_lib_source_files', 'get_data_files',
'dot_join', 'get_frame', 'minrelpath','njoin',
'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language',
'quote_args', 'get_build_architecture', 'get_info', 'get_pkg_info']
class InstallableLib:
"""
Container to hold information on an installable library.
Parameters
----------
name : str
Name of the installed library.
build_info : dict
Dictionary holding build information.
target_dir : str
Absolute path specifying where to install the library.
See Also
--------
Configuration.add_installed_library
Notes
-----
The three parameters are stored as attributes with the same names.
"""
def __init__(self, name, build_info, target_dir):
self.name = name
self.build_info = build_info
self.target_dir = target_dir
def quote_args(args):
# don't used _nt_quote_args as it does not check if
# args items already have quotes or not.
args = list(args)
for i in range(len(args)):
a = args[i]
if ' ' in a and a[0] not in '"\'':
args[i] = '"%s"' % (a)
return args
def allpath(name):
"Convert a /-separated pathname to one using the OS's path separator."
splitted = name.split('/')
return os.path.join(*splitted)
def rel_path(path, parent_path):
"""Return path relative to parent_path.
"""
pd = os.path.abspath(parent_path)
apath = os.path.abspath(path)
if len(apath)<len(pd):
return path
if apath==pd:
return ''
if pd == apath[:len(pd)]:
assert apath[len(pd)] in [os.sep],repr((path,apath[len(pd)]))
path = apath[len(pd)+1:]
return path
def get_path_from_frame(frame, parent_path=None):
"""Return path of the module given a frame object from the call stack.
Returned path is relative to parent_path when given,
otherwise it is absolute path.
"""
# First, try to find if the file name is in the frame.
try:
caller_file = eval('__file__', frame.f_globals, frame.f_locals)
d = os.path.dirname(os.path.abspath(caller_file))
except NameError:
# __file__ is not defined, so let's try __name__. We try this second
# because setuptools spoofs __name__ to be '__main__' even though
# sys.modules['__main__'] might be something else, like easy_install(1).
caller_name = eval('__name__', frame.f_globals, frame.f_locals)
__import__(caller_name)
mod = sys.modules[caller_name]
if hasattr(mod, '__file__'):
d = os.path.dirname(os.path.abspath(mod.__file__))
else:
# we're probably running setup.py as execfile("setup.py")
# (likely we're building an egg)
d = os.path.abspath('.')
# hmm, should we use sys.argv[0] like in __builtin__ case?
if parent_path is not None:
d = rel_path(d, parent_path)
return d or '.'
def njoin(*path):
"""Join two or more pathname components +
- convert a /-separated pathname to one using the OS's path separator.
- resolve `..` and `.` from path.
Either passing n arguments as in njoin('a','b'), or a sequence
of n names as in njoin(['a','b']) is handled, or a mixture of such arguments.
"""
paths = []
for p in path:
if is_sequence(p):
# njoin(['a', 'b'], 'c')
paths.append(njoin(*p))
else:
assert is_string(p)
paths.append(p)
path = paths
if not path:
# njoin()
joined = ''
else:
# njoin('a', 'b')
joined = os.path.join(*path)
if os.path.sep != '/':
joined = joined.replace('/',os.path.sep)
return minrelpath(joined)
def get_mathlibs(path=None):
"""Return the MATHLIB line from numpyconfig.h
"""
if path is not None:
config_file = os.path.join(path,'_numpyconfig.h')
else:
# Look for the file in each of the numpy include directories.
dirs = get_numpy_include_dirs()
for path in dirs:
fn = os.path.join(path,'_numpyconfig.h')
if os.path.exists(fn):
config_file = fn
break
else:
raise DistutilsError('_numpyconfig.h not found in numpy include '
'dirs %r' % (dirs,))
fid = open(config_file)
mathlibs = []
s = '#define MATHLIB'
for line in fid.readlines():
if line.startswith(s):
value = line[len(s):].strip()
if value:
mathlibs.extend(value.split(','))
fid.close()
return mathlibs
def minrelpath(path):
"""Resolve `..` and '.' from path.
"""
if not is_string(path):
return path
if '.' not in path:
return path
l = path.split(os.sep)
while l:
try:
i = l.index('.',1)
except ValueError:
break
del l[i]
j = 1
while l:
try:
i = l.index('..',j)
except ValueError:
break
if l[i-1]=='..':
j += 1
else:
del l[i],l[i-1]
j = 1
if not l:
return ''
return os.sep.join(l)
def _fix_paths(paths,local_path,include_non_existing):
assert is_sequence(paths), repr(type(paths))
new_paths = []
assert not is_string(paths),repr(paths)
for n in paths:
if is_string(n):
if '*' in n or '?' in n:
p = glob.glob(n)
p2 = glob.glob(njoin(local_path,n))
if p2:
new_paths.extend(p2)
elif p:
new_paths.extend(p)
else:
if include_non_existing:
new_paths.append(n)
print('could not resolve pattern in %r: %r' \
% (local_path,n))
else:
n2 = njoin(local_path,n)
if os.path.exists(n2):
new_paths.append(n2)
else:
if os.path.exists(n):
new_paths.append(n)
elif include_non_existing:
new_paths.append(n)
if not os.path.exists(n):
print('non-existing path in %r: %r' \
% (local_path,n))
elif is_sequence(n):
new_paths.extend(_fix_paths(n,local_path,include_non_existing))
else:
new_paths.append(n)
return [minrelpath(p) for p in new_paths]
def gpaths(paths, local_path='', include_non_existing=True):
"""Apply glob to paths and prepend local_path if needed.
"""
if is_string(paths):
paths = (paths,)
return _fix_paths(paths,local_path, include_non_existing)
_temporary_directory = None
def clean_up_temporary_directory():
from numpy.distutils import log
global _temporary_directory
if not _temporary_directory:
return
log.debug('removing %s', _temporary_directory)
try:
shutil.rmtree(_temporary_directory)
except OSError:
pass
_temporary_directory = None
def make_temp_file(suffix='', prefix='', text=True):
global _temporary_directory
if not _temporary_directory:
_temporary_directory = tempfile.mkdtemp()
atexit.register(clean_up_temporary_directory)
fid, name = tempfile.mkstemp(suffix=suffix,
prefix=prefix,
dir=_temporary_directory,
text=text)
fo = os.fdopen(fid, 'w')
return fo, name
# Hooks for colored terminal output.
# See also http://www.livinglogic.de/Python/ansistyle
def terminal_has_colors():
if sys.platform=='cygwin' and 'USE_COLOR' not in os.environ:
# Avoid importing curses that causes illegal operation
# with a message:
# PYTHON2 caused an invalid page fault in
# module CYGNURSES7.DLL as 015f:18bbfc28
# Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]
# ssh to Win32 machine from debian
# curses.version is 2.2
# CYGWIN_98-4.10, release 1.5.7(0.109/3/2))
return 0
if hasattr(sys.stdout,'isatty') and sys.stdout.isatty():
try:
import curses
curses.setupterm()
if (curses.tigetnum("colors") >= 0
and curses.tigetnum("pairs") >= 0
and ((curses.tigetstr("setf") is not None
and curses.tigetstr("setb") is not None)
or (curses.tigetstr("setaf") is not None
and curses.tigetstr("setab") is not None)
or curses.tigetstr("scp") is not None)):
return 1
except Exception:
pass
return 0
if terminal_has_colors():
_colour_codes = dict(black=0, red=1, green=2, yellow=3,
blue=4, magenta=5, cyan=6, white=7, default=9)
def colour_text(s, fg=None, bg=None, bold=False):
seq = []
if bold:
seq.append('1')
if fg:
fgcode = 30 + _colour_codes.get(fg.lower(), 0)
seq.append(str(fgcode))
if bg:
bgcode = 40 + _colour_codes.get(fg.lower(), 7)
seq.append(str(bgcode))
if seq:
return '\x1b[%sm%s\x1b[0m' % (';'.join(seq), s)
else:
return s
else:
def colour_text(s, fg=None, bg=None):
return s
def default_text(s):
return colour_text(s, 'default')
def red_text(s):
return colour_text(s, 'red')
def green_text(s):
return colour_text(s, 'green')
def yellow_text(s):
return colour_text(s, 'yellow')
def cyan_text(s):
return colour_text(s, 'cyan')
def blue_text(s):
return colour_text(s, 'blue')
#########################
def cyg2win32(path):
if sys.platform=='cygwin' and path.startswith('/cygdrive'):
path = path[10] + ':' + os.path.normcase(path[11:])
return path
def mingw32():
"""Return true when using mingw32 environment.
"""
if sys.platform=='win32':
if os.environ.get('OSTYPE','')=='msys':
return True
if os.environ.get('MSYSTEM','')=='MINGW32':
return True
return False
def msvc_runtime_library():
"Return name of MSVC runtime library if Python was built with MSVC >= 7"
msc_pos = sys.version.find('MSC v.')
if msc_pos != -1:
msc_ver = sys.version[msc_pos+6:msc_pos+10]
lib = {'1300' : 'msvcr70', # MSVC 7.0
'1310' : 'msvcr71', # MSVC 7.1
'1400' : 'msvcr80', # MSVC 8
'1500' : 'msvcr90', # MSVC 9 (VS 2008)
}.get(msc_ver, None)
else:
lib = None
return lib
def msvc_on_amd64():
if not (sys.platform=='win32' or os.name=='nt'):
return
if get_build_architecture() != 'AMD64':
return
if 'DISTUTILS_USE_SDK' in os.environ:
return
# try to avoid _MSVCCompiler__root attribute error
print('Forcing DISTUTILS_USE_SDK=1')
os.environ['DISTUTILS_USE_SDK']='1'
return
#########################
#XXX need support for .C that is also C++
cxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\Z',re.I).match
fortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\Z',re.I).match
f90_ext_match = re.compile(r'.*[.](f90|f95)\Z',re.I).match
f90_module_name_match = re.compile(r'\s*module\s*(?P<name>[\w_]+)',re.I).match
def _get_f90_modules(source):
"""Return a list of Fortran f90 module names that
given source file defines.
"""
if not f90_ext_match(source):
return []
modules = []
f = open(source,'r')
f_readlines = getattr(f,'xreadlines',f.readlines)
for line in f_readlines():
m = f90_module_name_match(line)
if m:
name = m.group('name')
modules.append(name)
# break # XXX can we assume that there is one module per file?
f.close()
return modules
def is_string(s):
return isinstance(s, str)
def all_strings(lst):
"""Return True if all items in lst are string objects. """
for item in lst:
if not is_string(item):
return False
return True
def is_sequence(seq):
if is_string(seq):
return False
try:
len(seq)
except:
return False
return True
def is_glob_pattern(s):
return is_string(s) and ('*' in s or '?' is s)
def as_list(seq):
if is_sequence(seq):
return list(seq)
else:
return [seq]
def get_language(sources):
# not used in numpy/scipy packages, use build_ext.detect_language instead
"""Determine language value (c,f77,f90) from sources """
language = None
for source in sources:
if isinstance(source, str):
if f90_ext_match(source):
language = 'f90'
break
elif fortran_ext_match(source):
language = 'f77'
return language
def has_f_sources(sources):
"""Return True if sources contains Fortran files """
for source in sources:
if fortran_ext_match(source):
return True
return False
def has_cxx_sources(sources):
"""Return True if sources contains C++ files """
for source in sources:
if cxx_ext_match(source):
return True
return False
def filter_sources(sources):
"""Return four lists of filenames containing
C, C++, Fortran, and Fortran 90 module sources,
respectively.
"""
c_sources = []
cxx_sources = []
f_sources = []
fmodule_sources = []
for source in sources:
if fortran_ext_match(source):
modules = _get_f90_modules(source)
if modules:
fmodule_sources.append(source)
else:
f_sources.append(source)
elif cxx_ext_match(source):
cxx_sources.append(source)
else:
c_sources.append(source)
return c_sources, cxx_sources, f_sources, fmodule_sources
def _get_headers(directory_list):
# get *.h files from list of directories
headers = []
for d in directory_list:
head = glob.glob(os.path.join(d,"*.h")) #XXX: *.hpp files??
headers.extend(head)
return headers
def _get_directories(list_of_sources):
# get unique directories from list of sources.
direcs = []
for f in list_of_sources:
d = os.path.split(f)
if d[0] != '' and not d[0] in direcs:
direcs.append(d[0])
return direcs
def get_dependencies(sources):
#XXX scan sources for include statements
return _get_headers(_get_directories(sources))
def is_local_src_dir(directory):
"""Return true if directory is local directory.
"""
if not is_string(directory):
return False
abs_dir = os.path.abspath(directory)
c = os.path.commonprefix([os.getcwd(),abs_dir])
new_dir = abs_dir[len(c):].split(os.sep)
if new_dir and not new_dir[0]:
new_dir = new_dir[1:]
if new_dir and new_dir[0]=='build':
return False
new_dir = os.sep.join(new_dir)
return os.path.isdir(new_dir)
def general_source_files(top_path):
pruned_directories = {'CVS':1, '.svn':1, 'build':1}
prune_file_pat = re.compile(r'(?:[~#]|\.py[co]|\.o)$')
for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):
pruned = [ d for d in dirnames if d not in pruned_directories ]
dirnames[:] = pruned
for f in filenames:
if not prune_file_pat.search(f):
yield os.path.join(dirpath, f)
def general_source_directories_files(top_path):
"""Return a directory name relative to top_path and
files contained.
"""
pruned_directories = ['CVS','.svn','build']
prune_file_pat = re.compile(r'(?:[~#]|\.py[co]|\.o)$')
for dirpath, dirnames, filenames in os.walk(top_path, topdown=True):
pruned = [ d for d in dirnames if d not in pruned_directories ]
dirnames[:] = pruned
for d in dirnames:
dpath = os.path.join(dirpath, d)
rpath = rel_path(dpath, top_path)
files = []
for f in os.listdir(dpath):
fn = os.path.join(dpath,f)
if os.path.isfile(fn) and not prune_file_pat.search(fn):
files.append(fn)
yield rpath, files
dpath = top_path
rpath = rel_path(dpath, top_path)
filenames = [os.path.join(dpath,f) for f in os.listdir(dpath) \
if not prune_file_pat.search(f)]
files = [f for f in filenames if os.path.isfile(f)]
yield rpath, files
def get_ext_source_files(ext):
# Get sources and any include files in the same directory.
filenames = []
sources = filter(is_string, ext.sources)
filenames.extend(sources)
filenames.extend(get_dependencies(sources))
for d in ext.depends:
if is_local_src_dir(d):
filenames.extend(list(general_source_files(d)))
elif os.path.isfile(d):
filenames.append(d)
return filenames
def get_script_files(scripts):
scripts = filter(is_string, scripts)
return scripts
def get_lib_source_files(lib):
filenames = []
sources = lib[1].get('sources',[])
sources = filter(is_string, sources)
filenames.extend(sources)
filenames.extend(get_dependencies(sources))
depends = lib[1].get('depends',[])
for d in depends:
if is_local_src_dir(d):
filenames.extend(list(general_source_files(d)))
elif os.path.isfile(d):
filenames.append(d)
return filenames
def get_data_files(data):
if is_string(data):
return [data]
sources = data[1]
filenames = []
for s in sources:
if hasattr(s, '__call__'):
continue
if is_local_src_dir(s):
filenames.extend(list(general_source_files(s)))
elif is_string(s):
if os.path.isfile(s):
filenames.append(s)
else:
print('Not existing data file:',s)
else:
raise TypeError(repr(s))
return filenames
def dot_join(*args):
return '.'.join([a for a in args if a])
def get_frame(level=0):
"""Return frame object from call stack with given level.
"""
try:
return sys._getframe(level+1)
except AttributeError:
frame = sys.exc_info()[2].tb_frame
for _ in range(level+1):
frame = frame.f_back
return frame
class SconsInfo(object):
"""
Container object holding build info for building a package with scons.
Parameters
----------
scons_path : str or None
Path to scons script, relative to the directory of setup.py.
If None, no scons script is specified. This can be useful to add only
pre- and post-hooks to a configuration.
parent_name : str or None
Name of the parent package (for example "numpy").
pre_hook : sequence of callables or None
Callables that are executed before scons is invoked.
Each callable should be defined as ``callable(*args, **kw)``.
post_hook : sequence of callables or None
Callables that are executed after scons is invoked.
Each callable should be defined as ``callable(*args, **kw)``.
source_files : list of str or None
List of paths to source files, relative to the directory of setup.py.
pkg_path : str or None
Path to the package for which the `SconsInfo` instance holds the
build info, relative to the directory of setup.py.
Notes
-----
All parameters are available as attributes of a `SconsInfo` instance.
"""
def __init__(self, scons_path, parent_name, pre_hook,
post_hook, source_files, pkg_path):
self.scons_path = scons_path
self.parent_name = parent_name
self.pre_hook = pre_hook
self.post_hook = post_hook
self.source_files = source_files
if pkg_path:
self.pkg_path = pkg_path
else:
if scons_path:
self.pkg_path = os.path.dirname(scons_path)
else:
self.pkg_path = ''
######################
class Configuration(object):
_list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs',
'libraries', 'headers', 'scripts', 'py_modules', 'scons_data',
'installed_libraries']
_dict_keys = ['package_dir', 'installed_pkg_config']
_extra_keys = ['name', 'version']
numpy_include_dirs = []
def __init__(self,
package_name=None,
parent_name=None,
top_path=None,
package_path=None,
caller_level=1,
setup_name='setup.py',
**attrs):
"""Construct configuration instance of a package.
package_name -- name of the package
Ex.: 'distutils'
parent_name -- name of the parent package
Ex.: 'numpy'
top_path -- directory of the toplevel package
Ex.: the directory where the numpy package source sits
package_path -- directory of package. Will be computed by magic from the
directory of the caller module if not specified
Ex.: the directory where numpy.distutils is
caller_level -- frame level to caller namespace, internal parameter.
"""
self.name = dot_join(parent_name, package_name)
self.version = None
caller_frame = get_frame(caller_level)
self.local_path = get_path_from_frame(caller_frame, top_path)
# local_path -- directory of a file (usually setup.py) that
# defines a configuration() function.
# local_path -- directory of a file (usually setup.py) that
# defines a configuration() function.
if top_path is None:
top_path = self.local_path
self.local_path = ''
if package_path is None:
package_path = self.local_path
elif os.path.isdir(njoin(self.local_path,package_path)):
package_path = njoin(self.local_path,package_path)
if not os.path.isdir(package_path or '.'):
raise ValueError("%r is not a directory" % (package_path,))
self.top_path = top_path
self.package_path = package_path
# this is the relative path in the installed package
self.path_in_package = os.path.join(*self.name.split('.'))
self.list_keys = self._list_keys[:]
self.dict_keys = self._dict_keys[:]
for n in self.list_keys:
v = copy.copy(attrs.get(n, []))
setattr(self, n, as_list(v))
for n in self.dict_keys:
v = copy.copy(attrs.get(n, {}))
setattr(self, n, v)
known_keys = self.list_keys + self.dict_keys
self.extra_keys = self._extra_keys[:]
for n in attrs.keys():
if n in known_keys:
continue
a = attrs[n]
setattr(self,n,a)
if isinstance(a, list):
self.list_keys.append(n)
elif isinstance(a, dict):
self.dict_keys.append(n)
else:
self.extra_keys.append(n)
if os.path.exists(njoin(package_path,'__init__.py')):
self.packages.append(self.name)
self.package_dir[self.name] = package_path
self.options = dict(
ignore_setup_xxx_py = False,
assume_default_configuration = False,
delegate_options_to_subpackages = False,
quiet = False,
)
caller_instance = None
for i in range(1,3):
try:
f = get_frame(i)
except ValueError:
break
try:
caller_instance = eval('self',f.f_globals,f.f_locals)
break
except NameError:
pass
if isinstance(caller_instance, self.__class__):
if caller_instance.options['delegate_options_to_subpackages']:
self.set_options(**caller_instance.options)
self.setup_name = setup_name
def todict(self):
"""
Return a dictionary compatible with the keyword arguments of distutils
setup function.
Examples
--------
>>> setup(**config.todict()) #doctest: +SKIP
"""
self._optimize_data_files()
d = {}
known_keys = self.list_keys + self.dict_keys + self.extra_keys
for n in known_keys:
a = getattr(self,n)
if a:
d[n] = a
return d
def info(self, message):
if not self.options['quiet']:
print(message)
def warn(self, message):
sys.stderr.write('Warning: %s' % (message,))
def set_options(self, **options):
"""
Configure Configuration instance.
The following options are available:
- ignore_setup_xxx_py
- assume_default_configuration
- delegate_options_to_subpackages
- quiet
"""
for key, value in options.items():
if key in self.options:
self.options[key] = value
else:
raise ValueError('Unknown option: '+key)
def get_distribution(self):
"""Return the distutils distribution object for self."""
from numpy.distutils.core import get_distribution
return get_distribution()
def _wildcard_get_subpackage(self, subpackage_name,
parent_name,
caller_level = 1):
l = subpackage_name.split('.')
subpackage_path = njoin([self.local_path]+l)
dirs = filter(os.path.isdir,glob.glob(subpackage_path))
config_list = []
for d in dirs:
if not os.path.isfile(njoin(d,'__init__.py')):
continue
if 'build' in d.split(os.sep):
continue
n = '.'.join(d.split(os.sep)[-len(l):])
c = self.get_subpackage(n,
parent_name = parent_name,
caller_level = caller_level+1)
config_list.extend(c)
return config_list
def _get_configuration_from_setup_py(self, setup_py,
subpackage_name,
subpackage_path,
parent_name,
caller_level = 1):
# In case setup_py imports local modules:
sys.path.insert(0,os.path.dirname(setup_py))
try:
fo_setup_py = open(setup_py, 'U')
setup_name = os.path.splitext(os.path.basename(setup_py))[0]
n = dot_join(self.name,subpackage_name,setup_name)
setup_module = imp.load_module('_'.join(n.split('.')),
fo_setup_py,
setup_py,
('.py', 'U', 1))
fo_setup_py.close()
if not hasattr(setup_module,'configuration'):
if not self.options['assume_default_configuration']:
self.warn('Assuming default configuration '\
'(%s does not define configuration())'\
% (setup_module))
config = Configuration(subpackage_name, parent_name,
self.top_path, subpackage_path,
caller_level = caller_level + 1)
else:
pn = dot_join(*([parent_name] + subpackage_name.split('.')[:-1]))
args = (pn,)
def fix_args_py2(args):
if setup_module.configuration.func_code.co_argcount > 1:
args = args + (self.top_path,)
return args
def fix_args_py3(args):
if setup_module.configuration.__code__.co_argcount > 1:
args = args + (self.top_path,)
return args
if sys.version_info[0] < 3:
args = fix_args_py2(args)
else:
args = fix_args_py3(args)
config = setup_module.configuration(*args)
if config.name!=dot_join(parent_name,subpackage_name):
self.warn('Subpackage %r configuration returned as %r' % \
(dot_join(parent_name,subpackage_name), config.name))
finally:
del sys.path[0]
return config
def get_subpackage(self,subpackage_name,
subpackage_path=None,
parent_name=None,
caller_level = 1):
"""Return list of subpackage configurations.
Parameters
----------
subpackage_name: str,None
Name of the subpackage to get the configuration. '*' in
subpackage_name is handled as a wildcard.
subpackage_path: str
If None, then the path is assumed to be the local path plus the
subpackage_name. If a setup.py file is not found in the
subpackage_path, then a default configuration is used.
parent_name: str
Parent name.
"""
if subpackage_name is None:
if subpackage_path is None:
raise ValueError(
"either subpackage_name or subpackage_path must be specified")
subpackage_name = os.path.basename(subpackage_path)
# handle wildcards
l = subpackage_name.split('.')
if subpackage_path is None and '*' in subpackage_name:
return self._wildcard_get_subpackage(subpackage_name,
parent_name,
caller_level = caller_level+1)
assert '*' not in subpackage_name,repr((subpackage_name, subpackage_path,parent_name))
if subpackage_path is None:
subpackage_path = njoin([self.local_path] + l)
else:
subpackage_path = njoin([subpackage_path] + l[:-1])
subpackage_path = self.paths([subpackage_path])[0]
setup_py = njoin(subpackage_path, self.setup_name)
if not self.options['ignore_setup_xxx_py']:
if not os.path.isfile(setup_py):
setup_py = njoin(subpackage_path,
'setup_%s.py' % (subpackage_name))
if not os.path.isfile(setup_py):
if not self.options['assume_default_configuration']:
self.warn('Assuming default configuration '\
'(%s/{setup_%s,setup}.py was not found)' \
% (os.path.dirname(setup_py), subpackage_name))
config = Configuration(subpackage_name, parent_name,
self.top_path, subpackage_path,
caller_level = caller_level+1)
else:
config = self._get_configuration_from_setup_py(
setup_py,
subpackage_name,
subpackage_path,
parent_name,
caller_level = caller_level + 1)
if config:
return [config]
else:
return []
def add_subpackage(self,subpackage_name,
subpackage_path=None,
standalone = False):
"""Add a sub-package to the current Configuration instance.
This is useful in a setup.py script for adding sub-packages to a
package.
Parameters
----------
subpackage_name: str
name of the subpackage
subpackage_path: str
if given, the subpackage path such as the subpackage is in
subpackage_path / subpackage_name. If None,the subpackage is
assumed to be located in the local path / subpackage_name.
standalone: bool
"""
if standalone:
parent_name = None
else:
parent_name = self.name
config_list = self.get_subpackage(subpackage_name,subpackage_path,
parent_name = parent_name,
caller_level = 2)
if not config_list:
self.warn('No configuration returned, assuming unavailable.')
for config in config_list:
d = config
if isinstance(config, Configuration):
d = config.todict()
assert isinstance(d,dict),repr(type(d))
self.info('Appending %s configuration to %s'
% (d.get('name'), self.name))
self.dict_append(**d)
dist = self.get_distribution()
if dist is not None:
self.warn('distutils distribution has been initialized,'
' it may be too late to add a subpackage '+
subpackage_name)
def add_data_dir(self,data_path):
"""Recursively add files under data_path to data_files list.
Recursively add files under data_path to the list of data_files to be
installed (and distributed). The data_path can be either a relative
path-name, or an absolute path-name, or a 2-tuple where the first
argument shows where in the install directory the data directory
should be installed to.
Parameters
----------
data_path: seq,str
Argument can be either
* 2-sequence (<datadir suffix>,<path to data directory>)
* path to data directory where python datadir suffix defaults
to package dir.
Notes
-----
Rules for installation paths:
foo/bar -> (foo/bar, foo/bar) -> parent/foo/bar
(gun, foo/bar) -> parent/gun
foo/* -> (foo/a, foo/a), (foo/b, foo/b) -> parent/foo/a, parent/foo/b
(gun, foo/*) -> (gun, foo/a), (gun, foo/b) -> gun
(gun/*, foo/*) -> parent/gun/a, parent/gun/b
/foo/bar -> (bar, /foo/bar) -> parent/bar
(gun, /foo/bar) -> parent/gun
(fun/*/gun/*, sun/foo/bar) -> parent/fun/foo/gun/bar
Examples
--------
For example suppose the source directory contains fun/foo.dat and
fun/bar/car.dat::
>>> self.add_data_dir('fun') #doctest: +SKIP
>>> self.add_data_dir(('sun', 'fun')) #doctest: +SKIP
>>> self.add_data_dir(('gun', '/full/path/to/fun'))#doctest: +SKIP
Will install data-files to the locations::
<package install directory>/
fun/
foo.dat
bar/
car.dat
sun/
foo.dat
bar/
car.dat
gun/
foo.dat
car.dat
"""
if is_sequence(data_path):
d, data_path = data_path
else:
d = None
if is_sequence(data_path):
[self.add_data_dir((d,p)) for p in data_path]
return
if not is_string(data_path):
raise TypeError("not a string: %r" % (data_path,))
if d is None:
if os.path.isabs(data_path):
return self.add_data_dir((os.path.basename(data_path),
data_path))
return self.add_data_dir((data_path, data_path))
paths = self.paths(data_path, include_non_existing=False)
if is_glob_pattern(data_path):
if is_glob_pattern(d):
pattern_list = allpath(d).split(os.sep)
pattern_list.reverse()
# /a/*//b/ -> /a/*/b
rl = range(len(pattern_list)-1); rl.reverse()
for i in rl:
if not pattern_list[i]:
del pattern_list[i]
#
for path in paths:
if not os.path.isdir(path):
print('Not a directory, skipping',path)
continue
rpath = rel_path(path, self.local_path)
path_list = rpath.split(os.sep)
path_list.reverse()
target_list = []
i = 0
for s in pattern_list:
if is_glob_pattern(s):
if i>=len(path_list):
raise ValueError('cannot fill pattern %r with %r' \
% (d, path))
target_list.append(path_list[i])
else:
assert s==path_list[i],repr((s,path_list[i],data_path,d,path,rpath))
target_list.append(s)
i += 1
if path_list[i:]:
self.warn('mismatch of pattern_list=%s and path_list=%s'\
% (pattern_list,path_list))
target_list.reverse()
self.add_data_dir((os.sep.join(target_list),path))
else:
for path in paths:
self.add_data_dir((d,path))
return
assert not is_glob_pattern(d),repr(d)
dist = self.get_distribution()
if dist is not None and dist.data_files is not None:
data_files = dist.data_files
else:
data_files = self.data_files
for path in paths:
for d1,f in list(general_source_directories_files(path)):
target_path = os.path.join(self.path_in_package,d,d1)
data_files.append((target_path, f))
def _optimize_data_files(self):
data_dict = {}
for p,files in self.data_files:
if p not in data_dict:
data_dict[p] = set()
for f in files:
data_dict[p].add(f)
self.data_files[:] = [(p,list(files)) for p,files in data_dict.items()]
def add_data_files(self,*files):
"""Add data files to configuration data_files.
Parameters
----------
files: sequence
Argument(s) can be either
* 2-sequence (<datadir prefix>,<path to data file(s)>)
* paths to data files where python datadir prefix defaults
to package dir.
Notes
-----
The form of each element of the files sequence is very flexible
allowing many combinations of where to get the files from the package
and where they should ultimately be installed on the system. The most
basic usage is for an element of the files argument sequence to be a
simple filename. This will cause that file from the local path to be
installed to the installation path of the self.name package (package
path). The file argument can also be a relative path in which case the
entire relative path will be installed into the package directory.
Finally, the file can be an absolute path name in which case the file
will be found at the absolute path name but installed to the package
path.
This basic behavior can be augmented by passing a 2-tuple in as the
file argument. The first element of the tuple should specify the
relative path (under the package install directory) where the
remaining sequence of files should be installed to (it has nothing to
do with the file-names in the source distribution). The second element
of the tuple is the sequence of files that should be installed. The
files in this sequence can be filenames, relative paths, or absolute
paths. For absolute paths the file will be installed in the top-level
package installation directory (regardless of the first argument).
Filenames and relative path names will be installed in the package
install directory under the path name given as the first element of
the tuple.
Rules for installation paths:
#. file.txt -> (., file.txt)-> parent/file.txt
#. foo/file.txt -> (foo, foo/file.txt) -> parent/foo/file.txt
#. /foo/bar/file.txt -> (., /foo/bar/file.txt) -> parent/file.txt
#. *.txt -> parent/a.txt, parent/b.txt
#. foo/*.txt -> parent/foo/a.txt, parent/foo/b.txt
#. */*.txt -> (*, */*.txt) -> parent/c/a.txt, parent/d/b.txt
#. (sun, file.txt) -> parent/sun/file.txt
#. (sun, bar/file.txt) -> parent/sun/file.txt
#. (sun, /foo/bar/file.txt) -> parent/sun/file.txt
#. (sun, *.txt) -> parent/sun/a.txt, parent/sun/b.txt
#. (sun, bar/*.txt) -> parent/sun/a.txt, parent/sun/b.txt
#. (sun/*, */*.txt) -> parent/sun/c/a.txt, parent/d/b.txt
An additional feature is that the path to a data-file can actually be
a function that takes no arguments and returns the actual path(s) to
the data-files. This is useful when the data files are generated while
building the package.
Examples
--------
Add files to the list of data_files to be included with the package.
>>> self.add_data_files('foo.dat',
... ('fun', ['gun.dat', 'nun/pun.dat', '/tmp/sun.dat']),
... 'bar/cat.dat',
... '/full/path/to/can.dat') #doctest: +SKIP
will install these data files to::
<package install directory>/
foo.dat
fun/
gun.dat
nun/
pun.dat
sun.dat
bar/
car.dat
can.dat
where <package install directory> is the package (or sub-package)
directory such as '/usr/lib/python2.4/site-packages/mypackage' ('C:
\\Python2.4 \\Lib \\site-packages \\mypackage') or
'/usr/lib/python2.4/site- packages/mypackage/mysubpackage' ('C:
\\Python2.4 \\Lib \\site-packages \\mypackage \\mysubpackage').
"""
if len(files)>1:
for f in files:
self.add_data_files(f)
return
assert len(files)==1
if is_sequence(files[0]):
d,files = files[0]
else:
d = None
if is_string(files):
filepat = files
elif is_sequence(files):
if len(files)==1:
filepat = files[0]
else:
for f in files:
self.add_data_files((d,f))
return
else:
raise TypeError(repr(type(files)))
if d is None:
if hasattr(filepat, '__call__'):
d = ''
elif os.path.isabs(filepat):
d = ''
else:
d = os.path.dirname(filepat)
self.add_data_files((d,files))
return
paths = self.paths(filepat, include_non_existing=False)
if is_glob_pattern(filepat):
if is_glob_pattern(d):
pattern_list = d.split(os.sep)
pattern_list.reverse()
for path in paths:
path_list = path.split(os.sep)
path_list.reverse()
path_list.pop() # filename
target_list = []
i = 0
for s in pattern_list:
if is_glob_pattern(s):
target_list.append(path_list[i])
i += 1
else:
target_list.append(s)
target_list.reverse()
self.add_data_files((os.sep.join(target_list), path))
else:
self.add_data_files((d,paths))
return
assert not is_glob_pattern(d),repr((d,filepat))
dist = self.get_distribution()
if dist is not None and dist.data_files is not None:
data_files = dist.data_files
else:
data_files = self.data_files
data_files.append((os.path.join(self.path_in_package,d),paths))
### XXX Implement add_py_modules
def add_include_dirs(self,*paths):
"""Add paths to configuration include directories.
Add the given sequence of paths to the beginning of the include_dirs
list. This list will be visible to all extension modules of the
current package.
"""
include_dirs = self.paths(paths)
dist = self.get_distribution()
if dist is not None:
if dist.include_dirs is None:
dist.include_dirs = []
dist.include_dirs.extend(include_dirs)
else:
self.include_dirs.extend(include_dirs)
def add_numarray_include_dirs(self):
import numpy.numarray.util as nnu
self.add_include_dirs(*nnu.get_numarray_include_dirs())
def add_headers(self,*files):
"""Add installable headers to configuration.
Add the given sequence of files to the beginning of the headers list.
By default, headers will be installed under <python-
include>/<self.name.replace('.','/')>/ directory. If an item of files
is a tuple, then its first argument specifies the actual installation
location relative to the <python-include> path.
Parameters
----------
files: str, seq
Argument(s) can be either:
* 2-sequence (<includedir suffix>,<path to header file(s)>)
* path(s) to header file(s) where python includedir suffix will
default to package name.
"""
headers = []
for path in files:
if is_string(path):
[headers.append((self.name,p)) for p in self.paths(path)]
else:
if not isinstance(path, (tuple, list)) or len(path) != 2:
raise TypeError(repr(path))
[headers.append((path[0],p)) for p in self.paths(path[1])]
dist = self.get_distribution()
if dist is not None:
if dist.headers is None:
dist.headers = []
dist.headers.extend(headers)
else:
self.headers.extend(headers)
def paths(self,*paths,**kws):
"""Apply glob to paths and prepend local_path if needed.
Applies glob.glob(...) to each path in the sequence (if needed) and
pre-pends the local_path if needed. Because this is called on all
source lists, this allows wildcard characters to be specified in lists
of sources for extension modules and libraries and scripts and allows
path-names be relative to the source directory.
"""
include_non_existing = kws.get('include_non_existing',True)
return gpaths(paths,
local_path = self.local_path,
include_non_existing=include_non_existing)
def _fix_paths_dict(self,kw):
for k in kw.keys():
v = kw[k]
if k in ['sources','depends','include_dirs','library_dirs',
'module_dirs','extra_objects']:
new_v = self.paths(v)
kw[k] = new_v
def add_extension(self,name,sources,**kw):
"""Add extension to configuration.
Create and add an Extension instance to the ext_modules list. This
method also takes the following optional keyword arguments that are
passed on to the Extension constructor.
Parameters
----------
name: str
name of the extension
sources: seq
list of the sources. The list of sources may contain functions
(called source generators) which must take an extension instance
and a build directory as inputs and return a source file or list of
source files or None. If None is returned then no sources are
generated. If the Extension instance has no sources after
processing all source generators, then no extension module is
built.
include_dirs:
define_macros:
undef_macros:
library_dirs:
libraries:
runtime_library_dirs:
extra_objects:
extra_compile_args:
extra_link_args:
export_symbols:
swig_opts:
depends:
The depends list contains paths to files or directories that the
sources of the extension module depend on. If any path in the
depends list is newer than the extension module, then the module
will be rebuilt.
language:
f2py_options:
module_dirs:
extra_info: dict,list
dict or list of dict of keywords to be appended to keywords.
Notes
-----
The self.paths(...) method is applied to all lists that may contain
paths.
"""
ext_args = copy.copy(kw)
ext_args['name'] = dot_join(self.name, name)
ext_args['sources'] = sources
if 'extra_info' in ext_args:
extra_info = ext_args['extra_info']
del ext_args['extra_info']
if isinstance(extra_info, dict):
extra_info = [extra_info]
for info in extra_info:
assert isinstance(info, dict), repr(info)
dict_append(ext_args,**info)
self._fix_paths_dict(ext_args)
# Resolve out-of-tree dependencies
libraries = ext_args.get('libraries',[])
libnames = []
ext_args['libraries'] = []
for libname in libraries:
if isinstance(libname, tuple):
self._fix_paths_dict(libname[1])
# Handle library names of the form libname@relative/path/to/library
if '@' in libname:
lname, lpath = libname.split('@',1)
lpath = os.path.abspath(njoin(self.local_path, lpath))
if os.path.isdir(lpath):
c = self.get_subpackage(None, lpath, caller_level=2)
if isinstance(c, Configuration):
c = c.todict()
for l in [l[0] for l in c.get('libraries',[])]:
llname = l.split('__OF__',1)[0]
if llname == lname:
c.pop('name',None)
dict_append(ext_args,**c)
break
continue
libnames.append(libname)
ext_args['libraries'] = libnames + ext_args['libraries']
from numpy.distutils.core import Extension
ext = Extension(**ext_args)
self.ext_modules.append(ext)
dist = self.get_distribution()
if dist is not None:
self.warn('distutils distribution has been initialized,'
' it may be too late to add an extension ' + name)
return ext
def add_library(self,name,sources,**build_info):
"""
Add library to configuration.
Parameters
----------
name : str
Name of the extension.
sources : sequence
List of the sources. The list of sources may contain functions
(called source generators) which must take an extension instance
and a build directory as inputs and return a source file or list of
source files or None. If None is returned then no sources are
generated. If the Extension instance has no sources after
processing all source generators, then no extension module is
built.
build_info : dict, optional
The following keys are allowed:
* depends
* macros
* include_dirs
* extra_compiler_args
* f2py_options
* language
"""
self._add_library(name, sources, None, build_info)
dist = self.get_distribution()
if dist is not None:
self.warn('distutils distribution has been initialized,'\
' it may be too late to add a library '+ name)
def _add_library(self, name, sources, install_dir, build_info):
"""Common implementation for add_library and add_installed_library. Do
not use directly"""
build_info = copy.copy(build_info)
name = name #+ '__OF__' + self.name
build_info['sources'] = sources
# Sometimes, depends is not set up to an empty list by default, and if
# depends is not given to add_library, distutils barfs (#1134)
if not 'depends' in build_info:
build_info['depends'] = []
self._fix_paths_dict(build_info)
# Add to libraries list so that it is build with build_clib
self.libraries.append((name, build_info))
def add_installed_library(self, name, sources, install_dir, build_info=None):
"""
Similar to add_library, but the specified library is installed.
Most C libraries used with `distutils` are only used to build python
extensions, but libraries built through this method will be installed
so that they can be reused by third-party packages.
Parameters
----------
name : str
Name of the installed library.
sources : sequence
List of the library's source files. See `add_library` for details.
install_dir : str
Path to install the library, relative to the current sub-package.
build_info : dict, optional
The following keys are allowed:
* depends
* macros
* include_dirs
* extra_compiler_args
* f2py_options
* language
Returns
-------
None
See Also
--------
add_library, add_npy_pkg_config, get_info
Notes
-----
The best way to encode the options required to link against the specified
C libraries is to use a "libname.ini" file, and use `get_info` to
retrieve the required options (see `add_npy_pkg_config` for more
information).
"""
if not build_info:
build_info = {}
install_dir = os.path.join(self.package_path, install_dir)
self._add_library(name, sources, install_dir, build_info)
self.installed_libraries.append(InstallableLib(name, build_info, install_dir))
def add_npy_pkg_config(self, template, install_dir, subst_dict=None):
"""
Generate and install a npy-pkg config file from a template.
The config file generated from `template` is installed in the
given install directory, using `subst_dict` for variable substitution.
Parameters
----------
template : str
The path of the template, relatively to the current package path.
install_dir : str
Where to install the npy-pkg config file, relatively to the current
package path.
subst_dict : dict, optional
If given, any string of the form ``@key@`` will be replaced by
``subst_dict[key]`` in the template file when installed. The install
prefix is always available through the variable ``@prefix@``, since the
install prefix is not easy to get reliably from setup.py.
See also
--------
add_installed_library, get_info
Notes
-----
This works for both standard installs and in-place builds, i.e. the
``@prefix@`` refer to the source directory for in-place builds.
Examples
--------
::
config.add_npy_pkg_config('foo.ini.in', 'lib', {'foo': bar})
Assuming the foo.ini.in file has the following content::
[meta]
Name=@foo@
Version=1.0
Description=dummy description
[default]
Cflags=-I@prefix@/include
Libs=
The generated file will have the following content::
[meta]
Name=bar
Version=1.0
Description=dummy description
[default]
Cflags=-Iprefix_dir/include
Libs=
and will be installed as foo.ini in the 'lib' subpath.
"""
if subst_dict is None:
subst_dict = {}
basename = os.path.splitext(template)[0]
template = os.path.join(self.package_path, template)
if self.name in self.installed_pkg_config:
self.installed_pkg_config[self.name].append((template, install_dir,
subst_dict))
else:
self.installed_pkg_config[self.name] = [(template, install_dir,
subst_dict)]
def add_scons_installed_library(self, name, install_dir):
"""
Add a scons-built installable library to distutils.
Parameters
----------
name : str
The name of the library.
install_dir : str
Path to install the library, relative to the current sub-package.
"""
install_dir = os.path.join(self.package_path, install_dir)
self.installed_libraries.append(InstallableLib(name, {}, install_dir))
def add_sconscript(self, sconscript, subpackage_path=None,
standalone = False, pre_hook = None,
post_hook = None, source_files = None, package_path=None):
"""Add a sconscript to configuration.
pre_hook and post hook should be sequences of callable, which will be
use before and after executing scons. The callable should be defined as
callable(*args, **kw). It is ugly, but well, hooks are ugly anyway...
sconscript can be None, which can be useful to add only post/pre
hooks."""
if standalone:
parent_name = None
else:
parent_name = self.name
dist = self.get_distribution()
# Convert the sconscript name to a relative filename (relative from top
# setup.py's directory)
fullsconsname = self.paths(sconscript)[0]
# XXX: Think about a way to automatically register source files from
# scons...
full_source_files = []
if source_files:
full_source_files.extend([self.paths(i)[0] for i in source_files])
scons_info = SconsInfo(fullsconsname, parent_name,
pre_hook, post_hook,
full_source_files, package_path)
if dist is not None:
if dist.scons_data is None:
dist.scons_data = []
dist.scons_data.append(scons_info)
self.warn('distutils distribution has been initialized,'\
' it may be too late to add a subpackage '+ subpackage_name)
# XXX: we add a fake extension, to correctly initialize some
# options in distutils command.
dist.add_extension('', sources = [])
else:
self.scons_data.append(scons_info)
# XXX: we add a fake extension, to correctly initialize some
# options in distutils command.
self.add_extension('', sources = [])
def add_scripts(self,*files):
"""Add scripts to configuration.
Add the sequence of files to the beginning of the scripts list.
Scripts will be installed under the <prefix>/bin/ directory.
"""
scripts = self.paths(files)
dist = self.get_distribution()
if dist is not None:
if dist.scripts is None:
dist.scripts = []
dist.scripts.extend(scripts)
else:
self.scripts.extend(scripts)
def dict_append(self,**dict):
for key in self.list_keys:
a = getattr(self,key)
a.extend(dict.get(key,[]))
for key in self.dict_keys:
a = getattr(self,key)
a.update(dict.get(key,{}))
known_keys = self.list_keys + self.dict_keys + self.extra_keys
for key in dict.keys():
if key not in known_keys:
a = getattr(self, key, None)
if a and a==dict[key]: continue
self.warn('Inheriting attribute %r=%r from %r' \
% (key,dict[key],dict.get('name','?')))
setattr(self,key,dict[key])
self.extra_keys.append(key)
elif key in self.extra_keys:
self.info('Ignoring attempt to set %r (from %r to %r)' \
% (key, getattr(self,key), dict[key]))
elif key in known_keys:
# key is already processed above
pass
else:
raise ValueError("Don't know about key=%r" % (key))
def __str__(self):
from pprint import pformat
known_keys = self.list_keys + self.dict_keys + self.extra_keys
s = '<'+5*'-' + '\n'
s += 'Configuration of '+self.name+':\n'
known_keys.sort()
for k in known_keys:
a = getattr(self,k,None)
if a:
s += '%s = %s\n' % (k,pformat(a))
s += 5*'-' + '>'
return s
def get_config_cmd(self):
"""
Returns the numpy.distutils config command instance.
"""
cmd = get_cmd('config')
cmd.ensure_finalized()
cmd.dump_source = 0
cmd.noisy = 0
old_path = os.environ.get('PATH')
if old_path:
path = os.pathsep.join(['.',old_path])
os.environ['PATH'] = path
return cmd
def get_build_temp_dir(self):
"""
Return a path to a temporary directory where temporary files should be
placed.
"""
cmd = get_cmd('build')
cmd.ensure_finalized()
return cmd.build_temp
def have_f77c(self):
"""Check for availability of Fortran 77 compiler.
Use it inside source generating function to ensure that
setup distribution instance has been initialized.
Notes
-----
True if a Fortran 77 compiler is available (because a simple Fortran 77
code was able to be compiled successfully).
"""
simple_fortran_subroutine = '''
subroutine simple
end
'''
config_cmd = self.get_config_cmd()
flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f77')
return flag
def have_f90c(self):
"""Check for availability of Fortran 90 compiler.
Use it inside source generating function to ensure that
setup distribution instance has been initialized.
Notes
-----
True if a Fortran 90 compiler is available (because a simple Fortran
90 code was able to be compiled successfully)
"""
simple_fortran_subroutine = '''
subroutine simple
end
'''
config_cmd = self.get_config_cmd()
flag = config_cmd.try_compile(simple_fortran_subroutine,lang='f90')
return flag
def append_to(self, extlib):
"""Append libraries, include_dirs to extension or library item.
"""
if is_sequence(extlib):
lib_name, build_info = extlib
dict_append(build_info,
libraries=self.libraries,
include_dirs=self.include_dirs)
else:
from numpy.distutils.core import Extension
assert isinstance(extlib,Extension), repr(extlib)
extlib.libraries.extend(self.libraries)
extlib.include_dirs.extend(self.include_dirs)
def _get_svn_revision(self,path):
"""Return path's SVN revision number.
"""
revision = None
m = None
cwd = os.getcwd()
try:
os.chdir(path or '.')
p = subprocess.Popen(['svnversion'], shell=True,
stdout=subprocess.PIPE, stderr=None,
close_fds=True)
sout = p.stdout
m = re.match(r'(?P<revision>\d+)', sout.read())
except:
pass
os.chdir(cwd)
if m:
revision = int(m.group('revision'))
return revision
if sys.platform=='win32' and os.environ.get('SVN_ASP_DOT_NET_HACK',None):
entries = njoin(path,'_svn','entries')
else:
entries = njoin(path,'.svn','entries')
if os.path.isfile(entries):
f = open(entries)
fstr = f.read()
f.close()
if fstr[:5] == '<?xml': # pre 1.4
m = re.search(r'revision="(?P<revision>\d+)"',fstr)
if m:
revision = int(m.group('revision'))
else: # non-xml entries file --- check to be sure that
m = re.search(r'dir[\n\r]+(?P<revision>\d+)', fstr)
if m:
revision = int(m.group('revision'))
return revision
def _get_hg_revision(self,path):
"""Return path's Mercurial revision number.
"""
revision = None
m = None
cwd = os.getcwd()
try:
os.chdir(path or '.')
p = subprocess.Popen(['hg identify --num'], shell=True,
stdout=subprocess.PIPE, stderr=None,
close_fds=True)
sout = p.stdout
m = re.match(r'(?P<revision>\d+)', sout.read())
except:
pass
os.chdir(cwd)
if m:
revision = int(m.group('revision'))
return revision
branch_fn = njoin(path,'.hg','branch')
branch_cache_fn = njoin(path,'.hg','branch.cache')
if os.path.isfile(branch_fn):
branch0 = None
f = open(branch_fn)
revision0 = f.read().strip()
f.close()
branch_map = {}
for line in file(branch_cache_fn, 'r'):
branch1, revision1 = line.split()[:2]
if revision1==revision0:
branch0 = branch1
try:
revision1 = int(revision1)
except ValueError:
continue
branch_map[branch1] = revision1
revision = branch_map.get(branch0)
return revision
def get_version(self, version_file=None, version_variable=None):
"""Try to get version string of a package.
Return a version string of the current package or None if the version
information could not be detected.
Notes
-----
This method scans files named
__version__.py, <packagename>_version.py, version.py, and
__svn_version__.py for string variables version, __version\__, and
<packagename>_version, until a version number is found.
"""
version = getattr(self,'version',None)
if version is not None:
return version
# Get version from version file.
if version_file is None:
files = ['__version__.py',
self.name.split('.')[-1]+'_version.py',
'version.py',
'__svn_version__.py',
'__hg_version__.py']
else:
files = [version_file]
if version_variable is None:
version_vars = ['version',
'__version__',
self.name.split('.')[-1]+'_version']
else:
version_vars = [version_variable]
for f in files:
fn = njoin(self.local_path,f)
if os.path.isfile(fn):
info = (open(fn),fn,('.py','U',1))
name = os.path.splitext(os.path.basename(fn))[0]
n = dot_join(self.name,name)
try:
version_module = imp.load_module('_'.join(n.split('.')),*info)
except ImportError:
msg = get_exception()
self.warn(str(msg))
version_module = None
if version_module is None:
continue
for a in version_vars:
version = getattr(version_module,a,None)
if version is not None:
break
if version is not None:
break
if version is not None:
self.version = version
return version
# Get version as SVN or Mercurial revision number
revision = self._get_svn_revision(self.local_path)
if revision is None:
revision = self._get_hg_revision(self.local_path)
if revision is not None:
version = str(revision)
self.version = version
return version
def make_svn_version_py(self, delete=True):
"""Appends a data function to the data_files list that will generate
__svn_version__.py file to the current package directory.
Generate package __svn_version__.py file from SVN revision number,
it will be removed after python exits but will be available
when sdist, etc commands are executed.
Notes
-----
If __svn_version__.py existed before, nothing is done.
This is
intended for working with source directories that are in an SVN
repository.
"""
target = njoin(self.local_path,'__svn_version__.py')
revision = self._get_svn_revision(self.local_path)
if os.path.isfile(target) or revision is None:
return
else:
def generate_svn_version_py():
if not os.path.isfile(target):
version = str(revision)
self.info('Creating %s (version=%r)' % (target,version))
f = open(target,'w')
f.write('version = %r\n' % (version))
f.close()
import atexit
def rm_file(f=target,p=self.info):
if delete:
try: os.remove(f); p('removed '+f)
except OSError: pass
try: os.remove(f+'c'); p('removed '+f+'c')
except OSError: pass
atexit.register(rm_file)
return target
self.add_data_files(('', generate_svn_version_py()))
def make_hg_version_py(self, delete=True):
"""Appends a data function to the data_files list that will generate
__hg_version__.py file to the current package directory.
Generate package __hg_version__.py file from Mercurial revision,
it will be removed after python exits but will be available
when sdist, etc commands are executed.
Notes
-----
If __hg_version__.py existed before, nothing is done.
This is intended for working with source directories that are
in an Mercurial repository.
"""
target = njoin(self.local_path,'__hg_version__.py')
revision = self._get_hg_revision(self.local_path)
if os.path.isfile(target) or revision is None:
return
else:
def generate_hg_version_py():
if not os.path.isfile(target):
version = str(revision)
self.info('Creating %s (version=%r)' % (target,version))
f = open(target,'w')
f.write('version = %r\n' % (version))
f.close()
import atexit
def rm_file(f=target,p=self.info):
if delete:
try: os.remove(f); p('removed '+f)
except OSError: pass
try: os.remove(f+'c'); p('removed '+f+'c')
except OSError: pass
atexit.register(rm_file)
return target
self.add_data_files(('', generate_hg_version_py()))
def make_config_py(self,name='__config__'):
"""Generate package __config__.py file containing system_info
information used during building the package.
This file is installed to the
package installation directory.
"""
self.py_modules.append((self.name,name,generate_config_py))
def scons_make_config_py(self, name = '__config__'):
"""Generate package __config__.py file containing system_info
information used during building the package.
"""
self.py_modules.append((self.name, name, scons_generate_config_py))
def get_info(self,*names):
"""Get resources information.
Return information (from system_info.get_info) for all of the names in
the argument list in a single dictionary.
"""
from system_info import get_info, dict_append
info_dict = {}
for a in names:
dict_append(info_dict,**get_info(a))
return info_dict
def get_cmd(cmdname, _cache={}):
if cmdname not in _cache:
import distutils.core
dist = distutils.core._setup_distribution
if dist is None:
from distutils.errors import DistutilsInternalError
raise DistutilsInternalError(
'setup distribution instance not initialized')
cmd = dist.get_command_obj(cmdname)
_cache[cmdname] = cmd
return _cache[cmdname]
def get_numpy_include_dirs():
# numpy_include_dirs are set by numpy/core/setup.py, otherwise []
include_dirs = Configuration.numpy_include_dirs[:]
if not include_dirs:
import numpy
include_dirs = [ numpy.get_include() ]
# else running numpy/core/setup.py
return include_dirs
def get_npy_pkg_dir():
"""Return the path where to find the npy-pkg-config directory."""
# XXX: import here for bootstrapping reasons
import numpy
d = os.path.join(os.path.dirname(numpy.__file__),
'core', 'lib', 'npy-pkg-config')
return d
def get_pkg_info(pkgname, dirs=None):
"""
Return library info for the given package.
Parameters
----------
pkgname : str
Name of the package (should match the name of the .ini file, without
the extension, e.g. foo for the file foo.ini).
dirs : sequence, optional
If given, should be a sequence of additional directories where to look
for npy-pkg-config files. Those directories are searched prior to the
NumPy directory.
Returns
-------
pkginfo : class instance
The `LibraryInfo` instance containing the build information.
Raises
------
PkgNotFound
If the package is not found.
See Also
--------
Configuration.add_npy_pkg_config, Configuration.add_installed_library,
get_info
"""
from numpy.distutils.npy_pkg_config import read_config
if dirs:
dirs.append(get_npy_pkg_dir())
else:
dirs = [get_npy_pkg_dir()]
return read_config(pkgname, dirs)
def get_info(pkgname, dirs=None):
"""
Return an info dict for a given C library.
The info dict contains the necessary options to use the C library.
Parameters
----------
pkgname : str
Name of the package (should match the name of the .ini file, without
the extension, e.g. foo for the file foo.ini).
dirs : sequence, optional
If given, should be a sequence of additional directories where to look
for npy-pkg-config files. Those directories are searched prior to the
NumPy directory.
Returns
-------
info : dict
The dictionary with build information.
Raises
------
PkgNotFound
If the package is not found.
See Also
--------
Configuration.add_npy_pkg_config, Configuration.add_installed_library,
get_pkg_info
Examples
--------
To get the necessary information for the npymath library from NumPy:
>>> npymath_info = np.distutils.misc_util.get_info('npymath')
>>> npymath_info #doctest: +SKIP
{'define_macros': [], 'libraries': ['npymath'], 'library_dirs':
['.../numpy/core/lib'], 'include_dirs': ['.../numpy/core/include']}
This info dict can then be used as input to a `Configuration` instance::
config.add_extension('foo', sources=['foo.c'], extra_info=npymath_info)
"""
from numpy.distutils.npy_pkg_config import parse_flags
pkg_info = get_pkg_info(pkgname, dirs)
# Translate LibraryInfo instance into a build_info dict
info = parse_flags(pkg_info.cflags())
for k, v in parse_flags(pkg_info.libs()).items():
info[k].extend(v)
# add_extension extra_info argument is ANAL
info['define_macros'] = info['macros']
del info['macros']
del info['ignored']
return info
def is_bootstrapping():
import __builtin__
try:
__builtin__.__NUMPY_SETUP__
return True
except AttributeError:
return False
__NUMPY_SETUP__ = False
def scons_generate_config_py(target):
"""generate config.py file containing system_info information
used during building the package.
usage:
config['py_modules'].append((packagename, '__config__',generate_config_py))
"""
from distutils.dir_util import mkpath
from numscons import get_scons_configres_dir, get_scons_configres_filename
d = {}
mkpath(os.path.dirname(target))
f = open(target, 'w')
f.write('# this file is generated by %s\n' % (os.path.abspath(sys.argv[0])))
f.write('# it contains system_info results at the time of building this package.\n')
f.write('__all__ = ["show"]\n\n')
confdir = get_scons_configres_dir()
confilename = get_scons_configres_filename()
for root, dirs, files in os.walk(confdir):
if files:
file = os.path.join(root, confilename)
assert root.startswith(confdir)
pkg_name = '.'.join(root[len(confdir)+1:].split(os.sep))
fid = open(file, 'r')
try:
cnt = fid.read()
d[pkg_name] = eval(cnt)
finally:
fid.close()
# d is a dictionary whose keys are package names, and values the
# corresponding configuration. Each configuration is itself a dictionary
# (lib : libinfo)
f.write('_config = %s\n' % d)
f.write(r'''
def show():
for pkg, config in _config.items():
print("package %s configuration:" % pkg)
for lib, libc in config.items():
print(' %s' % lib)
for line in libc.split('\n'):
print('\t%s' % line)
''')
f.close()
return target
#########################
def default_config_dict(name = None, parent_name = None, local_path=None):
"""Return a configuration dictionary for usage in
configuration() function defined in file setup_<name>.py.
"""
import warnings
warnings.warn('Use Configuration(%r,%r,top_path=%r) instead of '\
'deprecated default_config_dict(%r,%r,%r)'
% (name, parent_name, local_path,
name, parent_name, local_path,
))
c = Configuration(name, parent_name, local_path)
return c.todict()
def dict_append(d, **kws):
for k, v in kws.items():
if k in d:
ov = d[k]
if isinstance(ov,str):
d[k] = v
else:
d[k].extend(v)
else:
d[k] = v
def appendpath(prefix, path):
if os.path.sep != '/':
prefix = prefix.replace('/', os.path.sep)
path = path.replace('/', os.path.sep)
drive = ''
if os.path.isabs(path):
drive = os.path.splitdrive(prefix)[0]
absprefix = os.path.splitdrive(os.path.abspath(prefix))[1]
pathdrive, path = os.path.splitdrive(path)
d = os.path.commonprefix([absprefix, path])
if os.path.join(absprefix[:len(d)], absprefix[len(d):]) != absprefix \
or os.path.join(path[:len(d)], path[len(d):]) != path:
# Handle invalid paths
d = os.path.dirname(d)
subpath = path[len(d):]
if os.path.isabs(subpath):
subpath = subpath[1:]
else:
subpath = path
return os.path.normpath(njoin(drive + prefix, subpath))
def generate_config_py(target):
"""Generate config.py file containing system_info information
used during building the package.
Usage:
config['py_modules'].append((packagename, '__config__',generate_config_py))
"""
from numpy.distutils.system_info import system_info
from distutils.dir_util import mkpath
mkpath(os.path.dirname(target))
f = open(target, 'w')
f.write('# This file is generated by %s\n' % (os.path.abspath(sys.argv[0])))
f.write('# It contains system_info results at the time of building this package.\n')
f.write('__all__ = ["get_info","show"]\n\n')
for k, i in system_info.saved_results.items():
f.write('%s=%r\n' % (k, i))
f.write(r'''
def get_info(name):
g = globals()
return g.get(name, g.get(name + "_info", {}))
def show():
for name,info_dict in globals().items():
if name[0] == "_" or type(info_dict) is not type({}): continue
print(name + ":")
if not info_dict:
print(" NOT AVAILABLE")
for k,v in info_dict.items():
v = str(v)
if k == "sources" and len(v) > 200:
v = v[:60] + " ...\n... " + v[-60:]
print(" %s = %s" % (k,v))
''')
f.close()
return target
def msvc_version(compiler):
"""Return version major and minor of compiler instance if it is
MSVC, raise an exception otherwise."""
if not compiler.compiler_type == "msvc":
raise ValueError("Compiler instance is not msvc (%s)"\
% compiler.compiler_type)
return compiler._MSVCCompiler__version
if sys.version[:3] >= '2.5':
def get_build_architecture():
from distutils.msvccompiler import get_build_architecture
return get_build_architecture()
else:
#copied from python 2.5.1 distutils/msvccompiler.py
def get_build_architecture():
"""Return the processor architecture.
Possible results are "Intel", "Itanium", or "AMD64".
"""
prefix = " bit ("
i = sys.version.find(prefix)
if i == -1:
return "Intel"
j = sys.version.find(")", i)
return sys.version[i+len(prefix):j]
|
gpl-3.0
|
[
646,
747,
199,
646,
295,
199,
646,
984,
199,
646,
1742,
199,
646,
1331,
199,
646,
5739,
199,
646,
19840,
199,
646,
5549,
199,
646,
3873,
199,
646,
5145,
199,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
504,
2680,
14,
13350,
14,
5819,
492,
664,
63,
1971,
199,
199,
363,
452,
363,
275,
788,
5688,
297,
283,
362,
63,
4714,
63,
2613,
63,
3220,
297,
283,
885,
63,
888,
63,
807,
297,
1779,
283,
807,
63,
740,
297,
283,
740,
515,
297,
283,
4208,
63,
888,
63,
647,
297,
1779,
283,
362,
63,
1760,
297,
283,
452,
515,
297,
283,
362,
63,
3442,
8450,
297,
1779,
283,
12010,
63,
1989,
63,
7120,
297,
283,
581,
63,
505,
297,
283,
7731,
63,
505,
297,
283,
14514,
63,
505,
297,
1779,
283,
6304,
63,
505,
297,
283,
28291,
63,
505,
297,
283,
15076,
18,
2676,
708,
1673,
14566,
87,
708,
1673,
452,
63,
5465,
297,
1779,
283,
1989,
63,
70,
63,
4553,
297,
283,
1989,
63,
9634,
63,
4553,
297,
283,
1541,
63,
4553,
297,
1779,
283,
362,
63,
5714,
297,
283,
374,
63,
1832,
63,
2164,
63,
694,
297,
283,
362,
63,
832,
63,
1365,
63,
1725,
297,
1779,
283,
362,
63,
1579,
63,
1725,
297,
283,
362,
63,
773,
63,
1365,
63,
1725,
297,
283,
362,
63,
576,
63,
1725,
297,
1779,
283,
3287,
63,
904,
297,
283,
362,
63,
1943,
297,
283,
827,
12405,
1673,
78,
904,
297,
1779,
283,
374,
63,
4041,
297,
283,
374,
63,
875,
297,
283,
305,
63,
513,
297,
283,
71,
3771,
297,
283,
362,
63,
3671,
297,
1779,
283,
3513,
63,
589,
297,
283,
362,
63,
1506,
63,
19134,
297,
283,
362,
63,
815,
297,
283,
362,
63,
4600,
63,
815,
418,
199,
199,
533,
13276,
461,
4728,
26,
272,
408,
272,
15395,
370,
10266,
2556,
641,
376,
3907,
461,
3555,
14,
339,
3897,
272,
4143,
272,
536,
520,
620,
267,
2812,
402,
314,
4903,
3555,
14,
272,
1900,
63,
815,
520,
1211,
267,
11932,
17573,
1900,
2556,
14,
272,
1347,
63,
694,
520,
620,
267,
24964,
931,
9176,
2382,
370,
3907,
314,
3555,
14,
339,
1666,
6121,
272,
3001,
272,
11595,
14,
525,
63,
7657,
63,
4342,
339,
8144,
272,
9063,
272,
710,
7795,
2633,
787,
5489,
465,
3004,
543,
314,
2011,
1561,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1900,
63,
815,
12,
1347,
63,
694,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1506,
63,
815,
275,
1900,
63,
815,
267,
291,
14,
1375,
63,
694,
275,
1347,
63,
694,
199,
199,
318,
6313,
63,
589,
8,
589,
304,
272,
327,
2793,
1133,
1202,
485,
343,
63,
3513,
63,
589,
465,
652,
1630,
440,
1104,
340,
272,
327,
1249,
2974,
2575,
1172,
9344,
503,
440,
14,
272,
1249,
275,
769,
8,
589,
9,
272,
367,
284,
315,
1425,
8,
552,
8,
589,
2298,
267,
282,
275,
1249,
59,
73,
61,
267,
340,
283,
283,
315,
282,
436,
282,
59,
16,
61,
440,
315,
283,
3212,
7,
356,
288,
1249,
59,
73,
61,
275,
18253,
83,
4507,
450,
334,
65,
9,
272,
372,
1249,
199,
199,
318,
1006,
515,
8,
354,
304,
272,
298,
7306,
282,
1182,
13,
12794,
11776,
370,
1373,
1808,
314,
4403,
1159,
931,
9432,
2122,
272,
30183,
275,
536,
14,
1294,
7825,
272,
372,
747,
14,
515,
14,
904,
2031,
1294,
471,
9,
199,
199,
318,
4668,
63,
515,
8,
515,
12,
1676,
63,
515,
304,
272,
408,
1767,
931,
3847,
370,
1676,
63,
515,
14,
272,
408,
272,
6454,
275,
747,
14,
515,
14,
4832,
8,
1708,
63,
515,
9,
272,
282,
515,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
822,
8,
65,
515,
21528,
552,
8,
8961,
304,
267,
372,
931,
272,
340,
282,
515,
389,
8961,
26,
267,
372,
2125,
272,
340,
6454,
508,
282,
515,
1491,
552,
8,
8961,
19532,
267,
702,
282,
515,
59,
552,
8,
8961,
1874,
315,
359,
736,
14,
4127,
467,
2722,
1332,
515,
12,
65,
515,
59,
552,
8,
8961,
19563,
267,
931,
275,
282,
515,
59,
552,
8,
8961,
6393,
17,
2938,
272,
372,
931,
199,
199,
318,
664,
63,
515,
63,
504,
63,
1943,
8,
1943,
12,
1676,
63,
515,
29,
403,
304,
272,
408,
1767,
931,
402,
314,
859,
1627,
282,
2787,
909,
687,
314,
1240,
3464,
14,
339,
19907,
931,
365,
3847,
370,
1676,
63,
515,
1380,
1627,
12,
272,
4257,
652,
365,
3679,
931,
14,
272,
408,
339,
327,
7758,
12,
862,
370,
2342,
340,
314,
570,
536,
365,
315,
314,
2787,
14,
272,
862,
26,
267,
8025,
63,
493,
275,
3468,
10714,
493,
7500,
2787,
14,
70,
63,
8473,
12,
2787,
14,
70,
63,
9350,
9,
267,
366,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
11219,
63,
493,
430,
272,
871,
12746,
26,
267,
327,
636,
493,
363,
365,
440,
3247,
12,
880,
4691,
1159,
862,
636,
354,
4343,
2136,
862,
642,
3499,
267,
327,
2952,
9116,
25664,
14105,
636,
354,
363,
370,
506,
2560,
973,
12217,
2755,
10617,
267,
327,
984,
14,
3112,
13742,
973,
17501,
5594,
506,
6020,
587,
12,
2839,
8837,
63,
3174,
8,
17,
680,
267,
8025,
63,
354,
275,
3468,
10714,
354,
7500,
2787,
14,
70,
63,
8473,
12,
2787,
14,
70,
63,
9350,
9,
267,
636,
646,
721,
11219,
63,
354,
9,
267,
3413,
275,
984,
14,
3112,
59,
11219,
63,
354,
61,
267,
340,
2688,
8,
1494,
12,
2560,
493,
12168,
288,
366,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1494,
855,
493,
8964,
267,
587,
26,
288,
327,
781,
3984,
8646,
3879,
3272,
14,
647,
465,
22711,
480,
2758,
14,
647,
531,
288,
327,
334,
24227,
781,
3984,
10015,
376,
11393,
9,
288,
366,
275,
747,
14,
515,
14,
4832,
7563,
288,
327,
394,
596,
12,
1077,
781,
675,
984,
14,
3020,
59,
16,
61,
2839,
315,
636,
5351,
363,
1930,
31,
339,
340,
1676,
63,
515,
365,
440,
488,
26,
267,
366,
275,
4668
] |
[
747,
199,
646,
295,
199,
646,
984,
199,
646,
1742,
199,
646,
1331,
199,
646,
5739,
199,
646,
19840,
199,
646,
5549,
199,
646,
3873,
199,
646,
5145,
199,
199,
504,
7065,
14,
2550,
492,
12577,
547,
199,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
504,
2680,
14,
13350,
14,
5819,
492,
664,
63,
1971,
199,
199,
363,
452,
363,
275,
788,
5688,
297,
283,
362,
63,
4714,
63,
2613,
63,
3220,
297,
283,
885,
63,
888,
63,
807,
297,
1779,
283,
807,
63,
740,
297,
283,
740,
515,
297,
283,
4208,
63,
888,
63,
647,
297,
1779,
283,
362,
63,
1760,
297,
283,
452,
515,
297,
283,
362,
63,
3442,
8450,
297,
1779,
283,
12010,
63,
1989,
63,
7120,
297,
283,
581,
63,
505,
297,
283,
7731,
63,
505,
297,
283,
14514,
63,
505,
297,
1779,
283,
6304,
63,
505,
297,
283,
28291,
63,
505,
297,
283,
15076,
18,
2676,
708,
1673,
14566,
87,
708,
1673,
452,
63,
5465,
297,
1779,
283,
1989,
63,
70,
63,
4553,
297,
283,
1989,
63,
9634,
63,
4553,
297,
283,
1541,
63,
4553,
297,
1779,
283,
362,
63,
5714,
297,
283,
374,
63,
1832,
63,
2164,
63,
694,
297,
283,
362,
63,
832,
63,
1365,
63,
1725,
297,
1779,
283,
362,
63,
1579,
63,
1725,
297,
283,
362,
63,
773,
63,
1365,
63,
1725,
297,
283,
362,
63,
576,
63,
1725,
297,
1779,
283,
3287,
63,
904,
297,
283,
362,
63,
1943,
297,
283,
827,
12405,
1673,
78,
904,
297,
1779,
283,
374,
63,
4041,
297,
283,
374,
63,
875,
297,
283,
305,
63,
513,
297,
283,
71,
3771,
297,
283,
362,
63,
3671,
297,
1779,
283,
3513,
63,
589,
297,
283,
362,
63,
1506,
63,
19134,
297,
283,
362,
63,
815,
297,
283,
362,
63,
4600,
63,
815,
418,
199,
199,
533,
13276,
461,
4728,
26,
272,
408,
272,
15395,
370,
10266,
2556,
641,
376,
3907,
461,
3555,
14,
339,
3897,
272,
4143,
272,
536,
520,
620,
267,
2812,
402,
314,
4903,
3555,
14,
272,
1900,
63,
815,
520,
1211,
267,
11932,
17573,
1900,
2556,
14,
272,
1347,
63,
694,
520,
620,
267,
24964,
931,
9176,
2382,
370,
3907,
314,
3555,
14,
339,
1666,
6121,
272,
3001,
272,
11595,
14,
525,
63,
7657,
63,
4342,
339,
8144,
272,
9063,
272,
710,
7795,
2633,
787,
5489,
465,
3004,
543,
314,
2011,
1561,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1900,
63,
815,
12,
1347,
63,
694,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
1506,
63,
815,
275,
1900,
63,
815,
267,
291,
14,
1375,
63,
694,
275,
1347,
63,
694,
199,
199,
318,
6313,
63,
589,
8,
589,
304,
272,
327,
2793,
1133,
1202,
485,
343,
63,
3513,
63,
589,
465,
652,
1630,
440,
1104,
340,
272,
327,
1249,
2974,
2575,
1172,
9344,
503,
440,
14,
272,
1249,
275,
769,
8,
589,
9,
272,
367,
284,
315,
1425,
8,
552,
8,
589,
2298,
267,
282,
275,
1249,
59,
73,
61,
267,
340,
283,
283,
315,
282,
436,
282,
59,
16,
61,
440,
315,
283,
3212,
7,
356,
288,
1249,
59,
73,
61,
275,
18253,
83,
4507,
450,
334,
65,
9,
272,
372,
1249,
199,
199,
318,
1006,
515,
8,
354,
304,
272,
298,
7306,
282,
1182,
13,
12794,
11776,
370,
1373,
1808,
314,
4403,
1159,
931,
9432,
2122,
272,
30183,
275,
536,
14,
1294,
7825,
272,
372,
747,
14,
515,
14,
904,
2031,
1294,
471,
9,
199,
199,
318,
4668,
63,
515,
8,
515,
12,
1676,
63,
515,
304,
272,
408,
1767,
931,
3847,
370,
1676,
63,
515,
14,
272,
408,
272,
6454,
275,
747,
14,
515,
14,
4832,
8,
1708,
63,
515,
9,
272,
282,
515,
275,
747,
14,
515,
14,
4832,
8,
515,
9,
272,
340,
822,
8,
65,
515,
21528,
552,
8,
8961,
304,
267,
372,
931,
272,
340,
282,
515,
389,
8961,
26,
267,
372,
2125,
272,
340,
6454,
508,
282,
515,
1491,
552,
8,
8961,
19532,
267,
702,
282,
515,
59,
552,
8,
8961,
1874,
315,
359,
736,
14,
4127,
467,
2722,
1332,
515,
12,
65,
515,
59,
552,
8,
8961,
19563,
267,
931,
275,
282,
515,
59,
552,
8,
8961,
6393,
17,
2938,
272,
372,
931,
199,
199,
318,
664,
63,
515,
63,
504,
63,
1943,
8,
1943,
12,
1676,
63,
515,
29,
403,
304,
272,
408,
1767,
931,
402,
314,
859,
1627,
282,
2787,
909,
687,
314,
1240,
3464,
14,
339,
19907,
931,
365,
3847,
370,
1676,
63,
515,
1380,
1627,
12,
272,
4257,
652,
365,
3679,
931,
14,
272,
408,
339,
327,
7758,
12,
862,
370,
2342,
340,
314,
570,
536,
365,
315,
314,
2787,
14,
272,
862,
26,
267,
8025,
63,
493,
275,
3468,
10714,
493,
7500,
2787,
14,
70,
63,
8473,
12,
2787,
14,
70,
63,
9350,
9,
267,
366,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
11219,
63,
493,
430,
272,
871,
12746,
26,
267,
327,
636,
493,
363,
365,
440,
3247,
12,
880,
4691,
1159,
862,
636,
354,
4343,
2136,
862,
642,
3499,
267,
327,
2952,
9116,
25664,
14105,
636,
354,
363,
370,
506,
2560,
973,
12217,
2755,
10617,
267,
327,
984,
14,
3112,
13742,
973,
17501,
5594,
506,
6020,
587,
12,
2839,
8837,
63,
3174,
8,
17,
680,
267,
8025,
63,
354,
275,
3468,
10714,
354,
7500,
2787,
14,
70,
63,
8473,
12,
2787,
14,
70,
63,
9350,
9,
267,
636,
646,
721,
11219,
63,
354,
9,
267,
3413,
275,
984,
14,
3112,
59,
11219,
63,
354,
61,
267,
340,
2688,
8,
1494,
12,
2560,
493,
12168,
288,
366,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
8,
1494,
855,
493,
8964,
267,
587,
26,
288,
327,
781,
3984,
8646,
3879,
3272,
14,
647,
465,
22711,
480,
2758,
14,
647,
531,
288,
327,
334,
24227,
781,
3984,
10015,
376,
11393,
9,
288,
366,
275,
747,
14,
515,
14,
4832,
7563,
288,
327,
394,
596,
12,
1077,
781,
675,
984,
14,
3020,
59,
16,
61,
2839,
315,
636,
5351,
363,
1930,
31,
339,
340,
1676,
63,
515,
365,
440,
488,
26,
267,
366,
275,
4668,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ales-erjavec/orange-canvas
|
orangecanvas/scheme/tests/__init__.py
|
1
|
2700
|
"""
Scheme tests
"""
from AnyQt.QtCore import QObject, QEventLoop, QTimer, QCoreApplication, QEvent
from typing import List
class EventSpy(QObject):
"""
A testing utility class (similar to QSignalSpy) to record events
delivered to a QObject instance.
Note
----
Only event types can be recorded (as QEvent instances are deleted
on delivery).
Note
----
Can only be used with a QCoreApplication running.
Parameters
----------
object : QObject
An object whose events need to be recorded.
etype : Union[QEvent.Type, Sequence[QEvent.Type]
A event type (or types) that should be recorded
"""
def __init__(self, object: QObject, etype, **kwargs):
super().__init__(**kwargs)
if not isinstance(object, QObject):
raise TypeError
self.__object = object
try:
len(etype)
except TypeError:
etypes = {etype}
else:
etypes = set(etype)
self.__etypes = etypes
self.__record = []
self.__loop = QEventLoop()
self.__timer = QTimer(self, singleShot=True)
self.__timer.timeout.connect(self.__loop.quit)
self.__object.installEventFilter(self)
def wait(self, timeout=5000):
"""
Start an event loop that runs until a spied event or a timeout occurred.
Parameters
----------
timeout : int
Timeout in milliseconds.
Returns
-------
res : bool
True if the event occurred and False otherwise.
Example
-------
>>> app = QCoreApplication.instance() or QCoreApplication([])
>>> obj = QObject()
>>> spy = EventSpy(obj, QEvent.User)
>>> app.postEvent(obj, QEvent(QEvent.User))
>>> spy.wait()
True
>>> print(spy.events())
[1000]
"""
count = len(self.__record)
self.__timer.stop()
self.__timer.setInterval(timeout)
self.__timer.start()
self.__loop.exec_()
self.__timer.stop()
return len(self.__record) != count
def eventFilter(self, reciever: QObject, event: QEvent) -> bool:
if reciever is self.__object and event.type() in self.__etypes:
self.__record.append(event.type())
if self.__loop.isRunning():
self.__loop.quit()
return super().eventFilter(reciever, event)
def events(self) -> List[QEvent.Type]:
"""
Return a list of all (listened to) event types that occurred.
Returns
-------
events : List[QEvent.Type]
"""
return list(self.__record)
|
gpl-3.0
|
[
624,
199,
19530,
2295,
199,
624,
199,
504,
6184,
4238,
14,
10901,
492,
1413,
1692,
12,
1413,
2390,
7382,
12,
1413,
7929,
12,
1413,
29263,
12,
1413,
2390,
199,
504,
14090,
492,
3820,
421,
199,
533,
6763,
51,
647,
8,
32260,
304,
272,
408,
272,
437,
5343,
11420,
1021,
334,
23079,
370,
1413,
11274,
51,
647,
9,
370,
2777,
4474,
272,
28218,
370,
282,
1413,
1692,
1256,
14,
339,
3390,
272,
4099,
272,
5972,
1566,
2943,
883,
506,
18894,
334,
305,
1413,
2390,
4454,
787,
5463,
272,
641,
18719,
680,
339,
3390,
272,
4099,
272,
6855,
1454,
506,
1202,
543,
282,
1413,
29263,
3879,
14,
339,
3897,
272,
4143,
272,
909,
520,
1413,
1692,
267,
1626,
909,
7447,
4474,
1929,
370,
506,
18894,
14,
272,
30527,
520,
15961,
59,
49,
2390,
14,
804,
12,
10975,
59,
49,
2390,
14,
804,
61,
267,
437,
1566,
730,
334,
269,
2943,
9,
626,
1077,
506,
18894,
272,
408,
272,
347,
636,
826,
721,
277,
12,
909,
26,
1413,
1692,
12,
30527,
12,
1011,
958,
304,
267,
1613,
11027,
826,
14155,
958,
9,
267,
340,
440,
1228,
8,
785,
12,
1413,
1692,
304,
288,
746,
3146,
398,
291,
855,
785,
275,
909,
267,
862,
26,
288,
822,
8,
29232,
9,
267,
871,
3146,
26,
288,
325,
1313,
275,
469,
29232,
93,
267,
587,
26,
288,
325,
1313,
275,
663,
8,
29232,
9,
398,
291,
855,
69,
1313,
275,
325,
1313,
267,
291,
855,
3059,
275,
942,
267,
291,
855,
3813,
275,
1413,
2390,
7382,
342,
267,
291,
855,
7414,
275,
1413,
7929,
8,
277,
12,
2849,
2662,
357,
29,
549,
9,
267,
291,
855,
7414,
14,
2593,
14,
2242,
8,
277,
855,
3813,
14,
10589,
9,
267,
291,
855,
785,
14,
3174,
2390,
4131,
8,
277,
9,
339,
347,
3618,
8,
277,
12,
2653,
29,
13128,
304,
267,
408,
267,
7707,
376,
1566,
4438,
626,
7858,
5133,
282,
19441,
379,
1566,
503,
282,
2653,
8920,
14,
398,
3897,
267,
4143,
267,
2653,
520,
1109,
288,
12878,
315,
21131,
14,
398,
1803,
267,
5514,
267,
522,
520,
2155,
288,
715,
340,
314,
1566,
8920,
436,
756,
4257,
14,
398,
5679,
267,
5514,
267,
1306,
1145,
275,
1413,
29263,
14,
842,
342,
503,
1413,
29263,
4157,
267,
1306,
1559,
275,
1413,
1692,
342,
267,
1306,
308,
647,
275,
6763,
51,
647,
8,
1113,
12,
1413,
2390,
14,
1899,
9,
267,
1306,
1145,
14,
1932,
2390,
8,
1113,
12,
1413,
2390,
8,
49,
2390,
14,
1899,
430,
267,
1306,
308,
647,
14,
2573,
342,
267,
715,
267,
1306,
870,
8,
15252,
14,
4368,
1012,
267,
359,
5279,
61,
267,
408,
267,
2338,
275,
822,
8,
277,
855,
3059,
9,
267,
291,
855,
7414,
14,
2379,
342,
267,
291,
855,
7414,
14,
409,
8227,
8,
2593,
9,
267,
291,
855,
7414,
14,
928,
342,
267,
291,
855,
3813,
14,
1628,
12798,
267,
291,
855,
7414,
14,
2379,
342,
267,
372,
822,
8,
277,
855,
3059,
9,
1137,
2338,
339,
347,
1566,
4131,
8,
277,
12,
295,
559,
5907,
26,
1413,
1692,
12,
1566,
26,
1413,
2390,
9,
1035,
2155,
26,
267,
340,
295,
559,
5907,
365,
291,
855,
785,
436,
1566,
14,
466,
342,
315,
291,
855,
69,
1313,
26,
288,
291,
855,
3059,
14,
740,
8,
1430,
14,
466,
1012,
288,
340,
291,
855,
3813,
14,
374,
9602,
837,
355,
291,
855,
3813,
14,
10589,
342,
267,
372,
1613,
1252,
1430,
4131,
8,
264,
559,
5907,
12,
1566,
9,
339,
347,
4474,
8,
277,
9,
1035,
3820,
59,
49,
2390,
14,
804,
2189,
267,
408,
267,
1432,
282,
769,
402,
1006,
334,
5859,
379,
370,
9,
1566,
2943,
626,
8920,
14,
398,
1803,
267,
5514,
267,
4474,
520,
3820,
59,
49,
2390,
14,
804,
61,
267,
408,
267,
372,
769,
8,
277,
855,
3059,
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
] |
[
199,
19530,
2295,
199,
624,
199,
504,
6184,
4238,
14,
10901,
492,
1413,
1692,
12,
1413,
2390,
7382,
12,
1413,
7929,
12,
1413,
29263,
12,
1413,
2390,
199,
504,
14090,
492,
3820,
421,
199,
533,
6763,
51,
647,
8,
32260,
304,
272,
408,
272,
437,
5343,
11420,
1021,
334,
23079,
370,
1413,
11274,
51,
647,
9,
370,
2777,
4474,
272,
28218,
370,
282,
1413,
1692,
1256,
14,
339,
3390,
272,
4099,
272,
5972,
1566,
2943,
883,
506,
18894,
334,
305,
1413,
2390,
4454,
787,
5463,
272,
641,
18719,
680,
339,
3390,
272,
4099,
272,
6855,
1454,
506,
1202,
543,
282,
1413,
29263,
3879,
14,
339,
3897,
272,
4143,
272,
909,
520,
1413,
1692,
267,
1626,
909,
7447,
4474,
1929,
370,
506,
18894,
14,
272,
30527,
520,
15961,
59,
49,
2390,
14,
804,
12,
10975,
59,
49,
2390,
14,
804,
61,
267,
437,
1566,
730,
334,
269,
2943,
9,
626,
1077,
506,
18894,
272,
408,
272,
347,
636,
826,
721,
277,
12,
909,
26,
1413,
1692,
12,
30527,
12,
1011,
958,
304,
267,
1613,
11027,
826,
14155,
958,
9,
267,
340,
440,
1228,
8,
785,
12,
1413,
1692,
304,
288,
746,
3146,
398,
291,
855,
785,
275,
909,
267,
862,
26,
288,
822,
8,
29232,
9,
267,
871,
3146,
26,
288,
325,
1313,
275,
469,
29232,
93,
267,
587,
26,
288,
325,
1313,
275,
663,
8,
29232,
9,
398,
291,
855,
69,
1313,
275,
325,
1313,
267,
291,
855,
3059,
275,
942,
267,
291,
855,
3813,
275,
1413,
2390,
7382,
342,
267,
291,
855,
7414,
275,
1413,
7929,
8,
277,
12,
2849,
2662,
357,
29,
549,
9,
267,
291,
855,
7414,
14,
2593,
14,
2242,
8,
277,
855,
3813,
14,
10589,
9,
267,
291,
855,
785,
14,
3174,
2390,
4131,
8,
277,
9,
339,
347,
3618,
8,
277,
12,
2653,
29,
13128,
304,
267,
408,
267,
7707,
376,
1566,
4438,
626,
7858,
5133,
282,
19441,
379,
1566,
503,
282,
2653,
8920,
14,
398,
3897,
267,
4143,
267,
2653,
520,
1109,
288,
12878,
315,
21131,
14,
398,
1803,
267,
5514,
267,
522,
520,
2155,
288,
715,
340,
314,
1566,
8920,
436,
756,
4257,
14,
398,
5679,
267,
5514,
267,
1306,
1145,
275,
1413,
29263,
14,
842,
342,
503,
1413,
29263,
4157,
267,
1306,
1559,
275,
1413,
1692,
342,
267,
1306,
308,
647,
275,
6763,
51,
647,
8,
1113,
12,
1413,
2390,
14,
1899,
9,
267,
1306,
1145,
14,
1932,
2390,
8,
1113,
12,
1413,
2390,
8,
49,
2390,
14,
1899,
430,
267,
1306,
308,
647,
14,
2573,
342,
267,
715,
267,
1306,
870,
8,
15252,
14,
4368,
1012,
267,
359,
5279,
61,
267,
408,
267,
2338,
275,
822,
8,
277,
855,
3059,
9,
267,
291,
855,
7414,
14,
2379,
342,
267,
291,
855,
7414,
14,
409,
8227,
8,
2593,
9,
267,
291,
855,
7414,
14,
928,
342,
267,
291,
855,
3813,
14,
1628,
12798,
267,
291,
855,
7414,
14,
2379,
342,
267,
372,
822,
8,
277,
855,
3059,
9,
1137,
2338,
339,
347,
1566,
4131,
8,
277,
12,
295,
559,
5907,
26,
1413,
1692,
12,
1566,
26,
1413,
2390,
9,
1035,
2155,
26,
267,
340,
295,
559,
5907,
365,
291,
855,
785,
436,
1566,
14,
466,
342,
315,
291,
855,
69,
1313,
26,
288,
291,
855,
3059,
14,
740,
8,
1430,
14,
466,
1012,
288,
340,
291,
855,
3813,
14,
374,
9602,
837,
355,
291,
855,
3813,
14,
10589,
342,
267,
372,
1613,
1252,
1430,
4131,
8,
264,
559,
5907,
12,
1566,
9,
339,
347,
4474,
8,
277,
9,
1035,
3820,
59,
49,
2390,
14,
804,
2189,
267,
408,
267,
1432,
282,
769,
402,
1006,
334,
5859,
379,
370,
9,
1566,
2943,
626,
8920,
14,
398,
1803,
267,
5514,
267,
4474,
520,
3820,
59,
49,
2390,
14,
804,
61,
267,
408,
267,
372,
769,
8,
277,
855,
3059,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mcella/django
|
django/db/migrations/graph.py
|
351
|
10956
|
from __future__ import unicode_literals
import warnings
from collections import deque
from functools import total_ordering
from django.db.migrations.state import ProjectState
from django.utils.datastructures import OrderedSet
from django.utils.encoding import python_2_unicode_compatible
from .exceptions import CircularDependencyError, NodeNotFoundError
RECURSION_DEPTH_WARNING = (
"Maximum recursion depth exceeded while generating migration graph, "
"falling back to iterative approach. If you're experiencing performance issues, "
"consider squashing migrations as described at "
"https://docs.djangoproject.com/en/dev/topics/migrations/#squashing-migrations."
)
@python_2_unicode_compatible
@total_ordering
class Node(object):
"""
A single node in the migration graph. Contains direct links to adjacent
nodes in either direction.
"""
def __init__(self, key):
self.key = key
self.children = set()
self.parents = set()
def __eq__(self, other):
return self.key == other
def __lt__(self, other):
return self.key < other
def __hash__(self):
return hash(self.key)
def __getitem__(self, item):
return self.key[item]
def __str__(self):
return str(self.key)
def __repr__(self):
return '<Node: (%r, %r)>' % self.key
def add_child(self, child):
self.children.add(child)
def add_parent(self, parent):
self.parents.add(parent)
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
def ancestors(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_ancestors' not in self.__dict__:
ancestors = deque([self.key])
for parent in sorted(self.parents):
ancestors.extendleft(reversed(parent.ancestors()))
self.__dict__['_ancestors'] = list(OrderedSet(ancestors))
return self.__dict__['_ancestors']
# Use manual caching, @cached_property effectively doubles the
# recursion depth for each recursion.
def descendants(self):
# Use self.key instead of self to speed up the frequent hashing
# when constructing an OrderedSet.
if '_descendants' not in self.__dict__:
descendants = deque([self.key])
for child in sorted(self.children):
descendants.extendleft(reversed(child.descendants()))
self.__dict__['_descendants'] = list(OrderedSet(descendants))
return self.__dict__['_descendants']
@python_2_unicode_compatible
class MigrationGraph(object):
"""
Represents the digraph of all migrations in a project.
Each migration is a node, and each dependency is an edge. There are
no implicit dependencies between numbered migrations - the numbering is
merely a convention to aid file listing. Every new numbered migration
has a declared dependency to the previous number, meaning that VCS
branch merges can be detected and resolved.
Migrations files can be marked as replacing another set of migrations -
this is to support the "squash" feature. The graph handler isn't responsible
for these; instead, the code to load them in here should examine the
migration files and if the replaced migrations are all either unapplied
or not present, it should ignore the replaced ones, load in just the
replacing migration, and repoint any dependencies that pointed to the
replaced migrations to point to the replacing one.
A node should be a tuple: (app_path, migration_name). The tree special-cases
things within an app - namely, root nodes and leaf nodes ignore dependencies
to other apps.
"""
def __init__(self):
self.node_map = {}
self.nodes = {}
self.cached = False
def add_node(self, key, implementation):
node = Node(key)
self.node_map[key] = node
self.nodes[key] = implementation
self.clear_cache()
def add_dependency(self, migration, child, parent):
if child not in self.nodes:
raise NodeNotFoundError(
"Migration %s dependencies reference nonexistent child node %r" % (migration, child),
child
)
if parent not in self.nodes:
raise NodeNotFoundError(
"Migration %s dependencies reference nonexistent parent node %r" % (migration, parent),
parent
)
self.node_map[child].add_parent(self.node_map[parent])
self.node_map[parent].add_child(self.node_map[child])
self.clear_cache()
def clear_cache(self):
if self.cached:
for node in self.nodes:
self.node_map[node].__dict__.pop('_ancestors', None)
self.node_map[node].__dict__.pop('_descendants', None)
self.cached = False
def forwards_plan(self, target):
"""
Given a node, returns a list of which previous nodes (dependencies)
must be applied, ending with the node itself.
This is the list you would follow if applying the migrations to
a database.
"""
if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use parent.key instead of parent to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(target, lambda x: (parent.key for parent in self.node_map[x].parents))
self.cached = True
node = self.node_map[target]
try:
return node.ancestors()
except RuntimeError:
# fallback to iterative dfs
warnings.warn(RECURSION_DEPTH_WARNING, RuntimeWarning)
return self.iterative_dfs(node)
def backwards_plan(self, target):
"""
Given a node, returns a list of which dependent nodes (dependencies)
must be unapplied, ending with the node itself.
This is the list you would follow if removing the migrations from
a database.
"""
if target not in self.nodes:
raise NodeNotFoundError("Node %r not a valid node" % (target, ), target)
# Use child.key instead of child to speed up the frequent hashing in ensure_not_cyclic
self.ensure_not_cyclic(target, lambda x: (child.key for child in self.node_map[x].children))
self.cached = True
node = self.node_map[target]
try:
return node.descendants()
except RuntimeError:
# fallback to iterative dfs
warnings.warn(RECURSION_DEPTH_WARNING, RuntimeWarning)
return self.iterative_dfs(node, forwards=False)
def iterative_dfs(self, start, forwards=True):
"""
Iterative depth first search, for finding dependencies.
"""
visited = deque()
visited.append(start)
if forwards:
stack = deque(sorted(start.parents))
else:
stack = deque(sorted(start.children))
while stack:
node = stack.popleft()
visited.appendleft(node)
if forwards:
children = sorted(node.parents, reverse=True)
else:
children = sorted(node.children, reverse=True)
# reverse sorting is needed because prepending using deque.extendleft
# also effectively reverses values
stack.extendleft(children)
return list(OrderedSet(visited))
def root_nodes(self, app=None):
"""
Returns all root nodes - that is, nodes with no dependencies inside
their app. These are the starting point for an app.
"""
roots = set()
for node in self.nodes:
if (not any(key[0] == node[0] for key in self.node_map[node].parents)
and (not app or app == node[0])):
roots.add(node)
return sorted(roots)
def leaf_nodes(self, app=None):
"""
Returns all leaf nodes - that is, nodes with no dependents in their app.
These are the "most current" version of an app's schema.
Having more than one per app is technically an error, but one that
gets handled further up, in the interactive command - it's usually the
result of a VCS merge and needs some user input.
"""
leaves = set()
for node in self.nodes:
if (not any(key[0] == node[0] for key in self.node_map[node].children)
and (not app or app == node[0])):
leaves.add(node)
return sorted(leaves)
def ensure_not_cyclic(self, start, get_children):
# Algo from GvR:
# http://neopythonic.blogspot.co.uk/2009/01/detecting-cycles-in-directed-graph.html
todo = set(self.nodes)
while todo:
node = todo.pop()
stack = [node]
while stack:
top = stack[-1]
for node in get_children(top):
if node in stack:
cycle = stack[stack.index(node):]
raise CircularDependencyError(", ".join("%s.%s" % n for n in cycle))
if node in todo:
stack.append(node)
todo.remove(node)
break
else:
node = stack.pop()
def __str__(self):
return 'Graph: %s nodes, %s edges' % self._nodes_and_edges()
def __repr__(self):
nodes, edges = self._nodes_and_edges()
return '<%s: nodes=%s, edges=%s>' % (self.__class__.__name__, nodes, edges)
def _nodes_and_edges(self):
return len(self.nodes), sum(len(node.parents) for node in self.node_map.values())
def make_state(self, nodes=None, at_end=True, real_apps=None):
"""
Given a migration node or nodes, returns a complete ProjectState for it.
If at_end is False, returns the state before the migration has run.
If nodes is not provided, returns the overall most current project state.
"""
if nodes is None:
nodes = list(self.leaf_nodes())
if len(nodes) == 0:
return ProjectState()
if not isinstance(nodes[0], tuple):
nodes = [nodes]
plan = []
for node in nodes:
for migration in self.forwards_plan(node):
if migration not in plan:
if not at_end and migration in nodes:
continue
plan.append(migration)
project_state = ProjectState(real_apps=real_apps)
for node in plan:
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
return project_state
def __contains__(self, node):
return node in self.nodes
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
9143,
492,
3141,
63,
7128,
199,
199,
504,
1639,
14,
697,
14,
7685,
14,
929,
492,
7290,
2223,
199,
504,
1639,
14,
1208,
14,
23004,
492,
23617,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
504,
1275,
3924,
492,
445,
24998,
14403,
547,
12,
5013,
10870,
199,
199,
907,
7013,
3579,
63,
19715,
63,
9171,
275,
334,
272,
298,
10915,
16189,
5818,
22007,
1830,
12999,
8367,
3343,
12,
298,
272,
298,
70,
26039,
1771,
370,
4826,
857,
18140,
14,
982,
1265,
3984,
444,
5490,
287,
4477,
10238,
10876,
12,
298,
272,
298,
388,
16994,
12345,
1119,
316,
6180,
465,
11736,
737,
298,
272,
298,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
7685,
12645,
8471,
1119,
316,
13,
7685,
2122,
199,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
32,
2923,
63,
7128,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
1031,
315,
314,
8367,
3343,
14,
22493,
4125,
6220,
370,
24113,
272,
3380,
315,
1902,
7581,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
3223,
275,
663,
342,
267,
291,
14,
8859,
275,
663,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
508,
1163,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
665,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
498,
59,
1053,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
498,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
1716,
26,
4366,
82,
12,
450,
82,
9,
3524,
450,
291,
14,
498,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
291,
14,
3223,
14,
525,
8,
1739,
9,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
291,
14,
8859,
14,
525,
8,
1708,
9,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
20158,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
23732,
7,
440,
315,
291,
855,
807,
10651,
288,
20158,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1676,
315,
3355,
8,
277,
14,
8859,
304,
355,
20158,
14,
2880,
3039,
8,
13501,
8,
1708,
14,
23732,
4059,
288,
291,
855,
807,
363,
8680,
23732,
418,
275,
769,
8,
22567,
1084,
8,
23732,
430,
267,
372,
291,
855,
807,
363,
8680,
23732,
418,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
26061,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
29041,
7,
440,
315,
291,
855,
807,
10651,
288,
26061,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1982,
315,
3355,
8,
277,
14,
3223,
304,
355,
26061,
14,
2880,
3039,
8,
13501,
8,
1739,
14,
29041,
4059,
288,
291,
855,
807,
363,
8680,
29041,
418,
275,
769,
8,
22567,
1084,
8,
29041,
430,
267,
372,
291,
855,
807,
363,
8680,
29041,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12090,
4578,
8,
785,
304,
272,
408,
272,
21591,
314,
487,
2180,
402,
1006,
6180,
315,
282,
2199,
14,
339,
7048,
8367,
365,
282,
1031,
12,
436,
1924,
5936,
365,
376,
6275,
14,
6006,
787,
272,
949,
9227,
5124,
3382,
1967,
18897,
6180,
446,
314,
1329,
316,
365,
272,
562,
264,
590,
282,
16129,
370,
23939,
570,
13778,
14,
18414,
892,
1967,
18897,
8367,
272,
965,
282,
14290,
5936,
370,
314,
4136,
1329,
12,
11150,
626,
23563,
272,
5246,
32716,
883,
506,
10501,
436,
12152,
14,
339,
28195,
3801,
1584,
883,
506,
11584,
465,
15810,
4573,
663,
402,
6180,
446,
272,
642,
365,
370,
2291,
314,
298,
8471,
1119,
2,
3878,
14,
710,
3343,
3016,
5712,
1133,
17845,
272,
367,
3520,
27,
3140,
12,
314,
1233,
370,
2248,
3062,
315,
2348,
1077,
31758,
314,
272,
8367,
1584,
436,
340,
314,
8717,
6180,
787,
1006,
1902,
625,
17250,
272,
503,
440,
3451,
12,
652,
1077,
3686,
314,
8717,
7869,
12,
2248,
315,
2951,
314,
272,
15810,
8367,
12,
436,
295,
1403,
1263,
5124,
626,
32031,
370,
314,
272,
8717,
6180,
370,
2376,
370,
314,
15810,
1373,
14,
339,
437,
1031,
1077,
506,
282,
2008,
26,
334,
571,
63,
515,
12,
8367,
63,
354,
680,
710,
3123,
4539,
13,
9403,
272,
7645,
4453,
376,
1145,
446,
536,
590,
12,
1738,
3380,
436,
11747,
3380,
3686,
5124,
272,
370,
1163,
8686,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
932,
63,
1130,
275,
1052,
267,
291,
14,
2415,
275,
1052,
267,
291,
14,
5245,
275,
756,
339,
347,
1050,
63,
932,
8,
277,
12,
790,
12,
4514,
304,
267,
1031,
275,
5013,
8,
498,
9,
267,
291,
14,
932,
63,
1130,
59,
498,
61,
275,
1031,
267,
291,
14,
2415,
59,
498,
61,
275,
4514,
267,
291,
14,
3584,
63,
1637,
342,
339,
347,
1050,
63,
8575,
8,
277,
12,
8367,
12,
1982,
12,
1676,
304,
267,
340,
1982,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1982,
1031,
450,
82,
2,
450,
334,
8998,
12,
1982,
395,
355,
1982,
288,
776,
267,
340,
1676,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1676,
1031,
450,
82,
2,
450,
334,
8998,
12,
1676,
395,
355,
1676,
288,
776,
267,
291,
14,
932,
63,
1130,
59,
1739,
1055,
525,
63,
1708,
8,
277
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
3598,
199,
504,
5055,
492,
15782,
199,
504,
9143,
492,
3141,
63,
7128,
199,
199,
504,
1639,
14,
697,
14,
7685,
14,
929,
492,
7290,
2223,
199,
504,
1639,
14,
1208,
14,
23004,
492,
23617,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
199,
199,
504,
1275,
3924,
492,
445,
24998,
14403,
547,
12,
5013,
10870,
199,
199,
907,
7013,
3579,
63,
19715,
63,
9171,
275,
334,
272,
298,
10915,
16189,
5818,
22007,
1830,
12999,
8367,
3343,
12,
298,
272,
298,
70,
26039,
1771,
370,
4826,
857,
18140,
14,
982,
1265,
3984,
444,
5490,
287,
4477,
10238,
10876,
12,
298,
272,
298,
388,
16994,
12345,
1119,
316,
6180,
465,
11736,
737,
298,
272,
298,
2859,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
11299,
15,
7685,
12645,
8471,
1119,
316,
13,
7685,
2122,
199,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
32,
2923,
63,
7128,
199,
533,
5013,
8,
785,
304,
272,
408,
272,
437,
2849,
1031,
315,
314,
8367,
3343,
14,
22493,
4125,
6220,
370,
24113,
272,
3380,
315,
1902,
7581,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
790,
304,
267,
291,
14,
498,
275,
790,
267,
291,
14,
3223,
275,
663,
342,
267,
291,
14,
8859,
275,
663,
342,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
508,
1163,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
498,
665,
1163,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
498,
9,
339,
347,
636,
6095,
721,
277,
12,
1242,
304,
267,
372,
291,
14,
498,
59,
1053,
61,
339,
347,
636,
495,
721,
277,
304,
267,
372,
620,
8,
277,
14,
498,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
2650,
1716,
26,
4366,
82,
12,
450,
82,
9,
3524,
450,
291,
14,
498,
339,
347,
1050,
63,
1739,
8,
277,
12,
1982,
304,
267,
291,
14,
3223,
14,
525,
8,
1739,
9,
339,
347,
1050,
63,
1708,
8,
277,
12,
1676,
304,
267,
291,
14,
8859,
14,
525,
8,
1708,
9,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
20158,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
23732,
7,
440,
315,
291,
855,
807,
10651,
288,
20158,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1676,
315,
3355,
8,
277,
14,
8859,
304,
355,
20158,
14,
2880,
3039,
8,
13501,
8,
1708,
14,
23732,
4059,
288,
291,
855,
807,
363,
8680,
23732,
418,
275,
769,
8,
22567,
1084,
8,
23732,
430,
267,
372,
291,
855,
807,
363,
8680,
23732,
418,
339,
327,
3645,
8722,
13627,
12,
768,
5245,
63,
1829,
27881,
4270,
83,
314,
272,
327,
16189,
5818,
367,
1924,
16189,
14,
272,
347,
26061,
8,
277,
304,
267,
327,
3645,
291,
14,
498,
3140,
402,
291,
370,
8112,
1536,
314,
28914,
25223,
267,
327,
1380,
22048,
376,
23617,
14,
267,
340,
2513,
29041,
7,
440,
315,
291,
855,
807,
10651,
288,
26061,
275,
15782,
779,
277,
14,
498,
566,
288,
367,
1982,
315,
3355,
8,
277,
14,
3223,
304,
355,
26061,
14,
2880,
3039,
8,
13501,
8,
1739,
14,
29041,
4059,
288,
291,
855,
807,
363,
8680,
29041,
418,
275,
769,
8,
22567,
1084,
8,
29041,
430,
267,
372,
291,
855,
807,
363,
8680,
29041,
418,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
12090,
4578,
8,
785,
304,
272,
408,
272,
21591,
314,
487,
2180,
402,
1006,
6180,
315,
282,
2199,
14,
339,
7048,
8367,
365,
282,
1031,
12,
436,
1924,
5936,
365,
376,
6275,
14,
6006,
787,
272,
949,
9227,
5124,
3382,
1967,
18897,
6180,
446,
314,
1329,
316,
365,
272,
562,
264,
590,
282,
16129,
370,
23939,
570,
13778,
14,
18414,
892,
1967,
18897,
8367,
272,
965,
282,
14290,
5936,
370,
314,
4136,
1329,
12,
11150,
626,
23563,
272,
5246,
32716,
883,
506,
10501,
436,
12152,
14,
339,
28195,
3801,
1584,
883,
506,
11584,
465,
15810,
4573,
663,
402,
6180,
446,
272,
642,
365,
370,
2291,
314,
298,
8471,
1119,
2,
3878,
14,
710,
3343,
3016,
5712,
1133,
17845,
272,
367,
3520,
27,
3140,
12,
314,
1233,
370,
2248,
3062,
315,
2348,
1077,
31758,
314,
272,
8367,
1584,
436,
340,
314,
8717,
6180,
787,
1006,
1902,
625,
17250,
272,
503,
440,
3451,
12,
652,
1077,
3686,
314,
8717,
7869,
12,
2248,
315,
2951,
314,
272,
15810,
8367,
12,
436,
295,
1403,
1263,
5124,
626,
32031,
370,
314,
272,
8717,
6180,
370,
2376,
370,
314,
15810,
1373,
14,
339,
437,
1031,
1077,
506,
282,
2008,
26,
334,
571,
63,
515,
12,
8367,
63,
354,
680,
710,
3123,
4539,
13,
9403,
272,
7645,
4453,
376,
1145,
446,
536,
590,
12,
1738,
3380,
436,
11747,
3380,
3686,
5124,
272,
370,
1163,
8686,
14,
272,
408,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
932,
63,
1130,
275,
1052,
267,
291,
14,
2415,
275,
1052,
267,
291,
14,
5245,
275,
756,
339,
347,
1050,
63,
932,
8,
277,
12,
790,
12,
4514,
304,
267,
1031,
275,
5013,
8,
498,
9,
267,
291,
14,
932,
63,
1130,
59,
498,
61,
275,
1031,
267,
291,
14,
2415,
59,
498,
61,
275,
4514,
267,
291,
14,
3584,
63,
1637,
342,
339,
347,
1050,
63,
8575,
8,
277,
12,
8367,
12,
1982,
12,
1676,
304,
267,
340,
1982,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1982,
1031,
450,
82,
2,
450,
334,
8998,
12,
1982,
395,
355,
1982,
288,
776,
267,
340,
1676,
440,
315,
291,
14,
2415,
26,
288,
746,
5013,
10870,
8,
355,
298,
9816,
450,
83,
5124,
3659,
7179,
16931,
1676,
1031,
450,
82,
2,
450,
334,
8998,
12,
1676,
395,
355,
1676,
288,
776,
267,
291,
14,
932,
63,
1130,
59,
1739,
1055,
525,
63,
1708,
8,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
jsteemann/arangodb
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/sqlite3/dbapi2.py
|
161
|
2615
|
#-*- coding: ISO-8859-1 -*-
# pysqlite2/dbapi2.py: the DB-API 2.0 interface
#
# Copyright (C) 2004-2005 Gerhard Häring <gh@ghaering.de>
#
# This file is part of pysqlite.
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
import datetime
import time
from _sqlite3 import *
paramstyle = "qmark"
threadsafety = 1
apilevel = "2.0"
Date = datetime.date
Time = datetime.time
Timestamp = datetime.datetime
def DateFromTicks(ticks):
return Date(*time.localtime(ticks)[:3])
def TimeFromTicks(ticks):
return Time(*time.localtime(ticks)[3:6])
def TimestampFromTicks(ticks):
return Timestamp(*time.localtime(ticks)[:6])
version_info = tuple([int(x) for x in version.split(".")])
sqlite_version_info = tuple([int(x) for x in sqlite_version.split(".")])
Binary = buffer
def register_adapters_and_converters():
def adapt_date(val):
return val.isoformat()
def adapt_datetime(val):
return val.isoformat(" ")
def convert_date(val):
return datetime.date(*map(int, val.split("-")))
def convert_timestamp(val):
datepart, timepart = val.split(" ")
year, month, day = map(int, datepart.split("-"))
timepart_full = timepart.split(".")
hours, minutes, seconds = map(int, timepart_full[0].split(":"))
if len(timepart_full) == 2:
microseconds = int(timepart_full[1])
else:
microseconds = 0
val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
return val
register_adapter(datetime.date, adapt_date)
register_adapter(datetime.datetime, adapt_datetime)
register_converter("date", convert_date)
register_converter("timestamp", convert_timestamp)
register_adapters_and_converters()
# Clean up namespace
del(register_adapters_and_converters)
|
apache-2.0
|
[
3,
13,
1837,
2803,
26,
9055,
13,
4830,
13,
17,
1882,
199,
3,
10382,
29498,
18,
15,
22103,
18,
14,
647,
26,
314,
6249,
13,
3735,
499,
14,
16,
3217,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
13,
9397,
22261,
8726,
869,
13733,
5985,
665,
3561,
32,
71,
2411,
15663,
14,
271,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
10382,
29498,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
283,
305,
13,
374,
297,
1928,
1263,
4056,
503,
2478,
199,
3,
3750,
14,
221,
1010,
949,
1566,
911,
314,
11462,
506,
23608,
1212,
461,
367,
1263,
12927,
960,
83,
199,
3,
14554,
1044,
687,
314,
675,
402,
642,
2032,
14,
199,
3,
199,
3,
8779,
365,
10009,
370,
29165,
370,
675,
642,
2032,
367,
1263,
12016,
12,
199,
3,
5893,
2414,
23012,
13103,
12,
436,
370,
17355,
652,
436,
3604,
652,
199,
3,
20673,
7742,
12,
5420,
370,
314,
2569,
24488,
26,
199,
3,
199,
3,
413,
14,
710,
6330,
402,
642,
2032,
1471,
440,
506,
3201,
264,
10317,
27,
1265,
1471,
440,
199,
3,
259,
22498,
626,
1265,
336,
22665,
314,
3379,
2032,
14,
982,
1265,
675,
642,
2032,
199,
3,
259,
315,
282,
3336,
12,
376,
19807,
28609,
4740,
315,
314,
3336,
3794,
3955,
506,
199,
3,
259,
2771,
20940,
972,
1325,
365,
440,
1415,
14,
199,
3,
499,
14,
4580,
3014,
1350,
5459,
1471,
506,
8971,
590,
11584,
465,
4066,
12,
436,
1471,
440,
506,
199,
3,
259,
3201,
264,
10317,
465,
3769,
314,
3379,
2032,
14,
199,
3,
650,
14,
961,
4245,
1443,
440,
506,
4829,
503,
29815,
687,
1263,
1350,
4084,
14,
199,
199,
646,
2197,
199,
646,
900,
199,
199,
504,
485,
10659,
19,
492,
627,
199,
199,
635,
2487,
275,
298,
81,
1657,
2,
199,
199,
2671,
3489,
369,
275,
413,
199,
199,
439,
441,
1090,
275,
298,
18,
14,
16,
2,
199,
199,
2506,
275,
2197,
14,
602,
199,
199,
1366,
275,
2197,
14,
521,
199,
199,
10239,
275,
2197,
14,
2083,
199,
199,
318,
6148,
2532,
26441,
8,
10406,
304,
272,
372,
6148,
2031,
521,
14,
15198,
8,
10406,
18562,
19,
566,
199,
199,
318,
4703,
2532,
26441,
8,
10406,
304,
272,
372,
4703,
2031,
521,
14,
15198,
8,
10406,
2788,
19,
26,
22,
566,
199,
199,
318,
18267,
2532,
26441,
8,
10406,
304,
272,
372,
18267,
2031,
521,
14,
15198,
8,
10406,
18562,
22,
566,
199,
199,
1023,
63,
815,
275,
2008,
779,
442,
8,
88,
9,
367,
671,
315,
1015,
14,
1294,
15857,
566,
199,
10659,
63,
1023,
63,
815,
275,
2008,
779,
442,
8,
88,
9,
367,
671,
315,
11723,
63,
1023,
14,
1294,
15857,
566,
199,
199,
6636,
275,
3335,
199,
199,
318,
2274,
63,
21680,
63,
460,
63,
17911,
837,
272,
347,
19520,
63,
602,
8,
637,
304,
267,
372,
1139,
14,
17070,
342,
339,
347,
19520,
63,
2083,
8,
637,
304,
267,
372,
1139,
14,
17070,
480,
6099,
339,
347,
3957,
63,
602,
8,
637,
304,
267,
372,
2197,
14,
602,
2031,
1130,
8,
442,
12,
1139,
14,
1294,
6096,
13324,
339,
347,
3957,
63,
3954,
8,
637,
304,
267,
1434,
2064,
12,
900,
2064,
275,
1139,
14,
1294,
480,
6099,
267,
5361,
12,
5794,
12,
5382,
275,
2341,
8,
442,
12,
1434,
2064,
14,
1294,
6096,
2237,
267,
900,
2064,
63,
2861,
275,
900,
2064,
14,
1294,
15857,
267,
10857,
12,
9395,
12,
4696,
275,
2341,
8,
442,
12,
900,
2064,
63,
2861,
59,
16,
1055,
1294,
20308,
2237,
267,
340,
822,
8,
521,
2064,
63,
2861,
9,
508,
499,
26,
288,
21574,
275,
1109,
8,
521,
2064,
63,
2861,
59,
17,
566,
267,
587,
26,
288,
21574,
275,
378,
398,
1139,
275,
2197,
14,
2083,
8,
3403,
12,
5794,
12,
5382,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
9,
267,
372,
1139,
2378,
2274,
63,
10394,
8,
2083,
14,
602,
12,
19520,
63,
602,
9,
272,
2274,
63,
10394,
8,
2083,
14,
2083,
12,
19520,
63,
2083,
9,
272,
2274,
63,
11256,
480,
602,
401,
3957,
63,
602,
9,
272,
2274,
63,
11256,
480,
3954,
401,
3957,
63,
3954,
9,
199,
199,
2683,
63,
21680,
63,
460,
63,
17911,
342,
199,
199,
3,
12762,
1536,
3231,
199,
199,
2264,
8,
2683,
63,
21680,
63,
460,
63,
17911,
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
] |
[
13,
1837,
2803,
26,
9055,
13,
4830,
13,
17,
1882,
199,
3,
10382,
29498,
18,
15,
22103,
18,
14,
647,
26,
314,
6249,
13,
3735,
499,
14,
16,
3217,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
13,
9397,
22261,
8726,
869,
13733,
5985,
665,
3561,
32,
71,
2411,
15663,
14,
271,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
10382,
29498,
14,
199,
3,
199,
3,
961,
2032,
365,
2741,
283,
305,
13,
374,
297,
1928,
1263,
4056,
503,
2478,
199,
3,
3750,
14,
221,
1010,
949,
1566,
911,
314,
11462,
506,
23608,
1212,
461,
367,
1263,
12927,
960,
83,
199,
3,
14554,
1044,
687,
314,
675,
402,
642,
2032,
14,
199,
3,
199,
3,
8779,
365,
10009,
370,
29165,
370,
675,
642,
2032,
367,
1263,
12016,
12,
199,
3,
5893,
2414,
23012,
13103,
12,
436,
370,
17355,
652,
436,
3604,
652,
199,
3,
20673,
7742,
12,
5420,
370,
314,
2569,
24488,
26,
199,
3,
199,
3,
413,
14,
710,
6330,
402,
642,
2032,
1471,
440,
506,
3201,
264,
10317,
27,
1265,
1471,
440,
199,
3,
259,
22498,
626,
1265,
336,
22665,
314,
3379,
2032,
14,
982,
1265,
675,
642,
2032,
199,
3,
259,
315,
282,
3336,
12,
376,
19807,
28609,
4740,
315,
314,
3336,
3794,
3955,
506,
199,
3,
259,
2771,
20940,
972,
1325,
365,
440,
1415,
14,
199,
3,
499,
14,
4580,
3014,
1350,
5459,
1471,
506,
8971,
590,
11584,
465,
4066,
12,
436,
1471,
440,
506,
199,
3,
259,
3201,
264,
10317,
465,
3769,
314,
3379,
2032,
14,
199,
3,
650,
14,
961,
4245,
1443,
440,
506,
4829,
503,
29815,
687,
1263,
1350,
4084,
14,
199,
199,
646,
2197,
199,
646,
900,
199,
199,
504,
485,
10659,
19,
492,
627,
199,
199,
635,
2487,
275,
298,
81,
1657,
2,
199,
199,
2671,
3489,
369,
275,
413,
199,
199,
439,
441,
1090,
275,
298,
18,
14,
16,
2,
199,
199,
2506,
275,
2197,
14,
602,
199,
199,
1366,
275,
2197,
14,
521,
199,
199,
10239,
275,
2197,
14,
2083,
199,
199,
318,
6148,
2532,
26441,
8,
10406,
304,
272,
372,
6148,
2031,
521,
14,
15198,
8,
10406,
18562,
19,
566,
199,
199,
318,
4703,
2532,
26441,
8,
10406,
304,
272,
372,
4703,
2031,
521,
14,
15198,
8,
10406,
2788,
19,
26,
22,
566,
199,
199,
318,
18267,
2532,
26441,
8,
10406,
304,
272,
372,
18267,
2031,
521,
14,
15198,
8,
10406,
18562,
22,
566,
199,
199,
1023,
63,
815,
275,
2008,
779,
442,
8,
88,
9,
367,
671,
315,
1015,
14,
1294,
15857,
566,
199,
10659,
63,
1023,
63,
815,
275,
2008,
779,
442,
8,
88,
9,
367,
671,
315,
11723,
63,
1023,
14,
1294,
15857,
566,
199,
199,
6636,
275,
3335,
199,
199,
318,
2274,
63,
21680,
63,
460,
63,
17911,
837,
272,
347,
19520,
63,
602,
8,
637,
304,
267,
372,
1139,
14,
17070,
342,
339,
347,
19520,
63,
2083,
8,
637,
304,
267,
372,
1139,
14,
17070,
480,
6099,
339,
347,
3957,
63,
602,
8,
637,
304,
267,
372,
2197,
14,
602,
2031,
1130,
8,
442,
12,
1139,
14,
1294,
6096,
13324,
339,
347,
3957,
63,
3954,
8,
637,
304,
267,
1434,
2064,
12,
900,
2064,
275,
1139,
14,
1294,
480,
6099,
267,
5361,
12,
5794,
12,
5382,
275,
2341,
8,
442,
12,
1434,
2064,
14,
1294,
6096,
2237,
267,
900,
2064,
63,
2861,
275,
900,
2064,
14,
1294,
15857,
267,
10857,
12,
9395,
12,
4696,
275,
2341,
8,
442,
12,
900,
2064,
63,
2861,
59,
16,
1055,
1294,
20308,
2237,
267,
340,
822,
8,
521,
2064,
63,
2861,
9,
508,
499,
26,
288,
21574,
275,
1109,
8,
521,
2064,
63,
2861,
59,
17,
566,
267,
587,
26,
288,
21574,
275,
378,
398,
1139,
275,
2197,
14,
2083,
8,
3403,
12,
5794,
12,
5382,
12,
10857,
12,
9395,
12,
4696,
12,
21574,
9,
267,
372,
1139,
2378,
2274,
63,
10394,
8,
2083,
14,
602,
12,
19520,
63,
602,
9,
272,
2274,
63,
10394,
8,
2083,
14,
2083,
12,
19520,
63,
2083,
9,
272,
2274,
63,
11256,
480,
602,
401,
3957,
63,
602,
9,
272,
2274,
63,
11256,
480,
3954,
401,
3957,
63,
3954,
9,
199,
199,
2683,
63,
21680,
63,
460,
63,
17911,
342,
199,
199,
3,
12762,
1536,
3231,
199,
199,
2264,
8,
2683,
63,
21680,
63,
460,
63,
17911,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryandougherty/mwa-capstone
|
MWA_Tools/build/matplotlib/doc/mpl_examples/pylab_examples/demo_bboximage.py
|
12
|
1805
|
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.image import BboxImage
from matplotlib.transforms import Bbox, TransformedBbox
if __name__ == "__main__":
fig = plt.figure(1)
ax = plt.subplot(121)
txt = ax.text(0.5, 0.5, "test", size=30, ha="center", color="w")
kwargs = dict()
bbox_image = BboxImage(txt.get_window_extent,
norm = None,
origin=None,
clip_on=False,
**kwargs
)
a = np.arange(256).reshape(1,256)/256.
bbox_image.set_data(a)
ax.add_artist(bbox_image)
ax = plt.subplot(122)
a = np.linspace(0, 1, 256).reshape(1,-1)
a = np.vstack((a,a))
maps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
#nmaps = len(maps) + 1
#fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
ncol = 2
nrow = len(maps)//ncol + 1
xpad_fraction = 0.3
dx = 1./(ncol + xpad_fraction*(ncol-1))
ypad_fraction = 0.3
dy = 1./(nrow + ypad_fraction*(nrow-1))
for i,m in enumerate(maps):
ix, iy = divmod(i, nrow)
#plt.figimage(a, 10, i*10, cmap=plt.get_cmap(m), origin='lower')
bbox0 = Bbox.from_bounds(ix*dx*(1+xpad_fraction),
1.-iy*dy*(1+ypad_fraction)-dy,
dx, dy)
bbox = TransformedBbox(bbox0, ax.transAxes)
bbox_image = BboxImage(bbox,
cmap = plt.get_cmap(m),
norm = None,
origin=None,
**kwargs
)
bbox_image.set_data(a)
ax.add_artist(bbox_image)
plt.draw()
plt.show()
|
gpl-2.0
|
[
646,
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
504,
8027,
14,
1569,
492,
699,
1977,
3491,
199,
504,
8027,
14,
15133,
492,
699,
1977,
12,
6266,
6194,
34,
1977,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
6085,
275,
4488,
14,
8941,
8,
17,
9,
272,
2185,
275,
4488,
14,
13334,
8,
10753,
9,
339,
9444,
275,
2185,
14,
505,
8,
16,
14,
21,
12,
378,
14,
21,
12,
298,
396,
401,
1568,
29,
1216,
12,
18251,
628,
4218,
401,
3164,
628,
87,
531,
272,
2074,
275,
1211,
342,
339,
12494,
63,
1569,
275,
699,
1977,
3491,
8,
2424,
14,
362,
63,
3806,
63,
11599,
12,
2574,
6316,
275,
488,
12,
2574,
6330,
29,
403,
12,
2574,
11353,
63,
265,
29,
797,
12,
2574,
1011,
958,
2574,
776,
272,
282,
275,
980,
14,
5605,
8,
3912,
680,
5217,
8,
17,
12,
3912,
2447,
3912,
14,
272,
12494,
63,
1569,
14,
409,
63,
576,
8,
65,
9,
272,
2185,
14,
525,
63,
11215,
8,
11246,
63,
1569,
9,
2378,
2185,
275,
4488,
14,
13334,
8,
7507,
9,
272,
282,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
7633,
680,
5217,
8,
17,
3057,
17,
9,
272,
282,
275,
980,
14,
20221,
1332,
65,
12,
65,
430,
339,
9033,
275,
3355,
8,
77,
367,
333,
315,
4488,
14,
4400,
14,
4616,
350,
340,
440,
333,
14,
4130,
11008,
82,
2237,
272,
327,
78,
8919,
275,
822,
8,
8919,
9,
435,
413,
339,
327,
592,
14,
21430,
63,
10917,
8,
2119,
29,
16,
14,
1020,
12,
9048,
29,
16,
14,
614,
12,
3602,
29,
16,
14,
18,
12,
2451,
29,
16,
14,
1020,
9,
339,
302,
761,
275,
499,
272,
302,
1143,
275,
822,
8,
8919,
28428,
78,
761,
435,
413,
339,
671,
6226,
63,
13054,
275,
378,
14,
19,
272,
11868,
275,
413,
14,
7985,
78,
761,
435,
671,
6226,
63,
13054,
5830,
78,
761,
13,
17,
430,
339,
612,
6226,
63,
13054,
275,
378,
14,
19,
272,
13119,
275,
413,
14,
7985,
78,
1143,
435,
612,
6226,
63,
13054,
5830,
78,
1143,
13,
17,
430,
339,
367,
284,
12,
77,
315,
3874,
8,
8919,
304,
267,
20593,
12,
284,
89,
275,
16438,
8,
73,
12,
302,
1143,
9,
267,
327,
6003,
14,
592,
1569,
8,
65,
12,
1616,
12,
284,
10,
709,
12,
14920,
29,
6003,
14,
362,
63,
16513,
8,
77,
395,
6330,
534,
2325,
358,
267,
12494,
16,
275,
699,
1977,
14,
504,
63,
9632,
8,
1148,
10,
8373,
5830,
17,
11,
88,
6226,
63,
13054,
395,
639,
413,
23683,
31256,
10,
8161,
5830,
17,
11,
2279,
350,
63,
13054,
7216,
8161,
12,
639,
11868,
12,
13119,
9,
267,
12494,
275,
6266,
6194,
34,
1977,
8,
11246,
16,
12,
2185,
14,
1515,
20386,
9,
398,
12494,
63,
1569,
275,
699,
1977,
3491,
8,
11246,
12,
3044,
14920,
275,
4488,
14,
362,
63,
16513,
8,
77,
395,
3044,
6316,
275,
488,
12,
3044,
6330,
29,
403,
12,
3044,
1011,
958,
3044,
776,
398,
12494,
63,
1569,
14,
409,
63,
576,
8,
65,
9,
267,
2185,
14,
525,
63,
11215,
8,
11246,
63,
1569,
9,
339,
4488,
14,
5485,
342,
272,
4488,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
8027,
14,
13563,
465,
4488,
199,
646,
2680,
465,
980,
199,
504,
8027,
14,
1569,
492,
699,
1977,
3491,
199,
504,
8027,
14,
15133,
492,
699,
1977,
12,
6266,
6194,
34,
1977,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
339,
6085,
275,
4488,
14,
8941,
8,
17,
9,
272,
2185,
275,
4488,
14,
13334,
8,
10753,
9,
339,
9444,
275,
2185,
14,
505,
8,
16,
14,
21,
12,
378,
14,
21,
12,
298,
396,
401,
1568,
29,
1216,
12,
18251,
628,
4218,
401,
3164,
628,
87,
531,
272,
2074,
275,
1211,
342,
339,
12494,
63,
1569,
275,
699,
1977,
3491,
8,
2424,
14,
362,
63,
3806,
63,
11599,
12,
2574,
6316,
275,
488,
12,
2574,
6330,
29,
403,
12,
2574,
11353,
63,
265,
29,
797,
12,
2574,
1011,
958,
2574,
776,
272,
282,
275,
980,
14,
5605,
8,
3912,
680,
5217,
8,
17,
12,
3912,
2447,
3912,
14,
272,
12494,
63,
1569,
14,
409,
63,
576,
8,
65,
9,
272,
2185,
14,
525,
63,
11215,
8,
11246,
63,
1569,
9,
2378,
2185,
275,
4488,
14,
13334,
8,
7507,
9,
272,
282,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
7633,
680,
5217,
8,
17,
3057,
17,
9,
272,
282,
275,
980,
14,
20221,
1332,
65,
12,
65,
430,
339,
9033,
275,
3355,
8,
77,
367,
333,
315,
4488,
14,
4400,
14,
4616,
350,
340,
440,
333,
14,
4130,
11008,
82,
2237,
272,
327,
78,
8919,
275,
822,
8,
8919,
9,
435,
413,
339,
327,
592,
14,
21430,
63,
10917,
8,
2119,
29,
16,
14,
1020,
12,
9048,
29,
16,
14,
614,
12,
3602,
29,
16,
14,
18,
12,
2451,
29,
16,
14,
1020,
9,
339,
302,
761,
275,
499,
272,
302,
1143,
275,
822,
8,
8919,
28428,
78,
761,
435,
413,
339,
671,
6226,
63,
13054,
275,
378,
14,
19,
272,
11868,
275,
413,
14,
7985,
78,
761,
435,
671,
6226,
63,
13054,
5830,
78,
761,
13,
17,
430,
339,
612,
6226,
63,
13054,
275,
378,
14,
19,
272,
13119,
275,
413,
14,
7985,
78,
1143,
435,
612,
6226,
63,
13054,
5830,
78,
1143,
13,
17,
430,
339,
367,
284,
12,
77,
315,
3874,
8,
8919,
304,
267,
20593,
12,
284,
89,
275,
16438,
8,
73,
12,
302,
1143,
9,
267,
327,
6003,
14,
592,
1569,
8,
65,
12,
1616,
12,
284,
10,
709,
12,
14920,
29,
6003,
14,
362,
63,
16513,
8,
77,
395,
6330,
534,
2325,
358,
267,
12494,
16,
275,
699,
1977,
14,
504,
63,
9632,
8,
1148,
10,
8373,
5830,
17,
11,
88,
6226,
63,
13054,
395,
639,
413,
23683,
31256,
10,
8161,
5830,
17,
11,
2279,
350,
63,
13054,
7216,
8161,
12,
639,
11868,
12,
13119,
9,
267,
12494,
275,
6266,
6194,
34,
1977,
8,
11246,
16,
12,
2185,
14,
1515,
20386,
9,
398,
12494,
63,
1569,
275,
699,
1977,
3491,
8,
11246,
12,
3044,
14920,
275,
4488,
14,
362,
63,
16513,
8,
77,
395,
3044,
6316,
275,
488,
12,
3044,
6330,
29,
403,
12,
3044,
1011,
958,
3044,
776,
398,
12494,
63,
1569,
14,
409,
63,
576,
8,
65,
9,
267,
2185,
14,
525,
63,
11215,
8,
11246,
63,
1569,
9,
339,
4488,
14,
5485,
342,
272,
4488,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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.
"""MockService provides CRUD ops. for mocking calls to AtomPub services.
MockService: Exposes the publicly used methods of AtomService to provide
a mock interface which can be used in unit tests.
"""
import atom.service
import pickle
__author__ = 'api.jscudder (Jeffrey Scudder)'
# Recordings contains pairings of HTTP MockRequest objects with MockHttpResponse objects.
recordings = []
# If set, the mock service HttpRequest are actually made through this object.
real_request_handler = None
def ConcealValueWithSha(source):
import sha
return sha.new(source[:-5]).hexdigest()
def DumpRecordings(conceal_func=ConcealValueWithSha):
if conceal_func:
for recording_pair in recordings:
recording_pair[0].ConcealSecrets(conceal_func)
return pickle.dumps(recordings)
def LoadRecordings(recordings_file_or_string):
if isinstance(recordings_file_or_string, str):
atom.mock_service.recordings = pickle.loads(recordings_file_or_string)
elif hasattr(recordings_file_or_string, 'read'):
atom.mock_service.recordings = pickle.loads(
recordings_file_or_string.read())
def HttpRequest(service, operation, data, uri, extra_headers=None,
url_params=None, escape_params=True, content_type='application/atom+xml'):
"""Simulates an HTTP call to the server, makes an actual HTTP request if
real_request_handler is set.
This function operates in two different modes depending on if
real_request_handler is set or not. If real_request_handler is not set,
HttpRequest will look in this module's recordings list to find a response
which matches the parameters in the function call. If real_request_handler
is set, this function will call real_request_handler.HttpRequest, add the
response to the recordings list, and respond with the actual response.
Args:
service: atom.AtomService object which contains some of the parameters
needed to make the request. The following members are used to
construct the HTTP call: server (str), additional_headers (dict),
port (int), and ssl (bool).
operation: str The HTTP operation to be performed. This is usually one of
'GET', 'POST', 'PUT', or 'DELETE'
data: ElementTree, filestream, list of parts, or other object which can be
converted to a string.
Should be set to None when performing a GET or PUT.
If data is a file-like object which can be read, this method will read
a chunk of 100K bytes at a time and send them.
If the data is a list of parts to be sent, each part will be evaluated
and sent.
uri: The beginning of the URL to which the request should be sent.
Examples: '/', '/base/feeds/snippets',
'/m8/feeds/contacts/default/base'
extra_headers: dict of strings. HTTP headers which should be sent
in the request. These headers are in addition to those stored in
service.additional_headers.
url_params: dict of strings. Key value pairs to be added to the URL as
URL parameters. For example {'foo':'bar', 'test':'param'} will
become ?foo=bar&test=param.
escape_params: bool default True. If true, the keys and values in
url_params will be URL escaped when the form is constructed
(Special characters converted to %XX form.)
content_type: str The MIME type for the data being sent. Defaults to
'application/atom+xml', this is only used if data is set.
"""
full_uri = atom.service.BuildUri(uri, url_params, escape_params)
(server, port, ssl, uri) = atom.service.ProcessUrl(service, uri)
current_request = MockRequest(operation, full_uri, host=server, ssl=ssl,
data=data, extra_headers=extra_headers, url_params=url_params,
escape_params=escape_params, content_type=content_type)
# If the request handler is set, we should actually make the request using
# the request handler and record the response to replay later.
if real_request_handler:
response = real_request_handler.HttpRequest(service, operation, data, uri,
extra_headers=extra_headers, url_params=url_params,
escape_params=escape_params, content_type=content_type)
# TODO: need to copy the HTTP headers from the real response into the
# recorded_response.
recorded_response = MockHttpResponse(body=response.read(),
status=response.status, reason=response.reason)
# Insert a tuple which maps the request to the response object returned
# when making an HTTP call using the real_request_handler.
recordings.append((current_request, recorded_response))
return recorded_response
else:
# Look through available recordings to see if one matches the current
# request.
for request_response_pair in recordings:
if request_response_pair[0].IsMatch(current_request):
return request_response_pair[1]
return None
class MockRequest(object):
"""Represents a request made to an AtomPub server.
These objects are used to determine if a client request matches a recorded
HTTP request to determine what the mock server's response will be.
"""
def __init__(self, operation, uri, host=None, ssl=False, port=None,
data=None, extra_headers=None, url_params=None, escape_params=True,
content_type='application/atom+xml'):
"""Constructor for a MockRequest
Args:
operation: str One of 'GET', 'POST', 'PUT', or 'DELETE' this is the
HTTP operation requested on the resource.
uri: str The URL describing the resource to be modified or feed to be
retrieved. This should include the protocol (http/https) and the host
(aka domain). For example, these are some valud full_uris:
'http://example.com', 'https://www.google.com/accounts/ClientLogin'
host: str (optional) The server name which will be placed at the
beginning of the URL if the uri parameter does not begin with 'http'.
Examples include 'example.com', 'www.google.com', 'www.blogger.com'.
ssl: boolean (optional) If true, the request URL will begin with https
instead of http.
data: ElementTree, filestream, list of parts, or other object which can be
converted to a string. (optional)
Should be set to None when performing a GET or PUT.
If data is a file-like object which can be read, the constructor
will read the entire file into memory. If the data is a list of
parts to be sent, each part will be evaluated and stored.
extra_headers: dict (optional) HTTP headers included in the request.
url_params: dict (optional) Key value pairs which should be added to
the URL as URL parameters in the request. For example uri='/',
url_parameters={'foo':'1','bar':'2'} could become '/?foo=1&bar=2'.
escape_params: boolean (optional) Perform URL escaping on the keys and
values specified in url_params. Defaults to True.
content_type: str (optional) Provides the MIME type of the data being
sent.
"""
self.operation = operation
self.uri = _ConstructFullUrlBase(uri, host=host, ssl=ssl)
self.data = data
self.extra_headers = extra_headers
self.url_params = url_params or {}
self.escape_params = escape_params
self.content_type = content_type
def ConcealSecrets(self, conceal_func):
"""Conceal secret data in this request."""
if self.extra_headers.has_key('Authorization'):
self.extra_headers['Authorization'] = conceal_func(
self.extra_headers['Authorization'])
def IsMatch(self, other_request):
"""Check to see if the other_request is equivalent to this request.
Used to determine if a recording matches an incoming request so that a
recorded response should be sent to the client.
The matching is not exact, only the operation and URL are examined
currently.
Args:
other_request: MockRequest The request which we want to check this
(self) MockRequest against to see if they are equivalent.
"""
# More accurate matching logic will likely be required.
return (self.operation == other_request.operation and self.uri ==
other_request.uri)
def _ConstructFullUrlBase(uri, host=None, ssl=False):
"""Puts URL components into the form http(s)://full.host.strinf/uri/path
Used to construct a roughly canonical URL so that URLs which begin with
'http://example.com/' can be compared to a uri of '/' when the host is
set to 'example.com'
If the uri contains 'http://host' already, the host and ssl parameters
are ignored.
Args:
uri: str The path component of the URL, examples include '/'
host: str (optional) The host name which should prepend the URL. Example:
'example.com'
ssl: boolean (optional) If true, the returned URL will begin with https
instead of http.
Returns:
String which has the form http(s)://example.com/uri/string/contents
"""
if uri.startswith('http'):
return uri
if ssl:
return 'https://%s%s' % (host, uri)
else:
return 'http://%s%s' % (host, uri)
class MockHttpResponse(object):
"""Returned from MockService crud methods as the server's response."""
def __init__(self, body=None, status=None, reason=None, headers=None):
"""Construct a mock HTTPResponse and set members.
Args:
body: str (optional) The HTTP body of the server's response.
status: int (optional)
reason: str (optional)
headers: dict (optional)
"""
self.body = body
self.status = status
self.reason = reason
self.headers = headers or {}
def read(self):
return self.body
def getheader(self, header_name):
return self.headers[header_name]
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
624,
3346,
3167,
6571,
17101,
3383,
4156,
14,
367,
1683,
316,
4882,
370,
18840,
18060,
8500,
14,
819,
4420,
3167,
26,
1316,
10553,
314,
7974,
317,
429,
89,
1202,
3102,
402,
18840,
3167,
370,
5647,
489,
282,
1683,
3217,
1314,
883,
506,
1202,
315,
4137,
2295,
14,
199,
624,
199,
199,
646,
6222,
14,
1364,
199,
646,
5927,
421,
199,
363,
2502,
363,
275,
283,
1246,
14,
74,
551,
1181,
424,
334,
42,
3609,
17885,
13916,
1181,
424,
3171,
421,
199,
3,
12651,
780,
3509,
4092,
780,
402,
3101,
4420,
2017,
2251,
543,
4420,
16287,
2251,
14,
199,
3059,
780,
275,
942,
199,
3,
982,
663,
12,
314,
1683,
2435,
20730,
787,
5965,
6326,
4012,
642,
909,
14,
199,
3093,
63,
1069,
63,
2232,
275,
488,
199,
199,
318,
1448,
301,
279,
1110,
3007,
23527,
8,
1365,
304,
523,
492,
7793,
523,
372,
7793,
14,
1222,
8,
1365,
4439,
21,
6575,
11453,
342,
199,
199,
318,
19460,
5433,
780,
8,
388,
301,
279,
63,
1532,
29,
714,
301,
279,
1110,
3007,
23527,
304,
523,
340,
406,
301,
279,
63,
1532,
26,
272,
367,
20952,
63,
3852,
315,
2777,
780,
26,
489,
20952,
63,
3852,
59,
16,
1055,
714,
301,
279,
4933,
264,
1086,
8,
388,
301,
279,
63,
1532,
9,
523,
372,
5927,
14,
4180,
8,
3059,
780,
9,
199,
199,
318,
7190,
5433,
780,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
304,
523,
340,
1228,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
12,
620,
304,
272,
6222,
14,
1805,
63,
1364,
14,
3059,
780,
275,
221,
5927,
14,
3640,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
9,
523,
916,
2688,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
12,
283,
739,
735,
272,
6222,
14,
1805,
63,
1364,
14,
3059,
780,
275,
5927,
14,
3640,
8,
489,
2777,
780,
63,
493,
63,
269,
63,
875,
14,
739,
1012,
199,
199,
318,
20730,
8,
1364,
12,
3439,
12,
666,
12,
5108,
12,
2402,
63,
2139,
29,
403,
12,
272,
1166,
63,
1162,
29,
403,
12,
4772,
63,
1162,
29,
549,
12,
1564,
63,
466,
534,
3578,
15,
4188,
11,
1652,
735,
523,
408,
7467,
15409,
376,
3101,
1240,
370,
314,
1654,
12,
7704,
376,
3503,
3101,
1056,
340,
16421,
3363,
63,
1069,
63,
2232,
365,
663,
14,
819,
961,
805,
1758,
2335,
315,
2877,
3365,
12404,
10298,
641,
340,
16421,
3363,
63,
1069,
63,
2232,
365,
663,
503,
440,
14,
982,
3363,
63,
1069,
63,
2232,
365,
440,
663,
12,
523,
20730,
911,
3648,
315,
642,
859,
1159,
2777,
780,
769,
370,
2342,
282,
1177,
523,
1314,
4450,
314,
2633,
315,
314,
805,
1240,
14,
982,
3363,
63,
1069,
63,
2232,
523,
365,
663,
12,
642,
805,
911,
1240,
3363,
63,
1069,
63,
2232,
14,
10441,
12,
1050,
314,
523,
1177,
370,
314,
2777,
780,
769,
12,
436,
22722,
543,
314,
3503,
1177,
14,
819,
3033,
26,
272,
2435,
26,
6222,
14,
12097,
3167,
909,
1314,
3509,
2005,
402,
314,
2633,
267,
4346,
370,
1852,
314,
1056,
14,
710,
2569,
7556,
787,
1202,
370,
267,
6982,
314,
3101,
1240,
26,
1654,
334,
495,
395,
4722,
63,
2139,
334,
807,
395,
267,
1844,
334,
442,
395,
436,
6149,
334,
2245,
680,
272,
3439,
26,
620,
710,
3101,
3439,
370,
506,
10585,
14,
961,
365,
9987,
1373,
402,
267,
283,
2970,
297,
283,
4030,
297,
283,
4013,
297,
503,
283,
7014,
7,
272,
666,
26,
13139,
12,
570,
1745,
12,
769,
402,
4184,
12,
503,
1163,
909,
1314,
883,
506,
267,
6702,
370,
282,
1059,
14,
267,
7719,
506,
663,
370,
488,
1380,
19203,
282,
9576,
503,
18337,
14,
267,
982,
666,
365,
282,
570,
13,
2930,
909,
1314,
883,
506,
1586,
12,
642,
1083,
911,
1586,
267,
282,
3728,
402,
2948,
43,
2783,
737,
282,
900,
436,
3222,
3062,
14,
267,
982,
314,
666,
365,
282,
769,
402,
4184,
370,
506,
4847,
12,
1924,
1777,
911,
506,
13006,
267,
436,
4847,
14,
272,
5108,
26,
710,
9608,
402,
314,
2851,
370,
1314,
314,
1056,
1077,
506,
4847,
14,
267,
6058,
26,
17220,
1994,
1095,
15,
11522,
15,
32566,
297,
267,
1994,
77,
24,
15,
11522,
15,
18147,
15,
885,
15,
1095,
7,
272,
2402,
63,
2139,
26,
1211,
402,
3326,
14,
3101,
2323,
1314,
1077,
506,
4847,
267,
315,
314,
1056,
14,
5723,
2323,
787,
315,
10234,
370,
5204,
5489,
315,
267,
2435,
14,
8460,
63,
2139,
14,
272,
1166,
63,
1162,
26,
1211,
402,
3326,
14,
2606,
574,
6342,
370,
506,
3483,
370,
314,
2851,
465,
267,
2851,
2633,
14,
2104,
2893,
791,
1421,
5242,
1700,
297,
283,
396,
5242,
635,
936,
911,
267,
8649,
5805,
1421,
29,
1700,
6,
396,
29,
635,
14,
272,
4772,
63,
1162,
26,
2155,
849,
715,
14,
982,
2549,
12,
314,
2883,
436,
1338,
315,
267,
1166,
63,
1162,
911,
506,
2851,
11077,
1380,
314,
1824,
365,
14701,
267,
334,
12246,
4110,
6702,
370,
450,
2483,
1824,
4959,
272,
1564,
63,
466,
26,
620,
710,
14735,
730,
367,
314,
666,
3769,
4847,
14,
7827,
370,
267,
283,
3578,
15,
4188,
11,
1652,
297,
642,
365,
1454,
1202,
340,
666,
365,
663,
14,
523,
408,
523,
2615,
63,
2302,
275,
6222,
14,
1364,
14,
3425,
14014,
8,
2302,
12,
1166,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
624,
3346,
3167,
6571,
17101,
3383,
4156,
14,
367,
1683,
316,
4882,
370,
18840,
18060,
8500,
14,
819,
4420,
3167,
26,
1316,
10553,
314,
7974,
317,
429,
89,
1202,
3102,
402,
18840,
3167,
370,
5647,
489,
282,
1683,
3217,
1314,
883,
506,
1202,
315,
4137,
2295,
14,
199,
624,
199,
199,
646,
6222,
14,
1364,
199,
646,
5927,
421,
199,
363,
2502,
363,
275,
283,
1246,
14,
74,
551,
1181,
424,
334,
42,
3609,
17885,
13916,
1181,
424,
3171,
421,
199,
3,
12651,
780,
3509,
4092,
780,
402,
3101,
4420,
2017,
2251,
543,
4420,
16287,
2251,
14,
199,
3059,
780,
275,
942,
199,
3,
982,
663,
12,
314,
1683,
2435,
20730,
787,
5965,
6326,
4012,
642,
909,
14,
199,
3093,
63,
1069,
63,
2232,
275,
488,
199,
199,
318,
1448,
301,
279,
1110,
3007,
23527,
8,
1365,
304,
523,
492,
7793,
523,
372,
7793,
14,
1222,
8,
1365,
4439,
21,
6575,
11453,
342,
199,
199,
318,
19460,
5433,
780,
8,
388,
301,
279,
63,
1532,
29,
714,
301,
279,
1110,
3007,
23527,
304,
523,
340,
406,
301,
279,
63,
1532,
26,
272,
367,
20952,
63,
3852,
315,
2777,
780,
26,
489,
20952,
63,
3852,
59,
16,
1055,
714,
301,
279,
4933,
264,
1086,
8,
388,
301,
279,
63,
1532,
9,
523,
372,
5927,
14,
4180,
8,
3059,
780,
9,
199,
199,
318,
7190,
5433,
780,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
304,
523,
340,
1228,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
12,
620,
304,
272,
6222,
14,
1805,
63,
1364,
14,
3059,
780,
275,
221,
5927,
14,
3640,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
9,
523,
916,
2688,
8,
3059,
780,
63,
493,
63,
269,
63,
875,
12,
283,
739,
735,
272,
6222,
14,
1805,
63,
1364,
14,
3059,
780,
275,
5927,
14,
3640,
8,
489,
2777,
780,
63,
493,
63,
269,
63,
875,
14,
739,
1012,
199,
199,
318,
20730,
8,
1364,
12,
3439,
12,
666,
12,
5108,
12,
2402,
63,
2139,
29,
403,
12,
272,
1166,
63,
1162,
29,
403,
12,
4772,
63,
1162,
29,
549,
12,
1564,
63,
466,
534,
3578,
15,
4188,
11,
1652,
735,
523,
408,
7467,
15409,
376,
3101,
1240,
370,
314,
1654,
12,
7704,
376,
3503,
3101,
1056,
340,
16421,
3363,
63,
1069,
63,
2232,
365,
663,
14,
819,
961,
805,
1758,
2335,
315,
2877,
3365,
12404,
10298,
641,
340,
16421,
3363,
63,
1069,
63,
2232,
365,
663,
503,
440,
14,
982,
3363,
63,
1069,
63,
2232,
365,
440,
663,
12,
523,
20730,
911,
3648,
315,
642,
859,
1159,
2777,
780,
769,
370,
2342,
282,
1177,
523,
1314,
4450,
314,
2633,
315,
314,
805,
1240,
14,
982,
3363,
63,
1069,
63,
2232,
523,
365,
663,
12,
642,
805,
911,
1240,
3363,
63,
1069,
63,
2232,
14,
10441,
12,
1050,
314,
523,
1177,
370,
314,
2777,
780,
769,
12,
436,
22722,
543,
314,
3503,
1177,
14,
819,
3033,
26,
272,
2435,
26,
6222,
14,
12097,
3167,
909,
1314,
3509,
2005,
402,
314,
2633,
267,
4346,
370,
1852,
314,
1056,
14,
710,
2569,
7556,
787,
1202,
370,
267,
6982,
314,
3101,
1240,
26,
1654,
334,
495,
395,
4722,
63,
2139,
334,
807,
395,
267,
1844,
334,
442,
395,
436,
6149,
334,
2245,
680,
272,
3439,
26,
620,
710,
3101,
3439,
370,
506,
10585,
14,
961,
365,
9987,
1373,
402,
267,
283,
2970,
297,
283,
4030,
297,
283,
4013,
297,
503,
283,
7014,
7,
272,
666,
26,
13139,
12,
570,
1745,
12,
769,
402,
4184,
12,
503,
1163,
909,
1314,
883,
506,
267,
6702,
370,
282,
1059,
14,
267,
7719,
506,
663,
370,
488,
1380,
19203,
282,
9576,
503,
18337,
14,
267,
982,
666,
365,
282,
570,
13,
2930,
909,
1314,
883,
506,
1586,
12,
642,
1083,
911,
1586,
267,
282,
3728,
402,
2948,
43,
2783,
737,
282,
900,
436,
3222,
3062,
14,
267,
982,
314,
666,
365,
282,
769,
402,
4184,
370,
506,
4847,
12,
1924,
1777,
911,
506,
13006,
267,
436,
4847,
14,
272,
5108,
26,
710,
9608,
402,
314,
2851,
370,
1314,
314,
1056,
1077,
506,
4847,
14,
267,
6058,
26,
17220,
1994,
1095,
15,
11522,
15,
32566,
297,
267,
1994,
77,
24,
15,
11522,
15,
18147,
15,
885,
15,
1095,
7,
272,
2402,
63,
2139,
26,
1211,
402,
3326,
14,
3101,
2323,
1314,
1077,
506,
4847,
267,
315,
314,
1056,
14,
5723,
2323,
787,
315,
10234,
370,
5204,
5489,
315,
267,
2435,
14,
8460,
63,
2139,
14,
272,
1166,
63,
1162,
26,
1211,
402,
3326,
14,
2606,
574,
6342,
370,
506,
3483,
370,
314,
2851,
465,
267,
2851,
2633,
14,
2104,
2893,
791,
1421,
5242,
1700,
297,
283,
396,
5242,
635,
936,
911,
267,
8649,
5805,
1421,
29,
1700,
6,
396,
29,
635,
14,
272,
4772,
63,
1162,
26,
2155,
849,
715,
14,
982,
2549,
12,
314,
2883,
436,
1338,
315,
267,
1166,
63,
1162,
911,
506,
2851,
11077,
1380,
314,
1824,
365,
14701,
267,
334,
12246,
4110,
6702,
370,
450,
2483,
1824,
4959,
272,
1564,
63,
466,
26,
620,
710,
14735,
730,
367,
314,
666,
3769,
4847,
14,
7827,
370,
267,
283,
3578,
15,
4188,
11,
1652,
297,
642,
365,
1454,
1202,
340,
666,
365,
663,
14,
523,
408,
523,
2615,
63,
2302,
275,
6222,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Nicoretti/libslack
|
libslack/tests/__init__.py
|
1
|
1485
|
#!/usr/bin/env python3
#
# Copyright (c) 2015, Nicola Coretti
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 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.
__version__ = "0.5.0"
__author__ = 'Nicola Coretti'
__email__ = 'nico.coretti@gmail.com'
__all__ = ['slackapi_tests']
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
12,
653,
12802,
416,
11672,
84,
280,
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,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
259,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
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,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
363,
1023,
363,
275,
298,
16,
14,
21,
14,
16,
2,
199,
363,
2502,
363,
275,
283,
46,
12802,
416,
11672,
84,
280,
7,
199,
363,
2123,
363,
275,
283,
8445,
331,
14,
1018,
84,
280,
32,
6799,
14,
957,
7,
199,
199,
363,
452,
363,
275,
788,
24567,
1246,
63,
2219,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
19,
199,
3,
199,
3,
1898,
334,
67,
9,
6900,
12,
653,
12802,
416,
11672,
84,
280,
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,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
3,
259,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
499,
14,
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,
2401,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
9315,
199,
3,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
199,
3,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
199,
3,
5258,
1821,
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,
1634,
5749,
199,
3,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
363,
1023,
363,
275,
298,
16,
14,
21,
14,
16,
2,
199,
363,
2502,
363,
275,
283,
46,
12802,
416,
11672,
84,
280,
7,
199,
363,
2123,
363,
275,
283,
8445,
331,
14,
1018,
84,
280,
32,
6799,
14,
957,
7,
199,
199,
363,
452,
363,
275,
788,
24567,
1246,
63,
2219,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
edxnercel/edx-platform
|
pavelib/paver_tests/test_paver_get_quality_reports.py
|
56
|
1550
|
import os
import tempfile
import unittest
from mock import patch, Mock
from ddt import ddt, file_data
import pavelib.quality
import paver.easy
from paver.easy import BuildFailure
class TestGetReportFiles(unittest.TestCase):
"""
Ensure only the report files we want are returned as part of run_quality.
"""
@patch('os.walk')
def test_get_pylint_reports(self, my_mock):
my_mock.return_value = iter([
('/foo', ('',), ('pylint.report',)),
('/bar', ('/baz',), ('pylint.report',))
])
reports = pavelib.quality.get_violations_reports("pylint")
self.assertEqual(len(reports), 2)
@patch('os.walk')
def test_get_pep8_reports(self, my_mock):
my_mock.return_value = iter([
('/foo', ('',), ('pep8.report',)),
('/bar', ('/baz',), ('pep8.report',))
])
reports = pavelib.quality.get_violations_reports("pep8")
self.assertEqual(len(reports), 2)
@patch('os.walk')
def test_get_pep8_reports_noisy(self, my_mock):
""" Several conditions: different report types, different files, multiple files """
my_mock.return_value = iter([
('/foo', ('',), ('pep8.report',)),
('/fooz', ('/ball',), ('pylint.report',)),
('/fooz', ('/ball',), ('non.report',)),
('/fooz', ('/ball',), ('lms.xml',)),
('/bar', ('/baz',), ('pep8.report',))
])
reports = pavelib.quality.get_violations_reports("pep8")
self.assertEqual(len(reports), 2)
|
agpl-3.0
|
[
646,
747,
199,
646,
5549,
199,
646,
2882,
199,
504,
1683,
492,
3371,
12,
4420,
199,
504,
366,
3583,
492,
366,
3583,
12,
570,
63,
576,
199,
199,
646,
691,
432,
773,
14,
9161,
199,
646,
691,
422,
14,
13581,
199,
504,
691,
422,
14,
13581,
492,
6516,
6782,
421,
199,
533,
1379,
1002,
7457,
5535,
8,
2796,
14,
1746,
304,
272,
408,
272,
7523,
1454,
314,
3622,
1584,
781,
2934,
787,
2138,
465,
1777,
402,
1255,
63,
9161,
14,
272,
408,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
26324,
63,
15629,
8,
277,
12,
3002,
63,
1805,
304,
398,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
26324,
14,
3070,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
26324,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
26324,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
12636,
24,
63,
15629,
8,
277,
12,
3002,
63,
1805,
304,
267,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
12636,
24,
14,
3070,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
12636,
24,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
12636,
24,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
12636,
24,
63,
15629,
63,
889,
19765,
8,
277,
12,
3002,
63,
1805,
304,
267,
408,
3240,
422,
279,
3704,
26,
3365,
3622,
2943,
12,
3365,
1584,
12,
3663,
1584,
408,
267,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
12636,
24,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
26324,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
2865,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
15807,
14,
1652,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
12636,
24,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
12636,
24,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
5549,
199,
646,
2882,
199,
504,
1683,
492,
3371,
12,
4420,
199,
504,
366,
3583,
492,
366,
3583,
12,
570,
63,
576,
199,
199,
646,
691,
432,
773,
14,
9161,
199,
646,
691,
422,
14,
13581,
199,
504,
691,
422,
14,
13581,
492,
6516,
6782,
421,
199,
533,
1379,
1002,
7457,
5535,
8,
2796,
14,
1746,
304,
272,
408,
272,
7523,
1454,
314,
3622,
1584,
781,
2934,
787,
2138,
465,
1777,
402,
1255,
63,
9161,
14,
272,
408,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
26324,
63,
15629,
8,
277,
12,
3002,
63,
1805,
304,
398,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
26324,
14,
3070,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
26324,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
26324,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
12636,
24,
63,
15629,
8,
277,
12,
3002,
63,
1805,
304,
267,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
12636,
24,
14,
3070,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
12636,
24,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
12636,
24,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
339,
768,
2068,
360,
736,
14,
7757,
358,
272,
347,
511,
63,
362,
63,
12636,
24,
63,
15629,
63,
889,
19765,
8,
277,
12,
3002,
63,
1805,
304,
267,
408,
3240,
422,
279,
3704,
26,
3365,
3622,
2943,
12,
3365,
1584,
12,
3663,
1584,
408,
267,
3002,
63,
1805,
14,
1107,
63,
585,
275,
2740,
779,
288,
14606,
1421,
297,
661,
5529,
661,
12636,
24,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
26324,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
2865,
14,
3070,
16256,
288,
14606,
1421,
90,
297,
14606,
8571,
5529,
661,
15807,
14,
1652,
16256,
288,
14606,
1700,
297,
14606,
6185,
5529,
661,
12636,
24,
14,
3070,
16829,
267,
4794,
267,
13924,
275,
691,
432,
773,
14,
9161,
14,
362,
63,
433,
22938,
63,
15629,
480,
12636,
24,
531,
267,
291,
14,
629,
8,
552,
8,
15629,
395,
499,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Yuriy-Leonov/nova
|
nova/db/sqlalchemy/migrate_repo/versions/184_fix_159_migration_sync_shadow_table.py
|
16
|
2507
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 IBM Corp.
# 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 sqlalchemy import MetaData, String, Table
from sqlalchemy.dialects import postgresql
TABLE_COLUMNS = [
# table name, column name
('shadow_instances', 'access_ip_v4'),
('shadow_instances', 'access_ip_v6'),
('shadow_networks', 'gateway'),
('shadow_networks', 'gateway_v6'),
('shadow_networks', 'netmask'),
('shadow_networks', 'netmask_v6'),
('shadow_networks', 'broadcast'),
('shadow_networks', 'dns1'),
('shadow_networks', 'dns2'),
('shadow_networks', 'vpn_public_address'),
('shadow_networks', 'vpn_private_address'),
('shadow_networks', 'dhcp_start'),
('shadow_fixed_ips', 'address'),
('shadow_floating_ips', 'address'),
('shadow_console_pools', 'address')]
def upgrade(migrate_engine):
dialect = migrate_engine.url.get_dialect()
# NOTE(maurosr): this just affects mysql; postgresql uses INET
# type and sqlite doesn't goes fine with alter tables, so it should be done
# manually. This way we'll be able to keep UCs like the one inserted on
# version 158 which would get lost cause sqlite is not migrated as mysql or
# pgsql, it copies the column and data instead of execute an alter table
# command.
if dialect is not postgresql.dialect:
meta = MetaData(bind=migrate_engine)
for table, column in TABLE_COLUMNS:
t = Table(table, meta, autoload=True)
getattr(t.c, column).alter(type=String(39))
def downgrade(migrate_engine):
"""Convert columns back to the larger String(43) defined in version 149."""
dialect = migrate_engine.url.get_dialect()
if dialect is not postgresql.dialect:
meta = MetaData(bind=migrate_engine)
for table, column in TABLE_COLUMNS:
t = Table(table, meta, autoload=True)
getattr(t.c, column).alter(type=String(43))
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
8335,
492,
24905,
12,
2624,
12,
6957,
199,
504,
8335,
14,
11072,
83,
492,
25951,
199,
199,
8723,
63,
28427,
275,
359,
272,
327,
1817,
536,
12,
2763,
536,
272,
661,
14714,
63,
5990,
297,
283,
2732,
63,
711,
63,
86,
20,
659,
272,
661,
14714,
63,
5990,
297,
283,
2732,
63,
711,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
7019,
659,
272,
661,
14714,
63,
7642,
297,
283,
7019,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
14588,
659,
272,
661,
14714,
63,
7642,
297,
283,
14588,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
10786,
659,
272,
661,
14714,
63,
7642,
297,
283,
5797,
17,
659,
272,
661,
14714,
63,
7642,
297,
283,
5797,
18,
659,
272,
661,
14714,
63,
7642,
297,
283,
9702,
63,
3455,
63,
1562,
659,
272,
661,
14714,
63,
7642,
297,
283,
9702,
63,
4239,
63,
1562,
659,
272,
661,
14714,
63,
7642,
297,
283,
10801,
63,
928,
659,
272,
661,
14714,
63,
5964,
63,
6142,
297,
283,
1562,
659,
272,
661,
14714,
63,
7774,
63,
6142,
297,
283,
1562,
659,
272,
661,
14714,
63,
6614,
63,
12406,
297,
283,
1562,
5440,
421,
199,
318,
10754,
8,
8462,
63,
3908,
304,
272,
10982,
275,
12810,
63,
3908,
14,
633,
14,
362,
63,
11072,
342,
339,
327,
6944,
8,
391,
85,
4796,
82,
304,
642,
2951,
29476,
12896,
27,
25951,
4440,
1621,
775,
272,
327,
730,
436,
11723,
3181,
1133,
13538,
15701,
543,
17355,
6716,
12,
880,
652,
1077,
506,
4224,
272,
327,
10250,
14,
961,
4340,
781,
7171,
506,
7688,
370,
4215,
738,
13912,
2839,
314,
1373,
11788,
641,
272,
327,
1015,
413,
2010,
1314,
3955,
664,
14669,
7675,
11723,
365,
440,
28322,
465,
12896,
503,
272,
327,
299,
458,
1710,
12,
652,
6866,
314,
2763,
436,
666,
3140,
402,
5341,
376,
17355,
1817,
272,
327,
1414,
14,
272,
340,
10982,
365,
440,
25951,
14,
11072,
26,
267,
3404,
275,
24905,
8,
3409,
29,
8462,
63,
3908,
9,
267,
367,
1817,
12,
2763,
315,
9934,
63,
28427,
26,
288,
307,
275,
6957,
8,
1224,
12,
3404,
12,
2599,
912,
29,
549,
9,
288,
2519,
8,
84,
14,
67,
12,
2763,
680,
11858,
8,
466,
29,
1558,
8,
1355,
430,
421,
199,
318,
32498,
8,
8462,
63,
3908,
304,
272,
408,
7306,
4362,
1771,
370,
314,
12142,
2624,
8,
2824,
9,
3247,
315,
1015,
28528,
1041,
272,
10982,
275,
12810,
63,
3908,
14,
633,
14,
362,
63,
11072,
342,
272,
340,
10982,
365,
440,
25951,
14,
11072,
26,
267,
3404,
275,
24905,
8,
3409,
29,
8462,
63,
3908,
9,
267,
367,
1817,
12,
2763,
315,
9934,
63,
28427,
26,
288,
307,
275,
6957,
8,
1224,
12,
3404,
12,
2599,
912,
29,
549,
9,
288,
2519,
8,
84,
14,
67,
12,
2763,
680,
11858,
8,
466,
29,
1558,
8,
2824,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
6171,
26202,
22304,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
8335,
492,
24905,
12,
2624,
12,
6957,
199,
504,
8335,
14,
11072,
83,
492,
25951,
199,
199,
8723,
63,
28427,
275,
359,
272,
327,
1817,
536,
12,
2763,
536,
272,
661,
14714,
63,
5990,
297,
283,
2732,
63,
711,
63,
86,
20,
659,
272,
661,
14714,
63,
5990,
297,
283,
2732,
63,
711,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
7019,
659,
272,
661,
14714,
63,
7642,
297,
283,
7019,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
14588,
659,
272,
661,
14714,
63,
7642,
297,
283,
14588,
63,
86,
22,
659,
272,
661,
14714,
63,
7642,
297,
283,
10786,
659,
272,
661,
14714,
63,
7642,
297,
283,
5797,
17,
659,
272,
661,
14714,
63,
7642,
297,
283,
5797,
18,
659,
272,
661,
14714,
63,
7642,
297,
283,
9702,
63,
3455,
63,
1562,
659,
272,
661,
14714,
63,
7642,
297,
283,
9702,
63,
4239,
63,
1562,
659,
272,
661,
14714,
63,
7642,
297,
283,
10801,
63,
928,
659,
272,
661,
14714,
63,
5964,
63,
6142,
297,
283,
1562,
659,
272,
661,
14714,
63,
7774,
63,
6142,
297,
283,
1562,
659,
272,
661,
14714,
63,
6614,
63,
12406,
297,
283,
1562,
5440,
421,
199,
318,
10754,
8,
8462,
63,
3908,
304,
272,
10982,
275,
12810,
63,
3908,
14,
633,
14,
362,
63,
11072,
342,
339,
327,
6944,
8,
391,
85,
4796,
82,
304,
642,
2951,
29476,
12896,
27,
25951,
4440,
1621,
775,
272,
327,
730,
436,
11723,
3181,
1133,
13538,
15701,
543,
17355,
6716,
12,
880,
652,
1077,
506,
4224,
272,
327,
10250,
14,
961,
4340,
781,
7171,
506,
7688,
370,
4215,
738,
13912,
2839,
314,
1373,
11788,
641,
272,
327,
1015,
413,
2010,
1314,
3955,
664,
14669,
7675,
11723,
365,
440,
28322,
465,
12896,
503,
272,
327,
299,
458,
1710,
12,
652,
6866,
314,
2763,
436,
666,
3140,
402,
5341,
376,
17355,
1817,
272,
327,
1414,
14,
272,
340,
10982,
365,
440,
25951,
14,
11072,
26,
267,
3404,
275,
24905,
8,
3409,
29,
8462,
63,
3908,
9,
267,
367,
1817,
12,
2763,
315,
9934,
63,
28427,
26,
288,
307,
275,
6957,
8,
1224,
12,
3404,
12,
2599,
912,
29,
549,
9,
288,
2519,
8,
84,
14,
67,
12,
2763,
680,
11858,
8,
466,
29,
1558,
8,
1355,
430,
421,
199,
318,
32498,
8,
8462,
63,
3908,
304,
272,
408,
7306,
4362,
1771,
370,
314,
12142,
2624,
8,
2824,
9,
3247,
315,
1015,
28528,
1041,
272,
10982,
275,
12810,
63,
3908,
14,
633,
14,
362,
63,
11072,
342,
272,
340,
10982,
365,
440,
25951,
14,
11072,
26,
267,
3404,
275,
24905,
8,
3409,
29,
8462,
63,
3908,
9,
267,
367,
1817,
12,
2763,
315,
9934,
63,
28427,
26,
288,
307,
275,
6957,
8,
1224,
12,
3404,
12,
2599,
912,
29,
549,
9,
288,
2519,
8,
84,
14,
67,
12,
2763,
680,
11858,
8,
466,
29,
1558,
8,
2824,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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right (C) 2009 Andrew Resch <andrewresch@gmail.com>
#
# Deluge is free software.
#
# You may 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.
#
# deluge 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 deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
#
#
import deluge.component as component
from deluge.log import LOG as log
class EventManager(component.Component):
def __init__(self):
component.Component.__init__(self, "EventManager")
self.handlers = {}
def emit(self, event):
"""
Emits the event to interested clients.
:param event: DelugeEvent
"""
# Emit the event to the interested clients
component.get("RPCServer").emit_event(event)
# Call any handlers for the event
if event.name in self.handlers:
for handler in self.handlers[event.name]:
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
try:
handler(*event.args)
except Exception, e:
log.error("Event handler %s failed in %s with exception %s", event.name, handler, e)
def register_event_handler(self, event, handler):
"""
Registers a function to be called when a `:param:event` is emitted.
:param event: str, the event name
:param handler: function, to be called when `:param:event` is emitted
"""
if event not in self.handlers:
self.handlers[event] = []
if handler not in self.handlers[event]:
self.handlers[event].append(handler)
def deregister_event_handler(self, event, handler):
"""
Deregisters an event handler function.
:param event: str, the event name
:param handler: function, currently registered to handle `:param:event`
"""
if event in self.handlers and handler in self.handlers[event]:
self.handlers[event].remove(handler)
|
gpl-3.0
|
[
3,
199,
3,
1566,
2609,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
6061,
5257,
3591,
335,
665,
460,
5257,
470,
335,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
18464,
17730,
365,
2867,
2032,
14,
199,
3,
199,
3,
2047,
1443,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
12,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2150,
17730,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
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,
2150,
17730,
14,
259,
982,
440,
12,
2218,
370,
26,
199,
3,
221,
198,
1918,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
221,
198,
2869,
11236,
14259,
12,
12066,
11844,
199,
3,
221,
198,
34,
7797,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
259,
1010,
10234,
12,
465,
282,
4539,
1919,
12,
314,
4248,
31976,
8120,
199,
3,
259,
4983,
370,
2142,
314,
1233,
402,
12468,
402,
642,
2240,
543,
314,
14296,
199,
3,
259,
3555,
14,
199,
3,
259,
2047,
1471,
312,
32236,
314,
1664,
1696,
1684,
844,
315,
1006,
14021,
83,
367,
1006,
402,
199,
3,
259,
314,
1233,
1202,
1163,
2419,
14296,
14,
982,
1265,
2811,
570,
8,
83,
9,
543,
642,
199,
3,
259,
1919,
12,
1265,
1443,
12247,
642,
1919,
370,
2195,
1015,
402,
314,
570,
8,
83,
395,
199,
3,
259,
1325,
1265,
787,
440,
2607,
17506,
972,
370,
886,
880,
14,
982,
1265,
886,
440,
13809,
370,
886,
880,
12,
3145,
199,
3,
259,
642,
1919,
5164,
687,
2195,
1015,
14,
982,
1265,
3145,
642,
1919,
199,
3,
259,
5164,
687,
1006,
1350,
1584,
315,
314,
2240,
12,
2066,
2597,
3145,
652,
2348,
14,
199,
3,
199,
3,
199,
199,
646,
2150,
17730,
14,
3173,
465,
3931,
199,
504,
2150,
17730,
14,
793,
492,
5051,
465,
943,
199,
199,
533,
6763,
2988,
8,
3173,
14,
7004,
304,
272,
347,
636,
826,
721,
277,
304,
267,
3931,
14,
7004,
855,
826,
721,
277,
12,
298,
2390,
2988,
531,
267,
291,
14,
5586,
275,
1052,
339,
347,
8689,
8,
277,
12,
1566,
304,
267,
408,
267,
662,
1147,
83,
314,
1566,
370,
22201,
13431,
14,
398,
520,
635,
1566,
26,
18464,
17730,
2390,
267,
408,
267,
327,
662,
1147,
314,
1566,
370,
314,
22201,
13431,
267,
3931,
14,
362,
480,
8171,
3120,
3471,
8159,
63,
1430,
8,
1430,
9,
267,
327,
6523,
1263,
8297,
367,
314,
1566,
267,
340,
1566,
14,
354,
315,
291,
14,
5586,
26,
288,
367,
3016,
315,
291,
14,
5586,
59,
1430,
14,
354,
2189,
355,
327,
793,
14,
1757,
480,
9602,
3016,
450,
83,
367,
1566,
450,
83,
543,
1249,
26,
450,
83,
401,
1566,
14,
354,
12,
3016,
12,
1566,
14,
589,
9,
355,
862,
26,
490,
3016,
2031,
1430,
14,
589,
9,
355,
871,
2186,
12,
325,
26,
490,
943,
14,
705,
480,
2390,
3016,
450,
83,
3405,
315,
450,
83,
543,
1919,
450,
83,
401,
1566,
14,
354,
12,
3016,
12,
325,
9,
339,
347,
2274,
63,
1430,
63,
2232,
8,
277,
12,
1566,
12,
3016,
304,
267,
408,
267,
5044,
14186,
282,
805,
370,
506,
2797,
1380,
282,
658,
26,
635,
26,
1430,
64,
365,
19515,
14,
398,
520,
635,
1566,
26,
620,
12,
314,
1566,
536,
267,
520,
635,
3016,
26,
805,
12,
370,
506,
2797,
1380,
658,
26,
635,
26,
1430,
64,
365,
19515,
398,
408,
267,
340,
1566,
440,
315,
291,
14,
5586,
26,
288,
291,
14,
5586,
59,
1430,
61,
275,
942,
398,
340,
3016,
440,
315,
291,
14,
5586,
59,
1430,
2189,
288,
291,
14,
5586,
59,
1430,
1055,
740,
8,
2232,
9,
339,
347,
477,
2683,
63,
1430,
63,
2232,
8,
277,
12,
1566,
12,
3016,
304,
267,
408,
267,
1487,
30792,
376,
1566,
3016,
805,
14,
398,
520,
635,
1566,
26,
620,
12,
314,
1566,
536,
267,
520,
635,
3016,
26,
805,
12,
5544,
7264,
370,
2429,
658,
26,
635,
26,
1430,
64,
398,
408,
267,
340,
1566,
315,
291,
14,
5586,
436,
3016,
315,
291,
14,
5586,
59,
1430,
2189,
288,
291,
14,
5586,
59,
1430,
1055,
2168,
8,
2232,
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
] |
[
199,
3,
1566,
2609,
14,
647,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
6061,
5257,
3591,
335,
665,
460,
5257,
470,
335,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
18464,
17730,
365,
2867,
2032,
14,
199,
3,
199,
3,
2047,
1443,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
199,
3,
1664,
1696,
1684,
844,
12,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2150,
17730,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
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,
2150,
17730,
14,
259,
982,
440,
12,
2218,
370,
26,
199,
3,
221,
198,
1918,
2868,
2290,
2752,
12,
3277,
2020,
199,
3,
221,
198,
2869,
11236,
14259,
12,
12066,
11844,
199,
3,
221,
198,
34,
7797,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
3,
259,
1010,
10234,
12,
465,
282,
4539,
1919,
12,
314,
4248,
31976,
8120,
199,
3,
259,
4983,
370,
2142,
314,
1233,
402,
12468,
402,
642,
2240,
543,
314,
14296,
199,
3,
259,
3555,
14,
199,
3,
259,
2047,
1471,
312,
32236,
314,
1664,
1696,
1684,
844,
315,
1006,
14021,
83,
367,
1006,
402,
199,
3,
259,
314,
1233,
1202,
1163,
2419,
14296,
14,
982,
1265,
2811,
570,
8,
83,
9,
543,
642,
199,
3,
259,
1919,
12,
1265,
1443,
12247,
642,
1919,
370,
2195,
1015,
402,
314,
570,
8,
83,
395,
199,
3,
259,
1325,
1265,
787,
440,
2607,
17506,
972,
370,
886,
880,
14,
982,
1265,
886,
440,
13809,
370,
886,
880,
12,
3145,
199,
3,
259,
642,
1919,
5164,
687,
2195,
1015,
14,
982,
1265,
3145,
642,
1919,
199,
3,
259,
5164,
687,
1006,
1350,
1584,
315,
314,
2240,
12,
2066,
2597,
3145,
652,
2348,
14,
199,
3,
199,
3,
199,
199,
646,
2150,
17730,
14,
3173,
465,
3931,
199,
504,
2150,
17730,
14,
793,
492,
5051,
465,
943,
199,
199,
533,
6763,
2988,
8,
3173,
14,
7004,
304,
272,
347,
636,
826,
721,
277,
304,
267,
3931,
14,
7004,
855,
826,
721,
277,
12,
298,
2390,
2988,
531,
267,
291,
14,
5586,
275,
1052,
339,
347,
8689,
8,
277,
12,
1566,
304,
267,
408,
267,
662,
1147,
83,
314,
1566,
370,
22201,
13431,
14,
398,
520,
635,
1566,
26,
18464,
17730,
2390,
267,
408,
267,
327,
662,
1147,
314,
1566,
370,
314,
22201,
13431,
267,
3931,
14,
362,
480,
8171,
3120,
3471,
8159,
63,
1430,
8,
1430,
9,
267,
327,
6523,
1263,
8297,
367,
314,
1566,
267,
340,
1566,
14,
354,
315,
291,
14,
5586,
26,
288,
367,
3016,
315,
291,
14,
5586,
59,
1430,
14,
354,
2189,
355,
327,
793,
14,
1757,
480,
9602,
3016,
450,
83,
367,
1566,
450,
83,
543,
1249,
26,
450,
83,
401,
1566,
14,
354,
12,
3016,
12,
1566,
14,
589,
9,
355,
862,
26,
490,
3016,
2031,
1430,
14,
589,
9,
355,
871,
2186,
12,
325,
26,
490,
943,
14,
705,
480,
2390,
3016,
450,
83,
3405,
315,
450,
83,
543,
1919,
450,
83,
401,
1566,
14,
354,
12,
3016,
12,
325,
9,
339,
347,
2274,
63,
1430,
63,
2232,
8,
277,
12,
1566,
12,
3016,
304,
267,
408,
267,
5044,
14186,
282,
805,
370,
506,
2797,
1380,
282,
658,
26,
635,
26,
1430,
64,
365,
19515,
14,
398,
520,
635,
1566,
26,
620,
12,
314,
1566,
536,
267,
520,
635,
3016,
26,
805,
12,
370,
506,
2797,
1380,
658,
26,
635,
26,
1430,
64,
365,
19515,
398,
408,
267,
340,
1566,
440,
315,
291,
14,
5586,
26,
288,
291,
14,
5586,
59,
1430,
61,
275,
942,
398,
340,
3016,
440,
315,
291,
14,
5586,
59,
1430,
2189,
288,
291,
14,
5586,
59,
1430,
1055,
740,
8,
2232,
9,
339,
347,
477,
2683,
63,
1430,
63,
2232,
8,
277,
12,
1566,
12,
3016,
304,
267,
408,
267,
1487,
30792,
376,
1566,
3016,
805,
14,
398,
520,
635,
1566,
26,
620,
12,
314,
1566,
536,
267,
520,
635,
3016,
26,
805,
12,
5544,
7264,
370,
2429,
658,
26,
635,
26,
1430,
64,
398,
408,
267,
340,
1566,
315,
291,
14,
5586,
436,
3016,
315,
291,
14,
5586,
59,
1430,
2189,
288,
291,
14,
5586,
59,
1430,
1055,
2168,
8,
2232,
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,
0
] |
[
1,
1,
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/ZenKernel_Angler
|
tools/perf/scripts/python/futex-contention.py
|
11261
|
1486
|
# futex contention
# (c) 2010, Arnaldo Carvalho de Melo <acme@redhat.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Translation of:
#
# http://sourceware.org/systemtap/wiki/WSFutexContention
#
# to perf python scripting.
#
# Measures futex contention
import os, sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from Util import *
process_names = {}
thread_thislock = {}
thread_blocktime = {}
lock_waits = {} # long-lived stats on (tid,lock) blockage elapsed time
process_names = {} # long-lived pid-to-execname mapping
def syscalls__sys_enter_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, uaddr, op, val, utime, uaddr2, val3):
cmd = op & FUTEX_CMD_MASK
if cmd != FUTEX_WAIT:
return # we don't care about originators of WAKE events
process_names[tid] = comm
thread_thislock[tid] = uaddr
thread_blocktime[tid] = nsecs(s, ns)
def syscalls__sys_exit_futex(event, ctxt, cpu, s, ns, tid, comm,
nr, ret):
if thread_blocktime.has_key(tid):
elapsed = nsecs(s, ns) - thread_blocktime[tid]
add_stats(lock_waits, (tid, thread_thislock[tid]), elapsed)
del thread_blocktime[tid]
del thread_thislock[tid]
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
for (tid, lock) in lock_waits:
min, max, avg, count = lock_waits[tid, lock]
print "%s[%d] lock %x contended %d times, %d avg ns" % \
(process_names[tid], tid, lock, count, avg)
|
gpl-2.0
|
[
3,
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
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,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
289,
18173,
406,
9553,
199,
3,
334,
67,
9,
7129,
12,
1952,
78,
279,
1117,
14243,
637,
526,
477,
3194,
320,
665,
18107,
32,
17164,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
25224,
402,
26,
199,
3,
199,
3,
1455,
921,
1365,
1068,
14,
1308,
15,
2253,
16609,
15,
6797,
15,
5035,
38,
18173,
714,
9553,
199,
3,
199,
3,
370,
8582,
2366,
2884,
316,
14,
199,
3,
199,
3,
3194,
305,
1482,
289,
18173,
406,
9553,
199,
199,
646,
747,
12,
984,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
1994,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
504,
21248,
492,
627,
199,
199,
1412,
63,
1247,
275,
1052,
199,
2671,
63,
3749,
831,
275,
1052,
199,
2671,
63,
1457,
521,
275,
1052,
199,
199,
831,
63,
758,
1405,
275,
1052,
327,
1846,
13,
317,
1354,
5020,
641,
334,
5700,
12,
831,
9,
1853,
474,
14439,
900,
199,
1412,
63,
1247,
275,
1052,
327,
1846,
13,
317,
1354,
4422,
13,
475,
13,
1628,
354,
4412,
199,
199,
318,
19473,
363,
1274,
63,
4200,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
420,
14762,
12,
399,
2697,
12,
1687,
12,
1139,
12,
399,
521,
12,
399,
2697,
18,
12,
1139,
19,
304,
199,
198,
1760,
275,
1687,
1253,
481,
934,
1438,
63,
9744,
63,
12880,
199,
198,
692,
2088,
1137,
481,
934,
1438,
63,
12458,
26,
507,
198,
1107,
327,
781,
2793,
1133,
10296,
3595,
6330,
2750,
402,
644,
22339,
4474,
421,
198,
1412,
63,
1247,
59,
5700,
61,
275,
1923,
199,
198,
2671,
63,
3749,
831,
59,
5700,
61,
275,
399,
2697,
199,
198,
2671,
63,
1457,
521,
59,
5700,
61,
275,
13781,
8,
83,
12,
700,
9,
199,
199,
318,
19473,
363,
1274,
63,
2224,
63,
70,
18173,
8,
1430,
12,
11216,
12,
5033,
12,
308,
12,
700,
12,
11559,
12,
1923,
12,
1585,
258,
14762,
12,
2203,
304,
199,
198,
692,
2462,
63,
1457,
521,
14,
1989,
63,
498,
8,
5700,
304,
507,
198,
16691,
275,
13781,
8,
83,
12,
700,
9,
446,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
525,
63,
3200,
8,
831,
63,
758,
1405,
12,
334,
5700,
12,
2462,
63,
3749,
831,
59,
5700,
2522,
14439,
9,
507,
198,
2264,
2462,
63,
1457,
521,
59,
5700,
61,
507,
198,
2264,
2462,
63,
3749,
831,
59,
5700,
61,
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,
509,
334,
5700,
12,
4650,
9,
315,
4650,
63,
758,
1405,
26,
507,
198,
827,
12,
1390,
12,
12402,
12,
2338,
275,
4650,
63,
758,
1405,
59,
5700,
12,
4650,
61,
507,
198,
1361,
2071,
83,
9722,
68,
61,
4650,
450,
88,
406,
6943,
450,
68,
5431,
12,
450,
68,
12402,
700,
2,
450,
971,
686,
420,
334,
1412,
63,
1247,
59,
5700,
467,
11559,
12,
4650,
12,
2338,
12,
12402,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
AlexMathew/csipy-exercises
|
solution/words.py
|
1
|
1277
|
import sys
def setup(words):
new_words = []
for word in words:
new_words.append(word.lower())
words = new_words
# This could have been done easier with list comprehensions.
# words = [word.lower() for word in words]
wordset = set()
wordcount = dict()
for word in words:
prev_size = len(wordset)
wordset.add(word)
new_size = len(wordset)
if new_size > prev_size:
wordcount[word] = words.count(word)
return wordset, wordcount
def main():
if len(sys.argv) == 1 or len(sys.argv) > 2:
print 'FORMAT : python words.py --count|--set'
sys.exit(0)
# This could have been done by using exception handlers for IndexError.
option = sys.argv[1]
if option not in ['--count', '--set']:
print 'FORMAT : python words.py --count|--set'
sys.exit(0)
try:
with open('input.txt', 'r') as f:
text = f.read()
except Exception:
print 'Rename one of the two files there as input.txt'
words = text.split()
wordset, wordcount = setup(words)
if option == '--set':
content = " ".join(sorted(list(wordset)))
with open('output.txt', 'w') as f:
f.write(content)
elif option == '--count':
content = " ".join(sorted(wordcount, key=wordcount.get, reverse=True))
with open('output.txt', 'w') as f:
f.write(content)
if __name__ == '__main__':
main()
|
mit
|
[
646,
984,
199,
199,
318,
3272,
8,
3148,
304,
199,
198,
1222,
63,
3148,
275,
942,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
1222,
63,
3148,
14,
740,
8,
1027,
14,
2325,
1012,
199,
198,
3148,
275,
892,
63,
3148,
199,
198,
3,
961,
4293,
1172,
2757,
4224,
14905,
543,
769,
1013,
22868,
1356,
14,
199,
198,
3,
5932,
275,
359,
1027,
14,
2325,
342,
367,
4349,
315,
5932,
61,
199,
198,
1027,
409,
275,
663,
342,
199,
198,
1027,
835,
275,
1211,
342,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
5701,
63,
890,
275,
822,
8,
1027,
409,
9,
507,
198,
1027,
409,
14,
525,
8,
1027,
9,
507,
198,
1222,
63,
890,
275,
822,
8,
1027,
409,
9,
507,
198,
692,
892,
63,
890,
690,
5071,
63,
890,
26,
686,
198,
1027,
835,
59,
1027,
61,
275,
5932,
14,
835,
8,
1027,
9,
199,
198,
1107,
4349,
409,
12,
4349,
835,
199,
199,
318,
2446,
837,
199,
198,
692,
822,
8,
1274,
14,
3020,
9,
508,
413,
503,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
507,
198,
1361,
283,
4807,
520,
2366,
5932,
14,
647,
1553,
835,
92,
306,
409,
7,
507,
198,
1274,
14,
2224,
8,
16,
9,
199,
198,
3,
961,
4293,
1172,
2757,
4224,
701,
1808,
1919,
8297,
367,
7888,
14,
9948,
198,
1422,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
692,
945,
440,
315,
14574,
835,
297,
2850,
409,
2565,
507,
198,
1361,
283,
4807,
520,
2366,
5932,
14,
647,
1553,
835,
92,
306,
409,
7,
507,
198,
1274,
14,
2224,
8,
16,
9,
199,
198,
893,
26,
507,
198,
1045,
1551,
360,
1210,
14,
2424,
297,
283,
82,
358,
465,
289,
26,
686,
198,
505,
275,
289,
14,
739,
342,
199,
198,
2590,
2186,
26,
507,
198,
1361,
283,
16843,
1373,
402,
314,
2877,
1584,
2337,
465,
1324,
14,
2424,
7,
199,
198,
3148,
275,
1318,
14,
1294,
342,
199,
198,
1027,
409,
12,
4349,
835,
275,
3272,
8,
3148,
9,
199,
198,
692,
945,
508,
2850,
409,
356,
507,
198,
1317,
275,
298,
3680,
904,
8,
5917,
8,
513,
8,
1027,
409,
1724,
507,
198,
1045,
1551,
360,
1199,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
686,
198,
70,
14,
952,
8,
1317,
9,
199,
198,
4164,
945,
508,
2850,
835,
356,
507,
198,
1317,
275,
298,
3680,
904,
8,
5917,
8,
1027,
835,
12,
790,
29,
1027,
835,
14,
362,
12,
3837,
29,
549,
430,
507,
198,
1045,
1551,
360,
1199,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
686,
198,
70,
14,
952,
8,
1317,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
973,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
984,
199,
199,
318,
3272,
8,
3148,
304,
199,
198,
1222,
63,
3148,
275,
942,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
1222,
63,
3148,
14,
740,
8,
1027,
14,
2325,
1012,
199,
198,
3148,
275,
892,
63,
3148,
199,
198,
3,
961,
4293,
1172,
2757,
4224,
14905,
543,
769,
1013,
22868,
1356,
14,
199,
198,
3,
5932,
275,
359,
1027,
14,
2325,
342,
367,
4349,
315,
5932,
61,
199,
198,
1027,
409,
275,
663,
342,
199,
198,
1027,
835,
275,
1211,
342,
199,
198,
509,
4349,
315,
5932,
26,
507,
198,
5701,
63,
890,
275,
822,
8,
1027,
409,
9,
507,
198,
1027,
409,
14,
525,
8,
1027,
9,
507,
198,
1222,
63,
890,
275,
822,
8,
1027,
409,
9,
507,
198,
692,
892,
63,
890,
690,
5071,
63,
890,
26,
686,
198,
1027,
835,
59,
1027,
61,
275,
5932,
14,
835,
8,
1027,
9,
199,
198,
1107,
4349,
409,
12,
4349,
835,
199,
199,
318,
2446,
837,
199,
198,
692,
822,
8,
1274,
14,
3020,
9,
508,
413,
503,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
507,
198,
1361,
283,
4807,
520,
2366,
5932,
14,
647,
1553,
835,
92,
306,
409,
7,
507,
198,
1274,
14,
2224,
8,
16,
9,
199,
198,
3,
961,
4293,
1172,
2757,
4224,
701,
1808,
1919,
8297,
367,
7888,
14,
9948,
198,
1422,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
692,
945,
440,
315,
14574,
835,
297,
2850,
409,
2565,
507,
198,
1361,
283,
4807,
520,
2366,
5932,
14,
647,
1553,
835,
92,
306,
409,
7,
507,
198,
1274,
14,
2224,
8,
16,
9,
199,
198,
893,
26,
507,
198,
1045,
1551,
360,
1210,
14,
2424,
297,
283,
82,
358,
465,
289,
26,
686,
198,
505,
275,
289,
14,
739,
342,
199,
198,
2590,
2186,
26,
507,
198,
1361,
283,
16843,
1373,
402,
314,
2877,
1584,
2337,
465,
1324,
14,
2424,
7,
199,
198,
3148,
275,
1318,
14,
1294,
342,
199,
198,
1027,
409,
12,
4349,
835,
275,
3272,
8,
3148,
9,
199,
198,
692,
945,
508,
2850,
409,
356,
507,
198,
1317,
275,
298,
3680,
904,
8,
5917,
8,
513,
8,
1027,
409,
1724,
507,
198,
1045,
1551,
360,
1199,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
686,
198,
70,
14,
952,
8,
1317,
9,
199,
198,
4164,
945,
508,
2850,
835,
356,
507,
198,
1317,
275,
298,
3680,
904,
8,
5917,
8,
1027,
835,
12,
790,
29,
1027,
835,
14,
362,
12,
3837,
29,
549,
430,
507,
198,
1045,
1551,
360,
1199,
14,
2424,
297,
283,
87,
358,
465,
289,
26,
686,
198,
70,
14,
952,
8,
1317,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
199,
198,
973,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,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at
|
classifier/classifier.py
|
1
|
4355
|
#!/usr/bin/env python
"""
Author : tharindra galahena (inf0_warri0r)
Project: classifing music using neural network
Blog : http://www.inf0warri0r.blogspot.com
Date : 23/05/2013
License:
Copyright 2013 Tharindra Galahena
This 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 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. If not, see http://www.gnu.org/licenses/.
"""
from PySide import QtCore, QtGui
from classify import Ui_classifier
import os
import sys
import file_read
import histograme
import thread
import neural_net
import plot
class MyWidget(QtGui.QMainWindow, Ui_classifier):
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
self.setupUi(self)
self.file_name = ""
self.hist_u = list()
self.hist_n = list()
self.net = neural_net.neural(10, 1, 3, 15, 0.001, 0.0)
self.net.init()
self.net.put_weights(self.load())
self.img = ""
self.convert.clicked.connect(self.convert_file)
self.classify.clicked.connect(self.classify_func)
self.browse.clicked.connect(self.browse_func)
self.hist_lable.setScaledContents(True)
self.run = True
self.timer = QtCore.QTimer()
self.timer.setInterval(1000)
self.timer.timeout.connect(self.re_draw)
self.timer.start()
def browse_func(self):
fname, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
self.music_file.setText(str(fname))
def re_draw(self):
if not self.run:
QtGui.QMessageBox.about(self, "Done", "Done !!!")
self.run = True
return 0
def convert_file(self):
r, w = os.pipe()
self.file_name = self.music_file.text()
if self.file_name == "":
QtGui.QMessageBox.about(self, "ERROR", "invaild file")
return 0
pid = os.fork()
if pid:
os.waitpid(pid, 0)
else:
os.execlp("ffmpeg", "ffmpeg", "-i",
self.file_name, "-y", "out.aif")
exit(0)
try:
thread.start_new_thread(self.thread_func, ())
except Exception:
QtGui.QMessageBox.about(self, "ERROR", "thread error")
def thread_func(self):
self.run = True
f = file_read.file_read(("out.aif", "out.aif"))
f.convert()
f.save("./")
self.image = f.image
h = histograme.histograme(f.image)
h.create_histograme()
self.hist_u = h.unnormaliced_histograme()
self.hist_n = h.normalice_histograme()
print "done"
self.run = False
def classify_func(self):
p = plot.plot(self.hist_u, 600, 400, (256, 125, 0), (256, 256, 256))
p.set_scales()
p.set_plot()
p.draw("hist.jpg")
qimage = QtGui.QImage("out.aif.jpg")
pix = QtGui.QPixmap.fromImage(qimage)
self.label.setPixmap(pix)
qimage = QtGui.QImage("hist.jpg")
pix = QtGui.QPixmap.fromImage(qimage)
self.hist_lable.setPixmap(pix)
try:
thread.start_new_thread(self.thread_func2, ())
except Exception:
QtGui.QMessageBox.about(self, "ERROR", "thread error")
def thread_func2(self):
print self.hist_n
out = self.net.update(self.hist_n)
print out
self.gener.setText("")
if out[0] < 0.5:
self.type = "Rock"
else:
self.type = "Classic"
self.gener.setText(self.type)
def load(self):
f = open('weights', 'r')
cat = f.read()
f.close()
weights = list()
lst = cat.splitlines()
for i in range(0, len(lst)):
weights.append(float(lst[i]))
return weights
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = MyWidget()
window.show()
sys.exit(app.exec_())
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
5949,
520,
294,
285,
688,
345,
486,
279,
11326,
287,
65,
334,
4904,
16,
63,
3281,
322,
16,
82,
9,
199,
4761,
26,
11534,
70,
316,
30891,
1808,
1279,
4889,
2784,
199,
26081,
257,
520,
1455,
921,
1544,
14,
4904,
16,
3281,
322,
16,
82,
14,
66,
7270,
14173,
14,
957,
199,
2506,
257,
520,
6546,
15,
1717,
15,
6965,
199,
3761,
26,
10813,
1898,
6171,
3868,
285,
688,
345,
598,
279,
11326,
287,
65,
199,
199,
2765,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
1589,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
30216,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
1023,
14,
961,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
29946,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
38,
3061,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
5087,
14,
199,
199,
10,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3749,
14,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
199,
624,
199,
199,
504,
1611,
15414,
492,
10565,
12,
5928,
199,
504,
28837,
492,
32471,
63,
14720,
199,
646,
747,
199,
646,
984,
199,
646,
570,
63,
739,
199,
646,
13612,
974,
1186,
199,
646,
2462,
199,
646,
1279,
4889,
63,
846,
199,
646,
5137,
421,
199,
533,
4932,
3339,
8,
10604,
14,
49,
16031,
12,
32471,
63,
14720,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
8,
5713,
3339,
12,
291,
2843,
826,
721,
1708,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
267,
291,
14,
493,
63,
354,
275,
3087,
267,
291,
14,
11141,
63,
85,
275,
769,
342,
267,
291,
14,
11141,
63,
78,
275,
769,
342,
267,
291,
14,
846,
275,
1279,
4889,
63,
846,
14,
685,
4889,
8,
709,
12,
413,
12,
650,
12,
4114,
12,
378,
14,
4587,
12,
378,
14,
16,
9,
267,
291,
14,
846,
14,
826,
342,
267,
291,
14,
846,
14,
524,
63,
4916,
8,
277,
14,
912,
1012,
398,
291,
14,
4060,
275,
3087,
398,
291,
14,
3916,
14,
11276,
14,
2242,
8,
277,
14,
3916,
63,
493,
9,
267,
291,
14,
12334,
1399,
14,
11276,
14,
2242,
8,
277,
14,
12334,
1399,
63,
1532,
9,
267,
291,
14,
4570,
14,
11276,
14,
2242,
8,
277,
14,
4570,
63,
1532,
9,
267,
291,
14,
11141,
63,
76,
461,
14,
409,
18269,
1146,
11383,
8,
549,
9,
267,
291,
14,
1065,
275,
715,
267,
291,
14,
7414,
275,
10565,
14,
49,
7929,
342,
267,
291,
14,
7414,
14,
409,
8227,
8,
5279,
9,
267,
291,
14,
7414,
14,
2593,
14,
2242,
8,
277,
14,
264,
63,
5485,
9,
267,
291,
14,
7414,
14,
928,
342,
339,
347,
19249,
63,
1532,
8,
277,
304,
267,
6748,
12,
485,
275,
5928,
14,
49,
25213,
14,
362,
4299,
7733,
8,
277,
12,
283,
4299,
570,
358,
398,
291,
14,
20544,
63,
493,
14,
8341,
8,
495,
8,
5252,
430,
339,
347,
295,
63,
5485,
8,
277,
304,
267,
340,
440,
291,
14,
1065,
26,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
10759,
401,
298,
10759,
221,
3480,
9124,
288,
291,
14,
1065,
275,
715,
288,
372,
378,
339,
347,
3957,
63,
493,
8,
277,
304,
267,
519,
12,
336,
275,
747,
14,
4990,
342,
267,
291,
14,
493,
63,
354,
275,
291,
14,
20544,
63,
493,
14,
505,
342,
267,
340,
291,
14,
493,
63,
354,
508,
10812,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
3170,
401,
298,
262,
3042,
668,
570,
531,
288,
372,
378,
267,
4422,
275,
747,
14,
11796,
342,
267,
340,
4422,
26,
288,
747,
14,
2573,
3150,
8,
3150,
12,
378,
9,
267,
587,
26,
288,
747,
14,
5803,
429,
80,
480,
27648,
401,
298,
27648,
401,
3905,
73,
401,
355,
291,
14,
493,
63,
354,
12,
3905,
89,
401,
298,
548,
14,
65,
692,
531,
288,
4458,
8,
16,
9,
398,
862,
26,
288,
2462,
14,
928,
63,
1222,
63,
2671,
8,
277,
14,
2671,
63,
1532,
12,
14515,
267,
871,
2186,
26,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
3170,
401,
298,
2671,
1125,
531,
339,
347,
2462,
63,
1532,
8,
277,
304,
267,
291,
14,
1065,
275,
715,
267,
289,
275,
570,
63,
739,
14,
493,
63,
739,
9313,
548,
14,
65,
692,
401,
298,
548,
14,
65,
692,
2237,
267,
289,
14,
3916,
342,
267,
289,
14,
2117,
9520,
13589,
267,
291,
14,
1569,
275,
289,
14,
1569,
398,
394,
275,
13612,
974,
1186,
14,
11141,
974,
1186,
8,
70,
14,
1569,
9,
267,
394,
14,
981,
63,
11141,
974,
1186,
342,
267,
291,
14,
11141,
63,
85,
275,
394,
14,
324,
3302,
1885,
68,
63,
11141,
974,
1186,
342,
267,
291,
14,
11141,
63,
78,
275,
394,
14,
3302,
1885,
63,
11141,
974,
1186,
342,
398,
870,
298,
4456,
2,
267,
291,
14,
1065,
275,
756,
339,
347,
28837,
63,
1532,
8,
277,
304,
398,
299,
275,
5137,
14,
2798,
8,
277,
14,
11141,
63,
85,
12,
11624,
12,
8290,
12,
334,
3912,
12,
19163,
12,
378,
395,
334,
3912,
12,
7633,
12,
7633,
430,
267,
299,
14,
409,
63,
30832,
342,
267,
299,
14,
409,
63,
2798,
342,
267,
299,
14,
5485,
480,
11141,
14,
8476,
531,
398,
1894,
1569,
275,
5928,
14,
49,
3491,
480,
548,
14,
65,
692,
14,
8476,
531,
267,
25505,
275,
5928,
14,
49,
16049,
14,
504,
3491,
8,
81,
1569,
9,
267,
291,
14,
1302,
14,
409,
16049,
8,
6644,
9,
398,
1894,
1569,
275,
5928,
14,
49,
3491,
480,
11141,
14,
8476,
531,
267,
25505,
275,
5928,
14,
49,
16049,
14,
504,
3491,
8,
81,
1569,
9,
267,
291,
14,
11141,
63,
76,
461,
14,
409,
16049,
8,
6644,
9,
398,
862,
26,
288,
2462,
14,
928,
63,
1222,
63,
2671,
8,
277
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
5949,
520,
294,
285,
688,
345,
486,
279,
11326,
287,
65,
334,
4904,
16,
63,
3281,
322,
16,
82,
9,
199,
4761,
26,
11534,
70,
316,
30891,
1808,
1279,
4889,
2784,
199,
26081,
257,
520,
1455,
921,
1544,
14,
4904,
16,
3281,
322,
16,
82,
14,
66,
7270,
14173,
14,
957,
199,
2506,
257,
520,
6546,
15,
1717,
15,
6965,
199,
3761,
26,
10813,
1898,
6171,
3868,
285,
688,
345,
598,
279,
11326,
287,
65,
199,
199,
2765,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
1589,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
30216,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
1023,
14,
961,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
29946,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
199,
38,
3061,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
5087,
14,
199,
199,
10,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3749,
14,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
8083,
199,
199,
624,
199,
199,
504,
1611,
15414,
492,
10565,
12,
5928,
199,
504,
28837,
492,
32471,
63,
14720,
199,
646,
747,
199,
646,
984,
199,
646,
570,
63,
739,
199,
646,
13612,
974,
1186,
199,
646,
2462,
199,
646,
1279,
4889,
63,
846,
199,
646,
5137,
421,
199,
533,
4932,
3339,
8,
10604,
14,
49,
16031,
12,
32471,
63,
14720,
304,
272,
347,
636,
826,
721,
277,
12,
1676,
29,
403,
304,
267,
1613,
8,
5713,
3339,
12,
291,
2843,
826,
721,
1708,
9,
267,
291,
14,
2758,
18203,
8,
277,
9,
267,
291,
14,
493,
63,
354,
275,
3087,
267,
291,
14,
11141,
63,
85,
275,
769,
342,
267,
291,
14,
11141,
63,
78,
275,
769,
342,
267,
291,
14,
846,
275,
1279,
4889,
63,
846,
14,
685,
4889,
8,
709,
12,
413,
12,
650,
12,
4114,
12,
378,
14,
4587,
12,
378,
14,
16,
9,
267,
291,
14,
846,
14,
826,
342,
267,
291,
14,
846,
14,
524,
63,
4916,
8,
277,
14,
912,
1012,
398,
291,
14,
4060,
275,
3087,
398,
291,
14,
3916,
14,
11276,
14,
2242,
8,
277,
14,
3916,
63,
493,
9,
267,
291,
14,
12334,
1399,
14,
11276,
14,
2242,
8,
277,
14,
12334,
1399,
63,
1532,
9,
267,
291,
14,
4570,
14,
11276,
14,
2242,
8,
277,
14,
4570,
63,
1532,
9,
267,
291,
14,
11141,
63,
76,
461,
14,
409,
18269,
1146,
11383,
8,
549,
9,
267,
291,
14,
1065,
275,
715,
267,
291,
14,
7414,
275,
10565,
14,
49,
7929,
342,
267,
291,
14,
7414,
14,
409,
8227,
8,
5279,
9,
267,
291,
14,
7414,
14,
2593,
14,
2242,
8,
277,
14,
264,
63,
5485,
9,
267,
291,
14,
7414,
14,
928,
342,
339,
347,
19249,
63,
1532,
8,
277,
304,
267,
6748,
12,
485,
275,
5928,
14,
49,
25213,
14,
362,
4299,
7733,
8,
277,
12,
283,
4299,
570,
358,
398,
291,
14,
20544,
63,
493,
14,
8341,
8,
495,
8,
5252,
430,
339,
347,
295,
63,
5485,
8,
277,
304,
267,
340,
440,
291,
14,
1065,
26,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
10759,
401,
298,
10759,
221,
3480,
9124,
288,
291,
14,
1065,
275,
715,
288,
372,
378,
339,
347,
3957,
63,
493,
8,
277,
304,
267,
519,
12,
336,
275,
747,
14,
4990,
342,
267,
291,
14,
493,
63,
354,
275,
291,
14,
20544,
63,
493,
14,
505,
342,
267,
340,
291,
14,
493,
63,
354,
508,
10812,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
3170,
401,
298,
262,
3042,
668,
570,
531,
288,
372,
378,
267,
4422,
275,
747,
14,
11796,
342,
267,
340,
4422,
26,
288,
747,
14,
2573,
3150,
8,
3150,
12,
378,
9,
267,
587,
26,
288,
747,
14,
5803,
429,
80,
480,
27648,
401,
298,
27648,
401,
3905,
73,
401,
355,
291,
14,
493,
63,
354,
12,
3905,
89,
401,
298,
548,
14,
65,
692,
531,
288,
4458,
8,
16,
9,
398,
862,
26,
288,
2462,
14,
928,
63,
1222,
63,
2671,
8,
277,
14,
2671,
63,
1532,
12,
14515,
267,
871,
2186,
26,
288,
5928,
14,
30798,
14,
10254,
8,
277,
12,
298,
3170,
401,
298,
2671,
1125,
531,
339,
347,
2462,
63,
1532,
8,
277,
304,
267,
291,
14,
1065,
275,
715,
267,
289,
275,
570,
63,
739,
14,
493,
63,
739,
9313,
548,
14,
65,
692,
401,
298,
548,
14,
65,
692,
2237,
267,
289,
14,
3916,
342,
267,
289,
14,
2117,
9520,
13589,
267,
291,
14,
1569,
275,
289,
14,
1569,
398,
394,
275,
13612,
974,
1186,
14,
11141,
974,
1186,
8,
70,
14,
1569,
9,
267,
394,
14,
981,
63,
11141,
974,
1186,
342,
267,
291,
14,
11141,
63,
85,
275,
394,
14,
324,
3302,
1885,
68,
63,
11141,
974,
1186,
342,
267,
291,
14,
11141,
63,
78,
275,
394,
14,
3302,
1885,
63,
11141,
974,
1186,
342,
398,
870,
298,
4456,
2,
267,
291,
14,
1065,
275,
756,
339,
347,
28837,
63,
1532,
8,
277,
304,
398,
299,
275,
5137,
14,
2798,
8,
277,
14,
11141,
63,
85,
12,
11624,
12,
8290,
12,
334,
3912,
12,
19163,
12,
378,
395,
334,
3912,
12,
7633,
12,
7633,
430,
267,
299,
14,
409,
63,
30832,
342,
267,
299,
14,
409,
63,
2798,
342,
267,
299,
14,
5485,
480,
11141,
14,
8476,
531,
398,
1894,
1569,
275,
5928,
14,
49,
3491,
480,
548,
14,
65,
692,
14,
8476,
531,
267,
25505,
275,
5928,
14,
49,
16049,
14,
504,
3491,
8,
81,
1569,
9,
267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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
] |
unseenlaser/python-for-android
|
python3-alpha/python3-src/Lib/ctypes/test/test_numbers.py
|
45
|
8794
|
from ctypes import *
import unittest
import struct
def valid_ranges(*types):
# given a sequence of numeric types, collect their _type_
# attribute, which is a single format character compatible with
# the struct module, use the struct module to calculate the
# minimum and maximum value allowed for this format.
# Returns a list of (min, max) values.
result = []
for t in types:
fmt = t._type_
size = struct.calcsize(fmt)
a = struct.unpack(fmt, (b"\x00"*32)[:size])[0]
b = struct.unpack(fmt, (b"\xFF"*32)[:size])[0]
c = struct.unpack(fmt, (b"\x7F"+b"\x00"*32)[:size])[0]
d = struct.unpack(fmt, (b"\x80"+b"\xFF"*32)[:size])[0]
result.append((min(a, b, c, d), max(a, b, c, d)))
return result
ArgType = type(byref(c_int(0)))
unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong]
signed_types = [c_byte, c_short, c_int, c_long, c_longlong]
bool_types = []
float_types = [c_double, c_float]
try:
c_ulonglong
c_longlong
except NameError:
pass
else:
unsigned_types.append(c_ulonglong)
signed_types.append(c_longlong)
try:
c_bool
except NameError:
pass
else:
bool_types.append(c_bool)
unsigned_ranges = valid_ranges(*unsigned_types)
signed_ranges = valid_ranges(*signed_types)
bool_values = [True, False, 0, 1, -1, 5000, 'test', [], [1]]
################################################################
class NumberTestCase(unittest.TestCase):
def test_default_init(self):
# default values are set to zero
for t in signed_types + unsigned_types + float_types:
self.assertEqual(t().value, 0)
def test_unsigned_values(self):
# the value given to the constructor is available
# as the 'value' attribute
for t, (l, h) in zip(unsigned_types, unsigned_ranges):
self.assertEqual(t(l).value, l)
self.assertEqual(t(h).value, h)
def test_signed_values(self):
# see above
for t, (l, h) in zip(signed_types, signed_ranges):
self.assertEqual(t(l).value, l)
self.assertEqual(t(h).value, h)
def test_bool_values(self):
from operator import truth
for t, v in zip(bool_types, bool_values):
self.assertEqual(t(v).value, truth(v))
def test_typeerror(self):
# Only numbers are allowed in the contructor,
# otherwise TypeError is raised
for t in signed_types + unsigned_types + float_types:
self.assertRaises(TypeError, t, "")
self.assertRaises(TypeError, t, None)
## def test_valid_ranges(self):
## # invalid values of the correct type
## # raise ValueError (not OverflowError)
## for t, (l, h) in zip(unsigned_types, unsigned_ranges):
## self.assertRaises(ValueError, t, l-1)
## self.assertRaises(ValueError, t, h+1)
def test_from_param(self):
# the from_param class method attribute always
# returns PyCArgObject instances
for t in signed_types + unsigned_types + float_types:
self.assertEqual(ArgType, type(t.from_param(0)))
def test_byref(self):
# calling byref returns also a PyCArgObject instance
for t in signed_types + unsigned_types + float_types + bool_types:
parm = byref(t())
self.assertEqual(ArgType, type(parm))
def test_floats(self):
# c_float and c_double can be created from
# Python int, long and float
class FloatLike(object):
def __float__(self):
return 2.0
f = FloatLike()
for t in float_types:
self.assertEqual(t(2.0).value, 2.0)
self.assertEqual(t(2).value, 2.0)
self.assertEqual(t(2).value, 2.0)
self.assertEqual(t(f).value, 2.0)
def test_integers(self):
class FloatLike(object):
def __float__(self):
return 2.0
f = FloatLike()
class IntLike(object):
def __int__(self):
return 2
i = IntLike()
# integers cannot be constructed from floats,
# but from integer-like objects
for t in signed_types + unsigned_types:
self.assertRaises(TypeError, t, 3.14)
self.assertRaises(TypeError, t, f)
self.assertEqual(t(i).value, 2)
def test_sizes(self):
for t in signed_types + unsigned_types + float_types + bool_types:
try:
size = struct.calcsize(t._type_)
except struct.error:
continue
# sizeof of the type...
self.assertEqual(sizeof(t), size)
# and sizeof of an instance
self.assertEqual(sizeof(t()), size)
def test_alignments(self):
for t in signed_types + unsigned_types + float_types:
code = t._type_ # the typecode
align = struct.calcsize("c%c" % code) - struct.calcsize(code)
# alignment of the type...
self.assertEqual((code, alignment(t)),
(code, align))
# and alignment of an instance
self.assertEqual((code, alignment(t())),
(code, align))
def test_int_from_address(self):
from array import array
for t in signed_types + unsigned_types:
# the array module doesn't support all format codes
# (no 'q' or 'Q')
try:
array(t._type_)
except ValueError:
continue
a = array(t._type_, [100])
# v now is an integer at an 'external' memory location
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
self.assertEqual(type(v), t)
# changing the value at the memory location changes v's value also
a[0] = 42
self.assertEqual(v.value, a[0])
def test_float_from_address(self):
from array import array
for t in float_types:
a = array(t._type_, [3.14])
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
self.assertTrue(type(v) is t)
a[0] = 2.3456e17
self.assertEqual(v.value, a[0])
self.assertTrue(type(v) is t)
def test_char_from_address(self):
from ctypes import c_char
from array import array
a = array('b', [0])
a[0] = ord('x')
v = c_char.from_address(a.buffer_info()[0])
self.assertEqual(v.value, b'x')
self.assertTrue(type(v) is c_char)
a[0] = ord('?')
self.assertEqual(v.value, b'?')
# array does not support c_bool / 't'
# def test_bool_from_address(self):
# from ctypes import c_bool
# from array import array
# a = array(c_bool._type_, [True])
# v = t.from_address(a.buffer_info()[0])
# self.assertEqual(v.value, a[0])
# self.assertEqual(type(v) is t)
# a[0] = False
# self.assertEqual(v.value, a[0])
# self.assertEqual(type(v) is t)
def test_init(self):
# c_int() can be initialized from Python's int, and c_int.
# Not from c_long or so, which seems strange, abd should
# probably be changed:
self.assertRaises(TypeError, c_int, c_long(42))
## def test_perf(self):
## check_perf()
from ctypes import _SimpleCData
class c_int_S(_SimpleCData):
_type_ = "i"
__slots__ = []
def run_test(rep, msg, func, arg=None):
## items = [None] * rep
items = range(rep)
from time import clock
if arg is not None:
start = clock()
for i in items:
func(arg); func(arg); func(arg); func(arg); func(arg)
stop = clock()
else:
start = clock()
for i in items:
func(); func(); func(); func(); func()
stop = clock()
print("%15s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))
def check_perf():
# Construct 5 objects
from ctypes import c_int
REP = 200000
run_test(REP, "int()", int)
run_test(REP, "int(999)", int)
run_test(REP, "c_int()", c_int)
run_test(REP, "c_int(999)", c_int)
run_test(REP, "c_int_S()", c_int_S)
run_test(REP, "c_int_S(999)", c_int_S)
# Python 2.3 -OO, win2k, P4 700 MHz:
#
# int(): 0.87 us
# int(999): 0.87 us
# c_int(): 3.35 us
# c_int(999): 3.34 us
# c_int_S(): 3.23 us
# c_int_S(999): 3.24 us
# Python 2.2 -OO, win2k, P4 700 MHz:
#
# int(): 0.89 us
# int(999): 0.89 us
# c_int(): 9.99 us
# c_int(999): 10.02 us
# c_int_S(): 9.87 us
# c_int_S(999): 9.85 us
if __name__ == '__main__':
## check_perf()
unittest.main()
|
apache-2.0
|
[
504,
5577,
492,
627,
199,
646,
2882,
199,
646,
2702,
199,
199,
318,
1686,
63,
8404,
2031,
1313,
304,
272,
327,
1627,
282,
3414,
402,
8950,
2943,
12,
8775,
3932,
485,
466,
63,
272,
327,
2225,
12,
1314,
365,
282,
2849,
1475,
4528,
9025,
543,
272,
327,
314,
2702,
859,
12,
675,
314,
2702,
859,
370,
8671,
314,
272,
327,
7481,
436,
5696,
574,
4370,
367,
642,
1475,
14,
272,
327,
1803,
282,
769,
402,
334,
827,
12,
1390,
9,
1338,
14,
272,
754,
275,
942,
272,
367,
307,
315,
2943,
26,
267,
7104,
275,
307,
423,
466,
63,
267,
1568,
275,
2702,
14,
21691,
8,
5045,
9,
267,
282,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
383,
31761,
708,
18562,
890,
11057,
16,
61,
267,
330,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
9039,
31761,
708,
18562,
890,
11057,
16,
61,
267,
286,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
23,
38,
7709,
66,
3212,
88,
383,
31761,
708,
18562,
890,
11057,
16,
61,
267,
366,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
1257,
7709,
66,
3212,
9039,
31761,
708,
18562,
890,
11057,
16,
61,
267,
754,
14,
740,
1332,
827,
8,
65,
12,
330,
12,
286,
12,
366,
395,
1390,
8,
65,
12,
330,
12,
286,
12,
366,
1724,
272,
372,
754,
199,
199,
6373,
804,
275,
730,
8,
20447,
8,
67,
63,
442,
8,
16,
1724,
199,
199,
2244,
63,
1313,
275,
359,
67,
63,
20790,
12,
286,
63,
27170,
12,
286,
63,
1635,
12,
286,
63,
15688,
61,
199,
1737,
63,
1313,
275,
359,
67,
63,
4414,
12,
286,
63,
3612,
12,
286,
63,
442,
12,
286,
63,
2809,
12,
286,
63,
2809,
2809,
61,
199,
199,
2245,
63,
1313,
275,
942,
199,
199,
1609,
63,
1313,
275,
359,
67,
63,
3157,
12,
286,
63,
1609,
61,
199,
199,
893,
26,
272,
286,
63,
32020,
272,
286,
63,
2809,
2809,
199,
2590,
12746,
26,
272,
986,
199,
2836,
26,
272,
7381,
63,
1313,
14,
740,
8,
67,
63,
32020,
9,
272,
10514,
63,
1313,
14,
740,
8,
67,
63,
2809,
2809,
9,
199,
199,
893,
26,
272,
286,
63,
2245,
199,
2590,
12746,
26,
272,
986,
199,
2836,
26,
272,
2155,
63,
1313,
14,
740,
8,
67,
63,
2245,
9,
199,
199,
2244,
63,
8404,
275,
1686,
63,
8404,
2031,
2244,
63,
1313,
9,
199,
1737,
63,
8404,
275,
1686,
63,
8404,
2031,
1737,
63,
1313,
9,
199,
2245,
63,
1459,
275,
359,
549,
12,
756,
12,
378,
12,
413,
12,
446,
17,
12,
22369,
12,
283,
396,
297,
990,
359,
17,
2677,
199,
199,
3060,
199,
199,
533,
4860,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
885,
63,
826,
8,
277,
304,
267,
327,
849,
1338,
787,
663,
370,
4697,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
84,
1252,
585,
12,
378,
9,
339,
347,
511,
63,
2244,
63,
1459,
8,
277,
304,
267,
327,
314,
574,
1627,
370,
314,
3787,
365,
2808,
267,
327,
465,
314,
283,
585,
7,
2225,
267,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
2244,
63,
1313,
12,
7381,
63,
8404,
304,
288,
291,
14,
629,
8,
84,
8,
76,
680,
585,
12,
634,
9,
288,
291,
14,
629,
8,
84,
8,
72,
680,
585,
12,
394,
9,
339,
347,
511,
63,
1737,
63,
1459,
8,
277,
304,
267,
327,
1937,
3432,
267,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
1737,
63,
1313,
12,
10514,
63,
8404,
304,
288,
291,
14,
629,
8,
84,
8,
76,
680,
585,
12,
634,
9,
288,
291,
14,
629,
8,
84,
8,
72,
680,
585,
12,
394,
9,
339,
347,
511,
63,
2245,
63,
1459,
8,
277,
304,
267,
687,
4182,
492,
16865,
267,
367,
307,
12,
373,
315,
3482,
8,
2245,
63,
1313,
12,
2155,
63,
1459,
304,
288,
291,
14,
629,
8,
84,
8,
86,
680,
585,
12,
16865,
8,
86,
430,
339,
347,
511,
63,
466,
705,
8,
277,
304,
267,
327,
5972,
5579,
787,
4370,
315,
314,
406,
454,
85,
630,
12,
267,
327,
4257,
3146,
365,
4915,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
1855,
8,
4333,
12,
307,
12,
6899,
288,
291,
14,
1855,
8,
4333,
12,
307,
12,
488,
9,
199,
199,
309,
259,
347,
511,
63,
1078,
63,
8404,
8,
277,
304,
199,
309,
263,
327,
3866,
1338,
402,
314,
3211,
730,
199,
309,
263,
327,
746,
1722,
334,
1397,
23870,
9,
199,
309,
263,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
2244,
63,
1313,
12,
7381,
63,
8404,
304,
199,
309,
3322,
291,
14,
1855,
8,
3393,
12,
307,
12,
634,
13,
17,
9,
199,
309,
3322,
291,
14,
1855,
8,
3393,
12,
307,
12,
394,
11,
17,
9,
339,
347,
511,
63,
504,
63,
635,
8,
277,
304,
267,
327,
314,
687,
63,
635,
1021,
1083,
2225,
3544,
267,
327,
2529,
1611,
35,
6373,
1692,
4454,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
6373,
804,
12,
730,
8,
84,
14,
504,
63,
635,
8,
16,
1724,
339,
347,
511,
63,
20447,
8,
277,
304,
267,
327,
6358,
15968,
2529,
2597,
282,
1611,
35,
6373,
1692,
1256,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
435,
2155,
63,
1313,
26,
288,
623,
77,
275,
15968,
8,
84,
1012,
288,
291,
14,
629,
8,
6373,
804,
12,
730,
8,
22176,
430,
2378,
347,
511,
63,
1609,
83,
8,
277,
304,
267,
327,
286,
63,
1609,
436,
286,
63,
3157,
883,
506,
2737,
687,
267,
327,
2018,
1109,
12,
1846,
436,
2069,
267,
1021,
11140,
12545,
8,
785,
304,
288,
347,
636,
1609,
721,
277,
304,
355,
372,
499,
14,
16,
267,
289,
275,
11140,
12545,
342,
267,
367,
307,
315,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
84,
8,
18,
14
] |
[
5577,
492,
627,
199,
646,
2882,
199,
646,
2702,
199,
199,
318,
1686,
63,
8404,
2031,
1313,
304,
272,
327,
1627,
282,
3414,
402,
8950,
2943,
12,
8775,
3932,
485,
466,
63,
272,
327,
2225,
12,
1314,
365,
282,
2849,
1475,
4528,
9025,
543,
272,
327,
314,
2702,
859,
12,
675,
314,
2702,
859,
370,
8671,
314,
272,
327,
7481,
436,
5696,
574,
4370,
367,
642,
1475,
14,
272,
327,
1803,
282,
769,
402,
334,
827,
12,
1390,
9,
1338,
14,
272,
754,
275,
942,
272,
367,
307,
315,
2943,
26,
267,
7104,
275,
307,
423,
466,
63,
267,
1568,
275,
2702,
14,
21691,
8,
5045,
9,
267,
282,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
383,
31761,
708,
18562,
890,
11057,
16,
61,
267,
330,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
9039,
31761,
708,
18562,
890,
11057,
16,
61,
267,
286,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
23,
38,
7709,
66,
3212,
88,
383,
31761,
708,
18562,
890,
11057,
16,
61,
267,
366,
275,
2702,
14,
5301,
8,
5045,
12,
334,
66,
3212,
88,
1257,
7709,
66,
3212,
9039,
31761,
708,
18562,
890,
11057,
16,
61,
267,
754,
14,
740,
1332,
827,
8,
65,
12,
330,
12,
286,
12,
366,
395,
1390,
8,
65,
12,
330,
12,
286,
12,
366,
1724,
272,
372,
754,
199,
199,
6373,
804,
275,
730,
8,
20447,
8,
67,
63,
442,
8,
16,
1724,
199,
199,
2244,
63,
1313,
275,
359,
67,
63,
20790,
12,
286,
63,
27170,
12,
286,
63,
1635,
12,
286,
63,
15688,
61,
199,
1737,
63,
1313,
275,
359,
67,
63,
4414,
12,
286,
63,
3612,
12,
286,
63,
442,
12,
286,
63,
2809,
12,
286,
63,
2809,
2809,
61,
199,
199,
2245,
63,
1313,
275,
942,
199,
199,
1609,
63,
1313,
275,
359,
67,
63,
3157,
12,
286,
63,
1609,
61,
199,
199,
893,
26,
272,
286,
63,
32020,
272,
286,
63,
2809,
2809,
199,
2590,
12746,
26,
272,
986,
199,
2836,
26,
272,
7381,
63,
1313,
14,
740,
8,
67,
63,
32020,
9,
272,
10514,
63,
1313,
14,
740,
8,
67,
63,
2809,
2809,
9,
199,
199,
893,
26,
272,
286,
63,
2245,
199,
2590,
12746,
26,
272,
986,
199,
2836,
26,
272,
2155,
63,
1313,
14,
740,
8,
67,
63,
2245,
9,
199,
199,
2244,
63,
8404,
275,
1686,
63,
8404,
2031,
2244,
63,
1313,
9,
199,
1737,
63,
8404,
275,
1686,
63,
8404,
2031,
1737,
63,
1313,
9,
199,
2245,
63,
1459,
275,
359,
549,
12,
756,
12,
378,
12,
413,
12,
446,
17,
12,
22369,
12,
283,
396,
297,
990,
359,
17,
2677,
199,
199,
3060,
199,
199,
533,
4860,
1746,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
885,
63,
826,
8,
277,
304,
267,
327,
849,
1338,
787,
663,
370,
4697,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
84,
1252,
585,
12,
378,
9,
339,
347,
511,
63,
2244,
63,
1459,
8,
277,
304,
267,
327,
314,
574,
1627,
370,
314,
3787,
365,
2808,
267,
327,
465,
314,
283,
585,
7,
2225,
267,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
2244,
63,
1313,
12,
7381,
63,
8404,
304,
288,
291,
14,
629,
8,
84,
8,
76,
680,
585,
12,
634,
9,
288,
291,
14,
629,
8,
84,
8,
72,
680,
585,
12,
394,
9,
339,
347,
511,
63,
1737,
63,
1459,
8,
277,
304,
267,
327,
1937,
3432,
267,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
1737,
63,
1313,
12,
10514,
63,
8404,
304,
288,
291,
14,
629,
8,
84,
8,
76,
680,
585,
12,
634,
9,
288,
291,
14,
629,
8,
84,
8,
72,
680,
585,
12,
394,
9,
339,
347,
511,
63,
2245,
63,
1459,
8,
277,
304,
267,
687,
4182,
492,
16865,
267,
367,
307,
12,
373,
315,
3482,
8,
2245,
63,
1313,
12,
2155,
63,
1459,
304,
288,
291,
14,
629,
8,
84,
8,
86,
680,
585,
12,
16865,
8,
86,
430,
339,
347,
511,
63,
466,
705,
8,
277,
304,
267,
327,
5972,
5579,
787,
4370,
315,
314,
406,
454,
85,
630,
12,
267,
327,
4257,
3146,
365,
4915,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
1855,
8,
4333,
12,
307,
12,
6899,
288,
291,
14,
1855,
8,
4333,
12,
307,
12,
488,
9,
199,
199,
309,
259,
347,
511,
63,
1078,
63,
8404,
8,
277,
304,
199,
309,
263,
327,
3866,
1338,
402,
314,
3211,
730,
199,
309,
263,
327,
746,
1722,
334,
1397,
23870,
9,
199,
309,
263,
367,
307,
12,
334,
76,
12,
394,
9,
315,
3482,
8,
2244,
63,
1313,
12,
7381,
63,
8404,
304,
199,
309,
3322,
291,
14,
1855,
8,
3393,
12,
307,
12,
634,
13,
17,
9,
199,
309,
3322,
291,
14,
1855,
8,
3393,
12,
307,
12,
394,
11,
17,
9,
339,
347,
511,
63,
504,
63,
635,
8,
277,
304,
267,
327,
314,
687,
63,
635,
1021,
1083,
2225,
3544,
267,
327,
2529,
1611,
35,
6373,
1692,
4454,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
6373,
804,
12,
730,
8,
84,
14,
504,
63,
635,
8,
16,
1724,
339,
347,
511,
63,
20447,
8,
277,
304,
267,
327,
6358,
15968,
2529,
2597,
282,
1611,
35,
6373,
1692,
1256,
267,
367,
307,
315,
10514,
63,
1313,
435,
7381,
63,
1313,
435,
2069,
63,
1313,
435,
2155,
63,
1313,
26,
288,
623,
77,
275,
15968,
8,
84,
1012,
288,
291,
14,
629,
8,
6373,
804,
12,
730,
8,
22176,
430,
2378,
347,
511,
63,
1609,
83,
8,
277,
304,
267,
327,
286,
63,
1609,
436,
286,
63,
3157,
883,
506,
2737,
687,
267,
327,
2018,
1109,
12,
1846,
436,
2069,
267,
1021,
11140,
12545,
8,
785,
304,
288,
347,
636,
1609,
721,
277,
304,
355,
372,
499,
14,
16,
267,
289,
275,
11140,
12545,
342,
267,
367,
307,
315,
2069,
63,
1313,
26,
288,
291,
14,
629,
8,
84,
8,
18,
14,
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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ix
from cctbx import sgtbx
from cctbx.sgtbx import bravais_types
from dxtbx.model import Crystal, Experiment, ExperimentList
from dials.algorithms.indexing import assign_indices, non_primitive_basis
from dials.array_family import flex
@pytest.mark.parametrize("space_group_symbol", bravais_types.acentric)
def test_detect(space_group_symbol):
sgi = sgtbx.space_group_info(space_group_symbol)
cs = sgi.any_compatible_crystal_symmetry(volume=1000)
ms = cs.build_miller_set(anomalous_flag=True, d_min=1).expand_to_p1()
result = non_primitive_basis.detect(ms.indices())
if sgi.group().conventional_centring_type_symbol() != "P":
assert result is not None
assert isinstance(result, scitbx.matrix.sqr)
assert result.n == (3, 3)
else:
assert result is None
@pytest.mark.parametrize("space_group_symbol", bravais_types.acentric)
def test_correct(space_group_symbol):
sgi = sgtbx.space_group_info(space_group_symbol)
cs = sgi.any_compatible_crystal_symmetry(volume=1000)
ms = cs.build_miller_set(anomalous_flag=True, d_min=1).expand_to_p1()
# the reciprocal matrix
B = scitbx.matrix.sqr(cs.unit_cell().fractionalization_matrix()).transpose()
crystal = Crystal(B, sgtbx.space_group())
expts = ExperimentList([Experiment(crystal=crystal)])
refl = flex.reflection_table()
refl["miller_index"] = ms.indices()
refl["rlp"] = B.elems * ms.indices().as_vec3_double()
refl["imageset_id"] = flex.int(len(refl))
refl["xyzobs.mm.value"] = flex.vec3_double(len(refl))
non_primitive_basis.correct(expts, refl, assign_indices.AssignIndicesGlobal())
cs_corrected = expts.crystals()[0].get_crystal_symmetry()
assert cs_corrected.change_of_basis_op_to_primitive_setting().is_identity_op()
assert (
cs.change_of_basis_op_to_primitive_setting().apply(ms.indices())
== refl["miller_index"]
)
|
bsd-3-clause
|
[
646,
4613,
199,
199,
646,
4061,
390,
13691,
14,
3642,
199,
504,
286,
319,
13691,
492,
308,
3308,
13691,
199,
504,
286,
319,
13691,
14,
1226,
5842,
88,
492,
11137,
3042,
374,
63,
1313,
199,
504,
366,
400,
13691,
14,
1238,
492,
445,
651,
32100,
12,
23997,
12,
23997,
1296,
199,
199,
504,
487,
2551,
14,
24365,
14,
28703,
492,
5090,
63,
4108,
12,
2222,
63,
16161,
63,
19220,
199,
504,
487,
2551,
14,
1144,
63,
6606,
492,
20758,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2638,
63,
923,
63,
5155,
401,
11137,
3042,
374,
63,
1313,
14,
645,
484,
1567,
9,
199,
318,
511,
63,
13552,
8,
2638,
63,
923,
63,
5155,
304,
272,
308,
6153,
275,
308,
3308,
13691,
14,
2638,
63,
923,
63,
815,
8,
2638,
63,
923,
63,
5155,
9,
272,
7117,
275,
308,
6153,
14,
1629,
63,
6490,
63,
3019,
32100,
63,
3840,
10987,
8,
2405,
29,
5279,
9,
272,
6605,
275,
7117,
14,
1506,
63,
77,
19576,
63,
409,
8,
290,
676,
279,
1785,
63,
4173,
29,
549,
12,
366,
63,
827,
29,
17,
680,
4441,
63,
475,
63,
80,
17,
342,
272,
754,
275,
2222,
63,
16161,
63,
19220,
14,
13552,
8,
706,
14,
4108,
1012,
272,
340,
308,
6153,
14,
923,
1252,
388,
18803,
279,
63,
2497,
1232,
63,
466,
63,
5155,
342,
1137,
298,
48,
582,
267,
702,
754,
365,
440,
488,
267,
702,
1228,
8,
1099,
12,
4061,
390,
13691,
14,
3642,
14,
3526,
82,
9,
267,
702,
754,
14,
78,
508,
334,
19,
12,
650,
9,
272,
587,
26,
267,
702,
754,
365,
488,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2638,
63,
923,
63,
5155,
401,
11137,
3042,
374,
63,
1313,
14,
645,
484,
1567,
9,
199,
318,
511,
63,
4525,
8,
2638,
63,
923,
63,
5155,
304,
339,
308,
6153,
275,
308,
3308,
13691,
14,
2638,
63,
923,
63,
815,
8,
2638,
63,
923,
63,
5155,
9,
272,
7117,
275,
308,
6153,
14,
1629,
63,
6490,
63,
3019,
32100,
63,
3840,
10987,
8,
2405,
29,
5279,
9,
272,
6605,
275,
7117,
14,
1506,
63,
77,
19576,
63,
409,
8,
290,
676,
279,
1785,
63,
4173,
29,
549,
12,
366,
63,
827,
29,
17,
680,
4441,
63,
475,
63,
80,
17,
342,
339,
327,
314,
295,
31846,
3634,
272,
699,
275,
4061,
390,
13691,
14,
3642,
14,
3526,
82,
8,
1259,
14,
3248,
63,
3890,
1252,
13054,
279,
2072,
63,
3642,
8801,
10483,
342,
272,
286,
651,
32100,
275,
445,
651,
32100,
8,
34,
12,
308,
3308,
13691,
14,
2638,
63,
923,
1012,
272,
444,
8382,
275,
23997,
1296,
779,
20781,
8,
3019,
32100,
29,
3019,
32100,
3948,
339,
295,
2327,
275,
20758,
14,
14906,
63,
1224,
342,
272,
295,
2327,
905,
77,
19576,
63,
1080,
937,
275,
6605,
14,
4108,
342,
272,
295,
2327,
905,
4308,
80,
937,
275,
699,
14,
17482,
627,
6605,
14,
4108,
1252,
305,
63,
6046,
19,
63,
3157,
342,
272,
295,
2327,
905,
1569,
409,
63,
344,
937,
275,
20758,
14,
442,
8,
552,
8,
1121,
76,
430,
272,
295,
2327,
905,
8568,
11226,
14,
596,
14,
585,
937,
275,
20758,
14,
6046,
19,
63,
3157,
8,
552,
8,
1121,
76,
430,
339,
2222,
63,
16161,
63,
19220,
14,
4525,
8,
476,
8382,
12,
295,
2327,
12,
5090,
63,
4108,
14,
9595,
18488,
7025,
1012,
339,
7117,
63,
28125,
275,
444,
8382,
14,
3019,
270,
2551,
3430,
16,
1055,
362,
63,
3019,
32100,
63,
3840,
10987,
342,
272,
702,
7117,
63,
28125,
14,
1461,
63,
1618,
63,
19220,
63,
411,
63,
475,
63,
16161,
63,
6031,
1252,
374,
63,
5582,
63,
411,
342,
272,
702,
334,
267,
7117,
14,
1461,
63,
1618,
63,
19220,
63,
411,
63,
475,
63,
16161,
63,
6031,
1252,
4998,
8,
706,
14,
4108,
1012,
267,
508,
295,
2327,
905,
77,
19576,
63,
1080,
937,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4613,
199,
199,
646,
4061,
390,
13691,
14,
3642,
199,
504,
286,
319,
13691,
492,
308,
3308,
13691,
199,
504,
286,
319,
13691,
14,
1226,
5842,
88,
492,
11137,
3042,
374,
63,
1313,
199,
504,
366,
400,
13691,
14,
1238,
492,
445,
651,
32100,
12,
23997,
12,
23997,
1296,
199,
199,
504,
487,
2551,
14,
24365,
14,
28703,
492,
5090,
63,
4108,
12,
2222,
63,
16161,
63,
19220,
199,
504,
487,
2551,
14,
1144,
63,
6606,
492,
20758,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2638,
63,
923,
63,
5155,
401,
11137,
3042,
374,
63,
1313,
14,
645,
484,
1567,
9,
199,
318,
511,
63,
13552,
8,
2638,
63,
923,
63,
5155,
304,
272,
308,
6153,
275,
308,
3308,
13691,
14,
2638,
63,
923,
63,
815,
8,
2638,
63,
923,
63,
5155,
9,
272,
7117,
275,
308,
6153,
14,
1629,
63,
6490,
63,
3019,
32100,
63,
3840,
10987,
8,
2405,
29,
5279,
9,
272,
6605,
275,
7117,
14,
1506,
63,
77,
19576,
63,
409,
8,
290,
676,
279,
1785,
63,
4173,
29,
549,
12,
366,
63,
827,
29,
17,
680,
4441,
63,
475,
63,
80,
17,
342,
272,
754,
275,
2222,
63,
16161,
63,
19220,
14,
13552,
8,
706,
14,
4108,
1012,
272,
340,
308,
6153,
14,
923,
1252,
388,
18803,
279,
63,
2497,
1232,
63,
466,
63,
5155,
342,
1137,
298,
48,
582,
267,
702,
754,
365,
440,
488,
267,
702,
1228,
8,
1099,
12,
4061,
390,
13691,
14,
3642,
14,
3526,
82,
9,
267,
702,
754,
14,
78,
508,
334,
19,
12,
650,
9,
272,
587,
26,
267,
702,
754,
365,
488,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
2638,
63,
923,
63,
5155,
401,
11137,
3042,
374,
63,
1313,
14,
645,
484,
1567,
9,
199,
318,
511,
63,
4525,
8,
2638,
63,
923,
63,
5155,
304,
339,
308,
6153,
275,
308,
3308,
13691,
14,
2638,
63,
923,
63,
815,
8,
2638,
63,
923,
63,
5155,
9,
272,
7117,
275,
308,
6153,
14,
1629,
63,
6490,
63,
3019,
32100,
63,
3840,
10987,
8,
2405,
29,
5279,
9,
272,
6605,
275,
7117,
14,
1506,
63,
77,
19576,
63,
409,
8,
290,
676,
279,
1785,
63,
4173,
29,
549,
12,
366,
63,
827,
29,
17,
680,
4441,
63,
475,
63,
80,
17,
342,
339,
327,
314,
295,
31846,
3634,
272,
699,
275,
4061,
390,
13691,
14,
3642,
14,
3526,
82,
8,
1259,
14,
3248,
63,
3890,
1252,
13054,
279,
2072,
63,
3642,
8801,
10483,
342,
272,
286,
651,
32100,
275,
445,
651,
32100,
8,
34,
12,
308,
3308,
13691,
14,
2638,
63,
923,
1012,
272,
444,
8382,
275,
23997,
1296,
779,
20781,
8,
3019,
32100,
29,
3019,
32100,
3948,
339,
295,
2327,
275,
20758,
14,
14906,
63,
1224,
342,
272,
295,
2327,
905,
77,
19576,
63,
1080,
937,
275,
6605,
14,
4108,
342,
272,
295,
2327,
905,
4308,
80,
937,
275,
699,
14,
17482,
627,
6605,
14,
4108,
1252,
305,
63,
6046,
19,
63,
3157,
342,
272,
295,
2327,
905,
1569,
409,
63,
344,
937,
275,
20758,
14,
442,
8,
552,
8,
1121,
76,
430,
272,
295,
2327,
905,
8568,
11226,
14,
596,
14,
585,
937,
275,
20758,
14,
6046,
19,
63,
3157,
8,
552,
8,
1121,
76,
430,
339,
2222,
63,
16161,
63,
19220,
14,
4525,
8,
476,
8382,
12,
295,
2327,
12,
5090,
63,
4108,
14,
9595,
18488,
7025,
1012,
339,
7117,
63,
28125,
275,
444,
8382,
14,
3019,
270,
2551,
3430,
16,
1055,
362,
63,
3019,
32100,
63,
3840,
10987,
342,
272,
702,
7117,
63,
28125,
14,
1461,
63,
1618,
63,
19220,
63,
411,
63,
475,
63,
16161,
63,
6031,
1252,
374,
63,
5582,
63,
411,
342,
272,
702,
334,
267,
7117,
14,
1461,
63,
1618,
63,
19220,
63,
411,
63,
475,
63,
16161,
63,
6031,
1252,
4998,
8,
706,
14,
4108,
1012,
267,
508,
295,
2327,
905,
77,
19576,
63,
1080,
937,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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
0,
0,
0,
0
] |
vijeth-aradhya/coala-bears
|
bears/js/ESLintBear.py
|
1
|
2949
|
import json
from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.NpmRequirement import NpmRequirement
from coalib.results.Diff import Diff
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from coalib.results.Result import Result
@linter(executable='eslint',
use_stdin=True,
use_stderr=True)
class ESLintBear:
"""
Check JavaScript and JSX code for style issues and semantic errors.
Find out more at <http://eslint.org/docs/rules/>.
"""
LANGUAGES = {'JavaScript', 'JSX'}
REQUIREMENTS = {NpmRequirement('eslint', '2')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
ASCIINEMA_URL = 'https://asciinema.org/a/38739'
CAN_DETECT = {'Syntax'}
CAN_FIX = {'Formatting'}
severity_map = {2: RESULT_SEVERITY.MAJOR,
1: RESULT_SEVERITY.NORMAL,
0: RESULT_SEVERITY.INFO}
@staticmethod
def create_arguments(filename, file, config_file,
eslint_config: str=''):
"""
:param eslint_config: The location of the .eslintrc config file.
"""
args = (
'--no-ignore',
'--no-color',
'-f=json',
'--stdin',
'--stdin-filename=' + filename,
)
if eslint_config:
args += ('--config', eslint_config)
else:
args += ('--config', config_file)
return args
@staticmethod
def generate_config(filename, file):
return '{"extends": "eslint:recommended"}'
def process_output(self, output, filename, file):
if output[1]:
self.warn('While running {0}, some issues were found:'
.format(self.__class__.__name__))
self.warn(output[1])
if not file or not output[0]:
return
output = json.loads(output[0])
lines = ''.join(file)
assert len(output) == 1
for result in output[0]['messages']:
if 'fix' not in result:
diffs = None
else:
fix = result['fix']
start, end = fix['range']
replacement_text = fix['text']
new_output = lines[:start] + replacement_text + lines[end:]
diffs = {filename: Diff.from_string_arrays(
lines.splitlines(True), new_output.splitlines(True))}
origin = (
'{class_name} ({rule})'.format(class_name=type(self).__name__,
rule=result['ruleId'])
if result['ruleId'] is not None else self)
yield Result.from_values(
origin=origin, message=result['message'],
file=filename, line=result['line'], diffs=diffs,
severity=self.severity_map[result['severity']])
|
agpl-3.0
|
[
646,
2022,
199,
199,
504,
512,
25530,
14,
31796,
773,
14,
371,
14183,
2452,
14,
44,
1058,
492,
7403,
351,
199,
504,
5936,
63,
8110,
14,
7538,
14,
46,
7073,
17947,
492,
653,
7073,
17947,
199,
504,
512,
25530,
14,
2604,
14,
10746,
492,
27134,
199,
504,
512,
25530,
14,
2604,
14,
9517,
63,
899,
2111,
1922,
492,
20668,
63,
899,
2111,
1922,
199,
504,
512,
25530,
14,
2604,
14,
2889,
492,
10695,
421,
199,
32,
25240,
8,
5904,
534,
397,
3854,
297,
267,
675,
63,
6626,
29,
549,
12,
267,
675,
63,
3083,
29,
549,
9,
199,
533,
10427,
44,
442,
30860,
26,
272,
408,
272,
2670,
15250,
436,
18001,
56,
1233,
367,
3449,
10876,
436,
32451,
2552,
14,
339,
6668,
734,
1655,
737,
665,
1014,
921,
397,
3854,
14,
1308,
15,
4757,
15,
4423,
4743,
272,
408,
339,
30508,
5383,
275,
791,
21986,
297,
283,
11378,
56,
936,
272,
17023,
21201,
20967,
275,
469,
46,
7073,
17947,
360,
397,
3854,
297,
283,
18,
21004,
272,
10610,
275,
791,
1918,
512,
14774,
19782,
936,
272,
10610,
63,
10089,
51,
275,
791,
331,
14774,
13,
27870,
32,
3098,
2634,
14,
957,
936,
272,
5113,
275,
283,
1254,
2749,
13,
19,
14,
16,
7,
272,
4319,
3553,
3565,
2054,
63,
2632,
275,
283,
2859,
921,
305,
559,
1132,
391,
14,
1308,
15,
65,
15,
12399,
1355,
7,
272,
29661,
63,
17442,
3582,
275,
791,
16626,
936,
272,
29661,
63,
5192,
275,
791,
20552,
936,
339,
25574,
63,
1130,
275,
469,
18,
26,
20668,
63,
899,
2111,
1922,
14,
29241,
12,
490,
413,
26,
20668,
63,
899,
2111,
1922,
14,
10765,
12,
490,
378,
26,
20668,
63,
899,
2111,
1922,
14,
4531,
93,
339,
768,
4639,
272,
347,
1218,
63,
4958,
8,
1501,
12,
570,
12,
1101,
63,
493,
12,
586,
325,
2482,
442,
63,
888,
26,
620,
9280,
267,
408,
267,
520,
635,
325,
2482,
442,
63,
888,
26,
710,
2909,
402,
314,
1275,
397,
3854,
1195,
1101,
570,
14,
267,
408,
267,
1249,
275,
334,
288,
2850,
889,
13,
4247,
297,
288,
2850,
889,
13,
2326,
297,
288,
2475,
70,
29,
1001,
297,
288,
2850,
6626,
297,
288,
2850,
6626,
13,
1501,
534,
435,
1788,
12,
267,
776,
398,
340,
325,
2482,
442,
63,
888,
26,
288,
1249,
847,
26362,
888,
297,
325,
2482,
442,
63,
888,
9,
267,
587,
26,
288,
1249,
847,
26362,
888,
297,
1101,
63,
493,
9,
398,
372,
1249,
339,
768,
4639,
272,
347,
3550,
63,
888,
8,
1501,
12,
570,
304,
267,
372,
17137,
11036,
582,
298,
397,
3854,
26,
264,
11902,
3570,
7,
339,
347,
2112,
63,
1199,
8,
277,
12,
1072,
12,
1788,
12,
570,
304,
267,
340,
1072,
59,
17,
2189,
288,
291,
14,
4050,
360,
25215,
3879,
469,
16,
1386,
2005,
10876,
4898,
1911,
4881,
1993,
1275,
908,
8,
277,
855,
533,
4914,
354,
8964,
288,
291,
14,
4050,
8,
1199,
59,
17,
566,
398,
340,
440,
570,
503,
440,
1072,
59,
16,
2189,
288,
372,
398,
1072,
275,
2022,
14,
3640,
8,
1199,
59,
16,
566,
267,
2385,
275,
6522,
904,
8,
493,
9,
398,
702,
822,
8,
1199,
9,
508,
413,
398,
367,
754,
315,
1072,
59,
16,
2733,
3431,
2565,
288,
340,
283,
970,
7,
440,
315,
754,
26,
355,
14981,
275,
488,
288,
587,
26,
355,
5325,
275,
754,
459,
970,
418,
355,
1343,
12,
1284,
275,
5325,
459,
1842,
418,
355,
8343,
63,
505,
275,
5325,
459,
505,
418,
355,
892,
63,
1199,
275,
2385,
1491,
928,
61,
435,
8343,
63,
505,
435,
2385,
59,
500,
2938,
355,
14981,
275,
469,
1501,
26,
27134,
14,
504,
63,
875,
63,
10095,
8,
490,
2385,
14,
7644,
8,
549,
395,
892,
63,
1199,
14,
7644,
8,
549,
430,
93,
953,
6330,
275,
334,
355,
5041,
533,
63,
354,
93,
11459,
2200,
25885,
908,
8,
533,
63,
354,
29,
466,
8,
277,
2843,
354,
3108,
6901,
2332,
29,
1099,
459,
2200,
1304,
1105,
355,
340,
754,
459,
2200,
1304,
418,
365,
440,
488,
587,
291,
9,
288,
1995,
10695,
14,
504,
63,
1459,
8,
355,
6330,
29,
6493,
12,
1245,
29,
1099,
459,
1188,
995,
355,
570,
29,
1501,
12,
1004,
29,
1099,
459,
604,
995,
14981,
29,
17418,
12,
355,
25574,
29,
277,
14,
20394,
63,
1130,
59,
1099,
459,
20394,
12121,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2022,
199,
199,
504,
512,
25530,
14,
31796,
773,
14,
371,
14183,
2452,
14,
44,
1058,
492,
7403,
351,
199,
504,
5936,
63,
8110,
14,
7538,
14,
46,
7073,
17947,
492,
653,
7073,
17947,
199,
504,
512,
25530,
14,
2604,
14,
10746,
492,
27134,
199,
504,
512,
25530,
14,
2604,
14,
9517,
63,
899,
2111,
1922,
492,
20668,
63,
899,
2111,
1922,
199,
504,
512,
25530,
14,
2604,
14,
2889,
492,
10695,
421,
199,
32,
25240,
8,
5904,
534,
397,
3854,
297,
267,
675,
63,
6626,
29,
549,
12,
267,
675,
63,
3083,
29,
549,
9,
199,
533,
10427,
44,
442,
30860,
26,
272,
408,
272,
2670,
15250,
436,
18001,
56,
1233,
367,
3449,
10876,
436,
32451,
2552,
14,
339,
6668,
734,
1655,
737,
665,
1014,
921,
397,
3854,
14,
1308,
15,
4757,
15,
4423,
4743,
272,
408,
339,
30508,
5383,
275,
791,
21986,
297,
283,
11378,
56,
936,
272,
17023,
21201,
20967,
275,
469,
46,
7073,
17947,
360,
397,
3854,
297,
283,
18,
21004,
272,
10610,
275,
791,
1918,
512,
14774,
19782,
936,
272,
10610,
63,
10089,
51,
275,
791,
331,
14774,
13,
27870,
32,
3098,
2634,
14,
957,
936,
272,
5113,
275,
283,
1254,
2749,
13,
19,
14,
16,
7,
272,
4319,
3553,
3565,
2054,
63,
2632,
275,
283,
2859,
921,
305,
559,
1132,
391,
14,
1308,
15,
65,
15,
12399,
1355,
7,
272,
29661,
63,
17442,
3582,
275,
791,
16626,
936,
272,
29661,
63,
5192,
275,
791,
20552,
936,
339,
25574,
63,
1130,
275,
469,
18,
26,
20668,
63,
899,
2111,
1922,
14,
29241,
12,
490,
413,
26,
20668,
63,
899,
2111,
1922,
14,
10765,
12,
490,
378,
26,
20668,
63,
899,
2111,
1922,
14,
4531,
93,
339,
768,
4639,
272,
347,
1218,
63,
4958,
8,
1501,
12,
570,
12,
1101,
63,
493,
12,
586,
325,
2482,
442,
63,
888,
26,
620,
9280,
267,
408,
267,
520,
635,
325,
2482,
442,
63,
888,
26,
710,
2909,
402,
314,
1275,
397,
3854,
1195,
1101,
570,
14,
267,
408,
267,
1249,
275,
334,
288,
2850,
889,
13,
4247,
297,
288,
2850,
889,
13,
2326,
297,
288,
2475,
70,
29,
1001,
297,
288,
2850,
6626,
297,
288,
2850,
6626,
13,
1501,
534,
435,
1788,
12,
267,
776,
398,
340,
325,
2482,
442,
63,
888,
26,
288,
1249,
847,
26362,
888,
297,
325,
2482,
442,
63,
888,
9,
267,
587,
26,
288,
1249,
847,
26362,
888,
297,
1101,
63,
493,
9,
398,
372,
1249,
339,
768,
4639,
272,
347,
3550,
63,
888,
8,
1501,
12,
570,
304,
267,
372,
17137,
11036,
582,
298,
397,
3854,
26,
264,
11902,
3570,
7,
339,
347,
2112,
63,
1199,
8,
277,
12,
1072,
12,
1788,
12,
570,
304,
267,
340,
1072,
59,
17,
2189,
288,
291,
14,
4050,
360,
25215,
3879,
469,
16,
1386,
2005,
10876,
4898,
1911,
4881,
1993,
1275,
908,
8,
277,
855,
533,
4914,
354,
8964,
288,
291,
14,
4050,
8,
1199,
59,
17,
566,
398,
340,
440,
570,
503,
440,
1072,
59,
16,
2189,
288,
372,
398,
1072,
275,
2022,
14,
3640,
8,
1199,
59,
16,
566,
267,
2385,
275,
6522,
904,
8,
493,
9,
398,
702,
822,
8,
1199,
9,
508,
413,
398,
367,
754,
315,
1072,
59,
16,
2733,
3431,
2565,
288,
340,
283,
970,
7,
440,
315,
754,
26,
355,
14981,
275,
488,
288,
587,
26,
355,
5325,
275,
754,
459,
970,
418,
355,
1343,
12,
1284,
275,
5325,
459,
1842,
418,
355,
8343,
63,
505,
275,
5325,
459,
505,
418,
355,
892,
63,
1199,
275,
2385,
1491,
928,
61,
435,
8343,
63,
505,
435,
2385,
59,
500,
2938,
355,
14981,
275,
469,
1501,
26,
27134,
14,
504,
63,
875,
63,
10095,
8,
490,
2385,
14,
7644,
8,
549,
395,
892,
63,
1199,
14,
7644,
8,
549,
430,
93,
953,
6330,
275,
334,
355,
5041,
533,
63,
354,
93,
11459,
2200,
25885,
908,
8,
533,
63,
354,
29,
466,
8,
277,
2843,
354,
3108,
6901,
2332,
29,
1099,
459,
2200,
1304,
1105,
355,
340,
754,
459,
2200,
1304,
418,
365,
440,
488,
587,
291,
9,
288,
1995,
10695,
14,
504,
63,
1459,
8,
355,
6330,
29,
6493,
12,
1245,
29,
1099,
459,
1188,
995,
355,
570,
29,
1501,
12,
1004,
29,
1099,
459,
604,
995,
14981,
29,
17418,
12,
355,
25574,
29,
277,
14,
20394,
63,
1130,
59,
1099,
459,
20394,
12121,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CVML/cvxpy
|
examples/extensions/feature_selection.py
|
11
|
1062
|
from cvxpy import *
from mixed_integer import *
import numpy as np
# Feature selection on a linear kernel SVM classifier.
# Uses the Alternating Direction Method of Multipliers
# with a (non-convex) cardinality constraint.
# Generate data.
np.random.seed(1)
N = 50
M = 40
n = 10
data = []
for i in xrange(N):
data += [(1, np.random.normal(1.0, 2.0, (n, 1)))]
for i in xrange(M):
data += [(-1, np.random.normal(-1.0, 2.0, (n, 1)))]
# Construct problem.
gamma = Parameter(sign="positive")
gamma.value = 0.1
# 'a' is a variable constrained to have at most 6 non-zero entries.
a = Card(n, k=6)
b = Variable()
slack = [pos(1 - label*(sample.T*a - b)) for (label, sample) in data]
objective = Minimize(norm(a, 2) + gamma*sum(slack))
p = Problem(objective)
# Extensions can attach new solve methods to the CVXPY Problem class.
p.solve(method="admm")
# Count misclassifications.
error = 0
for label, sample in data:
if not label*(a.value.T*sample - b.value)[0] >= 0:
error += 1
print "%s misclassifications" % error
print a.value
print b.value
|
gpl-3.0
|
[
504,
6277,
88,
647,
492,
627,
199,
504,
13492,
63,
4115,
492,
627,
199,
646,
2680,
465,
980,
199,
199,
3,
13407,
7267,
641,
282,
7798,
5114,
428,
6849,
12429,
14,
199,
3,
14911,
314,
17669,
1958,
25596,
414,
9075,
402,
603,
2092,
14035,
199,
3,
543,
282,
334,
2865,
13,
388,
26221,
9,
12564,
15664,
5828,
14,
199,
199,
3,
7958,
666,
14,
199,
1590,
14,
2355,
14,
5176,
8,
17,
9,
199,
46,
275,
5238,
199,
45,
275,
6335,
199,
78,
275,
1616,
199,
576,
275,
942,
199,
509,
284,
315,
4945,
8,
46,
304,
272,
666,
847,
3842,
17,
12,
980,
14,
2355,
14,
3302,
8,
17,
14,
16,
12,
499,
14,
16,
12,
334,
78,
12,
413,
1724,
61,
199,
509,
284,
315,
4945,
8,
45,
304,
272,
666,
847,
359,
2801,
17,
12,
980,
14,
2355,
14,
3302,
2801,
17,
14,
16,
12,
499,
14,
16,
12,
334,
78,
12,
413,
1724,
61,
199,
199,
3,
9215,
5160,
14,
199,
7325,
275,
12009,
8,
1037,
628,
8965,
531,
199,
7325,
14,
585,
275,
378,
14,
17,
199,
3,
283,
65,
7,
365,
282,
1750,
28483,
370,
1172,
737,
4750,
1227,
2222,
13,
4262,
4811,
14,
199,
65,
275,
445,
1005,
8,
78,
12,
1022,
29,
22,
9,
199,
66,
275,
4905,
342,
199,
199,
24567,
275,
359,
1712,
8,
17,
446,
1768,
5830,
3271,
14,
52,
10,
65,
446,
330,
430,
367,
334,
1302,
12,
2690,
9,
315,
666,
61,
199,
24091,
275,
10195,
11807,
8,
4791,
8,
65,
12,
499,
9,
435,
10169,
10,
1838,
8,
24567,
430,
199,
80,
275,
20980,
8,
24091,
9,
199,
3,
11524,
1356,
883,
6554,
892,
14241,
3102,
370,
314,
445,
28493,
4521,
20980,
1021,
14,
199,
80,
14,
11356,
8,
765,
628,
350,
596,
531,
199,
199,
3,
14826,
3201,
14368,
83,
14,
199,
705,
275,
378,
199,
509,
1768,
12,
2690,
315,
666,
26,
272,
340,
440,
1768,
5830,
65,
14,
585,
14,
52,
10,
3271,
446,
330,
14,
585,
2788,
16,
61,
2356,
378,
26,
267,
1125,
847,
413,
199,
199,
1361,
2071,
83,
3201,
14368,
83,
2,
450,
1125,
199,
1361,
282,
14,
585,
199,
1361,
330,
14,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6277,
88,
647,
492,
627,
199,
504,
13492,
63,
4115,
492,
627,
199,
646,
2680,
465,
980,
199,
199,
3,
13407,
7267,
641,
282,
7798,
5114,
428,
6849,
12429,
14,
199,
3,
14911,
314,
17669,
1958,
25596,
414,
9075,
402,
603,
2092,
14035,
199,
3,
543,
282,
334,
2865,
13,
388,
26221,
9,
12564,
15664,
5828,
14,
199,
199,
3,
7958,
666,
14,
199,
1590,
14,
2355,
14,
5176,
8,
17,
9,
199,
46,
275,
5238,
199,
45,
275,
6335,
199,
78,
275,
1616,
199,
576,
275,
942,
199,
509,
284,
315,
4945,
8,
46,
304,
272,
666,
847,
3842,
17,
12,
980,
14,
2355,
14,
3302,
8,
17,
14,
16,
12,
499,
14,
16,
12,
334,
78,
12,
413,
1724,
61,
199,
509,
284,
315,
4945,
8,
45,
304,
272,
666,
847,
359,
2801,
17,
12,
980,
14,
2355,
14,
3302,
2801,
17,
14,
16,
12,
499,
14,
16,
12,
334,
78,
12,
413,
1724,
61,
199,
199,
3,
9215,
5160,
14,
199,
7325,
275,
12009,
8,
1037,
628,
8965,
531,
199,
7325,
14,
585,
275,
378,
14,
17,
199,
3,
283,
65,
7,
365,
282,
1750,
28483,
370,
1172,
737,
4750,
1227,
2222,
13,
4262,
4811,
14,
199,
65,
275,
445,
1005,
8,
78,
12,
1022,
29,
22,
9,
199,
66,
275,
4905,
342,
199,
199,
24567,
275,
359,
1712,
8,
17,
446,
1768,
5830,
3271,
14,
52,
10,
65,
446,
330,
430,
367,
334,
1302,
12,
2690,
9,
315,
666,
61,
199,
24091,
275,
10195,
11807,
8,
4791,
8,
65,
12,
499,
9,
435,
10169,
10,
1838,
8,
24567,
430,
199,
80,
275,
20980,
8,
24091,
9,
199,
3,
11524,
1356,
883,
6554,
892,
14241,
3102,
370,
314,
445,
28493,
4521,
20980,
1021,
14,
199,
80,
14,
11356,
8,
765,
628,
350,
596,
531,
199,
199,
3,
14826,
3201,
14368,
83,
14,
199,
705,
275,
378,
199,
509,
1768,
12,
2690,
315,
666,
26,
272,
340,
440,
1768,
5830,
65,
14,
585,
14,
52,
10,
3271,
446,
330,
14,
585,
2788,
16,
61,
2356,
378,
26,
267,
1125,
847,
413,
199,
199,
1361,
2071,
83,
3201,
14368,
83,
2,
450,
1125,
199,
1361,
282,
14,
585,
199,
1361,
330,
14,
585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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
] |
JesseLivezey/plankton
|
pylearn2/space/__init__.py
|
4
|
86621
|
"""
Classes that define how vector spaces are formatted
Most of our models can be viewed as linearly transforming
one vector space to another. These classes define how the
vector spaces should be represented as theano/numpy
variables.
For example, the VectorSpace class just represents a
vector space with a vector, and the model can transform
between spaces with a matrix multiply. The Conv2DSpace
represents a vector space as an image, and the model
can transform between spaces with a 2D convolution.
To make models as general as possible, models should be
written in terms of Spaces, rather than in terms of
numbers of hidden units, etc. The model should also be
written to transform between spaces using a generic
linear transformer from the pylearn2.linear module.
The Space class is needed so that the model can specify
what kinds of inputs it needs and what kinds of outputs
it will produce when communicating with other parts of
the library. The model also uses Space objects internally
to allocate parameters like hidden unit bias terms in
the right space.
"""
__authors__ = "Ian Goodfellow"
__copyright__ = "Copyright 2010-2012, Universite de Montreal"
__credits__ = ["Ian Goodfellow"]
__license__ = "3-clause BSD"
__maintainer__ = "LISA Lab"
__email__ = "pylearn-dev@googlegroups"
import functools
import warnings
import numpy as np
from theano.compat.six.moves import xrange
import theano
import theano.sparse
from theano import tensor
from theano.tensor import TensorType
from theano.gof.op import get_debug_values
from theano.sandbox.cuda.type import CudaNdarrayType
from pylearn2.utils import py_integer_types, safe_zip, sharedX, wraps
from pylearn2.format.target_format import OneHotFormatter
if theano.sparse.enable_sparse:
# We know scipy.sparse is available
import scipy.sparse
def _is_batch_all(batch, predicate):
"""
Implementation of is_symbolic_batch() and is_numeric_batch().
Returns True iff predicate() returns True for all components of
(possibly composite) batch.
Parameters
----------
batch : any numeric or symbolic batch.
This includes numpy.ndarray, theano.gof.Variable, None, or a (nested)
tuple thereof.
predicate : function.
A unary function of any non-composite batch that returns True or False.
"""
# Catches any CompositeSpace batches that were mistakenly hand-constructed
# using nested lists rather than nested tuples.
assert not isinstance(batch, list)
# Data-less batches such as None or () are valid numeric and symbolic
# batches.
#
# Justification: we'd like
# is_symbolic_batch(space.make_theano_batch()) to always be True, even if
# space is an empty CompositeSpace.
if batch is None or (isinstance(batch, tuple) and len(batch) == 0):
return True
if isinstance(batch, tuple):
subbatch_results = tuple(_is_batch_all(b, predicate)
for b in batch)
result = all(subbatch_results)
# The subbatch_results must be all true, or all false, not a mix.
assert result == any(subbatch_results), ("composite batch had a "
"mixture of numeric and "
"symbolic subbatches. This "
"should never happen.")
return result
else:
return predicate(batch)
def is_symbolic_batch(batch):
"""
Returns True if batch is a symbolic variable.
Note that a batch may be both a symbolic and numeric variable
(e.g. () for empty CompositeSpaces, None for NullSpaces).
"""
return _is_batch_all(batch, lambda x: isinstance(x, theano.gof.Variable))
def is_numeric_batch(batch):
"""
Returns True if batch is a numeric variable.
Note that a batch may be both a symbolic and numeric variable
(e.g. () for empty CompositeSpaces, None for NullSpaces).
"""
def is_numeric(batch):
# Uses the 'CudaNdarray' string to avoid importing
# theano.sandbox.cuda when it is not available
return (isinstance(batch, np.ndarray) or
scipy.sparse.issparse(batch) or
str(type(batch)) == "<type 'CudaNdarray'>")
return _is_batch_all(batch, is_numeric)
def _dense_to_sparse(batch):
"""
Casts dense batches to sparse batches (non-composite).
Supports both symbolic and numeric variables.
"""
if isinstance(batch, tuple):
raise TypeError("Composite batches not supported.")
assert not isinstance(batch, list)
if is_symbolic_batch(batch):
assert isinstance(batch, theano.tensor.TensorVariable)
return theano.sparse.csr_from_dense(batch)
else:
assert isinstance(batch, np.ndarray), "type of batch: %s" % type(batch)
return scipy.sparse.csr_matrix(batch)
def _reshape(arg, shape):
"""
Reshapes a tensor. Supports both symbolic and numeric variables.
This is a hack that first converts from sparse to dense, reshapes
the dense tensor, then re-converts from dense to sparse. It is
therefore memory-inefficient and unsuitable for large tensors. It
will be replaced by a proper sparse reshaping Op once Theano
implements that.
"""
if isinstance(arg, tuple):
raise TypeError("Composite batches not supported.")
assert not isinstance(arg, list)
if isinstance(arg, (np.ndarray, theano.tensor.TensorVariable)):
return arg.reshape(shape)
elif isinstance(arg, theano.sparse.SparseVariable):
warnings.warn("Using pylearn2.space._reshape(), which is a "
"memory-inefficient hack for reshaping sparse tensors. "
"Do not use this on large tensors. This will eventually "
"be replaced by a proper Theano Op for sparse "
"reshaping, once that is written.")
dense = theano.sparse.dense_from_sparse(arg)
dense = dense.reshape(shape)
if arg.format == 'csr':
return theano.sparse.csr_from_dense(dense)
elif arg.format == 'csc':
return theano.sparse.csc_from_dense(dense)
else:
raise ValueError('Unexpected sparse format "%s".' % arg.format)
else:
raise TypeError('Unexpected batch type "%s"' % str(type(arg)))
def _cast(arg, dtype):
"""
Does element-wise casting to dtype.
Supports symbolic, numeric, simple, and composite batches.
Returns <arg> untouched if <dtype> is None, or dtype is unchanged
(i.e. casting a float32 batch to float32).
(One exception: composite batches are never returned as-is.
A new tuple will always be returned. However, any components
with unchanged dtypes will be returned untouched.)
"""
if dtype is None:
return arg
assert dtype in tuple(t.dtype for t in theano.scalar.all_types)
if isinstance(arg, tuple):
return tuple(_cast(a, dtype) for a in arg)
elif isinstance(arg, np.ndarray):
# theano._asarray is a safer drop-in replacement to numpy.asarray.
return theano._asarray(arg, dtype=dtype)
elif str(type(arg)) == "<type 'CudaNdarray'>": # numeric CUDA array
if str(dtype) != 'float32':
raise TypeError("Can only cast a numeric CudaNdarray to "
"float32, not %s" % dtype)
else:
return arg
elif (isinstance(arg, theano.gof.Variable) and
isinstance(arg.type, CudaNdarrayType)): # symbolic CUDA array
if str(dtype) != 'float32':
raise TypeError("Can only cast a theano CudaNdArrayType to "
"float32, not %s" % dtype)
else:
return arg
elif scipy.sparse.issparse(arg):
return arg.astype(dtype)
elif isinstance(arg, theano.tensor.TensorVariable):
return theano.tensor.cast(arg, dtype)
elif isinstance(arg, theano.sparse.SparseVariable):
return theano.sparse.cast(arg, dtype)
elif isinstance(arg, theano.sandbox.cuda.var.CudaNdarrayVariable):
return arg
else:
raise TypeError("Unsupported arg type '%s'" % str(type(arg)))
class Space(object):
"""
A vector space that can be transformed by a linear operator.
Space and its subclasses are used to transform a data batch's geometry
(e.g. vectors <--> matrices) and optionally, its dtype (e.g. float <-->
int).
Batches may be one of the following types:
- numpy.ndarray
- scipy.sparse.csr_matrix
- theano.gof.Variable
- None (for NullSpace)
- A (nested) tuple of the above, possibly empty
(for CompositeSpace).
Parameters
----------
validate_callbacks : list
Callbacks that are run at the start of a call to validate.
Each should be a callable with the same signature as validate.
An example use case is installing an instance-specific error
handler that provides extra instructions for how to correct an
input that is in a bad space.
np_validate_callacks : list
similar to validate_callbacks, but run on calls to np_validate
"""
def __init__(self, validate_callbacks=None,
np_validate_callbacks=None):
if validate_callbacks is None:
validate_callbacks = []
if np_validate_callbacks is None:
np_validate_callbacks = []
self.validate_callbacks = validate_callbacks
self.np_validate_callbacks = np_validate_callbacks
# Forces subclasses to implement __eq__.
# This is necessary for _format_as to work correctly.
def __eq__(self, other):
"""
Returns true iff
space.format_as(batch, self) and
space.format_as(batch, other) return the same formatted batch.
"""
raise NotImplementedError("__eq__ not implemented in class %s." %
type(self))
def get_batch_axis(self):
"""
Returns the batch axis of the output space.
Returns
-------
batch_axis : int
the axis of the batch in the output space.
"""
return 0
def __ne__(self, other):
"""
.. todo::
WRITEME
"""
return not (self == other)
def __repr__(self):
"""
.. todo::
WRITEME
"""
return str(self)
@property
def dtype(self):
"""
An object representing the data type used by this space.
For simple spaces, this will be a dtype string, as used by numpy,
scipy, and theano (e.g. 'float32').
For data-less spaces like NoneType, this will be some other string.
For composite spaces, this will be a nested tuple of such strings.
"""
raise NotImplementedError()
@dtype.setter
def dtype(self, new_value):
"""
.. todo::
WRITEME
"""
raise NotImplementedError()
@dtype.deleter
def dtype(self):
"""
.. todo::
WRITEME
"""
raise RuntimeError("You may not delete the dtype of a space, "
"though you can set it to None.")
def get_origin(self):
"""
Returns the origin in this space.
Returns
-------
origin : ndarray
An NumPy array, the shape of a single points in this
space, representing the origin.
"""
raise NotImplementedError()
def get_origin_batch(self, batch_size, dtype=None):
"""
Returns a batch containing `batch_size` copies of the origin.
Parameters
----------
batch_size : int
The number of examples in the batch to be returned.
dtype : WRITEME
The dtype of the batch to be returned. Default = None.
If None, use self.dtype.
Returns
-------
batch : ndarray
A NumPy array in the shape of a batch of `batch_size` points in
this space (with points being indexed along the first axis),
each `batch[i]` being a copy of the origin.
"""
raise NotImplementedError()
def make_shared_batch(self, batch_size, name=None, dtype=None):
"""
.. todo::
WRITEME
"""
dtype = self._clean_dtype_arg(dtype)
origin_batch = self.get_origin_batch(batch_size, dtype)
return theano.shared(origin_batch, name=name)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
"""
Returns a symbolic variable representing a batch of points
in this space.
Parameters
----------
name : str
Variable name for the returned batch.
dtype : str
Data type for the returned batch.
If omitted (None), self.dtype is used.
batch_size : int
Number of examples in the returned batch.
Returns
-------
batch : TensorVariable, SparseVariable, or tuple thereof
A batch with the appropriate number of dimensions and
appropriate broadcast flags to represent a batch of
points in this space.
"""
raise NotImplementedError()
def make_batch_theano(self, name=None, dtype=None, batch_size=None):
""" An alias to make_theano_batch """
return self.make_theano_batch(name=name,
dtype=dtype,
batch_size=batch_size)
@wraps(make_theano_batch)
def get_theano_batch(self, *args, **kwargs):
return self.make_theano_batch(*args, **kwargs)
def get_total_dimension(self):
"""
Returns a Python int (not a theano iscalar) representing
the dimensionality of a point in this space.
If you format a batch of examples in this space as a
design matrix (i.e., VectorSpace batch) then the
number of columns will be equal to the total dimension.
"""
raise NotImplementedError(str(type(self)) +
" does not implement get_total_dimension.")
def np_format_as(self, batch, space):
"""
Returns a numeric batch (e.g. a numpy.ndarray or scipy.sparse sparse
array), formatted to lie in this space.
This is just a wrapper around self._format_as, with an extra check
to throw an exception if <batch> is symbolic.
Should be invertible, i.e. batch should equal
`space.format_as(self.format_as(batch, space), self)`
Parameters
----------
batch : numpy.ndarray, or one of the scipy.sparse matrices.
Array which lies in this space.
space : Space
Target space to format batch to.
Returns
-------
WRITEME
The formatted batch
"""
self._check_is_numeric(batch)
return self._format_as(is_numeric=True,
batch=batch,
space=space)
def _check_sizes(self, space):
"""
Called by self._format_as(space), to check whether self and space
have compatible sizes. Throws a ValueError if they don't.
"""
my_dimension = self.get_total_dimension()
other_dimension = space.get_total_dimension()
if my_dimension != other_dimension:
raise ValueError(str(self) + " with total dimension " +
str(my_dimension) +
" can't format a batch into " +
str(space) + "because its total dimension is " +
str(other_dimension))
def format_as(self, batch, space):
"""
.. todo::
WRITEME
"""
self._check_is_symbolic(batch)
return self._format_as(is_numeric=False,
batch=batch,
space=space)
def _format_as(self, is_numeric, batch, space):
"""
The shared implementation of format_as() and np_format_as().
Agnostic to whether batch is symbolic or numeric, which avoids
duplicating a lot of code between format_as() and np_format_as().
Calls the appropriate callbacks, then calls self._format_as_impl().
Should be invertible, i.e. batch should equal
`space._format_as(self._format_as(batch, space), self)`
Parameters
----------
is_numeric : bool
Set to True to call np_validate_callbacks().
Set to False to call validate_callbacks().
batch : WRITEME
space : Space
WRITEME
Returns
-------
WRITEME
"""
assert isinstance(is_numeric, bool)
# Checks if batch belongs to this space
self._validate(is_numeric, batch)
# checks if self and space have compatible sizes for formatting.
self._check_sizes(space)
return self._format_as_impl(is_numeric, batch, space)
def _format_as_impl(self, is_numeric, batch, target_space):
"""
Actual implementation of format_as/np_format_as. Formats batch to
target_space.
Should be invertible, i.e. batch should equal
`space._format_as_impl(self._format_as_impl(batch, space), self)`
Parameters
----------
is_numeric : bool
Set to True to treat batch as a numeric batch, False to
treat it as a symbolic batch. This is necessary because
sometimes a batch's numeric/symbolicness can be ambiguous,
i.e. when it's the empty tuple ().
batch : a numpy.ndarray, scipy.sparse matrix, theano symbol, or a \
nested tuple thereof
Implementations of this method may assume that batch lies in this
space (i.e. that it passed self._validate(batch) without throwing
an exception).
target_space : A Space subclass
The space to transform batch into.
Returns
-------
The batch, converted to the target_space.
"""
raise NotImplementedError("%s does not implement _format_as_impl()." %
type(self))
def validate(self, batch):
"""
Runs all validate_callbacks, then checks that batch lies in this space.
Raises an exception if the batch isn't symbolic, or if any of these
checks fails.
Parameters
----------
batch : a symbolic (Theano) variable that lies in this space.
"""
self._check_is_symbolic(batch)
self._validate(is_numeric=False, batch=batch)
def np_validate(self, batch):
"""
Runs all np_validate_callbacks, then checks that batch lies in this
space. Raises an exception if the batch isn't numeric, or if any of
these checks fails.
Parameters
----------
batch : a numeric (numpy/scipy.sparse) variable that lies in this \
space
"""
self._check_is_numeric(batch)
self._validate(is_numeric=True, batch=batch)
def _validate(self, is_numeric, batch):
"""
Shared implementation of validate() and np_validate().
Calls validate_callbacks or np_validate_callbacks as appropriate,
then calls self._validate_impl(batch) to verify that batch belongs
to this space.
Parameters
----------
is_numeric : bool.
Set to True to call np_validate_callbacks,
False to call validate_callbacks.
Necessary because it can be impossible to tell from the
batch whether it should be treated as a numeric of symbolic
batch, for example when the batch is the empty tuple (),
or NullSpace batch None.
batch : a theano variable, numpy ndarray, scipy.sparse matrix \
or a nested tuple thereof
Represents a batch belonging to this space.
"""
if is_numeric:
self._check_is_numeric(batch)
callbacks_name = "np_validate_callbacks"
else:
self._check_is_symbolic(batch)
callbacks_name = "validate_callbacks"
if not hasattr(self, callbacks_name):
warnings.warn("It looks like the " + str(type(self)) +
"subclass of Space does not call the superclass "
"__init__ method. Currently this is a warning. It "
"will become an error on or after 2014-06-17.")
else:
callbacks = getattr(self, callbacks_name)
for callback in callbacks:
callback(batch)
self._validate_impl(is_numeric, batch)
def _validate_impl(self, is_numeric, batch):
"""
Subclasses must override this method so that it throws an
exception if the batch is the wrong shape or dtype for this Space.
Parameters
----------
is_numeric : bool
Set to True to treat batch as a numeric type
(numpy.ndarray or scipy.sparse matrix).
Set to False to treat batch as a symbolic (Theano) variable.
Necessary because batch could be (), which could be numeric
or symbolic.
batch : A numpy ndarray, scipy.sparse matrix, theano variable \
or a nested tuple thereof.
Must be a valid batch belonging to this space.
"""
raise NotImplementedError('Class "%s" does not implement '
'_validate_impl()' % type(self))
def batch_size(self, batch):
"""
Returns the batch size of a symbolic batch.
Parameters
----------
batch : WRITEME
"""
return self._batch_size(is_numeric=False, batch=batch)
def np_batch_size(self, batch):
"""
Returns the batch size of a numeric (numpy/scipy.sparse) batch.
Parameters
----------
batch : WRITEME
"""
return self._batch_size(is_numeric=True, batch=batch)
def _batch_size(self, is_numeric, batch):
"""
.. todo::
WRITEME
"""
self._validate(is_numeric, batch)
return self._batch_size_impl(is_numeric, batch)
def _batch_size_impl(self, is_numeric, batch):
"""
Returns the batch size of a batch.
Parameters
----------
batch : WRITEME
"""
raise NotImplementedError("%s does not implement batch_size" %
type(self))
def get_batch(self, data, start, end):
"""
Returns a batch of data starting from index `start` to index `stop`
Parameters
----------
data : WRITEME
start : WRITEME
end : WRITEME
"""
raise NotImplementedError(str(type(self)) + " does not implement " +
"get_batch")
@staticmethod
def _check_is_numeric(batch):
"""
.. todo::
WRITEME
"""
if not is_numeric_batch(batch):
raise TypeError('Expected batch to be a numeric variable, but '
'instead it was of type "%s"' % type(batch))
@staticmethod
def _check_is_symbolic(batch):
"""
.. todo::
WRITEME
"""
if not is_symbolic_batch(batch):
raise TypeError('Expected batch to be a symbolic variable, but '
'instead it was of type "%s"' % type(batch))
def _clean_dtype_arg(self, dtype):
"""
Checks dtype string for validity, and returns it if it is.
If dtype is 'floatX', returns the theano.config.floatX dtype (this will
either be 'float32' or 'float64'.
"""
if isinstance(dtype, np.dtype):
dtype = str(dtype)
if dtype == 'floatX':
return theano.config.floatX
if dtype is None or \
dtype in tuple(x.dtype for x in theano.scalar.all_types):
return dtype
raise TypeError('Unrecognized value "%s" (type %s) for dtype arg' %
(dtype, type(dtype)))
class SimplyTypedSpace(Space):
"""
An abstract base class for Spaces that use a numpy/theano dtype string for
its .dtype property.
"""
def __init__(self, dtype='floatX', **kwargs):
super(SimplyTypedSpace, self).__init__(**kwargs)
self._dtype = super(SimplyTypedSpace, self)._clean_dtype_arg(dtype)
def _clean_dtype_arg(self, dtype):
"""
if dtype is None, checks that self.dtype is not None.
Otherwise, same as superclass' implementation.
"""
if dtype is None:
if self.dtype is None:
raise TypeError("self.dtype is None, so you must provide a "
"non-None dtype argument to this method.")
return self.dtype
return super(SimplyTypedSpace, self)._clean_dtype_arg(dtype)
def _validate_impl(self, is_numeric, batch):
"""
.. todo::
WRITEME
"""
if isinstance(batch, tuple):
raise TypeError("This space only supports simple dtypes, but "
"received a composite batch.")
# Checks for information-destroying casts.
#
# To be maximally strict, we'd guard against all loss of precision by
# checking if np.can_cast(batch.dtype, self.dtype).
#
# Because this prohibits float64->float32, it breaks too much of the
# codebase (float64 is default float, float32 is default CUDA float for
# many graphics cards).
#
# Therefore, we only prohibit the following:
# * non-integral type to integral type
# * complex to non-complex
def is_complex(dtype):
return np.issubdtype(dtype, np.complex)
def is_integral(dtype):
return np.issubdtype(dtype, np.integer)
if self.dtype is not None:
if (is_complex(batch.dtype) and not is_complex(self.dtype)) or \
(not is_integral(batch.dtype) and is_integral(self.dtype)):
raise TypeError("Cannot safely cast batch dtype %s to "
"space's dtype %s. " %
(batch.dtype, self.dtype))
@property
def dtype(self):
"""
.. todo::
WRITEME
"""
return self._dtype
@dtype.setter
def dtype(self, new_dtype):
"""
.. todo::
WRITEME
"""
self._dtype = super(SimplyTypedSpace, self)._clean_dtype_arg(new_dtype)
def __setstate__(self, state_dict):
"""
.. todo::
WRITEME
"""
self.__dict__.update(state_dict)
# When unpickling a Space that was pickled before Spaces had dtypes,
# we need to set the _dtype to the default value.
if '_dtype' not in state_dict:
self._dtype = theano.config.floatX
class IndexSpace(SimplyTypedSpace):
"""
A space representing indices, for example MNIST labels (0-10) or the
indices of words in a dictionary for NLP tasks. A single space can
contain multiple indices, for example the word indices of an n-gram.
IndexSpaces can be converted to VectorSpaces in two ways: Either the
labels are converted into one-hot vectors which are then concatenated,
or they are converted into a single vector where 1s indicate labels
present i.e. for 4 possible labels we have [0, 2] -> [1 0 1 0] or
[0, 2] -> [1 0 0 0 0 0 1 0].
Parameters
----------
max_labels : int
The number of possible classes/labels. This means that
all labels should be < max_labels. Example: For MNIST
there are 10 numbers and hence max_labels = 10.
dim : int
The number of indices in one space e.g. for MNIST there is
one target label and hence dim = 1. If we have an n-gram
of word indices as input to a neurel net language model, dim = n.
dtype : str
A numpy dtype string indicating this space's dtype.
Must be an integer type e.g. int32 or int64.
kwargs : dict
Passes on to superclass constructor
"""
def __init__(self, max_labels, dim, dtype='int64', **kwargs):
if 'int' not in dtype:
raise ValueError("The dtype of IndexSpace must be an integer type")
super(IndexSpace, self).__init__(dtype, **kwargs)
self.max_labels = max_labels
self.dim = dim
self.formatter = OneHotFormatter(self.max_labels)
def __str__(self):
"""Return a string representation"""
return ('%(classname)s(dim=%(dim)s, max_labels=%(max_labels)s, '
'dtype=%(dtype)s)') % dict(classname=self.__class__.__name__,
dim=self.dim,
max_labels=self.max_labels,
dtype=self.dtype)
def __hash__(self):
return hash((type(self), self.dim, self.max_labels, self.dtype))
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
return (type(self) == type(other) and
self.max_labels == other.max_labels and
self.dim == other.dim and
self.dtype == other.dtype)
def __ne__(self, other):
"""
.. todo::
WRITEME
"""
return (not self == other)
@functools.wraps(Space.get_total_dimension)
def get_total_dimension(self):
return self.dim
@functools.wraps(Space.get_origin)
def get_origin(self):
return np.zeros((1, self.dim,))
@functools.wraps(Space.get_origin_batch)
def get_origin_batch(self, batch_size, dtype=None):
dtype = self._clean_dtype_arg(dtype)
return np.zeros((batch_size, self.dim), dtype=dtype)
@functools.wraps(Space._check_sizes)
def _check_sizes(self, space):
if isinstance(space, VectorSpace):
if space.dim not in (self.max_labels, # merged onehots
self.dim * self.max_labels): # concatenated
raise ValueError("Can't convert to VectorSpace of dim %d. "
"Expected either dim=%d (merged one-hots) or "
"%d (concatenated one-hots)" %
(space.dim,
self.max_labels,
self.dim * self.max_labels))
elif isinstance(space, IndexSpace):
if space.dim != self.dim or space.max_labels != self.max_labels:
raise ValueError("Can't convert to IndexSpace of dim %d and "
"max_labels %d." %
(space.dim, self.max_labels))
else:
raise ValueError("Can't convert to " + str(space.__class__))
@functools.wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
if isinstance(space, VectorSpace):
if self.max_labels == space.dim:
mode = 'merge'
elif self.dim * self.max_labels == space.dim:
mode = 'concatenate'
else:
raise ValueError("There is a bug. Couldn't format to a "
"VectorSpace because it had an incorrect "
"size, but this should've been caught in "
"IndexSpace._check_sizes().")
format_func = (self.formatter.format if is_numeric else
self.formatter.theano_expr)
return _cast(format_func(batch, sparse=space.sparse, mode=mode),
space.dtype)
elif isinstance(space, IndexSpace):
if space.dim != self.dim or space.max_labels != self.max_labels:
raise ValueError("The two IndexSpaces' dim and max_labels "
"values don't match. This should have been "
"caught by IndexSpace._check_sizes().")
return _cast(batch, space.dtype)
else:
raise ValueError("Can't convert %s to %s"
% (self, space))
@functools.wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
if batch_size == 1:
rval = tensor.lrow(name=name)
else:
rval = tensor.lmatrix(name=name)
if theano.config.compute_test_value != 'off':
if batch_size == 1:
n = 1
else:
# TODO: try to extract constant scalar value from batch_size
n = 4
rval.tag.test_value = self.get_origin_batch(batch_size=n,
dtype=dtype)
return rval
@functools.wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
return batch.shape[0]
@functools.wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
"""
.. todo::
WRITEME
"""
# checks that batch isn't a tuple, checks batch.type against self.dtype
super(IndexSpace, self)._validate_impl(is_numeric, batch)
if is_numeric:
# Use the 'CudaNdarray' string to avoid importing
# theano.sandbox.cuda when it is not available
if not isinstance(batch, np.ndarray) \
and str(type(batch)) != "<type 'CudaNdarray'>":
raise TypeError("The value of a IndexSpace batch should be a "
"numpy.ndarray, or CudaNdarray, but is %s."
% str(type(batch)))
if batch.ndim != 2:
raise ValueError("The value of a IndexSpace batch must be "
"2D, got %d dimensions for %s." % (batch.ndim,
batch))
if batch.shape[1] != self.dim:
raise ValueError("The width of a IndexSpace batch must match "
"with the space's dimension, but batch has "
"shape %s and dim = %d." % (str(batch.shape),
self.dim))
else:
if not isinstance(batch, theano.gof.Variable):
raise TypeError("IndexSpace batch should be a theano "
"Variable, got " + str(type(batch)))
if not isinstance(batch.type, (theano.tensor.TensorType,
CudaNdarrayType)):
raise TypeError("IndexSpace batch should be TensorType or "
"CudaNdarrayType, got " + str(batch.type))
if batch.ndim != 2:
raise ValueError('IndexSpace batches must be 2D, got %d '
'dimensions' % batch.ndim)
for val in get_debug_values(batch):
self.np_validate(val)
class VectorSpace(SimplyTypedSpace):
"""
A space whose points are defined as fixed-length vectors.
Parameters
----------
dim : int
Dimensionality of a vector in this space.
sparse : bool, optional
Sparse vector or not
dtype : str, optional
A numpy dtype string (e.g. 'float32') indicating this space's
dtype, or None for a dtype-agnostic space.
kwargs : dict
Passed on to superclass constructor.
"""
def __init__(self,
dim,
sparse=False,
dtype='floatX',
**kwargs):
super(VectorSpace, self).__init__(dtype, **kwargs)
self.dim = dim
self.sparse = sparse
def __str__(self):
"""
.. todo::
WRITEME
"""
return ('%s(dim=%d%s, dtype=%s)' %
(self.__class__.__name__,
self.dim,
', sparse' if self.sparse else '',
self.dtype))
@functools.wraps(Space.get_origin)
def get_origin(self):
return np.zeros((self.dim,))
@functools.wraps(Space.get_origin_batch)
def get_origin_batch(self, batch_size, dtype=None):
dtype = self._clean_dtype_arg(dtype)
if self.sparse:
return scipy.sparse.csr_matrix((batch_size, self.dim), dtype=dtype)
else:
return np.zeros((batch_size, self.dim), dtype=dtype)
@functools.wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
return batch.shape[0]
@functools.wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
dtype = self._clean_dtype_arg(dtype)
if self.sparse:
if batch_size is not None:
raise NotImplementedError("batch_size not implemented "
"for sparse case")
rval = theano.sparse.csr_matrix(name=name, dtype=dtype)
else:
if batch_size == 1:
rval = tensor.row(name=name, dtype=dtype)
else:
rval = tensor.matrix(name=name, dtype=dtype)
if theano.config.compute_test_value != 'off':
if batch_size == 1:
n = 1
else:
# TODO: try to extract constant scalar value from batch_size
n = 4
rval.tag.test_value = self.get_origin_batch(batch_size=n,
dtype=dtype)
return rval
@functools.wraps(Space.get_total_dimension)
def get_total_dimension(self):
return self.dim
@functools.wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
to_type = None
def is_sparse(batch):
return (isinstance(batch, theano.sparse.SparseVariable) or
scipy.sparse.issparse(batch))
if not isinstance(space, IndexSpace):
my_dimension = self.get_total_dimension()
other_dimension = space.get_total_dimension()
if my_dimension != other_dimension:
raise ValueError(str(self) + " with total dimension " +
str(my_dimension) +
" can't format a batch into " +
str(space) +
"because its total dimension is " +
str(other_dimension))
if isinstance(space, CompositeSpace):
if isinstance(batch, theano.sparse.SparseVariable):
warnings.warn('Formatting from a sparse VectorSpace to a '
'CompositeSpace is currently (2 Jan 2014) a '
'non-differentiable action. This is because it '
'calls slicing operations on a sparse batch '
'(e.g. "my_matrix[r:R, c:C]", which Theano does '
'not yet have a gradient operator for. If '
'autodifferentiation is reporting an error, '
'this may be why. Formatting batch type %s '
'from space %s to space %s' %
(type(batch), self, space))
pos = 0
pieces = []
for component in space.components:
width = component.get_total_dimension()
subtensor = batch[:, pos:pos + width]
pos += width
vector_subspace = VectorSpace(dim=width,
dtype=self.dtype,
sparse=self.sparse)
formatted = vector_subspace._format_as(is_numeric,
subtensor,
component)
pieces.append(formatted)
result = tuple(pieces)
elif isinstance(space, Conv2DSpace):
if is_sparse(batch):
raise TypeError("Formatting a SparseVariable to a Conv2DSpace "
"is not supported, since neither scipy nor "
"Theano has sparse tensors with more than 2 "
"dimensions. We need 4 dimensions to "
"represent a Conv2DSpace batch")
dims = {'b': batch.shape[0],
'c': space.num_channels,
0: space.shape[0],
1: space.shape[1]}
if space.axes != space.default_axes:
# Always use default_axes, so conversions like
# Conv2DSpace(c01b) -> VectorSpace -> Conv2DSpace(b01c) work
shape = [dims[ax] for ax in space.default_axes]
batch = _reshape(batch, shape)
batch = batch.transpose(*[space.default_axes.index(ax)
for ax in space.axes])
result = batch
else:
shape = tuple([dims[elem] for elem in space.axes])
result = _reshape(batch, shape)
to_type = space.dtype
elif isinstance(space, VectorSpace):
if self.dim != space.dim:
raise ValueError("Can't convert between VectorSpaces of "
"different sizes (%d to %d)."
% (self.dim, space.dim))
if space.sparse != is_sparse(batch):
if space.sparse:
batch = _dense_to_sparse(batch)
elif isinstance(batch, theano.sparse.SparseVariable):
batch = theano.sparse.dense_from_sparse(batch)
elif scipy.sparse.issparse(batch):
batch = batch.todense()
else:
assert False, ("Unplanned-for branch in if-elif-elif "
"chain. This is a bug in the code.")
result = batch
to_type = space.dtype
else:
raise NotImplementedError("%s doesn't know how to format as %s" %
(self, space))
return _cast(result, dtype=to_type)
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
return (type(self) == type(other) and
self.dim == other.dim and
self.sparse == other.sparse and
self.dtype == other.dtype)
def __hash__(self):
"""
.. todo::
WRITEME
"""
return hash((type(self), self.dim, self.sparse, self.dtype))
@functools.wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
"""
.. todo::
WRITEME
"""
# checks that batch isn't a tuple, checks batch.type against self.dtype
super(VectorSpace, self)._validate_impl(is_numeric, batch)
if isinstance(batch, theano.gof.Variable):
if self.sparse:
if not isinstance(batch.type, theano.sparse.SparseType):
raise TypeError('This VectorSpace is%s sparse, but the '
'provided batch is not. (batch type: "%s")'
% ('' if self.sparse else ' not',
type(batch)))
elif not isinstance(batch.type, (theano.tensor.TensorType,
CudaNdarrayType)):
raise TypeError("VectorSpace batch should be TensorType or "
"CudaNdarrayType, got " + str(batch.type))
if batch.ndim != 2:
raise ValueError('VectorSpace batches must be 2D, got %d '
'dimensions' % batch.ndim)
for val in get_debug_values(batch):
self.np_validate(val) # sic; val is numeric, not symbolic
else:
# Use the 'CudaNdarray' string to avoid importing
# theano.sandbox.cuda when it is not available
if (not self.sparse
and not isinstance(batch, np.ndarray)
and type(batch) != 'CudaNdarray'):
raise TypeError("The value of a VectorSpace batch should be a "
"numpy.ndarray, or CudaNdarray, but is %s."
% str(type(batch)))
if self.sparse:
if not theano.sparse.enable_sparse:
raise TypeError("theano.sparse is not enabled, cannot "
"have a value for a sparse VectorSpace.")
if not scipy.sparse.issparse(batch):
raise TypeError("The value of a sparse VectorSpace batch "
"should be a sparse scipy matrix, got %s "
"of type %s." % (batch, type(batch)))
if batch.ndim != 2:
raise ValueError("The value of a VectorSpace batch must be "
"2D, got %d dimensions for %s." % (batch.ndim,
batch))
if batch.shape[1] != self.dim:
raise ValueError("The width of a VectorSpace batch must match "
"with the space's dimension, but batch has "
"shape %s and dim = %d." %
(str(batch.shape), self.dim))
class VectorSequenceSpace(SimplyTypedSpace):
"""
A space representing a single, variable-length sequence of fixed-sized
vectors.
Parameters
----------
dim : int
Vector size
dtype : str, optional
A numpy dtype string indicating this space's dtype.
kwargs : dict
Passes on to superclass constructor
"""
def __init__(self, dim, dtype='floatX', **kwargs):
super(VectorSequenceSpace, self).__init__(dtype, **kwargs)
self.dim = dim
def __str__(self):
"""Return a string representation"""
return ('%(classname)s(dim=%(dim)s, dtype=%(dtype)s)' %
dict(classname=self.__class__.__name__,
dim=self.dim,
dtype=self.dtype))
@wraps(Space.__eq__)
def __eq__(self, other):
return (type(self) == type(other) and
self.dim == other.dim and
self.dtype == other.dtype)
@wraps(Space._check_sizes)
def _check_sizes(self, space):
if not isinstance(space, VectorSequenceSpace):
raise ValueError("Can't convert to " + str(space.__class__))
else:
if space.dim != self.dim:
raise ValueError("Can't convert to VectorSequenceSpace of "
"dim %d" %
(space.dim,))
@wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
if isinstance(space, VectorSequenceSpace):
if space.dim != self.dim:
raise ValueError("The two VectorSequenceSpaces' dim "
"values don't match. This should have been "
"caught by "
"VectorSequenceSpace._check_sizes().")
return _cast(batch, space.dtype)
else:
raise ValueError("Can't convert %s to %s" % (self, space))
@wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
if batch_size == 1:
return tensor.matrix(name=name)
else:
return ValueError("VectorSequenceSpace does not support batches "
"of sequences.")
@wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
# Only batch size of 1 is supported
return 1
@wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
# checks that batch isn't a tuple, checks batch.type against self.dtype
super(VectorSequenceSpace, self)._validate_impl(is_numeric, batch)
if is_numeric:
# Use the 'CudaNdarray' string to avoid importing
# theano.sandbox.cuda when it is not available
if not isinstance(batch, np.ndarray) \
and str(type(batch)) != "<type 'CudaNdarray'>":
raise TypeError("The value of a VectorSequenceSpace batch "
"should be a numpy.ndarray, or CudaNdarray, "
"but is %s." % str(type(batch)))
if batch.ndim != 2:
raise ValueError("The value of a VectorSequenceSpace batch "
"must be 2D, got %d dimensions for %s."
% (batch.ndim, batch))
if batch.shape[1] != self.dim:
raise ValueError("The width of a VectorSequenceSpace 'batch' "
"must match with the space's window"
"dimension, but batch has dim %d and "
"this space's dim is %d."
% (batch.shape[1], self.dim))
else:
if not isinstance(batch, theano.gof.Variable):
raise TypeError("VectorSequenceSpace batch should be a theano "
"Variable, got " + str(type(batch)))
if not isinstance(batch.type, (theano.tensor.TensorType,
CudaNdarrayType)):
raise TypeError("VectorSequenceSpace batch should be "
"TensorType or CudaNdarrayType, got " +
str(batch.type))
if batch.ndim != 2:
raise ValueError("VectorSequenceSpace 'batches' must be 2D, "
"got %d dimensions" % batch.ndim)
for val in get_debug_values(batch):
self.np_validate(val)
class IndexSequenceSpace(SimplyTypedSpace):
"""
A space representing a single, variable-length sequence of indexes.
Parameters
----------
max_labels : int
The number of possible classes/labels. This means that
all labels should be < max_labels.
dim : int
The number of indices in one element of the sequence
dtype : str
A numpy dtype string indicating this space's dtype.
Must be an integer type e.g. int32 or int64.
kwargs : dict
Passes on to superclass constructor
"""
def __init__(self, max_labels, dim, dtype='int64', **kwargs):
if 'int' not in dtype:
raise ValueError("The dtype of IndexSequenceSpace must be an "
"integer type")
super(IndexSequenceSpace, self).__init__(dtype, **kwargs)
self.max_labels = max_labels
self.dim = dim
self.formatter = OneHotFormatter(self.max_labels)
def __str__(self):
"""Return a string representation"""
return ('%(classname)s(dim=%(dim)s, max_labels=%(max_labels)s, '
'dtype=%(dtype)s)') % dict(classname=self.__class__.__name__,
dim=self.dim,
max_labels=self.max_labels,
dtype=self.dtype)
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
return (type(self) == type(other) and
self.max_labels == other.max_labels and
self.dim == other.dim and
self.dtype == other.dtype)
@wraps(Space._check_sizes)
def _check_sizes(self, space):
if isinstance(space, VectorSequenceSpace):
# self.max_labels -> merged onehots
# self.dim * self.max_labels -> concatenated
if space.dim not in (self.max_labels, self.dim * self.max_labels):
raise ValueError("Can't convert to VectorSequenceSpace of "
"dim %d. Expected either "
"dim=%d (merged one-hots) or %d "
"(concatenated one-hots)" %
(space.dim,
self.max_labels,
self.dim * self.max_labels))
elif isinstance(space, IndexSequenceSpace):
if space.dim != self.dim or space.max_labels != self.max_labels:
raise ValueError("Can't convert to IndexSequenceSpace of "
"dim %d and max_labels %d." %
(space.dim, self.max_labels))
else:
raise ValueError("Can't convert to " + str(space.__class__))
@wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
if isinstance(space, VectorSequenceSpace):
if self.max_labels == space.dim:
mode = 'merge'
elif self.dim * self.max_labels == space.dim:
mode = 'concatenate'
else:
raise ValueError("There is a bug. Couldn't format to a "
"VectorSequenceSpace because it had an "
"incorrect size, but this should've been "
"caught in "
"IndexSequenceSpace._check_sizes().")
format_func = (self.formatter.format if is_numeric else
self.formatter.theano_expr)
return _cast(format_func(batch, mode=mode), space.dtype)
elif isinstance(space, IndexSequenceSpace):
if space.dim != self.dim or space.max_labels != self.max_labels:
raise ValueError("The two IndexSequenceSpaces' dim and "
"max_labels values don't match. This should "
"have been caught by "
"IndexSequenceSpace._check_sizes().")
return _cast(batch, space.dtype)
else:
raise ValueError("Can't convert %s to %s"
% (self, space))
@wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
if batch_size == 1:
return tensor.matrix(name=name)
else:
return ValueError("IndexSequenceSpace does not support batches "
"of sequences.")
@wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
# Only batch size of 1 is supported
return 1
@wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
# checks that batch isn't a tuple, checks batch.type against self.dtype
super(IndexSequenceSpace, self)._validate_impl(is_numeric, batch)
if is_numeric:
# Use the 'CudaNdarray' string to avoid importing
# theano.sandbox.cuda when it is not available
if not isinstance(batch, np.ndarray) \
and str(type(batch)) != "<type 'CudaNdarray'>":
raise TypeError("The value of a IndexSequenceSpace batch "
"should be a numpy.ndarray, or CudaNdarray, "
"but is %s." % str(type(batch)))
if batch.ndim != 2:
raise ValueError("The value of a IndexSequenceSpace batch "
"must be 2D, got %d dimensions for %s." %
(batch.ndim, batch))
if batch.shape[1] != self.dim:
raise ValueError("The width of a IndexSequenceSpace batch "
"must match with the space's dimension, but "
"batch has shape %s and dim = %d." %
(str(batch.shape), self.dim))
else:
if not isinstance(batch, theano.gof.Variable):
raise TypeError("IndexSequenceSpace batch should be a theano "
"Variable, got " + str(type(batch)))
if not isinstance(batch.type, (theano.tensor.TensorType,
CudaNdarrayType)):
raise TypeError("IndexSequenceSpace batch should be "
"TensorType or CudaNdarrayType, got " +
str(batch.type))
if batch.ndim != 2:
raise ValueError('IndexSequenceSpace batches must be 2D, got '
'%d dimensions' % batch.ndim)
for val in get_debug_values(batch):
self.np_validate(val)
class Conv2DSpace(SimplyTypedSpace):
"""
A space whose points are 3-D tensors representing (potentially
multi-channel) images.
Parameters
----------
shape : sequence, length 2
The shape of a single image, i.e. (rows, cols).
num_channels : int (synonym: channels)
Number of channels in the image, i.e. 3 if RGB.
axes : tuple
A tuple indicating the semantics of each axis, containing the
following elements in some order:
- 'b' : this axis is the batch index of a minibatch.
- 'c' : this axis the channel index of a minibatch.
- 0 : topological axis 0 (rows)
- 1 : topological axis 1 (columns)
For example, a PIL image has axes (0, 1, 'c') or (0, 1).
The pylearn2 image displaying functionality uses
('b', 0, 1, 'c') for batches and (0, 1, 'c') for images.
theano's conv2d operator uses ('b', 'c', 0, 1) images.
dtype : str
A numpy dtype string (e.g. 'float32') indicating this space's
dtype, or None for a dtype-agnostic space.
kwargs : dict
Passed on to superclass constructor
"""
# Assume pylearn2's get_topological_view format, since this is how
# data is currently served up. If we make better iterators change
# default to ('b', 'c', 0, 1) for theano conv2d
default_axes = ('b', 0, 1, 'c')
def __init__(self,
shape,
channels=None,
num_channels=None,
axes=None,
dtype='floatX',
**kwargs):
super(Conv2DSpace, self).__init__(dtype, **kwargs)
assert (channels is None) + (num_channels is None) == 1
if num_channels is None:
num_channels = channels
assert isinstance(num_channels, py_integer_types)
if not hasattr(shape, '__len__'):
raise ValueError("shape argument for Conv2DSpace must have a "
"length. Got %s." % str(shape))
if len(shape) != 2:
raise ValueError("shape argument to Conv2DSpace must be length 2, "
"not %d" % len(shape))
assert all(isinstance(elem, py_integer_types) for elem in shape)
assert all(elem > 0 for elem in shape)
assert isinstance(num_channels, py_integer_types)
assert num_channels > 0
# Converts shape to a tuple, so it can be hashable, and self can be too
self.shape = tuple(shape)
self.num_channels = num_channels
if axes is None:
axes = self.default_axes
assert len(axes) == 4
self.axes = tuple(axes)
def __str__(self):
"""
.. todo::
WRITEME
"""
return ("%s(shape=%s, num_channels=%d, axes=%s, dtype=%s)" %
(self.__class__.__name__,
str(self.shape),
self.num_channels,
str(self.axes),
self.dtype))
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
assert isinstance(self.axes, tuple)
if isinstance(other, Conv2DSpace):
assert isinstance(other.axes, tuple)
return (type(self) == type(other) and
self.shape == other.shape and
self.num_channels == other.num_channels and
self.axes == other.axes and
self.dtype == other.dtype)
def __hash__(self):
"""
.. todo::
WRITEME
"""
return hash((type(self),
self.shape,
self.num_channels,
self.axes,
self.dtype))
@functools.wraps(Space.get_batch_axis)
def get_batch_axis(self):
return self.axes.index('b')
@functools.wraps(Space.get_origin)
def get_origin(self):
dims = {0: self.shape[0], 1: self.shape[1], 'c': self.num_channels}
shape = [dims[elem] for elem in self.axes if elem != 'b']
return np.zeros(shape, dtype=self.dtype)
@functools.wraps(Space.get_origin_batch)
def get_origin_batch(self, batch_size, dtype=None):
dtype = self._clean_dtype_arg(dtype)
if not isinstance(batch_size, py_integer_types):
raise TypeError("Conv2DSpace.get_origin_batch expects an int, "
"got %s of type %s" % (str(batch_size),
type(batch_size)))
assert batch_size > 0
dims = {'b': batch_size,
0: self.shape[0],
1: self.shape[1],
'c': self.num_channels}
shape = [dims[elem] for elem in self.axes]
return np.zeros(shape, dtype=dtype)
@functools.wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None, batch_size=None):
dtype = self._clean_dtype_arg(dtype)
broadcastable = [False] * 4
broadcastable[self.axes.index('c')] = (self.num_channels == 1)
broadcastable[self.axes.index('b')] = (batch_size == 1)
broadcastable = tuple(broadcastable)
rval = TensorType(dtype=dtype,
broadcastable=broadcastable
)(name=name)
if theano.config.compute_test_value != 'off':
if batch_size == 1:
n = 1
else:
# TODO: try to extract constant scalar value from batch_size
n = 4
rval.tag.test_value = self.get_origin_batch(batch_size=n,
dtype=dtype)
return rval
@functools.wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
return batch.shape[self.axes.index('b')]
@staticmethod
def convert(tensor, src_axes, dst_axes):
"""
Returns a view of tensor using the axis semantics defined
by dst_axes. (If src_axes matches dst_axes, returns
tensor itself)
Useful for transferring tensors between different
Conv2DSpaces.
Parameters
----------
tensor : tensor_like
A 4-tensor representing a batch of images
src_axes : WRITEME
Axis semantics of tensor
dst_axes : WRITEME
WRITEME
"""
src_axes = tuple(src_axes)
dst_axes = tuple(dst_axes)
assert len(src_axes) == 4
assert len(dst_axes) == 4
if src_axes == dst_axes:
return tensor
shuffle = [src_axes.index(elem) for elem in dst_axes]
if is_symbolic_batch(tensor):
return tensor.dimshuffle(*shuffle)
else:
return tensor.transpose(*shuffle)
@staticmethod
def convert_numpy(tensor, src_axes, dst_axes):
"""
.. todo::
WRITEME
"""
return Conv2DSpace.convert(tensor, src_axes, dst_axes)
@functools.wraps(Space.get_total_dimension)
def get_total_dimension(self):
# Patch old pickle files
if not hasattr(self, 'num_channels'):
self.num_channels = self.nchannels
return self.shape[0] * self.shape[1] * self.num_channels
@functools.wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
# checks batch.type against self.dtype
super(Conv2DSpace, self)._validate_impl(is_numeric, batch)
if isinstance(batch, theano.gof.Variable):
if isinstance(batch, theano.sparse.SparseVariable):
raise TypeError("Conv2DSpace cannot use SparseVariables, "
"since as of this writing (28 Dec 2013), "
"there is not yet a SparseVariable type with "
"4 dimensions")
if not isinstance(batch, theano.gof.Variable):
raise TypeError("Conv2DSpace batches must be theano "
"Variables, got " + str(type(batch)))
if not isinstance(batch.type, (theano.tensor.TensorType,
CudaNdarrayType)):
raise TypeError('Expected TensorType or CudaNdArrayType, got '
'"%s"' % type(batch.type))
if batch.ndim != 4:
raise ValueError("The value of a Conv2DSpace batch must be "
"4D, got %d dimensions for %s." %
(batch.ndim, batch))
for val in get_debug_values(batch):
self.np_validate(val)
else:
if scipy.sparse.issparse(batch):
raise TypeError("Conv2DSpace cannot use sparse batches, since "
"scipy.sparse does not support 4 dimensional "
"tensors currently (28 Dec 2013).")
if (not isinstance(batch, np.ndarray)) \
and type(batch) != 'CudaNdarray':
raise TypeError("The value of a Conv2DSpace batch should be a "
"numpy.ndarray, or CudaNdarray, but is %s."
% str(type(batch)))
if batch.ndim != 4:
raise ValueError("The value of a Conv2DSpace batch must be "
"4D, got %d dimensions for %s." %
(batch.ndim, batch))
d = self.axes.index('c')
actual_channels = batch.shape[d]
if actual_channels != self.num_channels:
raise ValueError("Expected axis %d to be number of channels "
"(%d) but it is %d" %
(d, self.num_channels, actual_channels))
assert batch.shape[self.axes.index('c')] == self.num_channels
for coord in [0, 1]:
d = self.axes.index(coord)
actual_shape = batch.shape[d]
expected_shape = self.shape[coord]
if actual_shape != expected_shape:
raise ValueError("Conv2DSpace with shape %s and axes %s "
"expected dimension %s of a batch (%s) "
"to have length %s but it has %s"
% (str(self.shape),
str(self.axes),
str(d),
str(batch),
str(expected_shape),
str(actual_shape)))
@functools.wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
if isinstance(space, VectorSpace):
# We need to ensure that the resulting batch will always be
# the same in `space`, no matter what the axes of `self` are.
if self.axes != self.default_axes:
# The batch index goes on the first axis
assert self.default_axes[0] == 'b'
batch = batch.transpose(*[self.axes.index(axis)
for axis in self.default_axes])
result = batch.reshape((batch.shape[0],
self.get_total_dimension()))
if space.sparse:
result = _dense_to_sparse(result)
elif isinstance(space, Conv2DSpace):
result = Conv2DSpace.convert(batch, self.axes, space.axes)
else:
raise NotImplementedError("%s doesn't know how to format as %s"
% (str(self), str(space)))
return _cast(result, space.dtype)
class CompositeSpace(Space):
"""
A Space whose points are tuples of points in other spaces.
May be nested, in which case the points are nested tuples.
Parameters
----------
components : WRITEME
kwargs : dict
WRITEME
"""
def __init__(self, components, **kwargs):
super(CompositeSpace, self).__init__(**kwargs)
assert isinstance(components, (list, tuple))
for i, component in enumerate(components):
if not isinstance(component, Space):
raise TypeError("component %d is %s of type %s, expected "
"Space instance. " %
(i, str(component), str(type(component))))
self.components = list(components)
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
return (type(self) == type(other) and
len(self.components) == len(other.components) and
all(my_component == other_component for
my_component, other_component in
zip(self.components, other.components)))
def __hash__(self):
"""
.. todo::
WRITEME
"""
return hash((type(self), tuple(self.components)))
def __str__(self):
"""
.. todo::
WRITEME
"""
return '%(classname)s(%(components)s)' % \
dict(classname=self.__class__.__name__,
components=', '.join([str(c) for c in self.components]))
@property
def dtype(self):
"""
Returns a nested tuple of dtype strings. NullSpaces will yield a bogus
dtype string (see NullSpace.dtype).
"""
def get_dtype_of_space(space):
if isinstance(space, CompositeSpace):
return tuple(get_dtype_of_space(c) for c in space.components)
elif isinstance(space, NullSpace):
return NullSpace().dtype
else:
return space.dtype
return get_dtype_of_space(self)
@dtype.setter
def dtype(self, new_dtype):
"""
If new_dtype is None or a string, it will be applied to all components
(except any NullSpaces).
If new_dtype is a (nested) tuple, its elements will be applied to
corresponding components.
"""
if isinstance(new_dtype, tuple):
for component, new_dt in safe_zip(self.components, new_dtype):
component.dtype = new_dt
elif new_dtype is None or isinstance(new_dtype, str):
for component in self.components:
if not isinstance(component, NullSpace):
component.dtype = new_dtype
def restrict(self, subset):
"""
Returns a new Space containing only the components whose indices
are given in subset.
The new space will contain the components in the order given in the
subset list.
Parameters
----------
subset : WRITEME
Notes
-----
The returned Space may not be a CompositeSpace if `subset` contains
only one index.
"""
assert isinstance(subset, (list, tuple))
if len(subset) == 1:
idx, = subset
return self.components[idx]
return CompositeSpace([self.components[i] for i in subset])
def restrict_batch(self, batch, subset):
"""
Returns a batch containing only the components whose indices are
present in subset.
May not be a tuple anymore if there is only one index.
Outputs will be ordered in the order that they appear in subset.
Only supports symbolic batches.
Parameters
----------
batch : WRITEME
subset : WRITEME
"""
self._validate(is_numeric=False, batch=batch)
assert isinstance(subset, (list, tuple))
if len(subset) == 1:
idx, = subset
return batch[idx]
return tuple([batch[i] for i in subset])
@functools.wraps(Space.get_total_dimension)
def get_total_dimension(self):
return sum([component.get_total_dimension() for component in
self.components])
@functools.wraps(Space.make_shared_batch)
def make_shared_batch(self, batch_size, name=None, dtype=None):
dtype = self._clean_dtype_arg(dtype)
batch = self.get_origin_batch(batch_size, dtype)
def recursive_shared(batch):
if isinstance(batch, tuple):
return tuple(recursive_shared(b) for b in batch)
else:
return theano.shared(batch, name=name)
return recursive_shared(batch)
@functools.wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
"""
Supports formatting to a single VectorSpace, or to a CompositeSpace.
CompositeSpace->VectorSpace:
Traverses the nested components in depth-first order, serializing the
leaf nodes (i.e. the non-composite subspaces) into the VectorSpace.
CompositeSpace->CompositeSpace:
Only works for two CompositeSpaces that have the same nested
structure. Traverses both CompositeSpaces' nested components in
parallel, converting between corresponding non-composite components
in <self> and <space> as:
`self_component._format_as(is_numeric,
batch_component,
space_component)`
Parameters
----------
batch : WRITEME
space : WRITEME
Returns
-------
WRITEME
"""
if isinstance(space, VectorSpace):
pieces = []
for component, input_piece in zip(self.components, batch):
subspace = VectorSpace(dim=component.get_total_dimension(),
dtype=space.dtype,
sparse=space.sparse)
pieces.append(component._format_as(is_numeric,
input_piece,
subspace))
# Pieces should all have the same dtype, before we concatenate them
if len(pieces) > 0:
for piece in pieces[1:]:
if pieces[0].dtype != piece.dtype:
assert space.dtype is None
raise TypeError("Tried to format components with "
"differing dtypes into a VectorSpace "
"with no dtype of its own. "
"dtypes: %s" %
str(tuple(str(p.dtype)
for p in pieces)))
if is_symbolic_batch(batch):
if space.sparse:
return theano.sparse.hstack(pieces)
else:
return tensor.concatenate(pieces, axis=1)
else:
if space.sparse:
return scipy.sparse.hstack(pieces)
else:
return np.concatenate(pieces, axis=1)
if isinstance(space, CompositeSpace):
def recursive_format_as(orig_space, batch, dest_space):
if not (isinstance(orig_space, CompositeSpace) ==
isinstance(dest_space, CompositeSpace)):
raise TypeError("Can't convert between CompositeSpaces "
"with different tree structures")
# No need to check batch's tree structure. Space._format_as()
# already did that by calling _validate(), before calling this
# method.
if isinstance(orig_space, CompositeSpace):
return tuple(recursive_format_as(os, bt, ds)
for os, bt, ds
in safe_zip(orig_space.components,
batch,
dest_space.components))
else:
return orig_space._format_as(is_numeric, batch, dest_space)
return recursive_format_as(self, batch, space)
raise NotImplementedError(str(self) +
" does not know how to format as " +
str(space))
@functools.wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
if not isinstance(batch, tuple):
raise TypeError("The value of a CompositeSpace batch should be a "
"tuple, but is %s of type %s." %
(batch, type(batch)))
if len(batch) != len(self.components):
raise ValueError("Expected %d elements in batch, got %d"
% (len(self.components), len(batch)))
for batch_elem, component in zip(batch, self.components):
component._validate(is_numeric, batch_elem)
def get_origin_batch(self, batch_size, dtype=None):
"""
Calls get_origin_batch on all subspaces, and returns a (nested)
tuple containing their return values.
Parameters
----------
batch_size : int
Batch size.
dtype : str
the dtype to use for all the get_origin_batch() calls on
subspaces. If dtype is None, or a single dtype string, that will
be used for all calls. If dtype is a (nested) tuple, it must
mirror the tree structure of this CompositeSpace.
"""
dtype = self._clean_dtype_arg(dtype)
return tuple(component.get_origin_batch(batch_size, dt)
for component, dt
in safe_zip(self.components, dtype))
@functools.wraps(Space.make_theano_batch)
def make_theano_batch(self,
name=None,
dtype=None,
batch_size=None):
"""
Calls make_theano_batch on all subspaces, and returns a (nested)
tuple containing their return values.
Parameters
----------
name : str
Name of the symbolic variable
dtype : str
The dtype of the returned batch.
If dtype is a string, it will be applied to all components.
If dtype is None, C.dtype will be used for each component C.
If dtype is a nested tuple, its elements will be applied to
corresponding elements in the components.
batch_size : int
Batch size.
"""
if name is None:
name = [None] * len(self.components)
elif not isinstance(name, (list, tuple)):
name = ['%s[%i]' % (name, i) for i in xrange(len(self.components))]
dtype = self._clean_dtype_arg(dtype)
assert isinstance(name, (list, tuple))
assert isinstance(dtype, (list, tuple))
rval = tuple([x.make_theano_batch(name=n,
dtype=d,
batch_size=batch_size)
for x, n, d in safe_zip(self.components,
name,
dtype)])
return rval
@functools.wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
def has_no_data(space):
"""
Returns True if space can contain no data.
"""
return (isinstance(subspace, NullSpace) or
(isinstance(subspace, CompositeSpace) and
len(subspace.components) == 0))
if is_symbolic_batch(batch):
for subspace, subbatch in safe_zip(self.components, batch):
if not has_no_data(subspace):
return subspace._batch_size(is_numeric, subbatch)
return 0 # TODO: shouldn't this line return a Theano object?
else:
result = None
for subspace, subbatch in safe_zip(self.components, batch):
batch_size = subspace._batch_size(is_numeric, subbatch)
if has_no_data(subspace):
assert batch_size == 0
else:
if result is None:
result = batch_size
elif batch_size != result:
raise ValueError("All non-empty components of a "
"CompositeSpace should have the same "
"batch size, but we encountered "
"components with size %s, then %s." %
(result, batch_size))
return 0 if result is None else result
def _clean_dtype_arg(self, dtype):
"""
If dtype is None or a string, this returns a nested tuple that mirrors
the tree structure of this CompositeSpace, with dtype at the leaves.
If dtype is a nested tuple, this checks that it has the same tree
structure as this CompositeSpace.
"""
super_self = super(CompositeSpace, self)
def make_dtype_tree(dtype, space):
"""
Creates a nested tuple tree that mirrors the tree structure of
<space>, populating the leaves with <dtype>.
"""
if isinstance(space, CompositeSpace):
return tuple(make_dtype_tree(dtype, component)
for component in space.components)
else:
return super_self._clean_dtype_arg(dtype)
def check_dtype_tree(dtype, space):
"""
Verifies that a dtype tree mirrors the tree structure of <space>,
calling Space._clean_dtype_arg on the leaves.
"""
if isinstance(space, CompositeSpace):
if not isinstance(dtype, tuple):
raise TypeError("Tree structure mismatch.")
return tuple(check_dtype_tree(dt, c)
for dt, c in safe_zip(dtype, space.components))
else:
if not (dtype is None or isinstance(dtype, str)):
raise TypeError("Tree structure mismatch.")
return super_self._clean_dtype_arg(dtype)
if dtype is None or isinstance(dtype, str):
dtype = super_self._clean_dtype_arg(dtype)
return make_dtype_tree(dtype, self)
else:
return check_dtype_tree(dtype, self)
class NullSpace(Space):
"""
A space that contains no data. As such, it has the following quirks:
* Its validate()/np_validate() methods only accept None.
* Its dtype string is "Nullspace's dtype".
* The source name associated to this Space is the empty string ('').
"""
# NullSpaces don't support validation callbacks, since they only take None
# as data batches.
def __init__(self):
super(NullSpace, self).__init__()
def __str__(self):
"""
.. todo::
WRITEME
"""
return "NullSpace"
def __eq__(self, other):
"""
.. todo::
WRITEME
"""
return type(self) == type(other)
def __hash__(self):
"""
.. todo::
WRITEME
"""
return hash(type(self))
@property
def dtype(self):
"""
.. todo::
WRITEME
"""
return "%s's dtype" % self.__class__.__name__
@dtype.setter
def dtype(self, new_dtype):
"""
.. todo::
WRITEME
"""
if new_dtype != self.dtype:
raise TypeError('%s can only take the bogus dtype "%s"' %
(self.__class__.__name__,
self.dtype))
# otherwise, do nothing
@functools.wraps(Space.make_theano_batch)
def make_theano_batch(self, name=None, dtype=None):
return None
@functools.wraps(Space._validate_impl)
def _validate_impl(self, is_numeric, batch):
if batch is not None:
raise TypeError('NullSpace only accepts None, as a dummy data '
'batch. Instead, got %s of type %s'
% (batch, type(batch)))
@functools.wraps(Space._format_as_impl)
def _format_as_impl(self, is_numeric, batch, space):
assert isinstance(space, NullSpace)
return None
@functools.wraps(Space._batch_size_impl)
def _batch_size_impl(self, is_numeric, batch):
# There is no way to know how many examples would actually
# have been in the batch, since it is empty. We return 0.
self._validate(is_numeric, batch)
return 0
|
bsd-3-clause
|
[
624,
199,
15711,
626,
5627,
4212,
5477,
7883,
787,
7871,
199,
199,
24625,
402,
4154,
1709,
883,
506,
2455,
379,
465,
7798,
590,
5793,
316,
199,
368,
5477,
4601,
370,
4573,
14,
5723,
3992,
5627,
4212,
314,
199,
4106,
7883,
1077,
506,
11159,
465,
14377,
15,
4714,
199,
3669,
14,
199,
199,
1858,
2893,
12,
314,
11388,
7643,
1021,
2951,
8469,
282,
199,
4106,
4601,
543,
282,
5477,
12,
436,
314,
1402,
883,
5793,
199,
13007,
7883,
543,
282,
3634,
21699,
14,
710,
19140,
18,
3177,
1142,
199,
13063,
83,
282,
5477,
4601,
465,
376,
1834,
12,
436,
314,
1402,
199,
2425,
5793,
3382,
7883,
543,
282,
499,
36,
17461,
14,
199,
199,
1378,
1852,
1709,
465,
8605,
465,
3962,
12,
1709,
1077,
506,
199,
8938,
315,
2895,
402,
428,
4285,
12,
7830,
2419,
315,
2895,
402,
199,
10548,
402,
8752,
6204,
12,
5423,
14,
710,
1402,
1077,
2597,
506,
199,
8938,
370,
5793,
3382,
7883,
1808,
282,
7809,
199,
6676,
21484,
687,
314,
27959,
18,
14,
6676,
859,
14,
199,
199,
1918,
19326,
1021,
365,
4346,
880,
626,
314,
1402,
883,
4165,
199,
10058,
24241,
402,
4153,
652,
4839,
436,
4052,
24241,
402,
4704,
199,
390,
911,
7389,
1380,
13882,
1958,
543,
1163,
4184,
402,
199,
1589,
3555,
14,
710,
1402,
2597,
4440,
19326,
2251,
14448,
199,
475,
18310,
2633,
2839,
8752,
4137,
10671,
2895,
315,
199,
1589,
2451,
4601,
14,
199,
624,
199,
363,
8149,
363,
275,
298,
41,
290,
22311,
70,
10723,
2,
199,
363,
7307,
363,
275,
298,
7384,
7129,
13,
7409,
12,
1910,
4380,
2124,
477,
603,
1888,
3093,
2,
199,
363,
22461,
363,
275,
2097,
41,
290,
22311,
70,
10723,
937,
199,
363,
1682,
363,
275,
298,
19,
13,
8501,
6289,
2,
199,
363,
26665,
363,
275,
298,
44,
1311,
33,
16871,
2,
199,
363,
2123,
363,
275,
298,
647,
4643,
13,
2374,
32,
3098,
2634,
2,
199,
199,
646,
9143,
199,
646,
3598,
199,
646,
2680,
465,
980,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
646,
14377,
199,
646,
14377,
14,
4421,
199,
504,
14377,
492,
2345,
199,
504,
14377,
14,
3128,
492,
5878,
804,
199,
504,
14377,
14,
71,
1618,
14,
411,
492,
664,
63,
1757,
63,
1459,
199,
504,
14377,
14,
16647,
14,
16309,
14,
466,
492,
445,
28613,
804,
199,
504,
27959,
18,
14,
1208,
492,
1134,
63,
4115,
63,
1313,
12,
5048,
63,
3065,
12,
5709,
56,
12,
14018,
199,
504,
27959,
18,
14,
908,
14,
1375,
63,
908,
492,
7309,
19942,
7772,
199,
199,
692,
14377,
14,
4421,
14,
4296,
63,
4421,
26,
272,
327,
2136,
5715,
7026,
14,
4421,
365,
2808,
272,
492,
7026,
14,
4421,
421,
199,
318,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
11944,
304,
272,
408,
272,
24425,
402,
365,
63,
22836,
63,
2912,
342,
436,
365,
63,
6677,
63,
2912,
1252,
272,
1803,
715,
17963,
11944,
342,
2529,
715,
367,
1006,
7323,
402,
272,
334,
19614,
19306,
9,
3522,
14,
339,
3897,
272,
4143,
272,
3522,
520,
1263,
8950,
503,
13673,
3522,
14,
267,
961,
6952,
2680,
14,
8237,
12,
14377,
14,
71,
1618,
14,
2773,
12,
488,
12,
503,
282,
334,
6376,
9,
267,
2008,
2337,
1618,
14,
339,
11944,
520,
805,
14,
267,
437,
21603,
805,
402,
1263,
2222,
13,
16907,
3522,
626,
2529,
715,
503,
756,
14,
272,
408,
272,
327,
32754,
397,
1263,
27506,
2124,
7643,
19593,
626,
4898,
27572,
65,
917,
590,
4926,
13,
388,
11614,
272,
327,
1808,
6032,
5548,
7830,
2419,
6032,
6346,
14,
272,
702,
440,
1228,
8,
2912,
12,
769,
9,
339,
327,
3918,
13,
2003,
19593,
4066,
465,
488,
503,
6248,
787,
1686,
8950,
436,
13673,
272,
327,
19593,
14,
272,
327,
272,
327,
13870,
7313,
26,
781,
5121,
2839,
272,
327,
365,
63,
22836,
63,
2912,
8,
2638,
14,
1875,
63,
32057,
63,
2912,
1012,
370,
3544,
506,
715,
12,
2755,
340,
272,
327,
4601,
365,
376,
2701,
27506,
2124,
7643,
14,
272,
340,
3522,
365,
488,
503,
334,
6074,
8,
2912,
12,
2008,
9,
436,
822,
8,
2912,
9,
508,
378,
304,
267,
372,
715,
339,
340,
1228,
8,
2912,
12,
2008,
304,
267,
1007,
2912,
63,
2604,
275,
2008,
1547,
374,
63,
2912,
63,
452,
8,
66,
12,
11944,
9,
639,
367,
330,
315,
3522,
9,
267,
754,
275,
1006,
8,
954,
2912,
63,
2604,
9,
398,
327,
710,
1007,
2912,
63,
2604,
1471,
506,
1006,
2549,
12,
503,
1006,
3055,
12,
440,
282,
13667,
14,
267,
702,
754,
508,
1263,
8,
954,
2912,
63,
2604,
395,
1689,
16907,
3522,
10530,
282,
298,
1740,
298,
2664,
4167,
402,
8950,
436,
298,
1740,
298,
22836,
1007,
14896,
14,
961,
298,
1740,
298,
5626,
7078,
5992,
2685,
267,
372,
754,
272,
587,
26,
267,
372,
11944,
8,
2912,
9,
421,
199,
318,
365,
63,
22836,
63,
2912,
8,
2912,
304,
272,
408,
272,
1803,
715,
340,
3522,
365,
282,
13673,
1750,
14,
339,
3390,
626,
282,
3522,
1443,
506,
3865,
282,
13673,
436,
8950,
1750,
272,
334,
69,
14,
71,
14,
6248,
367,
2701,
27506,
2124,
23415,
12,
488,
367,
12119,
23415,
680,
272,
408,
339,
372,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
2400,
671,
26,
1228,
8,
88,
12,
14377,
14,
71,
1618,
14,
2773,
430,
421,
199,
318,
365,
63,
6677,
63,
2912,
8,
2912,
304,
272,
408,
272,
1803,
715,
340,
3522,
365,
282,
8950,
1750,
14,
339,
3390,
626,
282,
3522,
1443,
506,
3865,
282,
13673,
436,
8950,
1750,
272,
334,
69,
14,
71,
14,
6248,
367,
2701,
27506,
2124,
23415,
12,
488,
367,
12119,
23415,
680,
272,
408,
272,
347,
365,
63,
6677,
8,
2912,
304,
267,
327,
14911,
314,
283,
35,
28613,
7,
1059,
370,
5126,
16306,
267,
327,
14377,
14,
16647,
14,
16309,
1380,
652,
365,
440,
2808,
267,
372,
334,
6074,
8,
2912,
12,
980,
14,
8237,
9,
503,
355,
7026,
14,
4421,
14,
30962,
8,
2912,
9,
503,
355,
620,
8,
466,
8,
2912,
430,
508,
3886,
466,
283,
35,
28613,
8423,
531,
339,
372,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
365,
63,
6677,
9,
421,
199,
318,
485,
7253,
63,
475,
63
] |
[
199,
15711,
626,
5627,
4212,
5477,
7883,
787,
7871,
199,
199,
24625,
402,
4154,
1709,
883,
506,
2455,
379,
465,
7798,
590,
5793,
316,
199,
368,
5477,
4601,
370,
4573,
14,
5723,
3992,
5627,
4212,
314,
199,
4106,
7883,
1077,
506,
11159,
465,
14377,
15,
4714,
199,
3669,
14,
199,
199,
1858,
2893,
12,
314,
11388,
7643,
1021,
2951,
8469,
282,
199,
4106,
4601,
543,
282,
5477,
12,
436,
314,
1402,
883,
5793,
199,
13007,
7883,
543,
282,
3634,
21699,
14,
710,
19140,
18,
3177,
1142,
199,
13063,
83,
282,
5477,
4601,
465,
376,
1834,
12,
436,
314,
1402,
199,
2425,
5793,
3382,
7883,
543,
282,
499,
36,
17461,
14,
199,
199,
1378,
1852,
1709,
465,
8605,
465,
3962,
12,
1709,
1077,
506,
199,
8938,
315,
2895,
402,
428,
4285,
12,
7830,
2419,
315,
2895,
402,
199,
10548,
402,
8752,
6204,
12,
5423,
14,
710,
1402,
1077,
2597,
506,
199,
8938,
370,
5793,
3382,
7883,
1808,
282,
7809,
199,
6676,
21484,
687,
314,
27959,
18,
14,
6676,
859,
14,
199,
199,
1918,
19326,
1021,
365,
4346,
880,
626,
314,
1402,
883,
4165,
199,
10058,
24241,
402,
4153,
652,
4839,
436,
4052,
24241,
402,
4704,
199,
390,
911,
7389,
1380,
13882,
1958,
543,
1163,
4184,
402,
199,
1589,
3555,
14,
710,
1402,
2597,
4440,
19326,
2251,
14448,
199,
475,
18310,
2633,
2839,
8752,
4137,
10671,
2895,
315,
199,
1589,
2451,
4601,
14,
199,
624,
199,
363,
8149,
363,
275,
298,
41,
290,
22311,
70,
10723,
2,
199,
363,
7307,
363,
275,
298,
7384,
7129,
13,
7409,
12,
1910,
4380,
2124,
477,
603,
1888,
3093,
2,
199,
363,
22461,
363,
275,
2097,
41,
290,
22311,
70,
10723,
937,
199,
363,
1682,
363,
275,
298,
19,
13,
8501,
6289,
2,
199,
363,
26665,
363,
275,
298,
44,
1311,
33,
16871,
2,
199,
363,
2123,
363,
275,
298,
647,
4643,
13,
2374,
32,
3098,
2634,
2,
199,
199,
646,
9143,
199,
646,
3598,
199,
646,
2680,
465,
980,
199,
504,
14377,
14,
5819,
14,
4174,
14,
4912,
492,
4945,
199,
646,
14377,
199,
646,
14377,
14,
4421,
199,
504,
14377,
492,
2345,
199,
504,
14377,
14,
3128,
492,
5878,
804,
199,
504,
14377,
14,
71,
1618,
14,
411,
492,
664,
63,
1757,
63,
1459,
199,
504,
14377,
14,
16647,
14,
16309,
14,
466,
492,
445,
28613,
804,
199,
504,
27959,
18,
14,
1208,
492,
1134,
63,
4115,
63,
1313,
12,
5048,
63,
3065,
12,
5709,
56,
12,
14018,
199,
504,
27959,
18,
14,
908,
14,
1375,
63,
908,
492,
7309,
19942,
7772,
199,
199,
692,
14377,
14,
4421,
14,
4296,
63,
4421,
26,
272,
327,
2136,
5715,
7026,
14,
4421,
365,
2808,
272,
492,
7026,
14,
4421,
421,
199,
318,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
11944,
304,
272,
408,
272,
24425,
402,
365,
63,
22836,
63,
2912,
342,
436,
365,
63,
6677,
63,
2912,
1252,
272,
1803,
715,
17963,
11944,
342,
2529,
715,
367,
1006,
7323,
402,
272,
334,
19614,
19306,
9,
3522,
14,
339,
3897,
272,
4143,
272,
3522,
520,
1263,
8950,
503,
13673,
3522,
14,
267,
961,
6952,
2680,
14,
8237,
12,
14377,
14,
71,
1618,
14,
2773,
12,
488,
12,
503,
282,
334,
6376,
9,
267,
2008,
2337,
1618,
14,
339,
11944,
520,
805,
14,
267,
437,
21603,
805,
402,
1263,
2222,
13,
16907,
3522,
626,
2529,
715,
503,
756,
14,
272,
408,
272,
327,
32754,
397,
1263,
27506,
2124,
7643,
19593,
626,
4898,
27572,
65,
917,
590,
4926,
13,
388,
11614,
272,
327,
1808,
6032,
5548,
7830,
2419,
6032,
6346,
14,
272,
702,
440,
1228,
8,
2912,
12,
769,
9,
339,
327,
3918,
13,
2003,
19593,
4066,
465,
488,
503,
6248,
787,
1686,
8950,
436,
13673,
272,
327,
19593,
14,
272,
327,
272,
327,
13870,
7313,
26,
781,
5121,
2839,
272,
327,
365,
63,
22836,
63,
2912,
8,
2638,
14,
1875,
63,
32057,
63,
2912,
1012,
370,
3544,
506,
715,
12,
2755,
340,
272,
327,
4601,
365,
376,
2701,
27506,
2124,
7643,
14,
272,
340,
3522,
365,
488,
503,
334,
6074,
8,
2912,
12,
2008,
9,
436,
822,
8,
2912,
9,
508,
378,
304,
267,
372,
715,
339,
340,
1228,
8,
2912,
12,
2008,
304,
267,
1007,
2912,
63,
2604,
275,
2008,
1547,
374,
63,
2912,
63,
452,
8,
66,
12,
11944,
9,
639,
367,
330,
315,
3522,
9,
267,
754,
275,
1006,
8,
954,
2912,
63,
2604,
9,
398,
327,
710,
1007,
2912,
63,
2604,
1471,
506,
1006,
2549,
12,
503,
1006,
3055,
12,
440,
282,
13667,
14,
267,
702,
754,
508,
1263,
8,
954,
2912,
63,
2604,
395,
1689,
16907,
3522,
10530,
282,
298,
1740,
298,
2664,
4167,
402,
8950,
436,
298,
1740,
298,
22836,
1007,
14896,
14,
961,
298,
1740,
298,
5626,
7078,
5992,
2685,
267,
372,
754,
272,
587,
26,
267,
372,
11944,
8,
2912,
9,
421,
199,
318,
365,
63,
22836,
63,
2912,
8,
2912,
304,
272,
408,
272,
1803,
715,
340,
3522,
365,
282,
13673,
1750,
14,
339,
3390,
626,
282,
3522,
1443,
506,
3865,
282,
13673,
436,
8950,
1750,
272,
334,
69,
14,
71,
14,
6248,
367,
2701,
27506,
2124,
23415,
12,
488,
367,
12119,
23415,
680,
272,
408,
339,
372,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
2400,
671,
26,
1228,
8,
88,
12,
14377,
14,
71,
1618,
14,
2773,
430,
421,
199,
318,
365,
63,
6677,
63,
2912,
8,
2912,
304,
272,
408,
272,
1803,
715,
340,
3522,
365,
282,
8950,
1750,
14,
339,
3390,
626,
282,
3522,
1443,
506,
3865,
282,
13673,
436,
8950,
1750,
272,
334,
69,
14,
71,
14,
6248,
367,
2701,
27506,
2124,
23415,
12,
488,
367,
12119,
23415,
680,
272,
408,
272,
347,
365,
63,
6677,
8,
2912,
304,
267,
327,
14911,
314,
283,
35,
28613,
7,
1059,
370,
5126,
16306,
267,
327,
14377,
14,
16647,
14,
16309,
1380,
652,
365,
440,
2808,
267,
372,
334,
6074,
8,
2912,
12,
980,
14,
8237,
9,
503,
355,
7026,
14,
4421,
14,
30962,
8,
2912,
9,
503,
355,
620,
8,
466,
8,
2912,
430,
508,
3886,
466,
283,
35,
28613,
8423,
531,
339,
372,
485,
374,
63,
2912,
63,
452,
8,
2912,
12,
365,
63,
6677,
9,
421,
199,
318,
485,
7253,
63,
475,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
devs1991/test_edx_docmode
|
venv/lib/python2.7/site-packages/numpy/numarray/util.py
|
94
|
1547
|
import os
import numpy as np
__all__ = ['MathDomainError', 'UnderflowError', 'NumOverflowError',
'handleError', 'get_numarray_include_dirs']
class MathDomainError(ArithmeticError):
pass
class UnderflowError(ArithmeticError):
pass
class NumOverflowError(OverflowError, ArithmeticError):
pass
def handleError(errorStatus, sourcemsg):
"""Take error status and use error mode to handle it."""
modes = np.geterr()
if errorStatus & np.FPE_INVALID:
if modes['invalid'] == "warn":
print "Warning: Encountered invalid numeric result(s)", sourcemsg
if modes['invalid'] == "raise":
raise MathDomainError(sourcemsg)
if errorStatus & np.FPE_DIVIDEBYZERO:
if modes['dividebyzero'] == "warn":
print "Warning: Encountered divide by zero(s)", sourcemsg
if modes['dividebyzero'] == "raise":
raise ZeroDivisionError(sourcemsg)
if errorStatus & np.FPE_OVERFLOW:
if modes['overflow'] == "warn":
print "Warning: Encountered overflow(s)", sourcemsg
if modes['overflow'] == "raise":
raise NumOverflowError(sourcemsg)
if errorStatus & np.FPE_UNDERFLOW:
if modes['underflow'] == "warn":
print "Warning: Encountered underflow(s)", sourcemsg
if modes['underflow'] == "raise":
raise UnderflowError(sourcemsg)
def get_numarray_include_dirs():
base = os.path.dirname(np.__file__)
newdirs = [os.path.join(base, 'numarray', 'include')]
return newdirs
|
agpl-3.0
|
[
646,
747,
199,
646,
2680,
465,
980,
199,
199,
363,
452,
363,
275,
788,
18568,
7705,
547,
297,
283,
16001,
15160,
297,
283,
5667,
21821,
297,
1779,
283,
2479,
547,
297,
283,
362,
63,
1507,
1144,
63,
2613,
63,
3220,
418,
199,
199,
533,
21066,
7705,
547,
8,
26291,
18764,
547,
304,
272,
986,
421,
199,
533,
25010,
15160,
8,
26291,
18764,
547,
304,
272,
986,
421,
199,
533,
16817,
21821,
8,
21821,
12,
31153,
18764,
547,
304,
272,
986,
421,
199,
318,
2429,
547,
8,
705,
3694,
12,
1350,
1328,
304,
272,
408,
27200,
1125,
2004,
436,
675,
1125,
818,
370,
2429,
652,
1041,
272,
12404,
275,
980,
14,
303,
22406,
342,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
9692,
26,
267,
340,
12404,
459,
3197,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
3866,
8950,
754,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
3197,
418,
508,
298,
3730,
582,
288,
746,
21066,
7705,
547,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
1914,
5437,
37,
8285,
24655,
26,
267,
340,
12404,
459,
16081,
991,
4262,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
23003,
701,
4697,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
16081,
991,
4262,
418,
508,
298,
3730,
582,
288,
746,
25838,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
14336,
17114,
26,
267,
340,
12404,
459,
14108,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
15784,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
14108,
418,
508,
298,
3730,
582,
288,
746,
16817,
21821,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
6131,
540,
17114,
26,
267,
340,
12404,
459,
7138,
1659,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
1334,
1659,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
7138,
1659,
418,
508,
298,
3730,
582,
288,
746,
25010,
15160,
8,
1365,
1328,
9,
421,
199,
318,
664,
63,
1507,
1144,
63,
2613,
63,
3220,
837,
272,
1300,
275,
747,
14,
515,
14,
3475,
8,
1590,
855,
493,
3368,
272,
892,
3220,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
12,
283,
1507,
1144,
297,
283,
2613,
5440,
272,
372,
892,
3220,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
2680,
465,
980,
199,
199,
363,
452,
363,
275,
788,
18568,
7705,
547,
297,
283,
16001,
15160,
297,
283,
5667,
21821,
297,
1779,
283,
2479,
547,
297,
283,
362,
63,
1507,
1144,
63,
2613,
63,
3220,
418,
199,
199,
533,
21066,
7705,
547,
8,
26291,
18764,
547,
304,
272,
986,
421,
199,
533,
25010,
15160,
8,
26291,
18764,
547,
304,
272,
986,
421,
199,
533,
16817,
21821,
8,
21821,
12,
31153,
18764,
547,
304,
272,
986,
421,
199,
318,
2429,
547,
8,
705,
3694,
12,
1350,
1328,
304,
272,
408,
27200,
1125,
2004,
436,
675,
1125,
818,
370,
2429,
652,
1041,
272,
12404,
275,
980,
14,
303,
22406,
342,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
9692,
26,
267,
340,
12404,
459,
3197,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
3866,
8950,
754,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
3197,
418,
508,
298,
3730,
582,
288,
746,
21066,
7705,
547,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
1914,
5437,
37,
8285,
24655,
26,
267,
340,
12404,
459,
16081,
991,
4262,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
23003,
701,
4697,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
16081,
991,
4262,
418,
508,
298,
3730,
582,
288,
746,
25838,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
14336,
17114,
26,
267,
340,
12404,
459,
14108,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
15784,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
14108,
418,
508,
298,
3730,
582,
288,
746,
16817,
21821,
8,
1365,
1328,
9,
272,
340,
1125,
3694,
1253,
980,
14,
38,
1510,
63,
6131,
540,
17114,
26,
267,
340,
12404,
459,
7138,
1659,
418,
508,
298,
4050,
582,
288,
870,
298,
3849,
26,
3447,
12613,
1334,
1659,
8,
83,
4186,
1350,
1328,
267,
340,
12404,
459,
7138,
1659,
418,
508,
298,
3730,
582,
288,
746,
25010,
15160,
8,
1365,
1328,
9,
421,
199,
318,
664,
63,
1507,
1144,
63,
2613,
63,
3220,
837,
272,
1300,
275,
747,
14,
515,
14,
3475,
8,
1590,
855,
493,
3368,
272,
892,
3220,
275,
359,
736,
14,
515,
14,
904,
8,
1095,
12,
283,
1507,
1144,
297,
283,
2613,
5440,
272,
372,
892,
3220,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
start-jsk/jsk_apc
|
demos/instance_occlsegm/examples/synthetic2d/instance_image_fg_extraction/generate_item_data_mask_pred.py
|
2
|
2320
|
#!/usr/bin/env python
import argparse
import chainer
import fcn
import numpy as np
import tqdm
import instance_occlsegm_lib
from instance_occlsegm_lib.contrib import synthetic2d
def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
item_data_choices = list(
synthetic2d.datasets.InstanceImageDataset.item_data_dirs.keys()
)
parser.add_argument(
'--item-data',
default='arc2017_all',
choices=item_data_choices,
help='item data',
)
parser.add_argument('--gpu', '-g', type=int, default=0, help='gpu id')
args = parser.parse_args()
model = fcn.models.FCN8sAtOnce(n_class=2)
model_file = instance_occlsegm_lib.data.download(
url='https://drive.google.com/uc?id=1k7qCONNta6WDjqdXAXdem8rDQjWPWeFb',
md5='5739cb23249993428dcc67e6d763b00a',
)
chainer.serializers.load_npz(model_file, model)
chainer.cuda.get_device_from_id(args.gpu).use()
model.to_gpu()
dataset = synthetic2d.datasets.InstanceImageDataset(
item_data_dir=args.item_data, load_pred=False
)
obj_data_dir = dataset.item_data_dir
obj_names, obj_data = instance_occlsegm_lib.datasets.apc.\
arc2017.load_item_data(obj_data_dir, skip_known=False)
for obj_datum in tqdm.tqdm(obj_data):
img_file = obj_datum['img_file']
img = obj_datum['img']
lbl_fgbg = obj_datum['mask'].astype(np.int32)
x = fcn.datasets.transform_lsvrc2012_vgg16((img, lbl_fgbg))[0]
x = chainer.cuda.to_gpu(x)
with chainer.no_backprop_mode(), chainer.using_config('train', False):
model(x[None])
lbl_pred = model.xp.argmax(model.score.array, axis=1)
lbl_pred = chainer.cuda.to_cpu(lbl_pred)[0]
# lbl_fgbg = instance_occlsegm_lib.image.label2rgb(lbl_fgbg, img)
# lbl_pred = instance_occlsegm_lib.image.label2rgb(lbl_pred, img)
# instance_occlsegm_lib.io.imshow(
# instance_occlsegm_lib.image.tile([img, lbl_fgbg, lbl_pred]))
# instance_occlsegm_lib.io.waitkey()
mask_pred = lbl_pred.astype(np.uint8) * 255
mask_file = img_file + '.mask_pred.jpg'
instance_occlsegm_lib.io.imsave(mask_file, mask_pred)
if __name__ == '__main__':
main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
7534,
199,
199,
646,
20333,
199,
646,
289,
6413,
199,
646,
2680,
465,
980,
199,
646,
307,
81,
6428,
199,
199,
646,
1256,
63,
679,
429,
8359,
77,
63,
773,
199,
504,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2828,
492,
9560,
21231,
18,
68,
421,
199,
318,
2446,
837,
272,
1798,
275,
7534,
14,
10730,
8,
267,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
12,
272,
776,
272,
1242,
63,
576,
63,
4577,
275,
769,
8,
267,
9560,
21231,
18,
68,
14,
12281,
14,
3244,
3491,
9271,
14,
1053,
63,
576,
63,
3220,
14,
1612,
342,
272,
776,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
1053,
13,
576,
297,
267,
849,
534,
9912,
10680,
63,
452,
297,
267,
3415,
29,
1053,
63,
576,
63,
4577,
12,
267,
1720,
534,
1053,
666,
297,
272,
776,
272,
1798,
14,
525,
63,
2094,
4517,
6477,
297,
2475,
71,
297,
730,
29,
442,
12,
849,
29,
16,
12,
1720,
534,
6477,
1305,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
1402,
275,
289,
6413,
14,
992,
14,
4161,
46,
24,
83,
1271,
25690,
8,
78,
63,
533,
29,
18,
9,
272,
1402,
63,
493,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
576,
14,
4249,
8,
267,
1166,
534,
2859,
921,
9541,
14,
3098,
14,
957,
15,
947,
31,
344,
29,
17,
75,
23,
81,
17489,
502,
22,
16698,
74,
23097,
56,
9839,
23522,
24,
82,
11888,
74,
22512,
6004,
38,
66,
297,
267,
6128,
21,
534,
1641,
1355,
2894,
8001,
20,
5637,
1082,
1651,
68,
2055,
1822,
69,
22,
68,
24924,
66,
383,
65,
297,
272,
776,
272,
20333,
14,
12844,
14,
912,
63,
1590,
90,
8,
1238,
63,
493,
12,
1402,
9,
339,
20333,
14,
16309,
14,
362,
63,
1782,
63,
504,
63,
344,
8,
589,
14,
6477,
680,
1180,
342,
272,
1402,
14,
475,
63,
6477,
342,
339,
4789,
275,
9560,
21231,
18,
68,
14,
12281,
14,
3244,
3491,
9271,
8,
267,
1242,
63,
576,
63,
694,
29,
589,
14,
1053,
63,
576,
12,
2248,
63,
5991,
29,
797,
272,
776,
272,
1559,
63,
576,
63,
694,
275,
4789,
14,
1053,
63,
576,
63,
694,
272,
1559,
63,
1247,
12,
1559,
63,
576,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
12281,
14,
439,
67,
3134,
267,
14972,
10680,
14,
912,
63,
1053,
63,
576,
8,
1113,
63,
576,
63,
694,
12,
3372,
63,
3159,
29,
797,
9,
339,
367,
1559,
63,
18945,
315,
307,
81,
6428,
14,
84,
81,
6428,
8,
1113,
63,
576,
304,
267,
6050,
63,
493,
275,
1559,
63,
18945,
459,
4060,
63,
493,
418,
267,
6050,
275,
1559,
63,
18945,
459,
4060,
418,
267,
32375,
63,
70,
4908,
71,
275,
1559,
63,
18945,
459,
2629,
2278,
6041,
8,
1590,
14,
442,
708,
9,
398,
671,
275,
289,
6413,
14,
12281,
14,
4711,
63,
478,
86,
1195,
7409,
63,
27948,
975,
1332,
4060,
12,
32375,
63,
70,
4908,
71,
11515,
16,
61,
267,
671,
275,
20333,
14,
16309,
14,
475,
63,
6477,
8,
88,
9,
267,
543,
20333,
14,
889,
63,
31113,
63,
632,
1062,
20333,
14,
4941,
63,
888,
360,
2834,
297,
756,
304,
288,
1402,
8,
88,
59,
403,
566,
288,
32375,
63,
5991,
275,
1402,
14,
9290,
14,
16383,
8,
1238,
14,
3397,
14,
1144,
12,
3114,
29,
17,
9,
267,
32375,
63,
5991,
275,
20333,
14,
16309,
14,
475,
63,
3541,
8,
18842,
63,
5991,
2788,
16,
61,
267,
327,
32375,
63,
70,
4908,
71,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
1302,
18,
10090,
8,
18842,
63,
70,
4908,
71,
12,
6050,
9,
267,
327,
32375,
63,
5991,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
1302,
18,
10090,
8,
18842,
63,
5991,
12,
6050,
9,
267,
327,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
20413,
8,
267,
327,
259,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
7172,
779,
4060,
12,
32375,
63,
70,
4908,
71,
12,
32375,
63,
5991,
2459,
267,
327,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
2573,
498,
342,
398,
3656,
63,
5991,
275,
32375,
63,
5991,
14,
6041,
8,
1590,
14,
1635,
24,
9,
627,
5450,
267,
3656,
63,
493,
275,
6050,
63,
493,
435,
1987,
2629,
63,
5991,
14,
8476,
7,
267,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
11171,
811,
8,
2629,
63,
493,
12,
3656,
63,
5991,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
7534,
199,
199,
646,
20333,
199,
646,
289,
6413,
199,
646,
2680,
465,
980,
199,
646,
307,
81,
6428,
199,
199,
646,
1256,
63,
679,
429,
8359,
77,
63,
773,
199,
504,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2828,
492,
9560,
21231,
18,
68,
421,
199,
318,
2446,
837,
272,
1798,
275,
7534,
14,
10730,
8,
267,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
12,
272,
776,
272,
1242,
63,
576,
63,
4577,
275,
769,
8,
267,
9560,
21231,
18,
68,
14,
12281,
14,
3244,
3491,
9271,
14,
1053,
63,
576,
63,
3220,
14,
1612,
342,
272,
776,
272,
1798,
14,
525,
63,
2094,
8,
267,
2850,
1053,
13,
576,
297,
267,
849,
534,
9912,
10680,
63,
452,
297,
267,
3415,
29,
1053,
63,
576,
63,
4577,
12,
267,
1720,
534,
1053,
666,
297,
272,
776,
272,
1798,
14,
525,
63,
2094,
4517,
6477,
297,
2475,
71,
297,
730,
29,
442,
12,
849,
29,
16,
12,
1720,
534,
6477,
1305,
358,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
1402,
275,
289,
6413,
14,
992,
14,
4161,
46,
24,
83,
1271,
25690,
8,
78,
63,
533,
29,
18,
9,
272,
1402,
63,
493,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
576,
14,
4249,
8,
267,
1166,
534,
2859,
921,
9541,
14,
3098,
14,
957,
15,
947,
31,
344,
29,
17,
75,
23,
81,
17489,
502,
22,
16698,
74,
23097,
56,
9839,
23522,
24,
82,
11888,
74,
22512,
6004,
38,
66,
297,
267,
6128,
21,
534,
1641,
1355,
2894,
8001,
20,
5637,
1082,
1651,
68,
2055,
1822,
69,
22,
68,
24924,
66,
383,
65,
297,
272,
776,
272,
20333,
14,
12844,
14,
912,
63,
1590,
90,
8,
1238,
63,
493,
12,
1402,
9,
339,
20333,
14,
16309,
14,
362,
63,
1782,
63,
504,
63,
344,
8,
589,
14,
6477,
680,
1180,
342,
272,
1402,
14,
475,
63,
6477,
342,
339,
4789,
275,
9560,
21231,
18,
68,
14,
12281,
14,
3244,
3491,
9271,
8,
267,
1242,
63,
576,
63,
694,
29,
589,
14,
1053,
63,
576,
12,
2248,
63,
5991,
29,
797,
272,
776,
272,
1559,
63,
576,
63,
694,
275,
4789,
14,
1053,
63,
576,
63,
694,
272,
1559,
63,
1247,
12,
1559,
63,
576,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
12281,
14,
439,
67,
3134,
267,
14972,
10680,
14,
912,
63,
1053,
63,
576,
8,
1113,
63,
576,
63,
694,
12,
3372,
63,
3159,
29,
797,
9,
339,
367,
1559,
63,
18945,
315,
307,
81,
6428,
14,
84,
81,
6428,
8,
1113,
63,
576,
304,
267,
6050,
63,
493,
275,
1559,
63,
18945,
459,
4060,
63,
493,
418,
267,
6050,
275,
1559,
63,
18945,
459,
4060,
418,
267,
32375,
63,
70,
4908,
71,
275,
1559,
63,
18945,
459,
2629,
2278,
6041,
8,
1590,
14,
442,
708,
9,
398,
671,
275,
289,
6413,
14,
12281,
14,
4711,
63,
478,
86,
1195,
7409,
63,
27948,
975,
1332,
4060,
12,
32375,
63,
70,
4908,
71,
11515,
16,
61,
267,
671,
275,
20333,
14,
16309,
14,
475,
63,
6477,
8,
88,
9,
267,
543,
20333,
14,
889,
63,
31113,
63,
632,
1062,
20333,
14,
4941,
63,
888,
360,
2834,
297,
756,
304,
288,
1402,
8,
88,
59,
403,
566,
288,
32375,
63,
5991,
275,
1402,
14,
9290,
14,
16383,
8,
1238,
14,
3397,
14,
1144,
12,
3114,
29,
17,
9,
267,
32375,
63,
5991,
275,
20333,
14,
16309,
14,
475,
63,
3541,
8,
18842,
63,
5991,
2788,
16,
61,
267,
327,
32375,
63,
70,
4908,
71,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
1302,
18,
10090,
8,
18842,
63,
70,
4908,
71,
12,
6050,
9,
267,
327,
32375,
63,
5991,
275,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
1302,
18,
10090,
8,
18842,
63,
5991,
12,
6050,
9,
267,
327,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
20413,
8,
267,
327,
259,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
1569,
14,
7172,
779,
4060,
12,
32375,
63,
70,
4908,
71,
12,
32375,
63,
5991,
2459,
267,
327,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
2573,
498,
342,
398,
3656,
63,
5991,
275,
32375,
63,
5991,
14,
6041,
8,
1590,
14,
1635,
24,
9,
627,
5450,
267,
3656,
63,
493,
275,
6050,
63,
493,
435,
1987,
2629,
63,
5991,
14,
8476,
7,
267,
1256,
63,
679,
429,
8359,
77,
63,
773,
14,
2308,
14,
11171,
811,
8,
2629,
63,
493,
12,
3656,
63,
5991,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Jgarcia-IAS/localizacion
|
openerp/addons-extra/odoo-pruebas/odoo-server/addons/l10n_tr/__openerp__.py
|
170
|
2160
|
# -*- 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/>.
#
##############################################################################
{
'name': 'Turkey - Accounting',
'version': '1.beta',
'category': 'Localization/Account Charts',
'description': """
Türkiye için Tek düzen hesap planı şablonu OpenERP Modülü.
==========================================================
Bu modül kurulduktan sonra, Muhasebe yapılandırma sihirbazı çalışır
* Sihirbaz sizden hesap planı şablonu, planın kurulacağı şirket, banka hesap
bilgileriniz, ilgili para birimi gibi bilgiler isteyecek.
""",
'author': 'Ahmet Altınışık',
'maintainer':'https://launchpad.net/~openerp-turkey',
'website':'https://launchpad.net/openerp-turkey',
'depends': [
'account',
'base_vat',
'account_chart',
],
'data': [
'account_code_template.xml',
'account_tdhp_turkey.xml',
'account_tax_code_template.xml',
'account_chart_template.xml',
'account_tax_template.xml',
'l10n_tr_wizard.xml',
],
'demo': [],
'installable': True,
'images': ['images/chart_l10n_tr_1.jpg','images/chart_l10n_tr_2.jpg','images/chart_l10n_tr_3.jpg'],
}
# 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,
91,
272,
283,
354,
356,
283,
27438,
498,
446,
9973,
316,
297,
272,
283,
1023,
356,
283,
17,
14,
5683,
297,
272,
283,
3710,
356,
283,
5339,
2072,
15,
6009,
24874,
83,
297,
272,
283,
1802,
356,
408,
199,
52,
17709,
82,
8810,
8048,
284,
15368,
262,
377,
5711,
366,
17709,
5193,
394,
397,
439,
8683,
28871,
221,
130,
254,
371,
5298,
85,
7653,
22035,
17709,
76,
17709,
14,
199,
12813,
17575,
199,
199,
1713,
3413,
17709,
76,
1022,
300,
854,
3210,
12990,
27970,
345,
12,
603,
22451,
482,
1235,
612,
439,
28871,
9688,
28871,
82,
391,
13877,
72,
723,
6185,
28871,
13333,
101,
279,
28871,
130,
254,
28871,
82,
272,
627,
428,
24278,
723,
6185,
308,
565,
848,
394,
397,
439,
8683,
28871,
221,
130,
254,
371,
5298,
85,
12,
8683,
28871,
78,
1022,
300,
348,
30632,
129,
254,
28871,
221,
130,
254,
723,
75,
386,
12,
16297,
65,
394,
397,
439,
489,
330,
382,
71,
3566,
262,
565,
12,
284,
9783,
1638,
12665,
12111,
322,
2664,
486,
1892,
73,
330,
382,
71,
3566,
365,
266,
8048,
301,
75,
14,
272,
10327,
272,
283,
2502,
356,
283,
33,
72,
10207,
437,
4116,
28871,
78,
28871,
130,
254,
28871,
75,
297,
272,
283,
26665,
5242,
2859,
921,
9850,
6226,
14,
846,
22500,
11267,
13,
16218,
498,
297,
272,
283,
7360,
5242,
2859,
921,
9850,
6226,
14,
846,
15,
11267,
13,
16218,
498,
297,
272,
283,
8912,
356,
359,
267,
283,
2048,
297,
267,
283,
1095,
63,
16305,
297,
267,
283,
2048,
63,
9019,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
2048,
63,
600,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
2076,
12025,
63,
16218,
498,
14,
1652,
297,
267,
283,
2048,
63,
5530,
63,
600,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
9019,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
5530,
63,
1160,
14,
1652,
297,
267,
283,
76,
709,
78,
63,
454,
63,
9819,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
4782,
356,
788,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
17,
14,
8476,
1673,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
18,
14,
8476,
1673,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
19,
14,
8476,
995,
199,
93,
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
] |
[
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,
91,
272,
283,
354,
356,
283,
27438,
498,
446,
9973,
316,
297,
272,
283,
1023,
356,
283,
17,
14,
5683,
297,
272,
283,
3710,
356,
283,
5339,
2072,
15,
6009,
24874,
83,
297,
272,
283,
1802,
356,
408,
199,
52,
17709,
82,
8810,
8048,
284,
15368,
262,
377,
5711,
366,
17709,
5193,
394,
397,
439,
8683,
28871,
221,
130,
254,
371,
5298,
85,
7653,
22035,
17709,
76,
17709,
14,
199,
12813,
17575,
199,
199,
1713,
3413,
17709,
76,
1022,
300,
854,
3210,
12990,
27970,
345,
12,
603,
22451,
482,
1235,
612,
439,
28871,
9688,
28871,
82,
391,
13877,
72,
723,
6185,
28871,
13333,
101,
279,
28871,
130,
254,
28871,
82,
272,
627,
428,
24278,
723,
6185,
308,
565,
848,
394,
397,
439,
8683,
28871,
221,
130,
254,
371,
5298,
85,
12,
8683,
28871,
78,
1022,
300,
348,
30632,
129,
254,
28871,
221,
130,
254,
723,
75,
386,
12,
16297,
65,
394,
397,
439,
489,
330,
382,
71,
3566,
262,
565,
12,
284,
9783,
1638,
12665,
12111,
322,
2664,
486,
1892,
73,
330,
382,
71,
3566,
365,
266,
8048,
301,
75,
14,
272,
10327,
272,
283,
2502,
356,
283,
33,
72,
10207,
437,
4116,
28871,
78,
28871,
130,
254,
28871,
75,
297,
272,
283,
26665,
5242,
2859,
921,
9850,
6226,
14,
846,
22500,
11267,
13,
16218,
498,
297,
272,
283,
7360,
5242,
2859,
921,
9850,
6226,
14,
846,
15,
11267,
13,
16218,
498,
297,
272,
283,
8912,
356,
359,
267,
283,
2048,
297,
267,
283,
1095,
63,
16305,
297,
267,
283,
2048,
63,
9019,
297,
272,
2156,
272,
283,
576,
356,
359,
267,
283,
2048,
63,
600,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
2076,
12025,
63,
16218,
498,
14,
1652,
297,
267,
283,
2048,
63,
5530,
63,
600,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
9019,
63,
1160,
14,
1652,
297,
267,
283,
2048,
63,
5530,
63,
1160,
14,
1652,
297,
267,
283,
76,
709,
78,
63,
454,
63,
9819,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
21762,
356,
715,
12,
272,
283,
4782,
356,
788,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
17,
14,
8476,
1673,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
18,
14,
8476,
1673,
4782,
15,
9019,
63,
76,
709,
78,
63,
454,
63,
19,
14,
8476,
995,
199,
93,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
unreal666/namebench
|
libnamebench/cli.py
|
173
|
4760
|
#!/usr/bin/env python
# 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.
"""Simple DNS server comparison benchmarking tool.
Designed to assist system administrators in selection and prioritization.
"""
__author__ = 'tstromberg@google.com (Thomas Stromberg)'
import datetime
import math
import sys
import base_ui
import conn_quality
import nameserver_list
class NameBenchCli(base_ui.BaseUI):
"""A command-line implementation of the namebench workflow."""
def __init__(self, options):
self.options = options
self.last_msg = (None, None, None, None)
self.last_msg_count_posted = 0
super(NameBenchCli, self).__init__()
def UpdateStatus(self, msg, count=None, total=None, error=False, debug=False):
"""Status updates for the command-line. A lot of voodoo here."""
if self.last_msg == (msg, count, total, error):
return None
if debug:
return None
if error:
print
print '* ERROR: %s' % msg
sys.exit(2)
elif not total:
self.last_msg_count_posted = 0
sys.stdout.write('- %s\n' % msg)
elif self.last_msg[0] != msg:
self.last_msg_count_posted = 0
sys.stdout.write('- %s: %s/%s' % (msg, count, total))
self.start_ts = datetime.datetime.now()
last_count = 0
else:
last_count = self.last_msg[1]
if total:
if count and (count - last_count > 0):
# Write a few dots to catch up to where we should be.
catch_up = int(math.ceil((count - last_count) / 2.0))
sys.stdout.write('.' * catch_up)
if count == total:
sys.stdout.write('%s/%s in %s\n' % (count, total, datetime.datetime.now() - self.start_ts))
elif total > 25 and count and (count - self.last_msg_count_posted > (total * 0.20)):
sys.stdout.write(str(count))
self.last_msg_count_posted = count
sys.stdout.flush()
self.last_msg = (msg, count, total, error)
def RunAndOpenReports(self):
self.RunBenchmark()
print "\n%s\n" % self.reporter.CreateReport(format='ascii')
self.CreateReports()
if self.options.open_webbrowser:
self.DisplayHtmlReport()
def Execute(self):
"""Called by namebench.py to start the show."""
print('namebench %s - %s (%s) on %s' %
(self.options.version, self.options.input_source or 'best source',
self.options.select_mode, datetime.datetime.now()))
print ('threads=%s/%s queries=%s runs=%s timeout=%s health_timeout=%s servers=%s' %
(self.options.health_thread_count, self.options.benchmark_thread_count,
self.options.query_count,
self.options.run_count, self.options.timeout,
self.options.health_timeout, self.options.num_servers))
print '-' * 78
if not self.options.tags:
print "You need to specify some DNS servers to benchmark. Try:"
print ""
print "namebench.py -s all # Test best available DNS servers"
print "namebench.py -s preferred,isp # Only test preferred + ISP DNS servers"
print "namebench.py -s system # Only test current system DNS servers"
print "namebench.py -s global 8.8.8.8 # Benchmark global DNS servers + 8.8.8.8"
print "namebench.py 8.8.8.8 10.0.0.1 # Benchmark just these two servers"
print ""
print "For more assistance, get help via namebench.py -h"
sys.exit(1)
self.PrepareNameServers()
try:
self.LoadDataSources()
self.PrepareTestRecords()
print '-' * 78
if not self.options.skip_health_checks:
self.CheckNameServerHealth()
print 'Final list of nameservers considered:'
print '-' * 78
for n in self.nameservers.SortEnabledByFastest():
print '%-15.15s %-18.18s %-4.0fms | %s' % (n.ip, n.name, n.check_average,
n.warnings_string)
print ''
print ''
self.PrepareBenchmark()
self.RunAndOpenReports()
except (nameserver_list.OutgoingUdpInterception,
nameserver_list.TooFewNameservers,
conn_quality.OfflineConnection):
(exc_type, exception) = sys.exc_info()[0:2]
self.UpdateStatus("%s - %s" % (exc_type, exception), error=True)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
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,
421,
199,
624,
3184,
10237,
1654,
9132,
12338,
316,
4744,
14,
199,
199,
872,
1737,
370,
465,
11734,
2656,
4628,
3075,
2750,
315,
7267,
436,
6791,
5277,
13362,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
199,
199,
646,
2197,
199,
646,
3473,
199,
646,
984,
199,
199,
646,
1300,
63,
1907,
199,
646,
2557,
63,
9161,
199,
646,
536,
1000,
63,
513,
421,
199,
533,
2812,
34,
5368,
20653,
8,
1095,
63,
1907,
14,
1563,
6379,
304,
523,
408,
33,
1414,
13,
604,
4514,
402,
314,
536,
16571,
10431,
1041,
819,
347,
636,
826,
721,
277,
12,
1511,
304,
272,
291,
14,
1419,
275,
1511,
272,
291,
14,
2019,
63,
1328,
275,
334,
403,
12,
488,
12,
488,
12,
488,
9,
272,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
272,
1613,
8,
985,
34,
5368,
20653,
12,
291,
2843,
826,
4533,
819,
347,
6162,
3694,
8,
277,
12,
1499,
12,
2338,
29,
403,
12,
3141,
29,
403,
12,
1125,
29,
797,
12,
3105,
29,
797,
304,
272,
408,
3694,
7029,
367,
314,
1414,
13,
604,
14,
437,
13918,
402,
14164,
22058,
2348,
1041,
272,
340,
291,
14,
2019,
63,
1328,
508,
334,
1328,
12,
2338,
12,
3141,
12,
1125,
304,
489,
372,
488,
339,
340,
3105,
26,
489,
372,
488,
339,
340,
1125,
26,
489,
870,
489,
870,
6438,
12539,
26,
450,
83,
7,
450,
1499,
489,
984,
14,
2224,
8,
18,
9,
272,
916,
440,
3141,
26,
489,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
489,
984,
14,
2703,
14,
952,
3654,
450,
83,
60,
78,
7,
450,
1499,
9,
272,
916,
291,
14,
2019,
63,
1328,
59,
16,
61,
1137,
1499,
26,
489,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
489,
984,
14,
2703,
14,
952,
3654,
450,
83,
26,
450,
83,
3149,
83,
7,
450,
334,
1328,
12,
2338,
12,
3141,
430,
489,
291,
14,
928,
63,
1086,
275,
2197,
14,
2083,
14,
2131,
342,
489,
2061,
63,
835,
275,
378,
272,
587,
26,
489,
2061,
63,
835,
275,
291,
14,
2019,
63,
1328,
59,
17,
61,
339,
340,
3141,
26,
489,
340,
2338,
436,
334,
835,
446,
2061,
63,
835,
690,
378,
304,
267,
327,
6990,
282,
9284,
21185,
370,
8579,
1536,
370,
2382,
781,
1077,
506,
14,
267,
8579,
63,
384,
275,
1109,
8,
3442,
14,
14085,
1332,
835,
446,
2061,
63,
835,
9,
1182,
499,
14,
16,
430,
267,
984,
14,
2703,
14,
952,
360,
3530,
627,
8579,
63,
384,
9,
2541,
340,
2338,
508,
3141,
26,
2126,
984,
14,
2703,
14,
952,
3508,
83,
3149,
83,
315,
450,
83,
60,
78,
7,
450,
334,
835,
12,
3141,
12,
2197,
14,
2083,
14,
2131,
342,
446,
291,
14,
928,
63,
1086,
430,
489,
916,
3141,
690,
5661,
436,
2338,
436,
334,
835,
446,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
690,
334,
2923,
627,
378,
14,
1165,
2298,
267,
984,
14,
2703,
14,
952,
8,
495,
8,
835,
430,
267,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
2338,
272,
984,
14,
2703,
14,
4939,
342,
272,
291,
14,
2019,
63,
1328,
275,
334,
1328,
12,
2338,
12,
3141,
12,
1125,
9,
819,
347,
3378,
3325,
4299,
497,
5203,
8,
277,
304,
272,
291,
14,
2540,
18644,
342,
272,
870,
1867,
78,
5,
83,
60,
78,
2,
450,
291,
14,
12222,
14,
2499,
7457,
8,
908,
534,
4371,
358,
272,
291,
14,
2499,
497,
5203,
342,
272,
340,
291,
14,
1419,
14,
1490,
63,
1129,
29063,
26,
489,
291,
14,
7687,
12957,
7457,
342,
819,
347,
17009,
8,
277,
304,
272,
408,
10474,
701,
536,
16571,
14,
647,
370,
1343,
314,
2498,
1041,
272,
870,
360,
354,
16571,
450,
83,
446,
450,
83,
4366,
83,
9,
641,
450,
83,
7,
450,
881,
334,
277,
14,
1419,
14,
1023,
12,
291,
14,
1419,
14,
1210,
63,
1365,
503,
283,
7010,
1350,
297,
1779,
291,
14,
1419,
14,
2416,
63,
632,
12,
2197,
14,
2083,
14,
2131,
4059,
272,
870,
661,
6962,
2458,
83,
3149,
83,
9212,
2458,
83,
7858,
2458,
83,
2653,
2458,
83,
13822,
63,
2593,
2458,
83,
8037,
2458,
83,
7,
450,
1779,
334,
277,
14,
1419,
14,
9665,
63,
2671,
63,
835,
12,
291,
14,
1419,
14,
11861,
63,
2671,
63,
835,
12,
288,
291,
14,
1419,
14,
1131,
63,
835,
12,
288,
291,
14,
1419,
14,
1065,
63,
835,
12,
291,
14,
1419,
14,
2593,
12,
288,
291,
14,
1419,
14,
9665,
63,
2593,
12,
291,
14,
1419,
14,
1507,
63,
5871,
430,
272,
870,
10791,
627,
14679,
339,
340,
440,
291,
14,
1419,
14,
2969,
26,
489,
870,
298,
5556,
1929,
370,
4165,
2005,
10237,
8037,
370,
12338,
14,
7649,
5424,
489,
870,
3087,
489,
870,
298,
354,
16571,
14,
647,
446,
83,
1006,
4519,
327,
1379,
5526,
2808,
10237,
8037,
2,
489,
870,
298,
354,
16571,
14,
647,
446,
83,
14388,
12,
27474,
259,
327,
5972,
511,
14388,
435,
2281,
48,
10237,
8037,
2,
489,
870,
298,
354,
16571,
14,
647,
446,
83,
2656,
3698,
327,
5972,
511,
1453,
2656,
10237,
8037,
2,
489,
870,
298,
354,
16571,
14,
647
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
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,
421,
199,
624,
3184,
10237,
1654,
9132,
12338,
316,
4744,
14,
199,
199,
872,
1737,
370,
465,
11734,
2656,
4628,
3075,
2750,
315,
7267,
436,
6791,
5277,
13362,
14,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
84,
31672,
14630,
32,
3098,
14,
957,
334,
52,
526,
5892,
1933,
417,
14630,
3171,
199,
199,
646,
2197,
199,
646,
3473,
199,
646,
984,
199,
199,
646,
1300,
63,
1907,
199,
646,
2557,
63,
9161,
199,
646,
536,
1000,
63,
513,
421,
199,
533,
2812,
34,
5368,
20653,
8,
1095,
63,
1907,
14,
1563,
6379,
304,
523,
408,
33,
1414,
13,
604,
4514,
402,
314,
536,
16571,
10431,
1041,
819,
347,
636,
826,
721,
277,
12,
1511,
304,
272,
291,
14,
1419,
275,
1511,
272,
291,
14,
2019,
63,
1328,
275,
334,
403,
12,
488,
12,
488,
12,
488,
9,
272,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
272,
1613,
8,
985,
34,
5368,
20653,
12,
291,
2843,
826,
4533,
819,
347,
6162,
3694,
8,
277,
12,
1499,
12,
2338,
29,
403,
12,
3141,
29,
403,
12,
1125,
29,
797,
12,
3105,
29,
797,
304,
272,
408,
3694,
7029,
367,
314,
1414,
13,
604,
14,
437,
13918,
402,
14164,
22058,
2348,
1041,
272,
340,
291,
14,
2019,
63,
1328,
508,
334,
1328,
12,
2338,
12,
3141,
12,
1125,
304,
489,
372,
488,
339,
340,
3105,
26,
489,
372,
488,
339,
340,
1125,
26,
489,
870,
489,
870,
6438,
12539,
26,
450,
83,
7,
450,
1499,
489,
984,
14,
2224,
8,
18,
9,
272,
916,
440,
3141,
26,
489,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
489,
984,
14,
2703,
14,
952,
3654,
450,
83,
60,
78,
7,
450,
1499,
9,
272,
916,
291,
14,
2019,
63,
1328,
59,
16,
61,
1137,
1499,
26,
489,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
378,
489,
984,
14,
2703,
14,
952,
3654,
450,
83,
26,
450,
83,
3149,
83,
7,
450,
334,
1328,
12,
2338,
12,
3141,
430,
489,
291,
14,
928,
63,
1086,
275,
2197,
14,
2083,
14,
2131,
342,
489,
2061,
63,
835,
275,
378,
272,
587,
26,
489,
2061,
63,
835,
275,
291,
14,
2019,
63,
1328,
59,
17,
61,
339,
340,
3141,
26,
489,
340,
2338,
436,
334,
835,
446,
2061,
63,
835,
690,
378,
304,
267,
327,
6990,
282,
9284,
21185,
370,
8579,
1536,
370,
2382,
781,
1077,
506,
14,
267,
8579,
63,
384,
275,
1109,
8,
3442,
14,
14085,
1332,
835,
446,
2061,
63,
835,
9,
1182,
499,
14,
16,
430,
267,
984,
14,
2703,
14,
952,
360,
3530,
627,
8579,
63,
384,
9,
2541,
340,
2338,
508,
3141,
26,
2126,
984,
14,
2703,
14,
952,
3508,
83,
3149,
83,
315,
450,
83,
60,
78,
7,
450,
334,
835,
12,
3141,
12,
2197,
14,
2083,
14,
2131,
342,
446,
291,
14,
928,
63,
1086,
430,
489,
916,
3141,
690,
5661,
436,
2338,
436,
334,
835,
446,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
690,
334,
2923,
627,
378,
14,
1165,
2298,
267,
984,
14,
2703,
14,
952,
8,
495,
8,
835,
430,
267,
291,
14,
2019,
63,
1328,
63,
835,
63,
21760,
275,
2338,
272,
984,
14,
2703,
14,
4939,
342,
272,
291,
14,
2019,
63,
1328,
275,
334,
1328,
12,
2338,
12,
3141,
12,
1125,
9,
819,
347,
3378,
3325,
4299,
497,
5203,
8,
277,
304,
272,
291,
14,
2540,
18644,
342,
272,
870,
1867,
78,
5,
83,
60,
78,
2,
450,
291,
14,
12222,
14,
2499,
7457,
8,
908,
534,
4371,
358,
272,
291,
14,
2499,
497,
5203,
342,
272,
340,
291,
14,
1419,
14,
1490,
63,
1129,
29063,
26,
489,
291,
14,
7687,
12957,
7457,
342,
819,
347,
17009,
8,
277,
304,
272,
408,
10474,
701,
536,
16571,
14,
647,
370,
1343,
314,
2498,
1041,
272,
870,
360,
354,
16571,
450,
83,
446,
450,
83,
4366,
83,
9,
641,
450,
83,
7,
450,
881,
334,
277,
14,
1419,
14,
1023,
12,
291,
14,
1419,
14,
1210,
63,
1365,
503,
283,
7010,
1350,
297,
1779,
291,
14,
1419,
14,
2416,
63,
632,
12,
2197,
14,
2083,
14,
2131,
4059,
272,
870,
661,
6962,
2458,
83,
3149,
83,
9212,
2458,
83,
7858,
2458,
83,
2653,
2458,
83,
13822,
63,
2593,
2458,
83,
8037,
2458,
83,
7,
450,
1779,
334,
277,
14,
1419,
14,
9665,
63,
2671,
63,
835,
12,
291,
14,
1419,
14,
11861,
63,
2671,
63,
835,
12,
288,
291,
14,
1419,
14,
1131,
63,
835,
12,
288,
291,
14,
1419,
14,
1065,
63,
835,
12,
291,
14,
1419,
14,
2593,
12,
288,
291,
14,
1419,
14,
9665,
63,
2593,
12,
291,
14,
1419,
14,
1507,
63,
5871,
430,
272,
870,
10791,
627,
14679,
339,
340,
440,
291,
14,
1419,
14,
2969,
26,
489,
870,
298,
5556,
1929,
370,
4165,
2005,
10237,
8037,
370,
12338,
14,
7649,
5424,
489,
870,
3087,
489,
870,
298,
354,
16571,
14,
647,
446,
83,
1006,
4519,
327,
1379,
5526,
2808,
10237,
8037,
2,
489,
870,
298,
354,
16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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
] |
javilonas/NCam
|
cross/android-toolchain/lib/python2.7/xml/sax/saxutils.py
|
43
|
11384
|
"""\
A library of useful helper classes to the SAX classes, for the
convenience of application and driver writers.
"""
import os, urlparse, urllib, types
import io
import sys
import handler
import xmlreader
try:
_StringTypes = [types.StringType, types.UnicodeType]
except AttributeError:
_StringTypes = [types.StringType]
def __dict_replace(s, d):
"""Replace substrings of a string using a dictionary."""
for key, value in d.items():
s = s.replace(key, value)
return s
def escape(data, entities={}):
"""Escape &, <, and > in a string of data.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
# must do ampersand first
data = data.replace("&", "&")
data = data.replace(">", ">")
data = data.replace("<", "<")
if entities:
data = __dict_replace(data, entities)
return data
def unescape(data, entities={}):
"""Unescape &, <, and > in a string of data.
You can unescape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
data = data.replace("<", "<")
data = data.replace(">", ">")
if entities:
data = __dict_replace(data, entities)
# must do ampersand last
return data.replace("&", "&")
def quoteattr(data, entities={}):
"""Escape and quote an attribute value.
Escape &, <, and > in a string of data, then quote it for use as
an attribute value. The \" character will be escaped as well, if
necessary.
You can escape other strings of data by passing a dictionary as
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
entities = entities.copy()
entities.update({'\n': ' ', '\r': ' ', '\t':'	'})
data = escape(data, entities)
if '"' in data:
if "'" in data:
data = '"%s"' % data.replace('"', """)
else:
data = "'%s'" % data
else:
data = '"%s"' % data
return data
def _gettextwriter(out, encoding):
if out is None:
import sys
out = sys.stdout
if isinstance(out, io.RawIOBase):
buffer = io.BufferedIOBase(out)
# Keep the original file open when the TextIOWrapper is
# destroyed
buffer.close = lambda: None
else:
# This is to handle passed objects that aren't in the
# IOBase hierarchy, but just have a write method
buffer = io.BufferedIOBase()
buffer.writable = lambda: True
buffer.write = out.write
try:
# TextIOWrapper uses this methods to determine
# if BOM (for UTF-16, etc) should be added
buffer.seekable = out.seekable
buffer.tell = out.tell
except AttributeError:
pass
# wrap a binary writer with TextIOWrapper
class UnbufferedTextIOWrapper(io.TextIOWrapper):
def write(self, s):
super(UnbufferedTextIOWrapper, self).write(s)
self.flush()
return UnbufferedTextIOWrapper(buffer, encoding=encoding,
errors='xmlcharrefreplace',
newline='\n')
class XMLGenerator(handler.ContentHandler):
def __init__(self, out=None, encoding="iso-8859-1"):
handler.ContentHandler.__init__(self)
out = _gettextwriter(out, encoding)
self._write = out.write
self._flush = out.flush
self._ns_contexts = [{}] # contains uri -> prefix dicts
self._current_context = self._ns_contexts[-1]
self._undeclared_ns_maps = []
self._encoding = encoding
def _qname(self, name):
"""Builds a qualified name from a (ns_url, localname) pair"""
if name[0]:
# Per http://www.w3.org/XML/1998/namespace, The 'xml' prefix is
# bound by definition to http://www.w3.org/XML/1998/namespace. It
# does not need to be declared and will not usually be found in
# self._current_context.
if 'http://www.w3.org/XML/1998/namespace' == name[0]:
return 'xml:' + name[1]
# The name is in a non-empty namespace
prefix = self._current_context[name[0]]
if prefix:
# If it is not the default namespace, prepend the prefix
return prefix + ":" + name[1]
# Return the unqualified name
return name[1]
# ContentHandler methods
def startDocument(self):
self._write(u'<?xml version="1.0" encoding="%s"?>\n' %
self._encoding)
def endDocument(self):
self._flush()
def startPrefixMapping(self, prefix, uri):
self._ns_contexts.append(self._current_context.copy())
self._current_context[uri] = prefix
self._undeclared_ns_maps.append((prefix, uri))
def endPrefixMapping(self, prefix):
self._current_context = self._ns_contexts[-1]
del self._ns_contexts[-1]
def startElement(self, name, attrs):
self._write(u'<' + name)
for (name, value) in attrs.items():
self._write(u' %s=%s' % (name, quoteattr(value)))
self._write(u'>')
def endElement(self, name):
self._write(u'</%s>' % name)
def startElementNS(self, name, qname, attrs):
self._write(u'<' + self._qname(name))
for prefix, uri in self._undeclared_ns_maps:
if prefix:
self._write(u' xmlns:%s="%s"' % (prefix, uri))
else:
self._write(u' xmlns="%s"' % uri)
self._undeclared_ns_maps = []
for (name, value) in attrs.items():
self._write(u' %s=%s' % (self._qname(name), quoteattr(value)))
self._write(u'>')
def endElementNS(self, name, qname):
self._write(u'</%s>' % self._qname(name))
def characters(self, content):
self._write(escape(unicode(content)))
def ignorableWhitespace(self, content):
self._write(unicode(content))
def processingInstruction(self, target, data):
self._write(u'<?%s %s?>' % (target, data))
class XMLFilterBase(xmlreader.XMLReader):
"""This class is designed to sit between an XMLReader and the
client application's event handlers. By default, it does nothing
but pass requests up to the reader and events on to the handlers
unmodified, but subclasses can override specific methods to modify
the event stream or the configuration requests as they pass
through."""
def __init__(self, parent = None):
xmlreader.XMLReader.__init__(self)
self._parent = parent
# ErrorHandler methods
def error(self, exception):
self._err_handler.error(exception)
def fatalError(self, exception):
self._err_handler.fatalError(exception)
def warning(self, exception):
self._err_handler.warning(exception)
# ContentHandler methods
def setDocumentLocator(self, locator):
self._cont_handler.setDocumentLocator(locator)
def startDocument(self):
self._cont_handler.startDocument()
def endDocument(self):
self._cont_handler.endDocument()
def startPrefixMapping(self, prefix, uri):
self._cont_handler.startPrefixMapping(prefix, uri)
def endPrefixMapping(self, prefix):
self._cont_handler.endPrefixMapping(prefix)
def startElement(self, name, attrs):
self._cont_handler.startElement(name, attrs)
def endElement(self, name):
self._cont_handler.endElement(name)
def startElementNS(self, name, qname, attrs):
self._cont_handler.startElementNS(name, qname, attrs)
def endElementNS(self, name, qname):
self._cont_handler.endElementNS(name, qname)
def characters(self, content):
self._cont_handler.characters(content)
def ignorableWhitespace(self, chars):
self._cont_handler.ignorableWhitespace(chars)
def processingInstruction(self, target, data):
self._cont_handler.processingInstruction(target, data)
def skippedEntity(self, name):
self._cont_handler.skippedEntity(name)
# DTDHandler methods
def notationDecl(self, name, publicId, systemId):
self._dtd_handler.notationDecl(name, publicId, systemId)
def unparsedEntityDecl(self, name, publicId, systemId, ndata):
self._dtd_handler.unparsedEntityDecl(name, publicId, systemId, ndata)
# EntityResolver methods
def resolveEntity(self, publicId, systemId):
return self._ent_handler.resolveEntity(publicId, systemId)
# XMLReader methods
def parse(self, source):
self._parent.setContentHandler(self)
self._parent.setErrorHandler(self)
self._parent.setEntityResolver(self)
self._parent.setDTDHandler(self)
self._parent.parse(source)
def setLocale(self, locale):
self._parent.setLocale(locale)
def getFeature(self, name):
return self._parent.getFeature(name)
def setFeature(self, name, state):
self._parent.setFeature(name, state)
def getProperty(self, name):
return self._parent.getProperty(name)
def setProperty(self, name, value):
self._parent.setProperty(name, value)
# XMLFilter methods
def getParent(self):
return self._parent
def setParent(self, parent):
self._parent = parent
# --- Utility functions
def prepare_input_source(source, base = ""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
if type(source) in _StringTypes:
source = xmlreader.InputSource(source)
elif hasattr(source, "read"):
f = source
source = xmlreader.InputSource()
source.setByteStream(f)
if hasattr(f, "name"):
source.setSystemId(f.name)
if source.getByteStream() is None:
try:
sysid = source.getSystemId()
basehead = os.path.dirname(os.path.normpath(base))
encoding = sys.getfilesystemencoding()
if isinstance(sysid, unicode):
if not isinstance(basehead, unicode):
try:
basehead = basehead.decode(encoding)
except UnicodeDecodeError:
sysid = sysid.encode(encoding)
else:
if isinstance(basehead, unicode):
try:
sysid = sysid.decode(encoding)
except UnicodeDecodeError:
basehead = basehead.encode(encoding)
sysidfilename = os.path.join(basehead, sysid)
isfile = os.path.isfile(sysidfilename)
except UnicodeError:
isfile = False
if isfile:
source.setSystemId(sysidfilename)
f = open(sysidfilename, "rb")
else:
source.setSystemId(urlparse.urljoin(base, source.getSystemId()))
f = urllib.urlopen(source.getSystemId())
source.setByteStream(f)
return source
|
gpl-3.0
|
[
19659,
199,
33,
3555,
402,
2997,
5922,
3992,
370,
314,
19310,
3992,
12,
367,
314,
199,
388,
23329,
402,
4223,
436,
5253,
2211,
878,
14,
199,
624,
199,
199,
646,
747,
12,
7097,
12,
4011,
12,
2943,
199,
646,
5890,
199,
646,
984,
199,
646,
3016,
199,
646,
2748,
5503,
199,
199,
893,
26,
272,
485,
1558,
4100,
275,
359,
1313,
14,
22463,
12,
2943,
14,
7087,
804,
61,
199,
2590,
4281,
26,
272,
485,
1558,
4100,
275,
359,
1313,
14,
22463,
61,
199,
199,
318,
636,
807,
63,
1814,
8,
83,
12,
366,
304,
272,
408,
11328,
1007,
5465,
402,
282,
1059,
1808,
282,
2600,
1041,
272,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
267,
308,
275,
308,
14,
1814,
8,
498,
12,
574,
9,
272,
372,
308,
199,
199,
318,
4772,
8,
576,
12,
9045,
16420,
272,
408,
10260,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
339,
327,
1471,
886,
15204,
1192,
460,
1642,
272,
666,
275,
666,
14,
1814,
22077,
401,
11746,
5282,
15027,
272,
666,
275,
666,
14,
1814,
480,
7166,
11746,
3308,
15027,
272,
666,
275,
666,
14,
1814,
6757,
401,
11746,
4116,
15027,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
372,
666,
199,
199,
318,
22221,
8,
576,
12,
9045,
16420,
272,
408,
1358,
3765,
1253,
5282,
27031,
1253,
4116,
27031,
436,
1253,
3308,
27,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
22221,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
666,
275,
666,
14,
1814,
22077,
4116,
17259,
3886,
531,
272,
666,
275,
666,
14,
1814,
22077,
3308,
17259,
298,
9579,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
327,
1471,
886,
15204,
1192,
460,
2061,
272,
372,
666,
14,
1814,
22077,
5282,
17259,
11746,
531,
199,
199,
318,
6313,
962,
8,
576,
12,
9045,
16420,
272,
408,
10260,
436,
6313,
376,
2225,
574,
14,
339,
21067,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
12,
2066,
6313,
652,
367,
675,
465,
272,
376,
2225,
574,
14,
221,
710,
8441,
4528,
911,
506,
11077,
465,
5521,
12,
340,
272,
5784,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
9045,
275,
9045,
14,
1574,
342,
272,
9045,
14,
873,
2561,
1154,
78,
356,
7673,
3,
709,
10805,
1557,
82,
356,
7673,
3,
969,
10805,
1557,
84,
5242,
7997,
25,
27,
3071,
272,
666,
275,
4772,
8,
576,
12,
9045,
9,
272,
340,
14788,
315,
666,
26,
267,
340,
21673,
315,
666,
26,
288,
666,
275,
18253,
83,
4507,
450,
666,
14,
1814,
20630,
11746,
5184,
15027,
267,
587,
26,
288,
666,
275,
17648,
83,
4065,
450,
666,
272,
587,
26,
267,
666,
275,
18253,
83,
4507,
450,
666,
272,
372,
666,
421,
199,
318,
485,
5152,
5491,
8,
548,
12,
2644,
304,
272,
340,
734,
365,
488,
26,
267,
492,
984,
267,
734,
275,
984,
14,
2703,
339,
340,
1228,
8,
548,
12,
5890,
14,
7963,
23413,
304,
267,
3335,
275,
5890,
14,
23139,
23413,
8,
548,
9,
267,
327,
14797,
314,
3379,
570,
1551,
1380,
314,
4516,
29365,
365,
267,
327,
28924,
267,
3335,
14,
1600,
275,
2400,
26,
488,
272,
587,
26,
267,
327,
961,
365,
370,
2429,
3032,
2251,
626,
10621,
1133,
315,
314,
267,
327,
5004,
1563,
14446,
12,
1325,
2951,
1172,
282,
2218,
1083,
267,
3335,
275,
5890,
14,
23139,
23413,
342,
267,
3335,
14,
15053,
275,
2400,
26,
715,
267,
3335,
14,
952,
275,
734,
14,
952,
267,
862,
26,
288,
327,
4516,
29365,
4440,
642,
3102,
370,
6705,
288,
327,
340,
17720,
334,
509,
9094,
13,
975,
12,
5423,
9,
1077,
506,
3483,
288,
3335,
14,
25895,
275,
734,
14,
25895,
288,
3335,
14,
9974,
275,
734,
14,
9974,
267,
871,
4281,
26,
288,
986,
272,
327,
4816,
282,
3366,
7060,
543,
4516,
29365,
272,
1021,
1910,
17605,
1872,
29365,
8,
2308,
14,
1872,
29365,
304,
267,
347,
2218,
8,
277,
12,
308,
304,
288,
1613,
8,
1358,
17605,
1872,
29365,
12,
291,
680,
952,
8,
83,
9,
288,
291,
14,
4939,
342,
272,
372,
1910,
17605,
1872,
29365,
8,
2738,
12,
2644,
29,
2991,
12,
3521,
2552,
534,
1652,
24253,
1814,
297,
3521,
8057,
17115,
78,
358,
199,
199,
533,
4692,
7599,
8,
2232,
14,
2714,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
734,
29,
403,
12,
2644,
628,
4595,
13,
4830,
13,
17,
2349,
267,
3016,
14,
2714,
2461,
855,
826,
721,
277,
9,
267,
734,
275,
485,
5152,
5491,
8,
548,
12,
2644,
9,
267,
291,
423,
952,
275,
734,
14,
952,
267,
291,
423,
4939,
275,
734,
14,
4939,
267,
291,
423,
561,
63,
19010,
275,
359,
27922,
327,
3509,
5108,
1035,
2403,
10809,
267,
291,
423,
1818,
63,
1100,
275,
291,
423,
561,
63,
19010,
1988,
17,
61,
267,
291,
423,
31531,
63,
561,
63,
8919,
275,
942,
267,
291,
423,
2991,
275,
2644,
339,
347,
485,
12333,
8,
277,
12,
536,
304,
267,
408,
27856,
282,
12313,
536,
687,
282,
334,
561,
63,
633,
12,
2257,
354,
9,
4092,
624,
267,
340,
536,
59,
16,
2189,
288,
327,
3492,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
12,
710,
283,
1652,
7,
2403,
365,
288,
327,
3914,
701,
5492,
370,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
14,
221,
2779,
288,
327,
1630,
440,
1929,
370,
506,
14290,
436,
911,
440,
9987
] |
[
199,
33,
3555,
402,
2997,
5922,
3992,
370,
314,
19310,
3992,
12,
367,
314,
199,
388,
23329,
402,
4223,
436,
5253,
2211,
878,
14,
199,
624,
199,
199,
646,
747,
12,
7097,
12,
4011,
12,
2943,
199,
646,
5890,
199,
646,
984,
199,
646,
3016,
199,
646,
2748,
5503,
199,
199,
893,
26,
272,
485,
1558,
4100,
275,
359,
1313,
14,
22463,
12,
2943,
14,
7087,
804,
61,
199,
2590,
4281,
26,
272,
485,
1558,
4100,
275,
359,
1313,
14,
22463,
61,
199,
199,
318,
636,
807,
63,
1814,
8,
83,
12,
366,
304,
272,
408,
11328,
1007,
5465,
402,
282,
1059,
1808,
282,
2600,
1041,
272,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
267,
308,
275,
308,
14,
1814,
8,
498,
12,
574,
9,
272,
372,
308,
199,
199,
318,
4772,
8,
576,
12,
9045,
16420,
272,
408,
10260,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
339,
327,
1471,
886,
15204,
1192,
460,
1642,
272,
666,
275,
666,
14,
1814,
22077,
401,
11746,
5282,
15027,
272,
666,
275,
666,
14,
1814,
480,
7166,
11746,
3308,
15027,
272,
666,
275,
666,
14,
1814,
6757,
401,
11746,
4116,
15027,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
372,
666,
199,
199,
318,
22221,
8,
576,
12,
9045,
16420,
272,
408,
1358,
3765,
1253,
5282,
27031,
1253,
4116,
27031,
436,
1253,
3308,
27,
315,
282,
1059,
402,
666,
14,
339,
2047,
883,
22221,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
666,
275,
666,
14,
1814,
22077,
4116,
17259,
3886,
531,
272,
666,
275,
666,
14,
1814,
22077,
3308,
17259,
298,
9579,
272,
340,
9045,
26,
267,
666,
275,
636,
807,
63,
1814,
8,
576,
12,
9045,
9,
272,
327,
1471,
886,
15204,
1192,
460,
2061,
272,
372,
666,
14,
1814,
22077,
5282,
17259,
11746,
531,
199,
199,
318,
6313,
962,
8,
576,
12,
9045,
16420,
272,
408,
10260,
436,
6313,
376,
2225,
574,
14,
339,
21067,
17181,
665,
12,
436,
690,
315,
282,
1059,
402,
666,
12,
2066,
6313,
652,
367,
675,
465,
272,
376,
2225,
574,
14,
221,
710,
8441,
4528,
911,
506,
11077,
465,
5521,
12,
340,
272,
5784,
14,
339,
2047,
883,
4772,
1163,
3326,
402,
666,
701,
9476,
282,
2600,
465,
272,
314,
2716,
9045,
2725,
14,
221,
710,
2883,
436,
1338,
1471,
1006,
506,
272,
3326,
27,
1924,
790,
911,
506,
8717,
543,
2399,
5226,
574,
14,
272,
408,
272,
9045,
275,
9045,
14,
1574,
342,
272,
9045,
14,
873,
2561,
1154,
78,
356,
7673,
3,
709,
10805,
1557,
82,
356,
7673,
3,
969,
10805,
1557,
84,
5242,
7997,
25,
27,
3071,
272,
666,
275,
4772,
8,
576,
12,
9045,
9,
272,
340,
14788,
315,
666,
26,
267,
340,
21673,
315,
666,
26,
288,
666,
275,
18253,
83,
4507,
450,
666,
14,
1814,
20630,
11746,
5184,
15027,
267,
587,
26,
288,
666,
275,
17648,
83,
4065,
450,
666,
272,
587,
26,
267,
666,
275,
18253,
83,
4507,
450,
666,
272,
372,
666,
421,
199,
318,
485,
5152,
5491,
8,
548,
12,
2644,
304,
272,
340,
734,
365,
488,
26,
267,
492,
984,
267,
734,
275,
984,
14,
2703,
339,
340,
1228,
8,
548,
12,
5890,
14,
7963,
23413,
304,
267,
3335,
275,
5890,
14,
23139,
23413,
8,
548,
9,
267,
327,
14797,
314,
3379,
570,
1551,
1380,
314,
4516,
29365,
365,
267,
327,
28924,
267,
3335,
14,
1600,
275,
2400,
26,
488,
272,
587,
26,
267,
327,
961,
365,
370,
2429,
3032,
2251,
626,
10621,
1133,
315,
314,
267,
327,
5004,
1563,
14446,
12,
1325,
2951,
1172,
282,
2218,
1083,
267,
3335,
275,
5890,
14,
23139,
23413,
342,
267,
3335,
14,
15053,
275,
2400,
26,
715,
267,
3335,
14,
952,
275,
734,
14,
952,
267,
862,
26,
288,
327,
4516,
29365,
4440,
642,
3102,
370,
6705,
288,
327,
340,
17720,
334,
509,
9094,
13,
975,
12,
5423,
9,
1077,
506,
3483,
288,
3335,
14,
25895,
275,
734,
14,
25895,
288,
3335,
14,
9974,
275,
734,
14,
9974,
267,
871,
4281,
26,
288,
986,
272,
327,
4816,
282,
3366,
7060,
543,
4516,
29365,
272,
1021,
1910,
17605,
1872,
29365,
8,
2308,
14,
1872,
29365,
304,
267,
347,
2218,
8,
277,
12,
308,
304,
288,
1613,
8,
1358,
17605,
1872,
29365,
12,
291,
680,
952,
8,
83,
9,
288,
291,
14,
4939,
342,
272,
372,
1910,
17605,
1872,
29365,
8,
2738,
12,
2644,
29,
2991,
12,
3521,
2552,
534,
1652,
24253,
1814,
297,
3521,
8057,
17115,
78,
358,
199,
199,
533,
4692,
7599,
8,
2232,
14,
2714,
2461,
304,
339,
347,
636,
826,
721,
277,
12,
734,
29,
403,
12,
2644,
628,
4595,
13,
4830,
13,
17,
2349,
267,
3016,
14,
2714,
2461,
855,
826,
721,
277,
9,
267,
734,
275,
485,
5152,
5491,
8,
548,
12,
2644,
9,
267,
291,
423,
952,
275,
734,
14,
952,
267,
291,
423,
4939,
275,
734,
14,
4939,
267,
291,
423,
561,
63,
19010,
275,
359,
27922,
327,
3509,
5108,
1035,
2403,
10809,
267,
291,
423,
1818,
63,
1100,
275,
291,
423,
561,
63,
19010,
1988,
17,
61,
267,
291,
423,
31531,
63,
561,
63,
8919,
275,
942,
267,
291,
423,
2991,
275,
2644,
339,
347,
485,
12333,
8,
277,
12,
536,
304,
267,
408,
27856,
282,
12313,
536,
687,
282,
334,
561,
63,
633,
12,
2257,
354,
9,
4092,
624,
267,
340,
536,
59,
16,
2189,
288,
327,
3492,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
12,
710,
283,
1652,
7,
2403,
365,
288,
327,
3914,
701,
5492,
370,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
4317,
15,
23756,
15,
3251,
14,
221,
2779,
288,
327,
1630,
440,
1929,
370,
506,
14290,
436,
911,
440,
9987,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Sinar/mapit
|
bin/scrape_admin_boundaries_tables.py
|
2
|
2263
|
#!/usr/bin/env python
import sys, re
from bs4 import BeautifulSoup
import urllib2
url = "http://wiki.openstreetmap.org/wiki/Tag:boundary%3Dadministrative"
f = urllib2.urlopen(url)
data = f.read()
f.close()
soup = BeautifulSoup(data, "lxml")
def strip_all_tags(element):
for br in element.find_all('br'):
br.replaceWith(u"\n")
return "".join(element.findAll(text=True)).strip()
# Tidy up the country name column - I'm not sure there's an obviously
# smarter way of doing this for the moment:
def get_country_name(s):
if re.search('(?s)new levels.*Germany', s):
return 'Germany'
result = re.sub(r' +[\(/].*', '', s)
result = re.sub(r'(?ms)$.*', '', result)
result = re.sub(r'\s+(see also|has it)', '', result)
result = re.sub(r'(Poland|Portugal|France|Georgia|Germany).*', '\\1', result)
result = re.sub(r'^(?u)Flag of Isle of Man\s+', '', result)
return result
def make_missing_none(s):
if re.search('(?uis)^\s*N/A\s*$', s):
return None
else:
return s
country_to_admin_levels = {}
for table in soup.find_all('table', 'wikitable'):
rows = table.findAll('tr', recursive=False)
for row in rows:
ths = row.findAll('th', recursive=False)
if ths:
headers = [th.string.strip() for th in ths]
continue
tds = row.findAll('td', recursive=False)
if len(tds) <= 2:
continue
country_name = get_country_name(strip_all_tags(tds[0]))
if len(tds) != len(headers):
print >> sys.stderr, "Warning: Ignoring row of unexpected length", len(tds)
continue
levels = [None]
levels += [make_missing_none(strip_all_tags(td))
for td in tds[1:]]
if country_name in country_to_admin_levels:
print >> sys.stderr, "Warning: Overwriting previous information for country '%s'" % (country_name,)
country_to_admin_levels[country_name] = levels
for country_name, levels in sorted(country_to_admin_levels.items()):
print "####", country_name.encode('utf-8')
for i, s in enumerate(levels):
print "---- level", i
if s:
print " " + s.encode('utf-8')
else:
print " [No information]"
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
12,
295,
199,
504,
9922,
20,
492,
17132,
199,
646,
4011,
18,
199,
199,
633,
275,
298,
1014,
921,
6797,
14,
1490,
20451,
1130,
14,
1308,
15,
6797,
15,
1931,
26,
9891,
5,
19,
36,
2113,
25124,
2,
199,
199,
70,
275,
4011,
18,
14,
10890,
8,
633,
9,
199,
576,
275,
289,
14,
739,
342,
199,
70,
14,
1600,
342,
199,
199,
9317,
275,
17132,
8,
576,
12,
298,
22899,
531,
199,
199,
318,
6202,
63,
452,
63,
2969,
8,
2108,
304,
272,
367,
11665,
315,
1819,
14,
1623,
63,
452,
360,
3289,
735,
267,
11665,
14,
1814,
3007,
8,
85,
3212,
78,
531,
272,
372,
10587,
904,
8,
2108,
14,
32651,
8,
505,
29,
549,
4992,
1913,
342,
199,
199,
3,
377,
344,
89,
1536,
314,
9023,
536,
2763,
446,
473,
6704,
440,
3238,
2337,
1159,
376,
25259,
590,
199,
3,
4383,
16972,
4340,
402,
9689,
642,
367,
314,
12427,
26,
199,
199,
318,
664,
63,
6063,
63,
354,
8,
83,
304,
272,
340,
295,
14,
1733,
28353,
83,
9,
1222,
11106,
2795,
27866,
3479,
297,
308,
304,
267,
372,
283,
27866,
3479,
7,
272,
754,
275,
295,
14,
954,
8,
82,
7,
435,
7023,
29478,
1055,
7693,
3260,
308,
9,
272,
754,
275,
295,
14,
954,
8,
82,
10120,
706,
9,
4,
16110,
3260,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
1154,
83,
15622,
3239,
2597,
92,
1989,
652,
3196,
3260,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
6774,
5858,
460,
92,
4313,
1518,
279,
92,
13848,
554,
92,
4240,
1308,
4674,
92,
27866,
3479,
680,
7693,
6468,
17,
297,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
24550,
85,
9,
5318,
402,
6596,
274,
402,
4688,
60,
83,
7386,
3260,
754,
9,
272,
372,
754,
199,
199,
318,
1852,
63,
4752,
63,
3592,
8,
83,
304,
272,
340,
295,
14,
1733,
28353,
85,
374,
9,
12773,
83,
10,
46,
15,
33,
60,
83,
32125,
308,
304,
267,
372,
488,
272,
587,
26,
267,
372,
308,
199,
199,
6063,
63,
475,
63,
2113,
63,
11402,
275,
1052,
199,
199,
509,
1817,
315,
9108,
14,
1623,
63,
452,
360,
1224,
297,
283,
5319,
390,
461,
735,
272,
4730,
275,
1817,
14,
32651,
360,
454,
297,
9133,
29,
797,
9,
272,
367,
1962,
315,
4730,
26,
267,
294,
83,
275,
1962,
14,
32651,
360,
273,
297,
9133,
29,
797,
9,
267,
340,
294,
83,
26,
288,
2323,
275,
359,
273,
14,
875,
14,
1913,
342,
367,
294,
315,
294,
83,
61,
288,
1980,
267,
307,
795,
275,
1962,
14,
32651,
360,
2076,
297,
9133,
29,
797,
9,
267,
340,
822,
8,
84,
795,
9,
2695,
499,
26,
288,
1980,
267,
9023,
63,
354,
275,
664,
63,
6063,
63,
354,
8,
1913,
63,
452,
63,
2969,
8,
84,
795,
59,
16,
2459,
267,
340,
822,
8,
84,
795,
9,
1137,
822,
8,
2139,
304,
288,
870,
4331,
984,
14,
3083,
12,
298,
3849,
26,
20489,
6854,
1962,
402,
10537,
2582,
401,
822,
8,
84,
795,
9,
288,
1980,
267,
11106,
275,
359,
403,
61,
267,
11106,
847,
359,
1875,
63,
4752,
63,
3592,
8,
1913,
63,
452,
63,
2969,
8,
2076,
430,
673,
367,
12749,
315,
307,
795,
59,
17,
21316,
267,
340,
9023,
63,
354,
315,
9023,
63,
475,
63,
2113,
63,
11402,
26,
288,
870,
4331,
984,
14,
3083,
12,
298,
3849,
26,
7259,
14827,
4136,
2556,
367,
9023,
1543,
83,
4065,
450,
334,
6063,
63,
354,
4258,
267,
9023,
63,
475,
63,
2113,
63,
11402,
59,
6063,
63,
354,
61,
275,
11106,
199,
199,
509,
9023,
63,
354,
12,
11106,
315,
3355,
8,
6063,
63,
475,
63,
2113,
63,
11402,
14,
1744,
5109,
272,
870,
298,
381,
401,
9023,
63,
354,
14,
2143,
360,
1624,
13,
24,
358,
272,
367,
284,
12,
308,
315,
3874,
8,
11402,
304,
267,
870,
298,
375,
2166,
401,
284,
267,
340,
308,
26,
288,
870,
298,
221,
298,
435,
308,
14,
2143,
360,
1624,
13,
24,
358,
267,
587,
26,
288,
870,
298,
221,
359,
1944,
2556,
8480,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
984,
12,
295,
199,
504,
9922,
20,
492,
17132,
199,
646,
4011,
18,
199,
199,
633,
275,
298,
1014,
921,
6797,
14,
1490,
20451,
1130,
14,
1308,
15,
6797,
15,
1931,
26,
9891,
5,
19,
36,
2113,
25124,
2,
199,
199,
70,
275,
4011,
18,
14,
10890,
8,
633,
9,
199,
576,
275,
289,
14,
739,
342,
199,
70,
14,
1600,
342,
199,
199,
9317,
275,
17132,
8,
576,
12,
298,
22899,
531,
199,
199,
318,
6202,
63,
452,
63,
2969,
8,
2108,
304,
272,
367,
11665,
315,
1819,
14,
1623,
63,
452,
360,
3289,
735,
267,
11665,
14,
1814,
3007,
8,
85,
3212,
78,
531,
272,
372,
10587,
904,
8,
2108,
14,
32651,
8,
505,
29,
549,
4992,
1913,
342,
199,
199,
3,
377,
344,
89,
1536,
314,
9023,
536,
2763,
446,
473,
6704,
440,
3238,
2337,
1159,
376,
25259,
590,
199,
3,
4383,
16972,
4340,
402,
9689,
642,
367,
314,
12427,
26,
199,
199,
318,
664,
63,
6063,
63,
354,
8,
83,
304,
272,
340,
295,
14,
1733,
28353,
83,
9,
1222,
11106,
2795,
27866,
3479,
297,
308,
304,
267,
372,
283,
27866,
3479,
7,
272,
754,
275,
295,
14,
954,
8,
82,
7,
435,
7023,
29478,
1055,
7693,
3260,
308,
9,
272,
754,
275,
295,
14,
954,
8,
82,
10120,
706,
9,
4,
16110,
3260,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
1154,
83,
15622,
3239,
2597,
92,
1989,
652,
3196,
3260,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
6774,
5858,
460,
92,
4313,
1518,
279,
92,
13848,
554,
92,
4240,
1308,
4674,
92,
27866,
3479,
680,
7693,
6468,
17,
297,
754,
9,
272,
754,
275,
295,
14,
954,
8,
82,
24550,
85,
9,
5318,
402,
6596,
274,
402,
4688,
60,
83,
7386,
3260,
754,
9,
272,
372,
754,
199,
199,
318,
1852,
63,
4752,
63,
3592,
8,
83,
304,
272,
340,
295,
14,
1733,
28353,
85,
374,
9,
12773,
83,
10,
46,
15,
33,
60,
83,
32125,
308,
304,
267,
372,
488,
272,
587,
26,
267,
372,
308,
199,
199,
6063,
63,
475,
63,
2113,
63,
11402,
275,
1052,
199,
199,
509,
1817,
315,
9108,
14,
1623,
63,
452,
360,
1224,
297,
283,
5319,
390,
461,
735,
272,
4730,
275,
1817,
14,
32651,
360,
454,
297,
9133,
29,
797,
9,
272,
367,
1962,
315,
4730,
26,
267,
294,
83,
275,
1962,
14,
32651,
360,
273,
297,
9133,
29,
797,
9,
267,
340,
294,
83,
26,
288,
2323,
275,
359,
273,
14,
875,
14,
1913,
342,
367,
294,
315,
294,
83,
61,
288,
1980,
267,
307,
795,
275,
1962,
14,
32651,
360,
2076,
297,
9133,
29,
797,
9,
267,
340,
822,
8,
84,
795,
9,
2695,
499,
26,
288,
1980,
267,
9023,
63,
354,
275,
664,
63,
6063,
63,
354,
8,
1913,
63,
452,
63,
2969,
8,
84,
795,
59,
16,
2459,
267,
340,
822,
8,
84,
795,
9,
1137,
822,
8,
2139,
304,
288,
870,
4331,
984,
14,
3083,
12,
298,
3849,
26,
20489,
6854,
1962,
402,
10537,
2582,
401,
822,
8,
84,
795,
9,
288,
1980,
267,
11106,
275,
359,
403,
61,
267,
11106,
847,
359,
1875,
63,
4752,
63,
3592,
8,
1913,
63,
452,
63,
2969,
8,
2076,
430,
673,
367,
12749,
315,
307,
795,
59,
17,
21316,
267,
340,
9023,
63,
354,
315,
9023,
63,
475,
63,
2113,
63,
11402,
26,
288,
870,
4331,
984,
14,
3083,
12,
298,
3849,
26,
7259,
14827,
4136,
2556,
367,
9023,
1543,
83,
4065,
450,
334,
6063,
63,
354,
4258,
267,
9023,
63,
475,
63,
2113,
63,
11402,
59,
6063,
63,
354,
61,
275,
11106,
199,
199,
509,
9023,
63,
354,
12,
11106,
315,
3355,
8,
6063,
63,
475,
63,
2113,
63,
11402,
14,
1744,
5109,
272,
870,
298,
381,
401,
9023,
63,
354,
14,
2143,
360,
1624,
13,
24,
358,
272,
367,
284,
12,
308,
315,
3874,
8,
11402,
304,
267,
870,
298,
375,
2166,
401,
284,
267,
340,
308,
26,
288,
870,
298,
221,
298,
435,
308,
14,
2143,
360,
1624,
13,
24,
358,
267,
587,
26,
288,
870,
298,
221,
359,
1944,
2556,
8480,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
40123210/2015cd-midterm2
|
static/Brython3.1.1-20150328-091302/Lib/datetime.py
|
628
|
75044
|
"""Concrete date/time and related types.
See http://www.iana.org/time-zones/repository/tz-link.html for
time zone and DST data sources.
"""
import time as _time
import math as _math
def _cmp(x, y):
return 0 if x == y else 1 if x > y else -1
MINYEAR = 1
MAXYEAR = 9999
_MAXORDINAL = 3652059 # date.max.toordinal()
# Utility functions, adapted from Python's Demo/classes/Dates.py, which
# also assumes the current Gregorian calendar indefinitely extended in
# both directions. Difference: Dates.py calls January 1 of year 0 day
# number 1. The code here calls January 1 of year 1 day number 1. This is
# to match the definition of the "proleptic Gregorian" calendar in Dershowitz
# and Reingold's "Calendrical Calculations", where it's the base calendar
# for all computations. See the book for algorithms for converting between
# proleptic Gregorian ordinals and many other calendar systems.
_DAYS_IN_MONTH = [None, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
_DAYS_BEFORE_MONTH = [None]
dbm = 0
for dim in _DAYS_IN_MONTH[1:]:
_DAYS_BEFORE_MONTH.append(dbm)
dbm += dim
del dbm, dim
def _is_leap(year):
"year -> 1 if leap year, else 0."
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
def _days_before_year(year):
"year -> number of days before January 1st of year."
y = year - 1
return y*365 + y//4 - y//100 + y//400
def _days_in_month(year, month):
"year, month -> number of days in that month in that year."
assert 1 <= month <= 12, month
if month == 2 and _is_leap(year):
return 29
return _DAYS_IN_MONTH[month]
def _days_before_month(year, month):
"year, month -> number of days in year preceding first day of month."
assert 1 <= month <= 12, 'month must be in 1..12'
return _DAYS_BEFORE_MONTH[month] + (month > 2 and _is_leap(year))
def _ymd2ord(year, month, day):
"year, month, day -> ordinal, considering 01-Jan-0001 as day 1."
assert 1 <= month <= 12, 'month must be in 1..12'
dim = _days_in_month(year, month)
assert 1 <= day <= dim, ('day must be in 1..%d' % dim)
return (_days_before_year(year) +
_days_before_month(year, month) +
day)
_DI400Y = _days_before_year(401) # number of days in 400 years
_DI100Y = _days_before_year(101) # " " " " 100 "
_DI4Y = _days_before_year(5) # " " " " 4 "
# A 4-year cycle has an extra leap day over what we'd get from pasting
# together 4 single years.
assert _DI4Y == 4 * 365 + 1
# Similarly, a 400-year cycle has an extra leap day over what we'd get from
# pasting together 4 100-year cycles.
assert _DI400Y == 4 * _DI100Y + 1
# OTOH, a 100-year cycle has one fewer leap day than we'd get from
# pasting together 25 4-year cycles.
assert _DI100Y == 25 * _DI4Y - 1
def _ord2ymd(n):
"ordinal -> (year, month, day), considering 01-Jan-0001 as day 1."
# n is a 1-based index, starting at 1-Jan-1. The pattern of leap years
# repeats exactly every 400 years. The basic strategy is to find the
# closest 400-year boundary at or before n, then work with the offset
# from that boundary to n. Life is much clearer if we subtract 1 from
# n first -- then the values of n at 400-year boundaries are exactly
# those divisible by _DI400Y:
#
# D M Y n n-1
# -- --- ---- ---------- ----------------
# 31 Dec -400 -_DI400Y -_DI400Y -1
# 1 Jan -399 -_DI400Y +1 -_DI400Y 400-year boundary
# ...
# 30 Dec 000 -1 -2
# 31 Dec 000 0 -1
# 1 Jan 001 1 0 400-year boundary
# 2 Jan 001 2 1
# 3 Jan 001 3 2
# ...
# 31 Dec 400 _DI400Y _DI400Y -1
# 1 Jan 401 _DI400Y +1 _DI400Y 400-year boundary
n -= 1
n400, n = divmod(n, _DI400Y)
year = n400 * 400 + 1 # ..., -399, 1, 401, ...
# Now n is the (non-negative) offset, in days, from January 1 of year, to
# the desired date. Now compute how many 100-year cycles precede n.
# Note that it's possible for n100 to equal 4! In that case 4 full
# 100-year cycles precede the desired day, which implies the desired
# day is December 31 at the end of a 400-year cycle.
n100, n = divmod(n, _DI100Y)
# Now compute how many 4-year cycles precede it.
n4, n = divmod(n, _DI4Y)
# And now how many single years. Again n1 can be 4, and again meaning
# that the desired day is December 31 at the end of the 4-year cycle.
n1, n = divmod(n, 365)
year += n100 * 100 + n4 * 4 + n1
if n1 == 4 or n100 == 4:
assert n == 0
return year-1, 12, 31
# Now the year is correct, and n is the offset from January 1. We find
# the month via an estimate that's either exact or one too large.
leapyear = n1 == 3 and (n4 != 24 or n100 == 3)
assert leapyear == _is_leap(year)
month = (n + 50) >> 5
preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear)
if preceding > n: # estimate is too large
month -= 1
preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear)
n -= preceding
assert 0 <= n < _days_in_month(year, month)
# Now the year and month are correct, and n is the offset from the
# start of that month: we're done!
return year, month, n+1
# Month and day names. For localized versions, see the calendar module.
_MONTHNAMES = [None, "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
_DAYNAMES = [None, "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
def _build_struct_time(y, m, d, hh, mm, ss, dstflag):
wday = (_ymd2ord(y, m, d) + 6) % 7
dnum = _days_before_month(y, m) + d
return _time.struct_time((y, m, d, hh, mm, ss, wday, dnum, dstflag))
def _format_time(hh, mm, ss, us):
# Skip trailing microseconds when us==0.
result = "%02d:%02d:%02d" % (hh, mm, ss)
if us:
result += ".%06d" % us
return result
# Correctly substitute for %z and %Z escapes in strftime formats.
def _wrap_strftime(object, format, timetuple):
# Don't call utcoffset() or tzname() unless actually needed.
freplace = None # the string to use for %f
zreplace = None # the string to use for %z
Zreplace = None # the string to use for %Z
# Scan format for %z and %Z escapes, replacing as needed.
newformat = []
push = newformat.append
i, n = 0, len(format)
while i < n:
ch = format[i]
i += 1
if ch == '%':
if i < n:
ch = format[i]
i += 1
if ch == 'f':
if freplace is None:
freplace = '%06d' % getattr(object,
'microsecond', 0)
newformat.append(freplace)
elif ch == 'z':
if zreplace is None:
zreplace = ""
if hasattr(object, "utcoffset"):
offset = object.utcoffset()
if offset is not None:
sign = '+'
if offset.days < 0:
offset = -offset
sign = '-'
h, m = divmod(offset, timedelta(hours=1))
assert not m % timedelta(minutes=1), "whole minute"
m //= timedelta(minutes=1)
zreplace = '%c%02d%02d' % (sign, h, m)
assert '%' not in zreplace
newformat.append(zreplace)
elif ch == 'Z':
if Zreplace is None:
Zreplace = ""
if hasattr(object, "tzname"):
s = object.tzname()
if s is not None:
# strftime is going to have at this: escape %
Zreplace = s.replace('%', '%%')
newformat.append(Zreplace)
else:
push('%')
push(ch)
else:
push('%')
else:
push(ch)
newformat = "".join(newformat)
return _time.strftime(newformat, timetuple)
def _call_tzinfo_method(tzinfo, methname, tzinfoarg):
if tzinfo is None:
return None
return getattr(tzinfo, methname)(tzinfoarg)
# Just raise TypeError if the arg isn't None or a string.
def _check_tzname(name):
if name is not None and not isinstance(name, str):
raise TypeError("tzinfo.tzname() must return None or string, "
"not '%s'" % type(name))
# name is the offset-producing method, "utcoffset" or "dst".
# offset is what it returned.
# If offset isn't None or timedelta, raises TypeError.
# If offset is None, returns None.
# Else offset is checked for being in range, and a whole # of minutes.
# If it is, its integer value is returned. Else ValueError is raised.
def _check_utc_offset(name, offset):
assert name in ("utcoffset", "dst")
if offset is None:
return
if not isinstance(offset, timedelta):
raise TypeError("tzinfo.%s() must return None "
"or timedelta, not '%s'" % (name, type(offset)))
if offset % timedelta(minutes=1) or offset.microseconds:
raise ValueError("tzinfo.%s() must return a whole number "
"of minutes, got %s" % (name, offset))
if not -timedelta(1) < offset < timedelta(1):
raise ValueError("%s()=%s, must be must be strictly between"
" -timedelta(hours=24) and timedelta(hours=24)"
% (name, offset))
def _check_date_fields(year, month, day):
if not isinstance(year, int):
raise TypeError('int expected')
if not MINYEAR <= year <= MAXYEAR:
raise ValueError('year must be in %d..%d' % (MINYEAR, MAXYEAR), year)
if not 1 <= month <= 12:
raise ValueError('month must be in 1..12', month)
dim = _days_in_month(year, month)
if not 1 <= day <= dim:
raise ValueError('day must be in 1..%d' % dim, day)
def _check_time_fields(hour, minute, second, microsecond):
if not isinstance(hour, int):
raise TypeError('int expected')
if not 0 <= hour <= 23:
raise ValueError('hour must be in 0..23', hour)
if not 0 <= minute <= 59:
raise ValueError('minute must be in 0..59', minute)
if not 0 <= second <= 59:
raise ValueError('second must be in 0..59', second)
if not 0 <= microsecond <= 999999:
raise ValueError('microsecond must be in 0..999999', microsecond)
def _check_tzinfo_arg(tz):
if tz is not None and not isinstance(tz, tzinfo):
raise TypeError("tzinfo argument must be None or of a tzinfo subclass")
def _cmperror(x, y):
raise TypeError("can't compare '%s' to '%s'" % (
type(x).__name__, type(y).__name__))
class timedelta:
"""Represent the difference between two datetime objects.
Supported operators:
- add, subtract timedelta
- unary plus, minus, abs
- compare to timedelta
- multiply, divide by int
In addition, datetime supports subtraction of two datetime objects
returning a timedelta, and addition or subtraction of a datetime
and a timedelta giving a datetime.
Representation: (days, seconds, microseconds). Why? Because I
felt like it.
"""
__slots__ = '_days', '_seconds', '_microseconds'
def __new__(cls, days=0, seconds=0, microseconds=0,
milliseconds=0, minutes=0, hours=0, weeks=0):
# Doing this efficiently and accurately in C is going to be difficult
# and error-prone, due to ubiquitous overflow possibilities, and that
# C double doesn't have enough bits of precision to represent
# microseconds over 10K years faithfully. The code here tries to make
# explicit where go-fast assumptions can be relied on, in order to
# guide the C implementation; it's way more convoluted than speed-
# ignoring auto-overflow-to-long idiomatic Python could be.
# XXX Check that all inputs are ints or floats.
# Final values, all integer.
# s and us fit in 32-bit signed ints; d isn't bounded.
d = s = us = 0
# Normalize everything to days, seconds, microseconds.
days += weeks*7
seconds += minutes*60 + hours*3600
microseconds += milliseconds*1000
# Get rid of all fractions, and normalize s and us.
# Take a deep breath <wink>.
if isinstance(days, float):
dayfrac, days = _math.modf(days)
daysecondsfrac, daysecondswhole = _math.modf(dayfrac * (24.*3600.))
assert daysecondswhole == int(daysecondswhole) # can't overflow
s = int(daysecondswhole)
assert days == int(days)
d = int(days)
else:
daysecondsfrac = 0.0
d = days
assert isinstance(daysecondsfrac, float)
assert abs(daysecondsfrac) <= 1.0
assert isinstance(d, int)
assert abs(s) <= 24 * 3600
# days isn't referenced again before redefinition
if isinstance(seconds, float):
secondsfrac, seconds = _math.modf(seconds)
assert seconds == int(seconds)
seconds = int(seconds)
secondsfrac += daysecondsfrac
assert abs(secondsfrac) <= 2.0
else:
secondsfrac = daysecondsfrac
# daysecondsfrac isn't referenced again
assert isinstance(secondsfrac, float)
assert abs(secondsfrac) <= 2.0
assert isinstance(seconds, int)
days, seconds = divmod(seconds, 24*3600)
d += days
s += int(seconds) # can't overflow
assert isinstance(s, int)
assert abs(s) <= 2 * 24 * 3600
# seconds isn't referenced again before redefinition
usdouble = secondsfrac * 1e6
assert abs(usdouble) < 2.1e6 # exact value not critical
# secondsfrac isn't referenced again
if isinstance(microseconds, float):
microseconds += usdouble
microseconds = round(microseconds, 0)
seconds, microseconds = divmod(microseconds, 1e6)
assert microseconds == int(microseconds)
assert seconds == int(seconds)
days, seconds = divmod(seconds, 24.*3600.)
assert days == int(days)
assert seconds == int(seconds)
d += int(days)
s += int(seconds) # can't overflow
assert isinstance(s, int)
assert abs(s) <= 3 * 24 * 3600
else:
seconds, microseconds = divmod(microseconds, 1000000)
days, seconds = divmod(seconds, 24*3600)
d += days
s += int(seconds) # can't overflow
assert isinstance(s, int)
assert abs(s) <= 3 * 24 * 3600
microseconds = float(microseconds)
microseconds += usdouble
microseconds = round(microseconds, 0)
assert abs(s) <= 3 * 24 * 3600
assert abs(microseconds) < 3.1e6
# Just a little bit of carrying possible for microseconds and seconds.
assert isinstance(microseconds, float)
assert int(microseconds) == microseconds
us = int(microseconds)
seconds, us = divmod(us, 1000000)
s += seconds # cant't overflow
assert isinstance(s, int)
days, s = divmod(s, 24*3600)
d += days
assert isinstance(d, int)
assert isinstance(s, int) and 0 <= s < 24*3600
assert isinstance(us, int) and 0 <= us < 1000000
self = object.__new__(cls)
self._days = d
self._seconds = s
self._microseconds = us
if abs(d) > 999999999:
raise OverflowError("timedelta # of days is too large: %d" % d)
return self
def __repr__(self):
if self._microseconds:
return "%s(%d, %d, %d)" % ('datetime.' + self.__class__.__name__,
self._days,
self._seconds,
self._microseconds)
if self._seconds:
return "%s(%d, %d)" % ('datetime.' + self.__class__.__name__,
self._days,
self._seconds)
return "%s(%d)" % ('datetime.' + self.__class__.__name__, self._days)
def __str__(self):
mm, ss = divmod(self._seconds, 60)
hh, mm = divmod(mm, 60)
s = "%d:%02d:%02d" % (hh, mm, ss)
if self._days:
def plural(n):
return n, abs(n) != 1 and "s" or ""
s = ("%d day%s, " % plural(self._days)) + s
if self._microseconds:
s = s + ".%06d" % self._microseconds
return s
def total_seconds(self):
"""Total seconds in the duration."""
return ((self.days * 86400 + self.seconds)*10**6 +
self.microseconds) / 10**6
# Read-only field accessors
@property
def days(self):
"""days"""
return self._days
@property
def seconds(self):
"""seconds"""
return self._seconds
@property
def microseconds(self):
"""microseconds"""
return self._microseconds
def __add__(self, other):
if isinstance(other, timedelta):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(self._days + other._days,
self._seconds + other._seconds,
self._microseconds + other._microseconds)
return NotImplemented
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, timedelta):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(self._days - other._days,
self._seconds - other._seconds,
self._microseconds - other._microseconds)
return NotImplemented
def __rsub__(self, other):
if isinstance(other, timedelta):
return -self + other
return NotImplemented
def __neg__(self):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(-self._days,
-self._seconds,
-self._microseconds)
def __pos__(self):
return self
def __abs__(self):
if self._days < 0:
return -self
else:
return self
def __mul__(self, other):
if isinstance(other, int):
# for CPython compatibility, we cannot use
# our __class__ here, but need a real timedelta
return timedelta(self._days * other,
self._seconds * other,
self._microseconds * other)
if isinstance(other, float):
a, b = other.as_integer_ratio()
return self * a / b
return NotImplemented
__rmul__ = __mul__
def _to_microseconds(self):
return ((self._days * (24*3600) + self._seconds) * 1000000 +
self._microseconds)
def __floordiv__(self, other):
if not isinstance(other, (int, timedelta)):
return NotImplemented
usec = self._to_microseconds()
if isinstance(other, timedelta):
return usec // other._to_microseconds()
if isinstance(other, int):
return timedelta(0, 0, usec // other)
def __truediv__(self, other):
if not isinstance(other, (int, float, timedelta)):
return NotImplemented
usec = self._to_microseconds()
if isinstance(other, timedelta):
return usec / other._to_microseconds()
if isinstance(other, int):
return timedelta(0, 0, usec / other)
if isinstance(other, float):
a, b = other.as_integer_ratio()
return timedelta(0, 0, b * usec / a)
def __mod__(self, other):
if isinstance(other, timedelta):
r = self._to_microseconds() % other._to_microseconds()
return timedelta(0, 0, r)
return NotImplemented
def __divmod__(self, other):
if isinstance(other, timedelta):
q, r = divmod(self._to_microseconds(),
other._to_microseconds())
return q, timedelta(0, 0, r)
return NotImplemented
# Comparisons of timedelta objects with other.
def __eq__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) == 0
else:
return False
def __ne__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) != 0
else:
return True
def __le__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) <= 0
else:
_cmperror(self, other)
def __lt__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) < 0
else:
_cmperror(self, other)
def __ge__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) >= 0
else:
_cmperror(self, other)
def __gt__(self, other):
if isinstance(other, timedelta):
return self._cmp(other) > 0
else:
_cmperror(self, other)
def _cmp(self, other):
assert isinstance(other, timedelta)
return _cmp(self._getstate(), other._getstate())
def __hash__(self):
return hash(self._getstate())
def __bool__(self):
return (self._days != 0 or
self._seconds != 0 or
self._microseconds != 0)
# Pickle support.
def _getstate(self):
return (self._days, self._seconds, self._microseconds)
def __reduce__(self):
return (self.__class__, self._getstate())
timedelta.min = timedelta(-999999999)
timedelta.max = timedelta(days=999999999, hours=23, minutes=59, seconds=59,
microseconds=999999)
timedelta.resolution = timedelta(microseconds=1)
class date:
"""Concrete date type.
Constructors:
__new__()
fromtimestamp()
today()
fromordinal()
Operators:
__repr__, __str__
__cmp__, __hash__
__add__, __radd__, __sub__ (add/radd only with timedelta arg)
Methods:
timetuple()
toordinal()
weekday()
isoweekday(), isocalendar(), isoformat()
ctime()
strftime()
Properties (readonly):
year, month, day
"""
__slots__ = '_year', '_month', '_day'
def __new__(cls, year, month=None, day=None):
"""Constructor.
Arguments:
year, month, day (required, base 1)
"""
if (isinstance(year, bytes) and len(year) == 4 and
1 <= year[2] <= 12 and month is None): # Month is sane
# Pickle support
self = object.__new__(cls)
self.__setstate(year)
return self
_check_date_fields(year, month, day)
self = object.__new__(cls)
self._year = year
self._month = month
self._day = day
return self
# Additional constructors
@classmethod
def fromtimestamp(cls, t):
"Construct a date from a POSIX timestamp (like time.time())."
y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
return cls(y, m, d)
@classmethod
def today(cls):
"Construct a date from time.time()."
t = _time.time()
return cls.fromtimestamp(t)
@classmethod
def fromordinal(cls, n):
"""Contruct a date from a proleptic Gregorian ordinal.
January 1 of year 1 is day 1. Only the year, month and day are
non-zero in the result.
"""
y, m, d = _ord2ymd(n)
return cls(y, m, d)
# Conversions to string
def __repr__(self):
"""Convert to formal string, for repr().
>>> dt = datetime(2010, 1, 1)
>>> repr(dt)
'datetime.datetime(2010, 1, 1, 0, 0)'
>>> dt = datetime(2010, 1, 1, tzinfo=timezone.utc)
>>> repr(dt)
'datetime.datetime(2010, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)'
"""
return "%s(%d, %d, %d)" % ('datetime.' + self.__class__.__name__,
self._year,
self._month,
self._day)
# XXX These shouldn't depend on time.localtime(), because that
# clips the usable dates to [1970 .. 2038). At least ctime() is
# easily done without using strftime() -- that's better too because
# strftime("%c", ...) is locale specific.
def ctime(self):
"Return ctime() style string."
weekday = self.toordinal() % 7 or 7
return "%s %s %2d 00:00:00 %04d" % (
_DAYNAMES[weekday],
_MONTHNAMES[self._month],
self._day, self._year)
def strftime(self, fmt):
"Format using strftime()."
return _wrap_strftime(self, fmt, self.timetuple())
def __format__(self, fmt):
if len(fmt) != 0:
return self.strftime(fmt)
return str(self)
def isoformat(self):
"""Return the date formatted according to ISO.
This is 'YYYY-MM-DD'.
References:
- http://www.w3.org/TR/NOTE-datetime
- http://www.cl.cam.ac.uk/~mgk25/iso-time.html
"""
return "%04d-%02d-%02d" % (self._year, self._month, self._day)
__str__ = isoformat
# Read-only field accessors
@property
def year(self):
"""year (1-9999)"""
return self._year
@property
def month(self):
"""month (1-12)"""
return self._month
@property
def day(self):
"""day (1-31)"""
return self._day
# Standard conversions, __cmp__, __hash__ (and helpers)
def timetuple(self):
"Return local time tuple compatible with time.localtime()."
return _build_struct_time(self._year, self._month, self._day,
0, 0, 0, -1)
def toordinal(self):
"""Return proleptic Gregorian ordinal for the year, month and day.
January 1 of year 1 is day 1. Only the year, month and day values
contribute to the result.
"""
return _ymd2ord(self._year, self._month, self._day)
def replace(self, year=None, month=None, day=None):
"""Return a new date with new values for the specified fields."""
if year is None:
year = self._year
if month is None:
month = self._month
if day is None:
day = self._day
_check_date_fields(year, month, day)
return date(year, month, day)
# Comparisons of date objects with other.
def __eq__(self, other):
if isinstance(other, date):
return self._cmp(other) == 0
return NotImplemented
def __ne__(self, other):
if isinstance(other, date):
return self._cmp(other) != 0
return NotImplemented
def __le__(self, other):
if isinstance(other, date):
return self._cmp(other) <= 0
return NotImplemented
def __lt__(self, other):
if isinstance(other, date):
return self._cmp(other) < 0
return NotImplemented
def __ge__(self, other):
if isinstance(other, date):
return self._cmp(other) >= 0
return NotImplemented
def __gt__(self, other):
if isinstance(other, date):
return self._cmp(other) > 0
return NotImplemented
def _cmp(self, other):
assert isinstance(other, date)
y, m, d = self._year, self._month, self._day
y2, m2, d2 = other._year, other._month, other._day
return _cmp((y, m, d), (y2, m2, d2))
def __hash__(self):
"Hash."
return hash(self._getstate())
# Computations
def __add__(self, other):
"Add a date to a timedelta."
if isinstance(other, timedelta):
o = self.toordinal() + other.days
if 0 < o <= _MAXORDINAL:
return date.fromordinal(o)
raise OverflowError("result out of range")
return NotImplemented
__radd__ = __add__
def __sub__(self, other):
"""Subtract two dates, or a date and a timedelta."""
if isinstance(other, timedelta):
return self + timedelta(-other.days)
if isinstance(other, date):
days1 = self.toordinal()
days2 = other.toordinal()
return timedelta(days1 - days2)
return NotImplemented
def weekday(self):
"Return day of the week, where Monday == 0 ... Sunday == 6."
return (self.toordinal() + 6) % 7
# Day-of-the-week and week-of-the-year, according to ISO
def isoweekday(self):
"Return day of the week, where Monday == 1 ... Sunday == 7."
# 1-Jan-0001 is a Monday
return self.toordinal() % 7 or 7
def isocalendar(self):
"""Return a 3-tuple containing ISO year, week number, and weekday.
The first ISO week of the year is the (Mon-Sun) week
containing the year's first Thursday; everything else derives
from that.
The first week is 1; Monday is 1 ... Sunday is 7.
ISO calendar algorithm taken from
http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
"""
year = self._year
week1monday = _isoweek1monday(year)
today = _ymd2ord(self._year, self._month, self._day)
# Internally, week and day have origin 0
week, day = divmod(today - week1monday, 7)
if week < 0:
year -= 1
week1monday = _isoweek1monday(year)
week, day = divmod(today - week1monday, 7)
elif week >= 52:
if today >= _isoweek1monday(year+1):
year += 1
week = 0
return year, week+1, day+1
# Pickle support.
def _getstate(self):
yhi, ylo = divmod(self._year, 256)
return bytes([yhi, ylo, self._month, self._day]),
def __setstate(self, string):
if len(string) != 4 or not (1 <= string[2] <= 12):
raise TypeError("not enough arguments")
yhi, ylo, self._month, self._day = string
self._year = yhi * 256 + ylo
def __reduce__(self):
return (self.__class__, self._getstate())
_date_class = date # so functions w/ args named "date" can get at the class
date.min = date(1, 1, 1)
date.max = date(9999, 12, 31)
date.resolution = timedelta(days=1)
class tzinfo:
"""Abstract base class for time zone info classes.
Subclasses must override the name(), utcoffset() and dst() methods.
"""
__slots__ = ()
def tzname(self, dt):
"datetime -> string name of time zone."
raise NotImplementedError("tzinfo subclass must override tzname()")
def utcoffset(self, dt):
"datetime -> minutes east of UTC (negative for west of UTC)"
raise NotImplementedError("tzinfo subclass must override utcoffset()")
def dst(self, dt):
"""datetime -> DST offset in minutes east of UTC.
Return 0 if DST not in effect. utcoffset() must include the DST
offset.
"""
raise NotImplementedError("tzinfo subclass must override dst()")
def fromutc(self, dt):
"datetime in UTC -> datetime in local time."
if not isinstance(dt, datetime):
raise TypeError("fromutc() requires a datetime argument")
if dt.tzinfo is not self:
raise ValueError("dt.tzinfo is not self")
dtoff = dt.utcoffset()
if dtoff is None:
raise ValueError("fromutc() requires a non-None utcoffset() "
"result")
# See the long comment block at the end of this file for an
# explanation of this algorithm.
dtdst = dt.dst()
if dtdst is None:
raise ValueError("fromutc() requires a non-None dst() result")
delta = dtoff - dtdst
if delta:
dt += delta
dtdst = dt.dst()
if dtdst is None:
raise ValueError("fromutc(): dt.dst gave inconsistent "
"results; cannot convert")
return dt + dtdst
# Pickle support.
def __reduce__(self):
getinitargs = getattr(self, "__getinitargs__", None)
if getinitargs:
args = getinitargs()
else:
args = ()
getstate = getattr(self, "__getstate__", None)
if getstate:
state = getstate()
else:
state = getattr(self, "__dict__", None) or None
if state is None:
return (self.__class__, args)
else:
return (self.__class__, args, state)
_tzinfo_class = tzinfo
class time:
"""Time with time zone.
Constructors:
__new__()
Operators:
__repr__, __str__
__cmp__, __hash__
Methods:
strftime()
isoformat()
utcoffset()
tzname()
dst()
Properties (readonly):
hour, minute, second, microsecond, tzinfo
"""
def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
"""Constructor.
Arguments:
hour, minute (required)
second, microsecond (default to zero)
tzinfo (default to None)
"""
self = object.__new__(cls)
if isinstance(hour, bytes) and len(hour) == 6:
# Pickle support
self.__setstate(hour, minute or None)
return self
_check_tzinfo_arg(tzinfo)
_check_time_fields(hour, minute, second, microsecond)
self._hour = hour
self._minute = minute
self._second = second
self._microsecond = microsecond
self._tzinfo = tzinfo
return self
# Read-only field accessors
@property
def hour(self):
"""hour (0-23)"""
return self._hour
@property
def minute(self):
"""minute (0-59)"""
return self._minute
@property
def second(self):
"""second (0-59)"""
return self._second
@property
def microsecond(self):
"""microsecond (0-999999)"""
return self._microsecond
@property
def tzinfo(self):
"""timezone info object"""
return self._tzinfo
# Standard conversions, __hash__ (and helpers)
# Comparisons of time objects with other.
def __eq__(self, other):
if isinstance(other, time):
return self._cmp(other, allow_mixed=True) == 0
else:
return False
def __ne__(self, other):
if isinstance(other, time):
return self._cmp(other, allow_mixed=True) != 0
else:
return True
def __le__(self, other):
if isinstance(other, time):
return self._cmp(other) <= 0
else:
_cmperror(self, other)
def __lt__(self, other):
if isinstance(other, time):
return self._cmp(other) < 0
else:
_cmperror(self, other)
def __ge__(self, other):
if isinstance(other, time):
return self._cmp(other) >= 0
else:
_cmperror(self, other)
def __gt__(self, other):
if isinstance(other, time):
return self._cmp(other) > 0
else:
_cmperror(self, other)
def _cmp(self, other, allow_mixed=False):
assert isinstance(other, time)
mytz = self._tzinfo
ottz = other._tzinfo
myoff = otoff = None
if mytz is ottz:
base_compare = True
else:
myoff = self.utcoffset()
otoff = other.utcoffset()
base_compare = myoff == otoff
if base_compare:
return _cmp((self._hour, self._minute, self._second,
self._microsecond),
(other._hour, other._minute, other._second,
other._microsecond))
if myoff is None or otoff is None:
if allow_mixed:
return 2 # arbitrary non-zero value
else:
raise TypeError("cannot compare naive and aware times")
myhhmm = self._hour * 60 + self._minute - myoff//timedelta(minutes=1)
othhmm = other._hour * 60 + other._minute - otoff//timedelta(minutes=1)
return _cmp((myhhmm, self._second, self._microsecond),
(othhmm, other._second, other._microsecond))
def __hash__(self):
"""Hash."""
tzoff = self.utcoffset()
if not tzoff: # zero or None
return hash(self._getstate()[0])
h, m = divmod(timedelta(hours=self.hour, minutes=self.minute) - tzoff,
timedelta(hours=1))
assert not m % timedelta(minutes=1), "whole minute"
m //= timedelta(minutes=1)
if 0 <= h < 24:
return hash(time(h, m, self.second, self.microsecond))
return hash((h, m, self.second, self.microsecond))
# Conversion to string
def _tzstr(self, sep=":"):
"""Return formatted timezone offset (+xx:xx) or None."""
off = self.utcoffset()
if off is not None:
if off.days < 0:
sign = "-"
off = -off
else:
sign = "+"
hh, mm = divmod(off, timedelta(hours=1))
assert not mm % timedelta(minutes=1), "whole minute"
mm //= timedelta(minutes=1)
assert 0 <= hh < 24
off = "%s%02d%s%02d" % (sign, hh, sep, mm)
return off
def __repr__(self):
"""Convert to formal string, for repr()."""
if self._microsecond != 0:
s = ", %d, %d" % (self._second, self._microsecond)
elif self._second != 0:
s = ", %d" % self._second
else:
s = ""
s= "%s(%d, %d%s)" % ('datetime.' + self.__class__.__name__,
self._hour, self._minute, s)
if self._tzinfo is not None:
assert s[-1:] == ")"
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
return s
def isoformat(self):
"""Return the time formatted according to ISO.
This is 'HH:MM:SS.mmmmmm+zz:zz', or 'HH:MM:SS+zz:zz' if
self.microsecond == 0.
"""
s = _format_time(self._hour, self._minute, self._second,
self._microsecond)
tz = self._tzstr()
if tz:
s += tz
return s
__str__ = isoformat
def strftime(self, fmt):
"""Format using strftime(). The date part of the timestamp passed
to underlying strftime should not be used.
"""
# The year must be >= 1000 else Python's strftime implementation
# can raise a bogus exception.
timetuple = (1900, 1, 1,
self._hour, self._minute, self._second,
0, 1, -1)
return _wrap_strftime(self, fmt, timetuple)
def __format__(self, fmt):
if len(fmt) != 0:
return self.strftime(fmt)
return str(self)
# Timezone functions
def utcoffset(self):
"""Return the timezone offset in minutes east of UTC (negative west of
UTC)."""
if self._tzinfo is None:
return None
offset = self._tzinfo.utcoffset(None)
_check_utc_offset("utcoffset", offset)
return offset
def tzname(self):
"""Return the timezone name.
Note that the name is 100% informational -- there's no requirement that
it mean anything in particular. For example, "GMT", "UTC", "-500",
"-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies.
"""
if self._tzinfo is None:
return None
name = self._tzinfo.tzname(None)
_check_tzname(name)
return name
def dst(self):
"""Return 0 if DST is not in effect, or the DST offset (in minutes
eastward) if DST is in effect.
This is purely informational; the DST offset has already been added to
the UTC offset returned by utcoffset() if applicable, so there's no
need to consult dst() unless you're interested in displaying the DST
info.
"""
if self._tzinfo is None:
return None
offset = self._tzinfo.dst(None)
_check_utc_offset("dst", offset)
return offset
def replace(self, hour=None, minute=None, second=None, microsecond=None,
tzinfo=True):
"""Return a new time with new values for the specified fields."""
if hour is None:
hour = self.hour
if minute is None:
minute = self.minute
if second is None:
second = self.second
if microsecond is None:
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
_check_time_fields(hour, minute, second, microsecond)
_check_tzinfo_arg(tzinfo)
return time(hour, minute, second, microsecond, tzinfo)
def __bool__(self):
if self.second or self.microsecond:
return True
offset = self.utcoffset() or timedelta(0)
return timedelta(hours=self.hour, minutes=self.minute) != offset
# Pickle support.
def _getstate(self):
us2, us3 = divmod(self._microsecond, 256)
us1, us2 = divmod(us2, 256)
basestate = bytes([self._hour, self._minute, self._second,
us1, us2, us3])
if self._tzinfo is None:
return (basestate,)
else:
return (basestate, self._tzinfo)
def __setstate(self, string, tzinfo):
if len(string) != 6 or string[0] >= 24:
raise TypeError("an integer is required")
(self._hour, self._minute, self._second,
us1, us2, us3) = string
self._microsecond = (((us1 << 8) | us2) << 8) | us3
if tzinfo is None or isinstance(tzinfo, _tzinfo_class):
self._tzinfo = tzinfo
else:
raise TypeError("bad tzinfo state arg %r" % tzinfo)
def __reduce__(self):
return (time, self._getstate())
_time_class = time # so functions w/ args named "time" can get at the class
time.min = time(0, 0, 0)
time.max = time(23, 59, 59, 999999)
time.resolution = timedelta(microseconds=1)
class datetime(date):
"""datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints.
"""
__slots__ = date.__slots__ + (
'_hour', '_minute', '_second',
'_microsecond', '_tzinfo')
def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
microsecond=0, tzinfo=None):
if isinstance(year, bytes) and len(year) == 10:
# Pickle support
self = date.__new__(cls, year[:4])
self.__setstate(year, month)
return self
_check_tzinfo_arg(tzinfo)
_check_time_fields(hour, minute, second, microsecond)
self = date.__new__(cls, year, month, day)
self._hour = hour
self._minute = minute
self._second = second
self._microsecond = microsecond
self._tzinfo = tzinfo
return self
# Read-only field accessors
@property
def hour(self):
"""hour (0-23)"""
return self._hour
@property
def minute(self):
"""minute (0-59)"""
return self._minute
@property
def second(self):
"""second (0-59)"""
return self._second
@property
def microsecond(self):
"""microsecond (0-999999)"""
return self._microsecond
@property
def tzinfo(self):
"""timezone info object"""
return self._tzinfo
@classmethod
def fromtimestamp(cls, t, tz=None):
"""Construct a datetime from a POSIX timestamp (like time.time()).
A timezone info object may be passed in as well.
"""
_check_tzinfo_arg(tz)
converter = _time.localtime if tz is None else _time.gmtime
t, frac = divmod(t, 1.0)
us = int(frac * 1e6)
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,
# roll over to seconds, otherwise, ValueError is raised
# by the constructor.
if us == 1000000:
t += 1
us = 0
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)
ss = min(ss, 59) # clamp out leap seconds if the platform has them
result = cls(y, m, d, hh, mm, ss, us, tz)
if tz is not None:
result = tz.fromutc(result)
return result
@classmethod
def utcfromtimestamp(cls, t):
"Construct a UTC datetime from a POSIX timestamp (like time.time())."
t, frac = divmod(t, 1.0)
us = int(frac * 1e6)
# If timestamp is less than one microsecond smaller than a
# full second, us can be rounded up to 1000000. In this case,
# roll over to seconds, otherwise, ValueError is raised
# by the constructor.
if us == 1000000:
t += 1
us = 0
y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t)
ss = min(ss, 59) # clamp out leap seconds if the platform has them
return cls(y, m, d, hh, mm, ss, us)
# XXX This is supposed to do better than we *can* do by using time.time(),
# XXX if the platform supports a more accurate way. The C implementation
# XXX uses gettimeofday on platforms that have it, but that isn't
# XXX available from Python. So now() may return different results
# XXX across the implementations.
@classmethod
def now(cls, tz=None):
"Construct a datetime from time.time() and optional time zone info."
t = _time.time()
return cls.fromtimestamp(t, tz)
@classmethod
def utcnow(cls):
"Construct a UTC datetime from time.time()."
t = _time.time()
return cls.utcfromtimestamp(t)
@classmethod
def combine(cls, date, time):
"Construct a datetime from a given date and a given time."
if not isinstance(date, _date_class):
raise TypeError("date argument must be a date instance")
if not isinstance(time, _time_class):
raise TypeError("time argument must be a time instance")
return cls(date.year, date.month, date.day,
time.hour, time.minute, time.second, time.microsecond,
time.tzinfo)
def timetuple(self):
"Return local time tuple compatible with time.localtime()."
dst = self.dst()
if dst is None:
dst = -1
elif dst:
dst = 1
else:
dst = 0
return _build_struct_time(self.year, self.month, self.day,
self.hour, self.minute, self.second,
dst)
def timestamp(self):
"Return POSIX timestamp as float"
if self._tzinfo is None:
return _time.mktime((self.year, self.month, self.day,
self.hour, self.minute, self.second,
-1, -1, -1)) + self.microsecond / 1e6
else:
return (self - _EPOCH).total_seconds()
def utctimetuple(self):
"Return UTC time tuple compatible with time.gmtime()."
offset = self.utcoffset()
if offset:
self -= offset
y, m, d = self.year, self.month, self.day
hh, mm, ss = self.hour, self.minute, self.second
return _build_struct_time(y, m, d, hh, mm, ss, 0)
def date(self):
"Return the date part."
return date(self._year, self._month, self._day)
def time(self):
"Return the time part, with tzinfo None."
return time(self.hour, self.minute, self.second, self.microsecond)
def timetz(self):
"Return the time part, with same tzinfo."
return time(self.hour, self.minute, self.second, self.microsecond,
self._tzinfo)
def replace(self, year=None, month=None, day=None, hour=None,
minute=None, second=None, microsecond=None, tzinfo=True):
"""Return a new datetime with new values for the specified fields."""
if year is None:
year = self.year
if month is None:
month = self.month
if day is None:
day = self.day
if hour is None:
hour = self.hour
if minute is None:
minute = self.minute
if second is None:
second = self.second
if microsecond is None:
microsecond = self.microsecond
if tzinfo is True:
tzinfo = self.tzinfo
_check_date_fields(year, month, day)
_check_time_fields(hour, minute, second, microsecond)
_check_tzinfo_arg(tzinfo)
return datetime(year, month, day, hour, minute, second,
microsecond, tzinfo)
def astimezone(self, tz=None):
if tz is None:
if self.tzinfo is None:
raise ValueError("astimezone() requires an aware datetime")
ts = (self - _EPOCH) // timedelta(seconds=1)
localtm = _time.localtime(ts)
local = datetime(*localtm[:6])
try:
# Extract TZ data if available
gmtoff = localtm.tm_gmtoff
zone = localtm.tm_zone
except AttributeError:
# Compute UTC offset and compare with the value implied
# by tm_isdst. If the values match, use the zone name
# implied by tm_isdst.
delta = local - datetime(*_time.gmtime(ts)[:6])
dst = _time.daylight and localtm.tm_isdst > 0
gmtoff = -(_time.altzone if dst else _time.timezone)
if delta == timedelta(seconds=gmtoff):
tz = timezone(delta, _time.tzname[dst])
else:
tz = timezone(delta)
else:
tz = timezone(timedelta(seconds=gmtoff), zone)
elif not isinstance(tz, tzinfo):
raise TypeError("tz argument must be an instance of tzinfo")
mytz = self.tzinfo
if mytz is None:
raise ValueError("astimezone() requires an aware datetime")
if tz is mytz:
return self
# Convert self to UTC, and attach the new time zone object.
myoffset = self.utcoffset()
if myoffset is None:
raise ValueError("astimezone() requires an aware datetime")
utc = (self - myoffset).replace(tzinfo=tz)
# Convert from UTC to tz's local time.
return tz.fromutc(utc)
# Ways to produce a string.
def ctime(self):
"Return ctime() style string."
weekday = self.toordinal() % 7 or 7
return "%s %s %2d %02d:%02d:%02d %04d" % (
_DAYNAMES[weekday],
_MONTHNAMES[self._month],
self._day,
self._hour, self._minute, self._second,
self._year)
def isoformat(self, sep='T'):
"""Return the time formatted according to ISO.
This is 'YYYY-MM-DD HH:MM:SS.mmmmmm', or 'YYYY-MM-DD HH:MM:SS' if
self.microsecond == 0.
If self.tzinfo is not None, the UTC offset is also attached, giving
'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM' or 'YYYY-MM-DD HH:MM:SS+HH:MM'.
Optional argument sep specifies the separator between date and
time, default 'T'.
"""
s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day,
sep) +
_format_time(self._hour, self._minute, self._second,
self._microsecond))
off = self.utcoffset()
if off is not None:
if off.days < 0:
sign = "-"
off = -off
else:
sign = "+"
hh, mm = divmod(off, timedelta(hours=1))
assert not mm % timedelta(minutes=1), "whole minute"
mm //= timedelta(minutes=1)
s += "%s%02d:%02d" % (sign, hh, mm)
return s
def __repr__(self):
"""Convert to formal string, for repr()."""
L = [self._year, self._month, self._day, # These are never zero
self._hour, self._minute, self._second, self._microsecond]
if L[-1] == 0:
del L[-1]
if L[-1] == 0:
del L[-1]
s = ", ".join(map(str, L))
s = "%s(%s)" % ('datetime.' + self.__class__.__name__, s)
if self._tzinfo is not None:
assert s[-1:] == ")"
s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")"
return s
def __str__(self):
"Convert to string, for str()."
return self.isoformat(sep=' ')
@classmethod
def strptime(cls, date_string, format):
'string, format -> new datetime parsed from a string (like time.strptime()).'
import _strptime
return _strptime._strptime_datetime(cls, date_string, format)
def utcoffset(self):
"""Return the timezone offset in minutes east of UTC (negative west of
UTC)."""
if self._tzinfo is None:
return None
offset = self._tzinfo.utcoffset(self)
_check_utc_offset("utcoffset", offset)
return offset
def tzname(self):
"""Return the timezone name.
Note that the name is 100% informational -- there's no requirement that
it mean anything in particular. For example, "GMT", "UTC", "-500",
"-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies.
"""
name = _call_tzinfo_method(self._tzinfo, "tzname", self)
_check_tzname(name)
return name
def dst(self):
"""Return 0 if DST is not in effect, or the DST offset (in minutes
eastward) if DST is in effect.
This is purely informational; the DST offset has already been added to
the UTC offset returned by utcoffset() if applicable, so there's no
need to consult dst() unless you're interested in displaying the DST
info.
"""
if self._tzinfo is None:
return None
offset = self._tzinfo.dst(self)
_check_utc_offset("dst", offset)
return offset
# Comparisons of datetime objects with other.
def __eq__(self, other):
if isinstance(other, datetime):
return self._cmp(other, allow_mixed=True) == 0
elif not isinstance(other, date):
return NotImplemented
else:
return False
def __ne__(self, other):
if isinstance(other, datetime):
return self._cmp(other, allow_mixed=True) != 0
elif not isinstance(other, date):
return NotImplemented
else:
return True
def __le__(self, other):
if isinstance(other, datetime):
return self._cmp(other) <= 0
elif not isinstance(other, date):
return NotImplemented
else:
_cmperror(self, other)
def __lt__(self, other):
if isinstance(other, datetime):
return self._cmp(other) < 0
elif not isinstance(other, date):
return NotImplemented
else:
_cmperror(self, other)
def __ge__(self, other):
if isinstance(other, datetime):
return self._cmp(other) >= 0
elif not isinstance(other, date):
return NotImplemented
else:
_cmperror(self, other)
def __gt__(self, other):
if isinstance(other, datetime):
return self._cmp(other) > 0
elif not isinstance(other, date):
return NotImplemented
else:
_cmperror(self, other)
def _cmp(self, other, allow_mixed=False):
assert isinstance(other, datetime)
mytz = self._tzinfo
ottz = other._tzinfo
myoff = otoff = None
if mytz is ottz:
base_compare = True
else:
myoff = self.utcoffset()
otoff = other.utcoffset()
base_compare = myoff == otoff
if base_compare:
return _cmp((self._year, self._month, self._day,
self._hour, self._minute, self._second,
self._microsecond),
(other._year, other._month, other._day,
other._hour, other._minute, other._second,
other._microsecond))
if myoff is None or otoff is None:
if allow_mixed:
return 2 # arbitrary non-zero value
else:
raise TypeError("cannot compare naive and aware datetimes")
# XXX What follows could be done more efficiently...
diff = self - other # this will take offsets into account
if diff.days < 0:
return -1
return diff and 1 or 0
def __add__(self, other):
"Add a datetime and a timedelta."
if not isinstance(other, timedelta):
return NotImplemented
delta = timedelta(self.toordinal(),
hours=self._hour,
minutes=self._minute,
seconds=self._second,
microseconds=self._microsecond)
delta += other
hour, rem = divmod(delta.seconds, 3600)
minute, second = divmod(rem, 60)
if 0 < delta.days <= _MAXORDINAL:
return datetime.combine(date.fromordinal(delta.days),
time(hour, minute, second,
delta.microseconds,
tzinfo=self._tzinfo))
raise OverflowError("result out of range")
__radd__ = __add__
def __sub__(self, other):
"Subtract two datetimes, or a datetime and a timedelta."
if not isinstance(other, datetime):
if isinstance(other, timedelta):
return self + -other
return NotImplemented
days1 = self.toordinal()
days2 = other.toordinal()
secs1 = self._second + self._minute * 60 + self._hour * 3600
secs2 = other._second + other._minute * 60 + other._hour * 3600
base = timedelta(days1 - days2,
secs1 - secs2,
self._microsecond - other._microsecond)
if self._tzinfo is other._tzinfo:
return base
myoff = self.utcoffset()
otoff = other.utcoffset()
if myoff == otoff:
return base
if myoff is None or otoff is None:
raise TypeError("cannot mix naive and timezone-aware time")
return base + otoff - myoff
def __hash__(self):
tzoff = self.utcoffset()
if tzoff is None:
return hash(self._getstate()[0])
days = _ymd2ord(self.year, self.month, self.day)
seconds = self.hour * 3600 + self.minute * 60 + self.second
return hash(timedelta(days, seconds, self.microsecond) - tzoff)
# Pickle support.
def _getstate(self):
yhi, ylo = divmod(self._year, 256)
us2, us3 = divmod(self._microsecond, 256)
us1, us2 = divmod(us2, 256)
basestate = bytes([yhi, ylo, self._month, self._day,
self._hour, self._minute, self._second,
us1, us2, us3])
if self._tzinfo is None:
return (basestate,)
else:
return (basestate, self._tzinfo)
def __setstate(self, string, tzinfo):
(yhi, ylo, self._month, self._day, self._hour,
self._minute, self._second, us1, us2, us3) = string
self._year = yhi * 256 + ylo
self._microsecond = (((us1 << 8) | us2) << 8) | us3
if tzinfo is None or isinstance(tzinfo, _tzinfo_class):
self._tzinfo = tzinfo
else:
raise TypeError("bad tzinfo state arg %r" % tzinfo)
def __reduce__(self):
return (self.__class__, self._getstate())
datetime.min = datetime(1, 1, 1)
datetime.max = datetime(9999, 12, 31, 23, 59, 59, 999999)
datetime.resolution = timedelta(microseconds=1)
def _isoweek1monday(year):
# Helper to calculate the day number of the Monday starting week 1
# XXX This could be done more efficiently
THURSDAY = 3
firstday = _ymd2ord(year, 1, 1)
firstweekday = (firstday + 6) % 7 # See weekday() above
week1monday = firstday - firstweekday
if firstweekday > THURSDAY:
week1monday += 7
return week1monday
class timezone(tzinfo):
__slots__ = '_offset', '_name'
# Sentinel value to disallow None
_Omitted = object()
def __new__(cls, offset, name=_Omitted):
if not isinstance(offset, timedelta):
raise TypeError("offset must be a timedelta")
if name is cls._Omitted:
if not offset:
return cls.utc
name = None
elif not isinstance(name, str):
raise TypeError("name must be a string")
if not cls._minoffset <= offset <= cls._maxoffset:
raise ValueError("offset must be a timedelta"
" strictly between -timedelta(hours=24) and"
" timedelta(hours=24).")
if (offset.microseconds != 0 or
offset.seconds % 60 != 0):
raise ValueError("offset must be a timedelta"
" representing a whole number of minutes")
return cls._create(offset, name)
@classmethod
def _create(cls, offset, name=None):
self = tzinfo.__new__(cls)
self._offset = offset
self._name = name
return self
def __getinitargs__(self):
"""pickle support"""
if self._name is None:
return (self._offset,)
return (self._offset, self._name)
def __eq__(self, other):
if type(other) != timezone:
return False
return self._offset == other._offset
def __hash__(self):
return hash(self._offset)
def __repr__(self):
"""Convert to formal string, for repr().
>>> tz = timezone.utc
>>> repr(tz)
'datetime.timezone.utc'
>>> tz = timezone(timedelta(hours=-5), 'EST')
>>> repr(tz)
"datetime.timezone(datetime.timedelta(-1, 68400), 'EST')"
"""
if self is self.utc:
return 'datetime.timezone.utc'
if self._name is None:
return "%s(%r)" % ('datetime.' + self.__class__.__name__,
self._offset)
return "%s(%r, %r)" % ('datetime.' + self.__class__.__name__,
self._offset, self._name)
def __str__(self):
return self.tzname(None)
def utcoffset(self, dt):
if isinstance(dt, datetime) or dt is None:
return self._offset
raise TypeError("utcoffset() argument must be a datetime instance"
" or None")
def tzname(self, dt):
if isinstance(dt, datetime) or dt is None:
if self._name is None:
return self._name_from_offset(self._offset)
return self._name
raise TypeError("tzname() argument must be a datetime instance"
" or None")
def dst(self, dt):
if isinstance(dt, datetime) or dt is None:
return None
raise TypeError("dst() argument must be a datetime instance"
" or None")
def fromutc(self, dt):
if isinstance(dt, datetime):
if dt.tzinfo is not self:
raise ValueError("fromutc: dt.tzinfo "
"is not self")
return dt + self._offset
raise TypeError("fromutc() argument must be a datetime instance"
" or None")
_maxoffset = timedelta(hours=23, minutes=59)
_minoffset = -_maxoffset
@staticmethod
def _name_from_offset(delta):
if delta < timedelta(0):
sign = '-'
delta = -delta
else:
sign = '+'
hours, rest = divmod(delta, timedelta(hours=1))
minutes = rest // timedelta(minutes=1)
return 'UTC{}{:02d}:{:02d}'.format(sign, hours, minutes)
timezone.utc = timezone._create(timedelta(0))
timezone.min = timezone._create(timezone._minoffset)
timezone.max = timezone._create(timezone._maxoffset)
_EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
"""
Some time zone algebra. For a datetime x, let
x.n = x stripped of its timezone -- its naive time.
x.o = x.utcoffset(), and assuming that doesn't raise an exception or
return None
x.d = x.dst(), and assuming that doesn't raise an exception or
return None
x.s = x's standard offset, x.o - x.d
Now some derived rules, where k is a duration (timedelta).
1. x.o = x.s + x.d
This follows from the definition of x.s.
2. If x and y have the same tzinfo member, x.s = y.s.
This is actually a requirement, an assumption we need to make about
sane tzinfo classes.
3. The naive UTC time corresponding to x is x.n - x.o.
This is again a requirement for a sane tzinfo class.
4. (x+k).s = x.s
This follows from #2, and that datimetimetz+timedelta preserves tzinfo.
5. (x+k).n = x.n + k
Again follows from how arithmetic is defined.
Now we can explain tz.fromutc(x). Let's assume it's an interesting case
(meaning that the various tzinfo methods exist, and don't blow up or return
None when called).
The function wants to return a datetime y with timezone tz, equivalent to x.
x is already in UTC.
By #3, we want
y.n - y.o = x.n [1]
The algorithm starts by attaching tz to x.n, and calling that y. So
x.n = y.n at the start. Then it wants to add a duration k to y, so that [1]
becomes true; in effect, we want to solve [2] for k:
(y+k).n - (y+k).o = x.n [2]
By #1, this is the same as
(y+k).n - ((y+k).s + (y+k).d) = x.n [3]
By #5, (y+k).n = y.n + k, which equals x.n + k because x.n=y.n at the start.
Substituting that into [3],
x.n + k - (y+k).s - (y+k).d = x.n; the x.n terms cancel, leaving
k - (y+k).s - (y+k).d = 0; rearranging,
k = (y+k).s - (y+k).d; by #4, (y+k).s == y.s, so
k = y.s - (y+k).d
On the RHS, (y+k).d can't be computed directly, but y.s can be, and we
approximate k by ignoring the (y+k).d term at first. Note that k can't be
very large, since all offset-returning methods return a duration of magnitude
less than 24 hours. For that reason, if y is firmly in std time, (y+k).d must
be 0, so ignoring it has no consequence then.
In any case, the new value is
z = y + y.s [4]
It's helpful to step back at look at [4] from a higher level: it's simply
mapping from UTC to tz's standard time.
At this point, if
z.n - z.o = x.n [5]
we have an equivalent time, and are almost done. The insecurity here is
at the start of daylight time. Picture US Eastern for concreteness. The wall
time jumps from 1:59 to 3:00, and wall hours of the form 2:MM don't make good
sense then. The docs ask that an Eastern tzinfo class consider such a time to
be EDT (because it's "after 2"), which is a redundant spelling of 1:MM EST
on the day DST starts. We want to return the 1:MM EST spelling because that's
the only spelling that makes sense on the local wall clock.
In fact, if [5] holds at this point, we do have the standard-time spelling,
but that takes a bit of proof. We first prove a stronger result. What's the
difference between the LHS and RHS of [5]? Let
diff = x.n - (z.n - z.o) [6]
Now
z.n = by [4]
(y + y.s).n = by #5
y.n + y.s = since y.n = x.n
x.n + y.s = since z and y are have the same tzinfo member,
y.s = z.s by #2
x.n + z.s
Plugging that back into [6] gives
diff =
x.n - ((x.n + z.s) - z.o) = expanding
x.n - x.n - z.s + z.o = cancelling
- z.s + z.o = by #2
z.d
So diff = z.d.
If [5] is true now, diff = 0, so z.d = 0 too, and we have the standard-time
spelling we wanted in the endcase described above. We're done. Contrarily,
if z.d = 0, then we have a UTC equivalent, and are also done.
If [5] is not true now, diff = z.d != 0, and z.d is the offset we need to
add to z (in effect, z is in tz's standard time, and we need to shift the
local clock into tz's daylight time).
Let
z' = z + z.d = z + diff [7]
and we can again ask whether
z'.n - z'.o = x.n [8]
If so, we're done. If not, the tzinfo class is insane, according to the
assumptions we've made. This also requires a bit of proof. As before, let's
compute the difference between the LHS and RHS of [8] (and skipping some of
the justifications for the kinds of substitutions we've done several times
already):
diff' = x.n - (z'.n - z'.o) = replacing z'.n via [7]
x.n - (z.n + diff - z'.o) = replacing diff via [6]
x.n - (z.n + x.n - (z.n - z.o) - z'.o) =
x.n - z.n - x.n + z.n - z.o + z'.o = cancel x.n
- z.n + z.n - z.o + z'.o = cancel z.n
- z.o + z'.o = #1 twice
-z.s - z.d + z'.s + z'.d = z and z' have same tzinfo
z'.d - z.d
So z' is UTC-equivalent to x iff z'.d = z.d at this point. If they are equal,
we've found the UTC-equivalent so are done. In fact, we stop with [7] and
return z', not bothering to compute z'.d.
How could z.d and z'd differ? z' = z + z.d [7], so merely moving z' by
a dst() offset, and starting *from* a time already in DST (we know z.d != 0),
would have to change the result dst() returns: we start in DST, and moving
a little further into it takes us out of DST.
There isn't a sane case where this can happen. The closest it gets is at
the end of DST, where there's an hour in UTC with no spelling in a hybrid
tzinfo class. In US Eastern, that's 5:MM UTC = 0:MM EST = 1:MM EDT. During
that hour, on an Eastern clock 1:MM is taken as being in standard time (6:MM
UTC) because the docs insist on that, but 0:MM is taken as being in daylight
time (4:MM UTC). There is no local time mapping to 5:MM UTC. The local
clock jumps from 1:59 back to 1:00 again, and repeats the 1:MM hour in
standard time. Since that's what the local clock *does*, we want to map both
UTC hours 5:MM and 6:MM to 1:MM Eastern. The result is ambiguous
in local time, but so it goes -- it's the way the local clock works.
When x = 5:MM UTC is the input to this algorithm, x.o=0, y.o=-5 and y.d=0,
so z=0:MM. z.d=60 (minutes) then, so [5] doesn't hold and we keep going.
z' = z + z.d = 1:MM then, and z'.d=0, and z'.d - z.d = -60 != 0 so [8]
(correctly) concludes that z' is not UTC-equivalent to x.
Because we know z.d said z was in daylight time (else [5] would have held and
we would have stopped then), and we know z.d != z'.d (else [8] would have held
and we have stopped then), and there are only 2 possible values dst() can
return in Eastern, it follows that z'.d must be 0 (which it is in the example,
but the reasoning doesn't depend on the example -- it depends on there being
two possible dst() outcomes, one zero and the other non-zero). Therefore
z' must be in standard time, and is the spelling we want in this case.
Note again that z' is not UTC-equivalent as far as the hybrid tzinfo class is
concerned (because it takes z' as being in standard time rather than the
daylight time we intend here), but returning it gives the real-life "local
clock repeats an hour" behavior when mapping the "unspellable" UTC hour into
tz.
When the input is 6:MM, z=1:MM and z.d=0, and we stop at once, again with
the 1:MM standard time spelling we want.
So how can this break? One of the assumptions must be violated. Two
possibilities:
1) [2] effectively says that y.s is invariant across all y belong to a given
time zone. This isn't true if, for political reasons or continental drift,
a region decides to change its base offset from UTC.
2) There may be versions of "double daylight" time where the tail end of
the analysis gives up a step too early. I haven't thought about that
enough to say.
In any case, it's clear that the default fromutc() is strong enough to handle
"almost all" time zones: so long as the standard offset is invariant, it
doesn't matter if daylight time transition points change from year to year, or
if daylight time is skipped in some years; it doesn't matter how large or
small dst() may get within its bounds; and it doesn't even matter if some
perverse time zone returns a negative dst()). So a breaking case must be
pretty bizarre, and a tzinfo subclass can override fromutc() if it is.
"""
#brython does not have a _datetime, so lets comment this out for now.
#try:
# from _datetime import *
#except ImportError:
# pass
#else:
# # Clean up unused names
# del (_DAYNAMES, _DAYS_BEFORE_MONTH, _DAYS_IN_MONTH,
# _DI100Y, _DI400Y, _DI4Y, _MAXORDINAL, _MONTHNAMES,
# _build_struct_time, _call_tzinfo_method, _check_date_fields,
# _check_time_fields, _check_tzinfo_arg, _check_tzname,
# _check_utc_offset, _cmp, _cmperror, _date_class, _days_before_month,
# _days_before_year, _days_in_month, _format_time, _is_leap,
# _isoweek1monday, _math, _ord2ymd, _time, _time_class, _tzinfo_class,
# _wrap_strftime, _ymd2ord)
# # XXX Since import * above excludes names that start with _,
# # docstring does not get overwritten. In the future, it may be
# # appropriate to maintain a single module level docstring and
# # remove the following line.
# #from _datetime import __doc__
|
agpl-3.0
|
[
624,
714,
7564,
1434,
15,
521,
436,
4048,
2943,
14,
199,
199,
9295,
1455,
921,
1544,
14,
5653,
65,
14,
1308,
15,
521,
13,
13325,
15,
8421,
15,
3903,
13,
1073,
14,
1360,
367,
199,
521,
5718,
436,
22782,
666,
5274,
14,
199,
624,
199,
199,
646,
900,
465,
485,
521,
199,
646,
3473,
465,
485,
3442,
199,
199,
318,
485,
5730,
8,
88,
12,
612,
304,
272,
372,
378,
340,
671,
508,
612,
587,
413,
340,
671,
690,
612,
587,
446,
17,
199,
199,
4896,
19216,
275,
413,
199,
4283,
19216,
275,
221,
5008,
199,
63,
4283,
3731,
13384,
275,
28046,
1165,
1427,
327,
1434,
14,
988,
14,
475,
17460,
342,
199,
199,
3,
20511,
3423,
12,
26266,
687,
2018,
1159,
28939,
15,
2888,
15,
36,
2335,
14,
647,
12,
1314,
199,
3,
2597,
15194,
314,
1453,
29096,
269,
5653,
11234,
315,
23442,
590,
9243,
315,
199,
3,
3865,
28820,
14,
221,
18029,
4646,
26,
221,
577,
2335,
14,
647,
4882,
17474,
20527,
413,
402,
5361,
378,
5382,
199,
3,
1329,
413,
14,
221,
710,
1233,
2348,
4882,
17474,
20527,
413,
402,
5361,
413,
5382,
1329,
413,
14,
221,
961,
365,
199,
3,
370,
1336,
314,
5492,
402,
314,
298,
496,
274,
80,
764,
29096,
269,
5653,
2,
11234,
315,
577,
1192,
1917,
23751,
199,
3,
436,
799,
316,
1753,
1159,
298,
3630,
12944,
8825,
19821,
1298,
401,
2382,
652,
1159,
314,
1300,
11234,
199,
3,
367,
1006,
28319,
1298,
14,
221,
1666,
314,
6719,
367,
18036,
367,
13806,
3382,
199,
3,
557,
274,
80,
764,
29096,
269,
5653,
24943,
83,
436,
5002,
1163,
11234,
10460,
14,
199,
199,
63,
25683,
63,
568,
63,
16413,
275,
359,
403,
12,
7105,
12,
7294,
12,
7105,
12,
4233,
12,
7105,
12,
4233,
12,
7105,
12,
7105,
12,
4233,
12,
7105,
12,
4233,
12,
7105,
61,
199,
199,
63,
25683,
63,
31481,
63,
16413,
275,
359,
403,
61,
199,
20666,
275,
378,
199,
509,
8134,
315,
485,
25683,
63,
568,
63,
16413,
59,
17,
10688,
272,
485,
25683,
63,
31481,
63,
16413,
14,
740,
8,
20666,
9,
272,
31093,
847,
8134,
199,
2264,
31093,
12,
8134,
199,
199,
318,
485,
374,
63,
28764,
8,
3403,
304,
272,
298,
3403,
1035,
413,
340,
29487,
5361,
12,
587,
378,
2122,
272,
372,
5361,
450,
841,
508,
378,
436,
334,
3403,
450,
2948,
1137,
378,
503,
5361,
450,
8290,
508,
378,
9,
199,
199,
318,
485,
4899,
63,
5182,
63,
3403,
8,
3403,
304,
272,
298,
3403,
1035,
1329,
402,
7609,
2544,
17474,
20527,
413,
270,
402,
5361,
2122,
272,
612,
275,
5361,
446,
413,
272,
372,
612,
10,
12664,
435,
612,
501,
20,
446,
612,
501,
1960,
435,
612,
501,
5303,
199,
199,
318,
485,
4899,
63,
262,
63,
4482,
8,
3403,
12,
5794,
304,
272,
298,
3403,
12,
5794,
1035,
1329,
402,
7609,
315,
626,
5794,
315,
626,
5361,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
5794,
272,
340,
5794,
508,
499,
436,
485,
374,
63,
28764,
8,
3403,
304,
267,
372,
7349,
272,
372,
485,
25683,
63,
568,
63,
16413,
59,
4482,
61,
199,
199,
318,
485,
4899,
63,
5182,
63,
4482,
8,
3403,
12,
5794,
304,
272,
298,
3403,
12,
5794,
1035,
1329,
402,
7609,
315,
5361,
22627,
1642,
5382,
402,
5794,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
283,
4482,
1471,
506,
315,
413,
703,
713,
7,
272,
372,
485,
25683,
63,
31481,
63,
16413,
59,
4482,
61,
435,
334,
4482,
690,
499,
436,
485,
374,
63,
28764,
8,
3403,
430,
199,
199,
318,
485,
89,
1064,
18,
2181,
8,
3403,
12,
5794,
12,
5382,
304,
272,
298,
3403,
12,
5794,
12,
5382,
1035,
24943,
12,
11201,
316,
17163,
13,
19825,
13,
4183,
465,
5382,
413,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
283,
4482,
1471,
506,
315,
413,
703,
713,
7,
272,
8134,
275,
485,
4899,
63,
262,
63,
4482,
8,
3403,
12,
5794,
9,
272,
702,
413,
2695,
5382,
2695,
8134,
12,
661,
2977,
1471,
506,
315,
413,
703,
5,
68,
7,
450,
8134,
9,
272,
372,
6110,
4899,
63,
5182,
63,
3403,
8,
3403,
9,
435,
288,
485,
4899,
63,
5182,
63,
4482,
8,
3403,
12,
5794,
9,
435,
288,
5382,
9,
199,
199,
63,
1914,
5303,
57,
275,
485,
4899,
63,
5182,
63,
3403,
8,
8854,
9,
259,
327,
1329,
402,
7609,
315,
8290,
17399,
199,
63,
1914,
1960,
57,
275,
485,
4899,
63,
5182,
63,
3403,
8,
4893,
9,
259,
327,
259,
298,
259,
298,
257,
298,
257,
298,
2948,
257,
298,
199,
63,
1914,
20,
57,
257,
275,
485,
4899,
63,
5182,
63,
3403,
8,
21,
9,
420,
327,
259,
298,
259,
298,
257,
298,
257,
298,
257,
841,
257,
298,
199,
199,
3,
437,
841,
13,
3403,
8643,
965,
376,
2402,
29487,
5382,
1806,
4052,
781,
5121,
664,
687,
13541,
316,
199,
3,
10451,
841,
2849,
17399,
14,
199,
479,
485,
1914,
20,
57,
508,
841,
627,
28046,
435,
413,
199,
199,
3,
20046,
590,
12,
282,
8290,
13,
3403,
8643,
965,
376,
2402,
29487,
5382,
1806,
4052,
781,
5121,
664,
687,
199,
3,
13541,
316,
10451,
841,
2948,
13,
3403,
19001,
14,
199,
479,
485,
1914,
5303,
57,
508,
841,
627,
485,
1914,
1960,
57,
435,
413,
199,
199,
3,
593,
2566,
40,
12,
282,
2948,
13,
3403,
8643,
965,
1373,
27392,
29487,
5382,
2419,
781,
5121,
664,
687,
199,
3,
13541,
316,
10451,
5661,
841,
13,
3403,
19001,
14,
199,
479,
485,
1914,
1960,
57,
508,
5661,
627,
485,
1914,
20,
57,
446,
413,
199,
199,
318,
485,
2181,
18,
89,
1064,
8,
78,
304,
272,
298,
17460,
1035,
334,
3403,
12,
5794,
12,
5382,
395,
11201,
316,
17163,
13,
19825,
13,
4183,
465,
5382,
413,
2122,
339,
327,
302,
365,
282,
413,
13,
6788,
1478,
12,
6617,
737,
413,
13,
19825,
13,
17,
14,
221,
710,
3851,
402,
29487,
17399,
272,
327,
28908,
8840,
4036,
8290,
17399,
14,
221,
710,
5678,
10054,
365,
370,
2342,
314,
272,
327,
18284,
8290,
13,
3403,
8424,
737,
503,
2544,
302,
12,
2066,
1736,
543,
314,
3268,
272,
327,
687,
626,
8424,
370,
302,
14,
221,
491,
16839,
365,
8298,
15158,
21462
] |
[
714,
7564,
1434,
15,
521,
436,
4048,
2943,
14,
199,
199,
9295,
1455,
921,
1544,
14,
5653,
65,
14,
1308,
15,
521,
13,
13325,
15,
8421,
15,
3903,
13,
1073,
14,
1360,
367,
199,
521,
5718,
436,
22782,
666,
5274,
14,
199,
624,
199,
199,
646,
900,
465,
485,
521,
199,
646,
3473,
465,
485,
3442,
199,
199,
318,
485,
5730,
8,
88,
12,
612,
304,
272,
372,
378,
340,
671,
508,
612,
587,
413,
340,
671,
690,
612,
587,
446,
17,
199,
199,
4896,
19216,
275,
413,
199,
4283,
19216,
275,
221,
5008,
199,
63,
4283,
3731,
13384,
275,
28046,
1165,
1427,
327,
1434,
14,
988,
14,
475,
17460,
342,
199,
199,
3,
20511,
3423,
12,
26266,
687,
2018,
1159,
28939,
15,
2888,
15,
36,
2335,
14,
647,
12,
1314,
199,
3,
2597,
15194,
314,
1453,
29096,
269,
5653,
11234,
315,
23442,
590,
9243,
315,
199,
3,
3865,
28820,
14,
221,
18029,
4646,
26,
221,
577,
2335,
14,
647,
4882,
17474,
20527,
413,
402,
5361,
378,
5382,
199,
3,
1329,
413,
14,
221,
710,
1233,
2348,
4882,
17474,
20527,
413,
402,
5361,
413,
5382,
1329,
413,
14,
221,
961,
365,
199,
3,
370,
1336,
314,
5492,
402,
314,
298,
496,
274,
80,
764,
29096,
269,
5653,
2,
11234,
315,
577,
1192,
1917,
23751,
199,
3,
436,
799,
316,
1753,
1159,
298,
3630,
12944,
8825,
19821,
1298,
401,
2382,
652,
1159,
314,
1300,
11234,
199,
3,
367,
1006,
28319,
1298,
14,
221,
1666,
314,
6719,
367,
18036,
367,
13806,
3382,
199,
3,
557,
274,
80,
764,
29096,
269,
5653,
24943,
83,
436,
5002,
1163,
11234,
10460,
14,
199,
199,
63,
25683,
63,
568,
63,
16413,
275,
359,
403,
12,
7105,
12,
7294,
12,
7105,
12,
4233,
12,
7105,
12,
4233,
12,
7105,
12,
7105,
12,
4233,
12,
7105,
12,
4233,
12,
7105,
61,
199,
199,
63,
25683,
63,
31481,
63,
16413,
275,
359,
403,
61,
199,
20666,
275,
378,
199,
509,
8134,
315,
485,
25683,
63,
568,
63,
16413,
59,
17,
10688,
272,
485,
25683,
63,
31481,
63,
16413,
14,
740,
8,
20666,
9,
272,
31093,
847,
8134,
199,
2264,
31093,
12,
8134,
199,
199,
318,
485,
374,
63,
28764,
8,
3403,
304,
272,
298,
3403,
1035,
413,
340,
29487,
5361,
12,
587,
378,
2122,
272,
372,
5361,
450,
841,
508,
378,
436,
334,
3403,
450,
2948,
1137,
378,
503,
5361,
450,
8290,
508,
378,
9,
199,
199,
318,
485,
4899,
63,
5182,
63,
3403,
8,
3403,
304,
272,
298,
3403,
1035,
1329,
402,
7609,
2544,
17474,
20527,
413,
270,
402,
5361,
2122,
272,
612,
275,
5361,
446,
413,
272,
372,
612,
10,
12664,
435,
612,
501,
20,
446,
612,
501,
1960,
435,
612,
501,
5303,
199,
199,
318,
485,
4899,
63,
262,
63,
4482,
8,
3403,
12,
5794,
304,
272,
298,
3403,
12,
5794,
1035,
1329,
402,
7609,
315,
626,
5794,
315,
626,
5361,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
5794,
272,
340,
5794,
508,
499,
436,
485,
374,
63,
28764,
8,
3403,
304,
267,
372,
7349,
272,
372,
485,
25683,
63,
568,
63,
16413,
59,
4482,
61,
199,
199,
318,
485,
4899,
63,
5182,
63,
4482,
8,
3403,
12,
5794,
304,
272,
298,
3403,
12,
5794,
1035,
1329,
402,
7609,
315,
5361,
22627,
1642,
5382,
402,
5794,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
283,
4482,
1471,
506,
315,
413,
703,
713,
7,
272,
372,
485,
25683,
63,
31481,
63,
16413,
59,
4482,
61,
435,
334,
4482,
690,
499,
436,
485,
374,
63,
28764,
8,
3403,
430,
199,
199,
318,
485,
89,
1064,
18,
2181,
8,
3403,
12,
5794,
12,
5382,
304,
272,
298,
3403,
12,
5794,
12,
5382,
1035,
24943,
12,
11201,
316,
17163,
13,
19825,
13,
4183,
465,
5382,
413,
2122,
272,
702,
413,
2695,
5794,
2695,
3144,
12,
283,
4482,
1471,
506,
315,
413,
703,
713,
7,
272,
8134,
275,
485,
4899,
63,
262,
63,
4482,
8,
3403,
12,
5794,
9,
272,
702,
413,
2695,
5382,
2695,
8134,
12,
661,
2977,
1471,
506,
315,
413,
703,
5,
68,
7,
450,
8134,
9,
272,
372,
6110,
4899,
63,
5182,
63,
3403,
8,
3403,
9,
435,
288,
485,
4899,
63,
5182,
63,
4482,
8,
3403,
12,
5794,
9,
435,
288,
5382,
9,
199,
199,
63,
1914,
5303,
57,
275,
485,
4899,
63,
5182,
63,
3403,
8,
8854,
9,
259,
327,
1329,
402,
7609,
315,
8290,
17399,
199,
63,
1914,
1960,
57,
275,
485,
4899,
63,
5182,
63,
3403,
8,
4893,
9,
259,
327,
259,
298,
259,
298,
257,
298,
257,
298,
2948,
257,
298,
199,
63,
1914,
20,
57,
257,
275,
485,
4899,
63,
5182,
63,
3403,
8,
21,
9,
420,
327,
259,
298,
259,
298,
257,
298,
257,
298,
257,
841,
257,
298,
199,
199,
3,
437,
841,
13,
3403,
8643,
965,
376,
2402,
29487,
5382,
1806,
4052,
781,
5121,
664,
687,
13541,
316,
199,
3,
10451,
841,
2849,
17399,
14,
199,
479,
485,
1914,
20,
57,
508,
841,
627,
28046,
435,
413,
199,
199,
3,
20046,
590,
12,
282,
8290,
13,
3403,
8643,
965,
376,
2402,
29487,
5382,
1806,
4052,
781,
5121,
664,
687,
199,
3,
13541,
316,
10451,
841,
2948,
13,
3403,
19001,
14,
199,
479,
485,
1914,
5303,
57,
508,
841,
627,
485,
1914,
1960,
57,
435,
413,
199,
199,
3,
593,
2566,
40,
12,
282,
2948,
13,
3403,
8643,
965,
1373,
27392,
29487,
5382,
2419,
781,
5121,
664,
687,
199,
3,
13541,
316,
10451,
5661,
841,
13,
3403,
19001,
14,
199,
479,
485,
1914,
1960,
57,
508,
5661,
627,
485,
1914,
20,
57,
446,
413,
199,
199,
318,
485,
2181,
18,
89,
1064,
8,
78,
304,
272,
298,
17460,
1035,
334,
3403,
12,
5794,
12,
5382,
395,
11201,
316,
17163,
13,
19825,
13,
4183,
465,
5382,
413,
2122,
339,
327,
302,
365,
282,
413,
13,
6788,
1478,
12,
6617,
737,
413,
13,
19825,
13,
17,
14,
221,
710,
3851,
402,
29487,
17399,
272,
327,
28908,
8840,
4036,
8290,
17399,
14,
221,
710,
5678,
10054,
365,
370,
2342,
314,
272,
327,
18284,
8290,
13,
3403,
8424,
737,
503,
2544,
302,
12,
2066,
1736,
543,
314,
3268,
272,
327,
687,
626,
8424,
370,
302,
14,
221,
491,
16839,
365,
8298,
15158,
21462,
0
] |
[
1,
1,
1,
1,
1,
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
python3-alpha/python3-src/Lib/gzip.py
|
47
|
21968
|
"""Functions that read and write gzipped files.
The user of the file doesn't have to worry about the compression,
but random access is not allowed."""
# based on Andrew Kuchling's minigzip.py distributed with the zlib module
import struct, sys, time, os
import zlib
import builtins
import io
__all__ = ["GzipFile", "open", "compress", "decompress"]
FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16
READ, WRITE = 1, 2
def U32(i):
"""Return i as an unsigned integer, assuming it fits in 32 bits.
If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
"""
if i < 0:
i += 1 << 32
return i
def LOWU32(i):
"""Return the low-order 32 bits, as a non-negative int"""
return i & 0xFFFFFFFF
def write32u(output, value):
# The L format writes the bit pattern correctly whether signed
# or unsigned.
output.write(struct.pack("<L", value))
def read32(input):
return struct.unpack("<I", input.read(4))[0]
def open(filename, mode="rb", compresslevel=9):
"""Shorthand for GzipFile(filename, mode, compresslevel).
The filename argument is required; mode defaults to 'rb'
and compresslevel defaults to 9.
"""
return GzipFile(filename, mode, compresslevel)
class _PaddedFile:
"""Minimal read-only file object that prepends a string to the contents
of an actual file. Shouldn't be used outside of gzip.py, as it lacks
essential functionality."""
def __init__(self, f, prepend=b''):
self._buffer = prepend
self._length = len(prepend)
self.file = f
self._read = 0
def read(self, size):
if self._read is None:
return self.file.read(size)
if self._read + size <= self._length:
read = self._read
self._read += size
return self._buffer[read:self._read]
else:
read = self._read
self._read = None
return self._buffer[read:] + \
self.file.read(size-self._length+read)
def prepend(self, prepend=b'', readprevious=False):
if self._read is None:
self._buffer = prepend
elif readprevious and len(prepend) <= self._read:
self._read -= len(prepend)
return
else:
self._buffer = self._buffer[read:] + prepend
self._length = len(self._buffer)
self._read = 0
def unused(self):
if self._read is None:
return b''
return self._buffer[self._read:]
def seek(self, offset, whence=0):
# This is only ever called with offset=whence=0
if whence == 1 and self._read is not None:
if 0 <= offset + self._read <= self._length:
self._read += offset
return
else:
offset += self._length - self._read
self._read = None
self._buffer = None
return self.file.seek(offset, whence)
def __getattr__(self, name):
return getattr(self.file, name)
class GzipFile(io.BufferedIOBase):
"""The GzipFile class simulates most of the methods of a file object with
the exception of the readinto() and truncate() methods.
"""
myfileobj = None
max_read_chunk = 10 * 1024 * 1024 # 10Mb
def __init__(self, filename=None, mode=None,
compresslevel=9, fileobj=None, mtime=None):
"""Constructor for the GzipFile class.
At least one of fileobj and filename must be given a
non-trivial value.
The new class instance is based on fileobj, which can be a regular
file, a StringIO object, or any other object which simulates a file.
It defaults to None, in which case filename is opened to provide
a file object.
When fileobj is not None, the filename argument is only used to be
included in the gzip file header, which may includes the original
filename of the uncompressed file. It defaults to the filename of
fileobj, if discernible; otherwise, it defaults to the empty string,
and in this case the original filename is not included in the header.
The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
depending on whether the file will be read or written. The default
is the mode of fileobj if discernible; otherwise, the default is 'rb'.
Be aware that only the 'rb', 'ab', and 'wb' values should be used
for cross-platform portability.
The compresslevel argument is an integer from 1 to 9 controlling the
level of compression; 1 is fastest and produces the least compression,
and 9 is slowest and produces the most compression. The default is 9.
The mtime argument is an optional numeric timestamp to be written
to the stream when compressing. All gzip compressed streams
are required to contain a timestamp. If omitted or None, the
current time is used. This module ignores the timestamp when
decompressing; however, some programs, such as gunzip, make use
of it. The format of the timestamp is the same as that of the
return value of time.time() and of the st_mtime member of the
object returned by os.stat().
"""
# guarantee the file is opened in binary mode on platforms
# that care about that sort of thing
if mode and 'b' not in mode:
mode += 'b'
if fileobj is None:
fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
if filename is None:
if hasattr(fileobj, 'name'): filename = fileobj.name
else: filename = ''
if mode is None:
if hasattr(fileobj, 'mode'): mode = fileobj.mode
else: mode = 'rb'
if mode[0:1] == 'r':
self.mode = READ
# Set flag indicating start of a new member
self._new_member = True
# Buffer data read from gzip file. extrastart is offset in
# stream where buffer starts. extrasize is number of
# bytes remaining in buffer from current stream position.
self.extrabuf = b""
self.extrasize = 0
self.extrastart = 0
self.name = filename
# Starts small, scales exponentially
self.min_readsize = 100
fileobj = _PaddedFile(fileobj)
elif mode[0:1] == 'w' or mode[0:1] == 'a':
self.mode = WRITE
self._init_write(filename)
self.compress = zlib.compressobj(compresslevel,
zlib.DEFLATED,
-zlib.MAX_WBITS,
zlib.DEF_MEM_LEVEL,
0)
else:
raise IOError("Mode " + mode + " not supported")
self.fileobj = fileobj
self.offset = 0
self.mtime = mtime
if self.mode == WRITE:
self._write_gzip_header()
@property
def filename(self):
import warnings
warnings.warn("use the name attribute", DeprecationWarning, 2)
if self.mode == WRITE and self.name[-3:] != ".gz":
return self.name + ".gz"
return self.name
def __repr__(self):
fileobj = self.fileobj
if isinstance(fileobj, _PaddedFile):
fileobj = fileobj.file
s = repr(fileobj)
return '<gzip ' + s[1:-1] + ' ' + hex(id(self)) + '>'
def _check_closed(self):
"""Raises a ValueError if the underlying file object has been closed.
"""
if self.closed:
raise ValueError('I/O operation on closed file.')
def _init_write(self, filename):
self.name = filename
self.crc = zlib.crc32(b"") & 0xffffffff
self.size = 0
self.writebuf = []
self.bufsize = 0
def _write_gzip_header(self):
self.fileobj.write(b'\037\213') # magic header
self.fileobj.write(b'\010') # compression method
try:
# RFC 1952 requires the FNAME field to be Latin-1. Do not
# include filenames that cannot be represented that way.
fname = os.path.basename(self.name)
fname = fname.encode('latin-1')
if fname.endswith(b'.gz'):
fname = fname[:-3]
except UnicodeEncodeError:
fname = b''
flags = 0
if fname:
flags = FNAME
self.fileobj.write(chr(flags).encode('latin-1'))
mtime = self.mtime
if mtime is None:
mtime = time.time()
write32u(self.fileobj, int(mtime))
self.fileobj.write(b'\002')
self.fileobj.write(b'\377')
if fname:
self.fileobj.write(fname + b'\000')
def _init_read(self):
self.crc = zlib.crc32(b"") & 0xffffffff
self.size = 0
def _read_gzip_header(self):
magic = self.fileobj.read(2)
if magic == b'':
raise EOFError("Reached EOF")
if magic != b'\037\213':
raise IOError('Not a gzipped file')
method = ord( self.fileobj.read(1) )
if method != 8:
raise IOError('Unknown compression method')
flag = ord( self.fileobj.read(1) )
self.mtime = read32(self.fileobj)
# extraflag = self.fileobj.read(1)
# os = self.fileobj.read(1)
self.fileobj.read(2)
if flag & FEXTRA:
# Read & discard the extra field, if present
xlen = ord(self.fileobj.read(1))
xlen = xlen + 256*ord(self.fileobj.read(1))
self.fileobj.read(xlen)
if flag & FNAME:
# Read and discard a null-terminated string containing the filename
while True:
s = self.fileobj.read(1)
if not s or s==b'\000':
break
if flag & FCOMMENT:
# Read and discard a null-terminated string containing a comment
while True:
s = self.fileobj.read(1)
if not s or s==b'\000':
break
if flag & FHCRC:
self.fileobj.read(2) # Read & discard the 16-bit header CRC
unused = self.fileobj.unused()
if unused:
uncompress = self.decompress.decompress(unused)
self._add_read_data(uncompress)
def write(self,data):
self._check_closed()
if self.mode != WRITE:
import errno
raise IOError(errno.EBADF, "write() on read-only GzipFile object")
if self.fileobj is None:
raise ValueError("write() on closed GzipFile object")
# Convert data type if called by io.BufferedWriter.
if isinstance(data, memoryview):
data = data.tobytes()
if len(data) > 0:
self.size = self.size + len(data)
self.crc = zlib.crc32(data, self.crc) & 0xffffffff
self.fileobj.write( self.compress.compress(data) )
self.offset += len(data)
return len(data)
def read(self, size=-1):
self._check_closed()
if self.mode != READ:
import errno
raise IOError(errno.EBADF, "read() on write-only GzipFile object")
if self.extrasize <= 0 and self.fileobj is None:
return b''
readsize = 1024
if size < 0: # get the whole thing
try:
while True:
self._read(readsize)
readsize = min(self.max_read_chunk, readsize * 2)
except EOFError:
size = self.extrasize
else: # just get some more of it
try:
while size > self.extrasize:
self._read(readsize)
readsize = min(self.max_read_chunk, readsize * 2)
except EOFError:
if size > self.extrasize:
size = self.extrasize
offset = self.offset - self.extrastart
chunk = self.extrabuf[offset: offset + size]
self.extrasize = self.extrasize - size
self.offset += size
return chunk
def peek(self, n):
if self.mode != READ:
import errno
raise IOError(errno.EBADF, "peek() on write-only GzipFile object")
# Do not return ridiculously small buffers, for one common idiom
# is to call peek(1) and expect more bytes in return.
if n < 100:
n = 100
if self.extrasize == 0:
if self.fileobj is None:
return b''
try:
# 1024 is the same buffering heuristic used in read()
self._read(max(n, 1024))
except EOFError:
pass
offset = self.offset - self.extrastart
remaining = self.extrasize
assert remaining == len(self.extrabuf) - offset
return self.extrabuf[offset:offset + n]
def _unread(self, buf):
self.extrasize = len(buf) + self.extrasize
self.offset -= len(buf)
def _read(self, size=1024):
if self.fileobj is None:
raise EOFError("Reached EOF")
if self._new_member:
# If the _new_member flag is set, we have to
# jump to the next member, if there is one.
self._init_read()
self._read_gzip_header()
self.decompress = zlib.decompressobj(-zlib.MAX_WBITS)
self._new_member = False
# Read a chunk of data from the file
buf = self.fileobj.read(size)
# If the EOF has been reached, flush the decompression object
# and mark this object as finished.
if buf == b"":
uncompress = self.decompress.flush()
# Prepend the already read bytes to the fileobj to they can be
# seen by _read_eof()
self.fileobj.prepend(self.decompress.unused_data, True)
self._read_eof()
self._add_read_data( uncompress )
raise EOFError('Reached EOF')
uncompress = self.decompress.decompress(buf)
self._add_read_data( uncompress )
if self.decompress.unused_data != b"":
# Ending case: we've come to the end of a member in the file,
# so seek back to the start of the unused data, finish up
# this member, and read a new gzip header.
# Prepend the already read bytes to the fileobj to they can be
# seen by _read_eof() and _read_gzip_header()
self.fileobj.prepend(self.decompress.unused_data, True)
# Check the CRC and file size, and set the flag so we read
# a new member on the next call
self._read_eof()
self._new_member = True
def _add_read_data(self, data):
self.crc = zlib.crc32(data, self.crc) & 0xffffffff
offset = self.offset - self.extrastart
self.extrabuf = self.extrabuf[offset:] + data
self.extrasize = self.extrasize + len(data)
self.extrastart = self.offset
self.size = self.size + len(data)
def _read_eof(self):
# We've read to the end of the file
# We check the that the computed CRC and size of the
# uncompressed data matches the stored values. Note that the size
# stored is the true file size mod 2**32.
crc32 = read32(self.fileobj)
isize = read32(self.fileobj) # may exceed 2GB
if crc32 != self.crc:
raise IOError("CRC check failed %s != %s" % (hex(crc32),
hex(self.crc)))
elif isize != (self.size & 0xffffffff):
raise IOError("Incorrect length of data produced")
# Gzip files can be padded with zeroes and still have archives.
# Consume all zero bytes and set the file position to the first
# non-zero byte. See http://www.gzip.org/#faq8
c = b"\x00"
while c == b"\x00":
c = self.fileobj.read(1)
if c:
self.fileobj.prepend(c, True)
@property
def closed(self):
return self.fileobj is None
def close(self):
if self.fileobj is None:
return
if self.mode == WRITE:
self.fileobj.write(self.compress.flush())
write32u(self.fileobj, self.crc)
# self.size may exceed 2GB, or even 4GB
write32u(self.fileobj, self.size & 0xffffffff)
self.fileobj = None
elif self.mode == READ:
self.fileobj = None
if self.myfileobj:
self.myfileobj.close()
self.myfileobj = None
def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH):
self._check_closed()
if self.mode == WRITE:
# Ensure the compressor's buffer is flushed
self.fileobj.write(self.compress.flush(zlib_mode))
self.fileobj.flush()
def fileno(self):
"""Invoke the underlying file object's fileno() method.
This will raise AttributeError if the underlying file object
doesn't support fileno().
"""
return self.fileobj.fileno()
def rewind(self):
'''Return the uncompressed stream file position indicator to the
beginning of the file'''
if self.mode != READ:
raise IOError("Can't rewind in write mode")
self.fileobj.seek(0)
self._new_member = True
self.extrabuf = b""
self.extrasize = 0
self.extrastart = 0
self.offset = 0
def readable(self):
return self.mode == READ
def writable(self):
return self.mode == WRITE
def seekable(self):
return True
def seek(self, offset, whence=0):
if whence:
if whence == 1:
offset = self.offset + offset
else:
raise ValueError('Seek from end not supported')
if self.mode == WRITE:
if offset < self.offset:
raise IOError('Negative seek in write mode')
count = offset - self.offset
chunk = bytes(1024)
for i in range(count // 1024):
self.write(chunk)
self.write(bytes(count % 1024))
elif self.mode == READ:
if offset < self.offset:
# for negative seek, rewind and do positive seek
self.rewind()
count = offset - self.offset
for i in range(count // 1024):
self.read(1024)
self.read(count % 1024)
return self.offset
def readline(self, size=-1):
if size < 0:
# Shortcut common case - newline found in buffer.
offset = self.offset - self.extrastart
i = self.extrabuf.find(b'\n', offset) + 1
if i > 0:
self.extrasize -= i - offset
self.offset += i - offset
return self.extrabuf[offset: i]
size = sys.maxsize
readsize = self.min_readsize
else:
readsize = size
bufs = []
while size != 0:
c = self.read(readsize)
i = c.find(b'\n')
# We set i=size to break out of the loop under two
# conditions: 1) there's no newline, and the chunk is
# larger than size, or 2) there is a newline, but the
# resulting line would be longer than 'size'.
if (size <= i) or (i == -1 and len(c) > size):
i = size - 1
if i >= 0 or c == b'':
bufs.append(c[:i + 1]) # Add portion of last chunk
self._unread(c[i + 1:]) # Push back rest of chunk
break
# Append chunk to list, decrease 'size',
bufs.append(c)
size = size - len(c)
readsize = min(size, readsize * 2)
if readsize > self.min_readsize:
self.min_readsize = min(readsize, self.min_readsize * 2, 512)
return b''.join(bufs) # Return resulting line
def compress(data, compresslevel=9):
"""Compress data in one shot and return the compressed string.
Optional argument is the compression level, in range of 1-9.
"""
buf = io.BytesIO()
with GzipFile(fileobj=buf, mode='wb', compresslevel=compresslevel) as f:
f.write(data)
return buf.getvalue()
def decompress(data):
"""Decompress a gzip compressed string in one shot.
Return the decompressed string.
"""
with GzipFile(fileobj=io.BytesIO(data)) as f:
return f.read()
def _test():
# Act like gzip; with -d, act like gunzip.
# The input file is not deleted, however, nor are any other gzip
# options or features supported.
args = sys.argv[1:]
decompress = args and args[0] == "-d"
if decompress:
args = args[1:]
if not args:
args = ["-"]
for arg in args:
if decompress:
if arg == "-":
f = GzipFile(filename="", mode="rb", fileobj=sys.stdin.buffer)
g = sys.stdout.buffer
else:
if arg[-3:] != ".gz":
print("filename doesn't end in .gz:", repr(arg))
continue
f = open(arg, "rb")
g = builtins.open(arg[:-3], "wb")
else:
if arg == "-":
f = sys.stdin.buffer
g = GzipFile(filename="", mode="wb", fileobj=sys.stdout.buffer)
else:
f = builtins.open(arg, "rb")
g = open(arg + ".gz", "wb")
while True:
chunk = f.read(1024)
if not chunk:
break
g.write(chunk)
if g is not sys.stdout:
g.close()
if f is not sys.stdin:
f.close()
if __name__ == '__main__':
_test()
|
apache-2.0
|
[
624,
13967,
626,
1586,
436,
2218,
11756,
1915,
1584,
14,
199,
199,
1918,
922,
402,
314,
570,
3181,
1133,
1172,
370,
30944,
3595,
314,
10291,
12,
199,
7911,
2196,
2879,
365,
440,
4370,
1041,
199,
199,
3,
4079,
641,
6061,
5257,
1804,
2133,
2983,
1159,
1748,
528,
3065,
14,
647,
1854,
543,
314,
12472,
859,
199,
199,
646,
2702,
12,
984,
12,
900,
12,
747,
199,
646,
12472,
199,
646,
12963,
199,
646,
5890,
199,
199,
363,
452,
363,
275,
2097,
29827,
401,
298,
1490,
401,
298,
6447,
401,
298,
14954,
937,
199,
199,
2161,
2472,
12,
481,
40,
29243,
12,
481,
18555,
12,
481,
2339,
12,
481,
10973,
275,
413,
12,
499,
12,
841,
12,
1695,
12,
3193,
199,
199,
5670,
12,
32280,
275,
413,
12,
499,
199,
199,
318,
738,
708,
8,
73,
304,
272,
408,
1767,
284,
465,
376,
7381,
3000,
12,
18002,
652,
20147,
315,
4337,
5821,
14,
272,
982,
652,
1159,
2356,
499,
6487,
1380,
2455,
379,
465,
282,
4337,
13,
2075,
7381,
1109,
12,
372,
282,
1846,
14,
272,
408,
272,
340,
284,
665,
378,
26,
267,
284,
847,
413,
5213,
4337,
272,
372,
284,
199,
199,
318,
21359,
53,
708,
8,
73,
304,
272,
408,
1767,
314,
6465,
13,
1648,
4337,
5821,
12,
465,
282,
2222,
13,
7371,
1109,
624,
272,
372,
284,
1253,
378,
32158,
199,
199,
318,
2218,
708,
85,
8,
1199,
12,
574,
304,
272,
327,
710,
491,
1475,
14511,
314,
4546,
3851,
6657,
3775,
10514,
272,
327,
503,
7381,
14,
272,
1072,
14,
952,
8,
1820,
14,
1389,
6757,
44,
401,
574,
430,
199,
199,
318,
1586,
708,
8,
1210,
304,
272,
372,
2702,
14,
5301,
6757,
41,
401,
1324,
14,
739,
8,
20,
11515,
16,
61,
199,
199,
318,
1551,
8,
1501,
12,
818,
628,
4848,
401,
11029,
1896,
29,
25,
304,
272,
408,
2662,
23999,
367,
598,
3065,
1173,
8,
1501,
12,
818,
12,
11029,
1896,
680,
339,
710,
1788,
1423,
365,
1415,
27,
818,
4243,
370,
283,
4848,
7,
272,
436,
11029,
1896,
4243,
370,
1749,
14,
339,
408,
272,
372,
598,
3065,
1173,
8,
1501,
12,
818,
12,
11029,
1896,
9,
199,
199,
533,
485,
48,
3270,
1173,
26,
272,
408,
4649,
7265,
1586,
13,
2118,
570,
909,
626,
19986,
3198,
282,
1059,
370,
314,
4072,
272,
402,
376,
3503,
570,
14,
7719,
78,
1133,
506,
1202,
9682,
402,
11756,
14,
647,
12,
465,
652,
1127,
5618,
272,
22829,
1009,
9330,
1041,
339,
347,
636,
826,
721,
277,
12,
289,
12,
18213,
29,
66,
7,
735,
267,
291,
423,
2738,
275,
18213,
267,
291,
423,
1267,
275,
822,
8,
20637,
9,
267,
291,
14,
493,
275,
289,
267,
291,
423,
739,
275,
378,
339,
347,
1586,
8,
277,
12,
1568,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
372,
291,
14,
493,
14,
739,
8,
890,
9,
267,
340,
291,
423,
739,
435,
1568,
2695,
291,
423,
1267,
26,
288,
1586,
275,
291,
423,
739,
288,
291,
423,
739,
847,
1568,
288,
372,
291,
423,
2738,
59,
739,
26,
277,
423,
739,
61,
267,
587,
26,
288,
1586,
275,
291,
423,
739,
288,
291,
423,
739,
275,
488,
288,
372,
291,
423,
2738,
59,
739,
2938,
435,
971,
673,
291,
14,
493,
14,
739,
8,
890,
13,
277,
423,
1267,
11,
739,
9,
339,
347,
18213,
8,
277,
12,
18213,
29,
66,
6448,
1586,
6352,
29,
797,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
291,
423,
2738,
275,
18213,
267,
916,
1586,
6352,
436,
822,
8,
20637,
9,
2695,
291,
423,
739,
26,
288,
291,
423,
739,
4862,
822,
8,
20637,
9,
288,
372,
267,
587,
26,
288,
291,
423,
2738,
275,
291,
423,
2738,
59,
739,
2938,
435,
18213,
267,
291,
423,
1267,
275,
822,
8,
277,
423,
2738,
9,
267,
291,
423,
739,
275,
378,
339,
347,
9563,
8,
277,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
372,
330,
891,
267,
372,
291,
423,
2738,
59,
277,
423,
739,
2938,
339,
347,
12005,
8,
277,
12,
3268,
12,
23328,
29,
16,
304,
267,
327,
961,
365,
1454,
14433,
2797,
543,
3268,
29,
2191,
4894,
29,
16,
267,
340,
23328,
508,
413,
436,
291,
423,
739,
365,
440,
488,
26,
288,
340,
378,
2695,
3268,
435,
291,
423,
739,
2695,
291,
423,
1267,
26,
355,
291,
423,
739,
847,
3268,
355,
372,
288,
587,
26,
355,
3268,
847,
291,
423,
1267,
446,
291,
423,
739,
267,
291,
423,
739,
275,
488,
267,
291,
423,
2738,
275,
488,
267,
372,
291,
14,
493,
14,
5507,
8,
2743,
12,
23328,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
14,
493,
12,
536,
9,
421,
199,
533,
598,
3065,
1173,
8,
2308,
14,
23139,
23413,
304,
272,
408,
1918,
598,
3065,
1173,
1021,
4389,
15409,
4750,
402,
314,
3102,
402,
282,
570,
909,
543,
272,
314,
1919,
402,
314,
1586,
9924,
342,
436,
14547,
342,
3102,
14,
339,
408,
339,
3002,
9234,
275,
488,
272,
1390,
63,
739,
63,
4604,
275,
1616,
627,
6619,
627,
6619,
257,
327,
1616,
16789,
339,
347,
636,
826,
721,
277,
12,
1788,
29,
403,
12,
818,
29,
403,
12,
326,
11029,
1896,
29,
25,
12,
11099,
29,
403,
12,
15005,
29,
403,
304,
267,
408,
11447,
367,
314,
598,
3065,
1173,
1021,
14,
398,
2854,
5210,
1373,
402,
11099,
436,
1788,
1471,
506,
1627,
282,
267,
2222,
13,
23844,
574,
14,
398,
710,
892,
1021,
1256,
365,
4079,
641,
11099,
12,
1314,
883,
506,
282,
5578,
267,
570,
12,
282,
5228,
909,
12,
503,
1263,
1163,
909,
1314,
4389,
15409,
282,
570,
14,
267,
2779,
4243,
370,
488,
12,
315,
1314,
1930,
1788,
365,
12123,
370,
5647,
267,
282,
570,
909,
14,
398,
3979,
11099,
365,
440,
488,
12,
314,
1788,
1423,
365,
1454,
1202,
370,
506,
267,
5120,
315,
314,
11756,
570,
1406,
12,
1314,
1443,
6952,
314,
3379,
267,
1788,
402,
314,
25904,
570,
14,
221,
2779,
4243,
370,
314,
1788,
402,
267,
11099,
12,
340,
4339,
27569,
7247,
27,
4257,
12,
652,
4243,
370,
314,
2701,
1059,
12,
267,
436,
315,
642,
1930,
314,
3379,
1788,
365
] |
[
13967,
626,
1586,
436,
2218,
11756,
1915,
1584,
14,
199,
199,
1918,
922,
402,
314,
570,
3181,
1133,
1172,
370,
30944,
3595,
314,
10291,
12,
199,
7911,
2196,
2879,
365,
440,
4370,
1041,
199,
199,
3,
4079,
641,
6061,
5257,
1804,
2133,
2983,
1159,
1748,
528,
3065,
14,
647,
1854,
543,
314,
12472,
859,
199,
199,
646,
2702,
12,
984,
12,
900,
12,
747,
199,
646,
12472,
199,
646,
12963,
199,
646,
5890,
199,
199,
363,
452,
363,
275,
2097,
29827,
401,
298,
1490,
401,
298,
6447,
401,
298,
14954,
937,
199,
199,
2161,
2472,
12,
481,
40,
29243,
12,
481,
18555,
12,
481,
2339,
12,
481,
10973,
275,
413,
12,
499,
12,
841,
12,
1695,
12,
3193,
199,
199,
5670,
12,
32280,
275,
413,
12,
499,
199,
199,
318,
738,
708,
8,
73,
304,
272,
408,
1767,
284,
465,
376,
7381,
3000,
12,
18002,
652,
20147,
315,
4337,
5821,
14,
272,
982,
652,
1159,
2356,
499,
6487,
1380,
2455,
379,
465,
282,
4337,
13,
2075,
7381,
1109,
12,
372,
282,
1846,
14,
272,
408,
272,
340,
284,
665,
378,
26,
267,
284,
847,
413,
5213,
4337,
272,
372,
284,
199,
199,
318,
21359,
53,
708,
8,
73,
304,
272,
408,
1767,
314,
6465,
13,
1648,
4337,
5821,
12,
465,
282,
2222,
13,
7371,
1109,
624,
272,
372,
284,
1253,
378,
32158,
199,
199,
318,
2218,
708,
85,
8,
1199,
12,
574,
304,
272,
327,
710,
491,
1475,
14511,
314,
4546,
3851,
6657,
3775,
10514,
272,
327,
503,
7381,
14,
272,
1072,
14,
952,
8,
1820,
14,
1389,
6757,
44,
401,
574,
430,
199,
199,
318,
1586,
708,
8,
1210,
304,
272,
372,
2702,
14,
5301,
6757,
41,
401,
1324,
14,
739,
8,
20,
11515,
16,
61,
199,
199,
318,
1551,
8,
1501,
12,
818,
628,
4848,
401,
11029,
1896,
29,
25,
304,
272,
408,
2662,
23999,
367,
598,
3065,
1173,
8,
1501,
12,
818,
12,
11029,
1896,
680,
339,
710,
1788,
1423,
365,
1415,
27,
818,
4243,
370,
283,
4848,
7,
272,
436,
11029,
1896,
4243,
370,
1749,
14,
339,
408,
272,
372,
598,
3065,
1173,
8,
1501,
12,
818,
12,
11029,
1896,
9,
199,
199,
533,
485,
48,
3270,
1173,
26,
272,
408,
4649,
7265,
1586,
13,
2118,
570,
909,
626,
19986,
3198,
282,
1059,
370,
314,
4072,
272,
402,
376,
3503,
570,
14,
7719,
78,
1133,
506,
1202,
9682,
402,
11756,
14,
647,
12,
465,
652,
1127,
5618,
272,
22829,
1009,
9330,
1041,
339,
347,
636,
826,
721,
277,
12,
289,
12,
18213,
29,
66,
7,
735,
267,
291,
423,
2738,
275,
18213,
267,
291,
423,
1267,
275,
822,
8,
20637,
9,
267,
291,
14,
493,
275,
289,
267,
291,
423,
739,
275,
378,
339,
347,
1586,
8,
277,
12,
1568,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
372,
291,
14,
493,
14,
739,
8,
890,
9,
267,
340,
291,
423,
739,
435,
1568,
2695,
291,
423,
1267,
26,
288,
1586,
275,
291,
423,
739,
288,
291,
423,
739,
847,
1568,
288,
372,
291,
423,
2738,
59,
739,
26,
277,
423,
739,
61,
267,
587,
26,
288,
1586,
275,
291,
423,
739,
288,
291,
423,
739,
275,
488,
288,
372,
291,
423,
2738,
59,
739,
2938,
435,
971,
673,
291,
14,
493,
14,
739,
8,
890,
13,
277,
423,
1267,
11,
739,
9,
339,
347,
18213,
8,
277,
12,
18213,
29,
66,
6448,
1586,
6352,
29,
797,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
291,
423,
2738,
275,
18213,
267,
916,
1586,
6352,
436,
822,
8,
20637,
9,
2695,
291,
423,
739,
26,
288,
291,
423,
739,
4862,
822,
8,
20637,
9,
288,
372,
267,
587,
26,
288,
291,
423,
2738,
275,
291,
423,
2738,
59,
739,
2938,
435,
18213,
267,
291,
423,
1267,
275,
822,
8,
277,
423,
2738,
9,
267,
291,
423,
739,
275,
378,
339,
347,
9563,
8,
277,
304,
267,
340,
291,
423,
739,
365,
488,
26,
288,
372,
330,
891,
267,
372,
291,
423,
2738,
59,
277,
423,
739,
2938,
339,
347,
12005,
8,
277,
12,
3268,
12,
23328,
29,
16,
304,
267,
327,
961,
365,
1454,
14433,
2797,
543,
3268,
29,
2191,
4894,
29,
16,
267,
340,
23328,
508,
413,
436,
291,
423,
739,
365,
440,
488,
26,
288,
340,
378,
2695,
3268,
435,
291,
423,
739,
2695,
291,
423,
1267,
26,
355,
291,
423,
739,
847,
3268,
355,
372,
288,
587,
26,
355,
3268,
847,
291,
423,
1267,
446,
291,
423,
739,
267,
291,
423,
739,
275,
488,
267,
291,
423,
2738,
275,
488,
267,
372,
291,
14,
493,
14,
5507,
8,
2743,
12,
23328,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
372,
2519,
8,
277,
14,
493,
12,
536,
9,
421,
199,
533,
598,
3065,
1173,
8,
2308,
14,
23139,
23413,
304,
272,
408,
1918,
598,
3065,
1173,
1021,
4389,
15409,
4750,
402,
314,
3102,
402,
282,
570,
909,
543,
272,
314,
1919,
402,
314,
1586,
9924,
342,
436,
14547,
342,
3102,
14,
339,
408,
339,
3002,
9234,
275,
488,
272,
1390,
63,
739,
63,
4604,
275,
1616,
627,
6619,
627,
6619,
257,
327,
1616,
16789,
339,
347,
636,
826,
721,
277,
12,
1788,
29,
403,
12,
818,
29,
403,
12,
326,
11029,
1896,
29,
25,
12,
11099,
29,
403,
12,
15005,
29,
403,
304,
267,
408,
11447,
367,
314,
598,
3065,
1173,
1021,
14,
398,
2854,
5210,
1373,
402,
11099,
436,
1788,
1471,
506,
1627,
282,
267,
2222,
13,
23844,
574,
14,
398,
710,
892,
1021,
1256,
365,
4079,
641,
11099,
12,
1314,
883,
506,
282,
5578,
267,
570,
12,
282,
5228,
909,
12,
503,
1263,
1163,
909,
1314,
4389,
15409,
282,
570,
14,
267,
2779,
4243,
370,
488,
12,
315,
1314,
1930,
1788,
365,
12123,
370,
5647,
267,
282,
570,
909,
14,
398,
3979,
11099,
365,
440,
488,
12,
314,
1788,
1423,
365,
1454,
1202,
370,
506,
267,
5120,
315,
314,
11756,
570,
1406,
12,
1314,
1443,
6952,
314,
3379,
267,
1788,
402,
314,
25904,
570,
14,
221,
2779,
4243,
370,
314,
1788,
402,
267,
11099,
12,
340,
4339,
27569,
7247,
27,
4257,
12,
652,
4243,
370,
314,
2701,
1059,
12,
267,
436,
315,
642,
1930,
314,
3379,
1788,
365,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
franekp/millandict
|
ankidict/thirdparty/cherrypy/wsgiserver/ssl_builtin.py
|
12
|
4032
|
"""A library for integrating Python's builtin ``ssl`` library with CherryPy.
The ssl module must be importable for SSL functionality.
To use this module, set ``CherryPyWSGIServer.ssl_adapter`` to an instance of
``BuiltinSSLAdapter``.
"""
try:
import ssl
except ImportError:
ssl = None
try:
from _pyio import DEFAULT_BUFFER_SIZE
except ImportError:
try:
from io import DEFAULT_BUFFER_SIZE
except ImportError:
DEFAULT_BUFFER_SIZE = -1
import sys
from cherrypy import wsgiserver
class BuiltinSSLAdapter(wsgiserver.SSLAdapter):
"""A wrapper for integrating Python's builtin ssl module with CherryPy."""
certificate = None
"""The filename of the server SSL certificate."""
private_key = None
"""The filename of the server's private key file."""
certificate_chain = None
"""The filename of the certificate chain file."""
"""The ssl.SSLContext that will be used to wrap sockets where available
(on Python > 2.7.9 / 3.3)
"""
context = None
def __init__(self, certificate, private_key, certificate_chain=None):
if ssl is None:
raise ImportError("You must install the ssl module to use HTTPS.")
self.certificate = certificate
self.private_key = private_key
self.certificate_chain = certificate_chain
if hasattr(ssl, 'create_default_context'):
self.context = ssl.create_default_context(
purpose=ssl.Purpose.CLIENT_AUTH,
cafile=certificate_chain
)
self.context.load_cert_chain(certificate, private_key)
def bind(self, sock):
"""Wrap and return the given socket."""
return sock
def wrap(self, sock):
"""Wrap and return the given socket, plus WSGI environ entries."""
try:
if self.context is not None:
s = self.context.wrap_socket(sock,do_handshake_on_connect=True,
server_side=True)
else:
s = ssl.wrap_socket(sock, do_handshake_on_connect=True,
server_side=True, certfile=self.certificate,
keyfile=self.private_key,
ssl_version=ssl.PROTOCOL_SSLv23,
ca_certs=self.certificate_chain)
except ssl.SSLError:
e = sys.exc_info()[1]
if e.errno == ssl.SSL_ERROR_EOF:
# This is almost certainly due to the cherrypy engine
# 'pinging' the socket to assert it's connectable;
# the 'ping' isn't SSL.
return None, {}
elif e.errno == ssl.SSL_ERROR_SSL:
if e.args[1].endswith('http request'):
# The client is speaking HTTP to an HTTPS server.
raise wsgiserver.NoSSLError
elif e.args[1].endswith('unknown protocol'):
# The client is speaking some non-HTTP protocol.
# Drop the conn.
return None, {}
raise
return s, self.get_environ(s)
# TODO: fill this out more with mod ssl env
def get_environ(self, sock):
"""Create WSGI environ entries to be merged into each request."""
cipher = sock.cipher()
ssl_environ = {
"wsgi.url_scheme": "https",
"HTTPS": "on",
'SSL_PROTOCOL': cipher[1],
'SSL_CIPHER': cipher[0]
# SSL_VERSION_INTERFACE string The mod_ssl program version
# SSL_VERSION_LIBRARY string The OpenSSL program version
}
return ssl_environ
if sys.version_info >= (3, 0):
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
return wsgiserver.CP_makefile(sock, mode, bufsize)
else:
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
return wsgiserver.CP_fileobject(sock, mode, bufsize)
|
mit
|
[
624,
33,
3555,
367,
17806,
1958,
2018,
1159,
6762,
1124,
4266,
1040,
3555,
543,
30992,
27794,
14,
199,
199,
1918,
6149,
859,
1471,
506,
492,
461,
367,
7799,
9330,
14,
199,
199,
1378,
675,
642,
859,
12,
663,
1124,
1049,
281,
27794,
55,
28732,
14,
4266,
63,
10394,
1040,
370,
376,
1256,
402,
199,
1040,
12306,
5413,
10200,
4345,
199,
624,
199,
199,
893,
26,
272,
492,
6149,
199,
2590,
3545,
26,
272,
6149,
275,
488,
199,
199,
893,
26,
272,
687,
485,
647,
2308,
492,
6186,
63,
10960,
63,
4305,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
5890,
492,
6186,
63,
10960,
63,
4305,
272,
871,
3545,
26,
267,
6186,
63,
10960,
63,
4305,
275,
446,
17,
199,
199,
646,
984,
199,
199,
504,
13397,
492,
12464,
1000,
421,
199,
533,
22422,
5413,
10200,
8,
6508,
1000,
14,
5413,
10200,
304,
339,
408,
33,
4975,
367,
17806,
1958,
2018,
1159,
6762,
6149,
859,
543,
30992,
27794,
1041,
339,
5897,
275,
488,
272,
408,
1918,
1788,
402,
314,
1654,
7799,
5897,
1041,
339,
5726,
63,
498,
275,
488,
272,
408,
1918,
1788,
402,
314,
1654,
1159,
5726,
790,
570,
1041,
2286,
5897,
63,
4429,
275,
488,
272,
408,
1918,
1788,
402,
314,
5897,
6036,
570,
1041,
2286,
408,
1918,
6149,
14,
5413,
2998,
626,
911,
506,
1202,
370,
4816,
18772,
2382,
2808,
272,
334,
265,
2018,
690,
499,
14,
23,
14,
25,
1182,
650,
14,
19,
9,
272,
408,
272,
1067,
275,
488,
339,
347,
636,
826,
721,
277,
12,
5897,
12,
5726,
63,
498,
12,
5897,
63,
4429,
29,
403,
304,
267,
340,
6149,
365,
488,
26,
288,
746,
3545,
480,
5556,
1471,
3907,
314,
6149,
859,
370,
675,
14147,
2685,
267,
291,
14,
6999,
275,
5897,
267,
291,
14,
4239,
63,
498,
275,
5726,
63,
498,
267,
291,
14,
6999,
63,
4429,
275,
5897,
63,
4429,
267,
340,
2688,
8,
4266,
12,
283,
981,
63,
885,
63,
1100,
735,
288,
291,
14,
1100,
275,
6149,
14,
981,
63,
885,
63,
1100,
8,
355,
12016,
29,
4266,
14,
14959,
4070,
14,
9901,
63,
5580,
12,
355,
1704,
493,
29,
6999,
63,
4429,
288,
776,
288,
291,
14,
1100,
14,
912,
63,
4736,
63,
4429,
8,
6999,
12,
5726,
63,
498,
9,
339,
347,
5398,
8,
277,
12,
6771,
304,
267,
408,
15991,
436,
372,
314,
1627,
2838,
1041,
267,
372,
6771,
339,
347,
4816,
8,
277,
12,
6771,
304,
267,
408,
15991,
436,
372,
314,
1627,
2838,
12,
12254,
9279,
6160,
4811,
1041,
267,
862,
26,
288,
340,
291,
14,
1100,
365,
440,
488,
26,
355,
308,
275,
291,
14,
1100,
14,
3823,
63,
3450,
8,
5096,
12,
1117,
63,
11913,
63,
265,
63,
2242,
29,
549,
12,
6163,
1654,
63,
2441,
29,
549,
9,
288,
587,
26,
355,
308,
275,
6149,
14,
3823,
63,
3450,
8,
5096,
12,
886,
63,
11913,
63,
265,
63,
2242,
29,
549,
12,
2511,
1654,
63,
2441,
29,
549,
12,
27660,
29,
277,
14,
6999,
12,
2511,
25776,
29,
277,
14,
4239,
63,
498,
12,
2511,
6149,
63,
1023,
29,
4266,
14,
9583,
63,
21082,
1789,
12,
2511,
1704,
63,
8356,
29,
277,
14,
6999,
63,
4429,
9,
267,
871,
6149,
14,
27102,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
340,
325,
14,
7931,
508,
6149,
14,
5413,
63,
3170,
63,
13178,
26,
355,
327,
961,
365,
18871,
9842,
590,
7037,
370,
314,
13397,
6869,
355,
327,
283,
4073,
316,
7,
314,
2838,
370,
702,
652,
1159,
4907,
461,
27,
355,
327,
314,
283,
4073,
7,
5712,
1133,
7799,
14,
355,
372,
488,
12,
1052,
288,
916,
325,
14,
7931,
508,
6149,
14,
5413,
63,
3170,
63,
5413,
26,
355,
340,
325,
14,
589,
59,
17,
1055,
4130,
360,
1014,
1056,
735,
490,
327,
710,
1890,
365,
308,
8556,
316,
3101,
370,
376,
14147,
1654,
14,
490,
746,
12464,
1000,
14,
1944,
27102,
355,
916,
325,
14,
589,
59,
17,
1055,
4130,
360,
5187,
4113,
735,
490,
327,
710,
1890,
365,
308,
8556,
316,
2005,
2222,
13,
2856,
4113,
14,
490,
327,
18110,
314,
2557,
14,
490,
372,
488,
12,
1052,
288,
746,
267,
372,
308,
12,
291,
14,
362,
63,
2314,
8,
83,
9,
339,
327,
3254,
26,
5554,
642,
734,
1655,
543,
3413,
6149,
2589,
272,
347,
664,
63,
2314,
8,
277,
12,
6771,
304,
267,
408,
2499,
9279,
6160,
4811,
370,
506,
9545,
1901,
1924,
1056,
1041,
267,
10830,
275,
6771,
14,
9231,
342,
267,
6149,
63,
2314,
275,
469,
288,
298,
6508,
14,
633,
63,
5512,
582,
298,
2859,
401,
288,
298,
14921,
582,
298,
265,
401,
288,
283,
5413,
63,
9583,
356,
10830,
59,
17,
467,
288,
283,
5413,
63,
35,
1772,
3452,
356,
10830,
59,
16,
61,
288,
327,
7799,
63,
4612,
63,
17598,
221,
198,
875,
221,
198,
1918,
3413,
63,
4266,
2240,
1015,
288,
327,
7799,
63,
4612,
63,
16983,
221,
198,
875,
221,
198,
1918,
14296,
2240,
1015,
267,
789,
267,
372,
6149,
63,
2314,
339,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
378,
304,
267,
347,
16818,
8,
277,
12,
6771,
12,
818,
534,
82,
297,
17080,
29,
3472,
63,
10960,
63,
4305,
304,
288,
372,
12464,
1000,
14,
2890,
63,
13941,
8,
5096,
12,
818,
12,
17080,
9,
272,
587,
26,
267,
347,
16818,
8,
277,
12,
6771,
12,
818,
534,
82,
297,
17080,
29,
3472,
63,
10960,
63,
4305,
304,
288,
372,
12464,
1000,
14,
2890,
63,
493,
785,
8,
5096,
12,
818,
12,
17080,
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
] |
[
33,
3555,
367,
17806,
1958,
2018,
1159,
6762,
1124,
4266,
1040,
3555,
543,
30992,
27794,
14,
199,
199,
1918,
6149,
859,
1471,
506,
492,
461,
367,
7799,
9330,
14,
199,
199,
1378,
675,
642,
859,
12,
663,
1124,
1049,
281,
27794,
55,
28732,
14,
4266,
63,
10394,
1040,
370,
376,
1256,
402,
199,
1040,
12306,
5413,
10200,
4345,
199,
624,
199,
199,
893,
26,
272,
492,
6149,
199,
2590,
3545,
26,
272,
6149,
275,
488,
199,
199,
893,
26,
272,
687,
485,
647,
2308,
492,
6186,
63,
10960,
63,
4305,
199,
2590,
3545,
26,
272,
862,
26,
267,
687,
5890,
492,
6186,
63,
10960,
63,
4305,
272,
871,
3545,
26,
267,
6186,
63,
10960,
63,
4305,
275,
446,
17,
199,
199,
646,
984,
199,
199,
504,
13397,
492,
12464,
1000,
421,
199,
533,
22422,
5413,
10200,
8,
6508,
1000,
14,
5413,
10200,
304,
339,
408,
33,
4975,
367,
17806,
1958,
2018,
1159,
6762,
6149,
859,
543,
30992,
27794,
1041,
339,
5897,
275,
488,
272,
408,
1918,
1788,
402,
314,
1654,
7799,
5897,
1041,
339,
5726,
63,
498,
275,
488,
272,
408,
1918,
1788,
402,
314,
1654,
1159,
5726,
790,
570,
1041,
2286,
5897,
63,
4429,
275,
488,
272,
408,
1918,
1788,
402,
314,
5897,
6036,
570,
1041,
2286,
408,
1918,
6149,
14,
5413,
2998,
626,
911,
506,
1202,
370,
4816,
18772,
2382,
2808,
272,
334,
265,
2018,
690,
499,
14,
23,
14,
25,
1182,
650,
14,
19,
9,
272,
408,
272,
1067,
275,
488,
339,
347,
636,
826,
721,
277,
12,
5897,
12,
5726,
63,
498,
12,
5897,
63,
4429,
29,
403,
304,
267,
340,
6149,
365,
488,
26,
288,
746,
3545,
480,
5556,
1471,
3907,
314,
6149,
859,
370,
675,
14147,
2685,
267,
291,
14,
6999,
275,
5897,
267,
291,
14,
4239,
63,
498,
275,
5726,
63,
498,
267,
291,
14,
6999,
63,
4429,
275,
5897,
63,
4429,
267,
340,
2688,
8,
4266,
12,
283,
981,
63,
885,
63,
1100,
735,
288,
291,
14,
1100,
275,
6149,
14,
981,
63,
885,
63,
1100,
8,
355,
12016,
29,
4266,
14,
14959,
4070,
14,
9901,
63,
5580,
12,
355,
1704,
493,
29,
6999,
63,
4429,
288,
776,
288,
291,
14,
1100,
14,
912,
63,
4736,
63,
4429,
8,
6999,
12,
5726,
63,
498,
9,
339,
347,
5398,
8,
277,
12,
6771,
304,
267,
408,
15991,
436,
372,
314,
1627,
2838,
1041,
267,
372,
6771,
339,
347,
4816,
8,
277,
12,
6771,
304,
267,
408,
15991,
436,
372,
314,
1627,
2838,
12,
12254,
9279,
6160,
4811,
1041,
267,
862,
26,
288,
340,
291,
14,
1100,
365,
440,
488,
26,
355,
308,
275,
291,
14,
1100,
14,
3823,
63,
3450,
8,
5096,
12,
1117,
63,
11913,
63,
265,
63,
2242,
29,
549,
12,
6163,
1654,
63,
2441,
29,
549,
9,
288,
587,
26,
355,
308,
275,
6149,
14,
3823,
63,
3450,
8,
5096,
12,
886,
63,
11913,
63,
265,
63,
2242,
29,
549,
12,
2511,
1654,
63,
2441,
29,
549,
12,
27660,
29,
277,
14,
6999,
12,
2511,
25776,
29,
277,
14,
4239,
63,
498,
12,
2511,
6149,
63,
1023,
29,
4266,
14,
9583,
63,
21082,
1789,
12,
2511,
1704,
63,
8356,
29,
277,
14,
6999,
63,
4429,
9,
267,
871,
6149,
14,
27102,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
340,
325,
14,
7931,
508,
6149,
14,
5413,
63,
3170,
63,
13178,
26,
355,
327,
961,
365,
18871,
9842,
590,
7037,
370,
314,
13397,
6869,
355,
327,
283,
4073,
316,
7,
314,
2838,
370,
702,
652,
1159,
4907,
461,
27,
355,
327,
314,
283,
4073,
7,
5712,
1133,
7799,
14,
355,
372,
488,
12,
1052,
288,
916,
325,
14,
7931,
508,
6149,
14,
5413,
63,
3170,
63,
5413,
26,
355,
340,
325,
14,
589,
59,
17,
1055,
4130,
360,
1014,
1056,
735,
490,
327,
710,
1890,
365,
308,
8556,
316,
3101,
370,
376,
14147,
1654,
14,
490,
746,
12464,
1000,
14,
1944,
27102,
355,
916,
325,
14,
589,
59,
17,
1055,
4130,
360,
5187,
4113,
735,
490,
327,
710,
1890,
365,
308,
8556,
316,
2005,
2222,
13,
2856,
4113,
14,
490,
327,
18110,
314,
2557,
14,
490,
372,
488,
12,
1052,
288,
746,
267,
372,
308,
12,
291,
14,
362,
63,
2314,
8,
83,
9,
339,
327,
3254,
26,
5554,
642,
734,
1655,
543,
3413,
6149,
2589,
272,
347,
664,
63,
2314,
8,
277,
12,
6771,
304,
267,
408,
2499,
9279,
6160,
4811,
370,
506,
9545,
1901,
1924,
1056,
1041,
267,
10830,
275,
6771,
14,
9231,
342,
267,
6149,
63,
2314,
275,
469,
288,
298,
6508,
14,
633,
63,
5512,
582,
298,
2859,
401,
288,
298,
14921,
582,
298,
265,
401,
288,
283,
5413,
63,
9583,
356,
10830,
59,
17,
467,
288,
283,
5413,
63,
35,
1772,
3452,
356,
10830,
59,
16,
61,
288,
327,
7799,
63,
4612,
63,
17598,
221,
198,
875,
221,
198,
1918,
3413,
63,
4266,
2240,
1015,
288,
327,
7799,
63,
4612,
63,
16983,
221,
198,
875,
221,
198,
1918,
14296,
2240,
1015,
267,
789,
267,
372,
6149,
63,
2314,
339,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
378,
304,
267,
347,
16818,
8,
277,
12,
6771,
12,
818,
534,
82,
297,
17080,
29,
3472,
63,
10960,
63,
4305,
304,
288,
372,
12464,
1000,
14,
2890,
63,
13941,
8,
5096,
12,
818,
12,
17080,
9,
272,
587,
26,
267,
347,
16818,
8,
277,
12,
6771,
12,
818,
534,
82,
297,
17080,
29,
3472,
63,
10960,
63,
4305,
304,
288,
372,
12464,
1000,
14,
2890,
63,
493,
785,
8,
5096,
12,
818,
12,
17080,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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-*-
# Copyright 2020 Google LLC
#
# 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.
#
# Generated code. DO NOT EDIT!
#
# Snippet for ListFeeds
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.
# To install the latest published package dependency, execute the following:
# python3 -m pip install google-cloud-asset
# [START cloudasset_generated_asset_v1_AssetService_ListFeeds_async]
from google.cloud import asset_v1
async def sample_list_feeds():
"""Snippet for list_feeds"""
# Create a client
client = asset_v1.AssetServiceAsyncClient()
# Initialize request argument(s)
request = asset_v1.ListFeedsRequest(
)
# Make the request
response = await client.list_feeds(request=request)
# Handle response
print("{}".format(response))
# [END cloudasset_generated_asset_v1_AssetService_ListFeeds_async]
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
17065,
1233,
14,
3506,
2845,
24981,
1,
199,
3,
199,
3,
428,
78,
11088,
367,
3820,
3456,
5923,
199,
3,
6944,
26,
961,
17440,
965,
2757,
5847,
4046,
367,
22907,
833,
30498,
12901,
1454,
14,
199,
3,
2779,
1443,
4409,
23070,
370,
1736,
315,
2195,
3734,
14,
199,
199,
3,
4005,
3907,
314,
8839,
3267,
2559,
5936,
12,
5341,
314,
2569,
26,
199,
3,
257,
2366,
19,
446,
77,
7305,
3907,
6233,
13,
4091,
13,
6562,
421,
199,
3,
359,
7363,
8002,
6562,
63,
10176,
63,
6562,
63,
86,
17,
63,
19979,
3167,
63,
1296,
3456,
5923,
63,
4146,
61,
199,
504,
6233,
14,
4091,
492,
8977,
63,
86,
17,
421,
199,
4146,
347,
2690,
63,
513,
63,
11522,
837,
272,
408,
20821,
11088,
367,
769,
63,
11522,
624,
339,
327,
2790,
282,
1890,
272,
1890,
275,
8977,
63,
86,
17,
14,
19979,
3167,
12807,
3041,
342,
339,
327,
11578,
1056,
1423,
8,
83,
9,
272,
1056,
275,
8977,
63,
86,
17,
14,
1296,
3456,
5923,
2017,
8,
272,
776,
339,
327,
4155,
314,
1056,
272,
1177,
275,
5517,
1890,
14,
513,
63,
11522,
8,
1069,
29,
1069,
9,
339,
327,
8690,
1177,
272,
870,
480,
13536,
908,
8,
1310,
430,
199,
199,
3,
359,
3902,
8002,
6562,
63,
10176,
63,
6562,
63,
86,
17,
63,
19979,
3167,
63,
1296,
3456,
5923,
63,
4146,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
17065,
1233,
14,
3506,
2845,
24981,
1,
199,
3,
199,
3,
428,
78,
11088,
367,
3820,
3456,
5923,
199,
3,
6944,
26,
961,
17440,
965,
2757,
5847,
4046,
367,
22907,
833,
30498,
12901,
1454,
14,
199,
3,
2779,
1443,
4409,
23070,
370,
1736,
315,
2195,
3734,
14,
199,
199,
3,
4005,
3907,
314,
8839,
3267,
2559,
5936,
12,
5341,
314,
2569,
26,
199,
3,
257,
2366,
19,
446,
77,
7305,
3907,
6233,
13,
4091,
13,
6562,
421,
199,
3,
359,
7363,
8002,
6562,
63,
10176,
63,
6562,
63,
86,
17,
63,
19979,
3167,
63,
1296,
3456,
5923,
63,
4146,
61,
199,
504,
6233,
14,
4091,
492,
8977,
63,
86,
17,
421,
199,
4146,
347,
2690,
63,
513,
63,
11522,
837,
272,
408,
20821,
11088,
367,
769,
63,
11522,
624,
339,
327,
2790,
282,
1890,
272,
1890,
275,
8977,
63,
86,
17,
14,
19979,
3167,
12807,
3041,
342,
339,
327,
11578,
1056,
1423,
8,
83,
9,
272,
1056,
275,
8977,
63,
86,
17,
14,
1296,
3456,
5923,
2017,
8,
272,
776,
339,
327,
4155,
314,
1056,
272,
1177,
275,
5517,
1890,
14,
513,
63,
11522,
8,
1069,
29,
1069,
9,
339,
327,
8690,
1177,
272,
870,
480,
13536,
908,
8,
1310,
430,
199,
199,
3,
359,
3902,
8002,
6562,
63,
10176,
63,
6562,
63,
86,
17,
63,
19979,
3167,
63,
1296,
3456,
5923,
63,
4146,
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,
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,
0,
0,
0,
0,
0,
0,
0
] |
elainenaomi/sciwonc-dataflow-examples
|
dissertation2017/Experiment 1B/instances/10_2_workflow_full_10files_secondary_wmj_3sh_3rs_with_annot_with_proj_3s_range_old/taskevent_8/TaskEvent_8.py
|
32
|
6282
|
#!/usr/bin/env python
"""
Computes per event type:
- how many tasks are per event?
- which is the average and standard deviation of CPU request per event?
- which is the average and standard deviation of Memory request per event?
"""
# It will connect to DataStoreClient
from sciwonc.dataflow.DataStoreClient import DataStoreClient
import sys
##################################################################
import ConfigDB_Task_StatsCPUMemory_8
client_averagecpu = DataStoreClient("mongodb", ConfigDB_Task_StatsCPUMemory_8)
data_averagecpu = client_averagecpu.getData()
if data_averagecpu:
while True:
doc = data_averagecpu.next()
if doc is None:
break;
sd_cpu = doc['standard deviation cpu']
avg_cpu = doc['average cpu']
sd_memory = doc['standard deviation memory']
avg_memory = doc['average memory']
sd_ratio = doc['standard deviation ratio']
avg_ratio = doc['average ratio']
##################################################################
import ConfigDB_Task_GeneralInfo_8
client_geninfo = DataStoreClient("mongodb", ConfigDB_Task_GeneralInfo_8)
data_geninfo = client_geninfo.getData()
if data_geninfo:
while True:
doc = data_geninfo.next()
if doc is None:
break;
print doc
total_items = doc['total items']
##################################################################
import ConfigDB_TaskEvent_8
import math
# connector and config
config = ConfigDB_TaskEvent_8
client = DataStoreClient("mongodb", config)
# according to config
eventList = client.getData() # return an array of docs (like a csv reader)
info = {}
if(eventList):
for index in eventList:
# sum_ratio = 0
total_valid_tasks = 0
total_tasks = 0
event_type = index[config.COLUMN]
sum_memory = 0
sum_cpu = 0
sum_ratio = 0
while True:
doc = index['data'].next()
if doc is None:
break;
total_tasks += 1
if(doc['memory request']):
sum_memory = sum_memory + float(doc['memory request'])
if(doc['CPU request']):
sum_cpu = sum_cpu + float(doc['CPU request'])
if(doc['CPU request']) and (doc['memory request']):
ratio = float(doc['CPU request'])/ float(doc['memory request']) if float(doc['memory request']) > 0 else 0
sum_ratio = sum_ratio + ratio
total_valid_tasks += 1
# average
average_memory = sum_memory / total_valid_tasks if total_valid_tasks > 0 else 0
average_cpu = sum_cpu / total_valid_tasks if total_valid_tasks > 0 else 0
average_ratio = sum_ratio / total_valid_tasks if total_valid_tasks > 0 else 0
event_info = {}
event_info['event type'] = event_type
event_info['sum memory'] = sum_memory
event_info['sum cpu'] = sum_cpu
event_info['sum ratio'] = sum_ratio
event_info['total valid tasks'] = total_valid_tasks
event_info['total tasks'] = total_tasks
event_info['average memory'] = average_memory
event_info['average cpu'] = average_cpu
event_info['average ratio'] = average_ratio
info[event_type] = event_info
# according to config
eventList = client.getData() # return an array of docs (like a csv reader)
output = []
if(eventList):
for index in eventList:
event_type = index[config.COLUMN]
total_variance_memory = 0
total_variance_cpu = 0
total_variance_ratio = 0
average_memory = info[event_type]['average memory']
average_cpu = info[event_type]['average cpu']
average_ratio = info[event_type]['average ratio']
while True:
doc = index['data'].next()
if doc is None:
break;
if(doc['memory request'] and doc['CPU request']):
total_variance_memory = total_variance_memory + (float(doc['memory request']) - average_memory) ** 2
total_variance_cpu = total_variance_cpu + (float(doc['CPU request']) - average_cpu) ** 2
ratio = float(doc['CPU request']) / float(doc['memory request']) if float(doc['memory request']) > 0 else 0
total_variance_ratio = total_variance_ratio + (ratio - average_ratio) ** 2
total_valid_tasks = info[event_type]['total valid tasks'] if total_valid_tasks is not None else 0
newline = {}
newline['event type'] = event_type
newline['sum memory'] = info[event_type]['sum memory']
newline['sum cpu'] = info[event_type]['sum cpu']
newline['sum ratio'] = info[event_type]['sum ratio']
newline['total valid tasks'] = info[event_type]['total valid tasks']
newline['total tasks'] = info[event_type]['total tasks']
newline['average memory'] = average_memory
newline['average cpu'] = average_cpu
newline['average ratio'] = average_ratio
newline['variance memory'] = total_variance_memory/total_valid_tasks if total_valid_tasks > 0 else None
newline['variance cpu'] = total_variance_cpu/total_valid_tasks if total_valid_tasks > 0 else None
newline['variance ratio'] = total_variance_ratio/total_valid_tasks if total_valid_tasks > 0 else None
newline['standard deviation memory'] = math.sqrt(total_variance_memory/total_valid_tasks) if total_valid_tasks > 0 else None
newline['standard deviation cpu'] = math.sqrt(total_variance_cpu/total_valid_tasks) if total_valid_tasks > 0 else None
newline['standard deviation ratio'] = math.sqrt(total_variance_ratio/total_valid_tasks) if total_valid_tasks > 0 else None
newline['percentagem from total'] = total_items * 100.0 / total_valid_tasks if total_valid_tasks > 0 else None
newline['sds from avg cpu'] = (average_cpu - avg_cpu)/sd_cpu if sd_cpu is not None else None
newline['sds from avg memory'] = (average_memory - avg_memory)/sd_memory if sd_memory is not None else None
newline['sds from avg ratio'] = (average_ratio - avg_ratio)/sd_ratio if sd_ratio is not None else None
output.append(newline)
# save
client.saveData(output)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
22594,
1126,
1566,
730,
26,
523,
446,
4212,
5002,
6527,
787,
1126,
1566,
31,
523,
446,
1314,
365,
314,
8095,
436,
4465,
18458,
402,
11952,
1056,
1126,
1566,
31,
523,
446,
1314,
365,
314,
8095,
436,
4465,
18458,
402,
15825,
1056,
1126,
1566,
31,
199,
624,
199,
199,
3,
2779,
911,
4907,
370,
3918,
5502,
3041,
199,
504,
6276,
87,
265,
67,
14,
576,
1659,
14,
1451,
5502,
3041,
492,
3918,
5502,
3041,
199,
646,
984,
199,
3060,
309,
199,
646,
4094,
2846,
63,
4476,
63,
8257,
11011,
8628,
63,
24,
199,
1258,
63,
8536,
3541,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
4094,
2846,
63,
4476,
63,
8257,
11011,
8628,
63,
24,
9,
199,
576,
63,
8536,
3541,
275,
1890,
63,
8536,
3541,
14,
29276,
342,
199,
199,
692,
666,
63,
8536,
3541,
26,
272,
1830,
715,
26,
267,
1382,
275,
666,
63,
8536,
3541,
14,
2184,
342,
267,
340,
1382,
365,
488,
26,
288,
2059,
27,
398,
14613,
63,
3541,
275,
1382,
459,
6807,
18458,
5033,
418,
267,
12402,
63,
3541,
275,
1382,
459,
8536,
5033,
418,
267,
14613,
63,
4844,
275,
1382,
459,
6807,
18458,
4402,
418,
267,
12402,
63,
4844,
275,
1382,
459,
8536,
4402,
418,
267,
14613,
63,
6884,
275,
1382,
459,
6807,
18458,
10463,
418,
267,
12402,
63,
6884,
275,
1382,
459,
8536,
10463,
418,
421,
199,
3060,
309,
199,
646,
4094,
2846,
63,
4476,
63,
14109,
2354,
63,
24,
199,
1258,
63,
2268,
815,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
4094,
2846,
63,
4476,
63,
14109,
2354,
63,
24,
9,
199,
576,
63,
2268,
815,
275,
1890,
63,
2268,
815,
14,
29276,
342,
199,
199,
692,
666,
63,
2268,
815,
26,
272,
1830,
715,
26,
267,
1382,
275,
666,
63,
2268,
815,
14,
2184,
342,
267,
340,
1382,
365,
488,
26,
288,
2059,
27,
267,
870,
1382,
267,
3141,
63,
1744,
275,
1382,
459,
2923,
2974,
418,
199,
199,
3060,
309,
421,
199,
646,
4094,
2846,
63,
4476,
2390,
63,
24,
199,
646,
3473,
199,
199,
3,
13252,
436,
1101,
199,
888,
275,
4094,
2846,
63,
4476,
2390,
63,
24,
199,
1258,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
1101,
9,
199,
199,
3,
7182,
370,
1101,
199,
1430,
1296,
275,
1890,
14,
29276,
342,
327,
372,
376,
1625,
402,
9149,
334,
2930,
282,
7392,
7002,
9,
199,
199,
815,
275,
1052,
199,
199,
692,
8,
1430,
1296,
304,
272,
367,
1478,
315,
1566,
1296,
26,
398,
327,
3089,
63,
6884,
275,
378,
267,
3141,
63,
1078,
63,
5054,
275,
378,
267,
3141,
63,
5054,
275,
378,
267,
1566,
63,
466,
275,
1478,
59,
888,
14,
21436,
61,
267,
3089,
63,
4844,
275,
378,
267,
3089,
63,
3541,
275,
378,
267,
3089,
63,
6884,
275,
378,
398,
1830,
715,
26,
288,
1382,
275,
1478,
459,
576,
2278,
2184,
342,
953,
340,
1382,
365,
488,
26,
355,
2059,
27,
953,
3141,
63,
5054,
847,
413,
953,
340,
8,
1301,
459,
4844,
1056,
9090,
355,
3089,
63,
4844,
275,
3089,
63,
4844,
435,
2069,
8,
1301,
459,
4844,
1056,
1105,
953,
340,
8,
1301,
459,
11011,
1056,
9090,
355,
3089,
63,
3541,
275,
3089,
63,
3541,
435,
2069,
8,
1301,
459,
11011,
1056,
1105,
953,
340,
8,
1301,
459,
11011,
1056,
1105,
436,
334,
1301,
459,
4844,
1056,
9090,
355,
10463,
275,
2069,
8,
1301,
459,
11011,
1056,
1105,
15,
2069,
8,
1301,
459,
4844,
1056,
1105,
340,
2069,
8,
1301,
459,
4844,
1056,
1105,
690,
378,
587,
378,
355,
3089,
63,
6884,
275,
3089,
63,
6884,
435,
10463,
355,
3141,
63,
1078,
63,
5054,
847,
413,
398,
327,
8095,
267,
8095,
63,
4844,
275,
3089,
63,
4844,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
267,
8095,
63,
3541,
275,
3089,
63,
3541,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
267,
8095,
63,
6884,
275,
3089,
63,
6884,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
398,
1566,
63,
815,
275,
1052,
267,
1566,
63,
815,
459,
1430,
730,
418,
275,
1566,
63,
466,
267,
1566,
63,
815,
459,
1838,
4402,
418,
275,
3089,
63,
4844,
267,
1566,
63,
815,
459,
1838,
5033,
418,
275,
3089,
63,
3541,
267,
1566,
63,
815,
459,
1838,
10463,
418,
275,
3089,
63,
6884,
398,
1566,
63,
815,
459,
2923,
1686,
6527,
418,
275,
3141,
63,
1078,
63,
5054,
267,
1566,
63,
815,
459,
2923,
6527,
418,
275,
3141,
63,
5054,
398,
1566,
63,
815,
459,
8536,
4402,
418,
275,
8095,
63,
4844,
267,
1566,
63,
815,
459,
8536,
5033,
418,
275,
8095,
63,
3541,
267,
1566,
63,
815,
459,
8536,
10463,
418,
275,
8095,
63,
6884,
267,
2256,
59,
1430,
63,
466,
61,
275,
1566,
63,
815,
4388,
199,
3,
7182,
370,
1101,
199,
1430,
1296,
275,
1890,
14,
29276,
342,
327,
372,
376,
1625,
402,
9149,
334,
2930,
282,
7392,
7002,
9,
199,
1199,
275,
942,
199,
199,
692,
8,
1430,
1296,
304,
272,
367,
1478,
315,
1566,
1296,
26,
398,
1566,
63,
466,
275,
1478,
59,
888,
14,
21436,
61,
267,
3141,
63,
6221,
63,
4844,
275,
378,
267,
3141,
63,
6221,
63,
3541,
275,
378,
267,
3141,
63,
6221,
63,
6884,
275,
378,
398,
8095,
63,
4844,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
4402,
418,
267,
8095,
63,
3541,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
5033,
418,
267,
8095,
63,
6884,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
10463,
418,
398,
1830,
715,
26,
288,
1382,
275,
1478,
459,
576,
2278,
2184,
342,
288,
340,
1382,
365,
488,
26,
355,
2059,
27,
953,
340,
8,
1301,
459,
4844,
1056,
418,
436,
1382,
459,
11011,
1056,
9090,
355,
3141,
63,
6221,
63,
4844,
275,
3141,
63,
6221,
63,
4844,
435,
334,
1609,
8,
1301,
459,
4844,
1056,
1105,
446,
8095,
63,
4844,
9,
1011,
499,
355,
3141,
63,
6221,
63,
3541,
275,
3141,
63,
6221,
63,
3541,
435,
334,
1609,
8,
1301,
459,
11011,
1056,
1105,
446,
8095,
63,
3541,
9,
1011,
499,
355,
10463
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
22594,
1126,
1566,
730,
26,
523,
446,
4212,
5002,
6527,
787,
1126,
1566,
31,
523,
446,
1314,
365,
314,
8095,
436,
4465,
18458,
402,
11952,
1056,
1126,
1566,
31,
523,
446,
1314,
365,
314,
8095,
436,
4465,
18458,
402,
15825,
1056,
1126,
1566,
31,
199,
624,
199,
199,
3,
2779,
911,
4907,
370,
3918,
5502,
3041,
199,
504,
6276,
87,
265,
67,
14,
576,
1659,
14,
1451,
5502,
3041,
492,
3918,
5502,
3041,
199,
646,
984,
199,
3060,
309,
199,
646,
4094,
2846,
63,
4476,
63,
8257,
11011,
8628,
63,
24,
199,
1258,
63,
8536,
3541,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
4094,
2846,
63,
4476,
63,
8257,
11011,
8628,
63,
24,
9,
199,
576,
63,
8536,
3541,
275,
1890,
63,
8536,
3541,
14,
29276,
342,
199,
199,
692,
666,
63,
8536,
3541,
26,
272,
1830,
715,
26,
267,
1382,
275,
666,
63,
8536,
3541,
14,
2184,
342,
267,
340,
1382,
365,
488,
26,
288,
2059,
27,
398,
14613,
63,
3541,
275,
1382,
459,
6807,
18458,
5033,
418,
267,
12402,
63,
3541,
275,
1382,
459,
8536,
5033,
418,
267,
14613,
63,
4844,
275,
1382,
459,
6807,
18458,
4402,
418,
267,
12402,
63,
4844,
275,
1382,
459,
8536,
4402,
418,
267,
14613,
63,
6884,
275,
1382,
459,
6807,
18458,
10463,
418,
267,
12402,
63,
6884,
275,
1382,
459,
8536,
10463,
418,
421,
199,
3060,
309,
199,
646,
4094,
2846,
63,
4476,
63,
14109,
2354,
63,
24,
199,
1258,
63,
2268,
815,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
4094,
2846,
63,
4476,
63,
14109,
2354,
63,
24,
9,
199,
576,
63,
2268,
815,
275,
1890,
63,
2268,
815,
14,
29276,
342,
199,
199,
692,
666,
63,
2268,
815,
26,
272,
1830,
715,
26,
267,
1382,
275,
666,
63,
2268,
815,
14,
2184,
342,
267,
340,
1382,
365,
488,
26,
288,
2059,
27,
267,
870,
1382,
267,
3141,
63,
1744,
275,
1382,
459,
2923,
2974,
418,
199,
199,
3060,
309,
421,
199,
646,
4094,
2846,
63,
4476,
2390,
63,
24,
199,
646,
3473,
199,
199,
3,
13252,
436,
1101,
199,
888,
275,
4094,
2846,
63,
4476,
2390,
63,
24,
199,
1258,
275,
3918,
5502,
3041,
480,
22130,
13152,
401,
1101,
9,
199,
199,
3,
7182,
370,
1101,
199,
1430,
1296,
275,
1890,
14,
29276,
342,
327,
372,
376,
1625,
402,
9149,
334,
2930,
282,
7392,
7002,
9,
199,
199,
815,
275,
1052,
199,
199,
692,
8,
1430,
1296,
304,
272,
367,
1478,
315,
1566,
1296,
26,
398,
327,
3089,
63,
6884,
275,
378,
267,
3141,
63,
1078,
63,
5054,
275,
378,
267,
3141,
63,
5054,
275,
378,
267,
1566,
63,
466,
275,
1478,
59,
888,
14,
21436,
61,
267,
3089,
63,
4844,
275,
378,
267,
3089,
63,
3541,
275,
378,
267,
3089,
63,
6884,
275,
378,
398,
1830,
715,
26,
288,
1382,
275,
1478,
459,
576,
2278,
2184,
342,
953,
340,
1382,
365,
488,
26,
355,
2059,
27,
953,
3141,
63,
5054,
847,
413,
953,
340,
8,
1301,
459,
4844,
1056,
9090,
355,
3089,
63,
4844,
275,
3089,
63,
4844,
435,
2069,
8,
1301,
459,
4844,
1056,
1105,
953,
340,
8,
1301,
459,
11011,
1056,
9090,
355,
3089,
63,
3541,
275,
3089,
63,
3541,
435,
2069,
8,
1301,
459,
11011,
1056,
1105,
953,
340,
8,
1301,
459,
11011,
1056,
1105,
436,
334,
1301,
459,
4844,
1056,
9090,
355,
10463,
275,
2069,
8,
1301,
459,
11011,
1056,
1105,
15,
2069,
8,
1301,
459,
4844,
1056,
1105,
340,
2069,
8,
1301,
459,
4844,
1056,
1105,
690,
378,
587,
378,
355,
3089,
63,
6884,
275,
3089,
63,
6884,
435,
10463,
355,
3141,
63,
1078,
63,
5054,
847,
413,
398,
327,
8095,
267,
8095,
63,
4844,
275,
3089,
63,
4844,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
267,
8095,
63,
3541,
275,
3089,
63,
3541,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
267,
8095,
63,
6884,
275,
3089,
63,
6884,
1182,
3141,
63,
1078,
63,
5054,
340,
3141,
63,
1078,
63,
5054,
690,
378,
587,
378,
398,
1566,
63,
815,
275,
1052,
267,
1566,
63,
815,
459,
1430,
730,
418,
275,
1566,
63,
466,
267,
1566,
63,
815,
459,
1838,
4402,
418,
275,
3089,
63,
4844,
267,
1566,
63,
815,
459,
1838,
5033,
418,
275,
3089,
63,
3541,
267,
1566,
63,
815,
459,
1838,
10463,
418,
275,
3089,
63,
6884,
398,
1566,
63,
815,
459,
2923,
1686,
6527,
418,
275,
3141,
63,
1078,
63,
5054,
267,
1566,
63,
815,
459,
2923,
6527,
418,
275,
3141,
63,
5054,
398,
1566,
63,
815,
459,
8536,
4402,
418,
275,
8095,
63,
4844,
267,
1566,
63,
815,
459,
8536,
5033,
418,
275,
8095,
63,
3541,
267,
1566,
63,
815,
459,
8536,
10463,
418,
275,
8095,
63,
6884,
267,
2256,
59,
1430,
63,
466,
61,
275,
1566,
63,
815,
4388,
199,
3,
7182,
370,
1101,
199,
1430,
1296,
275,
1890,
14,
29276,
342,
327,
372,
376,
1625,
402,
9149,
334,
2930,
282,
7392,
7002,
9,
199,
1199,
275,
942,
199,
199,
692,
8,
1430,
1296,
304,
272,
367,
1478,
315,
1566,
1296,
26,
398,
1566,
63,
466,
275,
1478,
59,
888,
14,
21436,
61,
267,
3141,
63,
6221,
63,
4844,
275,
378,
267,
3141,
63,
6221,
63,
3541,
275,
378,
267,
3141,
63,
6221,
63,
6884,
275,
378,
398,
8095,
63,
4844,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
4402,
418,
267,
8095,
63,
3541,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
5033,
418,
267,
8095,
63,
6884,
275,
2256,
59,
1430,
63,
466,
2733,
8536,
10463,
418,
398,
1830,
715,
26,
288,
1382,
275,
1478,
459,
576,
2278,
2184,
342,
288,
340,
1382,
365,
488,
26,
355,
2059,
27,
953,
340,
8,
1301,
459,
4844,
1056,
418,
436,
1382,
459,
11011,
1056,
9090,
355,
3141,
63,
6221,
63,
4844,
275,
3141,
63,
6221,
63,
4844,
435,
334,
1609,
8,
1301,
459,
4844,
1056,
1105,
446,
8095,
63,
4844,
9,
1011,
499,
355,
3141,
63,
6221,
63,
3541,
275,
3141,
63,
6221,
63,
3541,
435,
334,
1609,
8,
1301,
459,
11011,
1056,
1105,
446,
8095,
63,
3541,
9,
1011,
499,
355,
10463,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bc-python-tools/mistool
|
test/python/dict/test_dictvalues.py
|
1
|
1422
|
#!/usr/bin/env python3
# --------------------- #
# -- SEVERAL IMPORTS -- #
# --------------------- #
from pathlib import Path
from pytest import fixture
from orpyste.data import ReadBlock as READ
# ------------------- #
# -- MODULE TESTED -- #
# ------------------- #
from mistool import python_use
# ----------------------- #
# -- GENERAL CONSTANTS -- #
# ----------------------- #
THIS_DIR = Path(__file__).parent
DICT_VALUES_FUNCTION = python_use.dictvalues
# ----------------------- #
# -- DATAS FOR TESTING -- #
# ----------------------- #
THE_DATAS_FOR_TESTING = READ(
content = THIS_DIR / 'dictvalues.txt',
mode = {"keyval:: =": ":default:"}
)
@fixture(scope="module")
def or_datas(request):
THE_DATAS_FOR_TESTING.build()
def remove_extras():
THE_DATAS_FOR_TESTING.remove_extras()
request.addfinalizer(remove_extras)
# ------------- #
# -- QUOTING -- #
# ------------- #
def test_python_use_dictvalues(or_datas):
tests = THE_DATAS_FOR_TESTING.mydict("std nosep nonb")
for testname, infos in tests.items():
onedict = infos['onedict']
onedict = eval(onedict)
singlevalues_wanted = infos['singlevalues']
singlevalues_wanted = eval(singlevalues_wanted)
singlevalues_found = DICT_VALUES_FUNCTION(onedict)
singlevalues_found = sorted(singlevalues_found)
assert singlevalues_wanted == singlevalues_found
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
10652,
9858,
327,
199,
3,
1553,
5795,
2111,
748,
5025,
2596,
51,
1553,
327,
199,
3,
10652,
9858,
327,
199,
199,
504,
32212,
492,
6912,
199,
504,
4613,
492,
10949,
199,
199,
504,
503,
15983,
266,
14,
576,
492,
5574,
3142,
465,
16767,
421,
199,
3,
10652,
2595,
327,
199,
3,
1553,
30223,
7393,
1149,
1553,
327,
199,
3,
10652,
2595,
327,
199,
199,
504,
333,
7133,
393,
492,
2366,
63,
1180,
421,
199,
3,
10652,
12797,
327,
199,
3,
1553,
29087,
748,
21803,
1441,
51,
1553,
327,
199,
3,
10652,
12797,
327,
199,
199,
24571,
63,
3022,
275,
6912,
3460,
493,
28634,
1708,
199,
199,
12511,
63,
15514,
63,
15476,
275,
2366,
63,
1180,
14,
807,
1459,
421,
199,
3,
10652,
12797,
327,
199,
3,
1553,
17971,
1179,
2381,
7393,
1206,
1553,
327,
199,
3,
10652,
12797,
327,
199,
199,
18061,
63,
28231,
63,
2707,
63,
2864,
1206,
275,
16767,
8,
272,
1564,
275,
5749,
63,
3022,
1182,
283,
807,
1459,
14,
2424,
297,
272,
818,
259,
275,
2420,
31217,
447,
275,
582,
7244,
885,
26,
3570,
199,
9,
199,
199,
32,
5997,
8,
2645,
628,
578,
531,
199,
318,
503,
63,
11563,
8,
1069,
304,
272,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
1506,
342,
339,
347,
2813,
63,
9975,
837,
267,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
2168,
63,
9975,
342,
339,
1056,
14,
525,
30092,
8,
2168,
63,
9975,
9,
421,
199,
3,
3001,
9858,
327,
199,
3,
1553,
11364,
1206,
1553,
327,
199,
3,
3001,
9858,
327,
199,
199,
318,
511,
63,
1548,
63,
1180,
63,
807,
1459,
8,
269,
63,
11563,
304,
272,
2295,
275,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
1662,
807,
480,
1516,
949,
4127,
2222,
66,
531,
339,
367,
511,
354,
12,
24485,
315,
2295,
14,
1744,
837,
267,
1373,
807,
275,
24485,
459,
368,
807,
418,
267,
1373,
807,
275,
3468,
8,
368,
807,
9,
398,
2849,
1459,
63,
19361,
275,
24485,
459,
4780,
1459,
418,
267,
2849,
1459,
63,
19361,
275,
3468,
8,
4780,
1459,
63,
19361,
9,
398,
2849,
1459,
63,
4214,
275,
577,
6196,
63,
15514,
63,
15476,
8,
368,
807,
9,
267,
2849,
1459,
63,
4214,
275,
3355,
8,
4780,
1459,
63,
4214,
9,
398,
702,
2849,
1459,
63,
19361,
508,
2849,
1459,
63,
4214,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
19,
199,
199,
3,
10652,
9858,
327,
199,
3,
1553,
5795,
2111,
748,
5025,
2596,
51,
1553,
327,
199,
3,
10652,
9858,
327,
199,
199,
504,
32212,
492,
6912,
199,
504,
4613,
492,
10949,
199,
199,
504,
503,
15983,
266,
14,
576,
492,
5574,
3142,
465,
16767,
421,
199,
3,
10652,
2595,
327,
199,
3,
1553,
30223,
7393,
1149,
1553,
327,
199,
3,
10652,
2595,
327,
199,
199,
504,
333,
7133,
393,
492,
2366,
63,
1180,
421,
199,
3,
10652,
12797,
327,
199,
3,
1553,
29087,
748,
21803,
1441,
51,
1553,
327,
199,
3,
10652,
12797,
327,
199,
199,
24571,
63,
3022,
275,
6912,
3460,
493,
28634,
1708,
199,
199,
12511,
63,
15514,
63,
15476,
275,
2366,
63,
1180,
14,
807,
1459,
421,
199,
3,
10652,
12797,
327,
199,
3,
1553,
17971,
1179,
2381,
7393,
1206,
1553,
327,
199,
3,
10652,
12797,
327,
199,
199,
18061,
63,
28231,
63,
2707,
63,
2864,
1206,
275,
16767,
8,
272,
1564,
275,
5749,
63,
3022,
1182,
283,
807,
1459,
14,
2424,
297,
272,
818,
259,
275,
2420,
31217,
447,
275,
582,
7244,
885,
26,
3570,
199,
9,
199,
199,
32,
5997,
8,
2645,
628,
578,
531,
199,
318,
503,
63,
11563,
8,
1069,
304,
272,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
1506,
342,
339,
347,
2813,
63,
9975,
837,
267,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
2168,
63,
9975,
342,
339,
1056,
14,
525,
30092,
8,
2168,
63,
9975,
9,
421,
199,
3,
3001,
9858,
327,
199,
3,
1553,
11364,
1206,
1553,
327,
199,
3,
3001,
9858,
327,
199,
199,
318,
511,
63,
1548,
63,
1180,
63,
807,
1459,
8,
269,
63,
11563,
304,
272,
2295,
275,
2334,
63,
28231,
63,
2707,
63,
2864,
1206,
14,
1662,
807,
480,
1516,
949,
4127,
2222,
66,
531,
339,
367,
511,
354,
12,
24485,
315,
2295,
14,
1744,
837,
267,
1373,
807,
275,
24485,
459,
368,
807,
418,
267,
1373,
807,
275,
3468,
8,
368,
807,
9,
398,
2849,
1459,
63,
19361,
275,
24485,
459,
4780,
1459,
418,
267,
2849,
1459,
63,
19361,
275,
3468,
8,
4780,
1459,
63,
19361,
9,
398,
2849,
1459,
63,
4214,
275,
577,
6196,
63,
15514,
63,
15476,
8,
368,
807,
9,
267,
2849,
1459,
63,
4214,
275,
3355,
8,
4780,
1459,
63,
4214,
9,
398,
702,
2849,
1459,
63,
19361,
508,
2849,
1459,
63,
4214,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
mdanielwork/intellij-community
|
python/helpers/sphinxcontrib/napoleon/docstring.py
|
44
|
32526
|
# -*- coding: utf-8 -*-
# Copyright 2014 Rob Ruana
# Licensed under the BSD License, see LICENSE file for details.
"""Classes for docstring parsing and formatting."""
import collections
import inspect
import re
import sys
from six.moves import range
from pockets import modify_iter
from six import string_types
_directive_regex = re.compile(r'\.\. \S+::')
_google_section_regex = re.compile(r'^(\s|\w)+:\s*$')
_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.+?)\s*\)')
_numpy_section_regex = re.compile(r'^[=\-`:\'"~^_*+#<>]{2,}\s*$')
_xref_regex = re.compile(r'(:\w+:\S+:`.+?`|:\S+:`.+?`|`.+?`)')
class GoogleDocstring(object):
"""Convert Google style docstrings to reStructuredText.
Parameters
----------
docstring : str or List[str]
The docstring to parse, given either as a string or split into
individual lines.
config : Optional[sphinxcontrib.napoleon.Config or sphinx.config.Config]
The configuration settings to use. If not given, defaults to the
config object on `app`; or if `app` is not given defaults to the
a new `sphinxcontrib.napoleon.Config` object.
See Also
--------
:class:`sphinxcontrib.napoleon.Config`
Other Parameters
----------------
app : Optional[sphinx.application.Sphinx]
Application object representing the Sphinx process.
what : Optional[str]
A string specifying the type of the object to which the docstring
belongs. Valid values: "module", "class", "exception", "function",
"method", "attribute".
name : Optional[str]
The fully qualified name of the object.
obj : module, class, exception, function, method, or attribute
The object to which the docstring belongs.
options : Optional[sphinx.ext.autodoc.Options]
The options given to the directive: an object with attributes
inherited_members, undoc_members, show_inheritance and noindex that
are True if the flag option of same name was given to the auto
directive.
Example
-------
>>> from sphinxcontrib.napoleon import Config
>>> config = Config(napoleon_use_param=True, napoleon_use_rtype=True)
>>> docstring = '''One line summary.
...
... Extended description.
...
... Args:
... arg1(int): Description of `arg1`
... arg2(str): Description of `arg2`
... Returns:
... str: Description of return value.
... '''
>>> print(GoogleDocstring(docstring, config))
One line summary.
<BLANKLINE>
Extended description.
<BLANKLINE>
:param arg1: Description of `arg1`
:type arg1: int
:param arg2: Description of `arg2`
:type arg2: str
<BLANKLINE>
:returns: Description of return value.
:rtype: str
<BLANKLINE>
"""
def __init__(self, docstring, config=None, app=None, what='', name='',
obj=None, options=None):
self._config = config
self._app = app
if not self._config:
from sphinxcontrib.napoleon import Config
self._config = self._app and self._app.config or Config()
if not what:
if inspect.isclass(obj):
what = 'class'
elif inspect.ismodule(obj):
what = 'module'
elif isinstance(obj, collections.Callable):
what = 'function'
else:
what = 'object'
self._what = what
self._name = name
self._obj = obj
self._opt = options
if isinstance(docstring, string_types):
docstring = docstring.splitlines()
self._lines = docstring
self._line_iter = modify_iter(docstring, modifier=lambda s: s.rstrip())
self._parsed_lines = []
self._is_in_section = False
self._section_indent = 0
if not hasattr(self, '_directive_sections'):
self._directive_sections = []
if not hasattr(self, '_sections'):
self._sections = {
'args': self._parse_parameters_section,
'arguments': self._parse_parameters_section,
'attributes': self._parse_attributes_section,
'example': self._parse_examples_section,
'examples': self._parse_examples_section,
'keyword args': self._parse_keyword_arguments_section,
'keyword arguments': self._parse_keyword_arguments_section,
'methods': self._parse_methods_section,
'note': self._parse_note_section,
'notes': self._parse_notes_section,
'other parameters': self._parse_other_parameters_section,
'parameters': self._parse_parameters_section,
'return': self._parse_returns_section,
'returns': self._parse_returns_section,
'raises': self._parse_raises_section,
'references': self._parse_references_section,
'see also': self._parse_see_also_section,
'warning': self._parse_warning_section,
'warnings': self._parse_warning_section,
'warns': self._parse_warns_section,
'yield': self._parse_yields_section,
'yields': self._parse_yields_section,
}
self._parse()
def __str__(self):
"""Return the parsed docstring in reStructuredText format.
Returns
-------
str
UTF-8 encoded version of the docstring.
"""
if sys.version_info[0] >= 3:
return self.__unicode__()
else:
return self.__unicode__().encode('utf8')
def __unicode__(self):
"""Return the parsed docstring in reStructuredText format.
Returns
-------
unicode
Unicode version of the docstring.
"""
return u'\n'.join(self.lines())
def lines(self):
"""Return the parsed lines of the docstring in reStructuredText format.
Returns
-------
List[str]
The lines of the docstring in a list.
"""
return self._parsed_lines
def _consume_indented_block(self, indent=1):
lines = []
line = self._line_iter.peek()
while(not self._is_section_break() and
(not line or self._is_indented(line, indent))):
lines.append(next(self._line_iter))
line = self._line_iter.peek()
return lines
def _consume_contiguous(self):
lines = []
while (self._line_iter.has_next() and
self._line_iter.peek() and
not self._is_section_header()):
lines.append(next(self._line_iter))
return lines
def _consume_empty(self):
lines = []
line = self._line_iter.peek()
while self._line_iter.has_next() and not line:
lines.append(next(self._line_iter))
line = self._line_iter.peek()
return lines
def _consume_field(self, parse_type=True, prefer_type=False):
line = next(self._line_iter)
before, colon, after = self._partition_field_on_colon(line)
_name, _type, _desc = before, '', after
if parse_type:
match = _google_typed_arg_regex.match(before)
if match:
_name = match.group(1)
_type = match.group(2)
if _name[:2] == '**':
_name = r'\*\*'+_name[2:]
elif _name[:1] == '*':
_name = r'\*'+_name[1:]
if prefer_type and not _type:
_type, _name = _name, _type
indent = self._get_indent(line) + 1
_desc = [_desc] + self._dedent(self._consume_indented_block(indent))
_desc = self.__class__(_desc, self._config).lines()
return _name, _type, _desc
def _consume_fields(self, parse_type=True, prefer_type=False):
self._consume_empty()
fields = []
while not self._is_section_break():
_name, _type, _desc = self._consume_field(parse_type, prefer_type)
if _name or _type or _desc:
fields.append((_name, _type, _desc,))
return fields
def _consume_inline_attribute(self):
line = next(self._line_iter)
_type, colon, _desc = self._partition_field_on_colon(line)
if not colon:
_type, _desc = _desc, _type
_desc = [_desc] + self._dedent(self._consume_to_end())
_desc = self.__class__(_desc, self._config).lines()
return _type, _desc
def _consume_returns_section(self):
lines = self._dedent(self._consume_to_next_section())
if lines:
before, colon, after = self._partition_field_on_colon(lines[0])
_name, _type, _desc = '', '', lines
if colon:
if after:
_desc = [after] + lines[1:]
else:
_desc = lines[1:]
match = _google_typed_arg_regex.match(before)
if match:
_name = match.group(1)
_type = match.group(2)
else:
_type = before
_desc = self.__class__(_desc, self._config).lines()
return [(_name, _type, _desc,)]
else:
return []
def _consume_usage_section(self):
lines = self._dedent(self._consume_to_next_section())
return lines
def _consume_section_header(self):
section = next(self._line_iter)
stripped_section = section.strip(':')
if stripped_section.lower() in self._sections:
section = stripped_section
return section
def _consume_to_end(self):
lines = []
while self._line_iter.has_next():
lines.append(next(self._line_iter))
return lines
def _consume_to_next_section(self):
self._consume_empty()
lines = []
while not self._is_section_break():
lines.append(next(self._line_iter))
return lines + self._consume_empty()
def _dedent(self, lines, full=False):
if full:
return [line.lstrip() for line in lines]
else:
min_indent = self._get_min_indent(lines)
return [line[min_indent:] for line in lines]
def _format_admonition(self, admonition, lines):
lines = self._strip_empty(lines)
if len(lines) == 1:
return ['.. %s:: %s' % (admonition, lines[0].strip()), '']
elif lines:
lines = self._indent(self._dedent(lines), 3)
return ['.. %s::' % admonition, ''] + lines + ['']
else:
return ['.. %s::' % admonition, '']
def _format_block(self, prefix, lines, padding=None):
if lines:
if padding is None:
padding = ' ' * len(prefix)
result_lines = []
for i, line in enumerate(lines):
if i == 0:
result_lines.append((prefix + line).rstrip())
elif line:
result_lines.append(padding + line)
else:
result_lines.append('')
return result_lines
else:
return [prefix]
def _format_field(self, _name, _type, _desc):
_desc = self._strip_empty(_desc)
has_desc = any(_desc)
separator = has_desc and ' -- ' or ''
if _name:
if _type:
if '`' in _type:
field = '**%s** (%s)%s' % (_name, _type, separator)
else:
field = '**%s** (*%s*)%s' % (_name, _type, separator)
else:
field = '**%s**%s' % (_name, separator)
elif _type:
if '`' in _type:
field = '%s%s' % (_type, separator)
else:
field = '*%s*%s' % (_type, separator)
else:
field = ''
if has_desc:
return [field + _desc[0]] + _desc[1:]
else:
return [field]
def _format_fields(self, field_type, fields):
field_type = ':%s:' % field_type.strip()
padding = ' ' * len(field_type)
multi = len(fields) > 1
lines = []
for _name, _type, _desc in fields:
field = self._format_field(_name, _type, _desc)
if multi:
if lines:
lines.extend(self._format_block(padding + ' * ', field))
else:
lines.extend(self._format_block(field_type + ' * ', field))
else:
lines.extend(self._format_block(field_type + ' ', field))
if lines and lines[-1]:
lines.append('')
return lines
def _get_current_indent(self, peek_ahead=0):
line = self._line_iter.peek(peek_ahead + 1)[peek_ahead]
while line != self._line_iter.sentinel:
if line:
return self._get_indent(line)
peek_ahead += 1
line = self._line_iter.peek(peek_ahead + 1)[peek_ahead]
return 0
def _get_indent(self, line):
for i, s in enumerate(line):
if not s.isspace():
return i
return len(line)
def _get_min_indent(self, lines):
min_indent = None
for line in lines:
if line:
indent = self._get_indent(line)
if min_indent is None:
min_indent = indent
elif indent < min_indent:
min_indent = indent
return min_indent or 0
def _indent(self, lines, n=4):
return [(' ' * n) + line for line in lines]
def _is_indented(self, line, indent=1):
for i, s in enumerate(line):
if i >= indent:
return True
elif not s.isspace():
return False
return False
def _is_section_header(self):
section = self._line_iter.peek().lower()
match = _google_section_regex.match(section)
if match and section.strip(':') in self._sections:
header_indent = self._get_indent(section)
section_indent = self._get_current_indent(peek_ahead=1)
return section_indent > header_indent
elif self._directive_sections:
if _directive_regex.match(section):
for directive_section in self._directive_sections:
if section.startswith(directive_section):
return True
return False
def _is_section_break(self):
line = self._line_iter.peek()
return (not self._line_iter.has_next() or
self._is_section_header() or
(self._is_in_section and
line and
not self._is_indented(line, self._section_indent)))
def _parse(self):
self._parsed_lines = self._consume_empty()
if self._name and (self._what == 'attribute' or self._what == 'data'):
self._parsed_lines.extend(self._parse_attribute_docstring())
return
while self._line_iter.has_next():
if self._is_section_header():
try:
section = self._consume_section_header()
self._is_in_section = True
self._section_indent = self._get_current_indent()
if _directive_regex.match(section):
lines = [section] + self._consume_to_next_section()
else:
lines = self._sections[section.lower()](section)
finally:
self._is_in_section = False
self._section_indent = 0
else:
if not self._parsed_lines:
lines = self._consume_contiguous() + self._consume_empty()
else:
lines = self._consume_to_next_section()
self._parsed_lines.extend(lines)
def _parse_attribute_docstring(self):
_type, _desc = self._consume_inline_attribute()
return self._format_field('', _type, _desc)
def _parse_attributes_section(self, section):
lines = []
for _name, _type, _desc in self._consume_fields():
if self._config.napoleon_use_ivar:
field = ':ivar %s: ' % _name
lines.extend(self._format_block(field, _desc))
if _type:
lines.append(':vartype %s: %s' % (_name, _type))
else:
lines.extend(['.. attribute:: ' + _name, ''])
field = self._format_field('', _type, _desc)
lines.extend(self._indent(field, 3))
lines.append('')
if self._config.napoleon_use_ivar:
lines.append('')
return lines
def _parse_examples_section(self, section):
use_admonition = self._config.napoleon_use_admonition_for_examples
return self._parse_generic_section(section, use_admonition)
def _parse_usage_section(self, section):
header = ['.. rubric:: Usage:', '']
block = ['.. code-block:: python', '']
lines = self._consume_usage_section()
lines = self._indent(lines, 3)
return header + block + lines + ['']
def _parse_generic_section(self, section, use_admonition):
lines = self._strip_empty(self._consume_to_next_section())
lines = self._dedent(lines)
if use_admonition:
header = '.. admonition:: %s' % section
lines = self._indent(lines, 3)
else:
header = '.. rubric:: %s' % section
if lines:
return [header, ''] + lines + ['']
else:
return [header, '']
def _parse_keyword_arguments_section(self, section):
return self._format_fields('Keyword Arguments', self._consume_fields())
def _parse_methods_section(self, section):
lines = []
for _name, _, _desc in self._consume_fields(parse_type=False):
lines.append('.. method:: %s' % _name)
if _desc:
lines.extend([''] + self._indent(_desc, 3))
lines.append('')
return lines
def _parse_note_section(self, section):
lines = self._consume_to_next_section()
return self._format_admonition('note', lines)
def _parse_notes_section(self, section):
use_admonition = self._config.napoleon_use_admonition_for_notes
return self._parse_generic_section('Notes', use_admonition)
def _parse_other_parameters_section(self, section):
return self._format_fields('Other Parameters', self._consume_fields())
def _parse_parameters_section(self, section):
fields = self._consume_fields()
if self._config.napoleon_use_param:
lines = []
for _name, _type, _desc in fields:
field = ':param %s: ' % _name
lines.extend(self._format_block(field, _desc))
if _type:
lines.append(':type %s: %s' % (_name, _type))
return lines + ['']
else:
return self._format_fields('Parameters', fields)
def _parse_raises_section(self, section):
fields = self._consume_fields(parse_type=False, prefer_type=True)
field_type = ':raises:'
padding = ' ' * len(field_type)
multi = len(fields) > 1
lines = []
for _, _type, _desc in fields:
_desc = self._strip_empty(_desc)
has_desc = any(_desc)
separator = has_desc and ' -- ' or ''
if _type:
has_refs = '`' in _type or ':' in _type
has_space = any(c in ' \t\n\v\f ' for c in _type)
if not has_refs and not has_space:
_type = ':exc:`%s`%s' % (_type, separator)
elif has_desc and has_space:
_type = '*%s*%s' % (_type, separator)
else:
_type = '%s%s' % (_type, separator)
if has_desc:
field = [_type + _desc[0]] + _desc[1:]
else:
field = [_type]
else:
field = _desc
if multi:
if lines:
lines.extend(self._format_block(padding + ' * ', field))
else:
lines.extend(self._format_block(field_type + ' * ', field))
else:
lines.extend(self._format_block(field_type + ' ', field))
if lines and lines[-1]:
lines.append('')
return lines
def _parse_references_section(self, section):
use_admonition = self._config.napoleon_use_admonition_for_references
return self._parse_generic_section('References', use_admonition)
def _parse_returns_section(self, section):
fields = self._consume_returns_section()
multi = len(fields) > 1
if multi:
use_rtype = False
else:
use_rtype = self._config.napoleon_use_rtype
lines = []
for _name, _type, _desc in fields:
if use_rtype:
field = self._format_field(_name, '', _desc)
else:
field = self._format_field(_name, _type, _desc)
if multi:
if lines:
lines.extend(self._format_block(' * ', field))
else:
lines.extend(self._format_block(':returns: * ', field))
else:
lines.extend(self._format_block(':returns: ', field))
if _type and use_rtype:
lines.extend([':rtype: %s' % _type, ''])
if lines and lines[-1]:
lines.append('')
return lines
def _parse_see_also_section(self, section):
lines = self._consume_to_next_section()
return self._format_admonition('seealso', lines)
def _parse_warning_section(self, section):
lines = self._consume_to_next_section()
return self._format_admonition('warning', lines)
def _parse_warns_section(self, section):
return self._format_fields('Warns', self._consume_fields())
def _parse_yields_section(self, section):
fields = self._consume_returns_section()
return self._format_fields('Yields', fields)
def _partition_field_on_colon(self, line):
before_colon = []
after_colon = []
colon = ''
found_colon = False
for i, source in enumerate(_xref_regex.split(line)):
if found_colon:
after_colon.append(source)
else:
if (i % 2) == 0 and ":" in source:
found_colon = True
before, colon, after = source.partition(":")
before_colon.append(before)
after_colon.append(after)
else:
before_colon.append(source)
return ("".join(before_colon).strip(),
colon,
"".join(after_colon).strip())
def _strip_empty(self, lines):
if lines:
start = -1
for i, line in enumerate(lines):
if line:
start = i
break
if start == -1:
lines = []
end = -1
for i in reversed(range(len(lines))):
line = lines[i]
if line:
end = i
break
if start > 0 or end + 1 < len(lines):
lines = lines[start:end + 1]
return lines
class NumpyDocstring(GoogleDocstring):
"""Convert NumPy style docstrings to reStructuredText.
Parameters
----------
docstring : str or List[str]
The docstring to parse, given either as a string or split into
individual lines.
config : Optional[sphinxcontrib.napoleon.Config or sphinx.config.Config]
The configuration settings to use. If not given, defaults to the
config object on `app`; or if `app` is not given defaults to the
a new `sphinxcontrib.napoleon.Config` object.
See Also
--------
:class:`sphinxcontrib.napoleon.Config`
Other Parameters
----------------
app : Optional[sphinx.application.Sphinx]
Application object representing the Sphinx process.
what : Optional[str]
A string specifying the type of the object to which the docstring
belongs. Valid values: "module", "class", "exception", "function",
"method", "attribute".
name : Optional[str]
The fully qualified name of the object.
obj : module, class, exception, function, method, or attribute
The object to which the docstring belongs.
options : Optional[sphinx.ext.autodoc.Options]
The options given to the directive: an object with attributes
inherited_members, undoc_members, show_inheritance and noindex that
are True if the flag option of same name was given to the auto
directive.
Example
-------
>>> from sphinxcontrib.napoleon import Config
>>> config = Config(napoleon_use_param=True, napoleon_use_rtype=True)
>>> docstring = '''One line summary.
...
... Extended description.
...
... Parameters
... ----------
... arg1 : int
... Description of `arg1`
... arg2 : str
... Description of `arg2`
... Returns
... -------
... str
... Description of return value.
... '''
>>> print(NumpyDocstring(docstring, config))
One line summary.
<BLANKLINE>
Extended description.
<BLANKLINE>
:param arg1: Description of `arg1`
:type arg1: int
:param arg2: Description of `arg2`
:type arg2: str
<BLANKLINE>
:returns: Description of return value.
:rtype: str
<BLANKLINE>
Methods
-------
__str__()
Return the parsed docstring in reStructuredText format.
Returns
-------
str
UTF-8 encoded version of the docstring.
__unicode__()
Return the parsed docstring in reStructuredText format.
Returns
-------
unicode
Unicode version of the docstring.
lines()
Return the parsed lines of the docstring in reStructuredText format.
Returns
-------
List[str]
The lines of the docstring in a list.
"""
def __init__(self, docstring, config=None, app=None, what='', name='',
obj=None, options=None):
self._directive_sections = ['.. index::']
super(NumpyDocstring, self).__init__(docstring, config, app, what,
name, obj, options)
def _consume_field(self, parse_type=True, prefer_type=False):
line = next(self._line_iter)
if parse_type:
_name, _, _type = self._partition_field_on_colon(line)
else:
_name, _type = line, ''
_name, _type = _name.strip(), _type.strip()
if prefer_type and not _type:
_type, _name = _name, _type
if _name[:2] == '**':
_name = r'\*\*'+_name[2:]
elif _name[:1] == '*':
_name = r'\*'+_name[1:]
indent = self._get_indent(line)
_desc = self._dedent(self._consume_indented_block(indent + 1))
_desc = self.__class__(_desc, self._config).lines()
return _name, _type, _desc
def _consume_returns_section(self):
return self._consume_fields(prefer_type=True)
def _consume_section_header(self):
section = next(self._line_iter)
if not _directive_regex.match(section):
# Consume the header underline
next(self._line_iter)
return section
def _is_section_break(self):
line1, line2 = self._line_iter.peek(2)
return (not self._line_iter.has_next() or
self._is_section_header() or
['', ''] == [line1, line2] or
(self._is_in_section and
line1 and
not self._is_indented(line1, self._section_indent)))
def _is_section_header(self):
section, underline = self._line_iter.peek(2)
section = section.lower()
if section in self._sections and isinstance(underline, string_types):
return bool(_numpy_section_regex.match(underline))
elif self._directive_sections:
if _directive_regex.match(section):
for directive_section in self._directive_sections:
if section.startswith(directive_section):
return True
return False
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`|"
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
def _parse_see_also_section(self, section):
lines = self._consume_to_next_section()
try:
return self._parse_numpydoc_see_also_section(lines)
except ValueError:
return self._format_admonition('seealso', lines)
def _parse_numpydoc_see_also_section(self, content):
"""
Derived from the NumpyDoc implementation of _parse_see_also.
See Also
--------
func_name : Descriptive text
continued text
another_func_name : Descriptive text
func_name1, func_name2, :meth:`func_name`, func_name3
"""
items = []
def parse_item_name(text):
"""Match ':role:`name`' or 'name'"""
m = self._name_rgx.match(text)
if m:
g = m.groups()
if g[1] is None:
return g[3], None
else:
return g[2], g[1]
raise ValueError("%s is not a item name" % text)
def push_item(name, rest):
if not name:
return
name, role = parse_item_name(name)
items.append((name, list(rest), role))
del rest[:]
current_func = None
rest = []
for line in content:
if not line.strip():
continue
m = self._name_rgx.match(line)
if m and line[m.end():].strip().startswith(':'):
push_item(current_func, rest)
current_func, line = line[:m.end()], line[m.end():]
rest = [line.split(':', 1)[1].strip()]
if not rest[0]:
rest = []
elif not line.startswith(' '):
push_item(current_func, rest)
current_func = None
if ',' in line:
for func in line.split(','):
if func.strip():
push_item(func, [])
elif line.strip():
current_func = line
elif current_func is not None:
rest.append(line.strip())
push_item(current_func, rest)
if not items:
return []
roles = {
'method': 'meth',
'meth': 'meth',
'function': 'func',
'func': 'func',
'class': 'class',
'exception': 'exc',
'exc': 'exc',
'object': 'obj',
'obj': 'obj',
'module': 'mod',
'mod': 'mod',
'data': 'data',
'constant': 'const',
'const': 'const',
'attribute': 'attr',
'attr': 'attr'
}
if self._what is None:
func_role = 'obj'
else:
func_role = roles.get(self._what, '')
lines = []
last_had_desc = True
for func, desc, role in items:
if role:
link = ':%s:`%s`' % (role, func)
elif func_role:
link = ':%s:`%s`' % (func_role, func)
else:
link = "`%s`_" % func
if desc or last_had_desc:
lines += ['']
lines += [link]
else:
lines[-1] += ", %s" % link
if desc:
lines += self._indent([' '.join(desc)])
last_had_desc = True
else:
last_had_desc = False
lines += ['']
return self._format_admonition('seealso', lines)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6927,
820,
2873,
820,
85,
6738,
199,
3,
3909,
1334,
314,
6289,
844,
12,
1937,
5113,
570,
367,
2436,
14,
199,
199,
624,
15711,
367,
9214,
6057,
436,
10803,
1041,
199,
199,
646,
5055,
199,
646,
6485,
199,
646,
295,
199,
646,
984,
199,
504,
3816,
14,
4912,
492,
1425,
199,
199,
504,
299,
1539,
83,
492,
2811,
63,
1661,
199,
504,
3816,
492,
1059,
63,
1313,
199,
199,
63,
15047,
63,
3821,
275,
295,
14,
2014,
8,
82,
1154,
3134,
14,
971,
51,
11,
447,
358,
199,
63,
3098,
63,
2792,
63,
3821,
275,
295,
14,
2014,
8,
82,
31344,
83,
6113,
87,
6393,
3427,
83,
10,
9988,
199,
63,
3098,
63,
22033,
63,
1273,
63,
3821,
275,
295,
14,
2014,
8,
82,
1154,
83,
5830,
11198,
2862,
83,
7590,
2961,
83,
5830,
11198,
2862,
83,
7590,
5942,
199,
63,
4714,
63,
2792,
63,
3821,
275,
295,
14,
2014,
8,
82,
23811,
9529,
13,
64,
3427,
4065,
94,
62,
15192,
11,
3,
16137,
8194,
18,
12,
4988,
83,
10,
9988,
199,
63,
31332,
63,
3821,
275,
295,
14,
2014,
8,
82,
6774,
3427,
87,
11,
3427,
51,
11,
5026,
23778,
64,
92,
3427,
51,
11,
5026,
23778,
64,
92,
2313,
23778,
64,
5942,
421,
199,
533,
4475,
3768,
875,
8,
785,
304,
272,
408,
7306,
4475,
3449,
20964,
370,
295,
27486,
1872,
14,
339,
3897,
272,
4143,
272,
9214,
520,
620,
503,
3820,
59,
495,
61,
267,
710,
9214,
370,
2198,
12,
1627,
1902,
465,
282,
1059,
503,
3715,
1901,
267,
8212,
2385,
14,
272,
1101,
520,
4879,
59,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
503,
15882,
14,
888,
14,
2028,
61,
267,
710,
2897,
2202,
370,
675,
14,
982,
440,
1627,
12,
4243,
370,
314,
267,
1101,
909,
641,
658,
571,
64,
27,
503,
340,
658,
571,
64,
365,
440,
1627,
4243,
370,
314,
267,
282,
892,
658,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
64,
909,
14,
398,
1666,
6121,
267,
3001,
267,
520,
533,
1705,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
64,
339,
5439,
3897,
272,
10652,
272,
1145,
520,
4879,
59,
8008,
14,
3578,
14,
51,
7807,
61,
267,
13515,
909,
6144,
314,
10229,
2112,
14,
272,
4052,
520,
4879,
59,
495,
61,
267,
437,
1059,
9176,
314,
730,
402,
314,
909,
370,
1314,
314,
9214,
267,
15006,
14,
4821,
1338,
26,
298,
578,
401,
298,
533,
401,
298,
1971,
401,
298,
1593,
401,
267,
298,
765,
401,
298,
3215,
1674,
272,
536,
520,
4879,
59,
495,
61,
267,
710,
9999,
12313,
536,
402,
314,
909,
14,
272,
1559,
520,
859,
12,
1021,
12,
1919,
12,
805,
12,
1083,
12,
503,
2225,
267,
710,
909,
370,
1314,
314,
9214,
15006,
14,
272,
1511,
520,
4879,
59,
8008,
14,
832,
14,
28056,
14,
4558,
61,
267,
710,
1511,
1627,
370,
314,
13613,
26,
376,
909,
543,
3004,
267,
12623,
63,
6334,
12,
625,
1301,
63,
6334,
12,
2498,
63,
13136,
436,
949,
1080,
626,
267,
787,
715,
340,
314,
3305,
945,
402,
2011,
536,
1990,
1627,
370,
314,
2599,
267,
13613,
14,
339,
5679,
272,
5514,
272,
1306,
687,
15882,
2828,
14,
2542,
16721,
265,
492,
4094,
272,
1306,
1101,
275,
4094,
8,
2542,
16721,
265,
63,
1180,
63,
635,
29,
549,
12,
302,
439,
16721,
265,
63,
1180,
63,
4500,
29,
549,
9,
272,
1306,
9214,
275,
1449,
4395,
1004,
6212,
14,
272,
2263,
272,
2263,
13706,
1369,
14,
272,
2263,
272,
2263,
3033,
26,
272,
2263,
257,
1680,
17,
8,
442,
304,
11994,
402,
658,
1273,
17,
64,
272,
2263,
257,
1680,
18,
8,
495,
304,
11994,
402,
658,
1273,
18,
64,
272,
2263,
1803,
26,
272,
2263,
257,
620,
26,
11994,
402,
372,
574,
14,
272,
2263,
1449,
272,
1306,
870,
8,
13266,
3768,
875,
8,
12485,
12,
1101,
430,
272,
7309,
1004,
6212,
14,
272,
665,
29353,
30,
272,
13706,
1369,
14,
272,
665,
29353,
30,
272,
520,
635,
1680,
17,
26,
11994,
402,
658,
1273,
17,
64,
272,
520,
466,
1680,
17,
26,
1109,
272,
520,
635,
1680,
18,
26,
11994,
402,
658,
1273,
18,
64,
272,
520,
466,
1680,
18,
26,
620,
272,
665,
29353,
30,
272,
520,
5808,
26,
11994,
402,
372,
574,
14,
272,
520,
4500,
26,
620,
272,
665,
29353,
30,
339,
408,
272,
347,
636,
826,
721,
277,
12,
9214,
12,
1101,
29,
403,
12,
1145,
29,
403,
12,
4052,
4581,
536,
4581,
326,
1559,
29,
403,
12,
1511,
29,
403,
304,
267,
291,
423,
888,
275,
1101,
267,
291,
423,
571,
275,
1145,
398,
340,
440,
291,
423,
888,
26,
288,
687,
15882,
2828,
14,
2542,
16721,
265,
492,
4094,
288,
291,
423,
888,
275,
291,
423,
571,
436,
291,
423,
571,
14,
888,
503,
4094,
342,
398,
340,
440,
4052,
26,
288,
340,
6485,
14,
28450,
8,
1113,
304,
355,
4052,
275,
283,
533,
7,
288,
916,
6485,
14,
374,
578,
8,
1113,
304,
355,
4052,
275,
283,
578,
7,
288,
916,
1228,
8,
1113,
12,
5055,
14,
16410,
304,
355,
4052,
275,
283,
1593,
7,
288,
587,
26,
355,
4052,
275,
283,
785,
7,
398,
291,
423,
10058,
275,
4052,
267,
291,
423,
354,
275,
536,
267,
291,
423,
1113,
275,
1559,
267,
291,
423,
2992,
275,
1511,
267,
340,
1228,
8,
12485,
12,
1059,
63,
1313,
304,
288,
9214,
275,
9214,
14,
7644,
342,
267,
291,
423,
1278,
275,
9214,
267,
291,
423,
604,
63,
1661,
275,
2811,
63,
1661,
8,
12485,
12,
17880,
29,
2734,
308,
26,
308,
14,
6735,
1012,
267,
291,
423,
6751,
63,
1278,
275,
942,
267,
291,
423,
374,
63,
262,
63,
2792,
275,
756,
267,
291,
423,
2792,
63,
3724,
275,
378,
267,
340,
440,
2688,
8,
277,
12,
2513,
15047,
63,
7786,
735,
288,
291,
423,
15047,
63,
7786,
275,
942,
267,
340,
440,
2688,
8,
277,
12,
2513,
7786,
735,
288,
291,
423,
7786,
275,
469,
355,
283,
589,
356,
291,
423,
1122,
63,
3214,
63,
2792,
12,
355,
283,
4958,
356,
291,
423,
1122,
63,
3214,
63,
2792,
12,
355,
283,
2987,
356,
291,
423,
1122,
63,
2987,
63,
2792,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
6927,
820,
2873,
820,
85,
6738,
199,
3,
3909,
1334,
314,
6289,
844,
12,
1937,
5113,
570,
367,
2436,
14,
199,
199,
624,
15711,
367,
9214,
6057,
436,
10803,
1041,
199,
199,
646,
5055,
199,
646,
6485,
199,
646,
295,
199,
646,
984,
199,
504,
3816,
14,
4912,
492,
1425,
199,
199,
504,
299,
1539,
83,
492,
2811,
63,
1661,
199,
504,
3816,
492,
1059,
63,
1313,
199,
199,
63,
15047,
63,
3821,
275,
295,
14,
2014,
8,
82,
1154,
3134,
14,
971,
51,
11,
447,
358,
199,
63,
3098,
63,
2792,
63,
3821,
275,
295,
14,
2014,
8,
82,
31344,
83,
6113,
87,
6393,
3427,
83,
10,
9988,
199,
63,
3098,
63,
22033,
63,
1273,
63,
3821,
275,
295,
14,
2014,
8,
82,
1154,
83,
5830,
11198,
2862,
83,
7590,
2961,
83,
5830,
11198,
2862,
83,
7590,
5942,
199,
63,
4714,
63,
2792,
63,
3821,
275,
295,
14,
2014,
8,
82,
23811,
9529,
13,
64,
3427,
4065,
94,
62,
15192,
11,
3,
16137,
8194,
18,
12,
4988,
83,
10,
9988,
199,
63,
31332,
63,
3821,
275,
295,
14,
2014,
8,
82,
6774,
3427,
87,
11,
3427,
51,
11,
5026,
23778,
64,
92,
3427,
51,
11,
5026,
23778,
64,
92,
2313,
23778,
64,
5942,
421,
199,
533,
4475,
3768,
875,
8,
785,
304,
272,
408,
7306,
4475,
3449,
20964,
370,
295,
27486,
1872,
14,
339,
3897,
272,
4143,
272,
9214,
520,
620,
503,
3820,
59,
495,
61,
267,
710,
9214,
370,
2198,
12,
1627,
1902,
465,
282,
1059,
503,
3715,
1901,
267,
8212,
2385,
14,
272,
1101,
520,
4879,
59,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
503,
15882,
14,
888,
14,
2028,
61,
267,
710,
2897,
2202,
370,
675,
14,
982,
440,
1627,
12,
4243,
370,
314,
267,
1101,
909,
641,
658,
571,
64,
27,
503,
340,
658,
571,
64,
365,
440,
1627,
4243,
370,
314,
267,
282,
892,
658,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
64,
909,
14,
398,
1666,
6121,
267,
3001,
267,
520,
533,
1705,
8008,
2828,
14,
2542,
16721,
265,
14,
2028,
64,
339,
5439,
3897,
272,
10652,
272,
1145,
520,
4879,
59,
8008,
14,
3578,
14,
51,
7807,
61,
267,
13515,
909,
6144,
314,
10229,
2112,
14,
272,
4052,
520,
4879,
59,
495,
61,
267,
437,
1059,
9176,
314,
730,
402,
314,
909,
370,
1314,
314,
9214,
267,
15006,
14,
4821,
1338,
26,
298,
578,
401,
298,
533,
401,
298,
1971,
401,
298,
1593,
401,
267,
298,
765,
401,
298,
3215,
1674,
272,
536,
520,
4879,
59,
495,
61,
267,
710,
9999,
12313,
536,
402,
314,
909,
14,
272,
1559,
520,
859,
12,
1021,
12,
1919,
12,
805,
12,
1083,
12,
503,
2225,
267,
710,
909,
370,
1314,
314,
9214,
15006,
14,
272,
1511,
520,
4879,
59,
8008,
14,
832,
14,
28056,
14,
4558,
61,
267,
710,
1511,
1627,
370,
314,
13613,
26,
376,
909,
543,
3004,
267,
12623,
63,
6334,
12,
625,
1301,
63,
6334,
12,
2498,
63,
13136,
436,
949,
1080,
626,
267,
787,
715,
340,
314,
3305,
945,
402,
2011,
536,
1990,
1627,
370,
314,
2599,
267,
13613,
14,
339,
5679,
272,
5514,
272,
1306,
687,
15882,
2828,
14,
2542,
16721,
265,
492,
4094,
272,
1306,
1101,
275,
4094,
8,
2542,
16721,
265,
63,
1180,
63,
635,
29,
549,
12,
302,
439,
16721,
265,
63,
1180,
63,
4500,
29,
549,
9,
272,
1306,
9214,
275,
1449,
4395,
1004,
6212,
14,
272,
2263,
272,
2263,
13706,
1369,
14,
272,
2263,
272,
2263,
3033,
26,
272,
2263,
257,
1680,
17,
8,
442,
304,
11994,
402,
658,
1273,
17,
64,
272,
2263,
257,
1680,
18,
8,
495,
304,
11994,
402,
658,
1273,
18,
64,
272,
2263,
1803,
26,
272,
2263,
257,
620,
26,
11994,
402,
372,
574,
14,
272,
2263,
1449,
272,
1306,
870,
8,
13266,
3768,
875,
8,
12485,
12,
1101,
430,
272,
7309,
1004,
6212,
14,
272,
665,
29353,
30,
272,
13706,
1369,
14,
272,
665,
29353,
30,
272,
520,
635,
1680,
17,
26,
11994,
402,
658,
1273,
17,
64,
272,
520,
466,
1680,
17,
26,
1109,
272,
520,
635,
1680,
18,
26,
11994,
402,
658,
1273,
18,
64,
272,
520,
466,
1680,
18,
26,
620,
272,
665,
29353,
30,
272,
520,
5808,
26,
11994,
402,
372,
574,
14,
272,
520,
4500,
26,
620,
272,
665,
29353,
30,
339,
408,
272,
347,
636,
826,
721,
277,
12,
9214,
12,
1101,
29,
403,
12,
1145,
29,
403,
12,
4052,
4581,
536,
4581,
326,
1559,
29,
403,
12,
1511,
29,
403,
304,
267,
291,
423,
888,
275,
1101,
267,
291,
423,
571,
275,
1145,
398,
340,
440,
291,
423,
888,
26,
288,
687,
15882,
2828,
14,
2542,
16721,
265,
492,
4094,
288,
291,
423,
888,
275,
291,
423,
571,
436,
291,
423,
571,
14,
888,
503,
4094,
342,
398,
340,
440,
4052,
26,
288,
340,
6485,
14,
28450,
8,
1113,
304,
355,
4052,
275,
283,
533,
7,
288,
916,
6485,
14,
374,
578,
8,
1113,
304,
355,
4052,
275,
283,
578,
7,
288,
916,
1228,
8,
1113,
12,
5055,
14,
16410,
304,
355,
4052,
275,
283,
1593,
7,
288,
587,
26,
355,
4052,
275,
283,
785,
7,
398,
291,
423,
10058,
275,
4052,
267,
291,
423,
354,
275,
536,
267,
291,
423,
1113,
275,
1559,
267,
291,
423,
2992,
275,
1511,
267,
340,
1228,
8,
12485,
12,
1059,
63,
1313,
304,
288,
9214,
275,
9214,
14,
7644,
342,
267,
291,
423,
1278,
275,
9214,
267,
291,
423,
604,
63,
1661,
275,
2811,
63,
1661,
8,
12485,
12,
17880,
29,
2734,
308,
26,
308,
14,
6735,
1012,
267,
291,
423,
6751,
63,
1278,
275,
942,
267,
291,
423,
374,
63,
262,
63,
2792,
275,
756,
267,
291,
423,
2792,
63,
3724,
275,
378,
267,
340,
440,
2688,
8,
277,
12,
2513,
15047,
63,
7786,
735,
288,
291,
423,
15047,
63,
7786,
275,
942,
267,
340,
440,
2688,
8,
277,
12,
2513,
7786,
735,
288,
291,
423,
7786,
275,
469,
355,
283,
589,
356,
291,
423,
1122,
63,
3214,
63,
2792,
12,
355,
283,
4958,
356,
291,
423,
1122,
63,
3214,
63,
2792,
12,
355,
283,
2987,
356,
291,
423,
1122,
63,
2987,
63,
2792,
12,
0
] |
[
1,
1,
1,
1,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ctf
|
dist/scaffold15.py
|
4
|
9186
|
# This binary takes both an integer and a string as a parameter. A certain
# integer input causes the program to reach a buffer overflow with which we can
# read a string from an arbitrary memory location. Our goal is to use Angr to
# search the program for this buffer overflow and then automatically generate
# an exploit to read the string "Good Job."
#
# What is the point of reading the string "Good Job."?
# This CTF attempts to replicate a simplified version of a possible vulnerability
# where a user can exploit the program to print a secret, such as a password or
# a private key. In order to keep consistency with the other challenges and to
# simplify the challenge, the goal of this program will be to print "Good Job."
# instead.
#
# The general strategy for crafting this script will be to:
# 1) Search for calls of the 'puts' function, which will eventually be exploited
# to print out "Good Job."
# 2) Determine if the first parameter of 'puts', a pointer to the string to be
# printed, can be controlled by the user to be set to the location of the
# "Good Job." string.
# 3) Solve for the input that prints "Good Job."
#
# Note: The script is structured to implement step #2 before #1.
# Some of the source code for this challenge:
#
# #include <stdio.h>
# #include <stdlib.h>
# #include <string.h>
# #include <stdint.h>
#
# // This will all be in .rodata
# char msg[] = "${ description }$";
# char* try_again = "Try again.";
# char* good_job = "Good Job.";
# uint32_t key;
#
# void print_msg() {
# printf("%s", msg);
# }
#
# uint32_t complex_function(uint32_t input) {
# ...
# }
#
# struct overflow_me {
# char buffer[16];
# char* to_print;
# };
#
# int main(int argc, char* argv[]) {
# struct overflow_me locals;
# locals.to_print = try_again;
#
# print_msg();
#
# printf("Enter the password: ");
# scanf("%u %20s", &key, locals.buffer);
#
# key = complex_function(key);
#
# switch (key) {
# case ?:
# puts(try_again);
# break;
#
# ...
#
# case ?:
# // Our goal is to trick this call to puts to print the "secret
# // password" (which happens, in our case, to be the string
# // "Good Job.")
# puts(locals.to_print);
# break;
#
# ...
# }
#
# return 0;
# }
import angr
import claripy
import sys
def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
# You can either use a blank state or an entry state; just make sure to start
# at the beginning of the program.
# (!)
initial_state = ???
# Again, scanf needs to be replaced.
class ReplacementScanf(angr.SimProcedure):
# Hint: scanf("%u %20s")
def run(self, format_string, ...???):
# %u
scanf0 = claripy.BVS('scanf0', ???)
# %20s
scanf1 = claripy.BVS('scanf1', ???)
# The bitvector.chop(bits=n) function splits the bitvector into a Python
# list containing the bitvector in segments of n bits each. In this case,
# we are splitting them into segments of 8 bits (one byte.)
for char in scanf1.chop(bits=8):
# Ensure that each character in the string is printable. An interesting
# experiment, once you have a working solution, would be to run the code
# without constraining the characters to the capital letters.
# Even though the solution will technically work without this, it's more
# difficult to enter in a solution that contains character you can't
# copy, paste, or type into your terminal or the web form that checks
# your solution.
# If you are using the web form to submit answers, your solution must be
# entirely alphanumeric except for spaces.
# (!)
self.state.add_constraints(char >= ???, char <= ???)
# Warning: Endianness only applies to integers. If you store a string in
# memory and treat it as a little-endian integer, it will be backwards.
scanf0_address = ???
self.state.memory.store(scanf0_address, scanf0, endness=project.arch.memory_endness)
...
self.state.globals['solution0'] = ???
...
scanf_symbol = ??? # :string
project.hook_symbol(scanf_symbol, ReplacementScanf())
# We will call this whenever puts is called. The goal of this function is to
# determine if the pointer passed to puts is controllable by the user, such
# that we can rewrite it to point to the string "Good Job."
def check_puts(state):
# Recall that puts takes one parameter, a pointer to the string it will
# print. If we load that pointer from memory, we can analyse it to determine
# if it can be controlled by the user input in order to point it to the
# location of the "Good Job." string.
#
# Treat the implementation of this function as if puts was just called.
# The stack, registers, memory, etc should be set up as if the x86 call
# instruction was just invoked (but, of course, the function hasn't copied
# the buffers yet.)
# The stack will look as follows:
# ...
# esp + 7 -> /----------------\
# esp + 6 -> | puts |
# esp + 5 -> | parameter |
# esp + 4 -> \----------------/
# esp + 3 -> /----------------\
# esp + 2 -> | return |
# esp + 1 -> | address |
# esp -> \----------------/
#
# Hint: Look at level 08, 09, or 10 to review how to load a value from a
# memory address. Remember to use the correct endianness in the future when
# loading integers; it has been included for you here.
# (!)
puts_parameter = state.memory.load(???, ???, endness=project.arch.memory_endness)
# The following function takes a bitvector as a parameter and checks if it
# can take on more than one value. While this does not necessary tell us we
# have found an exploitable state, it is a strong indication that the
# bitvector we checked may be controllable by the user.
# Use it to determine if the pointer passed to puts is symbolic.
# (!)
if state.se.symbolic(???):
# Determine the location of the "Good Job." string. We want to print it
# out, and we will do so by attempting to constrain the puts parameter to
# equal it. (Hint: look at .rodata).
# Hint: use 'objdump -s <binary>' to look for the string's address.
# (!)
good_job_string_address = ??? # :integer, probably hexadecimal
# Create an expression that will test if puts_parameter equals
# good_job_string_address. If we add this as a constraint to our solver,
# it will try and find an input to make this expression true. Take a look
# at level 08 to remind yourself of the syntax of this.
# (!)
is_vulnerable_expression = ??? # :boolean bitvector expression
# Have Angr evaluate the state to determine if all the constraints can
# be met, including the one we specified above. If it can be satisfied,
# we have found our exploit!
#
# When doing this, however, we do not want to edit our state in case we
# have not yet found what we are looking for. To test if our expression
# is satisfiable without editing the original, we need to clone the state.
copied_state = state.copy()
# We can now play around with the copied state without changing the
# original. We need to add our vulnerable expression as a state to test it.
# Look at level 08 and compare this call to how it is called there.
copied_state.add_constraints(is_vulnerable_expression)
# Finally, we test if we can satisfy the constraints of the state.
if copied_state.satisfiable():
# Before we return, let's add the constraint to the solver for real.
state.add_constraints(is_vulnerable_expression)
return True
else:
return False
else: # not state.se.symbolic(???)
return False
simulation = project.factory.simgr(initial_state)
# In order to determine if we have found a vulnerable call to 'puts', we need
# to run the function check_puts (defined above) whenever we reach a 'puts'
# call. To do this, we will look for the place where the instruction pointer,
# state.addr, is equal to the beginning of the puts function.
def is_successful(state):
# We are looking for puts. Check that the address is at the (very) beginning
# of the puts function. Warning: while, in theory, you could look for
# any address in puts, if you execute any instruction that adjusts the stack
# pointer, the stack diagram above will be incorrect. Therefore, it is
# recommended that you check for the very beginning of puts.
# (!)
puts_address = ???
if state.addr == puts_address:
# Return True if we determine this call to puts is exploitable.
return check_puts(state)
else:
# We have not yet found a call to puts; we should continue!
return False
simulation.explore(find=is_successful)
if simulation.found:
solution_state = simulation.found[0]
solution = ???
print solution
else:
raise Exception('Could not find the solution')
if __name__ == '__main__':
main(sys.argv)
|
gpl-3.0
|
[
3,
961,
3366,
6181,
3865,
376,
3000,
436,
282,
1059,
465,
282,
2725,
14,
437,
9842,
199,
3,
3000,
1324,
14486,
314,
2240,
370,
12276,
282,
3335,
15784,
543,
1314,
781,
883,
199,
3,
1586,
282,
1059,
687,
376,
9697,
4402,
2909,
14,
25119,
14850,
365,
370,
675,
1626,
2587,
370,
221,
199,
3,
2754,
314,
2240,
367,
642,
3335,
15784,
436,
2066,
5847,
3550,
199,
3,
376,
15868,
390,
370,
1586,
314,
1059,
298,
20652,
15057,
2122,
221,
199,
3,
199,
3,
14791,
365,
314,
2376,
402,
7664,
314,
1059,
298,
20652,
15057,
2122,
31,
199,
3,
961,
445,
6145,
12454,
370,
29738,
282,
26867,
1015,
402,
282,
3962,
373,
29419,
199,
3,
2382,
282,
922,
883,
15868,
390,
314,
2240,
370,
870,
282,
7565,
12,
4066,
465,
282,
2505,
503,
199,
3,
282,
5726,
790,
14,
1010,
1865,
370,
4215,
17754,
543,
314,
1163,
682,
30599,
436,
370,
199,
3,
15037,
314,
14929,
12,
314,
14850,
402,
642,
2240,
911,
506,
370,
870,
298,
20652,
15057,
2122,
199,
3,
3140,
14,
199,
3,
199,
3,
710,
8605,
10054,
367,
286,
4800,
316,
642,
2884,
911,
506,
370,
26,
199,
3,
413,
9,
8730,
367,
4882,
402,
314,
283,
524,
83,
7,
805,
12,
1314,
911,
21356,
506,
15868,
5703,
199,
3,
259,
370,
870,
734,
298,
20652,
15057,
2122,
199,
3,
499,
9,
14703,
340,
314,
1642,
2725,
402,
283,
524,
83,
297,
282,
7849,
370,
314,
1059,
370,
506,
221,
199,
3,
259,
12487,
12,
883,
506,
22284,
701,
314,
922,
370,
506,
663,
370,
314,
2909,
402,
314,
199,
3,
259,
298,
20652,
15057,
2122,
1059,
14,
199,
3,
650,
9,
428,
3344,
367,
314,
1324,
626,
14767,
298,
20652,
15057,
2122,
199,
3,
199,
3,
3390,
26,
710,
2884,
365,
21781,
370,
5669,
3650,
327,
18,
2544,
327,
17,
14,
199,
199,
3,
6601,
402,
314,
1350,
1233,
367,
642,
14929,
26,
199,
3,
199,
3,
327,
2613,
665,
32011,
14,
72,
30,
199,
3,
327,
2613,
665,
28683,
14,
72,
30,
199,
3,
327,
2613,
665,
875,
14,
72,
30,
199,
3,
327,
2613,
665,
1516,
442,
14,
72,
30,
199,
3,
221,
199,
3,
5001,
961,
911,
1006,
506,
315,
1275,
293,
576,
199,
3,
1495,
1499,
8607,
275,
29696,
1369,
789,
4,
11436,
199,
3,
1495,
10,
862,
63,
14199,
275,
298,
12357,
4020,
2122,
27,
199,
3,
1495,
10,
6954,
63,
2423,
275,
298,
20652,
15057,
2122,
27,
199,
3,
3152,
708,
63,
84,
790,
27,
199,
3,
221,
199,
3,
2309,
870,
63,
1328,
342,
469,
199,
3,
257,
870,
70,
3647,
83,
401,
1499,
2736,
199,
3,
789,
199,
3,
199,
3,
3152,
708,
63,
84,
6114,
63,
1593,
8,
1635,
708,
63,
84,
1324,
9,
469,
199,
3,
257,
2263,
199,
3,
789,
199,
3,
221,
199,
3,
2702,
15784,
63,
278,
469,
199,
3,
257,
1495,
3335,
59,
975,
11566,
199,
3,
257,
1495,
10,
370,
63,
1361,
27,
199,
3,
16735,
221,
199,
3,
221,
199,
3,
1109,
2446,
8,
442,
1680,
67,
12,
1495,
10,
9238,
59,
566,
469,
199,
3,
257,
2702,
15784,
63,
278,
9480,
27,
199,
3,
257,
9480,
14,
475,
63,
1361,
275,
862,
63,
14199,
27,
199,
3,
221,
199,
3,
257,
870,
63,
1328,
7303,
199,
3,
221,
199,
3,
257,
870,
70,
480,
8468,
314,
2505,
26,
298,
2736,
199,
3,
257,
8000,
70,
3647,
85,
450,
1165,
83,
401,
1253,
498,
12,
9480,
14,
2738,
2736,
199,
3,
199,
3,
257,
790,
275,
6114,
63,
1593,
8,
498,
2736,
199,
3,
221,
199,
3,
257,
6258,
334,
498,
9,
469,
199,
3,
258,
1930,
5805,
26,
199,
3,
755,
27000,
8,
893,
63,
14199,
2736,
199,
3,
755,
2059,
27,
199,
3,
199,
3,
258,
2263,
199,
3,
199,
3,
258,
1930,
5805,
26,
199,
3,
755,
5001,
25119,
14850,
365,
370,
20907,
642,
1240,
370,
27000,
370,
870,
314,
298,
4731,
199,
3,
755,
5001,
2505,
2,
334,
6777,
10986,
12,
315,
4154,
1930,
12,
370,
506,
314,
1059,
199,
3,
755,
5001,
298,
20652,
15057,
2685,
199,
3,
755,
27000,
8,
9350,
14,
475,
63,
1361,
2736,
199,
3,
755,
2059,
27,
199,
3,
420,
199,
3,
258,
2263,
199,
3,
257,
789,
199,
3,
221,
199,
3,
257,
372,
378,
27,
199,
3,
789,
199,
199,
646,
376,
2587,
199,
646,
824,
759,
647,
199,
646,
984,
199,
199,
318,
2446,
8,
3020,
304,
523,
931,
63,
475,
63,
3008,
275,
9238,
59,
17,
61,
523,
2199,
275,
376,
2587,
14,
4761,
8,
515,
63,
475,
63,
3008,
9,
819,
327,
2047,
883,
1902,
675,
282,
4596,
1174,
503,
376,
2397,
1174,
27,
2951,
1852,
3238,
370,
1343,
523,
327,
737,
314,
9608,
402,
314,
2240,
14,
523,
327,
19452,
9,
523,
2536,
63,
929,
275,
5805,
10674,
819,
327,
437,
13020,
12,
8000,
70,
4839,
370,
506,
8717,
14,
523,
1021,
14402,
434,
15936,
70,
8,
621,
82,
14,
7467,
919,
12194,
304,
272,
327,
869,
442,
26,
8000,
70,
3647,
85,
450,
1165,
83,
531,
272,
347,
1255,
8,
277,
12,
1475,
63,
875,
12,
2263,
10674,
31,
304,
489,
327,
450,
85,
489,
8000,
70,
16,
275,
824,
759,
647,
14,
34,
7428,
360,
6282,
70,
16,
297,
5805,
10674,
9,
32115,
327,
450,
1165,
83,
489,
8000,
70,
17,
275,
824,
759,
647,
14,
34,
7428,
360,
6282,
70,
17,
297,
5805,
10674,
9,
2541,
327,
710,
4546,
4106,
14,
335,
411,
8,
5609,
29,
78,
9,
805,
19115,
314,
4546,
4106,
1901,
282,
2018,
489,
327,
769,
3035,
314,
4546,
4106,
315,
11998,
402,
302,
5821,
1924,
14,
1010,
642,
1930,
12,
489,
327,
781,
787,
26518,
3062,
1901,
11998,
402,
1695,
5821,
334,
368,
3696,
4959,
489,
367,
1495,
315,
8000,
70,
17,
14,
335,
411,
8,
5609,
29,
24,
304,
267,
327,
7523,
626,
1924,
4528,
315,
314,
1059,
365,
21834,
14,
1626,
19604,
267,
327,
11805,
12,
5403,
1265,
1172,
282,
6449,
8744,
12,
3955,
506,
370,
1255,
314,
1233,
267,
327,
1928,
950,
6322,
316,
314,
4110,
370,
314,
17094,
14435,
14,
267,
327,
22207,
10617,
314,
8744,
911
] |
[
961,
3366,
6181,
3865,
376,
3000,
436,
282,
1059,
465,
282,
2725,
14,
437,
9842,
199,
3,
3000,
1324,
14486,
314,
2240,
370,
12276,
282,
3335,
15784,
543,
1314,
781,
883,
199,
3,
1586,
282,
1059,
687,
376,
9697,
4402,
2909,
14,
25119,
14850,
365,
370,
675,
1626,
2587,
370,
221,
199,
3,
2754,
314,
2240,
367,
642,
3335,
15784,
436,
2066,
5847,
3550,
199,
3,
376,
15868,
390,
370,
1586,
314,
1059,
298,
20652,
15057,
2122,
221,
199,
3,
199,
3,
14791,
365,
314,
2376,
402,
7664,
314,
1059,
298,
20652,
15057,
2122,
31,
199,
3,
961,
445,
6145,
12454,
370,
29738,
282,
26867,
1015,
402,
282,
3962,
373,
29419,
199,
3,
2382,
282,
922,
883,
15868,
390,
314,
2240,
370,
870,
282,
7565,
12,
4066,
465,
282,
2505,
503,
199,
3,
282,
5726,
790,
14,
1010,
1865,
370,
4215,
17754,
543,
314,
1163,
682,
30599,
436,
370,
199,
3,
15037,
314,
14929,
12,
314,
14850,
402,
642,
2240,
911,
506,
370,
870,
298,
20652,
15057,
2122,
199,
3,
3140,
14,
199,
3,
199,
3,
710,
8605,
10054,
367,
286,
4800,
316,
642,
2884,
911,
506,
370,
26,
199,
3,
413,
9,
8730,
367,
4882,
402,
314,
283,
524,
83,
7,
805,
12,
1314,
911,
21356,
506,
15868,
5703,
199,
3,
259,
370,
870,
734,
298,
20652,
15057,
2122,
199,
3,
499,
9,
14703,
340,
314,
1642,
2725,
402,
283,
524,
83,
297,
282,
7849,
370,
314,
1059,
370,
506,
221,
199,
3,
259,
12487,
12,
883,
506,
22284,
701,
314,
922,
370,
506,
663,
370,
314,
2909,
402,
314,
199,
3,
259,
298,
20652,
15057,
2122,
1059,
14,
199,
3,
650,
9,
428,
3344,
367,
314,
1324,
626,
14767,
298,
20652,
15057,
2122,
199,
3,
199,
3,
3390,
26,
710,
2884,
365,
21781,
370,
5669,
3650,
327,
18,
2544,
327,
17,
14,
199,
199,
3,
6601,
402,
314,
1350,
1233,
367,
642,
14929,
26,
199,
3,
199,
3,
327,
2613,
665,
32011,
14,
72,
30,
199,
3,
327,
2613,
665,
28683,
14,
72,
30,
199,
3,
327,
2613,
665,
875,
14,
72,
30,
199,
3,
327,
2613,
665,
1516,
442,
14,
72,
30,
199,
3,
221,
199,
3,
5001,
961,
911,
1006,
506,
315,
1275,
293,
576,
199,
3,
1495,
1499,
8607,
275,
29696,
1369,
789,
4,
11436,
199,
3,
1495,
10,
862,
63,
14199,
275,
298,
12357,
4020,
2122,
27,
199,
3,
1495,
10,
6954,
63,
2423,
275,
298,
20652,
15057,
2122,
27,
199,
3,
3152,
708,
63,
84,
790,
27,
199,
3,
221,
199,
3,
2309,
870,
63,
1328,
342,
469,
199,
3,
257,
870,
70,
3647,
83,
401,
1499,
2736,
199,
3,
789,
199,
3,
199,
3,
3152,
708,
63,
84,
6114,
63,
1593,
8,
1635,
708,
63,
84,
1324,
9,
469,
199,
3,
257,
2263,
199,
3,
789,
199,
3,
221,
199,
3,
2702,
15784,
63,
278,
469,
199,
3,
257,
1495,
3335,
59,
975,
11566,
199,
3,
257,
1495,
10,
370,
63,
1361,
27,
199,
3,
16735,
221,
199,
3,
221,
199,
3,
1109,
2446,
8,
442,
1680,
67,
12,
1495,
10,
9238,
59,
566,
469,
199,
3,
257,
2702,
15784,
63,
278,
9480,
27,
199,
3,
257,
9480,
14,
475,
63,
1361,
275,
862,
63,
14199,
27,
199,
3,
221,
199,
3,
257,
870,
63,
1328,
7303,
199,
3,
221,
199,
3,
257,
870,
70,
480,
8468,
314,
2505,
26,
298,
2736,
199,
3,
257,
8000,
70,
3647,
85,
450,
1165,
83,
401,
1253,
498,
12,
9480,
14,
2738,
2736,
199,
3,
199,
3,
257,
790,
275,
6114,
63,
1593,
8,
498,
2736,
199,
3,
221,
199,
3,
257,
6258,
334,
498,
9,
469,
199,
3,
258,
1930,
5805,
26,
199,
3,
755,
27000,
8,
893,
63,
14199,
2736,
199,
3,
755,
2059,
27,
199,
3,
199,
3,
258,
2263,
199,
3,
199,
3,
258,
1930,
5805,
26,
199,
3,
755,
5001,
25119,
14850,
365,
370,
20907,
642,
1240,
370,
27000,
370,
870,
314,
298,
4731,
199,
3,
755,
5001,
2505,
2,
334,
6777,
10986,
12,
315,
4154,
1930,
12,
370,
506,
314,
1059,
199,
3,
755,
5001,
298,
20652,
15057,
2685,
199,
3,
755,
27000,
8,
9350,
14,
475,
63,
1361,
2736,
199,
3,
755,
2059,
27,
199,
3,
420,
199,
3,
258,
2263,
199,
3,
257,
789,
199,
3,
221,
199,
3,
257,
372,
378,
27,
199,
3,
789,
199,
199,
646,
376,
2587,
199,
646,
824,
759,
647,
199,
646,
984,
199,
199,
318,
2446,
8,
3020,
304,
523,
931,
63,
475,
63,
3008,
275,
9238,
59,
17,
61,
523,
2199,
275,
376,
2587,
14,
4761,
8,
515,
63,
475,
63,
3008,
9,
819,
327,
2047,
883,
1902,
675,
282,
4596,
1174,
503,
376,
2397,
1174,
27,
2951,
1852,
3238,
370,
1343,
523,
327,
737,
314,
9608,
402,
314,
2240,
14,
523,
327,
19452,
9,
523,
2536,
63,
929,
275,
5805,
10674,
819,
327,
437,
13020,
12,
8000,
70,
4839,
370,
506,
8717,
14,
523,
1021,
14402,
434,
15936,
70,
8,
621,
82,
14,
7467,
919,
12194,
304,
272,
327,
869,
442,
26,
8000,
70,
3647,
85,
450,
1165,
83,
531,
272,
347,
1255,
8,
277,
12,
1475,
63,
875,
12,
2263,
10674,
31,
304,
489,
327,
450,
85,
489,
8000,
70,
16,
275,
824,
759,
647,
14,
34,
7428,
360,
6282,
70,
16,
297,
5805,
10674,
9,
32115,
327,
450,
1165,
83,
489,
8000,
70,
17,
275,
824,
759,
647,
14,
34,
7428,
360,
6282,
70,
17,
297,
5805,
10674,
9,
2541,
327,
710,
4546,
4106,
14,
335,
411,
8,
5609,
29,
78,
9,
805,
19115,
314,
4546,
4106,
1901,
282,
2018,
489,
327,
769,
3035,
314,
4546,
4106,
315,
11998,
402,
302,
5821,
1924,
14,
1010,
642,
1930,
12,
489,
327,
781,
787,
26518,
3062,
1901,
11998,
402,
1695,
5821,
334,
368,
3696,
4959,
489,
367,
1495,
315,
8000,
70,
17,
14,
335,
411,
8,
5609,
29,
24,
304,
267,
327,
7523,
626,
1924,
4528,
315,
314,
1059,
365,
21834,
14,
1626,
19604,
267,
327,
11805,
12,
5403,
1265,
1172,
282,
6449,
8744,
12,
3955,
506,
370,
1255,
314,
1233,
267,
327,
1928,
950,
6322,
316,
314,
4110,
370,
314,
17094,
14435,
14,
267,
327,
22207,
10617,
314,
8744,
911,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nfg/yagmail
|
yagmail/error.py
|
4
|
1173
|
"""Contains the exceptions"""
class YagConnectionClosed(Exception):
"""
The connection object has been closed by the user.
This object can be used to send emails again after logging in,
using self.login().
"""
pass
class YagAddressError(Exception):
"""
This means that the address was given in an invalid format.
Note that From can either be a string, or a dictionary where the key is an email,
and the value is an alias {'sample@gmail.com', 'Sam'}. In the case of 'to',
it can either be a string (email), a list of emails (email addresses without aliases)
or a dictionary where keys are the email addresses and the values indicate the aliases.
Furthermore, it does not do any validation of whether an email exists.
"""
pass
class YagInvalidEmailAddress(Exception):
"""
Note that this will only filter out syntax mistakes in emailaddresses.
If a human would think it is probably a valid email, it will most likely pass.
However, it could still very well be that the actual emailaddress has simply
not be claimed by anyone (so then this function fails to devalidate).
"""
pass
|
mit
|
[
624,
6906,
314,
4967,
624,
421,
199,
533,
1488,
643,
3225,
15190,
8,
1726,
304,
339,
408,
272,
710,
1950,
909,
965,
2757,
6876,
701,
314,
922,
14,
272,
961,
909,
883,
506,
1202,
370,
3222,
14931,
4020,
2410,
2050,
315,
12,
272,
1808,
291,
14,
2886,
1252,
272,
408,
272,
986,
421,
199,
533,
1488,
643,
1476,
547,
8,
1726,
304,
339,
408,
272,
961,
4910,
626,
314,
2287,
1990,
1627,
315,
376,
3866,
1475,
14,
272,
3390,
626,
11606,
883,
1902,
506,
282,
1059,
12,
503,
282,
2600,
2382,
314,
790,
365,
376,
3031,
12,
272,
436,
314,
574,
365,
376,
5162,
791,
3271,
32,
6799,
14,
957,
297,
283,
51,
455,
936,
14,
1010,
314,
1930,
402,
283,
475,
297,
272,
652,
883,
1902,
506,
282,
1059,
334,
2123,
395,
282,
769,
402,
14931,
334,
2123,
7149,
1928,
5481,
9,
272,
503,
282,
2600,
2382,
2883,
787,
314,
3031,
7149,
436,
314,
1338,
6623,
314,
5481,
14,
272,
28876,
6878,
12,
652,
1630,
440,
886,
1263,
6411,
402,
3775,
376,
3031,
3495,
14,
272,
408,
272,
986,
421,
199,
533,
1488,
643,
3364,
7035,
1476,
8,
1726,
304,
339,
408,
272,
3390,
626,
642,
911,
1454,
2457,
734,
6302,
27572,
4364,
315,
3031,
7423,
14,
272,
982,
282,
11779,
3955,
13516,
652,
365,
8646,
282,
1686,
3031,
12,
652,
911,
4750,
12060,
986,
14,
272,
9738,
12,
652,
4293,
5139,
7437,
5521,
506,
626,
314,
3503,
3031,
1562,
965,
9329,
272,
440,
506,
6108,
21538,
701,
29165,
334,
1152,
2066,
642,
805,
6918,
370,
477,
3502,
680,
272,
408,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6906,
314,
4967,
624,
421,
199,
533,
1488,
643,
3225,
15190,
8,
1726,
304,
339,
408,
272,
710,
1950,
909,
965,
2757,
6876,
701,
314,
922,
14,
272,
961,
909,
883,
506,
1202,
370,
3222,
14931,
4020,
2410,
2050,
315,
12,
272,
1808,
291,
14,
2886,
1252,
272,
408,
272,
986,
421,
199,
533,
1488,
643,
1476,
547,
8,
1726,
304,
339,
408,
272,
961,
4910,
626,
314,
2287,
1990,
1627,
315,
376,
3866,
1475,
14,
272,
3390,
626,
11606,
883,
1902,
506,
282,
1059,
12,
503,
282,
2600,
2382,
314,
790,
365,
376,
3031,
12,
272,
436,
314,
574,
365,
376,
5162,
791,
3271,
32,
6799,
14,
957,
297,
283,
51,
455,
936,
14,
1010,
314,
1930,
402,
283,
475,
297,
272,
652,
883,
1902,
506,
282,
1059,
334,
2123,
395,
282,
769,
402,
14931,
334,
2123,
7149,
1928,
5481,
9,
272,
503,
282,
2600,
2382,
2883,
787,
314,
3031,
7149,
436,
314,
1338,
6623,
314,
5481,
14,
272,
28876,
6878,
12,
652,
1630,
440,
886,
1263,
6411,
402,
3775,
376,
3031,
3495,
14,
272,
408,
272,
986,
421,
199,
533,
1488,
643,
3364,
7035,
1476,
8,
1726,
304,
339,
408,
272,
3390,
626,
642,
911,
1454,
2457,
734,
6302,
27572,
4364,
315,
3031,
7423,
14,
272,
982,
282,
11779,
3955,
13516,
652,
365,
8646,
282,
1686,
3031,
12,
652,
911,
4750,
12060,
986,
14,
272,
9738,
12,
652,
4293,
5139,
7437,
5521,
506,
626,
314,
3503,
3031,
1562,
965,
9329,
272,
440,
506,
6108,
21538,
701,
29165,
334,
1152,
2066,
642,
805,
6918,
370,
477,
3502,
680,
272,
408,
272,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shadow000902/blog_source
|
node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py
|
327
|
132617
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import copy
import ntpath
import os
import posixpath
import re
import subprocess
import sys
import gyp.common
import gyp.easy_xml as easy_xml
import gyp.generator.ninja as ninja_generator
import gyp.MSVSNew as MSVSNew
import gyp.MSVSProject as MSVSProject
import gyp.MSVSSettings as MSVSSettings
import gyp.MSVSToolFile as MSVSToolFile
import gyp.MSVSUserFile as MSVSUserFile
import gyp.MSVSUtil as MSVSUtil
import gyp.MSVSVersion as MSVSVersion
from gyp.common import GypError
from gyp.common import OrderedSet
# TODO: Remove once bots are on 2.7, http://crbug.com/241769
def _import_OrderedDict():
import collections
try:
return collections.OrderedDict
except AttributeError:
import gyp.ordered_dict
return gyp.ordered_dict.OrderedDict
OrderedDict = _import_OrderedDict()
# Regular expression for validating Visual Studio GUIDs. If the GUID
# contains lowercase hex letters, MSVS will be fine. However,
# IncrediBuild BuildConsole will parse the solution file, but then
# silently skip building the target causing hard to track down errors.
# Note that this only happens with the BuildConsole, and does not occur
# if IncrediBuild is executed from inside Visual Studio. This regex
# validates that the string looks like a GUID with all uppercase hex
# letters.
VALID_MSVS_GUID_CHARS = re.compile(r'^[A-F0-9\-]+$')
generator_default_variables = {
'EXECUTABLE_PREFIX': '',
'EXECUTABLE_SUFFIX': '.exe',
'STATIC_LIB_PREFIX': '',
'SHARED_LIB_PREFIX': '',
'STATIC_LIB_SUFFIX': '.lib',
'SHARED_LIB_SUFFIX': '.dll',
'INTERMEDIATE_DIR': '$(IntDir)',
'SHARED_INTERMEDIATE_DIR': '$(OutDir)obj/global_intermediate',
'OS': 'win',
'PRODUCT_DIR': '$(OutDir)',
'LIB_DIR': '$(OutDir)lib',
'RULE_INPUT_ROOT': '$(InputName)',
'RULE_INPUT_DIRNAME': '$(InputDir)',
'RULE_INPUT_EXT': '$(InputExt)',
'RULE_INPUT_NAME': '$(InputFileName)',
'RULE_INPUT_PATH': '$(InputPath)',
'CONFIGURATION_NAME': '$(ConfigurationName)',
}
# The msvs specific sections that hold paths
generator_additional_path_sections = [
'msvs_cygwin_dirs',
'msvs_props',
]
generator_additional_non_configuration_keys = [
'msvs_cygwin_dirs',
'msvs_cygwin_shell',
'msvs_large_pdb',
'msvs_shard',
'msvs_external_builder',
'msvs_external_builder_out_dir',
'msvs_external_builder_build_cmd',
'msvs_external_builder_clean_cmd',
'msvs_external_builder_clcompile_cmd',
'msvs_enable_winrt',
'msvs_requires_importlibrary',
'msvs_enable_winphone',
'msvs_application_type_revision',
'msvs_target_platform_version',
'msvs_target_platform_minversion',
]
# List of precompiled header related keys.
precomp_keys = [
'msvs_precompiled_header',
'msvs_precompiled_source',
]
cached_username = None
cached_domain = None
# TODO(gspencer): Switch the os.environ calls to be
# win32api.GetDomainName() and win32api.GetUserName() once the
# python version in depot_tools has been updated to work on Vista
# 64-bit.
def _GetDomainAndUserName():
if sys.platform not in ('win32', 'cygwin'):
return ('DOMAIN', 'USERNAME')
global cached_username
global cached_domain
if not cached_domain or not cached_username:
domain = os.environ.get('USERDOMAIN')
username = os.environ.get('USERNAME')
if not domain or not username:
call = subprocess.Popen(['net', 'config', 'Workstation'],
stdout=subprocess.PIPE)
config = call.communicate()[0]
username_re = re.compile(r'^User name\s+(\S+)', re.MULTILINE)
username_match = username_re.search(config)
if username_match:
username = username_match.group(1)
domain_re = re.compile(r'^Logon domain\s+(\S+)', re.MULTILINE)
domain_match = domain_re.search(config)
if domain_match:
domain = domain_match.group(1)
cached_domain = domain
cached_username = username
return (cached_domain, cached_username)
fixpath_prefix = None
def _NormalizedSource(source):
"""Normalize the path.
But not if that gets rid of a variable, as this may expand to something
larger than one directory.
Arguments:
source: The path to be normalize.d
Returns:
The normalized path.
"""
normalized = os.path.normpath(source)
if source.count('$') == normalized.count('$'):
source = normalized
return source
def _FixPath(path):
"""Convert paths to a form that will make sense in a vcproj file.
Arguments:
path: The path to convert, may contain / etc.
Returns:
The path with all slashes made into backslashes.
"""
if fixpath_prefix and path and not os.path.isabs(path) and not path[0] == '$':
path = os.path.join(fixpath_prefix, path)
path = path.replace('/', '\\')
path = _NormalizedSource(path)
if path and path[-1] == '\\':
path = path[:-1]
return path
def _FixPaths(paths):
"""Fix each of the paths of the list."""
return [_FixPath(i) for i in paths]
def _ConvertSourcesToFilterHierarchy(sources, prefix=None, excluded=None,
list_excluded=True, msvs_version=None):
"""Converts a list split source file paths into a vcproj folder hierarchy.
Arguments:
sources: A list of source file paths split.
prefix: A list of source file path layers meant to apply to each of sources.
excluded: A set of excluded files.
msvs_version: A MSVSVersion object.
Returns:
A hierarchy of filenames and MSVSProject.Filter objects that matches the
layout of the source tree.
For example:
_ConvertSourcesToFilterHierarchy([['a', 'bob1.c'], ['b', 'bob2.c']],
prefix=['joe'])
-->
[MSVSProject.Filter('a', contents=['joe\\a\\bob1.c']),
MSVSProject.Filter('b', contents=['joe\\b\\bob2.c'])]
"""
if not prefix: prefix = []
result = []
excluded_result = []
folders = OrderedDict()
# Gather files into the final result, excluded, or folders.
for s in sources:
if len(s) == 1:
filename = _NormalizedSource('\\'.join(prefix + s))
if filename in excluded:
excluded_result.append(filename)
else:
result.append(filename)
elif msvs_version and not msvs_version.UsesVcxproj():
# For MSVS 2008 and earlier, we need to process all files before walking
# the sub folders.
if not folders.get(s[0]):
folders[s[0]] = []
folders[s[0]].append(s[1:])
else:
contents = _ConvertSourcesToFilterHierarchy([s[1:]], prefix + [s[0]],
excluded=excluded,
list_excluded=list_excluded,
msvs_version=msvs_version)
contents = MSVSProject.Filter(s[0], contents=contents)
result.append(contents)
# Add a folder for excluded files.
if excluded_result and list_excluded:
excluded_folder = MSVSProject.Filter('_excluded_files',
contents=excluded_result)
result.append(excluded_folder)
if msvs_version and msvs_version.UsesVcxproj():
return result
# Populate all the folders.
for f in folders:
contents = _ConvertSourcesToFilterHierarchy(folders[f], prefix=prefix + [f],
excluded=excluded,
list_excluded=list_excluded,
msvs_version=msvs_version)
contents = MSVSProject.Filter(f, contents=contents)
result.append(contents)
return result
def _ToolAppend(tools, tool_name, setting, value, only_if_unset=False):
if not value: return
_ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset)
def _ToolSetOrAppend(tools, tool_name, setting, value, only_if_unset=False):
# TODO(bradnelson): ugly hack, fix this more generally!!!
if 'Directories' in setting or 'Dependencies' in setting:
if type(value) == str:
value = value.replace('/', '\\')
else:
value = [i.replace('/', '\\') for i in value]
if not tools.get(tool_name):
tools[tool_name] = dict()
tool = tools[tool_name]
if tool.get(setting):
if only_if_unset: return
if type(tool[setting]) == list and type(value) == list:
tool[setting] += value
else:
raise TypeError(
'Appending "%s" to a non-list setting "%s" for tool "%s" is '
'not allowed, previous value: %s' % (
value, setting, tool_name, str(tool[setting])))
else:
tool[setting] = value
def _ConfigPlatform(config_data):
return config_data.get('msvs_configuration_platform', 'Win32')
def _ConfigBaseName(config_name, platform_name):
if config_name.endswith('_' + platform_name):
return config_name[0:-len(platform_name) - 1]
else:
return config_name
def _ConfigFullName(config_name, config_data):
platform_name = _ConfigPlatform(config_data)
return '%s|%s' % (_ConfigBaseName(config_name, platform_name), platform_name)
def _ConfigWindowsTargetPlatformVersion(config_data):
ver = config_data.get('msvs_windows_target_platform_version')
if not ver or re.match(r'^\d+', ver):
return ver
for key in [r'HKLM\Software\Microsoft\Microsoft SDKs\Windows\%s',
r'HKLM\Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows\%s']:
sdkdir = MSVSVersion._RegistryGetValue(key % ver, 'InstallationFolder')
if not sdkdir:
continue
version = MSVSVersion._RegistryGetValue(key % ver, 'ProductVersion') or ''
# find a matching entry in sdkdir\include
names = sorted([x for x in os.listdir(r'%s\include' % sdkdir) \
if x.startswith(version)], reverse = True)
return names[0]
def _BuildCommandLineForRuleRaw(spec, cmd, cygwin_shell, has_input_path,
quote_cmd, do_setup_env):
if [x for x in cmd if '$(InputDir)' in x]:
input_dir_preamble = (
'set INPUTDIR=$(InputDir)\n'
'if NOT DEFINED INPUTDIR set INPUTDIR=.\\\n'
'set INPUTDIR=%INPUTDIR:~0,-1%\n'
)
else:
input_dir_preamble = ''
if cygwin_shell:
# Find path to cygwin.
cygwin_dir = _FixPath(spec.get('msvs_cygwin_dirs', ['.'])[0])
# Prepare command.
direct_cmd = cmd
direct_cmd = [i.replace('$(IntDir)',
'`cygpath -m "${INTDIR}"`') for i in direct_cmd]
direct_cmd = [i.replace('$(OutDir)',
'`cygpath -m "${OUTDIR}"`') for i in direct_cmd]
direct_cmd = [i.replace('$(InputDir)',
'`cygpath -m "${INPUTDIR}"`') for i in direct_cmd]
if has_input_path:
direct_cmd = [i.replace('$(InputPath)',
'`cygpath -m "${INPUTPATH}"`')
for i in direct_cmd]
direct_cmd = ['\\"%s\\"' % i.replace('"', '\\\\\\"') for i in direct_cmd]
# direct_cmd = gyp.common.EncodePOSIXShellList(direct_cmd)
direct_cmd = ' '.join(direct_cmd)
# TODO(quote): regularize quoting path names throughout the module
cmd = ''
if do_setup_env:
cmd += 'call "$(ProjectDir)%(cygwin_dir)s\\setup_env.bat" && '
cmd += 'set CYGWIN=nontsec&& '
if direct_cmd.find('NUMBER_OF_PROCESSORS') >= 0:
cmd += 'set /a NUMBER_OF_PROCESSORS_PLUS_1=%%NUMBER_OF_PROCESSORS%%+1&& '
if direct_cmd.find('INTDIR') >= 0:
cmd += 'set INTDIR=$(IntDir)&& '
if direct_cmd.find('OUTDIR') >= 0:
cmd += 'set OUTDIR=$(OutDir)&& '
if has_input_path and direct_cmd.find('INPUTPATH') >= 0:
cmd += 'set INPUTPATH=$(InputPath) && '
cmd += 'bash -c "%(cmd)s"'
cmd = cmd % {'cygwin_dir': cygwin_dir,
'cmd': direct_cmd}
return input_dir_preamble + cmd
else:
# Convert cat --> type to mimic unix.
if cmd[0] == 'cat':
command = ['type']
else:
command = [cmd[0].replace('/', '\\')]
# Add call before command to ensure that commands can be tied together one
# after the other without aborting in Incredibuild, since IB makes a bat
# file out of the raw command string, and some commands (like python) are
# actually batch files themselves.
command.insert(0, 'call')
# Fix the paths
# TODO(quote): This is a really ugly heuristic, and will miss path fixing
# for arguments like "--arg=path" or "/opt:path".
# If the argument starts with a slash or dash, it's probably a command line
# switch
arguments = [i if (i[:1] in "/-") else _FixPath(i) for i in cmd[1:]]
arguments = [i.replace('$(InputDir)', '%INPUTDIR%') for i in arguments]
arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments]
if quote_cmd:
# Support a mode for using cmd directly.
# Convert any paths to native form (first element is used directly).
# TODO(quote): regularize quoting path names throughout the module
arguments = ['"%s"' % i for i in arguments]
# Collapse into a single command.
return input_dir_preamble + ' '.join(command + arguments)
def _BuildCommandLineForRule(spec, rule, has_input_path, do_setup_env):
# Currently this weird argument munging is used to duplicate the way a
# python script would need to be run as part of the chrome tree.
# Eventually we should add some sort of rule_default option to set this
# per project. For now the behavior chrome needs is the default.
mcs = rule.get('msvs_cygwin_shell')
if mcs is None:
mcs = int(spec.get('msvs_cygwin_shell', 1))
elif isinstance(mcs, str):
mcs = int(mcs)
quote_cmd = int(rule.get('msvs_quote_cmd', 1))
return _BuildCommandLineForRuleRaw(spec, rule['action'], mcs, has_input_path,
quote_cmd, do_setup_env=do_setup_env)
def _AddActionStep(actions_dict, inputs, outputs, description, command):
"""Merge action into an existing list of actions.
Care must be taken so that actions which have overlapping inputs either don't
get assigned to the same input, or get collapsed into one.
Arguments:
actions_dict: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
inputs: list of inputs
outputs: list of outputs
description: description of the action
command: command line to execute
"""
# Require there to be at least one input (call sites will ensure this).
assert inputs
action = {
'inputs': inputs,
'outputs': outputs,
'description': description,
'command': command,
}
# Pick where to stick this action.
# While less than optimal in terms of build time, attach them to the first
# input for now.
chosen_input = inputs[0]
# Add it there.
if chosen_input not in actions_dict:
actions_dict[chosen_input] = []
actions_dict[chosen_input].append(action)
def _AddCustomBuildToolForMSVS(p, spec, primary_input,
inputs, outputs, description, cmd):
"""Add a custom build tool to execute something.
Arguments:
p: the target project
spec: the target project dict
primary_input: input file to attach the build tool to
inputs: list of inputs
outputs: list of outputs
description: description of the action
cmd: command line to execute
"""
inputs = _FixPaths(inputs)
outputs = _FixPaths(outputs)
tool = MSVSProject.Tool(
'VCCustomBuildTool',
{'Description': description,
'AdditionalDependencies': ';'.join(inputs),
'Outputs': ';'.join(outputs),
'CommandLine': cmd,
})
# Add to the properties of primary input for each config.
for config_name, c_data in spec['configurations'].iteritems():
p.AddFileConfig(_FixPath(primary_input),
_ConfigFullName(config_name, c_data), tools=[tool])
def _AddAccumulatedActionsToMSVS(p, spec, actions_dict):
"""Add actions accumulated into an actions_dict, merging as needed.
Arguments:
p: the target project
spec: the target project dict
actions_dict: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
"""
for primary_input in actions_dict:
inputs = OrderedSet()
outputs = OrderedSet()
descriptions = []
commands = []
for action in actions_dict[primary_input]:
inputs.update(OrderedSet(action['inputs']))
outputs.update(OrderedSet(action['outputs']))
descriptions.append(action['description'])
commands.append(action['command'])
# Add the custom build step for one input file.
description = ', and also '.join(descriptions)
command = '\r\n'.join(commands)
_AddCustomBuildToolForMSVS(p, spec,
primary_input=primary_input,
inputs=inputs,
outputs=outputs,
description=description,
cmd=command)
def _RuleExpandPath(path, input_file):
"""Given the input file to which a rule applied, string substitute a path.
Arguments:
path: a path to string expand
input_file: the file to which the rule applied.
Returns:
The string substituted path.
"""
path = path.replace('$(InputName)',
os.path.splitext(os.path.split(input_file)[1])[0])
path = path.replace('$(InputDir)', os.path.dirname(input_file))
path = path.replace('$(InputExt)',
os.path.splitext(os.path.split(input_file)[1])[1])
path = path.replace('$(InputFileName)', os.path.split(input_file)[1])
path = path.replace('$(InputPath)', input_file)
return path
def _FindRuleTriggerFiles(rule, sources):
"""Find the list of files which a particular rule applies to.
Arguments:
rule: the rule in question
sources: the set of all known source files for this project
Returns:
The list of sources that trigger a particular rule.
"""
return rule.get('rule_sources', [])
def _RuleInputsAndOutputs(rule, trigger_file):
"""Find the inputs and outputs generated by a rule.
Arguments:
rule: the rule in question.
trigger_file: the main trigger for this rule.
Returns:
The pair of (inputs, outputs) involved in this rule.
"""
raw_inputs = _FixPaths(rule.get('inputs', []))
raw_outputs = _FixPaths(rule.get('outputs', []))
inputs = OrderedSet()
outputs = OrderedSet()
inputs.add(trigger_file)
for i in raw_inputs:
inputs.add(_RuleExpandPath(i, trigger_file))
for o in raw_outputs:
outputs.add(_RuleExpandPath(o, trigger_file))
return (inputs, outputs)
def _GenerateNativeRulesForMSVS(p, rules, output_dir, spec, options):
"""Generate a native rules file.
Arguments:
p: the target project
rules: the set of rules to include
output_dir: the directory in which the project/gyp resides
spec: the project dict
options: global generator options
"""
rules_filename = '%s%s.rules' % (spec['target_name'],
options.suffix)
rules_file = MSVSToolFile.Writer(os.path.join(output_dir, rules_filename),
spec['target_name'])
# Add each rule.
for r in rules:
rule_name = r['rule_name']
rule_ext = r['extension']
inputs = _FixPaths(r.get('inputs', []))
outputs = _FixPaths(r.get('outputs', []))
# Skip a rule with no action and no inputs.
if 'action' not in r and not r.get('rule_sources', []):
continue
cmd = _BuildCommandLineForRule(spec, r, has_input_path=True,
do_setup_env=True)
rules_file.AddCustomBuildRule(name=rule_name,
description=r.get('message', rule_name),
extensions=[rule_ext],
additional_dependencies=inputs,
outputs=outputs,
cmd=cmd)
# Write out rules file.
rules_file.WriteIfChanged()
# Add rules file to project.
p.AddToolFile(rules_filename)
def _Cygwinify(path):
path = path.replace('$(OutDir)', '$(OutDirCygwin)')
path = path.replace('$(IntDir)', '$(IntDirCygwin)')
return path
def _GenerateExternalRules(rules, output_dir, spec,
sources, options, actions_to_add):
"""Generate an external makefile to do a set of rules.
Arguments:
rules: the list of rules to include
output_dir: path containing project and gyp files
spec: project specification data
sources: set of sources known
options: global generator options
actions_to_add: The list of actions we will add to.
"""
filename = '%s_rules%s.mk' % (spec['target_name'], options.suffix)
mk_file = gyp.common.WriteOnDiff(os.path.join(output_dir, filename))
# Find cygwin style versions of some paths.
mk_file.write('OutDirCygwin:=$(shell cygpath -u "$(OutDir)")\n')
mk_file.write('IntDirCygwin:=$(shell cygpath -u "$(IntDir)")\n')
# Gather stuff needed to emit all: target.
all_inputs = OrderedSet()
all_outputs = OrderedSet()
all_output_dirs = OrderedSet()
first_outputs = []
for rule in rules:
trigger_files = _FindRuleTriggerFiles(rule, sources)
for tf in trigger_files:
inputs, outputs = _RuleInputsAndOutputs(rule, tf)
all_inputs.update(OrderedSet(inputs))
all_outputs.update(OrderedSet(outputs))
# Only use one target from each rule as the dependency for
# 'all' so we don't try to build each rule multiple times.
first_outputs.append(list(outputs)[0])
# Get the unique output directories for this rule.
output_dirs = [os.path.split(i)[0] for i in outputs]
for od in output_dirs:
all_output_dirs.add(od)
first_outputs_cyg = [_Cygwinify(i) for i in first_outputs]
# Write out all: target, including mkdir for each output directory.
mk_file.write('all: %s\n' % ' '.join(first_outputs_cyg))
for od in all_output_dirs:
if od:
mk_file.write('\tmkdir -p `cygpath -u "%s"`\n' % od)
mk_file.write('\n')
# Define how each output is generated.
for rule in rules:
trigger_files = _FindRuleTriggerFiles(rule, sources)
for tf in trigger_files:
# Get all the inputs and outputs for this rule for this trigger file.
inputs, outputs = _RuleInputsAndOutputs(rule, tf)
inputs = [_Cygwinify(i) for i in inputs]
outputs = [_Cygwinify(i) for i in outputs]
# Prepare the command line for this rule.
cmd = [_RuleExpandPath(c, tf) for c in rule['action']]
cmd = ['"%s"' % i for i in cmd]
cmd = ' '.join(cmd)
# Add it to the makefile.
mk_file.write('%s: %s\n' % (' '.join(outputs), ' '.join(inputs)))
mk_file.write('\t%s\n\n' % cmd)
# Close up the file.
mk_file.close()
# Add makefile to list of sources.
sources.add(filename)
# Add a build action to call makefile.
cmd = ['make',
'OutDir=$(OutDir)',
'IntDir=$(IntDir)',
'-j', '${NUMBER_OF_PROCESSORS_PLUS_1}',
'-f', filename]
cmd = _BuildCommandLineForRuleRaw(spec, cmd, True, False, True, True)
# Insert makefile as 0'th input, so it gets the action attached there,
# as this is easier to understand from in the IDE.
all_inputs = list(all_inputs)
all_inputs.insert(0, filename)
_AddActionStep(actions_to_add,
inputs=_FixPaths(all_inputs),
outputs=_FixPaths(all_outputs),
description='Running external rules for %s' %
spec['target_name'],
command=cmd)
def _EscapeEnvironmentVariableExpansion(s):
"""Escapes % characters.
Escapes any % characters so that Windows-style environment variable
expansions will leave them alone.
See http://connect.microsoft.com/VisualStudio/feedback/details/106127/cl-d-name-text-containing-percentage-characters-doesnt-compile
to understand why we have to do this.
Args:
s: The string to be escaped.
Returns:
The escaped string.
"""
s = s.replace('%', '%%')
return s
quote_replacer_regex = re.compile(r'(\\*)"')
def _EscapeCommandLineArgumentForMSVS(s):
"""Escapes a Windows command-line argument.
So that the Win32 CommandLineToArgv function will turn the escaped result back
into the original string.
See http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
("Parsing C++ Command-Line Arguments") to understand why we have to do
this.
Args:
s: the string to be escaped.
Returns:
the escaped string.
"""
def _Replace(match):
# For a literal quote, CommandLineToArgv requires an odd number of
# backslashes preceding it, and it produces half as many literal backslashes
# (rounded down). So we need to produce 2n+1 backslashes.
return 2 * match.group(1) + '\\"'
# Escape all quotes so that they are interpreted literally.
s = quote_replacer_regex.sub(_Replace, s)
# Now add unescaped quotes so that any whitespace is interpreted literally.
s = '"' + s + '"'
return s
delimiters_replacer_regex = re.compile(r'(\\*)([,;]+)')
def _EscapeVCProjCommandLineArgListItem(s):
"""Escapes command line arguments for MSVS.
The VCProj format stores string lists in a single string using commas and
semi-colons as separators, which must be quoted if they are to be
interpreted literally. However, command-line arguments may already have
quotes, and the VCProj parser is ignorant of the backslash escaping
convention used by CommandLineToArgv, so the command-line quotes and the
VCProj quotes may not be the same quotes. So to store a general
command-line argument in a VCProj list, we need to parse the existing
quoting according to VCProj's convention and quote any delimiters that are
not already quoted by that convention. The quotes that we add will also be
seen by CommandLineToArgv, so if backslashes precede them then we also have
to escape those backslashes according to the CommandLineToArgv
convention.
Args:
s: the string to be escaped.
Returns:
the escaped string.
"""
def _Replace(match):
# For a non-literal quote, CommandLineToArgv requires an even number of
# backslashes preceding it, and it produces half as many literal
# backslashes. So we need to produce 2n backslashes.
return 2 * match.group(1) + '"' + match.group(2) + '"'
segments = s.split('"')
# The unquoted segments are at the even-numbered indices.
for i in range(0, len(segments), 2):
segments[i] = delimiters_replacer_regex.sub(_Replace, segments[i])
# Concatenate back into a single string
s = '"'.join(segments)
if len(segments) % 2 == 0:
# String ends while still quoted according to VCProj's convention. This
# means the delimiter and the next list item that follow this one in the
# .vcproj file will be misinterpreted as part of this item. There is nothing
# we can do about this. Adding an extra quote would correct the problem in
# the VCProj but cause the same problem on the final command-line. Moving
# the item to the end of the list does works, but that's only possible if
# there's only one such item. Let's just warn the user.
print >> sys.stderr, ('Warning: MSVS may misinterpret the odd number of ' +
'quotes in ' + s)
return s
def _EscapeCppDefineForMSVS(s):
"""Escapes a CPP define so that it will reach the compiler unaltered."""
s = _EscapeEnvironmentVariableExpansion(s)
s = _EscapeCommandLineArgumentForMSVS(s)
s = _EscapeVCProjCommandLineArgListItem(s)
# cl.exe replaces literal # characters with = in preprocesor definitions for
# some reason. Octal-encode to work around that.
s = s.replace('#', '\\%03o' % ord('#'))
return s
quote_replacer_regex2 = re.compile(r'(\\+)"')
def _EscapeCommandLineArgumentForMSBuild(s):
"""Escapes a Windows command-line argument for use by MSBuild."""
def _Replace(match):
return (len(match.group(1)) / 2 * 4) * '\\' + '\\"'
# Escape all quotes so that they are interpreted literally.
s = quote_replacer_regex2.sub(_Replace, s)
return s
def _EscapeMSBuildSpecialCharacters(s):
escape_dictionary = {
'%': '%25',
'$': '%24',
'@': '%40',
"'": '%27',
';': '%3B',
'?': '%3F',
'*': '%2A'
}
result = ''.join([escape_dictionary.get(c, c) for c in s])
return result
def _EscapeCppDefineForMSBuild(s):
"""Escapes a CPP define so that it will reach the compiler unaltered."""
s = _EscapeEnvironmentVariableExpansion(s)
s = _EscapeCommandLineArgumentForMSBuild(s)
s = _EscapeMSBuildSpecialCharacters(s)
# cl.exe replaces literal # characters with = in preprocesor definitions for
# some reason. Octal-encode to work around that.
s = s.replace('#', '\\%03o' % ord('#'))
return s
def _GenerateRulesForMSVS(p, output_dir, options, spec,
sources, excluded_sources,
actions_to_add):
"""Generate all the rules for a particular project.
Arguments:
p: the project
output_dir: directory to emit rules to
options: global options passed to the generator
spec: the specification for this project
sources: the set of all known source files in this project
excluded_sources: the set of sources excluded from normal processing
actions_to_add: deferred list of actions to add in
"""
rules = spec.get('rules', [])
rules_native = [r for r in rules if not int(r.get('msvs_external_rule', 0))]
rules_external = [r for r in rules if int(r.get('msvs_external_rule', 0))]
# Handle rules that use a native rules file.
if rules_native:
_GenerateNativeRulesForMSVS(p, rules_native, output_dir, spec, options)
# Handle external rules (non-native rules).
if rules_external:
_GenerateExternalRules(rules_external, output_dir, spec,
sources, options, actions_to_add)
_AdjustSourcesForRules(rules, sources, excluded_sources, False)
def _AdjustSourcesForRules(rules, sources, excluded_sources, is_msbuild):
# Add outputs generated by each rule (if applicable).
for rule in rules:
# Add in the outputs from this rule.
trigger_files = _FindRuleTriggerFiles(rule, sources)
for trigger_file in trigger_files:
# Remove trigger_file from excluded_sources to let the rule be triggered
# (e.g. rule trigger ax_enums.idl is added to excluded_sources
# because it's also in an action's inputs in the same project)
excluded_sources.discard(_FixPath(trigger_file))
# Done if not processing outputs as sources.
if int(rule.get('process_outputs_as_sources', False)):
inputs, outputs = _RuleInputsAndOutputs(rule, trigger_file)
inputs = OrderedSet(_FixPaths(inputs))
outputs = OrderedSet(_FixPaths(outputs))
inputs.remove(_FixPath(trigger_file))
sources.update(inputs)
if not is_msbuild:
excluded_sources.update(inputs)
sources.update(outputs)
def _FilterActionsFromExcluded(excluded_sources, actions_to_add):
"""Take inputs with actions attached out of the list of exclusions.
Arguments:
excluded_sources: list of source files not to be built.
actions_to_add: dict of actions keyed on source file they're attached to.
Returns:
excluded_sources with files that have actions attached removed.
"""
must_keep = OrderedSet(_FixPaths(actions_to_add.keys()))
return [s for s in excluded_sources if s not in must_keep]
def _GetDefaultConfiguration(spec):
return spec['configurations'][spec['default_configuration']]
def _GetGuidOfProject(proj_path, spec):
"""Get the guid for the project.
Arguments:
proj_path: Path of the vcproj or vcxproj file to generate.
spec: The target dictionary containing the properties of the target.
Returns:
the guid.
Raises:
ValueError: if the specified GUID is invalid.
"""
# Pluck out the default configuration.
default_config = _GetDefaultConfiguration(spec)
# Decide the guid of the project.
guid = default_config.get('msvs_guid')
if guid:
if VALID_MSVS_GUID_CHARS.match(guid) is None:
raise ValueError('Invalid MSVS guid: "%s". Must match regex: "%s".' %
(guid, VALID_MSVS_GUID_CHARS.pattern))
guid = '{%s}' % guid
guid = guid or MSVSNew.MakeGuid(proj_path)
return guid
def _GetMsbuildToolsetOfProject(proj_path, spec, version):
"""Get the platform toolset for the project.
Arguments:
proj_path: Path of the vcproj or vcxproj file to generate.
spec: The target dictionary containing the properties of the target.
version: The MSVSVersion object.
Returns:
the platform toolset string or None.
"""
# Pluck out the default configuration.
default_config = _GetDefaultConfiguration(spec)
toolset = default_config.get('msbuild_toolset')
if not toolset and version.DefaultToolset():
toolset = version.DefaultToolset()
return toolset
def _GenerateProject(project, options, version, generator_flags):
"""Generates a vcproj file.
Arguments:
project: the MSVSProject object.
options: global generator options.
version: the MSVSVersion object.
generator_flags: dict of generator-specific flags.
Returns:
A list of source files that cannot be found on disk.
"""
default_config = _GetDefaultConfiguration(project.spec)
# Skip emitting anything if told to with msvs_existing_vcproj option.
if default_config.get('msvs_existing_vcproj'):
return []
if version.UsesVcxproj():
return _GenerateMSBuildProject(project, options, version, generator_flags)
else:
return _GenerateMSVSProject(project, options, version, generator_flags)
# TODO: Avoid code duplication with _ValidateSourcesForOSX in make.py.
def _ValidateSourcesForMSVSProject(spec, version):
"""Makes sure if duplicate basenames are not specified in the source list.
Arguments:
spec: The target dictionary containing the properties of the target.
version: The VisualStudioVersion object.
"""
# This validation should not be applied to MSVC2010 and later.
assert not version.UsesVcxproj()
# TODO: Check if MSVC allows this for loadable_module targets.
if spec.get('type', None) not in ('static_library', 'shared_library'):
return
sources = spec.get('sources', [])
basenames = {}
for source in sources:
name, ext = os.path.splitext(source)
is_compiled_file = ext in [
'.c', '.cc', '.cpp', '.cxx', '.m', '.mm', '.s', '.S']
if not is_compiled_file:
continue
basename = os.path.basename(name) # Don't include extension.
basenames.setdefault(basename, []).append(source)
error = ''
for basename, files in basenames.iteritems():
if len(files) > 1:
error += ' %s: %s\n' % (basename, ' '.join(files))
if error:
print('static library %s has several files with the same basename:\n' %
spec['target_name'] + error + 'MSVC08 cannot handle that.')
raise GypError('Duplicate basenames in sources section, see list above')
def _GenerateMSVSProject(project, options, version, generator_flags):
"""Generates a .vcproj file. It may create .rules and .user files too.
Arguments:
project: The project object we will generate the file for.
options: Global options passed to the generator.
version: The VisualStudioVersion object.
generator_flags: dict of generator-specific flags.
"""
spec = project.spec
gyp.common.EnsureDirExists(project.path)
platforms = _GetUniquePlatforms(spec)
p = MSVSProject.Writer(project.path, version, spec['target_name'],
project.guid, platforms)
# Get directory project file is in.
project_dir = os.path.split(project.path)[0]
gyp_path = _NormalizedSource(project.build_file)
relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
config_type = _GetMSVSConfigurationType(spec, project.build_file)
for config_name, config in spec['configurations'].iteritems():
_AddConfigurationToMSVSProject(p, spec, config_type, config_name, config)
# MSVC08 and prior version cannot handle duplicate basenames in the same
# target.
# TODO: Take excluded sources into consideration if possible.
_ValidateSourcesForMSVSProject(spec, version)
# Prepare list of sources and excluded sources.
gyp_file = os.path.split(project.build_file)[1]
sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
gyp_file)
# Add rules.
actions_to_add = {}
_GenerateRulesForMSVS(p, project_dir, options, spec,
sources, excluded_sources,
actions_to_add)
list_excluded = generator_flags.get('msvs_list_excluded_files', True)
sources, excluded_sources, excluded_idl = (
_AdjustSourcesAndConvertToFilterHierarchy(spec, options, project_dir,
sources, excluded_sources,
list_excluded, version))
# Add in files.
missing_sources = _VerifySourcesExist(sources, project_dir)
p.AddFiles(sources)
_AddToolFilesToMSVS(p, spec)
_HandlePreCompiledHeaders(p, sources, spec)
_AddActions(actions_to_add, spec, relative_path_of_gyp_file)
_AddCopies(actions_to_add, spec)
_WriteMSVSUserFile(project.path, version, spec)
# NOTE: this stanza must appear after all actions have been decided.
# Don't excluded sources with actions attached, or they won't run.
excluded_sources = _FilterActionsFromExcluded(
excluded_sources, actions_to_add)
_ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
list_excluded)
_AddAccumulatedActionsToMSVS(p, spec, actions_to_add)
# Write it out.
p.WriteIfChanged()
return missing_sources
def _GetUniquePlatforms(spec):
"""Returns the list of unique platforms for this spec, e.g ['win32', ...].
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
The MSVSUserFile object created.
"""
# Gather list of unique platforms.
platforms = OrderedSet()
for configuration in spec['configurations']:
platforms.add(_ConfigPlatform(spec['configurations'][configuration]))
platforms = list(platforms)
return platforms
def _CreateMSVSUserFile(proj_path, version, spec):
"""Generates a .user file for the user running this Gyp program.
Arguments:
proj_path: The path of the project file being created. The .user file
shares the same path (with an appropriate suffix).
version: The VisualStudioVersion object.
spec: The target dictionary containing the properties of the target.
Returns:
The MSVSUserFile object created.
"""
(domain, username) = _GetDomainAndUserName()
vcuser_filename = '.'.join([proj_path, domain, username, 'user'])
user_file = MSVSUserFile.Writer(vcuser_filename, version,
spec['target_name'])
return user_file
def _GetMSVSConfigurationType(spec, build_file):
"""Returns the configuration type for this project.
It's a number defined by Microsoft. May raise an exception.
Args:
spec: The target dictionary containing the properties of the target.
build_file: The path of the gyp file.
Returns:
An integer, the configuration type.
"""
try:
config_type = {
'executable': '1', # .exe
'shared_library': '2', # .dll
'loadable_module': '2', # .dll
'static_library': '4', # .lib
'none': '10', # Utility type
}[spec['type']]
except KeyError:
if spec.get('type'):
raise GypError('Target type %s is not a valid target type for '
'target %s in %s.' %
(spec['type'], spec['target_name'], build_file))
else:
raise GypError('Missing type field for target %s in %s.' %
(spec['target_name'], build_file))
return config_type
def _AddConfigurationToMSVSProject(p, spec, config_type, config_name, config):
"""Adds a configuration to the MSVS project.
Many settings in a vcproj file are specific to a configuration. This
function the main part of the vcproj file that's configuration specific.
Arguments:
p: The target project being generated.
spec: The target dictionary containing the properties of the target.
config_type: The configuration type, a number as defined by Microsoft.
config_name: The name of the configuration.
config: The dictionary that defines the special processing to be done
for this configuration.
"""
# Get the information for this configuration
include_dirs, midl_include_dirs, resource_include_dirs = \
_GetIncludeDirs(config)
libraries = _GetLibraries(spec)
library_dirs = _GetLibraryDirs(config)
out_file, vc_tool, _ = _GetOutputFilePathAndTool(spec, msbuild=False)
defines = _GetDefines(config)
defines = [_EscapeCppDefineForMSVS(d) for d in defines]
disabled_warnings = _GetDisabledWarnings(config)
prebuild = config.get('msvs_prebuild')
postbuild = config.get('msvs_postbuild')
def_file = _GetModuleDefinition(spec)
precompiled_header = config.get('msvs_precompiled_header')
# Prepare the list of tools as a dictionary.
tools = dict()
# Add in user specified msvs_settings.
msvs_settings = config.get('msvs_settings', {})
MSVSSettings.ValidateMSVSSettings(msvs_settings)
# Prevent default library inheritance from the environment.
_ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', ['$(NOINHERIT)'])
for tool in msvs_settings:
settings = config['msvs_settings'][tool]
for setting in settings:
_ToolAppend(tools, tool, setting, settings[setting])
# Add the information to the appropriate tool
_ToolAppend(tools, 'VCCLCompilerTool',
'AdditionalIncludeDirectories', include_dirs)
_ToolAppend(tools, 'VCMIDLTool',
'AdditionalIncludeDirectories', midl_include_dirs)
_ToolAppend(tools, 'VCResourceCompilerTool',
'AdditionalIncludeDirectories', resource_include_dirs)
# Add in libraries.
_ToolAppend(tools, 'VCLinkerTool', 'AdditionalDependencies', libraries)
_ToolAppend(tools, 'VCLinkerTool', 'AdditionalLibraryDirectories',
library_dirs)
if out_file:
_ToolAppend(tools, vc_tool, 'OutputFile', out_file, only_if_unset=True)
# Add defines.
_ToolAppend(tools, 'VCCLCompilerTool', 'PreprocessorDefinitions', defines)
_ToolAppend(tools, 'VCResourceCompilerTool', 'PreprocessorDefinitions',
defines)
# Change program database directory to prevent collisions.
_ToolAppend(tools, 'VCCLCompilerTool', 'ProgramDataBaseFileName',
'$(IntDir)$(ProjectName)\\vc80.pdb', only_if_unset=True)
# Add disabled warnings.
_ToolAppend(tools, 'VCCLCompilerTool',
'DisableSpecificWarnings', disabled_warnings)
# Add Pre-build.
_ToolAppend(tools, 'VCPreBuildEventTool', 'CommandLine', prebuild)
# Add Post-build.
_ToolAppend(tools, 'VCPostBuildEventTool', 'CommandLine', postbuild)
# Turn on precompiled headers if appropriate.
if precompiled_header:
precompiled_header = os.path.split(precompiled_header)[1]
_ToolAppend(tools, 'VCCLCompilerTool', 'UsePrecompiledHeader', '2')
_ToolAppend(tools, 'VCCLCompilerTool',
'PrecompiledHeaderThrough', precompiled_header)
_ToolAppend(tools, 'VCCLCompilerTool',
'ForcedIncludeFiles', precompiled_header)
# Loadable modules don't generate import libraries;
# tell dependent projects to not expect one.
if spec['type'] == 'loadable_module':
_ToolAppend(tools, 'VCLinkerTool', 'IgnoreImportLibrary', 'true')
# Set the module definition file if any.
if def_file:
_ToolAppend(tools, 'VCLinkerTool', 'ModuleDefinitionFile', def_file)
_AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name)
def _GetIncludeDirs(config):
"""Returns the list of directories to be used for #include directives.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of directory paths.
"""
# TODO(bradnelson): include_dirs should really be flexible enough not to
# require this sort of thing.
include_dirs = (
config.get('include_dirs', []) +
config.get('msvs_system_include_dirs', []))
midl_include_dirs = (
config.get('midl_include_dirs', []) +
config.get('msvs_system_include_dirs', []))
resource_include_dirs = config.get('resource_include_dirs', include_dirs)
include_dirs = _FixPaths(include_dirs)
midl_include_dirs = _FixPaths(midl_include_dirs)
resource_include_dirs = _FixPaths(resource_include_dirs)
return include_dirs, midl_include_dirs, resource_include_dirs
def _GetLibraryDirs(config):
"""Returns the list of directories to be used for library search paths.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of directory paths.
"""
library_dirs = config.get('library_dirs', [])
library_dirs = _FixPaths(library_dirs)
return library_dirs
def _GetLibraries(spec):
"""Returns the list of libraries for this configuration.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
The list of directory paths.
"""
libraries = spec.get('libraries', [])
# Strip out -l, as it is not used on windows (but is needed so we can pass
# in libraries that are assumed to be in the default library path).
# Also remove duplicate entries, leaving only the last duplicate, while
# preserving order.
found = OrderedSet()
unique_libraries_list = []
for entry in reversed(libraries):
library = re.sub(r'^\-l', '', entry)
if not os.path.splitext(library)[1]:
library += '.lib'
if library not in found:
found.add(library)
unique_libraries_list.append(library)
unique_libraries_list.reverse()
return unique_libraries_list
def _GetOutputFilePathAndTool(spec, msbuild):
"""Returns the path and tool to use for this target.
Figures out the path of the file this spec will create and the name of
the VC tool that will create it.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
A triple of (file path, name of the vc tool, name of the msbuild tool)
"""
# Select a name for the output file.
out_file = ''
vc_tool = ''
msbuild_tool = ''
output_file_map = {
'executable': ('VCLinkerTool', 'Link', '$(OutDir)', '.exe'),
'shared_library': ('VCLinkerTool', 'Link', '$(OutDir)', '.dll'),
'loadable_module': ('VCLinkerTool', 'Link', '$(OutDir)', '.dll'),
'static_library': ('VCLibrarianTool', 'Lib', '$(OutDir)lib\\', '.lib'),
}
output_file_props = output_file_map.get(spec['type'])
if output_file_props and int(spec.get('msvs_auto_output_file', 1)):
vc_tool, msbuild_tool, out_dir, suffix = output_file_props
if spec.get('standalone_static_library', 0):
out_dir = '$(OutDir)'
out_dir = spec.get('product_dir', out_dir)
product_extension = spec.get('product_extension')
if product_extension:
suffix = '.' + product_extension
elif msbuild:
suffix = '$(TargetExt)'
prefix = spec.get('product_prefix', '')
product_name = spec.get('product_name', '$(ProjectName)')
out_file = ntpath.join(out_dir, prefix + product_name + suffix)
return out_file, vc_tool, msbuild_tool
def _GetOutputTargetExt(spec):
"""Returns the extension for this target, including the dot
If product_extension is specified, set target_extension to this to avoid
MSB8012, returns None otherwise. Ignores any target_extension settings in
the input files.
Arguments:
spec: The target dictionary containing the properties of the target.
Returns:
A string with the extension, or None
"""
target_extension = spec.get('product_extension')
if target_extension:
return '.' + target_extension
return None
def _GetDefines(config):
"""Returns the list of preprocessor definitions for this configuation.
Arguments:
config: The dictionary that defines the special processing to be done
for this configuration.
Returns:
The list of preprocessor definitions.
"""
defines = []
for d in config.get('defines', []):
if type(d) == list:
fd = '='.join([str(dpart) for dpart in d])
else:
fd = str(d)
defines.append(fd)
return defines
def _GetDisabledWarnings(config):
return [str(i) for i in config.get('msvs_disabled_warnings', [])]
def _GetModuleDefinition(spec):
def_file = ''
if spec['type'] in ['shared_library', 'loadable_module', 'executable']:
def_files = [s for s in spec.get('sources', []) if s.endswith('.def')]
if len(def_files) == 1:
def_file = _FixPath(def_files[0])
elif def_files:
raise ValueError(
'Multiple module definition files in one target, target %s lists '
'multiple .def files: %s' % (
spec['target_name'], ' '.join(def_files)))
return def_file
def _ConvertToolsToExpectedForm(tools):
"""Convert tools to a form expected by Visual Studio.
Arguments:
tools: A dictionary of settings; the tool name is the key.
Returns:
A list of Tool objects.
"""
tool_list = []
for tool, settings in tools.iteritems():
# Collapse settings with lists.
settings_fixed = {}
for setting, value in settings.iteritems():
if type(value) == list:
if ((tool == 'VCLinkerTool' and
setting == 'AdditionalDependencies') or
setting == 'AdditionalOptions'):
settings_fixed[setting] = ' '.join(value)
else:
settings_fixed[setting] = ';'.join(value)
else:
settings_fixed[setting] = value
# Add in this tool.
tool_list.append(MSVSProject.Tool(tool, settings_fixed))
return tool_list
def _AddConfigurationToMSVS(p, spec, tools, config, config_type, config_name):
"""Add to the project file the configuration specified by config.
Arguments:
p: The target project being generated.
spec: the target project dict.
tools: A dictionary of settings; the tool name is the key.
config: The dictionary that defines the special processing to be done
for this configuration.
config_type: The configuration type, a number as defined by Microsoft.
config_name: The name of the configuration.
"""
attributes = _GetMSVSAttributes(spec, config, config_type)
# Add in this configuration.
tool_list = _ConvertToolsToExpectedForm(tools)
p.AddConfig(_ConfigFullName(config_name, config),
attrs=attributes, tools=tool_list)
def _GetMSVSAttributes(spec, config, config_type):
# Prepare configuration attributes.
prepared_attrs = {}
source_attrs = config.get('msvs_configuration_attributes', {})
for a in source_attrs:
prepared_attrs[a] = source_attrs[a]
# Add props files.
vsprops_dirs = config.get('msvs_props', [])
vsprops_dirs = _FixPaths(vsprops_dirs)
if vsprops_dirs:
prepared_attrs['InheritedPropertySheets'] = ';'.join(vsprops_dirs)
# Set configuration type.
prepared_attrs['ConfigurationType'] = config_type
output_dir = prepared_attrs.get('OutputDirectory',
'$(SolutionDir)$(ConfigurationName)')
prepared_attrs['OutputDirectory'] = _FixPath(output_dir) + '\\'
if 'IntermediateDirectory' not in prepared_attrs:
intermediate = '$(ConfigurationName)\\obj\\$(ProjectName)'
prepared_attrs['IntermediateDirectory'] = _FixPath(intermediate) + '\\'
else:
intermediate = _FixPath(prepared_attrs['IntermediateDirectory']) + '\\'
intermediate = MSVSSettings.FixVCMacroSlashes(intermediate)
prepared_attrs['IntermediateDirectory'] = intermediate
return prepared_attrs
def _AddNormalizedSources(sources_set, sources_array):
sources_set.update(_NormalizedSource(s) for s in sources_array)
def _PrepareListOfSources(spec, generator_flags, gyp_file):
"""Prepare list of sources and excluded sources.
Besides the sources specified directly in the spec, adds the gyp file so
that a change to it will cause a re-compile. Also adds appropriate sources
for actions and copies. Assumes later stage will un-exclude files which
have custom build steps attached.
Arguments:
spec: The target dictionary containing the properties of the target.
gyp_file: The name of the gyp file.
Returns:
A pair of (list of sources, list of excluded sources).
The sources will be relative to the gyp file.
"""
sources = OrderedSet()
_AddNormalizedSources(sources, spec.get('sources', []))
excluded_sources = OrderedSet()
# Add in the gyp file.
if not generator_flags.get('standalone'):
sources.add(gyp_file)
# Add in 'action' inputs and outputs.
for a in spec.get('actions', []):
inputs = a['inputs']
inputs = [_NormalizedSource(i) for i in inputs]
# Add all inputs to sources and excluded sources.
inputs = OrderedSet(inputs)
sources.update(inputs)
if not spec.get('msvs_external_builder'):
excluded_sources.update(inputs)
if int(a.get('process_outputs_as_sources', False)):
_AddNormalizedSources(sources, a.get('outputs', []))
# Add in 'copies' inputs and outputs.
for cpy in spec.get('copies', []):
_AddNormalizedSources(sources, cpy.get('files', []))
return (sources, excluded_sources)
def _AdjustSourcesAndConvertToFilterHierarchy(
spec, options, gyp_dir, sources, excluded_sources, list_excluded, version):
"""Adjusts the list of sources and excluded sources.
Also converts the sets to lists.
Arguments:
spec: The target dictionary containing the properties of the target.
options: Global generator options.
gyp_dir: The path to the gyp file being processed.
sources: A set of sources to be included for this project.
excluded_sources: A set of sources to be excluded for this project.
version: A MSVSVersion object.
Returns:
A trio of (list of sources, list of excluded sources,
path of excluded IDL file)
"""
# Exclude excluded sources coming into the generator.
excluded_sources.update(OrderedSet(spec.get('sources_excluded', [])))
# Add excluded sources into sources for good measure.
sources.update(excluded_sources)
# Convert to proper windows form.
# NOTE: sources goes from being a set to a list here.
# NOTE: excluded_sources goes from being a set to a list here.
sources = _FixPaths(sources)
# Convert to proper windows form.
excluded_sources = _FixPaths(excluded_sources)
excluded_idl = _IdlFilesHandledNonNatively(spec, sources)
precompiled_related = _GetPrecompileRelatedFiles(spec)
# Find the excluded ones, minus the precompiled header related ones.
fully_excluded = [i for i in excluded_sources if i not in precompiled_related]
# Convert to folders and the right slashes.
sources = [i.split('\\') for i in sources]
sources = _ConvertSourcesToFilterHierarchy(sources, excluded=fully_excluded,
list_excluded=list_excluded,
msvs_version=version)
# Prune filters with a single child to flatten ugly directory structures
# such as ../../src/modules/module1 etc.
if version.UsesVcxproj():
while all([isinstance(s, MSVSProject.Filter) for s in sources]) \
and len(set([s.name for s in sources])) == 1:
assert all([len(s.contents) == 1 for s in sources])
sources = [s.contents[0] for s in sources]
else:
while len(sources) == 1 and isinstance(sources[0], MSVSProject.Filter):
sources = sources[0].contents
return sources, excluded_sources, excluded_idl
def _IdlFilesHandledNonNatively(spec, sources):
# If any non-native rules use 'idl' as an extension exclude idl files.
# Gather a list here to use later.
using_idl = False
for rule in spec.get('rules', []):
if rule['extension'] == 'idl' and int(rule.get('msvs_external_rule', 0)):
using_idl = True
break
if using_idl:
excluded_idl = [i for i in sources if i.endswith('.idl')]
else:
excluded_idl = []
return excluded_idl
def _GetPrecompileRelatedFiles(spec):
# Gather a list of precompiled header related sources.
precompiled_related = []
for _, config in spec['configurations'].iteritems():
for k in precomp_keys:
f = config.get(k)
if f:
precompiled_related.append(_FixPath(f))
return precompiled_related
def _ExcludeFilesFromBeingBuilt(p, spec, excluded_sources, excluded_idl,
list_excluded):
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
for file_name, excluded_configs in exclusions.iteritems():
if (not list_excluded and
len(excluded_configs) == len(spec['configurations'])):
# If we're not listing excluded files, then they won't appear in the
# project, so don't try to configure them to be excluded.
pass
else:
for config_name, config in excluded_configs:
p.AddFileConfig(file_name, _ConfigFullName(config_name, config),
{'ExcludedFromBuild': 'true'})
def _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl):
exclusions = {}
# Exclude excluded sources from being built.
for f in excluded_sources:
excluded_configs = []
for config_name, config in spec['configurations'].iteritems():
precomped = [_FixPath(config.get(i, '')) for i in precomp_keys]
# Don't do this for ones that are precompiled header related.
if f not in precomped:
excluded_configs.append((config_name, config))
exclusions[f] = excluded_configs
# If any non-native rules use 'idl' as an extension exclude idl files.
# Exclude them now.
for f in excluded_idl:
excluded_configs = []
for config_name, config in spec['configurations'].iteritems():
excluded_configs.append((config_name, config))
exclusions[f] = excluded_configs
return exclusions
def _AddToolFilesToMSVS(p, spec):
# Add in tool files (rules).
tool_files = OrderedSet()
for _, config in spec['configurations'].iteritems():
for f in config.get('msvs_tool_files', []):
tool_files.add(f)
for f in tool_files:
p.AddToolFile(f)
def _HandlePreCompiledHeaders(p, sources, spec):
# Pre-compiled header source stubs need a different compiler flag
# (generate precompiled header) and any source file not of the same
# kind (i.e. C vs. C++) as the precompiled header source stub needs
# to have use of precompiled headers disabled.
extensions_excluded_from_precompile = []
for config_name, config in spec['configurations'].iteritems():
source = config.get('msvs_precompiled_source')
if source:
source = _FixPath(source)
# UsePrecompiledHeader=1 for if using precompiled headers.
tool = MSVSProject.Tool('VCCLCompilerTool',
{'UsePrecompiledHeader': '1'})
p.AddFileConfig(source, _ConfigFullName(config_name, config),
{}, tools=[tool])
basename, extension = os.path.splitext(source)
if extension == '.c':
extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx']
else:
extensions_excluded_from_precompile = ['.c']
def DisableForSourceTree(source_tree):
for source in source_tree:
if isinstance(source, MSVSProject.Filter):
DisableForSourceTree(source.contents)
else:
basename, extension = os.path.splitext(source)
if extension in extensions_excluded_from_precompile:
for config_name, config in spec['configurations'].iteritems():
tool = MSVSProject.Tool('VCCLCompilerTool',
{'UsePrecompiledHeader': '0',
'ForcedIncludeFiles': '$(NOINHERIT)'})
p.AddFileConfig(_FixPath(source),
_ConfigFullName(config_name, config),
{}, tools=[tool])
# Do nothing if there was no precompiled source.
if extensions_excluded_from_precompile:
DisableForSourceTree(sources)
def _AddActions(actions_to_add, spec, relative_path_of_gyp_file):
# Add actions.
actions = spec.get('actions', [])
# Don't setup_env every time. When all the actions are run together in one
# batch file in VS, the PATH will grow too long.
# Membership in this set means that the cygwin environment has been set up,
# and does not need to be set up again.
have_setup_env = set()
for a in actions:
# Attach actions to the gyp file if nothing else is there.
inputs = a.get('inputs') or [relative_path_of_gyp_file]
attached_to = inputs[0]
need_setup_env = attached_to not in have_setup_env
cmd = _BuildCommandLineForRule(spec, a, has_input_path=False,
do_setup_env=need_setup_env)
have_setup_env.add(attached_to)
# Add the action.
_AddActionStep(actions_to_add,
inputs=inputs,
outputs=a.get('outputs', []),
description=a.get('message', a['action_name']),
command=cmd)
def _WriteMSVSUserFile(project_path, version, spec):
# Add run_as and test targets.
if 'run_as' in spec:
run_as = spec['run_as']
action = run_as.get('action', [])
environment = run_as.get('environment', [])
working_directory = run_as.get('working_directory', '.')
elif int(spec.get('test', 0)):
action = ['$(TargetPath)', '--gtest_print_time']
environment = []
working_directory = '.'
else:
return # Nothing to add
# Write out the user file.
user_file = _CreateMSVSUserFile(project_path, version, spec)
for config_name, c_data in spec['configurations'].iteritems():
user_file.AddDebugSettings(_ConfigFullName(config_name, c_data),
action, environment, working_directory)
user_file.WriteIfChanged()
def _AddCopies(actions_to_add, spec):
copies = _GetCopies(spec)
for inputs, outputs, cmd, description in copies:
_AddActionStep(actions_to_add, inputs=inputs, outputs=outputs,
description=description, command=cmd)
def _GetCopies(spec):
copies = []
# Add copies.
for cpy in spec.get('copies', []):
for src in cpy.get('files', []):
dst = os.path.join(cpy['destination'], os.path.basename(src))
# _AddCustomBuildToolForMSVS() will call _FixPath() on the inputs and
# outputs, so do the same for our generated command line.
if src.endswith('/'):
src_bare = src[:-1]
base_dir = posixpath.split(src_bare)[0]
outer_dir = posixpath.split(src_bare)[1]
cmd = 'cd "%s" && xcopy /e /f /y "%s" "%s\\%s\\"' % (
_FixPath(base_dir), outer_dir, _FixPath(dst), outer_dir)
copies.append(([src], ['dummy_copies', dst], cmd,
'Copying %s to %s' % (src, dst)))
else:
cmd = 'mkdir "%s" 2>nul & set ERRORLEVEL=0 & copy /Y "%s" "%s"' % (
_FixPath(cpy['destination']), _FixPath(src), _FixPath(dst))
copies.append(([src], [dst], cmd, 'Copying %s to %s' % (src, dst)))
return copies
def _GetPathDict(root, path):
# |path| will eventually be empty (in the recursive calls) if it was initially
# relative; otherwise it will eventually end up as '\', 'D:\', etc.
if not path or path.endswith(os.sep):
return root
parent, folder = os.path.split(path)
parent_dict = _GetPathDict(root, parent)
if folder not in parent_dict:
parent_dict[folder] = dict()
return parent_dict[folder]
def _DictsToFolders(base_path, bucket, flat):
# Convert to folders recursively.
children = []
for folder, contents in bucket.iteritems():
if type(contents) == dict:
folder_children = _DictsToFolders(os.path.join(base_path, folder),
contents, flat)
if flat:
children += folder_children
else:
folder_children = MSVSNew.MSVSFolder(os.path.join(base_path, folder),
name='(' + folder + ')',
entries=folder_children)
children.append(folder_children)
else:
children.append(contents)
return children
def _CollapseSingles(parent, node):
# Recursively explorer the tree of dicts looking for projects which are
# the sole item in a folder which has the same name as the project. Bring
# such projects up one level.
if (type(node) == dict and
len(node) == 1 and
node.keys()[0] == parent + '.vcproj'):
return node[node.keys()[0]]
if type(node) != dict:
return node
for child in node:
node[child] = _CollapseSingles(child, node[child])
return node
def _GatherSolutionFolders(sln_projects, project_objects, flat):
root = {}
# Convert into a tree of dicts on path.
for p in sln_projects:
gyp_file, target = gyp.common.ParseQualifiedTarget(p)[0:2]
gyp_dir = os.path.dirname(gyp_file)
path_dict = _GetPathDict(root, gyp_dir)
path_dict[target + '.vcproj'] = project_objects[p]
# Walk down from the top until we hit a folder that has more than one entry.
# In practice, this strips the top-level "src/" dir from the hierarchy in
# the solution.
while len(root) == 1 and type(root[root.keys()[0]]) == dict:
root = root[root.keys()[0]]
# Collapse singles.
root = _CollapseSingles('', root)
# Merge buckets until everything is a root entry.
return _DictsToFolders('', root, flat)
def _GetPathOfProject(qualified_target, spec, options, msvs_version):
default_config = _GetDefaultConfiguration(spec)
proj_filename = default_config.get('msvs_existing_vcproj')
if not proj_filename:
proj_filename = (spec['target_name'] + options.suffix +
msvs_version.ProjectExtension())
build_file = gyp.common.BuildFile(qualified_target)
proj_path = os.path.join(os.path.dirname(build_file), proj_filename)
fix_prefix = None
if options.generator_output:
project_dir_path = os.path.dirname(os.path.abspath(proj_path))
proj_path = os.path.join(options.generator_output, proj_path)
fix_prefix = gyp.common.RelativePath(project_dir_path,
os.path.dirname(proj_path))
return proj_path, fix_prefix
def _GetPlatformOverridesOfProject(spec):
# Prepare a dict indicating which project configurations are used for which
# solution configurations for this target.
config_platform_overrides = {}
for config_name, c in spec['configurations'].iteritems():
config_fullname = _ConfigFullName(config_name, c)
platform = c.get('msvs_target_platform', _ConfigPlatform(c))
fixed_config_fullname = '%s|%s' % (
_ConfigBaseName(config_name, _ConfigPlatform(c)), platform)
config_platform_overrides[config_fullname] = fixed_config_fullname
return config_platform_overrides
def _CreateProjectObjects(target_list, target_dicts, options, msvs_version):
"""Create a MSVSProject object for the targets found in target list.
Arguments:
target_list: the list of targets to generate project objects for.
target_dicts: the dictionary of specifications.
options: global generator options.
msvs_version: the MSVSVersion object.
Returns:
A set of created projects, keyed by target.
"""
global fixpath_prefix
# Generate each project.
projects = {}
for qualified_target in target_list:
spec = target_dicts[qualified_target]
if spec['toolset'] != 'target':
raise GypError(
'Multiple toolsets not supported in msvs build (target %s)' %
qualified_target)
proj_path, fixpath_prefix = _GetPathOfProject(qualified_target, spec,
options, msvs_version)
guid = _GetGuidOfProject(proj_path, spec)
overrides = _GetPlatformOverridesOfProject(spec)
build_file = gyp.common.BuildFile(qualified_target)
# Create object for this project.
obj = MSVSNew.MSVSProject(
proj_path,
name=spec['target_name'],
guid=guid,
spec=spec,
build_file=build_file,
config_platform_overrides=overrides,
fixpath_prefix=fixpath_prefix)
# Set project toolset if any (MS build only)
if msvs_version.UsesVcxproj():
obj.set_msbuild_toolset(
_GetMsbuildToolsetOfProject(proj_path, spec, msvs_version))
projects[qualified_target] = obj
# Set all the dependencies, but not if we are using an external builder like
# ninja
for project in projects.values():
if not project.spec.get('msvs_external_builder'):
deps = project.spec.get('dependencies', [])
deps = [projects[d] for d in deps]
project.set_dependencies(deps)
return projects
def _InitNinjaFlavor(params, target_list, target_dicts):
"""Initialize targets for the ninja flavor.
This sets up the necessary variables in the targets to generate msvs projects
that use ninja as an external builder. The variables in the spec are only set
if they have not been set. This allows individual specs to override the
default values initialized here.
Arguments:
params: Params provided to the generator.
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
"""
for qualified_target in target_list:
spec = target_dicts[qualified_target]
if spec.get('msvs_external_builder'):
# The spec explicitly defined an external builder, so don't change it.
continue
path_to_ninja = spec.get('msvs_path_to_ninja', 'ninja.exe')
spec['msvs_external_builder'] = 'ninja'
if not spec.get('msvs_external_builder_out_dir'):
gyp_file, _, _ = gyp.common.ParseQualifiedTarget(qualified_target)
gyp_dir = os.path.dirname(gyp_file)
configuration = '$(Configuration)'
if params.get('target_arch') == 'x64':
configuration += '_x64'
spec['msvs_external_builder_out_dir'] = os.path.join(
gyp.common.RelativePath(params['options'].toplevel_dir, gyp_dir),
ninja_generator.ComputeOutputDir(params),
configuration)
if not spec.get('msvs_external_builder_build_cmd'):
spec['msvs_external_builder_build_cmd'] = [
path_to_ninja,
'-C',
'$(OutDir)',
'$(ProjectName)',
]
if not spec.get('msvs_external_builder_clean_cmd'):
spec['msvs_external_builder_clean_cmd'] = [
path_to_ninja,
'-C',
'$(OutDir)',
'-tclean',
'$(ProjectName)',
]
def CalculateVariables(default_variables, params):
"""Generated variables that require params to be known."""
generator_flags = params.get('generator_flags', {})
# Select project file format version (if unset, default to auto detecting).
msvs_version = MSVSVersion.SelectVisualStudioVersion(
generator_flags.get('msvs_version', 'auto'))
# Stash msvs_version for later (so we don't have to probe the system twice).
params['msvs_version'] = msvs_version
# Set a variable so conditions can be based on msvs_version.
default_variables['MSVS_VERSION'] = msvs_version.ShortName()
# To determine processor word size on Windows, in addition to checking
# PROCESSOR_ARCHITECTURE (which reflects the word size of the current
# process), it is also necessary to check PROCESSOR_ARCITEW6432 (which
# contains the actual word size of the system when running thru WOW64).
if (os.environ.get('PROCESSOR_ARCHITECTURE', '').find('64') >= 0 or
os.environ.get('PROCESSOR_ARCHITEW6432', '').find('64') >= 0):
default_variables['MSVS_OS_BITS'] = 64
else:
default_variables['MSVS_OS_BITS'] = 32
if gyp.common.GetFlavor(params) == 'ninja':
default_variables['SHARED_INTERMEDIATE_DIR'] = '$(OutDir)gen'
def PerformBuild(data, configurations, params):
options = params['options']
msvs_version = params['msvs_version']
devenv = os.path.join(msvs_version.path, 'Common7', 'IDE', 'devenv.com')
for build_file, build_file_dict in data.iteritems():
(build_file_root, build_file_ext) = os.path.splitext(build_file)
if build_file_ext != '.gyp':
continue
sln_path = build_file_root + options.suffix + '.sln'
if options.generator_output:
sln_path = os.path.join(options.generator_output, sln_path)
for config in configurations:
arguments = [devenv, sln_path, '/Build', config]
print 'Building [%s]: %s' % (config, arguments)
rtn = subprocess.check_call(arguments)
def GenerateOutput(target_list, target_dicts, data, params):
"""Generate .sln and .vcproj files.
This is the entry point for this generator.
Arguments:
target_list: List of target pairs: 'base/base.gyp:base'.
target_dicts: Dict of target properties keyed on target pair.
data: Dictionary containing per .gyp data.
"""
global fixpath_prefix
options = params['options']
# Get the project file format version back out of where we stashed it in
# GeneratorCalculatedVariables.
msvs_version = params['msvs_version']
generator_flags = params.get('generator_flags', {})
# Optionally shard targets marked with 'msvs_shard': SHARD_COUNT.
(target_list, target_dicts) = MSVSUtil.ShardTargets(target_list, target_dicts)
# Optionally use the large PDB workaround for targets marked with
# 'msvs_large_pdb': 1.
(target_list, target_dicts) = MSVSUtil.InsertLargePdbShims(
target_list, target_dicts, generator_default_variables)
# Optionally configure each spec to use ninja as the external builder.
if params.get('flavor') == 'ninja':
_InitNinjaFlavor(params, target_list, target_dicts)
# Prepare the set of configurations.
configs = set()
for qualified_target in target_list:
spec = target_dicts[qualified_target]
for config_name, config in spec['configurations'].iteritems():
configs.add(_ConfigFullName(config_name, config))
configs = list(configs)
# Figure out all the projects that will be generated and their guids
project_objects = _CreateProjectObjects(target_list, target_dicts, options,
msvs_version)
# Generate each project.
missing_sources = []
for project in project_objects.values():
fixpath_prefix = project.fixpath_prefix
missing_sources.extend(_GenerateProject(project, options, msvs_version,
generator_flags))
fixpath_prefix = None
for build_file in data:
# Validate build_file extension
if not build_file.endswith('.gyp'):
continue
sln_path = os.path.splitext(build_file)[0] + options.suffix + '.sln'
if options.generator_output:
sln_path = os.path.join(options.generator_output, sln_path)
# Get projects in the solution, and their dependents.
sln_projects = gyp.common.BuildFileTargets(target_list, build_file)
sln_projects += gyp.common.DeepDependencyTargets(target_dicts, sln_projects)
# Create folder hierarchy.
root_entries = _GatherSolutionFolders(
sln_projects, project_objects, flat=msvs_version.FlatSolution())
# Create solution.
sln = MSVSNew.MSVSSolution(sln_path,
entries=root_entries,
variants=configs,
websiteProperties=False,
version=msvs_version)
sln.Write()
if missing_sources:
error_message = "Missing input files:\n" + \
'\n'.join(set(missing_sources))
if generator_flags.get('msvs_error_on_missing_sources', False):
raise GypError(error_message)
else:
print >> sys.stdout, "Warning: " + error_message
def _GenerateMSBuildFiltersFile(filters_path, source_files,
rule_dependencies, extension_to_rule_name):
"""Generate the filters file.
This file is used by Visual Studio to organize the presentation of source
files into folders.
Arguments:
filters_path: The path of the file to be created.
source_files: The hierarchical structure of all the sources.
extension_to_rule_name: A dictionary mapping file extensions to rules.
"""
filter_group = []
source_group = []
_AppendFiltersForMSBuild('', source_files, rule_dependencies,
extension_to_rule_name, filter_group, source_group)
if filter_group:
content = ['Project',
{'ToolsVersion': '4.0',
'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'
},
['ItemGroup'] + filter_group,
['ItemGroup'] + source_group
]
easy_xml.WriteXmlIfChanged(content, filters_path, pretty=True, win32=True)
elif os.path.exists(filters_path):
# We don't need this filter anymore. Delete the old filter file.
os.unlink(filters_path)
def _AppendFiltersForMSBuild(parent_filter_name, sources, rule_dependencies,
extension_to_rule_name,
filter_group, source_group):
"""Creates the list of filters and sources to be added in the filter file.
Args:
parent_filter_name: The name of the filter under which the sources are
found.
sources: The hierarchy of filters and sources to process.
extension_to_rule_name: A dictionary mapping file extensions to rules.
filter_group: The list to which filter entries will be appended.
source_group: The list to which source entries will be appeneded.
"""
for source in sources:
if isinstance(source, MSVSProject.Filter):
# We have a sub-filter. Create the name of that sub-filter.
if not parent_filter_name:
filter_name = source.name
else:
filter_name = '%s\\%s' % (parent_filter_name, source.name)
# Add the filter to the group.
filter_group.append(
['Filter', {'Include': filter_name},
['UniqueIdentifier', MSVSNew.MakeGuid(source.name)]])
# Recurse and add its dependents.
_AppendFiltersForMSBuild(filter_name, source.contents,
rule_dependencies, extension_to_rule_name,
filter_group, source_group)
else:
# It's a source. Create a source entry.
_, element = _MapFileToMsBuildSourceType(source, rule_dependencies,
extension_to_rule_name)
source_entry = [element, {'Include': source}]
# Specify the filter it is part of, if any.
if parent_filter_name:
source_entry.append(['Filter', parent_filter_name])
source_group.append(source_entry)
def _MapFileToMsBuildSourceType(source, rule_dependencies,
extension_to_rule_name):
"""Returns the group and element type of the source file.
Arguments:
source: The source file name.
extension_to_rule_name: A dictionary mapping file extensions to rules.
Returns:
A pair of (group this file should be part of, the label of element)
"""
_, ext = os.path.splitext(source)
if ext in extension_to_rule_name:
group = 'rule'
element = extension_to_rule_name[ext]
elif ext in ['.cc', '.cpp', '.c', '.cxx']:
group = 'compile'
element = 'ClCompile'
elif ext in ['.h', '.hxx']:
group = 'include'
element = 'ClInclude'
elif ext == '.rc':
group = 'resource'
element = 'ResourceCompile'
elif ext == '.asm':
group = 'masm'
element = 'MASM'
elif ext == '.idl':
group = 'midl'
element = 'Midl'
elif source in rule_dependencies:
group = 'rule_dependency'
element = 'CustomBuild'
else:
group = 'none'
element = 'None'
return (group, element)
def _GenerateRulesForMSBuild(output_dir, options, spec,
sources, excluded_sources,
props_files_of_rules, targets_files_of_rules,
actions_to_add, rule_dependencies,
extension_to_rule_name):
# MSBuild rules are implemented using three files: an XML file, a .targets
# file and a .props file.
# See http://blogs.msdn.com/b/vcblog/archive/2010/04/21/quick-help-on-vs2010-custom-build-rule.aspx
# for more details.
rules = spec.get('rules', [])
rules_native = [r for r in rules if not int(r.get('msvs_external_rule', 0))]
rules_external = [r for r in rules if int(r.get('msvs_external_rule', 0))]
msbuild_rules = []
for rule in rules_native:
# Skip a rule with no action and no inputs.
if 'action' not in rule and not rule.get('rule_sources', []):
continue
msbuild_rule = MSBuildRule(rule, spec)
msbuild_rules.append(msbuild_rule)
rule_dependencies.update(msbuild_rule.additional_dependencies.split(';'))
extension_to_rule_name[msbuild_rule.extension] = msbuild_rule.rule_name
if msbuild_rules:
base = spec['target_name'] + options.suffix
props_name = base + '.props'
targets_name = base + '.targets'
xml_name = base + '.xml'
props_files_of_rules.add(props_name)
targets_files_of_rules.add(targets_name)
props_path = os.path.join(output_dir, props_name)
targets_path = os.path.join(output_dir, targets_name)
xml_path = os.path.join(output_dir, xml_name)
_GenerateMSBuildRulePropsFile(props_path, msbuild_rules)
_GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules)
_GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules)
if rules_external:
_GenerateExternalRules(rules_external, output_dir, spec,
sources, options, actions_to_add)
_AdjustSourcesForRules(rules, sources, excluded_sources, True)
class MSBuildRule(object):
"""Used to store information used to generate an MSBuild rule.
Attributes:
rule_name: The rule name, sanitized to use in XML.
target_name: The name of the target.
after_targets: The name of the AfterTargets element.
before_targets: The name of the BeforeTargets element.
depends_on: The name of the DependsOn element.
compute_output: The name of the ComputeOutput element.
dirs_to_make: The name of the DirsToMake element.
inputs: The name of the _inputs element.
tlog: The name of the _tlog element.
extension: The extension this rule applies to.
description: The message displayed when this rule is invoked.
additional_dependencies: A string listing additional dependencies.
outputs: The outputs of this rule.
command: The command used to run the rule.
"""
def __init__(self, rule, spec):
self.display_name = rule['rule_name']
# Assure that the rule name is only characters and numbers
self.rule_name = re.sub(r'\W', '_', self.display_name)
# Create the various element names, following the example set by the
# Visual Studio 2008 to 2010 conversion. I don't know if VS2010
# is sensitive to the exact names.
self.target_name = '_' + self.rule_name
self.after_targets = self.rule_name + 'AfterTargets'
self.before_targets = self.rule_name + 'BeforeTargets'
self.depends_on = self.rule_name + 'DependsOn'
self.compute_output = 'Compute%sOutput' % self.rule_name
self.dirs_to_make = self.rule_name + 'DirsToMake'
self.inputs = self.rule_name + '_inputs'
self.tlog = self.rule_name + '_tlog'
self.extension = rule['extension']
if not self.extension.startswith('.'):
self.extension = '.' + self.extension
self.description = MSVSSettings.ConvertVCMacrosToMSBuild(
rule.get('message', self.rule_name))
old_additional_dependencies = _FixPaths(rule.get('inputs', []))
self.additional_dependencies = (
';'.join([MSVSSettings.ConvertVCMacrosToMSBuild(i)
for i in old_additional_dependencies]))
old_outputs = _FixPaths(rule.get('outputs', []))
self.outputs = ';'.join([MSVSSettings.ConvertVCMacrosToMSBuild(i)
for i in old_outputs])
old_command = _BuildCommandLineForRule(spec, rule, has_input_path=True,
do_setup_env=True)
self.command = MSVSSettings.ConvertVCMacrosToMSBuild(old_command)
def _GenerateMSBuildRulePropsFile(props_path, msbuild_rules):
"""Generate the .props file."""
content = ['Project',
{'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'}]
for rule in msbuild_rules:
content.extend([
['PropertyGroup',
{'Condition': "'$(%s)' == '' and '$(%s)' == '' and "
"'$(ConfigurationType)' != 'Makefile'" % (rule.before_targets,
rule.after_targets)
},
[rule.before_targets, 'Midl'],
[rule.after_targets, 'CustomBuild'],
],
['PropertyGroup',
[rule.depends_on,
{'Condition': "'$(ConfigurationType)' != 'Makefile'"},
'_SelectedFiles;$(%s)' % rule.depends_on
],
],
['ItemDefinitionGroup',
[rule.rule_name,
['CommandLineTemplate', rule.command],
['Outputs', rule.outputs],
['ExecutionDescription', rule.description],
['AdditionalDependencies', rule.additional_dependencies],
],
]
])
easy_xml.WriteXmlIfChanged(content, props_path, pretty=True, win32=True)
def _GenerateMSBuildRuleTargetsFile(targets_path, msbuild_rules):
"""Generate the .targets file."""
content = ['Project',
{'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'
}
]
item_group = [
'ItemGroup',
['PropertyPageSchema',
{'Include': '$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml'}
]
]
for rule in msbuild_rules:
item_group.append(
['AvailableItemName',
{'Include': rule.rule_name},
['Targets', rule.target_name],
])
content.append(item_group)
for rule in msbuild_rules:
content.append(
['UsingTask',
{'TaskName': rule.rule_name,
'TaskFactory': 'XamlTaskFactory',
'AssemblyName': 'Microsoft.Build.Tasks.v4.0'
},
['Task', '$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml'],
])
for rule in msbuild_rules:
rule_name = rule.rule_name
target_outputs = '%%(%s.Outputs)' % rule_name
target_inputs = ('%%(%s.Identity);%%(%s.AdditionalDependencies);'
'$(MSBuildProjectFile)') % (rule_name, rule_name)
rule_inputs = '%%(%s.Identity)' % rule_name
extension_condition = ("'%(Extension)'=='.obj' or "
"'%(Extension)'=='.res' or "
"'%(Extension)'=='.rsc' or "
"'%(Extension)'=='.lib'")
remove_section = [
'ItemGroup',
{'Condition': "'@(SelectedFiles)' != ''"},
[rule_name,
{'Remove': '@(%s)' % rule_name,
'Condition': "'%(Identity)' != '@(SelectedFiles)'"
}
]
]
inputs_section = [
'ItemGroup',
[rule.inputs, {'Include': '%%(%s.AdditionalDependencies)' % rule_name}]
]
logging_section = [
'ItemGroup',
[rule.tlog,
{'Include': '%%(%s.Outputs)' % rule_name,
'Condition': ("'%%(%s.Outputs)' != '' and "
"'%%(%s.ExcludedFromBuild)' != 'true'" %
(rule_name, rule_name))
},
['Source', "@(%s, '|')" % rule_name],
['Inputs', "@(%s -> '%%(Fullpath)', ';')" % rule.inputs],
],
]
message_section = [
'Message',
{'Importance': 'High',
'Text': '%%(%s.ExecutionDescription)' % rule_name
}
]
write_tlog_section = [
'WriteLinesToFile',
{'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule.tlog, rule.tlog),
'File': '$(IntDir)$(ProjectName).write.1.tlog',
'Lines': "^%%(%s.Source);@(%s->'%%(Fullpath)')" % (rule.tlog,
rule.tlog)
}
]
read_tlog_section = [
'WriteLinesToFile',
{'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule.tlog, rule.tlog),
'File': '$(IntDir)$(ProjectName).read.1.tlog',
'Lines': "^%%(%s.Source);%%(%s.Inputs)" % (rule.tlog, rule.tlog)
}
]
command_and_input_section = [
rule_name,
{'Condition': "'@(%s)' != '' and '%%(%s.ExcludedFromBuild)' != "
"'true'" % (rule_name, rule_name),
'EchoOff': 'true',
'StandardOutputImportance': 'High',
'StandardErrorImportance': 'High',
'CommandLineTemplate': '%%(%s.CommandLineTemplate)' % rule_name,
'AdditionalOptions': '%%(%s.AdditionalOptions)' % rule_name,
'Inputs': rule_inputs
}
]
content.extend([
['Target',
{'Name': rule.target_name,
'BeforeTargets': '$(%s)' % rule.before_targets,
'AfterTargets': '$(%s)' % rule.after_targets,
'Condition': "'@(%s)' != ''" % rule_name,
'DependsOnTargets': '$(%s);%s' % (rule.depends_on,
rule.compute_output),
'Outputs': target_outputs,
'Inputs': target_inputs
},
remove_section,
inputs_section,
logging_section,
message_section,
write_tlog_section,
read_tlog_section,
command_and_input_section,
],
['PropertyGroup',
['ComputeLinkInputsTargets',
'$(ComputeLinkInputsTargets);',
'%s;' % rule.compute_output
],
['ComputeLibInputsTargets',
'$(ComputeLibInputsTargets);',
'%s;' % rule.compute_output
],
],
['Target',
{'Name': rule.compute_output,
'Condition': "'@(%s)' != ''" % rule_name
},
['ItemGroup',
[rule.dirs_to_make,
{'Condition': "'@(%s)' != '' and "
"'%%(%s.ExcludedFromBuild)' != 'true'" % (rule_name, rule_name),
'Include': '%%(%s.Outputs)' % rule_name
}
],
['Link',
{'Include': '%%(%s.Identity)' % rule.dirs_to_make,
'Condition': extension_condition
}
],
['Lib',
{'Include': '%%(%s.Identity)' % rule.dirs_to_make,
'Condition': extension_condition
}
],
['ImpLib',
{'Include': '%%(%s.Identity)' % rule.dirs_to_make,
'Condition': extension_condition
}
],
],
['MakeDir',
{'Directories': ("@(%s->'%%(RootDir)%%(Directory)')" %
rule.dirs_to_make)
}
]
],
])
easy_xml.WriteXmlIfChanged(content, targets_path, pretty=True, win32=True)
def _GenerateMSBuildRuleXmlFile(xml_path, msbuild_rules):
# Generate the .xml file
content = [
'ProjectSchemaDefinitions',
{'xmlns': ('clr-namespace:Microsoft.Build.Framework.XamlTypes;'
'assembly=Microsoft.Build.Framework'),
'xmlns:x': 'http://schemas.microsoft.com/winfx/2006/xaml',
'xmlns:sys': 'clr-namespace:System;assembly=mscorlib',
'xmlns:transformCallback':
'Microsoft.Cpp.Dev10.ConvertPropertyCallback'
}
]
for rule in msbuild_rules:
content.extend([
['Rule',
{'Name': rule.rule_name,
'PageTemplate': 'tool',
'DisplayName': rule.display_name,
'Order': '200'
},
['Rule.DataSource',
['DataSource',
{'Persistence': 'ProjectFile',
'ItemType': rule.rule_name
}
]
],
['Rule.Categories',
['Category',
{'Name': 'General'},
['Category.DisplayName',
['sys:String', 'General'],
],
],
['Category',
{'Name': 'Command Line',
'Subtype': 'CommandLine'
},
['Category.DisplayName',
['sys:String', 'Command Line'],
],
],
],
['StringListProperty',
{'Name': 'Inputs',
'Category': 'Command Line',
'IsRequired': 'true',
'Switch': ' '
},
['StringListProperty.DataSource',
['DataSource',
{'Persistence': 'ProjectFile',
'ItemType': rule.rule_name,
'SourceType': 'Item'
}
]
],
],
['StringProperty',
{'Name': 'CommandLineTemplate',
'DisplayName': 'Command Line',
'Visible': 'False',
'IncludeInCommandLine': 'False'
}
],
['DynamicEnumProperty',
{'Name': rule.before_targets,
'Category': 'General',
'EnumProvider': 'Targets',
'IncludeInCommandLine': 'False'
},
['DynamicEnumProperty.DisplayName',
['sys:String', 'Execute Before'],
],
['DynamicEnumProperty.Description',
['sys:String', 'Specifies the targets for the build customization'
' to run before.'
],
],
['DynamicEnumProperty.ProviderSettings',
['NameValuePair',
{'Name': 'Exclude',
'Value': '^%s|^Compute' % rule.before_targets
}
]
],
['DynamicEnumProperty.DataSource',
['DataSource',
{'Persistence': 'ProjectFile',
'HasConfigurationCondition': 'true'
}
]
],
],
['DynamicEnumProperty',
{'Name': rule.after_targets,
'Category': 'General',
'EnumProvider': 'Targets',
'IncludeInCommandLine': 'False'
},
['DynamicEnumProperty.DisplayName',
['sys:String', 'Execute After'],
],
['DynamicEnumProperty.Description',
['sys:String', ('Specifies the targets for the build customization'
' to run after.')
],
],
['DynamicEnumProperty.ProviderSettings',
['NameValuePair',
{'Name': 'Exclude',
'Value': '^%s|^Compute' % rule.after_targets
}
]
],
['DynamicEnumProperty.DataSource',
['DataSource',
{'Persistence': 'ProjectFile',
'ItemType': '',
'HasConfigurationCondition': 'true'
}
]
],
],
['StringListProperty',
{'Name': 'Outputs',
'DisplayName': 'Outputs',
'Visible': 'False',
'IncludeInCommandLine': 'False'
}
],
['StringProperty',
{'Name': 'ExecutionDescription',
'DisplayName': 'Execution Description',
'Visible': 'False',
'IncludeInCommandLine': 'False'
}
],
['StringListProperty',
{'Name': 'AdditionalDependencies',
'DisplayName': 'Additional Dependencies',
'IncludeInCommandLine': 'False',
'Visible': 'false'
}
],
['StringProperty',
{'Subtype': 'AdditionalOptions',
'Name': 'AdditionalOptions',
'Category': 'Command Line'
},
['StringProperty.DisplayName',
['sys:String', 'Additional Options'],
],
['StringProperty.Description',
['sys:String', 'Additional Options'],
],
],
],
['ItemType',
{'Name': rule.rule_name,
'DisplayName': rule.display_name
}
],
['FileExtension',
{'Name': '*' + rule.extension,
'ContentType': rule.rule_name
}
],
['ContentType',
{'Name': rule.rule_name,
'DisplayName': '',
'ItemType': rule.rule_name
}
]
])
easy_xml.WriteXmlIfChanged(content, xml_path, pretty=True, win32=True)
def _GetConfigurationAndPlatform(name, settings):
configuration = name.rsplit('_', 1)[0]
platform = settings.get('msvs_configuration_platform', 'Win32')
return (configuration, platform)
def _GetConfigurationCondition(name, settings):
return (r"'$(Configuration)|$(Platform)'=='%s|%s'" %
_GetConfigurationAndPlatform(name, settings))
def _GetMSBuildProjectConfigurations(configurations):
group = ['ItemGroup', {'Label': 'ProjectConfigurations'}]
for (name, settings) in sorted(configurations.iteritems()):
configuration, platform = _GetConfigurationAndPlatform(name, settings)
designation = '%s|%s' % (configuration, platform)
group.append(
['ProjectConfiguration', {'Include': designation},
['Configuration', configuration],
['Platform', platform]])
return [group]
def _GetMSBuildGlobalProperties(spec, guid, gyp_file_name):
namespace = os.path.splitext(gyp_file_name)[0]
properties = [
['PropertyGroup', {'Label': 'Globals'},
['ProjectGuid', guid],
['Keyword', 'Win32Proj'],
['RootNamespace', namespace],
['IgnoreWarnCompileDuplicatedFilename', 'true'],
]
]
if os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or \
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64':
properties[0].append(['PreferredToolArchitecture', 'x64'])
if spec.get('msvs_enable_winrt'):
properties[0].append(['DefaultLanguage', 'en-US'])
properties[0].append(['AppContainerApplication', 'true'])
if spec.get('msvs_application_type_revision'):
app_type_revision = spec.get('msvs_application_type_revision')
properties[0].append(['ApplicationTypeRevision', app_type_revision])
else:
properties[0].append(['ApplicationTypeRevision', '8.1'])
if spec.get('msvs_target_platform_version'):
target_platform_version = spec.get('msvs_target_platform_version')
properties[0].append(['WindowsTargetPlatformVersion',
target_platform_version])
if spec.get('msvs_target_platform_minversion'):
target_platform_minversion = spec.get('msvs_target_platform_minversion')
properties[0].append(['WindowsTargetPlatformMinVersion',
target_platform_minversion])
else:
properties[0].append(['WindowsTargetPlatformMinVersion',
target_platform_version])
if spec.get('msvs_enable_winphone'):
properties[0].append(['ApplicationType', 'Windows Phone'])
else:
properties[0].append(['ApplicationType', 'Windows Store'])
platform_name = None
msvs_windows_target_platform_version = None
for configuration in spec['configurations'].itervalues():
platform_name = platform_name or _ConfigPlatform(configuration)
msvs_windows_target_platform_version = \
msvs_windows_target_platform_version or \
_ConfigWindowsTargetPlatformVersion(configuration)
if platform_name and msvs_windows_target_platform_version:
break
if platform_name == 'ARM':
properties[0].append(['WindowsSDKDesktopARMSupport', 'true'])
if msvs_windows_target_platform_version:
properties[0].append(['WindowsTargetPlatformVersion', \
str(msvs_windows_target_platform_version)])
return properties
def _GetMSBuildConfigurationDetails(spec, build_file):
properties = {}
for name, settings in spec['configurations'].iteritems():
msbuild_attributes = _GetMSBuildAttributes(spec, settings, build_file)
condition = _GetConfigurationCondition(name, settings)
character_set = msbuild_attributes.get('CharacterSet')
_AddConditionalProperty(properties, condition, 'ConfigurationType',
msbuild_attributes['ConfigurationType'])
if character_set:
if 'msvs_enable_winrt' not in spec :
_AddConditionalProperty(properties, condition, 'CharacterSet',
character_set)
return _GetMSBuildPropertyGroup(spec, 'Configuration', properties)
def _GetMSBuildLocalProperties(msbuild_toolset):
# Currently the only local property we support is PlatformToolset
properties = {}
if msbuild_toolset:
properties = [
['PropertyGroup', {'Label': 'Locals'},
['PlatformToolset', msbuild_toolset],
]
]
return properties
def _GetMSBuildPropertySheets(configurations):
user_props = r'$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props'
additional_props = {}
props_specified = False
for name, settings in sorted(configurations.iteritems()):
configuration = _GetConfigurationCondition(name, settings)
if settings.has_key('msbuild_props'):
additional_props[configuration] = _FixPaths(settings['msbuild_props'])
props_specified = True
else:
additional_props[configuration] = ''
if not props_specified:
return [
['ImportGroup',
{'Label': 'PropertySheets'},
['Import',
{'Project': user_props,
'Condition': "exists('%s')" % user_props,
'Label': 'LocalAppDataPlatform'
}
]
]
]
else:
sheets = []
for condition, props in additional_props.iteritems():
import_group = [
'ImportGroup',
{'Label': 'PropertySheets',
'Condition': condition
},
['Import',
{'Project': user_props,
'Condition': "exists('%s')" % user_props,
'Label': 'LocalAppDataPlatform'
}
]
]
for props_file in props:
import_group.append(['Import', {'Project':props_file}])
sheets.append(import_group)
return sheets
def _ConvertMSVSBuildAttributes(spec, config, build_file):
config_type = _GetMSVSConfigurationType(spec, build_file)
msvs_attributes = _GetMSVSAttributes(spec, config, config_type)
msbuild_attributes = {}
for a in msvs_attributes:
if a in ['IntermediateDirectory', 'OutputDirectory']:
directory = MSVSSettings.ConvertVCMacrosToMSBuild(msvs_attributes[a])
if not directory.endswith('\\'):
directory += '\\'
msbuild_attributes[a] = directory
elif a == 'CharacterSet':
msbuild_attributes[a] = _ConvertMSVSCharacterSet(msvs_attributes[a])
elif a == 'ConfigurationType':
msbuild_attributes[a] = _ConvertMSVSConfigurationType(msvs_attributes[a])
else:
print 'Warning: Do not know how to convert MSVS attribute ' + a
return msbuild_attributes
def _ConvertMSVSCharacterSet(char_set):
if char_set.isdigit():
char_set = {
'0': 'MultiByte',
'1': 'Unicode',
'2': 'MultiByte',
}[char_set]
return char_set
def _ConvertMSVSConfigurationType(config_type):
if config_type.isdigit():
config_type = {
'1': 'Application',
'2': 'DynamicLibrary',
'4': 'StaticLibrary',
'10': 'Utility'
}[config_type]
return config_type
def _GetMSBuildAttributes(spec, config, build_file):
if 'msbuild_configuration_attributes' not in config:
msbuild_attributes = _ConvertMSVSBuildAttributes(spec, config, build_file)
else:
config_type = _GetMSVSConfigurationType(spec, build_file)
config_type = _ConvertMSVSConfigurationType(config_type)
msbuild_attributes = config.get('msbuild_configuration_attributes', {})
msbuild_attributes.setdefault('ConfigurationType', config_type)
output_dir = msbuild_attributes.get('OutputDirectory',
'$(SolutionDir)$(Configuration)')
msbuild_attributes['OutputDirectory'] = _FixPath(output_dir) + '\\'
if 'IntermediateDirectory' not in msbuild_attributes:
intermediate = _FixPath('$(Configuration)') + '\\'
msbuild_attributes['IntermediateDirectory'] = intermediate
if 'CharacterSet' in msbuild_attributes:
msbuild_attributes['CharacterSet'] = _ConvertMSVSCharacterSet(
msbuild_attributes['CharacterSet'])
if 'TargetName' not in msbuild_attributes:
prefix = spec.get('product_prefix', '')
product_name = spec.get('product_name', '$(ProjectName)')
target_name = prefix + product_name
msbuild_attributes['TargetName'] = target_name
if 'TargetExt' not in msbuild_attributes and 'product_extension' in spec:
ext = spec.get('product_extension')
msbuild_attributes['TargetExt'] = '.' + ext
if spec.get('msvs_external_builder'):
external_out_dir = spec.get('msvs_external_builder_out_dir', '.')
msbuild_attributes['OutputDirectory'] = _FixPath(external_out_dir) + '\\'
# Make sure that 'TargetPath' matches 'Lib.OutputFile' or 'Link.OutputFile'
# (depending on the tool used) to avoid MSB8012 warning.
msbuild_tool_map = {
'executable': 'Link',
'shared_library': 'Link',
'loadable_module': 'Link',
'static_library': 'Lib',
}
msbuild_tool = msbuild_tool_map.get(spec['type'])
if msbuild_tool:
msbuild_settings = config['finalized_msbuild_settings']
out_file = msbuild_settings[msbuild_tool].get('OutputFile')
if out_file:
msbuild_attributes['TargetPath'] = _FixPath(out_file)
target_ext = msbuild_settings[msbuild_tool].get('TargetExt')
if target_ext:
msbuild_attributes['TargetExt'] = target_ext
return msbuild_attributes
def _GetMSBuildConfigurationGlobalProperties(spec, configurations, build_file):
# TODO(jeanluc) We could optimize out the following and do it only if
# there are actions.
# TODO(jeanluc) Handle the equivalent of setting 'CYGWIN=nontsec'.
new_paths = []
cygwin_dirs = spec.get('msvs_cygwin_dirs', ['.'])[0]
if cygwin_dirs:
cyg_path = '$(MSBuildProjectDirectory)\\%s\\bin\\' % _FixPath(cygwin_dirs)
new_paths.append(cyg_path)
# TODO(jeanluc) Change the convention to have both a cygwin_dir and a
# python_dir.
python_path = cyg_path.replace('cygwin\\bin', 'python_26')
new_paths.append(python_path)
if new_paths:
new_paths = '$(ExecutablePath);' + ';'.join(new_paths)
properties = {}
for (name, configuration) in sorted(configurations.iteritems()):
condition = _GetConfigurationCondition(name, configuration)
attributes = _GetMSBuildAttributes(spec, configuration, build_file)
msbuild_settings = configuration['finalized_msbuild_settings']
_AddConditionalProperty(properties, condition, 'IntDir',
attributes['IntermediateDirectory'])
_AddConditionalProperty(properties, condition, 'OutDir',
attributes['OutputDirectory'])
_AddConditionalProperty(properties, condition, 'TargetName',
attributes['TargetName'])
if 'TargetExt' in attributes:
_AddConditionalProperty(properties, condition, 'TargetExt',
attributes['TargetExt'])
if attributes.get('TargetPath'):
_AddConditionalProperty(properties, condition, 'TargetPath',
attributes['TargetPath'])
if attributes.get('TargetExt'):
_AddConditionalProperty(properties, condition, 'TargetExt',
attributes['TargetExt'])
if new_paths:
_AddConditionalProperty(properties, condition, 'ExecutablePath',
new_paths)
tool_settings = msbuild_settings.get('', {})
for name, value in sorted(tool_settings.iteritems()):
formatted_value = _GetValueFormattedForMSBuild('', name, value)
_AddConditionalProperty(properties, condition, name, formatted_value)
return _GetMSBuildPropertyGroup(spec, None, properties)
def _AddConditionalProperty(properties, condition, name, value):
"""Adds a property / conditional value pair to a dictionary.
Arguments:
properties: The dictionary to be modified. The key is the name of the
property. The value is itself a dictionary; its key is the value and
the value a list of condition for which this value is true.
condition: The condition under which the named property has the value.
name: The name of the property.
value: The value of the property.
"""
if name not in properties:
properties[name] = {}
values = properties[name]
if value not in values:
values[value] = []
conditions = values[value]
conditions.append(condition)
# Regex for msvs variable references ( i.e. $(FOO) ).
MSVS_VARIABLE_REFERENCE = re.compile(r'\$\(([a-zA-Z_][a-zA-Z0-9_]*)\)')
def _GetMSBuildPropertyGroup(spec, label, properties):
"""Returns a PropertyGroup definition for the specified properties.
Arguments:
spec: The target project dict.
label: An optional label for the PropertyGroup.
properties: The dictionary to be converted. The key is the name of the
property. The value is itself a dictionary; its key is the value and
the value a list of condition for which this value is true.
"""
group = ['PropertyGroup']
if label:
group.append({'Label': label})
num_configurations = len(spec['configurations'])
def GetEdges(node):
# Use a definition of edges such that user_of_variable -> used_varible.
# This happens to be easier in this case, since a variable's
# definition contains all variables it references in a single string.
edges = set()
for value in sorted(properties[node].keys()):
# Add to edges all $(...) references to variables.
#
# Variable references that refer to names not in properties are excluded
# These can exist for instance to refer built in definitions like
# $(SolutionDir).
#
# Self references are ignored. Self reference is used in a few places to
# append to the default value. I.e. PATH=$(PATH);other_path
edges.update(set([v for v in MSVS_VARIABLE_REFERENCE.findall(value)
if v in properties and v != node]))
return edges
properties_ordered = gyp.common.TopologicallySorted(
properties.keys(), GetEdges)
# Walk properties in the reverse of a topological sort on
# user_of_variable -> used_variable as this ensures variables are
# defined before they are used.
# NOTE: reverse(topsort(DAG)) = topsort(reverse_edges(DAG))
for name in reversed(properties_ordered):
values = properties[name]
for value, conditions in sorted(values.iteritems()):
if len(conditions) == num_configurations:
# If the value is the same all configurations,
# just add one unconditional entry.
group.append([name, value])
else:
for condition in conditions:
group.append([name, {'Condition': condition}, value])
return [group]
def _GetMSBuildToolSettingsSections(spec, configurations):
groups = []
for (name, configuration) in sorted(configurations.iteritems()):
msbuild_settings = configuration['finalized_msbuild_settings']
group = ['ItemDefinitionGroup',
{'Condition': _GetConfigurationCondition(name, configuration)}
]
for tool_name, tool_settings in sorted(msbuild_settings.iteritems()):
# Skip the tool named '' which is a holder of global settings handled
# by _GetMSBuildConfigurationGlobalProperties.
if tool_name:
if tool_settings:
tool = [tool_name]
for name, value in sorted(tool_settings.iteritems()):
formatted_value = _GetValueFormattedForMSBuild(tool_name, name,
value)
tool.append([name, formatted_value])
group.append(tool)
groups.append(group)
return groups
def _FinalizeMSBuildSettings(spec, configuration):
if 'msbuild_settings' in configuration:
converted = False
msbuild_settings = configuration['msbuild_settings']
MSVSSettings.ValidateMSBuildSettings(msbuild_settings)
else:
converted = True
msvs_settings = configuration.get('msvs_settings', {})
msbuild_settings = MSVSSettings.ConvertToMSBuildSettings(msvs_settings)
include_dirs, midl_include_dirs, resource_include_dirs = \
_GetIncludeDirs(configuration)
libraries = _GetLibraries(spec)
library_dirs = _GetLibraryDirs(configuration)
out_file, _, msbuild_tool = _GetOutputFilePathAndTool(spec, msbuild=True)
target_ext = _GetOutputTargetExt(spec)
defines = _GetDefines(configuration)
if converted:
# Visual Studio 2010 has TR1
defines = [d for d in defines if d != '_HAS_TR1=0']
# Warn of ignored settings
ignored_settings = ['msvs_tool_files']
for ignored_setting in ignored_settings:
value = configuration.get(ignored_setting)
if value:
print ('Warning: The automatic conversion to MSBuild does not handle '
'%s. Ignoring setting of %s' % (ignored_setting, str(value)))
defines = [_EscapeCppDefineForMSBuild(d) for d in defines]
disabled_warnings = _GetDisabledWarnings(configuration)
prebuild = configuration.get('msvs_prebuild')
postbuild = configuration.get('msvs_postbuild')
def_file = _GetModuleDefinition(spec)
precompiled_header = configuration.get('msvs_precompiled_header')
# Add the information to the appropriate tool
# TODO(jeanluc) We could optimize and generate these settings only if
# the corresponding files are found, e.g. don't generate ResourceCompile
# if you don't have any resources.
_ToolAppend(msbuild_settings, 'ClCompile',
'AdditionalIncludeDirectories', include_dirs)
_ToolAppend(msbuild_settings, 'Midl',
'AdditionalIncludeDirectories', midl_include_dirs)
_ToolAppend(msbuild_settings, 'ResourceCompile',
'AdditionalIncludeDirectories', resource_include_dirs)
# Add in libraries, note that even for empty libraries, we want this
# set, to prevent inheriting default libraries from the enviroment.
_ToolSetOrAppend(msbuild_settings, 'Link', 'AdditionalDependencies',
libraries)
_ToolAppend(msbuild_settings, 'Link', 'AdditionalLibraryDirectories',
library_dirs)
if out_file:
_ToolAppend(msbuild_settings, msbuild_tool, 'OutputFile', out_file,
only_if_unset=True)
if target_ext:
_ToolAppend(msbuild_settings, msbuild_tool, 'TargetExt', target_ext,
only_if_unset=True)
# Add defines.
_ToolAppend(msbuild_settings, 'ClCompile',
'PreprocessorDefinitions', defines)
_ToolAppend(msbuild_settings, 'ResourceCompile',
'PreprocessorDefinitions', defines)
# Add disabled warnings.
_ToolAppend(msbuild_settings, 'ClCompile',
'DisableSpecificWarnings', disabled_warnings)
# Turn on precompiled headers if appropriate.
if precompiled_header:
precompiled_header = os.path.split(precompiled_header)[1]
_ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'Use')
_ToolAppend(msbuild_settings, 'ClCompile',
'PrecompiledHeaderFile', precompiled_header)
_ToolAppend(msbuild_settings, 'ClCompile',
'ForcedIncludeFiles', [precompiled_header])
else:
_ToolAppend(msbuild_settings, 'ClCompile', 'PrecompiledHeader', 'NotUsing')
# Turn off WinRT compilation
_ToolAppend(msbuild_settings, 'ClCompile', 'CompileAsWinRT', 'false')
# Turn on import libraries if appropriate
if spec.get('msvs_requires_importlibrary'):
_ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'false')
# Loadable modules don't generate import libraries;
# tell dependent projects to not expect one.
if spec['type'] == 'loadable_module':
_ToolAppend(msbuild_settings, '', 'IgnoreImportLibrary', 'true')
# Set the module definition file if any.
if def_file:
_ToolAppend(msbuild_settings, 'Link', 'ModuleDefinitionFile', def_file)
configuration['finalized_msbuild_settings'] = msbuild_settings
if prebuild:
_ToolAppend(msbuild_settings, 'PreBuildEvent', 'Command', prebuild)
if postbuild:
_ToolAppend(msbuild_settings, 'PostBuildEvent', 'Command', postbuild)
def _GetValueFormattedForMSBuild(tool_name, name, value):
if type(value) == list:
# For some settings, VS2010 does not automatically extends the settings
# TODO(jeanluc) Is this what we want?
if name in ['AdditionalIncludeDirectories',
'AdditionalLibraryDirectories',
'AdditionalOptions',
'DelayLoadDLLs',
'DisableSpecificWarnings',
'PreprocessorDefinitions']:
value.append('%%(%s)' % name)
# For most tools, entries in a list should be separated with ';' but some
# settings use a space. Check for those first.
exceptions = {
'ClCompile': ['AdditionalOptions'],
'Link': ['AdditionalOptions'],
'Lib': ['AdditionalOptions']}
if tool_name in exceptions and name in exceptions[tool_name]:
char = ' '
else:
char = ';'
formatted_value = char.join(
[MSVSSettings.ConvertVCMacrosToMSBuild(i) for i in value])
else:
formatted_value = MSVSSettings.ConvertVCMacrosToMSBuild(value)
return formatted_value
def _VerifySourcesExist(sources, root_dir):
"""Verifies that all source files exist on disk.
Checks that all regular source files, i.e. not created at run time,
exist on disk. Missing files cause needless recompilation but no otherwise
visible errors.
Arguments:
sources: A recursive list of Filter/file names.
root_dir: The root directory for the relative path names.
Returns:
A list of source files that cannot be found on disk.
"""
missing_sources = []
for source in sources:
if isinstance(source, MSVSProject.Filter):
missing_sources.extend(_VerifySourcesExist(source.contents, root_dir))
else:
if '$' not in source:
full_path = os.path.join(root_dir, source)
if not os.path.exists(full_path):
missing_sources.append(full_path)
return missing_sources
def _GetMSBuildSources(spec, sources, exclusions, rule_dependencies,
extension_to_rule_name, actions_spec,
sources_handled_by_action, list_excluded):
groups = ['none', 'masm', 'midl', 'include', 'compile', 'resource', 'rule',
'rule_dependency']
grouped_sources = {}
for g in groups:
grouped_sources[g] = []
_AddSources2(spec, sources, exclusions, grouped_sources,
rule_dependencies, extension_to_rule_name,
sources_handled_by_action, list_excluded)
sources = []
for g in groups:
if grouped_sources[g]:
sources.append(['ItemGroup'] + grouped_sources[g])
if actions_spec:
sources.append(['ItemGroup'] + actions_spec)
return sources
def _AddSources2(spec, sources, exclusions, grouped_sources,
rule_dependencies, extension_to_rule_name,
sources_handled_by_action,
list_excluded):
extensions_excluded_from_precompile = []
for source in sources:
if isinstance(source, MSVSProject.Filter):
_AddSources2(spec, source.contents, exclusions, grouped_sources,
rule_dependencies, extension_to_rule_name,
sources_handled_by_action,
list_excluded)
else:
if not source in sources_handled_by_action:
detail = []
excluded_configurations = exclusions.get(source, [])
if len(excluded_configurations) == len(spec['configurations']):
detail.append(['ExcludedFromBuild', 'true'])
else:
for config_name, configuration in sorted(excluded_configurations):
condition = _GetConfigurationCondition(config_name, configuration)
detail.append(['ExcludedFromBuild',
{'Condition': condition},
'true'])
# Add precompile if needed
for config_name, configuration in spec['configurations'].iteritems():
precompiled_source = configuration.get('msvs_precompiled_source', '')
if precompiled_source != '':
precompiled_source = _FixPath(precompiled_source)
if not extensions_excluded_from_precompile:
# If the precompiled header is generated by a C source, we must
# not try to use it for C++ sources, and vice versa.
basename, extension = os.path.splitext(precompiled_source)
if extension == '.c':
extensions_excluded_from_precompile = ['.cc', '.cpp', '.cxx']
else:
extensions_excluded_from_precompile = ['.c']
if precompiled_source == source:
condition = _GetConfigurationCondition(config_name, configuration)
detail.append(['PrecompiledHeader',
{'Condition': condition},
'Create'
])
else:
# Turn off precompiled header usage for source files of a
# different type than the file that generated the
# precompiled header.
for extension in extensions_excluded_from_precompile:
if source.endswith(extension):
detail.append(['PrecompiledHeader', ''])
detail.append(['ForcedIncludeFiles', ''])
group, element = _MapFileToMsBuildSourceType(source, rule_dependencies,
extension_to_rule_name)
grouped_sources[group].append([element, {'Include': source}] + detail)
def _GetMSBuildProjectReferences(project):
references = []
if project.dependencies:
group = ['ItemGroup']
for dependency in project.dependencies:
guid = dependency.guid
project_dir = os.path.split(project.path)[0]
relative_path = gyp.common.RelativePath(dependency.path, project_dir)
project_ref = ['ProjectReference',
{'Include': relative_path},
['Project', guid],
['ReferenceOutputAssembly', 'false']
]
for config in dependency.spec.get('configurations', {}).itervalues():
if config.get('msvs_use_library_dependency_inputs', 0):
project_ref.append(['UseLibraryDependencyInputs', 'true'])
break
# If it's disabled in any config, turn it off in the reference.
if config.get('msvs_2010_disable_uldi_when_referenced', 0):
project_ref.append(['UseLibraryDependencyInputs', 'false'])
break
group.append(project_ref)
references.append(group)
return references
def _GenerateMSBuildProject(project, options, version, generator_flags):
spec = project.spec
configurations = spec['configurations']
project_dir, project_file_name = os.path.split(project.path)
gyp.common.EnsureDirExists(project.path)
# Prepare list of sources and excluded sources.
gyp_path = _NormalizedSource(project.build_file)
relative_path_of_gyp_file = gyp.common.RelativePath(gyp_path, project_dir)
gyp_file = os.path.split(project.build_file)[1]
sources, excluded_sources = _PrepareListOfSources(spec, generator_flags,
gyp_file)
# Add rules.
actions_to_add = {}
props_files_of_rules = set()
targets_files_of_rules = set()
rule_dependencies = set()
extension_to_rule_name = {}
list_excluded = generator_flags.get('msvs_list_excluded_files', True)
# Don't generate rules if we are using an external builder like ninja.
if not spec.get('msvs_external_builder'):
_GenerateRulesForMSBuild(project_dir, options, spec,
sources, excluded_sources,
props_files_of_rules, targets_files_of_rules,
actions_to_add, rule_dependencies,
extension_to_rule_name)
else:
rules = spec.get('rules', [])
_AdjustSourcesForRules(rules, sources, excluded_sources, True)
sources, excluded_sources, excluded_idl = (
_AdjustSourcesAndConvertToFilterHierarchy(spec, options,
project_dir, sources,
excluded_sources,
list_excluded, version))
# Don't add actions if we are using an external builder like ninja.
if not spec.get('msvs_external_builder'):
_AddActions(actions_to_add, spec, project.build_file)
_AddCopies(actions_to_add, spec)
# NOTE: this stanza must appear after all actions have been decided.
# Don't excluded sources with actions attached, or they won't run.
excluded_sources = _FilterActionsFromExcluded(
excluded_sources, actions_to_add)
exclusions = _GetExcludedFilesFromBuild(spec, excluded_sources, excluded_idl)
actions_spec, sources_handled_by_action = _GenerateActionsForMSBuild(
spec, actions_to_add)
_GenerateMSBuildFiltersFile(project.path + '.filters', sources,
rule_dependencies,
extension_to_rule_name)
missing_sources = _VerifySourcesExist(sources, project_dir)
for configuration in configurations.itervalues():
_FinalizeMSBuildSettings(spec, configuration)
# Add attributes to root element
import_default_section = [
['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.Default.props'}]]
import_cpp_props_section = [
['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.props'}]]
import_cpp_targets_section = [
['Import', {'Project': r'$(VCTargetsPath)\Microsoft.Cpp.targets'}]]
import_masm_props_section = [
['Import',
{'Project': r'$(VCTargetsPath)\BuildCustomizations\masm.props'}]]
import_masm_targets_section = [
['Import',
{'Project': r'$(VCTargetsPath)\BuildCustomizations\masm.targets'}]]
macro_section = [['PropertyGroup', {'Label': 'UserMacros'}]]
content = [
'Project',
{'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003',
'ToolsVersion': version.ProjectVersion(),
'DefaultTargets': 'Build'
}]
content += _GetMSBuildProjectConfigurations(configurations)
content += _GetMSBuildGlobalProperties(spec, project.guid, project_file_name)
content += import_default_section
content += _GetMSBuildConfigurationDetails(spec, project.build_file)
if spec.get('msvs_enable_winphone'):
content += _GetMSBuildLocalProperties('v120_wp81')
else:
content += _GetMSBuildLocalProperties(project.msbuild_toolset)
content += import_cpp_props_section
content += import_masm_props_section
content += _GetMSBuildExtensions(props_files_of_rules)
content += _GetMSBuildPropertySheets(configurations)
content += macro_section
content += _GetMSBuildConfigurationGlobalProperties(spec, configurations,
project.build_file)
content += _GetMSBuildToolSettingsSections(spec, configurations)
content += _GetMSBuildSources(
spec, sources, exclusions, rule_dependencies, extension_to_rule_name,
actions_spec, sources_handled_by_action, list_excluded)
content += _GetMSBuildProjectReferences(project)
content += import_cpp_targets_section
content += import_masm_targets_section
content += _GetMSBuildExtensionTargets(targets_files_of_rules)
if spec.get('msvs_external_builder'):
content += _GetMSBuildExternalBuilderTargets(spec)
# TODO(jeanluc) File a bug to get rid of runas. We had in MSVS:
# has_run_as = _WriteMSVSUserFile(project.path, version, spec)
easy_xml.WriteXmlIfChanged(content, project.path, pretty=True, win32=True)
return missing_sources
def _GetMSBuildExternalBuilderTargets(spec):
"""Return a list of MSBuild targets for external builders.
The "Build" and "Clean" targets are always generated. If the spec contains
'msvs_external_builder_clcompile_cmd', then the "ClCompile" target will also
be generated, to support building selected C/C++ files.
Arguments:
spec: The gyp target spec.
Returns:
List of MSBuild 'Target' specs.
"""
build_cmd = _BuildCommandLineForRuleRaw(
spec, spec['msvs_external_builder_build_cmd'],
False, False, False, False)
build_target = ['Target', {'Name': 'Build'}]
build_target.append(['Exec', {'Command': build_cmd}])
clean_cmd = _BuildCommandLineForRuleRaw(
spec, spec['msvs_external_builder_clean_cmd'],
False, False, False, False)
clean_target = ['Target', {'Name': 'Clean'}]
clean_target.append(['Exec', {'Command': clean_cmd}])
targets = [build_target, clean_target]
if spec.get('msvs_external_builder_clcompile_cmd'):
clcompile_cmd = _BuildCommandLineForRuleRaw(
spec, spec['msvs_external_builder_clcompile_cmd'],
False, False, False, False)
clcompile_target = ['Target', {'Name': 'ClCompile'}]
clcompile_target.append(['Exec', {'Command': clcompile_cmd}])
targets.append(clcompile_target)
return targets
def _GetMSBuildExtensions(props_files_of_rules):
extensions = ['ImportGroup', {'Label': 'ExtensionSettings'}]
for props_file in props_files_of_rules:
extensions.append(['Import', {'Project': props_file}])
return [extensions]
def _GetMSBuildExtensionTargets(targets_files_of_rules):
targets_node = ['ImportGroup', {'Label': 'ExtensionTargets'}]
for targets_file in sorted(targets_files_of_rules):
targets_node.append(['Import', {'Project': targets_file}])
return [targets_node]
def _GenerateActionsForMSBuild(spec, actions_to_add):
"""Add actions accumulated into an actions_to_add, merging as needed.
Arguments:
spec: the target project dict
actions_to_add: dictionary keyed on input name, which maps to a list of
dicts describing the actions attached to that input file.
Returns:
A pair of (action specification, the sources handled by this action).
"""
sources_handled_by_action = OrderedSet()
actions_spec = []
for primary_input, actions in actions_to_add.iteritems():
inputs = OrderedSet()
outputs = OrderedSet()
descriptions = []
commands = []
for action in actions:
inputs.update(OrderedSet(action['inputs']))
outputs.update(OrderedSet(action['outputs']))
descriptions.append(action['description'])
cmd = action['command']
# For most actions, add 'call' so that actions that invoke batch files
# return and continue executing. msbuild_use_call provides a way to
# disable this but I have not seen any adverse effect from doing that
# for everything.
if action.get('msbuild_use_call', True):
cmd = 'call ' + cmd
commands.append(cmd)
# Add the custom build action for one input file.
description = ', and also '.join(descriptions)
# We can't join the commands simply with && because the command line will
# get too long. See also _AddActions: cygwin's setup_env mustn't be called
# for every invocation or the command that sets the PATH will grow too
# long.
command = '\r\n'.join([c + '\r\nif %errorlevel% neq 0 exit /b %errorlevel%'
for c in commands])
_AddMSBuildAction(spec,
primary_input,
inputs,
outputs,
command,
description,
sources_handled_by_action,
actions_spec)
return actions_spec, sources_handled_by_action
def _AddMSBuildAction(spec, primary_input, inputs, outputs, cmd, description,
sources_handled_by_action, actions_spec):
command = MSVSSettings.ConvertVCMacrosToMSBuild(cmd)
primary_input = _FixPath(primary_input)
inputs_array = _FixPaths(inputs)
outputs_array = _FixPaths(outputs)
additional_inputs = ';'.join([i for i in inputs_array
if i != primary_input])
outputs = ';'.join(outputs_array)
sources_handled_by_action.add(primary_input)
action_spec = ['CustomBuild', {'Include': primary_input}]
action_spec.extend(
# TODO(jeanluc) 'Document' for all or just if as_sources?
[['FileType', 'Document'],
['Command', command],
['Message', description],
['Outputs', outputs]
])
if additional_inputs:
action_spec.append(['AdditionalInputs', additional_inputs])
actions_spec.append(action_spec)
|
mit
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
13377,
515,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
13581,
63,
1652,
465,
8837,
63,
1652,
199,
646,
4902,
14,
4679,
14,
8675,
465,
14822,
63,
4679,
199,
646,
4902,
14,
14206,
4665,
465,
13828,
4665,
199,
646,
4902,
14,
14206,
4761,
465,
13828,
4761,
199,
646,
4902,
14,
14206,
5268,
465,
13828,
5268,
199,
646,
4902,
14,
3053,
54,
840,
21943,
1173,
465,
11694,
840,
21943,
1173,
199,
646,
4902,
14,
14206,
1899,
1173,
465,
13828,
1899,
1173,
199,
646,
4902,
14,
3053,
54,
6195,
2270,
465,
11694,
6195,
2270,
199,
646,
4902,
14,
14206,
3353,
465,
13828,
3353,
199,
504,
4902,
14,
2330,
492,
18151,
199,
504,
4902,
14,
2330,
492,
23617,
199,
199,
3,
3254,
26,
5852,
5403,
31726,
787,
641,
499,
14,
23,
12,
1455,
921,
1556,
1266,
14,
957,
15,
1194,
1196,
1876,
199,
318,
485,
646,
63,
16882,
837,
523,
492,
5055,
523,
862,
26,
272,
372,
5055,
14,
16882,
523,
871,
4281,
26,
272,
492,
4902,
14,
8235,
63,
807,
272,
372,
4902,
14,
8235,
63,
807,
14,
16882,
199,
16882,
275,
485,
646,
63,
16882,
342,
421,
199,
3,
18528,
3965,
367,
1686,
1958,
14702,
13225,
21645,
83,
14,
221,
982,
314,
21645,
199,
3,
3509,
12141,
6318,
14435,
12,
13828,
911,
506,
15701,
14,
9738,
12,
199,
3,
1010,
1353,
328,
3425,
6516,
9270,
911,
2198,
314,
8744,
570,
12,
1325,
2066,
199,
3,
18030,
3372,
10015,
314,
1347,
25498,
7508,
370,
4426,
3224,
2552,
14,
199,
3,
3390,
626,
642,
1454,
10986,
543,
314,
6516,
9270,
12,
436,
1630,
440,
4781,
199,
3,
340,
1010,
1353,
328,
3425,
365,
7934,
687,
6272,
14702,
13225,
14,
221,
961,
5163,
199,
3,
29280,
626,
314,
1059,
10734,
2839,
282,
21645,
543,
1006,
22681,
6318,
199,
3,
14435,
14,
199,
5600,
63,
14206,
63,
17856,
63,
16326,
275,
295,
14,
2014,
8,
82,
23811,
33,
13,
38,
16,
13,
25,
16185,
2807,
9988,
421,
199,
4679,
63,
885,
63,
3669,
275,
469,
272,
283,
21623,
63,
6351,
356,
3260,
272,
283,
21623,
63,
12273,
356,
1987,
5803,
297,
272,
283,
10449,
63,
5617,
63,
6351,
356,
3260,
272,
283,
13772,
63,
5617,
63,
6351,
356,
3260,
272,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
773,
297,
272,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
9259,
297,
272,
283,
23227,
63,
3022,
356,
9774,
25961,
3196,
272,
283,
13772,
63,
23227,
63,
3022,
356,
9774,
30654,
9,
1113,
15,
2966,
63,
15940,
297,
272,
283,
3100,
356,
283,
2676,
297,
272,
283,
14853,
63,
3022,
356,
9774,
30654,
3196,
272,
283,
5617,
63,
3022,
356,
9774,
30654,
9,
773,
297,
272,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
3205,
985,
3196,
272,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
3205,
3567,
3196,
272,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
3205,
4942,
3196,
272,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
3205,
7733,
3196,
272,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
3205,
2042,
3196,
272,
283,
22212,
63,
2339,
356,
9774,
5688,
985,
3196,
199,
93,
421,
199,
3,
710,
13795,
2488,
10189,
626,
10266,
3792,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
272,
283,
8338,
63,
16680,
63,
3220,
297,
272,
283,
8338,
63,
6750,
297,
199,
61,
421,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
272,
283,
8338,
63,
16680,
63,
3220,
297,
272,
283,
8338,
63,
16680,
63,
5641,
297,
272,
283,
8338,
63,
9629,
63,
10511,
297,
272,
283,
8338,
63,
10810,
297,
272,
283,
8338,
63,
5159,
63,
5649,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
548,
63,
694,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
1506,
63,
1760,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
3118,
63,
1760,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
429,
2014,
63,
1760,
297,
272,
283,
8338,
63,
4296,
63,
2676,
2591,
297,
272,
283,
8338,
63,
6537,
63,
646,
4342,
297,
272,
283,
8338,
63,
4296,
63,
2676,
9339,
297,
272,
283,
8338,
63,
3578,
63,
466,
63,
5792,
297,
272,
283,
8338,
63,
1375,
63,
3246,
63,
1023,
297,
272,
283,
8338,
63,
1375,
63,
3246,
63,
827,
1023,
297,
199,
61,
421,
199,
3,
3820,
402,
20626,
1406,
4048,
2883,
14,
199,
657,
863,
63,
1612,
275,
359,
272,
283,
8338,
63,
657,
8427,
63,
1291,
297,
272,
283,
8338,
63,
657,
8427,
63,
1365,
297,
199,
61,
421,
199,
5245,
63,
2473,
275,
488,
421,
199,
5245,
63,
2261,
275,
488,
421,
199,
3,
3254,
8,
458,
897,
2247,
304,
17711,
314,
747,
14,
2314,
4882,
370,
506,
199,
3,
4747,
708,
1246,
14,
1002,
7705,
985,
342,
436,
4747,
708,
1246,
14,
1002,
25108,
342,
5403,
314,
199,
3,
2366,
1015,
315,
32544,
63,
2537,
965,
2757,
4588,
370,
1736,
641,
19801,
65,
199,
3,
5049,
13,
2075,
14,
199,
318,
485,
1002,
7705,
3325,
25108,
837,
523,
340,
984,
14,
3246,
440,
315,
661,
2676,
708,
297,
283,
16680,
735,
272,
372,
661,
7378,
297,
283,
11958,
358,
523,
2288,
6328,
63,
2473,
523,
2288,
6328,
63,
2261,
523,
340,
440,
6328,
63,
2261,
503,
440,
6328,
63,
2473,
26,
272,
2881,
275,
747,
14,
2314,
14,
362,
360,
3791,
7378,
358,
272,
3434,
275,
747,
14,
2314,
14,
362,
360,
11958,
358,
272,
340,
440,
2881,
503,
440,
3434,
26,
489,
1240,
275,
3873,
14,
7942,
2941,
846,
297,
283,
888,
297,
283,
6517,
10600,
995,
2892,
3839,
29,
5781,
14,
6089,
9,
489,
1101,
275,
1240,
14,
10664,
3430,
16,
61,
489,
3434,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
1899,
536,
60,
83,
20900,
51,
14705,
295,
14,
16661,
9,
489,
3434,
63,
1431,
275,
3434,
63
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
1331,
199,
646,
13377,
515,
199,
646,
747,
199,
646,
15454,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
199,
646,
4902,
14,
2330,
199,
646,
4902,
14,
13581,
63,
1652,
465,
8837,
63,
1652,
199,
646,
4902,
14,
4679,
14,
8675,
465,
14822,
63,
4679,
199,
646,
4902,
14,
14206,
4665,
465,
13828,
4665,
199,
646,
4902,
14,
14206,
4761,
465,
13828,
4761,
199,
646,
4902,
14,
14206,
5268,
465,
13828,
5268,
199,
646,
4902,
14,
3053,
54,
840,
21943,
1173,
465,
11694,
840,
21943,
1173,
199,
646,
4902,
14,
14206,
1899,
1173,
465,
13828,
1899,
1173,
199,
646,
4902,
14,
3053,
54,
6195,
2270,
465,
11694,
6195,
2270,
199,
646,
4902,
14,
14206,
3353,
465,
13828,
3353,
199,
504,
4902,
14,
2330,
492,
18151,
199,
504,
4902,
14,
2330,
492,
23617,
199,
199,
3,
3254,
26,
5852,
5403,
31726,
787,
641,
499,
14,
23,
12,
1455,
921,
1556,
1266,
14,
957,
15,
1194,
1196,
1876,
199,
318,
485,
646,
63,
16882,
837,
523,
492,
5055,
523,
862,
26,
272,
372,
5055,
14,
16882,
523,
871,
4281,
26,
272,
492,
4902,
14,
8235,
63,
807,
272,
372,
4902,
14,
8235,
63,
807,
14,
16882,
199,
16882,
275,
485,
646,
63,
16882,
342,
421,
199,
3,
18528,
3965,
367,
1686,
1958,
14702,
13225,
21645,
83,
14,
221,
982,
314,
21645,
199,
3,
3509,
12141,
6318,
14435,
12,
13828,
911,
506,
15701,
14,
9738,
12,
199,
3,
1010,
1353,
328,
3425,
6516,
9270,
911,
2198,
314,
8744,
570,
12,
1325,
2066,
199,
3,
18030,
3372,
10015,
314,
1347,
25498,
7508,
370,
4426,
3224,
2552,
14,
199,
3,
3390,
626,
642,
1454,
10986,
543,
314,
6516,
9270,
12,
436,
1630,
440,
4781,
199,
3,
340,
1010,
1353,
328,
3425,
365,
7934,
687,
6272,
14702,
13225,
14,
221,
961,
5163,
199,
3,
29280,
626,
314,
1059,
10734,
2839,
282,
21645,
543,
1006,
22681,
6318,
199,
3,
14435,
14,
199,
5600,
63,
14206,
63,
17856,
63,
16326,
275,
295,
14,
2014,
8,
82,
23811,
33,
13,
38,
16,
13,
25,
16185,
2807,
9988,
421,
199,
4679,
63,
885,
63,
3669,
275,
469,
272,
283,
21623,
63,
6351,
356,
3260,
272,
283,
21623,
63,
12273,
356,
1987,
5803,
297,
272,
283,
10449,
63,
5617,
63,
6351,
356,
3260,
272,
283,
13772,
63,
5617,
63,
6351,
356,
3260,
272,
283,
10449,
63,
5617,
63,
12273,
356,
1987,
773,
297,
272,
283,
13772,
63,
5617,
63,
12273,
356,
1987,
9259,
297,
272,
283,
23227,
63,
3022,
356,
9774,
25961,
3196,
272,
283,
13772,
63,
23227,
63,
3022,
356,
9774,
30654,
9,
1113,
15,
2966,
63,
15940,
297,
272,
283,
3100,
356,
283,
2676,
297,
272,
283,
14853,
63,
3022,
356,
9774,
30654,
3196,
272,
283,
5617,
63,
3022,
356,
9774,
30654,
9,
773,
297,
272,
283,
13578,
63,
7321,
63,
5441,
356,
9774,
3205,
985,
3196,
272,
283,
13578,
63,
7321,
63,
3022,
2339,
356,
9774,
3205,
3567,
3196,
272,
283,
13578,
63,
7321,
63,
2472,
356,
9774,
3205,
4942,
3196,
272,
283,
13578,
63,
7321,
63,
2339,
356,
9774,
3205,
7733,
3196,
272,
283,
13578,
63,
7321,
63,
3243,
356,
9774,
3205,
2042,
3196,
272,
283,
22212,
63,
2339,
356,
9774,
5688,
985,
3196,
199,
93,
421,
199,
3,
710,
13795,
2488,
10189,
626,
10266,
3792,
199,
4679,
63,
8460,
63,
515,
63,
7786,
275,
359,
272,
283,
8338,
63,
16680,
63,
3220,
297,
272,
283,
8338,
63,
6750,
297,
199,
61,
421,
199,
4679,
63,
8460,
63,
2865,
63,
4758,
63,
1612,
275,
359,
272,
283,
8338,
63,
16680,
63,
3220,
297,
272,
283,
8338,
63,
16680,
63,
5641,
297,
272,
283,
8338,
63,
9629,
63,
10511,
297,
272,
283,
8338,
63,
10810,
297,
272,
283,
8338,
63,
5159,
63,
5649,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
548,
63,
694,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
1506,
63,
1760,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
3118,
63,
1760,
297,
272,
283,
8338,
63,
5159,
63,
5649,
63,
429,
2014,
63,
1760,
297,
272,
283,
8338,
63,
4296,
63,
2676,
2591,
297,
272,
283,
8338,
63,
6537,
63,
646,
4342,
297,
272,
283,
8338,
63,
4296,
63,
2676,
9339,
297,
272,
283,
8338,
63,
3578,
63,
466,
63,
5792,
297,
272,
283,
8338,
63,
1375,
63,
3246,
63,
1023,
297,
272,
283,
8338,
63,
1375,
63,
3246,
63,
827,
1023,
297,
199,
61,
421,
199,
3,
3820,
402,
20626,
1406,
4048,
2883,
14,
199,
657,
863,
63,
1612,
275,
359,
272,
283,
8338,
63,
657,
8427,
63,
1291,
297,
272,
283,
8338,
63,
657,
8427,
63,
1365,
297,
199,
61,
421,
199,
5245,
63,
2473,
275,
488,
421,
199,
5245,
63,
2261,
275,
488,
421,
199,
3,
3254,
8,
458,
897,
2247,
304,
17711,
314,
747,
14,
2314,
4882,
370,
506,
199,
3,
4747,
708,
1246,
14,
1002,
7705,
985,
342,
436,
4747,
708,
1246,
14,
1002,
25108,
342,
5403,
314,
199,
3,
2366,
1015,
315,
32544,
63,
2537,
965,
2757,
4588,
370,
1736,
641,
19801,
65,
199,
3,
5049,
13,
2075,
14,
199,
318,
485,
1002,
7705,
3325,
25108,
837,
523,
340,
984,
14,
3246,
440,
315,
661,
2676,
708,
297,
283,
16680,
735,
272,
372,
661,
7378,
297,
283,
11958,
358,
523,
2288,
6328,
63,
2473,
523,
2288,
6328,
63,
2261,
523,
340,
440,
6328,
63,
2261,
503,
440,
6328,
63,
2473,
26,
272,
2881,
275,
747,
14,
2314,
14,
362,
360,
3791,
7378,
358,
272,
3434,
275,
747,
14,
2314,
14,
362,
360,
11958,
358,
272,
340,
440,
2881,
503,
440,
3434,
26,
489,
1240,
275,
3873,
14,
7942,
2941,
846,
297,
283,
888,
297,
283,
6517,
10600,
995,
2892,
3839,
29,
5781,
14,
6089,
9,
489,
1101,
275,
1240,
14,
10664,
3430,
16,
61,
489,
3434,
63,
264,
275,
295,
14,
2014,
8,
82,
4289,
1899,
536,
60,
83,
20900,
51,
14705,
295,
14,
16661,
9,
489,
3434,
63,
1431,
275,
3434,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
andriy-s/django-rest-framework
|
rest_framework/viewsets.py
|
21
|
5303
|
"""
ViewSets are essentially just a type of class based view, that doesn't provide
any method handlers, such as `get()`, `post()`, etc... but instead has actions,
such as `list()`, `retrieve()`, `create()`, etc...
Actions are only bound to methods at the point of instantiating the views.
user_list = UserViewSet.as_view({'get': 'list'})
user_detail = UserViewSet.as_view({'get': 'retrieve'})
Typically, rather than instantiate views from viewsets directly, you'll
register the viewset with a router and let the URL conf be determined
automatically.
router = DefaultRouter()
router.register(r'users', UserViewSet, 'user')
urlpatterns = router.urls
"""
from __future__ import unicode_literals
from functools import update_wrapper
from django.utils.decorators import classonlymethod
from django.views.decorators.csrf import csrf_exempt
from rest_framework import views, generics, mixins
class ViewSetMixin(object):
"""
This is the magic.
Overrides `.as_view()` so that it takes an `actions` keyword that performs
the binding of HTTP methods to actions on the Resource.
For example, to create a concrete view binding the 'GET' and 'POST' methods
to the 'list' and 'create' actions...
view = MyViewSet.as_view({'get': 'list', 'post': 'create'})
"""
@classonlymethod
def as_view(cls, actions=None, **initkwargs):
"""
Because of the way class based views create a closure around the
instantiated view, we need to totally reimplement `.as_view`,
and slightly modify the view function that is created and returned.
"""
# The suffix initkwarg is reserved for identifying the viewset type
# eg. 'List' or 'Instance'.
cls.suffix = None
# actions must not be empty
if not actions:
raise TypeError("The `actions` argument must be provided when "
"calling `.as_view()` on a ViewSet. For example "
"`.as_view({'get': 'list'})`")
# sanitize keyword arguments
for key in initkwargs:
if key in cls.http_method_names:
raise TypeError("You tried to pass in the %s method name as a "
"keyword argument to %s(). Don't do that."
% (key, cls.__name__))
if not hasattr(cls, key):
raise TypeError("%s() received an invalid keyword %r" % (
cls.__name__, key))
def view(request, *args, **kwargs):
self = cls(**initkwargs)
# We also store the mapping of request methods to actions,
# so that we can later set the action attribute.
# eg. `self.action = 'list'` on an incoming GET request.
self.action_map = actions
# Bind methods to actions
# This is the bit that's different to a standard view
for method, action in actions.items():
handler = getattr(self, action)
setattr(self, method, handler)
# Patch this in as it's otherwise only present from 1.5 onwards
if hasattr(self, 'get') and not hasattr(self, 'head'):
self.head = self.get
# And continue as usual
return self.dispatch(request, *args, **kwargs)
# take name and docstring from class
update_wrapper(view, cls, updated=())
# and possible attributes set by decorators
# like csrf_exempt from dispatch
update_wrapper(view, cls.dispatch, assigned=())
# We need to set these on the view function, so that breadcrumb
# generation can pick out these bits of information from a
# resolved URL.
view.cls = cls
view.suffix = initkwargs.get('suffix', None)
return csrf_exempt(view)
def initialize_request(self, request, *args, **kwargs):
"""
Set the `.action` attribute on the view,
depending on the request method.
"""
request = super(ViewSetMixin, self).initialize_request(request, *args, **kwargs)
self.action = self.action_map.get(request.method.lower())
return request
class ViewSet(ViewSetMixin, views.APIView):
"""
The base ViewSet class does not provide any actions by default.
"""
pass
class GenericViewSet(ViewSetMixin, generics.GenericAPIView):
"""
The GenericViewSet class does not provide any actions by default,
but does include the base set of generic view behavior, such as
the `get_object` and `get_queryset` methods.
"""
pass
class ReadOnlyModelViewSet(mixins.RetrieveModelMixin,
mixins.ListModelMixin,
GenericViewSet):
"""
A viewset that provides default `list()` and `retrieve()` actions.
"""
pass
class ModelViewSet(mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
mixins.ListModelMixin,
GenericViewSet):
"""
A viewset that provides default `create()`, `retrieve()`, `update()`,
`partial_update()`, `destroy()` and `list()` actions.
"""
pass
|
bsd-2-clause
|
[
624,
199,
2768,
9899,
787,
28891,
2951,
282,
730,
402,
1021,
4079,
2455,
12,
626,
3181,
1133,
5647,
199,
1629,
1083,
8297,
12,
4066,
465,
658,
362,
342,
3559,
658,
1932,
342,
3559,
5423,
1396,
1325,
3140,
965,
5445,
12,
199,
10180,
465,
658,
513,
342,
3559,
658,
14270,
342,
3559,
658,
981,
342,
3559,
5423,
1396,
199,
199,
9303,
787,
1454,
3914,
370,
3102,
737,
314,
2376,
402,
9034,
1958,
314,
6858,
14,
339,
922,
63,
513,
275,
2876,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
513,
3071,
272,
922,
63,
5506,
275,
2876,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
14270,
3071,
199,
199,
21718,
7288,
12,
7830,
2419,
17321,
6858,
687,
2455,
2193,
5370,
12,
1265,
7171,
199,
2683,
314,
2455,
409,
543,
282,
6197,
436,
4691,
314,
2851,
3743,
506,
12037,
199,
2495,
17174,
14,
339,
6197,
275,
3758,
11691,
342,
272,
6197,
14,
2683,
8,
82,
7,
3707,
297,
2876,
21902,
12,
283,
751,
358,
272,
26177,
275,
6197,
14,
3603,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
25254,
199,
504,
4618,
63,
4857,
492,
6858,
12,
1519,
2932,
12,
13667,
3617,
421,
199,
533,
10935,
1084,
4256,
8,
785,
304,
272,
408,
272,
961,
365,
314,
10628,
14,
339,
31144,
19853,
305,
63,
1345,
11995,
880,
626,
652,
6181,
376,
658,
3723,
64,
4252,
626,
18628,
272,
314,
11696,
402,
3101,
3102,
370,
5445,
641,
314,
7337,
14,
339,
2104,
2893,
12,
370,
1218,
282,
13801,
2455,
11696,
314,
283,
2970,
7,
436,
283,
4030,
7,
3102,
272,
370,
314,
283,
513,
7,
436,
283,
981,
7,
5445,
1396,
339,
2455,
275,
4932,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
513,
297,
283,
1932,
356,
283,
981,
3071,
272,
408,
339,
768,
533,
2118,
765,
272,
347,
465,
63,
1345,
8,
1886,
12,
5445,
29,
403,
12,
1011,
826,
958,
304,
267,
408,
267,
13821,
402,
314,
4340,
1021,
4079,
6858,
1218,
282,
17903,
6818,
314,
267,
17544,
2455,
12,
781,
1929,
370,
12657,
1183,
295,
21463,
19853,
305,
63,
1345,
3559,
267,
436,
18023,
2811,
314,
2455,
805,
626,
365,
2737,
436,
2138,
14,
267,
408,
267,
327,
710,
4739,
4205,
12745,
365,
4644,
367,
21119,
314,
2455,
409,
730,
267,
327,
11837,
14,
283,
1296,
7,
503,
283,
3244,
1370,
267,
843,
14,
4511,
275,
488,
398,
327,
5445,
1471,
440,
506,
2701,
267,
340,
440,
5445,
26,
288,
746,
3146,
480,
1918,
658,
3723,
64,
1423,
1471,
506,
2741,
1380,
298,
1169,
298,
25566,
19853,
305,
63,
1345,
11995,
641,
282,
10935,
1084,
14,
2104,
2893,
298,
1169,
298,
2313,
305,
63,
1345,
3252,
362,
356,
283,
513,
3071,
22446,
398,
327,
21077,
4252,
2368,
267,
367,
790,
315,
4205,
958,
26,
288,
340,
790,
315,
843,
14,
1014,
63,
765,
63,
1247,
26,
355,
746,
3146,
480,
5556,
16416,
370,
986,
315,
314,
450,
83,
1083,
536,
465,
282,
298,
1816,
298,
6691,
1423,
370,
450,
83,
1252,
7529,
1133,
886,
626,
2122,
1816,
450,
334,
498,
12,
843,
855,
354,
8964,
288,
340,
440,
2688,
8,
1886,
12,
790,
304,
355,
746,
3146,
3647,
83,
342,
3086,
376,
3866,
4252,
450,
82,
2,
450,
334,
490,
843,
855,
354,
3108,
790,
430,
398,
347,
2455,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
288,
291,
275,
843,
3682,
826,
958,
9,
288,
327,
2136,
2597,
3877,
314,
4412,
402,
1056,
3102,
370,
5445,
12,
288,
327,
880,
626,
781,
883,
2945,
663,
314,
1595,
2225,
14,
288,
327,
11837,
14,
658,
277,
14,
1287,
275,
283,
513,
7,
64,
641,
376,
12467,
9576,
1056,
14,
288,
291,
14,
1287,
63,
1130,
275,
5445,
953,
327,
22630,
3102,
370,
5445,
288,
327,
961,
365,
314,
4546,
626,
1159,
3365,
370,
282,
4465,
2455,
288,
367,
1083,
12,
1595,
315,
5445,
14,
1744,
837,
355,
3016,
275,
2519,
8,
277,
12,
1595,
9,
355,
5371,
8,
277,
12,
1083,
12,
3016,
9,
953,
327,
19292,
642,
315,
465,
652,
1159,
4257,
1454,
3451,
687,
413,
14,
21,
641,
4751,
288,
340,
2688,
8,
277,
12,
283,
362,
358,
436,
440,
2688,
8,
277,
12,
283,
2993,
735,
355,
291,
14,
2993,
275,
291,
14,
362,
953,
327,
6061,
1980,
465,
20195,
288,
372,
291,
14,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
398,
327,
5452,
536,
436,
9214,
687,
1021,
267,
1678,
63,
5029,
8,
1345,
12,
843,
12,
4588,
29,
1012,
398,
327,
436,
3962,
3004,
663,
701,
20419,
267,
327,
2839,
19213,
63,
25254,
687,
7634,
267,
1678,
63,
5029,
8,
1345,
12,
843,
14,
6052,
12,
7943,
29,
1012,
398,
327,
2136,
1929,
370,
663,
3520,
641,
314,
2455,
805,
12,
880,
626,
330,
25972,
4295,
267,
327,
10152,
883,
3732,
734,
3520,
5821,
402,
2556,
687,
282,
267,
327,
12152,
2851,
14,
267,
2455,
14,
1886,
275,
843,
267,
2455,
14,
4511,
275,
4205,
958,
14,
362,
360,
4511,
297,
488,
9,
267,
372,
19213,
63,
25254,
8,
1345,
9,
339,
347,
8265,
63,
1069,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
2494,
314,
19853,
1287,
64,
2225,
641,
314,
2455,
12,
267,
10298,
641,
314,
1056,
1083,
14,
267,
408,
267,
1056,
275,
1613,
8,
21902,
4256,
12,
291,
680,
8489,
63,
1069,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
1287,
275,
291,
14,
1287,
63,
1130,
14,
362,
8,
1069,
14,
765,
14,
2325,
1012,
267,
372,
1056,
421,
199,
533,
10935,
1084,
8,
21902,
4256,
12,
6858,
14,
25778,
304,
272,
408,
272,
710,
1300,
10935,
1084,
1021,
1630,
440,
5647,
1263,
5445,
701,
849,
14,
272,
408,
272,
986,
421,
199,
533,
8307,
21902,
8,
21902,
4256,
12,
1519,
2932,
14,
9417,
25778,
304,
272,
408,
272,
710,
8307,
21902,
1021,
1630,
440,
5647,
1263,
5445,
701,
849,
12,
272,
1325,
1630,
2387,
314,
1300,
663,
402,
7809,
2455,
5953
] |
[
199,
2768,
9899,
787,
28891,
2951,
282,
730,
402,
1021,
4079,
2455,
12,
626,
3181,
1133,
5647,
199,
1629,
1083,
8297,
12,
4066,
465,
658,
362,
342,
3559,
658,
1932,
342,
3559,
5423,
1396,
1325,
3140,
965,
5445,
12,
199,
10180,
465,
658,
513,
342,
3559,
658,
14270,
342,
3559,
658,
981,
342,
3559,
5423,
1396,
199,
199,
9303,
787,
1454,
3914,
370,
3102,
737,
314,
2376,
402,
9034,
1958,
314,
6858,
14,
339,
922,
63,
513,
275,
2876,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
513,
3071,
272,
922,
63,
5506,
275,
2876,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
14270,
3071,
199,
199,
21718,
7288,
12,
7830,
2419,
17321,
6858,
687,
2455,
2193,
5370,
12,
1265,
7171,
199,
2683,
314,
2455,
409,
543,
282,
6197,
436,
4691,
314,
2851,
3743,
506,
12037,
199,
2495,
17174,
14,
339,
6197,
275,
3758,
11691,
342,
272,
6197,
14,
2683,
8,
82,
7,
3707,
297,
2876,
21902,
12,
283,
751,
358,
272,
26177,
275,
6197,
14,
3603,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
1639,
14,
1208,
14,
11582,
492,
1021,
2118,
765,
199,
504,
1639,
14,
4196,
14,
11582,
14,
10088,
492,
19213,
63,
25254,
199,
504,
4618,
63,
4857,
492,
6858,
12,
1519,
2932,
12,
13667,
3617,
421,
199,
533,
10935,
1084,
4256,
8,
785,
304,
272,
408,
272,
961,
365,
314,
10628,
14,
339,
31144,
19853,
305,
63,
1345,
11995,
880,
626,
652,
6181,
376,
658,
3723,
64,
4252,
626,
18628,
272,
314,
11696,
402,
3101,
3102,
370,
5445,
641,
314,
7337,
14,
339,
2104,
2893,
12,
370,
1218,
282,
13801,
2455,
11696,
314,
283,
2970,
7,
436,
283,
4030,
7,
3102,
272,
370,
314,
283,
513,
7,
436,
283,
981,
7,
5445,
1396,
339,
2455,
275,
4932,
21902,
14,
305,
63,
1345,
3252,
362,
356,
283,
513,
297,
283,
1932,
356,
283,
981,
3071,
272,
408,
339,
768,
533,
2118,
765,
272,
347,
465,
63,
1345,
8,
1886,
12,
5445,
29,
403,
12,
1011,
826,
958,
304,
267,
408,
267,
13821,
402,
314,
4340,
1021,
4079,
6858,
1218,
282,
17903,
6818,
314,
267,
17544,
2455,
12,
781,
1929,
370,
12657,
1183,
295,
21463,
19853,
305,
63,
1345,
3559,
267,
436,
18023,
2811,
314,
2455,
805,
626,
365,
2737,
436,
2138,
14,
267,
408,
267,
327,
710,
4739,
4205,
12745,
365,
4644,
367,
21119,
314,
2455,
409,
730,
267,
327,
11837,
14,
283,
1296,
7,
503,
283,
3244,
1370,
267,
843,
14,
4511,
275,
488,
398,
327,
5445,
1471,
440,
506,
2701,
267,
340,
440,
5445,
26,
288,
746,
3146,
480,
1918,
658,
3723,
64,
1423,
1471,
506,
2741,
1380,
298,
1169,
298,
25566,
19853,
305,
63,
1345,
11995,
641,
282,
10935,
1084,
14,
2104,
2893,
298,
1169,
298,
2313,
305,
63,
1345,
3252,
362,
356,
283,
513,
3071,
22446,
398,
327,
21077,
4252,
2368,
267,
367,
790,
315,
4205,
958,
26,
288,
340,
790,
315,
843,
14,
1014,
63,
765,
63,
1247,
26,
355,
746,
3146,
480,
5556,
16416,
370,
986,
315,
314,
450,
83,
1083,
536,
465,
282,
298,
1816,
298,
6691,
1423,
370,
450,
83,
1252,
7529,
1133,
886,
626,
2122,
1816,
450,
334,
498,
12,
843,
855,
354,
8964,
288,
340,
440,
2688,
8,
1886,
12,
790,
304,
355,
746,
3146,
3647,
83,
342,
3086,
376,
3866,
4252,
450,
82,
2,
450,
334,
490,
843,
855,
354,
3108,
790,
430,
398,
347,
2455,
8,
1069,
12,
627,
589,
12,
1011,
958,
304,
288,
291,
275,
843,
3682,
826,
958,
9,
288,
327,
2136,
2597,
3877,
314,
4412,
402,
1056,
3102,
370,
5445,
12,
288,
327,
880,
626,
781,
883,
2945,
663,
314,
1595,
2225,
14,
288,
327,
11837,
14,
658,
277,
14,
1287,
275,
283,
513,
7,
64,
641,
376,
12467,
9576,
1056,
14,
288,
291,
14,
1287,
63,
1130,
275,
5445,
953,
327,
22630,
3102,
370,
5445,
288,
327,
961,
365,
314,
4546,
626,
1159,
3365,
370,
282,
4465,
2455,
288,
367,
1083,
12,
1595,
315,
5445,
14,
1744,
837,
355,
3016,
275,
2519,
8,
277,
12,
1595,
9,
355,
5371,
8,
277,
12,
1083,
12,
3016,
9,
953,
327,
19292,
642,
315,
465,
652,
1159,
4257,
1454,
3451,
687,
413,
14,
21,
641,
4751,
288,
340,
2688,
8,
277,
12,
283,
362,
358,
436,
440,
2688,
8,
277,
12,
283,
2993,
735,
355,
291,
14,
2993,
275,
291,
14,
362,
953,
327,
6061,
1980,
465,
20195,
288,
372,
291,
14,
6052,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
398,
327,
5452,
536,
436,
9214,
687,
1021,
267,
1678,
63,
5029,
8,
1345,
12,
843,
12,
4588,
29,
1012,
398,
327,
436,
3962,
3004,
663,
701,
20419,
267,
327,
2839,
19213,
63,
25254,
687,
7634,
267,
1678,
63,
5029,
8,
1345,
12,
843,
14,
6052,
12,
7943,
29,
1012,
398,
327,
2136,
1929,
370,
663,
3520,
641,
314,
2455,
805,
12,
880,
626,
330,
25972,
4295,
267,
327,
10152,
883,
3732,
734,
3520,
5821,
402,
2556,
687,
282,
267,
327,
12152,
2851,
14,
267,
2455,
14,
1886,
275,
843,
267,
2455,
14,
4511,
275,
4205,
958,
14,
362,
360,
4511,
297,
488,
9,
267,
372,
19213,
63,
25254,
8,
1345,
9,
339,
347,
8265,
63,
1069,
8,
277,
12,
1056,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
2494,
314,
19853,
1287,
64,
2225,
641,
314,
2455,
12,
267,
10298,
641,
314,
1056,
1083,
14,
267,
408,
267,
1056,
275,
1613,
8,
21902,
4256,
12,
291,
680,
8489,
63,
1069,
8,
1069,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
1287,
275,
291,
14,
1287,
63,
1130,
14,
362,
8,
1069,
14,
765,
14,
2325,
1012,
267,
372,
1056,
421,
199,
533,
10935,
1084,
8,
21902,
4256,
12,
6858,
14,
25778,
304,
272,
408,
272,
710,
1300,
10935,
1084,
1021,
1630,
440,
5647,
1263,
5445,
701,
849,
14,
272,
408,
272,
986,
421,
199,
533,
8307,
21902,
8,
21902,
4256,
12,
1519,
2932,
14,
9417,
25778,
304,
272,
408,
272,
710,
8307,
21902,
1021,
1630,
440,
5647,
1263,
5445,
701,
849,
12,
272,
1325,
1630,
2387,
314,
1300,
663,
402,
7809,
2455,
5953,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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711
|
try:
# Python 2 compat
reload
except NameError:
# Regular Python 3+ import
from importlib import reload
import numpy as np
from sklearn.utils.testing import assert_array_equal
from sklearn.utils.testing import assert_array_almost_equal
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_almost_equal
from sklearn.utils.testing import assert_true
from sklearn.utils.testing import assert_raises
from sklearn.utils.testing import assert_raise_message
from sklearn.utils.testing import assert_warns
from sklearn.utils.testing import assert_greater
from sklearn.utils.testing import ignore_warnings
from sklearn.datasets import make_blobs
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
# Data is just 6 separable points in the plane
X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]], dtype='f')
y = np.array([1, 1, 1, 2, 2, 2])
y3 = np.array([1, 1, 2, 2, 3, 3])
# Degenerate data with only one feature (still should be separable)
X1 = np.array([[-2, ], [-1, ], [-1, ], [1, ], [1, ], [2, ]], dtype='f')
# Data is just 9 separable points in the plane
X6 = np.array([[0, 0], [-2, -2], [-2, -1], [-1, -1], [-1, -2],
[1, 3], [1, 2], [2, 1], [2, 2]])
y6 = np.array([1, 1, 1, 1, 1, 2, 2, 2, 2])
y7 = np.array([1, 2, 3, 2, 3, 1, 2, 3, 1])
# Degenerate data with 1 feature (still should be separable)
X7 = np.array([[-3, ], [-2, ], [-1, ], [-1, ], [0, ], [1, ], [1, ],
[2, ], [3, ]])
# Data that has zero variance in one dimension and needs regularization
X2 = np.array([[-3, 0], [-2, 0], [-1, 0], [-1, 0], [0, 0], [1, 0], [1, 0],
[2, 0], [3, 0]])
# One element class
y4 = np.array([1, 1, 1, 1, 1, 1, 1, 1, 2])
# Data with less samples in a class than n_features
X5 = np.c_[np.arange(8), np.zeros((8, 3))]
y5 = np.array([0, 0, 0, 0, 0, 1, 1, 1])
solver_shrinkage = [('svd', None), ('lsqr', None), ('eigen', None),
('lsqr', 'auto'), ('lsqr', 0), ('lsqr', 0.43),
('eigen', 'auto'), ('eigen', 0), ('eigen', 0.43)]
def test_lda_predict():
# Test LDA classification.
# This checks that LDA implements fit and predict and returns correct
# values for simple toy data.
for test_case in solver_shrinkage:
solver, shrinkage = test_case
clf = LinearDiscriminantAnalysis(solver=solver, shrinkage=shrinkage)
y_pred = clf.fit(X, y).predict(X)
assert_array_equal(y_pred, y, 'solver %s' % solver)
# Assert that it works with 1D data
y_pred1 = clf.fit(X1, y).predict(X1)
assert_array_equal(y_pred1, y, 'solver %s' % solver)
# Test probability estimates
y_proba_pred1 = clf.predict_proba(X1)
assert_array_equal((y_proba_pred1[:, 1] > 0.5) + 1, y,
'solver %s' % solver)
y_log_proba_pred1 = clf.predict_log_proba(X1)
assert_array_almost_equal(np.exp(y_log_proba_pred1), y_proba_pred1,
8, 'solver %s' % solver)
# Primarily test for commit 2f34950 -- "reuse" of priors
y_pred3 = clf.fit(X, y3).predict(X)
# LDA shouldn't be able to separate those
assert_true(np.any(y_pred3 != y3), 'solver %s' % solver)
# Test invalid shrinkages
clf = LinearDiscriminantAnalysis(solver="lsqr", shrinkage=-0.2231)
assert_raises(ValueError, clf.fit, X, y)
clf = LinearDiscriminantAnalysis(solver="eigen", shrinkage="dummy")
assert_raises(ValueError, clf.fit, X, y)
clf = LinearDiscriminantAnalysis(solver="svd", shrinkage="auto")
assert_raises(NotImplementedError, clf.fit, X, y)
# Test unknown solver
clf = LinearDiscriminantAnalysis(solver="dummy")
assert_raises(ValueError, clf.fit, X, y)
def test_lda_priors():
# Test priors (negative priors)
priors = np.array([0.5, -0.5])
clf = LinearDiscriminantAnalysis(priors=priors)
msg = "priors must be non-negative"
assert_raise_message(ValueError, msg, clf.fit, X, y)
# Test that priors passed as a list are correctly handled (run to see if
# failure)
clf = LinearDiscriminantAnalysis(priors=[0.5, 0.5])
clf.fit(X, y)
# Test that priors always sum to 1
priors = np.array([0.5, 0.6])
prior_norm = np.array([0.45, 0.55])
clf = LinearDiscriminantAnalysis(priors=priors)
clf.fit(X, y)
assert_array_almost_equal(clf.priors_, prior_norm, 2)
def test_lda_coefs():
# Test if the coefficients of the solvers are approximately the same.
n_features = 2
n_classes = 2
n_samples = 1000
X, y = make_blobs(n_samples=n_samples, n_features=n_features,
centers=n_classes, random_state=11)
clf_lda_svd = LinearDiscriminantAnalysis(solver="svd")
clf_lda_lsqr = LinearDiscriminantAnalysis(solver="lsqr")
clf_lda_eigen = LinearDiscriminantAnalysis(solver="eigen")
clf_lda_svd.fit(X, y)
clf_lda_lsqr.fit(X, y)
clf_lda_eigen.fit(X, y)
assert_array_almost_equal(clf_lda_svd.coef_, clf_lda_lsqr.coef_, 1)
assert_array_almost_equal(clf_lda_svd.coef_, clf_lda_eigen.coef_, 1)
assert_array_almost_equal(clf_lda_eigen.coef_, clf_lda_lsqr.coef_, 1)
def test_lda_transform():
# Test LDA transform.
clf = LinearDiscriminantAnalysis(solver="svd", n_components=1)
X_transformed = clf.fit(X, y).transform(X)
assert_equal(X_transformed.shape[1], 1)
clf = LinearDiscriminantAnalysis(solver="eigen", n_components=1)
X_transformed = clf.fit(X, y).transform(X)
assert_equal(X_transformed.shape[1], 1)
clf = LinearDiscriminantAnalysis(solver="lsqr", n_components=1)
clf.fit(X, y)
msg = "transform not implemented for 'lsqr'"
assert_raise_message(NotImplementedError, msg, clf.transform, X)
def test_lda_explained_variance_ratio():
# Test if the sum of the normalized eigen vectors values equals 1
n_features = 2
n_classes = 2
n_samples = 1000
X, y = make_blobs(n_samples=n_samples, n_features=n_features,
centers=n_classes, random_state=11)
clf_lda_eigen = LinearDiscriminantAnalysis(solver="eigen")
clf_lda_eigen.fit(X, y)
assert_almost_equal(clf_lda_eigen.explained_variance_ratio_.sum(), 1.0, 3)
def test_lda_orthogonality():
# arrange four classes with their means in a kite-shaped pattern
# the longer distance should be transformed to the first component, and
# the shorter distance to the second component.
means = np.array([[0, 0, -1], [0, 2, 0], [0, -2, 0], [0, 0, 5]])
# We construct perfectly symmetric distributions, so the LDA can estimate
# precise means.
scatter = np.array([[0.1, 0, 0], [-0.1, 0, 0], [0, 0.1, 0], [0, -0.1, 0],
[0, 0, 0.1], [0, 0, -0.1]])
X = (means[:, np.newaxis, :] + scatter[np.newaxis, :, :]).reshape((-1, 3))
y = np.repeat(np.arange(means.shape[0]), scatter.shape[0])
# Fit LDA and transform the means
clf = LinearDiscriminantAnalysis(solver="svd").fit(X, y)
means_transformed = clf.transform(means)
d1 = means_transformed[3] - means_transformed[0]
d2 = means_transformed[2] - means_transformed[1]
d1 /= np.sqrt(np.sum(d1 ** 2))
d2 /= np.sqrt(np.sum(d2 ** 2))
# the transformed within-class covariance should be the identity matrix
assert_almost_equal(np.cov(clf.transform(scatter).T), np.eye(2))
# the means of classes 0 and 3 should lie on the first component
assert_almost_equal(np.abs(np.dot(d1[:2], [1, 0])), 1.0)
# the means of classes 1 and 2 should lie on the second component
assert_almost_equal(np.abs(np.dot(d2[:2], [0, 1])), 1.0)
def test_lda_scaling():
# Test if classification works correctly with differently scaled features.
n = 100
rng = np.random.RandomState(1234)
# use uniform distribution of features to make sure there is absolutely no
# overlap between classes.
x1 = rng.uniform(-1, 1, (n, 3)) + [-10, 0, 0]
x2 = rng.uniform(-1, 1, (n, 3)) + [10, 0, 0]
x = np.vstack((x1, x2)) * [1, 100, 10000]
y = [-1] * n + [1] * n
for solver in ('svd', 'lsqr', 'eigen'):
clf = LinearDiscriminantAnalysis(solver=solver)
# should be able to separate the data perfectly
assert_equal(clf.fit(x, y).score(x, y), 1.0,
'using covariance: %s' % solver)
def test_qda():
# QDA classification.
# This checks that QDA implements fit and predict and returns
# correct values for a simple toy dataset.
clf = QuadraticDiscriminantAnalysis()
y_pred = clf.fit(X6, y6).predict(X6)
assert_array_equal(y_pred, y6)
# Assure that it works with 1D data
y_pred1 = clf.fit(X7, y6).predict(X7)
assert_array_equal(y_pred1, y6)
# Test probas estimates
y_proba_pred1 = clf.predict_proba(X7)
assert_array_equal((y_proba_pred1[:, 1] > 0.5) + 1, y6)
y_log_proba_pred1 = clf.predict_log_proba(X7)
assert_array_almost_equal(np.exp(y_log_proba_pred1), y_proba_pred1, 8)
y_pred3 = clf.fit(X6, y7).predict(X6)
# QDA shouldn't be able to separate those
assert_true(np.any(y_pred3 != y7))
# Classes should have at least 2 elements
assert_raises(ValueError, clf.fit, X6, y4)
def test_qda_priors():
clf = QuadraticDiscriminantAnalysis()
y_pred = clf.fit(X6, y6).predict(X6)
n_pos = np.sum(y_pred == 2)
neg = 1e-10
clf = QuadraticDiscriminantAnalysis(priors=np.array([neg, 1 - neg]))
y_pred = clf.fit(X6, y6).predict(X6)
n_pos2 = np.sum(y_pred == 2)
assert_greater(n_pos2, n_pos)
def test_qda_store_covariances():
# The default is to not set the covariances_ attribute
clf = QuadraticDiscriminantAnalysis().fit(X6, y6)
assert_true(not hasattr(clf, 'covariances_'))
# Test the actual attribute:
clf = QuadraticDiscriminantAnalysis().fit(X6, y6, store_covariances=True)
assert_true(hasattr(clf, 'covariances_'))
assert_array_almost_equal(
clf.covariances_[0],
np.array([[0.7, 0.45], [0.45, 0.7]])
)
assert_array_almost_equal(
clf.covariances_[1],
np.array([[0.33333333, -0.33333333], [-0.33333333, 0.66666667]])
)
def test_qda_regularization():
# the default is reg_param=0. and will cause issues
# when there is a constant variable
clf = QuadraticDiscriminantAnalysis()
with ignore_warnings():
y_pred = clf.fit(X2, y6).predict(X2)
assert_true(np.any(y_pred != y6))
# adding a little regularization fixes the problem
clf = QuadraticDiscriminantAnalysis(reg_param=0.01)
with ignore_warnings():
clf.fit(X2, y6)
y_pred = clf.predict(X2)
assert_array_equal(y_pred, y6)
# Case n_samples_in_a_class < n_features
clf = QuadraticDiscriminantAnalysis(reg_param=0.1)
with ignore_warnings():
clf.fit(X5, y5)
y_pred5 = clf.predict(X5)
assert_array_equal(y_pred5, y5)
def test_deprecated_lda_qda_deprecation():
def import_lda_module():
import sklearn.lda
# ensure that we trigger DeprecationWarning even if the sklearn.lda
# was loaded previously by another test.
reload(sklearn.lda)
return sklearn.lda
lda = assert_warns(DeprecationWarning, import_lda_module)
assert lda.LDA is LinearDiscriminantAnalysis
def import_qda_module():
import sklearn.qda
# ensure that we trigger DeprecationWarning even if the sklearn.qda
# was loaded previously by another test.
reload(sklearn.qda)
return sklearn.qda
qda = assert_warns(DeprecationWarning, import_qda_module)
assert qda.QDA is QuadraticDiscriminantAnalysis
|
bsd-3-clause
|
[
893,
26,
272,
327,
2018,
499,
8434,
272,
13101,
199,
2590,
12746,
26,
272,
327,
18528,
2018,
650,
11,
492,
272,
687,
14802,
492,
13101,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
12489,
2825,
1408,
827,
867,
13182,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
5843,
350,
19826,
2825,
1408,
827,
867,
13182,
421,
199,
3,
3918,
365,
2951,
1227,
4216,
461,
4501,
315,
314,
16388,
199,
56,
275,
980,
14,
1144,
22844,
18,
12,
446,
17,
467,
5243,
17,
12,
446,
17,
467,
5243,
17,
12,
446,
18,
467,
359,
17,
12,
413,
467,
359,
17,
12,
499,
467,
359,
18,
12,
413,
2365,
2152,
534,
70,
358,
199,
89,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
499,
12,
499,
12,
499,
566,
199,
89,
19,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
499,
12,
499,
12,
650,
12,
650,
566,
199,
199,
3,
1487,
4208,
666,
543,
1454,
1373,
3878,
334,
32310,
1077,
506,
4216,
461,
9,
199,
56,
17,
275,
980,
14,
1144,
22844,
18,
12,
2156,
5243,
17,
12,
2156,
5243,
17,
12,
2156,
359,
17,
12,
2156,
359,
17,
12,
2156,
359,
18,
12,
1622,
467,
2152,
534,
70,
358,
199,
199,
3,
3918,
365,
2951,
1749,
4216,
461,
4501,
315,
314,
16388,
199,
56,
22,
275,
980,
14,
1144,
4038,
16,
12,
378,
467,
5243,
18,
12,
446,
18,
467,
5243,
18,
12,
446,
17,
467,
5243,
17,
12,
446,
17,
467,
5243,
17,
12,
446,
18,
467,
1598,
359,
17,
12,
650,
467,
359,
17,
12,
499,
467,
359,
18,
12,
413,
467,
359,
18,
12,
499,
3934,
199,
89,
22,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
499,
12,
499,
12,
499,
12,
499,
566,
199,
89,
23,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
499,
12,
650,
12,
413,
12,
499,
12,
650,
12,
413,
566,
199,
199,
3,
1487,
4208,
666,
543,
413,
3878,
334,
32310,
1077,
506,
4216,
461,
9,
199,
56,
23,
275,
980,
14,
1144,
22844,
19,
12,
2156,
5243,
18,
12,
2156,
5243,
17,
12,
2156,
5243,
17,
12,
2156,
359,
16,
12,
2156,
359,
17,
12,
2156,
359,
17,
12,
2156,
2049,
359,
18,
12,
2156,
359,
19,
12,
1622,
566,
199,
199,
3,
3918,
626,
965,
4697,
11773,
315,
1373,
6240,
436,
4839,
21095,
199,
56,
18,
275,
980,
14,
1144,
22844,
19,
12,
378,
467,
5243,
18,
12,
378,
467,
5243,
17,
12,
378,
467,
5243,
17,
12,
378,
467,
359,
16,
12,
378,
467,
359,
17,
12,
378,
467,
359,
17,
12,
378,
467,
2049,
359,
18,
12,
378,
467,
359,
19,
12,
378,
3934,
199,
199,
3,
7309,
1819,
1021,
199,
89,
20,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
499,
566,
199,
199,
3,
3918,
543,
6656,
5845,
315,
282,
1021,
2419,
302,
63,
3179,
199,
56,
21,
275,
980,
14,
67,
9925,
1590,
14,
5605,
8,
24,
395,
980,
14,
4250,
1332,
24,
12,
650,
10524,
199,
89,
21,
275,
980,
14,
1144,
779,
16,
12,
378,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
566,
199,
199,
11263,
63,
23733,
474,
275,
4274,
18675,
297,
488,
395,
661,
478,
16596,
297,
488,
395,
661,
19545,
297,
488,
395,
490,
661,
478,
16596,
297,
283,
2495,
659,
661,
478,
16596,
297,
378,
395,
661,
478,
16596,
297,
378,
14,
2824,
395,
490,
661,
19545,
297,
283,
2495,
659,
661,
19545,
297,
378,
395,
661,
19545,
297,
378,
14,
2824,
1874,
421,
199,
318,
511,
63,
76,
983,
63,
6892,
837,
272,
327,
1379,
491,
8980,
12505,
14,
272,
327,
961,
5920,
626,
491,
8980,
9031,
5542,
436,
12610,
436,
2529,
3211,
272,
327,
1338,
367,
3486,
31239,
666,
14,
272,
367,
511,
63,
2546,
315,
10196,
63,
23733,
474,
26,
267,
10196,
12,
19790,
474,
275,
511,
63,
2546,
267,
6975,
275,
12489,
2825,
1408,
827,
867,
13182,
8,
11263,
29,
11263,
12,
19790,
474,
29,
23733,
474,
9,
267,
612,
63,
5991,
275,
6975,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
267,
702,
63,
1144,
63,
1452,
8,
89,
63,
5991,
12,
612,
12,
283,
11263,
450,
83,
7,
450,
10196,
9,
398,
327,
10716,
626,
652,
5419,
543,
413,
36,
666,
267,
612,
63,
5991,
17,
275,
6975,
14,
3269,
8,
56,
17,
12,
612,
680,
6892,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
1452,
8,
89,
63,
5991,
17,
12,
612,
12,
283,
11263,
450,
83,
7,
450,
10196,
9,
398,
327,
1379,
12224,
23505,
267,
612,
63,
14417,
63,
5991,
17,
275,
6975,
14,
6892,
63,
14417,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
1452,
1332,
89,
63,
14417,
63,
5991,
17,
3981,
413,
61,
690,
378,
14,
21,
9,
435,
413,
12,
612,
12,
2574,
283,
11263,
450,
83,
7,
450,
10196,
9,
267,
612,
63,
793,
63,
14417,
63,
5991,
17,
275,
6975,
14,
6892,
63,
793,
63,
14417,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
1474,
8,
89,
63,
793,
63,
14417,
63,
5991,
17,
395,
612,
63,
14417,
63,
5991,
17
] |
[
26,
272,
327,
2018,
499,
8434,
272,
13101,
199,
2590,
12746,
26,
272,
327,
18528,
2018,
650,
11,
492,
272,
687,
14802,
492,
13101,
199,
646,
2680,
465,
980,
199,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
4398,
63,
1452,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2052,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3536,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
3730,
63,
1188,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
19811,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
13154,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
504,
6357,
14,
12281,
492,
1852,
63,
21893,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
12489,
2825,
1408,
827,
867,
13182,
199,
504,
6357,
14,
328,
20129,
867,
63,
10466,
492,
5843,
350,
19826,
2825,
1408,
827,
867,
13182,
421,
199,
3,
3918,
365,
2951,
1227,
4216,
461,
4501,
315,
314,
16388,
199,
56,
275,
980,
14,
1144,
22844,
18,
12,
446,
17,
467,
5243,
17,
12,
446,
17,
467,
5243,
17,
12,
446,
18,
467,
359,
17,
12,
413,
467,
359,
17,
12,
499,
467,
359,
18,
12,
413,
2365,
2152,
534,
70,
358,
199,
89,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
499,
12,
499,
12,
499,
566,
199,
89,
19,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
499,
12,
499,
12,
650,
12,
650,
566,
199,
199,
3,
1487,
4208,
666,
543,
1454,
1373,
3878,
334,
32310,
1077,
506,
4216,
461,
9,
199,
56,
17,
275,
980,
14,
1144,
22844,
18,
12,
2156,
5243,
17,
12,
2156,
5243,
17,
12,
2156,
359,
17,
12,
2156,
359,
17,
12,
2156,
359,
18,
12,
1622,
467,
2152,
534,
70,
358,
199,
199,
3,
3918,
365,
2951,
1749,
4216,
461,
4501,
315,
314,
16388,
199,
56,
22,
275,
980,
14,
1144,
4038,
16,
12,
378,
467,
5243,
18,
12,
446,
18,
467,
5243,
18,
12,
446,
17,
467,
5243,
17,
12,
446,
17,
467,
5243,
17,
12,
446,
18,
467,
1598,
359,
17,
12,
650,
467,
359,
17,
12,
499,
467,
359,
18,
12,
413,
467,
359,
18,
12,
499,
3934,
199,
89,
22,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
499,
12,
499,
12,
499,
12,
499,
566,
199,
89,
23,
275,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
12,
499,
12,
650,
12,
413,
12,
499,
12,
650,
12,
413,
566,
199,
199,
3,
1487,
4208,
666,
543,
413,
3878,
334,
32310,
1077,
506,
4216,
461,
9,
199,
56,
23,
275,
980,
14,
1144,
22844,
19,
12,
2156,
5243,
18,
12,
2156,
5243,
17,
12,
2156,
5243,
17,
12,
2156,
359,
16,
12,
2156,
359,
17,
12,
2156,
359,
17,
12,
2156,
2049,
359,
18,
12,
2156,
359,
19,
12,
1622,
566,
199,
199,
3,
3918,
626,
965,
4697,
11773,
315,
1373,
6240,
436,
4839,
21095,
199,
56,
18,
275,
980,
14,
1144,
22844,
19,
12,
378,
467,
5243,
18,
12,
378,
467,
5243,
17,
12,
378,
467,
5243,
17,
12,
378,
467,
359,
16,
12,
378,
467,
359,
17,
12,
378,
467,
359,
17,
12,
378,
467,
2049,
359,
18,
12,
378,
467,
359,
19,
12,
378,
3934,
199,
199,
3,
7309,
1819,
1021,
199,
89,
20,
275,
980,
14,
1144,
779,
17,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
413,
12,
499,
566,
199,
199,
3,
3918,
543,
6656,
5845,
315,
282,
1021,
2419,
302,
63,
3179,
199,
56,
21,
275,
980,
14,
67,
9925,
1590,
14,
5605,
8,
24,
395,
980,
14,
4250,
1332,
24,
12,
650,
10524,
199,
89,
21,
275,
980,
14,
1144,
779,
16,
12,
378,
12,
378,
12,
378,
12,
378,
12,
413,
12,
413,
12,
413,
566,
199,
199,
11263,
63,
23733,
474,
275,
4274,
18675,
297,
488,
395,
661,
478,
16596,
297,
488,
395,
661,
19545,
297,
488,
395,
490,
661,
478,
16596,
297,
283,
2495,
659,
661,
478,
16596,
297,
378,
395,
661,
478,
16596,
297,
378,
14,
2824,
395,
490,
661,
19545,
297,
283,
2495,
659,
661,
19545,
297,
378,
395,
661,
19545,
297,
378,
14,
2824,
1874,
421,
199,
318,
511,
63,
76,
983,
63,
6892,
837,
272,
327,
1379,
491,
8980,
12505,
14,
272,
327,
961,
5920,
626,
491,
8980,
9031,
5542,
436,
12610,
436,
2529,
3211,
272,
327,
1338,
367,
3486,
31239,
666,
14,
272,
367,
511,
63,
2546,
315,
10196,
63,
23733,
474,
26,
267,
10196,
12,
19790,
474,
275,
511,
63,
2546,
267,
6975,
275,
12489,
2825,
1408,
827,
867,
13182,
8,
11263,
29,
11263,
12,
19790,
474,
29,
23733,
474,
9,
267,
612,
63,
5991,
275,
6975,
14,
3269,
8,
56,
12,
612,
680,
6892,
8,
56,
9,
267,
702,
63,
1144,
63,
1452,
8,
89,
63,
5991,
12,
612,
12,
283,
11263,
450,
83,
7,
450,
10196,
9,
398,
327,
10716,
626,
652,
5419,
543,
413,
36,
666,
267,
612,
63,
5991,
17,
275,
6975,
14,
3269,
8,
56,
17,
12,
612,
680,
6892,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
1452,
8,
89,
63,
5991,
17,
12,
612,
12,
283,
11263,
450,
83,
7,
450,
10196,
9,
398,
327,
1379,
12224,
23505,
267,
612,
63,
14417,
63,
5991,
17,
275,
6975,
14,
6892,
63,
14417,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
1452,
1332,
89,
63,
14417,
63,
5991,
17,
3981,
413,
61,
690,
378,
14,
21,
9,
435,
413,
12,
612,
12,
2574,
283,
11263,
450,
83,
7,
450,
10196,
9,
267,
612,
63,
793,
63,
14417,
63,
5991,
17,
275,
6975,
14,
6892,
63,
793,
63,
14417,
8,
56,
17,
9,
267,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
1474,
8,
89,
63,
793,
63,
14417,
63,
5991,
17,
395,
612,
63,
14417,
63,
5991,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
priseborough/ardupilot
|
Tools/ardupilotwaf/ardupilotwaf.py
|
1
|
14418
|
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
from waflib import Build, ConfigSet, Configure, Context, Errors, Logs, Options, Utils
from waflib.Configure import conf
from waflib.Scripting import run_command
from waflib.TaskGen import before_method, feature
import os.path, os
from collections import OrderedDict
import ap_persistent
SOURCE_EXTS = [
'*.S',
'*.c',
'*.cpp',
]
COMMON_VEHICLE_DEPENDENT_LIBRARIES = [
'AP_AccelCal',
'AP_ADC',
'AP_AHRS',
'AP_Airspeed',
'AP_Baro',
'AP_BattMonitor',
'AP_BoardConfig',
'AP_Common',
'AP_Compass',
'AP_Declination',
'AP_GPS',
'AP_HAL',
'AP_HAL_Empty',
'AP_InertialSensor',
'AP_Math',
'AP_Mission',
'AP_NavEKF2',
'AP_NavEKF3',
'AP_Notify',
'AP_OpticalFlow',
'AP_Param',
'AP_Rally',
'AP_RangeFinder',
'AP_Scheduler',
'AP_SerialManager',
'AP_Terrain',
'AP_Vehicle',
'AP_InternalError',
'AP_Logger',
'Filter',
'GCS_MAVLink',
'RC_Channel',
'SRV_Channel',
'StorageManager',
'AP_Tuning',
'AP_RPM',
'AP_RSSI',
'AP_Mount',
'AP_Module',
'AP_Button',
'AP_ICEngine',
'AP_Frsky_Telem',
'AP_FlashStorage',
'AP_Relay',
'AP_ServoRelayEvents',
'AP_Volz_Protocol',
'AP_SBusOut',
'AP_IOMCU',
'AP_Parachute',
'AP_RAMTRON',
'AP_RCProtocol',
'AP_Radio',
'AP_TempCalibration',
'AP_VisualOdom',
'AP_BLHeli',
'AP_ROMFS',
'AP_Proximity',
'AP_Gripper',
'AP_RTC',
'AC_Sprayer',
'AC_Fence',
'AC_Avoidance',
'AP_LandingGear',
'AP_RobotisServo',
'AP_ToshibaCAN',
]
def get_legacy_defines(sketch_name):
return [
'APM_BUILD_DIRECTORY=APM_BUILD_' + sketch_name,
'SKETCH="' + sketch_name + '"',
'SKETCHNAME="' + sketch_name + '"',
]
IGNORED_AP_LIBRARIES = [
'doc',
'AP_Scripting', # this gets explicitly included when it is needed and should otherwise never be globbed in
]
def ap_autoconfigure(execute_method):
"""
Decorator that enables context commands to run *configure* as needed.
"""
def execute(self):
"""
Wraps :py:func:`waflib.Context.Context.execute` on the context class
"""
if not Configure.autoconfig:
return execute_method(self)
# Disable autoconfig so waf's version doesn't run (and don't end up on loop of bad configure)
Configure.autoconfig = False
if self.variant == '':
raise Errors.WafError('The project is badly configured: run "waf configure" again!')
env = ConfigSet.ConfigSet()
do_config = False
try:
p = os.path.join(Context.out_dir, Build.CACHE_DIR, self.variant + Build.CACHE_SUFFIX)
env.load(p)
except EnvironmentError:
raise Errors.WafError('The project is not configured for board {0}: run "waf configure --board {0} [...]" first!'.format(self.variant))
lock_env = ConfigSet.ConfigSet()
try:
lock_env.load(os.path.join(Context.top_dir, Options.lockfile))
except EnvironmentError:
Logs.warn('Configuring the project')
do_config = True
else:
if lock_env.run_dir != Context.run_dir:
do_config = True
else:
h = 0
for f in env.CONFIGURE_FILES:
try:
h = Utils.h_list((h, Utils.readf(f, 'rb')))
except EnvironmentError:
do_config = True
break
else:
do_config = h != env.CONFIGURE_HASH
if do_config:
cmd = lock_env.config_cmd or 'configure'
tmp = Options.options.__dict__
if env.OPTIONS and sorted(env.OPTIONS.keys()) == sorted(tmp.keys()):
Options.options.__dict__ = env.OPTIONS
else:
raise Errors.WafError('The project configure options have changed: run "waf configure" again!')
try:
run_command(cmd)
finally:
Options.options.__dict__ = tmp
run_command(self.cmd)
else:
return execute_method(self)
return execute
def ap_configure_post_recurse():
post_recurse_orig = Configure.ConfigurationContext.post_recurse
def post_recurse(self, node):
post_recurse_orig(self, node)
self.all_envs[self.variant].CONFIGURE_FILES = self.files
self.all_envs[self.variant].CONFIGURE_HASH = self.hash
return post_recurse
@conf
def ap_get_all_libraries(bld):
if bld.env.BOOTLOADER:
# we don't need the full set of libraries for the bootloader build
return ['AP_HAL']
libraries = []
for lib_node in bld.srcnode.ant_glob('libraries/*', dir=True, src=False):
name = lib_node.name
if name in IGNORED_AP_LIBRARIES:
continue
if name.startswith('AP_HAL'):
continue
if name == 'SITL':
continue
libraries.append(name)
libraries.extend(['AP_HAL', 'AP_HAL_Empty'])
return libraries
@conf
def ap_common_vehicle_libraries(bld):
libraries = COMMON_VEHICLE_DEPENDENT_LIBRARIES
if bld.env.DEST_BINFMT == 'pe':
libraries += [
'AC_Fence',
'AC_AttitudeControl',
]
return libraries
_grouped_programs = {}
@conf
def ap_program(bld,
program_groups='bin',
program_dir=None,
use_legacy_defines=True,
program_name=None,
**kw):
if 'target' in kw:
bld.fatal('Do not pass target for program')
if 'defines' not in kw:
kw['defines'] = []
if 'source' not in kw:
kw['source'] = bld.path.ant_glob(SOURCE_EXTS)
if not program_name:
program_name = bld.path.name
if use_legacy_defines:
kw['defines'].extend(get_legacy_defines(bld.path.name))
kw['cxxflags'] = kw.get('cxxflags', []) + ['-include', 'ap_config.h']
kw['features'] = kw.get('features', []) + bld.env.AP_PROGRAM_FEATURES
program_groups = Utils.to_list(program_groups)
if not program_dir:
program_dir = program_groups[0]
name = os.path.join(program_dir, program_name)
tg_constructor = bld.program
if bld.env.AP_PROGRAM_AS_STLIB:
tg_constructor = bld.stlib
else:
if bld.env.STATIC_LINKING:
kw['features'].append('static_linking')
tg = tg_constructor(
target='#%s' % name,
name=name,
program_name=program_name,
program_dir=program_dir,
**kw
)
if 'use' in kw and bld.env.STATIC_LINKING:
# ensure we link against vehicle library
tg.env.STLIB += [kw['use']]
for group in program_groups:
_grouped_programs.setdefault(group, []).append(tg)
@conf
def ap_example(bld, **kw):
kw['program_groups'] = 'examples'
ap_program(bld, use_legacy_defines=False, **kw)
def unique_list(items):
'''remove duplicate elements from a list while maintaining ordering'''
return list(OrderedDict.fromkeys(items))
@conf
def ap_stlib(bld, **kw):
if 'name' not in kw:
bld.fatal('Missing name for ap_stlib')
if 'ap_vehicle' not in kw:
bld.fatal('Missing ap_vehicle for ap_stlib')
if 'ap_libraries' not in kw:
bld.fatal('Missing ap_libraries for ap_stlib')
kw['ap_libraries'] = unique_list(kw['ap_libraries'] + bld.env.AP_LIBRARIES)
for l in kw['ap_libraries']:
bld.ap_library(l, kw['ap_vehicle'])
kw['features'] = kw.get('features', []) + ['cxx', 'cxxstlib']
kw['target'] = kw['name']
kw['source'] = []
bld.stlib(**kw)
_created_program_dirs = set()
@feature('cxxstlib', 'cxxprogram')
@before_method('process_rule')
def ap_create_program_dir(self):
if not hasattr(self, 'program_dir'):
return
if self.program_dir in _created_program_dirs:
return
self.bld.bldnode.make_node(self.program_dir).mkdir()
_created_program_dirs.add(self.program_dir)
@feature('cxxstlib')
@before_method('process_rule')
def ap_stlib_target(self):
if self.target.startswith('#'):
self.target = self.target[1:]
self.target = '#%s' % os.path.join('lib', self.target)
@conf
def ap_find_tests(bld, use=[]):
if not bld.env.HAS_GTEST:
return
features = []
if bld.cmd == 'check':
features.append('test')
use = Utils.to_list(use)
use.append('GTEST')
includes = [bld.srcnode.abspath() + '/tests/']
for f in bld.path.ant_glob(incl='*.cpp'):
ap_program(
bld,
features=features,
includes=includes,
source=[f],
use=use,
program_name=f.change_ext('').name,
program_groups='tests',
use_legacy_defines=False,
cxxflags=['-Wno-undef'],
)
_versions = []
@conf
def ap_version_append_str(ctx, k, v):
ctx.env['AP_VERSION_ITEMS'] += [(k, '"{}"'.format(os.environ.get(k, v)))]
@conf
def ap_version_append_int(ctx, k, v):
ctx.env['AP_VERSION_ITEMS'] += [(k,v)]
@conf
def write_version_header(ctx, tgt):
with open(tgt, 'w') as f:
print(
'''// auto-generated header, do not edit
#pragma once
#ifndef FORCE_VERSION_H_INCLUDE
#error ap_version.h should never be included directly. You probably want to include AP_Common/AP_FWVersion.h
#endif
''', file=f)
for k, v in ctx.env['AP_VERSION_ITEMS']:
print('#define {} {}'.format(k, v), file=f)
@conf
def ap_find_benchmarks(bld, use=[]):
if not bld.env.HAS_GBENCHMARK:
return
includes = [bld.srcnode.abspath() + '/benchmarks/']
for f in bld.path.ant_glob(incl='*.cpp'):
ap_program(
bld,
features=['gbenchmark'],
includes=includes,
source=[f],
use=use,
program_name=f.change_ext('').name,
program_groups='benchmarks',
use_legacy_defines=False,
)
def test_summary(bld):
from io import BytesIO
import sys
if not hasattr(bld, 'utest_results'):
Logs.info('check: no test run')
return
fails = []
for filename, exit_code, out, err in bld.utest_results:
Logs.pprint('GREEN' if exit_code == 0 else 'YELLOW',
' %s' % filename,
'returned %d' % exit_code)
if exit_code != 0:
fails.append(filename)
elif not bld.options.check_verbose:
continue
if len(out):
buf = BytesIO(out)
for line in buf:
print(" OUT: %s" % line.decode(), end='', file=sys.stderr)
print()
if len(err):
buf = BytesIO(err)
for line in buf:
print(" ERR: %s" % line.decode(), end='', file=sys.stderr)
print()
if not fails:
Logs.info('check: All %u tests passed!' % len(bld.utest_results))
return
Logs.error('check: %u of %u tests failed' %
(len(fails), len(bld.utest_results)))
for filename in fails:
Logs.error(' %s' % filename)
bld.fatal('check: some tests failed')
_build_commands = {}
def _process_build_command(bld):
if bld.cmd not in _build_commands:
return
params = _build_commands[bld.cmd]
targets = params['targets']
if targets:
if bld.targets:
bld.targets += ',' + targets
else:
bld.targets = targets
program_group_list = Utils.to_list(params['program_group_list'])
bld.options.program_group.extend(program_group_list)
def build_command(name,
targets=None,
program_group_list=[],
doc='build shortcut'):
_build_commands[name] = dict(
targets=targets,
program_group_list=program_group_list,
)
class context_class(Build.BuildContext):
cmd = name
context_class.__doc__ = doc
def _select_programs_from_group(bld):
groups = bld.options.program_group
if not groups:
if bld.targets:
groups = []
else:
groups = ['bin']
if 'all' in groups:
groups = _grouped_programs.keys()
for group in groups:
if group not in _grouped_programs:
bld.fatal('Group %s not found' % group)
tg = _grouped_programs[group][0]
if bld.targets:
bld.targets += ',' + tg.name
else:
bld.targets = tg.name
for tg in _grouped_programs[group][1:]:
bld.targets += ',' + tg.name
def options(opt):
opt.ap_groups = {
'configure': opt.add_option_group('Ardupilot configure options'),
'linux': opt.add_option_group('Linux boards configure options'),
'build': opt.add_option_group('Ardupilot build options'),
'check': opt.add_option_group('Ardupilot check options'),
'clean': opt.add_option_group('Ardupilot clean options'),
}
g = opt.ap_groups['build']
g.add_option('--program-group',
action='append',
default=[],
help='''Select all programs that go in <PROGRAM_GROUP>/ for the build.
Example: `waf --program-group examples` builds all examples. The
special group "all" selects all programs.
''')
g.add_option('--upload',
action='store_true',
help='''Upload applicable targets to a connected device. Not all
platforms may support this. Example: `waf copter --upload` means "build
arducopter and upload it to my board".
''')
g = opt.ap_groups['check']
g.add_option('--check-verbose',
action='store_true',
help='Output all test programs.')
g = opt.ap_groups['clean']
g.add_option('--clean-all-sigs',
action='store_true',
help='''Clean signatures for all tasks. By default, tasks that scan for
implicit dependencies (like the compilation tasks) keep the dependency
information across clean commands, so that that information is changed
only when really necessary. Also, some tasks that don't really produce
files persist their signature. This option avoids that behavior when
cleaning the build.
''')
def build(bld):
bld.add_pre_fun(_process_build_command)
bld.add_pre_fun(_select_programs_from_group)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
31380,
492,
6516,
12,
4094,
1084,
12,
15453,
12,
9470,
12,
20456,
12,
3835,
458,
12,
8394,
12,
17397,
199,
504,
31380,
14,
17324,
492,
3743,
199,
504,
31380,
14,
5229,
316,
492,
1255,
63,
1531,
199,
504,
31380,
14,
4476,
8168,
492,
2544,
63,
765,
12,
3878,
199,
646,
747,
14,
515,
12,
747,
199,
504,
5055,
492,
8773,
199,
199,
646,
2771,
63,
18539,
199,
199,
10187,
63,
2472,
51,
275,
359,
272,
11937,
51,
297,
272,
11937,
67,
297,
272,
11937,
5910,
297,
199,
61,
199,
199,
21637,
63,
2524,
40,
948,
906,
63,
25743,
1309,
63,
32723,
275,
359,
272,
283,
1282,
63,
1945,
6067,
6584,
297,
272,
283,
1282,
63,
1554,
35,
297,
272,
283,
1282,
63,
33,
14784,
51,
297,
272,
283,
1282,
63,
28948,
7625,
297,
272,
283,
1282,
63,
5281,
79,
297,
272,
283,
1282,
63,
34,
6796,
13189,
297,
272,
283,
1282,
63,
18995,
2028,
297,
272,
283,
1282,
63,
7844,
297,
272,
283,
1282,
63,
2404,
405,
297,
272,
283,
1282,
63,
20856,
3155,
297,
272,
283,
1282,
63,
26359,
297,
272,
283,
1282,
63,
40,
748,
297,
272,
283,
1282,
63,
40,
748,
63,
4699,
297,
272,
283,
1282,
63,
607,
281,
1009,
10160,
297,
272,
283,
1282,
63,
18568,
297,
272,
283,
1282,
63,
5829,
438,
297,
272,
283,
1282,
63,
31488,
11959,
38,
18,
297,
272,
283,
1282,
63,
31488,
11959,
38,
19,
297,
272,
283,
1282,
63,
8645,
297,
272,
283,
1282,
63,
4619,
3294,
5060,
297,
272,
283,
1282,
63,
4098,
297,
272,
283,
1282,
63,
50,
1183,
297,
272,
283,
1282,
63,
4709,
11791,
297,
272,
283,
1282,
63,
11251,
297,
272,
283,
1282,
63,
3571,
2988,
297,
272,
283,
1282,
63,
8600,
6322,
297,
272,
283,
1282,
63,
15169,
13438,
297,
272,
283,
1282,
63,
8405,
547,
297,
272,
283,
1282,
63,
4455,
297,
272,
283,
4131,
297,
272,
283,
39,
3298,
63,
19273,
3834,
297,
272,
283,
8205,
63,
5358,
297,
272,
283,
31546,
63,
5358,
297,
272,
283,
6408,
2988,
297,
272,
283,
1282,
63,
22664,
316,
297,
272,
283,
1282,
63,
32067,
297,
272,
283,
1282,
63,
22786,
41,
297,
272,
283,
1282,
63,
24467,
297,
272,
283,
1282,
63,
2377,
297,
272,
283,
1282,
63,
4259,
297,
272,
283,
1282,
63,
948,
8524,
297,
272,
283,
1282,
63,
13848,
12267,
63,
52,
6086,
297,
272,
283,
1282,
63,
29189,
6408,
297,
272,
283,
1282,
63,
5640,
1187,
297,
272,
283,
1282,
63,
1505,
2392,
5640,
1187,
11770,
297,
272,
283,
1282,
63,
16969,
90,
63,
3658,
297,
272,
283,
1282,
63,
51,
12106,
2204,
297,
272,
283,
1282,
63,
2090,
7608,
53,
297,
272,
283,
1282,
63,
1262,
1225,
938,
297,
272,
283,
1282,
63,
30839,
1766,
615,
297,
272,
283,
1282,
63,
8205,
3658,
297,
272,
283,
1282,
63,
16065,
297,
272,
283,
1282,
63,
6530,
26015,
1754,
297,
272,
283,
1282,
63,
15039,
47,
4556,
297,
272,
283,
1282,
63,
7847,
1966,
317,
297,
272,
283,
1282,
63,
3810,
7079,
297,
272,
283,
1282,
63,
26689,
1017,
1209,
297,
272,
283,
1282,
63,
39,
24210,
529,
297,
272,
283,
1282,
63,
50,
5708,
297,
272,
283,
1348,
63,
5058,
803,
281,
297,
272,
283,
1348,
63,
38,
4894,
297,
272,
283,
1348,
63,
33,
1647,
554,
297,
272,
283,
1282,
63,
44,
460,
316,
39,
2210,
297,
272,
283,
1282,
63,
3863,
656,
16753,
1505,
2392,
297,
272,
283,
1282,
63,
1378,
609,
1892,
65,
18988,
297,
199,
61,
199,
199,
318,
664,
63,
10000,
63,
14334,
8,
1339,
2367,
63,
354,
304,
272,
372,
359,
267,
283,
1282,
45,
63,
8248,
63,
16436,
29,
1282,
45,
63,
8248,
8650,
435,
2386,
2367,
63,
354,
12,
267,
283,
8656,
26025,
26957,
435,
2386,
2367,
63,
354,
435,
32089,
267,
283,
8656,
26025,
2339,
26957,
435,
2386,
2367,
63,
354,
435,
32089,
272,
1622,
199,
199,
3203,
25517,
63,
1282,
63,
32723,
275,
359,
272,
283,
1301,
297,
272,
283,
1282,
63,
5229,
316,
297,
327,
642,
7545,
7662,
5120,
1380,
652,
365,
4346,
436,
1077,
4257,
7078,
506,
5739,
6123,
315,
199,
61,
421,
199,
318,
2771,
63,
2495,
6472,
8,
2526,
63,
765,
304,
272,
408,
272,
30684,
626,
22741,
1067,
3718,
370,
1255,
627,
6472,
10,
465,
4346,
14,
272,
408,
272,
347,
5341,
8,
277,
304,
267,
408,
267,
644,
8146,
520,
647,
26,
1532,
1705,
21500,
773,
14,
2998,
14,
2998,
14,
2526,
64,
641,
314,
1067,
1021,
267,
408,
267,
340,
440,
15453,
14,
2495,
888,
26,
288,
372,
5341,
63,
765,
8,
277,
9,
398,
327,
17534,
2599,
888,
880,
25782,
1159,
1015,
3181,
1133,
1255,
334,
460,
2793,
1133,
1284,
1536,
641,
4438,
402,
4875,
7908,
9,
267,
15453,
14,
2495,
888,
275,
756,
398,
340,
291,
14,
8759,
508,
8061,
288,
746,
20456,
14,
55,
2756,
547,
360,
1918,
2199,
365,
4875,
590,
7526,
26,
1255,
298,
21500,
7908,
2,
4020,
10916,
398,
2589,
275,
4094,
1084,
14,
2028,
1084,
342,
267,
886,
63,
888,
275,
756,
398,
862,
26,
288,
299,
275,
747,
14,
515,
14,
904,
8,
2998,
14,
548,
63,
694,
12,
6516,
14,
8677,
63,
3022,
12,
291,
14,
8759,
435,
6516,
14,
8677,
63,
12273,
9,
288,
2589,
14,
912,
8,
80,
9,
267,
871,
25139,
26,
288,
746,
20456,
14,
55,
2756,
547,
360,
1918,
2199,
365,
440,
7526,
367,
13811,
469,
16,
9160,
1255,
298,
21500,
7908,
1553,
3576,
469,
16,
93,
359,
1396,
8480,
1642,
1,
1370,
908,
8,
277,
14,
8759,
430,
398,
4650,
63,
1813,
275,
4094,
1084,
14,
2028,
1084,
342,
398,
862,
26,
288,
4650,
63,
1813,
14,
912,
8,
736,
14,
515,
14,
904,
8,
2998,
14,
2119,
63,
694,
12,
8394,
14,
26204,
430,
267,
871,
25139,
26,
288,
3835,
458,
14,
4050,
360,
2028,
4039,
314,
2199,
358,
288,
886,
63,
888,
275,
715,
267,
587,
26,
288,
340,
4650,
63,
1813,
14,
1065,
63,
694,
1137,
9470,
14,
1065,
63,
694
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
31380,
492,
6516,
12,
4094,
1084,
12,
15453,
12,
9470,
12,
20456,
12,
3835,
458,
12,
8394,
12,
17397,
199,
504,
31380,
14,
17324,
492,
3743,
199,
504,
31380,
14,
5229,
316,
492,
1255,
63,
1531,
199,
504,
31380,
14,
4476,
8168,
492,
2544,
63,
765,
12,
3878,
199,
646,
747,
14,
515,
12,
747,
199,
504,
5055,
492,
8773,
199,
199,
646,
2771,
63,
18539,
199,
199,
10187,
63,
2472,
51,
275,
359,
272,
11937,
51,
297,
272,
11937,
67,
297,
272,
11937,
5910,
297,
199,
61,
199,
199,
21637,
63,
2524,
40,
948,
906,
63,
25743,
1309,
63,
32723,
275,
359,
272,
283,
1282,
63,
1945,
6067,
6584,
297,
272,
283,
1282,
63,
1554,
35,
297,
272,
283,
1282,
63,
33,
14784,
51,
297,
272,
283,
1282,
63,
28948,
7625,
297,
272,
283,
1282,
63,
5281,
79,
297,
272,
283,
1282,
63,
34,
6796,
13189,
297,
272,
283,
1282,
63,
18995,
2028,
297,
272,
283,
1282,
63,
7844,
297,
272,
283,
1282,
63,
2404,
405,
297,
272,
283,
1282,
63,
20856,
3155,
297,
272,
283,
1282,
63,
26359,
297,
272,
283,
1282,
63,
40,
748,
297,
272,
283,
1282,
63,
40,
748,
63,
4699,
297,
272,
283,
1282,
63,
607,
281,
1009,
10160,
297,
272,
283,
1282,
63,
18568,
297,
272,
283,
1282,
63,
5829,
438,
297,
272,
283,
1282,
63,
31488,
11959,
38,
18,
297,
272,
283,
1282,
63,
31488,
11959,
38,
19,
297,
272,
283,
1282,
63,
8645,
297,
272,
283,
1282,
63,
4619,
3294,
5060,
297,
272,
283,
1282,
63,
4098,
297,
272,
283,
1282,
63,
50,
1183,
297,
272,
283,
1282,
63,
4709,
11791,
297,
272,
283,
1282,
63,
11251,
297,
272,
283,
1282,
63,
3571,
2988,
297,
272,
283,
1282,
63,
8600,
6322,
297,
272,
283,
1282,
63,
15169,
13438,
297,
272,
283,
1282,
63,
8405,
547,
297,
272,
283,
1282,
63,
4455,
297,
272,
283,
4131,
297,
272,
283,
39,
3298,
63,
19273,
3834,
297,
272,
283,
8205,
63,
5358,
297,
272,
283,
31546,
63,
5358,
297,
272,
283,
6408,
2988,
297,
272,
283,
1282,
63,
22664,
316,
297,
272,
283,
1282,
63,
32067,
297,
272,
283,
1282,
63,
22786,
41,
297,
272,
283,
1282,
63,
24467,
297,
272,
283,
1282,
63,
2377,
297,
272,
283,
1282,
63,
4259,
297,
272,
283,
1282,
63,
948,
8524,
297,
272,
283,
1282,
63,
13848,
12267,
63,
52,
6086,
297,
272,
283,
1282,
63,
29189,
6408,
297,
272,
283,
1282,
63,
5640,
1187,
297,
272,
283,
1282,
63,
1505,
2392,
5640,
1187,
11770,
297,
272,
283,
1282,
63,
16969,
90,
63,
3658,
297,
272,
283,
1282,
63,
51,
12106,
2204,
297,
272,
283,
1282,
63,
2090,
7608,
53,
297,
272,
283,
1282,
63,
1262,
1225,
938,
297,
272,
283,
1282,
63,
30839,
1766,
615,
297,
272,
283,
1282,
63,
8205,
3658,
297,
272,
283,
1282,
63,
16065,
297,
272,
283,
1282,
63,
6530,
26015,
1754,
297,
272,
283,
1282,
63,
15039,
47,
4556,
297,
272,
283,
1282,
63,
7847,
1966,
317,
297,
272,
283,
1282,
63,
3810,
7079,
297,
272,
283,
1282,
63,
26689,
1017,
1209,
297,
272,
283,
1282,
63,
39,
24210,
529,
297,
272,
283,
1282,
63,
50,
5708,
297,
272,
283,
1348,
63,
5058,
803,
281,
297,
272,
283,
1348,
63,
38,
4894,
297,
272,
283,
1348,
63,
33,
1647,
554,
297,
272,
283,
1282,
63,
44,
460,
316,
39,
2210,
297,
272,
283,
1282,
63,
3863,
656,
16753,
1505,
2392,
297,
272,
283,
1282,
63,
1378,
609,
1892,
65,
18988,
297,
199,
61,
199,
199,
318,
664,
63,
10000,
63,
14334,
8,
1339,
2367,
63,
354,
304,
272,
372,
359,
267,
283,
1282,
45,
63,
8248,
63,
16436,
29,
1282,
45,
63,
8248,
8650,
435,
2386,
2367,
63,
354,
12,
267,
283,
8656,
26025,
26957,
435,
2386,
2367,
63,
354,
435,
32089,
267,
283,
8656,
26025,
2339,
26957,
435,
2386,
2367,
63,
354,
435,
32089,
272,
1622,
199,
199,
3203,
25517,
63,
1282,
63,
32723,
275,
359,
272,
283,
1301,
297,
272,
283,
1282,
63,
5229,
316,
297,
327,
642,
7545,
7662,
5120,
1380,
652,
365,
4346,
436,
1077,
4257,
7078,
506,
5739,
6123,
315,
199,
61,
421,
199,
318,
2771,
63,
2495,
6472,
8,
2526,
63,
765,
304,
272,
408,
272,
30684,
626,
22741,
1067,
3718,
370,
1255,
627,
6472,
10,
465,
4346,
14,
272,
408,
272,
347,
5341,
8,
277,
304,
267,
408,
267,
644,
8146,
520,
647,
26,
1532,
1705,
21500,
773,
14,
2998,
14,
2998,
14,
2526,
64,
641,
314,
1067,
1021,
267,
408,
267,
340,
440,
15453,
14,
2495,
888,
26,
288,
372,
5341,
63,
765,
8,
277,
9,
398,
327,
17534,
2599,
888,
880,
25782,
1159,
1015,
3181,
1133,
1255,
334,
460,
2793,
1133,
1284,
1536,
641,
4438,
402,
4875,
7908,
9,
267,
15453,
14,
2495,
888,
275,
756,
398,
340,
291,
14,
8759,
508,
8061,
288,
746,
20456,
14,
55,
2756,
547,
360,
1918,
2199,
365,
4875,
590,
7526,
26,
1255,
298,
21500,
7908,
2,
4020,
10916,
398,
2589,
275,
4094,
1084,
14,
2028,
1084,
342,
267,
886,
63,
888,
275,
756,
398,
862,
26,
288,
299,
275,
747,
14,
515,
14,
904,
8,
2998,
14,
548,
63,
694,
12,
6516,
14,
8677,
63,
3022,
12,
291,
14,
8759,
435,
6516,
14,
8677,
63,
12273,
9,
288,
2589,
14,
912,
8,
80,
9,
267,
871,
25139,
26,
288,
746,
20456,
14,
55,
2756,
547,
360,
1918,
2199,
365,
440,
7526,
367,
13811,
469,
16,
9160,
1255,
298,
21500,
7908,
1553,
3576,
469,
16,
93,
359,
1396,
8480,
1642,
1,
1370,
908,
8,
277,
14,
8759,
430,
398,
4650,
63,
1813,
275,
4094,
1084,
14,
2028,
1084,
342,
398,
862,
26,
288,
4650,
63,
1813,
14,
912,
8,
736,
14,
515,
14,
904,
8,
2998,
14,
2119,
63,
694,
12,
8394,
14,
26204,
430,
267,
871,
25139,
26,
288,
3835,
458,
14,
4050,
360,
2028,
4039,
314,
2199,
358,
288,
886,
63,
888,
275,
715,
267,
587,
26,
288,
340,
4650,
63,
1813,
14,
1065,
63,
694,
1137,
9470,
14,
1065,
63,
694,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,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cutils.py
|
45
|
17768
|
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsOgcUtils.
From build dir, run: ctest -R PyQgsOgcUtils -V
.. 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__ = 'René-Luc Dhont'
__date__ = '21/06/2019'
__copyright__ = 'Copyright 2019, The QGIS Project'
import qgis # NOQA switch sip api
from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtXml import QDomDocument
from qgis.core import QgsOgcUtils, QgsVectorLayer, QgsField
from qgis.testing import start_app, unittest
start_app()
class TestQgsOgcUtils(unittest.TestCase):
def test_expressionFromOgcFilterWithInt(self):
"""
Test expressionFromOgcFilter with Int type field
"""
vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.Int)])
vl.updateFields()
# Literals are Integer 1 and 3
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.0 and 3.0
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.5 and 3.5
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.5</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.5</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 2 AND id < 4')
# Literals are Scientific notation 15e-01 and 35e-01
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>15e-01</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>35e-01</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 2 AND id < 4')
def test_expressionFromOgcFilterWithLonglong(self):
"""
Test expressionFromOgcFilter with LongLong type field
"""
vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.LongLong)])
vl.updateFields()
# Literals are Integer 1 and 3
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.0 and 3.0
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.5 and 3.5
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.5</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.5</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 2 AND id < 4')
# Literals are Scientific notation 15e-01 and 35e-01
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>15e-01</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>35e-01</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 2 AND id < 4')
def test_expressionFromOgcFilterWithDouble(self):
"""
Test expressionFromOgcFilter with Double type field
"""
vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.Double)])
vl.updateFields()
# Literals are Integer 1 and 3
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.0 and 3.0
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1 AND id < 3')
# Literals are Double 1.5 and 3.5
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.5</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.5</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1.5 AND id < 3.5')
# Literals are Scientific notation 15e-01 and 35e-01
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>15e-01</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>35e-01</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > 1.5 AND id < 3.5')
def test_expressionFromOgcFilterWithString(self):
"""
Test expressionFromOgcFilter with String type field
"""
vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.String)])
vl.updateFields()
# Literals are Integer 1 and 3
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > \'1\' AND id < \'3\'')
# Literals are Double 1.0 and 3.0
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.0</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.0</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > \'1.0\' AND id < \'3.0\'')
# Literals are Double 1.5 and 3.5
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>1.5</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>3.5</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > \'1.5\' AND id < \'3.5\'')
# Literals are Scientific notation 15e-01 and 35e-01
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsGreaterThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>15e-01</ogc:Literal>
</ogc:PropertyIsGreaterThan>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>id</ogc:PropertyName>
<ogc:Literal>35e-01</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'id > \'15e-01\' AND id < \'35e-01\'')
def test_expressionFromOgcFilterWithAndOrPropertyIsLike(self):
"""
Test expressionFromOgcFilter with And, Or and PropertyIsLike with wildCard
"""
vl = QgsVectorLayer('Point', 'vl', 'memory')
vl.dataProvider().addAttributes([QgsField('id', QVariant.LongLong), QgsField('THEME', QVariant.String), QgsField('PROGRAMME', QVariant.String)])
vl.updateFields()
f = '''<?xml version="1.0" encoding="UTF-8"?>
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsLike escape="\\" wildCard="%" singleChar="_">
<ogc:PropertyName>THEME</ogc:PropertyName>
<ogc:Literal>%Phytoplancton total%</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:Or>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>REPHY;*</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>*;REPHY</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>*;REPHY;*</ogc:Literal>
</ogc:PropertyIsLike>
<ogc:PropertyIsLike escapeChar="\\" matchCase="false" singleChar="?" wildCard="*">
<ogc:PropertyName>PROGRAMME</ogc:PropertyName>
<ogc:Literal>^REPHY$</ogc:Literal>
</ogc:PropertyIsLike>
</ogc:Or>
</ogc:And>
</ogc:Filter>
'''
d = QDomDocument('filter')
d.setContent(f, True)
e = QgsOgcUtils.expressionFromOgcFilter(d.documentElement(), vl)
self.assertEqual(e.expression(), 'THEME LIKE \'%Phytoplancton total%\' AND (PROGRAMME ILIKE \'REPHY;%\' OR PROGRAMME ILIKE \'%;REPHY\' OR PROGRAMME ILIKE \'%;REPHY;%\' OR PROGRAMME ILIKE \'^REPHY$\')')
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
47,
9493,
7535,
14,
199,
199,
2532,
1900,
2935,
12,
1255,
26,
286,
396,
446,
50,
1611,
7350,
47,
9493,
7535,
446,
54,
421,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
624,
199,
363,
2502,
363,
275,
283,
5349,
5741,
13,
44,
947,
577,
72,
1888,
7,
199,
363,
602,
363,
275,
283,
2025,
15,
1690,
15,
14982,
7,
199,
363,
7307,
363,
275,
283,
7384,
20312,
12,
710,
27024,
7290,
7,
199,
199,
646,
15640,
221,
327,
20432,
6258,
25342,
2986,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
199,
504,
15640,
14,
24107,
14,
4238,
8672,
492,
1413,
20106,
5564,
199,
504,
15640,
14,
1018,
492,
4888,
47,
9493,
7535,
12,
22507,
12,
4888,
792,
199,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
199,
928,
63,
571,
342,
421,
199,
533,
1379,
7350,
47,
9493,
7535,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
5599,
2532,
47,
9493,
4131,
3007,
3241,
8,
277,
304,
267,
408,
267,
1379,
3965,
2532,
47,
9493,
4131,
543,
9805,
730,
901,
267,
408,
267,
17876,
275,
22507,
360,
3428,
297,
283,
7300,
297,
283,
4844,
358,
267,
17876,
14,
27735,
1252,
525,
5379,
779,
7350,
792,
360,
344,
297,
27875,
14,
3241,
3948,
267,
17876,
14,
873,
7304,
342,
398,
327,
491,
1661,
2551,
787,
7225,
413,
436,
650,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
413,
2401,
1305,
665,
650,
358,
398,
327,
491,
1661,
2551,
787,
22945,
413,
14,
16,
436,
650,
14,
16,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
14,
16,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
14,
16,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
413,
2401,
1305,
665,
650,
358,
398,
327,
491,
1661,
2551,
787,
22945,
413,
14,
21,
436,
650,
14,
21,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
14,
21,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
14,
21,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
499,
2401,
1305,
665,
841,
358,
398,
327,
491,
1661,
2551,
787,
16578,
23509,
15843,
4114,
69,
13,
614,
436,
8685,
69,
13,
614,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
1046,
69,
13,
614,
1108,
29238
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
31329,
12008,
2295,
367,
4888,
47,
9493,
7535,
14,
199,
199,
2532,
1900,
2935,
12,
1255,
26,
286,
396,
446,
50,
1611,
7350,
47,
9493,
7535,
446,
54,
421,
199,
703,
5317,
447,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
624,
199,
363,
2502,
363,
275,
283,
5349,
5741,
13,
44,
947,
577,
72,
1888,
7,
199,
363,
602,
363,
275,
283,
2025,
15,
1690,
15,
14982,
7,
199,
363,
7307,
363,
275,
283,
7384,
20312,
12,
710,
27024,
7290,
7,
199,
199,
646,
15640,
221,
327,
20432,
6258,
25342,
2986,
199,
199,
504,
15640,
14,
24107,
14,
10901,
492,
27875,
199,
504,
15640,
14,
24107,
14,
4238,
8672,
492,
1413,
20106,
5564,
199,
504,
15640,
14,
1018,
492,
4888,
47,
9493,
7535,
12,
22507,
12,
4888,
792,
199,
199,
504,
15640,
14,
4776,
492,
1343,
63,
571,
12,
2882,
199,
199,
928,
63,
571,
342,
421,
199,
533,
1379,
7350,
47,
9493,
7535,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
5599,
2532,
47,
9493,
4131,
3007,
3241,
8,
277,
304,
267,
408,
267,
1379,
3965,
2532,
47,
9493,
4131,
543,
9805,
730,
901,
267,
408,
267,
17876,
275,
22507,
360,
3428,
297,
283,
7300,
297,
283,
4844,
358,
267,
17876,
14,
27735,
1252,
525,
5379,
779,
7350,
792,
360,
344,
297,
27875,
14,
3241,
3948,
267,
17876,
14,
873,
7304,
342,
398,
327,
491,
1661,
2551,
787,
7225,
413,
436,
650,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
413,
2401,
1305,
665,
650,
358,
398,
327,
491,
1661,
2551,
787,
22945,
413,
14,
16,
436,
650,
14,
16,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
14,
16,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
14,
16,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
413,
2401,
1305,
665,
650,
358,
398,
327,
491,
1661,
2551,
787,
22945,
413,
14,
21,
436,
650,
14,
21,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
17,
14,
21,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
11891,
19760,
30,
355,
665,
29238,
26,
3697,
1831,
32693,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
19,
14,
21,
1108,
29238,
26,
7621,
30,
355,
3068,
29238,
26,
3697,
1831,
32693,
30,
1598,
3068,
29238,
26,
3325,
30,
288,
3068,
29238,
26,
4131,
30,
267,
1449,
267,
366,
275,
1413,
20106,
5564,
360,
1541,
358,
267,
366,
14,
28680,
8,
70,
12,
715,
9,
398,
325,
275,
4888,
47,
9493,
7535,
14,
5599,
2532,
47,
9493,
4131,
8,
68,
14,
22464,
1062,
17876,
9,
267,
291,
14,
629,
8,
69,
14,
5599,
1062,
283,
344,
690,
499,
2401,
1305,
665,
841,
358,
398,
327,
491,
1661,
2551,
787,
16578,
23509,
15843,
4114,
69,
13,
614,
436,
8685,
69,
13,
614,
267,
289,
275,
28827,
31,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
24327,
288,
665,
29238,
26,
4131,
9604,
26,
29238,
628,
1014,
921,
1544,
14,
1490,
5668,
14,
846,
15,
29238,
1743,
1598,
665,
29238,
26,
3325,
30,
355,
665,
29238,
26,
3697,
1831,
11891,
19760,
30,
2116,
665,
29238,
26,
3697,
985,
30,
344,
1108,
29238,
26,
3697,
985,
30,
2116,
665,
29238,
26,
7621,
30,
1046,
69,
13,
614,
1108,
29238,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
aurelijusb/arangodb
|
3rdParty/V8-4.3.61/third_party/python_26/Lib/test/test_future4.py
|
58
|
1513
|
from __future__ import unicode_literals
import unittest
from test import test_support
class TestFuture(unittest.TestCase):
def assertType(self, obj, typ):
self.assert_(type(obj) is typ,
"type(%r) is %r, not %r" % (obj, type(obj), typ))
def test_unicode_strings(self):
self.assertType("", unicode)
self.assertType('', unicode)
self.assertType(r"", unicode)
self.assertType(r'', unicode)
self.assertType(""" """, unicode)
self.assertType(''' ''', unicode)
self.assertType(r""" """, unicode)
self.assertType(r''' ''', unicode)
self.assertType(u"", unicode)
self.assertType(u'', unicode)
self.assertType(ur"", unicode)
self.assertType(ur'', unicode)
self.assertType(u""" """, unicode)
self.assertType(u''' ''', unicode)
self.assertType(ur""" """, unicode)
self.assertType(ur''' ''', unicode)
self.assertType(b"", str)
self.assertType(b'', str)
self.assertType(br"", str)
self.assertType(br'', str)
self.assertType(b""" """, str)
self.assertType(b''' ''', str)
self.assertType(br""" """, str)
self.assertType(br''' ''', str)
self.assertType('' '', unicode)
self.assertType('' u'', unicode)
self.assertType(u'' '', unicode)
self.assertType(u'' u'', unicode)
def test_main():
test_support.run_unittest(TestFuture)
if __name__ == "__main__":
test_main()
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
1379,
14224,
8,
2796,
14,
1746,
304,
272,
347,
702,
804,
8,
277,
12,
1559,
12,
6211,
304,
267,
291,
14,
479,
2531,
466,
8,
1113,
9,
365,
6211,
12,
288,
298,
466,
4042,
82,
9,
365,
450,
82,
12,
440,
450,
82,
2,
450,
334,
1113,
12,
730,
8,
1113,
395,
6211,
430,
339,
347,
511,
63,
2975,
63,
5465,
8,
277,
304,
267,
291,
14,
479,
804,
12398,
2649,
9,
267,
291,
14,
479,
804,
8594,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
6448,
2649,
9,
267,
291,
14,
479,
804,
4852,
10327,
2649,
9,
267,
291,
14,
479,
804,
10505,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
2344,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
2344,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
2344,
21281,
2649,
9,
398,
291,
14,
479,
804,
8,
66,
5151,
620,
9,
267,
291,
14,
479,
804,
8,
66,
6448,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
5151,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
6448,
620,
9,
267,
291,
14,
479,
804,
8,
66,
624,
10327,
620,
9,
267,
291,
14,
479,
804,
8,
66,
2344,
21281,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
624,
10327,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
2344,
21281,
620,
9,
398,
291,
14,
479,
804,
360,
7,
3260,
2649,
9,
267,
291,
14,
479,
804,
360,
7,
399,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
891,
3260,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
891,
399,
6448,
2649,
9,
199,
199,
318,
511,
63,
973,
837,
272,
511,
63,
4058,
14,
1065,
63,
2796,
8,
774,
14224,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2882,
199,
504,
511,
492,
511,
63,
4058,
199,
199,
533,
1379,
14224,
8,
2796,
14,
1746,
304,
272,
347,
702,
804,
8,
277,
12,
1559,
12,
6211,
304,
267,
291,
14,
479,
2531,
466,
8,
1113,
9,
365,
6211,
12,
288,
298,
466,
4042,
82,
9,
365,
450,
82,
12,
440,
450,
82,
2,
450,
334,
1113,
12,
730,
8,
1113,
395,
6211,
430,
339,
347,
511,
63,
2975,
63,
5465,
8,
277,
304,
267,
291,
14,
479,
804,
12398,
2649,
9,
267,
291,
14,
479,
804,
8594,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
6448,
2649,
9,
267,
291,
14,
479,
804,
4852,
10327,
2649,
9,
267,
291,
14,
479,
804,
10505,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
82,
2344,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
5151,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
2344,
21281,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
624,
10327,
2649,
9,
267,
291,
14,
479,
804,
8,
300,
2344,
21281,
2649,
9,
398,
291,
14,
479,
804,
8,
66,
5151,
620,
9,
267,
291,
14,
479,
804,
8,
66,
6448,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
5151,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
6448,
620,
9,
267,
291,
14,
479,
804,
8,
66,
624,
10327,
620,
9,
267,
291,
14,
479,
804,
8,
66,
2344,
21281,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
624,
10327,
620,
9,
267,
291,
14,
479,
804,
8,
3289,
2344,
21281,
620,
9,
398,
291,
14,
479,
804,
360,
7,
3260,
2649,
9,
267,
291,
14,
479,
804,
360,
7,
399,
6448,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
891,
3260,
2649,
9,
267,
291,
14,
479,
804,
8,
85,
891,
399,
6448,
2649,
9,
199,
199,
318,
511,
63,
973,
837,
272,
511,
63,
4058,
14,
1065,
63,
2796,
8,
774,
14224,
9,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
511,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
usc-isi/horizon-old
|
horizon/horizon/dashboards/settings/user/urls.py
|
1
|
1066
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2011 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.conf.urls.defaults import patterns, url
from django.views.generic import TemplateView
urlpatterns = patterns('',
url(r'^$', TemplateView.as_view(
template_name='settings/user/settings.html'),
name='index'))
|
apache-2.0
|
[
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
7760,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
2190,
14,
3603,
14,
4322,
492,
7970,
12,
1166,
199,
504,
1639,
14,
4196,
14,
6767,
492,
5458,
2768,
421,
199,
20050,
275,
7970,
8594,
272,
1166,
8,
82,
4289,
4268,
5458,
2768,
14,
305,
63,
1345,
8,
355,
1978,
63,
354,
534,
1751,
15,
751,
15,
1751,
14,
1360,
659,
355,
536,
534,
1080,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
1898,
7760,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
1898,
7760,
653,
2871,
7586,
12,
3277,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
2190,
14,
3603,
14,
4322,
492,
7970,
12,
1166,
199,
504,
1639,
14,
4196,
14,
6767,
492,
5458,
2768,
421,
199,
20050,
275,
7970,
8594,
272,
1166,
8,
82,
4289,
4268,
5458,
2768,
14,
305,
63,
1345,
8,
355,
1978,
63,
354,
534,
1751,
15,
751,
15,
1751,
14,
1360,
659,
355,
536,
534,
1080,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
ammarkhann/FinalSeniorCode
|
lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_svg2pdf.py
|
11
|
2336
|
"""Tests for the svg2pdf preprocessor"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
from ipython_genutils.testing import decorators as dec
from nbformat import v4 as nbformat
from .base import PreprocessorTestsBase
from ..svg2pdf import SVG2PDFPreprocessor
class Testsvg2pdf(PreprocessorTestsBase):
"""Contains test functions for svg2pdf.py"""
simple_svg = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.0"
x="0.00000000"
y="0.00000000"
width="500.00000"
height="500.00000"
id="svg2">
<defs
id="defs4" />
<g
id="layer1">
<rect
width="300.00000"
height="300.00000"
x="100.00000"
y="100.00000"
style="opacity:1.0000000;fill:none;fill-opacity:1.0000000;fill-rule:evenodd;stroke:#000000;stroke-width:8.0000000;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-dasharray:none;stroke-dashoffset:0.00000000;stroke-opacity:1.0000000"
id="rect5719" />
</g>
</svg>"""
def build_notebook(self):
"""Build a reveal slides notebook in memory for use with tests.
Overrides base in PreprocessorTestsBase"""
outputs = [nbformat.new_output(output_type='display_data',
data={'image/svg+xml':self.simple_svg})
]
cells=[nbformat.new_code_cell(source="", execution_count=1, outputs=outputs)]
return nbformat.new_notebook(cells=cells)
def build_preprocessor(self):
"""Make an instance of a preprocessor"""
preprocessor = SVG2PDFPreprocessor()
preprocessor.enabled = True
return preprocessor
def test_constructor(self):
"""Can a SVG2PDFPreprocessor be constructed?"""
self.build_preprocessor()
@dec.onlyif_cmds_exist('inkscape')
def test_output(self):
"""Test the output of the SVG2PDFPreprocessor"""
nb = self.build_notebook()
res = self.build_resources()
preprocessor = self.build_preprocessor()
nb, res = preprocessor(nb, res)
self.assertIn('application/pdf', nb.cells[0].outputs[0].data)
|
mit
|
[
624,
2925,
367,
314,
21218,
18,
5607,
22335,
624,
199,
199,
3,
1898,
334,
67,
9,
16243,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
504,
284,
1548,
63,
2268,
1208,
14,
4776,
492,
20419,
465,
9700,
199,
504,
8526,
908,
492,
373,
20,
465,
8526,
908,
199,
199,
504,
1275,
1095,
492,
5543,
6459,
2925,
1563,
199,
504,
2508,
10273,
18,
5607,
492,
32062,
18,
7638,
16482,
421,
199,
533,
1379,
10273,
18,
5607,
8,
16482,
2925,
1563,
304,
272,
408,
6906,
511,
3423,
367,
21218,
18,
5607,
14,
647,
624,
339,
3486,
63,
10273,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
2,
18042,
628,
889,
24327,
199,
25273,
18208,
543,
1010,
75,
3588,
334,
1014,
921,
1544,
14,
2292,
3588,
14,
1308,
24793,
10541,
199,
28,
10273,
2043,
9604,
26,
10273,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
2,
2043,
9604,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
2,
2043,
1015,
628,
17,
14,
16,
2,
2043,
671,
628,
16,
14,
3607,
2,
2043,
612,
628,
16,
14,
3607,
2,
2043,
3462,
628,
5783,
14,
5345,
2,
2043,
4569,
628,
5783,
14,
5345,
2,
2043,
1305,
628,
10273,
18,
1743,
523,
665,
8710,
1362,
1305,
628,
8710,
20,
2,
7082,
523,
665,
71,
1362,
1305,
628,
1897,
17,
1743,
272,
665,
1201,
2126,
3462,
628,
5863,
14,
5345,
2,
2126,
4569,
628,
5863,
14,
5345,
2,
2126,
671,
628,
1960,
14,
5345,
2,
2126,
612,
628,
1960,
14,
5345,
2,
2126,
3449,
628,
21861,
26,
17,
14,
9084,
27,
4498,
26,
3592,
27,
4498,
13,
21861,
26,
17,
14,
9084,
27,
4498,
13,
2200,
26,
12056,
16216,
27,
11473,
15596,
3273,
27,
11473,
13,
2063,
26,
24,
14,
9084,
27,
11473,
13,
604,
2874,
26,
2363,
27,
11473,
13,
604,
904,
26,
2363,
27,
11473,
13,
77,
1661,
3097,
26,
20,
14,
9084,
27,
11473,
13,
6760,
1144,
26,
3592,
27,
11473,
13,
24315,
526,
12449,
26,
16,
14,
3607,
27,
11473,
13,
21861,
26,
17,
14,
9084,
2,
2126,
1305,
628,
1201,
1641,
1167,
2,
7082,
523,
3068,
71,
30,
199,
1108,
10273,
11193,
339,
347,
1900,
63,
19174,
8,
277,
304,
267,
408,
3425,
282,
295,
432,
279,
27498,
3424,
20751,
315,
4402,
367,
675,
543,
2295,
14,
267,
31144,
1300,
315,
5543,
6459,
2925,
1563,
624,
398,
4704,
275,
359,
4994,
908,
14,
1222,
63,
1199,
8,
1199,
63,
466,
534,
2918,
63,
576,
297,
4318,
666,
3713,
1569,
15,
10273,
11,
1652,
356,
277,
14,
4129,
63,
10273,
1552,
2116,
1622,
398,
10106,
1524,
4994,
908,
14,
1222,
63,
600,
63,
3890,
8,
1365,
8772,
6451,
63,
835,
29,
17,
12,
4704,
29,
4467,
1874,
398,
372,
8526,
908,
14,
1222,
63,
19174,
8,
9041,
29,
9041,
9,
2378,
347,
1900,
63,
657,
6459,
8,
277,
304,
267,
408,
5483,
376,
1256,
402,
282,
22335,
624,
267,
22335,
275,
32062,
18,
7638,
16482,
342,
267,
22335,
14,
3827,
275,
715,
267,
372,
22335,
2378,
347,
511,
63,
1880,
8,
277,
304,
267,
408,
6049,
282,
32062,
18,
7638,
16482,
506,
14701,
30196,
267,
291,
14,
1506,
63,
657,
6459,
342,
2378,
768,
7778,
14,
2118,
692,
63,
12975,
63,
4494,
360,
2292,
3588,
358,
272,
347,
511,
63,
1199,
8,
277,
304,
267,
408,
774,
314,
1072,
402,
314,
32062,
18,
7638,
16482,
624,
267,
8526,
275,
291,
14,
1506,
63,
19174,
342,
267,
522,
275,
291,
14,
1506,
63,
4435,
342,
267,
22335,
275,
291,
14,
1506,
63,
657,
6459,
342,
267,
8526,
12,
522,
275,
22335,
8,
4994,
12,
522,
9,
267,
291,
14,
4080,
360,
3578,
15,
5607,
297,
8526,
14,
9041,
59,
16,
1055,
4467,
59,
16,
1055,
576,
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
] |
[
2925,
367,
314,
21218,
18,
5607,
22335,
624,
199,
199,
3,
1898,
334,
67,
9,
16243,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
504,
284,
1548,
63,
2268,
1208,
14,
4776,
492,
20419,
465,
9700,
199,
504,
8526,
908,
492,
373,
20,
465,
8526,
908,
199,
199,
504,
1275,
1095,
492,
5543,
6459,
2925,
1563,
199,
504,
2508,
10273,
18,
5607,
492,
32062,
18,
7638,
16482,
421,
199,
533,
1379,
10273,
18,
5607,
8,
16482,
2925,
1563,
304,
272,
408,
6906,
511,
3423,
367,
21218,
18,
5607,
14,
647,
624,
339,
3486,
63,
10273,
275,
31501,
1652,
1015,
628,
17,
14,
16,
2,
2644,
628,
6610,
13,
24,
2,
18042,
628,
889,
24327,
199,
25273,
18208,
543,
1010,
75,
3588,
334,
1014,
921,
1544,
14,
2292,
3588,
14,
1308,
24793,
10541,
199,
28,
10273,
2043,
9604,
26,
10273,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
2,
2043,
9604,
628,
1014,
921,
1544,
14,
87,
19,
14,
1308,
15,
8269,
15,
10273,
2,
2043,
1015,
628,
17,
14,
16,
2,
2043,
671,
628,
16,
14,
3607,
2,
2043,
612,
628,
16,
14,
3607,
2,
2043,
3462,
628,
5783,
14,
5345,
2,
2043,
4569,
628,
5783,
14,
5345,
2,
2043,
1305,
628,
10273,
18,
1743,
523,
665,
8710,
1362,
1305,
628,
8710,
20,
2,
7082,
523,
665,
71,
1362,
1305,
628,
1897,
17,
1743,
272,
665,
1201,
2126,
3462,
628,
5863,
14,
5345,
2,
2126,
4569,
628,
5863,
14,
5345,
2,
2126,
671,
628,
1960,
14,
5345,
2,
2126,
612,
628,
1960,
14,
5345,
2,
2126,
3449,
628,
21861,
26,
17,
14,
9084,
27,
4498,
26,
3592,
27,
4498,
13,
21861,
26,
17,
14,
9084,
27,
4498,
13,
2200,
26,
12056,
16216,
27,
11473,
15596,
3273,
27,
11473,
13,
2063,
26,
24,
14,
9084,
27,
11473,
13,
604,
2874,
26,
2363,
27,
11473,
13,
604,
904,
26,
2363,
27,
11473,
13,
77,
1661,
3097,
26,
20,
14,
9084,
27,
11473,
13,
6760,
1144,
26,
3592,
27,
11473,
13,
24315,
526,
12449,
26,
16,
14,
3607,
27,
11473,
13,
21861,
26,
17,
14,
9084,
2,
2126,
1305,
628,
1201,
1641,
1167,
2,
7082,
523,
3068,
71,
30,
199,
1108,
10273,
11193,
339,
347,
1900,
63,
19174,
8,
277,
304,
267,
408,
3425,
282,
295,
432,
279,
27498,
3424,
20751,
315,
4402,
367,
675,
543,
2295,
14,
267,
31144,
1300,
315,
5543,
6459,
2925,
1563,
624,
398,
4704,
275,
359,
4994,
908,
14,
1222,
63,
1199,
8,
1199,
63,
466,
534,
2918,
63,
576,
297,
4318,
666,
3713,
1569,
15,
10273,
11,
1652,
356,
277,
14,
4129,
63,
10273,
1552,
2116,
1622,
398,
10106,
1524,
4994,
908,
14,
1222,
63,
600,
63,
3890,
8,
1365,
8772,
6451,
63,
835,
29,
17,
12,
4704,
29,
4467,
1874,
398,
372,
8526,
908,
14,
1222,
63,
19174,
8,
9041,
29,
9041,
9,
2378,
347,
1900,
63,
657,
6459,
8,
277,
304,
267,
408,
5483,
376,
1256,
402,
282,
22335,
624,
267,
22335,
275,
32062,
18,
7638,
16482,
342,
267,
22335,
14,
3827,
275,
715,
267,
372,
22335,
2378,
347,
511,
63,
1880,
8,
277,
304,
267,
408,
6049,
282,
32062,
18,
7638,
16482,
506,
14701,
30196,
267,
291,
14,
1506,
63,
657,
6459,
342,
2378,
768,
7778,
14,
2118,
692,
63,
12975,
63,
4494,
360,
2292,
3588,
358,
272,
347,
511,
63,
1199,
8,
277,
304,
267,
408,
774,
314,
1072,
402,
314,
32062,
18,
7638,
16482,
624,
267,
8526,
275,
291,
14,
1506,
63,
19174,
342,
267,
522,
275,
291,
14,
1506,
63,
4435,
342,
267,
22335,
275,
291,
14,
1506,
63,
657,
6459,
342,
267,
8526,
12,
522,
275,
22335,
8,
4994,
12,
522,
9,
267,
291,
14,
4080,
360,
3578,
15,
5607,
297,
8526,
14,
9041,
59,
16,
1055,
4467,
59,
16,
1055,
576,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hifly/Pentaho-reports-for-OpenERP
|
openerp_addon/pentaho_reports/ui.py
|
7
|
18357
|
# -*- encoding: utf-8 -*-
import os
import base64
from openerp.tools.safe_eval import safe_eval
from openerp import models, fields, api, _
from openerp.exceptions import except_orm
from openerp.tools import config
from openerp import SUPERUSER_ID
import core
from java_oe import JAVA_MAPPING, check_java_list, PARAM_VALUES
ADDONS_PATHS = config['addons_path'].split(",")
class report_xml(models.Model):
_inherit = 'ir.actions.report.xml'
report_type = fields.Selection(selection_add=[('pentaho','Pentaho Report')])
pentaho_report_output_type = fields.Selection([("pdf", "PDF"), ("html", "HTML"), ("csv", "CSV"), ("xls", "Excel"), ("xlsx", "Excel 2007"), ("rtf", "RTF"), ("txt", "Plain text")],
string = 'Output format')
pentaho_report_model_id = fields.Many2one('ir.model', string='Model')
pentaho_file = fields.Binary(string='File', filters='*.prpt')
pentaho_filename = fields.Char(string='Filename', size=256, required=False)
# 'is_pentaho_report': fields.boolean('Is this a Pentaho report?'),
linked_menu_id = fields.Many2one('ir.ui.menu', string='Linked menu item', select=True)
created_menu_id = fields.Many2one('ir.ui.menu', string='Created menu item')
# This is not displayed on the client - it is a trigger to indicate that
# a prpt file needs to be loaded - normally it is loaded by the client interface
# In this case, the filename should be specified with a module path.
pentaho_load_file = fields.Boolean(string='Load prpt file from filename')
@api.onchange('report_type')
def _onchange_report_type(self):
if self.report_type == 'pentaho':
self.auto = False
self.pentaho_report_output_type = 'pdf'
if self.model:
if not self.pentaho_report_model_id or self.pentaho_report_model_id.model != self.model:
self.pentaho_report_model_id = self.env['ir.model'].search([('model', '=', self.model)])[0]
else:
if self.pentaho_report_model_id:
self.model = self.pentaho_report_model_id.model
@api.onchange('pentaho_report_model_id')
def _onchange_model_id(self):
if self.pentaho_report_model_id:
self.model = self.pentaho_report_model_id.model
else:
self.model = False
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
if context is None:
context = {}
default = default.copy()
default.update({'created_menu_id': 0})
return super(report_xml, self).copy(cr, uid, id, default, context=context)
def create_menu(self, cr, uid, vals, context=None):
view_ids = self.pool.get('ir.ui.view').search(cr, uid, [('model', '=', 'ir.actions.report.promptwizard'), ('type', '=', 'form')], context=context)
action_vals = {'name': vals.get('name', 'Pentaho Report'),
'res_model': 'ir.actions.report.promptwizard',
'type' : 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'tree,form',
'view_id' : view_ids and view_ids[0] or 0,
'context' : "{'service_name': '%s'}" % vals.get('report_name', ''),
'target' : 'new',
}
action_id = self.pool.get('ir.actions.act_window').create(cr, uid, action_vals, context=context)
result = self.pool.get('ir.ui.menu').create(cr, SUPERUSER_ID, {
'name': vals.get('name' ,'Pentaho Report'),
'sequence': 10,
'parent_id': vals['linked_menu_id'],
'groups_id': vals.get('groups_id', []),
'icon': 'STOCK_PRINT',
'action': 'ir.actions.act_window,%d' % (action_id,),
}, context=context)
return result
def delete_menu(self, cr, uid, menu_id, context=None):
action = self.pool.get('ir.ui.menu').browse(cr, uid, menu_id, context=context).action
if action and action._model._name == 'ir.actions.act_window':
self.pool.get('ir.actions.act_window').unlink(cr, uid, [action.id], context=context)
result = self.pool.get('ir.ui.menu').unlink(cr, SUPERUSER_ID, [menu_id], context=context)
return result
def update_menu(self, cr, uid, action_report, context=None):
if action_report.created_menu_id and not action_report.linked_menu_id:
self.delete_menu(cr, uid, action_report.created_menu_id.id, context=context)
if action_report.report_type == 'pentaho' and action_report.linked_menu_id:
groups_id = [(6, 0, map(lambda x: x.id, action_report.groups_id))]
if not action_report.created_menu_id:
result = self.create_menu(cr, uid, {'name': action_report.name,
'linked_menu_id': action_report.linked_menu_id.id,
'report_name': action_report.report_name,
'groups_id': groups_id,
}, context=context)
else:
action = action_report.created_menu_id.action
if action and action._model._name == 'ir.actions.act_window':
existing_context = safe_eval(self.pool.get('ir.actions.act_window').browse(cr, uid, action.id, context=context).context)
new_context = existing_context if type(existing_context) == dict else {}
new_context['service_name'] = action_report.report_name or ''
self.pool.get('ir.actions.act_window').write(cr, uid, [action.id], {'name': action_report.name or 'Pentaho Report',
'context': str(new_context),
}, context=context)
self.pool.get('ir.ui.menu').write(cr, SUPERUSER_ID, [action_report.created_menu_id.id], {'name': action_report.name or 'Pentaho Report',
'parent_id': action_report.linked_menu_id.id,
'groups_id': groups_id,
}, context=context)
result = action_report.created_menu_id.id
else:
result = 0
return result
def create(self, cr, uid, vals, context = None):
if vals.get('report_type','') == 'pentaho':
vals.update({
'auto': False,
})
if vals.get('linked_menu_id', False):
vals['created_menu_id'] = self.create_menu(cr, uid, vals, context=context)
res = super(report_xml, self).create(cr, uid, vals, context=context)
self.update_pentaho(cr, uid, [res], context=context)
return res
def write(self, cr, uid, ids, vals, context = None):
if vals.get('report_type','') == 'pentaho':
vals.update({
'type': 'ir.actions.report.xml',
'auto': False,
})
res = super(report_xml, self).write(cr, uid, ids, vals, context=context)
for r in self.browse(cr, uid, ids if isinstance(ids, list) else [ids], context=context):
created_menu_id = self.update_menu(cr, uid, r, context=context)
if created_menu_id != r.created_menu_id:
super(report_xml, self).write(cr, uid, [r.id], {'created_menu_id': created_menu_id}, context=context)
self.update_pentaho(cr, uid, ids if isinstance(ids, list) else [ids], context=context)
return res
def unlink(self, cr, uid, ids, context=None):
values_obj = self.pool.get('ir.values')
for r in self.browse(cr, uid, ids, context=context):
if r.created_menu_id:
self.delete_menu(cr, uid, r.created_menu_id.id, context=context)
values_obj.unlink(cr, SUPERUSER_ID, values_obj.search(cr, uid, [('value', '=', 'ir.actions.report.xml,%s' % r.id)]), context=context)
return super(report_xml, self).unlink(cr, uid, ids, context=context)
def update_pentaho(self, cr, uid, ids, context = None):
values_obj = self.pool.get('ir.values')
for report in self.browse(cr, uid, ids):
values_ids = values_obj.search(cr, uid, [('value', '=', 'ir.actions.report.xml,%s' % report.id)])
if report.report_type == 'pentaho':
if report.pentaho_filename:
if report.pentaho_load_file:
# if we receive a filename and no content, this has probably been loaded by a process other than the standard client, such as a data import
# in this case, we expect the filename to be a fully specified file within a module from which we load the file data
super(report_xml, self).write(cr, uid, [report.id], {'pentaho_filename': os.path.basename(report.pentaho_filename),
'pentaho_file': self.read_content_from_file(report.pentaho_filename),
'pentaho_load_file': False
})
report = self.browse(cr, uid, report.id)
# path = self.save_content_to_file(report.pentaho_filename, report.pentaho_file)
# super(report_xml, self).write(cr, uid, [report.id], {'report_rml': path})
# we are no longer relying on report_rml to contain a name at all - for clarity, though, still store it...
super(report_xml, self).write(cr, uid, [report.id], {'report_rml': report.pentaho_filename})
if not report.linked_menu_id and report.pentaho_filename.endswith('.prpt'):
data = {
'name': report.name,
'model': report.model,
'key': 'action',
'object': True,
'key2': 'client_print_multi',
'value': 'ir.actions.report.xml,%s' % report.id,
}
if not values_ids:
values_obj.create(cr, SUPERUSER_ID, data, context=context)
else:
values_obj.write(cr, SUPERUSER_ID, values_ids, data, context=context)
values_ids = []
# core.register_pentaho_report(report.report_name)
elif report.pentaho_file:
super(report_xml, self).write(cr, uid, [report.id], {'pentaho_file': False})
# If this is a pentaho report and there are still "values_ids", it means that
# the action is not considered valid - get rid of the values_ids...
if values_ids:
values_obj.unlink(cr, SUPERUSER_ID, values_ids, context=context)
# If this is not a pentaho report, then the action should always have a row in values
else:
if not values_ids:
values_obj.create(cr, SUPERUSER_ID, {
'name': report.name,
'model': report.model,
'key': 'action',
'object': True,
'key2': 'client_print_multi',
'value': 'ir.actions.report.xml,%s' % report.id,
},
context = context)
return True
def read_content_from_file(self, name):
path_found = False
for addons_path in ADDONS_PATHS:
try:
os.stat(addons_path + os.sep + name)
path_found = True
break
except:
pass
if not path_found:
raise except_orm(_('Error'), _('Could not locate path for file %s') % name)
path = addons_path + os.sep + name
with open(path, "rb") as report_file:
data = base64.encodestring(report_file.read())
return data
def pentaho_validate_params(self, cr, uid, report, param_vals, context=None):
"""Validate a list of passed parameters against the defined params for
a Pentaho report.
Raises an exception if any of the params are invalid.
@param report: Browse object on the ir.actions.report.xml record for the report.
@param param_vals: Dict with parameter values to pass to the report. These are python
data types prior to conversion for passing to the Pentaho server.
"""
param_defs = core.fetch_report_parameters(cr, uid, report.report_name, context=context)
val_names = param_vals.keys()
for pdef in param_defs:
pname = pdef.get('name', '')
if not pname:
continue
if pname in val_names:
val_names.remove(pname)
else:
if pdef.get('default_value', False):
if type(pdef['default_value']) in (list, tuple):
param_vals[pname] = pdef['default_value'][0]
else:
param_vals[pname] = pdef['default_value']
else:
if pdef.get('is_mandatory', False):
raise except_orm(_('Error'), _("Report '%s'. No value passed for mandatory report parameter '%s'.") % (report.report_name, pname))
continue
# Make sure data types match
value_type = pdef.get('value_type', '')
java_list, value_type = check_java_list(value_type)
if not value_type in JAVA_MAPPING:
raise except_orm(_('Error'), _("Report '%s', parameter '%s'. Type '%s' not supported.") % (report.report_name, pname, pdef.get('value_type', '')))
local_type = JAVA_MAPPING[value_type](pdef.get('attributes', {}).get('data-format', False))
param_val = param_vals[pname]
if not local_type in PARAM_VALUES:
raise except_orm(_('Error'), _("Report '%s', parameter '%s'. Local type '%s' not supported.") % (report.report_name, pname, local_type))
if not isinstance(param_val, PARAM_VALUES[local_type]['py_types']):
raise except_orm(_('Error'), _("Report '%s', parameter '%s'. Passed value is '%s' but must be one of '%s'.") % (report.report_name, pname, param_val.__class__.__name__, PARAM_VALUES[local_type]['py_types']))
converter = PARAM_VALUES[local_type].get('convert')
if converter:
try:
converter(param_val)
except Exception, e:
raise except_orm(_('Error'), _("Report '%s', parameter '%s'. Passed value '%s' failed data conversion to type '%s'.\n%s") % (report.report_name, pname, param_val, local_type, str(e)))
# Make sure all passed values have a param to go to on the report.
# This wouldn't raise an error on the Pentaho side but flagging it here
# might save a lot of development time if a param is misnamed.
if val_names:
raise except_orm(_('Error'), _("Report '%s'. Parameter values not required by report: %s") % (report.report_name, val_names))
def pentaho_report_action(self, cr, uid, service_name, active_ids=None, param_values=None, context=None):
"""Return the action definition to run a Pentaho report.
The action definition is returned as a dict which can be returned
to the OpenERP client from a wizard button or server action to
cause the client to request the report.
@param service_name: The report service name (without leading 'report.').
@param active_ids: List of ids on the report model to pass.
@param param_values: Dict with parameter values for the report.
The keys are the parameter names as defined by the Pentaho report.
"""
report = False
report_ids = self.search(cr, uid, [('report_name', '=', service_name)], context=context)
if report_ids:
report = self.browse(cr, uid, report_ids[0], context=context)
if not report or report.report_type != 'pentaho':
raise except_orm(_('Error'), _("Report '%s' is not a Pentaho report.") % service_name)
if not active_ids and not param_values:
raise except_orm(_('Error'), _("Report '%s' must be passed active ids or parameter values.") % service_name)
datas = {'model': report.model,
'report_type': report.report_type,
}
if active_ids:
datas['ids'] = active_ids
if param_values:
self.pentaho_validate_params(cr, uid, report, param_values, context=context)
datas['variables'] = param_values
return {
'type': 'ir.actions.report.xml',
'report_name': report.report_name,
'datas': datas,
}
|
gpl-2.0
|
[
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
1300,
772,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
504,
5166,
14,
3924,
492,
871,
63,
1025,
199,
504,
5166,
14,
2537,
492,
1101,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
199,
646,
6170,
199,
199,
504,
12120,
63,
13361,
492,
1603,
28520,
63,
20351,
12,
1104,
63,
6138,
63,
513,
12,
16565,
63,
15514,
199,
199,
9732,
23300,
63,
20202,
275,
1101,
459,
10788,
63,
515,
2278,
1294,
20324,
421,
199,
533,
3622,
63,
1652,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
723,
14,
3723,
14,
3070,
14,
1652,
7,
339,
3622,
63,
466,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
80,
21335,
526,
1673,
48,
21335,
526,
11774,
2023,
272,
299,
21335,
526,
63,
3070,
63,
1199,
63,
466,
275,
1504,
14,
7713,
27187,
5607,
401,
298,
7638,
1288,
1689,
1360,
401,
298,
4943,
1288,
1689,
4737,
401,
298,
19018,
1288,
1689,
19023,
401,
298,
920,
6067,
1288,
1689,
19023,
88,
401,
298,
920,
6067,
10219,
1288,
1689,
2591,
70,
401,
298,
50,
6145,
1288,
1689,
2424,
401,
298,
20711,
1318,
17857,
8962,
1059,
275,
283,
2959,
1475,
358,
272,
299,
21335,
526,
63,
3070,
63,
1238,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1238,
297,
1059,
534,
1685,
358,
272,
299,
21335,
526,
63,
493,
275,
1504,
14,
6636,
8,
875,
534,
1173,
297,
4766,
534,
4856,
2700,
541,
358,
272,
299,
21335,
526,
63,
1501,
275,
1504,
14,
1610,
8,
875,
534,
8117,
297,
1568,
29,
3912,
12,
1415,
29,
797,
9,
199,
3,
463,
283,
374,
63,
80,
21335,
526,
63,
3070,
356,
1504,
14,
4871,
360,
1831,
642,
282,
510,
21335,
526,
3622,
31,
659,
272,
10632,
63,
4470,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1907,
14,
4470,
297,
1059,
534,
26748,
6269,
1242,
297,
3504,
29,
549,
9,
272,
2737,
63,
4470,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1907,
14,
4470,
297,
1059,
534,
10502,
6269,
1242,
358,
272,
327,
961,
365,
440,
9080,
641,
314,
1890,
446,
652,
365,
282,
6804,
370,
6623,
626,
272,
327,
282,
5448,
541,
570,
4839,
370,
506,
6511,
446,
12252,
652,
365,
6511,
701,
314,
1890,
3217,
272,
327,
1010,
642,
1930,
12,
314,
1788,
1077,
506,
2013,
543,
282,
859,
931,
14,
272,
299,
21335,
526,
63,
912,
63,
493,
275,
1504,
14,
4082,
8,
875,
534,
6200,
5448,
541,
570,
687,
1788,
358,
339,
768,
1246,
14,
18128,
360,
3070,
63,
466,
358,
272,
347,
485,
18128,
63,
3070,
63,
466,
8,
277,
304,
267,
340,
291,
14,
3070,
63,
466,
508,
283,
80,
21335,
526,
356,
288,
291,
14,
2495,
275,
756,
288,
291,
14,
80,
21335,
526,
63,
3070,
63,
1199,
63,
466,
275,
283,
5607,
7,
953,
340,
291,
14,
1238,
26,
355,
340,
440,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
503,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
1137,
291,
14,
1238,
26,
490,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
275,
291,
14,
1813,
459,
723,
14,
1238,
2278,
1733,
8318,
1238,
297,
6291,
291,
14,
1238,
3948,
59,
16,
61,
267,
587,
26,
288,
340,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
26,
355,
291,
14,
1238,
275,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
339,
768,
1246,
14,
18128,
360,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
358,
272,
347,
485,
18128,
63,
1238,
63,
344,
8,
277,
304,
267,
340,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
26,
288,
291,
14,
1238,
275,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
267,
587,
26,
288,
291,
14,
1238,
275,
756,
339,
347,
1331,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
849,
29,
403,
12,
1067,
29,
403,
304,
267,
340,
849,
365,
488,
26,
288,
849,
275,
1052,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
849,
275,
849,
14,
1574,
342,
267,
849,
14,
873,
3252,
3966,
63,
4470,
63,
344,
356,
378,
1552,
267,
372,
1613,
8,
3070,
63,
1652,
12,
291,
680,
1574,
8,
1556,
12,
1747,
12,
1305,
12,
849,
12,
1067,
29,
1100,
9,
339,
347,
1218,
63,
4470,
8,
277,
12,
2467,
12,
1747,
12,
5322,
12,
1067,
29,
403,
304,
267,
2455,
63,
1580,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1907,
14,
1345,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
297,
6291,
283,
723,
14,
3723,
14,
3070,
14,
7650,
9819,
659,
661,
466,
297,
6291,
283,
964,
2665,
1067,
29,
1100,
9,
398,
1595,
63,
3643,
275,
791,
354,
356,
5322,
14,
362,
360,
354,
297,
283,
48,
21335,
526,
11774,
659,
2432,
283,
470,
63,
1238,
356,
283,
723,
14,
3723,
14,
3070,
14,
7650,
9819,
297,
2432,
283,
466,
7,
520,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
2432,
283,
1345,
63,
466,
356,
283,
964,
297,
2432,
283,
1345,
63,
632,
356,
283,
2350,
12,
964,
297,
2432,
283,
1345,
63,
344,
7,
520,
2455,
63,
1580,
436,
2455,
63,
1580,
59,
16,
61,
503,
378,
12,
2432,
283,
1100,
7,
520,
298,
1445,
1364,
63,
354,
356,
1543,
83,
936,
2,
450,
5322,
14,
362,
360,
3070,
63,
354,
297,
9929,
2432,
283,
1375,
7,
520,
283,
1222,
297,
2432,
789,
267,
1595,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
1959,
981,
8,
1556,
12,
1747,
12,
1595,
63,
3643,
12,
1067,
29,
1100,
9,
398,
754,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1907,
14,
4470,
1959,
981,
8,
1556,
12,
12824,
63,
998,
12,
469,
6684,
755,
283,
354,
356,
5322,
14,
362,
360,
354,
7,
20606,
48,
21335,
526,
11774,
659,
6684,
755
] |
[
1882,
2644,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
1300,
772,
199,
504,
5166,
14,
2537,
14,
3489,
63,
2579,
492,
5048,
63,
2579,
199,
504,
5166,
492,
1709,
12,
1504,
12,
2986,
12,
485,
199,
504,
5166,
14,
3924,
492,
871,
63,
1025,
199,
504,
5166,
14,
2537,
492,
1101,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
199,
646,
6170,
199,
199,
504,
12120,
63,
13361,
492,
1603,
28520,
63,
20351,
12,
1104,
63,
6138,
63,
513,
12,
16565,
63,
15514,
199,
199,
9732,
23300,
63,
20202,
275,
1101,
459,
10788,
63,
515,
2278,
1294,
20324,
421,
199,
533,
3622,
63,
1652,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
723,
14,
3723,
14,
3070,
14,
1652,
7,
339,
3622,
63,
466,
275,
1504,
14,
7713,
8,
5592,
63,
525,
11699,
80,
21335,
526,
1673,
48,
21335,
526,
11774,
2023,
272,
299,
21335,
526,
63,
3070,
63,
1199,
63,
466,
275,
1504,
14,
7713,
27187,
5607,
401,
298,
7638,
1288,
1689,
1360,
401,
298,
4943,
1288,
1689,
4737,
401,
298,
19018,
1288,
1689,
19023,
401,
298,
920,
6067,
1288,
1689,
19023,
88,
401,
298,
920,
6067,
10219,
1288,
1689,
2591,
70,
401,
298,
50,
6145,
1288,
1689,
2424,
401,
298,
20711,
1318,
17857,
8962,
1059,
275,
283,
2959,
1475,
358,
272,
299,
21335,
526,
63,
3070,
63,
1238,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1238,
297,
1059,
534,
1685,
358,
272,
299,
21335,
526,
63,
493,
275,
1504,
14,
6636,
8,
875,
534,
1173,
297,
4766,
534,
4856,
2700,
541,
358,
272,
299,
21335,
526,
63,
1501,
275,
1504,
14,
1610,
8,
875,
534,
8117,
297,
1568,
29,
3912,
12,
1415,
29,
797,
9,
199,
3,
463,
283,
374,
63,
80,
21335,
526,
63,
3070,
356,
1504,
14,
4871,
360,
1831,
642,
282,
510,
21335,
526,
3622,
31,
659,
272,
10632,
63,
4470,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1907,
14,
4470,
297,
1059,
534,
26748,
6269,
1242,
297,
3504,
29,
549,
9,
272,
2737,
63,
4470,
63,
344,
275,
1504,
14,
4089,
18,
368,
360,
723,
14,
1907,
14,
4470,
297,
1059,
534,
10502,
6269,
1242,
358,
272,
327,
961,
365,
440,
9080,
641,
314,
1890,
446,
652,
365,
282,
6804,
370,
6623,
626,
272,
327,
282,
5448,
541,
570,
4839,
370,
506,
6511,
446,
12252,
652,
365,
6511,
701,
314,
1890,
3217,
272,
327,
1010,
642,
1930,
12,
314,
1788,
1077,
506,
2013,
543,
282,
859,
931,
14,
272,
299,
21335,
526,
63,
912,
63,
493,
275,
1504,
14,
4082,
8,
875,
534,
6200,
5448,
541,
570,
687,
1788,
358,
339,
768,
1246,
14,
18128,
360,
3070,
63,
466,
358,
272,
347,
485,
18128,
63,
3070,
63,
466,
8,
277,
304,
267,
340,
291,
14,
3070,
63,
466,
508,
283,
80,
21335,
526,
356,
288,
291,
14,
2495,
275,
756,
288,
291,
14,
80,
21335,
526,
63,
3070,
63,
1199,
63,
466,
275,
283,
5607,
7,
953,
340,
291,
14,
1238,
26,
355,
340,
440,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
503,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
1137,
291,
14,
1238,
26,
490,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
275,
291,
14,
1813,
459,
723,
14,
1238,
2278,
1733,
8318,
1238,
297,
6291,
291,
14,
1238,
3948,
59,
16,
61,
267,
587,
26,
288,
340,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
26,
355,
291,
14,
1238,
275,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
339,
768,
1246,
14,
18128,
360,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
358,
272,
347,
485,
18128,
63,
1238,
63,
344,
8,
277,
304,
267,
340,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
26,
288,
291,
14,
1238,
275,
291,
14,
80,
21335,
526,
63,
3070,
63,
1238,
63,
344,
14,
1238,
267,
587,
26,
288,
291,
14,
1238,
275,
756,
339,
347,
1331,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
849,
29,
403,
12,
1067,
29,
403,
304,
267,
340,
849,
365,
488,
26,
288,
849,
275,
1052,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
849,
275,
849,
14,
1574,
342,
267,
849,
14,
873,
3252,
3966,
63,
4470,
63,
344,
356,
378,
1552,
267,
372,
1613,
8,
3070,
63,
1652,
12,
291,
680,
1574,
8,
1556,
12,
1747,
12,
1305,
12,
849,
12,
1067,
29,
1100,
9,
339,
347,
1218,
63,
4470,
8,
277,
12,
2467,
12,
1747,
12,
5322,
12,
1067,
29,
403,
304,
267,
2455,
63,
1580,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1907,
14,
1345,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
1238,
297,
6291,
283,
723,
14,
3723,
14,
3070,
14,
7650,
9819,
659,
661,
466,
297,
6291,
283,
964,
2665,
1067,
29,
1100,
9,
398,
1595,
63,
3643,
275,
791,
354,
356,
5322,
14,
362,
360,
354,
297,
283,
48,
21335,
526,
11774,
659,
2432,
283,
470,
63,
1238,
356,
283,
723,
14,
3723,
14,
3070,
14,
7650,
9819,
297,
2432,
283,
466,
7,
520,
283,
723,
14,
3723,
14,
2442,
63,
3806,
297,
2432,
283,
1345,
63,
466,
356,
283,
964,
297,
2432,
283,
1345,
63,
632,
356,
283,
2350,
12,
964,
297,
2432,
283,
1345,
63,
344,
7,
520,
2455,
63,
1580,
436,
2455,
63,
1580,
59,
16,
61,
503,
378,
12,
2432,
283,
1100,
7,
520,
298,
1445,
1364,
63,
354,
356,
1543,
83,
936,
2,
450,
5322,
14,
362,
360,
3070,
63,
354,
297,
9929,
2432,
283,
1375,
7,
520,
283,
1222,
297,
2432,
789,
267,
1595,
63,
344,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
3723,
14,
2442,
63,
3806,
1959,
981,
8,
1556,
12,
1747,
12,
1595,
63,
3643,
12,
1067,
29,
1100,
9,
398,
754,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
1907,
14,
4470,
1959,
981,
8,
1556,
12,
12824,
63,
998,
12,
469,
6684,
755,
283,
354,
356,
5322,
14,
362,
360,
354,
7,
20606,
48,
21335,
526,
11774,
659,
6684,
755,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
codelucas/facebook-context
|
backend-flask/backend/example.py
|
1
|
15518
|
#!/usr/bin/env python
# Copyright 2013 AlchemyAPI
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from alchemyapi import AlchemyAPI
import json
demo_text = 'Yesterday dumb Bob destroyed my fancy iPhone in beautiful Denver, Colorado. I guess I will have to head over to the Apple Store and buy a new one.'
demo_url = 'http://www.npr.org/2013/11/26/247336038/dont-stuff-the-turkey-and-other-tips-from-americas-test-kitchen'
demo_html = '<html><head><title>Python Demo | AlchemyAPI</title></head><body><h1>Did you know that AlchemyAPI works on HTML?</h1><p>Well, you do now.</p></body></html>'
print('')
print('')
print(' , ')
print(' .I7777~ ')
print(' .I7777777 ')
print(' +. 77777777 ')
print(' =???, I7777777= ')
print('=?????? 7777777? ,:::===? ')
print('=???????. 777777777777777777~ .77: ?? :7 =$, :$$$$$$+ =$? ')
print(' ????????: .777777777777777777 II77 ?? :7 $$7 :$? 7$7 =$? ')
print(' .???????= +7777777777777777 .7 =7: ?? :7777+ :7:I777? ?777I= 77~777? ,777I I7 77 +$?$: :$? $$ =$? ')
print(' ???????+ ~777???+===::: :7+ ~7 ?? .77 +7 :7?. II 7~ ,I7 77+ I77 ~7 ?7 =7: .$, =$ :$? ,$$? =$? ')
print(' ,???????~ 77 7: ?? ?I. 7 :7 :7 ~7 7 77 =7: 7 7 7~ 7$ $= :$$$$$$~ =$? ')
print(' .??????? ,???I77777777777~ :77777777~ ?? 7: :7 :7 777777777:77 =7 7 +7 ~7 $$$$$$$$I :$? =$? ')
print(' .??????? ,7777777777777777 7= 77 ?? I+ 7 :7 :7 ?? 7,77 =7 7 7~ 7, =$7 $$, :$? =$? ')
print(' .???????. I77777777777777777 +7 ,7??? 77 I7 :7 :7 7~ .?7 77 =7 7 ,77I $+ 7$ :$? =$? ')
print(' ,???????= :77777777777777777~ 7= ~7?? ~I77777 :7 :7 ,777777. 77 =7 7 77, +$ .$::$? =$? ')
print(',??????? :7777777 77 ')
print(' =????? ,7777777 77= ')
print(' +?+ 7777777? ')
print(' + ~7777777 ')
print(' I777777 ')
print(' :~ ')
#Create the AlchemyAPI Object
alchemyapi = AlchemyAPI()
print('')
print('')
print('############################################')
print('# Entity Extraction Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.entities('text',demo_text, { 'sentiment':1 })
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Entities ##')
for entity in response['entities']:
print('text: ', entity['text'].encode('utf-8'))
print('type: ', entity['type'])
print('relevance: ', entity['relevance'])
print('sentiment: ', entity['sentiment']['type'])
if 'score' in entity['sentiment']:
print('sentiment score: ' + entity['sentiment']['score'])
print('')
else:
print('Error in entity extraction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Keyword Extraction Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.keywords('text',demo_text, { 'sentiment':1 })
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Keywords ##')
for keyword in response['keywords']:
print('text: ', keyword['text'].encode('utf-8'))
print('relevance: ', keyword['relevance'])
print('sentiment: ', keyword['sentiment']['type'])
if 'score' in keyword['sentiment']:
print('sentiment score: ' + keyword['sentiment']['score'])
print('')
else:
print('Error in keyword extaction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Concept Tagging Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.concepts('text',demo_text)
if response['status'] == 'OK':
print('## Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Concepts ##')
for concept in response['concepts']:
print('text: ', concept['text'])
print('relevance: ', concept['relevance'])
print('')
else:
print('Error in concept tagging call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Sentiment Analysis Example #')
print('############################################')
print('')
print('')
print('Processing html: ', demo_html)
print('')
response = alchemyapi.sentiment('html',demo_html)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Document Sentiment ##')
print('type: ', response['docSentiment']['type'])
if 'score' in response['docSentiment']:
print('score: ', response['docSentiment']['score'])
else:
print('Error in sentiment analysis call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Targeted Sentiment Analysis Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.sentiment_targeted('text',demo_text, 'Denver')
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Targeted Sentiment ##')
print('type: ', response['docSentiment']['type'])
if 'score' in response['docSentiment']:
print('score: ', response['docSentiment']['score'])
else:
print('Error in targeted sentiment analysis call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Text Extraction Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.text('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Text ##')
print('text: ', response['text'].encode('utf-8'))
print('')
else:
print('Error in text extraction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Author Extraction Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.author('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Author ##')
print('author: ', response['author'].encode('utf-8'))
print('')
else:
print('Error in author extraction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Language Detection Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.language('text',demo_text)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Language ##')
print('language: ', response['language'])
print('iso-639-1: ', response['iso-639-1'])
print('native speakers: ', response['native-speakers'])
print('')
else:
print('Error in language detection call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Title Extraction Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.title('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Title ##')
print('title: ', response['title'].encode('utf-8'))
print('')
else:
print('Error in title extraction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Relation Extraction Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.relations('text',demo_text)
if response['status'] == 'OK':
print('## Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Relations ##')
for relation in response['relations']:
if 'subject' in relation:
print('Subject: ', relation['subject']['text'].encode('utf-8'))
if 'action' in relation:
print('Action: ', relation['action']['text'].encode('utf-8'))
if 'object' in relation:
print('Object: ', relation['object']['text'].encode('utf-8'))
print('')
else:
print('Error in relation extaction call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Text Categorization Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.category('text',demo_text)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Category ##')
print('text: ', response['category'])
print('score: ', response['score'])
print('')
else:
print('Error in text categorization call: ', response['statusInfo'])
print('')
print('')
print('')
print('############################################')
print('# Feed Detection Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.feeds('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Feeds ##')
for feed in response['feeds']:
print('feed: ', feed['feed'])
else:
print('Error in feed detection call: ', response['statusInfo'])
print('')
print('')
print('')
print('')
print('')
print('############################################')
print('# Microformats Parsing Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.microformats('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Microformats ##')
for microformat in response['microformats']:
print('Field: ', microformat['field'].encode('utf-8'))
print('Data: ', microformat['data'])
print('')
else:
print('Error in microformats parsing call: ', response['statusInfo'])
print('')
print('')
print('')
print('')
print('')
print('############################################')
print('# Image Extraction Example #')
print('############################################')
print('')
print('')
print('Processing url: ', demo_url)
print('')
response = alchemyapi.imageExtraction('url',demo_url)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Image ##')
print('Image: ', response['image'])
print('')
else:
print('Error in image extraction call: ', response['statusInfo'])
print('')
print('')
print('')
print('')
print('')
print('############################################')
print('# Taxonomy Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.taxonomy('text',demo_text)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Categories ##')
for category in response['taxonomy']:
print(category['label'], ' : ', category['score'])
print('')
else:
print('Error in taxonomy call: ', response['statusInfo'])
print('')
print('')
print('')
print('')
print('')
print('############################################')
print('# Combined Example #')
print('############################################')
print('')
print('')
print('Processing text: ', demo_text)
print('')
response = alchemyapi.combined('text',demo_text)
if response['status'] == 'OK':
print('## Response Object ##')
print(json.dumps(response, indent=4))
print('')
print('## Keywords ##')
for keyword in response['keywords']:
print(keyword['text'], ' : ', keyword['relevance'])
print('')
print('## Concepts ##')
for concept in response['concepts']:
print(concept['text'], ' : ', concept['relevance'])
print('')
print('## Entities ##')
for entity in response['entities']:
print(entity['type'], ' : ', entity['text'], ', ', entity['relevance'])
print(' ')
else:
print('Error in combined call: ', response['statusInfo'])
print('')
print('')
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
198,
7384,
6171,
4580,
5623,
3735,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
421,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
741,
5623,
1246,
492,
4580,
5623,
3735,
199,
646,
2022,
421,
199,
8768,
63,
505,
275,
283,
12555,
25297,
32490,
699,
2873,
28924,
3002,
27571,
284,
15199,
315,
506,
25146,
25187,
422,
12,
11581,
5129,
14,
473,
9519,
473,
911,
1172,
370,
4854,
1806,
370,
314,
21257,
13874,
436,
1032,
89,
282,
892,
1373,
3530,
199,
8768,
63,
633,
275,
283,
1014,
921,
1544,
14,
1590,
82,
14,
1308,
15,
6965,
15,
845,
15,
1479,
15,
11717,
12135,
14273,
15,
18671,
13,
14573,
13,
1589,
13,
16218,
498,
13,
460,
13,
1848,
13,
25842,
13,
504,
13,
313,
1567,
305,
13,
396,
13,
6065,
24604,
7,
199,
8768,
63,
1360,
275,
2650,
1360,
2535,
2993,
2535,
1213,
30,
4718,
28939,
1204,
4580,
5623,
3735,
1108,
1213,
2957,
2993,
2535,
2030,
2535,
72,
17,
30,
17366,
1265,
5715,
626,
4580,
5623,
3735,
5419,
641,
4163,
31,
1108,
72,
17,
2535,
80,
30,
55,
1697,
12,
1265,
886,
3063,
9758,
80,
2957,
2030,
2957,
1360,
3524,
421,
199,
1361,
8355,
199,
1361,
8355,
199,
1361,
360,
3322,
2360,
6208,
2476,
19242,
5320,
221,
199,
1361,
360,
420,
1275,
41,
16713,
94,
6208,
2476,
19242,
5320,
199,
1361,
360,
258,
1275,
41,
16713,
11956,
6208,
2476,
17907,
5320,
199,
1361,
360,
257,
435,
14,
221,
8375,
16713,
1138,
6208,
2476,
14960,
5320,
199,
1361,
360,
275,
10674,
22556,
221,
473,
16713,
11956,
29,
6208,
2476,
14516,
5320,
199,
1361,
26800,
10674,
10674,
10674,
257,
8375,
1138,
11956,
31,
257,
2360,
447,
26,
5918,
31,
6208,
2476,
4519,
5320,
199,
1361,
26800,
10674,
10674,
10674,
31,
14,
221,
8375,
16713,
16713,
16713,
16713,
94,
260,
1275,
1138,
26,
259,
5805,
31,
3698,
520,
23,
2476,
4519,
275,
4,
12,
258,
520,
23174,
23174,
23174,
11,
221,
275,
4,
31,
3515,
5320,
199,
1361,
360,
5805,
10674,
10674,
10674,
31,
26,
1275,
16713,
16713,
16713,
16713,
1138,
260,
473,
41,
1138,
259,
5805,
31,
3698,
520,
23,
2476,
4519,
2672,
4,
23,
258,
520,
4,
31,
257,
1520,
4,
23,
275,
4,
31,
3515,
5320,
199,
1361,
360,
221,
1275,
10674,
10674,
10674,
23295,
221,
435,
16713,
16713,
16713,
16713,
263,
1275,
23,
275,
23,
26,
257,
5805,
31,
257,
520,
16713,
11,
221,
520,
23,
26,
41,
11956,
31,
259,
5805,
11956,
41,
29,
221,
8375,
94,
11956,
31,
2360,
11956,
41,
473,
23,
420,
8375,
257,
435,
4,
31,
4,
26,
259,
520,
4,
31,
259,
2672,
4,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
5805,
10674,
10674,
10674,
11,
221,
6146,
11956,
10674,
31,
11,
5918,
447,
26,
260,
520,
23,
11,
221,
6146,
23,
257,
5805,
31,
1275,
1138,
259,
435,
23,
520,
23,
31,
14,
257,
473,
41,
221,
1520,
94,
257,
2360,
41,
23,
8375,
11,
257,
473,
1138,
257,
6146,
23,
5805,
23,
259,
275,
23,
26,
221,
1275,
4,
12,
275,
4,
259,
520,
4,
31,
221,
2360,
23174,
31,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
2360,
10674,
10674,
10674,
31,
94,
12788,
8375,
259,
1520,
26,
221,
5805,
31,
5805,
41,
14,
258,
1520,
520,
23,
258,
520,
23,
6146,
23,
420,
1520,
8375,
259,
275,
23,
26,
259,
1520,
221,
1520,
259,
1520,
94,
257,
1520,
4,
257,
2672,
29,
257,
520,
23174,
23174,
23174,
94,
221,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
1275,
10674,
10674,
10674,
31,
221,
2360,
10674,
31,
41,
16713,
16713,
11956,
94,
258,
520,
16713,
16713,
94,
5805,
31,
1520,
26,
263,
520,
23,
258,
520,
23,
8375,
16713,
11956,
26,
1138,
259,
275,
23,
258,
1520,
221,
435,
23,
221,
6146,
23,
257,
2672,
23174,
23174,
23174,
4,
41,
221,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
257,
1275,
10674,
10674,
10674,
31,
221,
2360,
16713,
16713,
16713,
16713,
420,
1520,
29,
420,
8375,
5805,
31,
473,
11,
420,
1520,
520,
23,
258,
520,
23,
5805,
31,
420,
1520,
12,
1138,
259,
275,
23,
258,
1520,
257,
1520,
94,
1520,
12,
221,
275,
4,
23,
258,
2672,
4,
12,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
221,
1275,
10674,
10674,
10674,
31,
14,
473,
16713,
16713,
16713,
1138,
11956,
258,
435,
23,
755,
2360,
23,
10674,
31,
221,
8375,
259,
473,
23,
520,
23,
258,
520,
23,
221,
1520,
94,
257,
1275,
31,
23,
8375,
259,
275,
23,
258,
1520,
257,
2360,
1138,
41,
257,
2672,
11,
755,
1520,
4,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
2360,
10674,
10674,
10674,
23295,
520,
16713,
16713,
16713,
1138,
11956,
94,
258,
1520,
29,
263,
6146,
23,
10674,
221,
6146,
41,
1138,
11956,
221,
520,
23,
258,
520,
23,
221,
2360,
16713,
1138,
14,
8375,
259,
275,
23,
258,
1520,
259,
8375,
12,
221,
435,
4,
263,
1275,
4,
447,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
5102,
10674,
10674,
10674,
31,
221,
520,
16713,
11956,
6208,
4483,
8375,
2476,
755,
5320,
199,
1361,
360,
275,
10674,
10674,
31,
221,
2360,
16713,
11956,
6208,
5185,
8375,
29,
2476,
263,
5320,
199,
1361,
360,
257,
435,
31,
11,
221,
8375,
1138,
11956,
31
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
198,
7384,
6171,
4580,
5623,
3735,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
421,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
741,
5623,
1246,
492,
4580,
5623,
3735,
199,
646,
2022,
421,
199,
8768,
63,
505,
275,
283,
12555,
25297,
32490,
699,
2873,
28924,
3002,
27571,
284,
15199,
315,
506,
25146,
25187,
422,
12,
11581,
5129,
14,
473,
9519,
473,
911,
1172,
370,
4854,
1806,
370,
314,
21257,
13874,
436,
1032,
89,
282,
892,
1373,
3530,
199,
8768,
63,
633,
275,
283,
1014,
921,
1544,
14,
1590,
82,
14,
1308,
15,
6965,
15,
845,
15,
1479,
15,
11717,
12135,
14273,
15,
18671,
13,
14573,
13,
1589,
13,
16218,
498,
13,
460,
13,
1848,
13,
25842,
13,
504,
13,
313,
1567,
305,
13,
396,
13,
6065,
24604,
7,
199,
8768,
63,
1360,
275,
2650,
1360,
2535,
2993,
2535,
1213,
30,
4718,
28939,
1204,
4580,
5623,
3735,
1108,
1213,
2957,
2993,
2535,
2030,
2535,
72,
17,
30,
17366,
1265,
5715,
626,
4580,
5623,
3735,
5419,
641,
4163,
31,
1108,
72,
17,
2535,
80,
30,
55,
1697,
12,
1265,
886,
3063,
9758,
80,
2957,
2030,
2957,
1360,
3524,
421,
199,
1361,
8355,
199,
1361,
8355,
199,
1361,
360,
3322,
2360,
6208,
2476,
19242,
5320,
221,
199,
1361,
360,
420,
1275,
41,
16713,
94,
6208,
2476,
19242,
5320,
199,
1361,
360,
258,
1275,
41,
16713,
11956,
6208,
2476,
17907,
5320,
199,
1361,
360,
257,
435,
14,
221,
8375,
16713,
1138,
6208,
2476,
14960,
5320,
199,
1361,
360,
275,
10674,
22556,
221,
473,
16713,
11956,
29,
6208,
2476,
14516,
5320,
199,
1361,
26800,
10674,
10674,
10674,
257,
8375,
1138,
11956,
31,
257,
2360,
447,
26,
5918,
31,
6208,
2476,
4519,
5320,
199,
1361,
26800,
10674,
10674,
10674,
31,
14,
221,
8375,
16713,
16713,
16713,
16713,
94,
260,
1275,
1138,
26,
259,
5805,
31,
3698,
520,
23,
2476,
4519,
275,
4,
12,
258,
520,
23174,
23174,
23174,
11,
221,
275,
4,
31,
3515,
5320,
199,
1361,
360,
5805,
10674,
10674,
10674,
31,
26,
1275,
16713,
16713,
16713,
16713,
1138,
260,
473,
41,
1138,
259,
5805,
31,
3698,
520,
23,
2476,
4519,
2672,
4,
23,
258,
520,
4,
31,
257,
1520,
4,
23,
275,
4,
31,
3515,
5320,
199,
1361,
360,
221,
1275,
10674,
10674,
10674,
23295,
221,
435,
16713,
16713,
16713,
16713,
263,
1275,
23,
275,
23,
26,
257,
5805,
31,
257,
520,
16713,
11,
221,
520,
23,
26,
41,
11956,
31,
259,
5805,
11956,
41,
29,
221,
8375,
94,
11956,
31,
2360,
11956,
41,
473,
23,
420,
8375,
257,
435,
4,
31,
4,
26,
259,
520,
4,
31,
259,
2672,
4,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
5805,
10674,
10674,
10674,
11,
221,
6146,
11956,
10674,
31,
11,
5918,
447,
26,
260,
520,
23,
11,
221,
6146,
23,
257,
5805,
31,
1275,
1138,
259,
435,
23,
520,
23,
31,
14,
257,
473,
41,
221,
1520,
94,
257,
2360,
41,
23,
8375,
11,
257,
473,
1138,
257,
6146,
23,
5805,
23,
259,
275,
23,
26,
221,
1275,
4,
12,
275,
4,
259,
520,
4,
31,
221,
2360,
23174,
31,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
2360,
10674,
10674,
10674,
31,
94,
12788,
8375,
259,
1520,
26,
221,
5805,
31,
5805,
41,
14,
258,
1520,
520,
23,
258,
520,
23,
6146,
23,
420,
1520,
8375,
259,
275,
23,
26,
259,
1520,
221,
1520,
259,
1520,
94,
257,
1520,
4,
257,
2672,
29,
257,
520,
23174,
23174,
23174,
94,
221,
275,
4,
31,
3515,
5320,
199,
1361,
360,
259,
1275,
10674,
10674,
10674,
31,
221,
2360,
10674,
31,
41,
16713,
16713,
11956,
94,
258,
520,
16713,
16713,
94,
5805,
31,
1520,
26,
263,
520,
23,
258,
520,
23,
8375,
16713,
11956,
26,
1138,
259,
275,
23,
258,
1520,
221,
435,
23,
221,
6146,
23,
257,
2672,
23174,
23174,
23174,
4,
41,
221,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
257,
1275,
10674,
10674,
10674,
31,
221,
2360,
16713,
16713,
16713,
16713,
420,
1520,
29,
420,
8375,
5805,
31,
473,
11,
420,
1520,
520,
23,
258,
520,
23,
5805,
31,
420,
1520,
12,
1138,
259,
275,
23,
258,
1520,
257,
1520,
94,
1520,
12,
221,
275,
4,
23,
258,
2672,
4,
12,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
221,
1275,
10674,
10674,
10674,
31,
14,
473,
16713,
16713,
16713,
1138,
11956,
258,
435,
23,
755,
2360,
23,
10674,
31,
221,
8375,
259,
473,
23,
520,
23,
258,
520,
23,
221,
1520,
94,
257,
1275,
31,
23,
8375,
259,
275,
23,
258,
1520,
257,
2360,
1138,
41,
257,
2672,
11,
755,
1520,
4,
520,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
360,
2360,
10674,
10674,
10674,
23295,
520,
16713,
16713,
16713,
1138,
11956,
94,
258,
1520,
29,
263,
6146,
23,
10674,
221,
6146,
41,
1138,
11956,
221,
520,
23,
258,
520,
23,
221,
2360,
16713,
1138,
14,
8375,
259,
275,
23,
258,
1520,
259,
8375,
12,
221,
435,
4,
263,
1275,
4,
447,
4,
31,
755,
275,
4,
31,
3515,
5320,
199,
1361,
5102,
10674,
10674,
10674,
31,
221,
520,
16713,
11956,
6208,
4483,
8375,
2476,
755,
5320,
199,
1361,
360,
275,
10674,
10674,
31,
221,
2360,
16713,
11956,
6208,
5185,
8375,
29,
2476,
263,
5320,
199,
1361,
360,
257,
435,
31,
11,
221,
8375,
1138,
11956,
31,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hammerhorn/hammerhorn-jive
|
cjh/letterator.py
|
6
|
1511
|
#!/usr/bin/env python
"""
Generates sequences, e.g., 'a', 'b', 'c', ... , 'z', 'aa', 'bb' .... and
in the same manner for capital letters.
"""
class Letter(object):
"""
* Convert to closure or lambda of some kind? These two generators have a
lot in common....
"""
pass_no = 1
@classmethod
def caps_gen(cls, start_letter='A'):
"""Generates sequences of capital letters."""
start_ord = ord(start_letter)
if start_ord >= 65 and start_ord < 91:
letters = iter(range(start_ord, 91))
while True:
try:
output = chr(next(letters))
if output != 'I':
yield output * cls.pass_no
except StopIteration:
cls.pass_no += 1
letters = iter(range(65, 91))
else: raise ValueError
@classmethod
def lower_gen(cls, start_letter='a'):
"""Generates sequences of lower-case letters."""
start_ord = ord(start_letter)
if start_ord >= 97 and start_ord < 123:
letters = iter(range(start_ord, 123))
while True:
try:
output = chr(next(letters))
if output != 'i':
yield output * cls.pass_no
except StopIteration:
cls.pass_no += 1
letters = iter(xrange(97, 123))
else: raise ValueError
# @staticmethod
# def ord()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
20551,
8013,
12,
325,
14,
71,
2020,
283,
65,
297,
283,
66,
297,
283,
67,
297,
2263,
2360,
283,
90,
297,
283,
2158,
297,
283,
2501,
7,
29222,
436,
199,
262,
314,
2011,
30800,
367,
17094,
14435,
14,
199,
624,
199,
199,
533,
12230,
351,
8,
785,
304,
272,
408,
272,
627,
7905,
370,
17903,
503,
2400,
402,
2005,
4928,
31,
5723,
2877,
16952,
1172,
282,
272,
13918,
315,
2863,
4496,
272,
408,
339,
986,
63,
889,
275,
413,
339,
768,
3744,
272,
347,
22053,
63,
2268,
8,
1886,
12,
1343,
63,
9269,
534,
33,
735,
267,
408,
20551,
8013,
402,
17094,
14435,
1041,
267,
1343,
63,
2181,
275,
6206,
8,
928,
63,
9269,
9,
267,
340,
1343,
63,
2181,
2356,
11738,
436,
1343,
63,
2181,
665,
21358,
26,
288,
14435,
275,
2740,
8,
1842,
8,
928,
63,
2181,
12,
21358,
430,
288,
1830,
715,
26,
355,
862,
26,
490,
1072,
275,
8678,
8,
2184,
8,
16415,
430,
490,
340,
1072,
1137,
283,
41,
356,
717,
1995,
1072,
627,
843,
14,
1529,
63,
889,
355,
871,
10852,
26,
490,
843,
14,
1529,
63,
889,
847,
413,
490,
14435,
275,
2740,
8,
1842,
8,
2182,
12,
21358,
430,
267,
587,
26,
746,
1722,
339,
768,
3744,
272,
347,
5117,
63,
2268,
8,
1886,
12,
1343,
63,
9269,
534,
65,
735,
267,
408,
20551,
8013,
402,
5117,
13,
2546,
14435,
1041,
267,
1343,
63,
2181,
275,
6206,
8,
928,
63,
9269,
9,
267,
340,
1343,
63,
2181,
2356,
15997,
436,
1343,
63,
2181,
665,
11869,
26,
288,
14435,
275,
2740,
8,
1842,
8,
928,
63,
2181,
12,
11869,
430,
288,
1830,
715,
26,
355,
862,
26,
490,
1072,
275,
8678,
8,
2184,
8,
16415,
430,
490,
340,
1072,
1137,
283,
73,
356,
717,
1995,
1072,
627,
843,
14,
1529,
63,
889,
355,
871,
10852,
26,
490,
843,
14,
1529,
63,
889,
847,
413,
490,
14435,
275,
2740,
8,
21120,
8,
2576,
12,
11869,
430,
267,
587,
26,
746,
1722,
199,
199,
3,
259,
768,
4639,
199,
3,
259,
347,
6206,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
20551,
8013,
12,
325,
14,
71,
2020,
283,
65,
297,
283,
66,
297,
283,
67,
297,
2263,
2360,
283,
90,
297,
283,
2158,
297,
283,
2501,
7,
29222,
436,
199,
262,
314,
2011,
30800,
367,
17094,
14435,
14,
199,
624,
199,
199,
533,
12230,
351,
8,
785,
304,
272,
408,
272,
627,
7905,
370,
17903,
503,
2400,
402,
2005,
4928,
31,
5723,
2877,
16952,
1172,
282,
272,
13918,
315,
2863,
4496,
272,
408,
339,
986,
63,
889,
275,
413,
339,
768,
3744,
272,
347,
22053,
63,
2268,
8,
1886,
12,
1343,
63,
9269,
534,
33,
735,
267,
408,
20551,
8013,
402,
17094,
14435,
1041,
267,
1343,
63,
2181,
275,
6206,
8,
928,
63,
9269,
9,
267,
340,
1343,
63,
2181,
2356,
11738,
436,
1343,
63,
2181,
665,
21358,
26,
288,
14435,
275,
2740,
8,
1842,
8,
928,
63,
2181,
12,
21358,
430,
288,
1830,
715,
26,
355,
862,
26,
490,
1072,
275,
8678,
8,
2184,
8,
16415,
430,
490,
340,
1072,
1137,
283,
41,
356,
717,
1995,
1072,
627,
843,
14,
1529,
63,
889,
355,
871,
10852,
26,
490,
843,
14,
1529,
63,
889,
847,
413,
490,
14435,
275,
2740,
8,
1842,
8,
2182,
12,
21358,
430,
267,
587,
26,
746,
1722,
339,
768,
3744,
272,
347,
5117,
63,
2268,
8,
1886,
12,
1343,
63,
9269,
534,
65,
735,
267,
408,
20551,
8013,
402,
5117,
13,
2546,
14435,
1041,
267,
1343,
63,
2181,
275,
6206,
8,
928,
63,
9269,
9,
267,
340,
1343,
63,
2181,
2356,
15997,
436,
1343,
63,
2181,
665,
11869,
26,
288,
14435,
275,
2740,
8,
1842,
8,
928,
63,
2181,
12,
11869,
430,
288,
1830,
715,
26,
355,
862,
26,
490,
1072,
275,
8678,
8,
2184,
8,
16415,
430,
490,
340,
1072,
1137,
283,
73,
356,
717,
1995,
1072,
627,
843,
14,
1529,
63,
889,
355,
871,
10852,
26,
490,
843,
14,
1529,
63,
889,
847,
413,
490,
14435,
275,
2740,
8,
21120,
8,
2576,
12,
11869,
430,
267,
587,
26,
746,
1722,
199,
199,
3,
259,
768,
4639,
199,
3,
259,
347,
6206,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
KaranToor/MA450
|
google-cloud-sdk/.install/.backup/platform/gsutil/third_party/boto/boto/sdb/regioninfo.py
|
167
|
1524
|
# Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/
# Copyright (c) 2010, Eucalyptus Systems, Inc.
# 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.
#
from boto.regioninfo import RegionInfo
class SDBRegionInfo(RegionInfo):
def __init__(self, connection=None, name=None, endpoint=None,
connection_cls=None):
from boto.sdb.connection import SDBConnection
super(SDBRegionInfo, self).__init__(connection, name, endpoint,
SDBConnection)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
8315,
13,
6542,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
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,
3,
199,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
199,
199,
533,
428,
2846,
10708,
2354,
8,
10708,
2354,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
6037,
29,
403,
12,
326,
1950,
63,
1886,
29,
403,
304,
267,
687,
6055,
14,
21624,
14,
2105,
492,
428,
2846,
3225,
267,
1613,
8,
51,
2846,
10708,
2354,
12,
291,
2843,
826,
721,
2105,
12,
536,
12,
6037,
12,
1169,
428,
2846,
3225,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
8315,
13,
6542,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
199,
3,
1898,
334,
67,
9,
7129,
12,
662,
85,
915,
89,
541,
527,
15285,
12,
3277,
14,
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,
3,
199,
199,
504,
6055,
14,
4551,
815,
492,
22240,
2354,
199,
199,
533,
428,
2846,
10708,
2354,
8,
10708,
2354,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
6037,
29,
403,
12,
326,
1950,
63,
1886,
29,
403,
304,
267,
687,
6055,
14,
21624,
14,
2105,
492,
428,
2846,
3225,
267,
1613,
8,
51,
2846,
10708,
2354,
12,
291,
2843,
826,
721,
2105,
12,
536,
12,
6037,
12,
1169,
428,
2846,
3225,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PDuckworth/strands_qsr_lib
|
qsr_prob_rep/src/qsrrep_utils/qtc_model_creation.py
|
5
|
4167
|
# -*- coding: utf-8 -*-
from qsrrep_utils.model_creation_abstractclass import ModelCreationAbstractclass, return_numpy_array
import numpy as np
class QTCModelCreation(ModelCreationAbstractclass):
class qtc_types():
qtcbs = 'qtcbs'
qtccs = 'qtccs'
qtcbcs = 'qtcbcs'
qtch = 'qtch'
robot = 'robot'
__confusion_matrix = np.array([
[.9, .1, .0, .0],
[.1, .8, .1, .0],
[.0, .1, .9, .0],
[.0, .0, .0, 1.]
])
__states = [-1, 0, 1, np.nan]
def __create_states(self, qtc_type, start_end=False):
if qtc_type == self.qtc_types.qtcbs:
if start_end:
yield [np.NaN, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
yield [i-2, j-2]
if start_end:
yield [np.NaN, np.NaN]
elif qtc_type == self.qtc_types.qtccs:
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
for k in xrange(1, 4):
for l in xrange(1, 4):
yield [i-2, j-2, k-2, l-2]
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
elif qtc_type.startswith(self.qtc_types.qtcbcs):
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
yield [i-2, j-2, np.NaN, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
for k in xrange(1, 4):
for l in xrange(1, 4):
yield [i-2, j-2, k-2, l-2]
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
elif qtc_type == self.qtc_types.qtch:
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
for k in xrange(1, 4):
yield [i-2, j-2, k-2, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
for k in xrange(1, 4):
for l in xrange(1, 4):
yield [i-2, j-2, k-2, l-2]
if start_end:
yield [np.NaN, np.NaN, np.NaN, np.NaN]
elif qtc_type == self.qtc_types.robot:
if start_end:
yield [np.NaN, np.NaN]
for i in xrange(1, 4):
yield [i-2, np.NaN]
for i in xrange(1, 4):
for j in xrange(1, 4):
yield [i-2, j-2]
if start_end:
yield [np.NaN, np.NaN]
else:
print "QTC type: '%s' not found" % qtc_type
def create_states(self, **kwargs):
res = [self._create_qtc_string(x) for x in self.__create_states(kwargs["qtc_type"])]
if kwargs["start_end"]:
res.reverse()
res.append("start")
res.reverse()
res.append("end")
return res
def _create_qtc_string(self, qtc):
qtc = np.array(qtc)
qtc = qtc[~np.isnan(qtc)]
return ','.join(map(str, qtc.astype(int))).replace('-1','-').replace('1','+')
def create_prediction_model(self, **kwargs):
raise NotImplementedError("Static prediction model creation for QTC is not available. Please use the trained Markov Model from the HMM.")
@return_numpy_array
def create_observation_model(self, **kwargs):
states = [x for x in self.__create_states(kwargs["qtc_type"], kwargs["start_end"])]
res = []
for p in states:
res.append([])
for o in states:
res[-1].append(
np.prod([
self.__confusion_matrix[self.__states.index(p[y])][self.__states.index(o[y])] \
for y in np.arange(0, len(p))
])
)
res[-1] = res[-1]/np.sum(res[-1])
return res
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1894,
5474,
1155,
63,
1208,
14,
1238,
63,
8782,
63,
6198,
533,
492,
5822,
13921,
8458,
533,
12,
372,
63,
4714,
63,
1144,
199,
646,
2680,
465,
980,
421,
199,
533,
1413,
5708,
1685,
13921,
8,
1685,
13921,
8458,
533,
304,
339,
1021,
1894,
3641,
63,
1313,
837,
267,
1894,
3641,
1533,
275,
283,
81,
3641,
1533,
7,
267,
1894,
3641,
1259,
275,
283,
81,
3641,
1259,
7,
267,
19227,
2894,
1259,
275,
283,
8440,
2894,
1259,
7,
267,
19227,
335,
275,
283,
8440,
335,
7,
267,
14544,
275,
283,
9751,
7,
2378,
636,
2190,
12444,
63,
3642,
275,
980,
14,
1144,
779,
267,
26496,
25,
12,
1275,
17,
12,
1275,
16,
12,
1275,
16,
467,
267,
26496,
17,
12,
1275,
24,
12,
1275,
17,
12,
1275,
16,
467,
267,
26496,
16,
12,
1275,
17,
12,
1275,
25,
12,
1275,
16,
467,
267,
26496,
16,
12,
1275,
16,
12,
1275,
16,
12,
413,
19784,
272,
4794,
272,
636,
4981,
275,
5243,
17,
12,
378,
12,
413,
12,
980,
14,
4304,
61,
339,
347,
636,
981,
63,
4981,
8,
277,
12,
1894,
3641,
63,
466,
12,
1343,
63,
500,
29,
797,
304,
267,
340,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
81,
3641,
1533,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
81,
3641,
1259,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
14,
2460,
8,
277,
14,
81,
3641,
63,
1313,
14,
8440,
2894,
1259,
304,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
8440,
335,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
9751,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
1995,
359,
73,
13,
18,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
267,
587,
26,
288,
870,
298,
49,
5708,
730,
26,
1543,
83,
7,
440,
1911,
2,
450,
1894,
3641,
63,
466,
339,
347,
1218,
63,
4981,
8,
277,
12,
1011,
958,
304,
267,
522,
275,
359,
277,
423,
981,
63,
81,
3641,
63,
875,
8,
88,
9,
367,
671,
315,
291,
855,
981,
63,
4981,
8,
958,
905,
81,
3641,
63,
466,
3135,
61,
267,
340,
2074,
905,
928,
63,
500,
6229,
288,
522,
14,
4471,
342,
288,
522,
14,
740,
480,
928,
531,
288,
522,
14,
4471,
342,
288,
522,
14,
740,
480,
500,
531,
267,
372,
522,
339,
347,
485,
981,
63,
81,
3641,
63,
875,
8,
277,
12,
1894,
3641,
304,
267,
1894,
3641,
275,
980,
14,
1144,
8,
81,
3641,
9,
267,
1894,
3641,
275,
1894,
3641,
19911,
1590,
14,
12936,
8,
81,
3641,
1874,
267,
372,
12814,
904,
8,
1130,
8,
495,
12,
1894,
3641,
14,
6041,
8,
442,
23261,
1814,
3654,
17,
21810,
1959,
1814,
360,
17,
1673,
13854,
339,
347
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1894,
5474,
1155,
63,
1208,
14,
1238,
63,
8782,
63,
6198,
533,
492,
5822,
13921,
8458,
533,
12,
372,
63,
4714,
63,
1144,
199,
646,
2680,
465,
980,
421,
199,
533,
1413,
5708,
1685,
13921,
8,
1685,
13921,
8458,
533,
304,
339,
1021,
1894,
3641,
63,
1313,
837,
267,
1894,
3641,
1533,
275,
283,
81,
3641,
1533,
7,
267,
1894,
3641,
1259,
275,
283,
81,
3641,
1259,
7,
267,
19227,
2894,
1259,
275,
283,
8440,
2894,
1259,
7,
267,
19227,
335,
275,
283,
8440,
335,
7,
267,
14544,
275,
283,
9751,
7,
2378,
636,
2190,
12444,
63,
3642,
275,
980,
14,
1144,
779,
267,
26496,
25,
12,
1275,
17,
12,
1275,
16,
12,
1275,
16,
467,
267,
26496,
17,
12,
1275,
24,
12,
1275,
17,
12,
1275,
16,
467,
267,
26496,
16,
12,
1275,
17,
12,
1275,
25,
12,
1275,
16,
467,
267,
26496,
16,
12,
1275,
16,
12,
1275,
16,
12,
413,
19784,
272,
4794,
272,
636,
4981,
275,
5243,
17,
12,
378,
12,
413,
12,
980,
14,
4304,
61,
339,
347,
636,
981,
63,
4981,
8,
277,
12,
1894,
3641,
63,
466,
12,
1343,
63,
500,
29,
797,
304,
267,
340,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
81,
3641,
1533,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
81,
3641,
1259,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
14,
2460,
8,
277,
14,
81,
3641,
63,
1313,
14,
8440,
2894,
1259,
304,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
8440,
335,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
367,
1022,
315,
4945,
8,
17,
12,
841,
304,
717,
367,
634,
315,
4945,
8,
17,
12,
841,
304,
1169,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
12,
1022,
13,
18,
12,
634,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
12,
980,
14,
14300,
61,
267,
916,
1894,
3641,
63,
466,
508,
291,
14,
81,
3641,
63,
1313,
14,
9751,
26,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
1995,
359,
73,
13,
18,
12,
980,
14,
14300,
61,
288,
367,
284,
315,
4945,
8,
17,
12,
841,
304,
355,
367,
1335,
315,
4945,
8,
17,
12,
841,
304,
490,
1995,
359,
73,
13,
18,
12,
1335,
13,
18,
61,
288,
340,
1343,
63,
500,
26,
355,
1995,
359,
1590,
14,
14300,
12,
980,
14,
14300,
61,
267,
587,
26,
288,
870,
298,
49,
5708,
730,
26,
1543,
83,
7,
440,
1911,
2,
450,
1894,
3641,
63,
466,
339,
347,
1218,
63,
4981,
8,
277,
12,
1011,
958,
304,
267,
522,
275,
359,
277,
423,
981,
63,
81,
3641,
63,
875,
8,
88,
9,
367,
671,
315,
291,
855,
981,
63,
4981,
8,
958,
905,
81,
3641,
63,
466,
3135,
61,
267,
340,
2074,
905,
928,
63,
500,
6229,
288,
522,
14,
4471,
342,
288,
522,
14,
740,
480,
928,
531,
288,
522,
14,
4471,
342,
288,
522,
14,
740,
480,
500,
531,
267,
372,
522,
339,
347,
485,
981,
63,
81,
3641,
63,
875,
8,
277,
12,
1894,
3641,
304,
267,
1894,
3641,
275,
980,
14,
1144,
8,
81,
3641,
9,
267,
1894,
3641,
275,
1894,
3641,
19911,
1590,
14,
12936,
8,
81,
3641,
1874,
267,
372,
12814,
904,
8,
1130,
8,
495,
12,
1894,
3641,
14,
6041,
8,
442,
23261,
1814,
3654,
17,
21810,
1959,
1814,
360,
17,
1673,
13854,
339,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
oblique-labs/pyVM
|
rpython/rlib/unicodedata/test/test_unicodedata.py
|
1
|
6594
|
# encoding: utf-8
import random
import unicodedata
import py
from rpython.rlib.unicodedata import (
unicodedb_3_2_0, unicodedb_5_2_0, unicodedb_6_0_0, unicodedb_6_2_0,
unicodedb_8_0_0)
class TestUnicodeData(object):
def setup_class(cls):
if unicodedata.unidata_version != '5.2.0':
py.test.skip('Needs python with unicode 5.2.0 database.')
seed = random.getrandbits(32)
print "random seed: ", seed
random.seed(seed)
cls.charlist = charlist = []
cls.nocharlist = nocharlist = []
while len(charlist) < 1000 or len(nocharlist) < 1000:
chr = unichr(random.randrange(65536))
try:
charlist.append((chr, unicodedata.name(chr)))
except ValueError:
nocharlist.append(chr)
def test_random_charnames(self):
for chr, name in self.charlist:
assert unicodedb_5_2_0.name(ord(chr)) == name
assert unicodedb_5_2_0.lookup(name) == ord(chr)
def test_random_missing_chars(self):
for chr in self.nocharlist:
py.test.raises(KeyError, unicodedb_5_2_0.name, ord(chr))
def test_isprintable(self):
assert unicodedb_5_2_0.isprintable(ord(' '))
assert unicodedb_5_2_0.isprintable(ord('a'))
assert not unicodedb_5_2_0.isprintable(127)
assert unicodedb_5_2_0.isprintable(0x00010346) # GOTHIC LETTER FAIHU
assert unicodedb_5_2_0.isprintable(0xfffd) # REPLACEMENT CHARACTER
assert unicodedb_5_2_0.isprintable(0xfffd) # REPLACEMENT CHARACTER
assert not unicodedb_5_2_0.isprintable(0xd800) # SURROGATE
assert not unicodedb_5_2_0.isprintable(0xE0020) # TAG SPACE
def test_identifier(self):
assert unicodedb_5_2_0.isxidstart(ord('A'))
assert not unicodedb_5_2_0.isxidstart(ord('_'))
assert not unicodedb_5_2_0.isxidstart(ord('0'))
assert not unicodedb_5_2_0.isxidstart(ord('('))
assert unicodedb_5_2_0.isxidcontinue(ord('A'))
assert unicodedb_5_2_0.isxidcontinue(ord('_'))
assert unicodedb_5_2_0.isxidcontinue(ord('0'))
assert not unicodedb_5_2_0.isxidcontinue(ord('('))
oc = ord(u'日')
assert unicodedb_5_2_0.isxidstart(oc)
def test_compare_functions(self):
def getX(fun, code):
try:
return getattr(unicodedb_5_2_0, fun)(code)
except KeyError:
return -1
for code in range(0x10000):
char = unichr(code)
assert unicodedata.digit(char, -1) == getX('digit', code)
assert unicodedata.numeric(char, -1) == getX('numeric', code)
assert unicodedata.decimal(char, -1) == getX('decimal', code)
assert unicodedata.category(char) == unicodedb_5_2_0.category(code)
assert unicodedata.bidirectional(char) == unicodedb_5_2_0.bidirectional(code)
assert unicodedata.decomposition(char) == unicodedb_5_2_0.decomposition(code)
assert unicodedata.mirrored(char) == unicodedb_5_2_0.mirrored(code)
assert unicodedata.combining(char) == unicodedb_5_2_0.combining(code)
def test_compare_methods(self):
for code in range(0x10000):
char = unichr(code)
assert char.isalnum() == unicodedb_5_2_0.isalnum(code)
assert char.isalpha() == unicodedb_5_2_0.isalpha(code)
assert char.isdecimal() == unicodedb_5_2_0.isdecimal(code)
assert char.isdigit() == unicodedb_5_2_0.isdigit(code)
assert char.islower() == unicodedb_5_2_0.islower(code)
assert char.isnumeric() == unicodedb_5_2_0.isnumeric(code)
assert char.isspace() == unicodedb_5_2_0.isspace(code), hex(code)
assert char.istitle() == (unicodedb_5_2_0.isupper(code) or unicodedb_5_2_0.istitle(code)), code
assert char.isupper() == unicodedb_5_2_0.isupper(code)
assert char.lower() == unichr(unicodedb_5_2_0.tolower(code))
assert char.upper() == unichr(unicodedb_5_2_0.toupper(code))
assert char.title() == unichr(unicodedb_5_2_0.totitle(code)), hex(code)
def test_hangul_difference_520(self):
assert unicodedb_5_2_0.name(40874) == 'CJK UNIFIED IDEOGRAPH-9FAA'
def test_differences(self):
assert unicodedb_5_2_0.name(9187) == 'BENZENE RING WITH CIRCLE'
assert unicodedb_5_2_0.lookup('BENZENE RING WITH CIRCLE') == 9187
py.test.raises(KeyError, unicodedb_3_2_0.lookup, 'BENZENE RING WITH CIRCLE')
py.test.raises(KeyError, unicodedb_3_2_0.name, 9187)
def test_casefolding(self):
assert unicodedb_6_2_0.casefold_lookup(223) == [115, 115]
assert unicodedb_6_2_0.casefold_lookup(976) == [946]
assert unicodedb_5_2_0.casefold_lookup(42592) == None
# 1010 has been remove between 3.2.0 and 5.2.0
assert unicodedb_3_2_0.casefold_lookup(1010) == [963]
assert unicodedb_5_2_0.casefold_lookup(1010) == None
# 7838 has been added in 5.2.0
assert unicodedb_3_2_0.casefold_lookup(7838) == None
assert unicodedb_5_2_0.casefold_lookup(7838) == [115, 115]
# Only lookup who cannot be resolved by `lower` are stored in database
assert unicodedb_3_2_0.casefold_lookup(ord('E')) == None
class TestUnicodeData600(object):
def test_some_additions(self):
additions = {
ord(u"\u20B9"): 'INDIAN RUPEE SIGN',
# u'\U0001F37A'
127866: 'BEER MUG',
# u'\U0001F37B'
127867: 'CLINKING BEER MUGS',
# u"\U0001F0AD"
127149: 'PLAYING CARD QUEEN OF SPADES',
# u"\U0002B740"
177984: "CJK UNIFIED IDEOGRAPH-2B740",
}
for un, name in additions.iteritems():
assert unicodedb_6_0_0.name(un) == name
assert unicodedb_6_0_0.isprintable(un)
def test_special_casing(self):
assert unicodedb_6_0_0.tolower_full(ord('A')) == [ord('a')]
# The German es-zed is special--the normal mapping is to SS.
assert unicodedb_6_0_0.tolower_full(ord(u'\xdf')) == [0xdf]
assert unicodedb_6_0_0.toupper_full(ord(u'\xdf')) == map(ord, 'SS')
assert unicodedb_6_0_0.totitle_full(ord(u'\xdf')) == map(ord, 'Ss')
def test_islower(self):
assert unicodedb_6_2_0.islower(0x2177)
class TestUnicodeData800(object):
def test_changed_in_version_8(self):
assert unicodedb_6_2_0.toupper_full(0x025C) == [0x025C]
assert unicodedb_8_0_0.toupper_full(0x025C) == [0xA7AB]
|
mit
|
[
3,
2644,
26,
2774,
13,
24,
199,
646,
2196,
199,
646,
23128,
199,
199,
646,
1134,
199,
199,
504,
519,
1548,
14,
82,
773,
14,
2975,
576,
492,
334,
272,
2649,
697,
63,
19,
63,
18,
63,
16,
12,
2649,
697,
63,
21,
63,
18,
63,
16,
12,
2649,
697,
63,
22,
63,
16,
63,
16,
12,
2649,
697,
63,
22,
63,
18,
63,
16,
12,
272,
2649,
697,
63,
24,
63,
16,
63,
16,
9,
421,
199,
533,
1379,
7087,
1451,
8,
785,
304,
272,
347,
3272,
63,
533,
8,
1886,
304,
267,
340,
23128,
14,
324,
344,
419,
63,
1023,
1137,
283,
21,
14,
18,
14,
16,
356,
288,
1134,
14,
396,
14,
2759,
360,
28390,
2366,
543,
2649,
959,
14,
18,
14,
16,
3050,
2659,
398,
6347,
275,
2196,
14,
362,
3759,
5609,
8,
708,
9,
267,
870,
298,
2355,
6347,
26,
3872,
6347,
267,
2196,
14,
5176,
8,
5176,
9,
267,
843,
14,
1560,
513,
275,
1495,
513,
275,
942,
267,
843,
14,
889,
1560,
513,
275,
949,
1560,
513,
275,
942,
267,
1830,
822,
8,
1560,
513,
9,
665,
5198,
503,
822,
8,
889,
1560,
513,
9,
665,
5198,
26,
288,
8678,
275,
17742,
8,
2355,
14,
20539,
8,
10027,
1344,
430,
288,
862,
26,
355,
1495,
513,
14,
740,
1332,
10194,
12,
23128,
14,
354,
8,
10194,
1724,
288,
871,
1722,
26,
355,
949,
1560,
513,
14,
740,
8,
10194,
9,
339,
347,
511,
63,
2355,
63,
1560,
1247,
8,
277,
304,
267,
367,
8678,
12,
536,
315,
291,
14,
1560,
513,
26,
288,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
354,
8,
2181,
8,
10194,
430,
508,
536,
288,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
3892,
8,
354,
9,
508,
6206,
8,
10194,
9,
339,
347,
511,
63,
2355,
63,
4752,
63,
6574,
8,
277,
304,
267,
367,
8678,
315,
291,
14,
889,
1560,
513,
26,
288,
1134,
14,
396,
14,
3536,
8,
10230,
12,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
354,
12,
6206,
8,
10194,
430,
339,
347,
511,
63,
374,
20557,
8,
277,
304,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
2181,
360,
20005,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
2181,
360,
65,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
4195,
9,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
88,
30889,
12583,
9,
221,
327,
598,
22949,
948,
1578,
481,
7730,
28327,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
3581,
2592,
9,
221,
327,
5363,
2749,
22194,
9502,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
3581,
2592,
9,
221,
327,
5363,
2749,
22194,
9502,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
2207,
6718,
9,
221,
327,
428,
1230,
1092,
26624,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
6991,
20734,
9,
221,
327,
18395,
16796,
339,
347,
511,
63,
5364,
8,
277,
304,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
360,
33,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
6412,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
360,
16,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
14097,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
360,
33,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
6412,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
360,
16,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
14097,
1333,
267,
4244,
275,
6206,
8,
85,
7,
17243,
358,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
679,
9,
339,
347,
511,
63,
5785,
63,
5777,
8,
277,
304,
267,
347,
664,
56,
8,
7036,
12,
1233,
304,
288,
862,
26,
355,
372,
2519,
8,
2975,
697,
63,
21,
63,
18,
63,
16,
12,
9627,
5130,
600,
9,
288,
871,
4067,
26,
355,
372,
446,
17,
398,
367,
1233,
315,
1425,
8,
16,
88,
9943,
304,
288,
1495,
275,
17742,
8,
600,
9,
288,
702,
23128,
14,
8573,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
8573,
297,
1233,
9,
288,
702,
23128,
14,
6677,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
6677,
297,
1233,
9,
288,
702,
23128,
14,
6355,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
6355,
297,
1233,
9,
288,
702,
23128,
14,
3710,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
3710,
8,
600,
9,
288,
702,
23128,
14,
4492,
21360,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
4492,
21360,
8,
600,
9,
288,
702,
23128,
14,
31384,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
31384,
8,
600,
9,
288,
702,
23128,
14,
77,
27533,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
77,
27533,
8,
600,
9,
288,
702,
23128,
14,
6560,
7969,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
6560,
7969,
8,
600,
9,
339,
347,
511,
63,
5785,
63,
2474,
8,
277,
304,
267,
367,
1233,
315,
1425,
8,
16,
88,
9943,
304,
288,
1495,
275,
17742,
8,
600,
9,
288,
702,
1495,
14,
28235,
1507,
342,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
28235,
1507,
8,
600,
9,
288,
702,
1495,
14,
374,
4468,
342,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
4468,
8,
600,
9,
288
] |
[
2644,
26,
2774,
13,
24,
199,
646,
2196,
199,
646,
23128,
199,
199,
646,
1134,
199,
199,
504,
519,
1548,
14,
82,
773,
14,
2975,
576,
492,
334,
272,
2649,
697,
63,
19,
63,
18,
63,
16,
12,
2649,
697,
63,
21,
63,
18,
63,
16,
12,
2649,
697,
63,
22,
63,
16,
63,
16,
12,
2649,
697,
63,
22,
63,
18,
63,
16,
12,
272,
2649,
697,
63,
24,
63,
16,
63,
16,
9,
421,
199,
533,
1379,
7087,
1451,
8,
785,
304,
272,
347,
3272,
63,
533,
8,
1886,
304,
267,
340,
23128,
14,
324,
344,
419,
63,
1023,
1137,
283,
21,
14,
18,
14,
16,
356,
288,
1134,
14,
396,
14,
2759,
360,
28390,
2366,
543,
2649,
959,
14,
18,
14,
16,
3050,
2659,
398,
6347,
275,
2196,
14,
362,
3759,
5609,
8,
708,
9,
267,
870,
298,
2355,
6347,
26,
3872,
6347,
267,
2196,
14,
5176,
8,
5176,
9,
267,
843,
14,
1560,
513,
275,
1495,
513,
275,
942,
267,
843,
14,
889,
1560,
513,
275,
949,
1560,
513,
275,
942,
267,
1830,
822,
8,
1560,
513,
9,
665,
5198,
503,
822,
8,
889,
1560,
513,
9,
665,
5198,
26,
288,
8678,
275,
17742,
8,
2355,
14,
20539,
8,
10027,
1344,
430,
288,
862,
26,
355,
1495,
513,
14,
740,
1332,
10194,
12,
23128,
14,
354,
8,
10194,
1724,
288,
871,
1722,
26,
355,
949,
1560,
513,
14,
740,
8,
10194,
9,
339,
347,
511,
63,
2355,
63,
1560,
1247,
8,
277,
304,
267,
367,
8678,
12,
536,
315,
291,
14,
1560,
513,
26,
288,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
354,
8,
2181,
8,
10194,
430,
508,
536,
288,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
3892,
8,
354,
9,
508,
6206,
8,
10194,
9,
339,
347,
511,
63,
2355,
63,
4752,
63,
6574,
8,
277,
304,
267,
367,
8678,
315,
291,
14,
889,
1560,
513,
26,
288,
1134,
14,
396,
14,
3536,
8,
10230,
12,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
354,
12,
6206,
8,
10194,
430,
339,
347,
511,
63,
374,
20557,
8,
277,
304,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
2181,
360,
20005,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
2181,
360,
65,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
4195,
9,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
88,
30889,
12583,
9,
221,
327,
598,
22949,
948,
1578,
481,
7730,
28327,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
3581,
2592,
9,
221,
327,
5363,
2749,
22194,
9502,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
3581,
2592,
9,
221,
327,
5363,
2749,
22194,
9502,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
2207,
6718,
9,
221,
327,
428,
1230,
1092,
26624,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
20557,
8,
16,
6991,
20734,
9,
221,
327,
18395,
16796,
339,
347,
511,
63,
5364,
8,
277,
304,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
360,
33,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
6412,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
360,
16,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
2181,
14097,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
360,
33,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
6412,
1333,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
360,
16,
1333,
267,
702,
440,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
6958,
8,
2181,
14097,
1333,
267,
4244,
275,
6206,
8,
85,
7,
17243,
358,
267,
702,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
21352,
928,
8,
679,
9,
339,
347,
511,
63,
5785,
63,
5777,
8,
277,
304,
267,
347,
664,
56,
8,
7036,
12,
1233,
304,
288,
862,
26,
355,
372,
2519,
8,
2975,
697,
63,
21,
63,
18,
63,
16,
12,
9627,
5130,
600,
9,
288,
871,
4067,
26,
355,
372,
446,
17,
398,
367,
1233,
315,
1425,
8,
16,
88,
9943,
304,
288,
1495,
275,
17742,
8,
600,
9,
288,
702,
23128,
14,
8573,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
8573,
297,
1233,
9,
288,
702,
23128,
14,
6677,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
6677,
297,
1233,
9,
288,
702,
23128,
14,
6355,
8,
1560,
12,
446,
17,
9,
508,
664,
56,
360,
6355,
297,
1233,
9,
288,
702,
23128,
14,
3710,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
3710,
8,
600,
9,
288,
702,
23128,
14,
4492,
21360,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
4492,
21360,
8,
600,
9,
288,
702,
23128,
14,
31384,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
31384,
8,
600,
9,
288,
702,
23128,
14,
77,
27533,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
77,
27533,
8,
600,
9,
288,
702,
23128,
14,
6560,
7969,
8,
1560,
9,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
6560,
7969,
8,
600,
9,
339,
347,
511,
63,
5785,
63,
2474,
8,
277,
304,
267,
367,
1233,
315,
1425,
8,
16,
88,
9943,
304,
288,
1495,
275,
17742,
8,
600,
9,
288,
702,
1495,
14,
28235,
1507,
342,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
28235,
1507,
8,
600,
9,
288,
702,
1495,
14,
374,
4468,
342,
508,
2649,
697,
63,
21,
63,
18,
63,
16,
14,
374,
4468,
8,
600,
9,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
dereneaton/ipyrad
|
ipyrad/core/paramsinfo.py
|
1
|
21970
|
#!/usr/bin/env python
""" Return explanation and options for each parameter.
ip.get_params_info(1) or ip.get_params_info("project_dir")
return the same result. If not argument, a summary of the available
parameters and their numbered references is returned.
Parameter info is stored as a dict of tuples. Each tuple consists of a
short and a long desription for each parameter. By default if you as
for a parameter you'll get the long description
"""
from __future__ import print_function
from collections import OrderedDict
pinfo = OrderedDict([
("0", ("""
(0) assembly_name ----------------------------------------------------
This is the name of your assembly. It will be the prefix for all
directories inside the project directory. An easy default for this
parameter is the name of your project directory. For example if your
project directory is ./white-crowns, then your assembly name could be
white-crowns. Assembly name is variable because you might want to
fork assemblies within a project to try different runs with different
minimum coverage values, different levels of indels allowed, etc.
Examples:
----------------------------------------------------------------------
data.set_params('assembly_name', "white-crowns") ## verbose
----------------------------------------------------------------------
""", "Assembly name. Used to name output directories for assembly steps")
),
("1", ("""
(1) project_dir ------------------------------------------------------
Project name / path for working directory where all data files will be
saved. This parameter affects all steps of assembly (1-7).
Examples:
----------------------------------------------------------------------
data.set_params('project_dir', "./") ## verbose
----------------------------------------------------------------------
""", "Project dir (made in curdir if not present)")
),
("2", ("""
(2) raw_fastq_path ---------------------------------------------------
The directory or files (selected with * wildcard selector) in which
FASTQ data files reside. Files can be gzipped. This parameter affects
only step 1 of assembly. Examples:
----------------------------------------------------------------------
data.set_params("raw_fastq_path", "raw/*.fastq.gz") ## verbose
----------------------------------------------------------------------
""", "Location of raw non-demultiplexed fastq files")
),
("3", ("""
(3) barcodes_path ----------------------------------------------------
Path to the barcodes file used in step 1 of assembly for
demultiplexing. If data are already demultiplexed this can be left
blank. This parameter affects only step 1 of assembly. NB: iPyrad
can only handle one barcodes file at a time, so if you have multiple
barcodes files and multiple raw files then you'll need to run each
separately. Examples:
----------------------------------------------------------------------
data.set_params("barcodes_path", "./barcodes.txt") ## verbose
----------------------------------------------------------------------
""", "Location of barcodes file")
),
("4", ("""
(4) sorted_fastq_path ------------------------------------------------
Path to demultiplexed fastq data. If left blank, this is assigned
automatically to <data.name>_fastq/ within the working directory. If your
data are already demultiplexed then you must enter the location of your
data here. Wildcard selectors can be used to select a subsample of files
within a directory, else all files are selected in the directory.
This parameter affects only step 2 of assembly.
Examples:
----------------------------------------------------------------------
data.set_params("sorted_fastq_path", "data/*.gz") ##
----------------------------------------------------------------------
""", "Location of demultiplexed/sorted fastq files")
),
("5", ("""
(5) assembly_method --------------------------------------------------
A string specifying the desired assembly method. There are four
available options for assembly method:
denovo - Denovo assembly is the classic pyrad method, and
it is the <default> unless otherwise specified.
Denovo will cluster and align all reads from scratch
reference - Reference assembly will map and align reads to the
provided reference sequence, which must be specified
in parameter 28 (reference_sequence). Strict refer-
ence assembly will throw out all unmapped reads,
which could be a significant proportion depending
on the distance between your reference and study
species.'.
----------------------------------------------------------------------
data.set_params("assembly_method", "denovo") ## verbose
----------------------------------------------------------------------
""", "Assembly method (denovo, reference)")
),
("6", ("""
(6) reference_sequence -----------------------------------------------
The path to the reference sequence you desire to map your reads to.
The reference may be either fasta or gzipped fasta. It should be a
complete reference sequence, including all chromosomes, scaffolds, and
contigs in one huge file (most reference sequences available will be
in this format, especially non-model references). The first time you
attempt to use this sequence it will be indexed (we are using bwa
for reference mapping). This is a time intensive process so expect the
first run to take some time, certainly more than ten minutes, but less
than an hour. If you desire to index the reference yourself you can do
this, but best not to unless you really care about bwa indexing
settings. We chose conservative defaults that have worked well for us
on other projects.
A word on the format of the path (this is important). The path may
either be a full path (desirable) or a path relative to the directory
you are running ipyrad from (supported but be careful of the path).
----------------------------------------------------------------------
data.set_params(6) = /home/wat/data/reference.fa ## set a full path
data.set_params(6) = ./data/reference.fa.gz ## set a relative path
data.set_params("reference_sequence") = ./data/reference.fa ## verbose
----------------------------------------------------------------------
""", "Location of reference sequence file")
),
("7", ("""
(7) datatype ---------------------------------------------------------
Options: rad, gbs, 2brad, ddrad, pairddrad, pairgbs, pair3rad,
This parameter affects all steps of assembly (1-7).
Examples:
----------------------------------------------------------------------
data.set_params(7) = 'rad' ## rad data type
data.set_params(7) = 'gbs' ## gbs data type
data.set_params(7) = 'pairddrad' ## gbs data type
data.set_params("datatype") = 'ddrad' ## verbose
----------------------------------------------------------------------
""", "Datatype (see docs): rad, gbs, ddrad, etc.")
),
("8", ("""
(8) restriction_overhang ---------------------------------------------
A tuple containing one or two restriction overhangs. Single digest
RADseq with sonication requires only one overhange, all other data
types should have two. The first is used for detecting barcodes, the
second is not required, but is used in filtering, and is needed for
removal from short DNA fragments. This parameter affects steps 1,2,4,5,
and 7 of assembly.
Examples:
----------------------------------------------------------------------
data.set_params(8) = ("TGCAG", "") ## default rad (PstI)
data.set_params(8) = ("CWGC", "CWGC") ## gbs or pairgbs (ApeKI)
data.set_params(8) = ("CAGT", "AATT") ## ddrad (ApeKI, MSI)
data.set_params(8) = ("CAGT", "AATT") ## pairddrad (ApeKI, MSI)
data.set_params("restriction_overhang") = ("CAGT", "AATT") ## verbose
----------------------------------------------------------------------
""", "Restriction overhang (cut1,) or (cut1, cut2)")
),
("9", ("""
(9) max_low_qual_bases -----------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(9) = 10
data.set_params("max_low_qual_bases") = 6
----------------------------------------------------------------------
""", "Max low quality base calls (Q<20) in a read")
),
("10", ("""
(10) phred_Qscore_offset ---------------------------------------------
The threshold at which a base call is considered low quality during
step 2 filtering is determined by the phred_Qscore_offset. The default
offset is 33, which is equivalent to a minimum qscore of 20 (99% call
confidence). Some older data use a qscore offset of 64. You can toggle
the offset number to change the threshold for low qual bases. For
example, reducing the offset to 26 is equivalent to a minimum qscore
of 13, which is approximately 95% probability of a correct base call.
Examples:
----------------------------------------------------------------------
data.set_params(10) = 33
data.set_params("phred_Qscore_offset") = 26 ## 95% confidence
data.set_params("phred_Qscore_offset") = 43 ## 99.9% confidence
data.set_params("phred_Qscore_offset") = 33
----------------------------------------------------------------------
""", "phred Q score offset (33 is default and very standard)")
),
("11", ("""
(11) mindepth_statistical --------------------------------------------
An integer value indicating the mindepth for statistical base calls
based a binomial probability with H and E estimated from the data.
Base calls are made at >= the value entered. For most reasonable
estimates of E and H, statistical base calls cannot be made below 5
or 6, and will instead be called N.
The parameter affects steps 5 and 7 of assembly.
Examples:
----------------------------------------------------------------------
data.set_params(11) = (6, 6) ## only stat base calls down to depth=6
data.set_params(11) = (10, 5) ## stat calls above 9, majrule from 9-5.
data.set_params(11) = (10, 1) ## stat calls above 9, majrule from 9-1.
data.set_params(mindepth_statistical) = 6 ## verbose
----------------------------------------------------------------------
""", "Min depth for statistical base calling")
),
("12", ("""
(12) mindepth_majrule ------------------------------------------------
An integer value indicating the mindepth for majority-rule base calls.
Base calls are made at >= the value entered. It may often be advant-
ageous to use a low value for majrule calls to preserve most data during
assembly within-samples, so that more data is clustered between samples.
Low depth data can be filtered out later from the final data set if needed.
The parameter affects steps 5 and 7 of assembly.
Examples:
----------------------------------------------------------------------
data.set_params(12) = (6, 6) ## only stat base calls down to depth=6
data.set_params(12) = (10, 5) ## stat calls above 9, majrule from 9-5.
data.set_params(12) = (10, 1) ## stat calls above 9, majrule from 9-1.
data.set_params(mindepth_majrule) = 6 ## verbose
----------------------------------------------------------------------
""", "Min depth for majority-rule base calling")
),
("13", ("""
(13) maxdepth --------------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(13) = 33
data.set_params("maxdepth") = 33
----------------------------------------------------------------------
""", "Max cluster depth within samples")
),
("14", ("""
(14) clust_threshold -------------------------------------------------
Clustering threshold.
Examples:
----------------------------------------------------------------------
data.set_params(14) = .85 ## clustering similarity threshold
data.set_params(14) = .90 ## clustering similarity threshold
data.set_params(14) = .95 ## very high values not recommended
data.set_params("clust_threshold") = .83 ## verbose
----------------------------------------------------------------------
""", "Clustering threshold for de novo assembly")
),
("15", ("""
(15) max_barcode_mismatch --------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(15) = 1
data.set_params("max_barcode_mismatch") = 1
----------------------------------------------------------------------
""", "Max number of allowable mismatches in barcodes")
),
("16", ("""
(16) filter_adapters ----------------------------------------------
Examples:
-------------------------------------------------------------------
data.set_params(16) = 1
data.set_params("filter_adapters") = 1
-------------------------------------------------------------------
""", "Filter for adapters/primers (1 or 2=stricter)")
),
("17", ("""
(17) filter_min_trim_len ---------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(17) = 1
data.set_params("filter_min_trim_len") = 1
----------------------------------------------------------------------
""", "Min length of reads after adapter trim")
),
("18", ("""
(18) max_alleles_consens ---------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(18) = 1
data.set_params("max_alleles_consens") = 1
----------------------------------------------------------------------
""", "Max alleles per site in consensus sequences")
),
("19", ("""
(19) max_Ns_consens --------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(19) = 1
data.set_params("max_Ns_consens") = 1
----------------------------------------------------------------------
""", "Max N's (uncalled bases) in consensus")
),
("20", ("""
(20) max_Hs_consens --------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(20) = 1
data.set_params("max_Hs_consens") = 1
----------------------------------------------------------------------
""", "Max Hs (heterozygotes) in consensus")
),
("21", ("""
(21) min_samples_locus -----------------------------------------------
Minimum number of samples a locus must be shared across to be included
in the exported data set following filtering for sequencing depth,
paralogs, ...
Examples
----------------------------------------------------------------------
data.set_params(21) = 4 ## min 4; most inclusive phylo data
data.set_params(21) = 20 ## min 20; less data, less missing
data.set_params(21) = 1 ## min 1; most data, most missing
data.set_params("min_samples_locus") = 4 ## verbose
----------------------------------------------------------------------
""", "Min # samples per locus for output")
),
("22", ("""
(22) max_SNPs_locus --------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(22) = 1
data.set_params("max_SNPs_locus") = 1
----------------------------------------------------------------------
""", "Max # SNPs per locus")
),
("23", ("""
(23) max_Indels_locus ------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params(23) = 1
data.set_params("max_Indels_locus") = 1
----------------------------------------------------------------------
""", "Max # of indels per locus")
),
("24", ("""
(24) max_shared_Hs_locus ---------------------------------------------
...
----------------------------------------------------------------------
data.set_params(24) = .25 ## set as proportion of samples
data.set_params(24) = 4 ## set as number of samples
data.set_params(24) = 9999 ## set arbitrarily high
data.set_params("max_shared_Hs_locus") = 4 ## verbose
----------------------------------------------------------------------
""", "Max # heterozygous sites per locus")
),
("25", ("""
(25) trim_reads -- ---------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params("trim_reads") = (0, -5, 0, 0) ## trims last 5 from R1
data.set_params("trim_reads") = (5, 85, 0, 0) ## trims R1 from 5-85
data.set_params("trim_reads") = (5, 85, 5, 85) ## trims both pairs 5-85
----------------------------------------------------------------------
""", "Trim raw read edges (R1>, <R1, R2>, <R2) (see docs)")
),
("26", ("""
(26) trim_loci -------------------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params("trim_loci") = (0, 5, 5, 0)
----------------------------------------------------------------------
""", "Trim locus edges (see docs) (R1>, <R1, R2>, <R2)")
),
("27", ("""
(27) output_formats --------------------------------------------------
Examples:
----------------------------------------------------------------------
* ## [27] output_formats: * means all formats
vcf, phy, nex ## [27] list subset of formats if you want
----------------------------------------------------------------------
""", "Output formats (see docs)")
),
("28", ("""
(28) pop_assign_file -------------------------------------------------
Examples:
----------------------------------------------------------------------
./popfile.txt ## [28] pop_assign_file
/home/users/Documents/popfile.txt ## [28] pop_assign_file
----------------------------------------------------------------------
""", "Path to population assignment file")
),
("29", ("""
(29) reference_as_filter ---------------------------------------------
Examples:
----------------------------------------------------------------------
data.set_params("reference_as_filter") = ./data/reference.fa ## verbose
----------------------------------------------------------------------
""", "Reads mapped to this reference are removed in step 3")
),
])
def paramname(param=""):
""" Get the param name from the dict index value.
"""
try:
name = pinfo[str(param)][0].strip().split(" ")[1]
except (KeyError, ValueError) as err:
## TODO: paramsinfo get description by param string not working.
## It would be cool to have an assembly object bcz then you could
## just do this:
##
## print(pinfo[data.paramsinfo.keys().index(param)])
print("\tKey name/number not recognized - ".format(param), err)
raise
return name
def paraminfo(param="", short=False):
""" Returns detailed information for the numbered parameter.
Further information is available in the tutorial.
Unlike params() this function doesn't deal well with *
It only takes one parameter at a time and returns the desc
"""
## If the short flag is set return the short description, otherwise
## return the long.
if short:
desc = 1
else:
desc = 0
try:
description = pinfo[str(param)][desc]
except (KeyError, ValueError) as err:
## TODO: paramsinfo get description by param string not working.
## It would be cool to have an assembly object bcz then you could
## just do this:
##
## print(pinfo[data.paramsinfo.keys().index(param)])
print("\tKey name/number not recognized - ".format(param), err)
raise
return description
def paramsinfo(param="", short=False):
""" This is the human readable version of the paramsinfo() function.
You give it a param and it prints to stdout.
"""
if short:
desc = 1
else:
desc = 0
if param == "*":
for key in pinfo:
print(pinfo[str(key)][desc])
elif param:
try:
print(pinfo[str(param)][desc])
except (KeyError, ValueError) as err:
## TODO: paramsinfo get description by param string not working.
## It would be cool to have an assembly object bcz then you could
## just do this:
##
## print(pinfo[data.paramsinfo.keys().index(param)])
print("\tKey name/number not recognized", err)
raise
else:
print("Enter a name or number for explanation of the parameter\n")
for key in pinfo:
print(pinfo[str(key)][desc].split("\n")[1][2:-10])
if __name__ == "__main__":
pass
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1432,
17531,
436,
1511,
367,
1924,
2725,
14,
5591,
3384,
14,
362,
63,
1162,
63,
815,
8,
17,
9,
503,
3384,
14,
362,
63,
1162,
63,
815,
480,
1715,
63,
694,
531,
5591,
372,
314,
2011,
754,
14,
982,
440,
1423,
12,
282,
6212,
402,
314,
2808,
272,
2633,
436,
3932,
1967,
18897,
6941,
365,
2138,
14,
5591,
12009,
2256,
365,
5489,
465,
282,
1211,
402,
6346,
14,
7048,
2008,
18581,
402,
282,
272,
3974,
436,
282,
1846,
18618,
322,
494,
367,
1924,
2725,
14,
4885,
849,
340,
1265,
465,
272,
367,
282,
2725,
1265,
7171,
664,
314,
1846,
1369,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
8773,
421,
199,
80,
815,
275,
8773,
779,
199,
480,
16,
401,
334,
624,
272,
334,
16,
9,
24869,
63,
354,
9527,
375,
272,
961,
365,
314,
536,
402,
2195,
24869,
14,
2779,
911,
506,
314,
2403,
367,
1006,
5591,
6602,
6272,
314,
2199,
2082,
14,
1626,
8837,
849,
367,
642,
272,
2725,
365,
314,
536,
402,
2195,
2199,
2082,
14,
2104,
2893,
340,
2195,
272,
2199,
2082,
365,
16605,
7510,
13,
67,
1143,
561,
12,
2066,
2195,
24869,
536,
4293,
506,
272,
10424,
13,
67,
1143,
561,
14,
3709,
9621,
536,
365,
1750,
2952,
1265,
5594,
2934,
370,
272,
14926,
465,
8946,
6528,
4453,
282,
2199,
370,
862,
3365,
7858,
543,
3365,
272,
7481,
11745,
1338,
12,
3365,
11106,
402,
31043,
478,
4370,
12,
5423,
14,
272,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
360,
17828,
63,
354,
297,
298,
7510,
13,
67,
1143,
561,
531,
258,
925,
3376,
272,
20359,
272,
10327,
298,
16489,
536,
14,
8051,
370,
536,
1072,
6602,
367,
24869,
7124,
531,
199,
395,
199,
480,
17,
401,
334,
624,
272,
334,
17,
9,
2199,
63,
694,
9527,
8648,
272,
7290,
536,
1182,
931,
367,
6449,
2082,
2382,
1006,
666,
1584,
911,
506,
5591,
6290,
14,
961,
2725,
29476,
1006,
7124,
402,
24869,
334,
17,
13,
23,
680,
5591,
6058,
26,
5591,
20359,
272,
666,
14,
409,
63,
1162,
360,
1715,
63,
694,
297,
3680,
13589,
463,
925,
3376,
272,
20359,
272,
10327,
298,
4761,
2935,
334,
29519,
315,
1094,
694,
340,
440,
3451,
6320,
199,
395,
199,
199,
480,
18,
401,
334,
624,
272,
334,
18,
9,
3066,
63,
26423,
63,
515,
9527,
2595,
272,
710,
2082,
503,
1584,
334,
5511,
543,
627,
16792,
9759,
9,
315,
1314,
5591,
481,
11307,
49,
666,
1584,
295,
2441,
14,
16920,
883,
506,
11756,
1915,
14,
961,
2725,
29476,
5591,
1454,
3650,
413,
402,
24869,
14,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
1773,
63,
26423,
63,
515,
401,
298,
1773,
20362,
26423,
14,
6838,
531,
257,
925,
3376,
5591,
20359,
272,
10327,
298,
6592,
402,
3066,
2222,
13,
271,
6048,
7887,
7377,
81,
1584,
531,
199,
395,
199,
199,
480,
19,
401,
334,
624,
272,
334,
19,
9,
4681,
6021,
63,
515,
9527,
375,
272,
6912,
370,
314,
4681,
6021,
570,
1202,
315,
3650,
413,
402,
24869,
367,
5591,
477,
6048,
88,
316,
14,
982,
666,
787,
2575,
477,
6048,
7887,
642,
883,
506,
3602,
5591,
4596,
14,
961,
2725,
29476,
1454,
3650,
413,
402,
24869,
14,
25377,
26,
284,
2713,
9525,
272,
883,
1454,
2429,
1373,
4681,
6021,
570,
737,
282,
900,
12,
880,
340,
1265,
1172,
3663,
272,
4681,
6021,
1584,
436,
3663,
3066,
1584,
2066,
1265,
7171,
1929,
370,
1255,
1924,
272,
18159,
14,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
1700,
6021,
63,
515,
401,
26069,
1700,
6021,
14,
2424,
531,
259,
925,
3376,
272,
20359,
272,
10327,
298,
6592,
402,
4681,
6021,
570,
531,
199,
395,
199,
199,
480,
20,
401,
334,
624,
272,
334,
20,
9,
3355,
63,
26423,
63,
515,
9527,
272,
6912,
370,
477,
6048,
7887,
7377,
81,
666,
14,
982,
3602,
4596,
12,
642,
365,
7943,
272,
5847,
370,
665,
576,
14,
354,
30,
63,
26423,
15,
4453,
314,
6449,
2082,
14,
982,
2195,
272,
666,
787,
2575,
477,
6048,
7887,
2066,
1265,
1471,
9509,
314,
2909,
402,
2195,
23855,
666,
2348,
14,
644,
10210,
9759,
83,
883,
506,
1202,
370,
3504,
282,
1007,
3271,
402,
1584,
5591,
4453,
282,
2082,
12,
587,
1006,
1584,
787,
4895,
315,
314,
2082,
14,
272,
961,
2725,
29476,
1454,
3650,
499,
402,
24869,
14,
5591,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
5917,
63,
26423,
63,
515,
401,
298,
576,
20362,
6838,
531,
258,
925,
5591,
20359,
272,
10327,
298,
6592,
402,
477,
6048,
7887,
15,
5917,
7377,
81,
1584,
531,
199,
395,
199,
199,
480,
21,
401,
334,
624,
272,
334,
21,
9,
24869,
63,
765,
23271,
272,
437,
1059,
9176,
314,
6387,
24869,
1083,
14,
6006,
787,
11648,
5591,
2808,
1511,
367,
24869,
1083,
26,
1779,
477,
889,
2392,
446,
257,
25187,
31445,
24869,
365,
314,
31205,
1134,
9525,
1083,
12,
436,
1993,
652,
365,
314,
665,
885,
30,
7444,
4257,
2013,
14,
1993,
25187,
31445,
911,
4350,
436,
6998,
1006,
11597,
687,
28975,
267,
3659,
446,
257,
10944,
24869,
911,
2341,
436,
6998,
11597,
370,
314,
1993,
2741,
3659,
3414,
12,
1314,
1471,
506,
2013,
1993,
315,
2725,
7294,
334,
4443,
63,
4041,
680,
23052,
10618,
13,
1993,
655,
301,
24869,
911,
7978,
734,
1006,
625,
11663,
11597,
12,
221,
1993,
1314,
4293,
506,
282,
16474,
24382,
10298,
1993,
641,
314,
6033,
3382,
2195,
3659,
436,
25932,
1993,
20340,
17374,
1362,
20359,
272,
666,
14,
409,
63,
1162,
480,
17828,
63,
765,
401,
298,
848,
31445,
531,
257,
925,
3376,
272,
20359,
5591,
10327,
298,
16489,
1083,
334,
848,
31445,
12,
3659,
6320,
199,
395,
199,
199,
480,
22,
401,
334,
624,
272,
334,
22,
9,
3659,
63,
4041,
11016,
18964,
272,
710,
931,
370,
314,
3659,
3414,
1265,
477,
338,
264,
370,
2341,
2195,
11597,
370,
14,
272,
710,
3659,
1443,
506,
1902,
30544,
503,
11756,
1915,
30544,
14,
2779,
1077,
506,
282,
5591,
4890,
3659,
3414,
12,
5893,
1006,
20074,
26803,
83,
12,
12328,
556,
8250,
12,
436,
272,
406,
280,
458,
315,
1373,
27791,
570,
334,
2786
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
1432,
17531,
436,
1511,
367,
1924,
2725,
14,
5591,
3384,
14,
362,
63,
1162,
63,
815,
8,
17,
9,
503,
3384,
14,
362,
63,
1162,
63,
815,
480,
1715,
63,
694,
531,
5591,
372,
314,
2011,
754,
14,
982,
440,
1423,
12,
282,
6212,
402,
314,
2808,
272,
2633,
436,
3932,
1967,
18897,
6941,
365,
2138,
14,
5591,
12009,
2256,
365,
5489,
465,
282,
1211,
402,
6346,
14,
7048,
2008,
18581,
402,
282,
272,
3974,
436,
282,
1846,
18618,
322,
494,
367,
1924,
2725,
14,
4885,
849,
340,
1265,
465,
272,
367,
282,
2725,
1265,
7171,
664,
314,
1846,
1369,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
8773,
421,
199,
80,
815,
275,
8773,
779,
199,
480,
16,
401,
334,
624,
272,
334,
16,
9,
24869,
63,
354,
9527,
375,
272,
961,
365,
314,
536,
402,
2195,
24869,
14,
2779,
911,
506,
314,
2403,
367,
1006,
5591,
6602,
6272,
314,
2199,
2082,
14,
1626,
8837,
849,
367,
642,
272,
2725,
365,
314,
536,
402,
2195,
2199,
2082,
14,
2104,
2893,
340,
2195,
272,
2199,
2082,
365,
16605,
7510,
13,
67,
1143,
561,
12,
2066,
2195,
24869,
536,
4293,
506,
272,
10424,
13,
67,
1143,
561,
14,
3709,
9621,
536,
365,
1750,
2952,
1265,
5594,
2934,
370,
272,
14926,
465,
8946,
6528,
4453,
282,
2199,
370,
862,
3365,
7858,
543,
3365,
272,
7481,
11745,
1338,
12,
3365,
11106,
402,
31043,
478,
4370,
12,
5423,
14,
272,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
360,
17828,
63,
354,
297,
298,
7510,
13,
67,
1143,
561,
531,
258,
925,
3376,
272,
20359,
272,
10327,
298,
16489,
536,
14,
8051,
370,
536,
1072,
6602,
367,
24869,
7124,
531,
199,
395,
199,
480,
17,
401,
334,
624,
272,
334,
17,
9,
2199,
63,
694,
9527,
8648,
272,
7290,
536,
1182,
931,
367,
6449,
2082,
2382,
1006,
666,
1584,
911,
506,
5591,
6290,
14,
961,
2725,
29476,
1006,
7124,
402,
24869,
334,
17,
13,
23,
680,
5591,
6058,
26,
5591,
20359,
272,
666,
14,
409,
63,
1162,
360,
1715,
63,
694,
297,
3680,
13589,
463,
925,
3376,
272,
20359,
272,
10327,
298,
4761,
2935,
334,
29519,
315,
1094,
694,
340,
440,
3451,
6320,
199,
395,
199,
199,
480,
18,
401,
334,
624,
272,
334,
18,
9,
3066,
63,
26423,
63,
515,
9527,
2595,
272,
710,
2082,
503,
1584,
334,
5511,
543,
627,
16792,
9759,
9,
315,
1314,
5591,
481,
11307,
49,
666,
1584,
295,
2441,
14,
16920,
883,
506,
11756,
1915,
14,
961,
2725,
29476,
5591,
1454,
3650,
413,
402,
24869,
14,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
1773,
63,
26423,
63,
515,
401,
298,
1773,
20362,
26423,
14,
6838,
531,
257,
925,
3376,
5591,
20359,
272,
10327,
298,
6592,
402,
3066,
2222,
13,
271,
6048,
7887,
7377,
81,
1584,
531,
199,
395,
199,
199,
480,
19,
401,
334,
624,
272,
334,
19,
9,
4681,
6021,
63,
515,
9527,
375,
272,
6912,
370,
314,
4681,
6021,
570,
1202,
315,
3650,
413,
402,
24869,
367,
5591,
477,
6048,
88,
316,
14,
982,
666,
787,
2575,
477,
6048,
7887,
642,
883,
506,
3602,
5591,
4596,
14,
961,
2725,
29476,
1454,
3650,
413,
402,
24869,
14,
25377,
26,
284,
2713,
9525,
272,
883,
1454,
2429,
1373,
4681,
6021,
570,
737,
282,
900,
12,
880,
340,
1265,
1172,
3663,
272,
4681,
6021,
1584,
436,
3663,
3066,
1584,
2066,
1265,
7171,
1929,
370,
1255,
1924,
272,
18159,
14,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
1700,
6021,
63,
515,
401,
26069,
1700,
6021,
14,
2424,
531,
259,
925,
3376,
272,
20359,
272,
10327,
298,
6592,
402,
4681,
6021,
570,
531,
199,
395,
199,
199,
480,
20,
401,
334,
624,
272,
334,
20,
9,
3355,
63,
26423,
63,
515,
9527,
272,
6912,
370,
477,
6048,
7887,
7377,
81,
666,
14,
982,
3602,
4596,
12,
642,
365,
7943,
272,
5847,
370,
665,
576,
14,
354,
30,
63,
26423,
15,
4453,
314,
6449,
2082,
14,
982,
2195,
272,
666,
787,
2575,
477,
6048,
7887,
2066,
1265,
1471,
9509,
314,
2909,
402,
2195,
23855,
666,
2348,
14,
644,
10210,
9759,
83,
883,
506,
1202,
370,
3504,
282,
1007,
3271,
402,
1584,
5591,
4453,
282,
2082,
12,
587,
1006,
1584,
787,
4895,
315,
314,
2082,
14,
272,
961,
2725,
29476,
1454,
3650,
499,
402,
24869,
14,
5591,
6058,
26,
272,
20359,
272,
666,
14,
409,
63,
1162,
480,
5917,
63,
26423,
63,
515,
401,
298,
576,
20362,
6838,
531,
258,
925,
5591,
20359,
272,
10327,
298,
6592,
402,
477,
6048,
7887,
15,
5917,
7377,
81,
1584,
531,
199,
395,
199,
199,
480,
21,
401,
334,
624,
272,
334,
21,
9,
24869,
63,
765,
23271,
272,
437,
1059,
9176,
314,
6387,
24869,
1083,
14,
6006,
787,
11648,
5591,
2808,
1511,
367,
24869,
1083,
26,
1779,
477,
889,
2392,
446,
257,
25187,
31445,
24869,
365,
314,
31205,
1134,
9525,
1083,
12,
436,
1993,
652,
365,
314,
665,
885,
30,
7444,
4257,
2013,
14,
1993,
25187,
31445,
911,
4350,
436,
6998,
1006,
11597,
687,
28975,
267,
3659,
446,
257,
10944,
24869,
911,
2341,
436,
6998,
11597,
370,
314,
1993,
2741,
3659,
3414,
12,
1314,
1471,
506,
2013,
1993,
315,
2725,
7294,
334,
4443,
63,
4041,
680,
23052,
10618,
13,
1993,
655,
301,
24869,
911,
7978,
734,
1006,
625,
11663,
11597,
12,
221,
1993,
1314,
4293,
506,
282,
16474,
24382,
10298,
1993,
641,
314,
6033,
3382,
2195,
3659,
436,
25932,
1993,
20340,
17374,
1362,
20359,
272,
666,
14,
409,
63,
1162,
480,
17828,
63,
765,
401,
298,
848,
31445,
531,
257,
925,
3376,
272,
20359,
5591,
10327,
298,
16489,
1083,
334,
848,
31445,
12,
3659,
6320,
199,
395,
199,
199,
480,
22,
401,
334,
624,
272,
334,
22,
9,
3659,
63,
4041,
11016,
18964,
272,
710,
931,
370,
314,
3659,
3414,
1265,
477,
338,
264,
370,
2341,
2195,
11597,
370,
14,
272,
710,
3659,
1443,
506,
1902,
30544,
503,
11756,
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
] |
pshchelo/heat
|
heat/engine/resources/stack_resource.py
|
1
|
20765
|
#
# 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 hashlib
import json
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import excutils
import six
from heat.common import exception
from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.common import identifier
from heat.common import template_format
from heat.engine import attributes
from heat.engine import environment
from heat.engine import resource
from heat.engine import scheduler
from heat.engine import stack as parser
from heat.engine import template
from heat.rpc import api as rpc_api
LOG = logging.getLogger(__name__)
class StackResource(resource.Resource):
'''
An abstract Resource subclass that allows the management of an entire Stack
as a resource in a parent stack.
'''
# Assume True as this is evaluated before the stack is created
# so there is no way to know for sure without subclass-specific
# template parsing.
requires_deferred_auth = True
def __init__(self, name, json_snippet, stack):
super(StackResource, self).__init__(name, json_snippet, stack)
self._nested = None
self.resource_info = None
def validate(self):
super(StackResource, self).validate()
self.validate_nested_stack()
def validate_nested_stack(self):
try:
name = "%s-%s" % (self.stack.name, self.name)
nested_stack = self._parse_nested_stack(
name,
self.child_template(),
self.child_params())
nested_stack.strict_validate = False
nested_stack.validate()
except AssertionError:
raise
except Exception as ex:
raise exception.StackValidationFailed(
error=_("Failed to validate"),
path=[self.stack.t.get_section_name('resources'), self.name],
message=six.text_type(ex))
def _outputs_to_attribs(self, json_snippet):
outputs = json_snippet.get('Outputs')
if not self.attributes and outputs:
self.attributes_schema = (
attributes.Attributes.schema_from_outputs(outputs))
self.attributes = attributes.Attributes(self.name,
self.attributes_schema,
self._resolve_attribute)
def _needs_update(self, after, before, after_props, before_props,
prev_resource):
# Always issue an update to the nested stack and let the individual
# resources in it decide if they need updating.
return True
@scheduler.wrappertask
def update(self, after, before=None, prev_resource=None):
try:
yield super(StackResource, self).update(after, before,
prev_resource)
except StopIteration:
with excutils.save_and_reraise_exception():
stack_identity = identifier.HeatIdentifier(
self.context.tenant_id,
self.physical_resource_name(),
self.resource_id)
self.rpc_client().stack_cancel_update(self.context,
stack_identity)
def nested(self, force_reload=False, show_deleted=False):
'''Return a Stack object representing the nested (child) stack.
:param force_reload: Forces reloading from the DB instead of returning
the locally cached Stack object
:param show_deleted: Returns the stack even if it's been deleted
'''
if force_reload:
self._nested = None
if self._nested is None and self.resource_id is not None:
self._nested = parser.Stack.load(self.context,
self.resource_id,
show_deleted=show_deleted,
force_reload=force_reload)
if self._nested is None:
raise exception.NotFound(_("Nested stack not found in DB"))
return self._nested
def child_template(self):
'''
Default implementation to get the child template.
Resources that inherit from StackResource should override this method
with specific details about the template used by them.
'''
raise NotImplementedError()
def child_params(self):
'''
Default implementation to get the child params.
Resources that inherit from StackResource should override this method
with specific details about the parameters used by them.
'''
raise NotImplementedError()
def preview(self):
'''
Preview a StackResource as resources within a Stack.
This method overrides the original Resource.preview to return a preview
of all the resources contained in this Stack. For this to be possible,
the specific resources need to override both ``child_template`` and
``child_params`` with specific information to allow the stack to be
parsed correctly. If any of these methods is missing, the entire
StackResource will be returned as if it were a regular Resource.
'''
try:
child_template = self.child_template()
params = self.child_params()
except NotImplementedError:
LOG.warn(_LW("Preview of '%s' not yet implemented"),
self.__class__.__name__)
return self
name = "%s-%s" % (self.stack.name, self.name)
self._nested = self._parse_nested_stack(name, child_template, params)
return self.nested().preview_resources()
def _parse_child_template(self, child_template, child_env):
parsed_child_template = child_template
if isinstance(parsed_child_template, template.Template):
parsed_child_template = parsed_child_template.t
return template.Template(parsed_child_template,
files=self.stack.t.files, env=child_env)
def _parse_nested_stack(self, stack_name, child_template,
child_params, timeout_mins=None,
adopt_data=None):
if timeout_mins is None:
timeout_mins = self.stack.timeout_mins
stack_user_project_id = self.stack.stack_user_project_id
new_nested_depth = self._child_nested_depth()
child_env = environment.get_child_environment(
self.stack.env, child_params,
child_resource_name=self.name,
item_to_remove=self.resource_info)
parsed_template = self._child_parsed_template(child_template,
child_env)
# Note we disable rollback for nested stacks, since they
# should be rolled back by the parent stack on failure
nested = parser.Stack(self.context,
stack_name,
parsed_template,
timeout_mins=timeout_mins,
disable_rollback=True,
parent_resource=self.name,
owner_id=self.stack.id,
user_creds_id=self.stack.user_creds_id,
stack_user_project_id=stack_user_project_id,
adopt_stack_data=adopt_data,
nested_depth=new_nested_depth)
return nested
def _child_nested_depth(self):
if self.stack.nested_depth >= cfg.CONF.max_nested_stack_depth:
msg = _("Recursion depth exceeds %d."
) % cfg.CONF.max_nested_stack_depth
raise exception.RequestLimitExceeded(message=msg)
return self.stack.nested_depth + 1
def _child_parsed_template(self, child_template, child_env):
parsed_template = self._parse_child_template(child_template, child_env)
self._validate_nested_resources(parsed_template)
# Don't overwrite the attributes_schema for subclasses that
# define their own attributes_schema.
if not hasattr(type(self), 'attributes_schema'):
self.attributes = None
self._outputs_to_attribs(parsed_template)
return parsed_template
def _validate_nested_resources(self, templ):
total_resources = (len(templ[templ.RESOURCES]) +
self.stack.root_stack.total_resources())
if self.nested():
# It's an update and these resources will be deleted
total_resources -= len(self.nested().resources)
if (total_resources > cfg.CONF.max_resources_per_stack):
message = exception.StackResourceLimitExceeded.msg_fmt
raise exception.RequestLimitExceeded(message=message)
def create_with_template(self, child_template, user_params=None,
timeout_mins=None, adopt_data=None):
"""Create the nested stack with the given template."""
name = self.physical_resource_name()
if timeout_mins is None:
timeout_mins = self.stack.timeout_mins
stack_user_project_id = self.stack.stack_user_project_id
if user_params is None:
user_params = self.child_params()
child_env = environment.get_child_environment(
self.stack.env,
user_params,
child_resource_name=self.name,
item_to_remove=self.resource_info)
new_nested_depth = self._child_nested_depth()
parsed_template = self._child_parsed_template(child_template,
child_env)
adopt_data_str = None
if adopt_data is not None:
if 'environment' not in adopt_data:
adopt_data['environment'] = child_env.user_env_as_dict()
if 'template' not in adopt_data:
adopt_data['template'] = child_template
adopt_data_str = json.dumps(adopt_data)
args = {rpc_api.PARAM_TIMEOUT: timeout_mins,
rpc_api.PARAM_DISABLE_ROLLBACK: True,
rpc_api.PARAM_ADOPT_STACK_DATA: adopt_data_str}
try:
result = self.rpc_client()._create_stack(
self.context,
name,
parsed_template.t,
child_env.user_env_as_dict(),
parsed_template.files,
args,
owner_id=self.stack.id,
user_creds_id=self.stack.user_creds_id,
stack_user_project_id=stack_user_project_id,
nested_depth=new_nested_depth,
parent_resource_name=self.name)
except Exception as ex:
self.raise_local_exception(ex)
self.resource_id_set(result['stack_id'])
def raise_local_exception(self, ex):
ex_type = ex.__class__.__name__
is_remote = ex_type.endswith('_Remote')
if is_remote:
ex_type = ex_type[:-len('_Remote')]
full_message = six.text_type(ex)
if full_message.find('\n') > -1 and is_remote:
message, msg_trace = full_message.split('\n', 1)
else:
message = full_message
if (isinstance(ex, exception.ActionInProgress) and
self.stack.action == self.stack.ROLLBACK):
# The update was interrupted and the rollback is already in
# progress, so just ignore the error and wait for the rollback to
# finish
return
if isinstance(ex, exception.HeatException):
message = ex.message
local_ex = copy.copy(getattr(exception, ex_type))
local_ex.msg_fmt = "%(message)s"
raise local_ex(message=message)
def check_create_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.CREATE)
def _check_status_complete(self, action, show_deleted=False,
cookie=None):
try:
nested = self.nested(force_reload=True, show_deleted=show_deleted)
except exception.NotFound:
if action == resource.Resource.DELETE:
return True
# It's possible the engine handling the create hasn't persisted
# the stack to the DB when we first start polling for state
return False
if nested is None:
return True
if nested.action != action:
return False
# Has the action really started?
#
# The rpc call to update does not guarantee that the stack will be
# placed into IN_PROGRESS by the time it returns (it runs stack.update
# in a thread) so you could also have a situation where we get into
# this method and the update hasn't even started.
#
# So we are using a mixture of state (action+status) and updated_at
# to see if the action has actually progressed.
# - very fast updates (like something with one RandomString) we will
# probably miss the state change, but we should catch the updated_at.
# - very slow updates we won't see the updated_at for quite a while,
# but should see the state change.
if cookie is not None:
prev_state = cookie['previous']['state']
prev_updated_at = cookie['previous']['updated_at']
if (prev_updated_at == nested.updated_time and
prev_state == nested.state):
return False
if nested.status == resource.Resource.IN_PROGRESS:
return False
elif nested.status == resource.Resource.COMPLETE:
return True
elif nested.status == resource.Resource.FAILED:
raise resource.ResourceUnknownStatus(
resource_status=nested.status,
status_reason=nested.status_reason)
else:
raise resource.ResourceUnknownStatus(
resource_status=nested.status,
result=_('Stack unknown status'))
def check_adopt_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.ADOPT)
def update_with_template(self, child_template, user_params=None,
timeout_mins=None):
"""Update the nested stack with the new template."""
if self.id is None:
self._store()
nested_stack = self.nested()
if nested_stack is None:
# if the create failed for some reason and the nested
# stack was not created, we need to create an empty stack
# here so that the update will work.
def _check_for_completion(creator_fn):
while not self.check_create_complete(creator_fn):
yield
empty_temp = template_format.parse(
"heat_template_version: '2013-05-23'")
stack_creator = self.create_with_template(empty_temp, {})
checker = scheduler.TaskRunner(_check_for_completion,
stack_creator)
checker(timeout=self.stack.timeout_secs())
if stack_creator is not None:
stack_creator.run_to_completion()
nested_stack = self.nested()
if timeout_mins is None:
timeout_mins = self.stack.timeout_mins
if user_params is None:
user_params = self.child_params()
child_env = environment.get_child_environment(
self.stack.env,
user_params,
child_resource_name=self.name,
item_to_remove=self.resource_info)
parsed_template = self._child_parsed_template(child_template,
child_env)
cookie = {'previous': {
'updated_at': nested_stack.updated_time,
'state': nested_stack.state}}
args = {rpc_api.PARAM_TIMEOUT: timeout_mins}
try:
self.rpc_client().update_stack(
self.context,
nested_stack.identifier(),
parsed_template.t,
child_env.user_env_as_dict(),
parsed_template.files,
args)
except Exception as ex:
LOG.exception('update_stack')
self.raise_local_exception(ex)
return cookie
def check_update_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.UPDATE,
cookie=cookie)
def delete_nested(self):
'''
Delete the nested stack.
'''
stack_identity = identifier.HeatIdentifier(
self.context.tenant_id,
self.physical_resource_name(),
self.resource_id)
try:
self.rpc_client().delete_stack(self.context, stack_identity)
except Exception as ex:
self.rpc_client().ignore_error_named(ex, 'NotFound')
def check_delete_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.DELETE,
show_deleted=True)
def handle_suspend(self):
stack = self.nested()
if stack is None:
raise exception.Error(_('Cannot suspend %s, stack not created')
% self.name)
stack_identity = identifier.HeatIdentifier(
self.context.tenant_id,
self.physical_resource_name(),
self.resource_id)
self.rpc_client().stack_suspend(self.context, stack_identity)
def check_suspend_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.SUSPEND)
def handle_resume(self):
stack = self.nested()
if stack is None:
raise exception.Error(_('Cannot resume %s, stack not created')
% self.name)
stack_identity = identifier.HeatIdentifier(
self.context.tenant_id,
self.physical_resource_name(),
self.resource_id)
self.rpc_client().stack_resume(self.context, stack_identity)
def check_resume_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.RESUME)
def handle_check(self):
stack = self.nested()
if stack is None:
raise exception.Error(_('Cannot check %s, stack not created')
% self.name)
stack_identity = identifier.HeatIdentifier(
self.context.tenant_id,
self.physical_resource_name(),
self.resource_id)
self.rpc_client().stack_check(self.context, stack_identity)
def check_check_complete(self, cookie=None):
return self._check_status_complete(resource.Resource.CHECK)
def prepare_abandon(self):
return self.nested().prepare_abandon()
def get_output(self, op):
'''
Return the specified Output value from the nested stack.
If the output key does not exist, raise an InvalidTemplateAttribute
exception.
'''
stack = self.nested()
if stack is None:
return None
if op not in stack.outputs:
raise exception.InvalidTemplateAttribute(resource=self.name,
key=op)
return stack.output(op)
def _resolve_attribute(self, name):
return self.get_output(name)
def implementation_signature(self):
schema_names = ([prop for prop in self.properties_schema] +
[at for at in self.attributes_schema])
schema_hash = hashlib.sha256(';'.join(schema_names))
definition = {'template': self.child_template(),
'files': self.stack.t.files}
definition_hash = hashlib.sha256(jsonutils.dumps(definition))
return (schema_hash.hexdigest(), definition_hash.hexdigest())
|
apache-2.0
|
[
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,
1331,
199,
646,
8337,
199,
646,
2022,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
11258,
63,
1208,
492,
32763,
199,
646,
3816,
199,
199,
504,
20408,
14,
2330,
492,
1919,
199,
504,
20408,
14,
2330,
14,
73,
1085,
78,
492,
485,
199,
504,
20408,
14,
2330,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
20408,
14,
2330,
492,
5148,
199,
504,
20408,
14,
2330,
492,
1978,
63,
908,
199,
504,
20408,
14,
3908,
492,
3004,
199,
504,
20408,
14,
3908,
492,
3734,
199,
504,
20408,
14,
3908,
492,
2073,
199,
504,
20408,
14,
3908,
492,
11899,
199,
504,
20408,
14,
3908,
492,
3464,
465,
1798,
199,
504,
20408,
14,
3908,
492,
1978,
199,
504,
20408,
14,
4354,
492,
2986,
465,
8985,
63,
1246,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
13894,
4031,
8,
1927,
14,
4031,
304,
272,
1449,
272,
1626,
9006,
7337,
5516,
626,
6127,
314,
10041,
402,
376,
8039,
13894,
272,
465,
282,
2073,
315,
282,
1676,
3464,
14,
272,
1449,
339,
327,
16269,
715,
465,
642,
365,
13006,
2544,
314,
3464,
365,
2737,
272,
327,
880,
2337,
365,
949,
4340,
370,
5715,
367,
3238,
1928,
5516,
13,
6100,
272,
327,
1978,
6057,
14,
272,
5074,
63,
12116,
63,
1178,
275,
715,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2022,
63,
18547,
12,
3464,
304,
267,
1613,
8,
4851,
4031,
12,
291,
2843,
826,
721,
354,
12,
2022,
63,
18547,
12,
3464,
9,
267,
291,
423,
6376,
275,
488,
267,
291,
14,
1927,
63,
815,
275,
488,
339,
347,
4107,
8,
277,
304,
267,
1613,
8,
4851,
4031,
12,
291,
680,
3502,
342,
267,
291,
14,
3502,
63,
6376,
63,
2340,
342,
339,
347,
4107,
63,
6376,
63,
2340,
8,
277,
304,
267,
862,
26,
288,
536,
275,
2071,
83,
3295,
83,
2,
450,
334,
277,
14,
2340,
14,
354,
12,
291,
14,
354,
9,
288,
6032,
63,
2340,
275,
291,
423,
1122,
63,
6376,
63,
2340,
8,
355,
536,
12,
355,
291,
14,
1739,
63,
1160,
1062,
355,
291,
14,
1739,
63,
1162,
1012,
288,
6032,
63,
2340,
14,
4768,
63,
3502,
275,
756,
288,
6032,
63,
2340,
14,
3502,
342,
267,
871,
9070,
26,
288,
746,
267,
871,
2186,
465,
444,
26,
288,
746,
1919,
14,
4851,
13816,
4276,
8,
355,
1125,
9384,
4276,
370,
4107,
1288,
355,
931,
1524,
277,
14,
2340,
14,
84,
14,
362,
63,
2792,
63,
354,
360,
4435,
659,
291,
14,
354,
467,
355,
1245,
29,
4174,
14,
505,
63,
466,
8,
476,
430,
339,
347,
485,
4467,
63,
475,
63,
30674,
8,
277,
12,
2022,
63,
18547,
304,
267,
4704,
275,
2022,
63,
18547,
14,
362,
360,
18669,
358,
267,
340,
440,
291,
14,
2987,
436,
4704,
26,
288,
291,
14,
2987,
63,
3629,
275,
334,
355,
3004,
14,
5379,
14,
3629,
63,
504,
63,
4467,
8,
4467,
430,
288,
291,
14,
2987,
275,
3004,
14,
5379,
8,
277,
14,
354,
12,
8105,
291,
14,
2987,
63,
3629,
12,
8105,
291,
423,
6983,
63,
3215,
9,
339,
347,
485,
10065,
63,
873,
8,
277,
12,
2410,
12,
2544,
12,
2410,
63,
6750,
12,
2544,
63,
6750,
12,
1993,
5071,
63,
1927,
304,
267,
327,
16763,
4976,
376,
1678,
370,
314,
6032,
3464,
436,
4691,
314,
8212,
267,
327,
5944,
315,
652,
19822,
340,
2985,
1929,
12928,
14,
267,
372,
715,
339,
768,
8874,
14,
5029,
1765,
272,
347,
1678,
8,
277,
12,
2410,
12,
2544,
29,
403,
12,
5071,
63,
1927,
29,
403,
304,
267,
862,
26,
288,
1995,
1613,
8,
4851,
4031,
12,
291,
680,
873,
8,
4399,
12,
2544,
12,
8105,
5071,
63,
1927,
9,
267,
871,
10852,
26,
288,
543,
32763,
14,
2117,
63,
460,
63,
20614,
63,
1971,
837,
355,
3464,
63,
5582,
275,
5148,
14,
30770,
7544,
8,
490,
291,
14,
1100,
14,
4647,
63,
344,
12,
490,
291,
14,
15020,
63,
1927,
63,
354,
1062,
490,
291,
14,
1927,
63,
344,
9,
355,
291,
14,
4354,
63,
1258,
1252,
2340,
63,
6406,
63,
873,
8,
277,
14,
1100,
12,
10028,
3464,
63,
5582,
9,
339,
347,
6032,
8,
277,
12,
3542,
63,
9233,
29,
797,
12,
2498,
63,
6062,
29,
797,
304,
267,
1449,
1767,
282,
13894,
909,
6144,
314,
6032,
334,
1739,
9,
3464,
14,
398,
520,
635,
3542,
63,
9233,
26,
2104,
823,
295,
8786,
687,
314,
6249,
3140,
402,
8152,
2490,
314,
17738,
6328,
13894,
909,
267,
520,
635,
2498,
63,
6062,
26,
1803,
314,
3464,
2755,
340,
652,
1159,
2757,
5463,
267,
1449,
267,
340,
3542,
63,
9233,
26,
288,
291,
423,
6376,
275,
488,
398,
340,
291,
423,
6376,
365,
488,
436,
291,
14,
1927,
63,
344,
365,
440,
488,
26,
288,
291,
423,
6376,
275,
1798,
14,
4851,
14,
912,
8,
277,
14,
1100,
12,
6163,
291,
14,
1927,
63,
344,
12,
6163,
2498,
63,
6062,
29,
2384,
63,
6062,
12,
6163,
3542,
63,
9233,
29,
3990,
63,
9233,
9,
953,
340,
291,
423,
6376,
365,
488,
26,
355,
746,
1919,
14,
4667,
6115,
13029,
3464,
440,
1911,
315,
6249,
2237,
398,
372,
291,
423,
6376,
339,
347,
1982,
63,
1160,
8,
277,
304,
267,
1449,
267,
3758,
4514,
370,
664,
314,
1982
] |
[
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,
1331,
199,
646,
8337,
199,
646,
2022,
199,
199,
504,
11258,
63,
888,
492,
4810,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
12161,
492,
18705,
199,
504,
11258,
63,
1208,
492,
32763,
199,
646,
3816,
199,
199,
504,
20408,
14,
2330,
492,
1919,
199,
504,
20408,
14,
2330,
14,
73,
1085,
78,
492,
485,
199,
504,
20408,
14,
2330,
14,
73,
1085,
78,
492,
485,
20145,
199,
504,
20408,
14,
2330,
492,
5148,
199,
504,
20408,
14,
2330,
492,
1978,
63,
908,
199,
504,
20408,
14,
3908,
492,
3004,
199,
504,
20408,
14,
3908,
492,
3734,
199,
504,
20408,
14,
3908,
492,
2073,
199,
504,
20408,
14,
3908,
492,
11899,
199,
504,
20408,
14,
3908,
492,
3464,
465,
1798,
199,
504,
20408,
14,
3908,
492,
1978,
199,
504,
20408,
14,
4354,
492,
2986,
465,
8985,
63,
1246,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
13894,
4031,
8,
1927,
14,
4031,
304,
272,
1449,
272,
1626,
9006,
7337,
5516,
626,
6127,
314,
10041,
402,
376,
8039,
13894,
272,
465,
282,
2073,
315,
282,
1676,
3464,
14,
272,
1449,
339,
327,
16269,
715,
465,
642,
365,
13006,
2544,
314,
3464,
365,
2737,
272,
327,
880,
2337,
365,
949,
4340,
370,
5715,
367,
3238,
1928,
5516,
13,
6100,
272,
327,
1978,
6057,
14,
272,
5074,
63,
12116,
63,
1178,
275,
715,
339,
347,
636,
826,
721,
277,
12,
536,
12,
2022,
63,
18547,
12,
3464,
304,
267,
1613,
8,
4851,
4031,
12,
291,
2843,
826,
721,
354,
12,
2022,
63,
18547,
12,
3464,
9,
267,
291,
423,
6376,
275,
488,
267,
291,
14,
1927,
63,
815,
275,
488,
339,
347,
4107,
8,
277,
304,
267,
1613,
8,
4851,
4031,
12,
291,
680,
3502,
342,
267,
291,
14,
3502,
63,
6376,
63,
2340,
342,
339,
347,
4107,
63,
6376,
63,
2340,
8,
277,
304,
267,
862,
26,
288,
536,
275,
2071,
83,
3295,
83,
2,
450,
334,
277,
14,
2340,
14,
354,
12,
291,
14,
354,
9,
288,
6032,
63,
2340,
275,
291,
423,
1122,
63,
6376,
63,
2340,
8,
355,
536,
12,
355,
291,
14,
1739,
63,
1160,
1062,
355,
291,
14,
1739,
63,
1162,
1012,
288,
6032,
63,
2340,
14,
4768,
63,
3502,
275,
756,
288,
6032,
63,
2340,
14,
3502,
342,
267,
871,
9070,
26,
288,
746,
267,
871,
2186,
465,
444,
26,
288,
746,
1919,
14,
4851,
13816,
4276,
8,
355,
1125,
9384,
4276,
370,
4107,
1288,
355,
931,
1524,
277,
14,
2340,
14,
84,
14,
362,
63,
2792,
63,
354,
360,
4435,
659,
291,
14,
354,
467,
355,
1245,
29,
4174,
14,
505,
63,
466,
8,
476,
430,
339,
347,
485,
4467,
63,
475,
63,
30674,
8,
277,
12,
2022,
63,
18547,
304,
267,
4704,
275,
2022,
63,
18547,
14,
362,
360,
18669,
358,
267,
340,
440,
291,
14,
2987,
436,
4704,
26,
288,
291,
14,
2987,
63,
3629,
275,
334,
355,
3004,
14,
5379,
14,
3629,
63,
504,
63,
4467,
8,
4467,
430,
288,
291,
14,
2987,
275,
3004,
14,
5379,
8,
277,
14,
354,
12,
8105,
291,
14,
2987,
63,
3629,
12,
8105,
291,
423,
6983,
63,
3215,
9,
339,
347,
485,
10065,
63,
873,
8,
277,
12,
2410,
12,
2544,
12,
2410,
63,
6750,
12,
2544,
63,
6750,
12,
1993,
5071,
63,
1927,
304,
267,
327,
16763,
4976,
376,
1678,
370,
314,
6032,
3464,
436,
4691,
314,
8212,
267,
327,
5944,
315,
652,
19822,
340,
2985,
1929,
12928,
14,
267,
372,
715,
339,
768,
8874,
14,
5029,
1765,
272,
347,
1678,
8,
277,
12,
2410,
12,
2544,
29,
403,
12,
5071,
63,
1927,
29,
403,
304,
267,
862,
26,
288,
1995,
1613,
8,
4851,
4031,
12,
291,
680,
873,
8,
4399,
12,
2544,
12,
8105,
5071,
63,
1927,
9,
267,
871,
10852,
26,
288,
543,
32763,
14,
2117,
63,
460,
63,
20614,
63,
1971,
837,
355,
3464,
63,
5582,
275,
5148,
14,
30770,
7544,
8,
490,
291,
14,
1100,
14,
4647,
63,
344,
12,
490,
291,
14,
15020,
63,
1927,
63,
354,
1062,
490,
291,
14,
1927,
63,
344,
9,
355,
291,
14,
4354,
63,
1258,
1252,
2340,
63,
6406,
63,
873,
8,
277,
14,
1100,
12,
10028,
3464,
63,
5582,
9,
339,
347,
6032,
8,
277,
12,
3542,
63,
9233,
29,
797,
12,
2498,
63,
6062,
29,
797,
304,
267,
1449,
1767,
282,
13894,
909,
6144,
314,
6032,
334,
1739,
9,
3464,
14,
398,
520,
635,
3542,
63,
9233,
26,
2104,
823,
295,
8786,
687,
314,
6249,
3140,
402,
8152,
2490,
314,
17738,
6328,
13894,
909,
267,
520,
635,
2498,
63,
6062,
26,
1803,
314,
3464,
2755,
340,
652,
1159,
2757,
5463,
267,
1449,
267,
340,
3542,
63,
9233,
26,
288,
291,
423,
6376,
275,
488,
398,
340,
291,
423,
6376,
365,
488,
436,
291,
14,
1927,
63,
344,
365,
440,
488,
26,
288,
291,
423,
6376,
275,
1798,
14,
4851,
14,
912,
8,
277,
14,
1100,
12,
6163,
291,
14,
1927,
63,
344,
12,
6163,
2498,
63,
6062,
29,
2384,
63,
6062,
12,
6163,
3542,
63,
9233,
29,
3990,
63,
9233,
9,
953,
340,
291,
423,
6376,
365,
488,
26,
355,
746,
1919,
14,
4667,
6115,
13029,
3464,
440,
1911,
315,
6249,
2237,
398,
372,
291,
423,
6376,
339,
347,
1982,
63,
1160,
8,
277,
304,
267,
1449,
267,
3758,
4514,
370,
664,
314,
1982,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hds-lab/coding-ml
|
msgvis/apps/enhance/migrations/0002_auto_20160222_0230.py
|
1
|
1306
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('enhance', '0001_initial'),
(b'auth', b'__first__'), # This line and the next line is for fixing the "Lookup failed auth.User" error
(b'contenttypes', b'__first__'),
]
operations = [
migrations.AddField(
model_name='feature',
name='created_at',
field=models.DateTimeField(default=None, auto_now_add=True),
preserve_default=True,
),
migrations.AddField(
model_name='feature',
name='last_updated',
field=models.DateTimeField(default=None, auto_now=True, auto_now_add=True),
preserve_default=True,
),
migrations.AddField(
model_name='feature',
name='valid',
field=models.BooleanField(default=True),
preserve_default=True,
),
migrations.AlterField(
model_name='feature',
name='source',
field=models.ForeignKey(related_name='features', default=None, to=settings.AUTH_USER_MODEL),
preserve_default=True,
),
]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
287,
14666,
297,
283,
4183,
63,
2747,
659,
267,
334,
66,
7,
1178,
297,
330,
31279,
2246,
363,
659,
263,
327,
961,
1004,
436,
314,
2163,
1004,
365,
367,
5325,
316,
314,
298,
7521,
3405,
1790,
14,
1899,
2,
1125,
267,
334,
66,
7,
10778,
297,
330,
31279,
2246,
363,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
3966,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
885,
29,
403,
12,
2599,
63,
2131,
63,
525,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
2019,
63,
5334,
297,
288,
901,
29,
992,
14,
4626,
8,
885,
29,
403,
12,
2599,
63,
2131,
29,
549,
12,
2599,
63,
2131,
63,
525,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
1078,
297,
288,
901,
29,
992,
14,
5036,
8,
885,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
1365,
297,
288,
901,
29,
992,
14,
3190,
8,
2407,
63,
354,
534,
3179,
297,
849,
29,
403,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
504,
1639,
14,
2190,
492,
2202,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
287,
14666,
297,
283,
4183,
63,
2747,
659,
267,
334,
66,
7,
1178,
297,
330,
31279,
2246,
363,
659,
263,
327,
961,
1004,
436,
314,
2163,
1004,
365,
367,
5325,
316,
314,
298,
7521,
3405,
1790,
14,
1899,
2,
1125,
267,
334,
66,
7,
10778,
297,
330,
31279,
2246,
363,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
3966,
63,
292,
297,
288,
901,
29,
992,
14,
4626,
8,
885,
29,
403,
12,
2599,
63,
2131,
63,
525,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
2019,
63,
5334,
297,
288,
901,
29,
992,
14,
4626,
8,
885,
29,
403,
12,
2599,
63,
2131,
29,
549,
12,
2599,
63,
2131,
63,
525,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
1078,
297,
288,
901,
29,
992,
14,
5036,
8,
885,
29,
549,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
267,
6180,
14,
19275,
8,
288,
1402,
63,
354,
534,
4445,
297,
288,
536,
534,
1365,
297,
288,
901,
29,
992,
14,
3190,
8,
2407,
63,
354,
534,
3179,
297,
849,
29,
403,
12,
370,
29,
1751,
14,
5580,
63,
3791,
63,
11429,
395,
288,
11211,
63,
885,
29,
549,
12,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
cchamberlain/npm-msys2
|
node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py
|
1509
|
17165
|
# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Handle version information related to Visual Stuio."""
import errno
import os
import re
import subprocess
import sys
import gyp
import glob
class VisualStudioVersion(object):
"""Information regarding a version of Visual Studio."""
def __init__(self, short_name, description,
solution_version, project_version, flat_sln, uses_vcxproj,
path, sdk_based, default_toolset=None):
self.short_name = short_name
self.description = description
self.solution_version = solution_version
self.project_version = project_version
self.flat_sln = flat_sln
self.uses_vcxproj = uses_vcxproj
self.path = path
self.sdk_based = sdk_based
self.default_toolset = default_toolset
def ShortName(self):
return self.short_name
def Description(self):
"""Get the full description of the version."""
return self.description
def SolutionVersion(self):
"""Get the version number of the sln files."""
return self.solution_version
def ProjectVersion(self):
"""Get the version number of the vcproj or vcxproj files."""
return self.project_version
def FlatSolution(self):
return self.flat_sln
def UsesVcxproj(self):
"""Returns true if this version uses a vcxproj file."""
return self.uses_vcxproj
def ProjectExtension(self):
"""Returns the file extension for the project."""
return self.uses_vcxproj and '.vcxproj' or '.vcproj'
def Path(self):
"""Returns the path to Visual Studio installation."""
return self.path
def ToolPath(self, tool):
"""Returns the path to a given compiler tool. """
return os.path.normpath(os.path.join(self.path, "VC/bin", tool))
def DefaultToolset(self):
"""Returns the msbuild toolset version that will be used in the absence
of a user override."""
return self.default_toolset
def SetupScript(self, target_arch):
"""Returns a command (with arguments) to be used to set up the
environment."""
# Check if we are running in the SDK command line environment and use
# the setup script from the SDK if so. |target_arch| should be either
# 'x86' or 'x64'.
assert target_arch in ('x86', 'x64')
sdk_dir = os.environ.get('WindowsSDKDir')
if self.sdk_based and sdk_dir:
return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')),
'/' + target_arch]
else:
# We don't use VC/vcvarsall.bat for x86 because vcvarsall calls
# vcvars32, which it can only find if VS??COMNTOOLS is set, which it
# isn't always.
if target_arch == 'x86':
if self.short_name >= '2013' and self.short_name[-1] != 'e' and (
os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64'):
# VS2013 and later, non-Express have a x64-x86 cross that we want
# to prefer.
return [os.path.normpath(
os.path.join(self.path, 'VC/vcvarsall.bat')), 'amd64_x86']
# Otherwise, the standard x86 compiler.
return [os.path.normpath(
os.path.join(self.path, 'Common7/Tools/vsvars32.bat'))]
else:
assert target_arch == 'x64'
arg = 'x86_amd64'
# Use the 64-on-64 compiler if we're not using an express
# edition and we're running on a 64bit OS.
if self.short_name[-1] != 'e' and (
os.environ.get('PROCESSOR_ARCHITECTURE') == 'AMD64' or
os.environ.get('PROCESSOR_ARCHITEW6432') == 'AMD64'):
arg = 'amd64'
return [os.path.normpath(
os.path.join(self.path, 'VC/vcvarsall.bat')), arg]
def _RegistryQueryBase(sysdir, key, value):
"""Use reg.exe to read a particular key.
While ideally we might use the win32 module, we would like gyp to be
python neutral, so for instance cygwin python lacks this module.
Arguments:
sysdir: The system subdirectory to attempt to launch reg.exe from.
key: The registry key to read from.
value: The particular value to read.
Return:
stdout from reg.exe, or None for failure.
"""
# Skip if not on Windows or Python Win32 setup issue
if sys.platform not in ('win32', 'cygwin'):
return None
# Setup params to pass to and attempt to launch reg.exe
cmd = [os.path.join(os.environ.get('WINDIR', ''), sysdir, 'reg.exe'),
'query', key]
if value:
cmd.extend(['/v', value])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Obtain the stdout from reg.exe, reading to the end so p.returncode is valid
# Note that the error text may be in [1] in some cases
text = p.communicate()[0]
# Check return code from reg.exe; officially 0==success and 1==error
if p.returncode:
return None
return text
def _RegistryQuery(key, value=None):
r"""Use reg.exe to read a particular key through _RegistryQueryBase.
First tries to launch from %WinDir%\Sysnative to avoid WoW64 redirection. If
that fails, it falls back to System32. Sysnative is available on Vista and
up and available on Windows Server 2003 and XP through KB patch 942589. Note
that Sysnative will always fail if using 64-bit python due to it being a
virtual directory and System32 will work correctly in the first place.
KB 942589 - http://support.microsoft.com/kb/942589/en-us.
Arguments:
key: The registry key.
value: The particular registry value to read (optional).
Return:
stdout from reg.exe, or None for failure.
"""
text = None
try:
text = _RegistryQueryBase('Sysnative', key, value)
except OSError, e:
if e.errno == errno.ENOENT:
text = _RegistryQueryBase('System32', key, value)
else:
raise
return text
def _RegistryGetValueUsingWinReg(key, value):
"""Use the _winreg module to obtain the value of a registry key.
Args:
key: The registry key.
value: The particular registry value to read.
Return:
contents of the registry key's value, or None on failure. Throws
ImportError if _winreg is unavailable.
"""
import _winreg
try:
root, subkey = key.split('\\', 1)
assert root == 'HKLM' # Only need HKLM for now.
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
return _winreg.QueryValueEx(hkey, value)[0]
except WindowsError:
return None
def _RegistryGetValue(key, value):
"""Use _winreg or reg.exe to obtain the value of a registry key.
Using _winreg is preferable because it solves an issue on some corporate
environments where access to reg.exe is locked down. However, we still need
to fallback to reg.exe for the case where the _winreg module is not available
(for example in cygwin python).
Args:
key: The registry key.
value: The particular registry value to read.
Return:
contents of the registry key's value, or None on failure.
"""
try:
return _RegistryGetValueUsingWinReg(key, value)
except ImportError:
pass
# Fallback to reg.exe if we fail to import _winreg.
text = _RegistryQuery(key, value)
if not text:
return None
# Extract value.
match = re.search(r'REG_\w+\s+([^\r]+)\r\n', text)
if not match:
return None
return match.group(1)
def _CreateVersion(name, path, sdk_based=False):
"""Sets up MSVS project generation.
Setup is based off the GYP_MSVS_VERSION environment variable or whatever is
autodetected if GYP_MSVS_VERSION is not explicitly specified. If a version is
passed in that doesn't match a value in versions python will throw a error.
"""
if path:
path = os.path.normpath(path)
versions = {
'2015': VisualStudioVersion('2015',
'Visual Studio 2015',
solution_version='12.00',
project_version='14.0',
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v140'),
'2013': VisualStudioVersion('2013',
'Visual Studio 2013',
solution_version='13.00',
project_version='12.0',
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v120'),
'2013e': VisualStudioVersion('2013e',
'Visual Studio 2013',
solution_version='13.00',
project_version='12.0',
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v120'),
'2012': VisualStudioVersion('2012',
'Visual Studio 2012',
solution_version='12.00',
project_version='4.0',
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v110'),
'2012e': VisualStudioVersion('2012e',
'Visual Studio 2012',
solution_version='12.00',
project_version='4.0',
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based,
default_toolset='v110'),
'2010': VisualStudioVersion('2010',
'Visual Studio 2010',
solution_version='11.00',
project_version='4.0',
flat_sln=False,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based),
'2010e': VisualStudioVersion('2010e',
'Visual C++ Express 2010',
solution_version='11.00',
project_version='4.0',
flat_sln=True,
uses_vcxproj=True,
path=path,
sdk_based=sdk_based),
'2008': VisualStudioVersion('2008',
'Visual Studio 2008',
solution_version='10.00',
project_version='9.00',
flat_sln=False,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based),
'2008e': VisualStudioVersion('2008e',
'Visual Studio 2008',
solution_version='10.00',
project_version='9.00',
flat_sln=True,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based),
'2005': VisualStudioVersion('2005',
'Visual Studio 2005',
solution_version='9.00',
project_version='8.00',
flat_sln=False,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based),
'2005e': VisualStudioVersion('2005e',
'Visual Studio 2005',
solution_version='9.00',
project_version='8.00',
flat_sln=True,
uses_vcxproj=False,
path=path,
sdk_based=sdk_based),
}
return versions[str(name)]
def _ConvertToCygpath(path):
"""Convert to cygwin path if we are using cygwin."""
if sys.platform == 'cygwin':
p = subprocess.Popen(['cygpath', path], stdout=subprocess.PIPE)
path = p.communicate()[0].strip()
return path
def _DetectVisualStudioVersions(versions_to_check, force_express):
"""Collect the list of installed visual studio versions.
Returns:
A list of visual studio versions installed in descending order of
usage preference.
Base this on the registry and a quick check if devenv.exe exists.
Only versions 8-10 are considered.
Possibilities are:
2005(e) - Visual Studio 2005 (8)
2008(e) - Visual Studio 2008 (9)
2010(e) - Visual Studio 2010 (10)
2012(e) - Visual Studio 2012 (11)
2013(e) - Visual Studio 2013 (12)
2015 - Visual Studio 2015 (14)
Where (e) is e for express editions of MSVS and blank otherwise.
"""
version_to_year = {
'8.0': '2005',
'9.0': '2008',
'10.0': '2010',
'11.0': '2012',
'12.0': '2013',
'14.0': '2015',
}
versions = []
for version in versions_to_check:
# Old method of searching for which VS version is installed
# We don't use the 2010-encouraged-way because we also want to get the
# path to the binaries, which it doesn't offer.
keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version,
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version,
r'HKLM\Software\Microsoft\VCExpress\%s' % version,
r'HKLM\Software\Wow6432Node\Microsoft\VCExpress\%s' % version]
for index in range(len(keys)):
path = _RegistryGetValue(keys[index], 'InstallDir')
if not path:
continue
path = _ConvertToCygpath(path)
# Check for full.
full_path = os.path.join(path, 'devenv.exe')
express_path = os.path.join(path, '*express.exe')
if not force_express and os.path.exists(full_path):
# Add this one.
versions.append(_CreateVersion(version_to_year[version],
os.path.join(path, '..', '..')))
# Check for express.
elif glob.glob(express_path):
# Add this one.
versions.append(_CreateVersion(version_to_year[version] + 'e',
os.path.join(path, '..', '..')))
# The old method above does not work when only SDK is installed.
keys = [r'HKLM\Software\Microsoft\VisualStudio\SxS\VC7',
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7']
for index in range(len(keys)):
path = _RegistryGetValue(keys[index], version)
if not path:
continue
path = _ConvertToCygpath(path)
if version != '14.0': # There is no Express edition for 2015.
versions.append(_CreateVersion(version_to_year[version] + 'e',
os.path.join(path, '..'), sdk_based=True))
return versions
def SelectVisualStudioVersion(version='auto', allow_fallback=True):
"""Select which version of Visual Studio projects to generate.
Arguments:
version: Hook to allow caller to force a particular version (vs auto).
Returns:
An object representing a visual studio project format version.
"""
# In auto mode, check environment variable for override.
if version == 'auto':
version = os.environ.get('GYP_MSVS_VERSION', 'auto')
version_map = {
'auto': ('14.0', '12.0', '10.0', '9.0', '8.0', '11.0'),
'2005': ('8.0',),
'2005e': ('8.0',),
'2008': ('9.0',),
'2008e': ('9.0',),
'2010': ('10.0',),
'2010e': ('10.0',),
'2012': ('11.0',),
'2012e': ('11.0',),
'2013': ('12.0',),
'2013e': ('12.0',),
'2015': ('14.0',),
}
override_path = os.environ.get('GYP_MSVS_OVERRIDE_PATH')
if override_path:
msvs_version = os.environ.get('GYP_MSVS_VERSION')
if not msvs_version:
raise ValueError('GYP_MSVS_OVERRIDE_PATH requires GYP_MSVS_VERSION to be '
'set to a particular version (e.g. 2010e).')
return _CreateVersion(msvs_version, override_path, sdk_based=True)
version = str(version)
versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
if not versions:
if not allow_fallback:
raise ValueError('Could not locate Visual Studio installation.')
if version == 'auto':
# Default to 2005 if we couldn't find anything
return _CreateVersion('2005', None)
else:
return _CreateVersion(version, None)
return versions[0]
|
artistic-2.0
|
[
3,
1898,
334,
67,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5940,
1015,
2556,
4048,
370,
14702,
1933,
1907,
79,
1041,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
646,
4902,
199,
646,
5739,
421,
199,
533,
14702,
21025,
3353,
8,
785,
304,
523,
408,
4935,
12602,
282,
1015,
402,
14702,
13225,
1041,
819,
347,
636,
826,
721,
277,
12,
3974,
63,
354,
12,
1369,
12,
2049,
8744,
63,
1023,
12,
2199,
63,
1023,
12,
6829,
63,
29938,
12,
4440,
63,
6737,
88,
5468,
12,
2049,
931,
12,
13628,
63,
6788,
12,
849,
63,
12081,
29,
403,
304,
272,
291,
14,
3612,
63,
354,
275,
3974,
63,
354,
272,
291,
14,
1802,
275,
1369,
272,
291,
14,
14458,
63,
1023,
275,
8744,
63,
1023,
272,
291,
14,
1715,
63,
1023,
275,
2199,
63,
1023,
272,
291,
14,
7088,
63,
29938,
275,
6829,
63,
29938,
272,
291,
14,
5589,
63,
6737,
88,
5468,
275,
4440,
63,
6737,
88,
5468,
272,
291,
14,
515,
275,
931,
272,
291,
14,
9277,
63,
6788,
275,
13628,
63,
6788,
272,
291,
14,
885,
63,
12081,
275,
849,
63,
12081,
819,
347,
20124,
985,
8,
277,
304,
272,
372,
291,
14,
3612,
63,
354,
819,
347,
11994,
8,
277,
304,
272,
408,
1002,
314,
2615,
1369,
402,
314,
1015,
1041,
272,
372,
291,
14,
1802,
819,
347,
9274,
3353,
8,
277,
304,
272,
408,
1002,
314,
1015,
1329,
402,
314,
5340,
78,
1584,
1041,
272,
372,
291,
14,
14458,
63,
1023,
819,
347,
7290,
3353,
8,
277,
304,
272,
408,
1002,
314,
1015,
1329,
402,
314,
16548,
5468,
503,
373,
11859,
5468,
1584,
1041,
272,
372,
291,
14,
1715,
63,
1023,
819,
347,
19005,
24277,
8,
277,
304,
272,
372,
291,
14,
7088,
63,
29938,
819,
347,
14911,
54,
11859,
5468,
8,
277,
304,
272,
408,
3407,
2549,
340,
642,
1015,
4440,
282,
373,
11859,
5468,
570,
1041,
272,
372,
291,
14,
5589,
63,
6737,
88,
5468,
819,
347,
7290,
6382,
8,
277,
304,
272,
408,
3407,
314,
570,
3329,
367,
314,
2199,
1041,
272,
372,
291,
14,
5589,
63,
6737,
88,
5468,
436,
1987,
6737,
88,
5468,
7,
503,
1987,
6737,
5468,
7,
819,
347,
6912,
8,
277,
304,
272,
408,
3407,
314,
931,
370,
14702,
13225,
12096,
1041,
272,
372,
291,
14,
515,
819,
347,
15650,
2042,
8,
277,
12,
4744,
304,
272,
408,
3407,
314,
931,
370,
282,
1627,
6365,
4744,
14,
408,
272,
372,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
277,
14,
515,
12,
298,
9454,
15,
1393,
401,
4744,
430,
819,
347,
3758,
5157,
409,
8,
277,
304,
272,
408,
3407,
314,
14835,
20070,
1015,
626,
911,
506,
1202,
315,
314,
2236,
14073,
272,
402,
282,
922,
4278,
1041,
272,
372,
291,
14,
885,
63,
12081,
819,
347,
12439,
5229,
8,
277,
12,
1347,
63,
1047,
304,
272,
408,
3407,
282,
1414,
334,
1045,
2368,
9,
370,
506,
1202,
370,
663,
1536,
314,
272,
3734,
1041,
272,
327,
2670,
340,
781,
787,
3879,
315,
314,
15610,
1414,
1004,
3734,
436,
675,
272,
327,
314,
3272,
2884,
687,
314,
15610,
340,
880,
14,
1204,
1375,
63,
1047,
92,
1077,
506,
1902,
272,
327,
283,
88,
1184,
7,
503,
283,
88,
772,
1370,
272,
702,
1347,
63,
1047,
315,
661,
88,
1184,
297,
283,
88,
772,
358,
272,
13628,
63,
694,
275,
747,
14,
2314,
14,
362,
360,
8647,
14939,
3567,
358,
272,
340,
291,
14,
9277,
63,
6788,
436,
13628,
63,
694,
26,
489,
372,
359,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
9277,
63,
694,
12,
283,
13394,
15,
1084,
7744,
14,
7874,
3855,
1598,
7324,
435,
1347,
63,
1047,
61,
272,
587,
26,
489,
327,
2136,
2793,
1133,
675,
24955,
15,
6737,
2936,
452,
14,
13475,
367,
671,
1184,
2952,
16548,
2936,
452,
4882,
489,
327,
16548,
2936,
708,
12,
1314,
652,
883,
1454,
2342,
340,
21685,
10674,
11265,
46,
20261,
365,
663,
12,
1314,
652,
489,
327,
5712,
1133,
3544,
14,
489,
340,
1347,
63,
1047,
508,
283,
88,
1184,
356,
267,
340,
291,
14,
3612,
63,
354,
2356,
283,
6965,
7,
436,
291,
14,
3612,
63,
354,
1988,
17,
61,
1137,
283,
69,
7,
436,
334,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
358,
508,
283,
22909,
772,
7,
503,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
358,
508,
283,
22909,
772,
735,
881,
327,
21685,
6965,
436,
2945,
12,
2222,
13,
32161,
1172,
282,
671,
772,
13,
88,
1184,
8059,
626,
781,
2934,
881,
327,
370,
16602,
14,
881,
372,
359,
736,
14,
515,
14,
9267,
8,
1467,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
9454,
15,
6737,
2936,
452,
14,
13475,
3855,
283,
21778,
772,
63,
88,
1184,
418,
267,
327,
6630,
12,
314,
4465,
671,
1184,
6365,
14,
267,
372,
359,
736,
14,
515,
14,
9267,
8,
881,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
7844,
23,
15,
11654,
15,
3122,
2936,
708,
14,
13475,
27738,
489,
587,
26,
267,
702,
1347,
63,
1047,
508,
283,
88,
772,
7,
267,
1680,
275,
283,
88,
1184,
63,
21778,
772,
7,
267,
327,
3645,
314,
5049,
13,
265,
13,
772,
6365,
340,
781,
3984,
440,
1808,
376,
4056,
267,
327,
325,
1671,
436,
781,
3984,
3879,
641,
282,
5049,
2075,
4403,
14,
267,
340,
291,
14,
3612,
63,
354,
1988,
17,
61,
1137,
283,
69,
7,
436,
334,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
358,
508,
283,
22909,
772,
7,
503,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
358,
508,
283,
22909,
772,
735,
881,
1680,
275,
283,
21778,
772,
7,
267,
372,
359,
736,
14,
515,
14,
9267,
8,
288,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
9454,
15,
6737,
2936,
452
] |
[
1898,
334,
67,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
5940,
1015,
2556,
4048,
370,
14702,
1933,
1907,
79,
1041,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
199,
646,
4902,
199,
646,
5739,
421,
199,
533,
14702,
21025,
3353,
8,
785,
304,
523,
408,
4935,
12602,
282,
1015,
402,
14702,
13225,
1041,
819,
347,
636,
826,
721,
277,
12,
3974,
63,
354,
12,
1369,
12,
2049,
8744,
63,
1023,
12,
2199,
63,
1023,
12,
6829,
63,
29938,
12,
4440,
63,
6737,
88,
5468,
12,
2049,
931,
12,
13628,
63,
6788,
12,
849,
63,
12081,
29,
403,
304,
272,
291,
14,
3612,
63,
354,
275,
3974,
63,
354,
272,
291,
14,
1802,
275,
1369,
272,
291,
14,
14458,
63,
1023,
275,
8744,
63,
1023,
272,
291,
14,
1715,
63,
1023,
275,
2199,
63,
1023,
272,
291,
14,
7088,
63,
29938,
275,
6829,
63,
29938,
272,
291,
14,
5589,
63,
6737,
88,
5468,
275,
4440,
63,
6737,
88,
5468,
272,
291,
14,
515,
275,
931,
272,
291,
14,
9277,
63,
6788,
275,
13628,
63,
6788,
272,
291,
14,
885,
63,
12081,
275,
849,
63,
12081,
819,
347,
20124,
985,
8,
277,
304,
272,
372,
291,
14,
3612,
63,
354,
819,
347,
11994,
8,
277,
304,
272,
408,
1002,
314,
2615,
1369,
402,
314,
1015,
1041,
272,
372,
291,
14,
1802,
819,
347,
9274,
3353,
8,
277,
304,
272,
408,
1002,
314,
1015,
1329,
402,
314,
5340,
78,
1584,
1041,
272,
372,
291,
14,
14458,
63,
1023,
819,
347,
7290,
3353,
8,
277,
304,
272,
408,
1002,
314,
1015,
1329,
402,
314,
16548,
5468,
503,
373,
11859,
5468,
1584,
1041,
272,
372,
291,
14,
1715,
63,
1023,
819,
347,
19005,
24277,
8,
277,
304,
272,
372,
291,
14,
7088,
63,
29938,
819,
347,
14911,
54,
11859,
5468,
8,
277,
304,
272,
408,
3407,
2549,
340,
642,
1015,
4440,
282,
373,
11859,
5468,
570,
1041,
272,
372,
291,
14,
5589,
63,
6737,
88,
5468,
819,
347,
7290,
6382,
8,
277,
304,
272,
408,
3407,
314,
570,
3329,
367,
314,
2199,
1041,
272,
372,
291,
14,
5589,
63,
6737,
88,
5468,
436,
1987,
6737,
88,
5468,
7,
503,
1987,
6737,
5468,
7,
819,
347,
6912,
8,
277,
304,
272,
408,
3407,
314,
931,
370,
14702,
13225,
12096,
1041,
272,
372,
291,
14,
515,
819,
347,
15650,
2042,
8,
277,
12,
4744,
304,
272,
408,
3407,
314,
931,
370,
282,
1627,
6365,
4744,
14,
408,
272,
372,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
277,
14,
515,
12,
298,
9454,
15,
1393,
401,
4744,
430,
819,
347,
3758,
5157,
409,
8,
277,
304,
272,
408,
3407,
314,
14835,
20070,
1015,
626,
911,
506,
1202,
315,
314,
2236,
14073,
272,
402,
282,
922,
4278,
1041,
272,
372,
291,
14,
885,
63,
12081,
819,
347,
12439,
5229,
8,
277,
12,
1347,
63,
1047,
304,
272,
408,
3407,
282,
1414,
334,
1045,
2368,
9,
370,
506,
1202,
370,
663,
1536,
314,
272,
3734,
1041,
272,
327,
2670,
340,
781,
787,
3879,
315,
314,
15610,
1414,
1004,
3734,
436,
675,
272,
327,
314,
3272,
2884,
687,
314,
15610,
340,
880,
14,
1204,
1375,
63,
1047,
92,
1077,
506,
1902,
272,
327,
283,
88,
1184,
7,
503,
283,
88,
772,
1370,
272,
702,
1347,
63,
1047,
315,
661,
88,
1184,
297,
283,
88,
772,
358,
272,
13628,
63,
694,
275,
747,
14,
2314,
14,
362,
360,
8647,
14939,
3567,
358,
272,
340,
291,
14,
9277,
63,
6788,
436,
13628,
63,
694,
26,
489,
372,
359,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
9277,
63,
694,
12,
283,
13394,
15,
1084,
7744,
14,
7874,
3855,
1598,
7324,
435,
1347,
63,
1047,
61,
272,
587,
26,
489,
327,
2136,
2793,
1133,
675,
24955,
15,
6737,
2936,
452,
14,
13475,
367,
671,
1184,
2952,
16548,
2936,
452,
4882,
489,
327,
16548,
2936,
708,
12,
1314,
652,
883,
1454,
2342,
340,
21685,
10674,
11265,
46,
20261,
365,
663,
12,
1314,
652,
489,
327,
5712,
1133,
3544,
14,
489,
340,
1347,
63,
1047,
508,
283,
88,
1184,
356,
267,
340,
291,
14,
3612,
63,
354,
2356,
283,
6965,
7,
436,
291,
14,
3612,
63,
354,
1988,
17,
61,
1137,
283,
69,
7,
436,
334,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
358,
508,
283,
22909,
772,
7,
503,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
358,
508,
283,
22909,
772,
735,
881,
327,
21685,
6965,
436,
2945,
12,
2222,
13,
32161,
1172,
282,
671,
772,
13,
88,
1184,
8059,
626,
781,
2934,
881,
327,
370,
16602,
14,
881,
372,
359,
736,
14,
515,
14,
9267,
8,
1467,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
9454,
15,
6737,
2936,
452,
14,
13475,
3855,
283,
21778,
772,
63,
88,
1184,
418,
267,
327,
6630,
12,
314,
4465,
671,
1184,
6365,
14,
267,
372,
359,
736,
14,
515,
14,
9267,
8,
881,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
7844,
23,
15,
11654,
15,
3122,
2936,
708,
14,
13475,
27738,
489,
587,
26,
267,
702,
1347,
63,
1047,
508,
283,
88,
772,
7,
267,
1680,
275,
283,
88,
1184,
63,
21778,
772,
7,
267,
327,
3645,
314,
5049,
13,
265,
13,
772,
6365,
340,
781,
3984,
440,
1808,
376,
4056,
267,
327,
325,
1671,
436,
781,
3984,
3879,
641,
282,
5049,
2075,
4403,
14,
267,
340,
291,
14,
3612,
63,
354,
1988,
17,
61,
1137,
283,
69,
7,
436,
334,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
649,
3582,
3942,
358,
508,
283,
22909,
772,
7,
503,
288,
747,
14,
2314,
14,
362,
360,
24341,
63,
7762,
4427,
55,
23313,
358,
508,
283,
22909,
772,
735,
881,
1680,
275,
283,
21778,
772,
7,
267,
372,
359,
736,
14,
515,
14,
9267,
8,
288,
747,
14,
515,
14,
904,
8,
277,
14,
515,
12,
283,
9454,
15,
6737,
2936,
452,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SnappleCap/oh-mainline
|
vendor/packages/south/south/tests/db_firebird.py
|
93
|
1143
|
from django.db import models
from south.db import db
from south.tests import unittest, skipUnless
class FirebirdTests(unittest.TestCase):
"""
Tests firebird related issues
"""
def setUp(self):
print('=' * 80)
print('Begin Firebird test')
def tearDown(self):
print('End Firebird test')
print('=' * 80)
@skipUnless(db.backend_name == "firebird", "Firebird-only test")
def test_firebird_double_index_creation_1317(self):
"""
Tests foreign key creation, especially uppercase (see #61)
"""
Test = db.mock_model(model_name='Test',
db_table='test5a',
db_tablespace='',
pk_field_name='ID',
pk_field_type=models.AutoField,
pk_field_args=[]
)
db.create_table("test5a", [('ID', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True))])
db.create_table("test5b", [
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('UNIQUE', models.ForeignKey(Test)),
])
db.execute_deferred_sql()
|
agpl-3.0
|
[
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
2219,
492,
2882,
12,
3372,
5524,
421,
199,
533,
15967,
22488,
2925,
8,
2796,
14,
1746,
304,
339,
408,
272,
6496,
8344,
22488,
4048,
10876,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
870,
360,
534,
627,
5939,
9,
267,
870,
360,
5595,
15967,
22488,
511,
358,
339,
347,
6766,
8,
277,
304,
267,
870,
360,
3005,
15967,
22488,
511,
358,
267,
870,
360,
534,
627,
5939,
9,
339,
768,
11278,
8,
697,
14,
4620,
63,
354,
508,
298,
8935,
22488,
401,
298,
13081,
22488,
13,
2118,
511,
531,
272,
347,
511,
63,
8935,
22488,
63,
3157,
63,
1080,
63,
8782,
63,
969,
1196,
8,
277,
304,
267,
408,
267,
6496,
11608,
790,
7143,
12,
24002,
22681,
334,
3239,
327,
2976,
9,
267,
408,
267,
1379,
275,
1592,
14,
1805,
63,
1238,
8,
1238,
63,
354,
534,
774,
297,
288,
1592,
63,
1224,
534,
396,
21,
65,
297,
288,
1592,
63,
26730,
4581,
288,
3803,
63,
698,
63,
354,
534,
998,
297,
288,
3803,
63,
698,
63,
466,
29,
992,
14,
4378,
12,
288,
3803,
63,
698,
63,
589,
9811,
267,
776,
267,
1592,
14,
981,
63,
1224,
480,
396,
21,
65,
401,
4274,
998,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
18229,
267,
1592,
14,
981,
63,
1224,
480,
396,
21,
66,
401,
359,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
28060,
297,
1709,
14,
3190,
8,
774,
1826,
267,
4794,
267,
1592,
14,
2526,
63,
12116,
63,
3009,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
2219,
492,
2882,
12,
3372,
5524,
421,
199,
533,
15967,
22488,
2925,
8,
2796,
14,
1746,
304,
339,
408,
272,
6496,
8344,
22488,
4048,
10876,
272,
408,
339,
347,
3613,
8,
277,
304,
267,
870,
360,
534,
627,
5939,
9,
267,
870,
360,
5595,
15967,
22488,
511,
358,
339,
347,
6766,
8,
277,
304,
267,
870,
360,
3005,
15967,
22488,
511,
358,
267,
870,
360,
534,
627,
5939,
9,
339,
768,
11278,
8,
697,
14,
4620,
63,
354,
508,
298,
8935,
22488,
401,
298,
13081,
22488,
13,
2118,
511,
531,
272,
347,
511,
63,
8935,
22488,
63,
3157,
63,
1080,
63,
8782,
63,
969,
1196,
8,
277,
304,
267,
408,
267,
6496,
11608,
790,
7143,
12,
24002,
22681,
334,
3239,
327,
2976,
9,
267,
408,
267,
1379,
275,
1592,
14,
1805,
63,
1238,
8,
1238,
63,
354,
534,
774,
297,
288,
1592,
63,
1224,
534,
396,
21,
65,
297,
288,
1592,
63,
26730,
4581,
288,
3803,
63,
698,
63,
354,
534,
998,
297,
288,
3803,
63,
698,
63,
466,
29,
992,
14,
4378,
12,
288,
3803,
63,
698,
63,
589,
9811,
267,
776,
267,
1592,
14,
981,
63,
1224,
480,
396,
21,
65,
401,
4274,
998,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
18229,
267,
1592,
14,
981,
63,
1224,
480,
396,
21,
66,
401,
359,
288,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
5062,
63,
498,
29,
549,
12,
2599,
63,
3966,
29,
549,
1826,
288,
661,
28060,
297,
1709,
14,
3190,
8,
774,
1826,
267,
4794,
267,
1592,
14,
2526,
63,
12116,
63,
3009,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Endika/OpenUpgrade
|
addons/l10n_in_hr_payroll/report/payslip_report.py
|
340
|
3978
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import tools
from openerp.osv import fields, osv
class payslip_report(osv.osv):
_name = "payslip.report"
_description = "Payslip Analysis"
_auto = False
_columns = {
'name':fields.char('Name', readonly=True),
'date_from': fields.date('Date From', readonly=True,),
'date_to': fields.date('Date To', readonly=True,),
'year': fields.char('Year', size=4, readonly=True),
'month': fields.selection([('01', 'January'), ('02', 'February'), ('03', 'March'), ('04', 'April'),
('05', 'May'), ('06', 'June'), ('07', 'July'), ('08', 'August'), ('09', 'September'),
('10', 'October'), ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
'day': fields.char('Day', size=128, readonly=True),
'state': fields.selection([
('draft', 'Draft'),
('done', 'Done'),
('cancel', 'Rejected'),
], 'Status', readonly=True),
'employee_id': fields.many2one('hr.employee', 'Employee', readonly=True),
'nbr': fields.integer('# Payslip lines', readonly=True),
'number': fields.char('Number', readonly=True),
'struct_id': fields.many2one('hr.payroll.structure', 'Structure', readonly=True),
'company_id':fields.many2one('res.company', 'Company', readonly=True),
'paid': fields.boolean('Made Payment Order ? ', readonly=True),
'total': fields.float('Total', readonly=True),
'category_id':fields.many2one('hr.salary.rule.category', 'Category', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'payslip_report')
cr.execute("""
create or replace view payslip_report as (
select
min(l.id) as id,
l.name,
p.struct_id,
p.state,
p.date_from,
p.date_to,
p.number,
p.company_id,
p.paid,
l.category_id,
l.employee_id,
sum(l.total) as total,
to_char(p.date_from, 'YYYY') as year,
to_char(p.date_from, 'MM') as month,
to_char(p.date_from, 'YYYY-MM-DD') as day,
to_char(p.date_to, 'YYYY') as to_year,
to_char(p.date_to, 'MM') as to_month,
to_char(p.date_to, 'YYYY-MM-DD') as to_day,
1 AS nbr
from
hr_payslip as p
left join hr_payslip_line as l on (p.id=l.slip_id)
where
l.employee_id IS NOT NULL
group by
p.number,l.name,p.date_from,p.date_to,p.state,p.company_id,p.paid,
l.employee_id,p.struct_id,l.category_id
)
""")
# 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,
6029,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
691,
18909,
63,
3070,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
25854,
14,
3070,
2,
272,
485,
1802,
275,
298,
4232,
18909,
21916,
2,
272,
485,
2495,
275,
756,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
955,
14,
1560,
360,
985,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
2506,
11606,
297,
6863,
29,
549,
4706,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
2506,
4005,
297,
6863,
29,
549,
4706,
267,
283,
3403,
356,
1504,
14,
1560,
360,
15731,
297,
1568,
29,
20,
12,
6863,
29,
549,
395,
267,
283,
4482,
356,
1504,
14,
5592,
8318,
614,
297,
283,
19825,
20527,
659,
661,
996,
297,
283,
27717,
26709,
659,
661,
1644,
297,
283,
45,
1047,
659,
661,
966,
297,
283,
33,
28026,
659,
288,
661,
1717,
297,
283,
15586,
659,
661,
1690,
297,
283,
42,
11474,
659,
661,
1780,
297,
283,
42,
21797,
659,
661,
2036,
297,
283,
21640,
833,
659,
661,
1643,
297,
283,
23337,
31575,
659,
288,
661,
709,
297,
283,
17584,
22459,
659,
661,
845,
297,
283,
1944,
432,
976,
659,
661,
713,
297,
283,
872,
26381,
2665,
283,
14306,
297,
6863,
29,
549,
395,
267,
283,
2977,
356,
1504,
14,
1560,
360,
12631,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
267,
283,
929,
356,
1504,
14,
5592,
779,
288,
661,
7185,
297,
283,
18332,
659,
288,
661,
4456,
297,
283,
10759,
659,
288,
661,
6406,
297,
283,
497,
8553,
659,
267,
2156,
283,
3694,
297,
6863,
29,
549,
395,
267,
283,
10103,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6271,
14,
10103,
297,
283,
22635,
297,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
510,
5758,
3587,
2385,
297,
6863,
29,
549,
395,
267,
283,
1955,
356,
1504,
14,
1560,
360,
3259,
297,
6863,
29,
549,
395,
267,
283,
1820,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6271,
14,
5989,
2827,
14,
6976,
297,
283,
10766,
297,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
16555,
356,
1504,
14,
4871,
360,
26973,
25523,
9240,
5805,
1656,
6863,
29,
549,
395,
267,
283,
2923,
356,
1504,
14,
1609,
360,
7316,
297,
6863,
29,
549,
395,
267,
283,
3710,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
6271,
14,
22025,
14,
2200,
14,
3710,
297,
283,
7841,
297,
6863,
29,
549,
395,
272,
789,
272,
347,
4205,
8,
277,
12,
2467,
304,
267,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
25854,
63,
3070,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
691,
18909,
63,
3070,
465,
334,
355,
3504,
490,
1748,
8,
76,
14,
344,
9,
465,
1305,
12,
490,
634,
14,
354,
12,
490,
299,
14,
1820,
63,
344,
12,
490,
299,
14,
929,
12,
490,
299,
14,
602,
63,
504,
12,
490,
299,
14,
602,
63,
475,
12,
490,
299,
14,
1955,
12,
490,
299,
14,
4627,
63,
344,
12,
490,
299,
14,
16555,
12,
490,
634,
14,
3710,
63,
344,
12,
490,
634,
14,
10103,
63,
344,
12,
490,
3089,
8,
76,
14,
2923,
9,
465,
3141,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
15703,
358,
465,
5361,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
3218,
358,
465,
5794,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
15703,
13,
3218,
13,
5745,
358,
465,
5382,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
15703,
358,
465,
370,
63,
3403,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
3218,
358,
465,
370,
63,
4482,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
15703,
13,
3218,
13,
5745,
358,
465,
370,
63,
2977,
12,
490,
413,
4319,
31646,
355,
687,
490,
16140,
63,
25854,
465,
299,
490,
3602,
4263,
16140,
63,
25854,
63,
604,
465,
634,
641,
334,
80,
14,
344,
29,
76,
14,
83,
3587,
63,
344,
9,
355,
2382,
15324,
634,
14,
10103,
63,
344,
2281,
2845,
5962,
355,
1572,
701,
490,
299,
14,
1955,
12,
76,
14,
354,
12,
80,
14,
602,
63,
504,
12,
80,
14,
602,
63,
475,
12,
80,
14,
929,
12,
80,
14,
4627,
63,
344,
12,
80,
14,
16555,
12,
490,
634,
14,
10103,
63,
344,
12,
80,
14,
1820,
63,
344,
12,
76,
14,
3710,
63,
344,
288,
776,
267,
7857,
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
] |
[
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,
6029,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
691,
18909,
63,
3070,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
25854,
14,
3070,
2,
272,
485,
1802,
275,
298,
4232,
18909,
21916,
2,
272,
485,
2495,
275,
756,
272,
485,
3406,
275,
469,
267,
283,
354,
356,
955,
14,
1560,
360,
985,
297,
6863,
29,
549,
395,
267,
283,
602,
63,
504,
356,
1504,
14,
602,
360,
2506,
11606,
297,
6863,
29,
549,
4706,
267,
283,
602,
63,
475,
356,
1504,
14,
602,
360,
2506,
4005,
297,
6863,
29,
549,
4706,
267,
283,
3403,
356,
1504,
14,
1560,
360,
15731,
297,
1568,
29,
20,
12,
6863,
29,
549,
395,
267,
283,
4482,
356,
1504,
14,
5592,
8318,
614,
297,
283,
19825,
20527,
659,
661,
996,
297,
283,
27717,
26709,
659,
661,
1644,
297,
283,
45,
1047,
659,
661,
966,
297,
283,
33,
28026,
659,
288,
661,
1717,
297,
283,
15586,
659,
661,
1690,
297,
283,
42,
11474,
659,
661,
1780,
297,
283,
42,
21797,
659,
661,
2036,
297,
283,
21640,
833,
659,
661,
1643,
297,
283,
23337,
31575,
659,
288,
661,
709,
297,
283,
17584,
22459,
659,
661,
845,
297,
283,
1944,
432,
976,
659,
661,
713,
297,
283,
872,
26381,
2665,
283,
14306,
297,
6863,
29,
549,
395,
267,
283,
2977,
356,
1504,
14,
1560,
360,
12631,
297,
1568,
29,
3933,
12,
6863,
29,
549,
395,
267,
283,
929,
356,
1504,
14,
5592,
779,
288,
661,
7185,
297,
283,
18332,
659,
288,
661,
4456,
297,
283,
10759,
659,
288,
661,
6406,
297,
283,
497,
8553,
659,
267,
2156,
283,
3694,
297,
6863,
29,
549,
395,
267,
283,
10103,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6271,
14,
10103,
297,
283,
22635,
297,
6863,
29,
549,
395,
267,
283,
23299,
356,
1504,
14,
4115,
7863,
510,
5758,
3587,
2385,
297,
6863,
29,
549,
395,
267,
283,
1955,
356,
1504,
14,
1560,
360,
3259,
297,
6863,
29,
549,
395,
267,
283,
1820,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
6271,
14,
5989,
2827,
14,
6976,
297,
283,
10766,
297,
6863,
29,
549,
395,
267,
283,
4627,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
470,
14,
4627,
297,
283,
16063,
297,
6863,
29,
549,
395,
267,
283,
16555,
356,
1504,
14,
4871,
360,
26973,
25523,
9240,
5805,
1656,
6863,
29,
549,
395,
267,
283,
2923,
356,
1504,
14,
1609,
360,
7316,
297,
6863,
29,
549,
395,
267,
283,
3710,
63,
344,
356,
955,
14,
3479,
18,
368,
360,
6271,
14,
22025,
14,
2200,
14,
3710,
297,
283,
7841,
297,
6863,
29,
549,
395,
272,
789,
272,
347,
4205,
8,
277,
12,
2467,
304,
267,
7249,
14,
4824,
63,
1345,
63,
692,
63,
2444,
8,
1556,
12,
283,
25854,
63,
3070,
358,
267,
2467,
14,
2526,
4852,
288,
1218,
503,
3350,
2455,
691,
18909,
63,
3070,
465,
334,
355,
3504,
490,
1748,
8,
76,
14,
344,
9,
465,
1305,
12,
490,
634,
14,
354,
12,
490,
299,
14,
1820,
63,
344,
12,
490,
299,
14,
929,
12,
490,
299,
14,
602,
63,
504,
12,
490,
299,
14,
602,
63,
475,
12,
490,
299,
14,
1955,
12,
490,
299,
14,
4627,
63,
344,
12,
490,
299,
14,
16555,
12,
490,
634,
14,
3710,
63,
344,
12,
490,
634,
14,
10103,
63,
344,
12,
490,
3089,
8,
76,
14,
2923,
9,
465,
3141,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
15703,
358,
465,
5361,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
3218,
358,
465,
5794,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
504,
12,
283,
15703,
13,
3218,
13,
5745,
358,
465,
5382,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
15703,
358,
465,
370,
63,
3403,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
3218,
358,
465,
370,
63,
4482,
12,
490,
370,
63,
1560,
8,
80,
14,
602,
63,
475,
12,
283,
15703,
13,
3218,
13,
5745,
358,
465,
370,
63,
2977,
12,
490,
413,
4319,
31646,
355,
687,
490,
16140,
63,
25854,
465,
299,
490,
3602,
4263,
16140,
63,
25854,
63,
604,
465,
634,
641,
334,
80,
14,
344,
29,
76,
14,
83,
3587,
63,
344,
9,
355,
2382,
15324,
634,
14,
10103,
63,
344,
2281,
2845,
5962,
355,
1572,
701,
490,
299,
14,
1955,
12,
76,
14,
354,
12,
80,
14,
602,
63,
504,
12,
80,
14,
602,
63,
475,
12,
80,
14,
929,
12,
80,
14,
4627,
63,
344,
12,
80,
14,
16555,
12,
490,
634,
14,
10103,
63,
344,
12,
80,
14,
1820,
63,
344,
12,
76,
14,
3710,
63,
344,
288,
776,
267,
7857,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0
] |
Nick-Hall/gramps
|
data/man/pl/conf.py
|
12
|
7708
|
# -*- coding: utf-8 -*-
#
# Gramps documentation build configuration file, created by
# sphinx-quickstart on Sat Dec 1 14:38:29 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'pl'
# General information about the project.
project = u'Gramps'
copyright = u'2015, Gramps project'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '4.2'
# The full version, including alpha/beta/rc tags.
release = '4.2.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
locale_dirs = './locale'
gettext_compact = True
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'Grampsdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'Gramps.tex', u'Gramps Documentation',
u'.', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('pl', 'gramps', u'Gramps Documentation',
[u'.'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Gramps', u'Gramps Documentation',
u'.', 'Gramps', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
10268,
13408,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
428,
292,
13966,
221,
413,
4329,
26,
1703,
26,
1398,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1168,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
5761,
13408,
7,
199,
7307,
275,
399,
7,
7806,
12,
10268,
13408,
2199,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
20,
14,
18,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
20,
14,
18,
14,
16,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
5508,
63,
3220,
275,
21526,
5508,
7,
199,
5152,
63,
23046,
275,
715,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
10268,
13408,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
428,
292,
13966,
221,
413,
4329,
26,
1703,
26,
1398,
6029,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
3035,
2935,
14,
199,
3,
199,
3,
3390,
626,
440,
1006,
3962,
2897,
1338,
787,
3451,
315,
642,
199,
3,
18392,
570,
14,
199,
3,
199,
3,
2900,
2897,
1338,
1172,
282,
849,
27,
1338,
626,
787,
21804,
734,
199,
3,
14062,
370,
2498,
314,
849,
14,
199,
199,
646,
984,
12,
747,
199,
199,
3,
982,
5478,
334,
269,
4621,
370,
2213,
543,
29973,
9,
787,
315,
4573,
2082,
12,
199,
3,
1050,
3520,
6602,
370,
984,
14,
515,
2348,
14,
982,
314,
2082,
365,
3847,
370,
314,
199,
3,
3794,
1738,
12,
675,
747,
14,
515,
14,
4832,
370,
1852,
652,
3679,
12,
2839,
9164,
2348,
14,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
9858,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
10065,
63,
8008,
275,
283,
17,
14,
16,
7,
199,
199,
3,
2654,
1263,
10229,
3329,
859,
1561,
2348,
12,
465,
3326,
14,
9322,
883,
506,
5478,
199,
3,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
7869,
14,
199,
5359,
275,
942,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
7009,
2348,
12,
3847,
370,
642,
2082,
14,
199,
5876,
63,
515,
275,
4044,
5876,
418,
199,
199,
3,
710,
4739,
402,
1350,
6203,
14,
199,
1365,
63,
4511,
275,
1987,
8332,
7,
199,
199,
3,
710,
2644,
402,
1350,
1584,
14,
199,
3,
1365,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1168,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
5761,
13408,
7,
199,
7307,
275,
399,
7,
7806,
12,
10268,
13408,
2199,
7,
199,
199,
3,
710,
1015,
2256,
367,
314,
2199,
1265,
3984,
29904,
12,
17795,
465,
8343,
367,
199,
3,
1204,
1023,
92,
436,
1204,
3221,
18712,
2597,
1202,
315,
7750,
1163,
9825,
23088,
314,
199,
3,
6137,
8247,
14,
199,
3,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
283,
20,
14,
18,
7,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
283,
20,
14,
18,
14,
16,
7,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
5508,
63,
3220,
275,
21526,
5508,
7,
199,
5152,
63,
23046,
275,
715,
199,
199,
3,
6006,
787,
2877,
1511,
367,
15810,
1204,
8136,
25004,
1902,
12,
1265,
663,
11168,
370,
2005,
199,
3,
2222,
13,
3910,
574,
12,
2066,
652,
365,
1202,
26,
199,
3,
8136,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
8136,
63,
5045,
275,
1543,
34,
450,
68,
12,
450,
57,
7,
199,
199,
3,
3820,
402,
7970,
12,
3847,
370,
1350,
2082,
12,
626,
1336,
1584,
436,
199,
3,
6602,
370,
3686,
1380,
10023,
367,
1350,
1584,
14,
199,
5473,
63,
7435,
275,
4044,
1506,
418,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
8247,
14,
199,
3,
885,
63,
3756,
275,
488,
199,
199,
3,
982,
2549,
12,
26380,
911,
506,
11544,
370,
520,
1532,
26,
5423,
14,
8059,
13,
4443,
1318,
14,
199,
3,
525,
63,
1593,
63,
25510,
275,
715,
199,
199,
3,
982,
2549,
12,
314,
1453,
859,
536,
911,
506,
20247,
370,
1006,
1369,
199,
3,
4137,
16194,
334,
10180,
465,
2508,
805,
32469,
199,
3,
525,
63,
578,
63,
1247,
275,
715,
199,
199,
3,
982,
2549,
12,
3420,
2502,
436,
28966,
13502,
911,
506,
9164,
315,
314,
199,
3,
1072,
14,
9322,
787,
5525,
701,
849,
14,
199,
3,
2384,
63,
8149,
275,
756,
199,
199,
3,
710,
536,
402,
314,
14493,
334,
7093,
22437,
9,
3449,
370,
675,
14,
199,
12173,
63,
2487,
275,
283,
8008,
7,
199,
199,
3,
437,
769,
402,
5525,
13158,
367,
859,
1478,
13351,
14,
199,
3,
27555,
63,
2330,
63,
1861,
275,
942,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
9527,
2595,
199,
199,
3,
710,
8879,
370,
675,
367,
4163,
436,
4163,
15456,
6497,
14,
221,
1666,
314,
3794,
367,
199,
3,
282,
769,
402,
6762,
17915,
14,
199,
1360,
63,
7915,
275,
283,
885,
7,
199,
199,
3,
23978,
1511,
787,
8879,
13,
6100,
436,
17551,
314,
3648,
436,
23109,
402,
282,
8879,
199,
3,
9848,
14,
221,
2104,
282,
769,
402,
1511,
2808,
367,
1924,
8879,
12,
1937,
314,
199,
3,
3794,
14,
199,
3,
1360,
63,
7915,
63,
1419,
275,
1052,
199,
199,
3,
2654,
1263,
3792,
626,
1395,
3537,
17915,
2348,
12,
3847,
370,
642,
2082,
14,
199,
3,
1360,
63,
7915,
63,
515,
275,
942,
199,
199,
3,
710,
536,
367,
642,
663,
402,
10229,
8247,
14,
221,
982,
488,
12,
652,
4243,
370,
199,
3,
3886,
1715,
30,
373,
28,
3221,
30,
3794,
1674,
199,
3,
1360,
63,
1213,
275,
488,
199,
199,
3,
437,
18299,
2538,
367,
314,
19191,
4681,
14,
221,
3758,
365,
314,
2011,
465,
3517,
63,
1213,
14,
199,
3,
1360,
63,
3612,
63,
1213,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
6188,
370,
642,
2082,
9,
370,
4192,
737,
314,
2746,
199,
3,
402,
314,
18437,
14,
199,
3,
1360,
63,
9733,
275,
488,
199,
199,
3,
710,
536,
402,
376,
1834,
570,
334,
12541,
314,
2955,
931,
9,
370,
675,
465,
29139,
402,
314,
199,
3,
9149,
14,
221,
961,
570,
1077,
506,
282,
5417,
7016,
570,
17048,
12802,
9,
3769,
3193,
88,
975,
503,
4337,
88,
708,
199,
3,
11094,
7031,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BaichuanWu/Blog_on_django
|
site-packages/django/test/utils.py
|
52
|
17489
|
from contextlib import contextmanager
import logging
import re
import sys
import time
from unittest import skipUnless
import warnings
from functools import wraps
from xml.dom.minidom import parseString, Node
from django.apps import apps
from django.conf import settings, UserSettingsHolder
from django.core import mail
from django.core.signals import request_started
from django.db import reset_queries
from django.http import request
from django.template import Template, loader, TemplateDoesNotExist
from django.template.loaders import cached
from django.test.signals import template_rendered, setting_changed
from django.utils import six
from django.utils.deprecation import RemovedInDjango18Warning, RemovedInDjango19Warning
from django.utils.encoding import force_str
from django.utils.translation import deactivate
__all__ = (
'Approximate', 'ContextList', 'get_runner',
'modify_settings', 'override_settings',
'requires_tz_support',
'setup_test_environment', 'teardown_test_environment',
)
RESTORE_LOADERS_ATTR = '_original_template_source_loaders'
TZ_SUPPORT = hasattr(time, 'tzset')
class Approximate(object):
def __init__(self, val, places=7):
self.val = val
self.places = places
def __repr__(self):
return repr(self.val)
def __eq__(self, other):
if self.val == other:
return True
return round(abs(self.val - other), self.places) == 0
class ContextList(list):
"""A wrapper that provides direct key access to context items contained
in a list of context objects.
"""
def __getitem__(self, key):
if isinstance(key, six.string_types):
for subcontext in self:
if key in subcontext:
return subcontext[key]
raise KeyError(key)
else:
return super(ContextList, self).__getitem__(key)
def __contains__(self, key):
try:
self[key]
except KeyError:
return False
return True
def keys(self):
"""
Flattened keys of subcontexts.
"""
keys = set()
for subcontext in self:
for dict in subcontext:
keys |= set(dict.keys())
return keys
def instrumented_test_render(self, context):
"""
An instrumented Template render method, providing a signal
that can be intercepted by the test system Client
"""
template_rendered.send(sender=self, template=self, context=context)
return self.nodelist.render(context)
def setup_test_environment():
"""Perform any global pre-test setup. This involves:
- Installing the instrumented test renderer
- Set the email backend to the locmem email backend.
- Setting the active locale to match the LANGUAGE_CODE setting.
"""
Template._original_render = Template._render
Template._render = instrumented_test_render
# Storing previous values in the settings module itself is problematic.
# Store them in arbitrary (but related) modules instead. See #20636.
mail._original_email_backend = settings.EMAIL_BACKEND
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
request._original_allowed_hosts = settings.ALLOWED_HOSTS
settings.ALLOWED_HOSTS = ['*']
mail.outbox = []
deactivate()
def teardown_test_environment():
"""Perform any global post-test teardown. This involves:
- Restoring the original test renderer
- Restoring the email sending functions
"""
Template._render = Template._original_render
del Template._original_render
settings.EMAIL_BACKEND = mail._original_email_backend
del mail._original_email_backend
settings.ALLOWED_HOSTS = request._original_allowed_hosts
del request._original_allowed_hosts
del mail.outbox
def get_runner(settings, test_runner_class=None):
if not test_runner_class:
test_runner_class = settings.TEST_RUNNER
test_path = test_runner_class.split('.')
# Allow for Python 2.5 relative paths
if len(test_path) > 1:
test_module_name = '.'.join(test_path[:-1])
else:
test_module_name = '.'
test_module = __import__(test_module_name, {}, {}, force_str(test_path[-1]))
test_runner = getattr(test_module, test_path[-1])
return test_runner
def setup_test_template_loader(templates_dict, use_cached_loader=False):
"""
Changes Django to only find templates from within a dictionary (where each
key is the template name and each value is the corresponding template
content to return).
Use meth:`restore_template_loaders` to restore the original loaders.
"""
if hasattr(loader, RESTORE_LOADERS_ATTR):
raise Exception("loader.%s already exists" % RESTORE_LOADERS_ATTR)
def test_template_loader(template_name, template_dirs=None):
"A custom template loader that loads templates from a dictionary."
try:
return (templates_dict[template_name], "test:%s" % template_name)
except KeyError:
raise TemplateDoesNotExist(template_name)
if use_cached_loader:
template_loader = cached.Loader(('test_template_loader',))
template_loader._cached_loaders = (test_template_loader,)
else:
template_loader = test_template_loader
setattr(loader, RESTORE_LOADERS_ATTR, loader.template_source_loaders)
loader.template_source_loaders = (template_loader,)
return template_loader
def restore_template_loaders():
"""
Restores the original template loaders after
:meth:`setup_test_template_loader` has been run.
"""
loader.template_source_loaders = getattr(loader, RESTORE_LOADERS_ATTR)
delattr(loader, RESTORE_LOADERS_ATTR)
class override_settings(object):
"""
Acts as either a decorator, or a context manager. If it's a decorator it
takes a function and returns a wrapped function. If it's a contextmanager
it's used with the ``with`` statement. In either event entering/exiting
are called before and after, respectively, the function/block is executed.
"""
def __init__(self, **kwargs):
self.options = kwargs
def __enter__(self):
self.enable()
def __exit__(self, exc_type, exc_value, traceback):
self.disable()
def __call__(self, test_func):
from django.test import SimpleTestCase
if isinstance(test_func, type):
if not issubclass(test_func, SimpleTestCase):
raise Exception(
"Only subclasses of Django SimpleTestCase can be decorated "
"with override_settings")
self.save_options(test_func)
return test_func
else:
@wraps(test_func)
def inner(*args, **kwargs):
with self:
return test_func(*args, **kwargs)
return inner
def save_options(self, test_func):
if test_func._overridden_settings is None:
test_func._overridden_settings = self.options
else:
# Duplicate dict to prevent subclasses from altering their parent.
test_func._overridden_settings = dict(
test_func._overridden_settings, **self.options)
def enable(self):
# Keep this code at the beginning to leave the settings unchanged
# in case it raises an exception because INSTALLED_APPS is invalid.
if 'INSTALLED_APPS' in self.options:
try:
apps.set_installed_apps(self.options['INSTALLED_APPS'])
except Exception:
apps.unset_installed_apps()
raise
override = UserSettingsHolder(settings._wrapped)
for key, new_value in self.options.items():
setattr(override, key, new_value)
self.wrapped = settings._wrapped
settings._wrapped = override
for key, new_value in self.options.items():
setting_changed.send(sender=settings._wrapped.__class__,
setting=key, value=new_value, enter=True)
def disable(self):
if 'INSTALLED_APPS' in self.options:
apps.unset_installed_apps()
settings._wrapped = self.wrapped
del self.wrapped
for key in self.options:
new_value = getattr(settings, key, None)
setting_changed.send(sender=settings._wrapped.__class__,
setting=key, value=new_value, enter=False)
class modify_settings(override_settings):
"""
Like override_settings, but makes it possible to append, prepend or remove
items instead of redefining the entire list.
"""
def __init__(self, *args, **kwargs):
if args:
# Hack used when instantiating from SimpleTestCase._pre_setup.
assert not kwargs
self.operations = args[0]
else:
assert not args
self.operations = list(kwargs.items())
def save_options(self, test_func):
if test_func._modified_settings is None:
test_func._modified_settings = self.operations
else:
# Duplicate list to prevent subclasses from altering their parent.
test_func._modified_settings = list(
test_func._modified_settings) + self.operations
def enable(self):
self.options = {}
for name, operations in self.operations:
try:
# When called from SimpleTestCase._pre_setup, values may be
# overridden several times; cumulate changes.
value = self.options[name]
except KeyError:
value = list(getattr(settings, name, []))
for action, items in operations.items():
# items my be a single value or an iterable.
if isinstance(items, six.string_types):
items = [items]
if action == 'append':
value = value + [item for item in items if item not in value]
elif action == 'prepend':
value = [item for item in items if item not in value] + value
elif action == 'remove':
value = [item for item in value if item not in items]
else:
raise ValueError("Unsupported action: %s" % action)
self.options[name] = value
super(modify_settings, self).enable()
def override_system_checks(new_checks):
""" Acts as a decorator. Overrides list of registered system checks.
Useful when you override `INSTALLED_APPS`, e.g. if you exclude `auth` app,
you also need to exclude its system checks. """
from django.core.checks.registry import registry
def outer(test_func):
@wraps(test_func)
def inner(*args, **kwargs):
old_checks = registry.registered_checks
registry.registered_checks = new_checks
try:
return test_func(*args, **kwargs)
finally:
registry.registered_checks = old_checks
return inner
return outer
def compare_xml(want, got):
"""Tries to do a 'xml-comparison' of want and got. Plain string
comparison doesn't always work because, for example, attribute
ordering should not be important. Comment nodes are not considered in the
comparison.
Based on http://codespeak.net/svn/lxml/trunk/src/lxml/doctestcompare.py
"""
_norm_whitespace_re = re.compile(r'[ \t\n][ \t\n]+')
def norm_whitespace(v):
return _norm_whitespace_re.sub(' ', v)
def child_text(element):
return ''.join([c.data for c in element.childNodes
if c.nodeType == Node.TEXT_NODE])
def children(element):
return [c for c in element.childNodes
if c.nodeType == Node.ELEMENT_NODE]
def norm_child_text(element):
return norm_whitespace(child_text(element))
def attrs_dict(element):
return dict(element.attributes.items())
def check_element(want_element, got_element):
if want_element.tagName != got_element.tagName:
return False
if norm_child_text(want_element) != norm_child_text(got_element):
return False
if attrs_dict(want_element) != attrs_dict(got_element):
return False
want_children = children(want_element)
got_children = children(got_element)
if len(want_children) != len(got_children):
return False
for want, got in zip(want_children, got_children):
if not check_element(want, got):
return False
return True
def first_node(document):
for node in document.childNodes:
if node.nodeType != Node.COMMENT_NODE:
return node
want, got = strip_quotes(want, got)
want = want.replace('\\n', '\n')
got = got.replace('\\n', '\n')
# If the string is not a complete xml document, we may need to add a
# root element. This allow us to compare fragments, like "<foo/><bar/>"
if not want.startswith('<?xml'):
wrapper = '<root>%s</root>'
want = wrapper % want
got = wrapper % got
# Parse the want and got strings, and compare the parsings.
want_root = first_node(parseString(want))
got_root = first_node(parseString(got))
return check_element(want_root, got_root)
def strip_quotes(want, got):
"""
Strip quotes of doctests output values:
>>> strip_quotes("'foo'")
"foo"
>>> strip_quotes('"foo"')
"foo"
"""
def is_quoted_string(s):
s = s.strip()
return (len(s) >= 2
and s[0] == s[-1]
and s[0] in ('"', "'"))
def is_quoted_unicode(s):
s = s.strip()
return (len(s) >= 3
and s[0] == 'u'
and s[1] == s[-1]
and s[1] in ('"', "'"))
if is_quoted_string(want) and is_quoted_string(got):
want = want.strip()[1:-1]
got = got.strip()[1:-1]
elif is_quoted_unicode(want) and is_quoted_unicode(got):
want = want.strip()[2:-1]
got = got.strip()[2:-1]
return want, got
def str_prefix(s):
return s % {'_': '' if six.PY3 else 'u'}
class CaptureQueriesContext(object):
"""
Context manager that captures queries executed by the specified connection.
"""
def __init__(self, connection):
self.connection = connection
def __iter__(self):
return iter(self.captured_queries)
def __getitem__(self, index):
return self.captured_queries[index]
def __len__(self):
return len(self.captured_queries)
@property
def captured_queries(self):
return self.connection.queries[self.initial_queries:self.final_queries]
def __enter__(self):
self.use_debug_cursor = self.connection.use_debug_cursor
self.connection.use_debug_cursor = True
self.initial_queries = len(self.connection.queries)
self.final_queries = None
request_started.disconnect(reset_queries)
return self
def __exit__(self, exc_type, exc_value, traceback):
self.connection.use_debug_cursor = self.use_debug_cursor
request_started.connect(reset_queries)
if exc_type is not None:
return
self.final_queries = len(self.connection.queries)
class IgnoreDeprecationWarningsMixin(object):
warning_classes = [RemovedInDjango18Warning]
def setUp(self):
super(IgnoreDeprecationWarningsMixin, self).setUp()
self.catch_warnings = warnings.catch_warnings()
self.catch_warnings.__enter__()
for warning_class in self.warning_classes:
warnings.filterwarnings("ignore", category=warning_class)
def tearDown(self):
self.catch_warnings.__exit__(*sys.exc_info())
super(IgnoreDeprecationWarningsMixin, self).tearDown()
class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
warning_classes = [RemovedInDjango19Warning]
class IgnoreAllDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
warning_classes = [RemovedInDjango19Warning, RemovedInDjango18Warning]
@contextmanager
def patch_logger(logger_name, log_level):
"""
Context manager that takes a named logger and the logging level
and provides a simple mock-like list of messages received
"""
calls = []
def replacement(msg, *args, **kwargs):
calls.append(msg % args)
logger = logging.getLogger(logger_name)
orig = getattr(logger, log_level)
setattr(logger, log_level, replacement)
try:
yield calls
finally:
setattr(logger, log_level, orig)
# On OSes that don't provide tzset (Windows), we can't set the timezone
# in which the program runs. As a consequence, we must skip tests that
# don't enforce a specific timezone (with timezone.override or equivalent),
# or attempt to interpret naive datetimes in the default timezone.
requires_tz_support = skipUnless(TZ_SUPPORT,
"This test relies on the ability to run a program in an arbitrary "
"time zone, but your operating system isn't able to do that.")
@contextmanager
def extend_sys_path(*paths):
"""Context manager to temporarily add paths to sys.path."""
_orig_sys_path = sys.path[:]
sys.path.extend(paths)
try:
yield
finally:
sys.path = _orig_sys_path
|
mit
|
[
504,
15502,
492,
27608,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
504,
2882,
492,
3372,
5524,
199,
646,
3598,
199,
504,
9143,
492,
14018,
199,
504,
2748,
14,
4556,
14,
21827,
492,
2198,
1558,
12,
5013,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
2190,
492,
2202,
12,
2876,
5268,
22570,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
10458,
492,
1056,
63,
8924,
199,
504,
1639,
14,
697,
492,
5305,
63,
10590,
199,
504,
1639,
14,
1014,
492,
1056,
199,
504,
1639,
14,
1160,
492,
5458,
12,
5077,
12,
27193,
199,
504,
1639,
14,
1160,
14,
16370,
492,
6328,
199,
504,
1639,
14,
396,
14,
10458,
492,
1978,
63,
16841,
12,
4260,
63,
2489,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1085,
3849,
12,
23687,
1167,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
25560,
421,
199,
363,
452,
363,
275,
334,
272,
283,
13117,
8221,
6897,
297,
283,
2998,
1296,
297,
283,
362,
63,
5933,
297,
272,
283,
8951,
63,
1751,
297,
283,
4415,
63,
1751,
297,
272,
283,
6537,
63,
3903,
63,
4058,
297,
272,
283,
2758,
63,
396,
63,
5418,
297,
283,
15236,
63,
396,
63,
5418,
297,
199,
9,
199,
199,
15740,
5788,
63,
7405,
3960,
63,
5280,
275,
2513,
5043,
63,
1160,
63,
1365,
63,
16370,
7,
199,
14226,
63,
10640,
275,
2688,
8,
521,
12,
283,
3903,
409,
358,
421,
199,
533,
13450,
8221,
6897,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
9825,
29,
23,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
10696,
275,
9825,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
637,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
291,
14,
637,
508,
1163,
26,
288,
372,
715,
267,
372,
6168,
8,
2101,
8,
277,
14,
637,
446,
1163,
395,
291,
14,
10696,
9,
508,
378,
421,
199,
533,
9470,
1296,
8,
513,
304,
272,
408,
33,
4975,
626,
6571,
4125,
790,
2879,
370,
1067,
2974,
10470,
272,
315,
282,
769,
402,
1067,
2251,
14,
272,
408,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
1228,
8,
498,
12,
3816,
14,
875,
63,
1313,
304,
288,
367,
1007,
1100,
315,
291,
26,
355,
340,
790,
315,
1007,
1100,
26,
490,
372,
1007,
1100,
59,
498,
61,
288,
746,
4067,
8,
498,
9,
267,
587,
26,
288,
372,
1613,
8,
2998,
1296,
12,
291,
2843,
6095,
721,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
862,
26,
288,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
756,
267,
372,
715,
339,
347,
2883,
8,
277,
304,
267,
408,
267,
19005,
724,
379,
2883,
402,
1007,
19010,
14,
267,
408,
267,
2883,
275,
663,
342,
267,
367,
1007,
1100,
315,
291,
26,
288,
367,
1211,
315,
1007,
1100,
26,
355,
2883,
8901,
663,
8,
807,
14,
1612,
1012,
267,
372,
2883,
421,
199,
318,
18885,
12546,
63,
396,
63,
3352,
8,
277,
12,
1067,
304,
272,
408,
272,
1626,
18885,
12546,
5458,
3795,
1083,
12,
13070,
282,
4673,
272,
626,
883,
506,
1640,
7203,
701,
314,
511,
2656,
6810,
272,
408,
272,
1978,
63,
16841,
14,
2254,
8,
8114,
29,
277,
12,
1978,
29,
277,
12,
1067,
29,
1100,
9,
272,
372,
291,
14,
14371,
14,
3352,
8,
1100,
9,
421,
199,
318,
3272,
63,
396,
63,
5418,
837,
272,
408,
20906,
1263,
2288,
876,
13,
396,
3272,
14,
961,
25613,
2310,
26,
398,
446,
13276,
316,
314,
18885,
12546,
511,
11889,
267,
446,
2494,
314,
3031,
4865,
370,
314,
4355,
5286,
3031,
4865,
14,
267,
446,
13510,
314,
4702,
5867,
370,
1336,
314,
30508,
2962,
63,
6012,
4260,
14,
272,
408,
272,
5458,
423,
5043,
63,
3352,
275,
5458,
423,
3352,
272,
5458,
423,
3352,
275,
18885,
12546,
63,
396,
63,
3352,
339,
327,
1933,
6854,
4136,
1338,
315,
314,
2202,
859,
6337,
365,
557,
31197,
14,
272,
327,
13874,
3062,
315,
9697,
334,
7911,
4048,
9,
4621,
3140,
14,
1666,
327,
11089,
1344,
14,
339,
6016,
423,
5043,
63,
2123,
63,
4620,
275,
2202,
14,
10089,
63,
18145,
272,
2202,
14,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
2102,
5286,
14,
7035,
8447,
7,
339,
1056,
423,
5043,
63,
6541,
63,
5146,
275,
2202,
14,
17350,
63,
23775,
272,
2202,
14,
17350,
63,
23775,
275,
788,
10,
418,
339,
6016,
14,
17244,
275,
942,
339,
25560,
342,
421,
199,
318,
17558,
63,
396,
63,
5418,
837,
272,
408,
20906,
1263,
2288,
2963,
13,
396,
17558,
14,
961,
25613,
2310,
26,
398,
446,
30417,
6854,
314,
3379,
511,
11889,
267,
446,
30417,
6854,
314,
3031,
10209,
3423,
339,
408,
272,
5458,
423,
3352,
275,
5458,
423,
5043,
63,
3352,
272,
2150,
5458,
423,
5043,
63,
3352,
339,
2202,
14,
10089,
63,
18145,
275,
6016,
423,
5043,
63,
2123,
63,
4620,
272,
2150,
6016,
423,
5043,
63,
2123,
63,
4620,
339,
2202,
14,
17350,
63,
23775,
275,
1056,
423,
5043,
63,
6541,
63,
5146,
272,
2150,
1056,
423,
5043,
63,
6541,
63,
5146,
339,
2150,
6016,
14,
17244,
421,
199,
318,
664,
63,
5933,
8,
1751,
12,
511,
63,
5933,
63,
533,
29,
403,
304,
272,
340,
440,
511,
63,
5933,
63,
533,
26,
267,
511,
63,
5933,
63,
533,
275,
2202,
14,
2864,
63,
9390,
15215,
339,
511,
63,
515,
275,
511,
63,
5933,
63,
533,
14,
1294,
7563,
272,
327,
9812,
367,
2018,
499,
14,
21,
3847,
3792,
272,
340,
822,
8,
396,
63,
515,
9,
690,
413,
26,
267,
511,
63,
578,
63,
354,
275,
15671,
904,
8,
396,
63,
515,
4439,
17,
566,
272,
587,
26,
267,
511,
63,
578,
63,
354,
275,
7815,
272,
511,
63,
578,
275,
636,
646,
721,
396,
63,
578,
63,
354,
12,
5479,
5479,
3542,
63,
495,
8,
396,
63,
515,
1988,
17,
2459,
272,
511,
63,
5933,
275,
2519,
8,
396,
63,
578,
12,
511,
63,
515
] |
[
15502,
492,
27608,
199,
646,
2050,
199,
646,
295,
199,
646,
984,
199,
646,
900,
199,
504,
2882,
492,
3372,
5524,
199,
646,
3598,
199,
504,
9143,
492,
14018,
199,
504,
2748,
14,
4556,
14,
21827,
492,
2198,
1558,
12,
5013,
199,
199,
504,
1639,
14,
5181,
492,
8686,
199,
504,
1639,
14,
2190,
492,
2202,
12,
2876,
5268,
22570,
199,
504,
1639,
14,
1018,
492,
6016,
199,
504,
1639,
14,
1018,
14,
10458,
492,
1056,
63,
8924,
199,
504,
1639,
14,
697,
492,
5305,
63,
10590,
199,
504,
1639,
14,
1014,
492,
1056,
199,
504,
1639,
14,
1160,
492,
5458,
12,
5077,
12,
27193,
199,
504,
1639,
14,
1160,
14,
16370,
492,
6328,
199,
504,
1639,
14,
396,
14,
10458,
492,
1978,
63,
16841,
12,
4260,
63,
2489,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1085,
3849,
12,
23687,
1167,
3849,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
6893,
492,
25560,
421,
199,
363,
452,
363,
275,
334,
272,
283,
13117,
8221,
6897,
297,
283,
2998,
1296,
297,
283,
362,
63,
5933,
297,
272,
283,
8951,
63,
1751,
297,
283,
4415,
63,
1751,
297,
272,
283,
6537,
63,
3903,
63,
4058,
297,
272,
283,
2758,
63,
396,
63,
5418,
297,
283,
15236,
63,
396,
63,
5418,
297,
199,
9,
199,
199,
15740,
5788,
63,
7405,
3960,
63,
5280,
275,
2513,
5043,
63,
1160,
63,
1365,
63,
16370,
7,
199,
14226,
63,
10640,
275,
2688,
8,
521,
12,
283,
3903,
409,
358,
421,
199,
533,
13450,
8221,
6897,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1139,
12,
9825,
29,
23,
304,
267,
291,
14,
637,
275,
1139,
267,
291,
14,
10696,
275,
9825,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
4700,
8,
277,
14,
637,
9,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
291,
14,
637,
508,
1163,
26,
288,
372,
715,
267,
372,
6168,
8,
2101,
8,
277,
14,
637,
446,
1163,
395,
291,
14,
10696,
9,
508,
378,
421,
199,
533,
9470,
1296,
8,
513,
304,
272,
408,
33,
4975,
626,
6571,
4125,
790,
2879,
370,
1067,
2974,
10470,
272,
315,
282,
769,
402,
1067,
2251,
14,
272,
408,
272,
347,
636,
6095,
721,
277,
12,
790,
304,
267,
340,
1228,
8,
498,
12,
3816,
14,
875,
63,
1313,
304,
288,
367,
1007,
1100,
315,
291,
26,
355,
340,
790,
315,
1007,
1100,
26,
490,
372,
1007,
1100,
59,
498,
61,
288,
746,
4067,
8,
498,
9,
267,
587,
26,
288,
372,
1613,
8,
2998,
1296,
12,
291,
2843,
6095,
721,
498,
9,
339,
347,
636,
6134,
721,
277,
12,
790,
304,
267,
862,
26,
288,
291,
59,
498,
61,
267,
871,
4067,
26,
288,
372,
756,
267,
372,
715,
339,
347,
2883,
8,
277,
304,
267,
408,
267,
19005,
724,
379,
2883,
402,
1007,
19010,
14,
267,
408,
267,
2883,
275,
663,
342,
267,
367,
1007,
1100,
315,
291,
26,
288,
367,
1211,
315,
1007,
1100,
26,
355,
2883,
8901,
663,
8,
807,
14,
1612,
1012,
267,
372,
2883,
421,
199,
318,
18885,
12546,
63,
396,
63,
3352,
8,
277,
12,
1067,
304,
272,
408,
272,
1626,
18885,
12546,
5458,
3795,
1083,
12,
13070,
282,
4673,
272,
626,
883,
506,
1640,
7203,
701,
314,
511,
2656,
6810,
272,
408,
272,
1978,
63,
16841,
14,
2254,
8,
8114,
29,
277,
12,
1978,
29,
277,
12,
1067,
29,
1100,
9,
272,
372,
291,
14,
14371,
14,
3352,
8,
1100,
9,
421,
199,
318,
3272,
63,
396,
63,
5418,
837,
272,
408,
20906,
1263,
2288,
876,
13,
396,
3272,
14,
961,
25613,
2310,
26,
398,
446,
13276,
316,
314,
18885,
12546,
511,
11889,
267,
446,
2494,
314,
3031,
4865,
370,
314,
4355,
5286,
3031,
4865,
14,
267,
446,
13510,
314,
4702,
5867,
370,
1336,
314,
30508,
2962,
63,
6012,
4260,
14,
272,
408,
272,
5458,
423,
5043,
63,
3352,
275,
5458,
423,
3352,
272,
5458,
423,
3352,
275,
18885,
12546,
63,
396,
63,
3352,
339,
327,
1933,
6854,
4136,
1338,
315,
314,
2202,
859,
6337,
365,
557,
31197,
14,
272,
327,
13874,
3062,
315,
9697,
334,
7911,
4048,
9,
4621,
3140,
14,
1666,
327,
11089,
1344,
14,
339,
6016,
423,
5043,
63,
2123,
63,
4620,
275,
2202,
14,
10089,
63,
18145,
272,
2202,
14,
10089,
63,
18145,
275,
283,
1176,
14,
1018,
14,
1198,
14,
7765,
14,
2102,
5286,
14,
7035,
8447,
7,
339,
1056,
423,
5043,
63,
6541,
63,
5146,
275,
2202,
14,
17350,
63,
23775,
272,
2202,
14,
17350,
63,
23775,
275,
788,
10,
418,
339,
6016,
14,
17244,
275,
942,
339,
25560,
342,
421,
199,
318,
17558,
63,
396,
63,
5418,
837,
272,
408,
20906,
1263,
2288,
2963,
13,
396,
17558,
14,
961,
25613,
2310,
26,
398,
446,
30417,
6854,
314,
3379,
511,
11889,
267,
446,
30417,
6854,
314,
3031,
10209,
3423,
339,
408,
272,
5458,
423,
3352,
275,
5458,
423,
5043,
63,
3352,
272,
2150,
5458,
423,
5043,
63,
3352,
339,
2202,
14,
10089,
63,
18145,
275,
6016,
423,
5043,
63,
2123,
63,
4620,
272,
2150,
6016,
423,
5043,
63,
2123,
63,
4620,
339,
2202,
14,
17350,
63,
23775,
275,
1056,
423,
5043,
63,
6541,
63,
5146,
272,
2150,
1056,
423,
5043,
63,
6541,
63,
5146,
339,
2150,
6016,
14,
17244,
421,
199,
318,
664,
63,
5933,
8,
1751,
12,
511,
63,
5933,
63,
533,
29,
403,
304,
272,
340,
440,
511,
63,
5933,
63,
533,
26,
267,
511,
63,
5933,
63,
533,
275,
2202,
14,
2864,
63,
9390,
15215,
339,
511,
63,
515,
275,
511,
63,
5933,
63,
533,
14,
1294,
7563,
272,
327,
9812,
367,
2018,
499,
14,
21,
3847,
3792,
272,
340,
822,
8,
396,
63,
515,
9,
690,
413,
26,
267,
511,
63,
578,
63,
354,
275,
15671,
904,
8,
396,
63,
515,
4439,
17,
566,
272,
587,
26,
267,
511,
63,
578,
63,
354,
275,
7815,
272,
511,
63,
578,
275,
636,
646,
721,
396,
63,
578,
63,
354,
12,
5479,
5479,
3542,
63,
495,
8,
396,
63,
515,
1988,
17,
2459,
272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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
jj1bdx/wspr
|
WsprMod/iq.py
|
1
|
4726
|
#------------------------------------------------------------------ iq
from Tkinter import *
import Pmw
import g
import w
import time
import tkMessageBox
import pickle
def done():
root.withdraw()
root=Toplevel()
root.withdraw()
root.protocol('WM_DELETE_WINDOW',done)
if g.Win32: root.iconbitmap("wsjt.ico")
root.title("I-Q Mode")
def iq2(t):
root.geometry(t)
root.deiconify()
root.focus_set()
j=ib.get()
lab0.configure(text=str(mb[j])+' m')
iqmode=IntVar()
iqrx=IntVar()
iqtx=IntVar()
fiq=IntVar()
iqrxapp=IntVar()
iqrxadj=IntVar()
isc2=IntVar()
isc2.set(0)
isc2a=IntVar()
isc2a.set(0)
isc3=IntVar()
isc3.set(0)
isc3a=IntVar()
isc3a.set(0)
ib=IntVar()
gain=DoubleVar()
phdeg=DoubleVar()
mb=[0,600,160,80,60,40,30,20,17,15,12,10,6,4,2,0]
tbal=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
tpha=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
rbal=[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]
rpha=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
allbands=0
def saveband(event=NONE):
global allbands,tbal,tpha,rbal,rpha
if allbands:
for j in range(1,15):
tbal[j]=isc2.get() + 0.02*isc2a.get()
tpha[j]=isc3.get() + 0.02*isc3a.get()
rbal[j]=w.acom1.gain
rpha[j]=57.2957795*w.acom1.phase
else:
j=ib.get()
tbal[j]=isc2.get() + 0.02*isc2a.get()
tpha[j]=isc3.get() + 0.02*isc3a.get()
rbal[j]=w.acom1.gain
rpha[j]=57.2957795*w.acom1.phase
f=open(g.appdir+'/iqpickle',mode='w')
pickle.dump(tbal,f)
pickle.dump(tpha,f)
pickle.dump(rbal,f)
pickle.dump(rpha,f)
f.close()
def saveall(event=NONE):
global allbands
allbands=1
saveband()
allbands=0
def restore():
global tbal,tpha,rbal,rpha
try:
f=open(g.appdir+'/iqpickle',mode='r')
tbal=pickle.load(f)
tpha=pickle.load(f)
rbal=pickle.load(f)
rpha=pickle.load(f)
f.close()
except:
pass
newband()
def newband():
j=ib.get()
lab0.configure(text=str(mb[j])+' m')
w.acom1.gain=rbal[j]
w.acom1.phase=rpha[j]/57.2957795
isc2.set(int(tbal[j]))
isc2a.set(int((tbal[j]-isc2.get())/0.02))
isc3.set(int(tpha[j]))
isc3a.set(int((tpha[j]-isc3.get())/0.02))
#-------------------------------------------------------- Create GUI widgets
g1=Pmw.Group(root,tag_pyclass=None)
lab0=Label(g1.interior(),text='160 m',bg='yellow',pady=5)
lab0.place(x=180,y=40, anchor='e')
#lab0.pack(anchor=W,padx=5,pady=4)
biqmode=Checkbutton(g1.interior(),text='Enable I/Q mode',variable=iqmode)
biqmode.pack(anchor=W,padx=5,pady=2)
biqtx=Checkbutton(g1.interior(),text='Reverse Tx I,Q',variable=iqtx)
biqtx.pack(anchor=W,padx=5,pady=2)
biqrx=Checkbutton(g1.interior(),text='Reverse Rx I,Q',variable=iqrx)
biqrx.pack(anchor=W,padx=5,pady=2)
biqrxapp=Checkbutton(g1.interior(),text='Apply Rx phasing corrections', \
variable=iqrxapp)
biqrxapp.pack(anchor=W,padx=5,pady=2)
biqrxadj=Checkbutton(g1.interior(),text='Adjust Rx phasing', \
variable=iqrxadj)
biqrxadj.pack(anchor=W,padx=5,pady=2)
lab1=Label(g1.interior(),text='',justify=LEFT)
lab1.pack(anchor=W,padx=5,pady=4)
fiq_entry=Pmw.EntryField(g1.interior(),labelpos=W,label_text='Fiq (Hz): ',
value='12000',entry_textvariable=fiq,entry_width=10,
validate={'validator':'integer','min':-24000,'max':24000,
'minstrict':0,'maxstrict':0})
fiq_entry.pack(fill=X,padx=2,pady=4)
sc2=Scale(g1.interior(),orient=HORIZONTAL,length=200,from_=-30, \
to=30,variable=isc2,label='Tx I/Q Balance (0.1 dB)', \
relief=SOLID,bg='#EEDD82')
sc2.pack(side=TOP,padx=4,pady=2)
sc2a=Scale(g1.interior(),orient=HORIZONTAL,length=200,from_=-50, \
to=50,variable=isc2a,label='Tx I/Q Balance (0.002 dB)', \
relief=SOLID,bg='#EEDD82')
sc2a.pack(side=TOP,padx=4,pady=2)
sc3=Scale(g1.interior(),orient=HORIZONTAL,length=200,from_=-20, \
to=20,variable=isc3,label='Tx Phase (deg)', \
relief=SOLID,bg='#AFeeee')
sc3.pack(side=TOP,padx=4,pady=2)
sc3a=Scale(g1.interior(),orient=HORIZONTAL,length=200,from_=-50, \
to=50,variable=isc3a,label='Tx Phase (0.02 deg)', \
relief=SOLID,bg='#AFeeee')
sc3a.pack(side=TOP,padx=4,pady=2)
bsave=Button(g1.interior(), text='Save for this band',command=saveband,
width=32,padx=1,pady=2)
bsave.pack(padx=2,pady=4)
bsaveall=Button(g1.interior(), text='Save for all bands',command=saveall,
width=32,padx=1,pady=2)
bsaveall.pack(padx=2,pady=4)
f1=Frame(g1.interior(),width=100,height=1)
f1.pack()
g1.pack(side=LEFT,fill=BOTH,expand=1,padx=4,pady=4)
|
gpl-2.0
|
[
7656,
306,
284,
81,
199,
504,
16826,
492,
627,
199,
646,
510,
14716,
199,
646,
486,
199,
646,
336,
199,
646,
900,
199,
646,
10157,
13695,
199,
646,
5927,
199,
199,
318,
4224,
837,
272,
1738,
14,
1045,
5485,
342,
199,
199,
1231,
29,
6105,
1896,
342,
199,
1231,
14,
1045,
5485,
342,
199,
1231,
14,
3922,
360,
13073,
63,
7014,
63,
15480,
297,
4456,
9,
199,
692,
486,
14,
8886,
708,
26,
1738,
14,
4677,
20299,
480,
3569,
26002,
14,
12802,
531,
199,
1231,
14,
1213,
480,
41,
13,
49,
4900,
531,
199,
199,
318,
284,
81,
18,
8,
84,
304,
272,
1738,
14,
7660,
8,
84,
9,
272,
1738,
14,
271,
4677,
2021,
342,
272,
1738,
14,
12283,
63,
409,
342,
272,
1335,
29,
1892,
14,
362,
342,
272,
19888,
16,
14,
6472,
8,
505,
29,
495,
8,
887,
59,
74,
566,
4786,
333,
358,
199,
199,
9962,
632,
29,
3241,
5894,
342,
199,
9962,
6872,
29,
3241,
5894,
342,
199,
9962,
2347,
29,
3241,
5894,
342,
199,
329,
81,
29,
3241,
5894,
342,
199,
9962,
6872,
571,
29,
3241,
5894,
342,
199,
9962,
6872,
12551,
29,
3241,
5894,
342,
199,
199,
10840,
18,
29,
3241,
5894,
342,
199,
10840,
18,
14,
409,
8,
16,
9,
199,
10840,
18,
65,
29,
3241,
5894,
342,
199,
10840,
18,
65,
14,
409,
8,
16,
9,
199,
10840,
19,
29,
3241,
5894,
342,
199,
10840,
19,
14,
409,
8,
16,
9,
199,
10840,
19,
65,
29,
3241,
5894,
342,
199,
10840,
19,
65,
14,
409,
8,
16,
9,
199,
199,
1892,
29,
3241,
5894,
342,
199,
13020,
29,
7281,
5894,
342,
199,
838,
6458,
29,
7281,
5894,
342,
199,
887,
1524,
16,
12,
6683,
12,
8488,
12,
1257,
12,
2259,
12,
2167,
12,
1216,
12,
1165,
12,
1196,
12,
1046,
12,
713,
12,
709,
12,
22,
12,
20,
12,
18,
12,
16,
61,
199,
84,
4982,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
683,
2411,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
4848,
279,
1524,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
61,
199,
82,
2914,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
452,
23086,
29,
16,
199,
199,
318,
3354,
7877,
8,
1430,
29,
9185,
304,
272,
2288,
1006,
23086,
12,
84,
4982,
12,
683,
2411,
12,
4848,
279,
12,
82,
2914,
272,
340,
1006,
23086,
26,
267,
367,
1335,
315,
1425,
8,
17,
12,
1046,
304,
288,
307,
4982,
59,
74,
10404,
10840,
18,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
18,
65,
14,
362,
342,
288,
307,
2914,
59,
74,
10404,
10840,
19,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
19,
65,
14,
362,
342,
288,
519,
4982,
59,
74,
10404,
87,
14,
65,
957,
17,
14,
13020,
288,
519,
2914,
59,
74,
10404,
1641,
14,
11405,
1138,
2720,
10,
87,
14,
65,
957,
17,
14,
6971,
272,
587,
26,
267,
1335,
29,
1892,
14,
362,
342,
267,
307,
4982,
59,
74,
10404,
10840,
18,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
18,
65,
14,
362,
342,
267,
307,
2914,
59,
74,
10404,
10840,
19,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
19,
65,
14,
362,
342,
267,
519,
4982,
59,
74,
10404,
87,
14,
65,
957,
17,
14,
13020,
267,
519,
2914,
59,
74,
10404,
1641,
14,
11405,
1138,
2720,
10,
87,
14,
65,
957,
17,
14,
6971,
339,
289,
29,
1490,
8,
71,
14,
571,
694,
23164,
9962,
8092,
297,
632,
534,
87,
358,
272,
5927,
14,
2724,
8,
84,
4982,
12,
70,
9,
14821,
5927,
14,
2724,
8,
683,
2411,
12,
70,
9,
14821,
5927,
14,
2724,
8,
4848,
279,
12,
70,
9,
14821,
5927,
14,
2724,
8,
82,
2914,
12,
70,
9,
14821,
289,
14,
1600,
342,
199,
199,
318,
3354,
452,
8,
1430,
29,
9185,
304,
272,
2288,
1006,
23086,
272,
1006,
23086,
29,
17,
272,
3354,
7877,
342,
272,
1006,
23086,
29,
16,
199,
199,
318,
9066,
837,
272,
2288,
307,
4982,
12,
683,
2411,
12,
4848,
279,
12,
82,
2914,
272,
862,
26,
267,
289,
29,
1490,
8,
71,
14,
571,
694,
23164,
9962,
8092,
297,
632,
534,
82,
358,
267,
307,
4982,
29,
8092,
14,
912,
8,
70,
9,
267,
307,
2914,
29,
8092,
14,
912,
8,
70,
9,
267,
519,
4982,
29,
8092,
14,
912,
8,
70,
9,
267,
519,
2914,
29,
8092,
14,
912,
8,
70,
9,
267,
289,
14,
1600,
342,
272,
871,
26,
267,
986,
272,
892,
7877,
342,
199,
199,
318,
892,
7877,
837,
272,
1335,
29,
1892,
14,
362,
342,
272,
19888,
16,
14,
6472,
8,
505,
29,
495,
8,
887,
59,
74,
566,
4786,
333,
358,
272,
336,
14,
65,
957,
17,
14,
13020,
29,
4848,
279,
59,
74,
61,
272,
336,
14,
65,
957,
17
] |
[
306,
284,
81,
199,
504,
16826,
492,
627,
199,
646,
510,
14716,
199,
646,
486,
199,
646,
336,
199,
646,
900,
199,
646,
10157,
13695,
199,
646,
5927,
199,
199,
318,
4224,
837,
272,
1738,
14,
1045,
5485,
342,
199,
199,
1231,
29,
6105,
1896,
342,
199,
1231,
14,
1045,
5485,
342,
199,
1231,
14,
3922,
360,
13073,
63,
7014,
63,
15480,
297,
4456,
9,
199,
692,
486,
14,
8886,
708,
26,
1738,
14,
4677,
20299,
480,
3569,
26002,
14,
12802,
531,
199,
1231,
14,
1213,
480,
41,
13,
49,
4900,
531,
199,
199,
318,
284,
81,
18,
8,
84,
304,
272,
1738,
14,
7660,
8,
84,
9,
272,
1738,
14,
271,
4677,
2021,
342,
272,
1738,
14,
12283,
63,
409,
342,
272,
1335,
29,
1892,
14,
362,
342,
272,
19888,
16,
14,
6472,
8,
505,
29,
495,
8,
887,
59,
74,
566,
4786,
333,
358,
199,
199,
9962,
632,
29,
3241,
5894,
342,
199,
9962,
6872,
29,
3241,
5894,
342,
199,
9962,
2347,
29,
3241,
5894,
342,
199,
329,
81,
29,
3241,
5894,
342,
199,
9962,
6872,
571,
29,
3241,
5894,
342,
199,
9962,
6872,
12551,
29,
3241,
5894,
342,
199,
199,
10840,
18,
29,
3241,
5894,
342,
199,
10840,
18,
14,
409,
8,
16,
9,
199,
10840,
18,
65,
29,
3241,
5894,
342,
199,
10840,
18,
65,
14,
409,
8,
16,
9,
199,
10840,
19,
29,
3241,
5894,
342,
199,
10840,
19,
14,
409,
8,
16,
9,
199,
10840,
19,
65,
29,
3241,
5894,
342,
199,
10840,
19,
65,
14,
409,
8,
16,
9,
199,
199,
1892,
29,
3241,
5894,
342,
199,
13020,
29,
7281,
5894,
342,
199,
838,
6458,
29,
7281,
5894,
342,
199,
887,
1524,
16,
12,
6683,
12,
8488,
12,
1257,
12,
2259,
12,
2167,
12,
1216,
12,
1165,
12,
1196,
12,
1046,
12,
713,
12,
709,
12,
22,
12,
20,
12,
18,
12,
16,
61,
199,
84,
4982,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
683,
2411,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
4848,
279,
1524,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
12,
17,
14,
16,
61,
199,
82,
2914,
1524,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
12,
16,
14,
16,
61,
199,
452,
23086,
29,
16,
199,
199,
318,
3354,
7877,
8,
1430,
29,
9185,
304,
272,
2288,
1006,
23086,
12,
84,
4982,
12,
683,
2411,
12,
4848,
279,
12,
82,
2914,
272,
340,
1006,
23086,
26,
267,
367,
1335,
315,
1425,
8,
17,
12,
1046,
304,
288,
307,
4982,
59,
74,
10404,
10840,
18,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
18,
65,
14,
362,
342,
288,
307,
2914,
59,
74,
10404,
10840,
19,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
19,
65,
14,
362,
342,
288,
519,
4982,
59,
74,
10404,
87,
14,
65,
957,
17,
14,
13020,
288,
519,
2914,
59,
74,
10404,
1641,
14,
11405,
1138,
2720,
10,
87,
14,
65,
957,
17,
14,
6971,
272,
587,
26,
267,
1335,
29,
1892,
14,
362,
342,
267,
307,
4982,
59,
74,
10404,
10840,
18,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
18,
65,
14,
362,
342,
267,
307,
2914,
59,
74,
10404,
10840,
19,
14,
362,
342,
435,
378,
14,
996,
10,
10840,
19,
65,
14,
362,
342,
267,
519,
4982,
59,
74,
10404,
87,
14,
65,
957,
17,
14,
13020,
267,
519,
2914,
59,
74,
10404,
1641,
14,
11405,
1138,
2720,
10,
87,
14,
65,
957,
17,
14,
6971,
339,
289,
29,
1490,
8,
71,
14,
571,
694,
23164,
9962,
8092,
297,
632,
534,
87,
358,
272,
5927,
14,
2724,
8,
84,
4982,
12,
70,
9,
14821,
5927,
14,
2724,
8,
683,
2411,
12,
70,
9,
14821,
5927,
14,
2724,
8,
4848,
279,
12,
70,
9,
14821,
5927,
14,
2724,
8,
82,
2914,
12,
70,
9,
14821,
289,
14,
1600,
342,
199,
199,
318,
3354,
452,
8,
1430,
29,
9185,
304,
272,
2288,
1006,
23086,
272,
1006,
23086,
29,
17,
272,
3354,
7877,
342,
272,
1006,
23086,
29,
16,
199,
199,
318,
9066,
837,
272,
2288,
307,
4982,
12,
683,
2411,
12,
4848,
279,
12,
82,
2914,
272,
862,
26,
267,
289,
29,
1490,
8,
71,
14,
571,
694,
23164,
9962,
8092,
297,
632,
534,
82,
358,
267,
307,
4982,
29,
8092,
14,
912,
8,
70,
9,
267,
307,
2914,
29,
8092,
14,
912,
8,
70,
9,
267,
519,
4982,
29,
8092,
14,
912,
8,
70,
9,
267,
519,
2914,
29,
8092,
14,
912,
8,
70,
9,
267,
289,
14,
1600,
342,
272,
871,
26,
267,
986,
272,
892,
7877,
342,
199,
199,
318,
892,
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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
] |
xinwu/horizon
|
openstack_dashboard/dashboards/project/stacks/mappings.py
|
9
|
14997
|
# 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 json
import logging
from django.conf import settings
from django.core.urlresolvers import reverse
from django.template.defaultfilters import register # noqa
from django.utils import html
from django.utils import safestring
import six
import six.moves.urllib.parse as urlparse
from openstack_dashboard.api import swift
LOG = logging.getLogger(__name__)
resource_urls = {
"AWS::AutoScaling::AutoScalingGroup": {
'link': 'horizon:project:stacks:detail'},
"AWS::CloudFormation::Stack": {
'link': 'horizon:project:stacks:detail'},
"AWS::EC2::Instance": {
'link': 'horizon:project:instances:detail'},
"AWS::EC2::InternetGateway": {
'link': 'horizon:project:networks:ports:detail'},
"AWS::EC2::NetworkInterface": {
'link': 'horizon:project:networks:ports:detail'},
"AWS::EC2::RouteTable": {
'link': 'horizon:project:routers:detail'},
"AWS::EC2::SecurityGroup": {
'link': 'horizon:project:access_and_security:index'},
"AWS::EC2::Subnet": {
'link': 'horizon:project:networks:subnets:detail'},
"AWS::EC2::Volume": {
'link': 'horizon:project:volumes:volumes:detail'},
"AWS::EC2::VPC": {
'link': 'horizon:project:networks:detail'},
"AWS::S3::Bucket": {
'link': 'horizon:project:containers:index'},
"OS::Cinder::Volume": {
'link': 'horizon:project:volumes:volumes:detail'},
"OS::Heat::AccessPolicy": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::AutoScalingGroup": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::CloudConfig": {
'link': 'horizon:project:stacks:detail'},
"OS::Neutron::Firewall": {
'link': 'horizon:project:firewalls:firewalldetails'},
"OS::Neutron::FirewallPolicy": {
'link': 'horizon:project:firewalls:policydetails'},
"OS::Neutron::FirewallRule": {
'link': 'horizon:project:firewalls:ruledetails'},
"OS::Heat::HARestarter": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::InstanceGroup": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::MultipartMime": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::ResourceGroup": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::SoftwareConfig": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::StructuredConfig": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::StructuredDeployment": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::Stack": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::WaitCondition": {
'link': 'horizon:project:stacks:detail'},
"OS::Heat::WaitConditionHandle": {
'link': 'horizon:project:stacks:detail'},
"OS::Neutron::HealthMonitor": {
'link': 'horizon:project:loadbalancers:monitordetails'},
"OS::Neutron::IKEPolicy": {
'link': 'horizon:project:vpn:ikepolicydetails'},
"OS::Neutron::IPsecPolicy": {
'link': 'horizon:project:vpn:ipsecpolicydetails'},
"OS::Neutron::IPsecSiteConnection": {
'link': 'horizon:project:vpn:ipsecsiteconnectiondetails'},
"OS::Neutron::Net": {
'link': 'horizon:project:networks:detail'},
"OS::Neutron::Pool": {
'link': 'horizon:project:loadbalancers:pooldetails'},
"OS::Neutron::PoolMember": {
'link': 'horizon:project:loadbalancers:memberdetails'},
"OS::Neutron::Port": {
'link': 'horizon:project:networks:ports:detail'},
"OS::Neutron::Router": {
'link': 'horizon:project:routers:detail'},
"OS::Neutron::Subnet": {
'link': 'horizon:project:networks:subnets:detail'},
"OS::Neutron::VPNService": {
'link': 'horizon:project:vpn:vpnservicedetails'},
"OS::Nova::KeyPair": {
'link': 'horizon:project:access_and_security:index'},
"OS::Nova::Server": {
'link': 'horizon:project:instances:detail'},
"OS::Swift::Container": {
'link': 'horizon:project:containers:index',
'format_pattern': '%s' + swift.FOLDER_DELIMITER},
}
def resource_to_url(resource):
if not resource or not resource.physical_resource_id:
return None
mapping = resource_urls.get(resource.resource_type, {})
try:
if 'link' not in mapping:
return None
format_pattern = mapping.get('format_pattern') or '%s'
rid = format_pattern % resource.physical_resource_id
url = reverse(mapping['link'], args=(rid,))
except Exception as e:
LOG.exception(e)
return None
return url
@register.filter
def stack_output(output):
if not output:
return u''
if isinstance(output, basestring):
parts = urlparse.urlsplit(output)
if parts.netloc and parts.scheme in ('http', 'https'):
url = html.escape(output)
safe_link = u'<a href="%s" target="_blank">%s</a>' % (url, url)
return safestring.mark_safe(safe_link)
if isinstance(output, dict) or isinstance(output, list):
output = json.dumps(output, indent=2)
return safestring.mark_safe(u'<pre>%s</pre>' % html.escape(output))
static_url = getattr(settings, "STATIC_URL", "/static/")
resource_images = {
'LB_FAILED': static_url + 'dashboard/img/lb-red.svg',
'LB_DELETE': static_url + 'dashboard/img/lb-red.svg',
'LB_IN_PROGRESS': static_url + 'dashboard/img/lb-gray.gif',
'LB_INIT': static_url + 'dashboard/img/lb-gray.svg',
'LB_COMPLETE': static_url + 'dashboard/img/lb-green.svg',
'DB_FAILED': static_url + 'dashboard/img/db-red.svg',
'DB_DELETE': static_url + 'dashboard/img/db-red.svg',
'DB_IN_PROGRESS': static_url + 'dashboard/img/db-gray.gif',
'DB_INIT': static_url + 'dashboard/img/db-gray.svg',
'DB_COMPLETE': static_url + 'dashboard/img/db-green.svg',
'STACK_FAILED': static_url + 'dashboard/img/stack-red.svg',
'STACK_DELETE': static_url + 'dashboard/img/stack-red.svg',
'STACK_IN_PROGRESS': static_url + 'dashboard/img/stack-gray.gif',
'STACK_INIT': static_url + 'dashboard/img/stack-gray.svg',
'STACK_COMPLETE': static_url + 'dashboard/img/stack-green.svg',
'SERVER_FAILED': static_url + 'dashboard/img/server-red.svg',
'SERVER_DELETE': static_url + 'dashboard/img/server-red.svg',
'SERVER_IN_PROGRESS': static_url + 'dashboard/img/server-gray.gif',
'SERVER_INIT': static_url + 'dashboard/img/server-gray.svg',
'SERVER_COMPLETE': static_url + 'dashboard/img/server-green.svg',
'ALARM_FAILED': static_url + 'dashboard/img/alarm-red.svg',
'ALARM_DELETE': static_url + 'dashboard/img/alarm-red.svg',
'ALARM_IN_PROGRESS': static_url + 'dashboard/img/alarm-gray.gif',
'ALARM_INIT': static_url + 'dashboard/img/alarm-gray.svg',
'ALARM_COMPLETE': static_url + 'dashboard/img/alarm-green.svg',
'VOLUME_FAILED': static_url + 'dashboard/img/volume-red.svg',
'VOLUME_DELETE': static_url + 'dashboard/img/volume-red.svg',
'VOLUME_IN_PROGRESS': static_url + 'dashboard/img/volume-gray.gif',
'VOLUME_INIT': static_url + 'dashboard/img/volume-gray.svg',
'VOLUME_COMPLETE': static_url + 'dashboard/img/volume-green.svg',
'IMAGE_FAILED': static_url + 'dashboard/img/image-red.svg',
'IMAGE_DELETE': static_url + 'dashboard/img/image-red.svg',
'IMAGE_IN_PROGRESS': static_url + 'dashboard/img/image-gray.gif',
'IMAGE_INIT': static_url + 'dashboard/img/image-gray.svg',
'IMAGE_COMPLETE': static_url + 'dashboard/img/image-green.svg',
'WAIT_FAILED': static_url + 'dashboard/img/wait-red.svg',
'WAIT_DELETE': static_url + 'dashboard/img/wait-red.svg',
'WAIT_IN_PROGRESS': static_url + 'dashboard/img/wait-gray.gif',
'WAIT_INIT': static_url + 'dashboard/img/wait-gray.svg',
'WAIT_COMPLETE': static_url + 'dashboard/img/wait-green.svg',
'FIREWALL_FAILED': static_url + 'dashboard/img/firewall-red.svg',
'FIREWALL_DELETE': static_url + 'dashboard/img/firewall-red.svg',
'FIREWALL_IN_PROGRESS': static_url + 'dashboard/img/firewall-gray.gif',
'FIREWALL_INIT': static_url + 'dashboard/img/firewall-gray.svg',
'FIREWALL_COMPLETE': static_url + 'dashboard/img/firewall-green.svg',
'FLOATINGIP_FAILED': static_url + 'dashboard/img/floatingip-red.svg',
'FLOATINGIP_DELETE': static_url + 'dashboard/img/floatingip-red.svg',
'FLOATINGIP_IN_PROGRESS': static_url + 'dashboard/img/floatingip-gray.gif',
'FLOATINGIP_INIT': static_url + 'dashboard/img/floatingip-gray.svg',
'FLOATINGIP_COMPLETE': static_url + 'dashboard/img/floatingip-green.svg',
'ROUTER_FAILED': static_url + 'dashboard/img/router-red.svg',
'ROUTER_DELETE': static_url + 'dashboard/img/router-red.svg',
'ROUTER_IN_PROGRESS': static_url + 'dashboard/img/router-gray.gif',
'ROUTER_INIT': static_url + 'dashboard/img/router-gray.svg',
'ROUTER_COMPLETE': static_url + 'dashboard/img/router-green.svg',
'POLICY_FAILED': static_url + 'dashboard/img/policy-red.svg',
'POLICY_DELETE': static_url + 'dashboard/img/policy-red.svg',
'POLICY_IN_PROGRESS': static_url + 'dashboard/img/policy-gray.gif',
'POLICY_INIT': static_url + 'dashboard/img/policy-gray.svg',
'POLICY_COMPLETE': static_url + 'dashboard/img/policy-green.svg',
'CONFIG_FAILED': static_url + 'dashboard/img/config-red.svg',
'CONFIG_DELETE': static_url + 'dashboard/img/config-red.svg',
'CONFIG_IN_PROGRESS': static_url + 'dashboard/img/config-gray.gif',
'CONFIG_INIT': static_url + 'dashboard/img/config-gray.svg',
'CONFIG_COMPLETE': static_url + 'dashboard/img/config-green.svg',
'NETWORK_FAILED': static_url + 'dashboard/img/network-red.svg',
'NETWORK_DELETE': static_url + 'dashboard/img/network-red.svg',
'NETWORK_IN_PROGRESS': static_url + 'dashboard/img/network-gray.gif',
'NETWORK_INIT': static_url + 'dashboard/img/network-gray.svg',
'NETWORK_COMPLETE': static_url + 'dashboard/img/network-green.svg',
'PORT_FAILED': static_url + 'dashboard/img/port-red.svg',
'PORT_DELETE': static_url + 'dashboard/img/port-red.svg',
'PORT_IN_PROGRESS': static_url + 'dashboard/img/port-gray.gif',
'PORT_INIT': static_url + 'dashboard/img/port-gray.svg',
'PORT_COMPLETE': static_url + 'dashboard/img/port-green.svg',
'SECURITYGROUP_FAILED': static_url + 'dashboard/img/securitygroup-red.svg',
'SECURITYGROUP_DELETE': static_url + 'dashboard/img/securitygroup-red.svg',
'SECURITYGROUP_IN_PROGRESS':
static_url + 'dashboard/img/securitygroup-gray.gif',
'SECURITYGROUP_INIT': static_url + 'dashboard/img/securitygroup-gray.svg',
'SECURITYGROUP_COMPLETE':
static_url + 'dashboard/img/securitygroup-green.svg',
'VPN_FAILED': static_url + 'dashboard/img/vpn-red.svg',
'VPN_DELETE': static_url + 'dashboard/img/vpn-red.svg',
'VPN_IN_PROGRESS': static_url + 'dashboard/img/vpn-gray.gif',
'VPN_INIT': static_url + 'dashboard/img/vpn-gray.svg',
'VPN_COMPLETE': static_url + 'dashboard/img/vpn-green.svg',
'FLAVOR_FAILED': static_url + 'dashboard/img/flavor-red.svg',
'FLAVOR_DELETE': static_url + 'dashboard/img/flavor-red.svg',
'FLAVOR_IN_PROGRESS': static_url + 'dashboard/img/flavor-gray.gif',
'FLAVOR_INIT': static_url + 'dashboard/img/flavor-gray.svg',
'FLAVOR_COMPLETE': static_url + 'dashboard/img/flavor-green.svg',
'KEYPAIR_FAILED': static_url + 'dashboard/img/keypair-red.svg',
'KEYPAIR_DELETE': static_url + 'dashboard/img/keypair-red.svg',
'KEYPAIR_IN_PROGRESS': static_url + 'dashboard/img/keypair-gray.gif',
'KEYPAIR_INIT': static_url + 'dashboard/img/keypair-gray.svg',
'KEYPAIR_COMPLETE': static_url + 'dashboard/img/keypair-green.svg',
'UNKNOWN_FAILED': static_url + 'dashboard/img/unknown-red.svg',
'UNKNOWN_DELETE': static_url + 'dashboard/img/unknown-red.svg',
'UNKNOWN_IN_PROGRESS': static_url + 'dashboard/img/unknown-gray.gif',
'UNKNOWN_INIT': static_url + 'dashboard/img/unknown-gray.svg',
'UNKNOWN_COMPLETE': static_url + 'dashboard/img/unknown-green.svg',
}
resource_types = {
# LB
'LoadBalance': 'LB',
'HealthMonitor': 'LB',
'PoolMember': 'LB',
'Pool': 'LB',
# DB
'DBInstance': 'DB',
'Database': 'DB',
# SERVER
'Instance': 'SERVER',
'Server': 'SERVER',
# ALARM
'Alarm': 'ALARM',
'CombinationAlarm': 'ALARM',
'CWLiteAlarm': 'ALARM',
# VOLUME
'Volume': 'VOLUME',
'VolumeAttachment': 'VOLUME',
# STACK
'stack': 'STACK',
'AutoScalingGroup': 'STACK',
'InstanceGroup': 'STACK',
'ServerGroup': 'STACK',
'ResourceGroup': 'STACK',
# IMAGE
'Image': 'IMAGE',
# WAIT
'WaitCondition': 'WAIT',
'WaitConditionHandle': 'WAIT',
'UpdateWaitConditionHandle': 'WAIT',
# FIREWALL
'Firewall': 'FIREWALL',
'FirewallPolicy': 'FIREWALL',
'FirewallRule': 'FIREWALL',
# FLOATINGIP
'FloatingIP': 'FLOATINGIP',
'FloatingIPAssociation': 'FLOATINGIP',
# ROUTER
'Router': 'ROUTER',
'RouterGateway': 'ROUTER',
'RouterInterface': 'ROUTER',
# POLICY
'ScalingPolicy': 'POLICY',
# CONFIG
'CloudConfig': 'CONFIG',
'MultipartMime': 'CONFIG',
'SoftwareConfig': 'CONFIG',
'SoftwareDeployment': 'CONFIG',
'StructuredConfig': 'CONFIG',
'StructuredDeployment': 'CONFIG',
# NETWORK
'Net': 'NETWORK',
'Subnet': 'NETWORK',
'NetworkGateway': 'NETWORK',
'ProviderNet': 'NETWORK',
# PORT
'Port': 'PORT',
# SECURITYGROUP
'SecurityGroup': 'SECURITYGROUP',
# VPN
'VPNService': 'VPN',
# FLAVOR
'Flavor': 'FLAVOR',
# KEYPAIR
'KeyPair': 'KEYPAIR',
}
def get_resource_type(type):
for key, value in six.iteritems(resource_types):
if key in type:
return value
return 'UNKNOWN'
def get_resource_status(status):
if ('IN_PROGRESS' in status):
return 'IN_PROGRESS'
elif ('FAILED' in status):
return 'FAILED'
elif ('DELETE' in status):
return 'DELETE'
elif ('INIT' in status):
return 'INIT'
else:
return 'COMPLETE'
def get_resource_image(status, type):
"""Sets the image url and in_progress action sw based on status."""
resource_type = get_resource_type(type)
resource_status = get_resource_status(status)
resource_state = resource_type + "_" + resource_status
for key in resource_images:
if key == resource_state:
return resource_images.get(key)
|
apache-2.0
|
[
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,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
14,
885,
4273,
492,
2274,
221,
327,
8151,
199,
504,
1639,
14,
1208,
492,
3517,
199,
504,
1639,
14,
1208,
492,
5048,
875,
199,
646,
3816,
199,
646,
3816,
14,
4912,
14,
4078,
14,
1122,
465,
7097,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
16275,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
1927,
63,
3603,
275,
469,
272,
298,
13226,
447,
3358,
26416,
447,
3358,
26416,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
13226,
447,
9089,
1858,
1615,
447,
4851,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
3244,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
5990,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
29820,
12455,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5203,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
4491,
4267,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5203,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
7161,
3186,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
17292,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
19280,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
2732,
63,
460,
63,
4416,
26,
1080,
2267,
272,
298,
13226,
447,
4220,
18,
447,
15238,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
14967,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
6464,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
8838,
26,
8838,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
54,
4222,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5506,
2267,
272,
298,
13226,
447,
51,
19,
447,
12311,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
13577,
26,
1080,
2267,
272,
298,
3100,
447,
35,
5755,
447,
6464,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
8838,
26,
8838,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3946,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3358,
26416,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
9089,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
10794,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
5065,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
2200,
5087,
2267,
272,
298,
3100,
447,
30770,
447,
6294,
497,
7848,
351,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3244,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27242,
45,
1036,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
4031,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
10337,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27486,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27486,
25434,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
4851,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
7536,
9558,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
7536,
9558,
5940,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
20915,
447,
18850,
13189,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
912,
29674,
26,
7157,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
41,
2430,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
7455,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
1772,
3321,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
19867,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
1772,
3321,
8972,
3225,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
19867,
2124,
2105,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
2480,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5506,
2267,
272,
298
] |
[
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,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1160,
14,
885,
4273,
492,
2274,
221,
327,
8151,
199,
504,
1639,
14,
1208,
492,
3517,
199,
504,
1639,
14,
1208,
492,
5048,
875,
199,
646,
3816,
199,
646,
3816,
14,
4912,
14,
4078,
14,
1122,
465,
7097,
199,
199,
504,
13869,
63,
9743,
14,
1246,
492,
16275,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
1927,
63,
3603,
275,
469,
272,
298,
13226,
447,
3358,
26416,
447,
3358,
26416,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
13226,
447,
9089,
1858,
1615,
447,
4851,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
3244,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
5990,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
29820,
12455,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5203,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
4491,
4267,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5203,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
7161,
3186,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
17292,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
19280,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
2732,
63,
460,
63,
4416,
26,
1080,
2267,
272,
298,
13226,
447,
4220,
18,
447,
15238,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
14967,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
6464,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
8838,
26,
8838,
26,
5506,
2267,
272,
298,
13226,
447,
4220,
18,
447,
54,
4222,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
26,
5506,
2267,
272,
298,
13226,
447,
51,
19,
447,
12311,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
13577,
26,
1080,
2267,
272,
298,
3100,
447,
35,
5755,
447,
6464,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
8838,
26,
8838,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3946,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3358,
26416,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
9089,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
10794,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
24260,
5065,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
10794,
83,
26,
2200,
5087,
2267,
272,
298,
3100,
447,
30770,
447,
6294,
497,
7848,
351,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
3244,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27242,
45,
1036,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
4031,
2448,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
10337,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27486,
2028,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
27486,
25434,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
4851,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
7536,
9558,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
30770,
447,
7536,
9558,
5940,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
21707,
26,
5506,
2267,
272,
298,
3100,
447,
20915,
447,
18850,
13189,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
912,
29674,
26,
7157,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
41,
2430,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
7455,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
1772,
3321,
4845,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
19867,
3185,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
1772,
3321,
8972,
3225,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
9702,
26,
19867,
2124,
2105,
5087,
2267,
272,
298,
3100,
447,
20915,
447,
2480,
582,
469,
267,
283,
1073,
356,
283,
16561,
26,
1715,
26,
7642,
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1,
1,
1,
1,
1,
1,
1,
1
] |
zestyr/lbry
|
lbrynet/core/server/ServerRequestHandler.py
|
1
|
5866
|
import json
import logging
from twisted.internet import interfaces, defer
from zope.interface import implements
from lbrynet.interfaces import IRequestHandler
log = logging.getLogger(__name__)
class ServerRequestHandler(object):
"""This class handles requests from clients. It can upload blobs and
return request for information about more blobs that are
associated with streams.
"""
implements(interfaces.IPushProducer, interfaces.IConsumer, IRequestHandler)
def __init__(self, consumer):
self.consumer = consumer
self.production_paused = False
self.request_buff = ''
self.response_buff = ''
self.producer = None
self.request_received = False
self.CHUNK_SIZE = 2**14
self.query_handlers = {} # {IQueryHandler: [query_identifiers]}
self.blob_sender = None
self.consumer.registerProducer(self, True)
#IPushProducer stuff
def pauseProducing(self):
self.production_paused = True
def stopProducing(self):
if self.producer is not None:
self.producer.stopProducing()
self.producer = None
self.production_paused = True
self.consumer.unregisterProducer()
def resumeProducing(self):
from twisted.internet import reactor
self.production_paused = False
self._produce_more()
if self.producer is not None:
reactor.callLater(0, self.producer.resumeProducing)
def _produce_more(self):
from twisted.internet import reactor
if self.production_paused:
return
chunk = self.response_buff[:self.CHUNK_SIZE]
self.response_buff = self.response_buff[self.CHUNK_SIZE:]
if chunk == '':
return
log.trace("writing %s bytes to the client", len(chunk))
self.consumer.write(chunk)
reactor.callLater(0, self._produce_more)
#IConsumer stuff
def registerProducer(self, producer, streaming):
self.producer = producer
assert streaming is False
producer.resumeProducing()
def unregisterProducer(self):
self.producer = None
def write(self, data):
from twisted.internet import reactor
self.response_buff = self.response_buff + data
self._produce_more()
def get_more_data():
if self.producer is not None:
log.trace("Requesting more data from the producer")
self.producer.resumeProducing()
reactor.callLater(0, get_more_data)
#From Protocol
def data_received(self, data):
log.debug("Received data")
log.debug("%s", str(data))
if self.request_received is False:
return self._parse_data_and_maybe_send_blob(data)
else:
log.warning(
"The client sent data when we were uploading a file. This should not happen")
def _parse_data_and_maybe_send_blob(self, data):
self.request_buff = self.request_buff + data
msg = self.try_to_parse_request(self.request_buff)
if msg:
self.request_buff = ''
self._process_msg(msg)
else:
log.debug("Request buff not a valid json message")
log.debug("Request buff: %s", self.request_buff)
def _process_msg(self, msg):
d = self.handle_request(msg)
if self.blob_sender:
d.addCallback(lambda _: self.blob_sender.send_blob_if_requested(self))
d.addCallbacks(lambda _: self.finished_response(), self.request_failure_handler)
######### IRequestHandler #########
def register_query_handler(self, query_handler, query_identifiers):
self.query_handlers[query_handler] = query_identifiers
def register_blob_sender(self, blob_sender):
self.blob_sender = blob_sender
#response handling
def request_failure_handler(self, err):
log.warning("An error occurred handling a request. Error: %s", err.getErrorMessage())
self.stopProducing()
return err
def finished_response(self):
self.request_received = False
self._produce_more()
def send_response(self, msg):
m = json.dumps(msg)
log.debug("Sending a response of length %s", str(len(m)))
log.debug("Response: %s", str(m))
self.response_buff = self.response_buff + m
self._produce_more()
return True
def handle_request(self, msg):
log.debug("Handling a request")
log.debug(str(msg))
def create_response_message(results):
response = {}
for success, result in results:
if success is True:
response.update(result)
else:
# result is a Failure
return result
log.debug("Finished making the response message. Response: %s", str(response))
return response
def log_errors(err):
log.warning(
"An error occurred handling a client request. Error message: %s",
err.getErrorMessage())
return err
def send_response(response):
self.send_response(response)
return True
ds = []
for query_handler, query_identifiers in self.query_handlers.iteritems():
queries = {q_i: msg[q_i] for q_i in query_identifiers if q_i in msg}
d = query_handler.handle_queries(queries)
d.addErrback(log_errors)
ds.append(d)
dl = defer.DeferredList(ds)
dl.addCallback(create_response_message)
dl.addCallback(send_response)
return dl
def try_to_parse_request(self, request_buff):
try:
msg = json.loads(request_buff)
return msg
except ValueError:
return None
|
mit
|
[
646,
2022,
199,
646,
2050,
199,
504,
7390,
14,
4901,
492,
8386,
12,
10133,
199,
504,
20110,
14,
3266,
492,
9031,
199,
504,
11104,
651,
846,
14,
7436,
492,
473,
11149,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
7146,
11149,
8,
785,
304,
272,
408,
2765,
1021,
10022,
4145,
687,
13431,
14,
2779,
883,
5802,
9182,
83,
436,
272,
372,
1056,
367,
2556,
3595,
1655,
9182,
83,
626,
787,
272,
4568,
543,
13788,
14,
272,
408,
272,
9031,
8,
7436,
14,
1772,
2084,
15532,
12,
8386,
14,
41,
18186,
12,
473,
11149,
9,
339,
347,
636,
826,
721,
277,
12,
9790,
304,
267,
291,
14,
8542,
275,
9790,
267,
291,
14,
10777,
63,
22478,
275,
756,
267,
291,
14,
1069,
63,
16830,
275,
2125,
267,
291,
14,
1310,
63,
16830,
275,
2125,
267,
291,
14,
16376,
275,
488,
267,
291,
14,
1069,
63,
9226,
275,
756,
267,
291,
14,
20512,
63,
4305,
275,
499,
538,
1079,
267,
291,
14,
1131,
63,
5586,
275,
1052,
221,
327,
469,
41,
3227,
2461,
26,
359,
1131,
63,
14227,
9420,
267,
291,
14,
6582,
63,
8114,
275,
488,
267,
291,
14,
8542,
14,
2683,
15532,
8,
277,
12,
715,
9,
339,
327,
1772,
2084,
15532,
8292,
339,
347,
16834,
24982,
8,
277,
304,
267,
291,
14,
10777,
63,
22478,
275,
715,
339,
347,
3631,
24982,
8,
277,
304,
267,
340,
291,
14,
16376,
365,
440,
488,
26,
288,
291,
14,
16376,
14,
2379,
24982,
342,
288,
291,
14,
16376,
275,
488,
267,
291,
14,
10777,
63,
22478,
275,
715,
267,
291,
14,
8542,
14,
18408,
15532,
342,
339,
347,
14604,
24982,
8,
277,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
291,
14,
10777,
63,
22478,
275,
756,
267,
291,
423,
7832,
63,
6878,
342,
267,
340,
291,
14,
16376,
365,
440,
488,
26,
288,
9655,
14,
1250,
22028,
8,
16,
12,
291,
14,
16376,
14,
9964,
24982,
9,
339,
347,
485,
7832,
63,
6878,
8,
277,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
340,
291,
14,
10777,
63,
22478,
26,
288,
372,
267,
3728,
275,
291,
14,
1310,
63,
16830,
1491,
277,
14,
20512,
63,
4305,
61,
267,
291,
14,
1310,
63,
16830,
275,
291,
14,
1310,
63,
16830,
59,
277,
14,
20512,
63,
4305,
2938,
267,
340,
3728,
508,
8061,
288,
372,
267,
943,
14,
3446,
480,
14827,
450,
83,
2783,
370,
314,
1890,
401,
822,
8,
4604,
430,
267,
291,
14,
8542,
14,
952,
8,
4604,
9,
267,
9655,
14,
1250,
22028,
8,
16,
12,
291,
423,
7832,
63,
6878,
9,
339,
327,
41,
18186,
8292,
339,
347,
2274,
15532,
8,
277,
12,
17339,
12,
18490,
304,
267,
291,
14,
16376,
275,
17339,
267,
702,
18490,
365,
756,
267,
17339,
14,
9964,
24982,
342,
339,
347,
24369,
15532,
8,
277,
304,
267,
291,
14,
16376,
275,
488,
339,
347,
2218,
8,
277,
12,
666,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
291,
14,
1310,
63,
16830,
275,
291,
14,
1310,
63,
16830,
435,
666,
267,
291,
423,
7832,
63,
6878,
342,
398,
347,
664,
63,
6878,
63,
576,
837,
288,
340,
291,
14,
16376,
365,
440,
488,
26,
355,
943,
14,
3446,
480,
2017,
316,
1655,
666,
687,
314,
17339,
531,
355,
291,
14,
16376,
14,
9964,
24982,
342,
398,
9655,
14,
1250,
22028,
8,
16,
12,
664,
63,
6878,
63,
576,
9,
339,
327,
2532,
11557,
339,
347,
666,
63,
9226,
8,
277,
12,
666,
304,
267,
943,
14,
1757,
480,
9392,
666,
531,
267,
943,
14,
1757,
3647,
83,
401,
620,
8,
576,
430,
267,
340,
291,
14,
1069,
63,
9226,
365,
756,
26,
288,
372,
291,
423,
1122,
63,
576,
63,
460,
63,
11853,
63,
2254,
63,
6582,
8,
576,
9,
267,
587,
26,
288,
943,
14,
3764,
8,
355,
298,
1918,
1890,
4847,
666,
1380,
781,
4898,
24349,
282,
570,
14,
961,
1077,
440,
5992,
531,
339,
347,
485,
1122,
63,
576,
63,
460,
63,
11853,
63,
2254,
63,
6582,
8,
277,
12,
666,
304,
267,
291,
14,
1069,
63,
16830,
275,
291,
14,
1069,
63,
16830,
435,
666,
267,
1499,
275,
291,
14,
893,
63,
475,
63,
1122,
63,
1069,
8,
277,
14,
1069,
63,
16830,
9,
267,
340,
1499,
26,
288,
291,
14,
1069,
63,
16830,
275,
2125,
288,
291,
423,
1412,
63,
1328,
8,
1328,
9,
267,
587,
26,
288,
943,
14,
1757,
480,
2017,
17893,
440,
282,
1686,
2022,
1245,
531,
288,
943,
14,
1757,
480,
2017,
17893,
26,
450,
83,
401,
291,
14,
1069,
63,
16830,
9,
339,
347,
485,
1412,
63,
1328,
8,
277,
12,
1499,
304,
267,
366,
275,
291,
14,
2479,
63,
1069,
8,
1328,
9,
267,
340,
291,
14,
6582,
63,
8114,
26,
288,
366,
14,
10053,
8,
2734,
24700,
291,
14,
6582,
63,
8114,
14,
2254,
63,
6582,
63,
692,
63,
11151,
8,
277,
430,
267,
366,
14,
10053,
83,
8,
2734,
24700,
291,
14,
8669,
63,
1310,
1062,
291,
14,
1069,
63,
5328,
63,
2232,
9,
2378,
21937,
3,
473,
11149,
21937,
3,
339,
347,
2274,
63,
1131,
63,
2232,
8,
277,
12,
1827,
63,
2232,
12,
1827,
63,
14227,
304,
267,
291,
14,
1131,
63,
5586,
59,
1131,
63,
2232,
61,
275,
1827,
63,
14227,
339,
347,
2274,
63,
6582,
63,
8114,
8,
277,
12,
9182,
63,
8114,
304,
267,
291,
14,
6582,
63,
8114,
275,
9182,
63,
8114,
339,
327,
1310,
7252,
339,
347,
1056,
63,
5328,
63,
2232,
8,
277,
12,
2329,
304,
267,
943,
14,
3764,
480,
2493,
1125,
8920,
7252,
282,
1056,
14,
4520,
26,
450,
83,
401,
2329,
14,
362,
547,
2209,
1012,
267,
291,
14,
2379,
24982,
342,
267,
372,
2329,
339,
347,
9158,
63,
1310,
8,
277,
304,
267,
291,
14,
1069,
63,
9226,
275,
756,
267,
291,
423,
7832,
63,
6878,
342,
339,
347,
3222,
63,
1310,
8,
277,
12,
1499,
304,
267,
333,
275,
2022,
14,
4180,
8,
1328,
9,
267,
943,
14,
1757,
480,
27219,
282,
1177,
402,
2582,
450,
83,
401,
620,
8,
552,
8,
77,
1724,
267,
943,
14,
1757,
480,
2364,
26,
450,
83,
401,
620,
8,
77,
430,
267,
291,
14,
1310,
63,
16830
] |
[
2022,
199,
646,
2050,
199,
504,
7390,
14,
4901,
492,
8386,
12,
10133,
199,
504,
20110,
14,
3266,
492,
9031,
199,
504,
11104,
651,
846,
14,
7436,
492,
473,
11149,
421,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
7146,
11149,
8,
785,
304,
272,
408,
2765,
1021,
10022,
4145,
687,
13431,
14,
2779,
883,
5802,
9182,
83,
436,
272,
372,
1056,
367,
2556,
3595,
1655,
9182,
83,
626,
787,
272,
4568,
543,
13788,
14,
272,
408,
272,
9031,
8,
7436,
14,
1772,
2084,
15532,
12,
8386,
14,
41,
18186,
12,
473,
11149,
9,
339,
347,
636,
826,
721,
277,
12,
9790,
304,
267,
291,
14,
8542,
275,
9790,
267,
291,
14,
10777,
63,
22478,
275,
756,
267,
291,
14,
1069,
63,
16830,
275,
2125,
267,
291,
14,
1310,
63,
16830,
275,
2125,
267,
291,
14,
16376,
275,
488,
267,
291,
14,
1069,
63,
9226,
275,
756,
267,
291,
14,
20512,
63,
4305,
275,
499,
538,
1079,
267,
291,
14,
1131,
63,
5586,
275,
1052,
221,
327,
469,
41,
3227,
2461,
26,
359,
1131,
63,
14227,
9420,
267,
291,
14,
6582,
63,
8114,
275,
488,
267,
291,
14,
8542,
14,
2683,
15532,
8,
277,
12,
715,
9,
339,
327,
1772,
2084,
15532,
8292,
339,
347,
16834,
24982,
8,
277,
304,
267,
291,
14,
10777,
63,
22478,
275,
715,
339,
347,
3631,
24982,
8,
277,
304,
267,
340,
291,
14,
16376,
365,
440,
488,
26,
288,
291,
14,
16376,
14,
2379,
24982,
342,
288,
291,
14,
16376,
275,
488,
267,
291,
14,
10777,
63,
22478,
275,
715,
267,
291,
14,
8542,
14,
18408,
15532,
342,
339,
347,
14604,
24982,
8,
277,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
291,
14,
10777,
63,
22478,
275,
756,
267,
291,
423,
7832,
63,
6878,
342,
267,
340,
291,
14,
16376,
365,
440,
488,
26,
288,
9655,
14,
1250,
22028,
8,
16,
12,
291,
14,
16376,
14,
9964,
24982,
9,
339,
347,
485,
7832,
63,
6878,
8,
277,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
340,
291,
14,
10777,
63,
22478,
26,
288,
372,
267,
3728,
275,
291,
14,
1310,
63,
16830,
1491,
277,
14,
20512,
63,
4305,
61,
267,
291,
14,
1310,
63,
16830,
275,
291,
14,
1310,
63,
16830,
59,
277,
14,
20512,
63,
4305,
2938,
267,
340,
3728,
508,
8061,
288,
372,
267,
943,
14,
3446,
480,
14827,
450,
83,
2783,
370,
314,
1890,
401,
822,
8,
4604,
430,
267,
291,
14,
8542,
14,
952,
8,
4604,
9,
267,
9655,
14,
1250,
22028,
8,
16,
12,
291,
423,
7832,
63,
6878,
9,
339,
327,
41,
18186,
8292,
339,
347,
2274,
15532,
8,
277,
12,
17339,
12,
18490,
304,
267,
291,
14,
16376,
275,
17339,
267,
702,
18490,
365,
756,
267,
17339,
14,
9964,
24982,
342,
339,
347,
24369,
15532,
8,
277,
304,
267,
291,
14,
16376,
275,
488,
339,
347,
2218,
8,
277,
12,
666,
304,
398,
687,
7390,
14,
4901,
492,
9655,
398,
291,
14,
1310,
63,
16830,
275,
291,
14,
1310,
63,
16830,
435,
666,
267,
291,
423,
7832,
63,
6878,
342,
398,
347,
664,
63,
6878,
63,
576,
837,
288,
340,
291,
14,
16376,
365,
440,
488,
26,
355,
943,
14,
3446,
480,
2017,
316,
1655,
666,
687,
314,
17339,
531,
355,
291,
14,
16376,
14,
9964,
24982,
342,
398,
9655,
14,
1250,
22028,
8,
16,
12,
664,
63,
6878,
63,
576,
9,
339,
327,
2532,
11557,
339,
347,
666,
63,
9226,
8,
277,
12,
666,
304,
267,
943,
14,
1757,
480,
9392,
666,
531,
267,
943,
14,
1757,
3647,
83,
401,
620,
8,
576,
430,
267,
340,
291,
14,
1069,
63,
9226,
365,
756,
26,
288,
372,
291,
423,
1122,
63,
576,
63,
460,
63,
11853,
63,
2254,
63,
6582,
8,
576,
9,
267,
587,
26,
288,
943,
14,
3764,
8,
355,
298,
1918,
1890,
4847,
666,
1380,
781,
4898,
24349,
282,
570,
14,
961,
1077,
440,
5992,
531,
339,
347,
485,
1122,
63,
576,
63,
460,
63,
11853,
63,
2254,
63,
6582,
8,
277,
12,
666,
304,
267,
291,
14,
1069,
63,
16830,
275,
291,
14,
1069,
63,
16830,
435,
666,
267,
1499,
275,
291,
14,
893,
63,
475,
63,
1122,
63,
1069,
8,
277,
14,
1069,
63,
16830,
9,
267,
340,
1499,
26,
288,
291,
14,
1069,
63,
16830,
275,
2125,
288,
291,
423,
1412,
63,
1328,
8,
1328,
9,
267,
587,
26,
288,
943,
14,
1757,
480,
2017,
17893,
440,
282,
1686,
2022,
1245,
531,
288,
943,
14,
1757,
480,
2017,
17893,
26,
450,
83,
401,
291,
14,
1069,
63,
16830,
9,
339,
347,
485,
1412,
63,
1328,
8,
277,
12,
1499,
304,
267,
366,
275,
291,
14,
2479,
63,
1069,
8,
1328,
9,
267,
340,
291,
14,
6582,
63,
8114,
26,
288,
366,
14,
10053,
8,
2734,
24700,
291,
14,
6582,
63,
8114,
14,
2254,
63,
6582,
63,
692,
63,
11151,
8,
277,
430,
267,
366,
14,
10053,
83,
8,
2734,
24700,
291,
14,
8669,
63,
1310,
1062,
291,
14,
1069,
63,
5328,
63,
2232,
9,
2378,
21937,
3,
473,
11149,
21937,
3,
339,
347,
2274,
63,
1131,
63,
2232,
8,
277,
12,
1827,
63,
2232,
12,
1827,
63,
14227,
304,
267,
291,
14,
1131,
63,
5586,
59,
1131,
63,
2232,
61,
275,
1827,
63,
14227,
339,
347,
2274,
63,
6582,
63,
8114,
8,
277,
12,
9182,
63,
8114,
304,
267,
291,
14,
6582,
63,
8114,
275,
9182,
63,
8114,
339,
327,
1310,
7252,
339,
347,
1056,
63,
5328,
63,
2232,
8,
277,
12,
2329,
304,
267,
943,
14,
3764,
480,
2493,
1125,
8920,
7252,
282,
1056,
14,
4520,
26,
450,
83,
401,
2329,
14,
362,
547,
2209,
1012,
267,
291,
14,
2379,
24982,
342,
267,
372,
2329,
339,
347,
9158,
63,
1310,
8,
277,
304,
267,
291,
14,
1069,
63,
9226,
275,
756,
267,
291,
423,
7832,
63,
6878,
342,
339,
347,
3222,
63,
1310,
8,
277,
12,
1499,
304,
267,
333,
275,
2022,
14,
4180,
8,
1328,
9,
267,
943,
14,
1757,
480,
27219,
282,
1177,
402,
2582,
450,
83,
401,
620,
8,
552,
8,
77,
1724,
267,
943,
14,
1757,
480,
2364,
26,
450,
83,
401,
620,
8,
77,
430,
267,
291,
14,
1310,
63,
16830,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alexeyum/scikit-learn
|
sklearn/externals/joblib/hashing.py
|
31
|
10064
|
"""
Fast cryptographic hash of Python objects, with a special case for fast
hashing of numpy arrays.
"""
# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# Copyright (c) 2009 Gael Varoquaux
# License: BSD Style, 3 clauses.
import pickle
import hashlib
import sys
import types
import struct
import io
from ._compat import _bytes_or_unicode, PY3_OR_LATER
if PY3_OR_LATER:
Pickler = pickle._Pickler
else:
Pickler = pickle.Pickler
class _ConsistentSet(object):
""" Class used to ensure the hash of Sets is preserved
whatever the order of its items.
"""
def __init__(self, set_sequence):
# Forces order of elements in set to ensure consistent hash.
try:
# Trying first to order the set assuming the type of elements is
# consistent and orderable.
# This fails on python 3 when elements are unorderable
# but we keep it in a try as it's faster.
self._sequence = sorted(set_sequence)
except TypeError:
# If elements are unorderable, sorting them using their hash.
# This is slower but works in any case.
self._sequence = sorted((hash(e) for e in set_sequence))
class _MyHash(object):
""" Class used to hash objects that won't normally pickle """
def __init__(self, *args):
self.args = args
class Hasher(Pickler):
""" A subclass of pickler, to do cryptographic hashing, rather than
pickling.
"""
def __init__(self, hash_name='md5'):
self.stream = io.BytesIO()
# By default we want a pickle protocol that only changes with
# the major python version and not the minor one
protocol = (pickle.DEFAULT_PROTOCOL if PY3_OR_LATER
else pickle.HIGHEST_PROTOCOL)
Pickler.__init__(self, self.stream, protocol=protocol)
# Initialise the hash obj
self._hash = hashlib.new(hash_name)
def hash(self, obj, return_digest=True):
try:
self.dump(obj)
except pickle.PicklingError as e:
e.args += ('PicklingError while hashing %r: %r' % (obj, e),)
raise
dumps = self.stream.getvalue()
self._hash.update(dumps)
if return_digest:
return self._hash.hexdigest()
def save(self, obj):
if isinstance(obj, (types.MethodType, type({}.pop))):
# the Pickler cannot pickle instance methods; here we decompose
# them into components that make them uniquely identifiable
if hasattr(obj, '__func__'):
func_name = obj.__func__.__name__
else:
func_name = obj.__name__
inst = obj.__self__
if type(inst) == type(pickle):
obj = _MyHash(func_name, inst.__name__)
elif inst is None:
# type(None) or type(module) do not pickle
obj = _MyHash(func_name, inst)
else:
cls = obj.__self__.__class__
obj = _MyHash(func_name, inst, cls)
Pickler.save(self, obj)
def memoize(self, obj):
# We want hashing to be sensitive to value instead of reference.
# For example we want ['aa', 'aa'] and ['aa', 'aaZ'[:2]]
# to hash to the same value and that's why we disable memoization
# for strings
if isinstance(obj, _bytes_or_unicode):
return
Pickler.memoize(self, obj)
# The dispatch table of the pickler is not accessible in Python
# 3, as these lines are only bugware for IPython, we skip them.
def save_global(self, obj, name=None, pack=struct.pack):
# We have to override this method in order to deal with objects
# defined interactively in IPython that are not injected in
# __main__
kwargs = dict(name=name, pack=pack)
if sys.version_info >= (3, 4):
del kwargs['pack']
try:
Pickler.save_global(self, obj, **kwargs)
except pickle.PicklingError:
Pickler.save_global(self, obj, **kwargs)
module = getattr(obj, "__module__", None)
if module == '__main__':
my_name = name
if my_name is None:
my_name = obj.__name__
mod = sys.modules[module]
if not hasattr(mod, my_name):
# IPython doesn't inject the variables define
# interactively in __main__
setattr(mod, my_name, obj)
dispatch = Pickler.dispatch.copy()
# builtin
dispatch[type(len)] = save_global
# type
dispatch[type(object)] = save_global
# classobj
dispatch[type(Pickler)] = save_global
# function
dispatch[type(pickle.dump)] = save_global
def _batch_setitems(self, items):
# forces order of keys in dict to ensure consistent hash.
try:
# Trying first to compare dict assuming the type of keys is
# consistent and orderable.
# This fails on python 3 when keys are unorderable
# but we keep it in a try as it's faster.
Pickler._batch_setitems(self, iter(sorted(items)))
except TypeError:
# If keys are unorderable, sorting them using their hash. This is
# slower but works in any case.
Pickler._batch_setitems(self, iter(sorted((hash(k), v)
for k, v in items)))
def save_set(self, set_items):
# forces order of items in Set to ensure consistent hash
Pickler.save(self, _ConsistentSet(set_items))
dispatch[type(set())] = save_set
class NumpyHasher(Hasher):
""" Special case the hasher for when numpy is loaded.
"""
def __init__(self, hash_name='md5', coerce_mmap=False):
"""
Parameters
----------
hash_name: string
The hash algorithm to be used
coerce_mmap: boolean
Make no difference between np.memmap and np.ndarray
objects.
"""
self.coerce_mmap = coerce_mmap
Hasher.__init__(self, hash_name=hash_name)
# delayed import of numpy, to avoid tight coupling
import numpy as np
self.np = np
if hasattr(np, 'getbuffer'):
self._getbuffer = np.getbuffer
else:
self._getbuffer = memoryview
def save(self, obj):
""" Subclass the save method, to hash ndarray subclass, rather
than pickling them. Off course, this is a total abuse of
the Pickler class.
"""
if isinstance(obj, self.np.ndarray) and not obj.dtype.hasobject:
# Compute a hash of the object:
try:
# memoryview is not supported for some dtypes,
# e.g. datetime64, see
# https://github.com/numpy/numpy/issues/4983. The
# workaround is to view the array as bytes before
# taking the memoryview
obj_bytes_view = obj.view(self.np.uint8)
self._hash.update(self._getbuffer(obj_bytes_view))
# ValueError is raised by .view when the array is not contiguous
# BufferError is raised by Python 3 in the hash update if
# the array is Fortran rather than C contiguous
except (ValueError, BufferError):
# Cater for non-single-segment arrays: this creates a
# copy, and thus aleviates this issue.
# XXX: There might be a more efficient way of doing this
obj_bytes_view = obj.flatten().view(self.np.uint8)
self._hash.update(self._getbuffer(obj_bytes_view))
# We store the class, to be able to distinguish between
# Objects with the same binary content, but different
# classes.
if self.coerce_mmap and isinstance(obj, self.np.memmap):
# We don't make the difference between memmap and
# normal ndarrays, to be able to reload previously
# computed results with memmap.
klass = self.np.ndarray
else:
klass = obj.__class__
# We also return the dtype and the shape, to distinguish
# different views on the same data with different dtypes.
# The object will be pickled by the pickler hashed at the end.
obj = (klass, ('HASHED', obj.dtype, obj.shape, obj.strides))
elif isinstance(obj, self.np.dtype):
# Atomic dtype objects are interned by their default constructor:
# np.dtype('f8') is np.dtype('f8')
# This interning is not maintained by a
# pickle.loads + pickle.dumps cycle, because __reduce__
# uses copy=True in the dtype constructor. This
# non-deterministic behavior causes the internal memoizer
# of the hasher to generate different hash values
# depending on the history of the dtype object.
# To prevent the hash from being sensitive to this, we use
# .descr which is a full (and never interned) description of
# the array dtype according to the numpy doc.
klass = obj.__class__
obj = (klass, ('HASHED', obj.descr))
Hasher.save(self, obj)
def hash(obj, hash_name='md5', coerce_mmap=False):
""" Quick calculation of a hash to identify uniquely Python objects
containing numpy arrays.
Parameters
-----------
hash_name: 'md5' or 'sha1'
Hashing algorithm used. sha1 is supposedly safer, but md5 is
faster.
coerce_mmap: boolean
Make no difference between np.memmap and np.ndarray
"""
if 'numpy' in sys.modules:
hasher = NumpyHasher(hash_name=hash_name, coerce_mmap=coerce_mmap)
else:
hasher = Hasher(hash_name=hash_name)
return hasher.hash(obj)
|
bsd-3-clause
|
[
624,
199,
16976,
13230,
9770,
2631,
402,
2018,
2251,
12,
543,
282,
4539,
1930,
367,
7377,
199,
2227,
316,
402,
2680,
6572,
14,
199,
624,
199,
199,
3,
6529,
26,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
6308,
2729,
79,
392,
10962,
737,
6590,
17667,
1961,
6308,
5981,
30,
199,
3,
1898,
334,
67,
9,
8937,
9647,
352,
21084,
79,
392,
10962,
199,
3,
844,
26,
6289,
19442,
12,
650,
25089,
14,
199,
199,
646,
5927,
199,
646,
8337,
199,
646,
984,
199,
646,
2943,
199,
646,
2702,
199,
646,
5890,
199,
199,
504,
13653,
5819,
492,
485,
2394,
63,
269,
63,
2975,
12,
7843,
19,
63,
726,
63,
44,
10447,
421,
199,
692,
7843,
19,
63,
726,
63,
44,
10447,
26,
272,
16568,
1435,
275,
5927,
423,
8587,
1435,
199,
2836,
26,
272,
16568,
1435,
275,
5927,
14,
8587,
1435,
421,
199,
533,
485,
714,
6082,
1084,
8,
785,
304,
272,
408,
8089,
1202,
370,
4868,
314,
2631,
402,
10729,
365,
17731,
267,
15685,
314,
1865,
402,
2399,
2974,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
663,
63,
4041,
304,
267,
327,
2104,
823,
1865,
402,
4008,
315,
663,
370,
4868,
12137,
2631,
14,
267,
862,
26,
288,
327,
7649,
316,
1642,
370,
1865,
314,
663,
18002,
314,
730,
402,
4008,
365,
288,
327,
12137,
436,
503,
271,
6842,
14,
288,
327,
961,
6918,
641,
2366,
650,
1380,
4008,
787,
625,
27788,
6842,
288,
327,
1325,
781,
4215,
652,
315,
282,
862,
465,
652,
1159,
12930,
14,
288,
291,
423,
4041,
275,
3355,
8,
409,
63,
4041,
9,
267,
871,
3146,
26,
288,
327,
982,
4008,
787,
625,
27788,
6842,
12,
13351,
3062,
1808,
3932,
2631,
14,
288,
327,
961,
365,
26200,
1325,
5419,
315,
1263,
1930,
14,
288,
291,
423,
4041,
275,
3355,
1332,
2227,
8,
69,
9,
367,
325,
315,
663,
63,
4041,
430,
421,
199,
533,
485,
5713,
3476,
8,
785,
304,
272,
408,
8089,
1202,
370,
2631,
2251,
626,
7859,
1133,
12252,
5927,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
589,
275,
1249,
421,
199,
533,
16101,
281,
8,
8587,
1435,
304,
272,
408,
437,
5516,
402,
3732,
1435,
12,
370,
886,
13230,
9770,
25223,
12,
7830,
2419,
267,
24394,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2631,
63,
354,
534,
1064,
21,
735,
267,
291,
14,
1745,
275,
5890,
14,
15466,
342,
267,
327,
4885,
849,
781,
2934,
282,
5927,
4113,
626,
1454,
4493,
543,
267,
327,
314,
12160,
2366,
1015,
436,
440,
314,
12612,
1373,
267,
4113,
275,
334,
8092,
14,
3472,
63,
9583,
340,
7843,
19,
63,
726,
63,
44,
10447,
490,
587,
5927,
14,
31977,
63,
9583,
9,
267,
16568,
1435,
855,
826,
721,
277,
12,
291,
14,
1745,
12,
4113,
29,
3922,
9,
267,
327,
6026,
572,
314,
2631,
1559,
267,
291,
423,
2227,
275,
8337,
14,
1222,
8,
2227,
63,
354,
9,
339,
347,
2631,
8,
277,
12,
1559,
12,
372,
63,
5671,
29,
549,
304,
267,
862,
26,
288,
291,
14,
2724,
8,
1113,
9,
267,
871,
5927,
14,
8587,
2983,
547,
465,
325,
26,
288,
325,
14,
589,
847,
661,
8587,
2983,
547,
1830,
25223,
450,
82,
26,
450,
82,
7,
450,
334,
1113,
12,
325,
16945,
288,
746,
267,
16864,
275,
291,
14,
1745,
14,
7150,
342,
267,
291,
423,
2227,
14,
873,
8,
4180,
9,
267,
340,
372,
63,
5671,
26,
288,
372,
291,
423,
2227,
14,
11453,
342,
339,
347,
3354,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
334,
1313,
14,
24674,
12,
730,
24692,
14,
1935,
15206,
288,
327,
314,
16568,
1435,
3913,
5927,
1256,
3102,
27,
2348,
781,
477,
12607,
288,
327,
3062,
1901,
7323,
626,
1852,
3062,
28727,
16346,
461,
288,
340,
2688,
8,
1113,
12,
2560,
1532,
12168,
355,
2562,
63,
354,
275,
1559,
855,
1532,
4914,
354,
363,
288,
587,
26,
355,
2562,
63,
354,
275,
1559,
855,
354,
363,
288,
2727,
275,
1559,
855,
277,
363,
288,
340,
730,
8,
3615,
9,
508,
730,
8,
8092,
304,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
855,
354,
3368,
288,
916,
2727,
365,
488,
26,
355,
327,
730,
8,
403,
9,
503,
730,
8,
578,
9,
886,
440,
5927,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
9,
288,
587,
26,
355,
843,
275,
1559,
855,
277,
4914,
533,
363,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
12,
843,
9,
267,
16568,
1435,
14,
2117,
8,
277,
12,
1559,
9,
339,
347,
11955,
794,
8,
277,
12,
1559,
304,
267,
327,
2136,
2934,
25223,
370,
506,
18423,
370,
574,
3140,
402,
3659,
14,
267,
327,
2104,
2893,
781,
2934,
788,
2158,
297,
283,
2158,
418,
436,
788,
2158,
297,
283,
2158,
58,
7,
1491,
18,
2677,
267,
327,
370,
2631,
370,
314,
2011,
574,
436,
626,
1159,
10842,
781,
3507,
11955,
2072,
267,
327,
367,
3326,
267,
340,
1228,
8,
1113,
12,
485,
2394,
63,
269,
63,
2975,
304,
288,
372,
267,
16568,
1435,
14,
11979,
794,
8,
277,
12,
1559,
9,
339,
327,
710,
7634,
1817,
402,
314,
3732,
1435,
365,
440,
17909,
315,
2018,
272,
327,
650,
12,
465,
3520,
2385,
787,
1454,
6519,
1068,
367,
16243,
12,
781,
3372,
3062,
14,
272,
347,
3354,
63,
2966,
8,
277,
12,
1559,
12,
536,
29,
403,
12,
1706,
29,
1820,
14,
1389,
304,
267,
327,
2136,
1172,
370,
4278,
642,
1083,
315,
1865,
370,
7962,
543,
2251,
267,
327,
3247,
315,
2967,
67,
9462,
315,
16243,
626,
787,
440,
26121,
315,
267,
327,
636,
973,
363,
267,
2074,
275,
1211,
8,
354,
29,
354,
12,
1706,
29,
1389,
9,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
841,
304,
288,
2150,
2074,
459,
1389,
418,
267,
862,
26,
288,
16568,
1435,
14,
2117,
63,
2966,
8,
277,
12,
1559,
12,
1011,
958,
9,
267,
871,
5927,
14,
8587,
2983,
547,
26,
288,
16568,
1435,
14,
2117,
63,
2966,
8,
277,
12,
1559,
12,
1011,
958,
9,
288,
859,
275,
2519,
8,
1113,
12,
4396,
578,
13915,
488
] |
[
199,
16976,
13230,
9770,
2631,
402,
2018,
2251,
12,
543,
282,
4539,
1930,
367,
7377,
199,
2227,
316,
402,
2680,
6572,
14,
199,
624,
199,
199,
3,
6529,
26,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
6308,
2729,
79,
392,
10962,
737,
6590,
17667,
1961,
6308,
5981,
30,
199,
3,
1898,
334,
67,
9,
8937,
9647,
352,
21084,
79,
392,
10962,
199,
3,
844,
26,
6289,
19442,
12,
650,
25089,
14,
199,
199,
646,
5927,
199,
646,
8337,
199,
646,
984,
199,
646,
2943,
199,
646,
2702,
199,
646,
5890,
199,
199,
504,
13653,
5819,
492,
485,
2394,
63,
269,
63,
2975,
12,
7843,
19,
63,
726,
63,
44,
10447,
421,
199,
692,
7843,
19,
63,
726,
63,
44,
10447,
26,
272,
16568,
1435,
275,
5927,
423,
8587,
1435,
199,
2836,
26,
272,
16568,
1435,
275,
5927,
14,
8587,
1435,
421,
199,
533,
485,
714,
6082,
1084,
8,
785,
304,
272,
408,
8089,
1202,
370,
4868,
314,
2631,
402,
10729,
365,
17731,
267,
15685,
314,
1865,
402,
2399,
2974,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
663,
63,
4041,
304,
267,
327,
2104,
823,
1865,
402,
4008,
315,
663,
370,
4868,
12137,
2631,
14,
267,
862,
26,
288,
327,
7649,
316,
1642,
370,
1865,
314,
663,
18002,
314,
730,
402,
4008,
365,
288,
327,
12137,
436,
503,
271,
6842,
14,
288,
327,
961,
6918,
641,
2366,
650,
1380,
4008,
787,
625,
27788,
6842,
288,
327,
1325,
781,
4215,
652,
315,
282,
862,
465,
652,
1159,
12930,
14,
288,
291,
423,
4041,
275,
3355,
8,
409,
63,
4041,
9,
267,
871,
3146,
26,
288,
327,
982,
4008,
787,
625,
27788,
6842,
12,
13351,
3062,
1808,
3932,
2631,
14,
288,
327,
961,
365,
26200,
1325,
5419,
315,
1263,
1930,
14,
288,
291,
423,
4041,
275,
3355,
1332,
2227,
8,
69,
9,
367,
325,
315,
663,
63,
4041,
430,
421,
199,
533,
485,
5713,
3476,
8,
785,
304,
272,
408,
8089,
1202,
370,
2631,
2251,
626,
7859,
1133,
12252,
5927,
408,
339,
347,
636,
826,
721,
277,
12,
627,
589,
304,
267,
291,
14,
589,
275,
1249,
421,
199,
533,
16101,
281,
8,
8587,
1435,
304,
272,
408,
437,
5516,
402,
3732,
1435,
12,
370,
886,
13230,
9770,
25223,
12,
7830,
2419,
267,
24394,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2631,
63,
354,
534,
1064,
21,
735,
267,
291,
14,
1745,
275,
5890,
14,
15466,
342,
267,
327,
4885,
849,
781,
2934,
282,
5927,
4113,
626,
1454,
4493,
543,
267,
327,
314,
12160,
2366,
1015,
436,
440,
314,
12612,
1373,
267,
4113,
275,
334,
8092,
14,
3472,
63,
9583,
340,
7843,
19,
63,
726,
63,
44,
10447,
490,
587,
5927,
14,
31977,
63,
9583,
9,
267,
16568,
1435,
855,
826,
721,
277,
12,
291,
14,
1745,
12,
4113,
29,
3922,
9,
267,
327,
6026,
572,
314,
2631,
1559,
267,
291,
423,
2227,
275,
8337,
14,
1222,
8,
2227,
63,
354,
9,
339,
347,
2631,
8,
277,
12,
1559,
12,
372,
63,
5671,
29,
549,
304,
267,
862,
26,
288,
291,
14,
2724,
8,
1113,
9,
267,
871,
5927,
14,
8587,
2983,
547,
465,
325,
26,
288,
325,
14,
589,
847,
661,
8587,
2983,
547,
1830,
25223,
450,
82,
26,
450,
82,
7,
450,
334,
1113,
12,
325,
16945,
288,
746,
267,
16864,
275,
291,
14,
1745,
14,
7150,
342,
267,
291,
423,
2227,
14,
873,
8,
4180,
9,
267,
340,
372,
63,
5671,
26,
288,
372,
291,
423,
2227,
14,
11453,
342,
339,
347,
3354,
8,
277,
12,
1559,
304,
267,
340,
1228,
8,
1113,
12,
334,
1313,
14,
24674,
12,
730,
24692,
14,
1935,
15206,
288,
327,
314,
16568,
1435,
3913,
5927,
1256,
3102,
27,
2348,
781,
477,
12607,
288,
327,
3062,
1901,
7323,
626,
1852,
3062,
28727,
16346,
461,
288,
340,
2688,
8,
1113,
12,
2560,
1532,
12168,
355,
2562,
63,
354,
275,
1559,
855,
1532,
4914,
354,
363,
288,
587,
26,
355,
2562,
63,
354,
275,
1559,
855,
354,
363,
288,
2727,
275,
1559,
855,
277,
363,
288,
340,
730,
8,
3615,
9,
508,
730,
8,
8092,
304,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
855,
354,
3368,
288,
916,
2727,
365,
488,
26,
355,
327,
730,
8,
403,
9,
503,
730,
8,
578,
9,
886,
440,
5927,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
9,
288,
587,
26,
355,
843,
275,
1559,
855,
277,
4914,
533,
363,
355,
1559,
275,
485,
5713,
3476,
8,
1532,
63,
354,
12,
2727,
12,
843,
9,
267,
16568,
1435,
14,
2117,
8,
277,
12,
1559,
9,
339,
347,
11955,
794,
8,
277,
12,
1559,
304,
267,
327,
2136,
2934,
25223,
370,
506,
18423,
370,
574,
3140,
402,
3659,
14,
267,
327,
2104,
2893,
781,
2934,
788,
2158,
297,
283,
2158,
418,
436,
788,
2158,
297,
283,
2158,
58,
7,
1491,
18,
2677,
267,
327,
370,
2631,
370,
314,
2011,
574,
436,
626,
1159,
10842,
781,
3507,
11955,
2072,
267,
327,
367,
3326,
267,
340,
1228,
8,
1113,
12,
485,
2394,
63,
269,
63,
2975,
304,
288,
372,
267,
16568,
1435,
14,
11979,
794,
8,
277,
12,
1559,
9,
339,
327,
710,
7634,
1817,
402,
314,
3732,
1435,
365,
440,
17909,
315,
2018,
272,
327,
650,
12,
465,
3520,
2385,
787,
1454,
6519,
1068,
367,
16243,
12,
781,
3372,
3062,
14,
272,
347,
3354,
63,
2966,
8,
277,
12,
1559,
12,
536,
29,
403,
12,
1706,
29,
1820,
14,
1389,
304,
267,
327,
2136,
1172,
370,
4278,
642,
1083,
315,
1865,
370,
7962,
543,
2251,
267,
327,
3247,
315,
2967,
67,
9462,
315,
16243,
626,
787,
440,
26121,
315,
267,
327,
636,
973,
363,
267,
2074,
275,
1211,
8,
354,
29,
354,
12,
1706,
29,
1389,
9,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
841,
304,
288,
2150,
2074,
459,
1389,
418,
267,
862,
26,
288,
16568,
1435,
14,
2117,
63,
2966,
8,
277,
12,
1559,
12,
1011,
958,
9,
267,
871,
5927,
14,
8587,
2983,
547,
26,
288,
16568,
1435,
14,
2117,
63,
2966,
8,
277,
12,
1559,
12,
1011,
958,
9,
288,
859,
275,
2519,
8,
1113,
12,
4396,
578,
13915,
488,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RealImpactAnalytics/airflow
|
tests/contrib/hooks/test_databricks_hook.py
|
10
|
9514
|
# -*- coding: utf-8 -*-
#
# 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 json
import unittest
from airflow import __version__
from airflow.contrib.hooks.databricks_hook import DatabricksHook, RunState, SUBMIT_RUN_ENDPOINT, _TokenAuth
from airflow.exceptions import AirflowException
from airflow.models import Connection
from airflow.utils import db
from requests import exceptions as requests_exceptions
try:
from unittest import mock
except ImportError:
try:
import mock
except ImportError:
mock = None
TASK_ID = 'databricks-operator'
DEFAULT_CONN_ID = 'databricks_default'
NOTEBOOK_TASK = {
'notebook_path': '/test'
}
NEW_CLUSTER = {
'spark_version': '2.0.x-scala2.10',
'node_type_id': 'r3.xlarge',
'num_workers': 1
}
RUN_ID = 1
HOST = 'xx.cloud.databricks.com'
HOST_WITH_SCHEME = 'https://xx.cloud.databricks.com'
LOGIN = 'login'
PASSWORD = 'password'
TOKEN = 'token'
USER_AGENT_HEADER = {'user-agent': 'airflow-{v}'.format(v=__version__)}
RUN_PAGE_URL = 'https://XX.cloud.databricks.com/#jobs/1/runs/1'
LIFE_CYCLE_STATE = 'PENDING'
STATE_MESSAGE = 'Waiting for cluster'
GET_RUN_RESPONSE = {
'run_page_url': RUN_PAGE_URL,
'state': {
'life_cycle_state': LIFE_CYCLE_STATE,
'state_message': STATE_MESSAGE
}
}
RESULT_STATE = None
def submit_run_endpoint(host):
"""
Utility function to generate the submit run endpoint given the host.
"""
return 'https://{}/api/2.0/jobs/runs/submit'.format(host)
def get_run_endpoint(host):
"""
Utility function to generate the get run endpoint given the host.
"""
return 'https://{}/api/2.0/jobs/runs/get'.format(host)
def cancel_run_endpoint(host):
"""
Utility function to generate the get run endpoint given the host.
"""
return 'https://{}/api/2.0/jobs/runs/cancel'.format(host)
class DatabricksHookTest(unittest.TestCase):
"""
Tests for DatabricksHook.
"""
@db.provide_session
def setUp(self, session=None):
conn = session.query(Connection) \
.filter(Connection.conn_id == DEFAULT_CONN_ID) \
.first()
conn.host = HOST
conn.login = LOGIN
conn.password = PASSWORD
session.commit()
self.hook = DatabricksHook()
def test_parse_host_with_proper_host(self):
host = self.hook._parse_host(HOST)
self.assertEquals(host, HOST)
def test_parse_host_with_scheme(self):
host = self.hook._parse_host(HOST_WITH_SCHEME)
self.assertEquals(host, HOST)
def test_init_bad_retry_limit(self):
with self.assertRaises(AssertionError):
DatabricksHook(retry_limit = 0)
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_do_api_call_with_error_retry(self, mock_requests):
for exception in [requests_exceptions.ConnectionError, requests_exceptions.Timeout]:
with mock.patch.object(self.hook.log, 'error') as mock_errors:
mock_requests.reset_mock()
mock_requests.post.side_effect = exception()
with self.assertRaises(AirflowException):
self.hook._do_api_call(SUBMIT_RUN_ENDPOINT, {})
self.assertEquals(len(mock_errors.mock_calls), self.hook.retry_limit)
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_do_api_call_with_bad_status_code(self, mock_requests):
mock_requests.codes.ok = 200
status_code_mock = mock.PropertyMock(return_value=500)
type(mock_requests.post.return_value).status_code = status_code_mock
with self.assertRaises(AirflowException):
self.hook._do_api_call(SUBMIT_RUN_ENDPOINT, {})
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_submit_run(self, mock_requests):
mock_requests.codes.ok = 200
mock_requests.post.return_value.json.return_value = {'run_id': '1'}
status_code_mock = mock.PropertyMock(return_value=200)
type(mock_requests.post.return_value).status_code = status_code_mock
json = {
'notebook_task': NOTEBOOK_TASK,
'new_cluster': NEW_CLUSTER
}
run_id = self.hook.submit_run(json)
self.assertEquals(run_id, '1')
mock_requests.post.assert_called_once_with(
submit_run_endpoint(HOST),
json={
'notebook_task': NOTEBOOK_TASK,
'new_cluster': NEW_CLUSTER,
},
auth=(LOGIN, PASSWORD),
headers=USER_AGENT_HEADER,
timeout=self.hook.timeout_seconds)
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_get_run_page_url(self, mock_requests):
mock_requests.codes.ok = 200
mock_requests.get.return_value.json.return_value = GET_RUN_RESPONSE
status_code_mock = mock.PropertyMock(return_value=200)
type(mock_requests.get.return_value).status_code = status_code_mock
run_page_url = self.hook.get_run_page_url(RUN_ID)
self.assertEquals(run_page_url, RUN_PAGE_URL)
mock_requests.get.assert_called_once_with(
get_run_endpoint(HOST),
json={'run_id': RUN_ID},
auth=(LOGIN, PASSWORD),
headers=USER_AGENT_HEADER,
timeout=self.hook.timeout_seconds)
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_get_run_state(self, mock_requests):
mock_requests.codes.ok = 200
mock_requests.get.return_value.json.return_value = GET_RUN_RESPONSE
status_code_mock = mock.PropertyMock(return_value=200)
type(mock_requests.get.return_value).status_code = status_code_mock
run_state = self.hook.get_run_state(RUN_ID)
self.assertEquals(run_state, RunState(
LIFE_CYCLE_STATE,
RESULT_STATE,
STATE_MESSAGE))
mock_requests.get.assert_called_once_with(
get_run_endpoint(HOST),
json={'run_id': RUN_ID},
auth=(LOGIN, PASSWORD),
headers=USER_AGENT_HEADER,
timeout=self.hook.timeout_seconds)
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_cancel_run(self, mock_requests):
mock_requests.codes.ok = 200
mock_requests.post.return_value.json.return_value = GET_RUN_RESPONSE
status_code_mock = mock.PropertyMock(return_value=200)
type(mock_requests.post.return_value).status_code = status_code_mock
self.hook.cancel_run(RUN_ID)
mock_requests.post.assert_called_once_with(
cancel_run_endpoint(HOST),
json={'run_id': RUN_ID},
auth=(LOGIN, PASSWORD),
headers=USER_AGENT_HEADER,
timeout=self.hook.timeout_seconds)
class DatabricksHookTokenTest(unittest.TestCase):
"""
Tests for DatabricksHook when auth is done with token.
"""
@db.provide_session
def setUp(self, session=None):
conn = session.query(Connection) \
.filter(Connection.conn_id == DEFAULT_CONN_ID) \
.first()
conn.extra = json.dumps({'token': TOKEN})
session.commit()
self.hook = DatabricksHook()
@mock.patch('airflow.contrib.hooks.databricks_hook.requests')
def test_submit_run(self, mock_requests):
mock_requests.codes.ok = 200
mock_requests.post.return_value.json.return_value = {'run_id': '1'}
status_code_mock = mock.PropertyMock(return_value=200)
type(mock_requests.post.return_value).status_code = status_code_mock
json = {
'notebook_task': NOTEBOOK_TASK,
'new_cluster': NEW_CLUSTER
}
run_id = self.hook.submit_run(json)
self.assertEquals(run_id, '1')
args = mock_requests.post.call_args
kwargs = args[1]
self.assertEquals(kwargs['auth'].token, TOKEN)
class RunStateTest(unittest.TestCase):
def test_is_terminal_true(self):
terminal_states = ['TERMINATED', 'SKIPPED', 'INTERNAL_ERROR']
for state in terminal_states:
run_state = RunState(state, '', '')
self.assertTrue(run_state.is_terminal)
def test_is_terminal_false(self):
non_terminal_states = ['PENDING', 'RUNNING', 'TERMINATING']
for state in non_terminal_states:
run_state = RunState(state, '', '')
self.assertFalse(run_state.is_terminal)
def test_is_terminal_with_nonexistent_life_cycle_state(self):
run_state = RunState('blah', '', '')
with self.assertRaises(AirflowException):
run_state.is_terminal
def test_is_successful(self):
run_state = RunState('TERMINATED', 'SUCCESS', '')
self.assertTrue(run_state.is_successful)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
16321,
492,
636,
1023,
363,
199,
504,
16321,
14,
2828,
14,
7922,
14,
68,
1936,
322,
5618,
63,
3664,
492,
577,
1936,
322,
5618,
8481,
12,
3378,
2223,
12,
7605,
13965,
63,
9390,
63,
21054,
12,
485,
3264,
2817,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
199,
504,
16321,
14,
992,
492,
8113,
199,
504,
16321,
14,
1208,
492,
1592,
199,
504,
4145,
492,
4967,
465,
4145,
63,
3924,
199,
199,
893,
26,
272,
687,
2882,
492,
1683,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
1683,
272,
871,
3545,
26,
267,
1683,
275,
488,
199,
199,
17179,
63,
998,
275,
283,
68,
1936,
322,
5618,
13,
3856,
7,
199,
3472,
63,
17489,
63,
998,
275,
283,
68,
1936,
322,
5618,
63,
885,
7,
199,
19855,
21155,
63,
17179,
275,
469,
272,
283,
19174,
63,
515,
356,
1994,
396,
7,
199,
93,
199,
11365,
63,
26340,
275,
469,
272,
283,
9852,
63,
1023,
356,
283,
18,
14,
16,
14,
88,
13,
28708,
18,
14,
709,
297,
272,
283,
932,
63,
466,
63,
344,
356,
283,
82,
19,
14,
28598,
297,
272,
283,
1507,
63,
11009,
356,
413,
199,
93,
199,
9390,
63,
998,
275,
413,
199,
5449,
275,
283,
2154,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
7,
199,
5449,
63,
9139,
63,
30430,
275,
283,
2859,
921,
2154,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
7,
199,
17208,
275,
283,
2886,
7,
199,
9032,
275,
283,
2060,
7,
199,
8803,
275,
283,
1418,
7,
199,
3791,
63,
14565,
63,
7311,
275,
791,
751,
13,
4054,
356,
283,
15815,
24185,
86,
5285,
908,
8,
86,
18971,
1023,
3368,
93,
199,
9390,
63,
12898,
63,
2632,
275,
283,
2859,
921,
2483,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
12645,
6920,
15,
17,
15,
10802,
15,
17,
7,
199,
2673,
5100,
63,
15068,
12507,
63,
6689,
275,
283,
21243,
7,
199,
6689,
63,
8272,
275,
283,
19189,
367,
4350,
7,
199,
2970,
63,
9390,
63,
12801,
275,
469,
272,
283,
1065,
63,
1606,
63,
633,
356,
21277,
63,
12898,
63,
2632,
12,
272,
283,
929,
356,
469,
267,
283,
13602,
63,
7612,
63,
929,
356,
3782,
5100,
63,
15068,
12507,
63,
6689,
12,
267,
283,
929,
63,
1188,
356,
11377,
63,
8272,
272,
789,
199,
93,
199,
9517,
63,
6689,
275,
488,
421,
199,
318,
11482,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
11482,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
7275,
1370,
908,
8,
1102,
9,
421,
199,
318,
664,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
664,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
362,
1370,
908,
8,
1102,
9,
199,
199,
318,
9311,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
664,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
6406,
1370,
908,
8,
1102,
9,
199,
199,
533,
577,
1936,
322,
5618,
8481,
774,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
577,
1936,
322,
5618,
8481,
14,
272,
408,
272,
768,
697,
14,
20824,
63,
1730,
272,
347,
3613,
8,
277,
12,
2351,
29,
403,
304,
267,
2557,
275,
2351,
14,
1131,
8,
3225,
9,
971,
288,
1275,
1541,
8,
3225,
14,
1631,
63,
344,
508,
6186,
63,
17489,
63,
998,
9,
971,
288,
1275,
2246,
342,
267,
2557,
14,
1102,
275,
25741,
267,
2557,
14,
2886,
275,
5051,
568,
267,
2557,
14,
2060,
275,
21705,
5172,
267,
2351,
14,
3543,
342,
398,
291,
14,
3664,
275,
577,
1936,
322,
5618,
8481,
342,
339,
347,
511,
63,
1122,
63,
1102,
63,
1045,
63,
28314,
63,
1102,
8,
277,
304,
267,
1591,
275,
291,
14,
3664,
423,
1122,
63,
1102,
8,
5449,
9,
267,
291,
14,
2947,
8,
1102,
12,
25741,
9,
339,
347,
511,
63,
1122,
63,
1102,
63,
1045,
63,
5512,
8,
277,
304,
267,
1591,
275,
291,
14,
3664,
423,
1122,
63,
1102,
8,
5449,
63,
9139,
63,
30430,
9,
267,
291,
14,
2947,
8,
1102,
12,
25741,
9,
339,
347,
511,
63,
826,
63,
4087,
63,
7154,
63,
3097,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
14844,
304,
288,
577,
1936,
322,
5618,
8481,
8,
7154,
63,
3097,
275,
378,
9,
339,
768,
1805,
14,
2068,
360,
15815,
14,
2828,
14,
7922,
14,
68,
1936,
322,
5618,
63,
3664,
14,
6615,
358,
272,
347,
511,
63,
1117,
63,
1246,
63,
1250,
63,
1045,
63,
705,
63,
7154,
8,
277,
12,
1683,
63,
6615,
304,
267,
367,
1919,
315,
359,
6615,
63,
3924,
14,
20349,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
221,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
3,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
16321,
492,
636,
1023,
363,
199,
504,
16321,
14,
2828,
14,
7922,
14,
68,
1936,
322,
5618,
63,
3664,
492,
577,
1936,
322,
5618,
8481,
12,
3378,
2223,
12,
7605,
13965,
63,
9390,
63,
21054,
12,
485,
3264,
2817,
199,
504,
16321,
14,
3924,
492,
31040,
1726,
199,
504,
16321,
14,
992,
492,
8113,
199,
504,
16321,
14,
1208,
492,
1592,
199,
504,
4145,
492,
4967,
465,
4145,
63,
3924,
199,
199,
893,
26,
272,
687,
2882,
492,
1683,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
1683,
272,
871,
3545,
26,
267,
1683,
275,
488,
199,
199,
17179,
63,
998,
275,
283,
68,
1936,
322,
5618,
13,
3856,
7,
199,
3472,
63,
17489,
63,
998,
275,
283,
68,
1936,
322,
5618,
63,
885,
7,
199,
19855,
21155,
63,
17179,
275,
469,
272,
283,
19174,
63,
515,
356,
1994,
396,
7,
199,
93,
199,
11365,
63,
26340,
275,
469,
272,
283,
9852,
63,
1023,
356,
283,
18,
14,
16,
14,
88,
13,
28708,
18,
14,
709,
297,
272,
283,
932,
63,
466,
63,
344,
356,
283,
82,
19,
14,
28598,
297,
272,
283,
1507,
63,
11009,
356,
413,
199,
93,
199,
9390,
63,
998,
275,
413,
199,
5449,
275,
283,
2154,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
7,
199,
5449,
63,
9139,
63,
30430,
275,
283,
2859,
921,
2154,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
7,
199,
17208,
275,
283,
2886,
7,
199,
9032,
275,
283,
2060,
7,
199,
8803,
275,
283,
1418,
7,
199,
3791,
63,
14565,
63,
7311,
275,
791,
751,
13,
4054,
356,
283,
15815,
24185,
86,
5285,
908,
8,
86,
18971,
1023,
3368,
93,
199,
9390,
63,
12898,
63,
2632,
275,
283,
2859,
921,
2483,
14,
4091,
14,
68,
1936,
322,
5618,
14,
957,
12645,
6920,
15,
17,
15,
10802,
15,
17,
7,
199,
2673,
5100,
63,
15068,
12507,
63,
6689,
275,
283,
21243,
7,
199,
6689,
63,
8272,
275,
283,
19189,
367,
4350,
7,
199,
2970,
63,
9390,
63,
12801,
275,
469,
272,
283,
1065,
63,
1606,
63,
633,
356,
21277,
63,
12898,
63,
2632,
12,
272,
283,
929,
356,
469,
267,
283,
13602,
63,
7612,
63,
929,
356,
3782,
5100,
63,
15068,
12507,
63,
6689,
12,
267,
283,
929,
63,
1188,
356,
11377,
63,
8272,
272,
789,
199,
93,
199,
9517,
63,
6689,
275,
488,
421,
199,
318,
11482,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
11482,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
7275,
1370,
908,
8,
1102,
9,
421,
199,
318,
664,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
664,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
362,
1370,
908,
8,
1102,
9,
199,
199,
318,
9311,
63,
1065,
63,
6520,
8,
1102,
304,
272,
408,
272,
20511,
805,
370,
3550,
314,
664,
1255,
6037,
1627,
314,
1591,
14,
272,
408,
272,
372,
283,
2859,
921,
2440,
15,
1246,
15,
18,
14,
16,
15,
6920,
15,
10802,
15,
6406,
1370,
908,
8,
1102,
9,
199,
199,
533,
577,
1936,
322,
5618,
8481,
774,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
577,
1936,
322,
5618,
8481,
14,
272,
408,
272,
768,
697,
14,
20824,
63,
1730,
272,
347,
3613,
8,
277,
12,
2351,
29,
403,
304,
267,
2557,
275,
2351,
14,
1131,
8,
3225,
9,
971,
288,
1275,
1541,
8,
3225,
14,
1631,
63,
344,
508,
6186,
63,
17489,
63,
998,
9,
971,
288,
1275,
2246,
342,
267,
2557,
14,
1102,
275,
25741,
267,
2557,
14,
2886,
275,
5051,
568,
267,
2557,
14,
2060,
275,
21705,
5172,
267,
2351,
14,
3543,
342,
398,
291,
14,
3664,
275,
577,
1936,
322,
5618,
8481,
342,
339,
347,
511,
63,
1122,
63,
1102,
63,
1045,
63,
28314,
63,
1102,
8,
277,
304,
267,
1591,
275,
291,
14,
3664,
423,
1122,
63,
1102,
8,
5449,
9,
267,
291,
14,
2947,
8,
1102,
12,
25741,
9,
339,
347,
511,
63,
1122,
63,
1102,
63,
1045,
63,
5512,
8,
277,
304,
267,
1591,
275,
291,
14,
3664,
423,
1122,
63,
1102,
8,
5449,
63,
9139,
63,
30430,
9,
267,
291,
14,
2947,
8,
1102,
12,
25741,
9,
339,
347,
511,
63,
826,
63,
4087,
63,
7154,
63,
3097,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
14844,
304,
288,
577,
1936,
322,
5618,
8481,
8,
7154,
63,
3097,
275,
378,
9,
339,
768,
1805,
14,
2068,
360,
15815,
14,
2828,
14,
7922,
14,
68,
1936,
322,
5618,
63,
3664,
14,
6615,
358,
272,
347,
511,
63,
1117,
63,
1246,
63,
1250,
63,
1045,
63,
705,
63,
7154,
8,
277,
12,
1683,
63,
6615,
304,
267,
367,
1919,
315,
359,
6615,
63,
3924,
14,
20349,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
# (C) British Crown Copyright 2013 - 2016, Met Office
#
# This file is part of Iris.
#
# Iris 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 3 of the License, or
# (at your option) any later version.
#
# Iris 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 Iris. If not, see <http://www.gnu.org/licenses/>.
#
# DO NOT EDIT: AUTO-GENERATED
# Created on 12 February 2016 17:02 from
# http://www.metarelate.net/metOcean
# at commit cf419fba84a70fba5f394f1481cfcdbba28877ff
# https://github.com/metarelate/metOcean/commit/cf419fba84a70fba5f394f1481cfcdbba28877ff
"""
Provides UM/CF phenomenon translations.
"""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
from collections import namedtuple
CFName = namedtuple('CFName', 'standard_name long_name units')
LBFC_TO_CF = {
5: CFName('atmosphere_boundary_layer_thickness', None, 'm'),
16: CFName('air_temperature', None, 'K'),
23: CFName('soil_temperature', None, 'K'),
27: CFName('air_density', None, 'kg m-3'),
36: CFName('land_area_fraction', None, '1'),
37: CFName('sea_ice_area_fraction', None, '1'),
50: CFName('wind_speed', None, 'm s-1'),
56: CFName('x_wind', None, 'm s-1'),
57: CFName('y_wind', None, 'm s-1'),
73: CFName('atmosphere_relative_vorticity', None, 's-1'),
74: CFName('divergence_of_wind', None, 's-1'),
83: CFName('potential_vorticity_of_atmosphere_layer', None, 'Pa-1 s-1'),
94: CFName('convective_rainfall_amount', None, 'kg m-2'),
97: CFName('rainfall_flux', None, 'kg m-2 s-1'),
102: CFName('stratiform_rainfall_amount', None, 'kg m-2'),
108: CFName('snowfall_flux', None, 'kg m-2 s-1'),
111: CFName('surface_runoff_amount', None, 'kg m-2'),
116: CFName('stratiform_snowfall_amount', None, 'kg m-2'),
117: CFName('convective_snowfall_amount', None, 'kg m-2'),
122: CFName('moisture_content_of_soil_layer', None, 'kg m-2'),
183: CFName('wind_speed', None, 'm s-1'),
200: CFName('toa_incoming_shortwave_flux', None, 'W m-2'),
203: CFName('surface_downwelling_shortwave_flux_in_air', None, 'W m-2'),
206: CFName('toa_outgoing_longwave_flux', None, 'W m-2'),
208: CFName('surface_downwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
209: CFName('sea_ice_temperature', None, 'K'),
253: CFName('tendency_of_air_temperature_due_to_longwave_heating', None, 'K s-1'),
261: CFName('downward_heat_flux_in_sea_ice', None, 'W m-2'),
321: CFName('root_depth', None, 'm'),
326: CFName('vegetation_area_fraction', None, '1'),
328: CFName('surface_albedo_assuming_deep_snow', None, '1'),
329: CFName('volume_fraction_of_condensed_water_in_soil_at_wilting_point', None, '1'),
330: CFName('volume_fraction_of_condensed_water_in_soil_at_critical_point', None, '1'),
332: CFName('soil_porosity', None, '1'),
333: CFName('soil_hydraulic_conductivity_at_saturation', None, 'm s-1'),
335: CFName('soil_thermal_capacity', None, 'J kg-1 K-1'),
336: CFName('soil_thermal_conductivity', None, 'W m-1 K-1'),
342: CFName('soil_suction_at_saturation', None, 'Pa'),
687: CFName('sea_ice_thickness', None, 'm'),
701: CFName('surface_eastward_sea_water_velocity', None, 'm s-1'),
702: CFName('surface_northward_sea_water_velocity', None, 'm s-1'),
1025: CFName('surface_downward_eastward_stress', None, 'Pa'),
1026: CFName('surface_downward_northward_stress', None, 'Pa'),
1373: CFName('mass_fraction_of_dimethyl_sulfide_in_air', None, '1'),
1374: CFName('mass_fraction_of_sulfur_dioxide_in_air', None, '1'),
1382: CFName('leaf_area_index', None, '1'),
1383: CFName('canopy_height', None, 'm'),
1385: CFName('mass_fraction_of_unfrozen_water_in_soil_moisture', None, '1'),
1386: CFName('mass_fraction_of_frozen_water_in_soil_moisture', None, '1'),
1392: CFName('leaf_area_index', None, '1'),
1393: CFName('canopy_height', None, 'm'),
1395: CFName('soil_albedo', None, '1'),
1507: CFName('snow_grain_size', None, '1e-6 m'),
1559: CFName('soil_moisture_content_at_field_capacity', None, 'kg m-2'),
1720: CFName('cloud_area_fraction_in_atmosphere_layer', None, '1'),
}
STASH_TO_CF = {
'm01s00i001': CFName('surface_air_pressure', None, 'Pa'),
'm01s00i002': CFName('x_wind', None, 'm s-1'),
'm01s00i003': CFName('y_wind', None, 'm s-1'),
'm01s00i004': CFName('air_potential_temperature', None, 'K'),
'm01s00i009': CFName('moisture_content_of_soil_layer', None, 'kg m-2'),
'm01s00i010': CFName('specific_humidity', None, 'kg kg-1'),
'm01s00i012': CFName('mass_fraction_of_cloud_ice_in_air', None, 'kg kg-1'),
'm01s00i013': CFName('convective_cloud_area_fraction', None, '1'),
'm01s00i020': CFName('soil_temperature', None, 'K'),
'm01s00i023': CFName('snowfall_amount', None, 'kg m-2'),
'm01s00i024': CFName('surface_temperature', None, 'K'),
'm01s00i025': CFName('atmosphere_boundary_layer_thickness', None, 'm'),
'm01s00i026': CFName('surface_roughness_length', None, 'm'),
'm01s00i028': CFName('surface_eastward_sea_water_velocity', None, 'm s-1'),
'm01s00i029': CFName('surface_northward_sea_water_velocity', None, 'm s-1'),
'm01s00i030': CFName('land_binary_mask', None, '1'),
'm01s00i031': CFName('sea_ice_area_fraction', None, '1'),
'm01s00i032': CFName('sea_ice_thickness', None, 'm'),
'm01s00i033': CFName('surface_altitude', None, 'm'),
'm01s00i040': CFName('volume_fraction_of_condensed_water_in_soil_at_wilting_point', None, '1'),
'm01s00i041': CFName('volume_fraction_of_condensed_water_in_soil_at_critical_point', None, '1'),
'm01s00i043': CFName('soil_porosity', None, '1'),
'm01s00i044': CFName('soil_hydraulic_conductivity_at_saturation', None, 'm s-1'),
'm01s00i046': CFName('soil_thermal_capacity', None, 'J kg-1 K-1'),
'm01s00i047': CFName('soil_thermal_conductivity', None, 'W m-1 K-1'),
'm01s00i048': CFName('soil_suction_at_saturation', None, 'Pa'),
'm01s00i049': CFName('sea_ice_temperature', None, 'K'),
'm01s00i050': CFName('vegetation_area_fraction', None, '1'),
'm01s00i051': CFName('root_depth', None, 'm'),
'm01s00i052': CFName('surface_albedo_assuming_no_snow', None, '1'),
'm01s00i053': CFName('surface_albedo_assuming_deep_snow', None, '1'),
'm01s00i058': CFName(None, 'tendency_of_atmosphere_mass_content_of_sulfur_dioxide_expressed_as_sulfur_due_to_low_level_emission', 'kg/m2/s'),
'm01s00i059': CFName(None, 'tendency_of_atmosphere_mass_content_of_dimethyl_sulfide_expressed_as_sulfur_due_to_emission', 'kg/m2/s'),
'm01s00i060': CFName('mass_fraction_of_ozone_in_air', None, '1'),
'm01s00i095': CFName(None, 'Snow amount on sea ice', 'kg/m^2'),
'm01s00i101': CFName(None, 'mass_fraction_of_sulfur_dioxide_expressed_as_sulfur_in_air', 'kg/kg'),
'm01s00i102': CFName(None, 'mass_fraction_of_dimethyl_sulfide_expressed_as_sulfur_in_air', 'kg/kg'),
'm01s00i103': CFName(None, 'mass_fraction_of_aitken_mode_sulfate_dry_aerosol_expressed_as_sulfur_in_air', 'kg/kg'),
'm01s00i104': CFName(None, 'mass_fraction_of_accumulation_mode_sulfate_dry_aerosol_expressed_as_sulfur_in_air', 'kg/kg'),
'm01s00i105': CFName(None, 'mass_fraction_of_dissolved_sulfate_dry_aerosol_expressed_as_sulfur_in_air', 'kg/kg'),
'm01s00i106': CFName('mass_fraction_of_hydrogen_peroxide_in_air', None, 'kg/kg'),
'm01s00i107': CFName(None, 'mass_fraction_of_ammonia_expressed_as_nitrogen_in_air', 'kg/kg'),
'm01s00i108': CFName(None, 'mass_fraction_of_fresh_black_carbon_dry_aerosol_in_air', 'kg/kg'),
'm01s00i109': CFName(None, 'mass_fraction_of_aged_black_carbon_dry_aerosol_in_air', 'kg/kg'),
'm01s00i110': CFName(None, 'mass_fraction_of_cloud_black_carbon_dry_aerosol_in_air', 'kg/kg'),
'm01s00i111': CFName(None, 'mass_fraction_of_fresh_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i112': CFName(None, 'mass_fraction_of_aged_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i113': CFName(None, 'mass_fraction_of_cloud_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i114': CFName(None, 'mass_fraction_of_fresh_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i115': CFName(None, 'mass_fraction_of_aged_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i116': CFName(None, 'mass_fraction_of_cloud_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i117': CFName(None, 'mass_fraction_of_accumulation_mode_nitrate_dry_aerosol_expressed_as_nitrogen_in_air', 'kg/kg'),
'm01s00i118': CFName(None, 'mass_fraction_of_dissolved_nitrate_dry_aerosol_expressed_as_nitrogen_in_air', 'kg/kg'),
'm01s00i121': CFName(None, 'tendency_of_atmosphere_mass_content_of_sulfur_dioxide_expressed_as_sulfur_due_to_volcanic_emission', 'kg/kg'),
'm01s00i122': CFName(None, 'molecular_concentration_of_hydroxyl_radical_in_air', 'cm-3'),
'm01s00i123': CFName(None, 'molecular_concentration_of_hydroperoxyl_radical_in_air', 'cm-3'),
'm01s00i124': CFName('mass_fraction_of_hydrogen_peroxide_in_air', None, 'kg/kg'),
'm01s00i125': CFName('mass_fraction_of_ozone_in_air', None, 'kg/kg'),
'm01s00i126': CFName(None, 'tendency_of_atmosphere_mass_content_of_sulfur_dioxide_expressed_as_sulfur_due_to_high_level_emission', 'kg/m2/s'),
'm01s00i127': CFName(None, 'tendency_of_atmosphere_mass_content_of_ammonia_expressed_as_nitrogen_due_to_emission', 'kg/m2/s'),
'm01s00i128': CFName(None, 'tendency_of_atmosphere_mass_content_of_black_carbon_dry_aerosol_due_to_low_level_emission', 'kg/m2/s'),
'm01s00i129': CFName(None, 'tendency_of_atmosphere_mass_content_of_black_carbon_dry_aerosol_due_to_high_level_emission', 'kg/m2/s'),
'm01s00i130': CFName(None, 'tendency_of_atmosphere_mass_content_of_biomass_burning_dry_aerosol_due_to_low_level_emission', 'kg/m2/s'),
'm01s00i131': CFName(None, 'tendency_of_atmosphere_mass_content_of_biomass_burning_dry_aerosol_due_to_high_level_emission', 'kg/m2/s'),
'm01s00i132': CFName('mole_concentration_of_dimethyl_sulfide_in_sea_water', None, 'nanomole/l'),
'm01s00i134': CFName(None, 'tendency_of_atmosphere_mass_content_of_organic_carbon_from_fossil_fuel_dry_aerosol_due_to_low_level_emission', 'kg/m2/s'),
'm01s00i135': CFName(None, 'tendency_of_atmosphere_mass_content_of_organic_carbon_from_fossil_fuel_dry_aerosol_due_to_high_level_emission', 'kg/m2/s'),
'm01s00i150': CFName('upward_air_velocity', None, 'm s-1'),
'm01s00i205': CFName('land_area_fraction', None, '1'),
'm01s00i208': CFName('leaf_area_index', None, '1'),
'm01s00i209': CFName('canopy_height', None, 'm'),
'm01s00i211': CFName(None, 'Convective cloud amount with anvil', '1'),
'm01s00i214': CFName('mass_fraction_of_unfrozen_water_in_soil_moisture', None, '1'),
'm01s00i215': CFName('mass_fraction_of_frozen_water_in_soil_moisture', None, '1'),
'm01s00i217': CFName('leaf_area_index', None, '1'),
'm01s00i218': CFName('canopy_height', None, 'm'),
'm01s00i220': CFName('soil_albedo', None, '1'),
'm01s00i223': CFName('soil_carbon_content', None, 'kg m-2'),
'm01s00i231': CFName('snow_grain_size', None, '1e-6 m'),
'm01s00i243': CFName(None, 'surface_diffuse_albedo_assuming_no_snow', '1'),
'm01s00i244': CFName(None, 'surface_diffuse_albedo_of_photosynthetically_active_radiation_assuming_no_snow', '1'),
'm01s00i245': CFName(None, 'surface_diffuse_albedo_of_near_infra_red_radiation_assuming_no_snow', '1'),
'm01s00i252': CFName('mass_fraction_of_carbon_dioxide_in_air', None, '1'),
'm01s00i254': CFName('mass_fraction_of_cloud_liquid_water_in_air', None, 'kg kg-1'),
'm01s00i255': CFName('dimensionless_exner_function', None, '1'),
'm01s00i265': CFName('cloud_area_fraction_in_atmosphere_layer', None, '1'),
'm01s00i266': CFName(None, 'cloud_volume_fraction_in_atmosphere_layer', '1'),
'm01s00i267': CFName(None, 'liquid_cloud_volume_fraction_in_atmosphere_layer', '1'),
'm01s00i268': CFName(None, 'ice_cloud_volume_fraction_in_atmosphere_layer', '1'),
'm01s00i269': CFName('surface_eastward_sea_water_velocity', None, 'm s-1'),
'm01s00i270': CFName('surface_northward_sea_water_velocity', None, 'm s-1'),
'm01s00i351': CFName(None, 'mass_concentration_of_biogenic_nmvoc_in_air', 'kg/kg'),
'm01s00i352': CFName(None, 'mass_fraction_of_fresh_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i353': CFName(None, 'mass_fraction_of_aged_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i354': CFName(None, 'mass_fraction_of_cloud_biomass_burning_dry_aerosol_in_air', 'kg/kg'),
'm01s00i355': CFName(None, 'mass_fraction_of_fresh_black_carbon_dry_aerosol_in_air', 'kg/kg'),
'm01s00i356': CFName(None, 'mass_fraction_of_aged_black_carbon_dry_aerosol_in_air', 'kg/kg'),
'm01s00i357': CFName(None, 'atmosphere_number_concentration_of_film_mode_sea_salt_particles', 'kg/kg'),
'm01s00i358': CFName(None, 'atmosphere_number_concentration_of_jet_mode_sea_salt_particles', 'kg/kg'),
'm01s00i359': CFName(None, 'mass_fraction_of_aitken_mode_sulfate_dry_aerosol_in_air_expressed_as_sulfur', 'kg/kg'),
'm01s00i360': CFName(None, 'mass_fraction_of_accumulation_mode_sulfate_dry_aerosol_in_air_expressed_as_sulfur', 'kg/kg'),
'm01s00i361': CFName(None, 'mass_fraction_of_dissolved_sulfate_dry_aerosol_in_air_expressed_as_sulfur', 'kg/kg'),
'm01s00i362': CFName(None, 'mass_fraction_of_dust_ukmo_division_1_dry_aerosol_in_air', 'kg/kg'),
'm01s00i363': CFName(None, 'mass_fraction_of_dust_ukmo_division_2_dry_aerosol_in_air', 'kg/kg'),
'm01s00i364': CFName(None, 'mass_fraction_of_dust_ukmo_division_3_dry_aerosol_in_air', 'kg/kg'),
'm01s00i365': CFName(None, 'mass_fraction_of_dust_ukmo_division_4_dry_aerosol_in_air', 'kg/kg'),
'm01s00i366': CFName(None, 'mass_fraction_of_dust_ukmo_division_5_dry_aerosol_in_air', 'kg/kg'),
'm01s00i367': CFName(None, 'mass_fraction_of_dust_ukmo_division_6_dry_aerosol_in_air', 'kg/kg'),
'm01s00i368': CFName(None, 'mass_fraction_of_fresh_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i369': CFName(None, 'mass_fraction_of_aged_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i370': CFName(None, 'mass_fraction_of_cloud_organic_carbon_from_fossil_fuel_dry_aerosol_in_air', 'kg/kg'),
'm01s00i371': CFName(None, 'mass_concentration_of_unspecified_aerosol_in_air', 'kg/kg'),
'm01s00i406': CFName('dimensionless_exner_function', None, '1'),
'm01s00i407': CFName('air_pressure', None, 'Pa'),
'm01s00i408': CFName('air_pressure', None, 'Pa'),
'm01s00i409': CFName('surface_air_pressure', None, 'Pa'),
'm01s00i413': CFName(None, 'Sea ice concentration by categories', '1'),
'm01s00i414': CFName(None, 'Sea ice thickness GBM by categories', 'm'),
'm01s00i415': CFName('sea_ice_surface_temperature', None, 'K'),
'm01s00i416': CFName(None, 'Snow thickness on sea ice', 'm'),
'm01s00i418': CFName('volume_fraction_of_clay_in_soil', None, 'm3/m3'),
'm01s00i419': CFName('volume_fraction_of_silt_in_soil', None, 'm3/m3'),
'm01s00i420': CFName('volume_fraction_of_sand_in_soil', None, 'm3/m3'),
'm01s00i421': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division1', 'kg/kg'),
'm01s00i422': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division2', 'kg/kg'),
'm01s00i423': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division3', 'kg/kg'),
'm01s00i424': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division4', 'kg/kg'),
'm01s00i425': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division5', 'kg/kg'),
'm01s00i426': CFName(None, 'mass_fraction_of_soil_particles_in_ukmo_division6', 'kg/kg'),
'm01s00i431': CFName(None, 'mass_fraction_of_dust_ukmo_division_1_dry_aerosol_in_air', 'kg/kg'),
'm01s00i432': CFName(None, 'mass_fraction_of_dust_ukmo_division_2_dry_aerosol_in_air', 'kg/kg'),
'm01s00i433': CFName(None, 'mass_fraction_of_dust_ukmo_division_3_dry_aerosol_in_air', 'kg/kg'),
'm01s00i434': CFName(None, 'mass_fraction_of_dust_ukmo_division_4_dry_aerosol_in_air', 'kg/kg'),
'm01s00i435': CFName(None, 'mass_fraction_of_dust_ukmo_division_5_dry_aerosol_in_air', 'kg/kg'),
'm01s00i436': CFName(None, 'mass_fraction_of_dust_ukmo_division_6_dry_aerosol_in_air', 'kg/kg'),
'm01s00i505': CFName('land_area_fraction', None, '1'),
'm01s00i506': CFName('surface_temperature', None, 'K'),
'm01s00i507': CFName('surface_temperature', None, 'K'),
'm01s00i508': CFName('surface_temperature', None, 'K'),
'm01s00i509': CFName(None, 'product_of_sea_ice_albedo_and_sunlit_binary_mask', '1'),
'm01s00i510': CFName(None, 'product_of_land_albedo_and_sunlit_binary_mask', '1'),
'm01s01i004': CFName('air_temperature', None, 'K'),
'm01s01i101': CFName(None, 'northward_horizon_angle_from_zenith', 'rad'),
'm01s01i102': CFName(None, 'northeastward_horizon_angle_from_zenith', 'rad'),
'm01s01i103': CFName(None, 'eastward_horizon_angle_from_zenith', 'rad'),
'm01s01i104': CFName(None, 'southeastward_horizon_angle_from_zenith', 'rad'),
'm01s01i105': CFName(None, 'southward_horizon_angle_from_zenith', 'rad'),
'm01s01i106': CFName(None, 'southwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i107': CFName(None, 'westward_horizon_angle_from_zenith', 'rad'),
'm01s01i108': CFName(None, 'northwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i109': CFName(None, 'northnortheastward_horizon_angle_from_zenith', 'rad'),
'm01s01i110': CFName(None, 'eastnortheastward_horizon_angle_from_zenith', 'rad'),
'm01s01i111': CFName(None, 'eastsoutheastward_horizon_angle_from_zenith', 'rad'),
'm01s01i112': CFName(None, 'southsoutheastward_horizon_angle_from_zenith', 'rad'),
'm01s01i113': CFName(None, 'southsouthwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i114': CFName(None, 'westsouthwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i115': CFName(None, 'westnorthwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i116': CFName(None, 'northnorthwestward_horizon_angle_from_zenith', 'rad'),
'm01s01i201': CFName('surface_net_downward_shortwave_flux', None, 'W m-2'),
'm01s01i203': CFName('surface_net_downward_shortwave_flux', None, 'W m-2'),
'm01s01i205': CFName('toa_outgoing_shortwave_flux', None, 'W m-2'),
'm01s01i207': CFName('toa_incoming_shortwave_flux', None, 'W m-2'),
'm01s01i208': CFName('toa_outgoing_shortwave_flux', None, 'W m-2'),
'm01s01i209': CFName('toa_outgoing_shortwave_flux_assuming_clear_sky', None, 'W m-2'),
'm01s01i210': CFName('surface_downwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s01i211': CFName('surface_upwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s01i217': CFName('upwelling_shortwave_flux_in_air', None, 'W m-2'),
'm01s01i218': CFName('downwelling_shortwave_flux_in_air', None, 'W m-2'),
'm01s01i219': CFName('upwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s01i220': CFName('downwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s01i221': CFName(None, 'product_of_effective_radius_of_stratiform_cloud_liquid_water_particle_and_stratiform_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', 'um'),
'm01s01i223': CFName(None, 'product_of_stratiform_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', '1'),
'm01s01i224': CFName(None, 'product_of_stratiform_cloud_liquid_water_path_and_stratiform_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', 'kg m-2'),
'm01s01i225': CFName(None, 'product_of_effective_radius_of_convective_cloud_liquid_water_particle_and_convective_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', 'um'),
'm01s01i226': CFName(None, 'product_of_convective_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', '1'),
'm01s01i232': CFName('tendency_of_air_temperature_due_to_shortwave_heating', None, 'K s-1'),
'm01s01i233': CFName('tendency_of_air_temperature_due_to_shortwave_heating_assuming_clear_sky', None, 'K s-1'),
'm01s01i235': CFName('surface_downwelling_shortwave_flux_in_air', None, 'W m-2'),
'm01s01i237': CFName('net_downward_shortwave_flux_in_air', None, 'W m-2'),
'm01s01i238': CFName('tropopause_upwelling_shortwave_flux', None, 'unknown'),
'm01s01i241': CFName(None, 'product_of_number_concentration_of_stratiform_cloud_liquid_water_particles_and_stratiform_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', 'cm-3'),
'm01s01i242': CFName(None, 'product_of_stratiform_cloud_liquid_water_content_and_stratiform_cloud_liquid_water_area_fraction_and_sunlit_binary_mask', 'g cm-3'),
'm01s01i243': CFName(None, 'product_of_mass_concentration_of_sulfate_ion_and_sunlit_binary_mask', 'ug m-3'),
'm01s01i244': CFName(None, 'sunlit_binary_mask_in_atmosphere_layer_below_cloud_top', '1'),
'm01s01i245': CFName(None, 'product_of_effective_radius_of_cloud_liquid_water_particle_and_cloud_liquid_water_area_fraction_exposed_to_space_and_sunlit_binary_mask', 'um'),
'm01s01i246': CFName(None, 'product_of_cloud_liquid_water_area_fraction_exposed_to_space_and_sunlit_binary_mask', '1'),
'm01s01i247': CFName(None, 'atmosphere_number_concentration_of_film_mode_sea_salt_particles', 'm-3'),
'm01s01i248': CFName(None, 'atmosphere_number_concentration_of_jet_mode_sea_salt_particles', 'm-3'),
'm01s01i254': CFName(None, 'product_of_effective_radius_of_warm_cloud_liquid_water_particle_and_warm_cloud_liquid_water_area_fraction_exposed_to_space_and_sunlit_binary_mask', 'um'),
'm01s01i255': CFName(None, 'product_of_warm_cloud_liquid_water_area_fraction_exposed_to_space_and_sunlit_binary_mask', '1'),
'm01s01i268': CFName(None, 'surface_direct_beam_albedo_assuming_no_snow', '1'),
'm01s01i269': CFName(None, 'surface_diffuse_albedo_assuming_no_snow', '1'),
'm01s01i270': CFName(None, 'scaling_factor_for_surface_diffuse_albedo_of_photosynthetically_active_radiation_assuming_no_snow', '1'),
'm01s01i271': CFName(None, 'scaling_factor_for_surface_diffuse_albedo_of_near_infra_red_radiation_assuming_no_snow', '1'),
'm01s01i280': CFName(None, 'product_of_atmosphere_number_content_of_cloud_droplets_and_warm_cloud_area_fraction_and_sunlit_binary_mask', 'm-2'),
'm01s01i281': CFName(None, 'product_of_warm_cloud_area_fraction_and_sunlit_binary_mask', '1'),
'm01s01i294': CFName(None, 'surface_mean_slope_angle', 'rad'),
'm01s01i295': CFName(None, 'orographic_correction_factor_to_surface_direct_downwelling_shortwave_flux', '1'),
'm01s01i410': CFName('surface_downwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s01i435': CFName('surface_downwelling_shortwave_flux_in_air', None, 'W m-2'),
'm01s02i004': CFName('air_temperature', None, 'K'),
'm01s02i101': CFName(None, 'ratio_of_skyview_factor_to_cosine_of_surface_mean_slope_angle', '1'),
'm01s02i201': CFName('surface_net_downward_longwave_flux', None, 'W m-2'),
'm01s02i203': CFName('surface_net_downward_longwave_flux', None, 'W m-2'),
'm01s02i204': CFName('cloud_area_fraction', None, '1'),
'm01s02i205': CFName('toa_outgoing_longwave_flux', None, 'W m-2'),
'm01s02i206': CFName('toa_outgoing_longwave_flux_assuming_clear_sky', None, 'W m-2'),
'm01s02i207': CFName('surface_downwelling_longwave_flux', None, 'W m-2'),
'm01s02i208': CFName(None, 'surface_downwelling_longwave_flux_assuming_clear_sky', 'W m-2'),
'm01s02i217': CFName('upwelling_longwave_flux_in_air', None, 'W m-2'),
'm01s02i218': CFName('downwelling_longwave_flux_in_air', None, 'W m-2'),
'm01s02i219': CFName('upwelling_longwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s02i220': CFName('downwelling_longwave_flux_in_air_assuming_clear_sky', None, 'W m-2'),
'm01s02i232': CFName('tendency_of_air_temperature_due_to_longwave_heating', None, 'K s-1'),
'm01s02i233': CFName('tendency_of_air_temperature_due_to_longwave_heating_assuming_clear_sky', None, 'K s-1'),
'm01s02i237': CFName('tropopause_net_downward_longwave_flux', None, 'W m-2'),
'm01s02i238': CFName('tropopause_downwelling_longwave_flux', None, 'W m-2'),
'm01s02i260': CFName('mass_fraction_of_ozone_in_air', None, '1'),
'm01s02i261': CFName('cloud_area_fraction_in_atmosphere_layer', None, '1'),
'm01s02i262': CFName(None, 'product_of_mass_absorption_coefficient_due_to_cloud_and_upwelling_longwave_flux_assuming_clear_sky_and_cloud_area_fraction_in_atmosphere_layer', 'W kg-1'),
'm01s02i263': CFName(None, 'product_of_upwelling_longwave_flux_assuming_clear_sky_and_cloud_area_fraction_in_atmosphere_layer', 'W m-2'),
'm01s02i264': CFName(None, 'product_of_mass_absorption_coefficient_due_to_stratiform_cloud_and_upwelling_longwave_flux_assuming_clear_sky_and_stratiform_cloud_area_fraction_in_atmosphere_layer', 'W kg-1'),
'm01s02i265': CFName(None, 'product_of_upwelling_longwave_flux_assuming_clear_sky_and_stratiform_cloud_area_fraction_in_atmosphere_layer', 'W m-2'),
'm01s02i266': CFName(None, 'product_of_mass_absorption_coefficient_due_to_convective_cloud_and_upwelling_longwave_flux_assuming_clear_sky_and_convective_cloud_area_fraction_in_atmosphere_layer', 'W kg-1'),
'm01s02i267': CFName(None, 'product_of_upwelling_longwave_flux_assuming_clear_sky_and_convective_cloud_area_fraction_in_atmosphere_layer', 'W m-2'),
'm01s02i280': CFName(None, 'model_level_number_at_ozone_tropopause', '1'),
'm01s02i281': CFName(None, 'ozone_tropopause_altitude', 'm'),
'm01s02i282': CFName(None, 'model_level_number_at_thermal_tropopause', '1'),
'm01s02i283': CFName(None, 'thermal_tropopause_altitude', 'm'),
'm01s02i284': CFName(None, 'atmosphere_optical_thickness_due_to_sulphate_ambient_aerosol', '1'),
'm01s02i285': CFName('atmosphere_optical_thickness_due_to_dust_ambient_aerosol', None, '1'),
'm01s02i286': CFName('atmosphere_optical_thickness_due_to_seasalt_ambient_aerosol', None, '1'),
'm01s02i287': CFName('atmosphere_optical_thickness_due_to_black_carbon_ambient_aerosol', None, '1'),
'm01s02i288': CFName(None, 'atmosphere_optical_thickness_due_to_biomass_burning_ambient_aerosol', '1'),
'm01s02i289': CFName(None, 'atmosphere_optical_thickness_due_to_biogenic_aerosol', '1'),
'm01s02i295': CFName(None, 'atmosphere_optical_thickness_due_to_fossil_fuel_organic_carbon_ambient_aerosol', '1'),
'm01s02i296': CFName(None, 'atmosphere_optical_thickness_due_to_unspecified_aerosol', '1'),
'm01s02i297': CFName(None, 'atmosphere_optical_thickness_due_to_ammonium_nitrate_ambient_aerosol', '1'),
'm01s02i298': CFName(None, 'atmosphere_optical_thickness_due_all_ambient_aerosol', '1'),
'm01s02i299': CFName('angstrom_exponent_of_ambient_aerosol_in_air', None, '1'),
'm01s02i300': CFName(None, 'atmosphere_optical_thickness_due_to_soluble_aitken_mode_sulphate_aerosol', '1'),
'm01s02i301': CFName(None, 'atmosphere_optical_thickness_due_to_soluble_accumulation_mode_sulphate_aerosol', '1'),
'm01s02i302': CFName(None, 'atmosphere_optical_thickness_due_to_soluble_coarse_mode_sulphate_aerosol', '1'),
'm01s02i303': CFName(None, 'atmosphere_optical_thickness_due_to_insoluble_aitken_mode_sulphate_aerosol', '1'),
'm01s02i304': CFName(None, 'atmosphere_optical_thickness_due_to_unsoluble_accumulation_mode_sulphate_aerosol', '1'),
'm01s02i305': CFName(None, 'atmosphere_optical_thickness_due_to_unsoluble_coarse_mode_sulphate_aerosol', '1'),
'm01s02i308': CFName('mass_fraction_of_stratiform_cloud_liquid_water_in_air', None, '1'),
'm01s02i309': CFName('mass_fraction_of_stratiform_cloud_ice_in_air', None, '1'),
'm01s02i310': CFName('mass_fraction_of_convective_cloud_liquid_water_in_air', None, '1'),
'm01s02i311': CFName('mass_fraction_of_convective_cloud_ice_in_air', None, '1'),
'm01s02i312': CFName(None, 'stratiform_cloud_liquid_water_area_fraction_in_atmosphere_layer', '1'),
'm01s02i313': CFName(None, 'stratiform_cloud_ice_area_fraction_in_atmosphere_layer', '1'),
'm01s02i314': CFName(None, 'convective_cloud_liquid_water_area_fraction_in_atmosphere_layer', '1'),
'm01s02i315': CFName(None, 'convective_cloud_ice_area_fraction_in_atmosphere_layer', '1'),
'm01s02i348': CFName('toa_bidirectional_reflectance', None, '1'),
'm01s02i351': CFName('equivalent_reflectivity_factor', None, 'dB'),
'm01s02i370': CFName('histogram_of_backscattering_ratio_over_height_above_reference_ellipsoid', None, '1'),
'm01s02i372': CFName('histogram_of_equivalent_reflectivity_factor_over_height_above_reference_ellipsoid', None, '1'),
'm01s02i375': CFName('atmosphere_optical_thickness_due_to_stratiform_cloud', None, '1'),
'm01s02i376': CFName('stratiform_cloud_longwave_emissivity', None, '1'),
'm01s02i377': CFName('atmosphere_optical_thickness_due_to_convective_cloud', None, '1'),
'm01s02i378': CFName('convective_cloud_longwave_emissivity', None, '1'),
'm01s02i380': CFName('effective_radius_of_stratiform_cloud_liquid_water_particle', None, 'm'),
'm01s02i381': CFName('effective_radius_of_stratiform_cloud_ice_particle', None, 'm'),
'm01s02i382': CFName('effective_radius_of_stratiform_cloud_rain_particle', None, 'm'),
'm01s02i383': CFName('effective_radius_of_stratiform_cloud_snow_particle', None, 'm'),
'm01s02i384': CFName('effective_radius_of_convective_cloud_liquid_water_particle', None, 'm'),
'm01s02i385': CFName('effective_radius_of_convective_cloud_ice_particle', None, 'm'),
'm01s02i386': CFName('effective_radius_of_convective_cloud_rain_particle', None, 'm'),
'm01s02i387': CFName('effective_radius_of_convective_cloud_snow_particle', None, 'm'),
'm01s02i388': CFName('effective_radius_of_stratiform_cloud_graupel_particle', None, 'm'),
'm01s02i421': CFName(None, 'atmosphere_optical_thickness_due_to_sulphate_ambient_aerosol', '1'),
'm01s02i422': CFName('atmosphere_optical_thickness_due_to_dust_ambient_aerosol', None, '1'),
'm01s02i423': CFName('atmosphere_optical_thickness_due_to_seasalt_ambient_aerosol', None, '1'),
'm01s02i424': CFName('atmosphere_optical_thickness_due_to_black_carbon_ambient_aerosol', None, '1'),
'm01s02i425': CFName(None, 'atmosphere_optical_thickness_due_to_biomass_burning_ambient_aerosol', '1'),
'm01s02i426': CFName(None, 'atmosphere_optical_thickness_due_to_fossil_fuel_organic_carbon_ambient_aerosol', '1'),
'm01s02i427': CFName(None, 'atmosphere_optical_thickness_due_to_ammonium_nitrate_ambient_aerosol', '1'),
'm01s03i004': CFName('air_temperature', None, 'm s-1'),
'm01s03i010': CFName('specific_humidity', None, '1'),
'm01s03i025': CFName('atmosphere_boundary_layer_thickness', None, 'm'),
'm01s03i201': CFName('downward_heat_flux_in_sea_ice', None, 'W m-2'),
'm01s03i202': CFName('downward_heat_flux_in_soil', None, 'unknown'),
'm01s03i209': CFName('x_wind', None, 'm s-1'),
'm01s03i210': CFName('y_wind', None, 'm s-1'),
'm01s03i217': CFName('surface_upward_sensible_heat_flux', None, 'W m-2'),
'm01s03i219': CFName('surface_downward_eastward_stress', None, 'Pa'),
'm01s03i220': CFName('surface_downward_northward_stress', None, 'Pa'),
'm01s03i223': CFName('surface_upward_water_flux', None, 'kg m-2 s-1'),
'm01s03i224': CFName('wind_mixing_energy_flux_into_sea_water', None, 'W m-2'),
'm01s03i225': CFName('x_wind', None, 'm s-1'),
'm01s03i226': CFName('y_wind', None, 'm s-1'),
'm01s03i227': CFName('wind_speed', None, 'm s-1'),
'm01s03i228': CFName('surface_upward_sensible_heat_flux', None, 'W m-2'),
'm01s03i230': CFName('wind_speed', None, 'm s-1'),
'm01s03i231': CFName(None, 'water_sublimation_flux_in_timestep', 'kg m-2'),
'm01s03i232': CFName(None, 'Evaporation flux from open sea', 'kg/m^2/s'),
'm01s03i234': CFName('surface_upward_latent_heat_flux', None, 'W m-2'),
'm01s03i235': CFName(None, 'Latent heat flux from sea ice top melt', 'W/m^2'),
'm01s03i236': CFName('air_temperature', None, 'K'),
'm01s03i237': CFName('specific_humidity', None, '1'),
'm01s03i238': CFName('soil_temperature', None, 'K'),
'm01s03i245': CFName('relative_humidity', None, '%'),
'm01s03i247': CFName('visibility_in_air', None, 'm'),
'm01s03i248': CFName('fog_area_fraction', None, '1'),
'm01s03i249': CFName('wind_speed', None, 'm s-1'),
'm01s03i250': CFName('dew_point_temperature', None, 'K'),
'm01s03i256': CFName(None, 'Heat flux through sea ice', 'W/m^2'),
'm01s03i257': CFName(None, 'Heat flux in sea ice surface melt', 'W/m^2'),
'm01s03i258': CFName('surface_snow_melt_heat_flux', None, 'W m-2'),
'm01s03i261': CFName('gross_primary_productivity_of_carbon', None, 'kg m-2 s-1'),
'm01s03i262': CFName('net_primary_productivity_of_carbon', None, 'kg m-2 s-1'),
'm01s03i263': CFName('plant_respiration_carbon_flux', None, 'kg/m^2/s'),
'm01s03i270': CFName('tendency_of_atmosphere_mass_content_of_sulfur_dioxide_due_to_dry_deposition', None, 'kg m-2 s-1'),
'm01s03i281': CFName('visibility_in_air', None, 'm'),
'm01s03i293': CFName('soil_respiration_carbon_flux', None, 'kg/m^2/s'),
'm01s03i295': CFName(None, 'surface_snow_area_fraction_where_land', '%'),
'm01s03i296': CFName(None, 'Evaporation from soil surface', 'kg/m^2/s'),
'm01s03i297': CFName(None, 'Evaporation from canopy', 'kg/m^2/s'),
'm01s03i298': CFName('water_sublimation_flux', None, 'kg m-2 s-1'),
'm01s03i300': CFName('tendency_of_atmosphere_mass_content_of_ammonia_due_to_dry_deposition', None, 'kg m-2 s-1'),
'm01s03i304': CFName(None, 'Turbulent mixing height after boundary layer', 'm'),
'm01s03i305': CFName(None, 'Stable boundary layer indicator', '1'),
'm01s03i306': CFName(None, 'Stratocumulus over stable boundary layer indicator', '1'),
'm01s03i307': CFName(None, 'Well-mixed boundary layer indicator', '1'),
'm01s03i308': CFName(None, 'Decoupled stratocumulus not over cumulus indicator', '1'),
'm01s03i309': CFName(None, 'Decoupled stratocumulus over cumulus indicator', '1'),
'm01s03i310': CFName(None, 'Cumulus capped boundary layer indicator', '1'),
'm01s03i313': CFName('soil_moisture_content_at_field_capacity', None, 'kg m-2'),
'm01s03i321': CFName(None, 'Canopy water on tiles', 'kg/m^2'),
'm01s03i331': CFName(None, 'Sublimation moisture flux on tiles', 'kg/m^2/s'),
'm01s03i332': CFName('toa_outgoing_longwave_flux', None, 'W m-2'),
'm01s03i334': CFName('water_potential_evaporation_flux', None, 'kg m-2 s-1'),
'm01s03i337': CFName('downward_heat_flux_in_soil', None, 'W m-2'),
'm01s03i340': CFName(None, 'Shear driven boundary layer indicator', '1'),
'm01s03i353': CFName(None, 'Sublimation of sea ice meaned over sea portion of grid box', 'kg/m^2/s'),
'm01s03i391': CFName('surface_downward_eastward_stress', None, 'Pa'),
'm01s03i392': CFName('surface_downward_eastward_stress', None, 'Pa'),
'm01s03i393': CFName('surface_downward_northward_stress', None, 'Pa'),
'm01s03i394': CFName('surface_downward_northward_stress', None, 'Pa'),
'm01s03i401': CFName(None, 'Dust emissions division 1', 'kg/m^2/s'),
'm01s03i402': CFName(None, 'Dust emissions division 2', 'kg/m^2/s'),
'm01s03i403': CFName(None, 'Dust emissions division 3', 'kg/m^2/s'),
'm01s03i404': CFName(None, 'Dust emissions division 4', 'kg/m^2/s'),
'm01s03i405': CFName(None, 'Dust emissions division 5', 'kg/m^2/s'),
'm01s03i406': CFName(None, 'Dust emissions division 6', 'kg/m^2/s'),
'm01s03i430': CFName(None, 'Dust friction velocity', 'm/s'),
'm01s03i441': CFName(None, 'Dust dry deposition flux division 1 from level 1', 'kg/m^2/s'),
'm01s03i442': CFName(None, 'Dust dry deposition flux division 2 from level 1', 'kg/m^2/s'),
'm01s03i443': CFName(None, 'Dust dry deposition flux division 3 from level 1', 'kg/m^2/s'),
'm01s03i444': CFName(None, 'Dust dry deposition flux division 4 from level 1', 'kg/m^2/s'),
'm01s03i445': CFName(None, 'Dust dry deposition flux division 5 from level 1', 'kg/m^2/s'),
'm01s03i446': CFName(None, 'Dust dry deposition flux division 6 from level 1', 'kg/m^2/s'),
'm01s03i451': CFName(None, 'Dust dry deposition flux division 1 from level 2', 'kg/m^2/s'),
'm01s03i452': CFName(None, 'Dust dry deposition flux division 2 from level 2', 'kg/m^2/s'),
'm01s03i453': CFName(None, 'Dust dry deposition flux division 3 from level 2', 'kg/m^2/s'),
'm01s03i454': CFName(None, 'Dust dry deposition flux division 4 from level 2', 'kg/m^2/s'),
'm01s03i455': CFName(None, 'Dust dry deposition flux division 5 from level 2', 'kg/m^2/s'),
'm01s03i456': CFName(None, 'Dust dry deposition flux division 6 from level 2', 'kg/m^2/s'),
'm01s03i460': CFName('surface_downward_eastward_stress', None, 'Pa'),
'm01s03i461': CFName('surface_downward_northward_stress', None, 'Pa'),
'm01s03i463': CFName('wind_speed_of_gust', None, 'm s-1'),
'm01s03i471': CFName('atmosphere_momentum_diffusivity', None, 'm2 s-1'),
'm01s03i472': CFName('atmosphere_heat_diffusivity', None, 'm2 s-1'),
'm01s03i491': CFName('surface_carbon_dioxide_mole_flux', None, 'mol m-2 s-1'),
'm01s04i004': CFName('air_temperature', None, 'K'),
'm01s04i010': CFName('specific_humidity', None, '1'),
'm01s04i201': CFName('stratiform_rainfall_amount', None, 'kg m-2'),
'm01s04i202': CFName('stratiform_snowfall_amount', None, 'kg m-2'),
'm01s04i203': CFName('stratiform_rainfall_rate', None, 'kg m-2 s-1'),
'm01s04i204': CFName(None, 'stratiform_snowfall_rate', 'kg m-2 s-1'),
'm01s04i205': CFName('mass_fraction_of_cloud_liquid_water_in_air', None, '1'),
'm01s04i206': CFName('mass_fraction_of_cloud_ice_in_air', None, '1'),
'm01s04i222': CFName('large_scale_rainfall_flux', None, 'kg m-2 s-1'),
'm01s04i223': CFName('large_scale_snowfall_flux', None, 'kg m-2 s-1'),
'm01s04i231': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 1', 'kg/m^2/s'),
'm01s04i232': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 2', 'kg/m^2/s'),
'm01s04i233': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 3', 'kg/m^2/s'),
'm01s04i234': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 4', 'kg/m^2/s'),
'm01s04i235': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 5', 'kg/m^2/s'),
'm01s04i236': CFName(None, 'Dust wet deposition flux due to large scale precipitation division 6', 'kg/m^2/s'),
'm01s04i240': CFName('tendency_of_mass_fraction_of_stratiform_cloud_ice_in_air_due_to_homogeneous_nucleation', None, 's-1'),
'm01s04i242': CFName('tendency_of_mass_fraction_of_stratiform_cloud_ice_in_air_due_to_heterogeneous_nucleation_from_cloud_liquid', None, 's-1'),
'm01s04i247': CFName('tendency_of_mass_fraction_of_stratiform_cloud_ice_in_air_due_to_riming_from_cloud_liquid', None, 's-1'),
'm01s05i010': CFName('specific_humidity', None, '1'),
'm01s05i181': CFName('tendency_of_air_temperature_due_to_convection', None, 'K s-1'),
'm01s05i182': CFName('tendency_of_specific_humidity_due_to_convection', None, 's-1'),
'm01s05i185': CFName('tendency_of_eastward_wind_due_to_convection', None, 'm s-2'),
'm01s05i186': CFName('tendency_of_northward_wind_due_to_convection', None, 'm s-2'),
'm01s05i201': CFName('convective_rainfall_amount', None, 'kg m-2'),
'm01s05i202': CFName('convective_snowfall_amount', None, 'kg m-2'),
'm01s05i205': CFName('convective_rainfall_rate', None, 'kg m-2 s-1'),
'm01s05i206': CFName('convective_snowfall_flux', None, 'kg m-2 s-1'),
'm01s05i207': CFName('air_pressure_at_convective_cloud_base', None, 'Pa'),
'm01s05i208': CFName('air_pressure_at_convective_cloud_top', None, 'Pa'),
'm01s05i209': CFName('air_temperature', None, 'K'),
'm01s05i212': CFName('convective_cloud_area_fraction_in_atmosphere_layer', None, 'unknown'),
'm01s05i213': CFName('mass_fraction_of_convective_cloud_liquid_water_in_air', None, '1'),
'm01s05i214': CFName('rainfall_flux', None, 'kg m-2 s-1'),
'm01s05i215': CFName('snowfall_flux', None, 'kg m-2 s-1'),
'm01s05i216': CFName('precipitation_flux', None, 'kg m-2 s-1'),
'm01s05i222': CFName('air_pressure_at_convective_cloud_base', None, 'Pa'),
'm01s05i226': CFName('precipitation_amount', None, 'kg m-2'),
'm01s05i227': CFName('convective_rainfall_flux', None, 'kg m-2 s-1'),
'm01s05i228': CFName('convective_snowfall_flux', None, 'kg m-2 s-1'),
'm01s05i231': CFName(None, 'Cape time scale (deep)', 's'),
'm01s05i232': CFName(None, 'reduced cape time scale indicator', '1'),
'm01s05i233': CFName('mass_fraction_of_convective_cloud_liquid_water_in_air', None, '1'),
'm01s05i269': CFName(None, 'deep convection indicator', '1'),
'm01s05i270': CFName(None, 'shallow convection indicator', '1'),
'm01s05i272': CFName(None, 'mid level convection indicator', '1'),
'm01s05i277': CFName(None, 'deep convective precipitation rate', 'kg/m^2/s'),
'm01s05i278': CFName(None, 'shallow convective precipitation rate', 'kg/m^2/s'),
'm01s05i279': CFName(None, 'mid level convective precipitation rate', 'kg/m^2/s'),
'm01s05i281': CFName(None, 'Dust wet deposition flux due to convective precipitation division 1', 'kg/m^2/s'),
'm01s05i282': CFName(None, 'Dust wet deposition flux due to convective precipitation division 2', 'kg/m^2/s'),
'm01s05i283': CFName(None, 'Dust wet deposition flux due to convective precipitation division 3', 'kg/m^2/s'),
'm01s05i284': CFName(None, 'Dust wet deposition flux due to convective precipitation division 4', 'kg/m^2/s'),
'm01s05i285': CFName(None, 'Dust wet deposition flux due to convective precipitation division 5', 'kg/m^2/s'),
'm01s05i286': CFName(None, 'Dust wet deposition flux due to convective precipitation division 6', 'kg/m^2/s'),
'm01s06i111': CFName('upward_eastward_momentum_flux_in_air_due_to_nonorographic_eastward_gravity_waves', None, 'Pa'),
'm01s06i113': CFName('upward_eastward_momentum_flux_in_air_due_to_nonorographic_westward_gravity_waves', None, 'Pa'),
'm01s06i115': CFName('tendency_of_eastward_wind_due_to_nonorographic_gravity_wave_drag', None, 'm s-2'),
'm01s06i185': CFName('tendency_of_eastward_wind_due_to_gravity_wave_drag', None, 'm s-2'),
'm01s06i186': CFName('tendency_of_northward_wind_due_to_gravity_wave_drag', None, 'm s-2'),
'm01s06i201': CFName('atmosphere_eastward_stress_due_to_gravity_wave_drag', None, 'Pa'),
'm01s06i202': CFName('atmosphere_northward_stress_due_to_gravity_wave_drag', None, 'Pa'),
'm01s06i241': CFName('upward_eastward_momentum_flux_in_air_due_to_orographic_gravity_waves', None, 'Pa'),
'm01s06i247': CFName('tendency_of_eastward_wind_due_to_orographic_gravity_wave_drag', None, 'm s-2'),
'm01s08i023': CFName('surface_snow_amount', None, 'kg m-2'),
'm01s08i202': CFName(None, 'surface_snow_melt_flux_where_land', 'kg m-2 s-1'),
'm01s08i204': CFName('surface_runoff_amount', None, 'kg m-2'),
'm01s08i205': CFName('subsurface_runoff_amount', None, 'kg m-2'),
'm01s08i208': CFName('soil_moisture_content', None, 'unknown'),
'm01s08i209': CFName('canopy_water_amount', None, 'unknown'),
'm01s08i223': CFName('moisture_content_of_soil_layer', None, 'kg m-2'),
'm01s08i225': CFName('soil_temperature', None, 'K'),
'm01s08i229': CFName('mass_fraction_of_unfrozen_water_in_soil_moisture', None, 'unknown'),
'm01s08i230': CFName('mass_fraction_of_frozen_water_in_soil_moisture', None, 'unknown'),
'm01s08i231': CFName(None, 'surface_snow_melt_flux_where_land', 'kg m-2 s-1'),
'm01s08i233': CFName('canopy_throughfall_flux', None, 'kg/m^2/s'),
'm01s08i234': CFName('surface_runoff_flux', None, 'kg m-2 s-1'),
'm01s08i235': CFName('subsurface_runoff_flux', None, 'kg m-2 s-1'),
'm01s08i245': CFName(None, 'Inland basin flow on atmospheric grid', 'kg/m^2/s'),
'm01s08i258': CFName('surface_runoff_flux', None, 'kg m-2 s-1'),
'm01s09i004': CFName('air_temperature', None, 'K'),
'm01s09i010': CFName('specific_humidity', None, '1'),
'm01s09i201': CFName('stratiform_cloud_area_fraction_in_atmosphere_layer', None, '1'),
'm01s09i203': CFName('low_type_cloud_area_fraction', None, '1'),
'm01s09i204': CFName('medium_type_cloud_area_fraction', None, '1'),
'm01s09i205': CFName('high_type_cloud_area_fraction', None, '1'),
'm01s09i208': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_0p1_oktas', 'kft'),
'm01s09i209': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_1p5_oktas', 'kft'),
'm01s09i210': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_2p5_oktas', 'kft'),
'm01s09i211': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_3p5_oktas', 'kft'),
'm01s09i212': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_4p5_oktas', 'kft'),
'm01s09i213': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_5p5_oktas', 'kft'),
'm01s09i214': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_6p5_oktas', 'kft'),
'm01s09i215': CFName(None, 'cloud_base_altitude_assuming_only_consider_cloud_area_fraction_greater_than_7p5_oktas', 'kft'),
'm01s09i216': CFName(None, 'cloud_area_fraction_assuming_random_overlap', '1'),
'm01s09i217': CFName(None, 'cloud_area_fraction_assuming_maximum_random_overlap', '1'),
'm01s09i218': CFName(None, 'cloud_area_fraction_assuming_only_consider_surface_to_1000_feet_asl', '1'),
'm01s09i219': CFName('cloud_base_altitude', None, 'ft'),
'm01s09i221': CFName(None, 'wet_bulb_freezing_level_altitude', 'm'),
'm01s09i222': CFName('wet_bulb_temperature', None, 'K'),
'm01s09i226': CFName(None, 'binary_mask_where_cloud_area_fraction_in_atmosphere_layer_gt_0', '1'),
'm01s09i228': CFName(None, 'relative_humidity_at_which_cloud_assumed_to_form', '1'),
'm01s09i229': CFName('relative_humidity', None, '1'),
'm01s09i230': CFName(None, 'visibility_in_atmosphere_layer', 'm'),
'm01s12i004': CFName('air_temperature', None, 'K'),
'm01s12i010': CFName('specific_humidity', None, '1'),
'm01s12i012': CFName('mass_fraction_of_cloud_ice_in_air', None, '1'),
'm01s12i181': CFName('tendency_of_air_temperature_due_to_advection', None, 'K s-1'),
'm01s12i182': CFName('tendency_of_specific_humidity_due_to_advection', None, 's-1'),
'm01s12i183': CFName('tendency_of_mass_fraction_of_cloud_liquid_water_in_air_due_to_advection', None, 's-1'),
'm01s12i184': CFName('tendency_of_mass_fraction_of_cloud_ice_in_air_due_to_advection', None, 's-1'),
'm01s12i185': CFName('tendency_of_eastward_wind_due_to_advection', None, 'm s-1'),
'm01s12i186': CFName('tendency_of_northward_wind_due_to_advection', None, 'm s-1'),
'm01s12i187': CFName(None, 'change_over_time_in_upward_air_velocity_due_to_advection', 'm s-1'),
'm01s12i201': CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'),
'm01s12i202': CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'),
'm01s13i002': CFName('eastward_wind', None, 'm s-1'),
'm01s13i003': CFName('northward_wind', None, 'm s-1'),
'm01s13i004': CFName('air_temperature', None, 'K'),
'm01s13i181': CFName('tendency_of_air_temperature_due_to_diffusion', None, 'K s-1'),
'm01s13i182': CFName('tendency_of_specific_humidity_due_to_diffusion', None, 's-1'),
'm01s13i185': CFName('tendency_of_eastward_wind_due_to_diffusion', None, 'm s-1'),
'm01s13i186': CFName('tendency_of_northward_wind_due_to_diffusion', None, 'm s-1'),
'm01s15i101': CFName('height_above_reference_ellipsoid', None, 'm'),
'm01s15i102': CFName('height_above_reference_ellipsoid', None, 'm'),
'm01s15i108': CFName('air_pressure', None, 'Pa'),
'm01s15i119': CFName('air_potential_temperature', None, 'K'),
'm01s15i127': CFName('air_density', None, 'kg m-3'),
'm01s15i142': CFName('upward_air_velocity', None, 'm s-1'),
'm01s15i143': CFName('x_wind', None, 'm s-1'),
'm01s15i144': CFName('y_wind', None, 'm s-1'),
'm01s15i201': CFName('x_wind', None, 'm s-1'),
'm01s15i202': CFName('y_wind', None, 'm s-1'),
'm01s15i214': CFName('ertel_potential_vorticity', None, 'K m2 kg-1 s-1'),
'm01s15i215': CFName('air_potential_temperature', None, 'K'),
'm01s15i216': CFName('air_potential_temperature', None, 'K'),
'm01s15i217': CFName('potential_vorticity_of_atmosphere_layer', None, 'Pa-1 s-1'),
'm01s15i218': CFName('potential_vorticity_of_atmosphere_layer', None, 'Pa-1 s-1'),
'm01s15i219': CFName('square_of_air_temperature', None, 'unknown'),
'm01s15i220': CFName('square_of_eastward_wind', None, 'unknown'),
'm01s15i221': CFName('square_of_northward_wind', None, 'unknown'),
'm01s15i222': CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'),
'm01s15i223': CFName('product_of_omega_and_air_temperature', None, 'unknown'),
'm01s15i224': CFName('product_of_eastward_wind_and_omega', None, 'unknown'),
'm01s15i225': CFName('product_of_northward_wind_and_omega', None, 'unknown'),
'm01s15i226': CFName('specific_humidity', None, 'unknown'),
'm01s15i227': CFName('product_of_eastward_wind_and_specific_humidity', None, 'unknown'),
'm01s15i228': CFName('product_of_northward_wind_and_specific_humidity', None, 'unknown'),
'm01s15i235': CFName('product_of_omega_and_specific_humidity', None, 'unknown'),
'm01s15i238': CFName('geopotential_height', None, 'unknown'),
'm01s15i239': CFName('product_of_eastward_wind_and_geopotential_height', None, 'unknown'),
'm01s15i240': CFName('product_of_northward_wind_and_geopotential_height', None, 'unknown'),
'm01s15i242': CFName('upward_air_velocity', None, 'm s-1'),
'm01s15i243': CFName('x_wind', None, 'm s-1'),
'm01s15i244': CFName('y_wind', None, 'm s-1'),
'm01s16i004': CFName('air_temperature', None, 'K'),
'm01s16i201': CFName('geopotential_height', None, 'm'),
'm01s16i202': CFName('geopotential_height', None, 'm'),
'm01s16i203': CFName('air_temperature', None, 'K'),
'm01s16i204': CFName('relative_humidity', None, '%'),
'm01s16i205': CFName(None, 'wet_bulb_potential_temperature', 'K'),
'm01s16i222': CFName('air_pressure_at_sea_level', None, 'Pa'),
'm01s16i224': CFName(None, 'square_of_height', 'm2'),
'm01s16i255': CFName('geopotential_height', None, 'm'),
'm01s16i256': CFName('relative_humidity', None, '%'),
'm01s17i220': CFName(None, 'mass_concentration_of_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i221': CFName(None, 'mass_concentration_of_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i222': CFName(None, 'mass_concentration_of_ammonium_sulfate_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i223': CFName(None, 'mass_concentration_of_ammonium_sulfate_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i224': CFName(None, 'mass_concentration_of_black_carbon_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i225': CFName(None, 'mass_concentration_of_black_carbon_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i226': CFName(None, 'mass_concentration_of_biomass_burning_aerosol_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i227': CFName(None, 'mass_concentration_of_biomass_burning_aerosol_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i228': CFName(None, 'mass_concentration_of_organic_carbon_from_fossil_fuel_combustion_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i229': CFName(None, 'mass_concentration_of_organic_carbon_from_fossil_fuel_combustion_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i230': CFName(None, 'mass_concentration_of_secondary_particulate_organic_matter_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i231': CFName(None, 'mass_concentration_of_secondary_particulate_organic_matter_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i232': CFName(None, 'mass_concentration_of_seasalt_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i233': CFName(None, 'mass_concentration_of_seasalt_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i234': CFName(None, 'mass_concentration_of_dust_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i235': CFName(None, 'mass_concentration_of_dust_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i236': CFName(None, 'mass_concentration_of_ammonium_nitrate_in_pm10_dry_aerosol_in_air', 'ug m-3'),
'm01s17i237': CFName(None, 'mass_concentration_of_ammonium_nitrate_in_pm2p5_dry_aerosol_in_air', 'ug m-3'),
'm01s17i257': CFName('mass_concentration_of_dust_dry_aerosol_in_air', None, 'ug m-3'),
'm01s19i002': CFName('vegetation_carbon_content', None, 'kg m-2'),
'm01s19i016': CFName('soil_carbon_content', None, 'kg m-2'),
'm01s20i003': CFName('wind_speed', None, 'm s-1'),
'm01s20i004': CFName('wind_speed', None, 'm s-1'),
'm01s20i005': CFName('divergence_of_wind', None, 's-1'),
'm01s20i006': CFName('atmosphere_relative_vorticity', None, 's-1'),
'm01s20i024': CFName('tropopause_air_pressure', None, 'Pa'),
'm01s20i025': CFName('tropopause_air_temperature', None, 'K'),
'm01s20i026': CFName('tropopause_altitude', None, 'm'),
'm01s20i034': CFName('air_pressure_at_freezing_level', None, 'Pa'),
'm01s20i064': CFName('tropopause_air_pressure', None, 'Pa'),
'm01s20i065': CFName('tropopause_air_temperature', None, 'K'),
'm01s20i066': CFName('tropopause_altitude', None, 'm'),
'm01s26i001': CFName(None, 'river water storage', 'kg'),
'm01s26i002': CFName(None, 'gridbox outflow', 'kg/s'),
'm01s26i003': CFName(None, 'gridbox inflow', 'kg/s'),
'm01s26i004': CFName('water_flux_into_sea_water_from_rivers', None, 'kg m-2 s-1'),
'm01s26i006': CFName(None, 'Inland basin flow on trip grid', 'kg/s'),
'm01s30i003': CFName('upward_air_velocity', None, 'm s-1'),
'm01s30i004': CFName('air_temperature', None, 'K'),
'm01s30i005': CFName('specific_humidity', None, '1'),
'm01s30i007': CFName('specific_kinetic_energy_of_air', None, 'm2 s-2'),
'm01s30i008': CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'),
'm01s30i111': CFName('air_temperature', None, 'K'),
'm01s30i113': CFName('relative_humidity', None, '%'),
'm01s30i181': CFName('tendency_of_air_temperature', None, 'K s-1'),
'm01s30i182': CFName('tendency_of_specific_humidity', None, 's-1'),
'm01s30i183': CFName('tendency_of_mass_fraction_of_cloud_liquid_water_in_air', None, 's-1'),
'm01s30i184': CFName('tendency_of_mass_fraction_of_cloud_ice_in_air', None, 's-1'),
'm01s30i185': CFName('tendency_of_eastward_wind', None, 'm s-1'),
'm01s30i186': CFName('tendency_of_northward_wind', None, 'm s-1'),
'm01s30i187': CFName('tendency_of_upward_air_velocity', None, 'm s-1'),
'm01s30i188': CFName('tendency_of_air_density', None, 'kg m-3 s-1'),
'm01s30i201': CFName('x_wind', None, 'm s-1'),
'm01s30i202': CFName('y_wind', None, 'm s-1'),
'm01s30i203': CFName('upward_air_velocity', None, 'm s-1'),
'm01s30i204': CFName('air_temperature', None, 'K'),
'm01s30i205': CFName('specific_humidity', None, '1'),
'm01s30i207': CFName('geopotential_height', None, 'm'),
'm01s30i208': CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'),
'm01s30i211': CFName('square_of_eastward_wind', None, 'm2 s-2'),
'm01s30i212': CFName('product_of_eastward_wind_and_northward_wind', None, 'm2 s-2'),
'm01s30i213': CFName('product_of_eastward_wind_and_upward_air_velocity', None, 'm2 s-2'),
'm01s30i214': CFName('product_of_eastward_wind_and_air_temperature', None, 'K m s-1'),
'm01s30i215': CFName('product_of_eastward_wind_and_specific_humidity', None, 'm s-1'),
'm01s30i217': CFName('product_of_eastward_wind_and_geopotential_height', None, 'm2 s-1'),
'm01s30i218': CFName('product_of_eastward_wind_and_omega', None, 'Pa m s-1'),
'm01s30i222': CFName('square_of_northward_wind', None, 'm2 s-2'),
'm01s30i223': CFName('product_of_northward_wind_and_upward_air_velocity', None, 'm2 s-2'),
'm01s30i224': CFName('product_of_northward_wind_and_air_temperature', None, 'K m s-1'),
'm01s30i225': CFName('product_of_northward_wind_and_specific_humidity', None, 'm s-1'),
'm01s30i227': CFName('product_of_northward_wind_and_geopotential_height', None, 'm2 s-1'),
'm01s30i228': CFName('product_of_northward_wind_and_omega', None, 'Pa m s-1'),
'm01s30i233': CFName('square_of_upward_air_velocity', None, 'm2 s-2'),
'm01s30i234': CFName('product_of_upward_air_velocity_and_air_temperature', None, 'K m s-1'),
'm01s30i235': CFName('product_of_upward_air_velocity_and_specific_humidity', None, 'm s-1'),
'm01s30i244': CFName('square_of_air_temperature', None, 'K2'),
'm01s30i245': CFName('product_of_air_temperature_and_specific_humidity', None, 'K'),
'm01s30i248': CFName('product_of_air_temperature_and_omega', None, 'K Pa s-1'),
'm01s30i258': CFName('product_of_specific_humidity_and_omega', None, 'Pa s-1'),
'm01s30i277': CFName('square_of_geopotential_height', None, 'm2'),
'm01s30i278': CFName('product_of_geopotential_height_and_omega', None, 'Pa m s-1'),
'm01s30i288': CFName('square_of_lagrangian_tendency_of_air_pressure', None, 'Pa2 s-2'),
'm01s30i301': CFName(None, 'Heavyside function on pressure levels', '1'),
'm01s30i302': CFName('virtual_temperature', None, 'K'),
'm01s30i310': CFName('northward_transformed_eulerian_mean_air_velocity', None, 'm s-1'),
'm01s30i311': CFName('northward_transformed_eulerian_mean_air_velocity', None, 'm s-1'),
'm01s30i312': CFName('northward_eliassen_palm_flux_in_air', None, 'kg s-2'),
'm01s30i313': CFName('upward_eliassen_palm_flux_in_air', None, 'kg s-2'),
'm01s30i314': CFName('tendency_of_eastward_wind_due_to_eliassen_palm_flux_divergence', None, 'm s-2'),
'm01s30i401': CFName('atmosphere_kinetic_energy_content', None, 'J m-2'),
'm01s30i404': CFName('atmosphere_mass_content_of_water', None, 'kg m-2'),
'm01s30i405': CFName('atmosphere_cloud_liquid_water_content', None, 'kg m-2'),
'm01s30i406': CFName('atmosphere_cloud_ice_content', None, 'kg m-2'),
'm01s30i417': CFName('surface_air_pressure', None, 'Pa'),
'm01s30i418': CFName('surface_air_pressure', None, 'Pa'),
'm01s30i451': CFName('tropopause_air_pressure', None, 'Pa'),
'm01s30i452': CFName('tropopause_air_temperature', None, 'K'),
'm01s30i453': CFName('tropopause_altitude', None, 'm'),
'm01s33i001': CFName('mole_fraction_of_ozone_in_air', None, 'mole mole-1'),
'm01s33i004': CFName(None, 'mole_fraction_of_nitrogen_trioxide_in_air', 'mole mole-1'),
'm01s33i005': CFName('mole_fraction_of_dinitrogen_pentoxide_in_air', None, 'mole mole-1'),
'm01s33i006': CFName('mole_fraction_of_peroxynitric_acid_in_air', None, 'mole mole-1'),
'm01s33i007': CFName('mole_fraction_of_chlorine_nitrate_in_air', None, 'mole mole-1'),
'm01s33i009': CFName('mole_fraction_of_methane_in_air', None, 'mole mole-1'),
'm01s33i041': CFName('mole_fraction_of_atomic_chlorine_in_air', None, '1'),
'm01s33i042': CFName('mole_fraction_of_chlorine_monoxide_in_air', None, '1'),
'm01s33i043': CFName('mole_fraction_of_dichlorine_peroxide_in_air', None, '1'),
'm01s33i044': CFName('mole_fraction_of_chlorine_dioxide_in_air', None, '1'),
'm01s33i047': CFName('mole_fraction_of_bromine_chloride_in_air', None, '1'),
'm01s33i048': CFName('mole_fraction_of_bromine_nitrate_in_air', None, '1'),
'm01s33i049': CFName('mole_fraction_of_nitrous_oxide_in_air', None, '1'),
'm01s33i051': CFName('mole_fraction_of_hypochlorous_acid_in_air', None, '1'),
'm01s33i054': CFName('mole_fraction_of_chlorine_nitrate_in_air', None, '1'),
'm01s33i055': CFName('mole_fraction_of_cfc11_in_air', None, '1'),
'm01s33i056': CFName('mole_fraction_of_cfc12_in_air', None, '1'),
'm01s33i058': CFName('mole_fraction_of_atomic_nitrogen_in_air', None, '1'),
'm01s33i150': CFName('age_of_stratospheric_air', None, '1'),
'm01s34i001': CFName('mass_fraction_of_ozone_in_air', None, 'kg kg-1'),
'm01s34i002': CFName('mass_fraction_of_nitrogen_monoxide_in_air', None, 'kg kg-1'),
'm01s34i003': CFName('mass_fraction_of_nitrate_radical_in_air', None, 'kg kg-1'),
'm01s34i004': CFName('mass_fraction_of_nitrogen_dioxide_in_air', None, 'kg kg-1'),
'm01s34i005': CFName('mass_fraction_of_dinitrogen_pentoxide_in_air', None, 'kg kg-1'),
'm01s34i006': CFName('mass_fraction_of_peroxynitric_acid_in_air', None, 'kg kg-1'),
'm01s34i007': CFName('mass_fraction_of_nitric_acid_in_air', None, 'kg kg-1'),
'm01s34i008': CFName('mass_fraction_of_hydrogen_peroxide_in_air', None, 'kg kg-1'),
'm01s34i009': CFName('mass_fraction_of_methane_in_air', None, 'kg kg-1'),
'm01s34i010': CFName('mass_fraction_of_carbon_monoxide_in_air', None, 'kg kg-1'),
'm01s34i011': CFName('mass_fraction_of_formaldehyde_in_air', None, 'kg kg-1'),
'm01s34i012': CFName('mass_fraction_of_methyl_hydroperoxide_in_air', None, 'kg kg-1'),
'm01s34i013': CFName('mass_fraction_of_nitrous_acid_in_air', None, 'kg kg-1'),
'm01s34i014': CFName('mass_fraction_of_ethane_in_air', None, 'kg kg-1'),
'm01s34i015': CFName(None, 'mass_fraction_of_ethyl_hydroperoxide_in_air', 'kg kg-1'),
'm01s34i016': CFName(None, 'mass_fraction_of_acetaldehyde_in_air', 'kg kg-1'),
'm01s34i017': CFName('mass_fraction_of_peroxyacetyl_nitrate_in_air', None, 'kg kg-1'),
'm01s34i018': CFName('mass_fraction_of_propane_in_air', None, 'kg kg-1'),
'm01s34i019': CFName(None, 'mass_fraction_of_n-propyl_hydroperoxide_in_air', 'kg kg-1'),
'm01s34i020': CFName(None, 'mass_fraction_of_i-propyl_hydroperoxide_in_air', 'kg kg-1'),
'm01s34i021': CFName(None, 'mass_fraction_of_propanal_in_air', 'kg kg-1'),
'm01s34i022': CFName(None, 'mass_fraction_of_acetone_in_air', 'kg kg-1'),
'm01s34i023': CFName(None, 'mass_fraction_of_acetonylhydroperoxide_in_air', 'kg kg-1'),
'm01s34i024': CFName(None, 'mass_fraction_of_peroxypropionyl_nitrate_in_air', 'kg kg-1'),
'm01s34i025': CFName(None, 'mass_fraction_of_methyl_nitrate_in_air', 'kg kg-1'),
'm01s34i026': CFName(None, 'mass_fraction_of_stratospheric_ozone_in_air', 'kg kg-1'),
'm01s34i027': CFName('mass_fraction_of_isoprene_in_air', None, 'kg kg-1'),
'm01s34i028': CFName(None, 'mass_fraction_of_isoprene_hydroperoxide_in_air', 'kg kg-1'),
'm01s34i030': CFName(None, 'mass_fraction_of_methacrolein_in_air', 'kg kg-1'),
'm01s34i031': CFName(None, 'mass_fraction_of_methacroyl_hydroperoxide_in_air', 'kg kg-1'),
'm01s34i032': CFName(None, 'mass_fraction_of_methacryloylperoxy_nitrate_in_air', 'kg kg-1'),
'm01s34i033': CFName(None, 'mass_fraction_of_hydroxyacetone_in_air', 'kg kg-1'),
'm01s34i034': CFName(None, 'mass_fraction_of_methlyglyoxal_in_air', 'kg kg-1'),
'm01s34i035': CFName(None, 'mass_fraction_of_second_generation_isoprene_nitrate_in_air', 'kg kg-1'),
'm01s34i036': CFName('mass_fraction_of_formic_acid_in_air', None, 'kg kg-1'),
'm01s34i037': CFName(None, 'mass_fraction_of_peracetic_acid_in_air', 'kg kg-1'),
'm01s34i038': CFName('mass_fraction_of_acetic_acid_in_air', None, 'kg kg-1'),
'm01s34i041': CFName('mass_fraction_of_atomic_chlorine_in_air', None, 'kg kg-1'),
'm01s34i042': CFName('mass_fraction_of_chlorine_monoxide_in_air', None, 'kg kg-1'),
'm01s34i043': CFName('mass_fraction_of_dichlorine_peroxide_in_air', None, 'kg kg-1'),
'm01s34i044': CFName('mass_fraction_of_chlorine_dioxide_in_air', None, 'kg kg-1'),
'm01s34i045': CFName('mass_fraction_of_atomic_bromine_in_air', None, 'kg kg-1'),
'm01s34i047': CFName('mass_fraction_of_bromine_chloride_in_air', None, 'kg kg-1'),
'm01s34i048': CFName('mass_fraction_of_bromine_nitrate_in_air', None, 'kg kg-1'),
'm01s34i049': CFName('mass_fraction_of_nitrous_oxide_in_air', None, 'kg kg-1'),
'm01s34i051': CFName('mass_fraction_of_hypochlorous_acid_in_air', None, 'kg kg-1'),
'm01s34i052': CFName('mass_fraction_of_hydrogen_bromide_in_air', None, 'kg kg-1'),
'm01s34i053': CFName('mole_fraction_of_hypobromous_acid_in_air', None, 'kg kg-1'),
'm01s34i054': CFName('mass_fraction_of_chlorine_nitrate_in_air', None, 'kg kg-1'),
'm01s34i055': CFName('mass_fraction_of_cfc11_in_air', None, 'kg kg-1'),
'm01s34i056': CFName('mass_fraction_of_cfc12_in_air', None, 'kg kg-1'),
'm01s34i057': CFName('mass_fraction_of_methyl_bromide_in_air', None, 'kg kg-1'),
'm01s34i058': CFName('mass_fraction_of_atomic_nitrogen_in_air', None, 'kg kg-1'),
'm01s34i059': CFName(None, 'mass_fraction_of_ground_state_atomic_oxygen_in_air', 'kg kg-1'),
'm01s34i070': CFName('mass_fraction_of_molecular_hydrogen_in_air', None, 'kg kg-1'),
'm01s34i071': CFName('mass_concentration_of_dimethyl_sulfide_in_air', None, 'kg kg-1'),
'm01s34i072': CFName('mass_concentration_of_sulfur_dioxide_in_air', None, 'kg kg-1'),
'm01s34i073': CFName('mass_fraction_of_sulfuric_acid_in_air', None, 'kg kg-1'),
'm01s34i074': CFName(None, 'mass_fraction_of_methanesulfonic_acid_in_air', 'kg kg-1'),
'm01s34i075': CFName(None, 'mass_fraction_of_dimethyl_sulfoxide', 'kg kg-1'),
'm01s34i076': CFName('mass_fraction_of_ammonia_in_air', None, 'kg kg-1'),
'm01s34i077': CFName(None, 'mass_fraction_of_carbon_disulfide_in_air', 'kg kg-1'),
'm01s34i078': CFName(None, 'mass_fraction_of_carbonyl_sulfide_in_air', 'kg kg-1'),
'm01s34i079': CFName(None, 'mass_fraction_of_hydrogen_sulfide_in_air', 'kg kg-1'),
'm01s34i080': CFName(None, 'mass_fraction_of_atomic_hydrogen_in_air', 'kg kg-1'),
'm01s34i081': CFName('mass_fraction_of_hydroxyl_radical_in_air', None, 'kg kg-1'),
'm01s34i082': CFName('mass_fraction_of_hydroperoxyl_radical_in_air', None, 'kg kg-1'),
'm01s34i083': CFName('mass_fraction_of_methyl_peroxy_radical_in_air', None, 'kg kg-1'),
'm01s34i084': CFName(None, 'mass_fraction_of_ethyl_peroxy_radical_in_air', 'kg kg-1'),
'm01s34i085': CFName(None, 'mass_fraction_of_peroxyacetyl_radical_in_air', 'kg kg-1'),
'm01s34i086': CFName(None, 'mass_fraction_of_n-propylperoxy_radical_in_air', 'kg kg-1'),
'm01s34i087': CFName(None, 'mass_fraction_of_isopropylperoxy_radical_in_air', 'kg kg-1'),
'm01s34i088': CFName(None, 'mass_fraction_of_peroxypropanoyl_radical_in_air', 'kg kg-1'),
'm01s34i089': CFName(None, 'mass_fraction_of_acetonyl_peroxy_radical_in_air', 'kg kg-1'),
'm01s34i093': CFName('mass_fraction_of_propene_in_air', None, 'kg kg-1'),
'm01s34i096': CFName(None, 'mass_fraction_of_methyl_ethyl_ketone_in_air', 'kg kg-1'),
'm01s34i097': CFName('mass_fraction_of_toluene_in_air', None, 'kg kg-1'),
'm01s34i100': CFName(None, 'mass_fraction_of_lumped_chlorine_expressed_as_hydrogen_chloride', 'kg kg-1'),
'm01s34i102': CFName(None, 'mass_fraction_of_sulfuric_acid_in_soluble_nucleation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i104': CFName(None, 'mass_fraction_of_sulfuric_acid_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i105': CFName(None, 'mass_fraction_of_black_carbon_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i106': CFName(None, 'mass_fraction_of_particulate_organic_matter_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i108': CFName(None, 'mass_fraction_of_sulfuric_acid_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i109': CFName(None, 'mass_fraction_of_black_carbon_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i110': CFName(None, 'mass_fraction_of_particulate_organic_matter_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i111': CFName(None, 'mass_fraction_of_seasalt_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i112': CFName(None, 'mass_fraction_of_dust_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i114': CFName(None, 'mass_fraction_of_sulfuric_acid_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i115': CFName(None, 'mass_fraction_of_black_carbon_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i116': CFName(None, 'mass_fraction_of_particulate_organic_matter_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i117': CFName(None, 'mass_fraction_of_seasalt_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i118': CFName(None, 'mass_fraction_of_dust_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i120': CFName(None, 'mass_fraction_of_black_carbon_in_insoluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i121': CFName(None, 'mass_fraction_of_particulate_organic_matter_in_insoluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i123': CFName(None, 'mass_fraction_of_dust_in_insoluble_accumulation_mode_aerosol_in_air', 'kg kg-1'),
'm01s34i125': CFName(None, 'mass_fraction_of_dust_in_insoluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i126': CFName(None, 'mass_fraction_of_particulate_organic_matter_in_soluble_nucleation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i127': CFName(None, 'mass_fraction_of_seasalt_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i128': CFName(None, 'mass_fraction_of_secondary_particulate_organic_matter_in_soluble_nucleation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i129': CFName(None, 'mass_fraction_of_secondary_particulate_organic_matter_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i130': CFName(None, 'mass_fraction_of_secondary_particulate_organic_matter_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i131': CFName(None, 'mass_fraction_of_secondary_particulate_organic_matter_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i132': CFName(None, 'mass_fraction_of_ammonium_in_soluble_nucleation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i133': CFName(None, 'mass_fraction_of_ammonium_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i134': CFName(None, 'mass_fraction_of_ammonium_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i135': CFName(None, 'mass_fraction_of_ammonium_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i136': CFName(None, 'mass_fraction_of_nitrate_in_soluble_nucleation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i137': CFName(None, 'mass_fraction_of_nitrate_in_soluble_aitken_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i138': CFName(None, 'mass_fraction_of_nitrate_in_soluble_accumulation_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i139': CFName(None, 'mass_fraction_of_nitrate_in_soluble_coarse_mode_dry_aerosol_in_air', 'kg kg-1'),
'm01s34i150': CFName('age_of_stratospheric_air', None, 's'),
'm01s34i159': CFName('equivalent_thickness_at_stp_of_atmosphere_ozone_content', None, 'DU'),
'm02s00i101': CFName('sea_water_potential_temperature', None, 'degC'),
'm02s00i102': CFName('sea_water_salinity', None, '1e3 @0.035'),
'm02s00i121': CFName('baroclinic_eastward_sea_water_velocity', None, 'cm s-1'),
'm02s00i122': CFName('baroclinic_northward_sea_water_velocity', None, 'cm s-1'),
'm02s00i130': CFName('ocean_barotropic_streamfunction', None, 'cm3 s-1'),
'm02s00i131': CFName('ocean_barotropic_streamfunction', None, 'cm3 s-1'),
'm02s00i132': CFName('tendency_of_ocean_barotropic_streamfunction', None, 'cm3 s-2'),
'm02s00i133': CFName('tendency_of_ocean_barotropic_streamfunction', None, 'cm3 s-2'),
'm02s00i134': CFName('surface_air_pressure', None, 'g cm-1 s-2'),
'm02s00i135': CFName('barotropic_eastward_sea_water_velocity', None, 'cm s-1'),
'm02s00i136': CFName('barotropic_northward_sea_water_velocity', None, 'cm s-1'),
'm02s00i137': CFName('ocean_mixed_layer_thickness', None, 'm'),
'm02s00i139': CFName('downward_eastward_stress_at_sea_ice_base', None, 'Pa'),
'm02s00i140': CFName('downward_northward_stress_at_sea_ice_base', None, 'Pa'),
'm02s00i141': CFName('surface_snow_thickness', None, 'm'),
'm02s00i143': CFName('upward_sea_ice_basal_heat_flux', None, 'W m-2'),
'm02s00i146': CFName('sea_ice_area_fraction', None, '1'),
'm02s00i147': CFName('sea_ice_thickness', None, 'm'),
'm02s00i148': CFName('eastward_sea_ice_velocity', None, 'm s-1'),
'm02s00i149': CFName('northward_sea_ice_velocity', None, 'm s-1'),
'm02s00i150': CFName('surface_downward_eastward_stress', None, 'Pa'),
'm02s00i151': CFName('surface_downward_northward_stress', None, 'Pa'),
'm02s00i152': CFName('wind_mixing_energy_flux_into_sea_water', None, 'W m-2'),
'm02s00i166': CFName('water_flux_into_sea_water_from_rivers', None, 'kg m-2 s-1'),
'm02s00i171': CFName('snowfall_flux', None, 'kg m-2 s-1'),
'm02s00i172': CFName('surface_snow_and_ice_sublimation_flux', None, 'kg m-2 s-1'),
'm02s00i180': CFName('sea_surface_temperature', None, 'K'),
'm02s00i181': CFName('sea_surface_salinity', None, '1e3 @0.035'),
'm02s00i182': CFName('air_temperature', None, 'K'),
'm02s00i183': CFName('sea_ice_thickness', None, 'm'),
'm02s00i185': CFName('heat_flux_correction', None, 'W m-2'),
'm02s00i186': CFName('water_flux_correction', None, 'kg m-2 s-1'),
'm02s00i190': CFName('surface_snow_and_ice_melt_heat_flux', None, 'W m-2'),
'm02s00i191': CFName('downward_heat_flux_in_sea_ice', None, 'W m-2'),
'm02s00i192': CFName('water_flux_into_sea_water_due_to_sea_ice_thermodynamics', None, 'kg m-2 s-1'),
'm02s30i201': CFName('upward_sea_water_velocity', None, 'cm s-1'),
'm02s30i202': CFName('ocean_mixed_layer_thickness', None, 'm'),
'm02s30i211': CFName('northward_ocean_heat_transport', None, 'PW'),
'm02s30i212': CFName('northward_ocean_salt_transport', None, '1e7kg s-1'),
'm02s30i320': CFName('eastward_sea_water_velocity', None, 'cm s-1'),
'm02s30i321': CFName('northward_sea_water_velocity', None, 'cm s-1'),
'm02s30i324': CFName('ocean_mixed_layer_thickness', None, 'm'),
'm02s30i406': CFName(None, 'mole_concentration_of_dimethyl_sulphide_in_seawater', 'mol m-3'),
'm02s32i201': CFName('tendency_of_sea_ice_area_fraction_due_to_dynamics', None, 's-1'),
'm02s32i202': CFName('tendency_of_sea_ice_thickness_due_to_dynamics', None, 'm s-1'),
'm02s32i209': CFName('eastward_sea_ice_velocity', None, 'm s-1'),
'm02s32i210': CFName('northward_sea_ice_velocity', None, 'm s-1'),
'm02s32i211': CFName('tendency_of_sea_ice_area_fraction_due_to_thermodynamics', None, 's-1'),
'm02s32i212': CFName('tendency_of_sea_ice_thickness_due_to_thermodynamics', None, 'm s-1'),
'm02s32i215': CFName('snowfall_flux', None, 'kg m-2 s-1'),
'm02s32i219': CFName('downward_eastward_stress_at_sea_ice_base', None, 'Pa'),
'm02s32i220': CFName('downward_northward_stress_at_sea_ice_base', None, 'Pa'),
'm03s00i177': CFName(None, 'prescribed_heat_flux_into_slab_ocean', 'W m-2'),
'm04s06i001': CFName('sea_surface_wind_wave_significant_height', None, 'm'),
}
STASHCODE_IMPLIED_HEIGHTS = {
'm01s03i209': (10.0,),
'm01s03i210': (10.0,),
'm01s03i225': (10.0,),
'm01s03i226': (10.0,),
'm01s03i227': (10.0,),
'm01s03i236': (1.5,),
'm01s03i237': (1.5,),
'm01s03i245': (1.5,),
'm01s03i247': (1.5,),
'm01s03i250': (1.5,),
'm01s03i281': (1.5,),
'm01s03i463': (10.0,),
}
CF_TO_LBFC = {
CFName(None, 'stratiform_snowfall_rate', 'kg m-2 s-1'): 118,
CFName('age_of_stratospheric_air', None, '1'): 501,
CFName('air_density', None, 'kg m-3'): 27,
CFName('air_potential_temperature', None, 'K'): 19,
CFName('air_pressure', None, 'Pa'): 8,
CFName('air_pressure_at_freezing_level', None, 'Pa'): 8,
CFName('air_pressure_at_sea_level', None, 'Pa'): 8,
CFName('air_temperature', None, 'K'): 16,
CFName('atmosphere_boundary_layer_thickness', None, 'm'): 5,
CFName('atmosphere_eastward_stress_due_to_gravity_wave_drag', None, 'Pa'): 61,
CFName('atmosphere_kinetic_energy_content', None, 'J m-2'): 63,
CFName('atmosphere_northward_stress_due_to_gravity_wave_drag', None, 'Pa'): 62,
CFName('atmosphere_relative_vorticity', None, 's-1'): 73,
CFName('cloud_area_fraction', None, '1'): 30,
CFName('cloud_area_fraction_in_atmosphere_layer', None, '1'): 1720,
CFName('convective_cloud_area_fraction', None, '1'): 34,
CFName('convective_rainfall_amount', None, 'kg m-2'): 94,
CFName('convective_snowfall_amount', None, 'kg m-2'): 117,
CFName('dimensionless_exner_function', None, '1'): 7,
CFName('divergence_of_wind', None, 's-1'): 74,
CFName('downward_heat_flux_in_sea_ice', None, 'W m-2'): 261,
CFName('downward_heat_flux_in_soil', None, 'W m-2'): 1564,
CFName('eastward_wind', None, 'm s-1'): 56,
CFName('ertel_potential_vorticity', None, 'K m2 kg-1 s-1'): 82,
CFName('geopotential_height', None, 'm'): 1,
CFName('lagrangian_tendency_of_air_pressure', None, 'Pa s-1'): 40,
CFName('land_binary_mask', None, '1'): 395,
CFName('large_scale_rainfall_rate', None, 'm s-1'): 99,
CFName('mass_fraction_of_carbon_dioxide_in_air', None, '1'): 1564,
CFName('mass_fraction_of_cloud_liquid_water_in_air', None, '1'): 79,
CFName('mass_fraction_of_dimethyl_sulfide_in_air', None, '1'): 1373,
CFName('mass_fraction_of_frozen_water_in_soil_moisture', None, '1'): 1386,
CFName('mass_fraction_of_ozone_in_air', None, '1'): 453,
CFName('mass_fraction_of_sulfur_dioxide_in_air', None, '1'): 1374,
CFName('mass_fraction_of_unfrozen_water_in_soil_moisture', None, '1'): 1385,
CFName('moisture_content_of_soil_layer', None, 'kg m-2'): 122,
CFName('mole_fraction_of_atomic_chlorine_in_air', None, '1'): 501,
CFName('mole_fraction_of_atomic_nitrogen_in_air', None, '1'): 501,
CFName('mole_fraction_of_bromine_chloride_in_air', None, '1'): 501,
CFName('mole_fraction_of_bromine_nitrate_in_air', None, '1'): 501,
CFName('mole_fraction_of_cfc11_in_air', None, '1'): 501,
CFName('mole_fraction_of_cfc12_in_air', None, '1'): 501,
CFName('mole_fraction_of_chlorine_dioxide_in_air', None, '1'): 501,
CFName('mole_fraction_of_chlorine_monoxide_in_air', None, '1'): 501,
CFName('mole_fraction_of_chlorine_nitrate_in_air', None, '1'): 501,
CFName('mole_fraction_of_dichlorine_peroxide_in_air', None, '1'): 501,
CFName('mole_fraction_of_hypochlorous_acid_in_air', None, '1'): 501,
CFName('mole_fraction_of_nitrous_oxide_in_air', None, '1'): 501,
CFName('northward_wind', None, 'm s-1'): 57,
CFName('rainfall_flux', None, 'kg m-2 s-1'): 97,
CFName('relative_humidity', None, '%'): 88,
CFName('root_depth', None, 'm'): 321,
CFName('sea_ice_albedo', None, '1'): 322,
CFName('sea_ice_area_fraction', None, '1'): 37,
CFName('sea_ice_temperature', None, 'K'): 209,
CFName('sea_ice_thickness', None, 'm'): 687,
CFName('sea_surface_elevation', None, 'm'): 608,
CFName('snow_grain_size', None, '1e-6 m'): 1507,
CFName('snowfall_amount', None, 'kg m-2'): 93,
CFName('snowfall_flux', None, 'kg m-2 s-1'): 108,
CFName('soil_albedo', None, '1'): 1395,
CFName('soil_carbon_content', None, 'kg m-2'): 1397,
CFName('soil_hydraulic_conductivity_at_saturation', None, 'm s-1'): 333,
CFName('soil_moisture_content_at_field_capacity', None, 'kg m-2'): 1559,
CFName('soil_porosity', None, '1'): 332,
CFName('soil_suction_at_saturation', None, 'Pa'): 342,
CFName('soil_temperature', None, 'K'): 23,
CFName('soil_thermal_capacity', None, 'J kg-1 K-1'): 335,
CFName('soil_thermal_conductivity', None, 'W m-1 K-1'): 336,
CFName('specific_kinetic_energy_of_air', None, 'm2 s-2'): 60,
CFName('stratiform_cloud_area_fraction_in_atmosphere_layer', None, '1'): 220,
CFName('stratiform_rainfall_amount', None, 'kg m-2'): 102,
CFName('stratiform_rainfall_rate', None, 'kg m-2 s-1'): 99,
CFName('stratiform_snowfall_amount', None, 'kg m-2'): 116,
CFName('subsurface_runoff_amount', None, 'kg m-2'): 112,
CFName('subsurface_runoff_flux', None, 'kg m-2 s-1'): 1533,
CFName('surface_albedo_assuming_deep_snow', None, '1'): 328,
CFName('surface_albedo_assuming_no_snow', None, '1'): 322,
CFName('surface_altitude', None, 'm'): 1,
CFName('surface_downwelling_shortwave_flux_in_air', None, 'W m-2'): 203,
CFName('surface_downwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'): 208,
CFName('surface_eastward_sea_water_velocity', None, 'm s-1'): 701,
CFName('surface_net_downward_longwave_flux', None, 'W m-2'): 187,
CFName('surface_net_downward_shortwave_flux', None, 'W m-2'): 186,
CFName('surface_northward_sea_water_velocity', None, 'm s-1'): 702,
CFName('surface_roughness_length', None, 'm'): 324,
CFName('surface_runoff_amount', None, 'kg m-2'): 111,
CFName('surface_runoff_flux', None, 'kg m-2 s-1'): 1532,
CFName('surface_snow_amount', None, 'kg m-2'): 93,
CFName('surface_temperature', None, 'K'): 16,
CFName('surface_upward_sensible_heat_flux', None, 'W m-2'): 178,
CFName('surface_upward_water_flux', None, 'kg m-2 s-1'): 184,
CFName('surface_upwelling_shortwave_flux_in_air_assuming_clear_sky', None, 'W m-2'): 207,
CFName('tendency_of_air_density', None, 'kg m-3 s-1'): 7,
CFName('tendency_of_air_temperature', None, 'K s-1'): 16,
CFName('tendency_of_air_temperature_due_to_diffusion', None, 'K s-1'): 16,
CFName('tendency_of_air_temperature_due_to_longwave_heating', None, 'K s-1'): 253,
CFName('tendency_of_eastward_wind', None, 'm s-1'): 56,
CFName('tendency_of_eastward_wind_due_to_diffusion', None, 'm s-1'): 56,
CFName('tendency_of_mass_fraction_of_cloud_ice_in_air', None, 's-1'): 78,
CFName('tendency_of_mass_fraction_of_cloud_liquid_water_in_air', None, 's-1'): 79,
CFName('tendency_of_northward_wind', None, 'm s-1'): 57,
CFName('tendency_of_northward_wind_due_to_diffusion', None, 'm s-1'): 57,
CFName('tendency_of_specific_humidity', None, 's-1'): 95,
CFName('tendency_of_specific_humidity_due_to_diffusion', None, 's-1'): 95,
CFName('tendency_of_upward_air_velocity', None, 'm s-1'): 42,
CFName('toa_incoming_shortwave_flux', None, 'W m-2'): 200,
CFName('toa_outgoing_longwave_flux', None, 'W m-2'): 206,
CFName('toa_outgoing_longwave_flux_assuming_clear_sky', None, 'W m-2'): 210,
CFName('toa_outgoing_shortwave_flux', None, 'W m-2'): 201,
CFName('toa_outgoing_shortwave_flux_assuming_clear_sky', None, 'W m-2'): 207,
CFName('tropopause_air_pressure', None, 'Pa'): 8,
CFName('tropopause_air_temperature', None, 'K'): 16,
CFName('tropopause_altitude', None, 'm'): 1,
CFName('upward_air_velocity', None, 'm s-1'): 42,
CFName('vegetation_area_fraction', None, '1'): 326,
CFName('virtual_temperature', None, 'K'): 16,
CFName('volume_fraction_of_condensed_water_in_soil_at_critical_point', None, '1'): 330,
CFName('volume_fraction_of_condensed_water_in_soil_at_wilting_point', None, '1'): 329,
CFName('water_potential_evaporation_flux', None, 'kg m-2 s-1'): 115,
CFName('wind_mixing_energy_flux_into_sea_water', None, 'W m-2'): 182,
CFName('wind_speed', None, 'm s-1'): 50,
CFName('x_wind', None, 'm s-1'): 56,
CFName('y_wind', None, 'm s-1'): 57,
}
|
lgpl-3.0
|
[
3,
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
6171,
446,
7800,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
3506,
2845,
24981,
26,
25420,
13,
12795,
6989,
199,
3,
18208,
641,
3144,
21141,
26709,
7800,
5557,
26,
996,
687,
221,
199,
3,
1455,
921,
1544,
14,
2024,
17322,
14,
846,
15,
10207,
47,
20867,
199,
3,
737,
5532,
3980,
25230,
70,
2470,
1349,
65,
2760,
70,
2470,
21,
70,
13549,
70,
1079,
2835,
2177,
24035,
2470,
10740,
1138,
556,
199,
199,
3,
4178,
921,
5031,
14,
957,
15,
2024,
17322,
15,
10207,
47,
20867,
15,
3543,
15,
2177,
25230,
70,
2470,
1349,
65,
2760,
70,
2470,
21,
70,
13549,
70,
1079,
2835,
2177,
24035,
2470,
10740,
1138,
556,
199,
199,
624,
199,
17473,
738,
45,
15,
5487,
3945,
287,
1377,
2865,
15547,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
199,
504,
5055,
492,
12863,
421,
199,
5487,
985,
275,
12863,
360,
5487,
985,
297,
283,
6807,
63,
354,
1846,
63,
354,
6204,
358,
421,
199,
11568,
4161,
63,
2566,
63,
5487,
275,
469,
272,
959,
26,
24609,
360,
292,
573,
14980,
63,
9891,
63,
1897,
63,
26199,
297,
488,
12,
283,
77,
659,
272,
3193,
26,
24609,
360,
8387,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
6546,
26,
24609,
360,
1152,
382,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
8087,
26,
24609,
360,
8387,
63,
15669,
297,
488,
12,
283,
9761,
333,
13,
19,
659,
272,
8780,
26,
24609,
360,
9688,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
6877,
26,
24609,
360,
27590,
63,
1885,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
5238,
26,
24609,
360,
11530,
63,
7625,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
12001,
26,
24609,
360,
88,
63,
11530,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
12699,
26,
24609,
360,
89,
63,
11530,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
18525,
26,
24609,
360,
292,
573,
14980,
63,
6188,
63,
14419,
280,
3690,
297,
488,
12,
283,
83,
13,
17,
659,
272,
9720,
26,
24609,
360,
32049,
63,
1618,
63,
11530,
297,
488,
12,
283,
83,
13,
17,
659,
272,
20582,
26,
24609,
360,
24668,
63,
14419,
280,
3690,
63,
1618,
63,
292,
573,
14980,
63,
1897,
297,
488,
12,
283,
4232,
13,
17,
308,
13,
17,
659,
272,
18729,
26,
24609,
360,
388,
6046,
857,
63,
345,
4904,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
15997,
26,
24609,
360,
345,
4904,
452,
63,
14477,
297,
488,
12,
283,
9761,
333,
13,
18,
308,
13,
17,
659,
272,
12996,
26,
24609,
360,
14183,
280,
964,
63,
345,
4904,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
24579,
26,
24609,
360,
27765,
70,
452,
63,
14477,
297,
488,
12,
283,
9761,
333,
13,
18,
308,
13,
17,
659,
272,
20128,
26,
24609,
360,
10992,
63,
1065,
1997,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
25186,
26,
24609,
360,
14183,
280,
964,
63,
27765,
70,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
26189,
26,
24609,
360,
388,
6046,
857,
63,
27765,
70,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
24557,
26,
24609,
360,
573,
631,
608,
63,
1317,
63,
1618,
63,
1152,
382,
63,
1897,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
413,
2658,
26,
24609,
360,
11530,
63,
7625,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
1926,
26,
24609,
360,
475,
65,
63,
15994,
63,
3612,
10024,
63,
14477,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
29202,
26,
24609,
360,
10992,
63,
2110,
20501,
316,
63,
3612,
10024,
63,
14477,
63,
262,
63,
8387,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
26761,
26,
24609,
360,
475,
65,
63,
19388,
63,
2809,
10024,
63,
14477,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
29203,
26,
24609,
360,
10992,
63,
2110,
20501,
316,
63,
3612,
10024,
63,
14477,
63,
262,
63,
8387,
63,
405,
12848,
63,
3584,
63,
12267,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
499,
1643,
26,
24609,
360,
27590,
63,
1885,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
26727,
26,
24609,
360,
724,
848,
1480,
63,
1618,
63,
8387,
63,
12954,
63,
11933,
63,
475,
63,
2809,
10024,
63,
426,
1958,
297,
488,
12,
283,
43,
308,
13,
17,
659,
272,
499,
2976,
26,
24609,
360,
2110,
3079,
63,
16614,
63,
14477,
63,
262,
63,
27590,
63,
1885,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
650,
2025,
26,
24609,
360,
1231,
63,
4631,
297,
488,
12,
283,
77,
659,
272,
650,
1479,
26,
24609,
360,
432,
362,
425,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
650,
1651,
26,
24609,
360
] |
[
334,
35,
9,
699,
322,
23184,
445,
18406,
1898,
6171,
446,
7800,
12,
10072,
593,
11286,
301,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
473,
5719,
14,
199,
3,
199,
3,
473,
5719,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
465,
3267,
701,
314,
199,
3,
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,
473,
5719,
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,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
199,
3,
3180,
543,
473,
5719,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
3506,
2845,
24981,
26,
25420,
13,
12795,
6989,
199,
3,
18208,
641,
3144,
21141,
26709,
7800,
5557,
26,
996,
687,
221,
199,
3,
1455,
921,
1544,
14,
2024,
17322,
14,
846,
15,
10207,
47,
20867,
199,
3,
737,
5532,
3980,
25230,
70,
2470,
1349,
65,
2760,
70,
2470,
21,
70,
13549,
70,
1079,
2835,
2177,
24035,
2470,
10740,
1138,
556,
199,
199,
3,
4178,
921,
5031,
14,
957,
15,
2024,
17322,
15,
10207,
47,
20867,
15,
3543,
15,
2177,
25230,
70,
2470,
1349,
65,
2760,
70,
2470,
21,
70,
13549,
70,
1079,
2835,
2177,
24035,
2470,
10740,
1138,
556,
199,
199,
624,
199,
17473,
738,
45,
15,
5487,
3945,
287,
1377,
2865,
15547,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
504,
3816,
14,
4912,
492,
334,
1541,
12,
1324,
12,
2341,
12,
1425,
12,
3482,
9,
221,
327,
8151,
199,
199,
504,
5055,
492,
12863,
421,
199,
5487,
985,
275,
12863,
360,
5487,
985,
297,
283,
6807,
63,
354,
1846,
63,
354,
6204,
358,
421,
199,
11568,
4161,
63,
2566,
63,
5487,
275,
469,
272,
959,
26,
24609,
360,
292,
573,
14980,
63,
9891,
63,
1897,
63,
26199,
297,
488,
12,
283,
77,
659,
272,
3193,
26,
24609,
360,
8387,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
6546,
26,
24609,
360,
1152,
382,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
8087,
26,
24609,
360,
8387,
63,
15669,
297,
488,
12,
283,
9761,
333,
13,
19,
659,
272,
8780,
26,
24609,
360,
9688,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
6877,
26,
24609,
360,
27590,
63,
1885,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
5238,
26,
24609,
360,
11530,
63,
7625,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
12001,
26,
24609,
360,
88,
63,
11530,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
12699,
26,
24609,
360,
89,
63,
11530,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
18525,
26,
24609,
360,
292,
573,
14980,
63,
6188,
63,
14419,
280,
3690,
297,
488,
12,
283,
83,
13,
17,
659,
272,
9720,
26,
24609,
360,
32049,
63,
1618,
63,
11530,
297,
488,
12,
283,
83,
13,
17,
659,
272,
20582,
26,
24609,
360,
24668,
63,
14419,
280,
3690,
63,
1618,
63,
292,
573,
14980,
63,
1897,
297,
488,
12,
283,
4232,
13,
17,
308,
13,
17,
659,
272,
18729,
26,
24609,
360,
388,
6046,
857,
63,
345,
4904,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
15997,
26,
24609,
360,
345,
4904,
452,
63,
14477,
297,
488,
12,
283,
9761,
333,
13,
18,
308,
13,
17,
659,
272,
12996,
26,
24609,
360,
14183,
280,
964,
63,
345,
4904,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
24579,
26,
24609,
360,
27765,
70,
452,
63,
14477,
297,
488,
12,
283,
9761,
333,
13,
18,
308,
13,
17,
659,
272,
20128,
26,
24609,
360,
10992,
63,
1065,
1997,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
25186,
26,
24609,
360,
14183,
280,
964,
63,
27765,
70,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
26189,
26,
24609,
360,
388,
6046,
857,
63,
27765,
70,
452,
63,
4606,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
24557,
26,
24609,
360,
573,
631,
608,
63,
1317,
63,
1618,
63,
1152,
382,
63,
1897,
297,
488,
12,
283,
9761,
333,
13,
18,
659,
272,
413,
2658,
26,
24609,
360,
11530,
63,
7625,
297,
488,
12,
283,
77,
308,
13,
17,
659,
272,
1926,
26,
24609,
360,
475,
65,
63,
15994,
63,
3612,
10024,
63,
14477,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
29202,
26,
24609,
360,
10992,
63,
2110,
20501,
316,
63,
3612,
10024,
63,
14477,
63,
262,
63,
8387,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
26761,
26,
24609,
360,
475,
65,
63,
19388,
63,
2809,
10024,
63,
14477,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
29203,
26,
24609,
360,
10992,
63,
2110,
20501,
316,
63,
3612,
10024,
63,
14477,
63,
262,
63,
8387,
63,
405,
12848,
63,
3584,
63,
12267,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
499,
1643,
26,
24609,
360,
27590,
63,
1885,
63,
12954,
297,
488,
12,
283,
43,
659,
272,
26727,
26,
24609,
360,
724,
848,
1480,
63,
1618,
63,
8387,
63,
12954,
63,
11933,
63,
475,
63,
2809,
10024,
63,
426,
1958,
297,
488,
12,
283,
43,
308,
13,
17,
659,
272,
499,
2976,
26,
24609,
360,
2110,
3079,
63,
16614,
63,
14477,
63,
262,
63,
27590,
63,
1885,
297,
488,
12,
283,
55,
333,
13,
18,
659,
272,
650,
2025,
26,
24609,
360,
1231,
63,
4631,
297,
488,
12,
283,
77,
659,
272,
650,
1479,
26,
24609,
360,
432,
362,
425,
63,
6789,
63,
13054,
297,
488,
12,
283,
17,
659,
272,
650,
1651,
26,
24609,
360,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
diegodelemos/reana-job-controller
|
tests/test_job_manager.py
|
1
|
4870
|
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2019 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""REANA-Job-Controller Job Manager tests."""
import json
import os
import uuid
import mock
import pytest
from reana_db.models import Job, JobStatus
from reana_job_controller.job_manager import JobManager
from reana_job_controller.kubernetes_job_manager import KubernetesJobManager
def test_execute_kubernetes_job(
app,
session,
sample_serial_workflow_in_db,
sample_workflow_workspace,
default_user,
empty_user_secrets,
corev1_api_client_with_user_secrets,
monkeypatch,
):
"""Test execution of Kubernetes job."""
workflow_uuid = sample_serial_workflow_in_db.id_
workflow_workspace = next(sample_workflow_workspace(str(workflow_uuid)))
env_var_key = "key"
env_var_value = "value"
expected_env_var = {env_var_key: env_var_value}
expected_image = "busybox"
expected_command = ["ls"]
monkeypatch.setenv("REANA_USER_ID", str(default_user.id_))
job_manager = KubernetesJobManager(
docker_img=expected_image,
cmd=expected_command,
env_vars=expected_env_var,
workflow_uuid=workflow_uuid,
workflow_workspace=workflow_workspace,
)
with mock.patch(
"reana_job_controller.kubernetes_job_manager." "current_k8s_batchv1_api_client"
) as kubernetes_client:
with mock.patch(
"reana_commons.k8s.secrets." "current_k8s_corev1_api_client",
corev1_api_client_with_user_secrets(empty_user_secrets),
):
kubernetes_job_id = job_manager.execute()
created_job = (
session.query(Job)
.filter_by(backend_job_id=kubernetes_job_id)
.one_or_none()
)
assert created_job
assert created_job.docker_img == expected_image
assert created_job.cmd == json.dumps(expected_command)
assert json.dumps(expected_env_var) in created_job.env_vars
assert created_job.status == JobStatus.created
kubernetes_client.create_namespaced_job.assert_called_once()
body = kubernetes_client.create_namespaced_job.call_args[1]["body"]
env_vars = body["spec"]["template"]["spec"]["containers"][0]["env"]
image = body["spec"]["template"]["spec"]["containers"][0]["image"]
command = body["spec"]["template"]["spec"]["containers"][0]["command"]
assert len(env_vars) == 3
assert {"name": env_var_key, "value": env_var_value} in env_vars
assert image == expected_image
assert command == expected_command
def test_stop_kubernetes_job(
app,
session,
sample_serial_workflow_in_db,
sample_workflow_workspace,
empty_user_secrets,
default_user,
corev1_api_client_with_user_secrets,
monkeypatch,
):
"""Test stop of Kubernetes job."""
workflow_uuid = sample_serial_workflow_in_db.id_
workflow_workspace = next(sample_workflow_workspace(str(workflow_uuid)))
expected_env_var_name = "env_var"
expected_env_var_value = "value"
expected_image = "busybox"
expected_command = ["ls"]
monkeypatch.setenv("REANA_USER_ID", str(default_user.id_))
job_manager = KubernetesJobManager(
docker_img=expected_image,
cmd=expected_command,
env_vars={expected_env_var_name: expected_env_var_value},
workflow_uuid=workflow_uuid,
workflow_workspace=workflow_workspace,
)
with mock.patch(
"reana_job_controller.kubernetes_job_manager." "current_k8s_batchv1_api_client"
) as kubernetes_client:
with mock.patch(
"reana_commons.k8s.secrets." "current_k8s_corev1_api_client",
corev1_api_client_with_user_secrets(empty_user_secrets),
):
kubernetes_job_id = job_manager.execute()
kubernetes_client.create_namespaced_job.assert_called_once()
job_manager.stop(kubernetes_job_id)
kubernetes_client.delete_namespaced_job.assert_called_once()
def test_execution_hooks():
"""Test hook execution order."""
class TestJobManger(JobManager):
@JobManager.execution_hook
def execute(self):
self.order_list.append(2)
job_id = str(uuid.uuid4())
return job_id
def before_execution(self):
self.order_list = []
self.order_list.append(1)
def create_job_in_db(self, job_id):
self.order_list.append(3)
def cache_job(self):
self.order_list.append(4)
job_manager = TestJobManger("busybox", "ls", {})
job_manager.execute()
assert job_manager.order_list == [1, 2, 3, 4]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
5363,
879,
33,
14,
199,
3,
1898,
334,
35,
9,
20312,
24354,
14,
199,
3,
199,
3,
5363,
879,
33,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
5113,
570,
367,
1655,
2436,
14,
199,
199,
624,
907,
879,
33,
13,
6694,
13,
7506,
15057,
13537,
2295,
1041,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
5377,
199,
199,
646,
1683,
199,
646,
4613,
199,
504,
295,
6738,
63,
697,
14,
992,
492,
15057,
12,
15057,
3694,
199,
199,
504,
295,
6738,
63,
2423,
63,
5538,
14,
2423,
63,
2609,
492,
15057,
2988,
199,
504,
295,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
492,
28723,
6694,
2988,
421,
199,
318,
511,
63,
2526,
63,
17422,
63,
2423,
8,
272,
1145,
12,
272,
2351,
12,
272,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
12,
272,
2690,
63,
8856,
63,
13249,
12,
272,
849,
63,
751,
12,
272,
2701,
63,
751,
63,
16153,
12,
272,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
12,
272,
17309,
12,
199,
304,
272,
408,
774,
6451,
402,
28723,
3906,
1041,
272,
10431,
63,
2580,
275,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
14,
344,
63,
272,
10431,
63,
13249,
275,
2163,
8,
3271,
63,
8856,
63,
13249,
8,
495,
8,
8856,
63,
2580,
1724,
272,
2589,
63,
1391,
63,
498,
275,
298,
498,
2,
272,
2589,
63,
1391,
63,
585,
275,
298,
585,
2,
272,
1420,
63,
1813,
63,
1391,
275,
469,
1813,
63,
1391,
63,
498,
26,
2589,
63,
1391,
63,
585,
93,
272,
1420,
63,
1569,
275,
298,
25265,
1977,
2,
272,
1420,
63,
1531,
275,
2097,
478,
937,
272,
17309,
14,
261,
9072,
480,
907,
879,
33,
63,
3791,
63,
998,
401,
620,
8,
885,
63,
751,
14,
344,
13309,
272,
3906,
63,
2609,
275,
28723,
6694,
2988,
8,
267,
12424,
63,
4060,
29,
2062,
63,
1569,
12,
267,
2088,
29,
2062,
63,
1531,
12,
267,
2589,
63,
2936,
29,
2062,
63,
1813,
63,
1391,
12,
267,
10431,
63,
2580,
29,
8856,
63,
2580,
12,
267,
10431,
63,
13249,
29,
8856,
63,
13249,
12,
272,
776,
272,
543,
1683,
14,
2068,
8,
267,
298,
264,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
2122,
298,
1818,
63,
75,
24,
83,
63,
2912,
86,
17,
63,
1246,
63,
1258,
2,
272,
776,
465,
31160,
63,
1258,
26,
267,
543,
1683,
14,
2068,
8,
288,
298,
264,
6738,
63,
2330,
83,
14,
75,
24,
83,
14,
16153,
2122,
298,
1818,
63,
75,
24,
83,
63,
1018,
86,
17,
63,
1246,
63,
1258,
401,
288,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
8,
1667,
63,
751,
63,
16153,
395,
267,
3461,
288,
31160,
63,
2423,
63,
344,
275,
3906,
63,
2609,
14,
2526,
342,
288,
2737,
63,
2423,
275,
334,
355,
2351,
14,
1131,
8,
6694,
9,
355,
1275,
1541,
63,
991,
8,
4620,
63,
2423,
63,
344,
29,
17422,
63,
2423,
63,
344,
9,
355,
1275,
368,
63,
269,
63,
3592,
342,
288,
776,
288,
702,
2737,
63,
2423,
288,
702,
2737,
63,
2423,
14,
9991,
63,
4060,
508,
1420,
63,
1569,
288,
702,
2737,
63,
2423,
14,
1760,
508,
2022,
14,
4180,
8,
2062,
63,
1531,
9,
288,
702,
2022,
14,
4180,
8,
2062,
63,
1813,
63,
1391,
9,
315,
2737,
63,
2423,
14,
1813,
63,
2936,
288,
702,
2737,
63,
2423,
14,
1205,
508,
15057,
3694,
14,
3966,
288,
31160,
63,
1258,
14,
981,
63,
19980,
63,
2423,
14,
479,
63,
3527,
63,
5089,
342,
288,
2396,
275,
31160,
63,
1258,
14,
981,
63,
19980,
63,
2423,
14,
1250,
63,
589,
59,
17,
7541,
2030,
937,
288,
2589,
63,
2936,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1813,
937,
288,
1834,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1569,
937,
288,
1414,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1531,
937,
288,
702,
822,
8,
1813,
63,
2936,
9,
508,
650,
288,
702,
2420,
354,
582,
2589,
63,
1391,
63,
498,
12,
298,
585,
582,
2589,
63,
1391,
63,
585,
93,
315,
2589,
63,
2936,
288,
702,
1834,
508,
1420,
63,
1569,
288,
702,
1414,
508,
1420,
63,
1531,
421,
199,
318,
511,
63,
2379,
63,
17422,
63,
2423,
8,
272,
1145,
12,
272,
2351,
12,
272,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
12,
272,
2690,
63,
8856,
63,
13249,
12,
272,
2701,
63,
751,
63,
16153,
12,
272,
849,
63,
751,
12,
272,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
12,
272,
17309,
12,
199,
304,
272,
408,
774,
3631,
402,
28723,
3906,
1041,
272,
10431,
63,
2580,
275,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
14,
344,
63,
272,
10431,
63,
13249,
275,
2163,
8,
3271,
63,
8856,
63,
13249,
8,
495,
8,
8856,
63,
2580,
1724,
272,
1420,
63,
1813,
63,
1391,
63,
354,
275,
298,
1813,
63,
1391,
2,
272,
1420,
63,
1813,
63,
1391,
63,
585,
275,
298,
585,
2,
272,
1420,
63,
1569,
275,
298,
25265,
1977,
2,
272,
1420,
63,
1531,
275,
2097,
478,
937,
272,
17309,
14,
261,
9072,
480,
907,
879,
33,
63,
3791,
63,
998,
401,
620,
8,
885,
63,
751,
14,
344,
13309,
272,
3906,
63,
2609,
275,
28723,
6694,
2988,
8,
267,
12424,
63,
4060,
29,
2062,
63,
1569,
12,
267,
2088,
29,
2062,
63,
1531,
12,
267,
2589,
63,
2936,
3126,
2062,
63,
1813,
63,
1391,
63,
354,
26,
1420,
63,
1813,
63,
1391,
63,
585,
1386,
267,
10431,
63,
2580,
29,
8856,
63,
2580,
12,
267,
10431,
63,
13249,
29,
8856,
63,
13249,
12,
272,
776,
272,
543,
1683,
14,
2068,
8,
267,
298,
264,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
2122,
298,
1818,
63,
75,
24,
83,
63,
2912,
86,
17
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
5363,
879,
33,
14,
199,
3,
1898,
334,
35,
9,
20312,
24354,
14,
199,
3,
199,
3,
5363,
879,
33,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
199,
3,
1334,
314,
2895,
402,
314,
10697,
844,
27,
1937,
5113,
570,
367,
1655,
2436,
14,
199,
199,
624,
907,
879,
33,
13,
6694,
13,
7506,
15057,
13537,
2295,
1041,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
5377,
199,
199,
646,
1683,
199,
646,
4613,
199,
504,
295,
6738,
63,
697,
14,
992,
492,
15057,
12,
15057,
3694,
199,
199,
504,
295,
6738,
63,
2423,
63,
5538,
14,
2423,
63,
2609,
492,
15057,
2988,
199,
504,
295,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
492,
28723,
6694,
2988,
421,
199,
318,
511,
63,
2526,
63,
17422,
63,
2423,
8,
272,
1145,
12,
272,
2351,
12,
272,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
12,
272,
2690,
63,
8856,
63,
13249,
12,
272,
849,
63,
751,
12,
272,
2701,
63,
751,
63,
16153,
12,
272,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
12,
272,
17309,
12,
199,
304,
272,
408,
774,
6451,
402,
28723,
3906,
1041,
272,
10431,
63,
2580,
275,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
14,
344,
63,
272,
10431,
63,
13249,
275,
2163,
8,
3271,
63,
8856,
63,
13249,
8,
495,
8,
8856,
63,
2580,
1724,
272,
2589,
63,
1391,
63,
498,
275,
298,
498,
2,
272,
2589,
63,
1391,
63,
585,
275,
298,
585,
2,
272,
1420,
63,
1813,
63,
1391,
275,
469,
1813,
63,
1391,
63,
498,
26,
2589,
63,
1391,
63,
585,
93,
272,
1420,
63,
1569,
275,
298,
25265,
1977,
2,
272,
1420,
63,
1531,
275,
2097,
478,
937,
272,
17309,
14,
261,
9072,
480,
907,
879,
33,
63,
3791,
63,
998,
401,
620,
8,
885,
63,
751,
14,
344,
13309,
272,
3906,
63,
2609,
275,
28723,
6694,
2988,
8,
267,
12424,
63,
4060,
29,
2062,
63,
1569,
12,
267,
2088,
29,
2062,
63,
1531,
12,
267,
2589,
63,
2936,
29,
2062,
63,
1813,
63,
1391,
12,
267,
10431,
63,
2580,
29,
8856,
63,
2580,
12,
267,
10431,
63,
13249,
29,
8856,
63,
13249,
12,
272,
776,
272,
543,
1683,
14,
2068,
8,
267,
298,
264,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
2122,
298,
1818,
63,
75,
24,
83,
63,
2912,
86,
17,
63,
1246,
63,
1258,
2,
272,
776,
465,
31160,
63,
1258,
26,
267,
543,
1683,
14,
2068,
8,
288,
298,
264,
6738,
63,
2330,
83,
14,
75,
24,
83,
14,
16153,
2122,
298,
1818,
63,
75,
24,
83,
63,
1018,
86,
17,
63,
1246,
63,
1258,
401,
288,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
8,
1667,
63,
751,
63,
16153,
395,
267,
3461,
288,
31160,
63,
2423,
63,
344,
275,
3906,
63,
2609,
14,
2526,
342,
288,
2737,
63,
2423,
275,
334,
355,
2351,
14,
1131,
8,
6694,
9,
355,
1275,
1541,
63,
991,
8,
4620,
63,
2423,
63,
344,
29,
17422,
63,
2423,
63,
344,
9,
355,
1275,
368,
63,
269,
63,
3592,
342,
288,
776,
288,
702,
2737,
63,
2423,
288,
702,
2737,
63,
2423,
14,
9991,
63,
4060,
508,
1420,
63,
1569,
288,
702,
2737,
63,
2423,
14,
1760,
508,
2022,
14,
4180,
8,
2062,
63,
1531,
9,
288,
702,
2022,
14,
4180,
8,
2062,
63,
1813,
63,
1391,
9,
315,
2737,
63,
2423,
14,
1813,
63,
2936,
288,
702,
2737,
63,
2423,
14,
1205,
508,
15057,
3694,
14,
3966,
288,
31160,
63,
1258,
14,
981,
63,
19980,
63,
2423,
14,
479,
63,
3527,
63,
5089,
342,
288,
2396,
275,
31160,
63,
1258,
14,
981,
63,
19980,
63,
2423,
14,
1250,
63,
589,
59,
17,
7541,
2030,
937,
288,
2589,
63,
2936,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1813,
937,
288,
1834,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1569,
937,
288,
1414,
275,
2396,
905,
1650,
6611,
1160,
6611,
1650,
6611,
13577,
9210,
16,
7541,
1531,
937,
288,
702,
822,
8,
1813,
63,
2936,
9,
508,
650,
288,
702,
2420,
354,
582,
2589,
63,
1391,
63,
498,
12,
298,
585,
582,
2589,
63,
1391,
63,
585,
93,
315,
2589,
63,
2936,
288,
702,
1834,
508,
1420,
63,
1569,
288,
702,
1414,
508,
1420,
63,
1531,
421,
199,
318,
511,
63,
2379,
63,
17422,
63,
2423,
8,
272,
1145,
12,
272,
2351,
12,
272,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
12,
272,
2690,
63,
8856,
63,
13249,
12,
272,
2701,
63,
751,
63,
16153,
12,
272,
849,
63,
751,
12,
272,
512,
4964,
17,
63,
1246,
63,
1258,
63,
1045,
63,
751,
63,
16153,
12,
272,
17309,
12,
199,
304,
272,
408,
774,
3631,
402,
28723,
3906,
1041,
272,
10431,
63,
2580,
275,
2690,
63,
2171,
63,
8856,
63,
262,
63,
697,
14,
344,
63,
272,
10431,
63,
13249,
275,
2163,
8,
3271,
63,
8856,
63,
13249,
8,
495,
8,
8856,
63,
2580,
1724,
272,
1420,
63,
1813,
63,
1391,
63,
354,
275,
298,
1813,
63,
1391,
2,
272,
1420,
63,
1813,
63,
1391,
63,
585,
275,
298,
585,
2,
272,
1420,
63,
1569,
275,
298,
25265,
1977,
2,
272,
1420,
63,
1531,
275,
2097,
478,
937,
272,
17309,
14,
261,
9072,
480,
907,
879,
33,
63,
3791,
63,
998,
401,
620,
8,
885,
63,
751,
14,
344,
13309,
272,
3906,
63,
2609,
275,
28723,
6694,
2988,
8,
267,
12424,
63,
4060,
29,
2062,
63,
1569,
12,
267,
2088,
29,
2062,
63,
1531,
12,
267,
2589,
63,
2936,
3126,
2062,
63,
1813,
63,
1391,
63,
354,
26,
1420,
63,
1813,
63,
1391,
63,
585,
1386,
267,
10431,
63,
2580,
29,
8856,
63,
2580,
12,
267,
10431,
63,
13249,
29,
8856,
63,
13249,
12,
272,
776,
272,
543,
1683,
14,
2068,
8,
267,
298,
264,
6738,
63,
2423,
63,
5538,
14,
17422,
63,
2423,
63,
2609,
2122,
298,
1818,
63,
75,
24,
83,
63,
2912,
86,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
intgr/django
|
django/contrib/sites/managers.py
|
132
|
1929
|
from django.conf import settings
from django.core import checks
from django.core.exceptions import FieldDoesNotExist
from django.db import models
class CurrentSiteManager(models.Manager):
"Use this to limit objects to those associated with the current site."
use_in_migrations = True
def __init__(self, field_name=None):
super().__init__()
self.__field_name = field_name
def check(self, **kwargs):
errors = super().check(**kwargs)
errors.extend(self._check_field_name())
return errors
def _check_field_name(self):
field_name = self._get_field_name()
try:
field = self.model._meta.get_field(field_name)
except FieldDoesNotExist:
return [
checks.Error(
"CurrentSiteManager could not find a field named '%s'." % field_name,
obj=self,
id='sites.E001',
)
]
if not field.many_to_many and not isinstance(field, (models.ForeignKey)):
return [
checks.Error(
"CurrentSiteManager cannot use '%s.%s' as it is not a foreign key or a many-to-many field." % (
self.model._meta.object_name, field_name
),
obj=self,
id='sites.E002',
)
]
return []
def _get_field_name(self):
""" Return self.__field_name or 'site' or 'sites'. """
if not self.__field_name:
try:
self.model._meta.get_field('site')
except FieldDoesNotExist:
self.__field_name = 'sites'
else:
self.__field_name = 'site'
return self.__field_name
def get_queryset(self):
return super().get_queryset().filter(**{self._get_field_name() + '__id': settings.SITE_ID})
|
bsd-3-clause
|
[
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
1018,
14,
3924,
492,
29994,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
9338,
8972,
2988,
8,
992,
14,
2988,
304,
272,
298,
6119,
642,
370,
2304,
2251,
370,
5204,
4568,
543,
314,
1453,
4770,
2122,
339,
675,
63,
262,
63,
7685,
275,
715,
339,
347,
636,
826,
721,
277,
12,
901,
63,
354,
29,
403,
304,
267,
1613,
11027,
826,
4533,
267,
291,
855,
698,
63,
354,
275,
901,
63,
354,
339,
347,
1104,
8,
277,
12,
1011,
958,
304,
267,
2552,
275,
1613,
1252,
1074,
3682,
958,
9,
267,
2552,
14,
2880,
8,
277,
423,
1074,
63,
698,
63,
354,
1012,
267,
372,
2552,
339,
347,
485,
1074,
63,
698,
63,
354,
8,
277,
304,
267,
901,
63,
354,
275,
291,
423,
362,
63,
698,
63,
354,
342,
267,
862,
26,
288,
901,
275,
291,
14,
1238,
423,
2024,
14,
362,
63,
698,
8,
698,
63,
354,
9,
267,
871,
29994,
26,
288,
372,
359,
355,
5920,
14,
547,
8,
490,
298,
5639,
8972,
2988,
4293,
440,
2342,
282,
901,
4310,
1543,
83,
16669,
450,
901,
63,
354,
12,
490,
1559,
29,
277,
12,
490,
1305,
534,
8619,
14,
37,
4587,
297,
355,
776,
288,
1622,
398,
340,
440,
901,
14,
3479,
63,
475,
63,
3479,
436,
440,
1228,
8,
698,
12,
334,
992,
14,
3190,
2298,
288,
372,
359,
355,
5920,
14,
547,
8,
490,
298,
5639,
8972,
2988,
3913,
675,
1543,
83,
4111,
83,
7,
465,
652,
365,
440,
282,
11608,
790,
503,
282,
5002,
13,
475,
13,
3479,
901,
2122,
450,
334,
717,
291,
14,
1238,
423,
2024,
14,
785,
63,
354,
12,
901,
63,
354,
490,
2318,
490,
1559,
29,
277,
12,
490,
1305,
534,
8619,
14,
37,
7432,
297,
355,
776,
288,
1622,
398,
372,
942,
339,
347,
485,
362,
63,
698,
63,
354,
8,
277,
304,
267,
408,
1432,
291,
855,
698,
63,
354,
503,
283,
2124,
7,
503,
283,
8619,
1370,
408,
398,
340,
440,
291,
855,
698,
63,
354,
26,
288,
862,
26,
355,
291,
14,
1238,
423,
2024,
14,
362,
63,
698,
360,
2124,
358,
288,
871,
29994,
26,
355,
291,
855,
698,
63,
354,
275,
283,
8619,
7,
288,
587,
26,
355,
291,
855,
698,
63,
354,
275,
283,
2124,
7,
267,
372,
291,
855,
698,
63,
354,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
1252,
362,
63,
7924,
1252,
1541,
25679,
277,
423,
362,
63,
698,
63,
354,
342,
435,
2560,
344,
356,
2202,
14,
7917,
63,
998,
1552,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
492,
5920,
199,
504,
1639,
14,
1018,
14,
3924,
492,
29994,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
9338,
8972,
2988,
8,
992,
14,
2988,
304,
272,
298,
6119,
642,
370,
2304,
2251,
370,
5204,
4568,
543,
314,
1453,
4770,
2122,
339,
675,
63,
262,
63,
7685,
275,
715,
339,
347,
636,
826,
721,
277,
12,
901,
63,
354,
29,
403,
304,
267,
1613,
11027,
826,
4533,
267,
291,
855,
698,
63,
354,
275,
901,
63,
354,
339,
347,
1104,
8,
277,
12,
1011,
958,
304,
267,
2552,
275,
1613,
1252,
1074,
3682,
958,
9,
267,
2552,
14,
2880,
8,
277,
423,
1074,
63,
698,
63,
354,
1012,
267,
372,
2552,
339,
347,
485,
1074,
63,
698,
63,
354,
8,
277,
304,
267,
901,
63,
354,
275,
291,
423,
362,
63,
698,
63,
354,
342,
267,
862,
26,
288,
901,
275,
291,
14,
1238,
423,
2024,
14,
362,
63,
698,
8,
698,
63,
354,
9,
267,
871,
29994,
26,
288,
372,
359,
355,
5920,
14,
547,
8,
490,
298,
5639,
8972,
2988,
4293,
440,
2342,
282,
901,
4310,
1543,
83,
16669,
450,
901,
63,
354,
12,
490,
1559,
29,
277,
12,
490,
1305,
534,
8619,
14,
37,
4587,
297,
355,
776,
288,
1622,
398,
340,
440,
901,
14,
3479,
63,
475,
63,
3479,
436,
440,
1228,
8,
698,
12,
334,
992,
14,
3190,
2298,
288,
372,
359,
355,
5920,
14,
547,
8,
490,
298,
5639,
8972,
2988,
3913,
675,
1543,
83,
4111,
83,
7,
465,
652,
365,
440,
282,
11608,
790,
503,
282,
5002,
13,
475,
13,
3479,
901,
2122,
450,
334,
717,
291,
14,
1238,
423,
2024,
14,
785,
63,
354,
12,
901,
63,
354,
490,
2318,
490,
1559,
29,
277,
12,
490,
1305,
534,
8619,
14,
37,
7432,
297,
355,
776,
288,
1622,
398,
372,
942,
339,
347,
485,
362,
63,
698,
63,
354,
8,
277,
304,
267,
408,
1432,
291,
855,
698,
63,
354,
503,
283,
2124,
7,
503,
283,
8619,
1370,
408,
398,
340,
440,
291,
855,
698,
63,
354,
26,
288,
862,
26,
355,
291,
14,
1238,
423,
2024,
14,
362,
63,
698,
360,
2124,
358,
288,
871,
29994,
26,
355,
291,
855,
698,
63,
354,
275,
283,
8619,
7,
288,
587,
26,
355,
291,
855,
698,
63,
354,
275,
283,
2124,
7,
267,
372,
291,
855,
698,
63,
354,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
1252,
362,
63,
7924,
1252,
1541,
25679,
277,
423,
362,
63,
698,
63,
354,
342,
435,
2560,
344,
356,
2202,
14,
7917,
63,
998,
1552,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ptcrypto/pycoin
|
tests/blockchain_test.py
|
22
|
8237
|
from pycoin.blockchain.BlockChain import BlockChain
class FakeBlock(object):
def __init__(self, n, previous_block_hash=None):
if previous_block_hash is None:
previous_block_hash = n - 1
self.n = n
self.previous_block_hash = previous_block_hash
self.difficulty = 1
def hash(self):
return self.n
def longest_block_chain(self):
c = []
for idx in range(self.length()):
c.append(self.hash_for_index(idx))
return c
def longest_locked_block_chain(self):
c = []
for idx in range(self.locked_length(), self.length()):
c.append(self.hash_for_index(idx))
return c
parent_for_0 = "motherless"
def test_basic():
BC = BlockChain(parent_for_0)
ITEMS = [FakeBlock(i) for i in range(100)]
ITEMS[0] = FakeBlock(0, parent_for_0)
assert longest_block_chain(BC) == []
assert BC.length() == 0
assert BC.locked_length() == 0
assert set(BC.chain_finder.missing_parents()) == set()
assert BC.parent_hash == parent_for_0
assert BC.index_for_hash(0) is None
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[:5])
assert ops == [("add", ITEMS[i], i) for i in range(5)]
assert BC.parent_hash == parent_for_0
assert longest_block_chain(BC) == list(range(5))
assert BC.length() == 5
assert BC.locked_length() == 0
assert set(BC.chain_finder.missing_parents()) == {parent_for_0}
for i in range(5):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[:7])
assert ops == [("add", ITEMS[i], i) for i in range(5,7)]
assert BC.parent_hash == parent_for_0
assert longest_block_chain(BC) == list(range(7))
assert BC.length() == 7
assert BC.locked_length() == 0
assert set(BC.chain_finder.missing_parents()) == {parent_for_0}
for i in range(7):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[10:14])
assert ops == []
assert BC.parent_hash == parent_for_0
assert longest_block_chain(BC) == [0, 1, 2, 3, 4, 5, 6]
assert BC.locked_length() == 0
assert BC.locked_length() == 0
assert BC.length() == 7
assert set(BC.chain_finder.missing_parents()) == {parent_for_0, 9}
for i in range(7):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[7:10])
assert ops == [("add", ITEMS[i], i) for i in range(7,14)]
assert longest_block_chain(BC) == list(range(14))
assert set(BC.chain_finder.missing_parents()) == {parent_for_0}
assert BC.parent_hash == parent_for_0
assert BC.locked_length() == 0
assert BC.length() == 14
for i in range(14):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[90:])
assert ops == []
assert longest_block_chain(BC) == list(range(14))
assert set(BC.chain_finder.missing_parents()) == {parent_for_0, 89}
assert BC.parent_hash == parent_for_0
assert BC.locked_length() == 0
assert BC.length() == 14
for i in range(14):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
ops = BC.add_headers(ITEMS[14:90])
assert ops == [("add", ITEMS[i], i) for i in range(14,100)]
assert longest_block_chain(BC) == list(range(100))
assert set(BC.chain_finder.missing_parents()) == {parent_for_0}
assert BC.parent_hash == parent_for_0
assert BC.locked_length() == 0
assert BC.length() == 100
for i in range(100):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
def test_fork():
parent_for_0 = b'\0' * 32
# 0 <= 1 <= ... <= 5 <= 6
# 3 <= 301 <= 302 <= 303 <= 304 <= 305
#parent_for_0 = "motherless"
BC = BlockChain(parent_for_0)
ITEMS = dict((i, FakeBlock(i)) for i in range(7))
ITEMS[0] = FakeBlock(0, parent_for_0)
ITEMS.update(dict((i, FakeBlock(i)) for i in range(301, 306)))
ITEMS[301] = FakeBlock(301, 3)
assert longest_block_chain(BC) == []
assert BC.locked_length() == 0
assert BC.length() == 0
assert set(BC.chain_finder.missing_parents()) == set()
# send them all except 302
ops = BC.add_headers((ITEMS[i] for i in ITEMS.keys() if i != 302))
assert ops == [("add", ITEMS[i], i) for i in range(7)]
assert set(BC.chain_finder.missing_parents()) == set([parent_for_0, 302])
# now send 302
ops = BC.add_headers([ITEMS[302]])
# we should see a change
expected = [("remove", ITEMS[i], i) for i in range(6, 3, -1)]
expected += [("add", ITEMS[i], i+4-301) for i in range(301,306)]
assert ops == expected
assert set(BC.chain_finder.missing_parents()) == set([parent_for_0])
def test_callback():
R = []
def the_callback(blockchain, ops):
R.extend(ops)
parent_for_0 = b'\0' * 32
# same as test_fork, above
BC = BlockChain(parent_for_0)
BC.add_change_callback(the_callback)
ITEMS = dict((i, FakeBlock(i)) for i in range(7))
ITEMS[0] = FakeBlock(0, parent_for_0)
ITEMS.update(dict((i, FakeBlock(i)) for i in range(301, 306)))
ITEMS[301] = FakeBlock(301, 3)
# send them all except 302
ops = BC.add_headers((ITEMS[i] for i in ITEMS.keys() if i != 302))
# now send 302
ops = BC.add_headers([ITEMS[302]])
expected = [("add", ITEMS[i], i) for i in range(7)]
expected += [("remove", ITEMS[i], i) for i in range(6, 3, -1)]
expected += [("add", ITEMS[i], i+4-301) for i in range(301,306)]
assert R == expected
def test_large():
SIZE = 3000
ITEMS = [FakeBlock(i) for i in range(SIZE)]
ITEMS[0] = FakeBlock(0, parent_for_0)
BC = BlockChain(parent_for_0)
assert longest_block_chain(BC) == []
assert BC.locked_length() == 0
assert BC.length() == 0
assert set(BC.chain_finder.missing_parents()) == set()
ops = BC.add_headers(ITEMS)
assert ops == [("add", ITEMS[i], i) for i in range(SIZE)]
assert longest_block_chain(BC) == list(range(SIZE))
assert set(BC.chain_finder.missing_parents()) == {parent_for_0}
assert BC.parent_hash == parent_for_0
assert BC.locked_length() == 0
assert BC.length() == SIZE
for i in range(SIZE):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
def test_chain_locking():
SIZE = 2000
COUNT = 200
ITEMS = [FakeBlock(i, i-1) for i in range(SIZE*COUNT)]
ITEMS[0] = FakeBlock(0, parent_for_0)
BC = BlockChain(parent_for_0)
assert longest_block_chain(BC) == []
assert BC.locked_length() == 0
assert BC.length() == 0
assert set(BC.chain_finder.missing_parents()) == set()
for i in range(COUNT):
start, end = i*SIZE, (i+1)*SIZE
lock_start = max(0, start-10)
expected_parent = lock_start-1 if lock_start else parent_for_0
assert BC.length() == start
assert BC.locked_length() == lock_start
ops = BC.add_headers(ITEMS[start:end])
assert ops == [("add", ITEMS[i], i) for i in range(start, end)]
assert longest_locked_block_chain(BC) == list(range(lock_start, end))
assert set(BC.chain_finder.missing_parents()) == {expected_parent}
assert BC.parent_hash == expected_parent
assert BC.locked_length() == lock_start
assert BC.length() == end
for i in range(start, end):
v = BC.tuple_for_index(i)
assert v[0] == i
assert v[1] == parent_for_0 if i == 0 else i
assert BC.index_for_hash(-1) is None
assert BC.locked_length() == max(0, lock_start)
BC.lock_to_index(end-10)
assert BC.locked_length() == end-10
|
mit
|
[
199,
504,
1134,
9061,
14,
1457,
4429,
14,
3142,
10720,
492,
8651,
10720,
421,
199,
533,
7777,
3142,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
302,
12,
4136,
63,
1457,
63,
2227,
29,
403,
304,
267,
340,
4136,
63,
1457,
63,
2227,
365,
488,
26,
288,
4136,
63,
1457,
63,
2227,
275,
302,
446,
413,
267,
291,
14,
78,
275,
302,
267,
291,
14,
6352,
63,
1457,
63,
2227,
275,
4136,
63,
1457,
63,
2227,
267,
291,
14,
29801,
275,
413,
339,
347,
2631,
8,
277,
304,
267,
372,
291,
14,
78,
421,
199,
318,
21303,
63,
1457,
63,
4429,
8,
277,
304,
272,
286,
275,
942,
272,
367,
4280,
315,
1425,
8,
277,
14,
1267,
5109,
267,
286,
14,
740,
8,
277,
14,
2227,
63,
509,
63,
1080,
8,
2996,
430,
272,
372,
286,
421,
199,
318,
21303,
63,
9325,
63,
1457,
63,
4429,
8,
277,
304,
272,
286,
275,
942,
272,
367,
4280,
315,
1425,
8,
277,
14,
9325,
63,
1267,
1062,
291,
14,
1267,
5109,
267,
286,
14,
740,
8,
277,
14,
2227,
63,
509,
63,
1080,
8,
2996,
430,
272,
372,
286,
421,
199,
1708,
63,
509,
63,
16,
275,
298,
573,
728,
2003,
2,
199,
199,
318,
511,
63,
4316,
837,
272,
32758,
275,
8651,
10720,
8,
1708,
63,
509,
63,
16,
9,
272,
473,
22057,
51,
275,
359,
8249,
3142,
8,
73,
9,
367,
284,
315,
1425,
8,
1960,
1874,
272,
473,
22057,
51,
59,
16,
61,
275,
7777,
3142,
8,
16,
12,
1676,
63,
509,
63,
16,
9,
339,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
942,
272,
702,
32758,
14,
1267,
342,
508,
378,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
663,
342,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
8,
16,
9,
365,
488,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
1491,
21,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
21,
1874,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
21,
430,
272,
702,
32758,
14,
1267,
342,
508,
959,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
367,
284,
315,
1425,
8,
21,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
1491,
23,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
21,
12,
23,
1874,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
23,
430,
272,
702,
32758,
14,
1267,
342,
508,
1520,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
367,
284,
315,
1425,
8,
23,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
59,
709,
26,
1079,
566,
272,
702,
4156,
508,
942,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
61,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
1267,
342,
508,
1520,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
12,
1749,
93,
272,
367,
284,
315,
1425,
8,
23,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
59,
23,
26,
709,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
23,
12,
1079,
1874,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
1079,
430,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
1267,
342,
508,
4329,
272,
367,
284,
315,
1425,
8,
1079,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9
] |
[
504,
1134,
9061,
14,
1457,
4429,
14,
3142,
10720,
492,
8651,
10720,
421,
199,
533,
7777,
3142,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
302,
12,
4136,
63,
1457,
63,
2227,
29,
403,
304,
267,
340,
4136,
63,
1457,
63,
2227,
365,
488,
26,
288,
4136,
63,
1457,
63,
2227,
275,
302,
446,
413,
267,
291,
14,
78,
275,
302,
267,
291,
14,
6352,
63,
1457,
63,
2227,
275,
4136,
63,
1457,
63,
2227,
267,
291,
14,
29801,
275,
413,
339,
347,
2631,
8,
277,
304,
267,
372,
291,
14,
78,
421,
199,
318,
21303,
63,
1457,
63,
4429,
8,
277,
304,
272,
286,
275,
942,
272,
367,
4280,
315,
1425,
8,
277,
14,
1267,
5109,
267,
286,
14,
740,
8,
277,
14,
2227,
63,
509,
63,
1080,
8,
2996,
430,
272,
372,
286,
421,
199,
318,
21303,
63,
9325,
63,
1457,
63,
4429,
8,
277,
304,
272,
286,
275,
942,
272,
367,
4280,
315,
1425,
8,
277,
14,
9325,
63,
1267,
1062,
291,
14,
1267,
5109,
267,
286,
14,
740,
8,
277,
14,
2227,
63,
509,
63,
1080,
8,
2996,
430,
272,
372,
286,
421,
199,
1708,
63,
509,
63,
16,
275,
298,
573,
728,
2003,
2,
199,
199,
318,
511,
63,
4316,
837,
272,
32758,
275,
8651,
10720,
8,
1708,
63,
509,
63,
16,
9,
272,
473,
22057,
51,
275,
359,
8249,
3142,
8,
73,
9,
367,
284,
315,
1425,
8,
1960,
1874,
272,
473,
22057,
51,
59,
16,
61,
275,
7777,
3142,
8,
16,
12,
1676,
63,
509,
63,
16,
9,
339,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
942,
272,
702,
32758,
14,
1267,
342,
508,
378,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
663,
342,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
8,
16,
9,
365,
488,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
1491,
21,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
21,
1874,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
21,
430,
272,
702,
32758,
14,
1267,
342,
508,
959,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
367,
284,
315,
1425,
8,
21,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
1491,
23,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
21,
12,
23,
1874,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
23,
430,
272,
702,
32758,
14,
1267,
342,
508,
1520,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
367,
284,
315,
1425,
8,
23,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
59,
709,
26,
1079,
566,
272,
702,
4156,
508,
942,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
359,
16,
12,
413,
12,
499,
12,
650,
12,
841,
12,
959,
12,
1227,
61,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
1267,
342,
508,
1520,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
12,
1749,
93,
272,
367,
284,
315,
1425,
8,
23,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
365,
488,
339,
4156,
275,
32758,
14,
525,
63,
2139,
8,
10439,
51,
59,
23,
26,
709,
566,
272,
702,
4156,
508,
10003,
525,
401,
473,
22057,
51,
59,
73,
467,
284,
9,
367,
284,
315,
1425,
8,
23,
12,
1079,
1874,
272,
702,
21303,
63,
1457,
63,
4429,
8,
6265,
9,
508,
769,
8,
1842,
8,
1079,
430,
272,
702,
663,
8,
6265,
14,
4429,
63,
11681,
14,
4752,
63,
8859,
1012,
508,
469,
1708,
63,
509,
63,
16,
93,
272,
702,
32758,
14,
1708,
63,
2227,
508,
1676,
63,
509,
63,
16,
272,
702,
32758,
14,
9325,
63,
1267,
342,
508,
378,
272,
702,
32758,
14,
1267,
342,
508,
4329,
272,
367,
284,
315,
1425,
8,
1079,
304,
267,
373,
275,
32758,
14,
2960,
63,
509,
63,
1080,
8,
73,
9,
267,
702,
373,
59,
16,
61,
508,
284,
267,
702,
373,
59,
17,
61,
508,
1676,
63,
509,
63,
16,
340,
284,
508,
378,
587,
284,
272,
702,
32758,
14,
1080,
63,
509,
63,
2227,
2801,
17,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
ysywh/ryu
|
ryu/contrib/tinyrpc/transports/zmq.py
|
43
|
2299
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import # needed for zmq import
import zmq
from . import ServerTransport, ClientTransport
class ZmqServerTransport(ServerTransport):
"""Server transport based on a :py:const:`zmq.ROUTER` socket.
:param socket: A :py:const:`zmq.ROUTER` socket instance, bound to an
endpoint.
"""
def __init__(self, socket):
self.socket = socket
def receive_message(self):
msg = self.socket.recv_multipart()
return msg[:-1], msg[-1]
def send_reply(self, context, reply):
self.socket.send_multipart(context + [reply])
@classmethod
def create(cls, zmq_context, endpoint):
"""Create new server transport.
Instead of creating the socket yourself, you can call this function and
merely pass the :py:class:`zmq.core.context.Context` instance.
By passing a context imported from :py:mod:`zmq.green`, you can use
green (gevent) 0mq sockets as well.
:param zmq_context: A 0mq context.
:param endpoint: The endpoint clients will connect to.
"""
socket = zmq_context.socket(zmq.ROUTER)
socket.bind(endpoint)
return cls(socket)
class ZmqClientTransport(ClientTransport):
"""Client transport based on a :py:const:`zmq.REQ` socket.
:param socket: A :py:const:`zmq.REQ` socket instance, connected to the
server socket.
"""
def __init__(self, socket):
self.socket = socket
def send_message(self, message, expect_reply=True):
self.socket.send(message)
if expect_reply:
return self.socket.recv()
@classmethod
def create(cls, zmq_context, endpoint):
"""Create new client transport.
Instead of creating the socket yourself, you can call this function and
merely pass the :py:class:`zmq.core.context.Context` instance.
By passing a context imported from :py:mod:`zmq.green`, you can use
green (gevent) 0mq sockets as well.
:param zmq_context: A 0mq context.
:param endpoint: The endpoint the server is bound to.
"""
socket = zmq_context.socket(zmq.REQ)
socket.connect(endpoint)
return cls(socket)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
221,
327,
4346,
367,
26633,
492,
199,
646,
26633,
199,
199,
504,
1275,
492,
7146,
7836,
12,
6810,
7836,
421,
199,
533,
3107,
8334,
3120,
7836,
8,
3120,
7836,
304,
272,
408,
3120,
7773,
4079,
641,
282,
520,
647,
26,
1297,
1705,
21290,
14,
19281,
64,
2838,
14,
339,
520,
635,
2838,
26,
437,
520,
647,
26,
1297,
1705,
21290,
14,
19281,
64,
2838,
1256,
12,
3914,
370,
376,
673,
6037,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
14,
3450,
275,
2838,
339,
347,
9128,
63,
1188,
8,
277,
304,
267,
1499,
275,
291,
14,
3450,
14,
7637,
63,
10123,
342,
267,
372,
1499,
4439,
17,
467,
1499,
1988,
17,
61,
339,
347,
3222,
63,
8102,
8,
277,
12,
1067,
12,
9351,
304,
267,
291,
14,
3450,
14,
2254,
63,
10123,
8,
1100,
435,
359,
8102,
566,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
26633,
63,
1100,
12,
6037,
304,
267,
408,
2499,
892,
1654,
7773,
14,
398,
15345,
402,
6425,
314,
2838,
28225,
12,
1265,
883,
1240,
642,
805,
436,
267,
562,
264,
590,
986,
314,
520,
647,
26,
533,
1705,
21290,
14,
1018,
14,
1100,
14,
2998,
64,
1256,
14,
398,
4885,
9476,
282,
1067,
8439,
687,
520,
647,
26,
1494,
1705,
21290,
14,
7731,
3559,
1265,
883,
675,
267,
12431,
334,
303,
782,
9,
378,
8334,
18772,
465,
5521,
14,
398,
520,
635,
26633,
63,
1100,
26,
437,
378,
8334,
1067,
14,
267,
520,
635,
6037,
26,
710,
6037,
13431,
911,
4907,
370,
14,
267,
408,
267,
2838,
275,
26633,
63,
1100,
14,
3450,
8,
21290,
14,
19281,
9,
267,
2838,
14,
3409,
8,
6520,
9,
267,
372,
843,
8,
3450,
9,
421,
199,
533,
3107,
8334,
3041,
7836,
8,
3041,
7836,
304,
272,
408,
3041,
7773,
4079,
641,
282,
520,
647,
26,
1297,
1705,
21290,
14,
14583,
64,
2838,
14,
339,
520,
635,
2838,
26,
437,
520,
647,
26,
1297,
1705,
21290,
14,
14583,
64,
2838,
1256,
12,
8539,
370,
314,
673,
1654,
2838,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
14,
3450,
275,
2838,
339,
347,
3222,
63,
1188,
8,
277,
12,
1245,
12,
4282,
63,
8102,
29,
549,
304,
267,
291,
14,
3450,
14,
2254,
8,
1188,
9,
398,
340,
4282,
63,
8102,
26,
288,
372,
291,
14,
3450,
14,
7637,
342,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
26633,
63,
1100,
12,
6037,
304,
267,
408,
2499,
892,
1890,
7773,
14,
398,
15345,
402,
6425,
314,
2838,
28225,
12,
1265,
883,
1240,
642,
805,
436,
267,
562,
264,
590,
986,
314,
520,
647,
26,
533,
1705,
21290,
14,
1018,
14,
1100,
14,
2998,
64,
1256,
14,
398,
4885,
9476,
282,
1067,
8439,
687,
520,
647,
26,
1494,
1705,
21290,
14,
7731,
3559,
1265,
883,
675,
267,
12431,
334,
303,
782,
9,
378,
8334,
18772,
465,
5521,
14,
398,
520,
635,
26633,
63,
1100,
26,
437,
378,
8334,
1067,
14,
267,
520,
635,
6037,
26,
710,
6037,
314,
1654,
365,
3914,
370,
14,
267,
408,
267,
2838,
275,
26633,
63,
1100,
14,
3450,
8,
21290,
14,
14583,
9,
267,
2838,
14,
2242,
8,
6520,
9,
267,
372,
843,
8,
3450,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
221,
327,
4346,
367,
26633,
492,
199,
646,
26633,
199,
199,
504,
1275,
492,
7146,
7836,
12,
6810,
7836,
421,
199,
533,
3107,
8334,
3120,
7836,
8,
3120,
7836,
304,
272,
408,
3120,
7773,
4079,
641,
282,
520,
647,
26,
1297,
1705,
21290,
14,
19281,
64,
2838,
14,
339,
520,
635,
2838,
26,
437,
520,
647,
26,
1297,
1705,
21290,
14,
19281,
64,
2838,
1256,
12,
3914,
370,
376,
673,
6037,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
14,
3450,
275,
2838,
339,
347,
9128,
63,
1188,
8,
277,
304,
267,
1499,
275,
291,
14,
3450,
14,
7637,
63,
10123,
342,
267,
372,
1499,
4439,
17,
467,
1499,
1988,
17,
61,
339,
347,
3222,
63,
8102,
8,
277,
12,
1067,
12,
9351,
304,
267,
291,
14,
3450,
14,
2254,
63,
10123,
8,
1100,
435,
359,
8102,
566,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
26633,
63,
1100,
12,
6037,
304,
267,
408,
2499,
892,
1654,
7773,
14,
398,
15345,
402,
6425,
314,
2838,
28225,
12,
1265,
883,
1240,
642,
805,
436,
267,
562,
264,
590,
986,
314,
520,
647,
26,
533,
1705,
21290,
14,
1018,
14,
1100,
14,
2998,
64,
1256,
14,
398,
4885,
9476,
282,
1067,
8439,
687,
520,
647,
26,
1494,
1705,
21290,
14,
7731,
3559,
1265,
883,
675,
267,
12431,
334,
303,
782,
9,
378,
8334,
18772,
465,
5521,
14,
398,
520,
635,
26633,
63,
1100,
26,
437,
378,
8334,
1067,
14,
267,
520,
635,
6037,
26,
710,
6037,
13431,
911,
4907,
370,
14,
267,
408,
267,
2838,
275,
26633,
63,
1100,
14,
3450,
8,
21290,
14,
19281,
9,
267,
2838,
14,
3409,
8,
6520,
9,
267,
372,
843,
8,
3450,
9,
421,
199,
533,
3107,
8334,
3041,
7836,
8,
3041,
7836,
304,
272,
408,
3041,
7773,
4079,
641,
282,
520,
647,
26,
1297,
1705,
21290,
14,
14583,
64,
2838,
14,
339,
520,
635,
2838,
26,
437,
520,
647,
26,
1297,
1705,
21290,
14,
14583,
64,
2838,
1256,
12,
8539,
370,
314,
673,
1654,
2838,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2838,
304,
267,
291,
14,
3450,
275,
2838,
339,
347,
3222,
63,
1188,
8,
277,
12,
1245,
12,
4282,
63,
8102,
29,
549,
304,
267,
291,
14,
3450,
14,
2254,
8,
1188,
9,
398,
340,
4282,
63,
8102,
26,
288,
372,
291,
14,
3450,
14,
7637,
342,
339,
768,
3744,
272,
347,
1218,
8,
1886,
12,
26633,
63,
1100,
12,
6037,
304,
267,
408,
2499,
892,
1890,
7773,
14,
398,
15345,
402,
6425,
314,
2838,
28225,
12,
1265,
883,
1240,
642,
805,
436,
267,
562,
264,
590,
986,
314,
520,
647,
26,
533,
1705,
21290,
14,
1018,
14,
1100,
14,
2998,
64,
1256,
14,
398,
4885,
9476,
282,
1067,
8439,
687,
520,
647,
26,
1494,
1705,
21290,
14,
7731,
3559,
1265,
883,
675,
267,
12431,
334,
303,
782,
9,
378,
8334,
18772,
465,
5521,
14,
398,
520,
635,
26633,
63,
1100,
26,
437,
378,
8334,
1067,
14,
267,
520,
635,
6037,
26,
710,
6037,
314,
1654,
365,
3914,
370,
14,
267,
408,
267,
2838,
275,
26633,
63,
1100,
14,
3450,
8,
21290,
14,
14583,
9,
267,
2838,
14,
2242,
8,
6520,
9,
267,
372,
843,
8,
3450,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
0x19/flask-peewee
|
flask_peewee/tests/auth.py
|
7
|
8613
|
from __future__ import with_statement
import datetime
try:
import urlparse
except ImportError:
from urllib import parse as urlparse
from flask import get_flashed_messages
from flask import request
from flask import session
from flask import url_for
from flask_peewee.auth import Auth
from flask_peewee.auth import LoginForm
from flask_peewee.tests.base import FlaskPeeweeTestCase
from flask_peewee.tests.test_app import User
from flask_peewee.tests.test_app import app
from flask_peewee.tests.test_app import auth
from flask_peewee.tests.test_app import db
class TestAuth(Auth):
def setup(self):
pass
class AuthTestCase(FlaskPeeweeTestCase):
def setUp(self):
super(AuthTestCase, self).setUp()
self.test_auth = TestAuth(app, db)
def login(self, username='admin', password='admin', context=None):
context = context or self.app
return context.post('/accounts/login/', data={
'username': username,
'password': password,
})
def logout(self, context=None):
context = context or self.app
return context.post('/accounts/logout/')
def test_table(self):
self.assertEqual(self.test_auth.User._meta.db_table, 'user')
fake_auth = TestAuth(app, db, db_table='peewee_users')
self.assertEqual(fake_auth.User._meta.db_table, 'peewee_users')
def test_login_view(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.get('/accounts/login/')
self.assertEqual(resp.status_code, 200)
# check that we have no logged-in user
self.assertContext('user', None)
frm = self.get_context('form')
self.assertTrue(isinstance(frm, LoginForm))
self.assertEqual(frm.data, {'username': None, 'password': None})
# make a post missing the username
resp = c.post('/accounts/login/', data={
'username': '',
'password': 'xxx',
})
self.assertEqual(resp.status_code, 200)
# check form for errors
frm = self.get_context('form')
self.assertEqual(frm.errors, {'username': [u'This field is required.']})
# check that no messages were generated
self.assertFalse('_flashes' in session)
# check that the auth API does not indicate a logged-in user
self.assertEqual(auth.get_logged_in_user(), None)
# make a post with a bad username/password combo
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'baz',
})
self.assertEqual(resp.status_code, 200)
# both fields were present so no form errors, but flash the user
# indicating bad username/password combo
self.assertTrue('_flashes' in session)
messages = get_flashed_messages()
self.assertEqual(messages, [
'Incorrect username or password',
])
# check that the auth API does not indicate a logged-in user
self.assertEqual(auth.get_logged_in_user(), None)
# make a post with an inactive user
resp = c.post('/accounts/login/', data={
'username': 'inactive',
'password': 'inactive',
})
self.assertEqual(resp.status_code, 200)
# still no logged-in user
self.assertContext('user', None)
# check that the auth API does not indicate a logged-in user
self.assertEqual(auth.get_logged_in_user(), None)
# finally post as a known good user
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
})
self.assertEqual(resp.status_code, 302)
# check that we now have a logged-in user
self.assertEqual(auth.get_logged_in_user(), self.normal)
def test_login_redirect_in_depth(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.get('/admin/')
location = resp.location
parsed = urlparse.urlparse(location)
querystring = urlparse.parse_qs(parsed.query)
self.assertEqual(querystring, {'next': ['/admin/']})
# Following the redirect, the next url is passed to context.
location = location.replace('http://localhost', '')
resp = c.get(location)
self.assertEqual(self.get_context('next'), '/admin/')
# Simulate incorrect password.
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'incorrect-password',
'next': '/admin/',
})
self.assertEqual(resp.status_code, 200)
self.assertEqual(self.get_context('next'), '/admin/')
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
'next': '/admin/',
})
self.assertEqual(resp.status_code, 302)
self.assertTrue(resp.headers['location'].endswith('/admin/'))
def test_login_default_redirect(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
})
self.assertEqual(resp.status_code, 302)
location = resp.location.replace('http://localhost', '')
self.assertTrue(location, '/')
def test_login_redirect(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
'next': '/foo-baz/',
})
self.assertEqual(resp.status_code, 302)
self.assertTrue(resp.headers['location'].endswith('/foo-baz/'))
def test_login_logout(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
})
self.assertEqual(auth.get_logged_in_user(), self.normal)
resp = c.post('/accounts/logout/')
self.assertEqual(auth.get_logged_in_user(), None)
resp = c.post('/accounts/login/', data={
'username': 'admin',
'password': 'admin',
})
self.assertEqual(auth.get_logged_in_user(), self.admin)
# log back in without logging out
resp = c.post('/accounts/login/', data={
'username': 'normal',
'password': 'normal',
})
self.assertEqual(auth.get_logged_in_user(), self.normal)
def test_login_required(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.get('/private/')
self.assertEqual(resp.status_code, 302)
self.assertTrue(resp.headers['location'].endswith('/accounts/login/?next=%2Fprivate%2F'))
self.login('normal', 'normal', c)
resp = c.get('/private/')
self.assertEqual(resp.status_code, 200)
self.assertEqual(auth.get_logged_in_user(), self.normal)
self.login('admin', 'admin', c)
resp = c.get('/private/')
self.assertEqual(resp.status_code, 200)
self.assertEqual(auth.get_logged_in_user(), self.admin)
def test_admin_required(self):
self.create_users()
with self.flask_app.test_client() as c:
resp = c.get('/secret/')
self.assertEqual(resp.status_code, 302)
self.assertTrue(resp.headers['location'].endswith('/accounts/login/?next=%2Fsecret%2F'))
self.login('normal', 'normal', c)
resp = c.get('/secret/')
self.assertEqual(resp.status_code, 302)
self.assertTrue(resp.headers['location'].endswith('/accounts/login/?next=%2Fsecret%2F'))
self.assertEqual(auth.get_logged_in_user(), self.normal)
self.login('admin', 'admin', c)
resp = c.get('/secret/')
self.assertEqual(resp.status_code, 200)
self.assertEqual(auth.get_logged_in_user(), self.admin)
|
mit
|
[
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2197,
199,
893,
26,
272,
492,
7097,
199,
2590,
3545,
26,
272,
687,
4011,
492,
2198,
465,
7097,
199,
199,
504,
7209,
492,
664,
63,
11331,
379,
63,
3431,
199,
504,
7209,
492,
1056,
199,
504,
7209,
492,
2351,
199,
504,
7209,
492,
1166,
63,
509,
199,
199,
504,
7209,
63,
321,
546,
1024,
14,
1178,
492,
3590,
199,
504,
7209,
63,
321,
546,
1024,
14,
1178,
492,
16430,
2821,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
1095,
492,
16704,
8070,
546,
1024,
1746,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
2876,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1145,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1790,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1592,
421,
199,
533,
1379,
2817,
8,
2817,
304,
272,
347,
3272,
8,
277,
304,
267,
986,
421,
199,
533,
3590,
1746,
8,
14182,
8070,
546,
1024,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
2817,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
396,
63,
1178,
275,
1379,
2817,
8,
571,
12,
1592,
9,
339,
347,
4676,
8,
277,
12,
3434,
534,
2113,
297,
2505,
534,
2113,
297,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
291,
14,
571,
267,
372,
1067,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
288,
283,
2473,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
3828,
339,
347,
22079,
8,
277,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
291,
14,
571,
267,
372,
1067,
14,
1932,
2336,
8370,
15,
11646,
6217,
339,
347,
511,
63,
1224,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
396,
63,
1178,
14,
1899,
423,
2024,
14,
697,
63,
1224,
12,
283,
751,
358,
398,
4026,
63,
1178,
275,
1379,
2817,
8,
571,
12,
1592,
12,
1592,
63,
1224,
534,
321,
546,
1024,
63,
3707,
358,
267,
291,
14,
629,
8,
3183,
63,
1178,
14,
1899,
423,
2024,
14,
697,
63,
1224,
12,
283,
321,
546,
1024,
63,
3707,
358,
339,
347,
511,
63,
2886,
63,
1345,
8,
277,
304,
267,
291,
14,
981,
63,
3707,
342,
398,
543,
291,
14,
15720,
63,
571,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
3085,
275,
286,
14,
362,
2336,
8370,
15,
2886,
6217,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
1104,
626,
781,
1172,
949,
10367,
13,
262,
922,
288,
291,
14,
479,
2998,
360,
751,
297,
488,
9,
953,
289,
5682,
275,
291,
14,
362,
63,
1100,
360,
964,
358,
288,
291,
14,
1815,
8,
6074,
8,
20095,
12,
16430,
2821,
430,
288,
291,
14,
629,
8,
20095,
14,
576,
12,
791,
2473,
356,
488,
12,
283,
2060,
356,
488,
1552,
953,
327,
1852,
282,
2963,
4124,
314,
3434,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
3260,
355,
283,
2060,
356,
283,
10013,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
1104,
1824,
367,
2552,
288,
289,
5682,
275,
291,
14,
362,
63,
1100,
360,
964,
358,
288,
291,
14,
629,
8,
20095,
14,
2550,
12,
791,
2473,
356,
359,
85,
7,
2765,
901,
365,
1415,
14,
13678,
953,
327,
1104,
626,
949,
3788,
4898,
4046,
288,
291,
14,
3334,
6412,
2327,
9030,
7,
315,
2351,
9,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
1852,
282,
2963,
543,
282,
4875,
3434,
15,
2060,
20972,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
3302,
297,
355,
283,
2060,
356,
283,
6185,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
3865,
1504,
4898,
3451,
880,
949,
1824,
2552,
12,
1325,
14775,
314,
922,
288,
327,
9297,
4875,
3434,
15,
2060,
20972,
288,
291,
14,
1815,
6412,
2327,
9030,
7,
315,
2351,
9,
288,
3788,
275,
664,
63,
11331,
379,
63,
3431,
342,
953,
291,
14,
629,
8,
3431,
12,
359,
355,
283,
18298,
3434,
503,
2505,
297,
288,
4794,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
1852,
282,
2963,
543,
376,
21325,
922,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
16856,
297,
355,
283,
2060,
356,
283,
16856,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
5139,
949,
10367,
13,
262,
922,
288,
291,
14,
479,
2998,
360,
751,
297,
488,
9,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
3753,
2963,
465,
282,
6040,
6954,
922,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
3302,
297,
355,
283,
2060,
356,
283,
3302,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
11485,
9,
953,
327,
1104,
626,
781,
3063,
1172,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
291,
14,
3302,
9,
339,
347,
511,
63,
2886,
63,
4876,
63,
262,
63,
4631,
8,
277,
304,
267,
291,
14,
981,
63,
3707,
342,
398,
543,
291,
14,
15720,
63,
571,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
3085,
275,
286,
14,
362,
2336,
2113,
6217,
288,
2909,
275,
3085,
14,
1985,
288,
4565,
275,
7097,
14,
10290,
8,
1985,
9,
288,
1827,
875,
275
] |
[
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
2197,
199,
893,
26,
272,
492,
7097,
199,
2590,
3545,
26,
272,
687,
4011,
492,
2198,
465,
7097,
199,
199,
504,
7209,
492,
664,
63,
11331,
379,
63,
3431,
199,
504,
7209,
492,
1056,
199,
504,
7209,
492,
2351,
199,
504,
7209,
492,
1166,
63,
509,
199,
199,
504,
7209,
63,
321,
546,
1024,
14,
1178,
492,
3590,
199,
504,
7209,
63,
321,
546,
1024,
14,
1178,
492,
16430,
2821,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
1095,
492,
16704,
8070,
546,
1024,
1746,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
2876,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1145,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1790,
199,
504,
7209,
63,
321,
546,
1024,
14,
2219,
14,
396,
63,
571,
492,
1592,
421,
199,
533,
1379,
2817,
8,
2817,
304,
272,
347,
3272,
8,
277,
304,
267,
986,
421,
199,
533,
3590,
1746,
8,
14182,
8070,
546,
1024,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
2817,
1746,
12,
291,
680,
5996,
342,
398,
291,
14,
396,
63,
1178,
275,
1379,
2817,
8,
571,
12,
1592,
9,
339,
347,
4676,
8,
277,
12,
3434,
534,
2113,
297,
2505,
534,
2113,
297,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
291,
14,
571,
267,
372,
1067,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
288,
283,
2473,
356,
3434,
12,
288,
283,
2060,
356,
2505,
12,
267,
3828,
339,
347,
22079,
8,
277,
12,
1067,
29,
403,
304,
267,
1067,
275,
1067,
503,
291,
14,
571,
267,
372,
1067,
14,
1932,
2336,
8370,
15,
11646,
6217,
339,
347,
511,
63,
1224,
8,
277,
304,
267,
291,
14,
629,
8,
277,
14,
396,
63,
1178,
14,
1899,
423,
2024,
14,
697,
63,
1224,
12,
283,
751,
358,
398,
4026,
63,
1178,
275,
1379,
2817,
8,
571,
12,
1592,
12,
1592,
63,
1224,
534,
321,
546,
1024,
63,
3707,
358,
267,
291,
14,
629,
8,
3183,
63,
1178,
14,
1899,
423,
2024,
14,
697,
63,
1224,
12,
283,
321,
546,
1024,
63,
3707,
358,
339,
347,
511,
63,
2886,
63,
1345,
8,
277,
304,
267,
291,
14,
981,
63,
3707,
342,
398,
543,
291,
14,
15720,
63,
571,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
3085,
275,
286,
14,
362,
2336,
8370,
15,
2886,
6217,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
1104,
626,
781,
1172,
949,
10367,
13,
262,
922,
288,
291,
14,
479,
2998,
360,
751,
297,
488,
9,
953,
289,
5682,
275,
291,
14,
362,
63,
1100,
360,
964,
358,
288,
291,
14,
1815,
8,
6074,
8,
20095,
12,
16430,
2821,
430,
288,
291,
14,
629,
8,
20095,
14,
576,
12,
791,
2473,
356,
488,
12,
283,
2060,
356,
488,
1552,
953,
327,
1852,
282,
2963,
4124,
314,
3434,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
3260,
355,
283,
2060,
356,
283,
10013,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
1104,
1824,
367,
2552,
288,
289,
5682,
275,
291,
14,
362,
63,
1100,
360,
964,
358,
288,
291,
14,
629,
8,
20095,
14,
2550,
12,
791,
2473,
356,
359,
85,
7,
2765,
901,
365,
1415,
14,
13678,
953,
327,
1104,
626,
949,
3788,
4898,
4046,
288,
291,
14,
3334,
6412,
2327,
9030,
7,
315,
2351,
9,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
1852,
282,
2963,
543,
282,
4875,
3434,
15,
2060,
20972,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
3302,
297,
355,
283,
2060,
356,
283,
6185,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
3865,
1504,
4898,
3451,
880,
949,
1824,
2552,
12,
1325,
14775,
314,
922,
288,
327,
9297,
4875,
3434,
15,
2060,
20972,
288,
291,
14,
1815,
6412,
2327,
9030,
7,
315,
2351,
9,
288,
3788,
275,
664,
63,
11331,
379,
63,
3431,
342,
953,
291,
14,
629,
8,
3431,
12,
359,
355,
283,
18298,
3434,
503,
2505,
297,
288,
4794,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
1852,
282,
2963,
543,
376,
21325,
922,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
16856,
297,
355,
283,
2060,
356,
283,
16856,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
1926,
9,
953,
327,
5139,
949,
10367,
13,
262,
922,
288,
291,
14,
479,
2998,
360,
751,
297,
488,
9,
953,
327,
1104,
626,
314,
1790,
3261,
1630,
440,
6623,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
488,
9,
953,
327,
3753,
2963,
465,
282,
6040,
6954,
922,
288,
3085,
275,
286,
14,
1932,
2336,
8370,
15,
2886,
3678,
666,
3126,
355,
283,
2473,
356,
283,
3302,
297,
355,
283,
2060,
356,
283,
3302,
297,
288,
3828,
288,
291,
14,
629,
8,
4518,
14,
1205,
63,
600,
12,
11485,
9,
953,
327,
1104,
626,
781,
3063,
1172,
282,
10367,
13,
262,
922,
288,
291,
14,
629,
8,
1178,
14,
362,
63,
12419,
63,
262,
63,
751,
1062,
291,
14,
3302,
9,
339,
347,
511,
63,
2886,
63,
4876,
63,
262,
63,
4631,
8,
277,
304,
267,
291,
14,
981,
63,
3707,
342,
398,
543,
291,
14,
15720,
63,
571,
14,
396,
63,
1258,
342,
465,
286,
26,
288,
3085,
275,
286,
14,
362,
2336,
2113,
6217,
288,
2909,
275,
3085,
14,
1985,
288,
4565,
275,
7097,
14,
10290,
8,
1985,
9,
288,
1827,
875,
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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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
] |
kencochrane/docker-django-demo
|
dockerdemo/voting/migrations/0001_initial.py
|
1
|
1782
|
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-16 20:05
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Choice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_text', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question_text', models.CharField(max_length=200)),
('pub_date', models.DateTimeField(auto_now_add=True, verbose_name='date published')),
('last_update', models.DateTimeField(auto_now=True, verbose_name='last updated')),
],
),
migrations.CreateModel(
name='Vote',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('vote_date', models.DateTimeField(auto_now=True, verbose_name='date voted')),
('ip_address', models.GenericIPAddressField()),
('selection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='voting.Choice')),
],
),
migrations.AddField(
model_name='choice',
name='question',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='voting.Question'),
),
]
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
25,
14,
18,
641,
7800,
13,
996,
13,
975,
3388,
26,
1717,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
9054,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
5095,
63,
505,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
16778,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
4790,
63,
505,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
1826,
355,
661,
5645,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
602,
3267,
3855,
355,
661,
2019,
63,
873,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
3376,
63,
354,
534,
2019,
4588,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
54,
1583,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
14317,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
3376,
63,
354,
534,
602,
373,
5731,
3855,
355,
661,
711,
63,
1562,
297,
1709,
14,
9417,
26969,
4000,
355,
661,
5592,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
86,
15866,
14,
9054,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
5095,
297,
288,
536,
534,
4790,
297,
288,
901,
29,
992,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
86,
15866,
14,
16778,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
17065,
701,
5634,
413,
14,
25,
14,
18,
641,
7800,
13,
996,
13,
975,
3388,
26,
1717,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
6180,
12,
1709,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
2536,
275,
715,
339,
5124,
275,
359,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
9054,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
5095,
63,
505,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
1826,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
16778,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
4790,
63,
505,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1840,
1826,
355,
661,
5645,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
12,
3376,
63,
354,
534,
602,
3267,
3855,
355,
661,
2019,
63,
873,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
3376,
63,
354,
534,
2019,
4588,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
14907,
8,
288,
536,
534,
54,
1583,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
2495,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
12,
8437,
29,
797,
12,
3376,
63,
354,
534,
998,
3855,
355,
661,
14317,
63,
602,
297,
1709,
14,
4626,
8,
2495,
63,
2131,
29,
549,
12,
3376,
63,
354,
534,
602,
373,
5731,
3855,
355,
661,
711,
63,
1562,
297,
1709,
14,
9417,
26969,
4000,
355,
661,
5592,
297,
1709,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
86,
15866,
14,
9054,
3855,
288,
2156,
267,
2318,
267,
6180,
14,
18381,
8,
288,
1402,
63,
354,
534,
5095,
297,
288,
536,
534,
4790,
297,
288,
901,
29,
992,
14,
3190,
8,
265,
63,
1807,
29,
1176,
14,
697,
14,
992,
14,
14281,
14,
10855,
12,
370,
534,
86,
15866,
14,
16778,
659,
267,
2318,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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requests/packages/chardet/sbcsgroupprober.py
|
2936
|
3291
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Universal charset detector code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
# Shy Shalom - original C code
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
from .charsetgroupprober import CharSetGroupProber
from .sbcharsetprober import SingleByteCharSetProber
from .langcyrillicmodel import (Win1251CyrillicModel, Koi8rModel,
Latin5CyrillicModel, MacCyrillicModel,
Ibm866Model, Ibm855Model)
from .langgreekmodel import Latin7GreekModel, Win1253GreekModel
from .langbulgarianmodel import Latin5BulgarianModel, Win1251BulgarianModel
from .langhungarianmodel import Latin2HungarianModel, Win1250HungarianModel
from .langthaimodel import TIS620ThaiModel
from .langhebrewmodel import Win1255HebrewModel
from .hebrewprober import HebrewProber
class SBCSGroupProber(CharSetGroupProber):
def __init__(self):
CharSetGroupProber.__init__(self)
self._mProbers = [
SingleByteCharSetProber(Win1251CyrillicModel),
SingleByteCharSetProber(Koi8rModel),
SingleByteCharSetProber(Latin5CyrillicModel),
SingleByteCharSetProber(MacCyrillicModel),
SingleByteCharSetProber(Ibm866Model),
SingleByteCharSetProber(Ibm855Model),
SingleByteCharSetProber(Latin7GreekModel),
SingleByteCharSetProber(Win1253GreekModel),
SingleByteCharSetProber(Latin5BulgarianModel),
SingleByteCharSetProber(Win1251BulgarianModel),
SingleByteCharSetProber(Latin2HungarianModel),
SingleByteCharSetProber(Win1250HungarianModel),
SingleByteCharSetProber(TIS620ThaiModel),
]
hebrewProber = HebrewProber()
logicalHebrewProber = SingleByteCharSetProber(Win1255HebrewModel,
False, hebrewProber)
visualHebrewProber = SingleByteCharSetProber(Win1255HebrewModel, True,
hebrewProber)
hebrewProber.set_model_probers(logicalHebrewProber, visualHebrewProber)
self._mProbers.extend([hebrewProber, logicalHebrewProber,
visualHebrewProber])
self.reset()
|
lgpl-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,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
9264,
6043,
19903,
492,
13050,
21312,
199,
504,
1275,
4159,
17405,
1238,
492,
334,
8886,
21381,
9156,
11909,
1685,
12,
1804,
16142,
24,
82,
1685,
12,
1816,
23864,
21,
9156,
11909,
1685,
12,
10444,
9156,
11909,
1685,
12,
1816,
473,
12648,
13465,
1685,
12,
473,
12648,
12593,
1685,
9,
199,
504,
1275,
4159,
32007,
1238,
492,
23864,
23,
29480,
1685,
12,
13036,
28452,
29480,
1685,
199,
504,
1275,
4159,
25792,
71,
15289,
1238,
492,
23864,
21,
34,
27092,
15289,
1685,
12,
13036,
21381,
34,
27092,
15289,
1685,
199,
504,
1275,
4159,
72,
25364,
1238,
492,
23864,
18,
40,
25364,
1685,
12,
13036,
26572,
40,
25364,
1685,
199,
504,
1275,
4159,
24825,
1238,
492,
377,
1311,
22085,
52,
17945,
1685,
199,
504,
1275,
4159,
14557,
1238,
492,
13036,
20197,
1966,
15850,
1685,
199,
504,
1275,
14557,
19903,
492,
19771,
8029,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
13050,
21312,
8,
8886,
21381,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
43,
16142,
24,
82,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
3399,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
13465,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
12593,
1685,
395,
288,
13050,
21312,
8,
27317,
23,
29480,
1685,
395,
288,
13050,
21312,
8,
8886,
28452,
29480,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
8886,
21381,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
267,
1622,
267,
946,
15850,
8029,
275,
19771,
8029,
342,
267,
11461,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
10028,
756,
12,
946,
15850,
8029,
9,
267,
13104,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
9349,
946,
15850,
8029,
9,
267,
946,
15850,
8029,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
1966,
15850,
8029,
12,
13104,
1966,
15850,
8029,
9,
267,
291,
423,
77,
8029,
83,
14,
2880,
779,
14557,
8029,
12,
11461,
1966,
15850,
8029,
12,
3044,
13104,
1966,
15850,
8029,
566,
398,
291,
14,
3958,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
6043,
923,
19903,
492,
6659,
1084,
2448,
8029,
199,
504,
1275,
9264,
6043,
19903,
492,
13050,
21312,
199,
504,
1275,
4159,
17405,
1238,
492,
334,
8886,
21381,
9156,
11909,
1685,
12,
1804,
16142,
24,
82,
1685,
12,
1816,
23864,
21,
9156,
11909,
1685,
12,
10444,
9156,
11909,
1685,
12,
1816,
473,
12648,
13465,
1685,
12,
473,
12648,
12593,
1685,
9,
199,
504,
1275,
4159,
32007,
1238,
492,
23864,
23,
29480,
1685,
12,
13036,
28452,
29480,
1685,
199,
504,
1275,
4159,
25792,
71,
15289,
1238,
492,
23864,
21,
34,
27092,
15289,
1685,
12,
13036,
21381,
34,
27092,
15289,
1685,
199,
504,
1275,
4159,
72,
25364,
1238,
492,
23864,
18,
40,
25364,
1685,
12,
13036,
26572,
40,
25364,
1685,
199,
504,
1275,
4159,
24825,
1238,
492,
377,
1311,
22085,
52,
17945,
1685,
199,
504,
1275,
4159,
14557,
1238,
492,
13036,
20197,
1966,
15850,
1685,
199,
504,
1275,
14557,
19903,
492,
19771,
8029,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
6659,
1084,
2448,
8029,
855,
826,
721,
277,
9,
267,
291,
423,
77,
8029,
83,
275,
359,
288,
13050,
21312,
8,
8886,
21381,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
43,
16142,
24,
82,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
3399,
9156,
11909,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
13465,
1685,
395,
288,
13050,
21312,
8,
41,
12648,
12593,
1685,
395,
288,
13050,
21312,
8,
27317,
23,
29480,
1685,
395,
288,
13050,
21312,
8,
8886,
28452,
29480,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
8886,
21381,
34,
27092,
15289,
1685,
395,
288,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
267,
1622,
267,
946,
15850,
8029,
275,
19771,
8029,
342,
267,
11461,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
10028,
756,
12,
946,
15850,
8029,
9,
267,
13104,
1966,
15850,
8029,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
9349,
946,
15850,
8029,
9,
267,
946,
15850,
8029,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
1966,
15850,
8029,
12,
13104,
1966,
15850,
8029,
9,
267,
291,
423,
77,
8029,
83,
14,
2880,
779,
14557,
8029,
12,
11461,
1966,
15850,
8029,
12,
3044,
13104,
1966,
15850,
8029,
566,
398,
291,
14,
3958,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
WillGuan105/django
|
tests/admin_widgets/models.py
|
227
|
4760
|
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
class MyFileField(models.FileField):
pass
@python_2_unicode_compatible
class Member(models.Model):
name = models.CharField(max_length=100)
birthdate = models.DateTimeField(blank=True, null=True)
gender = models.CharField(max_length=1, blank=True, choices=[('M', 'Male'), ('F', 'Female')])
email = models.EmailField(blank=True)
def __str__(self):
return self.name
@python_2_unicode_compatible
class Band(models.Model):
name = models.CharField(max_length=100)
style = models.CharField(max_length=20)
members = models.ManyToManyField(Member)
def __str__(self):
return self.name
@python_2_unicode_compatible
class Album(models.Model):
band = models.ForeignKey(Band, models.CASCADE)
name = models.CharField(max_length=100)
cover_art = models.FileField(upload_to='albums')
backside_art = MyFileField(upload_to='albums_back', null=True)
def __str__(self):
return self.name
class HiddenInventoryManager(models.Manager):
def get_queryset(self):
return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False)
@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', models.SET_NULL, to_field='barcode', blank=True, null=True)
name = models.CharField(blank=False, max_length=20)
hidden = models.BooleanField(default=False)
# see #9258
default_manager = models.Manager()
objects = HiddenInventoryManager()
def __str__(self):
return self.name
class Event(models.Model):
main_band = models.ForeignKey(
Band,
models.CASCADE,
limit_choices_to=models.Q(pk__gt=0),
related_name='events_main_band_at',
)
supporting_bands = models.ManyToManyField(Band, blank=True, related_name='events_supporting_band_at')
start_date = models.DateField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
description = models.TextField(blank=True)
link = models.URLField(blank=True)
min_age = models.IntegerField(blank=True, null=True)
@python_2_unicode_compatible
class Car(models.Model):
owner = models.ForeignKey(User, models.CASCADE)
make = models.CharField(max_length=30)
model = models.CharField(max_length=30)
def __str__(self):
return "%s %s" % (self.make, self.model)
class CarTire(models.Model):
"""
A single car tire. This to test that a user can only select their own cars.
"""
car = models.ForeignKey(Car, models.CASCADE)
class Honeycomb(models.Model):
location = models.CharField(max_length=20)
class Bee(models.Model):
"""
A model with a FK to a model that won't be registered with the admin
(Honeycomb) so the corresponding raw ID widget won't have a magnifying
glass link to select related honeycomb instances.
"""
honeycomb = models.ForeignKey(Honeycomb, models.CASCADE)
class Individual(models.Model):
"""
A model with a FK to itself. It won't be registered with the admin, so the
corresponding raw ID widget won't have a magnifying glass link to select
related instances (rendering will be called programmatically in this case).
"""
name = models.CharField(max_length=20)
parent = models.ForeignKey('self', models.SET_NULL, null=True)
soulmate = models.ForeignKey('self', models.CASCADE, null=True, related_name='soulmates')
class Company(models.Model):
name = models.CharField(max_length=20)
class Advisor(models.Model):
"""
A model with a m2m to a model that won't be registered with the admin
(Company) so the corresponding raw ID widget won't have a magnifying
glass link to select related company instances.
"""
name = models.CharField(max_length=20)
companies = models.ManyToManyField(Company)
@python_2_unicode_compatible
class Student(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Meta:
ordering = ('name',)
@python_2_unicode_compatible
class School(models.Model):
name = models.CharField(max_length=255)
students = models.ManyToManyField(Student, related_name='current_schools')
alumni = models.ManyToManyField(Student, related_name='previous_schools')
def __str__(self):
return self.name
@python_2_unicode_compatible
class Profile(models.Model):
user = models.ForeignKey('auth.User', models.CASCADE, to_field='username')
def __str__(self):
return self.user.username
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
533,
4932,
23252,
8,
992,
14,
23252,
304,
272,
986,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
14409,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
21036,
602,
275,
1709,
14,
4626,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
24395,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
17,
12,
4596,
29,
549,
12,
3415,
11699,
45,
297,
283,
45,
1895,
659,
661,
38,
297,
283,
3456,
17667,
2023,
272,
3031,
275,
1709,
14,
16577,
8,
2500,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
27709,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
3449,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
272,
7556,
275,
1709,
14,
7624,
8,
7021,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
4580,
7767,
8,
992,
14,
1685,
304,
272,
10981,
275,
1709,
14,
3190,
8,
11675,
12,
1709,
14,
10855,
9,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
8486,
63,
580,
275,
1709,
14,
23252,
8,
5064,
63,
475,
534,
12110,
83,
358,
272,
1771,
2441,
63,
580,
275,
4932,
23252,
8,
5064,
63,
475,
534,
12110,
83,
63,
894,
297,
2973,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
26401,
19304,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
14983,
19304,
2988,
12,
291,
680,
362,
63,
7924,
1252,
1541,
8,
5642,
29,
797,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
19337,
8,
992,
14,
1685,
304,
272,
24323,
275,
1709,
14,
8591,
8,
3235,
29,
549,
9,
272,
1676,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
3597,
63,
8084,
12,
370,
63,
698,
534,
22091,
297,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
536,
275,
1709,
14,
2183,
8,
2500,
29,
797,
12,
1390,
63,
1267,
29,
1165,
9,
272,
8752,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
327,
1937,
327,
25,
12234,
272,
849,
63,
2609,
275,
1709,
14,
2988,
342,
272,
2251,
275,
26401,
19304,
2988,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
6763,
8,
992,
14,
1685,
304,
272,
2446,
63,
7877,
275,
1709,
14,
3190,
8,
267,
27709,
12,
267,
1709,
14,
10855,
12,
267,
2304,
63,
4577,
63,
475,
29,
992,
14,
49,
8,
2051,
363,
3308,
29,
16,
395,
267,
4048,
63,
354,
534,
4368,
63,
973,
63,
7877,
63,
292,
297,
272,
776,
272,
21038,
63,
23086,
275,
1709,
14,
7624,
8,
11675,
12,
4596,
29,
549,
12,
4048,
63,
354,
534,
4368,
63,
4058,
316,
63,
7877,
63,
292,
358,
272,
1343,
63,
602,
275,
1709,
14,
14071,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
1343,
63,
521,
275,
1709,
14,
27115,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
2142,
275,
1709,
14,
17363,
8,
2500,
29,
549,
9,
272,
1748,
63,
474,
275,
1709,
14,
3901,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
14243,
8,
992,
14,
1685,
304,
272,
5771,
275,
1709,
14,
3190,
8,
1899,
12,
1709,
14,
10855,
9,
272,
1852,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
272,
1402,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
1875,
12,
291,
14,
1238,
9,
421,
199,
533,
14243,
52,
3621,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
2849,
9590,
3367,
264,
14,
961,
370,
511,
626,
282,
922,
883,
1454,
3504,
3932,
5705,
286,
4291,
14,
272,
408,
272,
9590,
275,
1709,
14,
3190,
8,
16034,
12,
1709,
14,
10855,
9,
421,
199,
533,
869,
13234,
6560,
8,
992,
14,
1685,
304,
272,
2909,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
421,
199,
533,
699,
1024,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
1402,
543,
282,
18821,
370,
282,
1402,
626,
7859,
1133,
506,
7264,
543,
314,
4628,
272,
334,
40,
13234,
6560,
9,
880,
314,
5226,
3066,
2870,
3938,
7859,
1133,
1172,
282,
15916,
2021,
316,
272,
486,
4297,
2142,
370,
3504,
4048,
394,
13234,
6560,
4454,
14,
272,
408,
272,
394,
13234,
6560,
275,
1709,
14,
3190,
8,
40,
13234,
6560,
12,
1709,
14,
10855,
9,
421,
199,
533,
1010,
15067,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
1402,
543,
282,
18821,
370,
6337,
14,
2779,
7859,
1133,
506,
7264,
543,
314,
4628,
12,
880,
314,
272,
5226,
3066,
2870,
3938,
7859,
1133,
1172,
282,
15916,
2021,
316,
486,
4297,
2142,
370,
3504,
272,
4048,
4454,
334,
28228,
911,
506,
2797,
2240,
17174,
315,
642,
1930,
680,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
272,
1676,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
3597,
63,
8084,
12,
2973,
29,
549,
9,
272,
880,
348,
17684,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
10855,
12,
2973,
29,
549,
12,
4048,
63,
354,
534,
1152,
348,
77,
2335,
358,
421,
199,
533,
15878,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
421,
199,
533,
4431,
8286,
8,
992,
14,
1685,
304
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
1208,
14,
2991,
492,
2366,
63,
18,
63,
2975,
63,
6490,
421,
199,
533,
4932,
23252,
8,
992,
14,
23252,
304,
272,
986,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
14409,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
21036,
602,
275,
1709,
14,
4626,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
24395,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
17,
12,
4596,
29,
549,
12,
3415,
11699,
45,
297,
283,
45,
1895,
659,
661,
38,
297,
283,
3456,
17667,
2023,
272,
3031,
275,
1709,
14,
16577,
8,
2500,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
27709,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
3449,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
272,
7556,
275,
1709,
14,
7624,
8,
7021,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
4580,
7767,
8,
992,
14,
1685,
304,
272,
10981,
275,
1709,
14,
3190,
8,
11675,
12,
1709,
14,
10855,
9,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
9,
272,
8486,
63,
580,
275,
1709,
14,
23252,
8,
5064,
63,
475,
534,
12110,
83,
358,
272,
1771,
2441,
63,
580,
275,
4932,
23252,
8,
5064,
63,
475,
534,
12110,
83,
63,
894,
297,
2973,
29,
549,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
26401,
19304,
2988,
8,
992,
14,
2988,
304,
272,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
14983,
19304,
2988,
12,
291,
680,
362,
63,
7924,
1252,
1541,
8,
5642,
29,
797,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
19337,
8,
992,
14,
1685,
304,
272,
24323,
275,
1709,
14,
8591,
8,
3235,
29,
549,
9,
272,
1676,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
3597,
63,
8084,
12,
370,
63,
698,
534,
22091,
297,
4596,
29,
549,
12,
2973,
29,
549,
9,
272,
536,
275,
1709,
14,
2183,
8,
2500,
29,
797,
12,
1390,
63,
1267,
29,
1165,
9,
272,
8752,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
327,
1937,
327,
25,
12234,
272,
849,
63,
2609,
275,
1709,
14,
2988,
342,
272,
2251,
275,
26401,
19304,
2988,
342,
339,
347,
636,
495,
721,
277,
304,
267,
372,
291,
14,
354,
421,
199,
533,
6763,
8,
992,
14,
1685,
304,
272,
2446,
63,
7877,
275,
1709,
14,
3190,
8,
267,
27709,
12,
267,
1709,
14,
10855,
12,
267,
2304,
63,
4577,
63,
475,
29,
992,
14,
49,
8,
2051,
363,
3308,
29,
16,
395,
267,
4048,
63,
354,
534,
4368,
63,
973,
63,
7877,
63,
292,
297,
272,
776,
272,
21038,
63,
23086,
275,
1709,
14,
7624,
8,
11675,
12,
4596,
29,
549,
12,
4048,
63,
354,
534,
4368,
63,
4058,
316,
63,
7877,
63,
292,
358,
272,
1343,
63,
602,
275,
1709,
14,
14071,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
1343,
63,
521,
275,
1709,
14,
27115,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
272,
1369,
275,
1709,
14,
6254,
8,
2500,
29,
549,
9,
272,
2142,
275,
1709,
14,
17363,
8,
2500,
29,
549,
9,
272,
1748,
63,
474,
275,
1709,
14,
3901,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
421,
199,
32,
1548,
63,
18,
63,
2975,
63,
6490,
199,
533,
14243,
8,
992,
14,
1685,
304,
272,
5771,
275,
1709,
14,
3190,
8,
1899,
12,
1709,
14,
10855,
9,
272,
1852,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
272,
1402,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1216,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
2071,
83,
450,
83,
2,
450,
334,
277,
14,
1875,
12,
291,
14,
1238,
9,
421,
199,
533,
14243,
52,
3621,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
2849,
9590,
3367,
264,
14,
961,
370,
511,
626,
282,
922,
883,
1454,
3504,
3932,
5705,
286,
4291,
14,
272,
408,
272,
9590,
275,
1709,
14,
3190,
8,
16034,
12,
1709,
14,
10855,
9,
421,
199,
533,
869,
13234,
6560,
8,
992,
14,
1685,
304,
272,
2909,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
421,
199,
533,
699,
1024,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
1402,
543,
282,
18821,
370,
282,
1402,
626,
7859,
1133,
506,
7264,
543,
314,
4628,
272,
334,
40,
13234,
6560,
9,
880,
314,
5226,
3066,
2870,
3938,
7859,
1133,
1172,
282,
15916,
2021,
316,
272,
486,
4297,
2142,
370,
3504,
4048,
394,
13234,
6560,
4454,
14,
272,
408,
272,
394,
13234,
6560,
275,
1709,
14,
3190,
8,
40,
13234,
6560,
12,
1709,
14,
10855,
9,
421,
199,
533,
1010,
15067,
8,
992,
14,
1685,
304,
272,
408,
272,
437,
1402,
543,
282,
18821,
370,
6337,
14,
2779,
7859,
1133,
506,
7264,
543,
314,
4628,
12,
880,
314,
272,
5226,
3066,
2870,
3938,
7859,
1133,
1172,
282,
15916,
2021,
316,
486,
4297,
2142,
370,
3504,
272,
4048,
4454,
334,
28228,
911,
506,
2797,
2240,
17174,
315,
642,
1930,
680,
272,
408,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
272,
1676,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
3597,
63,
8084,
12,
2973,
29,
549,
9,
272,
880,
348,
17684,
275,
1709,
14,
3190,
360,
277,
297,
1709,
14,
10855,
12,
2973,
29,
549,
12,
4048,
63,
354,
534,
1152,
348,
77,
2335,
358,
421,
199,
533,
15878,
8,
992,
14,
1685,
304,
272,
536,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1165,
9,
421,
199,
533,
4431,
8286,
8,
992,
14,
1685,
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