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
|
|---|---|---|---|---|---|---|---|---|
jhbsz/OSI-OS
|
crypto/heimdal/lib/wind/UnicodeData.py
|
82
|
2167
|
#!/usr/local/bin/python
# -*- coding: iso-8859-1 -*-
# $Id$
# Copyright (c) 2004 Kungliga Tekniska Högskolan
# (Royal Institute of Technology, Stockholm, Sweden).
# 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.
#
# 3. Neither the name of the Institute 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 INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
import re
import string
def read(filename):
"""return a dict of unicode characters"""
ud = open(filename, 'r')
ret = {}
while True:
l = ud.readline()
if not l:
break
l = re.sub('#.*$', '', l)
if l == "\n":
continue
f = l.split(';')
key = int(f[0], 0x10)
if key in ret:
raise Exception('Duplicate key in UnicodeData')
ret[key] = f[1:]
ud.close()
return ret
|
bsd-3-clause
|
[
3381,
2647,
15,
1832,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
3,
2672,
1304,
4,
199,
199,
3,
1898,
334,
67,
9,
8353,
1804,
10335,
317,
5294,
377,
5711,
26294,
7351,
869,
14614,
458,
75,
393,
290,
199,
3,
334,
3863,
31876,
1010,
25585,
402,
21580,
12,
28406,
24588,
77,
12,
428,
1129,
848,
680,
221,
199,
3,
2900,
4481,
4644,
14,
221,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
221,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
221,
199,
3,
787,
7647,
26,
221,
199,
3,
221,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
221,
199,
3,
221,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
221,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
221,
199,
3,
221,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
1010,
25585,
6590,
314,
1561,
402,
2399,
8417,
221,
199,
3,
259,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
221,
199,
3,
259,
1928,
2488,
6791,
5313,
4983,
14,
221,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
1621,
8895,
2401,
6483,
1124,
1179,
2281,
891,
2401,
221,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
221,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
221,
199,
3,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
1621,
8895,
1549,
6483,
6262,
7024,
221,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
221,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
221,
199,
3,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
221,
199,
3,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
221,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
221,
199,
3,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
221,
199,
3,
9712,
9784,
14,
9948,
199,
646,
295,
199,
646,
1059,
199,
199,
318,
1586,
8,
1501,
304,
272,
408,
1107,
282,
1211,
402,
2649,
4110,
624,
272,
26759,
275,
1551,
8,
1501,
12,
283,
82,
358,
272,
2203,
275,
1052,
272,
1830,
715,
26,
267,
634,
275,
26759,
14,
6407,
342,
267,
340,
440,
634,
26,
288,
2059,
267,
634,
275,
295,
14,
954,
7863,
2795,
4268,
3260,
634,
9,
267,
340,
634,
508,
1867,
78,
582,
288,
1980,
267,
289,
275,
634,
14,
1294,
26468,
267,
790,
275,
1109,
8,
70,
59,
16,
467,
378,
88,
709,
9,
199,
198,
692,
790,
315,
2203,
26,
288,
746,
2186,
360,
14773,
790,
315,
6140,
1451,
358,
267,
2203,
59,
498,
61,
275,
289,
59,
17,
2938,
272,
26759,
14,
1600,
342,
272,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1832,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
11601,
13,
4830,
13,
17,
1882,
199,
199,
3,
2672,
1304,
4,
199,
199,
3,
1898,
334,
67,
9,
8353,
1804,
10335,
317,
5294,
377,
5711,
26294,
7351,
869,
14614,
458,
75,
393,
290,
199,
3,
334,
3863,
31876,
1010,
25585,
402,
21580,
12,
28406,
24588,
77,
12,
428,
1129,
848,
680,
221,
199,
3,
2900,
4481,
4644,
14,
221,
199,
3,
221,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
221,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
221,
199,
3,
787,
7647,
26,
221,
199,
3,
221,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
221,
199,
3,
221,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
221,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
221,
199,
3,
259,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
221,
199,
3,
221,
199,
3,
650,
14,
11443,
314,
536,
402,
314,
1010,
25585,
6590,
314,
1561,
402,
2399,
8417,
221,
199,
3,
259,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
221,
199,
3,
259,
1928,
2488,
6791,
5313,
4983,
14,
221,
199,
3,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
1621,
8895,
2401,
6483,
1124,
1179,
2281,
891,
2401,
221,
199,
3,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
221,
199,
3,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
3104,
221,
199,
3,
9315,
9706,
14,
221,
1621,
4825,
6461,
7000,
2334,
1621,
8895,
1549,
6483,
6262,
7024,
221,
199,
3,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
221,
199,
3,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
221,
199,
3,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
221,
199,
3,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
221,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
221,
199,
3,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
221,
199,
3,
9712,
9784,
14,
9948,
199,
646,
295,
199,
646,
1059,
199,
199,
318,
1586,
8,
1501,
304,
272,
408,
1107,
282,
1211,
402,
2649,
4110,
624,
272,
26759,
275,
1551,
8,
1501,
12,
283,
82,
358,
272,
2203,
275,
1052,
272,
1830,
715,
26,
267,
634,
275,
26759,
14,
6407,
342,
267,
340,
440,
634,
26,
288,
2059,
267,
634,
275,
295,
14,
954,
7863,
2795,
4268,
3260,
634,
9,
267,
340,
634,
508,
1867,
78,
582,
288,
1980,
267,
289,
275,
634,
14,
1294,
26468,
267,
790,
275,
1109,
8,
70,
59,
16,
467,
378,
88,
709,
9,
199,
198,
692,
790,
315,
2203,
26,
288,
746,
2186,
360,
14773,
790,
315,
6140,
1451,
358,
267,
2203,
59,
498,
61,
275,
289,
59,
17,
2938,
272,
26759,
14,
1600,
342,
272,
372,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmartinezchaine/OpenERP
|
openerp/addons/base_calendar/__openerp__.py
|
9
|
2127
|
# -*- 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": "Calendar Layer",
"version": "1.0",
"depends": ["base", "mail"],
'complexity': "easy",
'description': """
This is a full-featured calendar system.
========================================
It supports:
- Calendar of events
- Alerts (create requests)
- Recurring events
- Invitations to people
If you need to manage your meetings, you should install the CRM module.
""",
"author": "OpenERP SA",
'category': 'Hidden/Dependency',
'website': 'http://www.openerp.com',
"init_xml": [
'base_calendar_data.xml'
],
"demo_xml": [],
"update_xml": [
'security/calendar_security.xml',
'security/ir.model.access.csv',
'wizard/base_calendar_invite_attendee_view.xml',
'base_calendar_view.xml'
],
"test" : ['test/base_calendar_test.yml'],
"installable": True,
"auto_install": False,
"certificate": "00694071962960352821",
'images': ['images/base_calendar1.jpeg','images/base_calendar2.jpeg','images/base_calendar3.jpeg','images/base_calendar4.jpeg',],
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
582,
298,
18688,
11915,
401,
272,
298,
1023,
582,
298,
17,
14,
16,
401,
272,
298,
8912,
582,
2097,
1095,
401,
298,
1198,
2255,
272,
283,
5254,
1209,
356,
298,
13581,
401,
272,
283,
1802,
356,
408,
199,
2765,
365,
282,
2615,
13,
30779,
11234,
2656,
14,
199,
2486,
763,
199,
199,
7940,
5171,
26,
272,
446,
27779,
402,
4474,
272,
446,
437,
16676,
334,
981,
4145,
9,
272,
446,
18306,
5985,
4474,
272,
446,
30110,
390,
1298,
370,
13135,
199,
199,
3917,
1265,
1929,
370,
9635,
2195,
26743,
780,
12,
1265,
1077,
3907,
314,
445,
11026,
859,
14,
272,
10327,
272,
298,
2502,
582,
298,
25347,
13950,
401,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
298,
826,
63,
1652,
582,
359,
267,
283,
1095,
63,
8183,
63,
576,
14,
1652,
7,
272,
2156,
272,
298,
8768,
63,
1652,
582,
990,
272,
298,
873,
63,
1652,
582,
359,
267,
283,
4416,
15,
8183,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9819,
15,
1095,
63,
8183,
63,
19061,
63,
30469,
63,
1345,
14,
1652,
297,
267,
283,
1095,
63,
8183,
63,
1345,
14,
1652,
7,
272,
2156,
272,
298,
396,
2,
520,
788,
396,
15,
1095,
63,
8183,
63,
396,
14,
11714,
995,
272,
298,
21762,
582,
715,
12,
272,
298,
2495,
63,
3174,
582,
756,
12,
272,
298,
6999,
582,
298,
28815,
12641,
10800,
1398,
2259,
1276,
1651,
2025,
401,
272,
283,
4782,
356,
788,
4782,
15,
1095,
63,
8183,
17,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
18,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
19,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
20,
14,
14230,
297,
467,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
91,
272,
298,
354,
582,
298,
18688,
11915,
401,
272,
298,
1023,
582,
298,
17,
14,
16,
401,
272,
298,
8912,
582,
2097,
1095,
401,
298,
1198,
2255,
272,
283,
5254,
1209,
356,
298,
13581,
401,
272,
283,
1802,
356,
408,
199,
2765,
365,
282,
2615,
13,
30779,
11234,
2656,
14,
199,
2486,
763,
199,
199,
7940,
5171,
26,
272,
446,
27779,
402,
4474,
272,
446,
437,
16676,
334,
981,
4145,
9,
272,
446,
18306,
5985,
4474,
272,
446,
30110,
390,
1298,
370,
13135,
199,
199,
3917,
1265,
1929,
370,
9635,
2195,
26743,
780,
12,
1265,
1077,
3907,
314,
445,
11026,
859,
14,
272,
10327,
272,
298,
2502,
582,
298,
25347,
13950,
401,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
298,
826,
63,
1652,
582,
359,
267,
283,
1095,
63,
8183,
63,
576,
14,
1652,
7,
272,
2156,
272,
298,
8768,
63,
1652,
582,
990,
272,
298,
873,
63,
1652,
582,
359,
267,
283,
4416,
15,
8183,
63,
4416,
14,
1652,
297,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
9819,
15,
1095,
63,
8183,
63,
19061,
63,
30469,
63,
1345,
14,
1652,
297,
267,
283,
1095,
63,
8183,
63,
1345,
14,
1652,
7,
272,
2156,
272,
298,
396,
2,
520,
788,
396,
15,
1095,
63,
8183,
63,
396,
14,
11714,
995,
272,
298,
21762,
582,
715,
12,
272,
298,
2495,
63,
3174,
582,
756,
12,
272,
298,
6999,
582,
298,
28815,
12641,
10800,
1398,
2259,
1276,
1651,
2025,
401,
272,
283,
4782,
356,
788,
4782,
15,
1095,
63,
8183,
17,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
18,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
19,
14,
14230,
1673,
4782,
15,
1095,
63,
8183,
20,
14,
14230,
297,
467,
199,
93,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bzennn/blog_flask
|
python/lib/python3.5/site-packages/gunicorn/workers/sync.py
|
40
|
7153
|
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
#
from datetime import datetime
import errno
import os
import select
import socket
import ssl
import sys
import gunicorn.http as http
import gunicorn.http.wsgi as wsgi
import gunicorn.util as util
import gunicorn.workers.base as base
from gunicorn import six
class StopWaiting(Exception):
""" exception raised to stop waiting for a connnection """
class SyncWorker(base.Worker):
def accept(self, listener):
client, addr = listener.accept()
client.setblocking(1)
util.close_on_exec(client)
self.handle(listener, client, addr)
def wait(self, timeout):
try:
self.notify()
ret = select.select(self.wait_fds, [], [], timeout)
if ret[0]:
if self.PIPE[0] in ret[0]:
os.read(self.PIPE[0], 1)
return ret[0]
except select.error as e:
if e.args[0] == errno.EINTR:
return self.sockets
if e.args[0] == errno.EBADF:
if self.nr < 0:
return self.sockets
else:
raise StopWaiting
raise
def is_parent_alive(self):
# If our parent changed then we shut down.
if self.ppid != os.getppid():
self.log.info("Parent changed, shutting down: %s", self)
return False
return True
def run_for_one(self, timeout):
listener = self.sockets[0]
while self.alive:
self.notify()
# Accept a connection. If we get an error telling us
# that no connection is waiting we fall down to the
# select which is where we'll wait for a bit for new
# workers to come give us some love.
try:
self.accept(listener)
# Keep processing clients until no one is waiting. This
# prevents the need to select() for every client that we
# process.
continue
except EnvironmentError as e:
if e.errno not in (errno.EAGAIN, errno.ECONNABORTED,
errno.EWOULDBLOCK):
raise
if not self.is_parent_alive():
return
try:
self.wait(timeout)
except StopWaiting:
return
def run_for_multiple(self, timeout):
while self.alive:
self.notify()
try:
ready = self.wait(timeout)
except StopWaiting:
return
if ready is not None:
for listener in ready:
if listener == self.PIPE[0]:
continue
try:
self.accept(listener)
except EnvironmentError as e:
if e.errno not in (errno.EAGAIN, errno.ECONNABORTED,
errno.EWOULDBLOCK):
raise
if not self.is_parent_alive():
return
def run(self):
# if no timeout is given the worker will never wait and will
# use the CPU for nothing. This minimal timeout prevent it.
timeout = self.timeout or 0.5
# self.socket appears to lose its blocking status after
# we fork in the arbiter. Reset it here.
for s in self.sockets:
s.setblocking(0)
if len(self.sockets) > 1:
self.run_for_multiple(timeout)
else:
self.run_for_one(timeout)
def handle(self, listener, client, addr):
req = None
try:
if self.cfg.is_ssl:
client = ssl.wrap_socket(client, server_side=True,
**self.cfg.ssl_options)
parser = http.RequestParser(self.cfg, client)
req = six.next(parser)
self.handle_request(listener, req, client, addr)
except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e)
except StopIteration as e:
self.log.debug("Closing connection. %s", e)
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_EOF:
self.log.debug("ssl connection closed")
client.close()
else:
self.log.debug("Error processing SSL request.")
self.handle_error(req, client, addr, e)
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring EPIPE")
except Exception as e:
self.handle_error(req, client, addr, e)
finally:
util.close(client)
def handle_request(self, listener, req, client, addr):
environ = {}
resp = None
try:
self.cfg.pre_request(self, req)
request_start = datetime.now()
resp, environ = wsgi.create(req, client, addr,
listener.getsockname(), self.cfg)
# Force the connection closed until someone shows
# a buffering proxy that supports Keep-Alive to
# the backend.
resp.force_close()
self.nr += 1
if self.nr >= self.max_requests:
self.log.info("Autorestarting worker after current request.")
self.alive = False
respiter = self.wsgi(environ, resp.start_response)
try:
if isinstance(respiter, environ['wsgi.file_wrapper']):
resp.write_file(respiter)
else:
for item in respiter:
resp.write(item)
resp.close()
request_time = datetime.now() - request_start
self.log.access(resp, req, environ, request_time)
finally:
if hasattr(respiter, "close"):
respiter.close()
except EnvironmentError:
# pass to next try-except level
six.reraise(*sys.exc_info())
except Exception:
if resp and resp.headers_sent:
# If the requests have already been sent, we should close the
# connection to indicate the error.
self.log.exception("Error handling request")
try:
client.shutdown(socket.SHUT_RDWR)
client.close()
except EnvironmentError:
pass
raise StopIteration()
raise
finally:
try:
self.cfg.post_request(self, req, environ, resp)
except Exception:
self.log.exception("Exception in post_request hook")
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
446,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
486,
29067,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
12840,
367,
1655,
2556,
14,
199,
3,
199,
199,
504,
2197,
492,
2197,
199,
646,
7554,
199,
646,
747,
199,
646,
3504,
199,
646,
2838,
199,
646,
6149,
199,
646,
984,
199,
199,
646,
486,
29067,
14,
1014,
465,
1455,
199,
646,
486,
29067,
14,
1014,
14,
6508,
465,
12464,
199,
646,
486,
29067,
14,
1974,
465,
4884,
199,
646,
486,
29067,
14,
11009,
14,
1095,
465,
1300,
199,
504,
486,
29067,
492,
3816,
199,
199,
533,
8015,
19189,
8,
1726,
304,
272,
408,
1919,
4915,
370,
3631,
10923,
367,
282,
2557,
1112,
408,
199,
199,
533,
22407,
12678,
8,
1095,
14,
12678,
304,
339,
347,
4729,
8,
277,
12,
11647,
304,
267,
1890,
12,
5552,
275,
11647,
14,
5694,
342,
267,
1890,
14,
409,
13091,
8,
17,
9,
267,
4884,
14,
1600,
63,
265,
63,
1628,
8,
1258,
9,
267,
291,
14,
2479,
8,
9799,
12,
1890,
12,
5552,
9,
339,
347,
3618,
8,
277,
12,
2653,
304,
267,
862,
26,
288,
291,
14,
6814,
342,
288,
2203,
275,
3504,
14,
2416,
8,
277,
14,
2573,
63,
14240,
12,
990,
990,
2653,
9,
288,
340,
2203,
59,
16,
2189,
355,
340,
291,
14,
6089,
59,
16,
61,
315,
2203,
59,
16,
2189,
490,
747,
14,
739,
8,
277,
14,
6089,
59,
16,
467,
413,
9,
355,
372,
2203,
59,
16,
61,
398,
871,
3504,
14,
705,
465,
325,
26,
288,
340,
325,
14,
589,
59,
16,
61,
508,
7554,
14,
37,
19652,
26,
355,
372,
291,
14,
20517,
288,
340,
325,
14,
589,
59,
16,
61,
508,
7554,
14,
37,
9439,
38,
26,
355,
340,
291,
14,
7865,
665,
378,
26,
490,
372,
291,
14,
20517,
355,
587,
26,
490,
746,
8015,
19189,
288,
746,
339,
347,
365,
63,
1708,
63,
9631,
8,
277,
304,
267,
327,
982,
4154,
1676,
2896,
2066,
781,
24761,
3224,
14,
267,
340,
291,
14,
802,
344,
1137,
747,
14,
362,
802,
344,
837,
288,
291,
14,
793,
14,
815,
480,
6652,
2896,
12,
24761,
1337,
3224,
26,
450,
83,
401,
291,
9,
288,
372,
756,
267,
372,
715,
339,
347,
1255,
63,
509,
63,
368,
8,
277,
12,
2653,
304,
267,
11647,
275,
291,
14,
20517,
59,
16,
61,
267,
1830,
291,
14,
9631,
26,
288,
291,
14,
6814,
342,
953,
327,
15506,
282,
1950,
14,
982,
781,
664,
376,
1125,
1565,
10564,
2739,
288,
327,
626,
949,
1950,
365,
10923,
781,
11264,
3224,
370,
314,
288,
327,
3504,
1314,
365,
2382,
781,
7171,
3618,
367,
282,
4546,
367,
892,
288,
327,
14123,
370,
11492,
8120,
2739,
2005,
560,
432,
14,
288,
862,
26,
355,
291,
14,
5694,
8,
9799,
9,
355,
327,
14797,
6661,
13431,
5133,
949,
1373,
365,
10923,
14,
961,
355,
327,
21925,
314,
1929,
370,
3504,
342,
367,
4036,
1890,
626,
781,
355,
327,
2112,
14,
355,
1980,
953,
871,
25139,
465,
325,
26,
355,
340,
325,
14,
7931,
440,
315,
334,
7931,
14,
37,
1254,
9021,
12,
7554,
14,
37,
17489,
27113,
1149,
12,
717,
7554,
14,
37,
11325,
1293,
2846,
4406,
304,
490,
746,
953,
340,
440,
291,
14,
374,
63,
1708,
63,
9631,
837,
355,
372,
953,
862,
26,
355,
291,
14,
2573,
8,
2593,
9,
288,
871,
8015,
19189,
26,
355,
372,
339,
347,
1255,
63,
509,
63,
6048,
8,
277,
12,
2653,
304,
267,
1830,
291,
14,
9631,
26,
288,
291,
14,
6814,
342,
953,
862,
26,
355,
10144,
275,
291,
14,
2573,
8,
2593,
9,
288,
871,
8015,
19189,
26,
355,
372,
953,
340,
10144,
365,
440,
488,
26,
355,
367,
11647,
315,
10144,
26,
490,
340,
11647,
508,
291,
14,
6089,
59,
16,
2189,
717,
1980,
4951,
862,
26,
717,
291,
14,
5694,
8,
9799,
9,
490,
871,
25139,
465,
325,
26,
717,
340,
325,
14,
7931,
440,
315,
334,
7931,
14,
37,
1254,
9021,
12,
7554,
14,
37,
17489,
27113,
1149,
12,
1816,
7554,
14,
37,
11325,
1293,
2846,
4406,
304,
1169,
746,
953,
340,
440,
291,
14,
374,
63,
1708,
63,
9631,
837,
355,
372,
339,
347,
1255,
8,
277,
304,
267,
327,
340,
949,
2653,
365,
1627,
314,
7239,
911,
7078,
3618,
436,
911,
267,
327,
675,
314,
11952,
367,
6548,
14,
961,
13460,
2653,
7981,
652,
14,
267,
2653,
275,
291,
14,
2593,
503,
378,
14,
21,
398,
327,
291,
14,
3450,
11337,
370,
27332,
2399,
14592,
2004,
2410,
267,
327,
781,
14926,
315,
314,
601,
66,
1661,
14,
15510,
652,
2348,
14,
267,
367,
308,
315,
291,
14,
20517,
26,
288,
308,
14,
409,
13091,
8,
16,
9,
398,
340,
822,
8,
277,
14,
20517,
9,
690,
413,
26,
288,
291,
14,
1065,
63,
509,
63,
6048,
8,
2593,
9,
267,
587,
26,
288,
291,
14,
1065,
63,
509,
63,
368,
8,
2593,
9,
339,
347,
2429,
8,
277,
12,
11647,
12,
1890,
12,
5552,
304,
267,
2648,
275,
488,
267,
862,
26,
288,
340,
291,
14,
4128,
14,
374,
63,
4266,
26,
355,
1890,
275,
6149,
14,
3823,
63,
3450,
8,
1258,
12,
1654,
63,
2441,
29,
549,
12,
490,
1011,
277,
14,
4128,
14,
4266,
63,
1419,
9,
953,
1798,
275,
1455,
14,
2017,
2842,
8,
277,
14,
4128,
12,
1890,
9,
288,
2648,
275,
3816,
14,
2184,
8,
2087,
9,
288,
291,
14,
2479,
63,
1069,
8,
9799,
12,
2648,
12,
1890,
12,
5552,
9,
267,
871,
1455,
14,
2550,
14,
1944,
11053,
1451,
465,
325,
26,
288,
291,
14,
793,
14,
1757,
480,
19399,
2908,
876,
19925,
1890,
2153,
2105,
14,
450,
83,
401,
325,
9,
267,
871,
10852,
465,
325,
26,
288,
291,
14,
793,
14,
1757,
480,
18433,
1950,
14,
450,
83,
401,
325,
9,
267,
871,
6149,
14,
27102,
465,
325,
26,
288,
340,
325,
14,
589,
59,
16,
61,
508,
6149,
14,
5413,
63,
3170,
63,
13178,
26,
355,
291,
14,
793,
14,
1757,
480,
4266,
1950,
6876,
531,
355,
1890,
14,
1600,
342,
288,
587,
26,
355,
291,
14,
793,
14,
1757,
480,
547,
6661,
7799,
1056,
2685,
355,
291,
14,
2479,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
446,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
486,
29067,
14286,
1334,
314,
10697,
4190,
14,
199,
3,
1666,
314,
12840,
367,
1655,
2556,
14,
199,
3,
199,
199,
504,
2197,
492,
2197,
199,
646,
7554,
199,
646,
747,
199,
646,
3504,
199,
646,
2838,
199,
646,
6149,
199,
646,
984,
199,
199,
646,
486,
29067,
14,
1014,
465,
1455,
199,
646,
486,
29067,
14,
1014,
14,
6508,
465,
12464,
199,
646,
486,
29067,
14,
1974,
465,
4884,
199,
646,
486,
29067,
14,
11009,
14,
1095,
465,
1300,
199,
504,
486,
29067,
492,
3816,
199,
199,
533,
8015,
19189,
8,
1726,
304,
272,
408,
1919,
4915,
370,
3631,
10923,
367,
282,
2557,
1112,
408,
199,
199,
533,
22407,
12678,
8,
1095,
14,
12678,
304,
339,
347,
4729,
8,
277,
12,
11647,
304,
267,
1890,
12,
5552,
275,
11647,
14,
5694,
342,
267,
1890,
14,
409,
13091,
8,
17,
9,
267,
4884,
14,
1600,
63,
265,
63,
1628,
8,
1258,
9,
267,
291,
14,
2479,
8,
9799,
12,
1890,
12,
5552,
9,
339,
347,
3618,
8,
277,
12,
2653,
304,
267,
862,
26,
288,
291,
14,
6814,
342,
288,
2203,
275,
3504,
14,
2416,
8,
277,
14,
2573,
63,
14240,
12,
990,
990,
2653,
9,
288,
340,
2203,
59,
16,
2189,
355,
340,
291,
14,
6089,
59,
16,
61,
315,
2203,
59,
16,
2189,
490,
747,
14,
739,
8,
277,
14,
6089,
59,
16,
467,
413,
9,
355,
372,
2203,
59,
16,
61,
398,
871,
3504,
14,
705,
465,
325,
26,
288,
340,
325,
14,
589,
59,
16,
61,
508,
7554,
14,
37,
19652,
26,
355,
372,
291,
14,
20517,
288,
340,
325,
14,
589,
59,
16,
61,
508,
7554,
14,
37,
9439,
38,
26,
355,
340,
291,
14,
7865,
665,
378,
26,
490,
372,
291,
14,
20517,
355,
587,
26,
490,
746,
8015,
19189,
288,
746,
339,
347,
365,
63,
1708,
63,
9631,
8,
277,
304,
267,
327,
982,
4154,
1676,
2896,
2066,
781,
24761,
3224,
14,
267,
340,
291,
14,
802,
344,
1137,
747,
14,
362,
802,
344,
837,
288,
291,
14,
793,
14,
815,
480,
6652,
2896,
12,
24761,
1337,
3224,
26,
450,
83,
401,
291,
9,
288,
372,
756,
267,
372,
715,
339,
347,
1255,
63,
509,
63,
368,
8,
277,
12,
2653,
304,
267,
11647,
275,
291,
14,
20517,
59,
16,
61,
267,
1830,
291,
14,
9631,
26,
288,
291,
14,
6814,
342,
953,
327,
15506,
282,
1950,
14,
982,
781,
664,
376,
1125,
1565,
10564,
2739,
288,
327,
626,
949,
1950,
365,
10923,
781,
11264,
3224,
370,
314,
288,
327,
3504,
1314,
365,
2382,
781,
7171,
3618,
367,
282,
4546,
367,
892,
288,
327,
14123,
370,
11492,
8120,
2739,
2005,
560,
432,
14,
288,
862,
26,
355,
291,
14,
5694,
8,
9799,
9,
355,
327,
14797,
6661,
13431,
5133,
949,
1373,
365,
10923,
14,
961,
355,
327,
21925,
314,
1929,
370,
3504,
342,
367,
4036,
1890,
626,
781,
355,
327,
2112,
14,
355,
1980,
953,
871,
25139,
465,
325,
26,
355,
340,
325,
14,
7931,
440,
315,
334,
7931,
14,
37,
1254,
9021,
12,
7554,
14,
37,
17489,
27113,
1149,
12,
717,
7554,
14,
37,
11325,
1293,
2846,
4406,
304,
490,
746,
953,
340,
440,
291,
14,
374,
63,
1708,
63,
9631,
837,
355,
372,
953,
862,
26,
355,
291,
14,
2573,
8,
2593,
9,
288,
871,
8015,
19189,
26,
355,
372,
339,
347,
1255,
63,
509,
63,
6048,
8,
277,
12,
2653,
304,
267,
1830,
291,
14,
9631,
26,
288,
291,
14,
6814,
342,
953,
862,
26,
355,
10144,
275,
291,
14,
2573,
8,
2593,
9,
288,
871,
8015,
19189,
26,
355,
372,
953,
340,
10144,
365,
440,
488,
26,
355,
367,
11647,
315,
10144,
26,
490,
340,
11647,
508,
291,
14,
6089,
59,
16,
2189,
717,
1980,
4951,
862,
26,
717,
291,
14,
5694,
8,
9799,
9,
490,
871,
25139,
465,
325,
26,
717,
340,
325,
14,
7931,
440,
315,
334,
7931,
14,
37,
1254,
9021,
12,
7554,
14,
37,
17489,
27113,
1149,
12,
1816,
7554,
14,
37,
11325,
1293,
2846,
4406,
304,
1169,
746,
953,
340,
440,
291,
14,
374,
63,
1708,
63,
9631,
837,
355,
372,
339,
347,
1255,
8,
277,
304,
267,
327,
340,
949,
2653,
365,
1627,
314,
7239,
911,
7078,
3618,
436,
911,
267,
327,
675,
314,
11952,
367,
6548,
14,
961,
13460,
2653,
7981,
652,
14,
267,
2653,
275,
291,
14,
2593,
503,
378,
14,
21,
398,
327,
291,
14,
3450,
11337,
370,
27332,
2399,
14592,
2004,
2410,
267,
327,
781,
14926,
315,
314,
601,
66,
1661,
14,
15510,
652,
2348,
14,
267,
367,
308,
315,
291,
14,
20517,
26,
288,
308,
14,
409,
13091,
8,
16,
9,
398,
340,
822,
8,
277,
14,
20517,
9,
690,
413,
26,
288,
291,
14,
1065,
63,
509,
63,
6048,
8,
2593,
9,
267,
587,
26,
288,
291,
14,
1065,
63,
509,
63,
368,
8,
2593,
9,
339,
347,
2429,
8,
277,
12,
11647,
12,
1890,
12,
5552,
304,
267,
2648,
275,
488,
267,
862,
26,
288,
340,
291,
14,
4128,
14,
374,
63,
4266,
26,
355,
1890,
275,
6149,
14,
3823,
63,
3450,
8,
1258,
12,
1654,
63,
2441,
29,
549,
12,
490,
1011,
277,
14,
4128,
14,
4266,
63,
1419,
9,
953,
1798,
275,
1455,
14,
2017,
2842,
8,
277,
14,
4128,
12,
1890,
9,
288,
2648,
275,
3816,
14,
2184,
8,
2087,
9,
288,
291,
14,
2479,
63,
1069,
8,
9799,
12,
2648,
12,
1890,
12,
5552,
9,
267,
871,
1455,
14,
2550,
14,
1944,
11053,
1451,
465,
325,
26,
288,
291,
14,
793,
14,
1757,
480,
19399,
2908,
876,
19925,
1890,
2153,
2105,
14,
450,
83,
401,
325,
9,
267,
871,
10852,
465,
325,
26,
288,
291,
14,
793,
14,
1757,
480,
18433,
1950,
14,
450,
83,
401,
325,
9,
267,
871,
6149,
14,
27102,
465,
325,
26,
288,
340,
325,
14,
589,
59,
16,
61,
508,
6149,
14,
5413,
63,
3170,
63,
13178,
26,
355,
291,
14,
793,
14,
1757,
480,
4266,
1950,
6876,
531,
355,
1890,
14,
1600,
342,
288,
587,
26,
355,
291,
14,
793,
14,
1757,
480,
547,
6661,
7799,
1056,
2685,
355,
291,
14,
2479,
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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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
] |
tesidroni/mp
|
Lib/encodings/unicode_escape.py
|
852
|
1184
|
""" Python 'unicode-escape' Codec
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""
import codecs
### Codec APIs
class Codec(codecs.Codec):
# Note: Binding these as C functions will result in the class not
# converting them to methods. This is intended.
encode = codecs.unicode_escape_encode
decode = codecs.unicode_escape_decode
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.unicode_escape_encode(input, self.errors)[0]
class IncrementalDecoder(codecs.IncrementalDecoder):
def decode(self, input, final=False):
return codecs.unicode_escape_decode(input, self.errors)[0]
class StreamWriter(Codec,codecs.StreamWriter):
pass
class StreamReader(Codec,codecs.StreamReader):
pass
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='unicode-escape',
encode=Codec.encode,
decode=Codec.decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamwriter=StreamWriter,
streamreader=StreamReader,
)
|
gpl-3.0
|
[
624,
2018,
283,
2975,
13,
3765,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
327,
3390,
26,
22630,
316,
3520,
465,
445,
3423,
911,
754,
315,
314,
1021,
440,
272,
327,
13806,
3062,
370,
3102,
14,
961,
365,
11619,
14,
272,
3752,
275,
6010,
14,
2975,
63,
3765,
63,
2143,
272,
4849,
275,
6010,
14,
2975,
63,
3765,
63,
2708,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
2975,
13,
3765,
297,
267,
3752,
29,
8818,
14,
2143,
12,
267,
4849,
29,
8818,
14,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
2975,
13,
3765,
7,
13732,
421,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
199,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
199,
199,
624,
199,
646,
6010,
199,
199,
5680,
13732,
15913,
199,
199,
533,
13732,
8,
8933,
14,
8818,
304,
339,
327,
3390,
26,
22630,
316,
3520,
465,
445,
3423,
911,
754,
315,
314,
1021,
440,
272,
327,
13806,
3062,
370,
3102,
14,
961,
365,
11619,
14,
272,
3752,
275,
6010,
14,
2975,
63,
3765,
63,
2143,
272,
4849,
275,
6010,
14,
2975,
63,
3765,
63,
2708,
199,
199,
533,
24350,
8,
8933,
14,
17016,
304,
272,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24385,
8,
8933,
14,
16703,
304,
272,
347,
4849,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
267,
372,
6010,
14,
2975,
63,
3765,
63,
2708,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
199,
199,
533,
24163,
8,
8818,
12,
8933,
14,
16551,
304,
272,
986,
199,
199,
533,
22970,
8,
8818,
12,
8933,
14,
16132,
304,
272,
986,
199,
199,
5680,
14134,
859,
3261,
199,
199,
318,
26116,
837,
272,
372,
6010,
14,
26375,
8,
267,
536,
534,
2975,
13,
3765,
297,
267,
3752,
29,
8818,
14,
2143,
12,
267,
4849,
29,
8818,
14,
2708,
12,
267,
26329,
29,
17016,
12,
267,
26317,
29,
16703,
12,
267,
26112,
29,
16551,
12,
267,
26101,
29,
16132,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ryangallen/django
|
django/contrib/gis/geos/prepared.py
|
328
|
2445
|
from .base import GEOSBase
from .error import GEOSException
from .libgeos import geos_version_info
from .prototypes import prepared as capi
class PreparedGeometry(GEOSBase):
"""
A geometry that is prepared for performing certain operations.
At the moment this includes the contains covers, and intersects
operations.
"""
ptr_type = capi.PREPGEOM_PTR
def __init__(self, geom):
# Keeping a reference to the original geometry object to prevent it
# from being garbage collected which could then crash the prepared one
# See #21662
self._base_geom = geom
from .geometry import GEOSGeometry
if not isinstance(geom, GEOSGeometry):
raise TypeError
self.ptr = capi.geos_prepare(geom.ptr)
def __del__(self):
if self._ptr and capi:
capi.prepared_destroy(self._ptr)
def contains(self, other):
return capi.prepared_contains(self.ptr, other.ptr)
def contains_properly(self, other):
return capi.prepared_contains_properly(self.ptr, other.ptr)
def covers(self, other):
return capi.prepared_covers(self.ptr, other.ptr)
def intersects(self, other):
return capi.prepared_intersects(self.ptr, other.ptr)
# Added in GEOS 3.3:
def crosses(self, other):
if geos_version_info()['version'] < '3.3.0':
raise GEOSException("crosses on prepared geometries requires GEOS >= 3.3.0")
return capi.prepared_crosses(self.ptr, other.ptr)
def disjoint(self, other):
if geos_version_info()['version'] < '3.3.0':
raise GEOSException("disjoint on prepared geometries requires GEOS >= 3.3.0")
return capi.prepared_disjoint(self.ptr, other.ptr)
def overlaps(self, other):
if geos_version_info()['version'] < '3.3.0':
raise GEOSException("overlaps on prepared geometries requires GEOS >= 3.3.0")
return capi.prepared_overlaps(self.ptr, other.ptr)
def touches(self, other):
if geos_version_info()['version'] < '3.3.0':
raise GEOSException("touches on prepared geometries requires GEOS >= 3.3.0")
return capi.prepared_touches(self.ptr, other.ptr)
def within(self, other):
if geos_version_info()['version'] < '3.3.0':
raise GEOSException("within on prepared geometries requires GEOS >= 3.3.0")
return capi.prepared_within(self.ptr, other.ptr)
|
bsd-3-clause
|
[
504,
1275,
1095,
492,
11920,
1563,
199,
504,
1275,
705,
492,
21390,
21686,
199,
504,
1275,
773,
12151,
492,
30259,
63,
1023,
63,
815,
199,
504,
1275,
16141,
83,
492,
16318,
465,
13648,
421,
199,
533,
5543,
9508,
6831,
8,
14151,
1563,
304,
272,
408,
272,
437,
3400,
626,
365,
16318,
367,
19203,
9842,
5331,
14,
272,
2854,
314,
12427,
642,
6952,
314,
3509,
25858,
12,
436,
1640,
25353,
272,
5331,
14,
272,
408,
272,
12448,
63,
466,
275,
13648,
14,
4225,
48,
31080,
63,
14528,
339,
347,
636,
826,
721,
277,
12,
9671,
304,
267,
327,
1804,
1024,
4073,
282,
3659,
370,
314,
3379,
3400,
909,
370,
7981,
652,
267,
327,
687,
3769,
17516,
13736,
1314,
4293,
2066,
12420,
314,
16318,
1373,
267,
327,
1666,
327,
9669,
2789,
267,
291,
423,
1095,
63,
6481,
275,
9671,
267,
687,
1275,
7660,
492,
21479,
267,
340,
440,
1228,
8,
6481,
12,
21479,
304,
288,
746,
3146,
267,
291,
14,
4695,
275,
13648,
14,
12151,
63,
6726,
8,
6481,
14,
4695,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
340,
291,
423,
4695,
436,
13648,
26,
288,
13648,
14,
19260,
63,
7237,
8,
277,
423,
4695,
9,
339,
347,
3509,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
6134,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
3509,
63,
28314,
590,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
6134,
63,
28314,
590,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
25858,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
5899,
83,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
1640,
25353,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
1058,
25353,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
327,
16230,
315,
11920,
650,
14,
19,
26,
339,
347,
25532,
874,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
20363,
874,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
20363,
874,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
2153,
10153,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
31880,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
31880,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
29755,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
20798,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
20798,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
12943,
397,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
12376,
397,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
12376,
397,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
4453,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
12541,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
12541,
8,
277,
14,
4695,
12,
1163,
14,
4695,
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
] |
[
1275,
1095,
492,
11920,
1563,
199,
504,
1275,
705,
492,
21390,
21686,
199,
504,
1275,
773,
12151,
492,
30259,
63,
1023,
63,
815,
199,
504,
1275,
16141,
83,
492,
16318,
465,
13648,
421,
199,
533,
5543,
9508,
6831,
8,
14151,
1563,
304,
272,
408,
272,
437,
3400,
626,
365,
16318,
367,
19203,
9842,
5331,
14,
272,
2854,
314,
12427,
642,
6952,
314,
3509,
25858,
12,
436,
1640,
25353,
272,
5331,
14,
272,
408,
272,
12448,
63,
466,
275,
13648,
14,
4225,
48,
31080,
63,
14528,
339,
347,
636,
826,
721,
277,
12,
9671,
304,
267,
327,
1804,
1024,
4073,
282,
3659,
370,
314,
3379,
3400,
909,
370,
7981,
652,
267,
327,
687,
3769,
17516,
13736,
1314,
4293,
2066,
12420,
314,
16318,
1373,
267,
327,
1666,
327,
9669,
2789,
267,
291,
423,
1095,
63,
6481,
275,
9671,
267,
687,
1275,
7660,
492,
21479,
267,
340,
440,
1228,
8,
6481,
12,
21479,
304,
288,
746,
3146,
267,
291,
14,
4695,
275,
13648,
14,
12151,
63,
6726,
8,
6481,
14,
4695,
9,
339,
347,
636,
2264,
721,
277,
304,
267,
340,
291,
423,
4695,
436,
13648,
26,
288,
13648,
14,
19260,
63,
7237,
8,
277,
423,
4695,
9,
339,
347,
3509,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
6134,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
3509,
63,
28314,
590,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
6134,
63,
28314,
590,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
25858,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
5899,
83,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
1640,
25353,
8,
277,
12,
1163,
304,
267,
372,
13648,
14,
19260,
63,
1058,
25353,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
327,
16230,
315,
11920,
650,
14,
19,
26,
339,
347,
25532,
874,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
20363,
874,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
20363,
874,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
2153,
10153,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
31880,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
31880,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
29755,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
20798,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
20798,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
12943,
397,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
12376,
397,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
12376,
397,
8,
277,
14,
4695,
12,
1163,
14,
4695,
9,
339,
347,
4453,
8,
277,
12,
1163,
304,
267,
340,
30259,
63,
1023,
63,
815,
12047,
1023,
418,
665,
283,
19,
14,
19,
14,
16,
356,
288,
746,
21390,
21686,
480,
12541,
641,
16318,
24883,
5074,
11920,
2356,
650,
14,
19,
14,
16,
531,
267,
372,
13648,
14,
19260,
63,
12541,
8,
277,
14,
4695,
12,
1163,
14,
4695,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
absoludity/servo
|
tests/wpt/web-platform-tests/tools/pytest/testing/code/test_excinfo.py
|
165
|
30814
|
# -*- coding: utf-8 -*-
import _pytest
import py
import pytest
from _pytest._code.code import FormattedExcinfo, ReprExceptionInfo
queue = py.builtin._tryimport('queue', 'Queue')
failsonjython = pytest.mark.xfail("sys.platform.startswith('java')")
from test_source import astonly
try:
import importlib
except ImportError:
invalidate_import_caches = None
else:
invalidate_import_caches = getattr(importlib, "invalidate_caches", None)
import pytest
pytest_version_info = tuple(map(int, pytest.__version__.split(".")[:3]))
class TWMock:
def __init__(self):
self.lines = []
def sep(self, sep, line=None):
self.lines.append((sep, line))
def line(self, line, **kw):
self.lines.append(line)
def markup(self, text, **kw):
return text
fullwidth = 80
def test_excinfo_simple():
try:
raise ValueError
except ValueError:
info = _pytest._code.ExceptionInfo()
assert info.type == ValueError
def test_excinfo_getstatement():
def g():
raise ValueError
def f():
g()
try:
f()
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
linenumbers = [_pytest._code.getrawcode(f).co_firstlineno - 1 + 3,
_pytest._code.getrawcode(f).co_firstlineno - 1 + 1,
_pytest._code.getrawcode(g).co_firstlineno - 1 + 1, ]
l = list(excinfo.traceback)
foundlinenumbers = [x.lineno for x in l]
assert foundlinenumbers == linenumbers
#for x in info:
# print "%s:%d %s" %(x.path.relto(root), x.lineno, x.statement)
#xxx
# testchain for getentries test below
def f():
#
raise ValueError
#
def g():
#
__tracebackhide__ = True
f()
#
def h():
#
g()
#
class TestTraceback_f_g_h:
def setup_method(self, method):
try:
h()
except ValueError:
self.excinfo = _pytest._code.ExceptionInfo()
def test_traceback_entries(self):
tb = self.excinfo.traceback
entries = list(tb)
assert len(tb) == 4 # maybe fragile test
assert len(entries) == 4 # maybe fragile test
names = ['f', 'g', 'h']
for entry in entries:
try:
names.remove(entry.frame.code.name)
except ValueError:
pass
assert not names
def test_traceback_entry_getsource(self):
tb = self.excinfo.traceback
s = str(tb[-1].getsource() )
assert s.startswith("def f():")
assert s.endswith("raise ValueError")
@astonly
@failsonjython
def test_traceback_entry_getsource_in_construct(self):
source = _pytest._code.Source("""\
def xyz():
try:
raise ValueError
except somenoname:
pass
xyz()
""")
try:
exec (source.compile())
except NameError:
tb = _pytest._code.ExceptionInfo().traceback
print (tb[-1].getsource())
s = str(tb[-1].getsource())
assert s.startswith("def xyz():\n try:")
assert s.strip().endswith("except somenoname:")
def test_traceback_cut(self):
co = _pytest._code.Code(f)
path, firstlineno = co.path, co.firstlineno
traceback = self.excinfo.traceback
newtraceback = traceback.cut(path=path, firstlineno=firstlineno)
assert len(newtraceback) == 1
newtraceback = traceback.cut(path=path, lineno=firstlineno+2)
assert len(newtraceback) == 1
def test_traceback_cut_excludepath(self, testdir):
p = testdir.makepyfile("def f(): raise ValueError")
excinfo = pytest.raises(ValueError, "p.pyimport().f()")
basedir = py.path.local(pytest.__file__).dirpath()
newtraceback = excinfo.traceback.cut(excludepath=basedir)
for x in newtraceback:
if hasattr(x, 'path'):
assert not py.path.local(x.path).relto(basedir)
assert newtraceback[-1].frame.code.path == p
def test_traceback_filter(self):
traceback = self.excinfo.traceback
ntraceback = traceback.filter()
assert len(ntraceback) == len(traceback) - 1
def test_traceback_recursion_index(self):
def f(n):
if n < 10:
n += 1
f(n)
excinfo = pytest.raises(RuntimeError, f, 8)
traceback = excinfo.traceback
recindex = traceback.recursionindex()
assert recindex == 3
def test_traceback_only_specific_recursion_errors(self, monkeypatch):
def f(n):
if n == 0:
raise RuntimeError("hello")
f(n-1)
excinfo = pytest.raises(RuntimeError, f, 100)
monkeypatch.delattr(excinfo.traceback.__class__, "recursionindex")
repr = excinfo.getrepr()
assert "RuntimeError: hello" in str(repr.reprcrash)
def test_traceback_no_recursion_index(self):
def do_stuff():
raise RuntimeError
def reraise_me():
import sys
exc, val, tb = sys.exc_info()
py.builtin._reraise(exc, val, tb)
def f(n):
try:
do_stuff()
except:
reraise_me()
excinfo = pytest.raises(RuntimeError, f, 8)
traceback = excinfo.traceback
recindex = traceback.recursionindex()
assert recindex is None
def test_traceback_messy_recursion(self):
#XXX: simplified locally testable version
decorator = pytest.importorskip('decorator').decorator
def log(f, *k, **kw):
print('%s %s' % (k, kw))
f(*k, **kw)
log = decorator(log)
def fail():
raise ValueError('')
fail = log(log(fail))
excinfo = pytest.raises(ValueError, fail)
assert excinfo.traceback.recursionindex() is None
def test_traceback_getcrashentry(self):
def i():
__tracebackhide__ = True
raise ValueError
def h():
i()
def g():
__tracebackhide__ = True
h()
def f():
g()
excinfo = pytest.raises(ValueError, f)
tb = excinfo.traceback
entry = tb.getcrashentry()
co = _pytest._code.Code(h)
assert entry.frame.code.path == co.path
assert entry.lineno == co.firstlineno + 1
assert entry.frame.code.name == 'h'
def test_traceback_getcrashentry_empty(self):
def g():
__tracebackhide__ = True
raise ValueError
def f():
__tracebackhide__ = True
g()
excinfo = pytest.raises(ValueError, f)
tb = excinfo.traceback
entry = tb.getcrashentry()
co = _pytest._code.Code(g)
assert entry.frame.code.path == co.path
assert entry.lineno == co.firstlineno + 2
assert entry.frame.code.name == 'g'
def hello(x):
x + 5
def test_tbentry_reinterpret():
try:
hello("hello")
except TypeError:
excinfo = _pytest._code.ExceptionInfo()
tbentry = excinfo.traceback[-1]
msg = tbentry.reinterpret()
assert msg.startswith("TypeError: ('hello' + 5)")
def test_excinfo_exconly():
excinfo = pytest.raises(ValueError, h)
assert excinfo.exconly().startswith('ValueError')
excinfo = pytest.raises(ValueError,
"raise ValueError('hello\\nworld')")
msg = excinfo.exconly(tryshort=True)
assert msg.startswith('ValueError')
assert msg.endswith("world")
def test_excinfo_repr():
excinfo = pytest.raises(ValueError, h)
s = repr(excinfo)
assert s == "<ExceptionInfo ValueError tblen=4>"
def test_excinfo_str():
excinfo = pytest.raises(ValueError, h)
s = str(excinfo)
assert s.startswith(__file__[:-9]) # pyc file and $py.class
assert s.endswith("ValueError")
assert len(s.split(":")) >= 3 # on windows it's 4
def test_excinfo_errisinstance():
excinfo = pytest.raises(ValueError, h)
assert excinfo.errisinstance(ValueError)
def test_excinfo_no_sourcecode():
try:
exec ("raise ValueError()")
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
s = str(excinfo.traceback[-1])
if py.std.sys.version_info < (2,5):
assert s == " File '<string>':1 in ?\n ???\n"
else:
assert s == " File '<string>':1 in <module>\n ???\n"
def test_excinfo_no_python_sourcecode(tmpdir):
#XXX: simplified locally testable version
tmpdir.join('test.txt').write("{{ h()}}:")
jinja2 = pytest.importorskip('jinja2')
loader = jinja2.FileSystemLoader(str(tmpdir))
env = jinja2.Environment(loader=loader)
template = env.get_template('test.txt')
excinfo = pytest.raises(ValueError,
template.render, h=h)
for item in excinfo.traceback:
print(item) #XXX: for some reason jinja.Template.render is printed in full
item.source # shouldnt fail
if item.path.basename == 'test.txt':
assert str(item.source) == '{{ h()}}:'
def test_entrysource_Queue_example():
try:
queue.Queue().get(timeout=0.001)
except queue.Empty:
excinfo = _pytest._code.ExceptionInfo()
entry = excinfo.traceback[-1]
source = entry.getsource()
assert source is not None
s = str(source).strip()
assert s.startswith("def get")
def test_codepath_Queue_example():
try:
queue.Queue().get(timeout=0.001)
except queue.Empty:
excinfo = _pytest._code.ExceptionInfo()
entry = excinfo.traceback[-1]
path = entry.path
assert isinstance(path, py.path.local)
assert path.basename.lower() == "queue.py"
assert path.check()
class TestFormattedExcinfo:
def pytest_funcarg__importasmod(self, request):
def importasmod(source):
source = _pytest._code.Source(source)
tmpdir = request.getfuncargvalue("tmpdir")
modpath = tmpdir.join("mod.py")
tmpdir.ensure("__init__.py")
modpath.write(source)
if invalidate_import_caches is not None:
invalidate_import_caches()
return modpath.pyimport()
return importasmod
def excinfo_from_exec(self, source):
source = _pytest._code.Source(source).strip()
try:
exec (source.compile())
except KeyboardInterrupt:
raise
except:
return _pytest._code.ExceptionInfo()
assert 0, "did not raise"
def test_repr_source(self):
pr = FormattedExcinfo()
source = _pytest._code.Source("""
def f(x):
pass
""").strip()
pr.flow_marker = "|"
lines = pr.get_source(source, 0)
assert len(lines) == 2
assert lines[0] == "| def f(x):"
assert lines[1] == " pass"
def test_repr_source_excinfo(self):
""" check if indentation is right """
pr = FormattedExcinfo()
excinfo = self.excinfo_from_exec("""
def f():
assert 0
f()
""")
pr = FormattedExcinfo()
source = pr._getentrysource(excinfo.traceback[-1])
lines = pr.get_source(source, 1, excinfo)
assert lines == [
' def f():',
'> assert 0',
'E assert 0'
]
def test_repr_source_not_existing(self):
pr = FormattedExcinfo()
co = compile("raise ValueError()", "", "exec")
try:
exec (co)
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
repr = pr.repr_excinfo(excinfo)
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
def test_repr_many_line_source_not_existing(self):
pr = FormattedExcinfo()
co = compile("""
a = 1
raise ValueError()
""", "", "exec")
try:
exec (co)
except ValueError:
excinfo = _pytest._code.ExceptionInfo()
repr = pr.repr_excinfo(excinfo)
assert repr.reprtraceback.reprentries[1].lines[0] == "> ???"
def test_repr_source_failing_fullsource(self):
pr = FormattedExcinfo()
class FakeCode(object):
class raw:
co_filename = '?'
path = '?'
firstlineno = 5
def fullsource(self):
return None
fullsource = property(fullsource)
class FakeFrame(object):
code = FakeCode()
f_locals = {}
f_globals = {}
class FakeTracebackEntry(_pytest._code.Traceback.Entry):
def __init__(self, tb):
self.lineno = 5+3
@property
def frame(self):
return FakeFrame()
class Traceback(_pytest._code.Traceback):
Entry = FakeTracebackEntry
class FakeExcinfo(_pytest._code.ExceptionInfo):
typename = "Foo"
def __init__(self):
pass
def exconly(self, tryshort):
return "EXC"
def errisinstance(self, cls):
return False
excinfo = FakeExcinfo()
class FakeRawTB(object):
tb_next = None
tb = FakeRawTB()
excinfo.traceback = Traceback(tb)
fail = IOError() # noqa
repr = pr.repr_excinfo(excinfo)
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
fail = py.error.ENOENT # noqa
repr = pr.repr_excinfo(excinfo)
assert repr.reprtraceback.reprentries[0].lines[0] == "> ???"
def test_repr_local(self):
p = FormattedExcinfo(showlocals=True)
loc = {'y': 5, 'z': 7, 'x': 3, '@x': 2, '__builtins__': {}}
reprlocals = p.repr_locals(loc)
assert reprlocals.lines
assert reprlocals.lines[0] == '__builtins__ = <builtins>'
assert reprlocals.lines[1] == 'x = 3'
assert reprlocals.lines[2] == 'y = 5'
assert reprlocals.lines[3] == 'z = 7'
def test_repr_tracebackentry_lines(self, importasmod):
mod = importasmod("""
def func1():
raise ValueError("hello\\nworld")
""")
excinfo = pytest.raises(ValueError, mod.func1)
excinfo.traceback = excinfo.traceback.filter()
p = FormattedExcinfo()
reprtb = p.repr_traceback_entry(excinfo.traceback[-1])
# test as intermittent entry
lines = reprtb.lines
assert lines[0] == ' def func1():'
assert lines[1] == '> raise ValueError("hello\\nworld")'
# test as last entry
p = FormattedExcinfo(showlocals=True)
repr_entry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
lines = repr_entry.lines
assert lines[0] == ' def func1():'
assert lines[1] == '> raise ValueError("hello\\nworld")'
assert lines[2] == 'E ValueError: hello'
assert lines[3] == 'E world'
assert not lines[4:]
loc = repr_entry.reprlocals is not None
loc = repr_entry.reprfileloc
assert loc.path == mod.__file__
assert loc.lineno == 3
#assert loc.message == "ValueError: hello"
def test_repr_tracebackentry_lines2(self, importasmod):
mod = importasmod("""
def func1(m, x, y, z):
raise ValueError("hello\\nworld")
""")
excinfo = pytest.raises(ValueError, mod.func1, "m"*90, 5, 13, "z"*120)
excinfo.traceback = excinfo.traceback.filter()
entry = excinfo.traceback[-1]
p = FormattedExcinfo(funcargs=True)
reprfuncargs = p.repr_args(entry)
assert reprfuncargs.args[0] == ('m', repr("m"*90))
assert reprfuncargs.args[1] == ('x', '5')
assert reprfuncargs.args[2] == ('y', '13')
assert reprfuncargs.args[3] == ('z', repr("z" * 120))
p = FormattedExcinfo(funcargs=True)
repr_entry = p.repr_traceback_entry(entry)
assert repr_entry.reprfuncargs.args == reprfuncargs.args
tw = TWMock()
repr_entry.toterminal(tw)
assert tw.lines[0] == "m = " + repr('m' * 90)
assert tw.lines[1] == "x = 5, y = 13"
assert tw.lines[2] == "z = " + repr('z' * 120)
def test_repr_tracebackentry_lines_var_kw_args(self, importasmod):
mod = importasmod("""
def func1(x, *y, **z):
raise ValueError("hello\\nworld")
""")
excinfo = pytest.raises(ValueError, mod.func1, 'a', 'b', c='d')
excinfo.traceback = excinfo.traceback.filter()
entry = excinfo.traceback[-1]
p = FormattedExcinfo(funcargs=True)
reprfuncargs = p.repr_args(entry)
assert reprfuncargs.args[0] == ('x', repr('a'))
assert reprfuncargs.args[1] == ('y', repr(('b',)))
assert reprfuncargs.args[2] == ('z', repr({'c': 'd'}))
p = FormattedExcinfo(funcargs=True)
repr_entry = p.repr_traceback_entry(entry)
assert repr_entry.reprfuncargs.args == reprfuncargs.args
tw = TWMock()
repr_entry.toterminal(tw)
assert tw.lines[0] == "x = 'a', y = ('b',), z = {'c': 'd'}"
def test_repr_tracebackentry_short(self, importasmod):
mod = importasmod("""
def func1():
raise ValueError("hello")
def entry():
func1()
""")
excinfo = pytest.raises(ValueError, mod.entry)
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback_entry(excinfo.traceback[-2])
lines = reprtb.lines
basename = py.path.local(mod.__file__).basename
assert lines[0] == ' func1()'
assert basename in str(reprtb.reprfileloc.path)
assert reprtb.reprfileloc.lineno == 5
# test last entry
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
lines = reprtb.lines
assert lines[0] == ' raise ValueError("hello")'
assert lines[1] == 'E ValueError: hello'
assert basename in str(reprtb.reprfileloc.path)
assert reprtb.reprfileloc.lineno == 3
def test_repr_tracebackentry_no(self, importasmod):
mod = importasmod("""
def func1():
raise ValueError("hello")
def entry():
func1()
""")
excinfo = pytest.raises(ValueError, mod.entry)
p = FormattedExcinfo(style="no")
p.repr_traceback_entry(excinfo.traceback[-2])
p = FormattedExcinfo(style="no")
reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
lines = reprentry.lines
assert lines[0] == 'E ValueError: hello'
assert not lines[1:]
def test_repr_traceback_tbfilter(self, importasmod):
mod = importasmod("""
def f(x):
raise ValueError(x)
def entry():
f(0)
""")
excinfo = pytest.raises(ValueError, mod.entry)
p = FormattedExcinfo(tbfilter=True)
reprtb = p.repr_traceback(excinfo)
assert len(reprtb.reprentries) == 2
p = FormattedExcinfo(tbfilter=False)
reprtb = p.repr_traceback(excinfo)
assert len(reprtb.reprentries) == 3
def test_traceback_short_no_source(self, importasmod, monkeypatch):
mod = importasmod("""
def func1():
raise ValueError("hello")
def entry():
func1()
""")
excinfo = pytest.raises(ValueError, mod.entry)
from _pytest._code.code import Code
monkeypatch.setattr(Code, 'path', 'bogus')
excinfo.traceback[0].frame.code.path = "bogus"
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback_entry(excinfo.traceback[-2])
lines = reprtb.lines
last_p = FormattedExcinfo(style="short")
last_reprtb = last_p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
last_lines = last_reprtb.lines
monkeypatch.undo()
assert lines[0] == ' func1()'
assert last_lines[0] == ' raise ValueError("hello")'
assert last_lines[1] == 'E ValueError: hello'
def test_repr_traceback_and_excinfo(self, importasmod):
mod = importasmod("""
def f(x):
raise ValueError(x)
def entry():
f(0)
""")
excinfo = pytest.raises(ValueError, mod.entry)
for style in ("long", "short"):
p = FormattedExcinfo(style=style)
reprtb = p.repr_traceback(excinfo)
assert len(reprtb.reprentries) == 2
assert reprtb.style == style
assert not reprtb.extraline
repr = p.repr_excinfo(excinfo)
assert repr.reprtraceback
assert len(repr.reprtraceback.reprentries) == len(reprtb.reprentries)
assert repr.reprcrash.path.endswith("mod.py")
assert repr.reprcrash.message == "ValueError: 0"
def test_repr_traceback_with_invalid_cwd(self, importasmod, monkeypatch):
mod = importasmod("""
def f(x):
raise ValueError(x)
def entry():
f(0)
""")
excinfo = pytest.raises(ValueError, mod.entry)
p = FormattedExcinfo()
def raiseos():
raise OSError(2)
monkeypatch.setattr(py.std.os, 'getcwd', raiseos)
assert p._makepath(__file__) == __file__
p.repr_traceback(excinfo)
def test_repr_excinfo_addouterr(self, importasmod):
mod = importasmod("""
def entry():
raise ValueError()
""")
excinfo = pytest.raises(ValueError, mod.entry)
repr = excinfo.getrepr()
repr.addsection("title", "content")
twmock = TWMock()
repr.toterminal(twmock)
assert twmock.lines[-1] == "content"
assert twmock.lines[-2] == ("-", "title")
def test_repr_excinfo_reprcrash(self, importasmod):
mod = importasmod("""
def entry():
raise ValueError()
""")
excinfo = pytest.raises(ValueError, mod.entry)
repr = excinfo.getrepr()
assert repr.reprcrash.path.endswith("mod.py")
assert repr.reprcrash.lineno == 3
assert repr.reprcrash.message == "ValueError"
assert str(repr.reprcrash).endswith("mod.py:3: ValueError")
def test_repr_traceback_recursion(self, importasmod):
mod = importasmod("""
def rec2(x):
return rec1(x+1)
def rec1(x):
return rec2(x-1)
def entry():
rec1(42)
""")
excinfo = pytest.raises(RuntimeError, mod.entry)
for style in ("short", "long", "no"):
p = FormattedExcinfo(style="short")
reprtb = p.repr_traceback(excinfo)
assert reprtb.extraline == "!!! Recursion detected (same locals & position)"
assert str(reprtb)
def test_tb_entry_AssertionError(self, importasmod):
# probably this test is a bit redundant
# as py/magic/testing/test_assertion.py
# already tests correctness of
# assertion-reinterpretation logic
mod = importasmod("""
def somefunc():
x = 1
assert x == 2
""")
excinfo = pytest.raises(AssertionError, mod.somefunc)
p = FormattedExcinfo()
reprentry = p.repr_traceback_entry(excinfo.traceback[-1], excinfo)
lines = reprentry.lines
assert lines[-1] == "E assert 1 == 2"
def test_reprexcinfo_getrepr(self, importasmod):
mod = importasmod("""
def f(x):
raise ValueError(x)
def entry():
f(0)
""")
excinfo = pytest.raises(ValueError, mod.entry)
for style in ("short", "long", "no"):
for showlocals in (True, False):
repr = excinfo.getrepr(style=style, showlocals=showlocals)
assert isinstance(repr, ReprExceptionInfo)
assert repr.reprtraceback.style == style
def test_reprexcinfo_unicode(self):
from _pytest._code.code import TerminalRepr
class MyRepr(TerminalRepr):
def toterminal(self, tw):
tw.line(py.builtin._totext("я", "utf-8"))
x = py.builtin._totext(MyRepr())
assert x == py.builtin._totext("я", "utf-8")
def test_toterminal_long(self, importasmod):
mod = importasmod("""
def g(x):
raise ValueError(x)
def f():
g(3)
""")
excinfo = pytest.raises(ValueError, mod.f)
excinfo.traceback = excinfo.traceback.filter()
repr = excinfo.getrepr()
tw = TWMock()
repr.toterminal(tw)
assert tw.lines[0] == ""
tw.lines.pop(0)
assert tw.lines[0] == " def f():"
assert tw.lines[1] == "> g(3)"
assert tw.lines[2] == ""
assert tw.lines[3].endswith("mod.py:5: ")
assert tw.lines[4] == ("_ ", None)
assert tw.lines[5] == ""
assert tw.lines[6] == " def g(x):"
assert tw.lines[7] == "> raise ValueError(x)"
assert tw.lines[8] == "E ValueError: 3"
assert tw.lines[9] == ""
assert tw.lines[10].endswith("mod.py:3: ValueError")
def test_toterminal_long_missing_source(self, importasmod, tmpdir):
mod = importasmod("""
def g(x):
raise ValueError(x)
def f():
g(3)
""")
excinfo = pytest.raises(ValueError, mod.f)
tmpdir.join('mod.py').remove()
excinfo.traceback = excinfo.traceback.filter()
repr = excinfo.getrepr()
tw = TWMock()
repr.toterminal(tw)
assert tw.lines[0] == ""
tw.lines.pop(0)
assert tw.lines[0] == "> ???"
assert tw.lines[1] == ""
assert tw.lines[2].endswith("mod.py:5: ")
assert tw.lines[3] == ("_ ", None)
assert tw.lines[4] == ""
assert tw.lines[5] == "> ???"
assert tw.lines[6] == "E ValueError: 3"
assert tw.lines[7] == ""
assert tw.lines[8].endswith("mod.py:3: ValueError")
def test_toterminal_long_incomplete_source(self, importasmod, tmpdir):
mod = importasmod("""
def g(x):
raise ValueError(x)
def f():
g(3)
""")
excinfo = pytest.raises(ValueError, mod.f)
tmpdir.join('mod.py').write('asdf')
excinfo.traceback = excinfo.traceback.filter()
repr = excinfo.getrepr()
tw = TWMock()
repr.toterminal(tw)
assert tw.lines[0] == ""
tw.lines.pop(0)
assert tw.lines[0] == "> ???"
assert tw.lines[1] == ""
assert tw.lines[2].endswith("mod.py:5: ")
assert tw.lines[3] == ("_ ", None)
assert tw.lines[4] == ""
assert tw.lines[5] == "> ???"
assert tw.lines[6] == "E ValueError: 3"
assert tw.lines[7] == ""
assert tw.lines[8].endswith("mod.py:3: ValueError")
def test_toterminal_long_filenames(self, importasmod):
mod = importasmod("""
def f():
raise ValueError()
""")
excinfo = pytest.raises(ValueError, mod.f)
tw = TWMock()
path = py.path.local(mod.__file__)
old = path.dirpath().chdir()
try:
repr = excinfo.getrepr(abspath=False)
repr.toterminal(tw)
line = tw.lines[-1]
x = py.path.local().bestrelpath(path)
if len(x) < len(str(path)):
assert line == "mod.py:3: ValueError"
repr = excinfo.getrepr(abspath=True)
repr.toterminal(tw)
line = tw.lines[-1]
assert line == "%s:3: ValueError" %(path,)
finally:
old.chdir()
@pytest.mark.parametrize('reproptions', [
{'style': style, 'showlocals': showlocals,
'funcargs': funcargs, 'tbfilter': tbfilter
} for style in ("long", "short", "no")
for showlocals in (True, False)
for tbfilter in (True, False)
for funcargs in (True, False)])
def test_format_excinfo(self, importasmod, reproptions):
mod = importasmod("""
def g(x):
raise ValueError(x)
def f():
g(3)
""")
excinfo = pytest.raises(ValueError, mod.f)
tw = py.io.TerminalWriter(stringio=True)
repr = excinfo.getrepr(**reproptions)
repr.toterminal(tw)
assert tw.stringio.getvalue()
def test_native_style(self):
excinfo = self.excinfo_from_exec("""
assert 0
""")
repr = excinfo.getrepr(style='native')
assert "assert 0" in str(repr.reprcrash)
s = str(repr)
assert s.startswith('Traceback (most recent call last):\n File')
assert s.endswith('\nAssertionError: assert 0')
assert 'exec (source.compile())' in s
# python 2.4 fails to get the source line for the assert
if py.std.sys.version_info >= (2, 5):
assert s.count('assert 0') == 2
def test_traceback_repr_style(self, importasmod):
mod = importasmod("""
def f():
g()
def g():
h()
def h():
i()
def i():
raise ValueError()
""")
excinfo = pytest.raises(ValueError, mod.f)
excinfo.traceback = excinfo.traceback.filter()
excinfo.traceback[1].set_repr_style("short")
excinfo.traceback[2].set_repr_style("short")
r = excinfo.getrepr(style="long")
tw = TWMock()
r.toterminal(tw)
for line in tw.lines: print (line)
assert tw.lines[0] == ""
assert tw.lines[1] == " def f():"
assert tw.lines[2] == "> g()"
assert tw.lines[3] == ""
assert tw.lines[4].endswith("mod.py:3: ")
assert tw.lines[5] == ("_ ", None)
assert tw.lines[6].endswith("in g")
assert tw.lines[7] == " h()"
assert tw.lines[8].endswith("in h")
assert tw.lines[9] == " i()"
assert tw.lines[10] == ("_ ", None)
assert tw.lines[11] == ""
assert tw.lines[12] == " def i():"
assert tw.lines[13] == "> raise ValueError()"
assert tw.lines[14] == "E ValueError"
assert tw.lines[15] == ""
assert tw.lines[16].endswith("mod.py:9: ValueError")
|
mpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
485,
4462,
199,
646,
1134,
199,
646,
4613,
199,
504,
485,
4462,
423,
600,
14,
600,
492,
9701,
471,
20702,
815,
12,
799,
2700,
1726,
2354,
199,
199,
1825,
275,
1134,
14,
5351,
423,
893,
646,
360,
1825,
297,
283,
3737,
358,
199,
199,
1633,
834,
27179,
275,
4613,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
26530,
199,
504,
511,
63,
1365,
492,
6073,
2118,
199,
199,
893,
26,
272,
492,
14802,
199,
2590,
3545,
26,
272,
24841,
63,
646,
63,
17595,
275,
488,
199,
2836,
26,
272,
24841,
63,
646,
63,
17595,
275,
2519,
8,
25893,
12,
298,
17197,
63,
17595,
401,
488,
9,
199,
199,
646,
4613,
199,
4462,
63,
1023,
63,
815,
275,
2008,
8,
1130,
8,
442,
12,
4613,
855,
1023,
4343,
1294,
15857,
1491,
19,
2459,
199,
199,
533,
377,
55,
3346,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1278,
275,
942,
272,
347,
7375,
8,
277,
12,
7375,
12,
1004,
29,
403,
304,
267,
291,
14,
1278,
14,
740,
1332,
4127,
12,
1004,
430,
272,
347,
1004,
8,
277,
12,
1004,
12,
1011,
829,
304,
267,
291,
14,
1278,
14,
740,
8,
604,
9,
272,
347,
9189,
8,
277,
12,
1318,
12,
1011,
829,
304,
267,
372,
1318,
339,
2615,
2063,
275,
5939,
199,
199,
318,
511,
63,
27447,
63,
4129,
837,
272,
862,
26,
267,
746,
1722,
272,
871,
1722,
26,
267,
2256,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
272,
702,
2256,
14,
466,
508,
1722,
199,
199,
318,
511,
63,
27447,
63,
362,
6242,
837,
272,
347,
486,
837,
267,
746,
1722,
272,
347,
289,
837,
267,
486,
342,
272,
862,
26,
267,
289,
342,
272,
871,
1722,
26,
267,
21596,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
272,
10165,
29330,
275,
15500,
4462,
423,
600,
14,
362,
1773,
600,
8,
70,
680,
331,
63,
30114,
446,
413,
435,
650,
12,
673,
485,
4462,
423,
600,
14,
362,
1773,
600,
8,
70,
680,
331,
63,
30114,
446,
413,
435,
413,
12,
673,
485,
4462,
423,
600,
14,
362,
1773,
600,
8,
71,
680,
331,
63,
30114,
446,
413,
435,
413,
12,
1622,
272,
634,
275,
769,
8,
27447,
14,
6894,
9,
272,
1911,
2950,
29330,
275,
359,
88,
14,
3469,
367,
671,
315,
634,
61,
272,
702,
1911,
2950,
29330,
508,
10165,
29330,
272,
327,
509,
671,
315,
2256,
26,
272,
327,
259,
870,
2071,
83,
2689,
68,
221,
450,
83,
2,
2818,
88,
14,
515,
14,
3369,
475,
8,
1231,
395,
671,
14,
3469,
12,
671,
14,
6242,
9,
272,
327,
10013,
199,
199,
3,
511,
4429,
367,
2312,
767,
1996,
511,
5084,
199,
318,
289,
837,
272,
327,
272,
746,
1722,
272,
327,
199,
318,
486,
837,
272,
327,
272,
636,
6894,
8191,
363,
275,
715,
272,
289,
342,
272,
327,
199,
318,
394,
837,
272,
327,
272,
486,
342,
272,
327,
199,
199,
533,
1379,
15905,
63,
70,
63,
71,
63,
72,
26,
272,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
862,
26,
288,
394,
342,
267,
871,
1722,
26,
288,
291,
14,
27447,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
339,
347,
511,
63,
6894,
63,
3189,
8,
277,
304,
267,
7070,
275,
291,
14,
27447,
14,
6894,
267,
4811,
275,
769,
8,
5842,
9,
267,
702,
822,
8,
5842,
9,
508,
841,
327,
11703,
11101,
441,
511,
267,
702,
822,
8,
3189,
9,
508,
841,
327,
11703,
11101,
441,
511,
267,
1561,
275,
788,
70,
297,
283,
71,
297,
283,
72,
418,
267,
367,
2397,
315,
4811,
26,
288,
862,
26,
355,
1561,
14,
2168,
8,
2373,
14,
1943,
14,
600,
14,
354,
9,
288,
871,
1722,
26,
355,
986,
267,
702,
440,
1561,
339,
347,
511,
63,
6894,
63,
2373,
63,
362,
1365,
8,
277,
304,
267,
7070,
275,
291,
14,
27447,
14,
6894,
267,
308,
275,
620,
8,
5842,
1988,
17,
1055,
362,
1365,
342,
776,
267,
702,
308,
14,
2460,
480,
318,
289,
837,
531,
267,
702,
308,
14,
4130,
480,
3730,
1722,
531,
339,
768,
1810,
2118,
272,
768,
1633,
834,
27179,
272,
347,
511,
63,
6894,
63,
2373,
63,
362,
1365,
63,
262,
63,
8514,
8,
277,
304,
267,
1350,
275,
485,
4462,
423,
600,
14,
2980,
21723,
288,
347,
24122,
837,
355,
862,
26,
490,
746,
1722,
355,
871,
880,
1410,
32203,
26,
490,
986,
288,
24122,
342,
267,
7857,
267,
862,
26,
288,
2146,
334,
1365,
14,
2014,
1012,
267,
871,
12746,
26,
288,
7070,
275,
485,
4462,
423,
600,
14,
1726,
2354,
1252,
6894,
288,
870,
334,
5842,
1988,
17,
1055,
362,
1365,
1012,
288,
308,
275,
620,
8,
5842,
1988,
17,
1055,
362,
1365,
1012,
288,
702,
308,
14,
2460,
480,
318,
24122,
837,
60,
78,
259,
862,
9107,
288,
702,
308,
14,
1913,
1252,
4130,
480,
2590,
880,
1410,
32203,
9107,
339,
347,
511,
63,
6894,
63,
5919,
8,
277,
304,
267,
512,
275,
485,
4462,
423,
600,
14,
3034,
8,
70,
9,
267,
931,
12,
1642,
3469,
275,
512,
14,
515,
12,
512,
14,
30114,
267,
5190,
275,
291,
14,
27447,
14,
6894,
267,
892,
6894,
275,
5190,
14,
5919,
8,
515,
29,
515,
12,
1642,
3469,
29,
30114,
9,
267,
702,
822,
8,
1222,
6894,
9,
508,
413,
267,
892,
6894,
275,
5190,
14,
5919,
8,
515,
29,
515,
12,
5874,
29,
30114,
11,
18,
9,
267,
702,
822,
8,
1222,
6894,
9,
508,
413,
339,
347,
511,
63,
6894,
63,
5919,
63,
5473,
515,
8,
277,
12,
7368,
304,
267,
299,
275,
7368,
14,
17358,
480,
318,
289,
837,
746,
1722,
531,
267,
21596,
275,
4613,
14,
3536,
8,
3393,
12,
298,
80,
14,
647,
646,
1252,
70,
16060,
267,
19380,
275,
1134,
14,
515,
14,
1832,
8,
4462,
855,
493,
28634,
17254,
342,
267,
892,
6894,
275,
21596,
14,
6894,
14,
5919,
8,
5473,
515,
29,
12484,
9,
267,
367,
671,
315,
892,
6894,
26,
288,
340,
2688,
8,
88,
12,
283,
515,
735,
355,
702,
440,
1134,
14,
515,
14,
1832,
8,
88,
14,
515,
680
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
485,
4462,
199,
646,
1134,
199,
646,
4613,
199,
504,
485,
4462,
423,
600,
14,
600,
492,
9701,
471,
20702,
815,
12,
799,
2700,
1726,
2354,
199,
199,
1825,
275,
1134,
14,
5351,
423,
893,
646,
360,
1825,
297,
283,
3737,
358,
199,
199,
1633,
834,
27179,
275,
4613,
14,
1657,
14,
22557,
480,
1274,
14,
3246,
14,
2460,
360,
6138,
26530,
199,
504,
511,
63,
1365,
492,
6073,
2118,
199,
199,
893,
26,
272,
492,
14802,
199,
2590,
3545,
26,
272,
24841,
63,
646,
63,
17595,
275,
488,
199,
2836,
26,
272,
24841,
63,
646,
63,
17595,
275,
2519,
8,
25893,
12,
298,
17197,
63,
17595,
401,
488,
9,
199,
199,
646,
4613,
199,
4462,
63,
1023,
63,
815,
275,
2008,
8,
1130,
8,
442,
12,
4613,
855,
1023,
4343,
1294,
15857,
1491,
19,
2459,
199,
199,
533,
377,
55,
3346,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1278,
275,
942,
272,
347,
7375,
8,
277,
12,
7375,
12,
1004,
29,
403,
304,
267,
291,
14,
1278,
14,
740,
1332,
4127,
12,
1004,
430,
272,
347,
1004,
8,
277,
12,
1004,
12,
1011,
829,
304,
267,
291,
14,
1278,
14,
740,
8,
604,
9,
272,
347,
9189,
8,
277,
12,
1318,
12,
1011,
829,
304,
267,
372,
1318,
339,
2615,
2063,
275,
5939,
199,
199,
318,
511,
63,
27447,
63,
4129,
837,
272,
862,
26,
267,
746,
1722,
272,
871,
1722,
26,
267,
2256,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
272,
702,
2256,
14,
466,
508,
1722,
199,
199,
318,
511,
63,
27447,
63,
362,
6242,
837,
272,
347,
486,
837,
267,
746,
1722,
272,
347,
289,
837,
267,
486,
342,
272,
862,
26,
267,
289,
342,
272,
871,
1722,
26,
267,
21596,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
272,
10165,
29330,
275,
15500,
4462,
423,
600,
14,
362,
1773,
600,
8,
70,
680,
331,
63,
30114,
446,
413,
435,
650,
12,
673,
485,
4462,
423,
600,
14,
362,
1773,
600,
8,
70,
680,
331,
63,
30114,
446,
413,
435,
413,
12,
673,
485,
4462,
423,
600,
14,
362,
1773,
600,
8,
71,
680,
331,
63,
30114,
446,
413,
435,
413,
12,
1622,
272,
634,
275,
769,
8,
27447,
14,
6894,
9,
272,
1911,
2950,
29330,
275,
359,
88,
14,
3469,
367,
671,
315,
634,
61,
272,
702,
1911,
2950,
29330,
508,
10165,
29330,
272,
327,
509,
671,
315,
2256,
26,
272,
327,
259,
870,
2071,
83,
2689,
68,
221,
450,
83,
2,
2818,
88,
14,
515,
14,
3369,
475,
8,
1231,
395,
671,
14,
3469,
12,
671,
14,
6242,
9,
272,
327,
10013,
199,
199,
3,
511,
4429,
367,
2312,
767,
1996,
511,
5084,
199,
318,
289,
837,
272,
327,
272,
746,
1722,
272,
327,
199,
318,
486,
837,
272,
327,
272,
636,
6894,
8191,
363,
275,
715,
272,
289,
342,
272,
327,
199,
318,
394,
837,
272,
327,
272,
486,
342,
272,
327,
199,
199,
533,
1379,
15905,
63,
70,
63,
71,
63,
72,
26,
272,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
862,
26,
288,
394,
342,
267,
871,
1722,
26,
288,
291,
14,
27447,
275,
485,
4462,
423,
600,
14,
1726,
2354,
342,
339,
347,
511,
63,
6894,
63,
3189,
8,
277,
304,
267,
7070,
275,
291,
14,
27447,
14,
6894,
267,
4811,
275,
769,
8,
5842,
9,
267,
702,
822,
8,
5842,
9,
508,
841,
327,
11703,
11101,
441,
511,
267,
702,
822,
8,
3189,
9,
508,
841,
327,
11703,
11101,
441,
511,
267,
1561,
275,
788,
70,
297,
283,
71,
297,
283,
72,
418,
267,
367,
2397,
315,
4811,
26,
288,
862,
26,
355,
1561,
14,
2168,
8,
2373,
14,
1943,
14,
600,
14,
354,
9,
288,
871,
1722,
26,
355,
986,
267,
702,
440,
1561,
339,
347,
511,
63,
6894,
63,
2373,
63,
362,
1365,
8,
277,
304,
267,
7070,
275,
291,
14,
27447,
14,
6894,
267,
308,
275,
620,
8,
5842,
1988,
17,
1055,
362,
1365,
342,
776,
267,
702,
308,
14,
2460,
480,
318,
289,
837,
531,
267,
702,
308,
14,
4130,
480,
3730,
1722,
531,
339,
768,
1810,
2118,
272,
768,
1633,
834,
27179,
272,
347,
511,
63,
6894,
63,
2373,
63,
362,
1365,
63,
262,
63,
8514,
8,
277,
304,
267,
1350,
275,
485,
4462,
423,
600,
14,
2980,
21723,
288,
347,
24122,
837,
355,
862,
26,
490,
746,
1722,
355,
871,
880,
1410,
32203,
26,
490,
986,
288,
24122,
342,
267,
7857,
267,
862,
26,
288,
2146,
334,
1365,
14,
2014,
1012,
267,
871,
12746,
26,
288,
7070,
275,
485,
4462,
423,
600,
14,
1726,
2354,
1252,
6894,
288,
870,
334,
5842,
1988,
17,
1055,
362,
1365,
1012,
288,
308,
275,
620,
8,
5842,
1988,
17,
1055,
362,
1365,
1012,
288,
702,
308,
14,
2460,
480,
318,
24122,
837,
60,
78,
259,
862,
9107,
288,
702,
308,
14,
1913,
1252,
4130,
480,
2590,
880,
1410,
32203,
9107,
339,
347,
511,
63,
6894,
63,
5919,
8,
277,
304,
267,
512,
275,
485,
4462,
423,
600,
14,
3034,
8,
70,
9,
267,
931,
12,
1642,
3469,
275,
512,
14,
515,
12,
512,
14,
30114,
267,
5190,
275,
291,
14,
27447,
14,
6894,
267,
892,
6894,
275,
5190,
14,
5919,
8,
515,
29,
515,
12,
1642,
3469,
29,
30114,
9,
267,
702,
822,
8,
1222,
6894,
9,
508,
413,
267,
892,
6894,
275,
5190,
14,
5919,
8,
515,
29,
515,
12,
5874,
29,
30114,
11,
18,
9,
267,
702,
822,
8,
1222,
6894,
9,
508,
413,
339,
347,
511,
63,
6894,
63,
5919,
63,
5473,
515,
8,
277,
12,
7368,
304,
267,
299,
275,
7368,
14,
17358,
480,
318,
289,
837,
746,
1722,
531,
267,
21596,
275,
4613,
14,
3536,
8,
3393,
12,
298,
80,
14,
647,
646,
1252,
70,
16060,
267,
19380,
275,
1134,
14,
515,
14,
1832,
8,
4462,
855,
493,
28634,
17254,
342,
267,
892,
6894,
275,
21596,
14,
6894,
14,
5919,
8,
5473,
515,
29,
12484,
9,
267,
367,
671,
315,
892,
6894,
26,
288,
340,
2688,
8,
88,
12,
283,
515,
735,
355,
702,
440,
1134,
14,
515,
14,
1832,
8,
88,
14,
515,
680,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lancelote/banneret
|
tests/conftest.py
|
1
|
1955
|
import logging
import sys
import pytest
from click.testing import CliRunner
from banneret import Banneret, Docker
from banneret.cli import LINUX, MACOS
only_mac = pytest.mark.skipif(sys.platform not in MACOS, reason='Not macOS')
only_linux = pytest.mark.skipif(sys.platform not in LINUX, reason='Not Linux')
@pytest.fixture
def bnrt():
return Banneret()
@pytest.fixture
def docker_daemon():
return Docker()
@pytest.fixture
def runner():
return CliRunner()
@pytest.fixture
def base_path(tmpdir):
return tmpdir.mkdir('base_path')
@pytest.fixture
def log(caplog):
caplog.set_level(logging.INFO)
return caplog
@pytest.fixture
def mock_remove(mocker):
yield mocker.patch('banneret.Banneret.remove')
@pytest.fixture
def mock_remove_all(mocker):
yield mocker.patch('banneret.Banneret.remove_all')
@pytest.fixture
def mock_archive_project(mocker):
yield mocker.patch('banneret.Banneret.archive_project')
@pytest.fixture
def mock_clean_docker(mocker):
yield mocker.patch('banneret.Banneret.clean_docker')
@pytest.fixture
def mock_enable_error(mocker):
yield mocker.patch('banneret.Banneret.enable_error')
@pytest.fixture
def mock_enable_errors(mocker):
yield mocker.patch('banneret.Banneret.enable_errors')
@pytest.fixture
def mock_remove_containers(mocker):
yield mocker.patch('banneret.Docker.remove_containers')
@pytest.fixture
def mock_remove_images(mocker):
yield mocker.patch('banneret.Docker.remove_images')
@pytest.fixture
def mock_remove_volumes(mocker):
yield mocker.patch('banneret.Docker.remove_volumes')
def create_settings(base_path, versions):
"""Create settings folder depending on the OS."""
if sys.platform in MACOS:
for version in versions:
base_path.mkdir(version)
elif sys.platform in LINUX:
for version in versions:
base_path.mkdir('.' + version)
else:
raise OSError('Unsupported OS')
|
mit
|
[
646,
2050,
199,
646,
984,
199,
199,
646,
4613,
199,
504,
8968,
14,
4776,
492,
445,
317,
7446,
199,
199,
504,
30354,
685,
3292,
492,
699,
290,
685,
3292,
12,
22067,
199,
504,
30354,
685,
3292,
14,
2764,
492,
491,
568,
14272,
12,
13347,
3100,
199,
199,
2118,
63,
3088,
275,
4613,
14,
1657,
14,
22696,
8,
1274,
14,
3246,
440,
315,
13347,
3100,
12,
4499,
534,
1763,
4497,
3100,
358,
199,
2118,
63,
5135,
275,
4613,
14,
1657,
14,
22696,
8,
1274,
14,
3246,
440,
315,
491,
568,
14272,
12,
4499,
534,
1763,
10130,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
21847,
2591,
837,
272,
372,
699,
290,
685,
3292,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
12424,
63,
10824,
837,
272,
372,
22067,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
7876,
837,
272,
372,
445,
317,
7446,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
1300,
63,
515,
8,
8616,
304,
272,
372,
12885,
14,
8215,
360,
1095,
63,
515,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
943,
8,
2874,
793,
304,
272,
32297,
14,
409,
63,
1896,
8,
4806,
14,
4531,
9,
272,
372,
32297,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
2168,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
452,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
2168,
63,
452,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
6404,
63,
1715,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
6404,
63,
1715,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
3118,
63,
9991,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
3118,
63,
9991,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
4296,
63,
705,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
4296,
63,
705,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
4296,
63,
2550,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
4296,
63,
2550,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
13577,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
13577,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
4782,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
4782,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
8838,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
8838,
358,
421,
199,
318,
1218,
63,
1751,
8,
1095,
63,
515,
12,
5459,
304,
272,
408,
2499,
2202,
4922,
10298,
641,
314,
4403,
1041,
272,
340,
984,
14,
3246,
315,
13347,
3100,
26,
267,
367,
1015,
315,
5459,
26,
288,
1300,
63,
515,
14,
8215,
8,
1023,
9,
272,
916,
984,
14,
3246,
315,
491,
568,
14272,
26,
267,
367,
1015,
315,
5459,
26,
288,
1300,
63,
515,
14,
8215,
360,
3530,
435,
1015,
9,
272,
587,
26,
267,
746,
6440,
360,
12647,
4403,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
199,
646,
984,
199,
199,
646,
4613,
199,
504,
8968,
14,
4776,
492,
445,
317,
7446,
199,
199,
504,
30354,
685,
3292,
492,
699,
290,
685,
3292,
12,
22067,
199,
504,
30354,
685,
3292,
14,
2764,
492,
491,
568,
14272,
12,
13347,
3100,
199,
199,
2118,
63,
3088,
275,
4613,
14,
1657,
14,
22696,
8,
1274,
14,
3246,
440,
315,
13347,
3100,
12,
4499,
534,
1763,
4497,
3100,
358,
199,
2118,
63,
5135,
275,
4613,
14,
1657,
14,
22696,
8,
1274,
14,
3246,
440,
315,
491,
568,
14272,
12,
4499,
534,
1763,
10130,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
21847,
2591,
837,
272,
372,
699,
290,
685,
3292,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
12424,
63,
10824,
837,
272,
372,
22067,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
7876,
837,
272,
372,
445,
317,
7446,
342,
421,
199,
32,
4462,
14,
5997,
199,
318,
1300,
63,
515,
8,
8616,
304,
272,
372,
12885,
14,
8215,
360,
1095,
63,
515,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
943,
8,
2874,
793,
304,
272,
32297,
14,
409,
63,
1896,
8,
4806,
14,
4531,
9,
272,
372,
32297,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
2168,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
452,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
2168,
63,
452,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
6404,
63,
1715,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
6404,
63,
1715,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
3118,
63,
9991,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
3118,
63,
9991,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
4296,
63,
705,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
4296,
63,
705,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
4296,
63,
2550,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
28018,
685,
3292,
14,
4296,
63,
2550,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
13577,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
13577,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
4782,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
4782,
358,
421,
199,
32,
4462,
14,
5997,
199,
318,
1683,
63,
2168,
63,
8838,
8,
27899,
304,
272,
1995,
15981,
14,
2068,
360,
13206,
685,
3292,
14,
31463,
14,
2168,
63,
8838,
358,
421,
199,
318,
1218,
63,
1751,
8,
1095,
63,
515,
12,
5459,
304,
272,
408,
2499,
2202,
4922,
10298,
641,
314,
4403,
1041,
272,
340,
984,
14,
3246,
315,
13347,
3100,
26,
267,
367,
1015,
315,
5459,
26,
288,
1300,
63,
515,
14,
8215,
8,
1023,
9,
272,
916,
984,
14,
3246,
315,
491,
568,
14272,
26,
267,
367,
1015,
315,
5459,
26,
288,
1300,
63,
515,
14,
8215,
360,
3530,
435,
1015,
9,
272,
587,
26,
267,
746,
6440,
360,
12647,
4403,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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test/test_frombuffer.py
|
70
|
2481
|
from ctypes import *
import array
import gc
import unittest
class X(Structure):
_fields_ = [("c_int", c_int)]
init_called = False
def __init__(self):
self._init_called = True
class Test(unittest.TestCase):
def test_fom_buffer(self):
a = array.array("i", range(16))
x = (c_int * 16).from_buffer(a)
y = X.from_buffer(a)
self.assertEqual(y.c_int, a[0])
self.assertFalse(y.init_called)
self.assertEqual(x[:], a.tolist())
a[0], a[-1] = 200, -200
self.assertEqual(x[:], a.tolist())
self.assertIn(a, x._objects.values())
self.assertRaises(ValueError,
c_int.from_buffer, a, -1)
expected = x[:]
del a; gc.collect(); gc.collect(); gc.collect()
self.assertEqual(x[:], expected)
self.assertRaises(TypeError,
(c_char * 16).from_buffer, "a" * 16)
def test_fom_buffer_with_offset(self):
a = array.array("i", range(16))
x = (c_int * 15).from_buffer(a, sizeof(c_int))
self.assertEqual(x[:], a.tolist()[1:])
self.assertRaises(ValueError, lambda: (c_int * 16).from_buffer(a, sizeof(c_int)))
self.assertRaises(ValueError, lambda: (c_int * 1).from_buffer(a, 16 * sizeof(c_int)))
def test_from_buffer_copy(self):
a = array.array("i", range(16))
x = (c_int * 16).from_buffer_copy(a)
y = X.from_buffer_copy(a)
self.assertEqual(y.c_int, a[0])
self.assertFalse(y.init_called)
self.assertEqual(x[:], list(range(16)))
a[0], a[-1] = 200, -200
self.assertEqual(x[:], list(range(16)))
self.assertEqual(x._objects, None)
self.assertRaises(ValueError,
c_int.from_buffer, a, -1)
del a; gc.collect(); gc.collect(); gc.collect()
self.assertEqual(x[:], list(range(16)))
x = (c_char * 16).from_buffer_copy(b"a" * 16)
self.assertEqual(x[:], b"a" * 16)
def test_fom_buffer_copy_with_offset(self):
a = array.array("i", range(16))
x = (c_int * 15).from_buffer_copy(a, sizeof(c_int))
self.assertEqual(x[:], a.tolist()[1:])
self.assertRaises(ValueError,
(c_int * 16).from_buffer_copy, a, sizeof(c_int))
self.assertRaises(ValueError,
(c_int * 1).from_buffer_copy, a, 16 * sizeof(c_int))
if __name__ == '__main__':
unittest.main()
|
lgpl-3.0
|
[
504,
5577,
492,
627,
199,
646,
1625,
199,
646,
9486,
199,
646,
2882,
199,
199,
533,
1323,
8,
10766,
304,
272,
485,
955,
63,
275,
10003,
67,
63,
442,
401,
286,
63,
442,
1874,
272,
4205,
63,
3527,
275,
756,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
826,
63,
3527,
275,
715,
199,
199,
533,
1379,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
545,
77,
63,
2738,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
8,
65,
9,
398,
612,
275,
1323,
14,
504,
63,
2738,
8,
65,
9,
267,
291,
14,
629,
8,
89,
14,
67,
63,
442,
12,
282,
59,
16,
566,
267,
291,
14,
3334,
8,
89,
14,
826,
63,
3527,
9,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
1012,
398,
282,
59,
16,
467,
282,
1988,
17,
61,
275,
1926,
12,
446,
1840,
267,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
1012,
398,
291,
14,
4080,
8,
65,
12,
671,
423,
1462,
14,
1459,
1012,
398,
291,
14,
1855,
8,
3393,
12,
2079,
286,
63,
442,
14,
504,
63,
2738,
12,
282,
12,
446,
17,
9,
398,
1420,
275,
671,
5873,
267,
2150,
282,
27,
9486,
14,
7112,
7303,
9486,
14,
7112,
7303,
9486,
14,
7112,
342,
267,
291,
14,
629,
8,
88,
23315,
1420,
9,
398,
291,
14,
1855,
8,
4333,
12,
2079,
334,
67,
63,
1560,
627,
3193,
680,
504,
63,
2738,
12,
298,
65,
2,
627,
3193,
9,
339,
347,
511,
63,
545,
77,
63,
2738,
63,
1045,
63,
2743,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
4114,
680,
504,
63,
2738,
8,
65,
12,
13855,
8,
67,
63,
442,
430,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
3430,
17,
5728,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
8,
65,
12,
13855,
8,
67,
63,
442,
1724,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
334,
67,
63,
442,
627,
413,
680,
504,
63,
2738,
8,
65,
12,
3193,
627,
13855,
8,
67,
63,
442,
1724,
339,
347,
511,
63,
504,
63,
2738,
63,
1574,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
63,
1574,
8,
65,
9,
398,
612,
275,
1323,
14,
504,
63,
2738,
63,
1574,
8,
65,
9,
267,
291,
14,
629,
8,
89,
14,
67,
63,
442,
12,
282,
59,
16,
566,
267,
291,
14,
3334,
8,
89,
14,
826,
63,
3527,
9,
398,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
282,
59,
16,
467,
282,
1988,
17,
61,
275,
1926,
12,
446,
1840,
267,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
291,
14,
629,
8,
88,
423,
1462,
12,
488,
9,
398,
291,
14,
1855,
8,
3393,
12,
2079,
286,
63,
442,
14,
504,
63,
2738,
12,
282,
12,
446,
17,
9,
398,
2150,
282,
27,
9486,
14,
7112,
7303,
9486,
14,
7112,
7303,
9486,
14,
7112,
342,
267,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
671,
275,
334,
67,
63,
1560,
627,
3193,
680,
504,
63,
2738,
63,
1574,
8,
66,
2,
65,
2,
627,
3193,
9,
267,
291,
14,
629,
8,
88,
23315,
330,
2,
65,
2,
627,
3193,
9,
339,
347,
511,
63,
545,
77,
63,
2738,
63,
1574,
63,
1045,
63,
2743,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
4114,
680,
504,
63,
2738,
63,
1574,
8,
65,
12,
13855,
8,
67,
63,
442,
430,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
3430,
17,
5728,
267,
291,
14,
1855,
8,
3393,
12,
2079,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
63,
1574,
12,
282,
12,
13855,
8,
67,
63,
442,
430,
267,
291,
14,
1855,
8,
3393,
12,
2079,
334,
67,
63,
442,
627,
413,
680,
504,
63,
2738,
63,
1574,
12,
282,
12,
3193,
627,
13855,
8,
67,
63,
442,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5577,
492,
627,
199,
646,
1625,
199,
646,
9486,
199,
646,
2882,
199,
199,
533,
1323,
8,
10766,
304,
272,
485,
955,
63,
275,
10003,
67,
63,
442,
401,
286,
63,
442,
1874,
272,
4205,
63,
3527,
275,
756,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
826,
63,
3527,
275,
715,
199,
199,
533,
1379,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
545,
77,
63,
2738,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
8,
65,
9,
398,
612,
275,
1323,
14,
504,
63,
2738,
8,
65,
9,
267,
291,
14,
629,
8,
89,
14,
67,
63,
442,
12,
282,
59,
16,
566,
267,
291,
14,
3334,
8,
89,
14,
826,
63,
3527,
9,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
1012,
398,
282,
59,
16,
467,
282,
1988,
17,
61,
275,
1926,
12,
446,
1840,
267,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
1012,
398,
291,
14,
4080,
8,
65,
12,
671,
423,
1462,
14,
1459,
1012,
398,
291,
14,
1855,
8,
3393,
12,
2079,
286,
63,
442,
14,
504,
63,
2738,
12,
282,
12,
446,
17,
9,
398,
1420,
275,
671,
5873,
267,
2150,
282,
27,
9486,
14,
7112,
7303,
9486,
14,
7112,
7303,
9486,
14,
7112,
342,
267,
291,
14,
629,
8,
88,
23315,
1420,
9,
398,
291,
14,
1855,
8,
4333,
12,
2079,
334,
67,
63,
1560,
627,
3193,
680,
504,
63,
2738,
12,
298,
65,
2,
627,
3193,
9,
339,
347,
511,
63,
545,
77,
63,
2738,
63,
1045,
63,
2743,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
4114,
680,
504,
63,
2738,
8,
65,
12,
13855,
8,
67,
63,
442,
430,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
3430,
17,
5728,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
8,
65,
12,
13855,
8,
67,
63,
442,
1724,
267,
291,
14,
1855,
8,
3393,
12,
2400,
26,
334,
67,
63,
442,
627,
413,
680,
504,
63,
2738,
8,
65,
12,
3193,
627,
13855,
8,
67,
63,
442,
1724,
339,
347,
511,
63,
504,
63,
2738,
63,
1574,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
63,
1574,
8,
65,
9,
398,
612,
275,
1323,
14,
504,
63,
2738,
63,
1574,
8,
65,
9,
267,
291,
14,
629,
8,
89,
14,
67,
63,
442,
12,
282,
59,
16,
566,
267,
291,
14,
3334,
8,
89,
14,
826,
63,
3527,
9,
398,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
282,
59,
16,
467,
282,
1988,
17,
61,
275,
1926,
12,
446,
1840,
267,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
291,
14,
629,
8,
88,
423,
1462,
12,
488,
9,
398,
291,
14,
1855,
8,
3393,
12,
2079,
286,
63,
442,
14,
504,
63,
2738,
12,
282,
12,
446,
17,
9,
398,
2150,
282,
27,
9486,
14,
7112,
7303,
9486,
14,
7112,
7303,
9486,
14,
7112,
342,
267,
291,
14,
629,
8,
88,
23315,
769,
8,
1842,
8,
975,
1724,
398,
671,
275,
334,
67,
63,
1560,
627,
3193,
680,
504,
63,
2738,
63,
1574,
8,
66,
2,
65,
2,
627,
3193,
9,
267,
291,
14,
629,
8,
88,
23315,
330,
2,
65,
2,
627,
3193,
9,
339,
347,
511,
63,
545,
77,
63,
2738,
63,
1574,
63,
1045,
63,
2743,
8,
277,
304,
267,
282,
275,
1625,
14,
1144,
480,
73,
401,
1425,
8,
975,
430,
267,
671,
275,
334,
67,
63,
442,
627,
4114,
680,
504,
63,
2738,
63,
1574,
8,
65,
12,
13855,
8,
67,
63,
442,
430,
398,
291,
14,
629,
8,
88,
23315,
282,
14,
13633,
3430,
17,
5728,
267,
291,
14,
1855,
8,
3393,
12,
2079,
334,
67,
63,
442,
627,
3193,
680,
504,
63,
2738,
63,
1574,
12,
282,
12,
13855,
8,
67,
63,
442,
430,
267,
291,
14,
1855,
8,
3393,
12,
2079,
334,
67,
63,
442,
627,
413,
680,
504,
63,
2738,
63,
1574,
12,
282,
12,
3193,
627,
13855,
8,
67,
63,
442,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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ationsLeafGF(tester, operations):
for op in operations:
apply(op[1], op[2])
tuples = map(None, op[0].xy, op[3])
for tup in tuples:
tester.failIf(tup[0] <= tup[1] - tester.e)
tester.failIf(tup[0] >= tup[1] + tester.e)
class UselessVisitor:
def __init__(self):
self.visited = ""
def visitRectangleGF(self, rectangleGF):
self.ref = rectangleGF
self.visited = "RectangleGF"
def visitOvalGF(self, ovalGF):
self.ref = ovalGF
self.visited = "OvalGF"
def visitPolygonGF(self, polygonGF):
self.ref = polygonGF
self.visited = "PolygonGF"
def visitPolylineGF(self, polylineGF):
self.ref = polylineGF
self.visited = "PolylineGF"
def visitTextGF(self, textGF):
self.ref = textGF
self.visited = "TextGF"
def visitConnectorGF(self, connectorGF):
self.ref = connectorGF
self.visited = "ConnectorGF"
def visitCompositeGF(self, compositeGF):
self.ref = compositeGF
self.visited = "CompositeGF"
#verify that GF is an abstract class and cannot be instantiated
class testGF(unittest.TestCase):
def testNotImplementedGF(self):
"""test failure to instantiate GF"""
self.assertRaises(NotImplementedError, Graphics.GF)
# tests depend on the internal structure of the GF classes
class testLeafGF(unittest.TestCase):
root = Tkinter.Tk()
canvas = Tkinter.Canvas(height = 100, width = 100)
#epsilon. Tolerated error on operations
e = 0.00000000001
def testNotImplementedLeafGF(self):
"""test failure to instantiate LeafGF"""
self.assertRaises(NotImplementedError, Graphics.LeafGF)
def testBoundingBoxLeafGF(self):
"""test LeafGF getApproxBoundingBox"""
#Leaf GFs
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
box = gf.getApproxBoundingBox()
numPoints = len(gf.xy)/2
for i in range(numPoints):
self.failIf(box[0] > round(gf.xy[2*i]))
self.failIf(box[2] < round(gf.xy[2*i]))
self.failIf(box[1] > round(gf.xy[2*i+1]))
self.failIf(box[3] < round(gf.xy[2*i+1]))
def testSetZoomLeafGF(self):
"""test LeafGF setZoom"""
#Leaf GFs
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
gf.setZoom(7.2)
self.assertEqual(gf.zoom, 7.2)
def testLockSanity(self):
"""test lock sanity LeafGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
gf.setLock(1)
self.assertEqual(gf.getLock(), 1)
gf.setLock(0)
self.assertEqual(gf.getLock(), 0)
def testLock(self):
"""test lock LeafGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
old_xy = gf.xy[:]
gf.setLock(1)
gf.translate(2,3)
self.assertEqual(old_xy, gf.xy)
gf.setLock(0)
gf.translate(2,3)
self.assertNotEqual(old_xy, gf.xy)
def testSetFillColorSanity(self):
"""test fill color sanity LeafGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
gf.setFillColor("green")
self.assertEqual(gf.getFillColor(), "green")
def testSetOutlineColorSanity(self):
"""test outline color sanity for LeafGFs with outline"""
leafGFs = [Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)]
for gf in leafGFs:
gf.setOutlineColor("green")
self.assertEqual(gf.getOutlineColor(), "green")
def testTranslateLeafGF(self):
"""test LeafGF translate"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
translations = [(leafGFs[0], leafGFs[0].translate, (3.4, 54.), (4.4, 66.0)),
(leafGFs[1], leafGFs[1].translate, (2.4, 4.), (12.4, 24.0)),
(leafGFs[2], leafGFs[2].translate, (-2., 33.), (-4.0, 36.0, -68.0, 65.3, 0.3, 45.0)),
(leafGFs[3], leafGFs[3].translate, (-2.1, 0.1), (-14.1, 12.33, 63.7, -32.9)),
(leafGFs[4], leafGFs[4].translate, (1.,1.), (2.0, 2.0, 13.0, 13.0)),
(leafGFs[5], leafGFs[5].translate, (4., 3.0), (6.0, 9.0, 8.8, 9.4))]
testOperationsLeafGF(self, translations)
def testRotateLeafGF(self):
"""test LeafGF rotate"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
rotations = [(leafGFs[0], leafGFs[0].rotate, (0, 0, 90), (-12.0, 1.0)),
(leafGFs[1], leafGFs[1].rotate, (0, 0, 180), (-10.0, -20.0)),
(leafGFs[2], leafGFs[2].rotate, (0, 0, 0), (-2.0, 3.0, -66.0, 32.3, 2.3, 12)),
(leafGFs[3], leafGFs[3].rotate, (0, 0, 270), (12.23, 12.0, -33.0, -65.8)),
(leafGFs[4], leafGFs[4].rotate, (0, 0, -90), (1.0, -1.0, 12.0, -12.0)),
(leafGFs[5], leafGFs[5].rotate, (0, 0, 90), (-6.0, 2.0, -6.4, 4.8))]
testOperationsLeafGF(self, rotations)
def testScaleLeafGF(self):
"""test LeafGF scale"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
scalings = [(leafGFs[0], leafGFs[0].scale, (0, 0, 0, 0), (0, 0)),
(leafGFs[1], leafGFs[1].scale, (0, 0, 1.0, 2.0), (10.0, 40.0)),
(leafGFs[2], leafGFs[2].scale, (0, 0, 2.0, 3.0), (-4.0, 9.0, -132.0, 96.9, 4.6, 36)),
(leafGFs[3], leafGFs[3].scale, (0, 0, -1.0, 2.0), (12.0, 24.46, -65.8, -66.0)),
(leafGFs[4], leafGFs[4].scale, (0, 0, 3.0, 3.0), (3.0, 3.0, 36.0, 36.0)),
(leafGFs[5], leafGFs[5].scale, (0, 0, 0.0, 0.5), (0.0, 3.0, 0.0, 3.2))]
testOperationsLeafGF(self, scalings)
#test accept visitor
def testAcceptRectangleGF(self):
"""test accept visitor RectangleGF"""
visitor = UselessVisitor()
rectangleGF = Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
rectangleGF.accept(visitor)
self.assertEqual(visitor.visited, "RectangleGF")
self.failIf(not (visitor.ref is rectangleGF))
def testAcceptOvalGF(self):
"""test accept visitor OvalGF"""
visitor = UselessVisitor()
ovalGF = Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
ovalGF.accept(visitor)
self.assertEqual(visitor.visited, "OvalGF")
self.failIf(not (visitor.ref is ovalGF))
def testAcceptPolygonGF(self):
"""test accept visitor PolygonGF"""
visitor = UselessVisitor()
polygonGF = Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
polygonGF.accept(visitor)
self.assertEqual(visitor.visited, "PolygonGF")
self.failIf(not (visitor.ref is polygonGF))
def testAcceptPolylineGF(self):
"""test accept visitor PolylineGF"""
visitor = UselessVisitor()
polylineGF = Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)
polylineGF.accept(visitor)
self.assertEqual(visitor.visited, "PolylineGF")
self.failIf(not (visitor.ref is polylineGF))
def testAcceptTextGF(self):
"""test accept visitor TextGF"""
visitor = UselessVisitor()
textGF = Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None)
textGF.accept(visitor)
self.assertEqual(visitor.visited, "TextGF")
self.failIf(not (visitor.ref is textGF))
def testAcceptConnectorGF(self):
"""test accept visitor ConnectorGF"""
visitor = UselessVisitor()
connectorGF = Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None)
connectorGF.accept(visitor)
self.assertEqual(visitor.visited, "ConnectorGF")
self.failIf(not (visitor.ref is connectorGF))
#test copy return type
def testCopyTypeRectangleGF(self):
"""test RectangleGF copy return type"""
rectangleGF = Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(rectangleGF.copy(), Graphics.RectangleGF))
def testCopyTypeOvalGF(self):
"""test OvalGF copy return type"""
ovalGF = Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(ovalGF.copy(), Graphics.OvalGF))
def testCopyTypePolygonGF(self):
"""test PolygonGF copy return type"""
polygonGF = Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(polygonGF.copy(), Graphics.PolygonGF))
def testCopyTypePolylineGF(self):
"""test Polyline copy return type"""
polylineGF = Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(polylineGF.copy(), Graphics.PolylineGF))
def testCopyTypeTextGF(self):
"""test TextGF copy return type"""
textGF = Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(textGF.copy(), Graphics.TextGF))
def testCopyTypeConnectorGF(self):
"""test ConnectorGF copy return type"""
connectorGF = Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None)
self.failIf(not isinstance(connectorGF.copy(), Graphics.ConnectorGF))
#test validity of the copy
def testCopyRectangleGF(self):
"""test RectangleGF copy"""
gf = Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.outline, gf2.outline)
self.assertEqual(gf.width, gf2.width)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
def testCopyOvalGF(self):
"""test OvalGF copy"""
gf = Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.outline, gf2.outline)
self.assertEqual(gf.width, gf2.width)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
def testCopyPolygonGF(self):
"""test PolygonGF copy"""
gf = Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 32], "black", "blue", 0, 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.outline, gf2.outline)
self.assertEqual(gf.width, gf2.width)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
def testCopyPolylineGF(self):
"""test Polyline copy"""
gf = Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4, 2.3, 32], "black", 0, 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.width, gf2.width)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
def testCopyTextGF(self):
"""test TextGF copy"""
gf = Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.textCopy, gf2.textCopy)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
def testCopyConnectorGF(self):
"""test ConnectorGF copy"""
gf = Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None)
gf2 = gf.copy()
self.assertEqual(gf.xy, gf2.xy)
self.assertEqual(gf.fill, gf2.fill)
self.assertEqual(gf.outline, gf2.outline)
self.assertEqual(gf.width, gf2.width)
self.assertEqual(gf.isActive, gf2.isActive)
self.assertEqual(gf.isLocked, gf2.isLocked)
self.assertEqual(gf.zoom, gf2.zoom)
class testCompositeGF(unittest.TestCase):
root = Tkinter.Tk()
canvas = Tkinter.Canvas(height = 100, width = 100)
#test accept visitor
def testAcceptCompositeGF(self):
"""test accept visitor CompositeGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None)]
visitor = UselessVisitor()
compositeGF = Graphics.CompositeGF([leafGFs[0], leafGFs[1]], 1, 0, 1.0, None)
compositeGF.accept(visitor)
self.assertEqual(visitor.visited, "CompositeGF")
self.failIf(not (visitor.ref is compositeGF))
def testLockSanity(self):
"""test lock sanity CompositeGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGFs = [Graphics.CompositeGF([leafGFs[0], leafGFs[1]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[1], leafGFs[3]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[1], leafGFs[4]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[3], leafGFs[5]], 1, 0, 1.0, None)]
for gf in compositeGFs:
gf.setLock(1)
self.assertEqual(gf.getLock(), 1)
gf.setLock(0)
self.assertEqual(gf.getLock(), 0)
def testLock(self):
"""test lock sanity CompositeGF"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGFs = [Graphics.CompositeGF([leafGFs[0], leafGFs[1]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[1], leafGFs[3]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[1], leafGFs[4]], 1, 0, 1.0, None),
Graphics.CompositeGF([leafGFs[3], leafGFs[5]], 1, 0, 1.0, None)]
for gf in compositeGFs:
components = gf.getComponents()
oldCoordList = []
for c in components:
oldCoordList.append(c.xy[:])
#lock
gf.setLock(1)
gf.translate(2,2)
newCoordList = []
for c in components:
newCoordList.append(c.xy[:])
tuples = map(None, oldCoordList, newCoordList)
for t in tuples:
self.assertEqual(t[0], t[1])
#now unlock
gf.setLock(0)
gf.translate(2,2)
newCoordList = []
for c in components:
newCoordList.append(c.xy[:])
tuples = map(None, oldCoordList, newCoordList)
for t in tuples:
self.assertNotEqual(t[0], t[1])
def testTranslateCompositeGF(self):
"""test CompositeGF translate"""
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
components = compositeGF.getComponents()
oldCoordLists = []
for c in components:
oldCoordLists.append(c.xy[:])
compositeGF.translate(2,2)
newCoordLists = []
for c in components:
newCoordLists.append(c.xy[:])
listPairs = map(None, oldCoordLists, newCoordLists)
for p in listPairs:
coordPair = map(None, p[0], p[1])
for c in coordPair:
self.assertEqual(c[0] + 2, c[1])
def testRotateCompositeGF(self):
"""test CompositeGF rotate"""
leafGFs = [Graphics.PolygonGF([-2.0, 3.0, -66.0, 32.3, 2.3, 12], "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.OvalGF(-12.0, 12.23, 65.8, -33.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
components = compositeGF.getComponents()
oldCoordLists = []
for c in components:
oldCoordLists.append(c.xy[:])
compositeGF.rotate(0,0,180)
newCoordLists = []
for c in components:
newCoordLists.append(c.xy[:])
listPairs = map(None, oldCoordLists, newCoordLists)
for p in listPairs:
coordPair = map(None, p[0], p[1])
for c in coordPair:
self.assertEqual(-c[0], c[1])
def testScaleCompositeGF(self):
"""test CompositeGF scale"""
leafGFs = [Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
components = compositeGF.getComponents()
oldCoordLists = []
for c in components:
oldCoordLists.append(c.xy[:])
compositeGF.scale(0,0,2,2)
newCoordLists = []
for c in components:
newCoordLists.append(c.xy[:])
listPairs = map(None, oldCoordLists, newCoordLists)
for p in listPairs:
coordPair = map(None, p[0], p[1])
for c in coordPair:
self.assertEqual(2*c[0], c[1])
def testGetComponentsCompositeGF(self):
"""test CompositeGF getComponents"""
leafGFs = [Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
components = compositeGF.getComponents()
self.failIf(not components[0] is leafGFs[0])
self.failIf(not components[1] is leafGFs[1])
def testBoundingBoxCompositeGF(self):
"""test CompositeGF getApproxBoundingBox"""
#Leaf GFs
leafGFs = [Graphics.TextGF(1.0, 12.0, "text", "blue", 1, 0, self.canvas, 1.0, None),
Graphics.ConnectorGF(10.0, 20.0, "black", "blue", 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
box = compositeGF.getApproxBoundingBox()
for gf in leafGFs:
leafBox = gf.getApproxBoundingBox()
self.failIf(box[0] > leafBox[0])
self.failIf(box[2] < leafBox[2])
self.failIf(box[1] > leafBox[1])
self.failIf(box[3] < leafBox[3])
#test copy return type
def testCopyTypeCompositeGF(self):
"""test CompositeGF copy return type"""
leafGFs = [Graphics.RectangleGF(1.0, 1.0, 12.0, 12.0, "black", "blue", 0, 1, 0, self.canvas, 1.0, None),
Graphics.PolylineGF([2.0, 6.0, 4.8, 6.4], "black", 0, 1, 0, self.canvas, 1.0, None)]
compositeGF = Graphics.CompositeGF(leafGFs, 1, 0, 1.0, None)
self.failIf(not isinstance(compositeGF.copy(), Graphics.CompositeGF))
class testGeometry(unittest.TestCase):
rotationTests = [((10.2,30,0,0,0), (10.2,30)),
((10.1,30.0,0,0,90), (-30.0,10.1)),
((10,30,0,0,180), (-10,-30)),
((10,30,0,0,270), (30,-10)),
((10.33,30,5,15,0), (10.33,30)),
((10,30,5,10,90), (-15,15)),
((10,30,5,10,180), (0,-10)),
((10,30,5,10,270), (25,5))]
translationTests = [((1.77,2,0,0), (1.77,2)),
((1,2,1.8,5), (2.8,7))]
scalingTests = [((1,2,0,0,0,0), (0,0)),
((1,2.2,0,0,1,1), (1,2.2)),
((1,2.4,0,0,2,2), (2,4.8)),
((1,2,1,2,0,0), (1,2)),
((1,2,1,2,1,1), (1,2)),
((1,2,1,2,2,2), (1,2)),
((1,2,2,5,0,0), (2,5)),
((1,2,2,5,1,1), (1,2)),
((1,2,2,5,2,2), (0,-1))]
horizontalFlipTests = [((1,2,7),(13,2)),
((1,2,1),(1,2))]
verticalFlipTests = [((1,2,7),(1,12)),
((1,2,2),(1,2))]
def testRotation(self):
"""testing rotation primitive"""
for t in self.rotationTests:
point = Geometry.rotate(t[0][0], t[0][1], t[0][2], t[0][3], t[0][4])
self.assertEqual(point, t[1])
def testTranslation(self):
"""testing translation primitive"""
for t in self.translationTests:
point = Geometry.translate(t[0][0], t[0][1], t[0][2], t[0][3])
self.assertEqual(point, t[1])
def testScaling(self):
"""testing scaling primitive"""
for t in self.scalingTests:
point = Geometry.scale(t[0][0], t[0][1], t[0][2], t[0][3], t[0][4], t[0][5])
self.assertEqual(point, t[1])
if __name__ == "__main__":
unittest.main()
|
gpl-3.0
|
[
646,
2882,
202,
199,
646,
16826,
202,
199,
646,
11513,
2932,
202,
199,
646,
10579,
202,
199,
3,
2366,
18,
14,
18,
511,
18859,
14,
647,
446,
86,
8065,
199,
318,
511,
12929,
20475,
17395,
8,
8234,
12,
5331,
304,
258,
10292,
367,
1687,
315,
5331,
26,
1128,
4838,
8,
411,
59,
17,
467,
1687,
59,
18,
566,
1128,
6346,
275,
2341,
8,
403,
12,
1687,
59,
16,
1055,
1702,
12,
1687,
59,
19,
566,
1128,
367,
16477,
315,
6346,
26,
8608,
17570,
14,
19670,
8,
17034,
59,
16,
61,
2695,
16477,
59,
17,
61,
446,
17570,
14,
69,
9,
8608,
17570,
14,
19670,
8,
17034,
59,
16,
61,
2356,
16477,
59,
17,
61,
435,
17570,
14,
69,
9,
2999,
199,
533,
3645,
2003,
18324,
26,
10292,
347,
636,
826,
721,
277,
304,
1128,
291,
14,
21736,
275,
3087,
25052,
347,
5684,
18127,
17395,
8,
277,
12,
20412,
17395,
304,
1128,
291,
14,
1121,
275,
20412,
17395,
1128,
291,
14,
21736,
275,
298,
18127,
17395,
2,
25052,
347,
5684,
47,
637,
17395,
8,
277,
12,
312,
637,
17395,
304,
1128,
291,
14,
1121,
275,
312,
637,
17395,
1128,
291,
14,
21736,
275,
298,
47,
637,
17395,
2,
25052,
347,
5684,
12367,
17395,
8,
277,
12,
17248,
17395,
304,
1128,
291,
14,
1121,
275,
17248,
17395,
1128,
291,
14,
21736,
275,
298,
12367,
17395,
2,
25052,
347,
5684,
12747,
604,
17395,
8,
277,
12,
8446,
604,
17395,
304,
1128,
291,
14,
1121,
275,
8446,
604,
17395,
1128,
291,
14,
21736,
275,
298,
12747,
604,
17395,
2,
25052,
347,
5684,
1872,
17395,
8,
277,
12,
1318,
17395,
304,
1128,
291,
14,
1121,
275,
1318,
17395,
1128,
291,
14,
21736,
275,
298,
1872,
17395,
2,
25052,
347,
5684,
20476,
17395,
8,
277,
12,
13252,
17395,
304,
1128,
291,
14,
1121,
275,
13252,
17395,
1128,
291,
14,
21736,
275,
298,
20476,
17395,
2,
25052,
347,
5684,
24039,
17395,
8,
277,
12,
19306,
17395,
304,
1128,
291,
14,
1121,
275,
19306,
17395,
1128,
291,
14,
21736,
275,
298,
24039,
17395,
2,
8065,
199,
3,
4712,
626,
598,
38,
365,
376,
9006,
1021,
436,
3913,
506,
17544,
202,
199,
533,
511,
17395,
8,
2796,
14,
1746,
304,
10292,
347,
511,
14278,
17395,
8,
277,
304,
1128,
408,
396,
5988,
370,
17321,
598,
38,
624,
1128,
291,
14,
1855,
8,
18097,
12,
11513,
2932,
14,
17395,
9,
8065,
199,
3,
2295,
11687,
641,
314,
5007,
5523,
402,
314,
598,
38,
3992,
202,
199,
533,
511,
20475,
17395,
8,
2796,
14,
1746,
304,
10292,
1738,
275,
16826,
14,
15189,
342,
10292,
10218,
275,
16826,
14,
15174,
8,
3333,
275,
2948,
12,
3462,
275,
2948,
9,
10292,
327,
15761,
14,
4005,
1435,
972,
1125,
641,
5331,
10292,
325,
275,
378,
14,
20625,
17,
8065,
523,
347,
511,
14278,
20475,
17395,
8,
277,
304,
1128,
408,
396,
5988,
370,
17321,
27836,
17395,
624,
1128,
291,
14,
1855,
8,
18097,
12,
11513,
2932,
14,
20475,
17395,
9,
8065,
523,
347,
511,
8934,
316,
3532,
20475,
17395,
8,
277,
304,
1128,
408,
396,
27836,
17395,
664,
25923,
8094,
1034,
316,
3532,
624,
1128,
327,
20475,
598,
19239,
1128,
11747,
17395,
83,
275,
359,
18859,
14,
1872,
17395,
8,
17,
14,
16,
12,
3144,
14,
16,
12,
298,
505,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
20476,
17395,
8,
709,
14,
16,
12,
3388,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
12367,
17395,
11468,
18,
14,
16,
12,
650,
14,
16,
12,
446,
1272,
14,
16,
12,
4337,
14,
19,
467,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
47,
637,
17395,
2801,
713,
14,
16,
12,
3144,
14,
1789,
12,
11738,
14,
24,
12,
446,
1153,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
18127,
17395,
8,
17,
14,
16,
12,
413,
14,
16,
12,
3144,
14,
16,
12,
3144,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
12747,
604,
17395,
779,
18,
14,
16,
12,
1227,
14,
16,
12,
841,
14,
24,
12,
1227,
14,
20,
467,
298,
8399,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
1874,
1128,
367,
15719,
315,
11747,
17395,
83,
26,
8608,
5689,
275,
15719,
14,
362,
25923,
8094,
1034,
316,
3532,
342,
8608,
1967,
10225,
275,
822,
8,
7102,
14,
1702,
2447,
18,
8608,
367,
284,
315,
1425,
8,
1507,
10225,
304,
1039,
291,
14,
19670,
8,
1977,
59,
16,
61,
690,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
18,
61,
665,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
17,
61,
690,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
11,
17,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
19,
61,
665,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
11,
17,
2459,
8065,
523,
347,
511,
1084,
26798,
20475,
17395,
8,
277,
304,
1128,
408,
396,
27836,
17395,
663,
26798,
624,
1128,
327,
20475,
598,
19239,
1128,
11747,
17395,
83,
275,
359,
18859,
14,
1872,
17395,
8,
17,
14,
16,
12,
3144,
14,
16,
12,
298,
505,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
20476,
17395,
8,
709,
14,
16,
12,
3388,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
12367,
17395,
11468,
18,
14,
16,
12,
650,
14,
16,
12,
446,
1272,
14,
16,
12,
4337,
14,
19,
467,
298,
8399,
401,
298,
6304,
401,
378,
12
] |
[
2882,
202,
199,
646,
16826,
202,
199,
646,
11513,
2932,
202,
199,
646,
10579,
202,
199,
3,
2366,
18,
14,
18,
511,
18859,
14,
647,
446,
86,
8065,
199,
318,
511,
12929,
20475,
17395,
8,
8234,
12,
5331,
304,
258,
10292,
367,
1687,
315,
5331,
26,
1128,
4838,
8,
411,
59,
17,
467,
1687,
59,
18,
566,
1128,
6346,
275,
2341,
8,
403,
12,
1687,
59,
16,
1055,
1702,
12,
1687,
59,
19,
566,
1128,
367,
16477,
315,
6346,
26,
8608,
17570,
14,
19670,
8,
17034,
59,
16,
61,
2695,
16477,
59,
17,
61,
446,
17570,
14,
69,
9,
8608,
17570,
14,
19670,
8,
17034,
59,
16,
61,
2356,
16477,
59,
17,
61,
435,
17570,
14,
69,
9,
2999,
199,
533,
3645,
2003,
18324,
26,
10292,
347,
636,
826,
721,
277,
304,
1128,
291,
14,
21736,
275,
3087,
25052,
347,
5684,
18127,
17395,
8,
277,
12,
20412,
17395,
304,
1128,
291,
14,
1121,
275,
20412,
17395,
1128,
291,
14,
21736,
275,
298,
18127,
17395,
2,
25052,
347,
5684,
47,
637,
17395,
8,
277,
12,
312,
637,
17395,
304,
1128,
291,
14,
1121,
275,
312,
637,
17395,
1128,
291,
14,
21736,
275,
298,
47,
637,
17395,
2,
25052,
347,
5684,
12367,
17395,
8,
277,
12,
17248,
17395,
304,
1128,
291,
14,
1121,
275,
17248,
17395,
1128,
291,
14,
21736,
275,
298,
12367,
17395,
2,
25052,
347,
5684,
12747,
604,
17395,
8,
277,
12,
8446,
604,
17395,
304,
1128,
291,
14,
1121,
275,
8446,
604,
17395,
1128,
291,
14,
21736,
275,
298,
12747,
604,
17395,
2,
25052,
347,
5684,
1872,
17395,
8,
277,
12,
1318,
17395,
304,
1128,
291,
14,
1121,
275,
1318,
17395,
1128,
291,
14,
21736,
275,
298,
1872,
17395,
2,
25052,
347,
5684,
20476,
17395,
8,
277,
12,
13252,
17395,
304,
1128,
291,
14,
1121,
275,
13252,
17395,
1128,
291,
14,
21736,
275,
298,
20476,
17395,
2,
25052,
347,
5684,
24039,
17395,
8,
277,
12,
19306,
17395,
304,
1128,
291,
14,
1121,
275,
19306,
17395,
1128,
291,
14,
21736,
275,
298,
24039,
17395,
2,
8065,
199,
3,
4712,
626,
598,
38,
365,
376,
9006,
1021,
436,
3913,
506,
17544,
202,
199,
533,
511,
17395,
8,
2796,
14,
1746,
304,
10292,
347,
511,
14278,
17395,
8,
277,
304,
1128,
408,
396,
5988,
370,
17321,
598,
38,
624,
1128,
291,
14,
1855,
8,
18097,
12,
11513,
2932,
14,
17395,
9,
8065,
199,
3,
2295,
11687,
641,
314,
5007,
5523,
402,
314,
598,
38,
3992,
202,
199,
533,
511,
20475,
17395,
8,
2796,
14,
1746,
304,
10292,
1738,
275,
16826,
14,
15189,
342,
10292,
10218,
275,
16826,
14,
15174,
8,
3333,
275,
2948,
12,
3462,
275,
2948,
9,
10292,
327,
15761,
14,
4005,
1435,
972,
1125,
641,
5331,
10292,
325,
275,
378,
14,
20625,
17,
8065,
523,
347,
511,
14278,
20475,
17395,
8,
277,
304,
1128,
408,
396,
5988,
370,
17321,
27836,
17395,
624,
1128,
291,
14,
1855,
8,
18097,
12,
11513,
2932,
14,
20475,
17395,
9,
8065,
523,
347,
511,
8934,
316,
3532,
20475,
17395,
8,
277,
304,
1128,
408,
396,
27836,
17395,
664,
25923,
8094,
1034,
316,
3532,
624,
1128,
327,
20475,
598,
19239,
1128,
11747,
17395,
83,
275,
359,
18859,
14,
1872,
17395,
8,
17,
14,
16,
12,
3144,
14,
16,
12,
298,
505,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
20476,
17395,
8,
709,
14,
16,
12,
3388,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
12367,
17395,
11468,
18,
14,
16,
12,
650,
14,
16,
12,
446,
1272,
14,
16,
12,
4337,
14,
19,
467,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
47,
637,
17395,
2801,
713,
14,
16,
12,
3144,
14,
1789,
12,
11738,
14,
24,
12,
446,
1153,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
18127,
17395,
8,
17,
14,
16,
12,
413,
14,
16,
12,
3144,
14,
16,
12,
3144,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
12747,
604,
17395,
779,
18,
14,
16,
12,
1227,
14,
16,
12,
841,
14,
24,
12,
1227,
14,
20,
467,
298,
8399,
401,
378,
12,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
1874,
1128,
367,
15719,
315,
11747,
17395,
83,
26,
8608,
5689,
275,
15719,
14,
362,
25923,
8094,
1034,
316,
3532,
342,
8608,
1967,
10225,
275,
822,
8,
7102,
14,
1702,
2447,
18,
8608,
367,
284,
315,
1425,
8,
1507,
10225,
304,
1039,
291,
14,
19670,
8,
1977,
59,
16,
61,
690,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
18,
61,
665,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
17,
61,
690,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
11,
17,
2459,
1039,
291,
14,
19670,
8,
1977,
59,
19,
61,
665,
6168,
8,
7102,
14,
1702,
59,
18,
10,
73,
11,
17,
2459,
8065,
523,
347,
511,
1084,
26798,
20475,
17395,
8,
277,
304,
1128,
408,
396,
27836,
17395,
663,
26798,
624,
1128,
327,
20475,
598,
19239,
1128,
11747,
17395,
83,
275,
359,
18859,
14,
1872,
17395,
8,
17,
14,
16,
12,
3144,
14,
16,
12,
298,
505,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14,
20476,
17395,
8,
709,
14,
16,
12,
3388,
14,
16,
12,
298,
8399,
401,
298,
6304,
401,
413,
12,
378,
12,
291,
14,
7682,
12,
413,
14,
16,
12,
488,
395,
27514,
11513,
2932,
14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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
notmyname/swift
|
test/unit/proxy/controllers/test_info.py
|
12
|
12321
|
# Copyright (c) 2010-2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import unittest
import time
from mock import Mock
from swift.proxy.controllers import InfoController
from swift.proxy.server import Application as ProxyApp
from swift.common import utils
from swift.common.swob import Request, HTTPException
class TestInfoController(unittest.TestCase):
def setUp(self):
utils._swift_info = {}
utils._swift_admin_info = {}
def get_controller(self, expose_info=None, disallowed_sections=None,
admin_key=None):
disallowed_sections = disallowed_sections or []
app = Mock(spec=ProxyApp)
return InfoController(app, None, expose_info,
disallowed_sections, admin_key)
def start_response(self, status, headers):
self.got_statuses.append(status)
for h in headers:
self.got_headers.append({h[0]: h[1]})
def test_disabled_info(self):
controller = self.get_controller(expose_info=False)
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('403 Forbidden', str(resp))
def test_get_info(self):
controller = self.get_controller(expose_info=True)
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body)
self.assertNotIn('admin', info)
self.assertIn('foo', info)
self.assertIn('bar', info['foo'])
self.assertEqual(info['foo']['bar'], 'baz')
def test_options_info(self):
controller = self.get_controller(expose_info=True)
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'GET'})
resp = controller.OPTIONS(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
self.assertIn('Allow', resp.headers)
def test_get_info_cors(self):
controller = self.get_controller(expose_info=True)
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'GET'},
headers={'Origin': 'http://example.com'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body)
self.assertNotIn('admin', info)
self.assertIn('foo', info)
self.assertIn('bar', info['foo'])
self.assertEqual(info['foo']['bar'], 'baz')
self.assertIn('Access-Control-Allow-Origin', resp.headers)
self.assertIn('Access-Control-Expose-Headers', resp.headers)
def test_head_info(self):
controller = self.get_controller(expose_info=True)
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'HEAD'})
resp = controller.HEAD(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
def test_disallow_info(self):
controller = self.get_controller(expose_info=True,
disallowed_sections=['foo2'])
utils._swift_info = {'foo': {'bar': 'baz'},
'foo2': {'bar2': 'baz2'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
req = Request.blank(
'/info', environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body)
self.assertIn('foo', info)
self.assertIn('bar', info['foo'])
self.assertEqual(info['foo']['bar'], 'baz')
self.assertNotIn('foo2', info)
def test_disabled_admin_info(self):
controller = self.get_controller(expose_info=True, admin_key='')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/info', expires, '')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('403 Forbidden', str(resp))
def test_get_admin_info(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body)
self.assertIn('admin', info)
self.assertIn('qux', info['admin'])
self.assertIn('quux', info['admin']['qux'])
self.assertEqual(info['admin']['qux']['quux'], 'corge')
def test_head_admin_info(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'HEAD'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
expires = int(time.time() + 86400)
sig = utils.get_hmac('HEAD', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'HEAD'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
def test_get_admin_info_invalid_method(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('HEAD', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('401 Unauthorized', str(resp))
def test_get_admin_info_invalid_expires(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = 1
sig = utils.get_hmac('GET', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('401 Unauthorized', str(resp))
expires = 'abc'
sig = utils.get_hmac('GET', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('401 Unauthorized', str(resp))
def test_get_admin_info_invalid_path(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/foo', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('401 Unauthorized', str(resp))
def test_get_admin_info_invalid_key(self):
controller = self.get_controller(expose_info=True,
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/foo', expires, 'invalid-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('401 Unauthorized', str(resp))
def test_admin_disallow_info(self):
controller = self.get_controller(expose_info=True,
disallowed_sections=['foo2'],
admin_key='secret-admin-key')
utils._swift_info = {'foo': {'bar': 'baz'},
'foo2': {'bar2': 'baz2'}}
utils._swift_admin_info = {'qux': {'quux': 'corge'}}
expires = int(time.time() + 86400)
sig = utils.get_hmac('GET', '/info', expires, 'secret-admin-key')
path = '/info?swiftinfo_sig={sig}&swiftinfo_expires={expires}'.format(
sig=sig, expires=expires)
req = Request.blank(
path, environ={'REQUEST_METHOD': 'GET'})
resp = controller.GET(req)
self.assertIsInstance(resp, HTTPException)
self.assertEqual('200 OK', str(resp))
info = json.loads(resp.body)
self.assertNotIn('foo2', info)
self.assertIn('admin', info)
self.assertIn('disallowed_sections', info['admin'])
self.assertIn('foo2', info['admin']['disallowed_sections'])
self.assertIn('qux', info['admin'])
self.assertIn('quux', info['admin']['qux'])
self.assertEqual(info['admin']['qux']['quux'], 'corge')
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
646,
2882,
199,
646,
900,
199,
504,
1683,
492,
4420,
199,
199,
504,
16275,
14,
3280,
14,
20531,
492,
10332,
7506,
199,
504,
16275,
14,
3280,
14,
1000,
492,
13515,
465,
12373,
2640,
199,
504,
16275,
14,
2330,
492,
3778,
199,
504,
16275,
14,
2330,
14,
83,
32517,
492,
4784,
12,
28185,
421,
199,
533,
1379,
2354,
7506,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
3778,
423,
13215,
63,
815,
275,
1052,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
1052,
339,
347,
664,
63,
5538,
8,
277,
12,
23705,
63,
815,
29,
403,
12,
30994,
63,
7786,
29,
403,
12,
2432,
4628,
63,
498,
29,
403,
304,
267,
30994,
63,
7786,
275,
30994,
63,
7786,
503,
942,
398,
1145,
275,
4420,
8,
1650,
29,
4936,
2640,
9,
267,
372,
10332,
7506,
8,
571,
12,
488,
12,
23705,
63,
815,
12,
2892,
30994,
63,
7786,
12,
4628,
63,
498,
9,
339,
347,
1343,
63,
1310,
8,
277,
12,
2004,
12,
2323,
304,
267,
291,
14,
7808,
63,
17084,
14,
740,
8,
1205,
9,
267,
367,
394,
315,
2323,
26,
288,
291,
14,
7808,
63,
2139,
14,
740,
2561,
72,
59,
16,
2189,
394,
59,
17,
13412,
339,
347,
511,
63,
7011,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
797,
9,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
13353,
2104,
10912,
297,
620,
8,
4518,
430,
339,
347,
511,
63,
362,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
2256,
275,
2022,
14,
3640,
8,
4518,
14,
2030,
9,
267,
291,
14,
8795,
360,
2113,
297,
2256,
9,
267,
291,
14,
4080,
360,
1421,
297,
2256,
9,
267,
291,
14,
4080,
360,
1700,
297,
2256,
459,
1421,
1105,
267,
291,
14,
629,
8,
815,
459,
1421,
2545,
1700,
995,
283,
6185,
358,
339,
347,
511,
63,
1419,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
8808,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
291,
14,
4080,
360,
7852,
297,
3085,
14,
2139,
9,
339,
347,
511,
63,
362,
63,
815,
63,
30967,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
2267,
288,
2323,
3713,
12834,
356,
283,
1014,
921,
2694,
14,
957,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
2256,
275,
2022,
14,
3640,
8,
4518,
14,
2030,
9,
267,
291,
14,
8795,
360,
2113,
297,
2256,
9,
267,
291,
14,
4080,
360,
1421,
297,
2256,
9,
267,
291,
14,
4080,
360,
1700,
297,
2256,
459,
1421,
1105,
267,
291,
14,
629,
8,
815,
459,
1421,
2545,
1700,
995,
283,
6185,
358,
267,
291,
14,
4080,
360,
3946,
13,
3717,
13,
7852,
13,
12834,
297,
3085,
14,
2139,
9,
267,
291,
14,
4080,
360,
3946,
13,
3717,
13,
920,
4070,
13,
9883,
297,
3085,
14,
2139,
9,
339,
347,
511,
63,
2993,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
5211,
3071,
267,
3085,
275,
7614,
14,
5211,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
339,
347,
511,
63,
2297,
3306,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549
] |
[
1898,
334,
67,
9,
7129,
13,
7409,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2022,
199,
646,
2882,
199,
646,
900,
199,
504,
1683,
492,
4420,
199,
199,
504,
16275,
14,
3280,
14,
20531,
492,
10332,
7506,
199,
504,
16275,
14,
3280,
14,
1000,
492,
13515,
465,
12373,
2640,
199,
504,
16275,
14,
2330,
492,
3778,
199,
504,
16275,
14,
2330,
14,
83,
32517,
492,
4784,
12,
28185,
421,
199,
533,
1379,
2354,
7506,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
3778,
423,
13215,
63,
815,
275,
1052,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
1052,
339,
347,
664,
63,
5538,
8,
277,
12,
23705,
63,
815,
29,
403,
12,
30994,
63,
7786,
29,
403,
12,
2432,
4628,
63,
498,
29,
403,
304,
267,
30994,
63,
7786,
275,
30994,
63,
7786,
503,
942,
398,
1145,
275,
4420,
8,
1650,
29,
4936,
2640,
9,
267,
372,
10332,
7506,
8,
571,
12,
488,
12,
23705,
63,
815,
12,
2892,
30994,
63,
7786,
12,
4628,
63,
498,
9,
339,
347,
1343,
63,
1310,
8,
277,
12,
2004,
12,
2323,
304,
267,
291,
14,
7808,
63,
17084,
14,
740,
8,
1205,
9,
267,
367,
394,
315,
2323,
26,
288,
291,
14,
7808,
63,
2139,
14,
740,
2561,
72,
59,
16,
2189,
394,
59,
17,
13412,
339,
347,
511,
63,
7011,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
797,
9,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
13353,
2104,
10912,
297,
620,
8,
4518,
430,
339,
347,
511,
63,
362,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
2256,
275,
2022,
14,
3640,
8,
4518,
14,
2030,
9,
267,
291,
14,
8795,
360,
2113,
297,
2256,
9,
267,
291,
14,
4080,
360,
1421,
297,
2256,
9,
267,
291,
14,
4080,
360,
1700,
297,
2256,
459,
1421,
1105,
267,
291,
14,
629,
8,
815,
459,
1421,
2545,
1700,
995,
283,
6185,
358,
339,
347,
511,
63,
1419,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
3071,
267,
3085,
275,
7614,
14,
8808,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
291,
14,
4080,
360,
7852,
297,
3085,
14,
2139,
9,
339,
347,
511,
63,
362,
63,
815,
63,
30967,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
2970,
2267,
288,
2323,
3713,
12834,
356,
283,
1014,
921,
2694,
14,
957,
3071,
267,
3085,
275,
7614,
14,
2970,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
267,
2256,
275,
2022,
14,
3640,
8,
4518,
14,
2030,
9,
267,
291,
14,
8795,
360,
2113,
297,
2256,
9,
267,
291,
14,
4080,
360,
1421,
297,
2256,
9,
267,
291,
14,
4080,
360,
1700,
297,
2256,
459,
1421,
1105,
267,
291,
14,
629,
8,
815,
459,
1421,
2545,
1700,
995,
283,
6185,
358,
267,
291,
14,
4080,
360,
3946,
13,
3717,
13,
7852,
13,
12834,
297,
3085,
14,
2139,
9,
267,
291,
14,
4080,
360,
3946,
13,
3717,
13,
920,
4070,
13,
9883,
297,
3085,
14,
2139,
9,
339,
347,
511,
63,
2993,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
9,
267,
3778,
423,
13215,
63,
815,
275,
791,
1421,
356,
791,
1700,
356,
283,
6185,
18620,
267,
3778,
423,
13215,
63,
2113,
63,
815,
275,
791,
27519,
356,
791,
32050,
356,
283,
989,
303,
18620,
398,
2648,
275,
4784,
14,
2500,
8,
288,
1994,
815,
297,
6160,
3713,
6780,
63,
9977,
356,
283,
5211,
3071,
267,
3085,
275,
7614,
14,
5211,
8,
2103,
9,
267,
291,
14,
6926,
8,
4518,
12,
28185,
9,
267,
291,
14,
629,
360,
1840,
9949,
297,
620,
8,
4518,
430,
339,
347,
511,
63,
2297,
3306,
63,
815,
8,
277,
304,
267,
7614,
275,
291,
14,
362,
63,
5538,
8,
20586,
63,
815,
29,
549,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mortada/tensorflow
|
tensorflow/contrib/distributions/python/kernel_tests/bijectors/sigmoid_test.py
|
72
|
2402
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Sigmoid Tests."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from scipy import special
from tensorflow.contrib.distributions.python.ops.bijectors.sigmoid import Sigmoid
from tensorflow.python.ops.distributions.bijector_test_util import assert_bijective_and_finite
from tensorflow.python.ops.distributions.bijector_test_util import assert_scalar_congruency
from tensorflow.python.platform import test
class SigmoidBijectorTest(test.TestCase):
"""Tests correctness of the Y = g(X) = (1 + exp(-X))^-1 transformation."""
def testBijector(self):
with self.test_session():
self.assertEqual("sigmoid", Sigmoid().name)
x = np.linspace(-10., 10., 100).reshape([2, 5, 10]).astype(np.float32)
y = special.expit(x)
ildj = -np.log(y) - np.log1p(-y)
self.assertAllClose(y, Sigmoid().forward(x).eval(), atol=0., rtol=1e-2)
self.assertAllClose(x, Sigmoid().inverse(y).eval(), atol=0., rtol=1e-4)
self.assertAllClose(ildj, Sigmoid().inverse_log_det_jacobian(y).eval(),
atol=0., rtol=1e-6)
self.assertAllClose(-ildj, Sigmoid().forward_log_det_jacobian(x).eval(),
atol=0., rtol=1e-4)
def testScalarCongruency(self):
with self.test_session():
assert_scalar_congruency(Sigmoid(), lower_x=-7., upper_x=7.)
def testBijectiveAndFinite(self):
with self.test_session():
x = np.linspace(-7., 7., 100).astype(np.float32)
eps = 1e-3
y = np.linspace(eps, 1. - eps, 100).astype(np.float32)
assert_bijective_and_finite(Sigmoid(), x, y, atol=0., rtol=1e-4)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
11575,
14356,
6496,
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,
504,
7026,
492,
4539,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4492,
963,
1384,
14,
20035,
492,
14625,
14356,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4492,
19625,
63,
396,
63,
1974,
492,
702,
63,
4492,
74,
6850,
63,
460,
63,
8005,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4492,
19625,
63,
396,
63,
1974,
492,
702,
63,
7033,
63,
388,
2587,
85,
9501,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
14625,
14356,
17975,
19625,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
29102,
402,
314,
1488,
275,
486,
8,
56,
9,
275,
334,
17,
435,
1437,
2801,
56,
430,
26185,
17,
13315,
1041,
819,
347,
511,
17975,
19625,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
629,
480,
20035,
401,
14625,
14356,
1252,
354,
9,
489,
671,
275,
980,
14,
11649,
2801,
709,
2020,
1616,
2020,
2948,
680,
5217,
779,
18,
12,
959,
12,
1616,
6575,
6041,
8,
1590,
14,
1609,
708,
9,
489,
612,
275,
4539,
14,
1474,
390,
8,
88,
9,
489,
284,
1447,
74,
275,
446,
1590,
14,
793,
8,
89,
9,
446,
980,
14,
793,
17,
80,
2801,
89,
9,
489,
291,
14,
7260,
8,
89,
12,
14625,
14356,
1252,
6688,
8,
88,
680,
2579,
1062,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
18,
9,
489,
291,
14,
7260,
8,
88,
12,
14625,
14356,
1252,
11668,
8,
89,
680,
2579,
1062,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
489,
291,
14,
7260,
8,
668,
74,
12,
14625,
14356,
1252,
11668,
63,
793,
63,
9886,
63,
27342,
8,
89,
680,
2579,
1062,
2079,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
22,
9,
489,
291,
14,
7260,
2801,
668,
74,
12,
14625,
14356,
1252,
6688,
63,
793,
63,
9886,
63,
27342,
8,
88,
680,
2579,
1062,
2079,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
819,
347,
511,
13090,
714,
2587,
85,
9501,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
702,
63,
7033,
63,
388,
2587,
85,
9501,
8,
11575,
14356,
1062,
5117,
63,
88,
4022,
23,
2020,
7008,
63,
88,
29,
23,
4959,
819,
347,
511,
34,
7879,
6850,
3325,
8694,
1175,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
671,
275,
980,
14,
11649,
2801,
23,
2020,
1520,
2020,
2948,
680,
6041,
8,
1590,
14,
1609,
708,
9,
489,
10245,
275,
413,
69,
13,
19,
489,
612,
275,
980,
14,
11649,
8,
8277,
12,
413,
14,
446,
10245,
12,
2948,
680,
6041,
8,
1590,
14,
1609,
708,
9,
489,
702,
63,
4492,
74,
6850,
63,
460,
63,
8005,
8,
11575,
14356,
1062,
671,
12,
612,
12,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
11575,
14356,
6496,
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,
504,
7026,
492,
4539,
199,
199,
504,
3228,
14,
2828,
14,
5613,
14,
1548,
14,
1483,
14,
4492,
963,
1384,
14,
20035,
492,
14625,
14356,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4492,
19625,
63,
396,
63,
1974,
492,
702,
63,
4492,
74,
6850,
63,
460,
63,
8005,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
14,
4492,
19625,
63,
396,
63,
1974,
492,
702,
63,
7033,
63,
388,
2587,
85,
9501,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
14625,
14356,
17975,
19625,
774,
8,
396,
14,
1746,
304,
523,
408,
2925,
29102,
402,
314,
1488,
275,
486,
8,
56,
9,
275,
334,
17,
435,
1437,
2801,
56,
430,
26185,
17,
13315,
1041,
819,
347,
511,
17975,
19625,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
291,
14,
629,
480,
20035,
401,
14625,
14356,
1252,
354,
9,
489,
671,
275,
980,
14,
11649,
2801,
709,
2020,
1616,
2020,
2948,
680,
5217,
779,
18,
12,
959,
12,
1616,
6575,
6041,
8,
1590,
14,
1609,
708,
9,
489,
612,
275,
4539,
14,
1474,
390,
8,
88,
9,
489,
284,
1447,
74,
275,
446,
1590,
14,
793,
8,
89,
9,
446,
980,
14,
793,
17,
80,
2801,
89,
9,
489,
291,
14,
7260,
8,
89,
12,
14625,
14356,
1252,
6688,
8,
88,
680,
2579,
1062,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
18,
9,
489,
291,
14,
7260,
8,
88,
12,
14625,
14356,
1252,
11668,
8,
89,
680,
2579,
1062,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
489,
291,
14,
7260,
8,
668,
74,
12,
14625,
14356,
1252,
11668,
63,
793,
63,
9886,
63,
27342,
8,
89,
680,
2579,
1062,
2079,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
22,
9,
489,
291,
14,
7260,
2801,
668,
74,
12,
14625,
14356,
1252,
6688,
63,
793,
63,
9886,
63,
27342,
8,
88,
680,
2579,
1062,
2079,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
819,
347,
511,
13090,
714,
2587,
85,
9501,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
702,
63,
7033,
63,
388,
2587,
85,
9501,
8,
11575,
14356,
1062,
5117,
63,
88,
4022,
23,
2020,
7008,
63,
88,
29,
23,
4959,
819,
347,
511,
34,
7879,
6850,
3325,
8694,
1175,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
837,
489,
671,
275,
980,
14,
11649,
2801,
23,
2020,
1520,
2020,
2948,
680,
6041,
8,
1590,
14,
1609,
708,
9,
489,
10245,
275,
413,
69,
13,
19,
489,
612,
275,
980,
14,
11649,
8,
8277,
12,
413,
14,
446,
10245,
12,
2948,
680,
6041,
8,
1590,
14,
1609,
708,
9,
489,
702,
63,
4492,
74,
6850,
63,
460,
63,
8005,
8,
11575,
14356,
1062,
671,
12,
612,
12,
9543,
29,
16,
2020,
10561,
29,
17,
69,
13,
20,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
511,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
betoesquivel/fil2014
|
build/django/django/core/servers/basehttp.py
|
62
|
6111
|
"""
HTTP server that implements the Python WSGI protocol (PEP 333, rev 1.21).
Based on wsgiref.simple_server which is part of the standard library since 2.5.
This is a simple server for use in testing or debugging Django apps. It hasn't
been reviewed for security issues. DON'T USE IT FOR PRODUCTION USE!
"""
from __future__ import unicode_literals
from io import BytesIO
import socket
import sys
import traceback
from wsgiref import simple_server
from wsgiref.util import FileWrapper # for backwards compatibility
from django.core.management.color import color_style
from django.core.wsgi import get_wsgi_application
from django.utils.module_loading import import_by_path
from django.utils import six
from django.utils.six.moves.urllib.parse import urljoin
from django.utils.six.moves import socketserver
__all__ = ('WSGIServer', 'WSGIRequestHandler', 'MAX_SOCKET_CHUNK_SIZE')
# If data is too large, socket will choke, so write chunks no larger than 32MB
# at a time. The rationale behind the 32MB can be found on Django's Trac:
# https://code.djangoproject.com/ticket/5596#comment:4
MAX_SOCKET_CHUNK_SIZE = 32 * 1024 * 1024 # 32 MB
def get_internal_wsgi_application():
"""
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``.
This function, and the ``WSGI_APPLICATION`` setting itself, are only useful
for Django's internal servers (runserver, runfcgi); external WSGI servers
should just be configured to point to the correct application object
directly.
If settings.WSGI_APPLICATION is not set (is ``None``), we just return
whatever ``django.core.wsgi.get_wsgi_application`` returns.
"""
from django.conf import settings
app_path = getattr(settings, 'WSGI_APPLICATION')
if app_path is None:
return get_wsgi_application()
return import_by_path(
app_path,
error_prefix="WSGI application '%s' could not be loaded; " % app_path
)
class ServerHandler(simple_server.ServerHandler, object):
error_status = str("500 INTERNAL SERVER ERROR")
def write(self, data):
"""'write()' callable as specified by PEP 3333"""
assert isinstance(data, bytes), "write() argument must be bytestring"
if not self.status:
raise AssertionError("write() before start_response()")
elif not self.headers_sent:
# Before the first output, send the stored headers
self.bytes_sent = len(data) # make sure we know content-length
self.send_headers()
else:
self.bytes_sent += len(data)
# XXX check Content-Length and truncate if too many bytes written?
data = BytesIO(data)
for chunk in iter(lambda: data.read(MAX_SOCKET_CHUNK_SIZE), b''):
self._write(chunk)
self._flush()
def error_output(self, environ, start_response):
super(ServerHandler, self).error_output(environ, start_response)
return ['\n'.join(traceback.format_exception(*sys.exc_info()))]
# Backport of http://hg.python.org/cpython/rev/d5af1b235dab. See #16241.
# This can be removed when support for Python <= 2.7.3 is deprecated.
def finish_response(self):
try:
if not self.result_is_file() or not self.sendfile():
for data in self.result:
self.write(data)
self.finish_content()
finally:
self.close()
class WSGIServer(simple_server.WSGIServer, object):
"""BaseHTTPServer that implements the Python WSGI protocol"""
request_queue_size = 10
def __init__(self, *args, **kwargs):
if kwargs.pop('ipv6', False):
self.address_family = socket.AF_INET6
super(WSGIServer, self).__init__(*args, **kwargs)
def server_bind(self):
"""Override server_bind to store the server name."""
super(WSGIServer, self).server_bind()
self.setup_environ()
class WSGIRequestHandler(simple_server.WSGIRequestHandler, object):
def __init__(self, *args, **kwargs):
from django.conf import settings
self.admin_static_prefix = urljoin(settings.STATIC_URL, 'admin/')
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
self.style = color_style()
super(WSGIRequestHandler, self).__init__(*args, **kwargs)
def address_string(self):
# Short-circuit parent method to not call socket.getfqdn
return self.client_address[0]
def log_message(self, format, *args):
# Don't bother logging requests for admin images or the favicon.
if (self.path.startswith(self.admin_static_prefix)
or self.path == '/favicon.ico'):
return
msg = "[%s] %s\n" % (self.log_date_time_string(), format % args)
# Utilize terminal colors, if available
if args[1][0] == '2':
# Put 2XX first, since it should be the common case
msg = self.style.HTTP_SUCCESS(msg)
elif args[1][0] == '1':
msg = self.style.HTTP_INFO(msg)
elif args[1] == '304':
msg = self.style.HTTP_NOT_MODIFIED(msg)
elif args[1][0] == '3':
msg = self.style.HTTP_REDIRECT(msg)
elif args[1] == '404':
msg = self.style.HTTP_NOT_FOUND(msg)
elif args[1][0] == '4':
msg = self.style.HTTP_BAD_REQUEST(msg)
else:
# Any 5XX, or any other response
msg = self.style.HTTP_SERVER_ERROR(msg)
sys.stderr.write(msg)
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
server_address = (addr, port)
if threading:
httpd_cls = type(str('WSGIServer'), (socketserver.ThreadingMixIn, WSGIServer), {})
else:
httpd_cls = WSGIServer
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
httpd.set_app(wsgi_handler)
httpd.serve_forever()
|
mit
|
[
624,
199,
2856,
1654,
626,
9031,
314,
2018,
9279,
4113,
334,
25633,
23792,
12,
6822,
413,
14,
2025,
680,
199,
199,
20409,
641,
12464,
1121,
14,
4129,
63,
1000,
1314,
365,
1777,
402,
314,
4465,
3555,
3967,
499,
14,
21,
14,
199,
199,
2765,
365,
282,
3486,
1654,
367,
675,
315,
5343,
503,
10201,
5634,
8686,
14,
2779,
18699,
1133,
199,
1235,
287,
11248,
379,
367,
6391,
10876,
14,
577,
615,
7,
52,
4815,
473,
52,
2381,
3611,
4980,
5430,
4815,
1,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
5890,
492,
11808,
199,
646,
2838,
199,
646,
984,
199,
646,
5190,
199,
504,
12464,
1121,
492,
3486,
63,
1000,
199,
504,
12464,
1121,
14,
1974,
492,
3814,
4590,
257,
327,
367,
8552,
7163,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
991,
63,
515,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
2838,
1000,
199,
199,
363,
452,
363,
275,
661,
55,
28732,
297,
283,
16828,
11149,
297,
283,
4283,
63,
17462,
63,
20512,
63,
4305,
358,
421,
199,
3,
982,
666,
365,
4634,
7031,
12,
2838,
911,
2468,
415,
12,
880,
2218,
8291,
949,
12142,
2419,
4337,
4567,
199,
3,
737,
282,
900,
14,
710,
660,
296,
1895,
22172,
314,
4337,
4567,
883,
506,
1911,
641,
5634,
1159,
377,
6457,
26,
199,
3,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
1229,
2534,
3,
3349,
26,
20,
199,
4283,
63,
17462,
63,
20512,
63,
4305,
275,
4337,
627,
6619,
627,
6619,
221,
327,
4337,
19487,
421,
199,
318,
664,
63,
4672,
63,
6508,
63,
3578,
837,
272,
408,
272,
30367,
436,
2529,
314,
9279,
4223,
465,
7526,
701,
314,
922,
315,
272,
1124,
1751,
14,
16828,
63,
24051,
4345,
8777,
314,
849,
1124,
928,
1715,
1040,
7054,
12,
272,
642,
911,
506,
314,
1124,
3578,
1040,
909,
315,
1124,
1715,
354,
15,
6508,
14,
647,
4345,
339,
961,
805,
12,
436,
314,
1124,
16828,
63,
24051,
1040,
4260,
6337,
12,
787,
1454,
2997,
272,
367,
5634,
1159,
5007,
8037,
334,
1065,
1000,
12,
1255,
30076,
2736,
5957,
9279,
8037,
272,
1077,
2951,
506,
7526,
370,
2376,
370,
314,
3211,
4223,
909,
272,
5370,
14,
339,
982,
2202,
14,
16828,
63,
24051,
365,
440,
663,
334,
374,
1124,
403,
1040,
395,
781,
2951,
372,
272,
15685,
1124,
1176,
14,
1018,
14,
6508,
14,
362,
63,
6508,
63,
3578,
1040,
2529,
14,
339,
408,
272,
687,
1639,
14,
2190,
492,
2202,
272,
1145,
63,
515,
275,
2519,
8,
1751,
12,
283,
16828,
63,
24051,
358,
272,
340,
1145,
63,
515,
365,
488,
26,
267,
372,
664,
63,
6508,
63,
3578,
342,
339,
372,
492,
63,
991,
63,
515,
8,
267,
1145,
63,
515,
12,
267,
1125,
63,
1861,
628,
16828,
4223,
1543,
83,
7,
4293,
440,
506,
6511,
27,
298,
450,
1145,
63,
515,
272,
776,
421,
199,
533,
7146,
2461,
8,
4129,
63,
1000,
14,
3120,
2461,
12,
909,
304,
272,
1125,
63,
1205,
275,
620,
480,
5783,
1621,
17071,
23578,
12539,
531,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
408,
7,
952,
11716,
4550,
465,
2013,
701,
13663,
650,
11769,
624,
398,
702,
1228,
8,
576,
12,
2783,
395,
298,
952,
342,
1423,
1471,
506,
23888,
2,
398,
340,
440,
291,
14,
1205,
26,
288,
746,
9070,
480,
952,
342,
2544,
1343,
63,
1310,
16060,
398,
916,
440,
291,
14,
2139,
63,
1150,
26,
288,
327,
21467,
314,
1642,
1072,
12,
3222,
314,
5489,
2323,
288,
291,
14,
2394,
63,
1150,
275,
822,
8,
576,
9,
259,
327,
1852,
3238,
781,
5715,
1564,
13,
1267,
288,
291,
14,
2254,
63,
2139,
342,
267,
587,
26,
288,
291,
14,
2394,
63,
1150,
847,
822,
8,
576,
9,
398,
327,
5787,
1104,
6646,
13,
4625,
436,
14547,
340,
4634,
5002,
2783,
5313,
31,
267,
666,
275,
11808,
8,
576,
9,
267,
367,
3728,
315,
2740,
8,
2734,
26,
666,
14,
739,
8,
4283,
63,
17462,
63,
20512,
63,
4305,
395,
330,
7,
735,
288,
291,
423,
952,
8,
4604,
9,
288,
291,
423,
4939,
342,
339,
347,
1125,
63,
1199,
8,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1613,
8,
3120,
2461,
12,
291,
680,
705,
63,
1199,
8,
2314,
12,
1343,
63,
1310,
9,
267,
372,
788,
60,
78,
1370,
904,
8,
6894,
14,
908,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
4059,
61,
339,
327,
10257,
719,
402,
1455,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
4964,
15,
68,
21,
2756,
17,
66,
8276,
68,
371,
14,
1666,
327,
975,
13571,
14,
272,
327,
961,
883,
506,
4829,
1380,
2291,
367,
2018,
2695,
499,
14,
23,
14,
19,
365,
5906,
14,
272,
347,
9578,
63,
1310,
8,
277,
304,
267,
862,
26,
288,
340,
440,
291,
14,
1099,
63,
374,
63,
493,
342,
503,
440,
291,
14,
2254,
493,
837,
355,
367,
666,
315,
291,
14,
1099,
26,
490,
291,
14,
952,
8,
576,
9,
355,
291,
14,
8192,
63,
1317,
342,
267,
3753,
26,
288,
291,
14,
1600,
342,
421,
199,
533,
644,
28732,
8,
4129,
63,
1000,
14,
55,
28732,
12,
909,
304,
272,
408,
1563,
14938,
626,
9031,
314,
2018,
9279,
4113,
624,
339,
1056,
63,
1825,
63,
890,
275,
1616,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
360,
4774,
22,
297,
756,
304,
288,
291,
14,
1562,
63,
6606,
275,
2838,
14,
5699,
63,
11367,
22,
267,
1613,
8,
55,
28732,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
1654,
63,
3409,
8,
277,
304,
267,
408,
11954,
1654,
63,
3409,
370,
3877,
314,
1654,
536,
1041,
267,
1613,
8,
55,
28732,
12,
291,
680,
1000,
63,
3409,
342,
267,
291,
14,
2758,
63,
2314,
342,
421,
199,
533,
9279,
11149
] |
[
199,
2856,
1654,
626,
9031,
314,
2018,
9279,
4113,
334,
25633,
23792,
12,
6822,
413,
14,
2025,
680,
199,
199,
20409,
641,
12464,
1121,
14,
4129,
63,
1000,
1314,
365,
1777,
402,
314,
4465,
3555,
3967,
499,
14,
21,
14,
199,
199,
2765,
365,
282,
3486,
1654,
367,
675,
315,
5343,
503,
10201,
5634,
8686,
14,
2779,
18699,
1133,
199,
1235,
287,
11248,
379,
367,
6391,
10876,
14,
577,
615,
7,
52,
4815,
473,
52,
2381,
3611,
4980,
5430,
4815,
1,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
5890,
492,
11808,
199,
646,
2838,
199,
646,
984,
199,
646,
5190,
199,
504,
12464,
1121,
492,
3486,
63,
1000,
199,
504,
12464,
1121,
14,
1974,
492,
3814,
4590,
257,
327,
367,
8552,
7163,
199,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
3164,
63,
2487,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
504,
1639,
14,
1208,
14,
578,
63,
8786,
492,
492,
63,
991,
63,
515,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
20818,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
492,
2838,
1000,
199,
199,
363,
452,
363,
275,
661,
55,
28732,
297,
283,
16828,
11149,
297,
283,
4283,
63,
17462,
63,
20512,
63,
4305,
358,
421,
199,
3,
982,
666,
365,
4634,
7031,
12,
2838,
911,
2468,
415,
12,
880,
2218,
8291,
949,
12142,
2419,
4337,
4567,
199,
3,
737,
282,
900,
14,
710,
660,
296,
1895,
22172,
314,
4337,
4567,
883,
506,
1911,
641,
5634,
1159,
377,
6457,
26,
199,
3,
4178,
921,
600,
14,
14013,
14,
957,
15,
9201,
15,
1229,
2534,
3,
3349,
26,
20,
199,
4283,
63,
17462,
63,
20512,
63,
4305,
275,
4337,
627,
6619,
627,
6619,
221,
327,
4337,
19487,
421,
199,
318,
664,
63,
4672,
63,
6508,
63,
3578,
837,
272,
408,
272,
30367,
436,
2529,
314,
9279,
4223,
465,
7526,
701,
314,
922,
315,
272,
1124,
1751,
14,
16828,
63,
24051,
4345,
8777,
314,
849,
1124,
928,
1715,
1040,
7054,
12,
272,
642,
911,
506,
314,
1124,
3578,
1040,
909,
315,
1124,
1715,
354,
15,
6508,
14,
647,
4345,
339,
961,
805,
12,
436,
314,
1124,
16828,
63,
24051,
1040,
4260,
6337,
12,
787,
1454,
2997,
272,
367,
5634,
1159,
5007,
8037,
334,
1065,
1000,
12,
1255,
30076,
2736,
5957,
9279,
8037,
272,
1077,
2951,
506,
7526,
370,
2376,
370,
314,
3211,
4223,
909,
272,
5370,
14,
339,
982,
2202,
14,
16828,
63,
24051,
365,
440,
663,
334,
374,
1124,
403,
1040,
395,
781,
2951,
372,
272,
15685,
1124,
1176,
14,
1018,
14,
6508,
14,
362,
63,
6508,
63,
3578,
1040,
2529,
14,
339,
408,
272,
687,
1639,
14,
2190,
492,
2202,
272,
1145,
63,
515,
275,
2519,
8,
1751,
12,
283,
16828,
63,
24051,
358,
272,
340,
1145,
63,
515,
365,
488,
26,
267,
372,
664,
63,
6508,
63,
3578,
342,
339,
372,
492,
63,
991,
63,
515,
8,
267,
1145,
63,
515,
12,
267,
1125,
63,
1861,
628,
16828,
4223,
1543,
83,
7,
4293,
440,
506,
6511,
27,
298,
450,
1145,
63,
515,
272,
776,
421,
199,
533,
7146,
2461,
8,
4129,
63,
1000,
14,
3120,
2461,
12,
909,
304,
272,
1125,
63,
1205,
275,
620,
480,
5783,
1621,
17071,
23578,
12539,
531,
339,
347,
2218,
8,
277,
12,
666,
304,
267,
408,
7,
952,
11716,
4550,
465,
2013,
701,
13663,
650,
11769,
624,
398,
702,
1228,
8,
576,
12,
2783,
395,
298,
952,
342,
1423,
1471,
506,
23888,
2,
398,
340,
440,
291,
14,
1205,
26,
288,
746,
9070,
480,
952,
342,
2544,
1343,
63,
1310,
16060,
398,
916,
440,
291,
14,
2139,
63,
1150,
26,
288,
327,
21467,
314,
1642,
1072,
12,
3222,
314,
5489,
2323,
288,
291,
14,
2394,
63,
1150,
275,
822,
8,
576,
9,
259,
327,
1852,
3238,
781,
5715,
1564,
13,
1267,
288,
291,
14,
2254,
63,
2139,
342,
267,
587,
26,
288,
291,
14,
2394,
63,
1150,
847,
822,
8,
576,
9,
398,
327,
5787,
1104,
6646,
13,
4625,
436,
14547,
340,
4634,
5002,
2783,
5313,
31,
267,
666,
275,
11808,
8,
576,
9,
267,
367,
3728,
315,
2740,
8,
2734,
26,
666,
14,
739,
8,
4283,
63,
17462,
63,
20512,
63,
4305,
395,
330,
7,
735,
288,
291,
423,
952,
8,
4604,
9,
288,
291,
423,
4939,
342,
339,
347,
1125,
63,
1199,
8,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1613,
8,
3120,
2461,
12,
291,
680,
705,
63,
1199,
8,
2314,
12,
1343,
63,
1310,
9,
267,
372,
788,
60,
78,
1370,
904,
8,
6894,
14,
908,
63,
1971,
2031,
1274,
14,
2804,
63,
815,
4059,
61,
339,
327,
10257,
719,
402,
1455,
921,
9208,
14,
1548,
14,
1308,
15,
67,
1548,
15,
4964,
15,
68,
21,
2756,
17,
66,
8276,
68,
371,
14,
1666,
327,
975,
13571,
14,
272,
327,
961,
883,
506,
4829,
1380,
2291,
367,
2018,
2695,
499,
14,
23,
14,
19,
365,
5906,
14,
272,
347,
9578,
63,
1310,
8,
277,
304,
267,
862,
26,
288,
340,
440,
291,
14,
1099,
63,
374,
63,
493,
342,
503,
440,
291,
14,
2254,
493,
837,
355,
367,
666,
315,
291,
14,
1099,
26,
490,
291,
14,
952,
8,
576,
9,
355,
291,
14,
8192,
63,
1317,
342,
267,
3753,
26,
288,
291,
14,
1600,
342,
421,
199,
533,
644,
28732,
8,
4129,
63,
1000,
14,
55,
28732,
12,
909,
304,
272,
408,
1563,
14938,
626,
9031,
314,
2018,
9279,
4113,
624,
339,
1056,
63,
1825,
63,
890,
275,
1616,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
2074,
14,
1935,
360,
4774,
22,
297,
756,
304,
288,
291,
14,
1562,
63,
6606,
275,
2838,
14,
5699,
63,
11367,
22,
267,
1613,
8,
55,
28732,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
347,
1654,
63,
3409,
8,
277,
304,
267,
408,
11954,
1654,
63,
3409,
370,
3877,
314,
1654,
536,
1041,
267,
1613,
8,
55,
28732,
12,
291,
680,
1000,
63,
3409,
342,
267,
291,
14,
2758,
63,
2314,
342,
421,
199,
533,
9279,
11149,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nicolashainaux/mathmakerlib
|
tests/03_calculus/03_unit_test.py
|
1
|
3736
|
# -*- coding: utf-8 -*-
# Mathmaker Lib offers lualatex-printable mathematical objects.
# Copyright 2006-2017 Nicolas Hainaux <nh.techn@gmail.com>
# This file is part of Mathmaker Lib.
# Mathmaker Lib 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
# any later version.
# Mathmaker Lib 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 Mathmaker Lib; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import pytest
from decimal import Decimal
from mathmakerlib import required
from mathmakerlib.calculus import Unit, physical_quantity, Number
from mathmakerlib.calculus import difference_of_orders_of_magnitude
def test_physical_quantity():
"""Check physical_quantity()"""
assert physical_quantity('mm') == 'length'
assert physical_quantity('hL') == 'capacity'
assert physical_quantity('pg') == 'mass'
assert physical_quantity(Unit('pg')) == 'mass'
assert physical_quantity(Unit('mm', exponent=2)) == 'area'
assert physical_quantity(Unit('mm', exponent=3)) == 'volume'
assert physical_quantity('undefined') is None
assert physical_quantity(r'\officialeuro') == 'currency'
assert physical_quantity(r'\textdegree') == 'angle'
def test_difference_of_orders_of_magnitude_exceptions():
"""Check wrong units trigger an error."""
with pytest.raises(TypeError) as excinfo:
difference_of_orders_of_magnitude('cm', 'hL')
assert str(excinfo.value) == 'Cannot give the difference of orders of ' \
'magnitude between two units that do not belong to the same physical '\
'quantity (cm and hL).'
def test_difference_of_orders_of_magnitude():
"""Check the difference of orders of magnitude is calculated correctly."""
assert difference_of_orders_of_magnitude('L', 'mL') == Decimal('1000')
assert difference_of_orders_of_magnitude('cm', 'm') == Decimal('0.01')
assert difference_of_orders_of_magnitude('kg', 'mg') == Decimal('1000000')
def test_Unit_errors():
"""Check the Unit class exceptions."""
with pytest.raises(TypeError) as excinfo:
Unit(6)
assert str(excinfo.value) == 'content must be a str or a Unit. ' \
'Got <class \'int\'> instead.'
def test_Unit():
"""Check the Unit class."""
assert Unit('cm').printed == r'\si{cm}'
assert Unit('cm', exponent=Number(2)).printed == r'\si{cm^{2}}'
u = Unit('cm')
assert Unit(u).printed == r'\si{cm}'
assert Unit(u, exponent=2).printed == r'\si{cm^{2}}'
assert Unit(u, exponent=Number(3)).printed == r'\si{cm^{3}}'
u = Unit('cm', exponent=2)
assert Unit(u).printed == r'\si{cm^{2}}'
v = Unit('cm', exponent=2)
assert u == v
w = Unit(v, exponent=3)
assert v != w
w = Unit(v, exponent=2)
assert v == w
assert u != 6
def test_printing():
"""Check printing."""
assert Unit('cm', exponent=2).uiprinted == 'cm^2'
assert Unit('cm', exponent=2).printed == r'\si{cm^{2}}'
assert str(Unit('cm')) == 'cm'
assert str(Unit('cm', exponent=2)) == 'cm^2'
required.package['eurosym'] = False
Unit(r'\officialeuro').printed
assert required.package['eurosym']
def test_repr():
"""Check __repr__."""
assert repr(Unit('cm')) == 'Unit(\'cm\')'
assert repr(Unit('cm', exponent=2)) == 'Unit(\'cm\'^Number(\'2\'))'
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
21066,
14367,
8003,
32563,
634,
1061,
24026,
13,
20557,
610,
28491,
2251,
14,
199,
3,
1898,
8315,
13,
10680,
30650,
761,
305,
869,
1581,
10962,
665,
29199,
14,
266,
11019,
32,
6799,
14,
957,
30,
199,
199,
3,
961,
570,
365,
1777,
402,
21066,
14367,
8003,
14,
199,
199,
3,
21066,
14367,
8003,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
1263,
2945,
1015,
14,
199,
199,
3,
21066,
14367,
8003,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
21066,
14367,
8003,
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,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
4613,
199,
504,
6107,
492,
6345,
199,
199,
504,
3473,
14367,
773,
492,
1415,
199,
504,
3473,
14367,
773,
14,
13494,
527,
492,
12008,
12,
14095,
63,
10577,
12,
4860,
199,
504,
3473,
14367,
773,
14,
13494,
527,
492,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
421,
199,
318,
511,
63,
15020,
63,
10577,
837,
272,
408,
1799,
14095,
63,
10577,
32664,
272,
702,
14095,
63,
10577,
360,
596,
358,
508,
283,
1267,
7,
272,
702,
14095,
63,
10577,
360,
72,
44,
358,
508,
283,
10457,
7,
272,
702,
14095,
63,
10577,
360,
4198,
358,
508,
283,
11535,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
4198,
1333,
508,
283,
11535,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
596,
297,
16588,
29,
18,
430,
508,
283,
6789,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
596,
297,
16588,
29,
19,
430,
508,
283,
2405,
7,
272,
702,
14095,
63,
10577,
360,
10705,
358,
365,
488,
272,
702,
14095,
63,
10577,
8,
82,
1154,
1618,
4294,
1895,
9129,
358,
508,
283,
4968,
7,
272,
702,
14095,
63,
10577,
8,
82,
1154,
505,
10956,
358,
508,
283,
4593,
7,
421,
199,
318,
511,
63,
9196,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
63,
3924,
837,
272,
408,
1799,
6835,
6204,
6804,
376,
1125,
1041,
272,
543,
4613,
14,
3536,
8,
4333,
9,
465,
21596,
26,
267,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
4400,
297,
283,
72,
44,
358,
272,
702,
620,
8,
27447,
14,
585,
9,
508,
283,
6612,
8120,
314,
8865,
402,
15460,
402,
283,
971,
267,
283,
32167,
3382,
2877,
6204,
626,
886,
440,
13511,
370,
314,
2011,
14095,
1557,
267,
283,
10577,
334,
4400,
436,
394,
44,
28823,
421,
199,
318,
511,
63,
9196,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
837,
272,
408,
1799,
314,
8865,
402,
15460,
402,
22877,
365,
12950,
6657,
1041,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
44,
297,
283,
77,
44,
358,
508,
6345,
360,
5279,
358,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
4400,
297,
283,
77,
358,
508,
6345,
360,
16,
14,
614,
358,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
9761,
297,
283,
6649,
358,
508,
6345,
360,
22589,
358,
421,
199,
318,
511,
63,
5072,
63,
2550,
837,
272,
408,
1799,
314,
12008,
1021,
4967,
1041,
272,
543,
4613,
14,
3536,
8,
4333,
9,
465,
21596,
26,
267,
12008,
8,
22,
9,
272,
702,
620,
8,
27447,
14,
585,
9,
508,
283,
1317,
1471,
506,
282,
620,
503,
282,
12008,
14,
283,
971,
267,
283,
13662,
665,
533,
8891,
442,
3985,
30,
3140,
3530,
421,
199,
318,
511,
63,
5072,
837,
272,
408,
1799,
314,
12008,
1021,
1041,
272,
702,
12008,
360,
4400,
1959,
27131,
508,
519,
1154,
338,
91,
4400,
6834,
272,
702,
12008,
360,
4400,
297,
16588,
29,
3259,
8,
18,
4992,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
399,
275,
12008,
360,
4400,
358,
272,
702,
12008,
8,
85,
680,
27131,
508,
519,
1154,
338,
91,
4400,
6834,
272,
702,
12008,
8,
85,
12,
16588,
29,
18,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
702,
12008,
8,
85,
12,
16588,
29,
3259,
8,
19,
4992,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
19,
4863,
7,
272,
399,
275,
12008,
360,
4400,
297,
16588,
29,
18,
9,
272,
702,
12008,
8,
85,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
373,
275,
12008,
360,
4400,
297,
16588,
29,
18,
9,
272,
702,
399,
508,
373,
272,
336,
275,
12008,
8,
86,
12,
16588,
29,
19,
9,
272,
702,
373,
1137,
336,
272,
336,
275,
12008,
8,
86,
12,
16588,
29,
18,
9,
272,
702,
373,
508,
336,
272,
702,
399,
1137,
1227,
421,
199,
318,
511,
63,
26514,
837,
272,
408,
1799,
16116,
1041,
272,
702,
12008,
360,
4400,
297,
16588,
29,
18,
680,
85,
711,
82,
9082,
508,
283,
4400,
62,
18,
7,
272,
702,
12008,
360,
4400,
297,
16588,
29,
18,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
702,
620,
8,
5072,
360,
4400,
1333,
508,
283,
4400,
7,
272,
702,
620,
8,
5072,
360,
4400,
297,
16588,
29,
18,
430,
508,
283,
4400,
62,
18,
7,
272,
1415,
14,
2491,
459,
27089,
3840,
418,
275,
756,
272,
12008,
8,
82,
1154,
1618,
4294,
1895,
9129,
1959,
27131,
272,
702,
1415,
14,
2491,
459,
27089,
3840,
418,
421,
199,
318,
511,
63,
2722,
837,
272,
408,
1799,
636,
2722,
363,
1041,
272,
702,
4700,
8,
5072,
360,
4400,
1333,
508,
283,
5072,
30338,
4400,
60,
358,
7,
272,
702,
4700,
8,
5072,
360,
4400,
297,
16588,
29,
18
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
21066,
14367,
8003,
32563,
634,
1061,
24026,
13,
20557,
610,
28491,
2251,
14,
199,
3,
1898,
8315,
13,
10680,
30650,
761,
305,
869,
1581,
10962,
665,
29199,
14,
266,
11019,
32,
6799,
14,
957,
30,
199,
199,
3,
961,
570,
365,
1777,
402,
21066,
14367,
8003,
14,
199,
199,
3,
21066,
14367,
8003,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
1263,
2945,
1015,
14,
199,
199,
3,
21066,
14367,
8003,
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,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
21066,
14367,
8003,
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,
221,
11315,
13,
10067,
221,
8217,
199,
199,
646,
4613,
199,
504,
6107,
492,
6345,
199,
199,
504,
3473,
14367,
773,
492,
1415,
199,
504,
3473,
14367,
773,
14,
13494,
527,
492,
12008,
12,
14095,
63,
10577,
12,
4860,
199,
504,
3473,
14367,
773,
14,
13494,
527,
492,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
421,
199,
318,
511,
63,
15020,
63,
10577,
837,
272,
408,
1799,
14095,
63,
10577,
32664,
272,
702,
14095,
63,
10577,
360,
596,
358,
508,
283,
1267,
7,
272,
702,
14095,
63,
10577,
360,
72,
44,
358,
508,
283,
10457,
7,
272,
702,
14095,
63,
10577,
360,
4198,
358,
508,
283,
11535,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
4198,
1333,
508,
283,
11535,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
596,
297,
16588,
29,
18,
430,
508,
283,
6789,
7,
272,
702,
14095,
63,
10577,
8,
5072,
360,
596,
297,
16588,
29,
19,
430,
508,
283,
2405,
7,
272,
702,
14095,
63,
10577,
360,
10705,
358,
365,
488,
272,
702,
14095,
63,
10577,
8,
82,
1154,
1618,
4294,
1895,
9129,
358,
508,
283,
4968,
7,
272,
702,
14095,
63,
10577,
8,
82,
1154,
505,
10956,
358,
508,
283,
4593,
7,
421,
199,
318,
511,
63,
9196,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
63,
3924,
837,
272,
408,
1799,
6835,
6204,
6804,
376,
1125,
1041,
272,
543,
4613,
14,
3536,
8,
4333,
9,
465,
21596,
26,
267,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
4400,
297,
283,
72,
44,
358,
272,
702,
620,
8,
27447,
14,
585,
9,
508,
283,
6612,
8120,
314,
8865,
402,
15460,
402,
283,
971,
267,
283,
32167,
3382,
2877,
6204,
626,
886,
440,
13511,
370,
314,
2011,
14095,
1557,
267,
283,
10577,
334,
4400,
436,
394,
44,
28823,
421,
199,
318,
511,
63,
9196,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
837,
272,
408,
1799,
314,
8865,
402,
15460,
402,
22877,
365,
12950,
6657,
1041,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
44,
297,
283,
77,
44,
358,
508,
6345,
360,
5279,
358,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
4400,
297,
283,
77,
358,
508,
6345,
360,
16,
14,
614,
358,
272,
702,
8865,
63,
1618,
63,
14387,
63,
1618,
63,
32167,
360,
9761,
297,
283,
6649,
358,
508,
6345,
360,
22589,
358,
421,
199,
318,
511,
63,
5072,
63,
2550,
837,
272,
408,
1799,
314,
12008,
1021,
4967,
1041,
272,
543,
4613,
14,
3536,
8,
4333,
9,
465,
21596,
26,
267,
12008,
8,
22,
9,
272,
702,
620,
8,
27447,
14,
585,
9,
508,
283,
1317,
1471,
506,
282,
620,
503,
282,
12008,
14,
283,
971,
267,
283,
13662,
665,
533,
8891,
442,
3985,
30,
3140,
3530,
421,
199,
318,
511,
63,
5072,
837,
272,
408,
1799,
314,
12008,
1021,
1041,
272,
702,
12008,
360,
4400,
1959,
27131,
508,
519,
1154,
338,
91,
4400,
6834,
272,
702,
12008,
360,
4400,
297,
16588,
29,
3259,
8,
18,
4992,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
399,
275,
12008,
360,
4400,
358,
272,
702,
12008,
8,
85,
680,
27131,
508,
519,
1154,
338,
91,
4400,
6834,
272,
702,
12008,
8,
85,
12,
16588,
29,
18,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
702,
12008,
8,
85,
12,
16588,
29,
3259,
8,
19,
4992,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
19,
4863,
7,
272,
399,
275,
12008,
360,
4400,
297,
16588,
29,
18,
9,
272,
702,
12008,
8,
85,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
373,
275,
12008,
360,
4400,
297,
16588,
29,
18,
9,
272,
702,
399,
508,
373,
272,
336,
275,
12008,
8,
86,
12,
16588,
29,
19,
9,
272,
702,
373,
1137,
336,
272,
336,
275,
12008,
8,
86,
12,
16588,
29,
18,
9,
272,
702,
373,
508,
336,
272,
702,
399,
1137,
1227,
421,
199,
318,
511,
63,
26514,
837,
272,
408,
1799,
16116,
1041,
272,
702,
12008,
360,
4400,
297,
16588,
29,
18,
680,
85,
711,
82,
9082,
508,
283,
4400,
62,
18,
7,
272,
702,
12008,
360,
4400,
297,
16588,
29,
18,
680,
27131,
508,
519,
1154,
338,
91,
4400,
11683,
18,
4863,
7,
272,
702,
620,
8,
5072,
360,
4400,
1333,
508,
283,
4400,
7,
272,
702,
620,
8,
5072,
360,
4400,
297,
16588,
29,
18,
430,
508,
283,
4400,
62,
18,
7,
272,
1415,
14,
2491,
459,
27089,
3840,
418,
275,
756,
272,
12008,
8,
82,
1154,
1618,
4294,
1895,
9129,
1959,
27131,
272,
702,
1415,
14,
2491,
459,
27089,
3840,
418,
421,
199,
318,
511,
63,
2722,
837,
272,
408,
1799,
636,
2722,
363,
1041,
272,
702,
4700,
8,
5072,
360,
4400,
1333,
508,
283,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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
] |
thechampanurag/django-oscar
|
src/oscar/test/factories/offer.py
|
23
|
1385
|
import factory
from oscar.core.loading import get_model
__all__ = [
'RangeFactory', 'ConditionFactory', 'BenefitFactory',
'ConditionalOfferFactory',
]
class RangeFactory(factory.DjangoModelFactory):
name = factory.Sequence(lambda n: 'Range %d' % n)
slug = factory.Sequence(lambda n: 'range-%d' % n)
class Meta:
model = get_model('offer', 'Range')
@factory.post_generation
def products(self, create, extracted, **kwargs):
if not create or not extracted:
return
RangeProduct = get_model('offer', 'RangeProduct')
for product in extracted:
RangeProduct.objects.create(product=product, range=self)
class BenefitFactory(factory.DjangoModelFactory):
type = get_model('offer', 'Benefit').PERCENTAGE
value = 10
max_affected_items = None
range = factory.SubFactory(RangeFactory)
class Meta:
model = get_model('offer', 'Benefit')
class ConditionFactory(factory.DjangoModelFactory):
type = get_model('offer', 'Condition').COUNT
value = 10
class Meta:
model = get_model('offer', 'Condition')
class ConditionalOfferFactory(factory.DjangoModelFactory):
name = 'Test offer'
benefit = factory.SubFactory(BenefitFactory)
condition = factory.SubFactory(ConditionFactory)
class Meta:
model = get_model('offer', 'ConditionalOffer')
|
bsd-3-clause
|
[
646,
6434,
199,
199,
504,
312,
22707,
14,
1018,
14,
8786,
492,
664,
63,
1238,
421,
199,
363,
452,
363,
275,
359,
272,
283,
4709,
2927,
297,
283,
9558,
2927,
297,
283,
34,
6349,
3269,
2927,
297,
272,
283,
21321,
22154,
2927,
297,
199,
61,
421,
199,
533,
13114,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
536,
275,
6434,
14,
5826,
8,
2734,
302,
26,
283,
4709,
450,
68,
7,
450,
302,
9,
272,
8889,
275,
6434,
14,
5826,
8,
2734,
302,
26,
283,
1842,
3295,
68,
7,
450,
302,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
4709,
358,
339,
768,
3702,
14,
1932,
63,
15043,
272,
347,
7585,
8,
277,
12,
1218,
12,
12509,
12,
1011,
958,
304,
267,
340,
440,
1218,
503,
440,
12509,
26,
288,
372,
398,
13114,
5884,
275,
664,
63,
1238,
360,
12786,
297,
283,
4709,
5884,
358,
398,
367,
3336,
315,
12509,
26,
288,
13114,
5884,
14,
1462,
14,
981,
8,
2558,
29,
2558,
12,
1425,
29,
277,
9,
421,
199,
533,
699,
6349,
3269,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
730,
275,
664,
63,
1238,
360,
12786,
297,
283,
34,
6349,
3269,
1959,
4227,
17349,
2962,
272,
574,
275,
1616,
272,
1390,
63,
26653,
63,
1744,
275,
488,
272,
1425,
275,
6434,
14,
2610,
2927,
8,
4709,
2927,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
34,
6349,
3269,
358,
421,
199,
533,
28401,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
730,
275,
664,
63,
1238,
360,
12786,
297,
283,
9558,
1959,
8760,
272,
574,
275,
1616,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
9558,
358,
421,
199,
533,
24191,
22154,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
536,
275,
283,
774,
19793,
7,
272,
22477,
3269,
275,
6434,
14,
2610,
2927,
8,
34,
6349,
3269,
2927,
9,
272,
5558,
275,
6434,
14,
2610,
2927,
8,
9558,
2927,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
21321,
22154,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
6434,
199,
199,
504,
312,
22707,
14,
1018,
14,
8786,
492,
664,
63,
1238,
421,
199,
363,
452,
363,
275,
359,
272,
283,
4709,
2927,
297,
283,
9558,
2927,
297,
283,
34,
6349,
3269,
2927,
297,
272,
283,
21321,
22154,
2927,
297,
199,
61,
421,
199,
533,
13114,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
536,
275,
6434,
14,
5826,
8,
2734,
302,
26,
283,
4709,
450,
68,
7,
450,
302,
9,
272,
8889,
275,
6434,
14,
5826,
8,
2734,
302,
26,
283,
1842,
3295,
68,
7,
450,
302,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
4709,
358,
339,
768,
3702,
14,
1932,
63,
15043,
272,
347,
7585,
8,
277,
12,
1218,
12,
12509,
12,
1011,
958,
304,
267,
340,
440,
1218,
503,
440,
12509,
26,
288,
372,
398,
13114,
5884,
275,
664,
63,
1238,
360,
12786,
297,
283,
4709,
5884,
358,
398,
367,
3336,
315,
12509,
26,
288,
13114,
5884,
14,
1462,
14,
981,
8,
2558,
29,
2558,
12,
1425,
29,
277,
9,
421,
199,
533,
699,
6349,
3269,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
730,
275,
664,
63,
1238,
360,
12786,
297,
283,
34,
6349,
3269,
1959,
4227,
17349,
2962,
272,
574,
275,
1616,
272,
1390,
63,
26653,
63,
1744,
275,
488,
272,
1425,
275,
6434,
14,
2610,
2927,
8,
4709,
2927,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
34,
6349,
3269,
358,
421,
199,
533,
28401,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
730,
275,
664,
63,
1238,
360,
12786,
297,
283,
9558,
1959,
8760,
272,
574,
275,
1616,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
9558,
358,
421,
199,
533,
24191,
22154,
2927,
8,
3702,
14,
9323,
1685,
2927,
304,
272,
536,
275,
283,
774,
19793,
7,
272,
22477,
3269,
275,
6434,
14,
2610,
2927,
8,
34,
6349,
3269,
2927,
9,
272,
5558,
275,
6434,
14,
2610,
2927,
8,
9558,
2927,
9,
339,
1021,
6288,
26,
267,
1402,
275,
664,
63,
1238,
360,
12786,
297,
283,
21321,
22154,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
EmreAtes/spack
|
var/spack/repos/builtin/packages/r-pbdzmq/package.py
|
5
|
2114
|
##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program 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) version 2.1, February 1999.
#
# 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 terms and
# conditions of 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 program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
class RPbdzmq(RPackage):
"""'ZeroMQ' is a well-known library for high-performance asynchronous
messaging in scalable, distributed applications. This package provides
high level R wrapper functions to easily utilize 'ZeroMQ'. We mainly focus
on interactive client/server programming frameworks. For convenience, a
minimal 'ZeroMQ' library (4.1.0 rc1) is shipped with 'pbdZMQ', which can
be used if no system installation of 'ZeroMQ' is available. A few wrapper
functions compatible with 'rzmq' are also provided."""
homepage = "http://r-pbd.org/"
url = "https://cran.r-project.org/src/contrib/pbdZMQ_0.2-4.tar.gz"
list_url = "https://cran.r-project.org/src/contrib/Archive/pbdZMQ"
version('0.2-4', 'e5afb70199aa54d737ee7a0e26bde060')
depends_on('r-r6', type=('build', 'run'))
depends_on('zeromq')
|
lgpl-2.1
|
[
4605,
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
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,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
48,
3691,
21290,
8,
50,
8599,
304,
272,
408,
7,
8681,
14449,
7,
365,
282,
5521,
13,
3159,
3555,
367,
4721,
13,
20576,
15608,
272,
30429,
315,
5269,
461,
12,
1854,
13103,
14,
961,
2559,
6571,
272,
4721,
2166,
820,
4975,
3423,
370,
16174,
7678,
13559,
283,
8681,
14449,
1370,
2136,
27580,
16470,
272,
641,
12777,
1890,
15,
1000,
31768,
10059,
83,
14,
2104,
16777,
12,
282,
272,
13460,
283,
8681,
14449,
7,
3555,
334,
20,
14,
17,
14,
16,
4819,
17,
9,
365,
15924,
1915,
543,
283,
3317,
68,
58,
14449,
297,
1314,
883,
272,
506,
1202,
340,
949,
2656,
12096,
402,
283,
8681,
14449,
7,
365,
2808,
14,
437,
9284,
4975,
272,
3423,
9025,
543,
283,
82,
21290,
7,
787,
2597,
2741,
1041,
339,
26586,
275,
298,
1014,
921,
82,
13,
3317,
68,
14,
1308,
6687,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
3317,
68,
58,
14449,
63,
16,
14,
18,
13,
20,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
13042,
15,
3317,
68,
58,
14449,
2,
339,
1015,
360,
16,
14,
18,
13,
20,
297,
283,
69,
21,
2756,
66,
28852,
1020,
2158,
1477,
68,
29045,
1024,
23,
65,
16,
69,
1479,
66,
271,
18857,
358,
339,
8350,
63,
265,
360,
82,
13,
82,
22,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
2282,
676,
81,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
1898,
334,
67,
9,
6171,
13,
12682,
12,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
14,
199,
3,
2165,
16584,
737,
314,
7964,
29590,
491,
4380,
6878,
20548,
16871,
31671,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
428,
1389,
14,
199,
3,
18208,
701,
377,
16216,
598,
11020,
472,
12,
22387,
11020,
472,
32,
914,
7530,
14,
16294,
12,
2900,
4481,
4644,
14,
199,
3,
491,
44,
14176,
13,
6012,
13,
8557,
11501,
199,
3,
199,
3,
2104,
2436,
12,
1937,
4178,
921,
5031,
14,
957,
15,
83,
1389,
15,
83,
1389,
199,
3,
7754,
2597,
1937,
314,
12840,
436,
5113,
1584,
367,
4154,
4245,
436,
314,
32426,
14,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
844,
334,
305,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
9,
1015,
499,
14,
17,
12,
21141,
26709,
21300,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
3,
2428,
1821,
3408,
27,
1928,
2755,
314,
5292,
3408,
1634,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
2895,
436,
199,
3,
3704,
402,
314,
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,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
8217,
199,
4605,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
48,
3691,
21290,
8,
50,
8599,
304,
272,
408,
7,
8681,
14449,
7,
365,
282,
5521,
13,
3159,
3555,
367,
4721,
13,
20576,
15608,
272,
30429,
315,
5269,
461,
12,
1854,
13103,
14,
961,
2559,
6571,
272,
4721,
2166,
820,
4975,
3423,
370,
16174,
7678,
13559,
283,
8681,
14449,
1370,
2136,
27580,
16470,
272,
641,
12777,
1890,
15,
1000,
31768,
10059,
83,
14,
2104,
16777,
12,
282,
272,
13460,
283,
8681,
14449,
7,
3555,
334,
20,
14,
17,
14,
16,
4819,
17,
9,
365,
15924,
1915,
543,
283,
3317,
68,
58,
14449,
297,
1314,
883,
272,
506,
1202,
340,
949,
2656,
12096,
402,
283,
8681,
14449,
7,
365,
2808,
14,
437,
9284,
4975,
272,
3423,
9025,
543,
283,
82,
21290,
7,
787,
2597,
2741,
1041,
339,
26586,
275,
298,
1014,
921,
82,
13,
3317,
68,
14,
1308,
6687,
272,
1166,
420,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
3317,
68,
58,
14449,
63,
16,
14,
18,
13,
20,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
67,
1312,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
13042,
15,
3317,
68,
58,
14449,
2,
339,
1015,
360,
16,
14,
18,
13,
20,
297,
283,
69,
21,
2756,
66,
28852,
1020,
2158,
1477,
68,
29045,
1024,
23,
65,
16,
69,
1479,
66,
271,
18857,
358,
339,
8350,
63,
265,
360,
82,
13,
82,
22,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
2282,
676,
81,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eickenberg/scikit-learn
|
sklearn/metrics/cluster/unsupervised.py
|
10
|
8104
|
""" Unsupervised evaluation metrics. """
# Authors: Robert Layton <robertlayton@gmail.com>
#
# License: BSD 3 clause
import numpy as np
from ...utils import check_random_state
from ..pairwise import pairwise_distances
def silhouette_score(X, labels, metric='euclidean', sample_size=None,
random_state=None, **kwds):
"""Compute the mean Silhouette Coefficient of all samples.
The Silhouette Coefficient is calculated using the mean intra-cluster
distance (``a``) and the mean nearest-cluster distance (``b``) for each
sample. The Silhouette Coefficient for a sample is ``(b - a) / max(a,
b)``. To clarify, ``b`` is the distance between a sample and the nearest
cluster that the sample is not a part of.
Note that Silhouette Coefficent is only defined if number of labels
is 2 <= n_labels <= n_samples - 1.
This function returns the mean Silhouette Coefficient over all samples.
To obtain the values for each sample, use :func:`silhouette_samples`.
The best value is 1 and the worst value is -1. Values near 0 indicate
overlapping clusters. Negative values generally indicate that a sample has
been assigned to the wrong cluster, as a different cluster is more similar.
Parameters
----------
X : array [n_samples_a, n_samples_a] if metric == "precomputed", or, \
[n_samples_a, n_features] otherwise
Array of pairwise distances between samples, or a feature array.
labels : array, shape = [n_samples]
label values for each sample
metric : string, or callable
The metric to use when calculating distance between instances in a
feature array. If metric is a string, it must be one of the options
allowed by :func:`metrics.pairwise.pairwise_distances
<sklearn.metrics.pairwise.pairwise_distances>`. If X is the distance
array itself, use ``metric="precomputed"``.
sample_size : int or None
The size of the sample to use when computing the Silhouette
Coefficient. If ``sample_size is None``, no sampling is used.
random_state : integer or numpy.RandomState, optional
The generator used to initialize the centers. If an integer is
given, it fixes the seed. Defaults to the global numpy random
number generator.
`**kwds` : optional keyword parameters
Any further parameters are passed directly to the distance function.
If using a scipy.spatial.distance metric, the parameters are still
metric dependent. See the scipy docs for usage examples.
Returns
-------
silhouette : float
Mean Silhouette Coefficient for all samples.
References
----------
.. [1] `Peter J. Rousseeuw (1987). "Silhouettes: a Graphical Aid to the
Interpretation and Validation of Cluster Analysis". Computational
and Applied Mathematics 20: 53-65.
<http://www.sciencedirect.com/science/article/pii/0377042787901257>`_
.. [2] `Wikipedia entry on the Silhouette Coefficient
<http://en.wikipedia.org/wiki/Silhouette_(clustering)>`_
"""
n_labels = len(np.unique(labels))
n_samples = X.shape[0]
if not 2 <= n_labels <= n_samples-1:
raise ValueError("Number of labels is %d "
"but should be more than 2"
"and less than n_samples - 1" % n_labels)
if sample_size is not None:
random_state = check_random_state(random_state)
indices = random_state.permutation(X.shape[0])[:sample_size]
if metric == "precomputed":
X, labels = X[indices].T[indices].T, labels[indices]
else:
X, labels = X[indices], labels[indices]
return np.mean(silhouette_samples(X, labels, metric=metric, **kwds))
def silhouette_samples(X, labels, metric='euclidean', **kwds):
"""Compute the Silhouette Coefficient for each sample.
The Silhoeutte Coefficient is a measure of how well samples are clustered
with samples that are similar to themselves. Clustering models with a high
Silhouette Coefficient are said to be dense, where samples in the same
cluster are similar to each other, and well separated, where samples in
different clusters are not very similar to each other.
The Silhouette Coefficient is calculated using the mean intra-cluster
distance (``a``) and the mean nearest-cluster distance (``b``) for each
sample. The Silhouette Coefficient for a sample is ``(b - a) / max(a,
b)``.
Note that Silhouette Coefficent is only defined if number of labels
is 2 <= n_labels <= n_samples - 1.
This function returns the Silhouette Coefficient for each sample.
The best value is 1 and the worst value is -1. Values near 0 indicate
overlapping clusters.
Parameters
----------
X : array [n_samples_a, n_samples_a] if metric == "precomputed", or, \
[n_samples_a, n_features] otherwise
Array of pairwise distances between samples, or a feature array.
labels : array, shape = [n_samples]
label values for each sample
metric : string, or callable
The metric to use when calculating distance between instances in a
feature array. If metric is a string, it must be one of the options
allowed by :func:`sklearn.metrics.pairwise.pairwise_distances`. If X is
the distance array itself, use "precomputed" as the metric.
`**kwds` : optional keyword parameters
Any further parameters are passed directly to the distance function.
If using a ``scipy.spatial.distance`` metric, the parameters are still
metric dependent. See the scipy docs for usage examples.
Returns
-------
silhouette : array, shape = [n_samples]
Silhouette Coefficient for each samples.
References
----------
.. [1] `Peter J. Rousseeuw (1987). "Silhouettes: a Graphical Aid to the
Interpretation and Validation of Cluster Analysis". Computational
and Applied Mathematics 20: 53-65.
<http://www.sciencedirect.com/science/article/pii/0377042787901257>`_
.. [2] `Wikipedia entry on the Silhouette Coefficient
<http://en.wikipedia.org/wiki/Silhouette_(clustering)>`_
"""
distances = pairwise_distances(X, metric=metric, **kwds)
n = labels.shape[0]
A = np.array([_intra_cluster_distance(distances[i], labels, i)
for i in range(n)])
B = np.array([_nearest_cluster_distance(distances[i], labels, i)
for i in range(n)])
sil_samples = (B - A) / np.maximum(A, B)
# nan values are for clusters of size 1, and should be 0
return np.nan_to_num(sil_samples)
def _intra_cluster_distance(distances_row, labels, i):
"""Calculate the mean intra-cluster distance for sample i.
Parameters
----------
distances_row : array, shape = [n_samples]
Pairwise distance matrix between sample i and each sample.
labels : array, shape = [n_samples]
label values for each sample
i : int
Sample index being calculated. It is excluded from calculation and
used to determine the current label
Returns
-------
a : float
Mean intra-cluster distance for sample i
"""
mask = labels == labels[i]
mask[i] = False
a = np.mean(distances_row[mask])
return a
def _nearest_cluster_distance(distances_row, labels, i):
"""Calculate the mean nearest-cluster distance for sample i.
Parameters
----------
distances_row : array, shape = [n_samples]
Pairwise distance matrix between sample i and each sample.
labels : array, shape = [n_samples]
label values for each sample
i : int
Sample index being calculated. It is used to determine the current
label.
Returns
-------
b : float
Mean nearest-cluster distance for sample i
"""
label = labels[i]
b = np.min([np.mean(distances_row[labels == cur_label])
for cur_label in set(labels) if not cur_label == label])
return b
|
bsd-3-clause
|
[
624,
15254,
27951,
17311,
11735,
7186,
14,
408,
199,
199,
3,
6642,
26,
6848,
12504,
9366,
1860,
665,
293,
12504,
817,
1860,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2263,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
2508,
25069,
492,
24859,
63,
15482,
421,
199,
318,
24968,
526,
310,
14586,
63,
3397,
8,
56,
12,
3628,
12,
6370,
534,
26479,
297,
2690,
63,
890,
29,
403,
12,
2151,
2196,
63,
929,
29,
403,
12,
1011,
10340,
304,
272,
408,
8564,
314,
4615,
428,
382,
526,
310,
14586,
1849,
21069,
402,
1006,
5845,
14,
339,
710,
428,
382,
526,
310,
14586,
1849,
21069,
365,
12950,
1808,
314,
4615,
1109,
345,
13,
4201,
272,
6033,
15693,
65,
16580,
436,
314,
4615,
17173,
13,
4201,
6033,
15693,
66,
16580,
367,
1924,
272,
2690,
14,
221,
710,
428,
382,
526,
310,
14586,
1849,
21069,
367,
282,
2690,
365,
15475,
66,
446,
282,
9,
1182,
1390,
8,
65,
12,
272,
330,
20642,
221,
4005,
824,
285,
2021,
12,
1124,
66,
1040,
365,
314,
6033,
3382,
282,
2690,
436,
314,
17173,
272,
4350,
626,
314,
2690,
365,
440,
282,
1777,
402,
14,
272,
3390,
626,
428,
382,
526,
310,
14586,
1849,
2829,
1792,
484,
365,
1454,
3247,
340,
1329,
402,
3628,
272,
365,
499,
2695,
302,
63,
3512,
2695,
302,
63,
3356,
446,
413,
14,
339,
961,
805,
2529,
314,
4615,
428,
382,
526,
310,
14586,
1849,
21069,
1806,
1006,
5845,
14,
272,
4005,
3332,
314,
1338,
367,
1924,
2690,
12,
675,
520,
1532,
1705,
20329,
526,
310,
14586,
63,
3356,
2313,
339,
710,
5526,
574,
365,
413,
436,
314,
1319,
270,
574,
365,
446,
17,
14,
13468,
17429,
378,
6623,
272,
28281,
13865,
14,
32548,
1338,
16711,
6623,
626,
282,
2690,
965,
272,
2757,
7943,
370,
314,
6835,
4350,
12,
465,
282,
3365,
4350,
365,
1655,
8545,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
359,
78,
63,
3356,
63,
65,
12,
302,
63,
3356,
63,
65,
61,
340,
6370,
508,
298,
26596,
401,
503,
12,
971,
1467,
359,
78,
63,
3356,
63,
65,
12,
302,
63,
3179,
61,
4257,
267,
8725,
402,
24859,
15108,
3382,
5845,
12,
503,
282,
3878,
1625,
14,
339,
3628,
520,
1625,
12,
2215,
275,
359,
78,
63,
3356,
61,
1467,
1768,
1338,
367,
1924,
2690,
339,
6370,
520,
1059,
12,
503,
4550,
267,
710,
6370,
370,
675,
1380,
26079,
6033,
3382,
4454,
315,
282,
267,
3878,
1625,
14,
982,
6370,
365,
282,
1059,
12,
652,
1471,
506,
1373,
402,
314,
1511,
267,
4370,
701,
520,
1532,
1705,
6759,
14,
25069,
14,
25069,
63,
15482,
267,
665,
27993,
14,
6759,
14,
25069,
14,
25069,
63,
15482,
14943,
982,
1323,
365,
314,
6033,
267,
1625,
6337,
12,
675,
1124,
5165,
628,
26596,
2,
4345,
339,
2690,
63,
890,
520,
1109,
503,
488,
267,
710,
1568,
402,
314,
2690,
370,
675,
1380,
17226,
314,
428,
382,
526,
310,
14586,
267,
1849,
21069,
14,
982,
1124,
3271,
63,
890,
365,
488,
4542,
949,
15877,
365,
1202,
14,
339,
2196,
63,
929,
520,
3000,
503,
2680,
14,
15726,
12,
2716,
267,
710,
4306,
1202,
370,
8265,
314,
19190,
14,
982,
376,
3000,
365,
267,
1627,
12,
652,
25079,
314,
6347,
14,
7827,
370,
314,
2288,
2680,
2196,
267,
1329,
4306,
14,
339,
658,
538,
10340,
64,
520,
2716,
4252,
2633,
267,
6184,
9848,
2633,
787,
3032,
5370,
370,
314,
6033,
805,
14,
267,
982,
1808,
282,
7026,
14,
11679,
14,
5590,
6370,
12,
314,
2633,
787,
5139,
267,
6370,
11410,
14,
1666,
314,
7026,
9149,
367,
4503,
7251,
14,
339,
1803,
272,
5514,
272,
24968,
526,
310,
14586,
520,
2069,
267,
25136,
428,
382,
526,
310,
14586,
1849,
21069,
367,
1006,
5845,
14,
339,
14504,
272,
4143,
339,
2508,
359,
17,
61,
658,
8070,
351,
1603,
14,
820,
1785,
3239,
29638,
334,
30828,
680,
298,
51,
382,
526,
310,
84,
744,
26,
282,
11513,
2652,
437,
344,
370,
314,
2126,
6551,
25133,
425,
436,
19381,
402,
16454,
21916,
1674,
3599,
337,
6279,
2126,
436,
4693,
1857,
16593,
1589,
3889,
83,
3388,
26,
13564,
13,
2182,
14,
2126,
665,
1014,
921,
1544,
14,
9907,
4894,
2275,
14,
957,
15,
9907,
4894,
15,
6934,
15,
1038,
73,
15,
1644,
1138,
31793,
13657,
614,
11551,
18740,
339,
2508,
359,
18,
61,
658,
55,
29386,
2397,
641,
314,
428,
382,
526,
310,
14586,
1849,
21069,
1779,
665,
1014,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
51,
382,
526,
310,
14586,
2531,
25802,
9,
18740,
339,
408,
272,
302,
63,
3512,
275,
822,
8,
1590,
14,
3235,
8,
3512,
430,
272,
302,
63,
3356,
275,
1323,
14,
1392,
59,
16,
61,
272,
340,
440,
499,
2695,
302,
63,
3512,
2695,
302,
63,
3356,
13,
17,
26,
267,
746,
1722,
480,
3259,
402,
3628,
365,
450,
68,
298,
586,
298,
7911,
1077,
506,
1655,
2419,
499,
2,
586,
298,
460,
6656,
2419,
302,
63,
3356,
446,
413,
2,
450,
302,
63,
3512,
9,
339,
340,
2690,
63,
890,
365,
440,
488,
26,
267,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
2355,
63,
929,
9,
267,
4918,
275,
2196,
63,
929,
14,
23832,
8,
56,
14,
1392,
59,
16,
566,
1491,
3271,
63,
890,
61,
267,
340,
6370,
508,
298,
26596,
582,
288,
1323,
12,
3628,
275,
1323,
59,
4108,
1055,
52,
59,
4108,
1055,
52,
12,
3628,
59,
4108,
61,
267,
587,
26,
288,
1323,
12,
3628,
275,
1323,
59,
4108,
467,
3628,
59,
4108,
61,
272,
372,
980,
14,
3670,
8,
20329,
526,
310,
14586,
63,
3356,
8,
56,
12,
3628,
12,
6370,
29,
5165,
12,
1011,
10340,
430,
421,
199,
318,
24968,
526,
310,
14586,
63,
3356,
8,
56,
12,
3628,
12,
6370,
534,
26479,
297,
1011,
10340,
304,
272,
408,
8564,
314,
428,
382,
526,
310,
14586,
1849,
21069,
367,
1924,
2690,
14,
339,
710,
428,
382,
526,
69,
337,
266,
1849,
21069,
365,
282,
9775,
402,
4212,
5521,
5845,
787,
824,
527,
3014,
272,
543,
5845,
626,
787,
8545,
370,
17279,
14,
16454,
316,
1709,
543,
282,
4721,
272,
428,
382,
526,
310,
14586,
1849,
21069
] |
[
15254,
27951,
17311,
11735,
7186,
14,
408,
199,
199,
3,
6642,
26,
6848,
12504,
9366,
1860,
665,
293,
12504,
817,
1860,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
2263,
1208,
492,
1104,
63,
2355,
63,
929,
199,
504,
2508,
25069,
492,
24859,
63,
15482,
421,
199,
318,
24968,
526,
310,
14586,
63,
3397,
8,
56,
12,
3628,
12,
6370,
534,
26479,
297,
2690,
63,
890,
29,
403,
12,
2151,
2196,
63,
929,
29,
403,
12,
1011,
10340,
304,
272,
408,
8564,
314,
4615,
428,
382,
526,
310,
14586,
1849,
21069,
402,
1006,
5845,
14,
339,
710,
428,
382,
526,
310,
14586,
1849,
21069,
365,
12950,
1808,
314,
4615,
1109,
345,
13,
4201,
272,
6033,
15693,
65,
16580,
436,
314,
4615,
17173,
13,
4201,
6033,
15693,
66,
16580,
367,
1924,
272,
2690,
14,
221,
710,
428,
382,
526,
310,
14586,
1849,
21069,
367,
282,
2690,
365,
15475,
66,
446,
282,
9,
1182,
1390,
8,
65,
12,
272,
330,
20642,
221,
4005,
824,
285,
2021,
12,
1124,
66,
1040,
365,
314,
6033,
3382,
282,
2690,
436,
314,
17173,
272,
4350,
626,
314,
2690,
365,
440,
282,
1777,
402,
14,
272,
3390,
626,
428,
382,
526,
310,
14586,
1849,
2829,
1792,
484,
365,
1454,
3247,
340,
1329,
402,
3628,
272,
365,
499,
2695,
302,
63,
3512,
2695,
302,
63,
3356,
446,
413,
14,
339,
961,
805,
2529,
314,
4615,
428,
382,
526,
310,
14586,
1849,
21069,
1806,
1006,
5845,
14,
272,
4005,
3332,
314,
1338,
367,
1924,
2690,
12,
675,
520,
1532,
1705,
20329,
526,
310,
14586,
63,
3356,
2313,
339,
710,
5526,
574,
365,
413,
436,
314,
1319,
270,
574,
365,
446,
17,
14,
13468,
17429,
378,
6623,
272,
28281,
13865,
14,
32548,
1338,
16711,
6623,
626,
282,
2690,
965,
272,
2757,
7943,
370,
314,
6835,
4350,
12,
465,
282,
3365,
4350,
365,
1655,
8545,
14,
339,
3897,
272,
4143,
272,
1323,
520,
1625,
359,
78,
63,
3356,
63,
65,
12,
302,
63,
3356,
63,
65,
61,
340,
6370,
508,
298,
26596,
401,
503,
12,
971,
1467,
359,
78,
63,
3356,
63,
65,
12,
302,
63,
3179,
61,
4257,
267,
8725,
402,
24859,
15108,
3382,
5845,
12,
503,
282,
3878,
1625,
14,
339,
3628,
520,
1625,
12,
2215,
275,
359,
78,
63,
3356,
61,
1467,
1768,
1338,
367,
1924,
2690,
339,
6370,
520,
1059,
12,
503,
4550,
267,
710,
6370,
370,
675,
1380,
26079,
6033,
3382,
4454,
315,
282,
267,
3878,
1625,
14,
982,
6370,
365,
282,
1059,
12,
652,
1471,
506,
1373,
402,
314,
1511,
267,
4370,
701,
520,
1532,
1705,
6759,
14,
25069,
14,
25069,
63,
15482,
267,
665,
27993,
14,
6759,
14,
25069,
14,
25069,
63,
15482,
14943,
982,
1323,
365,
314,
6033,
267,
1625,
6337,
12,
675,
1124,
5165,
628,
26596,
2,
4345,
339,
2690,
63,
890,
520,
1109,
503,
488,
267,
710,
1568,
402,
314,
2690,
370,
675,
1380,
17226,
314,
428,
382,
526,
310,
14586,
267,
1849,
21069,
14,
982,
1124,
3271,
63,
890,
365,
488,
4542,
949,
15877,
365,
1202,
14,
339,
2196,
63,
929,
520,
3000,
503,
2680,
14,
15726,
12,
2716,
267,
710,
4306,
1202,
370,
8265,
314,
19190,
14,
982,
376,
3000,
365,
267,
1627,
12,
652,
25079,
314,
6347,
14,
7827,
370,
314,
2288,
2680,
2196,
267,
1329,
4306,
14,
339,
658,
538,
10340,
64,
520,
2716,
4252,
2633,
267,
6184,
9848,
2633,
787,
3032,
5370,
370,
314,
6033,
805,
14,
267,
982,
1808,
282,
7026,
14,
11679,
14,
5590,
6370,
12,
314,
2633,
787,
5139,
267,
6370,
11410,
14,
1666,
314,
7026,
9149,
367,
4503,
7251,
14,
339,
1803,
272,
5514,
272,
24968,
526,
310,
14586,
520,
2069,
267,
25136,
428,
382,
526,
310,
14586,
1849,
21069,
367,
1006,
5845,
14,
339,
14504,
272,
4143,
339,
2508,
359,
17,
61,
658,
8070,
351,
1603,
14,
820,
1785,
3239,
29638,
334,
30828,
680,
298,
51,
382,
526,
310,
84,
744,
26,
282,
11513,
2652,
437,
344,
370,
314,
2126,
6551,
25133,
425,
436,
19381,
402,
16454,
21916,
1674,
3599,
337,
6279,
2126,
436,
4693,
1857,
16593,
1589,
3889,
83,
3388,
26,
13564,
13,
2182,
14,
2126,
665,
1014,
921,
1544,
14,
9907,
4894,
2275,
14,
957,
15,
9907,
4894,
15,
6934,
15,
1038,
73,
15,
1644,
1138,
31793,
13657,
614,
11551,
18740,
339,
2508,
359,
18,
61,
658,
55,
29386,
2397,
641,
314,
428,
382,
526,
310,
14586,
1849,
21069,
1779,
665,
1014,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
51,
382,
526,
310,
14586,
2531,
25802,
9,
18740,
339,
408,
272,
302,
63,
3512,
275,
822,
8,
1590,
14,
3235,
8,
3512,
430,
272,
302,
63,
3356,
275,
1323,
14,
1392,
59,
16,
61,
272,
340,
440,
499,
2695,
302,
63,
3512,
2695,
302,
63,
3356,
13,
17,
26,
267,
746,
1722,
480,
3259,
402,
3628,
365,
450,
68,
298,
586,
298,
7911,
1077,
506,
1655,
2419,
499,
2,
586,
298,
460,
6656,
2419,
302,
63,
3356,
446,
413,
2,
450,
302,
63,
3512,
9,
339,
340,
2690,
63,
890,
365,
440,
488,
26,
267,
2196,
63,
929,
275,
1104,
63,
2355,
63,
929,
8,
2355,
63,
929,
9,
267,
4918,
275,
2196,
63,
929,
14,
23832,
8,
56,
14,
1392,
59,
16,
566,
1491,
3271,
63,
890,
61,
267,
340,
6370,
508,
298,
26596,
582,
288,
1323,
12,
3628,
275,
1323,
59,
4108,
1055,
52,
59,
4108,
1055,
52,
12,
3628,
59,
4108,
61,
267,
587,
26,
288,
1323,
12,
3628,
275,
1323,
59,
4108,
467,
3628,
59,
4108,
61,
272,
372,
980,
14,
3670,
8,
20329,
526,
310,
14586,
63,
3356,
8,
56,
12,
3628,
12,
6370,
29,
5165,
12,
1011,
10340,
430,
421,
199,
318,
24968,
526,
310,
14586,
63,
3356,
8,
56,
12,
3628,
12,
6370,
534,
26479,
297,
1011,
10340,
304,
272,
408,
8564,
314,
428,
382,
526,
310,
14586,
1849,
21069,
367,
1924,
2690,
14,
339,
710,
428,
382,
526,
69,
337,
266,
1849,
21069,
365,
282,
9775,
402,
4212,
5521,
5845,
787,
824,
527,
3014,
272,
543,
5845,
626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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
] |
bqbn/addons-server
|
src/olympia/scanners/migrations/0004_auto_20191018_0740.py
|
7
|
1115
|
from django.db import migrations
from olympia.constants.scanners import YARA
class Migration(migrations.Migration):
dependencies = [
('scanners', '0003_auto_20191017_1514'),
('yara', '0003_auto_20191010_1446'),
]
operations = [
migrations.RunSQL(
[
(
'INSERT INTO scanners_results ('
' created,'
' modified,'
' upload_id,'
' results,'
' scanner,'
' version_id,'
' has_matches,'
' matches'
') '
'SELECT '
' created,'
' modified,'
' upload_id,'
' %s,'
' %s,'
' version_id,'
' has_matches,'
' matches '
'FROM yara_results;',
['[]', YARA], # [`results`, `scanner`]
)
]
)
]
|
bsd-3-clause
|
[
504,
1639,
14,
697,
492,
6180,
199,
199,
504,
312,
590,
311,
4674,
14,
5559,
14,
551,
27297,
492,
1488,
689,
33,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
551,
27297,
297,
283,
16861,
63,
2495,
63,
1797,
3328,
9570,
63,
1046,
1079,
659,
267,
661,
89,
17956,
297,
283,
16861,
63,
2495,
63,
1797,
3328,
9523,
63,
1079,
2466,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
2540,
4657,
8,
288,
359,
355,
334,
490,
283,
10258,
12872,
4061,
27297,
63,
2604,
661,
490,
283,
221,
2737,
2584,
490,
283,
221,
6042,
2584,
490,
283,
221,
5802,
63,
344,
2584,
490,
283,
221,
2058,
2584,
490,
283,
221,
19121,
2584,
490,
283,
221,
1015,
63,
344,
2584,
490,
283,
221,
965,
63,
6742,
2584,
490,
283,
221,
4450,
7,
490,
5320,
283,
490,
283,
4859,
283,
490,
283,
221,
2737,
2584,
490,
283,
221,
6042,
2584,
490,
283,
221,
5802,
63,
344,
2584,
490,
283,
221,
450,
83,
2584,
490,
283,
221,
450,
83,
2584,
490,
283,
221,
1015,
63,
344,
2584,
490,
283,
221,
965,
63,
6742,
2584,
490,
283,
221,
4450,
283,
490,
283,
12491,
612,
17956,
63,
2604,
10805,
490,
788,
59,
4300,
1488,
689,
33,
467,
221,
327,
359,
64,
2604,
3559,
658,
16378,
64,
61,
355,
776,
288,
1622,
267,
776,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6180,
199,
199,
504,
312,
590,
311,
4674,
14,
5559,
14,
551,
27297,
492,
1488,
689,
33,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
551,
27297,
297,
283,
16861,
63,
2495,
63,
1797,
3328,
9570,
63,
1046,
1079,
659,
267,
661,
89,
17956,
297,
283,
16861,
63,
2495,
63,
1797,
3328,
9523,
63,
1079,
2466,
659,
272,
1622,
339,
5331,
275,
359,
267,
6180,
14,
2540,
4657,
8,
288,
359,
355,
334,
490,
283,
10258,
12872,
4061,
27297,
63,
2604,
661,
490,
283,
221,
2737,
2584,
490,
283,
221,
6042,
2584,
490,
283,
221,
5802,
63,
344,
2584,
490,
283,
221,
2058,
2584,
490,
283,
221,
19121,
2584,
490,
283,
221,
1015,
63,
344,
2584,
490,
283,
221,
965,
63,
6742,
2584,
490,
283,
221,
4450,
7,
490,
5320,
283,
490,
283,
4859,
283,
490,
283,
221,
2737,
2584,
490,
283,
221,
6042,
2584,
490,
283,
221,
5802,
63,
344,
2584,
490,
283,
221,
450,
83,
2584,
490,
283,
221,
450,
83,
2584,
490,
283,
221,
1015,
63,
344,
2584,
490,
283,
221,
965,
63,
6742,
2584,
490,
283,
221,
4450,
283,
490,
283,
12491,
612,
17956,
63,
2604,
10805,
490,
788,
59,
4300,
1488,
689,
33,
467,
221,
327,
359,
64,
2604,
3559,
658,
16378,
64,
61,
355,
776,
288,
1622,
267,
776,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
MobinRanjbar/hue
|
desktop/core/ext-py/boto-2.38.0/boto/ec2/placementgroup.py
|
150
|
2002
|
# Copyright (c) 2010 Mitch Garnaat http://garnaat.org/
#
# 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.
"""
Represents an EC2 Placement Group
"""
from boto.ec2.ec2object import EC2Object
from boto.exception import BotoClientError
class PlacementGroup(EC2Object):
def __init__(self, connection=None, name=None, strategy=None, state=None):
super(PlacementGroup, self).__init__(connection)
self.name = name
self.strategy = strategy
self.state = state
def __repr__(self):
return 'PlacementGroup:%s' % self.name
def endElement(self, name, value, connection):
if name == 'groupName':
self.name = value
elif name == 'strategy':
self.strategy = value
elif name == 'state':
self.state = value
else:
setattr(self, name, value)
def delete(self, dry_run=False):
return self.connection.delete_placement_group(
self.name,
dry_run=dry_run
)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
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,
624,
199,
18089,
376,
15352,
18,
10902,
434,
5611,
199,
624,
199,
504,
6055,
14,
825,
18,
14,
825,
18,
785,
492,
15352,
18,
1692,
199,
504,
6055,
14,
1971,
492,
24411,
19992,
421,
199,
533,
10902,
434,
2448,
8,
4220,
18,
1692,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
10054,
29,
403,
12,
1174,
29,
403,
304,
267,
1613,
8,
32360,
2448,
12,
291,
2843,
826,
721,
2105,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
8590,
275,
10054,
267,
291,
14,
929,
275,
1174,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
32360,
2448,
2689,
83,
7,
450,
291,
14,
354,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
923,
985,
356,
288,
291,
14,
354,
275,
574,
267,
916,
536,
508,
283,
8590,
356,
288,
291,
14,
8590,
275,
574,
267,
916,
536,
508,
283,
929,
356,
288,
291,
14,
929,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
3145,
8,
277,
12,
9951,
63,
1065,
29,
797,
304,
267,
372,
291,
14,
2105,
14,
1807,
63,
16748,
63,
923,
8,
288,
291,
14,
354,
12,
288,
9951,
63,
1065,
29,
10481,
63,
1065,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
7129,
603,
9414,
598,
26272,
1455,
921,
71,
26272,
14,
1308,
15,
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,
624,
199,
18089,
376,
15352,
18,
10902,
434,
5611,
199,
624,
199,
504,
6055,
14,
825,
18,
14,
825,
18,
785,
492,
15352,
18,
1692,
199,
504,
6055,
14,
1971,
492,
24411,
19992,
421,
199,
533,
10902,
434,
2448,
8,
4220,
18,
1692,
304,
339,
347,
636,
826,
721,
277,
12,
1950,
29,
403,
12,
536,
29,
403,
12,
10054,
29,
403,
12,
1174,
29,
403,
304,
267,
1613,
8,
32360,
2448,
12,
291,
2843,
826,
721,
2105,
9,
267,
291,
14,
354,
275,
536,
267,
291,
14,
8590,
275,
10054,
267,
291,
14,
929,
275,
1174,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
32360,
2448,
2689,
83,
7,
450,
291,
14,
354,
339,
347,
28920,
8,
277,
12,
536,
12,
574,
12,
1950,
304,
267,
340,
536,
508,
283,
923,
985,
356,
288,
291,
14,
354,
275,
574,
267,
916,
536,
508,
283,
8590,
356,
288,
291,
14,
8590,
275,
574,
267,
916,
536,
508,
283,
929,
356,
288,
291,
14,
929,
275,
574,
267,
587,
26,
288,
5371,
8,
277,
12,
536,
12,
574,
9,
339,
347,
3145,
8,
277,
12,
9951,
63,
1065,
29,
797,
304,
267,
372,
291,
14,
2105,
14,
1807,
63,
16748,
63,
923,
8,
288,
291,
14,
354,
12,
288,
9951,
63,
1065,
29,
10481,
63,
1065,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Architektor/PySnip
|
venv/lib/python2.7/site-packages/pip/download.py
|
143
|
31722
|
from __future__ import absolute_import
import cgi
import email.utils
import getpass
import json
import logging
import mimetypes
import os
import platform
import re
import shutil
import sys
import tempfile
try:
import ssl # noqa
HAS_TLS = True
except ImportError:
HAS_TLS = False
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves.urllib import request as urllib_request
import pip
from pip.exceptions import InstallationError, HashMismatch
from pip.models import PyPI
from pip.utils import (splitext, rmtree, format_size, display_path,
backup_dir, ask_path_exists, unpack_file,
ARCHIVE_EXTENSIONS, consume, call_subprocess)
from pip.utils.encoding import auto_decode
from pip.utils.filesystem import check_path_owner
from pip.utils.logging import indent_log
from pip.utils.setuptools_build import SETUPTOOLS_SHIM
from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
from pip.locations import write_delete_marker_file
from pip.vcs import vcs
from pip._vendor import requests, six
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response
from pip._vendor.requests.structures import CaseInsensitiveDict
from pip._vendor.requests.packages import urllib3
from pip._vendor.cachecontrol import CacheControlAdapter
from pip._vendor.cachecontrol.caches import FileCache
from pip._vendor.lockfile import LockError
from pip._vendor.six.moves import xmlrpc_client
__all__ = ['get_file_content',
'is_url', 'url_to_path', 'path_to_url',
'is_archive_file', 'unpack_vcs_link',
'unpack_file_url', 'is_vcs_url', 'is_file_url',
'unpack_http_url', 'unpack_url']
logger = logging.getLogger(__name__)
def user_agent():
"""
Return a string representing the user agent.
"""
data = {
"installer": {"name": "pip", "version": pip.__version__},
"python": platform.python_version(),
"implementation": {
"name": platform.python_implementation(),
},
}
if data["implementation"]["name"] == 'CPython':
data["implementation"]["version"] = platform.python_version()
elif data["implementation"]["name"] == 'PyPy':
if sys.pypy_version_info.releaselevel == 'final':
pypy_version_info = sys.pypy_version_info[:3]
else:
pypy_version_info = sys.pypy_version_info
data["implementation"]["version"] = ".".join(
[str(x) for x in pypy_version_info]
)
elif data["implementation"]["name"] == 'Jython':
# Complete Guess
data["implementation"]["version"] = platform.python_version()
elif data["implementation"]["name"] == 'IronPython':
# Complete Guess
data["implementation"]["version"] = platform.python_version()
if sys.platform.startswith("linux"):
distro = dict(filter(
lambda x: x[1],
zip(["name", "version", "id"], platform.linux_distribution()),
))
libc = dict(filter(
lambda x: x[1],
zip(["lib", "version"], platform.libc_ver()),
))
if libc:
distro["libc"] = libc
if distro:
data["distro"] = distro
if sys.platform.startswith("darwin") and platform.mac_ver()[0]:
data["distro"] = {"name": "OS X", "version": platform.mac_ver()[0]}
if platform.system():
data.setdefault("system", {})["name"] = platform.system()
if platform.release():
data.setdefault("system", {})["release"] = platform.release()
if platform.machine():
data["cpu"] = platform.machine()
# Python 2.6 doesn't have ssl.OPENSSL_VERSION.
if HAS_TLS and sys.version_info[:2] > (2, 6):
data["openssl_version"] = ssl.OPENSSL_VERSION
return "{data[installer][name]}/{data[installer][version]} {json}".format(
data=data,
json=json.dumps(data, separators=(",", ":"), sort_keys=True),
)
class MultiDomainBasicAuth(AuthBase):
def __init__(self, prompting=True):
self.prompting = prompting
self.passwords = {}
def __call__(self, req):
parsed = urllib_parse.urlparse(req.url)
# Get the netloc without any embedded credentials
netloc = parsed.netloc.rsplit("@", 1)[-1]
# Set the url of the request to the url without any credentials
req.url = urllib_parse.urlunparse(parsed[:1] + (netloc,) + parsed[2:])
# Use any stored credentials that we have for this netloc
username, password = self.passwords.get(netloc, (None, None))
# Extract credentials embedded in the url if we have none stored
if username is None:
username, password = self.parse_credentials(parsed.netloc)
if username or password:
# Store the username and password
self.passwords[netloc] = (username, password)
# Send the basic auth with this request
req = HTTPBasicAuth(username or "", password or "")(req)
# Attach a hook to handle 401 responses
req.register_hook("response", self.handle_401)
return req
def handle_401(self, resp, **kwargs):
# We only care about 401 responses, anything else we want to just
# pass through the actual response
if resp.status_code != 401:
return resp
# We are not able to prompt the user so simple return the response
if not self.prompting:
return resp
parsed = urllib_parse.urlparse(resp.url)
# Prompt the user for a new username and password
username = six.moves.input("User for %s: " % parsed.netloc)
password = getpass.getpass("Password: ")
# Store the new username and password to use for future requests
if username or password:
self.passwords[parsed.netloc] = (username, password)
# Consume content and release the original connection to allow our new
# request to reuse the same one.
resp.content
resp.raw.release_conn()
# Add our new username and password to the request
req = HTTPBasicAuth(username or "", password or "")(resp.request)
# Send our new request
new_resp = resp.connection.send(req, **kwargs)
new_resp.history.append(resp)
return new_resp
def parse_credentials(self, netloc):
if "@" in netloc:
userinfo = netloc.rsplit("@", 1)[0]
if ":" in userinfo:
return userinfo.split(":", 1)
return userinfo, None
return None, None
class LocalFSAdapter(BaseAdapter):
def send(self, request, stream=None, timeout=None, verify=None, cert=None,
proxies=None):
pathname = url_to_path(request.url)
resp = Response()
resp.status_code = 200
resp.url = request.url
try:
stats = os.stat(pathname)
except OSError as exc:
resp.status_code = 404
resp.raw = exc
else:
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
content_type = mimetypes.guess_type(pathname)[0] or "text/plain"
resp.headers = CaseInsensitiveDict({
"Content-Type": content_type,
"Content-Length": stats.st_size,
"Last-Modified": modified,
})
resp.raw = open(pathname, "rb")
resp.close = resp.raw.close
return resp
def close(self):
pass
class SafeFileCache(FileCache):
"""
A file based cache which is safe to use even when the target directory may
not be accessible or writable.
"""
def __init__(self, *args, **kwargs):
super(SafeFileCache, self).__init__(*args, **kwargs)
# Check to ensure that the directory containing our cache directory
# is owned by the user current executing pip. If it does not exist
# we will check the parent directory until we find one that does exist.
# If it is not owned by the user executing pip then we will disable
# the cache and log a warning.
if not check_path_owner(self.directory):
logger.warning(
"The directory '%s' or its parent directory is not owned by "
"the current user and the cache has been disabled. Please "
"check the permissions and owner of that directory. If "
"executing pip with sudo, you may want sudo's -H flag.",
self.directory,
)
# Set our directory to None to disable the Cache
self.directory = None
def get(self, *args, **kwargs):
# If we don't have a directory, then the cache should be a no-op.
if self.directory is None:
return
try:
return super(SafeFileCache, self).get(*args, **kwargs)
except (LockError, OSError, IOError):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
def set(self, *args, **kwargs):
# If we don't have a directory, then the cache should be a no-op.
if self.directory is None:
return
try:
return super(SafeFileCache, self).set(*args, **kwargs)
except (LockError, OSError, IOError):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
def delete(self, *args, **kwargs):
# If we don't have a directory, then the cache should be a no-op.
if self.directory is None:
return
try:
return super(SafeFileCache, self).delete(*args, **kwargs)
except (LockError, OSError, IOError):
# We intentionally silence this error, if we can't access the cache
# then we can just skip caching and process the request as if
# caching wasn't enabled.
pass
class InsecureHTTPAdapter(HTTPAdapter):
def cert_verify(self, conn, url, verify, cert):
conn.cert_reqs = 'CERT_NONE'
conn.ca_certs = None
class PipSession(requests.Session):
timeout = None
def __init__(self, *args, **kwargs):
retries = kwargs.pop("retries", 0)
cache = kwargs.pop("cache", None)
insecure_hosts = kwargs.pop("insecure_hosts", [])
super(PipSession, self).__init__(*args, **kwargs)
# Attach our User Agent to the request
self.headers["User-Agent"] = user_agent()
# Attach our Authentication handler to the session
self.auth = MultiDomainBasicAuth()
# Create our urllib3.Retry instance which will allow us to customize
# how we handle retries.
retries = urllib3.Retry(
# Set the total number of retries that a particular request can
# have.
total=retries,
# A 503 error from PyPI typically means that the Fastly -> Origin
# connection got interupted in some way. A 503 error in general
# is typically considered a transient error so we'll go ahead and
# retry it.
status_forcelist=[503],
# Add a small amount of back off between failed requests in
# order to prevent hammering the service.
backoff_factor=0.25,
)
# We want to _only_ cache responses on securely fetched origins. We do
# this because we can't validate the response of an insecurely fetched
# origin, and we don't want someone to be able to poison the cache and
# require manual eviction from the cache to fix it.
if cache:
secure_adapter = CacheControlAdapter(
cache=SafeFileCache(cache, use_dir_lock=True),
max_retries=retries,
)
else:
secure_adapter = HTTPAdapter(max_retries=retries)
# Our Insecure HTTPAdapter disables HTTPS validation. It does not
# support caching (see above) so we'll use it for all http:// URLs as
# well as any https:// host that we've marked as ignoring TLS errors
# for.
insecure_adapter = InsecureHTTPAdapter(max_retries=retries)
self.mount("https://", secure_adapter)
self.mount("http://", insecure_adapter)
# Enable file:// urls
self.mount("file://", LocalFSAdapter())
# We want to use a non-validating adapter for any requests which are
# deemed insecure.
for host in insecure_hosts:
self.mount("https://{0}/".format(host), insecure_adapter)
def request(self, method, url, *args, **kwargs):
# Allow setting a default timeout on a session
kwargs.setdefault("timeout", self.timeout)
# Dispatch the actual request
return super(PipSession, self).request(method, url, *args, **kwargs)
def get_file_content(url, comes_from=None, session=None):
"""Gets the content of a file; it may be a filename, file: URL, or
http: URL. Returns (location, content). Content is unicode."""
if session is None:
raise TypeError(
"get_file_content() missing 1 required keyword argument: 'session'"
)
match = _scheme_re.search(url)
if match:
scheme = match.group(1).lower()
if (scheme == 'file' and comes_from and
comes_from.startswith('http')):
raise InstallationError(
'Requirements file %s references URL %s, which is local'
% (comes_from, url))
if scheme == 'file':
path = url.split(':', 1)[1]
path = path.replace('\\', '/')
match = _url_slash_drive_re.match(path)
if match:
path = match.group(1) + ':' + path.split('|', 1)[1]
path = urllib_parse.unquote(path)
if path.startswith('/'):
path = '/' + path.lstrip('/')
url = path
else:
# FIXME: catch some errors
resp = session.get(url)
resp.raise_for_status()
return resp.url, resp.text
try:
with open(url, 'rb') as f:
content = auto_decode(f.read())
except IOError as exc:
raise InstallationError(
'Could not open requirements file: %s' % str(exc)
)
return url, content
_scheme_re = re.compile(r'^(http|https|file):', re.I)
_url_slash_drive_re = re.compile(r'/*([a-z])\|', re.I)
def is_url(name):
"""Returns true if the name looks like a URL"""
if ':' not in name:
return False
scheme = name.split(':', 1)[0].lower()
return scheme in ['http', 'https', 'file', 'ftp'] + vcs.all_schemes
def url_to_path(url):
"""
Convert a file: URL to a path.
"""
assert url.startswith('file:'), (
"You can only turn file: urls into filenames (not %r)" % url)
_, netloc, path, _, _ = urllib_parse.urlsplit(url)
# if we have a UNC path, prepend UNC share notation
if netloc:
netloc = '\\\\' + netloc
path = urllib_request.url2pathname(netloc + path)
return path
def path_to_url(path):
"""
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
"""
path = os.path.normpath(os.path.abspath(path))
url = urllib_parse.urljoin('file:', urllib_request.pathname2url(path))
return url
def is_archive_file(name):
"""Return True if `name` is a considered as an archive file."""
ext = splitext(name)[1].lower()
if ext in ARCHIVE_EXTENSIONS:
return True
return False
def unpack_vcs_link(link, location):
vcs_backend = _get_used_vcs_backend(link)
vcs_backend.unpack(location)
def _get_used_vcs_backend(link):
for backend in vcs.backends:
if link.scheme in backend.schemes:
vcs_backend = backend(link.url)
return vcs_backend
def is_vcs_url(link):
return bool(_get_used_vcs_backend(link))
def is_file_url(link):
return link.url.lower().startswith('file:')
def is_dir_url(link):
"""Return whether a file:// Link points to a directory.
``link`` must not have any other scheme but file://. Call is_file_url()
first.
"""
link_path = url_to_path(link.url_without_fragment)
return os.path.isdir(link_path)
def _progress_indicator(iterable, *args, **kwargs):
return iterable
def _download_url(resp, link, content_file, hashes):
try:
total_length = int(resp.headers['content-length'])
except (ValueError, KeyError, TypeError):
total_length = 0
cached_resp = getattr(resp, "from_cache", False)
if logger.getEffectiveLevel() > logging.INFO:
show_progress = False
elif cached_resp:
show_progress = False
elif total_length > (40 * 1000):
show_progress = True
elif not total_length:
show_progress = True
else:
show_progress = False
show_url = link.show_url
def resp_read(chunk_size):
try:
# Special case for urllib3.
for chunk in resp.raw.stream(
chunk_size,
# We use decode_content=False here because we don't
# want urllib3 to mess with the raw bytes we get
# from the server. If we decompress inside of
# urllib3 then we cannot verify the checksum
# because the checksum will be of the compressed
# file. This breakage will only occur if the
# server adds a Content-Encoding header, which
# depends on how the server was configured:
# - Some servers will notice that the file isn't a
# compressible file and will leave the file alone
# and with an empty Content-Encoding
# - Some servers will notice that the file is
# already compressed and will leave the file
# alone and will add a Content-Encoding: gzip
# header
# - Some servers won't notice anything at all and
# will take a file that's already been compressed
# and compress it again and set the
# Content-Encoding: gzip header
#
# By setting this not to decode automatically we
# hope to eliminate problems with the second case.
decode_content=False):
yield chunk
except AttributeError:
# Standard file-like object.
while True:
chunk = resp.raw.read(chunk_size)
if not chunk:
break
yield chunk
def written_chunks(chunks):
for chunk in chunks:
content_file.write(chunk)
yield chunk
progress_indicator = _progress_indicator
if link.netloc == PyPI.netloc:
url = show_url
else:
url = link.url_without_fragment
if show_progress: # We don't show progress on cached responses
if total_length:
logger.info("Downloading %s (%s)", url, format_size(total_length))
progress_indicator = DownloadProgressBar(max=total_length).iter
else:
logger.info("Downloading %s", url)
progress_indicator = DownloadProgressSpinner().iter
elif cached_resp:
logger.info("Using cached %s", url)
else:
logger.info("Downloading %s", url)
logger.debug('Downloading from URL %s', link)
downloaded_chunks = written_chunks(
progress_indicator(
resp_read(CONTENT_CHUNK_SIZE),
CONTENT_CHUNK_SIZE
)
)
if hashes:
hashes.check_against_chunks(downloaded_chunks)
else:
consume(downloaded_chunks)
def _copy_file(filename, location, link):
copy = True
download_location = os.path.join(location, link.filename)
if os.path.exists(download_location):
response = ask_path_exists(
'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' %
display_path(download_location), ('i', 'w', 'b'))
if response == 'i':
copy = False
elif response == 'w':
logger.warning('Deleting %s', display_path(download_location))
os.remove(download_location)
elif response == 'b':
dest_file = backup_dir(download_location)
logger.warning(
'Backing up %s to %s',
display_path(download_location),
display_path(dest_file),
)
shutil.move(download_location, dest_file)
if copy:
shutil.copy(filename, download_location)
logger.info('Saved %s', display_path(download_location))
def unpack_http_url(link, location, download_dir=None,
session=None, hashes=None):
if session is None:
raise TypeError(
"unpack_http_url() missing 1 required keyword argument: 'session'"
)
temp_dir = tempfile.mkdtemp('-unpack', 'pip-')
# If a download dir is specified, is the file already downloaded there?
already_downloaded_path = None
if download_dir:
already_downloaded_path = _check_download_dir(link,
download_dir,
hashes)
if already_downloaded_path:
from_path = already_downloaded_path
content_type = mimetypes.guess_type(from_path)[0]
else:
# let's download to a tmp dir
from_path, content_type = _download_http_url(link,
session,
temp_dir,
hashes)
# unpack the archive to the build dir location. even when only downloading
# archives, they have to be unpacked to parse dependencies
unpack_file(from_path, location, content_type, link)
# a download dir is specified; let's copy the archive there
if download_dir and not already_downloaded_path:
_copy_file(from_path, download_dir, link)
if not already_downloaded_path:
os.unlink(from_path)
rmtree(temp_dir)
def unpack_file_url(link, location, download_dir=None, hashes=None):
"""Unpack link into location.
If download_dir is provided and link points to a file, make a copy
of the link file inside download_dir.
"""
link_path = url_to_path(link.url_without_fragment)
# If it's a url to a local directory
if is_dir_url(link):
if os.path.isdir(location):
rmtree(location)
shutil.copytree(link_path, location, symlinks=True)
if download_dir:
logger.info('Link is a directory, ignoring download_dir')
return
# If --require-hashes is off, `hashes` is either empty, the
# link's embeddded hash, or MissingHashes; it is required to
# match. If --require-hashes is on, we are satisfied by any
# hash in `hashes` matching: a URL-based or an option-based
# one; no internet-sourced hash will be in `hashes`.
if hashes:
hashes.check_against_path(link_path)
# If a download dir is specified, is the file already there and valid?
already_downloaded_path = None
if download_dir:
already_downloaded_path = _check_download_dir(link,
download_dir,
hashes)
if already_downloaded_path:
from_path = already_downloaded_path
else:
from_path = link_path
content_type = mimetypes.guess_type(from_path)[0]
# unpack the archive to the build dir location. even when only downloading
# archives, they have to be unpacked to parse dependencies
unpack_file(from_path, location, content_type, link)
# a download dir is specified and not already downloaded
if download_dir and not already_downloaded_path:
_copy_file(from_path, download_dir, link)
def _copy_dist_from_dir(link_path, location):
"""Copy distribution files in `link_path` to `location`.
Invoked when user requests to install a local directory. E.g.:
pip install .
pip install ~/dev/git-repos/python-prompt-toolkit
"""
# Note: This is currently VERY SLOW if you have a lot of data in the
# directory, because it copies everything with `shutil.copytree`.
# What it should really do is build an sdist and install that.
# See https://github.com/pypa/pip/issues/2195
if os.path.isdir(location):
rmtree(location)
# build an sdist
setup_py = 'setup.py'
sdist_args = [sys.executable]
sdist_args.append('-c')
sdist_args.append(SETUPTOOLS_SHIM % setup_py)
sdist_args.append('sdist')
sdist_args += ['--dist-dir', location]
logger.info('Running setup.py sdist for %s', link_path)
with indent_log():
call_subprocess(sdist_args, cwd=link_path, show_stdout=False)
# unpack sdist into `location`
sdist = os.path.join(location, os.listdir(location)[0])
logger.info('Unpacking sdist %s into %s', sdist, location)
unpack_file(sdist, location, content_type=None, link=None)
class PipXmlrpcTransport(xmlrpc_client.Transport):
"""Provide a `xmlrpclib.Transport` implementation via a `PipSession`
object.
"""
def __init__(self, index_url, session, use_datetime=False):
xmlrpc_client.Transport.__init__(self, use_datetime)
index_parts = urllib_parse.urlparse(index_url)
self._scheme = index_parts.scheme
self._session = session
def request(self, host, handler, request_body, verbose=False):
parts = (self._scheme, host, handler, None, None, None)
url = urllib_parse.urlunparse(parts)
try:
headers = {'Content-Type': 'text/xml'}
response = self._session.post(url, data=request_body,
headers=headers, stream=True)
response.raise_for_status()
self.verbose = verbose
return self.parse_response(response.raw)
except requests.HTTPError as exc:
logger.critical(
"HTTP error %s while getting %s",
exc.response.status_code, url,
)
raise
def unpack_url(link, location, download_dir=None,
only_download=False, session=None, hashes=None):
"""Unpack link.
If link is a VCS link:
if only_download, export into download_dir and ignore location
else unpack into location
for other types of link:
- unpack into location
- if download_dir, copy the file into download_dir
- if only_download, mark location for deletion
:param hashes: A Hashes object, one of whose embedded hashes must match,
or HashMismatch will be raised. If the Hashes is empty, no matches are
required, and unhashable types of requirements (like VCS ones, which
would ordinarily raise HashUnsupported) are allowed.
"""
# non-editable vcs urls
if is_vcs_url(link):
unpack_vcs_link(link, location)
# file urls
elif is_file_url(link):
unpack_file_url(link, location, download_dir, hashes=hashes)
# http urls
else:
if session is None:
session = PipSession()
unpack_http_url(
link,
location,
download_dir,
session,
hashes=hashes
)
if only_download:
write_delete_marker_file(location)
def _download_http_url(link, session, temp_dir, hashes):
"""Download link url into temp_dir using provided session"""
target_url = link.url.split('#', 1)[0]
try:
resp = session.get(
target_url,
# We use Accept-Encoding: identity here because requests
# defaults to accepting compressed responses. This breaks in
# a variety of ways depending on how the server is configured.
# - Some servers will notice that the file isn't a compressible
# file and will leave the file alone and with an empty
# Content-Encoding
# - Some servers will notice that the file is already
# compressed and will leave the file alone and will add a
# Content-Encoding: gzip header
# - Some servers won't notice anything at all and will take
# a file that's already been compressed and compress it again
# and set the Content-Encoding: gzip header
# By setting this to request only the identity encoding We're
# hoping to eliminate the third case. Hopefully there does not
# exist a server which when given a file will notice it is
# already compressed and that you're not asking for a
# compressed file and will then decompress it before sending
# because if that's the case I don't think it'll ever be
# possible to make this work.
headers={"Accept-Encoding": "identity"},
stream=True,
)
resp.raise_for_status()
except requests.HTTPError as exc:
logger.critical(
"HTTP error %s while getting %s", exc.response.status_code, link,
)
raise
content_type = resp.headers.get('content-type', '')
filename = link.filename # fallback
# Have a look at the Content-Disposition header for a better guess
content_disposition = resp.headers.get('content-disposition')
if content_disposition:
type, params = cgi.parse_header(content_disposition)
# We use ``or`` here because we don't want to use an "empty" value
# from the filename param.
filename = params.get('filename') or filename
ext = splitext(filename)[1]
if not ext:
ext = mimetypes.guess_extension(content_type)
if ext:
filename += ext
if not ext and link.url != resp.url:
ext = os.path.splitext(resp.url)[1]
if ext:
filename += ext
file_path = os.path.join(temp_dir, filename)
with open(file_path, 'wb') as content_file:
_download_url(resp, link, content_file, hashes)
return file_path, content_type
def _check_download_dir(link, download_dir, hashes):
""" Check download_dir for previously downloaded file with correct hash
If a correct file is found return its path else None
"""
download_path = os.path.join(download_dir, link.filename)
if os.path.exists(download_path):
# If already downloaded, does its hash match?
logger.info('File was already downloaded %s', download_path)
if hashes:
try:
hashes.check_against_path(download_path)
except HashMismatch:
logger.warning(
'Previously-downloaded file %s has bad hash. '
'Re-downloading.',
download_path
)
os.unlink(download_path)
return None
return download_path
return None
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
16004,
199,
646,
3031,
14,
1208,
199,
646,
18354,
199,
646,
2022,
199,
646,
2050,
199,
646,
13290,
199,
646,
747,
199,
646,
4298,
199,
646,
295,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
893,
26,
272,
492,
6149,
221,
327,
8151,
272,
7509,
63,
10224,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
10224,
275,
756,
199,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
2198,
465,
4011,
63,
1122,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
1056,
465,
4011,
63,
1069,
199,
199,
646,
7305,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
12,
16101,
23055,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
1208,
492,
334,
7973,
12,
20978,
12,
1475,
63,
890,
12,
2929,
63,
515,
12,
2432,
6902,
63,
694,
12,
7198,
63,
515,
63,
2444,
12,
7787,
63,
493,
12,
2432,
4160,
1244,
5399,
63,
18451,
12,
9451,
12,
1240,
63,
5781,
9,
199,
504,
7305,
14,
1208,
14,
2991,
492,
2599,
63,
2708,
199,
504,
7305,
14,
1208,
14,
11381,
492,
1104,
63,
515,
63,
4597,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
1208,
14,
13623,
63,
1506,
492,
11543,
2160,
20261,
63,
3234,
1469,
199,
504,
7305,
14,
1208,
14,
1907,
492,
17955,
11504,
5281,
12,
17955,
11504,
5058,
5216,
199,
504,
7305,
14,
8022,
492,
2218,
63,
1807,
63,
4211,
63,
493,
199,
504,
7305,
14,
15525,
492,
19827,
199,
504,
7305,
423,
9884,
492,
4145,
12,
3816,
199,
504,
7305,
423,
9884,
14,
6615,
14,
21680,
492,
3523,
10200,
12,
3101,
10200,
199,
504,
7305,
423,
9884,
14,
6615,
14,
1178,
492,
3590,
1563,
12,
3101,
6845,
2817,
199,
504,
7305,
423,
9884,
14,
6615,
14,
992,
492,
29417,
63,
20512,
63,
4305,
12,
7232,
199,
504,
7305,
423,
9884,
14,
6615,
14,
13547,
492,
12425,
32697,
199,
504,
7305,
423,
9884,
14,
6615,
14,
5154,
492,
4011,
19,
199,
504,
7305,
423,
9884,
14,
1637,
2785,
492,
11977,
3717,
10200,
199,
504,
7305,
423,
9884,
14,
1637,
2785,
14,
17595,
492,
3814,
4437,
199,
504,
7305,
423,
9884,
14,
26204,
492,
15536,
547,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
15432,
63,
1258,
421,
199,
363,
452,
363,
275,
788,
362,
63,
493,
63,
1317,
297,
1779,
283,
374,
63,
633,
297,
283,
633,
63,
475,
63,
515,
297,
283,
515,
63,
475,
63,
633,
297,
1779,
283,
374,
63,
6404,
63,
493,
297,
283,
5301,
63,
15525,
63,
1073,
297,
1779,
283,
5301,
63,
493,
63,
633,
297,
283,
374,
63,
15525,
63,
633,
297,
283,
374,
63,
493,
63,
633,
297,
1779,
283,
5301,
63,
1014,
63,
633,
297,
283,
5301,
63,
633,
418,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
922,
63,
4054,
837,
272,
408,
272,
1432,
282,
1059,
6144,
314,
922,
6631,
14,
272,
408,
272,
666,
275,
469,
267,
298,
17047,
582,
2420,
354,
582,
298,
9983,
401,
298,
1023,
582,
7305,
855,
1023,
363,
1386,
267,
298,
1548,
582,
4298,
14,
1548,
63,
1023,
1062,
267,
298,
12236,
582,
469,
288,
298,
354,
582,
4298,
14,
1548,
63,
12236,
1062,
267,
1660,
272,
789,
339,
340,
666,
905,
12236,
6611,
354,
937,
508,
283,
35,
4718,
356,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
2713,
2713,
356,
267,
340,
984,
14,
20233,
63,
1023,
63,
815,
14,
3221,
1896,
508,
283,
5094,
356,
288,
1134,
647,
63,
1023,
63,
815,
275,
984,
14,
20233,
63,
1023,
63,
815,
1491,
19,
61,
267,
587,
26,
288,
1134,
647,
63,
1023,
63,
815,
275,
984,
14,
20233,
63,
1023,
63,
815,
267,
666,
905,
12236,
6611,
1023,
937,
275,
32443,
904,
8,
288,
359,
495,
8,
88,
9,
367,
671,
315,
1134,
647,
63,
1023,
63,
815,
61,
267,
776,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
42,
11361,
356,
267,
327,
28393,
24570,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
41,
2641,
4718,
356,
267,
327,
28393,
24570,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
339,
340,
984,
14,
3246,
14,
2460,
480,
5135,
2349,
267,
20499,
275,
1211,
8,
1541,
8,
288,
2400,
671,
26,
671,
59,
17,
467,
288,
3482,
5234,
354,
401,
298,
1023,
401,
298,
344,
2255,
4298,
14,
5135,
63,
4972,
4000,
267,
5082,
267,
1973,
67,
275,
1211,
8,
1541,
8,
288,
2400,
671,
26,
671,
59,
17,
467,
288,
3482,
5234,
773,
401,
298,
1023,
2255,
4298,
14,
20217,
63,
422,
4000,
267,
5082,
267,
340,
1973,
67,
26,
288,
20499,
905,
20217,
937,
275,
1973,
67,
267,
340,
20499,
26,
288,
666,
905,
18371,
937,
275,
20499,
339,
340,
984,
14,
3246,
14,
2460,
480,
13245,
531,
436,
4298,
14,
3088,
63,
422,
3430,
16,
2189,
267,
666,
905,
18371,
937,
275,
2420,
354,
582,
298,
3100,
1323,
401,
298,
1023,
582,
4298,
14,
3088,
63,
422,
3430,
16,
9420,
339,
340,
4298,
14,
2253,
837,
267,
666,
14,
5486,
480,
2253,
401,
5009,
905,
354,
937,
275,
4298,
14,
2253,
342,
339,
340,
4298,
14,
3221,
837,
267,
666,
14,
5486,
480,
2253,
401,
5009,
905,
3221,
937,
275,
4298,
14,
3221,
342,
339,
340,
4298,
14,
6744,
837,
267,
666,
905,
3541,
937,
275,
4298,
14,
6744,
342,
339,
327,
2018,
499,
14,
22,
3181,
1133,
1172,
6149,
14,
9935,
5413,
63,
4612,
14,
272,
340,
7509,
63,
10224,
436,
984,
14,
1023,
63,
815,
1491,
18,
61,
690,
334,
18,
12,
1227,
304,
267,
666,
905,
14837,
63,
1023,
937,
275,
6149,
14,
9935,
5413,
63,
4612,
339,
372,
5310,
576,
59,
17047,
1527,
354,
9420,
5321,
576,
59,
17047,
1527,
1023,
9420,
469,
1001,
5469,
908,
8,
267,
666,
29,
576,
12,
267,
2022,
29
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
16004,
199,
646,
3031,
14,
1208,
199,
646,
18354,
199,
646,
2022,
199,
646,
2050,
199,
646,
13290,
199,
646,
747,
199,
646,
4298,
199,
646,
295,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
893,
26,
272,
492,
6149,
221,
327,
8151,
272,
7509,
63,
10224,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
10224,
275,
756,
199,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
2198,
465,
4011,
63,
1122,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
14,
4078,
492,
1056,
465,
4011,
63,
1069,
199,
199,
646,
7305,
199,
199,
504,
7305,
14,
3924,
492,
26866,
547,
12,
16101,
23055,
199,
504,
7305,
14,
992,
492,
24330,
199,
504,
7305,
14,
1208,
492,
334,
7973,
12,
20978,
12,
1475,
63,
890,
12,
2929,
63,
515,
12,
2432,
6902,
63,
694,
12,
7198,
63,
515,
63,
2444,
12,
7787,
63,
493,
12,
2432,
4160,
1244,
5399,
63,
18451,
12,
9451,
12,
1240,
63,
5781,
9,
199,
504,
7305,
14,
1208,
14,
2991,
492,
2599,
63,
2708,
199,
504,
7305,
14,
1208,
14,
11381,
492,
1104,
63,
515,
63,
4597,
199,
504,
7305,
14,
1208,
14,
4806,
492,
4363,
63,
793,
199,
504,
7305,
14,
1208,
14,
13623,
63,
1506,
492,
11543,
2160,
20261,
63,
3234,
1469,
199,
504,
7305,
14,
1208,
14,
1907,
492,
17955,
11504,
5281,
12,
17955,
11504,
5058,
5216,
199,
504,
7305,
14,
8022,
492,
2218,
63,
1807,
63,
4211,
63,
493,
199,
504,
7305,
14,
15525,
492,
19827,
199,
504,
7305,
423,
9884,
492,
4145,
12,
3816,
199,
504,
7305,
423,
9884,
14,
6615,
14,
21680,
492,
3523,
10200,
12,
3101,
10200,
199,
504,
7305,
423,
9884,
14,
6615,
14,
1178,
492,
3590,
1563,
12,
3101,
6845,
2817,
199,
504,
7305,
423,
9884,
14,
6615,
14,
992,
492,
29417,
63,
20512,
63,
4305,
12,
7232,
199,
504,
7305,
423,
9884,
14,
6615,
14,
13547,
492,
12425,
32697,
199,
504,
7305,
423,
9884,
14,
6615,
14,
5154,
492,
4011,
19,
199,
504,
7305,
423,
9884,
14,
1637,
2785,
492,
11977,
3717,
10200,
199,
504,
7305,
423,
9884,
14,
1637,
2785,
14,
17595,
492,
3814,
4437,
199,
504,
7305,
423,
9884,
14,
26204,
492,
15536,
547,
199,
504,
7305,
423,
9884,
14,
4174,
14,
4912,
492,
15432,
63,
1258,
421,
199,
363,
452,
363,
275,
788,
362,
63,
493,
63,
1317,
297,
1779,
283,
374,
63,
633,
297,
283,
633,
63,
475,
63,
515,
297,
283,
515,
63,
475,
63,
633,
297,
1779,
283,
374,
63,
6404,
63,
493,
297,
283,
5301,
63,
15525,
63,
1073,
297,
1779,
283,
5301,
63,
493,
63,
633,
297,
283,
374,
63,
15525,
63,
633,
297,
283,
374,
63,
493,
63,
633,
297,
1779,
283,
5301,
63,
1014,
63,
633,
297,
283,
5301,
63,
633,
418,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
922,
63,
4054,
837,
272,
408,
272,
1432,
282,
1059,
6144,
314,
922,
6631,
14,
272,
408,
272,
666,
275,
469,
267,
298,
17047,
582,
2420,
354,
582,
298,
9983,
401,
298,
1023,
582,
7305,
855,
1023,
363,
1386,
267,
298,
1548,
582,
4298,
14,
1548,
63,
1023,
1062,
267,
298,
12236,
582,
469,
288,
298,
354,
582,
4298,
14,
1548,
63,
12236,
1062,
267,
1660,
272,
789,
339,
340,
666,
905,
12236,
6611,
354,
937,
508,
283,
35,
4718,
356,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
2713,
2713,
356,
267,
340,
984,
14,
20233,
63,
1023,
63,
815,
14,
3221,
1896,
508,
283,
5094,
356,
288,
1134,
647,
63,
1023,
63,
815,
275,
984,
14,
20233,
63,
1023,
63,
815,
1491,
19,
61,
267,
587,
26,
288,
1134,
647,
63,
1023,
63,
815,
275,
984,
14,
20233,
63,
1023,
63,
815,
267,
666,
905,
12236,
6611,
1023,
937,
275,
32443,
904,
8,
288,
359,
495,
8,
88,
9,
367,
671,
315,
1134,
647,
63,
1023,
63,
815,
61,
267,
776,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
42,
11361,
356,
267,
327,
28393,
24570,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
272,
916,
666,
905,
12236,
6611,
354,
937,
508,
283,
41,
2641,
4718,
356,
267,
327,
28393,
24570,
267,
666,
905,
12236,
6611,
1023,
937,
275,
4298,
14,
1548,
63,
1023,
342,
339,
340,
984,
14,
3246,
14,
2460,
480,
5135,
2349,
267,
20499,
275,
1211,
8,
1541,
8,
288,
2400,
671,
26,
671,
59,
17,
467,
288,
3482,
5234,
354,
401,
298,
1023,
401,
298,
344,
2255,
4298,
14,
5135,
63,
4972,
4000,
267,
5082,
267,
1973,
67,
275,
1211,
8,
1541,
8,
288,
2400,
671,
26,
671,
59,
17,
467,
288,
3482,
5234,
773,
401,
298,
1023,
2255,
4298,
14,
20217,
63,
422,
4000,
267,
5082,
267,
340,
1973,
67,
26,
288,
20499,
905,
20217,
937,
275,
1973,
67,
267,
340,
20499,
26,
288,
666,
905,
18371,
937,
275,
20499,
339,
340,
984,
14,
3246,
14,
2460,
480,
13245,
531,
436,
4298,
14,
3088,
63,
422,
3430,
16,
2189,
267,
666,
905,
18371,
937,
275,
2420,
354,
582,
298,
3100,
1323,
401,
298,
1023,
582,
4298,
14,
3088,
63,
422,
3430,
16,
9420,
339,
340,
4298,
14,
2253,
837,
267,
666,
14,
5486,
480,
2253,
401,
5009,
905,
354,
937,
275,
4298,
14,
2253,
342,
339,
340,
4298,
14,
3221,
837,
267,
666,
14,
5486,
480,
2253,
401,
5009,
905,
3221,
937,
275,
4298,
14,
3221,
342,
339,
340,
4298,
14,
6744,
837,
267,
666,
905,
3541,
937,
275,
4298,
14,
6744,
342,
339,
327,
2018,
499,
14,
22,
3181,
1133,
1172,
6149,
14,
9935,
5413,
63,
4612,
14,
272,
340,
7509,
63,
10224,
436,
984,
14,
1023,
63,
815,
1491,
18,
61,
690,
334,
18,
12,
1227,
304,
267,
666,
905,
14837,
63,
1023,
937,
275,
6149,
14,
9935,
5413,
63,
4612,
339,
372,
5310,
576,
59,
17047,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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
] |
tpoisot/tammy
|
tests/services.py
|
1
|
1229
|
#! /usr/bin/env python3
import sys, os
import unittest
import yaml
import json
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import tammy
class PeerJ(unittest.TestCase):
def test_pubtype(self):
self.assertRaises(ValueError, tammy.from_peerj, 200, 'paper')
def test_argtype(self):
self.assertRaises(TypeError, tammy.from_peerj, ['200'], 'article')
def test_works_for_paper(self):
test_paper = tammy.from_peerj(251, 'article')
assert test_paper[u'author'][0][u'family'] == u'Poisot'
def test_no_id(self):
self.assertRaises(ValueError, tammy.from_peerj, 0, 'article')
def test_works_for_preprint(self):
test_paper = tammy.from_peerj(50, 'preprint')
assert test_paper[u'author'][0][u'family'] == u'Poisot'
class CrossRef(unittest.TestCase):
def test_correct_doi(self):
assert isinstance(tammy.from_crossref_doi('10.7717/peerj.426'), dict)
def test_no_doi(self):
with self.assertRaises(ValueError):
tammy.from_crossref_doi('no/no/no')
def main():
if sys.version_info[1] < 7 :
unittest.main(verbosity=2)
else :
unittest.main(verbosity=2)
if __name__ == '__main__':
main()
|
bsd-2-clause
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
984,
12,
747,
199,
646,
2882,
199,
646,
8864,
199,
646,
2022,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
646,
307,
455,
1662,
199,
199,
533,
11379,
281,
42,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5645,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
1926,
12,
283,
10443,
358,
272,
347,
511,
63,
1273,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
788,
1840,
995,
283,
6934,
358,
272,
347,
511,
63,
12243,
63,
509,
63,
10443,
8,
277,
304,
267,
511,
63,
10443,
275,
307,
455,
1662,
14,
504,
63,
7866,
74,
8,
12140,
12,
283,
6934,
358,
267,
702,
511,
63,
10443,
59,
85,
7,
2502,
3488,
16,
1527,
85,
7,
6606,
418,
508,
399,
7,
1575,
374,
357,
7,
272,
347,
511,
63,
889,
63,
344,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
378,
12,
283,
6934,
358,
272,
347,
511,
63,
12243,
63,
509,
63,
657,
1361,
8,
277,
304,
267,
511,
63,
10443,
275,
307,
455,
1662,
14,
504,
63,
7866,
74,
8,
1400,
12,
283,
657,
1361,
358,
267,
702,
511,
63,
10443,
59,
85,
7,
2502,
3488,
16,
1527,
85,
7,
6606,
418,
508,
399,
7,
1575,
374,
357,
7,
199,
199,
533,
28965,
2891,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4525,
63,
27334,
8,
277,
304,
267,
702,
1228,
8,
84,
455,
1662,
14,
504,
63,
7925,
1121,
63,
27334,
360,
709,
14,
1138,
1196,
15,
7866,
74,
14,
25422,
659,
1211,
9,
272,
347,
511,
63,
889,
63,
27334,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
307,
455,
1662,
14,
504,
63,
7925,
1121,
63,
27334,
360,
889,
15,
889,
15,
889,
358,
199,
199,
318,
2446,
837,
272,
340,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1520,
520,
267,
2882,
14,
973,
8,
9833,
29,
18,
9,
272,
587,
520,
267,
2882,
14,
973,
8,
9833,
29,
18,
9,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
646,
984,
12,
747,
199,
646,
2882,
199,
646,
8864,
199,
646,
2022,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
11541,
1333,
199,
646,
307,
455,
1662,
199,
199,
533,
11379,
281,
42,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
5645,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
1926,
12,
283,
10443,
358,
272,
347,
511,
63,
1273,
466,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
788,
1840,
995,
283,
6934,
358,
272,
347,
511,
63,
12243,
63,
509,
63,
10443,
8,
277,
304,
267,
511,
63,
10443,
275,
307,
455,
1662,
14,
504,
63,
7866,
74,
8,
12140,
12,
283,
6934,
358,
267,
702,
511,
63,
10443,
59,
85,
7,
2502,
3488,
16,
1527,
85,
7,
6606,
418,
508,
399,
7,
1575,
374,
357,
7,
272,
347,
511,
63,
889,
63,
344,
8,
277,
304,
267,
291,
14,
1855,
8,
3393,
12,
307,
455,
1662,
14,
504,
63,
7866,
74,
12,
378,
12,
283,
6934,
358,
272,
347,
511,
63,
12243,
63,
509,
63,
657,
1361,
8,
277,
304,
267,
511,
63,
10443,
275,
307,
455,
1662,
14,
504,
63,
7866,
74,
8,
1400,
12,
283,
657,
1361,
358,
267,
702,
511,
63,
10443,
59,
85,
7,
2502,
3488,
16,
1527,
85,
7,
6606,
418,
508,
399,
7,
1575,
374,
357,
7,
199,
199,
533,
28965,
2891,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
4525,
63,
27334,
8,
277,
304,
267,
702,
1228,
8,
84,
455,
1662,
14,
504,
63,
7925,
1121,
63,
27334,
360,
709,
14,
1138,
1196,
15,
7866,
74,
14,
25422,
659,
1211,
9,
272,
347,
511,
63,
889,
63,
27334,
8,
277,
304,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
307,
455,
1662,
14,
504,
63,
7925,
1121,
63,
27334,
360,
889,
15,
889,
15,
889,
358,
199,
199,
318,
2446,
837,
272,
340,
984,
14,
1023,
63,
815,
59,
17,
61,
665,
1520,
520,
267,
2882,
14,
973,
8,
9833,
29,
18,
9,
272,
587,
520,
267,
2882,
14,
973,
8,
9833,
29,
18,
9,
199,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jahantech/Python
|
information_system.py
|
1
|
9855
|
#!/usr/bin/python
import webbrowser
import os
import datetime
def stringchecker (orig,v1):
ret = True
x = len(v1)
j=0
for j in range(0,x,1):
if(len(v1)<=len(orig)):
if orig[j].capitalize() == v1[j] or orig[j]==v1[j]:
ret = ret and True
elif orig[j] != v1[j]:
ret = ret and False
else:
ret = ret and False
return ret
username = raw_input("Login Name:")
while 1:
print "\n**************************************************************"
print "1:Customer\n2:Suppliers\n3:Useful Calls\n4:Useful Data\n5:Contacts and emails\n6:Clear Screen"
print "7:End the Program\n8:Internet\n9:Edit Data\n10:Printers"
sel = raw_input("Please Select an Option:")
print "**************************************************************\n"
if sel=="1":
phonenum = raw_input("Enter the telephone Number OR Account Code:")
v = phonenum
status1 = raw_input("Log a new call? (Y or N):")
NUMBERFILE = open("numfile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
i=0
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "New call logged"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==4):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="2":
phonenum = raw_input("Enter the Supplier Name:")
v = phonenum
status1 = raw_input("New call? (Y or N):")
NUMBERFILE = open("suppfile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "NEW CALL LOGGED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==4):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="3":
phonenum = raw_input("Name:")
v = phonenum
status1 = raw_input("Enter contact (Y/N):")
NUMBERFILE = open("confile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "NEW CONTACT ADDED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==4):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="4":
phonenum = raw_input("Data to Search:")
status1 = raw_input("New Data(Y/N):")
NUMBERFILE = open("datafile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
v = phonenum
i=0
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "NEW DATA ENTERED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==4):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="5":
phonenum = raw_input("Contact or Number to Search:")
status1 = raw_input("New Contact(Y/N):")
NUMBERFILE = open("incon.txt","r+")
NUMLINES = NUMBERFILE.readlines()
v = phonenum
i=0
if status1 == "Y":
comm1 = raw_input("Enter the details:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+" " +comm1+"\n=========================")
print "NEW Contact ENTERED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==1):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="6":
os.system('CLS')
elif sel=="7":
print "Thanks for using this software"
exit()
elif sel=="8":
url = raw_input("Enter the URL:")
webbrowser.open("http://"+url,new=2)
elif sel=="9":
phonenum = raw_input("Data to Search:")
status1 = "N"
NUMBERFILE = open("datafile.txt","r+")
TEMPFILE = open("tempfile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
linecount =0
v = phonenum
i=0
if status1 == "Y":
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
linecount = linecount + 1
if(stringchecker(phonenum,v) or (i>0)):
phonenum = phonenum.replace("\n"," ")
print phonenum+" at line:"+str(linecount)
i = i+ 1
if (i==4):
i=0
else:
i = 0
linecount=0
editline = input("Enter the Line Number to edit:")
print "\n*********************\n"
phonenum =""
for phonenum in NUMLINES:
linecount = linecount + 1
if(linecount==editline):
print "ORIGINAL DATA:"+phonenum
CHANGED = raw_input("Enter new Data:")
TEMPFILE.write(CHANGED+"\n")
else:
TEMPFILE.write(phonenum)
i = 0
TEMPFILE.close()
NUMBERFILE.close()
os.remove("datafile.txt")
os.rename("tempfile.txt","datafile.txt")
TEMPNEW = open("tempfile.txt","w+")
elif sel=="10":
phonenum = raw_input("Enter Printer Serial Number or Press Enter:")
status1 = "N"
NUMBERFILE = open("printers.txt","r+")
NUMLINES = NUMBERFILE.readlines()
v = phonenum
i=0
if status1 == "Y":
comm1 = raw_input("Enter the details:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+" " +comm1+"\n=========================")
print "NEW Contact ENTERED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==1):
i=0
else:
i = 0
NUMBERFILE.close()
if sel=="1":
phonenum = raw_input("Enter the telephone Number OR Account Code:")
v = phonenum
status1 = raw_input("Log a new call? (Y or N):")
NUMBERFILE = open("numfile.txt","r+")
NUMLINES = NUMBERFILE.readlines()
i=0
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "New call logged"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if(stringchecker(phonenum,v) or (i>0)):
print phonenum
i = i+ 1
if (i==4):
i=0
else:
i = 0
NUMBERFILE.close()
elif sel=="11":
phonenum = raw_input("Enter the WORD:")
v = phonenum
status1 = "N"
NUMBERFILE = open("datafile.txt","r+")
NUMLINES = NUMBERFILE.read()
if status1 == "Y":
comm1 = raw_input("Enter the comments:")
now = datetime.datetime.now()
NUMBERFILE.write("=========================\n"+phonenum+"\n" +comm1+"\n"+str(now)+" By:"+username+"\n=========================")
print "NEW CALL LOGGED SUCCESSFULLY"
NUMBERFILE.close()
elif status1 == "N":
print "\n*********************\n"
for phonenum in NUMLINES:
if stringchecker(phonenum,v):
print "MATCHED"
NUMBERFILE.close()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
646,
781,
29063,
199,
646,
747,
199,
646,
2197,
199,
199,
318,
1059,
6743,
334,
2981,
12,
86,
17,
304,
199,
2203,
275,
715,
199,
671,
275,
822,
8,
86,
17,
9,
199,
1335,
29,
16,
199,
367,
1335,
315,
1425,
8,
16,
12,
88,
12,
17,
304,
272,
340,
8,
552,
8,
86,
17,
9,
12932,
552,
8,
2981,
2298,
489,
340,
2306,
59,
74,
1055,
18351,
342,
508,
373,
17,
59,
74,
61,
503,
2306,
59,
74,
19219,
86,
17,
59,
74,
2189,
881,
2203,
275,
2203,
436,
715,
489,
916,
2306,
59,
74,
61,
1137,
373,
17,
59,
74,
2189,
881,
2203,
275,
2203,
436,
756,
272,
587,
26,
489,
2203,
275,
2203,
436,
756,
421,
372,
2203,
421,
199,
2473,
275,
3066,
63,
1210,
480,
8880,
2812,
9107,
199,
199,
6710,
413,
26,
199,
870,
1867,
78,
5815,
30948,
26537,
2,
199,
870,
298,
17,
26,
17025,
60,
78,
18,
26,
17127,
14035,
60,
78,
19,
26,
6119,
1893,
28055,
60,
78,
20,
26,
6119,
1893,
3918,
60,
78,
21,
26,
714,
11961,
436,
14931,
60,
78,
22,
26,
9721,
17804,
2,
199,
870,
221,
298,
23,
26,
3005,
314,
18841,
60,
78,
24,
26,
29820,
60,
78,
25,
26,
4685,
3918,
60,
78,
709,
26,
9779,
11005,
2,
199,
13680,
275,
3066,
63,
1210,
480,
8254,
9496,
376,
3207,
9107,
199,
870,
298,
5815,
30948,
1116,
23262,
78,
2,
421,
340,
13680,
11800,
17,
582,
2742,
221,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
8468,
314,
14001,
9339,
4860,
1549,
9973,
5495,
9107,
881,
373,
275,
3945,
265,
4869,
17957,
2004,
17,
275,
3066,
63,
1210,
480,
2445,
282,
892,
1240,
31,
334,
57,
503,
653,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
1507,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
881,
284,
29,
16,
2742,
221,
340,
2004,
17,
508,
298,
57,
582,
272,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
4665,
1240,
10367,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
7846,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
8592,
18122,
3817,
14,
1600,
342,
221,
421,
916,
13680,
11800,
18,
582,
1362,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
8468,
314,
29083,
5697,
2812,
9107,
881,
373,
275,
3945,
265,
4869,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
4665,
1240,
31,
334,
57,
503,
653,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
8621,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
421,
17957,
340,
2004,
17,
508,
298,
57,
582,
1362,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
11365,
24251,
3412,
2916,
1149,
28364,
14742,
57,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
21979,
288,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
8592,
18122,
3817,
14,
1600,
342,
16421,
199,
916,
13680,
11800,
19,
582,
1779,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
985,
9107,
881,
373,
275,
3945,
265,
4869,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
8468,
8966,
334,
57,
15,
46,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
388,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
2742,
221,
340,
2004,
17,
508,
298,
57,
582,
1362,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
11365,
7408,
3036,
16271,
8280,
28364,
14742,
57,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
523,
288,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
4388,
881,
18122,
3817,
14,
1600,
342,
221,
421,
916,
13680,
11800,
20,
582,
1779,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
1451,
370,
8730,
9107,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
4665,
3918,
8
] |
[
2647,
15,
1393,
15,
1548,
199,
646,
781,
29063,
199,
646,
747,
199,
646,
2197,
199,
199,
318,
1059,
6743,
334,
2981,
12,
86,
17,
304,
199,
2203,
275,
715,
199,
671,
275,
822,
8,
86,
17,
9,
199,
1335,
29,
16,
199,
367,
1335,
315,
1425,
8,
16,
12,
88,
12,
17,
304,
272,
340,
8,
552,
8,
86,
17,
9,
12932,
552,
8,
2981,
2298,
489,
340,
2306,
59,
74,
1055,
18351,
342,
508,
373,
17,
59,
74,
61,
503,
2306,
59,
74,
19219,
86,
17,
59,
74,
2189,
881,
2203,
275,
2203,
436,
715,
489,
916,
2306,
59,
74,
61,
1137,
373,
17,
59,
74,
2189,
881,
2203,
275,
2203,
436,
756,
272,
587,
26,
489,
2203,
275,
2203,
436,
756,
421,
372,
2203,
421,
199,
2473,
275,
3066,
63,
1210,
480,
8880,
2812,
9107,
199,
199,
6710,
413,
26,
199,
870,
1867,
78,
5815,
30948,
26537,
2,
199,
870,
298,
17,
26,
17025,
60,
78,
18,
26,
17127,
14035,
60,
78,
19,
26,
6119,
1893,
28055,
60,
78,
20,
26,
6119,
1893,
3918,
60,
78,
21,
26,
714,
11961,
436,
14931,
60,
78,
22,
26,
9721,
17804,
2,
199,
870,
221,
298,
23,
26,
3005,
314,
18841,
60,
78,
24,
26,
29820,
60,
78,
25,
26,
4685,
3918,
60,
78,
709,
26,
9779,
11005,
2,
199,
13680,
275,
3066,
63,
1210,
480,
8254,
9496,
376,
3207,
9107,
199,
870,
298,
5815,
30948,
1116,
23262,
78,
2,
421,
340,
13680,
11800,
17,
582,
2742,
221,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
8468,
314,
14001,
9339,
4860,
1549,
9973,
5495,
9107,
881,
373,
275,
3945,
265,
4869,
17957,
2004,
17,
275,
3066,
63,
1210,
480,
2445,
282,
892,
1240,
31,
334,
57,
503,
653,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
1507,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
881,
284,
29,
16,
2742,
221,
340,
2004,
17,
508,
298,
57,
582,
272,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
4665,
1240,
10367,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
7846,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
8592,
18122,
3817,
14,
1600,
342,
221,
421,
916,
13680,
11800,
18,
582,
1362,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
8468,
314,
29083,
5697,
2812,
9107,
881,
373,
275,
3945,
265,
4869,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
4665,
1240,
31,
334,
57,
503,
653,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
8621,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
421,
17957,
340,
2004,
17,
508,
298,
57,
582,
1362,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
11365,
24251,
3412,
2916,
1149,
28364,
14742,
57,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
21979,
288,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
8592,
18122,
3817,
14,
1600,
342,
16421,
199,
916,
13680,
11800,
19,
582,
1779,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
985,
9107,
881,
373,
275,
3945,
265,
4869,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
8468,
8966,
334,
57,
15,
46,
304,
531,
2742,
221,
18122,
3817,
275,
1551,
480,
388,
493,
14,
2424,
2266,
82,
21425,
523,
267,
198,
221,
653,
53,
1698,
568,
654,
221,
275,
18122,
3817,
14,
9684,
342,
2742,
221,
340,
2004,
17,
508,
298,
57,
582,
1362,
507,
258,
1923,
17,
275,
3066,
63,
1210,
480,
8468,
314,
6786,
9107,
1467,
3063,
275,
2197,
14,
2083,
14,
2131,
342,
755,
1467,
18122,
3817,
14,
952,
480,
1280,
763,
9529,
78,
7709,
838,
265,
4869,
25789,
78,
2,
435,
1404,
17,
25789,
78,
7709,
495,
8,
2131,
18663,
4885,
5424,
11,
2473,
25789,
78,
1280,
15495,
531,
1362,
1467,
870,
298,
11365,
7408,
3036,
16271,
8280,
28364,
14742,
57,
2,
1467,
18122,
3817,
14,
1600,
342,
2742,
221,
916,
2004,
17,
508,
298,
46,
582,
523,
288,
870,
1867,
78,
3096,
1116,
7590,
78,
2,
6722,
367,
3945,
265,
4869,
315,
653,
53,
1698,
568,
654,
26,
10798,
340,
8,
875,
6743,
8,
838,
265,
4869,
12,
86,
9,
503,
334,
73,
30,
16,
2298,
507,
263,
870,
3945,
265,
4869,
355,
284,
275,
284,
11,
413,
355,
340,
334,
73,
389,
20,
304,
2079,
284,
29,
16,
2116,
1467,
587,
26,
355,
284,
275,
378,
4388,
881,
18122,
3817,
14,
1600,
342,
221,
421,
916,
13680,
11800,
20,
582,
1779,
17957,
3945,
265,
4869,
275,
3066,
63,
1210,
480,
1451,
370,
8730,
9107,
2742,
221,
2004,
17,
275,
3066,
63,
1210,
480,
4665,
3918,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dufferzafar/mitmproxy
|
mitmproxy/contrib/wbxml/ASWBXMLCodePage.py
|
47
|
1781
|
#!/usr/bin/env python
'''
@author: David Shaw, david.shaw.aw@gmail.com
Inspired by EAS Inspector for Fiddler
https://easinspectorforfiddler.codeplex.com
----- The MIT License (MIT) -----
Filename: ASWBXMLCodePage.py
Copyright (c) 2014, David P. Shaw
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.
'''
class ASWBXMLCodePage:
def __init__(self):
self.namespace = ""
self.xmlns = ""
self.tokenLookup = {}
self.tagLookup = {}
def addToken(self, token, tag):
self.tokenLookup[token] = tag
self.tagLookup[tag] = token
def getToken(self, tag):
if self.tagLookup.has_key(tag):
return self.tagLookup[tag]
return 0xFF
def getTag(self, token):
if self.tokenLookup.has_key(token):
return self.tokenLookup[token]
return None
def __repr__(self):
return str(self.tokenLookup)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
2344,
199,
32,
2502,
26,
20232,
428,
2411,
87,
12,
366,
17204,
14,
4835,
87,
14,
10084,
32,
6799,
14,
957,
199,
199,
13962,
1038,
581,
701,
662,
1179,
12062,
15152,
367,
481,
344,
68,
1435,
199,
2859,
921,
69,
305,
26047,
509,
329,
617,
1435,
14,
600,
22198,
14,
957,
199,
199,
9858,
710,
10697,
844,
334,
13965,
9,
9063,
221,
199,
8117,
26,
4319,
24819,
4317,
3034,
3276,
14,
647,
199,
7384,
334,
67,
9,
6927,
12,
20232,
510,
14,
428,
2411,
87,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
2344,
199,
533,
4319,
24819,
4317,
3034,
3276,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
3251,
275,
3087,
507,
198,
277,
14,
13991,
275,
3087,
507,
198,
277,
14,
1418,
7521,
275,
1052,
507,
198,
277,
14,
1450,
7521,
275,
1052,
8299,
198,
318,
1050,
3264,
8,
277,
12,
1526,
12,
1947,
304,
507,
198,
277,
14,
1418,
7521,
59,
1418,
61,
275,
1947,
507,
198,
277,
14,
1450,
7521,
59,
1450,
61,
275,
1526,
8299,
198,
318,
664,
3264,
8,
277,
12,
1947,
304,
507,
198,
692,
291,
14,
1450,
7521,
14,
1989,
63,
498,
8,
1450,
304,
686,
198,
1107,
291,
14,
1450,
7521,
59,
1450,
61,
507,
198,
1107,
378,
9039,
8299,
198,
318,
664,
1931,
8,
277,
12,
1526,
304,
507,
198,
692,
291,
14,
1418,
7521,
14,
1989,
63,
498,
8,
1418,
304,
686,
198,
1107,
291,
14,
1418,
7521,
59,
1418,
61,
507,
198,
1107,
488,
8299,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
620,
8,
277,
14,
1418,
7521,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2344,
199,
32,
2502,
26,
20232,
428,
2411,
87,
12,
366,
17204,
14,
4835,
87,
14,
10084,
32,
6799,
14,
957,
199,
199,
13962,
1038,
581,
701,
662,
1179,
12062,
15152,
367,
481,
344,
68,
1435,
199,
2859,
921,
69,
305,
26047,
509,
329,
617,
1435,
14,
600,
22198,
14,
957,
199,
199,
9858,
710,
10697,
844,
334,
13965,
9,
9063,
221,
199,
8117,
26,
4319,
24819,
4317,
3034,
3276,
14,
647,
199,
7384,
334,
67,
9,
6927,
12,
20232,
510,
14,
428,
2411,
87,
199,
199,
7980,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
1618,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
262,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
475,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
16847,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
70,
13399,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
199,
1918,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
199,
452,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
199,
18061,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
8947,
5177,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
38,
3061,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
5580,
4149,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
2673,
2477,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
1877,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
199,
18061,
4141,
14,
199,
2344,
199,
533,
4319,
24819,
4317,
3034,
3276,
26,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
3251,
275,
3087,
507,
198,
277,
14,
13991,
275,
3087,
507,
198,
277,
14,
1418,
7521,
275,
1052,
507,
198,
277,
14,
1450,
7521,
275,
1052,
8299,
198,
318,
1050,
3264,
8,
277,
12,
1526,
12,
1947,
304,
507,
198,
277,
14,
1418,
7521,
59,
1418,
61,
275,
1947,
507,
198,
277,
14,
1450,
7521,
59,
1450,
61,
275,
1526,
8299,
198,
318,
664,
3264,
8,
277,
12,
1947,
304,
507,
198,
692,
291,
14,
1450,
7521,
14,
1989,
63,
498,
8,
1450,
304,
686,
198,
1107,
291,
14,
1450,
7521,
59,
1450,
61,
507,
198,
1107,
378,
9039,
8299,
198,
318,
664,
1931,
8,
277,
12,
1526,
304,
507,
198,
692,
291,
14,
1418,
7521,
14,
1989,
63,
498,
8,
1418,
304,
686,
198,
1107,
291,
14,
1418,
7521,
59,
1418,
61,
507,
198,
1107,
488,
8299,
198,
318,
636,
2722,
721,
277,
304,
507,
198,
1107,
620,
8,
277,
14,
1418,
7521,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
meteorcloudy/tensorflow
|
tensorflow/python/training/tensorboard_logging.py
|
165
|
5328
|
# Copyright 2015 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.
# ==============================================================================
"""tensorboard_logging provides logging that is also written to the events file.
Any messages logged via this module will be logged both via the platform logging
mechanism and to the SummaryWriter set via `set_summary_writer`. This is useful
for logging messages that you might want to be visible from inside TensorBoard
or that should be permanently associated with the training session.
You can use this just like the logging module:
>>> tensorboard_logging.set_summary_writer(summary_writer)
>>> tensorboard_logging.info("my %s", "message")
>>> tensorboard_logging.log(tensorboard_logging.WARN, "something")
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
from tensorflow.core.util import event_pb2
from tensorflow.python.platform import tf_logging as logging
DEBUG = 'DEBUG'
INFO = 'INFO'
WARN = 'WARN'
ERROR = 'ERROR'
FATAL = 'FATAL'
# Messages with levels below this verbosity will not be logged.
_verbosity = WARN
# A value meaning 'not set yet' so we can use None to mean 'user actively told
# us they don't want a SummaryWriter'.
_sentinel_summary_writer = object()
# The SummaryWriter instance to use when logging, or None to not log, or
# _sentinel_summary_writer to indicate that the user hasn't called
# set_summary_writer yet.
_summary_writer = _sentinel_summary_writer
# Map from the tensorboard_logging logging enum values to the proto's enum
# values.
_LEVEL_PROTO_MAP = {
DEBUG: event_pb2.LogMessage.DEBUGGING,
INFO: event_pb2.LogMessage.INFO,
WARN: event_pb2.LogMessage.WARN,
ERROR: event_pb2.LogMessage.ERROR,
FATAL: event_pb2.LogMessage.FATAL,
}
# Map from the tensorboard_logging module levels to the logging module levels.
_PLATFORM_LOGGING_LEVEL_MAP = {
DEBUG: logging.DEBUG,
INFO: logging.INFO,
WARN: logging.WARN,
ERROR: logging.ERROR,
FATAL: logging.FATAL
}
def get_verbosity():
return _verbosity
def set_verbosity(verbosity):
_check_verbosity(verbosity)
global _verbosity
_verbosity = verbosity
def _check_verbosity(verbosity):
if verbosity not in _LEVEL_PROTO_MAP:
raise ValueError('Level %s is not a valid tensorboard_logging level' %
verbosity)
def set_summary_writer(summary_writer):
"""Sets the summary writer that events will be logged to.
Calling any logging methods inside this module without calling this method
will fail. If you don't want to log, call `set_summary_writer(None)`.
Args:
summary_writer: Either a SummaryWriter or None. None will cause messages not
to be logged to any SummaryWriter, but they will still be passed to the
platform logging module.
"""
global _summary_writer
_summary_writer = summary_writer
def _clear_summary_writer():
"""Makes all subsequent log invocations error.
This is only used for testing. If you want to disable TensorBoard logging,
call `set_summary_writer(None)` instead.
"""
global _summary_writer
_summary_writer = _sentinel_summary_writer
def log(level, message, *args):
"""Conditionally logs `message % args` at the level `level`.
Note that tensorboard_logging verbosity and logging verbosity are separate;
the message will always be passed through to the logging module regardless of
whether it passes the tensorboard_logging verbosity check.
Args:
level: The verbosity level to use. Must be one of
tensorboard_logging.{DEBUG, INFO, WARN, ERROR, FATAL}.
message: The message template to use.
*args: Arguments to interpolate to the message template, if any.
Raises:
ValueError: If `level` is not a valid logging level.
RuntimeError: If the `SummaryWriter` to use has not been set.
"""
if _summary_writer is _sentinel_summary_writer:
raise RuntimeError('Must call set_summary_writer before doing any '
'logging from tensorboard_logging')
_check_verbosity(level)
proto_level = _LEVEL_PROTO_MAP[level]
if proto_level >= _LEVEL_PROTO_MAP[_verbosity]:
log_message = event_pb2.LogMessage(level=proto_level,
message=message % args)
event = event_pb2.Event(wall_time=time.time(), log_message=log_message)
if _summary_writer:
_summary_writer.add_event(event)
logging.log(_PLATFORM_LOGGING_LEVEL_MAP[level], message, *args)
def debug(message, *args):
log(DEBUG, message, *args)
def info(message, *args):
log(INFO, message, *args)
def warn(message, *args):
log(WARN, message, *args)
def error(message, *args):
log(ERROR, message, *args)
def fatal(message, *args):
log(FATAL, message, *args)
|
apache-2.0
|
[
3,
1898,
6900,
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,
3128,
3576,
63,
4806,
6571,
2050,
626,
365,
2597,
5313,
370,
314,
4474,
570,
14,
199,
199,
9874,
3788,
10367,
4799,
642,
859,
911,
506,
10367,
3865,
4799,
314,
4298,
2050,
199,
278,
11993,
436,
370,
314,
22486,
6261,
663,
4799,
658,
409,
63,
4705,
63,
5491,
2313,
961,
365,
2997,
199,
509,
2050,
3788,
626,
1265,
5594,
2934,
370,
506,
8917,
687,
6272,
5878,
18995,
199,
269,
626,
1077,
506,
19860,
590,
4568,
543,
314,
6093,
2351,
14,
199,
199,
5556,
883,
675,
642,
2951,
2839,
314,
2050,
859,
26,
199,
199,
6071,
2345,
3576,
63,
4806,
14,
409,
63,
4705,
63,
5491,
8,
4705,
63,
5491,
9,
199,
6071,
2345,
3576,
63,
4806,
14,
815,
480,
1662,
450,
83,
401,
298,
1188,
531,
199,
6071,
2345,
3576,
63,
4806,
14,
793,
8,
3128,
3576,
63,
4806,
14,
17449,
12,
298,
10297,
531,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
900,
199,
199,
504,
3228,
14,
1018,
14,
1974,
492,
1566,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
199,
199,
5287,
275,
283,
5287,
7,
199,
4531,
275,
283,
4531,
7,
199,
17449,
275,
283,
17449,
7,
199,
3170,
275,
283,
3170,
7,
199,
29086,
275,
283,
29086,
7,
199,
199,
3,
27377,
543,
11106,
5084,
642,
8661,
911,
440,
506,
10367,
14,
199,
63,
9833,
275,
13253,
46,
199,
199,
3,
437,
574,
11150,
283,
1397,
663,
5966,
7,
880,
781,
883,
675,
488,
370,
4615,
283,
751,
6633,
5636,
370,
1447,
199,
3,
2739,
2985,
2793,
1133,
2934,
282,
22486,
6261,
1370,
199,
63,
13400,
63,
4705,
63,
5491,
275,
909,
342,
199,
199,
3,
710,
22486,
6261,
1256,
370,
675,
1380,
2050,
12,
503,
488,
370,
440,
943,
12,
503,
199,
3,
485,
13400,
63,
4705,
63,
5491,
370,
6623,
626,
314,
922,
18699,
1133,
2797,
199,
3,
663,
63,
4705,
63,
5491,
5966,
14,
199,
63,
4705,
63,
5491,
275,
485,
13400,
63,
4705,
63,
5491,
199,
199,
3,
9672,
687,
314,
2345,
3576,
63,
4806,
2050,
4952,
1338,
370,
314,
4104,
1159,
4952,
199,
3,
1338,
14,
199,
63,
11817,
63,
7459,
63,
5443,
275,
469,
272,
10990,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
1093,
2910,
22790,
12,
272,
24008,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
4531,
12,
272,
13253,
46,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
17449,
12,
272,
12539,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
3170,
12,
272,
481,
619,
748,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
29086,
12,
199,
93,
199,
199,
3,
9672,
687,
314,
2345,
3576,
63,
4806,
859,
11106,
370,
314,
2050,
859,
11106,
14,
199,
63,
17805,
63,
27896,
63,
11817,
63,
5443,
275,
469,
272,
10990,
26,
2050,
14,
5287,
12,
272,
24008,
26,
2050,
14,
4531,
12,
272,
13253,
46,
26,
2050,
14,
17449,
12,
272,
12539,
26,
2050,
14,
3170,
12,
272,
481,
619,
748,
26,
2050,
14,
29086,
199,
93,
421,
199,
318,
664,
63,
9833,
837,
523,
372,
485,
9833,
421,
199,
318,
663,
63,
9833,
8,
9833,
304,
523,
485,
1074,
63,
9833,
8,
9833,
9,
523,
2288,
485,
9833,
523,
485,
9833,
275,
8661,
421,
199,
318,
485,
1074,
63,
9833,
8,
9833,
304,
523,
340,
8661,
440,
315,
485,
11817,
63,
7459,
63,
5443,
26,
272,
746,
1722,
360,
4670,
450,
83,
365,
440,
282,
1686,
2345,
3576,
63,
4806,
2166,
7,
450,
2151,
8661,
9,
421,
199,
318,
663,
63,
4705,
63,
5491,
8,
4705,
63,
5491,
304,
523,
408,
9899,
314,
6212,
7060,
626,
4474,
911,
506,
10367,
370,
14,
819,
23892,
1263,
2050,
3102,
6272,
642,
859,
1928,
6358,
642,
1083,
523,
911,
2449,
14,
982,
1265,
2793,
1133,
2934,
370,
943,
12,
1240,
658,
409,
63,
4705,
63,
5491,
8,
403,
20414,
819,
3033,
26,
272,
6212,
63,
5491,
26,
13083,
282,
22486,
6261,
503,
488,
14,
488,
911,
7675,
3788,
440,
272,
370,
506,
10367,
370,
1263,
22486,
6261,
12,
1325,
2985,
911,
5139,
506,
3032,
370,
314,
272,
4298,
2050,
859,
14,
523,
408,
523,
2288,
485,
4705,
63,
5491,
523,
485,
4705,
63,
5491,
275,
6212,
63,
5491,
421,
199,
318,
485,
3584,
63,
4705,
63,
5491,
837,
523,
408,
27142,
1006,
13372,
943,
28202,
1125,
14,
819,
961,
365,
1454,
1202,
367,
5343,
14,
982,
1265,
2934,
370,
3507,
5878,
18995,
2050,
12,
523,
1240,
658,
409,
63,
4705,
63,
5491,
8,
403,
12544,
3140,
14,
523,
408,
523,
2288,
485,
4705,
63,
5491,
523,
485,
4705,
63,
5491,
275,
485,
13400,
63,
4705,
63,
5491,
421,
199,
318,
943,
8,
1896,
12,
1245,
12,
627,
589,
304,
523,
408,
9558,
1183,
9610,
658,
1188,
450,
1249,
64,
737,
314,
2166,
658,
1896,
2313,
819,
3390,
626,
2345,
3576,
63,
4806,
8661,
436,
2050,
8661,
787,
7396,
27,
523,
314,
1245,
911,
3544,
506,
3032,
4012,
370,
314,
2050,
859,
15270,
402,
523,
3775,
652,
14933,
314,
2345,
3576,
63,
4806,
8661,
1104,
14,
819,
3033,
26,
272,
2166,
26,
710,
8661,
2166,
370,
675,
14,
9498,
506,
1373,
402
] |
[
1898,
6900,
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,
3128,
3576,
63,
4806,
6571,
2050,
626,
365,
2597,
5313,
370,
314,
4474,
570,
14,
199,
199,
9874,
3788,
10367,
4799,
642,
859,
911,
506,
10367,
3865,
4799,
314,
4298,
2050,
199,
278,
11993,
436,
370,
314,
22486,
6261,
663,
4799,
658,
409,
63,
4705,
63,
5491,
2313,
961,
365,
2997,
199,
509,
2050,
3788,
626,
1265,
5594,
2934,
370,
506,
8917,
687,
6272,
5878,
18995,
199,
269,
626,
1077,
506,
19860,
590,
4568,
543,
314,
6093,
2351,
14,
199,
199,
5556,
883,
675,
642,
2951,
2839,
314,
2050,
859,
26,
199,
199,
6071,
2345,
3576,
63,
4806,
14,
409,
63,
4705,
63,
5491,
8,
4705,
63,
5491,
9,
199,
6071,
2345,
3576,
63,
4806,
14,
815,
480,
1662,
450,
83,
401,
298,
1188,
531,
199,
6071,
2345,
3576,
63,
4806,
14,
793,
8,
3128,
3576,
63,
4806,
14,
17449,
12,
298,
10297,
531,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
900,
199,
199,
504,
3228,
14,
1018,
14,
1974,
492,
1566,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
199,
199,
5287,
275,
283,
5287,
7,
199,
4531,
275,
283,
4531,
7,
199,
17449,
275,
283,
17449,
7,
199,
3170,
275,
283,
3170,
7,
199,
29086,
275,
283,
29086,
7,
199,
199,
3,
27377,
543,
11106,
5084,
642,
8661,
911,
440,
506,
10367,
14,
199,
63,
9833,
275,
13253,
46,
199,
199,
3,
437,
574,
11150,
283,
1397,
663,
5966,
7,
880,
781,
883,
675,
488,
370,
4615,
283,
751,
6633,
5636,
370,
1447,
199,
3,
2739,
2985,
2793,
1133,
2934,
282,
22486,
6261,
1370,
199,
63,
13400,
63,
4705,
63,
5491,
275,
909,
342,
199,
199,
3,
710,
22486,
6261,
1256,
370,
675,
1380,
2050,
12,
503,
488,
370,
440,
943,
12,
503,
199,
3,
485,
13400,
63,
4705,
63,
5491,
370,
6623,
626,
314,
922,
18699,
1133,
2797,
199,
3,
663,
63,
4705,
63,
5491,
5966,
14,
199,
63,
4705,
63,
5491,
275,
485,
13400,
63,
4705,
63,
5491,
199,
199,
3,
9672,
687,
314,
2345,
3576,
63,
4806,
2050,
4952,
1338,
370,
314,
4104,
1159,
4952,
199,
3,
1338,
14,
199,
63,
11817,
63,
7459,
63,
5443,
275,
469,
272,
10990,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
1093,
2910,
22790,
12,
272,
24008,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
4531,
12,
272,
13253,
46,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
17449,
12,
272,
12539,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
3170,
12,
272,
481,
619,
748,
26,
1566,
63,
3317,
18,
14,
2445,
2209,
14,
29086,
12,
199,
93,
199,
199,
3,
9672,
687,
314,
2345,
3576,
63,
4806,
859,
11106,
370,
314,
2050,
859,
11106,
14,
199,
63,
17805,
63,
27896,
63,
11817,
63,
5443,
275,
469,
272,
10990,
26,
2050,
14,
5287,
12,
272,
24008,
26,
2050,
14,
4531,
12,
272,
13253,
46,
26,
2050,
14,
17449,
12,
272,
12539,
26,
2050,
14,
3170,
12,
272,
481,
619,
748,
26,
2050,
14,
29086,
199,
93,
421,
199,
318,
664,
63,
9833,
837,
523,
372,
485,
9833,
421,
199,
318,
663,
63,
9833,
8,
9833,
304,
523,
485,
1074,
63,
9833,
8,
9833,
9,
523,
2288,
485,
9833,
523,
485,
9833,
275,
8661,
421,
199,
318,
485,
1074,
63,
9833,
8,
9833,
304,
523,
340,
8661,
440,
315,
485,
11817,
63,
7459,
63,
5443,
26,
272,
746,
1722,
360,
4670,
450,
83,
365,
440,
282,
1686,
2345,
3576,
63,
4806,
2166,
7,
450,
2151,
8661,
9,
421,
199,
318,
663,
63,
4705,
63,
5491,
8,
4705,
63,
5491,
304,
523,
408,
9899,
314,
6212,
7060,
626,
4474,
911,
506,
10367,
370,
14,
819,
23892,
1263,
2050,
3102,
6272,
642,
859,
1928,
6358,
642,
1083,
523,
911,
2449,
14,
982,
1265,
2793,
1133,
2934,
370,
943,
12,
1240,
658,
409,
63,
4705,
63,
5491,
8,
403,
20414,
819,
3033,
26,
272,
6212,
63,
5491,
26,
13083,
282,
22486,
6261,
503,
488,
14,
488,
911,
7675,
3788,
440,
272,
370,
506,
10367,
370,
1263,
22486,
6261,
12,
1325,
2985,
911,
5139,
506,
3032,
370,
314,
272,
4298,
2050,
859,
14,
523,
408,
523,
2288,
485,
4705,
63,
5491,
523,
485,
4705,
63,
5491,
275,
6212,
63,
5491,
421,
199,
318,
485,
3584,
63,
4705,
63,
5491,
837,
523,
408,
27142,
1006,
13372,
943,
28202,
1125,
14,
819,
961,
365,
1454,
1202,
367,
5343,
14,
982,
1265,
2934,
370,
3507,
5878,
18995,
2050,
12,
523,
1240,
658,
409,
63,
4705,
63,
5491,
8,
403,
12544,
3140,
14,
523,
408,
523,
2288,
485,
4705,
63,
5491,
523,
485,
4705,
63,
5491,
275,
485,
13400,
63,
4705,
63,
5491,
421,
199,
318,
943,
8,
1896,
12,
1245,
12,
627,
589,
304,
523,
408,
9558,
1183,
9610,
658,
1188,
450,
1249,
64,
737,
314,
2166,
658,
1896,
2313,
819,
3390,
626,
2345,
3576,
63,
4806,
8661,
436,
2050,
8661,
787,
7396,
27,
523,
314,
1245,
911,
3544,
506,
3032,
4012,
370,
314,
2050,
859,
15270,
402,
523,
3775,
652,
14933,
314,
2345,
3576,
63,
4806,
8661,
1104,
14,
819,
3033,
26,
272,
2166,
26,
710,
8661,
2166,
370,
675,
14,
9498,
506,
1373,
402,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
openstack/octavia
|
octavia/amphorae/backends/utils/haproxy_query.py
|
1
|
4759
|
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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 csv
import socket
from octavia.common import constants as consts
from octavia.common import utils as octavia_utils
from octavia.i18n import _
class HAProxyQuery(object):
"""Class used for querying the HAProxy statistics socket.
The CSV output is defined in the HAProxy documentation:
http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#9
"""
def __init__(self, stats_socket):
"""stats_socket
Path to the HAProxy statistics socket file.
"""
self.socket = stats_socket
def _query(self, query):
"""Send the given query to the haproxy statistics socket.
:returns: the output of a successful query as a string with trailing
newlines removed, or raise an Exception if the query fails.
"""
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.connect(self.socket)
except socket.error as e:
raise Exception(
_("HAProxy '{0}' query failed.").format(query)) from e
try:
sock.send(octavia_utils.b(query + '\n'))
data = u''
while True:
x = sock.recv(1024)
if not x:
break
data += x.decode('ascii') if (
isinstance(x, bytes)) else x
return data.rstrip()
finally:
sock.close()
def show_info(self):
"""Get and parse output from 'show info' command."""
results = self._query('show info')
dict_results = dict()
for r in results.split('\n'):
vals = r.split(":", 1)
dict_results[vals[0].strip()] = vals[1].strip()
return dict_results
def show_stat(self, proxy_iid=-1, object_type=-1, server_id=-1):
"""Get and parse output from 'show stat' command.
:param proxy_iid: Proxy ID (column 27 in CSV output). -1 for all.
:param object_type: Select the type of dumpable object. Values can
be ORed.
-1 - everything
1 - frontends
2 - backends
4 - servers
:param server_id: Server ID (column 28 in CSV output?), or -1
for everything.
:returns: stats (split into an array by newline)
"""
results = self._query(
'show stat {proxy_iid} {object_type} {server_id}'.format(
proxy_iid=proxy_iid,
object_type=object_type,
server_id=server_id))
list_results = results[2:].split('\n')
csv_reader = csv.DictReader(list_results)
return list(csv_reader)
def get_pool_status(self):
"""Get status for each server and the pool as a whole.
:returns: pool data structure
{<pool-name>: {
'uuid': <uuid>,
'status': 'UP'|'DOWN',
'members': [<name>: 'UP'|'DOWN'|'DRAIN'|'no check'] }}
"""
results = self.show_stat(object_type=6) # servers + pool
final_results = {}
for line in results:
# pxname: pool, svname: server_name, status: status
# Due to a bug in some versions of HAProxy, DRAIN mode isn't
# calculated correctly, but we can spoof the correct value here.
if line['status'] == consts.UP and line['weight'] == 0:
line['status'] = consts.DRAIN
if line['pxname'] not in final_results:
final_results[line['pxname']] = dict(members={})
if line['svname'] == 'BACKEND':
pool_id, listener_id = line['pxname'].split(':')
final_results[line['pxname']]['pool_uuid'] = pool_id
final_results[line['pxname']]['listener_uuid'] = listener_id
final_results[line['pxname']]['status'] = line['status']
else:
final_results[line['pxname']]['members'][line['svname']] = (
line['status'])
return final_results
|
apache-2.0
|
[
3,
1898,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
7392,
199,
646,
2838,
199,
199,
504,
17162,
7194,
65,
14,
2330,
492,
5262,
465,
950,
83,
199,
504,
17162,
7194,
65,
14,
2330,
492,
3778,
465,
17162,
7194,
65,
63,
1208,
199,
504,
17162,
7194,
65,
14,
73,
1085,
78,
492,
485,
421,
199,
533,
16100,
4936,
3227,
8,
785,
304,
272,
408,
2543,
1202,
367,
27405,
314,
16100,
4936,
11076,
2838,
14,
339,
710,
14689,
1072,
365,
3247,
315,
314,
16100,
4936,
3794,
26,
339,
1455,
921,
2894,
265,
266,
14,
5031,
14,
2308,
15,
72,
30204,
1702,
13,
68,
5598,
15,
4758,
13,
17,
14,
20,
14,
1360,
3,
25,
272,
408,
339,
347,
636,
826,
721,
277,
12,
5020,
63,
3450,
304,
267,
408,
3200,
63,
3450,
953,
6912,
370,
314,
16100,
4936,
11076,
2838,
570,
14,
267,
408,
398,
291,
14,
3450,
275,
5020,
63,
3450,
339,
347,
485,
1131,
8,
277,
12,
1827,
304,
267,
408,
6795,
314,
1627,
1827,
370,
314,
394,
30204,
1702,
11076,
2838,
14,
398,
520,
5808,
26,
314,
1072,
402,
282,
9512,
1827,
465,
282,
1059,
543,
8520,
2116,
14930,
4829,
12,
503,
746,
376,
2186,
340,
314,
1827,
6918,
14,
267,
408,
398,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
19584,
12,
2838,
14,
9469,
63,
9484,
9,
398,
862,
26,
288,
6771,
14,
2242,
8,
277,
14,
3450,
9,
267,
871,
2838,
14,
705,
465,
325,
26,
288,
746,
2186,
8,
355,
3824,
6294,
4936,
5041,
16,
6834,
1827,
3405,
2685,
14,
908,
8,
1131,
430,
687,
325,
398,
862,
26,
288,
6771,
14,
2254,
8,
15560,
7194,
65,
63,
1208,
14,
66,
8,
1131,
435,
1557,
78,
1333,
288,
666,
275,
399,
891,
288,
1830,
715,
26,
355,
671,
275,
6771,
14,
7637,
8,
7727,
9,
355,
340,
440,
671,
26,
490,
2059,
355,
666,
847,
671,
14,
2708,
360,
4371,
358,
340,
334,
490,
1228,
8,
88,
12,
2783,
430,
587,
671,
288,
372,
666,
14,
6735,
342,
267,
3753,
26,
288,
6771,
14,
1600,
342,
339,
347,
2498,
63,
815,
8,
277,
304,
267,
408,
1002,
436,
2198,
1072,
687,
283,
2384,
2256,
7,
1414,
1041,
267,
2058,
275,
291,
423,
1131,
360,
2384,
2256,
358,
398,
1211,
63,
2604,
275,
1211,
342,
267,
367,
519,
315,
2058,
14,
1294,
2258,
78,
735,
288,
5322,
275,
519,
14,
1294,
480,
6783,
413,
9,
288,
1211,
63,
2604,
59,
3643,
59,
16,
1055,
1913,
5106,
275,
5322,
59,
17,
1055,
1913,
342,
267,
372,
1211,
63,
2604,
339,
347,
2498,
63,
3736,
8,
277,
12,
4566,
63,
73,
344,
4022,
17,
12,
909,
63,
466,
4022,
17,
12,
1654,
63,
344,
4022,
17,
304,
267,
408,
1002,
436,
2198,
1072,
687,
283,
2384,
5672,
7,
1414,
14,
398,
520,
635,
4566,
63,
73,
344,
26,
12373,
2870,
334,
2301,
8087,
315,
14689,
1072,
680,
446,
17,
367,
1006,
14,
267,
520,
635,
909,
63,
466,
26,
9496,
314,
730,
402,
5461,
461,
909,
14,
13468,
883,
1169,
506,
1549,
379,
14,
1169,
446,
17,
446,
8137,
1169,
413,
446,
289,
2641,
724,
795,
1169,
499,
446,
14745,
1169,
841,
446,
8037,
267,
520,
635,
1654,
63,
344,
26,
7146,
2870,
334,
2301,
7294,
315,
14689,
1072,
31,
395,
503,
446,
17,
2079,
367,
8137,
14,
267,
520,
5808,
26,
5020,
334,
1294,
1901,
376,
1625,
701,
8057,
9,
398,
408,
398,
2058,
275,
291,
423,
1131,
8,
288,
283,
2384,
5672,
469,
3280,
63,
73,
344,
93,
469,
785,
63,
466,
93,
469,
1000,
63,
344,
5285,
908,
8,
355,
4566,
63,
73,
344,
29,
3280,
63,
73,
344,
12,
355,
909,
63,
466,
29,
785,
63,
466,
12,
355,
1654,
63,
344,
29,
1000,
63,
344,
430,
267,
769,
63,
2604,
275,
2058,
59,
18,
11455,
1294,
2258,
78,
358,
267,
7392,
63,
5503,
275,
7392,
14,
2141,
5929,
8,
513,
63,
2604,
9,
267,
372,
769,
8,
4737,
63,
5503,
9,
339,
347,
664,
63,
2293,
63,
1205,
8,
277,
304,
267,
408,
1002,
2004,
367,
1924,
1654,
436,
314,
4203,
465,
282,
8852,
14,
398,
520,
5808,
26,
4203,
666,
5523,
2116,
469,
28,
2293,
13,
354,
20020,
469,
2116,
283,
2580,
356,
665,
2580,
6244,
2116,
283,
1205,
356,
283,
2160,
26972,
8819,
297,
2116,
283,
6334,
356,
24936,
354,
20020,
283,
2160,
26972,
8819,
26972,
36,
21715,
26972,
889,
1104,
418,
3586,
267,
408,
398,
2058,
275,
291,
14,
2384,
63,
3736,
8,
785,
63,
466,
29,
22,
9,
221,
327,
8037,
435,
4203,
398,
4242,
63,
2604,
275,
1052,
267,
367,
1004,
315,
2058,
26,
288,
327,
21162,
354,
26,
4203,
12,
19291,
354,
26,
1654,
63,
354,
12,
2004,
26,
2004,
953,
327,
25855,
370,
282,
6519,
315,
2005,
5459,
402,
16100,
4936,
12,
577,
21715,
818,
5712,
1133,
288,
327,
12950,
6657,
12,
1325,
781,
883,
25664,
1618,
314,
3211,
574,
2348,
14,
288,
340,
1004,
459,
1205,
418,
508,
950,
83,
14,
2160,
436,
1004,
459,
3463,
418,
508,
378,
26,
355,
1004,
459,
1205,
418,
275,
950,
83,
14,
36,
21715,
953,
340,
1004,
459,
5326,
354,
418,
440,
315,
4242,
63,
2604,
26,
355,
4242,
63,
2604,
59,
604,
459,
5326,
354,
6538,
275,
1211,
8,
6334,
21146,
953,
340,
1004,
459,
2772,
354,
418,
508,
283,
18145,
356
] |
[
1898,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
7392,
199,
646,
2838,
199,
199,
504,
17162,
7194,
65,
14,
2330,
492,
5262,
465,
950,
83,
199,
504,
17162,
7194,
65,
14,
2330,
492,
3778,
465,
17162,
7194,
65,
63,
1208,
199,
504,
17162,
7194,
65,
14,
73,
1085,
78,
492,
485,
421,
199,
533,
16100,
4936,
3227,
8,
785,
304,
272,
408,
2543,
1202,
367,
27405,
314,
16100,
4936,
11076,
2838,
14,
339,
710,
14689,
1072,
365,
3247,
315,
314,
16100,
4936,
3794,
26,
339,
1455,
921,
2894,
265,
266,
14,
5031,
14,
2308,
15,
72,
30204,
1702,
13,
68,
5598,
15,
4758,
13,
17,
14,
20,
14,
1360,
3,
25,
272,
408,
339,
347,
636,
826,
721,
277,
12,
5020,
63,
3450,
304,
267,
408,
3200,
63,
3450,
953,
6912,
370,
314,
16100,
4936,
11076,
2838,
570,
14,
267,
408,
398,
291,
14,
3450,
275,
5020,
63,
3450,
339,
347,
485,
1131,
8,
277,
12,
1827,
304,
267,
408,
6795,
314,
1627,
1827,
370,
314,
394,
30204,
1702,
11076,
2838,
14,
398,
520,
5808,
26,
314,
1072,
402,
282,
9512,
1827,
465,
282,
1059,
543,
8520,
2116,
14930,
4829,
12,
503,
746,
376,
2186,
340,
314,
1827,
6918,
14,
267,
408,
398,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
19584,
12,
2838,
14,
9469,
63,
9484,
9,
398,
862,
26,
288,
6771,
14,
2242,
8,
277,
14,
3450,
9,
267,
871,
2838,
14,
705,
465,
325,
26,
288,
746,
2186,
8,
355,
3824,
6294,
4936,
5041,
16,
6834,
1827,
3405,
2685,
14,
908,
8,
1131,
430,
687,
325,
398,
862,
26,
288,
6771,
14,
2254,
8,
15560,
7194,
65,
63,
1208,
14,
66,
8,
1131,
435,
1557,
78,
1333,
288,
666,
275,
399,
891,
288,
1830,
715,
26,
355,
671,
275,
6771,
14,
7637,
8,
7727,
9,
355,
340,
440,
671,
26,
490,
2059,
355,
666,
847,
671,
14,
2708,
360,
4371,
358,
340,
334,
490,
1228,
8,
88,
12,
2783,
430,
587,
671,
288,
372,
666,
14,
6735,
342,
267,
3753,
26,
288,
6771,
14,
1600,
342,
339,
347,
2498,
63,
815,
8,
277,
304,
267,
408,
1002,
436,
2198,
1072,
687,
283,
2384,
2256,
7,
1414,
1041,
267,
2058,
275,
291,
423,
1131,
360,
2384,
2256,
358,
398,
1211,
63,
2604,
275,
1211,
342,
267,
367,
519,
315,
2058,
14,
1294,
2258,
78,
735,
288,
5322,
275,
519,
14,
1294,
480,
6783,
413,
9,
288,
1211,
63,
2604,
59,
3643,
59,
16,
1055,
1913,
5106,
275,
5322,
59,
17,
1055,
1913,
342,
267,
372,
1211,
63,
2604,
339,
347,
2498,
63,
3736,
8,
277,
12,
4566,
63,
73,
344,
4022,
17,
12,
909,
63,
466,
4022,
17,
12,
1654,
63,
344,
4022,
17,
304,
267,
408,
1002,
436,
2198,
1072,
687,
283,
2384,
5672,
7,
1414,
14,
398,
520,
635,
4566,
63,
73,
344,
26,
12373,
2870,
334,
2301,
8087,
315,
14689,
1072,
680,
446,
17,
367,
1006,
14,
267,
520,
635,
909,
63,
466,
26,
9496,
314,
730,
402,
5461,
461,
909,
14,
13468,
883,
1169,
506,
1549,
379,
14,
1169,
446,
17,
446,
8137,
1169,
413,
446,
289,
2641,
724,
795,
1169,
499,
446,
14745,
1169,
841,
446,
8037,
267,
520,
635,
1654,
63,
344,
26,
7146,
2870,
334,
2301,
7294,
315,
14689,
1072,
31,
395,
503,
446,
17,
2079,
367,
8137,
14,
267,
520,
5808,
26,
5020,
334,
1294,
1901,
376,
1625,
701,
8057,
9,
398,
408,
398,
2058,
275,
291,
423,
1131,
8,
288,
283,
2384,
5672,
469,
3280,
63,
73,
344,
93,
469,
785,
63,
466,
93,
469,
1000,
63,
344,
5285,
908,
8,
355,
4566,
63,
73,
344,
29,
3280,
63,
73,
344,
12,
355,
909,
63,
466,
29,
785,
63,
466,
12,
355,
1654,
63,
344,
29,
1000,
63,
344,
430,
267,
769,
63,
2604,
275,
2058,
59,
18,
11455,
1294,
2258,
78,
358,
267,
7392,
63,
5503,
275,
7392,
14,
2141,
5929,
8,
513,
63,
2604,
9,
267,
372,
769,
8,
4737,
63,
5503,
9,
339,
347,
664,
63,
2293,
63,
1205,
8,
277,
304,
267,
408,
1002,
2004,
367,
1924,
1654,
436,
314,
4203,
465,
282,
8852,
14,
398,
520,
5808,
26,
4203,
666,
5523,
2116,
469,
28,
2293,
13,
354,
20020,
469,
2116,
283,
2580,
356,
665,
2580,
6244,
2116,
283,
1205,
356,
283,
2160,
26972,
8819,
297,
2116,
283,
6334,
356,
24936,
354,
20020,
283,
2160,
26972,
8819,
26972,
36,
21715,
26972,
889,
1104,
418,
3586,
267,
408,
398,
2058,
275,
291,
14,
2384,
63,
3736,
8,
785,
63,
466,
29,
22,
9,
221,
327,
8037,
435,
4203,
398,
4242,
63,
2604,
275,
1052,
267,
367,
1004,
315,
2058,
26,
288,
327,
21162,
354,
26,
4203,
12,
19291,
354,
26,
1654,
63,
354,
12,
2004,
26,
2004,
953,
327,
25855,
370,
282,
6519,
315,
2005,
5459,
402,
16100,
4936,
12,
577,
21715,
818,
5712,
1133,
288,
327,
12950,
6657,
12,
1325,
781,
883,
25664,
1618,
314,
3211,
574,
2348,
14,
288,
340,
1004,
459,
1205,
418,
508,
950,
83,
14,
2160,
436,
1004,
459,
3463,
418,
508,
378,
26,
355,
1004,
459,
1205,
418,
275,
950,
83,
14,
36,
21715,
953,
340,
1004,
459,
5326,
354,
418,
440,
315,
4242,
63,
2604,
26,
355,
4242,
63,
2604,
59,
604,
459,
5326,
354,
6538,
275,
1211,
8,
6334,
21146,
953,
340,
1004,
459,
2772,
354,
418,
508,
283,
18145,
356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tastynoodle/django
|
django/views/csrf.py
|
235
|
3802
|
from django.http import HttpResponseForbidden
from django.template import Context, Template
from django.conf import settings
# We include the template inline since we need to be able to reliably display
# this error message, especially for the sake of developers, and there isn't any
# other way of making it available independent of what is in the settings file.
CSRF_FAILURE_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="robots" content="NONE,NOARCHIVE">
<title>403 Forbidden</title>
<style type="text/css">
html * { padding:0; margin:0; }
body * { padding:10px 20px; }
body * * { padding:0; }
body { font:small sans-serif; background:#eee; }
body>div { border-bottom:1px solid #ddd; }
h1 { font-weight:normal; margin-bottom:.4em; }
h1 span { font-size:60%; color:#666; font-weight:normal; }
#info { background:#f6f6f6; }
#info ul { margin: 0.5em 4em; }
#info p, #summary p { padding-top:10px; }
#summary { background: #ffc; }
#explanation { background:#eee; border-bottom: 0px none; }
</style>
</head>
<body>
<div id="summary">
<h1>Forbidden <span>(403)</span></h1>
<p>CSRF verification failed. Request aborted.</p>
{% if no_referer %}
<p>You are seeing this message because this HTTPS site requires a 'Referer
header' to be sent by your Web browser, but none was sent. This header is
required for security reasons, to ensure that your browser is not being
hijacked by third parties.</p>
<p>If you have configured your browser to disable 'Referer' headers, please
re-enable them, at least for this site, or for HTTPS connections, or for
'same-origin' requests.</p>
{% endif %}
</div>
{% if DEBUG %}
<div id="info">
<h2>Help</h2>
{% if reason %}
<p>Reason given for failure:</p>
<pre>
{{ reason }}
</pre>
{% endif %}
<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
<a
href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'>Django's
CSRF mechanism</a> has not been used correctly. For POST forms, you need to
ensure:</p>
<ul>
<li>Your browser is accepting cookies.</li>
<li>The view function uses <a
href='http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext'><code>RequestContext</code></a>
for the template, instead of <code>Context</code>.</li>
<li>In the template, there is a <code>{% templatetag openblock %} csrf_token
{% templatetag closeblock %}</code> template tag inside each POST form that
targets an internal URL.</li>
<li>If you are not using <code>CsrfViewMiddleware</code>, then you must use
<code>csrf_protect</code> on any views that use the <code>csrf_token</code>
template tag, as well as those that accept the POST data.</li>
</ul>
<p>You're seeing the help section of this page because you have <code>DEBUG =
True</code> in your Django settings file. Change that to <code>False</code>,
and only the initial error message will be displayed. </p>
<p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p>
</div>
{% else %}
<div id="explanation">
<p><small>More information is available with DEBUG=True.</small></p>
</div>
{% endif %}
</body>
</html>
"""
def csrf_failure(request, reason=""):
"""
Default view used when request fails CSRF protection
"""
from django.middleware.csrf import REASON_NO_REFERER
t = Template(CSRF_FAILURE_TEMPLATE)
c = Context({'DEBUG': settings.DEBUG,
'reason': reason,
'no_referer': reason == REASON_NO_REFERER
})
return HttpResponseForbidden(t.render(c), content_type='text/html')
|
bsd-3-clause
|
[
504,
1639,
14,
1014,
492,
6183,
17454,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
3,
2136,
2387,
314,
1978,
8308,
3967,
781,
1929,
370,
506,
7688,
370,
16492,
6665,
2929,
199,
3,
642,
1125,
1245,
12,
24002,
367,
314,
308,
1728,
402,
19782,
12,
436,
2337,
5712,
1133,
1263,
199,
3,
1163,
4340,
402,
10663,
652,
2808,
12717,
402,
4052,
365,
315,
314,
2202,
570,
14,
199,
199,
26405,
63,
13989,
63,
7433,
275,
408,
199,
11230,
16556,
3517,
30,
199,
28,
1360,
6339,
628,
287,
1743,
199,
28,
2993,
30,
523,
665,
2024,
1455,
13,
20146,
628,
1317,
13,
466,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
28889,
2,
1564,
628,
9185,
12,
2826,
28800,
1743,
523,
665,
1213,
30,
13353,
2104,
10912,
1108,
1213,
30,
523,
665,
2487,
730,
628,
505,
15,
3919,
1743,
272,
3517,
627,
469,
6273,
26,
16,
27,
11042,
26,
16,
27,
789,
272,
2396,
627,
469,
6273,
26,
709,
5326,
3388,
5326,
27,
789,
272,
2396,
627,
627,
469,
6273,
26,
16,
27,
789,
272,
2396,
469,
5023,
26,
7241,
308,
796,
13,
24977,
27,
8020,
15596,
18777,
27,
789,
272,
2396,
30,
3015,
469,
9162,
13,
8305,
26,
17,
5326,
18609,
327,
15389,
27,
789,
272,
394,
17,
469,
5023,
13,
3463,
26,
3302,
27,
11042,
13,
8305,
14010,
20,
5633,
27,
789,
272,
394,
17,
13598,
469,
5023,
13,
890,
26,
2259,
5,
27,
3164,
15596,
11829,
27,
5023,
13,
3463,
26,
3302,
27,
789,
272,
327,
815,
469,
8020,
15596,
70,
22,
70,
22,
70,
22,
27,
789,
272,
327,
815,
12581,
469,
11042,
26,
378,
14,
21,
5633,
841,
5633,
27,
789,
272,
327,
815,
299,
12,
327,
4705,
299,
469,
6273,
13,
2119,
26,
709,
5326,
27,
789,
272,
327,
4705,
469,
8020,
26,
327,
26299,
27,
789,
272,
327,
15228,
469,
8020,
15596,
18777,
27,
9162,
13,
8305,
26,
378,
5326,
7179,
27,
789,
523,
3068,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
3015,
1305,
628,
4705,
1743,
523,
665,
72,
17,
30,
17454,
665,
3751,
13661,
13353,
15939,
3751,
2957,
72,
17,
30,
523,
665,
80,
30,
26405,
14786,
3405,
14,
4784,
26815,
9758,
80,
30,
199,
3996,
340,
949,
63,
20996,
3674,
523,
665,
80,
30,
5556,
787,
1937,
316,
642,
1245,
2952,
642,
14147,
4770,
5074,
282,
283,
28900,
2043,
1406,
7,
370,
506,
4847,
701,
2195,
6001,
7042,
12,
1325,
7179,
1990,
4847,
14,
961,
1406,
365,
2043,
1415,
367,
6391,
14872,
12,
370,
4868,
626,
2195,
7042,
365,
440,
3769,
2043,
394,
7879,
564,
379,
701,
10919,
623,
1417,
9758,
80,
30,
819,
665,
80,
30,
3917,
1265,
1172,
7526,
2195,
7042,
370,
3507,
283,
28900,
7,
2323,
12,
8749,
2043,
295,
13,
4296,
3062,
12,
737,
5210,
367,
642,
4770,
12,
503,
367,
14147,
6947,
12,
503,
367,
2043,
283,
7191,
13,
6493,
7,
4145,
9758,
80,
30,
199,
3996,
14454,
3674,
199,
1108,
3015,
30,
199,
3996,
340,
10990,
3674,
199,
28,
3015,
1305,
628,
815,
1743,
523,
665,
72,
18,
30,
8673,
1108,
72,
18,
30,
272,
7749,
340,
4499,
3674,
272,
665,
80,
30,
16148,
1627,
367,
5988,
9919,
80,
30,
272,
665,
657,
30,
272,
8448,
4499,
3586,
272,
3068,
657,
30,
272,
7749,
14454,
3674,
819,
665,
80,
30,
607,
8605,
12,
642,
883,
4781,
1380,
2337,
365,
282,
3805,
85,
1132,
28965,
11666,
4784,
2104,
836,
89,
12,
503,
1380,
523,
665,
65,
523,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
2828,
15,
10088,
12645,
1121,
13,
2828,
13,
10088,
8423,
9323,
1159,
523,
22468,
14729,
1108,
65,
30,
965,
440,
2757,
1202,
6657,
14,
221,
2104,
8761,
4513,
12,
1265,
1929,
370,
523,
4868,
9919,
80,
30,
819,
665,
348,
30,
272,
665,
317,
30,
14398,
7042,
365,
32163,
10049,
9758,
317,
30,
339,
665,
317,
30,
1918,
2455,
805,
4440,
665,
65,
272,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
27904,
13,
1100,
13,
1069,
1100,
7,
2535,
600,
30,
17679,
1108,
600,
2957,
65,
30,
272,
367,
314,
1978,
12,
3140,
402,
665,
600,
30,
2998,
1108,
600,
30,
9758,
317,
30,
339,
665,
317,
30,
607,
314,
1978,
12,
2337,
365,
282,
665,
600,
30,
3996,
1978,
1450,
1551,
1457,
3674,
19213,
63,
1418,
272,
7749,
1978,
1450,
4002,
1457,
3674,
1108,
600,
30,
1978,
1947,
6272,
1924,
8761,
1824,
626,
272,
4545,
376,
5007,
2851,
9758,
317,
30,
339,
665,
317,
30,
3917,
1265,
787,
440,
1808,
665,
600,
30,
13912,
25322,
1108,
600,
6244,
2066,
1265,
1471,
675,
272,
665,
600,
30,
10088,
63,
18292,
1108,
600,
30,
641,
1263,
6858,
626,
675,
314,
665,
600,
30,
10088,
63,
1418,
1108,
600,
30,
272,
1978,
1947,
12,
465,
5521,
465,
5204,
626,
4729,
314,
8761,
666,
9758,
317,
30,
819,
3068,
348,
30,
819,
665,
80,
30,
5556,
3984,
1937,
316,
314,
1720,
3420,
402,
642,
2034,
2952,
1265,
1172,
665,
600,
30,
5287,
275,
523,
715,
1108,
600,
30,
315,
2195,
5634,
2202,
570,
14,
7743,
626,
370,
665,
600,
30,
797,
1108,
600,
6244,
523,
436,
1454,
314,
2536,
1125,
1245,
911,
506,
9080,
14,
221,
3068,
80,
30,
819,
665,
80,
30,
5556,
883,
17551,
642,
2034,
1808,
314,
22468,
63,
13989,
63,
12058,
4260,
9758,
80,
30,
199,
1108,
3015,
30,
199,
3996,
587,
3674,
199,
28,
3015,
1305,
628,
15228,
1743,
523,
665,
80,
2535,
7241,
30,
11053,
2556,
365,
2808,
543,
10990,
29,
549,
9758,
7241,
2957,
80,
30,
199,
1108,
3015,
30,
199,
3996,
14454,
3674,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199,
199,
318,
19213,
63,
5328,
8,
1069,
12,
4499,
17364,
272,
408,
272,
3758,
2455,
1202,
1380,
1056,
6918,
22468,
23977,
272,
408,
272,
687,
1639,
14,
5754,
14,
10088,
492,
5363,
28883,
63,
2826,
63,
19494,
540,
272,
307,
275,
5458,
8,
26405,
63,
13989,
63,
7433,
9,
272
] |
[
1639,
14,
1014,
492,
6183,
17454,
199,
504,
1639,
14,
1160,
492,
9470,
12,
5458,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
3,
2136,
2387,
314,
1978,
8308,
3967,
781,
1929,
370,
506,
7688,
370,
16492,
6665,
2929,
199,
3,
642,
1125,
1245,
12,
24002,
367,
314,
308,
1728,
402,
19782,
12,
436,
2337,
5712,
1133,
1263,
199,
3,
1163,
4340,
402,
10663,
652,
2808,
12717,
402,
4052,
365,
315,
314,
2202,
570,
14,
199,
199,
26405,
63,
13989,
63,
7433,
275,
408,
199,
11230,
16556,
3517,
30,
199,
28,
1360,
6339,
628,
287,
1743,
199,
28,
2993,
30,
523,
665,
2024,
1455,
13,
20146,
628,
1317,
13,
466,
2,
1564,
628,
505,
15,
1360,
27,
5960,
29,
1624,
13,
24,
1743,
523,
665,
2024,
536,
628,
28889,
2,
1564,
628,
9185,
12,
2826,
28800,
1743,
523,
665,
1213,
30,
13353,
2104,
10912,
1108,
1213,
30,
523,
665,
2487,
730,
628,
505,
15,
3919,
1743,
272,
3517,
627,
469,
6273,
26,
16,
27,
11042,
26,
16,
27,
789,
272,
2396,
627,
469,
6273,
26,
709,
5326,
3388,
5326,
27,
789,
272,
2396,
627,
627,
469,
6273,
26,
16,
27,
789,
272,
2396,
469,
5023,
26,
7241,
308,
796,
13,
24977,
27,
8020,
15596,
18777,
27,
789,
272,
2396,
30,
3015,
469,
9162,
13,
8305,
26,
17,
5326,
18609,
327,
15389,
27,
789,
272,
394,
17,
469,
5023,
13,
3463,
26,
3302,
27,
11042,
13,
8305,
14010,
20,
5633,
27,
789,
272,
394,
17,
13598,
469,
5023,
13,
890,
26,
2259,
5,
27,
3164,
15596,
11829,
27,
5023,
13,
3463,
26,
3302,
27,
789,
272,
327,
815,
469,
8020,
15596,
70,
22,
70,
22,
70,
22,
27,
789,
272,
327,
815,
12581,
469,
11042,
26,
378,
14,
21,
5633,
841,
5633,
27,
789,
272,
327,
815,
299,
12,
327,
4705,
299,
469,
6273,
13,
2119,
26,
709,
5326,
27,
789,
272,
327,
4705,
469,
8020,
26,
327,
26299,
27,
789,
272,
327,
15228,
469,
8020,
15596,
18777,
27,
9162,
13,
8305,
26,
378,
5326,
7179,
27,
789,
523,
3068,
2487,
30,
199,
1108,
2993,
30,
199,
28,
2030,
30,
199,
28,
3015,
1305,
628,
4705,
1743,
523,
665,
72,
17,
30,
17454,
665,
3751,
13661,
13353,
15939,
3751,
2957,
72,
17,
30,
523,
665,
80,
30,
26405,
14786,
3405,
14,
4784,
26815,
9758,
80,
30,
199,
3996,
340,
949,
63,
20996,
3674,
523,
665,
80,
30,
5556,
787,
1937,
316,
642,
1245,
2952,
642,
14147,
4770,
5074,
282,
283,
28900,
2043,
1406,
7,
370,
506,
4847,
701,
2195,
6001,
7042,
12,
1325,
7179,
1990,
4847,
14,
961,
1406,
365,
2043,
1415,
367,
6391,
14872,
12,
370,
4868,
626,
2195,
7042,
365,
440,
3769,
2043,
394,
7879,
564,
379,
701,
10919,
623,
1417,
9758,
80,
30,
819,
665,
80,
30,
3917,
1265,
1172,
7526,
2195,
7042,
370,
3507,
283,
28900,
7,
2323,
12,
8749,
2043,
295,
13,
4296,
3062,
12,
737,
5210,
367,
642,
4770,
12,
503,
367,
14147,
6947,
12,
503,
367,
2043,
283,
7191,
13,
6493,
7,
4145,
9758,
80,
30,
199,
3996,
14454,
3674,
199,
1108,
3015,
30,
199,
3996,
340,
10990,
3674,
199,
28,
3015,
1305,
628,
815,
1743,
523,
665,
72,
18,
30,
8673,
1108,
72,
18,
30,
272,
7749,
340,
4499,
3674,
272,
665,
80,
30,
16148,
1627,
367,
5988,
9919,
80,
30,
272,
665,
657,
30,
272,
8448,
4499,
3586,
272,
3068,
657,
30,
272,
7749,
14454,
3674,
819,
665,
80,
30,
607,
8605,
12,
642,
883,
4781,
1380,
2337,
365,
282,
3805,
85,
1132,
28965,
11666,
4784,
2104,
836,
89,
12,
503,
1380,
523,
665,
65,
523,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
2828,
15,
10088,
12645,
1121,
13,
2828,
13,
10088,
8423,
9323,
1159,
523,
22468,
14729,
1108,
65,
30,
965,
440,
2757,
1202,
6657,
14,
221,
2104,
8761,
4513,
12,
1265,
1929,
370,
523,
4868,
9919,
80,
30,
819,
665,
348,
30,
272,
665,
317,
30,
14398,
7042,
365,
32163,
10049,
9758,
317,
30,
339,
665,
317,
30,
1918,
2455,
805,
4440,
665,
65,
272,
4369,
534,
1014,
921,
4757,
14,
14013,
14,
957,
15,
287,
15,
2374,
15,
1121,
15,
5876,
15,
1246,
12645,
27904,
13,
1100,
13,
1069,
1100,
7,
2535,
600,
30,
17679,
1108,
600,
2957,
65,
30,
272,
367,
314,
1978,
12,
3140,
402,
665,
600,
30,
2998,
1108,
600,
30,
9758,
317,
30,
339,
665,
317,
30,
607,
314,
1978,
12,
2337,
365,
282,
665,
600,
30,
3996,
1978,
1450,
1551,
1457,
3674,
19213,
63,
1418,
272,
7749,
1978,
1450,
4002,
1457,
3674,
1108,
600,
30,
1978,
1947,
6272,
1924,
8761,
1824,
626,
272,
4545,
376,
5007,
2851,
9758,
317,
30,
339,
665,
317,
30,
3917,
1265,
787,
440,
1808,
665,
600,
30,
13912,
25322,
1108,
600,
6244,
2066,
1265,
1471,
675,
272,
665,
600,
30,
10088,
63,
18292,
1108,
600,
30,
641,
1263,
6858,
626,
675,
314,
665,
600,
30,
10088,
63,
1418,
1108,
600,
30,
272,
1978,
1947,
12,
465,
5521,
465,
5204,
626,
4729,
314,
8761,
666,
9758,
317,
30,
819,
3068,
348,
30,
819,
665,
80,
30,
5556,
3984,
1937,
316,
314,
1720,
3420,
402,
642,
2034,
2952,
1265,
1172,
665,
600,
30,
5287,
275,
523,
715,
1108,
600,
30,
315,
2195,
5634,
2202,
570,
14,
7743,
626,
370,
665,
600,
30,
797,
1108,
600,
6244,
523,
436,
1454,
314,
2536,
1125,
1245,
911,
506,
9080,
14,
221,
3068,
80,
30,
819,
665,
80,
30,
5556,
883,
17551,
642,
2034,
1808,
314,
22468,
63,
13989,
63,
12058,
4260,
9758,
80,
30,
199,
1108,
3015,
30,
199,
3996,
587,
3674,
199,
28,
3015,
1305,
628,
15228,
1743,
523,
665,
80,
2535,
7241,
30,
11053,
2556,
365,
2808,
543,
10990,
29,
549,
9758,
7241,
2957,
80,
30,
199,
1108,
3015,
30,
199,
3996,
14454,
3674,
199,
1108,
2030,
30,
199,
1108,
1360,
30,
199,
624,
199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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
] |
zsiciarz/django
|
django/template/loader.py
|
129
|
2054
|
from . import engines
from .exceptions import TemplateDoesNotExist
def get_template(template_name, using=None):
"""
Load and return a template for the given name.
Raise TemplateDoesNotExist if no such template exists.
"""
chain = []
engines = _engine_list(using)
for engine in engines:
try:
return engine.get_template(template_name)
except TemplateDoesNotExist as e:
chain.append(e)
raise TemplateDoesNotExist(template_name, chain=chain)
def select_template(template_name_list, using=None):
"""
Load and return a template for one of the given names.
Try names in order and return the first template found.
Raise TemplateDoesNotExist if no such template exists.
"""
if isinstance(template_name_list, str):
raise TypeError(
'select_template() takes an iterable of template names but got a '
'string: %r. Use get_template() if you want to load a single '
'template by name.' % template_name_list
)
chain = []
engines = _engine_list(using)
for template_name in template_name_list:
for engine in engines:
try:
return engine.get_template(template_name)
except TemplateDoesNotExist as e:
chain.append(e)
if template_name_list:
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
else:
raise TemplateDoesNotExist("No template names provided")
def render_to_string(template_name, context=None, request=None, using=None):
"""
Load a template and render it with a context. Return a string.
template_name may be a string or a list of strings.
"""
if isinstance(template_name, (list, tuple)):
template = select_template(template_name, using=using)
else:
template = get_template(template_name, using=using)
return template.render(context, request)
def _engine_list(using=None):
return engines.all() if using is None else [engines[using]]
|
bsd-3-clause
|
[
504,
1275,
492,
28156,
199,
504,
1275,
3924,
492,
27193,
421,
199,
318,
664,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
436,
372,
282,
1978,
367,
314,
1627,
536,
14,
339,
14771,
27193,
340,
949,
4066,
1978,
3495,
14,
272,
408,
272,
6036,
275,
942,
272,
28156,
275,
485,
3908,
63,
513,
8,
4941,
9,
272,
367,
6869,
315,
28156,
26,
267,
862,
26,
288,
372,
6869,
14,
362,
63,
1160,
8,
1160,
63,
354,
9,
267,
871,
27193,
465,
325,
26,
288,
6036,
14,
740,
8,
69,
9,
339,
746,
27193,
8,
1160,
63,
354,
12,
6036,
29,
4429,
9,
421,
199,
318,
3504,
63,
1160,
8,
1160,
63,
354,
63,
513,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
436,
372,
282,
1978,
367,
1373,
402,
314,
1627,
1561,
14,
339,
7649,
1561,
315,
1865,
436,
372,
314,
1642,
1978,
1911,
14,
339,
14771,
27193,
340,
949,
4066,
1978,
3495,
14,
272,
408,
272,
340,
1228,
8,
1160,
63,
354,
63,
513,
12,
620,
304,
267,
746,
3146,
8,
288,
283,
2416,
63,
1160,
342,
6181,
376,
6076,
402,
1978,
1561,
1325,
4788,
282,
283,
288,
283,
875,
26,
450,
82,
14,
3645,
664,
63,
1160,
342,
340,
1265,
2934,
370,
2248,
282,
2849,
283,
288,
283,
1160,
701,
536,
3530,
450,
1978,
63,
354,
63,
513,
267,
776,
339,
6036,
275,
942,
272,
28156,
275,
485,
3908,
63,
513,
8,
4941,
9,
272,
367,
1978,
63,
354,
315,
1978,
63,
354,
63,
513,
26,
267,
367,
6869,
315,
28156,
26,
288,
862,
26,
355,
372,
6869,
14,
362,
63,
1160,
8,
1160,
63,
354,
9,
288,
871,
27193,
465,
325,
26,
355,
6036,
14,
740,
8,
69,
9,
339,
340,
1978,
63,
354,
63,
513,
26,
267,
746,
27193,
5102,
1987,
904,
8,
1160,
63,
354,
63,
513,
395,
6036,
29,
4429,
9,
272,
587,
26,
267,
746,
27193,
480,
1944,
1978,
1561,
2741,
531,
421,
199,
318,
3795,
63,
475,
63,
875,
8,
1160,
63,
354,
12,
1067,
29,
403,
12,
1056,
29,
403,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
282,
1978,
436,
3795,
652,
543,
282,
1067,
14,
1432,
282,
1059,
14,
339,
1978,
63,
354,
1443,
506,
282,
1059,
503,
282,
769,
402,
3326,
14,
272,
408,
272,
340,
1228,
8,
1160,
63,
354,
12,
334,
513,
12,
2008,
2298,
267,
1978,
275,
3504,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
4941,
9,
272,
587,
26,
267,
1978,
275,
664,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
4941,
9,
272,
372,
1978,
14,
3352,
8,
1100,
12,
1056,
9,
421,
199,
318,
485,
3908,
63,
513,
8,
4941,
29,
403,
304,
272,
372,
28156,
14,
452,
342,
340,
1808,
365,
488,
587,
359,
30378,
59,
4941,
2677,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1275,
492,
28156,
199,
504,
1275,
3924,
492,
27193,
421,
199,
318,
664,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
436,
372,
282,
1978,
367,
314,
1627,
536,
14,
339,
14771,
27193,
340,
949,
4066,
1978,
3495,
14,
272,
408,
272,
6036,
275,
942,
272,
28156,
275,
485,
3908,
63,
513,
8,
4941,
9,
272,
367,
6869,
315,
28156,
26,
267,
862,
26,
288,
372,
6869,
14,
362,
63,
1160,
8,
1160,
63,
354,
9,
267,
871,
27193,
465,
325,
26,
288,
6036,
14,
740,
8,
69,
9,
339,
746,
27193,
8,
1160,
63,
354,
12,
6036,
29,
4429,
9,
421,
199,
318,
3504,
63,
1160,
8,
1160,
63,
354,
63,
513,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
436,
372,
282,
1978,
367,
1373,
402,
314,
1627,
1561,
14,
339,
7649,
1561,
315,
1865,
436,
372,
314,
1642,
1978,
1911,
14,
339,
14771,
27193,
340,
949,
4066,
1978,
3495,
14,
272,
408,
272,
340,
1228,
8,
1160,
63,
354,
63,
513,
12,
620,
304,
267,
746,
3146,
8,
288,
283,
2416,
63,
1160,
342,
6181,
376,
6076,
402,
1978,
1561,
1325,
4788,
282,
283,
288,
283,
875,
26,
450,
82,
14,
3645,
664,
63,
1160,
342,
340,
1265,
2934,
370,
2248,
282,
2849,
283,
288,
283,
1160,
701,
536,
3530,
450,
1978,
63,
354,
63,
513,
267,
776,
339,
6036,
275,
942,
272,
28156,
275,
485,
3908,
63,
513,
8,
4941,
9,
272,
367,
1978,
63,
354,
315,
1978,
63,
354,
63,
513,
26,
267,
367,
6869,
315,
28156,
26,
288,
862,
26,
355,
372,
6869,
14,
362,
63,
1160,
8,
1160,
63,
354,
9,
288,
871,
27193,
465,
325,
26,
355,
6036,
14,
740,
8,
69,
9,
339,
340,
1978,
63,
354,
63,
513,
26,
267,
746,
27193,
5102,
1987,
904,
8,
1160,
63,
354,
63,
513,
395,
6036,
29,
4429,
9,
272,
587,
26,
267,
746,
27193,
480,
1944,
1978,
1561,
2741,
531,
421,
199,
318,
3795,
63,
475,
63,
875,
8,
1160,
63,
354,
12,
1067,
29,
403,
12,
1056,
29,
403,
12,
1808,
29,
403,
304,
272,
408,
272,
7190,
282,
1978,
436,
3795,
652,
543,
282,
1067,
14,
1432,
282,
1059,
14,
339,
1978,
63,
354,
1443,
506,
282,
1059,
503,
282,
769,
402,
3326,
14,
272,
408,
272,
340,
1228,
8,
1160,
63,
354,
12,
334,
513,
12,
2008,
2298,
267,
1978,
275,
3504,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
4941,
9,
272,
587,
26,
267,
1978,
275,
664,
63,
1160,
8,
1160,
63,
354,
12,
1808,
29,
4941,
9,
272,
372,
1978,
14,
3352,
8,
1100,
12,
1056,
9,
421,
199,
318,
485,
3908,
63,
513,
8,
4941,
29,
403,
304,
272,
372,
28156,
14,
452,
342,
340,
1808,
365,
488,
587,
359,
30378,
59,
4941,
2677,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ping/youtube-dl
|
youtube_dl/extractor/sportdeutschland.py
|
53
|
3779
|
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..utils import (
parse_iso8601,
sanitized_Request,
)
class SportDeutschlandIE(InfoExtractor):
_VALID_URL = r'https?://sportdeutschland\.tv/(?P<sport>[^/?#]+)/(?P<id>[^?#/]+)(?:$|[?#])'
_TESTS = [{
'url': 'http://sportdeutschland.tv/badminton/live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen',
'info_dict': {
'id': 'live-li-ning-badminton-weltmeisterschaft-2014-kopenhagen',
'ext': 'mp4',
'title': 're:Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen',
'categories': ['Badminton'],
'view_count': int,
'thumbnail': r're:^https?://.*\.jpg$',
'description': r're:Die Badminton-WM 2014 aus Kopenhagen bei Sportdeutschland\.TV',
'timestamp': int,
'upload_date': 're:^201408[23][0-9]$',
},
'params': {
'skip_download': 'Live stream',
},
}, {
'url': 'http://sportdeutschland.tv/li-ning-badminton-wm-2014/lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs',
'info_dict': {
'id': 'lee-li-ning-badminton-weltmeisterschaft-2014-kopenhagen-herren-einzel-wei-vs',
'ext': 'mp4',
'upload_date': '20140825',
'description': 'md5:60a20536b57cee7d9a4ec005e8687504',
'timestamp': 1408976060,
'duration': 2732,
'title': 'Li-Ning Badminton Weltmeisterschaft 2014 Kopenhagen: Herren Einzel, Wei Lee vs. Keun Lee',
'thumbnail': r're:^https?://.*\.jpg$',
'view_count': int,
'categories': ['Li-Ning Badminton WM 2014'],
}
}]
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
sport_id = mobj.group('sport')
api_url = 'http://proxy.vidibusdynamic.net/sportdeutschland.tv/api/permalinks/%s/%s?access_token=true' % (
sport_id, video_id)
req = sanitized_Request(api_url, headers={
'Accept': 'application/vnd.vidibus.v2.html+json',
'Referer': url,
})
data = self._download_json(req, video_id)
asset = data['asset']
categories = [data['section']['title']]
formats = []
smil_url = asset['video']
if '.smil' in smil_url:
m3u8_url = smil_url.replace('.smil', '.m3u8')
formats.extend(
self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4'))
smil_doc = self._download_xml(
smil_url, video_id, note='Downloading SMIL metadata')
base_url_el = smil_doc.find('./head/meta')
if base_url_el:
base_url = base_url_el.attrib['base']
formats.extend([{
'format_id': 'rmtp',
'url': base_url if base_url_el else n.attrib['src'],
'play_path': n.attrib['src'],
'ext': 'flv',
'preference': -100,
'format_note': 'Seems to fail at example stream',
} for n in smil_doc.findall('./body/video')])
else:
formats.append({'url': smil_url})
self._sort_formats(formats)
return {
'id': video_id,
'formats': formats,
'title': asset['title'],
'thumbnail': asset.get('image'),
'description': asset.get('teaser'),
'duration': asset.get('duration'),
'categories': categories,
'view_count': asset.get('views'),
'rtmp_live': asset.get('live'),
'timestamp': parse_iso8601(asset.get('date')),
}
|
unlicense
|
[
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
2198,
63,
4595,
15363,
12,
272,
31734,
63,
2017,
12,
199,
9,
421,
199,
533,
428,
719,
872,
14608,
335,
9688,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
3275,
271,
14608,
335,
9688,
4537,
6993,
9448,
48,
28,
3275,
13489,
10197,
3,
24598,
2229,
48,
28,
344,
13489,
31,
3,
15,
11896,
5169,
4,
17884,
31,
3,
566,
7,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
4087,
77,
442,
265,
15,
6442,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
6442,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
15330,
278,
14186,
9518,
856,
6927,
1804,
1490,
72,
24758,
297,
288,
283,
8906,
356,
788,
5725,
77,
442,
265,
995,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
288,
283,
1802,
356,
519,
3984,
26,
1341,
69,
8857,
77,
442,
265,
13,
13073,
6927,
282,
527,
1804,
1490,
72,
24758,
32731,
428,
719,
271,
14608,
335,
9688,
4537,
12764,
297,
288,
283,
3954,
356,
1109,
12,
288,
283,
5064,
63,
602,
356,
283,
264,
23497,
7280,
2036,
59,
1789,
1527,
16,
13,
25,
61,
4268,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
283,
17458,
2547,
297,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
16240,
13,
7280,
15,
18387,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
13,
2523,
828,
13,
69,
262,
90,
352,
13,
21431,
13,
3122,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
18387,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
13,
2523,
828,
13,
69,
262,
90,
352,
13,
21431,
13,
3122,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
5064,
63,
602,
356,
283,
7280,
2036,
821,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
2259,
65,
10629,
1344,
66,
1641,
29377,
23,
68,
25,
65,
20,
825,
7972,
69,
1184,
13357,
966,
297,
288,
283,
3954,
356,
22796,
1407,
2114,
18857,
12,
288,
283,
5553,
356,
8087,
708,
12,
288,
283,
1213,
356,
283,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
15330,
278,
14186,
9518,
856,
6927,
1804,
1490,
72,
24758,
26,
18769,
828,
662,
262,
90,
352,
12,
2136,
73,
491,
1024,
8118,
14,
25645,
324,
491,
1024,
297,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8906,
356,
788,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
45,
6927,
995,
398,
789,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
308,
719,
63,
344,
275,
14208,
14,
923,
360,
3275,
358,
398,
2986,
63,
633,
275,
283,
1014,
921,
3280,
14,
433,
328,
464,
3893,
4495,
14,
846,
15,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
1246,
15,
529,
2174,
2292,
83,
3149,
83,
3149,
83,
31,
2732,
63,
1418,
29,
2052,
7,
450,
334,
288,
308,
719,
63,
344,
12,
3991,
63,
344,
9,
267,
2648,
275,
31734,
63,
2017,
8,
1246,
63,
633,
12,
2323,
3126,
288,
283,
8422,
356,
283,
3578,
15,
26379,
14,
433,
328,
5610,
14,
86,
18,
14,
1360,
11,
1001,
297,
288,
283,
28900,
356,
1166,
12,
267,
3828,
267,
666,
275,
291,
423,
4249,
63,
1001,
8,
2103,
12,
3991,
63,
344,
9,
398,
8977,
275,
666,
459,
6562,
418,
267,
9695,
275,
359,
576,
459,
2792,
2545,
1213,
6538,
398,
6752,
275,
942,
267,
4383,
382,
63,
633,
275,
8977,
459,
3722,
418,
267,
340,
1987,
3300,
382,
7,
315,
4383,
382,
63,
633,
26,
288,
333,
19,
85,
24,
63,
633,
275,
4383,
382,
63,
633,
14,
1814,
5175,
3300,
382,
297,
1987,
77,
19,
85,
24,
358,
288,
6752,
14,
2880,
8,
355,
291,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
77,
19,
85,
24,
63,
633,
12,
3991,
63,
344,
12,
1599,
534,
311,
20,
1333,
953,
4383,
382,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
4383,
382,
63,
633,
12,
3991,
63,
344,
12,
5317,
534,
18085,
2389,
1193,
3341,
358,
288,
1300,
63,
633,
63,
352,
275,
4383,
382,
63,
1301,
14,
1623,
17371,
2993,
15,
2024,
358,
288,
340,
1300,
63,
633,
63,
352,
26,
355,
1300,
63,
633,
275,
1300,
63,
633,
63,
352,
14,
6640,
459,
1095,
418,
288,
6752,
14,
2880,
779,
91,
355,
283,
908,
63,
344,
356,
283,
5682,
683,
297,
355,
283,
633,
356,
1300,
63,
633,
340,
1300,
63,
633,
63,
352,
587,
302,
14,
6640,
459,
2164,
995,
355,
283,
2802,
63,
515,
356,
302,
14,
6640,
459,
2164,
995,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
14994,
356,
446,
1960,
12,
355,
283,
908,
63,
4610,
356,
283,
9295,
706,
370,
2449,
737,
2893,
2547,
297,
288,
789,
367,
302,
315,
4383,
382,
63,
1301,
14,
6452,
17371,
2030,
15,
3722,
2023,
267,
587,
26,
288,
6752,
14,
740,
3252,
633,
356,
4383,
382,
63
] |
[
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
334,
272,
2198,
63,
4595,
15363,
12,
272,
31734,
63,
2017,
12,
199,
9,
421,
199,
533,
428,
719,
872,
14608,
335,
9688,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
14144,
3275,
271,
14608,
335,
9688,
4537,
6993,
9448,
48,
28,
3275,
13489,
10197,
3,
24598,
2229,
48,
28,
344,
13489,
31,
3,
15,
11896,
5169,
4,
17884,
31,
3,
566,
7,
272,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
1014,
921,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
4087,
77,
442,
265,
15,
6442,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
6442,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
15330,
278,
14186,
9518,
856,
6927,
1804,
1490,
72,
24758,
297,
288,
283,
8906,
356,
788,
5725,
77,
442,
265,
995,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
288,
283,
1802,
356,
519,
3984,
26,
1341,
69,
8857,
77,
442,
265,
13,
13073,
6927,
282,
527,
1804,
1490,
72,
24758,
32731,
428,
719,
271,
14608,
335,
9688,
4537,
12764,
297,
288,
283,
3954,
356,
1109,
12,
288,
283,
5064,
63,
602,
356,
283,
264,
23497,
7280,
2036,
59,
1789,
1527,
16,
13,
25,
61,
4268,
267,
1660,
267,
283,
1162,
356,
469,
288,
283,
2759,
63,
4249,
356,
283,
17458,
2547,
297,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
1014,
921,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
16240,
13,
7280,
15,
18387,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
13,
2523,
828,
13,
69,
262,
90,
352,
13,
21431,
13,
3122,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
18387,
13,
317,
13,
1835,
13,
4087,
77,
442,
265,
13,
87,
15330,
278,
14186,
9518,
856,
13,
7280,
13,
75,
1490,
72,
24758,
13,
2523,
828,
13,
69,
262,
90,
352,
13,
21431,
13,
3122,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
5064,
63,
602,
356,
283,
7280,
2036,
821,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
2259,
65,
10629,
1344,
66,
1641,
29377,
23,
68,
25,
65,
20,
825,
7972,
69,
1184,
13357,
966,
297,
288,
283,
3954,
356,
22796,
1407,
2114,
18857,
12,
288,
283,
5553,
356,
8087,
708,
12,
288,
283,
1213,
356,
283,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
15330,
278,
14186,
9518,
856,
6927,
1804,
1490,
72,
24758,
26,
18769,
828,
662,
262,
90,
352,
12,
2136,
73,
491,
1024,
8118,
14,
25645,
324,
491,
1024,
297,
288,
283,
8311,
356,
519,
3984,
23497,
2859,
32569,
8476,
4268,
288,
283,
1345,
63,
835,
356,
1109,
12,
288,
283,
8906,
356,
788,
13009,
13,
46,
316,
8857,
77,
442,
265,
644,
45,
6927,
995,
398,
789,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
308,
719,
63,
344,
275,
14208,
14,
923,
360,
3275,
358,
398,
2986,
63,
633,
275,
283,
1014,
921,
3280,
14,
433,
328,
464,
3893,
4495,
14,
846,
15,
3275,
271,
14608,
335,
9688,
14,
6993,
15,
1246,
15,
529,
2174,
2292,
83,
3149,
83,
3149,
83,
31,
2732,
63,
1418,
29,
2052,
7,
450,
334,
288,
308,
719,
63,
344,
12,
3991,
63,
344,
9,
267,
2648,
275,
31734,
63,
2017,
8,
1246,
63,
633,
12,
2323,
3126,
288,
283,
8422,
356,
283,
3578,
15,
26379,
14,
433,
328,
5610,
14,
86,
18,
14,
1360,
11,
1001,
297,
288,
283,
28900,
356,
1166,
12,
267,
3828,
267,
666,
275,
291,
423,
4249,
63,
1001,
8,
2103,
12,
3991,
63,
344,
9,
398,
8977,
275,
666,
459,
6562,
418,
267,
9695,
275,
359,
576,
459,
2792,
2545,
1213,
6538,
398,
6752,
275,
942,
267,
4383,
382,
63,
633,
275,
8977,
459,
3722,
418,
267,
340,
1987,
3300,
382,
7,
315,
4383,
382,
63,
633,
26,
288,
333,
19,
85,
24,
63,
633,
275,
4383,
382,
63,
633,
14,
1814,
5175,
3300,
382,
297,
1987,
77,
19,
85,
24,
358,
288,
6752,
14,
2880,
8,
355,
291,
423,
5005,
63,
77,
19,
85,
24,
63,
6321,
8,
77,
19,
85,
24,
63,
633,
12,
3991,
63,
344,
12,
1599,
534,
311,
20,
1333,
953,
4383,
382,
63,
1301,
275,
291,
423,
4249,
63,
1652,
8,
355,
4383,
382,
63,
633,
12,
3991,
63,
344,
12,
5317,
534,
18085,
2389,
1193,
3341,
358,
288,
1300,
63,
633,
63,
352,
275,
4383,
382,
63,
1301,
14,
1623,
17371,
2993,
15,
2024,
358,
288,
340,
1300,
63,
633,
63,
352,
26,
355,
1300,
63,
633,
275,
1300,
63,
633,
63,
352,
14,
6640,
459,
1095,
418,
288,
6752,
14,
2880,
779,
91,
355,
283,
908,
63,
344,
356,
283,
5682,
683,
297,
355,
283,
633,
356,
1300,
63,
633,
340,
1300,
63,
633,
63,
352,
587,
302,
14,
6640,
459,
2164,
995,
355,
283,
2802,
63,
515,
356,
302,
14,
6640,
459,
2164,
995,
355,
283,
832,
356,
283,
22753,
297,
355,
283,
14994,
356,
446,
1960,
12,
355,
283,
908,
63,
4610,
356,
283,
9295,
706,
370,
2449,
737,
2893,
2547,
297,
288,
789,
367,
302,
315,
4383,
382,
63,
1301,
14,
6452,
17371,
2030,
15,
3722,
2023,
267,
587,
26,
288,
6752,
14,
740,
3252,
633,
356,
4383,
382,
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,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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
] |
djt5019/tornado
|
tornado/testing.py
|
19
|
27280
|
#!/usr/bin/env python
"""Support classes for automated testing.
* `AsyncTestCase` and `AsyncHTTPTestCase`: Subclasses of unittest.TestCase
with additional support for testing asynchronous (`.IOLoop` based) code.
* `ExpectLog` and `LogTrapTestCase`: Make test logs less spammy.
* `main()`: A simple test runner (wrapper around unittest.main()) with support
for the tornado.autoreload module to rerun the tests when code changes.
"""
from __future__ import absolute_import, division, print_function, with_statement
try:
from tornado import gen
from tornado.httpclient import AsyncHTTPClient
from tornado.httpserver import HTTPServer
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.ioloop import IOLoop, TimeoutError
from tornado import netutil
from tornado.process import Subprocess
except ImportError:
# These modules are not importable on app engine. Parts of this module
# won't work, but e.g. LogTrapTestCase and main() will.
AsyncHTTPClient = None
gen = None
HTTPServer = None
IOLoop = None
netutil = None
SimpleAsyncHTTPClient = None
Subprocess = None
from tornado.log import gen_log, app_log
from tornado.stack_context import ExceptionStackContext
from tornado.util import raise_exc_info, basestring_type
import functools
import logging
import os
import re
import signal
import socket
import sys
try:
from cStringIO import StringIO # py2
except ImportError:
from io import StringIO # py3
try:
from collections.abc import Generator as GeneratorType # py35+
except ImportError:
from types import GeneratorType
# Tornado's own test suite requires the updated unittest module
# (either py27+ or unittest2) so tornado.test.util enforces
# this requirement, but for other users of tornado.testing we want
# to allow the older version if unitest2 is not available.
if sys.version_info >= (3,):
# On python 3, mixing unittest2 and unittest (including doctest)
# doesn't seem to work, so always use unittest.
import unittest
else:
# On python 2, prefer unittest2 when available.
try:
import unittest2 as unittest
except ImportError:
import unittest
_next_port = 10000
def get_unused_port():
"""Returns a (hopefully) unused port number.
This function does not guarantee that the port it returns is available,
only that a series of get_unused_port calls in a single process return
distinct ports.
.. deprecated::
Use bind_unused_port instead, which is guaranteed to find an unused port.
"""
global _next_port
port = _next_port
_next_port = _next_port + 1
return port
def bind_unused_port(reuse_port=False):
"""Binds a server socket to an available port on localhost.
Returns a tuple (socket, port).
"""
[sock] = netutil.bind_sockets(None, 'localhost', family=socket.AF_INET,
reuse_port=reuse_port)
port = sock.getsockname()[1]
return sock, port
def get_async_test_timeout():
"""Get the global timeout setting for async tests.
Returns a float, the timeout in seconds.
.. versionadded:: 3.1
"""
try:
return float(os.environ.get('ASYNC_TEST_TIMEOUT'))
except (ValueError, TypeError):
return 5
class _TestMethodWrapper(object):
"""Wraps a test method to raise an error if it returns a value.
This is mainly used to detect undecorated generators (if a test
method yields it must use a decorator to consume the generator),
but will also detect other kinds of return values (these are not
necessarily errors, but we alert anyway since there is no good
reason to return a value from a test.
"""
def __init__(self, orig_method):
self.orig_method = orig_method
def __call__(self, *args, **kwargs):
result = self.orig_method(*args, **kwargs)
if isinstance(result, GeneratorType):
raise TypeError("Generator test methods should be decorated with "
"tornado.testing.gen_test")
elif result is not None:
raise ValueError("Return value from test method ignored: %r" %
result)
def __getattr__(self, name):
"""Proxy all unknown attributes to the original method.
This is important for some of the decorators in the `unittest`
module, such as `unittest.skipIf`.
"""
return getattr(self.orig_method, name)
class AsyncTestCase(unittest.TestCase):
"""`~unittest.TestCase` subclass for testing `.IOLoop`-based
asynchronous code.
The unittest framework is synchronous, so the test must be
complete by the time the test method returns. This means that
asynchronous code cannot be used in quite the same way as usual.
To write test functions that use the same ``yield``-based patterns
used with the `tornado.gen` module, decorate your test methods
with `tornado.testing.gen_test` instead of
`tornado.gen.coroutine`. This class also provides the `stop()`
and `wait()` methods for a more manual style of testing. The test
method itself must call ``self.wait()``, and asynchronous
callbacks should call ``self.stop()`` to signal completion.
By default, a new `.IOLoop` is constructed for each test and is available
as ``self.io_loop``. This `.IOLoop` should be used in the construction of
HTTP clients/servers, etc. If the code being tested requires a
global `.IOLoop`, subclasses should override `get_new_ioloop` to return it.
The `.IOLoop`'s ``start`` and ``stop`` methods should not be
called directly. Instead, use `self.stop <stop>` and `self.wait
<wait>`. Arguments passed to ``self.stop`` are returned from
``self.wait``. It is possible to have multiple ``wait``/``stop``
cycles in the same test.
Example::
# This test uses coroutine style.
class MyTestCase(AsyncTestCase):
@tornado.testing.gen_test
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
response = yield client.fetch("http://www.tornadoweb.org")
# Test contents of response
self.assertIn("FriendFeed", response.body)
# This test uses argument passing between self.stop and self.wait.
class MyTestCase2(AsyncTestCase):
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
client.fetch("http://www.tornadoweb.org/", self.stop)
response = self.wait()
# Test contents of response
self.assertIn("FriendFeed", response.body)
# This test uses an explicit callback-based style.
class MyTestCase3(AsyncTestCase):
def test_http_fetch(self):
client = AsyncHTTPClient(self.io_loop)
client.fetch("http://www.tornadoweb.org/", self.handle_fetch)
self.wait()
def handle_fetch(self, response):
# Test contents of response (failures and exceptions here
# will cause self.wait() to throw an exception and end the
# test).
# Exceptions thrown here are magically propagated to
# self.wait() in test_http_fetch() via stack_context.
self.assertIn("FriendFeed", response.body)
self.stop()
"""
def __init__(self, methodName='runTest', **kwargs):
super(AsyncTestCase, self).__init__(methodName, **kwargs)
self.__stopped = False
self.__running = False
self.__failure = None
self.__stop_args = None
self.__timeout = None
# It's easy to forget the @gen_test decorator, but if you do
# the test will silently be ignored because nothing will consume
# the generator. Replace the test method with a wrapper that will
# make sure it's not an undecorated generator.
setattr(self, methodName, _TestMethodWrapper(getattr(self, methodName)))
def setUp(self):
super(AsyncTestCase, self).setUp()
self.io_loop = self.get_new_ioloop()
self.io_loop.make_current()
def tearDown(self):
# Clean up Subprocess, so it can be used again with a new ioloop.
Subprocess.uninitialize()
self.io_loop.clear_current()
if (not IOLoop.initialized() or
self.io_loop is not IOLoop.instance()):
# Try to clean up any file descriptors left open in the ioloop.
# This avoids leaks, especially when tests are run repeatedly
# in the same process with autoreload (because curl does not
# set FD_CLOEXEC on its file descriptors)
self.io_loop.close(all_fds=True)
super(AsyncTestCase, self).tearDown()
# In case an exception escaped or the StackContext caught an exception
# when there wasn't a wait() to re-raise it, do so here.
# This is our last chance to raise an exception in a way that the
# unittest machinery understands.
self.__rethrow()
def get_new_ioloop(self):
"""Creates a new `.IOLoop` for this test. May be overridden in
subclasses for tests that require a specific `.IOLoop` (usually
the singleton `.IOLoop.instance()`).
"""
return IOLoop()
def _handle_exception(self, typ, value, tb):
if self.__failure is None:
self.__failure = (typ, value, tb)
else:
app_log.error("multiple unhandled exceptions in test",
exc_info=(typ, value, tb))
self.stop()
return True
def __rethrow(self):
if self.__failure is not None:
failure = self.__failure
self.__failure = None
raise_exc_info(failure)
def run(self, result=None):
with ExceptionStackContext(self._handle_exception):
super(AsyncTestCase, self).run(result)
# As a last resort, if an exception escaped super.run() and wasn't
# re-raised in tearDown, raise it here. This will cause the
# unittest run to fail messily, but that's better than silently
# ignoring an error.
self.__rethrow()
def stop(self, _arg=None, **kwargs):
"""Stops the `.IOLoop`, causing one pending (or future) call to `wait()`
to return.
Keyword arguments or a single positional argument passed to `stop()` are
saved and will be returned by `wait()`.
"""
assert _arg is None or not kwargs
self.__stop_args = kwargs or _arg
if self.__running:
self.io_loop.stop()
self.__running = False
self.__stopped = True
def wait(self, condition=None, timeout=None):
"""Runs the `.IOLoop` until stop is called or timeout has passed.
In the event of a timeout, an exception will be thrown. The
default timeout is 5 seconds; it may be overridden with a
``timeout`` keyword argument or globally with the
``ASYNC_TEST_TIMEOUT`` environment variable.
If ``condition`` is not None, the `.IOLoop` will be restarted
after `stop()` until ``condition()`` returns true.
.. versionchanged:: 3.1
Added the ``ASYNC_TEST_TIMEOUT`` environment variable.
"""
if timeout is None:
timeout = get_async_test_timeout()
if not self.__stopped:
if timeout:
def timeout_func():
try:
raise self.failureException(
'Async operation timed out after %s seconds' %
timeout)
except Exception:
self.__failure = sys.exc_info()
self.stop()
self.__timeout = self.io_loop.add_timeout(self.io_loop.time() + timeout, timeout_func)
while True:
self.__running = True
self.io_loop.start()
if (self.__failure is not None or
condition is None or condition()):
break
if self.__timeout is not None:
self.io_loop.remove_timeout(self.__timeout)
self.__timeout = None
assert self.__stopped
self.__stopped = False
self.__rethrow()
result = self.__stop_args
self.__stop_args = None
return result
class AsyncHTTPTestCase(AsyncTestCase):
"""A test case that starts up an HTTP server.
Subclasses must override `get_app()`, which returns the
`tornado.web.Application` (or other `.HTTPServer` callback) to be tested.
Tests will typically use the provided ``self.http_client`` to fetch
URLs from this server.
Example, assuming the "Hello, world" example from the user guide is in
``hello.py``::
import hello
class TestHelloApp(AsyncHTTPTestCase):
def get_app(self):
return hello.make_app()
def test_homepage(self):
response = self.fetch('/')
self.assertEqual(response.code, 200)
self.assertEqual(response.body, 'Hello, world')
That call to ``self.fetch()`` is equivalent to ::
self.http_client.fetch(self.get_url('/'), self.stop)
response = self.wait()
which illustrates how AsyncTestCase can turn an asynchronous operation,
like ``http_client.fetch()``, into a synchronous operation. If you need
to do other asynchronous operations in tests, you'll probably need to use
``stop()`` and ``wait()`` yourself.
"""
def setUp(self):
super(AsyncHTTPTestCase, self).setUp()
sock, port = bind_unused_port()
self.__port = port
self.http_client = self.get_http_client()
self._app = self.get_app()
self.http_server = self.get_http_server()
self.http_server.add_sockets([sock])
def get_http_client(self):
return AsyncHTTPClient(io_loop=self.io_loop)
def get_http_server(self):
return HTTPServer(self._app, io_loop=self.io_loop,
**self.get_httpserver_options())
def get_app(self):
"""Should be overridden by subclasses to return a
`tornado.web.Application` or other `.HTTPServer` callback.
"""
raise NotImplementedError()
def fetch(self, path, **kwargs):
"""Convenience method to synchronously fetch a url.
The given path will be appended to the local server's host and
port. Any additional kwargs will be passed directly to
`.AsyncHTTPClient.fetch` (and so could be used to pass
``method="POST"``, ``body="..."``, etc).
"""
self.http_client.fetch(self.get_url(path), self.stop, **kwargs)
return self.wait()
def get_httpserver_options(self):
"""May be overridden by subclasses to return additional
keyword arguments for the server.
"""
return {}
def get_http_port(self):
"""Returns the port used by the server.
A new port is chosen for each test.
"""
return self.__port
def get_protocol(self):
return 'http'
def get_url(self, path):
"""Returns an absolute url for the given path on the test server."""
return '%s://localhost:%s%s' % (self.get_protocol(),
self.get_http_port(), path)
def tearDown(self):
self.http_server.stop()
self.io_loop.run_sync(self.http_server.close_all_connections,
timeout=get_async_test_timeout())
if (not IOLoop.initialized() or
self.http_client.io_loop is not IOLoop.instance()):
self.http_client.close()
super(AsyncHTTPTestCase, self).tearDown()
class AsyncHTTPSTestCase(AsyncHTTPTestCase):
"""A test case that starts an HTTPS server.
Interface is generally the same as `AsyncHTTPTestCase`.
"""
def get_http_client(self):
return AsyncHTTPClient(io_loop=self.io_loop, force_instance=True,
defaults=dict(validate_cert=False))
def get_httpserver_options(self):
return dict(ssl_options=self.get_ssl_options())
def get_ssl_options(self):
"""May be overridden by subclasses to select SSL options.
By default includes a self-signed testing certificate.
"""
# Testing keys were generated with:
# openssl req -new -keyout tornado/test/test.key -out tornado/test/test.crt -nodes -days 3650 -x509
module_dir = os.path.dirname(__file__)
return dict(
certfile=os.path.join(module_dir, 'test', 'test.crt'),
keyfile=os.path.join(module_dir, 'test', 'test.key'))
def get_protocol(self):
return 'https'
def gen_test(func=None, timeout=None):
"""Testing equivalent of ``@gen.coroutine``, to be applied to test methods.
``@gen.coroutine`` cannot be used on tests because the `.IOLoop` is not
already running. ``@gen_test`` should be applied to test methods
on subclasses of `AsyncTestCase`.
Example::
class MyTest(AsyncHTTPTestCase):
@gen_test
def test_something(self):
response = yield gen.Task(self.fetch('/'))
By default, ``@gen_test`` times out after 5 seconds. The timeout may be
overridden globally with the ``ASYNC_TEST_TIMEOUT`` environment variable,
or for each test with the ``timeout`` keyword argument::
class MyTest(AsyncHTTPTestCase):
@gen_test(timeout=10)
def test_something_slow(self):
response = yield gen.Task(self.fetch('/'))
.. versionadded:: 3.1
The ``timeout`` argument and ``ASYNC_TEST_TIMEOUT`` environment
variable.
.. versionchanged:: 4.0
The wrapper now passes along ``*args, **kwargs`` so it can be used
on functions with arguments.
"""
if timeout is None:
timeout = get_async_test_timeout()
def wrap(f):
# Stack up several decorators to allow us to access the generator
# object itself. In the innermost wrapper, we capture the generator
# and save it in an attribute of self. Next, we run the wrapped
# function through @gen.coroutine. Finally, the coroutine is
# wrapped again to make it synchronous with run_sync.
#
# This is a good case study arguing for either some sort of
# extensibility in the gen decorators or cancellation support.
@functools.wraps(f)
def pre_coroutine(self, *args, **kwargs):
result = f(self, *args, **kwargs)
if isinstance(result, GeneratorType):
self._test_generator = result
else:
self._test_generator = None
return result
coro = gen.coroutine(pre_coroutine)
@functools.wraps(coro)
def post_coroutine(self, *args, **kwargs):
try:
return self.io_loop.run_sync(
functools.partial(coro, self, *args, **kwargs),
timeout=timeout)
except TimeoutError as e:
# run_sync raises an error with an unhelpful traceback.
# If we throw it back into the generator the stack trace
# will be replaced by the point where the test is stopped.
self._test_generator.throw(e)
# In case the test contains an overly broad except clause,
# we may get back here. In this case re-raise the original
# exception, which is better than nothing.
raise
return post_coroutine
if func is not None:
# Used like:
# @gen_test
# def f(self):
# pass
return wrap(func)
else:
# Used like @gen_test(timeout=10)
return wrap
# Without this attribute, nosetests will try to run gen_test as a test
# anywhere it is imported.
gen_test.__test__ = False
class LogTrapTestCase(unittest.TestCase):
"""A test case that captures and discards all logging output
if the test passes.
Some libraries can produce a lot of logging output even when
the test succeeds, so this class can be useful to minimize the noise.
Simply use it as a base class for your test case. It is safe to combine
with AsyncTestCase via multiple inheritance
(``class MyTestCase(AsyncHTTPTestCase, LogTrapTestCase):``)
This class assumes that only one log handler is configured and
that it is a `~logging.StreamHandler`. This is true for both
`logging.basicConfig` and the "pretty logging" configured by
`tornado.options`. It is not compatible with other log buffering
mechanisms, such as those provided by some test runners.
.. deprecated:: 4.1
Use the unittest module's ``--buffer`` option instead, or `.ExpectLog`.
"""
def run(self, result=None):
logger = logging.getLogger()
if not logger.handlers:
logging.basicConfig()
handler = logger.handlers[0]
if (len(logger.handlers) > 1 or
not isinstance(handler, logging.StreamHandler)):
# Logging has been configured in a way we don't recognize,
# so just leave it alone.
super(LogTrapTestCase, self).run(result)
return
old_stream = handler.stream
try:
handler.stream = StringIO()
gen_log.info("RUNNING TEST: " + str(self))
old_error_count = len(result.failures) + len(result.errors)
super(LogTrapTestCase, self).run(result)
new_error_count = len(result.failures) + len(result.errors)
if new_error_count != old_error_count:
old_stream.write(handler.stream.getvalue())
finally:
handler.stream = old_stream
class ExpectLog(logging.Filter):
"""Context manager to capture and suppress expected log output.
Useful to make tests of error conditions less noisy, while still
leaving unexpected log entries visible. *Not thread safe.*
The attribute ``logged_stack`` is set to true if any exception
stack trace was logged.
Usage::
with ExpectLog('tornado.application', "Uncaught exception"):
error_response = self.fetch("/some_page")
.. versionchanged:: 4.3
Added the ``logged_stack`` attribute.
"""
def __init__(self, logger, regex, required=True):
"""Constructs an ExpectLog context manager.
:param logger: Logger object (or name of logger) to watch. Pass
an empty string to watch the root logger.
:param regex: Regular expression to match. Any log entries on
the specified logger that match this regex will be suppressed.
:param required: If true, an exeption will be raised if the end of
the ``with`` statement is reached without matching any log entries.
"""
if isinstance(logger, basestring_type):
logger = logging.getLogger(logger)
self.logger = logger
self.regex = re.compile(regex)
self.required = required
self.matched = False
self.logged_stack = False
def filter(self, record):
if record.exc_info:
self.logged_stack = True
message = record.getMessage()
if self.regex.match(message):
self.matched = True
return False
return True
def __enter__(self):
self.logger.addFilter(self)
return self
def __exit__(self, typ, value, tb):
self.logger.removeFilter(self)
if not typ and self.required and not self.matched:
raise Exception("did not get expected log message")
def main(**kwargs):
"""A simple test runner.
This test runner is essentially equivalent to `unittest.main` from
the standard library, but adds support for tornado-style option
parsing and log formatting.
The easiest way to run a test is via the command line::
python -m tornado.testing tornado.test.stack_context_test
See the standard library unittest module for ways in which tests can
be specified.
Projects with many tests may wish to define a test script like
``tornado/test/runtests.py``. This script should define a method
``all()`` which returns a test suite and then call
`tornado.testing.main()`. Note that even when a test script is
used, the ``all()`` test suite may be overridden by naming a
single test on the command line::
# Runs all tests
python -m tornado.test.runtests
# Runs one test
python -m tornado.test.runtests tornado.test.stack_context_test
Additional keyword arguments passed through to ``unittest.main()``.
For example, use ``tornado.testing.main(verbosity=2)``
to show many test details as they are run.
See http://docs.python.org/library/unittest.html#unittest.main
for full argument list.
"""
from tornado.options import define, options, parse_command_line
define('exception_on_interrupt', type=bool, default=True,
help=("If true (default), ctrl-c raises a KeyboardInterrupt "
"exception. This prints a stack trace but cannot interrupt "
"certain operations. If false, the process is more reliably "
"killed, but does not print a stack trace."))
# support the same options as unittest's command-line interface
define('verbose', type=bool)
define('quiet', type=bool)
define('failfast', type=bool)
define('catch', type=bool)
define('buffer', type=bool)
argv = [sys.argv[0]] + parse_command_line(sys.argv)
if not options.exception_on_interrupt:
signal.signal(signal.SIGINT, signal.SIG_DFL)
if options.verbose is not None:
kwargs['verbosity'] = 2
if options.quiet is not None:
kwargs['verbosity'] = 0
if options.failfast is not None:
kwargs['failfast'] = True
if options.catch is not None:
kwargs['catchbreak'] = True
if options.buffer is not None:
kwargs['buffer'] = True
if __name__ == '__main__' and len(argv) == 1:
print("No tests specified", file=sys.stderr)
sys.exit(1)
try:
# In order to be able to run tests by their fully-qualified name
# on the command line without importing all tests here,
# module must be set to None. Python 3.2's unittest.main ignores
# defaultTest if no module is given (it tries to do its own
# test discovery, which is incompatible with auto2to3), so don't
# set module if we're not asking for a specific test.
if len(argv) > 1:
unittest.main(module=None, argv=argv, **kwargs)
else:
unittest.main(defaultTest="all", argv=argv, **kwargs)
except SystemExit as e:
if e.code == 0:
gen_log.info('PASS')
else:
gen_log.error('FAIL')
raise
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
11532,
3992,
367,
6384,
23513,
5343,
14,
199,
199,
10,
658,
12807,
1746,
64,
436,
658,
12807,
2856,
1746,
8340,
221,
20196,
402,
2882,
14,
1746,
523,
543,
4722,
2291,
367,
5343,
15608,
334,
2313,
23152,
64,
4079,
9,
1233,
14,
199,
199,
10,
658,
13495,
2445,
64,
436,
658,
2445,
52,
1330,
1746,
8340,
4155,
511,
9610,
6656,
5844,
31155,
14,
199,
199,
10,
658,
973,
342,
8340,
437,
3486,
511,
7876,
334,
5029,
6818,
2882,
14,
973,
1012,
543,
2291,
523,
367,
314,
12148,
14,
27082,
912,
859,
370,
295,
1065,
314,
2295,
1380,
1233,
4493,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
893,
26,
272,
687,
12148,
492,
3805,
272,
687,
12148,
14,
1014,
1258,
492,
15223,
27757,
272,
687,
12148,
14,
1014,
1000,
492,
3101,
3120,
272,
687,
12148,
14,
4129,
63,
1014,
1258,
492,
5870,
12807,
27757,
272,
687,
12148,
14,
27212,
492,
25584,
12,
31886,
272,
687,
12148,
492,
1851,
1974,
272,
687,
12148,
14,
1412,
492,
4804,
1412,
199,
2590,
3545,
26,
272,
327,
5723,
4621,
787,
440,
492,
461,
641,
1145,
6869,
14,
221,
14320,
83,
402,
642,
859,
272,
327,
7859,
1133,
1736,
12,
1325,
325,
14,
71,
14,
5297,
52,
1330,
1746,
436,
2446,
342,
911,
14,
272,
15223,
27757,
275,
488,
272,
3805,
275,
488,
272,
3101,
3120,
275,
488,
272,
25584,
275,
488,
272,
1851,
1974,
275,
488,
272,
5870,
12807,
27757,
275,
488,
272,
4804,
1412,
275,
488,
199,
504,
12148,
14,
793,
492,
3805,
63,
793,
12,
1145,
63,
793,
199,
504,
12148,
14,
2340,
63,
1100,
492,
2186,
4851,
2998,
199,
504,
12148,
14,
1974,
492,
746,
63,
2804,
63,
815,
12,
7116,
63,
466,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
199,
646,
2838,
199,
646,
984,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
221,
327,
1134,
18,
199,
2590,
3545,
26,
272,
687,
5890,
492,
5228,
221,
327,
1134,
19,
199,
199,
893,
26,
272,
687,
5055,
14,
3175,
492,
15042,
465,
15042,
804,
221,
327,
1134,
1276,
11,
199,
2590,
3545,
26,
272,
687,
2943,
492,
15042,
804,
199,
199,
3,
377,
8622,
1159,
5705,
511,
5241,
5074,
314,
4588,
2882,
859,
199,
3,
334,
22051,
1134,
1465,
11,
503,
2882,
18,
9,
880,
12148,
14,
396,
14,
1974,
655,
509,
823,
199,
3,
642,
10685,
12,
1325,
367,
1163,
4390,
402,
12148,
14,
4776,
781,
2934,
199,
3,
370,
2040,
314,
12731,
1015,
340,
15439,
396,
18,
365,
440,
2808,
14,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
19,
16095,
272,
327,
4068,
2366,
650,
12,
13667,
316,
2882,
18,
436,
2882,
334,
15768,
8868,
9,
272,
327,
3181,
1133,
17021,
370,
1736,
12,
880,
3544,
675,
2882,
14,
272,
492,
2882,
199,
2836,
26,
272,
327,
4068,
2366,
499,
12,
16602,
2882,
18,
1380,
2808,
14,
272,
862,
26,
267,
492,
2882,
18,
465,
2882,
272,
871,
3545,
26,
267,
492,
2882,
199,
199,
63,
2184,
63,
719,
275,
11630,
421,
199,
318,
664,
63,
8618,
63,
719,
837,
272,
408,
3407,
282,
334,
526,
321,
5836,
9,
9563,
1844,
1329,
14,
339,
961,
805,
1630,
440,
24197,
626,
314,
1844,
652,
2529,
365,
2808,
12,
272,
1454,
626,
282,
6779,
402,
664,
63,
8618,
63,
719,
4882,
315,
282,
2849,
2112,
372,
272,
15392,
8873,
14,
339,
2508,
5906,
447,
2126,
3645,
5398,
63,
8618,
63,
719,
3140,
12,
1314,
365,
17334,
370,
2342,
376,
9563,
1844,
14,
272,
408,
272,
2288,
485,
2184,
63,
719,
272,
1844,
275,
485,
2184,
63,
719,
272,
485,
2184,
63,
719,
275,
485,
2184,
63,
719,
435,
413,
272,
372,
1844,
421,
199,
318,
5398,
63,
8618,
63,
719,
8,
15712,
63,
719,
29,
797,
304,
272,
408,
8198,
83,
282,
1654,
2838,
370,
376,
2808,
1844,
641,
11667,
14,
339,
1803,
282,
2008,
334,
3450,
12,
1844,
680,
272,
408,
272,
359,
5096,
61,
275,
1851,
1974,
14,
3409,
63,
20517,
8,
403,
12,
283,
5967,
297,
9614,
29,
3450,
14,
5699,
63,
11367,
12,
3303,
12598,
63,
719,
29,
15712,
63,
719,
9,
272,
1844,
275,
6771,
14,
27886,
3430,
17,
61,
272,
372,
6771,
12,
1844,
421,
199,
318,
664,
63,
4146,
63,
396,
63,
2593,
837,
272,
408,
1002,
314,
2288,
2653,
4260,
367,
5316,
2295,
14,
339,
1803,
282,
2069,
12,
314,
2653,
315,
4696,
14,
339,
2508,
7445,
447,
650,
14,
17,
272,
408,
272,
862,
26,
267,
372,
2069,
8,
736,
14,
2314,
14,
362,
360,
26222,
6389,
63,
2864,
63,
8899,
1333,
272,
871,
334,
3393,
12,
3146,
304,
267,
372,
959,
421,
199,
533,
485,
774,
3767,
4590,
8,
785,
304,
272,
408,
55,
8146,
282,
511,
1083,
370,
746,
376,
1125,
340,
652,
2529,
282,
574,
14,
339,
961,
365,
27580,
1202,
370,
9696,
625,
29299,
16952,
334,
692,
282,
511,
272,
1083,
14801,
652,
1471,
675,
282,
7531,
370,
9451,
314,
4306,
395,
272,
1325,
911,
2597,
9696,
1163,
24241,
402,
372,
1338,
334,
29032,
787,
440,
272,
20513,
2552,
12,
1325,
781,
10459,
15988,
3967,
2337,
365,
949,
6954,
272,
4499,
370,
372,
282,
574,
687,
282,
511,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2306,
63,
765,
304,
267,
291,
14,
2981,
63,
765,
275,
2306,
63,
765,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
754,
275,
291,
14,
2981,
63,
765,
2031,
589,
12,
1011,
958,
9,
267,
340,
1228,
8,
1099,
12,
15042,
804,
304,
288,
746,
3146,
480,
7599,
511,
3102,
1077,
506,
16225,
543,
298,
1169,
298,
18443,
14,
4776,
14,
2268,
63,
396,
531,
267,
916,
754,
365,
440,
488,
26,
288,
746,
1722,
480,
1767,
574,
687,
511,
1083,
5525,
26,
450,
82,
2,
450,
2490,
754,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
408,
4936,
1006,
5809,
3004,
370,
314,
3379,
1083,
14,
398,
961,
365,
11012,
367,
2005,
402,
314,
20419,
315
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
11532,
3992,
367,
6384,
23513,
5343,
14,
199,
199,
10,
658,
12807,
1746,
64,
436,
658,
12807,
2856,
1746,
8340,
221,
20196,
402,
2882,
14,
1746,
523,
543,
4722,
2291,
367,
5343,
15608,
334,
2313,
23152,
64,
4079,
9,
1233,
14,
199,
199,
10,
658,
13495,
2445,
64,
436,
658,
2445,
52,
1330,
1746,
8340,
4155,
511,
9610,
6656,
5844,
31155,
14,
199,
199,
10,
658,
973,
342,
8340,
437,
3486,
511,
7876,
334,
5029,
6818,
2882,
14,
973,
1012,
543,
2291,
523,
367,
314,
12148,
14,
27082,
912,
859,
370,
295,
1065,
314,
2295,
1380,
1233,
4493,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
543,
63,
6242,
199,
199,
893,
26,
272,
687,
12148,
492,
3805,
272,
687,
12148,
14,
1014,
1258,
492,
15223,
27757,
272,
687,
12148,
14,
1014,
1000,
492,
3101,
3120,
272,
687,
12148,
14,
4129,
63,
1014,
1258,
492,
5870,
12807,
27757,
272,
687,
12148,
14,
27212,
492,
25584,
12,
31886,
272,
687,
12148,
492,
1851,
1974,
272,
687,
12148,
14,
1412,
492,
4804,
1412,
199,
2590,
3545,
26,
272,
327,
5723,
4621,
787,
440,
492,
461,
641,
1145,
6869,
14,
221,
14320,
83,
402,
642,
859,
272,
327,
7859,
1133,
1736,
12,
1325,
325,
14,
71,
14,
5297,
52,
1330,
1746,
436,
2446,
342,
911,
14,
272,
15223,
27757,
275,
488,
272,
3805,
275,
488,
272,
3101,
3120,
275,
488,
272,
25584,
275,
488,
272,
1851,
1974,
275,
488,
272,
5870,
12807,
27757,
275,
488,
272,
4804,
1412,
275,
488,
199,
504,
12148,
14,
793,
492,
3805,
63,
793,
12,
1145,
63,
793,
199,
504,
12148,
14,
2340,
63,
1100,
492,
2186,
4851,
2998,
199,
504,
12148,
14,
1974,
492,
746,
63,
2804,
63,
815,
12,
7116,
63,
466,
199,
646,
9143,
199,
646,
2050,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
199,
646,
2838,
199,
646,
984,
199,
199,
893,
26,
272,
687,
15073,
492,
5228,
221,
327,
1134,
18,
199,
2590,
3545,
26,
272,
687,
5890,
492,
5228,
221,
327,
1134,
19,
199,
199,
893,
26,
272,
687,
5055,
14,
3175,
492,
15042,
465,
15042,
804,
221,
327,
1134,
1276,
11,
199,
2590,
3545,
26,
272,
687,
2943,
492,
15042,
804,
199,
199,
3,
377,
8622,
1159,
5705,
511,
5241,
5074,
314,
4588,
2882,
859,
199,
3,
334,
22051,
1134,
1465,
11,
503,
2882,
18,
9,
880,
12148,
14,
396,
14,
1974,
655,
509,
823,
199,
3,
642,
10685,
12,
1325,
367,
1163,
4390,
402,
12148,
14,
4776,
781,
2934,
199,
3,
370,
2040,
314,
12731,
1015,
340,
15439,
396,
18,
365,
440,
2808,
14,
199,
692,
984,
14,
1023,
63,
815,
2356,
334,
19,
16095,
272,
327,
4068,
2366,
650,
12,
13667,
316,
2882,
18,
436,
2882,
334,
15768,
8868,
9,
272,
327,
3181,
1133,
17021,
370,
1736,
12,
880,
3544,
675,
2882,
14,
272,
492,
2882,
199,
2836,
26,
272,
327,
4068,
2366,
499,
12,
16602,
2882,
18,
1380,
2808,
14,
272,
862,
26,
267,
492,
2882,
18,
465,
2882,
272,
871,
3545,
26,
267,
492,
2882,
199,
199,
63,
2184,
63,
719,
275,
11630,
421,
199,
318,
664,
63,
8618,
63,
719,
837,
272,
408,
3407,
282,
334,
526,
321,
5836,
9,
9563,
1844,
1329,
14,
339,
961,
805,
1630,
440,
24197,
626,
314,
1844,
652,
2529,
365,
2808,
12,
272,
1454,
626,
282,
6779,
402,
664,
63,
8618,
63,
719,
4882,
315,
282,
2849,
2112,
372,
272,
15392,
8873,
14,
339,
2508,
5906,
447,
2126,
3645,
5398,
63,
8618,
63,
719,
3140,
12,
1314,
365,
17334,
370,
2342,
376,
9563,
1844,
14,
272,
408,
272,
2288,
485,
2184,
63,
719,
272,
1844,
275,
485,
2184,
63,
719,
272,
485,
2184,
63,
719,
275,
485,
2184,
63,
719,
435,
413,
272,
372,
1844,
421,
199,
318,
5398,
63,
8618,
63,
719,
8,
15712,
63,
719,
29,
797,
304,
272,
408,
8198,
83,
282,
1654,
2838,
370,
376,
2808,
1844,
641,
11667,
14,
339,
1803,
282,
2008,
334,
3450,
12,
1844,
680,
272,
408,
272,
359,
5096,
61,
275,
1851,
1974,
14,
3409,
63,
20517,
8,
403,
12,
283,
5967,
297,
9614,
29,
3450,
14,
5699,
63,
11367,
12,
3303,
12598,
63,
719,
29,
15712,
63,
719,
9,
272,
1844,
275,
6771,
14,
27886,
3430,
17,
61,
272,
372,
6771,
12,
1844,
421,
199,
318,
664,
63,
4146,
63,
396,
63,
2593,
837,
272,
408,
1002,
314,
2288,
2653,
4260,
367,
5316,
2295,
14,
339,
1803,
282,
2069,
12,
314,
2653,
315,
4696,
14,
339,
2508,
7445,
447,
650,
14,
17,
272,
408,
272,
862,
26,
267,
372,
2069,
8,
736,
14,
2314,
14,
362,
360,
26222,
6389,
63,
2864,
63,
8899,
1333,
272,
871,
334,
3393,
12,
3146,
304,
267,
372,
959,
421,
199,
533,
485,
774,
3767,
4590,
8,
785,
304,
272,
408,
55,
8146,
282,
511,
1083,
370,
746,
376,
1125,
340,
652,
2529,
282,
574,
14,
339,
961,
365,
27580,
1202,
370,
9696,
625,
29299,
16952,
334,
692,
282,
511,
272,
1083,
14801,
652,
1471,
675,
282,
7531,
370,
9451,
314,
4306,
395,
272,
1325,
911,
2597,
9696,
1163,
24241,
402,
372,
1338,
334,
29032,
787,
440,
272,
20513,
2552,
12,
1325,
781,
10459,
15988,
3967,
2337,
365,
949,
6954,
272,
4499,
370,
372,
282,
574,
687,
282,
511,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2306,
63,
765,
304,
267,
291,
14,
2981,
63,
765,
275,
2306,
63,
765,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
754,
275,
291,
14,
2981,
63,
765,
2031,
589,
12,
1011,
958,
9,
267,
340,
1228,
8,
1099,
12,
15042,
804,
304,
288,
746,
3146,
480,
7599,
511,
3102,
1077,
506,
16225,
543,
298,
1169,
298,
18443,
14,
4776,
14,
2268,
63,
396,
531,
267,
916,
754,
365,
440,
488,
26,
288,
746,
1722,
480,
1767,
574,
687,
511,
1083,
5525,
26,
450,
82,
2,
450,
2490,
754,
9,
339,
347,
636,
5675,
721,
277,
12,
536,
304,
267,
408,
4936,
1006,
5809,
3004,
370,
314,
3379,
1083,
14,
398,
961,
365,
11012,
367,
2005,
402,
314,
20419,
315,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
murusu/shadowsocks
|
shadowsocks/crypto/table.py
|
1044
|
8108
|
# !/usr/bin/env python
#
# Copyright 2015 clowwindy
#
# 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 absolute_import, division, print_function, \
with_statement
import string
import struct
import hashlib
__all__ = ['ciphers']
cached_tables = {}
if hasattr(string, 'maketrans'):
maketrans = string.maketrans
translate = string.translate
else:
maketrans = bytes.maketrans
translate = bytes.translate
def get_table(key):
m = hashlib.md5()
m.update(key)
s = m.digest()
a, b = struct.unpack('<QQ', s)
table = maketrans(b'', b'')
table = [table[i: i + 1] for i in range(len(table))]
for i in range(1, 1024):
table.sort(key=lambda x: int(a % (ord(x) + i)))
return table
def init_table(key):
if key not in cached_tables:
encrypt_table = b''.join(get_table(key))
decrypt_table = maketrans(encrypt_table, maketrans(b'', b''))
cached_tables[key] = [encrypt_table, decrypt_table]
return cached_tables[key]
class TableCipher(object):
def __init__(self, cipher_name, key, iv, op):
self._encrypt_table, self._decrypt_table = init_table(key)
self._op = op
def update(self, data):
if self._op:
return translate(data, self._encrypt_table)
else:
return translate(data, self._decrypt_table)
ciphers = {
'table': (0, 0, TableCipher)
}
def test_table_result():
from shadowsocks.common import ord
target1 = [
[60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181,
255, 143, 83, 247, 162, 16, 31, 209, 190, 171, 115, 65, 38, 41, 21,
245, 236, 46, 121, 62, 166, 233, 44, 154, 153, 145, 230, 49, 128, 216,
173, 29, 241, 119, 64, 229, 194, 103, 131, 110, 26, 197, 218, 59, 204,
56, 27, 34, 141, 221, 149, 239, 192, 195, 24, 155, 170, 183, 11, 254,
213, 37, 137, 226, 75, 203, 55, 19, 72, 248, 22, 129, 33, 175, 178,
10, 198, 71, 77, 36, 113, 167, 48, 2, 117, 140, 142, 66, 199, 232,
243, 32, 123, 54, 51, 82, 57, 177, 87, 251, 150, 196, 133, 5, 253,
130, 8, 184, 14, 152, 231, 3, 186, 159, 76, 89, 228, 205, 156, 96,
163, 146, 18, 91, 132, 85, 80, 109, 172, 176, 105, 13, 50, 235, 127,
0, 189, 95, 98, 136, 250, 200, 108, 179, 211, 214, 106, 168, 78, 79,
74, 210, 30, 73, 201, 151, 208, 114, 101, 174, 92, 52, 120, 240, 15,
169, 220, 182, 81, 224, 43, 185, 40, 99, 180, 17, 212, 158, 42, 90, 9,
191, 45, 6, 25, 4, 222, 67, 126, 1, 116, 124, 206, 69, 61, 7, 68, 97,
202, 63, 244, 20, 28, 58, 93, 134, 104, 144, 227, 147, 102, 118, 135,
148, 47, 238, 86, 112, 122, 70, 107, 215, 100, 139, 223, 225, 164,
237, 111, 125, 207, 160, 187, 246, 234, 161, 188, 193, 249, 252],
[151, 205, 99, 127, 201, 119, 199, 211, 122, 196, 91, 74, 12, 147, 124,
180, 21, 191, 138, 83, 217, 30, 86, 7, 70, 200, 56, 62, 218, 47, 168,
22, 107, 88, 63, 11, 95, 77, 28, 8, 188, 29, 194, 186, 38, 198, 33,
230, 98, 43, 148, 110, 177, 1, 109, 82, 61, 112, 219, 59, 0, 210, 35,
215, 50, 27, 103, 203, 212, 209, 235, 93, 84, 169, 166, 80, 130, 94,
164, 165, 142, 184, 111, 18, 2, 141, 232, 114, 6, 131, 195, 139, 176,
220, 5, 153, 135, 213, 154, 189, 238, 174, 226, 53, 222, 146, 162,
236, 158, 143, 55, 244, 233, 96, 173, 26, 206, 100, 227, 49, 178, 34,
234, 108, 207, 245, 204, 150, 44, 87, 121, 54, 140, 118, 221, 228,
155, 78, 3, 239, 101, 64, 102, 17, 223, 41, 137, 225, 229, 66, 116,
171, 125, 40, 39, 71, 134, 13, 193, 129, 247, 251, 20, 136, 242, 14,
36, 97, 163, 181, 72, 25, 144, 46, 175, 89, 145, 113, 90, 159, 190,
15, 183, 73, 123, 187, 128, 248, 252, 152, 24, 197, 68, 253, 52, 69,
117, 57, 92, 104, 157, 170, 214, 81, 60, 133, 208, 246, 172, 23, 167,
160, 192, 76, 161, 237, 45, 4, 58, 10, 182, 65, 202, 240, 185, 241,
79, 224, 132, 51, 42, 126, 105, 37, 250, 149, 32, 243, 231, 67, 179,
48, 9, 106, 216, 31, 249, 19, 85, 254, 156, 115, 255, 120, 75, 16]]
target2 = [
[124, 30, 170, 247, 27, 127, 224, 59, 13, 22, 196, 76, 72, 154, 32,
209, 4, 2, 131, 62, 101, 51, 230, 9, 166, 11, 99, 80, 208, 112, 36,
248, 81, 102, 130, 88, 218, 38, 168, 15, 241, 228, 167, 117, 158, 41,
10, 180, 194, 50, 204, 243, 246, 251, 29, 198, 219, 210, 195, 21, 54,
91, 203, 221, 70, 57, 183, 17, 147, 49, 133, 65, 77, 55, 202, 122,
162, 169, 188, 200, 190, 125, 63, 244, 96, 31, 107, 106, 74, 143, 116,
148, 78, 46, 1, 137, 150, 110, 181, 56, 95, 139, 58, 3, 231, 66, 165,
142, 242, 43, 192, 157, 89, 175, 109, 220, 128, 0, 178, 42, 255, 20,
214, 185, 83, 160, 253, 7, 23, 92, 111, 153, 26, 226, 33, 176, 144,
18, 216, 212, 28, 151, 71, 206, 222, 182, 8, 174, 205, 201, 152, 240,
155, 108, 223, 104, 239, 98, 164, 211, 184, 34, 193, 14, 114, 187, 40,
254, 12, 67, 93, 217, 6, 94, 16, 19, 82, 86, 245, 24, 197, 134, 132,
138, 229, 121, 5, 235, 238, 85, 47, 103, 113, 179, 69, 250, 45, 135,
156, 25, 61, 75, 44, 146, 189, 84, 207, 172, 119, 53, 123, 186, 120,
171, 68, 227, 145, 136, 100, 90, 48, 79, 159, 149, 39, 213, 236, 126,
52, 60, 225, 199, 105, 73, 233, 252, 118, 215, 35, 115, 64, 37, 97,
129, 161, 177, 87, 237, 141, 173, 191, 163, 140, 234, 232, 249],
[117, 94, 17, 103, 16, 186, 172, 127, 146, 23, 46, 25, 168, 8, 163, 39,
174, 67, 137, 175, 121, 59, 9, 128, 179, 199, 132, 4, 140, 54, 1, 85,
14, 134, 161, 238, 30, 241, 37, 224, 166, 45, 119, 109, 202, 196, 93,
190, 220, 69, 49, 21, 228, 209, 60, 73, 99, 65, 102, 7, 229, 200, 19,
82, 240, 71, 105, 169, 214, 194, 64, 142, 12, 233, 88, 201, 11, 72,
92, 221, 27, 32, 176, 124, 205, 189, 177, 246, 35, 112, 219, 61, 129,
170, 173, 100, 84, 242, 157, 26, 218, 20, 33, 191, 155, 232, 87, 86,
153, 114, 97, 130, 29, 192, 164, 239, 90, 43, 236, 208, 212, 185, 75,
210, 0, 81, 227, 5, 116, 243, 34, 18, 182, 70, 181, 197, 217, 95, 183,
101, 252, 248, 107, 89, 136, 216, 203, 68, 91, 223, 96, 141, 150, 131,
13, 152, 198, 111, 44, 222, 125, 244, 76, 251, 158, 106, 24, 42, 38,
77, 2, 213, 207, 249, 147, 113, 135, 245, 118, 193, 47, 98, 145, 66,
160, 123, 211, 165, 78, 204, 80, 250, 110, 162, 48, 58, 10, 180, 55,
231, 79, 149, 74, 62, 50, 148, 143, 206, 28, 15, 57, 159, 139, 225,
122, 237, 138, 171, 36, 56, 115, 63, 144, 154, 6, 230, 133, 215, 41,
184, 22, 104, 254, 234, 253, 187, 226, 247, 188, 156, 151, 40, 108,
51, 83, 178, 52, 3, 31, 255, 195, 53, 235, 126, 167, 120]]
encrypt_table = b''.join(get_table(b'foobar!'))
decrypt_table = maketrans(encrypt_table, maketrans(b'', b''))
for i in range(0, 256):
assert (target1[0][i] == ord(encrypt_table[i]))
assert (target1[1][i] == ord(decrypt_table[i]))
encrypt_table = b''.join(get_table(b'barfoo!'))
decrypt_table = maketrans(encrypt_table, maketrans(b'', b''))
for i in range(0, 256):
assert (target2[0][i] == ord(encrypt_table[i]))
assert (target2[1][i] == ord(decrypt_table[i]))
def test_encryption():
from shadowsocks.crypto import util
cipher = TableCipher('table', b'test', b'', 1)
decipher = TableCipher('table', b'test', b'', 0)
util.run_cipher(cipher, decipher)
if __name__ == '__main__':
test_table_result()
test_encryption()
|
apache-2.0
|
[
3,
8546,
15,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
1059,
199,
646,
2702,
199,
646,
8337,
421,
199,
363,
452,
363,
275,
788,
27426,
418,
199,
199,
5245,
63,
5987,
275,
1052,
199,
199,
692,
2688,
8,
875,
12,
283,
22191,
31552,
735,
272,
5475,
31552,
275,
1059,
14,
22191,
31552,
272,
9028,
275,
1059,
14,
5275,
199,
2836,
26,
272,
5475,
31552,
275,
2783,
14,
22191,
31552,
272,
9028,
275,
2783,
14,
5275,
421,
199,
318,
664,
63,
1224,
8,
498,
304,
272,
333,
275,
8337,
14,
1064,
21,
342,
272,
333,
14,
873,
8,
498,
9,
272,
308,
275,
333,
14,
5671,
342,
272,
282,
12,
330,
275,
2702,
14,
5301,
4827,
12917,
297,
308,
9,
272,
1817,
275,
5475,
31552,
8,
66,
6448,
330,
17483,
272,
1817,
275,
359,
1224,
59,
73,
26,
284,
435,
413,
61,
367,
284,
315,
1425,
8,
552,
8,
1224,
10524,
272,
367,
284,
315,
1425,
8,
17,
12,
6619,
304,
267,
1817,
14,
3191,
8,
498,
29,
2734,
671,
26,
1109,
8,
65,
450,
334,
2181,
8,
88,
9,
435,
284,
1724,
272,
372,
1817,
421,
199,
318,
4205,
63,
1224,
8,
498,
304,
272,
340,
790,
440,
315,
6328,
63,
5987,
26,
267,
14645,
63,
1224,
275,
330,
17067,
904,
8,
362,
63,
1224,
8,
498,
430,
267,
20090,
63,
1224,
275,
5475,
31552,
8,
11929,
63,
1224,
12,
5475,
31552,
8,
66,
6448,
330,
7,
1333,
267,
6328,
63,
5987,
59,
498,
61,
275,
359,
11929,
63,
1224,
12,
20090,
63,
1224,
61,
272,
372,
6328,
63,
5987,
59,
498,
61,
421,
199,
533,
6957,
21967,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
10830,
63,
354,
12,
790,
12,
18831,
12,
1687,
304,
267,
291,
423,
11929,
63,
1224,
12,
291,
423,
15682,
63,
1224,
275,
4205,
63,
1224,
8,
498,
9,
267,
291,
423,
411,
275,
1687,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
340,
291,
423,
411,
26,
288,
372,
9028,
8,
576,
12,
291,
423,
11929,
63,
1224,
9,
267,
587,
26,
288,
372,
9028,
8,
576,
12,
291,
423,
15682,
63,
1224,
9,
421,
199,
27426,
275,
469,
272,
283,
1224,
356,
334,
16,
12,
378,
12,
6957,
21967,
9,
199,
93,
421,
199,
318,
511,
63,
1224,
63,
1099,
837,
272,
687,
15084,
21234,
14,
2330,
492,
6206,
272,
1347,
17,
275,
359,
267,
359,
2259,
12,
13564,
12,
8264,
12,
26309,
12,
499,
1196,
12,
18729,
12,
10523,
12,
6546,
12,
10551,
12,
499,
2260,
12,
499,
1167,
12,
8685,
12,
3144,
12,
32400,
12,
31852,
12,
413,
2835,
12,
268,
5450,
12,
29235,
12,
20582,
12,
499,
2417,
12,
32729,
12,
3193,
12,
7105,
12,
499,
1643,
12,
29682,
12,
413,
3172,
12,
22560,
12,
11738,
12,
10448,
12,
13385,
12,
7829,
12,
268,
32102,
12,
499,
1344,
12,
12426,
12,
26228,
12,
16202,
12,
29923,
12,
499,
1153,
12,
10868,
12,
31693,
12,
25828,
12,
28818,
12,
28700,
12,
12260,
12,
7960,
12,
30630,
12,
268,
413,
2898,
12,
7349,
12,
499,
2953,
12,
26497,
12,
5049,
12,
499,
1398,
12,
413,
2635,
12,
22363,
12,
30542,
12,
16814,
12,
7875,
12,
413,
2576,
12,
32319,
12,
8155,
12,
14785,
12,
268,
12001,
12,
8087,
12,
8177,
12,
413,
2953,
12,
499,
2025,
12,
28528,
12,
499,
1355,
12,
13567,
12,
413,
2720,
12,
5504,
12,
29710,
12,
27209,
12,
413,
2658,
12,
4119,
12,
22540,
12,
268,
499,
969,
12,
6877,
12,
27750,
12,
32584,
12,
13098,
12,
29202,
12,
12766,
12,
5851,
12,
15323,
12,
499,
2006,
12,
6928,
12,
25454,
12,
9404,
12,
27306,
12,
413,
2277,
12,
268,
1616,
12,
413,
2905,
12,
17245,
12,
8375,
12,
8780,
12,
24073,
12,
31650,
12,
9615,
12,
499,
12,
26189,
12,
22796,
12,
31308,
12,
14157,
12,
9013,
12,
499,
708,
12,
268,
499,
2824,
12,
4337,
12,
11869,
12,
13470,
12,
8026,
12,
18051,
12,
12699,
12,
413,
1138,
12,
10513,
12,
499,
2869,
12,
14711,
12,
32132,
12,
28416,
12,
959,
12,
26727,
12,
268,
21334,
12,
1695,
12,
27631,
12,
4329,
12,
413,
2528,
12,
499,
2192,
12,
650,
12,
413,
1184,
12,
413,
1427,
12,
14646,
12,
17838,
12,
499,
1651,
12,
24005,
12,
32609,
12,
15580,
12,
268,
24619,
12,
31263,
12,
6155,
12,
21358,
12,
27207,
12,
16412,
12,
5939,
12,
24058,
12,
24911,
12,
27827,
12,
20462,
12,
4944,
12,
5238,
12,
31071,
12,
12792,
12,
268,
378,
12,
31446,
12,
16102,
12,
16096,
12,
27208,
12,
16074,
12,
1926,
12,
24579,
12,
31420,
12,
30301,
12,
21237,
12,
23746,
12,
413,
2333,
12,
14679,
12,
13734,
12,
268,
9720,
12,
26160,
12,
4233,
12,
18525,
12,
1784,
12,
413,
2869,
12,
29203,
12,
23510,
12,
14313,
12,
30698,
12,
20140,
12,
14589,
12,
13960,
12,
21883,
12,
4114,
12,
268,
20680,
12,
25647,
12,
413,
2564,
12,
19071,
12,
18565,
12,
11851,
12,
413,
2426,
12,
6335,
12,
8806,
12,
13576,
12,
5557,
12,
29532,
12,
413,
2010,
12,
5685,
12,
9137,
12,
1749,
12,
268,
413,
3328,
12,
10416,
12,
1227,
12,
5661,
12,
841,
12,
26485,
12,
13296,
12,
21572,
12,
413
] |
[
8546,
15,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
6900,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
1059,
199,
646,
2702,
199,
646,
8337,
421,
199,
363,
452,
363,
275,
788,
27426,
418,
199,
199,
5245,
63,
5987,
275,
1052,
199,
199,
692,
2688,
8,
875,
12,
283,
22191,
31552,
735,
272,
5475,
31552,
275,
1059,
14,
22191,
31552,
272,
9028,
275,
1059,
14,
5275,
199,
2836,
26,
272,
5475,
31552,
275,
2783,
14,
22191,
31552,
272,
9028,
275,
2783,
14,
5275,
421,
199,
318,
664,
63,
1224,
8,
498,
304,
272,
333,
275,
8337,
14,
1064,
21,
342,
272,
333,
14,
873,
8,
498,
9,
272,
308,
275,
333,
14,
5671,
342,
272,
282,
12,
330,
275,
2702,
14,
5301,
4827,
12917,
297,
308,
9,
272,
1817,
275,
5475,
31552,
8,
66,
6448,
330,
17483,
272,
1817,
275,
359,
1224,
59,
73,
26,
284,
435,
413,
61,
367,
284,
315,
1425,
8,
552,
8,
1224,
10524,
272,
367,
284,
315,
1425,
8,
17,
12,
6619,
304,
267,
1817,
14,
3191,
8,
498,
29,
2734,
671,
26,
1109,
8,
65,
450,
334,
2181,
8,
88,
9,
435,
284,
1724,
272,
372,
1817,
421,
199,
318,
4205,
63,
1224,
8,
498,
304,
272,
340,
790,
440,
315,
6328,
63,
5987,
26,
267,
14645,
63,
1224,
275,
330,
17067,
904,
8,
362,
63,
1224,
8,
498,
430,
267,
20090,
63,
1224,
275,
5475,
31552,
8,
11929,
63,
1224,
12,
5475,
31552,
8,
66,
6448,
330,
7,
1333,
267,
6328,
63,
5987,
59,
498,
61,
275,
359,
11929,
63,
1224,
12,
20090,
63,
1224,
61,
272,
372,
6328,
63,
5987,
59,
498,
61,
421,
199,
533,
6957,
21967,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
10830,
63,
354,
12,
790,
12,
18831,
12,
1687,
304,
267,
291,
423,
11929,
63,
1224,
12,
291,
423,
15682,
63,
1224,
275,
4205,
63,
1224,
8,
498,
9,
267,
291,
423,
411,
275,
1687,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
340,
291,
423,
411,
26,
288,
372,
9028,
8,
576,
12,
291,
423,
11929,
63,
1224,
9,
267,
587,
26,
288,
372,
9028,
8,
576,
12,
291,
423,
15682,
63,
1224,
9,
421,
199,
27426,
275,
469,
272,
283,
1224,
356,
334,
16,
12,
378,
12,
6957,
21967,
9,
199,
93,
421,
199,
318,
511,
63,
1224,
63,
1099,
837,
272,
687,
15084,
21234,
14,
2330,
492,
6206,
272,
1347,
17,
275,
359,
267,
359,
2259,
12,
13564,
12,
8264,
12,
26309,
12,
499,
1196,
12,
18729,
12,
10523,
12,
6546,
12,
10551,
12,
499,
2260,
12,
499,
1167,
12,
8685,
12,
3144,
12,
32400,
12,
31852,
12,
413,
2835,
12,
268,
5450,
12,
29235,
12,
20582,
12,
499,
2417,
12,
32729,
12,
3193,
12,
7105,
12,
499,
1643,
12,
29682,
12,
413,
3172,
12,
22560,
12,
11738,
12,
10448,
12,
13385,
12,
7829,
12,
268,
32102,
12,
499,
1344,
12,
12426,
12,
26228,
12,
16202,
12,
29923,
12,
499,
1153,
12,
10868,
12,
31693,
12,
25828,
12,
28818,
12,
28700,
12,
12260,
12,
7960,
12,
30630,
12,
268,
413,
2898,
12,
7349,
12,
499,
2953,
12,
26497,
12,
5049,
12,
499,
1398,
12,
413,
2635,
12,
22363,
12,
30542,
12,
16814,
12,
7875,
12,
413,
2576,
12,
32319,
12,
8155,
12,
14785,
12,
268,
12001,
12,
8087,
12,
8177,
12,
413,
2953,
12,
499,
2025,
12,
28528,
12,
499,
1355,
12,
13567,
12,
413,
2720,
12,
5504,
12,
29710,
12,
27209,
12,
413,
2658,
12,
4119,
12,
22540,
12,
268,
499,
969,
12,
6877,
12,
27750,
12,
32584,
12,
13098,
12,
29202,
12,
12766,
12,
5851,
12,
15323,
12,
499,
2006,
12,
6928,
12,
25454,
12,
9404,
12,
27306,
12,
413,
2277,
12,
268,
1616,
12,
413,
2905,
12,
17245,
12,
8375,
12,
8780,
12,
24073,
12,
31650,
12,
9615,
12,
499,
12,
26189,
12,
22796,
12,
31308,
12,
14157,
12,
9013,
12,
499,
708,
12,
268,
499,
2824,
12,
4337,
12,
11869,
12,
13470,
12,
8026,
12,
18051,
12,
12699,
12,
413,
1138,
12,
10513,
12,
499,
2869,
12,
14711,
12,
32132,
12,
28416,
12,
959,
12,
26727,
12,
268,
21334,
12,
1695,
12,
27631,
12,
4329,
12,
413,
2528,
12,
499,
2192,
12,
650,
12,
413,
1184,
12,
413,
1427,
12,
14646,
12,
17838,
12,
499,
1651,
12,
24005,
12,
32609,
12,
15580,
12,
268,
24619,
12,
31263,
12,
6155,
12,
21358,
12,
27207,
12,
16412,
12,
5939,
12,
24058,
12,
24911,
12,
27827,
12,
20462,
12,
4944,
12,
5238,
12,
31071,
12,
12792,
12,
268,
378,
12,
31446,
12,
16102,
12,
16096,
12,
27208,
12,
16074,
12,
1926,
12,
24579,
12,
31420,
12,
30301,
12,
21237,
12,
23746,
12,
413,
2333,
12,
14679,
12,
13734,
12,
268,
9720,
12,
26160,
12,
4233,
12,
18525,
12,
1784,
12,
413,
2869,
12,
29203,
12,
23510,
12,
14313,
12,
30698,
12,
20140,
12,
14589,
12,
13960,
12,
21883,
12,
4114,
12,
268,
20680,
12,
25647,
12,
413,
2564,
12,
19071,
12,
18565,
12,
11851,
12,
413,
2426,
12,
6335,
12,
8806,
12,
13576,
12,
5557,
12,
29532,
12,
413,
2010,
12,
5685,
12,
9137,
12,
1749,
12,
268,
413,
3328,
12,
10416,
12,
1227,
12,
5661,
12,
841,
12,
26485,
12,
13296,
12,
21572,
12,
413,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Eseoghene/bite-project
|
deps/gdata-python-client/tests/atom_tests/url_test.py
|
41
|
3378
|
#!/usr/bin/python
#
# Copyright (C) 2008 Google 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.
__author__ = 'j.s@google.com (Jeff Scudder)'
import unittest
import atom.url
import gdata.test_config as conf
class UrlTest(unittest.TestCase):
def testParseUrl(self):
url = atom.url.parse_url('http://www.google.com/calendar/feeds')
self.assert_(url.protocol == 'http')
self.assert_(url.port is None)
self.assert_(url.host == 'www.google.com')
self.assert_(url.path == '/calendar/feeds')
self.assert_(url.params == {})
url = atom.url.parse_url('http://example.com:6091/calendar/feeds')
self.assert_(url.protocol == 'http')
self.assert_(url.host == 'example.com')
self.assert_(url.port == '6091')
self.assert_(url.path == '/calendar/feeds')
self.assert_(url.params == {})
url = atom.url.parse_url('/calendar/feeds?foo=bar')
self.assert_(url.protocol is None)
self.assert_(url.host is None)
self.assert_(url.path == '/calendar/feeds')
self.assert_(len(url.params.keys()) == 1)
self.assert_('foo' in url.params)
self.assert_(url.params['foo'] == 'bar')
url = atom.url.parse_url('/calendar/feeds?my+foo=bar%3Dx')
self.assert_(len(url.params.keys()) == 1)
self.assert_('my foo' in url.params)
self.assert_(url.params['my foo'] == 'bar=x')
def testUrlToString(self):
url = atom.url.Url(port=80)
url.host = 'example.com'
self.assert_(str(url), '//example.com:80')
url = atom.url.Url(protocol='http', host='example.com', path='/feed')
url.params['has spaces'] = 'sneaky=values?&!'
self.assert_(url.to_string() == (
'http://example.com/feed?has+spaces=sneaky%3Dvalues%3F%26%21'))
def testGetRequestUri(self):
url = atom.url.Url(protocol='http', host='example.com', path='/feed')
url.params['has spaces'] = 'sneaky=values?&!'
self.assert_(url.get_request_uri() == (
'/feed?has+spaces=sneaky%3Dvalues%3F%26%21'))
self.assert_(url.get_param_string() == (
'has+spaces=sneaky%3Dvalues%3F%26%21'))
def testComparistons(self):
url1 = atom.url.Url(protocol='http', host='example.com', path='/feed',
params={'x':'1', 'y':'2'})
url2 = atom.url.Url(host='example.com', port=80, path='/feed',
params={'y':'2', 'x':'1'})
self.assertEquals(url1, url2)
url3 = atom.url.Url(host='example.com', port=81, path='/feed',
params={'x':'1', 'y':'2'})
self.assert_(url1 != url3)
self.assert_(url2 != url3)
url4 = atom.url.Url(protocol='ftp', host='example.com', path='/feed',
params={'x':'1', 'y':'2'})
self.assert_(url1 != url4)
self.assert_(url2 != url4)
self.assert_(url3 != url4)
def suite():
return conf.build_suite([UrlTest])
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
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,
363,
2502,
363,
275,
283,
74,
14,
83,
32,
3098,
14,
957,
334,
42,
3609,
13916,
1181,
424,
3171,
421,
199,
646,
2882,
199,
646,
6222,
14,
633,
199,
646,
11006,
14,
396,
63,
888,
465,
3743,
421,
199,
533,
20503,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
4003,
6417,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
360,
1014,
921,
1544,
14,
3098,
14,
957,
15,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
508,
283,
1014,
358,
272,
291,
14,
479,
2531,
633,
14,
719,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
1102,
508,
283,
1544,
14,
3098,
14,
957,
358,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
1162,
508,
5009,
339,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
360,
1014,
921,
2694,
14,
957,
26,
14520,
17,
15,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
508,
283,
1014,
358,
272,
291,
14,
479,
2531,
633,
14,
1102,
508,
283,
2694,
14,
957,
358,
272,
291,
14,
479,
2531,
633,
14,
719,
508,
283,
14520,
17,
358,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
1162,
508,
5009,
2286,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
2336,
8183,
15,
11522,
31,
1421,
29,
1700,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
1102,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
552,
8,
633,
14,
1162,
14,
1612,
1012,
508,
413,
9,
272,
291,
14,
479,
11252,
1421,
7,
315,
1166,
14,
1162,
9,
272,
291,
14,
479,
2531,
633,
14,
1162,
459,
1421,
418,
508,
283,
1700,
358,
2286,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
2336,
8183,
15,
11522,
31,
1662,
11,
1421,
29,
1700,
5,
19,
36,
88,
358,
272,
291,
14,
479,
2531,
552,
8,
633,
14,
1162,
14,
1612,
1012,
508,
413,
9,
272,
291,
14,
479,
11252,
1662,
3925,
7,
315,
1166,
14,
1162,
9,
272,
291,
14,
479,
2531,
633,
14,
1162,
459,
1662,
3925,
418,
508,
283,
1700,
29,
88,
358,
272,
523,
347,
511,
6417,
7756,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
6417,
8,
719,
29,
1257,
9,
272,
1166,
14,
1102,
275,
283,
2694,
14,
957,
7,
272,
291,
14,
479,
2531,
495,
8,
633,
395,
18290,
2694,
14,
957,
26,
1257,
358,
339,
1166,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
358,
272,
1166,
14,
1162,
459,
1989,
7883,
418,
275,
283,
83,
685,
1151,
89,
29,
1459,
31,
6,
11213,
272,
291,
14,
479,
2531,
633,
14,
475,
63,
875,
342,
508,
334,
267,
283,
1014,
921,
2694,
14,
957,
15,
3871,
31,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
819,
347,
19970,
2017,
14014,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
358,
272,
1166,
14,
1162,
459,
1989,
7883,
418,
275,
283,
83,
685,
1151,
89,
29,
1459,
31,
6,
11213,
272,
291,
14,
479,
2531,
633,
14,
362,
63,
1069,
63,
2302,
342,
508,
334,
267,
1994,
3871,
31,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
272,
291,
14,
479,
2531,
633,
14,
362,
63,
635,
63,
875,
342,
508,
334,
267,
283,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
819,
347,
511,
2404,
285,
631,
4654,
8,
277,
304,
272,
1166,
17,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
297,
12723,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
1166,
18,
275,
6222,
14,
633,
14,
6417,
8,
1102,
534,
2694,
14,
957,
297,
1844,
29,
1257,
12,
931,
8805,
3871,
297,
12723,
1862,
3713,
89,
5242,
18,
297,
283,
88,
5242,
17,
3071,
272,
291,
14,
2947,
8,
633,
17,
12,
1166,
18,
9,
272,
1166,
19,
275,
6222,
14,
633,
14,
6417,
8,
1102,
534,
2694,
14,
957,
297,
1844,
29,
2835,
12,
931,
8805,
3871,
297,
12723,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
291,
14,
479,
2531,
633,
17,
1137,
1166,
19,
9,
272,
291,
14,
479,
2531,
633,
18,
1137,
1166,
19,
9,
272,
1166,
20,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
8915,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
297,
717,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
291,
14,
479,
2531,
633,
17,
1137,
1166,
20,
9,
272,
291,
14,
479,
2531,
633,
18,
1137,
1166,
20,
9,
272,
291,
14,
479,
2531,
633,
19
] |
[
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,
363,
2502,
363,
275,
283,
74,
14,
83,
32,
3098,
14,
957,
334,
42,
3609,
13916,
1181,
424,
3171,
421,
199,
646,
2882,
199,
646,
6222,
14,
633,
199,
646,
11006,
14,
396,
63,
888,
465,
3743,
421,
199,
533,
20503,
774,
8,
2796,
14,
1746,
304,
819,
347,
511,
4003,
6417,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
360,
1014,
921,
1544,
14,
3098,
14,
957,
15,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
508,
283,
1014,
358,
272,
291,
14,
479,
2531,
633,
14,
719,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
1102,
508,
283,
1544,
14,
3098,
14,
957,
358,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
1162,
508,
5009,
339,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
360,
1014,
921,
2694,
14,
957,
26,
14520,
17,
15,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
508,
283,
1014,
358,
272,
291,
14,
479,
2531,
633,
14,
1102,
508,
283,
2694,
14,
957,
358,
272,
291,
14,
479,
2531,
633,
14,
719,
508,
283,
14520,
17,
358,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
633,
14,
1162,
508,
5009,
2286,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
2336,
8183,
15,
11522,
31,
1421,
29,
1700,
358,
272,
291,
14,
479,
2531,
633,
14,
3922,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
1102,
365,
488,
9,
272,
291,
14,
479,
2531,
633,
14,
515,
508,
1994,
8183,
15,
11522,
358,
272,
291,
14,
479,
2531,
552,
8,
633,
14,
1162,
14,
1612,
1012,
508,
413,
9,
272,
291,
14,
479,
11252,
1421,
7,
315,
1166,
14,
1162,
9,
272,
291,
14,
479,
2531,
633,
14,
1162,
459,
1421,
418,
508,
283,
1700,
358,
2286,
1166,
275,
6222,
14,
633,
14,
1122,
63,
633,
2336,
8183,
15,
11522,
31,
1662,
11,
1421,
29,
1700,
5,
19,
36,
88,
358,
272,
291,
14,
479,
2531,
552,
8,
633,
14,
1162,
14,
1612,
1012,
508,
413,
9,
272,
291,
14,
479,
11252,
1662,
3925,
7,
315,
1166,
14,
1162,
9,
272,
291,
14,
479,
2531,
633,
14,
1162,
459,
1662,
3925,
418,
508,
283,
1700,
29,
88,
358,
272,
523,
347,
511,
6417,
7756,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
6417,
8,
719,
29,
1257,
9,
272,
1166,
14,
1102,
275,
283,
2694,
14,
957,
7,
272,
291,
14,
479,
2531,
495,
8,
633,
395,
18290,
2694,
14,
957,
26,
1257,
358,
339,
1166,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
358,
272,
1166,
14,
1162,
459,
1989,
7883,
418,
275,
283,
83,
685,
1151,
89,
29,
1459,
31,
6,
11213,
272,
291,
14,
479,
2531,
633,
14,
475,
63,
875,
342,
508,
334,
267,
283,
1014,
921,
2694,
14,
957,
15,
3871,
31,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
819,
347,
19970,
2017,
14014,
8,
277,
304,
272,
1166,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
358,
272,
1166,
14,
1162,
459,
1989,
7883,
418,
275,
283,
83,
685,
1151,
89,
29,
1459,
31,
6,
11213,
272,
291,
14,
479,
2531,
633,
14,
362,
63,
1069,
63,
2302,
342,
508,
334,
267,
1994,
3871,
31,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
272,
291,
14,
479,
2531,
633,
14,
362,
63,
635,
63,
875,
342,
508,
334,
267,
283,
1989,
11,
10749,
29,
83,
685,
1151,
89,
5,
19,
36,
1459,
5,
19,
38,
5,
1479,
5,
2025,
1333,
819,
347,
511,
2404,
285,
631,
4654,
8,
277,
304,
272,
1166,
17,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
1014,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
297,
12723,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
1166,
18,
275,
6222,
14,
633,
14,
6417,
8,
1102,
534,
2694,
14,
957,
297,
1844,
29,
1257,
12,
931,
8805,
3871,
297,
12723,
1862,
3713,
89,
5242,
18,
297,
283,
88,
5242,
17,
3071,
272,
291,
14,
2947,
8,
633,
17,
12,
1166,
18,
9,
272,
1166,
19,
275,
6222,
14,
633,
14,
6417,
8,
1102,
534,
2694,
14,
957,
297,
1844,
29,
2835,
12,
931,
8805,
3871,
297,
12723,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
291,
14,
479,
2531,
633,
17,
1137,
1166,
19,
9,
272,
291,
14,
479,
2531,
633,
18,
1137,
1166,
19,
9,
272,
1166,
20,
275,
6222,
14,
633,
14,
6417,
8,
3922,
534,
8915,
297,
1591,
534,
2694,
14,
957,
297,
931,
8805,
3871,
297,
717,
1862,
3713,
88,
5242,
17,
297,
283,
89,
5242,
18,
3071,
272,
291,
14,
479,
2531,
633,
17,
1137,
1166,
20,
9,
272,
291,
14,
479,
2531,
633,
18,
1137,
1166,
20,
9,
272,
291,
14,
479,
2531,
633,
19,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
gmm001/android_kernel_zte_nx503a-1
|
scripts/rt-tester/rt-tester.py
|
11005
|
5307
|
#!/usr/bin/python
#
# rt-mutex tester
#
# (C) 2006 Thomas Gleixner <tglx@linutronix.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
import os
import sys
import getopt
import shutil
import string
# Globals
quiet = 0
test = 0
comments = 0
sysfsprefix = "/sys/devices/system/rttest/rttest"
statusfile = "/status"
commandfile = "/command"
# Command opcodes
cmd_opcodes = {
"schedother" : "1",
"schedfifo" : "2",
"lock" : "3",
"locknowait" : "4",
"lockint" : "5",
"lockintnowait" : "6",
"lockcont" : "7",
"unlock" : "8",
"signal" : "11",
"resetevent" : "98",
"reset" : "99",
}
test_opcodes = {
"prioeq" : ["P" , "eq" , None],
"priolt" : ["P" , "lt" , None],
"priogt" : ["P" , "gt" , None],
"nprioeq" : ["N" , "eq" , None],
"npriolt" : ["N" , "lt" , None],
"npriogt" : ["N" , "gt" , None],
"unlocked" : ["M" , "eq" , 0],
"trylock" : ["M" , "eq" , 1],
"blocked" : ["M" , "eq" , 2],
"blockedwake" : ["M" , "eq" , 3],
"locked" : ["M" , "eq" , 4],
"opcodeeq" : ["O" , "eq" , None],
"opcodelt" : ["O" , "lt" , None],
"opcodegt" : ["O" , "gt" , None],
"eventeq" : ["E" , "eq" , None],
"eventlt" : ["E" , "lt" , None],
"eventgt" : ["E" , "gt" , None],
}
# Print usage information
def usage():
print "rt-tester.py <-c -h -q -t> <testfile>"
print " -c display comments after first command"
print " -h help"
print " -q quiet mode"
print " -t test mode (syntax check)"
print " testfile: read test specification from testfile"
print " otherwise from stdin"
return
# Print progress when not in quiet mode
def progress(str):
if not quiet:
print str
# Analyse a status value
def analyse(val, top, arg):
intval = int(val)
if top[0] == "M":
intval = intval / (10 ** int(arg))
intval = intval % 10
argval = top[2]
elif top[0] == "O":
argval = int(cmd_opcodes.get(arg, arg))
else:
argval = int(arg)
# progress("%d %s %d" %(intval, top[1], argval))
if top[1] == "eq" and intval == argval:
return 1
if top[1] == "lt" and intval < argval:
return 1
if top[1] == "gt" and intval > argval:
return 1
return 0
# Parse the commandline
try:
(options, arguments) = getopt.getopt(sys.argv[1:],'chqt')
except getopt.GetoptError, ex:
usage()
sys.exit(1)
# Parse commandline options
for option, value in options:
if option == "-c":
comments = 1
elif option == "-q":
quiet = 1
elif option == "-t":
test = 1
elif option == '-h':
usage()
sys.exit(0)
# Select the input source
if arguments:
try:
fd = open(arguments[0])
except Exception,ex:
sys.stderr.write("File not found %s\n" %(arguments[0]))
sys.exit(1)
else:
fd = sys.stdin
linenr = 0
# Read the test patterns
while 1:
linenr = linenr + 1
line = fd.readline()
if not len(line):
break
line = line.strip()
parts = line.split(":")
if not parts or len(parts) < 1:
continue
if len(parts[0]) == 0:
continue
if parts[0].startswith("#"):
if comments > 1:
progress(line)
continue
if comments == 1:
comments = 2
progress(line)
cmd = parts[0].strip().lower()
opc = parts[1].strip().lower()
tid = parts[2].strip()
dat = parts[3].strip()
try:
# Test or wait for a status value
if cmd == "t" or cmd == "w":
testop = test_opcodes[opc]
fname = "%s%s%s" %(sysfsprefix, tid, statusfile)
if test:
print fname
continue
while 1:
query = 1
fsta = open(fname, 'r')
status = fsta.readline().strip()
fsta.close()
stat = status.split(",")
for s in stat:
s = s.strip()
if s.startswith(testop[0]):
# Separate status value
val = s[2:].strip()
query = analyse(val, testop, dat)
break
if query or cmd == "t":
break
progress(" " + status)
if not query:
sys.stderr.write("Test failed in line %d\n" %(linenr))
sys.exit(1)
# Issue a command to the tester
elif cmd == "c":
cmdnr = cmd_opcodes[opc]
# Build command string and sys filename
cmdstr = "%s:%s" %(cmdnr, dat)
fname = "%s%s%s" %(sysfsprefix, tid, commandfile)
if test:
print fname
continue
fcmd = open(fname, 'w')
fcmd.write(cmdstr)
fcmd.close()
except Exception,ex:
sys.stderr.write(str(ex))
sys.stderr.write("\nSyntax error in line %d\n" %(linenr))
if not test:
fd.close()
sys.exit(1)
# Normal exit pass
print "Pass"
sys.exit(0)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
14059,
13,
19078,
17570,
199,
3,
199,
3,
334,
35,
9,
8315,
27864,
598,
274,
1148,
1372,
665,
84,
18660,
32,
472,
5373,
1148,
14,
271,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
499,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
646,
747,
199,
646,
984,
199,
646,
12733,
199,
646,
5145,
199,
646,
1059,
199,
199,
3,
13641,
83,
199,
10243,
275,
378,
199,
396,
275,
378,
199,
6223,
275,
378,
199,
199,
1274,
2319,
1861,
275,
3286,
1274,
15,
6410,
15,
2253,
15,
2591,
396,
15,
2591,
396,
2,
199,
1205,
493,
275,
3286,
1205,
2,
199,
1531,
493,
275,
3286,
1531,
2,
199,
199,
3,
5817,
27388,
199,
1760,
63,
22022,
275,
469,
272,
298,
10487,
1848,
2,
259,
520,
298,
17,
401,
272,
298,
10487,
22976,
2,
258,
520,
298,
18,
401,
272,
298,
831,
2,
3515,
520,
298,
19,
401,
272,
298,
831,
20870,
2,
259,
520,
298,
20,
401,
272,
298,
831,
442,
2,
755,
520,
298,
21,
401,
272,
298,
831,
442,
20870,
2,
520,
298,
22,
401,
272,
298,
831,
11096,
2,
420,
520,
298,
23,
401,
272,
298,
17966,
2,
263,
520,
298,
24,
401,
272,
298,
4653,
2,
263,
520,
298,
845,
401,
272,
298,
264,
30563,
782,
2,
259,
520,
298,
2905,
401,
272,
298,
3958,
2,
260,
520,
298,
1020,
401,
272,
789,
199,
199,
396,
63,
22022,
275,
469,
272,
298,
20572,
4077,
2,
263,
520,
2097,
48,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1359,
28934,
2,
263,
520,
2097,
48,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1359,
974,
84,
2,
263,
520,
2097,
48,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
78,
20572,
4077,
2,
755,
520,
2097,
46,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
78,
1359,
28934,
2,
755,
520,
2097,
46,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
78,
1359,
974,
84,
2,
755,
520,
2097,
46,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
32489,
2,
420,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
378,
467,
272,
298,
893,
831,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
413,
467,
272,
298,
17726,
2,
755,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
499,
467,
272,
298,
17726,
15181,
2,
257,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
650,
467,
272,
298,
9325,
2,
263,
520,
2097,
45,
2,
2360,
298,
4077,
2,
2360,
841,
467,
272,
298,
14325,
4077,
2,
420,
520,
2097,
47,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
14325,
4116,
2,
420,
520,
2097,
47,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
14325,
3308,
2,
420,
520,
2097,
47,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
298,
12056,
266,
81,
2,
755,
520,
2097,
37,
2,
2360,
298,
4077,
2,
2360,
488,
467,
272,
298,
1430,
4116,
2,
755,
520,
2097,
37,
2,
2360,
298,
4116,
2,
2360,
488,
467,
272,
298,
1430,
3308,
2,
755,
520,
2097,
37,
2,
2360,
298,
3308,
2,
2360,
488,
467,
272,
789,
199,
199,
3,
9101,
4503,
2556,
199,
318,
4503,
837,
272,
870,
298,
2591,
13,
8234,
14,
647,
25549,
67,
446,
72,
446,
81,
446,
84,
30,
665,
21091,
4335,
272,
870,
298,
446,
67,
259,
2929,
6786,
2410,
1642,
1414,
2,
272,
870,
298,
446,
72,
259,
1720,
2,
272,
870,
298,
446,
81,
259,
11971,
818,
2,
272,
870,
298,
446,
84,
259,
511,
818,
334,
7093,
1104,
2924,
272,
870,
298,
30530,
26,
1586,
511,
8929,
687,
30530,
2,
272,
870,
298,
4257,
687,
9009,
2,
272,
372,
199,
199,
3,
9101,
6696,
1380,
440,
315,
11971,
818,
199,
318,
6696,
8,
495,
304,
272,
340,
440,
11971,
26,
267,
870,
620,
199,
199,
3,
14279,
261,
282,
2004,
574,
199,
318,
21297,
8,
637,
12,
2746,
12,
1680,
304,
339,
26111,
275,
1109,
8,
637,
9,
339,
340,
2746,
59,
16,
61,
508,
298,
45,
582,
267,
26111,
275,
26111,
1182,
334,
709,
1011,
1109,
8,
1273,
430,
199,
198,
442,
637,
275,
26111,
450,
1616,
267,
27610,
275,
2746,
59,
18,
61,
272,
916,
2746,
59,
16,
61,
508,
298,
47,
582,
267,
27610,
275,
1109,
8,
1760,
63,
22022,
14,
362,
8,
1273,
12,
1680,
430,
272,
587,
26,
267,
27610,
275,
1109,
8,
1273,
9,
339,
327,
6696,
3647,
68,
450,
83,
450,
68,
2,
2818,
442,
637,
12,
2746,
59,
17,
467,
27610,
430,
339,
340,
2746,
59,
17,
61,
508,
298,
4077,
2,
436,
26111,
508,
27610,
26,
199,
198,
1107,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
4116,
2,
436,
26111,
665,
27610,
26,
267,
372,
413,
272,
340,
2746,
59,
17,
61,
508,
298,
3308,
2,
436,
26111,
690,
27610,
26,
199,
198,
1107,
413,
272,
372,
378,
199,
199,
3,
6077,
314,
28279,
199,
893,
26,
272,
334,
1419,
12,
2368,
9,
275,
12733,
14,
18907,
8,
1274,
14,
3020,
59,
17,
8429,
7,
335,
8440,
358,
199,
2590,
12733,
14,
1002,
29368,
12,
444,
26,
272,
4503,
342,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
3,
6077,
28279,
1511,
199,
509,
945,
12,
574,
315,
1511,
26,
272,
340,
945,
508,
3905,
67,
582,
267,
6786,
275,
413,
272,
916,
945,
508,
3905,
81,
582,
267,
11971,
275,
413,
272,
916,
945,
508,
3905,
84,
582,
267,
511,
275,
413,
272,
916,
945,
508,
2475,
72,
356,
267,
4503,
342,
267,
984,
14,
2224,
8,
16,
9,
199,
199,
3,
9496,
314,
1324,
1350,
199,
692,
2368,
26,
272,
862,
26,
267,
6111,
275,
1551,
8,
4958,
59,
16,
566,
272,
871,
2186,
12,
476,
26,
267,
984,
14,
3083,
14,
952,
480,
1173,
440,
1911,
450,
83,
60,
78,
2,
2818,
4958,
59,
16,
2459,
267,
984,
14,
2224,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tvotyakov/codeeval
|
easy/beautiful-strings/code.py
|
1
|
1499
|
#!python3
def max_beauty_of_string(in_str):
'''(string) -> int
Calculates maximum beauty of the in_str string.
The beauty of the string is the sum of the beauty of the
letters in it. The beauty of each letter is an integer
between 1 and 26, inclusive, and no two letters have the
same beauty.
>>> max_beauty_of_string('ABbCcc')
152
>>> max_beauty_of_string('Good luck in the Facebook Hacker Cup this year!')
754
>>> max_beauty_of_string('Ignore punctuation, please :)')
491
>>> max_beauty_of_string('Sometimes test cases are hard to make up.')
729
>>> max_beauty_of_string('So I just go consult Professor Dalves')
646
'''
normal_string = in_str.upper()
letters = set(ch for ch in normal_string if ch.isalpha())
letter_count_map = list((letter, normal_string.count(letter))
for letter in letters)
letter_count_map.sort(key=lambda t: t[1], reverse = True)
return sum(map(lambda t: t[0][1] * t[1],
zip(letter_count_map, range(26, 0, -1))))
if __name__ == '__main__':
import sys
if (len(sys.argv) <= 1):
import doctest
doctest.testmod()
else:
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
test = test.rstrip('\n')
if not test: continue # ignore an empty line
print(max_beauty_of_string(test))
test_cases.close()
|
gpl-2.0
|
[
3168,
1548,
19,
202,
199,
318,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
8,
262,
63,
495,
304,
1128,
1449,
8,
875,
9,
1035,
1109,
2958,
28562,
5696,
506,
6898,
89,
402,
314,
315,
63,
495,
1059,
14,
1128,
710,
506,
6898,
89,
402,
314,
1059,
365,
314,
3089,
402,
314,
506,
6898,
89,
402,
314,
1128,
14435,
315,
652,
14,
710,
506,
6898,
89,
402,
1924,
8082,
365,
376,
3000,
1128,
3382,
413,
436,
7875,
12,
20728,
12,
436,
949,
2877,
14435,
1172,
314,
1128,
2011,
506,
6898,
89,
14,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
1217,
66,
35,
2055,
358,
1128,
413,
2528,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
20652,
634,
10112,
315,
314,
27107,
30802,
281,
445,
384,
642,
5361,
10916,
1128,
1520,
1477,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
9495,
22929,
12,
8749,
520,
5942,
1128,
841,
3328,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
7700,
4508,
511,
5560,
787,
7508,
370,
1852,
1536,
2659,
1128,
1520,
1398,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
5158,
473,
2951,
2621,
13447,
427,
2165,
771,
385,
269,
577,
279,
2310,
358,
1128,
5049,
22,
1128,
1449,
1128,
3293,
63,
875,
275,
315,
63,
495,
14,
4142,
342,
1128,
14435,
275,
663,
8,
335,
367,
682,
315,
3293,
63,
875,
340,
682,
14,
374,
4468,
1012,
1128,
8082,
63,
835,
63,
1130,
275,
769,
1332,
9269,
12,
3293,
63,
875,
14,
835,
8,
9269,
430,
15372,
367,
8082,
315,
14435,
9,
1128,
8082,
63,
835,
63,
1130,
14,
3191,
8,
498,
29,
2734,
307,
26,
307,
59,
17,
467,
3837,
275,
715,
9,
1128,
372,
3089,
8,
1130,
8,
2734,
307,
26,
307,
59,
16,
1527,
17,
61,
627,
307,
59,
17,
467,
202,
673,
3482,
8,
9269,
63,
835,
63,
1130,
12,
1425,
8,
1479,
12,
378,
12,
446,
17,
7845,
2999,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
1128,
492,
984,
1128,
340,
334,
552,
8,
1274,
14,
3020,
9,
2695,
413,
304,
1039,
492,
8868,
1039,
8868,
14,
29446,
342,
1128,
587,
26,
1039,
511,
63,
9403,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
358,
1039,
367,
511,
315,
511,
63,
9403,
26,
1675,
511,
275,
511,
14,
6735,
2258,
78,
358,
1675,
340,
440,
511,
26,
1980,
327,
3686,
376,
2701,
1004,
1675,
870,
8,
988,
63,
1235,
6898,
89,
63,
1618,
63,
875,
8,
396,
430,
4341,
511,
63,
9403,
14,
1600,
342,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1548,
19,
202,
199,
318,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
8,
262,
63,
495,
304,
1128,
1449,
8,
875,
9,
1035,
1109,
2958,
28562,
5696,
506,
6898,
89,
402,
314,
315,
63,
495,
1059,
14,
1128,
710,
506,
6898,
89,
402,
314,
1059,
365,
314,
3089,
402,
314,
506,
6898,
89,
402,
314,
1128,
14435,
315,
652,
14,
710,
506,
6898,
89,
402,
1924,
8082,
365,
376,
3000,
1128,
3382,
413,
436,
7875,
12,
20728,
12,
436,
949,
2877,
14435,
1172,
314,
1128,
2011,
506,
6898,
89,
14,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
1217,
66,
35,
2055,
358,
1128,
413,
2528,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
20652,
634,
10112,
315,
314,
27107,
30802,
281,
445,
384,
642,
5361,
10916,
1128,
1520,
1477,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
9495,
22929,
12,
8749,
520,
5942,
1128,
841,
3328,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
7700,
4508,
511,
5560,
787,
7508,
370,
1852,
1536,
2659,
1128,
1520,
1398,
2958,
1306,
1390,
63,
1235,
6898,
89,
63,
1618,
63,
875,
360,
5158,
473,
2951,
2621,
13447,
427,
2165,
771,
385,
269,
577,
279,
2310,
358,
1128,
5049,
22,
1128,
1449,
1128,
3293,
63,
875,
275,
315,
63,
495,
14,
4142,
342,
1128,
14435,
275,
663,
8,
335,
367,
682,
315,
3293,
63,
875,
340,
682,
14,
374,
4468,
1012,
1128,
8082,
63,
835,
63,
1130,
275,
769,
1332,
9269,
12,
3293,
63,
875,
14,
835,
8,
9269,
430,
15372,
367,
8082,
315,
14435,
9,
1128,
8082,
63,
835,
63,
1130,
14,
3191,
8,
498,
29,
2734,
307,
26,
307,
59,
17,
467,
3837,
275,
715,
9,
1128,
372,
3089,
8,
1130,
8,
2734,
307,
26,
307,
59,
16,
1527,
17,
61,
627,
307,
59,
17,
467,
202,
673,
3482,
8,
9269,
63,
835,
63,
1130,
12,
1425,
8,
1479,
12,
378,
12,
446,
17,
7845,
2999,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
1128,
492,
984,
1128,
340,
334,
552,
8,
1274,
14,
3020,
9,
2695,
413,
304,
1039,
492,
8868,
1039,
8868,
14,
29446,
342,
1128,
587,
26,
1039,
511,
63,
9403,
275,
1551,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
358,
1039,
367,
511,
315,
511,
63,
9403,
26,
1675,
511,
275,
511,
14,
6735,
2258,
78,
358,
1675,
340,
440,
511,
26,
1980,
327,
3686,
376,
2701,
1004,
1675,
870,
8,
988,
63,
1235,
6898,
89,
63,
1618,
63,
875,
8,
396,
430,
4341,
511,
63,
9403,
14,
1600,
342,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
domyam97/airlights
|
slack/venv/lib/python2.7/site-packages/chardet/sbcsgroupprober.py
|
273
|
3546
|
######################## 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
from .langturkishmodel import Latin5TurkishModel
class SBCSGroupProber(CharSetGroupProber):
def __init__(self):
super(SBCSGroupProber, self).__init__()
self.probers = [
SingleByteCharSetProber(Win1251CyrillicModel),
SingleByteCharSetProber(Koi8rModel),
SingleByteCharSetProber(Latin5CyrillicModel),
SingleByteCharSetProber(MacCyrillicModel),
SingleByteCharSetProber(Ibm866Model),
SingleByteCharSetProber(Ibm855Model),
SingleByteCharSetProber(Latin7GreekModel),
SingleByteCharSetProber(Win1253GreekModel),
SingleByteCharSetProber(Latin5BulgarianModel),
SingleByteCharSetProber(Win1251BulgarianModel),
# TODO: Restore Hungarian encodings (iso-8859-2 and windows-1250)
# after we retrain model.
# SingleByteCharSetProber(Latin2HungarianModel),
# SingleByteCharSetProber(Win1250HungarianModel),
SingleByteCharSetProber(TIS620ThaiModel),
SingleByteCharSetProber(Latin5TurkishModel),
]
hebrew_prober = HebrewProber()
logical_hebrew_prober = SingleByteCharSetProber(Win1255HebrewModel,
False, hebrew_prober)
visual_hebrew_prober = SingleByteCharSetProber(Win1255HebrewModel, True,
hebrew_prober)
hebrew_prober.set_model_probers(logical_hebrew_prober, visual_hebrew_prober)
self.probers.extend([hebrew_prober, logical_hebrew_prober,
visual_hebrew_prober])
self.reset()
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
29347,
5960,
17842,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
12521,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
257,
428,
3577,
5244,
279,
676,
446,
3379,
445,
1233,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
504,
1275,
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,
3,
687,
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,
199,
504,
1275,
4159,
16218,
75,
2453,
1238,
492,
23864,
21,
27438,
75,
2453,
1685,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
12463,
3298,
2448,
8029,
12,
291,
2843,
826,
4533,
267,
291,
14,
19903,
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,
327,
3254,
26,
22379,
869,
25364,
14134,
334,
4595,
13,
4830,
13,
18,
436,
10061,
13,
26572,
9,
288,
327,
755,
2410,
781,
295,
2834,
1402,
14,
288,
327,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
327,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
27438,
75,
2453,
1685,
395,
267,
1622,
267,
946,
15850,
63,
19903,
275,
19771,
8029,
342,
267,
11461,
63,
14557,
63,
19903,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
9144,
756,
12,
946,
15850,
63,
19903,
9,
267,
13104,
63,
14557,
63,
19903,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
10940,
946,
15850,
63,
19903,
9,
267,
946,
15850,
63,
19903,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
63,
14557,
63,
19903,
12,
13104,
63,
14557,
63,
19903,
9,
267,
291,
14,
19903,
83,
14,
2880,
779,
14557,
63,
19903,
12,
11461,
63,
14557,
63,
19903,
12,
2490,
13104,
63,
14557,
63,
19903,
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
] |
[
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,
3,
687,
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,
199,
504,
1275,
4159,
16218,
75,
2453,
1238,
492,
23864,
21,
27438,
75,
2453,
1685,
421,
199,
533,
26811,
3298,
2448,
8029,
8,
1610,
1084,
2448,
8029,
304,
272,
347,
636,
826,
721,
277,
304,
267,
1613,
8,
12463,
3298,
2448,
8029,
12,
291,
2843,
826,
4533,
267,
291,
14,
19903,
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,
327,
3254,
26,
22379,
869,
25364,
14134,
334,
4595,
13,
4830,
13,
18,
436,
10061,
13,
26572,
9,
288,
327,
755,
2410,
781,
295,
2834,
1402,
14,
288,
327,
13050,
21312,
8,
27317,
18,
40,
25364,
1685,
395,
288,
327,
13050,
21312,
8,
8886,
26572,
40,
25364,
1685,
395,
288,
13050,
21312,
8,
52,
1311,
22085,
52,
17945,
1685,
395,
288,
13050,
21312,
8,
27317,
21,
27438,
75,
2453,
1685,
395,
267,
1622,
267,
946,
15850,
63,
19903,
275,
19771,
8029,
342,
267,
11461,
63,
14557,
63,
19903,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
9144,
756,
12,
946,
15850,
63,
19903,
9,
267,
13104,
63,
14557,
63,
19903,
275,
13050,
21312,
8,
8886,
20197,
1966,
15850,
1685,
12,
715,
12,
10940,
946,
15850,
63,
19903,
9,
267,
946,
15850,
63,
19903,
14,
409,
63,
1238,
63,
19903,
83,
8,
7954,
63,
14557,
63,
19903,
12,
13104,
63,
14557,
63,
19903,
9,
267,
291,
14,
19903,
83,
14,
2880,
779,
14557,
63,
19903,
12,
11461,
63,
14557,
63,
19903,
12,
2490,
13104,
63,
14557,
63,
19903,
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,
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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
] |
waseem18/oh-mainline
|
vendor/packages/kombu/docs/_ext/literals_to_xrefs.py
|
29
|
4801
|
"""
Runs through a reST file looking for old-style literals, and helps replace them
with new-style references.
"""
import re
import sys
import shelve
try:
input = input
except NameError:
input = raw_input # noqa
refre = re.compile(r'``([^`\s]+?)``')
ROLES = (
'attr',
'class',
"djadmin",
'data',
'exc',
'file',
'func',
'lookup',
'meth',
'mod',
"djadminopt",
"ref",
"setting",
"term",
"tfilter",
"ttag",
# special
"skip",
)
ALWAYS_SKIP = [
"NULL",
"True",
"False",
]
def fixliterals(fname):
data = open(fname).read()
last = 0
new = []
storage = shelve.open("/tmp/literals_to_xref.shelve")
lastvalues = storage.get("lastvalues", {})
for m in refre.finditer(data):
new.append(data[last:m.start()])
last = m.end()
line_start = data.rfind("\n", 0, m.start())
line_end = data.find("\n", m.end())
prev_start = data.rfind("\n", 0, line_start)
next_end = data.find("\n", line_end + 1)
# Skip always-skip stuff
if m.group(1) in ALWAYS_SKIP:
new.append(m.group(0))
continue
# skip when the next line is a title
next_line = data[m.end():next_end].strip()
if next_line[0] in "!-/:-@[-`{-~" and \
all(c == next_line[0] for c in next_line):
new.append(m.group(0))
continue
sys.stdout.write("\n" + "-" * 80 + "\n")
sys.stdout.write(data[prev_start + 1:m.start()])
sys.stdout.write(colorize(m.group(0), fg="red"))
sys.stdout.write(data[m.end():next_end])
sys.stdout.write("\n\n")
replace_type = None
while replace_type is None:
replace_type = input(
colorize("Replace role: ", fg="yellow")).strip().lower()
if replace_type and replace_type not in ROLES:
replace_type = None
if replace_type == "":
new.append(m.group(0))
continue
if replace_type == "skip":
new.append(m.group(0))
ALWAYS_SKIP.append(m.group(1))
continue
default = lastvalues.get(m.group(1), m.group(1))
if default.endswith("()") and \
replace_type in ("class", "func", "meth"):
default = default[:-2]
replace_value = input(
colorize("Text <target> [", fg="yellow") +
default +
colorize("]: ", fg="yellow"),
).strip()
if not replace_value:
replace_value = default
new.append(":%s:`%s`" % (replace_type, replace_value))
lastvalues[m.group(1)] = replace_value
new.append(data[last:])
open(fname, "w").write("".join(new))
storage["lastvalues"] = lastvalues
storage.close()
def colorize(text='', opts=(), **kwargs):
"""
Returns your text, enclosed in ANSI graphics codes.
Depends on the keyword arguments 'fg' and 'bg', and the contents of
the opts tuple/list.
Returns the RESET code if no parameters are given.
Valid colors:
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'
Valid options:
'bold'
'underscore'
'blink'
'reverse'
'conceal'
'noreset' - string will not be auto-terminated with the RESET code
Examples:
colorize('hello', fg='red', bg='blue', opts=('blink',))
colorize()
colorize('goodbye', opts=('underscore',))
print colorize('first line', fg='red', opts=('noreset',))
print 'this should be red too'
print colorize('and so should this')
print 'this should not be red'
"""
color_names = ('black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white')
foreground = dict([(color_names[x], '3%s' % x) for x in range(8)])
background = dict([(color_names[x], '4%s' % x) for x in range(8)])
RESET = '0'
opt_dict = {'bold': '1',
'underscore': '4',
'blink': '5',
'reverse': '7',
'conceal': '8'}
text = str(text)
code_list = []
if text == '' and len(opts) == 1 and opts[0] == 'reset':
return '\x1b[%sm' % RESET
for k, v in kwargs.iteritems():
if k == 'fg':
code_list.append(foreground[v])
elif k == 'bg':
code_list.append(background[v])
for o in opts:
if o in opt_dict:
code_list.append(opt_dict[o])
if 'noreset' not in opts:
text = text + '\x1b[%sm' % RESET
return ('\x1b[%sm' % ';'.join(code_list)) + text
if __name__ == '__main__':
try:
fixliterals(sys.argv[1])
except (KeyboardInterrupt, SystemExit):
print
|
agpl-3.0
|
[
624,
199,
16291,
4012,
282,
20883,
570,
10023,
367,
2269,
13,
2487,
18041,
12,
436,
22577,
3350,
3062,
199,
1045,
892,
13,
2487,
6941,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
1033,
15320,
199,
199,
893,
26,
272,
1324,
275,
1324,
199,
2590,
12746,
26,
272,
1324,
275,
3066,
63,
1210,
221,
327,
8151,
199,
199,
1121,
264,
275,
295,
14,
2014,
8,
82,
14700,
7059,
25502,
83,
2807,
31,
9719,
358,
199,
199,
6245,
654,
275,
334,
272,
283,
962,
297,
272,
283,
533,
297,
272,
298,
18256,
2113,
401,
272,
283,
576,
297,
272,
283,
2804,
297,
272,
283,
493,
297,
272,
283,
1532,
297,
272,
283,
3892,
297,
272,
283,
5247,
297,
272,
283,
1494,
297,
272,
298,
18256,
2113,
2992,
401,
272,
298,
1121,
401,
272,
298,
6031,
401,
272,
298,
5125,
401,
272,
298,
84,
1541,
401,
272,
298,
84,
1450,
401,
339,
327,
4539,
272,
298,
2759,
401,
199,
9,
199,
199,
32509,
63,
13525,
275,
359,
272,
298,
8084,
401,
272,
298,
549,
401,
272,
298,
797,
401,
199,
61,
421,
199,
318,
5325,
5955,
8,
5252,
304,
272,
666,
275,
1551,
8,
5252,
680,
739,
342,
339,
2061,
275,
378,
272,
892,
275,
942,
272,
4887,
275,
1033,
15320,
14,
1490,
4769,
2791,
15,
5955,
63,
475,
63,
31332,
14,
609,
15320,
531,
272,
2061,
1459,
275,
4887,
14,
362,
480,
2019,
1459,
401,
5009,
339,
367,
333,
315,
2984,
264,
14,
19373,
8,
576,
304,
398,
892,
14,
740,
8,
576,
59,
2019,
26,
77,
14,
928,
9383,
267,
2061,
275,
333,
14,
500,
342,
398,
1004,
63,
928,
275,
666,
14,
14542,
4582,
78,
401,
378,
12,
333,
14,
928,
1012,
267,
1004,
63,
500,
275,
666,
14,
1623,
4582,
78,
401,
333,
14,
500,
1012,
267,
5071,
63,
928,
275,
666,
14,
14542,
4582,
78,
401,
378,
12,
1004,
63,
928,
9,
267,
2163,
63,
500,
275,
666,
14,
1623,
4582,
78,
401,
1004,
63,
500,
435,
413,
9,
398,
327,
8232,
3544,
13,
2759,
8292,
267,
340,
333,
14,
923,
8,
17,
9,
315,
12112,
26194,
63,
13525,
26,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
327,
3372,
1380,
314,
2163,
1004,
365,
282,
2538,
267,
2163,
63,
604,
275,
666,
59,
77,
14,
500,
837,
2184,
63,
500,
1055,
1913,
342,
267,
340,
2163,
63,
604,
59,
16,
61,
315,
19724,
13,
15,
6809,
32,
1988,
64,
91,
13,
94,
2,
436,
971,
355,
1006,
8,
67,
508,
2163,
63,
604,
59,
16,
61,
367,
286,
315,
2163,
63,
604,
304,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
984,
14,
2703,
14,
952,
4582,
78,
2,
435,
17155,
627,
5939,
435,
1867,
78,
531,
267,
984,
14,
2703,
14,
952,
8,
576,
59,
5701,
63,
928,
435,
413,
26,
77,
14,
928,
9383,
267,
984,
14,
2703,
14,
952,
8,
2326,
794,
8,
77,
14,
923,
8,
16,
395,
16587,
628,
581,
2237,
267,
984,
14,
2703,
14,
952,
8,
576,
59,
77,
14,
500,
837,
2184,
63,
500,
566,
267,
984,
14,
2703,
14,
952,
4582,
78,
60,
78,
531,
398,
3350,
63,
466,
275,
488,
267,
1830,
3350,
63,
466,
365,
488,
26,
288,
3350,
63,
466,
275,
1324,
8,
355,
31019,
480,
11328,
4719,
26,
3872,
16587,
628,
14514,
21688,
1913,
1252,
2325,
342,
288,
340,
3350,
63,
466,
436,
3350,
63,
466,
440,
315,
820,
2228,
654,
26,
355,
3350,
63,
466,
275,
488,
398,
340,
3350,
63,
466,
508,
10812,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
340,
3350,
63,
466,
508,
298,
2759,
582,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
12112,
26194,
63,
13525,
14,
740,
8,
77,
14,
923,
8,
17,
430,
288,
1980,
398,
849,
275,
2061,
1459,
14,
362,
8,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
17,
430,
267,
340,
849,
14,
4130,
480,
16060,
436,
971,
355,
3350,
63,
466,
315,
1689,
533,
401,
298,
1532,
401,
298,
5247,
2349,
288,
849,
275,
849,
4439,
18,
61,
267,
3350,
63,
585,
275,
1324,
8,
288,
31019,
480,
1872,
665,
1375,
30,
359,
401,
16587,
628,
14514,
531,
435,
288,
849,
435,
288,
31019,
480,
2189,
3872,
16587,
628,
14514,
1288,
267,
7092,
1913,
342,
267,
340,
440,
3350,
63,
585,
26,
288,
3350,
63,
585,
275,
849,
267,
892,
14,
740,
480,
2689,
83,
1705,
5,
83,
64,
2,
450,
334,
1814,
63,
466,
12,
3350,
63,
585,
430,
267,
2061,
1459,
59,
77,
14,
923,
8,
17,
1874,
275,
3350,
63,
585,
339,
892,
14,
740,
8,
576,
59,
2019,
5728,
272,
1551,
8,
5252,
12,
298,
87,
3471,
952,
31059,
904,
8,
1222,
430,
339,
4887,
905,
2019,
1459,
937,
275,
2061,
1459,
272,
4887,
14,
1600,
342,
421,
199,
318,
31019,
8,
505,
4581,
3999,
16729,
1011,
958,
304,
272,
408,
272,
1803,
2195,
1318,
12,
27828,
315,
25600,
24348,
9479,
14,
339,
21588,
3198,
641,
314,
4252,
2368,
283,
9681,
7,
436,
283,
6856,
297,
436,
314,
4072,
402,
272,
314,
3999,
2008,
15,
513,
14,
339,
1803,
314,
12565,
775,
1233,
340,
949,
2633,
787,
1627,
14,
339,
4821,
9229,
26,
267,
283,
8399,
297,
283,
581,
297,
283,
7731,
297,
283,
14514,
297,
283,
6304,
297,
283,
5615,
21335,
297,
283,
28291,
297,
283,
7510,
7,
339,
4821,
1511,
26,
267,
283,
9771,
7,
267,
283,
21831,
7,
267,
283,
24042,
7,
267,
283,
4471,
7,
267,
283,
388,
301,
279,
7,
267,
283,
27400,
409,
7,
446,
1059,
911,
440,
506,
2599,
13,
18375,
543,
314,
12565,
775,
1233,
339,
6058,
26,
267,
31019,
360,
5006,
297,
16587,
534,
581,
297,
12994,
534,
6304,
297,
3999,
7782,
24042,
16829,
267,
31019,
342,
267,
31019,
360,
8302,
16481,
297,
3999,
7782,
21831,
16829,
267,
870,
31019,
360,
2246,
1004,
297,
16587,
534,
581,
297,
3999,
7782,
27400,
409,
16829,
267,
870,
283,
3749,
1077,
506,
8992,
4634,
7,
267,
870,
31019,
360,
460,
880,
1077,
642,
358,
267,
870
] |
[
199,
16291,
4012,
282,
20883,
570,
10023,
367,
2269,
13,
2487,
18041,
12,
436,
22577,
3350,
3062,
199,
1045,
892,
13,
2487,
6941,
14,
199,
624,
199,
199,
646,
295,
199,
646,
984,
199,
646,
1033,
15320,
199,
199,
893,
26,
272,
1324,
275,
1324,
199,
2590,
12746,
26,
272,
1324,
275,
3066,
63,
1210,
221,
327,
8151,
199,
199,
1121,
264,
275,
295,
14,
2014,
8,
82,
14700,
7059,
25502,
83,
2807,
31,
9719,
358,
199,
199,
6245,
654,
275,
334,
272,
283,
962,
297,
272,
283,
533,
297,
272,
298,
18256,
2113,
401,
272,
283,
576,
297,
272,
283,
2804,
297,
272,
283,
493,
297,
272,
283,
1532,
297,
272,
283,
3892,
297,
272,
283,
5247,
297,
272,
283,
1494,
297,
272,
298,
18256,
2113,
2992,
401,
272,
298,
1121,
401,
272,
298,
6031,
401,
272,
298,
5125,
401,
272,
298,
84,
1541,
401,
272,
298,
84,
1450,
401,
339,
327,
4539,
272,
298,
2759,
401,
199,
9,
199,
199,
32509,
63,
13525,
275,
359,
272,
298,
8084,
401,
272,
298,
549,
401,
272,
298,
797,
401,
199,
61,
421,
199,
318,
5325,
5955,
8,
5252,
304,
272,
666,
275,
1551,
8,
5252,
680,
739,
342,
339,
2061,
275,
378,
272,
892,
275,
942,
272,
4887,
275,
1033,
15320,
14,
1490,
4769,
2791,
15,
5955,
63,
475,
63,
31332,
14,
609,
15320,
531,
272,
2061,
1459,
275,
4887,
14,
362,
480,
2019,
1459,
401,
5009,
339,
367,
333,
315,
2984,
264,
14,
19373,
8,
576,
304,
398,
892,
14,
740,
8,
576,
59,
2019,
26,
77,
14,
928,
9383,
267,
2061,
275,
333,
14,
500,
342,
398,
1004,
63,
928,
275,
666,
14,
14542,
4582,
78,
401,
378,
12,
333,
14,
928,
1012,
267,
1004,
63,
500,
275,
666,
14,
1623,
4582,
78,
401,
333,
14,
500,
1012,
267,
5071,
63,
928,
275,
666,
14,
14542,
4582,
78,
401,
378,
12,
1004,
63,
928,
9,
267,
2163,
63,
500,
275,
666,
14,
1623,
4582,
78,
401,
1004,
63,
500,
435,
413,
9,
398,
327,
8232,
3544,
13,
2759,
8292,
267,
340,
333,
14,
923,
8,
17,
9,
315,
12112,
26194,
63,
13525,
26,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
327,
3372,
1380,
314,
2163,
1004,
365,
282,
2538,
267,
2163,
63,
604,
275,
666,
59,
77,
14,
500,
837,
2184,
63,
500,
1055,
1913,
342,
267,
340,
2163,
63,
604,
59,
16,
61,
315,
19724,
13,
15,
6809,
32,
1988,
64,
91,
13,
94,
2,
436,
971,
355,
1006,
8,
67,
508,
2163,
63,
604,
59,
16,
61,
367,
286,
315,
2163,
63,
604,
304,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
984,
14,
2703,
14,
952,
4582,
78,
2,
435,
17155,
627,
5939,
435,
1867,
78,
531,
267,
984,
14,
2703,
14,
952,
8,
576,
59,
5701,
63,
928,
435,
413,
26,
77,
14,
928,
9383,
267,
984,
14,
2703,
14,
952,
8,
2326,
794,
8,
77,
14,
923,
8,
16,
395,
16587,
628,
581,
2237,
267,
984,
14,
2703,
14,
952,
8,
576,
59,
77,
14,
500,
837,
2184,
63,
500,
566,
267,
984,
14,
2703,
14,
952,
4582,
78,
60,
78,
531,
398,
3350,
63,
466,
275,
488,
267,
1830,
3350,
63,
466,
365,
488,
26,
288,
3350,
63,
466,
275,
1324,
8,
355,
31019,
480,
11328,
4719,
26,
3872,
16587,
628,
14514,
21688,
1913,
1252,
2325,
342,
288,
340,
3350,
63,
466,
436,
3350,
63,
466,
440,
315,
820,
2228,
654,
26,
355,
3350,
63,
466,
275,
488,
398,
340,
3350,
63,
466,
508,
10812,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
1980,
398,
340,
3350,
63,
466,
508,
298,
2759,
582,
288,
892,
14,
740,
8,
77,
14,
923,
8,
16,
430,
288,
12112,
26194,
63,
13525,
14,
740,
8,
77,
14,
923,
8,
17,
430,
288,
1980,
398,
849,
275,
2061,
1459,
14,
362,
8,
77,
14,
923,
8,
17,
395,
333,
14,
923,
8,
17,
430,
267,
340,
849,
14,
4130,
480,
16060,
436,
971,
355,
3350,
63,
466,
315,
1689,
533,
401,
298,
1532,
401,
298,
5247,
2349,
288,
849,
275,
849,
4439,
18,
61,
267,
3350,
63,
585,
275,
1324,
8,
288,
31019,
480,
1872,
665,
1375,
30,
359,
401,
16587,
628,
14514,
531,
435,
288,
849,
435,
288,
31019,
480,
2189,
3872,
16587,
628,
14514,
1288,
267,
7092,
1913,
342,
267,
340,
440,
3350,
63,
585,
26,
288,
3350,
63,
585,
275,
849,
267,
892,
14,
740,
480,
2689,
83,
1705,
5,
83,
64,
2,
450,
334,
1814,
63,
466,
12,
3350,
63,
585,
430,
267,
2061,
1459,
59,
77,
14,
923,
8,
17,
1874,
275,
3350,
63,
585,
339,
892,
14,
740,
8,
576,
59,
2019,
5728,
272,
1551,
8,
5252,
12,
298,
87,
3471,
952,
31059,
904,
8,
1222,
430,
339,
4887,
905,
2019,
1459,
937,
275,
2061,
1459,
272,
4887,
14,
1600,
342,
421,
199,
318,
31019,
8,
505,
4581,
3999,
16729,
1011,
958,
304,
272,
408,
272,
1803,
2195,
1318,
12,
27828,
315,
25600,
24348,
9479,
14,
339,
21588,
3198,
641,
314,
4252,
2368,
283,
9681,
7,
436,
283,
6856,
297,
436,
314,
4072,
402,
272,
314,
3999,
2008,
15,
513,
14,
339,
1803,
314,
12565,
775,
1233,
340,
949,
2633,
787,
1627,
14,
339,
4821,
9229,
26,
267,
283,
8399,
297,
283,
581,
297,
283,
7731,
297,
283,
14514,
297,
283,
6304,
297,
283,
5615,
21335,
297,
283,
28291,
297,
283,
7510,
7,
339,
4821,
1511,
26,
267,
283,
9771,
7,
267,
283,
21831,
7,
267,
283,
24042,
7,
267,
283,
4471,
7,
267,
283,
388,
301,
279,
7,
267,
283,
27400,
409,
7,
446,
1059,
911,
440,
506,
2599,
13,
18375,
543,
314,
12565,
775,
1233,
339,
6058,
26,
267,
31019,
360,
5006,
297,
16587,
534,
581,
297,
12994,
534,
6304,
297,
3999,
7782,
24042,
16829,
267,
31019,
342,
267,
31019,
360,
8302,
16481,
297,
3999,
7782,
21831,
16829,
267,
870,
31019,
360,
2246,
1004,
297,
16587,
534,
581,
297,
3999,
7782,
27400,
409,
16829,
267,
870,
283,
3749,
1077,
506,
8992,
4634,
7,
267,
870,
31019,
360,
460,
880,
1077,
642,
358,
267,
870,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
huguesv/PTVS
|
Python/Product/Miniconda/Miniconda3-x64/Lib/site-packages/win32/Demos/security/sspi/fetch_url.py
|
6
|
5429
|
"""
Fetches a URL from a web-server supporting NTLM authentication
eg, IIS.
If no arguments are specified, a default of http://localhost/localstart.asp
is used. This script does follow simple 302 redirections, so pointing at the
root of an IIS server is should work.
"""
import sys
import urllib.request, urllib.parse, urllib.error
import http.client
import urllib.parse
from base64 import encodestring, decodestring
from sspi import ClientAuth
import optparse # sorry, this demo needs 2.3+
options = None # set to optparse options object
def open_url(host, url):
h = http.client.HTTPConnection(host)
# h.set_debuglevel(9)
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
print("Initial response is", resp.status, resp.reason)
body = resp.read()
if resp.status == 302: # object moved
url = "/" + resp.msg["location"]
resp.close()
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
print("After redirect response is", resp.status, resp.reason)
if options.show_headers:
print("Initial response headers:")
for name, val in list(resp.msg.items()):
print(" %s: %s" % (name, val))
if options.show_body:
print(body)
if resp.status == 401:
# 401: Unauthorized - here is where the real work starts
auth_info = None
if options.user or options.domain or options.password:
auth_info = options.user, options.domain, options.password
ca = ClientAuth("NTLM", auth_info=auth_info)
auth_scheme = ca.pkg_info['Name']
data = None
while 1:
err, out_buf = ca.authorize(data)
data = out_buf[0].Buffer
# Encode it as base64 as required by HTTP
auth = encodestring(data).replace("\012", "")
h.putrequest('GET', url)
h.putheader('Authorization', auth_scheme + ' ' + auth)
h.putheader('Content-Length', '0')
h.endheaders()
resp = h.getresponse()
if options.show_headers:
print("Token dance headers:")
for name, val in list(resp.msg.items()):
print(" %s: %s" % (name, val))
if err==0:
break
else:
if resp.status != 401:
print("Eeek - got response", resp.status)
cl = resp.msg.get("content-length")
if cl:
print(repr(resp.read(int(cl))))
else:
print("no content!")
assert resp.status == 401, resp.status
assert not resp.will_close, "NTLM is per-connection - must not close"
schemes = [s.strip() for s in resp.msg.get("WWW-Authenticate", "").split(",")]
for scheme in schemes:
if scheme.startswith(auth_scheme):
data = decodestring(scheme[len(auth_scheme)+1:])
break
else:
print("Could not find scheme '%s' in schemes %r" % (auth_scheme, schemes))
break
resp.read()
print("Final response status is", resp.status, resp.reason)
if resp.status == 200:
# Worked!
# Check we can read it again without re-authenticating.
if resp.will_close:
print("EEEK - response will close, but NTLM is per connection - it must stay open")
body = resp.read()
if options.show_body:
print("Final response body:")
print(body)
h.putrequest('GET', url)
h.endheaders()
resp = h.getresponse()
print("Second fetch response is", resp.status, resp.reason)
if options.show_headers:
print("Second response headers:")
for name, val in list(resp.msg.items()):
print(" %s: %s" % (name, val))
resp.read(int(resp.msg.get("content-length", 0)))
elif resp.status == 500:
print("Error text")
print(resp.read())
else:
if options.show_body:
cl = resp.msg.get("content-length")
print(resp.read(int(cl)))
if __name__=='__main__':
parser = optparse.OptionParser(description=__doc__)
parser.add_option("", "--show-body", action="store_true",
help="print the body of each response as it is received")
parser.add_option("", "--show-headers", action="store_true",
help="print the headers of each response as it is received")
parser.add_option("", "--user", action="store",
help="The username to login with")
parser.add_option("", "--password", action="store",
help="The password to login with")
parser.add_option("", "--domain", action="store",
help="The domain to login to")
options, args = parser.parse_args()
if not args:
print("Run with --help for usage details")
args = ["http://localhost/localstart.asp"]
for url in args:
scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(url)
if (scheme != "http") or params or query or fragment:
parser.error("Scheme must be http, URL must be simple")
print("Opening '%s' from '%s'" % (path, netloc))
r = open_url(netloc, path)
|
apache-2.0
|
[
624,
199,
11135,
397,
282,
2851,
687,
282,
3330,
13,
1000,
21038,
653,
25112,
6299,
199,
5902,
12,
473,
1311,
14,
199,
199,
3917,
949,
2368,
787,
2013,
12,
282,
849,
402,
1455,
921,
5967,
15,
1832,
928,
14,
20222,
199,
374,
1202,
14,
221,
961,
2884,
1630,
2035,
3486,
11485,
295,
27917,
12,
880,
20686,
737,
314,
199,
1231,
402,
376,
473,
1311,
1654,
365,
1077,
1736,
14,
199,
624,
199,
199,
646,
984,
199,
646,
4011,
14,
1069,
12,
4011,
14,
1122,
12,
4011,
14,
705,
199,
646,
1455,
14,
1258,
199,
646,
4011,
14,
1122,
199,
504,
1300,
772,
492,
3752,
875,
12,
4849,
875,
199,
199,
504,
308,
8721,
492,
6810,
2817,
199,
199,
646,
8691,
327,
308,
21342,
12,
642,
14779,
4839,
499,
14,
19,
11,
199,
199,
1419,
275,
488,
327,
663,
370,
8691,
1511,
909,
199,
199,
318,
1551,
63,
633,
8,
1102,
12,
1166,
304,
272,
394,
275,
1455,
14,
1258,
14,
19114,
8,
1102,
9,
199,
3,
259,
394,
14,
409,
63,
1757,
1896,
8,
25,
9,
272,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
272,
394,
14,
500,
2139,
342,
272,
3085,
275,
394,
14,
25006,
342,
272,
870,
480,
5733,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
2396,
275,
3085,
14,
739,
342,
272,
340,
3085,
14,
1205,
508,
11485,
26,
327,
909,
12155,
267,
1166,
275,
10609,
435,
3085,
14,
1328,
905,
1985,
937,
267,
3085,
14,
1600,
342,
267,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
267,
394,
14,
500,
2139,
342,
267,
3085,
275,
394,
14,
25006,
342,
267,
870,
480,
10881,
4660,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
340,
1511,
14,
2384,
63,
2139,
26,
267,
870,
480,
5733,
1177,
2323,
9107,
267,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
288,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
272,
340,
1511,
14,
2384,
63,
2030,
26,
267,
870,
8,
2030,
9,
272,
340,
3085,
14,
1205,
508,
13952,
26,
267,
327,
13952,
26,
1910,
11497,
446,
2348,
365,
2382,
314,
3363,
1736,
9174,
267,
1790,
63,
815,
275,
488,
267,
340,
1511,
14,
751,
503,
1511,
14,
2261,
503,
1511,
14,
2060,
26,
288,
1790,
63,
815,
275,
1511,
14,
751,
12,
1511,
14,
2261,
12,
1511,
14,
2060,
267,
1704,
275,
6810,
2817,
480,
46,
25112,
401,
1790,
63,
815,
29,
1178,
63,
815,
9,
267,
1790,
63,
5512,
275,
1704,
14,
4600,
63,
815,
459,
985,
418,
267,
666,
275,
488,
267,
1830,
413,
26,
288,
2329,
12,
734,
63,
1436,
275,
1704,
14,
14204,
8,
576,
9,
288,
666,
275,
734,
63,
1436,
59,
16,
1055,
3299,
288,
327,
19244,
652,
465,
1300,
772,
465,
1415,
701,
3101,
288,
1790,
275,
3752,
875,
8,
576,
680,
1814,
4582,
11533,
401,
6899,
288,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
288,
394,
14,
31233,
360,
11626,
297,
1790,
63,
5512,
435,
283,
283,
435,
1790,
9,
288,
394,
14,
31233,
360,
2714,
13,
4625,
297,
283,
16,
358,
288,
394,
14,
500,
2139,
342,
288,
3085,
275,
394,
14,
25006,
342,
288,
340,
1511,
14,
2384,
63,
2139,
26,
355,
870,
480,
3264,
366,
554,
2323,
9107,
355,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
490,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
953,
340,
2329,
389,
16,
26,
355,
2059,
288,
587,
26,
355,
340,
3085,
14,
1205,
1137,
13952,
26,
490,
870,
480,
37,
4374,
446,
4788,
1177,
401,
3085,
14,
1205,
9,
490,
824,
275,
3085,
14,
1328,
14,
362,
480,
1317,
13,
1267,
531,
490,
340,
824,
26,
717,
870,
8,
2722,
8,
4518,
14,
739,
8,
442,
8,
429,
7845,
490,
587,
26,
717,
870,
480,
889,
1564,
9124,
2234,
702,
3085,
14,
1205,
508,
13952,
12,
3085,
14,
1205,
953,
702,
440,
3085,
14,
14117,
63,
1600,
12,
298,
46,
25112,
365,
1126,
13,
2105,
446,
1471,
440,
4002,
2,
288,
21149,
275,
359,
83,
14,
1913,
342,
367,
308,
315,
3085,
14,
1328,
14,
362,
480,
27084,
13,
21476,
401,
25354,
1294,
11854,
11323,
288,
367,
5687,
315,
21149,
26,
355,
340,
5687,
14,
2460,
8,
1178,
63,
5512,
304,
490,
666,
275,
4849,
875,
8,
5512,
59,
552,
8,
1178,
63,
5512,
6393,
17,
5728,
490,
2059,
288,
587,
26,
355,
870,
480,
6531,
440,
2342,
5687,
1543,
83,
7,
315,
21149,
450,
82,
2,
450,
334,
1178,
63,
5512,
12,
21149,
430,
355,
2059,
27180,
3085,
14,
739,
342,
272,
870,
480,
12776,
1177,
2004,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
340,
3085,
14,
1205,
508,
1926,
26,
267,
327,
9361,
379,
1,
267,
327,
2670,
781,
883,
1586,
652,
4020,
1928,
295,
13,
1178,
2815,
1958,
14,
267,
340,
3085,
14,
14117,
63,
1600,
26,
288,
870,
480,
8699,
11959,
446,
1177,
911,
4002,
12,
1325,
653,
25112,
365,
1126,
1950,
446,
652,
1471,
25578,
1551,
531,
267,
2396,
275,
3085,
14,
739,
342,
267,
340,
1511,
14,
2384,
63,
2030,
26,
288,
870,
480,
12776,
1177,
2396,
9107,
288,
870,
8,
2030,
9,
267,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
267,
394,
14,
500,
2139,
342,
267,
3085,
275,
394,
14,
25006,
342,
267,
870,
480,
11906,
5267,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
267,
340,
1511,
14,
2384,
63,
2139,
26,
288,
870,
480,
11906,
1177,
2323,
9107,
288,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
355,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
2728,
3085,
14,
739,
8,
442,
8,
4518,
14,
1328,
14,
362,
480,
1317,
13,
1267,
401,
378,
1724,
272,
916,
3085,
14,
1205,
508,
6891,
26,
267,
870,
480,
547,
1318,
531,
267,
870,
8,
4518,
14,
739,
1012,
272,
587,
26,
267,
340,
1511,
14,
2384,
63,
2030,
26,
288,
824,
275,
3085,
14,
1328,
14,
362,
480,
1317,
13
] |
[
199,
11135,
397,
282,
2851,
687,
282,
3330,
13,
1000,
21038,
653,
25112,
6299,
199,
5902,
12,
473,
1311,
14,
199,
199,
3917,
949,
2368,
787,
2013,
12,
282,
849,
402,
1455,
921,
5967,
15,
1832,
928,
14,
20222,
199,
374,
1202,
14,
221,
961,
2884,
1630,
2035,
3486,
11485,
295,
27917,
12,
880,
20686,
737,
314,
199,
1231,
402,
376,
473,
1311,
1654,
365,
1077,
1736,
14,
199,
624,
199,
199,
646,
984,
199,
646,
4011,
14,
1069,
12,
4011,
14,
1122,
12,
4011,
14,
705,
199,
646,
1455,
14,
1258,
199,
646,
4011,
14,
1122,
199,
504,
1300,
772,
492,
3752,
875,
12,
4849,
875,
199,
199,
504,
308,
8721,
492,
6810,
2817,
199,
199,
646,
8691,
327,
308,
21342,
12,
642,
14779,
4839,
499,
14,
19,
11,
199,
199,
1419,
275,
488,
327,
663,
370,
8691,
1511,
909,
199,
199,
318,
1551,
63,
633,
8,
1102,
12,
1166,
304,
272,
394,
275,
1455,
14,
1258,
14,
19114,
8,
1102,
9,
199,
3,
259,
394,
14,
409,
63,
1757,
1896,
8,
25,
9,
272,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
272,
394,
14,
500,
2139,
342,
272,
3085,
275,
394,
14,
25006,
342,
272,
870,
480,
5733,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
2396,
275,
3085,
14,
739,
342,
272,
340,
3085,
14,
1205,
508,
11485,
26,
327,
909,
12155,
267,
1166,
275,
10609,
435,
3085,
14,
1328,
905,
1985,
937,
267,
3085,
14,
1600,
342,
267,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
267,
394,
14,
500,
2139,
342,
267,
3085,
275,
394,
14,
25006,
342,
267,
870,
480,
10881,
4660,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
340,
1511,
14,
2384,
63,
2139,
26,
267,
870,
480,
5733,
1177,
2323,
9107,
267,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
288,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
272,
340,
1511,
14,
2384,
63,
2030,
26,
267,
870,
8,
2030,
9,
272,
340,
3085,
14,
1205,
508,
13952,
26,
267,
327,
13952,
26,
1910,
11497,
446,
2348,
365,
2382,
314,
3363,
1736,
9174,
267,
1790,
63,
815,
275,
488,
267,
340,
1511,
14,
751,
503,
1511,
14,
2261,
503,
1511,
14,
2060,
26,
288,
1790,
63,
815,
275,
1511,
14,
751,
12,
1511,
14,
2261,
12,
1511,
14,
2060,
267,
1704,
275,
6810,
2817,
480,
46,
25112,
401,
1790,
63,
815,
29,
1178,
63,
815,
9,
267,
1790,
63,
5512,
275,
1704,
14,
4600,
63,
815,
459,
985,
418,
267,
666,
275,
488,
267,
1830,
413,
26,
288,
2329,
12,
734,
63,
1436,
275,
1704,
14,
14204,
8,
576,
9,
288,
666,
275,
734,
63,
1436,
59,
16,
1055,
3299,
288,
327,
19244,
652,
465,
1300,
772,
465,
1415,
701,
3101,
288,
1790,
275,
3752,
875,
8,
576,
680,
1814,
4582,
11533,
401,
6899,
288,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
288,
394,
14,
31233,
360,
11626,
297,
1790,
63,
5512,
435,
283,
283,
435,
1790,
9,
288,
394,
14,
31233,
360,
2714,
13,
4625,
297,
283,
16,
358,
288,
394,
14,
500,
2139,
342,
288,
3085,
275,
394,
14,
25006,
342,
288,
340,
1511,
14,
2384,
63,
2139,
26,
355,
870,
480,
3264,
366,
554,
2323,
9107,
355,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
490,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
953,
340,
2329,
389,
16,
26,
355,
2059,
288,
587,
26,
355,
340,
3085,
14,
1205,
1137,
13952,
26,
490,
870,
480,
37,
4374,
446,
4788,
1177,
401,
3085,
14,
1205,
9,
490,
824,
275,
3085,
14,
1328,
14,
362,
480,
1317,
13,
1267,
531,
490,
340,
824,
26,
717,
870,
8,
2722,
8,
4518,
14,
739,
8,
442,
8,
429,
7845,
490,
587,
26,
717,
870,
480,
889,
1564,
9124,
2234,
702,
3085,
14,
1205,
508,
13952,
12,
3085,
14,
1205,
953,
702,
440,
3085,
14,
14117,
63,
1600,
12,
298,
46,
25112,
365,
1126,
13,
2105,
446,
1471,
440,
4002,
2,
288,
21149,
275,
359,
83,
14,
1913,
342,
367,
308,
315,
3085,
14,
1328,
14,
362,
480,
27084,
13,
21476,
401,
25354,
1294,
11854,
11323,
288,
367,
5687,
315,
21149,
26,
355,
340,
5687,
14,
2460,
8,
1178,
63,
5512,
304,
490,
666,
275,
4849,
875,
8,
5512,
59,
552,
8,
1178,
63,
5512,
6393,
17,
5728,
490,
2059,
288,
587,
26,
355,
870,
480,
6531,
440,
2342,
5687,
1543,
83,
7,
315,
21149,
450,
82,
2,
450,
334,
1178,
63,
5512,
12,
21149,
430,
355,
2059,
27180,
3085,
14,
739,
342,
272,
870,
480,
12776,
1177,
2004,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
272,
340,
3085,
14,
1205,
508,
1926,
26,
267,
327,
9361,
379,
1,
267,
327,
2670,
781,
883,
1586,
652,
4020,
1928,
295,
13,
1178,
2815,
1958,
14,
267,
340,
3085,
14,
14117,
63,
1600,
26,
288,
870,
480,
8699,
11959,
446,
1177,
911,
4002,
12,
1325,
653,
25112,
365,
1126,
1950,
446,
652,
1471,
25578,
1551,
531,
267,
2396,
275,
3085,
14,
739,
342,
267,
340,
1511,
14,
2384,
63,
2030,
26,
288,
870,
480,
12776,
1177,
2396,
9107,
288,
870,
8,
2030,
9,
267,
394,
14,
524,
1069,
360,
2970,
297,
1166,
9,
267,
394,
14,
500,
2139,
342,
267,
3085,
275,
394,
14,
25006,
342,
267,
870,
480,
11906,
5267,
1177,
365,
401,
3085,
14,
1205,
12,
3085,
14,
5764,
9,
267,
340,
1511,
14,
2384,
63,
2139,
26,
288,
870,
480,
11906,
1177,
2323,
9107,
288,
367,
536,
12,
1139,
315,
769,
8,
4518,
14,
1328,
14,
1744,
5109,
355,
870,
480,
450,
83,
26,
450,
83,
2,
450,
334,
354,
12,
1139,
430,
2728,
3085,
14,
739,
8,
442,
8,
4518,
14,
1328,
14,
362,
480,
1317,
13,
1267,
401,
378,
1724,
272,
916,
3085,
14,
1205,
508,
6891,
26,
267,
870,
480,
547,
1318,
531,
267,
870,
8,
4518,
14,
739,
1012,
272,
587,
26,
267,
340,
1511,
14,
2384,
63,
2030,
26,
288,
824,
275,
3085,
14,
1328,
14,
362,
480,
1317,
13,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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org/licenses/MIT
from __future__ import print_function, unicode_literals
import os
import imp
import sys
import time
import types
import inspect
import logging
import unittest
from common import *
bundler = imp.load_source(
os.path.splitext(BUNDLET)[0],
BUNDLET_PATH
).AlfredBundler()
LOG = logging.getLogger('tests.wrapper')
LOG.debug('BUNDLER VERSION : {}'.format(MAJOR_VERSION))
class DeveloperTesting:
def __init__(self):
self._wrappers_dir = os.path.join(WRAPPERS_DIRECTORY)
self._wrappers = [
os.path.splitext(i)[0] for i in os.listdir(self._wrappers_dir) if (
os.path.splitext(i)[1].lower() == '.py') and
('__init__' not in i.lower())
]
class CocoaDialogTest(unittest.TestCase):
def setUp(self):
self.wrapper_name = 'cocoadialog'
self.testing = DeveloperTesting()
def tearDown(self):
pass
def test_wrapper_exists(self):
self.assertTrue(
self.wrapper_name in self.testing._wrappers,
'Could not find {} wrapper in {}'.format(
self.wrapper_name, self.testing._wrappers_dir
)
)
def test_wrapper_function(self):
_wrapper_load = bundler.wrapper(self.wrapper_name)
self.assertTrue(
hasattr(_wrapper_load, '__class__'),
'returned wrapper is not a class object'
)
self.assertTrue(
isinstance(_wrapper_load, types.InstanceType),
'returned wrapper is not a valid wrapper instance'
)
def test_msgbox(self):
_wrapper_load = bundler.wrapper(self.wrapper_name, debug=True)
_test_msgbox = _wrapper_load.msgbox(
title='Bundler::{}'.format(self.test_msgbox.__name__),
text='Please click the indicated button...',
button1='Click Me'
)
self.assertTrue(
isinstance(_test_msgbox, list),
'msgbox did not return list'
)
self.assertTrue(
len(_test_msgbox) > 0,
'msgbox did not return any values'
)
self.assertTrue(
_test_msgbox[0] == '1',
' '.join([
'msgbox returned invalid value for no string_output',
'actual: "{}", required: "{}"'
]).format('1', _test_msgbox[0])
)
_test_msgbox = _wrapper_load.msgbox(
title='Bundler::{}'.format(self.test_msgbox.__name__),
text='Please click the indicated button...',
button1='Click Me',
string_output=True
)
self.assertTrue(
isinstance(_test_msgbox, list),
'msgbox did not return list'
)
self.assertTrue(
len(_test_msgbox) > 0,
'msgbox did not return any values'
)
self.assertTrue(
_test_msgbox[0] == 'Click Me',
' '.join([
'msgbox returned invalid value for string_output',
'actual: "{}", required: "{}"'
]).format('Click Me', _test_msgbox[0])
)
def test_notify(self):
_wrapper_load = bundler.wrapper(self.wrapper_name, debug=True)
_test_notify = _wrapper_load.notify(
title='Bundler::{}'.format(self.test_notify.__name__),
description='This is just a test notification...'
)
self.assertIsNone(
_test_notify,
'notify returned value, must return nothing'
)
def test_progressbar(self):
_wrapper_load = bundler.wrapper(self.wrapper_name, debug=True)
_test_progressbar = _wrapper_load.progressbar(
title='Bundler::{}'.format(self.test_progressbar.__name__),
text='Testing progress bar...',
percent=0
)
self.assertTrue(
hasattr(_test_progressbar, '__class__'),
'returned progressbar is not a class object'
)
self.assertEquals(
type(_test_progressbar).__name__, 'progressbar',
'returned object is not a valid progressbar instance'
)
for i in range(101):
_test_progressbar.update(percent=i)
time.sleep(0.01)
_test_progressbar.finish()
def test_stoppable_progressbar(self):
_wrapper_load = bundler.wrapper(self.wrapper_name, debug=True)
_test_progressbar = _wrapper_load.progressbar(
title='Bundler::{}'.format(
self.test_stoppable_progressbar.__name__
),
text='Please press the stoppable button...',
percent=0,
stoppable=True
)
self.assertTrue(
hasattr(_test_progressbar, '__class__'),
'returned progressbar is not a class object'
)
self.assertEquals(
type(_test_progressbar).__name__, 'progressbar',
'returned object is not a valid progressbar instance'
)
for i in range(101):
_running_progress = _test_progressbar.update(percent=i)
if _running_progress == 0:
break
else:
self.assertEquals(
_running_progress, 1,
' '.join([
'invalid return from stoppable progress bar update,',
'actual: {}, required: {}'
]).format(_running_progress, '1')
)
time.sleep(1)
_killed_progress = _test_progressbar.update(percent=0)
self.assertEquals(
_killed_progress, 0,
' '.join([
'invalid return from stoppable progress bar update,',
'actual: {}, required: {}'
]).format(_killed_progress, '0')
)
class TerminalNotifierTest(unittest.TestCase):
def setUp(self):
self.wrapper_name = 'terminalnotifier'
self.testing = DeveloperTesting()
def tearDown(self):
pass
def test_wrapper_exists(self):
self.assertTrue(
self.wrapper_name in self.testing._wrappers,
'Could not find {} wrapper in {}'.format(
self.wrapper_name, self.testing._wrappers_dir
)
)
def test_wrapper_function(self):
_wrapper_load = bundler.wrapper(self.wrapper_name)
self.assertTrue(
hasattr(_wrapper_load, '__class__'),
'returned wrapper is not a class object'
)
self.assertTrue(
isinstance(_wrapper_load, types.InstanceType),
'returned wrapper is not a valid wrapper instance'
)
def test_notification(self):
_wrapper_load = bundler.wrapper(self.wrapper_name)
_test_notification = _wrapper_load.notify(
title='Bundler::{}'.format(self.test_notification.__name__),
message='This is just a test notification...'
)
self.assertIsNone(
_test_notification,
'notification returned value, must return nothing'
)
if __name__ in '__main__':
unittest.main()
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
22405,
103,
6927,
710,
437,
276,
581,
699,
725,
1435,
11682,
199,
3,
10697,
491,
530,
4894,
14,
1666,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
1742,
199,
646,
984,
199,
646,
900,
199,
646,
2943,
199,
646,
6485,
199,
646,
2050,
199,
646,
2882,
199,
199,
504,
2863,
492,
627,
199,
199,
66,
725,
1435,
275,
1742,
14,
912,
63,
1365,
8,
272,
747,
14,
515,
14,
7973,
8,
32044,
44,
775,
2788,
16,
467,
272,
699,
6131,
44,
775,
63,
3243,
199,
680,
33,
276,
581,
34,
725,
1435,
342,
199,
199,
4947,
275,
2050,
14,
5572,
360,
2219,
14,
5029,
358,
199,
4947,
14,
1757,
360,
32044,
19650,
15945,
520,
9499,
908,
8,
29241,
63,
4612,
430,
421,
199,
533,
9607,
9029,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
21148,
63,
694,
275,
747,
14,
515,
14,
904,
8,
6524,
7121,
3960,
63,
16436,
9,
267,
291,
423,
21148,
275,
359,
288,
747,
14,
515,
14,
7973,
8,
73,
2788,
16,
61,
367,
284,
315,
747,
14,
7374,
8,
277,
423,
21148,
63,
694,
9,
340,
334,
355,
747,
14,
515,
14,
7973,
8,
73,
2788,
17,
1055,
2325,
342,
508,
1987,
647,
358,
436,
288,
25038,
826,
12217,
440,
315,
284,
14,
2325,
1012,
267,
1622,
421,
199,
533,
1849,
331,
65,
5619,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5029,
63,
354,
275,
283,
331,
331,
65,
7196,
7,
267,
291,
14,
4776,
275,
9607,
9029,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
511,
63,
5029,
63,
2444,
8,
277,
304,
267,
291,
14,
1815,
8,
288,
291,
14,
5029,
63,
354,
315,
291,
14,
4776,
423,
21148,
12,
288,
283,
6531,
440,
2342,
1052,
4975,
315,
9499,
908,
8,
355,
291,
14,
5029,
63,
354,
12,
291,
14,
4776,
423,
21148,
63,
694,
288,
776,
267,
776,
339,
347,
511,
63,
5029,
63,
1593,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
9,
267,
291,
14,
1815,
8,
288,
2688,
1547,
5029,
63,
912,
12,
2560,
533,
363,
659,
288,
283,
19065,
4975,
365,
440,
282,
1021,
909,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
5029,
63,
912,
12,
2943,
14,
3244,
804,
395,
288,
283,
19065,
4975,
365,
440,
282,
1686,
4975,
1256,
7,
267,
776,
339,
347,
511,
63,
1328,
1977,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
1328,
1977,
275,
485,
5029,
63,
912,
14,
1328,
1977,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
1328,
1977,
855,
354,
10139,
288,
1318,
534,
8254,
8968,
314,
22141,
5528,
20833,
288,
5528,
17,
534,
12040,
3194,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
396,
63,
1328,
1977,
12,
769,
395,
288,
283,
1328,
1977,
8103,
440,
372,
769,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
822,
1547,
396,
63,
1328,
1977,
9,
690,
378,
12,
288,
283,
1328,
1977,
8103,
440,
372,
1263,
1338,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
485,
396,
63,
1328,
1977,
59,
16,
61,
508,
283,
17,
297,
288,
283,
1987,
904,
779,
355,
283,
1328,
1977,
2138,
3866,
574,
367,
949,
1059,
63,
1199,
297,
355,
283,
6514,
26,
11491,
401,
1415,
26,
11491,
4507,
288,
4794,
14,
908,
360,
17,
297,
485,
396,
63,
1328,
1977,
59,
16,
566,
267,
776,
267,
485,
396,
63,
1328,
1977,
275,
485,
5029,
63,
912,
14,
1328,
1977,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
1328,
1977,
855,
354,
10139,
288,
1318,
534,
8254,
8968,
314,
22141,
5528,
20833,
288,
5528,
17,
534,
12040,
3194,
297,
288,
1059,
63,
1199,
29,
549,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
396,
63,
1328,
1977,
12,
769,
395,
288,
283,
1328,
1977,
8103,
440,
372,
769,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
822,
1547,
396,
63,
1328,
1977,
9,
690,
378,
12,
288,
283,
1328,
1977,
8103,
440,
372,
1263,
1338,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
485,
396,
63,
1328,
1977,
59,
16,
61,
508,
283,
12040,
3194,
297,
288,
283,
1987,
904,
779,
355,
283,
1328,
1977,
2138,
3866,
574,
367,
1059,
63,
1199,
297,
355,
283,
6514,
26,
11491,
401,
1415,
26,
11491,
4507,
288,
4794,
14,
908,
360,
12040,
3194,
297,
485,
396,
63,
1328,
1977,
59,
16,
566,
267,
776,
339,
347,
511,
63,
6814,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
6814,
275,
485,
5029,
63,
912,
14,
6814,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
6814,
855,
354,
10139,
288,
1369,
534,
2765,
365,
2951,
282,
511,
6955,
13698,
267,
776,
267,
291,
14,
7702,
8,
288,
485,
396,
63,
6814,
12,
288,
283,
6814,
2138,
574,
12,
1471,
372,
6548,
7,
267,
776,
339,
347,
511,
63,
5734,
1700,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
5734,
1700,
275,
485,
5029,
63,
912,
14,
5734,
1700,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
5734,
1700,
855,
354,
10139,
288,
1318,
534,
9029,
6696,
4681,
20833,
288,
8878,
29,
16,
267,
776,
267,
291,
14,
1815,
8,
288,
2688,
1547,
396,
63,
5734,
1700,
12,
2560,
533,
363,
659,
288,
283,
19065,
6696,
1700,
365,
440,
282,
1021,
909,
7
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
199,
3,
1898,
22405,
103,
6927,
710,
437,
276,
581,
699,
725,
1435,
11682,
199,
3,
10697,
491,
530,
4894,
14,
1666,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
1742,
199,
646,
984,
199,
646,
900,
199,
646,
2943,
199,
646,
6485,
199,
646,
2050,
199,
646,
2882,
199,
199,
504,
2863,
492,
627,
199,
199,
66,
725,
1435,
275,
1742,
14,
912,
63,
1365,
8,
272,
747,
14,
515,
14,
7973,
8,
32044,
44,
775,
2788,
16,
467,
272,
699,
6131,
44,
775,
63,
3243,
199,
680,
33,
276,
581,
34,
725,
1435,
342,
199,
199,
4947,
275,
2050,
14,
5572,
360,
2219,
14,
5029,
358,
199,
4947,
14,
1757,
360,
32044,
19650,
15945,
520,
9499,
908,
8,
29241,
63,
4612,
430,
421,
199,
533,
9607,
9029,
26,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
21148,
63,
694,
275,
747,
14,
515,
14,
904,
8,
6524,
7121,
3960,
63,
16436,
9,
267,
291,
423,
21148,
275,
359,
288,
747,
14,
515,
14,
7973,
8,
73,
2788,
16,
61,
367,
284,
315,
747,
14,
7374,
8,
277,
423,
21148,
63,
694,
9,
340,
334,
355,
747,
14,
515,
14,
7973,
8,
73,
2788,
17,
1055,
2325,
342,
508,
1987,
647,
358,
436,
288,
25038,
826,
12217,
440,
315,
284,
14,
2325,
1012,
267,
1622,
421,
199,
533,
1849,
331,
65,
5619,
774,
8,
2796,
14,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
5029,
63,
354,
275,
283,
331,
331,
65,
7196,
7,
267,
291,
14,
4776,
275,
9607,
9029,
342,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
511,
63,
5029,
63,
2444,
8,
277,
304,
267,
291,
14,
1815,
8,
288,
291,
14,
5029,
63,
354,
315,
291,
14,
4776,
423,
21148,
12,
288,
283,
6531,
440,
2342,
1052,
4975,
315,
9499,
908,
8,
355,
291,
14,
5029,
63,
354,
12,
291,
14,
4776,
423,
21148,
63,
694,
288,
776,
267,
776,
339,
347,
511,
63,
5029,
63,
1593,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
9,
267,
291,
14,
1815,
8,
288,
2688,
1547,
5029,
63,
912,
12,
2560,
533,
363,
659,
288,
283,
19065,
4975,
365,
440,
282,
1021,
909,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
5029,
63,
912,
12,
2943,
14,
3244,
804,
395,
288,
283,
19065,
4975,
365,
440,
282,
1686,
4975,
1256,
7,
267,
776,
339,
347,
511,
63,
1328,
1977,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
1328,
1977,
275,
485,
5029,
63,
912,
14,
1328,
1977,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
1328,
1977,
855,
354,
10139,
288,
1318,
534,
8254,
8968,
314,
22141,
5528,
20833,
288,
5528,
17,
534,
12040,
3194,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
396,
63,
1328,
1977,
12,
769,
395,
288,
283,
1328,
1977,
8103,
440,
372,
769,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
822,
1547,
396,
63,
1328,
1977,
9,
690,
378,
12,
288,
283,
1328,
1977,
8103,
440,
372,
1263,
1338,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
485,
396,
63,
1328,
1977,
59,
16,
61,
508,
283,
17,
297,
288,
283,
1987,
904,
779,
355,
283,
1328,
1977,
2138,
3866,
574,
367,
949,
1059,
63,
1199,
297,
355,
283,
6514,
26,
11491,
401,
1415,
26,
11491,
4507,
288,
4794,
14,
908,
360,
17,
297,
485,
396,
63,
1328,
1977,
59,
16,
566,
267,
776,
267,
485,
396,
63,
1328,
1977,
275,
485,
5029,
63,
912,
14,
1328,
1977,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
1328,
1977,
855,
354,
10139,
288,
1318,
534,
8254,
8968,
314,
22141,
5528,
20833,
288,
5528,
17,
534,
12040,
3194,
297,
288,
1059,
63,
1199,
29,
549,
267,
776,
267,
291,
14,
1815,
8,
288,
1228,
1547,
396,
63,
1328,
1977,
12,
769,
395,
288,
283,
1328,
1977,
8103,
440,
372,
769,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
822,
1547,
396,
63,
1328,
1977,
9,
690,
378,
12,
288,
283,
1328,
1977,
8103,
440,
372,
1263,
1338,
7,
267,
776,
267,
291,
14,
1815,
8,
288,
485,
396,
63,
1328,
1977,
59,
16,
61,
508,
283,
12040,
3194,
297,
288,
283,
1987,
904,
779,
355,
283,
1328,
1977,
2138,
3866,
574,
367,
1059,
63,
1199,
297,
355,
283,
6514,
26,
11491,
401,
1415,
26,
11491,
4507,
288,
4794,
14,
908,
360,
12040,
3194,
297,
485,
396,
63,
1328,
1977,
59,
16,
566,
267,
776,
339,
347,
511,
63,
6814,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
6814,
275,
485,
5029,
63,
912,
14,
6814,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
6814,
855,
354,
10139,
288,
1369,
534,
2765,
365,
2951,
282,
511,
6955,
13698,
267,
776,
267,
291,
14,
7702,
8,
288,
485,
396,
63,
6814,
12,
288,
283,
6814,
2138,
574,
12,
1471,
372,
6548,
7,
267,
776,
339,
347,
511,
63,
5734,
1700,
8,
277,
304,
267,
485,
5029,
63,
912,
275,
330,
725,
1435,
14,
5029,
8,
277,
14,
5029,
63,
354,
12,
3105,
29,
549,
9,
267,
485,
396,
63,
5734,
1700,
275,
485,
5029,
63,
912,
14,
5734,
1700,
8,
288,
2538,
534,
34,
725,
1435,
447,
11123,
908,
8,
277,
14,
396,
63,
5734,
1700,
855,
354,
10139,
288,
1318,
534,
9029,
6696,
4681,
20833,
288,
8878,
29,
16,
267,
776,
267,
291,
14,
1815,
8,
288,
2688,
1547,
396,
63,
5734,
1700,
12,
2560,
533,
363,
659,
288,
283,
19065,
6696,
1700,
365,
440,
282,
1021,
909,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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plegame import Game, Transform, Axis, Animation, Sprite
from simplegame import Loader, MouseListener, Clear, Jukebox, KeyHandler
from simplegame import Vector
from upgrade import Upgrade
from rotation import Rotatable
import random
import pygame
import os
import math
class DestructibleBlock(Sprite):
def __init__(self, pos, tilefile):
super().__init__(pos, tilefile)
self.destroyed = False
def damage(self, amount, source, area):
if not self.destroyed:
if area.colliderect(self.rect):
self.image = Loader.load_image("brokenwindow")
class Laser(Rotatable):
def __init__(self, start, end, duration=0.1):
self.layer = 1
extent = end - start
middle = start + extent * 0.5
img = Loader.load_image("laser")
length = int(math.floor(extent.length))
source = Clear((length, 8))
for i in range(length):
pos = (i*16, 0)
source.blit(img, pos)
self.elapsed = 0
self.duration = duration
angle = extent.angle()
if end.y < start.y:
angle = 180 - angle
super().__init__(middle.tuple,"laser", 0)
self.source = source
self.rotation = -angle
destroy(Line(start, end), source)
def update(self, deltatime):
self.elapsed += deltatime
if self.elapsed >= self.duration:
self.destroy()
class Hydrant(Sprite):
def __init__(self, pos):
super().__init__(pos, "hydrant")
self.layer = 0
self.spout = None
self.destroyed = False
def damage(self, amount, source, area):
if not self.destroyed:
self.image = Loader.load_image("brokenhydrant")
self.destroyed = True
self.spout = Animation("resources/wateranim").play(True)
def render(self, surf):
if self.spout:
spoutpos = (self.pos - Vector(0, self.spout.get_height()-24)).tuple
surf.blit(self.spout, spoutpos)
super().render(surf)
def move(self, vec):
super().move(vec)
if self.rect.right < 0:
self.destroy()
def destroy(self):
super().destroy()
self.spout.stop()
class RelPosFinder(MouseListener):
def __init__(self, target):
super().__init__()
self.target = target
def on_press(self, pos, button):
rel = Vector(pos) - self.target.pos
print("Relative distance to the target:", rel.tuple)
def destroy(area, source):
for obj in Game.active.sprites:
if hasattr(obj, "damage"):
if area.colliderect(obj.rect):
obj.damage(10, source, area)
class Circle:
def __init__(self, pos, radius):
self.pos = pos
self.radius = radius
def colliderect(self, rect):
dist = math.sqrt((rect.centerx - self.pos[0])**2 + (rect.centery - self.pos[1])**2)
return dist < self.radius
class SmallExplosion(Transform):
def __init__(self, pos):
super().__init__(pygame.Rect(0,0,0,0), pos=pos, centered=True)
self.layer = -1
cb = lambda: Game.active.remove(self)
self.image = Animation("resources/smallExp", finish_cb=cb).play()
def render(self, surf):
surf.blit(self.image, self.drawpos)
class Line:
def __init__(self, startpos, endpos):
self.start = startpos
self.end = endpos
delta = Vector(self.end) - self.start
self.x1 = min(startpos[0], endpos[0])
self.x2 = max(startpos[0], endpos[0])
a = delta.y / delta.x
b = self.start[1] - a * self.start[0]
self.value = lambda x: a*x + b
def colliderect(self, rect):
left = self.value(rect.left)
if rect.right <= self.x1: return False
if rect.left >= self.x2: return False
if rect.top < left < rect.bottom:
return True
right = self.value(rect.right)
if rect.top < right < rect.bottom:
return True
return False
laser_length = 400
class LaserEyes(Upgrade):
def __init__(self, parent, key=pygame.K_e):
super().__init__(parent, "Laser Eyes", (35, 24), "lasereye",
"Zap!", centered=True)
self.key = key
self.keydown = False
def handle(self, event):
if event.type == pygame.KEYDOWN:
if event.key == self.key:
self.shoot_laser()
def shoot_laser(self):
start = Vector(self.rect.center)
direction = Vector(pygame.mouse.get_pos()) - start
end = start + direction.normalized * laser_length
Game.active.add(Laser(start, end))
class Skyscraper(Sprite):
def __init__(self, pos, size, tilefile, winwidth, cb):
self.layer = 10
self.tiles = []
img = Loader.load_image(tilefile)
x1, y1 = pos
w, h = img.get_size()
totalw = size[0] * w
totalh = size[1] * h
self.winwidth = winwidth
rect = pygame.Rect(x1, y1 - totalh, totalw, totalh)
super().__init__(rect.topleft, None, rect=rect)
self.visible = False
self.cb = cb
for x in range(1, size[0]+1):
for y in range(1, size[1]+1):
p = (x1 + x*w, y1 - y*h)
block = DestructibleBlock(p, tilefile)
self.add_child(block)
self.tiles.append(block)
def render(self, surf):
for tile in self.tiles:
tile.render(surf)
def damage(self, amount, source, area):
for tile in self.tiles:
if area.colliderect(tile.rect):
tile.damage(amount, area, area)
def move(self, vec):
if (not self.visible) and self.rect.right < self.winwidth:
self.visible = True
self.cb()
super().move(vec)
if self.rect.right < 0:
self.destroy()
speed = 100
class Kaijuu(Sprite):
def __init__(self, pos):
super().__init__(pos, "kaijuu")
self.still_image = self.image
self.dir = Vector(speed, 0)
self.walking = False
self.layer = 3
def update(self, deltatime):
Transform.update(self, deltatime)
if self.dir.x:
if not self.walking:
self.walking = True
self.image = Animation("resources/kaijuu").play(True)
else:
if self.walking:
self.walking = False
self.image.stop(self.still_image)
destroy(self.rect, self)
def move(self, vec):
#super().move(vec)
mov = vec * -1
for sprite in Game.active.sprites:
if hasattr(sprite, "move"):
if sprite is self:
continue
elif sprite in self.children:
continue
else:
sprite.move(mov)
class Ground(Sprite):
def __init__(self, windowsize, start=0):
super().__init__((start, windowsize[1]-16), "ground")
self.windowsize = windowsize
#print("Ground added at ", self.pos)
def move(self, vec):
Sprite.move(self, vec)
if self.rect.right < 0:
#print("Jumping!")
#print("old:", self.pos)
self.move(Vector(self.windowsize[0]*2, 0))
#print("new:", self.pos)
class Generator:
def __init__(self, ground, winwidth):
self.ground = ground
self.winwidth = winwidth
def start(self):
self.generate()
def generate(self, start=None):
start = start if start else self.winwidth
w = random.randint(4, 8)
h = random.randint(w, w*4)
padding = random.randint(4, 16)
x = start + padding
skyscraper = Skyscraper((x, self.ground), (w, h),
"window", self.winwidth, self.generate)
Game.active.add(skyscraper)
if random.randint(0,2) == 0:
if h < 10:
Game.active.add(Tank((start + 2 * 16, self.ground-64 - (h * 16))))
else:
Game.active.add(Tank((start + random.randint(0,32) , self.ground-64)))
if random.randint(0,3) == 0:
Game.active.add(Helicopter((start, 200 + random.randint(0,200))))
hydrants = random.randint(0, w//2)
s = start
for i in range(hydrants):
s = s + random.randint(2, 16)
Game.active.add(Hydrant((s, self.ground-16)))
s += 16
class Tank(Sprite):
def __init__(self, pos):
super().__init__(pos, "tank")
self.elapsed = random.randint(0,16) / 8
self.shoot_delay = 2.5
def update(self, deltatime):
self.elapsed += deltatime
if self.elapsed >= self.shoot_delay:
mis = Missile(self.pos + (10,15),(-5.8,-3.8))
Game.active.add(mis)
self.elapsed -= self.shoot_delay
def damage(self, amount, source, area):
mis = SmallExplosion(self.pos + (0,10))
Game.active.add(mis)
self.destroy()
gravity = Vector(0,0.1)
class Helicopter(Sprite):
def __init__(self, pos):
super().__init__(pos, "helekopter")
self.image = Animation("resources/helekopter").play(True)
self.elapsed = random.randint(0,8) / 8
self.shoot_delay = 2
self.vec = Vector(0,0.5)
def render(self, surf):
surf.blit(self.image, self.drawpos)
def update(self, deltatime):
self.pos += self.vec * deltatime * 50
self.elapsed += deltatime
if self.elapsed >= self.shoot_delay:
if self.pos.x < 400 or self.pos.y < 250:
mis = Missile(self.pos + (0,32),(-7,1))
else:
mis = Missile(self.pos + (0,32),(-8,-1))
Game.active.add(mis)
self.elapsed -= self.shoot_delay
self.vec = Vector(self.vec.x, -self.vec.y)
def damage(self, amount, source, area):
mis = SmallExplosion(self.pos)
Game.active.add(mis)
self.destroy()
class Missile(Rotatable):
def __init__(self, pos, vec):
super().__init__(pos, "missile", 0)
self.layer = 1
self.vec = Vector(vec)
def update(self, deltatime):
if self.vec.y < 0:
angle = self.vec.angle()
else:
angle = 360 - self.vec.angle()
self.rotation = angle
self.pos += self.vec * deltatime * 50
self.vec += gravity * deltatime * 50
if self.pos.y > 550:
self.explode()
def damage(self, amount, source, area):
if type(source) == Kaijuu:
restart()
self.explode()
def explode(self):
mis = SmallExplosion(self.pos - (32,32))
Game.active.add(mis)
self.destroy()
size = (800,600)
game = Game(size, "Kaijuu Game")
Jukebox.play("resources/234.wav", loop=True)
def restart():
game.clear()
ground = size[1]-16
game.add(Ground(size))
game.add(Ground(size, start=size[0]))
monster = Kaijuu((100, ground-192))
game.add(LaserEyes(monster))
game.add(monster)
gen = Generator(ground, size[0])
gen.start()
game.add(KeyHandler((restart, pygame.K_r)))
game.add(gen)
start()
game.run()
|
mit
|
[
199,
199,
504,
3486,
5097,
492,
25132,
12,
19463,
12,
23205,
12,
1626,
8182,
12,
8360,
752,
199,
504,
3486,
5097,
492,
22865,
12,
603,
7130,
10464,
12,
14836,
12,
1603,
85,
415,
1977,
12,
2606,
2461,
199,
504,
3486,
5097,
492,
11388,
199,
504,
10754,
492,
4949,
4523,
199,
504,
13038,
492,
20423,
15511,
199,
646,
2196,
199,
646,
9193,
199,
646,
747,
199,
646,
3473,
421,
199,
533,
1487,
9853,
21602,
3142,
8,
30185,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
12,
12835,
493,
304,
267,
1613,
11027,
826,
721,
1712,
12,
12835,
493,
9,
267,
291,
14,
7237,
379,
275,
756,
2286,
347,
12927,
960,
8,
277,
12,
5982,
12,
1350,
12,
9150,
304,
267,
340,
440,
291,
14,
7237,
379,
26,
288,
340,
9150,
14,
761,
8409,
1201,
8,
277,
14,
1201,
304,
355,
291,
14,
1569,
275,
22865,
14,
912,
63,
1569,
480,
15697,
3806,
531,
199,
199,
533,
7964,
332,
8,
14728,
15511,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
12,
1284,
12,
7373,
29,
16,
14,
17,
304,
267,
291,
14,
1897,
275,
413,
267,
13675,
275,
1284,
446,
1343,
267,
12180,
275,
1343,
435,
13675,
627,
378,
14,
21,
267,
6050,
275,
22865,
14,
912,
63,
1569,
480,
416,
332,
531,
267,
2582,
275,
1109,
8,
3442,
14,
11289,
8,
11599,
14,
1267,
430,
267,
1350,
275,
14836,
1332,
1267,
12,
1695,
430,
267,
367,
284,
315,
1425,
8,
1267,
304,
288,
2086,
275,
334,
73,
10,
975,
12,
378,
9,
288,
1350,
14,
15574,
8,
4060,
12,
2086,
9,
267,
291,
14,
16691,
275,
378,
267,
291,
14,
5553,
275,
7373,
267,
9324,
275,
13675,
14,
4593,
342,
267,
340,
1284,
14,
89,
665,
1343,
14,
89,
26,
288,
9324,
275,
13576,
446,
9324,
267,
1613,
11027,
826,
721,
14885,
14,
2960,
4589,
416,
332,
401,
378,
9,
267,
291,
14,
1365,
275,
1350,
267,
291,
14,
15362,
275,
446,
4593,
267,
11972,
8,
3049,
8,
928,
12,
1284,
395,
1350,
9,
5493,
347,
1678,
8,
277,
12,
5762,
521,
304,
267,
291,
14,
16691,
847,
5762,
521,
267,
340,
291,
14,
16691,
2356,
291,
14,
5553,
26,
288,
291,
14,
7237,
342,
199,
199,
533,
29591,
5012,
867,
8,
30185,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
304,
267,
1613,
11027,
826,
721,
1712,
12,
298,
3577,
5012,
867,
531,
267,
291,
14,
1897,
275,
378,
267,
291,
14,
681,
548,
275,
488,
267,
291,
14,
7237,
379,
275,
756,
2286,
347,
12927,
960,
8,
277,
12,
5982,
12,
1350,
12,
9150,
304,
267,
340,
440,
291,
14,
7237,
379,
26,
288,
291,
14,
1569,
275,
22865,
14,
912,
63,
1569,
480,
15697,
3577,
5012,
867,
531,
288,
291,
14,
7237,
379,
275,
715,
288,
291,
14,
681,
548,
275,
1626,
8182,
480,
4435,
15,
87,
323,
1312,
1017,
3471,
2802,
8,
549,
9,
2286,
347,
3795,
8,
277,
12,
24802,
304,
267,
340,
291,
14,
681,
548,
26,
288,
2249,
548,
1712,
275,
334,
277,
14,
1712,
446,
11388,
8,
16,
12,
291,
14,
681,
548,
14,
362,
63,
3333,
22251,
1194,
4992,
2960,
288,
24802,
14,
15574,
8,
277,
14,
681,
548,
12,
2249,
548,
1712,
9,
267,
1613,
1252,
3352,
8,
21579,
9,
2286,
347,
4057,
8,
277,
12,
10782,
304,
267,
1613,
1252,
1185,
8,
6046,
9,
267,
340,
291,
14,
1201,
14,
1019,
665,
378,
26,
288,
291,
14,
7237,
342,
2286,
347,
11972,
8,
277,
304,
267,
1613,
1252,
7237,
342,
267,
291,
14,
681,
548,
14,
2379,
342,
199,
199,
533,
9781,
6981,
11791,
8,
17141,
10464,
304,
272,
347,
636,
826,
721,
277,
12,
1347,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
1375,
275,
1347,
2286,
347,
641,
63,
2915,
8,
277,
12,
2086,
12,
5528,
304,
267,
4668,
275,
11388,
8,
1712,
9,
446,
291,
14,
1375,
14,
1712,
267,
870,
480,
15277,
6033,
370,
314,
1347,
6783,
4668,
14,
2960,
9,
268,
199,
318,
11972,
8,
6789,
12,
1350,
304,
272,
367,
1559,
315,
25132,
14,
2682,
14,
27495,
26,
267,
340,
2688,
8,
1113,
12,
298,
26551,
2349,
288,
340,
9150,
14,
761,
8409,
1201,
8,
1113,
14,
1201,
304,
355,
1559,
14,
26551,
8,
709,
12,
1350,
12,
9150,
9,
1467,
199,
533,
445,
12571,
26,
272,
347,
636,
826,
721,
277,
12,
2086,
12,
9362,
304,
267,
291,
14,
1712,
275,
2086,
267,
291,
14,
8017,
275,
9362,
2286,
347,
1048,
8409,
1201,
8,
277,
12,
8626,
304,
267,
2917,
275,
3473,
14,
5079,
1332,
1201,
14,
4218,
88,
446,
291,
14,
1712,
59,
16,
566,
538,
18,
435,
334,
1201,
14,
4218,
89,
446,
291,
14,
1712,
59,
17,
566,
538,
18,
9,
267,
372,
2917,
665,
291,
14,
8017,
199,
199,
533,
23704,
4527,
320,
438,
8,
6939,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
304,
267,
1613,
11027,
826,
721,
22278,
14,
8252,
8,
16,
12,
16,
12,
16,
12,
16,
395,
2086,
29,
1712,
12,
23903,
29,
549,
9,
267,
291,
14,
1897,
275,
446,
17,
267,
7434,
275,
2400,
26,
25132,
14,
2682,
14,
2168,
8,
277,
9,
267,
291,
14,
1569,
275,
1626,
8182,
480,
4435,
15,
7241,
4527,
401,
9578,
63,
2894,
29,
2894,
680,
2802,
342,
2286,
347,
3795,
8,
277,
12,
24802,
304,
267,
24802,
14,
15574,
8,
277,
14,
1569,
12,
291,
14,
5485,
1712,
9,
199,
199,
533,
7030,
26,
272,
347,
636,
826,
721,
277,
12,
1343,
1712,
12,
26690,
304,
267,
291,
14,
928,
275,
1343,
1712,
267,
291,
14,
500,
275,
26690,
267,
5762,
275,
11388,
8,
277,
14,
500,
9,
446,
291,
14,
928,
267,
291,
14,
88,
17,
275,
1748,
8,
31837,
59,
16,
467,
26690,
59,
16,
566,
267,
291,
14,
88,
18,
275,
1390,
8,
31837,
59,
16,
467,
26690,
59,
16,
566,
267,
282,
275,
5762,
14,
89,
1182,
5762,
14,
88,
267,
330,
275,
291,
14,
928,
59,
17,
61,
446,
282,
627,
291,
14,
928,
59,
16,
61,
267,
291,
14,
585,
275,
2400,
671,
26,
282,
10,
88,
435,
330,
2286,
347,
1048,
8409,
1201,
8,
277,
12,
8626
] |
[
199,
504,
3486,
5097,
492,
25132,
12,
19463,
12,
23205,
12,
1626,
8182,
12,
8360,
752,
199,
504,
3486,
5097,
492,
22865,
12,
603,
7130,
10464,
12,
14836,
12,
1603,
85,
415,
1977,
12,
2606,
2461,
199,
504,
3486,
5097,
492,
11388,
199,
504,
10754,
492,
4949,
4523,
199,
504,
13038,
492,
20423,
15511,
199,
646,
2196,
199,
646,
9193,
199,
646,
747,
199,
646,
3473,
421,
199,
533,
1487,
9853,
21602,
3142,
8,
30185,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
12,
12835,
493,
304,
267,
1613,
11027,
826,
721,
1712,
12,
12835,
493,
9,
267,
291,
14,
7237,
379,
275,
756,
2286,
347,
12927,
960,
8,
277,
12,
5982,
12,
1350,
12,
9150,
304,
267,
340,
440,
291,
14,
7237,
379,
26,
288,
340,
9150,
14,
761,
8409,
1201,
8,
277,
14,
1201,
304,
355,
291,
14,
1569,
275,
22865,
14,
912,
63,
1569,
480,
15697,
3806,
531,
199,
199,
533,
7964,
332,
8,
14728,
15511,
304,
272,
347,
636,
826,
721,
277,
12,
1343,
12,
1284,
12,
7373,
29,
16,
14,
17,
304,
267,
291,
14,
1897,
275,
413,
267,
13675,
275,
1284,
446,
1343,
267,
12180,
275,
1343,
435,
13675,
627,
378,
14,
21,
267,
6050,
275,
22865,
14,
912,
63,
1569,
480,
416,
332,
531,
267,
2582,
275,
1109,
8,
3442,
14,
11289,
8,
11599,
14,
1267,
430,
267,
1350,
275,
14836,
1332,
1267,
12,
1695,
430,
267,
367,
284,
315,
1425,
8,
1267,
304,
288,
2086,
275,
334,
73,
10,
975,
12,
378,
9,
288,
1350,
14,
15574,
8,
4060,
12,
2086,
9,
267,
291,
14,
16691,
275,
378,
267,
291,
14,
5553,
275,
7373,
267,
9324,
275,
13675,
14,
4593,
342,
267,
340,
1284,
14,
89,
665,
1343,
14,
89,
26,
288,
9324,
275,
13576,
446,
9324,
267,
1613,
11027,
826,
721,
14885,
14,
2960,
4589,
416,
332,
401,
378,
9,
267,
291,
14,
1365,
275,
1350,
267,
291,
14,
15362,
275,
446,
4593,
267,
11972,
8,
3049,
8,
928,
12,
1284,
395,
1350,
9,
5493,
347,
1678,
8,
277,
12,
5762,
521,
304,
267,
291,
14,
16691,
847,
5762,
521,
267,
340,
291,
14,
16691,
2356,
291,
14,
5553,
26,
288,
291,
14,
7237,
342,
199,
199,
533,
29591,
5012,
867,
8,
30185,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
304,
267,
1613,
11027,
826,
721,
1712,
12,
298,
3577,
5012,
867,
531,
267,
291,
14,
1897,
275,
378,
267,
291,
14,
681,
548,
275,
488,
267,
291,
14,
7237,
379,
275,
756,
2286,
347,
12927,
960,
8,
277,
12,
5982,
12,
1350,
12,
9150,
304,
267,
340,
440,
291,
14,
7237,
379,
26,
288,
291,
14,
1569,
275,
22865,
14,
912,
63,
1569,
480,
15697,
3577,
5012,
867,
531,
288,
291,
14,
7237,
379,
275,
715,
288,
291,
14,
681,
548,
275,
1626,
8182,
480,
4435,
15,
87,
323,
1312,
1017,
3471,
2802,
8,
549,
9,
2286,
347,
3795,
8,
277,
12,
24802,
304,
267,
340,
291,
14,
681,
548,
26,
288,
2249,
548,
1712,
275,
334,
277,
14,
1712,
446,
11388,
8,
16,
12,
291,
14,
681,
548,
14,
362,
63,
3333,
22251,
1194,
4992,
2960,
288,
24802,
14,
15574,
8,
277,
14,
681,
548,
12,
2249,
548,
1712,
9,
267,
1613,
1252,
3352,
8,
21579,
9,
2286,
347,
4057,
8,
277,
12,
10782,
304,
267,
1613,
1252,
1185,
8,
6046,
9,
267,
340,
291,
14,
1201,
14,
1019,
665,
378,
26,
288,
291,
14,
7237,
342,
2286,
347,
11972,
8,
277,
304,
267,
1613,
1252,
7237,
342,
267,
291,
14,
681,
548,
14,
2379,
342,
199,
199,
533,
9781,
6981,
11791,
8,
17141,
10464,
304,
272,
347,
636,
826,
721,
277,
12,
1347,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
1375,
275,
1347,
2286,
347,
641,
63,
2915,
8,
277,
12,
2086,
12,
5528,
304,
267,
4668,
275,
11388,
8,
1712,
9,
446,
291,
14,
1375,
14,
1712,
267,
870,
480,
15277,
6033,
370,
314,
1347,
6783,
4668,
14,
2960,
9,
268,
199,
318,
11972,
8,
6789,
12,
1350,
304,
272,
367,
1559,
315,
25132,
14,
2682,
14,
27495,
26,
267,
340,
2688,
8,
1113,
12,
298,
26551,
2349,
288,
340,
9150,
14,
761,
8409,
1201,
8,
1113,
14,
1201,
304,
355,
1559,
14,
26551,
8,
709,
12,
1350,
12,
9150,
9,
1467,
199,
533,
445,
12571,
26,
272,
347,
636,
826,
721,
277,
12,
2086,
12,
9362,
304,
267,
291,
14,
1712,
275,
2086,
267,
291,
14,
8017,
275,
9362,
2286,
347,
1048,
8409,
1201,
8,
277,
12,
8626,
304,
267,
2917,
275,
3473,
14,
5079,
1332,
1201,
14,
4218,
88,
446,
291,
14,
1712,
59,
16,
566,
538,
18,
435,
334,
1201,
14,
4218,
89,
446,
291,
14,
1712,
59,
17,
566,
538,
18,
9,
267,
372,
2917,
665,
291,
14,
8017,
199,
199,
533,
23704,
4527,
320,
438,
8,
6939,
304,
272,
347,
636,
826,
721,
277,
12,
2086,
304,
267,
1613,
11027,
826,
721,
22278,
14,
8252,
8,
16,
12,
16,
12,
16,
12,
16,
395,
2086,
29,
1712,
12,
23903,
29,
549,
9,
267,
291,
14,
1897,
275,
446,
17,
267,
7434,
275,
2400,
26,
25132,
14,
2682,
14,
2168,
8,
277,
9,
267,
291,
14,
1569,
275,
1626,
8182,
480,
4435,
15,
7241,
4527,
401,
9578,
63,
2894,
29,
2894,
680,
2802,
342,
2286,
347,
3795,
8,
277,
12,
24802,
304,
267,
24802,
14,
15574,
8,
277,
14,
1569,
12,
291,
14,
5485,
1712,
9,
199,
199,
533,
7030,
26,
272,
347,
636,
826,
721,
277,
12,
1343,
1712,
12,
26690,
304,
267,
291,
14,
928,
275,
1343,
1712,
267,
291,
14,
500,
275,
26690,
267,
5762,
275,
11388,
8,
277,
14,
500,
9,
446,
291,
14,
928,
267,
291,
14,
88,
17,
275,
1748,
8,
31837,
59,
16,
467,
26690,
59,
16,
566,
267,
291,
14,
88,
18,
275,
1390,
8,
31837,
59,
16,
467,
26690,
59,
16,
566,
267,
282,
275,
5762,
14,
89,
1182,
5762,
14,
88,
267,
330,
275,
291,
14,
928,
59,
17,
61,
446,
282,
627,
291,
14,
928,
59,
16,
61,
267,
291,
14,
585,
275,
2400,
671,
26,
282,
10,
88,
435,
330,
2286,
347,
1048,
8409,
1201,
8,
277,
12,
8626,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
judecalvillo/pyinotify
|
python2/examples/stats_threaded.py
|
9
|
1360
|
# Example: prints statistics (threaded version).
#
import time
import pyinotify
# Do the same thing than stats.py but with a ThreadedNotifier's
# instance.
# This example illustrates the use of this class but the recommanded
# implementation is whom of stats.py
class Identity(pyinotify.ProcessEvent):
def process_default(self, event):
# Does nothing, just to demonstrate how stuffs could be done
# after having processed statistics.
print 'Does nothing.'
# Thread #1
wm1 = pyinotify.WatchManager()
s1 = pyinotify.Stats() # Stats is a subclass of ProcessEvent
notifier1 = pyinotify.ThreadedNotifier(wm1, default_proc_fun=Identity(s1))
notifier1.start()
wm1.add_watch('/tmp/', pyinotify.ALL_EVENTS, rec=True, auto_add=True)
# Thread #2
wm2 = pyinotify.WatchManager()
s2 = pyinotify.Stats() # Stats is a subclass of ProcessEvent
notifier2 = pyinotify.ThreadedNotifier(wm2, default_proc_fun=Identity(s2))
notifier2.start()
wm2.add_watch('/var/log/', pyinotify.ALL_EVENTS, rec=False, auto_add=False)
while True:
try:
print "Thread 1", repr(s1)
print s1
print "Thread 2", repr(s2)
print s2
print
time.sleep(5)
except KeyboardInterrupt:
notifier1.stop()
notifier2.stop()
break
except:
notifier1.stop()
notifier2.stop()
raise
|
mit
|
[
3,
5679,
26,
14767,
11076,
334,
19710,
1015,
680,
199,
3,
199,
646,
900,
199,
646,
1134,
10175,
3338,
199,
199,
3,
4226,
314,
2011,
8377,
2419,
5020,
14,
647,
1325,
543,
282,
3868,
11698,
26884,
1159,
199,
3,
1256,
14,
199,
3,
961,
2893,
22907,
11409,
2335,
314,
675,
402,
642,
1021,
1325,
314,
295,
1404,
7028,
199,
3,
4514,
365,
12676,
402,
5020,
14,
647,
199,
199,
533,
22034,
8,
647,
10175,
3338,
14,
3498,
2390,
304,
272,
347,
2112,
63,
885,
8,
277,
12,
1566,
304,
267,
327,
12078,
6548,
12,
2951,
370,
23789,
18161,
4212,
8292,
83,
4293,
506,
4224,
267,
327,
2410,
9445,
7686,
11076,
14,
267,
870,
283,
6586,
6548,
3530,
199,
199,
3,
11086,
327,
17,
199,
16240,
17,
275,
1134,
10175,
3338,
14,
13978,
2988,
342,
199,
83,
17,
275,
1134,
10175,
3338,
14,
8257,
342,
327,
29062,
365,
282,
5516,
402,
7132,
2390,
199,
18031,
17,
275,
1134,
10175,
3338,
14,
31699,
26884,
8,
16240,
17,
12,
849,
63,
4687,
63,
7036,
29,
10193,
8,
83,
17,
430,
199,
18031,
17,
14,
928,
342,
199,
16240,
17,
14,
525,
63,
6821,
2336,
2791,
3678,
1134,
10175,
3338,
14,
1761,
63,
8193,
51,
12,
6488,
29,
549,
12,
2599,
63,
525,
29,
549,
9,
199,
199,
3,
11086,
327,
18,
199,
16240,
18,
275,
1134,
10175,
3338,
14,
13978,
2988,
342,
199,
83,
18,
275,
1134,
10175,
3338,
14,
8257,
342,
327,
29062,
365,
282,
5516,
402,
7132,
2390,
199,
18031,
18,
275,
1134,
10175,
3338,
14,
31699,
26884,
8,
16240,
18,
12,
849,
63,
4687,
63,
7036,
29,
10193,
8,
83,
18,
430,
199,
18031,
18,
14,
928,
342,
199,
16240,
18,
14,
525,
63,
6821,
2336,
1391,
15,
793,
3678,
1134,
10175,
3338,
14,
1761,
63,
8193,
51,
12,
6488,
29,
797,
12,
2599,
63,
525,
29,
797,
9,
199,
199,
6710,
715,
26,
272,
862,
26,
267,
870,
298,
4436,
413,
401,
4700,
8,
83,
17,
9,
267,
870,
308,
17,
267,
870,
298,
4436,
499,
401,
4700,
8,
83,
18,
9,
267,
870,
308,
18,
267,
870,
267,
900,
14,
4532,
8,
21,
9,
272,
871,
13483,
26,
267,
30154,
17,
14,
2379,
342,
267,
30154,
18,
14,
2379,
342,
267,
2059,
272,
871,
26,
267,
30154,
17,
14,
2379,
342,
267,
30154,
18,
14,
2379,
342,
267,
746,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5679,
26,
14767,
11076,
334,
19710,
1015,
680,
199,
3,
199,
646,
900,
199,
646,
1134,
10175,
3338,
199,
199,
3,
4226,
314,
2011,
8377,
2419,
5020,
14,
647,
1325,
543,
282,
3868,
11698,
26884,
1159,
199,
3,
1256,
14,
199,
3,
961,
2893,
22907,
11409,
2335,
314,
675,
402,
642,
1021,
1325,
314,
295,
1404,
7028,
199,
3,
4514,
365,
12676,
402,
5020,
14,
647,
199,
199,
533,
22034,
8,
647,
10175,
3338,
14,
3498,
2390,
304,
272,
347,
2112,
63,
885,
8,
277,
12,
1566,
304,
267,
327,
12078,
6548,
12,
2951,
370,
23789,
18161,
4212,
8292,
83,
4293,
506,
4224,
267,
327,
2410,
9445,
7686,
11076,
14,
267,
870,
283,
6586,
6548,
3530,
199,
199,
3,
11086,
327,
17,
199,
16240,
17,
275,
1134,
10175,
3338,
14,
13978,
2988,
342,
199,
83,
17,
275,
1134,
10175,
3338,
14,
8257,
342,
327,
29062,
365,
282,
5516,
402,
7132,
2390,
199,
18031,
17,
275,
1134,
10175,
3338,
14,
31699,
26884,
8,
16240,
17,
12,
849,
63,
4687,
63,
7036,
29,
10193,
8,
83,
17,
430,
199,
18031,
17,
14,
928,
342,
199,
16240,
17,
14,
525,
63,
6821,
2336,
2791,
3678,
1134,
10175,
3338,
14,
1761,
63,
8193,
51,
12,
6488,
29,
549,
12,
2599,
63,
525,
29,
549,
9,
199,
199,
3,
11086,
327,
18,
199,
16240,
18,
275,
1134,
10175,
3338,
14,
13978,
2988,
342,
199,
83,
18,
275,
1134,
10175,
3338,
14,
8257,
342,
327,
29062,
365,
282,
5516,
402,
7132,
2390,
199,
18031,
18,
275,
1134,
10175,
3338,
14,
31699,
26884,
8,
16240,
18,
12,
849,
63,
4687,
63,
7036,
29,
10193,
8,
83,
18,
430,
199,
18031,
18,
14,
928,
342,
199,
16240,
18,
14,
525,
63,
6821,
2336,
1391,
15,
793,
3678,
1134,
10175,
3338,
14,
1761,
63,
8193,
51,
12,
6488,
29,
797,
12,
2599,
63,
525,
29,
797,
9,
199,
199,
6710,
715,
26,
272,
862,
26,
267,
870,
298,
4436,
413,
401,
4700,
8,
83,
17,
9,
267,
870,
308,
17,
267,
870,
298,
4436,
499,
401,
4700,
8,
83,
18,
9,
267,
870,
308,
18,
267,
870,
267,
900,
14,
4532,
8,
21,
9,
272,
871,
13483,
26,
267,
30154,
17,
14,
2379,
342,
267,
30154,
18,
14,
2379,
342,
267,
2059,
272,
871,
26,
267,
30154,
17,
14,
2379,
342,
267,
30154,
18,
14,
2379,
342,
267,
746,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
Oefenweb/python-untraceables
|
untraceables/utilities/mysql.py
|
1
|
3852
|
# -*- coding: utf-8 -*-
"""
MySQL utility functions.
"""
from __future__ import absolute_import
from warnings import filterwarnings
import MySQLdb
import MySQLdb.cursors
from untraceables.utilities import query as query_utility
filterwarnings('ignore', category=MySQLdb.Warning)
def get_connection(host, user, password, database):
"""
Gets a mysql connection to given database.
:type str
:param host: A host
:type str
:param user: A username
:type str
:param password: A password
:type str
:param database: A database name
:rtype MySQLdb.connections.Connection
:return A mysql connection
"""
return MySQLdb.connect(host=host, user=user, passwd=password, db=database, cursorclass=MySQLdb.cursors.SSDictCursor)
def get_cursor(connection):
"""
Gets a cursor from a given connection.
:type MySQLdb.connections.Connection
:param connection: A mysql connection
:rtype MySQLdb.cursors.SSDictCursor
:return A mysql cursor
"""
return connection.cursor()
def close_connection_and_cursor(connection, cursor):
"""
Closes a given connection and cursor.
:type MySQLdb.connections.Connection
:param connection: A mysql connection
:type MySQLdb.cursors.SSDictCursor
:param cursor: A mysql cursor
:rtype bool
:return: Success
"""
attr = 'close'
for to_be_closed_o in (cursor, connection):
if hasattr(to_be_closed_o, attr):
getattr(to_be_closed_o, attr)
return True
def split_file(file_pointer, delimiter=';'):
"""
Splits a SQL file by a given delimiter so it can be executed statement by statement.
:type file
:param file_pointer: The file pointer to an unsplitted SQL file
:type str
:param delimiter: A delimiter
:rtype generator
:return A splitted SQL file
"""
buf = ''
while True:
while delimiter in buf:
pos = buf.index(delimiter)
yield buf[:pos]
buf = buf[pos + len(delimiter):]
chunk = file_pointer.read(4096)
if not chunk:
yield buf
break
buf += chunk
def get_show_columns(cursor, table):
"""
Gets the results of SHOW COLUMNS for a given table.
:type MySQLdb.cursors.SSDictCursor
:param cursor: A mysql cursor
:type str
:param table: A table name
:rtype tuple
:return The results of SHOW COLUMNS
"""
return _fetchall(cursor, query_utility.get_show_table_columns(table))
def get_show_tables(cursor, database):
"""
Gets the results of SHOW TABLES for a given database.
:type MySQLdb.cursors.SSDictCursor
:param cursor: A mysql cursor
:type str
:param database: A database name
:rtype tuple
:return The results of SHOW TABLES
"""
return _fetchall(cursor, query_utility.get_show_columns(database))
def get_max_id(cursor, database, table, column, order=None):
"""
Gets the maximum id for a given table / column.
:type MySQLdb.cursors.SSDictCursor
:param cursor: A mysql cursor
:type str
:param database: A database name
:type str
:param table: A table name
:type str
:param column: A column name
:type str
:param order: A column name to order on
:rtype long|bool
:return: The maximum id or False on failure
"""
for row in _fetchall(cursor, query_utility.get_max_id(database, table, column, order)):
return row[column]
return False
def _fetchall(cursor, statement):
"""
Fetches the results of a given SQL statement.
:type MySQLdb.cursors.SSDictCursor
:param cursor: A mysql cursor
:type str
:param statement: A SQL statement
:rtype tuple
:return The results of the MySQLdb statement
"""
cursor.execute(statement)
return cursor.fetchall()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
20784,
11420,
3423,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
3598,
492,
2457,
5451,
199,
646,
25709,
199,
646,
25709,
14,
17255,
1384,
199,
504,
625,
3446,
5921,
14,
16355,
492,
1827,
465,
1827,
63,
16877,
199,
199,
23945,
360,
4247,
297,
4637,
29,
20784,
697,
14,
3849,
9,
421,
199,
318,
664,
63,
2105,
8,
1102,
12,
922,
12,
2505,
12,
3050,
304,
272,
408,
272,
14509,
282,
12896,
1950,
370,
1627,
3050,
14,
339,
520,
466,
620,
272,
520,
635,
1591,
26,
437,
1591,
272,
520,
466,
620,
272,
520,
635,
922,
26,
437,
3434,
272,
520,
466,
620,
272,
520,
635,
2505,
26,
437,
2505,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
4500,
25709,
14,
7995,
14,
3225,
272,
520,
1107,
437,
12896,
1950,
272,
408,
339,
372,
25709,
14,
2242,
8,
1102,
29,
1102,
12,
922,
29,
751,
12,
15081,
29,
2060,
12,
1592,
29,
4659,
12,
3920,
533,
29,
20784,
697,
14,
17255,
1384,
14,
2300,
2141,
8993,
9,
421,
199,
318,
664,
63,
3937,
8,
2105,
304,
272,
408,
272,
14509,
282,
3920,
687,
282,
1627,
1950,
14,
339,
520,
466,
25709,
14,
7995,
14,
3225,
272,
520,
635,
1950,
26,
437,
12896,
1950,
272,
520,
4500,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
1107,
437,
12896,
3920,
272,
408,
339,
372,
1950,
14,
3937,
342,
421,
199,
318,
4002,
63,
2105,
63,
460,
63,
3937,
8,
2105,
12,
3920,
304,
272,
408,
272,
5980,
874,
282,
1627,
1950,
436,
3920,
14,
339,
520,
466,
25709,
14,
7995,
14,
3225,
272,
520,
635,
1950,
26,
437,
12896,
1950,
272,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
4500,
2155,
272,
520,
1107,
26,
22318,
272,
408,
339,
1921,
275,
283,
1600,
7,
272,
367,
370,
63,
1235,
63,
5938,
63,
79,
315,
334,
3937,
12,
1950,
304,
267,
340,
2688,
8,
475,
63,
1235,
63,
5938,
63,
79,
12,
1921,
304,
288,
2519,
8,
475,
63,
1235,
63,
5938,
63,
79,
12,
1921,
9,
339,
372,
715,
421,
199,
318,
3715,
63,
493,
8,
493,
63,
3929,
12,
11172,
534,
27,
735,
272,
408,
272,
11740,
83,
282,
5385,
570,
701,
282,
1627,
11172,
880,
652,
883,
506,
7934,
5164,
701,
5164,
14,
339,
520,
466,
570,
272,
520,
635,
570,
63,
3929,
26,
710,
570,
7849,
370,
376,
625,
1294,
471,
5385,
570,
272,
520,
466,
620,
272,
520,
635,
11172,
26,
437,
11172,
272,
520,
4500,
4306,
272,
520,
1107,
437,
30183,
5385,
570,
272,
408,
339,
4123,
275,
2125,
272,
1830,
715,
26,
267,
1830,
11172,
315,
4123,
26,
288,
2086,
275,
4123,
14,
1080,
8,
15104,
9,
288,
1995,
4123,
1491,
1712,
61,
288,
4123,
275,
4123,
59,
1712,
435,
822,
8,
15104,
15405,
267,
3728,
275,
570,
63,
3929,
14,
739,
8,
20579,
9,
267,
340,
440,
3728,
26,
288,
1995,
4123,
288,
2059,
267,
4123,
847,
3728,
421,
199,
318,
664,
63,
2384,
63,
3406,
8,
3937,
12,
1817,
304,
272,
408,
272,
14509,
314,
2058,
402,
428,
16210,
26865,
2709,
367,
282,
1627,
1817,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
1817,
26,
437,
1817,
536,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
428,
16210,
26865,
2709,
272,
408,
339,
372,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
2384,
63,
1224,
63,
3406,
8,
1224,
430,
421,
199,
318,
664,
63,
2384,
63,
5987,
8,
3937,
12,
3050,
304,
272,
408,
272,
14509,
314,
2058,
402,
428,
16210,
377,
17041,
367,
282,
1627,
3050,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
428,
16210,
377,
17041,
272,
408,
339,
372,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
2384,
63,
3406,
8,
4659,
430,
421,
199,
318,
664,
63,
988,
63,
344,
8,
3937,
12,
3050,
12,
1817,
12,
2763,
12,
1865,
29,
403,
304,
272,
408,
272,
14509,
314,
5696,
1305,
367,
282,
1627,
1817,
1182,
2763,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
466,
620,
272,
520,
635,
1817,
26,
437,
1817,
536,
272,
520,
466,
620,
272,
520,
635,
2763,
26,
437,
2763,
536,
272,
520,
466,
620,
272,
520,
635,
1865,
26,
437,
2763,
536,
370,
1865,
641,
272,
520,
4500,
1846,
92,
2245,
272,
520,
1107,
26,
710,
5696,
1305,
503,
756,
641,
5988,
272,
408,
339,
367,
1962,
315,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
988,
63,
344,
8,
4659,
12,
1817,
12,
2763,
12,
1865,
2298,
267,
372,
1962,
59,
2301,
61,
339,
372,
756,
421,
199,
318,
485,
10174,
8,
3937,
12,
5164,
304,
272,
408,
272,
16347,
397,
314,
2058,
402,
282,
1627,
5385,
5164,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
5164,
26,
437,
5385,
5164,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
314,
25709,
5164,
272,
408,
339,
3920,
14,
2526,
8,
6242,
9,
339,
372,
3920,
14,
10174,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
20784,
11420,
3423,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
3598,
492,
2457,
5451,
199,
646,
25709,
199,
646,
25709,
14,
17255,
1384,
199,
504,
625,
3446,
5921,
14,
16355,
492,
1827,
465,
1827,
63,
16877,
199,
199,
23945,
360,
4247,
297,
4637,
29,
20784,
697,
14,
3849,
9,
421,
199,
318,
664,
63,
2105,
8,
1102,
12,
922,
12,
2505,
12,
3050,
304,
272,
408,
272,
14509,
282,
12896,
1950,
370,
1627,
3050,
14,
339,
520,
466,
620,
272,
520,
635,
1591,
26,
437,
1591,
272,
520,
466,
620,
272,
520,
635,
922,
26,
437,
3434,
272,
520,
466,
620,
272,
520,
635,
2505,
26,
437,
2505,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
4500,
25709,
14,
7995,
14,
3225,
272,
520,
1107,
437,
12896,
1950,
272,
408,
339,
372,
25709,
14,
2242,
8,
1102,
29,
1102,
12,
922,
29,
751,
12,
15081,
29,
2060,
12,
1592,
29,
4659,
12,
3920,
533,
29,
20784,
697,
14,
17255,
1384,
14,
2300,
2141,
8993,
9,
421,
199,
318,
664,
63,
3937,
8,
2105,
304,
272,
408,
272,
14509,
282,
3920,
687,
282,
1627,
1950,
14,
339,
520,
466,
25709,
14,
7995,
14,
3225,
272,
520,
635,
1950,
26,
437,
12896,
1950,
272,
520,
4500,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
1107,
437,
12896,
3920,
272,
408,
339,
372,
1950,
14,
3937,
342,
421,
199,
318,
4002,
63,
2105,
63,
460,
63,
3937,
8,
2105,
12,
3920,
304,
272,
408,
272,
5980,
874,
282,
1627,
1950,
436,
3920,
14,
339,
520,
466,
25709,
14,
7995,
14,
3225,
272,
520,
635,
1950,
26,
437,
12896,
1950,
272,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
4500,
2155,
272,
520,
1107,
26,
22318,
272,
408,
339,
1921,
275,
283,
1600,
7,
272,
367,
370,
63,
1235,
63,
5938,
63,
79,
315,
334,
3937,
12,
1950,
304,
267,
340,
2688,
8,
475,
63,
1235,
63,
5938,
63,
79,
12,
1921,
304,
288,
2519,
8,
475,
63,
1235,
63,
5938,
63,
79,
12,
1921,
9,
339,
372,
715,
421,
199,
318,
3715,
63,
493,
8,
493,
63,
3929,
12,
11172,
534,
27,
735,
272,
408,
272,
11740,
83,
282,
5385,
570,
701,
282,
1627,
11172,
880,
652,
883,
506,
7934,
5164,
701,
5164,
14,
339,
520,
466,
570,
272,
520,
635,
570,
63,
3929,
26,
710,
570,
7849,
370,
376,
625,
1294,
471,
5385,
570,
272,
520,
466,
620,
272,
520,
635,
11172,
26,
437,
11172,
272,
520,
4500,
4306,
272,
520,
1107,
437,
30183,
5385,
570,
272,
408,
339,
4123,
275,
2125,
272,
1830,
715,
26,
267,
1830,
11172,
315,
4123,
26,
288,
2086,
275,
4123,
14,
1080,
8,
15104,
9,
288,
1995,
4123,
1491,
1712,
61,
288,
4123,
275,
4123,
59,
1712,
435,
822,
8,
15104,
15405,
267,
3728,
275,
570,
63,
3929,
14,
739,
8,
20579,
9,
267,
340,
440,
3728,
26,
288,
1995,
4123,
288,
2059,
267,
4123,
847,
3728,
421,
199,
318,
664,
63,
2384,
63,
3406,
8,
3937,
12,
1817,
304,
272,
408,
272,
14509,
314,
2058,
402,
428,
16210,
26865,
2709,
367,
282,
1627,
1817,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
1817,
26,
437,
1817,
536,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
428,
16210,
26865,
2709,
272,
408,
339,
372,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
2384,
63,
1224,
63,
3406,
8,
1224,
430,
421,
199,
318,
664,
63,
2384,
63,
5987,
8,
3937,
12,
3050,
304,
272,
408,
272,
14509,
314,
2058,
402,
428,
16210,
377,
17041,
367,
282,
1627,
3050,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
428,
16210,
377,
17041,
272,
408,
339,
372,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
2384,
63,
3406,
8,
4659,
430,
421,
199,
318,
664,
63,
988,
63,
344,
8,
3937,
12,
3050,
12,
1817,
12,
2763,
12,
1865,
29,
403,
304,
272,
408,
272,
14509,
314,
5696,
1305,
367,
282,
1627,
1817,
1182,
2763,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
3050,
26,
437,
3050,
536,
272,
520,
466,
620,
272,
520,
635,
1817,
26,
437,
1817,
536,
272,
520,
466,
620,
272,
520,
635,
2763,
26,
437,
2763,
536,
272,
520,
466,
620,
272,
520,
635,
1865,
26,
437,
2763,
536,
370,
1865,
641,
272,
520,
4500,
1846,
92,
2245,
272,
520,
1107,
26,
710,
5696,
1305,
503,
756,
641,
5988,
272,
408,
339,
367,
1962,
315,
485,
10174,
8,
3937,
12,
1827,
63,
16877,
14,
362,
63,
988,
63,
344,
8,
4659,
12,
1817,
12,
2763,
12,
1865,
2298,
267,
372,
1962,
59,
2301,
61,
339,
372,
756,
421,
199,
318,
485,
10174,
8,
3937,
12,
5164,
304,
272,
408,
272,
16347,
397,
314,
2058,
402,
282,
1627,
5385,
5164,
14,
339,
520,
466,
25709,
14,
17255,
1384,
14,
2300,
2141,
8993,
272,
520,
635,
3920,
26,
437,
12896,
3920,
272,
520,
466,
620,
272,
520,
635,
5164,
26,
437,
5385,
5164,
272,
520,
4500,
2008,
272,
520,
1107,
710,
2058,
402,
314,
25709,
5164,
272,
408,
339,
3920,
14,
2526,
8,
6242,
9,
339,
372,
3920,
14,
10174,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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parser.add_option('--loginput_host', help='MozDef Loginput host (default: http://127.0.0.1:8080)', default='http://127.0.0.1:8080')
parser.add_option('--num_times', help='Number of times event is sent to loginput (default: 20)', default=20)
options, arguments = parser.parse_args()
# Fill in with events you want to write
events = [
{
"category": "testcategory",
"details": {
"program": "sshd",
"type": "Success Login",
"username": "ttesterson",
"sourceipaddress": '1.2.3.4',
},
"processname": "auth0_cron",
"severity": "INFO",
"source": "auth0",
"summary": "login invalid ldap_count_entries failed",
"tags": ["auth0"],
}
]
for num in range(0, options.num_times):
for event in events:
mozmsg = mozdef.MozDefEvent(options.loginput_host + "/events/")
for key, value in event.items():
setattr(mozmsg, key, value)
mozmsg.send()
print("Wrote event to loginput")
time.sleep(0.2)
|
mpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
900,
199,
646,
8691,
199,
199,
646,
1303,
90,
318,
63,
1258,
465,
1303,
90,
318,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
2087,
14,
525,
63,
1422,
4517,
793,
1210,
63,
1102,
297,
1720,
534,
3716,
90,
6172,
16430,
524,
1591,
334,
885,
26,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
15844,
3196,
849,
534,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
15844,
358,
199,
2087,
14,
525,
63,
1422,
4517,
1507,
63,
4508,
297,
1720,
534,
3259,
402,
5431,
1566,
365,
4847,
370,
4676,
524,
334,
885,
26,
3388,
3196,
849,
29,
1165,
9,
199,
1419,
12,
2368,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
24797,
315,
543,
4474,
1265,
2934,
370,
2218,
199,
4368,
275,
359,
272,
469,
267,
298,
3710,
582,
298,
396,
3710,
401,
267,
298,
5087,
582,
469,
288,
298,
6815,
582,
298,
5510,
68,
401,
288,
298,
466,
582,
298,
8300,
16430,
401,
288,
298,
2473,
582,
298,
84,
8234,
834,
401,
288,
298,
1365,
21809,
582,
283,
17,
14,
18,
14,
19,
14,
20,
297,
267,
1660,
267,
298,
1412,
354,
582,
298,
1178,
16,
63,
14829,
401,
267,
298,
20394,
582,
298,
4531,
401,
267,
298,
1365,
582,
298,
1178,
16,
401,
267,
298,
4705,
582,
298,
2886,
3866,
13727,
63,
835,
63,
3189,
3405,
401,
267,
298,
2969,
582,
2097,
1178,
16,
2255,
272,
789,
199,
61,
199,
199,
509,
1967,
315,
1425,
8,
16,
12,
1511,
14,
1507,
63,
4508,
304,
272,
367,
1566,
315,
4474,
26,
267,
1303,
90,
1328,
275,
1303,
90,
318,
14,
3716,
90,
6172,
2390,
8,
1419,
14,
793,
1210,
63,
1102,
435,
3286,
4368,
13589,
267,
367,
790,
12,
574,
315,
1566,
14,
1744,
837,
288,
5371,
8,
23120,
1328,
12,
790,
12,
574,
9,
267,
1303,
90,
1328,
14,
2254,
342,
267,
870,
480,
55,
22665,
1566,
370,
4676,
524,
531,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
900,
199,
646,
8691,
199,
199,
646,
1303,
90,
318,
63,
1258,
465,
1303,
90,
318,
199,
199,
2087,
275,
8691,
14,
14553,
342,
199,
2087,
14,
525,
63,
1422,
4517,
793,
1210,
63,
1102,
297,
1720,
534,
3716,
90,
6172,
16430,
524,
1591,
334,
885,
26,
1455,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
15844,
3196,
849,
534,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
26,
15844,
358,
199,
2087,
14,
525,
63,
1422,
4517,
1507,
63,
4508,
297,
1720,
534,
3259,
402,
5431,
1566,
365,
4847,
370,
4676,
524,
334,
885,
26,
3388,
3196,
849,
29,
1165,
9,
199,
1419,
12,
2368,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
3,
24797,
315,
543,
4474,
1265,
2934,
370,
2218,
199,
4368,
275,
359,
272,
469,
267,
298,
3710,
582,
298,
396,
3710,
401,
267,
298,
5087,
582,
469,
288,
298,
6815,
582,
298,
5510,
68,
401,
288,
298,
466,
582,
298,
8300,
16430,
401,
288,
298,
2473,
582,
298,
84,
8234,
834,
401,
288,
298,
1365,
21809,
582,
283,
17,
14,
18,
14,
19,
14,
20,
297,
267,
1660,
267,
298,
1412,
354,
582,
298,
1178,
16,
63,
14829,
401,
267,
298,
20394,
582,
298,
4531,
401,
267,
298,
1365,
582,
298,
1178,
16,
401,
267,
298,
4705,
582,
298,
2886,
3866,
13727,
63,
835,
63,
3189,
3405,
401,
267,
298,
2969,
582,
2097,
1178,
16,
2255,
272,
789,
199,
61,
199,
199,
509,
1967,
315,
1425,
8,
16,
12,
1511,
14,
1507,
63,
4508,
304,
272,
367,
1566,
315,
4474,
26,
267,
1303,
90,
1328,
275,
1303,
90,
318,
14,
3716,
90,
6172,
2390,
8,
1419,
14,
793,
1210,
63,
1102,
435,
3286,
4368,
13589,
267,
367,
790,
12,
574,
315,
1566,
14,
1744,
837,
288,
5371,
8,
23120,
1328,
12,
790,
12,
574,
9,
267,
1303,
90,
1328,
14,
2254,
342,
267,
870,
480,
55,
22665,
1566,
370,
4676,
524,
531,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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el Corporation.
# 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 neutron.api.v2 import attributes as attrs
from neutron.db import common_db_mixin
from neutron.db import portsecurity_db_common as ps_db_common
from neutron.extensions import portsecurity as psec
from neutron.i18n import _LI
from neutron.plugins.ml2 import driver_api as api
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
class PortSecurityExtensionDriver(api.ExtensionDriver,
ps_db_common.PortSecurityDbCommon,
common_db_mixin.CommonDbMixin):
_supported_extension_alias = 'port-security'
def initialize(self):
LOG.info(_LI("PortSecurityExtensionDriver initialization complete"))
@property
def extension_alias(self):
return self._supported_extension_alias
def process_create_network(self, context, data, result):
# Create the network extension attributes.
if psec.PORTSECURITY not in data:
data[psec.PORTSECURITY] = (psec.EXTENDED_ATTRIBUTES_2_0['networks']
[psec.PORTSECURITY]['default'])
self._process_network_port_security_create(context, data, result)
def process_update_network(self, context, data, result):
# Update the network extension attributes.
if psec.PORTSECURITY in data:
self._process_network_port_security_update(context, data, result)
def process_create_port(self, context, data, result):
# Create the port extension attributes.
data[psec.PORTSECURITY] = self._determine_port_security(context, data)
self._process_port_port_security_create(context, data, result)
def process_update_port(self, context, data, result):
if psec.PORTSECURITY in data:
self._process_port_port_security_update(
context, data, result)
def extend_network_dict(self, session, db_data, result):
self._extend_port_security_dict(result, db_data)
def extend_port_dict(self, session, db_data, result):
self._extend_port_security_dict(result, db_data)
def _extend_port_security_dict(self, response_data, db_data):
if db_data.get('port_security') is None:
response_data[psec.PORTSECURITY] = (
psec.EXTENDED_ATTRIBUTES_2_0['networks']
[psec.PORTSECURITY]['default'])
else:
response_data[psec.PORTSECURITY] = (
db_data['port_security'][psec.PORTSECURITY])
def _determine_port_security(self, context, port):
"""Returns a boolean (port_security_enabled).
Port_security is the value associated with the port if one is present
otherwise the value associated with the network is returned.
"""
# we don't apply security groups for dhcp, router
if (port.get('device_owner') and
port['device_owner'].startswith('network:')):
return False
if attrs.is_attr_set(port.get(psec.PORTSECURITY)):
port_security_enabled = port[psec.PORTSECURITY]
else:
port_security_enabled = self._get_network_security_binding(
context, port['network_id'])
return port_security_enabled
|
apache-2.0
|
[
3,
1898,
6900,
20619,
11098,
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,
8224,
14,
1246,
14,
86,
18,
492,
3004,
465,
3290,
199,
504,
8224,
14,
697,
492,
2863,
63,
697,
63,
20406,
199,
504,
8224,
14,
697,
492,
1844,
4416,
63,
697,
63,
2330,
465,
7347,
63,
697,
63,
2330,
199,
504,
8224,
14,
5359,
492,
1844,
4416,
465,
299,
3321,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
2673,
199,
504,
8224,
14,
5265,
14,
757,
18,
492,
5253,
63,
1246,
465,
2986,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
10977,
7676,
6382,
6158,
8,
1246,
14,
6382,
6158,
12,
3303,
7347,
63,
697,
63,
2330,
14,
4313,
7676,
8882,
7844,
12,
3303,
2863,
63,
697,
63,
20406,
14,
7844,
8882,
4256,
304,
272,
485,
4946,
63,
3435,
63,
3620,
275,
283,
719,
13,
4416,
7,
339,
347,
8265,
8,
277,
304,
267,
5051,
14,
815,
1547,
2673,
480,
4313,
7676,
6382,
6158,
11097,
4890,
2237,
339,
768,
1829,
272,
347,
3329,
63,
3620,
8,
277,
304,
267,
372,
291,
423,
4946,
63,
3435,
63,
3620,
339,
347,
2112,
63,
981,
63,
1200,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
2790,
314,
2784,
3329,
3004,
14,
267,
340,
299,
3321,
14,
3657,
13554,
440,
315,
666,
26,
288,
666,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
80,
3321,
14,
27059,
63,
18166,
63,
18,
63,
16,
459,
7642,
418,
4318,
359,
80,
3321,
14,
3657,
13554,
2733,
885,
1105,
267,
291,
423,
1412,
63,
1200,
63,
719,
63,
4416,
63,
981,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
873,
63,
1200,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
6162,
314,
2784,
3329,
3004,
14,
267,
340,
299,
3321,
14,
3657,
13554,
315,
666,
26,
288,
291,
423,
1412,
63,
1200,
63,
719,
63,
4416,
63,
873,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
981,
63,
719,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
2790,
314,
1844,
3329,
3004,
14,
267,
666,
59,
80,
3321,
14,
3657,
13554,
61,
275,
291,
423,
22189,
63,
719,
63,
4416,
8,
1100,
12,
666,
9,
267,
291,
423,
1412,
63,
719,
63,
719,
63,
4416,
63,
981,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
873,
63,
719,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
340,
299,
3321,
14,
3657,
13554,
315,
666,
26,
288,
291,
423,
1412,
63,
719,
63,
719,
63,
4416,
63,
873,
8,
355,
1067,
12,
666,
12,
754,
9,
339,
347,
12247,
63,
1200,
63,
807,
8,
277,
12,
2351,
12,
1592,
63,
576,
12,
754,
304,
267,
291,
423,
2880,
63,
719,
63,
4416,
63,
807,
8,
1099,
12,
1592,
63,
576,
9,
339,
347,
12247,
63,
719,
63,
807,
8,
277,
12,
2351,
12,
1592,
63,
576,
12,
754,
304,
267,
291,
423,
2880,
63,
719,
63,
4416,
63,
807,
8,
1099,
12,
1592,
63,
576,
9,
339,
347,
485,
2880,
63,
719,
63,
4416,
63,
807,
8,
277,
12,
1177,
63,
576,
12,
1592,
63,
576,
304,
267,
340,
1592,
63,
576,
14,
362,
360,
719,
63,
4416,
358,
365,
488,
26,
288,
1177,
63,
576,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
355,
299,
3321,
14,
27059,
63,
18166,
63,
18,
63,
16,
459,
7642,
418,
355,
359,
80,
3321,
14,
3657,
13554,
2733,
885,
1105,
267,
587,
26,
288,
1177,
63,
576,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
1816,
1592,
63,
576,
459,
719,
63,
4416,
3488,
80,
3321,
14,
3657,
13554,
566,
339,
347,
485,
22189,
63,
719,
63,
4416,
8,
277,
12,
1067,
12,
1844,
304,
267,
408,
3407,
282,
5046,
334,
719,
63,
4416,
63,
3827,
680,
398,
10977,
63,
4416,
365,
314,
574,
4568,
543,
314,
1844,
340,
1373,
365,
3451,
267,
4257,
314,
574,
4568,
543,
314,
2784,
365,
2138,
14,
267,
408,
267,
327,
781,
2793,
1133,
4838,
6391,
4652,
367,
19064,
12,
6197,
267,
340,
334,
719,
14,
362,
360,
1782,
63,
4597,
358,
436,
355,
1844,
459,
1782,
63,
4597,
2278,
2460,
360,
1200,
26,
8109,
288,
372,
756,
398,
340,
3290,
14,
374,
63,
962,
63,
409,
8,
719,
14,
362,
8,
80,
3321,
14,
3657,
13554,
2298,
288,
1844,
63,
4416,
63,
3827,
275,
1844,
59,
80,
3321,
14,
3657,
13554,
61,
267,
587,
26,
288,
1844,
63,
4416,
63,
3827,
275,
291,
423,
362,
63,
1200,
63,
4416,
63,
9140,
8,
355,
1067,
12,
1844,
459,
1200,
63,
344,
1105,
398,
372,
1844,
63,
4416,
63,
3827,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6900,
20619,
11098,
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,
8224,
14,
1246,
14,
86,
18,
492,
3004,
465,
3290,
199,
504,
8224,
14,
697,
492,
2863,
63,
697,
63,
20406,
199,
504,
8224,
14,
697,
492,
1844,
4416,
63,
697,
63,
2330,
465,
7347,
63,
697,
63,
2330,
199,
504,
8224,
14,
5359,
492,
1844,
4416,
465,
299,
3321,
199,
504,
8224,
14,
73,
1085,
78,
492,
485,
2673,
199,
504,
8224,
14,
5265,
14,
757,
18,
492,
5253,
63,
1246,
465,
2986,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
10977,
7676,
6382,
6158,
8,
1246,
14,
6382,
6158,
12,
3303,
7347,
63,
697,
63,
2330,
14,
4313,
7676,
8882,
7844,
12,
3303,
2863,
63,
697,
63,
20406,
14,
7844,
8882,
4256,
304,
272,
485,
4946,
63,
3435,
63,
3620,
275,
283,
719,
13,
4416,
7,
339,
347,
8265,
8,
277,
304,
267,
5051,
14,
815,
1547,
2673,
480,
4313,
7676,
6382,
6158,
11097,
4890,
2237,
339,
768,
1829,
272,
347,
3329,
63,
3620,
8,
277,
304,
267,
372,
291,
423,
4946,
63,
3435,
63,
3620,
339,
347,
2112,
63,
981,
63,
1200,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
2790,
314,
2784,
3329,
3004,
14,
267,
340,
299,
3321,
14,
3657,
13554,
440,
315,
666,
26,
288,
666,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
80,
3321,
14,
27059,
63,
18166,
63,
18,
63,
16,
459,
7642,
418,
4318,
359,
80,
3321,
14,
3657,
13554,
2733,
885,
1105,
267,
291,
423,
1412,
63,
1200,
63,
719,
63,
4416,
63,
981,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
873,
63,
1200,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
6162,
314,
2784,
3329,
3004,
14,
267,
340,
299,
3321,
14,
3657,
13554,
315,
666,
26,
288,
291,
423,
1412,
63,
1200,
63,
719,
63,
4416,
63,
873,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
981,
63,
719,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
327,
2790,
314,
1844,
3329,
3004,
14,
267,
666,
59,
80,
3321,
14,
3657,
13554,
61,
275,
291,
423,
22189,
63,
719,
63,
4416,
8,
1100,
12,
666,
9,
267,
291,
423,
1412,
63,
719,
63,
719,
63,
4416,
63,
981,
8,
1100,
12,
666,
12,
754,
9,
339,
347,
2112,
63,
873,
63,
719,
8,
277,
12,
1067,
12,
666,
12,
754,
304,
267,
340,
299,
3321,
14,
3657,
13554,
315,
666,
26,
288,
291,
423,
1412,
63,
719,
63,
719,
63,
4416,
63,
873,
8,
355,
1067,
12,
666,
12,
754,
9,
339,
347,
12247,
63,
1200,
63,
807,
8,
277,
12,
2351,
12,
1592,
63,
576,
12,
754,
304,
267,
291,
423,
2880,
63,
719,
63,
4416,
63,
807,
8,
1099,
12,
1592,
63,
576,
9,
339,
347,
12247,
63,
719,
63,
807,
8,
277,
12,
2351,
12,
1592,
63,
576,
12,
754,
304,
267,
291,
423,
2880,
63,
719,
63,
4416,
63,
807,
8,
1099,
12,
1592,
63,
576,
9,
339,
347,
485,
2880,
63,
719,
63,
4416,
63,
807,
8,
277,
12,
1177,
63,
576,
12,
1592,
63,
576,
304,
267,
340,
1592,
63,
576,
14,
362,
360,
719,
63,
4416,
358,
365,
488,
26,
288,
1177,
63,
576,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
355,
299,
3321,
14,
27059,
63,
18166,
63,
18,
63,
16,
459,
7642,
418,
355,
359,
80,
3321,
14,
3657,
13554,
2733,
885,
1105,
267,
587,
26,
288,
1177,
63,
576,
59,
80,
3321,
14,
3657,
13554,
61,
275,
334,
1816,
1592,
63,
576,
459,
719,
63,
4416,
3488,
80,
3321,
14,
3657,
13554,
566,
339,
347,
485,
22189,
63,
719,
63,
4416,
8,
277,
12,
1067,
12,
1844,
304,
267,
408,
3407,
282,
5046,
334,
719,
63,
4416,
63,
3827,
680,
398,
10977,
63,
4416,
365,
314,
574,
4568,
543,
314,
1844,
340,
1373,
365,
3451,
267,
4257,
314,
574,
4568,
543,
314,
2784,
365,
2138,
14,
267,
408,
267,
327,
781,
2793,
1133,
4838,
6391,
4652,
367,
19064,
12,
6197,
267,
340,
334,
719,
14,
362,
360,
1782,
63,
4597,
358,
436,
355,
1844,
459,
1782,
63,
4597,
2278,
2460,
360,
1200,
26,
8109,
288,
372,
756,
398,
340,
3290,
14,
374,
63,
962,
63,
409,
8,
719,
14,
362,
8,
80,
3321,
14,
3657,
13554,
2298,
288,
1844,
63,
4416,
63,
3827,
275,
1844,
59,
80,
3321,
14,
3657,
13554,
61,
267,
587,
26,
288,
1844,
63,
4416,
63,
3827,
275,
291,
423,
362,
63,
1200,
63,
4416,
63,
9140,
8,
355,
1067,
12,
1844,
459,
1200,
63,
344,
1105,
398,
372,
1844,
63,
4416,
63,
3827,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Tyler2004/pychess
|
lib/pychess/Utils/Board.py
|
20
|
15130
|
from __future__ import absolute_import
from __future__ import print_function
from copy import copy
from pychess.compat import basestring
from .lutils.LBoard import LBoard
from .lutils.bitboard import iterBits
from .lutils.lmove import RANK, FILE, FCORD, FLAG, PROMOTE_PIECE, toAN
from .Piece import Piece
from .Cord import Cord
from .const import *
def reverse_enum(L):
for index in reversed(range(len(L))):
yield index, L[index]
class Board:
""" Board is a thin layer above LBoard, adding the Piece objects, which are
needed for animation in BoardView.
In contrast to LBoard, Board is immutable, which means it will clone
itself each time you apply a move to it.
Caveat: As the only objects, the Piece objects in the self.data lists
will not be cloned, to make animation state preserve between moves """
variant = NORMALCHESS
RANKS = 8
FILES = 8
def __init__ (self, setup=False, lboard=None):
self.data = [dict(enumerate([None]*self.FILES)) for i in range(self.RANKS)]
if lboard is None:
self.board = LBoard(self.variant)
else:
self.board = lboard
self.board.pieceBoard = self
if setup:
if lboard is None:
if setup == True:
self.board.applyFen(FEN_START)
elif isinstance(setup, basestring):
self.board.applyFen(setup)
wpieces = self.board.boards[WHITE]
bpieces = self.board.boards[BLACK]
for cord in iterBits(wpieces[PAWN]):
self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, PAWN)
for cord in iterBits(wpieces[KNIGHT]):
self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, KNIGHT)
for cord in iterBits(wpieces[BISHOP]):
self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, BISHOP)
for cord in iterBits(wpieces[ROOK]):
self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, ROOK)
for cord in iterBits(wpieces[QUEEN]):
self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, QUEEN)
if self.board.kings[WHITE] != -1:
self[Cord(self.board.kings[WHITE])] = Piece(WHITE, KING)
for cord in iterBits(bpieces[PAWN]):
self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, PAWN)
for cord in iterBits(bpieces[KNIGHT]):
self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, KNIGHT)
for cord in iterBits(bpieces[BISHOP]):
self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, BISHOP)
for cord in iterBits(bpieces[ROOK]):
self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, ROOK)
for cord in iterBits(bpieces[QUEEN]):
self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, QUEEN)
if self.board.kings[BLACK] != -1:
self[Cord(self.board.kings[BLACK])] = Piece(BLACK, KING)
if self.variant == CRAZYHOUSECHESS:
for color in (BLACK, WHITE):
holding = self.board.holding[color]
for piece in holding:
for i in range(holding[piece]):
self[self.newHoldingCord(color, 1)] = Piece(color, piece)
def getHoldingCord(self, color, piece):
"""Get the first occurence of piece in given colors holding"""
enum = reverse_enum if color == WHITE else enumerate
files = ((self.FILES+3, self.FILES+2, self.FILES+1), (-4, -3, -2))
for x in files[color]:
for i, row in enum(self.data):
if (row.get(x) is not None) and row.get(x).piece == piece:
return Cord(x, i)
def newHoldingCord(self, color, nth=1):
"""Find the nth empty slot in given colors holding.
In atomic explosions nth can be > 1.
"""
enum = reverse_enum if color == BLACK else enumerate
files = ((self.FILES+1, self.FILES+2, self.FILES+3), (-2, -3, -4))
empty = 0
for x in files[color]:
for i, row in enum(self.data):
if row.get(x) is None:
empty += 1
if empty == nth:
return Cord(x, i)
def simulateMove (self, board1, move):
moved = []
new = []
dead = []
if move.flag == NULL_MOVE:
return moved, new, dead
cord0, cord1 = move.cords
if move.flag == DROP:
piece = FCORD(move.move)
cord0 = self.getHoldingCord(self.color, piece)
moved.append( (self[cord0], cord0) )
return moved, new, dead
if self.variant == ATOMICCHESS and (self[cord1] or move.flag == ENPASSANT):
# Sequence nubers of next newHoldingCord of WHITE and BLACK
nth = [0, 0]
piece = self[cord0]
nth[1-piece.color] += 1
cord = self.newHoldingCord(1-piece.color, nth[1-piece.color])
moved.append( (board1[cord], cord0) )
new.append( board1[cord] )
else:
moved.append( (self[cord0], cord0) )
if self[cord1]:
piece = PAWN if self.variant == CRAZYHOUSECHESS and self[cord1].promoted else self[cord1].piece
cord = self.newHoldingCord(self.color)
moved.append( (board1[cord], cord1) )
new.append( board1[cord] )
if self.variant == ATOMICCHESS:
nth[self.color] += 1
from pychess.Variants.atomic import cordsAround
for acord in cordsAround(cord1):
piece = self[acord]
if piece and piece.piece != PAWN and acord != cord0:
nth[1-piece.color] += 1
cord = self.newHoldingCord(1-piece.color, nth[1-piece.color])
moved.append( (board1[cord], acord) )
new.append( board1[cord] )
if move.flag in (QUEEN_CASTLE, KING_CASTLE):
side = move.flag - QUEEN_CASTLE
if FILE(cord0.x) == 3 and self.board.variant in (WILDCASTLECHESS, WILDCASTLESHUFFLECHESS):
side = 0 if side == 1 else 1
rook = self.board.ini_rooks[self.color][side]
moved.append( (self[Cord(rook)], Cord(rook)) )
elif move.flag in PROMOTIONS:
newPiece = board1[cord1]
moved.append( (newPiece, cord0) )
new.append( newPiece )
elif move.flag == ENPASSANT:
shift = -1 if self.color == WHITE else 1
ep_cord = Cord(cord1.x, cord1.y + shift)
moved.append( (self[ep_cord], ep_cord) )
cord = self.newHoldingCord(self.color)
new.append( board1[cord] )
return moved, new, dead
def simulateUnmove (self, board1, move):
moved = []
new = []
dead = []
if move.flag == NULL_MOVE:
return moved, new, dead
cord0, cord1 = move.cords
if self.variant == ATOMICCHESS and (board1[cord1] or move.flag == ENPASSANT):
piece = board1[cord0].piece
cord = self.getHoldingCord(self.color, piece)
moved.append( (self[cord], cord) )
self[cord].opacity = 1
dead.append( self[cord] )
else:
moved.append( (self[cord1], cord1) )
if board1[cord1]:
piece = PAWN if self.variant == CRAZYHOUSECHESS and board1[cord1].promoted else board1[cord1].piece
cord = self.getHoldingCord(1-self.color, piece)
moved.append( (self[cord], cord) )
self[cord].opacity = 1
dead.append( self[cord] )
if self.variant == ATOMICCHESS:
from pychess.Variants.atomic import cordsAround
for acord in cordsAround(cord1):
piece = board1[acord]
if piece and piece.piece != PAWN and acord != cord0:
piece.opacity = 0
cord = self.getHoldingCord(1-piece.color, piece.piece)
moved.append( (self[cord], cord) )
self[cord].opacity = 1
dead.append( self[cord] )
if move.flag in (QUEEN_CASTLE, KING_CASTLE):
side = move.flag - QUEEN_CASTLE
if FILE(cord0.x) == 3 and self.board.variant in (WILDCASTLECHESS, WILDCASTLESHUFFLECHESS):
side = 0 if side == 1 else 1
rook = self.board.fin_rooks[board1.color][side]
moved.append( (self[Cord(rook)], Cord(rook)) )
elif move.flag in PROMOTIONS:
newPiece = board1[cord0]
moved.append( (newPiece, cord1) )
new.append( newPiece )
elif move.flag == ENPASSANT:
cord = self.getHoldingCord(1-self.color, PAWN)
moved.append( (self[cord], cord) )
self[cord].opacity = 1
dead.append( self[cord] )
return moved, new, dead
def move (self, move, lboard=None):
""" Creates a new Board object cloning itself then applying
the move.move to the clone Board's lboard.
If lboard param was given, it will be used when cloning,
and move will not be applyed, just the high level Piece
objects will be adjusted."""
# Sequence nubers of next newHoldingCord of WHITE and BLACK
nth = [0, 0]
flag = FLAG(move.move)
if flag != DROP:
assert self[move.cord0], "%s %s" % (move, self.asFen())
newBoard = self.clone(lboard=lboard)
if lboard is None:
newBoard.board.applyMove (move.move)
cord0, cord1 = move.cords
if self[move.cord1] is not None or flag == ENPASSANT:
if self.variant == CRAZYHOUSECHESS:
piece = PAWN if flag == ENPASSANT or self[move.cord1].promoted else self[move.cord1].piece
new_piece = Piece(self.color, piece, captured=True)
else:
piece = PAWN if flag == ENPASSANT else self[move.cord1].piece
new_piece = Piece(1-self.color, piece, captured=True)
nth[self.color] += 1
newBoard[self.newHoldingCord(self.color, nth[self.color])] = new_piece
if self.variant == ATOMICCHESS:
from pychess.Variants.atomic import cordsAround
for acord in cordsAround(move.cord1):
piece = self[acord]
if piece and piece.piece != PAWN and acord != cord0:
new_piece = Piece(piece.color, piece.piece, captured=True)
nth[1-piece.color] += 1
newBoard[self.newHoldingCord(1-piece.color, nth[1-piece.color])] = new_piece
newBoard[acord] = None
if flag == DROP:
piece = FCORD(move.move)
hc = self.getHoldingCord(self.color, piece)
if hc is None:
newBoard[cord1] = Piece(self.color, piece)
else:
newBoard[cord1] = newBoard[self.getHoldingCord(self.color, piece)]
newBoard[self.getHoldingCord(self.color, piece)] = None
else:
if self.variant == ATOMICCHESS and (flag == ENPASSANT or self[move.cord1] is not None):
piece = self[move.cord0].piece
new_piece = Piece(self.color, piece, captured=True)
nth[1-self.color] += 1
newBoard[self.newHoldingCord(1-self.color, nth[1-self.color])] = new_piece
newBoard[cord1] = None
else:
newBoard[cord1] = newBoard[cord0]
if flag != NULL_MOVE and flag != DROP:
newBoard[cord0] = None
if flag in (QUEEN_CASTLE, KING_CASTLE):
side = flag - QUEEN_CASTLE
if FILE(cord0.x) == 3 and self.board.variant in (WILDCASTLECHESS, WILDCASTLESHUFFLECHESS):
side = 0 if side == 1 else 1
inirook = self.board.ini_rooks[self.color][side]
finrook = self.board.fin_rooks[self.color][side]
newBoard[Cord(finrook)] = newBoard[Cord(inirook)]
newBoard[Cord(inirook)] = None
if flag in PROMOTIONS:
new_piece = Piece(self.color, PROMOTE_PIECE(flag))
new_piece.promoted = True
newBoard[cord1] = new_piece
elif flag == ENPASSANT:
newBoard[Cord(cord1.x, cord0.y)] = None
return newBoard
def switchColor (self):
""" Switches the current color to move and unsets the enpassant cord.
Mostly to be used by inversed analyzers """
return self.setColor(1-self.color)
def _get_enpassant (self):
if self.board.enpassant != None:
return Cord(self.board.enpassant)
return None
enpassant = property(_get_enpassant)
def setColor (self, color):
newBoard = self.clone()
newBoard.board.setColor(color)
newBoard.board.setEnpassant(None)
return newBoard
def _get_color (self):
return self.board.color
color = property(_get_color)
def _get_ply (self):
return self.board.plyCount
ply = property(_get_ply)
def asFen (self, enable_bfen=True):
return self.board.asFen(enable_bfen)
def __repr__ (self):
return repr(self.board)
def __getitem__ (self, cord):
return self.data[cord.y].get(cord.x)
def __setitem__ (self, cord, piece):
self.data[cord.y][cord.x] = piece
def clone (self, lboard=None):
if lboard is None:
lboard = self.board.clone()
if self.variant != NORMALCHESS:
from pychess.Variants import variants
newBoard = variants[self.variant].board()
else:
newBoard = Board()
newBoard.board = lboard
newBoard.board.pieceBoard = newBoard
for y, row in enumerate(self.data):
for x, piece in row.items():
newBoard.data[y][x] = piece
return newBoard
def __eq__ (self, other):
if not isinstance(self, type(other)): return False
return self.board == other.board
def printPieces(self):
b = ""
for row in reversed(self.data):
for i in range(-3, 11):
piece = row.get(i)
if piece is not None:
if piece.color == BLACK:
p = FAN_PIECES[BLACK][piece.piece]
else:
p = FAN_PIECES[WHITE][piece.piece]
b += p
else:
b += '.'
b += "\n"
print(b)
|
gpl-3.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
1331,
492,
1331,
199,
199,
504,
1134,
595,
385,
14,
5819,
492,
7116,
199,
504,
1275,
76,
1208,
14,
44,
18995,
492,
491,
18995,
199,
504,
1275,
76,
1208,
14,
2075,
3576,
492,
2740,
10787,
199,
504,
1275,
76,
1208,
14,
76,
1185,
492,
820,
15874,
12,
13024,
12,
20934,
3731,
12,
11031,
12,
3611,
45,
9407,
63,
2252,
37,
2089,
12,
370,
879,
199,
504,
1275,
48,
21564,
492,
510,
21564,
199,
504,
1275,
35,
2181,
492,
445,
2181,
199,
504,
1275,
1297,
492,
627,
421,
199,
318,
3837,
63,
4869,
8,
44,
304,
272,
367,
1478,
315,
10822,
8,
1842,
8,
552,
8,
44,
15206,
267,
1995,
1478,
12,
491,
59,
1080,
61,
421,
199,
533,
5088,
1005,
26,
272,
408,
5088,
1005,
365,
282,
30758,
4045,
3432,
491,
18995,
12,
7791,
314,
510,
21564,
2251,
12,
1314,
787,
267,
4346,
367,
24154,
315,
5088,
1005,
2768,
14,
267,
1010,
30347,
370,
491,
18995,
12,
5088,
1005,
365,
17092,
12,
1314,
4910,
652,
911,
7289,
267,
6337,
1924,
900,
1265,
4838,
282,
4057,
370,
652,
14,
267,
445,
811,
292,
26,
3709,
314,
1454,
2251,
12,
314,
510,
21564,
2251,
315,
314,
291,
14,
576,
5548,
267,
911,
440,
506,
26210,
12,
370,
1852,
24154,
1174,
11211,
3382,
14569,
408,
2286,
9854,
275,
653,
9623,
1244,
1608,
272,
820,
15874,
51,
275,
1695,
272,
16444,
654,
275,
1695,
2286,
347,
636,
826,
363,
334,
277,
12,
3272,
29,
797,
12,
634,
3576,
29,
403,
304,
267,
291,
14,
576,
275,
359,
807,
8,
26318,
779,
403,
3672,
277,
14,
9472,
430,
367,
284,
315,
1425,
8,
277,
14,
50,
15874,
51,
1874,
267,
340,
634,
3576,
365,
488,
26,
288,
291,
14,
3576,
275,
491,
18995,
8,
277,
14,
8759,
9,
267,
587,
26,
288,
291,
14,
3576,
275,
634,
3576,
267,
291,
14,
3576,
14,
20082,
18995,
275,
291,
2728,
340,
3272,
26,
288,
340,
634,
3576,
365,
488,
26,
355,
340,
3272,
508,
715,
26,
490,
291,
14,
3576,
14,
4998,
38,
287,
8,
38,
742,
63,
7363,
9,
355,
916,
1228,
8,
2758,
12,
7116,
304,
490,
291,
14,
3576,
14,
4998,
38,
287,
8,
2758,
9,
7846,
336,
15655,
275,
291,
14,
3576,
14,
19267,
59,
18817,
61,
288,
330,
15655,
275,
291,
14,
3576,
14,
19267,
59,
23113,
61,
7846,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
8470,
3705,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
510,
33,
3705,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
43,
46,
2830,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
1804,
46,
2830,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
34,
13898,
1938,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
699,
13898,
1938,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
1092,
3593,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
9769,
3593,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
10526,
742,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
1413,
4187,
742,
9,
288,
340,
291,
14,
3576,
14,
75,
780,
59,
18817,
61,
1137,
446,
17,
26,
355,
291,
59,
35,
2181,
8,
277,
14,
3576,
14,
75,
780,
59,
18817,
12457,
275,
510,
21564,
8,
18817,
12,
1804,
1206,
9,
7846,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
8470,
3705,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
510,
33,
3705,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
43,
46,
2830,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
1804,
46,
2830,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
34,
13898,
1938,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
699,
13898,
1938,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
1092,
3593,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
9769,
3593,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
10526,
742,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
1413,
4187,
742,
9,
288,
340,
291,
14,
3576,
14,
75,
780,
59,
23113,
61,
1137,
446,
17,
26,
355,
291,
59,
35,
2181,
8,
277,
14,
3576,
14,
75,
780,
59,
23113,
12457,
275,
510,
21564,
8,
23113,
12,
1804,
1206,
9,
7846,
340,
291,
14,
8759,
508,
445,
2847,
58,
57,
2979,
4701,
1244,
1608,
26,
355,
367,
3164,
315,
334,
23113,
12,
20483,
304,
490,
17573,
275,
291,
14,
3576,
14,
72,
13122,
59,
2326,
61,
490,
367,
14854,
315,
17573,
26,
717,
367,
284,
315,
1425,
8,
72,
13122,
59,
20082,
4682,
1169,
291,
59,
277,
14,
1222,
40,
13122,
35,
2181,
8,
2326,
12,
413,
1874,
275,
510,
21564,
8,
2326,
12,
14854,
9,
2286,
347,
664,
40,
13122,
35,
2181,
8,
277,
12,
3164,
12,
14854,
304,
267,
408,
1002,
314,
1642,
14706,
608,
21225,
402,
14854,
315,
1627,
9229,
17573,
624,
2728,
4952,
275,
3837,
63,
4869,
340,
3164,
508,
20483,
587,
3874,
267,
1584,
275,
3666,
277,
14,
9472,
11,
19,
12,
291,
14,
9472,
11,
18,
12,
291,
14,
9472,
11,
17,
395,
5868,
20,
12,
446,
19,
12,
446,
18,
430,
267,
367,
671,
315,
1584,
59,
2326,
2189,
288,
367,
284
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
1331,
492,
1331,
199,
199,
504,
1134,
595,
385,
14,
5819,
492,
7116,
199,
504,
1275,
76,
1208,
14,
44,
18995,
492,
491,
18995,
199,
504,
1275,
76,
1208,
14,
2075,
3576,
492,
2740,
10787,
199,
504,
1275,
76,
1208,
14,
76,
1185,
492,
820,
15874,
12,
13024,
12,
20934,
3731,
12,
11031,
12,
3611,
45,
9407,
63,
2252,
37,
2089,
12,
370,
879,
199,
504,
1275,
48,
21564,
492,
510,
21564,
199,
504,
1275,
35,
2181,
492,
445,
2181,
199,
504,
1275,
1297,
492,
627,
421,
199,
318,
3837,
63,
4869,
8,
44,
304,
272,
367,
1478,
315,
10822,
8,
1842,
8,
552,
8,
44,
15206,
267,
1995,
1478,
12,
491,
59,
1080,
61,
421,
199,
533,
5088,
1005,
26,
272,
408,
5088,
1005,
365,
282,
30758,
4045,
3432,
491,
18995,
12,
7791,
314,
510,
21564,
2251,
12,
1314,
787,
267,
4346,
367,
24154,
315,
5088,
1005,
2768,
14,
267,
1010,
30347,
370,
491,
18995,
12,
5088,
1005,
365,
17092,
12,
1314,
4910,
652,
911,
7289,
267,
6337,
1924,
900,
1265,
4838,
282,
4057,
370,
652,
14,
267,
445,
811,
292,
26,
3709,
314,
1454,
2251,
12,
314,
510,
21564,
2251,
315,
314,
291,
14,
576,
5548,
267,
911,
440,
506,
26210,
12,
370,
1852,
24154,
1174,
11211,
3382,
14569,
408,
2286,
9854,
275,
653,
9623,
1244,
1608,
272,
820,
15874,
51,
275,
1695,
272,
16444,
654,
275,
1695,
2286,
347,
636,
826,
363,
334,
277,
12,
3272,
29,
797,
12,
634,
3576,
29,
403,
304,
267,
291,
14,
576,
275,
359,
807,
8,
26318,
779,
403,
3672,
277,
14,
9472,
430,
367,
284,
315,
1425,
8,
277,
14,
50,
15874,
51,
1874,
267,
340,
634,
3576,
365,
488,
26,
288,
291,
14,
3576,
275,
491,
18995,
8,
277,
14,
8759,
9,
267,
587,
26,
288,
291,
14,
3576,
275,
634,
3576,
267,
291,
14,
3576,
14,
20082,
18995,
275,
291,
2728,
340,
3272,
26,
288,
340,
634,
3576,
365,
488,
26,
355,
340,
3272,
508,
715,
26,
490,
291,
14,
3576,
14,
4998,
38,
287,
8,
38,
742,
63,
7363,
9,
355,
916,
1228,
8,
2758,
12,
7116,
304,
490,
291,
14,
3576,
14,
4998,
38,
287,
8,
2758,
9,
7846,
336,
15655,
275,
291,
14,
3576,
14,
19267,
59,
18817,
61,
288,
330,
15655,
275,
291,
14,
3576,
14,
19267,
59,
23113,
61,
7846,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
8470,
3705,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
510,
33,
3705,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
43,
46,
2830,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
1804,
46,
2830,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
34,
13898,
1938,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
699,
13898,
1938,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
1092,
3593,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
9769,
3593,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
87,
15655,
59,
10526,
742,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
18817,
12,
1413,
4187,
742,
9,
288,
340,
291,
14,
3576,
14,
75,
780,
59,
18817,
61,
1137,
446,
17,
26,
355,
291,
59,
35,
2181,
8,
277,
14,
3576,
14,
75,
780,
59,
18817,
12457,
275,
510,
21564,
8,
18817,
12,
1804,
1206,
9,
7846,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
8470,
3705,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
510,
33,
3705,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
43,
46,
2830,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
1804,
46,
2830,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
34,
13898,
1938,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
699,
13898,
1938,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
1092,
3593,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
9769,
3593,
9,
288,
367,
1970,
68,
315,
2740,
10787,
8,
66,
15655,
59,
10526,
742,
4682,
355,
291,
14,
576,
59,
50,
15874,
8,
1577,
30372,
3817,
8,
1577,
1874,
275,
510,
21564,
8,
23113,
12,
1413,
4187,
742,
9,
288,
340,
291,
14,
3576,
14,
75,
780,
59,
23113,
61,
1137,
446,
17,
26,
355,
291,
59,
35,
2181,
8,
277,
14,
3576,
14,
75,
780,
59,
23113,
12457,
275,
510,
21564,
8,
23113,
12,
1804,
1206,
9,
7846,
340,
291,
14,
8759,
508,
445,
2847,
58,
57,
2979,
4701,
1244,
1608,
26,
355,
367,
3164,
315,
334,
23113,
12,
20483,
304,
490,
17573,
275,
291,
14,
3576,
14,
72,
13122,
59,
2326,
61,
490,
367,
14854,
315,
17573,
26,
717,
367,
284,
315,
1425,
8,
72,
13122,
59,
20082,
4682,
1169,
291,
59,
277,
14,
1222,
40,
13122,
35,
2181,
8,
2326,
12,
413,
1874,
275,
510,
21564,
8,
2326,
12,
14854,
9,
2286,
347,
664,
40,
13122,
35,
2181,
8,
277,
12,
3164,
12,
14854,
304,
267,
408,
1002,
314,
1642,
14706,
608,
21225,
402,
14854,
315,
1627,
9229,
17573,
624,
2728,
4952,
275,
3837,
63,
4869,
340,
3164,
508,
20483,
587,
3874,
267,
1584,
275,
3666,
277,
14,
9472,
11,
19,
12,
291,
14,
9472,
11,
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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
] |
chouseknecht/ansible
|
lib/ansible/module_utils/facts/hardware/base.py
|
172
|
2736
|
# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# (c) 2017 Red Hat Inc.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.module_utils.facts.collector import BaseFactCollector
class Hardware:
platform = 'Generic'
# FIXME: remove load_on_init when we can
def __init__(self, module, load_on_init=False):
self.module = module
def populate(self, collected_facts=None):
return {}
class HardwareCollector(BaseFactCollector):
name = 'hardware'
_fact_ids = set(['processor',
'processor_cores',
'processor_count',
# TODO: mounts isnt exactly hardware
'mounts',
'devices'])
_fact_class = Hardware
def collect(self, module=None, collected_facts=None):
collected_facts = collected_facts or {}
if not module:
return {}
# Network munges cached_facts by side effect, so give it a copy
facts_obj = self._fact_class(module)
facts_dict = facts_obj.populate(collected_facts=collected_facts)
return facts_dict
|
gpl-3.0
|
[
3,
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
10946,
492,
3523,
24704,
12852,
421,
199,
533,
22825,
1068,
26,
272,
4298,
275,
283,
9417,
7,
339,
327,
7600,
26,
2813,
2248,
63,
265,
63,
826,
1380,
781,
883,
272,
347,
636,
826,
721,
277,
12,
859,
12,
2248,
63,
265,
63,
826,
29,
797,
304,
267,
291,
14,
578,
275,
859,
339,
347,
13904,
8,
277,
12,
13736,
63,
5047,
29,
403,
304,
267,
372,
1052,
421,
199,
533,
22825,
1068,
12852,
8,
1563,
24704,
12852,
304,
272,
536,
275,
283,
16529,
7,
272,
485,
7783,
63,
1580,
275,
663,
2941,
6459,
297,
2151,
283,
6459,
63,
4630,
297,
2151,
283,
6459,
63,
835,
297,
2151,
327,
3254,
26,
10760,
83,
365,
343,
8840,
14991,
2151,
283,
25810,
297,
2151,
283,
6410,
1105,
272,
485,
7783,
63,
533,
275,
22825,
1068,
339,
347,
8775,
8,
277,
12,
859,
29,
403,
12,
13736,
63,
5047,
29,
403,
304,
267,
13736,
63,
5047,
275,
13736,
63,
5047,
503,
1052,
267,
340,
440,
859,
26,
288,
372,
1052,
398,
327,
7220,
333,
324,
3389,
6328,
63,
5047,
701,
5366,
7763,
12,
880,
8120,
652,
282,
1331,
267,
9036,
63,
1113,
275,
291,
423,
7783,
63,
533,
8,
578,
9,
398,
9036,
63,
807,
275,
9036,
63,
1113,
14,
13817,
8,
22766,
63,
5047,
29,
22766,
63,
5047,
9,
398,
372,
9036,
63,
807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
1233,
365,
1777,
402,
2622,
12,
1325,
365,
376,
12717,
3931,
14,
199,
3,
961,
6770,
570,
17440,
12,
436,
642,
570,
17440,
1454,
12,
365,
6289,
18233,
14,
199,
3,
18167,
1265,
2218,
1808,
642,
17440,
12,
1314,
365,
12169,
18774,
701,
2622,
199,
3,
5139,
13511,
370,
314,
4132,
402,
314,
859,
12,
436,
1443,
5090,
3932,
5705,
4190,
199,
3,
370,
314,
4890,
1736,
14,
199,
3,
199,
3,
334,
67,
9,
9708,
9572,
13002,
3277,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
420,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
420,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
420,
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,
9706,
14,
199,
3,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
199,
3,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
199,
3,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
5047,
14,
10946,
492,
3523,
24704,
12852,
421,
199,
533,
22825,
1068,
26,
272,
4298,
275,
283,
9417,
7,
339,
327,
7600,
26,
2813,
2248,
63,
265,
63,
826,
1380,
781,
883,
272,
347,
636,
826,
721,
277,
12,
859,
12,
2248,
63,
265,
63,
826,
29,
797,
304,
267,
291,
14,
578,
275,
859,
339,
347,
13904,
8,
277,
12,
13736,
63,
5047,
29,
403,
304,
267,
372,
1052,
421,
199,
533,
22825,
1068,
12852,
8,
1563,
24704,
12852,
304,
272,
536,
275,
283,
16529,
7,
272,
485,
7783,
63,
1580,
275,
663,
2941,
6459,
297,
2151,
283,
6459,
63,
4630,
297,
2151,
283,
6459,
63,
835,
297,
2151,
327,
3254,
26,
10760,
83,
365,
343,
8840,
14991,
2151,
283,
25810,
297,
2151,
283,
6410,
1105,
272,
485,
7783,
63,
533,
275,
22825,
1068,
339,
347,
8775,
8,
277,
12,
859,
29,
403,
12,
13736,
63,
5047,
29,
403,
304,
267,
13736,
63,
5047,
275,
13736,
63,
5047,
503,
1052,
267,
340,
440,
859,
26,
288,
372,
1052,
398,
327,
7220,
333,
324,
3389,
6328,
63,
5047,
701,
5366,
7763,
12,
880,
8120,
652,
282,
1331,
267,
9036,
63,
1113,
275,
291,
423,
7783,
63,
533,
8,
578,
9,
398,
9036,
63,
807,
275,
9036,
63,
1113,
14,
13817,
8,
22766,
63,
5047,
29,
22766,
63,
5047,
9,
398,
372,
9036,
63,
807,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ericjpj/ns-3-dev
|
.waf-1.7.13-5a064c2686fe54de4e11018d22148cfc/waflib/Tools/vala.py
|
276
|
7966
|
#! /usr/bin/env python
# encoding: utf-8
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
import os.path,shutil,re
from waflib import Context,Task,Utils,Logs,Options,Errors
from waflib.TaskGen import extension,taskgen_method
from waflib.Configure import conf
class valac(Task.Task):
vars=["VALAC","VALAC_VERSION","VALAFLAGS"]
ext_out=['.h']
def run(self):
cmd=[self.env['VALAC']]+self.env['VALAFLAGS']
cmd.extend([a.abspath()for a in self.inputs])
ret=self.exec_command(cmd,cwd=self.outputs[0].parent.abspath())
if ret:
return ret
for x in self.outputs:
if id(x.parent)!=id(self.outputs[0].parent):
shutil.move(self.outputs[0].parent.abspath()+os.sep+x.name,x.abspath())
if self.generator.dump_deps_node:
self.generator.dump_deps_node.write('\n'.join(self.generator.packages))
return ret
valac=Task.update_outputs(valac)
@taskgen_method
def init_vala_task(self):
self.profile=getattr(self,'profile','gobject')
if self.profile=='gobject':
self.uselib=Utils.to_list(getattr(self,'uselib',[]))
if not'GOBJECT'in self.uselib:
self.uselib.append('GOBJECT')
def addflags(flags):
self.env.append_value('VALAFLAGS',flags)
if self.profile:
addflags('--profile=%s'%self.profile)
if hasattr(self,'threading'):
if self.profile=='gobject':
if not'GTHREAD'in self.uselib:
self.uselib.append('GTHREAD')
else:
Logs.warn("Profile %s means no threading support"%self.profile)
self.threading=False
if self.threading:
addflags('--threading')
valatask=self.valatask
self.is_lib='cprogram'not in self.features
if self.is_lib:
addflags('--library=%s'%self.target)
h_node=self.path.find_or_declare('%s.h'%self.target)
valatask.outputs.append(h_node)
addflags('--header=%s'%h_node.name)
valatask.outputs.append(self.path.find_or_declare('%s.vapi'%self.target))
if getattr(self,'gir',None):
gir_node=self.path.find_or_declare('%s.gir'%self.gir)
addflags('--gir=%s'%gir_node.name)
valatask.outputs.append(gir_node)
self.vala_target_glib=getattr(self,'vala_target_glib',getattr(Options.options,'vala_target_glib',None))
if self.vala_target_glib:
addflags('--target-glib=%s'%self.vala_target_glib)
addflags(['--define=%s'%x for x in getattr(self,'vala_defines',[])])
packages_private=Utils.to_list(getattr(self,'packages_private',[]))
addflags(['--pkg=%s'%x for x in packages_private])
def _get_api_version():
api_version='1.0'
if hasattr(Context.g_module,'API_VERSION'):
version=Context.g_module.API_VERSION.split(".")
if version[0]=="0":
api_version="0."+version[1]
else:
api_version=version[0]+".0"
return api_version
self.includes=Utils.to_list(getattr(self,'includes',[]))
self.uselib=self.to_list(getattr(self,'uselib',[]))
valatask.install_path=getattr(self,'install_path','')
valatask.vapi_path=getattr(self,'vapi_path','${DATAROOTDIR}/vala/vapi')
valatask.pkg_name=getattr(self,'pkg_name',self.env['PACKAGE'])
valatask.header_path=getattr(self,'header_path','${INCLUDEDIR}/%s-%s'%(valatask.pkg_name,_get_api_version()))
valatask.install_binding=getattr(self,'install_binding',True)
self.packages=packages=Utils.to_list(getattr(self,'packages',[]))
self.vapi_dirs=vapi_dirs=Utils.to_list(getattr(self,'vapi_dirs',[]))
includes=[]
if hasattr(self,'use'):
local_packages=Utils.to_list(self.use)[:]
seen=[]
while len(local_packages)>0:
package=local_packages.pop()
if package in seen:
continue
seen.append(package)
try:
package_obj=self.bld.get_tgen_by_name(package)
except Errors.WafError:
continue
package_name=package_obj.target
package_node=package_obj.path
package_dir=package_node.path_from(self.path)
for task in package_obj.tasks:
for output in task.outputs:
if output.name==package_name+".vapi":
valatask.set_run_after(task)
if package_name not in packages:
packages.append(package_name)
if package_dir not in vapi_dirs:
vapi_dirs.append(package_dir)
if package_dir not in includes:
includes.append(package_dir)
if hasattr(package_obj,'use'):
lst=self.to_list(package_obj.use)
lst.reverse()
local_packages=[pkg for pkg in lst if pkg not in seen]+local_packages
addflags(['--pkg=%s'%p for p in packages])
for vapi_dir in vapi_dirs:
v_node=self.path.find_dir(vapi_dir)
if not v_node:
Logs.warn('Unable to locate Vala API directory: %r'%vapi_dir)
else:
addflags('--vapidir=%s'%v_node.abspath())
addflags('--vapidir=%s'%v_node.get_bld().abspath())
self.dump_deps_node=None
if self.is_lib and self.packages:
self.dump_deps_node=self.path.find_or_declare('%s.deps'%self.target)
valatask.outputs.append(self.dump_deps_node)
self.includes.append(self.bld.srcnode.abspath())
self.includes.append(self.bld.bldnode.abspath())
for include in includes:
try:
self.includes.append(self.path.find_dir(include).abspath())
self.includes.append(self.path.find_dir(include).get_bld().abspath())
except AttributeError:
Logs.warn("Unable to locate include directory: '%s'"%include)
if self.is_lib and valatask.install_binding:
headers_list=[o for o in valatask.outputs if o.suffix()==".h"]
try:
self.install_vheader.source=headers_list
except AttributeError:
self.install_vheader=self.bld.install_files(valatask.header_path,headers_list,self.env)
vapi_list=[o for o in valatask.outputs if(o.suffix()in(".vapi",".deps"))]
try:
self.install_vapi.source=vapi_list
except AttributeError:
self.install_vapi=self.bld.install_files(valatask.vapi_path,vapi_list,self.env)
gir_list=[o for o in valatask.outputs if o.suffix()=='.gir']
try:
self.install_gir.source=gir_list
except AttributeError:
self.install_gir=self.bld.install_files(getattr(self,'gir_path','${DATAROOTDIR}/gir-1.0'),gir_list,self.env)
@extension('.vala','.gs')
def vala_file(self,node):
try:
valatask=self.valatask
except AttributeError:
valatask=self.valatask=self.create_task('valac')
self.init_vala_task()
valatask.inputs.append(node)
c_node=node.change_ext('.c')
valatask.outputs.append(c_node)
self.source.append(c_node)
@conf
def find_valac(self,valac_name,min_version):
valac=self.find_program(valac_name,var='VALAC')
try:
output=self.cmd_and_log(valac+' --version')
except Exception:
valac_version=None
else:
ver=re.search(r'\d+.\d+.\d+',output).group(0).split('.')
valac_version=tuple([int(x)for x in ver])
self.msg('Checking for %s version >= %r'%(valac_name,min_version),valac_version,valac_version and valac_version>=min_version)
if valac and valac_version<min_version:
self.fatal("%s version %r is too old, need >= %r"%(valac_name,valac_version,min_version))
self.env['VALAC_VERSION']=valac_version
return valac
@conf
def check_vala(self,min_version=(0,8,0),branch=None):
if not branch:
branch=min_version[:2]
try:
find_valac(self,'valac-%d.%d'%(branch[0],branch[1]),min_version)
except self.errors.ConfigurationError:
find_valac(self,'valac',min_version)
@conf
def check_vala_deps(self):
if not self.env['HAVE_GOBJECT']:
pkg_args={'package':'gobject-2.0','uselib_store':'GOBJECT','args':'--cflags --libs'}
if getattr(Options.options,'vala_target_glib',None):
pkg_args['atleast_version']=Options.options.vala_target_glib
self.check_cfg(**pkg_args)
if not self.env['HAVE_GTHREAD']:
pkg_args={'package':'gthread-2.0','uselib_store':'GTHREAD','args':'--cflags --libs'}
if getattr(Options.options,'vala_target_glib',None):
pkg_args['atleast_version']=Options.options.vala_target_glib
self.check_cfg(**pkg_args)
def configure(self):
self.load('gnu_dirs')
self.check_vala_deps()
self.check_vala()
self.env.VALAFLAGS=['-C','--quiet']
def options(opt):
opt.load('gnu_dirs')
valaopts=opt.add_option_group('Vala Compiler Options')
valaopts.add_option('--vala-target-glib',default=None,dest='vala_target_glib',metavar='MAJOR.MINOR',help='Target version of glib for Vala GObject code generation')
|
gpl-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
646,
747,
14,
515,
12,
20938,
12,
264,
199,
504,
31380,
492,
9470,
12,
4476,
12,
7535,
12,
16333,
12,
4558,
12,
9298,
199,
504,
31380,
14,
4476,
8168,
492,
3329,
12,
1765,
2268,
63,
765,
199,
504,
31380,
14,
17324,
492,
3743,
199,
533,
1139,
645,
8,
4476,
14,
4476,
304,
199,
198,
2936,
6270,
3204,
1348,
2266,
3204,
1348,
63,
4612,
2266,
3204,
33,
4831,
937,
199,
198,
832,
63,
548,
2968,
14,
72,
418,
199,
198,
318,
1255,
8,
277,
304,
507,
198,
1760,
1524,
277,
14,
1813,
459,
3204,
1348,
418,
2807,
277,
14,
1813,
459,
3204,
33,
4831,
418,
507,
198,
1760,
14,
2880,
779,
65,
14,
4832,
342,
509,
282,
315,
291,
14,
3711,
566,
507,
198,
3292,
29,
277,
14,
1628,
63,
1531,
8,
1760,
12,
6525,
29,
277,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
1012,
507,
198,
692,
2203,
26,
686,
198,
1107,
2203,
507,
198,
509,
671,
315,
291,
14,
4467,
26,
686,
198,
692,
1305,
8,
88,
14,
1708,
9,
1111,
344,
8,
277,
14,
4467,
59,
16,
1055,
1708,
304,
1585,
198,
20938,
14,
1185,
8,
277,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
24543,
736,
14,
4127,
11,
88,
14,
354,
12,
88,
14,
4832,
1012,
507,
198,
692,
291,
14,
4679,
14,
2724,
63,
5846,
63,
932,
26,
686,
198,
277,
14,
4679,
14,
2724,
63,
5846,
63,
932,
14,
952,
2258,
78,
1370,
904,
8,
277,
14,
4679,
14,
5154,
430,
507,
198,
1107,
2203,
199,
637,
645,
29,
4476,
14,
873,
63,
4467,
8,
637,
645,
9,
199,
32,
1765,
2268,
63,
765,
199,
318,
4205,
63,
637,
65,
63,
1765,
8,
277,
304,
199,
198,
277,
14,
2913,
29,
5675,
8,
277,
2584,
2913,
1673,
71,
785,
358,
199,
198,
692,
291,
14,
2913,
6803,
71,
785,
356,
507,
198,
277,
14,
1180,
773,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
1180,
773,
23993,
2459,
507,
198,
692,
440,
7,
39,
9868,
7,
262,
291,
14,
1180,
773,
26,
686,
198,
277,
14,
1180,
773,
14,
740,
360,
39,
9868,
358,
199,
198,
318,
1050,
2469,
8,
2469,
304,
507,
198,
277,
14,
1813,
14,
740,
63,
585,
360,
3204,
33,
4831,
297,
2469,
9,
199,
198,
692,
291,
14,
2913,
26,
507,
198,
525,
2469,
4517,
2913,
2458,
83,
5956,
277,
14,
2913,
9,
199,
198,
692,
2688,
8,
277,
2584,
12562,
735,
507,
198,
692,
291,
14,
2913,
6803,
71,
785,
356,
686,
198,
692,
440,
7,
8521,
5670,
7,
262,
291,
14,
1180,
773,
26,
1585,
198,
277,
14,
1180,
773,
14,
740,
360,
8521,
5670,
358,
507,
198,
2836,
26,
686,
198,
16333,
14,
4050,
480,
5736,
450,
83,
4910,
949,
5796,
2291,
6808,
277,
14,
2913,
9,
686,
198,
277,
14,
12562,
29,
797,
507,
198,
692,
291,
14,
12562,
26,
686,
198,
525,
2469,
4517,
12562,
358,
199,
198,
637,
292,
813,
29,
277,
14,
637,
292,
813,
199,
198,
277,
14,
374,
63,
773,
534,
67,
6815,
7,
1397,
315,
291,
14,
3179,
199,
198,
692,
291,
14,
374,
63,
773,
26,
507,
198,
525,
2469,
4517,
4342,
2458,
83,
5956,
277,
14,
1375,
9,
507,
198,
72,
63,
932,
29,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
72,
5956,
277,
14,
1375,
9,
507,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
72,
63,
932,
9,
507,
198,
525,
2469,
4517,
1291,
2458,
83,
5956,
72,
63,
932,
14,
354,
9,
507,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
86,
1246,
5956,
277,
14,
1375,
430,
507,
198,
692,
2519,
8,
277,
2584,
71,
723,
297,
403,
304,
686,
198,
71,
723,
63,
932,
29,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
71,
723,
5956,
277,
14,
71,
723,
9,
686,
198,
525,
2469,
4517,
71,
723,
2458,
83,
5956,
71,
723,
63,
932,
14,
354,
9,
686,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
71,
723,
63,
932,
9,
199,
198,
277,
14,
637,
65,
63,
1375,
63,
30816,
29,
5675,
8,
277,
2584,
637,
65,
63,
1375,
63,
30816,
297,
5675,
8,
4558,
14,
1419,
2584,
637,
65,
63,
1375,
63,
30816,
297,
403,
430,
199,
198,
692,
291,
14,
637,
65,
63,
1375,
63,
30816,
26,
507,
198,
525,
2469,
4517,
1375,
13,
30816,
2458,
83,
5956,
277,
14,
637,
65,
63,
1375,
63,
30816,
9,
199,
198,
525,
2469,
18510,
4640,
2458,
83,
5956,
88,
367,
671,
315,
2519,
8,
277,
2584,
637,
65,
63,
14334,
23993,
24310,
199,
198,
5154,
63,
4239,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
5154,
63,
4239,
23993,
2459,
199,
198,
525,
2469,
18510,
4600,
2458,
83,
5956,
88,
367,
671,
315,
6117,
63,
4239,
566,
199,
198,
318,
485,
362,
63,
1246,
63,
1023,
837,
507,
198,
1246,
63,
1023,
534,
17,
14,
16,
7,
507,
198,
692,
2688,
8,
2998,
14,
71,
63,
578,
2584,
3735,
63,
4612,
735,
686,
198,
1023,
29,
2998,
14,
71,
63,
578,
14,
3735,
63,
4612,
14,
1294,
15857,
686,
198,
692,
1015,
59,
16,
61,
11800,
16,
582,
1585,
198,
1246,
63,
1023,
628,
16,
2122,
11,
1023,
59,
17,
61,
686,
198,
2836,
26,
1585,
198,
1246,
63,
1023,
29,
1023,
59,
16,
2807,
1674,
16,
2,
507,
198,
1107,
2986,
63,
1023,
199,
198,
277,
14,
9441,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
9441,
23993,
2459,
199,
198,
277,
14,
1180,
773,
29,
277,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
1180,
773,
23993,
2459,
199,
198,
637,
292,
813,
14,
3174,
63,
515,
29,
5675,
8,
277,
2584,
3174,
63,
515
] |
[
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2644,
26,
2774,
13,
24,
199,
3,
14750,
1,
4226,
440,
5283,
1,
1455,
921,
21500,
14,
31864,
14,
957,
15,
3187,
15,
4757,
15,
21500,
2706,
15,
4780,
14,
1360,
20930,
2873,
24522,
63,
1589,
63,
21500,
63,
493,
199,
199,
646,
747,
14,
515,
12,
20938,
12,
264,
199,
504,
31380,
492,
9470,
12,
4476,
12,
7535,
12,
16333,
12,
4558,
12,
9298,
199,
504,
31380,
14,
4476,
8168,
492,
3329,
12,
1765,
2268,
63,
765,
199,
504,
31380,
14,
17324,
492,
3743,
199,
533,
1139,
645,
8,
4476,
14,
4476,
304,
199,
198,
2936,
6270,
3204,
1348,
2266,
3204,
1348,
63,
4612,
2266,
3204,
33,
4831,
937,
199,
198,
832,
63,
548,
2968,
14,
72,
418,
199,
198,
318,
1255,
8,
277,
304,
507,
198,
1760,
1524,
277,
14,
1813,
459,
3204,
1348,
418,
2807,
277,
14,
1813,
459,
3204,
33,
4831,
418,
507,
198,
1760,
14,
2880,
779,
65,
14,
4832,
342,
509,
282,
315,
291,
14,
3711,
566,
507,
198,
3292,
29,
277,
14,
1628,
63,
1531,
8,
1760,
12,
6525,
29,
277,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
1012,
507,
198,
692,
2203,
26,
686,
198,
1107,
2203,
507,
198,
509,
671,
315,
291,
14,
4467,
26,
686,
198,
692,
1305,
8,
88,
14,
1708,
9,
1111,
344,
8,
277,
14,
4467,
59,
16,
1055,
1708,
304,
1585,
198,
20938,
14,
1185,
8,
277,
14,
4467,
59,
16,
1055,
1708,
14,
4832,
24543,
736,
14,
4127,
11,
88,
14,
354,
12,
88,
14,
4832,
1012,
507,
198,
692,
291,
14,
4679,
14,
2724,
63,
5846,
63,
932,
26,
686,
198,
277,
14,
4679,
14,
2724,
63,
5846,
63,
932,
14,
952,
2258,
78,
1370,
904,
8,
277,
14,
4679,
14,
5154,
430,
507,
198,
1107,
2203,
199,
637,
645,
29,
4476,
14,
873,
63,
4467,
8,
637,
645,
9,
199,
32,
1765,
2268,
63,
765,
199,
318,
4205,
63,
637,
65,
63,
1765,
8,
277,
304,
199,
198,
277,
14,
2913,
29,
5675,
8,
277,
2584,
2913,
1673,
71,
785,
358,
199,
198,
692,
291,
14,
2913,
6803,
71,
785,
356,
507,
198,
277,
14,
1180,
773,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
1180,
773,
23993,
2459,
507,
198,
692,
440,
7,
39,
9868,
7,
262,
291,
14,
1180,
773,
26,
686,
198,
277,
14,
1180,
773,
14,
740,
360,
39,
9868,
358,
199,
198,
318,
1050,
2469,
8,
2469,
304,
507,
198,
277,
14,
1813,
14,
740,
63,
585,
360,
3204,
33,
4831,
297,
2469,
9,
199,
198,
692,
291,
14,
2913,
26,
507,
198,
525,
2469,
4517,
2913,
2458,
83,
5956,
277,
14,
2913,
9,
199,
198,
692,
2688,
8,
277,
2584,
12562,
735,
507,
198,
692,
291,
14,
2913,
6803,
71,
785,
356,
686,
198,
692,
440,
7,
8521,
5670,
7,
262,
291,
14,
1180,
773,
26,
1585,
198,
277,
14,
1180,
773,
14,
740,
360,
8521,
5670,
358,
507,
198,
2836,
26,
686,
198,
16333,
14,
4050,
480,
5736,
450,
83,
4910,
949,
5796,
2291,
6808,
277,
14,
2913,
9,
686,
198,
277,
14,
12562,
29,
797,
507,
198,
692,
291,
14,
12562,
26,
686,
198,
525,
2469,
4517,
12562,
358,
199,
198,
637,
292,
813,
29,
277,
14,
637,
292,
813,
199,
198,
277,
14,
374,
63,
773,
534,
67,
6815,
7,
1397,
315,
291,
14,
3179,
199,
198,
692,
291,
14,
374,
63,
773,
26,
507,
198,
525,
2469,
4517,
4342,
2458,
83,
5956,
277,
14,
1375,
9,
507,
198,
72,
63,
932,
29,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
72,
5956,
277,
14,
1375,
9,
507,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
72,
63,
932,
9,
507,
198,
525,
2469,
4517,
1291,
2458,
83,
5956,
72,
63,
932,
14,
354,
9,
507,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
86,
1246,
5956,
277,
14,
1375,
430,
507,
198,
692,
2519,
8,
277,
2584,
71,
723,
297,
403,
304,
686,
198,
71,
723,
63,
932,
29,
277,
14,
515,
14,
1623,
63,
269,
63,
16536,
3508,
83,
14,
71,
723,
5956,
277,
14,
71,
723,
9,
686,
198,
525,
2469,
4517,
71,
723,
2458,
83,
5956,
71,
723,
63,
932,
14,
354,
9,
686,
198,
637,
292,
813,
14,
4467,
14,
740,
8,
71,
723,
63,
932,
9,
199,
198,
277,
14,
637,
65,
63,
1375,
63,
30816,
29,
5675,
8,
277,
2584,
637,
65,
63,
1375,
63,
30816,
297,
5675,
8,
4558,
14,
1419,
2584,
637,
65,
63,
1375,
63,
30816,
297,
403,
430,
199,
198,
692,
291,
14,
637,
65,
63,
1375,
63,
30816,
26,
507,
198,
525,
2469,
4517,
1375,
13,
30816,
2458,
83,
5956,
277,
14,
637,
65,
63,
1375,
63,
30816,
9,
199,
198,
525,
2469,
18510,
4640,
2458,
83,
5956,
88,
367,
671,
315,
2519,
8,
277,
2584,
637,
65,
63,
14334,
23993,
24310,
199,
198,
5154,
63,
4239,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
5154,
63,
4239,
23993,
2459,
199,
198,
525,
2469,
18510,
4600,
2458,
83,
5956,
88,
367,
671,
315,
6117,
63,
4239,
566,
199,
198,
318,
485,
362,
63,
1246,
63,
1023,
837,
507,
198,
1246,
63,
1023,
534,
17,
14,
16,
7,
507,
198,
692,
2688,
8,
2998,
14,
71,
63,
578,
2584,
3735,
63,
4612,
735,
686,
198,
1023,
29,
2998,
14,
71,
63,
578,
14,
3735,
63,
4612,
14,
1294,
15857,
686,
198,
692,
1015,
59,
16,
61,
11800,
16,
582,
1585,
198,
1246,
63,
1023,
628,
16,
2122,
11,
1023,
59,
17,
61,
686,
198,
2836,
26,
1585,
198,
1246,
63,
1023,
29,
1023,
59,
16,
2807,
1674,
16,
2,
507,
198,
1107,
2986,
63,
1023,
199,
198,
277,
14,
9441,
29,
7535,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
9441,
23993,
2459,
199,
198,
277,
14,
1180,
773,
29,
277,
14,
475,
63,
513,
8,
5675,
8,
277,
2584,
1180,
773,
23993,
2459,
199,
198,
637,
292,
813,
14,
3174,
63,
515,
29,
5675,
8,
277,
2584,
3174,
63,
515,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
major/os-ansible-deployment
|
releasenotes/source/conf.py
|
8
|
9227
|
# -*- coding: utf-8 -*-
# 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.
# Glance Release Notes documentation build configuration file, created by
# sphinx-quickstart on Tue Nov 3 17:40:50 2015.
#
# 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.
# 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 = [
'oslosphinx',
'reno.sphinxext',
]
# 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 = 'index'
# General information about the project.
project = u'OpenStack-Ansible Release Notes'
copyright = u'2015, OpenStack-Ansible Developers'
# 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.
import pbr.version
version_info = pbr.version.VersionInfo('openstack-ansible')
# The full version, including alpha/beta/rc tags.
release = version_info.version_string_with_vcs()
# The short X.Y version.
version = version_info.canonical_version_string()
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# 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 = []
# 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 = []
# If true, keep warnings as "system message" paragraphs in the built documents.
# keep_warnings = False
# -- 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']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
# html_extra_path = []
# 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 = 'OpenStackAnsibleReleaseNotesdoc'
# -- 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, or own class]).
latex_documents = [
('index', 'OpenStackAnsibleReleaseNotes.tex', u'OpenStack-Ansible Release Notes Documentation',
u'OpenStack-Ansible Developers', '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 = [
('index', 'openstackansiblereleasenotes', u'OpenStack-Ansible Release Notes Documentation',
[u'OpenStack-Ansible Developers'], 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', 'OpenStackAnsibleReleaseNotes', u'OpenStack-Ansible Release Notes Documentation',
u'OpenStack-Ansible Developers', 'OpenStackAnsibleReleaseNotes',
'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'
# If true, do not generate a @detailmenu in the "Top" node's menu.
# texinfo_no_detailmenu = False
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
598,
76,
554,
17646,
8144,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
3091,
86,
221,
650,
5557,
26,
2167,
26,
1400,
6900,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
199,
3,
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,
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,
984,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
4839,
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,
199,
3,
5478,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
199,
3,
7869,
14,
199,
5359,
275,
359,
272,
283,
736,
320,
8008,
297,
272,
283,
828,
79,
14,
8008,
832,
297,
199,
61,
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,
1350,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
26208,
13,
10047,
17646,
8144,
7,
199,
7307,
275,
399,
7,
7806,
12,
14260,
13,
10047,
23493,
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,
646,
299,
3289,
14,
1023,
199,
1023,
63,
815,
275,
299,
3289,
14,
1023,
14,
3353,
2354,
360,
8512,
13,
4853,
358,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
1015,
63,
815,
14,
1023,
63,
875,
63,
1045,
63,
15525,
342,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
1015,
63,
815,
14,
13109,
63,
1023,
63,
875,
342,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
2637,
275,
488,
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,
11168,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
11168,
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,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
199,
3,
8247,
14,
199,
3,
849,
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,
1050,
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,
1050,
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,
2498,
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,
3413,
1080,
63,
2330,
63,
1861,
275,
942,
199,
199,
3,
982,
2549,
12,
4215,
3598,
465,
298,
2253,
1245,
2,
26603,
315,
314,
6137,
8247,
14,
199,
3,
4215,
63,
5451,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
11016,
10965,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
3,
598,
76,
554,
17646,
8144,
3794,
1900,
2897,
570,
12,
2737,
701,
199,
3,
15882,
13,
28957,
641,
377,
310,
3091,
86,
221,
650,
5557,
26,
2167,
26,
1400,
6900,
14,
199,
3,
199,
3,
961,
570,
365,
22711,
342,
68,
543,
314,
1453,
2082,
663,
370,
2399,
199,
3,
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,
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,
984,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
24535,
199,
199,
3,
1553,
1696,
2897,
9527,
199,
199,
3,
982,
2195,
3794,
4839,
282,
13460,
10229,
1015,
12,
1174,
652,
2348,
14,
199,
3,
4839,
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,
199,
3,
5478,
17262,
543,
10229,
334,
4579,
283,
8008,
14,
832,
24915,
503,
2195,
3537,
199,
3,
7869,
14,
199,
5359,
275,
359,
272,
283,
736,
320,
8008,
297,
272,
283,
828,
79,
14,
8008,
832,
297,
199,
61,
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,
1350,
63,
2991,
275,
283,
1624,
13,
24,
13,
4093,
7,
199,
199,
3,
710,
5288,
28310,
2213,
14,
199,
4133,
63,
1301,
275,
283,
1080,
7,
199,
199,
3,
1696,
2556,
3595,
314,
2199,
14,
199,
1715,
275,
399,
7,
26208,
13,
10047,
17646,
8144,
7,
199,
7307,
275,
399,
7,
7806,
12,
14260,
13,
10047,
23493,
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,
646,
299,
3289,
14,
1023,
199,
1023,
63,
815,
275,
299,
3289,
14,
1023,
14,
3353,
2354,
360,
8512,
13,
4853,
358,
199,
3,
710,
2615,
1015,
12,
5893,
5131,
15,
5683,
15,
1195,
3762,
14,
199,
3221,
275,
1015,
63,
815,
14,
1023,
63,
875,
63,
1045,
63,
15525,
342,
199,
3,
710,
3974,
1323,
14,
57,
1015,
14,
199,
1023,
275,
1015,
63,
815,
14,
13109,
63,
1023,
63,
875,
342,
199,
199,
3,
710,
2637,
367,
1564,
18392,
701,
10229,
14,
21751,
370,
3794,
199,
3,
367,
282,
769,
402,
3748,
10815,
14,
199,
3,
2637,
275,
488,
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,
11168,
275,
2125,
199,
3,
19524,
12,
11168,
63,
5045,
365,
1202,
465,
314,
1475,
367,
282,
14053,
1240,
14,
199,
3,
11168,
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,
942,
199,
199,
3,
710,
20883,
849,
4719,
334,
2972,
367,
642,
9189,
26,
658,
505,
10522,
370,
675,
367,
1006,
199,
3,
8247,
14,
199,
3,
849,
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,
1050,
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,
1050,
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,
2498,
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,
3413,
1080,
63,
2330,
63,
1861,
275,
942,
199,
199,
3,
982,
2549,
12,
4215,
3598,
465,
298,
2253,
1245,
2,
26603,
315,
314,
6137,
8247,
14,
199,
3,
4215,
63,
5451,
275,
756,
421,
199,
3,
1553,
8394,
367,
4163,
1072,
11016,
10965,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jason-z-hang/airflow
|
airflow/contrib/plugins/metastore_browser/main.py
|
42
|
5126
|
from datetime import datetime
import json
from flask import Blueprint, request
from flask.ext.admin import BaseView, expose
import pandas as pd
from airflow.hooks import HiveMetastoreHook, MySqlHook, PrestoHook, HiveCliHook
from airflow.plugins_manager import AirflowPlugin
from airflow.www import utils as wwwutils
METASTORE_CONN_ID = 'metastore_default'
METASTORE_MYSQL_CONN_ID = 'metastore_mysql'
PRESTO_CONN_ID = 'presto_default'
HIVE_CLI_CONN_ID = 'hive_default'
DEFAULT_DB = 'default'
DB_WHITELIST = None
DB_BLACKLIST = ['tmp']
TABLE_SELECTOR_LIMIT = 2000
# Keeping pandas from truncating long strings
pd.set_option('display.max_colwidth', -1)
# Creating a flask admin BaseView
class MetastoreBrowserView(BaseView, wwwutils.DataProfilingMixin):
@expose('/')
def index(self):
sql = """
SELECT
a.name as db, db_location_uri as location,
count(1) as object_count, a.desc as description
FROM DBS a
JOIN TBLS b ON a.DB_ID = b.DB_ID
GROUP BY a.name, db_location_uri, a.desc
""".format(**locals())
h = MySqlHook(METASTORE_MYSQL_CONN_ID)
df = h.get_pandas_df(sql)
df.db = (
'<a href="/admin/metastorebrowserview/db/?db=' +
df.db + '">' + df.db + '</a>')
table = df.to_html(
classes="table table-striped table-bordered table-hover",
index=False,
escape=False,
na_rep='',)
return self.render(
"metastore_browser/dbs.html", table=table)
@expose('/table/')
def table(self):
table_name = request.args.get("table")
m = HiveMetastoreHook(METASTORE_CONN_ID)
table = m.get_table(table_name)
return self.render(
"metastore_browser/table.html",
table=table, table_name=table_name, datetime=datetime, int=int)
@expose('/db/')
def db(self):
db = request.args.get("db")
m = HiveMetastoreHook(METASTORE_CONN_ID)
tables = sorted(m.get_tables(db=db), key=lambda x: x.tableName)
return self.render(
"metastore_browser/db.html", tables=tables, db=db)
@wwwutils.gzipped
@expose('/partitions/')
def partitions(self):
schema, table = request.args.get("table").split('.')
sql = """
SELECT
a.PART_NAME,
a.CREATE_TIME,
c.LOCATION,
c.IS_COMPRESSED,
c.INPUT_FORMAT,
c.OUTPUT_FORMAT
FROM PARTITIONS a
JOIN TBLS b ON a.TBL_ID = b.TBL_ID
JOIN DBS d ON b.DB_ID = d.DB_ID
JOIN SDS c ON a.SD_ID = c.SD_ID
WHERE
b.TBL_NAME like '{table}' AND
d.NAME like '{schema}'
ORDER BY PART_NAME DESC
""".format(**locals())
h = MySqlHook(METASTORE_MYSQL_CONN_ID)
df = h.get_pandas_df(sql)
return df.to_html(
classes="table table-striped table-bordered table-hover",
index=False,
na_rep='',)
@wwwutils.gzipped
@expose('/objects/')
def objects(self):
where_clause = ''
if DB_WHITELIST:
dbs = ",".join(["'" + db + "'" for db in DB_WHITELIST])
where_clause = "AND b.name IN ({})".format(dbs)
if DB_BLACKLIST:
dbs = ",".join(["'" + db + "'" for db in DB_BLACKLIST])
where_clause = "AND b.name NOT IN ({})".format(dbs)
sql = """
SELECT CONCAT(b.NAME, '.', a.TBL_NAME), TBL_TYPE
FROM TBLS a
JOIN DBS b ON a.DB_ID = b.DB_ID
WHERE
a.TBL_NAME NOT LIKE '%tmp%' AND
a.TBL_NAME NOT LIKE '%temp%' AND
b.NAME NOT LIKE '%tmp%' AND
b.NAME NOT LIKE '%temp%'
{where_clause}
LIMIT {LIMIT};
""".format(where_clause=where_clause, LIMIT=TABLE_SELECTOR_LIMIT)
h = MySqlHook(METASTORE_MYSQL_CONN_ID)
d = [
{'id': row[0], 'text': row[0]}
for row in h.get_records(sql)]
return json.dumps(d)
@wwwutils.gzipped
@expose('/data/')
def data(self):
table = request.args.get("table")
sql = "SELECT * FROM {table} LIMIT 1000;".format(table=table)
h = PrestoHook(PRESTO_CONN_ID)
df = h.get_pandas_df(sql)
return df.to_html(
classes="table table-striped table-bordered table-hover",
index=False,
na_rep='',)
@expose('/ddl/')
def ddl(self):
table = request.args.get("table")
sql = "SHOW CREATE TABLE {table};".format(table=table)
h = HiveCliHook(HIVE_CLI_CONN_ID)
return h.run_cli(sql)
v = MetastoreBrowserView(category="Plugins", name="Hive Metadata Browser")
# Creating a flask blueprint to intergrate the templates and static folder
bp = Blueprint(
"metastore_browser", __name__,
template_folder='templates',
static_folder='static',
static_url_path='/static/metastore_browser')
# Defining the plugin class
class MetastoreBrowserPlugin(AirflowPlugin):
name = "metastore_browser"
flask_blueprints = [bp]
admin_views = [v]
|
apache-2.0
|
[
504,
2197,
492,
2197,
199,
646,
2022,
199,
199,
504,
7209,
492,
22447,
1361,
12,
1056,
199,
504,
7209,
14,
832,
14,
2113,
492,
3523,
2768,
12,
23705,
199,
646,
10634,
465,
6454,
199,
199,
504,
16321,
14,
7922,
492,
869,
1912,
3396,
1617,
8481,
12,
4932,
16790,
8481,
12,
510,
3911,
79,
8481,
12,
869,
1912,
20653,
8481,
199,
504,
16321,
14,
5265,
63,
2609,
492,
31040,
5061,
199,
504,
16321,
14,
1544,
492,
3778,
465,
20732,
1208,
199,
199,
10614,
16169,
63,
17489,
63,
998,
275,
283,
2024,
1617,
63,
885,
7,
199,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
275,
283,
2024,
1617,
63,
8644,
7,
199,
3311,
1719,
47,
63,
17489,
63,
998,
275,
283,
657,
14308,
63,
885,
7,
199,
40,
5399,
63,
7802,
63,
17489,
63,
998,
275,
283,
17230,
63,
885,
7,
199,
3472,
63,
2846,
275,
283,
885,
7,
199,
2846,
63,
18817,
4924,
275,
488,
199,
2846,
63,
23113,
4924,
275,
788,
2791,
418,
199,
8723,
63,
25691,
63,
13387,
275,
12293,
199,
199,
3,
1804,
1024,
4073,
10634,
687,
8181,
67,
1958,
1846,
3326,
199,
8961,
14,
409,
63,
1422,
360,
2918,
14,
988,
63,
761,
2063,
297,
446,
17,
9,
421,
199,
3,
20507,
282,
7209,
4628,
3523,
2768,
199,
533,
6288,
1617,
11930,
2768,
8,
1563,
2768,
12,
20732,
1208,
14,
1451,
919,
19294,
4256,
304,
339,
768,
20586,
7825,
272,
347,
1478,
8,
277,
304,
267,
3875,
275,
408,
267,
10468,
288,
282,
14,
354,
465,
1592,
12,
1592,
63,
1985,
63,
2302,
465,
2909,
12,
288,
2338,
8,
17,
9,
465,
909,
63,
835,
12,
282,
14,
3257,
465,
1369,
267,
4442,
6249,
51,
282,
267,
10593,
377,
34,
5296,
330,
5258,
282,
14,
2846,
63,
998,
275,
330,
14,
2846,
63,
998,
267,
15443,
6515,
282,
14,
354,
12,
1592,
63,
1985,
63,
2302,
12,
282,
14,
3257,
267,
30512,
908,
3682,
9350,
1012,
267,
394,
275,
4932,
16790,
8481,
8,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
9,
267,
4051,
275,
394,
14,
362,
63,
15718,
63,
1587,
8,
3009,
9,
267,
4051,
14,
697,
275,
334,
288,
2650,
65,
4369,
9555,
2113,
15,
2024,
1617,
5750,
1345,
15,
697,
10197,
697,
534,
435,
288,
4051,
14,
697,
435,
283,
15603,
435,
4051,
14,
697,
435,
11936,
65,
5971,
267,
1817,
275,
4051,
14,
475,
63,
1360,
8,
288,
3992,
628,
1224,
1817,
13,
816,
1915,
1817,
13,
66,
8235,
1817,
13,
22797,
401,
288,
1478,
29,
797,
12,
288,
4772,
29,
797,
12,
288,
11802,
63,
1155,
4581,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
30764,
14,
1360,
401,
1817,
29,
1224,
9,
339,
768,
20586,
2336,
1224,
6217,
272,
347,
1817,
8,
277,
304,
267,
1817,
63,
354,
275,
1056,
14,
589,
14,
362,
480,
1224,
531,
267,
333,
275,
869,
1912,
3396,
1617,
8481,
8,
10614,
16169,
63,
17489,
63,
998,
9,
267,
1817,
275,
333,
14,
362,
63,
1224,
8,
1224,
63,
354,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
1224,
14,
1360,
401,
288,
1817,
29,
1224,
12,
1817,
63,
354,
29,
1224,
63,
354,
12,
2197,
29,
2083,
12,
1109,
29,
442,
9,
339,
768,
20586,
2336,
697,
6217,
272,
347,
1592,
8,
277,
304,
267,
1592,
275,
1056,
14,
589,
14,
362,
480,
697,
531,
267,
333,
275,
869,
1912,
3396,
1617,
8481,
8,
10614,
16169,
63,
17489,
63,
998,
9,
267,
6716,
275,
3355,
8,
77,
14,
362,
63,
5987,
8,
697,
29,
697,
395,
790,
29,
2734,
671,
26,
671,
14,
1224,
985,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
697,
14,
1360,
401,
6716,
29,
5987,
12,
1592,
29,
697,
9,
339,
768,
1544,
1208,
14,
12256,
1915,
272,
768,
20586,
2336,
12553,
6217,
272,
347,
16394,
8,
277,
304,
267,
4177,
12,
1817,
275,
1056,
14,
589,
14,
362,
480,
1224,
3471,
1294,
7563,
267,
3875,
275,
408,
267,
10468,
288,
282,
14,
14848,
63,
2339,
12,
288,
282,
14,
8366,
63,
4961,
12,
288,
286,
14,
16575,
12,
288,
286,
14,
1311,
63,
6790,
3830,
10934,
12,
288,
286,
14,
7321,
63,
4807,
12,
288,
286,
14,
8414,
63,
4807,
267,
4442,
3076,
649,
2823,
282,
267,
10593,
377,
34,
5296,
330,
5258,
282,
14,
52,
7847,
63,
998,
275,
330,
14,
52,
7847,
63,
998,
267,
10593,
6249,
51,
366,
5258,
330,
14,
2846,
63,
998,
275,
366,
14,
2846,
63,
998,
267,
10593,
428,
3177,
286,
5258,
282,
14,
3693,
63,
998,
275,
286,
14,
3693,
63,
998,
267,
6038,
288,
330,
14,
52,
7847,
63,
2339,
2839,
5041,
1224,
6834,
2401,
288,
366,
14,
2339,
2839,
5041,
3629,
6834,
267,
16044,
6515,
3076,
63,
2339,
23915,
267,
30512,
908,
3682,
9350,
1012,
267,
394,
275,
4932,
16790,
8481,
8,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
9,
267,
4051,
275,
394,
14,
362,
63,
15718,
63,
1587,
8,
3009,
9,
267,
372,
4051,
14,
475,
63,
1360,
8,
288,
3992,
628,
1224,
1817,
13,
816,
1915,
1817,
13,
66,
8235,
1817,
13,
22797,
401,
288,
1478,
29,
797,
12,
288,
11802,
63,
1155,
4581,
9,
339,
768,
1544,
1208,
14,
12256,
1915,
272,
768,
20586,
2336,
1462,
6217,
272,
347,
2251,
8,
277,
304,
267,
2382,
63,
8501,
275,
2125,
267,
340,
6249,
63,
18817,
4924,
26,
288,
366,
1533,
275,
19089,
904,
5234,
4065,
435,
1592,
435,
21673,
367,
1592,
315,
6249,
63,
18817,
4924,
566,
288,
2382,
63,
8501,
275,
298,
3649,
330,
14,
354,
1621,
11459,
25974,
908,
8,
30764,
9,
267,
340,
6249,
63,
23113,
4924,
26,
288,
366,
1533,
275,
19089,
904,
5234,
4065,
435,
1592,
435,
21673,
367,
1592,
315,
6249,
63,
23113,
4924,
566,
288,
2382,
63,
8501,
275,
298,
3649,
330,
14,
354,
2845,
1621,
11459,
25974,
908,
8,
30764,
9,
267,
3875,
275,
408,
267,
10468,
1868,
11206,
8,
66,
14,
2339,
12,
22608,
282,
14,
52,
7847,
63,
2339,
395,
377,
7847,
63,
2711,
267,
4442,
377,
34,
5296,
282,
267,
10593,
6249,
51,
330,
5258
] |
[
2197,
492,
2197,
199,
646,
2022,
199,
199,
504,
7209,
492,
22447,
1361,
12,
1056,
199,
504,
7209,
14,
832,
14,
2113,
492,
3523,
2768,
12,
23705,
199,
646,
10634,
465,
6454,
199,
199,
504,
16321,
14,
7922,
492,
869,
1912,
3396,
1617,
8481,
12,
4932,
16790,
8481,
12,
510,
3911,
79,
8481,
12,
869,
1912,
20653,
8481,
199,
504,
16321,
14,
5265,
63,
2609,
492,
31040,
5061,
199,
504,
16321,
14,
1544,
492,
3778,
465,
20732,
1208,
199,
199,
10614,
16169,
63,
17489,
63,
998,
275,
283,
2024,
1617,
63,
885,
7,
199,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
275,
283,
2024,
1617,
63,
8644,
7,
199,
3311,
1719,
47,
63,
17489,
63,
998,
275,
283,
657,
14308,
63,
885,
7,
199,
40,
5399,
63,
7802,
63,
17489,
63,
998,
275,
283,
17230,
63,
885,
7,
199,
3472,
63,
2846,
275,
283,
885,
7,
199,
2846,
63,
18817,
4924,
275,
488,
199,
2846,
63,
23113,
4924,
275,
788,
2791,
418,
199,
8723,
63,
25691,
63,
13387,
275,
12293,
199,
199,
3,
1804,
1024,
4073,
10634,
687,
8181,
67,
1958,
1846,
3326,
199,
8961,
14,
409,
63,
1422,
360,
2918,
14,
988,
63,
761,
2063,
297,
446,
17,
9,
421,
199,
3,
20507,
282,
7209,
4628,
3523,
2768,
199,
533,
6288,
1617,
11930,
2768,
8,
1563,
2768,
12,
20732,
1208,
14,
1451,
919,
19294,
4256,
304,
339,
768,
20586,
7825,
272,
347,
1478,
8,
277,
304,
267,
3875,
275,
408,
267,
10468,
288,
282,
14,
354,
465,
1592,
12,
1592,
63,
1985,
63,
2302,
465,
2909,
12,
288,
2338,
8,
17,
9,
465,
909,
63,
835,
12,
282,
14,
3257,
465,
1369,
267,
4442,
6249,
51,
282,
267,
10593,
377,
34,
5296,
330,
5258,
282,
14,
2846,
63,
998,
275,
330,
14,
2846,
63,
998,
267,
15443,
6515,
282,
14,
354,
12,
1592,
63,
1985,
63,
2302,
12,
282,
14,
3257,
267,
30512,
908,
3682,
9350,
1012,
267,
394,
275,
4932,
16790,
8481,
8,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
9,
267,
4051,
275,
394,
14,
362,
63,
15718,
63,
1587,
8,
3009,
9,
267,
4051,
14,
697,
275,
334,
288,
2650,
65,
4369,
9555,
2113,
15,
2024,
1617,
5750,
1345,
15,
697,
10197,
697,
534,
435,
288,
4051,
14,
697,
435,
283,
15603,
435,
4051,
14,
697,
435,
11936,
65,
5971,
267,
1817,
275,
4051,
14,
475,
63,
1360,
8,
288,
3992,
628,
1224,
1817,
13,
816,
1915,
1817,
13,
66,
8235,
1817,
13,
22797,
401,
288,
1478,
29,
797,
12,
288,
4772,
29,
797,
12,
288,
11802,
63,
1155,
4581,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
30764,
14,
1360,
401,
1817,
29,
1224,
9,
339,
768,
20586,
2336,
1224,
6217,
272,
347,
1817,
8,
277,
304,
267,
1817,
63,
354,
275,
1056,
14,
589,
14,
362,
480,
1224,
531,
267,
333,
275,
869,
1912,
3396,
1617,
8481,
8,
10614,
16169,
63,
17489,
63,
998,
9,
267,
1817,
275,
333,
14,
362,
63,
1224,
8,
1224,
63,
354,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
1224,
14,
1360,
401,
288,
1817,
29,
1224,
12,
1817,
63,
354,
29,
1224,
63,
354,
12,
2197,
29,
2083,
12,
1109,
29,
442,
9,
339,
768,
20586,
2336,
697,
6217,
272,
347,
1592,
8,
277,
304,
267,
1592,
275,
1056,
14,
589,
14,
362,
480,
697,
531,
267,
333,
275,
869,
1912,
3396,
1617,
8481,
8,
10614,
16169,
63,
17489,
63,
998,
9,
267,
6716,
275,
3355,
8,
77,
14,
362,
63,
5987,
8,
697,
29,
697,
395,
790,
29,
2734,
671,
26,
671,
14,
1224,
985,
9,
267,
372,
291,
14,
3352,
8,
288,
298,
2024,
1617,
63,
5750,
15,
697,
14,
1360,
401,
6716,
29,
5987,
12,
1592,
29,
697,
9,
339,
768,
1544,
1208,
14,
12256,
1915,
272,
768,
20586,
2336,
12553,
6217,
272,
347,
16394,
8,
277,
304,
267,
4177,
12,
1817,
275,
1056,
14,
589,
14,
362,
480,
1224,
3471,
1294,
7563,
267,
3875,
275,
408,
267,
10468,
288,
282,
14,
14848,
63,
2339,
12,
288,
282,
14,
8366,
63,
4961,
12,
288,
286,
14,
16575,
12,
288,
286,
14,
1311,
63,
6790,
3830,
10934,
12,
288,
286,
14,
7321,
63,
4807,
12,
288,
286,
14,
8414,
63,
4807,
267,
4442,
3076,
649,
2823,
282,
267,
10593,
377,
34,
5296,
330,
5258,
282,
14,
52,
7847,
63,
998,
275,
330,
14,
52,
7847,
63,
998,
267,
10593,
6249,
51,
366,
5258,
330,
14,
2846,
63,
998,
275,
366,
14,
2846,
63,
998,
267,
10593,
428,
3177,
286,
5258,
282,
14,
3693,
63,
998,
275,
286,
14,
3693,
63,
998,
267,
6038,
288,
330,
14,
52,
7847,
63,
2339,
2839,
5041,
1224,
6834,
2401,
288,
366,
14,
2339,
2839,
5041,
3629,
6834,
267,
16044,
6515,
3076,
63,
2339,
23915,
267,
30512,
908,
3682,
9350,
1012,
267,
394,
275,
4932,
16790,
8481,
8,
10614,
16169,
63,
12339,
4657,
63,
17489,
63,
998,
9,
267,
4051,
275,
394,
14,
362,
63,
15718,
63,
1587,
8,
3009,
9,
267,
372,
4051,
14,
475,
63,
1360,
8,
288,
3992,
628,
1224,
1817,
13,
816,
1915,
1817,
13,
66,
8235,
1817,
13,
22797,
401,
288,
1478,
29,
797,
12,
288,
11802,
63,
1155,
4581,
9,
339,
768,
1544,
1208,
14,
12256,
1915,
272,
768,
20586,
2336,
1462,
6217,
272,
347,
2251,
8,
277,
304,
267,
2382,
63,
8501,
275,
2125,
267,
340,
6249,
63,
18817,
4924,
26,
288,
366,
1533,
275,
19089,
904,
5234,
4065,
435,
1592,
435,
21673,
367,
1592,
315,
6249,
63,
18817,
4924,
566,
288,
2382,
63,
8501,
275,
298,
3649,
330,
14,
354,
1621,
11459,
25974,
908,
8,
30764,
9,
267,
340,
6249,
63,
23113,
4924,
26,
288,
366,
1533,
275,
19089,
904,
5234,
4065,
435,
1592,
435,
21673,
367,
1592,
315,
6249,
63,
23113,
4924,
566,
288,
2382,
63,
8501,
275,
298,
3649,
330,
14,
354,
2845,
1621,
11459,
25974,
908,
8,
30764,
9,
267,
3875,
275,
408,
267,
10468,
1868,
11206,
8,
66,
14,
2339,
12,
22608,
282,
14,
52,
7847,
63,
2339,
395,
377,
7847,
63,
2711,
267,
4442,
377,
34,
5296,
282,
267,
10593,
6249,
51,
330,
5258,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
houlixin/BBB-TISDK
|
linux-devkit/sysroots/i686-arago-linux/usr/lib/python2.7/sysconfig.py
|
2
|
25753
|
"""Provide access to Python's configuration information.
"""
import sys
import os
from os.path import pardir, realpath
_INSTALL_SCHEMES = {
'posix_prefix': {
'stdlib': '{base}/'+sys.lib+'/python{py_version_short}',
'platstdlib': '{platbase}/'+sys.lib+'/python{py_version_short}',
'purelib': '{base}/'+sys.lib+'/python{py_version_short}/site-packages',
'platlib': '{platbase}/'+sys.lib+'/python{py_version_short}/site-packages',
'include': '{base}/include/python{py_version_short}',
'platinclude': '{platbase}/include/python{py_version_short}',
'scripts': '{base}/bin',
'data': '{base}',
},
'posix_home': {
'stdlib': '{base}/lib/python',
'platstdlib': '{base}/lib/python',
'purelib': '{base}/lib/python',
'platlib': '{base}/lib/python',
'include': '{base}/include/python',
'platinclude': '{base}/include/python',
'scripts': '{base}/bin',
'data' : '{base}',
},
'nt': {
'stdlib': '{base}/Lib',
'platstdlib': '{base}/Lib',
'purelib': '{base}/Lib/site-packages',
'platlib': '{base}/Lib/site-packages',
'include': '{base}/Include',
'platinclude': '{base}/Include',
'scripts': '{base}/Scripts',
'data' : '{base}',
},
'os2': {
'stdlib': '{base}/Lib',
'platstdlib': '{base}/Lib',
'purelib': '{base}/Lib/site-packages',
'platlib': '{base}/Lib/site-packages',
'include': '{base}/Include',
'platinclude': '{base}/Include',
'scripts': '{base}/Scripts',
'data' : '{base}',
},
'os2_home': {
'stdlib': '{userbase}/lib/python{py_version_short}',
'platstdlib': '{userbase}/lib/python{py_version_short}',
'purelib': '{userbase}/lib/python{py_version_short}/site-packages',
'platlib': '{userbase}/lib/python{py_version_short}/site-packages',
'include': '{userbase}/include/python{py_version_short}',
'scripts': '{userbase}/bin',
'data' : '{userbase}',
},
'nt_user': {
'stdlib': '{userbase}/Python{py_version_nodot}',
'platstdlib': '{userbase}/Python{py_version_nodot}',
'purelib': '{userbase}/Python{py_version_nodot}/site-packages',
'platlib': '{userbase}/Python{py_version_nodot}/site-packages',
'include': '{userbase}/Python{py_version_nodot}/Include',
'scripts': '{userbase}/Scripts',
'data' : '{userbase}',
},
'posix_user': {
'stdlib': '{userbase}/'+sys.lib+'/python{py_version_short}',
'platstdlib': '{userbase}/'+sys.lib+'/python{py_version_short}',
'purelib': '{userbase}/'+sys.lib+'/python{py_version_short}/site-packages',
'platlib': '{userbase}/'+sys.lib+'/python{py_version_short}/site-packages',
'include': '{userbase}/include/python{py_version_short}',
'scripts': '{userbase}/bin',
'data' : '{userbase}',
},
'osx_framework_user': {
'stdlib': '{userbase}/lib/python',
'platstdlib': '{userbase}/lib/python',
'purelib': '{userbase}/lib/python/site-packages',
'platlib': '{userbase}/lib/python/site-packages',
'include': '{userbase}/include',
'scripts': '{userbase}/bin',
'data' : '{userbase}',
},
}
_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
'scripts', 'data')
_PY_VERSION = sys.version.split()[0]
_PY_VERSION_SHORT = sys.version[:3]
_PY_VERSION_SHORT_NO_DOT = _PY_VERSION[0] + _PY_VERSION[2]
_PREFIX = os.path.normpath(sys.prefix)
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
_CONFIG_VARS = None
_USER_BASE = None
_PYTHONBUILDDIR = os.environ.get("PYTHONBUILDDIR", None)
def _safe_realpath(path):
try:
return realpath(path)
except OSError:
return path
if _PYTHONBUILDDIR:
_PROJECT_BASE = _PYTHONBUILDDIR
elif sys.executable:
_PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
else:
# sys.executable can be empty if argv[0] has been changed and Python is
# unable to retrieve the real program name
_PROJECT_BASE = _safe_realpath(os.getcwd())
if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir))
# PC/VS7.1
if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
# PC/AMD64
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
def is_python_build():
for fn in ("Setup.dist", "Setup.local"):
if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
return True
return False
_PYTHON_BUILD = is_python_build()
if _PYTHON_BUILD:
for scheme in ('posix_prefix', 'posix_home'):
_INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/Include'
_INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}'
def _subst_vars(s, local_vars):
try:
return s.format(**local_vars)
except KeyError:
try:
return s.format(**os.environ)
except KeyError, var:
raise AttributeError('{%s}' % var)
def _extend_dict(target_dict, other_dict):
target_keys = target_dict.keys()
for key, value in other_dict.items():
if key in target_keys:
continue
target_dict[key] = value
def _expand_vars(scheme, vars):
res = {}
if vars is None:
vars = {}
_extend_dict(vars, get_config_vars())
for key, value in _INSTALL_SCHEMES[scheme].items():
if os.name in ('posix', 'nt'):
value = os.path.expanduser(value)
res[key] = os.path.normpath(_subst_vars(value, vars))
return res
def _get_default_scheme():
if os.name == 'posix':
# the default scheme for posix is posix_prefix
return 'posix_prefix'
return os.name
def _getuserbase():
env_base = os.environ.get("PYTHONUSERBASE", None)
def joinuser(*args):
return os.path.expanduser(os.path.join(*args))
# what about 'os2emx', 'riscos' ?
if os.name == "nt":
base = os.environ.get("APPDATA") or "~"
return env_base if env_base else joinuser(base, "Python")
if sys.platform == "darwin":
framework = get_config_var("PYTHONFRAMEWORK")
if framework:
return env_base if env_base else \
joinuser("~", "Library", framework, "%d.%d"
% (sys.version_info[:2]))
return env_base if env_base else joinuser("~", ".local")
def _parse_makefile(filename, vars=None):
"""Parse a Makefile-style file.
A dictionary containing name/value pairs is returned. If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
import re
# Regexes needed for parsing Makefile (and similar syntaxes,
# like old-style Setup files).
_variable_rx = re.compile("([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*(.*)")
_findvar1_rx = re.compile(r"\$\(([A-Za-z][A-Za-z0-9_]*)\)")
_findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
if vars is None:
vars = {}
done = {}
notdone = {}
with open(filename) as f:
lines = f.readlines()
for line in lines:
if line.startswith('#') or line.strip() == '':
continue
m = _variable_rx.match(line)
if m:
n, v = m.group(1, 2)
v = v.strip()
# `$$' is a literal `$' in make
tmpv = v.replace('$$', '')
if "$" in tmpv:
notdone[n] = v
else:
try:
v = int(v)
except ValueError:
# insert literal `$'
done[n] = v.replace('$$', '$')
else:
done[n] = v
# do variable interpolation here
while notdone:
for name in notdone.keys():
value = notdone[name]
m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
if m:
n = m.group(1)
found = True
if n in done:
item = str(done[n])
elif n in notdone:
# get it on a subsequent round
found = False
elif n in os.environ:
# do it like make: fall back to environment
item = os.environ[n]
else:
done[n] = item = ""
if found:
after = value[m.end():]
value = value[:m.start()] + item + after
if "$" in after:
notdone[name] = value
else:
try: value = int(value)
except ValueError:
done[name] = value.strip()
else:
done[name] = value
del notdone[name]
else:
# bogus variable reference; just drop it since we can't deal
del notdone[name]
# strip spurious spaces
for k, v in done.items():
if isinstance(v, str):
done[k] = v.strip()
# save the results in the global dictionary
vars.update(done)
return vars
def _get_makefile_filename():
if _PYTHON_BUILD:
return os.path.join(_PROJECT_BASE, "Makefile")
return os.path.join(get_path('platstdlib'), "config", "Makefile")
def _init_posix(vars):
"""Initialize the module as appropriate for POSIX systems."""
# load the installed Makefile:
makefile = _get_makefile_filename()
try:
_parse_makefile(makefile, vars)
except IOError, e:
msg = "invalid Python installation: unable to open %s" % makefile
if hasattr(e, "strerror"):
msg = msg + " (%s)" % e.strerror
raise IOError(msg)
# load the installed pyconfig.h:
config_h = get_config_h_filename()
try:
with open(config_h) as f:
parse_config_h(f, vars)
except IOError, e:
msg = "invalid Python installation: unable to open %s" % config_h
if hasattr(e, "strerror"):
msg = msg + " (%s)" % e.strerror
raise IOError(msg)
# On AIX, there are wrong paths to the linker scripts in the Makefile
# -- these paths are relative to the Python source, but when installed
# the scripts are in another directory.
if _PYTHON_BUILD:
vars['LDSHARED'] = vars['BLDSHARED']
def _init_non_posix(vars):
"""Initialize the module as appropriate for NT"""
# set basic install directories
vars['LIBDEST'] = get_path('stdlib')
vars['BINLIBDEST'] = get_path('platstdlib')
vars['INCLUDEPY'] = get_path('include')
vars['SO'] = '.pyd'
vars['EXE'] = '.exe'
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
#
# public APIs
#
def parse_config_h(fp, vars=None):
"""Parse a config.h-style file.
A dictionary containing name/value pairs is returned. If an
optional dictionary is passed in as the second argument, it is
used instead of a new dictionary.
"""
import re
if vars is None:
vars = {}
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
while True:
line = fp.readline()
if not line:
break
m = define_rx.match(line)
if m:
n, v = m.group(1, 2)
try: v = int(v)
except ValueError: pass
vars[n] = v
else:
m = undef_rx.match(line)
if m:
vars[m.group(1)] = 0
return vars
def get_config_h_filename():
"""Returns the path of pyconfig.h."""
if _PYTHON_BUILD:
if os.name == "nt":
inc_dir = os.path.join(_PROJECT_BASE, "PC")
else:
inc_dir = _PROJECT_BASE
else:
inc_dir = get_path('platinclude')
return os.path.join(inc_dir, 'pyconfig.h')
def get_scheme_names():
"""Returns a tuple containing the schemes names."""
schemes = _INSTALL_SCHEMES.keys()
schemes.sort()
return tuple(schemes)
def get_path_names():
"""Returns a tuple containing the paths names."""
return _SCHEME_KEYS
def get_paths(scheme=_get_default_scheme(), vars=None, expand=True):
"""Returns a mapping containing an install scheme.
``scheme`` is the install scheme name. If not provided, it will
return the default scheme for the current platform.
"""
if expand:
return _expand_vars(scheme, vars)
else:
return _INSTALL_SCHEMES[scheme]
def get_path(name, scheme=_get_default_scheme(), vars=None, expand=True):
"""Returns a path corresponding to the scheme.
``scheme`` is the install scheme name.
"""
return get_paths(scheme, vars, expand)[name]
def get_config_vars(*args):
"""With no arguments, return a dictionary of all configuration
variables relevant for the current platform.
On Unix, this means every variable defined in Python's installed Makefile;
On Windows and Mac OS it's a much smaller set.
With arguments, return a list of values that result from looking up
each argument in the configuration variable dictionary.
"""
import re
global _CONFIG_VARS
if _CONFIG_VARS is None:
_CONFIG_VARS = {}
# Normalized versions of prefix and exec_prefix are handy to have;
# in fact, these are the standard versions used most places in the
# Distutils.
_CONFIG_VARS['prefix'] = _PREFIX
_CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
_CONFIG_VARS['py_version'] = _PY_VERSION
_CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
_CONFIG_VARS['py_version_nodot'] = _PY_VERSION[0] + _PY_VERSION[2]
_CONFIG_VARS['base'] = _PREFIX
_CONFIG_VARS['platbase'] = _EXEC_PREFIX
_CONFIG_VARS['projectbase'] = _PROJECT_BASE
if os.name in ('nt', 'os2'):
_init_non_posix(_CONFIG_VARS)
if os.name == 'posix':
_init_posix(_CONFIG_VARS)
# Setting 'userbase' is done below the call to the
# init function to enable using 'get_config_var' in
# the init-function.
_CONFIG_VARS['userbase'] = _getuserbase()
if 'srcdir' not in _CONFIG_VARS:
_CONFIG_VARS['srcdir'] = _PROJECT_BASE
# Convert srcdir into an absolute path if it appears necessary.
# Normally it is relative to the build directory. However, during
# testing, for example, we might be running a non-installed python
# from a different directory.
if _PYTHON_BUILD and os.name == "posix":
base = _PROJECT_BASE
try:
cwd = os.getcwd()
except OSError:
cwd = None
if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
base != cwd):
# srcdir is relative and we are not in the same directory
# as the executable. Assume executable is in the build
# directory and make srcdir absolute.
srcdir = os.path.join(base, _CONFIG_VARS['srcdir'])
_CONFIG_VARS['srcdir'] = os.path.normpath(srcdir)
if sys.platform == 'darwin':
kernel_version = os.uname()[2] # Kernel version (8.4.3)
major_version = int(kernel_version.split('.')[0])
if major_version < 8:
# On Mac OS X before 10.4, check if -arch and -isysroot
# are in CFLAGS or LDFLAGS and remove them if they are.
# This is needed when building extensions on a 10.3 system
# using a universal build of python.
for key in ('LDFLAGS', 'BASECFLAGS',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _CONFIG_VARS[key]
flags = re.sub('-arch\s+\w+\s', ' ', flags)
flags = re.sub('-isysroot [^ \t]*', ' ', flags)
_CONFIG_VARS[key] = flags
else:
# Allow the user to override the architecture flags using
# an environment variable.
# NOTE: This name was introduced by Apple in OSX 10.5 and
# is used by several scripting languages distributed with
# that OS release.
if 'ARCHFLAGS' in os.environ:
arch = os.environ['ARCHFLAGS']
for key in ('LDFLAGS', 'BASECFLAGS',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _CONFIG_VARS[key]
flags = re.sub('-arch\s+\w+\s', ' ', flags)
flags = flags + ' ' + arch
_CONFIG_VARS[key] = flags
# If we're on OSX 10.5 or later and the user tries to
# compiles an extension using an SDK that is not present
# on the current machine it is better to not use an SDK
# than to fail.
#
# The major usecase for this is users using a Python.org
# binary installer on OSX 10.6: that installer uses
# the 10.4u SDK, but that SDK is not installed by default
# when you install Xcode.
#
CFLAGS = _CONFIG_VARS.get('CFLAGS', '')
m = re.search('-isysroot\s+(\S+)', CFLAGS)
if m is not None:
sdk = m.group(1)
if not os.path.exists(sdk):
for key in ('LDFLAGS', 'BASECFLAGS',
# a number of derived variables. These need to be
# patched up as well.
'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
flags = _CONFIG_VARS[key]
flags = re.sub('-isysroot\s+\S+(\s|$)', ' ', flags)
_CONFIG_VARS[key] = flags
if args:
vals = []
for name in args:
vals.append(_CONFIG_VARS.get(name))
return vals
else:
return _CONFIG_VARS
def get_config_var(name):
"""Return the value of a single variable using the dictionary returned by
'get_config_vars()'.
Equivalent to get_config_vars().get(name)
"""
return get_config_vars().get(name)
def get_platform():
"""Return a string that identifies the current platform.
This is used mainly to distinguish platform-specific build directories and
platform-specific built distributions. Typically includes the OS name
and version and the architecture (as supplied by 'os.uname()'),
although the exact information included depends on the OS; eg. for IRIX
the architecture isn't particularly important (IRIX only runs on SGI
hardware), but for Linux the kernel version isn't particularly
important.
Examples of returned values:
linux-i586
linux-alpha (?)
solaris-2.6-sun4u
irix-5.3
irix64-6.2
Windows will return one of:
win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
win-ia64 (64bit Windows on Itanium)
win32 (all others - specifically, sys.platform is returned)
For other non-POSIX platforms, currently just returns 'sys.platform'.
"""
import re
if os.name == 'nt':
# sniff sys.version for architecture.
prefix = " bit ("
i = sys.version.find(prefix)
if i == -1:
return sys.platform
j = sys.version.find(")", i)
look = sys.version[i+len(prefix):j].lower()
if look == 'amd64':
return 'win-amd64'
if look == 'itanium':
return 'win-ia64'
return sys.platform
if os.name != "posix" or not hasattr(os, 'uname'):
# XXX what about the architecture? NT is Intel or Alpha,
# Mac OS is M68k or PPC, etc.
return sys.platform
# Try to distinguish various flavours of Unix
osname, host, release, version, machine = os.uname()
# Convert the OS name to lowercase, remove '/' characters
# (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
osname = osname.lower().replace('/', '')
machine = machine.replace(' ', '_')
machine = machine.replace('/', '-')
if osname[:5] == "linux":
# At least on Linux/Intel, 'machine' is the processor --
# i386, etc.
# XXX what about Alpha, SPARC, etc?
return "%s-%s" % (osname, machine)
elif osname[:5] == "sunos":
if release[0] >= "5": # SunOS 5 == Solaris 2
osname = "solaris"
release = "%d.%s" % (int(release[0]) - 3, release[2:])
# We can't use "platform.architecture()[0]" because a
# bootstrap problem. We use a dict to get an error
# if some suspicious happens.
bitness = {2147483647:"32bit", 9223372036854775807:"64bit"}
machine += ".%s" % bitness[sys.maxint]
# fall through to standard osname-release-machine representation
elif osname[:4] == "irix": # could be "irix64"!
return "%s-%s" % (osname, release)
elif osname[:3] == "aix":
return "%s-%s.%s" % (osname, version, release)
elif osname[:6] == "cygwin":
osname = "cygwin"
rel_re = re.compile (r'[\d.]+')
m = rel_re.match(release)
if m:
release = m.group()
elif osname[:6] == "darwin":
#
# For our purposes, we'll assume that the system version from
# distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
# to. This makes the compatibility story a bit more sane because the
# machine is going to compile and link as if it were
# MACOSX_DEPLOYMENT_TARGET.
cfgvars = get_config_vars()
macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
if 1:
# Always calculate the release of the running machine,
# needed to determine if we can build fat binaries or not.
macrelease = macver
# Get the system version. Reading this plist is a documented
# way to get the system version (see the documentation for
# the Gestalt Manager)
try:
f = open('/System/Library/CoreServices/SystemVersion.plist')
except IOError:
# We're on a plain darwin box, fall back to the default
# behaviour.
pass
else:
try:
m = re.search(
r'<key>ProductUserVisibleVersion</key>\s*' +
r'<string>(.*?)</string>', f.read())
if m is not None:
macrelease = '.'.join(m.group(1).split('.')[:2])
# else: fall back to the default behaviour
finally:
f.close()
if not macver:
macver = macrelease
if macver:
release = macver
osname = "macosx"
if (macrelease + '.') >= '10.4.' and \
'-arch' in get_config_vars().get('CFLAGS', '').strip():
# The universal build will build fat binaries, but not on
# systems before 10.4
#
# Try to detect 4-way universal builds, those have machine-type
# 'universal' instead of 'fat'.
machine = 'fat'
cflags = get_config_vars().get('CFLAGS')
archs = re.findall('-arch\s+(\S+)', cflags)
archs = tuple(sorted(set(archs)))
if len(archs) == 1:
machine = archs[0]
elif archs == ('i386', 'ppc'):
machine = 'fat'
elif archs == ('i386', 'x86_64'):
machine = 'intel'
elif archs == ('i386', 'ppc', 'x86_64'):
machine = 'fat3'
elif archs == ('ppc64', 'x86_64'):
machine = 'fat64'
elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
machine = 'universal'
else:
raise ValueError(
"Don't know machine value for archs=%r"%(archs,))
elif machine == 'i386':
# On OSX the machine type returned by uname is always the
# 32-bit variant, even if the executable architecture is
# the 64-bit variant
if sys.maxint >= 2**32:
machine = 'x86_64'
elif machine in ('PowerPC', 'Power_Macintosh'):
# Pick a sane name for the PPC architecture.
# See 'i386' case
if sys.maxint >= 2**32:
machine = 'ppc64'
else:
machine = 'ppc'
return "%s-%s-%s" % (osname, release, machine)
def get_python_version():
return _PY_VERSION_SHORT
|
gpl-2.0
|
[
624,
25107,
2879,
370,
2018,
1159,
2897,
2556,
14,
199,
199,
624,
199,
646,
984,
199,
646,
747,
199,
504,
747,
14,
515,
492,
623,
694,
12,
3363,
515,
199,
199,
63,
16811,
63,
17859,
654,
275,
469,
272,
283,
9228,
63,
1861,
356,
469,
267,
283,
28683,
356,
5041,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
14156,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
14156,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
2613,
356,
5041,
14156,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
1095,
5995,
1393,
297,
267,
283,
576,
356,
5041,
1095,
7293,
267,
1660,
272,
283,
9228,
63,
4219,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
343,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
736,
18,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
736,
18,
63,
4219,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
343,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
9228,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
28197,
63,
4857,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
297,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
297,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
789,
199,
199,
63,
30430,
63,
17434,
275,
661,
28683,
297,
283,
14156,
28683,
297,
283,
31882,
297,
283,
14156,
773,
297,
283,
2613,
297,
355,
283,
6429,
297,
283,
576,
358,
199,
63,
4521,
63,
4612,
275,
984,
14,
1023,
14,
1294,
3430,
16,
61,
199,
63,
4521,
63,
4612,
63,
13003,
275,
984,
14,
1023,
1491,
19
] |
[
25107,
2879,
370,
2018,
1159,
2897,
2556,
14,
199,
199,
624,
199,
646,
984,
199,
646,
747,
199,
504,
747,
14,
515,
492,
623,
694,
12,
3363,
515,
199,
199,
63,
16811,
63,
17859,
654,
275,
469,
272,
283,
9228,
63,
1861,
356,
469,
267,
283,
28683,
356,
5041,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
14156,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
14156,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
2613,
356,
5041,
14156,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
1095,
5995,
1393,
297,
267,
283,
576,
356,
5041,
1095,
7293,
267,
1660,
272,
283,
9228,
63,
4219,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
773,
15,
1548,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
2613,
15,
1548,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
343,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
736,
18,
356,
469,
267,
283,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
14156,
28683,
356,
5041,
1095,
5995,
4728,
297,
267,
283,
31882,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
1095,
5995,
4728,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
14156,
2613,
356,
5041,
1095,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
1095,
7293,
267,
1660,
272,
283,
736,
18,
63,
4219,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
343,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
4718,
91,
647,
63,
1023,
63,
18950,
357,
5995,
7826,
297,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
25681,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
9228,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
31882,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
93,
19047,
1274,
14,
773,
23164,
1548,
91,
647,
63,
1023,
63,
3612,
5995,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
15,
1548,
91,
647,
63,
1023,
63,
3612,
7293,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
283,
28197,
63,
4857,
63,
751,
356,
469,
267,
283,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
297,
267,
283,
14156,
28683,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
297,
267,
283,
31882,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
15,
2124,
13,
5154,
297,
267,
283,
14156,
773,
356,
5041,
751,
1095,
5995,
773,
15,
1548,
15,
2124,
13,
5154,
297,
267,
283,
2613,
356,
5041,
751,
1095,
5995,
2613,
297,
267,
283,
6429,
356,
5041,
751,
1095,
5995,
1393,
297,
267,
283,
576,
7,
257,
520,
5041,
751,
1095,
7293,
267,
1660,
272,
789,
199,
199,
63,
30430,
63,
17434,
275,
661,
28683,
297,
283,
14156,
28683,
297,
283,
31882,
297,
283,
14156,
773,
297,
283,
2613,
297,
355,
283,
6429,
297,
283,
576,
358,
199,
63,
4521,
63,
4612,
275,
984,
14,
1023,
14,
1294,
3430,
16,
61,
199,
63,
4521,
63,
4612,
63,
13003,
275,
984,
14,
1023,
1491,
19,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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-8 -*-
import os
# 扫描资源引用
import re
class ImageScanner(object):
def __init__(self, path):
self.path = path
def scan_image_name(self):
# 扫描所有图片资源,遇到.imageset结尾的文件夹,则返回
files = self.__class__.__get_all_files(self.path, r'.png|.jpg|.pdf')
image_files = set()
for i in files:
match = re.search(r'[\s\S]+?.imageset/', i, re.I)
if match:
image_files.add(match.group())
else:
image_files.add(i)
return image_files
def scan_resource_in_path(self, name, percent):
files = self.__class__.__get_all_files(self.path, r'.h$|.m$|.mm$|.cpp$')
# 过滤掉.framework的文件
files = filter(lambda i: '.framework/' not in i, files)
for path in files:
f = open(path, 'r')
content = f.read()
f.close()
match = re.search(r'{0}@"{1}"'.format('[\s\S]{15}', name), content, re.I)
if match:
print match.group()
return True
match = re.search(r'{0}@"{1}\..+?"'.format('[\s\S]{15}', name), content, re.I)
if match:
print match.group()
return True
print '%2f: %s' % (percent, path)
return False
def scan_resources_in_path(self, names):
return self.scan_resources_with_pattern(names, r'.h$|.m$|.mm$|.cpp$|.xib$|.plist$')
def scan_resources_with_pattern(self, names, pattern):
files = self.__class__.__get_all_files(self.path, pattern)
return self.scan_resources_in_files(files, names)
def scan_resources_in_files(self, files, names):
# 过滤掉.framework的文件
files = filter(lambda i: '.framework/' not in i, files)
# 过滤掉第三方库的文件
files = filter(lambda i: not i.startswith('/Users/zhengxiankai/Documents/uShareit/App/code/ushareit/3rdparty/'),
files)
# 过滤Pods文件夹下的文件
files = filter(lambda i: not i.startswith('/Users/zhengxiankai/Documents/uShareit/App/code/ushareit/Pods/'),
files)
match_values = []
for index, path in enumerate(files):
f = open(path, 'r')
content = f.read()
f.close()
_, file_ext = os.path.splitext(path)
match_names = []
for i in names:
# 取出名称
_, name = os.path.split(i.rstrip('/'))
name = name.replace(".imageset", '')
# 去掉扩展名
name, ext = os.path.splitext(name)
if file_ext == '.xib':
if self.__class__.__find_resource_in_xib(content, name):
match_names.append(i)
else:
print '{0}/{1} {2} {3}'.format(index, len(files), path, name)
elif file_ext == '.plist':
if name in content:
match_names.append(i)
else:
print '{0}/{1} {2} {3}'.format(index, len(files), path, name)
else:
match = re.search(r'{0}@"{1}"'.format('', name), content, re.I)
if match:
match_values.append(match.group())
match_names.append(i)
continue
match = re.search(r'{0}@"{1}\..+?"'.format('', name), content, re.I)
if match:
match_values.append(match.group())
match_names.append(i)
continue
print '{0}/{1} {2} {3}'.format(index, len(files), path, name)
for i in match_names:
names.remove(i)
if len(names) == 0:
break
return names, match_values
def scan_file_ext_in_folder(self):
files = self.__class__.__get_all_files(self.path, r'')
exts = set()
for i in files:
_, name = os.path.split(i)
n, ext = os.path.splitext(name)
exts.add(ext)
return exts
@staticmethod
def __get_all_files(folder, file_pattern):
files = []
for res in os.walk(folder):
# (文件夹, 当前子文件夹, 当前子文件)
for f in res[2]:
if re.search(file_pattern, f, re.I):
files.append('%s/%s' % (res[0], f))
return files
@staticmethod
def __find_resource_in_xib(content, resource):
# image="ic_mp_speaker_pressed"
pattern = 'image="{0}"'.format(resource)
match = re.search(pattern, content, re.I)
return match is not None
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
1624,
13,
24,
1882,
199,
646,
747,
199,
199,
3,
8853,
232,
105,
22843,
238,
16664,
163,
119,
239,
12586,
244,
11428,
199,
646,
295,
421,
199,
533,
6047,
20843,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
339,
347,
8000,
63,
1569,
63,
354,
8,
277,
304,
267,
327,
8853,
232,
105,
22843,
238,
16570,
20916,
14339,
123,
19431,
230,
16664,
163,
119,
239,
12,
24744,
230,
29507,
14,
1569,
409,
21872,
15348,
123,
8106,
29303,
11546,
118,
12,
9051,
248,
13201,
243,
22234,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
519,
1370,
4524,
18257,
8476,
18257,
5607,
358,
267,
1834,
63,
1725,
275,
663,
342,
267,
367,
284,
315,
1584,
26,
288,
1336,
275,
295,
14,
1733,
8,
82,
22123,
83,
60,
51,
2807,
31,
14,
1569,
409,
3678,
284,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
1834,
63,
1725,
14,
525,
8,
1431,
14,
923,
1012,
288,
587,
26,
355,
1834,
63,
1725,
14,
525,
8,
73,
9,
398,
372,
1834,
63,
1725,
339,
347,
8000,
63,
1927,
63,
262,
63,
515,
8,
277,
12,
536,
12,
8878,
304,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
519,
1370,
72,
4,
18257,
77,
4,
18257,
596,
4,
18257,
5910,
9988,
398,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
14,
4857,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
1987,
4857,
4805,
440,
315,
284,
12,
1584,
9,
398,
367,
931,
315,
1584,
26,
288,
289,
275,
1551,
8,
515,
12,
283,
82,
358,
288,
1564,
275,
289,
14,
739,
342,
288,
289,
14,
1600,
342,
953,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
7063,
1370,
908,
360,
7023,
83,
60,
51,
8194,
1046,
7293,
536,
395,
1564,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
870,
1336,
14,
923,
342,
355,
372,
715,
288,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
4988,
703,
11,
13472,
1370,
908,
360,
7023,
83,
60,
51,
8194,
1046,
7293,
536,
395,
1564,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
870,
1336,
14,
923,
342,
355,
372,
715,
288,
870,
1543,
18,
70,
26,
450,
83,
7,
450,
334,
7045,
12,
931,
9,
267,
372,
756,
2378,
347,
8000,
63,
4435,
63,
262,
63,
515,
8,
277,
12,
1561,
304,
267,
372,
291,
14,
6282,
63,
4435,
63,
1045,
63,
3401,
8,
1247,
12,
519,
1370,
72,
4,
18257,
77,
4,
18257,
596,
4,
18257,
5910,
4,
18257,
88,
1892,
4,
18257,
10265,
9988,
339,
347,
8000,
63,
4435,
63,
1045,
63,
3401,
8,
277,
12,
1561,
12,
3851,
304,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
3851,
9,
267,
372,
291,
14,
6282,
63,
4435,
63,
262,
63,
1725,
8,
1725,
12,
1561,
9,
2378,
347,
8000,
63,
4435,
63,
262,
63,
1725,
8,
277,
12,
1584,
12,
1561,
304,
267,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
14,
4857,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
1987,
4857,
4805,
440,
315,
284,
12,
1584,
9,
398,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
25238,
106,
4344,
232,
24302,
15013,
242,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
440,
284,
14,
2460,
2336,
12117,
15,
3951,
7420,
6865,
3580,
5789,
15,
26872,
15,
85,
18713,
390,
15,
2640,
15,
600,
15,
2084,
1530,
390,
15,
19,
6883,
7522,
20467,
2432,
1584,
9,
398,
327,
9065,
124,
230,
163,
120,
98,
25928,
83,
29303,
11546,
118,
24233,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
440,
284,
14,
2460,
2336,
12117,
15,
3951,
7420,
6865,
3580,
5789,
15,
26872,
15,
85,
18713,
390,
15,
2640,
15,
600,
15,
2084,
1530,
390,
15,
25928,
83,
20467,
2432,
1584,
9,
398,
1336,
63,
1459,
275,
942,
398,
367,
1478,
12,
931,
315,
3874,
8,
1725,
304,
288,
289,
275,
1551,
8,
515,
12,
283,
82,
358,
288,
1564,
275,
289,
14,
739,
342,
288,
289,
14,
1600,
342,
288,
5501,
570,
63,
832,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
22919,
1336,
63,
1247,
275,
942,
288,
367,
284,
315,
1561,
26,
355,
327,
221,
22924,
22914,
21434,
19012,
109,
355,
5501,
536,
275,
747,
14,
515,
14,
1294,
8,
73,
14,
6735,
28684,
2234,
536,
275,
536,
14,
1814,
9520,
1569,
409,
401,
4074,
2234,
327,
7094,
237,
120,
17797,
232,
10862,
103,
27289,
244,
21434,
355,
536,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
354,
9,
2234,
340,
570,
63,
832,
508,
1987,
88,
1892,
356,
490,
340,
291,
855,
533,
4914,
1623,
63,
1927,
63,
262,
63,
88,
1892,
8,
1317,
12,
536,
304,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
490,
587,
26,
717,
870,
5041,
16,
16152,
17,
93,
469,
18,
93,
469,
19,
5285,
908,
8,
1080,
12,
822,
8,
1725,
395,
931,
12,
536,
9,
355,
916,
570,
63,
832,
508,
1987,
10265,
356,
490,
340,
536,
315,
1564,
26,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
490,
587,
26,
717,
870,
5041,
16,
16152,
17,
93,
469,
18,
93,
469,
19,
5285,
908,
8,
1080,
12,
822,
8,
1725,
395,
931,
12,
536,
9,
355,
587,
26,
490,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
7063,
1370,
908,
8594,
536,
395,
1564,
12,
295,
14,
41,
9,
490,
340,
1336,
26,
717,
1336,
63,
1459,
14,
740,
8,
1431,
14,
923,
1012,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
717,
1980,
4951,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
4988,
703,
11,
13472,
1370,
908,
8594,
536,
395,
1564,
12,
295,
14,
41,
9,
490,
340,
1336,
26,
717,
1336,
63,
1459,
14,
740,
8,
1431,
14,
923,
1012,
717,
1336,
63
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
1624,
13,
24,
1882,
199,
646,
747,
199,
199,
3,
8853,
232,
105,
22843,
238,
16664,
163,
119,
239,
12586,
244,
11428,
199,
646,
295,
421,
199,
533,
6047,
20843,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
515,
275,
931,
339,
347,
8000,
63,
1569,
63,
354,
8,
277,
304,
267,
327,
8853,
232,
105,
22843,
238,
16570,
20916,
14339,
123,
19431,
230,
16664,
163,
119,
239,
12,
24744,
230,
29507,
14,
1569,
409,
21872,
15348,
123,
8106,
29303,
11546,
118,
12,
9051,
248,
13201,
243,
22234,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
519,
1370,
4524,
18257,
8476,
18257,
5607,
358,
267,
1834,
63,
1725,
275,
663,
342,
267,
367,
284,
315,
1584,
26,
288,
1336,
275,
295,
14,
1733,
8,
82,
22123,
83,
60,
51,
2807,
31,
14,
1569,
409,
3678,
284,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
1834,
63,
1725,
14,
525,
8,
1431,
14,
923,
1012,
288,
587,
26,
355,
1834,
63,
1725,
14,
525,
8,
73,
9,
398,
372,
1834,
63,
1725,
339,
347,
8000,
63,
1927,
63,
262,
63,
515,
8,
277,
12,
536,
12,
8878,
304,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
519,
1370,
72,
4,
18257,
77,
4,
18257,
596,
4,
18257,
5910,
9988,
398,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
14,
4857,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
1987,
4857,
4805,
440,
315,
284,
12,
1584,
9,
398,
367,
931,
315,
1584,
26,
288,
289,
275,
1551,
8,
515,
12,
283,
82,
358,
288,
1564,
275,
289,
14,
739,
342,
288,
289,
14,
1600,
342,
953,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
7063,
1370,
908,
360,
7023,
83,
60,
51,
8194,
1046,
7293,
536,
395,
1564,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
870,
1336,
14,
923,
342,
355,
372,
715,
288,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
4988,
703,
11,
13472,
1370,
908,
360,
7023,
83,
60,
51,
8194,
1046,
7293,
536,
395,
1564,
12,
295,
14,
41,
9,
288,
340,
1336,
26,
355,
870,
1336,
14,
923,
342,
355,
372,
715,
288,
870,
1543,
18,
70,
26,
450,
83,
7,
450,
334,
7045,
12,
931,
9,
267,
372,
756,
2378,
347,
8000,
63,
4435,
63,
262,
63,
515,
8,
277,
12,
1561,
304,
267,
372,
291,
14,
6282,
63,
4435,
63,
1045,
63,
3401,
8,
1247,
12,
519,
1370,
72,
4,
18257,
77,
4,
18257,
596,
4,
18257,
5910,
4,
18257,
88,
1892,
4,
18257,
10265,
9988,
339,
347,
8000,
63,
4435,
63,
1045,
63,
3401,
8,
277,
12,
1561,
12,
3851,
304,
267,
1584,
275,
291,
855,
533,
4914,
362,
63,
452,
63,
1725,
8,
277,
14,
515,
12,
3851,
9,
267,
372,
291,
14,
6282,
63,
4435,
63,
262,
63,
1725,
8,
1725,
12,
1561,
9,
2378,
347,
8000,
63,
4435,
63,
262,
63,
1725,
8,
277,
12,
1584,
12,
1561,
304,
267,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
14,
4857,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
1987,
4857,
4805,
440,
315,
284,
12,
1584,
9,
398,
327,
9065,
124,
230,
163,
120,
98,
17797,
232,
25238,
106,
4344,
232,
24302,
15013,
242,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
440,
284,
14,
2460,
2336,
12117,
15,
3951,
7420,
6865,
3580,
5789,
15,
26872,
15,
85,
18713,
390,
15,
2640,
15,
600,
15,
2084,
1530,
390,
15,
19,
6883,
7522,
20467,
2432,
1584,
9,
398,
327,
9065,
124,
230,
163,
120,
98,
25928,
83,
29303,
11546,
118,
24233,
8106,
29303,
267,
1584,
275,
2457,
8,
2734,
284,
26,
440,
284,
14,
2460,
2336,
12117,
15,
3951,
7420,
6865,
3580,
5789,
15,
26872,
15,
85,
18713,
390,
15,
2640,
15,
600,
15,
2084,
1530,
390,
15,
25928,
83,
20467,
2432,
1584,
9,
398,
1336,
63,
1459,
275,
942,
398,
367,
1478,
12,
931,
315,
3874,
8,
1725,
304,
288,
289,
275,
1551,
8,
515,
12,
283,
82,
358,
288,
1564,
275,
289,
14,
739,
342,
288,
289,
14,
1600,
342,
288,
5501,
570,
63,
832,
275,
747,
14,
515,
14,
7973,
8,
515,
9,
22919,
1336,
63,
1247,
275,
942,
288,
367,
284,
315,
1561,
26,
355,
327,
221,
22924,
22914,
21434,
19012,
109,
355,
5501,
536,
275,
747,
14,
515,
14,
1294,
8,
73,
14,
6735,
28684,
2234,
536,
275,
536,
14,
1814,
9520,
1569,
409,
401,
4074,
2234,
327,
7094,
237,
120,
17797,
232,
10862,
103,
27289,
244,
21434,
355,
536,
12,
1599,
275,
747,
14,
515,
14,
7973,
8,
354,
9,
2234,
340,
570,
63,
832,
508,
1987,
88,
1892,
356,
490,
340,
291,
855,
533,
4914,
1623,
63,
1927,
63,
262,
63,
88,
1892,
8,
1317,
12,
536,
304,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
490,
587,
26,
717,
870,
5041,
16,
16152,
17,
93,
469,
18,
93,
469,
19,
5285,
908,
8,
1080,
12,
822,
8,
1725,
395,
931,
12,
536,
9,
355,
916,
570,
63,
832,
508,
1987,
10265,
356,
490,
340,
536,
315,
1564,
26,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
490,
587,
26,
717,
870,
5041,
16,
16152,
17,
93,
469,
18,
93,
469,
19,
5285,
908,
8,
1080,
12,
822,
8,
1725,
395,
931,
12,
536,
9,
355,
587,
26,
490,
1336,
275,
295,
14,
1733,
8,
82,
16019,
16,
93,
32,
14381,
17,
7063,
1370,
908,
8594,
536,
395,
1564,
12,
295,
14,
41,
9,
490,
340,
1336,
26,
717,
1336,
63,
1459,
14,
740,
8,
1431,
14,
923,
1012,
717,
1336,
63,
1247,
14,
740,
8,
73,
9,
717,
1980,
4951,
1336,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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
] |
mjudsp/Tsallis
|
examples/classification/plot_digits_classification.py
|
34
|
2409
|
"""
================================
Recognizing hand-written digits
================================
An example showing how the scikit-learn can be used to recognize images of
hand-written digits.
This example is commented in the
:ref:`tutorial section of the user manual <introduction>`.
"""
print(__doc__)
# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# License: BSD 3 clause
# Standard scientific Python imports
import matplotlib.pyplot as plt
# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
# The digits dataset
digits = datasets.load_digits()
# The data that we are interested in is made of 8x8 images of digits, let's
# have a look at the first 4 images, stored in the `images` attribute of the
# dataset. If we were working from image files, we could load them using
# matplotlib.pyplot.imread. Note that each image must have the same size. For these
# images, we know which digit they represent: it is given in the 'target' of
# the dataset.
images_and_labels = list(zip(digits.images, digits.target))
for index, (image, label) in enumerate(images_and_labels[:4]):
plt.subplot(2, 4, index + 1)
plt.axis('off')
plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
plt.title('Training: %i' % label)
# To apply a classifier on this data, we need to flatten the image, to
# turn the data in a (samples, feature) matrix:
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))
# Create a classifier: a support vector classifier
classifier = svm.SVC(gamma=0.001)
# We learn the digits on the first half of the digits
classifier.fit(data[:n_samples / 2], digits.target[:n_samples / 2])
# Now predict the value of the digit on the second half:
expected = digits.target[n_samples / 2:]
predicted = classifier.predict(data[n_samples / 2:])
print("Classification report for classifier %s:\n%s\n"
% (classifier, metrics.classification_report(expected, predicted)))
print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
images_and_predictions = list(zip(digits.images[n_samples / 2:], predicted))
for index, (image, prediction) in enumerate(images_and_predictions[:4]):
plt.subplot(2, 4, index + 5)
plt.axis('off')
plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
plt.title('Prediction: %i' % prediction)
plt.show()
|
bsd-3-clause
|
[
624,
199,
2486,
199,
497,
6862,
9147,
4926,
13,
8938,
7576,
199,
2486,
199,
199,
2493,
2893,
21207,
4212,
314,
6276,
6065,
13,
4643,
883,
506,
1202,
370,
27159,
5935,
402,
199,
6868,
13,
8938,
7576,
14,
199,
199,
2765,
2893,
365,
21804,
315,
314,
199,
26,
1121,
1705,
23561,
3420,
402,
314,
922,
8722,
665,
18206,
5199,
14943,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
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,
844,
26,
6289,
650,
8502,
199,
199,
3,
9739,
6276,
23509,
2018,
8925,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
3,
3161,
13148,
12,
19137,
436,
10238,
7186,
199,
504,
6357,
492,
13148,
12,
23044,
12,
7186,
199,
199,
3,
710,
7576,
4789,
199,
7022,
275,
13148,
14,
912,
63,
7022,
342,
199,
199,
3,
710,
666,
626,
781,
787,
22201,
315,
365,
6326,
402,
1695,
88,
24,
5935,
402,
7576,
12,
4691,
1159,
199,
3,
1172,
282,
3648,
737,
314,
1642,
841,
5935,
12,
5489,
315,
314,
658,
4782,
64,
2225,
402,
314,
199,
3,
4789,
14,
221,
982,
781,
4898,
6449,
687,
1834,
1584,
12,
781,
4293,
2248,
3062,
1808,
199,
3,
8027,
14,
13563,
14,
1017,
739,
14,
221,
3390,
626,
1924,
1834,
1471,
1172,
314,
2011,
1568,
14,
2104,
3520,
199,
3,
5935,
12,
781,
5715,
1314,
10964,
2985,
2954,
26,
652,
365,
1627,
315,
314,
283,
1375,
7,
402,
199,
3,
314,
4789,
14,
199,
4782,
63,
460,
63,
3512,
275,
769,
8,
3065,
8,
7022,
14,
4782,
12,
7576,
14,
1375,
430,
199,
509,
1478,
12,
334,
1569,
12,
1768,
9,
315,
3874,
8,
4782,
63,
460,
63,
3512,
1491,
20,
4682,
272,
4488,
14,
13334,
8,
18,
12,
841,
12,
1478,
435,
413,
9,
272,
4488,
14,
3127,
360,
1997,
358,
272,
4488,
14,
20413,
8,
1569,
12,
14920,
29,
6003,
14,
4400,
14,
12150,
63,
82,
12,
14046,
534,
16615,
358,
272,
4488,
14,
1213,
360,
20463,
26,
450,
73,
7,
450,
1768,
9,
199,
199,
3,
4005,
4838,
282,
12429,
641,
642,
666,
12,
781,
1929,
370,
9378,
314,
1834,
12,
370,
199,
3,
7485,
314,
666,
315,
282,
334,
3356,
12,
3878,
9,
3634,
26,
199,
78,
63,
3356,
275,
822,
8,
7022,
14,
4782,
9,
199,
576,
275,
7576,
14,
4782,
14,
5217,
1332,
78,
63,
3356,
12,
446,
17,
430,
199,
199,
3,
2790,
282,
12429,
26,
282,
2291,
5477,
12429,
199,
14720,
275,
23044,
14,
17675,
8,
7325,
29,
16,
14,
4587,
9,
199,
199,
3,
2136,
12537,
314,
7576,
641,
314,
1642,
12995,
402,
314,
7576,
199,
14720,
14,
3269,
8,
576,
1491,
78,
63,
3356,
1182,
499,
467,
7576,
14,
1375,
1491,
78,
63,
3356,
1182,
499,
566,
199,
199,
3,
7356,
12610,
314,
574,
402,
314,
10964,
641,
314,
3499,
12995,
26,
199,
2062,
275,
7576,
14,
1375,
59,
78,
63,
3356,
1182,
499,
2938,
199,
21118,
275,
12429,
14,
6892,
8,
576,
59,
78,
63,
3356,
1182,
499,
5728,
199,
199,
1361,
480,
28362,
3622,
367,
12429,
450,
83,
3427,
78,
5,
83,
60,
78,
2,
489,
450,
334,
14720,
12,
7186,
14,
14368,
63,
3070,
8,
2062,
12,
14746,
1724,
199,
1361,
480,
8930,
12444,
3634,
3427,
78,
5,
83,
2,
450,
7186,
14,
2190,
12444,
63,
3642,
8,
2062,
12,
14746,
430,
199,
199,
4782,
63,
460,
63,
9869,
275,
769,
8,
3065,
8,
7022,
14,
4782,
59,
78,
63,
3356,
1182,
499,
8429,
14746,
430,
199,
509,
1478,
12,
334,
1569,
12,
12044,
9,
315,
3874,
8,
4782,
63,
460,
63,
9869,
1491,
20,
4682,
272,
4488,
14,
13334,
8,
18,
12,
841,
12,
1478,
435,
959,
9,
272,
4488,
14,
3127,
360,
1997,
358,
272,
4488,
14,
20413,
8,
1569,
12,
14920,
29,
6003,
14,
4400,
14,
12150,
63,
82,
12,
14046,
534,
16615,
358,
272,
4488,
14,
1213,
360,
24261,
26,
450,
73,
7,
450,
12044,
9,
199,
199,
6003,
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
] |
[
199,
2486,
199,
497,
6862,
9147,
4926,
13,
8938,
7576,
199,
2486,
199,
199,
2493,
2893,
21207,
4212,
314,
6276,
6065,
13,
4643,
883,
506,
1202,
370,
27159,
5935,
402,
199,
6868,
13,
8938,
7576,
14,
199,
199,
2765,
2893,
365,
21804,
315,
314,
199,
26,
1121,
1705,
23561,
3420,
402,
314,
922,
8722,
665,
18206,
5199,
14943,
199,
199,
624,
199,
1361,
3460,
1301,
3368,
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,
844,
26,
6289,
650,
8502,
199,
199,
3,
9739,
6276,
23509,
2018,
8925,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
3,
3161,
13148,
12,
19137,
436,
10238,
7186,
199,
504,
6357,
492,
13148,
12,
23044,
12,
7186,
199,
199,
3,
710,
7576,
4789,
199,
7022,
275,
13148,
14,
912,
63,
7022,
342,
199,
199,
3,
710,
666,
626,
781,
787,
22201,
315,
365,
6326,
402,
1695,
88,
24,
5935,
402,
7576,
12,
4691,
1159,
199,
3,
1172,
282,
3648,
737,
314,
1642,
841,
5935,
12,
5489,
315,
314,
658,
4782,
64,
2225,
402,
314,
199,
3,
4789,
14,
221,
982,
781,
4898,
6449,
687,
1834,
1584,
12,
781,
4293,
2248,
3062,
1808,
199,
3,
8027,
14,
13563,
14,
1017,
739,
14,
221,
3390,
626,
1924,
1834,
1471,
1172,
314,
2011,
1568,
14,
2104,
3520,
199,
3,
5935,
12,
781,
5715,
1314,
10964,
2985,
2954,
26,
652,
365,
1627,
315,
314,
283,
1375,
7,
402,
199,
3,
314,
4789,
14,
199,
4782,
63,
460,
63,
3512,
275,
769,
8,
3065,
8,
7022,
14,
4782,
12,
7576,
14,
1375,
430,
199,
509,
1478,
12,
334,
1569,
12,
1768,
9,
315,
3874,
8,
4782,
63,
460,
63,
3512,
1491,
20,
4682,
272,
4488,
14,
13334,
8,
18,
12,
841,
12,
1478,
435,
413,
9,
272,
4488,
14,
3127,
360,
1997,
358,
272,
4488,
14,
20413,
8,
1569,
12,
14920,
29,
6003,
14,
4400,
14,
12150,
63,
82,
12,
14046,
534,
16615,
358,
272,
4488,
14,
1213,
360,
20463,
26,
450,
73,
7,
450,
1768,
9,
199,
199,
3,
4005,
4838,
282,
12429,
641,
642,
666,
12,
781,
1929,
370,
9378,
314,
1834,
12,
370,
199,
3,
7485,
314,
666,
315,
282,
334,
3356,
12,
3878,
9,
3634,
26,
199,
78,
63,
3356,
275,
822,
8,
7022,
14,
4782,
9,
199,
576,
275,
7576,
14,
4782,
14,
5217,
1332,
78,
63,
3356,
12,
446,
17,
430,
199,
199,
3,
2790,
282,
12429,
26,
282,
2291,
5477,
12429,
199,
14720,
275,
23044,
14,
17675,
8,
7325,
29,
16,
14,
4587,
9,
199,
199,
3,
2136,
12537,
314,
7576,
641,
314,
1642,
12995,
402,
314,
7576,
199,
14720,
14,
3269,
8,
576,
1491,
78,
63,
3356,
1182,
499,
467,
7576,
14,
1375,
1491,
78,
63,
3356,
1182,
499,
566,
199,
199,
3,
7356,
12610,
314,
574,
402,
314,
10964,
641,
314,
3499,
12995,
26,
199,
2062,
275,
7576,
14,
1375,
59,
78,
63,
3356,
1182,
499,
2938,
199,
21118,
275,
12429,
14,
6892,
8,
576,
59,
78,
63,
3356,
1182,
499,
5728,
199,
199,
1361,
480,
28362,
3622,
367,
12429,
450,
83,
3427,
78,
5,
83,
60,
78,
2,
489,
450,
334,
14720,
12,
7186,
14,
14368,
63,
3070,
8,
2062,
12,
14746,
1724,
199,
1361,
480,
8930,
12444,
3634,
3427,
78,
5,
83,
2,
450,
7186,
14,
2190,
12444,
63,
3642,
8,
2062,
12,
14746,
430,
199,
199,
4782,
63,
460,
63,
9869,
275,
769,
8,
3065,
8,
7022,
14,
4782,
59,
78,
63,
3356,
1182,
499,
8429,
14746,
430,
199,
509,
1478,
12,
334,
1569,
12,
12044,
9,
315,
3874,
8,
4782,
63,
460,
63,
9869,
1491,
20,
4682,
272,
4488,
14,
13334,
8,
18,
12,
841,
12,
1478,
435,
959,
9,
272,
4488,
14,
3127,
360,
1997,
358,
272,
4488,
14,
20413,
8,
1569,
12,
14920,
29,
6003,
14,
4400,
14,
12150,
63,
82,
12,
14046,
534,
16615,
358,
272,
4488,
14,
1213,
360,
24261,
26,
450,
73,
7,
450,
12044,
9,
199,
199,
6003,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
airbnb/airflow
|
tests/providers/jenkins/hooks/test_jenkins.py
|
5
|
2658
|
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import unittest
from unittest import mock
from airflow.providers.jenkins.hooks.jenkins import JenkinsHook
class TestJenkinsHook(unittest.TestCase):
@mock.patch('airflow.hooks.base.BaseHook.get_connection')
def test_client_created_default_http(self, get_connection_mock):
"""tests `init` method to validate http client creation when all parameters are passed """
default_connection_id = 'jenkins_default'
connection_host = 'http://test.com'
connection_port = 8080
get_connection_mock.return_value = mock.Mock(
connection_id=default_connection_id,
login='test',
password='test',
extra='',
host=connection_host,
port=connection_port,
)
complete_url = f'http://{connection_host}:{connection_port}/'
hook = JenkinsHook(default_connection_id)
self.assertIsNotNone(hook.jenkins_server)
self.assertEqual(hook.jenkins_server.server, complete_url)
@mock.patch('airflow.hooks.base.BaseHook.get_connection')
def test_client_created_default_https(self, get_connection_mock):
"""tests `init` method to validate https client creation when all
parameters are passed"""
default_connection_id = 'jenkins_default'
connection_host = 'http://test.com'
connection_port = 8080
get_connection_mock.return_value = mock.Mock(
connection_id=default_connection_id,
login='test',
password='test',
extra='true',
host=connection_host,
port=connection_port,
)
complete_url = f'https://{connection_host}:{connection_port}/'
hook = JenkinsHook(default_connection_id)
self.assertIsNotNone(hook.jenkins_server)
self.assertEqual(hook.jenkins_server.server, complete_url)
|
apache-2.0
|
[
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
504,
2882,
492,
1683,
199,
199,
504,
16321,
14,
9710,
14,
25622,
14,
7922,
14,
25622,
492,
32516,
8481,
421,
199,
533,
1379,
42,
14758,
8481,
8,
2796,
14,
1746,
304,
272,
768,
1805,
14,
2068,
360,
15815,
14,
7922,
14,
1095,
14,
1563,
8481,
14,
362,
63,
2105,
358,
272,
347,
511,
63,
1258,
63,
3966,
63,
885,
63,
1014,
8,
277,
12,
664,
63,
2105,
63,
1805,
304,
267,
408,
2219,
658,
826,
64,
1083,
370,
4107,
1455,
1890,
7143,
1380,
1006,
2633,
787,
3032,
408,
267,
849,
63,
2105,
63,
344,
275,
283,
25622,
63,
885,
7,
398,
1950,
63,
1102,
275,
283,
1014,
921,
396,
14,
957,
7,
267,
1950,
63,
719,
275,
30220,
267,
664,
63,
2105,
63,
1805,
14,
1107,
63,
585,
275,
1683,
14,
3346,
8,
288,
1950,
63,
344,
29,
885,
63,
2105,
63,
344,
12,
288,
4676,
534,
396,
297,
288,
2505,
534,
396,
297,
288,
2402,
4581,
288,
1591,
29,
2105,
63,
1102,
12,
288,
1844,
29,
2105,
63,
719,
12,
267,
776,
398,
4890,
63,
633,
275,
289,
7,
1014,
20193,
2105,
63,
1102,
16495,
2105,
63,
719,
93,
4805,
267,
5759,
275,
32516,
8481,
8,
885,
63,
2105,
63,
344,
9,
267,
291,
14,
10389,
8,
3664,
14,
25622,
63,
1000,
9,
267,
291,
14,
629,
8,
3664,
14,
25622,
63,
1000,
14,
1000,
12,
4890,
63,
633,
9,
339,
768,
1805,
14,
2068,
360,
15815,
14,
7922,
14,
1095,
14,
1563,
8481,
14,
362,
63,
2105,
358,
272,
347,
511,
63,
1258,
63,
3966,
63,
885,
63,
2859,
8,
277,
12,
664,
63,
2105,
63,
1805,
304,
267,
408,
2219,
658,
826,
64,
1083,
370,
4107,
4178,
1890,
7143,
1380,
1006,
267,
2633,
787,
3032,
624,
267,
849,
63,
2105,
63,
344,
275,
283,
25622,
63,
885,
7,
398,
1950,
63,
1102,
275,
283,
1014,
921,
396,
14,
957,
7,
267,
1950,
63,
719,
275,
30220,
267,
664,
63,
2105,
63,
1805,
14,
1107,
63,
585,
275,
1683,
14,
3346,
8,
288,
1950,
63,
344,
29,
885,
63,
2105,
63,
344,
12,
288,
4676,
534,
396,
297,
288,
2505,
534,
396,
297,
288,
2402,
534,
2052,
297,
288,
1591,
29,
2105,
63,
1102,
12,
288,
1844,
29,
2105,
63,
719,
12,
267,
776,
398,
4890,
63,
633,
275,
289,
7,
2859,
20193,
2105,
63,
1102,
16495,
2105,
63,
719,
93,
4805,
267,
5759,
275,
32516,
8481,
8,
885,
63,
2105,
63,
344,
9,
267,
291,
14,
10389,
8,
3664,
14,
25622,
63,
1000,
9,
267,
291,
14,
629,
8,
3664,
14,
25622,
63,
1000,
14,
1000,
12,
4890,
63,
633,
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
] |
[
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
504,
2882,
492,
1683,
199,
199,
504,
16321,
14,
9710,
14,
25622,
14,
7922,
14,
25622,
492,
32516,
8481,
421,
199,
533,
1379,
42,
14758,
8481,
8,
2796,
14,
1746,
304,
272,
768,
1805,
14,
2068,
360,
15815,
14,
7922,
14,
1095,
14,
1563,
8481,
14,
362,
63,
2105,
358,
272,
347,
511,
63,
1258,
63,
3966,
63,
885,
63,
1014,
8,
277,
12,
664,
63,
2105,
63,
1805,
304,
267,
408,
2219,
658,
826,
64,
1083,
370,
4107,
1455,
1890,
7143,
1380,
1006,
2633,
787,
3032,
408,
267,
849,
63,
2105,
63,
344,
275,
283,
25622,
63,
885,
7,
398,
1950,
63,
1102,
275,
283,
1014,
921,
396,
14,
957,
7,
267,
1950,
63,
719,
275,
30220,
267,
664,
63,
2105,
63,
1805,
14,
1107,
63,
585,
275,
1683,
14,
3346,
8,
288,
1950,
63,
344,
29,
885,
63,
2105,
63,
344,
12,
288,
4676,
534,
396,
297,
288,
2505,
534,
396,
297,
288,
2402,
4581,
288,
1591,
29,
2105,
63,
1102,
12,
288,
1844,
29,
2105,
63,
719,
12,
267,
776,
398,
4890,
63,
633,
275,
289,
7,
1014,
20193,
2105,
63,
1102,
16495,
2105,
63,
719,
93,
4805,
267,
5759,
275,
32516,
8481,
8,
885,
63,
2105,
63,
344,
9,
267,
291,
14,
10389,
8,
3664,
14,
25622,
63,
1000,
9,
267,
291,
14,
629,
8,
3664,
14,
25622,
63,
1000,
14,
1000,
12,
4890,
63,
633,
9,
339,
768,
1805,
14,
2068,
360,
15815,
14,
7922,
14,
1095,
14,
1563,
8481,
14,
362,
63,
2105,
358,
272,
347,
511,
63,
1258,
63,
3966,
63,
885,
63,
2859,
8,
277,
12,
664,
63,
2105,
63,
1805,
304,
267,
408,
2219,
658,
826,
64,
1083,
370,
4107,
4178,
1890,
7143,
1380,
1006,
267,
2633,
787,
3032,
624,
267,
849,
63,
2105,
63,
344,
275,
283,
25622,
63,
885,
7,
398,
1950,
63,
1102,
275,
283,
1014,
921,
396,
14,
957,
7,
267,
1950,
63,
719,
275,
30220,
267,
664,
63,
2105,
63,
1805,
14,
1107,
63,
585,
275,
1683,
14,
3346,
8,
288,
1950,
63,
344,
29,
885,
63,
2105,
63,
344,
12,
288,
4676,
534,
396,
297,
288,
2505,
534,
396,
297,
288,
2402,
534,
2052,
297,
288,
1591,
29,
2105,
63,
1102,
12,
288,
1844,
29,
2105,
63,
719,
12,
267,
776,
398,
4890,
63,
633,
275,
289,
7,
2859,
20193,
2105,
63,
1102,
16495,
2105,
63,
719,
93,
4805,
267,
5759,
275,
32516,
8481,
8,
885,
63,
2105,
63,
344,
9,
267,
291,
14,
10389,
8,
3664,
14,
25622,
63,
1000,
9,
267,
291,
14,
629,
8,
3664,
14,
25622,
63,
1000,
14,
1000,
12,
4890,
63,
633,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
costingalan/ltp
|
testcases/network/nfsv4/acl/test_acl.py
|
27
|
3315
|
'''
Access Control Lists testing based on newpynfs framework
Aurelien Charbon - Bull SA
'''
from random_gen import *
import commands
import os
import threading
import time
import random
alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~'
t_alphabet=len(alphabet)
def test_acl_default(path):
# set default acl on the test directory
u = commands.getoutput('mkdir ' + path + "/" + testdir)
u = commands.getoutput('getfacl ' + path + "/" + testdir)
acl=[]
for i in range (len(splitedresult)-1)
splitedline = splitedresult[i].split('::')
name = splitedline[0]
entry = splitedline[1]
acl.append(name,entry)
# create a file in this directory
u = commands.getoutput('touch ' + path + "/" + testdir + testfile)
# get the file's ACL and verify
u = commands.getoutput('getfacl ' + path + "/" + testdir + testfile)
splitedresult = u.split('\n')
acl2=[]
for i in range (len(splitedresult)-1):
splitedline = splitedresult[i].split('::')
name = splitedline[0]
entry = splitedline[1]
acl2.append(name,entry)
result_final = True
while i < len(acl2):
result = False:
while j < len(acl2) and result = False:
if acl2[i] == acl[j]:
result = True
if result == False:
result_final = False
''' Measuring time to add an ACE to a list regarding the number of ACE already in the list'''
''' Doing the measurement on 100 files '''
def test_acl_long():
path = '/mnt/nfs/test-acl'
test = RandomGen()
test.createFile(path,100)
test.getUserList()
t0=time.time()
for test_file in test.fList:
for user in test.uList:
mode = test.createRandomMode()
u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + test_file)
t1=time.time()
print t1-t0
def test_nfs_acl():
print "test acl 10000\n"
test = RandomGen()
f = open('/tmp/acl-result-10000','w')
path = '/mnt/nfs/test-acl'
for i in range(10000):
print "test avec " + str(i) + " ACE"
test.getUserList()
testfile = 'testfile' + str(i)
u = commands.getoutput('touch ' + path + "/" + testfile)
t0=time.time()
for j in range(i):
user = test.uList.pop()
mode = test.createRandomMode()
u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile)
t1=time.time()
f.write(str(i) + "\t" + str(t1-t0)+"\n")
f.close()
def test_nfs_getfacl():
# mesures sur le getfacl
test = RandomGen()
path = '/mnt/nfs/test-acl' # NFS mounted directory
u = commands.getoutput('rm ' + path + "/*") # clean directory
print "test acl getfacl\n"
f = open('/tmp/acl-result-getfacl','w')
for i in range(37):
test.getUserList()
testfile = 'testfile' + str(i)
u = commands.getoutput('touch ' + path + "/" + testfile)
print "setfacl " + str(i) + " " + u
for j in range(i):
user = test.uList.pop()
mode = test.createRandomMode()
u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile)
t1=time.time()
u = commands.getoutput('getfacl ' + path + "/" + testfile)
print "getfacl - " + str(i) + u + "\n"
t2=time.time()
f.write(str(i) + "\t" + str(t2-t1)+"\n")
f.close()
def main():
# test getFileList
path = '/mnt/nfs/test-acl'
test = RandomGen()
test.getFileList(path)
print test.fList
main()
|
gpl-2.0
|
[
2344,
199,
198,
3946,
8612,
31289,
5343,
4079,
641,
892,
647,
19591,
10059,
199,
198,
33,
608,
317,
287,
6659,
13520,
446,
699,
979,
13950,
199,
2344,
199,
504,
2196,
63,
2268,
492,
627,
199,
646,
3718,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
31884,
534,
23459,
28114,
11272,
32069,
342,
6146,
7,
199,
84,
63,
31884,
29,
552,
8,
31884,
9,
199,
199,
318,
511,
63,
5853,
63,
885,
8,
515,
304,
199,
199,
3,
663,
849,
15316,
641,
314,
511,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
8215,
283,
435,
931,
435,
10609,
435,
7368,
9,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
362,
667,
429,
283,
435,
931,
435,
10609,
435,
7368,
9,
199,
198,
5853,
9811,
199,
198,
509,
284,
315,
1425,
334,
552,
8,
681,
317,
471,
1099,
7216,
17,
9,
507,
198,
681,
317,
471,
604,
275,
2249,
317,
471,
1099,
59,
73,
1055,
1294,
6176,
10993,
507,
198,
354,
275,
2249,
317,
471,
604,
59,
16,
61,
507,
198,
2373,
275,
2249,
317,
471,
604,
59,
17,
61,
507,
198,
5853,
14,
740,
8,
354,
12,
2373,
9,
199,
3,
1218,
282,
570,
315,
642,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
7368,
435,
30530,
9,
199,
3,
664,
314,
570,
1159,
16543,
436,
4911,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
362,
667,
429,
283,
435,
931,
435,
10609,
435,
7368,
435,
30530,
9,
199,
198,
681,
317,
471,
1099,
275,
399,
14,
1294,
2258,
78,
358,
199,
198,
5853,
18,
9811,
199,
198,
509,
284,
315,
1425,
334,
552,
8,
681,
317,
471,
1099,
7216,
17,
304,
507,
198,
681,
317,
471,
604,
275,
2249,
317,
471,
1099,
59,
73,
1055,
1294,
6176,
10993,
507,
198,
354,
275,
2249,
317,
471,
604,
59,
16,
61,
507,
198,
2373,
275,
2249,
317,
471,
604,
59,
17,
61,
507,
198,
5853,
18,
14,
740,
8,
354,
12,
2373,
9,
421,
198,
1099,
63,
5094,
275,
715,
199,
198,
6710,
284,
665,
822,
8,
5853,
18,
304,
507,
198,
1099,
275,
756,
26,
507,
198,
6710,
1335,
665,
822,
8,
5853,
18,
9,
436,
754,
275,
756,
26,
686,
198,
692,
15316,
18,
59,
73,
61,
508,
15316,
59,
74,
2189,
686,
198,
1099,
275,
715,
507,
198,
692,
754,
508,
756,
26,
686,
198,
1099,
63,
5094,
275,
756,
199,
199,
2344,
3194,
305,
4039,
900,
370,
1050,
376,
437,
2089,
370,
282,
769,
12602,
314,
1329,
402,
437,
2089,
2575,
315,
314,
769,
2344,
199,
2344,
4226,
316,
314,
18216,
641,
2948,
1584,
1449,
199,
318,
511,
63,
5853,
63,
2809,
837,
199,
198,
515,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
199,
198,
396,
275,
9571,
8168,
342,
199,
198,
396,
14,
981,
1173,
8,
515,
12,
1960,
9,
199,
198,
396,
14,
32627,
1296,
342,
199,
198,
84,
16,
29,
521,
14,
521,
342,
199,
198,
509,
511,
63,
493,
315,
511,
14,
70,
1296,
26,
507,
198,
509,
922,
315,
511,
14,
85,
1296,
26,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
686,
198,
85,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
511,
63,
493,
9,
199,
198,
84,
17,
29,
521,
14,
521,
342,
199,
198,
1361,
307,
17,
13,
84,
16,
199,
199,
318,
511,
63,
19591,
63,
5853,
837,
199,
198,
1361,
298,
396,
15316,
11630,
60,
78,
2,
199,
198,
396,
275,
9571,
8168,
342,
199,
198,
70,
275,
1551,
2336,
2791,
15,
5853,
13,
1099,
13,
9943,
1673,
87,
358,
398,
931,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
199,
198,
509,
284,
315,
1425,
8,
9943,
304,
507,
198,
1361,
298,
396,
282,
6046,
298,
435,
620,
8,
73,
9,
435,
298,
437,
2089,
2,
507,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
507,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
84,
16,
29,
521,
14,
521,
342,
355,
367,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
84,
17,
29,
521,
14,
521,
342,
355,
289,
14,
952,
8,
495,
8,
73,
9,
435,
1867,
84,
2,
435,
620,
8,
84,
17,
13,
84,
16,
6393,
3212,
78,
531,
267,
289,
14,
1600,
342,
421,
199,
318,
511,
63,
19591,
63,
362,
667,
429,
837,
199,
198,
3,
26560,
1482,
6296,
1026,
664,
667,
429,
199,
198,
396,
275,
9571,
8168,
342,
421,
198,
515,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
327,
653,
7079,
27979,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
5682,
283,
435,
931,
435,
3286,
10,
531,
198,
3,
3633,
2082,
199,
198,
1361,
298,
396,
15316,
664,
667,
429,
60,
78,
2,
199,
198,
70,
275,
1551,
2336,
2791,
15,
5853,
13,
1099,
13,
362,
667,
429,
1673,
87,
358,
199,
198,
509,
284,
315,
1425,
8,
1401,
304,
2742,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
2742,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
1361,
298,
409,
667,
429,
298,
435,
620,
8,
73,
9,
435,
298,
298,
435,
399,
507,
198,
509,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298
] |
[
199,
198,
3946,
8612,
31289,
5343,
4079,
641,
892,
647,
19591,
10059,
199,
198,
33,
608,
317,
287,
6659,
13520,
446,
699,
979,
13950,
199,
2344,
199,
504,
2196,
63,
2268,
492,
627,
199,
646,
3718,
199,
646,
747,
199,
646,
5796,
199,
646,
900,
199,
646,
2196,
199,
199,
31884,
534,
23459,
28114,
11272,
32069,
342,
6146,
7,
199,
84,
63,
31884,
29,
552,
8,
31884,
9,
199,
199,
318,
511,
63,
5853,
63,
885,
8,
515,
304,
199,
199,
3,
663,
849,
15316,
641,
314,
511,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
8215,
283,
435,
931,
435,
10609,
435,
7368,
9,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
362,
667,
429,
283,
435,
931,
435,
10609,
435,
7368,
9,
199,
198,
5853,
9811,
199,
198,
509,
284,
315,
1425,
334,
552,
8,
681,
317,
471,
1099,
7216,
17,
9,
507,
198,
681,
317,
471,
604,
275,
2249,
317,
471,
1099,
59,
73,
1055,
1294,
6176,
10993,
507,
198,
354,
275,
2249,
317,
471,
604,
59,
16,
61,
507,
198,
2373,
275,
2249,
317,
471,
604,
59,
17,
61,
507,
198,
5853,
14,
740,
8,
354,
12,
2373,
9,
199,
3,
1218,
282,
570,
315,
642,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
7368,
435,
30530,
9,
199,
3,
664,
314,
570,
1159,
16543,
436,
4911,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
362,
667,
429,
283,
435,
931,
435,
10609,
435,
7368,
435,
30530,
9,
199,
198,
681,
317,
471,
1099,
275,
399,
14,
1294,
2258,
78,
358,
199,
198,
5853,
18,
9811,
199,
198,
509,
284,
315,
1425,
334,
552,
8,
681,
317,
471,
1099,
7216,
17,
304,
507,
198,
681,
317,
471,
604,
275,
2249,
317,
471,
1099,
59,
73,
1055,
1294,
6176,
10993,
507,
198,
354,
275,
2249,
317,
471,
604,
59,
16,
61,
507,
198,
2373,
275,
2249,
317,
471,
604,
59,
17,
61,
507,
198,
5853,
18,
14,
740,
8,
354,
12,
2373,
9,
421,
198,
1099,
63,
5094,
275,
715,
199,
198,
6710,
284,
665,
822,
8,
5853,
18,
304,
507,
198,
1099,
275,
756,
26,
507,
198,
6710,
1335,
665,
822,
8,
5853,
18,
9,
436,
754,
275,
756,
26,
686,
198,
692,
15316,
18,
59,
73,
61,
508,
15316,
59,
74,
2189,
686,
198,
1099,
275,
715,
507,
198,
692,
754,
508,
756,
26,
686,
198,
1099,
63,
5094,
275,
756,
199,
199,
2344,
3194,
305,
4039,
900,
370,
1050,
376,
437,
2089,
370,
282,
769,
12602,
314,
1329,
402,
437,
2089,
2575,
315,
314,
769,
2344,
199,
2344,
4226,
316,
314,
18216,
641,
2948,
1584,
1449,
199,
318,
511,
63,
5853,
63,
2809,
837,
199,
198,
515,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
199,
198,
396,
275,
9571,
8168,
342,
199,
198,
396,
14,
981,
1173,
8,
515,
12,
1960,
9,
199,
198,
396,
14,
32627,
1296,
342,
199,
198,
84,
16,
29,
521,
14,
521,
342,
199,
198,
509,
511,
63,
493,
315,
511,
14,
70,
1296,
26,
507,
198,
509,
922,
315,
511,
14,
85,
1296,
26,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
686,
198,
85,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
511,
63,
493,
9,
199,
198,
84,
17,
29,
521,
14,
521,
342,
199,
198,
1361,
307,
17,
13,
84,
16,
199,
199,
318,
511,
63,
19591,
63,
5853,
837,
199,
198,
1361,
298,
396,
15316,
11630,
60,
78,
2,
199,
198,
396,
275,
9571,
8168,
342,
199,
198,
70,
275,
1551,
2336,
2791,
15,
5853,
13,
1099,
13,
9943,
1673,
87,
358,
398,
931,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
199,
198,
509,
284,
315,
1425,
8,
9943,
304,
507,
198,
1361,
298,
396,
282,
6046,
298,
435,
620,
8,
73,
9,
435,
298,
437,
2089,
2,
507,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
507,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
84,
16,
29,
521,
14,
521,
342,
355,
367,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
298,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
84,
17,
29,
521,
14,
521,
342,
355,
289,
14,
952,
8,
495,
8,
73,
9,
435,
1867,
84,
2,
435,
620,
8,
84,
17,
13,
84,
16,
6393,
3212,
78,
531,
267,
289,
14,
1600,
342,
421,
199,
318,
511,
63,
19591,
63,
362,
667,
429,
837,
199,
198,
3,
26560,
1482,
6296,
1026,
664,
667,
429,
199,
198,
396,
275,
9571,
8168,
342,
421,
198,
515,
275,
1994,
20481,
15,
19591,
15,
396,
13,
5853,
7,
327,
653,
7079,
27979,
2082,
199,
198,
85,
275,
3718,
14,
362,
1199,
360,
5682,
283,
435,
931,
435,
3286,
10,
531,
198,
3,
3633,
2082,
199,
198,
1361,
298,
396,
15316,
664,
667,
429,
60,
78,
2,
199,
198,
70,
275,
1551,
2336,
2791,
15,
5853,
13,
1099,
13,
362,
667,
429,
1673,
87,
358,
199,
198,
509,
284,
315,
1425,
8,
1401,
304,
2742,
198,
396,
14,
32627,
1296,
342,
507,
198,
21091,
275,
283,
21091,
7,
435,
620,
8,
73,
9,
2742,
198,
85,
275,
3718,
14,
362,
1199,
360,
12376,
283,
435,
931,
435,
10609,
435,
30530,
9,
507,
198,
1361,
298,
409,
667,
429,
298,
435,
620,
8,
73,
9,
435,
298,
298,
435,
399,
507,
198,
509,
1335,
315,
1425,
8,
73,
304,
686,
198,
751,
275,
511,
14,
85,
1296,
14,
1935,
342,
686,
198,
632,
275,
511,
14,
981,
3883,
1385,
342,
717,
399,
275,
3718,
14,
362,
1199,
360,
409,
667,
429,
446,
77,
399,
4881,
435,
922,
435,
10871,
435,
818,
435,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
seanli9jan/tensorflow
|
tensorflow/python/tools/freeze_graph_test.py
|
9
|
13561
|
# Copyright 2015 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 the graph freezing tool."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import re
from tensorflow.core.example import example_pb2
from tensorflow.core.framework import graph_pb2
from tensorflow.core.protobuf import saver_pb2
from tensorflow.python.client import session
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import graph_io
from tensorflow.python.framework import importer
from tensorflow.python.framework import ops
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import nn
from tensorflow.python.ops import parsing_ops
from tensorflow.python.ops import partitioned_variables
from tensorflow.python.ops import variable_scope
from tensorflow.python.ops import variables
from tensorflow.python.platform import test
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import signature_constants
from tensorflow.python.saved_model import signature_def_utils
from tensorflow.python.saved_model import tag_constants
from tensorflow.python.tools import freeze_graph
from tensorflow.python.training import saver as saver_lib
class FreezeGraphTest(test_util.TensorFlowTestCase):
def _testFreezeGraph(self, saver_write_version):
checkpoint_prefix = os.path.join(self.get_temp_dir(), "saved_checkpoint")
checkpoint_meta_graph_file = os.path.join(self.get_temp_dir(),
"saved_checkpoint.meta")
checkpoint_state_name = "checkpoint_state"
input_graph_name = "input_graph.pb"
output_graph_name = "output_graph.pb"
# We'll create an input graph that has a single variable containing 1.0,
# and that then multiplies it by 2.
with ops.Graph().as_default():
variable_node = variables.VariableV1(1.0, name="variable_node")
output_node = math_ops.multiply(variable_node, 2.0, name="output_node")
sess = session.Session()
init = variables.global_variables_initializer()
sess.run(init)
output = sess.run(output_node)
self.assertNear(2.0, output, 0.00001)
saver = saver_lib.Saver(write_version=saver_write_version)
checkpoint_path = saver.save(
sess,
checkpoint_prefix,
global_step=0,
latest_filename=checkpoint_state_name)
graph_io.write_graph(sess.graph, self.get_temp_dir(), input_graph_name)
# We save out the graph to disk, and then call the const conversion
# routine.
input_graph_path = os.path.join(self.get_temp_dir(), input_graph_name)
input_saver_def_path = ""
input_binary = False
output_node_names = "output_node"
restore_op_name = "save/restore_all"
filename_tensor_name = "save/Const:0"
output_graph_path = os.path.join(self.get_temp_dir(), output_graph_name)
clear_devices = False
input_meta_graph = checkpoint_meta_graph_file
freeze_graph.freeze_graph(
input_graph_path,
input_saver_def_path,
input_binary,
checkpoint_path,
output_node_names,
restore_op_name,
filename_tensor_name,
output_graph_path,
clear_devices,
"",
"",
input_meta_graph,
checkpoint_version=saver_write_version)
# Now we make sure the variable is now a constant, and that the graph still
# produces the expected result.
with ops.Graph().as_default():
output_graph_def = graph_pb2.GraphDef()
with open(output_graph_path, "rb") as f:
output_graph_def.ParseFromString(f.read())
_ = importer.import_graph_def(output_graph_def, name="")
self.assertEqual(4, len(output_graph_def.node))
for node in output_graph_def.node:
self.assertNotEqual("VariableV2", node.op)
self.assertNotEqual("Variable", node.op)
with session.Session() as sess:
output_node = sess.graph.get_tensor_by_name("output_node:0")
output = sess.run(output_node)
self.assertNear(2.0, output, 0.00001)
def _createTFExampleString(self, feature_name, feature_value):
"""Create a serialized tensorflow example."""
example = example_pb2.Example()
example.features.feature[feature_name].float_list.value.extend([
feature_value])
return example.SerializeToString()
def _writeDummySavedModel(self, path, feature_name):
"""Writes a classifier with two input features to the given path."""
with ops.Graph().as_default():
examples = array_ops.placeholder(dtypes.string, name="input_node")
feature_configs = {
feature_name: parsing_ops.FixedLenFeature(shape=[],
dtype=dtypes.float32),
}
features = parsing_ops.parse_example(examples, feature_configs)
feature = features[feature_name]
variable_node = variables.VariableV1(1.0, name="variable_node")
scores = math_ops.multiply(variable_node, feature, name="output_node")
class_feature = array_ops.fill(array_ops.shape(feature),
"class_%s" % feature_name)
classes = array_ops.transpose(class_feature)
with session.Session() as sess:
sess.run(variables.global_variables_initializer())
signature = (
signature_def_utils.classification_signature_def(
examples=examples,
classes=classes,
scores=scores,))
builder = saved_model_builder.SavedModelBuilder(path)
builder.add_meta_graph_and_variables(
sess,
[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature,
},)
builder.save(as_text=True)
def testFreezeGraphV1(self):
self._testFreezeGraph(saver_pb2.SaverDef.V1)
def testFreezeGraphV2(self):
self._testFreezeGraph(saver_pb2.SaverDef.V2)
def testFreezeMetaGraph(self):
tmp_dir = self.get_temp_dir()
checkpoint_prefix = os.path.join(tmp_dir, "meta_graph_checkpoint")
checkpoint_state_name = "checkpoint_state"
output_graph_filename = os.path.join(tmp_dir, "output_graph.pb")
with ops.Graph().as_default():
variable_node = variables.VariableV1(1.0, name="variable_node")
output_node = math_ops.multiply(variable_node, 2.0, name="output_node")
sess = session.Session()
init = variables.global_variables_initializer()
sess.run(init)
output = sess.run(output_node)
self.assertNear(2.0, output, 0.00001)
saver = saver_lib.Saver()
checkpoint_path = saver.save(
sess,
checkpoint_prefix,
global_step=0,
latest_filename=checkpoint_state_name)
input_saver_def_path = ""
input_binary = True
output_node_names = "output_node"
restore_op_name = "save/restore_all"
filename_tensor_name = "save/Const:0"
clear_devices = False
input_meta_graph = checkpoint_path + ".meta"
freeze_graph.freeze_graph(
"", input_saver_def_path, input_binary, checkpoint_path,
output_node_names, restore_op_name, filename_tensor_name,
output_graph_filename, clear_devices, "", "", "", input_meta_graph)
# Now we make sure the variable is now a constant, and that the graph still
# produces the expected result.
with ops.Graph().as_default():
output_graph_def = graph_pb2.GraphDef()
with open(output_graph_filename, "rb") as f:
output_graph_def.ParseFromString(f.read())
_ = importer.import_graph_def(output_graph_def, name="")
self.assertEqual(4, len(output_graph_def.node))
for node in output_graph_def.node:
self.assertNotEqual("VariableV2", node.op)
self.assertNotEqual("Variable", node.op)
with session.Session() as sess:
output_node = sess.graph.get_tensor_by_name("output_node:0")
output = sess.run(output_node)
self.assertNear(2.0, output, 0.00001)
def testFreezeSavedModel(self):
tmp_dir = self.get_temp_dir()
saved_model_dir = os.path.join(tmp_dir, "saved_model_dir")
feature_name = "feature"
self._writeDummySavedModel(saved_model_dir, feature_name)
output_graph_filename = os.path.join(tmp_dir, "output_graph.pb")
input_saved_model_dir = saved_model_dir
output_node_names = "output_node"
input_binary = False
input_saver_def_path = False
restore_op_name = None
filename_tensor_name = None
clear_devices = False
input_meta_graph = False
checkpoint_path = None
input_graph_filename = None
saved_model_tags = tag_constants.SERVING
freeze_graph.freeze_graph(input_graph_filename, input_saver_def_path,
input_binary, checkpoint_path, output_node_names,
restore_op_name, filename_tensor_name,
output_graph_filename, clear_devices, "", "", "",
input_meta_graph, input_saved_model_dir,
saved_model_tags)
# Now we make sure the variable is now a constant, and that the graph still
# produces the expected result.
with ops.Graph().as_default():
output_graph_def = graph_pb2.GraphDef()
with open(output_graph_filename, "rb") as f:
output_graph_def.ParseFromString(f.read())
_ = importer.import_graph_def(output_graph_def, name="")
self.assertEqual(8, len(output_graph_def.node))
for node in output_graph_def.node:
self.assertNotEqual("VariableV2", node.op)
self.assertNotEqual("Variable", node.op)
feature_value = 2.0
example = self._createTFExampleString(feature_name, feature_value)
with session.Session() as sess:
input_node = sess.graph.get_tensor_by_name("input_node:0")
output_node = sess.graph.get_tensor_by_name("output_node:0")
output = sess.run(output_node, feed_dict={input_node: [example]})
self.assertNear(feature_value, output, 0.00001)
def testSinglePartitionedVariable(self):
"""Ensures partitioned variables fail cleanly with freeze graph."""
checkpoint_prefix = os.path.join(self.get_temp_dir(), "saved_checkpoint")
checkpoint_state_name = "checkpoint_state"
input_graph_name = "input_graph.pb"
output_graph_name = "output_graph.pb"
# Create a graph with partition variables. When weights are partitioned into
# a single partition, the weights variable is followed by a identity ->
# identity (an additional identity node).
partitioner = partitioned_variables.fixed_size_partitioner(1)
with ops.Graph().as_default():
with variable_scope.variable_scope("part", partitioner=partitioner):
batch_size, height, width, depth = 5, 128, 128, 3
input1 = array_ops.zeros(
(batch_size, height, width, depth), name="input1")
input2 = array_ops.zeros(
(batch_size, height, width, depth), name="input2")
num_nodes = depth
filter1 = variable_scope.get_variable("filter", [num_nodes, num_nodes])
filter2 = array_ops.reshape(filter1, [1, 1, num_nodes, num_nodes])
conv = nn.conv2d(
input=input1, filter=filter2, strides=[1, 1, 1, 1], padding="SAME")
node = math_ops.add(conv, input2, name="test/add")
node = nn.relu6(node, name="test/relu6")
# Save graph and checkpoints.
sess = session.Session()
sess.run(variables.global_variables_initializer())
saver = saver_lib.Saver()
checkpoint_path = saver.save(
sess,
checkpoint_prefix,
global_step=0,
latest_filename=checkpoint_state_name)
graph_io.write_graph(sess.graph, self.get_temp_dir(), input_graph_name)
# Ensure this graph has partition variables.
self.assertTrue([
tensor.name.split(":")[0]
for op in sess.graph.get_operations()
for tensor in op.values()
if re.search(r"/part_\d+/", tensor.name)
])
# Test freezing graph doesn't make it crash.
output_node_names = "save/restore_all"
output_graph_path = os.path.join(self.get_temp_dir(), output_graph_name)
return_value = freeze_graph.freeze_graph_with_def_protos(
input_graph_def=sess.graph_def,
input_saver_def=None,
input_checkpoint=checkpoint_path,
output_node_names=output_node_names,
restore_op_name="save/restore_all", # default value
filename_tensor_name="save/Const:0", # default value
output_graph=output_graph_path,
clear_devices=False,
initializer_nodes="")
self.assertTrue(return_value, -1)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
6900,
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,
314,
3343,
2867,
20135,
4744,
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,
747,
199,
646,
295,
199,
199,
504,
3228,
14,
1018,
14,
2694,
492,
2893,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
4857,
492,
3343,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
17559,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3343,
63,
2308,
199,
504,
3228,
14,
1548,
14,
4857,
492,
13479,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
27105,
63,
3669,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
6545,
465,
6290,
63,
1238,
63,
5649,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
4955,
63,
5559,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
4955,
63,
318,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
1947,
63,
5559,
199,
504,
3228,
14,
1548,
14,
2537,
492,
22778,
63,
2180,
199,
504,
3228,
14,
1548,
14,
7588,
492,
17559,
465,
17559,
63,
773,
421,
199,
533,
2868,
806,
4578,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
485,
396,
10146,
806,
4578,
8,
277,
12,
17559,
63,
952,
63,
1023,
304,
339,
9997,
63,
1861,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
8420,
63,
10109,
531,
272,
9997,
63,
2024,
63,
2180,
63,
493,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
6343,
298,
8420,
63,
10109,
14,
2024,
531,
272,
9997,
63,
929,
63,
354,
275,
298,
10109,
63,
929,
2,
272,
1324,
63,
2180,
63,
354,
275,
298,
1210,
63,
2180,
14,
3317,
2,
272,
1072,
63,
2180,
63,
354,
275,
298,
1199,
63,
2180,
14,
3317,
2,
339,
327,
2136,
7171,
1218,
376,
1324,
3343,
626,
965,
282,
2849,
1750,
3035,
413,
14,
16,
12,
272,
327,
436,
626,
2066,
8897,
6528,
652,
701,
499,
14,
272,
543,
4156,
14,
4578,
1252,
305,
63,
885,
837,
489,
1750,
63,
932,
275,
2860,
14,
2773,
54,
17,
8,
17,
14,
16,
12,
536,
628,
1975,
63,
932,
531,
489,
1072,
63,
932,
275,
3473,
63,
1483,
14,
13710,
8,
1975,
63,
932,
12,
499,
14,
16,
12,
536,
628,
1199,
63,
932,
531,
489,
4043,
275,
2351,
14,
4434,
342,
489,
4205,
275,
2860,
14,
2966,
63,
3669,
63,
6498,
342,
489,
4043,
14,
1065,
8,
826,
9,
489,
1072,
275,
4043,
14,
1065,
8,
1199,
63,
932,
9,
489,
291,
14,
479,
46,
2210,
8,
18,
14,
16,
12,
1072,
12,
378,
14,
22417,
9,
489,
17559,
275,
17559,
63,
773,
14,
20829,
8,
952,
63,
1023,
29,
21166,
63,
952,
63,
1023,
9,
489,
9997,
63,
515,
275,
17559,
14,
2117,
8,
881,
4043,
12,
881,
9997,
63,
1861,
12,
881,
2288,
63,
2926,
29,
16,
12,
881,
8839,
63,
1501,
29,
10109,
63,
929,
63,
354,
9,
489,
3343,
63,
2308,
14,
952,
63,
2180,
8,
5480,
14,
2180,
12,
291,
14,
362,
63,
808,
63,
694,
1062,
1324,
63,
2180,
63,
354,
9,
339,
327,
2136,
3354,
734,
314,
3343,
370,
4543,
12,
436,
2066,
1240,
314,
950,
8603,
272,
327,
12981,
14,
272,
1324,
63,
2180,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
1324,
63,
2180,
63,
354,
9,
272,
1324,
63,
21166,
63,
318,
63,
515,
275,
3087,
272,
1324,
63,
3008,
275,
756,
272,
1072,
63,
932,
63,
1247,
275,
298,
1199,
63,
932,
2,
272,
9066,
63,
411,
63,
354,
275,
298,
2117,
15,
8011,
63,
452,
2,
272,
1788,
63,
3128,
63,
354,
275,
298,
2117,
15,
6361,
26,
16,
2,
272,
1072,
63,
2180,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
1072,
63,
2180,
63,
354,
9,
272,
5436,
63,
6410,
275,
756,
272,
1324,
63,
2024,
63,
2180,
275,
9997,
63,
2024,
63,
2180,
63,
493,
339,
22778,
63,
2180,
14,
18459,
63,
2180,
8,
267,
1324,
63,
2180,
63,
515,
12,
267,
1324,
63,
21166,
63,
318,
63,
515,
12,
267,
1324,
63,
3008,
12,
267,
9997,
63,
515,
12,
267,
1072,
63,
932,
63,
1247,
12,
267,
9066,
63,
411,
63,
354,
12,
267,
1788,
63,
3128,
63,
354,
12,
267,
1072,
63,
2180,
63,
515,
12,
267,
5436,
63,
6410,
12,
267,
4873,
267,
4873,
267,
1324,
63,
2024,
63,
2180,
12,
267,
9997,
63,
1023
] |
[
1898,
6900,
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,
314,
3343,
2867,
20135,
4744,
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,
747,
199,
646,
295,
199,
199,
504,
3228,
14,
1018,
14,
2694,
492,
2893,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
4857,
492,
3343,
63,
3317,
18,
199,
504,
3228,
14,
1018,
14,
7204,
492,
17559,
63,
3317,
18,
199,
504,
3228,
14,
1548,
14,
1258,
492,
2351,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3343,
63,
2308,
199,
504,
3228,
14,
1548,
14,
4857,
492,
13479,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4156,
199,
504,
3228,
14,
1548,
14,
4857,
492,
511,
63,
1974,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
11542,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6057,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
27105,
63,
3669,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1750,
63,
2645,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2860,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
6545,
465,
6290,
63,
1238,
63,
5649,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
4955,
63,
5559,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
4955,
63,
318,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
492,
1947,
63,
5559,
199,
504,
3228,
14,
1548,
14,
2537,
492,
22778,
63,
2180,
199,
504,
3228,
14,
1548,
14,
7588,
492,
17559,
465,
17559,
63,
773,
421,
199,
533,
2868,
806,
4578,
774,
8,
396,
63,
1974,
14,
26998,
1746,
304,
819,
347,
485,
396,
10146,
806,
4578,
8,
277,
12,
17559,
63,
952,
63,
1023,
304,
339,
9997,
63,
1861,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
8420,
63,
10109,
531,
272,
9997,
63,
2024,
63,
2180,
63,
493,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
6343,
298,
8420,
63,
10109,
14,
2024,
531,
272,
9997,
63,
929,
63,
354,
275,
298,
10109,
63,
929,
2,
272,
1324,
63,
2180,
63,
354,
275,
298,
1210,
63,
2180,
14,
3317,
2,
272,
1072,
63,
2180,
63,
354,
275,
298,
1199,
63,
2180,
14,
3317,
2,
339,
327,
2136,
7171,
1218,
376,
1324,
3343,
626,
965,
282,
2849,
1750,
3035,
413,
14,
16,
12,
272,
327,
436,
626,
2066,
8897,
6528,
652,
701,
499,
14,
272,
543,
4156,
14,
4578,
1252,
305,
63,
885,
837,
489,
1750,
63,
932,
275,
2860,
14,
2773,
54,
17,
8,
17,
14,
16,
12,
536,
628,
1975,
63,
932,
531,
489,
1072,
63,
932,
275,
3473,
63,
1483,
14,
13710,
8,
1975,
63,
932,
12,
499,
14,
16,
12,
536,
628,
1199,
63,
932,
531,
489,
4043,
275,
2351,
14,
4434,
342,
489,
4205,
275,
2860,
14,
2966,
63,
3669,
63,
6498,
342,
489,
4043,
14,
1065,
8,
826,
9,
489,
1072,
275,
4043,
14,
1065,
8,
1199,
63,
932,
9,
489,
291,
14,
479,
46,
2210,
8,
18,
14,
16,
12,
1072,
12,
378,
14,
22417,
9,
489,
17559,
275,
17559,
63,
773,
14,
20829,
8,
952,
63,
1023,
29,
21166,
63,
952,
63,
1023,
9,
489,
9997,
63,
515,
275,
17559,
14,
2117,
8,
881,
4043,
12,
881,
9997,
63,
1861,
12,
881,
2288,
63,
2926,
29,
16,
12,
881,
8839,
63,
1501,
29,
10109,
63,
929,
63,
354,
9,
489,
3343,
63,
2308,
14,
952,
63,
2180,
8,
5480,
14,
2180,
12,
291,
14,
362,
63,
808,
63,
694,
1062,
1324,
63,
2180,
63,
354,
9,
339,
327,
2136,
3354,
734,
314,
3343,
370,
4543,
12,
436,
2066,
1240,
314,
950,
8603,
272,
327,
12981,
14,
272,
1324,
63,
2180,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
1324,
63,
2180,
63,
354,
9,
272,
1324,
63,
21166,
63,
318,
63,
515,
275,
3087,
272,
1324,
63,
3008,
275,
756,
272,
1072,
63,
932,
63,
1247,
275,
298,
1199,
63,
932,
2,
272,
9066,
63,
411,
63,
354,
275,
298,
2117,
15,
8011,
63,
452,
2,
272,
1788,
63,
3128,
63,
354,
275,
298,
2117,
15,
6361,
26,
16,
2,
272,
1072,
63,
2180,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
1072,
63,
2180,
63,
354,
9,
272,
5436,
63,
6410,
275,
756,
272,
1324,
63,
2024,
63,
2180,
275,
9997,
63,
2024,
63,
2180,
63,
493,
339,
22778,
63,
2180,
14,
18459,
63,
2180,
8,
267,
1324,
63,
2180,
63,
515,
12,
267,
1324,
63,
21166,
63,
318,
63,
515,
12,
267,
1324,
63,
3008,
12,
267,
9997,
63,
515,
12,
267,
1072,
63,
932,
63,
1247,
12,
267,
9066,
63,
411,
63,
354,
12,
267,
1788,
63,
3128,
63,
354,
12,
267,
1072,
63,
2180,
63,
515,
12,
267,
5436,
63,
6410,
12,
267,
4873,
267,
4873,
267,
1324,
63,
2024,
63,
2180,
12,
267,
9997,
63,
1023,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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"""
import sys
import re
import logging
import json
import time
import subprocess
METRICS = [
'Total Services',
'Services Checked',
'Services Scheduled',
'Services Actively Checked',
'Services Passively Checked',
'Services Flapping',
'Services In Downtime',
'Total Hosts',
'Hosts Checked',
'Hosts Scheduled',
'Hosts Actively Checked',
'Host Passively Checked',
'Hosts Flapping',
'Hosts In Downtime'
]
METRICS_3AVG = [
'Passive Host Checks Last 1/5/15 min',
'Passive Service Checks Last 1/5/15 min',
'External Commands Last 1/5/15 min'
]
METRICS_3AVGf = [
'Total Service State Change',
'Active Service Latency',
'Active Service Execution Time',
'Active Service State Change',
'Passive Service Latency',
'Passive Service State Change',
'Total Host State Change',
'Active Host Latency',
'Active Host Execution Time',
'Active Host State Change',
'Passive Host Latency',
'Passive Host State Change'
]
METRICS_4AVG = [
'Active Services Last 1/5/15/60 min',
'Passive Services Last 1/5/15/60 min',
'Active Hosts Last 1/5/15/60 min',
'Passive Hosts Last 1/5/15/60 min'
]
class Nagios:
def __init__(self, agent_config, checks_logger, raw_config):
self.agent_config = agent_config
self.checks_logger = checks_logger
self.raw_config = raw_config
self.datastore = {}
self.cmd_path = self.raw_config['Nagios'].get('cmd_path', '/usr/local/nagios/bin/nagiostats')
def run(self):
data = ''
stats = {}
try:
data = subprocess.check_output([self.cmd_path])
except Exception as e:
self.checks_logger.error('Failed to run %s: %s' % (self.cmd_path, e))
sys.exit(1)
for metric in METRICS:
stats[metric] = int(re.search("{0}:\s+(\d+)".format(metric), data).group(1))
for metric in METRICS_3AVG:
m = re.search("{0}:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)".format(metric), data)
metric_name = re.match(r"(.*) Last 1/5/15 min", metric).group(1)
stats[metric_name] = int(m.group(1))
for metric in METRICS_3AVGf:
m = re.search("{0}:\s+(\d+\.\d+)\s+/\s+(\d+\.\d+)\s+/\s+(\d+\.\d+)".format(metric), data)
stats[metric] = float(m.group(1))
for metric in METRICS_4AVG:
m = re.search("{0}:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)".format(metric), data)
metric_name = re.match(r"(.*) Last 1/5/15/60 min", metric).group(1)
stats[metric_name] = int(m.group(1))
m = re.search("Services Ok/Warn/Unk/Crit:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)".format(metric), data)
stats['Services Status Ok'] = int(m.group(1))
stats['Services Status Warn'] = int(m.group(2))
stats['Services Status Unknown'] = int(m.group(3))
stats['Services Status Critical'] = int(m.group(4))
m = re.search("Hosts Up/Down/Unreach:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)".format(metric), data)
stats['Hosts Status Up'] = int(m.group(1))
stats['Hosts Status Down'] = int(m.group(2))
stats['Hosts Status Unreachable'] = int(m.group(3))
m = re.search("Active Host Checks Last 1/5/15 min:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Scheduled:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"On-demand:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Parallel:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Serial:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Cached:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+", data)
stats['Active Host Checks Total'] = int(m.group(1))
stats['Active Host Checks Scheduled'] = int(m.group(4))
stats['Active Host Checks On-demand'] = int(m.group(7))
stats['Active Host Checks Parallel'] = int(m.group(10))
stats['Active Host Checks Serial'] = int(m.group(13))
stats['Active Host Checks Cached'] = int(m.group(16))
m = re.search("Active Service Checks Last 1/5/15 min:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Scheduled:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"On-demand:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+"
"Cached:\s+(\d+)\s+/\s+(\d+)\s+/\s+(\d+)\s+", data)
stats['Active Service Checks Total'] = int(m.group(1))
stats['Active Service Checks Scheduled'] = int(m.group(4))
stats['Active Service Checks On-demand'] = int(m.group(7))
stats['Active Service Checks Cached'] = int(m.group(10))
m = re.search("Program Running Time:\s+(\d+)d\s+(\d+)h\s+(\d+)m\s+(\d+)s".format(metric), data)
stats['Uptime'] = int(m.group(4)) + int(m.group(3))*60 + int(m.group(3))*3600 + int(m.group(4))*86400
return stats
if __name__ == '__main__':
"""
Standalone test configuration
"""
raw_agent_config = {
'Nagios': {
'cmd_path': '/usr/local/nagios/bin/nagiostats',
}
}
main_checks_logger = logging.getLogger('Nagios')
main_checks_logger.setLevel(logging.DEBUG)
main_checks_logger.addHandler(logging.StreamHandler(sys.stdout))
host_check = Nagios({}, main_checks_logger, raw_agent_config)
while True:
try:
print json.dumps(host_check.run(), indent=4, sort_keys=True)
except:
main_checks_logger.exception("Unhandled exception")
finally:
time.sleep(60)
|
bsd-3-clause
|
[
624,
199,
3120,
25187,
3677,
653,
18560,
3589,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
646,
2050,
199,
646,
2022,
199,
646,
900,
199,
646,
3873,
199,
199,
30476,
275,
359,
272,
283,
7316,
21813,
297,
272,
283,
15803,
2670,
379,
297,
272,
283,
15803,
24317,
68,
297,
272,
283,
15803,
4473,
9462,
2670,
379,
297,
272,
283,
15803,
510,
2608,
5636,
2670,
379,
297,
272,
283,
15803,
481,
18352,
297,
272,
283,
15803,
1010,
13392,
521,
297,
272,
283,
7316,
10891,
83,
297,
272,
283,
19620,
2670,
379,
297,
272,
283,
19620,
24317,
68,
297,
272,
283,
19620,
4473,
9462,
2670,
379,
297,
272,
283,
4965,
510,
2608,
5636,
2670,
379,
297,
272,
283,
19620,
481,
18352,
297,
272,
283,
19620,
1010,
13392,
521,
7,
199,
61,
199,
199,
30476,
63,
19,
6087,
39,
275,
359,
272,
283,
48,
13202,
10891,
13813,
15237,
413,
15,
21,
15,
1046,
1748,
297,
272,
283,
48,
13202,
7591,
13813,
15237,
413,
15,
21,
15,
1046,
1748,
297,
272,
283,
11389,
5817,
83,
15237,
413,
15,
21,
15,
1046,
1748,
7,
199,
61,
199,
199,
30476,
63,
19,
6087,
39,
70,
275,
359,
272,
283,
7316,
7591,
8511,
7743,
297,
272,
283,
7472,
7591,
491,
323,
12501,
297,
272,
283,
7472,
7591,
28573,
4703,
297,
272,
283,
7472,
7591,
8511,
7743,
297,
272,
283,
48,
13202,
7591,
491,
323,
12501,
297,
272,
283,
48,
13202,
7591,
8511,
7743,
297,
272,
283,
7316,
10891,
8511,
7743,
297,
272,
283,
7472,
10891,
491,
323,
12501,
297,
272,
283,
7472,
10891,
28573,
4703,
297,
272,
283,
7472,
10891,
8511,
7743,
297,
272,
283,
48,
13202,
10891,
491,
323,
12501,
297,
272,
283,
48,
13202,
10891,
8511,
7743,
7,
199,
61,
199,
199,
30476,
63,
20,
6087,
39,
275,
359,
272,
283,
7472,
21813,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
48,
13202,
21813,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
7472,
10891,
83,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
48,
13202,
10891,
83,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
7,
199,
61,
199,
199,
533,
653,
18560,
26,
339,
347,
636,
826,
721,
277,
12,
6631,
63,
888,
12,
5920,
63,
2921,
12,
3066,
63,
888,
304,
267,
291,
14,
4054,
63,
888,
275,
6631,
63,
888,
267,
291,
14,
8625,
63,
2921,
275,
5920,
63,
2921,
267,
291,
14,
1773,
63,
888,
275,
3066,
63,
888,
267,
291,
14,
11450,
275,
1052,
398,
291,
14,
1760,
63,
515,
275,
291,
14,
1773,
63,
888,
459,
46,
18560,
2278,
362,
360,
1760,
63,
515,
297,
1994,
2647,
15,
1832,
15,
28084,
15,
1393,
15,
78,
643,
73,
941,
1956,
358,
339,
347,
1255,
8,
277,
304,
267,
666,
275,
2125,
267,
5020,
275,
1052,
398,
862,
26,
6722,
666,
275,
3873,
14,
1074,
63,
1199,
779,
277,
14,
1760,
63,
515,
566,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
8625,
63,
2921,
14,
705,
360,
4276,
370,
1255,
450,
83,
26,
450,
83,
7,
450,
334,
277,
14,
1760,
63,
515,
12,
325,
430,
288,
984,
14,
2224,
8,
17,
9,
398,
367,
6370,
315,
19357,
14673,
51,
26,
288,
5020,
59,
5165,
61,
275,
1109,
8,
264,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
680,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
19,
6087,
39,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
6370,
63,
354,
275,
295,
14,
1431,
8,
82,
26507,
12432,
15237,
413,
15,
21,
15,
1046,
1748,
401,
6370,
680,
923,
8,
17,
9,
288,
5020,
59,
5165,
63,
354,
61,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
19,
6087,
39,
70,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
23294,
68,
13439,
83,
11,
6307,
83,
20900,
68,
23294,
68,
13439,
83,
11,
6307,
83,
20900,
68,
23294,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
5020,
59,
5165,
61,
275,
2069,
8,
77,
14,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
20,
6087,
39,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
6370,
63,
354,
275,
295,
14,
1431,
8,
82,
26507,
12432,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
401,
6370,
680,
923,
8,
17,
9,
288,
5020,
59,
5165,
63,
354,
61,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
398,
333,
275,
295,
14,
1733,
480,
15803,
20049,
15,
22673,
15,
1358,
75,
15,
35,
11133,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
267,
5020,
459,
15803,
9795,
20049,
418,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
267,
5020,
459,
15803,
9795,
644,
1060,
418,
275,
1109,
8,
77,
14,
923,
8,
18,
430,
267,
5020,
459,
15803,
9795,
14831,
418,
275,
1109,
8,
77,
14,
923,
8,
19,
430,
267,
5020,
459,
15803,
9795,
445,
13919,
418,
275,
1109,
8,
77,
14,
923,
8,
20,
430,
398,
333,
275,
295,
14,
1733,
480,
19620,
4949,
15,
3514,
15,
1358,
12784,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
267,
5020,
459,
19620,
9795,
4949,
418,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
267,
5020,
459,
19620,
9795,
13392,
418,
275,
1109,
8,
77,
14,
923,
8,
18,
430,
267,
5020,
459,
19620,
9795,
1910,
15837,
418,
275,
1109,
8,
77,
14,
923
] |
[
199,
3120,
25187,
3677,
653,
18560,
3589,
199,
624,
199,
199,
646,
984,
199,
646,
295,
199,
646,
2050,
199,
646,
2022,
199,
646,
900,
199,
646,
3873,
199,
199,
30476,
275,
359,
272,
283,
7316,
21813,
297,
272,
283,
15803,
2670,
379,
297,
272,
283,
15803,
24317,
68,
297,
272,
283,
15803,
4473,
9462,
2670,
379,
297,
272,
283,
15803,
510,
2608,
5636,
2670,
379,
297,
272,
283,
15803,
481,
18352,
297,
272,
283,
15803,
1010,
13392,
521,
297,
272,
283,
7316,
10891,
83,
297,
272,
283,
19620,
2670,
379,
297,
272,
283,
19620,
24317,
68,
297,
272,
283,
19620,
4473,
9462,
2670,
379,
297,
272,
283,
4965,
510,
2608,
5636,
2670,
379,
297,
272,
283,
19620,
481,
18352,
297,
272,
283,
19620,
1010,
13392,
521,
7,
199,
61,
199,
199,
30476,
63,
19,
6087,
39,
275,
359,
272,
283,
48,
13202,
10891,
13813,
15237,
413,
15,
21,
15,
1046,
1748,
297,
272,
283,
48,
13202,
7591,
13813,
15237,
413,
15,
21,
15,
1046,
1748,
297,
272,
283,
11389,
5817,
83,
15237,
413,
15,
21,
15,
1046,
1748,
7,
199,
61,
199,
199,
30476,
63,
19,
6087,
39,
70,
275,
359,
272,
283,
7316,
7591,
8511,
7743,
297,
272,
283,
7472,
7591,
491,
323,
12501,
297,
272,
283,
7472,
7591,
28573,
4703,
297,
272,
283,
7472,
7591,
8511,
7743,
297,
272,
283,
48,
13202,
7591,
491,
323,
12501,
297,
272,
283,
48,
13202,
7591,
8511,
7743,
297,
272,
283,
7316,
10891,
8511,
7743,
297,
272,
283,
7472,
10891,
491,
323,
12501,
297,
272,
283,
7472,
10891,
28573,
4703,
297,
272,
283,
7472,
10891,
8511,
7743,
297,
272,
283,
48,
13202,
10891,
491,
323,
12501,
297,
272,
283,
48,
13202,
10891,
8511,
7743,
7,
199,
61,
199,
199,
30476,
63,
20,
6087,
39,
275,
359,
272,
283,
7472,
21813,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
48,
13202,
21813,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
7472,
10891,
83,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
297,
272,
283,
48,
13202,
10891,
83,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
7,
199,
61,
199,
199,
533,
653,
18560,
26,
339,
347,
636,
826,
721,
277,
12,
6631,
63,
888,
12,
5920,
63,
2921,
12,
3066,
63,
888,
304,
267,
291,
14,
4054,
63,
888,
275,
6631,
63,
888,
267,
291,
14,
8625,
63,
2921,
275,
5920,
63,
2921,
267,
291,
14,
1773,
63,
888,
275,
3066,
63,
888,
267,
291,
14,
11450,
275,
1052,
398,
291,
14,
1760,
63,
515,
275,
291,
14,
1773,
63,
888,
459,
46,
18560,
2278,
362,
360,
1760,
63,
515,
297,
1994,
2647,
15,
1832,
15,
28084,
15,
1393,
15,
78,
643,
73,
941,
1956,
358,
339,
347,
1255,
8,
277,
304,
267,
666,
275,
2125,
267,
5020,
275,
1052,
398,
862,
26,
6722,
666,
275,
3873,
14,
1074,
63,
1199,
779,
277,
14,
1760,
63,
515,
566,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
8625,
63,
2921,
14,
705,
360,
4276,
370,
1255,
450,
83,
26,
450,
83,
7,
450,
334,
277,
14,
1760,
63,
515,
12,
325,
430,
288,
984,
14,
2224,
8,
17,
9,
398,
367,
6370,
315,
19357,
14673,
51,
26,
288,
5020,
59,
5165,
61,
275,
1109,
8,
264,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
680,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
19,
6087,
39,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
6370,
63,
354,
275,
295,
14,
1431,
8,
82,
26507,
12432,
15237,
413,
15,
21,
15,
1046,
1748,
401,
6370,
680,
923,
8,
17,
9,
288,
5020,
59,
5165,
63,
354,
61,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
19,
6087,
39,
70,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
23294,
68,
13439,
83,
11,
6307,
83,
20900,
68,
23294,
68,
13439,
83,
11,
6307,
83,
20900,
68,
23294,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
5020,
59,
5165,
61,
275,
2069,
8,
77,
14,
923,
8,
17,
430,
398,
367,
6370,
315,
19357,
14673,
51,
63,
20,
6087,
39,
26,
288,
333,
275,
295,
14,
1733,
13076,
16,
93,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
288,
6370,
63,
354,
275,
295,
14,
1431,
8,
82,
26507,
12432,
15237,
413,
15,
21,
15,
1046,
15,
2259,
1748,
401,
6370,
680,
923,
8,
17,
9,
288,
5020,
59,
5165,
63,
354,
61,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
398,
333,
275,
295,
14,
1733,
480,
15803,
20049,
15,
22673,
15,
1358,
75,
15,
35,
11133,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
267,
5020,
459,
15803,
9795,
20049,
418,
275,
1109,
8,
77,
14,
923,
8,
17,
430,
267,
5020,
459,
15803,
9795,
644,
1060,
418,
275,
1109,
8,
77,
14,
923,
8,
18,
430,
267,
5020,
459,
15803,
9795,
14831,
418,
275,
1109,
8,
77,
14,
923,
8,
19,
430,
267,
5020,
459,
15803,
9795,
445,
13919,
418,
275,
1109,
8,
77,
14,
923,
8,
20,
430,
398,
333,
275,
295,
14,
1733,
480,
19620,
4949,
15,
3514,
15,
1358,
12784,
3427,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
13439,
83,
11,
6307,
83,
20900,
68,
8771,
1674,
908,
8,
5165,
395,
666,
9,
267,
5020,
459,
19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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
] |
rexshihaoren/scikit-learn
|
examples/linear_model/plot_sgd_penalties.py
|
249
|
1563
|
"""
==============
SGD: Penalties
==============
Plot the contours of the three penalties.
All of the above are supported by
:class:`sklearn.linear_model.stochastic_gradient`.
"""
from __future__ import division
print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
def l1(xs):
return np.array([np.sqrt((1 - np.sqrt(x ** 2.0)) ** 2.0) for x in xs])
def l2(xs):
return np.array([np.sqrt(1.0 - x ** 2.0) for x in xs])
def el(xs, z):
return np.array([(2 - 2 * x - 2 * z + 4 * x * z -
(4 * z ** 2
- 8 * x * z ** 2
+ 8 * x ** 2 * z ** 2
- 16 * x ** 2 * z ** 3
+ 8 * x * z ** 3 + 4 * x ** 2 * z ** 4) ** (1. / 2)
- 2 * x * z ** 2) / (2 - 4 * z) for x in xs])
def cross(ext):
plt.plot([-ext, ext], [0, 0], "k-")
plt.plot([0, 0], [-ext, ext], "k-")
xs = np.linspace(0, 1, 100)
alpha = 0.501 # 0.5 division throuh zero
cross(1.2)
plt.plot(xs, l1(xs), "r-", label="L1")
plt.plot(xs, -1.0 * l1(xs), "r-")
plt.plot(-1 * xs, l1(xs), "r-")
plt.plot(-1 * xs, -1.0 * l1(xs), "r-")
plt.plot(xs, l2(xs), "b-", label="L2")
plt.plot(xs, -1.0 * l2(xs), "b-")
plt.plot(-1 * xs, l2(xs), "b-")
plt.plot(-1 * xs, -1.0 * l2(xs), "b-")
plt.plot(xs, el(xs, alpha), "y-", label="Elastic Net")
plt.plot(xs, -1.0 * el(xs, alpha), "y-")
plt.plot(-1 * xs, el(xs, alpha), "y-")
plt.plot(-1 * xs, -1.0 * el(xs, alpha), "y-")
plt.xlabel(r"$w_0$")
plt.ylabel(r"$w_1$")
plt.legend()
plt.axis("equal")
plt.show()
|
bsd-3-clause
|
[
624,
199,
17224,
199,
4254,
36,
26,
510,
287,
279,
1417,
199,
17224,
199,
199,
10711,
314,
23176,
83,
402,
314,
7795,
12374,
279,
1417,
14,
199,
199,
2422,
402,
314,
3432,
787,
3748,
701,
199,
26,
533,
1705,
27993,
14,
6676,
63,
1238,
14,
14308,
21913,
63,
7490,
2313,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
318,
634,
17,
8,
7977,
304,
272,
372,
980,
14,
1144,
779,
1590,
14,
5079,
1332,
17,
446,
980,
14,
5079,
8,
88,
1011,
499,
14,
16,
430,
1011,
499,
14,
16,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
634,
18,
8,
7977,
304,
272,
372,
980,
14,
1144,
779,
1590,
14,
5079,
8,
17,
14,
16,
446,
671,
1011,
499,
14,
16,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
579,
8,
7977,
12,
1315,
304,
272,
372,
980,
14,
1144,
7694,
18,
446,
499,
627,
671,
446,
499,
627,
1315,
435,
841,
627,
671,
627,
1315,
446,
1993,
334,
20,
627,
1315,
1011,
499,
2432,
446,
1695,
627,
671,
627,
1315,
1011,
499,
2432,
435,
1695,
627,
671,
1011,
499,
627,
1315,
1011,
499,
2432,
446,
3193,
627,
671,
1011,
499,
627,
1315,
1011,
650,
2432,
435,
1695,
627,
671,
627,
1315,
1011,
650,
435,
841,
627,
671,
1011,
499,
627,
1315,
1011,
841,
9,
1011,
334,
17,
14,
1182,
499,
9,
1993,
446,
499,
627,
671,
627,
1315,
1011,
499,
9,
1182,
334,
18,
446,
841,
627,
1315,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
8059,
8,
832,
304,
272,
4488,
14,
2798,
11468,
832,
12,
1599,
467,
359,
16,
12,
378,
467,
298,
75,
13,
531,
272,
4488,
14,
2798,
779,
16,
12,
378,
467,
5243,
832,
12,
1599,
467,
298,
75,
13,
531,
199,
199,
7977,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
2948,
9,
199,
199,
4468,
275,
378,
14,
8216,
221,
327,
378,
14,
21,
4629,
294,
7930,
72,
4697,
199,
199,
7925,
8,
17,
14,
18,
9,
199,
199,
6003,
14,
2798,
8,
7977,
12,
634,
17,
8,
7977,
395,
298,
82,
13,
401,
1768,
628,
44,
17,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
199,
6003,
14,
2798,
8,
7977,
12,
634,
18,
8,
7977,
395,
298,
66,
13,
401,
1768,
628,
44,
18,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
199,
6003,
14,
2798,
8,
7977,
12,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
401,
1768,
628,
27822,
5365,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
199,
6003,
14,
14168,
8,
82,
2,
4,
87,
63,
16,
22550,
199,
6003,
14,
13849,
8,
82,
2,
4,
87,
63,
17,
22550,
199,
6003,
14,
10231,
342,
199,
199,
6003,
14,
3127,
480,
1452,
531,
199,
6003,
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
] |
[
199,
17224,
199,
4254,
36,
26,
510,
287,
279,
1417,
199,
17224,
199,
199,
10711,
314,
23176,
83,
402,
314,
7795,
12374,
279,
1417,
14,
199,
199,
2422,
402,
314,
3432,
787,
3748,
701,
199,
26,
533,
1705,
27993,
14,
6676,
63,
1238,
14,
14308,
21913,
63,
7490,
2313,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
199,
1361,
3460,
1301,
3368,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
318,
634,
17,
8,
7977,
304,
272,
372,
980,
14,
1144,
779,
1590,
14,
5079,
1332,
17,
446,
980,
14,
5079,
8,
88,
1011,
499,
14,
16,
430,
1011,
499,
14,
16,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
634,
18,
8,
7977,
304,
272,
372,
980,
14,
1144,
779,
1590,
14,
5079,
8,
17,
14,
16,
446,
671,
1011,
499,
14,
16,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
579,
8,
7977,
12,
1315,
304,
272,
372,
980,
14,
1144,
7694,
18,
446,
499,
627,
671,
446,
499,
627,
1315,
435,
841,
627,
671,
627,
1315,
446,
1993,
334,
20,
627,
1315,
1011,
499,
2432,
446,
1695,
627,
671,
627,
1315,
1011,
499,
2432,
435,
1695,
627,
671,
1011,
499,
627,
1315,
1011,
499,
2432,
446,
3193,
627,
671,
1011,
499,
627,
1315,
1011,
650,
2432,
435,
1695,
627,
671,
627,
1315,
1011,
650,
435,
841,
627,
671,
1011,
499,
627,
1315,
1011,
841,
9,
1011,
334,
17,
14,
1182,
499,
9,
1993,
446,
499,
627,
671,
627,
1315,
1011,
499,
9,
1182,
334,
18,
446,
841,
627,
1315,
9,
367,
671,
315,
12965,
566,
421,
199,
318,
8059,
8,
832,
304,
272,
4488,
14,
2798,
11468,
832,
12,
1599,
467,
359,
16,
12,
378,
467,
298,
75,
13,
531,
272,
4488,
14,
2798,
779,
16,
12,
378,
467,
5243,
832,
12,
1599,
467,
298,
75,
13,
531,
199,
199,
7977,
275,
980,
14,
11649,
8,
16,
12,
413,
12,
2948,
9,
199,
199,
4468,
275,
378,
14,
8216,
221,
327,
378,
14,
21,
4629,
294,
7930,
72,
4697,
199,
199,
7925,
8,
17,
14,
18,
9,
199,
199,
6003,
14,
2798,
8,
7977,
12,
634,
17,
8,
7977,
395,
298,
82,
13,
401,
1768,
628,
44,
17,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
634,
17,
8,
7977,
395,
298,
82,
13,
531,
199,
199,
6003,
14,
2798,
8,
7977,
12,
634,
18,
8,
7977,
395,
298,
66,
13,
401,
1768,
628,
44,
18,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
634,
18,
8,
7977,
395,
298,
66,
13,
531,
199,
199,
6003,
14,
2798,
8,
7977,
12,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
401,
1768,
628,
27822,
5365,
531,
199,
6003,
14,
2798,
8,
7977,
12,
446,
17,
14,
16,
627,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
6003,
14,
2798,
2801,
17,
627,
12965,
12,
446,
17,
14,
16,
627,
579,
8,
7977,
12,
5131,
395,
298,
89,
13,
531,
199,
199,
6003,
14,
14168,
8,
82,
2,
4,
87,
63,
16,
22550,
199,
6003,
14,
13849,
8,
82,
2,
4,
87,
63,
17,
22550,
199,
6003,
14,
10231,
342,
199,
199,
6003,
14,
3127,
480,
1452,
531,
199,
6003,
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,
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
] |
bcroq/kansha
|
kansha/validator.py
|
2
|
4635
|
# -*- coding:utf-8 -*-
#--
# Copyright (c) 2012-2014 Net-ng.
# All rights reserved.
#
# This software is licensed under the BSD License, as described in
# the file LICENSE.txt, which you should have received as part of
# this distribution.
#--
import re
import string
import ntpath
from lxml import html
from nagare import i18n
from nagare import validator
from nagare.i18n import _, _L
from lxml.html.clean import Cleaner
# mail regex extracted from http://www.regular-expressions.info/email.html
MAIL_RE = r"(?i)^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"
def clean_text(text):
text = text.replace(u'<br>', u'<br>\n')
text = text.replace(u'</p>', u'</p>\n')
text = text.replace(u'</li>', u'</li>\n')
return unicode(html.fromstring(text).text_content())
def clean_html(text):
cleaner = Cleaner(style=False)
return cleaner.clean_html(text)
class BoolValidator(validator.Validator):
"""Conversion and validation of integers
"""
def __init__(self, value, strip=True, *args, **kw):
"""Initialisation
Check that the value is a bool
In:
- ``v`` -- value to validate
"""
try:
if isinstance(value, basestring):
value = value.strip()
if value.lower() in ('yes', 'on', 'true', '1'):
self.value = True
elif value.lower() in ('no', 'off', 'false', '0'):
self.value = False
else:
self.value = False
else:
self.value = bool(value)
except (ValueError, TypeError):
raise ValueError(i18n._(u'Must be a boolean'))
to_bool = validator.Validator.__call__
def validate_identifier(value, start_with_uppercase_letter=False, max_len=256):
"""Validate an identifier: only letters, digits or underscore characters are accepted"""
if not value:
raise ValueError(_("Should not be empty"))
safe_chars = set("_%s%s" % (string.ascii_letters, string.digits))
ok = all(c in safe_chars for c in value)
if not ok:
raise ValueError(_('Should only contain ascii letters, digits or underscore characters'))
if start_with_uppercase_letter:
if value[0] not in string.ascii_uppercase:
raise ValueError(_("Should start with an uppercase ascii letter"))
else:
if value[0] not in string.ascii_letters:
raise ValueError(_("Should start with an ascii letter"))
if len(value) > max_len:
raise ValueError(
_("Identifier too long (max. %d characters)") % max_len)
return value
def validate_file(data, max_size=None, msg=_('Size must be less than %d KB')):
"""Validate a 'file' input data against the max size in KB"""
# check against the first roundtrip with the client
if data is None or isinstance(data, basestring):
return None
if data.done == -1:
raise ValueError(_('Transfer was interrupted'))
# gets the file size (it's a StringIO)
data.file.seek(0, 2) # 0 from EOF
filesize = data.file.tell()
data.file.seek(0)
if max_size is not None and filesize > max_size * 1024:
raise ValueError(msg % max_size)
filedata = data.file.read()
data.file.seek(0)
# some browsers (i.e. Internet Explorer) send the full path of the file
# instead of the filename
# so, we remove the path from the filename
filename = ntpath.basename(unicode(data.filename))
return {'filename': filename,
'data': filedata,
'content_type': unicode(data.type)}
def validate_non_empty_string(value, msg=_L("Required field")):
"""Check that the value is a non-empty string"""
# strip whitespace characters
return validator.StringValidator(value, strip=True).not_empty(_(msg)).to_string()
def validate_email(value, required_msg=_L("Required field"), invalid_msg=_L("Invalid email address")):
"""Check that the value is a valid email address"""
if not value:
raise ValueError(_(required_msg))
# convert to lowercase
value = value.lower()
if len(value) > 7:
if re.match(MAIL_RE, value):
return value
raise ValueError(_(invalid_msg))
def validate_password(value):
value = validate_non_empty_string(value)
# check password complexity
min_len = 6
if len(value) < min_len:
raise ValueError(_("Password too short: should have at least %d characters")
% min_len)
return value
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
1624,
13,
24,
1882,
199,
3,
306,
199,
3,
1898,
334,
67,
9,
6029,
13,
7280,
5365,
13,
2753,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
18233,
1334,
314,
6289,
844,
12,
465,
11736,
315,
199,
3,
314,
570,
5113,
14,
2424,
12,
1314,
1265,
1077,
1172,
3086,
465,
1777,
402,
199,
3,
642,
4084,
14,
199,
3,
306,
199,
199,
646,
295,
199,
646,
1059,
199,
646,
13377,
515,
199,
199,
504,
14490,
492,
3517,
199,
504,
302,
643,
1530,
492,
284,
1085,
78,
199,
504,
302,
643,
1530,
492,
11822,
199,
504,
302,
643,
1530,
14,
73,
1085,
78,
492,
5501,
485,
44,
199,
504,
14490,
14,
1360,
14,
3118,
492,
12762,
281,
421,
199,
3,
6016,
5163,
12509,
687,
1455,
921,
1544,
14,
7898,
13,
15264,
14,
815,
15,
2123,
14,
1360,
199,
8175,
63,
907,
275,
519,
24726,
73,
18979,
59,
65,
13,
90,
16,
13,
25,
1,
3,
22074,
6,
16804,
19616,
18048,
62,
28116,
91,
92,
93,
94,
20253,
15840,
24097,
65,
13,
90,
16,
13,
25,
1,
3,
22074,
6,
16804,
19616,
18048,
62,
28116,
91,
92,
93,
94,
20253,
3342,
32,
25060,
65,
13,
90,
16,
13,
25,
61,
25060,
65,
13,
90,
16,
13,
25,
13,
3672,
59,
65,
13,
90,
16,
13,
25,
566,
31,
4537,
6393,
59,
65,
13,
90,
16,
13,
25,
61,
25060,
65,
13,
90,
16,
13,
25,
13,
3672,
59,
65,
13,
90,
16,
13,
25,
566,
31,
17351,
421,
199,
318,
3633,
63,
505,
8,
505,
304,
272,
1318,
275,
1318,
14,
1814,
8,
85,
7601,
3289,
4206,
399,
7601,
3289,
3072,
78,
358,
272,
1318,
275,
1318,
14,
1814,
8,
85,
29477,
80,
4206,
399,
29477,
80,
3072,
78,
358,
272,
1318,
275,
1318,
14,
1814,
8,
85,
29477,
317,
4206,
399,
29477,
317,
3072,
78,
358,
339,
372,
2649,
8,
1360,
14,
13521,
8,
505,
680,
505,
63,
1317,
1012,
421,
199,
318,
3633,
63,
1360,
8,
505,
304,
272,
3633,
281,
275,
12762,
281,
8,
2487,
29,
797,
9,
272,
372,
3633,
281,
14,
3118,
63,
1360,
8,
505,
9,
421,
199,
533,
19287,
8640,
8,
11034,
14,
8640,
304,
272,
408,
20403,
436,
6411,
402,
9446,
272,
408,
339,
347,
636,
826,
721,
277,
12,
574,
12,
6202,
29,
549,
12,
627,
589,
12,
1011,
829,
304,
267,
408,
5733,
19914,
398,
2670,
626,
314,
574,
365,
282,
2155,
398,
1010,
26,
881,
446,
1124,
86,
1040,
1553,
574,
370,
4107,
267,
408,
267,
862,
26,
288,
340,
1228,
8,
585,
12,
7116,
304,
355,
574,
275,
574,
14,
1913,
342,
2234,
340,
574,
14,
2325,
342,
315,
661,
5066,
297,
283,
265,
297,
283,
2052,
297,
283,
17,
735,
490,
291,
14,
585,
275,
715,
355,
916,
574,
14,
2325,
342,
315,
661,
889,
297,
283,
1997,
297,
283,
3910,
297,
283,
16,
735,
490,
291,
14,
585,
275,
756,
355,
587,
26,
490,
291,
14,
585,
275,
756,
288,
587,
26,
355,
291,
14,
585,
275,
2155,
8,
585,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
746,
1722,
8,
73,
1085,
78,
423,
8,
85,
7,
13757,
506,
282,
5046,
1333,
339,
370,
63,
2245,
275,
11822,
14,
8640,
855,
1250,
363,
421,
199,
318,
4107,
63,
5364,
8,
585,
12,
1343,
63,
1045,
63,
26831,
63,
9269,
29,
797,
12,
1390,
63,
552,
29,
3912,
304,
272,
408,
12584,
376,
5148,
26,
1454,
14435,
12,
7576,
503,
18888,
4110,
787,
10226,
624,
272,
340,
440,
574,
26,
267,
746,
1722,
6115,
11408,
440,
506,
2701,
2237,
339,
5048,
63,
6574,
275,
663,
480,
4970,
83,
5,
83,
2,
450,
334,
875,
14,
4371,
63,
16415,
12,
1059,
14,
7022,
430,
272,
4112,
275,
1006,
8,
67,
315,
5048,
63,
6574,
367,
286,
315,
574,
9,
272,
340,
440,
4112,
26,
267,
746,
1722,
6723,
11408,
1454,
1395,
13294,
14435,
12,
7576,
503,
18888,
4110,
1333,
339,
340,
1343,
63,
1045,
63,
26831,
63,
9269,
26,
267,
340,
574,
59,
16,
61,
440,
315,
1059,
14,
4371,
63,
26831,
26,
288,
746,
1722,
6115,
11408,
1343,
543,
376,
22681,
13294,
8082,
2237,
272,
587,
26,
267,
340,
574,
59,
16,
61,
440,
315,
1059,
14,
4371,
63,
16415,
26,
288,
746,
1722,
6115,
11408,
1343,
543,
376,
13294,
8082,
2237,
339,
340,
822,
8,
585,
9,
690,
1390,
63,
552,
26,
267,
746,
1722,
8,
288,
3824,
7544,
4634,
1846,
334,
988,
14,
450,
68,
4110,
6320,
450,
1390,
63,
552,
9,
339,
372,
574,
421,
199,
318,
4107,
63,
493,
8,
576,
12,
1390,
63,
890,
29,
403,
12,
1499,
12397,
2320,
1471,
506,
6656,
2419,
450,
68,
27638,
8109,
272,
408,
12584,
282,
283,
493,
7,
1324,
666,
6169,
314,
1390,
1568,
315,
27638,
624,
272,
327,
1104,
6169,
314,
1642,
6168,
7254,
543,
314,
1890,
272,
340,
666,
365,
488,
503,
1228,
8,
576,
12,
7116,
304,
267,
372,
488,
339,
340,
666,
14,
4456,
508,
446,
17,
26,
267,
746,
1722,
6723,
11761,
1990,
31366,
1333,
339,
327,
7545,
314,
570,
1568,
334,
390,
1159,
282,
5228,
9,
272,
666,
14,
493,
14,
5507,
8,
16,
12,
499,
9,
221,
327,
378,
687,
9027,
272,
23858,
275,
666,
14,
493,
14,
9974,
342,
272,
666,
14,
493,
14,
5507,
8,
16,
9,
339,
340,
1390,
63,
890,
365,
440,
488,
436,
23858,
690,
1390,
63,
890,
627,
6619,
26,
267,
746,
1722,
8,
1328,
450,
1390,
63,
890,
9,
339,
570,
576,
275,
666,
14,
493,
14,
739,
342,
272,
666,
14,
493,
14,
5507,
8,
16,
9,
339,
327,
2005,
23776,
334,
73,
14,
69,
14,
22026,
7910,
22732,
9,
3222,
314,
2615,
931,
402,
314,
570,
272,
327,
3140,
402,
314,
1788,
272,
327,
880,
12,
781,
2813,
314,
931,
687,
314,
1788,
272,
1788,
275,
13377,
515,
14,
4846,
8,
2975,
8,
576,
14,
1501,
430,
339,
372,
791,
1501,
356,
1788,
12,
288,
283,
576,
356,
570,
576,
12,
288,
283,
1317,
63,
466,
356,
2649,
8,
576,
14,
466,
6769,
421,
199,
318,
4107,
63,
2865,
63,
1667,
63,
875
] |
[
1882,
2803,
26,
1624,
13,
24,
1882,
199,
3,
306,
199,
3,
1898,
334,
67,
9,
6029,
13,
7280,
5365,
13,
2753,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2032,
365,
18233,
1334,
314,
6289,
844,
12,
465,
11736,
315,
199,
3,
314,
570,
5113,
14,
2424,
12,
1314,
1265,
1077,
1172,
3086,
465,
1777,
402,
199,
3,
642,
4084,
14,
199,
3,
306,
199,
199,
646,
295,
199,
646,
1059,
199,
646,
13377,
515,
199,
199,
504,
14490,
492,
3517,
199,
504,
302,
643,
1530,
492,
284,
1085,
78,
199,
504,
302,
643,
1530,
492,
11822,
199,
504,
302,
643,
1530,
14,
73,
1085,
78,
492,
5501,
485,
44,
199,
504,
14490,
14,
1360,
14,
3118,
492,
12762,
281,
421,
199,
3,
6016,
5163,
12509,
687,
1455,
921,
1544,
14,
7898,
13,
15264,
14,
815,
15,
2123,
14,
1360,
199,
8175,
63,
907,
275,
519,
24726,
73,
18979,
59,
65,
13,
90,
16,
13,
25,
1,
3,
22074,
6,
16804,
19616,
18048,
62,
28116,
91,
92,
93,
94,
20253,
15840,
24097,
65,
13,
90,
16,
13,
25,
1,
3,
22074,
6,
16804,
19616,
18048,
62,
28116,
91,
92,
93,
94,
20253,
3342,
32,
25060,
65,
13,
90,
16,
13,
25,
61,
25060,
65,
13,
90,
16,
13,
25,
13,
3672,
59,
65,
13,
90,
16,
13,
25,
566,
31,
4537,
6393,
59,
65,
13,
90,
16,
13,
25,
61,
25060,
65,
13,
90,
16,
13,
25,
13,
3672,
59,
65,
13,
90,
16,
13,
25,
566,
31,
17351,
421,
199,
318,
3633,
63,
505,
8,
505,
304,
272,
1318,
275,
1318,
14,
1814,
8,
85,
7601,
3289,
4206,
399,
7601,
3289,
3072,
78,
358,
272,
1318,
275,
1318,
14,
1814,
8,
85,
29477,
80,
4206,
399,
29477,
80,
3072,
78,
358,
272,
1318,
275,
1318,
14,
1814,
8,
85,
29477,
317,
4206,
399,
29477,
317,
3072,
78,
358,
339,
372,
2649,
8,
1360,
14,
13521,
8,
505,
680,
505,
63,
1317,
1012,
421,
199,
318,
3633,
63,
1360,
8,
505,
304,
272,
3633,
281,
275,
12762,
281,
8,
2487,
29,
797,
9,
272,
372,
3633,
281,
14,
3118,
63,
1360,
8,
505,
9,
421,
199,
533,
19287,
8640,
8,
11034,
14,
8640,
304,
272,
408,
20403,
436,
6411,
402,
9446,
272,
408,
339,
347,
636,
826,
721,
277,
12,
574,
12,
6202,
29,
549,
12,
627,
589,
12,
1011,
829,
304,
267,
408,
5733,
19914,
398,
2670,
626,
314,
574,
365,
282,
2155,
398,
1010,
26,
881,
446,
1124,
86,
1040,
1553,
574,
370,
4107,
267,
408,
267,
862,
26,
288,
340,
1228,
8,
585,
12,
7116,
304,
355,
574,
275,
574,
14,
1913,
342,
2234,
340,
574,
14,
2325,
342,
315,
661,
5066,
297,
283,
265,
297,
283,
2052,
297,
283,
17,
735,
490,
291,
14,
585,
275,
715,
355,
916,
574,
14,
2325,
342,
315,
661,
889,
297,
283,
1997,
297,
283,
3910,
297,
283,
16,
735,
490,
291,
14,
585,
275,
756,
355,
587,
26,
490,
291,
14,
585,
275,
756,
288,
587,
26,
355,
291,
14,
585,
275,
2155,
8,
585,
9,
267,
871,
334,
3393,
12,
3146,
304,
288,
746,
1722,
8,
73,
1085,
78,
423,
8,
85,
7,
13757,
506,
282,
5046,
1333,
339,
370,
63,
2245,
275,
11822,
14,
8640,
855,
1250,
363,
421,
199,
318,
4107,
63,
5364,
8,
585,
12,
1343,
63,
1045,
63,
26831,
63,
9269,
29,
797,
12,
1390,
63,
552,
29,
3912,
304,
272,
408,
12584,
376,
5148,
26,
1454,
14435,
12,
7576,
503,
18888,
4110,
787,
10226,
624,
272,
340,
440,
574,
26,
267,
746,
1722,
6115,
11408,
440,
506,
2701,
2237,
339,
5048,
63,
6574,
275,
663,
480,
4970,
83,
5,
83,
2,
450,
334,
875,
14,
4371,
63,
16415,
12,
1059,
14,
7022,
430,
272,
4112,
275,
1006,
8,
67,
315,
5048,
63,
6574,
367,
286,
315,
574,
9,
272,
340,
440,
4112,
26,
267,
746,
1722,
6723,
11408,
1454,
1395,
13294,
14435,
12,
7576,
503,
18888,
4110,
1333,
339,
340,
1343,
63,
1045,
63,
26831,
63,
9269,
26,
267,
340,
574,
59,
16,
61,
440,
315,
1059,
14,
4371,
63,
26831,
26,
288,
746,
1722,
6115,
11408,
1343,
543,
376,
22681,
13294,
8082,
2237,
272,
587,
26,
267,
340,
574,
59,
16,
61,
440,
315,
1059,
14,
4371,
63,
16415,
26,
288,
746,
1722,
6115,
11408,
1343,
543,
376,
13294,
8082,
2237,
339,
340,
822,
8,
585,
9,
690,
1390,
63,
552,
26,
267,
746,
1722,
8,
288,
3824,
7544,
4634,
1846,
334,
988,
14,
450,
68,
4110,
6320,
450,
1390,
63,
552,
9,
339,
372,
574,
421,
199,
318,
4107,
63,
493,
8,
576,
12,
1390,
63,
890,
29,
403,
12,
1499,
12397,
2320,
1471,
506,
6656,
2419,
450,
68,
27638,
8109,
272,
408,
12584,
282,
283,
493,
7,
1324,
666,
6169,
314,
1390,
1568,
315,
27638,
624,
272,
327,
1104,
6169,
314,
1642,
6168,
7254,
543,
314,
1890,
272,
340,
666,
365,
488,
503,
1228,
8,
576,
12,
7116,
304,
267,
372,
488,
339,
340,
666,
14,
4456,
508,
446,
17,
26,
267,
746,
1722,
6723,
11761,
1990,
31366,
1333,
339,
327,
7545,
314,
570,
1568,
334,
390,
1159,
282,
5228,
9,
272,
666,
14,
493,
14,
5507,
8,
16,
12,
499,
9,
221,
327,
378,
687,
9027,
272,
23858,
275,
666,
14,
493,
14,
9974,
342,
272,
666,
14,
493,
14,
5507,
8,
16,
9,
339,
340,
1390,
63,
890,
365,
440,
488,
436,
23858,
690,
1390,
63,
890,
627,
6619,
26,
267,
746,
1722,
8,
1328,
450,
1390,
63,
890,
9,
339,
570,
576,
275,
666,
14,
493,
14,
739,
342,
272,
666,
14,
493,
14,
5507,
8,
16,
9,
339,
327,
2005,
23776,
334,
73,
14,
69,
14,
22026,
7910,
22732,
9,
3222,
314,
2615,
931,
402,
314,
570,
272,
327,
3140,
402,
314,
1788,
272,
327,
880,
12,
781,
2813,
314,
931,
687,
314,
1788,
272,
1788,
275,
13377,
515,
14,
4846,
8,
2975,
8,
576,
14,
1501,
430,
339,
372,
791,
1501,
356,
1788,
12,
288,
283,
576,
356,
570,
576,
12,
288,
283,
1317,
63,
466,
356,
2649,
8,
576,
14,
466,
6769,
421,
199,
318,
4107,
63,
2865,
63,
1667,
63,
875,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bwhite/hadoopy
|
hadoopy/thirdparty/pyinstaller/PyInstaller/lib/macholib/MachOGraph.py
|
1
|
3783
|
"""
Utilities for reading and writing Mach-O headers
"""
from pkg_resources import require
require("altgraph")
import os
import sys
from altgraph.Graph import Graph
from altgraph.ObjectGraph import ObjectGraph
from macholib.mach_o import *
from macholib.dyld import dyld_find
from macholib.MachO import MachO
from macholib.itergraphreport import itergraphreport
__all__ = ['MachOGraph']
class MissingMachO(object):
def __init__(self, filename):
self.graphident = filename
self.headers = ()
def __repr__(self):
return '<%s graphident=%r>' % (type(self).__name__, self.graphident)
class MachOGraph(ObjectGraph):
"""
Graph data structure of Mach-O dependencies
"""
def __init__(self, debug=0, graph=None, env=None, executable_path=None):
super(MachOGraph, self).__init__(debug=debug, graph=graph)
self.env = env
self.trans_table = {}
self.executable_path = executable_path
def locate(self, filename):
assert isinstance(filename, (str, unicode))
fn = self.trans_table.get(filename)
if fn is None:
try:
fn = dyld_find(filename, env=self.env,
executable_path=self.executable_path)
self.trans_table[filename] = fn
except ValueError:
return None
return fn
def findNode(self, name):
assert isinstance(name, (str, unicode))
data = super(MachOGraph, self).findNode(name)
if data is not None:
return data
newname = self.locate(name)
if newname is not None and newname != name:
return self.findNode(newname)
return None
def run_file(self, pathname, caller=None):
assert isinstance(pathname, (str, unicode))
self.msgin(2, "run_file", pathname)
m = self.findNode(pathname)
if m is None:
if not os.path.exists(pathname):
raise ValueError('%r does not exist' % (pathname,))
m = self.createNode(MachO, pathname)
self.createReference(caller, m, edge_data='run_file')
self.scan_node(m)
self.msgout(2, '')
return m
def load_file(self, name, caller=None):
assert isinstance(name, (str, unicode))
self.msgin(2, "load_file", name)
m = self.findNode(name)
if m is None:
newname = self.locate(name)
if newname is not None and newname != name:
return self.load_file(newname, caller=caller)
if os.path.exists(name):
m = self.createNode(MachO, name)
self.scan_node(m)
else:
m = self.createNode(MissingMachO, name)
self.msgout(2, '')
return m
def scan_node(self, node):
self.msgin(2, 'scan_node', node)
for header in node.headers:
for idx, name, filename in header.walkRelocatables():
assert isinstance(name, (str, unicode))
assert isinstance(filename, (str, unicode))
m = self.load_file(filename, caller=node)
self.createReference(node, m, edge_data=name)
self.msgout(2, '', node)
def itergraphreport(self, name='G'):
nodes = map(self.graph.describe_node, self.graph.iterdfs(self))
describe_edge = self.graph.describe_edge
return itergraphreport(nodes, describe_edge, name=name)
def graphreport(self, fileobj=None):
if fileobj is None:
fileobj = sys.stdout
fileobj.writelines(self.itergraphreport())
def main(args):
g = MachOGraph()
for arg in args:
g.run_file(arg)
g.graphreport()
if __name__ == '__main__':
main(sys.argv[1:] or ['/bin/ls'])
|
gpl-3.0
|
[
624,
199,
22905,
367,
7664,
436,
3575,
30611,
13,
47,
2323,
199,
624,
199,
199,
504,
5496,
63,
4435,
492,
4409,
199,
4365,
480,
4478,
2180,
531,
199,
199,
646,
747,
199,
646,
984,
199,
199,
504,
8791,
2180,
14,
4578,
492,
11513,
199,
504,
8791,
2180,
14,
1692,
4578,
492,
6935,
4578,
199,
199,
504,
610,
2239,
773,
14,
14121,
63,
79,
492,
627,
199,
504,
610,
2239,
773,
14,
8161,
1447,
492,
13119,
1447,
63,
1623,
199,
504,
610,
2239,
773,
14,
45,
1225,
47,
492,
30611,
47,
199,
504,
610,
2239,
773,
14,
1661,
2180,
3070,
492,
2740,
2180,
3070,
199,
199,
363,
452,
363,
275,
788,
45,
1225,
47,
4578,
418,
199,
199,
533,
15626,
45,
1225,
47,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
2180,
5425,
275,
1788,
267,
291,
14,
2139,
275,
6248,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
3343,
5425,
2458,
82,
3524,
450,
334,
466,
8,
277,
2843,
354,
3108,
291,
14,
2180,
5425,
9,
199,
199,
533,
30611,
47,
4578,
8,
1692,
4578,
304,
272,
408,
272,
11513,
666,
5523,
402,
30611,
13,
47,
5124,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3105,
29,
16,
12,
3343,
29,
403,
12,
2589,
29,
403,
12,
7286,
63,
515,
29,
403,
304,
267,
1613,
8,
45,
1225,
47,
4578,
12,
291,
2843,
826,
721,
1757,
29,
1757,
12,
3343,
29,
2180,
9,
267,
291,
14,
1813,
275,
2589,
267,
291,
14,
1515,
63,
1224,
275,
1052,
267,
291,
14,
5904,
63,
515,
275,
7286,
63,
515,
339,
347,
16592,
8,
277,
12,
1788,
304,
267,
702,
1228,
8,
1501,
12,
334,
495,
12,
2649,
430,
267,
4325,
275,
291,
14,
1515,
63,
1224,
14,
362,
8,
1501,
9,
267,
340,
4325,
365,
488,
26,
288,
862,
26,
355,
4325,
275,
13119,
1447,
63,
1623,
8,
1501,
12,
2589,
29,
277,
14,
1813,
12,
490,
7286,
63,
515,
29,
277,
14,
5904,
63,
515,
9,
355,
291,
14,
1515,
63,
1224,
59,
1501,
61,
275,
4325,
288,
871,
1722,
26,
355,
372,
488,
267,
372,
4325,
339,
347,
2342,
1716,
8,
277,
12,
536,
304,
267,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
267,
666,
275,
1613,
8,
45,
1225,
47,
4578,
12,
291,
680,
1623,
1716,
8,
354,
9,
267,
340,
666,
365,
440,
488,
26,
288,
372,
666,
267,
26383,
275,
291,
14,
6280,
8,
354,
9,
267,
340,
26383,
365,
440,
488,
436,
26383,
1137,
536,
26,
288,
372,
291,
14,
1623,
1716,
8,
1222,
354,
9,
267,
372,
488,
339,
347,
1255,
63,
493,
8,
277,
12,
11776,
12,
8025,
29,
403,
304,
267,
702,
1228,
8,
12445,
12,
334,
495,
12,
2649,
430,
267,
291,
14,
706,
903,
8,
18,
12,
298,
1065,
63,
493,
401,
11776,
9,
267,
333,
275,
291,
14,
1623,
1716,
8,
12445,
9,
267,
340,
333,
365,
488,
26,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
12445,
304,
355,
746,
1722,
3508,
82,
1630,
440,
2187,
7,
450,
334,
12445,
4641,
288,
333,
275,
291,
14,
981,
1716,
8,
45,
1225,
47,
12,
11776,
9,
288,
291,
14,
981,
5083,
8,
11219,
12,
333,
12,
6275,
63,
576,
534,
1065,
63,
493,
358,
288,
291,
14,
6282,
63,
932,
8,
77,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
4074,
267,
372,
333,
339,
347,
2248,
63,
493,
8,
277,
12,
536,
12,
8025,
29,
403,
304,
267,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
267,
291,
14,
706,
903,
8,
18,
12,
298,
912,
63,
493,
401,
536,
9,
267,
333,
275,
291,
14,
1623,
1716,
8,
354,
9,
267,
340,
333,
365,
488,
26,
288,
26383,
275,
291,
14,
6280,
8,
354,
9,
288,
340,
26383,
365,
440,
488,
436,
26383,
1137,
536,
26,
355,
372,
291,
14,
912,
63,
493,
8,
1222,
354,
12,
8025,
29,
11219,
9,
288,
340,
747,
14,
515,
14,
2444,
8,
354,
304,
355,
333,
275,
291,
14,
981,
1716,
8,
45,
1225,
47,
12,
536,
9,
355,
291,
14,
6282,
63,
932,
8,
77,
9,
288,
587,
26,
355,
333,
275,
291,
14,
981,
1716,
8,
7718,
45,
1225,
47,
12,
536,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
4074,
267,
372,
333,
339,
347,
8000,
63,
932,
8,
277,
12,
1031,
304,
267,
291,
14,
706,
903,
8,
18,
12,
283,
6282,
63,
932,
297,
1031,
9,
267,
367,
1406,
315,
1031,
14,
2139,
26,
288,
367,
4280,
12,
536,
12,
1788,
315,
1406,
14,
7757,
497,
2102,
292,
5921,
837,
355,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
355,
702,
1228,
8,
1501,
12,
334,
495,
12,
2649,
430,
355,
333,
275,
291,
14,
912,
63,
493,
8,
1501,
12,
8025,
29,
932,
9,
355,
291,
14,
981,
5083,
8,
932,
12,
333,
12,
6275,
63,
576,
29,
354,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
3260,
1031,
9,
339,
347,
2740,
2180,
3070,
8,
277,
12,
536,
534,
39,
735,
267,
3380,
275,
2341,
8,
277,
14,
2180,
14,
11935,
63,
932,
12,
291,
14,
2180,
14,
1661,
10434,
8,
277,
430,
267,
13743,
63,
5173,
275,
291,
14,
2180,
14,
11935,
63,
5173,
267,
372,
2740,
2180,
3070,
8,
2415,
12,
13743,
63,
5173,
12,
536,
29,
354,
9,
339,
347,
3343,
3070,
8,
277,
12,
11099,
29,
403,
304,
267,
340,
11099,
365,
488,
26,
288,
11099,
275,
984,
14,
2703,
267,
11099,
14,
23277,
8,
277,
14,
1661,
2180,
3070,
1012,
199,
199,
318,
2446,
8,
589,
304,
272,
486,
275,
30611,
47,
4578,
342,
272,
367,
1680,
315,
1249,
26,
267,
486,
14,
1065,
63,
493,
8,
1273,
9,
272,
486,
14,
2180,
3070,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
1274,
14,
3020,
59,
17,
2938,
503,
18744,
1393,
15,
478,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
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,
22905,
367,
7664,
436,
3575,
30611,
13,
47,
2323,
199,
624,
199,
199,
504,
5496,
63,
4435,
492,
4409,
199,
4365,
480,
4478,
2180,
531,
199,
199,
646,
747,
199,
646,
984,
199,
199,
504,
8791,
2180,
14,
4578,
492,
11513,
199,
504,
8791,
2180,
14,
1692,
4578,
492,
6935,
4578,
199,
199,
504,
610,
2239,
773,
14,
14121,
63,
79,
492,
627,
199,
504,
610,
2239,
773,
14,
8161,
1447,
492,
13119,
1447,
63,
1623,
199,
504,
610,
2239,
773,
14,
45,
1225,
47,
492,
30611,
47,
199,
504,
610,
2239,
773,
14,
1661,
2180,
3070,
492,
2740,
2180,
3070,
199,
199,
363,
452,
363,
275,
788,
45,
1225,
47,
4578,
418,
199,
199,
533,
15626,
45,
1225,
47,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1788,
304,
267,
291,
14,
2180,
5425,
275,
1788,
267,
291,
14,
2139,
275,
6248,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
18342,
83,
3343,
5425,
2458,
82,
3524,
450,
334,
466,
8,
277,
2843,
354,
3108,
291,
14,
2180,
5425,
9,
199,
199,
533,
30611,
47,
4578,
8,
1692,
4578,
304,
272,
408,
272,
11513,
666,
5523,
402,
30611,
13,
47,
5124,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3105,
29,
16,
12,
3343,
29,
403,
12,
2589,
29,
403,
12,
7286,
63,
515,
29,
403,
304,
267,
1613,
8,
45,
1225,
47,
4578,
12,
291,
2843,
826,
721,
1757,
29,
1757,
12,
3343,
29,
2180,
9,
267,
291,
14,
1813,
275,
2589,
267,
291,
14,
1515,
63,
1224,
275,
1052,
267,
291,
14,
5904,
63,
515,
275,
7286,
63,
515,
339,
347,
16592,
8,
277,
12,
1788,
304,
267,
702,
1228,
8,
1501,
12,
334,
495,
12,
2649,
430,
267,
4325,
275,
291,
14,
1515,
63,
1224,
14,
362,
8,
1501,
9,
267,
340,
4325,
365,
488,
26,
288,
862,
26,
355,
4325,
275,
13119,
1447,
63,
1623,
8,
1501,
12,
2589,
29,
277,
14,
1813,
12,
490,
7286,
63,
515,
29,
277,
14,
5904,
63,
515,
9,
355,
291,
14,
1515,
63,
1224,
59,
1501,
61,
275,
4325,
288,
871,
1722,
26,
355,
372,
488,
267,
372,
4325,
339,
347,
2342,
1716,
8,
277,
12,
536,
304,
267,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
267,
666,
275,
1613,
8,
45,
1225,
47,
4578,
12,
291,
680,
1623,
1716,
8,
354,
9,
267,
340,
666,
365,
440,
488,
26,
288,
372,
666,
267,
26383,
275,
291,
14,
6280,
8,
354,
9,
267,
340,
26383,
365,
440,
488,
436,
26383,
1137,
536,
26,
288,
372,
291,
14,
1623,
1716,
8,
1222,
354,
9,
267,
372,
488,
339,
347,
1255,
63,
493,
8,
277,
12,
11776,
12,
8025,
29,
403,
304,
267,
702,
1228,
8,
12445,
12,
334,
495,
12,
2649,
430,
267,
291,
14,
706,
903,
8,
18,
12,
298,
1065,
63,
493,
401,
11776,
9,
267,
333,
275,
291,
14,
1623,
1716,
8,
12445,
9,
267,
340,
333,
365,
488,
26,
288,
340,
440,
747,
14,
515,
14,
2444,
8,
12445,
304,
355,
746,
1722,
3508,
82,
1630,
440,
2187,
7,
450,
334,
12445,
4641,
288,
333,
275,
291,
14,
981,
1716,
8,
45,
1225,
47,
12,
11776,
9,
288,
291,
14,
981,
5083,
8,
11219,
12,
333,
12,
6275,
63,
576,
534,
1065,
63,
493,
358,
288,
291,
14,
6282,
63,
932,
8,
77,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
4074,
267,
372,
333,
339,
347,
2248,
63,
493,
8,
277,
12,
536,
12,
8025,
29,
403,
304,
267,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
267,
291,
14,
706,
903,
8,
18,
12,
298,
912,
63,
493,
401,
536,
9,
267,
333,
275,
291,
14,
1623,
1716,
8,
354,
9,
267,
340,
333,
365,
488,
26,
288,
26383,
275,
291,
14,
6280,
8,
354,
9,
288,
340,
26383,
365,
440,
488,
436,
26383,
1137,
536,
26,
355,
372,
291,
14,
912,
63,
493,
8,
1222,
354,
12,
8025,
29,
11219,
9,
288,
340,
747,
14,
515,
14,
2444,
8,
354,
304,
355,
333,
275,
291,
14,
981,
1716,
8,
45,
1225,
47,
12,
536,
9,
355,
291,
14,
6282,
63,
932,
8,
77,
9,
288,
587,
26,
355,
333,
275,
291,
14,
981,
1716,
8,
7718,
45,
1225,
47,
12,
536,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
4074,
267,
372,
333,
339,
347,
8000,
63,
932,
8,
277,
12,
1031,
304,
267,
291,
14,
706,
903,
8,
18,
12,
283,
6282,
63,
932,
297,
1031,
9,
267,
367,
1406,
315,
1031,
14,
2139,
26,
288,
367,
4280,
12,
536,
12,
1788,
315,
1406,
14,
7757,
497,
2102,
292,
5921,
837,
355,
702,
1228,
8,
354,
12,
334,
495,
12,
2649,
430,
355,
702,
1228,
8,
1501,
12,
334,
495,
12,
2649,
430,
355,
333,
275,
291,
14,
912,
63,
493,
8,
1501,
12,
8025,
29,
932,
9,
355,
291,
14,
981,
5083,
8,
932,
12,
333,
12,
6275,
63,
576,
29,
354,
9,
267,
291,
14,
1328,
548,
8,
18,
12,
3260,
1031,
9,
339,
347,
2740,
2180,
3070,
8,
277,
12,
536,
534,
39,
735,
267,
3380,
275,
2341,
8,
277,
14,
2180,
14,
11935,
63,
932,
12,
291,
14,
2180,
14,
1661,
10434,
8,
277,
430,
267,
13743,
63,
5173,
275,
291,
14,
2180,
14,
11935,
63,
5173,
267,
372,
2740,
2180,
3070,
8,
2415,
12,
13743,
63,
5173,
12,
536,
29,
354,
9,
339,
347,
3343,
3070,
8,
277,
12,
11099,
29,
403,
304,
267,
340,
11099,
365,
488,
26,
288,
11099,
275,
984,
14,
2703,
267,
11099,
14,
23277,
8,
277,
14,
1661,
2180,
3070,
1012,
199,
199,
318,
2446,
8,
589,
304,
272,
486,
275,
30611,
47,
4578,
342,
272,
367,
1680,
315,
1249,
26,
267,
486,
14,
1065,
63,
493,
8,
1273,
9,
272,
486,
14,
2180,
3070,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
1274,
14,
3020,
59,
17,
2938,
503,
18744,
1393,
15,
478,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
shail2810/nova
|
nova/virt/vmwareapi/network_util.py
|
23
|
8643
|
# Copyright (c) 2012 VMware, Inc.
# Copyright (c) 2011 Citrix Systems, Inc.
# Copyright 2011 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Utility functions for ESX Networking.
"""
from oslo_log import log as logging
from oslo_vmware import exceptions as vexc
from oslo_vmware import vim_util as vutil
from nova import exception
from nova.i18n import _
from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
LOG = logging.getLogger(__name__)
def _get_network_obj(session, network_objects, network_name):
"""Gets the network object for the requested network.
The network object will be used when creating the VM configuration
spec. The network object contains the relevant network details for
the specific network type, for example, a distributed port group.
The method will search for the network_name in the list of
network_objects.
:param session: vCenter soap session
:param network_objects: group of networks
:param network_name: the requested network
:return: network object
"""
network_obj = {}
# network_objects is actually a RetrieveResult object from vSphere API call
for obj_content in network_objects:
# the propset attribute "need not be set" by returning API
if not hasattr(obj_content, 'propSet'):
continue
prop_dict = vm_util.propset_dict(obj_content.propSet)
network_refs = prop_dict.get('network')
if network_refs:
network_refs = network_refs.ManagedObjectReference
for network in network_refs:
# Get network properties
if network._type == 'DistributedVirtualPortgroup':
props = session._call_method(vim_util,
"get_dynamic_property", network,
"DistributedVirtualPortgroup", "config")
# NOTE(asomya): This only works on ESXi if the port binding
# is set to ephemeral
# For a VLAN the network name will be the UUID. For a VXLAN
# network this will have a VXLAN prefix and then the
# network name.
if network_name in props.name:
network_obj['type'] = 'DistributedVirtualPortgroup'
network_obj['dvpg'] = props.key
dvs_props = session._call_method(vim_util,
"get_dynamic_property",
props.distributedVirtualSwitch,
"VmwareDistributedVirtualSwitch",
"uuid")
network_obj['dvsw'] = dvs_props
return network_obj
else:
props = session._call_method(vim_util,
"get_dynamic_property", network,
"Network", "summary.name")
if props == network_name:
network_obj['type'] = 'Network'
network_obj['name'] = network_name
return network_obj
def get_network_with_the_name(session, network_name="vmnet0", cluster=None):
"""Gets reference to the network whose name is passed as the
argument.
"""
vm_networks = session._call_method(vim_util,
'get_object_properties',
None, cluster,
'ClusterComputeResource', ['network'])
while vm_networks:
if vm_networks.objects:
network_obj = _get_network_obj(session, vm_networks.objects,
network_name)
if network_obj:
session._call_method(vutil, 'cancel_retrieval',
vm_networks)
return network_obj
vm_networks = session._call_method(vutil, 'continue_retrieval',
vm_networks)
LOG.debug("Network %s not found on cluster!", network_name)
def get_vswitch_for_vlan_interface(session, vlan_interface, cluster=None):
"""Gets the vswitch associated with the physical network adapter
with the name supplied.
"""
# Get the list of vSwicthes on the Host System
host_mor = vm_util.get_host_ref(session, cluster)
vswitches_ret = session._call_method(vim_util,
"get_dynamic_property", host_mor,
"HostSystem", "config.network.vswitch")
# Meaning there are no vSwitches on the host. Shouldn't be the case,
# but just doing code check
if not vswitches_ret:
return
vswitches = vswitches_ret.HostVirtualSwitch
# Get the vSwitch associated with the network adapter
for elem in vswitches:
try:
for nic_elem in elem.pnic:
if str(nic_elem).split('-')[-1].find(vlan_interface) != -1:
return elem.name
# Catching Attribute error as a vSwitch may not be associated with a
# physical NIC.
except AttributeError:
pass
def check_if_vlan_interface_exists(session, vlan_interface, cluster=None):
"""Checks if the vlan_interface exists on the esx host."""
host_mor = vm_util.get_host_ref(session, cluster)
physical_nics_ret = session._call_method(vim_util,
"get_dynamic_property", host_mor,
"HostSystem", "config.network.pnic")
# Meaning there are no physical nics on the host
if not physical_nics_ret:
return False
physical_nics = physical_nics_ret.PhysicalNic
for pnic in physical_nics:
if vlan_interface == pnic.device:
return True
return False
def get_vlanid_and_vswitch_for_portgroup(session, pg_name, cluster=None):
"""Get the vlan id and vswitch associated with the port group."""
host_mor = vm_util.get_host_ref(session, cluster)
port_grps_on_host_ret = session._call_method(vim_util,
"get_dynamic_property", host_mor,
"HostSystem", "config.network.portgroup")
if not port_grps_on_host_ret:
msg = _("ESX SOAP server returned an empty port group "
"for the host system in its response")
LOG.error(msg)
raise exception.NovaException(msg)
port_grps_on_host = port_grps_on_host_ret.HostPortGroup
for p_gp in port_grps_on_host:
if p_gp.spec.name == pg_name:
p_grp_vswitch_name = p_gp.vswitch.split("-")[-1]
return p_gp.spec.vlanId, p_grp_vswitch_name
return None, None
def create_port_group(session, pg_name, vswitch_name, vlan_id=0, cluster=None):
"""Creates a port group on the host system with the vlan tags
supplied. VLAN id 0 means no vlan id association.
"""
client_factory = session.vim.client.factory
add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec(
client_factory,
vswitch_name,
pg_name,
vlan_id)
host_mor = vm_util.get_host_ref(session, cluster)
network_system_mor = session._call_method(vim_util,
"get_dynamic_property", host_mor,
"HostSystem", "configManager.networkSystem")
LOG.debug("Creating Port Group with name %s on "
"the ESX host", pg_name)
try:
session._call_method(session.vim,
"AddPortGroup", network_system_mor,
portgrp=add_prt_grp_spec)
except vexc.AlreadyExistsException:
# There can be a race condition when two instances try
# adding port groups at the same time. One succeeds, then
# the other one will get an exception. Since we are
# concerned with the port group being created, which is done
# by the other call, we can ignore the exception.
LOG.debug("Port Group %s already exists.", pg_name)
LOG.debug("Created Port Group with name %s on "
"the ESX host", pg_name)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6029,
27391,
12,
3277,
14,
199,
3,
1898,
334,
67,
9,
7760,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
17505,
3423,
367,
10427,
56,
7220,
316,
14,
199,
624,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
18970,
492,
4967,
465,
373,
2804,
199,
504,
11258,
63,
18970,
492,
6695,
63,
1974,
465,
373,
1974,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
4169,
63,
1974,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
362,
63,
1200,
63,
1113,
8,
1730,
12,
2784,
63,
1462,
12,
2784,
63,
354,
304,
272,
408,
14426,
314,
2784,
909,
367,
314,
5839,
2784,
14,
339,
710,
2784,
909,
911,
506,
1202,
1380,
6425,
314,
7525,
2897,
272,
3158,
14,
710,
2784,
909,
3509,
314,
12082,
2784,
2436,
367,
272,
314,
2488,
2784,
730,
12,
367,
2893,
12,
282,
1854,
1844,
1572,
14,
339,
710,
1083,
911,
2754,
367,
314,
2784,
63,
354,
315,
314,
769,
402,
272,
2784,
63,
1462,
14,
339,
520,
635,
2351,
26,
373,
13551,
880,
439,
2351,
272,
520,
635,
2784,
63,
1462,
26,
1572,
402,
11759,
272,
520,
635,
2784,
63,
354,
26,
314,
5839,
2784,
272,
520,
1107,
26,
2784,
909,
272,
408,
339,
2784,
63,
1113,
275,
1052,
272,
327,
2784,
63,
1462,
365,
5965,
282,
13939,
2889,
909,
687,
373,
22385,
3261,
1240,
272,
367,
1559,
63,
1317,
315,
2784,
63,
1462,
26,
267,
327,
314,
5931,
409,
2225,
298,
9321,
440,
506,
663,
2,
701,
8152,
3261,
267,
340,
440,
2688,
8,
1113,
63,
1317,
12,
283,
4469,
1084,
735,
288,
1980,
267,
5931,
63,
807,
275,
4169,
63,
1974,
14,
4469,
409,
63,
807,
8,
1113,
63,
1317,
14,
4469,
1084,
9,
267,
2784,
63,
7655,
275,
5931,
63,
807,
14,
362,
360,
1200,
358,
267,
340,
2784,
63,
7655,
26,
288,
2784,
63,
7655,
275,
2784,
63,
7655,
14,
22625,
1692,
5083,
288,
367,
2784,
315,
2784,
63,
7655,
26,
355,
327,
2372,
2784,
4382,
355,
340,
2784,
423,
466,
508,
283,
27398,
8735,
4313,
923,
356,
490,
10792,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
1816,
298,
362,
63,
7764,
63,
1829,
401,
2784,
12,
1816,
298,
27398,
8735,
4313,
923,
401,
298,
888,
531,
490,
327,
6944,
8,
305,
676,
11552,
304,
961,
1454,
5419,
641,
10427,
14828,
340,
314,
1844,
11696,
490,
327,
365,
663,
370,
26288,
490,
327,
2104,
282,
17591,
314,
2784,
536,
911,
506,
314,
11134,
14,
2104,
282,
812,
56,
10825,
490,
327,
2784,
642,
911,
1172,
282,
812,
56,
10825,
2403,
436,
2066,
314,
490,
327,
2784,
536,
14,
490,
340,
2784,
63,
354,
315,
10792,
14,
354,
26,
717,
2784,
63,
1113,
459,
466,
418,
275,
283,
27398,
8735,
4313,
923,
7,
717,
2784,
63,
1113,
459,
8398,
4198,
418,
275,
10792,
14,
498,
717,
366,
3122,
63,
6750,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
3147,
298,
362,
63,
7764,
63,
1829,
401,
3147,
10792,
14,
16832,
8735,
10167,
12,
3147,
298,
17402,
1068,
27398,
8735,
10167,
401,
3147,
298,
2580,
531,
717,
2784,
63,
1113,
459,
68,
3122,
87,
418,
275,
366,
3122,
63,
6750,
717,
372,
2784,
63,
1113,
355,
587,
26,
490,
10792,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
1816,
298,
362,
63,
7764,
63,
1829,
401,
2784,
12,
1816,
298,
4491,
401,
298,
4705,
14,
354,
531,
490,
340,
10792,
508,
2784,
63,
354,
26,
717,
2784,
63,
1113,
459,
466,
418,
275,
283,
4491,
7,
717,
2784,
63,
1113,
459,
354,
418,
275,
2784,
63,
354,
717,
372,
2784,
63,
1113,
421,
199,
318,
664,
63,
1200,
63,
1045,
63,
1589,
63,
354,
8,
1730,
12,
2784,
63,
354,
628,
2611,
846,
16,
401,
4350,
29,
403,
304,
272,
408,
14426,
3659,
370,
314,
2784,
7447,
536,
365,
3032,
465,
314,
272,
1423,
14,
272,
408,
272,
4169,
63,
7642,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
4318,
283,
362,
63,
785,
63,
3282,
297,
4318,
488,
12,
4350,
12,
4318,
283,
9581,
8564,
4031,
297,
788,
1200,
1105,
272,
1830,
4169,
63,
7642,
26,
267,
340,
4169,
63,
7642,
14,
1462,
26,
288,
2784,
63,
1113,
275,
485,
362,
63,
1200,
63,
1113,
8,
1730,
12,
4169,
63,
7642,
14,
1462,
12,
5644,
2784,
63,
354,
9,
288,
340,
2784,
63,
1113,
26,
355,
2351,
423,
1250,
63,
765,
8,
86,
1974,
12,
283,
6406,
63,
11235,
2579,
297,
3660,
4169,
63,
7642,
9,
355,
372,
2784,
63,
1113,
267,
4169,
63,
7642,
275,
2351,
423,
1250,
63,
765,
8,
86,
1974,
12,
283,
6958,
63,
11235,
2579,
297,
5644,
4169,
63,
7642,
9,
272,
5051,
14,
1757,
480,
4491,
450,
83,
440,
1911,
641,
4350,
17716,
2784,
63,
354,
9,
421,
199,
318,
664,
63,
23201,
63,
509,
63,
7175,
63,
3266,
8,
1730,
12,
10119,
63,
3266,
12,
4350,
29,
403,
304,
272,
408,
14426,
314,
373,
5656,
4568,
543,
314,
14095,
2784,
12146,
272,
543,
314,
536
] |
[
1898,
334,
67,
9,
6029,
27391,
12,
3277,
14,
199,
3,
1898,
334,
67,
9,
7760,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
1898,
7760,
14260,
2752,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
624,
199,
17505,
3423,
367,
10427,
56,
7220,
316,
14,
199,
624,
199,
504,
11258,
63,
793,
492,
943,
465,
2050,
199,
504,
11258,
63,
18970,
492,
4967,
465,
373,
2804,
199,
504,
11258,
63,
18970,
492,
6695,
63,
1974,
465,
373,
1974,
199,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
73,
1085,
78,
492,
485,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
6695,
63,
1974,
199,
504,
5913,
14,
4549,
14,
18970,
1246,
492,
4169,
63,
1974,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
485,
362,
63,
1200,
63,
1113,
8,
1730,
12,
2784,
63,
1462,
12,
2784,
63,
354,
304,
272,
408,
14426,
314,
2784,
909,
367,
314,
5839,
2784,
14,
339,
710,
2784,
909,
911,
506,
1202,
1380,
6425,
314,
7525,
2897,
272,
3158,
14,
710,
2784,
909,
3509,
314,
12082,
2784,
2436,
367,
272,
314,
2488,
2784,
730,
12,
367,
2893,
12,
282,
1854,
1844,
1572,
14,
339,
710,
1083,
911,
2754,
367,
314,
2784,
63,
354,
315,
314,
769,
402,
272,
2784,
63,
1462,
14,
339,
520,
635,
2351,
26,
373,
13551,
880,
439,
2351,
272,
520,
635,
2784,
63,
1462,
26,
1572,
402,
11759,
272,
520,
635,
2784,
63,
354,
26,
314,
5839,
2784,
272,
520,
1107,
26,
2784,
909,
272,
408,
339,
2784,
63,
1113,
275,
1052,
272,
327,
2784,
63,
1462,
365,
5965,
282,
13939,
2889,
909,
687,
373,
22385,
3261,
1240,
272,
367,
1559,
63,
1317,
315,
2784,
63,
1462,
26,
267,
327,
314,
5931,
409,
2225,
298,
9321,
440,
506,
663,
2,
701,
8152,
3261,
267,
340,
440,
2688,
8,
1113,
63,
1317,
12,
283,
4469,
1084,
735,
288,
1980,
267,
5931,
63,
807,
275,
4169,
63,
1974,
14,
4469,
409,
63,
807,
8,
1113,
63,
1317,
14,
4469,
1084,
9,
267,
2784,
63,
7655,
275,
5931,
63,
807,
14,
362,
360,
1200,
358,
267,
340,
2784,
63,
7655,
26,
288,
2784,
63,
7655,
275,
2784,
63,
7655,
14,
22625,
1692,
5083,
288,
367,
2784,
315,
2784,
63,
7655,
26,
355,
327,
2372,
2784,
4382,
355,
340,
2784,
423,
466,
508,
283,
27398,
8735,
4313,
923,
356,
490,
10792,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
1816,
298,
362,
63,
7764,
63,
1829,
401,
2784,
12,
1816,
298,
27398,
8735,
4313,
923,
401,
298,
888,
531,
490,
327,
6944,
8,
305,
676,
11552,
304,
961,
1454,
5419,
641,
10427,
14828,
340,
314,
1844,
11696,
490,
327,
365,
663,
370,
26288,
490,
327,
2104,
282,
17591,
314,
2784,
536,
911,
506,
314,
11134,
14,
2104,
282,
812,
56,
10825,
490,
327,
2784,
642,
911,
1172,
282,
812,
56,
10825,
2403,
436,
2066,
314,
490,
327,
2784,
536,
14,
490,
340,
2784,
63,
354,
315,
10792,
14,
354,
26,
717,
2784,
63,
1113,
459,
466,
418,
275,
283,
27398,
8735,
4313,
923,
7,
717,
2784,
63,
1113,
459,
8398,
4198,
418,
275,
10792,
14,
498,
717,
366,
3122,
63,
6750,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
3147,
298,
362,
63,
7764,
63,
1829,
401,
3147,
10792,
14,
16832,
8735,
10167,
12,
3147,
298,
17402,
1068,
27398,
8735,
10167,
401,
3147,
298,
2580,
531,
717,
2784,
63,
1113,
459,
68,
3122,
87,
418,
275,
366,
3122,
63,
6750,
717,
372,
2784,
63,
1113,
355,
587,
26,
490,
10792,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
1816,
298,
362,
63,
7764,
63,
1829,
401,
2784,
12,
1816,
298,
4491,
401,
298,
4705,
14,
354,
531,
490,
340,
10792,
508,
2784,
63,
354,
26,
717,
2784,
63,
1113,
459,
466,
418,
275,
283,
4491,
7,
717,
2784,
63,
1113,
459,
354,
418,
275,
2784,
63,
354,
717,
372,
2784,
63,
1113,
421,
199,
318,
664,
63,
1200,
63,
1045,
63,
1589,
63,
354,
8,
1730,
12,
2784,
63,
354,
628,
2611,
846,
16,
401,
4350,
29,
403,
304,
272,
408,
14426,
3659,
370,
314,
2784,
7447,
536,
365,
3032,
465,
314,
272,
1423,
14,
272,
408,
272,
4169,
63,
7642,
275,
2351,
423,
1250,
63,
765,
8,
16361,
63,
1974,
12,
4318,
283,
362,
63,
785,
63,
3282,
297,
4318,
488,
12,
4350,
12,
4318,
283,
9581,
8564,
4031,
297,
788,
1200,
1105,
272,
1830,
4169,
63,
7642,
26,
267,
340,
4169,
63,
7642,
14,
1462,
26,
288,
2784,
63,
1113,
275,
485,
362,
63,
1200,
63,
1113,
8,
1730,
12,
4169,
63,
7642,
14,
1462,
12,
5644,
2784,
63,
354,
9,
288,
340,
2784,
63,
1113,
26,
355,
2351,
423,
1250,
63,
765,
8,
86,
1974,
12,
283,
6406,
63,
11235,
2579,
297,
3660,
4169,
63,
7642,
9,
355,
372,
2784,
63,
1113,
267,
4169,
63,
7642,
275,
2351,
423,
1250,
63,
765,
8,
86,
1974,
12,
283,
6958,
63,
11235,
2579,
297,
5644,
4169,
63,
7642,
9,
272,
5051,
14,
1757,
480,
4491,
450,
83,
440,
1911,
641,
4350,
17716,
2784,
63,
354,
9,
421,
199,
318,
664,
63,
23201,
63,
509,
63,
7175,
63,
3266,
8,
1730,
12,
10119,
63,
3266,
12,
4350,
29,
403,
304,
272,
408,
14426,
314,
373,
5656,
4568,
543,
314,
14095,
2784,
12146,
272,
543,
314,
536,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maemo-foss/meego-cellular-telepathy-ring
|
tools/glib-errors-enum-body-gen.py
|
14
|
1770
|
#!/usr/bin/python
import sys
import xml.dom.minidom
from libglibcodegen import NS_TP, camelcase_to_upper, get_docstring, \
get_descendant_text
class Generator(object):
def __init__(self, dom):
self.dom = dom
self.errors = self.dom.getElementsByTagNameNS(NS_TP, 'errors')[0]
def do_header(self):
print '/* Generated from the Telepathy spec\n'
copyrights = self.errors.getElementsByTagNameNS(NS_TP, 'copyright')
for copyright in copyrights:
print get_descendant_text(copyright)
license = self.errors.getElementsByTagNameNS(NS_TP, 'license')[0]
print '\n' + get_descendant_text(license) + '\n*/'
def do_enum_values(self):
for error in self.errors.getElementsByTagNameNS(NS_TP, 'error'):
print ''
nick = error.getAttribute('name').replace(' ', '')
name = camelcase_to_upper(nick.replace('.', ''))
ns = error.parentNode.getAttribute('namespace')
enum = 'TP_ERROR_' + name
print ' /* ' + ns + '.' + name
print ' ' + get_docstring(error)
print ' */'
print ' { %s, "%s", "%s" },' % (enum, enum, nick)
def do_get_type(self):
print """
#include <_gen/telepathy-errors.h>
GType
tp_error_get_type (void)
{
static GType etype = 0;
if (G_UNLIKELY (etype == 0))
{
static const GEnumValue values[] = {"""
self.do_enum_values()
print """\
};
etype = g_enum_register_static ("TpError", values);
}
return etype;
}
"""
def __call__(self):
self.do_header()
self.do_get_type()
if __name__ == '__main__':
argv = sys.argv[1:]
Generator(xml.dom.minidom.parse(argv[0]))()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
984,
199,
646,
2748,
14,
4556,
14,
21827,
199,
199,
504,
1973,
30816,
600,
2268,
492,
9380,
63,
6495,
12,
31129,
2546,
63,
475,
63,
4142,
12,
664,
63,
12485,
12,
971,
267,
664,
63,
31759,
63,
505,
199,
199,
533,
15042,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
8266,
304,
267,
291,
14,
4556,
275,
8266,
267,
291,
14,
2550,
275,
291,
14,
4556,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
2550,
5832,
16,
61,
339,
347,
886,
63,
1291,
8,
277,
304,
267,
870,
1994,
10,
17065,
687,
314,
23884,
515,
89,
3158,
60,
78,
7,
267,
4248,
83,
275,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
7307,
358,
267,
367,
4248,
315,
4248,
83,
26,
288,
870,
664,
63,
31759,
63,
505,
8,
7307,
9,
267,
4190,
275,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
1682,
5832,
16,
61,
267,
870,
1557,
78,
7,
435,
664,
63,
31759,
63,
505,
8,
1682,
9,
435,
1557,
78,
10,
4805,
339,
347,
886,
63,
4869,
63,
1459,
8,
277,
304,
267,
367,
1125,
315,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
705,
735,
288,
870,
2125,
288,
14900,
275,
1125,
14,
12956,
360,
354,
1959,
1814,
360,
1656,
4074,
288,
536,
275,
31129,
2546,
63,
475,
63,
4142,
8,
11082,
14,
1814,
14078,
12381,
288,
700,
275,
1125,
14,
24899,
14,
12956,
360,
3251,
358,
288,
4952,
275,
283,
6495,
63,
3170,
8650,
435,
536,
288,
870,
283,
263,
13505,
283,
435,
700,
435,
7815,
435,
536,
288,
870,
283,
259,
283,
435,
664,
63,
12485,
8,
705,
9,
288,
870,
283,
258,
627,
4805,
288,
870,
283,
263,
469,
450,
83,
12,
2071,
83,
401,
2071,
83,
2,
1660,
7,
450,
334,
4869,
12,
4952,
12,
14900,
9,
2378,
347,
886,
63,
362,
63,
466,
8,
277,
304,
267,
870,
408,
199,
3,
2613,
665,
63,
2268,
15,
15253,
515,
89,
13,
2550,
14,
72,
30,
199,
199,
39,
804,
199,
683,
63,
705,
63,
362,
63,
466,
334,
1647,
9,
199,
91,
523,
2955,
598,
804,
30527,
275,
378,
27,
523,
340,
334,
39,
63,
1734,
21929,
6084,
334,
29232,
508,
378,
430,
272,
469,
489,
2955,
950,
598,
14432,
1338,
8607,
275,
469,
624,
267,
291,
14,
1117,
63,
4869,
63,
1459,
342,
267,
870,
9638,
489,
16735,
2541,
30527,
275,
486,
63,
4869,
63,
2683,
63,
1986,
1689,
52,
80,
547,
401,
1338,
2736,
272,
789,
523,
372,
30527,
27,
199,
93,
199,
624,
339,
347,
636,
1250,
721,
277,
304,
267,
291,
14,
1117,
63,
1291,
342,
267,
291,
14,
1117,
63,
362,
63,
466,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9238,
275,
984,
14,
3020,
59,
17,
2938,
272,
15042,
8,
1652,
14,
4556,
14,
21827,
14,
1122,
8,
3020,
59,
16,
2459,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
646,
984,
199,
646,
2748,
14,
4556,
14,
21827,
199,
199,
504,
1973,
30816,
600,
2268,
492,
9380,
63,
6495,
12,
31129,
2546,
63,
475,
63,
4142,
12,
664,
63,
12485,
12,
971,
267,
664,
63,
31759,
63,
505,
199,
199,
533,
15042,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
8266,
304,
267,
291,
14,
4556,
275,
8266,
267,
291,
14,
2550,
275,
291,
14,
4556,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
2550,
5832,
16,
61,
339,
347,
886,
63,
1291,
8,
277,
304,
267,
870,
1994,
10,
17065,
687,
314,
23884,
515,
89,
3158,
60,
78,
7,
267,
4248,
83,
275,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
7307,
358,
267,
367,
4248,
315,
4248,
83,
26,
288,
870,
664,
63,
31759,
63,
505,
8,
7307,
9,
267,
4190,
275,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
1682,
5832,
16,
61,
267,
870,
1557,
78,
7,
435,
664,
63,
31759,
63,
505,
8,
1682,
9,
435,
1557,
78,
10,
4805,
339,
347,
886,
63,
4869,
63,
1459,
8,
277,
304,
267,
367,
1125,
315,
291,
14,
2550,
14,
15045,
2709,
8,
2709,
63,
6495,
12,
283,
705,
735,
288,
870,
2125,
288,
14900,
275,
1125,
14,
12956,
360,
354,
1959,
1814,
360,
1656,
4074,
288,
536,
275,
31129,
2546,
63,
475,
63,
4142,
8,
11082,
14,
1814,
14078,
12381,
288,
700,
275,
1125,
14,
24899,
14,
12956,
360,
3251,
358,
288,
4952,
275,
283,
6495,
63,
3170,
8650,
435,
536,
288,
870,
283,
263,
13505,
283,
435,
700,
435,
7815,
435,
536,
288,
870,
283,
259,
283,
435,
664,
63,
12485,
8,
705,
9,
288,
870,
283,
258,
627,
4805,
288,
870,
283,
263,
469,
450,
83,
12,
2071,
83,
401,
2071,
83,
2,
1660,
7,
450,
334,
4869,
12,
4952,
12,
14900,
9,
2378,
347,
886,
63,
362,
63,
466,
8,
277,
304,
267,
870,
408,
199,
3,
2613,
665,
63,
2268,
15,
15253,
515,
89,
13,
2550,
14,
72,
30,
199,
199,
39,
804,
199,
683,
63,
705,
63,
362,
63,
466,
334,
1647,
9,
199,
91,
523,
2955,
598,
804,
30527,
275,
378,
27,
523,
340,
334,
39,
63,
1734,
21929,
6084,
334,
29232,
508,
378,
430,
272,
469,
489,
2955,
950,
598,
14432,
1338,
8607,
275,
469,
624,
267,
291,
14,
1117,
63,
4869,
63,
1459,
342,
267,
870,
9638,
489,
16735,
2541,
30527,
275,
486,
63,
4869,
63,
2683,
63,
1986,
1689,
52,
80,
547,
401,
1338,
2736,
272,
789,
523,
372,
30527,
27,
199,
93,
199,
624,
339,
347,
636,
1250,
721,
277,
304,
267,
291,
14,
1117,
63,
1291,
342,
267,
291,
14,
1117,
63,
362,
63,
466,
342,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
9238,
275,
984,
14,
3020,
59,
17,
2938,
272,
15042,
8,
1652,
14,
4556,
14,
21827,
14,
1122,
8,
3020,
59,
16,
2459,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
willzhang05/postgrestesting1
|
postgrestesting1/lib/python3.5/site-packages/pip/_vendor/html5lib/sanitizer.py
|
283
|
17660
|
from __future__ import absolute_import, division, unicode_literals
import re
from xml.sax.saxutils import escape, unescape
from six.moves import urllib_parse as urlparse
from .tokenizer import HTMLTokenizer
from .constants import tokenTypes
content_type_rgx = re.compile(r'''
^
# Match a content type <application>/<type>
(?P<content_type>[-a-zA-Z0-9.]+/[-a-zA-Z0-9.]+)
# Match any character set and encoding
(?:(?:;charset=(?:[-a-zA-Z0-9]+)(?:;(?:base64))?)
|(?:;(?:base64))?(?:;charset=(?:[-a-zA-Z0-9]+))?)
# Assume the rest is data
,.*
$
''',
re.VERBOSE)
class HTMLSanitizerMixin(object):
""" sanitization of XHTML+MathML+SVG and of inline style attributes."""
acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',
'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',
'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
'dialog', 'dir', 'div', 'dl', 'dt', 'em', 'event-source', 'fieldset',
'figcaption', 'figure', 'footer', 'font', 'form', 'header', 'h1',
'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'input', 'ins',
'keygen', 'kbd', 'label', 'legend', 'li', 'm', 'map', 'menu', 'meter',
'multicol', 'nav', 'nextid', 'ol', 'output', 'optgroup', 'option',
'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
mathml_elements = ['maction', 'math', 'merror', 'mfrac', 'mi',
'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom',
'mprescripts', 'mroot', 'mrow', 'mspace', 'msqrt', 'mstyle', 'msub',
'msubsup', 'msup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder',
'munderover', 'none']
svg_elements = ['a', 'animate', 'animateColor', 'animateMotion',
'animateTransform', 'clipPath', 'circle', 'defs', 'desc', 'ellipse',
'font-face', 'font-face-name', 'font-face-src', 'g', 'glyph', 'hkern',
'linearGradient', 'line', 'marker', 'metadata', 'missing-glyph',
'mpath', 'path', 'polygon', 'polyline', 'radialGradient', 'rect',
'set', 'stop', 'svg', 'switch', 'text', 'title', 'tspan', 'use']
acceptable_attributes = ['abbr', 'accept', 'accept-charset', 'accesskey',
'action', 'align', 'alt', 'autocomplete', 'autofocus', 'axis',
'background', 'balance', 'bgcolor', 'bgproperties', 'border',
'bordercolor', 'bordercolordark', 'bordercolorlight', 'bottompadding',
'cellpadding', 'cellspacing', 'ch', 'challenge', 'char', 'charoff',
'choff', 'charset', 'checked', 'cite', 'class', 'clear', 'color',
'cols', 'colspan', 'compact', 'contenteditable', 'controls', 'coords',
'data', 'datafld', 'datapagesize', 'datasrc', 'datetime', 'default',
'delay', 'dir', 'disabled', 'draggable', 'dynsrc', 'enctype', 'end',
'face', 'for', 'form', 'frame', 'galleryimg', 'gutter', 'headers',
'height', 'hidefocus', 'hidden', 'high', 'href', 'hreflang', 'hspace',
'icon', 'id', 'inputmode', 'ismap', 'keytype', 'label', 'leftspacing',
'lang', 'list', 'longdesc', 'loop', 'loopcount', 'loopend',
'loopstart', 'low', 'lowsrc', 'max', 'maxlength', 'media', 'method',
'min', 'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'open',
'optimum', 'pattern', 'ping', 'point-size', 'poster', 'pqg', 'preload',
'prompt', 'radiogroup', 'readonly', 'rel', 'repeat-max', 'repeat-min',
'replace', 'required', 'rev', 'rightspacing', 'rows', 'rowspan',
'rules', 'scope', 'selected', 'shape', 'size', 'span', 'src', 'start',
'step', 'style', 'summary', 'suppress', 'tabindex', 'target',
'template', 'title', 'toppadding', 'type', 'unselectable', 'usemap',
'urn', 'valign', 'value', 'variable', 'volume', 'vspace', 'vrml',
'width', 'wrap', 'xml:lang']
mathml_attributes = ['actiontype', 'align', 'columnalign', 'columnalign',
'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'depth',
'display', 'displaystyle', 'equalcolumns', 'equalrows', 'fence',
'fontstyle', 'fontweight', 'frame', 'height', 'linethickness', 'lspace',
'mathbackground', 'mathcolor', 'mathvariant', 'mathvariant', 'maxsize',
'minsize', 'other', 'rowalign', 'rowalign', 'rowalign', 'rowlines',
'rowspacing', 'rowspan', 'rspace', 'scriptlevel', 'selection',
'separator', 'stretchy', 'width', 'width', 'xlink:href', 'xlink:show',
'xlink:type', 'xmlns', 'xmlns:xlink']
svg_attributes = ['accent-height', 'accumulate', 'additive', 'alphabetic',
'arabic-form', 'ascent', 'attributeName', 'attributeType',
'baseProfile', 'bbox', 'begin', 'by', 'calcMode', 'cap-height',
'class', 'clip-path', 'color', 'color-rendering', 'content', 'cx',
'cy', 'd', 'dx', 'dy', 'descent', 'display', 'dur', 'end', 'fill',
'fill-opacity', 'fill-rule', 'font-family', 'font-size',
'font-stretch', 'font-style', 'font-variant', 'font-weight', 'from',
'fx', 'fy', 'g1', 'g2', 'glyph-name', 'gradientUnits', 'hanging',
'height', 'horiz-adv-x', 'horiz-origin-x', 'id', 'ideographic', 'k',
'keyPoints', 'keySplines', 'keyTimes', 'lang', 'marker-end',
'marker-mid', 'marker-start', 'markerHeight', 'markerUnits',
'markerWidth', 'mathematical', 'max', 'min', 'name', 'offset',
'opacity', 'orient', 'origin', 'overline-position',
'overline-thickness', 'panose-1', 'path', 'pathLength', 'points',
'preserveAspectRatio', 'r', 'refX', 'refY', 'repeatCount',
'repeatDur', 'requiredExtensions', 'requiredFeatures', 'restart',
'rotate', 'rx', 'ry', 'slope', 'stemh', 'stemv', 'stop-color',
'stop-opacity', 'strikethrough-position', 'strikethrough-thickness',
'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap',
'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity',
'stroke-width', 'systemLanguage', 'target', 'text-anchor', 'to',
'transform', 'type', 'u1', 'u2', 'underline-position',
'underline-thickness', 'unicode', 'unicode-range', 'units-per-em',
'values', 'version', 'viewBox', 'visibility', 'width', 'widths', 'x',
'x-height', 'x1', 'x2', 'xlink:actuate', 'xlink:arcrole',
'xlink:href', 'xlink:role', 'xlink:show', 'xlink:title', 'xlink:type',
'xml:base', 'xml:lang', 'xml:space', 'xmlns', 'xmlns:xlink', 'y',
'y1', 'y2', 'zoomAndPan']
attr_val_is_uri = ['href', 'src', 'cite', 'action', 'longdesc', 'poster', 'background', 'datasrc',
'dynsrc', 'lowsrc', 'ping', 'poster', 'xlink:href', 'xml:base']
svg_attr_val_allows_ref = ['clip-path', 'color-profile', 'cursor', 'fill',
'filter', 'marker', 'marker-start', 'marker-mid', 'marker-end',
'mask', 'stroke']
svg_allow_local_href = ['altGlyph', 'animate', 'animateColor',
'animateMotion', 'animateTransform', 'cursor', 'feImage', 'filter',
'linearGradient', 'pattern', 'radialGradient', 'textpath', 'tref',
'set', 'use']
acceptable_css_properties = ['azimuth', 'background-color',
'border-bottom-color', 'border-collapse', 'border-color',
'border-left-color', 'border-right-color', 'border-top-color', 'clear',
'color', 'cursor', 'direction', 'display', 'elevation', 'float', 'font',
'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight',
'height', 'letter-spacing', 'line-height', 'overflow', 'pause',
'pause-after', 'pause-before', 'pitch', 'pitch-range', 'richness',
'speak', 'speak-header', 'speak-numeral', 'speak-punctuation',
'speech-rate', 'stress', 'text-align', 'text-decoration', 'text-indent',
'unicode-bidi', 'vertical-align', 'voice-family', 'volume',
'white-space', 'width']
acceptable_css_keywords = ['auto', 'aqua', 'black', 'block', 'blue',
'bold', 'both', 'bottom', 'brown', 'center', 'collapse', 'dashed',
'dotted', 'fuchsia', 'gray', 'green', '!important', 'italic', 'left',
'lime', 'maroon', 'medium', 'none', 'navy', 'normal', 'nowrap', 'olive',
'pointer', 'purple', 'red', 'right', 'solid', 'silver', 'teal', 'top',
'transparent', 'underline', 'white', 'yellow']
acceptable_svg_properties = ['fill', 'fill-opacity', 'fill-rule',
'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin',
'stroke-opacity']
acceptable_protocols = ['ed2k', 'ftp', 'http', 'https', 'irc',
'mailto', 'news', 'gopher', 'nntp', 'telnet', 'webcal',
'xmpp', 'callto', 'feed', 'urn', 'aim', 'rsync', 'tag',
'ssh', 'sftp', 'rtsp', 'afs', 'data']
acceptable_content_types = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp', 'text/plain']
# subclasses may define their own versions of these constants
allowed_elements = acceptable_elements + mathml_elements + svg_elements
allowed_attributes = acceptable_attributes + mathml_attributes + svg_attributes
allowed_css_properties = acceptable_css_properties
allowed_css_keywords = acceptable_css_keywords
allowed_svg_properties = acceptable_svg_properties
allowed_protocols = acceptable_protocols
allowed_content_types = acceptable_content_types
# Sanitize the +html+, escaping all elements not in ALLOWED_ELEMENTS, and
# stripping out all # attributes not in ALLOWED_ATTRIBUTES. Style
# attributes are parsed, and a restricted set, # specified by
# ALLOWED_CSS_PROPERTIES and ALLOWED_CSS_KEYWORDS, are allowed through.
# attributes in ATTR_VAL_IS_URI are scanned, and only URI schemes specified
# in ALLOWED_PROTOCOLS are allowed.
#
# sanitize_html('<script> do_nasty_stuff() </script>')
# => <script> do_nasty_stuff() </script>
# sanitize_html('<a href="javascript: sucker();">Click here for $100</a>')
# => <a>Click here for $100</a>
def sanitize_token(self, token):
# accommodate filters which use token_type differently
token_type = token["type"]
if token_type in list(tokenTypes.keys()):
token_type = tokenTypes[token_type]
if token_type in (tokenTypes["StartTag"], tokenTypes["EndTag"],
tokenTypes["EmptyTag"]):
if token["name"] in self.allowed_elements:
return self.allowed_token(token, token_type)
else:
return self.disallowed_token(token, token_type)
elif token_type == tokenTypes["Comment"]:
pass
else:
return token
def allowed_token(self, token, token_type):
if "data" in token:
attrs = dict([(name, val) for name, val in
token["data"][::-1]
if name in self.allowed_attributes])
for attr in self.attr_val_is_uri:
if attr not in attrs:
continue
val_unescaped = re.sub("[`\000-\040\177-\240\s]+", '',
unescape(attrs[attr])).lower()
# remove replacement characters from unescaped characters
val_unescaped = val_unescaped.replace("\ufffd", "")
uri = urlparse.urlparse(val_unescaped)
if uri:
if uri.scheme not in self.allowed_protocols:
del attrs[attr]
if uri.scheme == 'data':
m = content_type_rgx.match(uri.path)
if not m:
del attrs[attr]
if m.group('content_type') not in self.allowed_content_types:
del attrs[attr]
for attr in self.svg_attr_val_allows_ref:
if attr in attrs:
attrs[attr] = re.sub(r'url\s*\(\s*[^#\s][^)]+?\)',
' ',
unescape(attrs[attr]))
if (token["name"] in self.svg_allow_local_href and
'xlink:href' in attrs and re.search('^\s*[^#\s].*',
attrs['xlink:href'])):
del attrs['xlink:href']
if 'style' in attrs:
attrs['style'] = self.sanitize_css(attrs['style'])
token["data"] = [[name, val] for name, val in list(attrs.items())]
return token
def disallowed_token(self, token, token_type):
if token_type == tokenTypes["EndTag"]:
token["data"] = "</%s>" % token["name"]
elif token["data"]:
attrs = ''.join([' %s="%s"' % (k, escape(v)) for k, v in token["data"]])
token["data"] = "<%s%s>" % (token["name"], attrs)
else:
token["data"] = "<%s>" % token["name"]
if token.get("selfClosing"):
token["data"] = token["data"][:-1] + "/>"
if token["type"] in list(tokenTypes.keys()):
token["type"] = "Characters"
else:
token["type"] = tokenTypes["Characters"]
del token["name"]
return token
def sanitize_css(self, style):
# disallow urls
style = re.compile('url\s*\(\s*[^\s)]+?\s*\)\s*').sub(' ', style)
# gauntlet
if not re.match("""^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$""", style):
return ''
if not re.match("^\s*([-\w]+\s*:[^:;]*(;\s*|$))*$", style):
return ''
clean = []
for prop, value in re.findall("([-\w]+)\s*:\s*([^:;]*)", style):
if not value:
continue
if prop.lower() in self.allowed_css_properties:
clean.append(prop + ': ' + value + ';')
elif prop.split('-')[0].lower() in ['background', 'border', 'margin',
'padding']:
for keyword in value.split():
if keyword not in self.acceptable_css_keywords and \
not re.match("^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$", keyword):
break
else:
clean.append(prop + ': ' + value + ';')
elif prop.lower() in self.allowed_svg_properties:
clean.append(prop + ': ' + value + ';')
return ' '.join(clean)
class HTMLSanitizer(HTMLTokenizer, HTMLSanitizerMixin):
def __init__(self, stream, encoding=None, parseMeta=True, useChardet=True,
lowercaseElementName=False, lowercaseAttrName=False, parser=None):
# Change case matching defaults as we only output lowercase html anyway
# This solution doesn't seem ideal...
HTMLTokenizer.__init__(self, stream, encoding, parseMeta, useChardet,
lowercaseElementName, lowercaseAttrName, parser=parser)
def __iter__(self):
for token in HTMLTokenizer.__iter__(self):
token = self.sanitize_token(token)
if token:
yield token
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
12,
22221,
199,
504,
3816,
14,
4912,
492,
4011,
63,
1122,
465,
7097,
199,
199,
504,
1275,
13771,
492,
4163,
21782,
199,
504,
1275,
5559,
492,
10042,
421,
199,
1317,
63,
466,
63,
12430,
88,
275,
295,
14,
2014,
8,
82,
2344,
3044,
7167,
3044,
327,
9814,
282,
1564,
730,
665,
3578,
23220,
466,
30,
3044,
7558,
48,
28,
1317,
63,
466,
30,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
32455,
15,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
14,
11896,
3044,
327,
9814,
1263,
4528,
663,
436,
2644,
3044,
16697,
5169,
27,
6043,
29,
5169,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
11896,
5169,
27,
5169,
1095,
772,
430,
17076,
639,
1204,
5169,
27,
5169,
1095,
772,
22119,
5169,
27,
6043,
29,
5169,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
430,
17076,
3044,
327,
16269,
314,
4618,
365,
666,
3044,
2360,
2795,
3044,
2672,
3044,
21281,
2892,
295,
14,
16075,
9,
421,
199,
533,
4163,
51,
9385,
2282,
4256,
8,
785,
304,
272,
408,
25092,
13362,
402,
26223,
11,
18568,
1698,
11,
19366,
436,
402,
8308,
3449,
3004,
1041,
339,
14712,
63,
5527,
275,
788,
65,
297,
283,
20787,
297,
283,
645,
2641,
12828,
297,
283,
1562,
297,
283,
6789,
297,
2574,
283,
6934,
297,
283,
28135,
297,
283,
8130,
297,
283,
66,
297,
283,
5076,
297,
283,
28623,
297,
283,
3289,
297,
283,
3887,
297,
2574,
283,
7682,
297,
283,
13410,
297,
283,
4218,
297,
283,
25171,
297,
283,
600,
297,
283,
761,
297,
283,
761,
923,
297,
2574,
283,
1531,
297,
283,
576,
3825,
297,
283,
4616,
26279,
297,
283,
617,
297,
283,
2264,
297,
283,
5087,
297,
283,
1587,
78,
297,
2574,
283,
7196,
297,
283,
694,
297,
283,
3015,
297,
283,
5030,
297,
283,
3583,
297,
283,
5633,
297,
283,
1430,
13,
1365,
297,
283,
698,
409,
297,
2574,
283,
592,
13410,
297,
283,
8941,
297,
283,
12781,
297,
283,
4246,
297,
283,
964,
297,
283,
1291,
297,
283,
72,
17,
297,
2574,
283,
72,
18,
297,
283,
72,
19,
297,
283,
72,
20,
297,
283,
72,
21,
297,
283,
72,
22,
297,
283,
6271,
297,
283,
73,
297,
283,
4060,
297,
283,
1210,
297,
283,
3617,
297,
2574,
283,
498,
2268,
297,
283,
75,
3691,
297,
283,
1302,
297,
283,
10231,
297,
283,
317,
297,
283,
77,
297,
283,
1130,
297,
283,
4470,
297,
283,
10011,
297,
2574,
283,
3029,
761,
297,
283,
10927,
297,
283,
14743,
5700,
297,
283,
393,
297,
283,
1199,
297,
283,
2992,
923,
297,
283,
1422,
297,
2574,
283,
80,
297,
283,
657,
297,
283,
5734,
297,
283,
81,
297,
283,
83,
297,
283,
16557,
297,
283,
2792,
297,
283,
2416,
297,
2574,
283,
7241,
297,
283,
14990,
297,
283,
1365,
297,
283,
3770,
2247,
297,
283,
3751,
297,
283,
26845,
297,
283,
9370,
297,
2574,
283,
954,
297,
283,
1961,
297,
283,
1224,
297,
283,
17847,
297,
283,
2076,
297,
283,
20895,
297,
283,
521,
297,
283,
84,
11407,
297,
2574,
283,
273,
297,
283,
21519,
297,
283,
454,
297,
283,
6215,
297,
283,
85,
297,
283,
348,
297,
283,
1391,
297,
283,
3722,
418,
339,
3473,
757,
63,
5527,
275,
788,
391,
414,
297,
283,
3442,
297,
283,
2626,
451,
297,
283,
77,
10865,
297,
283,
2664,
297,
2432,
283,
596,
1141,
6429,
297,
283,
10344,
297,
283,
573,
297,
283,
573,
422,
297,
283,
311,
3270,
297,
283,
311,
19262,
3151,
297,
2432,
283,
311,
470,
1669,
83,
297,
283,
77,
1231,
297,
283,
77,
1143,
297,
283,
706,
1142,
297,
283,
706,
81,
2591,
297,
283,
77,
2487,
297,
283,
706,
456,
297,
2432,
283,
706,
456,
1961,
297,
283,
706,
384,
297,
283,
77,
1224,
297,
283,
2037,
68,
297,
283,
77,
505,
297,
283,
77,
454,
297,
283,
77,
7138,
297,
2432,
283,
32368,
271,
293,
422,
297,
283,
3592,
418,
339,
21218,
63,
5527,
275,
788,
65,
297,
283,
27062,
297,
283,
27062,
4117,
297,
283,
27062,
24875,
297,
490,
283,
27062,
6939,
297,
283,
7548,
2042,
297,
283,
11001,
297,
283,
8710,
297,
283,
3257,
297,
283,
16514,
261,
297,
490,
283,
4246,
13,
1409,
297,
283,
4246,
13,
1409,
13,
354,
297,
283,
4246,
13,
1409,
13,
2164,
297,
283,
71,
297,
283,
13723,
297,
283,
72,
30136,
297,
490,
283,
6676,
9942,
297,
283,
604,
297,
283,
4211,
297,
283,
2343,
297,
283,
4752,
13,
13723,
297,
490,
283,
8075,
297,
283,
515,
297,
283,
16295,
297,
283,
6023,
604,
297,
283,
12841,
279,
9942,
297,
283,
1201,
297,
490,
283,
409,
297,
283,
2379,
297,
283,
10273,
297,
283,
5656,
297,
283,
505,
297,
283,
1213,
297,
283,
84,
3751,
297,
283,
1180,
418,
339,
14712,
63,
2987,
275,
788,
20787,
297,
283,
5694,
297,
283,
5694,
13,
6043,
297,
283,
2732,
498,
297,
2490,
283,
1287,
297,
283,
5743,
297,
283,
4478,
297,
283,
29695,
297,
283,
2495,
12283,
297,
283,
3127,
297,
2490,
283,
7451,
297,
283,
7358,
297,
283,
28710,
297,
283,
6856,
3282,
297,
283,
8665,
297,
2490,
283,
8665,
2326,
297,
283,
8665,
761,
2181,
1096,
297,
283,
8665,
2326,
4040,
297,
283,
3018,
475,
311,
4095,
297,
2490,
283,
3890,
8358,
297,
283,
9041,
29277,
297,
283,
335,
297,
283,
13911,
297,
283,
1560,
297,
283,
1560,
1997,
297,
2490,
283,
335,
1997,
297,
283,
6043,
297,
283,
10718,
297,
283,
25171,
297,
283,
533,
297,
283,
3584,
297,
283,
2326,
297,
2490,
283,
4574,
297,
283,
4574,
10384,
297,
283,
23046,
297,
283,
388,
724,
266,
328,
1224,
297,
283,
13658,
297,
283,
8032,
297,
2490,
283,
576,
297,
283,
576,
17511,
297,
283,
576,
1606,
890,
297,
283,
11563,
1195,
297,
283,
2083,
297,
283,
885,
297,
2490,
283,
5814,
297,
283,
694,
297,
283,
7011,
297,
283,
14479,
16725,
297,
283,
8161,
561,
1195,
297,
283,
287,
3667,
297,
283,
500,
297,
2490,
283,
1409,
297,
283,
509,
297,
283,
964,
297,
283,
1943,
297,
283
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
295,
199,
504,
2748,
14,
14338,
14,
14338,
1208,
492,
4772,
12,
22221,
199,
504,
3816,
14,
4912,
492,
4011,
63,
1122,
465,
7097,
199,
199,
504,
1275,
13771,
492,
4163,
21782,
199,
504,
1275,
5559,
492,
10042,
421,
199,
1317,
63,
466,
63,
12430,
88,
275,
295,
14,
2014,
8,
82,
2344,
3044,
7167,
3044,
327,
9814,
282,
1564,
730,
665,
3578,
23220,
466,
30,
3044,
7558,
48,
28,
1317,
63,
466,
30,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
32455,
15,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
14,
11896,
3044,
327,
9814,
1263,
4528,
663,
436,
2644,
3044,
16697,
5169,
27,
6043,
29,
5169,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
11896,
5169,
27,
5169,
1095,
772,
430,
17076,
639,
1204,
5169,
27,
5169,
1095,
772,
22119,
5169,
27,
6043,
29,
5169,
1988,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
430,
17076,
3044,
327,
16269,
314,
4618,
365,
666,
3044,
2360,
2795,
3044,
2672,
3044,
21281,
2892,
295,
14,
16075,
9,
421,
199,
533,
4163,
51,
9385,
2282,
4256,
8,
785,
304,
272,
408,
25092,
13362,
402,
26223,
11,
18568,
1698,
11,
19366,
436,
402,
8308,
3449,
3004,
1041,
339,
14712,
63,
5527,
275,
788,
65,
297,
283,
20787,
297,
283,
645,
2641,
12828,
297,
283,
1562,
297,
283,
6789,
297,
2574,
283,
6934,
297,
283,
28135,
297,
283,
8130,
297,
283,
66,
297,
283,
5076,
297,
283,
28623,
297,
283,
3289,
297,
283,
3887,
297,
2574,
283,
7682,
297,
283,
13410,
297,
283,
4218,
297,
283,
25171,
297,
283,
600,
297,
283,
761,
297,
283,
761,
923,
297,
2574,
283,
1531,
297,
283,
576,
3825,
297,
283,
4616,
26279,
297,
283,
617,
297,
283,
2264,
297,
283,
5087,
297,
283,
1587,
78,
297,
2574,
283,
7196,
297,
283,
694,
297,
283,
3015,
297,
283,
5030,
297,
283,
3583,
297,
283,
5633,
297,
283,
1430,
13,
1365,
297,
283,
698,
409,
297,
2574,
283,
592,
13410,
297,
283,
8941,
297,
283,
12781,
297,
283,
4246,
297,
283,
964,
297,
283,
1291,
297,
283,
72,
17,
297,
2574,
283,
72,
18,
297,
283,
72,
19,
297,
283,
72,
20,
297,
283,
72,
21,
297,
283,
72,
22,
297,
283,
6271,
297,
283,
73,
297,
283,
4060,
297,
283,
1210,
297,
283,
3617,
297,
2574,
283,
498,
2268,
297,
283,
75,
3691,
297,
283,
1302,
297,
283,
10231,
297,
283,
317,
297,
283,
77,
297,
283,
1130,
297,
283,
4470,
297,
283,
10011,
297,
2574,
283,
3029,
761,
297,
283,
10927,
297,
283,
14743,
5700,
297,
283,
393,
297,
283,
1199,
297,
283,
2992,
923,
297,
283,
1422,
297,
2574,
283,
80,
297,
283,
657,
297,
283,
5734,
297,
283,
81,
297,
283,
83,
297,
283,
16557,
297,
283,
2792,
297,
283,
2416,
297,
2574,
283,
7241,
297,
283,
14990,
297,
283,
1365,
297,
283,
3770,
2247,
297,
283,
3751,
297,
283,
26845,
297,
283,
9370,
297,
2574,
283,
954,
297,
283,
1961,
297,
283,
1224,
297,
283,
17847,
297,
283,
2076,
297,
283,
20895,
297,
283,
521,
297,
283,
84,
11407,
297,
2574,
283,
273,
297,
283,
21519,
297,
283,
454,
297,
283,
6215,
297,
283,
85,
297,
283,
348,
297,
283,
1391,
297,
283,
3722,
418,
339,
3473,
757,
63,
5527,
275,
788,
391,
414,
297,
283,
3442,
297,
283,
2626,
451,
297,
283,
77,
10865,
297,
283,
2664,
297,
2432,
283,
596,
1141,
6429,
297,
283,
10344,
297,
283,
573,
297,
283,
573,
422,
297,
283,
311,
3270,
297,
283,
311,
19262,
3151,
297,
2432,
283,
311,
470,
1669,
83,
297,
283,
77,
1231,
297,
283,
77,
1143,
297,
283,
706,
1142,
297,
283,
706,
81,
2591,
297,
283,
77,
2487,
297,
283,
706,
456,
297,
2432,
283,
706,
456,
1961,
297,
283,
706,
384,
297,
283,
77,
1224,
297,
283,
2037,
68,
297,
283,
77,
505,
297,
283,
77,
454,
297,
283,
77,
7138,
297,
2432,
283,
32368,
271,
293,
422,
297,
283,
3592,
418,
339,
21218,
63,
5527,
275,
788,
65,
297,
283,
27062,
297,
283,
27062,
4117,
297,
283,
27062,
24875,
297,
490,
283,
27062,
6939,
297,
283,
7548,
2042,
297,
283,
11001,
297,
283,
8710,
297,
283,
3257,
297,
283,
16514,
261,
297,
490,
283,
4246,
13,
1409,
297,
283,
4246,
13,
1409,
13,
354,
297,
283,
4246,
13,
1409,
13,
2164,
297,
283,
71,
297,
283,
13723,
297,
283,
72,
30136,
297,
490,
283,
6676,
9942,
297,
283,
604,
297,
283,
4211,
297,
283,
2343,
297,
283,
4752,
13,
13723,
297,
490,
283,
8075,
297,
283,
515,
297,
283,
16295,
297,
283,
6023,
604,
297,
283,
12841,
279,
9942,
297,
283,
1201,
297,
490,
283,
409,
297,
283,
2379,
297,
283,
10273,
297,
283,
5656,
297,
283,
505,
297,
283,
1213,
297,
283,
84,
3751,
297,
283,
1180,
418,
339,
14712,
63,
2987,
275,
788,
20787,
297,
283,
5694,
297,
283,
5694,
13,
6043,
297,
283,
2732,
498,
297,
2490,
283,
1287,
297,
283,
5743,
297,
283,
4478,
297,
283,
29695,
297,
283,
2495,
12283,
297,
283,
3127,
297,
2490,
283,
7451,
297,
283,
7358,
297,
283,
28710,
297,
283,
6856,
3282,
297,
283,
8665,
297,
2490,
283,
8665,
2326,
297,
283,
8665,
761,
2181,
1096,
297,
283,
8665,
2326,
4040,
297,
283,
3018,
475,
311,
4095,
297,
2490,
283,
3890,
8358,
297,
283,
9041,
29277,
297,
283,
335,
297,
283,
13911,
297,
283,
1560,
297,
283,
1560,
1997,
297,
2490,
283,
335,
1997,
297,
283,
6043,
297,
283,
10718,
297,
283,
25171,
297,
283,
533,
297,
283,
3584,
297,
283,
2326,
297,
2490,
283,
4574,
297,
283,
4574,
10384,
297,
283,
23046,
297,
283,
388,
724,
266,
328,
1224,
297,
283,
13658,
297,
283,
8032,
297,
2490,
283,
576,
297,
283,
576,
17511,
297,
283,
576,
1606,
890,
297,
283,
11563,
1195,
297,
283,
2083,
297,
283,
885,
297,
2490,
283,
5814,
297,
283,
694,
297,
283,
7011,
297,
283,
14479,
16725,
297,
283,
8161,
561,
1195,
297,
283,
287,
3667,
297,
283,
500,
297,
2490,
283,
1409,
297,
283,
509,
297,
283,
964,
297,
283,
1943,
297,
283,
0
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,
1
] |
slevenhagen/odoo-npg
|
addons/sale_mrp/__openerp__.py
|
262
|
1912
|
# -*- 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': 'Sales and MRP Management',
'version': '1.0',
'category': 'Hidden',
'description': """
This module provides facility to the user to install mrp and sales modulesat a time.
====================================================================================
It is basically used when we want to keep track of production orders generated
from sales order. It adds sales name and sales Reference on production order.
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com/page/manufacturing',
'depends': ['mrp', 'sale_stock'],
'data': [
'security/ir.model.access.csv',
'sale_mrp_view.xml',
],
'demo': [],
'test':[
'test/cancellation_propagated.yml',
'test/sale_mrp.yml',
],
'installable': True,
'auto_install': True,
}
# 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,
421,
199,
91,
272,
283,
354,
356,
283,
18220,
436,
603,
18612,
8259,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
14983,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6571,
21395,
370,
314,
922,
370,
3907,
333,
4599,
436,
21702,
4621,
292,
282,
900,
14,
199,
5695,
1280,
532,
199,
199,
7940,
365,
26014,
1202,
1380,
781,
2934,
370,
4215,
4426,
402,
9920,
15460,
4046,
199,
504,
21702,
1865,
14,
2779,
9584,
21702,
536,
436,
21702,
10944,
641,
9920,
1865,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
1237,
7415,
319,
4039,
297,
272,
283,
8912,
356,
788,
17058,
297,
283,
8515,
63,
6088,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
8515,
63,
17058,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
15211,
288,
283,
396,
15,
6406,
2212,
63,
496,
15351,
972,
14,
11714,
297,
288,
283,
396,
15,
8515,
63,
17058,
14,
11714,
297,
12793,
288,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
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
] |
[
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,
421,
199,
91,
272,
283,
354,
356,
283,
18220,
436,
603,
18612,
8259,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
14983,
297,
272,
283,
1802,
356,
408,
199,
2765,
859,
6571,
21395,
370,
314,
922,
370,
3907,
333,
4599,
436,
21702,
4621,
292,
282,
900,
14,
199,
5695,
1280,
532,
199,
199,
7940,
365,
26014,
1202,
1380,
781,
2934,
370,
4215,
4426,
402,
9920,
15460,
4046,
199,
504,
21702,
1865,
14,
2779,
9584,
21702,
536,
436,
21702,
10944,
641,
9920,
1865,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
1237,
7415,
319,
4039,
297,
272,
283,
8912,
356,
788,
17058,
297,
283,
8515,
63,
6088,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
8515,
63,
17058,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
15211,
288,
283,
396,
15,
6406,
2212,
63,
496,
15351,
972,
14,
11714,
297,
288,
283,
396,
15,
8515,
63,
17058,
14,
11714,
297,
12793,
288,
2156,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
715,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ArtsiomCh/tensorflow
|
tensorflow/contrib/distributions/python/ops/normal_conjugate_posteriors.py
|
120
|
5530
|
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""The Normal distribution: conjugate posterior closed form calculations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.ops import math_ops
from tensorflow.python.ops.distributions import normal
def normal_conjugates_known_scale_posterior(prior, scale, s, n):
"""Posterior Normal distribution with conjugate prior on the mean.
This model assumes that `n` observations (with sum `s`) come from a
Normal with unknown mean `loc` (described by the Normal `prior`)
and known variance `scale**2`. The "known scale posterior" is
the distribution of the unknown `loc`.
Accepts a prior Normal distribution object, having parameters
`loc0` and `scale0`, as well as known `scale` values of the predictive
distribution(s) (also assumed Normal),
and statistical estimates `s` (the sum(s) of the observations) and
`n` (the number(s) of observations).
Returns a posterior (also Normal) distribution object, with parameters
`(loc', scale'**2)`, where:
```
mu ~ N(mu', sigma'**2)
sigma'**2 = 1/(1/sigma0**2 + n/sigma**2),
mu' = (mu0/sigma0**2 + s/sigma**2) * sigma'**2.
```
Distribution parameters from `prior`, as well as `scale`, `s`, and `n`.
will broadcast in the case of multidimensional sets of parameters.
Args:
prior: `Normal` object of type `dtype`:
the prior distribution having parameters `(loc0, scale0)`.
scale: tensor of type `dtype`, taking values `scale > 0`.
The known stddev parameter(s).
s: Tensor of type `dtype`. The sum(s) of observations.
n: Tensor of type `int`. The number(s) of observations.
Returns:
A new Normal posterior distribution object for the unknown observation
mean `loc`.
Raises:
TypeError: if dtype of `s` does not match `dtype`, or `prior` is not a
Normal object.
"""
if not isinstance(prior, normal.Normal):
raise TypeError("Expected prior to be an instance of type Normal")
if s.dtype != prior.dtype:
raise TypeError(
"Observation sum s.dtype does not match prior dtype: %s vs. %s"
% (s.dtype, prior.dtype))
n = math_ops.cast(n, prior.dtype)
scale0_2 = math_ops.square(prior.scale)
scale_2 = math_ops.square(scale)
scalep_2 = 1.0/(1/scale0_2 + n/scale_2)
return normal.Normal(
loc=(prior.loc/scale0_2 + s/scale_2) * scalep_2,
scale=math_ops.sqrt(scalep_2))
def normal_conjugates_known_scale_predictive(prior, scale, s, n):
"""Posterior predictive Normal distribution w. conjugate prior on the mean.
This model assumes that `n` observations (with sum `s`) come from a
Normal with unknown mean `loc` (described by the Normal `prior`)
and known variance `scale**2`. The "known scale predictive"
is the distribution of new observations, conditioned on the existing
observations and our prior.
Accepts a prior Normal distribution object, having parameters
`loc0` and `scale0`, as well as known `scale` values of the predictive
distribution(s) (also assumed Normal),
and statistical estimates `s` (the sum(s) of the observations) and
`n` (the number(s) of observations).
Calculates the Normal distribution(s) `p(x | sigma**2)`:
```
p(x | sigma**2) = int N(x | mu, sigma**2)N(mu | prior.loc, prior.scale**2) dmu
= N(x | prior.loc, 1 / (sigma**2 + prior.scale**2))
```
Returns the predictive posterior distribution object, with parameters
`(loc', scale'**2)`, where:
```
sigma_n**2 = 1/(1/sigma0**2 + n/sigma**2),
mu' = (mu0/sigma0**2 + s/sigma**2) * sigma_n**2.
sigma'**2 = sigma_n**2 + sigma**2,
```
Distribution parameters from `prior`, as well as `scale`, `s`, and `n`.
will broadcast in the case of multidimensional sets of parameters.
Args:
prior: `Normal` object of type `dtype`:
the prior distribution having parameters `(loc0, scale0)`.
scale: tensor of type `dtype`, taking values `scale > 0`.
The known stddev parameter(s).
s: Tensor of type `dtype`. The sum(s) of observations.
n: Tensor of type `int`. The number(s) of observations.
Returns:
A new Normal predictive distribution object.
Raises:
TypeError: if dtype of `s` does not match `dtype`, or `prior` is not a
Normal object.
"""
if not isinstance(prior, normal.Normal):
raise TypeError("Expected prior to be an instance of type Normal")
if s.dtype != prior.dtype:
raise TypeError(
"Observation sum s.dtype does not match prior dtype: %s vs. %s"
% (s.dtype, prior.dtype))
n = math_ops.cast(n, prior.dtype)
scale0_2 = math_ops.square(prior.scale)
scale_2 = math_ops.square(scale)
scalep_2 = 1.0/(1/scale0_2 + n/scale_2)
return normal.Normal(
loc=(prior.loc/scale0_2 + s/scale_2) * scalep_2,
scale=math_ops.sqrt(scalep_2 + scale_2))
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
11514,
4084,
26,
27246,
2086,
17514,
6876,
1824,
24258,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
3293,
421,
199,
318,
3293,
63,
14765,
1518,
2335,
63,
3159,
63,
3467,
63,
31228,
8,
13775,
12,
4666,
12,
308,
12,
302,
304,
523,
408,
6981,
17514,
11514,
4084,
543,
27246,
6791,
641,
314,
4615,
14,
819,
961,
1402,
15194,
626,
658,
78,
64,
19739,
334,
1045,
3089,
658,
83,
10522,
11492,
687,
282,
523,
11514,
543,
5809,
4615,
658,
2102,
64,
334,
271,
14922,
701,
314,
11514,
658,
13775,
10522,
523,
436,
6040,
11773,
658,
3467,
538,
18,
2313,
710,
298,
3159,
4666,
2086,
17514,
2,
365,
523,
314,
4084,
402,
314,
5809,
658,
2102,
2313,
819,
15506,
83,
282,
6791,
11514,
4084,
909,
12,
9445,
2633,
523,
658,
2102,
16,
64,
436,
658,
3467,
16,
3559,
465,
5521,
465,
6040,
658,
3467,
64,
1338,
402,
314,
4557,
6648,
523,
4084,
8,
83,
9,
334,
12344,
10826,
11514,
395,
523,
436,
8753,
270,
2652,
23505,
658,
83,
64,
334,
1589,
3089,
8,
83,
9,
402,
314,
19739,
9,
436,
523,
658,
78,
64,
334,
1589,
1329,
8,
83,
9,
402,
19739,
680,
819,
1803,
282,
2086,
17514,
334,
12344,
11514,
9,
4084,
909,
12,
543,
2633,
523,
16918,
2102,
297,
4666,
7,
538,
18,
32124,
2382,
26,
819,
10841,
523,
8504,
6146,
653,
8,
6553,
297,
10819,
7,
538,
18,
9,
523,
10819,
7,
538,
18,
275,
413,
7985,
17,
15,
9412,
16,
538,
18,
435,
302,
15,
9412,
538,
18,
395,
523,
8504,
7,
275,
334,
6553,
16,
15,
9412,
16,
538,
18,
435,
308,
15,
9412,
538,
18,
9,
627,
10819,
7,
538,
18,
14,
523,
10841,
819,
11839,
2633,
687,
658,
13775,
3559,
465,
5521,
465,
658,
3467,
3559,
658,
83,
3559,
436,
658,
78,
2313,
523,
911,
11180,
315,
314,
1930,
402,
3510,
13014,
5951,
402,
2633,
14,
819,
3033,
26,
272,
6791,
26,
658,
6241,
64,
909,
402,
730,
658,
2271,
8340,
489,
314,
6791,
4084,
9445,
2633,
16918,
2102,
16,
12,
4666,
16,
20414,
272,
4666,
26,
2345,
402,
730,
658,
2271,
3559,
16466,
1338,
658,
3467,
690,
378,
2313,
489,
710,
6040,
28052,
2725,
8,
83,
680,
272,
308,
26,
5878,
402,
730,
658,
2271,
2313,
710,
3089,
8,
83,
9,
402,
19739,
14,
272,
302,
26,
5878,
402,
730,
658,
442,
2313,
710,
1329,
8,
83,
9,
402,
19739,
14,
819,
1803,
26,
272,
437,
892,
11514,
2086,
17514,
4084,
909,
367,
314,
5809,
20038,
272,
4615,
658,
2102,
2313,
819,
6218,
26,
272,
3146,
26,
340,
2152,
402,
658,
83,
64,
1630,
440,
1336,
658,
2271,
3559,
503,
658,
13775,
64,
365,
440,
282,
489,
11514,
909,
14,
523,
408,
523,
340,
440,
1228,
8,
13775,
12,
3293,
14,
6241,
304,
272,
746,
3146,
480,
6964,
6791,
370,
506,
376,
1256,
402,
730,
11514,
531,
819,
340,
308,
14,
2271,
1137,
6791,
14,
2271,
26,
272,
746,
3146,
8,
267,
298,
11394,
8213,
3089,
308,
14,
2271,
1630,
440,
1336,
6791,
2152,
26,
450,
83,
8118,
14,
450,
83,
2,
267,
450,
334,
83,
14,
2271,
12,
6791,
14,
2271,
430,
819,
302,
275,
3473,
63,
1483,
14,
2931,
8,
78,
12,
6791,
14,
2271,
9,
523,
4666,
16,
63,
18,
275,
3473,
63,
1483,
14,
9646,
8,
13775,
14,
3467,
9,
523,
4666,
63,
18,
275,
3473,
63,
1483,
14,
9646,
8,
3467,
9,
523,
4666,
80,
63,
18,
275,
413,
14,
16,
7985,
17,
15,
3467,
16,
63,
18,
435,
302,
15,
3467,
63,
18,
9,
523,
372,
3293,
14,
6241,
8,
489,
4355,
2687,
13775,
14,
2102,
15,
3467,
16,
63,
18,
435,
308,
15,
3467,
63,
18,
9,
627,
4666,
80,
63,
18,
12,
489,
4666,
29,
3442,
63,
1483,
14,
5079,
8,
3467,
80,
63,
18,
430,
421,
199,
318,
3293,
63,
14765,
1518,
2335,
63,
3159,
63,
3467,
63,
657,
5000,
857,
8,
13775,
12,
4666,
12,
308,
12,
302,
304,
523,
408,
6981,
17514,
4557,
6648,
11514,
4084,
336,
14,
27246,
6791,
641,
314,
4615,
14,
819,
961,
1402,
15194,
626,
658,
78,
64,
19739,
334,
1045,
3089,
658,
83,
10522,
11492,
687,
282,
523,
11514,
543,
5809,
4615,
658,
2102,
64,
334,
271,
14922,
701,
314,
11514,
658,
13775,
10522,
523,
436,
6040,
11773,
658,
3467,
538,
18,
2313,
710,
298,
3159,
4666,
4557,
6648,
2,
523,
365,
314,
4084,
402,
892,
19739,
12,
5558,
379,
641,
314,
3411,
523,
19739,
436,
4154,
6791,
14,
819,
15506,
83,
282,
6791,
11514,
4084,
909,
12,
9445,
2633,
523,
658,
2102,
16,
64,
436,
658,
3467,
16,
3559,
465,
5521,
465,
6040,
658,
3467,
64,
1338,
402,
314,
4557,
6648,
523,
4084,
8,
83,
9,
334,
12344,
10826,
11514,
395,
523,
436,
8753,
270,
2652,
23505,
658,
83,
64,
334,
1589,
3089,
8,
83,
9,
402,
314,
19739,
9,
436,
523,
658,
78,
64,
334,
1589,
1329,
8,
83,
9,
402,
19739,
680,
819,
28562,
314,
11514,
4084,
8,
83,
9,
658,
80,
8,
88,
1204,
10819,
538,
18,
9,
8340
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
1918,
11514,
4084,
26,
27246,
2086,
17514,
6876,
1824,
24258,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
14,
5613,
492,
3293,
421,
199,
318,
3293,
63,
14765,
1518,
2335,
63,
3159,
63,
3467,
63,
31228,
8,
13775,
12,
4666,
12,
308,
12,
302,
304,
523,
408,
6981,
17514,
11514,
4084,
543,
27246,
6791,
641,
314,
4615,
14,
819,
961,
1402,
15194,
626,
658,
78,
64,
19739,
334,
1045,
3089,
658,
83,
10522,
11492,
687,
282,
523,
11514,
543,
5809,
4615,
658,
2102,
64,
334,
271,
14922,
701,
314,
11514,
658,
13775,
10522,
523,
436,
6040,
11773,
658,
3467,
538,
18,
2313,
710,
298,
3159,
4666,
2086,
17514,
2,
365,
523,
314,
4084,
402,
314,
5809,
658,
2102,
2313,
819,
15506,
83,
282,
6791,
11514,
4084,
909,
12,
9445,
2633,
523,
658,
2102,
16,
64,
436,
658,
3467,
16,
3559,
465,
5521,
465,
6040,
658,
3467,
64,
1338,
402,
314,
4557,
6648,
523,
4084,
8,
83,
9,
334,
12344,
10826,
11514,
395,
523,
436,
8753,
270,
2652,
23505,
658,
83,
64,
334,
1589,
3089,
8,
83,
9,
402,
314,
19739,
9,
436,
523,
658,
78,
64,
334,
1589,
1329,
8,
83,
9,
402,
19739,
680,
819,
1803,
282,
2086,
17514,
334,
12344,
11514,
9,
4084,
909,
12,
543,
2633,
523,
16918,
2102,
297,
4666,
7,
538,
18,
32124,
2382,
26,
819,
10841,
523,
8504,
6146,
653,
8,
6553,
297,
10819,
7,
538,
18,
9,
523,
10819,
7,
538,
18,
275,
413,
7985,
17,
15,
9412,
16,
538,
18,
435,
302,
15,
9412,
538,
18,
395,
523,
8504,
7,
275,
334,
6553,
16,
15,
9412,
16,
538,
18,
435,
308,
15,
9412,
538,
18,
9,
627,
10819,
7,
538,
18,
14,
523,
10841,
819,
11839,
2633,
687,
658,
13775,
3559,
465,
5521,
465,
658,
3467,
3559,
658,
83,
3559,
436,
658,
78,
2313,
523,
911,
11180,
315,
314,
1930,
402,
3510,
13014,
5951,
402,
2633,
14,
819,
3033,
26,
272,
6791,
26,
658,
6241,
64,
909,
402,
730,
658,
2271,
8340,
489,
314,
6791,
4084,
9445,
2633,
16918,
2102,
16,
12,
4666,
16,
20414,
272,
4666,
26,
2345,
402,
730,
658,
2271,
3559,
16466,
1338,
658,
3467,
690,
378,
2313,
489,
710,
6040,
28052,
2725,
8,
83,
680,
272,
308,
26,
5878,
402,
730,
658,
2271,
2313,
710,
3089,
8,
83,
9,
402,
19739,
14,
272,
302,
26,
5878,
402,
730,
658,
442,
2313,
710,
1329,
8,
83,
9,
402,
19739,
14,
819,
1803,
26,
272,
437,
892,
11514,
2086,
17514,
4084,
909,
367,
314,
5809,
20038,
272,
4615,
658,
2102,
2313,
819,
6218,
26,
272,
3146,
26,
340,
2152,
402,
658,
83,
64,
1630,
440,
1336,
658,
2271,
3559,
503,
658,
13775,
64,
365,
440,
282,
489,
11514,
909,
14,
523,
408,
523,
340,
440,
1228,
8,
13775,
12,
3293,
14,
6241,
304,
272,
746,
3146,
480,
6964,
6791,
370,
506,
376,
1256,
402,
730,
11514,
531,
819,
340,
308,
14,
2271,
1137,
6791,
14,
2271,
26,
272,
746,
3146,
8,
267,
298,
11394,
8213,
3089,
308,
14,
2271,
1630,
440,
1336,
6791,
2152,
26,
450,
83,
8118,
14,
450,
83,
2,
267,
450,
334,
83,
14,
2271,
12,
6791,
14,
2271,
430,
819,
302,
275,
3473,
63,
1483,
14,
2931,
8,
78,
12,
6791,
14,
2271,
9,
523,
4666,
16,
63,
18,
275,
3473,
63,
1483,
14,
9646,
8,
13775,
14,
3467,
9,
523,
4666,
63,
18,
275,
3473,
63,
1483,
14,
9646,
8,
3467,
9,
523,
4666,
80,
63,
18,
275,
413,
14,
16,
7985,
17,
15,
3467,
16,
63,
18,
435,
302,
15,
3467,
63,
18,
9,
523,
372,
3293,
14,
6241,
8,
489,
4355,
2687,
13775,
14,
2102,
15,
3467,
16,
63,
18,
435,
308,
15,
3467,
63,
18,
9,
627,
4666,
80,
63,
18,
12,
489,
4666,
29,
3442,
63,
1483,
14,
5079,
8,
3467,
80,
63,
18,
430,
421,
199,
318,
3293,
63,
14765,
1518,
2335,
63,
3159,
63,
3467,
63,
657,
5000,
857,
8,
13775,
12,
4666,
12,
308,
12,
302,
304,
523,
408,
6981,
17514,
4557,
6648,
11514,
4084,
336,
14,
27246,
6791,
641,
314,
4615,
14,
819,
961,
1402,
15194,
626,
658,
78,
64,
19739,
334,
1045,
3089,
658,
83,
10522,
11492,
687,
282,
523,
11514,
543,
5809,
4615,
658,
2102,
64,
334,
271,
14922,
701,
314,
11514,
658,
13775,
10522,
523,
436,
6040,
11773,
658,
3467,
538,
18,
2313,
710,
298,
3159,
4666,
4557,
6648,
2,
523,
365,
314,
4084,
402,
892,
19739,
12,
5558,
379,
641,
314,
3411,
523,
19739,
436,
4154,
6791,
14,
819,
15506,
83,
282,
6791,
11514,
4084,
909,
12,
9445,
2633,
523,
658,
2102,
16,
64,
436,
658,
3467,
16,
3559,
465,
5521,
465,
6040,
658,
3467,
64,
1338,
402,
314,
4557,
6648,
523,
4084,
8,
83,
9,
334,
12344,
10826,
11514,
395,
523,
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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
] |
Mj258/weiboapi
|
srapyDemo/envs/Lib/site-packages/twisted/spread/jelly.py
|
8
|
36158
|
# -*- test-case-name: twisted.test.test_jelly -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
S-expression-based persistence of python objects.
It does something very much like L{Pickle<pickle>}; however, pickle's main goal
seems to be efficiency (both in space and time); jelly's main goals are
security, human readability, and portability to other environments.
This is how Jelly converts various objects to s-expressions.
Boolean::
True --> ['boolean', 'true']
Integer::
1 --> 1
List::
[1, 2] --> ['list', 1, 2]
String::
\"hello\" --> \"hello\"
Float::
2.3 --> 2.3
Dictionary::
{'a': 1, 'b': 'c'} --> ['dictionary', ['b', 'c'], ['a', 1]]
Module::
UserString --> ['module', 'UserString']
Class::
UserString.UserString --> ['class', ['module', 'UserString'], 'UserString']
Function::
string.join --> ['function', 'join', ['module', 'string']]
Instance: s is an instance of UserString.UserString, with a __dict__
{'data': 'hello'}::
[\"UserString.UserString\", ['dictionary', ['data', 'hello']]]
Class Method: UserString.UserString.center::
['method', 'center', ['None'], ['class', ['module', 'UserString'],
'UserString']]
Instance Method: s.center, where s is an instance of UserString.UserString::
['method', 'center', ['instance', ['reference', 1, ['class',
['module', 'UserString'], 'UserString']], ['dictionary', ['data', 'd']]],
['dereference', 1]]
The C{set} builtin and the C{sets.Set} class are serialized to the same
thing, and unserialized to C{set} if available, else to C{sets.Set}. It means
that there's a possibility of type switching in the serialization process. The
solution is to always use C{set}.
The same rule applies for C{frozenset} and C{sets.ImmutableSet}.
@author: Glyph Lefkowitz
"""
# System Imports
import pickle
import types
import warnings
import decimal
from functools import reduce
from types import StringType
from types import IntType
from types import TupleType
from types import ListType
from types import LongType
from types import FloatType
from types import FunctionType
from types import MethodType
from types import ModuleType
from types import DictionaryType
from types import InstanceType
from types import NoneType
from types import ClassType
import copy
import datetime
from types import BooleanType
try:
# Filter out deprecation warning for Python >= 2.6
warnings.filterwarnings("ignore", category=DeprecationWarning,
message="the sets module is deprecated", append=True)
import sets as _sets
finally:
warnings.filters.pop()
from zope.interface import implementer
# Twisted Imports
from twisted.python.compat import unicode
from twisted.python.reflect import namedObject, qual
from twisted.persisted.crefutil import NotKnown, _Tuple, _InstanceMethod
from twisted.persisted.crefutil import _DictKeyAndValue, _Dereference
from twisted.persisted.crefutil import _Container
from twisted.spread.interfaces import IJellyable, IUnjellyable
from twisted.python.deprecate import deprecatedModuleAttribute
from twisted.python.versions import Version
DictTypes = (DictionaryType,)
None_atom = "None" # N
# code
class_atom = "class" # c
module_atom = "module" # m
function_atom = "function" # f
# references
dereference_atom = 'dereference' # D
persistent_atom = 'persistent' # p
reference_atom = 'reference' # r
# mutable collections
dictionary_atom = "dictionary" # d
list_atom = 'list' # l
set_atom = 'set'
# immutable collections
# (assignment to __dict__ and __class__ still might go away!)
tuple_atom = "tuple" # t
instance_atom = 'instance' # i
frozenset_atom = 'frozenset'
deprecatedModuleAttribute(
Version("Twisted", 15, 0, 0),
"instance_atom is unused within Twisted.",
"twisted.spread.jelly", "instance_atom")
# errors
unpersistable_atom = "unpersistable"# u
unjellyableRegistry = {}
unjellyableFactoryRegistry = {}
_NO_STATE = object()
def _newInstance(cls, state=_NO_STATE):
"""
Make a new instance of a class without calling its __init__ method.
Supports both new- and old-style classes.
@param state: A C{dict} used to update C{inst.__dict__} or C{_NO_STATE}
to skip this part of initialization.
@return: A new instance of C{cls}.
"""
if not isinstance(cls, types.ClassType):
# new-style
inst = cls.__new__(cls)
if state is not _NO_STATE:
inst.__dict__.update(state) # Copy 'instance' behaviour
else:
if state is not _NO_STATE:
inst = InstanceType(cls, state)
else:
inst = InstanceType(cls)
return inst
def _maybeClass(classnamep):
try:
object
except NameError:
isObject = 0
else:
isObject = isinstance(classnamep, type)
if isinstance(classnamep, ClassType) or isObject:
return qual(classnamep)
return classnamep
def setUnjellyableForClass(classname, unjellyable):
"""
Set which local class will represent a remote type.
If you have written a Copyable class that you expect your client to be
receiving, write a local "copy" class to represent it, then call::
jellier.setUnjellyableForClass('module.package.Class', MyCopier).
Call this at the module level immediately after its class
definition. MyCopier should be a subclass of RemoteCopy.
The classname may be a special tag returned by
'Copyable.getTypeToCopyFor' rather than an actual classname.
This call is also for cached classes, since there will be no
overlap. The rules are the same.
"""
global unjellyableRegistry
classname = _maybeClass(classname)
unjellyableRegistry[classname] = unjellyable
globalSecurity.allowTypes(classname)
def setUnjellyableFactoryForClass(classname, copyFactory):
"""
Set the factory to construct a remote instance of a type::
jellier.setUnjellyableFactoryForClass('module.package.Class', MyFactory)
Call this at the module level immediately after its class definition.
C{copyFactory} should return an instance or subclass of
L{RemoteCopy<pb.RemoteCopy>}.
Similar to L{setUnjellyableForClass} except it uses a factory instead
of creating an instance.
"""
global unjellyableFactoryRegistry
classname = _maybeClass(classname)
unjellyableFactoryRegistry[classname] = copyFactory
globalSecurity.allowTypes(classname)
def setUnjellyableForClassTree(module, baseClass, prefix=None):
"""
Set all classes in a module derived from C{baseClass} as copiers for
a corresponding remote class.
When you have a heirarchy of Copyable (or Cacheable) classes on one
side, and a mirror structure of Copied (or RemoteCache) classes on the
other, use this to setUnjellyableForClass all your Copieds for the
Copyables.
Each copyTag (the \"classname\" argument to getTypeToCopyFor, and
what the Copyable's getTypeToCopyFor returns) is formed from
adding a prefix to the Copied's class name. The prefix defaults
to module.__name__. If you wish the copy tag to consist of solely
the classname, pass the empty string \'\'.
@param module: a module object from which to pull the Copied classes.
(passing sys.modules[__name__] might be useful)
@param baseClass: the base class from which all your Copied classes derive.
@param prefix: the string prefixed to classnames to form the
unjellyableRegistry.
"""
if prefix is None:
prefix = module.__name__
if prefix:
prefix = "%s." % prefix
for i in dir(module):
i_ = getattr(module, i)
if type(i_) == types.ClassType:
if issubclass(i_, baseClass):
setUnjellyableForClass('%s%s' % (prefix, i), i_)
def getInstanceState(inst, jellier):
"""
Utility method to default to 'normal' state rules in serialization.
"""
if hasattr(inst, "__getstate__"):
state = inst.__getstate__()
else:
state = inst.__dict__
sxp = jellier.prepare(inst)
sxp.extend([qual(inst.__class__), jellier.jelly(state)])
return jellier.preserve(inst, sxp)
def setInstanceState(inst, unjellier, jellyList):
"""
Utility method to default to 'normal' state rules in unserialization.
"""
state = unjellier.unjelly(jellyList[1])
if hasattr(inst, "__setstate__"):
inst.__setstate__(state)
else:
inst.__dict__ = state
return inst
class Unpersistable:
"""
This is an instance of a class that comes back when something couldn't be
unpersisted.
"""
def __init__(self, reason):
"""
Initialize an unpersistable object with a descriptive C{reason} string.
"""
self.reason = reason
def __repr__(self):
return "Unpersistable(%s)" % repr(self.reason)
@implementer(IJellyable)
class Jellyable:
"""
Inherit from me to Jelly yourself directly with the `getStateFor'
convenience method.
"""
def getStateFor(self, jellier):
return self.__dict__
def jellyFor(self, jellier):
"""
@see: L{twisted.spread.interfaces.IJellyable.jellyFor}
"""
sxp = jellier.prepare(self)
sxp.extend([
qual(self.__class__),
jellier.jelly(self.getStateFor(jellier))])
return jellier.preserve(self, sxp)
@implementer(IUnjellyable)
class Unjellyable:
"""
Inherit from me to Unjelly yourself directly with the
C{setStateFor} convenience method.
"""
def setStateFor(self, unjellier, state):
self.__dict__ = state
def unjellyFor(self, unjellier, jellyList):
"""
Perform the inverse operation of L{Jellyable.jellyFor}.
@see: L{twisted.spread.interfaces.IUnjellyable.unjellyFor}
"""
state = unjellier.unjelly(jellyList[1])
self.setStateFor(unjellier, state)
return self
class _Jellier:
"""
(Internal) This class manages state for a call to jelly()
"""
def __init__(self, taster, persistentStore, invoker):
"""
Initialize.
"""
self.taster = taster
# `preserved' is a dict of previously seen instances.
self.preserved = {}
# `cooked' is a dict of previously backreferenced instances to their
# `ref' lists.
self.cooked = {}
self.cooker = {}
self._ref_id = 1
self.persistentStore = persistentStore
self.invoker = invoker
def _cook(self, object):
"""
(internal) Backreference an object.
Notes on this method for the hapless future maintainer: If I've already
gone through the prepare/preserve cycle on the specified object (it is
being referenced after the serializer is \"done with\" it, e.g. this
reference is NOT circular), the copy-in-place of aList is relevant,
since the list being modified is the actual, pre-existing jelly
expression that was returned for that object. If not, it's technically
superfluous, since the value in self.preserved didn't need to be set,
but the invariant that self.preserved[id(object)] is a list is
convenient because that means we don't have to test and create it or
not create it here, creating fewer code-paths. that's why
self.preserved is always set to a list.
Sorry that this code is so hard to follow, but Python objects are
tricky to persist correctly. -glyph
"""
aList = self.preserved[id(object)]
newList = copy.copy(aList)
# make a new reference ID
refid = self._ref_id
self._ref_id = self._ref_id + 1
# replace the old list in-place, so that we don't have to track the
# previous reference to it.
aList[:] = [reference_atom, refid, newList]
self.cooked[id(object)] = [dereference_atom, refid]
return aList
def prepare(self, object):
"""
(internal) Create a list for persisting an object to. This will allow
backreferences to be made internal to the object. (circular
references).
The reason this needs to happen is that we don't generate an ID for
every object, so we won't necessarily know which ID the object will
have in the future. When it is 'cooked' ( see _cook ), it will be
assigned an ID, and the temporary placeholder list created here will be
modified in-place to create an expression that gives this object an ID:
[reference id# [object-jelly]].
"""
# create a placeholder list to be preserved
self.preserved[id(object)] = []
# keep a reference to this object around, so it doesn't disappear!
# (This isn't always necessary, but for cases where the objects are
# dynamically generated by __getstate__ or getStateToCopyFor calls, it
# is; id() will return the same value for a different object if it gets
# garbage collected. This may be optimized later.)
self.cooker[id(object)] = object
return []
def preserve(self, object, sexp):
"""
(internal) Mark an object's persistent list for later referral.
"""
# if I've been cooked in the meanwhile,
if id(object) in self.cooked:
# replace the placeholder empty list with the real one
self.preserved[id(object)][2] = sexp
# but give this one back.
sexp = self.preserved[id(object)]
else:
self.preserved[id(object)] = sexp
return sexp
constantTypes = {types.StringType : 1, types.IntType : 1,
types.FloatType : 1, types.LongType : 1}
def _checkMutable(self,obj):
objId = id(obj)
if objId in self.cooked:
return self.cooked[objId]
if objId in self.preserved:
self._cook(obj)
return self.cooked[objId]
def jelly(self, obj):
if isinstance(obj, Jellyable):
preRef = self._checkMutable(obj)
if preRef:
return preRef
return obj.jellyFor(self)
objType = type(obj)
if self.taster.isTypeAllowed(qual(objType)):
# "Immutable" Types
if ((objType is StringType) or
(objType is IntType) or
(objType is LongType) or
(objType is FloatType)):
return obj
elif objType is MethodType:
return ["method",
obj.im_func.__name__,
self.jelly(obj.im_self),
self.jelly(obj.im_class)]
elif objType is unicode:
return ['unicode', obj.encode('UTF-8')]
elif objType is NoneType:
return ['None']
elif objType is FunctionType:
name = obj.__name__
return ['function', str(pickle.whichmodule(obj, obj.__name__))
+ '.' +
name]
elif objType is ModuleType:
return ['module', obj.__name__]
elif objType is BooleanType:
return ['boolean', obj and 'true' or 'false']
elif objType is datetime.datetime:
if obj.tzinfo:
raise NotImplementedError(
"Currently can't jelly datetime objects with tzinfo")
return ['datetime', '%s %s %s %s %s %s %s' % (
obj.year, obj.month, obj.day, obj.hour,
obj.minute, obj.second, obj.microsecond)]
elif objType is datetime.time:
if obj.tzinfo:
raise NotImplementedError(
"Currently can't jelly datetime objects with tzinfo")
return ['time', '%s %s %s %s' % (obj.hour, obj.minute,
obj.second, obj.microsecond)]
elif objType is datetime.date:
return ['date', '%s %s %s' % (obj.year, obj.month, obj.day)]
elif objType is datetime.timedelta:
return ['timedelta', '%s %s %s' % (obj.days, obj.seconds,
obj.microseconds)]
elif objType is ClassType or issubclass(objType, type):
return ['class', qual(obj)]
elif objType is decimal.Decimal:
return self.jelly_decimal(obj)
else:
preRef = self._checkMutable(obj)
if preRef:
return preRef
# "Mutable" Types
sxp = self.prepare(obj)
if objType is ListType:
sxp.extend(self._jellyIterable(list_atom, obj))
elif objType is TupleType:
sxp.extend(self._jellyIterable(tuple_atom, obj))
elif objType in DictTypes:
sxp.append(dictionary_atom)
for key, val in obj.items():
sxp.append([self.jelly(key), self.jelly(val)])
elif objType is set or objType is _sets.Set:
sxp.extend(self._jellyIterable(set_atom, obj))
elif objType is frozenset or objType is _sets.ImmutableSet:
sxp.extend(self._jellyIterable(frozenset_atom, obj))
else:
className = qual(obj.__class__)
persistent = None
if self.persistentStore:
persistent = self.persistentStore(obj, self)
if persistent is not None:
sxp.append(persistent_atom)
sxp.append(persistent)
elif self.taster.isClassAllowed(obj.__class__):
sxp.append(className)
if hasattr(obj, "__getstate__"):
state = obj.__getstate__()
else:
state = obj.__dict__
sxp.append(self.jelly(state))
else:
self.unpersistable(
"instance of class %s deemed insecure" %
qual(obj.__class__), sxp)
return self.preserve(obj, sxp)
else:
if objType is InstanceType:
raise InsecureJelly("Class not allowed for instance: %s %s" %
(obj.__class__, obj))
raise InsecureJelly("Type not allowed for object: %s %s" %
(objType, obj))
def _jellyIterable(self, atom, obj):
"""
Jelly an iterable object.
@param atom: the identifier atom of the object.
@type atom: C{str}
@param obj: any iterable object.
@type obj: C{iterable}
@return: a generator of jellied data.
@rtype: C{generator}
"""
yield atom
for item in obj:
yield self.jelly(item)
def jelly_decimal(self, d):
"""
Jelly a decimal object.
@param d: a decimal object to serialize.
@type d: C{decimal.Decimal}
@return: jelly for the decimal object.
@rtype: C{list}
"""
sign, guts, exponent = d.as_tuple()
value = reduce(lambda left, right: left * 10 + right, guts)
if sign:
value = -value
return ['decimal', value, exponent]
def unpersistable(self, reason, sxp=None):
"""
(internal) Returns an sexp: (unpersistable "reason"). Utility method
for making note that a particular object could not be serialized.
"""
if sxp is None:
sxp = []
sxp.append(unpersistable_atom)
sxp.append(reason)
return sxp
class _Unjellier:
def __init__(self, taster, persistentLoad, invoker):
self.taster = taster
self.persistentLoad = persistentLoad
self.references = {}
self.postCallbacks = []
self.invoker = invoker
def unjellyFull(self, obj):
o = self.unjelly(obj)
for m in self.postCallbacks:
m()
return o
def unjelly(self, obj):
if type(obj) is not types.ListType:
return obj
jelType = obj[0]
if not self.taster.isTypeAllowed(jelType):
raise InsecureJelly(jelType)
regClass = unjellyableRegistry.get(jelType)
if regClass is not None:
if isinstance(regClass, ClassType):
inst = _Dummy() # XXX chomp, chomp
inst.__class__ = regClass
method = inst.unjellyFor
elif isinstance(regClass, type):
# regClass.__new__ does not call regClass.__init__
inst = regClass.__new__(regClass)
method = inst.unjellyFor
else:
method = regClass # this is how it ought to be done
val = method(self, obj)
if hasattr(val, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return val
regFactory = unjellyableFactoryRegistry.get(jelType)
if regFactory is not None:
state = self.unjelly(obj[1])
inst = regFactory(state)
if hasattr(inst, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return inst
thunk = getattr(self, '_unjelly_%s'%jelType, None)
if thunk is not None:
ret = thunk(obj[1:])
else:
nameSplit = jelType.split('.')
modName = '.'.join(nameSplit[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly(
"Module %s not allowed (in type %s)." % (modName, jelType))
clz = namedObject(jelType)
if not self.taster.isClassAllowed(clz):
raise InsecureJelly("Class %s not allowed." % jelType)
if hasattr(clz, "__setstate__"):
ret = _newInstance(clz)
state = self.unjelly(obj[1])
ret.__setstate__(state)
else:
state = self.unjelly(obj[1])
ret = _newInstance(clz, state)
if hasattr(clz, 'postUnjelly'):
self.postCallbacks.append(ret.postUnjelly)
return ret
def _unjelly_None(self, exp):
return None
def _unjelly_unicode(self, exp):
return unicode(exp[0], "UTF-8")
def _unjelly_decimal(self, exp):
"""
Unjelly decimal objects.
"""
value = exp[0]
exponent = exp[1]
if value < 0:
sign = 1
else:
sign = 0
guts = decimal.Decimal(value).as_tuple()[1]
return decimal.Decimal((sign, guts, exponent))
def _unjelly_boolean(self, exp):
if BooleanType:
assert exp[0] in ('true', 'false')
return exp[0] == 'true'
else:
return Unpersistable("Could not unpersist boolean: %s" % (exp[0],))
def _unjelly_datetime(self, exp):
return datetime.datetime(*map(int, exp[0].split()))
def _unjelly_date(self, exp):
return datetime.date(*map(int, exp[0].split()))
def _unjelly_time(self, exp):
return datetime.time(*map(int, exp[0].split()))
def _unjelly_timedelta(self, exp):
days, seconds, microseconds = map(int, exp[0].split())
return datetime.timedelta(
days=days, seconds=seconds, microseconds=microseconds)
def unjellyInto(self, obj, loc, jel):
o = self.unjelly(jel)
if isinstance(o, NotKnown):
o.addDependant(obj, loc)
obj[loc] = o
return o
def _unjelly_dereference(self, lst):
refid = lst[0]
x = self.references.get(refid)
if x is not None:
return x
der = _Dereference(refid)
self.references[refid] = der
return der
def _unjelly_reference(self, lst):
refid = lst[0]
exp = lst[1]
o = self.unjelly(exp)
ref = self.references.get(refid)
if (ref is None):
self.references[refid] = o
elif isinstance(ref, NotKnown):
ref.resolveDependants(o)
self.references[refid] = o
else:
assert 0, "Multiple references with same ID!"
return o
def _unjelly_tuple(self, lst):
l = range(len(lst))
finished = 1
for elem in l:
if isinstance(self.unjellyInto(l, elem, lst[elem]), NotKnown):
finished = 0
if finished:
return tuple(l)
else:
return _Tuple(l)
def _unjelly_list(self, lst):
l = range(len(lst))
for elem in l:
self.unjellyInto(l, elem, lst[elem])
return l
def _unjellySetOrFrozenset(self, lst, containerType):
"""
Helper method to unjelly set or frozenset.
@param lst: the content of the set.
@type lst: C{list}
@param containerType: the type of C{set} to use.
"""
l = range(len(lst))
finished = True
for elem in l:
data = self.unjellyInto(l, elem, lst[elem])
if isinstance(data, NotKnown):
finished = False
if not finished:
return _Container(l, containerType)
else:
return containerType(l)
def _unjelly_set(self, lst):
"""
Unjelly set using the C{set} builtin.
"""
return self._unjellySetOrFrozenset(lst, set)
def _unjelly_frozenset(self, lst):
"""
Unjelly frozenset using the C{frozenset} builtin.
"""
return self._unjellySetOrFrozenset(lst, frozenset)
def _unjelly_dictionary(self, lst):
d = {}
for k, v in lst:
kvd = _DictKeyAndValue(d)
self.unjellyInto(kvd, 0, k)
self.unjellyInto(kvd, 1, v)
return d
def _unjelly_module(self, rest):
moduleName = rest[0]
if type(moduleName) != types.StringType:
raise InsecureJelly(
"Attempted to unjelly a module with a non-string name.")
if not self.taster.isModuleAllowed(moduleName):
raise InsecureJelly(
"Attempted to unjelly module named %r" % (moduleName,))
mod = __import__(moduleName, {}, {},"x")
return mod
def _unjelly_class(self, rest):
clist = rest[0].split('.')
modName = '.'.join(clist[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("module %s not allowed" % modName)
klaus = namedObject(rest[0])
objType = type(klaus)
if objType not in (types.ClassType, types.TypeType):
raise InsecureJelly(
"class %r unjellied to something that isn't a class: %r" % (
rest[0], klaus))
if not self.taster.isClassAllowed(klaus):
raise InsecureJelly("class not allowed: %s" % qual(klaus))
return klaus
def _unjelly_function(self, rest):
modSplit = rest[0].split('.')
modName = '.'.join(modSplit[:-1])
if not self.taster.isModuleAllowed(modName):
raise InsecureJelly("Module not allowed: %s"% modName)
# XXX do I need an isFunctionAllowed?
function = namedObject(rest[0])
return function
def _unjelly_persistent(self, rest):
if self.persistentLoad:
pload = self.persistentLoad(rest[0], self)
return pload
else:
return Unpersistable("Persistent callback not found")
def _unjelly_instance(self, rest):
"""
(internal) Unjelly an instance.
Called to handle the deprecated I{instance} token.
@param rest: The s-expression representing the instance.
@return: The unjellied instance.
"""
warnings.warn_explicit(
"Unjelly support for the instance atom is deprecated since "
"Twisted 15.0.0. Upgrade peer for modern instance support.",
category=DeprecationWarning, filename="", lineno=0)
clz = self.unjelly(rest[0])
if type(clz) is not types.ClassType:
raise InsecureJelly("Instance found with non-class class.")
if hasattr(clz, "__setstate__"):
inst = _newInstance(clz, {})
state = self.unjelly(rest[1])
inst.__setstate__(state)
else:
state = self.unjelly(rest[1])
inst = _newInstance(clz, state)
if hasattr(clz, 'postUnjelly'):
self.postCallbacks.append(inst.postUnjelly)
return inst
def _unjelly_unpersistable(self, rest):
return Unpersistable("Unpersistable data: %s" % (rest[0],))
def _unjelly_method(self, rest):
"""
(internal) Unjelly a method.
"""
im_name = rest[0]
im_self = self.unjelly(rest[1])
im_class = self.unjelly(rest[2])
if type(im_class) is not types.ClassType:
raise InsecureJelly("Method found with non-class class.")
if im_name in im_class.__dict__:
if im_self is None:
im = getattr(im_class, im_name)
elif isinstance(im_self, NotKnown):
im = _InstanceMethod(im_name, im_self, im_class)
else:
im = MethodType(im_class.__dict__[im_name], im_self, im_class)
else:
raise TypeError('instance method changed')
return im
class _Dummy:
"""
(Internal) Dummy class, used for unserializing instances.
"""
class _DummyNewStyle(object):
"""
(Internal) Dummy class, used for unserializing instances of new-style
classes.
"""
def _newDummyLike(instance):
"""
Create a new instance like C{instance}.
The new instance has the same class and instance dictionary as the given
instance.
@return: The new instance.
"""
if isinstance(instance.__class__, type):
# New-style class
dummy = _DummyNewStyle()
else:
# Classic class
dummy = _Dummy()
dummy.__class__ = instance.__class__
dummy.__dict__ = instance.__dict__
return dummy
#### Published Interface.
class InsecureJelly(Exception):
"""
This exception will be raised when a jelly is deemed `insecure'; e.g. it
contains a type, class, or module disallowed by the specified `taster'
"""
class DummySecurityOptions:
"""
DummySecurityOptions() -> insecure security options
Dummy security options -- this class will allow anything.
"""
def isModuleAllowed(self, moduleName):
"""
DummySecurityOptions.isModuleAllowed(moduleName) -> boolean
returns 1 if a module by that name is allowed, 0 otherwise
"""
return 1
def isClassAllowed(self, klass):
"""
DummySecurityOptions.isClassAllowed(class) -> boolean
Assumes the module has already been allowed. Returns 1 if the given
class is allowed, 0 otherwise.
"""
return 1
def isTypeAllowed(self, typeName):
"""
DummySecurityOptions.isTypeAllowed(typeName) -> boolean
Returns 1 if the given type is allowed, 0 otherwise.
"""
return 1
class SecurityOptions:
"""
This will by default disallow everything, except for 'none'.
"""
basicTypes = ["dictionary", "list", "tuple",
"reference", "dereference", "unpersistable",
"persistent", "long_int", "long", "dict"]
def __init__(self):
"""
SecurityOptions() initialize.
"""
# I don't believe any of these types can ever pose a security hazard,
# except perhaps "reference"...
self.allowedTypes = {"None": 1,
"bool": 1,
"boolean": 1,
"string": 1,
"str": 1,
"int": 1,
"float": 1,
"datetime": 1,
"time": 1,
"date": 1,
"timedelta": 1,
"NoneType": 1}
self.allowedTypes['unicode'] = 1
self.allowedTypes['decimal'] = 1
self.allowedTypes['set'] = 1
self.allowedTypes['frozenset'] = 1
self.allowedModules = {}
self.allowedClasses = {}
def allowBasicTypes(self):
"""
Allow all `basic' types. (Dictionary and list. Int, string, and float
are implicitly allowed.)
"""
self.allowTypes(*self.basicTypes)
def allowTypes(self, *types):
"""
SecurityOptions.allowTypes(typeString): Allow a particular type, by its
name.
"""
for typ in types:
if not isinstance(typ, str):
typ = qual(typ)
self.allowedTypes[typ] = 1
def allowInstancesOf(self, *classes):
"""
SecurityOptions.allowInstances(klass, klass, ...): allow instances
of the specified classes
This will also allow the 'instance', 'class' (renamed 'classobj' in
Python 2.3), and 'module' types, as well as basic types.
"""
self.allowBasicTypes()
self.allowTypes("instance", "class", "classobj", "module")
for klass in classes:
self.allowTypes(qual(klass))
self.allowModules(klass.__module__)
self.allowedClasses[klass] = 1
def allowModules(self, *modules):
"""
SecurityOptions.allowModules(module, module, ...): allow modules by
name. This will also allow the 'module' type.
"""
for module in modules:
if type(module) == types.ModuleType:
module = module.__name__
self.allowedModules[module] = 1
def isModuleAllowed(self, moduleName):
"""
SecurityOptions.isModuleAllowed(moduleName) -> boolean
returns 1 if a module by that name is allowed, 0 otherwise
"""
return moduleName in self.allowedModules
def isClassAllowed(self, klass):
"""
SecurityOptions.isClassAllowed(class) -> boolean
Assumes the module has already been allowed. Returns 1 if the given
class is allowed, 0 otherwise.
"""
return klass in self.allowedClasses
def isTypeAllowed(self, typeName):
"""
SecurityOptions.isTypeAllowed(typeName) -> boolean
Returns 1 if the given type is allowed, 0 otherwise.
"""
return (typeName in self.allowedTypes or '.' in typeName)
globalSecurity = SecurityOptions()
globalSecurity.allowBasicTypes()
def jelly(object, taster=DummySecurityOptions(), persistentStore=None,
invoker=None):
"""
Serialize to s-expression.
Returns a list which is the serialized representation of an object. An
optional 'taster' argument takes a SecurityOptions and will mark any
insecure objects as unpersistable rather than serializing them.
"""
return _Jellier(taster, persistentStore, invoker).jelly(object)
def unjelly(sexp, taster=DummySecurityOptions(), persistentLoad=None,
invoker=None):
"""
Unserialize from s-expression.
Takes an list that was the result from a call to jelly() and unserializes
an arbitrary object from it. The optional 'taster' argument, an instance
of SecurityOptions, will cause an InsecureJelly exception to be raised if a
disallowed type, module, or class attempted to unserialize.
"""
return _Unjellier(taster, persistentLoad, invoker).unjellyFull(sexp)
|
mit
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
74,
29051,
1882,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
51,
13,
5599,
13,
6788,
26882,
402,
2366,
2251,
14,
199,
199,
7940,
1630,
6020,
7437,
8298,
2839,
491,
91,
12755,
28,
8092,
30,
12084,
13432,
12,
5927,
1159,
2446,
14850,
199,
3239,
706,
370,
506,
25978,
334,
10727,
315,
4601,
436,
900,
2736,
1335,
29051,
1159,
2446,
2621,
2551,
787,
199,
4416,
12,
11779,
1586,
3616,
12,
436,
1844,
3616,
370,
1163,
22196,
14,
199,
199,
2765,
365,
4212,
1603,
29051,
15373,
7750,
2251,
370,
308,
13,
15264,
14,
199,
199,
4082,
447,
272,
715,
10541,
788,
4871,
297,
283,
2052,
418,
199,
199,
2674,
447,
272,
413,
10541,
413,
199,
199,
1296,
447,
272,
359,
17,
12,
499,
61,
10541,
788,
513,
297,
413,
12,
499,
61,
199,
199,
1558,
447,
272,
8441,
5006,
4451,
10541,
8441,
5006,
4451,
199,
199,
5136,
447,
272,
499,
14,
19,
10541,
499,
14,
19,
199,
199,
11728,
447,
272,
791,
65,
356,
413,
12,
283,
66,
356,
283,
67,
936,
10541,
788,
9086,
297,
788,
66,
297,
283,
67,
995,
788,
65,
297,
413,
2677,
199,
199,
2377,
447,
272,
2876,
1558,
10541,
788,
578,
297,
283,
1899,
1558,
418,
199,
199,
2543,
447,
272,
2876,
1558,
14,
1899,
1558,
10541,
788,
533,
297,
788,
578,
297,
283,
1899,
1558,
995,
283,
1899,
1558,
418,
199,
199,
3481,
447,
272,
1059,
14,
904,
10541,
788,
1593,
297,
283,
904,
297,
788,
578,
297,
283,
875,
6538,
199,
199,
3244,
26,
308,
365,
376,
1256,
402,
2876,
1558,
14,
1899,
1558,
12,
543,
282,
636,
807,
363,
199,
1445,
576,
356,
283,
5006,
936,
447,
272,
359,
4451,
1899,
1558,
14,
1899,
1558,
20756,
788,
9086,
297,
788,
576,
297,
283,
5006,
418,
2677,
199,
199,
2543,
9075,
26,
2876,
1558,
14,
1899,
1558,
14,
4218,
447,
272,
788,
765,
297,
283,
4218,
297,
788,
403,
995,
788,
533,
297,
788,
578,
297,
283,
1899,
1558,
995,
1362,
283,
1899,
1558,
6538,
199,
199,
3244,
9075,
26,
308,
14,
4218,
12,
2382,
308,
365,
376,
1256,
402,
2876,
1558,
14,
1899,
1558,
447,
272,
788,
765,
297,
283,
4218,
297,
788,
842,
297,
788,
4443,
297,
413,
12,
788,
533,
297,
272,
788,
578,
297,
283,
1899,
1558,
995,
283,
1899,
1558,
2157,
788,
9086,
297,
788,
576,
297,
283,
68,
4397,
272,
788,
27915,
297,
413,
2677,
199,
199,
1918,
445,
91,
409,
93,
6762,
436,
314,
445,
91,
2193,
14,
1084,
93,
1021,
787,
6380,
370,
314,
2011,
199,
2127,
12,
436,
625,
8397,
370,
445,
91,
409,
93,
340,
2808,
12,
587,
370,
445,
91,
2193,
14,
1084,
5565,
2779,
4910,
199,
9099,
2337,
1159,
282,
31077,
402,
730,
31620,
315,
314,
16953,
2112,
14,
710,
199,
14458,
365,
370,
3544,
675,
445,
91,
409,
5565,
199,
199,
1918,
2011,
2332,
12966,
367,
445,
91,
21362,
93,
436,
445,
91,
2193,
14,
29174,
1084,
5565,
199,
199,
32,
2502,
26,
598,
7234,
491,
2829,
75,
583,
23751,
199,
624,
199,
199,
3,
6187,
24339,
199,
646,
5927,
199,
646,
2943,
199,
646,
3598,
199,
646,
6107,
199,
504,
9143,
492,
7114,
199,
504,
2943,
492,
32654,
199,
504,
2943,
492,
9805,
804,
199,
504,
2943,
492,
11634,
804,
199,
504,
2943,
492,
3820,
804,
199,
504,
2943,
492,
19944,
804,
199,
504,
2943,
492,
11140,
804,
199,
504,
2943,
492,
6801,
804,
199,
504,
2943,
492,
9075,
804,
199,
504,
2943,
492,
5673,
804,
199,
504,
2943,
492,
11932,
804,
199,
504,
2943,
492,
10066,
804,
199,
504,
2943,
492,
488,
804,
199,
504,
2943,
492,
8089,
804,
199,
646,
1331,
199,
199,
646,
2197,
199,
504,
2943,
492,
9411,
804,
199,
199,
893,
26,
272,
327,
9388,
734,
17831,
5721,
367,
2018,
2356,
499,
14,
22,
272,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
12,
267,
1245,
628,
1589,
5951,
859,
365,
5906,
401,
5666,
29,
549,
9,
272,
492,
5951,
465,
485,
2193,
199,
15172,
26,
272,
3598,
14,
4273,
14,
1935,
342,
421,
199,
504,
20110,
14,
3266,
492,
2456,
28826,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
14,
5819,
492,
2649,
199,
504,
7390,
14,
1548,
14,
21963,
492,
4310,
1692,
12,
6420,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
2832,
24574,
12,
485,
7075,
12,
485,
3244,
3767,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
485,
2141,
1197,
3325,
1110,
12,
485,
872,
4443,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
485,
4076,
199,
199,
504,
7390,
14,
29889,
14,
7436,
492,
473,
42,
29051,
461,
12,
473,
1358,
74,
29051,
461,
199,
199,
504,
7390,
14,
1548,
14,
27891,
492,
5906,
2377,
1646,
199,
504,
7390,
14,
1548,
14,
6234,
492,
3394,
199,
199,
2141,
4100,
275,
334,
11728,
804,
4258,
199,
199,
403,
63,
4188,
275,
298,
403,
2,
8295,
327,
653,
199,
3,
1233,
199,
533,
63,
4188,
275,
298,
533,
2,
4483,
327,
286,
199,
578,
63,
4188,
275,
298,
578,
2,
4519,
327,
333,
199,
1593,
63,
4188,
275,
298,
1593,
2,
3515,
327,
289,
199,
199,
3,
6941,
199,
27915,
63,
4188,
275,
283,
27915,
7,
259,
327,
577,
199,
18539,
63,
4188,
275,
283,
18539,
7,
420,
327,
299,
199,
4443,
63,
4188,
275,
283,
4443,
7,
263,
327,
519,
199,
199,
3,
17194,
5055,
199,
9086,
63,
4188,
275,
298,
9086,
2,
420,
327,
366,
199,
513,
63,
4188,
275,
283,
513,
7,
8295,
327,
634,
199,
409,
63,
4188,
275,
283,
409,
7,
199,
199,
3,
17092,
5055,
199,
3,
257,
334,
10861,
370,
636,
807,
363,
436,
636,
533,
363,
5139,
5594,
2621,
13437,
21866,
199,
2960,
63,
4188,
275,
298,
2960,
2,
4483,
327,
307,
199,
842,
63,
4188,
275,
283,
842,
7,
3515,
327,
284,
199,
21362,
63,
4188,
275,
283,
21362,
7,
421,
199,
6667,
2377,
1646,
8,
272,
3394,
480,
52,
5221,
401,
4114,
12,
378,
12,
378,
395
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
396,
14,
396,
63,
74,
29051,
1882,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
51,
13,
5599,
13,
6788,
26882,
402,
2366,
2251,
14,
199,
199,
7940,
1630,
6020,
7437,
8298,
2839,
491,
91,
12755,
28,
8092,
30,
12084,
13432,
12,
5927,
1159,
2446,
14850,
199,
3239,
706,
370,
506,
25978,
334,
10727,
315,
4601,
436,
900,
2736,
1335,
29051,
1159,
2446,
2621,
2551,
787,
199,
4416,
12,
11779,
1586,
3616,
12,
436,
1844,
3616,
370,
1163,
22196,
14,
199,
199,
2765,
365,
4212,
1603,
29051,
15373,
7750,
2251,
370,
308,
13,
15264,
14,
199,
199,
4082,
447,
272,
715,
10541,
788,
4871,
297,
283,
2052,
418,
199,
199,
2674,
447,
272,
413,
10541,
413,
199,
199,
1296,
447,
272,
359,
17,
12,
499,
61,
10541,
788,
513,
297,
413,
12,
499,
61,
199,
199,
1558,
447,
272,
8441,
5006,
4451,
10541,
8441,
5006,
4451,
199,
199,
5136,
447,
272,
499,
14,
19,
10541,
499,
14,
19,
199,
199,
11728,
447,
272,
791,
65,
356,
413,
12,
283,
66,
356,
283,
67,
936,
10541,
788,
9086,
297,
788,
66,
297,
283,
67,
995,
788,
65,
297,
413,
2677,
199,
199,
2377,
447,
272,
2876,
1558,
10541,
788,
578,
297,
283,
1899,
1558,
418,
199,
199,
2543,
447,
272,
2876,
1558,
14,
1899,
1558,
10541,
788,
533,
297,
788,
578,
297,
283,
1899,
1558,
995,
283,
1899,
1558,
418,
199,
199,
3481,
447,
272,
1059,
14,
904,
10541,
788,
1593,
297,
283,
904,
297,
788,
578,
297,
283,
875,
6538,
199,
199,
3244,
26,
308,
365,
376,
1256,
402,
2876,
1558,
14,
1899,
1558,
12,
543,
282,
636,
807,
363,
199,
1445,
576,
356,
283,
5006,
936,
447,
272,
359,
4451,
1899,
1558,
14,
1899,
1558,
20756,
788,
9086,
297,
788,
576,
297,
283,
5006,
418,
2677,
199,
199,
2543,
9075,
26,
2876,
1558,
14,
1899,
1558,
14,
4218,
447,
272,
788,
765,
297,
283,
4218,
297,
788,
403,
995,
788,
533,
297,
788,
578,
297,
283,
1899,
1558,
995,
1362,
283,
1899,
1558,
6538,
199,
199,
3244,
9075,
26,
308,
14,
4218,
12,
2382,
308,
365,
376,
1256,
402,
2876,
1558,
14,
1899,
1558,
447,
272,
788,
765,
297,
283,
4218,
297,
788,
842,
297,
788,
4443,
297,
413,
12,
788,
533,
297,
272,
788,
578,
297,
283,
1899,
1558,
995,
283,
1899,
1558,
2157,
788,
9086,
297,
788,
576,
297,
283,
68,
4397,
272,
788,
27915,
297,
413,
2677,
199,
199,
1918,
445,
91,
409,
93,
6762,
436,
314,
445,
91,
2193,
14,
1084,
93,
1021,
787,
6380,
370,
314,
2011,
199,
2127,
12,
436,
625,
8397,
370,
445,
91,
409,
93,
340,
2808,
12,
587,
370,
445,
91,
2193,
14,
1084,
5565,
2779,
4910,
199,
9099,
2337,
1159,
282,
31077,
402,
730,
31620,
315,
314,
16953,
2112,
14,
710,
199,
14458,
365,
370,
3544,
675,
445,
91,
409,
5565,
199,
199,
1918,
2011,
2332,
12966,
367,
445,
91,
21362,
93,
436,
445,
91,
2193,
14,
29174,
1084,
5565,
199,
199,
32,
2502,
26,
598,
7234,
491,
2829,
75,
583,
23751,
199,
624,
199,
199,
3,
6187,
24339,
199,
646,
5927,
199,
646,
2943,
199,
646,
3598,
199,
646,
6107,
199,
504,
9143,
492,
7114,
199,
504,
2943,
492,
32654,
199,
504,
2943,
492,
9805,
804,
199,
504,
2943,
492,
11634,
804,
199,
504,
2943,
492,
3820,
804,
199,
504,
2943,
492,
19944,
804,
199,
504,
2943,
492,
11140,
804,
199,
504,
2943,
492,
6801,
804,
199,
504,
2943,
492,
9075,
804,
199,
504,
2943,
492,
5673,
804,
199,
504,
2943,
492,
11932,
804,
199,
504,
2943,
492,
10066,
804,
199,
504,
2943,
492,
488,
804,
199,
504,
2943,
492,
8089,
804,
199,
646,
1331,
199,
199,
646,
2197,
199,
504,
2943,
492,
9411,
804,
199,
199,
893,
26,
272,
327,
9388,
734,
17831,
5721,
367,
2018,
2356,
499,
14,
22,
272,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
15561,
12,
267,
1245,
628,
1589,
5951,
859,
365,
5906,
401,
5666,
29,
549,
9,
272,
492,
5951,
465,
485,
2193,
199,
15172,
26,
272,
3598,
14,
4273,
14,
1935,
342,
421,
199,
504,
20110,
14,
3266,
492,
2456,
28826,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
14,
5819,
492,
2649,
199,
504,
7390,
14,
1548,
14,
21963,
492,
4310,
1692,
12,
6420,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
2832,
24574,
12,
485,
7075,
12,
485,
3244,
3767,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
485,
2141,
1197,
3325,
1110,
12,
485,
872,
4443,
199,
504,
7390,
14,
529,
24925,
14,
67,
1121,
1974,
492,
485,
4076,
199,
199,
504,
7390,
14,
29889,
14,
7436,
492,
473,
42,
29051,
461,
12,
473,
1358,
74,
29051,
461,
199,
199,
504,
7390,
14,
1548,
14,
27891,
492,
5906,
2377,
1646,
199,
504,
7390,
14,
1548,
14,
6234,
492,
3394,
199,
199,
2141,
4100,
275,
334,
11728,
804,
4258,
199,
199,
403,
63,
4188,
275,
298,
403,
2,
8295,
327,
653,
199,
3,
1233,
199,
533,
63,
4188,
275,
298,
533,
2,
4483,
327,
286,
199,
578,
63,
4188,
275,
298,
578,
2,
4519,
327,
333,
199,
1593,
63,
4188,
275,
298,
1593,
2,
3515,
327,
289,
199,
199,
3,
6941,
199,
27915,
63,
4188,
275,
283,
27915,
7,
259,
327,
577,
199,
18539,
63,
4188,
275,
283,
18539,
7,
420,
327,
299,
199,
4443,
63,
4188,
275,
283,
4443,
7,
263,
327,
519,
199,
199,
3,
17194,
5055,
199,
9086,
63,
4188,
275,
298,
9086,
2,
420,
327,
366,
199,
513,
63,
4188,
275,
283,
513,
7,
8295,
327,
634,
199,
409,
63,
4188,
275,
283,
409,
7,
199,
199,
3,
17092,
5055,
199,
3,
257,
334,
10861,
370,
636,
807,
363,
436,
636,
533,
363,
5139,
5594,
2621,
13437,
21866,
199,
2960,
63,
4188,
275,
298,
2960,
2,
4483,
327,
307,
199,
842,
63,
4188,
275,
283,
842,
7,
3515,
327,
284,
199,
21362,
63,
4188,
275,
283,
21362,
7,
421,
199,
6667,
2377,
1646,
8,
272,
3394,
480,
52,
5221,
401,
4114,
12,
378,
12,
378,
395,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
goliveirab/odoo
|
addons/l10n_in_hr_payroll/report/report_payroll_advice.py
|
374
|
3442
|
#-*- coding:utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 OpenERP SA (<http://openerp.com>). All Rights Reserved
# d$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
from datetime import datetime
from openerp.osv import osv
from openerp.report import report_sxw
from openerp.tools import amount_to_text_en
class payroll_advice_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(payroll_advice_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'get_month': self.get_month,
'convert': self.convert,
'get_detail': self.get_detail,
'get_bysal_total': self.get_bysal_total,
})
self.context = context
def get_month(self, input_date):
payslip_pool = self.pool.get('hr.payslip')
res = {
'from_name': '', 'to_name': ''
}
slip_ids = payslip_pool.search(self.cr, self.uid, [('date_from','<=',input_date), ('date_to','>=',input_date)], context=self.context)
if slip_ids:
slip = payslip_pool.browse(self.cr, self.uid, slip_ids, context=self.context)[0]
from_date = datetime.strptime(slip.date_from, '%Y-%m-%d')
to_date = datetime.strptime(slip.date_to, '%Y-%m-%d')
res['from_name']= from_date.strftime('%d')+'-'+from_date.strftime('%B')+'-'+from_date.strftime('%Y')
res['to_name']= to_date.strftime('%d')+'-'+to_date.strftime('%B')+'-'+to_date.strftime('%Y')
return res
def convert(self, amount, cur):
return amount_to_text_en.amount_to_text(amount, 'en', cur);
def get_bysal_total(self):
return self.total_bysal
def get_detail(self, line_ids):
result = []
self.total_bysal = 0.00
for l in line_ids:
res = {}
res.update({
'name': l.employee_id.name,
'acc_no': l.name,
'ifsc_code': l.ifsc_code,
'bysal': l.bysal,
'debit_credit': l.debit_credit,
})
self.total_bysal += l.bysal
result.append(res)
return result
class wrapped_report_payroll_advice(osv.AbstractModel):
_name = 'report.l10n_in_hr_payroll.report_payrolladvice'
_inherit = 'report.abstract_report'
_template = 'l10n_in_hr_payroll.report_payrolladvice'
_wrapped_report_class = payroll_advice_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
2900,
5924,
5702,
199,
3,
259,
366,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
5166,
14,
2537,
492,
5982,
63,
475,
63,
505,
63,
287,
199,
199,
533,
8633,
2827,
63,
350,
722,
63,
3070,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
2286,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
5989,
2827,
63,
350,
722,
63,
3070,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
398,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
362,
63,
4482,
356,
291,
14,
362,
63,
4482,
12,
288,
283,
3916,
356,
291,
14,
3916,
12,
288,
283,
362,
63,
5506,
356,
291,
14,
362,
63,
5506,
12,
288,
283,
362,
63,
66,
588,
279,
63,
2923,
356,
291,
14,
362,
63,
66,
588,
279,
63,
2923,
12,
267,
3828,
267,
291,
14,
1100,
275,
1067,
5493,
347,
664,
63,
4482,
8,
277,
12,
1324,
63,
602,
304,
267,
691,
18909,
63,
2293,
275,
291,
14,
2293,
14,
362,
360,
6271,
14,
25854,
358,
267,
522,
275,
469,
2049,
283,
504,
63,
354,
356,
3260,
283,
475,
63,
354,
356,
2125,
2049,
789,
267,
308,
3587,
63,
1580,
275,
691,
18909,
63,
2293,
14,
1733,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
4274,
602,
63,
504,
1673,
28,
4009,
1210,
63,
602,
395,
661,
602,
63,
475,
1673,
30,
4009,
1210,
63,
602,
4360,
1067,
29,
277,
14,
1100,
9,
267,
340,
308,
3587,
63,
1580,
26,
288,
308,
3587,
275,
691,
18909,
63,
2293,
14,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
308,
3587,
63,
1580,
12,
1067,
29,
277,
14,
1100,
2788,
16,
61,
288,
687,
63,
602,
275,
2197,
14,
9866,
8,
83,
3587,
14,
602,
63,
504,
12,
1543,
57,
3295,
77,
3295,
68,
358,
288,
370,
63,
602,
275,
221,
2197,
14,
9866,
8,
83,
3587,
14,
602,
63,
475,
12,
1543,
57,
3295,
77,
3295,
68,
358,
288,
522,
459,
504,
63,
354,
13784,
687,
63,
602,
14,
6205,
3508,
68,
358,
4786,
13,
6828,
504,
63,
602,
14,
6205,
3508,
34,
358,
4786,
13,
6828,
504,
63,
602,
14,
6205,
3508,
57,
358,
288,
522,
459,
475,
63,
354,
13784,
370,
63,
602,
14,
6205,
3508,
68,
358,
4786,
13,
6828,
475,
63,
602,
14,
6205,
3508,
34,
358,
4786,
13,
6828,
475,
63,
602,
14,
6205,
3508,
57,
358,
267,
372,
522,
339,
347,
3957,
8,
277,
12,
5982,
12,
1094,
304,
267,
372,
5982,
63,
475,
63,
505,
63,
287,
14,
4606,
63,
475,
63,
505,
8,
4606,
12,
283,
287,
297,
1094,
2736,
339,
347,
664,
63,
66,
588,
279,
63,
2923,
8,
277,
304,
267,
372,
291,
14,
2923,
63,
66,
588,
279,
5493,
347,
664,
63,
5506,
8,
277,
12,
1004,
63,
1580,
304,
267,
754,
275,
942,
267,
291,
14,
2923,
63,
66,
588,
279,
275,
378,
14,
383,
267,
367,
634,
315,
1004,
63,
1580,
26,
288,
522,
275,
1052,
288,
522,
14,
873,
2561,
490,
283,
354,
356,
634,
14,
10103,
63,
344,
14,
354,
12,
490,
283,
5470,
63,
889,
356,
634,
14,
354,
12,
490,
283,
692,
551,
63,
600,
356,
634,
14,
692,
551,
63,
600,
12,
490,
283,
66,
588,
279,
356,
634,
14,
66,
588,
279,
12,
490,
283,
12964,
63,
9365,
356,
634,
14,
12964,
63,
9365,
12,
490,
3828,
288,
291,
14,
2923,
63,
66,
588,
279,
847,
634,
14,
66,
588,
279,
288,
754,
14,
740,
8,
470,
9,
4960,
372,
754,
199,
199,
533,
8072,
63,
3070,
63,
5989,
2827,
63,
350,
722,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
76,
709,
78,
63,
262,
63,
6271,
63,
5989,
2827,
14,
3070,
63,
5989,
2827,
350,
722,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
76,
709,
78,
63,
262,
63,
6271,
63,
5989,
2827,
14,
3070,
63,
5989,
2827,
350,
722,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
8633,
2827,
63,
350,
722,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
13,
1837,
2803,
26,
1624,
13,
24,
1882,
199,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7760,
7653,
13950,
8642,
1014,
921,
11267,
14,
957,
10121,
2900,
5924,
5702,
199,
3,
259,
366,
4,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
3267,
701,
199,
3,
259,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
259,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
5166,
14,
4795,
492,
9506,
199,
504,
5166,
14,
3070,
492,
3622,
63,
20851,
199,
504,
5166,
14,
2537,
492,
5982,
63,
475,
63,
505,
63,
287,
199,
199,
533,
8633,
2827,
63,
350,
722,
63,
3070,
8,
3070,
63,
20851,
14,
16300,
63,
1122,
304,
2286,
347,
636,
826,
721,
277,
12,
2467,
12,
1747,
12,
536,
12,
1067,
304,
267,
1613,
8,
5989,
2827,
63,
350,
722,
63,
3070,
12,
291,
2843,
826,
721,
1556,
12,
1747,
12,
536,
12,
1067,
29,
1100,
9,
398,
291,
14,
17886,
14,
873,
2561,
288,
283,
521,
356,
900,
12,
288,
283,
362,
63,
4482,
356,
291,
14,
362,
63,
4482,
12,
288,
283,
3916,
356,
291,
14,
3916,
12,
288,
283,
362,
63,
5506,
356,
291,
14,
362,
63,
5506,
12,
288,
283,
362,
63,
66,
588,
279,
63,
2923,
356,
291,
14,
362,
63,
66,
588,
279,
63,
2923,
12,
267,
3828,
267,
291,
14,
1100,
275,
1067,
5493,
347,
664,
63,
4482,
8,
277,
12,
1324,
63,
602,
304,
267,
691,
18909,
63,
2293,
275,
291,
14,
2293,
14,
362,
360,
6271,
14,
25854,
358,
267,
522,
275,
469,
2049,
283,
504,
63,
354,
356,
3260,
283,
475,
63,
354,
356,
2125,
2049,
789,
267,
308,
3587,
63,
1580,
275,
691,
18909,
63,
2293,
14,
1733,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
4274,
602,
63,
504,
1673,
28,
4009,
1210,
63,
602,
395,
661,
602,
63,
475,
1673,
30,
4009,
1210,
63,
602,
4360,
1067,
29,
277,
14,
1100,
9,
267,
340,
308,
3587,
63,
1580,
26,
288,
308,
3587,
275,
691,
18909,
63,
2293,
14,
4570,
8,
277,
14,
1556,
12,
291,
14,
1535,
12,
308,
3587,
63,
1580,
12,
1067,
29,
277,
14,
1100,
2788,
16,
61,
288,
687,
63,
602,
275,
2197,
14,
9866,
8,
83,
3587,
14,
602,
63,
504,
12,
1543,
57,
3295,
77,
3295,
68,
358,
288,
370,
63,
602,
275,
221,
2197,
14,
9866,
8,
83,
3587,
14,
602,
63,
475,
12,
1543,
57,
3295,
77,
3295,
68,
358,
288,
522,
459,
504,
63,
354,
13784,
687,
63,
602,
14,
6205,
3508,
68,
358,
4786,
13,
6828,
504,
63,
602,
14,
6205,
3508,
34,
358,
4786,
13,
6828,
504,
63,
602,
14,
6205,
3508,
57,
358,
288,
522,
459,
475,
63,
354,
13784,
370,
63,
602,
14,
6205,
3508,
68,
358,
4786,
13,
6828,
475,
63,
602,
14,
6205,
3508,
34,
358,
4786,
13,
6828,
475,
63,
602,
14,
6205,
3508,
57,
358,
267,
372,
522,
339,
347,
3957,
8,
277,
12,
5982,
12,
1094,
304,
267,
372,
5982,
63,
475,
63,
505,
63,
287,
14,
4606,
63,
475,
63,
505,
8,
4606,
12,
283,
287,
297,
1094,
2736,
339,
347,
664,
63,
66,
588,
279,
63,
2923,
8,
277,
304,
267,
372,
291,
14,
2923,
63,
66,
588,
279,
5493,
347,
664,
63,
5506,
8,
277,
12,
1004,
63,
1580,
304,
267,
754,
275,
942,
267,
291,
14,
2923,
63,
66,
588,
279,
275,
378,
14,
383,
267,
367,
634,
315,
1004,
63,
1580,
26,
288,
522,
275,
1052,
288,
522,
14,
873,
2561,
490,
283,
354,
356,
634,
14,
10103,
63,
344,
14,
354,
12,
490,
283,
5470,
63,
889,
356,
634,
14,
354,
12,
490,
283,
692,
551,
63,
600,
356,
634,
14,
692,
551,
63,
600,
12,
490,
283,
66,
588,
279,
356,
634,
14,
66,
588,
279,
12,
490,
283,
12964,
63,
9365,
356,
634,
14,
12964,
63,
9365,
12,
490,
3828,
288,
291,
14,
2923,
63,
66,
588,
279,
847,
634,
14,
66,
588,
279,
288,
754,
14,
740,
8,
470,
9,
4960,
372,
754,
199,
199,
533,
8072,
63,
3070,
63,
5989,
2827,
63,
350,
722,
8,
4795,
14,
8458,
1685,
304,
272,
485,
354,
275,
283,
3070,
14,
76,
709,
78,
63,
262,
63,
6271,
63,
5989,
2827,
14,
3070,
63,
5989,
2827,
350,
722,
7,
272,
485,
6486,
275,
283,
3070,
14,
6198,
63,
3070,
7,
272,
485,
1160,
275,
283,
76,
709,
78,
63,
262,
63,
6271,
63,
5989,
2827,
14,
3070,
63,
5989,
2827,
350,
722,
7,
272,
485,
9130,
63,
3070,
63,
533,
275,
8633,
2827,
63,
350,
722,
63,
3070,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ashemedai/ansible
|
lib/ansible/playbook/__init__.py
|
83
|
4214
|
# (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 os
from ansible import constants as C
from ansible.errors import AnsibleParserError
from ansible.module_utils._text import to_text
from ansible.playbook.play import Play
from ansible.playbook.playbook_include import PlaybookInclude
from ansible.plugins import get_all_plugin_loaders
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
__all__ = ['Playbook']
class Playbook:
def __init__(self, loader):
# Entries in the datastructure of a playbook may
# be either a play or an include statement
self._entries = []
self._basedir = to_text(os.getcwd(), errors='surrogate_or_strict')
self._loader = loader
self._file_name = None
@staticmethod
def load(file_name, variable_manager=None, loader=None):
pb = Playbook(loader=loader)
pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager)
return pb
def _load_playbook_data(self, file_name, variable_manager):
if os.path.isabs(file_name):
self._basedir = os.path.dirname(file_name)
else:
self._basedir = os.path.normpath(os.path.join(self._basedir, os.path.dirname(file_name)))
# set the loaders basedir
cur_basedir = self._loader.get_basedir()
self._loader.set_basedir(self._basedir)
self._file_name = file_name
# dynamically load any plugins from the playbook directory
for name, obj in get_all_plugin_loaders():
if obj.subdir:
plugin_path = os.path.join(self._basedir, obj.subdir)
if os.path.isdir(plugin_path):
obj.add_directory(plugin_path)
ds = self._loader.load_from_file(os.path.basename(file_name))
if not isinstance(ds, list):
# restore the basedir in case this error is caught and handled
self._loader.set_basedir(cur_basedir)
raise AnsibleParserError("playbooks must be a list of plays", obj=ds)
# Parse the playbook entries. For plays, we simply parse them
# using the Play() object, and includes are parsed using the
# PlaybookInclude() object
for entry in ds:
if not isinstance(entry, dict):
# restore the basedir in case this error is caught and handled
self._loader.set_basedir(cur_basedir)
raise AnsibleParserError("playbook entries must be either a valid play or an include statement", obj=entry)
if 'include' in entry:
pb = PlaybookInclude.load(entry, basedir=self._basedir, variable_manager=variable_manager, loader=self._loader)
if pb is not None:
self._entries.extend(pb._entries)
else:
display.display("skipping playbook include '%s' due to conditional test failure" % entry.get('include', entry), color=C.COLOR_SKIP)
else:
entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader)
self._entries.append(entry_obj)
# we're done, so restore the old basedir in the loader
self._loader.set_basedir(cur_basedir)
def get_loader(self):
return self._loader
def get_plays(self):
return self._entries[:]
|
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,
747,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
31775,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
14205,
14,
2802,
492,
16527,
199,
504,
3242,
14,
14205,
14,
14205,
63,
2613,
492,
16527,
2706,
7826,
199,
504,
3242,
14,
5265,
492,
664,
63,
452,
63,
2718,
63,
16370,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
421,
199,
363,
452,
363,
275,
788,
9651,
2706,
418,
421,
199,
533,
16527,
2706,
26,
339,
347,
636,
826,
721,
277,
12,
5077,
304,
267,
327,
23450,
1996,
315,
314,
666,
6976,
402,
282,
15695,
1443,
267,
327,
506,
1902,
282,
5232,
503,
376,
2387,
5164,
267,
291,
423,
3189,
275,
942,
267,
291,
423,
12484,
275,
370,
63,
505,
8,
736,
14,
9458,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
358,
267,
291,
423,
3422,
221,
275,
5077,
267,
291,
423,
493,
63,
354,
275,
488,
339,
768,
4639,
272,
347,
2248,
8,
493,
63,
354,
12,
1750,
63,
2609,
29,
403,
12,
5077,
29,
403,
304,
267,
10446,
275,
16527,
2706,
8,
3422,
29,
3422,
9,
267,
10446,
423,
912,
63,
14205,
63,
576,
8,
493,
63,
354,
29,
493,
63,
354,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
9,
267,
372,
10446,
339,
347,
485,
912,
63,
14205,
63,
576,
8,
277,
12,
570,
63,
354,
12,
1750,
63,
2609,
304,
398,
340,
747,
14,
515,
14,
17896,
8,
493,
63,
354,
304,
288,
291,
423,
12484,
275,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
9,
267,
587,
26,
288,
291,
423,
12484,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
277,
423,
12484,
12,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
1724,
398,
327,
663,
314,
25520,
19380,
267,
1094,
63,
12484,
275,
291,
423,
3422,
14,
362,
63,
12484,
342,
267,
291,
423,
3422,
14,
409,
63,
12484,
8,
277,
423,
12484,
9,
398,
291,
423,
493,
63,
354,
275,
570,
63,
354,
398,
327,
18774,
2248,
1263,
8963,
687,
314,
15695,
2082,
267,
367,
536,
12,
1559,
315,
664,
63,
452,
63,
2718,
63,
16370,
837,
288,
340,
1559,
14,
10622,
26,
355,
3589,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
12484,
12,
1559,
14,
10622,
9,
355,
340,
747,
14,
515,
14,
6027,
8,
2718,
63,
515,
304,
490,
1559,
14,
525,
63,
3619,
8,
2718,
63,
515,
9,
398,
6364,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
8,
736,
14,
515,
14,
4846,
8,
493,
63,
354,
430,
267,
340,
440,
1228,
8,
795,
12,
769,
304,
288,
327,
9066,
314,
19380,
315,
1930,
642,
1125,
365,
15604,
436,
8860,
288,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
288,
746,
31775,
480,
2802,
8858,
1471,
506,
282,
769,
402,
299,
9316,
401,
1559,
29,
795,
9,
398,
327,
6077,
314,
15695,
4811,
14,
2104,
299,
9316,
12,
781,
9329,
2198,
3062,
267,
327,
1808,
314,
16527,
342,
909,
12,
436,
6952,
787,
4565,
1808,
314,
267,
327,
16527,
2706,
7826,
342,
909,
267,
367,
2397,
315,
6364,
26,
288,
340,
440,
1228,
8,
2373,
12,
1211,
304,
355,
327,
9066,
314,
19380,
315,
1930,
642,
1125,
365,
15604,
436,
8860,
355,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
355,
746,
31775,
480,
14205,
4811,
1471,
506,
1902,
282,
1686,
5232,
503,
376,
2387,
5164,
401,
1559,
29,
2373,
9,
953,
340,
283,
2613,
7,
315,
2397,
26,
355,
10446,
275,
16527,
2706,
7826,
14,
912,
8,
2373,
12,
19380,
29,
277,
423,
12484,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
277,
423,
3422,
9,
355,
340,
10446,
365,
440,
488,
26,
490,
291,
423,
3189,
14,
2880,
8,
3317,
423,
3189,
9,
355,
587,
26,
490,
2929,
14,
2918,
480,
27713,
15695,
2387,
1543,
83,
7,
7037,
370,
12303,
511,
5988,
2,
450,
2397,
14,
362,
360,
2613,
297,
2397,
395,
3164,
29,
35,
14,
7134,
63,
13525,
9,
288,
587,
26,
355,
2397,
63,
1113,
275,
16527,
14,
912,
8,
2373,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
277,
423,
3422,
9,
355,
291,
423,
3189,
14,
740,
8,
2373,
63,
1113,
9,
398,
327,
781,
3984,
4224,
12,
880,
9066,
314,
2269,
19380,
315,
314,
5077,
267,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
339,
347,
664,
63,
3422,
8,
277,
304,
267,
372,
291,
423,
3422,
339,
347,
664,
63,
20591,
8,
277,
304,
267,
372,
291,
423,
3189,
5873,
199,
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,
747,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
31775,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
505,
199,
504,
3242,
14,
14205,
14,
2802,
492,
16527,
199,
504,
3242,
14,
14205,
14,
14205,
63,
2613,
492,
16527,
2706,
7826,
199,
504,
3242,
14,
5265,
492,
664,
63,
452,
63,
2718,
63,
16370,
199,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
421,
199,
363,
452,
363,
275,
788,
9651,
2706,
418,
421,
199,
533,
16527,
2706,
26,
339,
347,
636,
826,
721,
277,
12,
5077,
304,
267,
327,
23450,
1996,
315,
314,
666,
6976,
402,
282,
15695,
1443,
267,
327,
506,
1902,
282,
5232,
503,
376,
2387,
5164,
267,
291,
423,
3189,
275,
942,
267,
291,
423,
12484,
275,
370,
63,
505,
8,
736,
14,
9458,
1062,
2552,
534,
16380,
63,
269,
63,
4768,
358,
267,
291,
423,
3422,
221,
275,
5077,
267,
291,
423,
493,
63,
354,
275,
488,
339,
768,
4639,
272,
347,
2248,
8,
493,
63,
354,
12,
1750,
63,
2609,
29,
403,
12,
5077,
29,
403,
304,
267,
10446,
275,
16527,
2706,
8,
3422,
29,
3422,
9,
267,
10446,
423,
912,
63,
14205,
63,
576,
8,
493,
63,
354,
29,
493,
63,
354,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
9,
267,
372,
10446,
339,
347,
485,
912,
63,
14205,
63,
576,
8,
277,
12,
570,
63,
354,
12,
1750,
63,
2609,
304,
398,
340,
747,
14,
515,
14,
17896,
8,
493,
63,
354,
304,
288,
291,
423,
12484,
275,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
9,
267,
587,
26,
288,
291,
423,
12484,
275,
747,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
904,
8,
277,
423,
12484,
12,
747,
14,
515,
14,
3475,
8,
493,
63,
354,
1724,
398,
327,
663,
314,
25520,
19380,
267,
1094,
63,
12484,
275,
291,
423,
3422,
14,
362,
63,
12484,
342,
267,
291,
423,
3422,
14,
409,
63,
12484,
8,
277,
423,
12484,
9,
398,
291,
423,
493,
63,
354,
275,
570,
63,
354,
398,
327,
18774,
2248,
1263,
8963,
687,
314,
15695,
2082,
267,
367,
536,
12,
1559,
315,
664,
63,
452,
63,
2718,
63,
16370,
837,
288,
340,
1559,
14,
10622,
26,
355,
3589,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
423,
12484,
12,
1559,
14,
10622,
9,
355,
340,
747,
14,
515,
14,
6027,
8,
2718,
63,
515,
304,
490,
1559,
14,
525,
63,
3619,
8,
2718,
63,
515,
9,
398,
6364,
275,
291,
423,
3422,
14,
912,
63,
504,
63,
493,
8,
736,
14,
515,
14,
4846,
8,
493,
63,
354,
430,
267,
340,
440,
1228,
8,
795,
12,
769,
304,
288,
327,
9066,
314,
19380,
315,
1930,
642,
1125,
365,
15604,
436,
8860,
288,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
288,
746,
31775,
480,
2802,
8858,
1471,
506,
282,
769,
402,
299,
9316,
401,
1559,
29,
795,
9,
398,
327,
6077,
314,
15695,
4811,
14,
2104,
299,
9316,
12,
781,
9329,
2198,
3062,
267,
327,
1808,
314,
16527,
342,
909,
12,
436,
6952,
787,
4565,
1808,
314,
267,
327,
16527,
2706,
7826,
342,
909,
267,
367,
2397,
315,
6364,
26,
288,
340,
440,
1228,
8,
2373,
12,
1211,
304,
355,
327,
9066,
314,
19380,
315,
1930,
642,
1125,
365,
15604,
436,
8860,
355,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
355,
746,
31775,
480,
14205,
4811,
1471,
506,
1902,
282,
1686,
5232,
503,
376,
2387,
5164,
401,
1559,
29,
2373,
9,
953,
340,
283,
2613,
7,
315,
2397,
26,
355,
10446,
275,
16527,
2706,
7826,
14,
912,
8,
2373,
12,
19380,
29,
277,
423,
12484,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
277,
423,
3422,
9,
355,
340,
10446,
365,
440,
488,
26,
490,
291,
423,
3189,
14,
2880,
8,
3317,
423,
3189,
9,
355,
587,
26,
490,
2929,
14,
2918,
480,
27713,
15695,
2387,
1543,
83,
7,
7037,
370,
12303,
511,
5988,
2,
450,
2397,
14,
362,
360,
2613,
297,
2397,
395,
3164,
29,
35,
14,
7134,
63,
13525,
9,
288,
587,
26,
355,
2397,
63,
1113,
275,
16527,
14,
912,
8,
2373,
12,
1750,
63,
2609,
29,
1975,
63,
2609,
12,
5077,
29,
277,
423,
3422,
9,
355,
291,
423,
3189,
14,
740,
8,
2373,
63,
1113,
9,
398,
327,
781,
3984,
4224,
12,
880,
9066,
314,
2269,
19380,
315,
314,
5077,
267,
291,
423,
3422,
14,
409,
63,
12484,
8,
895,
63,
12484,
9,
339,
347,
664,
63,
3422,
8,
277,
304,
267,
372,
291,
423,
3422,
339,
347,
664,
63,
20591,
8,
277,
304,
267,
372,
291,
423,
3189,
5873,
199,
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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experimental compounds.
# Songpeng Zu
# 2014-12-30
import os
import xml.sax
class DrugBankHandler(xml.sax.ContentHandler):
def __int__(self):
self.CurrentData = ""
self.DrugBankID = ""
self.smallmolecule = ""
self.drugbank = ""
self.parentContent = ""
self.SMILES = ""
def startElement(self,tag,attributes):
self.CurrentData = tag
if tag == "drug" and "type" in attributes:
if attributes["type"] == "small molecule":
self.smallmolecule = "small molecule"
if tag == "drugbank-id" and 'primary' in attributes:
self.drugbank = True
def endElement(self,tag):
if self.CurrentData == "drugbank-id":
if self.drugbank and "DB0" in self.DrugBankID:
# with open("DrugBankID2SMILES.txt","a") as fid:
# fid.write(self.DrugBankID+"\t")
print "DrugBank-ID:",self.DrugBankID+"\n"
elif self.CurrentData == "value" and self.parentContent == "SMILES":
if self.smallmolecule and self.drugbank:
with open("DrugBankID2SMILES.txt","a") as fid:
fid.write(self.DrugBankID+"\t"+self.SMILES+"\n")
self.smallmolecule = ""
self.drugbank = ""
self.CurrentData = ""
def characters(self,content):
if self.CurrentData == "kind":
self.parentContent = content
elif self.CurrentData == "value":
self.SMILES = content
elif self.CurrentData == "drugbank-id" and "DB0" in content:
self.DrugBankID = content
if __name__ == "__main__":
try:
os.remove("DrugBankID2SMILES.txt")
except OSError:
print "No file has been written."
finally:
print "Clean up the written file."
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces,0)
Handler = DrugBankHandler()
parser.setContentHandler(Handler)
parser.parse("drugbank.xml")
print "The job has been done."
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
12892,
366,
6558,
458,
436,
22820,
16487,
83,
14,
199,
3,
29405,
897,
71,
3107,
85,
199,
3,
6927,
13,
713,
13,
1216,
199,
199,
646,
747,
199,
646,
2748,
14,
14338,
199,
199,
533,
577,
82,
1518,
14814,
2461,
8,
1652,
14,
14338,
14,
2714,
2461,
304,
272,
347,
636,
442,
721,
277,
304,
267,
291,
14,
5639,
1451,
275,
3087,
267,
291,
14,
21733,
1518,
14814,
998,
275,
3087,
267,
291,
14,
7241,
26310,
275,
3087,
267,
291,
14,
5012,
1518,
9860,
275,
3087,
267,
291,
14,
1708,
2714,
275,
3087,
267,
291,
14,
4029,
1193,
654,
275,
3087,
272,
347,
26325,
8,
277,
12,
1450,
12,
2987,
304,
267,
291,
14,
5639,
1451,
275,
1947,
267,
340,
1947,
508,
298,
5012,
1518,
2,
436,
221,
298,
466,
2,
315,
3004,
26,
288,
340,
3004,
905,
466,
937,
508,
298,
7241,
26350,
582,
355,
291,
14,
7241,
26310,
275,
298,
7241,
26350,
2,
267,
340,
1947,
508,
298,
5012,
1518,
9860,
13,
344,
2,
436,
283,
3327,
7,
315,
3004,
26,
288,
291,
14,
5012,
1518,
9860,
275,
715,
272,
347,
28920,
8,
277,
12,
1450,
304,
267,
340,
291,
14,
5639,
1451,
508,
298,
5012,
1518,
9860,
13,
344,
582,
288,
340,
291,
14,
5012,
1518,
9860,
436,
298,
2846,
16,
2,
315,
291,
14,
21733,
1518,
14814,
998,
26,
199,
3,
4483,
543,
1551,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
2266,
65,
531,
465,
8289,
26,
199,
3,
8540,
8289,
14,
952,
8,
277,
14,
21733,
1518,
14814,
998,
25789,
84,
531,
355,
870,
298,
21733,
1518,
14814,
13,
998,
6783,
277,
14,
21733,
1518,
14814,
998,
25789,
78,
2,
267,
916,
291,
14,
5639,
1451,
508,
298,
585,
2,
436,
291,
14,
1708,
2714,
508,
298,
4029,
1193,
654,
582,
288,
340,
291,
14,
7241,
26310,
436,
291,
14,
5012,
1518,
9860,
26,
355,
543,
1551,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
2266,
65,
531,
465,
8289,
26,
490,
8289,
14,
952,
8,
277,
14,
21733,
1518,
14814,
998,
25789,
84,
7709,
277,
14,
4029,
1193,
654,
25789,
78,
531,
355,
291,
14,
7241,
26310,
275,
3087,
355,
291,
14,
5012,
1518,
9860,
275,
3087,
267,
291,
14,
5639,
1451,
275,
3087,
272,
347,
4110,
8,
277,
12,
1317,
304,
267,
340,
291,
14,
5639,
1451,
508,
298,
5091,
582,
288,
291,
14,
1708,
2714,
275,
1564,
267,
916,
291,
14,
5639,
1451,
508,
298,
585,
582,
288,
291,
14,
4029,
1193,
654,
275,
1564,
267,
916,
291,
14,
5639,
1451,
508,
298,
5012,
1518,
9860,
13,
344,
2,
436,
298,
2846,
16,
2,
315,
1564,
26,
288,
291,
14,
21733,
1518,
14814,
998,
275,
1564,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
862,
26,
267,
747,
14,
2168,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
531,
272,
871,
6440,
26,
267,
870,
298,
1944,
570,
965,
2757,
5313,
2122,
272,
3753,
26,
267,
870,
298,
6580,
1536,
314,
5313,
570,
2122,
339,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
272,
1798,
14,
409,
5968,
8,
1652,
14,
14338,
14,
2232,
14,
4445,
63,
9247,
12,
16,
9,
272,
18599,
275,
577,
82,
1518,
14814,
2461,
342,
272,
1798,
14,
28680,
2461,
8,
2461,
9,
272,
1798,
14,
1122,
480,
5012,
1518,
9860,
14,
1652,
531,
339,
870,
298,
1918,
3906,
965,
2757,
4224,
2122,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
12892,
366,
6558,
458,
436,
22820,
16487,
83,
14,
199,
3,
29405,
897,
71,
3107,
85,
199,
3,
6927,
13,
713,
13,
1216,
199,
199,
646,
747,
199,
646,
2748,
14,
14338,
199,
199,
533,
577,
82,
1518,
14814,
2461,
8,
1652,
14,
14338,
14,
2714,
2461,
304,
272,
347,
636,
442,
721,
277,
304,
267,
291,
14,
5639,
1451,
275,
3087,
267,
291,
14,
21733,
1518,
14814,
998,
275,
3087,
267,
291,
14,
7241,
26310,
275,
3087,
267,
291,
14,
5012,
1518,
9860,
275,
3087,
267,
291,
14,
1708,
2714,
275,
3087,
267,
291,
14,
4029,
1193,
654,
275,
3087,
272,
347,
26325,
8,
277,
12,
1450,
12,
2987,
304,
267,
291,
14,
5639,
1451,
275,
1947,
267,
340,
1947,
508,
298,
5012,
1518,
2,
436,
221,
298,
466,
2,
315,
3004,
26,
288,
340,
3004,
905,
466,
937,
508,
298,
7241,
26350,
582,
355,
291,
14,
7241,
26310,
275,
298,
7241,
26350,
2,
267,
340,
1947,
508,
298,
5012,
1518,
9860,
13,
344,
2,
436,
283,
3327,
7,
315,
3004,
26,
288,
291,
14,
5012,
1518,
9860,
275,
715,
272,
347,
28920,
8,
277,
12,
1450,
304,
267,
340,
291,
14,
5639,
1451,
508,
298,
5012,
1518,
9860,
13,
344,
582,
288,
340,
291,
14,
5012,
1518,
9860,
436,
298,
2846,
16,
2,
315,
291,
14,
21733,
1518,
14814,
998,
26,
199,
3,
4483,
543,
1551,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
2266,
65,
531,
465,
8289,
26,
199,
3,
8540,
8289,
14,
952,
8,
277,
14,
21733,
1518,
14814,
998,
25789,
84,
531,
355,
870,
298,
21733,
1518,
14814,
13,
998,
6783,
277,
14,
21733,
1518,
14814,
998,
25789,
78,
2,
267,
916,
291,
14,
5639,
1451,
508,
298,
585,
2,
436,
291,
14,
1708,
2714,
508,
298,
4029,
1193,
654,
582,
288,
340,
291,
14,
7241,
26310,
436,
291,
14,
5012,
1518,
9860,
26,
355,
543,
1551,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
2266,
65,
531,
465,
8289,
26,
490,
8289,
14,
952,
8,
277,
14,
21733,
1518,
14814,
998,
25789,
84,
7709,
277,
14,
4029,
1193,
654,
25789,
78,
531,
355,
291,
14,
7241,
26310,
275,
3087,
355,
291,
14,
5012,
1518,
9860,
275,
3087,
267,
291,
14,
5639,
1451,
275,
3087,
272,
347,
4110,
8,
277,
12,
1317,
304,
267,
340,
291,
14,
5639,
1451,
508,
298,
5091,
582,
288,
291,
14,
1708,
2714,
275,
1564,
267,
916,
291,
14,
5639,
1451,
508,
298,
585,
582,
288,
291,
14,
4029,
1193,
654,
275,
1564,
267,
916,
291,
14,
5639,
1451,
508,
298,
5012,
1518,
9860,
13,
344,
2,
436,
298,
2846,
16,
2,
315,
1564,
26,
288,
291,
14,
21733,
1518,
14814,
998,
275,
1564,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
862,
26,
267,
747,
14,
2168,
480,
21733,
1518,
14814,
998,
18,
4029,
1193,
654,
14,
2424,
531,
272,
871,
6440,
26,
267,
870,
298,
1944,
570,
965,
2757,
5313,
2122,
272,
3753,
26,
267,
870,
298,
6580,
1536,
314,
5313,
570,
2122,
339,
1798,
275,
2748,
14,
14338,
14,
1875,
63,
2087,
342,
272,
1798,
14,
409,
5968,
8,
1652,
14,
14338,
14,
2232,
14,
4445,
63,
9247,
12,
16,
9,
272,
18599,
275,
577,
82,
1518,
14814,
2461,
342,
272,
1798,
14,
28680,
2461,
8,
2461,
9,
272,
1798,
14,
1122,
480,
5012,
1518,
9860,
14,
1652,
531,
339,
870,
298,
1918,
3906,
965,
2757,
4224,
2122,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
rxuriguera/bibtexIndexMaker
|
src/bibim/rce/extraction.py
|
1
|
4634
|
# Copyright 2010 Ramon Xuriguera
#
# This file is part of BibtexIndexMaker RCE.
#
#
# BibtexIndexMaker RCE 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.
#
# BibtexIndexMaker RCE 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 BibtexIndexMaker RCE. If not, see <http://www.gnu.org/licenses/>.
import platform #@UnresolvedImport
import subprocess #@UnresolvedImport
from os import path
from bibim import log
from bibim.document.document import Document
from bibim.util.beautifulsoup import BeautifulSoup
class ExtractionError(Exception):
"""
Raised when the content of the file cannot be extracted or the file is
corrupted.
"""
class Extractor(object):
"""
Extractor provides methods for content extraction.
"""
def __init__(self):
pass
def _check_input_file(self, input_file):
"""
Checks file existence and normalizes its path.
"""
if not path.isfile(input_file):
raise IOError('%s does not exist or is not a file.' % input_file)
return path.normpath(input_file)
def extract(self, input_file):
raise NotImplementedError
class TextExtractor(Extractor):
"""
TextExtractor provides methods to extract text from other kind of
documents.
"""
def extract(self, input_file):
raise NotImplementedError
class PDFTextExtractor(TextExtractor):
"""
This class allows text extraction from PDF documents.
"""
_tool_path = {
'Darwin':'../../../tools/xpdf/linux/pdftotext', # MAC OS
'Linux':'../../../tools/xpdf/linux/pdftotext',
'Windows':'../../../tools/xpdf/windows/pdftotext.exe'
}
@property
def _pdf_extraction_tool(self):
"""
Extraction tools normalised URL depending on the platform on which
the method is invoked.
"""
plat = platform.system()
if plat not in self._tool_path.keys():
plat = 'Linux'
return path.normpath(path.join(path.dirname(__file__),
(self._tool_path[plat])))
def extract(self, input_file):
input_file = self._check_input_file(input_file)
# Extraction command and its options. They may be parametrized in the
# future
command = [self._pdf_extraction_tool, '-q', '-f', '1', '-l', '2',
'-enc', 'ASCII7', '-htmlmeta', input_file, '-']
try:
pop = subprocess.Popen(command, stdout=subprocess.PIPE)
except subprocess.CalledProcessError as cpe:
log.error ('Error executing PDF text extraction tool. Return code: ' #@UndefinedVariable
+ repr(cpe.returncode))
except OSError:
log.error ('PDF extraction tool not found') #@UndefinedVariable
stdout = pop.communicate()[0]
if not stdout:
raise ExtractionError('Corrupted file')
parser = BeautifulSoup(stdout)
document = Document()
self._extract_metadata(parser, document)
self._extract_content(parser, document)
return document
def _extract_metadata(self, parser, document):
# Title
title = parser.find('title')
if title:
document.set_metadata_field('Title', title.find(text=True))
# Rest of metadata
metas = parser.findAll('meta')
for meta in metas:
document.set_metadata_field(meta['name'], meta['content'])
def _extract_content(self, parser, document):
pre = parser.find('pre')
raw_content = pre.find(text=True).strip()
if not raw_content:
raise ExtractionError('Could not extract content')
document.content = raw_content
class TXTTextExtractor(TextExtractor):
"""
Implements TextExtractor methods to wrap the process of loading text
documents.
"""
def extract(self, input_file):
input_file = self._check_input_file(input_file)
document = Document()
file = open(input_file)
document.content = file.read()
file.close()
return document
|
gpl-3.0
|
[
3,
1898,
7129,
820,
455,
265,
1323,
300,
528,
14262,
65,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
21949,
3858,
2681,
23560,
820,
2089,
14,
221,
199,
3,
199,
3,
199,
3,
21949,
3858,
2681,
23560,
820,
2089,
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,
21949,
3858,
2681,
23560,
820,
2089,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
21949,
3858,
2681,
23560,
820,
2089,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
646,
4298,
9213,
1358,
13697,
6295,
199,
646,
3873,
9213,
1358,
13697,
6295,
199,
504,
747,
492,
931,
199,
199,
504,
11314,
1017,
492,
943,
199,
504,
11314,
1017,
14,
3554,
14,
3554,
492,
7543,
199,
504,
11314,
1017,
14,
1974,
14,
1235,
25146,
9317,
492,
17132,
199,
199,
533,
7255,
6156,
547,
8,
1726,
304,
2286,
408,
272,
24997,
1380,
314,
1564,
402,
314,
570,
3913,
506,
12509,
503,
314,
570,
365,
272,
1970,
15692,
14,
272,
408,
199,
199,
533,
18925,
8,
785,
304,
2286,
408,
272,
18925,
6571,
3102,
367,
1564,
19967,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
485,
1074,
63,
1210,
63,
493,
8,
277,
12,
1324,
63,
493,
304,
267,
408,
267,
13813,
570,
23780,
436,
3293,
6491,
2399,
931,
14,
267,
408,
267,
340,
440,
931,
14,
6292,
8,
1210,
63,
493,
304,
288,
746,
5925,
3508,
83,
1630,
440,
2187,
503,
365,
440,
282,
570,
3530,
450,
1324,
63,
493,
9,
267,
372,
931,
14,
9267,
8,
1210,
63,
493,
9,
5493,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
746,
4279,
16872,
199,
533,
4516,
11039,
8,
11039,
304,
272,
408,
272,
4516,
11039,
6571,
3102,
370,
5536,
1318,
687,
1163,
4928,
402,
5591,
8247,
14,
23855,
408,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
746,
4279,
27844,
199,
533,
15537,
1872,
11039,
8,
1872,
11039,
304,
272,
408,
272,
961,
1021,
6127,
1318,
19967,
687,
15537,
8247,
14,
272,
408,
339,
485,
3557,
63,
515,
275,
469,
267,
283,
31065,
5242,
29866,
2537,
15,
88,
5607,
15,
5135,
15,
5607,
475,
505,
297,
327,
13347,
4403,
4960,
283,
14091,
5242,
29866,
2537,
15,
88,
5607,
15,
5135,
15,
5607,
475,
505,
297,
267,
283,
8647,
5242,
29866,
2537,
15,
88,
5607,
15,
8258,
15,
5607,
475,
505,
14,
5803,
7,
272,
789,
2286,
768,
1829,
272,
347,
485,
5607,
63,
24020,
63,
3557,
8,
277,
304,
267,
408,
267,
7255,
6156,
7249,
3293,
9096,
2851,
10298,
641,
314,
4298,
641,
1314,
267,
314,
1083,
365,
10302,
14,
267,
408,
267,
20819,
275,
4298,
14,
2253,
342,
267,
340,
20819,
440,
315,
291,
423,
3557,
63,
515,
14,
1612,
837,
288,
20819,
275,
283,
14091,
7,
267,
372,
931,
14,
9267,
8,
515,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
288,
334,
277,
423,
3557,
63,
515,
59,
14156,
11845,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
1324,
63,
493,
275,
291,
423,
1074,
63,
1210,
63,
493,
8,
1210,
63,
493,
9,
267,
327,
7255,
6156,
1414,
436,
2399,
1511,
14,
9322,
1443,
506,
18117,
599,
7068,
315,
314,
267,
327,
6466,
267,
1414,
275,
359,
277,
423,
5607,
63,
24020,
63,
3557,
12,
2475,
81,
297,
2475,
70,
297,
283,
17,
297,
2475,
76,
297,
283,
18,
297,
673,
2475,
10945,
297,
283,
12292,
23,
297,
2475,
1360,
2024,
297,
1324,
63,
493,
12,
2475,
418,
267,
862,
26,
288,
4560,
275,
3873,
14,
7942,
8,
1531,
12,
3839,
29,
5781,
14,
6089,
9,
267,
871,
3873,
14,
24691,
465,
286,
321,
26,
288,
943,
14,
705,
661,
547,
14043,
15537,
1318,
19967,
4744,
14,
1432,
1233,
26,
283,
9213,
16283,
2773,
673,
435,
4700,
8,
67,
321,
14,
9913,
430,
267,
871,
6440,
26,
288,
943,
14,
705,
661,
7638,
19967,
4744,
440,
1911,
358,
9213,
16283,
2773,
2728,
3839,
275,
4560,
14,
10664,
3430,
16,
61,
267,
340,
440,
3839,
26,
288,
746,
7255,
6156,
547,
360,
8380,
15692,
570,
358,
2728,
1798,
275,
17132,
8,
2703,
9,
267,
2213,
275,
7543,
342,
267,
291,
423,
5005,
63,
2343,
8,
2087,
12,
2213,
9,
267,
291,
423,
5005,
63,
1317,
8,
2087,
12,
2213,
9,
398,
372,
2213,
2286,
347,
485,
5005,
63,
2343,
8,
277,
12,
1798,
12,
2213,
304,
267,
327,
16881,
267,
2538,
275,
1798,
14,
1623,
360,
1213,
358,
267,
340,
2538,
26,
288,
2213,
14,
409,
63,
2343,
63,
698,
360,
6888,
297,
2538,
14,
1623,
8,
505,
29,
549,
430,
267,
327,
30417,
402,
3341,
267,
7647,
305,
275,
1798,
14,
32651,
360,
2024,
358,
267,
367,
3404,
315,
7647,
305,
26,
288,
2213,
14,
409,
63,
2343,
63,
698,
8,
2024,
459,
354,
995,
3404,
459,
1317,
1105,
2286,
347,
485,
5005,
63,
1317,
8,
277,
12,
1798,
12,
2213,
304,
267,
876,
275,
1798,
14,
1623,
360,
657,
358,
267,
3066,
63,
1317,
275,
876,
14,
1623,
8,
505,
29,
549,
680,
1913,
342,
267,
340,
440,
3066,
63,
1317,
26,
288,
746,
7255,
6156,
547,
360,
6531,
440,
5536,
1564,
358,
4960,
2213,
14,
1317,
275,
3066,
63,
1317,
268,
199,
533,
377,
56,
1481,
832,
11039,
8,
1872,
11039,
304,
272,
408,
272,
24664,
4516,
11039,
3102,
370,
4816,
314,
2112,
402,
8697,
1318,
5591,
8247,
14,
272,
408,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
1324,
63,
493,
275,
291,
423,
1074,
63,
1210
] |
[
1898,
7129,
820,
455,
265,
1323,
300,
528,
14262,
65,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
21949,
3858,
2681,
23560,
820,
2089,
14,
221,
199,
3,
199,
3,
199,
3,
21949,
3858,
2681,
23560,
820,
2089,
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,
21949,
3858,
2681,
23560,
820,
2089,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
21949,
3858,
2681,
23560,
820,
2089,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
646,
4298,
9213,
1358,
13697,
6295,
199,
646,
3873,
9213,
1358,
13697,
6295,
199,
504,
747,
492,
931,
199,
199,
504,
11314,
1017,
492,
943,
199,
504,
11314,
1017,
14,
3554,
14,
3554,
492,
7543,
199,
504,
11314,
1017,
14,
1974,
14,
1235,
25146,
9317,
492,
17132,
199,
199,
533,
7255,
6156,
547,
8,
1726,
304,
2286,
408,
272,
24997,
1380,
314,
1564,
402,
314,
570,
3913,
506,
12509,
503,
314,
570,
365,
272,
1970,
15692,
14,
272,
408,
199,
199,
533,
18925,
8,
785,
304,
2286,
408,
272,
18925,
6571,
3102,
367,
1564,
19967,
14,
272,
408,
2286,
347,
636,
826,
721,
277,
304,
267,
986,
339,
347,
485,
1074,
63,
1210,
63,
493,
8,
277,
12,
1324,
63,
493,
304,
267,
408,
267,
13813,
570,
23780,
436,
3293,
6491,
2399,
931,
14,
267,
408,
267,
340,
440,
931,
14,
6292,
8,
1210,
63,
493,
304,
288,
746,
5925,
3508,
83,
1630,
440,
2187,
503,
365,
440,
282,
570,
3530,
450,
1324,
63,
493,
9,
267,
372,
931,
14,
9267,
8,
1210,
63,
493,
9,
5493,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
746,
4279,
16872,
199,
533,
4516,
11039,
8,
11039,
304,
272,
408,
272,
4516,
11039,
6571,
3102,
370,
5536,
1318,
687,
1163,
4928,
402,
5591,
8247,
14,
23855,
408,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
746,
4279,
27844,
199,
533,
15537,
1872,
11039,
8,
1872,
11039,
304,
272,
408,
272,
961,
1021,
6127,
1318,
19967,
687,
15537,
8247,
14,
272,
408,
339,
485,
3557,
63,
515,
275,
469,
267,
283,
31065,
5242,
29866,
2537,
15,
88,
5607,
15,
5135,
15,
5607,
475,
505,
297,
327,
13347,
4403,
4960,
283,
14091,
5242,
29866,
2537,
15,
88,
5607,
15,
5135,
15,
5607,
475,
505,
297,
267,
283,
8647,
5242,
29866,
2537,
15,
88,
5607,
15,
8258,
15,
5607,
475,
505,
14,
5803,
7,
272,
789,
2286,
768,
1829,
272,
347,
485,
5607,
63,
24020,
63,
3557,
8,
277,
304,
267,
408,
267,
7255,
6156,
7249,
3293,
9096,
2851,
10298,
641,
314,
4298,
641,
1314,
267,
314,
1083,
365,
10302,
14,
267,
408,
267,
20819,
275,
4298,
14,
2253,
342,
267,
340,
20819,
440,
315,
291,
423,
3557,
63,
515,
14,
1612,
837,
288,
20819,
275,
283,
14091,
7,
267,
372,
931,
14,
9267,
8,
515,
14,
904,
8,
515,
14,
3475,
3460,
493,
10139,
288,
334,
277,
423,
3557,
63,
515,
59,
14156,
11845,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
1324,
63,
493,
275,
291,
423,
1074,
63,
1210,
63,
493,
8,
1210,
63,
493,
9,
267,
327,
7255,
6156,
1414,
436,
2399,
1511,
14,
9322,
1443,
506,
18117,
599,
7068,
315,
314,
267,
327,
6466,
267,
1414,
275,
359,
277,
423,
5607,
63,
24020,
63,
3557,
12,
2475,
81,
297,
2475,
70,
297,
283,
17,
297,
2475,
76,
297,
283,
18,
297,
673,
2475,
10945,
297,
283,
12292,
23,
297,
2475,
1360,
2024,
297,
1324,
63,
493,
12,
2475,
418,
267,
862,
26,
288,
4560,
275,
3873,
14,
7942,
8,
1531,
12,
3839,
29,
5781,
14,
6089,
9,
267,
871,
3873,
14,
24691,
465,
286,
321,
26,
288,
943,
14,
705,
661,
547,
14043,
15537,
1318,
19967,
4744,
14,
1432,
1233,
26,
283,
9213,
16283,
2773,
673,
435,
4700,
8,
67,
321,
14,
9913,
430,
267,
871,
6440,
26,
288,
943,
14,
705,
661,
7638,
19967,
4744,
440,
1911,
358,
9213,
16283,
2773,
2728,
3839,
275,
4560,
14,
10664,
3430,
16,
61,
267,
340,
440,
3839,
26,
288,
746,
7255,
6156,
547,
360,
8380,
15692,
570,
358,
2728,
1798,
275,
17132,
8,
2703,
9,
267,
2213,
275,
7543,
342,
267,
291,
423,
5005,
63,
2343,
8,
2087,
12,
2213,
9,
267,
291,
423,
5005,
63,
1317,
8,
2087,
12,
2213,
9,
398,
372,
2213,
2286,
347,
485,
5005,
63,
2343,
8,
277,
12,
1798,
12,
2213,
304,
267,
327,
16881,
267,
2538,
275,
1798,
14,
1623,
360,
1213,
358,
267,
340,
2538,
26,
288,
2213,
14,
409,
63,
2343,
63,
698,
360,
6888,
297,
2538,
14,
1623,
8,
505,
29,
549,
430,
267,
327,
30417,
402,
3341,
267,
7647,
305,
275,
1798,
14,
32651,
360,
2024,
358,
267,
367,
3404,
315,
7647,
305,
26,
288,
2213,
14,
409,
63,
2343,
63,
698,
8,
2024,
459,
354,
995,
3404,
459,
1317,
1105,
2286,
347,
485,
5005,
63,
1317,
8,
277,
12,
1798,
12,
2213,
304,
267,
876,
275,
1798,
14,
1623,
360,
657,
358,
267,
3066,
63,
1317,
275,
876,
14,
1623,
8,
505,
29,
549,
680,
1913,
342,
267,
340,
440,
3066,
63,
1317,
26,
288,
746,
7255,
6156,
547,
360,
6531,
440,
5536,
1564,
358,
4960,
2213,
14,
1317,
275,
3066,
63,
1317,
268,
199,
533,
377,
56,
1481,
832,
11039,
8,
1872,
11039,
304,
272,
408,
272,
24664,
4516,
11039,
3102,
370,
4816,
314,
2112,
402,
8697,
1318,
5591,
8247,
14,
272,
408,
2286,
347,
5536,
8,
277,
12,
1324,
63,
493,
304,
267,
1324,
63,
493,
275,
291,
423,
1074,
63,
1210,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Ghini/ghini.desktop
|
bauble/utils/web.py
|
1
|
2060
|
# -*- coding: utf-8 -*-
#
# Copyright 2008-2010 Brett Adams
# Copyright 2014-2017 Mario Frasca <mario@anche.no>.
# Copyright 2016 Ross Demuth <rossdemuth123@gmail.com>
#
# This file is part of ghini.desktop.
#
# ghini.desktop 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.
#
# ghini.desktop 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 ghini.desktop. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
import re
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
import bauble.utils.desktop as desktop
def _open_link(data=None, *args, **kwargs):
"""Open a web link"""
logger.debug("_open_link received data=%s, args=%s, kwargs=%s" % (data, args, kwargs))
desktop.open(data)
class BaubleLinkButton(Gtk.LinkButton):
_base_uri = "%s"
_space = "_"
title = _("Search")
tooltip = None
pt = re.compile(r'%\(([a-z_\.]*)\)s')
def __init__(self, title=_("Search"), tooltip=None):
super().__init__("", self.title)
self.set_tooltip_text(self.tooltip or self.title)
self.__class__.fields = self.pt.findall(self._base_uri)
def set_string(self, row):
if self.fields == []:
s = str(row)
self.set_uri(self._base_uri % s.replace(' ', self._space))
else:
values = {}
for key in self.fields:
value = row
for step in key.split('.'):
value = getattr(value, step, '-')
values[key] = (value == str(value)) and value or ''
self.set_uri(self._base_uri % values)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9079,
13,
6542,
699,
3292,
84,
4431,
19470,
199,
3,
1898,
6927,
13,
10680,
603,
6936,
481,
6360,
696,
665,
77,
6936,
32,
290,
595,
14,
889,
10827,
199,
3,
1898,
7800,
6848,
385,
1487,
77,
762,
665,
3685,
23522,
762,
4288,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
23310,
2730,
14,
14487,
14,
199,
3,
199,
3,
23310,
2730,
14,
14487,
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,
23310,
2730,
14,
14487,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
23310,
2730,
14,
14487,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
18895,
14,
8421,
492,
11424,
199,
646,
295,
199,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
2921,
14,
13548,
8,
4806,
14,
4531,
9,
199,
199,
646,
19325,
2016,
14,
1208,
14,
14487,
465,
19763,
4388,
199,
318,
485,
1490,
63,
1073,
8,
576,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
4299,
282,
3330,
2142,
624,
272,
2512,
14,
1757,
11008,
1490,
63,
1073,
3086,
666,
2458,
83,
12,
1249,
2458,
83,
12,
2074,
2458,
83,
2,
450,
334,
576,
12,
1249,
12,
2074,
430,
272,
19763,
14,
1490,
8,
576,
9,
421,
199,
533,
699,
65,
2016,
3834,
4259,
8,
18891,
14,
3834,
4259,
304,
339,
485,
1095,
63,
2302,
275,
2071,
83,
2,
272,
485,
2638,
275,
14220,
272,
2538,
275,
3824,
5278,
531,
272,
28013,
275,
488,
272,
10063,
275,
295,
14,
2014,
8,
82,
5956,
24805,
779,
65,
13,
90,
63,
4537,
3672,
2862,
9,
83,
358,
339,
347,
636,
826,
721,
277,
12,
2538,
9384,
5278,
1288,
28013,
29,
403,
304,
267,
1613,
11027,
826,
721,
5151,
291,
14,
1213,
9,
267,
291,
14,
409,
63,
22972,
63,
505,
8,
277,
14,
22972,
503,
291,
14,
1213,
9,
267,
291,
855,
533,
4343,
955,
275,
291,
14,
541,
14,
6452,
8,
277,
423,
1095,
63,
2302,
9,
339,
347,
663,
63,
875,
8,
277,
12,
1962,
304,
267,
340,
291,
14,
955,
508,
18410,
288,
308,
275,
620,
8,
1143,
9,
288,
291,
14,
409,
63,
2302,
8,
277,
423,
1095,
63,
2302,
450,
308,
14,
1814,
360,
1656,
291,
423,
2638,
430,
267,
587,
26,
288,
1338,
275,
1052,
288,
367,
790,
315,
291,
14,
955,
26,
355,
574,
275,
1962,
355,
367,
3650,
315,
790,
14,
1294,
26461,
490,
574,
275,
2519,
8,
585,
12,
3650,
12,
26942,
355,
1338,
59,
498,
61,
275,
334,
585,
508,
620,
8,
585,
430,
436,
574,
503,
2125,
288,
291,
14,
409,
63,
2302,
8,
277,
423,
1095,
63,
2302,
450,
1338,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
9079,
13,
6542,
699,
3292,
84,
4431,
19470,
199,
3,
1898,
6927,
13,
10680,
603,
6936,
481,
6360,
696,
665,
77,
6936,
32,
290,
595,
14,
889,
10827,
199,
3,
1898,
7800,
6848,
385,
1487,
77,
762,
665,
3685,
23522,
762,
4288,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
23310,
2730,
14,
14487,
14,
199,
3,
199,
3,
23310,
2730,
14,
14487,
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,
23310,
2730,
14,
14487,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
23310,
2730,
14,
14487,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
421,
199,
504,
18895,
14,
8421,
492,
11424,
199,
646,
295,
199,
199,
646,
2050,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
2921,
14,
13548,
8,
4806,
14,
4531,
9,
199,
199,
646,
19325,
2016,
14,
1208,
14,
14487,
465,
19763,
4388,
199,
318,
485,
1490,
63,
1073,
8,
576,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
4299,
282,
3330,
2142,
624,
272,
2512,
14,
1757,
11008,
1490,
63,
1073,
3086,
666,
2458,
83,
12,
1249,
2458,
83,
12,
2074,
2458,
83,
2,
450,
334,
576,
12,
1249,
12,
2074,
430,
272,
19763,
14,
1490,
8,
576,
9,
421,
199,
533,
699,
65,
2016,
3834,
4259,
8,
18891,
14,
3834,
4259,
304,
339,
485,
1095,
63,
2302,
275,
2071,
83,
2,
272,
485,
2638,
275,
14220,
272,
2538,
275,
3824,
5278,
531,
272,
28013,
275,
488,
272,
10063,
275,
295,
14,
2014,
8,
82,
5956,
24805,
779,
65,
13,
90,
63,
4537,
3672,
2862,
9,
83,
358,
339,
347,
636,
826,
721,
277,
12,
2538,
9384,
5278,
1288,
28013,
29,
403,
304,
267,
1613,
11027,
826,
721,
5151,
291,
14,
1213,
9,
267,
291,
14,
409,
63,
22972,
63,
505,
8,
277,
14,
22972,
503,
291,
14,
1213,
9,
267,
291,
855,
533,
4343,
955,
275,
291,
14,
541,
14,
6452,
8,
277,
423,
1095,
63,
2302,
9,
339,
347,
663,
63,
875,
8,
277,
12,
1962,
304,
267,
340,
291,
14,
955,
508,
18410,
288,
308,
275,
620,
8,
1143,
9,
288,
291,
14,
409,
63,
2302,
8,
277,
423,
1095,
63,
2302,
450,
308,
14,
1814,
360,
1656,
291,
423,
2638,
430,
267,
587,
26,
288,
1338,
275,
1052,
288,
367,
790,
315,
291,
14,
955,
26,
355,
574,
275,
1962,
355,
367,
3650,
315,
790,
14,
1294,
26461,
490,
574,
275,
2519,
8,
585,
12,
3650,
12,
26942,
355,
1338,
59,
498,
61,
275,
334,
585,
508,
620,
8,
585,
430,
436,
574,
503,
2125,
288,
291,
14,
409,
63,
2302,
8,
277,
423,
1095,
63,
2302,
450,
1338,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
arborh/tensorflow
|
tensorflow/python/platform/self_check.py
|
6
|
2436
|
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Platform-specific code for checking the integrity of the TensorFlow build."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
try:
from tensorflow.python.platform import build_info
except ImportError:
raise ImportError("Could not import tensorflow. Do not import tensorflow "
"from its source directory; change directory to outside "
"the TensorFlow source tree, and relaunch your Python "
"interpreter from there.")
def preload_check():
"""Raises an exception if the environment is not correctly configured.
Raises:
ImportError: If the check detects that the environment is not correctly
configured, and attempting to load the TensorFlow runtime will fail.
"""
if os.name == "nt":
# Attempt to load any DLLs that the Python extension depends on before
# we load the Python extension, so that we can raise an actionable error
# message if they are not found.
import ctypes # pylint: disable=g-import-not-at-top
if hasattr(build_info, "msvcp_dll_name"):
try:
ctypes.WinDLL(build_info.msvcp_dll_name)
except OSError:
raise ImportError(
"Could not find %r. TensorFlow requires that this DLL be "
"installed in a directory that is named in your %%PATH%% "
"environment variable. You may install this DLL by downloading "
"Visual C++ 2015 Redistributable Update 3 from this URL: "
"https://www.microsoft.com/en-us/download/details.aspx?id=53587"
% build_info.msvcp_dll_name)
else:
# TODO(mrry): Consider adding checks for the Linux and Mac OS X builds.
pass
|
apache-2.0
|
[
3,
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
10397,
13,
6100,
1233,
367,
7907,
314,
4661,
12997,
402,
314,
9134,
1900,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
421,
199,
893,
26,
523,
687,
3228,
14,
1548,
14,
3246,
492,
1900,
63,
815,
199,
2590,
3545,
26,
523,
746,
3545,
480,
6531,
440,
492,
3228,
14,
4226,
440,
492,
3228,
298,
490,
298,
504,
2399,
1350,
2082,
27,
1570,
2082,
370,
9682,
298,
490,
298,
1589,
9134,
1350,
3123,
12,
436,
295,
9850,
2195,
2018,
298,
490,
298,
20244,
687,
2337,
2685,
421,
199,
318,
32511,
63,
1074,
837,
523,
408,
1811,
376,
1919,
340,
314,
3734,
365,
440,
6657,
7526,
14,
819,
6218,
26,
272,
3545,
26,
982,
314,
1104,
477,
28853,
626,
314,
3734,
365,
440,
6657,
489,
7526,
12,
436,
19595,
370,
2248,
314,
9134,
8836,
911,
2449,
14,
523,
408,
523,
340,
747,
14,
354,
508,
298,
343,
582,
272,
327,
23115,
370,
2248,
1263,
577,
4464,
83,
626,
314,
2018,
3329,
8350,
641,
2544,
272,
327,
781,
2248,
314,
2018,
3329,
12,
880,
626,
781,
883,
746,
376,
1595,
461,
1125,
272,
327,
1245,
340,
2985,
787,
440,
1911,
14,
272,
492,
5577,
221,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
272,
340,
2688,
8,
1506,
63,
815,
12,
298,
706,
86,
1850,
63,
9259,
63,
354,
2349,
489,
862,
26,
267,
5577,
14,
8886,
15982,
8,
1506,
63,
815,
14,
706,
86,
1850,
63,
9259,
63,
354,
9,
489,
871,
6440,
26,
267,
746,
3545,
8,
288,
298,
6531,
440,
2342,
450,
82,
14,
9134,
5074,
626,
642,
577,
4464,
506,
298,
288,
298,
7657,
315,
282,
2082,
626,
365,
4310,
315,
2195,
11539,
3243,
8530,
298,
288,
298,
5418,
1750,
14,
2047,
1443,
3907,
642,
577,
4464,
701,
25937,
298,
288,
298,
15039,
445,
4176,
6900,
799,
20231,
2964,
6162,
650,
687,
642,
2851,
26,
298,
288,
298,
2859,
921,
1544,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4249,
15,
5087,
14,
26146,
31,
344,
29,
7920,
1555,
2,
288,
450,
1900,
63,
815,
14,
706,
86,
1850,
63,
9259,
63,
354,
9,
523,
587,
26,
272,
327,
3254,
8,
13118,
651,
304,
24413,
7791,
5920,
367,
314,
10130,
436,
10444,
4403,
1323,
14723,
14,
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
] |
[
1898,
9708,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
199,
624,
10397,
13,
6100,
1233,
367,
7907,
314,
4661,
12997,
402,
314,
9134,
1900,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
747,
421,
199,
893,
26,
523,
687,
3228,
14,
1548,
14,
3246,
492,
1900,
63,
815,
199,
2590,
3545,
26,
523,
746,
3545,
480,
6531,
440,
492,
3228,
14,
4226,
440,
492,
3228,
298,
490,
298,
504,
2399,
1350,
2082,
27,
1570,
2082,
370,
9682,
298,
490,
298,
1589,
9134,
1350,
3123,
12,
436,
295,
9850,
2195,
2018,
298,
490,
298,
20244,
687,
2337,
2685,
421,
199,
318,
32511,
63,
1074,
837,
523,
408,
1811,
376,
1919,
340,
314,
3734,
365,
440,
6657,
7526,
14,
819,
6218,
26,
272,
3545,
26,
982,
314,
1104,
477,
28853,
626,
314,
3734,
365,
440,
6657,
489,
7526,
12,
436,
19595,
370,
2248,
314,
9134,
8836,
911,
2449,
14,
523,
408,
523,
340,
747,
14,
354,
508,
298,
343,
582,
272,
327,
23115,
370,
2248,
1263,
577,
4464,
83,
626,
314,
2018,
3329,
8350,
641,
2544,
272,
327,
781,
2248,
314,
2018,
3329,
12,
880,
626,
781,
883,
746,
376,
1595,
461,
1125,
272,
327,
1245,
340,
2985,
787,
440,
1911,
14,
272,
492,
5577,
221,
327,
4287,
26,
3507,
29,
71,
13,
646,
13,
1397,
13,
292,
13,
2119,
272,
340,
2688,
8,
1506,
63,
815,
12,
298,
706,
86,
1850,
63,
9259,
63,
354,
2349,
489,
862,
26,
267,
5577,
14,
8886,
15982,
8,
1506,
63,
815,
14,
706,
86,
1850,
63,
9259,
63,
354,
9,
489,
871,
6440,
26,
267,
746,
3545,
8,
288,
298,
6531,
440,
2342,
450,
82,
14,
9134,
5074,
626,
642,
577,
4464,
506,
298,
288,
298,
7657,
315,
282,
2082,
626,
365,
4310,
315,
2195,
11539,
3243,
8530,
298,
288,
298,
5418,
1750,
14,
2047,
1443,
3907,
642,
577,
4464,
701,
25937,
298,
288,
298,
15039,
445,
4176,
6900,
799,
20231,
2964,
6162,
650,
687,
642,
2851,
26,
298,
288,
298,
2859,
921,
1544,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4249,
15,
5087,
14,
26146,
31,
344,
29,
7920,
1555,
2,
288,
450,
1900,
63,
815,
14,
706,
86,
1850,
63,
9259,
63,
354,
9,
523,
587,
26,
272,
327,
3254,
8,
13118,
651,
304,
24413,
7791,
5920,
367,
314,
10130,
436,
10444,
4403,
1323,
14723,
14,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
R4stl1n/allianceauth
|
allianceauth/groupmanagement/admin.py
|
5
|
2012
|
from django.contrib import admin
from django.contrib.auth.models import Group as BaseGroup
from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed
from django.dispatch import receiver
from .models import AuthGroup
from .models import GroupRequest
class AuthGroupInlineAdmin(admin.StackedInline):
model = AuthGroup
filter_horizontal = ('group_leaders',)
fields = ('description', 'group_leaders', 'internal', 'hidden', 'open', 'public')
verbose_name_plural = 'Auth Settings'
verbose_name = ''
def has_add_permission(self, request):
return False
def has_delete_permission(self, request, obj=None):
return False
def has_change_permission(self, request, obj=None):
return request.user.has_perm('auth.change_group')
class GroupAdmin(admin.ModelAdmin):
filter_horizontal = ('permissions',)
inlines = (AuthGroupInlineAdmin,)
class Group(BaseGroup):
class Meta:
proxy = True
verbose_name = BaseGroup._meta.verbose_name
verbose_name_plural = BaseGroup._meta.verbose_name_plural
try:
admin.site.unregister(BaseGroup)
finally:
admin.site.register(Group, GroupAdmin)
admin.site.register(GroupRequest)
@receiver(pre_save, sender=Group)
def redirect_pre_save(sender, signal=None, *args, **kwargs):
pre_save.send(BaseGroup, *args, **kwargs)
@receiver(post_save, sender=Group)
def redirect_post_save(sender, signal=None, *args, **kwargs):
post_save.send(BaseGroup, *args, **kwargs)
@receiver(pre_delete, sender=Group)
def redirect_pre_delete(sender, signal=None, *args, **kwargs):
pre_delete.send(BaseGroup, *args, **kwargs)
@receiver(post_delete, sender=Group)
def redirect_post_delete(sender, signal=None, *args, **kwargs):
post_delete.send(BaseGroup, *args, **kwargs)
@receiver(m2m_changed, sender=Group.permissions.through)
def redirect_m2m_changed_permissions(sender, signal=None, *args, **kwargs):
m2m_changed.send(BaseGroup, *args, **kwargs)
|
gpl-2.0
|
[
504,
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
5611,
465,
3523,
2448,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
2117,
12,
2963,
63,
2117,
12,
876,
63,
1807,
12,
2963,
63,
1807,
12,
333,
18,
77,
63,
2489,
199,
504,
1639,
14,
6052,
492,
13035,
199,
504,
1275,
992,
492,
3590,
2448,
199,
504,
1275,
992,
492,
5611,
2017,
421,
199,
533,
3590,
2448,
10307,
4880,
8,
2113,
14,
4851,
379,
10307,
304,
272,
1402,
275,
3590,
2448,
272,
2457,
63,
11392,
275,
661,
923,
63,
18498,
83,
9538,
272,
1504,
275,
661,
1802,
297,
283,
923,
63,
18498,
83,
297,
283,
4672,
297,
283,
5642,
297,
283,
1490,
297,
283,
3455,
358,
272,
3376,
63,
354,
63,
10019,
275,
283,
2817,
13303,
7,
272,
3376,
63,
354,
275,
2125,
339,
347,
965,
63,
525,
63,
5693,
8,
277,
12,
1056,
304,
267,
372,
756,
339,
347,
965,
63,
1807,
63,
5693,
8,
277,
12,
1056,
12,
1559,
29,
403,
304,
267,
372,
756,
339,
347,
965,
63,
1461,
63,
5693,
8,
277,
12,
1056,
12,
1559,
29,
403,
304,
267,
372,
1056,
14,
751,
14,
1989,
63,
8220,
360,
1178,
14,
1461,
63,
923,
358,
421,
199,
533,
5611,
4880,
8,
2113,
14,
12976,
304,
272,
2457,
63,
11392,
275,
661,
6060,
9538,
272,
29177,
275,
334,
2817,
2448,
10307,
4880,
4258,
421,
199,
533,
5611,
8,
1563,
2448,
304,
272,
1021,
6288,
26,
267,
4566,
275,
715,
267,
3376,
63,
354,
275,
3523,
2448,
423,
2024,
14,
3832,
63,
354,
267,
3376,
63,
354,
63,
10019,
275,
3523,
2448,
423,
2024,
14,
3832,
63,
354,
63,
10019,
199,
199,
893,
26,
272,
4628,
14,
2124,
14,
18408,
8,
1563,
2448,
9,
199,
15172,
26,
272,
4628,
14,
2124,
14,
2683,
8,
2448,
12,
5611,
4880,
9,
421,
199,
2113,
14,
2124,
14,
2683,
8,
2448,
2017,
9,
421,
199,
32,
10244,
8,
657,
63,
2117,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
657,
63,
2117,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
876,
63,
2117,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
1932,
63,
2117,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
1932,
63,
2117,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
2963,
63,
2117,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
657,
63,
1807,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
657,
63,
1807,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
876,
63,
1807,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
1932,
63,
1807,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
1932,
63,
1807,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
2963,
63,
1807,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
77,
18,
77,
63,
2489,
12,
8904,
29,
2448,
14,
6060,
14,
8304,
9,
199,
318,
4660,
63,
77,
18,
77,
63,
2489,
63,
6060,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
333,
18,
77,
63,
2489,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
492,
4628,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
5611,
465,
3523,
2448,
199,
504,
1639,
14,
697,
14,
992,
14,
10458,
492,
876,
63,
2117,
12,
2963,
63,
2117,
12,
876,
63,
1807,
12,
2963,
63,
1807,
12,
333,
18,
77,
63,
2489,
199,
504,
1639,
14,
6052,
492,
13035,
199,
504,
1275,
992,
492,
3590,
2448,
199,
504,
1275,
992,
492,
5611,
2017,
421,
199,
533,
3590,
2448,
10307,
4880,
8,
2113,
14,
4851,
379,
10307,
304,
272,
1402,
275,
3590,
2448,
272,
2457,
63,
11392,
275,
661,
923,
63,
18498,
83,
9538,
272,
1504,
275,
661,
1802,
297,
283,
923,
63,
18498,
83,
297,
283,
4672,
297,
283,
5642,
297,
283,
1490,
297,
283,
3455,
358,
272,
3376,
63,
354,
63,
10019,
275,
283,
2817,
13303,
7,
272,
3376,
63,
354,
275,
2125,
339,
347,
965,
63,
525,
63,
5693,
8,
277,
12,
1056,
304,
267,
372,
756,
339,
347,
965,
63,
1807,
63,
5693,
8,
277,
12,
1056,
12,
1559,
29,
403,
304,
267,
372,
756,
339,
347,
965,
63,
1461,
63,
5693,
8,
277,
12,
1056,
12,
1559,
29,
403,
304,
267,
372,
1056,
14,
751,
14,
1989,
63,
8220,
360,
1178,
14,
1461,
63,
923,
358,
421,
199,
533,
5611,
4880,
8,
2113,
14,
12976,
304,
272,
2457,
63,
11392,
275,
661,
6060,
9538,
272,
29177,
275,
334,
2817,
2448,
10307,
4880,
4258,
421,
199,
533,
5611,
8,
1563,
2448,
304,
272,
1021,
6288,
26,
267,
4566,
275,
715,
267,
3376,
63,
354,
275,
3523,
2448,
423,
2024,
14,
3832,
63,
354,
267,
3376,
63,
354,
63,
10019,
275,
3523,
2448,
423,
2024,
14,
3832,
63,
354,
63,
10019,
199,
199,
893,
26,
272,
4628,
14,
2124,
14,
18408,
8,
1563,
2448,
9,
199,
15172,
26,
272,
4628,
14,
2124,
14,
2683,
8,
2448,
12,
5611,
4880,
9,
421,
199,
2113,
14,
2124,
14,
2683,
8,
2448,
2017,
9,
421,
199,
32,
10244,
8,
657,
63,
2117,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
657,
63,
2117,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
876,
63,
2117,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
1932,
63,
2117,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
1932,
63,
2117,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
2963,
63,
2117,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
657,
63,
1807,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
657,
63,
1807,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
876,
63,
1807,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
1932,
63,
1807,
12,
8904,
29,
2448,
9,
199,
318,
4660,
63,
1932,
63,
1807,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
2963,
63,
1807,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
421,
199,
32,
10244,
8,
77,
18,
77,
63,
2489,
12,
8904,
29,
2448,
14,
6060,
14,
8304,
9,
199,
318,
4660,
63,
77,
18,
77,
63,
2489,
63,
6060,
8,
8114,
12,
4673,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
333,
18,
77,
63,
2489,
14,
2254,
8,
1563,
2448,
12,
627,
589,
12,
1011,
958,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
agentfog/qiime
|
tests/test_validate_mapping_file.py
|
15
|
84978
|
#!/usr/bin/env python
__author__ = "William Walters"
__copyright__ = "Copyright 2011, The QIIME Project" # consider project name
__credits__ = ["Rob Knight", "William Walters"] # remember to add yourself
__license__ = "GPL"
__version__ = "1.9.1-dev"
__maintainer__ = "William Walters"
__email__ = "william.a.walters@colorado.edu"
from os import close
from os.path import isdir, isfile, exists, join, basename
from tempfile import mkdtemp
from shutil import rmtree
from collections import defaultdict
from tempfile import mkstemp, mkdtemp
from unittest import TestCase, main
from skbio.util import remove_files
from skbio.util import create_dir
from qiime.check_id_map import (check_mapping_file, process_id_map,
check_data_fields, check_fields_past_bounds, check_chars_data_fields,
check_dna_chars_primers, check_dna_chars_bcs, check_bcs_lengths,
check_bc_duplicates, check_fixed_len_bcs_dups, check_variable_len_bcs_dups,
check_added_demultiplex_dups, check_sampleid_duplicates, check_header,
check_header_dups, check_header_chars, check_header_required_fields,
correct_mapping_data)
class CheckIdMapTests(TestCase):
def setUp(self):
# create the temporary input files that will be used
self._files_to_remove = []
# Input data
self.sample_correct_mapping_data = sample_correct_mapping_data
self.sample_errors_mapping_data = sample_errors_mapping_data
self.sample_warnings_mapping_data = sample_warnings_mapping_data
self.sample_errors_warnings_mapping_data =\
sample_errors_warnings_mapping_data
self.empty_fields_mapping_data = empty_fields_mapping_data
fd, self.correct_mapping_fp = mkstemp(
prefix='correct_mapping_',
suffix='.txt')
close(fd)
map_file = open(self.correct_mapping_fp, 'w')
map_file.write(self.sample_correct_mapping_data)
map_file.close()
fd, self.errors_mapping_fp = mkstemp(
prefix='errors_mapping_',
suffix='.txt')
close(fd)
map_file = open(self.errors_mapping_fp, 'w')
map_file.write(self.sample_errors_mapping_data)
map_file.close()
fd, self.empty_fields_fp = mkstemp(
prefix='empty_fields_',
suffix='.txt')
close(fd)
map_file = open(self.empty_fields_fp, 'w')
map_file.write(self.empty_fields_mapping_data)
map_file.close()
fd, self.warnings_mapping_fp = mkstemp(
prefix='warnings_mapping_',
suffix='.txt')
close(fd)
map_file = open(self.warnings_mapping_fp, 'w')
map_file.write(self.sample_warnings_mapping_data)
map_file.close()
fd, self.errors_warnings_mapping_fp = mkstemp(
prefix='errors_warnings_mapping_',
suffix='.txt')
close(fd)
map_file = open(self.errors_warnings_mapping_fp, 'w')
map_file.write(self.sample_errors_warnings_mapping_data)
map_file.close()
# Output data
self.expected_html_data_correct_input = expected_html_data_correct_input
self.expected_corrected_data_correct_input =\
expected_corrected_data_correct_input
self.expected_log_data_correct_input = expected_log_data_correct_input
self.expected_html_errors_output = expected_html_errors_output
self.expected_data_errors_corrected_output =\
expected_data_errors_corrected_output
self.expected_data_log_errors_output = expected_data_log_errors_output
self.expected_html_errors_suppressed_bcs =\
expected_html_errors_suppressed_bcs
self.expected_output_log_errors_bcs_suppressed =\
expected_output_log_errors_bcs_suppressed
self.expected_html_output_warnings = expected_html_output_warnings
self.expected_corrected_warnings_output =\
expected_corrected_warnings_output
self.expected_log_warnings_output =\
expected_log_warnings_output
self.expected_html_errors_warnings_output =\
expected_html_errors_warnings_output
self.expected_corrected_data_errors_warnings =\
expected_corrected_data_errors_warnings
self.expected_log_errors_warnings_output =\
expected_log_errors_warnings_output
self.output_dir = mkdtemp()
self.output_dir += '/'
create_dir(self.output_dir)
self._files_to_remove =\
[self.correct_mapping_fp, self.errors_mapping_fp,
self.warnings_mapping_fp, self.errors_warnings_mapping_fp,
self.empty_fields_fp]
def tearDown(self):
if self._files_to_remove:
remove_files(self._files_to_remove)
if exists(self.output_dir):
rmtree(self.output_dir)
def test_check_mapping_file_correct_file(self):
""" Gives proper files for valid mapping files """
# Use valid data, default parameters
check_mapping_file(mapping_fp=self.correct_mapping_fp,
output_dir=self.output_dir,
verbose=False)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_data_correct_input)
self.assertEqual(corrected_data,
self.expected_corrected_data_correct_input)
self.assertEqual(log_data, self.expected_log_data_correct_input)
# With additional parameters added should not change results using
# same valid input data
check_mapping_file(mapping_fp=self.correct_mapping_fp,
output_dir=self.output_dir,
has_barcodes=True,
char_replace="A",
verbose=False,
variable_len_barcodes=True,
disable_primer_check=True,
added_demultiplex_field=None)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.correct_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_data_correct_input)
self.assertEqual(corrected_data,
self.expected_corrected_data_correct_input)
self.assertEqual(log_data, self.expected_log_data_correct_input)
def test_check_mapping_file_errors(self):
""" Gives proper files for errors in mapping files """
# Use data with errors, default parameters
check_mapping_file(mapping_fp=self.errors_mapping_fp,
output_dir=self.output_dir,
verbose=False)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_errors_output)
self.assertEqual(corrected_data,
self.expected_data_errors_corrected_output)
self.assertEqual(log_data, self.expected_data_log_errors_output)
def test_check_mapping_file_errors_suppressed_bcs(self):
""" Should suppress errors about barcodes if bcs turned off """
# Should not flag bcs for errors with invalid characters
check_mapping_file(mapping_fp=self.errors_mapping_fp,
output_dir=self.output_dir,
has_barcodes=False,
char_replace="A",
verbose=False,
variable_len_barcodes=True,
disable_primer_check=True,
added_demultiplex_field=None)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.errors_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_errors_suppressed_bcs)
self.assertEqual(corrected_data,
self.expected_data_errors_corrected_output)
self.assertEqual(log_data,
self.expected_output_log_errors_bcs_suppressed)
def test_check_mapping_file_warnings(self):
""" Gives proper files for warnings in mapping files """
check_mapping_file(mapping_fp=self.warnings_mapping_fp,
output_dir=self.output_dir,
verbose=False)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.warnings_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.warnings_mapping_fp).replace('.txt', '_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.warnings_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_output_warnings)
self.assertEqual(corrected_data,
self.expected_corrected_warnings_output)
self.assertEqual(log_data, self.expected_log_warnings_output)
def test_check_mapping_file_multiple_problems(self):
""" Gives proper files for combinations of errors/warnings """
check_mapping_file(mapping_fp=self.errors_warnings_mapping_fp,
output_dir=self.output_dir,
added_demultiplex_field="DoesNotExist",
verbose=False)
# Check existence of expected output files
output_html_fp = join(self.output_dir,
basename(self.errors_warnings_mapping_fp).replace('.txt', '.html'))
output_corrected_fp =\
join(self.output_dir,
basename(self.errors_warnings_mapping_fp).replace('.txt',
'_corrected.txt'))
output_log_fp =\
join(self.output_dir,
basename(self.errors_warnings_mapping_fp).replace('.txt', '.log'))
overlib_js_fp = join(self.output_dir, 'overlib.js')
self.assertTrue(exists(output_html_fp))
self.assertTrue(exists(output_corrected_fp))
self.assertTrue(exists(output_log_fp))
self.assertTrue(exists(overlib_js_fp))
# Check output data for expected results
html_data = "".join([line for line in open(output_html_fp, "U")])
corrected_data =\
"".join([line for line in open(output_corrected_fp, "U")])
log_data = "".join([line for line in open(output_log_fp, "U")])
self.assertEqual(html_data, self.expected_html_errors_warnings_output)
self.assertEqual(corrected_data,
self.expected_corrected_data_errors_warnings)
self.assertEqual(log_data, self.expected_log_errors_warnings_output)
def test_process_id_map_correct_data(self):
""" Returns expected results for correct mapping data """
header, mapping_data, comments, errors, warnings =\
process_id_map(self.correct_mapping_fp)
expected_header = [
'SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Treatment',
'ReversePrimer',
'Description']
expected_mapping_data = [['PC.354',
'AGCACGAGCCTA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._354'],
['PC.355',
'AACTCGTCGATG',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._355'],
['PC.356',
'ACAGACCACTCA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._356']]
expected_comments = [
'Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).']
expected_errors = []
expected_warnings = []
self.assertEqual(header, expected_header)
self.assertEqual(mapping_data, expected_mapping_data)
self.assertEqual(comments, expected_comments)
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_process_id_map_errors(self):
""" Returns expected results for mapping data with errors """
header, mapping_data, comments, errors, warnings =\
process_id_map(self.errors_mapping_fp)
expected_header = [
'SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Treatment',
'ReversePrimer',
'NotDescription']
expected_mapping_data = [['PC.355',
'AGCACGAGCCxTA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._354'],
['PC.355',
'AACTCGTCGATG',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._355'],
['PC.356',
'ACAGACCACTCA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._356']]
expected_comments = [
'Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).']
expected_errors = [
'Found header field NotDescription, last field should be Description\t0,5',
'Invalid DNA sequence detected: AGCACGAGCCxTA\t1,1',
'Duplicate SampleID PC.355 found.\t1,0',
'Duplicate SampleID PC.355 found.\t2,0']
expected_warnings = [
'Barcode AGCACGAGCCxTA differs than length 12\t1,1']
self.assertEqual(header, expected_header)
self.assertEqual(mapping_data, expected_mapping_data)
self.assertEqual(comments, expected_comments)
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_process_id_map_empty_data_fields(self):
""" Returns expected results for mapping data with missing fields """
header, mapping_data, comments, errors, warnings =\
process_id_map(self.empty_fields_fp)
expected_header = [
'SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Treatment',
'ReversePrimer',
'Description']
expected_mapping_data = [['PC.354',
'AGCACGAGCCTA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._354'],
['PC.355',
'AACTCGTCGATG',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'',
''],
['PC.356',
'ACAGACCACTCA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._356']]
expected_comments = [
'Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).']
expected_errors = ['Missing expected DNA sequence\t2,4']
expected_warnings = [
'Empty data field found\t2,4',
'Empty data field found\t2,5']
self.assertEqual(header, expected_header)
self.assertEqual(mapping_data, expected_mapping_data)
self.assertEqual(comments, expected_comments)
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_process_id_map_warnings(self):
""" Returns expected results for mapping data with warnings """
header, mapping_data, comments, errors, warnings =\
process_id_map(self.warnings_mapping_fp)
expected_header = [
'SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Treatm-ent',
'ReversePrimer',
'Description']
expected_mapping_data = [['PC.354',
'AGCACGAGCCTA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._354'],
['PC_355',
'AACTCGTCGATG',
'YATGCTGCCTCCCGTAGGAGT',
'Co&ntrol',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._355',
'OutOfBounds'],
['PC.356',
'ACAGACCACTCA',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._356']]
expected_comments = [
'Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).']
expected_errors = []
expected_warnings = [
'Found invalid character in Treatm-ent header field.\t0,3',
'Invalid characters found in PC_355\t2,0',
'Invalid characters found in Co&ntrol\t2,3',
'Data field OutOfBounds found after Description column\t2,6']
self.assertEqual(header, expected_header)
self.assertEqual(mapping_data, expected_mapping_data)
self.assertEqual(comments, expected_comments)
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_process_id_map_multiple_problems(self):
""" Returns expected results for combinations of problems """
header, mapping_data, comments, errors, warnings =\
process_id_map(self.errors_warnings_mapping_fp)
expected_header = [
'SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Treatment',
'Treatment',
'Description']
expected_mapping_data = [['PC.354',
'AGCACGAGCCTA',
'YATGCTGCCTCCCGTAGGAGT',
'Cont^^rol',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._354'],
['PC-355',
'AACTCGTCGATGN',
'YATGCTGCCTCCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._355',
'outofbounds'],
['PC.356',
'ACAGACCACTCA',
'YATGCTGCCTCxCCGTAGGAGT',
'Control',
'ATGACCGATTRGACCAG',
'Control_mouse_I.D._356']]
expected_comments = [
'Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).']
expected_errors = [
'Treatment found in header 2 times. Header fields must be unique.\t0,3',
'Treatment found in header 2 times. Header fields must be unique.\t0,4',
'Invalid DNA sequence detected: YATGCTGCCTCxCCGTAGGAGT\t3,2',
'Invalid DNA sequence detected: AACTCGTCGATGN\t2,1']
expected_warnings = [
'Barcode AACTCGTCGATGN differs than length 12\t2,1',
'Invalid characters found in PC-355\t2,0',
'Invalid characters found in Cont^^rol\t1,3',
'Data field outofbounds found after Description column\t2,6']
self.assertEqual(header, expected_header)
self.assertEqual(mapping_data, expected_mapping_data)
self.assertEqual(comments, expected_comments)
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_data_fields(self):
""" Overall data fields check returns expected results """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s1', 'ACGT', 'AAAA', 's1_data'],
['s2', 'CGTA', 'AAAA', 's2_data']]
errors = []
warnings = []
errors, warnings = check_data_fields(header,
mapping_data, errors, warnings)
expected_errors = []
expected_warnings = []
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_data_fields_errors_warnings(self):
""" Overall data fields check returns expected results """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s1', 'ACGT', 'AAAxA', 's1_data'],
['s_2', 'CGTA', 'AAAA', 's2_data']]
errors = []
warnings = []
errors, warnings = check_data_fields(header,
mapping_data, errors, warnings)
expected_errors = ['Invalid DNA sequence detected: AAAxA\t1,2']
expected_warnings = ['Invalid characters found in s_2\t2,0']
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_fields_past_bounds(self):
""" Flags fields found past the Description column as warnings """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s1', 'ACGT', 'AAAA', 's1_data'],
['s2', 'CGTA', 'AAAA', 's2_data', 'out_of_bounds']]
warnings = []
warnings = check_fields_past_bounds(header, mapping_data, warnings)
expected_warnings =\
['Data field out_of_bounds found after Description column\t2,4']
self.assertEqual(warnings, expected_warnings)
def test_check_chars_data_fields(self):
""" Flags fields with invalid characters as warnings """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', 's1&data'],
['s2', 'CGTA', 'AAAA', 's2_data']]
warnings = []
warnings = check_chars_data_fields(header, mapping_data, warnings)
expected_warnings = ['Invalid characters found in s-1\t1,0',
'Invalid characters found in s1&data\t1,3']
self.assertEqual(warnings, expected_warnings)
def test_check_dna_chars_primers(self):
""" Flags primer fields with invalid characters as errors """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 's1&data'],
['s2', 'CGTA', 'AAA1A', 's2_data']]
errors = []
errors = check_dna_chars_primers(header, mapping_data, errors)
expected_errors = ['Invalid DNA sequence detected: AAA1A\t2,2']
self.assertEqual(errors, expected_errors)
# Should be able to suppress LinkerPrimerSequence check, won't
# suppress ReversePrimer check
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'ReversePrimer', 'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 'ACGT', 's1&data'],
['s2', 'CGTA', 'AAA1A', 'ACGTF', 's2_data']]
errors = []
errors = check_dna_chars_primers(header, mapping_data, errors,
disable_primer_check=True)
expected_errors = ['Invalid DNA sequence detected: ACGTF\t2,3']
self.assertEqual(errors, expected_errors)
def test_check_dna_chars_bcs(self):
""" Flags barcode fields with invalid characters as errors """
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 's1&data'],
['s2', 'CGTA', 'AAA1A', 's2_data']]
errors = []
errors = check_dna_chars_bcs(header, mapping_data, errors)
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should find no errors
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'ReversePrimer', 'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 'ACGT', 's1&data'],
['s2', 'C1GTA', 'AAA1A', 'ACGTF', 's2_data']]
errors = []
errors = check_dna_chars_bcs(header, mapping_data, errors,
has_barcodes=False)
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should find errors with has_barcodes=True
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'ReversePrimer', 'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 'ACGT', 's1&data'],
['s2', 'CNGTA', 'AAA1A', 'ACGTF', 's2_data']]
errors = []
errors = check_dna_chars_bcs(header, mapping_data, errors,
has_barcodes=True)
expected_errors = ['Invalid DNA sequence detected: CNGTA\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_bcs_lengths(self):
""" Flags barcodes of different lengths as warnings """
# should not give any warnings for equal lengths
header =\
['SampleID',
'BarcodeSequence',
'LinkerPrimerSequence',
'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 's1&data'],
['s2', 'CGTA', 'AAA1A', 's2_data']]
warnings = []
warnings = check_bcs_lengths(header, mapping_data, warnings)
expected_warnings = []
self.assertEqual(warnings, expected_warnings)
# Should give warning for different lengths
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'ReversePrimer', 'Description']
mapping_data = [['s-1', 'ACGT', 'AARNCWSVDAA', 'ACGT', 's1&data'],
['s2', 'C1GTA', 'AAA1A', 'ACGTF', 's2_data'],
['s3', 'CGTA', 'AAAAA', 'ACGTF', 's3_data']]
warnings = []
warnings = check_bcs_lengths(header, mapping_data, warnings)
expected_warnings = ['Barcode C1GTA differs than length 4\t2,1']
self.assertEqual(warnings, expected_warnings)
def test_check_bc_duplicates_default_correct(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=False,
added_demultiplex_field=None)
expected_errors = []
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_default_dups(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=False,
added_demultiplex_field=None)
expected_errors = ['Duplicate barcode ACGT found.\t1,1',
'Duplicate barcode ACGT found.\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_disable_bcs_dups(self):
""" Handles duplicate checks of no barcodes or added demultiplex data """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=False,
variable_len_barcodes=False,
added_demultiplex_field=None)
# Should return an error if more than one SampleID present and
# barcodes disabled and no added_demultiplex_field
expected_errors = [
"If no barcodes are present, and the added_demultiplex_field option isn't used, only a single SampleID can be present.\t-1,-1"]
self.assertEqual(errors, expected_errors)
# If a single sample present, should not raise any errors
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=False,
variable_len_barcodes=False,
added_demultiplex_field=None)
expected_errors = []
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_var_len_no_dupes(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGTA', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'TAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=True,
added_demultiplex_field=None)
# combination of primer seq and barcodes to match largest barcode
# present is ACGTA and ACGTT, so should not get a duplicate hit.
expected_errors = []
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_var_len_dupes(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGTA', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=True,
added_demultiplex_field=None)
# Barcode 1 is the largest, with 5 nts, is sequence ACGTA. When the
# last base at 5' end of primer is added to barcode 2, there is a
# duplicate, as this is also ACGTA.
expected_errors = [
'Duplicate barcode and primer fragment sequence ACGTA found.\t1,1',
'Duplicate barcode and primer fragment sequence ACGTA found.\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_added_demultiplex(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
# Should not find any duplicates
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=False,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should not find any duplicates with var length turned on.
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=True,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should not find errors when only looking at added field
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=False,
variable_len_barcodes=False,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
def test_check_bc_duplicates_added_demultiplex_finds_dups(self):
""" Handles duplicate checks of barcodes and added demultiplex data """
# Should find duplicates
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'CGTA', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '1', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=False,
added_demultiplex_field='run_prefix')
expected_errors = [
'Duplicate barcode and added demultiplex field CGTA1 found.\t1,1',
'Duplicate barcode and added demultiplex field CGTA1 found.\t2,1']
self.assertEqual(errors, expected_errors)
# Should find duplicates with var length turned on
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'CGTA', 'AAAA', '1', 's1&data'],
['s2', 'CGTAA', 'AAAA', '1', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=True,
variable_len_barcodes=True,
added_demultiplex_field='run_prefix')
expected_errors = [
'Duplicate barcode and added demultiplex field CGTAA1 found.\t1,1',
'Duplicate barcode and added demultiplex field CGTAA1 found.\t2,1']
self.assertEqual(errors, expected_errors)
# Should find duplicates when just using added fields
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'CGTA', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '1', 's2_data']]
errors = []
errors = check_bc_duplicates(header,
mapping_data,
errors,
has_barcodes=False,
variable_len_barcodes=False,
added_demultiplex_field='run_prefix')
expected_errors = [
'Duplicate added demultiplex field 1 found.\t1,3',
'Duplicate added demultiplex field 1 found.\t2,3']
self.assertEqual(errors, expected_errors)
def test_check_fixed_len_bcs_dups(self):
""" Properly detects duplicates of fixed length barcodes """
# Should not find any duplicates
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_fixed_len_bcs_dups(header,
mapping_data,
errors)
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should find duplicates
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'CGTA', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_fixed_len_bcs_dups(header,
mapping_data,
errors)
expected_errors = [
'Duplicate barcode CGTA found.\t1,1',
'Duplicate barcode CGTA found.\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_fixed_len_bcs_dups_mixed_caps(self):
# Should find duplicates with mixed caps
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'CGTA', 'AAAA', '1', 's1&data'],
['s2', 'cgta', 'AAAA', '2', 's2_data']]
errors = []
errors = check_fixed_len_bcs_dups(header,
mapping_data,
errors)
expected_errors = [
'Duplicate barcode CGTA found.\t1,1',
'Duplicate barcode CGTA found.\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_variable_len_bcs_dups(self):
""" Ensures that slices of barcodes + 5' primer fragments are unique """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGTA', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'TAAA', '2', 's2_data']]
errors = []
errors = check_variable_len_bcs_dups(header,
mapping_data,
errors)
# combination of primer seq and barcodes to match largest barcode
# present is ACGTA and ACGTT, so should not get a duplicate hit.
expected_errors = []
self.assertEqual(errors, expected_errors)
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGTA', 'AAAA', '1', 's1&data'],
['s2', 'ACGT', 'AAAA', '2', 's2_data']]
errors = []
errors = check_variable_len_bcs_dups(header,
mapping_data,
errors)
# Barcode 1 is the largest, with 5 nts, is sequence ACGTA. When the
# last base at 5' end of primer is added to barcode 2, there is a
# duplicate, as this is also ACGTA.
expected_errors = [
'Duplicate barcode and primer fragment sequence ACGTA found.\t1,1',
'Duplicate barcode and primer fragment sequence ACGTA found.\t2,1']
self.assertEqual(errors, expected_errors)
def test_check_added_demultiplex_dups(self):
""" Checks barcodes/added demultiplex field for unique combinations """
# Should not find any duplicates
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_added_demultiplex_dups(header, mapping_data, errors,
has_barcodes=True, added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should not find any duplicates with var length turned on.
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_added_demultiplex_dups(header,
mapping_data,
errors,
has_barcodes=True,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should not find errors when only looking at added field
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_added_demultiplex_dups(header,
mapping_data,
errors,
has_barcodes=False,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
def test_check_sampleid_duplicates(self):
""" Checks that all SampleIDs are unique """
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s2', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_sampleid_duplicates(header, mapping_data, errors)
# Should not find duplicates
expected_errors = []
self.assertEqual(errors, expected_errors)
header =\
['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [['s-1', 'ACGT', 'AAAA', '1', 's1&data'],
['s-1', 'CGTA', 'AAAA', '2', 's2_data']]
errors = []
errors = check_sampleid_duplicates(header, mapping_data, errors)
# Should find duplicates
expected_errors = [
'Duplicate SampleID s-1 found.\t1,0',
'Duplicate SampleID s-1 found.\t2,0']
self.assertEqual(errors, expected_errors)
def test_check_header(self):
""" All header problems are detected """
# Default header, should not generate any errors/warnings
header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'Description']
errors = []
warnings = []
errors, warnings = check_header(header,
errors,
warnings,
sample_id_ix=0,
desc_ix=3,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field=None)
expected_errors = []
expected_warnings = []
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_header_missing_fields(self):
""" All header problems are detected """
# Default header, should not generate any errors/warnings
header = ['AAA', 'XXX', 'YYY',
'ZZZ']
errors = []
warnings = []
errors, warnings = check_header(header,
errors,
warnings,
sample_id_ix=0,
desc_ix=3,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field=None)
expected_errors = [
'Found header field AAA, expected field SampleID\t0,0',
'Found header field XXX, expected field BarcodeSequence\t0,1',
'Found header field YYY, expected field LinkerPrimerSequence\t0,2',
'Found header field ZZZ, last field should be Description\t0,3']
expected_warnings = []
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_header_bad_chars(self):
""" All header problems are detected """
# Default header, should not generate any errors/warnings
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'AAA.^^2',
'Description']
errors = []
warnings = []
errors, warnings = check_header(header,
errors,
warnings,
sample_id_ix=0,
desc_ix=4,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field=None)
expected_errors = []
expected_warnings = [
'Found invalid character in AAA.^^2 header field.\t0,3']
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_header_missing_added_demultiplex(self):
""" All header problems are detected """
# Default header, should not generate any errors/warnings
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
errors = []
warnings = []
errors, warnings = check_header(header,
errors,
warnings,
sample_id_ix=0,
desc_ix=4,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field='run_prefix')
expected_errors = []
expected_warnings = []
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
# Default header, should not generate any errors/warnings
header = ['SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
'Description']
errors = []
warnings = []
errors, warnings = check_header(header,
errors,
warnings,
sample_id_ix=0,
desc_ix=3,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field='run_prefix')
expected_errors = ['Missing added demultiplex field run_prefix\t-1,-1']
expected_warnings = []
self.assertEqual(errors, expected_errors)
self.assertEqual(warnings, expected_warnings)
def test_check_header_dups(self):
""" Flags header duplicates as errors """
# Default header, should not generate any errors/warnings
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
errors = []
errors = check_header_dups(header, errors)
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should give errors with dups
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix', 'run_prefix',
'Description']
errors = []
errors = check_header_dups(header, errors)
expected_errors = [
'run_prefix found in header 2 times. Header fields must be unique.\t0,3',
'run_prefix found in header 2 times. Header fields must be unique.\t0,4']
self.assertEqual(errors, expected_errors)
def test_check_header_chars(self):
""" Flags invalid characters in header as warnings """
# Default header, should not generate any errors/warnings
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_p-%efix',
'Description']
warnings = []
warnings = check_header_chars(header, warnings)
expected_warnings = [
'Found invalid character in run_p-%efix header field.\t0,3']
self.assertEqual(warnings, expected_warnings)
def test_check_header_required_fields(self):
""" Flags missing header fields as errors """
# Default header, should not generate any errors/warnings
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
errors = []
errors = check_header_required_fields(header,
errors,
sample_id_ix=0,
desc_ix=4,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field='run_prefix')
expected_errors = []
self.assertEqual(errors, expected_errors)
# Should find all as errors if not named correctly
header = ['AAA', 'BBB', 'CCC', 'DDD',
'EEE']
errors = []
errors = check_header_required_fields(header,
errors,
sample_id_ix=0,
desc_ix=4,
bc_ix=1,
linker_primer_ix=2,
added_demultiplex_field='run_prefix')
expected_errors = [
'Found header field AAA, expected field SampleID\t0,0',
'Found header field BBB, expected field BarcodeSequence\t0,1',
'Found header field CCC, expected field LinkerPrimerSequence\t0,2',
'Found header field EEE, last field should be Description\t0,4',
'Missing added demultiplex field run_prefix\t-1,-1']
self.assertEqual(errors, expected_errors)
def test_correct_mapping_data(self):
""" Properly replaces invalid characters in mapping data """
header = [
'SampleID', 'BarcodeSequence', 'LinkerPrimerSequence', 'run_prefix',
'Description']
mapping_data = [
['AA_2', 'ACCAAGGACTT', 'ACGGATACCGAGx', '26^3', 'A-2'],
['AA.3', 'ACAGGATAAC', 'ARRACGGA', '12__', 'AA%3']]
corrected_data = correct_mapping_data(mapping_data, header)
# Should replace SampleID invalid characters with periods, other
# invalid characters with underscores, should not change DNA fields.
expected_corrected_data = [['AA.2',
'ACCAAGGACTT',
'ACGGATACCGAGx',
'26_3',
'A-2'],
['AA.3',
'ACAGGATAAC',
'ARRACGGA',
'12__',
'AA%3']]
self.assertEqual(corrected_data, expected_corrected_data)
# Input data
sample_correct_mapping_data = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment ReversePrimer Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._355
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356"""
sample_errors_mapping_data = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment ReversePrimer NotDescription
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.355 AGCACGAGCCxTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._355
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356"""
sample_warnings_mapping_data = """#SampleID BarcodeSequence LinkerPrimerSequence Treatm-ent ReversePrimer Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC_355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Co&ntrol ATGACCGATTRGACCAG Control_mouse_I.D._355 OutOfBounds
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356"""
sample_errors_warnings_mapping_data = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment Treatment Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Cont^^rol ATGACCGATTRGACCAG Control_mouse_I.D._354
PC-355 AACTCGTCGATGN YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._355 outofbounds
PC.356 ACAGACCACTCA YATGCTGCCTCxCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356"""
empty_fields_mapping_data = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment ReversePrimer Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Control
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356"""
# Expected output data
expected_html_data_correct_input = """<html>\n<head>\n\n<script type="text/javascript" src="./overlib.js"></script>\n</head>\n<body bgcolor="white"> <h1>No errors or warnings detected.<br></h1><h1>Mapping file error and warning details.</h1>\nNotes for interpreting this report:\n<ul>\n <li>Errors will be listed in red, warnings in yellow.\n <li>Mouse over an error or warning in a cell for more details.\n <li>Errors in the header row may mask other errors, so these should be corrected first.\n <li>Modifications to your mapping file to fix certain issues may result in different errors. You should run <tt>validate_mapping_file.py</tt> until no errors (nor warnings, ideally) are found.\n</ul>\n<p>\nSome general rules about formatting mapping files (see <a href="http://qiime.org/documentation/file_formats.html#metadata-mapping-files">here</a> for additional details):\n<ul>\n <li>Header characters should only contain alphanumeric and <tt>_</tt> characters only.\n <li>Valid characters for SampleID fields are alphanumeric and <tt>.</tt> only.<br>\n <li>Other fields allow alphanumeric and <tt>+-%./ :,;_</tt> characters.\n</ul>\nGeneral issues with your mapping file (i.e., those that do not pertain to a particular cell) will be listed here, if any:<table border="1" cellspacing="0" cellpadding="7"><tr></tr></table><br>\n<table border="2" cellspacing="0" cellpadding="5">\n\n<tr></tr>\n<tr>\n<th>SampleID</th><th>BarcodeSequence</th><th>LinkerPrimerSequence</th><th>Treatment</th><th>ReversePrimer</th><th>Description</th>\n</tr>\n\n<tr>\n<tr><th><tt>PC.354</tt></th><th><tt>AGCACGAGCCTA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._354\n</tt></th></tr><tr><th><tt>PC.355</tt></th><th><tt>AACTCGTCGATG</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._355\n</tt></th></tr><tr><th><tt>PC.356</tt></th><th><tt>ACAGACCACTCA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._356</tt></th></tr>\n</tr>\n</table>\n\n</body>\n</html>"""
expected_corrected_data_correct_input = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment ReversePrimer Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._355
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356
"""
expected_log_data_correct_input = """No errors or warnings found in mapping file."""
expected_html_errors_output = """<html>\n<head>\n\n<script type="text/javascript" src="./overlib.js"></script>\n</head>\n<body bgcolor="white"> <h1>Mapping file error and warning details.</h1>\nNotes for interpreting this report:\n<ul>\n <li>Errors will be listed in red, warnings in yellow.\n <li>Mouse over an error or warning in a cell for more details.\n <li>Errors in the header row may mask other errors, so these should be corrected first.\n <li>Modifications to your mapping file to fix certain issues may result in different errors. You should run <tt>validate_mapping_file.py</tt> until no errors (nor warnings, ideally) are found.\n</ul>\n<p>\nSome general rules about formatting mapping files (see <a href="http://qiime.org/documentation/file_formats.html#metadata-mapping-files">here</a> for additional details):\n<ul>\n <li>Header characters should only contain alphanumeric and <tt>_</tt> characters only.\n <li>Valid characters for SampleID fields are alphanumeric and <tt>.</tt> only.<br>\n <li>Other fields allow alphanumeric and <tt>+-%./ :,;_</tt> characters.\n</ul>\nGeneral issues with your mapping file (i.e., those that do not pertain to a particular cell) will be listed here, if any:<table border="1" cellspacing="0" cellpadding="7"><tr></tr></table><br>\n<table border="2" cellspacing="0" cellpadding="5">\n\n<tr></tr>\n<tr>\n<th>SampleID</th><th>BarcodeSequence</th><th>LinkerPrimerSequence</th><th>Treatment</th><th>ReversePrimer</th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Found header field NotDescription, last field should be Description<br>\');" onmouseout="return nd();"><font color=white>NotDescription</a></th>\n</tr>\n\n<tr>\n<tr><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Duplicate SampleID PC.355 found.<br>Location (SampleID,Header Field)<br>PC.355,SampleID\');" onmouseout="return nd();"><font color=white><tt>PC.355</tt></a></th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Barcode AGCACGAGCCxTA differs than length 12<br>Invalid DNA sequence detected: AGCACGAGCCxTA<br>Location (SampleID,Header Field)<br>PC.355,BarcodeSequence\');" onmouseout="return nd();"><font color=white><tt>AGCACGAGCCxTA</tt></a></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._354\n</tt></th></tr><tr><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Duplicate SampleID PC.355 found.<br>Location (SampleID,Header Field)<br>PC.355,SampleID\');" onmouseout="return nd();"><font color=white><tt>PC.355</tt></a></th><th><tt>AACTCGTCGATG</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._355\n</tt></th></tr><tr><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in PC.356<br>Location (SampleID,Header Field)<br> PC.356,SampleID\');" onmouseout="return nd();"><font color=black><tt> PC.356</tt></a></th><th><tt>ACAGACCACTCA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._356</tt></th></tr>\n</tr>\n</table>\n\n</body>\n</html>"""
expected_data_errors_corrected_output = """#SampleID\tBarcodeSequence\tLinkerPrimerSequence\tTreatment\tReversePrimer\tNotDescription\n#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).\nPC.355\tAGCACGAGCCxTA\tYATGCTGCCTCCCGTAGGAGT\tControl\tATGACCGATTRGACCAG\tControl_mouse_I.D._354\nPC.355\tAACTCGTCGATG\tYATGCTGCCTCCCGTAGGAGT\tControl\tATGACCGATTRGACCAG\tControl_mouse_I.D._355\n.PC.356\tACAGACCACTCA\tYATGCTGCCTCCCGTAGGAGT\tControl\tATGACCGATTRGACCAG\tControl_mouse_I.D._356\n"""
expected_data_log_errors_output = """# Errors and warnings are written as a tab separated columns, with the first column showing the error or warning, and the second column contains the location of the error or warning, written as row,column, where 0,0 is the top left header item (SampleID). Problems not specific to a particular data cell will be listed as having 'no location'.\nErrors -----------------------------\nFound header field NotDescription, last field should be Description\t0,5\nInvalid DNA sequence detected: AGCACGAGCCxTA\t1,1\nDuplicate SampleID PC.355 found.\t1,0\nDuplicate SampleID PC.355 found.\t2,0\nWarnings ---------------------------\nBarcode AGCACGAGCCxTA differs than length 12\t1,1\nInvalid characters found in PC.356\t3,0\n"""
expected_html_errors_suppressed_bcs = """<html>\n<head>\n\n<script type="text/javascript" src="./overlib.js"></script>\n</head>\n<body bgcolor="white"> <h1>Mapping file error and warning details.</h1>\nNotes for interpreting this report:\n<ul>\n <li>Errors will be listed in red, warnings in yellow.\n <li>Mouse over an error or warning in a cell for more details.\n <li>Errors in the header row may mask other errors, so these should be corrected first.\n <li>Modifications to your mapping file to fix certain issues may result in different errors. You should run <tt>validate_mapping_file.py</tt> until no errors (nor warnings, ideally) are found.\n</ul>\n<p>\nSome general rules about formatting mapping files (see <a href="http://qiime.org/documentation/file_formats.html#metadata-mapping-files">here</a> for additional details):\n<ul>\n <li>Header characters should only contain alphanumeric and <tt>_</tt> characters only.\n <li>Valid characters for SampleID fields are alphanumeric and <tt>.</tt> only.<br>\n <li>Other fields allow alphanumeric and <tt>+-%./ :,;_</tt> characters.\n</ul>\nGeneral issues with your mapping file (i.e., those that do not pertain to a particular cell) will be listed here, if any:<table border="1" cellspacing="0" cellpadding="7"><tr><td bgcolor="red"><font color="white">If no barcodes are present, and the added_demultiplex_field option isn\'t used, only a single SampleID can be present.<font color="black"></td></tr></table><br>\n<table border="2" cellspacing="0" cellpadding="5">\n\n<tr></tr>\n<tr>\n<th>SampleID</th><th>BarcodeSequence</th><th>LinkerPrimerSequence</th><th>Treatment</th><th>ReversePrimer</th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Found header field NotDescription, last field should be Description<br>\');" onmouseout="return nd();"><font color=white>NotDescription</a></th>\n</tr>\n\n<tr>\n<tr><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Duplicate SampleID PC.355 found.<br>Location (SampleID,Header Field)<br>PC.355,SampleID\');" onmouseout="return nd();"><font color=white><tt>PC.355</tt></a></th><th><tt>AGCACGAGCCxTA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._354\n</tt></th></tr><tr><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Duplicate SampleID PC.355 found.<br>Location (SampleID,Header Field)<br>PC.355,SampleID\');" onmouseout="return nd();"><font color=white><tt>PC.355</tt></a></th><th><tt>AACTCGTCGATG</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._355\n</tt></th></tr><tr><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in PC.356<br>Location (SampleID,Header Field)<br> PC.356,SampleID\');" onmouseout="return nd();"><font color=black><tt> PC.356</tt></a></th><th><tt>ACAGACCACTCA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._356</tt></th></tr>\n</tr>\n</table>\n\n</body>\n</html>"""
expected_output_log_errors_bcs_suppressed = """# Errors and warnings are written as a tab separated columns, with the first column showing the error or warning, and the second column contains the location of the error or warning, written as row,column, where 0,0 is the top left header item (SampleID). Problems not specific to a particular data cell will be listed as having 'no location'.\nErrors -----------------------------\nFound header field NotDescription, last field should be Description\t0,5\nIf no barcodes are present, and the added_demultiplex_field option isn't used, only a single SampleID can be present.\tno location\nDuplicate SampleID PC.355 found.\t1,0\nDuplicate SampleID PC.355 found.\t2,0\nWarnings ---------------------------\nInvalid characters found in PC.356\t3,0\n"""
expected_html_output_warnings = """<html>\n<head>\n\n<script type="text/javascript" src="./overlib.js"></script>\n</head>\n<body bgcolor="white"> <h1>Mapping file error and warning details.</h1>\nNotes for interpreting this report:\n<ul>\n <li>Errors will be listed in red, warnings in yellow.\n <li>Mouse over an error or warning in a cell for more details.\n <li>Errors in the header row may mask other errors, so these should be corrected first.\n <li>Modifications to your mapping file to fix certain issues may result in different errors. You should run <tt>validate_mapping_file.py</tt> until no errors (nor warnings, ideally) are found.\n</ul>\n<p>\nSome general rules about formatting mapping files (see <a href="http://qiime.org/documentation/file_formats.html#metadata-mapping-files">here</a> for additional details):\n<ul>\n <li>Header characters should only contain alphanumeric and <tt>_</tt> characters only.\n <li>Valid characters for SampleID fields are alphanumeric and <tt>.</tt> only.<br>\n <li>Other fields allow alphanumeric and <tt>+-%./ :,;_</tt> characters.\n</ul>\nGeneral issues with your mapping file (i.e., those that do not pertain to a particular cell) will be listed here, if any:<table border="1" cellspacing="0" cellpadding="7"><tr></tr></table><br>\n<table border="2" cellspacing="0" cellpadding="5">\n\n<tr></tr>\n<tr>\n<th>SampleID</th><th>BarcodeSequence</th><th>LinkerPrimerSequence</th><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Found invalid character in Treatm-ent header field.<br>\');" onmouseout="return nd();"><font color=black>Treatm-ent</a></th><th>ReversePrimer</th><th>Description</th>\n</tr>\n\n<tr>\n<tr><th><tt>PC.354</tt></th><th><tt>AGCACGAGCCTA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._354\n</tt></th></tr><tr><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in PC_355<br>Location (SampleID,Header Field)<br>PC_355,SampleID\');" onmouseout="return nd();"><font color=black><tt>PC_355</tt></a></th><th><tt>AACTCGTCGATG</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in Co&ntrol<br>Location (SampleID,Header Field)<br>PC_355,Treatm-ent\');" onmouseout="return nd();"><font color=black><tt>Co&ntrol</tt></a></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._355</tt></th><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Data field OutOfBounds found after Description column<br>Location (SampleID,Header Field)<br>PC_355,no header\');" onmouseout="return nd();"><font color=black><tt>OutOfBounds\n</tt></a></th></tr><tr><th><tt>PC.356</tt></th><th><tt>ACAGACCACTCA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._356</tt></th></tr>\n</tr>\n</table>\n\n</body>\n</html>"""
expected_corrected_warnings_output = """#SampleID BarcodeSequence LinkerPrimerSequence Treatm-ent ReversePrimer Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATG YATGCTGCCTCCCGTAGGAGT Co_ntrol ATGACCGATTRGACCAG Control_mouse_I.D._355 OutOfBounds
PC.356 ACAGACCACTCA YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356
"""
expected_log_warnings_output = """# Errors and warnings are written as a tab separated columns, with the first column showing the error or warning, and the second column contains the location of the error or warning, written as row,column, where 0,0 is the top left header item (SampleID). Problems not specific to a particular data cell will be listed as having 'no location'.
Errors -----------------------------
Warnings ---------------------------
Found invalid character in Treatm-ent header field. 0,3
Invalid characters found in PC_355 2,0
Invalid characters found in Co&ntrol 2,3
Data field OutOfBounds found after Description column 2,6
"""
expected_html_errors_warnings_output = """<html>\n<head>\n\n<script type="text/javascript" src="./overlib.js"></script>\n</head>\n<body bgcolor="white"> <h1>Mapping file error and warning details.</h1>\nNotes for interpreting this report:\n<ul>\n <li>Errors will be listed in red, warnings in yellow.\n <li>Mouse over an error or warning in a cell for more details.\n <li>Errors in the header row may mask other errors, so these should be corrected first.\n <li>Modifications to your mapping file to fix certain issues may result in different errors. You should run <tt>validate_mapping_file.py</tt> until no errors (nor warnings, ideally) are found.\n</ul>\n<p>\nSome general rules about formatting mapping files (see <a href="http://qiime.org/documentation/file_formats.html#metadata-mapping-files">here</a> for additional details):\n<ul>\n <li>Header characters should only contain alphanumeric and <tt>_</tt> characters only.\n <li>Valid characters for SampleID fields are alphanumeric and <tt>.</tt> only.<br>\n <li>Other fields allow alphanumeric and <tt>+-%./ :,;_</tt> characters.\n</ul>\nGeneral issues with your mapping file (i.e., those that do not pertain to a particular cell) will be listed here, if any:<table border="1" cellspacing="0" cellpadding="7"><tr><td bgcolor="red"><font color="white">Missing added demultiplex field DoesNotExist<font color="black"></td></tr></table><br>\n<table border="2" cellspacing="0" cellpadding="5">\n\n<tr></tr>\n<tr>\n<th>SampleID</th><th>BarcodeSequence</th><th>LinkerPrimerSequence</th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Treatment found in header 2 times. Header fields must be unique.<br>\');" onmouseout="return nd();"><font color=white>Treatment</a></th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Treatment found in header 2 times. Header fields must be unique.<br>\');" onmouseout="return nd();"><font color=white>Treatment</a></th><th>Description</th>\n</tr>\n\n<tr>\n<tr><th><tt>PC.354</tt></th><th><tt>AGCACGAGCCTA</tt></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in Cont^^rol<br>Location (SampleID,Header Field)<br>PC.354,Treatment\');" onmouseout="return nd();"><font color=black><tt>Cont^^rol</tt></a></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._354\n</tt></th></tr><tr><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid characters found in PC-355<br>Location (SampleID,Header Field)<br>PC-355,SampleID\');" onmouseout="return nd();"><font color=black><tt>PC-355</tt></a></th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Barcode AACTCGTCGATGN differs than length 12<br>Invalid DNA sequence detected: AACTCGTCGATGN<br>Location (SampleID,Header Field)<br>PC-355,BarcodeSequence\');" onmouseout="return nd();"><font color=white><tt>AACTCGTCGATGN</tt></a></th><th><tt>YATGCTGCCTCCCGTAGGAGT</tt></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._355</tt></th><th bgcolor=yellow><a href="javascript:void(0);" onmouseover="return overlib(\'Data field outofbounds found after Description column<br>Location (SampleID,Header Field)<br>PC-355,no header\');" onmouseout="return nd();"><font color=black><tt>outofbounds\n</tt></a></th></tr><tr><th><tt>PC.356</tt></th><th><tt>ACAGACCACTCA</tt></th><th bgcolor=red><a href="javascript:void(0);" onmouseover="return overlib(\'Invalid DNA sequence detected: YATGCTGCCTCxCCGTAGGAGT<br>Location (SampleID,Header Field)<br>PC.356,LinkerPrimerSequence\');" onmouseout="return nd();"><font color=white><tt>YATGCTGCCTCxCCGTAGGAGT</tt></a></th><th><tt>Control</tt></th><th><tt>ATGACCGATTRGACCAG</tt></th><th><tt>Control_mouse_I.D._356</tt></th></tr>\n</tr>\n</table>\n\n</body>\n</html>"""
expected_corrected_data_errors_warnings = """#SampleID BarcodeSequence LinkerPrimerSequence Treatment Treatment Description
#Example mapping file for the QIIME analysis package. These 9 samples are from a study of the effects of exercise and diet on mouse cardiac physiology (Crawford, et al, PNAS, 2009).
PC.354 AGCACGAGCCTA YATGCTGCCTCCCGTAGGAGT Cont__rol ATGACCGATTRGACCAG Control_mouse_I.D._354
PC.355 AACTCGTCGATGN YATGCTGCCTCCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._355 outofbounds
PC.356 ACAGACCACTCA YATGCTGCCTCxCCGTAGGAGT Control ATGACCGATTRGACCAG Control_mouse_I.D._356
"""
expected_log_errors_warnings_output = """# Errors and warnings are written as a tab separated columns, with the first column showing the error or warning, and the second column contains the location of the error or warning, written as row,column, where 0,0 is the top left header item (SampleID). Problems not specific to a particular data cell will be listed as having 'no location'.
Errors -----------------------------
Treatment found in header 2 times. Header fields must be unique. 0,3
Treatment found in header 2 times. Header fields must be unique. 0,4
Missing added demultiplex field DoesNotExist no location
Invalid DNA sequence detected: YATGCTGCCTCxCCGTAGGAGT 3,2
Invalid DNA sequence detected: AACTCGTCGATGN 2,1
Warnings ---------------------------
Barcode AACTCGTCGATGN differs than length 12 2,1
Invalid characters found in PC-355 2,0
Invalid characters found in Cont^^rol 1,3
Data field outofbounds found after Description column 2,6
"""
if __name__ == '__main__':
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
363,
2502,
363,
275,
298,
55,
8148,
455,
644,
31185,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
7290,
2,
221,
327,
11201,
2199,
536,
199,
363,
22461,
363,
275,
2097,
50,
2873,
1804,
14873,
401,
298,
55,
8148,
455,
644,
31185,
937,
221,
327,
21027,
370,
1050,
28225,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
55,
8148,
455,
644,
31185,
2,
199,
363,
2123,
363,
275,
298,
87,
8148,
455,
14,
65,
14,
20877,
878,
32,
2326,
5129,
14,
8654,
2,
199,
199,
504,
747,
492,
4002,
199,
504,
747,
14,
515,
492,
26004,
12,
29214,
12,
3495,
12,
4263,
12,
9593,
199,
504,
5549,
492,
31781,
199,
504,
5145,
492,
20978,
199,
504,
5055,
492,
10018,
199,
504,
5549,
492,
333,
6080,
808,
12,
31781,
199,
199,
504,
2882,
492,
7640,
12,
2446,
199,
504,
11448,
2308,
14,
1974,
492,
2813,
63,
1725,
199,
504,
11448,
2308,
14,
1974,
492,
1218,
63,
694,
199,
199,
504,
31402,
1036,
14,
1074,
63,
344,
63,
1130,
492,
334,
1074,
63,
4745,
63,
493,
12,
2112,
63,
344,
63,
1130,
12,
1816,
1104,
63,
576,
63,
955,
12,
1104,
63,
955,
63,
18597,
63,
9632,
12,
1104,
63,
6574,
63,
576,
63,
955,
12,
1816,
1104,
63,
21075,
63,
6574,
63,
12446,
2393,
12,
1104,
63,
21075,
63,
6574,
63,
66,
1259,
12,
1104,
63,
66,
1259,
63,
14563,
12,
1816,
1104,
63,
3776,
63,
18563,
12,
1104,
63,
5964,
63,
552,
63,
66,
1259,
63,
11048,
83,
12,
1104,
63,
1975,
63,
552,
63,
66,
1259,
63,
11048,
83,
12,
1816,
1104,
63,
3270,
63,
271,
6048,
88,
63,
11048,
83,
12,
1104,
63,
3271,
344,
63,
18563,
12,
1104,
63,
1291,
12,
1816,
1104,
63,
1291,
63,
11048,
83,
12,
1104,
63,
1291,
63,
6574,
12,
1104,
63,
1291,
63,
2427,
63,
955,
12,
1816,
3211,
63,
4745,
63,
576,
9,
421,
199,
533,
2670,
1304,
2956,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
1218,
314,
7937,
1324,
1584,
626,
911,
506,
1202,
398,
291,
423,
1725,
63,
475,
63,
2168,
275,
942,
398,
327,
6924,
666,
267,
291,
14,
3271,
63,
4525,
63,
4745,
63,
576,
275,
2690,
63,
4525,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
2550,
63,
4745,
63,
576,
275,
2690,
63,
2550,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
5451,
63,
4745,
63,
576,
275,
2690,
63,
5451,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
2550,
63,
5451,
63,
4745,
63,
576,
26447,
288,
2690,
63,
2550,
63,
5451,
63,
4745,
63,
576,
267,
291,
14,
1667,
63,
955,
63,
4745,
63,
576,
275,
2701,
63,
955,
63,
4745,
63,
576,
398,
6111,
12,
291,
14,
4525,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
4525,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
4525,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
4525,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
2550,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
2550,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
2550,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
2550,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
1667,
63,
955,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
1667,
63,
955,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
1667,
63,
955,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
1667,
63,
955,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
5451,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
5451,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
5451,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
5451,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
2550,
63,
5451,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
2550,
63,
5451,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
2550,
63,
5451,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
2550,
63,
5451,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
327,
7242,
666,
267,
291,
14,
2062,
63,
1360,
63,
576,
63,
4525,
63,
1210,
275,
1420,
63,
1360,
63,
576,
63,
4525,
63,
1210,
267,
291,
14,
2062,
63,
28125,
63,
576,
63,
4525,
63,
1210,
26447,
288,
1420,
63,
28125,
63,
576,
63,
4525,
63,
1210,
267,
291,
14,
2062,
63,
793,
63,
576,
63,
4525,
63,
1210,
275,
1420,
63,
793,
63,
576,
63,
4525,
63,
1210,
398,
291,
14,
2062,
63,
1360,
63,
2550,
63,
1199,
275,
1420,
63,
1360,
63,
2550,
63,
1199,
267,
291,
14,
2062,
63,
576,
63,
2550,
63,
28125,
63,
1199,
26447,
288,
1420,
63,
576,
63,
2550,
63,
28125,
63,
1199,
267,
291,
14,
2062,
63,
576,
63,
793,
63,
2550,
63,
1199,
275,
1420,
63,
576,
63,
793,
63,
2550,
63,
1199,
267,
291,
14,
2062,
63,
1360,
63,
2550,
63,
8621,
5111,
63,
66,
1259,
26447,
288,
1420,
63,
1360,
63,
2550,
63,
8621,
5111,
63,
66,
1259,
267
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
363,
2502,
363,
275,
298,
55,
8148,
455,
644,
31185,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
7290,
2,
221,
327,
11201,
2199,
536,
199,
363,
22461,
363,
275,
2097,
50,
2873,
1804,
14873,
401,
298,
55,
8148,
455,
644,
31185,
937,
221,
327,
21027,
370,
1050,
28225,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
55,
8148,
455,
644,
31185,
2,
199,
363,
2123,
363,
275,
298,
87,
8148,
455,
14,
65,
14,
20877,
878,
32,
2326,
5129,
14,
8654,
2,
199,
199,
504,
747,
492,
4002,
199,
504,
747,
14,
515,
492,
26004,
12,
29214,
12,
3495,
12,
4263,
12,
9593,
199,
504,
5549,
492,
31781,
199,
504,
5145,
492,
20978,
199,
504,
5055,
492,
10018,
199,
504,
5549,
492,
333,
6080,
808,
12,
31781,
199,
199,
504,
2882,
492,
7640,
12,
2446,
199,
504,
11448,
2308,
14,
1974,
492,
2813,
63,
1725,
199,
504,
11448,
2308,
14,
1974,
492,
1218,
63,
694,
199,
199,
504,
31402,
1036,
14,
1074,
63,
344,
63,
1130,
492,
334,
1074,
63,
4745,
63,
493,
12,
2112,
63,
344,
63,
1130,
12,
1816,
1104,
63,
576,
63,
955,
12,
1104,
63,
955,
63,
18597,
63,
9632,
12,
1104,
63,
6574,
63,
576,
63,
955,
12,
1816,
1104,
63,
21075,
63,
6574,
63,
12446,
2393,
12,
1104,
63,
21075,
63,
6574,
63,
66,
1259,
12,
1104,
63,
66,
1259,
63,
14563,
12,
1816,
1104,
63,
3776,
63,
18563,
12,
1104,
63,
5964,
63,
552,
63,
66,
1259,
63,
11048,
83,
12,
1104,
63,
1975,
63,
552,
63,
66,
1259,
63,
11048,
83,
12,
1816,
1104,
63,
3270,
63,
271,
6048,
88,
63,
11048,
83,
12,
1104,
63,
3271,
344,
63,
18563,
12,
1104,
63,
1291,
12,
1816,
1104,
63,
1291,
63,
11048,
83,
12,
1104,
63,
1291,
63,
6574,
12,
1104,
63,
1291,
63,
2427,
63,
955,
12,
1816,
3211,
63,
4745,
63,
576,
9,
421,
199,
533,
2670,
1304,
2956,
2925,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
327,
1218,
314,
7937,
1324,
1584,
626,
911,
506,
1202,
398,
291,
423,
1725,
63,
475,
63,
2168,
275,
942,
398,
327,
6924,
666,
267,
291,
14,
3271,
63,
4525,
63,
4745,
63,
576,
275,
2690,
63,
4525,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
2550,
63,
4745,
63,
576,
275,
2690,
63,
2550,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
5451,
63,
4745,
63,
576,
275,
2690,
63,
5451,
63,
4745,
63,
576,
267,
291,
14,
3271,
63,
2550,
63,
5451,
63,
4745,
63,
576,
26447,
288,
2690,
63,
2550,
63,
5451,
63,
4745,
63,
576,
267,
291,
14,
1667,
63,
955,
63,
4745,
63,
576,
275,
2701,
63,
955,
63,
4745,
63,
576,
398,
6111,
12,
291,
14,
4525,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
4525,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
4525,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
4525,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
2550,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
2550,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
2550,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
2550,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
1667,
63,
955,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
1667,
63,
955,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
1667,
63,
955,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
1667,
63,
955,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
5451,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
5451,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
5451,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
5451,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
6111,
12,
291,
14,
2550,
63,
5451,
63,
4745,
63,
3997,
275,
333,
6080,
808,
8,
288,
2403,
534,
2550,
63,
5451,
63,
4745,
14474,
288,
4739,
15637,
2424,
358,
267,
4002,
8,
2592,
9,
267,
2341,
63,
493,
275,
1551,
8,
277,
14,
2550,
63,
5451,
63,
4745,
63,
3997,
12,
283,
87,
358,
267,
2341,
63,
493,
14,
952,
8,
277,
14,
3271,
63,
2550,
63,
5451,
63,
4745,
63,
576,
9,
267,
2341,
63,
493,
14,
1600,
342,
398,
327,
7242,
666,
267,
291,
14,
2062,
63,
1360,
63,
576,
63,
4525,
63,
1210,
275,
1420,
63,
1360,
63,
576,
63,
4525,
63,
1210,
267,
291,
14,
2062,
63,
28125,
63,
576,
63,
4525,
63,
1210,
26447,
288,
1420,
63,
28125,
63,
576,
63,
4525,
63,
1210,
267,
291,
14,
2062,
63,
793,
63,
576,
63,
4525,
63,
1210,
275,
1420,
63,
793,
63,
576,
63,
4525,
63,
1210,
398,
291,
14,
2062,
63,
1360,
63,
2550,
63,
1199,
275,
1420,
63,
1360,
63,
2550,
63,
1199,
267,
291,
14,
2062,
63,
576,
63,
2550,
63,
28125,
63,
1199,
26447,
288,
1420,
63,
576,
63,
2550,
63,
28125,
63,
1199,
267,
291,
14,
2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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
] |
ruud-v-a/servo
|
etc/servo_gdb.py
|
20
|
4281
|
# Copyright 2013 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# A set of simple pretty printers for gdb to make debugging Servo a bit easier.
# To load these, you need to add something like the following
# to your .gdbinit file.
#python
#import sys
#sys.path.insert(0, '/home/<path to git checkout>/servo/src/etc')
#import servo_gdb
#servo_gdb.register_printers(None)
#end
import gdb
# Print Au in both raw value and CSS pixels
class AuPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
i32_type = gdb.lookup_type("i32")
au = self.val.cast(i32_type);
return "{0}px".format(au / 60.0)
# Print a U8 bitfield as binary
class BitFieldU8Printer:
def __init__(self, val):
self.val = val
def to_string(self):
u8_type = gdb.lookup_type("u8")
value = self.val.cast(u8_type);
return "[{0:#010b}]".format(int(value))
# Print a struct with fields as children
class ChildPrinter:
def __init__(self, val):
self.val = val
def children(self):
children = []
for f in self.val.type.fields():
children.append( (f.name, self.val[f.name]) )
return children
def to_string(self):
return None
# Allow a trusted node to be dereferenced in the debugger
class TrustedNodeAddressPrinter:
def __init__(self, val):
self.val = val
def children(self):
node_type = gdb.lookup_type("struct script::dom::node::Node").pointer()
value = self.val.cast(node_type)
return [('Node', value)]
def to_string(self):
return self.val.address
# Extract a node type ID from enum
class NodeTypeIdPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
u8_ptr_type = gdb.lookup_type("u8").pointer()
enum_0 = self.val.address.cast(u8_ptr_type).dereference()
enum_type = self.val.type.fields()[int(enum_0)].type;
return str(enum_type).lstrip('struct ')
# Printer for std::Option<>
class OptionPrinter:
def __init__(self, val):
self.val = val
def is_some(self):
# Get size of discriminator
d_size = self.val.type.fields()[0].type.sizeof
if d_size > 0 and d_size <= 8:
# Read first byte to check if None or Some
ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer())
discriminator = int(ptr.dereference())
return discriminator != 0
raise "unhandled discriminator size"
def children(self):
if self.is_some():
option_type = self.val.type
# Get total size and size of value
ptr = self.val.address.cast(gdb.lookup_type("unsigned char").pointer())
t_size = option_type.sizeof
value_type = option_type.fields()[1].type.fields()[1].type
v_size = value_type.sizeof
data_ptr = (ptr + t_size - v_size).cast(value_type.pointer()).dereference()
return [('Some', data_ptr)]
return [('None', None)]
def to_string(self):
return None
# Useful for debugging when type is unknown
class TestPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
return "[UNKNOWN - type = {0}]".format(str(self.val.type))
type_map = [
('struct Au', AuPrinter),
('FlowFlags', BitFieldU8Printer),
('IntrinsicWidths', ChildPrinter),
('PlacementInfo', ChildPrinter),
('TrustedNodeAddress', TrustedNodeAddressPrinter),
('NodeTypeId', NodeTypeIdPrinter),
('Option', OptionPrinter),
]
def lookup_servo_type (val):
val_type = str(val.type)
for (type_name, printer) in type_map:
if val_type == type_name or val_type.endswith("::"+type_name):
return printer(val)
return None
#return TestPrinter(val)
def register_printers(obj):
gdb.pretty_printers.append(lookup_servo_type)
|
mpl-2.0
|
[
3,
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
3,
437,
663,
402,
3486,
7268,
5448,
11005,
367,
12124,
370,
1852,
10201,
3739,
2392,
282,
4546,
14905,
14,
199,
199,
3,
4005,
2248,
3520,
12,
1265,
1929,
370,
1050,
6020,
2839,
314,
2569,
199,
3,
370,
2195,
1275,
17119,
826,
570,
14,
199,
3,
1548,
199,
3,
646,
984,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
1994,
4219,
8316,
515,
370,
6135,
15243,
12202,
25943,
15,
2164,
15,
6839,
358,
199,
3,
646,
8926,
2392,
63,
17119,
199,
3,
25943,
63,
17119,
14,
2683,
63,
24858,
8,
403,
9,
199,
3,
500,
199,
199,
646,
12124,
199,
199,
3,
9101,
31853,
315,
3865,
3066,
574,
436,
15750,
11094,
199,
533,
31853,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
284,
708,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
73,
708,
531,
267,
10576,
275,
291,
14,
637,
14,
2931,
8,
73,
708,
63,
466,
2736,
267,
372,
5310,
16,
93,
5326,
1674,
908,
8,
3844,
1182,
5212,
14,
16,
9,
199,
199,
3,
9101,
282,
738,
24,
4546,
698,
465,
3366,
199,
533,
10199,
792,
53,
24,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
399,
24,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
85,
24,
531,
267,
574,
275,
291,
14,
637,
14,
2931,
8,
85,
24,
63,
466,
2736,
267,
372,
7369,
91,
16,
15596,
9523,
66,
11049,
1674,
908,
8,
442,
8,
585,
430,
199,
199,
3,
9101,
282,
2702,
543,
1504,
465,
4978,
199,
533,
12988,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
4978,
8,
277,
304,
267,
4978,
275,
942,
267,
367,
289,
315,
291,
14,
637,
14,
466,
14,
955,
837,
288,
4978,
14,
740,
8,
334,
70,
14,
354,
12,
291,
14,
637,
59,
70,
14,
354,
566,
776,
267,
372,
4978,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
488,
199,
199,
3,
9812,
282,
19427,
1031,
370,
506,
477,
22355,
315,
314,
14958,
199,
533,
28814,
7274,
1716,
1476,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
4978,
8,
277,
304,
267,
1031,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
1820,
2884,
447,
4556,
447,
932,
447,
1716,
3471,
3929,
342,
267,
574,
275,
291,
14,
637,
14,
2931,
8,
932,
63,
466,
9,
267,
372,
4274,
1716,
297,
574,
1874,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
291,
14,
637,
14,
1562,
199,
199,
3,
12892,
282,
1031,
730,
2870,
687,
4952,
199,
533,
5013,
2568,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
399,
24,
63,
4695,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
85,
24,
3471,
3929,
342,
267,
4952,
63,
16,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
85,
24,
63,
4695,
63,
466,
680,
27915,
342,
267,
4952,
63,
466,
275,
291,
14,
637,
14,
466,
14,
955,
3430,
442,
8,
4869,
63,
16,
22509,
466,
27,
267,
372,
620,
8,
4869,
63,
466,
680,
10124,
360,
1820,
5320,
199,
199,
3,
25716,
1058,
367,
2418,
447,
2602,
16137,
199,
533,
3207,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
365,
63,
3972,
8,
277,
304,
267,
327,
2372,
1568,
402,
487,
24565,
267,
366,
63,
890,
275,
291,
14,
637,
14,
466,
14,
955,
3430,
16,
1055,
466,
14,
12590,
398,
340,
366,
63,
890,
690,
378,
436,
366,
63,
890,
2695,
1695,
26,
288,
327,
5574,
1642,
3696,
370,
1104,
340,
488,
503,
6601,
288,
12448,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
17119,
14,
3892,
63,
466,
480,
2244,
1495,
3471,
3929,
1012,
288,
487,
24565,
275,
1109,
8,
4695,
14,
27915,
1012,
288,
372,
487,
24565,
1137,
378,
398,
746,
298,
23648,
487,
24565,
1568,
2,
339,
347,
4978,
8,
277,
304,
267,
340,
291,
14,
374,
63,
3972,
837,
288,
945,
63,
466,
275,
291,
14,
637,
14,
466,
953,
327,
2372,
3141,
1568,
436,
1568,
402,
574,
288,
12448,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
17119,
14,
3892,
63,
466,
480,
2244,
1495,
3471,
3929,
1012,
288,
307,
63,
890,
275,
945,
63,
466,
14,
12590,
288,
574,
63,
466,
275,
945,
63,
466,
14,
955,
3430,
17,
1055,
466,
14,
955,
3430,
17,
1055,
466,
288,
373,
63,
890,
275,
574,
63,
466,
14,
12590,
288,
666,
63,
4695,
275,
334,
4695,
435,
307,
63,
890,
446,
373,
63,
890,
680,
2931,
8,
585,
63,
466,
14,
3929,
8801,
27915,
342,
288,
372,
4274,
7700,
297,
666,
63,
4695,
1874,
267,
372,
4274,
403,
297,
488,
1874,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
488,
199,
199,
3,
18491,
367,
10201,
1380,
730,
365,
5809,
199,
533,
1379,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
7369,
11588,
446,
730,
275,
469,
16,
11049,
1674,
908,
8,
495,
8,
277,
14,
637,
14,
466,
430,
199,
199
] |
[
1898,
6171,
710,
3739,
2392,
7290,
23493,
14,
1666,
314,
5877,
199,
3,
570,
737,
314,
2746,
13,
1896,
2082,
402,
642,
4084,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
665,
3961,
13,
1282,
33,
4576,
503,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
30,
503,
314,
10697,
4190,
199,
3,
665,
3961,
13,
13965,
503,
1455,
921,
16374,
14,
1308,
15,
2383,
15,
13965,
6244,
737,
2195,
199,
3,
945,
14,
961,
570,
1443,
440,
506,
8876,
12,
6042,
12,
503,
1854,
199,
3,
871,
7182,
370,
5204,
2895,
14,
199,
199,
3,
437,
663,
402,
3486,
7268,
5448,
11005,
367,
12124,
370,
1852,
10201,
3739,
2392,
282,
4546,
14905,
14,
199,
199,
3,
4005,
2248,
3520,
12,
1265,
1929,
370,
1050,
6020,
2839,
314,
2569,
199,
3,
370,
2195,
1275,
17119,
826,
570,
14,
199,
3,
1548,
199,
3,
646,
984,
199,
3,
1274,
14,
515,
14,
3176,
8,
16,
12,
1994,
4219,
8316,
515,
370,
6135,
15243,
12202,
25943,
15,
2164,
15,
6839,
358,
199,
3,
646,
8926,
2392,
63,
17119,
199,
3,
25943,
63,
17119,
14,
2683,
63,
24858,
8,
403,
9,
199,
3,
500,
199,
199,
646,
12124,
199,
199,
3,
9101,
31853,
315,
3865,
3066,
574,
436,
15750,
11094,
199,
533,
31853,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
284,
708,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
73,
708,
531,
267,
10576,
275,
291,
14,
637,
14,
2931,
8,
73,
708,
63,
466,
2736,
267,
372,
5310,
16,
93,
5326,
1674,
908,
8,
3844,
1182,
5212,
14,
16,
9,
199,
199,
3,
9101,
282,
738,
24,
4546,
698,
465,
3366,
199,
533,
10199,
792,
53,
24,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
399,
24,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
85,
24,
531,
267,
574,
275,
291,
14,
637,
14,
2931,
8,
85,
24,
63,
466,
2736,
267,
372,
7369,
91,
16,
15596,
9523,
66,
11049,
1674,
908,
8,
442,
8,
585,
430,
199,
199,
3,
9101,
282,
2702,
543,
1504,
465,
4978,
199,
533,
12988,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
4978,
8,
277,
304,
267,
4978,
275,
942,
267,
367,
289,
315,
291,
14,
637,
14,
466,
14,
955,
837,
288,
4978,
14,
740,
8,
334,
70,
14,
354,
12,
291,
14,
637,
59,
70,
14,
354,
566,
776,
267,
372,
4978,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
488,
199,
199,
3,
9812,
282,
19427,
1031,
370,
506,
477,
22355,
315,
314,
14958,
199,
533,
28814,
7274,
1716,
1476,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
4978,
8,
277,
304,
267,
1031,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
1820,
2884,
447,
4556,
447,
932,
447,
1716,
3471,
3929,
342,
267,
574,
275,
291,
14,
637,
14,
2931,
8,
932,
63,
466,
9,
267,
372,
4274,
1716,
297,
574,
1874,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
291,
14,
637,
14,
1562,
199,
199,
3,
12892,
282,
1031,
730,
2870,
687,
4952,
199,
533,
5013,
2568,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
399,
24,
63,
4695,
63,
466,
275,
12124,
14,
3892,
63,
466,
480,
85,
24,
3471,
3929,
342,
267,
4952,
63,
16,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
85,
24,
63,
4695,
63,
466,
680,
27915,
342,
267,
4952,
63,
466,
275,
291,
14,
637,
14,
466,
14,
955,
3430,
442,
8,
4869,
63,
16,
22509,
466,
27,
267,
372,
620,
8,
4869,
63,
466,
680,
10124,
360,
1820,
5320,
199,
199,
3,
25716,
1058,
367,
2418,
447,
2602,
16137,
199,
533,
3207,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
365,
63,
3972,
8,
277,
304,
267,
327,
2372,
1568,
402,
487,
24565,
267,
366,
63,
890,
275,
291,
14,
637,
14,
466,
14,
955,
3430,
16,
1055,
466,
14,
12590,
398,
340,
366,
63,
890,
690,
378,
436,
366,
63,
890,
2695,
1695,
26,
288,
327,
5574,
1642,
3696,
370,
1104,
340,
488,
503,
6601,
288,
12448,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
17119,
14,
3892,
63,
466,
480,
2244,
1495,
3471,
3929,
1012,
288,
487,
24565,
275,
1109,
8,
4695,
14,
27915,
1012,
288,
372,
487,
24565,
1137,
378,
398,
746,
298,
23648,
487,
24565,
1568,
2,
339,
347,
4978,
8,
277,
304,
267,
340,
291,
14,
374,
63,
3972,
837,
288,
945,
63,
466,
275,
291,
14,
637,
14,
466,
953,
327,
2372,
3141,
1568,
436,
1568,
402,
574,
288,
12448,
275,
291,
14,
637,
14,
1562,
14,
2931,
8,
17119,
14,
3892,
63,
466,
480,
2244,
1495,
3471,
3929,
1012,
288,
307,
63,
890,
275,
945,
63,
466,
14,
12590,
288,
574,
63,
466,
275,
945,
63,
466,
14,
955,
3430,
17,
1055,
466,
14,
955,
3430,
17,
1055,
466,
288,
373,
63,
890,
275,
574,
63,
466,
14,
12590,
288,
666,
63,
4695,
275,
334,
4695,
435,
307,
63,
890,
446,
373,
63,
890,
680,
2931,
8,
585,
63,
466,
14,
3929,
8801,
27915,
342,
288,
372,
4274,
7700,
297,
666,
63,
4695,
1874,
267,
372,
4274,
403,
297,
488,
1874,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
488,
199,
199,
3,
18491,
367,
10201,
1380,
730,
365,
5809,
199,
533,
1379,
14131,
26,
272,
347,
636,
826,
721,
277,
12,
1139,
304,
267,
291,
14,
637,
275,
1139,
339,
347,
370,
63,
875,
8,
277,
304,
267,
372,
7369,
11588,
446,
730,
275,
469,
16,
11049,
1674,
908,
8,
495,
8,
277,
14,
637,
14,
466,
430,
199,
199,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Averroes/autokey
|
src/lib/gtkui/settingsdialog.py
|
46
|
9114
|
# -*- coding: utf-8 -*-
# Copyright (C) 2011 Chris Dekter
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, sys
from gi.repository import Gtk
from autokey.configmanager import *
from autokey import iomediator, model, common
from dialogs import GlobalHotkeyDialog
import configwindow
DESKTOP_FILE = "/usr/share/applications/autokey-gtk.desktop"
AUTOSTART_DIR = os.path.expanduser("~/.config/autostart")
AUTOSTART_FILE = os.path.join(AUTOSTART_DIR, "autokey-gtk.desktop")
ICON_NAME_MAP = {
_("Light") : common.ICON_FILE_NOTIFICATION,
_("Dark") : common.ICON_FILE_NOTIFICATION_DARK
}
ICON_NAME_LIST = []
class SettingsDialog:
KEY_MAP = GlobalHotkeyDialog.KEY_MAP
REVERSE_KEY_MAP = GlobalHotkeyDialog.REVERSE_KEY_MAP
def __init__(self, parent, configManager):
builder = configwindow.get_ui("settingsdialog.xml")
self.ui = builder.get_object("settingsdialog")
builder.connect_signals(self)
self.ui.set_transient_for(parent)
self.configManager = configManager
# General Settings
self.autoStartCheckbox = builder.get_object("autoStartCheckbox")
self.promptToSaveCheckbox = builder.get_object("promptToSaveCheckbox")
self.showTrayCheckbox = builder.get_object("showTrayCheckbox")
self.allowKbNavCheckbox = builder.get_object("allowKbNavCheckbox")
self.allowKbNavCheckbox.hide()
self.sortByUsageCheckbox = builder.get_object("sortByUsageCheckbox")
self.enableUndoCheckbox = builder.get_object("enableUndoCheckbox")
self.iconStyleCombo = Gtk.ComboBoxText.new()
hbox = builder.get_object("hbox4")
hbox.pack_start(self.iconStyleCombo, False, True, 0)
hbox.show_all()
for key, value in ICON_NAME_MAP.items():
self.iconStyleCombo.append_text(key)
ICON_NAME_LIST.append(value)
self.iconStyleCombo.set_sensitive(ConfigManager.SETTINGS[SHOW_TRAY_ICON])
self.iconStyleCombo.set_active(ICON_NAME_LIST.index(ConfigManager.SETTINGS[NOTIFICATION_ICON]))
self.autoStartCheckbox.set_active(os.path.exists(AUTOSTART_FILE))
self.promptToSaveCheckbox.set_active(ConfigManager.SETTINGS[PROMPT_TO_SAVE])
self.showTrayCheckbox.set_active(ConfigManager.SETTINGS[SHOW_TRAY_ICON])
#self.allowKbNavCheckbox.set_active(ConfigManager.SETTINGS[MENU_TAKES_FOCUS])
self.sortByUsageCheckbox.set_active(ConfigManager.SETTINGS[SORT_BY_USAGE_COUNT])
self.enableUndoCheckbox.set_active(ConfigManager.SETTINGS[UNDO_USING_BACKSPACE])
# Hotkeys
self.showConfigDlg = GlobalHotkeyDialog(parent, configManager, self.on_config_response)
self.toggleMonitorDlg = GlobalHotkeyDialog(parent, configManager, self.on_monitor_response)
self.configKeyLabel = builder.get_object("configKeyLabel")
self.clearConfigButton = builder.get_object("clearConfigButton")
self.monitorKeyLabel = builder.get_object("monitorKeyLabel")
self.clearMonitorButton = builder.get_object("clearMonitorButton")
self.useConfigHotkey = self.__loadHotkey(configManager.configHotkey, self.configKeyLabel,
self.showConfigDlg, self.clearConfigButton)
self.useServiceHotkey = self.__loadHotkey(configManager.toggleServiceHotkey, self.monitorKeyLabel,
self.toggleMonitorDlg, self.clearMonitorButton)
# Script Engine Settings
self.userModuleChooserButton = builder.get_object("userModuleChooserButton")
if configManager.userCodeDir is not None:
self.userModuleChooserButton.set_current_folder(configManager.userCodeDir)
if configManager.userCodeDir in sys.path:
sys.path.remove(configManager.userCodeDir)
def on_save(self, widget, data=None):
if self.autoStartCheckbox.get_active():
if not os.path.exists(AUTOSTART_FILE):
try:
inFile = open(DESKTOP_FILE, 'r')
outFile = open(AUTOSTART_FILE, 'w')
contents = inFile.read()
contents = contents.replace(" -c\n", "\n")
outFile.write(contents)
inFile.close()
outFile.close()
except:
pass
else:
if os.path.exists(AUTOSTART_FILE):
os.remove(AUTOSTART_FILE)
ConfigManager.SETTINGS[PROMPT_TO_SAVE] = self.promptToSaveCheckbox.get_active()
ConfigManager.SETTINGS[SHOW_TRAY_ICON] = self.showTrayCheckbox.get_active()
#ConfigManager.SETTINGS[MENU_TAKES_FOCUS] = self.allowKbNavCheckbox.get_active()
ConfigManager.SETTINGS[SORT_BY_USAGE_COUNT] = self.sortByUsageCheckbox.get_active()
ConfigManager.SETTINGS[UNDO_USING_BACKSPACE] = self.enableUndoCheckbox.get_active()
ConfigManager.SETTINGS[NOTIFICATION_ICON] = ICON_NAME_MAP[self.iconStyleCombo.get_active_text()]
self.configManager.userCodeDir = self.userModuleChooserButton.get_current_folder()
sys.path.append(self.configManager.userCodeDir)
configHotkey = self.configManager.configHotkey
toggleHotkey = self.configManager.toggleServiceHotkey
app = self.configManager.app
if configHotkey.enabled:
app.hotkey_removed(configHotkey)
configHotkey.enabled = self.useConfigHotkey
if self.useConfigHotkey:
self.showConfigDlg.save(configHotkey)
app.hotkey_created(configHotkey)
if toggleHotkey.enabled:
app.hotkey_removed(toggleHotkey)
toggleHotkey.enabled = self.useServiceHotkey
if self.useServiceHotkey:
self.toggleMonitorDlg.save(toggleHotkey)
app.hotkey_created(toggleHotkey)
app.update_notifier_visibility()
self.configManager.config_altered(True)
self.hide()
self.destroy()
def on_cancel(self, widget, data=None):
self.hide()
self.destroy()
def __getattr__(self, attr):
# Magic fudge to allow us to pretend to be the ui class we encapsulate
return getattr(self.ui, attr)
def __loadHotkey(self, item, label, dialog, clearButton):
dialog.load(item)
if item.enabled:
key = item.hotKey.encode("utf-8")
label.set_text(item.get_hotkey_string())
clearButton.set_sensitive(True)
return True
else:
label.set_text(_("(None configured)"))
clearButton.set_sensitive(False)
return False
# ---- Signal handlers
def on_showTrayCheckbox_toggled(self, widget, data=None):
self.iconStyleCombo.set_sensitive(widget.get_active())
def on_setConfigButton_pressed(self, widget, data=None):
self.showConfigDlg.run()
def on_config_response(self, res):
if res == Gtk.ResponseType.OK:
self.useConfigHotkey = True
key = self.showConfigDlg.key
modifiers = self.showConfigDlg.build_modifiers()
self.configKeyLabel.set_text(self.build_hotkey_string(key, modifiers))
self.clearConfigButton.set_sensitive(True)
def on_clearConfigButton_pressed(self, widget, data=None):
self.useConfigHotkey = False
self.clearConfigButton.set_sensitive(False)
self.configKeyLabel.set_text(_("(None configured)"))
self.showConfigDlg.reset()
def on_setMonitorButton_pressed(self, widget, data=None):
self.toggleMonitorDlg.run()
def on_monitor_response(self, res):
if res == Gtk.ResponseType.OK:
self.useServiceHotkey = True
key = self.toggleMonitorDlg.key
modifiers = self.toggleMonitorDlg.build_modifiers()
self.monitorKeyLabel.set_text(self.build_hotkey_string(key, modifiers))
self.clearMonitorButton.set_sensitive(True)
def on_clearMonitorButton_pressed(self, widget, data=None):
self.useServiceHotkey = False
self.clearMonitorButton.set_sensitive(False)
self.monitorKeyLabel.set_text(_("(None configured)"))
self.toggleMonitorDlg.reset()
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
7760,
2799,
5719,
1487,
75,
351,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
12,
984,
199,
504,
18895,
14,
8421,
492,
11424,
199,
199,
504,
2599,
498,
14,
888,
2609,
492,
627,
199,
504,
2599,
498,
492,
284,
1377,
328,
707,
12,
1402,
12,
2863,
199,
504,
487,
18238,
492,
13641,
19942,
498,
5619,
199,
646,
1101,
3806,
199,
199,
4448,
43,
11422,
63,
3817,
275,
3286,
2647,
15,
6251,
15,
15853,
15,
2495,
498,
13,
12275,
14,
14487,
2,
199,
13883,
7363,
63,
3022,
275,
747,
14,
515,
14,
12131,
20793,
8083,
888,
15,
2495,
928,
531,
199,
13883,
7363,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
13883,
7363,
63,
3022,
12,
298,
2495,
498,
13,
12275,
14,
14487,
531,
199,
199,
15903,
63,
2339,
63,
5443,
275,
469,
355,
3824,
16393,
531,
520,
2863,
14,
15903,
63,
3817,
63,
22839,
2594,
12,
355,
3824,
36,
1096,
531,
520,
2863,
14,
15903,
63,
3817,
63,
22839,
2594,
63,
36,
5748,
355,
789,
199,
199,
15903,
63,
2339,
63,
4924,
275,
942,
199,
199,
533,
13303,
5619,
26,
2286,
9301,
63,
5443,
275,
13641,
19942,
498,
5619,
14,
3078,
63,
5443,
272,
28229,
63,
3078,
63,
5443,
275,
13641,
19942,
498,
5619,
14,
907,
21233,
63,
3078,
63,
5443,
2286,
347,
636,
826,
721,
277,
12,
1676,
12,
1101,
2988,
304,
267,
6545,
275,
1101,
3806,
14,
362,
63,
1907,
480,
1751,
7196,
14,
1652,
531,
267,
291,
14,
1907,
275,
6545,
14,
362,
63,
785,
480,
1751,
7196,
531,
267,
6545,
14,
2242,
63,
10458,
8,
277,
9,
267,
291,
14,
1907,
14,
409,
63,
23387,
63,
509,
8,
1708,
9,
267,
291,
14,
888,
2988,
275,
1101,
2988,
2728,
327,
1696,
13303,
267,
291,
14,
2495,
3162,
26366,
275,
6545,
14,
362,
63,
785,
480,
2495,
3162,
26366,
531,
267,
291,
14,
7650,
1378,
8229,
26366,
275,
6545,
14,
362,
63,
785,
480,
7650,
1378,
8229,
26366,
531,
267,
291,
14,
2384,
52,
803,
26366,
275,
6545,
14,
362,
63,
785,
480,
2384,
52,
803,
26366,
531,
267,
291,
14,
3306,
43,
66,
31488,
26366,
275,
6545,
14,
362,
63,
785,
480,
3306,
43,
66,
31488,
26366,
531,
267,
291,
14,
3306,
43,
66,
31488,
26366,
14,
8191,
342,
267,
291,
14,
3191,
2175,
7692,
26366,
275,
6545,
14,
362,
63,
785,
480,
3191,
2175,
7692,
26366,
531,
267,
291,
14,
4296,
29832,
26366,
275,
6545,
14,
362,
63,
785,
480,
4296,
29832,
26366,
531,
2728,
291,
14,
4677,
6609,
12413,
275,
11424,
14,
17491,
1872,
14,
1222,
342,
267,
24126,
275,
6545,
14,
362,
63,
785,
480,
21453,
20,
531,
267,
24126,
14,
1389,
63,
928,
8,
277,
14,
4677,
6609,
12413,
12,
756,
12,
715,
12,
378,
9,
267,
24126,
14,
2384,
63,
452,
342,
2728,
367,
790,
12,
574,
315,
473,
1864,
63,
2339,
63,
5443,
14,
1744,
837,
288,
291,
14,
4677,
6609,
12413,
14,
740,
63,
505,
8,
498,
9,
288,
473,
1864,
63,
2339,
63,
4924,
14,
740,
8,
585,
9,
267,
291,
14,
4677,
6609,
12413,
14,
409,
63,
7361,
8,
2028,
2988,
14,
13931,
59,
19085,
63,
1766,
3448,
63,
15903,
566,
267,
291,
14,
4677,
6609,
12413,
14,
409,
63,
2682,
8,
15903,
63,
2339,
63,
4924,
14,
1080,
8,
2028,
2988,
14,
13931,
59,
22839,
2594,
63,
15903,
2459,
2728,
291,
14,
2495,
3162,
26366,
14,
409,
63,
2682,
8,
736,
14,
515,
14,
2444,
8,
13883,
7363,
63,
3817,
430,
267,
291,
14,
7650,
1378,
8229,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
2514,
26178,
63,
2566,
63,
19318,
566,
267,
291,
14,
2384,
52,
803,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
19085,
63,
1766,
3448,
63,
15903,
566,
267,
327,
277,
14,
3306,
43,
66,
31488,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
18223,
63,
6166,
43,
654,
63,
3230,
35,
1668,
566,
267,
291,
14,
3191,
2175,
7692,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
23447,
63,
8285,
63,
20274,
63,
8760,
566,
267,
291,
14,
4296,
29832,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
1734,
1649,
63,
1668,
1206,
63,
7111,
11658,
566,
268,
421,
398,
327,
869,
357,
1612,
267,
291,
14,
2384,
2028,
20192,
275,
13641,
19942,
498,
5619,
8,
1708,
12,
1101,
2988,
12,
291,
14,
265,
63,
888,
63,
1310,
9,
267,
291,
14,
13396,
13189,
20192,
275,
13641,
19942,
498,
5619,
8,
1708,
12,
1101,
2988,
12,
291,
14,
265,
63,
7157,
63,
1310,
9,
267,
291,
14,
888,
1197,
4314,
275,
6545,
14,
362,
63,
785,
480,
888,
1197,
4314,
531,
267,
291,
14,
3584,
2028,
4259,
275,
6545,
14,
362,
63,
785,
480,
3584,
2028,
4259,
531,
267,
291,
14,
7157,
1197,
4314,
275,
6545,
14,
362,
63,
785,
480,
7157,
1197,
4314,
531,
267,
291,
14,
3584,
13189,
4259,
275,
6545,
14,
362,
63,
785,
480,
3584,
13189,
4259,
531,
258,
2728,
291,
14,
1180,
2028,
19942,
498,
275,
291,
855,
912,
19942,
498,
8,
888,
2988,
14,
888,
19942,
498,
12,
291,
14,
888,
1197,
4314,
12,
221,
8105,
291,
14,
2384,
2028
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
35,
9,
7760,
2799,
5719,
1487,
75,
351,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
747,
12,
984,
199,
504,
18895,
14,
8421,
492,
11424,
199,
199,
504,
2599,
498,
14,
888,
2609,
492,
627,
199,
504,
2599,
498,
492,
284,
1377,
328,
707,
12,
1402,
12,
2863,
199,
504,
487,
18238,
492,
13641,
19942,
498,
5619,
199,
646,
1101,
3806,
199,
199,
4448,
43,
11422,
63,
3817,
275,
3286,
2647,
15,
6251,
15,
15853,
15,
2495,
498,
13,
12275,
14,
14487,
2,
199,
13883,
7363,
63,
3022,
275,
747,
14,
515,
14,
12131,
20793,
8083,
888,
15,
2495,
928,
531,
199,
13883,
7363,
63,
3817,
275,
747,
14,
515,
14,
904,
8,
13883,
7363,
63,
3022,
12,
298,
2495,
498,
13,
12275,
14,
14487,
531,
199,
199,
15903,
63,
2339,
63,
5443,
275,
469,
355,
3824,
16393,
531,
520,
2863,
14,
15903,
63,
3817,
63,
22839,
2594,
12,
355,
3824,
36,
1096,
531,
520,
2863,
14,
15903,
63,
3817,
63,
22839,
2594,
63,
36,
5748,
355,
789,
199,
199,
15903,
63,
2339,
63,
4924,
275,
942,
199,
199,
533,
13303,
5619,
26,
2286,
9301,
63,
5443,
275,
13641,
19942,
498,
5619,
14,
3078,
63,
5443,
272,
28229,
63,
3078,
63,
5443,
275,
13641,
19942,
498,
5619,
14,
907,
21233,
63,
3078,
63,
5443,
2286,
347,
636,
826,
721,
277,
12,
1676,
12,
1101,
2988,
304,
267,
6545,
275,
1101,
3806,
14,
362,
63,
1907,
480,
1751,
7196,
14,
1652,
531,
267,
291,
14,
1907,
275,
6545,
14,
362,
63,
785,
480,
1751,
7196,
531,
267,
6545,
14,
2242,
63,
10458,
8,
277,
9,
267,
291,
14,
1907,
14,
409,
63,
23387,
63,
509,
8,
1708,
9,
267,
291,
14,
888,
2988,
275,
1101,
2988,
2728,
327,
1696,
13303,
267,
291,
14,
2495,
3162,
26366,
275,
6545,
14,
362,
63,
785,
480,
2495,
3162,
26366,
531,
267,
291,
14,
7650,
1378,
8229,
26366,
275,
6545,
14,
362,
63,
785,
480,
7650,
1378,
8229,
26366,
531,
267,
291,
14,
2384,
52,
803,
26366,
275,
6545,
14,
362,
63,
785,
480,
2384,
52,
803,
26366,
531,
267,
291,
14,
3306,
43,
66,
31488,
26366,
275,
6545,
14,
362,
63,
785,
480,
3306,
43,
66,
31488,
26366,
531,
267,
291,
14,
3306,
43,
66,
31488,
26366,
14,
8191,
342,
267,
291,
14,
3191,
2175,
7692,
26366,
275,
6545,
14,
362,
63,
785,
480,
3191,
2175,
7692,
26366,
531,
267,
291,
14,
4296,
29832,
26366,
275,
6545,
14,
362,
63,
785,
480,
4296,
29832,
26366,
531,
2728,
291,
14,
4677,
6609,
12413,
275,
11424,
14,
17491,
1872,
14,
1222,
342,
267,
24126,
275,
6545,
14,
362,
63,
785,
480,
21453,
20,
531,
267,
24126,
14,
1389,
63,
928,
8,
277,
14,
4677,
6609,
12413,
12,
756,
12,
715,
12,
378,
9,
267,
24126,
14,
2384,
63,
452,
342,
2728,
367,
790,
12,
574,
315,
473,
1864,
63,
2339,
63,
5443,
14,
1744,
837,
288,
291,
14,
4677,
6609,
12413,
14,
740,
63,
505,
8,
498,
9,
288,
473,
1864,
63,
2339,
63,
4924,
14,
740,
8,
585,
9,
267,
291,
14,
4677,
6609,
12413,
14,
409,
63,
7361,
8,
2028,
2988,
14,
13931,
59,
19085,
63,
1766,
3448,
63,
15903,
566,
267,
291,
14,
4677,
6609,
12413,
14,
409,
63,
2682,
8,
15903,
63,
2339,
63,
4924,
14,
1080,
8,
2028,
2988,
14,
13931,
59,
22839,
2594,
63,
15903,
2459,
2728,
291,
14,
2495,
3162,
26366,
14,
409,
63,
2682,
8,
736,
14,
515,
14,
2444,
8,
13883,
7363,
63,
3817,
430,
267,
291,
14,
7650,
1378,
8229,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
2514,
26178,
63,
2566,
63,
19318,
566,
267,
291,
14,
2384,
52,
803,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
19085,
63,
1766,
3448,
63,
15903,
566,
267,
327,
277,
14,
3306,
43,
66,
31488,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
18223,
63,
6166,
43,
654,
63,
3230,
35,
1668,
566,
267,
291,
14,
3191,
2175,
7692,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
23447,
63,
8285,
63,
20274,
63,
8760,
566,
267,
291,
14,
4296,
29832,
26366,
14,
409,
63,
2682,
8,
2028,
2988,
14,
13931,
59,
1734,
1649,
63,
1668,
1206,
63,
7111,
11658,
566,
268,
421,
398,
327,
869,
357,
1612,
267,
291,
14,
2384,
2028,
20192,
275,
13641,
19942,
498,
5619,
8,
1708,
12,
1101,
2988,
12,
291,
14,
265,
63,
888,
63,
1310,
9,
267,
291,
14,
13396,
13189,
20192,
275,
13641,
19942,
498,
5619,
8,
1708,
12,
1101,
2988,
12,
291,
14,
265,
63,
7157,
63,
1310,
9,
267,
291,
14,
888,
1197,
4314,
275,
6545,
14,
362,
63,
785,
480,
888,
1197,
4314,
531,
267,
291,
14,
3584,
2028,
4259,
275,
6545,
14,
362,
63,
785,
480,
3584,
2028,
4259,
531,
267,
291,
14,
7157,
1197,
4314,
275,
6545,
14,
362,
63,
785,
480,
7157,
1197,
4314,
531,
267,
291,
14,
3584,
13189,
4259,
275,
6545,
14,
362,
63,
785,
480,
3584,
13189,
4259,
531,
258,
2728,
291,
14,
1180,
2028,
19942,
498,
275,
291,
855,
912,
19942,
498,
8,
888,
2988,
14,
888,
19942,
498,
12,
291,
14,
888,
1197,
4314,
12,
221,
8105,
291,
14,
2384,
2028,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
matthewoliver/swift
|
swift/common/middleware/s3api/controllers/obj.py
|
1
|
5246
|
# Copyright (c) 2010-2014 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from swift.common.http import HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_NO_CONTENT
from swift.common.swob import Range, content_range_header_value
from swift.common.utils import public
from swift.common.middleware.s3api.utils import S3Timestamp
from swift.common.middleware.s3api.controllers.base import Controller
from swift.common.middleware.s3api.s3response import S3NotImplemented, \
InvalidRange, NoSuchKey, InvalidArgument
class ObjectController(Controller):
"""
Handles requests on objects
"""
def _gen_head_range_resp(self, req_range, resp):
"""
Swift doesn't handle Range header for HEAD requests.
So, this method generates HEAD range response from HEAD response.
S3 return HEAD range response, if the value of range satisfies the
conditions which are described in the following document.
- http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
"""
length = long(resp.headers.get('Content-Length'))
try:
content_range = Range(req_range)
except ValueError:
return resp
ranges = content_range.ranges_for_length(length)
if ranges == []:
raise InvalidRange()
elif ranges:
if len(ranges) == 1:
start, end = ranges[0]
resp.headers['Content-Range'] = \
content_range_header_value(start, end, length)
resp.headers['Content-Length'] = (end - start)
resp.status = HTTP_PARTIAL_CONTENT
return resp
else:
# TODO: It is necessary to confirm whether need to respond to
# multi-part response.(e.g. bytes=0-10,20-30)
pass
return resp
def GETorHEAD(self, req):
resp = req.get_response(self.app)
if req.method == 'HEAD':
resp.app_iter = None
for key in ('content-type', 'content-language', 'expires',
'cache-control', 'content-disposition',
'content-encoding'):
if 'response-' + key in req.params:
resp.headers[key] = req.params['response-' + key]
return resp
@public
def HEAD(self, req):
"""
Handle HEAD Object request
"""
resp = self.GETorHEAD(req)
if 'range' in req.headers:
req_range = req.headers['range']
resp = self._gen_head_range_resp(req_range, resp)
return resp
@public
def GET(self, req):
"""
Handle GET Object request
"""
return self.GETorHEAD(req)
@public
def PUT(self, req):
"""
Handle PUT Object and PUT Object (Copy) request
"""
# set X-Timestamp by s3api to use at copy resp body
req_timestamp = S3Timestamp.now()
req.headers['X-Timestamp'] = req_timestamp.internal
if all(h in req.headers
for h in ('X-Amz-Copy-Source', 'X-Amz-Copy-Source-Range')):
raise InvalidArgument('x-amz-copy-source-range',
req.headers['X-Amz-Copy-Source-Range'],
'Illegal copy header')
req.check_copy_source(self.app)
resp = req.get_response(self.app)
if 'X-Amz-Copy-Source' in req.headers:
resp.append_copy_resp_body(req.controller_name,
req_timestamp.s3xmlformat)
# delete object metadata from response
for key in list(resp.headers.keys()):
if key.startswith('x-amz-meta-'):
del resp.headers[key]
resp.status = HTTP_OK
return resp
@public
def POST(self, req):
raise S3NotImplemented()
@public
def DELETE(self, req):
"""
Handle DELETE Object request
"""
try:
query = req.gen_multipart_manifest_delete_query(self.app)
req.headers['Content-Type'] = None # Ignore client content-type
resp = req.get_response(self.app, query=query)
if query and resp.status_int == HTTP_OK:
for chunk in resp.app_iter:
pass # drain the bulk-deleter response
resp.status = HTTP_NO_CONTENT
resp.body = ''
except NoSuchKey:
# expect to raise NoSuchBucket when the bucket doesn't exist
exc_type, exc_value, exc_traceback = sys.exc_info()
req.get_container_info(self.app)
raise exc_type, exc_value, exc_traceback
return resp
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
13,
7280,
14260,
2752,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
504,
16275,
14,
2330,
14,
1014,
492,
3101,
63,
3593,
12,
3101,
63,
14848,
4938,
63,
9663,
12,
3101,
63,
2826,
63,
9663,
199,
504,
16275,
14,
2330,
14,
83,
32517,
492,
13114,
12,
1564,
63,
1842,
63,
1291,
63,
585,
199,
504,
16275,
14,
2330,
14,
1208,
492,
4575,
199,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
1208,
492,
428,
19,
10239,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
20531,
14,
1095,
492,
16282,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
83,
19,
1310,
492,
428,
19,
14278,
12,
971,
272,
6378,
4709,
12,
23798,
1197,
12,
6378,
5201,
421,
199,
533,
6935,
7506,
8,
7506,
304,
272,
408,
272,
23873,
4145,
641,
2251,
272,
408,
272,
347,
485,
2268,
63,
2993,
63,
1842,
63,
4518,
8,
277,
12,
2648,
63,
1842,
12,
3085,
304,
267,
408,
267,
16666,
2949,
3181,
1133,
2429,
13114,
1406,
367,
13053,
4145,
14,
267,
2002,
12,
642,
1083,
12821,
13053,
1425,
1177,
687,
13053,
1177,
14,
267,
428,
19,
372,
13053,
1425,
1177,
12,
340,
314,
574,
402,
1425,
13529,
5604,
314,
267,
3704,
1314,
787,
11736,
315,
314,
2569,
2213,
14,
267,
446,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
8548,
4574,
15,
8973,
25807,
15,
8973,
25807,
13,
3321,
1079,
14,
1360,
3,
3321,
1079,
14,
1276,
267,
408,
267,
2582,
275,
1846,
8,
4518,
14,
2139,
14,
362,
360,
2714,
13,
4625,
1333,
398,
862,
26,
288,
1564,
63,
1842,
275,
13114,
8,
2103,
63,
1842,
9,
267,
871,
1722,
26,
288,
372,
3085,
398,
12271,
275,
1564,
63,
1842,
14,
8404,
63,
509,
63,
1267,
8,
1267,
9,
267,
340,
12271,
508,
18410,
288,
746,
6378,
4709,
342,
267,
916,
12271,
26,
288,
340,
822,
8,
8404,
9,
508,
413,
26,
355,
1343,
12,
1284,
275,
12271,
59,
16,
61,
355,
3085,
14,
2139,
459,
2714,
13,
4709,
418,
275,
971,
490,
1564,
63,
1842,
63,
1291,
63,
585,
8,
928,
12,
1284,
12,
2582,
9,
355,
3085,
14,
2139,
459,
2714,
13,
4625,
418,
275,
334,
500,
446,
1343,
9,
355,
3085,
14,
1205,
275,
3101,
63,
14848,
4938,
63,
9663,
355,
372,
3085,
288,
587,
26,
355,
327,
3254,
26,
2779,
365,
5784,
370,
12679,
3775,
1929,
370,
22722,
370,
355,
327,
755,
3510,
13,
2064,
1177,
14,
8,
69,
14,
71,
14,
2783,
29,
16,
13,
709,
12,
1165,
13,
1216,
9,
355,
986,
398,
372,
3085,
339,
347,
9576,
269,
5211,
8,
277,
12,
2648,
304,
267,
3085,
275,
2648,
14,
362,
63,
1310,
8,
277,
14,
571,
9,
398,
340,
2648,
14,
765,
508,
283,
5211,
356,
288,
3085,
14,
571,
63,
1661,
275,
488,
398,
367,
790,
315,
661,
1317,
13,
466,
297,
283,
1317,
13,
3671,
297,
283,
12342,
297,
490,
283,
1637,
13,
2785,
297,
283,
1317,
13,
20173,
297,
490,
283,
1317,
13,
2991,
735,
288,
340,
283,
1310,
15668,
435,
790,
315,
2648,
14,
1162,
26,
355,
3085,
14,
2139,
59,
498,
61,
275,
2648,
14,
1162,
459,
1310,
15668,
435,
790,
61,
398,
372,
3085,
339,
768,
3455,
272,
347,
13053,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
13053,
6935,
1056,
267,
408,
267,
3085,
275,
291,
14,
2970,
269,
5211,
8,
2103,
9,
398,
340,
283,
1842,
7,
315,
2648,
14,
2139,
26,
288,
2648,
63,
1842,
275,
2648,
14,
2139,
459,
1842,
418,
288,
3085,
275,
291,
423,
2268,
63,
2993,
63,
1842,
63,
4518,
8,
2103,
63,
1842,
12,
3085,
9,
398,
372,
3085,
339,
768,
3455,
272,
347,
9576,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
9576,
6935,
1056,
267,
408,
267,
372,
291,
14,
2970,
269,
5211,
8,
2103,
9,
339,
768,
3455,
272,
347,
18337,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
18337,
6935,
436,
18337,
6935,
334,
5116,
9,
1056,
267,
408,
267,
327,
663,
1323,
13,
10239,
701,
308,
19,
1246,
370,
675,
737,
1331,
3085,
2396,
267,
2648,
63,
3954,
275,
428,
19,
10239,
14,
2131,
342,
267,
2648,
14,
2139,
459,
56,
13,
10239,
418,
275,
2648,
63,
3954,
14,
4672,
267,
340,
1006,
8,
72,
315,
2648,
14,
2139,
2049,
367,
394,
315,
661,
56,
13,
24566,
90,
13,
5116,
13,
2980,
297,
283,
56,
13,
24566,
90,
13,
5116,
13,
2980,
13,
4709,
8109,
288,
746,
6378,
5201,
360,
88,
13,
455,
90,
13,
1574,
13,
1365,
13,
1842,
297,
3303,
2648,
14,
2139,
459,
56,
13,
24566,
90,
13,
5116,
13,
2980,
13,
4709,
995,
3303,
283,
25501,
1331,
1406,
358,
267,
2648,
14,
1074,
63,
1574,
63,
1365,
8,
277,
14,
571,
9,
267,
3085,
275,
2648,
14,
362,
63,
1310,
8,
277,
14,
571,
9,
398,
340,
283,
56,
13,
24566,
90,
13,
5116,
13,
2980,
7,
315,
2648,
14,
2139,
26,
288,
3085,
14,
740,
63,
1574,
63,
4518,
63,
2030,
8,
2103,
14,
5538,
63,
354,
12,
4318,
2648,
63,
3954,
14,
83,
19,
10198,
276,
269,
569,
9,
953,
327,
3145,
909,
3341,
687,
1177,
288,
367,
790,
315,
769,
8,
4518,
14,
2139,
14,
1612,
5109,
355,
340,
790,
14,
2460,
360,
88,
13,
455,
90,
13,
2024,
13,
735
] |
[
1898,
334,
67,
9,
7129,
13,
7280,
14260,
2752,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
504,
16275,
14,
2330,
14,
1014,
492,
3101,
63,
3593,
12,
3101,
63,
14848,
4938,
63,
9663,
12,
3101,
63,
2826,
63,
9663,
199,
504,
16275,
14,
2330,
14,
83,
32517,
492,
13114,
12,
1564,
63,
1842,
63,
1291,
63,
585,
199,
504,
16275,
14,
2330,
14,
1208,
492,
4575,
199,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
1208,
492,
428,
19,
10239,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
20531,
14,
1095,
492,
16282,
199,
504,
16275,
14,
2330,
14,
5754,
14,
83,
19,
1246,
14,
83,
19,
1310,
492,
428,
19,
14278,
12,
971,
272,
6378,
4709,
12,
23798,
1197,
12,
6378,
5201,
421,
199,
533,
6935,
7506,
8,
7506,
304,
272,
408,
272,
23873,
4145,
641,
2251,
272,
408,
272,
347,
485,
2268,
63,
2993,
63,
1842,
63,
4518,
8,
277,
12,
2648,
63,
1842,
12,
3085,
304,
267,
408,
267,
16666,
2949,
3181,
1133,
2429,
13114,
1406,
367,
13053,
4145,
14,
267,
2002,
12,
642,
1083,
12821,
13053,
1425,
1177,
687,
13053,
1177,
14,
267,
428,
19,
372,
13053,
1425,
1177,
12,
340,
314,
574,
402,
1425,
13529,
5604,
314,
267,
3704,
1314,
787,
11736,
315,
314,
2569,
2213,
14,
267,
446,
1455,
921,
1544,
14,
87,
19,
14,
1308,
15,
8548,
4574,
15,
8973,
25807,
15,
8973,
25807,
13,
3321,
1079,
14,
1360,
3,
3321,
1079,
14,
1276,
267,
408,
267,
2582,
275,
1846,
8,
4518,
14,
2139,
14,
362,
360,
2714,
13,
4625,
1333,
398,
862,
26,
288,
1564,
63,
1842,
275,
13114,
8,
2103,
63,
1842,
9,
267,
871,
1722,
26,
288,
372,
3085,
398,
12271,
275,
1564,
63,
1842,
14,
8404,
63,
509,
63,
1267,
8,
1267,
9,
267,
340,
12271,
508,
18410,
288,
746,
6378,
4709,
342,
267,
916,
12271,
26,
288,
340,
822,
8,
8404,
9,
508,
413,
26,
355,
1343,
12,
1284,
275,
12271,
59,
16,
61,
355,
3085,
14,
2139,
459,
2714,
13,
4709,
418,
275,
971,
490,
1564,
63,
1842,
63,
1291,
63,
585,
8,
928,
12,
1284,
12,
2582,
9,
355,
3085,
14,
2139,
459,
2714,
13,
4625,
418,
275,
334,
500,
446,
1343,
9,
355,
3085,
14,
1205,
275,
3101,
63,
14848,
4938,
63,
9663,
355,
372,
3085,
288,
587,
26,
355,
327,
3254,
26,
2779,
365,
5784,
370,
12679,
3775,
1929,
370,
22722,
370,
355,
327,
755,
3510,
13,
2064,
1177,
14,
8,
69,
14,
71,
14,
2783,
29,
16,
13,
709,
12,
1165,
13,
1216,
9,
355,
986,
398,
372,
3085,
339,
347,
9576,
269,
5211,
8,
277,
12,
2648,
304,
267,
3085,
275,
2648,
14,
362,
63,
1310,
8,
277,
14,
571,
9,
398,
340,
2648,
14,
765,
508,
283,
5211,
356,
288,
3085,
14,
571,
63,
1661,
275,
488,
398,
367,
790,
315,
661,
1317,
13,
466,
297,
283,
1317,
13,
3671,
297,
283,
12342,
297,
490,
283,
1637,
13,
2785,
297,
283,
1317,
13,
20173,
297,
490,
283,
1317,
13,
2991,
735,
288,
340,
283,
1310,
15668,
435,
790,
315,
2648,
14,
1162,
26,
355,
3085,
14,
2139,
59,
498,
61,
275,
2648,
14,
1162,
459,
1310,
15668,
435,
790,
61,
398,
372,
3085,
339,
768,
3455,
272,
347,
13053,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
13053,
6935,
1056,
267,
408,
267,
3085,
275,
291,
14,
2970,
269,
5211,
8,
2103,
9,
398,
340,
283,
1842,
7,
315,
2648,
14,
2139,
26,
288,
2648,
63,
1842,
275,
2648,
14,
2139,
459,
1842,
418,
288,
3085,
275,
291,
423,
2268,
63,
2993,
63,
1842,
63,
4518,
8,
2103,
63,
1842,
12,
3085,
9,
398,
372,
3085,
339,
768,
3455,
272,
347,
9576,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
9576,
6935,
1056,
267,
408,
267,
372,
291,
14,
2970,
269,
5211,
8,
2103,
9,
339,
768,
3455,
272,
347,
18337,
8,
277,
12,
2648,
304,
267,
408,
267,
8690,
18337,
6935,
436,
18337,
6935,
334,
5116,
9,
1056,
267,
408,
267,
327,
663,
1323,
13,
10239,
701,
308,
19,
1246,
370,
675,
737,
1331,
3085,
2396,
267,
2648,
63,
3954,
275,
428,
19,
10239,
14,
2131,
342,
267,
2648,
14,
2139,
459,
56,
13,
10239,
418,
275,
2648,
63,
3954,
14,
4672,
267,
340,
1006,
8,
72,
315,
2648,
14,
2139,
2049,
367,
394,
315,
661,
56,
13,
24566,
90,
13,
5116,
13,
2980,
297,
283,
56,
13,
24566,
90,
13,
5116,
13,
2980,
13,
4709,
8109,
288,
746,
6378,
5201,
360,
88,
13,
455,
90,
13,
1574,
13,
1365,
13,
1842,
297,
3303,
2648,
14,
2139,
459,
56,
13,
24566,
90,
13,
5116,
13,
2980,
13,
4709,
995,
3303,
283,
25501,
1331,
1406,
358,
267,
2648,
14,
1074,
63,
1574,
63,
1365,
8,
277,
14,
571,
9,
267,
3085,
275,
2648,
14,
362,
63,
1310,
8,
277,
14,
571,
9,
398,
340,
283,
56,
13,
24566,
90,
13,
5116,
13,
2980,
7,
315,
2648,
14,
2139,
26,
288,
3085,
14,
740,
63,
1574,
63,
4518,
63,
2030,
8,
2103,
14,
5538,
63,
354,
12,
4318,
2648,
63,
3954,
14,
83,
19,
10198,
276,
269,
569,
9,
953,
327,
3145,
909,
3341,
687,
1177,
288,
367,
790,
315,
769,
8,
4518,
14,
2139,
14,
1612,
5109,
355,
340,
790,
14,
2460,
360,
88,
13,
455,
90,
13,
2024,
13,
735,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Samsung/skia
|
third_party/externals/jsoncpp/scons-tools/globtool.py
|
256
|
1667
|
import fnmatch
import os
def generate( env ):
def Glob( env, includes = None, excludes = None, dir = '.' ):
"""Adds Glob( includes = Split( '*' ), excludes = None, dir = '.')
helper function to environment.
Glob both the file-system files.
includes: list of file name pattern included in the return list when matched.
excludes: list of file name pattern exluced from the return list.
Example:
sources = env.Glob( ("*.cpp", '*.h'), "~*.cpp", "#src" )
"""
def filterFilename(path):
abs_path = os.path.join( dir, path )
if not os.path.isfile(abs_path):
return 0
fn = os.path.basename(path)
match = 0
for include in includes:
if fnmatch.fnmatchcase( fn, include ):
match = 1
break
if match == 1 and not excludes is None:
for exclude in excludes:
if fnmatch.fnmatchcase( fn, exclude ):
match = 0
break
return match
if includes is None:
includes = ('*',)
elif type(includes) in ( type(''), type(u'') ):
includes = (includes,)
if type(excludes) in ( type(''), type(u'') ):
excludes = (excludes,)
dir = env.Dir(dir).abspath
paths = os.listdir( dir )
def makeAbsFileNode( path ):
return env.File( os.path.join( dir, path ) )
nodes = filter( filterFilename, paths )
return map( makeAbsFileNode, nodes )
from SCons.Script import Environment
Environment.Glob = Glob
def exists(env):
"""
Tool always exists.
"""
return True
|
bsd-3-clause
|
[
646,
15951,
199,
646,
747,
199,
199,
318,
3550,
8,
2589,
3461,
221,
2043,
347,
598,
1191,
8,
2589,
12,
6952,
275,
488,
12,
23388,
275,
488,
12,
2935,
275,
7815,
3461,
489,
408,
14995,
598,
1191,
8,
6952,
275,
11740,
8,
13626,
2318,
23388,
275,
488,
12,
2935,
275,
20093,
2126,
5922,
805,
370,
3734,
14,
10817,
598,
1191,
3865,
314,
570,
13,
2253,
1584,
14,
10817,
6952,
26,
769,
402,
570,
536,
3851,
5120,
315,
314,
372,
769,
1380,
7838,
14,
2126,
23388,
26,
769,
402,
570,
536,
3851,
444,
76,
3683,
68,
687,
314,
372,
769,
14,
10817,
5679,
26,
2126,
5274,
275,
2589,
14,
25954,
8,
1689,
4856,
5910,
401,
11937,
72,
659,
26810,
4856,
5910,
401,
5426,
2164,
2,
776,
489,
408,
489,
347,
2457,
8117,
8,
515,
304,
268,
2853,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2935,
12,
931,
776,
268,
340,
440,
747,
14,
515,
14,
6292,
8,
2101,
63,
515,
304,
288,
372,
378,
268,
4325,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
268,
1336,
275,
378,
268,
367,
2387,
315,
6952,
26,
288,
340,
15951,
14,
15359,
2546,
8,
4325,
12,
2387,
3461,
2049,
1336,
275,
413,
2049,
2059,
268,
340,
1336,
508,
413,
436,
440,
23388,
365,
488,
26,
288,
367,
5760,
315,
23388,
26,
2049,
340,
15951,
14,
15359,
2546,
8,
4325,
12,
5760,
3461,
2116,
1336,
275,
378,
2116,
2059,
268,
372,
1336,
489,
340,
6952,
365,
488,
26,
268,
6952,
275,
661,
7693,
9,
489,
916,
730,
8,
9441,
9,
315,
334,
730,
31150,
730,
8,
85,
17483,
3461,
268,
6952,
275,
334,
9441,
4258,
489,
340,
730,
8,
26984,
9,
315,
334,
730,
31150,
730,
8,
85,
17483,
3461,
268,
23388,
275,
334,
26984,
4258,
489,
2935,
275,
2589,
14,
3567,
8,
694,
680,
4832,
489,
3792,
275,
747,
14,
7374,
8,
2935,
776,
489,
347,
1852,
15447,
1173,
1716,
8,
931,
3461,
268,
372,
2589,
14,
1173,
8,
747,
14,
515,
14,
904,
8,
2935,
12,
931,
776,
776,
489,
3380,
275,
2457,
8,
2457,
8117,
12,
3792,
776,
489,
372,
2341,
8,
1852,
15447,
1173,
1716,
12,
3380,
776,
8410,
687,
8218,
14,
5229,
492,
9711,
2043,
9711,
14,
25954,
275,
598,
1191,
199,
199,
318,
3495,
8,
1813,
304,
272,
408,
272,
15650,
3544,
3495,
14,
272,
408,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
15951,
199,
646,
747,
199,
199,
318,
3550,
8,
2589,
3461,
221,
2043,
347,
598,
1191,
8,
2589,
12,
6952,
275,
488,
12,
23388,
275,
488,
12,
2935,
275,
7815,
3461,
489,
408,
14995,
598,
1191,
8,
6952,
275,
11740,
8,
13626,
2318,
23388,
275,
488,
12,
2935,
275,
20093,
2126,
5922,
805,
370,
3734,
14,
10817,
598,
1191,
3865,
314,
570,
13,
2253,
1584,
14,
10817,
6952,
26,
769,
402,
570,
536,
3851,
5120,
315,
314,
372,
769,
1380,
7838,
14,
2126,
23388,
26,
769,
402,
570,
536,
3851,
444,
76,
3683,
68,
687,
314,
372,
769,
14,
10817,
5679,
26,
2126,
5274,
275,
2589,
14,
25954,
8,
1689,
4856,
5910,
401,
11937,
72,
659,
26810,
4856,
5910,
401,
5426,
2164,
2,
776,
489,
408,
489,
347,
2457,
8117,
8,
515,
304,
268,
2853,
63,
515,
275,
747,
14,
515,
14,
904,
8,
2935,
12,
931,
776,
268,
340,
440,
747,
14,
515,
14,
6292,
8,
2101,
63,
515,
304,
288,
372,
378,
268,
4325,
275,
747,
14,
515,
14,
4846,
8,
515,
9,
268,
1336,
275,
378,
268,
367,
2387,
315,
6952,
26,
288,
340,
15951,
14,
15359,
2546,
8,
4325,
12,
2387,
3461,
2049,
1336,
275,
413,
2049,
2059,
268,
340,
1336,
508,
413,
436,
440,
23388,
365,
488,
26,
288,
367,
5760,
315,
23388,
26,
2049,
340,
15951,
14,
15359,
2546,
8,
4325,
12,
5760,
3461,
2116,
1336,
275,
378,
2116,
2059,
268,
372,
1336,
489,
340,
6952,
365,
488,
26,
268,
6952,
275,
661,
7693,
9,
489,
916,
730,
8,
9441,
9,
315,
334,
730,
31150,
730,
8,
85,
17483,
3461,
268,
6952,
275,
334,
9441,
4258,
489,
340,
730,
8,
26984,
9,
315,
334,
730,
31150,
730,
8,
85,
17483,
3461,
268,
23388,
275,
334,
26984,
4258,
489,
2935,
275,
2589,
14,
3567,
8,
694,
680,
4832,
489,
3792,
275,
747,
14,
7374,
8,
2935,
776,
489,
347,
1852,
15447,
1173,
1716,
8,
931,
3461,
268,
372,
2589,
14,
1173,
8,
747,
14,
515,
14,
904,
8,
2935,
12,
931,
776,
776,
489,
3380,
275,
2457,
8,
2457,
8117,
12,
3792,
776,
489,
372,
2341,
8,
1852,
15447,
1173,
1716,
12,
3380,
776,
8410,
687,
8218,
14,
5229,
492,
9711,
2043,
9711,
14,
25954,
275,
598,
1191,
199,
199,
318,
3495,
8,
1813,
304,
272,
408,
272,
15650,
3544,
3495,
14,
272,
408,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
paulrouget/servo
|
tests/wpt/web-platform-tests/cors/resources/status.py
|
26
|
1209
|
def main(request, response):
response.headers.set("Access-Control-Allow-Origin", request.headers.get("origin"))
response.headers.set("Access-Control-Expose-Headers", "X-Request-Method")
if request.method == 'OPTIONS':
response.headers.set("Access-Control-Allow-Methods", "GET, CHICKEN, HEAD, POST, PUT")
if 'headers' in request.GET:
response.headers.set("Access-Control-Allow-Headers", request.GET.first('headers'))
response.headers.set("X-Request-Method", request.method)
response.headers.set("X-A-C-Request-Method", request.headers.get("Access-Control-Request-Method", ""))
#This should reasonably work for most response codes.
try:
code = int(request.GET.first("code", 200))
except ValueError:
code = 200
text = request.GET.first("text", "OMG")
if request.method == "OPTIONS" and "preflight" in request.GET:
try:
code = int(request.GET.first('preflight'))
except KeyError:
pass
status = code, text
if "type" in request.GET:
response.headers.set("Content-Type", request.GET.first('type'))
body = request.GET.first('content', "")
return status, [], body
|
mpl-2.0
|
[
318,
2446,
8,
1069,
12,
1177,
304,
272,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
12834,
401,
1056,
14,
2139,
14,
362,
480,
6493,
2237,
272,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
920,
4070,
13,
9883,
401,
298,
56,
13,
2017,
13,
3767,
531,
339,
340,
1056,
14,
765,
508,
283,
8808,
356,
267,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
10385,
401,
221,
298,
2970,
12,
6624,
948,
6945,
12,
13053,
12,
8761,
12,
18337,
531,
339,
340,
283,
2139,
7,
315,
1056,
14,
2970,
26,
267,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
9883,
401,
221,
1056,
14,
2970,
14,
2246,
360,
2139,
1333,
339,
1177,
14,
2139,
14,
409,
480,
56,
13,
2017,
13,
3767,
401,
1056,
14,
765,
9,
339,
1177,
14,
2139,
14,
409,
480,
56,
13,
33,
13,
35,
13,
2017,
13,
3767,
401,
1056,
14,
2139,
14,
362,
480,
3946,
13,
3717,
13,
2017,
13,
3767,
401,
25491,
2378,
327,
2765,
1077,
4499,
6665,
1736,
367,
4750,
1177,
9479,
14,
272,
862,
26,
267,
1233,
275,
1109,
8,
1069,
14,
2970,
14,
2246,
480,
600,
401,
1926,
430,
272,
871,
1722,
26,
267,
1233,
275,
1926,
339,
1318,
275,
1056,
14,
2970,
14,
2246,
480,
505,
401,
298,
7474,
39,
531,
339,
340,
1056,
14,
765,
508,
298,
8808,
2,
436,
298,
13829,
4040,
2,
315,
1056,
14,
2970,
26,
267,
862,
26,
288,
1233,
275,
1109,
8,
1069,
14,
2970,
14,
2246,
360,
13829,
4040,
1333,
267,
871,
4067,
26,
288,
986,
339,
2004,
275,
1233,
12,
1318,
339,
340,
298,
466,
2,
315,
1056,
14,
2970,
26,
267,
1177,
14,
2139,
14,
409,
480,
2714,
13,
804,
401,
1056,
14,
2970,
14,
2246,
360,
466,
1333,
339,
2396,
275,
1056,
14,
2970,
14,
2246,
360,
1317,
297,
6899,
339,
372,
2004,
12,
990,
2396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2446,
8,
1069,
12,
1177,
304,
272,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
12834,
401,
1056,
14,
2139,
14,
362,
480,
6493,
2237,
272,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
920,
4070,
13,
9883,
401,
298,
56,
13,
2017,
13,
3767,
531,
339,
340,
1056,
14,
765,
508,
283,
8808,
356,
267,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
10385,
401,
221,
298,
2970,
12,
6624,
948,
6945,
12,
13053,
12,
8761,
12,
18337,
531,
339,
340,
283,
2139,
7,
315,
1056,
14,
2970,
26,
267,
1177,
14,
2139,
14,
409,
480,
3946,
13,
3717,
13,
7852,
13,
9883,
401,
221,
1056,
14,
2970,
14,
2246,
360,
2139,
1333,
339,
1177,
14,
2139,
14,
409,
480,
56,
13,
2017,
13,
3767,
401,
1056,
14,
765,
9,
339,
1177,
14,
2139,
14,
409,
480,
56,
13,
33,
13,
35,
13,
2017,
13,
3767,
401,
1056,
14,
2139,
14,
362,
480,
3946,
13,
3717,
13,
2017,
13,
3767,
401,
25491,
2378,
327,
2765,
1077,
4499,
6665,
1736,
367,
4750,
1177,
9479,
14,
272,
862,
26,
267,
1233,
275,
1109,
8,
1069,
14,
2970,
14,
2246,
480,
600,
401,
1926,
430,
272,
871,
1722,
26,
267,
1233,
275,
1926,
339,
1318,
275,
1056,
14,
2970,
14,
2246,
480,
505,
401,
298,
7474,
39,
531,
339,
340,
1056,
14,
765,
508,
298,
8808,
2,
436,
298,
13829,
4040,
2,
315,
1056,
14,
2970,
26,
267,
862,
26,
288,
1233,
275,
1109,
8,
1069,
14,
2970,
14,
2246,
360,
13829,
4040,
1333,
267,
871,
4067,
26,
288,
986,
339,
2004,
275,
1233,
12,
1318,
339,
340,
298,
466,
2,
315,
1056,
14,
2970,
26,
267,
1177,
14,
2139,
14,
409,
480,
2714,
13,
804,
401,
1056,
14,
2970,
14,
2246,
360,
466,
1333,
339,
2396,
275,
1056,
14,
2970,
14,
2246,
360,
1317,
297,
6899,
339,
372,
2004,
12,
990,
2396,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dgarciam/Sick-Beard
|
lib/hachoir_core/field/basic_field_set.py
|
90
|
4762
|
from lib.hachoir_core.field import Field, FieldError
from lib.hachoir_core.stream import InputStream
from lib.hachoir_core.endian import BIG_ENDIAN, LITTLE_ENDIAN
from lib.hachoir_core.event_handler import EventHandler
class ParserError(FieldError):
"""
Error raised by a field set.
@see: L{FieldError}
"""
pass
class MatchError(FieldError):
"""
Error raised by a field set when the stream content doesn't
match to file format.
@see: L{FieldError}
"""
pass
class BasicFieldSet(Field):
_event_handler = None
is_field_set = True
endian = None
def __init__(self, parent, name, stream, description, size):
# Sanity checks (preconditions)
assert not parent or issubclass(parent.__class__, BasicFieldSet)
assert issubclass(stream.__class__, InputStream)
# Set field set size
if size is None and self.static_size:
assert isinstance(self.static_size, (int, long))
size = self.static_size
# Set Field attributes
self._parent = parent
self._name = name
self._size = size
self._description = description
self.stream = stream
self._field_array_count = {}
# Set endian
if not self.endian:
assert parent and parent.endian
self.endian = parent.endian
if parent:
# This field set is one of the root leafs
self._address = parent.nextFieldAddress()
self.root = parent.root
assert id(self.stream) == id(parent.stream)
else:
# This field set is the root
self._address = 0
self.root = self
self._global_event_handler = None
# Sanity checks (post-conditions)
assert self.endian in (BIG_ENDIAN, LITTLE_ENDIAN)
if (self._size is not None) and (self._size <= 0):
raise ParserError("Invalid parser '%s' size: %s" % (self.path, self._size))
def reset(self):
self._field_array_count = {}
def createValue(self):
return None
def connectEvent(self, event_name, handler, local=True):
assert event_name in (
# Callback prototype: def f(field)
# Called when new value is already set
"field-value-changed",
# Callback prototype: def f(field)
# Called when field size is already set
"field-resized",
# A new field has been inserted in the field set
# Callback prototype: def f(index, new_field)
"field-inserted",
# Callback prototype: def f(old_field, new_field)
# Called when new field is already in field set
"field-replaced",
# Callback prototype: def f(field, new_value)
# Called to ask to set new value
"set-field-value"
), "Event name %r is invalid" % event_name
if local:
if self._event_handler is None:
self._event_handler = EventHandler()
self._event_handler.connect(event_name, handler)
else:
if self.root._global_event_handler is None:
self.root._global_event_handler = EventHandler()
self.root._global_event_handler.connect(event_name, handler)
def raiseEvent(self, event_name, *args):
# Transfer event to local listeners
if self._event_handler is not None:
self._event_handler.raiseEvent(event_name, *args)
# Transfer event to global listeners
if self.root._global_event_handler is not None:
self.root._global_event_handler.raiseEvent(event_name, *args)
def setUniqueFieldName(self, field):
key = field._name[:-2]
try:
self._field_array_count[key] += 1
except KeyError:
self._field_array_count[key] = 0
field._name = key + "[%u]" % self._field_array_count[key]
def readFirstFields(self, number):
"""
Read first number fields if they are not read yet.
Returns number of new added fields.
"""
number = number - self.current_length
if 0 < number:
return self.readMoreFields(number)
else:
return 0
def createFields(self):
raise NotImplementedError()
def __iter__(self):
raise NotImplementedError()
def __len__(self):
raise NotImplementedError()
def getField(self, key, const=True):
raise NotImplementedError()
def nextFieldAddress(self):
raise NotImplementedError()
def getFieldIndex(self, field):
raise NotImplementedError()
def readMoreFields(self, number):
raise NotImplementedError()
|
gpl-3.0
|
[
504,
1973,
14,
72,
21301,
63,
1018,
14,
698,
492,
5024,
12,
27691,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
1745,
492,
6924,
3296,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
15009,
492,
16524,
63,
21046,
12,
491,
31783,
63,
21046,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
1430,
63,
2232,
492,
6763,
2461,
199,
199,
533,
10191,
547,
8,
792,
547,
304,
272,
408,
272,
4520,
4915,
701,
282,
901,
663,
14,
339,
768,
3239,
26,
491,
91,
792,
547,
93,
272,
408,
272,
986,
199,
199,
533,
9814,
547,
8,
792,
547,
304,
272,
408,
272,
4520,
4915,
701,
282,
901,
663,
1380,
314,
2547,
1564,
3181,
1133,
272,
1336,
370,
570,
1475,
14,
339,
768,
3239,
26,
491,
91,
792,
547,
93,
272,
408,
272,
986,
199,
199,
533,
10082,
23532,
8,
792,
304,
272,
485,
1430,
63,
2232,
275,
488,
272,
365,
63,
698,
63,
409,
275,
715,
272,
17638,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
2547,
12,
1369,
12,
1568,
304,
267,
327,
22111,
5920,
334,
657,
9855,
9,
267,
702,
440,
1676,
503,
11602,
8,
1708,
855,
533,
3108,
10082,
23532,
9,
267,
702,
11602,
8,
1745,
855,
533,
3108,
6924,
3296,
9,
398,
327,
2494,
901,
663,
1568,
267,
340,
1568,
365,
488,
436,
291,
14,
1986,
63,
890,
26,
288,
702,
1228,
8,
277,
14,
1986,
63,
890,
12,
334,
442,
12,
1846,
430,
288,
1568,
275,
291,
14,
1986,
63,
890,
398,
327,
2494,
5024,
3004,
267,
291,
423,
1708,
275,
1676,
267,
291,
423,
354,
275,
536,
267,
291,
423,
890,
275,
1568,
267,
291,
423,
1802,
275,
1369,
267,
291,
14,
1745,
275,
2547,
267,
291,
423,
698,
63,
1144,
63,
835,
275,
1052,
398,
327,
2494,
17638,
267,
340,
440,
291,
14,
15009,
26,
288,
702,
1676,
436,
1676,
14,
15009,
288,
291,
14,
15009,
275,
1676,
14,
15009,
398,
340,
1676,
26,
288,
327,
961,
901,
663,
365,
1373,
402,
314,
1738,
1026,
65,
2319,
288,
291,
423,
1562,
275,
1676,
14,
2184,
792,
1476,
342,
288,
291,
14,
1231,
275,
1676,
14,
1231,
288,
702,
1305,
8,
277,
14,
1745,
9,
508,
1305,
8,
1708,
14,
1745,
9,
267,
587,
26,
288,
327,
961,
901,
663,
365,
314,
1738,
288,
291,
423,
1562,
275,
378,
288,
291,
14,
1231,
275,
291,
288,
291,
423,
2966,
63,
1430,
63,
2232,
275,
488,
398,
327,
22111,
5920,
334,
1932,
13,
9855,
9,
267,
702,
291,
14,
15009,
315,
334,
18643,
63,
21046,
12,
491,
31783,
63,
21046,
9,
267,
340,
334,
277,
423,
890,
365,
440,
488,
9,
436,
334,
277,
423,
890,
2695,
378,
304,
288,
746,
10191,
547,
480,
3364,
1798,
1543,
83,
7,
1568,
26,
450,
83,
2,
450,
334,
277,
14,
515,
12,
291,
423,
890,
430,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
698,
63,
1144,
63,
835,
275,
1052,
339,
347,
1218,
1110,
8,
277,
304,
267,
372,
488,
339,
347,
4907,
2390,
8,
277,
12,
1566,
63,
354,
12,
3016,
12,
2257,
29,
549,
304,
267,
702,
1566,
63,
354,
315,
334,
288,
327,
17555,
19393,
26,
347,
289,
8,
698,
9,
288,
327,
12295,
1380,
892,
574,
365,
2575,
663,
288,
298,
698,
13,
585,
13,
2489,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
698,
9,
288,
327,
12295,
1380,
901,
1568,
365,
2575,
663,
288,
298,
698,
13,
264,
15308,
401,
953,
327,
437,
892,
901,
965,
2757,
11788,
315,
314,
901,
663,
288,
327,
17555,
19393,
26,
347,
289,
8,
1080,
12,
892,
63,
698,
9,
288,
298,
698,
13,
28565,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
1753,
63,
698,
12,
892,
63,
698,
9,
288,
327,
12295,
1380,
892,
901,
365,
2575,
315,
901,
663,
288,
298,
698,
13,
31473,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
698,
12,
892,
63,
585,
9,
288,
327,
12295,
370,
7198,
370,
663,
892,
574,
288,
298,
409,
13,
698,
13,
585,
2,
267,
2318,
298,
2390,
536,
450,
82,
365,
3866,
2,
450,
1566,
63,
354,
267,
340,
2257,
26,
288,
340,
291,
423,
1430,
63,
2232,
365,
488,
26,
355,
291,
423,
1430,
63,
2232,
275,
6763,
2461,
342,
288,
291,
423,
1430,
63,
2232,
14,
2242,
8,
1430,
63,
354,
12,
3016,
9,
267,
587,
26,
288,
340,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
365,
488,
26,
355,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
275,
6763,
2461,
342,
288,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
14,
2242,
8,
1430,
63,
354,
12,
3016,
9,
339,
347,
746,
2390,
8,
277,
12,
1566,
63,
354,
12,
627,
589,
304,
267,
327,
27507,
1566,
370,
2257,
19946,
267,
340,
291,
423,
1430,
63,
2232,
365,
440,
488,
26,
288,
291,
423,
1430,
63,
2232,
14,
3730,
2390,
8,
1430,
63,
354,
12,
627,
589,
9,
398,
327,
27507,
1566,
370,
2288,
19946,
267,
340,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
365,
440,
488,
26,
288,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
14,
3730,
2390,
8,
1430,
63,
354,
12,
627,
589,
9,
339,
347,
663,
11427,
792,
985,
8,
277,
12,
901,
304,
267,
790,
275,
901,
423,
354,
4439,
18,
61,
267,
862,
26,
288,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
847,
413,
267,
871,
4067,
26,
288,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
275,
378,
267,
901,
423,
354,
275,
790,
435,
26503,
85,
8480,
450,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
339,
347,
1586,
7147,
7304,
8,
277,
12,
1329,
304,
267,
408,
267,
5574,
1642,
1329,
1504,
340,
2985,
787,
440,
1586,
5966,
14,
398,
1803,
1329,
402,
892,
3483,
1504,
14,
267,
408,
267,
1329,
275,
1329,
446,
291,
14,
1818,
63,
1267,
267,
340,
378,
665,
1329,
26,
288,
372,
291,
14,
739,
11053,
7304,
8,
1955,
9,
267,
587,
26,
288,
372,
378,
339,
347,
24828,
8,
277,
304,
267,
746,
4279,
342,
272,
347,
636,
1661
] |
[
1973,
14,
72,
21301,
63,
1018,
14,
698,
492,
5024,
12,
27691,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
1745,
492,
6924,
3296,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
15009,
492,
16524,
63,
21046,
12,
491,
31783,
63,
21046,
199,
504,
1973,
14,
72,
21301,
63,
1018,
14,
1430,
63,
2232,
492,
6763,
2461,
199,
199,
533,
10191,
547,
8,
792,
547,
304,
272,
408,
272,
4520,
4915,
701,
282,
901,
663,
14,
339,
768,
3239,
26,
491,
91,
792,
547,
93,
272,
408,
272,
986,
199,
199,
533,
9814,
547,
8,
792,
547,
304,
272,
408,
272,
4520,
4915,
701,
282,
901,
663,
1380,
314,
2547,
1564,
3181,
1133,
272,
1336,
370,
570,
1475,
14,
339,
768,
3239,
26,
491,
91,
792,
547,
93,
272,
408,
272,
986,
199,
199,
533,
10082,
23532,
8,
792,
304,
272,
485,
1430,
63,
2232,
275,
488,
272,
365,
63,
698,
63,
409,
275,
715,
272,
17638,
275,
488,
339,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
2547,
12,
1369,
12,
1568,
304,
267,
327,
22111,
5920,
334,
657,
9855,
9,
267,
702,
440,
1676,
503,
11602,
8,
1708,
855,
533,
3108,
10082,
23532,
9,
267,
702,
11602,
8,
1745,
855,
533,
3108,
6924,
3296,
9,
398,
327,
2494,
901,
663,
1568,
267,
340,
1568,
365,
488,
436,
291,
14,
1986,
63,
890,
26,
288,
702,
1228,
8,
277,
14,
1986,
63,
890,
12,
334,
442,
12,
1846,
430,
288,
1568,
275,
291,
14,
1986,
63,
890,
398,
327,
2494,
5024,
3004,
267,
291,
423,
1708,
275,
1676,
267,
291,
423,
354,
275,
536,
267,
291,
423,
890,
275,
1568,
267,
291,
423,
1802,
275,
1369,
267,
291,
14,
1745,
275,
2547,
267,
291,
423,
698,
63,
1144,
63,
835,
275,
1052,
398,
327,
2494,
17638,
267,
340,
440,
291,
14,
15009,
26,
288,
702,
1676,
436,
1676,
14,
15009,
288,
291,
14,
15009,
275,
1676,
14,
15009,
398,
340,
1676,
26,
288,
327,
961,
901,
663,
365,
1373,
402,
314,
1738,
1026,
65,
2319,
288,
291,
423,
1562,
275,
1676,
14,
2184,
792,
1476,
342,
288,
291,
14,
1231,
275,
1676,
14,
1231,
288,
702,
1305,
8,
277,
14,
1745,
9,
508,
1305,
8,
1708,
14,
1745,
9,
267,
587,
26,
288,
327,
961,
901,
663,
365,
314,
1738,
288,
291,
423,
1562,
275,
378,
288,
291,
14,
1231,
275,
291,
288,
291,
423,
2966,
63,
1430,
63,
2232,
275,
488,
398,
327,
22111,
5920,
334,
1932,
13,
9855,
9,
267,
702,
291,
14,
15009,
315,
334,
18643,
63,
21046,
12,
491,
31783,
63,
21046,
9,
267,
340,
334,
277,
423,
890,
365,
440,
488,
9,
436,
334,
277,
423,
890,
2695,
378,
304,
288,
746,
10191,
547,
480,
3364,
1798,
1543,
83,
7,
1568,
26,
450,
83,
2,
450,
334,
277,
14,
515,
12,
291,
423,
890,
430,
339,
347,
5305,
8,
277,
304,
267,
291,
423,
698,
63,
1144,
63,
835,
275,
1052,
339,
347,
1218,
1110,
8,
277,
304,
267,
372,
488,
339,
347,
4907,
2390,
8,
277,
12,
1566,
63,
354,
12,
3016,
12,
2257,
29,
549,
304,
267,
702,
1566,
63,
354,
315,
334,
288,
327,
17555,
19393,
26,
347,
289,
8,
698,
9,
288,
327,
12295,
1380,
892,
574,
365,
2575,
663,
288,
298,
698,
13,
585,
13,
2489,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
698,
9,
288,
327,
12295,
1380,
901,
1568,
365,
2575,
663,
288,
298,
698,
13,
264,
15308,
401,
953,
327,
437,
892,
901,
965,
2757,
11788,
315,
314,
901,
663,
288,
327,
17555,
19393,
26,
347,
289,
8,
1080,
12,
892,
63,
698,
9,
288,
298,
698,
13,
28565,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
1753,
63,
698,
12,
892,
63,
698,
9,
288,
327,
12295,
1380,
892,
901,
365,
2575,
315,
901,
663,
288,
298,
698,
13,
31473,
401,
953,
327,
17555,
19393,
26,
347,
289,
8,
698,
12,
892,
63,
585,
9,
288,
327,
12295,
370,
7198,
370,
663,
892,
574,
288,
298,
409,
13,
698,
13,
585,
2,
267,
2318,
298,
2390,
536,
450,
82,
365,
3866,
2,
450,
1566,
63,
354,
267,
340,
2257,
26,
288,
340,
291,
423,
1430,
63,
2232,
365,
488,
26,
355,
291,
423,
1430,
63,
2232,
275,
6763,
2461,
342,
288,
291,
423,
1430,
63,
2232,
14,
2242,
8,
1430,
63,
354,
12,
3016,
9,
267,
587,
26,
288,
340,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
365,
488,
26,
355,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
275,
6763,
2461,
342,
288,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
14,
2242,
8,
1430,
63,
354,
12,
3016,
9,
339,
347,
746,
2390,
8,
277,
12,
1566,
63,
354,
12,
627,
589,
304,
267,
327,
27507,
1566,
370,
2257,
19946,
267,
340,
291,
423,
1430,
63,
2232,
365,
440,
488,
26,
288,
291,
423,
1430,
63,
2232,
14,
3730,
2390,
8,
1430,
63,
354,
12,
627,
589,
9,
398,
327,
27507,
1566,
370,
2288,
19946,
267,
340,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
365,
440,
488,
26,
288,
291,
14,
1231,
423,
2966,
63,
1430,
63,
2232,
14,
3730,
2390,
8,
1430,
63,
354,
12,
627,
589,
9,
339,
347,
663,
11427,
792,
985,
8,
277,
12,
901,
304,
267,
790,
275,
901,
423,
354,
4439,
18,
61,
267,
862,
26,
288,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
847,
413,
267,
871,
4067,
26,
288,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
275,
378,
267,
901,
423,
354,
275,
790,
435,
26503,
85,
8480,
450,
291,
423,
698,
63,
1144,
63,
835,
59,
498,
61,
339,
347,
1586,
7147,
7304,
8,
277,
12,
1329,
304,
267,
408,
267,
5574,
1642,
1329,
1504,
340,
2985,
787,
440,
1586,
5966,
14,
398,
1803,
1329,
402,
892,
3483,
1504,
14,
267,
408,
267,
1329,
275,
1329,
446,
291,
14,
1818,
63,
1267,
267,
340,
378,
665,
1329,
26,
288,
372,
291,
14,
739,
11053,
7304,
8,
1955,
9,
267,
587,
26,
288,
372,
378,
339,
347,
24828,
8,
277,
304,
267,
746,
4279,
342,
272,
347,
636,
1661,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
heke123/chromium-crosswalk
|
third_party/WebKit/Tools/Scripts/webkitpy/layout_tests/breakpad/dump_reader_multipart_unittest.py
|
7
|
5181
|
# Copyright (C) 2013 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
from webkitpy.common.host import Host
from webkitpy.common.host_mock import MockHost
from webkitpy.common.system.executive_mock import MockExecutive
from webkitpy.layout_tests.breakpad.dump_reader_multipart import DumpReaderMultipart
class TestDumpReaderMultipart(unittest.TestCase):
_MULTIPART_DUMP = [
'--boundary',
'Content-Disposition: form-data; name="prod"',
'',
'content_shell',
'--boundary',
'Content-Disposition: form-data; name="pid"',
'',
'4711',
'--boundary',
'Content-Disposition: form-data; name="upload_file_minidump"; filename="dump"',
'Content-Type: application/octet-stream',
'',
'MDMP',
'--boundary--',
]
def test_check_generate_breakpad_symbols_actually_exists(self):
host = Host()
dump_reader = DumpReaderMultipart(host, build_dir=None)
self.assertTrue(host.filesystem.exists(dump_reader._path_to_generate_breakpad_symbols()))
def test_check_is_functional_breakpad_tools_not_found(self):
host = MockHost()
build_dir = "/mock-checkout/out/Debug"
host.filesystem.maybe_make_directory(build_dir)
dump_reader = DumpReaderMultipart(host, build_dir)
dump_reader._file_extension = lambda: 'dmp'
dump_reader._binaries_to_symbolize = lambda: ['content_shell']
self.assertFalse(dump_reader.check_is_functional())
def test_get_pid_from_dump(self):
host = MockHost()
dump_file = '/crash-dumps/dump.dmp'
expected_pid = '4711'
host.filesystem.write_text_file(dump_file, "\r\n".join(TestDumpReaderMultipart._MULTIPART_DUMP))
build_dir = "/mock-checkout/out/Debug"
host.filesystem.maybe_make_directory(build_dir)
host.filesystem.exists = lambda x: True
# The mock file object returned by open_binary_file_for_reading doesn't
# have readline(), however, the real File object does.
host.filesystem.open_binary_file_for_reading = host.filesystem.open_text_file_for_reading
dump_reader = DumpReaderMultipart(host, build_dir)
dump_reader._file_extension = lambda: 'dmp'
dump_reader._binaries_to_symbolize = lambda: ['content_shell']
self.assertTrue(dump_reader.check_is_functional())
self.assertEqual(expected_pid, dump_reader._get_pid_from_dump(dump_file))
def test_get_stack_from_dump(self):
host = MockHost()
dump_file = '/crash-dumps/dump.dmp'
host.filesystem.write_text_file(dump_file, "\r\n".join(TestDumpReaderMultipart._MULTIPART_DUMP))
build_dir = "/mock-checkout/out/Debug"
host.filesystem.maybe_make_directory(build_dir)
host.filesystem.exists = lambda x: True
# The mock file object returned by open_binary_file_for_reading doesn't
# have readline(), however, the real File object does.
host.filesystem.open_binary_file_for_reading = host.filesystem.open_text_file_for_reading
dump_reader = DumpReaderMultipart(host, build_dir)
dump_reader._file_extension = lambda: 'dmp'
dump_reader._binaries_to_symbolize = lambda: ['content_shell']
self.assertTrue(dump_reader.check_is_functional())
self.assertEqual("MOCK output of child process", dump_reader._get_stack_from_dump(dump_file))
self.assertEqual(2, len(host.executive.calls))
cmd_line = " ".join(host.executive.calls[0])
self.assertIn('generate_breakpad_symbols.py', cmd_line)
cmd_line = " ".join(host.executive.calls[1])
self.assertIn('minidump_stackwalk', cmd_line)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
421,
199,
504,
18007,
14,
2330,
14,
1102,
492,
10891,
199,
504,
18007,
14,
2330,
14,
1102,
63,
1805,
492,
4420,
4965,
199,
504,
18007,
14,
2330,
14,
2253,
14,
1628,
13441,
63,
1805,
492,
4420,
4858,
13441,
199,
504,
18007,
14,
4209,
63,
2219,
14,
4785,
6226,
14,
2724,
63,
5503,
63,
10123,
492,
19460,
5929,
27242,
421,
199,
533,
1379,
11772,
5929,
27242,
8,
2796,
14,
1746,
304,
272,
485,
21894,
2294,
63,
26406,
275,
359,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
8788,
6949,
267,
3260,
267,
283,
1317,
63,
5641,
297,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
3150,
6949,
267,
3260,
267,
283,
2417,
845,
297,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
5064,
63,
493,
63,
827,
344,
1220,
11436,
1788,
628,
2724,
6949,
267,
283,
2714,
13,
804,
26,
4223,
15,
18162,
13,
1745,
297,
267,
3260,
267,
283,
5127,
1658,
297,
267,
2850,
9891,
306,
297,
272,
1622,
339,
347,
511,
63,
1074,
63,
4208,
63,
4785,
6226,
63,
7450,
63,
2442,
3163,
63,
2444,
8,
277,
304,
267,
1591,
275,
10891,
342,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
29,
403,
9,
267,
291,
14,
1815,
8,
1102,
14,
11381,
14,
2444,
8,
2724,
63,
5503,
423,
515,
63,
475,
63,
4208,
63,
4785,
6226,
63,
7450,
4059,
339,
347,
511,
63,
1074,
63,
374,
63,
15481,
63,
4785,
6226,
63,
2537,
63,
1397,
63,
4214,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
1900,
63,
694,
275,
3286,
1805,
13,
12891,
15,
548,
15,
7084,
2,
267,
1591,
14,
11381,
14,
11853,
63,
1875,
63,
3619,
8,
1506,
63,
694,
9,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
9,
267,
5461,
63,
5503,
423,
493,
63,
3435,
275,
2400,
26,
283,
10930,
7,
267,
5461,
63,
5503,
423,
27542,
63,
475,
63,
3840,
656,
13559,
275,
2400,
26,
788,
1317,
63,
5641,
418,
398,
291,
14,
3334,
8,
2724,
63,
5503,
14,
1074,
63,
374,
63,
15481,
1012,
339,
347,
511,
63,
362,
63,
3150,
63,
504,
63,
2724,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
5461,
63,
493,
275,
1994,
14807,
13,
4180,
15,
2724,
14,
10930,
7,
267,
1420,
63,
3150,
275,
283,
2417,
845,
7,
267,
1591,
14,
11381,
14,
952,
63,
505,
63,
493,
8,
2724,
63,
493,
12,
1867,
82,
60,
78,
1674,
904,
8,
774,
11772,
5929,
27242,
423,
21894,
2294,
63,
26406,
430,
267,
1900,
63,
694,
275,
3286,
1805,
13,
12891,
15,
548,
15,
7084,
2,
267,
1591,
14,
11381,
14,
11853,
63,
1875,
63,
3619,
8,
1506,
63,
694,
9,
267,
1591,
14,
11381,
14,
2444,
275,
2400,
671,
26,
715,
398,
327,
710,
1683,
570,
909,
2138,
701,
1551,
63,
3008,
63,
493,
63,
509,
63,
19332,
3181,
1133,
267,
327,
1172,
14441,
1062,
13432,
12,
314,
3363,
3814,
909,
1630,
14,
267,
1591,
14,
11381,
14,
1490,
63,
3008,
63,
493,
63,
509,
63,
19332,
275,
1591,
14,
11381,
14,
1490,
63,
505,
63,
493,
63,
509,
63,
19332,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
9,
267,
5461,
63,
5503,
423,
493,
63,
3435,
275,
2400,
26,
283,
10930,
7,
267,
5461,
63,
5503,
423,
27542,
63,
475,
63,
3840,
656,
13559,
275,
2400,
26,
788,
1317,
63,
5641,
418,
398,
291,
14,
1815,
8,
2724,
63,
5503,
14,
1074,
63,
374,
63,
15481,
1012,
267,
291,
14,
629,
8,
2062,
63,
3150,
12,
5461,
63,
5503,
423,
362,
63,
3150,
63,
504,
63,
2724,
8,
2724,
63,
493,
430,
339,
347,
511,
63,
362,
63,
2340,
63,
504,
63,
2724,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
5461,
63,
493,
275,
1994,
14807,
13,
4180,
15,
2724,
14,
10930,
7,
267,
1591,
14,
11381,
14,
952,
63,
505,
63,
493,
8,
2724,
63,
493,
12,
1867,
82,
60,
78,
1674,
904,
8,
774,
11772,
5929,
27242,
423,
21894,
2294,
63,
26406
] |
[
1898,
334,
35,
9,
6171,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
421,
199,
504,
18007,
14,
2330,
14,
1102,
492,
10891,
199,
504,
18007,
14,
2330,
14,
1102,
63,
1805,
492,
4420,
4965,
199,
504,
18007,
14,
2330,
14,
2253,
14,
1628,
13441,
63,
1805,
492,
4420,
4858,
13441,
199,
504,
18007,
14,
4209,
63,
2219,
14,
4785,
6226,
14,
2724,
63,
5503,
63,
10123,
492,
19460,
5929,
27242,
421,
199,
533,
1379,
11772,
5929,
27242,
8,
2796,
14,
1746,
304,
272,
485,
21894,
2294,
63,
26406,
275,
359,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
8788,
6949,
267,
3260,
267,
283,
1317,
63,
5641,
297,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
3150,
6949,
267,
3260,
267,
283,
2417,
845,
297,
267,
2850,
9891,
297,
267,
283,
2714,
13,
15954,
26,
1824,
13,
576,
27,
536,
628,
5064,
63,
493,
63,
827,
344,
1220,
11436,
1788,
628,
2724,
6949,
267,
283,
2714,
13,
804,
26,
4223,
15,
18162,
13,
1745,
297,
267,
3260,
267,
283,
5127,
1658,
297,
267,
2850,
9891,
306,
297,
272,
1622,
339,
347,
511,
63,
1074,
63,
4208,
63,
4785,
6226,
63,
7450,
63,
2442,
3163,
63,
2444,
8,
277,
304,
267,
1591,
275,
10891,
342,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
29,
403,
9,
267,
291,
14,
1815,
8,
1102,
14,
11381,
14,
2444,
8,
2724,
63,
5503,
423,
515,
63,
475,
63,
4208,
63,
4785,
6226,
63,
7450,
4059,
339,
347,
511,
63,
1074,
63,
374,
63,
15481,
63,
4785,
6226,
63,
2537,
63,
1397,
63,
4214,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
1900,
63,
694,
275,
3286,
1805,
13,
12891,
15,
548,
15,
7084,
2,
267,
1591,
14,
11381,
14,
11853,
63,
1875,
63,
3619,
8,
1506,
63,
694,
9,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
9,
267,
5461,
63,
5503,
423,
493,
63,
3435,
275,
2400,
26,
283,
10930,
7,
267,
5461,
63,
5503,
423,
27542,
63,
475,
63,
3840,
656,
13559,
275,
2400,
26,
788,
1317,
63,
5641,
418,
398,
291,
14,
3334,
8,
2724,
63,
5503,
14,
1074,
63,
374,
63,
15481,
1012,
339,
347,
511,
63,
362,
63,
3150,
63,
504,
63,
2724,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
5461,
63,
493,
275,
1994,
14807,
13,
4180,
15,
2724,
14,
10930,
7,
267,
1420,
63,
3150,
275,
283,
2417,
845,
7,
267,
1591,
14,
11381,
14,
952,
63,
505,
63,
493,
8,
2724,
63,
493,
12,
1867,
82,
60,
78,
1674,
904,
8,
774,
11772,
5929,
27242,
423,
21894,
2294,
63,
26406,
430,
267,
1900,
63,
694,
275,
3286,
1805,
13,
12891,
15,
548,
15,
7084,
2,
267,
1591,
14,
11381,
14,
11853,
63,
1875,
63,
3619,
8,
1506,
63,
694,
9,
267,
1591,
14,
11381,
14,
2444,
275,
2400,
671,
26,
715,
398,
327,
710,
1683,
570,
909,
2138,
701,
1551,
63,
3008,
63,
493,
63,
509,
63,
19332,
3181,
1133,
267,
327,
1172,
14441,
1062,
13432,
12,
314,
3363,
3814,
909,
1630,
14,
267,
1591,
14,
11381,
14,
1490,
63,
3008,
63,
493,
63,
509,
63,
19332,
275,
1591,
14,
11381,
14,
1490,
63,
505,
63,
493,
63,
509,
63,
19332,
267,
5461,
63,
5503,
275,
19460,
5929,
27242,
8,
1102,
12,
1900,
63,
694,
9,
267,
5461,
63,
5503,
423,
493,
63,
3435,
275,
2400,
26,
283,
10930,
7,
267,
5461,
63,
5503,
423,
27542,
63,
475,
63,
3840,
656,
13559,
275,
2400,
26,
788,
1317,
63,
5641,
418,
398,
291,
14,
1815,
8,
2724,
63,
5503,
14,
1074,
63,
374,
63,
15481,
1012,
267,
291,
14,
629,
8,
2062,
63,
3150,
12,
5461,
63,
5503,
423,
362,
63,
3150,
63,
504,
63,
2724,
8,
2724,
63,
493,
430,
339,
347,
511,
63,
362,
63,
2340,
63,
504,
63,
2724,
8,
277,
304,
267,
1591,
275,
4420,
4965,
342,
398,
5461,
63,
493,
275,
1994,
14807,
13,
4180,
15,
2724,
14,
10930,
7,
267,
1591,
14,
11381,
14,
952,
63,
505,
63,
493,
8,
2724,
63,
493,
12,
1867,
82,
60,
78,
1674,
904,
8,
774,
11772,
5929,
27242,
423,
21894,
2294,
63,
26406,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mioann47/mobile-app-privacy-analyzer
|
mypythonscripts/tools/modified/androguard/decompiler/dad/control_flow.py
|
7
|
15440
|
# This file is part of Androguard.
#
# Copyright (c) 2012 Geoffroy Gueguen <geoffroy.gueguen@gmail.com>
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from collections import defaultdict
from tools.modified.androguard.decompiler.dad.basic_blocks import (CatchBlock,
Condition,
LoopBlock,
ShortCircuitBlock,
TryBlock)
from tools.modified.androguard.decompiler.dad.graph import Graph
from tools.modified.androguard.decompiler.dad.node import Interval
from tools.modified.androguard.decompiler.dad.util import common_dom
logger = logging.getLogger('dad.control_flow')
def intervals(graph):
'''
Compute the intervals of the graph
Returns
interval_graph: a graph of the intervals of G
interv_heads: a dict of (header node, interval)
'''
interval_graph = Graph() # graph of intervals
heads = [graph.entry] # list of header nodes
interv_heads = {} # interv_heads[i] = interval of header i
processed = dict([(i, False) for i in graph])
edges = defaultdict(list)
while heads:
head = heads.pop(0)
if not processed[head]:
processed[head] = True
interv_heads[head] = Interval(head)
# Check if there is a node which has all its predecessor in the
# current interval. If there is, add that node to the interval and
# repeat until all the possible nodes have been added.
change = True
while change:
change = False
for node in graph.rpo[1:]:
if all(
p in interv_heads[head] for p in graph.all_preds(node)):
change |= interv_heads[head].add_node(node)
# At this stage, a node which is not in the interval, but has one
# of its predecessor in it, is the header of another interval. So
# we add all such nodes to the header list.
for node in graph:
if node not in interv_heads[head] and node not in heads:
if any(
p in interv_heads[head] for p in graph.all_preds(node)):
edges[interv_heads[head]].append(node)
assert(node not in heads)
heads.append(node)
interval_graph.add_node(interv_heads[head])
interv_heads[head].compute_end(graph)
# Edges is a mapping of 'Interval -> [header nodes of interval successors]'
for interval, heads in edges.items():
for head in heads:
interval_graph.add_edge(interval, interv_heads[head])
interval_graph.entry = graph.entry.interval
if graph.exit:
interval_graph.exit = graph.exit.interval
return interval_graph, interv_heads
def derived_sequence(graph):
'''
Compute the derived sequence of the graph G
The intervals of G are collapsed into nodes, intervals of these nodes are
built, and the process is repeated iteratively until we obtain a single
node (if the graph is not irreducible)
'''
deriv_seq = [graph]
deriv_interv = []
single_node = False
while not single_node:
interv_graph, interv_heads = intervals(graph)
deriv_interv.append(interv_heads)
single_node = len(interv_graph) == 1
if not single_node:
deriv_seq.append(interv_graph)
graph = interv_graph
graph.compute_rpo()
return deriv_seq, deriv_interv
def mark_loop_rec(graph, node, s_num, e_num, interval, nodes_in_loop):
if node in nodes_in_loop:
return
nodes_in_loop.append(node)
for pred in graph.all_preds(node):
if s_num < pred.num <= e_num and pred in interval:
mark_loop_rec(graph, pred, s_num, e_num, interval, nodes_in_loop)
def mark_loop(graph, start, end, interval):
logger.debug('MARKLOOP : %s END : %s', start, end)
head = start.get_head()
latch = end.get_end()
nodes_in_loop = [head]
mark_loop_rec(graph, latch, head.num, latch.num, interval, nodes_in_loop)
head.startloop = True
head.latch = latch
return nodes_in_loop
def loop_type(start, end, nodes_in_loop):
if end.type.is_cond:
if start.type.is_cond:
if start.true in nodes_in_loop and start.false in nodes_in_loop:
start.looptype.is_posttest = True
else:
start.looptype.is_pretest = True
else:
start.looptype.is_posttest = True
else:
if start.type.is_cond:
if start.true in nodes_in_loop and start.false in nodes_in_loop:
start.looptype.is_endless = True
else:
start.looptype.is_pretest = True
else:
start.looptype.is_endless = True
def loop_follow(start, end, nodes_in_loop):
follow = None
if start.looptype.is_pretest:
if start.true in nodes_in_loop:
follow = start.false
else:
follow = start.true
elif start.looptype.is_posttest:
if end.true in nodes_in_loop:
follow = end.false
else:
follow = end.true
else:
num_next = float('inf')
for node in nodes_in_loop:
if node.type.is_cond:
if (node.true.num < num_next
and node.true not in nodes_in_loop):
follow = node.true
num_next = follow.num
elif (node.false.num < num_next
and node.false not in nodes_in_loop):
follow = node.false
num_next = follow.num
start.follow['loop'] = follow
for node in nodes_in_loop:
node.follow['loop'] = follow
logger.debug('Start of loop %s', start)
logger.debug('Follow of loop: %s', start.follow['loop'])
def loop_struct(graphs_list, intervals_list):
first_graph = graphs_list[0]
for i, graph in enumerate(graphs_list):
interval = intervals_list[i]
for head in sorted(interval.keys(), key=lambda x: x.num):
loop_nodes = []
for node in graph.all_preds(head):
if node.interval is head.interval:
lnodes = mark_loop(first_graph, head, node, head.interval)
for lnode in lnodes:
if lnode not in loop_nodes:
loop_nodes.append(lnode)
head.get_head().loop_nodes = loop_nodes
def if_struct(graph, idoms):
unresolved = set()
for node in graph.post_order():
if node.type.is_cond:
ldominates = []
for n, idom in idoms.iteritems():
if node is idom and len(graph.reverse_edges.get(n, [])) > 1:
ldominates.append(n)
if len(ldominates) > 0:
n = max(ldominates, key=lambda x: x.num)
node.follow['if'] = n
for x in unresolved.copy():
if node.num < x.num < n.num:
x.follow['if'] = n
unresolved.remove(x)
else:
unresolved.add(node)
return unresolved
def switch_struct(graph, idoms):
unresolved = set()
for node in graph.post_order():
if node.type.is_switch:
m = node
for suc in graph.sucs(node):
if idoms[suc] is not node:
m = common_dom(idoms, node, suc)
ldominates = []
for n, dom in idoms.iteritems():
if m is dom and len(graph.all_preds(n)) > 1:
ldominates.append(n)
if len(ldominates) > 0:
n = max(ldominates, key=lambda x: x.num)
node.follow['switch'] = n
for x in unresolved:
x.follow['switch'] = n
unresolved = set()
else:
unresolved.add(node)
node.order_cases()
# TODO: deal with preds which are in catch
def short_circuit_struct(graph, idom, node_map):
def MergeNodes(node1, node2, is_and, is_not):
lpreds = set()
ldests = set()
for node in (node1, node2):
lpreds.update(graph.preds(node))
ldests.update(graph.sucs(node))
graph.remove_node(node)
done.add(node)
lpreds.difference_update((node1, node2))
ldests.difference_update((node1, node2))
entry = graph.entry in (node1, node2)
new_name = '%s+%s' % (node1.name, node2.name)
condition = Condition(node1, node2, is_and, is_not)
new_node = ShortCircuitBlock(new_name, condition)
for old_n, new_n in node_map.iteritems():
if new_n in (node1, node2):
node_map[old_n] = new_node
node_map[node1] = new_node
node_map[node2] = new_node
idom[new_node] = idom[node1]
idom.pop(node1)
idom.pop(node2)
new_node.copy_from(node1)
graph.add_node(new_node)
for pred in lpreds:
pred.update_attribute_with(node_map)
graph.add_edge(node_map.get(pred, pred), new_node)
for dest in ldests:
graph.add_edge(new_node, node_map.get(dest, dest))
if entry:
graph.entry = new_node
return new_node
change = True
while change:
change = False
done = set()
for node in graph.post_order():
if node.type.is_cond and node not in done:
then = node.true
els = node.false
if node in (then, els):
continue
if then.type.is_cond and len(graph.preds(then)) == 1:
if node in (then.true, then.false):
continue
if then.false is els: # node && t
change = True
merged_node = MergeNodes(node, then, True, False)
merged_node.true = then.true
merged_node.false = els
elif then.true is els: # !node || t
change = True
merged_node = MergeNodes(node, then, False, True)
merged_node.true = els
merged_node.false = then.false
elif els.type.is_cond and len(graph.preds(els)) == 1:
if node in (els.false, els.true):
continue
if els.false is then: # !node && e
change = True
merged_node = MergeNodes(node, els, True, True)
merged_node.true = els.true
merged_node.false = then
elif els.true is then: # node || e
change = True
merged_node = MergeNodes(node, els, False, False)
merged_node.true = then
merged_node.false = els.false
done.add(node)
if change:
graph.compute_rpo()
def while_block_struct(graph, node_map):
change = False
for node in graph.rpo[:]:
if node.startloop:
change = True
new_node = LoopBlock(node.name, node)
node_map[node] = new_node
new_node.copy_from(node)
entry = node is graph.entry
lpreds = graph.preds(node)
lsuccs = graph.sucs(node)
for pred in lpreds:
graph.add_edge(node_map.get(pred, pred), new_node)
for suc in lsuccs:
graph.add_edge(new_node, node_map.get(suc, suc))
if entry:
graph.entry = new_node
if node.type.is_cond:
new_node.true = node.true
new_node.false = node.false
graph.add_node(new_node)
graph.remove_node(node)
if change:
graph.compute_rpo()
def catch_struct(graph, idoms):
block_try_nodes = {}
node_map = {}
for catch_block in graph.reverse_catch_edges:
if catch_block in graph.catch_edges:
continue
catch_node = CatchBlock(catch_block)
try_block = idoms[catch_block]
try_node = block_try_nodes.get(try_block)
if try_node is None:
block_try_nodes[try_block] = TryBlock(try_block)
try_node = block_try_nodes[try_block]
node_map[try_block] = try_node
for pred in graph.all_preds(try_block):
pred.update_attribute_with(node_map)
if try_block in graph.sucs(pred):
graph.edges[pred].remove(try_block)
graph.add_edge(pred, try_node)
if try_block.type.is_stmt:
follow = graph.sucs(try_block)
if follow:
try_node.follow = graph.sucs(try_block)[0]
else:
try_node.follow = None
elif try_block.type.is_cond:
loop_follow = try_block.follow['loop']
if loop_follow:
try_node.follow = loop_follow
else:
try_node.follow = try_block.follow['if']
elif try_block.type.is_switch:
try_node.follow = try_block.follow['switch']
else: # return or throw
try_node.follow = None
try_node.add_catch_node(catch_node)
for node in graph.nodes:
node.update_attribute_with(node_map)
if graph.entry in node_map:
graph.entry = node_map[graph.entry]
def update_dom(idoms, node_map):
for n, dom in idoms.iteritems():
idoms[n] = node_map.get(dom, dom)
def identify_structures(graph, idoms):
Gi, Li = derived_sequence(graph)
switch_struct(graph, idoms)
loop_struct(Gi, Li)
node_map = {}
short_circuit_struct(graph, idoms, node_map)
update_dom(idoms, node_map)
if_unresolved = if_struct(graph, idoms)
while_block_struct(graph, node_map)
update_dom(idoms, node_map)
loop_starts = []
for node in graph.rpo:
node.update_attribute_with(node_map)
if node.startloop:
loop_starts.append(node)
for node in loop_starts:
loop_type(node, node.latch, node.loop_nodes)
loop_follow(node, node.latch, node.loop_nodes)
for node in if_unresolved:
follows = [n for n in (node.follow['loop'],
node.follow['switch']) if n]
if len(follows) >= 1:
follow = min(follows, key=lambda x: x.num)
node.follow['if'] = follow
catch_struct(graph, idoms)
|
gpl-3.0
|
[
3,
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
5346,
1997,
4813,
598,
310,
6051,
287,
665,
303,
1997,
4813,
14,
71,
310,
6051,
287,
32,
6799,
14,
957,
30,
199,
3,
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,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
504,
5055,
492,
10018,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
4316,
63,
4166,
492,
334,
26096,
3142,
12,
8105,
28401,
12,
8105,
18175,
3142,
12,
8105,
20124,
35,
14221,
3142,
12,
8105,
7649,
3142,
9,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2180,
492,
11513,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
932,
492,
18766,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1974,
492,
2863,
63,
4556,
421,
199,
2921,
275,
2050,
14,
5572,
360,
25805,
14,
2785,
63,
1659,
358,
421,
199,
318,
15802,
8,
2180,
304,
272,
1449,
272,
8354,
314,
15802,
402,
314,
3343,
272,
1803,
267,
6252,
63,
2180,
26,
282,
3343,
402,
314,
15802,
402,
598,
267,
1640,
86,
63,
17033,
26,
282,
1211,
402,
334,
1291,
1031,
12,
6252,
9,
272,
1449,
272,
6252,
63,
2180,
275,
11513,
342,
221,
327,
3343,
402,
15802,
272,
25362,
275,
359,
2180,
14,
2373,
61,
221,
327,
769,
402,
1406,
3380,
272,
1640,
86,
63,
17033,
275,
1052,
221,
327,
1640,
86,
63,
17033,
59,
73,
61,
275,
6252,
402,
1406,
284,
272,
7686,
275,
1211,
7694,
73,
12,
756,
9,
367,
284,
315,
3343,
566,
272,
8207,
275,
10018,
8,
513,
9,
339,
1830,
25362,
26,
267,
4854,
275,
25362,
14,
1935,
8,
16,
9,
398,
340,
440,
7686,
59,
2993,
2189,
288,
7686,
59,
2993,
61,
275,
715,
288,
1640,
86,
63,
17033,
59,
2993,
61,
275,
18766,
8,
2993,
9,
953,
327,
2670,
340,
2337,
365,
282,
1031,
1314,
965,
1006,
2399,
876,
27914,
269,
315,
314,
288,
327,
1453,
6252,
14,
982,
2337,
365,
12,
1050,
626,
1031,
370,
314,
6252,
436,
288,
327,
11982,
5133,
1006,
314,
3962,
3380,
1172,
2757,
3483,
14,
288,
1570,
275,
715,
288,
1830,
1570,
26,
355,
1570,
275,
756,
355,
367,
1031,
315,
3343,
14,
82,
555,
59,
17,
10688,
490,
340,
1006,
8,
1993,
299,
315,
1640,
86,
63,
17033,
59,
2993,
61,
367,
299,
315,
3343,
14,
452,
63,
28296,
8,
932,
2298,
717,
1570,
8901,
1640,
86,
63,
17033,
59,
2993,
1055,
525,
63,
932,
8,
932,
9,
953,
327,
2854,
642,
9546,
12,
282,
1031,
1314,
365,
440,
315,
314,
6252,
12,
1325,
965,
1373,
288,
327,
402,
2399,
876,
27914,
269,
315,
652,
12,
365,
314,
1406,
402,
4573,
6252,
14,
2002,
288,
327,
781,
1050,
1006,
4066,
3380,
370,
314,
1406,
769,
14,
288,
367,
1031,
315,
3343,
26,
355,
340,
1031,
440,
315,
1640,
86,
63,
17033,
59,
2993,
61,
436,
1031,
440,
315,
25362,
26,
490,
340,
1263,
8,
1993,
299,
315,
1640,
86,
63,
17033,
59,
2993,
61,
367,
299,
315,
3343,
14,
452,
63,
28296,
8,
932,
2298,
717,
8207,
59,
1058,
86,
63,
17033,
59,
2993,
20230,
740,
8,
932,
9,
717,
702,
8,
932,
440,
315,
25362,
9,
717,
25362,
14,
740,
8,
932,
9,
953,
6252,
63,
2180,
14,
525,
63,
932,
8,
1058,
86,
63,
17033,
59,
2993,
566,
288,
1640,
86,
63,
17033,
59,
2993,
1055,
3357,
63,
500,
8,
2180,
9,
339,
327,
17379,
3389,
365,
282,
4412,
402,
283,
8227,
1035,
359,
1291,
3380,
402,
6252,
3182,
1384,
6616,
272,
367,
6252,
12,
25362,
315,
8207,
14,
1744,
837,
267,
367,
4854,
315,
25362,
26,
288,
6252,
63,
2180,
14,
525,
63,
5173,
8,
4284,
12,
1640,
86,
63,
17033,
59,
2993,
566,
339,
6252,
63,
2180,
14,
2373,
275,
3343,
14,
2373,
14,
4284,
272,
340,
3343,
14,
2224,
26,
267,
6252,
63,
2180,
14,
2224,
275,
3343,
14,
2224,
14,
4284,
339,
372,
6252,
63,
2180,
12,
1640,
86,
63,
17033,
421,
199,
318,
7131,
63,
4041,
8,
2180,
304,
272,
1449,
272,
8354,
314,
7131,
3414,
402,
314,
3343,
598,
272,
710,
15802,
402,
598,
787,
31219,
1901,
3380,
12,
15802,
402,
3520,
3380,
787,
272,
6137,
12,
436,
314,
2112,
365,
10877,
4826,
9462,
5133,
781,
3332,
282,
2849,
272,
1031,
334,
692,
314,
3343,
365,
440,
8190,
19493,
559,
830,
9,
272,
1449,
272,
13624,
63,
3610,
275,
359,
2180,
61,
272,
13624,
63,
1058,
86,
275,
942,
272,
2849,
63,
932,
275,
756,
339,
1830,
440,
2849,
63,
932,
26,
398,
1640,
86,
63,
2180,
12,
1640,
86,
63,
17033,
275,
15802,
8,
2180,
9,
267,
13624,
63,
1058,
86,
14,
740,
8,
1058,
86,
63,
17033,
9,
398,
2849,
63,
932,
275,
822,
8,
1058,
86,
63,
2180,
9,
508,
413,
267,
340,
440,
2849,
63,
932,
26,
288,
13624,
63,
3610,
14,
740,
8,
1058,
86,
63,
2180,
9,
398,
3343,
275,
1640,
86,
63,
2180,
267,
3343,
14,
3357,
63,
82,
555,
342,
339,
372,
13624,
63,
3610,
12,
13624,
63,
1058,
86,
421,
199,
318,
2216,
63,
3813,
63,
2761,
8,
2180,
12,
1031,
12,
308,
63,
1507,
12,
325,
63,
1507,
12,
6252,
12,
3380,
63,
262,
63,
3813,
304,
272,
340,
1031,
315,
3380,
63
] |
[
961,
570,
365,
1777,
402,
6061,
293,
15606,
14,
199,
3,
199,
3,
1898,
334,
67,
9,
6029,
5346,
1997,
4813,
598,
310,
6051,
287,
665,
303,
1997,
4813,
14,
71,
310,
6051,
287,
32,
6799,
14,
957,
30,
199,
3,
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,
13,
1311,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
199,
504,
5055,
492,
10018,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
4316,
63,
4166,
492,
334,
26096,
3142,
12,
8105,
28401,
12,
8105,
18175,
3142,
12,
8105,
20124,
35,
14221,
3142,
12,
8105,
7649,
3142,
9,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
2180,
492,
11513,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
932,
492,
18766,
199,
504,
7249,
14,
5540,
14,
460,
293,
15606,
14,
271,
5772,
14,
25805,
14,
1974,
492,
2863,
63,
4556,
421,
199,
2921,
275,
2050,
14,
5572,
360,
25805,
14,
2785,
63,
1659,
358,
421,
199,
318,
15802,
8,
2180,
304,
272,
1449,
272,
8354,
314,
15802,
402,
314,
3343,
272,
1803,
267,
6252,
63,
2180,
26,
282,
3343,
402,
314,
15802,
402,
598,
267,
1640,
86,
63,
17033,
26,
282,
1211,
402,
334,
1291,
1031,
12,
6252,
9,
272,
1449,
272,
6252,
63,
2180,
275,
11513,
342,
221,
327,
3343,
402,
15802,
272,
25362,
275,
359,
2180,
14,
2373,
61,
221,
327,
769,
402,
1406,
3380,
272,
1640,
86,
63,
17033,
275,
1052,
221,
327,
1640,
86,
63,
17033,
59,
73,
61,
275,
6252,
402,
1406,
284,
272,
7686,
275,
1211,
7694,
73,
12,
756,
9,
367,
284,
315,
3343,
566,
272,
8207,
275,
10018,
8,
513,
9,
339,
1830,
25362,
26,
267,
4854,
275,
25362,
14,
1935,
8,
16,
9,
398,
340,
440,
7686,
59,
2993,
2189,
288,
7686,
59,
2993,
61,
275,
715,
288,
1640,
86,
63,
17033,
59,
2993,
61,
275,
18766,
8,
2993,
9,
953,
327,
2670,
340,
2337,
365,
282,
1031,
1314,
965,
1006,
2399,
876,
27914,
269,
315,
314,
288,
327,
1453,
6252,
14,
982,
2337,
365,
12,
1050,
626,
1031,
370,
314,
6252,
436,
288,
327,
11982,
5133,
1006,
314,
3962,
3380,
1172,
2757,
3483,
14,
288,
1570,
275,
715,
288,
1830,
1570,
26,
355,
1570,
275,
756,
355,
367,
1031,
315,
3343,
14,
82,
555,
59,
17,
10688,
490,
340,
1006,
8,
1993,
299,
315,
1640,
86,
63,
17033,
59,
2993,
61,
367,
299,
315,
3343,
14,
452,
63,
28296,
8,
932,
2298,
717,
1570,
8901,
1640,
86,
63,
17033,
59,
2993,
1055,
525,
63,
932,
8,
932,
9,
953,
327,
2854,
642,
9546,
12,
282,
1031,
1314,
365,
440,
315,
314,
6252,
12,
1325,
965,
1373,
288,
327,
402,
2399,
876,
27914,
269,
315,
652,
12,
365,
314,
1406,
402,
4573,
6252,
14,
2002,
288,
327,
781,
1050,
1006,
4066,
3380,
370,
314,
1406,
769,
14,
288,
367,
1031,
315,
3343,
26,
355,
340,
1031,
440,
315,
1640,
86,
63,
17033,
59,
2993,
61,
436,
1031,
440,
315,
25362,
26,
490,
340,
1263,
8,
1993,
299,
315,
1640,
86,
63,
17033,
59,
2993,
61,
367,
299,
315,
3343,
14,
452,
63,
28296,
8,
932,
2298,
717,
8207,
59,
1058,
86,
63,
17033,
59,
2993,
20230,
740,
8,
932,
9,
717,
702,
8,
932,
440,
315,
25362,
9,
717,
25362,
14,
740,
8,
932,
9,
953,
6252,
63,
2180,
14,
525,
63,
932,
8,
1058,
86,
63,
17033,
59,
2993,
566,
288,
1640,
86,
63,
17033,
59,
2993,
1055,
3357,
63,
500,
8,
2180,
9,
339,
327,
17379,
3389,
365,
282,
4412,
402,
283,
8227,
1035,
359,
1291,
3380,
402,
6252,
3182,
1384,
6616,
272,
367,
6252,
12,
25362,
315,
8207,
14,
1744,
837,
267,
367,
4854,
315,
25362,
26,
288,
6252,
63,
2180,
14,
525,
63,
5173,
8,
4284,
12,
1640,
86,
63,
17033,
59,
2993,
566,
339,
6252,
63,
2180,
14,
2373,
275,
3343,
14,
2373,
14,
4284,
272,
340,
3343,
14,
2224,
26,
267,
6252,
63,
2180,
14,
2224,
275,
3343,
14,
2224,
14,
4284,
339,
372,
6252,
63,
2180,
12,
1640,
86,
63,
17033,
421,
199,
318,
7131,
63,
4041,
8,
2180,
304,
272,
1449,
272,
8354,
314,
7131,
3414,
402,
314,
3343,
598,
272,
710,
15802,
402,
598,
787,
31219,
1901,
3380,
12,
15802,
402,
3520,
3380,
787,
272,
6137,
12,
436,
314,
2112,
365,
10877,
4826,
9462,
5133,
781,
3332,
282,
2849,
272,
1031,
334,
692,
314,
3343,
365,
440,
8190,
19493,
559,
830,
9,
272,
1449,
272,
13624,
63,
3610,
275,
359,
2180,
61,
272,
13624,
63,
1058,
86,
275,
942,
272,
2849,
63,
932,
275,
756,
339,
1830,
440,
2849,
63,
932,
26,
398,
1640,
86,
63,
2180,
12,
1640,
86,
63,
17033,
275,
15802,
8,
2180,
9,
267,
13624,
63,
1058,
86,
14,
740,
8,
1058,
86,
63,
17033,
9,
398,
2849,
63,
932,
275,
822,
8,
1058,
86,
63,
2180,
9,
508,
413,
267,
340,
440,
2849,
63,
932,
26,
288,
13624,
63,
3610,
14,
740,
8,
1058,
86,
63,
2180,
9,
398,
3343,
275,
1640,
86,
63,
2180,
267,
3343,
14,
3357,
63,
82,
555,
342,
339,
372,
13624,
63,
3610,
12,
13624,
63,
1058,
86,
421,
199,
318,
2216,
63,
3813,
63,
2761,
8,
2180,
12,
1031,
12,
308,
63,
1507,
12,
325,
63,
1507,
12,
6252,
12,
3380,
63,
262,
63,
3813,
304,
272,
340,
1031,
315,
3380,
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,
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
] |
olethanh/django-gcaltemplatetag
|
gcaltemplatetag/templatetags/gcal.py
|
1
|
4419
|
"""
Tags which can retrieve events from a public google calendar Atom feed,
and return the results for use in templates.
Copyright (c) 2011, Olivier Le Thanh Duong <olivier@lethanh.be>
Based on django-template-utils :
Copyright (c) 2009, James Bennett & Justin Quick
Based, in part, on the original idea by user baumer1122 and posted to
djangosnippets at http://www.djangosnippets.org/snippets/311/
"""
from django import template
from django.template.loader import render_to_string
import gdata.calendar.service
from datetime import datetime
calendar_service = gdata.calendar.service.CalendarService()
def get_feed(calendar_service, account, calendar='public'):
start_date = datetime.now().strftime("%Y-%m-%d")
query = gdata.calendar.service.CalendarEventQuery(account, calendar, 'full')
query.start_min = start_date
feed = calendar_service.CalendarQuery(query)
return feed
def parse_date(date):
try:
if len(date) == len("YYYY-MM-DD"):
d = datetime.strptime(date, "%Y-%m-%d")
else :
d = datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.000+01:00")
return d
except Exception, e:
return date
class EventItem(object):
def __init__(self, event):
"""
event : a gdata.calendar.CalendarEventEntry
"""
self._event = event
self._start_date = parse_date(event.when[0].start_time)
self._title = event.title.text
self._location = event.where[0].value_string
self._link = event.GetHtmlLink().href
def __str__(self):
return "<EventItem: %s on %s at %s>" % (self._title, self._start_date, self._location)
def title(self):
return self._title
def location(self):
return self._location
def start_date(self):
return self._start_date
def link(self):
return self._link
class GcalIncludeNode(template.Node):
def __init__(self, account, template_name, num_items=None):
self.account = account
self.num_items = int(num_items)
self.template_name = template_name
def render(self, context):
feed = get_feed(calendar_service, self.account)
event_items = [EventItem(event) for event in feed.entry[:self.num_items]]
return render_to_string(self.template_name, { 'items': event_items,
'feed': feed })
def do_include_gcal(parser, token):
"""
Parse an RSS or Atom feed and render a given number of its items
into HTML.
It is **highly** recommended that you use `Django's template
fragment caching`_ to cache the output of this tag for a
reasonable amount of time (e.g., one hour); polling a feed too
often is impolite, wastes bandwidth and may lead to the feed
provider banning your IP address.
.. _Django's template fragment caching: http://www.djangoproject.com/documentation/cache/#template-fragment-caching
Arguments should be:
1. The account of the gcal to parse.
2. The name of a template to use for rendering the results into HTML.
3. The number of items to render (if not supplied, renders all
items in the calendar).
The template used to render the results will receive two variables:
``items``
A list of object representing event items, each with
'title', 'location', 'link' and 'start_date' members.
``feed``
The feed itself, for pulling out arbitrary attributes.
Requires python-gdata, which can be obtained at http://google.com.
See `its documentation`_ for details of the parsed feed object.
.. _its documentation: http://code.google.com/apis/calendar/data/1.0/developers_guide_python.html
Syntax::
{% include_gcal [account] [num_items] [template_name] %}
Example::
{% include_gcal bla@group.calendar.google.com 10 events/eventitems.html %}
"""
bits = token.contents.split()
if len(bits) == 3:
return GcalIncludeNode(account=bits[1], template_name=bits[2])
elif len(bits) == 4:
return GcalIncludeNode(account=bits[1], template_name=bits[2], num_items=bits[3])
else:
raise template.TemplateSyntaxError("'%s' tag takes either two or three arguments" % bits[0])
register = template.Library()
register.tag('include_gcal', do_include_gcal)
|
bsd-3-clause
|
[
624,
199,
9440,
1314,
883,
8044,
4474,
687,
282,
4575,
6233,
11234,
18840,
4733,
12,
199,
460,
372,
314,
2058,
367,
675,
315,
7009,
14,
819,
1898,
334,
67,
9,
7760,
12,
593,
317,
26645,
7005,
3868,
290,
72,
577,
85,
951,
665,
23711,
26645,
32,
274,
13797,
72,
14,
1235,
30,
199,
199,
20409,
641,
1639,
13,
1160,
13,
1208,
520,
523,
1898,
334,
67,
9,
8937,
12,
1603,
14015,
26844,
846,
84,
1253,
13870,
262,
27534,
199,
199,
20409,
12,
315,
1777,
12,
641,
314,
3379,
16819,
701,
922,
19325,
940,
82,
6094,
18,
436,
22752,
370,
199,
12816,
736,
78,
15147,
737,
1455,
921,
1544,
14,
12816,
736,
78,
15147,
14,
1308,
15,
32566,
15,
17539,
15,
199,
199,
624,
199,
199,
504,
1639,
492,
1978,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
199,
646,
11006,
14,
8183,
14,
1364,
199,
504,
2197,
492,
2197,
4388,
199,
8183,
63,
1364,
275,
11006,
14,
8183,
14,
1364,
14,
18688,
3167,
342,
199,
199,
318,
664,
63,
3871,
8,
8183,
63,
1364,
12,
2933,
12,
11234,
534,
3455,
735,
272,
1343,
63,
602,
275,
2197,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
68,
531,
272,
1827,
275,
11006,
14,
8183,
14,
1364,
14,
18688,
2390,
3227,
8,
2048,
12,
11234,
12,
283,
2861,
358,
272,
1827,
14,
928,
63,
827,
275,
1343,
63,
602,
272,
4733,
275,
11234,
63,
1364,
14,
18688,
3227,
8,
1131,
9,
272,
372,
4733,
199,
199,
318,
2198,
63,
602,
8,
602,
304,
272,
862,
26,
267,
340,
822,
8,
602,
9,
508,
822,
480,
15703,
13,
3218,
13,
5745,
2349,
288,
366,
275,
2197,
14,
9866,
8,
602,
12,
2071,
57,
3295,
77,
3295,
68,
531,
267,
587,
520,
288,
366,
275,
2197,
14,
9866,
8,
602,
12,
2071,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
14,
1493,
11,
614,
26,
383,
531,
267,
372,
366,
272,
871,
2186,
12,
325,
26,
267,
372,
1434,
199,
199,
533,
6763,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1566,
304,
267,
408,
267,
1566,
520,
282,
11006,
14,
8183,
14,
18688,
2390,
3900,
267,
408,
267,
291,
423,
1430,
275,
1566,
267,
291,
423,
928,
63,
602,
275,
2198,
63,
602,
8,
1430,
14,
6526,
59,
16,
1055,
928,
63,
521,
9,
267,
291,
423,
1213,
275,
1566,
14,
1213,
14,
505,
267,
291,
423,
1985,
275,
1566,
14,
4509,
59,
16,
1055,
585,
63,
875,
267,
291,
423,
1073,
275,
1566,
14,
1002,
12957,
3834,
1252,
6399,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
2390,
2081,
26,
450,
83,
221,
641,
450,
83,
221,
737,
450,
83,
4335,
450,
334,
277,
423,
1213,
12,
291,
423,
928,
63,
602,
12,
291,
423,
1985,
9,
339,
347,
2538,
8,
277,
304,
267,
372,
291,
423,
1213,
339,
347,
2909,
8,
277,
304,
267,
372,
291,
423,
1985,
339,
347,
1343,
63,
602,
8,
277,
304,
267,
372,
291,
423,
928,
63,
602,
272,
347,
2142,
8,
277,
304,
267,
372,
291,
423,
1073,
199,
199,
533,
598,
915,
7826,
1716,
8,
1160,
14,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
2933,
12,
1978,
63,
354,
12,
1967,
63,
1744,
29,
403,
304,
267,
291,
14,
2048,
275,
2933,
267,
291,
14,
1507,
63,
1744,
275,
1109,
8,
1507,
63,
1744,
9,
267,
291,
14,
1160,
63,
354,
275,
1978,
63,
354,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
4733,
275,
664,
63,
3871,
8,
8183,
63,
1364,
12,
291,
14,
2048,
9,
267,
1566,
63,
1744,
275,
359,
2390,
2081,
8,
1430,
9,
367,
1566,
315,
4733,
14,
2373,
1491,
277,
14,
1507,
63,
1744,
2677,
267,
372,
3795,
63,
475,
63,
875,
8,
277,
14,
1160,
63,
354,
12,
469,
283,
1744,
356,
1566,
63,
1744,
12,
10028,
283,
3871,
356,
4733,
3828,
4388,
199,
318,
886,
63,
2613,
63,
71,
915,
8,
2087,
12,
1526,
304,
272,
408,
272,
6077,
376,
30331,
503,
18840,
4733,
436,
3795,
282,
1627,
1329,
402,
2399,
2974,
272,
1901,
4163,
14,
2286,
2779,
365,
1011,
6260,
590,
538,
14318,
626,
1265,
675,
658,
9323,
1159,
1978,
272,
7956,
13627,
18417,
370,
2581,
314,
1072,
402,
642,
1947,
367,
282,
272,
23255,
5982,
402,
900,
334,
69,
14,
71,
2020,
1373,
6925,
2736,
12353,
282,
4733,
4634,
272,
14115,
365,
1742,
79,
5333,
12,
1990,
744,
20434,
436,
1443,
12690,
370,
314,
4733,
272,
5022,
330,
11495,
2195,
3531,
2287,
14,
2286,
2508,
485,
9323,
1159,
1978,
7956,
13627,
26,
1455,
921,
1544,
14,
14013,
14,
957,
15,
9970,
15,
1637,
12645,
1160,
13,
7677,
13,
22738,
2286,
7628,
1077,
506,
26,
2286,
413,
14,
710,
2933,
402,
314,
486,
915,
370,
2198,
14,
2286,
499,
14,
710,
536,
402,
282,
1978,
370,
675,
367,
14066,
314,
2058,
1901,
4163,
14,
2286,
650,
14,
710,
1329,
402,
2974,
370,
3795,
334,
692,
440,
6841,
12,
3795,
83,
1006,
2126,
2974,
315,
314,
11234,
680,
267,
272,
710,
1978,
1202,
370,
3795,
314,
2058,
911,
9128,
2877,
2860,
26,
2286,
1124,
1744,
1040,
267,
437,
769,
402,
909,
6144,
1566,
2974,
12,
1924,
543,
267,
283,
1213,
297,
283,
1985,
297,
283,
1073,
7,
436,
283,
928,
63,
602,
7,
7556,
14,
2286,
1124,
3871,
1040,
267,
710,
4733,
6337,
12,
367,
10299,
316,
734,
9697,
3004,
14,
2286,
15127,
2366,
13,
15275,
12,
1314,
883,
506,
15884,
737,
1455,
921,
3098,
14,
957,
14,
272,
1666,
658,
1405,
3794,
18417,
367,
2436,
402,
314,
4565,
4733,
909,
14,
2286,
2508,
485,
1405,
3794,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
12662,
15,
8183,
15,
576,
15,
17,
14,
16,
15,
23826,
63,
17348,
63,
1548,
14,
1360,
2286,
18377,
447,
13857,
7749,
2387,
63,
71,
915,
359,
2048,
61,
359,
1507,
63,
1744,
61,
359,
1160,
63,
354,
61,
3674,
2286,
5679,
447,
13857,
7749,
2387,
63,
71,
915,
330,
416,
32,
923,
14,
8183,
14,
3098,
14,
957,
1616,
4474,
15,
12056,
280,
3733,
14,
1360,
3674,
2286,
408,
272,
5821,
275,
1526,
14,
4407
] |
[
199,
9440,
1314,
883,
8044,
4474,
687,
282,
4575,
6233,
11234,
18840,
4733,
12,
199,
460,
372,
314,
2058,
367,
675,
315,
7009,
14,
819,
1898,
334,
67,
9,
7760,
12,
593,
317,
26645,
7005,
3868,
290,
72,
577,
85,
951,
665,
23711,
26645,
32,
274,
13797,
72,
14,
1235,
30,
199,
199,
20409,
641,
1639,
13,
1160,
13,
1208,
520,
523,
1898,
334,
67,
9,
8937,
12,
1603,
14015,
26844,
846,
84,
1253,
13870,
262,
27534,
199,
199,
20409,
12,
315,
1777,
12,
641,
314,
3379,
16819,
701,
922,
19325,
940,
82,
6094,
18,
436,
22752,
370,
199,
12816,
736,
78,
15147,
737,
1455,
921,
1544,
14,
12816,
736,
78,
15147,
14,
1308,
15,
32566,
15,
17539,
15,
199,
199,
624,
199,
199,
504,
1639,
492,
1978,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
199,
646,
11006,
14,
8183,
14,
1364,
199,
504,
2197,
492,
2197,
4388,
199,
8183,
63,
1364,
275,
11006,
14,
8183,
14,
1364,
14,
18688,
3167,
342,
199,
199,
318,
664,
63,
3871,
8,
8183,
63,
1364,
12,
2933,
12,
11234,
534,
3455,
735,
272,
1343,
63,
602,
275,
2197,
14,
2131,
1252,
6205,
3647,
57,
3295,
77,
3295,
68,
531,
272,
1827,
275,
11006,
14,
8183,
14,
1364,
14,
18688,
2390,
3227,
8,
2048,
12,
11234,
12,
283,
2861,
358,
272,
1827,
14,
928,
63,
827,
275,
1343,
63,
602,
272,
4733,
275,
11234,
63,
1364,
14,
18688,
3227,
8,
1131,
9,
272,
372,
4733,
199,
199,
318,
2198,
63,
602,
8,
602,
304,
272,
862,
26,
267,
340,
822,
8,
602,
9,
508,
822,
480,
15703,
13,
3218,
13,
5745,
2349,
288,
366,
275,
2197,
14,
9866,
8,
602,
12,
2071,
57,
3295,
77,
3295,
68,
531,
267,
587,
520,
288,
366,
275,
2197,
14,
9866,
8,
602,
12,
2071,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
14,
1493,
11,
614,
26,
383,
531,
267,
372,
366,
272,
871,
2186,
12,
325,
26,
267,
372,
1434,
199,
199,
533,
6763,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1566,
304,
267,
408,
267,
1566,
520,
282,
11006,
14,
8183,
14,
18688,
2390,
3900,
267,
408,
267,
291,
423,
1430,
275,
1566,
267,
291,
423,
928,
63,
602,
275,
2198,
63,
602,
8,
1430,
14,
6526,
59,
16,
1055,
928,
63,
521,
9,
267,
291,
423,
1213,
275,
1566,
14,
1213,
14,
505,
267,
291,
423,
1985,
275,
1566,
14,
4509,
59,
16,
1055,
585,
63,
875,
267,
291,
423,
1073,
275,
1566,
14,
1002,
12957,
3834,
1252,
6399,
339,
347,
636,
495,
721,
277,
304,
267,
372,
3886,
2390,
2081,
26,
450,
83,
221,
641,
450,
83,
221,
737,
450,
83,
4335,
450,
334,
277,
423,
1213,
12,
291,
423,
928,
63,
602,
12,
291,
423,
1985,
9,
339,
347,
2538,
8,
277,
304,
267,
372,
291,
423,
1213,
339,
347,
2909,
8,
277,
304,
267,
372,
291,
423,
1985,
339,
347,
1343,
63,
602,
8,
277,
304,
267,
372,
291,
423,
928,
63,
602,
272,
347,
2142,
8,
277,
304,
267,
372,
291,
423,
1073,
199,
199,
533,
598,
915,
7826,
1716,
8,
1160,
14,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
2933,
12,
1978,
63,
354,
12,
1967,
63,
1744,
29,
403,
304,
267,
291,
14,
2048,
275,
2933,
267,
291,
14,
1507,
63,
1744,
275,
1109,
8,
1507,
63,
1744,
9,
267,
291,
14,
1160,
63,
354,
275,
1978,
63,
354,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
4733,
275,
664,
63,
3871,
8,
8183,
63,
1364,
12,
291,
14,
2048,
9,
267,
1566,
63,
1744,
275,
359,
2390,
2081,
8,
1430,
9,
367,
1566,
315,
4733,
14,
2373,
1491,
277,
14,
1507,
63,
1744,
2677,
267,
372,
3795,
63,
475,
63,
875,
8,
277,
14,
1160,
63,
354,
12,
469,
283,
1744,
356,
1566,
63,
1744,
12,
10028,
283,
3871,
356,
4733,
3828,
4388,
199,
318,
886,
63,
2613,
63,
71,
915,
8,
2087,
12,
1526,
304,
272,
408,
272,
6077,
376,
30331,
503,
18840,
4733,
436,
3795,
282,
1627,
1329,
402,
2399,
2974,
272,
1901,
4163,
14,
2286,
2779,
365,
1011,
6260,
590,
538,
14318,
626,
1265,
675,
658,
9323,
1159,
1978,
272,
7956,
13627,
18417,
370,
2581,
314,
1072,
402,
642,
1947,
367,
282,
272,
23255,
5982,
402,
900,
334,
69,
14,
71,
2020,
1373,
6925,
2736,
12353,
282,
4733,
4634,
272,
14115,
365,
1742,
79,
5333,
12,
1990,
744,
20434,
436,
1443,
12690,
370,
314,
4733,
272,
5022,
330,
11495,
2195,
3531,
2287,
14,
2286,
2508,
485,
9323,
1159,
1978,
7956,
13627,
26,
1455,
921,
1544,
14,
14013,
14,
957,
15,
9970,
15,
1637,
12645,
1160,
13,
7677,
13,
22738,
2286,
7628,
1077,
506,
26,
2286,
413,
14,
710,
2933,
402,
314,
486,
915,
370,
2198,
14,
2286,
499,
14,
710,
536,
402,
282,
1978,
370,
675,
367,
14066,
314,
2058,
1901,
4163,
14,
2286,
650,
14,
710,
1329,
402,
2974,
370,
3795,
334,
692,
440,
6841,
12,
3795,
83,
1006,
2126,
2974,
315,
314,
11234,
680,
267,
272,
710,
1978,
1202,
370,
3795,
314,
2058,
911,
9128,
2877,
2860,
26,
2286,
1124,
1744,
1040,
267,
437,
769,
402,
909,
6144,
1566,
2974,
12,
1924,
543,
267,
283,
1213,
297,
283,
1985,
297,
283,
1073,
7,
436,
283,
928,
63,
602,
7,
7556,
14,
2286,
1124,
3871,
1040,
267,
710,
4733,
6337,
12,
367,
10299,
316,
734,
9697,
3004,
14,
2286,
15127,
2366,
13,
15275,
12,
1314,
883,
506,
15884,
737,
1455,
921,
3098,
14,
957,
14,
272,
1666,
658,
1405,
3794,
18417,
367,
2436,
402,
314,
4565,
4733,
909,
14,
2286,
2508,
485,
1405,
3794,
26,
1455,
921,
600,
14,
3098,
14,
957,
15,
12662,
15,
8183,
15,
576,
15,
17,
14,
16,
15,
23826,
63,
17348,
63,
1548,
14,
1360,
2286,
18377,
447,
13857,
7749,
2387,
63,
71,
915,
359,
2048,
61,
359,
1507,
63,
1744,
61,
359,
1160,
63,
354,
61,
3674,
2286,
5679,
447,
13857,
7749,
2387,
63,
71,
915,
330,
416,
32,
923,
14,
8183,
14,
3098,
14,
957,
1616,
4474,
15,
12056,
280,
3733,
14,
1360,
3674,
2286,
408,
272,
5821,
275,
1526,
14,
4407,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
takis/odoo
|
addons/base_iban/__init__.py
|
447
|
1073
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base_iban
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
1300,
63,
1892,
290,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
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,
420,
199,
3,
199,
4605,
199,
199,
646,
1300,
63,
1892,
290,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mhaberler/machinekit
|
lib/python/gladevcp/hal_meter.py
|
39
|
9330
|
# vim: sts=4 sw=4 et
# GladeVcp Widgets
#
# Copyright (c) 2010 Pavel Shramov <shramov@mexmat.net>
#
# 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.
import gtk
import gobject
import cairo
import math
import gtk.glade
from hal_widgets import _HalWidgetBase, hal, hal_pin_changed_signal
MAX_INT = 0x7fffffff
def gdk_color_tuple(c):
if not c:
return 0, 0, 0
return c.red_float, c.green_float, c.blue_float
class HAL_Meter(gtk.DrawingArea, _HalWidgetBase):
__gtype_name__ = 'HAL_Meter'
__gsignals__ = dict([hal_pin_changed_signal])
__gproperties__ = {
'invert' : ( gobject.TYPE_BOOLEAN, 'Inverted', 'Invert min-max direction',
False, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'min' : ( gobject.TYPE_FLOAT, 'Min', 'Minimum value',
-MAX_INT, MAX_INT, 0, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'max' : ( gobject.TYPE_FLOAT, 'Max', 'Maximum value',
-MAX_INT, MAX_INT, 100, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'value' : ( gobject.TYPE_FLOAT, 'Value', 'Current meter value (for glade testing)',
-MAX_INT, MAX_INT, 0, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'majorscale' : ( gobject.TYPE_FLOAT, 'Major scale', 'Major ticks',
-MAX_INT, MAX_INT, 10, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'minorscale' : ( gobject.TYPE_FLOAT, 'Minor scale', 'Minor ticks',
-MAX_INT, MAX_INT, 2, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'z0_color' : ( gtk.gdk.Color.__gtype__, 'Zone 0 color', "Set color for first zone",
gobject.PARAM_READWRITE),
'z1_color' : ( gtk.gdk.Color.__gtype__, 'Zone 1 color', "Set color for second zone",
gobject.PARAM_READWRITE),
'z2_color' : ( gtk.gdk.Color.__gtype__, 'Zone 2 color', "Set color for third zone",
gobject.PARAM_READWRITE),
'z0_border' : ( gobject.TYPE_FLOAT, 'Zone 0 up limit', 'Up limit of zone 0',
-MAX_INT, MAX_INT, MAX_INT, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'z1_border' : ( gobject.TYPE_FLOAT, 'Zone 1 up limit', 'Up limit of zone 1',
-MAX_INT, MAX_INT, MAX_INT, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'bg_color' : ( gtk.gdk.Color.__gtype__, 'Background', "Choose background color",
gobject.PARAM_READWRITE),
'force_size' : ( gobject.TYPE_INT, 'Forced size', 'Force meter size not dependent on widget size. -1 to disable',
-1, MAX_INT, -1, gobject.PARAM_READWRITE | gobject.PARAM_CONSTRUCT),
'text_template' : ( gobject.TYPE_STRING, 'Text template',
'Text template to display. Python formatting may be used for one variable',
"%s", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
'label' : ( gobject.TYPE_STRING, 'Meter label', 'Label to display',
"", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
'sublabel' : ( gobject.TYPE_STRING, 'Meter sub label', 'Sub text to display',
"", gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT),
}
__gproperties = __gproperties__
def __init__(self):
super(HAL_Meter, self).__init__()
self.bg_color = gtk.gdk.Color('white')
self.z0_color = gtk.gdk.Color('green')
self.z1_color = gtk.gdk.Color('yellow')
self.z2_color = gtk.gdk.Color('red')
self.force_radius = None
self.connect("expose-event", self.expose)
def _hal_init(self):
_HalWidgetBase._hal_init(self)
self.hal_pin = self.hal.newpin(self.hal_name, hal.HAL_FLOAT, hal.HAL_IN)
self.hal_pin.connect('value-changed', lambda p: self.set_value(p.value))
self.hal_pin.connect('value-changed', lambda s: self.emit('hal-pin-changed', s))
def expose(self, widget, event):
if self.flags() & gtk.PARENT_SENSITIVE:
alpha = 1
else:
alpha = 0.3
w = self.allocation.width
h = self.allocation.height
r = min(w, h) / 2
fr = self.force_size
if fr > 0: r = min(fr, r)
if r < 20:
r = 40
self.set_size_request(2 * r, 2 * r)
cr = widget.window.cairo_create()
def set_color(c):
return cr.set_source_rgba(c.red_float, c.green_float, c.blue_float, alpha)
cr.set_line_width(2)
set_color(gtk.gdk.Color('black'))
#print w, h, aw, ah, fw, fh
cr.translate(w / 2, h / 2)
cr.arc(0, 0, r, 0, 2*math.pi)
cr.clip_preserve()
cr.stroke()
r -= 1
cr.set_line_width(1)
set_color(self.bg_color)
cr.arc(0, 0, r, 0, 2*math.pi)
cr.stroke_preserve()
cr.fill()
a_delta = math.pi / 6
a_start = 0.5 * math.pi + a_delta
a_size = 2 * math.pi - 2 * a_delta
def angle(v):
size = self.max - self.min
v = max(self.min, v)
v = min(self.max, v)
return a_start + a_size * (v - self.min) / size
set_color(self.z2_color)
self.draw_zone(cr, r, angle(self.z1_border), angle(self.max))
set_color(self.z1_color)
self.draw_zone(cr, r, angle(self.z0_border), angle(self.z1_border))
set_color(self.z0_color)
self.draw_zone(cr, r, angle(self.min), angle(self.z0_border))
set_color(gtk.gdk.Color('black'))
cr.set_font_size(r/10)
v = self.min
while v <= self.max:
if int(v) - v == 0: v = int(v)
self.draw_tick(cr, r, 0.15 * r, angle(v), text=str(v))
v += self.majorscale
v = self.min
while v <= self.max:
self.draw_tick(cr, r, 0.05 * r, angle(v))
v += self.minorscale
self.text_at(cr, self.sublabel, 0, r/5)
cr.set_font_size(r/5)
self.text_at(cr, self.label, 0, -r/5)
set_color(gtk.gdk.Color('red'))
self.draw_arrow(cr, r, angle(self.value))
set_color(gtk.gdk.Color('black'))
self.text_at(cr, self.text_template % self.value, 0, 0.8 * r)
return True
def draw_zone(self, cr, r, start, stop):
cr.arc(0, 0, r, start, stop)
cr.line_to(0.9 * r * math.cos(stop), 0.9 * r * math.sin(stop))
cr.arc_negative(0, 0, 0.9 * r, stop, start)
cr.line_to(r * math.cos(start), r * math.sin(start))
cr.stroke_preserve()
cr.fill()
def draw_tick(self, cr, r, sz, a, text=None):
cr.move_to((r - sz) * math.cos(a), (r - sz) * math.sin(a))
cr.line_to(r * math.cos(a), r * math.sin(a))
cr.stroke()
if not text:
return
self.text_at(cr, text, 0.75 * r * math.cos(a), 0.75 * r * math.sin(a))
def text_at(self, cr, text, x, y, xalign='center', yalign='center'):
xbearing, ybearing, width, height, xadvance, yadvance = cr.text_extents(text)
#print xbearing, ybearing, width, height, xadvance, yadvance
if xalign == 'center':
x = x - width/2
elif xalign == 'right':
x = x - width
if yalign == 'center':
y = y + height/2
elif yalign == 'top':
y = y + height
cr.move_to(x, y)
cr.show_text(text)
def draw_arrow(self, cr, r, a):
cr.rotate(a)
cr.move_to(0, 0)
cr.line_to(-r/10, r/20)
cr.line_to(0.8 * r, 0)
cr.line_to(-r/10, -r/20)
cr.line_to(0, 0)
cr.stroke_preserve()
cr.fill()
cr.rotate(-a)
def set_value(self, v):
self.value = v
self.queue_draw()
def do_get_property(self, property):
name = property.name.replace('-', '_')
if name in self.__gproperties.keys():
return getattr(self, name)
else:
raise AttributeError('unknown property %s' % property.name)
def do_set_property(self, property, value):
name = property.name.replace('-', '_')
if name == 'text_template':
try:
v = value % 0.0
except Exception, e:
print "Invalid format string '%s': %s" % (value, e)
return False
if name in ['bg_color', 'z0_color', 'z1_color', 'z2_color']:
if not value:
return False
if name in self.__gproperties.keys():
setattr(self, name, value)
self.queue_draw()
else:
raise AttributeError('unknown property %s' % property.name)
if name in ['force_size', 'force_size']:
#print "Forcing size request %s" % name
self.set_size_request(self.force_size, self.force_size)
self.queue_draw()
return True
|
lgpl-2.1
|
[
3,
6695,
26,
23014,
29,
20,
5584,
29,
20,
10844,
199,
3,
598,
17236,
54,
1850,
16905,
83,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
221,
10164,
1090,
5244,
345,
14469,
665,
609,
345,
14469,
32,
278,
88,
569,
14,
846,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
646,
8116,
199,
646,
25595,
199,
646,
1704,
14352,
199,
646,
3473,
199,
646,
8116,
14,
31589,
199,
199,
504,
22939,
63,
8583,
492,
485,
40,
279,
3339,
1563,
12,
22939,
12,
22939,
63,
7751,
63,
2489,
63,
4653,
199,
199,
4283,
63,
2919,
275,
378,
88,
23,
12596,
70,
199,
199,
318,
486,
6341,
63,
2326,
63,
2960,
8,
67,
304,
272,
340,
440,
286,
26,
267,
372,
378,
12,
378,
12,
378,
272,
372,
286,
14,
581,
63,
1609,
12,
286,
14,
7731,
63,
1609,
12,
286,
14,
6304,
63,
1609,
199,
199,
533,
869,
748,
63,
27937,
8,
12275,
14,
9654,
316,
11043,
12,
485,
40,
279,
3339,
1563,
304,
272,
636,
71,
466,
63,
354,
363,
275,
283,
40,
748,
63,
27937,
7,
272,
636,
71,
10458,
363,
275,
1211,
779,
19785,
63,
7751,
63,
2489,
63,
4653,
566,
272,
636,
71,
3282,
363,
275,
469,
267,
283,
18957,
7,
520,
334,
25595,
14,
2711,
63,
25312,
12,
283,
607,
16542,
297,
283,
26498,
1748,
13,
988,
7581,
297,
490,
756,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
827,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
4649,
297,
283,
12092,
574,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
378,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
988,
7,
221,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
4261,
297,
283,
10915,
574,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
2948,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
585,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
1110,
297,
283,
5639,
21247,
574,
334,
509,
486,
17236,
5343,
3196,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
378,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
8452,
3467,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
21657,
4666,
297,
283,
21657,
17779,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
1616,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
11067,
3467,
7,
221,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
23094,
4666,
297,
283,
23094,
17779,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
499,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
90,
16,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
378,
3164,
297,
298,
1084,
3164,
367,
1642,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
17,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
413,
3164,
297,
298,
1084,
3164,
367,
3499,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
18,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
499,
3164,
297,
298,
1084,
3164,
367,
10919,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
16,
63,
8665,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
11860,
378,
1536,
2304,
297,
283,
1721,
2304,
402,
5718,
378,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
9141,
63,
2919,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
90,
17,
63,
8665,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
11860,
413,
1536,
2304,
297,
283,
1721,
2304,
402,
5718,
413,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
9141,
63,
2919,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
6856,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
14148,
297,
298,
23932,
8020,
3164,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
3990,
63,
890,
7,
520,
334,
25595,
14,
2711,
63,
2919,
12,
283,
30548,
1568,
297,
283,
13606,
21247,
1568,
440,
11410,
641,
3938,
1568,
14,
446,
17,
370,
3507,
297,
490,
446,
17,
12,
9141,
63,
2919,
12,
446,
17,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
505,
63,
1160,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
1872,
1978,
297,
355,
283,
1872,
1978,
370,
2929,
14,
2018,
10803,
1443,
506,
1202,
367,
1373,
1750,
297,
355,
2071,
83,
401,
25595,
14,
7258,
63,
5670,
10387,
92,
71,
785,
14,
7258,
63,
1864,
8893,
395,
267,
283,
1302,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
27937,
1768,
297,
283,
4314,
370,
2929,
297,
355,
4873,
25595,
14,
7258,
63,
5670,
10387,
92,
71,
785,
14,
7258,
63,
1864,
8893,
395,
267,
283,
954,
1302,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
27937,
1007,
1768,
297,
283,
2610,
1318,
370,
2929,
297,
355,
4873,
25595,
14,
7258,
63,
5670
] |
[
6695,
26,
23014,
29,
20,
5584,
29,
20,
10844,
199,
3,
598,
17236,
54,
1850,
16905,
83,
199,
3,
199,
3,
1898,
334,
67,
9,
7129,
221,
10164,
1090,
5244,
345,
14469,
665,
609,
345,
14469,
32,
278,
88,
569,
14,
846,
30,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
646,
8116,
199,
646,
25595,
199,
646,
1704,
14352,
199,
646,
3473,
199,
646,
8116,
14,
31589,
199,
199,
504,
22939,
63,
8583,
492,
485,
40,
279,
3339,
1563,
12,
22939,
12,
22939,
63,
7751,
63,
2489,
63,
4653,
199,
199,
4283,
63,
2919,
275,
378,
88,
23,
12596,
70,
199,
199,
318,
486,
6341,
63,
2326,
63,
2960,
8,
67,
304,
272,
340,
440,
286,
26,
267,
372,
378,
12,
378,
12,
378,
272,
372,
286,
14,
581,
63,
1609,
12,
286,
14,
7731,
63,
1609,
12,
286,
14,
6304,
63,
1609,
199,
199,
533,
869,
748,
63,
27937,
8,
12275,
14,
9654,
316,
11043,
12,
485,
40,
279,
3339,
1563,
304,
272,
636,
71,
466,
63,
354,
363,
275,
283,
40,
748,
63,
27937,
7,
272,
636,
71,
10458,
363,
275,
1211,
779,
19785,
63,
7751,
63,
2489,
63,
4653,
566,
272,
636,
71,
3282,
363,
275,
469,
267,
283,
18957,
7,
520,
334,
25595,
14,
2711,
63,
25312,
12,
283,
607,
16542,
297,
283,
26498,
1748,
13,
988,
7581,
297,
490,
756,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
827,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
4649,
297,
283,
12092,
574,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
378,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
988,
7,
221,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
4261,
297,
283,
10915,
574,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
2948,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
585,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
1110,
297,
283,
5639,
21247,
574,
334,
509,
486,
17236,
5343,
3196,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
378,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
8452,
3467,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
21657,
4666,
297,
283,
21657,
17779,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
1616,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
11067,
3467,
7,
221,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
23094,
4666,
297,
283,
23094,
17779,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
499,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
90,
16,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
378,
3164,
297,
298,
1084,
3164,
367,
1642,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
17,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
413,
3164,
297,
298,
1084,
3164,
367,
3499,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
18,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
11860,
499,
3164,
297,
298,
1084,
3164,
367,
10919,
5718,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
90,
16,
63,
8665,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
11860,
378,
1536,
2304,
297,
283,
1721,
2304,
402,
5718,
378,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
9141,
63,
2919,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
90,
17,
63,
8665,
7,
520,
334,
25595,
14,
2711,
63,
11783,
12,
283,
11860,
413,
1536,
2304,
297,
283,
1721,
2304,
402,
5718,
413,
297,
490,
446,
4283,
63,
2919,
12,
9141,
63,
2919,
12,
9141,
63,
2919,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
6856,
63,
2326,
7,
520,
334,
8116,
14,
24697,
14,
4117,
855,
71,
466,
3108,
283,
14148,
297,
298,
23932,
8020,
3164,
401,
717,
25595,
14,
7258,
63,
5670,
10387,
395,
267,
283,
3990,
63,
890,
7,
520,
334,
25595,
14,
2711,
63,
2919,
12,
283,
30548,
1568,
297,
283,
13606,
21247,
1568,
440,
11410,
641,
3938,
1568,
14,
446,
17,
370,
3507,
297,
490,
446,
17,
12,
9141,
63,
2919,
12,
446,
17,
12,
25595,
14,
7258,
63,
5670,
10387,
1204,
25595,
14,
7258,
63,
1864,
8893,
395,
267,
283,
505,
63,
1160,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
1872,
1978,
297,
355,
283,
1872,
1978,
370,
2929,
14,
2018,
10803,
1443,
506,
1202,
367,
1373,
1750,
297,
355,
2071,
83,
401,
25595,
14,
7258,
63,
5670,
10387,
92,
71,
785,
14,
7258,
63,
1864,
8893,
395,
267,
283,
1302,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
27937,
1768,
297,
283,
4314,
370,
2929,
297,
355,
4873,
25595,
14,
7258,
63,
5670,
10387,
92,
71,
785,
14,
7258,
63,
1864,
8893,
395,
267,
283,
954,
1302,
7,
520,
334,
25595,
14,
2711,
63,
5353,
12,
283,
27937,
1007,
1768,
297,
283,
2610,
1318,
370,
2929,
297,
355,
4873,
25595,
14,
7258,
63,
5670,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jaharkema/loljournal
|
apps/match/views.py
|
1
|
2968
|
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse_lazy
from django.views.generic import FormView
from django.views.generic.edit import UpdateView
from django.views.generic.list import ListView
from apps.api.models import RiotGame, RiotChampion
from apps.core.forms import ApiDisclaimerForm
from .models import Match
class RetrieveRecentView(LoginRequiredMixin, FormView):
template_name = 'match/retrieve.html'
form_class = ApiDisclaimerForm
success_url = reverse_lazy('match.list')
def form_valid(self, form):
summoner = self.request.user
recent_matches = RiotGame.recent_for_summoner(
summoner.riot_id,
summoner.region
)
champions = {}
for match in recent_matches:
if match.champion_id not in champions:
riot_champ = RiotChampion.by_id(
match.champion_id,
summoner.region
)
champions.update({
riot_champ.id: riot_champ,
})
riot_champion = champions[match.champion_id]
Match.objects.get_or_create(
riot_id=match.id,
summoner=summoner,
defaults={
'win': match.win,
'champion_id': riot_champion.id,
'champion_name': riot_champion.name,
'created': match.created,
'kills': match.kills,
'deaths': match.deaths,
'assists': match.assists,
'minions': match.minions_killed,
'game_type': match.game_type,
}
)
return super(RetrieveRecentView, self).form_valid(form)
class MatchListView(LoginRequiredMixin, ListView):
model = Match
template_name = 'match/list.html'
context_object_name = 'matches'
paginate_by = 10
def get_queryset(self, *args, **kwargs):
queryset = self.model.objects.filter(summoner=self.request.user)
game_type = self.request.GET.get('game_type', None)
if game_type:
queryset = queryset.filter(game_type=game_type)
return queryset
def get_context_data(self, *args, **kwargs):
context_data = super(MatchListView, self).get_context_data(
*args, **kwargs
)
game_type = self.request.GET.get('game_type', None)
matches = Match.objects.all().order_by('game_type')
game_types = matches.values_list('game_type', flat=True).distinct()
context_data.update({
'game_types': game_types,
'selected_game_type': game_type,
})
return context_data
class MatchUpdateView(LoginRequiredMixin, UpdateView):
model = Match
template_name = 'match/update.html'
fields = ['notes']
success_url = reverse_lazy('match.list')
|
mit
|
[
504,
1639,
14,
2828,
14,
1178,
14,
30192,
492,
16430,
8030,
4256,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
504,
1639,
14,
4196,
14,
6767,
492,
8204,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
6162,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
513,
492,
3820,
2768,
199,
199,
504,
8686,
14,
1246,
14,
992,
492,
820,
73,
357,
11454,
12,
820,
73,
357,
1049,
5282,
1636,
199,
504,
8686,
14,
1018,
14,
3351,
492,
13986,
2825,
3995,
6267,
2821,
199,
199,
504,
1275,
992,
492,
9814,
421,
199,
533,
13939,
29574,
2768,
8,
8880,
8030,
4256,
12,
8204,
2768,
304,
272,
1978,
63,
354,
275,
283,
1431,
15,
14270,
14,
1360,
7,
272,
1824,
63,
533,
275,
13986,
2825,
3995,
6267,
2821,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
1431,
14,
513,
358,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
3089,
2106,
281,
275,
291,
14,
1069,
14,
751,
267,
8058,
63,
6742,
275,
820,
73,
357,
11454,
14,
14951,
63,
509,
63,
1838,
2106,
281,
8,
288,
3089,
2106,
281,
14,
322,
357,
63,
344,
12,
288,
3089,
2106,
281,
14,
4551,
267,
776,
398,
682,
5282,
15293,
275,
1052,
398,
367,
1336,
315,
8058,
63,
6742,
26,
288,
340,
1336,
14,
335,
5282,
1636,
63,
344,
440,
315,
682,
5282,
15293,
26,
2234,
8012,
357,
63,
335,
5282,
275,
820,
73,
357,
1049,
5282,
1636,
14,
991,
63,
344,
8,
490,
1336,
14,
335,
5282,
1636,
63,
344,
12,
490,
3089,
2106,
281,
14,
4551,
355,
776,
2234,
682,
5282,
15293,
14,
873,
2561,
490,
8012,
357,
63,
335,
5282,
14,
344,
26,
8012,
357,
63,
335,
5282,
12,
355,
3828,
953,
8012,
357,
63,
335,
5282,
1636,
275,
682,
5282,
15293,
59,
1431,
14,
335,
5282,
1636,
63,
344,
61,
953,
9814,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
355,
8012,
357,
63,
344,
29,
1431,
14,
344,
12,
355,
3089,
2106,
281,
29,
1838,
2106,
281,
12,
355,
4243,
3126,
490,
283,
2676,
356,
1336,
14,
2676,
12,
490,
283,
335,
5282,
1636,
63,
344,
356,
8012,
357,
63,
335,
5282,
1636,
14,
344,
12,
490,
283,
335,
5282,
1636,
63,
354,
356,
8012,
357,
63,
335,
5282,
1636,
14,
354,
12,
490,
283,
3966,
356,
1336,
14,
3966,
12,
490,
283,
75,
15350,
356,
1336,
14,
75,
15350,
12,
490,
283,
23727,
83,
356,
1336,
14,
23727,
83,
12,
490,
283,
2608,
10329,
356,
1336,
14,
2608,
10329,
12,
490,
283,
827,
15293,
356,
1336,
14,
827,
15293,
63,
75,
14535,
12,
490,
283,
5097,
63,
466,
356,
1336,
14,
5097,
63,
466,
12,
355,
789,
288,
776,
398,
372,
1613,
8,
15310,
29574,
2768,
12,
291,
680,
964,
63,
1078,
8,
964,
9,
421,
199,
533,
9814,
23239,
8,
8880,
8030,
4256,
12,
3820,
2768,
304,
272,
1402,
275,
9814,
272,
1978,
63,
354,
275,
283,
1431,
15,
513,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
6742,
7,
272,
9881,
23043,
63,
991,
275,
1616,
339,
347,
664,
63,
7924,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
7594,
275,
291,
14,
1238,
14,
1462,
14,
1541,
8,
1838,
2106,
281,
29,
277,
14,
1069,
14,
751,
9,
398,
9219,
63,
466,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
5097,
63,
466,
297,
488,
9,
398,
340,
9219,
63,
466,
26,
288,
7594,
275,
7594,
14,
1541,
8,
5097,
63,
466,
29,
5097,
63,
466,
9,
398,
372,
7594,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1067,
63,
576,
275,
1613,
8,
4486,
23239,
12,
291,
680,
362,
63,
1100,
63,
576,
8,
288,
627,
589,
12,
1011,
958,
267,
776,
398,
9219,
63,
466,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
5097,
63,
466,
297,
488,
9,
267,
4450,
275,
9814,
14,
1462,
14,
452,
1252,
1648,
63,
991,
360,
5097,
63,
466,
358,
267,
9219,
63,
1313,
275,
4450,
14,
1459,
63,
513,
360,
5097,
63,
466,
297,
6829,
29,
549,
680,
12926,
342,
398,
1067,
63,
576,
14,
873,
2561,
288,
283,
5097,
63,
1313,
356,
9219,
63,
1313,
12,
288,
283,
5511,
63,
5097,
63,
466,
356,
9219,
63,
466,
12,
267,
3828,
398,
372,
1067,
63,
576,
421,
199,
533,
9814,
4152,
2768,
8,
8880,
8030,
4256,
12,
6162,
2768,
304,
272,
1402,
275,
9814,
272,
1978,
63,
354,
275,
283,
1431,
15,
873,
14,
1360,
7,
272,
1504,
275,
788,
5983,
418,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
1431,
14,
513,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
14,
1178,
14,
30192,
492,
16430,
8030,
4256,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
63,
6395,
199,
504,
1639,
14,
4196,
14,
6767,
492,
8204,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
3773,
492,
6162,
2768,
199,
504,
1639,
14,
4196,
14,
6767,
14,
513,
492,
3820,
2768,
199,
199,
504,
8686,
14,
1246,
14,
992,
492,
820,
73,
357,
11454,
12,
820,
73,
357,
1049,
5282,
1636,
199,
504,
8686,
14,
1018,
14,
3351,
492,
13986,
2825,
3995,
6267,
2821,
199,
199,
504,
1275,
992,
492,
9814,
421,
199,
533,
13939,
29574,
2768,
8,
8880,
8030,
4256,
12,
8204,
2768,
304,
272,
1978,
63,
354,
275,
283,
1431,
15,
14270,
14,
1360,
7,
272,
1824,
63,
533,
275,
13986,
2825,
3995,
6267,
2821,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
1431,
14,
513,
358,
339,
347,
1824,
63,
1078,
8,
277,
12,
1824,
304,
267,
3089,
2106,
281,
275,
291,
14,
1069,
14,
751,
267,
8058,
63,
6742,
275,
820,
73,
357,
11454,
14,
14951,
63,
509,
63,
1838,
2106,
281,
8,
288,
3089,
2106,
281,
14,
322,
357,
63,
344,
12,
288,
3089,
2106,
281,
14,
4551,
267,
776,
398,
682,
5282,
15293,
275,
1052,
398,
367,
1336,
315,
8058,
63,
6742,
26,
288,
340,
1336,
14,
335,
5282,
1636,
63,
344,
440,
315,
682,
5282,
15293,
26,
2234,
8012,
357,
63,
335,
5282,
275,
820,
73,
357,
1049,
5282,
1636,
14,
991,
63,
344,
8,
490,
1336,
14,
335,
5282,
1636,
63,
344,
12,
490,
3089,
2106,
281,
14,
4551,
355,
776,
2234,
682,
5282,
15293,
14,
873,
2561,
490,
8012,
357,
63,
335,
5282,
14,
344,
26,
8012,
357,
63,
335,
5282,
12,
355,
3828,
953,
8012,
357,
63,
335,
5282,
1636,
275,
682,
5282,
15293,
59,
1431,
14,
335,
5282,
1636,
63,
344,
61,
953,
9814,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
355,
8012,
357,
63,
344,
29,
1431,
14,
344,
12,
355,
3089,
2106,
281,
29,
1838,
2106,
281,
12,
355,
4243,
3126,
490,
283,
2676,
356,
1336,
14,
2676,
12,
490,
283,
335,
5282,
1636,
63,
344,
356,
8012,
357,
63,
335,
5282,
1636,
14,
344,
12,
490,
283,
335,
5282,
1636,
63,
354,
356,
8012,
357,
63,
335,
5282,
1636,
14,
354,
12,
490,
283,
3966,
356,
1336,
14,
3966,
12,
490,
283,
75,
15350,
356,
1336,
14,
75,
15350,
12,
490,
283,
23727,
83,
356,
1336,
14,
23727,
83,
12,
490,
283,
2608,
10329,
356,
1336,
14,
2608,
10329,
12,
490,
283,
827,
15293,
356,
1336,
14,
827,
15293,
63,
75,
14535,
12,
490,
283,
5097,
63,
466,
356,
1336,
14,
5097,
63,
466,
12,
355,
789,
288,
776,
398,
372,
1613,
8,
15310,
29574,
2768,
12,
291,
680,
964,
63,
1078,
8,
964,
9,
421,
199,
533,
9814,
23239,
8,
8880,
8030,
4256,
12,
3820,
2768,
304,
272,
1402,
275,
9814,
272,
1978,
63,
354,
275,
283,
1431,
15,
513,
14,
1360,
7,
272,
1067,
63,
785,
63,
354,
275,
283,
6742,
7,
272,
9881,
23043,
63,
991,
275,
1616,
339,
347,
664,
63,
7924,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
7594,
275,
291,
14,
1238,
14,
1462,
14,
1541,
8,
1838,
2106,
281,
29,
277,
14,
1069,
14,
751,
9,
398,
9219,
63,
466,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
5097,
63,
466,
297,
488,
9,
398,
340,
9219,
63,
466,
26,
288,
7594,
275,
7594,
14,
1541,
8,
5097,
63,
466,
29,
5097,
63,
466,
9,
398,
372,
7594,
339,
347,
664,
63,
1100,
63,
576,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1067,
63,
576,
275,
1613,
8,
4486,
23239,
12,
291,
680,
362,
63,
1100,
63,
576,
8,
288,
627,
589,
12,
1011,
958,
267,
776,
398,
9219,
63,
466,
275,
291,
14,
1069,
14,
2970,
14,
362,
360,
5097,
63,
466,
297,
488,
9,
267,
4450,
275,
9814,
14,
1462,
14,
452,
1252,
1648,
63,
991,
360,
5097,
63,
466,
358,
267,
9219,
63,
1313,
275,
4450,
14,
1459,
63,
513,
360,
5097,
63,
466,
297,
6829,
29,
549,
680,
12926,
342,
398,
1067,
63,
576,
14,
873,
2561,
288,
283,
5097,
63,
1313,
356,
9219,
63,
1313,
12,
288,
283,
5511,
63,
5097,
63,
466,
356,
9219,
63,
466,
12,
267,
3828,
398,
372,
1067,
63,
576,
421,
199,
533,
9814,
4152,
2768,
8,
8880,
8030,
4256,
12,
6162,
2768,
304,
272,
1402,
275,
9814,
272,
1978,
63,
354,
275,
283,
1431,
15,
873,
14,
1360,
7,
272,
1504,
275,
788,
5983,
418,
272,
3182,
63,
633,
275,
3837,
63,
6395,
360,
1431,
14,
513,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hunger/cleanroom
|
tests/test_exceptions.py
|
1
|
1862
|
#!/usr/bin/python
"""Test for the exceptions of cleanroom.
@author: Tobias Hunger <tobias.hunger@gmail.com>
"""
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import cleanroom.exceptions as ex
import cleanroom.location as location
def test_base_exceptions() -> None:
"""Test the base exception class."""
e = ex.CleanRoomError("message")
assert str(e) == "Error: message"
def test_base_exceptions_multi_args() -> None:
"""Test the base exception class."""
e = ex.CleanRoomError("message", "something")
assert str(e) == "Error: ('message', 'something')"
def test_base_exceptions_with_location() -> None:
"""Test the base exception class with file."""
loc = location.Location(file_name="/foo/bar")
e = ex.CleanRoomError("message", location=loc)
assert str(e) == "Error in /foo/bar: message"
def test_base_exceptions_with_file_and_line() -> None:
"""Test the base exception class with file and line."""
loc = location.Location(file_name="/foo/bar", line_number=42)
e = ex.CleanRoomError("message", location=loc)
assert str(e) == "Error in /foo/bar:42: message"
def test_preflight() -> None:
"""Test preflight exception."""
e = ex.PreflightError("Something went wrong")
assert str(e) == "Error: Something went wrong"
def test_generate() -> None:
"""Test prepare exception."""
e = ex.GenerateError("Something went wrong")
assert str(e) == "Error: Something went wrong"
def test_system_not_found() -> None:
"""Test system not found exception."""
e = ex.SystemNotFoundError("Something went wrong")
assert str(e) == "Error: Something went wrong"
def test_parse() -> None:
"""Test parse exception."""
e = ex.ParseError("Something went wrong")
assert str(e) == "Error: Something went wrong"
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
624,
774,
367,
314,
4967,
402,
3633,
11245,
14,
199,
199,
32,
2502,
26,
377,
2873,
2241,
28386,
836,
665,
475,
8160,
14,
72,
324,
836,
32,
6799,
14,
957,
30,
199,
624,
421,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
13324,
199,
199,
646,
3633,
11245,
14,
3924,
465,
444,
199,
646,
3633,
11245,
14,
1985,
465,
2909,
421,
199,
318,
511,
63,
1095,
63,
3924,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
1041,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
1245,
2,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
3029,
63,
589,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
1041,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
298,
10297,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
661,
1188,
297,
283,
10297,
19124,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
1045,
63,
1985,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
543,
570,
1041,
272,
4355,
275,
2909,
14,
6592,
8,
493,
63,
354,
9555,
1421,
15,
1700,
531,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
2909,
29,
2102,
9,
272,
702,
620,
8,
69,
9,
508,
298,
547,
315,
1182,
1421,
15,
1700,
26,
1245,
2,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
1045,
63,
493,
63,
460,
63,
604,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
543,
570,
436,
1004,
1041,
272,
4355,
275,
2909,
14,
6592,
8,
493,
63,
354,
9555,
1421,
15,
1700,
401,
1004,
63,
1955,
29,
2260,
9,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
2909,
29,
2102,
9,
272,
702,
620,
8,
69,
9,
508,
298,
547,
315,
1182,
1421,
15,
1700,
26,
2260,
26,
1245,
2,
421,
199,
318,
511,
63,
13829,
4040,
342,
1035,
488,
26,
272,
408,
774,
20491,
4040,
1919,
1041,
272,
325,
275,
444,
14,
18441,
4040,
547,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
4208,
342,
1035,
488,
26,
272,
408,
774,
9275,
1919,
1041,
272,
325,
275,
444,
14,
6864,
547,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
2253,
63,
1397,
63,
4214,
342,
1035,
488,
26,
272,
408,
774,
2656,
440,
1911,
1919,
1041,
272,
325,
275,
444,
14,
3989,
10870,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
1122,
342,
1035,
488,
26,
272,
408,
774,
2198,
1919,
1041,
272,
325,
275,
444,
14,
9123,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
624,
774,
367,
314,
4967,
402,
3633,
11245,
14,
199,
199,
32,
2502,
26,
377,
2873,
2241,
28386,
836,
665,
475,
8160,
14,
72,
324,
836,
32,
6799,
14,
957,
30,
199,
624,
421,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
21777,
13324,
199,
199,
646,
3633,
11245,
14,
3924,
465,
444,
199,
646,
3633,
11245,
14,
1985,
465,
2909,
421,
199,
318,
511,
63,
1095,
63,
3924,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
1041,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
1245,
2,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
3029,
63,
589,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
1041,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
298,
10297,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
661,
1188,
297,
283,
10297,
19124,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
1045,
63,
1985,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
543,
570,
1041,
272,
4355,
275,
2909,
14,
6592,
8,
493,
63,
354,
9555,
1421,
15,
1700,
531,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
2909,
29,
2102,
9,
272,
702,
620,
8,
69,
9,
508,
298,
547,
315,
1182,
1421,
15,
1700,
26,
1245,
2,
421,
199,
318,
511,
63,
1095,
63,
3924,
63,
1045,
63,
493,
63,
460,
63,
604,
342,
1035,
488,
26,
272,
408,
774,
314,
1300,
1919,
1021,
543,
570,
436,
1004,
1041,
272,
4355,
275,
2909,
14,
6592,
8,
493,
63,
354,
9555,
1421,
15,
1700,
401,
1004,
63,
1955,
29,
2260,
9,
272,
325,
275,
444,
14,
6580,
25779,
547,
480,
1188,
401,
2909,
29,
2102,
9,
272,
702,
620,
8,
69,
9,
508,
298,
547,
315,
1182,
1421,
15,
1700,
26,
2260,
26,
1245,
2,
421,
199,
318,
511,
63,
13829,
4040,
342,
1035,
488,
26,
272,
408,
774,
20491,
4040,
1919,
1041,
272,
325,
275,
444,
14,
18441,
4040,
547,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
4208,
342,
1035,
488,
26,
272,
408,
774,
9275,
1919,
1041,
272,
325,
275,
444,
14,
6864,
547,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
2253,
63,
1397,
63,
4214,
342,
1035,
488,
26,
272,
408,
774,
2656,
440,
1911,
1919,
1041,
272,
325,
275,
444,
14,
3989,
10870,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
421,
199,
318,
511,
63,
1122,
342,
1035,
488,
26,
272,
408,
774,
2198,
1919,
1041,
272,
325,
275,
444,
14,
9123,
480,
20641,
22396,
6835,
531,
272,
702,
620,
8,
69,
9,
508,
298,
547,
26,
27173,
22396,
6835,
2,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
bacontext/mopidy
|
mopidy/mpd/protocol/playback.py
|
11
|
13933
|
from __future__ import absolute_import, unicode_literals
from mopidy.core import PlaybackState
from mopidy.internal import deprecation
from mopidy.mpd import exceptions, protocol
@protocol.commands.add('consume', state=protocol.BOOL)
def consume(context, state):
"""
*musicpd.org, playback section:*
``consume {STATE}``
Sets consume state to ``STATE``, ``STATE`` should be 0 or
1. When consume is activated, each song played is removed from
playlist.
"""
context.core.tracklist.set_consume(state)
@protocol.commands.add('crossfade', seconds=protocol.UINT)
def crossfade(context, seconds):
"""
*musicpd.org, playback section:*
``crossfade {SECONDS}``
Sets crossfading between songs.
"""
raise exceptions.MpdNotImplemented # TODO
@protocol.commands.add('mixrampdb')
def mixrampdb(context, decibels):
"""
*musicpd.org, playback section:*
``mixrampdb {deciBels}``
Sets the threshold at which songs will be overlapped. Like crossfading but
doesn't fade the track volume, just overlaps. The songs need to have
MixRamp tags added by an external tool. 0dB is the normalized maximum
volume so use negative values, I prefer -17dB. In the absence of mixramp
tags crossfading will be used. See http://sourceforge.net/projects/mixramp
"""
raise exceptions.MpdNotImplemented # TODO
@protocol.commands.add('mixrampdelay', seconds=protocol.UINT)
def mixrampdelay(context, seconds):
"""
*musicpd.org, playback section:*
``mixrampdelay {SECONDS}``
Additional time subtracted from the overlap calculated by mixrampdb. A
value of "nan" disables MixRamp overlapping and falls back to
crossfading.
"""
raise exceptions.MpdNotImplemented # TODO
@protocol.commands.add('next')
def next_(context):
"""
*musicpd.org, playback section:*
``next``
Plays next song in the playlist.
*MPD's behaviour when affected by repeat/random/single/consume:*
Given a playlist of three tracks numbered 1, 2, 3, and a currently
playing track ``c``. ``next_track`` is defined at the track that
will be played upon calls to ``next``.
Tests performed on MPD 0.15.4-1ubuntu3.
====== ====== ====== ======= ===== ===== ===== =====
Inputs next_track
------------------------------- ------------------- -----
repeat random single consume c = 1 c = 2 c = 3 Notes
====== ====== ====== ======= ===== ===== ===== =====
T T T T 2 3 EOPL
T T T . Rand Rand Rand [1]
T T . T Rand Rand Rand [4]
T T . . Rand Rand Rand [4]
T . T T 2 3 EOPL
T . T . 2 3 1
T . . T 3 3 EOPL
T . . . 2 3 1
. T T T Rand Rand Rand [3]
. T T . Rand Rand Rand [3]
. T . T Rand Rand Rand [2]
. T . . Rand Rand Rand [2]
. . T T 2 3 EOPL
. . T . 2 3 EOPL
. . . T 2 3 EOPL
. . . . 2 3 EOPL
====== ====== ====== ======= ===== ===== ===== =====
- When end of playlist (EOPL) is reached, the current track is
unset.
- [1] When *random* and *single* is combined, ``next`` selects
a track randomly at each invocation, and not just the next track
in an internal prerandomized playlist.
- [2] When *random* is active, ``next`` will skip through
all tracks in the playlist in random order, and finally EOPL is
reached.
- [3] *single* has no effect in combination with *random*
alone, or *random* and *consume*.
- [4] When *random* and *repeat* is active, EOPL is never
reached, but the playlist is played again, in the same random
order as the first time.
"""
return context.core.playback.next().get()
@protocol.commands.add('pause', state=protocol.BOOL)
def pause(context, state=None):
"""
*musicpd.org, playback section:*
``pause {PAUSE}``
Toggles pause/resumes playing, ``PAUSE`` is 0 or 1.
*MPDroid:*
- Calls ``pause`` without any arguments to toogle pause.
"""
if state is None:
deprecation.warn('mpd.protocol.playback.pause:state_arg')
playback_state = context.core.playback.get_state().get()
if (playback_state == PlaybackState.PLAYING):
context.core.playback.pause()
elif (playback_state == PlaybackState.PAUSED):
context.core.playback.resume()
elif state:
context.core.playback.pause()
else:
context.core.playback.resume()
@protocol.commands.add('play', songpos=protocol.INT)
def play(context, songpos=None):
"""
*musicpd.org, playback section:*
``play [SONGPOS]``
Begins playing the playlist at song number ``SONGPOS``.
The original MPD server resumes from the paused state on ``play``
without arguments.
*Clarifications:*
- ``play "-1"`` when playing is ignored.
- ``play "-1"`` when paused resumes playback.
- ``play "-1"`` when stopped with a current track starts playback at the
current track.
- ``play "-1"`` when stopped without a current track, e.g. after playlist
replacement, starts playback at the first track.
*BitMPC:*
- issues ``play 6`` without quotes around the argument.
"""
if songpos is None:
return context.core.playback.play().get()
elif songpos == -1:
return _play_minus_one(context)
try:
tl_track = context.core.tracklist.slice(songpos, songpos + 1).get()[0]
return context.core.playback.play(tl_track).get()
except IndexError:
raise exceptions.MpdArgError('Bad song index')
def _play_minus_one(context):
playback_state = context.core.playback.get_state().get()
if playback_state == PlaybackState.PLAYING:
return # Nothing to do
elif playback_state == PlaybackState.PAUSED:
return context.core.playback.resume().get()
current_tl_track = context.core.playback.get_current_tl_track().get()
if current_tl_track is not None:
return context.core.playback.play(current_tl_track).get()
tl_tracks = context.core.tracklist.slice(0, 1).get()
if tl_tracks:
return context.core.playback.play(tl_tracks[0]).get()
return # Fail silently
@protocol.commands.add('playid', tlid=protocol.INT)
def playid(context, tlid):
"""
*musicpd.org, playback section:*
``playid [SONGID]``
Begins playing the playlist at song ``SONGID``.
*Clarifications:*
- ``playid "-1"`` when playing is ignored.
- ``playid "-1"`` when paused resumes playback.
- ``playid "-1"`` when stopped with a current track starts playback at the
current track.
- ``playid "-1"`` when stopped without a current track, e.g. after playlist
replacement, starts playback at the first track.
"""
if tlid == -1:
return _play_minus_one(context)
tl_tracks = context.core.tracklist.filter({'tlid': [tlid]}).get()
if not tl_tracks:
raise exceptions.MpdNoExistError('No such song')
return context.core.playback.play(tl_tracks[0]).get()
@protocol.commands.add('previous')
def previous(context):
"""
*musicpd.org, playback section:*
``previous``
Plays previous song in the playlist.
*MPD's behaviour when affected by repeat/random/single/consume:*
Given a playlist of three tracks numbered 1, 2, 3, and a currently
playing track ``c``. ``previous_track`` is defined at the track
that will be played upon ``previous`` calls.
Tests performed on MPD 0.15.4-1ubuntu3.
====== ====== ====== ======= ===== ===== =====
Inputs previous_track
------------------------------- -------------------
repeat random single consume c = 1 c = 2 c = 3
====== ====== ====== ======= ===== ===== =====
T T T T Rand? Rand? Rand?
T T T . 3 1 2
T T . T Rand? Rand? Rand?
T T . . 3 1 2
T . T T 3 1 2
T . T . 3 1 2
T . . T 3 1 2
T . . . 3 1 2
. T T T c c c
. T T . c c c
. T . T c c c
. T . . c c c
. . T T 1 1 2
. . T . 1 1 2
. . . T 1 1 2
. . . . 1 1 2
====== ====== ====== ======= ===== ===== =====
- If :attr:`time_position` of the current track is 15s or more,
``previous`` should do a seek to time position 0.
"""
return context.core.playback.previous().get()
@protocol.commands.add('random', state=protocol.BOOL)
def random(context, state):
"""
*musicpd.org, playback section:*
``random {STATE}``
Sets random state to ``STATE``, ``STATE`` should be 0 or 1.
"""
context.core.tracklist.set_random(state)
@protocol.commands.add('repeat', state=protocol.BOOL)
def repeat(context, state):
"""
*musicpd.org, playback section:*
``repeat {STATE}``
Sets repeat state to ``STATE``, ``STATE`` should be 0 or 1.
"""
context.core.tracklist.set_repeat(state)
@protocol.commands.add('replay_gain_mode')
def replay_gain_mode(context, mode):
"""
*musicpd.org, playback section:*
``replay_gain_mode {MODE}``
Sets the replay gain mode. One of ``off``, ``track``, ``album``.
Changing the mode during playback may take several seconds, because
the new settings does not affect the buffered data.
This command triggers the options idle event.
"""
raise exceptions.MpdNotImplemented # TODO
@protocol.commands.add('replay_gain_status')
def replay_gain_status(context):
"""
*musicpd.org, playback section:*
``replay_gain_status``
Prints replay gain options. Currently, only the variable
``replay_gain_mode`` is returned.
"""
return 'off' # TODO
@protocol.commands.add('seek', songpos=protocol.UINT, seconds=protocol.UINT)
def seek(context, songpos, seconds):
"""
*musicpd.org, playback section:*
``seek {SONGPOS} {TIME}``
Seeks to the position ``TIME`` (in seconds) of entry ``SONGPOS`` in
the playlist.
*Droid MPD:*
- issues ``seek 1 120`` without quotes around the arguments.
"""
tl_track = context.core.playback.get_current_tl_track().get()
if context.core.tracklist.index(tl_track).get() != songpos:
play(context, songpos)
context.core.playback.seek(seconds * 1000).get()
@protocol.commands.add('seekid', tlid=protocol.UINT, seconds=protocol.UINT)
def seekid(context, tlid, seconds):
"""
*musicpd.org, playback section:*
``seekid {SONGID} {TIME}``
Seeks to the position ``TIME`` (in seconds) of song ``SONGID``.
"""
tl_track = context.core.playback.get_current_tl_track().get()
if not tl_track or tl_track.tlid != tlid:
playid(context, tlid)
context.core.playback.seek(seconds * 1000).get()
@protocol.commands.add('seekcur')
def seekcur(context, time):
"""
*musicpd.org, playback section:*
``seekcur {TIME}``
Seeks to the position ``TIME`` within the current song. If prefixed by
'+' or '-', then the time is relative to the current playing position.
"""
if time.startswith(('+', '-')):
position = context.core.playback.get_time_position().get()
position += protocol.INT(time) * 1000
context.core.playback.seek(position).get()
else:
position = protocol.UINT(time) * 1000
context.core.playback.seek(position).get()
@protocol.commands.add('setvol', volume=protocol.INT)
def setvol(context, volume):
"""
*musicpd.org, playback section:*
``setvol {VOL}``
Sets volume to ``VOL``, the range of volume is 0-100.
*Droid MPD:*
- issues ``setvol 50`` without quotes around the argument.
"""
# NOTE: we use INT as clients can pass in +N etc.
value = min(max(0, volume), 100)
success = context.core.mixer.set_volume(value).get()
if not success:
raise exceptions.MpdSystemError('problems setting volume')
@protocol.commands.add('single', state=protocol.BOOL)
def single(context, state):
"""
*musicpd.org, playback section:*
``single {STATE}``
Sets single state to ``STATE``, ``STATE`` should be 0 or 1. When
single is activated, playback is stopped after current song, or
song is repeated if the ``repeat`` mode is enabled.
"""
context.core.tracklist.set_single(state)
@protocol.commands.add('stop')
def stop(context):
"""
*musicpd.org, playback section:*
``stop``
Stops playing.
"""
context.core.playback.stop()
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
333,
411,
344,
89,
14,
1018,
492,
16527,
894,
2223,
199,
504,
333,
411,
344,
89,
14,
4672,
492,
17831,
199,
504,
333,
411,
344,
89,
14,
311,
68,
492,
4967,
12,
4113,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
10235,
297,
1174,
29,
3922,
14,
16026,
9,
199,
318,
9451,
8,
1100,
12,
1174,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
10235,
469,
6689,
93,
1040,
398,
10729,
9451,
1174,
370,
1124,
6689,
4542,
1124,
6689,
1040,
1077,
506,
378,
503,
267,
413,
14,
3979,
9451,
365,
22225,
12,
1924,
20178,
5232,
379,
365,
4829,
687,
267,
13210,
14,
272,
408,
272,
1067,
14,
1018,
14,
3885,
513,
14,
409,
63,
10235,
8,
929,
9,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
7925,
667,
271,
297,
4696,
29,
3922,
14,
17459,
9,
199,
318,
8059,
667,
271,
8,
1100,
12,
4696,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
7925,
667,
271,
469,
23319,
93,
1040,
398,
10729,
8059,
70,
5384,
3382,
308,
12358,
14,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
13979,
345,
311,
697,
358,
199,
318,
13667,
345,
311,
697,
8,
1100,
12,
12985,
66,
18099,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
13979,
345,
311,
697,
469,
22612,
34,
18099,
93,
1040,
339,
10729,
314,
8765,
737,
1314,
308,
12358,
911,
506,
15145,
1915,
14,
16485,
8059,
70,
5384,
1325,
272,
3181,
1133,
1433,
271,
314,
4426,
3301,
12,
2951,
29755,
14,
710,
308,
12358,
1929,
370,
1172,
272,
603,
1148,
1537,
311,
3762,
3483,
701,
376,
5957,
4744,
14,
378,
26256,
365,
314,
9657,
5696,
272,
3301,
880,
675,
6946,
1338,
12,
473,
16602,
446,
1196,
26256,
14,
1010,
314,
2236,
14073,
402,
13667,
345,
311,
272,
3762,
8059,
70,
5384,
911,
506,
1202,
14,
1666,
1455,
921,
22943,
14,
846,
15,
6776,
15,
13979,
345,
311,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
13979,
345,
311,
5814,
297,
4696,
29,
3922,
14,
17459,
9,
199,
318,
13667,
345,
311,
5814,
8,
1100,
12,
4696,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
13979,
345,
311,
5814,
469,
23319,
93,
1040,
398,
10961,
900,
1007,
1239,
1522,
687,
314,
15145,
12950,
701,
13667,
345,
311,
697,
14,
437,
267,
574,
402,
298,
4304,
2,
28421,
603,
1148,
1537,
311,
28281,
436,
26945,
1771,
370,
267,
8059,
70,
5384,
14,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
2184,
358,
199,
318,
2163,
2531,
1100,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
2184,
1040,
398,
510,
9316,
2163,
20178,
315,
314,
13210,
14,
339,
627,
1658,
36,
1159,
13942,
1380,
16955,
701,
11982,
15,
2355,
15,
4780,
15,
10235,
27344,
398,
9138,
282,
13210,
402,
7795,
18917,
1967,
18897,
413,
12,
499,
12,
650,
12,
436,
282,
5544,
267,
25692,
4426,
1124,
67,
4345,
1124,
2184,
63,
3885,
1040,
365,
3247,
737,
314,
4426,
626,
267,
911,
506,
5232,
379,
12188,
4882,
370,
1124,
2184,
4345,
398,
6496,
10585,
641,
603,
11435,
378,
14,
1046,
14,
20,
13,
17,
21151,
19,
14,
398,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
490,
30520,
8540,
2163,
63,
3885,
267,
10652,
18964,
221,
10652,
2595,
221,
9063,
267,
11982,
221,
2196,
221,
2849,
221,
9451,
221,
286,
275,
413,
221,
286,
275,
499,
221,
286,
275,
650,
221,
8144,
267,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
267,
377,
755,
377,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
377,
755,
377,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
17,
61,
267,
377,
755,
377,
755,
1275,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
20,
61,
267,
377,
755,
377,
755,
1275,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
20,
61,
267,
377,
755,
1275,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
1275,
755,
377,
755,
1275,
263,
499,
420,
650,
420,
413,
267,
377,
755,
1275,
755,
1275,
755,
377,
263,
650,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
1275,
755,
1275,
755,
1275,
263,
499,
420,
650,
420,
413,
267,
1275,
755,
377,
755,
377,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
19,
61,
267,
1275,
755,
377,
755,
377,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
19,
61,
267,
1275,
755,
377,
755,
1275,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
18,
61,
267,
1275,
755,
377,
755,
1275,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
18,
61,
267,
1275,
755,
1275,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
377,
755,
1275,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
1275,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
1275,
755,
1275,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
398,
446,
3979,
1284,
402,
13210,
334,
37,
1938,
44,
9,
365,
13075,
12,
314,
1453,
4426,
365,
881,
15376,
14,
267,
446,
359,
17,
61,
3979,
627,
2355,
10,
436
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
2649,
63,
5955,
199,
199,
504,
333,
411,
344,
89,
14,
1018,
492,
16527,
894,
2223,
199,
504,
333,
411,
344,
89,
14,
4672,
492,
17831,
199,
504,
333,
411,
344,
89,
14,
311,
68,
492,
4967,
12,
4113,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
10235,
297,
1174,
29,
3922,
14,
16026,
9,
199,
318,
9451,
8,
1100,
12,
1174,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
10235,
469,
6689,
93,
1040,
398,
10729,
9451,
1174,
370,
1124,
6689,
4542,
1124,
6689,
1040,
1077,
506,
378,
503,
267,
413,
14,
3979,
9451,
365,
22225,
12,
1924,
20178,
5232,
379,
365,
4829,
687,
267,
13210,
14,
272,
408,
272,
1067,
14,
1018,
14,
3885,
513,
14,
409,
63,
10235,
8,
929,
9,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
7925,
667,
271,
297,
4696,
29,
3922,
14,
17459,
9,
199,
318,
8059,
667,
271,
8,
1100,
12,
4696,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
7925,
667,
271,
469,
23319,
93,
1040,
398,
10729,
8059,
70,
5384,
3382,
308,
12358,
14,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
13979,
345,
311,
697,
358,
199,
318,
13667,
345,
311,
697,
8,
1100,
12,
12985,
66,
18099,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
13979,
345,
311,
697,
469,
22612,
34,
18099,
93,
1040,
339,
10729,
314,
8765,
737,
1314,
308,
12358,
911,
506,
15145,
1915,
14,
16485,
8059,
70,
5384,
1325,
272,
3181,
1133,
1433,
271,
314,
4426,
3301,
12,
2951,
29755,
14,
710,
308,
12358,
1929,
370,
1172,
272,
603,
1148,
1537,
311,
3762,
3483,
701,
376,
5957,
4744,
14,
378,
26256,
365,
314,
9657,
5696,
272,
3301,
880,
675,
6946,
1338,
12,
473,
16602,
446,
1196,
26256,
14,
1010,
314,
2236,
14073,
402,
13667,
345,
311,
272,
3762,
8059,
70,
5384,
911,
506,
1202,
14,
1666,
1455,
921,
22943,
14,
846,
15,
6776,
15,
13979,
345,
311,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
13979,
345,
311,
5814,
297,
4696,
29,
3922,
14,
17459,
9,
199,
318,
13667,
345,
311,
5814,
8,
1100,
12,
4696,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
13979,
345,
311,
5814,
469,
23319,
93,
1040,
398,
10961,
900,
1007,
1239,
1522,
687,
314,
15145,
12950,
701,
13667,
345,
311,
697,
14,
437,
267,
574,
402,
298,
4304,
2,
28421,
603,
1148,
1537,
311,
28281,
436,
26945,
1771,
370,
267,
8059,
70,
5384,
14,
272,
408,
272,
746,
4967,
14,
45,
8961,
14278,
221,
327,
3254,
421,
199,
32,
3922,
14,
4405,
14,
525,
360,
2184,
358,
199,
318,
2163,
2531,
1100,
304,
272,
408,
272,
627,
6553,
338,
1850,
68,
14,
1308,
12,
5232,
894,
3420,
27344,
398,
1124,
2184,
1040,
398,
510,
9316,
2163,
20178,
315,
314,
13210,
14,
339,
627,
1658,
36,
1159,
13942,
1380,
16955,
701,
11982,
15,
2355,
15,
4780,
15,
10235,
27344,
398,
9138,
282,
13210,
402,
7795,
18917,
1967,
18897,
413,
12,
499,
12,
650,
12,
436,
282,
5544,
267,
25692,
4426,
1124,
67,
4345,
1124,
2184,
63,
3885,
1040,
365,
3247,
737,
314,
4426,
626,
267,
911,
506,
5232,
379,
12188,
4882,
370,
1124,
2184,
4345,
398,
6496,
10585,
641,
603,
11435,
378,
14,
1046,
14,
20,
13,
17,
21151,
19,
14,
398,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
490,
30520,
8540,
2163,
63,
3885,
267,
10652,
18964,
221,
10652,
2595,
221,
9063,
267,
11982,
221,
2196,
221,
2849,
221,
9451,
221,
286,
275,
413,
221,
286,
275,
499,
221,
286,
275,
650,
221,
8144,
267,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
267,
377,
755,
377,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
377,
755,
377,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
17,
61,
267,
377,
755,
377,
755,
1275,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
20,
61,
267,
377,
755,
377,
755,
1275,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
20,
61,
267,
377,
755,
1275,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
1275,
755,
377,
755,
1275,
263,
499,
420,
650,
420,
413,
267,
377,
755,
1275,
755,
1275,
755,
377,
263,
650,
420,
650,
420,
662,
1938,
44,
267,
377,
755,
1275,
755,
1275,
755,
1275,
263,
499,
420,
650,
420,
413,
267,
1275,
755,
377,
755,
377,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
19,
61,
267,
1275,
755,
377,
755,
377,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
19,
61,
267,
1275,
755,
377,
755,
1275,
755,
377,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
18,
61,
267,
1275,
755,
377,
755,
1275,
755,
1275,
263,
820,
460,
257,
820,
460,
257,
820,
460,
257,
359,
18,
61,
267,
1275,
755,
1275,
755,
377,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
377,
755,
1275,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
1275,
755,
377,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
1275,
755,
1275,
755,
1275,
755,
1275,
263,
499,
420,
650,
420,
662,
1938,
44,
267,
9310,
29,
221,
9310,
29,
221,
9310,
29,
221,
9310,
389,
221,
9310,
221,
9310,
221,
9310,
221,
9310,
398,
446,
3979,
1284,
402,
13210,
334,
37,
1938,
44,
9,
365,
13075,
12,
314,
1453,
4426,
365,
881,
15376,
14,
267,
446,
359,
17,
61,
3979,
627,
2355,
10,
436,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mapr/hue
|
desktop/libs/indexer/src/indexer/urls.py
|
14
|
1784
|
#!/usr/bin/env python
# Licensed to Cloudera, Inc. under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. Cloudera, Inc. licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from django.conf.urls import patterns, url
urlpatterns = patterns('indexer.views',
url(r'^$', 'collections', name='collections'),
url(r'^install_examples$', 'install_examples', name='install_examples'),
)
urlpatterns += patterns('indexer.api',
url(r'^api/fields/parse/$', 'parse_fields', name='api_parse_fields'),
url(r'^api/collections/$', 'collections', name='api_collections'),
url(r'^api/collections/create/$', 'collections_create', name='api_collections_create'),
url(r'^api/collections/import/$', 'collections_import', name='api_collections_import'),
url(r'^api/collections/remove/$', 'collections_remove', name='api_collections_remove'),
url(r'^api/collections/(?P<collection>[^/]+)/fields/$', 'collections_fields', name='api_collections_fields'),
url(r'^api/collections/(?P<collection>[^/]+)/update/$', 'collections_update', name='api_collections_update'),
url(r'^api/collections/(?P<collection>[^/]+)/data/$', 'collections_data', name='api_collections_data')
)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3909,
370,
5980,
3786,
345,
12,
3277,
14,
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,
5980,
3786,
345,
12,
3277,
14,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
199,
20050,
275,
7970,
360,
15615,
14,
4196,
297,
523,
1166,
8,
82,
4289,
4268,
283,
7882,
297,
536,
534,
7882,
659,
523,
1166,
8,
82,
4289,
3174,
63,
8589,
4268,
283,
3174,
63,
8589,
297,
536,
534,
3174,
63,
8589,
659,
199,
9,
199,
199,
20050,
847,
7970,
360,
15615,
14,
1246,
297,
523,
1166,
8,
82,
4289,
1246,
15,
955,
15,
1122,
10884,
283,
1122,
63,
955,
297,
536,
534,
1246,
63,
1122,
63,
955,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
10884,
283,
7882,
297,
536,
534,
1246,
63,
7882,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
981,
10884,
283,
7882,
63,
981,
297,
536,
534,
1246,
63,
7882,
63,
981,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
646,
10884,
283,
7882,
63,
646,
297,
536,
534,
1246,
63,
7882,
63,
646,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
2168,
10884,
283,
7882,
63,
2168,
297,
536,
534,
1246,
63,
7882,
63,
2168,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
955,
10884,
283,
7882,
63,
955,
297,
536,
534,
1246,
63,
7882,
63,
955,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
873,
10884,
283,
7882,
63,
873,
297,
536,
534,
1246,
63,
7882,
63,
873,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
576,
10884,
283,
7882,
63,
576,
297,
536,
534,
1246,
63,
7882,
63,
576,
358,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3909,
370,
5980,
3786,
345,
12,
3277,
14,
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,
5980,
3786,
345,
12,
3277,
14,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
199,
20050,
275,
7970,
360,
15615,
14,
4196,
297,
523,
1166,
8,
82,
4289,
4268,
283,
7882,
297,
536,
534,
7882,
659,
523,
1166,
8,
82,
4289,
3174,
63,
8589,
4268,
283,
3174,
63,
8589,
297,
536,
534,
3174,
63,
8589,
659,
199,
9,
199,
199,
20050,
847,
7970,
360,
15615,
14,
1246,
297,
523,
1166,
8,
82,
4289,
1246,
15,
955,
15,
1122,
10884,
283,
1122,
63,
955,
297,
536,
534,
1246,
63,
1122,
63,
955,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
10884,
283,
7882,
297,
536,
534,
1246,
63,
7882,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
981,
10884,
283,
7882,
63,
981,
297,
536,
534,
1246,
63,
7882,
63,
981,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
646,
10884,
283,
7882,
63,
646,
297,
536,
534,
1246,
63,
7882,
63,
646,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
15,
2168,
10884,
283,
7882,
63,
2168,
297,
536,
534,
1246,
63,
7882,
63,
2168,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
955,
10884,
283,
7882,
63,
955,
297,
536,
534,
1246,
63,
7882,
63,
955,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
873,
10884,
283,
7882,
63,
873,
297,
536,
534,
1246,
63,
7882,
63,
873,
659,
523,
1166,
8,
82,
4289,
1246,
15,
7882,
9448,
48,
28,
3627,
26906,
2447,
576,
10884,
283,
7882,
63,
576,
297,
536,
534,
1246,
63,
7882,
63,
576,
358,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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 2012, Cheng-Lung Lee, University of Detroit Mercy.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the names of the authors nor the names of their
# affiliated organizations 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.
#
# Changelog
# 2012.12.13 Use Pos2D message, normalized to 0 ~ 2*PI
#
import roslib; roslib.load_manifest('SpartonCompass')
import rospy
from std_msgs.msg import String
from geometry_msgs.msg import Pose2D
import serial, string, math, time, calendar
#Check the NMEA sentence checksum. Return True if passes and False if failed
def check_checksum(nmea_sentence):
if ('$' in nmea_sentence) and ('*' in nmea_sentence) :
split_sentence = nmea_sentence.split('*')
transmitted_checksum = split_sentence[1].strip()
#Remove the $ at the front
data_to_checksum = split_sentence[0][1:]
checksum = 0
for c in data_to_checksum:
checksum ^= ord(c)
return ("%02X" % checksum) == transmitted_checksum.upper()
else:
return 0
def wrapTo2PI(theta):
'''Normalize an angle in radians to [0, 2*pi]
'''
return theta % (2.*math.pi)
def wrapToPI(theta):
'''Normalize an angle in radians to [-pi, pi]
'''
return (wrapTo2PI(theta+math.pi) - math.pi)
if __name__ == '__main__':
rospy.init_node('SpartonDigitalCompass')
pub = rospy.Publisher('SpartonCompass', Pose2D)
SpartonPose2D=Pose2D()
SpartonPose2D.x=float(0.0)
SpartonPose2D.y=float(0.0)
#Init D_Compass port
D_Compassport = rospy.get_param('~port','/dev/ttyUSB0')
D_Compassrate = rospy.get_param('~baud',115200)
#D_Compassrate = rospy.get_param('~baud',9600)
D_Compassfreq = rospy.get_param('~frequency',10)
#Digital compass heading offset in degree
D_Compass_offset = rospy.get_param('~offset',0.)
try:
#talker()
#ReadCompass()
#Setup Compass serial port
D_Compass = serial.Serial(port=D_Compassport, baudrate=D_Compassrate, timeout=1)
# Set Digital Compass in Continous Mode with right Frequency
# Send $ first with 10ms delay ( make it compatiable with SP3003D) then sned "xxHDT,PRT0.1<CR><LF>"
time.sleep(0.1)
D_Compass.write('$')
time.sleep(0.1)
myStr="xxHDT,RPT=%4.3f" % (1.0/D_Compassfreq)
D_Compass.write(myStr+'\r\n')
rospy.loginfo('Send to Digital Compass Serial:'+myStr)
#data = D_Compass.readline()
#Read in D_Compass
while not rospy.is_shutdown():
#read D_Compass line , The data example $HCHDT,295.5,T*2B
# [0] [1]
data = D_Compass.readline()
#rospy.loginfo("Received a sentence: %s" % data)
if not check_checksum(data):
rospy.logerr("Received a sentence with an invalid checksum. Sentence was: %s" % data)
continue
timeNow = rospy.get_rostime()
fields = data.split(',')
for i in fields:
i = i.strip(',')
try:
if 'HCHDT' in fields[0]:
#convert heading (degrees) to theta (radious) , theta=(90-compassdir)/(360.)*(2*pi)
#SpartonPose2D.theta = wrapToPI(((90.-float(fields[1]))/360.)*(2.*math.pi))
#SpartonPose2D.x = float(fields[1]) #just for debug
SpartonPose2D.theta = wrapToPI(math.radians(90.-float(fields[1])-D_Compass_offset))
pub.publish(SpartonPose2D)
else:
rospy.logerr("Received a sentence but not $HCHDT. Sentence was: %s" % data)
except ValueError as e:
rospy.logwarn("Value error, likely due to missing fields in the NMEA messages. No HCHDT header")
except rospy.ROSInterruptException:
D_Compass.write('$')
time.sleep(0.1)
D_Compass.write('xxHDT\r\n')
rospy.loginfo('Send to Digital Compass Serial:'+myStr)
D_Compass.close() #Close D_Compass serial port
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2290,
844,
28629,
334,
15400,
844,
9,
199,
199,
3,
428,
462,
1860,
29979,
3599,
405,
820,
3100,
19447,
367,
6988,
5863,
19,
36,
15,
33,
14784,
51,
13,
24,
15,
39,
1149,
35,
13,
22,
199,
3,
1898,
334,
67,
9,
6029,
12,
2799,
7420,
13,
44,
10335,
491,
1024,
12,
15904,
402,
577,
386,
293,
390,
18880,
1480,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
259,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
259,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
259,
543,
314,
4084,
14,
199,
3,
221,
627,
11443,
314,
1561,
402,
314,
11462,
6590,
314,
1561,
402,
3932,
199,
3,
259,
29172,
972,
20765,
12270,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
259,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
7743,
793,
199,
3,
6029,
14,
713,
14,
969,
3645,
25987,
18,
36,
1245,
12,
9657,
370,
378,
6146,
499,
10,
2252,
199,
3,
421,
199,
646,
882,
83,
773,
27,
882,
83,
773,
14,
912,
63,
6418,
360,
51,
462,
1860,
2404,
405,
358,
199,
646,
21848,
199,
504,
2418,
63,
13429,
14,
1328,
492,
2624,
199,
504,
3400,
63,
13429,
14,
1328,
492,
510,
3362,
18,
36,
199,
199,
646,
3012,
12,
1059,
12,
3473,
12,
900,
12,
11234,
421,
199,
3,
1799,
314,
653,
3635,
33,
14537,
9040,
14,
1432,
715,
340,
14933,
436,
756,
340,
3405,
199,
318,
1104,
63,
8928,
8,
78,
278,
65,
63,
17727,
304,
199,
198,
692,
221,
661,
12913,
315,
302,
278,
65,
63,
17727,
9,
436,
661,
10223,
315,
302,
278,
65,
63,
17727,
9,
520,
6722,
3715,
63,
17727,
275,
302,
278,
65,
63,
17727,
14,
1294,
360,
13418,
6722,
29818,
63,
8928,
275,
3715,
63,
17727,
59,
17,
1055,
1913,
342,
507,
258,
6722,
327,
5587,
314,
2672,
737,
314,
13738,
6722,
666,
63,
475,
63,
8928,
275,
3715,
63,
17727,
59,
16,
1527,
17,
2938,
6722,
9040,
275,
378,
6722,
367,
286,
315,
666,
63,
475,
63,
8928,
26,
507,
198,
8928,
31753,
6206,
8,
67,
9,
2742,
259,
372,
19426,
996,
56,
2,
450,
9040,
9,
221,
508,
29818,
63,
8928,
14,
4142,
342,
267,
587,
26,
288,
372,
378,
199,
199,
318,
4816,
1378,
18,
2252,
8,
9337,
304,
272,
1449,
22580,
376,
9324,
315,
26874,
370,
359,
16,
12,
499,
10,
1038,
61,
272,
1449,
272,
372,
12724,
450,
334,
18,
2795,
3442,
14,
1038,
9,
199,
199,
318,
4816,
1378,
2252,
8,
9337,
304,
272,
1449,
22580,
376,
9324,
315,
26874,
370,
5243,
1038,
12,
6682,
61,
272,
1449,
272,
372,
334,
3823,
1378,
18,
2252,
8,
9337,
11,
3442,
14,
1038,
9,
446,
3473,
14,
1038,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
21848,
14,
826,
63,
932,
360,
51,
462,
1860,
32660,
2404,
405,
358,
272,
7974,
275,
21848,
14,
27341,
360,
51,
462,
1860,
2404,
405,
297,
510,
3362,
18,
36,
9,
272,
428,
462,
1860,
1575,
261,
18,
36,
29,
1575,
261,
18,
36,
342,
272,
428,
462,
1860,
1575,
261,
18,
36,
14,
88,
29,
1609,
8,
16,
14,
16,
9,
272,
428,
462,
1860,
1575,
261,
18,
36,
14,
89,
29,
1609,
8,
16,
14,
16,
9,
272,
327,
9346,
577,
63,
2404,
405,
1844,
272,
577,
63,
2404,
405,
719,
275,
21848,
14,
362,
63,
635,
21114,
719,
32381,
2374,
15,
4707,
19919,
16,
358,
272,
577,
63,
2404,
405,
1866,
275,
21848,
14,
362,
63,
635,
21114,
2470,
1181,
297,
7680,
1840,
9,
272,
327,
36,
63,
2404,
405,
1866,
275,
21848,
14,
362,
63,
635,
21114,
2470,
1181,
297,
2534,
383,
9,
272,
577,
63,
2404,
405,
5646,
275,
21848,
14,
362,
63,
635,
21114,
11132,
297,
709,
9,
272,
327,
32660,
1013,
405,
16631,
3268,
315,
13666,
272,
577,
63,
2404,
405,
63,
2743,
275,
21848,
14,
362,
63,
635,
21114,
2743,
297,
16,
4959,
2286,
862,
26,
267,
327,
84,
14976,
342,
267,
327,
3284,
2404,
405,
342,
199,
198,
3,
8555,
3599,
405,
3012,
1844,
267,
577,
63,
2404,
405,
275,
3012,
14,
3571,
8,
719,
29,
36,
63,
2404,
405,
719,
12,
19325,
27112,
29,
36,
63,
2404,
405,
1866,
12,
2653,
29,
17,
9,
199,
198,
3,
2494,
29979,
3599,
405,
315,
1448,
1346,
1785,
4900,
543,
2451,
481,
6056,
199,
198,
3,
10217,
2672,
1642,
543,
1616,
706,
7339,
334,
1852,
652,
1013,
2159,
461,
543,
6988,
5863,
19,
36,
9,
2066,
6895,
379,
298,
2154,
40,
7438,
12,
3311,
52,
16,
14,
17,
28,
2944,
2535,
15965,
4335,
199
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
2290,
844,
28629,
334,
15400,
844,
9,
199,
199,
3,
428,
462,
1860,
29979,
3599,
405,
820,
3100,
19447,
367,
6988,
5863,
19,
36,
15,
33,
14784,
51,
13,
24,
15,
39,
1149,
35,
13,
22,
199,
3,
1898,
334,
67,
9,
6029,
12,
2799,
7420,
13,
44,
10335,
491,
1024,
12,
15904,
402,
577,
386,
293,
390,
18880,
1480,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
199,
3,
787,
7647,
26,
199,
3,
199,
3,
221,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
259,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
221,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
259,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
199,
3,
259,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
199,
3,
259,
543,
314,
4084,
14,
199,
3,
221,
627,
11443,
314,
1561,
402,
314,
11462,
6590,
314,
1561,
402,
3932,
199,
3,
259,
29172,
972,
20765,
12270,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
199,
3,
259,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
5877,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
199,
3,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
3,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
199,
3,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
199,
3,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
199,
3,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
199,
3,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
199,
3,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
7743,
793,
199,
3,
6029,
14,
713,
14,
969,
3645,
25987,
18,
36,
1245,
12,
9657,
370,
378,
6146,
499,
10,
2252,
199,
3,
421,
199,
646,
882,
83,
773,
27,
882,
83,
773,
14,
912,
63,
6418,
360,
51,
462,
1860,
2404,
405,
358,
199,
646,
21848,
199,
504,
2418,
63,
13429,
14,
1328,
492,
2624,
199,
504,
3400,
63,
13429,
14,
1328,
492,
510,
3362,
18,
36,
199,
199,
646,
3012,
12,
1059,
12,
3473,
12,
900,
12,
11234,
421,
199,
3,
1799,
314,
653,
3635,
33,
14537,
9040,
14,
1432,
715,
340,
14933,
436,
756,
340,
3405,
199,
318,
1104,
63,
8928,
8,
78,
278,
65,
63,
17727,
304,
199,
198,
692,
221,
661,
12913,
315,
302,
278,
65,
63,
17727,
9,
436,
661,
10223,
315,
302,
278,
65,
63,
17727,
9,
520,
6722,
3715,
63,
17727,
275,
302,
278,
65,
63,
17727,
14,
1294,
360,
13418,
6722,
29818,
63,
8928,
275,
3715,
63,
17727,
59,
17,
1055,
1913,
342,
507,
258,
6722,
327,
5587,
314,
2672,
737,
314,
13738,
6722,
666,
63,
475,
63,
8928,
275,
3715,
63,
17727,
59,
16,
1527,
17,
2938,
6722,
9040,
275,
378,
6722,
367,
286,
315,
666,
63,
475,
63,
8928,
26,
507,
198,
8928,
31753,
6206,
8,
67,
9,
2742,
259,
372,
19426,
996,
56,
2,
450,
9040,
9,
221,
508,
29818,
63,
8928,
14,
4142,
342,
267,
587,
26,
288,
372,
378,
199,
199,
318,
4816,
1378,
18,
2252,
8,
9337,
304,
272,
1449,
22580,
376,
9324,
315,
26874,
370,
359,
16,
12,
499,
10,
1038,
61,
272,
1449,
272,
372,
12724,
450,
334,
18,
2795,
3442,
14,
1038,
9,
199,
199,
318,
4816,
1378,
2252,
8,
9337,
304,
272,
1449,
22580,
376,
9324,
315,
26874,
370,
5243,
1038,
12,
6682,
61,
272,
1449,
272,
372,
334,
3823,
1378,
18,
2252,
8,
9337,
11,
3442,
14,
1038,
9,
446,
3473,
14,
1038,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
21848,
14,
826,
63,
932,
360,
51,
462,
1860,
32660,
2404,
405,
358,
272,
7974,
275,
21848,
14,
27341,
360,
51,
462,
1860,
2404,
405,
297,
510,
3362,
18,
36,
9,
272,
428,
462,
1860,
1575,
261,
18,
36,
29,
1575,
261,
18,
36,
342,
272,
428,
462,
1860,
1575,
261,
18,
36,
14,
88,
29,
1609,
8,
16,
14,
16,
9,
272,
428,
462,
1860,
1575,
261,
18,
36,
14,
89,
29,
1609,
8,
16,
14,
16,
9,
272,
327,
9346,
577,
63,
2404,
405,
1844,
272,
577,
63,
2404,
405,
719,
275,
21848,
14,
362,
63,
635,
21114,
719,
32381,
2374,
15,
4707,
19919,
16,
358,
272,
577,
63,
2404,
405,
1866,
275,
21848,
14,
362,
63,
635,
21114,
2470,
1181,
297,
7680,
1840,
9,
272,
327,
36,
63,
2404,
405,
1866,
275,
21848,
14,
362,
63,
635,
21114,
2470,
1181,
297,
2534,
383,
9,
272,
577,
63,
2404,
405,
5646,
275,
21848,
14,
362,
63,
635,
21114,
11132,
297,
709,
9,
272,
327,
32660,
1013,
405,
16631,
3268,
315,
13666,
272,
577,
63,
2404,
405,
63,
2743,
275,
21848,
14,
362,
63,
635,
21114,
2743,
297,
16,
4959,
2286,
862,
26,
267,
327,
84,
14976,
342,
267,
327,
3284,
2404,
405,
342,
199,
198,
3,
8555,
3599,
405,
3012,
1844,
267,
577,
63,
2404,
405,
275,
3012,
14,
3571,
8,
719,
29,
36,
63,
2404,
405,
719,
12,
19325,
27112,
29,
36,
63,
2404,
405,
1866,
12,
2653,
29,
17,
9,
199,
198,
3,
2494,
29979,
3599,
405,
315,
1448,
1346,
1785,
4900,
543,
2451,
481,
6056,
199,
198,
3,
10217,
2672,
1642,
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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
] |
isandlaTech/cohorte-demos
|
led/dump/led-demo-yun/cohorte/dist/cohorte-1.0.0-20141216.234517-57-python-distribution/repo/sleekxmpp/plugins/xep_0325/device.py
|
9
|
4559
|
"""
SleekXMPP: The Sleek XMPP Library
Implementation of xeps for Internet of Things
http://wiki.xmpp.org/web/Tech_pages/IoT_systems
Copyright (C) 2013 Sustainable Innovation, Joachim.lindborg@sust.se, bjorn.westrom@consoden.se
This file is part of SleekXMPP.
See the file LICENSE for copying permission.
"""
import datetime
class Device(object):
"""
Example implementation of a device control object.
The device object may by any custom implementation to support
specific devices, but it must implement the functions:
has_control_field
set_control_fields
"""
def __init__(self, nodeId):
self.nodeId = nodeId;
self.control_fields = {};
def has_control_field(self, field, typename):
"""
Returns true if the supplied field name exists
and the type matches for control in this device.
Arguments:
field -- The field name
typename -- The expected type
"""
if field in self.control_fields and self.control_fields[field]["type"] == typename:
return True;
return False;
def set_control_fields(self, fields, session, callback):
"""
Starts a control setting procedure. Verifies the fields,
sets the data and (if needed) and calls the callback.
Arguments:
fields -- List of control fields in tuple format:
(name, typename, value)
session -- Session id, only used in the callback as identifier
callback -- Callback function to call when control set is complete.
The callback function must support the following arguments:
session -- Session id, as supplied in the
request_fields call
nodeId -- Identifier for this device
result -- The current result status of the readout.
Valid values are:
"error" - Set fields failed.
"ok" - All fields were set.
error_field -- [optional] Only applies when result == "error"
The field name that failed
(usually means it is missing)
error_msg -- [optional] Only applies when result == "error".
Error details when a request failed.
"""
if len(fields) > 0:
# Check availiability
for name, typename, value in fields:
if not self.has_control_field(name, typename):
self._send_control_reject(session, name, "NotFound", callback)
return False;
for name, typename, value in fields:
self._set_field_value(name, value)
callback(session, result="ok", nodeId=self.nodeId);
return True
def _send_control_reject(self, session, field, message, callback):
"""
Sends a reject to the caller
Arguments:
session -- Session id, see definition in
set_control_fields function
callback -- Callback function, see definition in
set_control_fields function
"""
callback(session, result="error", nodeId=self.nodeId, error_field=field, error_msg=message);
def _add_control_field(self, name, typename, value):
"""
Adds a control field to the device
Arguments:
name -- Name of the field
typename -- Type of the field, one of:
(boolean, color, string, date, dateTime,
double, duration, int, long, time)
value -- Field value
"""
self.control_fields[name] = {"type": typename, "value": value};
def _set_field_value(self, name, value):
"""
Set the value of a control field
Arguments:
name -- Name of the field
value -- New value for the field
"""
if name in self.control_fields:
self.control_fields[name]["value"] = value;
def _get_field_value(self, name):
"""
Get the value of a control field. Only used for unit testing.
Arguments:
name -- Name of the field
"""
if name in self.control_fields:
return self.control_fields[name]["value"];
return None;
|
apache-2.0
|
[
624,
272,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
272,
24425,
402,
671,
8277,
367,
22026,
402,
3868,
780,
272,
1455,
921,
6797,
14,
26608,
14,
1308,
15,
2520,
15,
6301,
335,
63,
5856,
15,
16512,
52,
63,
19135,
272,
1898,
334,
35,
9,
6171,
428,
833,
1581,
461,
1010,
889,
4255,
12,
7135,
1225,
1017,
14,
472,
697,
1308,
32,
83,
833,
14,
261,
12,
330,
5857,
78,
14,
19082,
417,
32,
8704,
380,
78,
14,
261,
272,
961,
570,
365,
1777,
402,
428,
274,
5711,
56,
1658,
48,
14,
339,
1666,
314,
570,
5113,
367,
16743,
4983,
14,
199,
624,
199,
199,
646,
2197,
199,
199,
533,
12272,
8,
785,
304,
272,
408,
272,
5679,
4514,
402,
282,
2243,
3304,
909,
14,
2286,
710,
2243,
909,
1443,
701,
1263,
3537,
4514,
370,
2291,
5591,
2488,
7256,
12,
1325,
652,
1471,
5669,
314,
3423,
26,
881,
965,
63,
2785,
63,
698,
881,
663,
63,
2785,
63,
955,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1031,
1304,
304,
267,
291,
14,
932,
1304,
275,
1031,
1304,
27,
267,
291,
14,
2785,
63,
955,
275,
27978,
339,
347,
965,
63,
2785,
63,
698,
8,
277,
12,
901,
12,
19151,
304,
267,
408,
267,
1803,
2549,
340,
314,
6841,
901,
536,
3495,
267,
436,
314,
730,
4450,
367,
3304,
315,
642,
2243,
14,
398,
7628,
26,
288,
901,
420,
1553,
710,
901,
536,
260,
288,
19151,
257,
1553,
710,
1420,
730,
267,
408,
267,
340,
901,
315,
291,
14,
2785,
63,
955,
436,
291,
14,
2785,
63,
955,
59,
698,
7541,
466,
937,
508,
19151,
26,
288,
372,
715,
27,
267,
372,
756,
27,
339,
347,
663,
63,
2785,
63,
955,
8,
277,
12,
1504,
12,
2351,
12,
3233,
304,
267,
408,
267,
7707,
83,
282,
3304,
4260,
17782,
14,
26114,
314,
1504,
12,
267,
5951,
314,
666,
436,
334,
692,
4346,
9,
436,
4882,
314,
3233,
14,
398,
7628,
26,
288,
1504,
257,
1553,
3820,
402,
3304,
1504,
315,
2008,
1475,
26,
12723,
334,
354,
12,
19151,
12,
574,
9,
288,
2351,
221,
1553,
8596,
1305,
12,
1454,
1202,
315,
314,
3233,
465,
5148,
288,
3233,
1553,
17555,
805,
370,
1240,
1380,
3304,
663,
365,
4890,
14,
4951,
710,
3233,
805,
1471,
2291,
314,
2569,
2368,
26,
2234,
2351,
258,
1553,
8596,
1305,
12,
465,
6841,
315,
314,
221,
3044,
1056,
63,
955,
1240,
355,
1031,
1304,
420,
1553,
23285,
367,
642,
2243,
355,
754,
420,
1553,
710,
1453,
754,
2004,
402,
314,
1586,
548,
14,
221,
3044,
4821,
1338,
787,
26,
3044,
298,
705,
2,
221,
446,
2494,
1504,
3405,
14,
3044,
298,
745,
2,
258,
446,
2900,
1504,
4898,
663,
14,
355,
1125,
63,
698,
1553,
359,
4144,
61,
5972,
12966,
1380,
754,
508,
298,
705,
2,
221,
3044,
710,
901,
536,
626,
3405,
221,
3044,
334,
25118,
4910,
652,
365,
4124,
9,
355,
1125,
63,
1328,
257,
1553,
359,
4144,
61,
5972,
12966,
1380,
754,
508,
298,
705,
1674,
3044,
4520,
2436,
1380,
282,
1056,
3405,
14,
267,
408,
398,
340,
822,
8,
955,
9,
690,
378,
26,
288,
327,
2670,
2289,
65,
1638,
3616,
288,
367,
536,
12,
19151,
12,
574,
315,
1504,
26,
355,
340,
440,
291,
14,
1989,
63,
2785,
63,
698,
8,
354,
12,
19151,
304,
490,
291,
423,
2254,
63,
2785,
63,
16857,
8,
1730,
12,
536,
12,
298,
4667,
401,
3233,
9,
490,
372,
756,
27,
398,
367,
536,
12,
19151,
12,
574,
315,
1504,
26,
288,
291,
423,
409,
63,
698,
63,
585,
8,
354,
12,
574,
9,
398,
3233,
8,
1730,
12,
754,
628,
745,
401,
1031,
1304,
29,
277,
14,
932,
1304,
2736,
267,
372,
715,
339,
347,
485,
2254,
63,
2785,
63,
16857,
8,
277,
12,
2351,
12,
901,
12,
1245,
12,
3233,
304,
267,
408,
267,
428,
3198,
282,
17100,
370,
314,
8025,
398,
7628,
26,
288,
2351,
221,
1553,
8596,
1305,
12,
1937,
5492,
315,
12723,
663,
63,
2785,
63,
955,
805,
288,
3233,
1553,
17555,
805,
12,
1937,
5492,
315,
12723,
663,
63,
2785,
63,
955,
805,
267,
408,
267,
3233,
8,
1730,
12,
754,
628,
705,
401,
1031,
1304,
29,
277,
14,
932,
1304,
12,
1125,
63,
698,
29,
698,
12,
1125,
63,
1328,
29,
1188,
2736,
339,
347,
485,
525,
63,
2785,
63,
698,
8,
277,
12,
536,
12,
19151,
12,
574,
304,
267,
408,
267,
15747,
282,
3304,
901,
370,
314,
2243,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
288,
19151,
1553,
2434,
402,
314,
901,
12,
1373,
402,
26,
12723,
334,
4871,
12,
3164,
12,
1059,
12,
1434,
12,
1434,
1366,
12,
221,
586,
4270,
12,
7373,
12,
1109,
12,
1846,
12,
900,
9,
288,
574,
259,
1553,
5024,
574,
267,
408,
267,
291,
14,
2785,
63,
955,
59,
354,
61,
275,
2420,
466,
582,
19151,
12,
298,
585,
582,
574,
12084,
339,
347,
485,
409,
63,
698,
63,
585,
8,
277,
12,
536,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
282,
3304,
901,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
288,
574,
259,
1553,
7053,
574,
367,
314,
901,
267,
408,
267,
340,
536,
315,
291,
14,
2785,
63,
955,
26,
288,
291,
14,
2785,
63,
955,
59,
354,
7541,
585,
937,
275,
574,
27,
339,
347,
485,
362,
63,
698,
63,
585,
8,
277,
12,
536,
304,
267,
408,
267,
2372,
314,
574,
402,
282,
3304,
901,
14,
5972,
1202,
367,
4137,
5343,
14,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
267,
408,
267,
340,
536,
315,
291,
14,
2785,
63,
955,
26,
288,
372,
291,
14,
2785,
63,
955,
59,
354,
7541,
585,
937,
27,
267,
372,
488,
27,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
272,
428,
274,
5711,
56,
1658,
48,
26,
710,
428,
274,
5711,
1323,
1658,
48,
11243,
272,
24425,
402,
671,
8277,
367,
22026,
402,
3868,
780,
272,
1455,
921,
6797,
14,
26608,
14,
1308,
15,
2520,
15,
6301,
335,
63,
5856,
15,
16512,
52,
63,
19135,
272,
1898,
334,
35,
9,
6171,
428,
833,
1581,
461,
1010,
889,
4255,
12,
7135,
1225,
1017,
14,
472,
697,
1308,
32,
83,
833,
14,
261,
12,
330,
5857,
78,
14,
19082,
417,
32,
8704,
380,
78,
14,
261,
272,
961,
570,
365,
1777,
402,
428,
274,
5711,
56,
1658,
48,
14,
339,
1666,
314,
570,
5113,
367,
16743,
4983,
14,
199,
624,
199,
199,
646,
2197,
199,
199,
533,
12272,
8,
785,
304,
272,
408,
272,
5679,
4514,
402,
282,
2243,
3304,
909,
14,
2286,
710,
2243,
909,
1443,
701,
1263,
3537,
4514,
370,
2291,
5591,
2488,
7256,
12,
1325,
652,
1471,
5669,
314,
3423,
26,
881,
965,
63,
2785,
63,
698,
881,
663,
63,
2785,
63,
955,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1031,
1304,
304,
267,
291,
14,
932,
1304,
275,
1031,
1304,
27,
267,
291,
14,
2785,
63,
955,
275,
27978,
339,
347,
965,
63,
2785,
63,
698,
8,
277,
12,
901,
12,
19151,
304,
267,
408,
267,
1803,
2549,
340,
314,
6841,
901,
536,
3495,
267,
436,
314,
730,
4450,
367,
3304,
315,
642,
2243,
14,
398,
7628,
26,
288,
901,
420,
1553,
710,
901,
536,
260,
288,
19151,
257,
1553,
710,
1420,
730,
267,
408,
267,
340,
901,
315,
291,
14,
2785,
63,
955,
436,
291,
14,
2785,
63,
955,
59,
698,
7541,
466,
937,
508,
19151,
26,
288,
372,
715,
27,
267,
372,
756,
27,
339,
347,
663,
63,
2785,
63,
955,
8,
277,
12,
1504,
12,
2351,
12,
3233,
304,
267,
408,
267,
7707,
83,
282,
3304,
4260,
17782,
14,
26114,
314,
1504,
12,
267,
5951,
314,
666,
436,
334,
692,
4346,
9,
436,
4882,
314,
3233,
14,
398,
7628,
26,
288,
1504,
257,
1553,
3820,
402,
3304,
1504,
315,
2008,
1475,
26,
12723,
334,
354,
12,
19151,
12,
574,
9,
288,
2351,
221,
1553,
8596,
1305,
12,
1454,
1202,
315,
314,
3233,
465,
5148,
288,
3233,
1553,
17555,
805,
370,
1240,
1380,
3304,
663,
365,
4890,
14,
4951,
710,
3233,
805,
1471,
2291,
314,
2569,
2368,
26,
2234,
2351,
258,
1553,
8596,
1305,
12,
465,
6841,
315,
314,
221,
3044,
1056,
63,
955,
1240,
355,
1031,
1304,
420,
1553,
23285,
367,
642,
2243,
355,
754,
420,
1553,
710,
1453,
754,
2004,
402,
314,
1586,
548,
14,
221,
3044,
4821,
1338,
787,
26,
3044,
298,
705,
2,
221,
446,
2494,
1504,
3405,
14,
3044,
298,
745,
2,
258,
446,
2900,
1504,
4898,
663,
14,
355,
1125,
63,
698,
1553,
359,
4144,
61,
5972,
12966,
1380,
754,
508,
298,
705,
2,
221,
3044,
710,
901,
536,
626,
3405,
221,
3044,
334,
25118,
4910,
652,
365,
4124,
9,
355,
1125,
63,
1328,
257,
1553,
359,
4144,
61,
5972,
12966,
1380,
754,
508,
298,
705,
1674,
3044,
4520,
2436,
1380,
282,
1056,
3405,
14,
267,
408,
398,
340,
822,
8,
955,
9,
690,
378,
26,
288,
327,
2670,
2289,
65,
1638,
3616,
288,
367,
536,
12,
19151,
12,
574,
315,
1504,
26,
355,
340,
440,
291,
14,
1989,
63,
2785,
63,
698,
8,
354,
12,
19151,
304,
490,
291,
423,
2254,
63,
2785,
63,
16857,
8,
1730,
12,
536,
12,
298,
4667,
401,
3233,
9,
490,
372,
756,
27,
398,
367,
536,
12,
19151,
12,
574,
315,
1504,
26,
288,
291,
423,
409,
63,
698,
63,
585,
8,
354,
12,
574,
9,
398,
3233,
8,
1730,
12,
754,
628,
745,
401,
1031,
1304,
29,
277,
14,
932,
1304,
2736,
267,
372,
715,
339,
347,
485,
2254,
63,
2785,
63,
16857,
8,
277,
12,
2351,
12,
901,
12,
1245,
12,
3233,
304,
267,
408,
267,
428,
3198,
282,
17100,
370,
314,
8025,
398,
7628,
26,
288,
2351,
221,
1553,
8596,
1305,
12,
1937,
5492,
315,
12723,
663,
63,
2785,
63,
955,
805,
288,
3233,
1553,
17555,
805,
12,
1937,
5492,
315,
12723,
663,
63,
2785,
63,
955,
805,
267,
408,
267,
3233,
8,
1730,
12,
754,
628,
705,
401,
1031,
1304,
29,
277,
14,
932,
1304,
12,
1125,
63,
698,
29,
698,
12,
1125,
63,
1328,
29,
1188,
2736,
339,
347,
485,
525,
63,
2785,
63,
698,
8,
277,
12,
536,
12,
19151,
12,
574,
304,
267,
408,
267,
15747,
282,
3304,
901,
370,
314,
2243,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
288,
19151,
1553,
2434,
402,
314,
901,
12,
1373,
402,
26,
12723,
334,
4871,
12,
3164,
12,
1059,
12,
1434,
12,
1434,
1366,
12,
221,
586,
4270,
12,
7373,
12,
1109,
12,
1846,
12,
900,
9,
288,
574,
259,
1553,
5024,
574,
267,
408,
267,
291,
14,
2785,
63,
955,
59,
354,
61,
275,
2420,
466,
582,
19151,
12,
298,
585,
582,
574,
12084,
339,
347,
485,
409,
63,
698,
63,
585,
8,
277,
12,
536,
12,
574,
304,
267,
408,
267,
2494,
314,
574,
402,
282,
3304,
901,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
288,
574,
259,
1553,
7053,
574,
367,
314,
901,
267,
408,
267,
340,
536,
315,
291,
14,
2785,
63,
955,
26,
288,
291,
14,
2785,
63,
955,
59,
354,
7541,
585,
937,
275,
574,
27,
339,
347,
485,
362,
63,
698,
63,
585,
8,
277,
12,
536,
304,
267,
408,
267,
2372,
314,
574,
402,
282,
3304,
901,
14,
5972,
1202,
367,
4137,
5343,
14,
398,
7628,
26,
288,
536,
258,
1553,
2812,
402,
314,
901,
267,
408,
267,
340,
536,
315,
291,
14,
2785,
63,
955,
26,
288,
372,
291,
14,
2785,
63,
955,
59,
354,
7541,
585,
937,
27,
267,
372,
488,
27,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
obnoxxx/samba
|
python/samba/netcmd/testparm.py
|
31
|
8540
|
# Unix SMB/CIFS implementation.
# Test validity of smb.conf
# Copyright (C) 2010-2011 Jelmer Vernooij <jelmer@samba.org>
#
# Based on the original in C:
# Copyright (C) Karl Auer 1993, 1994-1998
# Extensively modified by Andrew Tridgell, 1995
# Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 2002
# Updated for Samba4 by Andrew Bartlett <abartlet@samba.org> 2006
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Testbed for loadparm.c/params.c
#
# This module simply loads a specified configuration file and
# if successful, dumps it's contents to stdout. Note that the
# operation is performed with DEBUGLEVEL at 3.
#
# Useful for a quick 'syntax check' of a configuration file.
#
import os
import sys
import samba
import samba.getopt as options
from samba.netcmd import Command, CommandError, Option
class cmd_testparm(Command):
"""Syntax check the configuration file."""
synopsis = "%prog [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions
}
takes_options = [
Option("--section-name", type=str,
help="Limit testparm to a named section"),
Option("--parameter-name", type=str,
help="Limit testparm to a named parameter"),
Option("--client-name", type=str,
help="Client DNS name for 'hosts allow' checking "
"(should match reverse lookup)"),
Option("--client-ip", type=str,
help="Client IP address for 'hosts allow' checking"),
Option("--suppress-prompt", action="store_true", default=False,
help="Suppress prompt for enter"),
Option("-v", "--verbose", action="store_true",
default=False, help="Show default options too"),
# We need support for smb.conf macros before this will work again
Option("--server", type=str, help="Set %L macro to servername"),
# These are harder to do with the new code structure
Option("--show-all-parameters", action="store_true", default=False,
help="Show the parameters, type, possible values")
]
takes_args = []
def run(self, sambaopts, versionopts, section_name=None,
parameter_name=None, client_ip=None, client_name=None,
verbose=False, suppress_prompt=None, show_all_parameters=False,
server=None):
if server:
raise NotImplementedError("--server not yet implemented")
if show_all_parameters:
raise NotImplementedError("--show-all-parameters not yet implemented")
if client_name is not None and client_ip is None:
raise CommandError("Both a DNS name and an IP address are "
"required for the host access check")
try:
lp = sambaopts.get_loadparm()
except RuntimeError, err:
raise CommandError(err)
# We need this to force the output
samba.set_debug_level(2)
logger = self.get_logger("testparm")
logger.info("Loaded smb config files from %s", lp.configfile)
logger.info("Loaded services file OK.")
valid = self.do_global_checks(lp, logger)
valid = valid and self.do_share_checks(lp, logger)
if client_name is not None and client_ip is not None:
self.check_client_access(lp, logger, client_name, client_ip)
else:
if section_name is not None or parameter_name is not None:
if parameter_name is None:
lp[section_name].dump(sys.stdout, lp.default_service,
verbose)
else:
lp.dump_a_parameter(sys.stdout, parameter_name, section_name)
else:
if not suppress_prompt:
self.outf.write("Press enter to see a dump of your service definitions\n")
sys.stdin.readline()
lp.dump(sys.stdout, verbose)
if valid:
return
else:
raise CommandError("Invalid smb.conf")
def do_global_checks(self, lp, logger):
valid = True
netbios_name = lp.get("netbios name")
if not samba.valid_netbios_name(netbios_name):
logger.error("netbios name %s is not a valid netbios name",
netbios_name)
valid = False
workgroup = lp.get("workgroup")
if not samba.valid_netbios_name(workgroup):
logger.error("workgroup name %s is not a valid netbios name",
workgroup)
valid = False
lockdir = lp.get("lockdir")
if not os.path.isdir(lockdir):
logger.error("lock directory %s does not exist", lockdir)
valid = False
piddir = lp.get("pid directory")
if not os.path.isdir(piddir):
logger.error("pid directory %s does not exist", piddir)
valid = False
winbind_separator = lp.get("winbind separator")
if len(winbind_separator) != 1:
logger.error("the 'winbind separator' parameter must be a single "
"character.")
valid = False
if winbind_separator == '+':
logger.error(
"'winbind separator = +' might cause problems with group "
"membership.")
valid = False
role = lp.get("server role")
charset = lp.get("unix charset").upper()
if role in ["active directory domain controller", "domain controller", "dc"] and charset not in ["UTF-8", "UTF8"]:
logger.warning(
"When acting as Active Directory domain controller, "
"unix charset is expected to be UTF-8.")
return valid
def allow_access(self, deny_list, allow_list, cname, caddr):
raise NotImplementedError(self.allow_access)
def do_share_checks(self, lp, logger):
valid = True
for s in lp.services():
if len(s) > 12:
logger.warning(
"You have some share names that are longer than 12 "
"characters. These may not be accessible to some older "
"clients. (Eg. Windows9x, WindowsMe, and not listed in "
"smbclient in Samba 3.0.)")
break
for s in lp.services():
deny_list = lp.get("hosts deny", s)
allow_list = lp.get("hosts allow", s)
if deny_list:
for entry in deny_list:
if "*" in entry or "?" in entry:
logger.error("Invalid character (* or ?) in hosts deny "
"list (%s) for service %s.", entry, s)
valid = False
if allow_list:
for entry in allow_list:
if "*" in entry or "?" in entry:
logger.error("Invalid character (* or ?) in hosts allow "
"list (%s) for service %s.", entry, s)
valid = False
return valid
def check_client_access(self, lp, logger, cname, caddr):
# this is totally ugly, a real `quick' hack
for s in lp.services():
if (self.allow_access(lp.get("hosts deny"), lp.get("hosts allow"), cname,
caddr) and
self.allow_access(lp.get("hosts deny", s), lp.get("hosts allow", s),
cname, caddr)):
logger.info("Allow connection from %s (%s) to %s", cname, caddr, s)
else:
logger.info("Deny connection from %s (%s) to %s", cname, caddr, s)
## FIXME: We need support for smb.conf macros before this will work again
##
## if (new_local_machine) {
## set_local_machine_name(new_local_machine, True)
## }
#
|
gpl-3.0
|
[
3,
257,
13074,
2389,
34,
15,
3553,
7079,
4514,
14,
199,
3,
257,
1379,
25667,
402,
22717,
14,
2190,
199,
3,
257,
1898,
334,
35,
9,
7129,
13,
8128,
1603,
352,
2626,
5444,
889,
79,
7879,
665,
74,
352,
2626,
32,
21693,
14,
1308,
30,
199,
3,
199,
3,
21311,
641,
314,
3379,
315,
445,
26,
199,
3,
257,
1898,
334,
35,
9,
1804,
285,
76,
437,
14262,
9013,
19,
12,
9013,
20,
13,
23756,
199,
3,
257,
11524,
9840,
6042,
701,
6061,
5257,
377,
5562,
914,
12,
9013,
21,
199,
3,
257,
11801,
471,
370,
299,
2992,
701,
1603,
352,
2626,
5444,
889,
79,
7879,
334,
74,
352,
2626,
32,
7530,
14,
5135,
14,
1308,
395,
14790,
199,
3,
257,
6162,
68,
367,
428,
14310,
20,
701,
6061,
5257,
699,
580,
22784,
665,
371,
580,
2723,
32,
21693,
14,
1308,
30,
8315,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1379,
6123,
367,
2248,
22176,
14,
67,
15,
1162,
14,
67,
199,
3,
199,
3,
961,
859,
9329,
14404,
282,
2013,
2897,
570,
436,
199,
3,
340,
9512,
12,
16864,
652,
1159,
4072,
370,
3839,
14,
3390,
626,
314,
199,
3,
3439,
365,
10585,
543,
10990,
11817,
737,
650,
14,
199,
3,
199,
3,
18491,
367,
282,
12530,
283,
7093,
1104,
7,
402,
282,
2897,
570,
14,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
31710,
199,
646,
31710,
14,
18907,
465,
1511,
199,
504,
31710,
14,
846,
1760,
492,
5817,
12,
14393,
12,
3207,
199,
199,
533,
2088,
63,
396,
22176,
8,
3110,
304,
272,
408,
16626,
1104,
314,
2897,
570,
1041,
339,
9560,
27573,
275,
2071,
6595,
359,
1419,
8480,
339,
6181,
63,
1422,
2634,
275,
469,
267,
298,
21693,
3291,
582,
1511,
14,
51,
14310,
4558,
12,
267,
298,
1023,
3291,
582,
1511,
14,
3353,
4558,
272,
789,
339,
6181,
63,
1419,
275,
359,
267,
3207,
6739,
2792,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
8407,
511,
22176,
370,
282,
4310,
3420,
1288,
267,
3207,
6739,
5329,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
8407,
511,
22176,
370,
282,
4310,
2725,
1288,
267,
3207,
6739,
1258,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
3041,
10237,
536,
367,
283,
5146,
2040,
7,
7907,
298,
490,
7340,
5626,
1336,
3837,
4237,
13185,
267,
3207,
6739,
1258,
13,
711,
401,
730,
29,
495,
12,
2049,
1720,
628,
3041,
3531,
2287,
367,
283,
5146,
2040,
7,
7907,
1288,
267,
3207,
6739,
17381,
13,
7650,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2049,
1720,
628,
18334,
8457,
367,
9509,
1288,
267,
3207,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
2049,
849,
29,
797,
12,
1720,
628,
6824,
849,
1511,
4634,
1288,
267,
327,
2136,
1929,
2291,
367,
22717,
14,
2190,
16954,
2544,
642,
911,
1736,
4020,
267,
3207,
6739,
1000,
401,
730,
29,
495,
12,
1720,
628,
1084,
450,
44,
9559,
370,
1654,
354,
1288,
267,
327,
5723,
787,
12159,
424,
370,
886,
543,
314,
892,
1233,
5523,
267,
3207,
6739,
2384,
13,
452,
13,
3214,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2049,
1720,
628,
6824,
314,
2633,
12,
730,
12,
3962,
1338,
531,
267,
1622,
339,
6181,
63,
589,
275,
942,
339,
347,
1255,
8,
277,
12,
31710,
3291,
12,
1015,
3291,
12,
3420,
63,
354,
29,
403,
12,
288,
2725,
63,
354,
29,
403,
12,
1890,
63,
711,
29,
403,
12,
1890,
63,
354,
29,
403,
12,
288,
3376,
29,
797,
12,
15678,
63,
7650,
29,
403,
12,
2498,
63,
452,
63,
3214,
29,
797,
12,
288,
1654,
29,
403,
304,
267,
340,
1654,
26,
288,
746,
4279,
6739,
1000,
440,
5966,
6366,
531,
267,
340,
2498,
63,
452,
63,
3214,
26,
288,
746,
4279,
6739,
2384,
13,
452,
13,
3214,
440,
5966,
6366,
531,
267,
340,
1890,
63,
354,
365,
440,
488,
436,
1890,
63,
711,
365,
488,
26,
288,
746,
14393,
480,
18088,
282,
10237,
536,
436,
376,
3531,
2287,
787,
298,
3044,
298,
2427,
367,
314,
1591,
2879,
1104,
531,
398,
862,
26,
288,
13204,
275,
31710,
3291,
14,
362,
63,
912,
22176,
342,
267,
871,
6064,
12,
2329,
26,
288,
746,
14393,
8,
1508,
9,
398,
327,
2136,
1929,
642,
370,
3542,
314,
1072,
267,
31710,
14,
409,
63,
1757,
63,
1896,
8,
18,
9,
398,
2512,
275,
291,
14,
362,
63,
2921,
480,
396,
22176,
531,
398,
2512,
14,
815,
480,
19757,
22717,
1101,
1584,
687,
450,
83,
401,
13204,
14,
29217,
9,
267,
2512,
14,
815,
480,
19757,
8500,
570,
9949,
2685,
398,
1686,
275,
291,
14,
1117,
63,
2966,
63,
8625,
8,
10343,
12,
2512,
9,
267,
1686,
275,
1686,
436,
291,
14,
1117,
63,
6251,
63,
8625,
8,
10343,
12,
2512,
9,
267,
340,
1890,
63,
354,
365,
440,
488,
436,
1890,
63,
711,
365,
440,
488,
26,
288,
291,
14,
1074,
63,
1258,
63,
2732,
8,
10343,
12,
2512,
12,
1890,
63,
354,
12,
1890,
63,
711,
9,
267,
587,
26,
288,
340,
3420,
63,
354,
365,
440,
488,
503,
2725,
63,
354,
365,
440,
488,
26,
355,
340,
2725,
63,
354,
365,
488,
26,
490,
13204,
59,
2792,
63,
354,
1055,
2724,
8,
1274,
14,
2703,
12,
13204,
14
] |
[
257,
13074,
2389,
34,
15,
3553,
7079,
4514,
14,
199,
3,
257,
1379,
25667,
402,
22717,
14,
2190,
199,
3,
257,
1898,
334,
35,
9,
7129,
13,
8128,
1603,
352,
2626,
5444,
889,
79,
7879,
665,
74,
352,
2626,
32,
21693,
14,
1308,
30,
199,
3,
199,
3,
21311,
641,
314,
3379,
315,
445,
26,
199,
3,
257,
1898,
334,
35,
9,
1804,
285,
76,
437,
14262,
9013,
19,
12,
9013,
20,
13,
23756,
199,
3,
257,
11524,
9840,
6042,
701,
6061,
5257,
377,
5562,
914,
12,
9013,
21,
199,
3,
257,
11801,
471,
370,
299,
2992,
701,
1603,
352,
2626,
5444,
889,
79,
7879,
334,
74,
352,
2626,
32,
7530,
14,
5135,
14,
1308,
395,
14790,
199,
3,
257,
6162,
68,
367,
428,
14310,
20,
701,
6061,
5257,
699,
580,
22784,
665,
371,
580,
2723,
32,
21693,
14,
1308,
30,
8315,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
3,
1379,
6123,
367,
2248,
22176,
14,
67,
15,
1162,
14,
67,
199,
3,
199,
3,
961,
859,
9329,
14404,
282,
2013,
2897,
570,
436,
199,
3,
340,
9512,
12,
16864,
652,
1159,
4072,
370,
3839,
14,
3390,
626,
314,
199,
3,
3439,
365,
10585,
543,
10990,
11817,
737,
650,
14,
199,
3,
199,
3,
18491,
367,
282,
12530,
283,
7093,
1104,
7,
402,
282,
2897,
570,
14,
199,
3,
199,
199,
646,
747,
199,
646,
984,
199,
199,
646,
31710,
199,
646,
31710,
14,
18907,
465,
1511,
199,
504,
31710,
14,
846,
1760,
492,
5817,
12,
14393,
12,
3207,
199,
199,
533,
2088,
63,
396,
22176,
8,
3110,
304,
272,
408,
16626,
1104,
314,
2897,
570,
1041,
339,
9560,
27573,
275,
2071,
6595,
359,
1419,
8480,
339,
6181,
63,
1422,
2634,
275,
469,
267,
298,
21693,
3291,
582,
1511,
14,
51,
14310,
4558,
12,
267,
298,
1023,
3291,
582,
1511,
14,
3353,
4558,
272,
789,
339,
6181,
63,
1419,
275,
359,
267,
3207,
6739,
2792,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
8407,
511,
22176,
370,
282,
4310,
3420,
1288,
267,
3207,
6739,
5329,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
8407,
511,
22176,
370,
282,
4310,
2725,
1288,
267,
3207,
6739,
1258,
13,
354,
401,
730,
29,
495,
12,
2049,
1720,
628,
3041,
10237,
536,
367,
283,
5146,
2040,
7,
7907,
298,
490,
7340,
5626,
1336,
3837,
4237,
13185,
267,
3207,
6739,
1258,
13,
711,
401,
730,
29,
495,
12,
2049,
1720,
628,
3041,
3531,
2287,
367,
283,
5146,
2040,
7,
7907,
1288,
267,
3207,
6739,
17381,
13,
7650,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2049,
1720,
628,
18334,
8457,
367,
9509,
1288,
267,
3207,
6096,
86,
401,
4320,
3832,
401,
1595,
628,
1617,
63,
2052,
401,
2049,
849,
29,
797,
12,
1720,
628,
6824,
849,
1511,
4634,
1288,
267,
327,
2136,
1929,
2291,
367,
22717,
14,
2190,
16954,
2544,
642,
911,
1736,
4020,
267,
3207,
6739,
1000,
401,
730,
29,
495,
12,
1720,
628,
1084,
450,
44,
9559,
370,
1654,
354,
1288,
267,
327,
5723,
787,
12159,
424,
370,
886,
543,
314,
892,
1233,
5523,
267,
3207,
6739,
2384,
13,
452,
13,
3214,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2049,
1720,
628,
6824,
314,
2633,
12,
730,
12,
3962,
1338,
531,
267,
1622,
339,
6181,
63,
589,
275,
942,
339,
347,
1255,
8,
277,
12,
31710,
3291,
12,
1015,
3291,
12,
3420,
63,
354,
29,
403,
12,
288,
2725,
63,
354,
29,
403,
12,
1890,
63,
711,
29,
403,
12,
1890,
63,
354,
29,
403,
12,
288,
3376,
29,
797,
12,
15678,
63,
7650,
29,
403,
12,
2498,
63,
452,
63,
3214,
29,
797,
12,
288,
1654,
29,
403,
304,
267,
340,
1654,
26,
288,
746,
4279,
6739,
1000,
440,
5966,
6366,
531,
267,
340,
2498,
63,
452,
63,
3214,
26,
288,
746,
4279,
6739,
2384,
13,
452,
13,
3214,
440,
5966,
6366,
531,
267,
340,
1890,
63,
354,
365,
440,
488,
436,
1890,
63,
711,
365,
488,
26,
288,
746,
14393,
480,
18088,
282,
10237,
536,
436,
376,
3531,
2287,
787,
298,
3044,
298,
2427,
367,
314,
1591,
2879,
1104,
531,
398,
862,
26,
288,
13204,
275,
31710,
3291,
14,
362,
63,
912,
22176,
342,
267,
871,
6064,
12,
2329,
26,
288,
746,
14393,
8,
1508,
9,
398,
327,
2136,
1929,
642,
370,
3542,
314,
1072,
267,
31710,
14,
409,
63,
1757,
63,
1896,
8,
18,
9,
398,
2512,
275,
291,
14,
362,
63,
2921,
480,
396,
22176,
531,
398,
2512,
14,
815,
480,
19757,
22717,
1101,
1584,
687,
450,
83,
401,
13204,
14,
29217,
9,
267,
2512,
14,
815,
480,
19757,
8500,
570,
9949,
2685,
398,
1686,
275,
291,
14,
1117,
63,
2966,
63,
8625,
8,
10343,
12,
2512,
9,
267,
1686,
275,
1686,
436,
291,
14,
1117,
63,
6251,
63,
8625,
8,
10343,
12,
2512,
9,
267,
340,
1890,
63,
354,
365,
440,
488,
436,
1890,
63,
711,
365,
440,
488,
26,
288,
291,
14,
1074,
63,
1258,
63,
2732,
8,
10343,
12,
2512,
12,
1890,
63,
354,
12,
1890,
63,
711,
9,
267,
587,
26,
288,
340,
3420,
63,
354,
365,
440,
488,
503,
2725,
63,
354,
365,
440,
488,
26,
355,
340,
2725,
63,
354,
365,
488,
26,
490,
13204,
59,
2792,
63,
354,
1055,
2724,
8,
1274,
14,
2703,
12,
13204,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
deokjinkim/servo
|
components/script/dom/bindings/codegen/parser/tests/test_nullable_equivalency.py
|
106
|
3835
|
import WebIDL
def WebIDLTest(parser, harness):
parser.parse("""
interface TestNullableEquivalency1 {
attribute long a;
attribute long? b;
};
interface TestNullableEquivalency2 {
attribute ArrayBuffer a;
attribute ArrayBuffer? b;
};
/* Can't have dictionary-valued attributes, so can't test that here */
enum TestNullableEquivalency4Enum {
"Foo",
"Bar"
};
interface TestNullableEquivalency4 {
attribute TestNullableEquivalency4Enum a;
attribute TestNullableEquivalency4Enum? b;
};
interface TestNullableEquivalency5 {
attribute TestNullableEquivalency4 a;
attribute TestNullableEquivalency4? b;
};
interface TestNullableEquivalency6 {
attribute boolean a;
attribute boolean? b;
};
interface TestNullableEquivalency7 {
attribute DOMString a;
attribute DOMString? b;
};
/* Not implemented. */
/*interface TestNullableEquivalency8 {
attribute float a;
attribute float? b;
};*/
interface TestNullableEquivalency8 {
attribute double a;
attribute double? b;
};
interface TestNullableEquivalency9 {
attribute object a;
attribute object? b;
};
interface TestNullableEquivalency10 {
attribute double[] a;
attribute double[]? b;
};
interface TestNullableEquivalency11 {
attribute TestNullableEquivalency9[] a;
attribute TestNullableEquivalency9[]? b;
};
""")
for decl in parser.finish():
if decl.isInterface():
checkEquivalent(decl, harness)
def checkEquivalent(iface, harness):
type1 = iface.members[0].type
type2 = iface.members[1].type
harness.check(type1.nullable(), False, 'attr1 should not be nullable')
harness.check(type2.nullable(), True, 'attr2 should be nullable')
# We don't know about type1, but type2, the nullable type, definitely
# shouldn't be builtin.
harness.check(type2.builtin, False, 'attr2 should not be builtin')
# Ensure that all attributes of type2 match those in type1, except for:
# - names on an ignore list,
# - names beginning with '_',
# - functions which throw when called with no args, and
# - class-level non-callables ("static variables").
#
# Yes, this is an ugly, fragile hack. But it finds bugs...
for attr in dir(type1):
if attr.startswith('_') or \
attr in ['nullable', 'builtin', 'filename', 'location',
'inner', 'QName'] or \
(hasattr(type(type1), attr) and not callable(getattr(type1, attr))):
continue
a1 = getattr(type1, attr)
if callable(a1):
try:
v1 = a1()
except:
# Can't call a1 with no args, so skip this attriute.
continue
try:
a2 = getattr(type2, attr)
except:
harness.ok(False, 'Missing %s attribute on type %s in %s' % (attr, type2, iface))
continue
if not callable(a2):
harness.ok(False, "%s attribute on type %s in %s wasn't callable" % (attr, type2, iface))
continue
v2 = a2()
harness.check(v2, v1, '%s method return value' % attr)
else:
try:
a2 = getattr(type2, attr)
except:
harness.ok(False, 'Missing %s attribute on type %s in %s' % (attr, type2, iface))
continue
harness.check(a2, a1, '%s attribute should match' % attr)
|
mpl-2.0
|
[
646,
22817,
199,
199,
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
1798,
14,
1122,
4852,
267,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
17,
469,
881,
2225,
1846,
221,
282,
27,
881,
2225,
1846,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
18,
469,
881,
2225,
8725,
3299,
221,
282,
27,
881,
2225,
8725,
3299,
31,
330,
27,
267,
16735,
398,
13505,
6855,
1133,
1172,
2600,
13,
16611,
3004,
12,
880,
883,
1133,
511,
626,
2348,
11589,
398,
4952,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
469,
881,
298,
5686,
401,
881,
298,
5281,
2,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
21,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
22,
469,
881,
2225,
5046,
221,
282,
27,
881,
2225,
5046,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
23,
469,
881,
2225,
14316,
1558,
221,
282,
27,
881,
2225,
14316,
1558,
31,
330,
27,
267,
16735,
398,
13505,
2832,
6366,
14,
11589,
267,
13505,
3266,
1379,
8849,
461,
37,
20571,
552,
1480,
24,
469,
881,
2225,
2069,
221,
282,
27,
881,
2225,
2069,
31,
330,
27,
267,
16735,
15870,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
24,
469,
881,
2225,
4270,
221,
282,
27,
881,
2225,
4270,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
469,
881,
2225,
909,
221,
282,
27,
881,
2225,
909,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
709,
469,
881,
2225,
4270,
8607,
221,
282,
27,
881,
2225,
4270,
8607,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
845,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
8607,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
8607,
31,
330,
27,
267,
16735,
272,
7857,
339,
367,
15021,
315,
1798,
14,
8192,
837,
267,
340,
15021,
14,
374,
4267,
837,
288,
1104,
37,
6190,
8,
9427,
12,
20458,
9,
199,
199,
318,
1104,
37,
6190,
8,
11166,
12,
20458,
304,
272,
730,
17,
275,
13395,
14,
6334,
59,
16,
1055,
466,
272,
730,
18,
275,
13395,
14,
6334,
59,
17,
1055,
466,
339,
20458,
14,
1074,
8,
466,
17,
14,
16375,
1062,
756,
12,
283,
962,
17,
1077,
440,
506,
7854,
358,
272,
20458,
14,
1074,
8,
466,
18,
14,
16375,
1062,
715,
12,
283,
962,
18,
1077,
506,
7854,
358,
339,
327,
2136,
2793,
1133,
5715,
3595,
730,
17,
12,
1325,
730,
18,
12,
314,
7854,
730,
12,
28088,
590,
272,
327,
9296,
1133,
506,
6762,
14,
272,
20458,
14,
1074,
8,
466,
18,
14,
5351,
12,
756,
12,
283,
962,
18,
1077,
440,
506,
6762,
358,
339,
327,
7523,
626,
1006,
3004,
402,
730,
18,
1336,
5204,
315,
730,
17,
12,
871,
367,
26,
272,
327,
221,
446,
1561,
641,
376,
3686,
769,
12,
272,
327,
221,
446,
1561,
9608,
543,
25469,
272,
327,
221,
446,
3423,
1314,
7978,
1380,
2797,
543,
949,
1249,
12,
436,
272,
327,
221,
446,
1021,
13,
1896,
2222,
13,
1250,
5921,
1689,
1986,
2860,
3471,
272,
327,
272,
327,
29715,
12,
642,
365,
376,
23761,
12,
11101,
441,
11176,
14,
221,
11017,
652,
17651,
18227,
1396,
272,
367,
1921,
315,
2935,
8,
466,
17,
304,
267,
340,
1921,
14,
2460,
26341,
503,
971,
1779,
1921,
315,
788,
16375,
297,
283,
5351,
297,
283,
1501,
297,
283,
1985,
297,
490,
283,
5216,
297,
283,
28105,
418,
503,
971,
1779,
334,
11161,
8,
466,
8,
466,
17,
395,
1921,
9,
436,
440,
4550,
8,
5675,
8,
466,
17,
12,
1921,
15206,
288,
1980,
398,
282,
17,
275,
2519,
8,
466,
17,
12,
1921,
9,
398,
340,
4550,
8,
65,
17,
304,
288,
862,
26,
355,
373,
17,
275,
282,
17,
342,
288,
871,
26,
355,
327,
6855,
1133,
1240,
282,
17,
543,
949,
1249,
12,
880,
3372,
642,
737,
599,
938,
14,
355,
1980,
953,
862,
26,
355,
282,
18,
275,
2519,
8,
466,
18,
12,
1921,
9,
288,
871,
26,
355,
20458,
14,
745,
8,
797,
12,
283,
7718,
450,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
7,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
340,
440,
4550,
8,
65,
18,
304,
355,
20458,
14,
745,
8,
797,
12,
2071,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
17373,
1133,
4550,
2,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
373,
18,
275,
282,
18,
342,
288,
20458,
14,
1074,
8,
86,
18,
12,
373,
17,
12,
1543,
83,
1083,
372,
574,
7,
450,
1921,
9,
267,
587,
26,
288,
862,
26,
355,
282,
18,
275,
2519,
8,
466,
18,
12,
1921,
9,
288,
871,
26,
355,
20458,
14,
745,
8,
797,
12,
283,
7718,
450,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
7,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
20458,
14,
1074,
8,
65,
18,
12,
282,
17,
12,
1543,
83,
2225,
1077,
1336,
7,
450,
1921,
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
] |
[
22817,
199,
199,
318,
22817,
774,
8,
2087,
12,
20458,
304,
272,
1798,
14,
1122,
4852,
267,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
17,
469,
881,
2225,
1846,
221,
282,
27,
881,
2225,
1846,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
18,
469,
881,
2225,
8725,
3299,
221,
282,
27,
881,
2225,
8725,
3299,
31,
330,
27,
267,
16735,
398,
13505,
6855,
1133,
1172,
2600,
13,
16611,
3004,
12,
880,
883,
1133,
511,
626,
2348,
11589,
398,
4952,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
469,
881,
298,
5686,
401,
881,
298,
5281,
2,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
5081,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
21,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
20,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
22,
469,
881,
2225,
5046,
221,
282,
27,
881,
2225,
5046,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
23,
469,
881,
2225,
14316,
1558,
221,
282,
27,
881,
2225,
14316,
1558,
31,
330,
27,
267,
16735,
398,
13505,
2832,
6366,
14,
11589,
267,
13505,
3266,
1379,
8849,
461,
37,
20571,
552,
1480,
24,
469,
881,
2225,
2069,
221,
282,
27,
881,
2225,
2069,
31,
330,
27,
267,
16735,
15870,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
24,
469,
881,
2225,
4270,
221,
282,
27,
881,
2225,
4270,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
469,
881,
2225,
909,
221,
282,
27,
881,
2225,
909,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
709,
469,
881,
2225,
4270,
8607,
221,
282,
27,
881,
2225,
4270,
8607,
31,
330,
27,
267,
16735,
398,
3217,
1379,
8849,
461,
37,
20571,
552,
1480,
845,
469,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
8607,
221,
282,
27,
881,
2225,
1379,
8849,
461,
37,
20571,
552,
1480,
25,
8607,
31,
330,
27,
267,
16735,
272,
7857,
339,
367,
15021,
315,
1798,
14,
8192,
837,
267,
340,
15021,
14,
374,
4267,
837,
288,
1104,
37,
6190,
8,
9427,
12,
20458,
9,
199,
199,
318,
1104,
37,
6190,
8,
11166,
12,
20458,
304,
272,
730,
17,
275,
13395,
14,
6334,
59,
16,
1055,
466,
272,
730,
18,
275,
13395,
14,
6334,
59,
17,
1055,
466,
339,
20458,
14,
1074,
8,
466,
17,
14,
16375,
1062,
756,
12,
283,
962,
17,
1077,
440,
506,
7854,
358,
272,
20458,
14,
1074,
8,
466,
18,
14,
16375,
1062,
715,
12,
283,
962,
18,
1077,
506,
7854,
358,
339,
327,
2136,
2793,
1133,
5715,
3595,
730,
17,
12,
1325,
730,
18,
12,
314,
7854,
730,
12,
28088,
590,
272,
327,
9296,
1133,
506,
6762,
14,
272,
20458,
14,
1074,
8,
466,
18,
14,
5351,
12,
756,
12,
283,
962,
18,
1077,
440,
506,
6762,
358,
339,
327,
7523,
626,
1006,
3004,
402,
730,
18,
1336,
5204,
315,
730,
17,
12,
871,
367,
26,
272,
327,
221,
446,
1561,
641,
376,
3686,
769,
12,
272,
327,
221,
446,
1561,
9608,
543,
25469,
272,
327,
221,
446,
3423,
1314,
7978,
1380,
2797,
543,
949,
1249,
12,
436,
272,
327,
221,
446,
1021,
13,
1896,
2222,
13,
1250,
5921,
1689,
1986,
2860,
3471,
272,
327,
272,
327,
29715,
12,
642,
365,
376,
23761,
12,
11101,
441,
11176,
14,
221,
11017,
652,
17651,
18227,
1396,
272,
367,
1921,
315,
2935,
8,
466,
17,
304,
267,
340,
1921,
14,
2460,
26341,
503,
971,
1779,
1921,
315,
788,
16375,
297,
283,
5351,
297,
283,
1501,
297,
283,
1985,
297,
490,
283,
5216,
297,
283,
28105,
418,
503,
971,
1779,
334,
11161,
8,
466,
8,
466,
17,
395,
1921,
9,
436,
440,
4550,
8,
5675,
8,
466,
17,
12,
1921,
15206,
288,
1980,
398,
282,
17,
275,
2519,
8,
466,
17,
12,
1921,
9,
398,
340,
4550,
8,
65,
17,
304,
288,
862,
26,
355,
373,
17,
275,
282,
17,
342,
288,
871,
26,
355,
327,
6855,
1133,
1240,
282,
17,
543,
949,
1249,
12,
880,
3372,
642,
737,
599,
938,
14,
355,
1980,
953,
862,
26,
355,
282,
18,
275,
2519,
8,
466,
18,
12,
1921,
9,
288,
871,
26,
355,
20458,
14,
745,
8,
797,
12,
283,
7718,
450,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
7,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
340,
440,
4550,
8,
65,
18,
304,
355,
20458,
14,
745,
8,
797,
12,
2071,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
17373,
1133,
4550,
2,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
373,
18,
275,
282,
18,
342,
288,
20458,
14,
1074,
8,
86,
18,
12,
373,
17,
12,
1543,
83,
1083,
372,
574,
7,
450,
1921,
9,
267,
587,
26,
288,
862,
26,
355,
282,
18,
275,
2519,
8,
466,
18,
12,
1921,
9,
288,
871,
26,
355,
20458,
14,
745,
8,
797,
12,
283,
7718,
450,
83,
2225,
641,
730,
450,
83,
315,
450,
83,
7,
450,
334,
962,
12,
730,
18,
12,
13395,
430,
355,
1980,
953,
20458,
14,
1074,
8,
65,
18,
12,
282,
17,
12,
1543,
83,
2225,
1077,
1336,
7,
450,
1921,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
freynaud/selenium
|
py/test/selenium/webdriver/support/event_firing_webdriver_tests.py
|
9
|
8182
|
#!/usr/bin/python
# Copyright 2011 Software Freedom Conservancy.
#
# 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 unittest
try:
from io import BytesIO
except ImportError:
from cStringIO import StringIO as BytesIO
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.events import EventFiringWebDriver, \
AbstractEventListener
class EventFiringWebDriverTests(unittest.TestCase):
def setup_method(self, method):
self.log = BytesIO()
def test_should_fire_navigation_events(self):
log = self.log
class TestListener(AbstractEventListener):
def before_navigate_to(self, url, driver):
log.write(("before_navigate_to %s" % url.split("/")[-1]).encode())
def after_navigate_to(self, url, driver):
log.write(("after_navigate_to %s" % url.split("/")[-1]).encode())
def before_navigate_back(self, driver):
log.write(b"before_navigate_back")
def after_navigate_back(self, driver):
log.write(b"after_navigate_back")
def before_navigate_forward(self, driver):
log.write(b"before_navigate_forward")
def after_navigate_forward(self, driver):
log.write(b"after_navigate_forward")
ef_driver = EventFiringWebDriver(self.driver, TestListener())
ef_driver.get(self._pageURL("formPage"))
ef_driver.find_element(by=By.ID, value="imageButton").submit()
self.assertEqual(ef_driver.title, "We Arrive Here")
ef_driver.back()
self.assertEqual(ef_driver.title, "We Leave From Here")
ef_driver.forward()
self.assertEqual(ef_driver.title, "We Arrive Here")
self.assertEqual(b"before_navigate_to formPage.html" \
+ b"after_navigate_to formPage.html" \
+ b"before_navigate_back" \
+ b"after_navigate_back" \
+ b"before_navigate_forward" \
+ b"after_navigate_forward", log.getvalue())
def test_should_fire_click_event(self):
log = self.log
class TestListener(AbstractEventListener):
def before_click(self, element, driver):
log.write(b"before_click")
def after_click(self, element, driver):
log.write(b"after_click")
ef_driver = EventFiringWebDriver(self.driver, TestListener())
ef_driver.get(self._pageURL("clicks"))
ef_driver.find_element(By.ID, "overflowLink").click()
self.assertEqual(ef_driver.title, "XHTML Test Page")
self.assertEqual(b"before_click" + b"after_click", log.getvalue())
def test_should_fire_change_value_event(self):
log = self.log
class TestListener(AbstractEventListener):
def before_change_value_of(self, element, driver):
log.write(b"before_change_value_of")
def after_change_value_of(self, element, driver):
log.write(b"after_change_value_of")
ef_driver = EventFiringWebDriver(self.driver, TestListener())
ef_driver.get(self._pageURL("readOnlyPage"))
element = ef_driver.find_element_by_id("writableTextInput")
element.clear()
self.assertEqual("", element.get_attribute("value"))
ef_driver.get(self._pageURL("javascriptPage"))
keyReporter = ef_driver.find_element(by=By.ID, value="keyReporter")
keyReporter.send_keys("abc def")
self.assertEqual(keyReporter.get_attribute("value"), "abc def")
self.assertEqual(b"before_change_value_of" \
+ b"after_change_value_of" \
+ b"before_change_value_of" \
+ b"after_change_value_of", log.getvalue())
def test_should_fire_find_event(self):
log = self.log
class TestListener(AbstractEventListener):
def before_find(self, by, value, driver):
log.write(("before_find by %s %s" % (by, value)).encode())
def after_find(self, by, value, driver):
log.write(("after_find by %s %s" % (by, value)).encode())
ef_driver = EventFiringWebDriver(self.driver, TestListener())
ef_driver.get(self._pageURL("simpleTest"))
e = ef_driver.find_element_by_id("oneline")
self.assertEqual("A single line of text", e.text)
e = ef_driver.find_element_by_xpath("/html/body/p[1]")
self.assertEqual("A single line of text", e.text)
ef_driver.get(self._pageURL("frameset"))
elements = ef_driver.find_elements_by_css_selector("frame#sixth")
self.assertEqual(1, len(elements))
self.assertEqual("frame", elements[0].tag_name.lower())
self.assertEqual("sixth", elements[0].get_attribute("id"))
self.assertEqual(b"before_find by id oneline" \
+ b"after_find by id oneline" \
+ b"before_find by xpath /html/body/p[1]" \
+ b"after_find by xpath /html/body/p[1]" \
+ b"before_find by css selector frame#sixth" \
+ b"after_find by css selector frame#sixth" , log.getvalue())
def test_should_call_listener_when_an_exception_is_thrown(self):
log = self.log
class TestListener(AbstractEventListener):
def on_exception(self, exception, driver):
if isinstance(exception, NoSuchElementException):
log.write(b"NoSuchElementException is thrown")
ef_driver = EventFiringWebDriver(self.driver, TestListener())
ef_driver.get(self._pageURL("simpleTest"))
try:
ef_driver.find_element(By.ID, "foo")
self.fail("Expected exception to be propagated")
except NoSuchElementException:
pass
self.assertEqual(b"NoSuchElementException is thrown", log.getvalue())
def test_should_unwrap_element_args_when_calling_scripts(self):
ef_driver = EventFiringWebDriver(self.driver, AbstractEventListener())
ef_driver.get(self._pageURL("javascriptPage"))
button = ef_driver.find_element_by_id("plainButton")
value = ef_driver.execute_script(
"arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble']",
button)
self.assertEqual("plainButton", value)
def test_should_be_able_to_access_wrapped_instance_from_event_calls(self):
driver = self.driver
class TestListener(AbstractEventListener):
def before_navigate_to(self, url, d):
assert driver is d
ef_driver = EventFiringWebDriver(driver, TestListener())
wrapped_driver = ef_driver.wrapped_driver
assert driver is wrapped_driver
ef_driver.get(self._pageURL("simpleTest"))
def teardown_method(self, method):
self.log.close()
def _pageURL(self, name):
return "http://localhost:%d/%s.html" % (self.webserver.port, name)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
7760,
2290,
481,
3798,
676,
1448,
7297,
9844,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
893,
26,
272,
687,
5890,
492,
11808,
199,
2590,
3545,
26,
272,
687,
15073,
492,
5228,
465,
11808,
199,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
504,
19481,
14,
17946,
14,
4058,
14,
4368,
492,
6763,
38,
16648,
27009,
12,
971,
8105,
11836,
2390,
10464,
9349,
199,
199,
533,
6763,
38,
16648,
27009,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
291,
14,
793,
275,
11808,
342,
5493,
347,
511,
63,
5626,
63,
8935,
63,
24148,
63,
4368,
8,
277,
304,
267,
943,
275,
291,
14,
793,
20169,
267,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
288,
347,
2544,
63,
15595,
3237,
63,
475,
8,
277,
12,
1166,
12,
5253,
304,
355,
943,
14,
952,
9313,
5182,
63,
15595,
3237,
63,
475,
450,
83,
2,
450,
1166,
14,
1294,
19031,
1988,
17,
6575,
2143,
1012,
288,
347,
2410,
63,
15595,
3237,
63,
475,
8,
277,
12,
1166,
12,
5253,
304,
355,
943,
14,
952,
9313,
4399,
63,
15595,
3237,
63,
475,
450,
83,
2,
450,
1166,
14,
1294,
19031,
1988,
17,
6575,
2143,
1012,
288,
347,
2544,
63,
15595,
3237,
63,
894,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
15595,
3237,
63,
894,
531,
288,
347,
2410,
63,
15595,
3237,
63,
894,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
15595,
3237,
63,
894,
531,
288,
347,
2544,
63,
15595,
3237,
63,
6688,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
15595,
3237,
63,
6688,
531,
288,
347,
2410,
63,
15595,
3237,
63,
6688,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
15595,
3237,
63,
6688,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
964,
3276,
2237,
267,
9530,
63,
3090,
14,
1623,
63,
2108,
8,
991,
29,
2175,
14,
998,
12,
574,
628,
1569,
4259,
3471,
7275,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
1952,
6053,
11842,
531,
398,
9530,
63,
3090,
14,
894,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
28015,
11606,
11842,
531,
398,
9530,
63,
3090,
14,
6688,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
1952,
6053,
11842,
531,
18418,
267,
291,
14,
629,
8,
66,
2,
5182,
63,
15595,
3237,
63,
475,
1824,
3276,
14,
1360,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
475,
1824,
3276,
14,
1360,
2,
971,
355,
435,
330,
2,
5182,
63,
15595,
3237,
63,
894,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
894,
2,
971,
355,
435,
330,
2,
5182,
63,
15595,
3237,
63,
6688,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
6688,
401,
943,
14,
7150,
1012,
339,
347,
511,
63,
5626,
63,
8935,
63,
4891,
63,
1430,
8,
277,
304,
267,
943,
275,
291,
14,
793,
2728,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
3777,
288,
347,
2544,
63,
4891,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
4891,
531,
288,
347,
2410,
63,
4891,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
4891,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
4891,
83,
2237,
18418,
9530,
63,
3090,
14,
1623,
63,
2108,
8,
2175,
14,
998,
12,
298,
14108,
3834,
3471,
4891,
342,
4960,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
56,
4943,
1379,
10331,
531,
2728,
291,
14,
629,
8,
66,
2,
5182,
63,
4891,
2,
435,
330,
2,
4399,
63,
4891,
401,
943,
14,
7150,
1012,
5493,
347,
511,
63,
5626,
63,
8935,
63,
1461,
63,
585,
63,
1430,
8,
277,
304,
267,
943,
275,
291,
14,
793,
2728,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
3777,
288,
347,
2544,
63,
1461,
63,
585,
63,
1618,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
1461,
63,
585,
63,
1618,
531,
288,
347,
2410,
63,
1461,
63,
585,
63,
1618,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
1461,
63,
585,
63,
1618,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
739,
5903,
3276,
2237,
463,
267,
1819,
275,
9530,
63,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
15053,
18362,
531,
267,
1819,
14,
3584,
342,
267,
291,
14,
629,
12398,
1819,
14,
362,
63,
3215,
480,
585,
2237,
2728,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
9554,
3276,
2237,
267,
790,
15891,
275,
9530,
63,
3090
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
7760,
2290,
481,
3798,
676,
1448,
7297,
9844,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2882,
199,
893,
26,
272,
687,
5890,
492,
11808,
199,
2590,
3545,
26,
272,
687,
15073,
492,
5228,
465,
11808,
199,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
504,
19481,
14,
17946,
14,
4058,
14,
4368,
492,
6763,
38,
16648,
27009,
12,
971,
8105,
11836,
2390,
10464,
9349,
199,
199,
533,
6763,
38,
16648,
27009,
2925,
8,
2796,
14,
1746,
304,
339,
347,
3272,
63,
765,
8,
277,
12,
1083,
304,
267,
291,
14,
793,
275,
11808,
342,
5493,
347,
511,
63,
5626,
63,
8935,
63,
24148,
63,
4368,
8,
277,
304,
267,
943,
275,
291,
14,
793,
20169,
267,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
288,
347,
2544,
63,
15595,
3237,
63,
475,
8,
277,
12,
1166,
12,
5253,
304,
355,
943,
14,
952,
9313,
5182,
63,
15595,
3237,
63,
475,
450,
83,
2,
450,
1166,
14,
1294,
19031,
1988,
17,
6575,
2143,
1012,
288,
347,
2410,
63,
15595,
3237,
63,
475,
8,
277,
12,
1166,
12,
5253,
304,
355,
943,
14,
952,
9313,
4399,
63,
15595,
3237,
63,
475,
450,
83,
2,
450,
1166,
14,
1294,
19031,
1988,
17,
6575,
2143,
1012,
288,
347,
2544,
63,
15595,
3237,
63,
894,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
15595,
3237,
63,
894,
531,
288,
347,
2410,
63,
15595,
3237,
63,
894,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
15595,
3237,
63,
894,
531,
288,
347,
2544,
63,
15595,
3237,
63,
6688,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
15595,
3237,
63,
6688,
531,
288,
347,
2410,
63,
15595,
3237,
63,
6688,
8,
277,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
15595,
3237,
63,
6688,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
964,
3276,
2237,
267,
9530,
63,
3090,
14,
1623,
63,
2108,
8,
991,
29,
2175,
14,
998,
12,
574,
628,
1569,
4259,
3471,
7275,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
1952,
6053,
11842,
531,
398,
9530,
63,
3090,
14,
894,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
28015,
11606,
11842,
531,
398,
9530,
63,
3090,
14,
6688,
342,
267,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
6004,
1952,
6053,
11842,
531,
18418,
267,
291,
14,
629,
8,
66,
2,
5182,
63,
15595,
3237,
63,
475,
1824,
3276,
14,
1360,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
475,
1824,
3276,
14,
1360,
2,
971,
355,
435,
330,
2,
5182,
63,
15595,
3237,
63,
894,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
894,
2,
971,
355,
435,
330,
2,
5182,
63,
15595,
3237,
63,
6688,
2,
971,
355,
435,
330,
2,
4399,
63,
15595,
3237,
63,
6688,
401,
943,
14,
7150,
1012,
339,
347,
511,
63,
5626,
63,
8935,
63,
4891,
63,
1430,
8,
277,
304,
267,
943,
275,
291,
14,
793,
2728,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
3777,
288,
347,
2544,
63,
4891,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
4891,
531,
288,
347,
2410,
63,
4891,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
4891,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
4891,
83,
2237,
18418,
9530,
63,
3090,
14,
1623,
63,
2108,
8,
2175,
14,
998,
12,
298,
14108,
3834,
3471,
4891,
342,
4960,
291,
14,
629,
8,
2829,
63,
3090,
14,
1213,
12,
298,
56,
4943,
1379,
10331,
531,
2728,
291,
14,
629,
8,
66,
2,
5182,
63,
4891,
2,
435,
330,
2,
4399,
63,
4891,
401,
943,
14,
7150,
1012,
5493,
347,
511,
63,
5626,
63,
8935,
63,
1461,
63,
585,
63,
1430,
8,
277,
304,
267,
943,
275,
291,
14,
793,
2728,
1021,
1379,
10464,
8,
8458,
2390,
10464,
304,
3777,
288,
347,
2544,
63,
1461,
63,
585,
63,
1618,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
5182,
63,
1461,
63,
585,
63,
1618,
531,
288,
347,
2410,
63,
1461,
63,
585,
63,
1618,
8,
277,
12,
1819,
12,
5253,
304,
355,
943,
14,
952,
8,
66,
2,
4399,
63,
1461,
63,
585,
63,
1618,
531,
10631,
9530,
63,
3090,
275,
6763,
38,
16648,
27009,
8,
277,
14,
3090,
12,
1379,
10464,
1012,
3777,
267,
9530,
63,
3090,
14,
362,
8,
277,
423,
1606,
2632,
480,
739,
5903,
3276,
2237,
463,
267,
1819,
275,
9530,
63,
3090,
14,
1623,
63,
2108,
63,
991,
63,
344,
480,
15053,
18362,
531,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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
] |
axelspringer/ansible-modules-core
|
cloud/openstack/os_object.py
|
58
|
4111
|
#!/usr/bin/python
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
# Copyright (c) 2013, Benno Joy <benno@ansible.com>
#
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
DOCUMENTATION = '''
---
module: os_object
short_description: Create or Delete objects and containers from OpenStack
version_added: "2.0"
author: "Monty Taylor (@emonty)"
extends_documentation_fragment: openstack
description:
- Create or Delete objects and containers from OpenStack
options:
container:
description:
- The name of the container in which to create the object
required: true
name:
description:
- Name to be give to the object. If omitted, operations will be on
the entire container
required: false
filename:
description:
- Path to local file to be uploaded.
required: false
container_access:
description:
- desired container access level.
required: false
choices: ['private', 'public']
default: private
state:
description:
- Should the resource be present or absent.
choices: [present, absent]
default: present
'''
EXAMPLES = '''
# Creates a object named 'fstab' in the 'config' container
- os_object: cloud=mordred state=present name=fstab container=config filename=/etc/fstab
# Deletes a container called config and all of its contents
- os_object: cloud=rax-iad state=absent container=config
'''
def process_object(
cloud_obj, container, name, filename, container_access, **kwargs):
changed = False
container_obj = cloud_obj.get_container(container)
if kwargs['state'] == 'present':
if not container_obj:
container_obj = cloud_obj.create_container(container)
changed = True
if cloud_obj.get_container_access(container) != container_access:
cloud_obj.set_container_access(container, container_access)
changed = True
if name:
if cloud_obj.is_object_stale(container, name, filename):
cloud_obj.create_object(container, name, filename)
changed = True
else:
if container_obj:
if name:
if cloud_obj.get_object_metadata(container, name):
cloud_obj.delete_object(container, name)
changed= True
else:
cloud_obj.delete_container(container)
changed= True
return changed
def main():
argument_spec = openstack_full_argument_spec(
name=dict(required=False, default=None),
container=dict(required=True),
filename=dict(required=False, default=None),
container_access=dict(default='private', choices=['private', 'public']),
state=dict(default='present', choices=['absent', 'present']),
)
module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
try:
cloud = shade.openstack_cloud(**module.params)
changed = process_object(cloud, **module.params)
module.exit_json(changed=changed)
except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e))
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import *
from ansible.module_utils.openstack import *
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1898,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
32250,
272,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
785,
199,
3612,
63,
1802,
26,
2790,
503,
8496,
2251,
436,
15333,
687,
14260,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
6671,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1802,
26,
2043,
446,
2790,
503,
8496,
2251,
436,
15333,
687,
14260,
199,
1419,
26,
2043,
3970,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
3970,
315,
1314,
370,
1218,
314,
909,
1362,
1415,
26,
2549,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
370,
506,
8120,
370,
314,
909,
14,
982,
11684,
12,
5331,
911,
506,
641,
881,
314,
8039,
3970,
1362,
1415,
26,
3055,
2043,
1788,
26,
1362,
1369,
26,
267,
446,
6912,
370,
2257,
570,
370,
506,
14238,
14,
1362,
1415,
26,
3055,
2043,
3970,
63,
2732,
26,
1362,
1369,
26,
267,
446,
6387,
3970,
2879,
2166,
14,
1362,
1415,
26,
3055,
1362,
3415,
26,
788,
4239,
297,
283,
3455,
418,
1362,
849,
26,
5726,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
849,
26,
3451,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
10560,
282,
909,
4310,
283,
15624,
371,
7,
315,
314,
283,
888,
7,
3970,
199,
13,
747,
63,
785,
26,
8002,
29,
77,
2181,
581,
1174,
29,
1881,
536,
29,
15624,
371,
3970,
29,
888,
1788,
13043,
6839,
15,
15624,
371,
199,
199,
3,
28382,
282,
3970,
2797,
1101,
436,
1006,
402,
2399,
4072,
199,
13,
747,
63,
785,
26,
8002,
29,
14495,
13,
73,
350,
1174,
29,
5575,
3970,
29,
888,
199,
2344,
421,
199,
318,
2112,
63,
785,
8,
267,
8002,
63,
1113,
12,
3970,
12,
536,
12,
1788,
12,
3970,
63,
2732,
12,
1011,
958,
304,
339,
2896,
275,
756,
272,
3970,
63,
1113,
275,
8002,
63,
1113,
14,
362,
63,
3600,
8,
3600,
9,
272,
340,
2074,
459,
929,
418,
508,
283,
1881,
356,
267,
340,
440,
3970,
63,
1113,
26,
288,
3970,
63,
1113,
275,
8002,
63,
1113,
14,
981,
63,
3600,
8,
3600,
9,
288,
2896,
275,
715,
267,
340,
8002,
63,
1113,
14,
362,
63,
3600,
63,
2732,
8,
3600,
9,
1137,
3970,
63,
2732,
26,
288,
8002,
63,
1113,
14,
409,
63,
3600,
63,
2732,
8,
3600,
12,
3970,
63,
2732,
9,
288,
2896,
275,
715,
267,
340,
536,
26,
288,
340,
8002,
63,
1113,
14,
374,
63,
785,
63,
20102,
8,
3600,
12,
536,
12,
1788,
304,
355,
8002,
63,
1113,
14,
981,
63,
785,
8,
3600,
12,
536,
12,
1788,
9,
355,
2896,
275,
715,
272,
587,
26,
267,
340,
3970,
63,
1113,
26,
288,
340,
536,
26,
355,
340,
8002,
63,
1113,
14,
362,
63,
785,
63,
2343,
8,
3600,
12,
536,
304,
2116,
8002,
63,
1113,
14,
1807,
63,
785,
8,
3600,
12,
536,
9,
355,
2896,
29,
715,
288,
587,
26,
355,
8002,
63,
1113,
14,
1807,
63,
3600,
8,
3600,
9,
355,
2896,
29,
715,
272,
372,
2896,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
3970,
29,
807,
8,
2427,
29,
549,
395,
267,
1788,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
3970,
63,
2732,
29,
807,
8,
885,
534,
4239,
297,
3415,
2968,
4239,
297,
283,
3455,
3815,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
272,
776,
272,
859,
63,
958,
275,
13869,
63,
578,
63,
958,
342,
272,
859,
275,
6953,
8,
2094,
63,
1650,
12,
1011,
578,
63,
958,
9,
339,
340,
440,
7509,
63,
8461,
1093,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
31170,
365,
1415,
367,
642,
859,
358,
339,
862,
26,
267,
8002,
275,
32250,
14,
8512,
63,
4091,
3682,
578,
14,
1162,
9,
398,
2896,
275,
2112,
63,
785,
8,
4091,
12,
1011,
578,
14,
1162,
9,
398,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
9,
272,
871,
32250,
14,
26208,
9089,
1726,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
199,
199,
3,
642,
365,
10628,
12,
1937,
1973,
15,
4853,
15,
578,
63,
2330,
14,
647,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
627,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
1898,
334,
67,
9,
6900,
27849,
13,
29471,
15290,
15878,
12,
491,
14,
48,
14,
199,
3,
1898,
334,
67,
9,
6171,
12,
26844,
889,
7135,
89,
665,
18486,
889,
32,
4853,
14,
957,
30,
199,
3,
199,
3,
961,
859,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2032,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2032,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
893,
26,
272,
492,
32250,
272,
7509,
63,
8461,
1093,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
8461,
1093,
275,
756,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
747,
63,
785,
199,
3612,
63,
1802,
26,
2790,
503,
8496,
2251,
436,
15333,
687,
14260,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
298,
6671,
369,
377,
1187,
25339,
8593,
69,
2106,
369,
2924,
199,
11036,
63,
9970,
63,
7677,
26,
13869,
199,
1802,
26,
2043,
446,
2790,
503,
8496,
2251,
436,
15333,
687,
14260,
199,
1419,
26,
2043,
3970,
26,
1362,
1369,
26,
267,
446,
710,
536,
402,
314,
3970,
315,
1314,
370,
1218,
314,
909,
1362,
1415,
26,
2549,
2043,
536,
26,
1362,
1369,
26,
267,
446,
2812,
370,
506,
8120,
370,
314,
909,
14,
982,
11684,
12,
5331,
911,
506,
641,
881,
314,
8039,
3970,
1362,
1415,
26,
3055,
2043,
1788,
26,
1362,
1369,
26,
267,
446,
6912,
370,
2257,
570,
370,
506,
14238,
14,
1362,
1415,
26,
3055,
2043,
3970,
63,
2732,
26,
1362,
1369,
26,
267,
446,
6387,
3970,
2879,
2166,
14,
1362,
1415,
26,
3055,
1362,
3415,
26,
788,
4239,
297,
283,
3455,
418,
1362,
849,
26,
5726,
2043,
1174,
26,
1362,
1369,
26,
2126,
446,
7719,
314,
2073,
506,
3451,
503,
9552,
14,
1362,
3415,
26,
359,
1881,
12,
9552,
61,
1362,
849,
26,
3451,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
10560,
282,
909,
4310,
283,
15624,
371,
7,
315,
314,
283,
888,
7,
3970,
199,
13,
747,
63,
785,
26,
8002,
29,
77,
2181,
581,
1174,
29,
1881,
536,
29,
15624,
371,
3970,
29,
888,
1788,
13043,
6839,
15,
15624,
371,
199,
199,
3,
28382,
282,
3970,
2797,
1101,
436,
1006,
402,
2399,
4072,
199,
13,
747,
63,
785,
26,
8002,
29,
14495,
13,
73,
350,
1174,
29,
5575,
3970,
29,
888,
199,
2344,
421,
199,
318,
2112,
63,
785,
8,
267,
8002,
63,
1113,
12,
3970,
12,
536,
12,
1788,
12,
3970,
63,
2732,
12,
1011,
958,
304,
339,
2896,
275,
756,
272,
3970,
63,
1113,
275,
8002,
63,
1113,
14,
362,
63,
3600,
8,
3600,
9,
272,
340,
2074,
459,
929,
418,
508,
283,
1881,
356,
267,
340,
440,
3970,
63,
1113,
26,
288,
3970,
63,
1113,
275,
8002,
63,
1113,
14,
981,
63,
3600,
8,
3600,
9,
288,
2896,
275,
715,
267,
340,
8002,
63,
1113,
14,
362,
63,
3600,
63,
2732,
8,
3600,
9,
1137,
3970,
63,
2732,
26,
288,
8002,
63,
1113,
14,
409,
63,
3600,
63,
2732,
8,
3600,
12,
3970,
63,
2732,
9,
288,
2896,
275,
715,
267,
340,
536,
26,
288,
340,
8002,
63,
1113,
14,
374,
63,
785,
63,
20102,
8,
3600,
12,
536,
12,
1788,
304,
355,
8002,
63,
1113,
14,
981,
63,
785,
8,
3600,
12,
536,
12,
1788,
9,
355,
2896,
275,
715,
272,
587,
26,
267,
340,
3970,
63,
1113,
26,
288,
340,
536,
26,
355,
340,
8002,
63,
1113,
14,
362,
63,
785,
63,
2343,
8,
3600,
12,
536,
304,
2116,
8002,
63,
1113,
14,
1807,
63,
785,
8,
3600,
12,
536,
9,
355,
2896,
29,
715,
288,
587,
26,
355,
8002,
63,
1113,
14,
1807,
63,
3600,
8,
3600,
9,
355,
2896,
29,
715,
272,
372,
2896,
421,
199,
318,
2446,
837,
272,
1423,
63,
1650,
275,
13869,
63,
2861,
63,
2094,
63,
1650,
8,
267,
536,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
3970,
29,
807,
8,
2427,
29,
549,
395,
267,
1788,
29,
807,
8,
2427,
29,
797,
12,
849,
29,
403,
395,
267,
3970,
63,
2732,
29,
807,
8,
885,
534,
4239,
297,
3415,
2968,
4239,
297,
283,
3455,
3815,
267,
1174,
29,
807,
8,
885,
534,
1881,
297,
3415,
2968,
5575,
297,
283,
1881,
3815,
272,
776,
272,
859,
63,
958,
275,
13869,
63,
578,
63,
958,
342,
272,
859,
275,
6953,
8,
2094,
63,
1650,
12,
1011,
578,
63,
958,
9,
339,
340,
440,
7509,
63,
8461,
1093,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
534,
31170,
365,
1415,
367,
642,
859,
358,
339,
862,
26,
267,
8002,
275,
32250,
14,
8512,
63,
4091,
3682,
578,
14,
1162,
9,
398,
2896,
275,
2112,
63,
785,
8,
4091,
12,
1011,
578,
14,
1162,
9,
398,
859,
14,
2224,
63,
1001,
8,
2489,
29,
2489,
9,
272,
871,
32250,
14,
26208,
9089,
1726,
465,
325,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
29,
495,
8,
69,
430,
199,
199,
3,
642,
365,
10628,
12,
1937,
1973,
15,
4853,
15,
578,
63,
2330,
14,
647,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
627,
199,
504,
3242,
14,
578,
63,
1208,
14,
8512,
492,
627,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
aricchen/openHR
|
openerp/addons/hr_holidays/hr_holidays.py
|
14
|
31505
|
# -*- coding: utf-8 -*-
##################################################################################
#
# Copyright (c) 2005-2006 Axelor SARL. (http://www.axelor.com)
# and 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# $Id: hr.py 4656 2006-11-24 09:58:42Z Cyp $
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import datetime
import time
from itertools import groupby
from operator import itemgetter
import math
from openerp import netsvc
from openerp import tools
from openerp.osv import fields, osv
from openerp.tools.translate import _
class hr_holidays_status(osv.osv):
_name = "hr.holidays.status"
_description = "Leave Type"
def get_days(self, cr, uid, ids, employee_id, return_false, context=None):
cr.execute("""SELECT id, type, number_of_days, holiday_status_id FROM hr_holidays WHERE employee_id = %s AND state='validate' AND holiday_status_id in %s""",
[employee_id, tuple(ids)])
result = sorted(cr.dictfetchall(), key=lambda x: x['holiday_status_id'])
grouped_lines = dict((k, [v for v in itr]) for k, itr in groupby(result, itemgetter('holiday_status_id')))
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = {}
max_leaves = leaves_taken = 0
if not return_false:
if record.id in grouped_lines:
leaves_taken = -sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'remove'])
max_leaves = sum([item['number_of_days'] for item in grouped_lines[record.id] if item['type'] == 'add'])
res[record.id]['max_leaves'] = max_leaves
res[record.id]['leaves_taken'] = leaves_taken
res[record.id]['remaining_leaves'] = max_leaves - leaves_taken
return res
def _user_left_days(self, cr, uid, ids, name, args, context=None):
return_false = False
employee_id = False
res = {}
if context and context.has_key('employee_id'):
if not context['employee_id']:
return_false = True
employee_id = context['employee_id']
else:
employee_ids = self.pool.get('hr.employee').search(cr, uid, [('user_id','=',uid)], context=context)
if employee_ids:
employee_id = employee_ids[0]
else:
return_false = True
if employee_id:
res = self.get_days(cr, uid, ids, employee_id, return_false, context=context)
else:
res = dict.fromkeys(ids, {'leaves_taken': 0, 'remaining_leaves': 0, 'max_leaves': 0})
return res
_columns = {
'name': fields.char('Leave Type', size=64, required=True, translate=True),
'categ_id': fields.many2one('crm.meeting.type', 'Meeting Type',
help='Once a leave is validated, OpenERP will create a corresponding meeting of this type in the calendar.'),
'color_name': fields.selection([('red', 'Red'),('blue','Blue'), ('lightgreen', 'Light Green'), ('lightblue','Light Blue'), ('lightyellow', 'Light Yellow'), ('magenta', 'Magenta'),('lightcyan', 'Light Cyan'),('black', 'Black'),('lightpink', 'Light Pink'),('brown', 'Brown'),('violet', 'Violet'),('lightcoral', 'Light Coral'),('lightsalmon', 'Light Salmon'),('lavender', 'Lavender'),('wheat', 'Wheat'),('ivory', 'Ivory')],'Color in Report', required=True, help='This color will be used in the leaves summary located in Reporting\Leaves by Department.'),
'limit': fields.boolean('Allow to Override Limit', help='If you select this check box, the system allows the employees to take more leaves than the available ones for this type and take them into account for the "Remaining Legal Leaves" defined on the employee form.'),
'active': fields.boolean('Active', help="If the active field is set to false, it will allow you to hide the leave type without removing it."),
'max_leaves': fields.function(_user_left_days, string='Maximum Allowed', help='This value is given by the sum of all holidays requests with a positive value.', multi='user_left_days'),
'leaves_taken': fields.function(_user_left_days, string='Leaves Already Taken', help='This value is given by the sum of all holidays requests with a negative value.', multi='user_left_days'),
'remaining_leaves': fields.function(_user_left_days, string='Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken', multi='user_left_days'),
'double_validation': fields.boolean('Apply Double Validation', help="When selected, the Allocation/Leave Requests for this type require a second validation to be approved."),
}
_defaults = {
'color_name': 'red',
'active': True,
}
def name_get(self, cr, uid, ids, context=None):
if not ids:
return []
res = []
for record in self.browse(cr, uid, ids, context=context):
name = record.name
if not record.limit:
name = name + (' (%d/%d)' % (record.leaves_taken or 0.0, record.max_leaves or 0.0))
res.append((record.id, name))
return res
class hr_holidays(osv.osv):
_name = "hr.holidays"
_description = "Leave"
_order = "type desc, date_from asc"
_inherit = ['mail.thread', 'ir.needaction_mixin']
_track = {
'state': {
'hr_holidays.mt_holidays_approved': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'validate',
'hr_holidays.mt_holidays_refused': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'refuse',
'hr_holidays.mt_holidays_confirmed': lambda self, cr, uid, obj, ctx=None: obj['state'] == 'confirm',
},
}
def _employee_get(self, cr, uid, context=None):
ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)
if ids:
return ids[0]
return False
def _compute_number_of_days(self, cr, uid, ids, name, args, context=None):
result = {}
for hol in self.browse(cr, uid, ids, context=context):
if hol.type=='remove':
result[hol.id] = -hol.number_of_days_temp
else:
result[hol.id] = hol.number_of_days_temp
return result
def _check_date(self, cr, uid, ids):
for holiday in self.browse(cr, uid, ids):
holiday_ids = self.search(cr, uid, [('date_from', '<=', holiday.date_to), ('date_to', '>=', holiday.date_from), ('employee_id', '=', holiday.employee_id.id), ('id', '<>', holiday.id)])
if holiday_ids:
return False
return True
_columns = {
'name': fields.char('Description', size=64),
'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'Second Approval'), ('validate', 'Approved')],
'Status', readonly=True, track_visibility='onchange',
help='The status is set to \'To Submit\', when a holiday request is created.\
\nThe status is \'To Approve\', when holiday request is confirmed by user.\
\nThe status is \'Refused\', when holiday request is refused by manager.\
\nThe status is \'Approved\', when holiday request is approved by manager.'),
'user_id':fields.related('employee_id', 'user_id', type='many2one', relation='res.users', string='User', store=True),
'date_from': fields.datetime('Start Date', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, select=True),
'date_to': fields.datetime('End Date', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'holiday_status_id': fields.many2one("hr.holidays.status", "Leave Type", required=True,readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'employee_id': fields.many2one('hr.employee', "Employee", select=True, invisible=False, readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'manager_id': fields.many2one('hr.employee', 'First Approval', invisible=False, readonly=True, help='This area is automatically filled by the user who validate the leave'),
'notes': fields.text('Reasons',readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'number_of_days_temp': fields.float('Allocation', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'number_of_days': fields.function(_compute_number_of_days, string='Number of Days', store=True),
'meeting_id': fields.many2one('crm.meeting', 'Meeting'),
'type': fields.selection([('remove','Leave Request'),('add','Allocation Request')], 'Request Type', required=True, readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, help="Choose 'Leave Request' if someone wants to take an off-day. \nChoose 'Allocation Request' if you want to increase the number of leaves available for someone", select=True),
'parent_id': fields.many2one('hr.holidays', 'Parent'),
'linked_request_ids': fields.one2many('hr.holidays', 'parent_id', 'Linked Requests',),
'department_id':fields.related('employee_id', 'department_id', string='Department', type='many2one', relation='hr.department', readonly=True, store=True),
'category_id': fields.many2one('hr.employee.category', "Employee Tag", help='Category of Employee', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'holiday_type': fields.selection([('employee','By Employee'),('category','By Employee Tag')], 'Allocation Mode', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, help='By Employee: Allocation/Request for individual Employee, By Employee Tag: Allocation/Request for group of employees in category', required=True),
'manager_id2': fields.many2one('hr.employee', 'Second Approval', readonly=True, help='This area is automaticly filled by the user who validate the leave with second level (If Leave type need second validation)'),
'double_validation': fields.related('holiday_status_id', 'double_validation', type='boolean', relation='hr.holidays.status', string='Apply Double Validation'),
}
_defaults = {
'employee_id': _employee_get,
'state': 'draft',
'type': 'remove',
'user_id': lambda obj, cr, uid, context: uid,
'holiday_type': 'employee'
}
_constraints = [
(_check_date, 'You can not have 2 leaves that overlaps on same day!', ['date_from','date_to']),
]
_sql_constraints = [
('type_value', "CHECK( (holiday_type='employee' AND employee_id IS NOT NULL) or (holiday_type='category' AND category_id IS NOT NULL))",
"The employee or employee category of this request is missing. Please make sure that your user login is linked to an employee."),
('date_check2', "CHECK ( (type='add') OR (date_from <= date_to))", "The start date must be anterior to the end date."),
('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0."),
]
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
if context is None:
context = {}
default = default.copy()
default['date_from'] = False
default['date_to'] = False
return super(hr_holidays, self).copy(cr, uid, id, default, context=context)
def _create_resource_leave(self, cr, uid, leaves, context=None):
'''This method will create entry in resource calendar leave object at the time of holidays validated '''
obj_res_leave = self.pool.get('resource.calendar.leaves')
for leave in leaves:
vals = {
'name': leave.name,
'date_from': leave.date_from,
'holiday_id': leave.id,
'date_to': leave.date_to,
'resource_id': leave.employee_id.resource_id.id,
'calendar_id': leave.employee_id.resource_id.calendar_id.id
}
obj_res_leave.create(cr, uid, vals, context=context)
return True
def _remove_resource_leave(self, cr, uid, ids, context=None):
'''This method will create entry in resource calendar leave object at the time of holidays cancel/removed'''
obj_res_leave = self.pool.get('resource.calendar.leaves')
leave_ids = obj_res_leave.search(cr, uid, [('holiday_id', 'in', ids)], context=context)
return obj_res_leave.unlink(cr, uid, leave_ids, context=context)
def onchange_type(self, cr, uid, ids, holiday_type):
result = {'value': {'employee_id': False}}
if holiday_type == 'employee':
ids_employee = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
if ids_employee:
result['value'] = {
'employee_id': ids_employee[0]
}
return result
def onchange_employee(self, cr, uid, ids, employee_id):
result = {'value': {'department_id': False}}
if employee_id:
employee = self.pool.get('hr.employee').browse(cr, uid, employee_id)
result['value'] = {'department_id': employee.department_id.id}
return result
# TODO: can be improved using resource calendar method
def _get_number_of_days(self, date_from, date_to):
"""Returns a float equals to the timedelta between two dates given as string."""
DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT)
to_dt = datetime.datetime.strptime(date_to, DATETIME_FORMAT)
timedelta = to_dt - from_dt
diff_day = timedelta.days + float(timedelta.seconds) / 86400
return diff_day
def unlink(self, cr, uid, ids, context=None):
for rec in self.browse(cr, uid, ids, context=context):
if rec.state not in ['draft', 'cancel', 'confirm']:
raise osv.except_osv(_('Warning!'),_('You cannot delete a leave which is in %s state.')%(rec.state))
return super(hr_holidays, self).unlink(cr, uid, ids, context)
def onchange_date_from(self, cr, uid, ids, date_to, date_from):
"""
If there are no date set for date_to, automatically set one 8 hours later than
the date_from.
Also update the number_of_days.
"""
# date_to has to be greater than date_from
if (date_from and date_to) and (date_from > date_to):
raise osv.except_osv(_('Warning!'),_('The start date must be anterior to the end date.'))
result = {'value': {}}
# No date_to set so far: automatically compute one 8 hours later
if date_from and not date_to:
date_to_with_delta = datetime.datetime.strptime(date_from, tools.DEFAULT_SERVER_DATETIME_FORMAT) + datetime.timedelta(hours=8)
result['value']['date_to'] = str(date_to_with_delta)
# Compute and update the number of days
if (date_to and date_from) and (date_from <= date_to):
diff_day = self._get_number_of_days(date_from, date_to)
result['value']['number_of_days_temp'] = round(math.floor(diff_day))+1
else:
result['value']['number_of_days_temp'] = 0
return result
def onchange_date_to(self, cr, uid, ids, date_to, date_from):
"""
Update the number_of_days.
"""
# date_to has to be greater than date_from
if (date_from and date_to) and (date_from > date_to):
raise osv.except_osv(_('Warning!'),_('The start date must be anterior to the end date.'))
result = {'value': {}}
# Compute and update the number of days
if (date_to and date_from) and (date_from <= date_to):
diff_day = self._get_number_of_days(date_from, date_to)
result['value']['number_of_days_temp'] = round(math.floor(diff_day))+1
else:
result['value']['number_of_days_temp'] = 0
return result
def create(self, cr, uid, values, context=None):
""" Override to avoid automatic logging of creation """
if context is None:
context = {}
context = dict(context, mail_create_nolog=True)
return super(hr_holidays, self).create(cr, uid, values, context=context)
def write(self, cr, uid, ids, vals, context=None):
check_fnct = self.pool.get('hr.holidays.status').check_access_rights
for holiday in self.browse(cr, uid, ids, context=context):
if holiday.state in ('validate','validate1') and not check_fnct(cr, uid, 'write', raise_exception=False):
raise osv.except_osv(_('Warning!'),_('You cannot modify a leave request that has been approved. Contact a human resource manager.'))
return super(hr_holidays, self).write(cr, uid, ids, vals, context=context)
def set_to_draft(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {
'state': 'draft',
'manager_id': False,
'manager_id2': False,
})
wf_service = netsvc.LocalService("workflow")
for id in ids:
wf_service.trg_delete(uid, 'hr.holidays', id, cr)
wf_service.trg_create(uid, 'hr.holidays', id, cr)
to_unlink = []
for record in self.browse(cr, uid, ids, context=context):
for record2 in record.linked_request_ids:
self.set_to_draft(cr, uid, [record2.id], context=context)
to_unlink.append(record2.id)
if to_unlink:
self.unlink(cr, uid, to_unlink, context=context)
return True
def holidays_first_validate(self, cr, uid, ids, context=None):
self.check_holidays(cr, uid, ids, context=context)
obj_emp = self.pool.get('hr.employee')
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
manager = ids2 and ids2[0] or False
self.holidays_first_validate_notificate(cr, uid, ids, context=context)
return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager})
def holidays_validate(self, cr, uid, ids, context=None):
self.check_holidays(cr, uid, ids, context=context)
obj_emp = self.pool.get('hr.employee')
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
manager = ids2 and ids2[0] or False
self.write(cr, uid, ids, {'state':'validate'})
data_holiday = self.browse(cr, uid, ids)
for record in data_holiday:
if record.double_validation:
self.write(cr, uid, [record.id], {'manager_id2': manager})
else:
self.write(cr, uid, [record.id], {'manager_id': manager})
if record.holiday_type == 'employee' and record.type == 'remove':
meeting_obj = self.pool.get('crm.meeting')
meeting_vals = {
'name': record.name or _('Leave Request'),
'categ_ids': record.holiday_status_id.categ_id and [(6,0,[record.holiday_status_id.categ_id.id])] or [],
'duration': record.number_of_days_temp * 8,
'description': record.notes,
'user_id': record.user_id.id,
'date': record.date_from,
'end_date': record.date_to,
'date_deadline': record.date_to,
'state': 'open', # to block that meeting date in the calendar
}
meeting_id = meeting_obj.create(cr, uid, meeting_vals)
self._create_resource_leave(cr, uid, [record], context=context)
self.write(cr, uid, ids, {'meeting_id': meeting_id})
elif record.holiday_type == 'category':
emp_ids = obj_emp.search(cr, uid, [('category_ids', 'child_of', [record.category_id.id])])
leave_ids = []
for emp in obj_emp.browse(cr, uid, emp_ids):
vals = {
'name': record.name,
'type': record.type,
'holiday_type': 'employee',
'holiday_status_id': record.holiday_status_id.id,
'date_from': record.date_from,
'date_to': record.date_to,
'notes': record.notes,
'number_of_days_temp': record.number_of_days_temp,
'parent_id': record.id,
'employee_id': emp.id
}
leave_ids.append(self.create(cr, uid, vals, context=None))
wf_service = netsvc.LocalService("workflow")
for leave_id in leave_ids:
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'confirm', cr)
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'validate', cr)
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr)
return True
def holidays_confirm(self, cr, uid, ids, context=None):
self.check_holidays(cr, uid, ids, context=context)
for record in self.browse(cr, uid, ids, context=context):
if record.employee_id and record.employee_id.parent_id and record.employee_id.parent_id.user_id:
self.message_subscribe_users(cr, uid, [record.id], user_ids=[record.employee_id.parent_id.user_id.id], context=context)
return self.write(cr, uid, ids, {'state': 'confirm'})
def holidays_refuse(self, cr, uid, ids, context=None):
obj_emp = self.pool.get('hr.employee')
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
manager = ids2 and ids2[0] or False
for holiday in self.browse(cr, uid, ids, context=context):
if holiday.state == 'validate1':
self.write(cr, uid, [holiday.id], {'state': 'refuse', 'manager_id': manager})
else:
self.write(cr, uid, [holiday.id], {'state': 'refuse', 'manager_id2': manager})
self.holidays_cancel(cr, uid, ids, context=context)
return True
def holidays_cancel(self, cr, uid, ids, context=None):
meeting_obj = self.pool.get('crm.meeting')
for record in self.browse(cr, uid, ids):
# Delete the meeting
if record.meeting_id:
meeting_obj.unlink(cr, uid, [record.meeting_id.id])
# If a category that created several holidays, cancel all related
wf_service = netsvc.LocalService("workflow")
for request in record.linked_request_ids or []:
wf_service.trg_validate(uid, 'hr.holidays', request.id, 'refuse', cr)
self._remove_resource_leave(cr, uid, ids, context=context)
return True
def check_holidays(self, cr, uid, ids, context=None):
holi_status_obj = self.pool.get('hr.holidays.status')
for record in self.browse(cr, uid, ids):
if record.holiday_type == 'employee' and record.type == 'remove':
if record.employee_id and not record.holiday_status_id.limit:
leaves_rest = holi_status_obj.get_days( cr, uid, [record.holiday_status_id.id], record.employee_id.id, False)[record.holiday_status_id.id]['remaining_leaves']
if leaves_rest < record.number_of_days_temp:
raise osv.except_osv(_('Warning!'), _('There are not enough %s allocated for employee %s; please create an allocation request for this leave type.') % (record.holiday_status_id.name, record.employee_id.name))
return True
# -----------------------------
# OpenChatter and notifications
# -----------------------------
def _needaction_domain_get(self, cr, uid, context=None):
emp_obj = self.pool.get('hr.employee')
empids = emp_obj.search(cr, uid, [('parent_id.user_id', '=', uid)], context=context)
dom = ['&', ('state', '=', 'confirm'), ('employee_id', 'in', empids)]
# if this user is a hr.manager, he should do second validations
if self.pool.get('res.users').has_group(cr, uid, 'base.group_hr_manager'):
dom = ['|'] + dom + [('state', '=', 'validate1')]
return dom
def holidays_first_validate_notificate(self, cr, uid, ids, context=None):
for obj in self.browse(cr, uid, ids, context=context):
self.message_post(cr, uid, [obj.id],
_("Request approved, waiting second validation."), context=context)
class resource_calendar_leaves(osv.osv):
_inherit = "resource.calendar.leaves"
_description = "Leave Detail"
_columns = {
'holiday_id': fields.many2one("hr.holidays", "Leave Request"),
}
resource_calendar_leaves()
class hr_employee(osv.osv):
_inherit="hr.employee"
def create(self, cr, uid, vals, context=None):
# don't pass the value of remaining leave if it's 0 at the creation time, otherwise it will trigger the inverse
# function _set_remaining_days and the system may not be configured for. Note that we don't have this problem on
# the write because the clients only send the fields that have been modified.
if 'remaining_leaves' in vals and not vals['remaining_leaves']:
del(vals['remaining_leaves'])
return super(hr_employee, self).create(cr, uid, vals, context=context)
def _set_remaining_days(self, cr, uid, empl_id, name, value, arg, context=None):
employee = self.browse(cr, uid, empl_id, context=context)
diff = value - employee.remaining_leaves
type_obj = self.pool.get('hr.holidays.status')
holiday_obj = self.pool.get('hr.holidays')
# Find for holidays status
status_ids = type_obj.search(cr, uid, [('limit', '=', False)], context=context)
if len(status_ids) != 1 :
raise osv.except_osv(_('Warning!'),_("The feature behind the field 'Remaining Legal Leaves' can only be used when there is only one leave type with the option 'Allow to Override Limit' unchecked. (%s Found). Otherwise, the update is ambiguous as we cannot decide on which leave type the update has to be done. \nYou may prefer to use the classic menus 'Leave Requests' and 'Allocation Requests' located in 'Human Resources \ Leaves' to manage the leave days of the employees if the configuration does not allow to use this field.") % (len(status_ids)))
status_id = status_ids and status_ids[0] or False
if not status_id:
return False
if diff > 0:
leave_id = holiday_obj.create(cr, uid, {'name': _('Allocation for %s') % employee.name, 'employee_id': employee.id, 'holiday_status_id': status_id, 'type': 'add', 'holiday_type': 'employee', 'number_of_days_temp': diff}, context=context)
elif diff < 0:
leave_id = holiday_obj.create(cr, uid, {'name': _('Leave Request for %s') % employee.name, 'employee_id': employee.id, 'holiday_status_id': status_id, 'type': 'remove', 'holiday_type': 'employee', 'number_of_days_temp': abs(diff)}, context=context)
else:
return False
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'confirm', cr)
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'validate', cr)
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr)
return True
def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
cr.execute("""SELECT
sum(h.number_of_days) as days,
h.employee_id
from
hr_holidays h
join hr_holidays_status s on (s.id=h.holiday_status_id)
where
h.state='validate' and
s.limit=False and
h.employee_id in (%s)
group by h.employee_id"""% (','.join(map(str,ids)),) )
res = cr.dictfetchall()
remaining = {}
for r in res:
remaining[r['employee_id']] = r['days']
for employee_id in ids:
if not remaining.get(employee_id):
remaining[employee_id] = 0.0
return remaining
def _get_leave_status(self, cr, uid, ids, name, args, context=None):
holidays_obj = self.pool.get('hr.holidays')
holidays_id = holidays_obj.search(cr, uid,
[('employee_id', 'in', ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')),
('date_to','>=',time.strftime('%Y-%m-%d 23:59:59')),('type','=','remove'),('state','not in',('cancel','refuse'))],
context=context)
result = {}
for id in ids:
result[id] = {
'current_leave_state': False,
'current_leave_id': False,
'leave_date_from':False,
'leave_date_to':False,
}
for holiday in self.pool.get('hr.holidays').browse(cr, uid, holidays_id, context=context):
result[holiday.employee_id.id]['leave_date_from'] = holiday.date_from
result[holiday.employee_id.id]['leave_date_to'] = holiday.date_to
result[holiday.employee_id.id]['current_leave_state'] = holiday.state
result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id
return result
_columns = {
'remaining_leaves': fields.function(_get_remaining_days, string='Remaining Legal Leaves', fnct_inv=_set_remaining_days, type="float", help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave request. Total based on all the leave types without overriding limit.'),
'current_leave_state': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Status", type="selection",
selection=[('draft', 'New'), ('confirm', 'Waiting Approval'), ('refuse', 'Refused'),
('validate1', 'Waiting Second Approval'), ('validate', 'Approved'), ('cancel', 'Cancelled')]),
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),
}
hr_employee()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
13289,
309,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
13,
7968,
437,
31418,
269,
428,
689,
44,
14,
334,
1014,
921,
1544,
14,
1219,
352,
269,
14,
957,
9,
199,
3,
436,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
2672,
1304,
26,
16140,
14,
647,
12426,
1367,
8315,
13,
845,
13,
1194,
21798,
26,
2010,
26,
2260,
58,
445,
2279,
2672,
199,
3,
199,
3,
258,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
258,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
258,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
258,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
258,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
258,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
258,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
258,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2197,
199,
646,
900,
199,
504,
7975,
492,
20371,
199,
504,
4182,
492,
1242,
7416,
199,
199,
646,
3473,
199,
504,
5166,
492,
1851,
10599,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
16140,
63,
26131,
63,
1205,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6271,
14,
26131,
14,
1205,
2,
272,
485,
1802,
275,
298,
23679,
2434,
2,
339,
347,
664,
63,
4899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15778,
63,
344,
12,
372,
63,
3910,
12,
1067,
29,
403,
304,
267,
2467,
14,
2526,
4852,
4859,
1305,
12,
730,
12,
1329,
63,
1618,
63,
4899,
12,
26475,
2977,
63,
1205,
63,
344,
4442,
16140,
63,
26131,
6038,
15778,
63,
344,
275,
450,
83,
2401,
1174,
534,
3502,
7,
2401,
26475,
2977,
63,
1205,
63,
344,
315,
450,
83,
7208,
288,
359,
10103,
63,
344,
12,
2008,
8,
1580,
3948,
267,
754,
275,
3355,
8,
1556,
14,
807,
10174,
1062,
790,
29,
2734,
671,
26,
671,
459,
20154,
2977,
63,
1205,
63,
344,
1105,
267,
16251,
63,
1278,
275,
1211,
1332,
75,
12,
359,
86,
367,
373,
315,
284,
454,
566,
367,
1022,
12,
284,
454,
315,
20371,
8,
1099,
12,
1242,
7416,
360,
20154,
2977,
63,
1205,
63,
344,
7058,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
1052,
288,
1390,
63,
16554,
275,
16733,
63,
28549,
275,
378,
288,
340,
440,
372,
63,
3910,
26,
355,
340,
2777,
14,
344,
315,
16251,
63,
1278,
26,
490,
16733,
63,
28549,
275,
446,
1838,
779,
1053,
459,
1955,
63,
1618,
63,
4899,
418,
367,
1242,
315,
16251,
63,
1278,
59,
3059,
14,
344,
61,
340,
1242,
459,
466,
418,
508,
283,
2168,
1105,
490,
1390,
63,
16554,
275,
3089,
779,
1053,
459,
1955,
63,
1618,
63,
4899,
418,
367,
1242,
315,
16251,
63,
1278,
59,
3059,
14,
344,
61,
340,
1242,
459,
466,
418,
508,
283,
525,
1105,
288,
522,
59,
3059,
14,
344,
2733,
988,
63,
16554,
418,
275,
1390,
63,
16554,
288,
522,
59,
3059,
14,
344,
2733,
16554,
63,
28549,
418,
275,
16733,
63,
28549,
288,
522,
59,
3059,
14,
344,
2733,
11266,
63,
16554,
418,
275,
1390,
63,
16554,
446,
16733,
63,
28549,
267,
372,
522,
339,
347,
485,
751,
63,
3039,
63,
4899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
372,
63,
3910,
275,
756,
267,
15778,
63,
344,
275,
756,
267,
522,
275,
1052,
267,
340,
1067,
436,
1067,
14,
1989,
63,
498,
360,
10103,
63,
344,
735,
288,
340,
440,
1067,
459,
10103,
63,
344,
2565,
355,
372,
63,
3910,
275,
715,
288,
15778,
63,
344,
275,
1067,
459,
10103,
63,
344,
418,
267,
587,
26,
288,
15778,
63,
1580,
275,
291,
14,
2293,
14,
362,
360,
6271,
14,
10103,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
751,
63,
344,
18937,
1535,
4360,
1067,
29,
1100,
9,
288,
340,
15778,
63,
1580,
26,
355,
15778,
63,
344,
275,
15778,
63,
1580,
59,
16,
61,
288,
587,
26,
355,
372,
63,
3910,
275,
715,
267,
340,
15778,
63,
344,
26,
288,
522,
275,
291,
14,
362,
63,
4899,
8,
1556,
12,
1747,
12,
2762,
12,
15778,
63,
344,
12,
372,
63,
3910,
12,
1067,
29,
1100,
9,
267,
587,
26,
288,
522,
275,
1211,
14,
19164,
8,
1580,
12,
791,
16554,
63,
28549,
356,
378,
12,
283,
11266,
63,
16554,
356,
378,
12,
283,
988,
63,
16554,
356,
378,
1552,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
23679,
2434,
297,
1568,
29,
772,
12,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
3533,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
278,
13800,
14,
466,
297,
283,
1352,
13800,
2434,
297,
288,
1720,
534,
25690,
282,
10137,
365,
16468,
12,
7653,
911,
1218,
282,
5226,
31495,
402,
642,
730,
315,
314,
11234,
8038,
267,
283,
2326,
63,
354,
356,
1504,
14,
5592,
8318,
581,
297,
283,
10858,
8157,
6304,
1673,
15617,
659,
661,
4040,
7731,
297,
283,
16393,
32585,
659,
661,
4040,
6304,
1673,
16393,
22447,
659,
661,
18975,
369,
10723,
297,
283,
16393,
1488,
10723,
659,
661,
5615,
21335,
297,
283,
45,
4054,
65,
8157,
4040,
28291,
297,
283,
16393,
18461,
290,
8157,
8399,
297,
283,
23405,
8157,
4040,
26591,
297,
283,
16393,
510,
2292,
8157,
27133,
297,
283,
34,
18406,
8157
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
13289,
309,
199,
3,
199,
3,
1898,
334,
67,
9,
11811,
13,
7968,
437,
31418,
269,
428,
689,
44,
14,
334,
1014,
921,
1544,
14,
1219,
352,
269,
14,
957,
9,
199,
3,
436,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
2672,
1304,
26,
16140,
14,
647,
12426,
1367,
8315,
13,
845,
13,
1194,
21798,
26,
2010,
26,
2260,
58,
445,
2279,
2672,
199,
3,
199,
3,
258,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
258,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
258,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
258,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
258,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
258,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
258,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
258,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
258,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
258,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2197,
199,
646,
900,
199,
504,
7975,
492,
20371,
199,
504,
4182,
492,
1242,
7416,
199,
199,
646,
3473,
199,
504,
5166,
492,
1851,
10599,
199,
504,
5166,
492,
7249,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
421,
199,
533,
16140,
63,
26131,
63,
1205,
8,
4795,
14,
4795,
304,
272,
485,
354,
275,
298,
6271,
14,
26131,
14,
1205,
2,
272,
485,
1802,
275,
298,
23679,
2434,
2,
339,
347,
664,
63,
4899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
15778,
63,
344,
12,
372,
63,
3910,
12,
1067,
29,
403,
304,
267,
2467,
14,
2526,
4852,
4859,
1305,
12,
730,
12,
1329,
63,
1618,
63,
4899,
12,
26475,
2977,
63,
1205,
63,
344,
4442,
16140,
63,
26131,
6038,
15778,
63,
344,
275,
450,
83,
2401,
1174,
534,
3502,
7,
2401,
26475,
2977,
63,
1205,
63,
344,
315,
450,
83,
7208,
288,
359,
10103,
63,
344,
12,
2008,
8,
1580,
3948,
267,
754,
275,
3355,
8,
1556,
14,
807,
10174,
1062,
790,
29,
2734,
671,
26,
671,
459,
20154,
2977,
63,
1205,
63,
344,
1105,
267,
16251,
63,
1278,
275,
1211,
1332,
75,
12,
359,
86,
367,
373,
315,
284,
454,
566,
367,
1022,
12,
284,
454,
315,
20371,
8,
1099,
12,
1242,
7416,
360,
20154,
2977,
63,
1205,
63,
344,
7058,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
1052,
288,
1390,
63,
16554,
275,
16733,
63,
28549,
275,
378,
288,
340,
440,
372,
63,
3910,
26,
355,
340,
2777,
14,
344,
315,
16251,
63,
1278,
26,
490,
16733,
63,
28549,
275,
446,
1838,
779,
1053,
459,
1955,
63,
1618,
63,
4899,
418,
367,
1242,
315,
16251,
63,
1278,
59,
3059,
14,
344,
61,
340,
1242,
459,
466,
418,
508,
283,
2168,
1105,
490,
1390,
63,
16554,
275,
3089,
779,
1053,
459,
1955,
63,
1618,
63,
4899,
418,
367,
1242,
315,
16251,
63,
1278,
59,
3059,
14,
344,
61,
340,
1242,
459,
466,
418,
508,
283,
525,
1105,
288,
522,
59,
3059,
14,
344,
2733,
988,
63,
16554,
418,
275,
1390,
63,
16554,
288,
522,
59,
3059,
14,
344,
2733,
16554,
63,
28549,
418,
275,
16733,
63,
28549,
288,
522,
59,
3059,
14,
344,
2733,
11266,
63,
16554,
418,
275,
1390,
63,
16554,
446,
16733,
63,
28549,
267,
372,
522,
339,
347,
485,
751,
63,
3039,
63,
4899,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
372,
63,
3910,
275,
756,
267,
15778,
63,
344,
275,
756,
267,
522,
275,
1052,
267,
340,
1067,
436,
1067,
14,
1989,
63,
498,
360,
10103,
63,
344,
735,
288,
340,
440,
1067,
459,
10103,
63,
344,
2565,
355,
372,
63,
3910,
275,
715,
288,
15778,
63,
344,
275,
1067,
459,
10103,
63,
344,
418,
267,
587,
26,
288,
15778,
63,
1580,
275,
291,
14,
2293,
14,
362,
360,
6271,
14,
10103,
1959,
1733,
8,
1556,
12,
1747,
12,
4274,
751,
63,
344,
18937,
1535,
4360,
1067,
29,
1100,
9,
288,
340,
15778,
63,
1580,
26,
355,
15778,
63,
344,
275,
15778,
63,
1580,
59,
16,
61,
288,
587,
26,
355,
372,
63,
3910,
275,
715,
267,
340,
15778,
63,
344,
26,
288,
522,
275,
291,
14,
362,
63,
4899,
8,
1556,
12,
1747,
12,
2762,
12,
15778,
63,
344,
12,
372,
63,
3910,
12,
1067,
29,
1100,
9,
267,
587,
26,
288,
522,
275,
1211,
14,
19164,
8,
1580,
12,
791,
16554,
63,
28549,
356,
378,
12,
283,
11266,
63,
16554,
356,
378,
12,
283,
988,
63,
16554,
356,
378,
1552,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
360,
23679,
2434,
297,
1568,
29,
772,
12,
1415,
29,
549,
12,
9028,
29,
549,
395,
267,
283,
3533,
63,
344,
356,
1504,
14,
3479,
18,
368,
360,
15213,
14,
278,
13800,
14,
466,
297,
283,
1352,
13800,
2434,
297,
288,
1720,
534,
25690,
282,
10137,
365,
16468,
12,
7653,
911,
1218,
282,
5226,
31495,
402,
642,
730,
315,
314,
11234,
8038,
267,
283,
2326,
63,
354,
356,
1504,
14,
5592,
8318,
581,
297,
283,
10858,
8157,
6304,
1673,
15617,
659,
661,
4040,
7731,
297,
283,
16393,
32585,
659,
661,
4040,
6304,
1673,
16393,
22447,
659,
661,
18975,
369,
10723,
297,
283,
16393,
1488,
10723,
659,
661,
5615,
21335,
297,
283,
45,
4054,
65,
8157,
4040,
28291,
297,
283,
16393,
18461,
290,
8157,
8399,
297,
283,
23405,
8157,
4040,
26591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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
SidSachdev/pycrunchbase
|
tests/test_node.py
|
3
|
1070
|
from unittest import TestCase
import json
from pycrunchbase.resource.node import Node
from pycrunchbase.resource.utils import parse_date
class TestNode(Node):
KNOWN_PROPERTIES = ['property1', 'property2']
def _coerce_values(self):
# intentionally coerce bad values for test purposes
attr = 'property1'
if getattr(self, attr, None):
setattr(self, attr, parse_date(getattr(self, attr)))
data = {
"type": "TestNode",
"uuid": "uuid",
'properties': {
'property1': 'one',
'property2': 'two'
},
'relationships': {
'unknown': {
'paging': {},
'items': {}
}
},
}
class NodeTestCase(TestCase):
def test_node_creation_from_dict(self):
node = TestNode(data)
self.assertEqual(node.property1, 'one')
self.assertEqual(node.property2, 'two')
def test_node_creation_from_string(self):
node = TestNode(json.dumps(data))
self.assertEqual(node.property1, 'one')
self.assertEqual(node.property2, 'two')
|
mit
|
[
504,
2882,
492,
7640,
199,
199,
646,
2022,
199,
199,
504,
28968,
1065,
335,
1095,
14,
1927,
14,
932,
492,
5013,
199,
504,
28968,
1065,
335,
1095,
14,
1927,
14,
1208,
492,
2198,
63,
602,
421,
199,
533,
1379,
1716,
8,
1716,
304,
272,
1804,
9165,
63,
18858,
29807,
275,
788,
1829,
17,
297,
283,
1829,
18,
418,
339,
347,
485,
14141,
63,
1459,
8,
277,
304,
267,
327,
32005,
19874,
4875,
1338,
367,
511,
12901,
267,
1921,
275,
283,
1829,
17,
7,
267,
340,
2519,
8,
277,
12,
1921,
12,
488,
304,
288,
5371,
8,
277,
12,
1921,
12,
2198,
63,
602,
8,
5675,
8,
277,
12,
1921,
1724,
199,
199,
576,
275,
469,
272,
298,
466,
582,
298,
774,
1716,
401,
272,
298,
2580,
582,
298,
2580,
401,
272,
283,
3282,
356,
469,
267,
283,
1829,
17,
356,
283,
368,
297,
267,
283,
1829,
18,
356,
283,
5601,
7,
272,
1660,
272,
283,
24034,
356,
469,
267,
283,
5187,
356,
469,
288,
283,
31691,
356,
5479,
288,
283,
1744,
356,
1052,
267,
789,
272,
1660,
199,
93,
421,
199,
533,
5013,
1746,
8,
1746,
304,
272,
347,
511,
63,
932,
63,
8782,
63,
504,
63,
807,
8,
277,
304,
267,
1031,
275,
1379,
1716,
8,
576,
9,
267,
291,
14,
629,
8,
932,
14,
1829,
17,
12,
283,
368,
358,
267,
291,
14,
629,
8,
932,
14,
1829,
18,
12,
283,
5601,
358,
339,
347,
511,
63,
932,
63,
8782,
63,
504,
63,
875,
8,
277,
304,
267,
1031,
275,
1379,
1716,
8,
1001,
14,
4180,
8,
576,
430,
267,
291,
14,
629,
8,
932,
14,
1829,
17,
12,
283,
368,
358,
267,
291,
14,
629,
8,
932,
14,
1829,
18,
12,
283,
5601,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
492,
7640,
199,
199,
646,
2022,
199,
199,
504,
28968,
1065,
335,
1095,
14,
1927,
14,
932,
492,
5013,
199,
504,
28968,
1065,
335,
1095,
14,
1927,
14,
1208,
492,
2198,
63,
602,
421,
199,
533,
1379,
1716,
8,
1716,
304,
272,
1804,
9165,
63,
18858,
29807,
275,
788,
1829,
17,
297,
283,
1829,
18,
418,
339,
347,
485,
14141,
63,
1459,
8,
277,
304,
267,
327,
32005,
19874,
4875,
1338,
367,
511,
12901,
267,
1921,
275,
283,
1829,
17,
7,
267,
340,
2519,
8,
277,
12,
1921,
12,
488,
304,
288,
5371,
8,
277,
12,
1921,
12,
2198,
63,
602,
8,
5675,
8,
277,
12,
1921,
1724,
199,
199,
576,
275,
469,
272,
298,
466,
582,
298,
774,
1716,
401,
272,
298,
2580,
582,
298,
2580,
401,
272,
283,
3282,
356,
469,
267,
283,
1829,
17,
356,
283,
368,
297,
267,
283,
1829,
18,
356,
283,
5601,
7,
272,
1660,
272,
283,
24034,
356,
469,
267,
283,
5187,
356,
469,
288,
283,
31691,
356,
5479,
288,
283,
1744,
356,
1052,
267,
789,
272,
1660,
199,
93,
421,
199,
533,
5013,
1746,
8,
1746,
304,
272,
347,
511,
63,
932,
63,
8782,
63,
504,
63,
807,
8,
277,
304,
267,
1031,
275,
1379,
1716,
8,
576,
9,
267,
291,
14,
629,
8,
932,
14,
1829,
17,
12,
283,
368,
358,
267,
291,
14,
629,
8,
932,
14,
1829,
18,
12,
283,
5601,
358,
339,
347,
511,
63,
932,
63,
8782,
63,
504,
63,
875,
8,
277,
304,
267,
1031,
275,
1379,
1716,
8,
1001,
14,
4180,
8,
576,
430,
267,
291,
14,
629,
8,
932,
14,
1829,
17,
12,
283,
368,
358,
267,
291,
14,
629,
8,
932,
14,
1829,
18,
12,
283,
5601,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
1haodian/eagle
|
eagle-external/eagle-ambari/lib/EAGLE/package/scripts/eagle_hive_topology.py
|
21
|
3252
|
#!/usr/bin/python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from resource_management import *
from resource_management.libraries.script.script import Script
from resource_management.libraries.functions import get_unique_id_and_date
from resource_management.libraries.functions.version import compare_versions, format_hdp_stack_version
from resource_management.libraries.functions.security_commons import build_expectations, \
cached_kinit_executor, get_params_from_filesystem, validate_security_config_properties, \
FILE_TYPE_JAAS_CONF
from resource_management.core.shell import call
from resource_management.core.logger import Logger
from resource_management.core.resources.system import Execute
from resource_management.libraries.functions.check_process_status import check_process_status
from resource_management.libraries.functions.format import format
from resource_management.libraries.functions.validate import call_and_match_output
from actions import *
class EagleHiveTopology(Script):
# def get_stack_to_component(self):
# return {"HDP": "EAGLE-TOPOLOGY"}
def install(self, env):
Logger.info('Install Eagle DAM HIVE Topology')
# self.install_packages(env)
import params
env.set_params(params)
self.configure(env)
# eagle_hive_topology_exec(action = 'init')
def configure(self,env):
Logger.info("Configure Eagle DAM HIVE Topology")
import params
env.set_params(params)
# eagle_hive_topology_exec(action = 'init')
def pre_rolling_restart(self,env):
Logger.info("Executing rolling pre-restart Eagle DAM HIVE Topology")
import params
env.set_params(params)
# if params.version and compare_versions(format_hdp_stack_version(params.version), '2.2.0.0') >= 0:
# Execute(format("hdp-select set eagle-topology {version}"))
def stop(self, env):
Logger.info('Stopping Eagle DAM HIVE Topology')
import params
env.set_params(params)
self.configure(env)
eagle_hive_topology_exec(action = 'stop')
def start(self, env):
Logger.info('Starting Eagle DAM HIVE Topology')
import params
env.set_params(params)
self.configure(env)
eagle_hive_topology_exec(action = 'init')
eagle_hive_topology_exec(action = 'start')
def status(self, env):
Logger.info('Checking Eagle DAM HIVE Topology status')
import params
env.set_params(params)
self.configure(env)
eagle_hive_topology_exec(action = 'status')
if __name__ == "__main__":
EagleHiveTopology().execute()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
504,
2073,
63,
8110,
492,
627,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
14,
1579,
492,
14914,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
492,
664,
63,
3235,
63,
344,
63,
460,
63,
602,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1023,
492,
6540,
63,
6234,
12,
1475,
63,
72,
5780,
63,
2340,
63,
1023,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
4416,
63,
2330,
83,
492,
1900,
63,
15752,
12,
971,
523,
6328,
63,
75,
826,
63,
13471,
12,
664,
63,
1162,
63,
504,
63,
11381,
12,
4107,
63,
4416,
63,
888,
63,
3282,
12,
971,
523,
13024,
63,
2711,
63,
29849,
1179,
63,
3103,
199,
504,
2073,
63,
8110,
14,
1018,
14,
5641,
492,
1240,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1074,
63,
1412,
63,
1205,
492,
1104,
63,
1412,
63,
1205,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
908,
492,
1475,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
3502,
492,
1240,
63,
460,
63,
1431,
63,
1199,
199,
199,
504,
5445,
492,
627,
199,
199,
533,
662,
643,
274,
30232,
15696,
8,
5229,
304,
523,
327,
347,
664,
63,
2340,
63,
475,
63,
3173,
8,
277,
304,
523,
327,
221,
372,
2420,
40,
11741,
582,
298,
37,
1254,
906,
13,
2566,
1512,
4947,
57,
3570,
819,
347,
3907,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
8154,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
327,
291,
14,
3174,
63,
5154,
8,
1813,
9,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
327,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
819,
347,
7908,
8,
277,
12,
1813,
304,
272,
15996,
14,
815,
480,
17324,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
531,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
327,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
819,
347,
876,
63,
31562,
63,
10506,
8,
277,
12,
1813,
304,
272,
15996,
14,
815,
480,
4858,
4655,
882,
10564,
876,
13,
10506,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
531,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
339,
327,
340,
1862,
14,
1023,
436,
6540,
63,
6234,
8,
908,
63,
72,
5780,
63,
2340,
63,
1023,
8,
1162,
14,
1023,
395,
283,
18,
14,
18,
14,
16,
14,
16,
358,
2356,
378,
26,
272,
327,
221,
17009,
8,
908,
480,
72,
5780,
13,
2416,
663,
325,
643,
274,
13,
10775,
469,
1023,
93,
2237,
819,
347,
3631,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
6293,
4073,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
2379,
358,
819,
347,
1343,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
14139,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
339,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
928,
358,
819,
347,
2004,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
14740,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
2004,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
1205,
358,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
662,
643,
274,
30232,
15696,
1252,
2526,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
504,
2073,
63,
8110,
492,
627,
199,
504,
2073,
63,
8110,
14,
10159,
14,
1579,
14,
1579,
492,
14914,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
492,
664,
63,
3235,
63,
344,
63,
460,
63,
602,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1023,
492,
6540,
63,
6234,
12,
1475,
63,
72,
5780,
63,
2340,
63,
1023,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
4416,
63,
2330,
83,
492,
1900,
63,
15752,
12,
971,
523,
6328,
63,
75,
826,
63,
13471,
12,
664,
63,
1162,
63,
504,
63,
11381,
12,
4107,
63,
4416,
63,
888,
63,
3282,
12,
971,
523,
13024,
63,
2711,
63,
29849,
1179,
63,
3103,
199,
504,
2073,
63,
8110,
14,
1018,
14,
5641,
492,
1240,
199,
504,
2073,
63,
8110,
14,
1018,
14,
2921,
492,
15996,
199,
504,
2073,
63,
8110,
14,
1018,
14,
4435,
14,
2253,
492,
17009,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
1074,
63,
1412,
63,
1205,
492,
1104,
63,
1412,
63,
1205,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
908,
492,
1475,
199,
504,
2073,
63,
8110,
14,
10159,
14,
5777,
14,
3502,
492,
1240,
63,
460,
63,
1431,
63,
1199,
199,
199,
504,
5445,
492,
627,
199,
199,
533,
662,
643,
274,
30232,
15696,
8,
5229,
304,
523,
327,
347,
664,
63,
2340,
63,
475,
63,
3173,
8,
277,
304,
523,
327,
221,
372,
2420,
40,
11741,
582,
298,
37,
1254,
906,
13,
2566,
1512,
4947,
57,
3570,
819,
347,
3907,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
8154,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
327,
291,
14,
3174,
63,
5154,
8,
1813,
9,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
327,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
819,
347,
7908,
8,
277,
12,
1813,
304,
272,
15996,
14,
815,
480,
17324,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
531,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
327,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
819,
347,
876,
63,
31562,
63,
10506,
8,
277,
12,
1813,
304,
272,
15996,
14,
815,
480,
4858,
4655,
882,
10564,
876,
13,
10506,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
531,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
339,
327,
340,
1862,
14,
1023,
436,
6540,
63,
6234,
8,
908,
63,
72,
5780,
63,
2340,
63,
1023,
8,
1162,
14,
1023,
395,
283,
18,
14,
18,
14,
16,
14,
16,
358,
2356,
378,
26,
272,
327,
221,
17009,
8,
908,
480,
72,
5780,
13,
2416,
663,
325,
643,
274,
13,
10775,
469,
1023,
93,
2237,
819,
347,
3631,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
6293,
4073,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
2379,
358,
819,
347,
1343,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
14139,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
339,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
826,
358,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
928,
358,
819,
347,
2004,
8,
277,
12,
2589,
304,
272,
15996,
14,
815,
360,
14740,
662,
643,
274,
5179,
869,
5399,
14132,
7085,
2004,
358,
272,
492,
1862,
272,
2589,
14,
409,
63,
1162,
8,
1162,
9,
272,
291,
14,
6472,
8,
1813,
9,
272,
325,
643,
274,
63,
17230,
63,
10775,
63,
1628,
8,
1287,
275,
283,
1205,
358,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
662,
643,
274,
30232,
15696,
1252,
2526,
342,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
espena/terminal
|
test/node_modules/testem/node_modules/js-yaml/support/pyyaml-src/representer.py
|
238
|
13528
|
__all__ = ['BaseRepresenter', 'SafeRepresenter', 'Representer',
'RepresenterError']
from .error import *
from .nodes import *
import datetime, sys, copyreg, types, base64
class RepresenterError(YAMLError):
pass
class BaseRepresenter:
yaml_representers = {}
yaml_multi_representers = {}
def __init__(self, default_style=None, default_flow_style=None):
self.default_style = default_style
self.default_flow_style = default_flow_style
self.represented_objects = {}
self.object_keeper = []
self.alias_key = None
def represent(self, data):
node = self.represent_data(data)
self.serialize(node)
self.represented_objects = {}
self.object_keeper = []
self.alias_key = None
def represent_data(self, data):
if self.ignore_aliases(data):
self.alias_key = None
else:
self.alias_key = id(data)
if self.alias_key is not None:
if self.alias_key in self.represented_objects:
node = self.represented_objects[self.alias_key]
#if node is None:
# raise RepresenterError("recursive objects are not allowed: %r" % data)
return node
#self.represented_objects[alias_key] = None
self.object_keeper.append(data)
data_types = type(data).__mro__
if data_types[0] in self.yaml_representers:
node = self.yaml_representers[data_types[0]](self, data)
else:
for data_type in data_types:
if data_type in self.yaml_multi_representers:
node = self.yaml_multi_representers[data_type](self, data)
break
else:
if None in self.yaml_multi_representers:
node = self.yaml_multi_representers[None](self, data)
elif None in self.yaml_representers:
node = self.yaml_representers[None](self, data)
else:
node = ScalarNode(None, str(data))
#if alias_key is not None:
# self.represented_objects[alias_key] = node
return node
@classmethod
def add_representer(cls, data_type, representer):
if not 'yaml_representers' in cls.__dict__:
cls.yaml_representers = cls.yaml_representers.copy()
cls.yaml_representers[data_type] = representer
@classmethod
def add_multi_representer(cls, data_type, representer):
if not 'yaml_multi_representers' in cls.__dict__:
cls.yaml_multi_representers = cls.yaml_multi_representers.copy()
cls.yaml_multi_representers[data_type] = representer
def represent_scalar(self, tag, value, style=None):
if style is None:
style = self.default_style
node = ScalarNode(tag, value, style=style)
if self.alias_key is not None:
self.represented_objects[self.alias_key] = node
return node
def represent_sequence(self, tag, sequence, flow_style=None):
value = []
node = SequenceNode(tag, value, flow_style=flow_style)
if self.alias_key is not None:
self.represented_objects[self.alias_key] = node
best_style = True
for item in sequence:
node_item = self.represent_data(item)
if not (isinstance(node_item, ScalarNode) and not node_item.style):
best_style = False
value.append(node_item)
if flow_style is None:
if self.default_flow_style is not None:
node.flow_style = self.default_flow_style
else:
node.flow_style = best_style
return node
def represent_mapping(self, tag, mapping, flow_style=None):
value = []
node = MappingNode(tag, value, flow_style=flow_style)
if self.alias_key is not None:
self.represented_objects[self.alias_key] = node
best_style = True
if hasattr(mapping, 'items'):
mapping = list(mapping.items())
try:
mapping = sorted(mapping)
except TypeError:
pass
for item_key, item_value in mapping:
node_key = self.represent_data(item_key)
node_value = self.represent_data(item_value)
if not (isinstance(node_key, ScalarNode) and not node_key.style):
best_style = False
if not (isinstance(node_value, ScalarNode) and not node_value.style):
best_style = False
value.append((node_key, node_value))
if flow_style is None:
if self.default_flow_style is not None:
node.flow_style = self.default_flow_style
else:
node.flow_style = best_style
return node
def ignore_aliases(self, data):
return False
class SafeRepresenter(BaseRepresenter):
def ignore_aliases(self, data):
if data in [None, ()]:
return True
if isinstance(data, (str, bytes, bool, int, float)):
return True
def represent_none(self, data):
return self.represent_scalar('tag:yaml.org,2002:null', 'null')
def represent_str(self, data):
return self.represent_scalar('tag:yaml.org,2002:str', data)
def represent_binary(self, data):
if hasattr(base64, 'encodebytes'):
data = base64.encodebytes(data).decode('ascii')
else:
data = base64.encodestring(data).decode('ascii')
return self.represent_scalar('tag:yaml.org,2002:binary', data, style='|')
def represent_bool(self, data):
if data:
value = 'true'
else:
value = 'false'
return self.represent_scalar('tag:yaml.org,2002:bool', value)
def represent_int(self, data):
return self.represent_scalar('tag:yaml.org,2002:int', str(data))
inf_value = 1e300
while repr(inf_value) != repr(inf_value*inf_value):
inf_value *= inf_value
def represent_float(self, data):
if data != data or (data == 0.0 and data == 1.0):
value = '.nan'
elif data == self.inf_value:
value = '.inf'
elif data == -self.inf_value:
value = '-.inf'
else:
value = repr(data).lower()
# Note that in some cases `repr(data)` represents a float number
# without the decimal parts. For instance:
# >>> repr(1e17)
# '1e17'
# Unfortunately, this is not a valid float representation according
# to the definition of the `!!float` tag. We fix this by adding
# '.0' before the 'e' symbol.
if '.' not in value and 'e' in value:
value = value.replace('e', '.0e', 1)
return self.represent_scalar('tag:yaml.org,2002:float', value)
def represent_list(self, data):
#pairs = (len(data) > 0 and isinstance(data, list))
#if pairs:
# for item in data:
# if not isinstance(item, tuple) or len(item) != 2:
# pairs = False
# break
#if not pairs:
return self.represent_sequence('tag:yaml.org,2002:seq', data)
#value = []
#for item_key, item_value in data:
# value.append(self.represent_mapping(u'tag:yaml.org,2002:map',
# [(item_key, item_value)]))
#return SequenceNode(u'tag:yaml.org,2002:pairs', value)
def represent_dict(self, data):
return self.represent_mapping('tag:yaml.org,2002:map', data)
def represent_set(self, data):
value = {}
for key in data:
value[key] = None
return self.represent_mapping('tag:yaml.org,2002:set', value)
def represent_date(self, data):
value = data.isoformat()
return self.represent_scalar('tag:yaml.org,2002:timestamp', value)
def represent_datetime(self, data):
value = data.isoformat(' ')
return self.represent_scalar('tag:yaml.org,2002:timestamp', value)
def represent_yaml_object(self, tag, data, cls, flow_style=None):
if hasattr(data, '__getstate__'):
state = data.__getstate__()
else:
state = data.__dict__.copy()
return self.represent_mapping(tag, state, flow_style=flow_style)
def represent_undefined(self, data):
raise RepresenterError("cannot represent an object: %s" % data)
SafeRepresenter.add_representer(type(None),
SafeRepresenter.represent_none)
SafeRepresenter.add_representer(str,
SafeRepresenter.represent_str)
SafeRepresenter.add_representer(bytes,
SafeRepresenter.represent_binary)
SafeRepresenter.add_representer(bool,
SafeRepresenter.represent_bool)
SafeRepresenter.add_representer(int,
SafeRepresenter.represent_int)
SafeRepresenter.add_representer(float,
SafeRepresenter.represent_float)
SafeRepresenter.add_representer(list,
SafeRepresenter.represent_list)
SafeRepresenter.add_representer(tuple,
SafeRepresenter.represent_list)
SafeRepresenter.add_representer(dict,
SafeRepresenter.represent_dict)
SafeRepresenter.add_representer(set,
SafeRepresenter.represent_set)
SafeRepresenter.add_representer(datetime.date,
SafeRepresenter.represent_date)
SafeRepresenter.add_representer(datetime.datetime,
SafeRepresenter.represent_datetime)
SafeRepresenter.add_representer(None,
SafeRepresenter.represent_undefined)
class Representer(SafeRepresenter):
def represent_complex(self, data):
if data.imag == 0.0:
data = '%r' % data.real
elif data.real == 0.0:
data = '%rj' % data.imag
elif data.imag > 0:
data = '%r+%rj' % (data.real, data.imag)
else:
data = '%r%rj' % (data.real, data.imag)
return self.represent_scalar('tag:yaml.org,2002:python/complex', data)
def represent_tuple(self, data):
return self.represent_sequence('tag:yaml.org,2002:python/tuple', data)
def represent_name(self, data):
name = '%s.%s' % (data.__module__, data.__name__)
return self.represent_scalar('tag:yaml.org,2002:python/name:'+name, '')
def represent_module(self, data):
return self.represent_scalar(
'tag:yaml.org,2002:python/module:'+data.__name__, '')
def represent_object(self, data):
# We use __reduce__ API to save the data. data.__reduce__ returns
# a tuple of length 2-5:
# (function, args, state, listitems, dictitems)
# For reconstructing, we calls function(*args), then set its state,
# listitems, and dictitems if they are not None.
# A special case is when function.__name__ == '__newobj__'. In this
# case we create the object with args[0].__new__(*args).
# Another special case is when __reduce__ returns a string - we don't
# support it.
# We produce a !!python/object, !!python/object/new or
# !!python/object/apply node.
cls = type(data)
if cls in copyreg.dispatch_table:
reduce = copyreg.dispatch_table[cls](data)
elif hasattr(data, '__reduce_ex__'):
reduce = data.__reduce_ex__(2)
elif hasattr(data, '__reduce__'):
reduce = data.__reduce__()
else:
raise RepresenterError("cannot represent object: %r" % data)
reduce = (list(reduce)+[None]*5)[:5]
function, args, state, listitems, dictitems = reduce
args = list(args)
if state is None:
state = {}
if listitems is not None:
listitems = list(listitems)
if dictitems is not None:
dictitems = dict(dictitems)
if function.__name__ == '__newobj__':
function = args[0]
args = args[1:]
tag = 'tag:yaml.org,2002:python/object/new:'
newobj = True
else:
tag = 'tag:yaml.org,2002:python/object/apply:'
newobj = False
function_name = '%s.%s' % (function.__module__, function.__name__)
if not args and not listitems and not dictitems \
and isinstance(state, dict) and newobj:
return self.represent_mapping(
'tag:yaml.org,2002:python/object:'+function_name, state)
if not listitems and not dictitems \
and isinstance(state, dict) and not state:
return self.represent_sequence(tag+function_name, args)
value = {}
if args:
value['args'] = args
if state or not isinstance(state, dict):
value['state'] = state
if listitems:
value['listitems'] = listitems
if dictitems:
value['dictitems'] = dictitems
return self.represent_mapping(tag+function_name, value)
Representer.add_representer(complex,
Representer.represent_complex)
Representer.add_representer(tuple,
Representer.represent_tuple)
Representer.add_representer(type,
Representer.represent_name)
Representer.add_representer(types.FunctionType,
Representer.represent_name)
Representer.add_representer(types.BuiltinFunctionType,
Representer.represent_name)
Representer.add_representer(types.ModuleType,
Representer.represent_module)
Representer.add_multi_representer(object,
Representer.represent_object)
|
mit
|
[
199,
363,
452,
363,
275,
788,
1563,
497,
22682,
297,
283,
11090,
497,
22682,
297,
283,
497,
22682,
297,
272,
283,
497,
22682,
547,
418,
199,
199,
504,
1275,
705,
492,
627,
199,
504,
1275,
2415,
492,
627,
199,
199,
646,
2197,
12,
984,
12,
1331,
1135,
12,
2943,
12,
1300,
772,
199,
199,
533,
799,
22682,
547,
8,
23103,
547,
304,
272,
986,
199,
199,
533,
3523,
497,
22682,
26,
339,
8864,
63,
264,
7732,
878,
275,
1052,
272,
8864,
63,
3029,
63,
264,
7732,
878,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
304,
267,
291,
14,
885,
63,
2487,
275,
849,
63,
2487,
267,
291,
14,
885,
63,
1659,
63,
2487,
275,
849,
63,
1659,
63,
2487,
267,
291,
14,
264,
10317,
63,
1462,
275,
1052,
267,
291,
14,
785,
63,
19951,
275,
942,
267,
291,
14,
3620,
63,
498,
275,
488,
339,
347,
2954,
8,
277,
12,
666,
304,
267,
1031,
275,
291,
14,
13063,
63,
576,
8,
576,
9,
267,
291,
14,
3549,
8,
932,
9,
267,
291,
14,
264,
10317,
63,
1462,
275,
1052,
267,
291,
14,
785,
63,
19951,
275,
942,
267,
291,
14,
3620,
63,
498,
275,
488,
339,
347,
2954,
63,
576,
8,
277,
12,
666,
304,
267,
340,
291,
14,
4247,
63,
8602,
8,
576,
304,
288,
291,
14,
3620,
63,
498,
275,
488,
267,
587,
26,
288,
291,
14,
3620,
63,
498,
275,
1305,
8,
576,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
340,
291,
14,
3620,
63,
498,
315,
291,
14,
264,
10317,
63,
1462,
26,
355,
1031,
275,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
355,
327,
692,
1031,
365,
488,
26,
355,
327,
259,
746,
799,
22682,
547,
480,
9931,
2251,
787,
440,
4370,
26,
450,
82,
2,
450,
666,
9,
355,
372,
1031,
288,
327,
277,
14,
264,
10317,
63,
1462,
59,
3620,
63,
498,
61,
275,
488,
288,
291,
14,
785,
63,
19951,
14,
740,
8,
576,
9,
267,
666,
63,
1313,
275,
730,
8,
576,
2843,
17335,
363,
267,
340,
666,
63,
1313,
59,
16,
61,
315,
291,
14,
5963,
63,
264,
7732,
878,
26,
288,
1031,
275,
291,
14,
5963,
63,
264,
7732,
878,
59,
576,
63,
1313,
59,
16,
2677,
8,
277,
12,
666,
9,
267,
587,
26,
288,
367,
666,
63,
466,
315,
666,
63,
1313,
26,
355,
340,
666,
63,
466,
315,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
576,
63,
466,
8738,
277,
12,
666,
9,
490,
2059,
288,
587,
26,
355,
340,
488,
315,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
403,
8738,
277,
12,
666,
9,
355,
916,
488,
315,
291,
14,
5963,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
264,
7732,
878,
59,
403,
8738,
277,
12,
666,
9,
355,
587,
26,
490,
1031,
275,
24289,
1716,
8,
403,
12,
620,
8,
576,
430,
267,
327,
692,
5162,
63,
498,
365,
440,
488,
26,
267,
327,
259,
291,
14,
264,
10317,
63,
1462,
59,
3620,
63,
498,
61,
275,
1031,
267,
372,
1031,
339,
768,
3744,
272,
347,
1050,
63,
264,
22682,
8,
1886,
12,
666,
63,
466,
12,
295,
22682,
304,
267,
340,
440,
283,
5963,
63,
264,
7732,
878,
7,
315,
843,
855,
807,
10651,
288,
843,
14,
5963,
63,
264,
7732,
878,
275,
843,
14,
5963,
63,
264,
7732,
878,
14,
1574,
342,
267,
843,
14,
5963,
63,
264,
7732,
878,
59,
576,
63,
466,
61,
275,
295,
22682,
339,
768,
3744,
272,
347,
1050,
63,
3029,
63,
264,
22682,
8,
1886,
12,
666,
63,
466,
12,
295,
22682,
304,
267,
340,
440,
283,
5963,
63,
3029,
63,
264,
7732,
878,
7,
315,
843,
855,
807,
10651,
288,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
275,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
14,
1574,
342,
267,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
576,
63,
466,
61,
275,
295,
22682,
339,
347,
2954,
63,
7033,
8,
277,
12,
1947,
12,
574,
12,
3449,
29,
403,
304,
267,
340,
3449,
365,
488,
26,
288,
3449,
275,
291,
14,
885,
63,
2487,
267,
1031,
275,
24289,
1716,
8,
1450,
12,
574,
12,
3449,
29,
2487,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
275,
1031,
267,
372,
1031,
339,
347,
2954,
63,
4041,
8,
277,
12,
1947,
12,
3414,
12,
6369,
63,
2487,
29,
403,
304,
267,
574,
275,
942,
267,
1031,
275,
10975,
1716,
8,
1450,
12,
574,
12,
6369,
63,
2487,
29,
1659,
63,
2487,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
275,
1031,
267,
5526,
63,
2487,
275,
715,
267,
367,
1242,
315,
3414,
26,
288,
1031,
63,
1053,
275,
291,
14,
13063,
63,
576,
8,
1053,
9,
288,
340,
440,
334,
6074,
8,
932,
63,
1053,
12,
24289,
1716,
9,
436,
440,
1031,
63,
1053,
14,
2487,
304,
355,
5526,
63,
2487,
275,
756,
288,
574,
14,
740,
8,
932,
63,
1053,
9,
267,
340,
6369,
63,
2487,
365,
488,
26,
288,
340,
291,
14,
885,
63,
1659,
63,
2487,
365,
440,
488,
26,
355,
1031,
14,
1659,
63,
2487,
275,
291,
14,
885,
63,
1659,
63,
2487,
288,
587,
26,
355,
1031,
14,
1659,
63,
2487,
275,
5526,
63,
2487,
267,
372,
1031,
339,
347,
2954,
63,
4745,
8,
277,
12,
1947,
12,
4412,
12,
6369,
63,
2487,
29,
403,
304,
267,
574,
275,
942,
267,
1031,
275,
12340,
1716,
8,
1450,
12,
574,
12,
6369,
63,
2487,
29,
1659,
63,
2487,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620
] |
[
363,
452,
363,
275,
788,
1563,
497,
22682,
297,
283,
11090,
497,
22682,
297,
283,
497,
22682,
297,
272,
283,
497,
22682,
547,
418,
199,
199,
504,
1275,
705,
492,
627,
199,
504,
1275,
2415,
492,
627,
199,
199,
646,
2197,
12,
984,
12,
1331,
1135,
12,
2943,
12,
1300,
772,
199,
199,
533,
799,
22682,
547,
8,
23103,
547,
304,
272,
986,
199,
199,
533,
3523,
497,
22682,
26,
339,
8864,
63,
264,
7732,
878,
275,
1052,
272,
8864,
63,
3029,
63,
264,
7732,
878,
275,
1052,
339,
347,
636,
826,
721,
277,
12,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
304,
267,
291,
14,
885,
63,
2487,
275,
849,
63,
2487,
267,
291,
14,
885,
63,
1659,
63,
2487,
275,
849,
63,
1659,
63,
2487,
267,
291,
14,
264,
10317,
63,
1462,
275,
1052,
267,
291,
14,
785,
63,
19951,
275,
942,
267,
291,
14,
3620,
63,
498,
275,
488,
339,
347,
2954,
8,
277,
12,
666,
304,
267,
1031,
275,
291,
14,
13063,
63,
576,
8,
576,
9,
267,
291,
14,
3549,
8,
932,
9,
267,
291,
14,
264,
10317,
63,
1462,
275,
1052,
267,
291,
14,
785,
63,
19951,
275,
942,
267,
291,
14,
3620,
63,
498,
275,
488,
339,
347,
2954,
63,
576,
8,
277,
12,
666,
304,
267,
340,
291,
14,
4247,
63,
8602,
8,
576,
304,
288,
291,
14,
3620,
63,
498,
275,
488,
267,
587,
26,
288,
291,
14,
3620,
63,
498,
275,
1305,
8,
576,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
340,
291,
14,
3620,
63,
498,
315,
291,
14,
264,
10317,
63,
1462,
26,
355,
1031,
275,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
355,
327,
692,
1031,
365,
488,
26,
355,
327,
259,
746,
799,
22682,
547,
480,
9931,
2251,
787,
440,
4370,
26,
450,
82,
2,
450,
666,
9,
355,
372,
1031,
288,
327,
277,
14,
264,
10317,
63,
1462,
59,
3620,
63,
498,
61,
275,
488,
288,
291,
14,
785,
63,
19951,
14,
740,
8,
576,
9,
267,
666,
63,
1313,
275,
730,
8,
576,
2843,
17335,
363,
267,
340,
666,
63,
1313,
59,
16,
61,
315,
291,
14,
5963,
63,
264,
7732,
878,
26,
288,
1031,
275,
291,
14,
5963,
63,
264,
7732,
878,
59,
576,
63,
1313,
59,
16,
2677,
8,
277,
12,
666,
9,
267,
587,
26,
288,
367,
666,
63,
466,
315,
666,
63,
1313,
26,
355,
340,
666,
63,
466,
315,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
576,
63,
466,
8738,
277,
12,
666,
9,
490,
2059,
288,
587,
26,
355,
340,
488,
315,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
403,
8738,
277,
12,
666,
9,
355,
916,
488,
315,
291,
14,
5963,
63,
264,
7732,
878,
26,
490,
1031,
275,
291,
14,
5963,
63,
264,
7732,
878,
59,
403,
8738,
277,
12,
666,
9,
355,
587,
26,
490,
1031,
275,
24289,
1716,
8,
403,
12,
620,
8,
576,
430,
267,
327,
692,
5162,
63,
498,
365,
440,
488,
26,
267,
327,
259,
291,
14,
264,
10317,
63,
1462,
59,
3620,
63,
498,
61,
275,
1031,
267,
372,
1031,
339,
768,
3744,
272,
347,
1050,
63,
264,
22682,
8,
1886,
12,
666,
63,
466,
12,
295,
22682,
304,
267,
340,
440,
283,
5963,
63,
264,
7732,
878,
7,
315,
843,
855,
807,
10651,
288,
843,
14,
5963,
63,
264,
7732,
878,
275,
843,
14,
5963,
63,
264,
7732,
878,
14,
1574,
342,
267,
843,
14,
5963,
63,
264,
7732,
878,
59,
576,
63,
466,
61,
275,
295,
22682,
339,
768,
3744,
272,
347,
1050,
63,
3029,
63,
264,
22682,
8,
1886,
12,
666,
63,
466,
12,
295,
22682,
304,
267,
340,
440,
283,
5963,
63,
3029,
63,
264,
7732,
878,
7,
315,
843,
855,
807,
10651,
288,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
275,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
14,
1574,
342,
267,
843,
14,
5963,
63,
3029,
63,
264,
7732,
878,
59,
576,
63,
466,
61,
275,
295,
22682,
339,
347,
2954,
63,
7033,
8,
277,
12,
1947,
12,
574,
12,
3449,
29,
403,
304,
267,
340,
3449,
365,
488,
26,
288,
3449,
275,
291,
14,
885,
63,
2487,
267,
1031,
275,
24289,
1716,
8,
1450,
12,
574,
12,
3449,
29,
2487,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
275,
1031,
267,
372,
1031,
339,
347,
2954,
63,
4041,
8,
277,
12,
1947,
12,
3414,
12,
6369,
63,
2487,
29,
403,
304,
267,
574,
275,
942,
267,
1031,
275,
10975,
1716,
8,
1450,
12,
574,
12,
6369,
63,
2487,
29,
1659,
63,
2487,
9,
267,
340,
291,
14,
3620,
63,
498,
365,
440,
488,
26,
288,
291,
14,
264,
10317,
63,
1462,
59,
277,
14,
3620,
63,
498,
61,
275,
1031,
267,
5526,
63,
2487,
275,
715,
267,
367,
1242,
315,
3414,
26,
288,
1031,
63,
1053,
275,
291,
14,
13063,
63,
576,
8,
1053,
9,
288,
340,
440,
334,
6074,
8,
932,
63,
1053,
12,
24289,
1716,
9,
436,
440,
1031,
63,
1053,
14,
2487,
304,
355,
5526,
63,
2487,
275,
756,
288,
574,
14,
740,
8,
932,
63,
1053,
9,
267,
340,
6369,
63,
2487,
365,
488,
26,
288,
340,
291,
14,
885,
63,
1659,
63,
2487,
365,
440,
488,
26,
355,
1031,
14,
1659,
63,
2487,
275,
291,
14,
885,
63,
1659,
63,
2487,
288,
587,
26,
355,
1031,
14,
1659,
63,
2487,
275,
5526,
63,
2487,
267,
372,
1031,
339,
347,
2954,
63,
4745,
8,
277,
12,
1947,
12,
4412,
12,
6369,
63,
2487,
29,
403,
304,
267,
574,
275,
942,
267,
1031,
275,
12340,
1716,
8,
1450,
12,
574,
12,
6369,
63,
2487,
29,
1659,
63,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
MultiRRomero/manhattan-map
|
lib/geopy-1.4.0-py2.6.egg/geopy/geocoders/bing.py
|
3
|
7138
|
"""
:class:`.Bing` geocoder.
"""
from geopy.compat import urlencode
from geopy.geocoders.base import Geocoder, DEFAULT_FORMAT_STRING, \
DEFAULT_TIMEOUT, DEFAULT_SCHEME
from geopy.location import Location
from geopy.util import logger, join_filter
__all__ = ("Bing", )
class Bing(Geocoder):
"""
Geocoder using the Bing Maps Locations API. Documentation at:
https://msdn.microsoft.com/en-us/library/ff701715.aspx
"""
def __init__(
self,
api_key,
format_string=DEFAULT_FORMAT_STRING,
scheme=DEFAULT_SCHEME,
timeout=DEFAULT_TIMEOUT,
proxies=None,
): # pylint: disable=R0913
"""Initialize a customized Bing geocoder with location-specific
address information and your Bing Maps API key.
:param string api_key: Should be a valid Bing Maps API key.
:param string format_string: String containing '%s' where the
string to geocode should be interpolated before querying the
geocoder. For example: '%s, Mountain View, CA'. The default
is just '%s'.
:param string scheme: Use 'https' or 'http' as the API URL's scheme.
Default is https. Note that SSL connections' certificates are not
verified.
.. versionadded:: 0.97
:param int timeout: Time, in seconds, to wait for the geocoding service
to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
exception.
.. versionadded:: 0.97
:param dict proxies: If specified, routes this geocoder's requests
through the specified proxy. E.g., {"https": "192.0.2.0"}. For
more information, see documentation on
:class:`urllib2.ProxyHandler`.
.. versionadded:: 0.96
"""
super(Bing, self).__init__(format_string, scheme, timeout, proxies)
self.api_key = api_key
self.api = "%s://dev.virtualearth.net/REST/v1/Locations" % self.scheme
def geocode(
self,
query,
exactly_one=True,
user_location=None,
timeout=None,
culture=None,
include_neighborhood=None,
include_country_code=False
): # pylint: disable=W0221
"""
Geocode an address.
:param string query: The address or query you wish to geocode.
:param bool exactly_one: Return one result or a list of results, if
available.
:param user_location: Prioritize results closer to
this location.
.. versionadded:: 0.96
:type user_location: :class:`geopy.point.Point`
:param int timeout: Time, in seconds, to wait for the geocoding service
to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
exception. Set this only if you wish to override, on this call
only, the value set during the geocoder's initialization.
.. versionadded:: 0.97
:param string culture: Affects the language of the response,
must be a two-letter country code.
.. versionadded:: 1.4.0
:param boolean include_neighborhood: Sets whether to include the
neighborhood field in the response.
.. versionadded:: 1.4.0
:param boolean include_country_code: Sets whether to include the
two-letter ISO code of the country in the response (field name
'countryRegionIso2').
.. versionadded:: 1.4.0
"""
params = {
'query': self.format_string % query,
'key': self.api_key
}
if user_location:
params['userLocation'] = ",".join(
(str(user_location.latitude), str(user_location.longitude))
)
if exactly_one is True:
params['maxResults'] = 1
if culture:
params['culture'] = culture
if include_neighborhood is not None:
params['includeNeighborhood'] = include_neighborhood
if include_country_code:
params['include'] = 'ciso2' # the only acceptable value
url = "?".join((self.api, urlencode(params)))
logger.debug("%s.geocode: %s", self.__class__.__name__, url)
return self._parse_json(
self._call_geocoder(url, timeout=timeout),
exactly_one
)
def reverse(self, query, exactly_one=True, timeout=None):
"""
Reverse geocode a point.
:param query: The coordinates for which you wish to obtain the
closest human-readable addresses.
:type query: :class:`geopy.point.Point`, list or tuple of (latitude,
longitude), or string as "%(latitude)s, %(longitude)s".
:param bool exactly_one: Return one result, or a list?
:param int timeout: Time, in seconds, to wait for the geocoding service
to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
exception. Set this only if you wish to override, on this call
only, the value set during the geocoder's initialization.
.. versionadded:: 0.97
"""
point = self._coerce_point_to_string(query)
params = {'key': self.api_key}
url = "%s/%s?%s" % (
self.api, point, urlencode(params))
logger.debug("%s.reverse: %s", self.__class__.__name__, url)
return self._parse_json(
self._call_geocoder(url, timeout=timeout),
exactly_one
)
@staticmethod
def _parse_json(doc, exactly_one=True): # pylint: disable=W0221
"""
Parse a location name, latitude, and longitude from an JSON response.
"""
resources = doc['resourceSets'][0]['resources']
if resources is None or not len(resources): # pragma: no cover
return None
def parse_resource(resource):
"""
Parse each return object.
"""
stripchars = ", \n"
addr = resource['address']
address = addr.get('addressLine', '').strip(stripchars)
city = addr.get('locality', '').strip(stripchars)
state = addr.get('adminDistrict', '').strip(stripchars)
zipcode = addr.get('postalCode', '').strip(stripchars)
country = addr.get('countryRegion', '').strip(stripchars)
city_state = join_filter(", ", [city, state])
place = join_filter(" ", [city_state, zipcode])
location = join_filter(", ", [address, place, country])
latitude = resource['point']['coordinates'][0] or None
longitude = resource['point']['coordinates'][1] or None
if latitude and longitude:
latitude = float(latitude)
longitude = float(longitude)
return Location(location, (latitude, longitude), resource)
if exactly_one:
return parse_resource(resources[0])
else:
return [parse_resource(resource) for resource in resources]
|
mit
|
[
624,
199,
26,
533,
5026,
34,
316,
64,
8509,
2693,
14,
199,
624,
199,
199,
504,
2312,
927,
14,
5819,
492,
16511,
199,
504,
2312,
927,
14,
6721,
2693,
83,
14,
1095,
492,
8875,
2693,
12,
6186,
63,
4807,
63,
5353,
12,
971,
272,
6186,
63,
8899,
12,
6186,
63,
30430,
199,
504,
2312,
927,
14,
1985,
492,
12625,
199,
504,
2312,
927,
14,
1974,
492,
2512,
12,
4263,
63,
1541,
421,
199,
363,
452,
363,
275,
1689,
34,
316,
401,
776,
421,
199,
533,
699,
316,
8,
10748,
2693,
304,
272,
408,
272,
8875,
2693,
1808,
314,
699,
316,
23673,
6263,
1298,
3261,
14,
15249,
737,
26,
267,
4178,
921,
706,
4272,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
556,
23,
9570,
1046,
14,
26146,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
288,
2986,
63,
498,
12,
288,
1475,
63,
875,
29,
3472,
63,
4807,
63,
5353,
12,
288,
5687,
29,
3472,
63,
30430,
12,
288,
2653,
29,
3472,
63,
8899,
12,
288,
14942,
29,
403,
12,
267,
3461,
221,
327,
4287,
26,
3507,
29,
50,
1643,
969,
267,
408,
9345,
282,
26707,
699,
316,
8509,
2693,
543,
2909,
13,
6100,
267,
2287,
2556,
436,
2195,
699,
316,
23673,
3261,
790,
14,
398,
520,
635,
1059,
2986,
63,
498,
26,
7719,
506,
282,
1686,
699,
316,
23673,
3261,
790,
14,
398,
520,
635,
1059,
1475,
63,
875,
26,
2624,
3035,
1543,
83,
7,
2382,
314,
288,
1059,
370,
8509,
600,
1077,
506,
23005,
972,
2544,
27405,
314,
288,
8509,
2693,
14,
2104,
2893,
26,
1543,
83,
12,
3930,
324,
877,
10935,
12,
7240,
1370,
710,
849,
288,
365,
2951,
1543,
83,
1370,
398,
520,
635,
1059,
5687,
26,
3645,
283,
2859,
7,
503,
283,
1014,
7,
465,
314,
3261,
2851,
1159,
5687,
14,
288,
3758,
365,
4178,
14,
3390,
626,
7799,
6947,
7,
14512,
787,
440,
288,
16317,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1109,
2653,
26,
4703,
12,
315,
4696,
12,
370,
3618,
367,
314,
8509,
1523,
2435,
288,
370,
22722,
2544,
17026,
282,
520,
533,
1705,
303,
927,
14,
2804,
14,
10748,
2693,
28682,
2204,
64,
288,
1919,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1211,
14942,
26,
982,
2013,
12,
15777,
642,
8509,
2693,
1159,
4145,
288,
4012,
314,
2013,
4566,
14,
662,
14,
71,
2020,
2420,
2859,
582,
298,
5756,
14,
16,
14,
18,
14,
16,
3570,
14,
2104,
288,
1655,
2556,
12,
1937,
3794,
641,
288,
520,
533,
1705,
4078,
18,
14,
4936,
2461,
2313,
953,
2508,
7445,
447,
378,
14,
2534,
267,
408,
267,
1613,
8,
34,
316,
12,
291,
2843,
826,
721,
908,
63,
875,
12,
5687,
12,
2653,
12,
14942,
9,
267,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
267,
291,
14,
1246,
275,
2071,
83,
921,
2374,
14,
4549,
1458,
4025,
273,
14,
846,
15,
15740,
15,
86,
17,
15,
27727,
2,
450,
291,
14,
5512,
339,
347,
8509,
600,
8,
288,
291,
12,
288,
1827,
12,
288,
8840,
63,
368,
29,
549,
12,
288,
922,
63,
1985,
29,
403,
12,
288,
2653,
29,
403,
12,
288,
286,
427,
608,
29,
403,
12,
288,
2387,
63,
13881,
10422,
29,
403,
12,
288,
2387,
63,
6063,
63,
600,
29,
797,
288,
3461,
221,
327,
4287,
26,
3507,
29,
55,
996,
2025,
267,
408,
267,
8875,
600,
376,
2287,
14,
398,
520,
635,
1059,
1827,
26,
710,
2287,
503,
1827,
1265,
13809,
370,
8509,
600,
14,
398,
520,
635,
2155,
8840,
63,
368,
26,
1432,
1373,
754,
503,
282,
769,
402,
2058,
12,
340,
288,
2808,
14,
398,
520,
635,
922,
63,
1985,
26,
8538,
269,
5277,
806,
2058,
2463,
332,
370,
288,
642,
2909,
14,
953,
2508,
7445,
447,
378,
14,
2534,
398,
520,
466,
922,
63,
1985,
26,
520,
533,
1705,
303,
927,
14,
1403,
14,
3428,
64,
398,
520,
635,
1109,
2653,
26,
4703,
12,
315,
4696,
12,
370,
3618,
367,
314,
8509,
1523,
2435,
288,
370,
22722,
2544,
17026,
282,
520,
533,
1705,
303,
927,
14,
2804,
14,
10748,
2693,
28682,
2204,
64,
288,
1919,
14,
2494,
642,
1454,
340,
1265,
13809,
370,
4278,
12,
641,
642,
1240,
288,
1454,
12,
314,
574,
663,
5309,
314,
8509,
2693,
1159,
11097,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1059,
286,
427,
608,
26,
437,
5551,
83,
314,
2637,
402,
314,
1177,
12,
288,
1471,
506,
282,
2877,
13,
9269,
9023,
1233,
14,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
398,
520,
635,
5046,
2387,
63,
13881,
10422,
26,
10729,
3775,
370,
2387,
314,
288,
15503,
10422,
901,
315,
314,
1177,
14,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
398,
520,
635,
5046,
2387,
63,
6063,
63,
600,
26,
10729,
3775,
370,
2387,
314,
288,
2877,
13,
9269,
9055,
1233,
402,
314,
9023,
315,
314,
1177,
334,
698,
536,
288,
283,
6063,
10708,
41,
1152,
18,
1959,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
267,
408,
267,
1862,
275,
469,
288,
283,
1131,
356,
291,
14,
908,
63,
875,
450,
1827,
12,
288,
283,
498,
356,
291,
14,
1246,
63,
498,
267,
789,
267,
340,
922,
63,
1985,
26,
288,
1862,
459,
751,
6592,
418,
275,
19089,
904,
8,
355,
334,
495,
8,
751,
63,
1985,
14,
13331,
395,
620,
8,
751,
63,
1985,
14,
13803,
430,
288,
776,
267,
340,
8840,
63,
368,
365,
715,
26,
288,
1862,
459,
988,
6579,
418,
275,
413,
267,
340,
286,
427,
608,
26,
288,
1862,
459,
67,
427,
608,
418,
275,
286,
427,
608,
267,
340,
2387,
63,
13881,
10422,
365,
440,
488,
26,
288,
1862,
459,
2613,
13779,
10422,
418,
275,
2387,
63,
13881,
10422,
267,
340,
2387,
63,
6063,
63,
600,
26,
288,
1862,
459,
2613,
418,
275,
283,
67,
4595,
18,
7,
221,
327,
314,
1454,
14712,
574,
398,
1166,
275,
23665,
1674,
904,
1332,
277,
14,
1246,
12,
16511,
8,
1162,
1724,
267,
2512,
14,
1757,
3647,
83,
14,
6721,
600,
26,
450,
83,
401,
291,
855,
533,
4914,
354,
3108,
1166,
9,
267,
372,
291,
423,
1122,
63,
1001,
8,
288,
291,
423
] |
[
199,
26,
533,
5026,
34,
316,
64,
8509,
2693,
14,
199,
624,
199,
199,
504,
2312,
927,
14,
5819,
492,
16511,
199,
504,
2312,
927,
14,
6721,
2693,
83,
14,
1095,
492,
8875,
2693,
12,
6186,
63,
4807,
63,
5353,
12,
971,
272,
6186,
63,
8899,
12,
6186,
63,
30430,
199,
504,
2312,
927,
14,
1985,
492,
12625,
199,
504,
2312,
927,
14,
1974,
492,
2512,
12,
4263,
63,
1541,
421,
199,
363,
452,
363,
275,
1689,
34,
316,
401,
776,
421,
199,
533,
699,
316,
8,
10748,
2693,
304,
272,
408,
272,
8875,
2693,
1808,
314,
699,
316,
23673,
6263,
1298,
3261,
14,
15249,
737,
26,
267,
4178,
921,
706,
4272,
14,
17040,
14,
957,
15,
287,
13,
527,
15,
4342,
15,
556,
23,
9570,
1046,
14,
26146,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
288,
2986,
63,
498,
12,
288,
1475,
63,
875,
29,
3472,
63,
4807,
63,
5353,
12,
288,
5687,
29,
3472,
63,
30430,
12,
288,
2653,
29,
3472,
63,
8899,
12,
288,
14942,
29,
403,
12,
267,
3461,
221,
327,
4287,
26,
3507,
29,
50,
1643,
969,
267,
408,
9345,
282,
26707,
699,
316,
8509,
2693,
543,
2909,
13,
6100,
267,
2287,
2556,
436,
2195,
699,
316,
23673,
3261,
790,
14,
398,
520,
635,
1059,
2986,
63,
498,
26,
7719,
506,
282,
1686,
699,
316,
23673,
3261,
790,
14,
398,
520,
635,
1059,
1475,
63,
875,
26,
2624,
3035,
1543,
83,
7,
2382,
314,
288,
1059,
370,
8509,
600,
1077,
506,
23005,
972,
2544,
27405,
314,
288,
8509,
2693,
14,
2104,
2893,
26,
1543,
83,
12,
3930,
324,
877,
10935,
12,
7240,
1370,
710,
849,
288,
365,
2951,
1543,
83,
1370,
398,
520,
635,
1059,
5687,
26,
3645,
283,
2859,
7,
503,
283,
1014,
7,
465,
314,
3261,
2851,
1159,
5687,
14,
288,
3758,
365,
4178,
14,
3390,
626,
7799,
6947,
7,
14512,
787,
440,
288,
16317,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1109,
2653,
26,
4703,
12,
315,
4696,
12,
370,
3618,
367,
314,
8509,
1523,
2435,
288,
370,
22722,
2544,
17026,
282,
520,
533,
1705,
303,
927,
14,
2804,
14,
10748,
2693,
28682,
2204,
64,
288,
1919,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1211,
14942,
26,
982,
2013,
12,
15777,
642,
8509,
2693,
1159,
4145,
288,
4012,
314,
2013,
4566,
14,
662,
14,
71,
2020,
2420,
2859,
582,
298,
5756,
14,
16,
14,
18,
14,
16,
3570,
14,
2104,
288,
1655,
2556,
12,
1937,
3794,
641,
288,
520,
533,
1705,
4078,
18,
14,
4936,
2461,
2313,
953,
2508,
7445,
447,
378,
14,
2534,
267,
408,
267,
1613,
8,
34,
316,
12,
291,
2843,
826,
721,
908,
63,
875,
12,
5687,
12,
2653,
12,
14942,
9,
267,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
267,
291,
14,
1246,
275,
2071,
83,
921,
2374,
14,
4549,
1458,
4025,
273,
14,
846,
15,
15740,
15,
86,
17,
15,
27727,
2,
450,
291,
14,
5512,
339,
347,
8509,
600,
8,
288,
291,
12,
288,
1827,
12,
288,
8840,
63,
368,
29,
549,
12,
288,
922,
63,
1985,
29,
403,
12,
288,
2653,
29,
403,
12,
288,
286,
427,
608,
29,
403,
12,
288,
2387,
63,
13881,
10422,
29,
403,
12,
288,
2387,
63,
6063,
63,
600,
29,
797,
288,
3461,
221,
327,
4287,
26,
3507,
29,
55,
996,
2025,
267,
408,
267,
8875,
600,
376,
2287,
14,
398,
520,
635,
1059,
1827,
26,
710,
2287,
503,
1827,
1265,
13809,
370,
8509,
600,
14,
398,
520,
635,
2155,
8840,
63,
368,
26,
1432,
1373,
754,
503,
282,
769,
402,
2058,
12,
340,
288,
2808,
14,
398,
520,
635,
922,
63,
1985,
26,
8538,
269,
5277,
806,
2058,
2463,
332,
370,
288,
642,
2909,
14,
953,
2508,
7445,
447,
378,
14,
2534,
398,
520,
466,
922,
63,
1985,
26,
520,
533,
1705,
303,
927,
14,
1403,
14,
3428,
64,
398,
520,
635,
1109,
2653,
26,
4703,
12,
315,
4696,
12,
370,
3618,
367,
314,
8509,
1523,
2435,
288,
370,
22722,
2544,
17026,
282,
520,
533,
1705,
303,
927,
14,
2804,
14,
10748,
2693,
28682,
2204,
64,
288,
1919,
14,
2494,
642,
1454,
340,
1265,
13809,
370,
4278,
12,
641,
642,
1240,
288,
1454,
12,
314,
574,
663,
5309,
314,
8509,
2693,
1159,
11097,
14,
953,
2508,
7445,
447,
378,
14,
2576,
398,
520,
635,
1059,
286,
427,
608,
26,
437,
5551,
83,
314,
2637,
402,
314,
1177,
12,
288,
1471,
506,
282,
2877,
13,
9269,
9023,
1233,
14,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
398,
520,
635,
5046,
2387,
63,
13881,
10422,
26,
10729,
3775,
370,
2387,
314,
288,
15503,
10422,
901,
315,
314,
1177,
14,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
398,
520,
635,
5046,
2387,
63,
6063,
63,
600,
26,
10729,
3775,
370,
2387,
314,
288,
2877,
13,
9269,
9055,
1233,
402,
314,
9023,
315,
314,
1177,
334,
698,
536,
288,
283,
6063,
10708,
41,
1152,
18,
1959,
953,
2508,
7445,
447,
413,
14,
20,
14,
16,
267,
408,
267,
1862,
275,
469,
288,
283,
1131,
356,
291,
14,
908,
63,
875,
450,
1827,
12,
288,
283,
498,
356,
291,
14,
1246,
63,
498,
267,
789,
267,
340,
922,
63,
1985,
26,
288,
1862,
459,
751,
6592,
418,
275,
19089,
904,
8,
355,
334,
495,
8,
751,
63,
1985,
14,
13331,
395,
620,
8,
751,
63,
1985,
14,
13803,
430,
288,
776,
267,
340,
8840,
63,
368,
365,
715,
26,
288,
1862,
459,
988,
6579,
418,
275,
413,
267,
340,
286,
427,
608,
26,
288,
1862,
459,
67,
427,
608,
418,
275,
286,
427,
608,
267,
340,
2387,
63,
13881,
10422,
365,
440,
488,
26,
288,
1862,
459,
2613,
13779,
10422,
418,
275,
2387,
63,
13881,
10422,
267,
340,
2387,
63,
6063,
63,
600,
26,
288,
1862,
459,
2613,
418,
275,
283,
67,
4595,
18,
7,
221,
327,
314,
1454,
14712,
574,
398,
1166,
275,
23665,
1674,
904,
1332,
277,
14,
1246,
12,
16511,
8,
1162,
1724,
267,
2512,
14,
1757,
3647,
83,
14,
6721,
600,
26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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
] |
defzzd/UserDataBase-Heroku
|
venv/Lib/site-packages/pip/_vendor/requests/packages/chardet/gb2312freq.py
|
3132
|
36011
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# GB2312 most frequently used character table
#
# Char to FreqOrder table , from hz6763
# 512 --> 0.79 -- 0.79
# 1024 --> 0.92 -- 0.13
# 2048 --> 0.98 -- 0.06
# 6768 --> 1.00 -- 0.02
#
# Ideal Distribution Ratio = 0.79135/(1-0.79135) = 3.79
# Random Distribution Ration = 512 / (3755 - 512) = 0.157
#
# Typical Distribution Ratio about 25% of Ideal one, still much higher that RDR
GB2312_TYPICAL_DISTRIBUTION_RATIO = 0.9
GB2312_TABLE_SIZE = 3760
GB2312CharToFreqOrder = (
1671, 749,1443,2364,3924,3807,2330,3921,1704,3463,2691,1511,1515, 572,3191,2205,
2361, 224,2558, 479,1711, 963,3162, 440,4060,1905,2966,2947,3580,2647,3961,3842,
2204, 869,4207, 970,2678,5626,2944,2956,1479,4048, 514,3595, 588,1346,2820,3409,
249,4088,1746,1873,2047,1774, 581,1813, 358,1174,3590,1014,1561,4844,2245, 670,
1636,3112, 889,1286, 953, 556,2327,3060,1290,3141, 613, 185,3477,1367, 850,3820,
1715,2428,2642,2303,2732,3041,2562,2648,3566,3946,1349, 388,3098,2091,1360,3585,
152,1687,1539, 738,1559, 59,1232,2925,2267,1388,1249,1741,1679,2960, 151,1566,
1125,1352,4271, 924,4296, 385,3166,4459, 310,1245,2850, 70,3285,2729,3534,3575,
2398,3298,3466,1960,2265, 217,3647, 864,1909,2084,4401,2773,1010,3269,5152, 853,
3051,3121,1244,4251,1895, 364,1499,1540,2313,1180,3655,2268, 562, 715,2417,3061,
544, 336,3768,2380,1752,4075, 950, 280,2425,4382, 183,2759,3272, 333,4297,2155,
1688,2356,1444,1039,4540, 736,1177,3349,2443,2368,2144,2225, 565, 196,1482,3406,
927,1335,4147, 692, 878,1311,1653,3911,3622,1378,4200,1840,2969,3149,2126,1816,
2534,1546,2393,2760, 737,2494, 13, 447, 245,2747, 38,2765,2129,2589,1079, 606,
360, 471,3755,2890, 404, 848, 699,1785,1236, 370,2221,1023,3746,2074,2026,2023,
2388,1581,2119, 812,1141,3091,2536,1519, 804,2053, 406,1596,1090, 784, 548,4414,
1806,2264,2936,1100, 343,4114,5096, 622,3358, 743,3668,1510,1626,5020,3567,2513,
3195,4115,5627,2489,2991, 24,2065,2697,1087,2719, 48,1634, 315, 68, 985,2052,
198,2239,1347,1107,1439, 597,2366,2172, 871,3307, 919,2487,2790,1867, 236,2570,
1413,3794, 906,3365,3381,1701,1982,1818,1524,2924,1205, 616,2586,2072,2004, 575,
253,3099, 32,1365,1182, 197,1714,2454,1201, 554,3388,3224,2748, 756,2587, 250,
2567,1507,1517,3529,1922,2761,2337,3416,1961,1677,2452,2238,3153, 615, 911,1506,
1474,2495,1265,1906,2749,3756,3280,2161, 898,2714,1759,3450,2243,2444, 563, 26,
3286,2266,3769,3344,2707,3677, 611,1402, 531,1028,2871,4548,1375, 261,2948, 835,
1190,4134, 353, 840,2684,1900,3082,1435,2109,1207,1674, 329,1872,2781,4055,2686,
2104, 608,3318,2423,2957,2768,1108,3739,3512,3271,3985,2203,1771,3520,1418,2054,
1681,1153, 225,1627,2929, 162,2050,2511,3687,1954, 124,1859,2431,1684,3032,2894,
585,4805,3969,2869,2704,2088,2032,2095,3656,2635,4362,2209, 256, 518,2042,2105,
3777,3657, 643,2298,1148,1779, 190, 989,3544, 414, 11,2135,2063,2979,1471, 403,
3678, 126, 770,1563, 671,2499,3216,2877, 600,1179, 307,2805,4937,1268,1297,2694,
252,4032,1448,1494,1331,1394, 127,2256, 222,1647,1035,1481,3056,1915,1048, 873,
3651, 210, 33,1608,2516, 200,1520, 415, 102, 0,3389,1287, 817, 91,3299,2940,
836,1814, 549,2197,1396,1669,2987,3582,2297,2848,4528,1070, 687, 20,1819, 121,
1552,1364,1461,1968,2617,3540,2824,2083, 177, 948,4938,2291, 110,4549,2066, 648,
3359,1755,2110,2114,4642,4845,1693,3937,3308,1257,1869,2123, 208,1804,3159,2992,
2531,2549,3361,2418,1350,2347,2800,2568,1291,2036,2680, 72, 842,1990, 212,1233,
1154,1586, 75,2027,3410,4900,1823,1337,2710,2676, 728,2810,1522,3026,4995, 157,
755,1050,4022, 710, 785,1936,2194,2085,1406,2777,2400, 150,1250,4049,1206, 807,
1910, 534, 529,3309,1721,1660, 274, 39,2827, 661,2670,1578, 925,3248,3815,1094,
4278,4901,4252, 41,1150,3747,2572,2227,4501,3658,4902,3813,3357,3617,2884,2258,
887, 538,4187,3199,1294,2439,3042,2329,2343,2497,1255, 107, 543,1527, 521,3478,
3568, 194,5062, 15, 961,3870,1241,1192,2664, 66,5215,3260,2111,1295,1127,2152,
3805,4135, 901,1164,1976, 398,1278, 530,1460, 748, 904,1054,1966,1426, 53,2909,
509, 523,2279,1534, 536,1019, 239,1685, 460,2353, 673,1065,2401,3600,4298,2272,
1272,2363, 284,1753,3679,4064,1695, 81, 815,2677,2757,2731,1386, 859, 500,4221,
2190,2566, 757,1006,2519,2068,1166,1455, 337,2654,3203,1863,1682,1914,3025,1252,
1409,1366, 847, 714,2834,2038,3209, 964,2970,1901, 885,2553,1078,1756,3049, 301,
1572,3326, 688,2130,1996,2429,1805,1648,2930,3421,2750,3652,3088, 262,1158,1254,
389,1641,1812, 526,1719, 923,2073,1073,1902, 468, 489,4625,1140, 857,2375,3070,
3319,2863, 380, 116,1328,2693,1161,2244, 273,1212,1884,2769,3011,1775,1142, 461,
3066,1200,2147,2212, 790, 702,2695,4222,1601,1058, 434,2338,5153,3640, 67,2360,
4099,2502, 618,3472,1329, 416,1132, 830,2782,1807,2653,3211,3510,1662, 192,2124,
296,3979,1739,1611,3684, 23, 118, 324, 446,1239,1225, 293,2520,3814,3795,2535,
3116, 17,1074, 467,2692,2201, 387,2922, 45,1326,3055,1645,3659,2817, 958, 243,
1903,2320,1339,2825,1784,3289, 356, 576, 865,2315,2381,3377,3916,1088,3122,1713,
1655, 935, 628,4689,1034,1327, 441, 800, 720, 894,1979,2183,1528,5289,2702,1071,
4046,3572,2399,1571,3281, 79, 761,1103, 327, 134, 758,1899,1371,1615, 879, 442,
215,2605,2579, 173,2048,2485,1057,2975,3317,1097,2253,3801,4263,1403,1650,2946,
814,4968,3487,1548,2644,1567,1285, 2, 295,2636, 97, 946,3576, 832, 141,4257,
3273, 760,3821,3521,3156,2607, 949,1024,1733,1516,1803,1920,2125,2283,2665,3180,
1501,2064,3560,2171,1592, 803,3518,1416, 732,3897,4258,1363,1362,2458, 119,1427,
602,1525,2608,1605,1639,3175, 694,3064, 10, 465, 76,2000,4846,4208, 444,3781,
1619,3353,2206,1273,3796, 740,2483, 320,1723,2377,3660,2619,1359,1137,1762,1724,
2345,2842,1850,1862, 912, 821,1866, 612,2625,1735,2573,3369,1093, 844, 89, 937,
930,1424,3564,2413,2972,1004,3046,3019,2011, 711,3171,1452,4178, 428, 801,1943,
432, 445,2811, 206,4136,1472, 730, 349, 73, 397,2802,2547, 998,1637,1167, 789,
396,3217, 154,1218, 716,1120,1780,2819,4826,1931,3334,3762,2139,1215,2627, 552,
3664,3628,3232,1405,2383,3111,1356,2652,3577,3320,3101,1703, 640,1045,1370,1246,
4996, 371,1575,2436,1621,2210, 984,4033,1734,2638, 16,4529, 663,2755,3255,1451,
3917,2257,1253,1955,2234,1263,2951, 214,1229, 617, 485, 359,1831,1969, 473,2310,
750,2058, 165, 80,2864,2419, 361,4344,2416,2479,1134, 796,3726,1266,2943, 860,
2715, 938, 390,2734,1313,1384, 248, 202, 877,1064,2854, 522,3907, 279,1602, 297,
2357, 395,3740, 137,2075, 944,4089,2584,1267,3802, 62,1533,2285, 178, 176, 780,
2440, 201,3707, 590, 478,1560,4354,2117,1075, 30, 74,4643,4004,1635,1441,2745,
776,2596, 238,1077,1692,1912,2844, 605, 499,1742,3947, 241,3053, 980,1749, 936,
2640,4511,2582, 515,1543,2162,5322,2892,2993, 890,2148,1924, 665,1827,3581,1032,
968,3163, 339,1044,1896, 270, 583,1791,1720,4367,1194,3488,3669, 43,2523,1657,
163,2167, 290,1209,1622,3378, 550, 634,2508,2510, 695,2634,2384,2512,1476,1414,
220,1469,2341,2138,2852,3183,2900,4939,2865,3502,1211,3680, 854,3227,1299,2976,
3172, 186,2998,1459, 443,1067,3251,1495, 321,1932,3054, 909, 753,1410,1828, 436,
2441,1119,1587,3164,2186,1258, 227, 231,1425,1890,3200,3942, 247, 959, 725,5254,
2741, 577,2158,2079, 929, 120, 174, 838,2813, 591,1115, 417,2024, 40,3240,1536,
1037, 291,4151,2354, 632,1298,2406,2500,3535,1825,1846,3451, 205,1171, 345,4238,
18,1163, 811, 685,2208,1217, 425,1312,1508,1175,4308,2552,1033, 587,1381,3059,
2984,3482, 340,1316,4023,3972, 792,3176, 519, 777,4690, 918, 933,4130,2981,3741,
90,3360,2911,2200,5184,4550, 609,3079,2030, 272,3379,2736, 363,3881,1130,1447,
286, 779, 357,1169,3350,3137,1630,1220,2687,2391, 747,1277,3688,2618,2682,2601,
1156,3196,5290,4034,3102,1689,3596,3128, 874, 219,2783, 798, 508,1843,2461, 269,
1658,1776,1392,1913,2983,3287,2866,2159,2372, 829,4076, 46,4253,2873,1889,1894,
915,1834,1631,2181,2318, 298, 664,2818,3555,2735, 954,3228,3117, 527,3511,2173,
681,2712,3033,2247,2346,3467,1652, 155,2164,3382, 113,1994, 450, 899, 494, 994,
1237,2958,1875,2336,1926,3727, 545,1577,1550, 633,3473, 204,1305,3072,2410,1956,
2471, 707,2134, 841,2195,2196,2663,3843,1026,4940, 990,3252,4997, 368,1092, 437,
3212,3258,1933,1829, 675,2977,2893, 412, 943,3723,4644,3294,3283,2230,2373,5154,
2389,2241,2661,2323,1404,2524, 593, 787, 677,3008,1275,2059, 438,2709,2609,2240,
2269,2246,1446, 36,1568,1373,3892,1574,2301,1456,3962, 693,2276,5216,2035,1143,
2720,1919,1797,1811,2763,4137,2597,1830,1699,1488,1198,2090, 424,1694, 312,3634,
3390,4179,3335,2252,1214, 561,1059,3243,2295,2561, 975,5155,2321,2751,3772, 472,
1537,3282,3398,1047,2077,2348,2878,1323,3340,3076, 690,2906, 51, 369, 170,3541,
1060,2187,2688,3670,2541,1083,1683, 928,3918, 459, 109,4427, 599,3744,4286, 143,
2101,2730,2490, 82,1588,3036,2121, 281,1860, 477,4035,1238,2812,3020,2716,3312,
1530,2188,2055,1317, 843, 636,1808,1173,3495, 649, 181,1002, 147,3641,1159,2414,
3750,2289,2795, 813,3123,2610,1136,4368, 5,3391,4541,2174, 420, 429,1728, 754,
1228,2115,2219, 347,2223,2733, 735,1518,3003,2355,3134,1764,3948,3329,1888,2424,
1001,1234,1972,3321,3363,1672,1021,1450,1584, 226, 765, 655,2526,3404,3244,2302,
3665, 731, 594,2184, 319,1576, 621, 658,2656,4299,2099,3864,1279,2071,2598,2739,
795,3086,3699,3908,1707,2352,2402,1382,3136,2475,1465,4847,3496,3865,1085,3004,
2591,1084, 213,2287,1963,3565,2250, 822, 793,4574,3187,1772,1789,3050, 595,1484,
1959,2770,1080,2650, 456, 422,2996, 940,3322,4328,4345,3092,2742, 965,2784, 739,
4124, 952,1358,2498,2949,2565, 332,2698,2378, 660,2260,2473,4194,3856,2919, 535,
1260,2651,1208,1428,1300,1949,1303,2942, 433,2455,2450,1251,1946, 614,1269, 641,
1306,1810,2737,3078,2912, 564,2365,1419,1415,1497,4460,2367,2185,1379,3005,1307,
3218,2175,1897,3063, 682,1157,4040,4005,1712,1160,1941,1399, 394, 402,2952,1573,
1151,2986,2404, 862, 299,2033,1489,3006, 346, 171,2886,3401,1726,2932, 168,2533,
47,2507,1030,3735,1145,3370,1395,1318,1579,3609,4560,2857,4116,1457,2529,1965,
504,1036,2690,2988,2405, 745,5871, 849,2397,2056,3081, 863,2359,3857,2096, 99,
1397,1769,2300,4428,1643,3455,1978,1757,3718,1440, 35,4879,3742,1296,4228,2280,
160,5063,1599,2013, 166, 520,3479,1646,3345,3012, 490,1937,1545,1264,2182,2505,
1096,1188,1369,1436,2421,1667,2792,2460,1270,2122, 727,3167,2143, 806,1706,1012,
1800,3037, 960,2218,1882, 805, 139,2456,1139,1521, 851,1052,3093,3089, 342,2039,
744,5097,1468,1502,1585,2087, 223, 939, 326,2140,2577, 892,2481,1623,4077, 982,
3708, 135,2131, 87,2503,3114,2326,1106, 876,1616, 547,2997,2831,2093,3441,4530,
4314, 9,3256,4229,4148, 659,1462,1986,1710,2046,2913,2231,4090,4880,5255,3392,
3274,1368,3689,4645,1477, 705,3384,3635,1068,1529,2941,1458,3782,1509, 100,1656,
2548, 718,2339, 408,1590,2780,3548,1838,4117,3719,1345,3530, 717,3442,2778,3220,
2898,1892,4590,3614,3371,2043,1998,1224,3483, 891, 635, 584,2559,3355, 733,1766,
1729,1172,3789,1891,2307, 781,2982,2271,1957,1580,5773,2633,2005,4195,3097,1535,
3213,1189,1934,5693,3262, 586,3118,1324,1598, 517,1564,2217,1868,1893,4445,3728,
2703,3139,1526,1787,1992,3882,2875,1549,1199,1056,2224,1904,2711,5098,4287, 338,
1993,3129,3489,2689,1809,2815,1997, 957,1855,3898,2550,3275,3057,1105,1319, 627,
1505,1911,1883,3526, 698,3629,3456,1833,1431, 746, 77,1261,2017,2296,1977,1885,
125,1334,1600, 525,1798,1109,2222,1470,1945, 559,2236,1186,3443,2476,1929,1411,
2411,3135,1777,3372,2621,1841,1613,3229, 668,1430,1839,2643,2916, 195,1989,2671,
2358,1387, 629,3205,2293,5256,4439, 123,1310, 888,1879,4300,3021,3605,1003,1162,
3192,2910,2010, 140,2395,2859, 55,1082,2012,2901, 662, 419,2081,1438, 680,2774,
4654,3912,1620,1731,1625,5035,4065,2328, 512,1344, 802,5443,2163,2311,2537, 524,
3399, 98,1155,2103,1918,2606,3925,2816,1393,2465,1504,3773,2177,3963,1478,4346,
180,1113,4655,3461,2028,1698, 833,2696,1235,1322,1594,4408,3623,3013,3225,2040,
3022, 541,2881, 607,3632,2029,1665,1219, 639,1385,1686,1099,2803,3231,1938,3188,
2858, 427, 676,2772,1168,2025, 454,3253,2486,3556, 230,1950, 580, 791,1991,1280,
1086,1974,2034, 630, 257,3338,2788,4903,1017, 86,4790, 966,2789,1995,1696,1131,
259,3095,4188,1308, 179,1463,5257, 289,4107,1248, 42,3413,1725,2288, 896,1947,
774,4474,4254, 604,3430,4264, 392,2514,2588, 452, 237,1408,3018, 988,4531,1970,
3034,3310, 540,2370,1562,1288,2990, 502,4765,1147, 4,1853,2708, 207, 294,2814,
4078,2902,2509, 684, 34,3105,3532,2551, 644, 709,2801,2344, 573,1727,3573,3557,
2021,1081,3100,4315,2100,3681, 199,2263,1837,2385, 146,3484,1195,2776,3949, 997,
1939,3973,1008,1091,1202,1962,1847,1149,4209,5444,1076, 493, 117,5400,2521, 972,
1490,2934,1796,4542,2374,1512,2933,2657, 413,2888,1135,2762,2314,2156,1355,2369,
766,2007,2527,2170,3124,2491,2593,2632,4757,2437, 234,3125,3591,1898,1750,1376,
1942,3468,3138, 570,2127,2145,3276,4131, 962, 132,1445,4196, 19, 941,3624,3480,
3366,1973,1374,4461,3431,2629, 283,2415,2275, 808,2887,3620,2112,2563,1353,3610,
955,1089,3103,1053, 96, 88,4097, 823,3808,1583, 399, 292,4091,3313, 421,1128,
642,4006, 903,2539,1877,2082, 596, 29,4066,1790, 722,2157, 130, 995,1569, 769,
1485, 464, 513,2213, 288,1923,1101,2453,4316, 133, 486,2445, 50, 625, 487,2207,
57, 423, 481,2962, 159,3729,1558, 491, 303, 482, 501, 240,2837, 112,3648,2392,
1783, 362, 8,3433,3422, 610,2793,3277,1390,1284,1654, 21,3823, 734, 367, 623,
193, 287, 374,1009,1483, 816, 476, 313,2255,2340,1262,2150,2899,1146,2581, 782,
2116,1659,2018,1880, 255,3586,3314,1110,2867,2137,2564, 986,2767,5185,2006, 650,
158, 926, 762, 881,3157,2717,2362,3587, 306,3690,3245,1542,3077,2427,1691,2478,
2118,2985,3490,2438, 539,2305, 983, 129,1754, 355,4201,2386, 827,2923, 104,1773,
2838,2771, 411,2905,3919, 376, 767, 122,1114, 828,2422,1817,3506, 266,3460,1007,
1609,4998, 945,2612,4429,2274, 726,1247,1964,2914,2199,2070,4002,4108, 657,3323,
1422, 579, 455,2764,4737,1222,2895,1670, 824,1223,1487,2525, 558, 861,3080, 598,
2659,2515,1967, 752,2583,2376,2214,4180, 977, 704,2464,4999,2622,4109,1210,2961,
819,1541, 142,2284, 44, 418, 457,1126,3730,4347,4626,1644,1876,3671,1864, 302,
1063,5694, 624, 723,1984,3745,1314,1676,2488,1610,1449,3558,3569,2166,2098, 409,
1011,2325,3704,2306, 818,1732,1383,1824,1844,3757, 999,2705,3497,1216,1423,2683,
2426,2954,2501,2726,2229,1475,2554,5064,1971,1794,1666,2014,1343, 783, 724, 191,
2434,1354,2220,5065,1763,2752,2472,4152, 131, 175,2885,3434, 92,1466,4920,2616,
3871,3872,3866, 128,1551,1632, 669,1854,3682,4691,4125,1230, 188,2973,3290,1302,
1213, 560,3266, 917, 763,3909,3249,1760, 868,1958, 764,1782,2097, 145,2277,3774,
4462, 64,1491,3062, 971,2132,3606,2442, 221,1226,1617, 218, 323,1185,3207,3147,
571, 619,1473,1005,1744,2281, 449,1887,2396,3685, 275, 375,3816,1743,3844,3731,
845,1983,2350,4210,1377, 773, 967,3499,3052,3743,2725,4007,1697,1022,3943,1464,
3264,2855,2722,1952,1029,2839,2467, 84,4383,2215, 820,1391,2015,2448,3672, 377,
1948,2168, 797,2545,3536,2578,2645, 94,2874,1678, 405,1259,3071, 771, 546,1315,
470,1243,3083, 895,2468, 981, 969,2037, 846,4181, 653,1276,2928, 14,2594, 557,
3007,2474, 156, 902,1338,1740,2574, 537,2518, 973,2282,2216,2433,1928, 138,2903,
1293,2631,1612, 646,3457, 839,2935, 111, 496,2191,2847, 589,3186, 149,3994,2060,
4031,2641,4067,3145,1870, 37,3597,2136,1025,2051,3009,3383,3549,1121,1016,3261,
1301, 251,2446,2599,2153, 872,3246, 637, 334,3705, 831, 884, 921,3065,3140,4092,
2198,1944, 246,2964, 108,2045,1152,1921,2308,1031, 203,3173,4170,1907,3890, 810,
1401,2003,1690, 506, 647,1242,2828,1761,1649,3208,2249,1589,3709,2931,5156,1708,
498, 666,2613, 834,3817,1231, 184,2851,1124, 883,3197,2261,3710,1765,1553,2658,
1178,2639,2351, 93,1193, 942,2538,2141,4402, 235,1821, 870,1591,2192,1709,1871,
3341,1618,4126,2595,2334, 603, 651, 69, 701, 268,2662,3411,2555,1380,1606, 503,
448, 254,2371,2646, 574,1187,2309,1770, 322,2235,1292,1801, 305, 566,1133, 229,
2067,2057, 706, 167, 483,2002,2672,3295,1820,3561,3067, 316, 378,2746,3452,1112,
136,1981, 507,1651,2917,1117, 285,4591, 182,2580,3522,1304, 335,3303,1835,2504,
1795,1792,2248, 674,1018,2106,2449,1857,2292,2845, 976,3047,1781,2600,2727,1389,
1281, 52,3152, 153, 265,3950, 672,3485,3951,4463, 430,1183, 365, 278,2169, 27,
1407,1336,2304, 209,1340,1730,2202,1852,2403,2883, 979,1737,1062, 631,2829,2542,
3876,2592, 825,2086,2226,3048,3625, 352,1417,3724, 542, 991, 431,1351,3938,1861,
2294, 826,1361,2927,3142,3503,1738, 463,2462,2723, 582,1916,1595,2808, 400,3845,
3891,2868,3621,2254, 58,2492,1123, 910,2160,2614,1372,1603,1196,1072,3385,1700,
3267,1980, 696, 480,2430, 920, 799,1570,2920,1951,2041,4047,2540,1321,4223,2469,
3562,2228,1271,2602, 401,2833,3351,2575,5157, 907,2312,1256, 410, 263,3507,1582,
996, 678,1849,2316,1480, 908,3545,2237, 703,2322, 667,1826,2849,1531,2604,2999,
2407,3146,2151,2630,1786,3711, 469,3542, 497,3899,2409, 858, 837,4446,3393,1274,
786, 620,1845,2001,3311, 484, 308,3367,1204,1815,3691,2332,1532,2557,1842,2020,
2724,1927,2333,4440, 567, 22,1673,2728,4475,1987,1858,1144,1597, 101,1832,3601,
12, 974,3783,4391, 951,1412, 1,3720, 453,4608,4041, 528,1041,1027,3230,2628,
1129, 875,1051,3291,1203,2262,1069,2860,2799,2149,2615,3278, 144,1758,3040, 31,
475,1680, 366,2685,3184, 311,1642,4008,2466,5036,1593,1493,2809, 216,1420,1668,
233, 304,2128,3284, 232,1429,1768,1040,2008,3407,2740,2967,2543, 242,2133, 778,
1565,2022,2620, 505,2189,2756,1098,2273, 372,1614, 708, 553,2846,2094,2278, 169,
3626,2835,4161, 228,2674,3165, 809,1454,1309, 466,1705,1095, 900,3423, 880,2667,
3751,5258,2317,3109,2571,4317,2766,1503,1342, 866,4447,1118, 63,2076, 314,1881,
1348,1061, 172, 978,3515,1747, 532, 511,3970, 6, 601, 905,2699,3300,1751, 276,
1467,3725,2668, 65,4239,2544,2779,2556,1604, 578,2451,1802, 992,2331,2624,1320,
3446, 713,1513,1013, 103,2786,2447,1661, 886,1702, 916, 654,3574,2031,1556, 751,
2178,2821,2179,1498,1538,2176, 271, 914,2251,2080,1325, 638,1953,2937,3877,2432,
2754, 95,3265,1716, 260,1227,4083, 775, 106,1357,3254, 426,1607, 555,2480, 772,
1985, 244,2546, 474, 495,1046,2611,1851,2061, 71,2089,1675,2590, 742,3758,2843,
3222,1433, 267,2180,2576,2826,2233,2092,3913,2435, 956,1745,3075, 856,2113,1116,
451, 3,1988,2896,1398, 993,2463,1878,2049,1341,2718,2721,2870,2108, 712,2904,
4363,2753,2324, 277,2872,2349,2649, 384, 987, 435, 691,3000, 922, 164,3939, 652,
1500,1184,4153,2482,3373,2165,4848,2335,3775,3508,3154,2806,2830,1554,2102,1664,
2530,1434,2408, 893,1547,2623,3447,2832,2242,2532,3169,2856,3223,2078, 49,3770,
3469, 462, 318, 656,2259,3250,3069, 679,1629,2758, 344,1138,1104,3120,1836,1283,
3115,2154,1437,4448, 934, 759,1999, 794,2862,1038, 533,2560,1722,2342, 855,2626,
1197,1663,4476,3127, 85,4240,2528, 25,1111,1181,3673, 407,3470,4561,2679,2713,
768,1925,2841,3986,1544,1165, 932, 373,1240,2146,1930,2673, 721,4766, 354,4333,
391,2963, 187, 61,3364,1442,1102, 330,1940,1767, 341,3809,4118, 393,2496,2062,
2211, 105, 331, 300, 439, 913,1332, 626, 379,3304,1557, 328, 689,3952, 309,1555,
931, 317,2517,3027, 325, 569, 686,2107,3084, 60,1042,1333,2794, 264,3177,4014,
1628, 258,3712, 7,4464,1176,1043,1778, 683, 114,1975, 78,1492, 383,1886, 510,
386, 645,5291,2891,2069,3305,4138,3867,2939,2603,2493,1935,1066,1848,3588,1015,
1282,1289,4609, 697,1453,3044,2666,3611,1856,2412, 54, 719,1330, 568,3778,2459,
1748, 788, 492, 551,1191,1000, 488,3394,3763, 282,1799, 348,2016,1523,3155,2390,
1049, 382,2019,1788,1170, 729,2968,3523, 897,3926,2785,2938,3292, 350,2319,3238,
1718,1717,2655,3453,3143,4465, 161,2889,2980,2009,1421, 56,1908,1640,2387,2232,
1917,1874,2477,4921, 148, 83,3438, 592,4245,2882,1822,1055, 741, 115,1496,1624,
381,1638,4592,1020, 516,3214, 458, 947,4575,1432, 211,1514,2926,1865,2142, 189,
852,1221,1400,1486, 882,2299,4036, 351, 28,1122, 700,6479,6480,6481,6482,6483, # last 512
#Everything below is of no interest for detection purpose
5508,6484,3900,3414,3974,4441,4024,3537,4037,5628,5099,3633,6485,3148,6486,3636,
5509,3257,5510,5973,5445,5872,4941,4403,3174,4627,5873,6276,2286,4230,5446,5874,
5122,6102,6103,4162,5447,5123,5323,4849,6277,3980,3851,5066,4246,5774,5067,6278,
3001,2807,5695,3346,5775,5974,5158,5448,6487,5975,5976,5776,3598,6279,5696,4806,
4211,4154,6280,6488,6489,6490,6281,4212,5037,3374,4171,6491,4562,4807,4722,4827,
5977,6104,4532,4079,5159,5324,5160,4404,3858,5359,5875,3975,4288,4610,3486,4512,
5325,3893,5360,6282,6283,5560,2522,4231,5978,5186,5449,2569,3878,6284,5401,3578,
4415,6285,4656,5124,5979,2506,4247,4449,3219,3417,4334,4969,4329,6492,4576,4828,
4172,4416,4829,5402,6286,3927,3852,5361,4369,4830,4477,4867,5876,4173,6493,6105,
4657,6287,6106,5877,5450,6494,4155,4868,5451,3700,5629,4384,6288,6289,5878,3189,
4881,6107,6290,6495,4513,6496,4692,4515,4723,5100,3356,6497,6291,3810,4080,5561,
3570,4430,5980,6498,4355,5697,6499,4724,6108,6109,3764,4050,5038,5879,4093,3226,
6292,5068,5217,4693,3342,5630,3504,4831,4377,4466,4309,5698,4431,5777,6293,5778,
4272,3706,6110,5326,3752,4676,5327,4273,5403,4767,5631,6500,5699,5880,3475,5039,
6294,5562,5125,4348,4301,4482,4068,5126,4593,5700,3380,3462,5981,5563,3824,5404,
4970,5511,3825,4738,6295,6501,5452,4516,6111,5881,5564,6502,6296,5982,6503,4213,
4163,3454,6504,6112,4009,4450,6113,4658,6297,6114,3035,6505,6115,3995,4904,4739,
4563,4942,4110,5040,3661,3928,5362,3674,6506,5292,3612,4791,5565,4149,5983,5328,
5259,5021,4725,4577,4564,4517,4364,6298,5405,4578,5260,4594,4156,4157,5453,3592,
3491,6507,5127,5512,4709,4922,5984,5701,4726,4289,6508,4015,6116,5128,4628,3424,
4241,5779,6299,4905,6509,6510,5454,5702,5780,6300,4365,4923,3971,6511,5161,3270,
3158,5985,4100, 867,5129,5703,6117,5363,3695,3301,5513,4467,6118,6512,5455,4232,
4242,4629,6513,3959,4478,6514,5514,5329,5986,4850,5162,5566,3846,4694,6119,5456,
4869,5781,3779,6301,5704,5987,5515,4710,6302,5882,6120,4392,5364,5705,6515,6121,
6516,6517,3736,5988,5457,5989,4695,2457,5883,4551,5782,6303,6304,6305,5130,4971,
6122,5163,6123,4870,3263,5365,3150,4871,6518,6306,5783,5069,5706,3513,3498,4409,
5330,5632,5366,5458,5459,3991,5990,4502,3324,5991,5784,3696,4518,5633,4119,6519,
4630,5634,4417,5707,4832,5992,3418,6124,5993,5567,4768,5218,6520,4595,3458,5367,
6125,5635,6126,4202,6521,4740,4924,6307,3981,4069,4385,6308,3883,2675,4051,3834,
4302,4483,5568,5994,4972,4101,5368,6309,5164,5884,3922,6127,6522,6523,5261,5460,
5187,4164,5219,3538,5516,4111,3524,5995,6310,6311,5369,3181,3386,2484,5188,3464,
5569,3627,5708,6524,5406,5165,4677,4492,6312,4872,4851,5885,4468,5996,6313,5709,
5710,6128,2470,5886,6314,5293,4882,5785,3325,5461,5101,6129,5711,5786,6525,4906,
6526,6527,4418,5887,5712,4808,2907,3701,5713,5888,6528,3765,5636,5331,6529,6530,
3593,5889,3637,4943,3692,5714,5787,4925,6315,6130,5462,4405,6131,6132,6316,5262,
6531,6532,5715,3859,5716,5070,4696,5102,3929,5788,3987,4792,5997,6533,6534,3920,
4809,5000,5998,6535,2974,5370,6317,5189,5263,5717,3826,6536,3953,5001,4883,3190,
5463,5890,4973,5999,4741,6133,6134,3607,5570,6000,4711,3362,3630,4552,5041,6318,
6001,2950,2953,5637,4646,5371,4944,6002,2044,4120,3429,6319,6537,5103,4833,6538,
6539,4884,4647,3884,6003,6004,4758,3835,5220,5789,4565,5407,6540,6135,5294,4697,
4852,6320,6321,3206,4907,6541,6322,4945,6542,6136,6543,6323,6005,4631,3519,6544,
5891,6545,5464,3784,5221,6546,5571,4659,6547,6324,6137,5190,6548,3853,6549,4016,
4834,3954,6138,5332,3827,4017,3210,3546,4469,5408,5718,3505,4648,5790,5131,5638,
5791,5465,4727,4318,6325,6326,5792,4553,4010,4698,3439,4974,3638,4335,3085,6006,
5104,5042,5166,5892,5572,6327,4356,4519,5222,5573,5333,5793,5043,6550,5639,5071,
4503,6328,6139,6551,6140,3914,3901,5372,6007,5640,4728,4793,3976,3836,4885,6552,
4127,6553,4451,4102,5002,6554,3686,5105,6555,5191,5072,5295,4611,5794,5296,6556,
5893,5264,5894,4975,5466,5265,4699,4976,4370,4056,3492,5044,4886,6557,5795,4432,
4769,4357,5467,3940,4660,4290,6141,4484,4770,4661,3992,6329,4025,4662,5022,4632,
4835,4070,5297,4663,4596,5574,5132,5409,5895,6142,4504,5192,4664,5796,5896,3885,
5575,5797,5023,4810,5798,3732,5223,4712,5298,4084,5334,5468,6143,4052,4053,4336,
4977,4794,6558,5335,4908,5576,5224,4233,5024,4128,5469,5225,4873,6008,5045,4729,
4742,4633,3675,4597,6559,5897,5133,5577,5003,5641,5719,6330,6560,3017,2382,3854,
4406,4811,6331,4393,3964,4946,6561,2420,3722,6562,4926,4378,3247,1736,4442,6332,
5134,6333,5226,3996,2918,5470,4319,4003,4598,4743,4744,4485,3785,3902,5167,5004,
5373,4394,5898,6144,4874,1793,3997,6334,4085,4214,5106,5642,4909,5799,6009,4419,
4189,3330,5899,4165,4420,5299,5720,5227,3347,6145,4081,6335,2876,3930,6146,3293,
3786,3910,3998,5900,5300,5578,2840,6563,5901,5579,6147,3531,5374,6564,6565,5580,
4759,5375,6566,6148,3559,5643,6336,6010,5517,6337,6338,5721,5902,3873,6011,6339,
6567,5518,3868,3649,5722,6568,4771,4947,6569,6149,4812,6570,2853,5471,6340,6341,
5644,4795,6342,6012,5723,6343,5724,6013,4349,6344,3160,6150,5193,4599,4514,4493,
5168,4320,6345,4927,3666,4745,5169,5903,5005,4928,6346,5725,6014,4730,4203,5046,
4948,3395,5170,6015,4150,6016,5726,5519,6347,5047,3550,6151,6348,4197,4310,5904,
6571,5581,2965,6152,4978,3960,4291,5135,6572,5301,5727,4129,4026,5905,4853,5728,
5472,6153,6349,4533,2700,4505,5336,4678,3583,5073,2994,4486,3043,4554,5520,6350,
6017,5800,4487,6351,3931,4103,5376,6352,4011,4321,4311,4190,5136,6018,3988,3233,
4350,5906,5645,4198,6573,5107,3432,4191,3435,5582,6574,4139,5410,6353,5411,3944,
5583,5074,3198,6575,6354,4358,6576,5302,4600,5584,5194,5412,6577,6578,5585,5413,
5303,4248,5414,3879,4433,6579,4479,5025,4854,5415,6355,4760,4772,3683,2978,4700,
3797,4452,3965,3932,3721,4910,5801,6580,5195,3551,5907,3221,3471,3029,6019,3999,
5908,5909,5266,5267,3444,3023,3828,3170,4796,5646,4979,4259,6356,5647,5337,3694,
6357,5648,5338,4520,4322,5802,3031,3759,4071,6020,5586,4836,4386,5048,6581,3571,
4679,4174,4949,6154,4813,3787,3402,3822,3958,3215,3552,5268,4387,3933,4950,4359,
6021,5910,5075,3579,6358,4234,4566,5521,6359,3613,5049,6022,5911,3375,3702,3178,
4911,5339,4521,6582,6583,4395,3087,3811,5377,6023,6360,6155,4027,5171,5649,4421,
4249,2804,6584,2270,6585,4000,4235,3045,6156,5137,5729,4140,4312,3886,6361,4330,
6157,4215,6158,3500,3676,4929,4331,3713,4930,5912,4265,3776,3368,5587,4470,4855,
3038,4980,3631,6159,6160,4132,4680,6161,6362,3923,4379,5588,4255,6586,4121,6587,
6363,4649,6364,3288,4773,4774,6162,6024,6365,3543,6588,4274,3107,3737,5050,5803,
4797,4522,5589,5051,5730,3714,4887,5378,4001,4523,6163,5026,5522,4701,4175,2791,
3760,6589,5473,4224,4133,3847,4814,4815,4775,3259,5416,6590,2738,6164,6025,5304,
3733,5076,5650,4816,5590,6591,6165,6592,3934,5269,6593,3396,5340,6594,5804,3445,
3602,4042,4488,5731,5732,3525,5591,4601,5196,6166,6026,5172,3642,4612,3202,4506,
4798,6366,3818,5108,4303,5138,5139,4776,3332,4304,2915,3415,4434,5077,5109,4856,
2879,5305,4817,6595,5913,3104,3144,3903,4634,5341,3133,5110,5651,5805,6167,4057,
5592,2945,4371,5593,6596,3474,4182,6367,6597,6168,4507,4279,6598,2822,6599,4777,
4713,5594,3829,6169,3887,5417,6170,3653,5474,6368,4216,2971,5228,3790,4579,6369,
5733,6600,6601,4951,4746,4555,6602,5418,5475,6027,3400,4665,5806,6171,4799,6028,
5052,6172,3343,4800,4747,5006,6370,4556,4217,5476,4396,5229,5379,5477,3839,5914,
5652,5807,4714,3068,4635,5808,6173,5342,4192,5078,5419,5523,5734,6174,4557,6175,
4602,6371,6176,6603,5809,6372,5735,4260,3869,5111,5230,6029,5112,6177,3126,4681,
5524,5915,2706,3563,4748,3130,6178,4018,5525,6604,6605,5478,4012,4837,6606,4534,
4193,5810,4857,3615,5479,6030,4082,3697,3539,4086,5270,3662,4508,4931,5916,4912,
5811,5027,3888,6607,4397,3527,3302,3798,2775,2921,2637,3966,4122,4388,4028,4054,
1633,4858,5079,3024,5007,3982,3412,5736,6608,3426,3236,5595,3030,6179,3427,3336,
3279,3110,6373,3874,3039,5080,5917,5140,4489,3119,6374,5812,3405,4494,6031,4666,
4141,6180,4166,6032,5813,4981,6609,5081,4422,4982,4112,3915,5653,3296,3983,6375,
4266,4410,5654,6610,6181,3436,5082,6611,5380,6033,3819,5596,4535,5231,5306,5113,
6612,4952,5918,4275,3113,6613,6376,6182,6183,5814,3073,4731,4838,5008,3831,6614,
4888,3090,3848,4280,5526,5232,3014,5655,5009,5737,5420,5527,6615,5815,5343,5173,
5381,4818,6616,3151,4953,6617,5738,2796,3204,4360,2989,4281,5739,5174,5421,5197,
3132,5141,3849,5142,5528,5083,3799,3904,4839,5480,2880,4495,3448,6377,6184,5271,
5919,3771,3193,6034,6035,5920,5010,6036,5597,6037,6378,6038,3106,5422,6618,5423,
5424,4142,6619,4889,5084,4890,4313,5740,6620,3437,5175,5307,5816,4199,5198,5529,
5817,5199,5656,4913,5028,5344,3850,6185,2955,5272,5011,5818,4567,4580,5029,5921,
3616,5233,6621,6622,6186,4176,6039,6379,6380,3352,5200,5273,2908,5598,5234,3837,
5308,6623,6624,5819,4496,4323,5309,5201,6625,6626,4983,3194,3838,4167,5530,5922,
5274,6381,6382,3860,3861,5599,3333,4292,4509,6383,3553,5481,5820,5531,4778,6187,
3955,3956,4324,4389,4218,3945,4325,3397,2681,5923,4779,5085,4019,5482,4891,5382,
5383,6040,4682,3425,5275,4094,6627,5310,3015,5483,5657,4398,5924,3168,4819,6628,
5925,6629,5532,4932,4613,6041,6630,4636,6384,4780,4204,5658,4423,5821,3989,4683,
5822,6385,4954,6631,5345,6188,5425,5012,5384,3894,6386,4490,4104,6632,5741,5053,
6633,5823,5926,5659,5660,5927,6634,5235,5742,5824,4840,4933,4820,6387,4859,5928,
4955,6388,4143,3584,5825,5346,5013,6635,5661,6389,5014,5484,5743,4337,5176,5662,
6390,2836,6391,3268,6392,6636,6042,5236,6637,4158,6638,5744,5663,4471,5347,3663,
4123,5143,4293,3895,6639,6640,5311,5929,5826,3800,6189,6393,6190,5664,5348,3554,
3594,4749,4603,6641,5385,4801,6043,5827,4183,6642,5312,5426,4761,6394,5665,6191,
4715,2669,6643,6644,5533,3185,5427,5086,5930,5931,5386,6192,6044,6645,4781,4013,
5745,4282,4435,5534,4390,4267,6045,5746,4984,6046,2743,6193,3501,4087,5485,5932,
5428,4184,4095,5747,4061,5054,3058,3862,5933,5600,6646,5144,3618,6395,3131,5055,
5313,6396,4650,4956,3855,6194,3896,5202,4985,4029,4225,6195,6647,5828,5486,5829,
3589,3002,6648,6397,4782,5276,6649,6196,6650,4105,3803,4043,5237,5830,6398,4096,
3643,6399,3528,6651,4453,3315,4637,6652,3984,6197,5535,3182,3339,6653,3096,2660,
6400,6654,3449,5934,4250,4236,6047,6401,5831,6655,5487,3753,4062,5832,6198,6199,
6656,3766,6657,3403,4667,6048,6658,4338,2897,5833,3880,2797,3780,4326,6659,5748,
5015,6660,5387,4351,5601,4411,6661,3654,4424,5935,4339,4072,5277,4568,5536,6402,
6662,5238,6663,5349,5203,6200,5204,6201,5145,4536,5016,5056,4762,5834,4399,4957,
6202,6403,5666,5749,6664,4340,6665,5936,5177,5667,6666,6667,3459,4668,6404,6668,
6669,4543,6203,6670,4276,6405,4480,5537,6671,4614,5205,5668,6672,3348,2193,4763,
6406,6204,5937,5602,4177,5669,3419,6673,4020,6205,4443,4569,5388,3715,3639,6407,
6049,4058,6206,6674,5938,4544,6050,4185,4294,4841,4651,4615,5488,6207,6408,6051,
5178,3241,3509,5835,6208,4958,5836,4341,5489,5278,6209,2823,5538,5350,5206,5429,
6675,4638,4875,4073,3516,4684,4914,4860,5939,5603,5389,6052,5057,3237,5490,3791,
6676,6409,6677,4821,4915,4106,5351,5058,4243,5539,4244,5604,4842,4916,5239,3028,
3716,5837,5114,5605,5390,5940,5430,6210,4332,6678,5540,4732,3667,3840,6053,4305,
3408,5670,5541,6410,2744,5240,5750,6679,3234,5606,6680,5607,5671,3608,4283,4159,
4400,5352,4783,6681,6411,6682,4491,4802,6211,6412,5941,6413,6414,5542,5751,6683,
4669,3734,5942,6684,6415,5943,5059,3328,4670,4144,4268,6685,6686,6687,6688,4372,
3603,6689,5944,5491,4373,3440,6416,5543,4784,4822,5608,3792,4616,5838,5672,3514,
5391,6417,4892,6690,4639,6691,6054,5673,5839,6055,6692,6056,5392,6212,4038,5544,
5674,4497,6057,6693,5840,4284,5675,4021,4545,5609,6418,4454,6419,6213,4113,4472,
5314,3738,5087,5279,4074,5610,4959,4063,3179,4750,6058,6420,6214,3476,4498,4716,
5431,4960,4685,6215,5241,6694,6421,6216,6695,5841,5945,6422,3748,5946,5179,3905,
5752,5545,5947,4374,6217,4455,6423,4412,6218,4803,5353,6696,3832,5280,6219,4327,
4702,6220,6221,6059,4652,5432,6424,3749,4751,6425,5753,4986,5393,4917,5948,5030,
5754,4861,4733,6426,4703,6697,6222,4671,5949,4546,4961,5180,6223,5031,3316,5281,
6698,4862,4295,4934,5207,3644,6427,5842,5950,6428,6429,4570,5843,5282,6430,6224,
5088,3239,6060,6699,5844,5755,6061,6431,2701,5546,6432,5115,5676,4039,3993,3327,
4752,4425,5315,6433,3941,6434,5677,4617,4604,3074,4581,6225,5433,6435,6226,6062,
4823,5756,5116,6227,3717,5678,4717,5845,6436,5679,5846,6063,5847,6064,3977,3354,
6437,3863,5117,6228,5547,5394,4499,4524,6229,4605,6230,4306,4500,6700,5951,6065,
3693,5952,5089,4366,4918,6701,6231,5548,6232,6702,6438,4704,5434,6703,6704,5953,
4168,6705,5680,3420,6706,5242,4407,6066,3812,5757,5090,5954,4672,4525,3481,5681,
4618,5395,5354,5316,5955,6439,4962,6707,4526,6440,3465,4673,6067,6441,5682,6708,
5435,5492,5758,5683,4619,4571,4674,4804,4893,4686,5493,4753,6233,6068,4269,6442,
6234,5032,4705,5146,5243,5208,5848,6235,6443,4963,5033,4640,4226,6236,5849,3387,
6444,6445,4436,4437,5850,4843,5494,4785,4894,6709,4361,6710,5091,5956,3331,6237,
4987,5549,6069,6711,4342,3517,4473,5317,6070,6712,6071,4706,6446,5017,5355,6713,
6714,4988,5436,6447,4734,5759,6715,4735,4547,4456,4754,6448,5851,6449,6450,3547,
5852,5318,6451,6452,5092,4205,6716,6238,4620,4219,5611,6239,6072,4481,5760,5957,
5958,4059,6240,6453,4227,4537,6241,5761,4030,4186,5244,5209,3761,4457,4876,3337,
5495,5181,6242,5959,5319,5612,5684,5853,3493,5854,6073,4169,5613,5147,4895,6074,
5210,6717,5182,6718,3830,6243,2798,3841,6075,6244,5855,5614,3604,4606,5496,5685,
5118,5356,6719,6454,5960,5357,5961,6720,4145,3935,4621,5119,5962,4261,6721,6455,
4786,5963,4375,4582,6245,6246,6247,6076,5437,4877,5856,3376,4380,6248,4160,6722,
5148,6456,5211,6457,6723,4718,6458,6724,6249,5358,4044,3297,6459,6250,5857,5615,
5497,5245,6460,5498,6725,6251,6252,5550,3793,5499,2959,5396,6461,6462,4572,5093,
5500,5964,3806,4146,6463,4426,5762,5858,6077,6253,4755,3967,4220,5965,6254,4989,
5501,6464,4352,6726,6078,4764,2290,5246,3906,5438,5283,3767,4964,2861,5763,5094,
6255,6256,4622,5616,5859,5860,4707,6727,4285,4708,4824,5617,6257,5551,4787,5212,
4965,4935,4687,6465,6728,6466,5686,6079,3494,4413,2995,5247,5966,5618,6729,5967,
5764,5765,5687,5502,6730,6731,6080,5397,6467,4990,6258,6732,4538,5060,5619,6733,
4719,5688,5439,5018,5149,5284,5503,6734,6081,4607,6259,5120,3645,5861,4583,6260,
4584,4675,5620,4098,5440,6261,4863,2379,3306,4585,5552,5689,4586,5285,6735,4864,
6736,5286,6082,6737,4623,3010,4788,4381,4558,5621,4587,4896,3698,3161,5248,4353,
4045,6262,3754,5183,4588,6738,6263,6739,6740,5622,3936,6741,6468,6742,6264,5095,
6469,4991,5968,6743,4992,6744,6083,4897,6745,4256,5766,4307,3108,3968,4444,5287,
3889,4343,6084,4510,6085,4559,6086,4898,5969,6746,5623,5061,4919,5249,5250,5504,
5441,6265,5320,4878,3242,5862,5251,3428,6087,6747,4237,5624,5442,6266,5553,4539,
6748,2585,3533,5398,4262,6088,5150,4736,4438,6089,6267,5505,4966,6749,6268,6750,
6269,5288,5554,3650,6090,6091,4624,6092,5690,6751,5863,4270,5691,4277,5555,5864,
6752,5692,4720,4865,6470,5151,4688,4825,6753,3094,6754,6471,3235,4653,6755,5213,
5399,6756,3201,4589,5865,4967,6472,5866,6473,5019,3016,6757,5321,4756,3957,4573,
6093,4993,5767,4721,6474,6758,5625,6759,4458,6475,6270,6760,5556,4994,5214,5252,
6271,3875,5768,6094,5034,5506,4376,5769,6761,2120,6476,5253,5770,6762,5771,5970,
3990,5971,5557,5558,5772,6477,6095,2787,4641,5972,5121,6096,6097,6272,6763,3703,
5867,5507,6273,4206,6274,4789,6098,6764,3619,3646,3833,3804,2394,3788,4936,3978,
4866,4899,6099,6100,5559,6478,6765,3599,5868,6101,5869,5870,6275,6766,4527,6767)
# flake8: noqa
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
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,
19960,
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,
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,
3,
18553,
16909,
4750,
28914,
590,
1202,
4528,
1817,
199,
3,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
687,
394,
90,
1822,
2766,
199,
199,
3,
10574,
221,
10541,
378,
14,
1965,
221,
1553,
378,
14,
1965,
199,
3,
6619,
10541,
378,
14,
2942,
221,
1553,
378,
14,
969,
199,
3,
18427,
10541,
378,
14,
2905,
221,
1553,
378,
14,
1690,
199,
3,
1227,
14408,
10541,
413,
14,
383,
221,
1553,
378,
14,
996,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1965,
8312,
7985,
17,
13,
16,
14,
1965,
8312,
9,
275,
650,
14,
1965,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
1401,
1229,
446,
10574,
9,
275,
378,
14,
10823,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
626,
820,
4564,
199,
199,
6487,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
25,
199,
199,
6487,
16909,
63,
8723,
63,
4305,
275,
650,
19036,
199,
199,
6487,
16909,
18139,
13875,
4738,
275,
334,
199,
975,
3172,
12,
9720,
25,
12,
1079,
2824,
12,
1789,
772,
12,
1355,
1194,
12,
19,
11369,
12,
10034,
16,
12,
1355,
2025,
12,
1196,
966,
12,
1082,
2766,
12,
1479,
3328,
12,
1046,
845,
12,
1046,
1046,
12,
959,
2819,
12,
19,
12632,
12,
1081,
1717,
12,
199,
10008,
17,
12,
18565,
12,
821,
2010,
12,
841,
1965,
12,
1196,
845,
12,
1749,
2766,
12,
19,
12438,
12,
841,
2167,
12,
13344,
16,
12,
1167,
1717,
12,
1398,
1272,
12,
1398,
2417,
12,
1276,
1257,
12,
18,
8557,
12,
1355,
2976,
12,
8188,
18,
12,
199,
1081,
966,
12,
10300,
25,
12,
20,
10744,
12,
1749,
2760,
12,
1479,
2277,
12,
1367,
1479,
12,
1398,
1602,
12,
1398,
1367,
12,
1079,
1965,
12,
5188,
24,
12,
959,
1079,
12,
1276,
2720,
12,
959,
1299,
12,
969,
2466,
12,
1651,
1165,
12,
1082,
1643,
12,
199,
499,
1887,
12,
2167,
1299,
12,
1196,
2466,
12,
1085,
2898,
12,
6686,
23,
12,
8881,
20,
12,
959,
2835,
12,
1085,
969,
12,
650,
2010,
12,
845,
1342,
12,
1276,
2710,
12,
4893,
20,
12,
1046,
2976,
12,
20,
16042,
12,
1081,
2322,
12,
1227,
2760,
12,
199,
975,
1344,
12,
2192,
713,
12,
10523,
25,
12,
713,
1184,
12,
1749,
2481,
12,
31074,
12,
8001,
23,
12,
1216,
2259,
12,
713,
2710,
12,
8988,
17,
12,
1227,
969,
12,
413,
2426,
12,
1082,
1138,
12,
969,
1822,
12,
1695,
1400,
12,
1703,
1165,
12,
199,
1196,
1046,
12,
1194,
1651,
12,
9408,
18,
12,
9687,
19,
12,
1465,
708,
12,
8533,
17,
12,
821,
2789,
12,
9408,
24,
12,
1276,
1272,
12,
1355,
2466,
12,
969,
1887,
12,
650,
1299,
12,
1216,
2905,
12,
1165,
3328,
12,
969,
2259,
12,
1276,
2426,
12,
199,
413,
2528,
12,
975,
1555,
12,
1046,
1355,
12,
1520,
1703,
12,
1046,
1427,
12,
221,
8155,
12,
713,
708,
12,
1398,
821,
12,
1081,
1822,
12,
969,
1299,
12,
713,
1887,
12,
1196,
2953,
12,
975,
1965,
12,
1398,
2259,
12,
413,
2869,
12,
1046,
1272,
12,
199,
6094,
21,
12,
969,
2528,
12,
20,
16344,
12,
1749,
1194,
12,
20,
11700,
12,
650,
2426,
12,
19,
10642,
12,
1602,
1427,
12,
650,
709,
12,
713,
2322,
12,
1651,
1400,
12,
221,
10045,
12,
708,
2426,
12,
1465,
1398,
12,
1276,
1082,
12,
1276,
2194,
12,
199,
9803,
24,
12,
708,
2905,
12,
1082,
1272,
12,
1167,
2259,
12,
30209,
12,
499,
1196,
12,
19,
8557,
12,
1695,
772,
12,
1167,
1643,
12,
1165,
1349,
12,
1602,
614,
12,
9963,
19,
12,
4893,
16,
12,
708,
1876,
12,
21,
11024,
12,
1695,
2481,
12,
199,
1216,
2869,
12,
19,
10753,
12,
713,
1602,
12,
20,
12140,
12,
1085,
2720,
12,
650,
772,
12,
1079,
1020,
12,
1046,
2167,
12,
1789,
969,
12,
845,
1257,
12,
1344,
1229,
12,
1081,
2333,
12,
959,
2789,
12,
1520,
1046,
12,
1194,
1196,
12,
1216,
2976,
12,
199,
959,
1602,
12,
650,
1344,
12,
1401,
2333,
12,
1789,
1257,
12,
1196,
2528,
12,
12641,
21,
12,
1749,
1400,
12,
499,
1257,
12,
1194,
821,
12,
20,
16244,
12,
413,
2658,
12,
1465,
1427,
12,
708,
2819,
12,
23792,
12,
20,
12615,
12,
7842,
21,
12,
199,
975,
1299,
12,
8276,
22,
12,
1079,
1602,
12,
709,
1355,
12,
12383,
16,
12,
1520,
1344,
12,
845,
1138,
12,
8425,
25,
12,
1194,
2824,
12,
10008,
24,
12,
6886,
20,
12,
1081,
821,
12,
959,
2182,
12,
32132,
12,
1079,
2564,
12,
1082,
1690,
12,
199,
1749,
1465,
12,
969,
1276,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
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,
19960,
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,
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,
3,
18553,
16909,
4750,
28914,
590,
1202,
4528,
1817,
199,
3,
199,
3,
6659,
370,
481,
2103,
4738,
1817,
2360,
687,
394,
90,
1822,
2766,
199,
199,
3,
10574,
221,
10541,
378,
14,
1965,
221,
1553,
378,
14,
1965,
199,
3,
6619,
10541,
378,
14,
2942,
221,
1553,
378,
14,
969,
199,
3,
18427,
10541,
378,
14,
2905,
221,
1553,
378,
14,
1690,
199,
3,
1227,
14408,
10541,
413,
14,
383,
221,
1553,
378,
14,
996,
199,
3,
199,
3,
473,
21245,
11839,
820,
32736,
275,
378,
14,
1965,
8312,
7985,
17,
13,
16,
14,
1965,
8312,
9,
275,
650,
14,
1965,
199,
3,
9571,
11839,
820,
425,
275,
10574,
1182,
334,
1401,
1229,
446,
10574,
9,
275,
378,
14,
10823,
199,
3,
199,
3,
29267,
11839,
820,
32736,
3595,
5661,
5,
402,
473,
21245,
1373,
12,
5139,
8298,
10948,
626,
820,
4564,
199,
199,
6487,
16909,
63,
7034,
5974,
63,
24580,
26601,
63,
26566,
275,
378,
14,
25,
199,
199,
6487,
16909,
63,
8723,
63,
4305,
275,
650,
19036,
199,
199,
6487,
16909,
18139,
13875,
4738,
275,
334,
199,
975,
3172,
12,
9720,
25,
12,
1079,
2824,
12,
1789,
772,
12,
1355,
1194,
12,
19,
11369,
12,
10034,
16,
12,
1355,
2025,
12,
1196,
966,
12,
1082,
2766,
12,
1479,
3328,
12,
1046,
845,
12,
1046,
1046,
12,
959,
2819,
12,
19,
12632,
12,
1081,
1717,
12,
199,
10008,
17,
12,
18565,
12,
821,
2010,
12,
841,
1965,
12,
1196,
845,
12,
1749,
2766,
12,
19,
12438,
12,
841,
2167,
12,
13344,
16,
12,
1167,
1717,
12,
1398,
1272,
12,
1398,
2417,
12,
1276,
1257,
12,
18,
8557,
12,
1355,
2976,
12,
8188,
18,
12,
199,
1081,
966,
12,
10300,
25,
12,
20,
10744,
12,
1749,
2760,
12,
1479,
2277,
12,
1367,
1479,
12,
1398,
1602,
12,
1398,
1367,
12,
1079,
1965,
12,
5188,
24,
12,
959,
1079,
12,
1276,
2720,
12,
959,
1299,
12,
969,
2466,
12,
1651,
1165,
12,
1082,
1643,
12,
199,
499,
1887,
12,
2167,
1299,
12,
1196,
2466,
12,
1085,
2898,
12,
6686,
23,
12,
8881,
20,
12,
959,
2835,
12,
1085,
969,
12,
650,
2010,
12,
845,
1342,
12,
1276,
2710,
12,
4893,
20,
12,
1046,
2976,
12,
20,
16042,
12,
1081,
2322,
12,
1227,
2760,
12,
199,
975,
1344,
12,
2192,
713,
12,
10523,
25,
12,
713,
1184,
12,
1749,
2481,
12,
31074,
12,
8001,
23,
12,
1216,
2259,
12,
713,
2710,
12,
8988,
17,
12,
1227,
969,
12,
413,
2426,
12,
1082,
1138,
12,
969,
1822,
12,
1695,
1400,
12,
1703,
1165,
12,
199,
1196,
1046,
12,
1194,
1651,
12,
9408,
18,
12,
9687,
19,
12,
1465,
708,
12,
8533,
17,
12,
821,
2789,
12,
9408,
24,
12,
1276,
1272,
12,
1355,
2466,
12,
969,
1887,
12,
650,
1299,
12,
1216,
2905,
12,
1165,
3328,
12,
969,
2259,
12,
1276,
2426,
12,
199,
413,
2528,
12,
975,
1555,
12,
1046,
1355,
12,
1520,
1703,
12,
1046,
1427,
12,
221,
8155,
12,
713,
708,
12,
1398,
821,
12,
1081,
1822,
12,
969,
1299,
12,
713,
1887,
12,
1196,
2953,
12,
975,
1965,
12,
1398,
2259,
12,
413,
2869,
12,
1046,
1272,
12,
199,
6094,
21,
12,
969,
2528,
12,
20,
16344,
12,
1749,
1194,
12,
20,
11700,
12,
650,
2426,
12,
19,
10642,
12,
1602,
1427,
12,
650,
709,
12,
713,
2322,
12,
1651,
1400,
12,
221,
10045,
12,
708,
2426,
12,
1465,
1398,
12,
1276,
1082,
12,
1276,
2194,
12,
199,
9803,
24,
12,
708,
2905,
12,
1082,
1272,
12,
1167,
2259,
12,
30209,
12,
499,
1196,
12,
19,
8557,
12,
1695,
772,
12,
1167,
1643,
12,
1165,
1349,
12,
1602,
614,
12,
9963,
19,
12,
4893,
16,
12,
708,
1876,
12,
21,
11024,
12,
1695,
2481,
12,
199,
1216,
2869,
12,
19,
10753,
12,
713,
1602,
12,
20,
12140,
12,
1085,
2720,
12,
650,
772,
12,
1079,
1020,
12,
1046,
2167,
12,
1789,
969,
12,
845,
1257,
12,
1344,
1229,
12,
1081,
2333,
12,
959,
2789,
12,
1520,
1046,
12,
1194,
1196,
12,
1216,
2976,
12,
199,
959,
1602,
12,
650,
1344,
12,
1401,
2333,
12,
1789,
1257,
12,
1196,
2528,
12,
12641,
21,
12,
1749,
1400,
12,
499,
1257,
12,
1194,
821,
12,
20,
16244,
12,
413,
2658,
12,
1465,
1427,
12,
708,
2819,
12,
23792,
12,
20,
12615,
12,
7842,
21,
12,
199,
975,
1299,
12,
8276,
22,
12,
1079,
1602,
12,
709,
1355,
12,
12383,
16,
12,
1520,
1344,
12,
845,
1138,
12,
8425,
25,
12,
1194,
2824,
12,
10008,
24,
12,
6886,
20,
12,
1081,
821,
12,
959,
2182,
12,
32132,
12,
1079,
2564,
12,
1082,
1690,
12,
199,
1749,
1465,
12,
969,
1276,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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-boilerplate.py
|
67
|
1646
|
#!/usr/bin/env python
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import ast
import sys
def main():
for path in sys.argv[1:] or sys.stdin.read().splitlines():
with open(path, 'rb') as path_fd:
lines = path_fd.read().splitlines()
missing = True
if not lines:
# Files are allowed to be empty of everything including boilerplate
missing = False
for text in lines:
if text in (b'from __future__ import (absolute_import, division, print_function)',
b'from __future__ import absolute_import, division, print_function'):
missing = False
break
if missing:
with open(path) as file:
contents = file.read()
# noinspection PyBroadException
try:
node = ast.parse(contents)
# files consisting of only assignments have no need for future import boilerplate
# the only exception would be division during assignment, but we'll overlook that for simplicity
# the most likely case is that of a documentation only python file
if all(isinstance(statement, ast.Assign) for statement in node.body):
missing = False
except Exception: # pylint: disable=broad-except
pass # the compile sanity test will report this error
if missing:
print('%s: missing: from __future__ import (absolute_import, division, print_function)' % path)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
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,
6073,
199,
646,
984,
421,
199,
318,
2446,
837,
272,
367,
931,
315,
984,
14,
3020,
59,
17,
2938,
503,
984,
14,
6626,
14,
739,
1252,
7644,
837,
267,
543,
1551,
8,
515,
12,
283,
4848,
358,
465,
931,
63,
2592,
26,
288,
2385,
275,
931,
63,
2592,
14,
739,
1252,
7644,
342,
398,
4124,
275,
715,
267,
340,
440,
2385,
26,
288,
327,
16920,
787,
4370,
370,
506,
2701,
402,
8137,
5893,
1234,
27025,
288,
4124,
275,
756,
398,
367,
1318,
315,
2385,
26,
288,
340,
1318,
315,
334,
66,
7,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
3196,
717,
330,
7,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
735,
355,
4124,
275,
756,
355,
2059,
398,
340,
4124,
26,
288,
543,
1551,
8,
515,
9,
465,
570,
26,
355,
4072,
275,
570,
14,
739,
342,
953,
327,
30870,
1611,
34,
5063,
1726,
288,
862,
26,
355,
1031,
275,
6073,
14,
1122,
8,
4407,
9,
2234,
327,
1584,
22581,
402,
1454,
18121,
1172,
949,
1929,
367,
6466,
492,
1234,
27025,
355,
327,
314,
1454,
1919,
3955,
506,
4629,
5309,
9801,
12,
1325,
781,
7171,
1806,
11660,
626,
367,
17553,
3690,
355,
327,
314,
4750,
12060,
1930,
365,
626,
402,
282,
3794,
1454,
2366,
570,
355,
340,
1006,
8,
6074,
8,
6242,
12,
6073,
14,
9595,
9,
367,
5164,
315,
1031,
14,
2030,
304,
490,
4124,
275,
756,
288,
871,
2186,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
355,
986,
221,
327,
314,
6555,
16740,
511,
911,
3622,
642,
1125,
398,
340,
4124,
26,
288,
870,
3508,
83,
26,
4124,
26,
687,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
3171,
450,
931,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
6073,
199,
646,
984,
421,
199,
318,
2446,
837,
272,
367,
931,
315,
984,
14,
3020,
59,
17,
2938,
503,
984,
14,
6626,
14,
739,
1252,
7644,
837,
267,
543,
1551,
8,
515,
12,
283,
4848,
358,
465,
931,
63,
2592,
26,
288,
2385,
275,
931,
63,
2592,
14,
739,
1252,
7644,
342,
398,
4124,
275,
715,
267,
340,
440,
2385,
26,
288,
327,
16920,
787,
4370,
370,
506,
2701,
402,
8137,
5893,
1234,
27025,
288,
4124,
275,
756,
398,
367,
1318,
315,
2385,
26,
288,
340,
1318,
315,
334,
66,
7,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
3196,
717,
330,
7,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
735,
355,
4124,
275,
756,
355,
2059,
398,
340,
4124,
26,
288,
543,
1551,
8,
515,
9,
465,
570,
26,
355,
4072,
275,
570,
14,
739,
342,
953,
327,
30870,
1611,
34,
5063,
1726,
288,
862,
26,
355,
1031,
275,
6073,
14,
1122,
8,
4407,
9,
2234,
327,
1584,
22581,
402,
1454,
18121,
1172,
949,
1929,
367,
6466,
492,
1234,
27025,
355,
327,
314,
1454,
1919,
3955,
506,
4629,
5309,
9801,
12,
1325,
781,
7171,
1806,
11660,
626,
367,
17553,
3690,
355,
327,
314,
4750,
12060,
1930,
365,
626,
402,
282,
3794,
1454,
2366,
570,
355,
340,
1006,
8,
6074,
8,
6242,
12,
6073,
14,
9595,
9,
367,
5164,
315,
1031,
14,
2030,
304,
490,
4124,
275,
756,
288,
871,
2186,
26,
221,
327,
4287,
26,
3507,
29,
29047,
13,
2590,
355,
986,
221,
327,
314,
6555,
16740,
511,
911,
3622,
642,
1125,
398,
340,
4124,
26,
288,
870,
3508,
83,
26,
4124,
26,
687,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
3171,
450,
931,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
adfernandes/pcp
|
src/pmdas/bpftrace/bpftrace/utils.py
|
4
|
1073
|
from typing import Optional, Tuple
import sys
import re
import subprocess
import asyncio
def get_bpftrace_version(bpftrace_path: str) -> Optional[Tuple]:
version_str = subprocess.check_output([bpftrace_path, '--version'], encoding='utf8').strip()
version_str = version_str[version_str.find(' ')+1:] # remove 'bpftrace' word
re_version = re.match(r'v(\d+)\.(\d+)\.(\d+)', version_str)
if re_version:
# regex enforces exactly 3 integers
return version_str, tuple(map(int, re_version.groups())) # (major, minor, patch)
return version_str, (999, 999, 999)
def get_tracepoints_csv(bpftrace_path: str) -> str:
# use a set to prevent duplicate probes
# see https://github.com/iovisor/bpftrace/issues/1581
tracepoints = frozenset(subprocess.check_output([bpftrace_path, '-l'], encoding='utf8').split())
return ','.join(tracepoints)
def asyncio_get_all_tasks(loop):
if sys.version_info >= (3, 7):
return asyncio.all_tasks(loop)
else:
return asyncio.Task.all_tasks(loop) # pylint: disable=no-member
|
lgpl-2.1
|
[
504,
14090,
492,
4879,
12,
11634,
199,
646,
984,
199,
646,
295,
199,
646,
3873,
199,
646,
16195,
421,
199,
318,
664,
63,
10913,
24856,
63,
1023,
8,
10913,
24856,
63,
515,
26,
620,
9,
1035,
4879,
59,
7075,
2189,
272,
1015,
63,
495,
275,
3873,
14,
1074,
63,
1199,
779,
10913,
24856,
63,
515,
12,
2850,
1023,
995,
2644,
534,
1624,
24,
1959,
1913,
342,
272,
1015,
63,
495,
275,
1015,
63,
495,
59,
1023,
63,
495,
14,
1623,
360,
5320,
11,
17,
2938,
221,
327,
2813,
283,
10913,
24856,
7,
4349,
272,
295,
63,
1023,
275,
295,
14,
1431,
8,
82,
7,
86,
2961,
68,
13439,
14,
2961,
68,
13439,
14,
2961,
68,
14705,
1015,
63,
495,
9,
272,
340,
295,
63,
1023,
26,
267,
327,
5163,
655,
509,
823,
8840,
650,
9446,
267,
372,
1015,
63,
495,
12,
2008,
8,
1130,
8,
442,
12,
295,
63,
1023,
14,
2634,
4059,
221,
327,
334,
8452,
12,
12612,
12,
3371,
9,
272,
372,
1015,
63,
495,
12,
334,
5637,
12,
22291,
12,
22291,
9,
421,
199,
318,
664,
63,
3446,
3438,
63,
4737,
8,
10913,
24856,
63,
515,
26,
620,
9,
1035,
620,
26,
272,
327,
675,
282,
663,
370,
7981,
9250,
5128,
397,
272,
327,
1937,
4178,
921,
5031,
14,
957,
15,
2308,
8286,
15,
10913,
24856,
15,
10115,
15,
1046,
2835,
272,
3307,
3438,
275,
9522,
8,
5781,
14,
1074,
63,
1199,
779,
10913,
24856,
63,
515,
12,
2475,
76,
995,
2644,
534,
1624,
24,
1959,
1294,
1012,
272,
372,
12814,
904,
8,
3446,
3438,
9,
421,
199,
318,
16195,
63,
362,
63,
452,
63,
5054,
8,
3813,
304,
272,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
1520,
304,
267,
372,
16195,
14,
452,
63,
5054,
8,
3813,
9,
272,
587,
26,
267,
372,
16195,
14,
4476,
14,
452,
63,
5054,
8,
3813,
9,
327,
4287,
26,
3507,
29,
889,
13,
1114,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
14090,
492,
4879,
12,
11634,
199,
646,
984,
199,
646,
295,
199,
646,
3873,
199,
646,
16195,
421,
199,
318,
664,
63,
10913,
24856,
63,
1023,
8,
10913,
24856,
63,
515,
26,
620,
9,
1035,
4879,
59,
7075,
2189,
272,
1015,
63,
495,
275,
3873,
14,
1074,
63,
1199,
779,
10913,
24856,
63,
515,
12,
2850,
1023,
995,
2644,
534,
1624,
24,
1959,
1913,
342,
272,
1015,
63,
495,
275,
1015,
63,
495,
59,
1023,
63,
495,
14,
1623,
360,
5320,
11,
17,
2938,
221,
327,
2813,
283,
10913,
24856,
7,
4349,
272,
295,
63,
1023,
275,
295,
14,
1431,
8,
82,
7,
86,
2961,
68,
13439,
14,
2961,
68,
13439,
14,
2961,
68,
14705,
1015,
63,
495,
9,
272,
340,
295,
63,
1023,
26,
267,
327,
5163,
655,
509,
823,
8840,
650,
9446,
267,
372,
1015,
63,
495,
12,
2008,
8,
1130,
8,
442,
12,
295,
63,
1023,
14,
2634,
4059,
221,
327,
334,
8452,
12,
12612,
12,
3371,
9,
272,
372,
1015,
63,
495,
12,
334,
5637,
12,
22291,
12,
22291,
9,
421,
199,
318,
664,
63,
3446,
3438,
63,
4737,
8,
10913,
24856,
63,
515,
26,
620,
9,
1035,
620,
26,
272,
327,
675,
282,
663,
370,
7981,
9250,
5128,
397,
272,
327,
1937,
4178,
921,
5031,
14,
957,
15,
2308,
8286,
15,
10913,
24856,
15,
10115,
15,
1046,
2835,
272,
3307,
3438,
275,
9522,
8,
5781,
14,
1074,
63,
1199,
779,
10913,
24856,
63,
515,
12,
2475,
76,
995,
2644,
534,
1624,
24,
1959,
1294,
1012,
272,
372,
12814,
904,
8,
3446,
3438,
9,
421,
199,
318,
16195,
63,
362,
63,
452,
63,
5054,
8,
3813,
304,
272,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
12,
1520,
304,
267,
372,
16195,
14,
452,
63,
5054,
8,
3813,
9,
272,
587,
26,
267,
372,
16195,
14,
4476,
14,
452,
63,
5054,
8,
3813,
9,
327,
4287,
26,
3507,
29,
889,
13,
1114,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gtrensch/nest-simulator
|
pynest/examples/clopath_synapse_small_network.py
|
8
|
7493
|
# -*- coding: utf-8 -*-
#
# clopath_synapse_small_network.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST 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.
#
# NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
"""
Clopath Rule: Bidirectional connections
---------------------------------------
This script simulates a small network of ten excitatory and three
inhibitory ``aeif_psc_delta_clopath`` neurons. The neurons are randomly connected
and driven by 500 Poisson generators. The synapses from the Poisson generators
to the excitatory population and those among the neurons of the network
are Clopath synapses. The rate of the Poisson generators is modulated with
a Gaussian profile whose center shifts randomly each 100 ms between ten
equally spaced positions.
This setup demonstrates that the Clopath synapse is able to establish
bidirectional connections. The example is adapted from [1]_ (cf. fig. 5).
References
~~~~~~~~~~
.. [1] Clopath C, Büsing L, Vasilaki E, Gerstner W (2010). Connectivity reflects coding:
a model of voltage-based STDP with homeostasis.
Nature Neuroscience 13:3, 344--352
"""
import nest
import numpy as np
import matplotlib.pyplot as plt
import random
##############################################################################
# Set the parameters
simulation_time = 1.0e4
resolution = 0.1
delay = resolution
# Poisson_generator parameters
pg_A = 30. # amplitude of Gaussian
pg_sigma = 10. # std deviation
nest.ResetKernel()
nest.SetKernelStatus({'resolution': resolution})
# Create neurons and devices
nrn_model = 'aeif_psc_delta_clopath'
nrn_params = {'V_m': -30.6,
'g_L': 30.0,
'w': 0.0,
'tau_plus': 7.0,
'tau_minus': 10.0,
'tau_w': 144.0,
'a': 4.0,
'C_m': 281.0,
'Delta_T': 2.0,
'V_peak': 20.0,
't_clamp': 2.0,
'A_LTP': 8.0e-6,
'A_LTD': 14.0e-6,
'A_LTD_const': False,
'b': 0.0805,
'u_ref_squared': 60.0**2}
pop_exc = nest.Create(nrn_model, 10, nrn_params)
pop_inh = nest.Create(nrn_model, 3, nrn_params)
##############################################################################
# We need parrot neurons since Poisson generators can only be connected
# with static connections
pop_input = nest.Create('parrot_neuron', 500) # helper neurons
pg = nest.Create('poisson_generator', 500)
wr = nest.Create('weight_recorder')
##############################################################################
# First connect Poisson generators to helper neurons
nest.Connect(pg, pop_input, 'one_to_one', {'synapse_model': 'static_synapse',
'weight': 1.0, 'delay': delay})
##############################################################################
# Create all the connections
nest.CopyModel('clopath_synapse', 'clopath_input_to_exc',
{'Wmax': 3.0})
conn_dict_input_to_exc = {'rule': 'all_to_all'}
syn_dict_input_to_exc = {'synapse_model': 'clopath_input_to_exc',
'weight': nest.random.uniform(0.5, 2.0),
'delay': delay}
nest.Connect(pop_input, pop_exc, conn_dict_input_to_exc,
syn_dict_input_to_exc)
# Create input->inh connections
conn_dict_input_to_inh = {'rule': 'all_to_all'}
syn_dict_input_to_inh = {'synapse_model': 'static_synapse',
'weight': nest.random.uniform(0.0, 0.5),
'delay': delay}
nest.Connect(pop_input, pop_inh, conn_dict_input_to_inh, syn_dict_input_to_inh)
# Create exc->exc connections
nest.CopyModel('clopath_synapse', 'clopath_exc_to_exc',
{'Wmax': 0.75, 'weight_recorder': wr})
syn_dict_exc_to_exc = {'synapse_model': 'clopath_exc_to_exc', 'weight': 0.25,
'delay': delay}
conn_dict_exc_to_exc = {'rule': 'all_to_all', 'allow_autapses': False}
nest.Connect(pop_exc, pop_exc, conn_dict_exc_to_exc, syn_dict_exc_to_exc)
# Create exc->inh connections
syn_dict_exc_to_inh = {'synapse_model': 'static_synapse',
'weight': 1.0, 'delay': delay}
conn_dict_exc_to_inh = {'rule': 'fixed_indegree', 'indegree': 8}
nest.Connect(pop_exc, pop_inh, conn_dict_exc_to_inh, syn_dict_exc_to_inh)
# Create inh->exc connections
syn_dict_inh_to_exc = {'synapse_model': 'static_synapse',
'weight': 1.0, 'delay': delay}
conn_dict_inh_to_exc = {'rule': 'fixed_outdegree', 'outdegree': 6}
nest.Connect(pop_inh, pop_exc, conn_dict_inh_to_exc, syn_dict_inh_to_exc)
##############################################################################
# Randomize the initial membrane potential
pop_exc.V_m = nest.random.normal(-60., 25.)
pop_inh.V_m = nest.random.normal(-60., 25.)
##############################################################################
# Simulation divided into intervals of 100ms for shifting the Gaussian
sim_interval = 100.
for i in range(int(simulation_time/sim_interval)):
# set rates of poisson generators
rates = np.empty(500)
# pg_mu will be randomly chosen out of 25,75,125,...,425,475
pg_mu = 25 + random.randint(0, 9) * 50
for j in range(500):
rates[j] = pg_A * np.exp((-1 * (j - pg_mu)**2) / (2 * pg_sigma**2))
pg[j].rate = rates[j]*1.75
nest.Simulate(sim_interval)
##############################################################################
# Plot results
fig, ax = plt.subplots(1, sharex=False)
# Plot synapse weights of the synapses within the excitatory population
# Sort weights according to sender and reshape
exc_conns = nest.GetConnections(pop_exc, pop_exc)
exc_conns_senders = np.array(exc_conns.source)
exc_conns_targets = np.array(exc_conns.target)
exc_conns_weights = np.array(exc_conns.weight)
idx_array = np.argsort(exc_conns_senders)
targets = np.reshape(exc_conns_targets[idx_array], (10, 10 - 1))
weights = np.reshape(exc_conns_weights[idx_array], (10, 10 - 1))
# Sort according to target
for i, (trgs, ws) in enumerate(zip(targets, weights)):
idx_array = np.argsort(trgs)
weights[i] = ws[idx_array]
weight_matrix = np.zeros((10, 10))
tu9 = np.triu_indices_from(weights)
tl9 = np.tril_indices_from(weights, -1)
tu10 = np.triu_indices_from(weight_matrix, 1)
tl10 = np.tril_indices_from(weight_matrix, -1)
weight_matrix[tu10[0], tu10[1]] = weights[tu9[0], tu9[1]]
weight_matrix[tl10[0], tl10[1]] = weights[tl9[0], tl9[1]]
# Difference between initial and final value
init_w_matrix = np.ones((10, 10))*0.25
init_w_matrix -= np.identity(10)*0.25
cax = ax.imshow(weight_matrix - init_w_matrix)
cbarB = fig.colorbar(cax, ax=ax)
ax.set_xticks([0, 2, 4, 6, 8])
ax.set_xticklabels(['1', '3', '5', '7', '9'])
ax.set_yticks([0, 2, 4, 6, 8])
ax.set_xticklabels(['1', '3', '5', '7', '9'])
ax.set_xlabel("to neuron")
ax.set_ylabel("from neuron")
ax.set_title("Change of syn weights before and after simulation")
plt.show()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
2463,
515,
63,
9466,
19111,
63,
7241,
63,
1200,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
3337,
515,
11949,
26,
31012,
21360,
6947,
199,
1444,
12797,
199,
199,
2765,
2884,
4389,
15409,
282,
7425,
2784,
402,
16685,
3178,
390,
8658,
436,
7795,
199,
17695,
1892,
390,
1089,
1124,
3624,
692,
63,
80,
551,
63,
3136,
63,
1251,
515,
1040,
1279,
32073,
14,
710,
1279,
32073,
787,
19311,
8539,
199,
460,
20921,
1856,
701,
6891,
4376,
18571,
16952,
14,
710,
9560,
25036,
687,
314,
4376,
18571,
16952,
199,
475,
314,
3178,
390,
8658,
16423,
436,
5204,
16885,
314,
1279,
32073,
402,
314,
2784,
199,
1530,
5980,
515,
9560,
25036,
14,
710,
6634,
402,
314,
4376,
18571,
16952,
365,
3413,
8097,
543,
199,
65,
17131,
4690,
7447,
8126,
20863,
1086,
19311,
1924,
2948,
6605,
3382,
16685,
199,
15788,
1183,
4601,
68,
12266,
14,
199,
2765,
3272,
23789,
31216,
626,
314,
5980,
515,
9560,
19111,
365,
7688,
370,
16873,
199,
4492,
21360,
6947,
14,
710,
2893,
365,
26266,
687,
359,
17,
25276,
334,
2177,
14,
6085,
14,
959,
680,
199,
199,
15242,
199,
4919,
1714,
199,
199,
703,
359,
17,
61,
5980,
515,
445,
12,
699,
17709,
1044,
491,
12,
812,
305,
382,
27387,
662,
12,
22261,
270,
1372,
644,
334,
6542,
680,
1448,
13498,
16806,
83,
2803,
26,
2126,
282,
1402,
402,
29943,
13,
6788,
4384,
11741,
543,
5629,
941,
4864,
14,
2126,
653,
1463,
5612,
9129,
9907,
4894,
4944,
26,
19,
12,
650,
1602,
306,
15139,
199,
624,
199,
199,
646,
10715,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2196,
199,
199,
4605,
199,
3,
2494,
314,
2633,
199,
199,
22930,
63,
521,
275,
413,
14,
16,
69,
20,
199,
12588,
275,
378,
14,
17,
199,
5814,
275,
12401,
199,
199,
3,
4376,
18571,
63,
4679,
2633,
199,
4198,
63,
33,
275,
4233,
14,
420,
327,
30727,
402,
17131,
199,
4198,
63,
9412,
275,
1616,
14,
221,
327,
2418,
18458,
199,
199,
15272,
14,
9637,
14127,
342,
199,
15272,
14,
1084,
14127,
3694,
3252,
12588,
356,
12401,
1552,
199,
199,
3,
2790,
1279,
32073,
436,
7256,
199,
7865,
78,
63,
1238,
275,
283,
3624,
692,
63,
80,
551,
63,
3136,
63,
1251,
515,
7,
199,
7865,
78,
63,
1162,
275,
791,
54,
63,
77,
356,
446,
1216,
14,
22,
12,
1598,
283,
71,
63,
44,
356,
4233,
14,
16,
12,
1598,
283,
87,
356,
378,
14,
16,
12,
1598,
283,
16656,
63,
6666,
356,
1520,
14,
16,
12,
1598,
283,
16656,
63,
13084,
356,
1616,
14,
16,
12,
1598,
283,
16656,
63,
87,
356,
21771,
14,
16,
12,
1598,
283,
65,
356,
841,
14,
16,
12,
1598,
283,
35,
63,
77,
356,
499,
2835,
14,
16,
12,
1598,
283,
13411,
63,
52,
356,
499,
14,
16,
12,
1598,
283,
54,
63,
8556,
356,
3388,
14,
16,
12,
1598,
283,
84,
63,
3995,
311,
356,
499,
14,
16,
12,
1598,
283,
33,
63,
44,
6495,
356,
1695,
14,
16,
69,
13,
22,
12,
1598,
283,
33,
63,
44,
13449,
356,
4329,
14,
16,
69,
13,
22,
12,
1598,
283,
33,
63,
44,
13449,
63,
1297,
356,
756,
12,
1598,
283,
66,
356,
378,
14,
16,
13027,
12,
1598,
283,
85,
63,
1121,
63,
12973,
356,
5212,
14,
16,
538,
18,
93,
199,
199,
1935,
63,
2804,
275,
10715,
14,
2499,
8,
7865,
78,
63,
1238,
12,
1616,
12,
302,
11641,
63,
1162,
9,
199,
1935,
63,
17695,
275,
10715,
14,
2499,
8,
7865,
78,
63,
1238,
12,
650,
12,
302,
11641,
63,
1162,
9,
199,
199,
4605,
199,
3,
2136,
1929,
623,
4571,
1279,
32073,
3967,
4376,
18571,
16952,
883,
1454,
506,
8539,
199,
3,
543,
2955,
6947,
199,
199,
1935,
63,
1210,
275,
10715,
14,
2499,
360,
462,
4571,
63,
32054,
297,
6891,
9,
221,
327,
5922,
1279,
32073,
199,
4198,
275,
10715,
14,
2499,
360,
29606,
63,
4679,
297,
6891,
9,
199,
17097,
275,
10715,
14,
2499,
360,
3463,
63,
27733,
358,
199,
199,
4605,
199,
3,
7758,
4907,
4376,
18571,
16952,
370,
5922,
1279,
32073,
199,
15272,
14,
8631,
8,
4198,
12,
4560,
63,
1210,
12,
283,
368,
63,
475,
63,
368,
297,
791,
9466,
19111,
63,
1238,
356,
283,
1986,
63,
9466,
19111,
297,
5644,
283,
3463,
356,
413,
14,
16,
12,
283,
5814,
356,
7339,
1552,
199,
199,
4605,
199,
3,
2790,
1006,
314,
6947,
199,
199,
15272,
14,
5116,
1685,
360,
1251,
515,
63,
9466,
19111,
297,
283,
1251,
515,
63,
1210,
63,
475,
63,
2804,
297,
2049,
791,
55,
988,
356,
650,
14,
16,
1552,
199,
1631,
63,
807,
63,
1210,
63,
475,
63,
2804,
275,
791,
2200,
356,
283,
452,
63,
475,
63,
452,
936,
199,
9466,
63,
807,
63,
1210,
63,
475,
63,
2804,
275,
791,
9466,
19111,
63,
1238,
356,
283,
1251,
515,
63,
1210,
63,
475,
63,
2804,
297,
586,
283,
3463,
356,
10715,
14,
2355,
14,
8830,
8,
16,
14,
21,
12,
499,
14,
16,
395,
586,
283,
5814,
356,
7339,
93,
199,
15272,
14,
8631,
8,
1935,
63,
1210,
12,
4560,
63,
2804
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
2463,
515,
63,
9466,
19111,
63,
7241,
63,
1200,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
3337,
515,
11949,
26,
31012,
21360,
6947,
199,
1444,
12797,
199,
199,
2765,
2884,
4389,
15409,
282,
7425,
2784,
402,
16685,
3178,
390,
8658,
436,
7795,
199,
17695,
1892,
390,
1089,
1124,
3624,
692,
63,
80,
551,
63,
3136,
63,
1251,
515,
1040,
1279,
32073,
14,
710,
1279,
32073,
787,
19311,
8539,
199,
460,
20921,
1856,
701,
6891,
4376,
18571,
16952,
14,
710,
9560,
25036,
687,
314,
4376,
18571,
16952,
199,
475,
314,
3178,
390,
8658,
16423,
436,
5204,
16885,
314,
1279,
32073,
402,
314,
2784,
199,
1530,
5980,
515,
9560,
25036,
14,
710,
6634,
402,
314,
4376,
18571,
16952,
365,
3413,
8097,
543,
199,
65,
17131,
4690,
7447,
8126,
20863,
1086,
19311,
1924,
2948,
6605,
3382,
16685,
199,
15788,
1183,
4601,
68,
12266,
14,
199,
2765,
3272,
23789,
31216,
626,
314,
5980,
515,
9560,
19111,
365,
7688,
370,
16873,
199,
4492,
21360,
6947,
14,
710,
2893,
365,
26266,
687,
359,
17,
25276,
334,
2177,
14,
6085,
14,
959,
680,
199,
199,
15242,
199,
4919,
1714,
199,
199,
703,
359,
17,
61,
5980,
515,
445,
12,
699,
17709,
1044,
491,
12,
812,
305,
382,
27387,
662,
12,
22261,
270,
1372,
644,
334,
6542,
680,
1448,
13498,
16806,
83,
2803,
26,
2126,
282,
1402,
402,
29943,
13,
6788,
4384,
11741,
543,
5629,
941,
4864,
14,
2126,
653,
1463,
5612,
9129,
9907,
4894,
4944,
26,
19,
12,
650,
1602,
306,
15139,
199,
624,
199,
199,
646,
10715,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
2196,
199,
199,
4605,
199,
3,
2494,
314,
2633,
199,
199,
22930,
63,
521,
275,
413,
14,
16,
69,
20,
199,
12588,
275,
378,
14,
17,
199,
5814,
275,
12401,
199,
199,
3,
4376,
18571,
63,
4679,
2633,
199,
4198,
63,
33,
275,
4233,
14,
420,
327,
30727,
402,
17131,
199,
4198,
63,
9412,
275,
1616,
14,
221,
327,
2418,
18458,
199,
199,
15272,
14,
9637,
14127,
342,
199,
15272,
14,
1084,
14127,
3694,
3252,
12588,
356,
12401,
1552,
199,
199,
3,
2790,
1279,
32073,
436,
7256,
199,
7865,
78,
63,
1238,
275,
283,
3624,
692,
63,
80,
551,
63,
3136,
63,
1251,
515,
7,
199,
7865,
78,
63,
1162,
275,
791,
54,
63,
77,
356,
446,
1216,
14,
22,
12,
1598,
283,
71,
63,
44,
356,
4233,
14,
16,
12,
1598,
283,
87,
356,
378,
14,
16,
12,
1598,
283,
16656,
63,
6666,
356,
1520,
14,
16,
12,
1598,
283,
16656,
63,
13084,
356,
1616,
14,
16,
12,
1598,
283,
16656,
63,
87,
356,
21771,
14,
16,
12,
1598,
283,
65,
356,
841,
14,
16,
12,
1598,
283,
35,
63,
77,
356,
499,
2835,
14,
16,
12,
1598,
283,
13411,
63,
52,
356,
499,
14,
16,
12,
1598,
283,
54,
63,
8556,
356,
3388,
14,
16,
12,
1598,
283,
84,
63,
3995,
311,
356,
499,
14,
16,
12,
1598,
283,
33,
63,
44,
6495,
356,
1695,
14,
16,
69,
13,
22,
12,
1598,
283,
33,
63,
44,
13449,
356,
4329,
14,
16,
69,
13,
22,
12,
1598,
283,
33,
63,
44,
13449,
63,
1297,
356,
756,
12,
1598,
283,
66,
356,
378,
14,
16,
13027,
12,
1598,
283,
85,
63,
1121,
63,
12973,
356,
5212,
14,
16,
538,
18,
93,
199,
199,
1935,
63,
2804,
275,
10715,
14,
2499,
8,
7865,
78,
63,
1238,
12,
1616,
12,
302,
11641,
63,
1162,
9,
199,
1935,
63,
17695,
275,
10715,
14,
2499,
8,
7865,
78,
63,
1238,
12,
650,
12,
302,
11641,
63,
1162,
9,
199,
199,
4605,
199,
3,
2136,
1929,
623,
4571,
1279,
32073,
3967,
4376,
18571,
16952,
883,
1454,
506,
8539,
199,
3,
543,
2955,
6947,
199,
199,
1935,
63,
1210,
275,
10715,
14,
2499,
360,
462,
4571,
63,
32054,
297,
6891,
9,
221,
327,
5922,
1279,
32073,
199,
4198,
275,
10715,
14,
2499,
360,
29606,
63,
4679,
297,
6891,
9,
199,
17097,
275,
10715,
14,
2499,
360,
3463,
63,
27733,
358,
199,
199,
4605,
199,
3,
7758,
4907,
4376,
18571,
16952,
370,
5922,
1279,
32073,
199,
15272,
14,
8631,
8,
4198,
12,
4560,
63,
1210,
12,
283,
368,
63,
475,
63,
368,
297,
791,
9466,
19111,
63,
1238,
356,
283,
1986,
63,
9466,
19111,
297,
5644,
283,
3463,
356,
413,
14,
16,
12,
283,
5814,
356,
7339,
1552,
199,
199,
4605,
199,
3,
2790,
1006,
314,
6947,
199,
199,
15272,
14,
5116,
1685,
360,
1251,
515,
63,
9466,
19111,
297,
283,
1251,
515,
63,
1210,
63,
475,
63,
2804,
297,
2049,
791,
55,
988,
356,
650,
14,
16,
1552,
199,
1631,
63,
807,
63,
1210,
63,
475,
63,
2804,
275,
791,
2200,
356,
283,
452,
63,
475,
63,
452,
936,
199,
9466,
63,
807,
63,
1210,
63,
475,
63,
2804,
275,
791,
9466,
19111,
63,
1238,
356,
283,
1251,
515,
63,
1210,
63,
475,
63,
2804,
297,
586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